Realizability and parametricity in pure type systems Jean-Philippe - - PowerPoint PPT Presentation

realizability and parametricity in pure type systems
SMART_READER_LITE
LIVE PREVIEW

Realizability and parametricity in pure type systems Jean-Philippe - - PowerPoint PPT Presentation

Realizability and parametricity in pure type systems Jean-Philippe Bernardy Chalmers university Marc Lasson Ecole Normale Sup erieure de Lyon February 15, 2011 1 / 41 Realizability and parametricity in pure type systems Marc


slide-1
SLIDE 1

Realizability and parametricity in pure type systems

Jean-Philippe Bernardy – Chalmers university Marc Lasson – ´ Ecole Normale Sup´ erieure de Lyon February 15, 2011

1 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-2
SLIDE 2

Parametric polymorphism

let rec f = function | [] -> 1 | hd::tl -> 2 * (f tl) val f : ∀α, α list → int Parametricity polymorphism: parametric types behave uniformly

  • ver abstracted types.

If ⊢F f : ∀α, αlist → int and |l| = |l′| then f l = f l′.

2 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-3
SLIDE 3

Parametricity relations

Tool introduced by Reynolds to study polymorphism.

3 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-4
SLIDE 4

Parametricity relations

Tool introduced by Reynolds to study polymorphism.

In System F

We define a relation s ∼τ t by induction on τ t1 ∼σ→τ t2 ≡ ∀x1 x2.x1 ∼σ x2 → (t1 x1) ∼τ (t2 x2) t1 ∼α t2 ≡ Rα t1 t2 t1 ∼∀α,τ t2 ≡ ∀Rα.t1 ∼τ t2 Two related functions map related inputs to related outputs.

3 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-5
SLIDE 5

Parametricity relations

Tool introduced by Reynolds to study polymorphism.

In System F

We define a relation s ∼τ t by induction on τ t1 ∼σ→τ t2 ≡ ∀x1 x2.x1 ∼σ x2 → (t1 x1) ∼τ (t2 x2) t1 ∼α t2 ≡ Rα t1 t2 t1 ∼∀α,τ t2 ≡ ∀Rα.t1 ∼τ t2 Two related functions map related inputs to related outputs.

Abstraction theorem

If ⊢ t : τ then we can prove that t ∼τ t.

3 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-6
SLIDE 6

Example

∀α.α → α

f ∼∀α.α→α g ≡ ∀R.∀xy.xRy → (f x)R(g y)

4 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-7
SLIDE 7

Example

∀α.α → α

f ∼∀α.α→α g ≡ ∀R.∀xy.xRy → (f x)R(g y)

∀αβ.α → β → α

f ∼∀αβ.α→β→α g ≡ ∀R1R2.∀x1y1.x1R1y1 → ∀x2y2.x2R2y2 → (f x1 x2)R1(g y1 y2)

4 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-8
SLIDE 8

Parametricity – Abstraction theorem

Abstraction theorem

If ⊢ t : τ then we can prove that t ∼τ t. Application : Theorems for free!

Let t be such that ⊢ t : ∀α.α → α

5 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-9
SLIDE 9

Parametricity – Abstraction theorem

Abstraction theorem

If ⊢ t : τ then we can prove that t ∼τ t. Application : Theorems for free!

Let t be such that ⊢ t : ∀α.α → α By the abstraction theorem, you obtain t ∼∀α.α→α t

5 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-10
SLIDE 10

Parametricity – Abstraction theorem

Abstraction theorem

If ⊢ t : τ then we can prove that t ∼τ t. Application : Theorems for free!

Let t be such that ⊢ t : ∀α.α → α By the abstraction theorem, you obtain t ∼∀α.α→α t By unfolding the definition of ∼∀α.α→α, ∀ Rα,β x : α y : β.xRy → (tα x)R(tβ y)

5 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-11
SLIDE 11

Parametricity – Abstraction theorem

Abstraction theorem

If ⊢ t : τ then we can prove that t ∼τ t. Application : Theorems for free!

Let t be such that ⊢ t : ∀α.α → α By the abstraction theorem, you obtain t ∼∀α.α→α t By unfolding the definition of ∼∀α.α→α, ∀ Rα,β x : α y : β.xRy → (tα x)R(tβ y) For all g : α → β, if you take to be R x y ⇔ (g x) = y, you have ∀g : α → β.∀x : α.g (tα x) = tβ (g x)

5 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-12
SLIDE 12

Parametricity – Abstraction theorem

Abstraction theorem

If ⊢ t : τ then we can prove that t ∼τ t. Application : Theorems for free!

Let t be such that ⊢ t : ∀α.α → α By the abstraction theorem, you obtain t ∼∀α.α→α t By unfolding the definition of ∼∀α.α→α, ∀ Rα,β x : α y : β.xRy → (tα x)R(tβ y) For all g : α → β, if you take to be R x y ⇔ (g x) = y, you have ∀g : α → β.∀x : α.g (tα x) = tβ (g x) By extensionality, it’s equivalent to ∀g : α → β.g ◦ tα = tβ ◦ g

5 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-13
SLIDE 13

Parametricity – Abstraction theorem

Abstraction theorem

If ⊢ t : τ then we can prove that t ∼τ t. Application : Theorems for free!

Let t be such that ⊢ t : ∀α.α → α By the abstraction theorem, you obtain t ∼∀α.α→α t By unfolding the definition of ∼∀α.α→α, ∀ Rα,β x : α y : β.xRy → (tα x)R(tβ y) For all g : α → β, if you take to be R x y ⇔ (g x) = y, you have ∀g : α → β.∀x : α.g (tα x) = tβ (g x) By extensionality, it’s equivalent to ∀g : α → β.g ◦ tα = tβ ◦ g Which is equivalent to the fact that t is the identity function

5 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-14
SLIDE 14

Realizability

Slogan

Specifying programs with formulas

  • r

giving computational content to formula.

6 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-15
SLIDE 15

Realizability

Slogan

Specifying programs with formulas

  • r

giving computational content to formula. We define “p realizes a formula F” (p F) by induction on F.

Key case of the definition

t P → Q ≡ ∀x.x P → (t x) Q

6 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-16
SLIDE 16

Realizability

Slogan

Specifying programs with formulas

  • r

giving computational content to formula. We define “p realizes a formula F” (p F) by induction on F.

Key case of the definition

t P → Q ≡ ∀x.x P → (t x) Q

Adequacy theorem

If there exists a proof π of P, then there exists a program pπ and a proof π′ of pπ P.

6 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-17
SLIDE 17

Realizability – Applications

Proving that axioms (e.g. excluded middle) are not derivable

7 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-18
SLIDE 18

Realizability – Applications

Proving that axioms (e.g. excluded middle) are not derivable Studying programs extracted from proofs:

7 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-19
SLIDE 19

Realizability – Applications

Proving that axioms (e.g. excluded middle) are not derivable Studying programs extracted from proofs:

Existence property

If ∀x∃y, ϕ(x, y) is a theorem, then there exists a program f such that ∀x, ϕ(x, f (x)).

7 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-20
SLIDE 20

Realizability – Applications

Proving that axioms (e.g. excluded middle) are not derivable Studying programs extracted from proofs:

Existence property

If ∀x∃y, ϕ(x, y) is a theorem, then there exists a program f such that ∀x, ϕ(x, f (x)).

