Cumulative Types Systems and Levels Franois Thir June 22, 2019 - - PowerPoint PPT Presentation

cumulative types systems and levels
SMART_READER_LITE
LIVE PREVIEW

Cumulative Types Systems and Levels Franois Thir June 22, 2019 - - PowerPoint PPT Presentation

Cumulative Types Systems and Levels Franois Thir June 22, 2019 LSV, CNRS, Inria, ENS Paris-Saclay 1 Logipedia (http://logipedia.science) Matita HOL D[STT ] D[CiC] Agda Coq D[MLTT] D[CiC] Dedukti 2 Logipedia


slide-1
SLIDE 1

Cumulative Types Systems and Levels

François Thiré June 22, 2019

LSV, CNRS, Inria, ENS Paris-Saclay 1

slide-2
SLIDE 2

Logipedia (http://logipedia.science)

Dedukti D[STT∀] D[CiC] D[CiC] D[MLTT] Coq Agda HOL Matita

2

slide-3
SLIDE 3

Logipedia (http://logipedia.science)

Dedukti D[CH + . . .] D[CM + . . .] D[CC + . . .] D[CA + . . .] Coq Agda HOL Matita

2

slide-4
SLIDE 4

Cumulative Type Systems

C = (S, A, R, C) Sorts Axioms Rules Cumul. Syntax t, u, A, B ::= s ∈ S | x | t u | λx : A. t | (x : A) → B

Γ ⊢C A : s1 Γ, x : A ⊢C B : s2 (s1, s2, s3) ∈ R Γ ⊢C (x : A) → B : s3

Π

Γ ⊢o

C wf

(s1, s2) ∈ A Γ ⊢o

C s1 : s2

Csort

Γ ⊢C t : A Γ ⊢C B : s AC

C B

Γ ⊢C t : B

Conv(CTS)

3

slide-5
SLIDE 5

Cumulative Type Systems

C = (S, A, R, ∅) Sorts Axioms Rules Cumul. Syntax t, u, A, B ::= s ∈ S | x | t u | λx : A. t | (x : A) → B

Γ ⊢C A : s1 Γ, x : A ⊢C B : s2 (s1, s2, s3) ∈ R Γ ⊢C (x : A) → B : s3

Π

Γ ⊢o

C wf

(s1, s2) ∈ A Γ ⊢o

C s1 : s2

Csort

Γ ⊢C t : A Γ ⊢C B : s A≡βB Γ ⊢C t : B

Conv(PTS)

3

slide-6
SLIDE 6

Translations

Dedukti D[CH + . . .] D[CM + . . .] D[CC + . . .] D[CA + . . .] Coq Agda HOL Matita

4

slide-7
SLIDE 7

Strange loop 1

Correctness of the translation: Γ ⊢C t : A ⇒ Γ ⊢D [t] : A

5

slide-8
SLIDE 8

Strange loop 1

Correctness of the translation: Γ ⊢C t : A ⇒ Γ ⊢D [t] : A Main lemma:

  • 1. A≡βB ⇒ A ≡β B

5

slide-9
SLIDE 9

Strange loop 1

Correctness of the translation: Γ ⊢C t : A ⇒ Γ ⊢D [t] : A Main lemma:

  • 1. A≡βB ⇒ A ≡β B
  • 2. [t] {x ← [N]} = [t {x ← N}]

Dependencies:

  • 1 → 2

5

slide-10
SLIDE 10

Strange loop 1

Correctness of the translation: Γ ⊢C t : A ⇒ Γ ⊢D [t] : A Main lemma:

  • 1. A≡βB ⇒ A ≡β B
  • 2. [t] {x ← [N]} = [t {x ← N}]

Dependencies:

  • 1 → 2
  • 2 → 1

Γ ⊢C t : A Γ ⊢C B : s A≡βB Γ ⊢C t : B

Conv

5

slide-11
SLIDE 11

Strange loop 1

Correctness of the translation: Γ ⊢C t : A ⇒ Γ ⊢D [t] : A Main lemma:

  • 1. A≡βB ⇒ A ≡β B
  • 2. [t] {x ← [N]} = [t {x ← N}]

Dependencies:

  • 1 → 2
  • 2 → 1 but for the type

Γ ⊢C t : A Γ ⊢C B : s A≡βB Γ ⊢C t : B

Conv

5

slide-12
SLIDE 12

Expansion Postponement

Γ ⊢C t : A A≡βB Γ ⊢C t : B

Conv

⇒ ⇒ Γ ⊢C t : A A ֒ →∗

β B

Γ ⊢C t : B

Red

Γ ⊢C t : A A ← ֓∗

β B

Γ ⊢C t : B

Exp

Expansion postponement Γ ⊢C t : A ⇔ ∃A′, A ֒ →∗

β A′ ∧ Γ ⊢r C t : A′ 6

slide-13
SLIDE 13

Expansion Postponement

Γ ⊢C t : A A≡βB Γ ⊢C t : B

Conv

⇒ Γ ⊢r

C t : A

A ֒ →∗

β B

Γ ⊢r

C t : B

Red

Expansion postponement Γ ⊢C t : A ⇔ ∃A′, A ֒ →∗

β A′ ∧ Γ ⊢r C t : A′ 6

slide-14
SLIDE 14

Strange Loop 2

Let’s try to prove Expansion Postponement (abstraction case): Γ, x : A ⊢C t : B Γ ⊢C (x : A) → B : s Γ ⊢C λx : A. t : (x : A) → B

λ

?

7

slide-15
SLIDE 15

Strange Loop 2

Let’s try to prove Expansion Postponement (abstraction case): Γ, x : A ⊢C t : B Γ ⊢C (x : A) → B : s Γ ⊢C λx : A. t : (x : A) → B

λ

Γ ⊢r

C (x : A) → B : s

?

7

slide-16
SLIDE 16

Strange Loop 2

Let’s try to prove Expansion Postponement (abstraction case): Γ, x : A ⊢C t : B Γ ⊢C (x : A) → B : s Γ ⊢C λx : A. t : (x : A) → B

λ

Γ, x : A ⊢r

C t : B′

Γ ⊢r

C (x : A) → B : s

?

7

slide-17
SLIDE 17

Strange Loop 2

Let’s try to prove Expansion Postponement (abstraction case): Γ, x : A ⊢C t : B Γ ⊢C (x : A) → B : s Γ ⊢C λx : A. t : (x : A) → B

λ

Γ, x : A ⊢r

C t : B′

Γ ⊢r

C (x : A) → B : s

?

λr

You need subject reduction for Γ ⊢r

C t : (x : A) → B! But... 7

slide-18
SLIDE 18

Strange Loop 2

Let’s try to prove Expansion Postponement (abstraction case): Γ, x : A ⊢C t : B Γ ⊢C (x : A) → B : s Γ ⊢C λx : A. t : (x : A) → B

λ

Γ, x : A ⊢r

C t : B′

Γ ⊢r

C (x : A) → B : s

?

λr

You need subject reduction for Γ ⊢r

C t : (x : A) → B! But...

  • 1. Subject Reduction needs the substitution lemma
  • 2. The substitution lemma needs subject reduction (for the

same reason as above) on the type

7

slide-19
SLIDE 19

Explicit conversion

Γ ⊢C t : A A≡βB Γ ⊢C t : B

Conv

⇓ Γ ⊢e

C t : A

Γ ⊢e

C A≡βB : s

Γ ⊢e

C t : B

Red

8

slide-20
SLIDE 20

Explicit conversion

Γ ⊢C t : A A≡βB Γ ⊢C t : B

Conv

⇓ Γ ⊢e

C t : A

Γ ⊢e

C A≡βB : s

Γ ⊢e

C t : B

Red

Γ ⊢e

C A : s1

Γ ⊢e

C B : s2

Γ ⊢e

C N : A

Γ, x : A ⊢e

C M : B

(s1, s2, s3) ∈ RC Γ ⊢e

C (λx : A. M) N≡βM {x ← N} : B {x ← N}

C ≡β

beta

. . .

8

slide-21
SLIDE 21

Explicit conversion

Γ ⊢C t : A A≡βB Γ ⊢C t : B

Conv

⇓ Γ ⊢e

C t : A

Γ ⊢e

C A≡βB : s

Γ ⊢e

C t : B

Red

Equivalence from implicit to explicit conversion Γ ⊢C t : A ⇔ Γ ⊢e

C t : A 8

slide-22
SLIDE 22

Strange Loop 3

Let’s try to prove the equivalence (conversion case): Γ ⊢C t : A Γ ⊢C B : s A≡βB Γ ⊢C t : B

Conv

9

slide-23
SLIDE 23

Strange Loop 3

Let’s try to prove the equivalence (conversion case): Γ ⊢C t : A Γ ⊢C B : s A≡βB Γ ⊢C t : B

Conv

Γ ⊢e

C t : A

Γ ⊢e

C B : s 9

slide-24
SLIDE 24

Strange Loop 3

Let’s try to prove the equivalence (conversion case): Γ ⊢C t : A Γ ⊢C B : s A≡βB Γ ⊢C t : B

Conv

Γ ⊢e

C t : A

Γ ⊢e

C B : s

We cannot use subject reduction on Γ ⊢C B : s

9

slide-25
SLIDE 25

Strange Loop 3

Let’s try to prove the equivalence (conversion case): Γ ⊢C t : A Γ ⊢C B : s A≡βB Γ ⊢C t : B

Conv

Γ ⊢e

C t : A

Γ ⊢e

C B : s

Γ ⊢e

C A≡βB : s

Γ ⊢e

C t : B

Conve

Instead, it would be easy if we had already proved the equivalence for the types (Γ ⊢e

C A : s and Γ ⊢e C B : s) thanks to

subject reduction.

9

slide-26
SLIDE 26

Strange Loop 3

Let’s try to prove the equivalence (conversion case): Γ ⊢C t : A Γ ⊢C B : s A≡βB Γ ⊢C t : B

Conv

Γ ⊢e

C t : A

Γ ⊢e

C B : s

Γ ⊢e

C A≡βB : s

Γ ⊢e

C t : B

Conve

9

slide-27
SLIDE 27

Levels

We are looking for a measure which is:

  • 1. strictly decreasing from a term t to its type A
  • 2. stable by β
  • 3. stable by subtree

10

slide-28
SLIDE 28

Levels

Lets denote >D: D → D → P, a relation on derivation trees such that 1. Π Γ ⊢C t : A >D Π′ Γ ⊢C A : s (A ∈ S) 2. Π Γ ⊢C t : A ≥D Π′ Γ ⊢C t′ : A (if t ֒ →β t′) 3. Π Γ ⊢C t : A ≥D Π′ Γ′ ⊢C u : B (if Π′ is a subtree of Π) Theorem The existence of >D implies a measure function L : D → O where O is a well-ordered set.

11

slide-29
SLIDE 29

Levels are nice

Theorem If >D exists, then we have the correctness of the CTS encoding into Dedukti Theorem If >D exists, then we have expansion postponement Theorem If >D exists, then we have the equivalence between the implicit and the explicit conversion

12

slide-30
SLIDE 30

Proof of expansion postponement with levels

Theorem The existence of >D implies expansion postponement: Γ ⊢C t : A ⇔ ∃A′, A ֒ →∗

β A′ ∧ Γ ⊢r C t : A′

Proof. By induction given by the measure function L.

  • Base case is trivial (though an induction on the derivation

tree is needed).

  • Inductive case is proved by induction on the derivation tree.

13

slide-31
SLIDE 31

Proving the inductive case

Assuming expansion postponement at level o′, we want to prove expansion postponement at level o (where o >D o′): Γ, x : A ⊢C t : B Γ ⊢C (x : A) → B : s Γ ⊢C λx : A. t : (x : A) → B

λ

Γ, x : A ⊢r

C t : B′

Γ ⊢r

C λx : A. t : (x : A) → B

λr

14

slide-32
SLIDE 32

Proving the inductive case

Assuming expansion postponement at level o′, we want to prove expansion postponement at level o (where o >D o′): Γ, x : A ⊢C t : B Γ ⊢C (x : A) → B : s Γ ⊢C λx : A. t : (x : A) → B

λ

Γ, x : A ⊢r

C t : B′

Γ ⊢r

C λx : A. t : (x : A) → B

λr

  • L(Γ ⊢C (x : A) → B : s) = o1 with o >D o1

14

slide-33
SLIDE 33

Proving the inductive case

Assuming expansion postponement at level o′, we want to prove expansion postponement at level o (where o >D o′): Γ, x : A ⊢C t : B Γ ⊢C (x : A) → B : s Γ ⊢C λx : A. t : (x : A) → B

λ

Γ, x : A ⊢r

C t : B′

Γ ⊢r

C λx : A. t : (x : A) → B

λr

  • L(Γ ⊢C (x : A) → B : s) = o1 with o >D o1
  • L(Γ ⊢C (x : A) → B′ : s) ≤D o1 from second condition of

>D

14

slide-34
SLIDE 34

Proving the inductive case

Assuming expansion postponement at level o′, we want to prove expansion postponement at level o (where o >D o′): Γ, x : A ⊢C t : B Γ ⊢C (x : A) → B : s Γ ⊢C λx : A. t : (x : A) → B

λ

Γ, x : A ⊢r

C t : B′

Γ ⊢r

C (x : A) → B′ : s

Γ ⊢r

C λx : A. t : (x : A) → B

λr

  • L(Γ ⊢C (x : A) → B : s) = o1 with o >D o1
  • L(Γ ⊢C (x : A) → B′ : s) ≤D o1 from second condition of

>D

  • Γ ⊢r

C (x : A) → B′ : s by EP 14

slide-35
SLIDE 35

The big question

Is it possible to find an order >D?

15

slide-36
SLIDE 36

Give it a try!

Instead of giving an order >D, we annotate a judgment with a level. Γ, x : A ⊢n+1

C

t : B Γ ⊢n

C (x : A) → B : s

Γ ⊢n+1

C

λx : A. t : (x : A) → B

λ

Γ ⊢n

C f : (x : A) → B

Γ ⊢n

C a : A

Γ ⊢n

C f a : B {x ← a}

app

16

slide-37
SLIDE 37

A counterexample

In the context Γ:

  • Nat : ⋆ (at level 1)
  • Vec : Nat → ⋆ (at level 2)
  • l : (x : Nat) → Vec x (at level 3)

Assume we have derivation of (3 is the minimum level) Γ ⊢3

C 10 : Nat

  • ne can derive that

Γ ⊢3

C (λx : Nat. l x) 10 : Vec 10

However, there is no derivation of Γ ⊢2

C Vec 10 : ⋆ 17

slide-38
SLIDE 38

A counterexample

In the context Γ:

  • Nat : ⋆ (at level 1)
  • Vec : Nat → ⋆ (at level 2)
  • l : (x : Nat) → Vec x (at level 3)

Assume we have derivation of (3 is the minimum level) Γ ⊢3

C 10 : Nat

  • ne can derive that

Γ ⊢3

C (λx : Nat. l x) 10 : Vec 10

However, there is no derivation of Γ ⊢2

C Vec 10 : ⋆

Levels are not stable by substitution!

17

slide-39
SLIDE 39

Other questions

  • Is it possible to find an order >D? Hard!
  • Is it possible to find an order >D for some specification C ?

easier! (ex: System Fω)

  • Is it possible to find an order >D for a concrete derivation

tree in some specification C ? even easier!

18

slide-40
SLIDE 40

Conclusion

  • We have introduced levels
  • It gives a natural solution to solve hard problems such as:
  • Expansion postponement
  • The equivalence between the explicit and implicit

conversion

  • The existence of levels is not guaranteed for all

specifications C

19

slide-41
SLIDE 41

Future work

Conjecture 1 EP + termination implies the existence of >D. Sufficient to prove the correctness of CTS encoding behind Coq,Agda,Lean in Dedukti

20

slide-42
SLIDE 42

Future work

Conjecture 1 EP + termination implies the existence of >D. Sufficient to prove the correctness of CTS encoding behind Coq,Agda,Lean in Dedukti Conjecture 2 >D exists for every specification C .

20

slide-43
SLIDE 43

Idea

Γ ⊢n

C f : (x : A) → B

Γ ⊢n

C a : A

Γ ⊢n

C f a : B {x ← a}

app

⇓ Γ ⊢n+1

C

f : (x : A) → B Γ ⊢n+1

C

a : A Γ ⊢n

C B {x ← A} : s

Γ ⊢n+1

C

f a : B {x ← a}

app

  • It is better (checked in practice)
  • Not enough since cuts are not taken into account: the

substitution is not applied on intermediate types

21