--- title: an imperfect algorithmic presentation of xtt date: 2023-06-12 tags: [computer, types] bibliography: quox.bib link-citations: true show-toc: true ... hello everyone. as part of my language [quox] i made a typechecking algorithm for xtt [@xtt]. plus other stuff. but here's just the xtt part, in case anyone is interested. [quox]: https://git.rhiannon.website/rhi/quox - the syntax is slightly different because it uses bidirectional typing [@bidi]. i've tried to roll back my other arbitrary syntactic changes for this document to avoid confusion though. other than subtyping instead of explicit lifting, because that seemed significantly easier. to me at least. - this algorithm [isn't very efficient](#compute-elim-ty). it is what currently exists in quox, and when i improve that stuff in future, hopefully i'll remember to come back and update this post. - i also **haven't proven anything**, so if it's wrong, then i apologise for my hubris. anyway. let's get started. # syntax mostly follows @xtt, but with a few annotations added or removed for bidirectional reasons. - a "term" is a type or an introduction form. it can be checked against a given type. - an "elimination" is a string of elimination forms applied to either a variable or an annotated term. its type can be synthesised. - substitutions take variables to _eliminations_, to preserve typeability, and in this presentation, syntactic well-formedness. - $x, y$ denote term variables, and $๐‘–, ๐‘—$ denote dimension variables. :::texdefs $$ \newcommand\Ceq{\Coloneqq} \newcommand\Or{\mathrel|} \newcommand\E\underline \newcommand\Bar{\mathrel|} \newcommand\Rule[3]{ \begin{array}{l} \text{\small [#3]} \\ \displaystyle \frac{ \begin{gather}#1\end{gather} }{ \begin{gather}#2\end{gather} } \end{array} } $$ ::: $$ \begin{aligned} ฮต &\Ceq 0 \Or 1 & \text{dimension constants} \\ p, q &\Ceq ๐‘– \Or ฮต & \text{dimensions} \\ ฮพ &\Ceq p = q & \text{dimension constraints} \\ ๐“€ &โˆˆ โ„• & \text{concrete universe levels} \\ โ„“ &\Ceq ๐“€ \Or \top & \text{judgement levels} \\ s, t, u, A, B, C &\Ceq ๐’ฐ_โ„“ \Or (x : A) โ†’ B \Or ฮปx. s \Or (x : A) ร— B \Or (s, t) \Or & \text{terms (incl. types)} \\ & \mathrel{\hphantom{\Ceq}} ๐—˜๐—พ_{๐‘–. A} \; s \; t \Or ฮป๐‘–. s \Or ๐—ฏ๐—ผ๐—ผ๐—น \Or ๐˜๐—ฟ๐˜‚๐—ฒ \Or ๐—ณ๐—ฎ๐—น๐˜€๐—ฒ \Or \E{e} \\ e, f, g &\Ceq x \Or f \; s \Or ๐—ณ๐˜€๐˜ \; e \Or ๐˜€๐—ป๐—ฑ \; e \Or f \; p \Or ๐—ถ๐—ณ_{x. A} \; e \; ๐˜๐—ต๐—ฒ๐—ป \; s \; ๐—ฒ๐—น๐˜€๐—ฒ \; t \Or s : A \Or & \text{eliminations} \\ & \mathrel{\hphantom{\Ceq}} [๐‘–. A] โ†“^p_{p'} s \Or A โ†“^p_{p'} s \; [q \; ๐˜„๐—ถ๐˜๐—ต \; 0 โ†ช ๐‘—. tโ‚€ \Bar 1 โ†ช ๐‘—. tโ‚] \Or \\ & \mathrel{\hphantom{\Ceq}} ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_A \; e \; \left[ \begin{array}{lcl} ๐’ฐ & โ†ช & t_๐’ฐ \\ ฮ  \; x \; y & โ†ช & t_ฮ  \\ ฮฃ \; x \; y & โ†ช & t_ฮฃ \\ ๐—˜๐—พ \; xโ‚€ \; xโ‚ \; x \; yโ‚€ \; yโ‚ & โ†ช & t_{๐—˜๐—พ} \\ ๐—ฏ๐—ผ๐—ผ๐—น & โ†ช & t_{๐—ฏ๐—ผ๐—ผ๐—น} \end{array} \right] \\ ฮจ, ฮฆ &\Ceq ยท \Or ฮจ, ๐‘– \Or ฮจ, ฮพ & \text{cubes} \\ ฮ“, ฮ” &\Ceq ยท \Or ฮ“, x: A & \text{contexts} \end{aligned} $$ only real levels $๐“€ โˆˆ โ„•$ can occur in expressions. the special level $\top$ is for checking a type in a context where any level is accepted, for example the type in an annotation $s : A$. in a $๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ$, the pattern variables are assigned this way: - for a function type $(z : A) โ†’ B : ๐’ฐ_๐“€$, the $ฮ $ case is taken with $x โ‰” (A : ๐’ฐ_๐“€)$ and $y โ‰” ((ฮปz. B) : ๐’ฐ_๐“€ โ†’ ๐’ฐ_๐“€)$. - same for a pair type $(z : A) ร— B$ and the $ฮฃ$ case. - for an equality type $๐—˜๐—พ_{i. A} \; s \; t : ๐’ฐ_๐“€$: - $xโ‚€$ and $xโ‚$ are set to the endpoints of the type line $A$; \ $xโ‚€ โ‰” (A[0/๐‘–] : ๐’ฐ_๐“€)$ and $xโ‚ โ‰” (A[1/๐‘–] : ๐’ฐ_๐“€)$. - $x$ is an equality between them; \ $x โ‰” ((ฮป๐‘–. A) : ๐—˜๐—พ_{๐‘–. ๐’ฐ_๐“€} \; A[0/๐‘–] \; A[1/๐‘–]$. - $yโ‚€$ and $yโ‚$ are the terms being equated; \ $yโ‚€ โ‰” (s : A[0/๐‘–])$ and $yโ‚ โ‰” (t : A[1/๐‘–])$. ---- :::texdefs $$ \newcommand\IN{\textcolor{#60c}} \newcommand\OUT{\textcolor{#082}} $$ ::: when introducing new judgements, the [inputs]{.input} and [outputs]{.output} are colour coded. all judgements assume that the cube and context are well formed (omitted). :::rulebox $$ \begin{gathered} \IN{ฮจ} โŠข \IN{p} \; ๐๐ข๐ฆ \qquad \IN{ฮจ} โŠข \IN{p} = \IN{p'} \; ๐๐ข๐ฆ \end{gathered} $$ ::: # dimension checking {#dim} the well-formedness rules are the same as in the paper. since quox uses well scoped de bruijn indices, every value of type `Dim d` is well formed, so they don't exist at all really. the equality rules are just baby's first equational theory solver. :::rulebox $$ \IN{ฮจ} \Bar \IN{ฮ“} โŠข \IN{A} โ‡ ๐ญ๐ฒ๐ฉ๐ž_{\IN{โ„“}} $$ ::: # type checking {#ty} $$ \Rule{}{ฮจ, 0=1 \Bar ฮ“ โŠข A โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“}{ty-01} $$ $$ \Rule{}{ฮจ \Bar ฮ“ โŠข ๐—ฏ๐—ผ๐—ผ๐—น โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“}{ty-bool} $$ $$ \Rule{ ฮจ \Bar ฮ“ โŠข A โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ \qquad ฮจ \Bar ฮ“, x : A โŠข B โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ }{ ฮจ \Bar ฮ“ โŠข (x : A) โ†’ B โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ \\ ฮจ \Bar ฮ“ โŠข (x : A) ร— B โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ }{ty-pi; ty-sig} $$ $$ \Rule{ ฮจ, ๐‘– \Bar ฮ“ โŠข A โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ \qquad ฮจ, ๐‘–, ๐‘– = ฮต \Bar ฮ“ โŠข s_ฮต โ‡ A }{ ฮจ \Bar ฮ“ โŠข ๐—˜๐—พ_{๐‘–. A} \; sโ‚€ \; sโ‚ โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ }{ty-eq} $$ $$ \Rule{ฮจ \Bar ฮ“ โŠข e โ‡’ ๐’ฐ_โ„“}{ฮจ \Bar ฮ“ โŠข \E e โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“}{ty-el} $$ :::rulebox $$ \IN{โ„“} < \IN{โ„“'} $$ ::: for comparing levels: $$ \Rule{๐“€ <_โ„• ๐“€'}{๐“€ < ๐“€'}{lvl-nat} \qquad \Rule{๐“€ โˆˆ โ„•}{๐“€ < \top}{lvl-top} $$ :::rulebox $$ \IN{ฮจ} \Bar \IN{ฮ“} โŠข \IN{s} โ‡ \IN{A} $$ ::: # term checking {#chk} assumes that $ฮจ \Bar ฮ“ โŠข A โ‡ ๐ญ๐ฒ๐ฉ๐ž_\top$. $$ \Rule{}{ฮจ, 0=1 \Bar ฮ“ โŠข s โ‡ A}{tm-01} $$ [reduce the expected type to whnf](#tm-red) before trying to match against it, of course. $$ \Rule{ ฮ“ โŠข ๐ฐ๐ก๐ง๐Ÿ \; A โ†ฆ A' \qquad ฮจ \Bar ฮ“ โŠข_w s โ‡ A' }{ฮจ \Bar ฮ“ โŠข s โ‡ A}{tm-whnf} $$ if $s$ is syntactically a type, then defer to $๐ญ๐ฒ๐ฉ๐ž$ [above](#ty). $$ \Rule{ฮจ \Bar ฮ“ โŠข A โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“}{ฮจ \Bar ฮ“ โŠข_w A โ‡ ๐’ฐ_โ„“}{tm-ty} $$ otherwise: $$ \Rule{ฮจ \Bar ฮ“, x : A โŠข s โ‡ B}{ฮจ \Bar ฮ“ โŠข_w ฮปx. s โ‡ (x : A) โ†’ B}{tm-lam} $$ $$ \Rule{ ฮจ \Bar ฮ“ โŠข s โ‡ A \qquad ฮจ \Bar ฮ“ โŠข t โ‡ B[(t:A)/x] }{ฮจ \Bar ฮ“ โŠข_w (s, t) โ‡ (x : A) ร— B}{tm-pair} $$ $$ \Rule{ ฮจ, i \Bar ฮ“ โŠข s โ‡ A \qquad ฮจ, i, i = ฮต \Bar ฮ“ โŠข s = s_ฮต โ‡ A }{ฮจ \Bar ฮ“ โŠข_w ฮป๐‘–. s โ‡ ๐—˜๐—พ_{๐‘–. A} \; sโ‚€ \; sโ‚}{tm-dlam} $$ $$ \Rule{}{ ฮจ \Bar ฮ“ โŠข_w ๐˜๐—ฟ๐˜‚๐—ฒ โ‡ ๐—ฏ๐—ผ๐—ผ๐—น \qquad ฮจ \Bar ฮ“ โŠข_w ๐—ณ๐—ฎ๐—น๐˜€๐—ฒ โ‡ ๐—ฏ๐—ผ๐—ผ๐—น }{tm-true; tm-false} $$ :::aside maybe you want to make $๐˜๐—ฟ๐˜‚๐—ฒ$ and $๐—ณ๐—ฎ๐—น๐˜€๐—ฒ$ inferrable. _in my opinion_, there are not that many cases where you end up having to write $๐˜๐—ฟ๐˜‚๐—ฒ : ๐—ฏ๐—ผ๐—ผ๐—น$, and, if you have separate term/elim syntactic classes like i do, it's not worth muddying the nice clean separation in e.g. $๐ฐ๐ก๐ง๐Ÿ$ for this. in my onion. :onion: ::: $$ \Rule{ ฮจ \Bar ฮ“ โŠข e โ‡’ A' \qquad ฮจ \Bar ฮ“ โŠข A <:_\top A' }{ฮจ \Bar ฮ“ โŠข \E e โ‡ A}{tm-el} $$ :::rulebox $$ \IN{ฮจ} \Bar \IN{ฮ“} โŠข \IN{e} โ‡’ \OUT{A} $$ ::: # elimination synthesis {#syn} $$ \Rule{}{ฮจ, 0=1 \Bar ฮ“ โŠข e โ‡’ ๐—ฏ๐—ผ๐—ผ๐—น}{el-01} $$ in an inconsistent cube, the type being returned is just a placeholder. in quox, the typechecker returns what is essentially a more fancily-typed `Maybe`, with `Nothing` iff $ฮจ โŠข 0=1 \; ๐๐ข๐ฆ$. $$ \Rule{x : A โˆˆ ฮ“}{ฮจ \Bar ฮ“ โŠข x โ‡’ A}{el-var} $$ $$ \Rule{ ฮจ \Bar ฮ“ โŠข f โ‡’ (x : A) โ†’ B \qquad ฮจ \Bar ฮ“ โŠข s โ‡ A }{ฮจ \Bar ฮ“ โŠข f \; s โ‡’ B[(s:A)/x]}{el-app} $$ $$ \Rule{ ฮจ \Bar ฮ“ โŠข e โ‡’ (x : A) ร— B }{ ฮจ \Bar ฮ“ โŠข ๐—ณ๐˜€๐˜ \; e โ‡’ A \qquad ฮจ \Bar ฮ“ โŠข ๐˜€๐—ป๐—ฑ \; e โ‡’ B[(๐—ณ๐˜€๐˜ \; e)/x] }{el-fst; el-snd} $$ $$ \Rule{ ฮจ \Bar ฮ“ โŠข e โ‡’ ๐—ฏ๐—ผ๐—ผ๐—น \qquad ฮจ \Bar ฮ“, x : ๐—ฏ๐—ผ๐—ผ๐—น โŠข A โ‡ ๐ญ๐ฒ๐ฉ๐ž_\top \\ ฮจ \Bar ฮ“ โŠข s โ‡ A[(๐˜๐—ฟ๐˜‚๐—ฒ : ๐—ฏ๐—ผ๐—ผ๐—น)/x] \qquad ฮจ \Bar ฮ“ โŠข t โ‡ A[(๐—ณ๐—ฎ๐—น๐˜€๐—ฒ : ๐—ฏ๐—ผ๐—ผ๐—น)/x] }{ ฮจ \Bar ฮ“ โŠข ๐—ถ๐—ณ_{x. A} \; e \; ๐˜๐—ต๐—ฒ๐—ป \; s \; ๐—ฒ๐—น๐˜€๐—ฒ \; t โ‡’ A[e/x] }{el-if} $$ :::aside maybe you want to make the head of $๐—ถ๐—ณ$ be checkable. same caveat as making $๐˜๐—ฟ๐˜‚๐—ฒ$/$๐—ณ๐—ฎ๐—น๐˜€๐—ฒ$ inferrable. i just don't think $๐—ถ๐—ณ \; ๐˜๐—ฟ๐˜‚๐—ฒ : ๐—ฏ๐—ผ๐—ผ๐—น \; ๐˜๐—ต๐—ฒ๐—ป โ‹ฏ$ comes up often enough to worry about it. ::: $$ \Rule{ ฮจ \Bar ฮ“ โŠข A โ‡ ๐ญ๐ฒ๐ฉ๐ž_\top \qquad ฮจ \Bar ฮ“ โŠข s โ‡ A }{ ฮจ \Bar ฮ“ โŠข s : A โ‡’ A }{el-ann} $$ $$ \Rule{ ฮจ, ๐‘– \Bar ฮ“ โŠข A โ‡ ๐ญ๐ฒ๐ฉ๐ž_\top \qquad ฮจ โŠข p \qquad ฮจ โŠข p' \qquad ฮจ \Bar ฮ“ โŠข s โ‡ A[p/๐‘–] }{ ฮจ \Bar ฮ“ โŠข [๐‘–. A] โ†“^p_{p'} s โ‡’ A[p'/๐‘–] }{el-coe} $$ $$ \Rule{ ฮจ \Bar ฮ“ โŠข A โ‡ ๐ญ๐ฒ๐ฉ๐ž_\top \qquad ฮจ \Bar ฮ“ โŠข s โ‡ A \\ ฮจ, q=ฮต, ๐‘— \Bar ฮ“ โŠข t_ฮต โ‡ A \qquad ฮจ, q=ฮต, ๐‘—, ๐‘—=p \Bar ฮ“ โŠข t_ฮต = s โ‡ A \\ }{ ฮจ \Bar ฮ“ โŠข A โ†“^p_{p'} s \; [q \; ๐˜„๐—ถ๐˜๐—ต \; 0 โ†ช ๐‘—. tโ‚€ \Bar 1 โ†ช ๐‘—. tโ‚] โ‡’ A }{el-comp} $$ $$ \Rule{ ฮจ \Bar ฮ“ โŠข A โ‡ ๐ญ๐ฒ๐ฉ๐ž_\top \qquad ฮจ \Bar ฮ“ โŠข e โ‡’ ๐’ฐ_๐“€ \\ ฮจ \Bar ฮ“ โŠข t_๐’ฐ โ‡ A \qquad ฮจ \Bar ฮ“ โŠข t_{๐—ฏ๐—ผ๐—ผ๐—น} โ‡ A \\ ฮจ \Bar ฮ“, x : ๐’ฐ_๐“€, y : ๐’ฐ_๐“€ โŠข t_ฮ  โ‡ A \qquad ฮจ \Bar ฮ“, x : ๐’ฐ_๐“€, y : ๐’ฐ_๐“€ โŠข t_ฮฃ โ‡ A \\ ฮจ \Bar ฮ“, xโ‚€ : ๐’ฐ_๐“€, xโ‚ : ๐’ฐ_๐“€, x : ๐—˜๐—พ_{\_. ๐’ฐ_๐“€} \; xโ‚€ \; xโ‚, yโ‚€ : xโ‚€, yโ‚ : xโ‚ โŠข t_{๐—˜๐—พ} โ‡ A }{ ฮจ \Bar ฮ“ โŠข ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_A \; e \; \left[ \begin{array}{lcl} ๐’ฐ & โ†ช & t_๐’ฐ \\ ฮ  \; x \; y & โ†ช & t_ฮ  \\ ฮฃ \; x \; y & โ†ช & t_ฮฃ \\ ๐—˜๐—พ \; xโ‚€ \; xโ‚ \; x \; yโ‚€ \; yโ‚ & โ†ช & t_{๐—˜๐—พ} \\ ๐—ฏ๐—ผ๐—ผ๐—น & โ†ช & t_{๐—ฏ๐—ผ๐—ผ๐—น} \end{array}\right] โ‡’ A }{el-tycase} $$ :::rulebox $$ \IN ฮจ \Bar \IN ฮ“ โŠข \IN A <:_{\IN โ„“} \IN B $$ ::: # subtyping {#sub} $$ \Rule{ฮจ \Bar ฮ“ โŠข A = A' โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“}{ฮจ \Bar ฮ“ โŠข A <:_{โ„“} A'}{sub-eq} \qquad \Rule{๐“€โ‚ โ‰ค ๐“€โ‚‚ < โ„“}{ฮจ \Bar ฮ“ โŠข ๐’ฐ_{๐“€โ‚} <:_{โ„“} ๐’ฐ_{๐“€โ‚‚}}{sub-univ} $$ $$ \Rule{ ฮจ \Bar ฮ“ โŠข A' <:_{โ„“} A \qquad ฮจ \Bar ฮ“ โŠข B <:_{โ„“} B' }{ ฮจ \Bar ฮ“ โŠข (x : A) โ†’ B <:_{โ„“} (x : A') โ†’ B' }{sub-ฮ } \qquad \Rule{ ฮจ \Bar ฮ“ โŠข A <:_{โ„“} A' \qquad ฮจ \Bar ฮ“ โŠข B <:_{โ„“} B' }{ ฮจ \Bar ฮ“ โŠข (x : A) ร— B <:_{โ„“} (x : A') ร— B' }{sub-ฮฃ} $$ $$ \Rule{ ฮจ \Bar ฮ“ โŠข A <:_{โ„“} A' \qquad ฮจ \Bar ฮ“ โŠข s = s' โ‡ A'[0/๐‘–] \qquad ฮจ \Bar ฮ“ โŠข t = t' โ‡ A'[1/๐‘–] }{ ฮจ \Bar ฮ“ โŠข ๐—˜๐—พ_{i.A} \; s \; t <:_{โ„“} ๐—˜๐—พ_{i. A'} \; s' \; t' }{sub-eq} $$ # equality {#eq} due to boundary separation, equality is tested separately in every consistent corner of the cube, by generating all dimension substitutions and applying each one in turn. the judgements with $โŠข_s$ are used in each corner individually. $$ ฯˆ, ฯ† \Ceq ยท \Or ฯˆ, ฮต/๐‘– \qquad \text{dimension substitutions} $$ :::rulebox $$ \OUT ฯˆ โˆˆ ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐๐ข๐ฆ} \; \IN ฮจ $$ ::: ## cube splitting in general $ฯˆ$ has multiple solutions, returned as a set. $$ \Rule{}{ยท โˆˆ ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐๐ข๐ฆ} \; ยท}{sd-nil} $$ $$ \Rule{ ฯˆ โˆˆ ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐๐ข๐ฆ} \; ฮจ }{ ฯˆ, 0/๐‘– โˆˆ ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐๐ข๐ฆ} (ฮจ, ๐‘–) \\ ฯˆ, 0/๐‘– โˆˆ ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐๐ข๐ฆ} (ฮจ, ๐‘–, ๐‘–=0) }{sd-0} \qquad \Rule{ ฯˆ โˆˆ ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐๐ข๐ฆ} \; ฮจ }{ ฯˆ, 1/๐‘– โˆˆ ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐๐ข๐ฆ} (ฮจ, ๐‘–) \\ ฯˆ, 1/๐‘– โˆˆ ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐๐ข๐ฆ} (ฮจ, ๐‘–, ๐‘–=1) }{sd-1} $$ :::rulebox $$ \IN{ฮจ} \Bar \IN{ฮ“} โŠข \IN{A} = \IN{A'} โ‡ ๐ญ๐ฒ๐ฉ๐ž_{\IN{โ„“}} $$ ::: ## types {#ty-eq} assumes that $ฮจ \Bar ฮ“ โŠข A โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“$ and $ฮจ \Bar ฮ“ โŠข A' โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“$. $$ \Rule{ โˆ€ ฯˆ โˆˆ ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐๐ข๐ฆ} \; ฮจ. ฮ“ โŠข_๐ฌ A[ฯˆ] = B[ฯˆ] โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ }{ ฮจ \Bar ฮ“ โŠข A = B โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ }{eq-ty-split} $$ $$ \Rule{๐“€ < โ„“}{ฮ“ โŠข_๐ฌ ๐’ฐ_๐“€ = ๐’ฐ_๐“€ โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“}{eq-ty-univ} $$ $$ \Rule{ ฮ“ โŠข_๐ฌ A = A' โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ \qquad ฮ“, x : A โŠข_๐ฌ B = B' โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ \qquad }{ ฮ“ โŠข_๐ฌ ((x : A) โ†’ B) = ((x : A') โ†’ B) โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ \\ ฮ“ โŠข_๐ฌ ((x : A) ร— B) = ((x : A') ร— B) โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ }{eq-ty-\{ฮ ,ฮฃ\}} $$ $$ \Rule{ ฮ“ โŠข_๐ฌ A[0/๐‘–] = A'[0/๐‘–] โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ \qquad ฮ“ โŠข_๐ฌ A[1/๐‘–] = A'[1/๐‘–] โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ \\ ฮ“ โŠข_๐ฌ s = s' โ‡ A[0/๐‘–] \qquad ฮ“ โŠข_๐ฌ t = t' โ‡ A[1/๐‘–] }{ ฮ“ โŠข_๐ฌ ๐—˜๐—พ_{i. A} \; s \; t = ๐—˜๐—พ_{i. A'} \; s' \; t' โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“ }{eq-ty-eq} $$ $$ \Rule{}{ฮ“ โŠข_๐ฌ ๐—ฏ๐—ผ๐—ผ๐—น = ๐—ฏ๐—ผ๐—ผ๐—น โ‡ ๐ญ๐ฒ๐ฉ๐ž_โ„“}{eq-ty-bool} $$ $$ \Rule{ฮ“ โŠข_๐ฌ e = e' โ‡’ ๐’ฐ_๐“€}{ฮ“ โŠข_๐ฌ \E{e} = \E{e'} โ‡ ๐ญ๐ฒ๐ฉ๐ž_๐“€}{eq-ty-el} $$ :::rulebox $$ \begin{gathered} \IN{ฮจ} \Bar \IN{ฮ“} โŠข \IN{s} = \IN{s'} โ‡ \IN{A} \\ \IN{ฮ“} โŠข_๐ฌ \IN{s} = \IN{s'} โ‡ \IN{A} \end{gathered} $$ ::: ## terms {#tm-eq} assumes that $ฮจ \Bar ฮ“ โŠข s โ‡ A$ and $ฮจ \Bar ฮ“ โŠข s' โ‡ A$. $$ \Rule{ โˆ€ ฯˆ โˆˆ ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐๐ข๐ฆ} \; ฮจ. ฮ“ โŠข_๐ฌ s[ฯˆ] = s'[ฯˆ] โ‡ A[ฯˆ] }{ ฮจ \Bar ฮ“ โŠข s = s' โ‡ A }{eq-tm-split} $$ $$ \Rule{ ฮ“ โŠข A \; ๐ฌ๐ฎ๐›๐ฌ๐ข๐ง๐  }{ ฮ“ โŠข_๐ฌ s = t โ‡ A }{eq-tm-subsing} $$ ### types $$ \Rule{ฮ“ โŠข_๐ฌ s = t โ‡ ๐ญ๐ฒ๐ฉ๐ž_๐“€}{ฮ“ โŠข_๐ฌ s = t โ‡ ๐’ฐ_๐“€}{eq-tm-ty} $$ ### functions $$ \Rule{ ฮ“, x : A โŠข_๐ฌ s = t โ‡ B }{ ฮ“ โŠข_๐ฌ (ฮปx. s) = (ฮปx. t) โ‡ (x : A) โ†’ B }{eq-tm-ฮป} $$ $$ \Rule{ ฮ“, x : A โŠข_๐ฌ s = \E{e \; x} โ‡ B }{ ฮ“ โŠข_๐ฌ (ฮปx. s) = \E e โ‡ (x : A) โ†’ B }{eq-tm-ฮป-ฮท1} \qquad \Rule{ ฮ“, x : A โŠข_๐ฌ \E{e \; x} = s โ‡ B }{ ฮ“ โŠข_๐ฌ \E e = (ฮปx. s) โ‡ (x : A) โ†’ B }{eq-tm-ฮป-ฮท2} $$ ### pairs $$ \Rule{ ฮ“ โŠข_๐ฌ sโ‚€ = tโ‚€ โ‡ A \qquad ฮ“, x : A โŠข_๐ฌ sโ‚ = tโ‚ โ‡ B[sโ‚€/x] }{ ฮ“ โŠข (sโ‚€, sโ‚) = (tโ‚€, tโ‚) โ‡ (x : A) ร— B }{eq-tm-pair} $$ $$ \Rule{ ฮ“ โŠข_๐ฌ sโ‚€ = \E{๐—ณ๐˜€๐˜ \; e} โ‡ A \qquad ฮ“ โŠข_๐ฌ sโ‚ = \E{๐˜€๐—ป๐—ฑ \; e} โ‡ B[sโ‚€/x] }{ ฮ“ โŠข (sโ‚€, sโ‚) = \E e โ‡ (x : A) ร— B }{eq-tm-pair-ฮท1} $$ $$ \Rule{ ฮ“ โŠข_๐ฌ \E{๐—ณ๐˜€๐˜ \; e} = tโ‚€ โ‡ A \qquad ฮ“ โŠข_๐ฌ \E{๐˜€๐—ป๐—ฑ \; e} = tโ‚ โ‡ B[tโ‚€/x] }{ ฮ“ โŠข \E e = (tโ‚€, tโ‚) โ‡ (x : A) ร— B }{eq-tm-pair-ฮท2} $$ ### equalities look! uip! $$ \Rule{}{ฮ“ โŠข_๐ฌ sโ‚€ = sโ‚ โ‡ ๐—˜๐—พ_{i. A} \; tโ‚€ \; tโ‚}{eq-tm-dฮป} $$ ### bool $$ \Rule{}{ฮ“ โŠข_๐ฌ ๐˜๐—ฟ๐˜‚๐—ฒ = ๐˜๐—ฟ๐˜‚๐—ฒ โ‡ ๐—ฏ๐—ผ๐—ผ๐—น}{eq-tm-true} \qquad \Rule{}{ฮ“ โŠข_๐ฌ ๐—ณ๐—ฎ๐—น๐˜€๐—ฒ = ๐—ณ๐—ฎ๐—น๐˜€๐—ฒ โ‡ ๐—ฏ๐—ผ๐—ผ๐—น}{eq-tm-false} $$ ### eliminations $$ \Rule{ฮ“ โŠข_๐ฌ e = e' โ‡’ A}{ฮ“ โŠข_๐ฌ \E e = \E{e'} โ‡ A}{eq-tm-el} $$ :::rulebox $$ \begin{gathered} \IN{ฮจ} \Bar \IN{ฮ“} โŠข \IN{e} = \IN{e'} \\ \IN{ฮ“} โŠข_๐ฌ \IN{e} = \IN{e'} โ‡’ \OUT{A} \end{gathered} $$ ::: ## eliminations {#el-eq} assumes that $ฮจ \Bar ฮ“ โŠข e โ‡’ A$ and $ฮจ \Bar ฮ“ โŠข e' โ‡’ A$ for some $A$. $$ \Rule{ โˆ€ ฯˆ โˆˆ ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐๐ข๐ฆ} \; ฮจ. โˆƒA. ฮ“ โŠข_๐ฌ e[ฯˆ] = e'[ฯˆ] โ‡’ A }{ ฮจ \Bar ฮ“ โŠข e = e' }{eq-el-split} $$ $$ \Rule{ ฮ“ โŠข ๐ญ๐ฒ \; e โ†ฆ A \qquad ฮ“ โŠข A \; ๐ฌ๐ฎ๐›๐ฌ๐ข๐ง๐  }{ ฮ“ โŠข_๐ฌ e = e' โ‡’ A }{eq-el-subsing} $$ :::aside the type computed for this rule can't be shared with the rest of the rules, because they only return a type when they succeed. very unsatisfying ::: $$ \Rule{(x : A) โˆˆ ฮ“}{ฮ“ โŠข_๐ฌ x = x โ‡’ A}{eq-el-var} $$ $$ \Rule{ ฮ“ โŠข_๐ฌ f = f' โ‡’ (x : A) โ†’ B \qquad ฮ“ โŠข_๐ฌ s = s' โ‡ A }{ ฮ“ โŠข_๐ฌ f \; s = f' \; s' โ‡’ B[s/x] }{eq-el-app} $$ $$ \Rule{ ฮ“ โŠข_๐ฌ e = e' โ‡’ (x : A) ร— B }{ ฮ“ โŠข_๐ฌ ๐—ณ๐˜€๐˜ \; e = ๐—ณ๐˜€๐˜ \; e' โ‡’ A \\ ฮ“ โŠข_๐ฌ ๐˜€๐—ป๐—ฑ \; e = ๐˜€๐—ป๐—ฑ \; e' โ‡’ B[๐—ณ๐˜€๐˜ \; e/x] }{eq-el-\{fst,snd\}} $$ $$ \Rule{ ฮ“, x : ๐—ฏ๐—ผ๐—ผ๐—น โŠข_๐ฌ A = A' โ‡ ๐ญ๐ฒ๐ฉ๐ž_\top \qquad ฮ“ โŠข_๐ฌ e = e' โ‡’ ๐—ฏ๐—ผ๐—ผ๐—น \\ ฮ“ โŠข_๐ฌ s = s' โ‡ A[(๐˜๐—ฟ๐˜‚๐—ฒ : ๐—ฏ๐—ผ๐—ผ๐—น)/x] \qquad ฮ“ โŠข_๐ฌ t = t' โ‡ A[(๐—ณ๐—ฎ๐—น๐˜€๐—ฒ : ๐—ฏ๐—ผ๐—ผ๐—น)/x] }{ ฮ“ โŠข_๐ฌ ๐—ถ๐—ณ_{x.A} \; e \; ๐˜๐—ต๐—ฒ๐—ป \; s \; ๐—ฒ๐—น๐˜€๐—ฒ \; t = ๐—ถ๐—ณ_{x.A'} \; e' \; ๐˜๐—ต๐—ฒ๐—ป \; s' \; ๐—ฒ๐—น๐˜€๐—ฒ \; t' โ‡’ A[e/x] }{eq-el-if} $$ TODO coe in an empty cube, there are no dimension applications or compositions. :::rulebox $$ \IN ฮ“ โŠข \IN A \; ๐ฌ๐ฎ๐›๐ฌ๐ข๐ง๐ $$ ::: # subsingleton types if a type is a subsingleton (only ever has zero or one possible values), then skip the equality check for its elements. this is used for neutral terms e.g. two bound variables of the same equality type. $$ \Rule{ ฮ“ โŠข ๐ฐ๐ก๐ง๐Ÿ \; A โ†ฆ A' \qquad ฮ“ โŠข A' \; ๐ฌ๐ฎ๐›๐ฌ๐ข๐ง๐ _๐ฐ }{ฮ“ โŠข A \; ๐ฌ๐ฎ๐›๐ฌ๐ข๐ง๐ }{subsing} $$ $$ \Rule{}{ ฮ“ โŠข ๐—˜๐—พ_{i. A} \; s \; t \; ๐ฌ๐ฎ๐›๐ฌ๐ข๐ง๐ _๐ฐ }{subsing-eq} $$ $$ \Rule{ ฮ“, x : A โŠข B \; ๐ฌ๐ฎ๐›๐ฌ๐ข๐ง๐  }{ ฮ“ โŠข (x : A) โ†’ B \; ๐ฌ๐ฎ๐›๐ฌ๐ข๐ง๐ _๐ฐ }{subsing-ฮ } \qquad \Rule{ ฮ“ โŠข A \; ๐ฌ๐ฎ๐›๐ฌ๐ข๐ง๐  \qquad ฮ“, x : A โŠข B \; ๐ฌ๐ฎ๐›๐ฌ๐ข๐ง๐  }{ ฮ“ โŠข (x : A) ร— B \; ๐ฌ๐ฎ๐›๐ฌ๐ข๐ง๐ _๐ฐ }{subsing-ฮฃ} $$ # reduction {#red} :::rulebox $$ \IN{ฮ“} โŠข ๐ฐ๐ก๐ง๐Ÿ \; \IN{s} โ†ฆ \OUT{s'} $$ ::: ## terms {#tm-red} assumes that $s$ is well-typed (in some consistent cube). types and introduction forms are already in whnf. so the only case non-trivial case is for embedded eliminations. $$ \Rule{ฮ“ โŠข ๐ฐ๐ก๐ง๐Ÿ \; e โ†ฆ e'}{ฮ“ โŠข ๐ฐ๐ก๐ง๐Ÿ \; \E e โ†ฆ \E{e'}}{whnf-embed} \qquad \Rule{\text{$t$ is not an elimination}}{ฮ“ โŠข ๐ฐ๐ก๐ง๐Ÿ \; t โ†ฆ t}{whnf-none} $$ :::rulebox $$ \begin{gathered} \IN{ฮ“} โŠข ๐ฐ๐ก๐ง๐Ÿ \; \IN{e} โ†ฆ \OUT{e'} \\ \IN{ฮ“} โŠข \IN{e} โ‡ \OUT{e'} \end{gathered} $$ ::: ## eliminations {#el-red} assumes that $e$ is well-typed (in some consistent cube). keep stepping the outermost expression until no more rules apply. $$ \Rule{ฮ“ โŠข e โ‡^! e'}{ฮ“ โŠข ๐ฐ๐ก๐ง๐Ÿ \; e โ†ฆ e'}{whnf-el} $$ ### function application $$ \Rule{ฮ“ โŠข e โ‡ e'}{ฮ“ โŠข e \; t โ‡ e' \; t}{step-app-head} $$ $$ \Rule{}{ ฮ“ โŠข ((ฮปx. t) : (x : A) โ†’ B) \; s โ‡ (t[(s:A)/x] : B[(s:A)/x]) }{step-app-ฮฒ} $$ $$ \Rule{ ฮ“ โŠข ๐ฌ๐ฉ๐ฅ๐ข๐ญ_ฮ  \; x \; C โ†ฆ (A, B) \qquad ๐ฅ๐ž๐ญ \; \hat{s}[๐‘—] โ‰” [๐‘–. A] โ†“^q_๐‘— s }{ ฮ“ โŠข (([๐‘–. C] โ†“^p_q s) \; t) โ‡ [๐‘–. B[\hat{s}[i]/x]] โ†“^p_q ((t : C[p/๐‘–]) \; \hat{s}[p]) }{step-app-coe} $$ where $\IN ฮ“ โŠข ๐ฌ๐ฉ๐ฅ๐ข๐ญ_ฮ  \; \IN{x} \; \IN{C} โ†ฆ (\OUT A, \OUT B)$ is: $$ \Rule{}{ฮ“ โŠข ๐ฌ๐ฉ๐ฅ๐ข๐ญ_ฮ  \; x \; ((y : A) โ†’ B) โ†ฆ (A, B[x/y])}{split-ฮ -con} $$ $$ \Rule{ ฮ“ โŠข ๐ญ๐ฒ \; e โ†ฆ ๐’ฐ_๐“€ \\ ๐ฅ๐ž๐ญ \; A โ‰” ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_{๐’ฐ_๐“€} \; e \; [ฮ  \; x \; \_ โ†ช x \Bar \_ โ†ช ๐—ฏ๐—ผ๐—ผ๐—น] \\ ๐ฅ๐ž๐ญ \; B โ‰” ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_{๐’ฐ_๐“€} \; e \; [ฮ  \; \_ \; y โ†ช y \Bar \_ โ†ช ๐—ฏ๐—ผ๐—ผ๐—น] }{ ฮ“ โŠข ๐ฌ๐ฉ๐ฅ๐ข๐ญ_ฮ  \; x \; \E e โ†ฆ (A, B \; x) }{split-ฮ -neut} $$ $A$ lives in $ฮ“$ and $B$ lives in $(ฮ“, x:A)$. ### pair projections $$ \Rule{ฮ“ โŠข e โ‡ e'}{ ฮ“ โŠข ๐—ณ๐˜€๐˜ \; e โ‡ ๐—ณ๐˜€๐˜ \; e' \qquad ฮ“ โŠข ๐˜€๐—ป๐—ฑ \; e โ‡ ๐˜€๐—ป๐—ฑ \; e' }{step-\{fst,snd\}-head} $$ $$ \Rule{}{ ฮ“ โŠข ๐—ณ๐˜€๐˜ ((s, t) : (x : A) ร— B) โ‡ (s : A) \\ ฮ“ โŠข ๐˜€๐—ป๐—ฑ ((s, t) : (x : A) ร— B) โ‡ (t : B[s/x]) }{step-\{fst,snd\}-ฮฒ} $$ $$ \Rule{ ฮ“ โŠข ๐ฌ๐ฉ๐ฅ๐ข๐ญ_ฮฃ \; x\ ; C โ†ฆ (A, B) }{ ฮ“ โŠข ๐—ณ๐˜€๐˜ ([๐‘–. C] โ†“^p_q s) โ‡ [๐‘–. A] โ†“^p_q ๐—ณ๐˜€๐˜ \; (s : A[p/๐‘–]) }{step-fst-coe} $$ $\IN ฮ“ โŠข ๐ฌ๐ฉ๐ฅ๐ข๐ญ_ฮฃ \; \IN{x} \; \IN{C} โ†ฆ (\OUT A, \OUT B)$ is: $$ \Rule{}{ ฮ“ โŠข ๐ฌ๐ฉ๐ฅ๐ข๐ญ_ฮฃ \; x \; ((y : A) ร— B) โ†ฆ (A, B[x/y]) }{split-ฮฃ-con} \qquad \Rule{ ฮ“ โŠข ๐ญ๐ฒ \; e โ†ฆ ๐’ฐ_๐“€ \\ ๐ฅ๐ž๐ญ \; A โ‰” ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_{๐’ฐ_๐“€} \; e \; [ฮฃ \; x \; y โ†ช x \Bar \_ โ†ช ๐—ฏ๐—ผ๐—ผ๐—น] \\ ๐ฅ๐ž๐ญ \; B โ‰” ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_{๐’ฐ_๐“€} \; e \; [ฮฃ \; x \; y โ†ช y \Bar \_ โ†ช ๐—ฏ๐—ผ๐—ผ๐—น] }{ ฮ“ โŠข ๐ฌ๐ฉ๐ฅ๐ข๐ญ_ฮฃ \; x \; \E e โ†ฆ (A, B \; x) }{split-ฮฃ-neut} $$ $A$ lives in $ฮ“$ and $B$ lives in $(ฮ“, x:A)$. ### dimension application $$ \Rule{ฮ“ โŠข e โ‡ e'}{ฮ“ โŠข e \; p โ‡ e' \; p}{step-dapp-head} $$ $$ \Rule{}{ ฮ“ โŠข ((ฮป๐‘–. t) : ๐—˜๐—พ_{๐‘–. A} \; sโ‚€ \; sโ‚) \; ฮต โ‡ (s_ฮต : A[ฮต/๐‘–]) }{step-dapp-ฮฒ-end} $$ $$ \Rule{}{ ฮ“ โŠข ((ฮป๐‘–. t) : ๐—˜๐—พ_{๐‘–. A} \; sโ‚€ \; sโ‚) \; ๐‘— โ‡ (t[๐‘—/๐‘–] : A[๐‘—/๐‘–]) }{step-dapp-ฮฒ-var} $$ $$ \Rule{ ฮ“ โŠข ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐—˜๐—พ} \; ๐‘– \; C โ†ฆ (Aโ‚€, Aโ‚, A, sโ‚€, sโ‚) }{ ฮ“ โŠข ([๐‘—. C] โ†“^p_{p'} t) \; q โ‡ [๐‘—. A[q/๐‘–]] โ†“^p_{p'} (t : (๐—˜๐—พ_{๐‘–.A} \; sโ‚€ \; sโ‚)[p/๐‘—]) \; [q \; ๐˜„๐—ถ๐˜๐—ต \; 0 โ†ช ๐‘—. sโ‚€ \Bar 1 โ†ช ๐‘—. sโ‚] }{step-dapp-coe} $$ this heterogeneous composition is defined in @xtt in terms of composition and coercion. $\IN ฮ“ โŠข ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐—˜๐—พ} \; \IN ๐‘– \; \IN C โ†ฆ (\OUT{Aโ‚€}, \OUT{Aโ‚}, \OUT A, \OUT{sโ‚€}, \OUT{sโ‚})$ is: $$ \Rule{}{ ฮ“ โŠข ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐—˜๐—พ} \; ๐‘– \; (๐—˜๐—พ_{j. A} \; sโ‚€ \; sโ‚) โ†ฆ (A[0/๐‘—], A[1/๐‘—], A[๐‘–/๐‘—], sโ‚€, sโ‚) }{split-Eq-con} $$ $$ \Rule{ ฮ“ โŠข ๐ญ๐ฒ \; e โ†ฆ ๐’ฐ_๐“€ \\ ๐ฅ๐ž๐ญ \; Aโ‚€ โ‰” ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_{๐’ฐ_๐“€} \; e \; [๐—˜๐—พ \; aโ‚€ \; aโ‚ \; a \; xโ‚€ \; xโ‚ โ†ช aโ‚€ \Bar \_ โ†ช ๐—ฏ๐—ผ๐—ผ๐—น] \\ ๐ฅ๐ž๐ญ \; Aโ‚ โ‰” ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_{๐’ฐ_๐“€} \; e \; [๐—˜๐—พ \; aโ‚€ \; aโ‚ \; a \; xโ‚€ \; xโ‚ โ†ช aโ‚ \Bar \_ โ†ช ๐—ฏ๐—ผ๐—ผ๐—น] \\ ๐ฅ๐ž๐ญ \; A โ‰” ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_{๐’ฐ_๐“€} \; e \; [๐—˜๐—พ \; aโ‚€ \; aโ‚ \; a \; xโ‚€ \; xโ‚ โ†ช a \Bar \_ โ†ช ๐—ฏ๐—ผ๐—ผ๐—น] \\ ๐ฅ๐ž๐ญ \; sโ‚€ โ‰” ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_{๐’ฐ_๐“€} \; e \; [๐—˜๐—พ \; aโ‚€ \; aโ‚ \; a \; xโ‚€ \; xโ‚ โ†ช xโ‚€ \Bar \_ โ†ช ๐—ฏ๐—ผ๐—ผ๐—น] \\ ๐ฅ๐ž๐ญ \; sโ‚ โ‰” ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_{๐’ฐ_๐“€} \; e \; [๐—˜๐—พ \; aโ‚€ \; aโ‚ \; a \; xโ‚€ \; xโ‚ โ†ช xโ‚ \Bar \_ โ†ช ๐—ฏ๐—ผ๐—ผ๐—น] }{ ฮ“ โŠข ๐ฌ๐ฉ๐ฅ๐ข๐ญ_{๐—˜๐—พ} \; ๐‘– \; \E e โ†ฆ (Aโ‚€, Aโ‚, A \; ๐‘–, sโ‚€, sโ‚) }{split-Eq-neut} $$ if $C$ lives in some cube $ฮจ$, then $A$ lives in $(ฮจ, i)$, and the others live in $ฮจ$. ### conditional $$ \Rule{ฮ“ โŠข e โ‡ e'}{ ฮ“ โŠข ๐—ถ๐—ณ_{x. A} \; e \; ๐˜๐—ต๐—ฒ๐—ป \; sโ‚€ \; ๐—ฒ๐—น๐˜€๐—ฒ \; sโ‚ โ‡ ๐—ถ๐—ณ_{x. A} \; e' \; ๐˜๐—ต๐—ฒ๐—ป \; sโ‚€ \; ๐—ฒ๐—น๐˜€๐—ฒ \; sโ‚}{step-if-head} $$ $$ \Rule{}{ ฮ“ โŠข ๐—ถ๐—ณ_{x. A} \; ๐˜๐—ฟ๐˜‚๐—ฒ:๐—ฏ๐—ผ๐—ผ๐—น \; ๐˜๐—ต๐—ฒ๐—ป \; sโ‚€ \; ๐—ฒ๐—น๐˜€๐—ฒ \; sโ‚ โ‡ (sโ‚€ : A[(๐˜๐—ฟ๐˜‚๐—ฒ:๐—ฏ๐—ผ๐—ผ๐—น)/x]) \\ ฮ“ โŠข ๐—ถ๐—ณ_{x. A} \; ๐—ณ๐—ฎ๐—น๐˜€๐—ฒ:๐—ฏ๐—ผ๐—ผ๐—น \; ๐˜๐—ต๐—ฒ๐—ป \; sโ‚€ \; ๐—ฒ๐—น๐˜€๐—ฒ \; sโ‚ โ‡ (sโ‚ : A[(๐—ณ๐—ฎ๐—น๐˜€๐—ฒ:๐—ฏ๐—ผ๐—ผ๐—น)/x]) }{step-if-true; step-if-false} $$ $$ \Rule{}{ ฮ“ โŠข ๐—ถ๐—ณ_{x.A} \; [๐‘–.C] โ†“^p_q t \; ๐˜๐—ต๐—ฒ๐—ป \; sโ‚€ \; ๐—ฒ๐—น๐˜€๐—ฒ \; sโ‚ โ‡ ๐—ถ๐—ณ_{x.A} \; t : ๐—ฏ๐—ผ๐—ผ๐—น \; ๐˜๐—ต๐—ฒ๐—ป \; sโ‚€ \; ๐—ฒ๐—น๐˜€๐—ฒ \; sโ‚ }{step-if-coe} $$ if the expression is well-typed, as we are assuming, then $C$ can only be something that reduces to $๐—ฏ๐—ผ๐—ผ๐—น$. ### coercion $$ \Rule{ฮ“ โŠข e โ‡ e'}{ฮ“ โŠข [๐‘–. \E e] โ†“^p_q s โ‡ [๐‘–. \E{e'}] โ†“^p_q s}{step-coe-ty} \qquad \Rule{๐‘– โˆ‰ ๐Ÿ๐๐ฏ \; C}{ฮ“ โŠข [๐‘–. C] โ†“^p_q s โ‡ s : C}{step-coe-non} $$ ### composition $$ \Rule{}{ฮ“ โŠข C โ†“^p_p s \; [q \; ๐˜„๐—ถ๐˜๐—ต โ‹ฏ] โ‡ s : C}{step-comp-id} $$ $$ \Rule{}{ ฮ“ โŠข A โ†“^p_{p'} s \; [ฮต \; ๐˜„๐—ถ๐˜๐—ต \; 0 โ†ช ๐‘—.sโ‚€ \Bar 1 โ†ช ๐‘—.sโ‚] โ‡ s_ฮต[p'/๐‘—] : A }{step-comp-end} $$ ### type case $$ \Rule{ฮ“ โŠข e โ‡ e'}{ ฮ“ โŠข ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_C \; e \; [โ‹ฏ] โ‡ ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_C \; e' \; [โ‹ฏ] }{step-tycase-head} $$ $$ \Rule{}{ ฮ“ โŠข ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_C \; ๐—ฏ๐—ผ๐—ผ๐—น:๐’ฐ_๐“€ \; [๐—ฏ๐—ผ๐—ผ๐—น โ†ช s \Bar โ‹ฏ] โ‡ s : C \\ \begin{split} ฮ“ โŠข ๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_C \; ((x : A) โ†’ B) : ๐’ฐ_๐“€ \; [ฮ  \; x \; y โ†ช s \Bar โ‹ฏ] \\ {} โ‡ s[(A:๐’ฐ_๐“€)/x, ((ฮปx. B) : ๐’ฐ_๐“€ โ†’ ๐’ฐ_๐“€)/y] : C \end{split} \\ \text{etc} }{step-tycase-bool; etc} $$ ### annotation $$ \Rule{}{ฮ“ โŠข \E e : A โ‡ e}{step-ann-nest} \qquad \Rule{ฮ“ โŠข e โ‡ e'}{ฮ“ โŠข s : \E e โ‡ s : \E{e'}}{step-ann-ty} $$ :::rulebox $$ \IN ฮ“ โŠข ๐ญ๐ฒ \; \IN e โ†ฆ \OUT A $$ ::: ## compute elim type {#compute-ty} assumes $ฮจ \Bar ฮ“ โŠข e โ‡’ A$ for some $ฮจ$, and just recovers the $A$ without doing any other checking. :::aside yeah. im trying to remove it - __why not just pass the type in?__ \ that gets you e.g. the type of $f \; s$, but that isn't enough information to know the type of $f$ ::: $$ \Rule{(x : A) โˆˆ ฮ“}{ฮ“ โŠข ๐ญ๐ฒ \; x โ†ฆ A}{rety-var} $$ $$ \Rule{ ฮ“ โŠข ๐ญ๐ฒ \; f โ†ฆ (x : A) โ†’ B }{ ฮ“ โŠข ๐ญ๐ฒ (f \; s) โ†ฆ B[(s:A)/x] }{rety-app} \qquad \Rule{ ฮ“ โŠข ๐ญ๐ฒ \; e โ†ฆ (x : A) ร— B }{ ฮ“ โŠข ๐ญ๐ฒ (๐—ณ๐˜€๐˜ \; e) โ†ฆ A \\ ฮ“ โŠข ๐ญ๐ฒ (๐˜€๐—ป๐—ฑ \; e) โ†ฆ B[(๐—ณ๐˜€๐˜ \; e)/x] }{rety-\{fst,snd\}} $$ $$ \Rule{ ฮ“ โŠข ๐ญ๐ฒ \; f โ†ฆ ๐—˜๐—พ_{๐‘–.A} \; s \; t }{ ฮ“ โŠข ๐ญ๐ฒ (f \; p) โ†ฆ A[p/๐‘–] }{rety-dapp} \qquad \Rule{}{ ฮ“ โŠข ๐ญ๐ฒ (๐—ถ๐—ณ_{x.A} \; e \; ๐˜๐—ต๐—ฒ๐—ป \; s \; ๐—ฒ๐—น๐˜€๐—ฒ \; t) โ†ฆ A[e/x] }{rety-if} $$ $$ \Rule{}{ ฮ“ โŠข ๐ญ๐ฒ ([๐‘–.C] โ†“^p_q s) โ†ฆ C[q/๐‘–] }{rety-coe} \qquad \Rule{}{ ฮ“ โŠข ๐ญ๐ฒ (A โ†“^p_{p'} s \; [q \; ๐˜„๐—ถ๐˜๐—ต โ‹ฏ]) โ†ฆ A }{rety-comp} $$ $$ \Rule{}{ ฮ“ โŠข ๐ญ๐ฒ (๐˜๐˜†๐—ฐ๐—ฎ๐˜€๐—ฒ_A \; e \; [โ‹ฏ]) โ†ฆ A }{rety-tycase} $$ # references {#refs}