Representation theorem

Functions definable in system F are exactly those provably total in second-order arithmetic.

7 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-21
SLIDE 21

Pure type systems – Generalities

A family of λ-calculi where types and terms are unified Provide a framework for studying dependent types Contains many famous type-systems:

simply typed λ-calculus, Girard and Reynolds polymorphic λ-calculus (system F), Huet-Coquand’s Calculus Of Constructions ...

It even contains inconsistent calculus (Type : Type) A PTS P is defined by a specification (S, A, R) where

S is a set of sorts, A ⊆ S × S a set of axioms, R ⊆ S × S × S a set of rules.

Typing judgement Γ ⊢P A : B of the PTS P = (S, A, R).

8 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-22
SLIDE 22

Pure type systems – Terms and typing rules

Terms

A, B := s | x | (A B) | λx : A.B | ∀x : A.B

(with s ∈ S)

9 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-23
SLIDE 23

Pure type systems – Terms and typing rules

Terms

A, B := s | x | (A B) | λx : A.B | ∀x : A.B

(with s ∈ S)

A → B is a notation for ∀x : A.B with x ∈ B

9 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-24
SLIDE 24

Pure type systems – Terms and typing rules

Terms

A, B := s | x | (A B) | λx : A.B | ∀x : A.B

(with s ∈ S)

A → B is a notation for ∀x : A.B with x ∈ B Axiom

(s1, s2) ∈ A

⊢ s1 : s2 Γ, x : A ⊢ C : B Γ ⊢ (∀x : A.B) : s Abstraction Γ ⊢ (λx : A.C) : (∀x : A.B) Γ ⊢ A : s1 Γ, x : A ⊢ B : s2 Product

(s1, s2, s3) ∈ R

Γ ⊢ (∀x : A.B) : s3

9 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-25
SLIDE 25

Pure type systems – Terms and typing rules

Terms

A, B := s | x | (A B) | λx : A.B | ∀x : A.B

(with s ∈ S)

A → B is a notation for ∀x : A.B with x ∈ B Axiom

(s1, s2) ∈ A

⊢ s1 : s2 Γ, x : A ⊢ C : B Γ ⊢ (∀x : A.B) : s Abstraction Γ ⊢ (λx : A.C) : (∀x : A.B) Γ ⊢ A : s1 Γ, x : A ⊢ B : s2 Product

(s1, s2, s3) ∈ R

Γ ⊢ (∀x : A.B) : s3 + Application + Start + Weakening

9 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-26
SLIDE 26

System F

System F

The PTS F has the following specification SF = {⋆, } AF = {(⋆, )} RF = {(⋆, ⋆, ⋆), (, ⋆, ⋆)}

10 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-27
SLIDE 27

System F

System F

The PTS F has the following specification SF = {⋆, } AF = {(⋆, )} RF = {(⋆, ⋆, ⋆), (, ⋆, ⋆)} Only two kinds of product : Arrow type (σ → τ) : (⋆, ⋆, ⋆) Type quantification (∀α, τ): (, ⋆, ⋆) Γ ⊢ t : τ : ⋆

10 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-28
SLIDE 28

System F

System F

The PTS F has the following specification SF = {⋆, } AF = {(⋆, )} RF = {(⋆, ⋆, ⋆), (, ⋆, ⋆)} Only two kinds of product : Arrow type (σ → τ) : (⋆, ⋆, ⋆) Type quantification (∀α, τ): (, ⋆, ⋆) Γ ⊢ t : τ : ⋆ Γ ⊢ σ : ⋆ Γ, x : σ ⊢ τ : ⋆ (⋆, ⋆, ⋆) ∈ RF Γ ⊢ ∀x : σ.τ : ⋆ We can prove that Γ ⊢ τ : ⋆ and Γ ⊢ x : σ : ⋆ then x ∈ τ. Therefore ∀x : σ.τ can always be written σ → τ.

10 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-29
SLIDE 29

System F

System F

The PTS F has the following specification SF = {⋆, } AF = {(⋆, )} RF = {(⋆, ⋆, ⋆), (, ⋆, ⋆)} Only two kinds of product : Arrow type (σ → τ) : (⋆, ⋆, ⋆) Type quantification (∀α, τ): (, ⋆, ⋆) Γ ⊢ t : τ : ⋆ Γ ⊢ σ : ⋆ Γ ⊢ τ : ⋆ (⋆, ⋆, ⋆) ∈ RF Γ ⊢ σ → τ : ⋆ We can prove that Γ ⊢ τ : ⋆ and Γ ⊢ x : σ : ⋆ then x ∈ τ. Therefore ∀x : σ.τ can always be written σ → τ.

10 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-30
SLIDE 30

System F

System F

The PTS F has the following specification SF = {⋆, } AF = {(⋆, )} RF = {(⋆, ⋆, ⋆), (, ⋆, ⋆)} Only two kinds of product : Arrow type (σ → τ) : (⋆, ⋆, ⋆) Type quantification (∀α, τ): (, ⋆, ⋆) Γ ⊢ t : τ : ⋆ Γ ⊢ σ : ⋆ Γ ⊢ τ : ⋆ (⋆, ⋆, ⋆) ∈ RF Γ ⊢ σ → τ : ⋆ We can prove that Γ ⊢ τ : ⋆ and Γ ⊢ x : σ : ⋆ then x ∈ τ. Therefore ∀x : σ.τ can always be written σ → τ. We can also prove that inhabitants of ⋆ are either : α, σ → τ or ∀α : ⋆.τ.

10 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-31
SLIDE 31

System F – Examples

Example

Nat ≡ ∀α : ⋆.(α → α) → (α → α) 0 ≡ λ(α : ⋆)(f : α → α)(x : α).x Succ ≡ λ(n : Nat)(α : ⋆)(f : α → α)(x : α).f (n α f x)

11 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-32
SLIDE 32

System F – Examples

Example

Nat ≡ ∀α : ⋆.(α → α) → (α → α) 0 ≡ λ(α : ⋆)(f : α → α)(x : α).x Succ ≡ λ(n : Nat)(α : ⋆)(f : α → α)(x : α).f (n α f x) ⊢ Nat : ⋆

11 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-33
SLIDE 33

System F – Examples

Example

Nat ≡ ∀α : ⋆.(α → α) → (α → α) 0 ≡ λ(α : ⋆)(f : α → α)(x : α).x Succ ≡ λ(n : Nat)(α : ⋆)(f : α → α)(x : α).f (n α f x) ⊢ Nat : ⋆ ⊢ 0 : Nat

11 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-34
SLIDE 34

System F – Examples

Example

Nat ≡ ∀α : ⋆.(α → α) → (α → α) 0 ≡ λ(α : ⋆)(f : α → α)(x : α).x Succ ≡ λ(n : Nat)(α : ⋆)(f : α → α)(x : α).f (n α f x) ⊢ Nat : ⋆ ⊢ 0 : Nat ⊢ Succ : Nat → Nat

11 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-35
SLIDE 35

1

Introduction

2

Building the logic

3

Parametricity and realizability in PTS’s

4

An application and an extension

12 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-36
SLIDE 36

From P to P2 – From realizers to logic

13 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-37
SLIDE 37

From P to P2 – From realizers to logic

13 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-38
SLIDE 38

From P to P2 – Definitions

