failure is not an option the curry-howard-shadok ...édrot.fr/slides/pps-02-18.pdf · failure is...

119
Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work with Nicolas Tabareau Max Planck Institute for Software Systems Séminaire PPS P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 1 / 44

Upload: others

Post on 14-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Failure is Not an OptionThe Curry-Howard-Shadok correspondence

Pierre-Marie Pédrotjoint work with Nicolas Tabareau

Max Planck Institute for Software Systems

Séminaire PPS

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 1 / 44

Page 2: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work
Page 3: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

It’s time to CIC ass and chew bubble-gum

CIC, the Calculus of Inductive Constructions.

CIC, a very fancy intuitionistic logical system.Not just higher-order logic, not just first-order logicFirst class notion of computation and crazy inductive types

CIC, a very powerful functional programming language.Finest types to describe your programsNo clear phase separation between runtime and compile time

The Pinnacle of the Curry-Howard correspondence

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 3 / 44

Page 4: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

It’s time to CIC ass and chew bubble-gum

CIC, the Calculus of Inductive Constructions.

CIC, a very fancy intuitionistic logical system.Not just higher-order logic, not just first-order logicFirst class notion of computation and crazy inductive types

CIC, a very powerful functional programming language.Finest types to describe your programsNo clear phase separation between runtime and compile time

The Pinnacle of the Curry-Howard correspondence

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 3 / 44

Page 5: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

It’s time to CIC ass and chew bubble-gum

CIC, the Calculus of Inductive Constructions.

CIC, a very fancy intuitionistic logical system.Not just higher-order logic, not just first-order logicFirst class notion of computation and crazy inductive types

CIC, a very powerful functional programming language.Finest types to describe your programsNo clear phase separation between runtime and compile time

The Pinnacle of the Curry-Howard correspondence

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 3 / 44

Page 6: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

It’s time to CIC ass and chew bubble-gum

CIC, the Calculus of Inductive Constructions.

CIC, a very fancy intuitionistic logical system.Not just higher-order logic, not just first-order logicFirst class notion of computation and crazy inductive types

CIC, a very powerful functional programming language.Finest types to describe your programsNo clear phase separation between runtime and compile time

The Pinnacle of the Curry-Howard correspondence

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 3 / 44

Page 7: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Un Coq qui fait de l'effet

My research has been focussed on the extension of CIC with side-effects.

To Program More!Obviously you want effects to programE.g. state, exceptions, non-termination, continuations...

To Prove More!A well-known fact here at PPSCurry-Howard ⊢ side-effects ⇔ new axiomsArchetypical example: callcc and classical logic (Griffin, Krivine)

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 4 / 44

Page 8: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Un Coq qui fait de l'effet

My research has been focussed on the extension of CIC with side-effects.

To Program More!Obviously you want effects to programE.g. state, exceptions, non-termination, continuations...

To Prove More!A well-known fact here at PPSCurry-Howard ⊢ side-effects ⇔ new axiomsArchetypical example: callcc and classical logic (Griffin, Krivine)

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 4 / 44

Page 9: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Un Coq qui fait de l'effet

My research has been focussed on the extension of CIC with side-effects.

To Program More!Obviously you want effects to programE.g. state, exceptions, non-termination, continuations...

To Prove More!A well-known fact here at PPSCurry-Howard ⊢ side-effects ⇔ new axiomsArchetypical example: callcc and classical logic (Griffin, Krivine)

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 4 / 44

Page 10: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Summary of the Previous Episodes

We already gave two instances of effectful variants of CIC.

Forcing (LICS 2016)

Bread and butter categorical model factory« Forcing: retour de l’être aimé – permis de conduire – désenvoûtement. »Computationally: a glorified monotonous reader monad

Weaning (LICS 2017)

A generic construction adding effectsHandles a rather wide class of monadsSomehow dual to forcing

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 5 / 44

Page 11: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Summary of the Previous Episodes

We already gave two instances of effectful variants of CIC.

Forcing (LICS 2016)

Bread and butter categorical model factory« Forcing: retour de l’être aimé – permis de conduire – désenvoûtement. »Computationally: a glorified monotonous reader monad

Weaning (LICS 2017)

A generic construction adding effectsHandles a rather wide class of monadsSomehow dual to forcing

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 5 / 44

Page 12: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Summary of the Previous Episodes

We already gave two instances of effectful variants of CIC.

Forcing (LICS 2016)

Bread and butter categorical model factory« Forcing: retour de l’être aimé – permis de conduire – désenvoûtement. »Computationally: a glorified monotonous reader monad

Weaning (LICS 2017)

A generic construction adding effectsHandles a rather wide class of monadsSomehow dual to forcing

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 5 / 44

Page 13: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

You Can’t Have Your Cake and Eat It

Effects make reduction strategies relevant.

Call-by-value Call-by-name

/ Weaker conversion rule, Full dependent elimination, Good old ML semantics

, Full conversion rule/ Weaker dependent elimination/ Strange PL realm

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 6 / 44

Page 14: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

You Can’t Have Your Cake and Eat It

Effects make reduction strategies relevant.Call-by-value Call-by-name

/ Weaker conversion rule, Full dependent elimination, Good old ML semantics

, Full conversion rule/ Weaker dependent elimination/ Strange PL realm

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 6 / 44

Page 15: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Last Propaganda Slide: A Flurry of Buzzwords

Recall that dependent elimination for booleans amounts to

Γ ⊢ M : B Γ ⊢ N1 : P{true} Γ ⊢ N2 : P{false}Γ ⊢ if M then N1 else N2 : P{M}

We proposed a generic restriction for effectful CBN dependent elimination.

P must be linear (∼= CBV / algebra hom.)

Generalizes Krivine’s storage operatorsIf you weren’t at my Geocal-LAC talk, tant pis pour vousTowards a Linear Dependent {Big Data, Machine Learning, IoT}

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 7 / 44

Page 16: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Last Propaganda Slide: A Flurry of Buzzwords

Recall that dependent elimination for booleans amounts to

Γ ⊢ M : B Γ ⊢ N1 : P{true} Γ ⊢ N2 : P{false}Γ ⊢ if M then N1 else N2 : P{M}

We proposed a generic restriction for effectful CBN dependent elimination.

P must be linear (∼= CBV / algebra hom.)

Generalizes Krivine’s storage operatorsIf you weren’t at my Geocal-LAC talk, tant pis pour vousTowards a Linear Dependent {Big Data, Machine Learning, IoT}

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 7 / 44

