Combinatorics of explicit substitutions Maciej Bendkowski 1 Pierre Lescanne 2 1 Jagiellonian University in Kraków 2 École normale supérieure de Lyon Computational Logic and Applications Paris, May 25th 2018 1/24
Outline λ -calculus and substitution resolution λυ -calculus and explicit substitutions Our contribution 2/24
β -reduction in λ -calculus Substitution of terms for variables forms the essence of β -reduction in λ -calculus. For instance, ( λ x . x ( yx )( λ z . z )) T → β T ( yT )( λ z . z ) : @ λ x @ T @ @ λ z @ λ z z @ x z @ T y y x T 3/24
β -reduction in λ -calculus (ii) However, what if we substitute T with free variables under an abstraction? For instance, what if z occurs freely in T , as in the following example: @ λ x T @ @ λ z y x @ y y 4/24
β -reduction in λ -calculus (ii) However, what if we substitute T with free variables under an abstraction? For instance, what if z occurs freely in T , as in the following example: ◮ We want to avoid the @ capture of variable z in T ; λ x T @ @ λ z y x @ y y 4/24
β -reduction in λ -calculus (ii) However, what if we substitute T with free variables under an abstraction? For instance, what if z occurs freely in T , as in the following example: ◮ We want to avoid the @ capture of variable z in T ; ◮ Requires keeping track λ x of variable names and (sometimes) their T @ renaming ; @ λ z y x @ y y 4/24
β -reduction in λ -calculus (ii) However, what if we substitute T with free variables under an abstraction? For instance, what if z occurs freely in T , as in the following example: ◮ We want to avoid the @ capture of variable z in T ; ◮ Requires keeping track λ x of variable names and (sometimes) their T @ renaming ; ◮ In principle feasible, but @ λ z in practice it is not a trivial operation to y x @ execute. y y 4/24
β -reduction and computational effectiveness Postulate (essentially due to de Bruijn ’78) The number of β -reductions required to normalise a given term (in other words, evaluate the encoded computation) does not quite reflect the computational effort required to carry out the computation. 5/24
β -reduction and computational effectiveness Postulate (essentially due to de Bruijn ’78) The number of β -reductions required to normalise a given term (in other words, evaluate the encoded computation) does not quite reflect the computational effort required to carry out the computation. ◮ It hides the non-trivial details of capture-avoiding substitution; 5/24
β -reduction and computational effectiveness Postulate (essentially due to de Bruijn ’78) The number of β -reductions required to normalise a given term (in other words, evaluate the encoded computation) does not quite reflect the computational effort required to carry out the computation. ◮ It hides the non-trivial details of capture-avoiding substitution; ◮ It does not reflect the cost of substitution resolution ; 5/24
β -reduction and computational effectiveness Postulate (essentially due to de Bruijn ’78) The number of β -reductions required to normalise a given term (in other words, evaluate the encoded computation) does not quite reflect the computational effort required to carry out the computation. ◮ It hides the non-trivial details of capture-avoiding substitution; ◮ It does not reflect the cost of substitution resolution ; ◮ and finally, it hides the details of evaluation strategies . 5/24
β -reduction and computational effectiveness Postulate (essentially due to de Bruijn ’78) The number of β -reductions required to normalise a given term (in other words, evaluate the encoded computation) does not quite reflect the computational effort required to carry out the computation. ◮ It hides the non-trivial details of capture-avoiding substitution; ◮ It does not reflect the cost of substitution resolution ; ◮ and finally, it hides the details of evaluation strategies . . . . and that is due to the epitheoretic substitution operation. 5/24
β -reduction and computational effectiveness (ii) Issue I β -reduction hides the non-trivial details of capture-avoiding substitution. Variable renaming can take time linear in the term size. @ λ x T @ @ λ z y x @ y y 6/24
β -reduction and computational effectiveness (iii) Issue II β -reduction does not reflect the cost of substitution resolution . Variable search can take time linear in the term size. @ λ x T @ @ λ z x z @ y x 7/24
β -reduction and computational effectiveness (iv) Issue III β -reduction hides the details of evaluation strategies . What if the substitution is carried out non-strictly, e.g. it is suspended and evaluated on demand (perhaps even never)? Real-life 1 example of an infinite lists of Fibonacci numbers: fibs = 0 : 1 : next fibs 1 where 2 next (a : b : xs) = (a + b) : next (b : xs) 3 1 Is this the real life ? Is this just fantasy? ( . . . ) [Mercury et al. ’75] 8/24
Effectuation of substitution In order to effectuate substitution, its resolution should be internalised into the calculus itself. Possible solutions: ◮ investigate combinatory logic, or 9/24
Effectuation of substitution In order to effectuate substitution, its resolution should be internalised into the calculus itself. Possible solutions: ◮ investigate combinatory logic, or ◮ investigate calculi of explicit substitution ; 9/24
Effectuation of substitution In order to effectuate substitution, its resolution should be internalised into the calculus itself. Possible solutions: ◮ investigate combinatory logic, or ◮ investigate calculi of explicit substitution ; Qest Investigate quantitative aspects of substitution. For instance, 9/24
Effectuation of substitution In order to effectuate substitution, its resolution should be internalised into the calculus itself. Possible solutions: ◮ investigate combinatory logic, or ◮ investigate calculi of explicit substitution ; Qest Investigate quantitative aspects of substitution. For instance, ◮ What is the average-case cost of resolving substitutions in computations (terms) of size n ? How does it change depending on the assumed evaluation strategy? What contributes to its execution time? 9/24
Effectuation of substitution In order to effectuate substitution, its resolution should be internalised into the calculus itself. Possible solutions: ◮ investigate combinatory logic, or ◮ investigate calculi of explicit substitution ; Qest Investigate quantitative aspects of substitution. For instance, ◮ What is the average-case cost of resolving substitutions in computations (terms) of size n ? How does it change depending on the assumed evaluation strategy? What contributes to its execution time? ◮ What is the average-case complexity of abstract machines executing (terminating) computations of considered calculi? Is it possible to optimise them based on the structure of typical computations? 9/24
Reflections on combinatory logic Normal-order reduction If a term (combinator) T is normalisable, then the iterative contraction of the lefmost-outermost redex leads to the (unique) normal form of T . Sxyz → xz ( yz ) = R 0 S � K � KR 0 � SR 0 � SR 0 R 0 Kxy → x = R 1 SR 1 � KR 1 � SR 0 R 1 � SR 1 R 0 � KR 0 C � KSCR 0 � KKCR 0 � KSCR 0 R 0 � K ( SR 0 ) CR 0 � SSSR 0 � SSKR 0 � SS ( SR 0 ) R 0 R 2 = . . . Figure: Rewriting rules of SK -combinators and the corresponding normal-order reduction grammars. 10/24
Reflections on combinatory logic (ii) Theorem (B., Grygiel and Zaionc ’17) For each k ≥ 1, the asymptotic density µ ( R k / C ) of combinators reducing in k normal-order reduction steps in the set of all combinators is positive . In particular, we have: Problem µ ( R k / C ) k How to port these results to the realm of 0 0 . λ -calculus having an external substitution? 1 0 . 08961 2 0 . 06417 3 0 . 05010 . . . use explicit substitutions ! 4 0 . 04131 5 0 . 03570 6 0 . 03119 7 0 . 02798 11/24
Outline λ -calculus and substitution resolution λυ -calculus and explicit substitutions Our contribution 12/24
λυ -calculus (lambda upsilon calculus) A simplistic calculus of explicit substitutions due to Lescanne ’94. T ::= N | λ T | T T | T [ S ] ( λ a ) b → a [ b / ] (Beta) S ::= T / | ⇑ ( S ) | ↑ (App) ( ab )[ s ] → a [ s ]( b [ s ]) N ::= 0 | S N . (Lambda) ( λ a )[ s ] → λ ( a [ ⇑ ( s )]) 0 [ a / ] → a (FVar) Figure: Terms of λυ -calculus. ( S n )[ a / ] → n (RVar) 0 [ ⇑ ( s )] → 0 (FVarLif) ( S n )[ ⇑ ( s )] → n [ s ][ ↑ ] (RVarLif) n [ ↑ ] → S n . (VarShif) Figure: Rewriting rules. 13/24
λυ -calculus (ii) Consider the term K = λ x .λ y . x ; denoted as λλ 1. Certainly, Kab → β a for each term a (in one step). Note however, that with explicit substitutions we have ( λλ 1 ) a → ( λ 1 )[ a / ] → λ ( 1 [ ⇑ ( a / )]) → λ ( 0 [ a / ][ ↑ ]) → λ ( a [ ↑ ]) . The final shif operator guarantees that (potential) free indices are aptly incremented so to avoid potential variable captures. If a is closed, then a [ ↑ ] resolves simply to a , as intended. 14/24
Outline λ -calculus and substitution resolution λυ -calculus and explicit substitutions Our contribution 15/24
Recommend
More recommend