Given a PTS P = (S, A, R), we define P2 = (S2, A2, R2) by S2 = S ∪ { ⌈s⌉ | s ∈ S} A2 = A ∪ { (⌈s1⌉, ⌈s2⌉) | (s1, s2) ∈ A} R2 = R ∪ { (⌈s1⌉, ⌈s2⌉, ⌈s3⌉) , (s1,⌈s3⌉,⌈s3⌉) | (s1, s2, s3) ∈ R} ∪ { (s1, ⌈s2⌉,⌈s2⌉) | (s1, s2) ∈ A}

14 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-39
SLIDE 39

From P to P2 – Definitions

Given a PTS P = (S, A, R), we define P2 = (S2, A2, R2) by S2 = S ∪ { ⌈s⌉ | s ∈ S} A2 = A ∪ { (⌈s1⌉, ⌈s2⌉) | (s1, s2) ∈ A} R2 = R ∪ { (⌈s1⌉, ⌈s2⌉, ⌈s3⌉) , (s1,⌈s3⌉,⌈s3⌉) | (s1, s2, s3) ∈ R} ∪ { (s1, ⌈s2⌉,⌈s2⌉) | (s1, s2) ∈ A} For each sort s we add a copy ⌈s⌉, For each axiom (s1, s2) we add the axiom (⌈s1⌉, ⌈s2⌉). Beside the original rules, we allow three new quantifications :

1

We lift constructs of realizer at the level of the logic,

14 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-40
SLIDE 40

From P to P2 – Definitions

Given a PTS P = (S, A, R), we define P2 = (S2, A2, R2) by S2 = S ∪ { ⌈s⌉ | s ∈ S} A2 = A ∪ { (⌈s1⌉, ⌈s2⌉) | (s1, s2) ∈ A} R2 = R ∪ { (⌈s1⌉, ⌈s2⌉, ⌈s3⌉) , (s1,⌈s3⌉,⌈s3⌉) | (s1, s2, s3) ∈ R} ∪ { (s1, ⌈s2⌉,⌈s2⌉) | (s1, s2) ∈ A} For each sort s we add a copy ⌈s⌉, For each axiom (s1, s2) we add the axiom (⌈s1⌉, ⌈s2⌉). Beside the original rules, we allow three new quantifications :

1

We lift constructs of realizer at the level of the logic,

2

We allow quantification over programs,

14 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-41
SLIDE 41

From P to P2 – Definitions

Given a PTS P = (S, A, R), we define P2 = (S2, A2, R2) by S2 = S ∪ { ⌈s⌉ | s ∈ S} A2 = A ∪ { (⌈s1⌉, ⌈s2⌉) | (s1, s2) ∈ A} R2 = R ∪ { (⌈s1⌉, ⌈s2⌉, ⌈s3⌉) , (s1,⌈s3⌉,⌈s3⌉) | (s1, s2, s3) ∈ R} ∪ { (s1, ⌈s2⌉,⌈s2⌉) | (s1, s2) ∈ A} For each sort s we add a copy ⌈s⌉, For each axiom (s1, s2) we add the axiom (⌈s1⌉, ⌈s2⌉). Beside the original rules, we allow three new quantifications :

1

We lift constructs of realizer at the level of the logic,

2

We allow quantification over programs,

3

We allow the formation of predicates.

14 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-42
SLIDE 42

A bit of vocabulary

a type inhabits an original sort s Γ ⊢ A : s a formula inhabits a lifted sort ⌈s⌉ Γ ⊢ A : ⌈s⌉ a program inhabits a type Γ ⊢ A : B : s a proof inhabits a formula Γ ⊢ A : B : ⌈s⌉ types & programs are first-level terms formulas & proofs are second-level terms

15 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-43
SLIDE 43

Second-order logic F 2

The PTS F 2 has the following specification: S2

F

= { ⋆, , ⌈⋆⌉, ⌈⌉ } A2

F

= { (⋆, ), (⌈⋆⌉, ⌈⌉) } R2

F

= { (⋆, ⋆, ⋆), (, ⋆, ⋆), (⌈⋆⌉, ⌈⋆⌉, ⌈⋆⌉), (⌈⌉, ⌈⋆⌉, ⌈⋆⌉) (⋆, ⌈⌉, ⌈⌉), (⋆, ⌈⋆⌉, ⌈⋆⌉), (, ⌈⋆⌉, ⌈⋆⌉) }. The logic F 2 is a second-order logic with higher-order typed individuals (FA2 with higher-order individuals).

16 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-44
SLIDE 44

Second-order logic F 2

The PTS F 2 has the following specification: S2

F

= { ⋆, , ⌈⋆⌉, ⌈⌉ } A2

F

= { (⋆, ), (⌈⋆⌉, ⌈⌉) } R2

F

= { (⋆, ⋆, ⋆), (, ⋆, ⋆), (⌈⋆⌉, ⌈⋆⌉, ⌈⋆⌉), (⌈⌉, ⌈⋆⌉, ⌈⋆⌉) (⋆, ⌈⌉, ⌈⌉), (⋆, ⌈⋆⌉, ⌈⋆⌉), (, ⌈⋆⌉, ⌈⋆⌉) }. The logic F 2 is a second-order logic with higher-order typed individuals (FA2 with higher-order individuals). ⌈⋆⌉ is the sort of formulas (like Prop in Coq).

16 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-45
SLIDE 45

Second-order logic F 2

The PTS F 2 has the following specification: S2

F

= { ⋆, , ⌈⋆⌉, ⌈⌉ } A2

F

= { (⋆, ), (⌈⋆⌉, ⌈⌉) } R2

F

= { (⋆, ⋆, ⋆), (, ⋆, ⋆), (⌈⋆⌉, ⌈⋆⌉, ⌈⋆⌉), (⌈⌉, ⌈⋆⌉, ⌈⋆⌉) (⋆, ⌈⌉, ⌈⌉), (⋆, ⌈⋆⌉, ⌈⋆⌉), (, ⌈⋆⌉, ⌈⋆⌉) }. The logic F 2 is a second-order logic with higher-order typed individuals (FA2 with higher-order individuals). ⌈⋆⌉ is the sort of formulas (like Prop in Coq). (⌈⋆⌉, ⌈⋆⌉, ⌈⋆⌉) allows to build implication P → Q.

16 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-46
SLIDE 46

Second-order logic F 2

The PTS F 2 has the following specification: S2

F

= { ⋆, , ⌈⋆⌉, ⌈⌉ } A2

F

= { (⋆, ), (⌈⋆⌉, ⌈⌉) } R2

F

= { (⋆, ⋆, ⋆), (, ⋆, ⋆), (⌈⋆⌉, ⌈⋆⌉, ⌈⋆⌉), (⌈⌉, ⌈⋆⌉, ⌈⋆⌉) (⋆, ⌈⌉, ⌈⌉), (⋆, ⌈⋆⌉, ⌈⋆⌉), (, ⌈⋆⌉, ⌈⋆⌉) }. The logic F 2 is a second-order logic with higher-order typed individuals (FA2 with higher-order individuals). ⌈⋆⌉ is the sort of formulas (like Prop in Coq). (⌈⋆⌉, ⌈⋆⌉, ⌈⋆⌉) allows to build implication P → Q. (⋆, ⌈⋆⌉, ⌈⋆⌉) allows to quantify over programs ∀x : τ.P.

16 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-47
SLIDE 47