Page 17: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Shameless Propaganda

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 8 / 44

Page 18: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Part IAn extension of CIC rooted in Shadok wisdom.

“The more it fails, the more likely it will eventually succeed.”

☺ Add a failure mechanism to CIC☺ Fully computational exceptions☺ Features full conversion☺ Features full dependent elimination😕 Didn’t I just say this was not possible???

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 9 / 44

Page 19: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Part IAn extension of CIC rooted in Shadok wisdom.

“The more it fails, the more likely it will eventually succeed.”

☺ Add a failure mechanism to CIC☺ Fully computational exceptions☺ Features full conversion☺ Features full dependent elimination

😕 Didn’t I just say this was not possible???

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 9 / 44

Page 20: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Part IAn extension of CIC rooted in Shadok wisdom.

“The more it fails, the more likely it will eventually succeed.”

☺ Add a failure mechanism to CIC☺ Fully computational exceptions☺ Features full conversion☺ Features full dependent elimination😕 Didn’t I just say this was not possible???

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 9 / 44

Page 21: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Part IAn extension of CIC rooted in Shadok wisdom.

“The more it fails, the more likely it will eventually succeed.”

☺ Add a failure mechanism to CIC☺ Fully computational exceptions☺ Features full conversion☺ Features full dependent elimination😕 Didn’t I just say this was not possible???

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 9 / 44

Page 22: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Type Theory: Overview

The exceptional type theory extends vanilla CIC with

E : □raise : ΠA : □.E → A

As hinted before, we need to be call-by-name to feature full conversion.raise (Πx : A.B) e ≡ λx : A. raise B ematch (raise I e) ret P with p⃗ ≡ raise (P (raise I e)) e

where P : I → □.

Remark that in call-by-name, if M : A → B, in generalM (raise A e) ̸≡ raise B e

for otherwise we would not have (λx : A.M) N ≡ M{x := N}.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 10 / 44

Page 23: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Type Theory: Overview

The exceptional type theory extends vanilla CIC with

E : □raise : ΠA : □.E → A

As hinted before, we need to be call-by-name to feature full conversion.raise (Πx : A.B) e ≡ λx : A. raise B ematch (raise I e) ret P with p⃗ ≡ raise (P (raise I e)) e

where P : I → □.

Remark that in call-by-name, if M : A → B, in generalM (raise A e) ̸≡ raise B e

for otherwise we would not have (λx : A.M) N ≡ M{x := N}.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 10 / 44

Page 24: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Type Theory: Overview

The exceptional type theory extends vanilla CIC with

E : □raise : ΠA : □.E → A

As hinted before, we need to be call-by-name to feature full conversion.raise (Πx : A.B) e ≡ λx : A. raise B ematch (raise I e) ret P with p⃗ ≡ raise (P (raise I e)) e

where P : I → □.

Remark that in call-by-name, if M : A → B, in generalM (raise A e) ̸≡ raise B e

for otherwise we would not have (λx : A.M) N ≡ M{x := N}.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 10 / 44

Page 25: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Catch Me If You CanRemember that on functions:

raise (Πx : A.B) e ≡ λx : A. raise B e

It means catching exceptions is limited to positive datatypes!

For inductive types, this is a generalized induction principle.

catchB : ΠP : B → □.P true →P false →(Πe : E.P (raise B e)) →

Πb : B.P b

Brect : ΠP : B → □.P true →P false →

Πb : B.P b

wherecatchB P pt pf pe true ≡ ptcatchB P pt pf pe false ≡ pfcatchB P pt pf pe (raise B e) ≡ pe e

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 11 / 44

Page 26: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Catch Me If You CanRemember that on functions:

raise (Πx : A.B) e ≡ λx : A. raise B e

It means catching exceptions is limited to positive datatypes!

For inductive types, this is a generalized induction principle.

catchB : ΠP : B → □.P true →P false →(Πe : E.P (raise B e)) →

Πb : B.P b

Brect : ΠP : B → □.P true →P false →

Πb : B.P b

wherecatchB P pt pf pe true ≡ ptcatchB P pt pf pe false ≡ pfcatchB P pt pf pe (raise B e) ≡ pe e

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 11 / 44

Page 27: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Mot d’Ordre: A Model

It’s not just randomly coming up with syntax though.

We want a justification for what we are doingWhat about normalization? Subject reduction? Other nice properties?... that’s called a model.

We want a model of the exceptional type theory!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 12 / 44

Page 28: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Mot d’Ordre: A Model

It’s not just randomly coming up with syntax though.

We want a justification for what we are doingWhat about normalization? Subject reduction? Other nice properties?

... that’s called a model.

We want a model of the exceptional type theory!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 12 / 44

Page 29: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Mot d’Ordre: A Model

It’s not just randomly coming up with syntax though.

We want a justification for what we are doingWhat about normalization? Subject reduction? Other nice properties?... that’s called a model.

We want a model of the exceptional type theory!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 12 / 44

Page 30: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Kardashian Functors, Anyone?Semantics of CIC has a fame of being horribly complex.

I won’t lie: it is. But part of this fame is nonetheless due to its models.

Set-theoretical models: because Sets are a (crappy) type theory.

Pro: Sets!Con: Sets!

Realizability models: construct programs that respect properties.

Pro: Computational, computer-science friendly.Con: Not foundational (requires an alien meta-theory), not decidable.

Categorical models: abstract description of type theory.

Pro: Abstract, subsumes the two former ones.Con: Realizability + very low level, gazillion variants, intrisically typed, static.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 13 / 44

Page 31: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Kardashian Functors, Anyone?Semantics of CIC has a fame of being horribly complex.

I won’t lie: it is. But part of this fame is nonetheless due to its models.

Set-theoretical models: because Sets are a (crappy) type theory.

Pro: Sets!Con: Sets!

Realizability models: construct programs that respect properties.

Pro: Computational, computer-science friendly.Con: Not foundational (requires an alien meta-theory), not decidable.

Categorical models: abstract description of type theory.

Pro: Abstract, subsumes the two former ones.Con: Realizability + very low level, gazillion variants, intrisically typed, static.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 13 / 44

Page 32: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Kardashian Functors, Anyone?Semantics of CIC has a fame of being horribly complex.

I won’t lie: it is. But part of this fame is nonetheless due to its models.

Set-theoretical models: because Sets are a (crappy) type theory.

Pro: Sets!Con: Sets!

Realizability models: construct programs that respect properties.

