Spinal Atomic Lambda-Calculus

We present the spinal atomic \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\lambda $$\end{document}λ-calculus, a typed \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\lambda $$\end{document}λ-calculus with explicit sharing and atomic duplication that achieves spinal full laziness: duplicating only the direct paths between a binder and bound variables is enough for beta reduction to proceed. We show this calculus is the result of a Curry–Howard style interpretation of a deep-inference proof system, and prove that it has natural properties with respect to the \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\lambda $$\end{document}λ-calculus: confluence and preservation of strong normalisation.


Introduction
In the λ-calculus, a main source of efficiency is sharing: multiple use of a single subterm, commonly expressed through graph reduction [27] or explicit substitution [1]. This work, and the atomic λ-calculus [16] on which it builds, is an investigation into sharing as it occurs naturally in intuitionistic deep-inference proof theory [26]. The atomic λ-calculus arose as a Curry-Howard interpretation of a deep-inference proof system, in particular of the distribution rule given below left, a variant of the characteristic medial rule [10,26]. In the term calculus, the corresponding distributor enables duplication to proceed atomically, on individual constructors, in the style of sharing graphs [21]. As a consequence, the natural reduction strategy in the atomic λ-calculus is fully lazy [27,4]: it duplicates only the minimal part of a term, the skeleton, that can be obtained by lifting out subterms as explicit substitutions. (While duplication is atomic locally, a duplicated abstraction does not form a redex until also its bound variables have been duplicated; hence duplication becomes fully lazy globally.)  not available to a binder λx outside λx.N ). The scope of an abstraction thus becomes explicitly indicated in the term. This opens up a distinction between balanced and unbalanced scopes: whether scopes must be properly nested, or not; for example, in λx.λy.N , a subterm λy. λx.M is balanced, but λx. λy.M is not. With balanced scope, one can indicate the skeleton of an abstraction; with unbalanced scope (which Hendriks and Van Oostrom dismiss) one can indicate the spine. We do so for our example term λx.λy. ( A closely related approach is director strings, introduced by Kennaway and Sleep [19] for combinator reduction and generalized to any reduction strategy by Fernández, Mackie, and Sinot in [13]. The idea is to use nameless abstractions identified by their nesting (as with De Bruijn indices), and make the paths to bound variables explicit by annotating each constructor with a string of directors, that outline the paths. The primary aim of these approaches is to eliminate αconversion and to streamline substitution. Consequently, while they can identify the spine, they do not readily isolate it for duplication.
The present work starts from our observation that the switch rule of open deduction functions as a proof-theoretic end-of-scope construction (see [25] for details). However, it does so in a structural way: it forces a deconstruction of a proof into readily duplicable parts, which together may form the spine of an abstraction. The derivations in Figure 1 demonstrate this, as we will now explain-see the next section for how they are formally constructed.
The abstraction λx corresponds in the proof system to the implication A→, explicitly scoping over its right-hand side. On the left, with the abstraction rule (λ), scopes must be balanced, and the proof system may identify the skeleton; here, that of λx as the largest blue box. Decomposing the abstraction (λ) into axiom (a) and switch (s), on the right the proof system may express unbalanced scope. It does so by separating the scope of an abstraction into multiple parts; here, that of λx is captured as the two top-level red boxes. Each box is ready to be duplicated; in this way, one may duplicate the spine of an abstraction only.
These two derivations correspond to terms in our calculus. The subterms not part of the skeleton (i.e. λz.z) remain shared and we are able to duplicate the skeleton alone. This is also possible in [16]. In our calculus we are also able to duplicate just the spine by using a distributor. We require this construct as otherwise we break the binding of the y-abstraction. The distributor manages and maintains these bindings. The y-abstraction in the spine (y⟨a⟩) is a phantomabstraction, because it is not real and we cannot perform β-reduction on it. However, it may become real during reduction. It can be seen as a placeholder for the abstraction. The variables in the cover (a) represent subterms that both remain shared and are found in the distributor.
Our investigation is then focused on the interaction of switch and distribution (later observed in the rewrite rule l 5 ). The use of the distribution rule allows us to perform duplication atomically, and thus provides a natural strategy for spinal full laziness. In Figure 1 on the right, this means duplicating the two top-level red boxes can be done independently from duplicating the yellow box.

Typing a λ-calculus in open deduction
We work in open deduction [15], a formalism of deep-inference proof theory, using the following proof system for (conjunction-implication) intuitionistic logic. A derivation from a premise formula X to a conclusion formula Z is constructed inductively as in Figure 2a, with from left to right: a propositional atom a, where X = Z = a; horizontal composition with a connective →, where X = Y → X 2 and Z = Y → Z 2 ; horizontal composition with a connective ∧, where X = X 1 ∧ X 2 and Z = Z 1 ∧ Z 2 ; and rule composition, where r is an inference rule ( Figure 2b) from Y 1 to Y 2 . The boxes serve as parentheses (since derivations extend in two dimensions) and may be omitted. Derivations are considered up to associativity of rule composition. One may consider formulas as derivations that omit rule composition. We work modulo associativity, symmetry, and unitality of conjunction, justifying the n-ary contraction, and may omit ⊺ from the axiom rule. A 0-ary contraction, with conclusion ⊺, is a weakening. Figure 2b: the abstraction rule (λ) is derived from axiom and switch. Vertical composition of a derivation from X to Y and one from Y to Z, depicted by a dashed line, is a defined operation, given in Figure 2c, where * ∈ {∧, →}.

The Sharing Calculus
Our starting point is the sharing calculus (Λ S ), a calculus with an explicit sharing construct, similar to explicit substitution.  .
The translation N of a λ-term N is the unique sharing-normal term t such that N = t . A term t will be typed by a derivation with restricted types, Fig. 3: Typing system for Λ S as shown below, where the context type Γ = A 1 ∧ ⋅ ⋅ ⋅ ∧ A n will have an A i for each free variable x i of t. We connect free variables to their premises by writing A x and Γ ⃗ x . The Λ S is then typed as in Figure 3.

The Spinal Atomic λ-Calculus
We now formally introduce the syntax of the spinal atomic λ-calculus (Λ S a ), by extending the definition of the sharing calculus in Definition 1 with a distributor construct that allows for atomic duplication of terms.

Definition 3 (Pre-Terms). The pre-terms r, s, t, closures [Γ ], and environments
Our generalized abstraction x⟨ ⃗ y ⟩.t is a phantom-abstraction, where x a phantom-variable and the cover ⃗ y will be a subset of the free variables of t. It can be thought of as a "delayed" abstraction: x is a binder, but possibly not in t itself, and instead in the terms substituted for the variables ⃗ y; in other words, x is a capturing binder for substitution into ⃗ y. We define standard λabstraction as the special case λx.t ≡ x⟨ x ⟩.t, and generally, when we refer to x⟨ ⃗ y ⟩ as a phantom-abstraction (rather than an abstraction) we assume ⃗ y ≠ x.
] binds the phantom-variables ⃗ x in u, while its environment [Γ ] will bind the variables in their covers; intuitively, it represents a set of explicit substitutions in which the variables ⃗ x are expected to be captured. The distributor is introduced when we wish to duplicate an abstraction, as depicted in Figure 4a. The sharing node (○) duplicates the abstraction node, creating a distributor (depiced as the sharing and unsharing node (•), together with the bindings of the phantom-variables (depicted with a dashed line). The variables captured by the environment are the variables connected to sharing nodes linked with a dotted line. Notice one sharing node can be linked with multiple unsharing nodes, and vice versa. Duplication of applications also duplicates ○ λx λy λx1 λx1 ). These subterms are those which are not part of the spine. Eventually, we will reach a state where the only sharing node connected to the unsharing node is the one that shared the variable bound to the unsharing, allowing us to eliminate the distributor ( Figure 4d). The purpose of the dotted line is similar to the brackets of optimal reduction graphs [21,24], to supervise which sharing and unsharing match. Terms are then pre-terms with sensible and correct bindings. To define terms, we first define free and bound variables and phantom variables; variables are bound by abstractions (not phantoms) and by sharings, while phantom-variables are bound by distributors.

