• Aucun résultat trouvé

Exercises on λ-calculus and Deduction Systems

N/A
N/A
Protected

Academic year: 2022

Partager "Exercises on λ-calculus and Deduction Systems"

Copied!
57
0
0

Texte intégral

(1)

Exercises on λ-calculus and Deduction Systems

Akim Demailleakim@lrde.epita.fr

EPITA — École Pour l’Informatique et les Techniques Avancées

June 10, 2016

(2)

Exercises on λ-calculus and Deduction Systems

1 λ-calculus

2 Deduction Systems

(3)

λ-calculus

1 λ-calculus

Untypedλ-calculus Simply Typedλ-calculus

2 Deduction Systems

(4)

Untyped λ-calculus

1 λ-calculus

Untypedλ-calculus Simply Typedλ-calculus

2 Deduction Systems

(5)

Substitutions

[λz·zz/x]λy·xy ≡

λy·(λz·zz)y [yy/z](λxy·zy) ≡ λxu·yyu

(6)

Substitutions

[λz·zz/x]λy·xy ≡ λy·(λz·zz)y [yy/z](λxy·zy) ≡

λxu·yyu

(7)

Substitutions

[λz·zz/x]λy·xy ≡ λy·(λz·zz)y [yy/z](λxy·zy) ≡ λxu·yyu

(8)

β-Reductions

(λx·xyx)λz·z →

(λz·z)y(λz·z) (λx·x)((λy·y)x) → (λx·x)(x) (λx·x)((λy·y)x) → ((λy·y)x) (λx·x)((λy·y)x) → x

(λx·xx)((λx·xx)y) → yy(yy) (λx·xx)((λx·x)y) → yy (λx·x)((λx·xx)y) → yy

(9)

β-Reductions

(λx·xyx)λz·z → (λz·z)y(λz·z) (λx·x)((λy·y)x) →

(λx·x)(x) (λx·x)((λy·y)x) → ((λy·y)x) (λx·x)((λy·y)x) → x

(λx·xx)((λx·xx)y) → yy(yy) (λx·xx)((λx·x)y) → yy (λx·x)((λx·xx)y) → yy

(10)

β-Reductions

(λx·xyx)λz·z → (λz·z)y(λz·z) (λx·x)((λy·y)x) → (λx·x)(x) (λx·x)((λy·y)x) →

((λy·y)x) (λx·x)((λy·y)x) → x

(λx·xx)((λx·xx)y) → yy(yy) (λx·xx)((λx·x)y) → yy (λx·x)((λx·xx)y) → yy

(11)

β-Reductions

(λx·xyx)λz·z → (λz·z)y(λz·z) (λx·x)((λy·y)x) → (λx·x)(x) (λx·x)((λy·y)x) → ((λy·y)x) (λx·x)((λy·y)x) →

x (λx·xx)((λx·xx)y) → yy(yy)

(λx·xx)((λx·x)y) → yy (λx·x)((λx·xx)y) → yy

(12)

β-Reductions

(λx·xyx)λz·z → (λz·z)y(λz·z) (λx·x)((λy·y)x) → (λx·x)(x) (λx·x)((λy·y)x) → ((λy·y)x) (λx·x)((λy·y)x) → x

(λx·xx)((λx·xx)y) →

yy(yy) (λx·xx)((λx·x)y) → yy (λx·x)((λx·xx)y) → yy

(13)

β-Reductions

(λx·xyx)λz·z → (λz·z)y(λz·z) (λx·x)((λy·y)x) → (λx·x)(x) (λx·x)((λy·y)x) → ((λy·y)x) (λx·x)((λy·y)x) → x

(λx·xx)((λx·xx)y) → yy(yy) (λx·xx)((λx·x)y) →

yy (λx·x)((λx·xx)y) → yy

(14)

β-Reductions

(λx·xyx)λz·z → (λz·z)y(λz·z) (λx·x)((λy·y)x) → (λx·x)(x) (λx·x)((λy·y)x) → ((λy·y)x) (λx·x)((λy·y)x) → x

(λx·xx)((λx·xx)y) → yy(yy) (λx·xx)((λx·x)y) → yy (λx·x)((λx·xx)y) →

yy

(15)

β-Reductions

(λx·xyx)λz·z → (λz·z)y(λz·z) (λx·x)((λy·y)x) → (λx·x)(x) (λx·x)((λy·y)x) → ((λy·y)x) (λx·x)((λy·y)x) → x

