• Aucun résultat trouvé

Demaille The Curry-Howard Isomorphism 2 / 45 Heyting’s Semantics of Proofs 1 Heyting’s Semantics of Proofs 2 The Curry-Howard Isomorphism 3 Agda Functional Interpretation [Girard, 2004, Chap

N/A
N/A
Protected

Academic year: 2022

Partager "Demaille The Curry-Howard Isomorphism 2 / 45 Heyting’s Semantics of Proofs 1 Heyting’s Semantics of Proofs 2 The Curry-Howard Isomorphism 3 Agda Functional Interpretation [Girard, 2004, Chap"

Copied!
12
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

The Curry-Howard Isomorphism

1 Heyting’s Semantics of Proofs

2 The Curry-Howard Isomorphism

3 Agda

A. Demaille The Curry-Howard Isomorphism 2 / 45

Heyting’s Semantics of Proofs

1 Heyting’s Semantics of Proofs

2 The Curry-Howard Isomorphism

3 Agda

Functional Interpretation

[Girard, 2004, Chap. 5]

Instead of “when is a sentence A true”

ask “what is a proofof A”?

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

(2)

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 AB A pairA, πB)s.t. πA`Aand πB `B AB A pair(i, π)s.t.

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

AB 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]

A. Demaille The Curry-Howard Isomorphism 5 / 45

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 ofAA

A. Demaille The Curry-Howard Isomorphism 6 / 45

The Curry-Howard Isomorphism

1 Heyting’s Semantics of Proofs

2 The Curry-Howard Isomorphism The Isomorphism

Consequences of the Isomorphism

3 Agda

A Striking Correspondence

Type Derivations

M:στ N:σ MN :τ app

[x :σ]

··· M :τ λx·M:στ abs

Natural Deduction AB A

B ⇒E

[A]··· B ⇒I AB

(3)

The Isomorphism

1 Heyting’s Semantics of Proofs

2 The Curry-Howard Isomorphism The Isomorphism

Consequences of the Isomorphism

3 Agda

A. Demaille The Curry-Howard Isomorphism 9 / 45

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.

A. Demaille The Curry-Howard Isomorphism 10 / 45

Deductions and Terms: Conjuction

xiA:Ai

··· u:A

··· v :B hu,vi:AB ∧I

··· u:AB

1E π1u:A

··· u:AB

2E π2u:B

Reductions

··· u:A

··· v :B hu,vi:AB ∧I

1E π1hu,vi:A

···

;

··· u:A

··· π1hu,vi ; u

π2hu,vi ; v

(4)

Deductions and Terms: Implication

xiA: [A]i

··· u:B

⇒Ii

λxiA·u:AB

··· u:AB

··· v :A uv :B ⇒E

A. Demaille The Curry-Howard Isomorphism 13 / 45

Disjunction

··· u:A

lI ιlu:AB

··· v :B

rI ιrv :AB

··· r :AB

[x :A]

··· u:C

[y :B]

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

A. Demaille The Curry-Howard Isomorphism 14 / 45

Reductions

··· r :A

lI ιlr :AB

[x :A]

··· u:C

[y :B]

··· v :C δ x·u y·v lr) :C ∨E

···

;

··· r :A

··· u[r/x] :C

···

δ x·u y·v lr) ; u[r/x]

δ x·u y·v rs) ; v[s/y]

Commutative Reductions

·· r :A·B

[x :A]

·· u:·C

[y :B]

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

··

· RE

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

··

·

;

·· r :A·B

[x :A]

·· u:·C

··

· RE u0:D

[y :B]

·· v :·C

··

· RE v0:D δ x·u0y·v0 r :D ∨E

··

·

(5)

Commutative Conversions: Disjunction vs. Disjunction

·· t:A·B

[x :A]

·· u:C·D

[y:B]

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

[x0:C]

·· u0·:E

[y0:D]

·· v0·:E δ x0·u0y0·v0 x·u y·v t) :E ∨E

··

·

·· t:A·B

[x :A]

·· u:C·D

[x0:C]

·· u0·:E

[y0:D]

·· v0·:E δ x0·u0 y0·v0 u:E ∨E

[y :B]

·· v :C·D

[x0:C]

·· u0·:E

[y0:D]

·· v0·:E δ x0·u0y0·v0 v:E ∨E δx·x0·u0 y0·v0u)y · x0·u0y0·v0v)t:E ∨E