Definition 5 (Free and Bound Phantom-Variables). The free phantomvariables (−) fp and bound phantom-variables (−) bp of the pre-term t are defined as follows
The free covers (u) fc and bound covers (u) bc are the covers associated with the free phantom-variables (u) fp respectively the bound phantom-variables (u) bp of u; that is, if x occurs as x⟨ ⃗ a ⟩ in u and x ∈ (u) fp then ⟨⃗ a⟩ ∈ (u) fc . When bound, x and the variables in ⃗ a may be alpha-converted independently. When then for technical convenience we may make the covers explicit in the distributor itself, and write The environment [Γ ] is expected to bind exactly the variables in the covers ⟨⃗ a i ⟩.
We apply this and other restrictions to define the terms of the calculus. Definition 6. Terms t ∈ Λ S a are pre-terms with the following constraints 1. Each variable may occur at most once. Example 1. Here we show some pre-terms that are not terms.

In a phantom-abstraction
(violates condition 4a) We also work modulo permutation with respect to the variables in the cover of phantom-abstractions. Let ⃗ x be a list of variables and let ⃗ x P be a permutation of that list, then the following terms are considered equal. Fig. 5: Typing derivations for phantom-abstractions and distributors Terms are typed with the typing system for Λ S extended with the distribution inference rule. This rule is the result of computationally interpreting the medial rule as done in [16]. We obtain this variant of the medial rule due to the restriction for implications and to avoid introducing disjunction to the typing system. The terms of Λ S a are then typed as in both Figure 3 and Figure 5. Note environments are typed by the derivations of all its closures composed horizontally with the conjunction connective. Also note that in the case for phantom-abstraction is similar for that of an abstraction, where we replace one occurrence of the simple type A by the conjunction Γ .