(λx·xx)((λx·xx)y) → yy(yy) (λx·xx)((λx·x)y) → yy (λx·x)((λx·xx)y) → yy

(16)

Simply Typed λ-calculus

1 λ-calculus

Untypedλ-calculus Simply Typedλ-calculus

2 Deduction Systems

(17)

Simply Typed λ-calculus

Type derivations are trees built from the following nodes.

M :σ→τ N:σ MN :τ

[

x :σ

]

··

· M :τ

λx·M :σ →τ

(18)

Simply Typed λ-calculus

Type derivations are trees built from the following nodes.

M :σ→τ N:σ MN :τ

[

x :σ

]

··

· M :τ

λx·M :σ →τ

(19)

Simply Typed λ-calculus

Type derivations are trees built from the following nodes.

M :σ→τ N:σ MN :τ

[x :σ]

··

· M :τ λx·M :σ →τ

(20)

Type Statements

Typeλfx·f(fx)

`λfx·f(fx) : (σ→σ)→σ→σ

[f :σ →σ](2)

[f :σ→σ](2) [x:σ](1) fx:σ

f(fx) :σ

(1) λx·f(fx) :σ →σ

(2) λfx·f(fx) : (σ →σ)→σ→σ

(21)

Type Statements

Typeλfx·f(fx)

`λfx·f(fx) : (σ→σ)→σ→σ

[f :σ →σ](2)

[f :σ→σ](2) [x:σ](1) fx:σ

f(fx) :σ

(1) λx·f(fx) :σ →σ

(2) λfx·f(fx) : (σ →σ)→σ→σ

(22)

Type Statements

Typeλfx·f(fx)

`λfx·f(fx) : (σ→σ)→σ→σ

[f :σ →σ](2)

[f :σ→σ](2) [x:σ](1) fx:σ

f(fx) :σ

(1) λx·f(fx) :σ →σ

(2) λfx·f(fx) : (σ →σ)→σ →σ

(23)

Type Statements

Typeλxy·x

`λxy·x :σ→τ →σ

[x :σ](1) λy·x :τ →σ

(1) λxy ·x :σ→τ →σ

(24)

Type Statements

Typeλxy·x

`λxy·x :σ→τ →σ

[x :σ](1) λy·x :τ →σ

(1) λxy ·x :σ→τ →σ

(25)

Type Statements

Typeλxy·x

`λxy·x :σ→τ →σ

[x :σ](1) λy·x :τ →σ

(1) λxy ·x :σ→τ →σ

(26)

Deduction Systems

1 λ-calculus

2 Deduction Systems Natural Deduction Sequent Calculus

(27)

Natural Deduction

1 λ-calculus

2 Deduction Systems Natural Deduction Sequent Calculus

(28)

Intuitionistic Natural Deduction

[A]·

··

B ⇒I A⇒B

A A⇒B

⇒E B

⊥E A

¬A:=A⇒ ⊥

A B

∧I A∧B

A∧B

∧lE A

A∧B

∧rE B

A ∨lI A∨B

B ∨rI

A∨B A∨B [A]·

·· C

[B]

··

· C

(29)

Prove A ∧ B ⇒ B ∧ A

[A∧B]1

∧rE B

[A∧B]1

∧lE A∧I B∧A

⇒I1 A∧B ⇒B∧A

(30)

Prove A ∧ B ⇒ B ∧ A

[A∧B]1

∧rE B

[A∧B]1

∧lE A∧I B∧A

⇒I1 A∧B ⇒B∧A

(31)

Prove A ∧ (B ∨ C ) ` (A ∧ B) ∨ (A ∧ C )

A(BC)

∧rE BC

A(BC)

∧lE

A [B]1

∧I AB

∨lI (AB)(AC)

A(BC)

∧lE A [C]1

∧I AC

∨rI (AB)(AC)

∨E1 (A∧B)∨(A∧C)

(32)

Prove A ∧ (B ∨ C ) ` (A ∧ B) ∨ (A ∧ C )

A(BC)

∧rE BC

A(BC)

∧lE

A [B]1

∧I AB

∨lI (AB)(AC)

A(BC)

∧lE A [C]1

∧I AC

∨rI (AB)(AC)

∨E1 (A∧B)∨(A∧C)

(33)

Prove (A ⇒ A) ⇒ A ⇒ A (LOFO-2005)

Remember,⇒ is right-associative.

[A]2 [A⇒A]1

⇒E A ⇒I2 A⇒A