Second-order logic F 2

The PTS F 2 has the following specification: S2

F

= { ⋆, , ⌈⋆⌉, ⌈⌉ } A2

F

= { (⋆, ), (⌈⋆⌉, ⌈⌉) } R2

F

= { (⋆, ⋆, ⋆), (, ⋆, ⋆), (⌈⋆⌉, ⌈⋆⌉, ⌈⋆⌉), (⌈⌉, ⌈⋆⌉, ⌈⋆⌉) (⋆, ⌈⌉, ⌈⌉), (⋆, ⌈⋆⌉, ⌈⋆⌉), (, ⌈⋆⌉, ⌈⋆⌉) }. The logic F 2 is a second-order logic with higher-order typed individuals (FA2 with higher-order individuals). ⌈⋆⌉ is the sort of formulas (like Prop in Coq). (⌈⋆⌉, ⌈⋆⌉, ⌈⋆⌉) allows to build implication P → Q. (⋆, ⌈⋆⌉, ⌈⋆⌉) allows to quantify over programs ∀x : τ.P. (, ⌈⋆⌉, ⌈⋆⌉) allows to quantify over types ∀α.P.

16 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-48
SLIDE 48

Second-order logic F 2

The PTS F 2 has the following specification: S2

F

= { ⋆, , ⌈⋆⌉, ⌈⌉ } A2

F

= { (⋆, ), (⌈⋆⌉, ⌈⌉) } R2

F

= { (⋆, ⋆, ⋆), (, ⋆, ⋆), (⌈⋆⌉, ⌈⋆⌉, ⌈⋆⌉), (⌈⌉, ⌈⋆⌉, ⌈⋆⌉) (⋆, ⌈⌉, ⌈⌉), (⋆, ⌈⋆⌉, ⌈⋆⌉), (, ⌈⋆⌉, ⌈⋆⌉) }. The logic F 2 is a second-order logic with higher-order typed individuals (FA2 with higher-order individuals). ⌈⋆⌉ is the sort of formulas (like Prop in Coq). (⌈⋆⌉, ⌈⋆⌉, ⌈⋆⌉) allows to build implication P → Q. (⋆, ⌈⋆⌉, ⌈⋆⌉) allows to quantify over programs ∀x : τ.P. (, ⌈⋆⌉, ⌈⋆⌉) allows to quantify over types ∀α.P. (⋆, ⌈⌉, ⌈⌉) is used to build signatures of predicates. They are all of the form τ1 → · · · → τn → ⌈⋆⌉.

16 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-49
SLIDE 49

Second-order logic F 2

The PTS F 2 has the following specification: S2

F

= { ⋆, , ⌈⋆⌉, ⌈⌉ } A2

F

= { (⋆, ), (⌈⋆⌉, ⌈⌉) } R2

F

= { (⋆, ⋆, ⋆), (, ⋆, ⋆), (⌈⋆⌉, ⌈⋆⌉, ⌈⋆⌉), (⌈⌉, ⌈⋆⌉, ⌈⋆⌉) (⋆, ⌈⌉, ⌈⌉), (⋆, ⌈⋆⌉, ⌈⋆⌉), (, ⌈⋆⌉, ⌈⋆⌉) }. The logic F 2 is a second-order logic with higher-order typed individuals (FA2 with higher-order individuals). ⌈⋆⌉ is the sort of formulas (like Prop in Coq). (⌈⋆⌉, ⌈⋆⌉, ⌈⋆⌉) allows to build implication P → Q. (⋆, ⌈⋆⌉, ⌈⋆⌉) allows to quantify over programs ∀x : τ.P. (, ⌈⋆⌉, ⌈⋆⌉) allows to quantify over types ∀α.P. (⋆, ⌈⌉, ⌈⌉) is used to build signatures of predicates. They are all of the form τ1 → · · · → τn → ⌈⋆⌉. (⌈⌉, ⌈⋆⌉, ⌈⋆⌉) allows to quantify over predicates ∀X : τ1 → · · · → τn → ⌈⋆⌉.P.

16 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-50
SLIDE 50

Second-order logic F 2 – A stratified presentation

We can prove that F 2 is equivalent to this presentation:

programs:

t, t1, t2 := x | λx : τ.t | Λα.τ | (t1 t2) | (t τ) types: τ, σ := α | σ → τ | ∀α.τ

17 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-51
SLIDE 51

Second-order logic F 2 – A stratified presentation

We can prove that F 2 is equivalent to this presentation:

programs:

t, t1, t2 := x | λx : τ.t | Λα.τ | (t1 t2) | (t τ) types: τ, σ := α | σ → τ | ∀α.τ formulas: P, Q := X t1... tn | P → Q | ∀α.P | ∀x : τ.P | ∀X : τ1 → ... → τn → Prop.P

17 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-52
SLIDE 52

Second-order logic F 2 – A stratified presentation

We can prove that F 2 is equivalent to this presentation:

programs:

t, t1, t2 := x | λx : τ.t | Λα.τ | (t1 t2) | (t τ) types: τ, σ := α | σ → τ | ∀α.τ formulas: P, Q := X t1... tn | P → Q | ∀α.P | ∀x : τ.P | ∀X : τ1 → ... → τn → Prop.P + a proof system

17 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-53
SLIDE 53

Second-order logic F 2 – A stratified presentation

We can prove that F 2 is equivalent to this presentation:

programs:

t, t1, t2 := x | λx : τ.t | Λα.τ | (t1 t2) | (t τ) types: τ, σ := α | σ → τ | ∀α.τ formulas: P, Q := X t1... tn | P → Q | ∀α.P | ∀x : τ.P | ∀X : τ1 → ... → τn → Prop.P + a proof system In the PTS presentation, proofs are represented by terms

17 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-54
SLIDE 54

Second-order logic: F 2 – Examples

Here are some examples in F 2. Truth: ⊤ ≡ ∀X : ⌈⋆⌉.X → X and is proved by λX : ⌈⋆⌉(h : X).h

18 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-55
SLIDE 55

Second-order logic: F 2 – Examples

Here are some examples in F 2. Truth: ⊤ ≡ ∀X : ⌈⋆⌉.X → X and is proved by λX : ⌈⋆⌉(h : X).h Leibniz equality: x =τ y ≡ ∀X : τ → ⌈⋆⌉.X x → X y

18 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-56
SLIDE 56

Second-order logic: F 2 – Examples

Here are some examples in F 2. Truth: ⊤ ≡ ∀X : ⌈⋆⌉.X → X and is proved by λX : ⌈⋆⌉(h : X).h Leibniz equality: x =τ y ≡ ∀X : τ → ⌈⋆⌉.X x → X y ∀(α : ⋆)(x : α).x =α x is proved by λ(α : ⋆)(x : α)(X : α → ⌈⋆⌉)(h : X x).h

18 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-57
SLIDE 57

Second-order logic: F 2 – Examples

Here are some examples in F 2. Truth: ⊤ ≡ ∀X : ⌈⋆⌉.X → X and is proved by λX : ⌈⋆⌉(h : X).h Leibniz equality: x =τ y ≡ ∀X : τ → ⌈⋆⌉.X x → X y ∀(α : ⋆)(x : α).x =α x is proved by λ(α : ⋆)(x : α)(X : α → ⌈⋆⌉)(h : X x).h The induction principle over Nat: N ≡ λx : Nat .∀X : Nat → ⌈⋆⌉.(∀y : Nat .X y → X (Succ y)) → X 0 → X x