Compilation and Readback.
We now define the translations between Λ S a and the original λ-calculus.
where x 1 , . . . , x k are the free variables of M such that | M | xi = n i > 1 and − ′ is defined on terms as (where n ≠ 1 in the abstraction case): The readback into the λ-calculus is slightly more complicated, specifically due to the bindings induced by the distributor. Interpreting a distributor construct as a λ-term requires (1) converting the phantom-abstractions it binds in u into abstractions (2) collapsing the environment (3) maintaining the bindings between the converted abstractions and the intended variables located in the environment.

Definition 8. Given a total function σ with domain D and codomain
We use the map σ as part of the translation, the intuition is that for all bound variables x in the term we are translating, it should be that σ(x) = x. The purpose of the map γ is to keep track of the binding of phantom-variables.
The following Proposition justifies working modulo permutation equivalence.

Rewrite Rules.
Both the spinal atomic λ-calculus and the atomic λ-calculus of [16] follow atomic reduction steps, i.e. they apply on individual constructors. The biggest difference is that our calculus is capable of duplicating not only the skeleton but also the spine. The rewrite rules in our calculus make use of 3 operations, substitution, book-keeping, and exorcism. The operation substitution t{s/x} propagates through the term t, and replaces the free occurences of the variable x with the term s. Moreover, if x occurs in the cover of a phantom-variable e⟨ ⃗ y ⋅ x ⟩, then substitution replaces the x in the cover with (s) fv , resulting in e⟨ ⃗ y ⋅ (s) fv ⟩. Although substitution performs some book-keeping on phantom-abstractions, we define an explicit notion of book-keeping {⃗ y/e} b that updates the variables stored in a free cover i.e. for a term t, e⟨ ⃗ x ⟩ ∈ (t) fc then e⟨ ⃗ y ⟩ ∈ (t{⃗ y/e} b ) fc . The last operation we introduce is called exorcism {c⟨ ⃗ x ⟩} e . We perform exorcisms on phantom-abstractions to convert them to abstractions. Intuitively, this will be performed on phantom-abstractions with phantom-variables bound to a distributor when said distributor is eliminated. It converts phantom-abstractions to abstractions by introducing a sharing of the phantom-variable that captures the variables in the cover, i.e.

