A Parametric CPS to Sprinkle CIC with Classical Reasoning - - PowerPoint PPT Presentation

a parametric cps to sprinkle cic with classical reasoning
SMART_READER_LITE
LIVE PREVIEW

A Parametric CPS to Sprinkle CIC with Classical Reasoning - - PowerPoint PPT Presentation

. . . . . . . . . . . . . . A Parametric CPS to Sprinkle CIC with Classical Reasoning Pierre-Marie Pdrot University of Ljubljana LOLA 2017 19th June 2017 Pdrot (U. Ljubljana) A Parametric CPS 19/06/2017 . . . . . . .


slide-1
SLIDE 1

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Parametric CPS to Sprinkle CIC with Classical Reasoning

Pierre-Marie Pédrot

University of Ljubljana

LOLA 2017 19th June 2017

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 1 / 33

slide-2
SLIDE 2

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CIC, I’m loving it Dependent Type Theory is awesome!

The pinacle of the Curry-Howard correspondence: You can program with it “A pure functional programming with crazily precise types.” You can prove with it “A incredibly rich constructive logic with built-in computation.” Everything at the same time! “Prove your programs! Program your proofs!”

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 2 / 33

slide-3
SLIDE 3

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CIC, I’m loving it Dependent Type Theory is awesome!

The pinacle of the Curry-Howard correspondence: You can program with it “A pure functional programming with crazily precise types.” You can prove with it “A incredibly rich constructive logic with built-in computation.” Everything at the same time! “Prove your programs! Program your proofs!”

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 2 / 33

slide-4
SLIDE 4

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CIC, I’m loving it Dependent Type Theory is awesome!

The pinacle of the Curry-Howard correspondence: You can program with it “A pure functional programming with crazily precise types.” You can prove with it “A incredibly rich constructive logic with built-in computation.” Everything at the same time! “Prove your programs! Program your proofs!”

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 2 / 33

slide-5
SLIDE 5

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

An efgective object

That’s just not theoretical ramble.

Lots of actual, serious, big developments.

CompCert, VST, RustBelt... Four Colour Theorem, Feit-Thompson...

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 3 / 33

slide-6
SLIDE 6

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

An efgective object

That’s just not theoretical ramble.

Lots of actual, serious, big developments.

CompCert, VST, RustBelt... Four Colour Theorem, Feit-Thompson...

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 3 / 33

slide-7
SLIDE 7

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Classical Problem

In practice, many people reason in the dreaded classical logic. em : Π(A : □). A ∨ ¬A Both a theoretical and practical limitation! CIC is deadcore intuitionistic Requires that you write your statements in the right way Most non-logicians don’t care about this fuss (both CS and math...)

It would be nice to have a type theory...

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 4 / 33

slide-8
SLIDE 8

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Classical Problem

In practice, many people reason in the dreaded classical logic. em : Π(A : □). A ∨ ¬A Both a theoretical and practical limitation! CIC is deadcore intuitionistic Requires that you write your statements in the right way Most non-logicians don’t care about this fuss (both CS and math...)

It would be nice to have a type theory...

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 4 / 33

slide-9
SLIDE 9

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Classical Problem

In practice, many people reason in the dreaded classical logic. em : Π(A : □). A ∨ ¬A Both a theoretical and practical limitation! CIC is deadcore intuitionistic Requires that you write your statements in the right way Most non-logicians don’t care about this fuss (both CS and math...)

It would be nice to have a classical type theory...

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 4 / 33

slide-10
SLIDE 10

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Attempt 1: The Truth is Out There

There is a very simple straightforward solution.

Axiom classical forall A Type A A

Pro: Simple, local, works in Coq, be my guest. Cons: Axioms are dangerous, you have to show consistency externally

Classical logic holds in the well-known Set model, blah-blah...

Non-trivial interactions: e.g. classical CIC implies proof-irrelevance.

Classical logic is incompatible with univalence! (Your mileage may vary.)

The logic does not compute anymore, axioms block reduction...

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 5 / 33

slide-11
SLIDE 11

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Attempt 1: The Truth is Out There

There is a very simple straightforward solution.

Axiom classical : forall (A : Type), A ∨ ¬A.

Pro: Simple, local, works in Coq, be my guest. Cons: Axioms are dangerous, you have to show consistency externally

Classical logic holds in the well-known Set model, blah-blah...

