• Nie Znaleziono Wyników

Rachunek lambda, lato 2019-20

N/A
N/A
Protected

Academic year: 2021

Share "Rachunek lambda, lato 2019-20"

Copied!
112
0
0

Pełen tekst

(1)

Rachunek lambda, lato 2019-20

Wykład 4

20 marca 2020

(2)

Tydzień temu: Liczebniki Churcha

c

n

= n = λfx .f

n

(x ),

0 = λfx .x ; 1 = λfx .fx ; 2 = λfx .f (fx );

3 = λfx .f (f (fx )), etc.

(3)

Definable functions

A partial functionf : Nk −◦ N is λ-definable if there is a term F such that for all n1, . . . , nk ∈ N:

I If f (n1, . . . , nk) = m, then F n1. . . nk =β m;

I If f (n1, . . . , nk) is undefined

then F n1. . . nk does not normalize.

Theorem

Every partial computable function is definable.

(4)

Definable functions

A partial functionf : Nk −◦ N is λ-definable if there is a term F such that for all n1, . . . , nk ∈ N:

I If f (n1, . . . , nk) = m, then F n1. . . nk =β m;

I If f (n1, . . . , nk) is undefined

then F n1. . . nk does not normalize.

Theorem

Every partial computable function is definable.

(5)

Encoding a Turing Machine

We have a termNext s.t.

Next(code of C1) β (code of C2), whenever the machine can move from C1 to C2.

The function computed by the machine is λ-definable as: λx .W (Init x )W,

where

W = λc.if Halt c then λw .Out c else λw .w (Next c)w .

(6)

Encoding a Turing Machine

We have a termNext s.t.

Next(code of C1) β (code of C2), whenever the machine can move from C1 to C2.

The function computed by the machine is λ-definable as: λx .W (Init x )W,

where

W = λc.if Halt c then λw .Out c else λw .w (Next c)w .

(7)

Encoding a Turing Machine

We have a termNext s.t.

Next(code of C1) β (code of C2), whenever the machine can move from C1 to C2.

The function computed by the machine is λ-definable as:

λx .W (Init x )W, where

(8)

Computing: C

0

⇒ C

1

⇒ C

2

⇒ · · ·

⇒ C

m

F = λx .W (Init x )W,

W = λc. if Halt c then λw .Out c else λw .w (Next c)w .

F n → W (Init n)W  W C0W →

[if Halt C0 then λw .Out C0 elseλw .w (Next C0)w ]W  [λw .w (Next C0)w ]W  [λw .w C1w ]W → W C1W → [if Halt C1 then λw .Out C1 elseλw .w (Next C1)w ]W  [λw .w (Next C1)w ]W  [λw .w C2w ]W → W C2W →

· · ·  W CmW → [if Halt Cm then λw .Out Cm else λw .w (Next Cm)w ]W  [λw .Out Cm]W → Out Cm  f(n).

(9)

Computing: C

0

⇒ C

1

⇒ C

2

⇒ · · ·

⇒ C

m

F = λx .W (Init x )W,

W = λc. if Halt c then λw .Out c else λw .w (Next c)w . F n → W (Init n)W  W C0W →

[if Halt C0 then λw .Out C0 elseλw .w (Next C0)w ]W  [λw .w (Next C0)w ]W  [λw .w C1w ]W → W C1W → [if Halt C1 then λw .Out C1 elseλw .w (Next C1)w ]W  [λw .w (Next C1)w ]W  [λw .w C2w ]W → W C2W →

· · ·  W CmW → [if Halt Cm then λw .Out Cm else λw .w (Next Cm)w ]W  [λw .Out Cm]W → Out Cm  f(n).

(10)

Computing: C

0

⇒ C

1

⇒ C

2

⇒ · · ·

⇒ C

m

F = λx .W (Init x )W,

W = λc. if Halt c then λw .Out c else λw .w (Next c)w . F n → W (Init n)W  W C0W →

[if Halt C0 then λw .Out C0 elseλw .w (Next C0)w ]W 

[λw .w (Next C0)w ]W  [λw .w C1w ]W → W C1W → [if Halt C1 then λw .Out C1 elseλw .w (Next C1)w ]W  [λw .w (Next C1)w ]W  [λw .w C2w ]W → W C2W →

· · ·  W CmW → [if Halt Cm then λw .Out Cm else λw .w (Next Cm)w ]W  [λw .Out Cm]W → Out Cm  f(n).

(11)

Computing: C

0

⇒ C

1

⇒ C

2

⇒ · · ·

⇒ C

m

F = λx .W (Init x )W,

W = λc. if Halt c then λw .Out c else λw .w (Next c)w . F n → W (Init n)W  W C0W →

[if Halt C0 then λw .Out C0 elseλw .w (Next C0)w ]W  [λw .w (Next C0)w ]W  [λw .w C1w ]W → W C1W →

[if Halt C1 then λw .Out C1 elseλw .w (Next C1)w ]W  [λw .w (Next C1)w ]W  [λw .w C2w ]W → W C2W →

· · ·  W CmW → [if Halt Cm then λw .Out Cm else λw .w (Next Cm)w ]W  [λw .Out Cm]W → Out Cm  f(n).

(12)

Computing: C

0

⇒ C

1

⇒ C

2

⇒ · · ·

⇒ C

m

F = λx .W (Init x )W,

W = λc. if Halt c then λw .Out c else λw .w (Next c)w . F n → W (Init n)W  W C0W →

[if Halt C0 then λw .Out C0 elseλw .w (Next C0)w ]W  [λw .w (Next C0)w ]W  [λw .w C1w ]W → W C1W → [if Halt C1 then λw .Out C1 elseλw .w (Next C1)w ]W 

[λw .w (Next C1)w ]W  [λw .w C2w ]W → W C2W →

· · ·  W CmW → [if Halt Cm then λw .Out Cm else λw .w (Next Cm)w ]W  [λw .Out Cm]W → Out Cm  f(n).

(13)

Computing: C

0

⇒ C

1

⇒ C

2

⇒ · · ·

⇒ C

m

F = λx .W (Init x )W,

W = λc. if Halt c then λw .Out c else λw .w (Next c)w . F n → W (Init n)W  W C0W →