Proposition 2.
The translation u | σ | γ commutes with substitutions, bookkeepings 1 , and exorcisms 2 in the following way Proof. See [25], proof of Proposition 18,19,20,21. Using these operations, we define the rewrite rules that allow for spinal duplication. Firstly we have beta reduction (↝ β ), which strictly requires an abstraction (not a phantom).
Here β-reduction is a linear operation, since the bound variable x occurs exactly once in the body t. Any duplication of the term t in the atomic λ-calculus proceeds via the sharing reductions.
The first set of sharing reduction rules move closures towards the outside of a term. Most of these rewrite rules only change the typing derivations in the way that subderivations are composed, with the exception of moving a closure out of scope of a distributor.
For the case of lifting a closure outside a distributor, we use a notation ∥ The graphical version of this rule is shown in Figure 4c, where we remove the edge only if there is no edge between t and the unsharing node. The proof rewrite rule corresponding with the rewrite rule l 5 can be broken down into two parts. The first part is readjusting how the derivations compose as shown below.
The second part of the rewrite rule justifies the need for the book-keeping operation. In the rewrite below, let A be the type of a variable z where z ∈ ⃗ z. After lifting, we want to remove the variable from the cover as to ensure correctness since the variables in the cover denote the variables captured by the environment. Book-keeping allows us to remove these variables simultaneously.
The lifting rules (l i ) are justified by the need to lift closures out of the distributor, as opposed to duplicating them. The second set of rewrite rules, consecutive sharings are compounded and unary sharings are applied as substitutions. For simplicity, in the equivalent proof rewrite step we only show the binary case.
The atomic steps for duplicating are given in the third and final set of rewrite rules. The first being the atomic duplication step of an application, which is the same rule used in [16]. The binary case proof rewrite steps for each rule are also provided. There are also shown graphically in (respectively) Figure 4b (where we maintain links between sharings and unsharings), Figure 4a, and Figure 4d (where the unsharing node is linked to exactly one connecting sharing node).
Reduction (↝ (L,C,D,β) ) preserves the conclusion of the derivation, and thus the following proposition is easy to observe. The following Lemma not only proves we have good translations in Section 3.1, and shows duplication preserves denotation.

Lemma 2.
Given a term t ∈ Λ S a , then t is t in sharing normal form. Proof. We can prove this by induction on the longest sharing reduction path from t. Our base case is already covered by Lemma 1. We are then interested in the inductive case, where t is not in sharing normal form. By Lemma 1, t = t ′ where t ↝ (D,L,C) t ′ . By induction hypothesis, t ′ is in sharing normal form. Hence t is in sharing normal form. ◻

Strong Normalisation of Sharing Reductions
In order to show our calculus is strongly normalising, we first show that the sharing reduction rules are strongly normalising. We indite a measure on terms and show that this measure strictly decreases as sharing reduction progresses. Similar ideas and results can be found elsewhere: with memory in [20], the λ-I calculus in [6], the λ-void calculus [2], and the weakening λμ-calculus [17]. Our measure will consist of three components. First, the height of a term is a multiset of integers, that measures the number of constructors from each sharing node to the root of the term in its graphical notation. The height is defined on terms as H i (−), where i is an integer. We say H(t) for H 1 (t). We use ⊍ to denote the disjoint union of two multisets. We denote

Definition 11 (Sharing Height). The sharing height H i (t) of a term t is given below, where n is the number of closures in [Γ ]
: This measure then strictly decreases for the rewrite rules l 1 , l 2 , l 3 , l 4 and l 5 , i.e. if t ↝ L u then H i (t) > H i (u). The second measure we consider is the weight of a term. Intuitively this quantifies the remaining duplications, which are performed with ↝ D reductions. If a term would be deleted, we assign it with a weight '1' to express that it is not duplicated. Calculating the weight requires an auxiliary function that assigns integer weights to the variables of a term. This function is defined on terms V i (−), where i is an integer. To measure variables independently of binders is vital. It allows to measure distributors, which duplicate λ's but not the bound variable. Also, only bound variables for abstractions are measured since variables bound by sharings are substituted in the interpretation.

Definition 12 (Variable Weights). The function V i (t) returns a function that assigns integer weights to the free variables of t. It is defined by the below,
The weight of a term can then be defined via the use of this auxiliary function. The auxiliary function is used when calculating the weight of a sharing, where the sharing weight of the variables bound by the sharing play a significant role in calculating the weight of the shared term. In the case of a weakening [← t], we assign an initial weight of 1. Again we say W (t) = W 1 (t).

Definition 13 (Sharing Weight). The sharing weight W i (t) of a term t is a multiset of integers computed by the function defined below
This measure then strictly decreases on the rewrite rules d 1 , d 2 , d 3 and is unaffected by all the other sharing reduction rules, i.e. if t ↝ D u then W i (t) > W i (u).
If t ↝ (L,C) u then W i (t) = W i (u). The third and last measure we consider is the number of closures in the term, where it can be easily observed that the rewrite rules c 1 and c 2 strictly decrease this measure, and that the ↝ L rules do not alter the number of closures. We then use this along with height and weight to define a sharing measure on terms.