⇒I1 (A⇒A)⇒A⇒A

[A]1

⇒I1 A⇒A

⇒I (A⇒A)⇒A⇒A

[A⇒A]1

⇒I1 (A⇒A)⇒A⇒A

(34)

Prove (A ⇒ A) ⇒ A ⇒ A (LOFO-2005)

Remember,⇒ is right-associative.

[A]2 [A⇒A]1

⇒E A ⇒I2 A⇒A

⇒I1 (A⇒A)⇒A⇒A

[A]1

⇒I1 A⇒A

⇒I (A⇒A)⇒A⇒A

[A⇒A]1

⇒I1 (A⇒A)⇒A⇒A

(35)

Prove (A ⇒ A) ⇒ A ⇒ A (LOFO-2005)

Remember,⇒ is right-associative.

[A]2 [A⇒A]1

⇒E A ⇒I2 A⇒A

⇒I1 (A⇒A)⇒A⇒A

[A]1

⇒I1 A⇒A

⇒I (A⇒A)⇒A⇒A

[A⇒A]1

⇒I1 (A⇒A)⇒A⇒A

(36)

Prove (A ⇒ A) ⇒ A ⇒ A (LOFO-2005)

Remember,⇒ is right-associative.

[A]2 [A⇒A]1

⇒E A ⇒I2 A⇒A

⇒I1 (A⇒A)⇒A⇒A

[A]1

⇒I1 A⇒A

⇒I (A⇒A)⇒A⇒A

[A⇒A]1

⇒I1 (A⇒A)⇒A⇒A

(37)

Prove A ⇒ B , B ⇒ C ` A ⇒ (B ∧ C ) (LOFO-2005)

[A]1 A⇒B

⇒E B

[A]1 A⇒B

⇒E

B B⇒C

⇒E C ∧I

B∧C

⇒I1 A⇒(B∧C)

(38)

Prove A ⇒ B , B ⇒ C ` A ⇒ (B ∧ C ) (LOFO-2005)

[A]1 A⇒B

⇒E B

[A]1 A⇒B

⇒E

B B⇒C

⇒E C ∧I

B∧C

⇒I1 A⇒(B∧C)

(39)

Prove A ∨ B , ¬B ` A (Intuitionistic) (LOFO-2005)

Recall that¬B :=B ⇒ ⊥.

A∨B [A]1

[B]1 B ⇒ ⊥

⊥ ⇒E

⊥E A∨E1 A

(40)

Prove A ∨ B , ¬B ` A (Intuitionistic) (LOFO-2005)

Recall that¬B :=B ⇒ ⊥.

A∨B [A]1

[B]1 B ⇒ ⊥

⊥ ⇒E

⊥E A∨E1 A

(41)

Prove A ∨ B , ¬B ` A (Intuitionistic) (LOFO-2005)

Recall that¬B :=B ⇒ ⊥.

A∨B [A]1

[B]1 B ⇒ ⊥

⊥ ⇒E

⊥E A∨E1 A

(42)

Sequent Calculus

1 λ-calculus

2 Deduction Systems Natural Deduction Sequent Calculus

(43)

Classical Sequent Calculus

Γ`

`X Γ`τ(∆)

Γ` X`

σ(Γ)`

Γ`

`W Γ`A,

Γ` W`

Γ,A`

Γ`A,A,∆

`C Γ`A,∆

Γ,A,A` C` Γ,A`

Id F`F

Γ`A, Γ0,A`0 Cut Γ,Γ0`∆,0 Γ,A`

` ¬ Γ` ¬A,∆

Γ`A,

¬ ` Γ,¬A` Γ`A,∆ Γ`B,∆

` ∧ Γ`AB,

Γ,A` l∧ ` Γ,AB`

Γ,B` r∧ ` Γ,AB` Γ`A,∆

`l∨

Γ`B,

`r

Γ,A` Γ,B`

∨ `

(44)

Prove A ∧ B ` A ∧ B

A`A l∧ ` A∧B `A

B `B

r∧ ` A∧B `B

` ∧ A∧B `A∧B

(45)

Prove A ∧ B ` A ∧ B

A`A l∧ ` A∧B `A

B `B

r∧ ` A∧B `B

` ∧ A∧B `A∧B

(46)

Prove A ∧ B ` A ∨ B

A`A l∧ ` A∧B `A

`r∨ A∧B `A∨B

(47)

Prove A ∧ B ` A ∨ B

A`A l∧ ` A∧B `A

