Naturality for Free The category interpretation of directed type - - PowerPoint PPT Presentation

naturality for free
SMART_READER_LITE
LIVE PREVIEW

Naturality for Free The category interpretation of directed type - - PowerPoint PPT Presentation

Naturality for Free The category interpretation of directed type theory Thorsten Altenkirch, Filippo Sestini Functional Programming Laboratory School of Computer Science University of Nottingham Homotopy Type Theory 2019 Thorsten Altenkirch,


slide-1
SLIDE 1

Naturality for Free

The category interpretation of directed type theory Thorsten Altenkirch, Filippo Sestini

Functional Programming Laboratory School of Computer Science University of Nottingham

Homotopy Type Theory 2019

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 1 / 29

slide-2
SLIDE 2

Types are abstract

This has powerful consequences: Parametricity Polymorphic functions preserve all logical relations. Univalence Isomorphic types are equal. How are these related?

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 2 / 29

slide-3
SLIDE 3

List reversal is natural

List : Set → Set rev :

  • A:Set

List A → List A f : A → B List A List A List B List B

revA List f List f revB

List f ◦ revA = revB ◦ List f

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 3 / 29

slide-4
SLIDE 4

Proof by induction

List f [a0, a1, . . . , an−1] = [f a0, f a1, . . . , f an−1] revA [a0, a1, . . . , an−1] = [an−1, . . . , a1, a0] (revB ◦ List f ) [a0, a1, . . . , an−1] = revB (List f [a0, a1, . . . , an−1]) = revB [f a0, f a1, . . . , f an−1]) = [f an−1, . . . , f a1, f a0]) = List f [an−1, . . . , a1, a0] = List f (revA [a0, a1, . . . , an−1]) = (List f ◦ revA) [a0, a1, . . . , an−1]

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 4 / 29

slide-5
SLIDE 5

Everything is natural . . .

F, G : Set → Set α :

  • A:Set

F A → G A f : A → B F A G A F B G B

αA F f G f αB

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 5 / 29

slide-6
SLIDE 6

. . . but we can’t prove it.

Naturality (parametricity) is a metatheorem, but we cannot prove it internally Solution: extend MLTT with constructs to internalise free theorems (Nuyts et al., Bernardy et al., ...) Can we link this to Univalence/HoTT?

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 6 / 29

slide-7
SLIDE 7

The hint (HoTT)

F, G : Set → Set α :

  • A:Set

F A ≃ G A f : A ≃ B F A G A F B G B

αA F f G f αB

A ≃ B means isomorphism (we work in a set-level setting); This is provable in HoTT, from Univalence + J.

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 7 / 29

slide-8
SLIDE 8

Set-level univalent type theory can be interpreted into the groupoid model (Hofmann & Streicher). The model validates a univalent universe of sets; Idea: replace groupoids with categories; This gives a semantics for a directed type theory with

◮ an internal Hom type; ◮ directed Univalence; Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 8 / 29

slide-9
SLIDE 9

The category with families of categories

Contexts Con : Set Γ : Con [[Γ]] : Cat Types Ty : Con → Set A : Ty Γ [[A]] : [[Γ]] → Cat Terms Tm : (Γ : Con) → Ty Γ → Set a : Tm Γ A [[a]] : Sect [[A]] Substitutions Tms : Con → Con → Set γ : Tms Γ ∆ [[γ]] : [[Γ]] → [[∆]]

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 9 / 29

slide-10
SLIDE 10

Operations on contexts

  • : Con

A : Ty Γ Γ.A : Con [[•]] := 1 |[[Γ.A]]| := (γ : |[[Γ]]|) × |[[A]] γ| [[Γ.A]]((γ, a), (γ′, a′)) := (f : [[Γ]](γ, γ′)) × ([[A]] γ′)([[A]] f a, a′) Grothendieck construction

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 10 / 29

slide-11
SLIDE 11

Opposites

Γ : Con Γ− : Con A : Ty Γ A− : Ty Γ [[Γ−]] := [[Γ]]op [[A−]] := op ◦ [[A]] where op : Cat − → Cat takes C into Cop.

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 11 / 29