Definition 14.
The sharing measure of a Λ S a -term t is a triple (W (t), C, H(t)), where C is the number of closures in the term t. We compare sharing measures by using the lexicographical preferences according to W > C > H. Now that we have proven the sharing reductions are strongly normalising, we can prove that they are confluent for closed terms. Proof. Lemma 1 tells us that the preservation is preserved under reduction i.e. for s ↝ (D,L,C) t, s = t . Therefore given t ↝ * (D,L,C) s 1 and t ↝ * (D,L,C) s 2 , t = s 1 = s 2 . Since we know that sharing reductions are strongly normalising, we know there exists terms u 1 and u 2 in sharing normal form such that s 1 ↝ * (D,L,C) u 1 and s 2 ↝ * (D,L,C) u 2 . Lemma 1 tells us that terms in sharing normal form are in correspondence with their denotations i.e. t = t. Since by Lemma 1 we know u 1 = s 1 = s 2 = u 2 , and by Lemma 1 u 1 = u 1 and u 2 = u 2 , we can conclude u 1 = u 2 . Hence, we prove confluence. ◻

Preservation of Strong Normalisation and Confluence
A β-step in our calculus may occur within a weakening, and therefore is simulated by zero β-steps in the λ-calculus. Therefore if there is an infinite reduction path located inside a weakening in Λ S a , then the reduction path is not preserved in the corresponding λ-term as there are no weakenings. To deal with this, just as done in [2,16,17], we make use of the weakening calculus. A β-step is non-deleting precisely because of the weakening construct. If a β-step would be deleting, then the weakening calculus would instead keep the deleted term around as 'garbage', which can continue to reduce unless explicitly 'garbage-collected' by extra (nonβ) reduction steps. PSN has already be shown for the weakening calculus through the use of a perpetual strategy in [16]. A part of proving PSN is then using the weakening calculus to prove that if t ∈ Λ S a has a infinite reduction path, then its translation into the weakening calculus also has an infinite reduction path.

Definition 15.
The W-terms of the weakening calculus (Λ W ) are The terms are variable, abstraction, application, weakening, and a bullet. In the weakening T [← U ], the subterm U is weakened. The interpretation of atomic terms to weakening terms − | − | − W can be seen as an extension of the translation into the λ-calculus (Definition 9).
defined as an extension of the translation in (Definition 9) with the following additional special cases.
We say t W = t | I | I W where I is the identity function. We also have translations of the weakening calculus to and from the λ-calculus. Both of these translations were provided in [16]. The interpretation ⌊ − ⌋ from weakening terms to λ-terms discards all weakenings.

Proposition 4.
For N ∈ Λ and t ∈ Λ S a the following properties hold When translating from Λ S a to Λ W , weakenings are maintained whilst sharings are interpreted via substitution. Thus the reduction rules in the weakening calculus cover the spinal reductions for nullary distributors and weakenings. Theorem 3. If N ∈ Λ is strongly normalising, then so is N .
Proof. For a given N ∈ Λ that is strongly normalising, we know by Lemma 5 that N W is strongly normalising. Then N W is strongly normalising, since Proposition 4 states that N W = N W . Then by Lemma 4, which states that if t W is strongly normalising, then t is strongly normalising, proves that N is strongly normalising. ◻ We also prove confluence, which is already known for the λ-calculus [11]. We first observe that a β-step in the λ-calculus is simulated in Λ S a by one β-step followed by zero or more sharing reductions.

Conclusion, related work, and future directions
We have studied the interaction between the switch and the medial rule, the two characteristic inference rules of deep inference. We built a Curry-Howard interpretation based on this interaction, whose resulting calculus not only has the ability to duplicate terms atomically but can also duplicate solely the spine of an abstraction such that beta reduction can proceed on the duplicates. We show that this calculus has natural properties with respect to the λ-calculus. This work, which started as an investigation into the Curry-Howard correspondence of the switch rule [25], fits into a broader effort to give a computational interpretation to intuitionistic deep-inference proof theory. Brünnler and McKinley [9] give a natural reduction mechanism without medial (or switch), and observe that preservation of strong normalization fails. Guenot and Straßburger [14] investigate a different switch rule, corresponding to the implication-left rule of sequent calculus. He [17] extends the atomic λ-calculus to the λμ-calculus.
Our future goal is to develop the intuitionistic open deduction formalism towards optimal reduction [23,21,3], via the remaining medial and switch rules [26].