Pro: Computational, computer-science friendly.Con: Not foundational (requires an alien meta-theory), not decidable.

Categorical models: abstract description of type theory.

Pro: Abstract, subsumes the two former ones.Con: Realizability + very low level, gazillion variants, intrisically typed, static.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 13 / 44

Page 33: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Kardashian Functors, Anyone?Semantics of CIC has a fame of being horribly complex.

I won’t lie: it is. But part of this fame is nonetheless due to its models.

Set-theoretical models: because Sets are a (crappy) type theory.

Pro: Sets!Con: Sets!

Realizability models: construct programs that respect properties.

Pro: Computational, computer-science friendly.Con: Not foundational (requires an alien meta-theory), not decidable.

Categorical models: abstract description of type theory.

Pro: Abstract, subsumes the two former ones.Con: Realizability + very low level, gazillion variants, intrisically typed, static.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 13 / 44

Page 34: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Kardashian Functors, Anyone?Semantics of CIC has a fame of being horribly complex.

I won’t lie: it is. But part of this fame is nonetheless due to its models.

Set-theoretical models: because Sets are a (crappy) type theory.

Pro: Sets!Con: Sets!

Realizability models: construct programs that respect properties.

Pro: Computational, computer-science friendly.Con: Not foundational (requires an alien meta-theory), not decidable.

Categorical models: abstract description of type theory.

Pro: Abstract, subsumes the two former ones.Con: Realizability + very low level, gazillion variants, intrisically typed, static.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 13 / 44

Page 35: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Curry-Howard Orthodoxy

Instead, let’s look at what Curry-Howard provides in simpler settings.

Logical Interpretations ⇔ Program Translations

On the programming side, implement effects using e.g. the monadic style.A type transformer T, two combinators, a few equationsInterpret mechanically effectful programs (e.g. in Haskell)

On the logic side, extend expressivity through proof translation.Double-negation ⇒ classical logic (callcc)Friedman’s trick ⇒ Markov’s rule (exceptions)Forcing ⇒ ¬CH (global monotonous cell)

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 14 / 44

Page 36: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Curry-Howard Orthodoxy

Instead, let’s look at what Curry-Howard provides in simpler settings.

Logical Interpretations ⇔ Program Translations

On the programming side, implement effects using e.g. the monadic style.A type transformer T, two combinators, a few equationsInterpret mechanically effectful programs (e.g. in Haskell)

On the logic side, extend expressivity through proof translation.Double-negation ⇒ classical logic (callcc)Friedman’s trick ⇒ Markov’s rule (exceptions)Forcing ⇒ ¬CH (global monotonous cell)

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 14 / 44

Page 37: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Curry-Howard Orthodoxy

Instead, let’s look at what Curry-Howard provides in simpler settings.

Logical Interpretations ⇔ Program Translations

On the programming side, implement effects using e.g. the monadic style.A type transformer T, two combinators, a few equationsInterpret mechanically effectful programs (e.g. in Haskell)

On the logic side, extend expressivity through proof translation.Double-negation ⇒ classical logic (callcc)Friedman’s trick ⇒ Markov’s rule (exceptions)Forcing ⇒ ¬CH (global monotonous cell)

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 14 / 44

Page 38: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Syntactic Models

Let us do the same thing with CIC: build syntactic models.

Step 0: Fix a theory T := CIC.

Step 1: Define [·] on the syntax of T and derive [[·]] from it s.t.

⊢T M : A implies ⊢CIC [M ] : [[A]]

Step 2: Flip views and actually pose

⊢T M : A ∆= ⊢CIC [M ] : [[A]]

Step 3: Expand T by going down to the CIC assembly language,implementing new terms given by the [·] translation.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 15 / 44

Page 39: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Syntactic Models

Let us do the same thing with CIC: build syntactic models.

Step 0: Fix a theory T := CIC.

Step 1: Define [·] on the syntax of T and derive [[·]] from it s.t.

⊢T M : A implies ⊢CIC [M ] : [[A]]

Step 2: Flip views and actually pose

⊢T M : A ∆= ⊢CIC [M ] : [[A]]

Step 3: Expand T by going down to the CIC assembly language,implementing new terms given by the [·] translation.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 15 / 44

Page 40: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Syntactic Models

Let us do the same thing with CIC: build syntactic models.

Step 0: Fix a theory T := CIC.

Step 1: Define [·] on the syntax of T and derive [[·]] from it s.t.

⊢T M : A implies ⊢CIC [M ] : [[A]]

Step 2: Flip views and actually pose

⊢T M : A ∆= ⊢CIC [M ] : [[A]]

Step 3: Expand T by going down to the CIC assembly language,implementing new terms given by the [·] translation.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 15 / 44

Page 41: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Syntactic Models

Let us do the same thing with CIC: build syntactic models.

Step 0: Fix a theory T := CIC.

Step 1: Define [·] on the syntax of T and derive [[·]] from it s.t.

⊢T M : A implies ⊢CIC [M ] : [[A]]

Step 2: Flip views and actually pose

⊢T M : A ∆= ⊢CIC [M ] : [[A]]

Step 3: Expand T by going down to the CIC assembly language,implementing new terms given by the [·] translation.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 15 / 44

Page 42: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Syntactic Models

Let us do the same thing with CIC: build syntactic models.

Step 0: Fix a theory T := CIC.

Step 1: Define [·] on the syntax of T and derive [[·]] from it s.t.

⊢T M : A implies ⊢CIC [M ] : [[A]]

Step 2: Flip views and actually pose

⊢T M : A ∆= ⊢CIC [M ] : [[A]]

Step 3: Expand T by going down to the CIC assembly language,implementing new terms given by the [·] translation.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 15 / 44

Page 43: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

« CIC, the LLVM of Type Theory »

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 16 / 44

Page 44: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation

Let’s implement the exceptional type theory into CIC!

Source is a CBN theory, so usual monadic encoding won’t work.We use a variant of our previous weaning translation.All typing and computations rules mentioned before hold for free.

Let’s call the exceptional type theory TE to disambiguate it from CIC.

Only parameter of the translation: a fixed type of exceptions in the target.

⊢CIC E : □

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 17 / 44

Page 45: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation

Let’s implement the exceptional type theory into CIC!

Source is a CBN theory, so usual monadic encoding won’t work.We use a variant of our previous weaning translation.All typing and computations rules mentioned before hold for free.

Let’s call the exceptional type theory TE to disambiguate it from CIC.