··

·

Commutative Reductions

δ x0·u0 y0·v0 x·u y·v t)

; δ x· x0·u0 y0·v0u)y· x0·u0 y0·v0v)t

π1 x·u y·v t)

; δ x·1u)y·1v)t

π2 x·u y·v t)

; δ x·2u)y·2v)t

x·u y·v t)w

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

A. Demaille The Curry-Howard Isomorphism 18 / 45

Consequences of the Isomorphism

1 Heyting’s Semantics of Proofs

2 The Curry-Howard Isomorphism The Isomorphism

Consequences of the Isomorphism

3 Agda

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 contradiction empty type

(6)

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

A. Demaille The Curry-Howard Isomorphism 21 / 45

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 orpolymorphicλ-calculus

Formalizes the notion of parametric polymorphismin programming languages

Corresponds to a second-order logic via Curry-Howard

`Λα·λxα·x:α·αα Strongly normalizing

Type inference is undecidable

A. Demaille The Curry-Howard Isomorphism 22 / 45

The system F

T:= Λα·λxα·λyα·x :α·ααα F:= Λα·λxα·λyα·y :α·ααα Beware that these function take threearguments.

Boolean:=α·ααα

The system F

and:=λxBoolean·λyBoolean·x Boolean y F or :=λxBoolean·λyBoolean·x Boolean T y and:=λxBoolean·λyBoolean·x Boolean F T

(7)

Agda

1 Heyting’s Semantics of Proofs

2 The Curry-Howard Isomorphism

3 Agda

A. Demaille The Curry-Howard Isomorphism 25 / 45

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]

A. Demaille The Curry-Howard Isomorphism 26 / 45

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

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

Guaranteed termination (termination checker).

(8)

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.

A. Demaille The Curry-Howard Isomorphism 29 / 45

Lists

infixr 40 _::_

data List (A : Set) : Set where [] : List A

_::_ : A List A List A

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

_._ : α α ? α ?

A. Demaille The Curry-Howard Isomorphism 30 / 45

Dependent Functions

(x : A) B

Type of functions taking an xof type A return a value of type B where xmay appear in B Special case: xis a type.

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 (x y : A B)

for (x : A)(x : A) B

(9)

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

one = identity _ (suc zero)

A. Demaille The Curry-Howard Isomorphism 33 / 45

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)

A. Demaille The Curry-Howard Isomorphism 34 / 45

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)

A Tricky One

_◦_ :

(f : B C) (g : A B) (x : A)

C

(f g) x = f (g x)

(10)

A Tricky One

_◦_ : {A : Set}

{B : Set}

{C : Set}

(f : B C) (g : A B) (x : A)

C

(f g) x = f (g x)

A. Demaille The Curry-Howard Isomorphism 37 / 45

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)

A. Demaille The Curry-Howard Isomorphism 38 / 45

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)

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)

(11)

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)

A. Demaille The Curry-Howard Isomorphism 41 / 45

Datatype families

data Vec (A : Set) : Nat Set where [] : Vec A zero

_::_ : {n : Nat} A Vec A n Vec A (suc n)

A is aparameter

Nat provides the indexes

A. Demaille The Curry-Howard Isomorphism 42 / 45

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)

Recommended Readings

[Norell, 2009]

A thorough introduction to Agda.

https://youtu.be/Da9WjINqY9c

Introductory examples on proof-terms in Coq.

(12)

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.

InProceedings of the 4th International Workshop on Types in Language Design and Implementation, TLDI ’09, pages 1–2, New York, NY, USA. ACM.

A. Demaille The Curry-Howard Isomorphism 45 / 45

Références

Documents relatifs

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

This theorem can be seen as a mixture of the estimates proven in [2], where the Boltzmann equation with general cross sections is considered, but where the large velocities are not

The intended denotational semantics is described in Section 4: we dissociate the core operations for switching between exceptions and non-exceptional values, on one side, from

Cette micrographie nous permet de constater l’état poreux de l’échantillon avec la présence de grains ayant une forme particulière et qui rappellent la rosace ou plutôt une

the x87 oating-point unit (FPU) uses 80-bit internal oating-point registers, FMA instructions compute xy ± z with a single rounding, or the compiler may optimize the assembly code

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des

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