<filename>doc/anders.tex<gh_stars>100-1000
\documentclass[a4paper,UKenglish,cleveref, autoref, thm-restate]{lipics-v2021}
\bibliographystyle{plainurl}
\title{Homotopy Type System with Strict Equality}
\titlerunning{CCHM/HTS}
\author{<NAME>}{Groupoid Infinity}{<EMAIL>}{https://orcid.org/0000-0001-7127-8796}{}
\author{Siegmentation Fault}{Groupoid Infinity}{<EMAIL>}{}{}
\authorrunning{<NAME> and Siegmentation Fault} %TODO mandatory. First: Use abbreviated first/middle names. Second (only in severe cases): Use first author plus 'et al.'
\Copyright{<NAME> and Siegmentation Fault} %TODO mandatory, please use full first names. LIPIcs license is "CC-BY";  http://creativecommons.org/licenses/by/3.0/

\begin{CCSXML}
<ccs2012>
<concept>
<concept_id>10003752.10003753.10003754.10003733</concept_id>
<concept_desc>Theory of computation~Lambda calculus</concept_desc>
<concept_significance>300</concept_significance>
</concept>
</ccs2012>
\end{CCSXML}

\ccsdesc[300]{Theory of computation~Lambda calculus}
\keywords{Homotopy Type System, Cubical Type Theory}

%\category{} %optional, e.g. invited paper

%\relatedversion{https://groupoid.space/anders.pdf} %optional, e.g. full version hosted on arXiv, HAL, or other respository/website
%\relatedversiondetails[linktext={opt. text shown instead of the URL}, cite=DBLP:books/mk/GrayR93]{Classification (e.g. Full Version, Extended Version, Previous Version}{URL to related version} %linktext and cite are optional
%\supplement{}%optional, e.g. related research data, source code, ... hosted on a repository like zenodo, figshare, GitHub, ...
%\supplementdetails[linktext={opt. text shown instead of the URL}, cite=DBLP:books/mk/GrayR93, subcategory={Description, Subcategory}, swhid={Software Heritage Identifier}]{General Classification (e.g. Software, Dataset, Model, ...)}{URL to related version} %linktext, cite, and subcategory are optional
%\funding{(Optional) general funding statement \dots}%optional, to capture a funding statement, which applies to all authors. Please enter author specific funding statements as fifth argument of the \author macro.

%\acknowledgements{Univalent people}%optional

\nolinenumbers %uncomment to disable line numbering
\hideLIPIcs  %uncomment to remove references to LIPIcs series (logo, DOI, ...), e.g. when preparing a pre-final version to be uploaded to arXiv or another public repository

%Editor-only macros:: begin (do not touch as author)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\EventEditors{<NAME> and <NAME>}
%\EventNoEds{2}
%\EventLongTitle{42nd Conference on Very Important Topics (CVIT 2016)}
%\EventShortTitle{CVIT 2016}
%\EventAcronym{CVIT}
%\EventYear{2016}
%\EventDate{December 24--27, 2016}
%\EventLocation{Little Whinging, United Kingdom}
%\EventLogo{}
%\SeriesVolume{42}
%\ArticleNo{23}

\frenchspacing

\newcommand{\tabstyle}[0]{\scriptsize\ttfamily\fontseries{l}\selectfont}

\begin{document}

\maketitle

\begin{abstract}
Here is presented a reincarnation of \textbf{cubicaltt} called \textbf{anders}.
\end{abstract}

\section{Motivation}
\label{sec:typesetting-summary}

The \textbf{HTS} \cite{Voevodsky13} 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 is to have an ability to express
semisemplicial types. Theoretical work was continued in \textbf{2LTT} \cite{Annenkov19}.

Our aim is to preserve \textbf{cubicaltt} programs and remain \textbf{anders}
implementation compatible with original \textbf{CCHM} \cite{Mortberg15} publications
along with \textbf{HTS} and \textbf{2LTT}. While we are on our road
to subset of \textbf{Lean} tactic language, currently we are at the stage of
regular cubical type checker with \textbf{CHM} \cite{Huber18} primitives.
You may try it at Github \footnote{\url{https://github.com/groupoid/anders}}
or install through OPAM: \textbf{opam install anders}.

\section{Syntax}

The syntax of \textbf{anders} resembles original syntax of the reference \textbf{CCHM} 
type checker \textbf{cubicaltt}, is slightly compatible with \textbf{Lean}
syntax and contains the full set of \textbf{Cubical Agda} \cite{Vezzosi19}
primitives. Here is given the mathematical pseudo-code notation of the language
expressions that comes immediately after parsing. The core syntax definition
of language E corresponds to the type defined in the OCaml module.

\begin{table}[ht]
\centering
\begin{tabular}{rl}
 cosmos :=&$\mathbf{U}_j \ |\ \mathbf{V}_k$ \\
    var :=&$\mathbf{var}\ name\ |\ \mathbf{hole}$ \\
     pi :=&$\Pi\ name\ E\ E\ |\ \lambda\ name\ E\ E\ |\ E\ E$ \\
  sigma :=&$\Sigma\ name\ E\ E\ |\ (E,E)\ |\ E.1\ |\ E.2$ \\
     id :=&$\mathbf{Id}\ E\ |\ \mathbf{ref}\ E\ |\ \mathbf{idJ}\ E$ \\
   path :=&$\mathbf{Path}\ E\ |\ E^i\ |\ E\ @\ E$ \\
      I :=&$\mathbf{I}\ |\ 0\ |\ 1\ |\ E\ \bigvee\ E\ |\ E\ \bigwedge\ E\ |\ \neg E$ \\
   part :=&$\mathbf{Partial}\ E\ E\ |\ \mathbf{[}\ (E=I) \rightarrow E, ...\ \mathbf{]}$ \\
    sub :=&$\mathbf{inc}\ E\ |\ \mathbf{ouc}\ E\ |\ E\ \mathbf{[}\ I\ \mapsto\ E\ \mathbf{]}$ \\
    kan :=&$\mathbf{transp}\ E\ E\ |\ \mathbf{hcomp}\ E$ \\
   glue :=&$\mathbf{Glue}\ E\ |\ \mathbf{glue}\ E\ |\ \mathbf{unglue}\ E\ E$ \\
\end{tabular}
\end{table}

Further Menhir BNF notation will be used to describe the top-level language E parser.

\begin{table}[ht]
\centering
\begin{tabular}{rl}
      E :=&$cosmos\ |\ var\ |\ MLTT\ |\ CCHM\ |\ HIT$ \\
    HIT :=&$\mathbf{inductive}\ E\ E\ |\ \mathbf{ctor}\ name\ E\ |\ \mathbf{match}\ E\ E$ \\
   CCHM :=&$path\ |\ I\ |\ part\ |\ sub\ |\ kan\ |\ glue$ \\
   MLTT :=&$pi\ |\ sigma\ |\ id$ \\
\end{tabular}
\end{table}


\textbf{Keywords}. The words of a top-level language (file or repl) consist of keywords or identifiers.
The keywords are following: \textbf{module}, \textbf{where}, \textbf{import}, \textbf{option}, \textbf{def}, \textbf{axiom},
\textbf{postulate}, \textbf{theorem}, \textbf{(}, \textbf{)}, \textbf{[}, \textbf{]}, \textbf{<}, \textbf{>},
\textbf{/}, \textbf{.1}, \textbf{.2}, \textbf{$\Pi$}, \textbf{$\Sigma$}, \textbf{,}, \textbf{$\lambda$}, \textbf{$\times$}, \textbf{$\rightarrow$}, \textbf{:}, \textbf{:=},
\textbf{$\mapsto$}, \textbf{U}, \textbf{V}, \textbf{$\bigvee$}, \textbf{$\bigwedge$}, \textbf{-}, \textbf{+}, \textbf{@}, \textbf{PathP},
\textbf{transp}, \textbf{hcomp}, \textbf{zero}, \textbf{one}, \textbf{Partial}, \textbf{inc},
\textbf{ouc}, \textbf{interval}, \textbf{inductive}, \textbf{Glue}, \textbf{glue}, \textbf{unglue}.\\

\textbf{Indentifiers}. Identifiers support UTF-8. Indentifiers couldn't start with $:$, $-$, $\rightarrow$. Sample identifiers:
$\neg$-of-$\bigvee$, 1$\rightarrow$1, is-?, =, \$$\sim$]!005x, $\infty$, x$\rightarrow$Nat.\\

\textbf{Modules}. Modules represent files with declarations. More accurate, BNF notation of module consists of imports, options and declarations.
\begin{table}[ht]
\tabstyle
\begin{tabular}{l}
\textbf{menhir} \\
\ \ \ 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 \\
\end{tabular}
\end{table}

\textbf{Imports}. The import construction supports file folder structure (without file extensions) by using reserved symbol / for hierarchy walking.\\

\textbf{Options}. Each option holds bool value. Language supports following options: 1) girard (enables U : U); 2) pre-eval (normalization cache);
3) impredicative (infinite hierarchy with impredicativity rule);
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 \textbf{MLTT-73} variation (Path instead of Id and no inductive types, see base library):
In order to turn HIT into ordinary CiC calculus you may say:

\begin{table}[ht]
\tabstyle
\begin{tabular}{l}
\textbf{option} HIT false \\
\textbf{option} CCHM false \\
\textbf{option} MLTT true \\
\end{tabular}
\end{table}

\textbf{Declarations}. Language supports following top level declarations:
1) axiom (non-computable declaration that breakes normalization);
2) postulate (alternative or inverted axiom that can preserve consistency);
3) definition (almost any explicit term or type in type theory);
4) lemma (helper in big game);
5) theorem (something valuable or complex enough).


\begin{table}[ht!]
\tabstyle
\begin{tabular}{l}
\textbf{axiom} isProp (A : U) : U \\
\textbf{def} isSet (A : U) : U := \textbf{$\Pi$} (a b : A) (x y : Path A a b), Path (Path A a b) x y
\end{tabular}
\end{table}

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.

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.

\begin{table}[ht]
\tabstyle
\begin{tabular}{l}
\textbf{menhir} \\
\ \ \ ident : IRREF | IDENT \\
\ \ \ lense : LPARENS ident+ 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
\end{tabular}
\end{table}

\textbf{Expressions}. All atomic language expressions are grouped by four categories:
exp0 (pair constructions), exp1 (non neutral constructions), exp2 (path and pi applcations),
exp3 (neutral constructions).

\begin{table}[ht]
\tabstyle
\begin{tabular}{ll}
\textbf{menhir} \\
\multicolumn{2}{l}{\ \ \ face : LPARENS IDENT IDENT IDENT RPARENS } \\
\multicolumn{2}{l}{\ \ \ part : face+ ARROW exp1 } \\
\multicolumn{2}{l}{\ \ \ exp0 : exp1 COMMA exp0 | exp1 } \\
\multicolumn{2}{l}{\ \ \ exp1 : LSQ separated(COMMA, part) RSQ } \\
\ \ \ \ \ \ | LAM telescope COMMA exp1   & | PI telescope COMMA exp1 \\
\ \ \ \ \ \ | SIGMA telescope COMMA exp1 & | LSQ IRREF ARROW exp1 RSQ \\
\ \ \ \ \ \ | LT ident+ GT exp1          & | exp2 ARROW exp1 \\
\ \ \ \ \ \ | exp2 PROD exp1             & | exp2 \\
\end{tabular}
\end{table}

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.
Universe indicies $U_j$ (inner fibrant), $V_k$ (outer pretypes) and S (outer strict omega) are using unicode subscript letters that are already processed in lexer.

