a nominal syntax for internal parametricity
play

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


  1. A nominal syntax for internal parametricity Thorsten Altenkirch, Ambrus Kaposi University of Nottingham TYPES Meeting, Tallinn 18-21 May 2015

  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¨ of: An intuitionistic theory of types, 1972 Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 2 / 16

  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

  4. External parametricity Specifying a logical relation ◮ The logical relation for a type A: Γ ⊢ A : U Γ ⊢ 0 Γ , 1 Γ : Γ = ⇒ Γ Γ = ⊢∼ A : A [0] → A [1] → U Γ = ⊢ ◮ The context of related elements: · = ≡ · (Γ , x : A ) = ≡ Γ = , x 0 : A [0] , x 1 : A [1] , x 2 : x 0 ∼ A x 1 ◮ Substitutions 0, 1 project out the corresponding components: ≡ () : · ⇒ ∅ i · i Γ , x : A ≡ ( i Γ , x �→ x i ) : (Γ , x : A ) = ⇒ Γ , x : A Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 4 / 16

  5. External parametricity Defining the logical relation Γ ⊢ A : U Γ = ⊢∼ A : A [0] → A [1] → U f 0 ∼ Π( x : A ) . B f 1 ≡ Π( x 0 : A [0] , x 1 : A [1] , x 2 : x 0 ∼ A x 1 ) . f 0 x 0 ∼ B f 1 x 1 ( a , b ) ∼ Σ( x : A ) . B ( a ′ , b ′ ) ≡ Σ( x 2 : a ∼ A a ′ ) . b ∼ B [ x 0 �→ a , x 1 �→ 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

  6. External parametricity Parametricity Γ ⊢ t : A Γ = ⊢ t = : t [0] ∼ A t [1] This can be proven by induction on the term t : ≡ f = u [0] u [1] u = ( f u ) = ( λ x . t ) = ≡ λ x 0 , x 1 , x 2 . t = x = ≡ x 2 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

  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 [R A : 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

  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 = x 0 x 1 x 2 . ◮ We could add a new term former refl = : Γ = ⊢ a 0 : A [0] Γ = ⊢ a 1 : A [1] Γ = ⊢ a 2 : a 0 ∼ A a 1 Γ ⊢ A : U Γ = ⊢ refl = a 0 a 1 a 2 : A == [R = Γ ] a 0 a 1 a 2 a 0 a 1 a 2 (refl a 0 ) (refl a 1 ) Γ = ⊢ refl a 2 : A == [R Γ = ] a 0 a 0 (refl a 0 ) a 1 a 1 (refl a 1 ) a 2 a 2 ◮ 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 = a 0 a 1 a 2 . Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 8 / 16

  9. Internal parametricity Higher dimensions ( x : A ) == can be viewed as a context of squares: ( x : A ) == . x 2 : x 0 ∼ A x 1 ) = ≡ ( x 0 : A [0] . x 1 : A [1] ≡ x 00 : A [00] . x 01 : A [01] . x 02 : x 00 ∼ A [0] x 01 . x 12 : x 10 ∼ A [1] x 11 . x 10 : A [10] . x 11 : A [11] . x 20 : x 00 ∼ A [0] x 10 . x 21 : x 01 ∼ A [1] x 11 . x 22 : x 20 ∼ x 0 ∼ A x 1 x 21 The result of R ( x : A ) = and (R x : A ) = : This can be drawn as: refl x 1 x 21 x 2 x 01 x 11 x 1 x 1 x 0 x 1 refl = x 0 x 1 x 2 x 02 x 22 x 12 x 2 x 2 refl x 2 refl x 0 refl x 1 x 20 refl x 0 x 2 x 00 x 10 x 0 x 0 x 0 x 1 Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 9 / 16

  10. Internal parametricity Adding dimension names = we First we add more information to the contexts: for each usage of − will use a new dimension name, so ( x : A ) == will become ( x : A ) ij : (Γ , x : A ) i ≡ Γ i , x i 0 : A [0 i ] , x i 1 : A [1 i ] , x i 2 : A i x i 0 x i 1 This refines the types of R ( x : A ) = and R = x : A : : ( x : A ) j ⇒ ( x : A ) ji R i ( x : A ) j (R i ( 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

  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. x i 1 j 2 corresponds to x j 2 i 1 . We add the following quotients: ρ : ∆ ⇒ Γ Γ ⊢ t : A Γ ij ≡ Γ ji Γ ij ⊢ t ij ≡ t ji : A ij { x �→ t } ij ρ ij ≡ ρ ji : ∆ ij ⇒ Γ 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. Π( x i 0 j 0 : A [0 i 0 j ] , x i 0 j 1 : A [0 i 1 j ] , x i 0 j 1 : A [0 i ] j x i 0 j 0 x i 0 j 1 , . . . ) . B ij . . . ≡ Π( x i 0 j 0 : A [0 i 0 j ] , x i 0 j 1 : A [0 i 1 j ] , . . . , x j 1 i 0 : ( A j [0 i ] x j 0 i 0 x j 1 i 0 ) . B ji . . . . Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 11 / 16

  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 : U } I Γ ⊢ Π( x : X ) I [ ξ ] . B : U Γ ⊢ Π { x : X } I [ ξ ] . U : U Γ + + ( { x : X } ) I [ ξ ] ⊢ t : B Γ ⊢ λ ( { x : X } { x : X } ) I [ ξ ] . t : Π( ) I [ ξ ] . B Γ ⊢ f : Π( { x : X } ) I [ ξ ] . B Γ ⊢ ω : ( { y : X } ) I [ ξ ] Γ ⊢ app I ( f , ω ) : B [id + + ω ] Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 12 / 16

  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 ⊢ t I : app I ( A I , { x �→ t } I ) The order of dimensions does not matter. Lifting of the universe becomes: U I ≡ λ { X : U } I . Π { x : X } I . U Now we have (refl i a ) j ≡ ( a i [R i Γ ]) j ≡ a ij [R i Γ j ] ≡ a ji [R i Γ j ] ≡ refl i a j , 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

  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 ::= U | (Π( { x : X } ) I [ ρ ] . A )[ ν ] | ( λ ( { x } ) I . t )[ ν ] | n values (whnfs) v n ::= g | app I ( n , ν ) neutral values ::= x | refl i g generic values g Ambrus Kaposi (University of Nottingham) A nominal syntax for internal parametricity May 22, 2015 14 / 16

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend