# Linear lambda-calculus and Reversible Automatic Combinators

In 2005, Abramsky introduced various linear/affine combinatory algebras of partial involutions over a suitable formal language, to discuss reversible computation in a game-theoretic setting. These algebras arise as instances of the general paradigm explored by Haghverdi (Abramsky's Programme), which amounts to defining a lambda-algebra starting from a GoI Situation in a traced symmetric monoidal category. We investigate this construction from the point of view of the model theory of lambda-calculus. We focus on the strictly linear and affine parts of Abramsky's Affine Combinatory Algebras, sketching how to encompass the full algebra. The gist of our approach is that the GoI interpretation of a term based on involutions is dual to the principal type of the term, w.r.t. the type discipline for a linear/affine lambda-calculus. In the general case the type discipline and the calculus need to be extended, resp., with intersection, !-types, and !-abstractions. Our analysis unveils three conceptually independent, but ultimately equivalent, accounts of application in the lambda-calculus: beta-reduction, the GoI application of involutions based on symmetric feedback (Girard's Execution Formula), and unification of principal types. Thus we provide an answer, in the strictly affine case, to the question raised in [1] of characterising the partial involutions arising from bi-orthogonal pattern matching automata, which are denotations of affine combinators, and we point to the answer to the full question. Furthermore, we prove that the strictly linear combinatory algebra of partial involutions is a strictly linear lambda-algebra, albeit not a combinatory model, while both the strictly affine combinatory algebra and the full affine combinatory algebra are not. To check all the equations involved in the definition of affine lambda-algebra, we implement in Erlang application of involutions.

## Authors

• 3 publications
• 4 publications
• 3 publications
• 5 publications
06/18/2018

### Lambda-calculus and Reversible Automatic Combinators

In 2005, Abramsky introduced various linear/affine combinatory algebras ...
09/29/2018

### Truly Concurrent Process Algebra Is Reversible

Based on our previous process algebra for concurrency APTC, we prove tha...
04/23/2019

### Towards a Semantic Measure of the Execution Time in Call-by-Value lambda-Calculus

We investigate the possibility of a semantic account of the execution ti...
08/14/2019

### On the Elementary Affine Lambda-Calculus with and Without Fixed Points

The elementary affine lambda-calculus was introduced as a polyvalent set...
10/14/2018

### Monads, partial evaluations, and rewriting

Monads can be interpreted as encoding formal expressions, or formal oper...
06/17/2020

### Local structure of idempotent algebras I

We refine and advance the study of the local structure of idempotent fin...
05/13/2021

### A Graphical Calculus for Lagrangian Relations

Symplectic vector spaces are the phase space of linear mechanical system...
##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1.1 Introduction

In [1], S. Abramsky discusses Reversible Computation in a game-theoretic setting. In particular, he introduces various kinds of reversible pattern-matching automata whose behaviour can be described in a finitary way as partial injective functions, actually involutions, over a suitable language. These yield affine combinatory algebras w.r.t. a notion of application between automata, for which the flow of control is analogous to the one between history-free strategies in game models. Similar constructions appear in various papers by S. Abramsky, e.g[2, 3], and are special cases of a general categorical paradigm explored by E. Haghverdi [16], Sections 5.3, 6, called “Abramsky’s Programme”. This Programme amounts to defining a -algebra starting from a GoI Situation in a “traced symmetric monoidal category”, where application arises from symmetric feedback/Girard’s Execution Formula. We recall that GoI is the acronym for “Geometry of Interaction”, an approach invented by J. Y. Girard [13, 14] in order to model, in a language-independent way, the fine semantics of Linear Logic.

In this paper, we discuss Abramsky’s algebras from the point of view of the model theory of -calculus. We focus on the strictly linear and strictly affine parts of Abramsky’s affine algebras. In particular, we consider strictly linear and strictly affine combinatory logic, their -calculus counterparts, and their models, i.eBCI-combinatory algebras and BCK-combinatory algebras. For each calculus we discuss also the corresponding notion of -algebra. This notion was originally introduced by D. Scott for the standard -calculus as the appropriate notion of categorical model for the calculus, see Section 5.2 of [5].

The gist of our approach is that the Geometry of Interaction interpretation of a -term in Abramsky’s model of partial involutions is “dual” to the principal type of that term w.r.t. the simple types discipline for a linear/affine -calculus.

In particular, we define an algorithm which, given a principal type of a -term, reads off the partial involution corresponding to the interpretation of that term. Conversely, we show how to extract a principal type from a partial involution, possibly not corresponding to any -term. Moreover, we show that the principal type of an affine -term provides a dual characterisation of the partial involution interpreting the term in Abramsky’s model. The overall effect of the GoI notion of application amounts to unifying the left-hand side of the principal type of the operator with the principal type of the operand, and applying the resulting substitution to the right hand side of the operator. Hence, the notion of application between partial involutions, corresponding to -terms and , can be explained as computing the involution corresponding to the principal type of , given the principal types of and .

This analysis, therefore, unveils three conceptually independent, but ultimately equivalent, accounts of application in the -calculus: -reduction, the GoI application of involutions based on symmetric feedback/Girard’s Execution Formula, and unification of principal types. Somehow surprisingly, this equivalence had not been hitherto pointed out.

Our results provide an answer, for the strictly affine part, to the question raised in [1] of characterising the partial involutions (arising from bi-orthogonal pattern matching automata), which are denotations of combinators. We show that these are precisely those partial involutions whose corresponding principal type is the principal type of a -term. In our view, this insight sheds new light on the deep nature of Game Semantics itself.

We prove, furthermore, that the strictly linear combinatory algebra of partial involutions is also a strictly linear -algebra, albeit not a combinatory model, while both the strictly affine combinatory algebra and the affine combinatory algebra are not -algebras. We also show that the last step of Abramsky’s programme, namely the one taking from a linear/affine combinatory algebra to a -algebra, is not immediate, since in general combinatory algebras cannot be quotiented non trivially to obtain -algebras.

In order to check all the necessary equations of -algebras, we implement in Erlang [10, 4] application of involutions, as well compilation of -terms as combinators and their interpreation as involutions.

In the final remarks, we briefly outline how to extend the above results to the full affine -calculus (i.e. the -calculus extended with a -operator and a corresponding pattern-abstraction) w.r.t. an extension of the intersection type discipline with a -constructor. Intersection types originated in [6] and have been utilised in discussing games in a different approach also in [11, 12].

A clarification is in order as far as the use of the term reversible by Abramsky and, hence, in the title of the present, although we do not develop it further here. Abramsky’s algebras provide indeed universal models of reversible computation, but not in the simplistic sense that application between combinators is itself reversible. What is reversible is the evaluation of the partial involution interpreting a combinator. Since the partial involutions interpreting, say 0 and 1, have different behaviours on a simple “tell-tale” word, we can test reversibly

any characteristic function expressed in terms of combinators, without evaluating the overall combinator. The

finitary descriptions of the partial involutions interpreting the combinators, therefore, have full right to be called reversible combinators.

Synopsis. In Section 1, we introduce the strictly linear and strictly affine versions of: combinatory logic, -calculus, combinatory algebra, and combinatory model, and we isolate the equations for the strictly linear and strictly affine combinatory algebras to be -algebras. In Section 1.3, we provide a type discipline for the strictly linear and strictly affine -calculus, and we define a corresponding notion of principal type. In Section 1.4, we recall Abramsky’s combinatory algebra of partial involutions, and we provide a characterisation of partial involutions via principal types, in the strictly affine case. Furthermore, we prove that partial involutions are a strictly linear -algebra but they are not a strictly affine (nor an affine) -algebra. In Section 1.5, we discuss the implementation in Erlang of the application between partial involutions, and compilation and interpretation of -terms. Concluding remarks appear in Section 1.6. The Appendix includes the detailed Erlang programs implementing compilations and effective operations on partial involutions.

## 1.2 Strictly Linear Notions and their Strictly Affine Extensions

First we introduce strictly linear versions of combinatory logic, -calculus, and combinatory algebras. For each notion we also introduce corresponding strictly affine extensions, which include constant operations and the combinator K. These notions are the restrictions of the corresponding notions of combinatory logic and -calculus [5] to the purely linear (affine) terms.

We assume the reader familiar with the basic notations and results in combinatory logic and -calculus, as presented e.g. in [5], and in [1], but we try to be self-contained as much as possible.

###### Definition 1 (Strictly Linear (Affine) Combinatory Logic).

The language of strictly linear (affine) combinatory logic () is generated by variables and constants, which include the distinguished constants (combinators) (and in the affine case) and it is closed under application, i.e.:
for
Combinators satisfy the following equations (we associate to the left and omit it when clear from the context):

where denote terms of combinatory logic.

###### Definition 2 (Strictly Linear (Affine) Lambda Calculus).

The language () of the strictly linear (affine) -calculus, i.e-calculus (-calculus) is inductively defined from variables , constants , and it is closed under the following formation rules:
:
:
where means that the variable appears free in exactly once.
where means that the variable appears free in at most once.

The rules of the -calculus (-calculus) are the restrictions of the standard -rule and -rule to strictly linear (affine) abstractions, namely:

.

.

All the remaining rules are the standard rules which make a congruence.

###### Proposition 1.

Well-formedness in (), i.e. strictly linear (affine) -abstractions are preserved under -reduction. The corresponding reduction calculi are Church-Rosser.

###### Proof.

Routine. ∎

In the sequel of this section, for conciseness, we discuss only the -calculus, since the corresponding notions/results carry over straightforwardly to the strictly linear version by simple restriction.

We start by specialising to the affine case the results in [5] on the encoding of -calculus into combinatory logic.

###### Definition 3.

We define two homomorphisms w.r.t. application:
(i) , given a term of , yields the term of obtained from by replacing each combinator with the corresponding -term as follows

(ii) , given a term , replaces each -abstraction by a -abstraction. Terms with -abstractions amount to -terms via the Abstraction Operation defined below.

###### Definition 4 (Strictly Affine Abstraction Operation).

The following operation, defined by induction on , provides an encoding of -calculus into :
, for ,

###### Theorem 1 (Strictly Affine Abstraction Theorem).

For all terms , .

###### Proof.

By strightforward induction on the definition of . ∎

The notion of strictly linear (affine) combinatory algebra, or BCI-algebra (BCK-algebra) is the restriction of the notion of combinatory algebra to strictly linear (affine) combinatory logic:

###### Definition 5 (Strictly Linear (Affine) Combinatory Algebra, Bci-algebra (Bck- algebra)).

(i) A strictly linear (affine) combinatory algebra, SLCA, (SACA) is an applicative structure , and distinguished elements (combinators) (and in the affine case) satisfying the following equations: for all ,

 Bxyz=Ax(yz) Ix=Ax Cxyz=A(xz)y Kxy=Ax

(ii) For a strictly linear (affine) combinatory algebra , we define as the natural interpretation of closed terms of () into .
(iii) For a strictly linear (affine) combinatory algebra , we define the set of strictly linear (affine) combinatory terms as the extension of () with constants for .

In what follows, when clear from the context, we will simply write in place of .

As we did earlier for the syntactic notions, we will discuss semantic notions only for the strictly affine case. If not stated explicitly, the corresponding notions/theorems carry over straightforwardly, mutatis mutandis, to the strictly linear case.

First we introduce strictly affine -algebras. These were originally introduced by D. Scott for standard -calculus as the appropriate notion of categorical model for the calculus, see Definition 5.2.2(i) of [5].

###### Definition 6 (Strictly Affine λ-algebra).

A SACA is a strictly affine -algebra if, for all closed ,

 ⊢(M)λA=λA(N)λA ⟹ [[M]]A=[[N]]A ,

where denotes provable equivalence on -terms, and denotes (by abuse of notation) the natural extension to terms in of the interpretation .

Given a BCIK-algebra, there exists a smallest quotient giving rise to a (possibly trivial) strictly affine -algebra, namely:

###### Definition 7.

Let be a SACA. For all , we define if and only if there exist closed such that , , and .

We have:

###### Proposition 2.

(i) Not all SACA’s are strictly affine -algebras.
(ii) Let be a SACA. Then the quotient is a strictly affine -algebra.
(iii) Not all non-trivial SACA’s can be quotiented to a non-trivial strictly affine -algebra.

###### Proof.

(i) A trivial example is the closed term model of strictly affine combinatory logic, i.e. the quotient of closed terms under equality, e.g. CKK I. A more subtle example is the algebra of partial involutions discussed in Section 1.4.
(ii) is a congruence w.r.t. application, since is a congruence. Then the thesis follows from definitions.
(iii) Consider the closed term model of standard combinatory algebra induced by the equations and . This is clearly a SACA. is the standard combinator from Combinatory Logic, see e.g[5]. The lhs’s are terms reducing to themselves, and thus can be consistently (i.e. without producing a trivial model) indipendently equated to whatever; but they are equated to each other in any strictly affine -algebra. Hence any quotient of this term model to a strictly affine -algebra is trivial, because . In the strictly linear case the argument has to be modified by taking the second equation to be e.g. ∎

We give now the notion of strictly affine combinatory model. The corresponding one for standard -calculus was introduced by A. Meyer in his seminal paper [19].

###### Definition 8 (Strictly Affine Combinatory λ-model).

A SACA is a strictly affine combinatory -model if there exists a selector combinator such that, for all , and .

###### Proposition 3.

Not all strictly affine -algebras are strictly affine combinatory -models.

###### Proof.

In the case of the standard combinatory logic, and hence strictly affine combinatory logic, this is implied by the well known conjecture of Barendregt on the failure of the -rule, finally disproved by G. Plotkin using universal generators, (see [5], Section 17.3-4). Theorem 6 below provides such a counterexample for the strictly linear case, namely the algebra of partial involutions . ∎

Curry was the first to discover that -algebras have purely equational definitions

. We give corresponding results for strictly linear and affine combinatory logic, which, although natural, are probably original. The significance of the following theorem is that a finite number of equations involving combinators,

, are enough to ensure that the congruence on -terms is closed under the -rule, as a rule of proof, namely if then .

###### Theorem 2.

A SACA satisfying the following sets of equations is a strictly affine -algebra:

•  B=λ∗xyz.x(yz)=λ∗xyz.Bxyz C=λ∗xyz.(xz)y=λ∗xyz.Cxyz I=λ∗x.x=λ∗x.Ix K=λ∗xy.x=λ∗xy.Kxy
• equations for to hold:

• equations for to hold:

• for to hold:

• for to hold :

• 2 more equations are necessary for in dealing with over axioms:

###### Proof.

(Sketch) The proof follows closely the argument in [5], Section 7.3. The equations allow for proving that is closed under the -rule. For each combinator we have therefore as many equations as possible branches in the Abstraction Operation. At the very end, suitable -abstractions need to be carried out in order to remove the parameters. ∎

The corresponding theorem in the strictly linear case is obtained by deleting all the equations referring to K.

## 1.3 Strictly Linear and Affine Type Discipline for the λ-calculus

In this section we introduce the key type-theoretic tools for understanding the fine structure of partial involutions, namely principal simple type schemes. Principal types were introduced by Hindley see e.g[17] but with a different purpose. We discuss the strictly linear and strictly affine cases separately, because they exhibit significantly different properties.

###### Definition 9 (Simple Types).

, where denotes a type variable.

###### Definition 10 (Strictly Linear Type Discipline).

The strictly linear type system for the -calculus is given by the following set of rules for assigning simple types to terms of . Let denote environments, i.e. sets of the form , where each variable in occurs exactly once:

.

We introduce now the crucial notion of principal type scheme:

###### Definition 11 (Principal Type Scheme).

Given a -term , the judgement denotes that is the principal type scheme of :

where gives the most general unifier, and it is defined (in a standard way) below. By abuse of notation, denotes also the substitution on contexts induced by .

###### Definition 12 (MGU(σ,τ)).

Given two types and , the partial algorithm yields a substitution on type variables (the identity almost everywhere) such that :

where denotes composition between the extensions of the substitutions to the whole set of terms; denotes the identical substitution.

As is well known, the above algorithm yields a substitution which factors any other unifier, see e.g[20].

The following theorem, which can be proved by induction on derivations, connects the systems defined above.

###### Theorem 3.

For all :
(i) if and are derivable, then and , i.e. and .
(ii) if is derivable, then each type variable occurs at most twice in .
(iii) if , then, for all substitutions such that each type variable occurs at most twice in , ;
(iv) if , then there exists a derivation and a type substitution , such that and .

Here are some well known examples of principal types:

 I λx.x α→α B λxyz.x(yz) (α→γ)→(β→α)→β→γ C λxyz.xzy (α→β→γ)→β→α→γ
###### Theorem 4 (Strictly Linear Subject Conversion).

Let , , and , then .

###### Proof.

First one proves subject conversion for , i.e.:
. This latter fact follows from:
,
which can be easily proved by induction on .
Now, let and . Then, by Theorem 3(iii), , and by subject conversion of , . Hence, by Theorem 3(iv), there exist such that and , . But then, by Theorem 3(iii), , and by subject conversion of , . Hence, by Theorem 3(iv), there exist such that and , . Finally, by Theorem 3(i), and , and hence also and . ∎

### 1.3.1 The Strictly Affine Case: Discussion

The extension to the -calculus of Definition 10 is apparently unproblematic. We can just add to the natural rule
and its counterpart to , namely     .
However, while we get type assignment systems which satisfy the extension of Theorem 3 to the affine case, the affine version of Theorem 4, i.e. subject conversion, fails. Namely, we cannot derive , but only , which is an instance of the former. But we have . This is the key reason for the failure of the Affine Combinatory Algebra defined in Section 1.4 to be a strictly affine -algebra.

## 1.4 Abramsky’s Model of Reversible Computation

S. Abramsky, in [1], impressively exploits the connection between automata and strategies and introduces various reversible universal models of computation. Building on earlier work, e.g[3, 16], S. Abramsky defines models arising from Geometry of Interaction (GoI) situations, consisting of history-free strategies. He discusses , the model of partial injections and , its substructure consisting of partial involutions. In particular, S. Abramsky introduces notions of reversible pattern-matching (bi-orthogonal) automata as concrete devices for implementing such strategies. In this paper, we focus on the model of partial involutions, similar results can be obtained for the one of partial injections.

The model of partial involutions yields an affine combinatory algebra. This notion extends that of strictly affine combinatory algebra, introduced in Definition 5, with a operation and extra combinators:

###### Definition 13 (Affine Combinatory Algebra, [1]).

An affine combinatory algebra (ACA), is an applicative structure with a unary (injective) operation !, and combinators satisfying the following equations: for all ,

 Bxyz=x(yz) Ix=x Cxyz=(xz)y Kxy=x Wx!y=x!y!y δ!x=!!x D!x=x F!x!y=!(xy).

Affine combinatory algebras are models of affine combinatory logic, which extends strictly affine combinatory logic, introduced in Definition 1, with !-operator and combinators , , , and .

Partial involutions are defined over a suitable language of moves, and they can be endowed with an ACA structure:

###### Definition 14 (The Model of Partial Involutions P).

(i) , the language of moves, is defined by the signature = {}, = {l,r}, ; terms are output words, while terms are input words (often denoted simply by and );
(ii) is the set of partial involutions over , i.e. the set of all partial injective functions such that ;
(iii) the operation of replication is defined by ;
(iv) the notion of linear application is defined by , where , for (see Fig. 1.1), where “” denotes postfix composition.

Following [1], we make a slight abuse of notation and assume that contains pattern variables for terms. The intended meaning will be clear from the context. In the sequel, we will use the notation , for , to denote the graph of the (finite) partial involution defined by . Again, following [1], we will use the above notation in place of a more automata-like presentation of the partial involution.

###### Proposition 4 ([1], Th.5.1).

can be endowed with the structure of an affine combinatory algebra, , where combinators are defined by the following partial involutions:
: : : : : : : : .

In Section 1.4 we focus on the strictly linear and affine part of the above combinatory algebra, i.e. together with combinators BCI (and K).

### 1.4.1 From Principal Types to Involutions (and back)

Our approach makes it possible to highlight a duality between principal type schemes and the interpretation of strict and affine combinators as involutions in . The following algorithm is a transform which, given a principal type scheme, i.e. a global representation of an object, yields for each type-variable (a component of) an involution:

###### Definition 15.

Given a closed term of -calculus such that , for each type variable , the judgements yield a pair in the graph of a partial involution, if occurs twice in , or an element of , if occurs once in :

where
and similarly for .
We define the partial involution

Vice versa, any partial involution interpreting a closed -term induces the corresponding principal type, inverting the clauses in Definition 15. Notice that so doing we can derive a principal type scheme from any partial involution, not just those which are indeed interpretations of -terms. This remark will be crucial in addressing Abramsky’s open question in Section 1.4.1.

###### Definition 16.

We denote by the interpretation of closed -terms in .

###### Theorem 5.

Given a closed term of , say , the partial involution interpreting , namely , can be read off the principal type scheme of , i.e.  if and only if .

###### Proof.

(Sketch) By induction on the structure of -terms. One can easily check that the thesis holds for combinators B, C, I, K. The inductive step amounts to showing that the notion of application in corresponds to computing the principal type scheme of the application, i.e., for closed -term, if , , , , , fresh, then . This latter fact can be proved by chasing, along the control flow diagram in the definition of application, the behaviour of the MGU. ∎

We are finally in the position of justifying the claims, in the introduction, that our analysis unveils three conceptually independent, but ultimately equivalent, accounts of application in the -calculus: -reduction, the GoI application of involutions based on symmetric feedback/Girard’s Execution Formula, and unification of principal types. In effect, computing the partial involutions , according to Definition 14, amounts by Theorem 5 to unifying the left-hand side of the principal type of with the principal type of , thus computing the principal type of . Using Definition 15 we can finally read off from this type scheme the partial involution .

The following theorem concludes our model theoretic analysis:

###### Theorem 6.

(i) The strictly linear combinatory algebra of partial involutions is a strictly linear -algebra, albeit not a strictly linear combinatory -model.
(ii) The strictly affine combinatory algebra of partial involutions is not a strictly affine -algebra.

###### Proof.

(i) All the equations in Theorem 2 have been verified. In order to avoid errors we used the Erlang [10, 4] program described in Section 1.5.

The proof that there does not exist a term which behaves as a selector combinator, namely that does not exist, follows from Lemma 1 below. The combination of items (i) and (ii) of Lemma 1 below contradicts the unique selection property of , namely we exhibit two objects, i.e and , which have the same empty applicative behaviour, but for any which satisfies , we have . Consider first the terms and , with . Clearly we have . But , by Lemma 1 (ii). Now . Hence , since .
(ii) We have that , but . Namely, while

###### Lemma 1.

Assume that there exists such that , then
(i) , and hence ;
(ii) , and hence has an “additive” applicative behaviour, namely .

###### Proof.

(i) We proceed in stages.

• , for any , otherwise , contradiction.

• , for any , otherwise let with and not unifiable. Then , but . Contradiction.

• , for any , otherwise let , then . Now, since is a selector, , there must occur in a term such that can unify with the l.h.s. of the only pair in the argument, i.e, but then would no longer be a non-ambiguous reversible relation, because by assumption . Contradiction.

• Similar arguments can be used to rule out the remaining cases, i.e and the case where one of the components is garbage, i.e. it has no functional effect.

(ii) We proceed in stages.

• From the very definition of application in , we have immediately that, if , then has an “additive” behaviour under application, because it calls the argument only once.

• because for all either or and , and hence there are no , since is an involution and the rewrite rules are deterministic. To see the above, first notice that for all , otherwise, checking the control-flow diagram, one can easily see that we could not have that . But now, again with just a little case analysis on the control-flow diagram, one can see that there are only two alternatives in and , which give rise to the cases above.
The only case left is . But then we would have that
Hence we have that ,

#### Abramsky’s Question.

In [1], S. Abramsky raised the question: “Characterize those partial involutions which arise from bi-orthogonal pattern-matching automata, or alternatively, those which arise as denotations of combinators”.

Theorem 5 suggests an answer to the above question for the strictly affine fragment, i.e. without the operator in the language of partial involutions. The first issue to address is how to present partial involutions. To this end we consider the language , which is the initial term algebra over the signature for , where is a set of variables, and . Sets of pairs in denote schemata of pairs over , i.e. partial involutions in . As pointed out in the previous section, given a partial involution defined by a finite collection of pairs in , say for , we can synthesize a type from by gradually specifying its tree-like format. Finally we check whether is the principal type of a strictly linear term. We proceed as follows. Each pair in will denote two leaves in the type , tagged with the same type variable. The sequence of ’s and ’s, appearing in the prefix before a variable in a pair , denotes the path along the tree of the type , which is under formation, where the type variable will occur. A fresh type variable is used for each different pair. At the end of this process we might not yet have obtained a complete type. Some leaves in the tree might not be tagged yet, these arise in correspondence of vacuous abstractions. We tag each such node with a new fresh type variable. is finite otherwise we end up with an infinite type, which cannot be the principal type of a finite combinator. The type thus obtained has the property that each type variable occurs at most twice in it. Potentially it is a principal type.

The type is indeed a principal type of a closable -term (i.e. a term which reduces to a closed term) if and only if it is an implication tautology in minimal logic. This can be effectively checked in polynomial-space [21].

To complete the argument we need to show that if the type is inhabited it is indeed inhabited by a term for which it is the principal type.

###### Proposition 5.

If is a type where each type variable occurs at most twice and it is inhabited by the closed term , then there exists such that and .

###### Proof.

(Sketch) If is a closed term, then there exists such that . The variables in will be eventually erased. If inhabits , then by Theorem 3 there exists a substitution such that . For each variable which is substituted by , say , two cases can arise, either occurs twice or once. In the first case we will replace the term variable, say , in in whose type occurs, which must exist, by a suitable long--expansion of . This long -expansion can always be carried out because the typed -expansion rule is a derivable rule in the typing system.
In case the type variable occurs only once in , there is a subterm of which is embedded in a vacuous abstraction. The term is obtained by nesting that subterm with a new vacuous -abstraction applied to a long--expansion of the variable vacuously abstracted in .

Here are two examples. From we can synthesize the type . The identity, , inhabits this type, but the type is not the principal type of the identity. It is instead the principal type of an -expansion of the identity, namely .
From we can synthesize the type . The term inhabits this type which is the principal type of its -expansion .

So we can finally state the result:

###### Theorem 7.

In the strictly affine case, the denotations of combinators in are precisely the partial involutions from which we can synthesize, according to the procedure outlined above, a principal type scheme which is a tautology in minimal logic.

###### Proof.

Use Proposition 5 above in one direction, and Definition 15 and Theorem 5 in the opposite direction. ∎

The above is a satisfactory characterisation because it is conceptually independent both from -terms and from involutions.

## 1.5 Automating Abramsky’s Linear Application

Since the manual verification of complicated equations like those appearing in Theorem 2 is a daunting and error-prone task, we developed an Erlang [10, 4] program to automatize it (see the Appendix for the details). The main components of our program are related to the implementation of the Strictly Affine Abstraction Operator (see Definition 4) and of the linear application operator (see Definition 14) introduced by S. Abramsky in [1].

There are several reasons behind the choice of Erlang: expressive pattern matching mechanisms, avoidance of side effects thanks to one-time assignment variables, powerful libraries for smooth handling of lists, tuples etc. However, other functional languages can be an effective and viable choice as well.

Rules can be written as, e.g (i.e., the representation of combinator I as a partial involution). For convenience, we allow the user to avoid specifying parentheses where their occurrence can be automatically inferred like in, e.g., . Moreover, we allow the user to write instead of .

For instance, starting from a string representing the three rules of combinator B (i.e., "rrrX<->lrX, llX<->rlrX, rllX<->rrlX"111In our implementation we actually use capital letters or strings with initial capital letter to denote variables, according to Erlang conventions.), we obtain the following internal representation (each rule with <-> yields two internal rules corresponding to the two possible directions of rewriting, since it is more convenient for coding purposes):

[{{r,{r,{r,{var,"X"}}}},{l,{r,{var,"X"}}}},
{{l,{r,{var,"X"}}},{r,{r,{r,{var,"X"}}}}},
{{l,{l,{var,"X"}}},{r,{l,{r,{var,"X"}}}}},
{{r,{l,{r,{var,"X"}}}},{l,{l,{var,"X"}}}},
{{r,{l,{l,{var,"X"}}}},{r,{r,{l,{var,"X"}}}}},
{{r,{r,{l,{var,"X"}}}},{r,{l,{l,{var,"X"}}}}}
]


Indeed, we can compute the composition (compose(F,G)) of two involutions and as the set of rules