\begin{table}[ht!]
\tabstyle
\begin{tabular}{llll}
\textbf{menhir} \\
\multicolumn{3}{l}{\ \ \ exp2 : exp2 exp3 | exp2 APPFORMULA exp3 | exp3 } \\
\multicolumn{4}{l}{\ \ \ exp3 : LPARENS exp0 RPARENS LSQ exp0 MAP exp0 RSQ } \\
\ \ \ \ \ \   | HOLE              & | PRE          & | KAN          & | IDJ exp3 \\
\ \ \ \ \ \   | exp3 FST          & | exp3 SND     & | NEGATE exp3  & | INC exp3 \\
\ \ \ \ \ \   | exp3 AND exp3     & | exp3 OR exp3 & | ID exp3      & | REF exp3\\
\ \ \ \ \ \   | OUC exp3          & | PATHP exp3   & | PARTIAL exp3 & | IDENT \\
\multicolumn{3}{l}{\ \ \ \ \ \    | IDENT LSQ exp0 MAP exp0 RSQ }   & | HCOMP exp3 \\
\multicolumn{3}{l}{\ \ \ \ \ \    | LPARENS exp0 RPARENS }          & | TRANSP exp3 exp3 \\
\end{tabular}
\end{table}


\newpage
\section{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.
\begin{table}[ht]
\tabstyle
\begin{tabular}{rcl}
 \textbf{inductive} lang : \textbf{U} & := & UNI: cosmos $\rightarrow$ lang \\
   & | & PI: pure lang $\rightarrow$ lang \\
   & | & SIGMA: total lang $\rightarrow$ lang \\
   & | & ID: uip lang $\rightarrow lang$ \\
   & | & PATH: homotopy lang $\rightarrow$ lang \\
   & | & GLUE: gluening lang $\rightarrow$ lang \\
   & | & HIT: hit lang $\rightarrow$ lang \\
\end{tabular}
\end{table}
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 mathematical components library.
We will use here the Coquand's notation for Presheaf Type Theories in terms of restriction maps.

\subsection{Universe Hierarchies}

Language supports Agda-style hierarchy of universes: prop, fibrant (U), interval pretypes (V) and strict omega
with explicit level manipulation. All universes are bounded with preorder
\begin{equation}
Prop_i \prec Fibrant_j \prec Pretypes_k \prec Strict_l,
\end{equation}
in which $i,j,k,l$ are bounded with equation:
\begin{equation}
i < j < k < l.
\end{equation}
Large elimination to upper universes is prohibited. This is extendable to Agda model:

\begin{table}[ht]
\tabstyle
\begin{tabular}{rcl}
  \textbf{inductive} cosmos : \textbf{U}& := & prop: nat $\rightarrow$ cosmos \\
   &|& fibrant: nat $\rightarrow$ cosmos \\
   &|& pretypes: nat $\rightarrow$ cosmos \\
   &|& strict: nat $\rightarrow$ cosmos \\
   &|& omega: cosmos \\
   &|& lock: cosmos \\
\end{tabular}
\end{table}

The \textbf{anders} model contains only fibrant $U_j$ and pretypes $V_k$ universe hierarchies.

\newpage

\subsection{Dependent Types}

\begin{definition}[Type]
A type is interpreted as a presheaf $A$, a family of sets $A_I$ with restriction maps
$u \mapsto u\ f, A_I \rightarrow A_J$ for $f: J\rightarrow I$. A dependent type
B on A is interpreted by a presheaf on category of elements of $A$: the objects
are pairs $(I,u)$ with $u : A_I$ and morphisms $f: (J,v) \rightarrow (I,u)$ are
maps $f : J \rightarrow$ such that $v = u\ f$. A dependent type B is thus given
by a family of sets $B(I,u)$ and restriction maps $B(I,u) \rightarrow B(J,u\ f)$.
\end{definition}


We think of $A$ as a type and $B$ as a family of presheves $B(x)$ varying $x:A$.
The operation $\Pi(x:A)B(x)$ generalizes the semantics of
implication in a Kripke model.

\begin{definition}[Pi]
An element $w:[\Pi(x:A)B(x)](I)$ is a family of functions $w_f : \Pi(u:A(J))B(J,u)$
for $f : J \rightarrow I$ such that $(w_f u)g=w_{f\ g}(u\ g)$ when $u:A(J)$ and $g:K\rightarrow J$.
\end{definition}
\begin{table}[ht]
\tabstyle
\begin{tabular}{rcl}
  \textbf{inductive} pure (lang : U) : \textbf{U}& := & pi: name $\rightarrow$ nat $\rightarrow$ lang $\rightarrow$ lang $\rightarrow$ pure lang \\
  &|& lambda: name $\rightarrow$ nat $\rightarrow$ lang $\rightarrow$ lang $\rightarrow$ pure lang \\
  &|& app: lang $\rightarrow$ lang $\rightarrow$ pure lang \\
\end{tabular}
\end{table}

\begin{definition}[Sigma]
The set $\Sigma(x:A)B(x)$ is the set of pairs $(u,v)$ when $u:A(I),v:B(I,u)$ and restriction map $(u,v)\ f=(u\ f,v\ f)$.
\end{definition}
\begin{table}[ht]
\tabstyle
\begin{tabular}{rcl}
  \textbf{inductive} total (lang : U) : \textbf{U}& := & sigma: name $\rightarrow$ lang $\rightarrow$ total lang \\
  &|& pair: lang $\rightarrow$ lang $\rightarrow$ total lang \\
  &|& fst: lang $\rightarrow$ total lang \\
  &|& snd: lang $\rightarrow$ total lang \\
\end{tabular}
\end{table}

The presheaf with only Pi and Sigma is called \textbf{MLTT-72}. Its internalization in \textbf{anders} is as follows:

\begin{table}[ht!]
\tabstyle
\begin{tabular}{l}
\textbf{def} MLTT-72 (A : U) (B : A $\rightarrow$ U) : U := $\Sigma$ \\
\ \ ($\Pi$-form$_1$ : U) \\
\ \ ($\Pi$-ctor$_1$ : Pi A B $\rightarrow$ Pi A B) \\
\ \ ($\Pi$-elim$_1$ : Pi A B $\rightarrow$ Pi A B) \\
\ \ ($\Pi$-comp$_1$ : (a : A) (f : Pi A B), $\Pi$-elim$_1$ ($\Pi$-ctor$_1$ f) a = f a) \\
\ \ ($\Pi$-comp$_2$ : (a : A) (f : Pi A B), f = $\lambda$ (x : A), f x) \\
\ \ ($\Sigma$-form$_1$ : U) \\
\ \ ($\Sigma$-ctor$_1$ : $\Pi$ (a : A) (b : B a) , Sigma A B) \\
\ \ ($\Sigma$-elim$_1$ : $\Pi$ (p : Sigma A B), A) \\
\ \ ($\Sigma$-elim$_2$ : $\Pi$ (p : Sigma A B), B (pr$_1$ A B p)) \\
\ \ ($\Sigma$-comp$_1$ : $\Pi$ (a : A) (b: B a), a = $\Sigma$-elim$_1$ ($\Sigma$-ctor$_1$ a b)) \\
\ \ ($\Sigma$-comp$_2$ : $\Pi$ (a : A) (b: B a), b = $\Sigma$-elim$_2$ (a, b)) \\
\ \ ($\Sigma$-comp$_3$ : $\Pi$ (p : Sigma A B), p = (pr$_1$ A B p, pr$_2$ A B p)), U
\end{tabular}
\end{table}

\newpage
\subsection{Path Equality}

\subsection{Strict Equality}

\subsection{Glue Types}

\subsection{Higher Inductive Types}

\bibliography{anders}

\end{document}
