• Aucun résultat trouvé

The Curry-Howard Isomorphism

N/A
N/A
Protected

Academic year: 2022

Partager "The Curry-Howard Isomorphism"

Copied!
105
0
0

Texte intégral

(1)

The Curry-Howard Isomorphism

Akim Demaille akim@lrde.epita.fr

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

June 14, 2016

(2)

The Curry-Howard Isomorphism

1

Heyting’s Semantics of Proofs

2

The Curry-Howard Isomorphism

3

Agda

(3)

Heyting’s Semantics of Proofs

1

Heyting’s Semantics of Proofs

2

The Curry-Howard Isomorphism

3

Agda

(4)

Functional Interpretation

[Girard, 2004, Chap. 5]

Instead of “when is a sentence A true”

ask “what is a proof of A”?

Also named BHK (Brouwer–Heyting–Kolmogorov) interpretation.

(5)

Functional Interpretation

[Girard et al., 1989, Sec. 1.2.2]

What is a proof π of A? (π ` A)

Atomic Values Assume we know what a proof is

A ∧ B A pair (π

A

, π

B

) s.t. π

A

` A and π

B

` B

A ∨ B A pair (i , π) s.t. i = 0 π ` A i = 1 π ` B

A ⇒ B A function f s.t. if π ` A then f (π) ` B

∀x · A A function f s.t. f (a) ` A[a/x]

∃x · A A pair (a, π) s.t. π ` A[a/x]

(6)

Functional Interpretation

[Girard et al., 1989, Sec. 1.2.2]

What is a proof π of A? (π ` A)

Atomic Values Assume we know what a proof is

A ∧ B A pair (π

A

, π

B

) s.t. π

A

` A and π

B

` B A ∨ B A pair (i, π) s.t.

i = 0 π ` A i = 1 π ` B

A ⇒ B A function f s.t. if π ` A then f (π) ` B

∀x · A A function f s.t. f (a) ` A[a/x]

∃x · A A pair (a, π) s.t. π ` A[a/x]

(7)

Functional Interpretation

[Girard et al., 1989, Sec. 1.2.2]

What is a proof π of A? (π ` A)

Atomic Values Assume we know what a proof is

A ∧ B A pair (π

A

, π

B

) s.t. π

A

` A and π

B

` B A ∨ B A pair (i, π) s.t.

i = 0 π ` A i = 1 π ` B

A ⇒ B A function f s.t. if π ` A then f (π) ` B

∀x · A A function f s.t. f (a) ` A[a/x]

∃x · A A pair (a, π) s.t. π ` A[a/x]

(8)

Functional Interpretation

[Girard et al., 1989, Sec. 1.2.2]

What is a proof π of A? (π ` A)

Atomic Values Assume we know what a proof is

A ∧ B A pair (π

A

, π

B

) s.t. π

A

` A and π

B

` B A ∨ B A pair (i, π) s.t.

i = 0 π ` A i = 1 π ` B

A ⇒ B A function f s.t. if π ` A then f (π) ` B

∀x · A A function f s.t. f (a) ` A[a/x]

∃x · A A pair (a, π) s.t. π ` A[a/x]

(9)

Functional Interpretation

[Girard et al., 1989, Sec. 1.2.2]