Non-trivial interactions: e.g. classical CIC implies proof-irrelevance.

Classical logic is incompatible with univalence! (Your mileage may vary.)

The logic does not compute anymore, axioms block reduction...

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 5 / 33

slide-12
SLIDE 12

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Attempt 1: The Truth is Out There

There is a very simple straightforward solution.

Axiom classical : forall (A : Type), A ∨ ¬A.

Pro: Simple, local, works in Coq, be my guest. Cons: Axioms are dangerous, you have to show consistency externally

Classical logic holds in the well-known Set model, blah-blah...

Non-trivial interactions: e.g. classical CIC implies proof-irrelevance.

Classical logic is incompatible with univalence! (Your mileage may vary.)

The logic does not compute anymore, axioms block reduction...

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 5 / 33

slide-13
SLIDE 13

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Attempt 2: CIC and call/cc are in a boat

Since Griffjn, it’s folklore that control operators implement classical logic.

callcc : ((A → B) → A) → A

Essentially allows to reify context evaluation. E callcc M callcc k E M E k The type of callcc is Peirce’s law, the minimal logic equivalement of EM.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 6 / 33

slide-14
SLIDE 14

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Attempt 2: CIC and call/cc are in a boat

Since Griffjn, it’s folklore that control operators implement classical logic.

callcc : ((A → B) → A) → A

Essentially allows to reify context evaluation. E[callcc M] ≡β callcc (λk. E[M (E ◦ k)]) The type of callcc is Peirce’s law, the minimal logic equivalement of EM.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 6 / 33

slide-15
SLIDE 15

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Attempt 2: CIC and call/cc are in a boat “Just” throw call/cc into CIC!

Pro: Computational by construction. Cons: Needs a whole new proof assistant implementation.

Reminder: Coq is a 33-year old project.

Changes the global meaning of logical connectives.

What does x A B means?

... and it changes it so much that it also proves False!!!

Pro: At least my proofs are going to be easier.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 7 / 33

slide-16
SLIDE 16

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Attempt 2: CIC and call/cc are in a boat “Just” throw call/cc into CIC!

Pro: Computational by construction. Cons: Needs a whole new proof assistant implementation.

Reminder: Coq is a 33-year old project.

Changes the global meaning of logical connectives.

What does Σx : A. B means?

... and it changes it so much that it also proves False!!!

Pro: At least my proofs are going to be easier.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 7 / 33

slide-17
SLIDE 17

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Attempt 2: CIC and call/cc are in a boat “Just” throw call/cc into CIC!

Pro: Computational by construction. Cons: Needs a whole new proof assistant implementation.

Reminder: Coq is a 33-year old project.

Changes the global meaning of logical connectives.

What does Σx : A. B means?

... and it changes it so much that it also proves False!!!

Pro: At least my proofs are going to be easier.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 7 / 33

slide-18
SLIDE 18

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Attempt 2: CIC fell into the water!

Herbelin showed a paradox in CIC + callcc, boiling down to:

Dependent elimination + Proof-relevance + callcc = TROUBLE.

Essentially: callcc allows to build booleans that are neither true nor false b if em CIC_consistency then true else false Dependent elimination is oblivious of this fact P P true P false b P b Modern avatar of “Axiom of choice in classical logic is fjshy”.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 8 / 33

slide-19
SLIDE 19

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Attempt 2: CIC fell into the water!

Herbelin showed a paradox in CIC + callcc, boiling down to:

Dependent elimination + Proof-relevance + callcc = TROUBLE.

Essentially: callcc allows to build booleans that are neither true nor false b := if em CIC_consistency then true else false Dependent elimination is oblivious of this fact ΠP : B → □. P true → P false → Πb : B. P b Modern avatar of “Axiom of choice in classical logic is fjshy”.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 8 / 33

slide-20
SLIDE 20

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

BLATANT ADVERTISMENT

Come to see my LICS talk for a potential generic solution to CIC + efgects! Restrict dependent eliminations to semantically call-by-value predicates. Buzzword: linearity. (Little to do with syntactic linearity BTW.)

M N P true N P false P linear in b if M then N else N P b M

Works for CBN forcing Works for our new weaning translation Inspired by classical realizability Prevents Herbelin’s particular paradox Unluckily, a consistent model of callcc is still missing!

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 9 / 33

slide-21
SLIDE 21

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

BLATANT ADVERTISMENT

