Logische Methoden des Software Engineerings
Combinators and combinatory logic
Jakob Rehof & Andrej Dudenhefner LS XIV – Software Engineering
TU Dortmund WS 2018/19
WS 2018/19
Combinators
LetCbe a set ofcombinator symbols, ranged over byX, Y, Z. The setΞC of combinatory expressions, ranged over byF, G, H are defined inductively by:
X∈ C ⇒X∈ΞC, x∈ V ⇒x∈ΞC, F, G∈ΞC⇒(F G)∈ΞC
Consider the set SKI={S,K,I}of combinator symbols (referred to as a combinatory base) and define the notion ofweak reductionwonΞSKIby setting, for all
X, Y, Z∈ΞSKI:
IF w F
KF G w F
SF GH w (F H)(GH)
Let→wandw be the reduction relations onΞSKIinduced byw, by closingw
under contextsC::= []|(CF)|(F C), (F∈ΞSKI).
Combinators
LetCbe a set ofcombinator symbols, ranged over byX, Y, Z. The setΞC of combinatory expressions, ranged over byF, G, H are defined inductively by:
X∈ C ⇒X∈ΞC, x∈ V ⇒x∈ΞC, F, G∈ΞC⇒(F G)∈ΞC
Consider the set SKI={S,K,I}of combinator symbols (referred to as a combinatory base) and define the notion ofweak reductionwonΞSKIby setting, for all
X, Y, Z∈ΞSKI:
IF w F
KF G w F
SF GH w (F H)(GH)
Let→wandw be the reduction relations onΞSKIinduced byw, by closingw
under contextsC::= []|(CF)|(F C), (F∈ΞSKI).
Combinators
LetCbe a set ofcombinator symbols, ranged over byX, Y, Z. The setΞC of combinatory expressions, ranged over byF, G, H are defined inductively by:
X∈ C ⇒X∈ΞC, x∈ V ⇒x∈ΞC, F, G∈ΞC⇒(F G)∈ΞC
Consider the set SKI={S,K,I}of combinator symbols (referred to as a combinatory base) and define the notion ofweak reductionwonΞSKIby setting, for all
X, Y, Z∈ΞSKI:
IF w F
KF G w F
SF GH w (F H)(GH)
Let→w andw be the reduction relations onΞSKIinduced byw, by closingw
under contextsC::= []|(CF)|(F C), (F∈ΞSKI).
Combinatory bases
By choosing different sets B ⊆ C of combinators (such as
B = SKI = {S, K, I}) we can study different combinatory calculi, since in each case we can consider a B-calculus generated from the combinators in B. In such cases, we refer to the set B as a combinatory base.
Exercise 1
Show that the combinator I can be coded in terms of S and K. Hint: Notice that (KF)(KF )
wF .
In other words, the base SKI = {S, K, I} is redundant. Or, in yet other
words, the base SK = {S, K} is complete with respect to SKI-calculus.
For this reason, one also talks about SK-calculus.
Combinatory bases
By choosing different sets B ⊆ C of combinators (such as
B = SKI = {S, K, I}) we can study different combinatory calculi, since in each case we can consider a B-calculus generated from the combinators in B. In such cases, we refer to the set B as a combinatory base.
Exercise 1
Show that the combinator I can be coded in terms of S and K. Hint:
Notice that (KF)(KF )
wF .
In other words, the base SKI = {S, K, I} is redundant. Or, in yet other words, the base SK = {S, K} is complete with respect to SKI-calculus.
For this reason, one also talks about SK-calculus.
Combinatory bases
Sch¨ onfinkel used, in addition to S and K, the combinators B and C with the definitions
BF GH
BF (GH ) CF GH
CF HG
But they are not strictly needed, for we can take B ≡ S(KS)K
C ≡ S(S(K(S(KS)K))S)(KK)
Combinatory bases
Sch¨ onfinkel used, in addition to S and K, the combinators B and C with the definitions
BF GH
BF (GH ) CF GH
CF HG But they are not strictly needed, for we can take
B ≡ S(KS)K
C ≡ S(S(K(S(KS)K))S)(KK)
Combinatory bases
Exercise 2 (One point basis) Define the combinator X by the rule
(XF )
X((F S)K)
Show that (XX)
XSK(KK).
Show that X(X(XX))
XK.
Show that X(X(X(XX)))
XS.
Conclude that {X} is complete with respect to SKI-calculus.
Ξ
SKI7→ Λ
Define the map( )Λ: ΞSKI→Λby induction on expressions inΞSKI: (x)Λ ≡ x, forx∈ V
(I)Λ ≡ λx.x (K)Λ ≡ λxy.x (S)Λ ≡ λxyz.(xz)(yz) (F G)Λ ≡ (F)Λ(G)Λ
Proposition 1
IfF wG, then(F)Λβ (G)Λ.
Exercise 3
Prove Proposition 1 by induction on the length ofF wG.
Λ 7→ Ξ
SKIDefine, for eachx∈ V, the “bracket abstraction” map [x]: ΞSKI→ΞSKIby induction on expressions inΞSKI:
[x]x ≡ I
[x]F ≡ KF, ifx6∈FV(F) [x](F G) ≡ S([x]F)([x]G), otherwise
Proposition 2 (Combinatory completeness)
1 ∀F∈ΞSKI.∀G∈ΞSKI.([x]F)GwF[x:=G]
2 ∀F∈ΞSKI.([x]F)Λβ λx.(F)Λ
3 ∀x∈ V.∀F ∈ΞSKI.∃H∈ΞSKI.∀G∈ΞSKI. HGwF[x:=G]
Exercise 4
Prove Proposition 2.
Λ 7→ Ξ
SKIDefine, for eachx∈ V, the “bracket abstraction” map [x]: ΞSKI→ΞSKIby induction on expressions inΞSKI:
[x]x ≡ I
[x]F ≡ KF, ifx6∈FV(F) [x](F G) ≡ S([x]F)([x]G), otherwise
Proposition 2 (Combinatory completeness)
1 ∀F∈ΞSKI.∀G∈ΞSKI.([x]F)GwF[x:=G]
2 ∀F∈ΞSKI.([x]F)Λβ λx.(F)Λ
3 ∀x∈ V.∀F ∈ΞSKI.∃H∈ΞSKI.∀G∈ΞSKI. HGwF[x:=G]
Exercise 4
Prove Proposition 2.
Λ 7→ Ξ
SKIDefine the map( )Ξ: Λ→ΞSKIby induction onλ-terms:
(x)Ξ ≡ x, forx∈ V (M N)Ξ ≡ (M)Ξ(N)Ξ
(λx.M)Ξ ≡ [x](M)Ξ
Proposition 3
For allM∈Λ, one has((M)Ξ)ΛβM.
Exercise 5
Prove Proposition 3.
Combinatory logic SKI
Γ, x:τ `skix:τ(var)
Γ`skiI:τ →τ(I)
Γ`skiK:τ →σ→τ(K)
Γ`skiS: (τ→σ→ρ)→(τ →σ)→τ →ρ(S) Γ`skiF:τ→σ Γ`skiG:τ
Γ`ski(F G) :σ (→E)
Notice that variablesxhave fixed,monomorphic types, whereas combinatorsS,K,I have infinitely many types (their types areschematicorpolymorphic).
Combinatory logic SKI
Lemma 1 (Deduction theorem for SKI)
IfΓ, x:σ`skiF :τ, thenΓ`ski[x]F :σ→τ.
Proposition 4
1 IfΓ`skiF:τ, thenΓ`Λ(F)Λ:τ.
2 IfΓ`ΛM:τ, thenΓ`ski(M)Ξ:τ.
Exercise 6
Prove Proposition 4. Hint: The first statement is proven by induction on the derivation ofΓ`skiF :τ. The second statement is proven by induction on the derivation of Γ`ΛM :τ using Lemma 1.