Functional Pearl: The Distributive λ -Calculus
aa r X i v : . [ c s . L O ] J u l Functional Pearl: the Distributive λ -Calculus Beniamino Accattoli and Alejandro D´ıaz-Caro , , Inria & LIX, ´Ecole Polytechnique, UMR 7161, Palaiseau, France [email protected] CONICET-Universidad de Buenos Aires. Instituto de Ciencias de la Computaci´on.Buenos Aires, Argentina. Departamento de Ciencia y Tecnolog´ıa. Universidad Nacional de Quilmes,Bernal, BA, Argentina [email protected]
Abstract.
We introduce a simple extension of the λ -calculus with pairs—called the distributive λ -calculus—obtained by adding a computationalinterpretation of the valid distributivity isomorphism A ⇒ ( B ∧ C ) ≡ ( A ⇒ B ) ∧ ( A ⇒ C ) of simple types. We study the calculus both as anuntyped and as a simply typed setting. Key features of the untyped cal-culus are confluence, the absence of clashes of constructs, that is, evalu-ation never gets stuck, and a leftmost-outermost normalization theorem,obtained with straightforward proofs. With respect to simple types, weshow that the new rules satisfy subject reduction if types are consideredup to the distributivity isomorphism. The main result is strong nor-malization for simple types up to distributivity. The proof is a smoothvariation over the one for the λ -calculus with pairs and simple types. Keywords: λ -calculus, type isomorphisms, rewriting, normalization The topic of this paper is an extension of the λ -calculus with pairs, deemed the distributive λ -calculus , obtained by adding a natural computational interpreta-tion of the distributivity isomorphism of simple types: A ⇒ ( B ∧ C ) ≡ ( A ⇒ B ) ∧ ( A ⇒ C ) (1)Namely, one extends the calculus with the following commutation rules: h t, s i u → h tu, su i π i ( λx.t ) → λx.π i t i = 1 , λ -calculus is a naturalsystem, and contributions are in both the typed and untyped settings.We study the untyped setting to show that our calculus makes perfect sensealso without types. This is to contrast with System I, another calculus providingcomputational interpretations of type isomorphisms recently introduced by D´ıaz-Caro and Dowek [8], that does not admit an untyped version—the relationshipbetween the two is discussed below. Accattoli & D´ıaz-Caro
Typing Up to Distributivity and Subject Reduction.
At the typed level, the keypoint is that simple types are here considered up to distributivity . In this way,the apparently ad-hoc new rules do satisfy the subject reduction property.Consider for instance π ( λx.t ): working up to the distributivity isomorphism—so that isomorphic types type the same terms—the subterm λx.t may now haveboth the arrow type A ⇒ ( B ∧ C ) and the conjunctive type ( A ⇒ B ) ∧ ( A ⇒ C ),so that π ( λx.t ) can be typed with A ⇒ B . Distributivity also allows for thetype to be preserved—that is, subject reduction holds. According to the arrowtype, indeed, the body t of the abstraction has type B ∧ C and thus the reductof the commutation rule π ( λx.t ) → λx.π t can also be typed with A ⇒ B . Theother commutation rule can be typed similarly. Overview of the Paper.
For the untyped setting, we show that the distributive λ -calculus is confluent, its closed normal forms are values, and it has a leftmost-outermost normalization theorem, exactly as for the λ -calculus (without pairs).With respect to types, we show subject reduction and strong normalizationof the distributive λ -calculus with simple types up to distributivity. The Pearl.
The proofs in the paper are remarkably smooth. The properties forthe untyped calculus are immediate. Confluence follows by the fact that thecalculus is an orthogonal higher-order rewriting system [1, 9, 10]. The leftmost-outermost normalization theorem, similarly, follows by an abstract result byvan Ramsdonk [12], because the calculus verifies two additional properties oforthogonal higher-order rewriting system from which leftmost-outermost nor-malization follows. Finally, the fact that closed normal forms are values—whatwe call progress —is obtained via a straightforward induction.For the typed setting, the given argument for subject reduction goes smoothlythrough. The main result of the paper is that the simply typed distributive λ -calculus is strongly normalizing. The proof follows Tait’s reducibility method.In particular, the interpretation of types is the same at work for the λ -calculuswith pairs and projections (that is, without distributive rules). The key pointis to prove that the two sides of the distributivity isomorphism have the sameinterpretation. This can be proved with two easy lemmas. Everything else is asin the case without distributive rules. Type Isomorphisms and System I.
As shown by Bruce, Di Cosmo and Longo [4]the isomorphisms of simple types can be completely characterized by distribu-tivity (that is, equation (1)) plus the following three (for more about type iso-morphisms see Di Cosmo’s short survey [6] or book [5]):
Commutativity A ∧ B ≡ B ∧ A Associativity ( A ∧ B ) ∧ C ≡ A ∧ ( B ∧ C ) Currying ( A ∧ B ) ⇒ C ≡ A ⇒ ( B ⇒ C )At the inception of D´ıaz-Caro and Dowek’s System I [8], there is the idea ofturning all these type isomorphisms into computational principles. Precisely, unctional Pearl: the Distributive λ -Calculus 3 these isomorphisms give rise to some equations t ∼ s between terms, such as h t, s i ∼ h s, t i for the commutativity of conjunctions, for instance. The result ofD´ıaz-Caro and Dowek is that the λ -calculus with pairs extended with 5 suchequations (distributivity induces 2 equations) is strongly normalizing modulo. System I Rests on Types.
The equations of System I, while well behaved withrespect to termination, come with two drawbacks. First, the calculus is notconfluent. Second, the definitions of the rewriting rules and of the equationsdepend on types, so that it is not possible to consider an untyped version. Bothissues are easily seen considering the commutativity equation. Consider t = π h s, u i . If pairs are commutative, t can rewrite to both s and u : s ← π h s, u i ∼ π h u, s i → u which breaks both confluence and subject reduction (if s has type A and u hastype B ). To recover subject reduction, one uses a projection π A indexed by atype rather than a coordinate so that (if s has type A and u has type B ): s ← π A h s, u i ∼ π A h u, s i → s note that in order to apply the rule we need to know the type of s . Moreover,confluence is not recovered—if both s and u have type A then the result maynon-deterministically be s or u , according to System I. D´ıaz-Caro and Dowekin [8] indeed adopt a sort of proof-irrelevant point of view, for which subjectreduction is more important than confluence for normalization: types guaranteethe existence of a result (strong normalization), and this guarantee is stable byevaluation (subject reduction), while uniqueness of the result is abandoned (noconfluence). System I and the Distributive λ -Calculus. The two issues of System I are notdue only to the commutativity isomorphism, as the currying and associativityisomorphisms also contribute to them. The distributive λ -calculus essentiallyrestricts System I by keeping only the distributive isomorphism, which is theonly one not hindering confluence and the possibility of defining the calculusindependently from the type system.To be precise, we do not simply restrict to distributivity, but we also changeits computational interpretation. First, we do not consider equations, but rewrit-ing rules, and also we consider the rule π i ( λx.t ) → λx.π i t that was not part ofSystem I , while we remove both equations: λx. h t, s i ∼ h λx.t, λx.s i π i ( ts ) ∼ λx. ( π i t ) s i = 1 , λ -calculus is instead trivially confluent, because it is an orthogonal higher-orderrewriting system, and all such systems are confluent. Such a rule was however present in an early version of System I, see [7]. Accattoli & D´ıaz-Caro
To sum up, System I aims at being a maximal enrichment of the λ -calculuswith computation principles induced by type isomorphisms, while the distribu-tive λ -calculus rather is a minimal extension aiming at being as conservativeas possible with respect to the λ -calculus, and in particular at being definablewithout types. Clashes.
Let us point out a pleasant by-product of the distributive rewritingrules that we adopt. A nice property of the λ -calculus is that there can neverbe clashes of constructors. In logical terms, there is only one introduction rule(corresponding to the abstraction constructor) and only one elimination rule (ap-plication) and they are duals, that is, they interact via β -reduction. Extensionsof the λ -calculus usually lack this property. Typically, extending the λ -calculuswith pairs h t, s i (and of course projections π t and π t ) introduces the followingtwo clashes: h t, s i u and π i ( λx.t ), for i = 1 ,
2, where an elimination construc-tor (application or projection) is applied to the wrong introduction rule (pairor abstraction). These clashes are stuck, as there are no rules to remove them,and it is not clear whether it makes any sense to consider such an unrestricted λ -calculus with pairs.Our distributive rules deal exactly with these clashes, removing them bycommuting constructors. Concretely, the absence of clashes materializes as a progress property: all closed normal forms are values, that is, their outermostconstructor corresponds to an introduction rule. Related work.
Beyond D´ıaz-Caro and Dowek’s System I, we are aware of onlythree works bearing some analogies to ours. The first one is Arbiser, Miquel,and R´ıos’ λ -calculus with constructors [3], where the λ -calculus is extended withconstructors and a pattern matching construct that commutes with applications.They show it to be confluent and even having a separation theorem akin toBohm’s. The calculus has been further studied in a typed setting by Petit [11],but type isomorphisms play no role in this case.The second related work is A¨ıt-Kaci and Garrigue’s label-selective λ -calculus[2], which considers the λ -calculus plus the only type isomorphism for the im-plication: A ⇒ B ⇒ C ≡ B ⇒ A ⇒ C . In order to avoid losing confluence andsubject reduction, they introduce a labeling system to the arguments, so thatthe application order becomes irrelevant.Last, the untyped distributive λ -calculus coincides with the extensionality-free fragment of Støvring’s λ F P [13]. Støvring uses it as a technical tool to studyconfluence and conservativity of surjective pairing. He points out—as we do—that the calculus is confluent because it is an orthogonal higher-order rewritingsystem, but then he gives nonetheless a proof using Tait-Martin L¨of’s technique. With conjunction, this isomorphism is a consequence of currying and commutativity.unctional Pearl: the Distributive λ -Calculus 5 λ -Calculus The language of the distributive λ -calculus λ dist is given by the following gram-mar: Terms t, s, u ::= x | λx.t | ts | h t, s i | π t | π t The rewriting rules are first given at top level:
Rules at top level
Standard rules ( λx.t ) s β t { x (cid:0) s } π i h t , t i 7→ π i t i i = 1 , Distributive rules h t, s i u @ × h tu, su i π i ( λx.t ) π λ λx.π i t i = 1 , h·i : Contexts
C, D, E ::= h·i | λx.C | Ct | tC | h C, t i | h t, C i | π C | π C The operation of replacing the hole h·i of a context C with a given term t iscalled plugging and it is noted C h t i . As usual, plugging can capture variables.Now we can define the contextual closure of the top level rules. Contextual closure t a sC h t i → a C h s i a ∈ { β, π , π , @ × , π λ } The contextual closure is given with contexts as a compact way of expressing theclosure of all rules by all constructors, in the proofs sometimes we consider theclosure by a single constructor. We use → dist for the union of all the rewritingrules defined above. Values and Neutral Terms.
Two subsets of terms play a special role in the follow-ing, terms whose outermost constructor corresponds to a logical introduction rule(values) and elimination rule (neutral terms), plus—in both cases—variables.
Definition 2.1 (Values and neutral terms).–
Values : a term is value if it is either a variable x , an abstraction λx.t , or apair h t, s i . – Neutral terms : a term is neutral if it is either a variable x , an application ts , or a projection π i t . Sometimes, neutral terms are also required to be normal. Here they are not.
Accattoli & D´ıaz-Caro
Progress.
The first property that we show is that all closed normal forms are values . Please note that evaluation is not call-by-value, here the aim is simply tostress that in the distributive λ -calculus there are no clashes, i.e. closed-normalneutral terms. Proposition 2.2 (Progress). If t is a closed normal form then it is a value.Proof. By induction on t . Cases: – Variable : impossible, since t is closed. – Abstraction or pair : then the statement holds. – Application , i.e. t = su . Since t is normal and closed, so is s . Then, by i.h. s is a value, that is, either an abstraction or a pair. In the first case, rule β applies and in the second case rule @ × applies. Hence, in any case t is not innormal form, absurd. Therefore, t cannot be an application in normal form. – Projection , i.e. t = π i s . Since t is normal and closed, so is s . Then, by i.h. s is a value, that is, either an abstraction or a pair. In the first case, rule π λ applies and in the second case rule π i applies. Therefore, t cannot be aprojection in normal form. Substitution.
For the proof of strong normalization we shall need a basic propertyof substitution with respect to rewriting steps.
Lemma 2.3 (Substitutivity of → dist ). Left substitutivity : if t → dist t ′ then t { x (cid:0) s } → dist t ′ { x (cid:0) s } .2. Right substitutivity : if s → dist s ′ then t { x (cid:0) s } → ∗ dist t { x (cid:0) s ′ } .Proof. The first point is an easy induction on the relation → dist , the second oneon t . Details in the Appendix. Confluence.
The distributive λ -calculus is an example of orthogonal higher-orderrewriting system [1,9,10], that is a class of rewriting systems for which confluencealways holds, because of the good shape of its rewriting rules. Theorem 2.4 (Confluence).
The distributive λ -calculus is confluent, that is,if s ∗ dist ← t → ∗ dist s then there exists u such that s → ∗ dist u ∗ dist ← s .Leftmost-Outermost Normalization. A classic property of the ordinary λ -calculusis the (untyped) normalization theorem for leftmost-outermost (shortened toLO) reduction. The theorem states that LO reduction → LO is normalizing , thatis, → LO reaches a normal form from t whenever t has a β reduction sequenceto a normal form. The definition of LO reduction → LO on ordinary λ -terms isgiven by: LO reduction for the ordinary λ -calculus ( λx.t ) s → LO t { x (cid:0) s } t → LO s t is neutral tu → LO sut → LO sλx.t → LO λx.s u is neutral and normal t → LO sut → LO us unctional Pearl: the Distributive λ -Calculus 7 By exploiting an abstract result by van Ramsdonk, we obtain a LO normalizationtheorem for λ dist for free. Leftmost-outermost reduction → LO can indeed bedefined uniformly for every orthogonal rewriting system. For the distributive λ -calculus we simply consider the previous rules with respect to terms in λ dist , andadd the following clauses: LO reduction clauses for pairs and projections π i h t , t i → LO t i h t, s i u → LO h tu, su i π i ( λx.t ) → LO λx.π i tt → LO sπ i t → LO π i s t → LO s h t, u i → LO h s, u i u is normal t → LO s h u, t i → LO h u, s i In [12], van Ramsdonk shows that every orthogonal higher-order rewriting sys-tem that is fully extended and left normal has a LO normalization theorem .These requirements, similarly to orthogonality, concern the shape of the rewrit-ing rules—see [12] for exact definitions. Verifying that the distributive λ -calculusis fully extended and left normal is a routine check, omitted here to avoid definingformally higher-order rewriting systems. The theorem then follows. Theorem 2.5 (Leftmost-outermost normalization). If t → ∗ dist s and s is → dist -normal then t → ∗ LO s . In this section we define the simply typed distributive λ -calculus and provesubject reduction. The type system.
The grammar of types is given by A ::= τ | A ⇒ A | A ∧ A where τ is a given atomic type.The relation ≡ denoting type isomorphism is defined by A ≡ A B ≡ AA ≡ B A ≡ B B ≡ CA ≡ C A ⇒ B ∧ C ≡ ( A ⇒ B ) ∧ ( A ⇒ C ) A ≡ CA ⇒ B ≡ C ⇒ B B ≡ CA ⇒ B ≡ A ⇒ C A ≡ CA ∧ B ≡ C ∧ B B ≡ CA ∧ B ≡ A ∧ C Precisely, on the one hand van Ramsdonk in [12] shows that full extendedness impliesthat outermost-fair strategies are normalizing. On the other hand, left-normality im-plies that leftmost-fair rewriting is normalizing. Then, the LO stategy is normalizing. Accattoli & D´ıaz-Caro
The typing rules are:
Γ, x : A ⊢ x : A ( ax ) Γ ⊢ t : A A ≡ BΓ ⊢ t : B ( ≡ ) Γ, x : A ⊢ t : BΓ ⊢ λx.t : A ⇒ B ( ⇒ i ) Γ ⊢ t : A ⇒ B Γ ⊢ s : BΓ ⊢ ts : B ( ⇒ e ) Γ ⊢ t : A Γ ⊢ s : BΓ ⊢ h t, s i : A ∧ B ( ∧ i ) Γ ⊢ t : A ∧ BΓ ⊢ π t : A ( ∧ e ) Γ ⊢ t : A ∧ BΓ ⊢ π t : B ( ∧ e )Note rule ≡ : it states that if t is typable with A then it is also typable with B for any type B ≡ A . It is the key rule for having subject reduction for thedistributive λ -calculus. Subject reduction.
The proof of subject reduction is built in a standard way,from a generation and a substitution lemma, plus a straightforward lemma onthe shape of isomorphic types.
Lemma 3.1 (Generation).
Let Γ ⊢ t : A . Then,1. If t = x , then Γ = Γ ′ , x : B and B ≡ A .2. If t = λx.s , then Γ, x : B ⊢ s : C and B ⇒ C ≡ A .3. If t = h s , s i , then Γ ⊢ s i : B i , for i = 1 , , and B ∧ B ≡ A .4. If t = su , then Γ ⊢ s : B ⇒ A , Γ ⊢ u : A .5. If t = π i s , then Γ ⊢ s : B ∧ B and B i = A .Proof. Formally, the proof is by induction on Γ ⊢ t : A , but we rather give aninformal explanation. If t is a value ( x , λx.s , or h s , s i ) then the last rule maybe either the corresponding introduction rule or ≡ , and the statement follows.If t is not a value there are two similar cases. If t = su what said for valuesstill holds, but we can say something more. Note indeed that if A ≡ C and Γ ⊢ s : B ⇒ C then since C is a sub-formula of B ⇒ C we can permute the ≡ rule upwards and obtain Γ ⊢ s : B ⇒ A . Similarly if t = π i s , which is also anelimination rule. Lemma 3.2 (Substitution). If Γ, x : A ⊢ t : B and Γ ⊢ s : A , then Γ ⊢ t { x (cid:0) s } : B .Proof. Easy induction on the derivation of
Γ, x : A ⊢ t : B . Details in theAppendix. Lemma 3.3 (Equivalence of types).
1. If A ∧ B ≡ C ∧ D then A ≡ C and B ≡ D .2. If A ⇒ B ≡ C ⇒ D then A ≡ C and B ≡ C .3. If A ∧ B ≡ C ⇒ D then D ≡ D ∧ D , A ≡ C ⇒ D and B ≡ C ⇒ D .Proof. By induction on the definition of ≡ . unctional Pearl: the Distributive λ -Calculus 9 Theorem 3.4 (Subject reduction). If Γ ⊢ t : A and t → dist s , then Γ ⊢ s : A .Proof. By induction on t → dist s using the generation lemma (Lemma 3.1). Wefirst deal with the cases of the rules applied at top level: – β -rule : ( λx.t ) s β t { x (cid:0) s } . By generation, Γ ⊢ λx.t : B ⇒ A , Γ ⊢ s : B .Again by generation, Γ, x : C ⊢ t : D , with C ⇒ D ≡ B ⇒ A , so byLemma 3.3, C ≡ B and D ≡ A . Then, by rule ( ≡ ) we have Γ ⊢ s : C ,and so, by the substitution lemma (Lemma 3.2) we have Γ ⊢ t { x (cid:0) s } : D ,therefore, by rule ( ≡ ), Γ ⊢ t { x (cid:0) s } : A . – Projection : π i h t , t i 7→ π i t i . By generation, Γ ⊢ h t , t i : B ∧ B with B i = A . By generation again, Γ ⊢ t i : C i with C ∧ C ≡ B ∧ B . Therefore,by rule ( ≡ ), Γ ⊢ t i : A . – Pair-application : h t, s i u @ × h tu, su i . By generation, Γ ⊢ h t, s i : B ⇒ A and Γ ⊢ u : B . By generation again, Γ ⊢ t : C and Γ ⊢ s : D with C ∧ D ≡ B ⇒ A . By Lemma 3.3, A ≡ A ∧ A , C ≡ B ⇒ A and D ≡ B ⇒ A .Then, Γ ⊢ t : CΓ ⊢ t : B ⇒ A ( ≡ ) Γ ⊢ u : BΓ ⊢ tu : A ( ⇒ e ) Γ ⊢ s : DΓ ⊢ s : B ⇒ A ( ≡ ) Γ ⊢ u : BΓ ⊢ su : A ( ⇒ e ) Γ ⊢ h tu, su i : A ∧ A ( ∧ i ) Γ ⊢ h tu, su i : A ( ≡ ) – Projection-abstraction : π i ( λx.t ) π λ λx.π i t . By generation, Γ ⊢ λx.t : B ∧ B with B i = A . By generation again, Γ, x : C ⊢ t : D , with C ⇒ D ≡ B ∧ B . Then, by Lemma 3.3, D ≡ D ∧ D , B ≡ C ⇒ D , and B ≡ C ⇒ D .Then, A = C ⇒ D i , and so, Γ, x : C ⊢ t : DΓ, x : C ⊢ t : D ∧ D ( ≡ ) Γ, x : C ⊢ π i t : D i ( ∧ e i ) Γ ⊢ λx.π i t : C ⇒ D i ( ⇒ i )The inductive cases are all straightforward. We give one of them, the othersare along the same lines. Let λx.t → dist λx.s because t → dist s . By generation, Γ, x : B ⊢ t : C , with B ⇒ C ≡ A . By i.h. , Γ, x : B ⊢ s : C , so, by rules ( ⇒ i )and ( ≡ ), Γ ⊢ λx.s : A . Here we prove strong normalization using Tait’s reducibility technique. The keypoint shall be proving that the interpretation of types is stable by distributivity.
Definition 4.1 (Basic definitions and notations).–
SN terms : we write SN for the set of strongly normalising terms. – One-step reducts : the set { s | t → dist s } of all the one-step reducts of a term t is noted Red ( t ) . – Evaluation length : eval ( t ) is the length of the longest path starting from t toarrive to a normal form – Size : size ( t ) is the size of the term t defined in the usual way.The interpretation of types. The starting point of the reducibility technique isthe definition of the interpretation of types, which is the standard one.
Definition 4.2 (Interpretation of types). J τ K := SN J A ⇒ B K := { t | ∀ s ∈ J A K , ts ∈ J B K } J A ∧ B K := { t | π t ∈ J A K and π t ∈ J B K } The reducibility properties.
The next step is to prove the standard three prop-erties of reducibility. The proof is standard, that is, the distributive rules do notplay a role here.
Lemma 4.3 (Properties of the interpretation).
For any type A the follow-ing properties of its interpretation are valid. CR1 J A K ⊆ SN . CR2 If t ∈ J A K and t → dist s , then s ∈ J A K . CR3 If t is neutral and Red ( t ) ⊆ J A K , then t ∈ J A K .Proof. CR1
By induction on A . Cases: – J τ K = SN . – Let t ∈ J A ⇒ B K . Then, for all s ∈ J A K , we have ts ∈ J B K . By i.h. , J B K ⊆ SN , so ts ∈ SN , and hence, t ∈ SN . – Let t ∈ J A ∧ B K . Then, in particular, π t ∈ J A K . By i.h. , J A K ⊆ SN , so π t ∈ SN , and hence, t ∈ SN . CR2
By induction on A . Cases: – Let t ∈ J τ K = SN . Then if t → dist s , we have s ∈ SN = J τ K . – Let t ∈ J A ⇒ B K . Then, for all u ∈ J A K , we have tu ∈ J B K . By i.h. on B ,since tu → dist su , we have su ∈ J B K and so s ∈ J A ⇒ B K . – Let t ∈ J A ∧ A K . Then, π i t ∈ J A i K , for i = 1 ,
2. By i.h. on A i , since π i t → dist π i s , we have π i s ∈ J A i K and so s ∈ J A ∧ A K . CR3
By induction on A . Let t be neutral. Cases: – Let
Red ( t ) ⊆ J τ K = SN . Then t ∈ SN = J τ K . – Let
Red ( t ) ⊆ J A ⇒ B K . Then for each t ′ ∈ Red ( t ), we have that for all s ∈ J A K , t ′ s ∈ J B K . Since ts is neutral, if we show that Red ( ts ) ⊆ J B K then the i.h. on B gives ts ∈ J B K and so t ∈ J A ⇒ B K .Since, by CR1 on J A K , we have s ∈ SN , we show that Red ( ts ) ⊆ J B K bya second induction on size ( s ). The possible reducts of ts are: • t ′ s , with t → dist t ′ , which is in J B K by hypothesis, unctional Pearl: the Distributive λ -Calculus 11 • ts ′ , with s → dist s ′ , then by the second induction hypothesis Red ( ts ′ ) ⊆ J B K and by i.h. ts ′ ∈ J B K .Note that since t is neutral there are no other reductions from ts . – Let
Red ( t ) ⊆ J A ∧ A K . Then for each t ′ ∈ Red ( t ), we have that π i t ′ ∈ J A i K , for i = 1 ,
2. We show that
Red ( π i t ) ⊆ J A i K , which—since π i t isneutral—by i.h. implies π i t ∈ J A i K , and so t ∈ J A ∧ A K .Since t is neutral, its only possible reducts have the form π i t ′ , with t → dist t ′ , which are in J A i K by hypothesis. Stability of the interpretation by isomorphism.
Finally, we come to the pointwhere distributivity plays a role. Here we prove that the interpretation of typesis stable by ≡ , that is, if A ≡ B then J A K = J B K . We need an auxiliary lemmastating a sort of stability by anti-reduction of J A K with respect to the standardrewriting rules of β and projection. Lemma 4.4.
1. If t, s ∈ SN and t { x (cid:0) s } ∈ J A K then ( λx.t ) s ∈ J A K .2. If t i ∈ J A i K then π i h t , t i ∈ J A i K , for i = 1 , .Proof.
1. By induction on eval ( t ) + eval ( s ). We show that Red (( λx.t ) s ) ⊆ J A K , andobtain the statement by CR3. Cases: – ( λx.t ) s → dist ( λx.t ′ ) s with t → dist t ′ . We can apply the i.h. becauseif t → dist t ′ then t { x (cid:0) s } → dist t ′ { x (cid:0) s } by left substitutivity of → dist (Lemma 2.3.1), and t ′ { x (cid:0) s } ∈ J A K by CR2. By i.h. , ( λx.t ′ ) s ∈ J A K . – ( λx.t ) s → dist ( λx.t ) s ′ with s → dist s ′ . We can apply the i.h. because if s → dist s ′ then t { x (cid:0) s } → ∗ dist t { x (cid:0) s ′ } by right substitutivity of → dist (Lemma 2.3.2), and t { x (cid:0) s ′ } ∈ J A K by CR2. By i.h. , ( λx.t ) s ′ ∈ J A K . – ( λx.t ) s → β t { x (cid:0) s } , which is in J A K by hypothesis.2. By CR1 we have t i ∈ SN . By induction on eval ( t ) + eval ( t ). The possiblereducts of π i h t , t i are: – t i , because of a → π i step. Then t i ∈ J A i K by hypothesis. – π i h t ′ , t i , with t → dist t ′ . We can apply the i.h. because J A K ∋ t → dist t ′ which is in J A K by CR2. Then π i h t ′ , t i ∈ J A K by i.h. – π i h t , t ′ i , with t → dist t ′ . As the previous case, just switching coordinateof the pair. Lemma 4.5 (Stability by isomorphism). If A ≡ B , then J A K = J B K .Proof. By induction on A ≡ B . The only interesting case is the base case A ⇒ B ∧ B ≡ ( A ⇒ B ) ∧ ( A ⇒ B ). The inductive cases follow immediately fromthe i.h. We prove J A ⇒ B ∧ B K = J ( A ⇒ B ) ∧ ( A ⇒ B ) K by proving the doubleinclusion. – Let t ∈ J A ⇒ B ∧ B K . Then for all s ∈ J A K we have ts ∈ J B ∧ B K , so π i ( ts ) ∈ J B i K (2)We need to prove that ( π i t ) s ∈ J B i K . Since this term is neutral, we provethat Red (( π i t ) s ) ⊆ J B i K and conclude by CR3. By CR1 and (2), t and s arein SN , so we proceed by induction on eval ( t ) + eval ( s ). The possible one-stepreducts fired from ( π i t ) s are: • ( π i t ′ ) s , with t → dist t ′ , then i.h. applies. • ( π i t ) s ′ , with s → dist s ′ , then i.h. applies. • t i s , if t = h t , t i . Since π i ( ts ) = π i ( h t , t i s ) → dist π i h t s, t s i → dist t s ,by (2) and CR2 we have t i s ∈ J B i K . • ( λx.π i u ) s if t = λx.u . Then we can apply Lemma 4.4.1, since we knowthat u and s are SN and that π i ( ts ) = π i (( λx.u ) s ) → β π i u { x (cid:0) s } whichby (2) and CR2 is in J B i K . We obtain ( λx.π i u ) s ∈ J B i K – Let t ∈ J ( A ⇒ B ) ∧ ( A ⇒ B ) K . Then π i t ∈ J A ⇒ B i K , and so for all s ∈ J A K , we have ( π i t ) s ∈ J B i K . By CR1 we have t, s ∈ SN , so we proceed byinduction on eval ( t ) + eval ( s ) to show that Red ( π i ( ts )) ⊆ J B i K , which implies π i ( ts ) ∈ J B i K and so ts ∈ J B ∧ B K , and then t ∈ J A ⇒ B ∧ B K . Thepossible reducts of π i ( ts ) are: • π i ( t ′ s ) with t → dist t ′ , then the i.h. applies. • π i ( ts ′ ) with s → dist s ′ , then the i.h. applies. • π i ( u { x (cid:0) s } ) if t = λx.u . Then since ( π i t ) s ∈ J B i K , we have ( π i λx.u ) s ∈ J B i K and ( π i λx.u ) s → π λ ( λx.π i u ) s → β π i ( u { x (cid:0) s } ), so, by CR2, π i ( u { x (cid:0) s } ) ∈ J B i K . • π i h t s, t s i if t = h t , t i . We apply Lemma 4.4.2, since we have ( π i h t , t i ) s ∈ J B i K and ( π i h t , t i ) s → π i t i s , so, by CR2, t i s ∈ J B i K . We then obtain π i h t s, t s i ∈ J B i K . Adequacy.
The last step is to prove what is usually called adequacy , that is, thattypability of t with A implies that t ∈ J A K , up to a substitution θ playing therole of the typing context Γ . The proof is standard, the distributive rules do notplay any role. Definition 4.6 (Valid substitution).
We say that a substitution θ is validwith respect to a context Γ (notation θ (cid:15) Γ ) if for all x : A ∈ Γ , we have θx ∈ J A K . Lemma 4.7 (Adequacy). If Γ ⊢ t : A and θ (cid:15) Γ , then θt ∈ J A K .Proof. By induction on the derivation of Γ ⊢ t : A . – Γ, x : A ⊢ x : A ( ax ) Since θ (cid:15) Γ, x : A , we have θx ∈ J A K . – Γ, x : A ⊢ t : BΓ ⊢ λx.t : A ⇒ B ( ⇒ i )By i.h. , if θ ′ (cid:15) Γ, x : A , then θ ′ t ∈ J B K . Let s ∈ J A K , we have to provethat θ ( λx.t ) s = ( λx.θt ) s ∈ J B K . By CR1, s, θt ∈ SN , so we proceed by asecond induction on size ( s ) + size ( θt ) to show that Red (( λx.θt ) s ) ⊆ J B K ,which implies ( λx.θt ) s ∈ J B K . The possible reducts of ( λx.θt ) s are: unctional Pearl: the Distributive λ -Calculus 13 • ( λx.t ′ ) s , with θt → dist t ′ , then the second i.h. applies. • ( λx.θt ) s ′ , with s → dist s ′ , then the second i.h. applies. • θt { x (cid:0) s } , then take θ ′ = θ, x s and notice that θ ′ (cid:15) Γ, x : A , so θt { x (cid:0) s } ∈ J B K . – Γ ⊢ t : A ⇒ B Γ ⊢ s : BΓ ⊢ ts : B ( ⇒ e )By i.h. , θt ∈ J A ⇒ B K and θs ∈ J B K , so, by definition, θtθs = θ ( ts ) ∈ J B K . – Γ ⊢ t : A Γ ⊢ t : A Γ ⊢ h t , t i : A ∧ A ( ∧ i )By i.h. , θt i ∈ J A i K , for i = 1 ,
2. By CR1 we have θt i ∈ SN , hence we proceedby a second induction on size ( θt )+ size ( θt ) to show that Red ( π i h θt , θt i ) ⊆ J A K , which, by CR3 implies π i h θt , θt i ∈ J A i K and so h θt , θt i ∈ J A ∧ A K .The possible one-step reducts of π i h θt , θt i are: • π i h t ′ , θt i , with θt → dist t ′ , then the second i.h. applies. • π i h θt , t ′ i , with θt → dist t ′ , then the second i.h. applies. • θt i ∈ J A i K . – Γ ⊢ t : A ∧ A Γ ⊢ π i t : A i ( ∧ e i ) By i.h. , θt ∈ J A ∧ A K , so, by definition, π i ( θt ) = θπ i t ∈ J A i K . – Γ ⊢ t : A A ≡ BΓ ⊢ t : B ( ≡ ) By i.h. , θt ∈ J A K , so, by Lemma 4.5, θt ∈ J B K . Theorem 4.8 (Strong normalisation). If Γ ⊢ t : A , then t ∈ SN .Proof. By Lemma 4.7, if θ (cid:15) Γ , θt ∈ J A K . By CR3, variables—which are neutralterms—are in all the interpretations, and so the identity substitution is valid inany context, in particular, in Γ . Hence, t ∈ J A K . By CR1, J A K ⊆ SN . Hence, t ∈ SN . The Unit Type.
The point of the paper is the fact that the distributive rewritingrules and typing up to distributivity perfectly marry together. The eliminationof clashes, on the other hand, is a nice consequence of our approach that shouldnot be taken too seriously, because it does not scale up, as we now show.Let’s consider the extension of the distributive λ -calculus with the unit type ⊤ and a construct ⋆ of type ⊤ . In this extended setting it is still possible tointerpret distributivity as in the previous sections, and all our results still holds.There are however two new clashes, namely ⋆ u and π i ⋆ . If one makes the furtherstep of eliminating them via new rules and type them up to new isomorphisms,then unfortunately normalization breaks, as we now show.Consider their natural commutation rules: ⋆ u → ⋆ π i ⋆ → ⋆ i = 1 , To have subject reduction along the same lines of what we did, one needs towork up to the following two isomorphisms: A ⇒ ⊤ ≡ ⊤ ⊤ ∧ ⊤ ≡ ⊤ Note that A ⇒ ⊤ ≡ ⊤ has to be valid for any type A , therefore in particular it istrue for ⊤ , giving ⊤ ⇒ ⊤ ≡ ⊤ . Now, unfortunately, one can type the divergingterm Ω := ( λx.xx )( λx.xx ), as the following derivation shows, and in fact all theterms of the ordinary λ -calculus—said differently strong normalization breaks. x : ⊤ ⊢ x : ⊤ ( ax ) x : ⊤ ⊢ x : ⊤ ⇒ ⊤ ( ≡ ) x : ⊤ ⊢ x : ⊤ ( ax ) x : ⊤ ⊢ xx : ⊤ ( ⇒ e ) ⊢ λx.x : ⊤ ⇒ ⊤ ( ⇒ i ) x : ⊤ ⊢ x : ⊤ ( ax ) x : ⊤ ⊢ x : ⊤ ⇒ ⊤ ( ≡ ) x : ⊤ ⊢ x : ⊤ ( ax ) x : ⊤ ⊢ xx : ⊤ ( ⇒ e ) ⊢ λx.x : ⊤ ⇒ ⊤ ( ⇒ i ) ⊢ λx.xx : ⊤ ( ≡ ) ⊢ ( λx.xx )( λx.xx ) : ⊤ ( ⇒ e ) This example also reinforces the fact, already stressed in the introduction, thatinterpretations of type isomorphisms tend to break key properties. Distributivity,instead, is somewhat special, as it admits an interpretation that is conservativewith respect to the properties of the underlying calculus.
Additional Distributivity Rules.
It is possible to add the two following distribu-tive rewriting rules: λx. h t, s i → h λx.t, λx.s i π i ( ts ) → ( π i t ) s i = 1 , π i ( λx. h t , t i ) π i h λx.t , λx.t i λx.π i h t , t i λx.t i π i ( h t , t i s ) ( π i h t , t i ) sπ i h t s, t s i t i s ( λx. h t, s i ) u h t { x (cid:0) u } , s { x (cid:0) u }ih λx.t, λx.s i u h ( λx.t ) u, ( λx.s ) u i π i (( λx.t ) s ) π i ( t { x (cid:0) s } )( π i ( λx.t )) s ( λx.π i t ) s While the pairs on the left side are easy to deal with, those on the right sidehave an unpleasant closing diagram and make the rewriting system much harderto study. unctional Pearl: the Distributive λ -Calculus 15 Conclusions.
We have extended the λ -calculus with pairs with two additionalcommutation rules inspired by the distributivity isomorphism of simple types,and showed that it is a well behaved setting. In the untyped case, confluence,progress, and leftmost-outermost normalization are obtained essentially for free.In the typed case, subject reduction up to distributivity holds, as well as strongnormalization. The proof of strong normalization, in particular, is a smoothadaptation of Tait’s standard reducibility proof for the λ -calculus with pairs. Acknowledgements.
This work has been partially funded by the ANR JCJCgrant COCA HOLA ANR-16-CE40-004-01, the ECOS-Sud grant QuCa A17C03,and the French-Argentinian International Research Project SINFIN.
References
1. Aczel, P.: A general church-rosser theorem. Tech. rep., University of Manchester(1978)2. A¨ıt-Kaci, H., Garrigue, J.: Label-selective λ -calculus syntax and confluence. The-oretical Computer Science (2), 353–383 (1995)3. Arbiser, A., Miquel, A., R´ıos, A.: The lambda-calculus with constructors: Syntax,confluence and separation. Journal of Functional Programming (5), 581–631(2009)4. Bruce, K.B., Di Cosmo, R., Longo, G.: Provable isomorphisms of types. Mathe-matical Structures in Computer Science (2), 231–247 (1992)5. Di Cosmo, R.: Isomorphisms of types: from λ -calculus to information retrieval andlanguage design. Progress in Theoretical Computer Science, Birkhauser (1995)6. Di Cosmo, R.: A short survey of isomorphisms of types. Mathematical Structuresin Computer Science (5), 825–838 (2005)7. D´ıaz-Caro, A., Dowek, G.: The probability of non-confluent systems. In: Ayala-Rinc´on, M., Bonelli, E., Mackie, I. (eds.) Proceedings of the 9th InternationalWorkshop on Developments in Computational Models. Electronic Proceedings inTheoretical Computer Science, vol. 144, pp. 1–15. (2014)8. D´ıaz-Caro, A., Dowek, G.: Proof normalisation in a logic identifying isomorphicpropositions. In: Geuvers, H. (ed.) 4th International Conference on Formal Struc-tures for Computation and Deduction (FSCD 2019). Leibniz International Pro-ceedings in Informatics (LIPIcs), vol. 131, pp. 14:1–14:23. (2019)9. Klop, J.W.: Combinatory Reduction Systems. Phd thesis, Utrecht University(1980)10. Nipkow, T.: Higher-order critical pairs. In: Proceedings of the Sixth Annual Sym-posium on Logic in Computer Science (LICS ’91), Amsterdam, The Netherlands,July 15-18, 1991. pp. 342–349 (1991)11. Petit, B.: Semantics of typed lambda-calculus with constructors. Logical Methodsin Computer Science (1) (2011)12. van Raamsdonk, F.: Outermost-fair rewriting. In: de Groote, P. (ed.) TypedLambda Calculi and Applications, Third International Conference on TypedLambda Calculi and Applications, TLCA ’97, Nancy, France, April 2-4, 1997, Pro-ceedings. Lecture Notes in Computer Science, vol. 1210, pp. 284–299. (1997)13. Støvring, K.: Extending the extensional lambda calculus with surjective pairing isconservative. Logical Methods in Computer Science (2:1), 1–14 (2006)6 Accattoli & D´ıaz-Caro A Proofs Appendix
Lemma 2.3 (Substitutivity of → dist ). Left substitutivity : if t → dist t ′ then t { x (cid:0) s } → dist t ′ { x (cid:0) s } .2. Right substitutivity : if s → dist s ′ then t { x (cid:0) s } → ∗ dist t { x (cid:0) s ′ } .Proof.
1. By induction on the relation → dist . Base cases: – Let t = ( λy.u ) r β u { y (cid:0) r } = t ′ . Then, t { x (cid:0) s } = (( λy.u ) r ) { x (cid:0) s } = ( λy.u { x (cid:0) s } ) r { x (cid:0) s }7→ β ( u { x (cid:0) s } ) { y (cid:0) r { x (cid:0) s }} = ( u { y (cid:0) r } ) { x (cid:0) s } = t ′ { x (cid:0) s } – Let t = π i h u , u i 7→ π i u i = t ′ . Then, t { x (cid:0) s } = ( π i h u , u i ) { x (cid:0) s } = π i h u { x (cid:0) s } , u { x (cid:0) s }i7→ π i u i { x (cid:0) s } = t ′ { x (cid:0) s } – Let t = h u, r i p @ × h up, rp i = t ′ . Then, t { x (cid:0) s } = ( h u, r i p ) { x (cid:0) s } = h u { x (cid:0) s } , r { x (cid:0) s }i ( p { x (cid:0) s } ) @ × h u { x (cid:0) s } p { x (cid:0) s } , r { x (cid:0) s } p { x (cid:0) s }i = h up, rp i{ x (cid:0) s } = t ′ { x (cid:0) s } – Let t = π i ( λy.u ) π λ λy.π i u = t ′ , Then, t { x (cid:0) s } = π ( λy.u ) { x (cid:0) s } = π ( λy.u { x (cid:0) s } ) π λ λy.π i ( u { x (cid:0) s } ) = ( λy.π i u ) { x (cid:0) s } = t ′ { x (cid:0) s } We treat the inductive cases compactly via contexts. First note that astraightforward induction on C shows that C h t i{ x (cid:0) s } = C { x (cid:0) s }h t { x (cid:0) s }i ,where the substitution C { x (cid:0) s } on contexts is defined as expected. Now, con-sider t = C h u i → a C h r i = t ′ with u a r , for some a ∈ { β, @ × , π , π , π λ } .By i.h. , u { x (cid:0) s } 7→ a r { x (cid:0) s } . Hence, t { x (cid:0) s } = C h u i{ x (cid:0) s } = C { x (cid:0) s }h u { x (cid:0) s }i→ a C { x (cid:0) s }h r { x (cid:0) s }i = C h r i{ x (cid:0) s } = t ′ { x (cid:0) s }
2. By induction on t . – Let t = x . Then, t { x (cid:0) s } = s → dist s ′ = t { x (cid:0) s ′ } – Let t = y . Then, t { x (cid:0) s } = y → ∗ dist y = t { x (cid:0) s ′ } unctional Pearl: the Distributive λ -Calculus 17 – Let t = λy.u . By i.h. , u { x (cid:0) s } → ∗ dist u { x (cid:0) s ′ } . Then, t { x (cid:0) s } = λy.u { x (cid:0) s } → ∗ dist λy.u { x (cid:0) s ′ } = t { x (cid:0) s ′ } – Let t = ur . By i.h. , u { x (cid:0) s } → ∗ dist u { x (cid:0) s ′ } and r { x (cid:0) s } → ∗ dist r { x (cid:0) s ′ } .Then, t { x (cid:0) s } = ( u { x (cid:0) s } )( r { x (cid:0) s } ) → ∗ dist ( u { x (cid:0) s ′ } )( r { x (cid:0) s ′ } ) = t { x (cid:0) s ′ } – Let t = h u , u i . By i.h. , for i = 1 , u i { x (cid:0) s } → ∗ dist u i { x (cid:0) s ′ } . Then, t { x (cid:0) s } = h u { x (cid:0) s } , u { x (cid:0) s }i → ∗ dist h u { x (cid:0) s ′ } , u { x (cid:0) s ′ }i = t { x (cid:0) s ′ } – Let t = π i u . By i.h. u { x (cid:0) s } → ∗ dist u { x (cid:0) s ′ } . Then, t { x (cid:0) s } = π i ( u { x (cid:0) s } ) → ∗ dist π i ( u { x (cid:0) s ′ } ) = t { x (cid:0) s ′ } Lemma 3.2 (Substitution). If Γ, x : A ⊢ t : B and Γ ⊢ s : A , then Γ ⊢ t { x (cid:0) s } : B .Proof. By induction on the derivation of
Γ, x : A ⊢ t : B . – Let
Γ, x : A ⊢ x : A as a consequence of rule ( ax ). Then, x { x (cid:0) s } = s , andwe have Γ ⊢ s : A . – Let
Γ, y : B, x : A ⊢ y : B as a consequence of rule ( ax ). Then, y { x (cid:0) s } = y ,and by rule ( ax ), Γ, y : B ⊢ y : B . – Let
Γ, x : A ⊢ t : B as a consequence of Γ, x : A ⊢ t : C , C ≡ B and rule( ≡ ). Then, by i.h. , Γ ⊢ t { x (cid:0) s } : C , so, by rule ( ≡ ), Γ ⊢ t { x (cid:0) s } : B . – Let
Γ, x : A ⊢ λy.t : B ⇒ C as a consequence of Γ, x : A, y : B ⊢ t : C and rule ( ⇒ i ). Then, by i.h. , Γ, y : B ⊢ t { x (cid:0) s } : C , so, by rule ( ⇒ i ), Γ ⊢ λy.t { x (cid:0) s } : B ⇒ C . Notice that λy.t { x (cid:0) s } = ( λy.t ) { x (cid:0) s } . – Let
Γ, x : A ⊢ tr : B as a consequence of Γ, x : A ⊢ t : C ⇒ B , Γ, x : A ⊢ r : C , and rule ( ⇒ e ). Then, by i.h. , Γ ⊢ t { x (cid:0) s } : C ⇒ B and Γ ⊢ r { x (cid:0) s } : C ,so, by rule ( ⇒ e ), Γ ⊢ t { x (cid:0) s } r { x (cid:0) s } : B . Notice that t { x (cid:0) s } r { x (cid:0) s } =( tr ) { x (cid:0) s } . – Let
Γ, x : A ⊢ h t , t i : B ∧ B as a consequence of Γ, x : A ⊢ t i : B i , i = 1 ,
2, and rule ( ∧ i ). Then, by i.h. , Γ ⊢ t i { x (cid:0) s } : B i , so, by rule( ∧ i ), Γ ⊢ h t { x (cid:0) s } , t { x (cid:0) s }i : B ∧ B . Notice that h t { x (cid:0) s } , t { x (cid:0) s }i = h t , t i{ x (cid:0) s } . – Let
Γ, x : A ⊢ π t : B as a consequence of Γ, x : A ⊢ t : B ∧ C and rule ( ∧ e ).Then, by i.h. , Γ ⊢ t { x (cid:0) s } : B ∧ C , so, by rule ( ∧ e ), Γ ⊢ π ( t { x (cid:0) s } ) : B .Notice that π ( t { x (cid:0) s } ) = π t { x (cid:0) s } . – Let
Γ, x : A ⊢ π t : B as a consequence of Γ, x : A ⊢ t : B ∧ B and rule ( ∧ e1