[if Halt C0 then λw .Out C0 elseλw .w (Next C0)w ]W  [λw .w (Next C0)w ]W  [λw .w C1w ]W → W C1W → [if Halt C1 then λw .Out C1 elseλw .w (Next C1)w ]W  [λw .w (Next C1)w ]W  [λw .w C2w ]W → W C2W →

· · ·  W CmW → [if Halt Cm then λw .Out Cm else λw .w (Next Cm)w ]W  [λw .Out Cm]W → Out Cm  f(n).

(14)

Computing: C

0

⇒ C

1

⇒ C

2

⇒ · · · ⇒ C

m

F = λx .W (Init x )W,

W = λc. if Halt c then λw .Out c else λw .w (Next c)w . F n → W (Init n)W  W C0W →

[if Halt C0 then λw .Out C0 elseλw .w (Next C0)w ]W  [λw .w (Next C0)w ]W  [λw .w C1w ]W → W C1W → [if Halt C1 then λw .Out C1 elseλw .w (Next C1)w ]W  [λw .w (Next C1)w ]W  [λw .w C2w ]W → W C2W →

· · ·  W CmW →

[if Halt Cm then λw .Out Cm else λw .w (Next Cm)w ]W  [λw .Out Cm]W → Out Cm  f(n).

(15)

Computing: C

0

⇒ C

1

⇒ C

2

⇒ · · · ⇒ C

m

F = λx .W (Init x )W,

W = λc. if Halt c then λw .Out c else λw .w (Next c)w . F n → W (Init n)W  W C0W →

[if Halt C0 then λw .Out C0 elseλw .w (Next C0)w ]W  [λw .w (Next C0)w ]W  [λw .w C1w ]W → W C1W → [if Halt C1 then λw .Out C1 elseλw .w (Next C1)w ]W  [λw .w (Next C1)w ]W  [λw .w C2w ]W → W C2W →

· · ·  W CmW → [if Halt Cm then λw .Out Cm else λw .w (Next Cm)w ]W 

[λw .Out Cm]W → Out Cm  f(n).

(16)

Computing: C

0

⇒ C

1

⇒ C

2

⇒ · · · ⇒ C

m

F = λx .W (Init x )W,

W = λc. if Halt c then λw .Out c else λw .w (Next c)w . F n → W (Init n)W  W C0W →

[if Halt C0 then λw .Out C0 elseλw .w (Next C0)w ]W  [λw .w (Next C0)w ]W  [λw .w C1w ]W → W C1W → [if Halt C1 then λw .Out C1 elseλw .w (Next C1)w ]W  [λw .w (Next C1)w ]W  [λw .w C2w ]W → W C2W →

· · ·  W CmW → [if Halt Cm then λw .Out Cm else λw .w (Next Cm)w ]W 

(17)

Question

We have definedF = λx .W (Init x )W, and

W = λc. if Halt c then λw .Out c else λw .w (Next c)w . Suppose we replace this definition by:

W = λcw .if Halt c then Out c elsew (Next c)w . Will anything change?

Answer: yes, the term W C0W would never be SN.

(18)

Question

We have definedF = λx .W (Init x )W, and

W = λc. if Halt c then λw .Out c else λw .w (Next c)w . Suppose we replace this definition by:

W = λcw .if Halt c then Out c elsew (Next c)w . Will anything change?

(19)

Computability ⇔ Definability

Twierdzenie

A partial functionf : N −◦ Nis λ-definable if and only if it is partial computable.

Dowód (⇒):

Letf be λ-definable byF.

To computef (n) reduce F nto normal form.

(20)

Computability ⇔ Definability

Twierdzenie

A partial functionf : N −◦ Nis λ-definable if and only if it is partial computable.

Dowód (⇒):

Letf be λ-definable by F.

To computef (n) reduce F n to normal form.

(21)

Computability ⇔ Definability

Twierdzenie

A partial functionf : N −◦ Nis λ-definable if and only if it is partial computable.

Dowód (⇐):

Zał.f : N −◦ Njest częściowo obliczalna. We encode the appropriate Turing Machine, and then:

I If f (n) is defined thenF n reduces to f(n).

I Otherwise we have an infinite quasi-leftmost reduction: F n  W C0W  [λw .w C1w ]W → W C1W 

[λw .w C2w ]W → W C2W  · · · ThereforeF n does not normalize.

(22)

Computability ⇔ Definability

Twierdzenie

A partial functionf : N −◦ Nis λ-definable if and only if it is partial computable.

Dowód (⇐): Zał. f : N −◦ Njest częściowo obliczalna.

We encode the appropriate Turing Machine, and then:

I If f (n) is defined thenF n reduces to f(n).

I Otherwise we have an infinite quasi-leftmost reduction: F n  W C0W  [λw .w C1w ]W → W C1W 

[λw .w C2w ]W → W C2W  · · · ThereforeF n does not normalize.

(23)

Computability ⇔ Definability

Twierdzenie

A partial functionf : N −◦ Nis λ-definable if and only if it is partial computable.

Dowód (⇐): Zał. f : N −◦ Njest częściowo obliczalna.

We encode the appropriate Turing Machine, and then:

I If f (n) is defined thenF n reduces to f(n).

I Otherwise we have an infinite quasi-leftmost reduction:

F n  W C0W  [λw .w C1w ]W → W C1W 

(24)

The following are undecidable problems:

I GivenM and N, doesM β N hold?

I GivenM and N, doesM =β N hold?

I GivenM, doesM normalize?

Proof: LetA ⊆ N be recursively enumerable, not recursive. LetχA be the partial characteristic function of A, i.e.,

χA(x ) =ifx ∈ A then0else undefined LetH lambda-define the function χA.

To decide ifn ∈ A, ask any of the questions:

I doesH n β 0 hold?

I doesH n =β 0 hold?

I doesH n have a normal form?

(25)

The following are undecidable problems:

I GivenM and N, doesM β N hold?

I GivenM and N, doesM =β N hold?

I GivenM, doesM normalize?

Proof: LetA ⊆ N be recursively enumerable, not recursive.

