A nominal syntax for internal parametricity Thorsten Altenkirch, - - PowerPoint PPT Presentation

a nominal syntax for internal parametricity
SMART_READER_LITE
LIVE PREVIEW

A nominal syntax for internal parametricity Thorsten Altenkirch, - - PowerPoint PPT Presentation

A nominal syntax for internal parametricity Thorsten Altenkirch, Ambrus Kaposi University of Nottingham TYPES Meeting, Tallinn 18-21 May 2015 Introduction Parametricity and univalence Parametricity says that terms respect logical


slide-1
SLIDE 1

A nominal syntax for internal parametricity

Thorsten Altenkirch, Ambrus Kaposi University of Nottingham TYPES Meeting, Tallinn 18-21 May 2015

slide-2
SLIDE 2

Introduction

Parametricity and univalence

◮ Parametricity says that terms respect logical relations.

◮ Two functions are related if they map related inputs to related outputs. ◮ Two pairs are related if they are componentwise related. ◮ Two types are related if there is a relation between them.

◮ In homotopy type theory, terms respect equality.

◮ Two functions are equal if they map equal inputs to equal outputs

(function extensionality).

◮ Two pairs are equal if they are componentwise equal. ◮ Two types are equal if there is a relation between them and this

relation is the graph of an equivalence (univalence).

◮ Our goal is to replace intensional equality in type theory by one which

is defined recursively over the type structure.

◮ Inspiration:

◮ Bernardy-Moulin: Internal parametricity, 2012 ◮ Bezem-Coquand-Huber: The cubical sets model of type theory, 2013 ◮ Altenkirch-McBride-Swierstra: Observational type theory, 2007 ◮ Martin-L¨

  • f: An intuitionistic theory of types, 1972

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 2 / 16

slide-3
SLIDE 3

External parametricity

Parametricity

◮ Parametricity says that terms respect logical relations.

A : U, u : A, s : A → A ⊢ t : A ρ0 ≡ (A → N, u → zero, s → suc) ρ1 ≡ (A → Bool, u → true, s → not)

◮ If ρ0 and ρ1 are related, then t[ρ0] is related to t[ρ1]. ◮ It can’t happen that t[ρ0] ≡ suc (suc zero) and t[ρ1] ≡ false.

∼A : N → Bool → U x ∼A b :≡ (x even) is b

◮ A simpler example:

A : U, x : A ⊢ t : A

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 3 / 16

slide-4
SLIDE 4

External parametricity

Specifying a logical relation

◮ The logical relation for a type A:

Γ ⊢ A : U Γ= ⊢∼A: A[0] → A[1] → U Γ ⊢ Γ= ⊢ 0Γ, 1Γ : Γ= ⇒ Γ

◮ The context of related elements:

·= ≡ · (Γ, x : A)= ≡ Γ=, x0 : A[0], x1 : A[1], x2 : x0 ∼A x1

◮ Substitutions 0, 1 project out the corresponding components:

i· ≡ () : · ⇒ ∅ iΓ,x:A ≡ (iΓ, x → xi) : (Γ, x : A)= ⇒ Γ, x : A

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 4 / 16

slide-5
SLIDE 5

External parametricity

Defining the logical relation

Γ ⊢ A : U Γ= ⊢∼A: A[0] → A[1] → U f0 ∼Π(x:A).B f1 ≡ Π(x0 : A[0], x1 : A[1], x2 : x0 ∼A x1).f0 x0 ∼B f1 x1 (a, b) ∼Σ(x:A).B (a′, b′) ≡ Σ(x2 : a ∼A a′).b ∼B [x0 → a, x1 → a′] b′ A ∼U B ≡ A → B → U (parametricity) A ∼U B ≡ A ≃ B (later)

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 5 / 16

slide-6
SLIDE 6

External parametricity

Parametricity

