A note on subject reduction in (→,∃) -Curry with respect to complete developments

A note on subject reduction in (→,∃) -Curry with respect to complete developments

Information Processing Letters 114 (2014) 72–75 Contents lists available at ScienceDirect Information Processing Letters www.elsevier.com/locate/ipl...

199KB Sizes 1 Downloads 64 Views

Information Processing Letters 114 (2014) 72–75

Contents lists available at ScienceDirect

Information Processing Letters www.elsevier.com/locate/ipl

A note on subject reduction in (→, ∃)-Curry with respect to complete developments Aleksy Schubert a,∗,1 , Ken-etsu Fujita b,2 a b

Institute of Informatics, University of Warsaw, ul. Banacha 2, 02-097 Warsaw, Poland Gunma University, Tenjin-cho 1-5-1, Kiryu 376-8515, Japan

a r t i c l e

i n f o

a b s t r a c t

Article history: Received 22 June 2012 Received in revised form 29 April 2013 Accepted 18 July 2013 Available online 21 August 2013 Communicated by A. Sabelfeld

We prove subject reduction of the Curry style existential system (→, ∃) with regard to complete developments. We use here a remote adaptation of the technique of Barbanera et al. used before for systems with union types. © 2013 Elsevier B.V. All rights reserved.

Keywords: Formal semantics Type systems Existential quantifier Abstract data types Subject reduction

1. The Curry system As demonstrated earlier [3], the systems with existential quantifier do not enjoy subject reduction with regard to β reduction. In this paper we show that they enjoy subject reduction with respect to the parallel β reduction. This, together with strong normalisation [4,6], proves that the system is consistent. In definition of the Curry style system we follow Sørensen and Urzyczyn [7]. The terms and types are generated using the following grammars, respectively:

M ::= x | (λx. M ) | ( M M )

A ::= X | A 1 → A 2 | ∃ X . A

The environments are partial finite functions from object variables to types. The type inference rules are presented

*

Corresponding author. Tel.: +48 22 5544575. E-mail addresses: [email protected] (A. Schubert), [email protected] (K.-e. Fujita). 1 This work was partly supported by Polish government Grant No. N N206 355836. 2 This work was partly supported by the bilateral program (2008) between Japan Society for the Promotion of Science and Polish Academy of Sciences. 0020-0190/$ – see front matter © 2013 Elsevier B.V. All rights reserved. http://dx.doi.org/10.1016/j.ipl.2013.07.027

in Fig. 1. As usual, we identify the types and terms up to renaming of bound variables. Note that M [x := N ] is the standard capture-avoiding substitution of N to all free occurrences of x in M. By FV( M ) we denote the set of free variables in M and TFV( A ) the set of free type variables in A. We use here the traditional syntax sugar for types and terms, see Sørensen and Urzyczyn [7]. If it does not lead to confusion, we omit C from the rule names. In case, Γ  M : A is derivable using the rules in Fig. 1, we write Γ (→,∃)Cu M : A. The pre-terms of (→, ∃)Cu in Church version are derived from the grammar:

    M ::= x A 1 | M1 M2 | λx A 1 .M   A 1 , M∃ X . A 2  let X , x A 1 = M1 in M2 As with the Curry style terms we can associate with the Church-style terms the set of free variables. We note that λ binds x A in the expression λx A .M and let binds the occurrences of x A in M2 inside the expression let  X , x A  = M1 in M2 . The typing rules are necessary to derive actual terms and are presented in Fig. 2. The rules are slightly non-standard, but to shorten the notational overhead we use object variables such as x with additional

A. Schubert, K.-e. Fujita / Information Processing Letters 114 (2014) 72–75

Γ, x : A 1  x : A 1 Γ, x : A 1  M : A 2 (→ I )C Γ  λx. M : A 1 → A 2 Γ  M : A 2 [ X := A 1 ] (∃ I )C Γ  M : ∃ X . A2 ∗ X

73

(var)C

Γ  M1 : A1 → A2 Γ  M2 : A1 (→ E )C Γ  M1 M2 : A2 Γ  M 1 : ∃ X . A 1 Γ, x : A 1  M 2 : A 2 (∃ E )C ∗ Γ  M 2 [x := M 1 ] : A 2

∈ / TFV(Γ, A 1 ) (eigenvariable condition) Fig. 1. The type inference rules for the Curry style system.

 x A1 : A 1  M : A2 (→ I )Ch  λx A 1 .M : A 1 → A 2  M : A 2 [ X := A 1 ] (∃ I )Ch   A 1 , M∃ X . A 2 : ∃ X . A 2 ∗ X

(var)Ch

 M1 : A 1 → A 2  M2 : A 1 (→ E )Ch  M1 M 2 : A 2  M1 : ∃ X . A 1  M 2 : A 2 (∃ E )Ch∗  let  X , x A 1  = M1 in M2 : A 2

