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 jww Filippo Sestini Functional Programming Laboratory School of Computer Science University of Nottingham March 28, 2019 Thorsten Altenkirch jww


slide-1
SLIDE 1

Naturality for Free

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

Functional Programming Laboratory School of Computer Science University of Nottingham

March 28, 2019

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 1 / 24

slide-2
SLIDE 2

The first commandment of Type Theory

Thou shalt not inspect a type!

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 2 / 24

slide-3
SLIDE 3

Consequences of the 1st commandment

Parametricity Polymorphic functions preserve all logical relations. Univalence Isomorphic types are equal. How are these related?

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 3 / 24

slide-4
SLIDE 4

reverse is natural

List : Set → Set rev : ΠA:SetList A → List A f : A → B List A List A List B List B

revA List f List f revB

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 4 / 24

slide-5
SLIDE 5

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 jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 5 / 24

slide-6
SLIDE 6

Everything is natural . . .

F, G : Set → Set α : ΠA:SetF A → G A f : A → B F A G A F B G B

αA F f G f αB

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 6 / 24

slide-7
SLIDE 7

. . . but we can’t prove it.

We know that all families of functions are natural. But we cannot prove it. It should be a free theorem.

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 7 / 24

slide-8
SLIDE 8

The hint (HoTT)

F, G : Set → Set α : ΠA:SetF A ≃ G A f : A ≃ B F A G A F B G B

αA F f G f αB

A ≃ B means isomorphism (for sets). This is provable in HoTT. It follows from univalence + J.

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 8 / 24

slide-9
SLIDE 9

Summary

The set-level fragment of HoTT can be interpreted using the groupoid model (Hofmann & Streicher). This interpretation also gives rise to a univalent, truncated universe of sets (but it doesn’t classify hsets). Can we replace groupoids by categories? Yes, but we need to take care of polarities. And some places we do need groupoids, hence we need an operation calculating the groupoid associated to a category (the core). I am going to derive a type theory guided by the semantics.

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 9 / 24

slide-10
SLIDE 10

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]] : . . . Subst Tms : Con → Con → Set γ : Tms Γ ∆ [[γ]] : [[Γ]] → [[∆]]

[[Γ.A]] [[Γ]]

  • [

[A] ] [ [a] ]

We write [[A]] for the associated opfibration.

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 10 / 24

slide-11
SLIDE 11

Operations on contexts

  • : Con

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

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 11 / 24

slide-12
SLIDE 12

Opposites

Γ : Con Γop : Con A : Ty Γ Aop : Ty Γ [[Γop]] = [[Γ]]op [[Aop]] x = ([[A]] x)op Note that

  • p : Cat → Cat is covariant!

But what is (Γ.A)op ? It cannot be Γop.Aop

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 12 / 24

slide-13
SLIDE 13

Fibrations

A : Ty Γop Γ.opA : Con |[[Γ.opA]]| = (x : |[[Γ|]]) × |[[A]] x| [[Γ.opA]]((x, a), (y, b)) = (f : [[Γ]](x, y)) × ([[A]] x)(a, [[A]] f b) (Γ.A)op = Γop.opAop

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 13 / 24

slide-14
SLIDE 14

Σ-types, undirected

A : Ty Γ B : Ty Γ.A Σ A B : Ty Γ Γ.A.B ∼ = Γ.(Σ A B) On objects: (Σ A B) x = (A x).(B x)

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 14 / 24

slide-15
SLIDE 15

Σ-types with polarities

A : Ty Γ B : Ty Γ.As Σs A B : Ty Γ Γ.As.B ∼ = Γ.(Σs A B) On objects: (Σs A B) x = (A x).s(B x) (Σs A B)op = Σs op Aop Bop

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 15 / 24

slide-16
SLIDE 16

Π-types, undirected

A : Ty Γ B : Ty Γ.A Π A B : Ty Γ Tm Γ.A B ∼ = Tm Γ (Π A B) On objects: |[[Π A B]] x| = Tm (A x) (B x)

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 16 / 24

slide-17
SLIDE 17

Π-types with polarities

A : Ty Γop B : Ty Γ.opAs Πs A B : Ty Γ Tm Γ.opAs B ∼ = Tm Γ (Πs A B) (Π A B)op = Πop Aop Bop On objects: |(Πs A B) x| = Tms (A x) (B x) = Tm (A x)s (B x)s

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 17 / 24

slide-18
SLIDE 18

The universe of sets

U : Ty Γ a : Tm Γ U El a : Ty Γ |[[U]] x| = Set ([[U]] x)(A, B) = A → B |[[El a]] x| = [[a]] x ([[El a]] x)(y, z) = (y = z)

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 18 / 24

slide-19
SLIDE 19

The hom type

a : Tm Γ Aop b : Tm Γ A a ⊑A b : Ty Γ [[a ⊑A b]] x = A x(a x, b x) But what about id (aka refl)? We would like to say a : Tm Γ A ida : a ⊑A a but this doesn’t type check!

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 19 / 24

slide-20
SLIDE 20

The core type

A : Ty Γ ¯ A : Ty Γ a : Tm Γ ¯ A a : Tm Γ As a : Tm Γ ¯ A ida : a ⊑A a a, b : Tm Γ ¯ A f : Tm Γ (a ⊑A b) f op : Tm Γ (b ⊑A a) l : Tm Γ (f ◦ f op ⊑ ida) r : Tm Γ (f op ◦ f ⊑ ida) f , f op, l, r : Tm Γ a ⊑ ¯

A b)

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 20 / 24

slide-21
SLIDE 21

Directed Path induction (J)

A : Ty Γ a : Tm Γ ¯ A M : Ty Γ, x : A, p : a ⊑As x m : Tm Γ M[x = a, p = ida] b : Tm Γ A q : Tm Γ a ⊑As b Js

a M m x p : M[x = b, p = q]

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 21 / 24

slide-22
SLIDE 22

The homtypes of sets

Homtypes of sets are symmetric a : Tm Γ A El a ≃ El a Homtypes of sets are proof irrelevant a : Tm Γ A Ka : Tm Γ (Πa : ¯ A, p : a ⊑A a.p ⊑ id a) Directed univalence a ⊑A b ≡ El a → El b

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 22 / 24

slide-23
SLIDE 23

Everything is natural, provably!

F, G : Set → Set α : ΠA:SetF A → G A f : A → B F A G A F B G B

αA F f G f αB

It follows from directed univalence + directed J.

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 23 / 24

slide-24
SLIDE 24

Further work

Filippo is formalising the calculus and its semantics in Agda. What is the relation to logical relations? Can we do higher categories (full directed HoTT)?

Thorsten Altenkirch jww Filippo Sestini (Nottingham) Naturality for Free March 28, 2019 24 / 24