18 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-58
SLIDE 58

Lifting and projection

Lifting

⌈·⌉ embeds the first level toward its copy.

⌈∀α : ⋆.α → α⌉ ≡ ∀X : ⌈⋆⌉.X → X ⌈Nat⌉ ≡ ∀X : ⌈⋆⌉.(X → X) → X → X

19 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-59
SLIDE 59

Lifting and projection

Projection

⌊·⌋ collapses the second level toward the first level.

⌊t1 =τ t2⌋ ≡ ⌊∀X : τ → ⌈⋆⌉.X t1 → X t2⌋ ≡ ∀α : ⋆.α → α ⌊N t⌋ ≡ ⌊∀X : Nat → ⌈⋆⌉.(∀y : Nat .X y → X (Succ y)) → X 0 → X t⌋ ≡ ∀α.(α → α) → α → α ≡ Nat

19 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-60
SLIDE 60

Lifting and projection – Lemmas

20 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-61
SLIDE 61

Lifting and projection – Lemmas

Lifting preserves typing

Γ ⊢ A : B : s ⇒ ⌈Γ⌉ ⊢ ⌈A⌉ : ⌈B⌉ : ⌈s⌉

20 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-62
SLIDE 62

Lifting and projection – Lemmas

Lifting preserves typing

Γ ⊢ A : B : s ⇒ ⌈Γ⌉ ⊢ ⌈A⌉ : ⌈B⌉ : ⌈s⌉

Lifting preserves β-reduction

A− →βB ⇒ ⌈A⌉− →β⌈B⌉

20 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-63
SLIDE 63

Lifting and projection – Lemmas

Lifting preserves typing

Γ ⊢ A : B : s ⇒ ⌈Γ⌉ ⊢ ⌈A⌉ : ⌈B⌉ : ⌈s⌉

Lifting preserves β-reduction

A− →βB ⇒ ⌈A⌉− →β⌈B⌉

Projection preserves typing

Γ ⊢ A : B : ⌈s⌉ ⇒ ⌊Γ⌋ ⊢ ⌊A⌋ : ⌊B⌋ : s

20 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-64
SLIDE 64

Lifting and projection – Lemmas

Lifting preserves typing

Γ ⊢ A : B : s ⇒ ⌈Γ⌉ ⊢ ⌈A⌉ : ⌈B⌉ : ⌈s⌉

Lifting preserves β-reduction

A− →βB ⇒ ⌈A⌉− →β⌈B⌉

Projection preserves typing

Γ ⊢ A : B : ⌈s⌉ ⇒ ⌊Γ⌋ ⊢ ⌊A⌋ : ⌊B⌋ : s

Projection preserves or removes β-reduction

If A− →βB, then either ⌊A⌋− →β⌊B⌋ or ⌊A⌋ = ⌊B⌋.

20 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-65
SLIDE 65

Lifting and projection – Lemmas

Lifting preserves typing

Γ ⊢ A : B : s ⇒ ⌈Γ⌉ ⊢ ⌈A⌉ : ⌈B⌉ : ⌈s⌉

Lifting preserves β-reduction

A− →βB ⇒ ⌈A⌉− →β⌈B⌉

Projection preserves typing

Γ ⊢ A : B : ⌈s⌉ ⇒ ⌊Γ⌋ ⊢ ⌊A⌋ : ⌊B⌋ : s

Projection preserves or removes β-reduction

If A− →βB, then either ⌊A⌋− →β⌊B⌋ or ⌊A⌋ = ⌊B⌋.

Projection is the left inverse of lifting

⌊⌈A⌉⌋ = A

20 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-66
SLIDE 66

Strong normalization

Theorem (Normalization)

If P is strongly normalizing, so is P2.

21 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-67
SLIDE 67

Strong normalization

Theorem (Normalization)

If P is strongly normalizing, so is P2.

Proof sketch.

If a term A is typable in P2 and not normalizable, then :

  • ne of the first-level subterms of A is not normalizable, or

the first-level term ⌊A⌋ is not normalizable.

21 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-68
SLIDE 68

1

Introduction

2

Building the logic

3

Parametricity and realizability in PTS’s

4

An application and an extension

22 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-69
SLIDE 69

Parametricity and realizability in PTS’s

In the following sections, We are going to define a parametricity relation : (A, B) ∈ C (we no longer use the notation A ∼C B) and a realizability relation : A B.

23 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-70
SLIDE 70

Parametricity and realizability in PTS’s

In the following sections, We are going to define a parametricity relation : (A, B) ∈ C (we no longer use the notation A ∼C B) and a realizability relation : A B. Formula Formula

  • (

· , · ) ∈ ·

↑ ↑

  • ·
  • ·

↑ ↑ Program/Program/Type Program/Formula

23 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-71
SLIDE 71

Parametricity and realizability in PTS’s

In the following sections, We are going to define a parametricity relation : (A, B) ∈ C (we no longer use the notation A ∼C B) and a realizability relation : A B. Formula Formula

  • (

· , · ) ∈ ·

↑ ↑

  • ·
  • ·

↑ ↑ Program/Program/Type Program/Formula Type/Type/Sort Type/Lifted Sort

23 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-72
SLIDE 72

Parametricity in PTS’s

We define at the same time :

a ternary notation (·, ·) ∈ · a unary notation ·

24 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-73
SLIDE 73

Parametricity in PTS’s

We define at the same time :

a ternary notation (·, ·) ∈ · a unary notation ·

We want to satisfy the abstraction theorem:

24 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-74
SLIDE 74

Parametricity in PTS’s

We define at the same time :

a ternary notation (·, ·) ∈ · a unary notation ·

We want to satisfy the abstraction theorem:

Theorem (abstraction)

If Γ ⊢ A : B : s, then Γ ⊢ A : (A, A) ∈ B : ⌈s⌉

24 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-75
SLIDE 75

Parametricity in PTS’s – Products, sorts and variables

(A1, A2) ∈ ∀x : B.C ≡ ∀(x1 : B)(x2 : B).(x1, x2) ∈ B → (A1 x1, A2 x2) ∈ C

25 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-76
SLIDE 76

Parametricity in PTS’s – Products, sorts and variables

(A1, A2) ∈ ∀x : B.C ≡ ∀(x1 : B)(x2 : B)(xR : (x1, x2) ∈ B).(A1 x1, A2 x2) ∈ C

25 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-77
SLIDE 77

Parametricity in PTS’s – Products, sorts and variables

(A1, A2) ∈ ∀x : B.C ≡ ∀(x1 : B)(x2 : B)(xR : (x1, x2) ∈ B).(A1 x1, A2 x2) ∈ C (A1, A2) ∈ x ≡ (xR A1 A2)

25 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-78
SLIDE 78

Parametricity in PTS’s – Products, sorts and variables

(A1, A2) ∈ ∀x : B.C ≡ ∀(x1 : B)(x2 : B)(xR : (x1, x2) ∈ B).(A1 x1, A2 x2) ∈ C (A1, A2) ∈ x ≡ (xR A1 A2) (A1, A2) ∈ s ≡ A1 → A2 → ⌈s⌉

25 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-79
SLIDE 79

Parametricity in PTS’s – Example