Only parameter of the translation: a fixed type of exceptions in the target.

⊢CIC E : □

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 17 / 44

Page 46: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation

Let’s implement the exceptional type theory into CIC!

Source is a CBN theory, so usual monadic encoding won’t work.We use a variant of our previous weaning translation.All typing and computations rules mentioned before hold for free.

Let’s call the exceptional type theory TE to disambiguate it from CIC.

Only parameter of the translation: a fixed type of exceptions in the target.

⊢CIC E : □

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 17 / 44

Page 47: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation

Let’s implement the exceptional type theory into CIC!

Source is a CBN theory, so usual monadic encoding won’t work.We use a variant of our previous weaning translation.All typing and computations rules mentioned before hold for free.

Let’s call the exceptional type theory TE to disambiguate it from CIC.

Only parameter of the translation: a fixed type of exceptions in the target.

⊢CIC E : □

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 17 / 44

Page 48: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation, Negative case

Intuition: ⊢TE A : □ ⇝ ⊢CIC [A] : ΣA : □.E → A.

Every exceptional type comes with its own implementation of failure!

[[A]] : □ := π1 [A] and [A]∅ : E → [[A]] := π2 [A]

[[Πx : A.B]] ≡ Πx : [[A]]. [[B]][Πx : A.B ]∅ e ≡ λx : [[A]]. [B ]∅ e[x ] ≡ x[M N ] ≡ [M ] [N ][λx : A.M ] ≡ λx : [[A]]. [M ]

If Γ ⊢CIC M : A then [[Γ]] ⊢CIC [M ] : [[A]].

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 18 / 44

Page 49: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation, Negative case

Intuition: ⊢TE A : □ ⇝ ⊢CIC [A] : ΣA : □.E → A.

Every exceptional type comes with its own implementation of failure!

[[A]] : □ := π1 [A] and [A]∅ : E → [[A]] := π2 [A]

[[Πx : A.B]] ≡ Πx : [[A]]. [[B]][Πx : A.B ]∅ e ≡ λx : [[A]]. [B ]∅ e[x ] ≡ x[M N ] ≡ [M ] [N ][λx : A.M ] ≡ λx : [[A]]. [M ]

If Γ ⊢CIC M : A then [[Γ]] ⊢CIC [M ] : [[A]].

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 18 / 44

Page 50: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation, Negative case

Intuition: ⊢TE A : □ ⇝ ⊢CIC [A] : ΣA : □.E → A.

Every exceptional type comes with its own implementation of failure!

[[A]] : □ := π1 [A] and [A]∅ : E → [[A]] := π2 [A]

[[Πx : A.B]] ≡ Πx : [[A]]. [[B]][Πx : A.B ]∅ e ≡ λx : [[A]]. [B ]∅ e[x ] ≡ x[M N ] ≡ [M ] [N ][λx : A.M ] ≡ λx : [[A]]. [M ]

If Γ ⊢CIC M : A then [[Γ]] ⊢CIC [M ] : [[A]].

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 18 / 44

Page 51: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation, Failure

It is straightforward to implement the failure operation.

E : □raise : ΠA : □.E → A

[E ] : ΣA : □.E → A[E ] := (E, λe : E. e)

[raise ] : ΠA0 : (ΣA : □.E → A).E → π1 A0

[raise ] := π2

Computational rules trivially hold![raise (Πx : A.B) e ] ≡ [λx : A. raise B e ]

≡ ≡

π2 ((Πx : [[A]]. [[B]]), (λ(e : E) (x : [[A]]). π2 [[B]] e)) [e ] ≡ λx : [[A]]. π2 [B ] [e ]

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 19 / 44

Page 52: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation, Failure

It is straightforward to implement the failure operation.

E : □raise : ΠA : □.E → A

[E ] : ΣA : □.E → A[E ] := (E, λe : E. e)

[raise ] : ΠA0 : (ΣA : □.E → A).E → π1 A0

[raise ] := π2

Computational rules trivially hold![raise (Πx : A.B) e ] ≡ [λx : A. raise B e ]

≡ ≡

π2 ((Πx : [[A]]. [[B]]), (λ(e : E) (x : [[A]]). π2 [[B]] e)) [e ] ≡ λx : [[A]]. π2 [B ] [e ]

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 19 / 44

Page 53: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation, Failure

It is straightforward to implement the failure operation.

E : □raise : ΠA : □.E → A

[E ] : ΣA : □.E → A[E ] := (E, λe : E. e)

[raise ] : ΠA0 : (ΣA : □.E → A).E → π1 A0

[raise ] := π2

Computational rules trivially hold![raise (Πx : A.B) e ] ≡ [λx : A. raise B e ]

≡ ≡

π2 ((Πx : [[A]]. [[B]]), (λ(e : E) (x : [[A]]). π2 [[B]] e)) [e ] ≡ λx : [[A]]. π2 [B ] [e ]

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 19 / 44

Page 54: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation, Positive case

The really interesting case is the inductive part of CIC.

How to implement [B]∅ : E → [[B]]?

Could pose [[B]] := B and take an arbitrary boolean for [B]∅...

... but that would not play well with computation, e.g. catch.

Worse, what about [⊥]∅ : E → [[⊥]]?

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 20 / 44

Page 55: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation, Positive case

The really interesting case is the inductive part of CIC.

How to implement [B]∅ : E → [[B]]?

Could pose [[B]] := B and take an arbitrary boolean for [B]∅...

... but that would not play well with computation, e.g. catch.

Worse, what about [⊥]∅ : E → [[⊥]]?

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 20 / 44

Page 56: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation, Positive case

The really interesting case is the inductive part of CIC.

How to implement [B]∅ : E → [[B]]?

Could pose [[B]] := B and take an arbitrary boolean for [B]∅...

... but that would not play well with computation, e.g. catch.

Worse, what about [⊥]∅ : E → [[⊥]]?

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 20 / 44

Page 57: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation, Positive case

Very elegant solution: add a default case to every inductive type!

Inductive [[B]] := [true ] : [[B]] | [false ] : [[B]] | B∅ : E → [[B]]

Pattern-matching is translated pointwise, except for the new case.

[[ΠP : B → □.P true → P false → Πb : B.P b]]

≡ ΠP : [[B]] → [[□]].P [true] → P [false] → Πb : [[B]].P b

If b is [true], use first hypothesisIf b is [false], use second hypothesisIf b is an error B∅ e, reraise e using [P b ]∅ e

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 21 / 44

