• Keine Ergebnisse gefunden

Logische Methoden des Software Engineerings Combinators and combinatory logic Jakob Rehof & Andrej Dudenhefner LS XIV – Software Engineering

N/A
N/A
Protected

Academic year: 2021

Aktie "Logische Methoden des Software Engineerings Combinators and combinatory logic Jakob Rehof & Andrej Dudenhefner LS XIV – Software Engineering"

Copied!
15
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

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

(2)

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).

(3)

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).

(4)

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).

(5)

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 )

w

F .

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.

(6)

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 )

w

F .

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.

(7)

Combinatory bases

Sch¨ onfinkel used, in addition to S and K, the combinators B and C with the definitions

BF GH

B

F (GH ) CF GH

C

F HG

But they are not strictly needed, for we can take B ≡ S(KS)K

C ≡ S(S(K(S(KS)K))S)(KK)

(8)

Combinatory bases

Sch¨ onfinkel used, in addition to S and K, the combinators B and C with the definitions

BF GH

B

F (GH ) CF GH

C

F HG But they are not strictly needed, for we can take

B ≡ S(KS)K

C ≡ S(S(K(S(KS)K))S)(KK)

(9)

Combinatory bases

Exercise 2 (One point basis) Define the combinator X by the rule

(XF )

X

((F S)K)

Show that (XX)

X

SK(KK).

Show that X(X(XX))

X

K.

Show that X(X(X(XX)))

X

S.

Conclude that {X} is complete with respect to SKI-calculus.

(10)

Ξ

SKI

7→ Λ

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.

(11)

Λ 7→ Ξ

SKI

Define, 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.

(12)

Λ 7→ Ξ

SKI

Define, 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.

(13)

Λ 7→ Ξ

SKI

Define 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.

(14)

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).

(15)

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.

Referenzen

ÄHNLICHE DOKUMENTE

aus Beispiel 2.1.1 aus Lectures on the Curry-Howard Isomorphism (entspricht Aufgabe 2.7.3 aus Søren- sen, Morten Heine B., Urzyczyn, Paweª: Lectures on the Curry-Howard

Gemeinsame Abgaben von Gruppen bis zu 4 Personen

Zeigen Sie, wie man mittels Disjunktion die boolschen Werte true und false repräsentieren kann, so dass die Repräsentation semantisch korrekt ist (d.h. die Reduktion entspricht

Zeigen Sie, dass jeder Typ nur linear (in der Typlänge) viele

Aufgabe 3 (Kontroll Operatoren) (3 Punkte) Leiten Sie die Reduktionsschritte für die folgenden Kontrolloperatorreduktionen

• Intuitionistic logic, in contrast, requires that we can construct the objects whose existence we assert and hence rejects the tertium non datur

03.10.2015 Arbeite Kapitel 1 aus dem Buch Sørensen, Morten Heine B., Urzyczyn, Paweª: Lectures on the Curry- Howard Isomorphism, 1998 soweit durch, dass mindestens die

17.11.2015 Arbeite Kapitel 1 aus dem Buch Sørensen, Morten Heine B., Urzyczyn, Paweª: Lectures on the Curry- Howard Isomorphism, 1998 soweit durch, dass mindestens die