∈ / TFV( A 2 ) and X ∈ / TFV( B ) for each x B ∈ FV(M2 ) − {x A 1 } (eigenvariable condition) Fig. 2. The typing rules for the Church-style system

type decoration (to avoid unnecessary complexity of argument we assume that there is no variable x which is decorated with two different types, i.e. there is no x A 1 and x A 2 where A 1 and A 2 are different types). This allows us to save the room of the contexts in the derivations. We can view the rules as a kind of correctness check for the terms in the Church style. Types of correct Church-style expressions are uniquely determined. We write M : A to stress that the uniquely determined type for M is A. A relation between correct Church-style expressions and derivations in Curry style are as follows. Definition 1 (Type erasure). For Church-style expressions we define a type erasure operation as follows:

• • • • •

|x A | = x, |MN| = |M||N|, |λx A .M| = λx.|M|, | A 1 , M∃ X . A 2 | = |M|, |let  X , x A  = M1 in M2 | = |M2 |[x := |M1 |].

We can naturally associate with a Church-style expression M a corresponding Curry style context Γ M = {x : A | x A ∈ FV(M)}. Proposition 2 (Type erasure and derivations). If M is a correct Church-style expression of type A then Γ M (→,∃)Cu |M| : A. If Γ (→,∃)Cu M : A then there is a correct Church-style expression M such that |M| = M. Proof. A standard reduction over the term M to prove (⇒) and over the derivation Γ M (→,∃)Cu |M| : A to prove (⇐). 2

Due to the proposition we can use the correct Churchstyle expressions to represent particular derivations in the Curry style. As in an earlier paper [3], we define a special form of derivations to be employed in the proof of subject reduction. Definition 3 (Simple derivations). A derivation M of Γ  M : A in the Curry style system is called simple, if M complies to all the restrictions: 1. For each application of the rule (∃ E ) in M of the form let  X , x A  = M1 in M2 we have x A ∈ FV(M2 ). 2. The derivation M contains no application of rules (∃ I ), (∃ E ) of the form let  X , x A 1  =  A 2 , M1 ∃ X . A 1 in M2 . 3. The derivation M contains no double application A of the rules (∃ E ) in the form of let  X 2 , x2 2  =

(let  X 1 , x1A 1  = M1 in M2 ) in M3 . 4. The derivation M contains no application of rules (∃ E ), (∃ I ) in the form of  A 1 , let  X , x A 2  = M1 in M2 ∃Y . A 3 . We recall properties, whose proofs were sketched in an earlier paper [3]. Proposition 4 (Simple derivations). If Γ  M : A has a derivation M in the Curry style system then it has also a simple derivation M . Proposition 5 (Substitution). If Γ, x : B (→,∃)Cu M : A and Γ (→,∃)Cu N : B in the Curry style system then there is a derivation for the judgement Γ (→,∃)Cu M [x := N ] : A. The β -reduction relation for terms of the untyped λ-calculus, i.e. the terms used in the Curry style formalism above, is defined by the context closure of the following rule (λx. M ) N →β M [x := N ]. We use standard notation

74

A. Schubert, K.-e. Fujita / Information Processing Letters 114 (2014) 72–75

→∗β to denote the reflexive–transitive closure of the relation →β . As is implied by the work of Riba [6], the relation is strongly normalising: Theorem 6 (Strong normalisation). If M is typable in (→, ∃)Curry then each β -reduction sequence starting with M terminates. 2. The lack of subject reduction for β It is known [7] that the subject reduction property is broken in the Curry system with both ∀ and ∃. A stronger result holds that the system (→, ∃)Cu does not enjoy the subject reduction property. The main idea behind the example is that the rule (∃ E ) derives a type for a term of the form M 2 [x := M 1 ] in the conclusion. In case a β -reduction step changes one of the copies of M 1 and leaves intact the other one, we are no longer able to apply the (∃ E ) rule and may not be able to reconstruct a derivation at all. This is exploited in the following proposition. Proposition 7 (Lack of subject reduction for β ). The subject reduction property of β -reduction is broken with respect to the existential system (→, ∃)Cu in Curry style. Let I ≡ λx.x and Γ be { f : Z → ∃ X .( X → X ), z : Z }. Then Γ (→,∃)Cu λx.( I f z)( I f zx) : ∃ X .( X → X ) but Γ (→,∃)Cu λx.( f z)( I f zx) : ∃ X .( X → X ). Proof. See the proof by Fujita and Schubert [3].

2