LetχA be the partial characteristic function of A, i.e., χA(x ) =ifx ∈ A then0else undefined LetH lambda-define the function χA.

To decide ifn ∈ A, ask any of the questions:

doesH n  0 hold?

(26)

Undecidability

The following problem is undecidable:

I GivenM, doesM ∈ SN hold?

Proof as before. To decide ifχA(n) is defined, ask ifH n is strongly normalizable.

But that requires a stronger result:

Every partial computable function is well-definable. Our coding has this property (proof omitted).

(27)

Undecidability

The following problem is undecidable:

I GivenM, doesM ∈ SN hold?

Proof as before. To decide ifχA(n) is defined, ask ifH n is strongly normalizable.

But that requires a stronger result:

Every partial computable function is well-definable. Our coding has this property (proof omitted).

(28)

Undecidability

The following problem is undecidable:

I GivenM, doesM ∈ SN hold?

Proof as before. To decide ifχA(n) is defined, ask ifH n is strongly normalizable.

But that requires a stronger result:

Every partial computable function is well-definable.

Our coding has this property (proof omitted).

(29)

Twierdzenie Rice’a

(30)

Some numbering tricks

Letn be the number of a term M. Write M forn.

This is the Church numeral for the number ofM.

There are computable functions app and num such that app(number of M)(number of N) = number of MN

num(n) = number of n. There are termsApp and Num such that

App M N =β MN and Num n =β n. Example: If the numeral2 = λfx. f (fx) has number 9, then num(2) = 9, 2 = 9, and Num 2 =β 9.

Now if 2 is the number of some M then Num M =β M = 9. SoM is the Church numeral for. . .

the number of the numeral forthe number of M.

(31)

Some numbering tricks

Letn be the number of a term M. Write M forn.

This is the Church numeral for the number ofM. There are computable functionsapp and num such that

app(number of M)(number of N) = number of MN num(n) = number of n.

There are termsApp and Num such that

App M N =β MN and Num n =β n. Example: If the numeral2 = λfx. f (fx) has number 9, then num(2) = 9, 2 = 9, and Num 2 =β 9.

Now if 2 is the number of some M then Num M =β M = 9. SoM is the Church numeral for. . .

the number of the numeral forthe number of M.

(32)

Some numbering tricks

Letn be the number of a term M. Write M forn.

This is the Church numeral for the number ofM. There are computable functionsapp and num such that

app(number of M)(number of N) = number of MN num(n) = number of n.

There are termsApp and Num such that

App M N =β MN and Num n =β n.

Example: If the numeral2 = λfx. f (fx) has number 9, then num(2) = 9, 2 = 9, and Num 2 =β 9.

Now if 2 is the number of some M then Num M =β M = 9. SoM is the Church numeral for. . .

the number of the numeral forthe number of M.

(33)

Some numbering tricks

Letn be the number of a term M. Write M forn.

This is the Church numeral for the number ofM. There are computable functionsapp and num such that

app(number of M)(number of N) = number of MN num(n) = number of n.

There are termsApp and Num such that

App M N =β MN and Num n =β n.

Example: If the numeral2 = λfx. f (fx) has number 9, then num(2) = 9,

2 = 9, and Num 2 =β 9.

Now if 2 is the number of some M then Num M =β M = 9. SoM is the Church numeral for. . .

the number of the numeral forthe number of M.

(34)

Some numbering tricks

Letn be the number of a term M. Write M forn.

This is the Church numeral for the number ofM. There are computable functionsapp and num such that

app(number of M)(number of N) = number of MN num(n) = number of n.

There are termsApp and Num such that

App M N =β MN and Num n =β n.

Example: If the numeral2 = λfx. f (fx) has number 9, then num(2) = 9, 2 = 9,

and Num 2 =β 9.

Now if 2 is the number of some M then Num M =β M = 9. SoM is the Church numeral for. . .

the number of the numeral forthe number of M.

(35)

Some numbering tricks

Letn be the number of a term M. Write M forn.

This is the Church numeral for the number ofM. There are computable functionsapp and num such that

app(number of M)(number of N) = number of MN num(n) = number of n.

There are termsApp and Num such that

App M N =β MN and Num n =β n.

Example: If the numeral2 = λfx. f (fx) has number 9, then num(2) = 9, 2 = 9, and Num 2 =β 9.

Now if 2 is the number of some M then Num M =β M = 9. SoM is the Church numeral for. . .

the number of the numeral forthe number of M.

(36)

Some numbering tricks

Letn be the number of a term M. Write M forn.

This is the Church numeral for the number ofM. There are computable functionsapp and num such that

app(number of M)(number of N) = number of MN num(n) = number of n.

There are termsApp and Num such that

App M N =β MN and Num n =β n.

Example: If the numeral2 = λfx. f (fx) has number 9, then num(2) = 9, 2 = 9, and Num 2 =β 9.

SoM is the Church numeral for. . .

the number of the numeral forthe number of M.

(37)

Some numbering tricks

Letn be the number of a term M. Write M forn.

This is the Church numeral for the number ofM. There are computable functionsapp and num such that

app(number of M)(number of N) = number of MN num(n) = number of n.

There are termsApp and Num such that

App M N =β MN and Num n =β n.

Example: If the numeral2 = λfx. f (fx) has number 9, then num(2) = 9, 2 = 9, and Num 2 =β 9.

the number of the numeral forthe number of M.

(38)

Some numbering tricks

Letn be the number of a term M. Write M forn.

This is the Church numeral for the number ofM. There are computable functionsapp and num such that

app(number of M)(number of N) = number of MN num(n) = number of n.

There are termsApp and Num such that

App M N =β MN and Num n =β n.

Example: If the numeral2 = λfx. f (fx) has number 9, then num(2) = 9, 2 = 9, and Num 2 =β 9.

(39)

A fixed-point theorem

Theorem

For every termF, there is a term X such that F (X ) =β X.

Proof

TakeX = Z Z, where Z = λx . F (App x (Num x )). Then: X = Z Z =β F (App Z (Num Z )) =β

F (App Z Z ) =β F (Z Z ) = F (X ).

(Compare X = Z Z to Yf = (λx. f (xx))(λx. f (xx)).)

(40)