Page 58: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Exceptional Implementation, Positive case

Very elegant solution: add a default case to every inductive type!

Inductive [[B]] := [true ] : [[B]] | [false ] : [[B]] | B∅ : E → [[B]]

Pattern-matching is translated pointwise, except for the new case.

[[ΠP : B → □.P true → P false → Πb : B.P b]]

≡ ΠP : [[B]] → [[□]].P [true] → P [false] → Πb : [[B]].P b

If b is [true], use first hypothesisIf b is [false], use second hypothesisIf b is an error B∅ e, reraise e using [P b ]∅ e

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 21 / 44

Page 59: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Shadok Logic Strikes Back

TheoremThe exceptional translation interprets all of CIC.

☺ A type theory with effects!☺ Compiled away to CIC!☺ Features full conversion☺ Features full dependent elimination😖 Ah, yeah, and also, the theory is inconsistent.

It suffices to raise an exception to inhabit any type.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 22 / 44

Page 60: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Shadok Logic Strikes Back

TheoremThe exceptional translation interprets all of CIC.

☺ A type theory with effects!☺ Compiled away to CIC!☺ Features full conversion☺ Features full dependent elimination

😖 Ah, yeah, and also, the theory is inconsistent.

It suffices to raise an exception to inhabit any type.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 22 / 44

Page 61: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Shadok Logic Strikes Back

TheoremThe exceptional translation interprets all of CIC.

☺ A type theory with effects!☺ Compiled away to CIC!☺ Features full conversion☺ Features full dependent elimination

😖 Ah, yeah, and also, the theory is inconsistent.

It suffices to raise an exception to inhabit any type.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 22 / 44

Page 62: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Shadok Logic Strikes Back

TheoremThe exceptional translation interprets all of CIC.

☺ A type theory with effects!☺ Compiled away to CIC!☺ Features full conversion☺ Features full dependent elimination😖 Ah, yeah, and also, the theory is inconsistent.

It suffices to raise an exception to inhabit any type.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 22 / 44

Page 63: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Consistency: A Social Construct

An Impure Dependently-typed Programming LanguageDo you whine about the fact that OCaml is logically inconsistent?

Theorem (Exceptional Canonicity a.k.a. Progress a.k.a. Meaningless explanations)

If ⊢TE M : ⊥, then M ≡ raise ⊥ e for some e : E.

A Safe Target FrameworkYou can still use the CIC target to prove properties about TE programs!

CliffhangerYou can prove that a program does not raise uncaught exceptions.

And now for a little ad before the second part of the show!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 23 / 44

Page 64: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Consistency: A Social Construct

An Impure Dependently-typed Programming LanguageDo you whine about the fact that OCaml is logically inconsistent?

Theorem (Exceptional Canonicity a.k.a. Progress a.k.a. Meaningless explanations)

If ⊢TE M : ⊥, then M ≡ raise ⊥ e for some e : E.

A Safe Target FrameworkYou can still use the CIC target to prove properties about TE programs!

CliffhangerYou can prove that a program does not raise uncaught exceptions.

And now for a little ad before the second part of the show!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 23 / 44

Page 65: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Consistency: A Social Construct

An Impure Dependently-typed Programming LanguageDo you whine about the fact that OCaml is logically inconsistent?

Theorem (Exceptional Canonicity a.k.a. Progress a.k.a. Meaningless explanations)

If ⊢TE M : ⊥, then M ≡ raise ⊥ e for some e : E.

A Safe Target FrameworkYou can still use the CIC target to prove properties about TE programs!

CliffhangerYou can prove that a program does not raise uncaught exceptions.

And now for a little ad before the second part of the show!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 23 / 44

Page 66: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Consistency: A Social Construct

An Impure Dependently-typed Programming LanguageDo you whine about the fact that OCaml is logically inconsistent?

Theorem (Exceptional Canonicity a.k.a. Progress a.k.a. Meaningless explanations)

If ⊢TE M : ⊥, then M ≡ raise ⊥ e for some e : E.

A Safe Target FrameworkYou can still use the CIC target to prove properties about TE programs!

CliffhangerYou can prove that a program does not raise uncaught exceptions.

And now for a little ad before the second part of the show!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 23 / 44

Page 67: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Consistency: A Social Construct

An Impure Dependently-typed Programming LanguageDo you whine about the fact that OCaml is logically inconsistent?

Theorem (Exceptional Canonicity a.k.a. Progress a.k.a. Meaningless explanations)

If ⊢TE M : ⊥, then M ≡ raise ⊥ e for some e : E.

A Safe Target FrameworkYou can still use the CIC target to prove properties about TE programs!

CliffhangerYou can prove that a program does not raise uncaught exceptions.

And now for a little ad before the second part of the show!P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 23 / 44

Page 68: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Informercial — Did You Know?

The exceptional translation is just a principled Friedman’s A-translation!

As such, it can be used for classical proof extraction.

Informative double-negation[[¬¬A]] ∼= ([[A]] → E) → E

First-order purificationIf P is a Σ0

1 type, then ⊢CIC [[P]] ↔ P + E.

Friedman’s Trick in CICIf P and Q are Σ0

1 types, ⊢CIC Πp : P.¬¬Q implies ⊢CIC Πp : P.Q.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 24 / 44

Page 69: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Informercial — Did You Know?

The exceptional translation is just a principled Friedman’s A-translation!

As such, it can be used for classical proof extraction.

Informative double-negation[[¬¬A]] ∼= ([[A]] → E) → E

First-order purificationIf P is a Σ0

1 type, then ⊢CIC [[P]] ↔ P + E.

Friedman’s Trick in CICIf P and Q are Σ0

1 types, ⊢CIC Πp : P.¬¬Q implies ⊢CIC Πp : P.Q.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 24 / 44

Page 70: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Informercial — Did You Know?

The exceptional translation is just a principled Friedman’s A-translation!

As such, it can be used for classical proof extraction.

Informative double-negation[[¬¬A]] ∼= ([[A]] → E) → E

First-order purificationIf P is a Σ0

1 type, then ⊢CIC [[P]] ↔ P + E.

Friedman’s Trick in CICIf P and Q are Σ0

1 types, ⊢CIC Πp : P.¬¬Q implies ⊢CIC Πp : P.Q.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 24 / 44

Page 71: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Informercial — Did You Know?

The exceptional translation is just a principled Friedman’s A-translation!

As such, it can be used for classical proof extraction.