Γ ⊢ t : A Γ= ⊢ t= : t[0] ∼A t[1] This can be proven by induction on the term t: (f u)= ≡ f = u[0] u[1] u= (λx.t)= ≡ λx0, x1, x2 . t= x= ≡ x2 U= ≡∼U (t[ρ])= ≡ t=[ρ=] (ρ= is pointwise) The previous example: (A : U, u : A, s : A → A)= ⊢ t= : t[0] ∼A t[1]

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 6 / 16

slide-7
SLIDE 7

Internal parametricity

Internalisation

◮ The type of param is not well-formed:

· ⊢ param : Π(A : U, t : A).t ∼A t

◮ We need a substitution from (A : U, t : A) to (A : U, t : A)=. ◮ We define RΓ : Γ ⇒ Γ=:

R· ≡ () RΓ.x:A ≡ (RΓ, x, x, refl x) Γ Γ=

RΓ 0Γ 1Γ

Γ ⊢ a : A Γ ⊢ refl a ≡ (a=)[RΓ] : a ∼A [RΓ] a

◮ Now we can define param:

· ⊢ λA, t.refl t : Π(A : U, t : A).t ∼A [RA:U] t

◮ Before adding refl we didn’t extend the theory. Now (refl x) is a new

normal form if x is a variable.

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 7 / 16

slide-8
SLIDE 8

Internal parametricity

Parametricity of parametricity

◮ Given (refl x) as a new normal form, we need to say what (refl x)= is,

i.e. refl= x0 x1 x2.

◮ We could add a new term former refl= :

Γ ⊢ A : U Γ= ⊢ a0 : A[0] Γ= ⊢ a1 : A[1] Γ= ⊢ a2 : a0 ∼A a1 Γ= ⊢ refl= a0 a1 a2 : A==[R=

Γ ] a0 a1 a2 a0 a1 a2 (refl a0) (refl a1)

Γ= ⊢ refl a2 : A==[RΓ=] a0 a0 (refl a0) a1 a1 (refl a1) a2 a2

◮ refl and refl= ways correspond to the two ways of degenerating a line

into a square.

◮ We have refl a ≡ a=[R]. ◮ We don’t know how to compute refl= a0 a1 a2.

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 8 / 16

slide-9
SLIDE 9

Internal parametricity

Higher dimensions

(x : A)== can be viewed as a context of squares: (x : A)== ≡(x0 : A[0] .x1 : A[1] .x2 : x0 ∼A x1)= ≡ x00 : A[00] .x01 : A[01] .x02 : x00 ∼A[0] x01 .x10 : A[10] .x11 : A[11] .x12 : x10 ∼A[1] x11 .x20 : x00 ∼A [0] x10.x21 : x01 ∼A [1] x11.x22 : x20 ∼x0∼Ax1 x21 This can be drawn as: The result of R(x:A)= and (Rx:A)=: x00 x01 x10 x11 x22 x20 x21 x02 x12 x0 x1 x0 x1 refl x2 refl x0 refl x1 x2 x2 x0 x0 x1 x1 refl= x0 x1 x2 x2 x2 refl x0 refl x1

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 9 / 16

slide-10
SLIDE 10

Internal parametricity

Adding dimension names

First we add more information to the contexts: for each usage of −

= we

will use a new dimension name, so (x : A)== will become (x : A)ij: (Γ, x : A)i ≡ Γi, xi0 : A[0i], xi1 : A[1i], xi2 : Ai xi0 xi1 This refines the types of R(x:A)= and R=

x:A:

Ri(x:A)j : (x : A)j ⇒ (x : A)ji (Ri(x:A))j : (x : A)j ⇒ (x : A)ij Their targets are different contexts, with dimensions swapped.

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 10 / 16

slide-11
SLIDE 11

Internal parametricity

A definitional quotient