A fixed-point theorem

Theorem

For every termF, there is a term X such that F (X ) =β X.

Proof

TakeX = Z Z, where Z = λx . F (App x (Num x )).

Then: X = Z Z =β F (App Z (Num Z )) =β

F (App Z Z ) =β F (Z Z ) = F (X ).

(Compare X = Z Z to Yf = (λx. f (xx))(λx. f (xx)).)

(41)

A fixed-point theorem

Theorem

For every termF, there is a term X such that F (X ) =β X.

Proof

TakeX = Z Z, where Z = λx . F (App x (Num x )). Then:

X = Z Z =β F (App Z (Num Z )) =β

F (App Z Z ) =β F (Z Z ) = F (X ).

(Compare X = Z Z to Yf = (λx. f (xx))(λx. f (xx)).)

(42)

A fixed-point theorem

Theorem

For every termF, there is a term X such that F (X ) =β X.

Proof

TakeX = Z Z, where Z = λx . F (App x (Num x )). Then:

X = Z Z =β F (App Z (Num Z )) =β

F (App Z Z ) =β F (Z Z ) = F (X ).

(43)

Rice’s theorem (Scott)

Theorem

LetAbe a set of λ-terms, which is:

I Nontrivial, i.e., not empty and not full;

I Closed under =β.

ThenA is undecidable (as a set of numbers).

Warning: Not every interesting set is closed under =β. For instance, the set SN and sets of typable terms.

(44)

Rice’s theorem (Scott)

Theorem

LetAbe a set of λ-terms, which is:

I Nontrivial, i.e., not empty and not full;

I Closed under =β.

ThenA is undecidable (as a set of numbers).

Warning: Not every interesting set is closed under =β. For instance, the set SN and sets of typable terms.

(45)

Rice’s theorem (Scott)

Theorem

LetAbe a set of λ-terms, which is:

I Nontrivial, i.e., not empty and not full;

I Closed under =β.

ThenA is undecidable (as a set of numbers).

Warning: Not every interesting set is closed under =β. For instance, the set SN and sets of typable terms.

(46)

Proof idea

SupposeAis decidable, nontrivial, and closed under =β.

We prove that there is no lambda-term F such that: FM =β 0, for M ∈ A and FM =β 1, for M 6∈ A. (If such anF existed, the set Awould be decidable.)

(But otherwise it is not enough.) TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1. LetN = YG. Then G (N) =β N.

If N ∈ A then N =β G (N) =β M2 6∈ A.

If N 6∈ A then N =β G (N) =β M1 ∈ A, contradiction.

(47)

Proof idea

SupposeAis decidable, nontrivial, and closed under =β. We prove that there is no lambda-term F such that:

FM =β 0, for M ∈ A and FM =β 1, for M 6∈ A.

(If such anF existed, the set Awould be decidable.) (But otherwise it is not enough.)

TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1. LetN = YG. Then G (N) =β N.

If N ∈ A then N =β G (N) =β M2 6∈ A.

If N 6∈ A then N =β G (N) =β M1 ∈ A, contradiction.

(48)

Proof idea

SupposeAis decidable, nontrivial, and closed under =β. We prove that there is no lambda-term F such that:

FM =β 0, for M ∈ A and FM =β 1, for M 6∈ A.

(If such anF existed, the set Awould be decidable.) (But otherwise it is not enough.)

TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1. LetN = YG. Then G (N) =β N.

If N ∈ A then N =β G (N) =β M2 6∈ A.

If N 6∈ A then N =β G (N) =β M1 ∈ A, contradiction.

(49)

Proof idea

SupposeAis decidable, nontrivial, and closed under =β. We prove that there is no lambda-term F such that:

FM =β 0, for M ∈ A and FM =β 1, for M 6∈ A.

(If such anF existed, the set Awould be decidable.) (But otherwise it is not enough.)

TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1.

LetN = YG. Then G (N) =β N. If N ∈ A then N =β G (N) =β M2 6∈ A.

If N 6∈ A then N =β G (N) =β M1 ∈ A, contradiction.

(50)

Proof idea

SupposeAis decidable, nontrivial, and closed under =β. We prove that there is no lambda-term F such that:

FM =β 0, for M ∈ A and FM =β 1, for M 6∈ A.

(If such anF existed, the set Awould be decidable.) (But otherwise it is not enough.)

TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1. LetN = YG. Then G (N) =β N.

If N ∈ A then N =β G (N) =β M2 6∈ A.

If N 6∈ A then N =β G (N) =β M1 ∈ A, contradiction.

(51)

Proof idea

SupposeAis decidable, nontrivial, and closed under =β. We prove that there is no lambda-term F such that:

FM =β 0, for M ∈ A and FM =β 1, for M 6∈ A.

(If such anF existed, the set Awould be decidable.) (But otherwise it is not enough.)

TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1. LetN = YG. Then G (N) =β N.

If N ∈ A then N = G (N) = M 6∈ A.

If N 6∈ A then N =β G (N) =β M1 ∈ A, contradiction.

(52)

Proof idea

SupposeAis decidable, nontrivial, and closed under =β. We prove that there is no lambda-term F such that:

FM =β 0, for M ∈ A and FM =β 1, for M 6∈ A.

(If such anF existed, the set Awould be decidable.) (But otherwise it is not enough.)

TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1. LetN = YG. Then G (N) =β N.

If N ∈ A then N = G (N) = M 6∈ A.

(53)

Proof of Rice’s theorem

SupposeAis decidable, nontrivial, and closed under =β.

LetF define the total characterictic function of A:

F M =β 0, for M ∈ A and F M =β 1, for M 6∈ A. TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1. LetN be such thatG (N) =β N.

If N ∈ A then N =β G (N) =β M2 6∈ A.

If N 6∈ A then N =β G (N) =β M1 ∈ A, contradiction.

(54)

Proof of Rice’s theorem

SupposeAis decidable, nontrivial, and closed under =β. LetF define the total characterictic function of A:

F M =β 0, for M ∈ A and F M =β 1, for M 6∈ A.

TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1. LetN be such thatG (N) =β N.

If N ∈ A then N =β G (N) =β M2 6∈ A.

