Eliminating reflection€¦ · reflection 㱺 vec A (S n + m) ... u ≡ v ETT = ITT + reflection...
Transcript of Eliminating reflection€¦ · reflection 㱺 vec A (S n + m) ... u ≡ v ETT = ITT + reflection...
Nicolas Tabareau
Eliminating reflection through reflection
Matthieu Sozeau
Théo Winterhalter
joint work with
EUTypes 2018
Different notions of equality
Conversion Identity typesExtends the notion of β-equality To handle equalities within type theory
(λx.t) u ≡ t[x← u] refl u : u = u
1
Different notions of equality
Conversion Identity typesExtends the notion of β-equality To handle equalities within type theory
(λx.t) u ≡ t[x← u] refl u : u = u
If u ≡ v then refl u : u = v
1
Reflection
Conversion Identity typesExtends the notion of β-equality To handle equalities within type theory
2
Reflection
Conversion Identity typesExtends the notion of β-equality To handle equalities within type theory
p : u = v
u ≡ v
2
Example
3
ExamplevecA : nat → Type
3
ExamplevecA : nat → Type
[] : vecA 0
3
ExamplevecA : nat → Type
[] : vecA 0
cons : ∀ n, A → vecA n → vecA (S n)
3
ExamplevecA : nat → Type
[] : vecA 0
cons : ∀ n, A → vecA n → vecA (S n)
rev : ∀ {n m}, vecA n → vecA m → vecA (n + m)
3
ExamplevecA : nat → Type
[] : vecA 0
cons : ∀ n, A → vecA n → vecA (S n)
rev : ∀ {n m}, vecA n → vecA m → vecA (n + m)
rev [] acc ≐ acc
3
ExamplevecA : nat → Type
[] : vecA 0
cons : ∀ n, A → vecA n → vecA (S n)
rev : ∀ {n m}, vecA n → vecA m → vecA (n + m)
rev [] acc ≐ acc
rev (cons n a v) acc ≐ rev v (cons m a acc)
3
ExamplevecA : nat → Type
[] : vecA 0
cons : ∀ n, A → vecA n → vecA (S n)
rev : ∀ {n m}, vecA n → vecA m → vecA (n + m)
rev [] acc ≐ acc
rev (cons n a v) acc ≐ rev v (cons m a acc)
vecA m 3
ExamplevecA : nat → Type
[] : vecA 0
cons : ∀ n, A → vecA n → vecA (S n)
rev : ∀ {n m}, vecA n → vecA m → vecA (n + m)
rev [] acc ≐ acc
rev (cons n a v) acc ≐ rev v (cons m a acc)
vecA (S m) 3
ExamplevecA : nat → Type
[] : vecA 0
cons : ∀ n, A → vecA n → vecA (S n)
rev : ∀ {n m}, vecA n → vecA m → vecA (n + m)
rev [] acc ≐ acc
rev (cons n a v) acc ≐ rev v (cons m a acc)
vecA (n + S m) 3
ExamplevecA : nat → Type
[] : vecA 0
cons : ∀ n, A → vecA n → vecA (S n)
rev : ∀ {n m}, vecA n → vecA m → vecA (n + m)
rev [] acc ≐ acc
rev (cons n a v) acc ≐ rev v (cons m a acc)
vecA (n + S m)expected: vecA (S n + m) ≠ 3
ExamplevecA : nat → Type
[] : vecA 0
cons : ∀ n, A → vecA n → vecA (S n)
rev : ∀ {n m}, vecA n → vecA m → vecA (n + m)
rev [] acc ≐ acc
rev (cons n a v) acc ≐ rev v (cons m a acc)
vecA (n + S m)reflection ⇒ vecA (S n + m) ≡ 3
Intensional VS Extensionalp : u = v
u ≡ v
ETT = ITT + reflection
4
Intensional VS Extensionalp : u = v
u ≡ v
ETT = ITT + reflection
What is the relation between the two?
4
Intensional VS ExtensionalWhat is the relation between the two?
1995 Martin HofmannETT is conservative over ITT + K + funext
5
Intensional VS ExtensionalWhat is the relation between the two?
1995 Martin HofmannETT is conservative over ITT + K + funext
5
Intensional VS ExtensionalWhat is the relation between the two?
1995 Martin HofmannETT is conservative over ITT + K + funext
K : ∀ A (x : A) (e : x = x), e = refl x
5
Intensional VS ExtensionalWhat is the relation between the two?
1995 Martin HofmannETT is conservative over ITT + K + funext
K : ∀ A (x : A) (e : x = x), e = refl x
funext : ∀ A B (f g : A → B), (∀ (x : A), f x = g x) → f = g
5
Intensional VS ExtensionalWhat is the relation between the two?
2005 Nicolas OuryETT can be translated to ITT + K + funext + ?
K : ∀ A (x : A) (e : x = x), e = refl x
funext : ∀ A B (f g : A → B), (∀ (x : A), f x = g x) → f = g
6
Intensional VS ExtensionalWhat is the relation between the two?
2005 Nicolas OuryETT can be translated to ITT + K + funext + ?
K : ∀ A (x : A) (e : x = x), e = refl x
funext : ∀ A B (f g : A → B), (∀ (x : A), f x = g x) → f = g
‘?’ : « heterogenous equality is a congruence for application »6
Intensional VS ExtensionalWhat is the relation between the two?
TODAYETT can be translated to ITT + K + funext
K : ∀ A (x : A) (e : x = x), e = refl x
funext : ∀ A B (f g : A → B), (∀ (x : A), f x = g x) → f = g
‘?’ : « heterogenous equality is a congruence for application »7
Intensional VS ExtensionalWhat is the relation between the two?
TODAYETT can be translated to ITT + K + funext
K : ∀ A (x : A) (e : x = x), e = refl x
funext : ∀ A B (f g : A → B), (∀ (x : A), f x = g x) → f = g
‘?’ : « heterogenous equality is a congruence for application »7
Intensional VS ExtensionalWhat is the relation between the two?
TODAYETT can be translated to ITT + K + funext
8
Intensional VS ExtensionalWhat is the relation between the two?
TODAYETT can be translated to ITT + K + funext
+ Minimal (axiom-wise)
+ Constructive (formalised in Coq)
+ Computes (produces Coq terms)8
Fundamental differenceOury Hofmann / us
9
Fundamental differenceOury Hofmann / us
Minimal annotations
λ(x : A).t
t u
9
Fundamental differenceOury Hofmann / us
Minimal annotations Fully annotated terms
λ(x : A).t
t u
λ(x : A).B.t
t @(x:A).B u
9
Fundamental differenceOury Hofmann / us
Minimal annotations Fully annotated terms
λ(x : A).t
t u
λ(x : A).B.t
t @(x:A).B u
Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
9
Fundamental differenceOury Hofmann / us
Minimal annotations Fully annotated terms
λ(x : A).t
t u
λ(x : A).B.t
t @(x:A).B u
Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
Free β-reduction
(λ(x : A).t) u≡ t[x := u]
9
Fundamental differenceOury Hofmann / us
Free β-reduction Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
(λ(x : A).t) u≡ t[x := u]
9
Fundamental differenceOury Hofmann / us
Free β-reduction Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
(λ(x : A).x) u≡ x[x := u]
9
Fundamental differenceOury Hofmann / us
Free β-reduction Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
(λ(x : A).x) u≡ u
9
Fundamental differenceOury Hofmann / us
Free β-reduction Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
(λ(x : nat).x) 0 ≡ 0
9
Fundamental differenceOury Hofmann / us
Free β-reduction Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
(λ(x : nat).x) 0 ≡ 0
nat → nat
9
Fundamental differenceOury Hofmann / us
Free β-reduction Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
(λ(x : nat).x) 0 ≡ 0
nat → nat
≡ nat → bool
9
under consistent context
Fundamental differenceOury Hofmann / us
Free β-reduction Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
(λ(x : nat).x) 0 ≡ 0
bool
9
Fundamental differenceOury Hofmann / us
Free β-reduction Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
(λ(x : nat).x) 0 ≡ 0
bool nat
9
Fundamental differenceOury Hofmann / us
Free β-reduction Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
(λ(x : nat).x) 0 ≡ 0
bool nat≠
9
under consistent context
Fundamental differenceOury Hofmann / us
Free β-reduction Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
(λ(x : nat).x) 0 ≡ 0
bool nat≠
No Uniqueness of type
No Subject reductionOR
9
Fundamental differenceOury Hofmann / us
Free β-reduction Blocked β-reduction
(λ(x : A).B.t) @(x:A).B u≡ t[x := u]
(λ(x : nat).x) 0 ≡ 0
bool nat≠
No Uniqueness of type
No Subject reductionOR
Uniqueness of typeandΓ ⊢ t : A Γ ⊢ t : B
⇒ Γ ⊢ A ≡ B 9
Principle of the translationETT ITT
10
Principle of the translationETT ITT
Typing derivation Well typed term
10
Principle of the translationETT ITT
Typing derivation Well typed term
Γ’ ⊢i t’ : A’
Γ ⊢x t : A
… ……… ⋮⋮⋮
10
Principle of the translationETT ITT
Typing derivation Well typed term
Γ’ ⊢i t’ : A’
Γ ⊢x t : A
… ……… ⋮⋮⋮
Idea: Conversion is translated to transport.10
Principle of the translationETT ITT
Typing derivation Well typed term
Γ’ ⊢i t’ : B’
Γ ⊢x t : A
⋮⋮
Idea: Conversion is translated to transport.
Γ ⊢x t : B Γ ⊢x B ≡ A Γ’ ⊢i e : B’ = A’
Γ’ ⊢i transp(e,t’) : A’⇓
10
Principle of the translationETT ITT
Typing derivation Well typed term
Γ’ ⊢i t’ : B’
Γ ⊢x t : A
⋮⋮
Idea: Conversion is translated to transport.
Γ ⊢x t : B Γ ⊢x B ≡ A Γ’ ⊢i e : B’ = A’
Γ’ ⊢i transp(e,t’) : A’⇓
⇒ Coherence problems10
Heterogenous equality
a A=B b
11
Heterogenous equality
a A=B b
≐ ∑ (p : A = B), transp(p,a) = b
11
Terms up to transportt ∼ t’
t ∼ transp(e,t’)
12
Terms up to transportt ∼ t’
t ∼ transp(e,t’) t @(x:A).B u ∼ t’ @(x:A’).B’ u’
t ∼ t’ A ∼ A’ B ∼ B’ u ∼ u’
12
Terms up to transportt ∼ t’
t ∼ transp(e,t’) t @(x:A).B u ∼ t’ @(x:A’).B’ u’
t ∼ t’ A ∼ A’ B ∼ B’ u ∼ u’…
12
Terms up to transportt ∼ t’
t ∼ transp(e,t’) t @(x:A).B u ∼ t’ @(x:A’).B’ u’
t ∼ t’ A ∼ A’ B ∼ B’ u ∼ u’…
t is translated to t’ with t ∼ t’Invariant
12
Terms up to transportt ∼ t’
t ∼ transp(e,t’) t @(x:A).B u ∼ t’ @(x:A’).B’ u’
t ∼ t’ A ∼ A’ B ∼ B’ u ∼ u’…
t is translated to t’ with t ∼ t’Invariant
Given Γ and t ∼ t’, there exists a term p such that if Γ ⊢i t : A and Γ ⊢i t’ : B then Γ ⊢x p : t A=B t’.
Fundamental lemma
12
Translation⊢x Γ ∑ Γᵗ ∼ Γ, ⊢i Γᵗif then
13
Translation⊢x Γ ∑ Γᵗ ∼ Γ, ⊢i Γᵗif then
∀ Γᵗ ∼ Γ, ⊢i Γᵗ → ∑ (tᵗ ∼ t) (Aᵗ ∼ A), Γᵗ ⊢i tᵗ : AᵗΓ ⊢x t : Aif then
13
Translation⊢x Γ ∑ Γᵗ ∼ Γ, ⊢i Γᵗif then
∀ Γᵗ ∼ Γ, ⊢i Γᵗ → ∑ (tᵗ ∼ t) (Aᵗ ∼ A), Γᵗ ⊢i tᵗ : AᵗΓ ⊢x t : Aif then
13
∀ Γᵗ ∼ Γ, ⊢i Γᵗ → ∑ (tᵗ ∼ t) (Aᵗ ∼ A) (uᵗ ∼ u) (Aˢ ∼ A) p,Γ ⊢x t ≡ u : Aif then
Γᵗ ⊢i p : tᵗ Aᵗ=Aˢ uᵗ
Conclusion
ETT ITT + K + funext
Term
Typing derivation
+
Term
Typing derivation
+
Translation relation
+
Translation
Conclusion
ETT ITT + K + funext
Term
Typing derivation
+
Term
Typing derivation
+
Translation relation
+
Translation
HTS Two Level TTOR OR
Conclusion
Coq + K + funextETT ITT + K + funext
Term
Typing derivation+
Term
Typing derivation
+
Translation relation+
Term
Translation Reflection (TemplateCoq)
Coq
Untyped Term
Reflection (TemplateCoq)
HTS Two Level TTOR OR
Conclusion
https://github.com/TheoWinterhalter/ett-to-itt
Coq + K + funextETT ITT + K + funext
Term
Typing derivation+
Term
Typing derivation
+
Translation relation+
Term
Translation Reflection (TemplateCoq)
Coq
Untyped Term
Reflection (TemplateCoq)
HTS Two Level TTOR OR