(t1, t2) ∈ ∀α : ⋆.α → α ≡ ∀(α1 : ⋆)(α2 : ⋆)(αR : (α1, α2) ∈ ⋆ ). (t1 α1, t2 α2) ∈ α → α

26 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-80
SLIDE 80

Parametricity in PTS’s – Example

(t1, t2) ∈ ∀α : ⋆.α → α ≡ ∀(α1 : ⋆)(α2 : ⋆)(αR : (α1, α2) ∈ ⋆ ). (t1 α1, t2 α2) ∈ α → α (α1, α2) ∈ ⋆ ≡ α1 → α2 → ⌈⋆⌉

26 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-81
SLIDE 81

Parametricity in PTS’s – Example

(t1, t2) ∈ ∀α : ⋆.α → α ≡ ∀(α1 : ⋆)(α2 : ⋆)(αR : α1 → α2 → ⌈⋆⌉). (t1 α1, t2 α2) ∈ α → α (α1, α2) ∈ ⋆ ≡ α1 → α2 → ⌈⋆⌉

26 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-82
SLIDE 82

Parametricity in PTS’s – Example

(t1, t2) ∈ ∀α : ⋆.α → α ≡ ∀(α1 : ⋆)(α2 : ⋆)(αR : α1 → α2 → ⌈⋆⌉). (t1 α1, t2 α2) ∈ α → α (α1, α2) ∈ ⋆ ≡ α1 → α2 → ⌈⋆⌉ (t1 α1, t2 α2) ∈ α → α ≡

26 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-83
SLIDE 83

Parametricity in PTS’s – Example

(t1, t2) ∈ ∀α : ⋆.α → α ≡ ∀(α1 : ⋆)(α2 : ⋆)(αR : α1 → α2 → ⌈⋆⌉). (t1 α1, t2 α2) ∈ α → α (α1, α2) ∈ ⋆ ≡ α1 → α2 → ⌈⋆⌉ (t1 α1, t2 α2) ∈ α → α ≡ ∀(x1 : α)(x2 : α). (x1, x2) ∈ α → (t1 α1 x1, t2 α2 x2) ∈ α

26 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-84
SLIDE 84

Parametricity in PTS’s – Example

(t1, t2) ∈ ∀α : ⋆.α → α ≡ ∀(α1 : ⋆)(α2 : ⋆)(αR : α1 → α2 → ⌈⋆⌉). (t1 α1, t2 α2) ∈ α → α (α1, α2) ∈ ⋆ ≡ α1 → α2 → ⌈⋆⌉ (t1 α1, t2 α2) ∈ α → α ≡ ∀(x1 : α)(x2 : α). (x1, x2) ∈ α → (t1 α1 x1, t2 α2 x2) ∈ α (A, B) ∈ α ≡ αR A B

26 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-85
SLIDE 85

Parametricity in PTS’s – Example

(t1, t2) ∈ ∀α : ⋆.α → α ≡ ∀(α1 : ⋆)(α2 : ⋆)(αR : α1 → α2 → ⌈⋆⌉). (t1 α1, t2 α2) ∈ α → α (α1, α2) ∈ ⋆ ≡ α1 → α2 → ⌈⋆⌉ (t1 α1, t2 α2) ∈ α → α ≡ ∀(x1 : α)(x2 : α). αR x1 x2 → αR (t1 α1 x1) (t2 α2 x2) (A, B) ∈ α ≡ αR A B

26 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-86
SLIDE 86

Parametricity in PTS’s – Example

(t1, t2) ∈ ∀α : ⋆.α → α ≡ ∀(α1 : ⋆)(α2 : ⋆)(αR : α1 → α2 → ⌈⋆⌉). (t1 α1, t2 α2) ∈ α → α (α1, α2) ∈ ⋆ ≡ α1 → α2 → ⌈⋆⌉ (t1 α1, t2 α2) ∈ α → α ≡ ∀(x1 : α)(x2 : α). αR x1 x2 → αR (t1 α1 x1) (t2 α2 x2) (A, B) ∈ α ≡ αR A B Finally, (t1, t2) ∈ ∀α : ⋆.α → α ≡ ∀(α1 : ⋆)(α2 : ⋆)(αR : α1 → α2 → ⌈⋆⌉). ∀(x1 : α1)(x2 : α2).αR x1 x2 → αR(t1 α1 x1) (t2 α2 x2)

26 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-87
SLIDE 87

Parametricity in PTS’s

Here is the transformation for the product: (A1, A2) ∈ ∀x : B.C ≡ ∀(x1 : B)(x2 : B)(xR : (x1, x2) ∈ B).(A1 x1, A2 x2) ∈ C

27 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-88
SLIDE 88

Parametricity in PTS’s

Here is the transformation for the product: (A1, A2) ∈ ∀x : B.C ≡ ∀(x1 : B)(x2 : B)(xR : (x1, x2) ∈ B).(A1 x1, A2 x2) ∈ C If we have ⊢ (λx : B.A) : (∀x : B.C), since we want to satisfy the abstraction theorem, we must take λx : B.A ≡ λ(x1 : B)(x2 : B)(xR : (x1, x2) ∈ B).A

27 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-89
SLIDE 89

Parametricity in PTS’s

Here is the transformation for the product: (A1, A2) ∈ ∀x : B.C ≡ ∀(x1 : B)(x2 : B)(xR : (x1, x2) ∈ B).(A1 x1, A2 x2) ∈ C If we have ⊢ (λx : B.A) : (∀x : B.C), since we want to satisfy the abstraction theorem, we must take λx : B.A ≡ λ(x1 : B)(x2 : B)(xR : (x1, x2) ∈ B).A Symmetrically, we need to take (A B) ≡ (A B B B).

27 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-90
SLIDE 90

Parametricity in PTS’s – The whole definition

Definition (parametricity)

(C1, C2) ∈ s (C1, C2) ∈ ∀x : A. B (C1, C2) ∈ T x λx : A.B A B T

28 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-91
SLIDE 91

Parametricity in PTS’s – The whole definition

Definition (parametricity)

(C1, C2) ∈ s = C1 → C2 → ⌈s⌉ (C1, C2) ∈ ∀x : A. B = ∀(x1 : A)(x2 : A)(xR : (x1, x2) ∈ A). (C1 x1, C2 x2) ∈ B (C1, C2) ∈ T = (T C1 C2) otherwise x λx : A.B A B T

Theorem (abstraction)

If Γ ⊢ A : B : s, then Γ ⊢ A : (A, A) ∈ B : ⌈s⌉

28 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-92
SLIDE 92

Parametricity in PTS’s – The whole definition

Definition (parametricity)

(C1, C2) ∈ s = C1 → C2 → ⌈s⌉ (C1, C2) ∈ ∀x : A. B = ∀(x1 : A)(x2 : A)(xR : (x1, x2) ∈ A). (C1 x1, C2 x2) ∈ B (C1, C2) ∈ T = (T C1 C2) otherwise x = xR λx : A.B = λ(x1 : A)(x2 : A)(xR : (x1, x2) ∈ A).B A B = A B B B T = λ(x1 x2 : T).(x1, x2) ∈ T otherwise

Theorem (abstraction)

If Γ ⊢ A : B : s, then Γ ⊢ A : (A, A) ∈ B : ⌈s⌉

28 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-93
SLIDE 93

Parametricity in PTS’s – The n-ary version

Definition (parametricity)