What is a proof π of A? (π ` A)

Atomic Values Assume we know what a proof is

A ∧ B A pair (π

A

, π

B

) s.t. π

A

` A and π

B

` B A ∨ B A pair (i, π) s.t.

i = 0 π ` A i = 1 π ` B

A ⇒ B A function f s.t. if π ` A then f (π) ` B

∀x · A A function f s.t. f (a) ` A[a/x]

(10)

Functional Interpretation

[Girard et al., 1989, Sec. 1.2.2]

What is a proof π of A? (π ` A)

Atomic Values Assume we know what a proof is A ∧ B A pair (π

A

, π

B

) s.t. π

A

` A and π

B

` B A ∨ B A pair (i, π) s.t.

i = 0 π ` A i = 1 π ` B

A ⇒ B A function f s.t. if π ` A then f (π) ` B

∀x · A A function f s.t. f (a) ` A[a/x]

(11)

Heyting’s Semantics of Proofs

An informal interpretation

The handling of ∨ and ∃ are similar to the disjunctive and existential properties

Therefore refers to a cut-free proof

For instance id is a proof of A ⇒ A

(12)

Heyting’s Semantics of Proofs

An informal interpretation

The handling of ∨ and ∃ are similar to the disjunctive and existential properties

Therefore refers to a cut-free proof

For instance id is a proof of A ⇒ A

(13)

Heyting’s Semantics of Proofs

An informal interpretation

The handling of ∨ and ∃ are similar to the disjunctive and existential properties

Therefore refers to a cut-free proof

For instance id is a proof of A ⇒ A

(14)

Heyting’s Semantics of Proofs

An informal interpretation

The handling of ∨ and ∃ are similar to the disjunctive and existential properties

Therefore refers to a cut-free proof

For instance id is a proof of A ⇒ A

(15)

The Curry-Howard Isomorphism

1

Heyting’s Semantics of Proofs

2

The Curry-Howard Isomorphism The Isomorphism

Consequences of the Isomorphism

3

Agda

(16)

A Striking Correspondence

Type Derivations

M : σ → τ N : σ app MN : τ

[x : σ]

· · M · : τ

abs λx · M : σ → τ

Natural Deduction A ⇒ B A

⇒E B

[A] ·

· ·

B ⇒I

A ⇒ B

(17)

A Striking Correspondence

Type Derivations

M : σ → τ N : σ app MN : τ

[x : σ]

· · M · : τ

abs λx · M : σ → τ

Natural Deduction A ⇒ B A

⇒E B

[A] ·

· ·

B ⇒I

A ⇒ B

(18)

The Isomorphism

1

Heyting’s Semantics of Proofs

2

The Curry-Howard Isomorphism The Isomorphism

Consequences of the Isomorphism

3

Agda

(19)

The Isomorphism

[Girard et al., 1989]

Curry-Howard Isomorphism

There is a perfect equivalence between two viewpoints:

Natural Deduction

Formulas A, deductions of A, normalization in natural deduction

Typed λ-calculus

Types A, terms of type A, normalization in λ-calculus.

(20)

Deductions and Terms: Conjuction

A

i

· ·

· A

· ·

· B ∧I A ∧ B

· ·

· A ∧ B

∧1E A ·

· ·

(21)

Deductions and Terms: Conjuction

x

iA

: A

i

· ·

· u : A

· ·

· v : B hu, v i : A ∧ B ∧I

· ·

· u : A ∧ B

∧1E π

1

u : A

· ·

·

(22)

Reductions

· ·

· A

· ·

· B ∧I A ∧ B

∧1E A ·

· ·

;

· · A ·

· ·

·

π

1

hu, vi ; u

π

2

hu, vi ; v

(23)

Reductions

· · u : · A

· · v : · B

∧I hu, v i : A ∧ B

∧1E π

1

hu, vi : A

· ·

·

;

· ·

· u : · A

· ·

π

1

hu, vi ; u

π

2

hu, vi ; v

(24)

Reductions

· · u : · A

· · v : · B

∧I hu, v i : A ∧ B

∧1E π

1

hu, vi : A

· ·

·

;

· ·

· u : · A

· ·

π

1

hu, vi ; u

π

2

hu, vi ; v

(25)

Deductions and Terms: Implication

[A]

i

· ·

·

B ⇒I

i

A ⇒ B

· ·

· A ⇒ B

· ·

·

A ⇒E

B

(26)

Deductions and Terms: Implication

x

iA

: [A]

i

· ·

· u : B

⇒I

i

λx

iA

· u : A ⇒ B

· · u : A · ⇒ B

· · v · : A

⇒E

uv : B

(27)

Disjunction

· ·

· A ∨l I A ∨ B

· ·

·

B ∨r I A ∨ B

· · A ∨ · B

[A] ·

· · C

[B] ·

· ·

C ∨E

C

(28)

Disjunction

· · u · : A

∨lI ι

l

u : A ∨ B

· ·

·

B ∨r I A ∨ B

· · A ∨ · B

[A] ·

· · C

[B] ·

· ·

C ∨E

C

(29)

Disjunction

· · u · : A

∨lI ι

l

u : A ∨ B

· ·

· v : B

∨rI ι

r

v : A ∨ B

· ·

· A ∨ B

[A] ·

· · C

[B] ·

· ·

C ∨E

C

(30)

Disjunction

· · u : · A

∨lI ι

l

u : A ∨ B

· ·

· v : B

∨r I ι

r

v : A ∨ B

· ·

· r : A ∨ B

[x : A]

· ·

· u : C

[y : B]

· ·

· v : C

∨E

C

(31)

Disjunction

· · u : · A

∨lI ι

l

u : A ∨ B

· ·

· v : B

∨r I ι

r

v : A ∨ B

· ·

· r : A ∨ B

[x : A]

· ·

· u : C

[y : B]

· ·

· v : C

∨E

δ x · u y · v r : C

(32)

Reductions

· ·

· r : A

∨lI A ∨ B

[A] ·

· · C

[B] ·

· · C ∨E C ·

· ·

;

· · A ·

· ·

· C ·

· ·

δ x · u y · v (ι

l

r ) ; u [r /x]

δ x · u y · v (ι

r

s ) ; v [s /y ]

(33)

Reductions

· ·

· r : A

∨lI ι

l

r : A ∨ B

[x : A]

· · u : · C

[y : B ]

· · v : · C

∨E C ·

· ·

;

· · A ·

· ·

· C ·

· ·

δ x · u y · v (ι

l

r ) ; u [r /x]

δ x · u y · v (ι

r

s ) ; v [s /y ]

(34)

Reductions

· · r : · A

∨lI ι

l

r : A ∨ B

[x : A]

· ·

· u : C

[y : B ]

· ·

· v : C

∨E δ x · u y · v (ι

l

r ) : C

· ·

·

;

· ·

· A ·

· · C ·

· ·

δ x · u y · v (ι

l

r ) ; u [r /x]

δ x · u y · v (ι

r

s ) ; v [s /y ]

(35)

Reductions

· · r : · A

∨lI ι

l

r : A ∨ B

[x : A]

· ·

· u : C

[y : B]

· ·

· v : C

∨E δ x · u y · v (ι

l

r) : C

· ·

·

;

· · r : · A

· ·

· u[r /x] : C

· ·

·

δ x · u y · v (ι

l

r ) ; u [r /x]

δ x · u y · v (ι

r

s ) ; v [s /y ]

(36)

Reductions

· · r : · A

∨lI ι

l

r : A ∨ B

[x : A]

· ·

· u : C

[y : B]

· ·

· v : C

∨E δ x · u y · v (ι

l

r) : C

· ·

·

;

· · r : · A

· ·

· u[r /x] : C

· ·

· δ x · u y · v (ι

l

r ) ; u [r /x]

δ x · u y · v (ι

r

s ) ; v [s /y]

(37)

Commutative Reductions

· ·

· A ∨ B

[A] ·

· · C

[B ]

· ·

· C

∨E C

· ·

· RE D ·

· ·

;

· ·

·

[A] ·

· · C

· ·

· RE

[B] ·

· · C

· ·

·

RE

(38)

Commutative Reductions

· ·

· r : A ∨ B

[x : A]

· ·

· u : C

[y : B]

· ·

· v : C

∨E C

· ·

· RE D ·

· ·

;

· ·

·

[A] ·

· · C

· ·

· RE

[B] ·

· · C

· ·

·

RE

(39)

Commutative Reductions

· ·

· r : A ∨ B

[x : A]

· ·

· u : C

[y : B]

· ·

· v : C

∨E δ x · u y · v r : C

· ·

· RE D ·

· ·

;

· ·

·

[A] ·

· · C

· ·

· RE

[B] ·

· · C

· ·

·

RE

(40)

Commutative Reductions

· · r : A · ∨ B

[x : A]

· · u : · C

[y : B]

· · v : · C

∨E δ x · u y · v r : C

· ·

· RE

· · · (δ x · u y · v r ) · · · : D

· ·

·

;

· ·

·

[A] ·

· · C

· ·

· RE

[B] ·

· · C

· ·

·

RE

(41)

Commutative Reductions

· · r : A · ∨ B

[x : A]

· · u : · C

[y : B]

· · v : · C

∨E δ x · u y · v r : C

· ·

· RE

· · · (δ x · u y · v r ) · · · : D

· ·

·

;

· ·

·

[x : A]

· · u : · C

· ·

· RE

[B] ·

· · C

· ·

·

RE

(42)

Commutative Reductions

· · r : A · ∨ B

[x : A]

· · u : · C

[y : B]

· · v : · C

∨E δ x · u y · v r : C

· ·

· RE

· · · (δ x · u y · v r ) · · · : D

· ·

·

;

· ·

·

[x : A]

· · u : · C

· ·

· RE

[y : B]

· · v : · C

· ·

·

RE

(43)

Commutative Reductions

· · r : A · ∨ B

[x : A]

· · u : · C

[y : B]

· · v : · C

∨E δ x · u y · v r : C

· ·

· RE

· · · (δ x · u y · v r ) · · · : D

· ·

·

;

· ·

·

[x : A]

· · u : · C

· ·

· RE

[y : B]

· · v : · C

· ·

·

RE

(44)

Commutative Reductions

· ·

· r : A ∨ B

[x : A]

· ·

· u : C

[y : B]

· ·

· v : C

∨E δ x · u y · v r : C

· ·

· RE

· · · (δ x · u y · v r ) · · · : D

· ·

·

;

· ·

·

[x : A]

· ·

· u : C

· ·

· RE

[y : B]

· ·

· v : C

· ·

·

RE

(45)

Commutative Conversions: Disjunction vs. Disjunction

· ·

· A ∨ B

[A] ·

· · C ∨ D

[B ]

· ·

· C ∨ D

∨E C ∨ D

[C ]

· ·

· E

[D] ·

· · E

∨E E ·

· ·

· ·

·

[A] ·

· · C ∨ D

[C] ·

· · E

[D] ·

· · E

∨E [B] ·

· · C ∨ D

[C] ·

· · E

[D] ·

· · E

∨E

(46)

Commutative Conversions: Disjunction vs. Disjunction

· ·

· t : A ∨ B

[x : A]

· ·

· u : C ∨ D

[y : B]

· ·

· v : C ∨ D

∨E C ∨ D

[C] ·

· · E

[D] ·

· · E

∨E E ·

· ·

· ·

·

[A] ·

· · C ∨ D

[C] ·

· · E

[D] ·

· · E

∨E [B] ·

· · C ∨ D

[C] ·

· · E

[D] ·

· · E

∨E

(47)

Commutative Conversions: Disjunction vs. Disjunction

· ·

· t : A ∨ B

[x : A]

· ·

· u : C ∨ D

[y : B]

· ·

· v : C ∨ D

∨E δ x · u y · v t : C ∨ D

[x

0

: C]

· ·

· u

0

: E

[y

0

: D]

· ·

· v

0

: E

∨E E ·

· ·

· ·

·

[A] ·

· · C ∨ D

[C] ·

· · E

[D] ·

· · E

∨E [B] ·

· · C ∨ D

[C] ·

· · E

[D] ·

· · E

∨E

(48)

Commutative Conversions: Disjunction vs. Disjunction

· ·

· t : A ∨ B

[x : A]

· ·

· u : C ∨ D

[y : B]

· ·

· v : C ∨ D

∨E δ x · u y · v t : C ∨ D

[x

0

: C]

· ·

· u

0

: E

[y

0

: D]

· ·

· v

0

: E

∨E δ x

0

· u

0

y

0

· v

0

(δ x · u y · v t) : E

· ·

·

· ·

·

[A]

· ·

· C ∨ D

[C]

· ·

· E

[D]

· ·

· E

∨E [B]

· ·

· C ∨ D

[C]

· ·

· E

[D]

· ·

· E

∨E

(49)

Commutative Conversions: Disjunction vs. Disjunction

· ·

· t : A ∨ B

[x : A]

· ·

· u : C ∨ D

[y : B]

· ·

· v : C ∨ D

∨E δ x · u y · v t : C ∨ D

[x

0

: C]

· ·

· u

0

: E

[y

0

: D]

· ·

· v

0

: E

∨E δ x

0

· u

0

y

0

· v

0

(δ x · u y · v t) : E

· ·

·

· ·

·

[x : A]

· ·

· u : C ∨ D

[x

0

: C]

· ·

· u

0

: E

[y

0

: D]

· ·

· v

0

: E

∨E

[y : B]

· ·

· v : C ∨ D

[x

0

: C ]

· ·

· u

0

: E

[y

0

: D]

· ·

· v

0

: E

∨E

(50)

Commutative Conversions: Disjunction vs. Disjunction

· ·

· t : A ∨ B

[x : A]

· ·

· u : C ∨ D

[y : B]

· ·

· v : C ∨ D

∨E δ x · u y · v t : C ∨ D

[x

0

: C]

· ·

· u

0

: E

[y

0

: D]

· ·

· v

0

: E

∨E δ x

0

· u

0

y

0

· v

0

(δ x · u y · v t) : E

· ·

·

· ·

·

[x : A]

· · u : C · ∨ D

[x

0

: C]

· ·

· u

0

: E

[y

0

: D]

· ·

· v

0

: E

∨E

[y : B]

· · v : C · ∨ D

[x

0

: C ]

· ·

· u

0

: E

[y

0

: D]

· ·

· v

0

: E

∨E

(51)

Commutative Reductions

δ x

0

· u

0

y

0

· v

0

(δ x · u y · v t)

; δ x · (δ x

0

· u

0

y

0

· v

0

u) y · (δ x

0

· u

0

y

0

· v

0

v) t

π

1

(δ x · u y · v t)

; δ x · (π

1

u) y · (π

1

v) t π

2

(δ x · u y · v t)

; δ x · (π

2

u) y · (π

2

v) t (δ x · u y · v t)w

; δ x · (uw ) y · (vw) t

(52)

Commutative Reductions

δ x

0

· u

0

y

0

· v

0

(δ x · u y · v t)

; δ x · (δ x

0

· u

0

y

0

· v

0

u) y · (δ x

0

· u

0

y

0

· v

0

v) t π

1

(δ x · u y · v t)

; δ x · (π

1

u) y · (π

1

v) t

π

2

(δ x · u y · v t)

; δ x · (π

2

u) y · (π

2

v) t (δ x · u y · v t)w

; δ x · (uw ) y · (vw) t

(53)

Commutative Reductions

δ x

0

· u

0

y

0

· v

0

(δ x · u y · v t)

; δ x · (δ x

0

· u

0

y

0

· v

0

u) y · (δ x

0

· u

0

y

0

· v

0

v) t π

1

(δ x · u y · v t)

; δ x · (π

1

u) y · (π

1

v) t π

2

(δ x · u y · v t)

; δ x · (π

2

u) y · (π

2

v) t

(δ x · u y · v t)w

; δ x · (uw ) y · (vw) t

(54)

Commutative Reductions

δ x

0

· u

0

y

0

· v

0

(δ x · u y · v t)

; δ x · (δ x

0

· u

0

y

0

· v

0

u) y · (δ x

0

· u

0

y

0

· v

0

v) t π

1

(δ x · u y · v t)

; δ x · (π

1

u) y · (π

1

v) t π

2

(δ x · u y · v t)

; δ x · (π

2

u) y · (π

2

v) t

(δ x · u y · v t)w

(55)

Consequences of the Isomorphism

1

Heyting’s Semantics of Proofs

2

The Curry-Howard Isomorphism The Isomorphism

Consequences of the Isomorphism

3

Agda

(56)

Correspondences

Logic λ-calculus Programs

proof strongly normalizable term halting program

cut redex function call etc.

cut elimination reduction execution step

cut-free proof normal form value

formula type interface

conjunction Cartesian product record

disjunction direct sum variant

implication functional type function type universal q. dependent products

existential q. dependent sums

(57)

Correspondences

Logic λ-calculus Programs

proof strongly normalizable term halting program

cut redex function call etc.

cut elimination reduction execution step

cut-free proof normal form value

formula type interface

conjunction Cartesian product record

disjunction direct sum variant

implication functional type function type universal q. dependent products

existential q. dependent sums

(58)

Correspondences

Logic λ-calculus Programs

proof strongly normalizable term halting program

cut redex function call etc.

cut elimination reduction execution step

cut-free proof normal form value

formula type interface

conjunction Cartesian product record

disjunction direct sum variant

implication functional type function type universal q. dependent products

existential q. dependent sums

(59)

Correspondences

Logic λ-calculus Programs

proof strongly normalizable term halting program

cut redex function call etc.

cut elimination reduction execution step

cut-free proof normal form value

formula type interface

conjunction Cartesian product record

disjunction direct sum variant

implication functional type function type universal q. dependent products

existential q. dependent sums

(60)

Correspondences

Logic λ-calculus Programs

proof strongly normalizable term halting program

cut redex function call etc.

cut elimination reduction execution step

cut-free proof normal form value

formula type interface

conjunction Cartesian product record

disjunction direct sum variant

implication functional type function type universal q. dependent products

existential q. dependent sums

(61)

Correspondences

Logic λ-calculus Programs

proof strongly normalizable term halting program

cut redex function call etc.

cut elimination reduction execution step

cut-free proof normal form value

formula type interface

conjunction Cartesian product record

disjunction direct sum variant

implication functional type function type universal q. dependent products

existential q. dependent sums

(62)

Correspondences

Logic λ-calculus Programs

proof strongly normalizable term halting program

cut redex function call etc.

cut elimination reduction execution step

cut-free proof normal form value

formula type interface

conjunction Cartesian product record

disjunction direct sum variant

implication functional type function type universal q. dependent products

existential q. dependent sums

(63)

Correspondences

Logic λ-calculus Programs

proof strongly normalizable term halting program

cut redex function call etc.

cut elimination reduction execution step

cut-free proof normal form value

formula type interface

conjunction Cartesian product record

disjunction direct sum variant

implication functional type function type universal q. dependent products

existential q. dependent sums

(64)

Correspondences

Logic λ-calculus Programs

proof strongly normalizable term halting program

cut redex function call etc.

cut elimination reduction execution step

cut-free proof normal form value

formula type interface

conjunction Cartesian product record

disjunction direct sum variant

implication functional type function type universal q. dependent products

existential q. dependent sums

(65)

Correspondences

Logic λ-calculus Programs

proof strongly normalizable term halting program

cut redex function call etc.

cut elimination reduction execution step

cut-free proof normal form value

formula type interface

conjunction Cartesian product record

disjunction direct sum variant

implication functional type function type universal q. dependent products

existential q. dependent sums

(66)

Correspondences

Logic λ-calculus Programs

proof strongly normalizable term halting program

cut redex function call etc.

cut elimination reduction execution step

cut-free proof normal form value

formula type interface

conjunction Cartesian product record

disjunction direct sum variant

implication functional type function type universal q. dependent products

existential q. dependent sums

(67)

Differences

logic focuses on propositions (types) type theory focuses on programs (proofs)

non-trivial type systems allow non-terminating programs such terms can be typed ⊥

so. . .

“propositions as types; proofs as programs” is ok

the converse generally does not yield a sane logical system

(68)

The system F

[Girard et al., 1989, Chap. 11],[Girard, 2004, Chap. 6]

Discovered by Jean-Yves Girard (1972).

A typed λ-calculus

Known as the second-order or polymorphic λ-calculus

Formalizes the notion of parametric polymorphism in programming languages

Corresponds to a second-order logic via Curry-Howard

` Λα · λx

α

· x : ∀α · α → α

Strongly normalizing

(69)

The system F

[Girard et al., 1989, Chap. 11],[Girard, 2004, Chap. 6]

Discovered by Jean-Yves Girard (1972).

A typed λ-calculus

Known as the second-order or polymorphic λ-calculus

Formalizes the notion of parametric polymorphism in programming languages

Corresponds to a second-order logic via Curry-Howard

` Λα · λx

α

· x : ∀α · α → α

Strongly normalizing

(70)

The system F

[Girard et al., 1989, Chap. 11],[Girard, 2004, Chap. 6]

Discovered by Jean-Yves Girard (1972).

A typed λ-calculus

Known as the second-order or polymorphic λ-calculus

Formalizes the notion of parametric polymorphism in programming languages

Corresponds to a second-order logic via Curry-Howard

` Λα · λx

α

· x : ∀α · α → α

Strongly normalizing

(71)

The system F

[Girard et al., 1989, Chap. 11],[Girard, 2004, Chap. 6]

Discovered by Jean-Yves Girard (1972).

A typed λ-calculus

Known as the second-order or polymorphic λ-calculus

Formalizes the notion of parametric polymorphism in programming languages

Corresponds to a second-order logic via Curry-Howard

` Λα · λx

α

· x : ∀α · α → α

Strongly normalizing

(72)

The system F

[Girard et al., 1989, Chap. 11],[Girard, 2004, Chap. 6]

Discovered by Jean-Yves Girard (1972).

A typed λ-calculus

Known as the second-order or polymorphic λ-calculus

Formalizes the notion of parametric polymorphism in programming languages

Corresponds to a second-order logic via Curry-Howard

` Λα · λx

α

· x : ∀α · α → α

Strongly normalizing

(73)

The system F

[Girard et al., 1989, Chap. 11],[Girard, 2004, Chap. 6]

Discovered by Jean-Yves Girard (1972).

A typed λ-calculus

Known as the second-order or polymorphic λ-calculus

Formalizes the notion of parametric polymorphism in programming languages

Corresponds to a second-order logic via Curry-Howard

` Λα · λx

α

· x : ∀α · α → α

Strongly normalizing

(74)

The system F

[Girard et al., 1989, Chap. 11],[Girard, 2004, Chap. 6]

Discovered by Jean-Yves Girard (1972).

A typed λ-calculus

Known as the second-order or polymorphic λ-calculus

Formalizes the notion of parametric polymorphism in programming languages

Corresponds to a second-order logic via Curry-Howard

` Λα · λx

α

· x : ∀α · α → α

Strongly normalizing

(75)

The system F

[Girard et al., 1989, Chap. 11],[Girard, 2004, Chap. 6]

Discovered by Jean-Yves Girard (1972).

A typed λ-calculus

Known as the second-order or polymorphic λ-calculus

Formalizes the notion of parametric polymorphism in programming languages

Corresponds to a second-order logic via Curry-Howard

` Λα · λx

α

· x : ∀α · α → α

Strongly normalizing

(76)

The system F

T := Λα · λx

α

· λy

α

· x : ∀α · α → α → α F := Λα · λx

α

· λy

α

· y : ∀α · α → α → α

Beware that these function take three arguments.

Boolean := ∀α · α → α → α

(77)

The system F

T := Λα · λx

α

· λy

α

· x : ∀α · α → α → α F := Λα · λx

α

· λy

α

· y : ∀α · α → α → α

Beware that these function take three arguments.

Boolean := ∀α · α → α → α

(78)

The system F

and := λx

Boolean

· λy

Boolean

· x Boolean y F

or := λx

Boolean

· λy

Boolean

· x Boolean T y

and := λx

Boolean

· λy

Boolean

· x Boolean F T

(79)

Agda

1

Heyting’s Semantics of Proofs

2

The Curry-Howard Isomorphism

3

Agda

(80)

Dependently Typed Programming in Agda

“ In Hindley-Milner style languages, such as Haskell and ML, there is a clear separation between types and values.

In a dependently typed language the line is more blurry — types can contain (depend on) arbitrary values and appear as arguments and results of ordinary functions.

— [Norell, 2009]

(81)

Datatypes and Pattern Matching

Booleans

data Bool :

Set

where true : Bool false : Bool not : Bool

Bool not true = false not false = true

_or_ : Bool

Bool

Bool true or x = x

false or _ = false

(82)

Datatypes and Pattern Matching

Natural Numbers

data Nat :

Set

where zero : Nat

suc : Nat

Nat _+_ : Nat

Nat

Nat zero + m = m

suc n + m = suc (n + m)

_*_ : Nat

Nat

Nat

zero * m = zero

suc n * m = m + n * m

(83)

Syntax

if_then_else_ : {A :

Set} →

Bool

A

A

A if true then x else y = x

if false then x else y = y infixl 60 _*_

infixl 40 _+_

infixr 20 _or_

infix 5 if_then_else_

Evaluation is in normal order: function first.

But not call-by-need: computations are not shared.

(84)

Lists

infixr 40 _::_

data List (A :

Set) : Set

where [] : List A

_::_ : A

List A

List A

data _? (α : Set) : Set where ε : α ?

_._ : α → α ? → α ?

(85)

Lists

infixr 40 _::_

data List (A :

Set) : Set

where [] : List A

_::_ : A

List A

List A

data _? (α :

Set) : Set

where

ε

:

α ?

_._ :

α → α ? → α ?

(86)

Dependent Functions

(x : A) → B

Type of functions

taking an x of type A

return a value of type B

where x may appear in B

Special case: x is a type.

(87)

Dependent Functions

identity : (A :

Set) →

A

A identity A x = x

zero’ : Nat

zero’ = identity Nat zero

apply : (A :

Set)(B

: A

→ Set) →

((x : A)

B x)

(a : A)

B a apply A B f a = f a

Shorthands:

(x : A)(y : B) → C

for (x : A) → (y : B) → C

(88)

Implicit Arguments

{x : A} → B

Same as (x : A) → B

but when used, let the type checker figure out x

id : {A :

Set} →

A

A id x = x

true’ : Bool true’ = id true

Or using _ to request assistance from the type checker:

one : Nat

(89)

Implicit Arguments

map : {A B :

Set} →

(A

B)

List A

List B map f [] = []

map f (x :: xs) = f x :: map f xs

_++_ : {A :

Set} →

List A

List A

List A [] ++ ys = ys

(x :: xs) ++ ys = x :: (xs ++ ys)

(90)

A Tricky One

_◦_ : {A :

Set}

{B : A

→ Set}

{C : (x : A)

B x

→ Set}

(f : {x : A}(y : B x)

C x y) (g : (x : A)

B x)

(x : A)

C x (g x)

(f

g) x = f (g x)

(91)

A Tricky One

_◦_ :

(f : B

C) (g : A

B) (x : A)

C

(f

g) x = f (g x)

(92)

A Tricky One

_◦_ : {A :

Set}

{B :

Set}

{C :

Set}

(f : B

C) (g : A

B) (x : A)

C

(f

g) x = f (g x)

(93)

A Tricky One

_◦_ : {A :

Set}

{B : A

→ Set}

{C :

Set}

(f : B

C)

(g : (x : A)

B x) (x : A)

C

(f

g) x = f (g x)

(94)

A Tricky One

_◦_ : {A :

Set}

{B : A

→ Set}

{C :

Set}

(f : (B x)

C) (g : (x : A)

B x) (x : A)

C

(f

g) x = f (g x)

(95)

A Tricky One

_◦_ : {A :

Set}

{B : A

→ Set}

{C :

Set}

(f : {x : A}(B x)

C) (g : (x : A)

B x) (x : A)

C

(f

g) x = f (g x)

(96)

A Tricky One

_◦_ : {A :

Set}

{B : A

→ Set}

{C : (x : A)

B x

→ Set}

(f : {x : A}(y : B x)

C x y) (g : (x : A)

B x)

(x : A)

C x (g x)

(f

g) x = f (g x)

(97)

Datatype families

data Vec (A :

Set) :

Nat

→ Set

where [] : Vec A zero

_::_ : {n : Nat}

A

Vec A n

Vec A (suc n)

A is a parameter

Nat provides the indexes

(98)

Datatype families

head : {A :

Set}{n

: Nat}

Vec A (suc n)

A head (x :: xs) = x

this is correct, but. . . what should be surprising?

where is the case for the empty list?

the type checker knows it’s impossible here!

why?

Vec A (suc n)

(99)

Datatype families

head : {A :

Set}{n

: Nat}

Vec A (suc n)

A head (x :: xs) = x

this is correct, but. . . what should be surprising?

where is the case for the empty list?

the type checker knows it’s impossible here!

why?

Vec A (suc n)

(100)

Datatype families

head : {A :

Set}{n

: Nat}

Vec A (suc n)

A head (x :: xs) = x

this is correct, but. . . what should be surprising?

where is the case for the empty list?

the type checker knows it’s impossible here!

why?

Vec A (suc n)

(101)

Datatype families

head : {A :

Set}{n

: Nat}

Vec A (suc n)

A head (x :: xs) = x

this is correct, but. . . what should be surprising?

where is the case for the empty list?

the type checker knows it’s impossible here!

why?

Vec A (suc n)

(102)

Datatype families

head : {A :

Set}{n

: Nat}

Vec A (suc n)

A head (x :: xs) = x

this is correct, but. . . what should be surprising?

where is the case for the empty list?

the type checker knows it’s impossible here!

why?

Vec A (suc n)

(103)

Datatype families

head : {A :

Set}{n

: Nat}

Vec A (suc n)

A head (x :: xs) = x

this is correct, but. . . what should be surprising?

where is the case for the empty list?

the type checker knows it’s impossible here!

why?

Vec A (suc n)

(104)

Recommended Readings

[Norell, 2009]

A thorough introduction to Agda.

https://youtu.be/Da9WjINqY9c

Introductory examples on proof-terms in Coq.

(105)

Bibliography I

Girard, J.-Y. (2004).

Cours de Logique, Rome, Automne 2004.

http://logica.uniroma3.it/uif/corso/.

Girard, J.-Y., Lafont, Y., and Taylor, P. (1989).

Proofs and Types.

Cambridge University Press.

http://www.cs.man.ac.uk/~pt/stable/Proofs+Types.html.

Norell, U. (2009).

Dependently typed programming in Agda.

In Proceedings of the 4th International Workshop on Types in

Références

Documents relatifs

In this paper, we establish a relation between these two approaches and show how proofs in Hoare logic can be interpreted in type theory, yielding a translation of imperative

logic focuses on propositions (types) type theory focuses on programs (proofs). non-trivial type systems allow non-terminating programs such terms can be

– We presented an argumentation semantics of defeasible logic programs, based on conflict resolution strategies within assumption-based frameworks, whose semantics satisfies

When termination and non-termination analysis produce complementary results for a logic procedure, then with respect to the leftmost selection rule and the language used to

stead of diretly desribing the syntax of language via a formal grammar, the.. linguist speies the strutures of this formal grammar using a

Since it has been understood that the Curry-Howard isomorphism relating proofs and programs can be extended to classical logic, various systems have been introduced: the λ c

Since it has been understood that the Curry-Howard isomorphism relating proofs and programs can be extended to classical logic, various systems have been introduced: the λ c

The adhesion forces can be splitted in different components : van der Waals, electrostatics and capillary condensation.. This work focuses on capillary condensation as it often can