Come to see my LICS talk for a potential generic solution to CIC + efgects! Restrict dependent eliminations to semantically call-by-value predicates. Buzzword: linearity. (Little to do with syntactic linearity BTW.)

Γ ⊢ M : B Γ ⊢ N1 : P true Γ ⊢ N2 : P false P linear in b Γ ⊢ if M then N1 else N2 : P{b := M}

Works for CBN forcing Works for our new weaning translation Inspired by classical realizability Prevents Herbelin’s particular paradox Unluckily, a consistent model of callcc is still missing!

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 9 / 33

slide-22
SLIDE 22

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

BLATANT ADVERTISMENT

Come to see my LICS talk for a potential generic solution to CIC + efgects! Restrict dependent eliminations to semantically call-by-value predicates. Buzzword: linearity. (Little to do with syntactic linearity BTW.)

Γ ⊢ M : B Γ ⊢ N1 : P true Γ ⊢ N2 : P false P linear in b Γ ⊢ if M then N1 else N2 : P{b := M}

Works for CBN forcing Works for our new weaning translation Inspired by classical realizability Prevents Herbelin’s particular paradox Unluckily, a consistent model of callcc is still missing!

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 9 / 33

slide-23
SLIDE 23

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

In This Talk: Program Translations

Observations: Morale of Attempt 1: Axioms are both unwieldy and fjshy. Morale of Attempt 2: Arbitrary computational primitives are fjshier. OTOH, a well-known program translation implementing callcc.

Continuation-passing style!

We propose in this talk a much less grand solution than linearity.

The fjrst cheating CPS translation of CIC.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 10 / 33

slide-24
SLIDE 24

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

In This Talk: Program Translations

Observations: Morale of Attempt 1: Axioms are both unwieldy and fjshy. Morale of Attempt 2: Arbitrary computational primitives are fjshier. OTOH, a well-known program translation implementing callcc.

Continuation-passing style!

We propose in this talk a much less grand solution than linearity.

The fjrst cheating CPS translation of CIC.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 10 / 33

slide-25
SLIDE 25

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

In This Talk: Program Translations

Observations: Morale of Attempt 1: Axioms are both unwieldy and fjshy. Morale of Attempt 2: Arbitrary computational primitives are fjshier. OTOH, a well-known program translation implementing callcc.

Continuation-passing style!

We propose in this talk a much less grand solution than linearity.

The fjrst cheating CPS translation of CIC.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 10 / 33

slide-26
SLIDE 26

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Syntactic Models, a.k.a. Program Translations of CIC

Defjne [·] on the syntax and derive the type interpretation [ [·] ] from it s.t. ⊢CIC+ M : A implies ⊢CIC [M] : [ [A] ] Obviously, that’s subtle. The correctness of lies in the meta (Darn, Gödel!) The translation must preserve typing (Not easy) In particular, it must preserve conversion (Argh!) Yet, a lot of nice consequences. Does not require non-type-theoretical foundations (monism) Can be implemented in your favourite proof assistant Easy to show (relative) consistency, look at False Easier to understand computationally

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 11 / 33

slide-27
SLIDE 27

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Syntactic Models, a.k.a. Program Translations of CIC

Defjne [·] on the syntax and derive the type interpretation [ [·] ] from it s.t. ⊢CIC+ M : A implies ⊢CIC [M] : [ [A] ] Obviously, that’s subtle. The correctness of [·] lies in the meta (Darn, Gödel!) The translation must preserve typing (Not easy) In particular, it must preserve conversion (Argh!) Yet, a lot of nice consequences. Does not require non-type-theoretical foundations (monism) Can be implemented in your favourite proof assistant Easy to show (relative) consistency, look at False Easier to understand computationally

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 11 / 33

slide-28
SLIDE 28

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Syntactic Models, a.k.a. Program Translations of CIC

Defjne [·] on the syntax and derive the type interpretation [ [·] ] from it s.t. ⊢CIC+ M : A implies ⊢CIC [M] : [ [A] ] Obviously, that’s subtle. The correctness of [·] lies in the meta (Darn, Gödel!) The translation must preserve typing (Not easy) In particular, it must preserve conversion (Argh!) Yet, a lot of nice consequences. Does not require non-type-theoretical foundations (monism) Can be implemented in your favourite proof assistant Easy to show (relative) consistency, look at [ [False] ] Easier to understand computationally

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 11 / 33