3. The proof of subject reduction The proof in this section remotely follows the method of Barbanera et al [1]. The proof there defines a special form of derivations and provides a measure of complexity for terms to carry out the inductive argument. Simple derivations are the special form we use here while our measure is adequate to natural deduction style of derivations instead of the sequent one used in the original case. As usual, we can identify a Curry style λ-term with its syntax tree. The strings from the set {0, 1}∗ represent positions in such a tree and form its domain. The positions address subterms as follows M |ε = M , M N |0·γ = M |γ , M N |1·γ = N |γ , (λx. M )|0·γ = M |γ , where ε is the empty string and γ · γ is the concatenation of γ and γ . When N is a subterm of M and its syntactical tree is in the tree of M rooted at a position γ ∈ {0, 1}∗ then we represent this particular occurrence of N in M with γ , N  M (we drop M when it is clear from the context). To refer to N in such a situation we write M |γ . We also write M [ N ]γ to represent the term obtained from M by replacing N at the position γ with N . This replacement is syntactical and all free variables in N with binders on the path γ in M become bound ones. Definition 8 (Uniform set of Curry redexes). Let M be a λ-term.

• Occ( M ) = {γ , N  | N = M |γ } is called the set of all occurrences of subterms in M.

• Red( M ) = {γ , (λx. N 1 ) N 2  | (λx. N 1 ) N 2 = M |γ } is the set of all occurrences of redexes in M. We sometimes abuse the notation and write R ∈ Red( M ) to mean that γ , R  ∈ Red( M ) for some γ . • A set F ⊆ Red( M ) is the uniform set of occurrences of redexes if whenever γ , R  ∈ F and γ , R  ∈ Red( M ) then γ , R  ∈ F . We introduce the notion of the parallel reduction following Xi [8]. We focus here on the evolution of a set of occurrences of redexes F in a term M where the set may range from a singleton to the set Red( M ) of all redexes in M. Definition 9 (Residuals). Let F be a set of occurrences of β -redexes in a λ-term M 1 and let M 1 →β M 2 be contracted with some β -redex R = (λx. M ) N where γ , R  ∈ Red( M 1 ). The set of residuals of a redex R ∈ F is defined as follows: 1. If R is R then ∅ is the set of residuals of R in M 2 . 2. If R = M 1 |γ ·1·γ = N |γ then all copies of R in M [x := N ] are residuals of R in M 2 , i.e. the set of residuals is {γ · ρ · γ , R  | ρ , x ∈ Occ( M )}. 3. If R = M 1 |γ ·0·0·γ = M γ then the set of residuals of R in M 2 is the singleton {γ · γ , R [x := N ]}. 4. If R contains R at γ then the residual of R in M 2 is the λ-term obtained by replacing R in R with its contractum, i.e. {γ , R } where R = R [ M [x := N ]]γ . 5. If R at γ and R at γ are disjoint then the residual is {γ , R }. Note that a contraction of a redex transforms F to a new set of redexes F that are residuals of the original ones. We denote by F /[ R ] the set of residuals of the occurrences of β -redexes in F after the redex R is contracted. For a sequence of redexes σ = R 1 , . . . , R n in successive terms from a reduction sequence, written sometimes [ R 1 ] + · · · + [ R n ], we define F /σ to be (· · · (F /[ R 1 ])/ · · · /[ R n ]). We extend the relation is residual of to connect redexes in F with ones obtained transitively in F /σ . Definition 10 (Development). Given a λ-term M and a set F of β -redexes in M, a sequence σ of β -redexes in successive terms from a reduction sequence starting with M is a development of F if for every R contracted in σ , R is a residual of some β -redex in F . Complete development of ( M , F ) where F ⊆ Red( M ) is a reduction such that all the redexes in F and their residuals are reduced and only the redexes and their residuals are reduced. We write ( M , F ) cpl N when N is the result of such complete development. The transitivity of the residual relation gives us that if

[ R ] + σ is a development of F , then σ is a development of F /[ R ]. A more rigorous way of introducing the developments employs the concept of labelling [8,5,2]. In the main proof we use the following properties of developments.

A. Schubert, K.-e. Fujita / Information Processing Letters 114 (2014) 72–75

Proposition 11 (Properties of developments). 1. If M = M 0 M 1 and F is a uniform set of redexes in M then Fi = {γ , R  | i · γ , R  ∈ F } is a uniform set of redexes in M i for i = 0, 1. 2. Let M = M 0 M 1 and let F be a uniform set of redexes in M. Suppose also that ε ∈ / π1 (F ) = {γ | γ , R  ∈ F }. If Fi = {γ , R  | i · γ , R  ∈ F }, and ( M i , Fi ) cpl N i for i = 0, 1 then ( M , F ) cpl N 0 N 1 . 3. Let M = M 2 [x := M 1 ] and F be a uniform set of redexes in M. If for each γ , R  ∈ F the conditions M 2 |γ ·0 = x and M 2 |γ = x hold, where γ  γ , then ( M , F ) cpl N 2 [x := M 1 ] and ( M 2 , F ) cpl N 2 for F = {γ , R  | γ , R [x := M 1 ] ∈ F }. Proof. The proof is left to the reader.