If N 6∈ A then N =β G (N) =β M1 ∈ A, contradiction.

(55)

Proof of Rice’s theorem

SupposeAis decidable, nontrivial, and closed under =β. LetF define the total characterictic function of A:

F M =β 0, for M ∈ A and F M =β 1, for M 6∈ A.

TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1.

LetN be such thatG (N) =β N. If N ∈ A then N =β G (N) =β M2 6∈ A.

If N 6∈ A then N =β G (N) =β M1 ∈ A, contradiction.

(56)

Proof of Rice’s theorem

SupposeAis decidable, nontrivial, and closed under =β. LetF define the total characterictic function of A:

F M =β 0, for M ∈ A and F M =β 1, for M 6∈ A.

TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1. LetN be such thatG (N) =β N.

If N ∈ A then N =β G (N) =β M2 6∈ A.

If N 6∈ A then N =β G (N) =β M1 ∈ A, contradiction.

(57)

Proof of Rice’s theorem

SupposeAis decidable, nontrivial, and closed under =β. LetF define the total characterictic function of A:

F M =β 0, for M ∈ A and F M =β 1, for M 6∈ A.

TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1. LetN be such thatG (N) =β N.

If N ∈ A then N =β G (N) =β M2 6∈ A.

If N 6∈ A then N =β G (N) =β M1 ∈ A, contradiction.

(58)

Proof of Rice’s theorem

SupposeAis decidable, nontrivial, and closed under =β. LetF define the total characterictic function of A:

F M =β 0, for M ∈ A and F M =β 1, for M 6∈ A.

TakeM1 ∈ A, M2 6∈ Aand define

G = λx . if zero(Fx ) then M2 else M1. LetN be such thatG (N) =β N.

If N ∈ A then N =β G (N) =β M2 6∈ A.

If N 6∈ A then N =β G (N) =β M1 ∈ A, contradiction.

(59)

Równość w rachunku lambda

(60)

Adding equational axioms

Example 1:

Recall that 1 = λfx.fx. Add the axiomI = 1 to the equational theory of λ-calculus.

Then, for everyM, one proves:

M = IM = 1M = λx . Mx.

Example 2:

Now add the axiomK = S. Then, for everyM, one proves:

M = SI(KM)I = KI(KM)I = I. This extension is inconsistent.

(61)

Adding equational axioms

Example 1:

Recall that 1 = λfx.fx. Add the axiomI = 1 to the equational theory of λ-calculus.

Then, for everyM, one proves:

M = IM = 1M = λx . Mx.

Example 2:

Now add the axiomK = S. Then, for everyM, one proves:

M = SI(KM)I = KI(KM)I = I. This extension is inconsistent.

(62)

Adding equational axioms

Example 1:

Recall that 1 = λfx.fx. Add the axiomI = 1 to the equational theory of λ-calculus.

Then, for everyM, one proves:

M = IM = 1M = λx . Mx.

Example 2:

Now add the axiom K = S.

Then, for everyM, one proves:

M = SI(KM)I = KI(KM)I = I. This extension is inconsistent.

(63)

Adding equational axioms

Example 1:

Recall that 1 = λfx.fx. Add the axiomI = 1 to the equational theory of λ-calculus.

Then, for everyM, one proves:

M = IM = 1M = λx . Mx.

Example 2:

Now add the axiom K = S.

Then, for everyM, one proves:

(64)

Böhm’s Theorem

LetM, N be β-normal combinators with M 6=βη N. ThenM ~P =β trueand N ~P =β false, for some P.~

Moral: Any consistent lambda-theory must discriminate between beta-eta normal forms.

(65)

Böhm’s Theorem

LetM, N be β-normal combinators with M 6=βη N. ThenM ~P =β trueand N ~P =β false, for some P.~

Moral: Any consistent lambda-theory must discriminate between beta-eta normal forms.

(66)

Böhm Trees (finite case)

λxy . x λxy . x

λz. x y λzv . x y

z y z x v

M = λxy .x (λz.xzy )y N = λxy .x (λzv .xzxv )y

(67)

Böhm Trees: the difference

λxy . x λxy . x

λz. x y λzv . x y

z y z x v

M = λxy .x (λz.xzy)y N = λxy .x (λzv .xzxv )y

Trick: Applying M to λuv . hu, v igives λy . hλz.hz, y i, y i. And components can be extracted from a pair.

(68)

Böhm Trees: the difference

λxy . x λxy . x

λz. x y λzv . x y

z y z x v

M = λxy .x (λz.xzy)y N = λxy .x (λzv .xzxv )y

(69)

Discriminating terms

M = λxy .x (λz.xzy)y N = λxy .x (λzv .xzxv )y

Applying M and N to P = λuv . hu, v i, then to any Q yields: hλz.hz, Qi, Qi hλzv .hz, Piv , Qi

Next appply both to true, I, false to obtain:

λz.hz, Qi λzv .hz, Piv

hI, Qi λv . hI, Piv

Q P = λuv .hu, v i

ChooseQ = λuvw . true and apply both sides tofalse, I, true:

true false.

(70)

Discriminating terms

M = λxy .x (λz.xzy)y N = λxy .x (λzv .xzxv )y Applying M and N to P = λuv . hu, v i, then to any Q yields:

hλz.hz, Qi, Qi hλzv .hz, Piv , Qi

Next appply both to true, I, false to obtain:

λz.hz, Qi λzv .hz, Piv

hI, Qi λv . hI, Piv

Q P = λuv .hu, v i

ChooseQ = λuvw . true and apply both sides tofalse, I, true:

true false.

(71)

Discriminating terms

M = λxy .x (λz.xzy)y N = λxy .x (λzv .xzxv )y Applying M and N to P = λuv . hu, v i, then to any Q yields:

hλz.hz, Qi, Qi hλzv .hz, Piv , Qi Next appply both to true, I, false to obtain:

λz.hz, Qi λzv .hz, Piv

hI, Qi λv . hI, Piv

Q P = λuv .hu, v i

ChooseQ = λuvw . true and apply both sides tofalse, I, true:

true false.

(72)

Discriminating terms

