MODAL HOMOTOPY TYPE SYSTEM
The HTS [1] language proposed by Voevodsky exposes two different presheaf models of type theory: the inner one is homotopy type system presheaf that models HoTT and the outer one is traditional Martin-Löf type system presheaf that models set theory with UIP. The motivation behind this doubling is to have an ability to express semisemplicial types. Theoretical work on merging inner and outer languages was continued in 2LTT [2,3].
$ opam install anders
Anders is fast, idiomatic and educational. We carefully draw the favourite Lean-compatible syntax to fit 200 LOC in Menhir. The CHM kernel is 1K LOC. Whole Anders compiles under 1 second and checks all the base library under 1/3 of a second [i5-12400]. Anders proof assistant as Homotopy Type System comes with its own Homotopy Library.
$ anders help
Anders Proof Assistant version 1.4.0
Copyright © 2021-2022 Groupoid Infinity
https://anders.groupoid.space/lib/
invocation = anders | anders list
list = [] | command list
primitive = zero | one | interval
command = check <filename> | lex <filename>
| parse <filename> | prim primitive <name>
| cubicaltt <filename> | girard
| trace | verbose
| repl | help
SYNTAX
The syntax resembles original syntax of the reference CCHM type checker cubicaltt, is slightly compatible with Lean syntax and contains the full set of Cubical Agda [10] primitives (except generic higher inductive schemes).
Here is given the mathematical pseudo-code notation
of the language expressions that come immediately after parsing.
The core syntax definition of HTS language
Further Menhir BNF notation will be used to describe the top-level language parser as type checker is written in OCaml.
(, ), [, ], <, >, /, .1, .2, Π, Σ, λ, ×, →,
:, :=, ↦, U, V, ∧, ∨, -, +, @, module, where, import,
option, def, axiom, inc, postulate, theorem, PathP,
transp, hcomp, zero, one, Partial, ouc, interval, W,
sup, Glue, glue, unglue, ind₀, ind₁, ind₂, indᵂ
¬-of-∨, 1=1, is-?, =, $^~]!005x, ∞, x→Nat, f'
%start <Module.file> file
%start <Module.command> repl
repl : COLON IDENT exp1 EOF | COLON IDENT EOF | exp0 EOF | EOF
file : MODULE IDENT WHERE line* EOF
path : IDENT
line :
| IMPORT path+
| OPTION IDENT IDENT
| declarations
In Anders you can enable or disable language core types, adjust syntaxes or tune inner variables of the type checker. Here is the example how to setup minimal core able to prove internalization of MLTT-73 variation (Path instead of Id and no inductive types, see base library):
ident : IRREF | IDENT
vars : ident+
lense : LPARENS vars COLON exp1 RPARENS
telescope : lense telescope
params : telescope | []
declarations:
| DEF IDENT params DEFEQ exp1
| DEF IDENT params COLON exp1 DEFEQ exp1
| AXIOM IDENT params COLON exp1
Sample declarations. For example, signature isProp (A : U) of type U could be defined as normalization-blocking axiom without proof-term or by providing proof-term as definition.
axiom isProp (A : U) : U
def isSet (A : U) : U := Π (a b : A)
(x y : Path A a b), Path (Path A a b) x y
In this example (A : U), (a b : A) and (x y : Path A a b) are called telescopes. Each telescope consists of a series of lenses or empty. Each lense provides a set of variables of the same type. Telescope defines parameters of a declaration. Types in a telescope, type of a declaration and a proof-terms are a language expressions exp1.
face : LPARENS IDENT IDENT IDENT RPARENS
partial : face+ ARROW exp1
exp0 :
| exp1 COMMA exp0
| exp1
exp1:
| LAM telescope COMMA exp1
| PI telescope COMMA exp1
| SIGMA telescope COMMA exp1
| LSQ IRREF ARROW exp1 RSQ
| LSQ separated_list(COMMA, partial) RSQ
| LT vars GT exp1
| exp2 ARROW exp1
| exp2 PROD exp1
| exp2
The LR parsers demand to define exp1 as expressions that cannot be used (without a parens enclosure) as a right part of left-associative application for both Path and Pi lambdas.
exp2 :
| exp2 exp3
| exp2 APPFORMULA exp3
| exp3
Universe indices Uj (inner fibrant) and Vk (outer pretypes) are using unicode subscript letters that are already processed in lexer.
exp3:
| HOLE | PRE
| KAN | exp3 FST
| exp3 SND | NEGATE exp3
| exp3 AND exp3 | exp3 OR exp3
| ID exp3 | REF exp3
| IDJ exp3 | INC exp3
| OUC exp3 | PATHP exp3
| TRANSP exp3 exp3 | HCOMP exp3
| PARTIAL exp3 | IDENT LSQ exp0 MAP exp0 RSQ
| LPARENS exp0 RPARENS | IDENT
| LPARENS exp0 RPARENS LSQ exp0 MAP exp0 RSQ
SEMANTICS
The idea is to have a unified layered type checker, so you can disbale/enable any MLTT-style inference, assign types to universes and enable/disable hierachies. This will be done by providing linking API for pluggable presheaf modules. We selected 5 levels of type checker awareness from universes and pure type systems up to synthetic language of homotopy type theory. Each layer corresponds to its presheaves with separate configuration for universe hierarchies.
inductive lang : U
| UNI: cosmos → lang
| PI: pure lang → lang
| SIGMA: total lang → lang
| ID: uip lang → lang
| PATH: homotopy lang → lang
| GLUE: gluening lang → lang
| HIT: hit lang → lang
We want to mention here with homage to its authors all categorical models of dependent type theory: Comprehension Categories (Grothendieck, Jacobs), LCCC (Seely), D-Categories and CwA (Cartmell), CwF (Dybjer), C-Systems (Voevodsky), Natural Models (Awodey). While we can build some transports between them, we leave this excercise for our The Cubical Base Library library.
We will use here the Coquand’s notation for Presheaf Type Theories in terms of restriction maps.
Universe Hierarchies
in which
inductive cosmos : U
| prop: nat → cosmos
| fibrant: nat → cosmos
| pretypes: nat → cosmos
| strict: nat → cosmos
| omega: cosmos
| lock: cosmos
Dependent Types
We think of
inductive pure (lang: U) : U
| var: name → nat → pure lang
| pi: name → nat → lang → lang → pure lang
| lambda: name → nat → lang → lang → pure lang
| app: lang → lang → pure lang
inductive total (lang: U) : U
| sigma: name → lang → lang → total lang
| pair: lang → lang → total lang
| fst: lang → total lang
| snd: lang → total lang
The preseaf configuration with only Pi and Sigma is called MLTT-72.
Path Equality
The fundamental development of equality inside MLTT provers led us to the notion of ∞-groupoid as spaces. In this way Path identity type appeared in the core of type checker along with De Morgan algebra on built-in interval type.
inductive homotopy (lang: U) : U
| PathP: lang → lang → lang → homotopy lang
| plam: name → lang → lang → homotopy lang
| papp: lang → lang → homotopy lang
| I: homotopy lang
| zero: homotopy lang
| one: homotopy lang
| meet: lang → lang → homotopy lang
| join: lang → lang → homotopy lang
| neg: lang → homotopy lang
| system: lang → homotopy lang
| Partial: lang → homotopy lang
| transp: lang → lang → homotopy lang
| hcomp: lang → homotopy lang
| Sub: lang → homotopy lang
| inc: lang → homotopy lang
| ouc: lang → homotopy lang
theorem Path-β (A : U) (a : A) (C : D A) (d: C a a (refl A a))
: Equ (C a a (refl A a)) d (J A a C d a (refl A a))
:= λ (A : U), λ (a : A), λ (C : Π (x : A), Π (y : A), PathP (<_> A) x y → U),
λ (d : C a a (<_> a)), <j> transp (<_> C a a (<_> a)) -j d
Transport is defined on fibrant types (only) and type checker should cover all the cases. Note that transpⁱ (Pathʲ A v w) φ u₀ case is relying on comp operation which depends on hcomp primitive.
transpⁱ N φ u₀ = u₀
transpⁱ U φ A = A
transpⁱ (Π (x : A), B) φ u₀ v = transpⁱ B(x/w) φ (u₀ w(i/0))
transpⁱ (Σ (x : A), B) φ u₀ = (transpⁱ A φ (u₀.1),transpⁱ B(x/v) φ(u₀.2))
transpⁱ (Pathʲ A v w) φ u₀ = 〈j〉compⁱ A [φ ↦ u₀ j, (j=0) ↦ v, (j=1) ↦ w] (u₀ j)
transpⁱ (Glue [φ ↦ (T,w)] A) ψ u₀ = glue [φ(i/1) ↦ t′₁] a′₁ : B(i/1)
w = transpFill⁻ⁱ A φ v, v : A(i/1)
v = transpFillⁱ A φ u₀.1
u : A(j/0), v : A(j/1)
transp⁻ⁱ A φ u = (transpⁱ A(i/1−i) φ u)(i/1−i) : A(i/0)
transpFillⁱ A φ u₀ = transpʲ A(i/i∧j) (φ∨(i=0)) u₀ : A
def Partial′ (A : U) (i : I) := Partial A i
def isOne : I -> V := Id I 1
def 1=>1 : isOne 1 := ref 1
def UIP (A : V) (a b : A) (p q : Id A a b) : Id (Id A a b) p q := ref p
def sub′ (A : U) (i : I) (u : Partial A i) : V := A [i ↦ u ]
def inc′ (A : U) (i : I) (a : A) : A [i ↦ [(i = 1) → a]] := inc A i a
def ouc′ (A : U) (i : I) (u : Partial A i) (a : A [i ↦ u]) : A := ouc a
We have forth and back fusion rules ouc (inc v) = v and inc (outc v) = v. Moreover, ouc v will reduce to u 1=1 when i=1.
def comp (A : I → U) (r : I) (u : Π (i : I), Partial (A i) r) (u₀ : (A 0)[r ↦ u 0]) : A 1
:= hcomp (A 1) r (λ (i : I), [(r = 1) → transp (<j> A (i ∨ j)) i (u i 1=>1)])
(transp (<i> A i) 0 (ouc u₀))
The type checker equations for hcomp primitive are following:
hcompⁱ N [φ ↦ 0] 0 = 0
hcompⁱ N [φ ↦ S u] (S u₀) = S (hcompⁱ N [φ ↦ u] u₀)
hcompⁱ U [φ ↦ E] A = Glue [φ ↦ (E(i/1), equivⁱ E(i/1−i))] A
hcompⁱ (Π (x : A), B) [φ ↦ u] u₀ v = hcompⁱ B(x/v) [φ ↦ u v] (u₀ v)
hcompⁱ (Σ (x : A), B) [φ ↦ u] u₀ = (v(i/1), compⁱ B(x/v) [φ ↦ u.2] u₀.2)
hcompⁱ (Pathʲ A v w) [φ ↦ u] u₀ = 〈j〉 hcompⁱ A [ φ ↦ u j, (j = 0) ↦ v, (j = 1) ↦ w ] (u₀ j)
hcompⁱ (Glue [φ ↦ (T,w)] A) [ψ ↦ u] u₀
= glue [φ ↦ t₁] a₁
= glue [φ ↦ u(i/1)] (unglue u(i/1))
= u(i/1) : Glue [φ ↦ (T,w)] A
hfillⁱ A [φ ↦ u] u₀ = hcompʲ A [φ ↦ u(i/i∧j), (i=0) ↦ u₀] u₀ : A
v = hfillⁱ A [φ ↦ u.1] u₀.1
t₁ = u(i/1) : T
a₁ = unglue u(i/1) : A
glue [φ ↦ t₁] a1 = t₁ : T
Strict Equality
To avoid conflicts with path equalities which live in fibrant universes strict equalities live in pretypes universes.
inductive strict (lang: U) : U
| Id: name → lang → total lang
| ref: lang → lang → total lang
| idJ: lang → lang → lang → total lang
We use strict equality in Anders for pretypes and partial elements which live in V. The presheaf configuration with Pi, Sigma and Id is called MLTT-73. The presheaf configuration with Pi, Sigma, Id and Path is called HTS.
Glue Types
The main purpose of Glue types is to construct a cube where some faces have been replaced by equivalent types. This is analogous to how hcomp lets us replace some faces of a cube by composing it with other cubes, but for Glue types you can compose with equivalences instead of paths. This implies the univalence principle and it is what lets us transport along paths built out of equivalences.
inductive gluening (lang: U) : U
| Glue: lang → lang → lang → gluening lang
| glue: lang → lang → gluening lang
| unglue: lang → lang → gluening lang
Generic Higher Inductive Schemes
The further development of induction inside MLTT provers led to the theory of polynomial functors and well-founded trees, known in programming languages as inductive types.
Inductive types could be encoded in PTS/Cedile using non-recursive representation of Bohm-Berarducci schemes or with categorical impredicative encoding by Steve Awodey.
Anders currently don’t support Lean-compatible generic inductive schemes definition but in case it will the following AST occurs:
inductive tele (A: U) : U | emp: tele A | tel: name → A → tele A → tele A
inductive branch (A: U) : U | br: name → branch A | args: list name → A → branch A
inductive label (A: U) : U | lab: name → label A | t: tele A → label A
inductive hit (lang: U)
| form: name → tele lang → list (label lang) → hit lang
| ctor: name → list lang → hit lang
| htor: name → list lang → list lang → lang → hit lang
| case: name → lang → list (branch lang) → hit lang
So instead of generic inductive schemes Anders supports well-founded trees (W-types). Basic data types like List, Nat, Fin, Vec are implemented as W-types in base library. As for higher inductive types Anders has Three-HIT basis (Coequalizer, HubSpoke and Colimit) to express other HIT.
The non-well-founded trees (M-types) or infinite coinductive trees are useful for modeling infinite processes and are part of Milner’s Pi-calculus. Coinductive streams could be found in many MLTT base libraries.
Bibliography
HTS
1) A simple type system with two identity types [Voevodsky]. 2) Two-level type theory and applications [Annenkov, Capriotti, Kraus, Sattler]. 3) Syntax for two-level type theory [Bonacina, Ahrens].
CCHM
4) Cubical Type Theory: a constructive interpretation of the univalence axiom [Cohen, Coquand, Huber, Mörtberg]; 5) On Higher Inductive Types in Cubical Type Theory [Coquand, Huber, Mörtberg]; 6) Canonicity for Cubical Type Theory [Huber]; 7) Canonicity and homotopy canonicity for cubical type theory [Coquand, Huber, Sattler]; 8) Cubical Synthetic Homotopy Theory [Mörtberg, Pujet]; 9) Unifying Cubical Models of Univalent Type Theory [Cavallo, Mörtberg, Swan]; 10) Cubical Agda: A Dependently Typed PL with Univalence and HITs [Vezzosi, Mörtberg, Abel]; 11) A Cubical Type Theory for Higher Inductive Types [Huber]; 12) Gluing for type theory [Kaposi, Huber, Sattler]. 13) Cubical Methods in HoTT/UF [Mörtberg].
MLTT
14) Intuitionistic Type Theory [Martin-Löf]; 15) An intuitionistic theory of types: predicative part. [Martin-Löf]; 16) Programming in Martin-Löf’s Type Theory [Nordström, Petersson, Smith]; 17) A simple type-theoretic language: Mini-TT [Coquand, Kinoshita, Nordström, Takeyama];
Modal HoTT
18) Differential cohomology in a cohesive ∞-topos [Schreiber]. 19) Cartan Geometry in Modal Homotopy Type Theory [Cherubini]. 20) Differential Cohesive Type Theory [Gross, Licata, New, Paykin, Riley, Shulman, Cherubini]. 21) Brouwer’s fixed-point theorem in real-cohesive homotopy type theory [Shulman].
🧊
This work was sponsored by