slide-29
SLIDE 29

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Baby steps CIC is call-by-name by construction.

That’s because of the β-equivalence used in conversion. Γ ⊢ M : B A ≡β B Γ ⊢ M : A

We have to use a CBN CPS translation.

Let’s stick to a variant close to the hardware: Lafont-Streicher-Reus CPS.

(This is LOLA after all.)

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 12 / 33

slide-30
SLIDE 30

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Baby steps CIC is call-by-name by construction.

That’s because of the β-equivalence used in conversion. Γ ⊢ M : B A ≡β B Γ ⊢ M : A

We have to use a CBN CPS translation.

Let’s stick to a variant close to the hardware: Lafont-Streicher-Reus CPS.

(This is LOLA after all.)

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 12 / 33

slide-31
SLIDE 31

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Quick recap

In the simply-typed case, the LSR CPS is given as follows.

1 Fix some return type

.

2 Inductively defjne the type of stacks

A and witnesses A . A A A B A B

3 Defjne the term translation

  • n the syntax s.t.

M A M A

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 13 / 33

slide-32
SLIDE 32

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Quick recap

In the simply-typed case, the LSR CPS is given as follows.

1 Fix some return type ‚. 2 Inductively defjne the type of stacks

A and witnesses A . A A A B A B

3 Defjne the term translation

  • n the syntax s.t.

M A M A

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 13 / 33

slide-33
SLIDE 33

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Quick recap

In the simply-typed case, the LSR CPS is given as follows.

1 Fix some return type ‚. 2 Inductively defjne the type of stacks C(A) and witnesses W(A).

W(A) := C(A) → ‚ C(α) := α → ‚ C(A → B) := W(A) × C(B)

3 Defjne the term translation

  • n the syntax s.t.

M A M A

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 13 / 33

slide-34
SLIDE 34

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Quick recap

In the simply-typed case, the LSR CPS is given as follows.

1 Fix some return type ‚. 2 Inductively defjne the type of stacks C(A) and witnesses W(A).

W(A) := C(A) → ‚ C(α) := α → ‚ C(A → B) := W(A) × C(B)

3 Defjne the term translation [·] on the syntax s.t.

Γ ⊢ M : A ⇝ W(Γ) ⊢ [M] : W(A)

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 13 / 33

slide-35
SLIDE 35

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

This Is LOLA After All

Here is the implementation: [x] := x [λx. M] := λ(x, ω). [M] ω [M N] := λω. [M] (N, ω) Holy celestial teapot! It implements the Krivine machine! x M N M x N M N M N Plus there is a proof of: A B A A mimicking what the classical KAM does.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 14 / 33

slide-36
SLIDE 36

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

This Is LOLA After All

Here is the implementation: [x] := x [λx. M] := λ(x, ω). [M] ω [M N] := λω. [M] (N, ω) Holy celestial teapot! It implements the Krivine machine! ⟨λx. M | N · π⟩ → ⟨M{x := N} | π⟩ ⟨M N | π⟩ → ⟨M | N · π⟩ Plus there is a proof of: A B A A mimicking what the classical KAM does.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 14 / 33

slide-37
SLIDE 37

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

This Is LOLA After All

Here is the implementation: [x] := x [λx. M] := λ(x, ω). [M] ω [M N] := λω. [M] (N, ω) Holy celestial teapot! It implements the Krivine machine! ⟨λx. M | N · π⟩ → ⟨M{x := N} | π⟩ ⟨M N | π⟩ → ⟨M | N · π⟩ Plus there is a proof of: W(((A → B) → A) → A) mimicking what the classical KAM does.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 14 / 33

slide-38
SLIDE 38

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CICking it out

So far so good, we have a syntactic model for simply-typed λ-calculus. Sketchy roadmap of what we have to do to scale LSR to CIC:

1 Acknowledging dependent functions 2 Implementing types-as-terms 3 Implementing dependent elimination

Spoiler: Turns out 1. is trivial, 2. and 3. impossible as-is.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 15 / 33

slide-39
SLIDE 39

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CICking it out

So far so good, we have a syntactic model for simply-typed λ-calculus. Sketchy roadmap of what we have to do to scale LSR to CIC:

1 Acknowledging dependent functions 2 Implementing types-as-terms 3 Implementing dependent elimination

Spoiler: Turns out 1. is trivial, 2. and 3. impossible as-is.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 15 / 33