M = λxy .x (λz.xzy)y N = λxy .x (λzv .xzxv )y Applying M and N to P = λuv . hu, v i, then to any Q yields:

hλz.hz, Qi, Qi hλzv .hz, Piv , Qi Next appply both to true, I, false to obtain:

λz.hz, Qi λzv .hz, Piv

hI, Qi λv . hI, Piv

Q P = λuv .hu, v i

ChooseQ = λuvw . true and apply both sides tofalse, I, true:

true false.

(73)

Discriminating terms

M = λxy .x (λz.xzy)y N = λxy .x (λzv .xzxv )y Applying M and N to P = λuv . hu, v i, then to any Q yields:

hλz.hz, Qi, Qi hλzv .hz, Piv , Qi Next appply both to true, I, false to obtain:

λz.hz, Qi λzv .hz, Piv

hI, Qi λv . hI, Piv

Q P = λuv .hu, v i

ChooseQ = λuvw . true and apply both sides tofalse, I, true:

true false.

(74)

Discriminating terms

M = λxy .x (λz.xzy)y N = λxy .x (λzv .xzxv )y Applying M and N to P = λuv . hu, v i, then to any Q yields:

hλz.hz, Qi, Qi hλzv .hz, Piv , Qi Next appply both to true, I, false to obtain:

λz.hz, Qi λzv .hz, Piv

hI, Qi λv . hI, Piv

Q P = λuv .hu, v i

ChooseQ = λuvw . true and apply both sides tofalse, I, true:

true false.

(75)

Discriminating terms

M = λxy .x (λz.xzy)y N = λxy .x (λzv .xzxv )y Applying M and N to P = λuv . hu, v i, then to any Q yields:

hλz.hz, Qi, Qi hλzv .hz, Piv , Qi Next appply both to true, I, false to obtain:

λz.hz, Qi λzv .hz, Piv

hI, Qi λv . hI, Piv

Q P = λuv .hu, v i

(76)

Twierdzenie Böhma: szkic dowodu

I Tuple creation operator

Tp = λx1. . . xp. hx1, . . . , xpi = λx1. . . xpλf . fx1. . . xp.

I SubstitutionS = [xi := Tpi]i =1,...,n is an m-substitution, whenp1, . . . , pn> m, and all pis are different.

I TermsM i N arem-discriminable, when for every m-substitution S there are combinators ~L with:

M[S ]~L β true and N[S ]~L β false.

(77)

Twierdzenie Böhma: szkic dowodu

I Tuple creation operator

Tp = λx1. . . xp. hx1, . . . , xpi = λx1. . . xpλf . fx1. . . xp.

I SubstitutionS = [xi := Tpi]i =1,...,n is an m-substitution, whenp1, . . . , pn> m, and all pis are different.

I TermsM i N arem-discriminable, when for every m-substitution S there are combinators ~L with:

M[S ]~L β true and N[S ]~L β false.

(78)

Twierdzenie Böhma: szkic dowodu

I Tuple creation operator

Tp = λx1. . . xp. hx1, . . . , xpi = λx1. . . xpλf . fx1. . . xp.

I SubstitutionS = [xi := Tpi]i =1,...,n is an m-substitution, whenp1, . . . , pn> m, and all pis are different.

I TermsM i N arem-discriminable, when for every m-substitution S there are combinators ~L with:

M[S ]~L  true and N[S ]~L  false.

(79)

Twierdzenie Böhma: main lemma

If M i N are normal and M 6=βη N,

then M i N arem-discriminable for almost everym.

Czyli:

for every m-substitution S, there are ~L, s.t.

M[S ]~L β true oraz N[S ]~L β false.

(80)

Twierdzenie Böhma: main lemma

If M i N are normal and M 6=βη N,

then M i N arem-discriminable for almost everym.

Czyli:

for everym-substitution S, there are ~L, s.t.

M[S ]~L β true oraz N[S ]~L β false.

(81)

Twierdzenie Böhma: main lemma

If M i N are normal and M 6=βη N,

then M i N arem-discriminable for almost everym.

Proof: Induction with respect to sum of lengths ofM, N. W.o.l.o.g., M = xP1. . . Pk and N = yQ1. . . Q`. Indeed:

I to discriminateλx M iλx N means to discriminate M iN;

I a missing lambda can be added: take λx Mx forM.

(82)

Twierdzenie Böhma: main lemma

If M i N are normal and M 6=βη N,

then M i N arem-discriminable for almost everym.

Proof: Induction with respect to sum of lengths ofM, N. W.o.l.o.g., M = xP1. . . Pk and N = yQ1. . . Q`. Indeed:

I to discriminateλx M iλx N means to discriminateM iN;

I a missing lambda can be added: take λx Mx forM.

(83)

Twierdzenie Böhma: main lemma

If M i N are normal and M 6=βη N,

then M i N arem-discriminable for almost everym.

Dowód: Induction with respect to sum of lengths of M, N. W.o.l.o.g., M = xP1. . . Pk and N = yQ1. . . Q`. Then:

M[S ] = TpP1[S ]...Pk[S ] β λ~uhP1[S ], ..., Pk[S ], u1, ..., up−ki N[S ] = TqQ1[S ]...Q`[S ] β λ~v hQ1[S ], ..., Q`[S ], v1, ..., vq−`i Base cases: x 6= y or x = y but k 6= `: exercise.

If x = y and k = ` then Pi 6=βη Qi, for some i. Project on the i-th coordinate and apply induction.

(84)

Twierdzenie Böhma: main lemma

If M i N are normal and M 6=βη N,

then M i N arem-discriminable for almost everym.

Dowód: Induction with respect to sum of lengths of M, N.

W.o.l.o.g., M = xP1. . . Pk and N = yQ1. . . Q`. Then:

M[S ] = TpP1[S ]...Pk[S ] β λ~uhP1[S ], ..., Pk[S ], u1, ..., up−ki N[S ] = TqQ1[S ]...Q`[S ] β λ~v hQ1[S ], ..., Q`[S ], v1, ..., vq−`i

Base cases: x 6= y or x = y but k 6= `: exercise. If x = y and k = ` then Pi 6=βη Qi, for some i. Project on the i-th coordinate and apply induction.

(85)

