Towards a theory of higher inductive types

Towards a theory of higher inductive types
Thorsten Altenkirch1 Paolo Capriotti1 Gabe Dijkstra1
Fredrik Nordvall Forsberg2
1 University
of Nottingham
2 University
of Strathclyde
May 20th, 2015
Towards a theory of HITs
May 20th, 2015
1 / 22
Goal
Our is goal is to:
Define a general class of higher inductive types
Akin to W-types
Building upon Shulman and Lumsdaine’s semantics
Towards a theory of HITs
May 20th, 2015
2 / 22
Higher inductive types versus ordinary inductive types
Ordinary inductive types:
data T : Type where
c0 : F0 T → T
..
.
ck : Fk T → T
where every Fi : Type → Type is a (strictly positive) functor.
Towards a theory of HITs
May 20th, 2015
3 / 22
Higher inductive types versus ordinary inductive types
Ordinary inductive types:
data T : Type where
c : F0 T + . . . + Fk T → T
..
.
where every Fi : Type → Type is a (strictly positive) functor.
Towards a theory of HITs
May 20th, 2015
3 / 22
Higher inductive types versus ordinary inductive types
Ordinary inductive types:
data T : Type where
c :F T →T
..
.
where F : Type → Type is a (strictly positive) functor.
Towards a theory of HITs
May 20th, 2015
3 / 22
Higher inductive types versus ordinary inductive types
Higher inductive types, e.g. the circle:
data S 1 : Type where
base : S 1
loop : base =S 1 base
Dependencies on previous constructors
Higher constructors: target of constructors not always T , but can also
be an iterated path space of T .
Single functor Type → Type no longer suffices
Towards a theory of HITs
May 20th, 2015
4 / 22
Higher inductive types versus ordinary inductive types
Higher inductive types, e.g. propositional truncation:
data||A|| : Type where
[ ] : A → ||A||
trunc : (x y : ||A||) → x = y
Dependencies on previous constructors
Higher constructors: target of constructors not always T , but can also
be an iterated path space of T .
Single functor Type → Type no longer suffices
Towards a theory of HITs
May 20th, 2015
4 / 22
General framework
Constructors are dependent dialgebras:
data T : Type where
c0 : (x : F0 T )
c1 : (x : F1 (T , c0 ))
..
.
→ G0 (T , x)
→ G1 ((T , c0 ), x)
ck : (x : Fk (T , c0 , . . . , ck−1 )) → Gk ((T , c0 , . . . , ck−1 ), x)
We will call:
Every Fi an argument functor
Every Gi a target functor
Towards a theory of HITs
May 20th, 2015
5 / 22
General framework – example: interval
The interval type:
data I : Type where
zero : I
one : I
seg : zero = one
Argument functors:
F0 X
F1 (X , z)
F2 (X , z, o)
:≡ 1
:≡ 1
:≡ 1
(F0 : Type
→ Type)
(F1 : (F0 , G0 )-alg → Type)
(F2 : (F1 , G1 )-alg → Type)
Target functors:
R
F0 → Type)
(G0 : Type
R
(G1 : (F0 ,G1 )-alg F1 → Type)
R
G2 ((X , z, o), x) :≡ (z = o) (G2 : (F1 ,G1 )-alg F2 → Type)
G0 (X
G1 ((X , z)
, x) :≡ X
, x) :≡ X
Towards a theory of HITs
May 20th, 2015
6 / 22
General framework – example: interval
The interval type:
data I : Type where
zero : I
one : I
seg : zero = one
Category of elements:
objects:
(X : Type) × F0 X
morphisms (X , x) → (Y , y ):
(f : X → Y ) × (F0 f x = y )
Argument functors:
F0 X
F1 (X , z)
F2 (X , z, o)
:≡ 1
:≡ 1
:≡ 1
(F0 : Type
→ Type)
(F1 : (F0 , G0 )-alg → Type)
(F2 : (F1 , G1 )-alg → Type)
Target functors:
R
F0 → Type)
(G0 : Type
R
(G1 : (F0 ,G1 )-alg F1 → Type)
R
G2 ((X , z, o), x) :≡ (z = o) (G2 : (F1 ,G1 )-alg F2 → Type)
G0 (X
G1 ((X , z)
, x) :≡ X
, x) :≡ X
Towards a theory of HITs
May 20th, 2015
6 / 22
General framework
Constructors are dependent dialgebras:
c : (x : F X ) → G (X , x)
where
C : Cat
F : C → Type (argument functor)
R
G : C F → Type (target functor)
Towards a theory of HITs
May 20th, 2015
7 / 22
General framework – 0-constructors
0-constructors are of the form:
c : (x : F X ) → U X
where
C : Cat with a forgetful functor U : C → Type
F : C → Type
R
G : C F → Type
G (X , x) :≡ U X
Towards a theory of HITs
May 20th, 2015
8 / 22
General framework – 1-constructors
1-constructors are of the form:
c : (x : F X ) → (l0 X x = r0 X x)
where
C : Cat with a forgetful functor U : C → Type
F : C → Type
R
G : C F → Type
l0 r0 : F → U
G (X , x) :≡ (l0 X x = r0 X x)
We call this G functor Eq0
Towards a theory of HITs
May 20th, 2015
9 / 22
General framework – 2-constructors
For 2-constructors:
c : (x : F X ) → (l1 X x = r1 X x)
where
l0 r0 : F → U
(with Eq0 (X , x) :≡ (l0 X x = r0 X x))
l1 r1 : 1 → Eq0
(with Eq1 (X , x) :≡ (l1 X x = r1 X x))
Towards a theory of HITs
May 20th, 2015
10 / 22
General framework – 3-constructors
For 3-constructors:
c : (x : F X ) → (l2 X x = r2 X x)
where
l0 r0 : F → U
(with Eq0 (X , x) :≡ (l0 X x = r0 X x))
l1 r1 : 1 → Eq0
(with Eq1 (X , x) :≡ (l1 X x = r1 X x))
l2 r2 : 1 → Eq1
(with Eq2 (X , x) :≡ (l2 X x = r2 X x))
Towards a theory of HITs
May 20th, 2015
10 / 22
General framework – (n + 1)-constructors
For (n + 1)-constructors:
c : (x : F X ) → (ln X x = rn X x)
where
l0 r0 : F → U
(with Eq0 (X , x) :≡ (l0 X x = r0 X x))
l1 r1 : 1 → Eq0
(with Eq1 (X , x) :≡ (l1 X x = r1 X x))
l2 r2 : 1 → Eq1
(with Eq2 (X , x) :≡ (l2 X x = r2 X x))
..
.
ln rn : 1 → Eqn−1
..
.
(with Eqn (X , x) :≡ (ln X x = rn X x))
Towards a theory of HITs
May 20th, 2015
10 / 22
Strict positivity – ordinary inductive types
We can’t allow any argument functor: it has to be strictly positive:
data Term : Type where
lam : (Term → Term) → Term
Towards a theory of HITs
May 20th, 2015
11 / 22
Strict positivity – higher inductive types
We can’t allow any argument functor: it has to be strictly positive:
data InitialField : Type where
0
: InitialField
1
: InitialField
_+_ : InitialField → InitialField → InitialField
_∗_ : InitialField → InitialField → InitialField
..
.
_−1 : (x : InitialField ) → (x = 0 → ⊥) → InitialField
..
.
InitialField does not exist: _−1 is not strictly positive
Towards a theory of HITs
May 20th, 2015
12 / 22
Type-containers
Strictly positive functors Type → Type: containers
Shapes S : Type
Positions T : S → Type
JS C PK0 : C → Type
JS C PK0 X :≡ (s : S) × (P s → X )
JS C PK1 : (X → Y ) → JS C PK0 X → JS C PK0 Y
JS C PK1 f (s, t) :≡ (s, f ◦ t)
Example:
constA X = JA C (λa.0)K0 X
= A × (0 → X )
=A
Towards a theory of HITs
May 20th, 2015
13 / 22
C-containers
Strictly positive functors C → Type: C-containers (or familially
representable)
Shapes S : Type
Positions T : S → |C|
JS C PK0 : C → Type
JS C PK0 X :≡ (s : S) × C (P s, X )
JS C PK1 : C (X , Y ) → JS C PK0 X → JS C PK0 Y
JS C PK1 f (s, t) :≡ (s, f ◦ t)
Example (assuming 0 : |C| is initial):
constA X = JA C (λa.0)K0 X
= A × C (0, X )
=A
Towards a theory of HITs
May 20th, 2015
14 / 22
C-container morphisms
Data for higher constructors requires natural transformations
Natural transformations between containers: container morphisms:
For containers S C P and T C Q, container morphisms are:
(f : S → T )
× (g : (a : S) → C (Q (f a), P a))
Container morphisms are complete:
Each container morphism gives rise to a natural transformation and
vice versa
Towards a theory of HITs
May 20th, 2015
15 / 22
Expressivity of containers
Data for constructors can be given using containers and container
morphisms:
Argument functors are given as containers
Forgetful functors Ui : (Fi , Gi )-alg → Type can be given as containers
if there exist Li a Ui
Data for Eqn functors are given as container morphisms
Eqn functors can be given as containers if we have (n + 1)-HITs
Towards a theory of HITs
May 20th, 2015
16 / 22
Simplified approach to 1-HITs
In practice, constructor arguments rarely seem to refer to previous
constructors.
We can identify a class of 1-HITs where we have:
0-constructors which do not depend on other constructors
1-constructors which may only depend on 0-constructors in the targets
No dependencies between the 1-constructors
Examples: circle, suspension, truncation
Non-example: hub-spokes version of the torus
Towards a theory of HITs
May 20th, 2015
17 / 22
Simplified approach to 1-HITs
If we have:
F0 : Type → Type with U0 : (F0 , G0 )-alg → Type
F1 : (F0 , G0 )-alg → Type such that F1 = F10 ◦ U0
. . . where F10 : Type → Type
then
F1 → U0 ' F10 → F0∗
where F0∗ is the free monad of F0 .
This approach has been fully formalised in Agda.
Towards a theory of HITs
May 20th, 2015
18 / 22
Coherence
We can use C-containers to internalise the theory
We still need to be able to talk about the categories of dependent
dialgebras
Towards a theory of HITs
May 20th, 2015
19 / 22
Coherence – Category of dependent dialgebras
Given C a category with functors F : C → Type and G :
can consider the category of dialgebras (F , G )-alg:
R
C
F → Type, we
objects:
(X : |C|)
× (θ : (x : F X ) → G (X , x))
morphisms (X , θ) → (Y , ρ):
(f : C (X , Y ))
× (comm : (x : F X ) → G (f , refl ) (θ x) = ρ (F f x))
Towards a theory of HITs
May 20th, 2015
20 / 22
Coherence
We can use C-containers to internalise the theory
We still need to be able to talk about the categories of dependent
dialgebras
Design choices:
Define the categories with strict equality and possibly lose some
expressivity (e.g. the torus)
Work with appropriately defined (∞, 1)-categories and deal with the
coherence issues, that increase with the number of constructors
Towards a theory of HITs
May 20th, 2015
21 / 22
Conclusions
Higher inductive types are sequences of dependent dialgebras
C-containers allow us to formalise the data needed to define
constructors
A simplified approach to 1-HITs has been successfully formalised
Coherence problems increase with the number of constructors
We can work in a type theory with strict equality and avoid coherence
problems but we lose some expressivity
Towards a theory of HITs
May 20th, 2015
22 / 22