slide-12
SLIDE 12

Opposites

Γ : Con Γ− : Con A : Ty Γ A− : Ty Γ [[Γ−]] := [[Γ]]op [[A−]] := op ◦ [[A]] where op : Cat − → Cat takes C into Cop. But what is (Γ.A)− ? Γ−.A− doesn’t typecheck.

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 11 / 29

slide-13
SLIDE 13

Contravariant context extension

A : Ty Γ− Γ.−A : Con |[[Γ.−A]]| := (γ : |[[Γ]]|) × |[[A]] γ| [[Γ.−A]]((γ, a), (γ′, a′)) := (f : [[Γ]](γ, γ′)) × ([[A]] γ)(a, [[A]] f a′) (Γ.A)− = Γ−.−A−

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 12 / 29

slide-14
SLIDE 14

Σ-types

A : Ty Γ B : Ty Γ.A Σ A B : Ty Γ On objects: [[Σ A B]] γ := ([[A]] γ).([[B]] γ)

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 13 / 29

slide-15
SLIDE 15

Σ-types

A : Ty Γ B : Ty Γ.A Σ A B : Ty Γ On objects: [[Σ A B]] γ := ([[A]] γ).([[B]] γ) What about (Σ A B)−?

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 13 / 29

slide-16
SLIDE 16

Σ−-types

A : Ty Γ B : Ty (Γ.A−) Σ− A B : Ty Γ On objects: [[Σ− A B]] γ := ([[A]] γ).−([[B]] γ) (Σ A B)− = Σ− A− B−

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 14 / 29

slide-17
SLIDE 17

Σ-types with polarities

A : Ty Γ B : Ty (Γ.As) Σs A B : Ty Γ M : Tms Γ A N : Tms Γ B[M] M, Ns : Tms Γ (Σs A B) M : Tms Γ (Σs A B) πs

1 M : Tms Γ A

M : Tms Γ (Σs A B) πs

2 M : Tms Γ (B[πs 1 M])

where s = {+, −} and Tm− Γ A ≡ Tm Γ− A−.

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 15 / 29

slide-18
SLIDE 18

Π-types

Groupoid construction of Π generalises to categories... ... but we need to be careful with polarities. A : Ty Γ− B : Ty (Γ.−A) Π A B : Ty Γ

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 16 / 29

slide-19
SLIDE 19

Π-types with polarities

A : Ty Γ− B : Ty (Γ.−As) Πs A B : Ty Γ t : Tms (Γ.−sA) B λs t : Tms Γ (Πs A B) t : Tms Γ (Πs A B) apps t : Tms (Γ.−sA) B (Πs A B)− = Π−s A− B−

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 17 / 29

slide-20
SLIDE 20

Universe of sets

U : Ty Γ A : Tm Γ Us El A : Ty Γs closed under Π, Σ, .... |[[U]] γ| := Set ([[U]] γ)(A, B) := A → B |[[El a]] γ| := [[a]] γ ([[El a]] γ)(y, z) := (y = z) (El A)− = El A

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 18 / 29

slide-21
SLIDE 21

The Hom type

a : Tm Γ A− b : Tm Γ A HomA a b : Ty Γ we also write a ⊑A b for HomA a b. On objects: [[HomA a b]] γ := A γ(a γ, b γ)

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 19 / 29

slide-22
SLIDE 22

The Hom type

a : Tm Γ A− b : Tm Γ A HomA a b : Ty Γ we also write a ⊑A b for HomA a b. On objects: [[HomA a b]] γ := A γ(a γ, b γ) But what about id (aka refl)? We would like to say a : Tm Γ A ida : HomA a a

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 19 / 29

slide-23
SLIDE 23

The Hom type

a : Tm Γ A− b : Tm Γ A HomA a b : Ty Γ we also write a ⊑A b for HomA a b. On objects: [[HomA a b]] γ := A γ(a γ, b γ) But what about id (aka refl)? We would like to say a : Tm Γ A ida : HomA a a but this doesn’t type check!

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 19 / 29

slide-24
SLIDE 24