C ∈ sn = C → ⌈s⌉ C ∈ ∀x : A. Bn = ∀x : A. ∀xR : x ∈ An. z x ∈ Bn C ∈ Tn = Tn C otherwise xn = xR λx : A. Bn = λx : A. λxR : x ∈ An. Bn A Bn = An B Bn Tn = λz : T. C ∈ Tn otherwise

Theorem (abstraction)

If Γ ⊢ A : B : s, then Γn ⊢ An : A ∈ Bn : ⌈s⌉

29 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-94
SLIDE 94

Realizability in second-order logic

In traditional presentation of realizability: t P → Q ≡ ∀x, x P → (t x) Q

30 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-95
SLIDE 95

Realizability in second-order logic

In traditional presentation of realizability: t P → Q ≡ ∀x, x P → (t x) Q t ∀x.P ≡ ∀x, t P

30 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-96
SLIDE 96

Realizability in second-order logic

In traditional presentation of realizability: t P → Q ≡ ∀x, x P → (t x) Q t ∀x.P ≡ ∀x, t P There are two kinds of quantification: First-level quantification Second-level quantification

30 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-97
SLIDE 97

Realizability in second-order logic

In traditional presentation of realizability: t P → Q ≡ ∀x, x P → (t x) Q t ∀x.P ≡ ∀x, t P There are two kinds of quantification: First-level quantification Second-level quantification

30 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-98
SLIDE 98

Realizability in second-order logic

In traditional presentation of realizability: t P → Q ≡ ∀x, x P → (t x) Q t ∀x.P ≡ ∀x, t P There are two kinds of quantification: First-level quantification : uniform, Second-level quantification

30 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-99
SLIDE 99

Realizability in second-order logic

In traditional presentation of realizability: t P → Q ≡ ∀x, x P → (t x) Q t ∀x.P ≡ ∀x, t P There are two kinds of quantification: First-level quantification : uniform, Second-level quantification

30 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-100
SLIDE 100

Realizability in second-order logic

In traditional presentation of realizability: t P → Q ≡ ∀x, x P → (t x) Q t ∀x.P ≡ ∀x, t P There are two kinds of quantification: First-level quantification : uniform, Second-level quantification : things happen.

30 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-101
SLIDE 101

Pure Type Systems – A technical detail: sort annotations

We annotate variables with the sort of their type

31 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-102
SLIDE 102

Pure Type Systems – A technical detail: sort annotations

We annotate variables with the sort of their type Here is the product rule : Γ ⊢ A : s1 Γ, x : A ⊢ B : s2 Product

(s1, s2, s3) ∈ R

Γ ⊢ (∀x : A.B) : s3

31 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-103
SLIDE 103

Pure Type Systems – A technical detail: sort annotations

We annotate variables with the sort of their type Here is the product rule : Γ ⊢ A : s1 Γ, xs1 : A ⊢ B : s2 Product

(s1, s2, s3) ∈ R

Γ ⊢ (∀xs1 : A.B) : s3 We can distinguish the two kinds of quantification:

First-level quantification of the form ∀xs : A.B, Second-level quantification of the form ∀x⌈s⌉ : A.B.

31 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-104
SLIDE 104

Realizability in PTS’s

We define at the same time :

a binary notation · · a unary notation ·

We want to satisfy the adequacy theorem:

Theorem (adequacy)

If Γ ⊢ A : B : ⌈s⌉, then Γ ⊢ A : ⌊A⌋ B : ⌈s⌉

32 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-105
SLIDE 105

Realizability in PTS’s – The products

First level quantification : C ∀xs : A.B = ∀xs : A.C B

33 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-106
SLIDE 106

Realizability in PTS’s – The products

First level quantification : C ∀xs : A.B = ∀xs : A.C B Second level quantification : C ∀x⌈s⌉ : A.B = ∀(⌊x⌋s : ⌊A⌋)(x⌈s⌉ : ⌊x⌋ A).(C ⌊x⌋) B

33 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-107
SLIDE 107

Realizability in PTS’s – The products

First level quantification : C ∀xs : A.B = ∀xs : A.C B Second level quantification : C ∀x⌈s⌉ : A.B = ∀(⌊x⌋s : ⌊A⌋)(x⌈s⌉ : ⌊x⌋ A).(C ⌊x⌋) B Sorts : C ⌈s⌉ = C → ⌈s⌉

33 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-108
SLIDE 108

Realizability in PTS’s – The products

First level quantification : C ∀xs : A.B = ∀xs : A.C B Second level quantification : C ∀x⌈s⌉ : A.B = ∀(⌊x⌋s : ⌊A⌋)(x⌈s⌉ : ⌊x⌋ A).(C ⌊x⌋) B Sorts : C ⌈s⌉ = C → ⌈s⌉ In F 2,

33 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-109
SLIDE 109

Realizability in PTS’s – The products

First level quantification : C ∀xs : A.B = ∀xs : A.C B Second level quantification : C ∀x⌈s⌉ : A.B = ∀(⌊x⌋s : ⌊A⌋)(x⌈s⌉ : ⌊x⌋ A).(C ⌊x⌋) B Sorts : C ⌈s⌉ = C → ⌈s⌉ In F 2, t ∀x : τ.P ≡ ∀x : τ.t Q

33 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-110
SLIDE 110

Realizability in PTS’s – The products

First level quantification : C ∀xs : A.B = ∀xs : A.C B Second level quantification : C ∀x⌈s⌉ : A.B = ∀(⌊x⌋s : ⌊A⌋)(x⌈s⌉ : ⌊x⌋ A).(C ⌊x⌋) B Sorts : C ⌈s⌉ = C → ⌈s⌉ In F 2, t ∀x : τ.P ≡ ∀x : τ.t Q

33 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-111
SLIDE 111

Realizability in PTS’s – The products

First level quantification : C ∀xs : A.B = ∀xs : A.C B Second level quantification : C ∀x⌈s⌉ : A.B = ∀(⌊x⌋s : ⌊A⌋)(x⌈s⌉ : ⌊x⌋ A).(C ⌊x⌋) B Sorts : C ⌈s⌉ = C → ⌈s⌉ In F 2, t ∀x : τ.P ≡ ∀x : τ.t Q t P → Q ≡ ∀x : ⌊P⌋.x P → (t x) Q

33 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-112
SLIDE 112

Realizability in PTS’s – The products

First level quantification : C ∀xs : A.B = ∀xs : A.C B Second level quantification : C ∀x⌈s⌉ : A.B = ∀(⌊x⌋s : ⌊A⌋)(x⌈s⌉ : ⌊x⌋ A).(C ⌊x⌋) B Sorts : C ⌈s⌉ = C → ⌈s⌉ In F 2, t ∀x : τ.P ≡ ∀x : τ.t Q t P → Q ≡ ∀x : ⌊P⌋.x P → (t x) Q

33 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-113
SLIDE 113

Realizability in PTS’s – The products

First level quantification : C ∀xs : A.B = ∀xs : A.C B Second level quantification : C ∀x⌈s⌉ : A.B = ∀(⌊x⌋s : ⌊A⌋)(x⌈s⌉ : ⌊x⌋ A).(C ⌊x⌋) B Sorts : C ⌈s⌉ = C → ⌈s⌉ In F 2, t ∀x : τ.P ≡ ∀x : τ.t Q t P → Q ≡ ∀x : ⌊P⌋.x P → (t x) Q t ∀X : τ1 → · · · → τn → ⌈⋆⌉.P ≡ ∀α : ⋆.∀X : τ1 → · · · → τn → α → ⌈⋆⌉.(t α) P