Twierdzenie Böhma: main lemma

If M i N are normal and M 6=βη N,

then M i N arem-discriminable for almost everym.

Dowód: Induction with respect to sum of lengths of M, N.

W.o.l.o.g., M = xP1. . . Pk and N = yQ1. . . Q`. Then:

M[S ] = TpP1[S ]...Pk[S ] β λ~uhP1[S ], ..., Pk[S ], u1, ..., up−ki N[S ] = TqQ1[S ]...Q`[S ] β λ~v hQ1[S ], ..., Q`[S ], v1, ..., vq−`i Base cases: x 6= y or x = y but k 6= `: exercise.

If x = y and k = ` then Pi 6=βη Qi, for some i. Project on the i-th coordinate and apply induction.

(86)

Twierdzenie Böhma: main lemma

If M i N are normal and M 6=βη N,

then M i N arem-discriminable for almost everym.

Dowód: Induction with respect to sum of lengths of M, N.

W.o.l.o.g., M = xP1. . . Pk and N = yQ1. . . Q`. Then:

M[S ] = TpP1[S ]...Pk[S ] β λ~uhP1[S ], ..., Pk[S ], u1, ..., up−ki N[S ] = TqQ1[S ]...Q`[S ] β λ~v hQ1[S ], ..., Q`[S ], v1, ..., vq−`i Base cases: x 6= y or x = y but k 6= `: exercise.

If x = y and k = ` then Pi 6=βη Qi, for some i. Project on the -th coordinate and apply induction.

(87)

The standard theory

(88)

The Meaning of “Value” and “Undefined”

First idea: Value = Normal form.

Undefined = without normal form.

Can we identify all such terms?

No: for instance λx .x KΩ = λx .x SΩ implies K = S (apply both toK).

Moral: A term without normal form can still behave in a well-defined way. In a sense it has a “value”. Better idea: Value = Head normal form. Undefined = without head normal form.

(89)

The Meaning of “Value” and “Undefined”

First idea: Value = Normal form.

Undefined = without normal form.

Can we identify all such terms?

No: for instance λx .x KΩ = λx .x SΩ implies K = S (apply both toK).

Moral: A term without normal form can still behave in a well-defined way. In a sense it has a “value”. Better idea: Value = Head normal form. Undefined = without head normal form.

(90)

The Meaning of “Value” and “Undefined”

First idea: Value = Normal form.

Undefined = without normal form.

Can we identify all such terms?

No: for instance λx .x KΩ = λx .x SΩ impliesK = S (apply both toK).

Moral: A term without normal form can still behave in a well-defined way. In a sense it has a “value”. Better idea: Value = Head normal form. Undefined = without head normal form.

(91)

The Meaning of “Value” and “Undefined”

First idea: Value = Normal form.

Undefined = without normal form.

Can we identify all such terms?

No: for instance λx .x KΩ = λx .x SΩ impliesK = S (apply both toK).

Moral: A term without normal form can still behave in a well-defined way. In a sense it has a “value”.

Better idea: Value = Head normal form. Undefined = without head normal form.

(92)

The Meaning of “Value” and “Undefined”

First idea: Value = Normal form.

Undefined = without normal form.

Can we identify all such terms?

No: for instance λx .x KΩ = λx .x SΩ impliesK = S (apply both toK).

Moral: A term without normal form can still behave in a well-defined way. In a sense it has a “value”.

(93)

Solvability

A closed term is solvable iff M ~P =β I, for some closed P~. If FV(M) = ~x then M is solvable iff λ~x M is solvable.

Theorem

A term is solvable iff it has a head normal form. Proof for closed terms:

(⇒) IfM ~P =β I then M ~P β I. If M ~P head normalizes then alsoM must head normalize.

(⇐) IfM =β λx1x2. . . xn.xiR1. . . Rm then MP . . . P =β I, forP = λy1. . . ym.I.

(94)

Solvability

A closed term is solvable iff M ~P =β I, for some closed P~. If FV(M) = ~x then M is solvable iff λ~x M is solvable.

Theorem

A term is solvable iff it has a head normal form.

Proof for closed terms:

(⇒) IfM ~P =β I then M ~P β I. If M ~P head normalizes then alsoM must head normalize.

(⇐) IfM =β λx1x2. . . xn.xiR1. . . Rm then MP . . . P =β I, forP = λy1. . . ym.I.

(95)

Solvability

A closed term is solvable iff M ~P =β I, for some closed P~. If FV(M) = ~x then M is solvable iff λ~x M is solvable.

Theorem

A term is solvable iff it has a head normal form.

Proof for closed terms:

(⇒) IfM ~P =β I then M ~P β I. If M ~P head normalizes then alsoM must head normalize.

(⇐) IfM =β λx1x2. . . xn.xiR1. . . Rm then MP . . . P =β I,

(96)

The standard theory

We identify all unsolvable terms as “undefined”.

Which solvable terms may be now be consistently identified?

We cannot classify terms by their head normal forms. Too many of them!

We can onlyobserve their behaviour.

(97)

The standard theory

We identify all unsolvable terms as “undefined”.

Which solvable terms may be now be consistently identified?

We cannot classify terms by their head normal forms.

Too many of them!

We can onlyobserve their behaviour.

(98)

The standard theory

We identify all unsolvable terms as “undefined”.

Which solvable terms may be now be consistently identified?

We cannot classify terms by their head normal forms.

Too many of them!

We can onlyobserve their behaviour.

(99)

Observational equivalence

TermsM, N with FV(M) ∪FV(N) = ~x, are observationally equivalent (M ≡ N) when, for all closed P:

P(λ~x .M) is solvable ⇐⇒ P(λ~x .N) is solvable

Put it differently: for any “context” C [ ]:

C [M] is solvable ⇐⇒ C [N] is solvable Note: If M =η N then M ≡ N.

(100)

Observational equivalence

TermsM, N with FV(M) ∪FV(N) = ~x, are observationally equivalent (M ≡ N) when, for all closed P:

P(λ~x .M) is solvable ⇐⇒ P(λ~x .N) is solvable Put it differently: for any “context” C [ ]:

C [M] is solvable ⇐⇒ C [N] is solvable