slide-40
SLIDE 40

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

LSR and dependency

Owing to the low-level nature of LSR, dependency is trivial. W(A) := C(A) → ‚ C(A → B) := W(A) × C(B) C(Πx : A. B) := Σx : W(A). C(B) Remark in particular that the arrow case is a degenerate variant. It means it is easy to give a LSR of λΠ s.t. Γ ⊢ M : A ⇝ W(Γ) ⊢ [M]W(A) Note: not as easy for other CBN CPS! So LSR is good for dependency.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 16 / 33

slide-41
SLIDE 41

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

LSR and dependency

Owing to the low-level nature of LSR, dependency is trivial. W(A) := C(A) → ‚ C(A → B) := W(A) × C(B) C(Πx : A. B) := Σx : W(A). C(B) Remark in particular that the arrow case is a degenerate variant. It means it is easy to give a LSR of λΠ s.t. Γ ⊢ M : A ⇝ W(Γ) ⊢ [M]W(A) Note: not as easy for other CBN CPS! So LSR is good for dependency.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 16 / 33

slide-42
SLIDE 42

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

LSR and inductive types

In LSR, inductive types are translated free algebras, e.g. C(B) := B → ‚ W(B) := (B → ‚) → ‚ Constructors are returns, elimination is continuation-passing.

[true] := λω. ω true [false] := λω. ω false [if M then N1 else N2] := λω. [M] (λb. if b then [N1] ω else [N2] ω)

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 17 / 33

slide-43
SLIDE 43

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

LSR and inductive types: a failure

Alas, no hope to implement dependent elimination! ΠP : B → □. P true → P false → Πb : B. P b ⇝ For a meta-theoretical reason: W(B) := (B → ‚) → ‚, so depending on the choice of ‚ there are non-standard booleans. ⇝ For a technical reason: In the typing of if, the type of a dependent ω would be wrong.

[if M then N1 else N2] := λω. [M] (λb. if b then [N1] ω else [N2] ω)

No way to recover an actual boolean from a classical boolean.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 18 / 33

slide-44
SLIDE 44

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

LSR and inductive types: a failure

Alas, no hope to implement dependent elimination! ΠP : B → □. P true → P false → Πb : B. P b ⇝ For a meta-theoretical reason: W(B) := (B → ‚) → ‚, so depending on the choice of ‚ there are non-standard booleans. ⇝ For a technical reason: In the typing of if, the type of a dependent ω would be wrong.

[if M then N1 else N2] := λω. [M] (λb. if b then [N1] ω else [N2] ω)

No way to recover an actual boolean from a classical boolean.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 18 / 33

slide-45
SLIDE 45

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

LSR and universes: failure again

Because ⊢CIC □i : □i+1, we must defjne C(□i). Universes are somehow free algebras, so take C(□i) := □i → ‚. In particular, W(□i) := (□i → ‚) → ‚. Now, how to implement the meta-function El , needed for A

i

A

i

Actually, you can’t. Just as for booleans, double-negation lost information. No way to recover an actual type from a classical type either.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 19 / 33

slide-46
SLIDE 46

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

LSR and universes: failure again

Because ⊢CIC □i : □i+1, we must defjne C(□i). Universes are somehow free algebras, so take C(□i) := □i → ‚. In particular, W(□i) := (□i → ‚) → ‚. Now, how to implement the meta-function El : W(□) ⇝ □, needed for Γ ⊢ A : □i ⊢ Γ, A : □i Actually, you can’t. Just as for booleans, double-negation lost information. No way to recover an actual type from a classical type either.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 19 / 33

slide-47
SLIDE 47

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Dire Situation

TL; DR: LSR handles negative connectives but not positive ones. Not totally unexpected from a CPS translation... How to solve this? It looks inherent to the CPS.

Let’s cheat!

. Let’s make the CPS intuitionistic again by using..

Parametricity.

Or equivalently, let’s do a bit of...

Intuitionistic realizability.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 20 / 33

slide-48
SLIDE 48

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Dire Situation

TL; DR: LSR handles negative connectives but not positive ones. Not totally unexpected from a CPS translation... How to solve this? It looks inherent to the CPS.

Let’s cheat!

. Let’s make the CPS intuitionistic again by using..

Parametricity.

Or equivalently, let’s do a bit of...

Intuitionistic realizability.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 20 / 33