`r∨ A∧B `A∨B

(48)

Prove A ∨ B ` A ∨ B

A`A

`l∨ A`A∨B

B `B

`r∨ B `A∨B

∨ ` A∨B `A∨B

(49)

Prove A ∨ B ` A ∨ B

A`A

`l∨

A`A∨B

B `B

`r∨ B `A∨B

∨ ` A∨B `A∨B

(50)

Prove (F ∧ G ) ⇒ H ` (F ⇒ H ) ∨ (G ⇒ H )

F `F W` F,G `F

G `G W` F,G `G

` ∧

F,G `F ∧G H `H

⇒` F,G,(F ∧G)⇒H`H

`W F,G,(F ∧G)⇒H`H,H

`⇒ F,(F ∧G)⇒H`H,G ⇒H

`⇒ (F ∧G)⇒H`F ⇒H,G ⇒H

`r∨ (F ∧G)⇒H `(F ⇒H)∨(G ⇒H),G ⇒H

`l∨ (F ∧G)⇒H`(F ⇒H)∨(G ⇒H),(F ⇒H)∨(G ⇒H)

`C (F ∧G)⇒H`(F ⇒H)∨(G ⇒H)

(51)

Prove (F ∧ G ) ⇒ H ` (F ⇒ H ) ∨ (G ⇒ H )

F `F W`

F,G `F

G `G W` F,G `G

` ∧

F,G `F ∧G H `H

⇒`

F,G,(F ∧G)⇒H`H

`W F,G,(F ∧G)⇒H`H,H

`⇒

F,(F ∧G)⇒H`H,G ⇒H

`⇒

(F ∧G)⇒H`F ⇒H,G ⇒H

`r∨ (F ∧G)⇒H `(F ⇒H)∨(G ⇒H),G ⇒H

`l∨

(52)

Prove (A ⇒ A) ⇒ A ⇒ A (LOFO-2005)

A`A A`A

⇒` A,A⇒A`A

`⇒ A⇒A`A⇒A

`(A⇒A)⇒A⇒A`⇒

(53)

Prove (A ⇒ A) ⇒ A ⇒ A (LOFO-2005)

A`A A`A

⇒`

A,A⇒A`A

`⇒

A⇒A`A⇒A

`(A⇒A)⇒A⇒A`⇒

(54)

Prove A ⇒ B , B ⇒ C ` A ⇒ (B ∧ C ) (LOFO-2005)

A`A B`B

⇒` A,A⇒B `B

W` A,A⇒B,B ⇒C `B

A`A C `C

⇒` A,B ⇒C `C

W` A,A⇒B,B ⇒C `C

∧ ` A,A⇒B,A,B⇒C `B∧C

C` A,A⇒B,B ⇒C `B∧C

(55)

Prove A ⇒ B , B ⇒ C ` A ⇒ (B ∧ C ) (LOFO-2005)

A`A B `B

⇒`

A,A⇒B `B

W` A,A⇒B,B ⇒C `B

A`A C `C

⇒`

A,B ⇒C `C

W`

A,A⇒B,B ⇒C `C

∧ ` A,A⇒B,A,B⇒C `B∧C

C` A,A⇒B,B ⇒C `B∧C

(56)

Prove A ∨ B , ¬B ` A (Classical) (LOFO-2005)

A`A W` A,¬B `A

B `B

`W B `B,A

` ¬ B,¬B `A

∨ ` A∨B,¬B `A

(57)

Prove A ∨ B , ¬B ` A (Classical) (LOFO-2005)

A`A W` A,¬B `A

B `B

`W B `B,A

` ¬ B,¬B `A

∨ ` A∨B,¬B `A

Références

Documents relatifs

2. A crucial tool, in this approach, is the notion of storage operator, to be defined later. As is well known, in call-by-name λ-calculus, a function must compute its argument

Abstraction is always binary: the names (or atoms) a that appear on the left-hand side are bound, and their scope is the expression e that appears on the right-hand side.... A

We then gave a type system that enables the static inference of the trustworthiness of values and the type system was proved to have the Subject Reduction property with respect to

Success approaches: normalisation by evaluation and category-theoretic models of

Stop considering anything can be applied to anything A function and its argument have different

EPITA — École Pour l’Informatique et les Techniques Avancées.. June

EPITA — École Pour l’Informatique et les Techniques Avancées. June

Stop considering anything can be applied to anything A function and its argument have different behaviors.. Demaille Simply Typed λ-Calculus 12