2

Definition 12 (Parallel Curry reduction). The reduction relation ⇒ p over λ-terms is defined as M ⇒ p N if and only if there is a uniform set of redexes F ⊆ Red( M ) such that ( M , F ) cpl N. Theorem 13 (Type invariance under parallel reduction). If

Γ (→,∃)Cu M : A and M ⇒ p N then Γ (→,∃)Cu N : A. Proof. Here is a detailed sketch of the proof. We prove a slightly different claim from which the theorem follows immediately. Let M be a derivation of Γ  M : A and F be a uniform set of redexes in M. If ( M , F ) cpl N then Γ (→,∃)Cu N : A has a derivation in (→, ∃)Cu. The proof is by induction over lexicographically ordered pairs (n, m) where n is the maximal number of reduction steps necessary to reach the normal form of M [6] and m is the size of its simple derivation M. The use of simple derivations here is possible by Proposition 4. We present here the non-trivial cases. The rest is left to the reader. The non-trivial cases are for n > 0. Then the proof is by cases according to the last rule used. Case when Γ  M : A is derived using the (→ E ) rule. In this case, M = M 0 M 1 and M = M0 M1 with |Mi | = M i where Mi for i = 0, 1 are simple. We can use Proposition 11(1) to obtain uniformity for subsets of redexes in M 0 and M 1 then by the induction hypothesis and Proposi-

75

tion 11(2) we can conclude successfully when there is no redex in root position. When there is a redex in root position we reduce first the redexes in M 0 , M 1 . After completing these contractions, we obtain M →∗β N 0 N 1 where N 0 = λx. N 0 . Note that the set of residuals of the redex is always a singleton at ε by (4) in Definition 9. Therefore, the term N 0 [x := N 1 ] is the result of complete development of F in M. We have to show that N 0 [x := N 1 ] has type A. Since the induction hypothesis gives that Γ (→,∃)Cu N i : A i for i = 0, 1 where A 0 = A 1 → A, we obtain that Γ (→,∃)Cu N 0 [x := N 1 ] : A by Proposition 5. Case when Γ  M : A is derived using the (∃ E ) rule. The derivation has the form let  X , x B  = M1 in M2 with

|Mi | = M i for i = 1, 2 and M = M 2 [x := M 1 ]. Note first that in case of simple derivations (Definition 3) no redexes in M = M 2 [x := M 1 ] are created by a copy of M 1 . Therefore, the only redexes are inside of copies of M 1 or they treat M 1 as a variable. As the reductions to be done in all copies are the same, we reduce all copies of M 1 to some term N 1 and then obtain by analysis and the induction hypothesis that M cpl N 2 [x := N 1 ]. In this case, we can reconstruct a derivation. 2 References [1] Franco Barbanera, Mariangiola Dezani-Ciancaglini, Ugo De’Liguoro, Intersection and union types: Syntax and semantics, Inf. Comput. 119 (2) (1995) 202–230. [2] Hendrik Pieter Barendregt, The Lambda Calculus – Its Syntax and Semantics, Studies in Logic and the Foundations of Mathematics, vol. 103, North-Holland, 1984. [3] Ken-etsu Fujita, Aleksy Schubert, Existential type systems with no types in terms, in: Pierre-Louis Curien (Ed.), Typed Lambda Calculi and Applications, Proceedings of the 9th International Conference, TLCA 2009, Brasilia, Brazil, July 1–3, 2009, in: LNCS, vol. 5608, SpringerVerlag, 2009, pp. 112–126. [4] Jean-Yves Girard, Une extension du système de fonctionelles recursives de Gödel et son application aux fondements de l’analyse, in: J.E. Fenstad (Ed.), Proceedings of the Second Scandinavian Logic Symposium, in: Studies in Logic and the Foundations of Mathematics, vol. 63, North-Holland, 1971, pp. 63–92. [5] Gérard P. Huet, Residual theory in lambda-calculus: A formal development, J. Funct. Program. 4 (3) (1994) 371–394. [6] Colin Riba, On the stability by union of reducibility candidates, in: Proceedings of the 10th International Conference on Foundations of Software Science and Computational Structures, in: LNCS, vol. 4423, Springer-Verlag, Berlin, Heidelberg, 2007, pp. 317–331. [7] Morten Heine Sørensen, Pawel Urzyczyn, Lectures on the Curry– Howard Isomorphism, Studies in Logic and the Foundations of Mathematics, vol. 149, Elsevier Science Inc., New York, NY, USA, 2006. [8] Hongwei Xi, Development separation in lambda-calculus, Electron. Notes Theor. Comput. Sci. 143 (January 2006) 207–221.