slide-49
SLIDE 49

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Dire Situation

TL; DR: LSR handles negative connectives but not positive ones. Not totally unexpected from a CPS translation... How to solve this? It looks inherent to the CPS.

Let’s cheat!

. Let’s make the CPS intuitionistic again by using..

Parametricity.

Or equivalently, let’s do a bit of...

Intuitionistic realizability.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 20 / 33

slide-50
SLIDE 50

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Grand Scheme

We lost information in the CPS, let’s add it back as a side-condition. Idea: instead of translating M A M A let’s rather do M A M A where A x A x A and M M M We will retrieve the information in A rather than in A ! M A is the parametricity (resp. realizability) relation of A.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 21 / 33

slide-51
SLIDE 51

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Grand Scheme

We lost information in the CPS, let’s add it back as a side-condition. Idea: instead of translating Γ ⊢ M : A ⇝ W(Γ) ⊢ [M] : W(A) let’s rather do Γ ⊢ M : A ⇝ [ [Γ] ] ⊢ [M]! : [ [A] ] where [ [A] ] := Σx : W(A). x ∈ A and [M]! := ([M], [M]ε) We will retrieve the information in A rather than in A ! M A is the parametricity (resp. realizability) relation of A.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 21 / 33

slide-52
SLIDE 52

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Grand Scheme

We lost information in the CPS, let’s add it back as a side-condition. Idea: instead of translating Γ ⊢ M : A ⇝ W(Γ) ⊢ [M] : W(A) let’s rather do Γ ⊢ M : A ⇝ [ [Γ] ] ⊢ [M]! : [ [A] ] where [ [A] ] := Σx : W(A). x ∈ A and [M]! := ([M], [M]ε) We will retrieve the information in · ∈ A rather than in W(A)! M ∈ A is the parametricity (resp. realizability) relation of A.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 21 / 33

slide-53
SLIDE 53

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Grand Scheme II

Morally, our translation is Intuitionistic Realizability (Kleene-style?) ... where realizers are Lafont-Streicher-Reus CPS-ifjed terms ... and where the realizability relation is internal to CIC A fancy mix... Is that a known technique? Has it a use per se? Can it be used for type-preserving compilation?

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 22 / 33

slide-54
SLIDE 54

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Grand Scheme II

Morally, our translation is Intuitionistic Realizability (Kleene-style?) ... where realizers are Lafont-Streicher-Reus CPS-ifjed terms ... and where the realizability relation is internal to CIC A fancy mix... Is that a known technique? Has it a use per se? Can it be used for type-preserving compilation?

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 22 / 33

slide-55
SLIDE 55

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Bit of Detail

Compared from the simply-typed case, [·] is unchanged. I will not give [·]ε here, but it is straightforward. More or less a projection. We defjne the realizability condition as follows: A A M A A x A B x A B x A M x B b M ret b X M ret X M Technically, A , A and M A are macros derived from A .

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 23 / 33

slide-56
SLIDE 56

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Bit of Detail

Compared from the simply-typed case, [·] is unchanged. I will not give [·]ε here, but it is straightforward. More or less a projection. We defjne the realizability condition as follows: A C(A) (M : C(A) → ‚) ∈ A Πx : A. B Σx : [ [A] ]. C(B) Πx : [ [A] ]. (λω. M (x, ω)) ∈ B b M ret b X M ret X M Technically, A , A and M A are macros derived from A .

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 23 / 33

slide-57
SLIDE 57

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Bit of Detail

Compared from the simply-typed case, [·] is unchanged. I will not give [·]ε here, but it is straightforward. More or less a projection. We defjne the realizability condition as follows: A C(A) (M : C(A) → ‚) ∈ A Πx : A. B Σx : [ [A] ]. C(B) Πx : [ [A] ]. (λω. M (x, ω)) ∈ B B B → ‚ Σb : B.M = ret b X M ret X M Technically, A , A and M A are macros derived from A .

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 23 / 33

slide-58
SLIDE 58

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Bit of Detail

Compared from the simply-typed case, [·] is unchanged. I will not give [·]ε here, but it is straightforward. More or less a projection. We defjne the realizability condition as follows: A C(A) (M : C(A) → ‚) ∈ A Πx : A. B Σx : [ [A] ]. C(B) Πx : [ [A] ]. (λω. M (x, ω)) ∈ B B B → ‚ Σb : B.M = ret b □ □ → ‚ ΣX : □. (M = ret X) × ((M → ‚) → □) Technically, A , A and M A are macros derived from A .

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 23 / 33