Note: If M =η N then M ≡ N.

(101)

Observational equivalence

TermsM, N with FV(M) ∪FV(N) = ~x, are observationally equivalent (M ≡ N) when, for all closed P:

P(λ~x .M) is solvable ⇐⇒ P(λ~x .N) is solvable Put it differently: for any “context” C [ ]:

C [M] is solvable ⇐⇒ C [N] is solvable Note: If M =η N then M ≡ N.

(102)

Böhm Trees

BT (λ~x .yP1. . . Pn) = λ~x . y

BT (P1) BT (P2) . . . BT (Pn)

(103)

Example: J = Y(λfxy . x(fy ))

Write Φfor λfxy . x (fy )). Then:

J = YΦ =β ΦJ

=β λxy0. x (Jy0) =β λxy0. x (ΦJy0)

=β λxy0. x (λy1. y0(Jy1)) =β λxy0. x (λy1. y0(ΦJy1)) =β . . .

The treeBT (J) consists of one infinite path: λxy0. x ——λy1. y0——λy2. y1——λy3. y2—— · · ·

(104)

Example: J = Y(λfxy . x(fy ))

Write Φfor λfxy . x (fy )). Then:

J = YΦ =β ΦJ =β λxy0. x (Jy0)

=β λxy0. x (ΦJy0)

=β λxy0. x (λy1. y0(Jy1)) =β λxy0. x (λy1. y0(ΦJy1)) =β . . .

The treeBT (J) consists of one infinite path: λxy0. x ——λy1. y0——λy2. y1——λy3. y2—— · · ·

(105)

Example: J = Y(λfxy . x(fy ))

Write Φfor λfxy . x (fy )). Then:

J = YΦ =β ΦJ =β λxy0. x (Jy0) =β λxy0. x (ΦJy0)

=β λxy0. x (λy1. y0(Jy1)) =β λxy0. x (λy1. y0(ΦJy1)) =β . . .

The treeBT (J) consists of one infinite path: λxy0. x ——λy1. y0——λy2. y1——λy3. y2—— · · ·

(106)

Example: J = Y(λfxy . x(fy ))

Write Φfor λfxy . x (fy )). Then:

J = YΦ =β ΦJ =β λxy0. x (Jy0) =β λxy0. x (ΦJy0)

=β λxy0. x (λy1. y0(Jy1))

=β λxy0. x (λy1. y0(ΦJy1)) =β . . .

The treeBT (J) consists of one infinite path: λxy0. x ——λy1. y0——λy2. y1——λy3. y2—— · · ·

(107)

Example: J = Y(λfxy . x(fy ))

Write Φfor λfxy . x (fy )). Then:

J = YΦ =β ΦJ =β λxy0. x (Jy0) =β λxy0. x (ΦJy0)

=β λxy0. x (λy1. y0(Jy1)) =β λxy0. x (λy1. y0(ΦJy1)) =β . . .

The treeBT (J) consists of one infinite path: λxy0. x ——λy1. y0——λy2. y1——λy3. y2—— · · ·

(108)

Example: J = Y(λfxy . x(fy ))

Write Φfor λfxy . x (fy )). Then:

J = YΦ =β ΦJ =β λxy0. x (Jy0) =β λxy0. x (ΦJy0)

=β λxy0. x (λy1. y0(Jy1)) =β λxy0. x (λy1. y0(ΦJy1)) =β . . .

The treeBT (J) consists of one infinite path:

λxy0. x ——λy1. y0——λy2. y1——λy3. y2—— · · ·

(109)

Example: J = Y(λfxy . x(fy ))

The treeBT (J) consists of one infinite path:

λxy0. x ——λy1. y0——λy2. y1——λy3. y2—— · · ·

The treeBT (I) consists of a single node: λx x

The first can be obtained from the second by means of an infinite sequence ofη-expansions:

λx x η← λxy0. x ——y0 η← λxy0. x ——λy1. y0——y1

(110)

Example: J = Y(λfxy . x(fy ))

The treeBT (J) consists of one infinite path:

λxy0. x ——λy1. y0——λy2. y1——λy3. y2—— · · ·

The treeBT (I) consists of a single node: λx x

The first can be obtained from the second by means of an infinite sequence ofη-expansions:

λx x η← λxy0. x ——y0 η← λxy0. x ——λy1. y0——y1

(111)

Example: J = Y(λfxy . x(fy ))

The treeBT (J) consists of one infinite path:

λxy0. x ——λy1. y0——λy2. y1——λy3. y2—— · · ·

The treeBT (I) consists of a single node: λx x

The first can be obtained from the second by means of an infinite sequence ofη-expansions:

η← λxy0. x ——λy1. y0——y1

(112)

Example: J = Y(λfxy . x(fy ))

The treeBT (J) consists of one infinite path:

λxy0. x ——λy1. y0——λy2. y1——λy3. y2—— · · ·

The treeBT (I) consists of a single node: λx x

The first can be obtained from the second by means of an infinite sequence ofη-expansions:

Cytaty

Powiązane dokumenty

For every number n of a type derivation for a lambda-term M there exists m such that every number of a finite reduction sequence of M is less

For every number n of a type derivation for a lambda-term M there exists m such that every number of a finite reduction sequence of M is less than m... Strong Normalization.. For

Uwaga: Klasyczny rachunek zdań jest.. Statman): Inhabitation in simple types is decidable and P SPACE -complete.?. Wniosek: To samo dotyczy minimalnego

(Potem zredukujemy J do typu bool → word.).. Typy proste: semantyka.. Schubert’97):.. Nierozstrzygalność drugiego rzędu nawet wtedy, gdy niewiadome nie są

I Validity/provability in second-order classical propositional logic (known as the QBF problem) is P SPACE -complete.. I Provability in second-order intuitionistic propositional

Twierdzenie ( Löb, 1976, Gabbay, 1974, Sobolew, 1977) Problem inhabitacji:.. Dany typ τ , czy istnieje term zamknięty M

I Przedmiotem dziaªania mo»e by¢ cokolwiek, zatem.. funkcja nie ma a priori

M = λ~x.(λy.P)Q~R → β λ~ x.P[y := Q]~R = N is called