33 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-114
SLIDE 114

Realizability in PTS’s – The whole definition

Definition (realizability)

C ⌈s⌉ = C → ⌈s⌉ C ∀xs : A.B = ∀xs : A.C B C ∀x⌈s⌉ : A.B = ∀(⌊x⌋s : ⌊A⌋)(x⌈s⌉ : ⌊x⌋ A).(C ⌊x⌋) B C F = F C otherwise

Theorem (adequacy)

If Γ ⊢ A : B : ⌈s⌉, then Γ ⊢ A : ⌊A⌋ B : ⌈s⌉

34 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-115
SLIDE 115

Realizability in PTS’s – The whole definition

Definition (realizability)

C ⌈s⌉ = C → ⌈s⌉ C ∀xs : A.B = ∀xs : A.C B C ∀x⌈s⌉ : A.B = ∀(⌊x⌋s : ⌊A⌋)(x⌈s⌉ : ⌊x⌋ A).(C ⌊x⌋) B C F = F C otherwise x⌈s⌉ = x⌈s⌉ λxs : A.B = λxs : A.B λx⌈s⌉ : A.B = λ(⌊x⌋s : ⌊A⌋)(x⌈s⌉ : ⌊x⌋ A).B (A B)s = (A B)s (A B)⌈s⌉ = ((A ⌊B⌋)s B)⌈s⌉ T = λzs : ⌊T⌋. z T otherwise

Theorem (adequacy)

If Γ ⊢ A : B : ⌈s⌉, then Γ ⊢ A : ⌊A⌋ B : ⌈s⌉

34 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-116
SLIDE 116

From realizability to parametricity

Theorem (realizability increases arity of parametricity)

  • B, C
  • ∈ An+1 = B
  • C ∈ An
  • and

An+1 = An

Lemma (0-parametricity is lifting)

A0 ≡ ⌈A⌉ We can define parametricity with lifting+realizability:

Corollary (From realizability to parametricity)

z ∈ An = z1 z2 · · · zn ⌈A⌉ and An = · · · ⌈A⌉ · · ·

35 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-117
SLIDE 117

A third level – From parametricity to realizability

Theorem (From parametricity to realizability)

If A is a second-level term, then z A = ⌊⌈z⌉ ∈ A1⌋ and A = ⌊A1⌋

36 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-118
SLIDE 118

1

Introduction

2

Building the logic

3

Parametricity and realizability in PTS’s

4

An application and an extension

37 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-119
SLIDE 119

Representation theorems

If P = F or P = Fω or P = calculus of construction,

38 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-120
SLIDE 120

Representation theorems

If P = F or P = Fω or P = calculus of construction, We can follow Krivine’s methodology

38 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-121
SLIDE 121

Representation theorems

If P = F or P = Fω or P = calculus of construction, We can follow Krivine’s methodology Using second-order encoding:

We can encode Leibniz equality · =τ · We use the induction principle N x to encode integer in proofs

38 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-122
SLIDE 122

Representation theorems

If P = F or P = Fω or P = calculus of construction, We can follow Krivine’s methodology Using second-order encoding:

We can encode Leibniz equality · =τ · We use the induction principle N x to encode integer in proofs

N is a datatype : ∀r x, r N x ⇔ (N x ∧ r =Nat x)

38 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-123
SLIDE 123

Representation theorems

If P = F or P = Fω or P = calculus of construction, We can follow Krivine’s methodology Using second-order encoding:

We can encode Leibniz equality · =τ · We use the induction principle N x to encode integer in proofs

N is a datatype : ∀r x, r N x ⇔ (N x ∧ r =Nat x) From any proof π of ∀x1...xn : Nat, N x1 → · · · → N xn → N (f x1 ... xn)

38 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-124
SLIDE 124

Representation theorems

If P = F or P = Fω or P = calculus of construction, We can follow Krivine’s methodology Using second-order encoding:

We can encode Leibniz equality · =τ · We use the induction principle N x to encode integer in proofs

N is a datatype : ∀r x, r N x ⇔ (N x ∧ r =Nat x) From any proof π of ∀x1...xn : Nat, N x1 → · · · → N xn → N (f x1 ... xn) ... we obtain a program ⌊π⌋ such that ⌊π⌋ =Nat f

38 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-125
SLIDE 125

Representation theorems

If P = F or P = Fω or P = calculus of construction, We can follow Krivine’s methodology Using second-order encoding:

We can encode Leibniz equality · =τ · We use the induction principle N x to encode integer in proofs

N is a datatype : ∀r x, r N x ⇔ (N x ∧ r =Nat x) From any proof π of ∀x1...xn : Nat, N x1 → · · · → N xn → N (f x1 ... xn) ... we obtain a program ⌊π⌋ such that ⌊π⌋ =Nat f Conversely : if ⊢P p : Nat → Nat we can find πp such that ⊢P2 πp : ∀x : Nat, N x → N (p x).

38 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-126
SLIDE 126

Representation theorems

If P = F or P = Fω or P = calculus of construction, We can follow Krivine’s methodology Using second-order encoding:

We can encode Leibniz equality · =τ · We use the induction principle N x to encode integer in proofs

N is a datatype : ∀r x, r N x ⇔ (N x ∧ r =Nat x) From any proof π of ∀x1...xn : Nat, N x1 → · · · → N xn → N (f x1 ... xn) ... we obtain a program ⌊π⌋ such that ⌊π⌋ =Nat f Conversely : if ⊢P p : Nat → Nat we can find πp such that ⊢P2 πp : ∀x : Nat, N x → N (p x).

Theorem

Arithmetic functions representable in P are those provably total in P2.

38 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-127
SLIDE 127

Inductive types

Encoding of conjunction: data ∧ : ⌈s⌉ → ⌈s⌉ → ⌈s⌉ where conj : Π P Q : ⌈s⌉.P → Q → P ∧ Q

39 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-128
SLIDE 128

Inductive types

Encoding of conjunction: data ∧ : ⌈s⌉ → ⌈s⌉ → ⌈s⌉ where conj : Π P Q : ⌈s⌉.P → Q → P ∧ Q Projection ⌊∧⌋ = ×: data × : s → s → s where ( , ) : Π α β : s.α → β → α × β

39 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-129
SLIDE 129

data ∧ : Π(α : s).(α → ⌈s⌉) → Π(β : s).(β → ⌈s⌉) → α × β → s where conj : Π(α : s)(P : α → ⌈s⌉) (β : s)(Q : β → ⌈s⌉)(x : α)(y : β). P x → Q y → ∧ α P β Q (x, y) By definition, t P ∧ Q means ∧ ⌊P⌋ P ⌊Q⌋ Q t. We have t P ∧ Q ⇔ (π1 t) P ∧ (π2 t) Q where π1 and π2 are projections upon cartesian product.

40 / 41 Realizability and parametricity in pure type systems Marc Lasson

slide-130
SLIDE 130

Conclusion

We gave a systematic way to formalize the meta-theory to study a programming language An account of parametricity and realizability in PTSs We exposed links between the two Extension: works with inductive types

41 / 41 Realizability and parametricity in pure type systems Marc Lasson