slide-59
SLIDE 59

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Bit of Detail

Compared from the simply-typed case, [·] is unchanged. I will not give [·]ε here, but it is straightforward. More or less a projection. We defjne the realizability condition as follows: A C(A) (M : C(A) → ‚) ∈ A Πx : A. B Σx : [ [A] ]. C(B) Πx : [ [A] ]. (λω. M (x, ω)) ∈ B B B → ‚ Σb : B.M = ret b □ □ → ‚ ΣX : □. (M = ret X) × ((M → ‚) → □) Technically, [ [A] ], C(A) and M ∈ A are macros derived from [A]ε.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 23 / 33

slide-60
SLIDE 60

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Few Isomorphims

This translation is very intuitionistic, as it is somehow the identity. Assuming ‚ is hProp: [ [Π(x : A). B] ] ∼ = Π(x : [ [A] ]). [ [B] ] [ [B] ] ∼ = B [ [empty] ] ∼ = empty In particular, it preserves consistency! The only difgerence (due to parametricity):

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 24 / 33

slide-61
SLIDE 61

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Few Isomorphims

This translation is very intuitionistic, as it is somehow the identity. Assuming ‚ is hProp: [ [Π(x : A). B] ] ∼ = Π(x : [ [A] ]). [ [B] ] [ [B] ] ∼ = B [ [empty] ] ∼ = empty In particular, it preserves consistency! The only difgerence (due to parametricity): [ [□] ] ̸∼ = □

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 24 / 33

slide-62
SLIDE 62

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Soundness

Interestingly, this translation can be carried in CIC. If Γ ⊢CIC M : A then [ [Γ] ] ⊢CIC [M]! : [ [A] ] So it is possible to provide this translation as Coq plugin! For now only a hand-written shallow embedding. https://github.com/CoqHott/coq-effects/blob/master/ theories/misc/CPS.v

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 25 / 33

slide-63
SLIDE 63

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Soundness

Interestingly, this translation can be carried in CIC. If Γ ⊢CIC M : A then [ [Γ] ] ⊢CIC [M]! : [ [A] ] So it is possible to provide this translation as Coq plugin! For now only a hand-written shallow embedding. https://github.com/CoqHott/coq-effects/blob/master/ theories/misc/CPS.v

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 25 / 33

slide-64
SLIDE 64

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Conservativity?

What did we gain? Not a lot of things... The resulting theory is almost a conservative extension of CIC For instance you can’t implement callcc in general It is not for sordid reasons related to types (namely ) ... in particular it negates univalence! That said, we have new statements in our theory.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 26 / 33

slide-65
SLIDE 65

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Conservativity?

What did we gain? Not a lot of things... The resulting theory is almost a conservative extension of CIC For instance you can’t implement callcc in general It is not for sordid reasons related to types (namely [ [□] ] ̸∼ = □) ... in particular it negates univalence! That said, we have new statements in our theory.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 26 / 33

slide-66
SLIDE 66

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Conservativity?

What did we gain? Not a lot of things... The resulting theory is almost a conservative extension of CIC For instance you can’t implement callcc in general It is not for sordid reasons related to types (namely [ [□] ] ̸∼ = □) ... in particular it negates univalence! That said, we have new statements in our theory.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 26 / 33

slide-67
SLIDE 67

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Sprinkling Classical Logic

Because we carry classical realizers, we can actually fall back to LSR! Behold the classical modality ! A A M A unit The modality just drops the parametric proof of the underlying type. A x A unit A As such, it allows to work with the raw LSR translation.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 27 / 33

slide-68
SLIDE 68

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Sprinkling Classical Logic

Because we carry classical realizers, we can actually fall back to LSR! Behold the classical modality ⟨·⟩! C(⟨A⟩) := C(A) M ∈ ⟨A⟩ := unit The modality just drops the parametric proof of the underlying type. A x A unit A As such, it allows to work with the raw LSR translation.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 27 / 33

slide-69
SLIDE 69

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Sprinkling Classical Logic

Because we carry classical realizers, we can actually fall back to LSR! Behold the classical modality ⟨·⟩! C(⟨A⟩) := C(A) M ∈ ⟨A⟩ := unit The modality just drops the parametric proof of the underlying type. [ [⟨A⟩] ] := Σx : W(A). unit ∼ = W(A) As such, it allows to work with the raw LSR translation.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 27 / 33