We would like to equate (x : A)ij and (x : A)ji. These have different variable names, but they contain the same information: eg. xi1j2 corresponds to xj2i1. We add the following quotients: Γij ≡ Γji ρ : ∆ ⇒ Γ ρij ≡ ρji : ∆ij ⇒ Γij Γ ⊢ t : A Γij ⊢ tij ≡ tji : Aij{x → t}ij {x → t}ij is (x → t)ij omitting the last element. Every term former needs to be symmetric, eg. Π types need to know which argument corresponds to which index, because we need (Π(x : A).B)ij ≡ (Π(x : A).B)ji. i.e. Π(xi0j0 : A[0i0j], xi0j1 : A[0i1j], xi0j1 : A[0i]j xi0j0 xi0j1, . . . ).Bij . . . ≡ Π(xi0j0 : A[0i0j], xi0j1 : A[0i1j], . . . , xj1i0 : (Aj[0i] xj0i0 xj1i0).Bji . . . .

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 11 / 16

slide-12
SLIDE 12

Internal parametricity

New rules for Π types

New rules for full Π types and relations (I is a set of dimension names): ξ : Γ ⇒ (X : U)I Γ.(x : X)I[ξ] ⊢ B : U Γ ⊢ Π(x : X)I[ξ].B : U ξ : Γ ⇒ {X : U}I Γ ⊢ Π{x : X}I[ξ].U : U Γ + + ( {x : X} )I[ξ] ⊢ t : B Γ ⊢ λ( {x : X} )I[ξ].t : Π( {x : X} )I[ξ].B Γ ⊢ f : Π( {x : X} )I[ξ].B Γ ⊢ ω : ( {y : X} )I[ξ] Γ ⊢ appI(f , ω) : B[id + + ω]

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 12 / 16

slide-13
SLIDE 13

Internal parametricity

The computation rule of refl=

We generalise the rule for parametricity from adding one dimension to adding a set of dimensions at a time. The parametricity rule becomes: Γ ⊢ t : A ΓI ⊢ tI : appI(AI, {x → t}I) The order of dimensions does not matter. Lifting of the universe becomes: UI ≡ λ{X : U}I.Π{x : X}I.U Now we have (refli a)j ≡ (ai[RiΓ])j ≡ aij[RiΓj] ≡ aji[RiΓj] ≡ refli aj, so the problem with the computation rule of refl= disappears.

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 13 / 16

slide-14
SLIDE 14

Internal parametricity

Operational semantics

To rigorously define the theory, we need telescope contexts and substitutions. We defined a call-by-name operational semantics for this theory where the weak-head normal forms are: t, A ::= . . . terms ν ::= () | (ν, x → g) | (ν, x → t[ν]) environments v ::= U | (Π( {x : X} )I[ρ].A)[ν] | (λ( {x} )I.t)[ν] | n values (whnfs) n ::= g | appI(n, ν) neutral values g ::= x | refli g generic values

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 14 / 16

slide-15
SLIDE 15

Univalence

Capturing univalence

Now we would like to replace the definition of Ui to be a relation which is a graph of an equivalence. We use the following notion of equivalence: (A ∼Ui B) = Σ(∼: A → B → U) .Π(x : A).isContr(Σ(y : B).x ∼ y) × Π(y : B).isContr(Σ(x : A).x ∼ y). The new rule for parametricity expresses that terms respect (cubical) equality (we need to project out the relation): Γ ⊢ t : A ΓI ⊢ tI : appI(∼AI , {x → t}I) Γ ⊢ A : U Γi ⊢ Ai : A[0i] ∼Ui A[1i] However we don’t have Uij ≡ Uji, so we need to refine this definition.

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 15 / 16

slide-16
SLIDE 16

Conclusion

Conclusions

◮ We defined a theory for internal parametricity with an operational

semantics.

◮ We still need to prove termination and completeness of the semantics. ◮ It’s not clear which definition of equivalence to use to capture

univalence in a symmetric way.

◮ The final goal is a type theory with internal parametricity and

univalence where some dimensions are parametricity dimensions and some dimensions are equalities (1-to-1 relations, having Kan fillers). Thank you for your attention!

Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 16 / 16