Core types

A : Ty Γ A : Ty Γ a : Tm Γ ¯ A as : Tm Γ As [[A]] := core ◦ [[A]] a, b : Tm Γ ¯ A f : Tm Γ (a− ⊑A b+) g : Tm Γ (b− ⊑A a+) l : Tm Γ (f ◦ g ⊑ idb) r : Tm Γ (g ◦ f ⊑ ida) f , g, l, r : Tm Γ HomA a b

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 20 / 29

slide-25
SLIDE 25

Some issues with cores

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 21 / 29

slide-26
SLIDE 26

Some issues with cores

Introduction rule? A − → A a : Tm Γ A a : Tm Γ A

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 21 / 29

slide-27
SLIDE 27

Some issues with cores

Introduction rule? A − → A a : Tm Γ A a : Tm Γ A Rules for core contexts? Γ.A ≃ Γ.A[...]

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 21 / 29

slide-28
SLIDE 28

Some issues with cores

Introduction rule? A − → A a : Tm Γ A a : Tm Γ A Rules for core contexts? Γ.A ≃ Γ.A[...] A ∼ = A

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 21 / 29

slide-29
SLIDE 29

Identity morphisms

a : Tm Γ A ida : HomA a− a+

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 22 / 29

slide-30
SLIDE 30

Morphism induction (Js)

a : Tm Γ A b : Tm Γ A M : Ty Γ, x : A, z : HomAsa−s x m : Tm Γ M[x := a+, z := ida] p : Tm Γ HomAs a−s b Js M m p : M[x := b, z := p]

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 23 / 29

slide-31
SLIDE 31

Morphism induction II (J)

a : Tm Γ A b : Tm Γ A M : Ty (Γ, x : A, z : HomA a− x+) m : Tm Γ M[x := a, z := ida] p : Tm Γ (HomA a− b+) J M m p : M[x := b, z := p]

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 24 / 29

slide-32
SLIDE 32

Directed Univalence

A : Tm Γ U− B : Tm Γ U HomU A B = El (A → B)

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 25 / 29

slide-33
SLIDE 33

Directed Univalence

A : Tm Γ U− B : Tm Γ U HomU A B = El (A → B) “Undirected” Univalence follows from the directed one. HomU A B = f : A− → B+, g : B− → A+, +proofs

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 25 / 29

slide-34
SLIDE 34

Every type family is functorial

X : U ⊢ F : U For any A, B : U, f : A− → B+ We can construct ap F f : F[A]− → F[B]+ from directed UA + J

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 26 / 29

slide-35
SLIDE 35

Every polymorphic function is natural

X : U ⊢ F, G : U α :

  • A:U

F[A]− → G[A]+ For any A, B : U f : A− → B+ F[A] G[A] F[B] G[B]

αA ap F f ap G f αB

nat f : HomF[A]−→G[B]+(ap G g ◦ αA) (αB ◦ ap F f ) from directed UA + J

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 27 / 29

slide-36
SLIDE 36

Every polymorphic function is natural

X : U ⊢ F, G : U α :

  • A:U

F[A]− → G[A]+ For any A, B : U f : A− → B+ F[A] G[A] F[B] G[B]

αA ap F f ap G f αB

nat f : HomF[A]−→G[B]+(ap G g ◦ αA) (αB ◦ ap F f ) from directed UA + J (assuming symmetric/core context)

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 27 / 29

slide-37
SLIDE 37

Related work

  • R. Harper & D. Licata, 2-dimensional Directed Type Theory;
  • P. North, Towards a directed Homotopy Type Theory;
  • A. Nuyts, MSc thesis
  • E. Riehl & M. Shulman, A type theory for synthetic ∞-categories (see

also Jonathan Weinberger’s talk);

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 28 / 29

slide-38
SLIDE 38

Future work

Formalisation of the calculus and its semantics in Agda (ongoing); Researching appropriate way to represent symmetric/groupoidal/core contexts; split-context modal type theory seems relevant (see also Dan Licata’s talk); What is the relation to logical relations? Can we do higher categories (full directed HoTT)?

Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 29 / 29