slide-70
SLIDE 70

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Moar Principles

This type constructor admits a lot of reasoning principles. It has a return: η : Π(A : □). A → ⟨A⟩ It has (a weak form of) choice: Π(x : A). ⟨B⟩ ∼ = ⟨Π(x : A). B⟩ It has a form of classical reasoning: cc : Π(A B : □). ((A → ⟨B⟩) → ⟨A⟩) → ⟨A⟩ It is not functorial. A → B ̸⊢ ⟨A⟩ → ⟨B⟩ In particular, it is not the double negation modality.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 28 / 33

slide-71
SLIDE 71

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Give Me My Propositional Logic Back

Piggy-backing on LSR, we get an embedding of propositional logic. If ⊢LJ A then ⊢CIC+ ⟨A⟩. Furthermore, the propositional logic combinators compute. E.g. if A A A if true N N N This is all because the LSR CPS is well-behaved w.r.t.

  • reduction.

Obviously no dependent elimination in sight. (Because LSR.)

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 29 / 33

slide-72
SLIDE 72

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Give Me My Propositional Logic Back

Piggy-backing on LSR, we get an embedding of propositional logic. If ⊢LJ A then ⊢CIC+ ⟨A⟩. Furthermore, the propositional logic combinators compute. E.g. if⟨·⟩ : ⟨B⟩ → ⟨A⟩ → ⟨A⟩ → ⟨A⟩ if⟨·⟩ (η B true) N1 N2 ≡β N1 This is all because the LSR CPS is well-behaved w.r.t. β-reduction. Obviously no dependent elimination in sight. (Because LSR.)

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 29 / 33

slide-73
SLIDE 73

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Even More

For particular values of ‚, we get more. Typically, for ‚ := empty. The modality is consistent. ⟨empty⟩ → empty The modality has excluded middle. em : Π(A : □). ⟨A + ¬A⟩

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 30 / 33

slide-74
SLIDE 74

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Use cases?

What can we do with this modality? Not clear. When empty, we can escape from it into falsity. Allows to fake the existence of classical logic in a systematic way.

The Coq user should be happy!

When is some other type, one can use it as delimited continuations.

What can we do with that?

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 31 / 33

slide-75
SLIDE 75

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Use cases?

What can we do with this modality? Not clear. When ‚ := empty, we can escape from it into falsity. Allows to fake the existence of classical logic in a systematic way.

The Coq user should be happy!

When is some other type, one can use it as delimited continuations.

What can we do with that?

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 31 / 33

slide-76
SLIDE 76

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Use cases?

What can we do with this modality? Not clear. When ‚ := empty, we can escape from it into falsity. Allows to fake the existence of classical logic in a systematic way.

The Coq user should be happy!

When ‚ is some other type, one can use it as delimited continuations.

What can we do with that?

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 31 / 33

slide-77
SLIDE 77

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Use cases?

What can we do with this modality? Not clear. When ‚ := empty, we can escape from it into falsity. Allows to fake the existence of classical logic in a systematic way.

The Coq user should be happy!

When ‚ is some other type, one can use it as delimited continuations.

What can we do with that?

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 31 / 33

slide-78
SLIDE 78

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Conclusion

The fjrst typed CPS of CIC! Although we cheat badly. An intricate mix of techniques. Implementable in Coq. A modality introducing classical logic. Preserving the propositional fragment, not dependent elimination.

Again, what can we do with that?

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 32 / 33

slide-79
SLIDE 79

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Conclusion

The fjrst typed CPS of CIC! Although we cheat badly. An intricate mix of techniques. Implementable in Coq. A modality introducing classical logic. Preserving the propositional fragment, not dependent elimination.

Again, what can we do with that?

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 32 / 33

slide-80
SLIDE 80

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Conclusion

The fjrst typed CPS of CIC! Although we cheat badly. An intricate mix of techniques. Implementable in Coq. A modality ⟨·⟩ introducing classical logic. Preserving the propositional fragment, not dependent elimination.

Again, what can we do with that?

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 32 / 33

slide-81
SLIDE 81

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Scribitur ad narrandum, non ad probandum

Thanks for your attention.

Pédrot (U. Ljubljana) A Parametric CPS 19/06/2017 33 / 33