Informative double-negation[[¬¬A]] ∼= ([[A]] → E) → E

First-order purificationIf P is a Σ0

1 type, then ⊢CIC [[P]] ↔ P + E.

Friedman’s Trick in CICIf P and Q are Σ0

1 types, ⊢CIC Πp : P.¬¬Q implies ⊢CIC Πp : P.Q.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 24 / 44

Page 72: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Part II

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 25 / 44

Page 73: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

If You Joined the Talk Recently

The exceptional type theory is logically inconsistent!

Cliffhanger (cont.)You can prove that a program does not raise uncaught exceptions.

Let’s call valid a program in TE that “does not raise exceptions”.

For instance,there is no valid proof of ⊥the only valid booleans are true and falsea function is valid if it produces a valid result out of a valid argument

Validity is a type-directed notion!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 26 / 44

Page 74: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

If You Joined the Talk Recently

The exceptional type theory is logically inconsistent!

Cliffhanger (cont.)You can prove that a program does not raise uncaught exceptions.

Let’s call valid a program in TE that “does not raise exceptions”.

For instance,there is no valid proof of ⊥the only valid booleans are true and falsea function is valid if it produces a valid result out of a valid argument

Validity is a type-directed notion!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 26 / 44

Page 75: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

If You Joined the Talk Recently

The exceptional type theory is logically inconsistent!

Cliffhanger (cont.)You can prove that a program does not raise uncaught exceptions.

Let’s call valid a program in TE that “does not raise exceptions”.

For instance,there is no valid proof of ⊥the only valid booleans are true and falsea function is valid if it produces a valid result out of a valid argument

Validity is a type-directed notion!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 26 / 44

Page 76: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Curry-Howard-Shadok CorrespondenceLet’s locally write M ⊩ A if M is valid at A.

f ⊩ A → B ≡ ∀x : [[A]]. x ⊩ A → f x ⊩ B

What? That’s just logical relations.

Come on. That’s intuitionistic realizability.

Fools ! That’s parametricity.

Zo!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 27 / 44

Page 77: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Curry-Howard-Shadok CorrespondenceLet’s locally write M ⊩ A if M is valid at A.

f ⊩ A → B ≡ ∀x : [[A]]. x ⊩ A → f x ⊩ B

What? That’s just logical relations.

Come on. That’s intuitionistic realizability.

Fools ! That’s parametricity.

Zo!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 27 / 44

Page 78: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Curry-Howard-Shadok CorrespondenceLet’s locally write M ⊩ A if M is valid at A.

f ⊩ A → B ≡ ∀x : [[A]]. x ⊩ A → f x ⊩ B

What? That’s just logical relations.

Come on. That’s intuitionistic realizability.

Fools ! That’s parametricity.

Zo!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 27 / 44

Page 79: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Curry-Howard-Shadok CorrespondenceLet’s locally write M ⊩ A if M is valid at A.

f ⊩ A → B ≡ ∀x : [[A]]. x ⊩ A → f x ⊩ B

What? That’s just logical relations.

Come on. That’s intuitionistic realizability.

Fools ! That’s parametricity.

Zo!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 27 / 44

Page 80: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Curry-Howard-Shadok CorrespondenceLet’s locally write M ⊩ A if M is valid at A.

f ⊩ A → B ≡ ∀x : [[A]]. x ⊩ A → f x ⊩ B

What? That’s just logical relations.

Come on. That’s intuitionistic realizability.

Fools ! That’s parametricity.

Zo!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 27 / 44

Page 81: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

The Curry-Howard-Shadok CorrespondenceLet’s locally write M ⊩ A if M is valid at A.

f ⊩ A → B ≡ ∀x : [[A]]. x ⊩ A → f x ⊩ B

What? That’s just logical relations.

Come on. That’s intuitionistic realizability.

Fools ! That’s parametricity.

Zo!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 27 / 44

Page 82: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Making Everybody Agree

It’s actually folklore that these techniques are essentially the same.

And there is already a parametricity translation for CIC! (Bernardy-Lasson)

We just have to adapt it to our exceptional translation.

Idea:

From ⊢ M : A produce two sequents

⊢CIC [M] : [[A]]

+

⊢CIC [M]ε : [[A]]ε [M]

where [[A]]ε : [[A]] → □ is the validity predicate.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 28 / 44

Page 83: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Making Everybody Agree

It’s actually folklore that these techniques are essentially the same.

And there is already a parametricity translation for CIC! (Bernardy-Lasson)

We just have to adapt it to our exceptional translation.

Idea:

From ⊢ M : A produce two sequents

⊢CIC [M] : [[A]]

+

⊢CIC [M]ε : [[A]]ε [M]

where [[A]]ε : [[A]] → □ is the validity predicate.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 28 / 44

Page 84: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Making Everybody Agree

It’s actually folklore that these techniques are essentially the same.

And there is already a parametricity translation for CIC! (Bernardy-Lasson)

We just have to adapt it to our exceptional translation.

Idea:

From ⊢ M : A produce two sequents

⊢CIC [M] : [[A]]

+

⊢CIC [M]ε : [[A]]ε [M]

where [[A]]ε : [[A]] → □ is the validity predicate.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 28 / 44

Page 85: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Parametric Exceptional Translation (Sketch)

Most notably,

[[Πx : A.B]]ε f ≡ Π(x : [[A]]) (xε : [[A]]ε x). [[B]]ε (f x)

[[B]]ε b ∼= b = [true] + b = [false]

[[⊥]]ε s ∼= ⊥

Every pure term is now automatically parametric.

If Γ ⊢CIC M : A then [[Γ]]ε ⊢CIC [M ]ε : [[A]]ε [M].

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 29 / 44

Page 86: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Parametric Exceptional Translation (Sketch)

Most notably,

[[Πx : A.B]]ε f ≡ Π(x : [[A]]) (xε : [[A]]ε x). [[B]]ε (f x)

[[B]]ε b ∼= b = [true] + b = [false]

[[⊥]]ε s ∼= ⊥

Every pure term is now automatically parametric.

If Γ ⊢CIC M : A then [[Γ]]ε ⊢CIC [M ]ε : [[A]]ε [M].

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 29 / 44

Page 87: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

A Few Nice Results

Let’s call T pE the resulting theory. It inherits a lot from CIC!

Theorem (Consistency)T pE is consistent.

Theorem (Canonicity)T pE enjoys canonicity, i.e if ⊢T p

EM : N then M⇝∗ n̄ ∈ N̄.

Theorem (Syntax)T pE has decidable type-checking, strong normalization and whatnot.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 30 / 44

Page 88: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

What If There Were No Cake?

Bernardy-Lasson parametricity is a conservative extension of CIC...

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 31 / 44

Page 89: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

What If There Were No Cake?

Bernardy-Lasson parametricity is a conservative extension of CIC...

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 31 / 44

Page 90: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

What If There Were No Cake?

Bernardy-Lasson parametricity is a conservative extension of CIC...

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 31 / 44

Page 91: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Less Is More

SpoilerT pE is not a conservative extension of CIC.

Intuitively,raising uncaught exceptions is forbidden in T p

E... but you can still raise them locally... as long as you prove they don’t escape!

TE is the unsafe Coq fragment, and T pE a semantical layer atop of it.

Actually T pE is the embodiement of Kreisel modified realizability in CIC.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 32 / 44

Page 92: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Less Is More

SpoilerT pE is not a conservative extension of CIC.

Intuitively,raising uncaught exceptions is forbidden in T p

E

... but you can still raise them locally

... as long as you prove they don’t escape!

TE is the unsafe Coq fragment, and T pE a semantical layer atop of it.

Actually T pE is the embodiement of Kreisel modified realizability in CIC.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 32 / 44

Page 93: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Less Is More

SpoilerT pE is not a conservative extension of CIC.

Intuitively,raising uncaught exceptions is forbidden in T p

E... but you can still raise them locally... as long as you prove they don’t escape!

TE is the unsafe Coq fragment, and T pE a semantical layer atop of it.

Actually T pE is the embodiement of Kreisel modified realizability in CIC.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 32 / 44

Page 94: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Less Is More

SpoilerT pE is not a conservative extension of CIC.

Intuitively,raising uncaught exceptions is forbidden in T p

E... but you can still raise them locally... as long as you prove they don’t escape!

TE is the unsafe Coq fragment, and T pE a semantical layer atop of it.

Actually T pE is the embodiement of Kreisel modified realizability in CIC.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 32 / 44

Page 95: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Less Is More

SpoilerT pE is not a conservative extension of CIC.

Intuitively,raising uncaught exceptions is forbidden in T p

E... but you can still raise them locally... as long as you prove they don’t escape!

TE is the unsafe Coq fragment, and T pE a semantical layer atop of it.

Actually T pE is the embodiement of Kreisel modified realizability in CIC.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 32 / 44

Page 96: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Explaining the Analogy

Kreisel realizability T pE

Source theory HA or HAω CIC

Programming language System T TE (“unsafe Coq”)

Logical meta-theory HAω CIC

Kreisel realizability extends arithmetic with essentially two principles.ACN : (∀n : N. ∃m : N.P (m,n)) → ∃f : N → N.∀n : N.P (n, f n)IP : (¬A → ∃n : N.P n) → ∃n : N.¬A → P n

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 33 / 44

Page 97: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Explaining the Analogy

Kreisel realizability T pE

Source theory HA or HAω CIC

Programming language System T TE (“unsafe Coq”)

Logical meta-theory HAω CIC

Kreisel realizability extends arithmetic with essentially two principles.ACN : (∀n : N. ∃m : N.P (m,n)) → ∃f : N → N.∀n : N.P (n, f n)IP : (¬A → ∃n : N.P n) → ∃n : N.¬A → P n

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 33 / 44

Page 98: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Choice

ACN : (∀n : N. ∃m : N.P (m,n)) → ∃f : N → N.∀n : N.P (n, f n)

Not much to say here.

In Kreisel realizability, ACN is a consequence of canonicity of System T.

In T pE , ACN is a consequence of dependent elimination.

The latter is in turn meta-theoretically justified by canonicity.

In both cases, choice is built-in and a consequence of canonicity.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 34 / 44

Page 99: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Choice

ACN : (∀n : N. ∃m : N.P (m,n)) → ∃f : N → N.∀n : N.P (n, f n)

Not much to say here.

In Kreisel realizability, ACN is a consequence of canonicity of System T.

In T pE , ACN is a consequence of dependent elimination.

The latter is in turn meta-theoretically justified by canonicity.

In both cases, choice is built-in and a consequence of canonicity.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 34 / 44

Page 100: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Choice

ACN : (∀n : N. ∃m : N.P (m,n)) → ∃f : N → N.∀n : N.P (n, f n)

Not much to say here.

In Kreisel realizability, ACN is a consequence of canonicity of System T.

In T pE , ACN is a consequence of dependent elimination.

The latter is in turn meta-theoretically justified by canonicity.

In both cases, choice is built-in and a consequence of canonicity.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 34 / 44

Page 101: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Independence of Premises

IP : (¬A → ∃n : N.P n) → ∃n : N.¬A → P n

That one is interesting! A unforeseen consequence of a subtle bug.

Kreisel’s bugEvery type of realizers is inhabited. In particular, [[⊥]]KR ≡ N.

The realizer of IP critically relies on that!

Assuming System T had an empty type 0, and setting [[⊥]]KR ≡ 0

KR is still a model of HAKR still validates ACN

KR doesn’t validate IP anymore

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 35 / 44

Page 102: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Independence of Premises

IP : (¬A → ∃n : N.P n) → ∃n : N.¬A → P n

That one is interesting! A unforeseen consequence of a subtle bug.

Kreisel’s bugEvery type of realizers is inhabited. In particular, [[⊥]]KR ≡ N.

The realizer of IP critically relies on that!

Assuming System T had an empty type 0, and setting [[⊥]]KR ≡ 0

KR is still a model of HAKR still validates ACN

KR doesn’t validate IP anymore

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 35 / 44

Page 103: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Volem Independència

IP : (¬A → ∃n : N.P n) → ∃n : N.¬A → P n

Theorem (CIC + IP)T pE validates IP, owing to the fact that in TE, every type is inhabited.

Proof (sketch).In TE, build a term ip : IP

Given f : ¬A → Σn : N.P n, apply it to raise (¬A) e.If the returned integer is pure, return it with the associated proof.Otherwise, return a dummy integer and failing proof.

Easy to show that ip is actually valid in T pE .

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 36 / 44

Page 104: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Volem Independència

IP : (¬A → ∃n : N.P n) → ∃n : N.¬A → P n

Theorem (CIC + IP)T pE validates IP, owing to the fact that in TE, every type is inhabited.

Proof (sketch).In TE, build a term ip : IP

Given f : ¬A → Σn : N.P n, apply it to raise (¬A) e.If the returned integer is pure, return it with the associated proof.Otherwise, return a dummy integer and failing proof.

Easy to show that ip is actually valid in T pE .

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 36 / 44

Page 105: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Another Result for FreeRecall Markov’s principle:

ΠP : N → B.¬¬(Σn : N.P n = true) → Σn : N.P n = true (MP)

Kreisel’s RazorPick two out of three: {canonicity, IP, MP}.

IP + MP ⇒ ΠP : N → B.Σn : N.Πm : N.P m = true → P n = true

Together with canonicity, this solves the halting problem.

Corollary̸⊢T p

EMP and thus ̸⊢CIC MP.

(This was proved recently by Coquand-Mannaa, although in a completely different way.)

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 37 / 44

Page 106: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Another Result for FreeRecall Markov’s principle:

ΠP : N → B.¬¬(Σn : N.P n = true) → Σn : N.P n = true (MP)

Kreisel’s RazorPick two out of three: {canonicity, IP, MP}.

IP + MP ⇒ ΠP : N → B.Σn : N.Πm : N.P m = true → P n = true

Together with canonicity, this solves the halting problem.

Corollary̸⊢T p

EMP and thus ̸⊢CIC MP.

(This was proved recently by Coquand-Mannaa, although in a completely different way.)

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 37 / 44

Page 107: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Another Result for FreeRecall Markov’s principle:

ΠP : N → B.¬¬(Σn : N.P n = true) → Σn : N.P n = true (MP)

Kreisel’s RazorPick two out of three: {canonicity, IP, MP}.

IP + MP ⇒ ΠP : N → B.Σn : N.Πm : N.P m = true → P n = true

Together with canonicity, this solves the halting problem.

Corollary̸⊢T p

EMP and thus ̸⊢CIC MP.

(This was proved recently by Coquand-Mannaa, although in a completely different way.)

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 37 / 44

Page 108: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Another Result for FreeRecall Markov’s principle:

ΠP : N → B.¬¬(Σn : N.P n = true) → Σn : N.P n = true (MP)

Kreisel’s RazorPick two out of three: {canonicity, IP, MP}.

IP + MP ⇒ ΠP : N → B.Σn : N.Πm : N.P m = true → P n = true

Together with canonicity, this solves the halting problem.

Corollary̸⊢T p

EMP and thus ̸⊢CIC MP.

(This was proved recently by Coquand-Mannaa, although in a completely different way.)P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 37 / 44

Page 109: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Function Intensionality

Another interesting consequence that is similar to what happens in KR.

T pE satisfies definitional η-expansion: λx : A.M x ≡ M.

But it violates function extensionality!

⊢T pEΠi : 1. i = tt and ⊢T p

E(λi : 1. i) ̸= (λi : 1. tt)

The reason is that there are invalid proofs of 1.

You cannot build them, but they exists as phantom arguments.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 38 / 44

Page 110: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Function Intensionality

Another interesting consequence that is similar to what happens in KR.

T pE satisfies definitional η-expansion: λx : A.M x ≡ M.

But it violates function extensionality!

⊢T pEΠi : 1. i = tt and ⊢T p

E(λi : 1. i) ̸= (λi : 1. tt)

The reason is that there are invalid proofs of 1.

You cannot build them, but they exists as phantom arguments.

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 38 / 44

Page 111: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

What Else?

What kind of similar horrors can we do in T pE ?

I don’t know!But there are probably lessons to be taken from realizabilityI’m probably pissing off both HoTT and PRL zealots by now

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 39 / 44

Page 112: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Get You A Larger Coq, Today!

We implemented TE and T pE in Coq in a plugin.

https://github.com/CoqHott/exceptional-tt

Allows to add exceptions to Coq just today.Compile effectful terms on the fly.Allows to reason about them in Coq.Write mind-blowing low-level code!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 40 / 44

Page 113: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

If You Were Sleeping During The Talk

TE, a type theory that allows failure!

Inconsistent as a logical theoryA dependently-typed effectful programming languageCan still be used for proof extraction like Friedman’s A-translation

T pE , a type theory that allows local failure!

A safe layer atop TE that enforces consistencyStrict superset of CIC: proves IP, ¬funext, disproves MP

Both of them justified by purely syntactical means!

“The more it fails, the more likely it will eventually succeed.”

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 41 / 44

Page 114: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

If You Were Sleeping During The Talk

TE, a type theory that allows failure!

Inconsistent as a logical theoryA dependently-typed effectful programming languageCan still be used for proof extraction like Friedman’s A-translation

T pE , a type theory that allows local failure!

A safe layer atop TE that enforces consistencyStrict superset of CIC: proves IP, ¬funext, disproves MP

Both of them justified by purely syntactical means!

“The more it fails, the more likely it will eventually succeed.”

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 41 / 44

Page 115: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

If You Were Sleeping During The Talk

TE, a type theory that allows failure!

Inconsistent as a logical theoryA dependently-typed effectful programming languageCan still be used for proof extraction like Friedman’s A-translation

T pE , a type theory that allows local failure!

A safe layer atop TE that enforces consistencyStrict superset of CIC: proves IP, ¬funext, disproves MP

Both of them justified by purely syntactical means!

“The more it fails, the more likely it will eventually succeed.”

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 41 / 44

Page 116: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

If You Were Sleeping During The Talk

TE, a type theory that allows failure!

Inconsistent as a logical theoryA dependently-typed effectful programming languageCan still be used for proof extraction like Friedman’s A-translation

T pE , a type theory that allows local failure!

A safe layer atop TE that enforces consistencyStrict superset of CIC: proves IP, ¬funext, disproves MP

Both of them justified by purely syntactical means!

“The more it fails, the more likely it will eventually succeed.”P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 41 / 44

Page 117: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

TODO When I Have a Permanent Position

TE looks like a good intermediate language for model buildingThe Calculus of Shadok ConstructionsPotential applications to Gradual Typing?Syntactic models are super cool! Let’s write more!

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 42 / 44

Page 118: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work
Page 119: Failure is Not an Option The Curry-Howard-Shadok ...édrot.fr/slides/pps-02-18.pdf · Failure is Not an Option The Curry-Howard-Shadok correspondence Pierre-Marie Pédrot joint work

Food For Thought

It seems you need to have a name starting with K to name a realizability.

KleeneKreiselKrivine

P.-M. Pédrot (MPI-SWS) Failure is Not an Option 22/02/2018 44 / 44