├── .gitignore ├── .vscode └── settings.json ├── Library20240927.bib ├── Library20240927.bib.bbl ├── Library20240927.bib.blg ├── README.md ├── appendixA.agdai ├── appendixA.lagda.md ├── default.latex ├── header.tex ├── makefile ├── part1.agdai ├── part1.lagda.md ├── part1v2.agdai ├── part1v2.lagda.md ├── part2.agdai ├── part2.lagda.md ├── part2v2.agdai ├── part2v2.lagda.md ├── part3.agdai ├── part3.lagda.md ├── part3v2.agdai ├── part3v2.lagda.md ├── part4.agdai ├── part4.lagda.md ├── part4v2.agdai ├── part4v2.lagda.md ├── part5v2.agdai ├── part5v2.lagda.md ├── part6v2.agdai ├── part6v2.lagda.md ├── poly-dependent-types.pdf ├── poly-dependent-types.tex ├── poly-universes.agdai ├── poly-universes.bbl.bbl ├── poly-universes.bbl.blg ├── poly-universes.lagda.md ├── poly-universes.tex ├── quiver.sty ├── sketching.agda └── sketching.agdai /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | poly-dependent-types.aux 3 | poly-dependent-types.bbl 4 | poly-dependent-types.bcf 5 | poly-dependent-types.blg 6 | poly-dependent-types.fdb_latexmk 7 | poly-dependent-types.fls 8 | poly-dependent-types.log 9 | poly-dependent-types.out 10 | poly-dependent-types.run.xml 11 | poly-dependent-types.synctex.gz 12 | poly-universes.aux 13 | poly-universes.bbl 14 | poly-universes.bcf 15 | poly-universes.fdb_latexmk 16 | poly-universes.fls 17 | poly-universes.log 18 | poly-universes.run.xml 19 | poly-universes.synctex.gz 20 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "makefile.configureOnOpen": false 3 | } -------------------------------------------------------------------------------- /Library20240927.bib.bbl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/Library20240927.bib.bbl -------------------------------------------------------------------------------- /Library20240927.bib.blg: -------------------------------------------------------------------------------- 1 | [0] Config.pm:307> INFO - This is Biber 2.19 2 | [0] Config.pm:310> INFO - Logfile is 'Library20240927.bib.blg' 3 | [39] biber-darwin:340> INFO - === Fri Sep 27, 2024, 22:41:06 4 | [129] Utils.pm:410> ERROR - Cannot find 'Library20240927.bib.bcf'! 5 | [129] Biber.pm:136> INFO - ERRORS: 1 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dependent-types -------------------------------------------------------------------------------- /appendixA.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/appendixA.agdai -------------------------------------------------------------------------------- /appendixA.lagda.md: -------------------------------------------------------------------------------- 1 | ```agda 2 | {-# OPTIONS --without-K --rewriting #-} 3 | module appendixA where 4 | 5 | open import part1v2 6 | open import Agda.Primitive 7 | open import Agda.Builtin.Sigma 8 | open import Agda.Builtin.Unit 9 | open import Agda.Builtin.Equality 10 | open import Agda.Builtin.Equality.Rewrite 11 | open import part2v2 12 | ``` 13 | 14 | ```agda 15 | transpAp : ∀ {ℓ ℓ' κ} {A : Type ℓ} {A' : Type ℓ'} {a b : A} 16 | → (B : A' → Type κ) (f : A → A') (e : a ≡ b) (x : B (f a)) 17 | → transp (λ x → B (f x)) e x ≡ transp B (ap f e) x 18 | transpAp B f refl x = refl 19 | 20 | •invr : ∀ {ℓ} {A : Type ℓ} {a b : A} 21 | → (e : a ≡ b) → (sym e) • e ≡ refl 22 | •invr refl = refl 23 | 24 | ≡siml : ∀ {ℓ} {A : Type ℓ} {a b : A} 25 | → (e : a ≡ b) → refl ≡ (b ≡〈 sym e 〉 e) 26 | ≡siml refl = refl 27 | 28 | ≡idr : ∀ {ℓ} {A : Type ℓ} {a b : A} 29 | → (e : a ≡ b) → e ≡ (a ≡〈 refl 〉 e) 30 | ≡idr refl = refl 31 | 32 | conj : ∀ {ℓ} {A : Type ℓ} {a b c d : A} 33 | → (e1 : a ≡ b) (e2 : a ≡ c) (e3 : b ≡ d) (e4 : c ≡ d) 34 | → (a ≡〈 e1 〉 e3) ≡ (a ≡〈 e2 〉 e4) 35 | → e3 ≡ (b ≡〈 sym e1 〉(a ≡〈 e2 〉 e4)) 36 | conj e1 e2 refl refl refl = ≡siml e1 37 | 38 | nat : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f g : A → B} {a b : A} 39 | → (α : (x : A) → f x ≡ g x) (e : a ≡ b) 40 | → ((f a) ≡〈 α a 〉 (ap g e)) ≡ ((f a) ≡〈 ap f e 〉 (α b)) 41 | nat {a = a} α refl = ≡idr (α a) 42 | 43 | cancel : ∀ {ℓ} {A : Type ℓ} {a b c : A} 44 | → (e1 e2 : a ≡ b) (e3 : b ≡ c) 45 | → (a ≡〈 e1 〉 e3) ≡ (a ≡〈 e2 〉 e3) 46 | → e1 ≡ e2 47 | cancel e1 e2 refl refl = refl 48 | 49 | apId : ∀ {ℓ} {A : Type ℓ} {a b : A} 50 | → (e : a ≡ b) → ap (λ x → x) e ≡ e 51 | apId refl = refl 52 | 53 | apComp : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {a b : A} 54 | → (f : A → B) (g : B → C) (e : a ≡ b) 55 | → ap (λ x → g (f x)) e ≡ ap g (ap f e) 56 | apComp f g refl = refl 57 | 58 | apHtpy : ∀ {ℓ} {A : Type ℓ} {a : A} 59 | → (i : A → A) (α : (x : A) → i x ≡ x) 60 | → ap i (α a) ≡ α (i a) 61 | apHtpy {a = a} i α = 62 | cancel (ap i (α a)) (α (i a)) (α a) 63 | ((i (i a) ≡〈 ap i (α a) 〉 α a) 64 | ≡〈 sym (nat α (α a)) 〉 65 | ((i (i a) ≡〈 α (i a) 〉 ap (λ z → z) (α a)) 66 | ≡〈 ap (λ e → i (i a) ≡〈 α (i a) 〉 e) (apId (α a)) 〉 67 | ((i (i a) ≡〈 α (i a) 〉 α a) □))) 68 | 69 | HAdj : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} 70 | → (A → B) → Set (ℓ ⊔ κ) 71 | HAdj {A = A} {B = B} f = 72 | Σ (B → A) (λ g → 73 | Σ ((x : A) → g (f x) ≡ x) (λ η → 74 | Σ ((y : B) → f (g y) ≡ y) (λ ε → 75 | (x : A) → ap f (η x) ≡ ε (f x)))) 76 | 77 | Iso→HAdj : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 78 | → Iso f → HAdj f 79 | Iso→HAdj {f = f} (g , η , ε) = 80 | g , (η 81 | , ( (λ y → 82 | f (g y) ≡〈 sym (ε (f (g y))) 〉 83 | (f (g (f (g y))) ≡〈 ap f (η (g y)) 〉 84 | (f (g y) ≡〈 ε y 〉 85 | (y □)))) 86 | , λ x → conj (ε (f (g (f x)))) (ap f (η (g (f x)))) 87 | (ap f (η x)) (ε (f x)) 88 | (((f (g (f (g (f x)))) ≡〈 ε (f (g (f x))) 〉 ap f (η x))) 89 | ≡〈 nat (λ z → ε (f z)) (η x) 〉 90 | (((f (g (f (g (f x)))) ≡〈 ap (λ z → f (g (f z))) (η x) 〉 ε (f x))) 91 | ≡〈 ap (λ e → (f (g (f (g (f x)))) ≡〈 e 〉 ε (f x))) 92 | ((ap (λ z → f (g (f z))) (η x)) 93 | ≡〈 apComp (λ z → g (f z)) f (η x) 〉 94 | ((ap f (ap (λ z → g (f z)) (η x))) 95 | ≡〈 ap (ap f) (apHtpy (λ z → g (f z)) η) 〉 96 | (ap f (η (g (f x))) □))) 〉 97 | (((f (g (f (g (f x)))) ≡〈 ap f (η (g (f x))) 〉 ε (f x))) □))))) 98 | 99 | pairEquiv1 : ∀ {ℓ ℓ' κ} {A : Type ℓ} {A' : Type ℓ'} {B : A' → Type κ} 100 | → (f : A → A') → isEquiv f 101 | → isEquiv {A = Σ A (λ x → B (f x))} {B = Σ A' B} 102 | (λ (x , y) → (f x , y)) 103 | pairEquiv1 {A = A} {A' = A'} {B = B} f ef = 104 | Iso→isEquiv 105 | ( (λ (x , y) → (g x , transp B (sym (ε x)) y)) 106 | , ( (λ (x , y) → pairEq (η x) (lemma x y)) 107 | , λ (x , y) → pairEq (ε x) (symr (ε x) y) ) ) 108 | where 109 | g : A' → A 110 | g = fst (Iso→HAdj (isEquiv→Iso ef)) 111 | η : (x : A) → g (f x) ≡ x 112 | η = fst (snd (Iso→HAdj (isEquiv→Iso ef))) 113 | ε : (y : A') → f (g y) ≡ y 114 | ε = fst (snd (snd (Iso→HAdj (isEquiv→Iso ef)))) 115 | ρ : (x : A) → ap f (η x) ≡ ε (f x) 116 | ρ = snd (snd (snd (Iso→HAdj (isEquiv→Iso ef)))) 117 | lemma : (x : A) (y : B (f x)) 118 | → transp (λ z → B (f z)) (η x) 119 | (transp B (sym (ε (f x))) y) 120 | ≡ y 121 | lemma x y = (transp (λ z → B (f z)) (η x) 122 | (transp B (sym (ε (f x))) y)) 123 | ≡〈 transpAp B f (η x) 124 | (transp B (sym (ε (f x))) y) 〉 125 | ( transp B (ap f (η x)) 126 | (transp B (sym (ε (f x))) y) 127 | ≡〈 ap (λ e → transp B e 128 | (transp B (sym (ε (f x))) y)) 129 | (ρ x) 〉 130 | ( (transp B (ε (f x)) 131 | (transp B (sym (ε (f x))) y)) 132 | ≡〈 (symr (ε (f x)) y) 〉 133 | (y □))) 134 | 135 | pairEquiv2 : ∀ {ℓ κ κ'} {A : Type ℓ} {B : A → Type κ} {B' : A → Type κ'} 136 | → (g : (x : A) → B x → B' x) → ((x : A) → isEquiv (g x)) 137 | → isEquiv {A = Σ A B} {B = Σ A B'} 138 | (λ (x , y) → (x , g x y)) 139 | pairEquiv2 g eg = 140 | let isog = (λ x → isEquiv→Iso (eg x)) 141 | in Iso→isEquiv ( (λ (x , y) → (x , fst (isog x) y)) 142 | , ( (λ (x , y) → 143 | pairEq refl (fst (snd (isog x)) y)) 144 | , λ (x , y) → 145 | pairEq refl (snd (snd (isog x)) y))) 146 | 147 | pairEquiv : ∀ {ℓ ℓ' κ κ'} {A : Type ℓ} {A' : Type ℓ'} 148 | → {B : A → Type κ} {B' : A' → Type κ'} 149 | → (f : A → A') (g : (x : A) → B x → B' (f x)) 150 | → isEquiv f → ((x : A) → isEquiv (g x)) 151 | → isEquiv {A = Σ A B} {B = Σ A' B'} 152 | (λ (x , y) → (f x , g x y)) 153 | pairEquiv f g ef eg = 154 | compIsEquiv (pairEquiv1 f ef) 155 | (pairEquiv2 g eg) 156 | 157 | J : ∀ {ℓ κ} {A : Type ℓ} {a : A} (B : (x : A) → a ≡ x → Type κ) 158 | → {a' : A} (e : a ≡ a') → B a refl → B a' e 159 | J B refl b = b 160 | 161 | transpPre : ∀ {ℓ0 ℓ1 κ0 κ1} {A : Type ℓ0} {a a' : A} {B : A → Type κ0} 162 | {C : Type ℓ1} {D : C → Type κ1} {f : A → C} 163 | (mf : isMono f) (g : (x : A) → B x → D (f x)) 164 | (e : f a ≡ f a') {b : B a} 165 | → transp D e (g a b) ≡ g a' (transp B (inv mf e) b) 166 | transpPre {a = a} {a' = a'} {B = B} {D = D} {f = f} mf g e {b = b} = 167 | transp D e (g a b) 168 | ≡〈 ap (λ e' → transp D e' (g a b)) (sym (snd (snd mf) e)) 〉 169 | ( _ ≡〈 (J (λ x e' → transp D (ap f e') (g a b) ≡ g x (transp B e' b)) 170 | (inv mf e) refl) 〉 171 | ((g a' (transp B (inv mf e) b)) □)) 172 | 173 | postulate 174 | funext : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {f g : (x : A) → B x} 175 | → ((x : A) → f x ≡ g x) → f ≡ g 176 | funextr : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {f g : (x : A) → B x} 177 | → (e : (x : A) → f x ≡ g x) → coAp (funext e) ≡ e 178 | funextl : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {f g : (x : A) → B x} 179 | → (e : f ≡ g) → funext (coAp e) ≡ e 180 | 181 | transpD : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {a a' : A} 182 | → (f : (x : A) → B x) (e : a ≡ a') 183 | → transp B e (f a) ≡ f a' 184 | transpD f refl = refl 185 | 186 | transpHAdj : ∀ {ℓ ℓ' κ} {A : Type ℓ} {B : Type ℓ'} 187 | → {C : B → Type κ} {a : A} 188 | → {g : A → B} {h : B → A} 189 | → (f : (x : A) → C (g x)) 190 | → (e : (y : B) → g (h y) ≡ y) 191 | → (e' : (x : A) → h (g x) ≡ x) 192 | → (e'' : (x : A) → e (g x) ≡ ap g (e' x)) 193 | → transp C (e (g a)) (f (h (g a))) ≡ f a 194 | transpHAdj {C = C} {a = a} {g = g} {h = h} f e e' e'' = 195 | transp C (e (g a)) (f (h (g a))) 196 | ≡〈 ap (λ ee → transp C ee (f (h (g a)))) (e'' a) 〉 197 | (transp C (ap g (e' a)) (f (h (g a))) 198 | ≡〈 sym (transpAp C g (e' a) (f (h (g a)))) 〉 199 | ((transp (λ x → C (g x)) (e' a) (f (h (g a)))) 200 | ≡〈 transpD f (e' a) 〉 201 | ((f a) □))) 202 | 203 | PreCompEquiv : ∀ {ℓ ℓ' κ} {A : Type ℓ} {B : Type ℓ'} {C : B → Type κ} 204 | → (f : A → B) → isEquiv f 205 | → isEquiv {A = (b : B) → C b} 206 | {B = (a : A) → C (f a)} 207 | (λ g → λ a → g (f a)) 208 | PreCompEquiv {C = C} f ef = 209 | let (f⁻¹ , l , r , e) = Iso→HAdj (isEquiv→Iso ef) 210 | in Iso→isEquiv ( (λ g b → transp C (r b) (g (f⁻¹ b))) 211 | , ( (λ g → funext (λ b → transpD g (r b))) 212 | , λ g → funext (λ a → transpHAdj g r l (λ x → sym (e x))))) 213 | 214 | PostCompEquiv : ∀ {ℓ κ κ'} {A : Type ℓ} {B : A → Type κ} {C : A → Type κ'} 215 | → (f : (x : A) → B x → C x) → ((x : A) → isEquiv (f x)) 216 | → isEquiv {A = (x : A) → B x} 217 | {B = (x : A) → C x} 218 | (λ g x → f x (g x)) 219 | PostCompEquiv f ef = 220 | ( ( (λ g x → fst (fst (ef x)) (g x)) 221 | , λ g → funext (λ x → snd (fst (ef x)) (g x)))) 222 | , ( (λ g x → fst (snd (ef x)) (g x)) 223 | , λ g → funext (λ x → snd (snd (ef x)) (g x))) 224 | ``` -------------------------------------------------------------------------------- /default.latex: -------------------------------------------------------------------------------- 1 | % Options for packages loaded elsewhere 2 | \PassOptionsToPackage{unicode$for(hyperrefoptions)$,$hyperrefoptions$$endfor$}{hyperref} 3 | \PassOptionsToPackage{hyphens}{url} 4 | $if(colorlinks)$ 5 | \PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor} 6 | $endif$ 7 | $if(CJKmainfont)$ 8 | \PassOptionsToPackage{space}{xeCJK} 9 | $endif$ 10 | % 11 | \documentclass[ 12 | $if(fontsize)$ 13 | $fontsize$, 14 | $endif$ 15 | $if(papersize)$ 16 | $papersize$paper, 17 | $endif$ 18 | $if(beamer)$ 19 | ignorenonframetext, 20 | $if(handout)$ 21 | handout, 22 | $endif$ 23 | $if(aspectratio)$ 24 | aspectratio=$aspectratio$, 25 | $endif$ 26 | $if(babel-lang)$ 27 | $babel-lang$, 28 | $endif$ 29 | $endif$ 30 | $for(classoption)$ 31 | $classoption$$sep$, 32 | $endfor$ 33 | ]{$documentclass$} 34 | $if(beamer)$ 35 | $if(background-image)$ 36 | \usebackgroundtemplate{% 37 | \includegraphics[width=\paperwidth]{$background-image$}% 38 | } 39 | % In beamer background-image does not work well when other images are used, so this is the workaround 40 | \pgfdeclareimage[width=\paperwidth,height=\paperheight]{background}{$background-image$} 41 | \usebackgroundtemplate{\pgfuseimage{background}} 42 | $endif$ 43 | \usepackage{pgfpages} 44 | \setbeamertemplate{caption}[numbered] 45 | \setbeamertemplate{caption label separator}{: } 46 | \setbeamercolor{caption name}{fg=normal text.fg} 47 | \beamertemplatenavigationsymbols$if(navigation)$$navigation$$else$empty$endif$ 48 | $for(beameroption)$ 49 | \setbeameroption{$beameroption$} 50 | $endfor$ 51 | % Prevent slide breaks in the middle of a paragraph 52 | \widowpenalties 1 10000 53 | \raggedbottom 54 | $if(section-titles)$ 55 | \setbeamertemplate{part page}{ 56 | \centering 57 | \begin{beamercolorbox}[sep=16pt,center]{part title} 58 | \usebeamerfont{part title}\insertpart\par 59 | \end{beamercolorbox} 60 | } 61 | \setbeamertemplate{section page}{ 62 | \centering 63 | \begin{beamercolorbox}[sep=12pt,center]{part title} 64 | \usebeamerfont{section title}\insertsection\par 65 | \end{beamercolorbox} 66 | } 67 | \setbeamertemplate{subsection page}{ 68 | \centering 69 | \begin{beamercolorbox}[sep=8pt,center]{part title} 70 | \usebeamerfont{subsection title}\insertsubsection\par 71 | \end{beamercolorbox} 72 | } 73 | \AtBeginPart{ 74 | \frame{\partpage} 75 | } 76 | \AtBeginSection{ 77 | \ifbibliography 78 | \else 79 | \frame{\sectionpage} 80 | \fi 81 | } 82 | \AtBeginSubsection{ 83 | \frame{\subsectionpage} 84 | } 85 | $endif$ 86 | $endif$ 87 | $if(beamerarticle)$ 88 | \usepackage{beamerarticle} % needs to be loaded first 89 | $endif$ 90 | \usepackage{amsmath,amssymb} 91 | $if(linestretch)$ 92 | \usepackage{setspace} 93 | $endif$ 94 | \usepackage{iftex} 95 | \ifPDFTeX 96 | \usepackage[$if(fontenc)$$fontenc$$else$T1$endif$]{fontenc} 97 | \usepackage[utf8]{inputenc} 98 | \usepackage{textcomp} % provide euro and other symbols 99 | \else % if luatex or xetex 100 | $if(mathspec)$ 101 | \ifXeTeX 102 | \usepackage{mathspec} % this also loads fontspec 103 | \else 104 | \usepackage{unicode-math} % this also loads fontspec 105 | \fi 106 | $else$ 107 | \usepackage{unicode-math} % this also loads fontspec 108 | $endif$ 109 | \defaultfontfeatures{Scale=MatchLowercase}$-- must come before Beamer theme 110 | \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1} 111 | \fi 112 | $if(fontfamily)$ 113 | $else$ 114 | $-- Set default font before Beamer theme so the theme can override it 115 | \usepackage{lmodern} 116 | $endif$ 117 | $-- Set Beamer theme before user font settings so they can override theme 118 | $if(beamer)$ 119 | $if(theme)$ 120 | \usetheme[$for(themeoptions)$$themeoptions$$sep$,$endfor$]{$theme$} 121 | $endif$ 122 | $if(colortheme)$ 123 | \usecolortheme{$colortheme$} 124 | $endif$ 125 | $if(fonttheme)$ 126 | \usefonttheme{$fonttheme$} 127 | $endif$ 128 | $if(mainfont)$ 129 | \usefonttheme{serif} % use mainfont rather than sansfont for slide text 130 | $endif$ 131 | $if(innertheme)$ 132 | \useinnertheme{$innertheme$} 133 | $endif$ 134 | $if(outertheme)$ 135 | \useoutertheme{$outertheme$} 136 | $endif$ 137 | $endif$ 138 | $-- User font settings (must come after default font and Beamer theme) 139 | $if(fontfamily)$ 140 | \usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$} 141 | $endif$ 142 | \ifPDFTeX\else 143 | % xetex/luatex font selection 144 | $if(mainfont)$ 145 | $if(mainfontfallback)$ 146 | \ifLuaTeX 147 | \usepackage{luaotfload} 148 | \directlua{luaotfload.add_fallback("mainfontfallback",{ 149 | $for(mainfontfallback)$"$mainfontfallback$"$sep$,$endfor$ 150 | })} 151 | \fi 152 | $endif$ 153 | \setmainfont[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$$if(mainfontfallback)$,RawFeature={fallback=mainfontfallback}$endif$]{$mainfont$} 154 | $endif$ 155 | $if(sansfont)$ 156 | $if(sansfontfallback)$ 157 | \ifLuaTeX 158 | \usepackage{luaotfload} 159 | \directlua{luaotfload.add_fallback("sansfontfallback",{ 160 | $for(sansfontfallback)$"$sansfontfallback$"$sep$,$endfor$ 161 | })} 162 | \fi 163 | $endif$ 164 | \setsansfont[$for(sansfontoptions)$$sansfontoptions$$sep$,$endfor$$if(sansfontfallback)$,RawFeature={fallback=sansfontfallback}$endif$]{$sansfont$} 165 | $endif$ 166 | $if(monofont)$ 167 | $if(monofontfallback)$ 168 | \ifLuaTeX 169 | \usepackage{luaotfload} 170 | \directlua{luaotfload.add_fallback("monofontfallback",{ 171 | $for(monofontfallback)$"$monofontfallback$"$sep$,$endfor$ 172 | })} 173 | \fi 174 | $endif$ 175 | \setmonofont[$for(monofontoptions)$$monofontoptions$$sep$,$endfor$$if(monofontfallback)$,RawFeature={fallback=monofontfallback}$endif$]{$monofont$} 176 | $endif$ 177 | $for(fontfamilies)$ 178 | \newfontfamily{$fontfamilies.name$}[$for(fontfamilies.options)$$fontfamilies.options$$sep$,$endfor$]{$fontfamilies.font$} 179 | $endfor$ 180 | $if(mathfont)$ 181 | $if(mathspec)$ 182 | \ifXeTeX 183 | \setmathfont(Digits,Latin,Greek)[$for(mathfontoptions)$$mathfontoptions$$sep$,$endfor$]{$mathfont$} 184 | \else 185 | \setmathfont[$for(mathfontoptions)$$mathfontoptions$$sep$,$endfor$]{$mathfont$} 186 | \fi 187 | $else$ 188 | \setmathfont[$for(mathfontoptions)$$mathfontoptions$$sep$,$endfor$]{$mathfont$} 189 | $endif$ 190 | $endif$ 191 | $if(CJKmainfont)$ 192 | \ifXeTeX 193 | \usepackage{xeCJK} 194 | \setCJKmainfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmainfont$} 195 | $if(CJKsansfont)$ 196 | \setCJKsansfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKsansfont$} 197 | $endif$ 198 | $if(CJKmonofont)$ 199 | \setCJKmonofont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmonofont$} 200 | $endif$ 201 | \fi 202 | $endif$ 203 | $if(luatexjapresetoptions)$ 204 | \ifLuaTeX 205 | \usepackage[$for(luatexjapresetoptions)$$luatexjapresetoptions$$sep$,$endfor$]{luatexja-preset} 206 | \fi 207 | $endif$ 208 | $if(CJKmainfont)$ 209 | \ifLuaTeX 210 | \usepackage[$for(luatexjafontspecoptions)$$luatexjafontspecoptions$$sep$,$endfor$]{luatexja-fontspec} 211 | \setmainjfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmainfont$} 212 | \fi 213 | $endif$ 214 | \fi 215 | $if(zero-width-non-joiner)$ 216 | %% Support for zero-width non-joiner characters. 217 | \makeatletter 218 | \def\zerowidthnonjoiner{% 219 | % Prevent ligatures and adjust kerning, but still support hyphenating. 220 | \texorpdfstring{% 221 | \TextOrMath{\nobreak\discretionary{-}{}{\kern.03em}% 222 | \ifvmode\else\nobreak\hskip\z@skip\fi}{}% 223 | }{}% 224 | } 225 | \makeatother 226 | \ifPDFTeX 227 | \DeclareUnicodeCharacter{200C}{\zerowidthnonjoiner} 228 | \else 229 | \catcode`^^^^200c=\active 230 | \protected\def ^^^^200c{\zerowidthnonjoiner} 231 | \fi 232 | %% End of ZWNJ support 233 | $endif$ 234 | % Use upquote if available, for straight quotes in verbatim environments 235 | \IfFileExists{upquote.sty}{\usepackage{upquote}}{} 236 | \IfFileExists{microtype.sty}{% use microtype if available 237 | \usepackage[$for(microtypeoptions)$$microtypeoptions$$sep$,$endfor$]{microtype} 238 | \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts 239 | }{} 240 | $if(indent)$ 241 | $else$ 242 | \makeatletter 243 | \@ifundefined{KOMAClassName}{% if non-KOMA class 244 | \IfFileExists{parskip.sty}{% 245 | \usepackage{parskip} 246 | }{% else 247 | \setlength{\parindent}{0pt} 248 | \setlength{\parskip}{6pt plus 2pt minus 1pt}} 249 | }{% if KOMA class 250 | \KOMAoptions{parskip=half}} 251 | \makeatother 252 | $endif$ 253 | $if(verbatim-in-note)$ 254 | \usepackage{fancyvrb} 255 | $endif$ 256 | \usepackage{xcolor} 257 | $if(geometry)$ 258 | $if(beamer)$ 259 | \geometry{$for(geometry)$$geometry$$sep$,$endfor$} 260 | $else$ 261 | \usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry} 262 | $endif$ 263 | $endif$ 264 | $if(beamer)$ 265 | \newif\ifbibliography 266 | $endif$ 267 | $if(listings)$ 268 | \usepackage{listings} 269 | \newcommand{\passthrough}[1]{#1} 270 | \lstset{defaultdialect=[5.3]Lua} 271 | \lstset{defaultdialect=[x86masm]Assembler} 272 | $endif$ 273 | $if(lhs)$ 274 | \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} 275 | $endif$ 276 | $if(highlighting-macros)$ 277 | $highlighting-macros$ 278 | $endif$ 279 | $if(tables)$ 280 | \usepackage{longtable,booktabs,array} 281 | $if(multirow)$ 282 | \usepackage{multirow} 283 | $endif$ 284 | \usepackage{calc} % for calculating minipage widths 285 | $if(beamer)$ 286 | \usepackage{caption} 287 | % Make caption package work with longtable 288 | \makeatletter 289 | \def\fnum@table{\tablename~\thetable} 290 | \makeatother 291 | $else$ 292 | % Correct order of tables after \paragraph or \subparagraph 293 | \usepackage{etoolbox} 294 | \makeatletter 295 | \patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{} 296 | \makeatother 297 | % Allow footnotes in longtable head/foot 298 | \IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}} 299 | \makesavenoteenv{longtable} 300 | $endif$ 301 | $endif$ 302 | $if(graphics)$ 303 | \usepackage{graphicx} 304 | \makeatletter 305 | \newsavebox\pandoc@box 306 | \newcommand*\pandocbounded[1]{% scales image to fit in text height/width 307 | \sbox\pandoc@box{#1}% 308 | \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% 309 | \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% 310 | \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both 311 | \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% 312 | \else\usebox{\pandoc@box}% 313 | \fi% 314 | } 315 | % Set default figure placement to htbp 316 | \def\fps@figure{htbp} 317 | \makeatother 318 | $endif$ 319 | $if(svg)$ 320 | \usepackage{svg} 321 | $endif$ 322 | $if(strikeout)$ 323 | $-- also used for underline 324 | \ifLuaTeX 325 | \usepackage{luacolor} 326 | \usepackage[soul]{lua-ul} 327 | \else 328 | \usepackage{soul} 329 | $if(beamer)$ 330 | \makeatletter 331 | \let\HL\hl 332 | \renewcommand\hl{% fix for beamer highlighting 333 | \let\set@color\beamerorig@set@color 334 | \let\reset@color\beamerorig@reset@color 335 | \HL} 336 | \makeatother 337 | $endif$ 338 | $if(CJKmainfont)$ 339 | \ifXeTeX 340 | % soul's \st doesn't work for CJK: 341 | \usepackage{xeCJKfntef} 342 | \renewcommand{\st}[1]{\sout{#1}} 343 | \fi 344 | $endif$ 345 | \fi 346 | $endif$ 347 | \setlength{\emergencystretch}{3em} % prevent overfull lines 348 | \providecommand{\tightlist}{% 349 | \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} 350 | $if(numbersections)$ 351 | \setcounter{secnumdepth}{$if(secnumdepth)$$secnumdepth$$else$5$endif$} 352 | $else$ 353 | \setcounter{secnumdepth}{-\maxdimen} % remove section numbering 354 | $endif$ 355 | $if(subfigure)$ 356 | \usepackage{subcaption} 357 | $endif$ 358 | $if(beamer)$ 359 | $else$ 360 | $if(block-headings)$ 361 | % Make \paragraph and \subparagraph free-standing 362 | \makeatletter 363 | \ifx\paragraph\undefined\else 364 | \let\oldparagraph\paragraph 365 | \renewcommand{\paragraph}{ 366 | \@ifstar 367 | \xxxParagraphStar 368 | \xxxParagraphNoStar 369 | } 370 | \newcommand{\xxxParagraphStar}[1]{\oldparagraph*{#1}\mbox{}} 371 | \newcommand{\xxxParagraphNoStar}[1]{\oldparagraph{#1}\mbox{}} 372 | \fi 373 | \ifx\subparagraph\undefined\else 374 | \let\oldsubparagraph\subparagraph 375 | \renewcommand{\subparagraph}{ 376 | \@ifstar 377 | \xxxSubParagraphStar 378 | \xxxSubParagraphNoStar 379 | } 380 | \newcommand{\xxxSubParagraphStar}[1]{\oldsubparagraph*{#1}\mbox{}} 381 | \newcommand{\xxxSubParagraphNoStar}[1]{\oldsubparagraph{#1}\mbox{}} 382 | \fi 383 | \makeatother 384 | $endif$ 385 | $endif$ 386 | $if(pagestyle)$ 387 | \pagestyle{$pagestyle$} 388 | $endif$ 389 | $if(csl-refs)$ 390 | % definitions for citeproc citations 391 | \NewDocumentCommand\citeproctext{}{} 392 | \NewDocumentCommand\citeproc{mm}{% 393 | \begingroup\def\citeproctext{#2}\cite{#1}\endgroup} 394 | \makeatletter 395 | % allow citations to break across lines 396 | \let\@cite@ofmt\@firstofone 397 | % avoid brackets around text for \cite: 398 | \def\@biblabel#1{} 399 | \def\@cite#1#2{{#1\if@tempswa , #2\fi}} 400 | \makeatother 401 | \newlength{\cslhangindent} 402 | \setlength{\cslhangindent}{1.5em} 403 | \newlength{\csllabelwidth} 404 | \setlength{\csllabelwidth}{3em} 405 | \newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing 406 | {\begin{list}{}{% 407 | \setlength{\itemindent}{0pt} 408 | \setlength{\leftmargin}{0pt} 409 | \setlength{\parsep}{0pt} 410 | % turn on hanging indent if param 1 is 1 411 | \ifodd #1 412 | \setlength{\leftmargin}{\cslhangindent} 413 | \setlength{\itemindent}{-1\cslhangindent} 414 | \fi 415 | % set entry spacing 416 | \setlength{\itemsep}{#2\baselineskip}}} 417 | {\end{list}} 418 | \usepackage{calc} 419 | \newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}} 420 | \newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}} 421 | \newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{\strut#1\strut}} 422 | \newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1} 423 | $endif$ 424 | $if(lang)$ 425 | \ifLuaTeX 426 | \usepackage[bidi=basic]{babel} 427 | \else 428 | \usepackage[bidi=default]{babel} 429 | \fi 430 | $if(babel-lang)$ 431 | \babelprovide[main,import]{$babel-lang$} 432 | $if(mainfont)$ 433 | \ifPDFTeX 434 | \else 435 | \babelfont{rm}[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$$if(mainfontfallback)$,RawFeature={fallback=mainfontfallback}$endif$]{$mainfont$} 436 | \fi 437 | $endif$ 438 | $endif$ 439 | $for(babel-otherlangs)$ 440 | \babelprovide[import]{$babel-otherlangs$} 441 | $endfor$ 442 | $for(babelfonts/pairs)$ 443 | \babelfont[$babelfonts.key$]{rm}{$babelfonts.value$} 444 | $endfor$ 445 | % get rid of language-specific shorthands (see #6817): 446 | \let\LanguageShortHands\languageshorthands 447 | \def\languageshorthands#1{} 448 | $if(selnolig-langs)$ 449 | \ifLuaTeX 450 | \usepackage[$for(selnolig-langs)$$it$$sep$,$endfor$]{selnolig} % disable illegal ligatures 451 | \fi 452 | $endif$ 453 | $endif$ 454 | $for(header-includes)$ 455 | $header-includes$ 456 | $endfor$ 457 | $if(dir)$ 458 | \ifPDFTeX 459 | \TeXXeTstate=1 460 | \newcommand{\RL}[1]{\beginR #1\endR} 461 | \newcommand{\LR}[1]{\beginL #1\endL} 462 | \newenvironment{RTL}{\beginR}{\endR} 463 | \newenvironment{LTR}{\beginL}{\endL} 464 | \fi 465 | $endif$ 466 | $if(natbib)$ 467 | \usepackage[$natbiboptions$]{natbib} 468 | \bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$} 469 | $endif$ 470 | $if(biblatex)$ 471 | \usepackage[$if(biblio-style)$style=$biblio-style$,$endif$$for(biblatexoptions)$$biblatexoptions$$sep$,$endfor$]{biblatex} 472 | $for(bibliography)$ 473 | \addbibresource{$bibliography$} 474 | $endfor$ 475 | $endif$ 476 | $if(nocite-ids)$ 477 | \nocite{$for(nocite-ids)$$it$$sep$, $endfor$} 478 | $endif$ 479 | $if(csquotes)$ 480 | \usepackage{csquotes} 481 | $endif$ 482 | \usepackage{bookmark} 483 | \IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available 484 | \urlstyle{$if(urlstyle)$$urlstyle$$else$same$endif$} 485 | $if(links-as-notes)$ 486 | % Make links footnotes instead of hotlinks: 487 | \DeclareRobustCommand{\href}[2]{#2\footnote{\url{#1}}} 488 | $endif$ 489 | $if(verbatim-in-note)$ 490 | \VerbatimFootnotes % allow verbatim text in footnotes 491 | $endif$ 492 | \hypersetup{ 493 | $if(title-meta)$ 494 | pdftitle={$title-meta$}, 495 | $endif$ 496 | $if(author-meta)$ 497 | pdfauthor={$author-meta$}, 498 | $endif$ 499 | $if(lang)$ 500 | pdflang={$lang$}, 501 | $endif$ 502 | $if(subject)$ 503 | pdfsubject={$subject$}, 504 | $endif$ 505 | $if(keywords)$ 506 | pdfkeywords={$for(keywords)$$keywords$$sep$, $endfor$}, 507 | $endif$ 508 | $if(colorlinks)$ 509 | colorlinks=true, 510 | linkcolor={$if(linkcolor)$$linkcolor$$else$Maroon$endif$}, 511 | filecolor={$if(filecolor)$$filecolor$$else$Maroon$endif$}, 512 | citecolor={$if(citecolor)$$citecolor$$else$Blue$endif$}, 513 | urlcolor={$if(urlcolor)$$urlcolor$$else$Blue$endif$}, 514 | $else$ 515 | $if(boxlinks)$ 516 | $else$ 517 | hidelinks, 518 | $endif$ 519 | $endif$ 520 | pdfcreator={LaTeX via pandoc}} 521 | 522 | $if(title)$ 523 | \title{$title$$if(thanks)$\thanks{$thanks$}$endif$} 524 | $endif$ 525 | $if(subtitle)$ 526 | $if(beamer)$ 527 | $else$ 528 | \usepackage{etoolbox} 529 | \makeatletter 530 | \providecommand{\subtitle}[1]{% add subtitle to \maketitle 531 | \apptocmd{\@title}{\par {\large #1 \par}}{}{} 532 | } 533 | \makeatother 534 | $endif$ 535 | \subtitle{$subtitle$} 536 | $endif$ 537 | \author{$for(author)$$author$$sep$ \and $endfor$} 538 | \date{$date$} 539 | $if(beamer)$ 540 | $if(institute)$ 541 | \institute{$for(institute)$$institute$$sep$ \and $endfor$} 542 | $endif$ 543 | $if(titlegraphic)$ 544 | \titlegraphic{\includegraphics$if(titlegraphicoptions)$[$for(titlegraphicoptions)$$titlegraphicoptions$$sep$, $endfor$]$endif${$titlegraphic$}} 545 | $endif$ 546 | $if(logo)$ 547 | \logo{\includegraphics{$logo$}} 548 | $endif$ 549 | $endif$ 550 | 551 | \begin{document} 552 | $if(has-frontmatter)$ 553 | \makeatletter 554 | \@ifclassloaded{memoir}{\ifartopt\else\frontmatter\fi}{\frontmatter} 555 | \makeatother 556 | $endif$ 557 | $if(title)$ 558 | $if(beamer)$ 559 | \frame{\titlepage} 560 | $else$ 561 | \maketitle 562 | $endif$ 563 | $if(abstract)$ 564 | \begin{abstract} 565 | $abstract$ 566 | \end{abstract} 567 | $endif$ 568 | $endif$ 569 | 570 | $for(include-before)$ 571 | $include-before$ 572 | 573 | $endfor$ 574 | $if(toc)$ 575 | $if(toc-title)$ 576 | \renewcommand*\contentsname{$toc-title$} 577 | $endif$ 578 | $if(beamer)$ 579 | \begin{frame}[allowframebreaks] 580 | $if(toc-title)$ 581 | \frametitle{$toc-title$} 582 | $endif$ 583 | \setcounter{tocdepth}{$toc-depth$} 584 | \tableofcontents 585 | \end{frame} 586 | $else$ 587 | { 588 | $if(colorlinks)$ 589 | \hypersetup{linkcolor=$if(toccolor)$$toccolor$$else$$endif$} 590 | $endif$ 591 | \setcounter{tocdepth}{$toc-depth$} 592 | \tableofcontents 593 | } 594 | $endif$ 595 | $endif$ 596 | $if(lof)$ 597 | \listoffigures 598 | $endif$ 599 | $if(lot)$ 600 | \listoftables 601 | $endif$ 602 | $if(linestretch)$ 603 | \setstretch{$linestretch$} 604 | $endif$ 605 | $if(has-frontmatter)$ 606 | \makeatletter 607 | \@ifclassloaded{memoir}{\ifartopt\else\mainmatter\fi}{\mainmatter} 608 | \makeatother 609 | $endif$ 610 | $body$ 611 | 612 | $if(has-frontmatter)$ 613 | \makeatletter 614 | \@ifclassloaded{memoir}{\ifartopt\else\backmatter\fi}{\backmatter} 615 | \makeatother 616 | $endif$ 617 | $if(natbib)$ 618 | $if(bibliography)$ 619 | $if(biblio-title)$ 620 | $if(has-chapters)$ 621 | \renewcommand\bibname{$biblio-title$} 622 | $else$ 623 | \renewcommand\refname{$biblio-title$} 624 | $endif$ 625 | $endif$ 626 | $if(beamer)$ 627 | \begin{frame}[allowframebreaks]{$biblio-title$} 628 | \bibliographytrue 629 | $endif$ 630 | \bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$} 631 | $if(beamer)$ 632 | \end{frame} 633 | $endif$ 634 | 635 | $endif$ 636 | $endif$ 637 | $if(biblatex)$ 638 | $if(beamer)$ 639 | \begin{frame}[allowframebreaks]{$biblio-title$} 640 | \bibliographytrue 641 | \printbibliography[heading=none] 642 | \end{frame} 643 | $else$ 644 | \printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$ 645 | $endif$ 646 | 647 | $endif$ 648 | $for(include-after)$ 649 | $include-after$ 650 | 651 | $endfor$ 652 | \end{document} 653 | -------------------------------------------------------------------------------- /header.tex: -------------------------------------------------------------------------------- 1 | \settrims{0pt}{0pt} % page and stock same size 2 | \settypeblocksize{*}{34.5pc}{*} % {height}{width}{ratio} 3 | \setlrmargins{*}{*}{1} % {spine}{edge}{ratio} 4 | \setulmarginsandblock{.98in}{.98in}{*} % height of typeblock computed 5 | \setheadfoot{\onelineskip}{2\onelineskip} % {headheight}{footskip} 6 | \setheaderspaces{*}{1.5\onelineskip}{*} % {headdrop}{headsep}{ratio} 7 | \checkandfixthelayout 8 | 9 | 10 | \usepackage{amsthm} 11 | \usepackage{mathtools} 12 | 13 | \usepackage[inline]{enumitem} 14 | \usepackage{ifthen} 15 | \usepackage[utf8]{inputenc} %allows non-ascii in bib file 16 | \usepackage{xcolor} 17 | 18 | \usepackage{newunicodechar} 19 | \newunicodechar{λ}{\ensuremath{\mathnormal\lambda}} 20 | \newunicodechar{∀}{\ensuremath{\mathnormal\forall}} 21 | \newunicodechar{≡}{\ensuremath{\mathnormal\equiv}} 22 | \newunicodechar{ℓ}{\ensuremath{\mathnormal\ell}} 23 | \newunicodechar{κ}{\ensuremath{\mathnormal\kappa}} 24 | \newunicodechar{Σ}{\ensuremath{\mathnormal\Sigma}} 25 | \newunicodechar{⊔}{\ensuremath{\mathnormal\sqcup}} 26 | \newunicodechar{♭}{\ensuremath{\mathnormal\flat}} 27 | \newunicodechar{ε}{\ensuremath{\mathnormal\epsilon}} 28 | \newunicodechar{₀}{\ensuremath{\mathnormal{_0}}} 29 | \newunicodechar{⊥}{\ensuremath{\mathnormal\bot}} 30 | \newunicodechar{⊤}{\ensuremath{\mathnormal\top}} 31 | \newunicodechar{α}{\ensuremath{\mathnormal\alpha}} 32 | \newunicodechar{β}{\ensuremath{\mathnormal\beta}} 33 | \newunicodechar{η}{\ensuremath{\mathnormal\eta}} 34 | \newunicodechar{⁻}{\ensuremath{\mathnormal{^-}}} 35 | \newunicodechar{¹}{\ensuremath{\mathnormal{^1}}} 36 | \newunicodechar{ℕ}{\ensuremath{\mathbb{N}}} 37 | \newunicodechar{ω}{\ensuremath{\mathnormal\omega}} 38 | \newunicodechar{∘}{\ensuremath{\mathnormal\circ}} 39 | \newunicodechar{◃}{\ensuremath{\mathnormal\triangleleft}} 40 | \newunicodechar{⊗}{\ensuremath{\mathnormal\otimes}} 41 | \newunicodechar{□}{\ensuremath{\mathnormal\Box}} 42 | \newunicodechar{∥}{\ensuremath{\mathnormal\Vert}} 43 | \newunicodechar{⇆}{\ensuremath{\mathnormal\leftrightarrows}} 44 | \newunicodechar{𝓤}{\ensuremath{\mathnormal\mathcal{U}}} 45 | \newunicodechar{𝔲}{\ensuremath{\mathnormal\mathfrak{u}}} 46 | \newunicodechar{♯}{\ensuremath{\mathnormal\sharp}} 47 | \newunicodechar{σ}{\ensuremath{\mathnormal\sigma}} 48 | \newunicodechar{Π}{\ensuremath{\mathnormal\Pi}} 49 | \newunicodechar{𝕪}{\ensuremath{\mathnormal y}} 50 | \newunicodechar{≃}{\ensuremath{\mathnormal\simeq}} 51 | \newunicodechar{μ}{\ensuremath{\mathnormal\mu}} 52 | \newunicodechar{ρ}{\ensuremath{\mathnormal\rho}} 53 | \newunicodechar{⇈}{\ensuremath{\mathnormal\upuparrows}} 54 | \newunicodechar{π}{\ensuremath{\mathnormal\pi}} 55 | \newunicodechar{γ}{\ensuremath{\mathnormal\gamma}} 56 | \newunicodechar{δ}{\ensuremath{\mathnormal\delta}} 57 | \newunicodechar{Ϝ}{\ensuremath{\mathnormal\digamma}} 58 | \newunicodechar{𝔽}{\ensuremath{\mathnormal\mathbb{F}}} 59 | \newunicodechar{ℙ}{\ensuremath{\mathnormal\mathbb{P}}} 60 | \newunicodechar{↔}{\ensuremath{\mathnormal\leftrightarrow}} 61 | \newunicodechar{≺}{\ensuremath{\mathnormal\prec}} 62 | \newunicodechar{ₘ}{\ensuremath{\mathnormal{_m}}} 63 | \newunicodechar{ₙ}{\ensuremath{\mathnormal{_m}}} 64 | \newunicodechar{𝓥}{\ensuremath{\mathnormal\mathcal{V}}} 65 | \newunicodechar{𝔳}{\ensuremath{\mathnormal\mathfrak{v}}} 66 | \newunicodechar{₁}{\ensuremath{\mathnormal{_1}}} 67 | \newunicodechar{⁼}{\ensuremath{\mathnormal{^=}}} 68 | 69 | 70 | \usepackage[backend=biber, backref=true, maxbibnames = 10, style = alphabetic]{biblatex} 71 | \usepackage[bookmarks=true, colorlinks=true, linkcolor=blue!50!black, 72 | citecolor=orange!50!black, urlcolor=orange!50!black, pdfencoding=unicode]{hyperref} 73 | \usepackage[capitalize]{cleveref} 74 | 75 | \usepackage{tikz} 76 | 77 | \usepackage{amssymb} 78 | \usepackage{newpxtext} 79 | \usepackage[varg,bigdelims]{newpxmath} 80 | \usepackage{mathrsfs} 81 | \usepackage{dutchcal} 82 | \usepackage{fontawesome} 83 | \usepackage{ebproof} 84 | \usepackage{stmaryrd} 85 | \usepackage{mathpartir} 86 | \usepackage{quiver} 87 | 88 | 89 | % cleveref % 90 | \newcommand{\creflastconjunction}{, and\nobreakspace} % serial comma 91 | \crefformat{enumi}{\##2#1#3} 92 | \crefalias{chapter}{section} 93 | 94 | 95 | % biblatex % 96 | \addbibresource{Library20211226.bib} 97 | 98 | % hyperref % 99 | \hypersetup{final} 100 | 101 | % enumitem % 102 | \setlist{nosep} 103 | \setlistdepth{6} 104 | 105 | 106 | 107 | % tikz % 108 | 109 | 110 | 111 | \usetikzlibrary{ 112 | cd, 113 | math, 114 | decorations.markings, 115 | decorations.pathreplacing, 116 | positioning, 117 | arrows.meta, 118 | shapes, 119 | shadows, 120 | shadings, 121 | calc, 122 | fit, 123 | quotes, 124 | intersections, 125 | circuits, 126 | circuits.ee.IEC 127 | } 128 | 129 | \tikzset{ 130 | biml/.tip={Glyph[glyph math command=triangleleft, glyph length=.95ex]}, 131 | bimr/.tip={Glyph[glyph math command=triangleright, glyph length=.95ex]}, 132 | } 133 | 134 | \tikzset{ 135 | tick/.style={postaction={ 136 | decorate, 137 | decoration={markings, mark=at position 0.5 with 138 | {\draw[-] (0,.4ex) -- (0,-.4ex);}}} 139 | } 140 | } 141 | \tikzset{ 142 | slash/.style={postaction={ 143 | decorate, 144 | decoration={markings, mark=at position 0.5 with 145 | {\draw[-] (.3ex,.3ex) -- (-.3ex,-.3ex);}}} 146 | } 147 | } 148 | 149 | \newcommand{\upp}{\begin{tikzcd}[row sep=6pt]~\\~\ar[u, bend left=50pt, looseness=1.3, start anchor=east, end anchor=east]\end{tikzcd}} 150 | 151 | \newcommand{\bito}[1][]{ 152 | \begin{tikzcd}[ampersand replacement=\&, cramped]\ar[r, biml-bimr, "#1"]\&~\end{tikzcd} 153 | } 154 | \newcommand{\bifrom}[1][]{ 155 | \begin{tikzcd}[ampersand replacement=\&, cramped]\ar[r, bimr-biml, "{#1}"]\&~\end{tikzcd} 156 | } 157 | \newcommand{\bifromlong}[2][]{ 158 | \begin{tikzcd}[ampersand replacement=\&, column sep=#2, cramped]\ar[r, bimr-biml, "#1"]\&~\end{tikzcd} 159 | } 160 | 161 | % Adjunctions 162 | \newcommand{\adj}[5][30pt]{%[size] Cat L, Left, Right, Cat R. 163 | \begin{tikzcd}[ampersand replacement=\&, column sep=#1] 164 | #2\ar[r, shift left=7pt, "#3"] 165 | \ar[r, phantom, "\scriptstyle\Rightarrow"]\& 166 | #5\ar[l, shift left=7pt, "#4"] 167 | \end{tikzcd} 168 | } 169 | 170 | \newcommand{\adjr}[5][30pt]{%[size] Cat R, Right, Left, Cat L. 171 | \begin{tikzcd}[ampersand replacement=\&, column sep=#1] 172 | #2\ar[r, shift left=7pt, "#3"]\& 173 | #5\ar[l, shift left=7pt, "#4"] 174 | \ar[l, phantom, "\scriptstyle\Leftarrow"] 175 | \end{tikzcd} 176 | } 177 | 178 | \newcommand{\xtickar}[1]{\begin{tikzcd}[baseline=-0.5ex,cramped,sep=small,ampersand 179 | replacement=\&]{}\ar[r,tick, "{#1}"]\&{}\end{tikzcd}} 180 | \newcommand{\xslashar}[1]{\begin{tikzcd}[baseline=-0.5ex,cramped,sep=small,ampersand 181 | replacement=\&]{}\ar[r,tick, "{#1}"]\&{}\end{tikzcd}} 182 | 183 | 184 | 185 | 186 | % amsthm % 187 | \theoremstyle{definition} 188 | \newtheorem{definitionx}{Definition}[chapter] 189 | \newtheorem{examplex}[definitionx]{Example} 190 | \newtheorem{remarkx}[definitionx]{Remark} 191 | \newtheorem{notation}[definitionx]{Notation} 192 | 193 | 194 | \theoremstyle{plain} 195 | 196 | \newtheorem{theorem}[definitionx]{Theorem} 197 | \newtheorem{proposition}[definitionx]{Proposition} 198 | \newtheorem{corollary}[definitionx]{Corollary} 199 | \newtheorem{lemma}[definitionx]{Lemma} 200 | \newtheorem{warning}[definitionx]{Warning} 201 | \newtheorem*{theorem*}{Theorem} 202 | \newtheorem*{proposition*}{Proposition} 203 | \newtheorem*{corollary*}{Corollary} 204 | \newtheorem*{lemma*}{Lemma} 205 | \newtheorem*{warning*}{Warning} 206 | %\theoremstyle{definition} 207 | %\newtheorem{definition}[theorem]{Definition} 208 | %\newtheorem{construction}[theorem]{Construction} 209 | 210 | \newenvironment{example} 211 | {\pushQED{\qed}\renewcommand{\qedsymbol}{$\lozenge$}\examplex} 212 | {\popQED\endexamplex} 213 | 214 | \newenvironment{remark} 215 | {\pushQED{\qed}\renewcommand{\qedsymbol}{$\lozenge$}\remarkx} 216 | {\popQED\endremarkx} 217 | 218 | \newenvironment{definition} 219 | {\pushQED{\qed}\renewcommand{\qedsymbol}{$\lozenge$}\definitionx} 220 | {\popQED\enddefinitionx} 221 | 222 | 223 | %-------- Single symbols --------% 224 | 225 | \DeclareSymbolFont{stmry}{U}{stmry}{m}{n} 226 | \DeclareMathSymbol\fatsemi\mathop{stmry}{"23} 227 | 228 | \DeclareFontFamily{U}{mathx}{\hyphenchar\font45} 229 | \DeclareFontShape{U}{mathx}{m}{n}{ 230 | <5> <6> <7> <8> <9> <10> 231 | <10.95> <12> <14.4> <17.28> <20.74> <24.88> 232 | mathx10 233 | }{} 234 | \DeclareSymbolFont{mathx}{U}{mathx}{m}{n} 235 | \DeclareFontSubstitution{U}{mathx}{m}{n} 236 | \DeclareMathAccent{\widecheck}{0}{mathx}{"71} 237 | 238 | 239 | %-------- Renewed commands --------% 240 | 241 | \renewcommand{\ss}{\subseteq} 242 | 243 | %-------- Other Macros --------% 244 | 245 | 246 | \DeclarePairedDelimiter{\present}{\langle}{\rangle} 247 | \DeclarePairedDelimiter{\copair}{[}{]} 248 | \DeclarePairedDelimiter{\floor}{\lfloor}{\rfloor} 249 | \DeclarePairedDelimiter{\ceil}{\lceil}{\rceil} 250 | \DeclarePairedDelimiter{\corners}{\ulcorner}{\urcorner} 251 | \DeclarePairedDelimiter{\ihom}{[}{]} 252 | 253 | \DeclareMathOperator{\Hom}{Hom} 254 | \DeclareMathOperator{\Mor}{Mor} 255 | \DeclareMathOperator{\dom}{dom} 256 | \DeclareMathOperator{\cod}{cod} 257 | \DeclareMathOperator{\idy}{idy} 258 | \DeclareMathOperator{\comp}{com} 259 | \DeclareMathOperator*{\colim}{colim} 260 | \DeclareMathOperator{\im}{im} 261 | \DeclareMathOperator{\ob}{Ob} 262 | \DeclareMathOperator{\Tr}{Tr} 263 | \DeclareMathOperator{\el}{El} 264 | 265 | 266 | 267 | 268 | \newcommand{\const}[1]{\texttt{#1}}%a constant, or named element of a set 269 | \newcommand{\Set}[1]{\mathsf{#1}}%a named set 270 | \newcommand{\ord}[1]{\mathsf{#1}}%an ordinal 271 | \newcommand{\cat}[1]{\mathcal{#1}}%a generic category 272 | \newcommand{\Cat}[1]{\mathbf{#1}}%a named category 273 | \newcommand{\fun}[1]{\mathrm{#1}}%a function 274 | \newcommand{\Fun}[1]{\mathit{#1}}%a named functor 275 | 276 | 277 | 278 | 279 | \newcommand{\id}{\mathrm{id}} 280 | \newcommand{\then}{\mathbin{\fatsemi}} 281 | 282 | \newcommand{\cocolon}{:\!} 283 | 284 | 285 | \newcommand{\iso}{\cong} 286 | \newcommand{\too}{\longrightarrow} 287 | \newcommand{\tto}{\rightrightarrows} 288 | \newcommand{\To}[2][]{\xrightarrow[#1]{#2}} 289 | \renewcommand{\Mapsto}[1]{\xmapsto{#1}} 290 | \newcommand{\Tto}[3][13pt]{\begin{tikzcd}[sep=#1, cramped, ampersand replacement=\&, text height=1ex, text depth=.3ex]\ar[r, shift left=2pt, "#2"]\ar[r, shift right=2pt, "#3"']\&{}\end{tikzcd}} 291 | \newcommand{\Too}[1]{\xrightarrow{\;\;#1\;\;}} 292 | \newcommand{\from}{\leftarrow} 293 | \newcommand{\ffrom}{\leftleftarrows} 294 | \newcommand{\From}[1]{\xleftarrow{#1}} 295 | \newcommand{\Fromm}[1]{\xleftarrow{\;\;#1\;\;}} 296 | \newcommand{\surj}{\twoheadrightarrow} 297 | \newcommand{\inj}{\rightarrowtail} 298 | \newcommand{\wavyto}{\rightsquigarrow} 299 | \newcommand{\lollipop}{\multimap} 300 | \newcommand{\imp}{\Rightarrow} 301 | \renewcommand{\iff}{\Leftrightarrow} 302 | \newcommand{\down}{\mathbin{\downarrow}} 303 | \newcommand{\fromto}{\leftrightarrows} 304 | \newcommand{\tickar}{\xtickar{}} 305 | \newcommand{\slashar}{\xslashar{}} 306 | 307 | 308 | 309 | \newcommand{\inv}{^{-1}} 310 | \newcommand{\op}{^\tn{op}} 311 | 312 | \newcommand{\tn}[1]{\textnormal{#1}} 313 | \newcommand{\ol}[1]{\overline{#1}} 314 | \newcommand{\ul}[1]{\underline{#1}} 315 | \newcommand{\wt}[1]{\widetilde{#1}} 316 | \newcommand{\wh}[1]{\widehat{#1}} 317 | \newcommand{\wc}[1]{\widecheck{#1}} 318 | \newcommand{\ubar}[1]{\underaccent{\bar}{#1}} 319 | 320 | 321 | 322 | \newcommand{\bb}{\mathbb{B}} 323 | \newcommand{\cc}{\mathbb{C}} 324 | \newcommand{\nn}{\mathbb{N}} 325 | \newcommand{\pp}{\mathbb{P}} 326 | \newcommand{\qq}{\mathbb{Q}} 327 | \newcommand{\zz}{\mathbb{Z}} 328 | \newcommand{\rr}{\mathbb{R}} 329 | 330 | 331 | \newcommand{\finset}{\Cat{Fin}} 332 | \newcommand{\smset}{\Cat{Set}} 333 | \newcommand{\smcat}{\Cat{Cat}} 334 | \newcommand{\catsharp}{\Cat{Cat}^{\sharp}} 335 | \newcommand{\ppolyfun}{\mathbb{P}\Cat{olyFun}} 336 | \newcommand{\ccatsharp}{\mathbb{C}\Cat{at}^{\sharp}} 337 | \newcommand{\ccatsharpdisc}{\mathbb{C}\Cat{at}^{\sharp}_{\tn{disc}}} 338 | \newcommand{\ccatsharplin}{\mathbb{C}\Cat{at}^{\sharp}_{\tn{lin}}} 339 | \newcommand{\ccatsharpdisccon}{\mathbb{C}\Cat{at}^{\sharp}_{\tn{disc,con}}} 340 | \newcommand{\sspan}{\mathbb{S}\Cat{pan}} 341 | \newcommand{\en}{\Cat{End}} 342 | 343 | \newcommand{\List}{\Fun{List}} 344 | \newcommand{\set}{\tn{-}\Cat{Set}} 345 | 346 | 347 | 348 | 349 | \newcommand{\yon}{\mathcal{y}} 350 | \newcommand{\poly}{\Cat{Poly}} 351 | \newcommand{\polycart}{\poly^{\Cat{Cart}}} 352 | \newcommand{\ppoly}{\mathbb{P}\Cat{oly}} 353 | \newcommand{\0}{\textsf{0}} 354 | \newcommand{\1}{\tn{\textsf{1}}} 355 | \newcommand{\U}{\tn{\textsf{U}}} 356 | \newcommand{\tri}{\mathbin{\triangleleft}} 357 | \newcommand{\triright}{\mathbin{\triangleright}} 358 | \newcommand{\tripow}[1]{^{\tri #1}} 359 | \newcommand{\indep}{\Fun{Indep}} 360 | \newcommand{\duoid}{\Fun{Duoid}} 361 | \newcommand{\jump}{\pi} 362 | \newcommand{\jumpmap}{\ol{\jump}} 363 | \newcommand{\founds}{\Yleft} 364 | 365 | 366 | % lenses 367 | \newcommand{\biglens}[2]{ 368 | \begin{bmatrix}{\vphantom{f_f^f}#2} \\ {\vphantom{f_f^f}#1} \end{bmatrix} 369 | } 370 | \newcommand{\littlelens}[2]{ 371 | \begin{bsmallmatrix}{\vphantom{f}#2} \\ {\vphantom{f}#1} \end{bsmallmatrix} 372 | } 373 | \newcommand{\lens}[2]{ 374 | \relax\if@display 375 | \biglens{#1}{#2} 376 | \else 377 | \littlelens{#1}{#2} 378 | \fi 379 | } 380 | 381 | 382 | 383 | \newcommand{\qand}{\quad\text{and}\quad} 384 | \newcommand{\qqand}{\qquad\text{and}\qquad} 385 | 386 | 387 | \newcommand{\coto}{\nrightarrow} 388 | \newcommand{\cofun}{{\raisebox{2pt}{\resizebox{2.5pt}{2.5pt}{$\setminus$}}}} 389 | 390 | \newcommand{\coalg}{\tn{-}\Cat{Coalg}} 391 | 392 | \newcommand{\bic}[2]{{}_{#1}\Cat{Comod}_{#2}} 393 | 394 | % ---- Changeable document parameters ---- % 395 | 396 | \linespread{1.1} 397 | \allowdisplaybreaks 398 | \setsecnumdepth{subsection} 399 | \settocdepth{subsection} 400 | \setlength{\parindent}{15pt} 401 | \setcounter{tocdepth}{1} -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | TAR = $(wildcard *.pdf) 2 | 3 | .PHONY: all clean 4 | 5 | all: $(TAR) 6 | 7 | poly-universes.pdf: poly-universes.lagda.md poly-universes.tex header.tex 8 | pandoc poly-universes.lagda.md -o poly-universes.tex --template default.latex -H header.tex 9 | pdflatex poly-universes.tex 10 | 11 | clean: 12 | rm -f $(TAR) -------------------------------------------------------------------------------- /part1.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/part1.agdai -------------------------------------------------------------------------------- /part1.lagda.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Polynomial Universes and Dependent Types 3 | author: 4 | - C.B. Aberlé 5 | - David I. Spivak 6 | documentclass: memoir 7 | classoption: 8 | - 11pt 9 | - oneside 10 | - article 11 | --- 12 | 13 | \begin{abstract} 14 | 15 | Awodey, later with Newstead, showed how polynomial pseudomonads $(u,\1,\Sigma)$ with extra structure (termed "natural models" by Awodey) hold within them the syntax and rules for dependent type theory. Their work presented these ideas clearly but ultimately led them outside of the category of polynomial functors in order to explain all of the structure possessed by such models of type theory. 16 | 17 | This paper builds off that work---explicating the syntax and rules for dependent type theory by axiomatizing them \emph{entirely} in the language of polynomial functors. In order to handle the higher-categorical coherences required for such an explanation, we work with polynomial functors internally in the language of Homotopy Type Theory, which allows for higher-dimensional structures such as pseudomonads, etc. to be expressed purely in terms of the structure of a suitably-chosen $\infty$-category of polynomial functors. The move from set theory to Homotopy Type Theory thus has a twofold effect of enabling a simpler exposition of natural models, which is at the same time amenable to formalization in a proof assistant, such as Agda. 18 | 19 | Moreover, the choice to remain firmly within the setting of polynomial functors reveals many additional structures of natural models that were otherwise left implicit or not considered by Awodey \& Newstead. Chief among these, we highlight the fact that every polynomial pseudomonad $(u,\1,\Sigma)$ as above that is also equipped with structure to interpret dependent product types gives rise to a self-distributive law $u\tri u\to u\tri u$, which witnesses the usual distributive law of dependent products over dependent sums. 20 | 21 | \end{abstract} 22 | 23 | # Introduction 24 | 25 | Dependent type theory \cite{martin-lof1975intuitionistic} was founded by Per Martin-Löf in 1975 (among others) to formalize constructive mathematics. The basic idea is that the \emph{order of events} is fundamental to the mathematical story arc: when playing out any specific example story in that arc, the beginning of the story affects not only the later events, but even the very terms with which the later events will be described. For example, in the story arc of conditional probability, one may say ``now if the set $P$ that we are asked to condition on happens to have measure zero, we must stop; but assuming that's not the case then the result will be a new probability measure.'' Here the story teller is saying that no terms will describe what happens if $P$ has measure zero, whereas otherwise the terms of standard probability will apply. 26 | 27 | Dependent types form a logical system with syntax, rules of computation, and methods of deduction. In \cite{awodey2014natural,awodey2018polynomial}, Awodey and later Newstead show that there is a strong connection between dependent type theory and polynomial functors, via their concept of *natural models*, which cleanly solve the problem of *strictififying* certain identities that typically hold only up to isomorphism in arbitrary categories, but must hold *strictly* in order for these to soundly model dependent type theory. The solution to this problem offered by Awodey and Newstead makes use of the type-theoretic concept of a *universe*. Such universes then turn out to naturally be regarded as polynomial functors on a suitably-chosen category of presheaves, satisfying a certain *representability* condition. 28 | 29 | Although the elementary structure of natural models is thus straightforwardly described by considering them as objects in the category of polynomial functors, Awodey and Newstead were ultimately led outside of this category in order to fully explicate those parts of natural models that require identities to hold only *up to isomorphism*, rather than strictly. There is thus an evident tension between *strict* and *weak* identities that has not yet been fully resolved in the story of natural models. In the present work, we build on Awodey and Newstead's work to fully resolve this impasse by showing how type universes can be fully axiomatized in terms of polynomial functors, by working with polynomial functors internally in the language of *Homotopy Type Theory* (HoTT). We thus come full circle from Awodey's original motivation to develop natural models *of* Homotopy Type Theory, to describing natural models *in* Homotopy Type Theory. 30 | 31 | The ability for us to tell the story of natural models as set entirely in the category of polynomial functors has a great simplifying effect upon the resultant theory, and reveals many additional structures, both of polynomial universes, and of the category of polynomial functors as a whole. As an illustration of this, we show how every polynomial universe $u$, regarded as a polynomial pseudomonad with additional structure, gives rise to self-distributive law $u\tri u\to u\tri u$, which in particular witnesses the usual distributive law of dependent products over dependent sums. 32 | 33 | Moreover, the move from set theory to HoTT as a setting in which to tell this story enables new tools to be applied for its telling. In particular, the account of polynomial universes we develop is well-suited to formalization in a proof assistant, and we present such a formalization in Agda. This paper is thus itself a literate Agda document in which all results have been fully formalized and checked for validity. 34 | 35 | ```agda 36 | {-# OPTIONS --without-K --rewriting #-} 37 | module part1 where 38 | 39 | open import Agda.Primitive 40 | open import Agda.Builtin.Sigma 41 | open import Agda.Builtin.Unit 42 | ``` 43 | 44 | The structure of this paper is as follows: 45 | 46 | # Background on Type Theory, Natural Models & HoTT 47 | 48 | We begin with a recap of natural models, dependent type theory, and HoTT, taking this also as an opportunity to introduce the basics of our Agda formalization. 49 | 50 | ## Dependent Types and their Categorical Semantics 51 | 52 | The question "what is a type" is as deep as it is philosophically fraught. For present purposes, however, we need not concern ourselves so much directly with what (dependent) type *are*, as with what they can *do*, and how best to mathematically model this behavior. Suffice it to say, then, that a type specifies rules for both constructing and using the *inhabitants* of that type in arbitrary contexts of usage. Following standard conventions, we use the notation `a : A` to mean that `a` is an inhabitant of type `A`. 53 | 54 | In Agda, one example of such a type is the *unit type* `⊤`, which is defined to have a single inhabitant `tt : ⊤`, such that for any other inhabitant `x : ⊤` we must have `x = tt`. 55 | 56 | Another type (or rather, family of types) of particular importance is the *universe* of types `Type`, whose inhabitants themsleves represent types.[^1] So e.g. to say that `⊤`, as defined above, is a type, we may simply write `⊤ : Type`. 57 | 58 | [^1]: For consistency with the usage of the term "set" in HoTT (whereby sets are types satisfying a certain *truncation* condition, to be explained shortly,) we relabel Agda's universes of types as `Type`, rather than the default `Set`. 59 | 60 | ```agda 61 | Type : (ℓ : Level) → Set (lsuc ℓ) 62 | Type ℓ = Set ℓ 63 | ``` 64 | 65 | Given a type `A`, one may in turn consider families of types `B x` indexed by, or *dependent* upon aribtrary inhabitants `x : A`. In agda, we represent such a type family `B` as a function `A → Type`. 66 | 67 | Given a type `A : Type` and a family of types `B : A → Type` as above, two key examples of types we may construct are: 68 | 69 | * The *dependent function type* `(x : A) → B x`, whose inhabitants are functions `λ x → f x` such that, for all `a : A`, we have `f a : B a`. 70 | * The *dependent pair type* `Σ A B`, whose inhabitants are of the form `(a , b)` for `a : A` and `b : B a`, such that there are functions `fst : Σ A B → A` and `snd : (p : Σ A B) → B (fst p)`. 71 | 72 | Note that in the case where `B` does not depend upon `x : A` (i.e. the variable `x` does not appear in the expression for `B`), these correspond to the more familiar function type `A → B` and pair type `A × B`, respectively. E.g. we can define the Cartesian product of two types `A` and `B` as follows: 73 | 74 | ```agda 75 | _×_ : ∀ {ℓ κ} (A : Type ℓ) (B : Type κ) → Type (ℓ ⊔ κ) 76 | A × B = Σ A (λ _ → B) 77 | ``` 78 | 79 | In more traditional type-theoretic notation, one might see the rules for these types written as follows: $$ 80 | \inferrule{}{\Gamma \vdash \top : \mathsf{Type}} \qquad \inferrule{}{\Gamma \vdash \mathsf{tt} : \top} \qquad \inferrule{\Gamma \vdash x : \top}{\Gamma \vdash x = tt} 81 | $$ $$ 82 | \inferrule{\Gamma \vdash A : \mathsf{Type}\\ \Gamma, x : A \vdash B[x] : \mathsf{Type}}{\Gamma \vdash \Pi x : A . B[x] : \mathsf{Type}} \qquad \inferrule{\Gamma \vdash A : \mathsf{Type}\\ \Gamma, x : A \vdash B[x] : \mathsf{Type}}{\Gamma \vdash \Sigma x : A . B[x] : \mathsf{Type}} 83 | $$ $$ 84 | \inferrule{\Gamma, x : A \vdash f[x] : B[x]}{\Gamma \vdash \lambda x . f[x] : \Pi x : A . B[x]} \qquad \inferrule{\Gamma \vdash a : A\\ \Gamma \vdash b : B[a]}{\Gamma \vdash (a , b) : \Sigma x : A . B[x]} 85 | $$ $$ 86 | \inferrule{\Gamma \vdash f : \Pi x : A . B[x]\\ \Gamma \vdash a : A}{\Gamma \vdash f a : B[a]} \qquad \inferrule{\Gamma \vdash p : \Sigma x : A . B[x]}{\Gamma \vdash \pi_1(p) : A} \quad \inferrule{\Gamma \vdash p : \Sigma x : A . B[x]}{\Gamma \vdash \pi_2(p) : B[\pi_1(p)]} 87 | $$ $$ 88 | (\lambda x . f[x]) a = f[a] \qquad \pi_1(a , b) = a \quad \pi_2(a , b) = b 89 | $$ $$ 90 | f = \lambda x . fx \qquad p = (\pi_1(p) , \pi_2(p)) 91 | $$ 92 | 93 | The constructors $\lambda$ and $(- , -)$ are called the *introduction* forms of $\Pi x : A . B[x]$ and $\Sigma x : A . B[x]$, while $f a$ and $\pi_1(p), ~ \pi_2(p)$ are called the *elimination* forms of these types, respectively. One may wonder why all typing judgments in the above rules have been decorated with annotations of the form $\Gamma \vdash$, for some $\Gamma$. In these cases, $\Gamma$ is the *context* of the corresponding judgment, used to keep track of the types of variables that may appear in that judgment. 94 | 95 | Although contexts may seem rather trivial from a syntactic perspective, they are key to understanding the categorical semantics of dependent type theory. In particular, when modelling a dependent type theory as a category, it is the *contexts* which form the objects of this category, with morphisms between contexts being *substitutions* of terms in the domain context for the variables of the codomain context. A type $A$ dependent upon variables in a context $\Gamma$ is then interpreted as a morphism (i.e. substitution) $\Gamma, x : A \to \Gamma$, whose domain represents the context $\Gamma$ extended with a variable of type $A$. We then interpret a term $a$ of type $A$ in context $\Gamma$ as a *section* of the display map representing $A$, i.e. $$ 96 | \begin{tikzcd} 97 | \Gamma & {\Gamma, x : A} \\ 98 | & \Gamma 99 | \arrow["a", from=1-1, to=1-2] 100 | \arrow[Rightarrow, no head, from=1-1, to=2-2] 101 | \arrow["A", from=1-2, to=2-2] 102 | \end{tikzcd} 103 | $$ Hence for each context $\Gamma$, there is a category $\mathbf{Ty}[\Gamma]$, which is the full subcategory of the slice category $\mathcal{C}/\Gamma$ consisting of all display maps, wherein objects correspond to types in context $\Gamma$, and morphisms correspond to terms. 104 | 105 | In typical categorical semantics, given a substitution $f : \Gamma \to \Delta$, and a type $A : \Delta, x : A \to \Delta$, we then interpret the action of $f$ on $A$ as a pullback: $$ 106 | \begin{tikzcd} 107 | {\Gamma, x : A[f]} & {\Delta, x : A} \\ 108 | \Gamma & \Delta 109 | \arrow[from=1-1, to=1-2] 110 | \arrow["{A[f]}"', from=1-1, to=2-1] 111 | \arrow["\lrcorner"{anchor=center, pos=0.125}, draw=none, from=1-1, to=2-2] 112 | \arrow["A", from=1-2, to=2-2] 113 | \arrow["f"', from=2-1, to=2-2] 114 | \end{tikzcd} 115 | $$ In particular, then, any display map $A : \Gamma, x : A \to \Gamma$ induces a functor $\mathbf{Ty}[\Gamma] \to \mathbf{Ty}[\Gamma, x : A]$ by substitution along $A$. The left and right adjoints to this functor (if they exist) then correspond to dependent pair and dependent function types, respectively. 116 | 117 | So far, we have told a pleasingly straightforward story of how to interpret the syntax of dependent type theory categorically. Unfortunately, this story is a fantasy, and the interpretation of type-theoretic syntax into categorical semantics sketched above is unsound, as it stands. The problem in essentials is that, in the syntax of type theory, substitution is strictly associative – i.e. given substitutions $f : \Gamma \to \Delta$ and $g : \Delta \to \Theta$ and a type `A`, we have $A[g][f] = A[g[f]]$; however, in the above categorical semantics, such iterated substitution is interpreted via successively taking pullbacks, which is in general only associative up to isomorphism. It seems, then, that something more is needed to account for this kind of *strictness* in the semantics of dependent type theory. [^2] It is precisely this problem which natural models exist to solve. 118 | 119 | [^2]: Something something Beck-Chevalley... 120 | 121 | ## Natural Models 122 | 123 | The key insight of Awodey in formulating the notion of a natural model is that the problem of strictness in the semantics of type theory has, in a sense, already been solved by the notion of *type universes*, such as `Type` as introduced above. Given a universe of types $\mathcal{U}$, rather than representing dependent types as display maps, and substitution as pullback, we can simply represent a family of types $B[x]$ dependent upon a type $A$ as a function $A \to \mathcal{U}$, with substitution then given by precomposition, which is automatically strictly associative. 124 | 125 | To interpret the syntax of dependent type theory in a category $\mathcal{C}$ of contexts and substitutions, it therefore suffices to *embed* $\mathcal{C}$ into a category whose type-theoretic internal language posesses such a universe whose types correspond to those of $\mathcal{C}$. For this purpose, we work in the category of *prehseaves* $\mathbf{Set}^{\mathcal{C}^{op}}$, with the embedding $\mathcal{C} \hookrightarrow \mathbf{Set}^{\mathcal{C}^{op}}$ being nothing other than the Yoneda embedding. 126 | 127 | The universe $\mathcal{U}$ is then given by an object of $\mathbf{Set}^{\mathcal{C}^{op}}$, i.e. an assignment, to each context $\Gamma$, of a set $\mathsf{Ty}[\Gamma]$ of types in context $\Gamma$, with functions $\mathsf{Ty}[\Delta] \to \mathsf{Ty}[\Gamma]$ for each substitution $f : \Gamma \to \Delta$ that compose associatively, together with a $\mathcal{U}$-indexed family of objects $u \in \mathbf{Set}^{\mathcal{C}^{op}}/\mathcal{U}$, i.e. a natural transformation $u : \mathcal{U}_\bullet \Rightarrow \mathcal{U}$, where for each context $\Gamma$ and type $A \in \mathsf{Ty}[\Gamma]$, the fibre of $u_\Gamma$ over $A$ is the set $\mathsf{Tm}[\Gamma,A]$ of inhabitants of $A$ in context $\Gamma$. 128 | 129 | The condition that all types in $\mathcal{U}$ "belong to $\mathcal{C}$", in an appropriate sense, can then be expressed by requiring $u$ to be *representable*, i.e. for any representable $\gamma \in \mathbf{Set}^{\mathcal{C}^{op}}$ with a natural transformation $\alpha : \gamma \Rightarrow \mathcal{U}$, the pullback $$ 130 | \begin{tikzcd} 131 | {\mathcal{\gamma} \times_{\alpha, u} \mathcal{U}_\bullet} & {\mathcal{U}_\bullet} \\ 132 | \gamma & {\mathcal{U}} 133 | \arrow[Rightarrow, from=1-1, to=1-2] 134 | \arrow["{u[\alpha]}"', Rightarrow, from=1-1, to=2-1] 135 | \arrow["\lrcorner"{anchor=center, pos=0.125}, draw=none, from=1-1, to=2-2] 136 | \arrow["u", Rightarrow, from=1-2, to=2-2] 137 | \arrow["\alpha"', Rightarrow, from=2-1, to=2-2] 138 | \end{tikzcd} 139 | $$ of $u$ along $\alpha$ is representable. 140 | 141 | The question, then, is how to express that $\mathcal{C}$ has dependent pair types, dependent function types, etc., in terms of the structure of $u$. A further insight of Awodey, toward answering this question, is that $u$ gives rise to a functor (indeed, a *polynomial functor*) $\overline{u} : \mathbf{Set}^{\mathcal{C}^{op}} \to \mathbf{Set}^{\mathcal{C}^{op}}$, defined as follows $$ 142 | \overline{u}(P)(\Gamma) = \sum_{A : \mathsf{Ty}[\Gamma]} P(\Gamma)^{\mathsf{Tm}[\Gamma, A]} 143 | $$ and much of the type-theoretic structure of $u$ can be accounted for in terms of this functor. For instance (for reasons to be explained shortly), dependent pair types are given by a natural transformation $\sigma : \overline{u} \circ \overline{u} \Rightarrow \overline{u}$, that is *Cartesian* in that, for every $\alpha : P \Rightarrow Q$, the following naturality square is a pullback $$ 144 | \begin{tikzcd} 145 | {\overline{u}(\overline{u}(P))} & {\overline{u}(\overline{u}(Q))} \\ 146 | {\overline{u}(P)} & {\overline{u}(Q)} 147 | \arrow["{\overline{u}(\overline{u}(\alpha))}", Rightarrow, from=1-1, to=1-2] 148 | \arrow["{\sigma_P}"', Rightarrow, from=1-1, to=2-1] 149 | \arrow["\lrcorner"{anchor=center, pos=0.125}, draw=none, from=1-1, to=2-2] 150 | \arrow["{\sigma_Q}", Rightarrow, from=1-2, to=2-2] 151 | \arrow["{\overline{u}(\alpha)}"', Rightarrow, from=2-1, to=2-2] 152 | \end{tikzcd} 153 | $$ 154 | 155 | A question that arises, then, is what structure such a natural transformation interpreting dependent pair types must possess. It is natural to think that $\sigma$, along with a suitably-chosen natural transformation $Id \Rightarrow \overline{u}$, ought to give $\overline{u}$ the structure of a monad. However, this turns out to be too strong a requirement, as it amounts to asking that $\Sigma x : A . (\Sigma y : B[x] . C[x,y]) = \Sigma (x,y) : (\Sigma x : A . B[x]) . C[x,y]$, when in general this identity only holds up to isomorphism. Hence we seem to have crossed over from Scylla of our semantics for dependent type theory not being strict enough to interpret those identities we expect to hold strictly, to the Charybdis of them now being too strict to interpret the identities we expect to hold only up to isomorphism. It was for this reason that Awodey & Newstead were forced to ultimately go beyond Polynomial functors in their accounts of natural models. 156 | 157 | However, another possibility exists to solve this dilemma – to use the language of HoTT itself to reason about such equality-up-to-isomorphism in natural models. For this purpose, rather than taking natural models to be certain (representable) morphisms in $\mathbf{Set}^{\mathcal{C}^{op}}$, we can instead expand the mathematical universe in which these models live to $\mathbf{\infty Grpd}^{\mathcal{C}^{op}}$, which, as an $\infty$-topos, has HoTT as its internal language. Taking advantage of this fact, we can use HoTT itself as a language for studying the semantics of type theory, by postulating an abstract type $\mathcal{U}$ together with a type family $u : \mathcal{U} \to \mathsf{Type}$, corresponding to a representable natural transformation $u : \mathcal{U}_\bullet \Rightarrow \mathcal{U}$ as above. 158 | 159 | What remains, then, is to show how the various type-theoretic properties of such natural models can be expressed in terms of polynomial functors in the language of HoTT, and the complex identities to which these give rise. For this purpose, we begin with a recap of the basics of HoTT, before launching into a development of the theory of polynomial functors within HoTT, with an eye toward the latter's use in the study of natural models. 160 | 161 | ## Homotopy Type Theory 162 | 163 | ### The Identity Type 164 | 165 | Given elements `a,b : A` for some type `A`, the identity type `a ≡ b` is inductively generated from the single constructor `refl : {x : A} → x ≡ x`, witnessing reflexivity of equality. 166 | 167 | ```agda 168 | open import Agda.Builtin.Equality 169 | open import Agda.Builtin.Equality.Rewrite 170 | ``` 171 | 172 | The core insight of Homotopy Type Theory is that the presence of (intensional) identity types in a system of dependent type theory endows each type with the structure of an $\infty$-groupoid, and endows each function between types with the structure of a functor between $\infty$-groupoids, etc. This allows a wealth of higher-categorical properties and structures to be defined and studied *internally* in the language of dependent type theory. 173 | 174 | Since an invocation of reflexivity typically occurs at the end of an equality proof, we introduce the notation `□` as a shorthand for `refl` as follows: 175 | 176 | ```agda 177 | _□ : ∀ {ℓ} {A : Type ℓ} (a : A) → a ≡ a 178 | a □ = refl 179 | ``` 180 | 181 | The inductive generation of `a ≡ b` from `refl` then gives rise to the operation of *transport* that allows an inhabitant of the type `B a` to be converted to an inhabitant of `B b` for any type family `B : (x : A) → Type`. 182 | 183 | ```agda 184 | transp : ∀ {ℓ κ} {A : Type ℓ} (B : A → Type κ) {a a' : A} 185 | → (e : a ≡ a') → B a → B a' 186 | transp B refl b = b 187 | ``` 188 | 189 | Transitivity of equality then follows in the usual way. Note, however, that we take advantage of Agda's support for mixfix notation to present transitivity in such a way as to streamline both the reading and writing of equality proofs: 190 | 191 | ```agda 192 | _≡〈_〉_ : ∀ {ℓ} {A : Type ℓ} (a : A) {b c : A} 193 | → a ≡ b → b ≡ c → a ≡ c 194 | a ≡〈 e 〉 refl = e 195 | ``` 196 | 197 | Symmetry of equality follows similarly: 198 | 199 | ```agda 200 | sym : ∀ {ℓ} {A : Type ℓ} {a a' : A} → a ≡ a' → a' ≡ a 201 | sym refl = refl 202 | ``` 203 | 204 | As mentioned above, each function `f : A → B` in HoTT is canonically endowed with the structure of a functor between $\infty$-groupoids, where the action of such a function `f` on paths (i.e. elements of the identity type) is as follows: 205 | 206 | ```agda 207 | ap : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {a a' : A} 208 | → (f : A → B) → a ≡ a' → (f a) ≡ (f a') 209 | ap f refl = refl 210 | ``` 211 | 212 | By the same token, given a proof `f ≡ g` for two functions `f,g : (x : A) → B x`, it follows that for any `a : A` we have `f a ≡ g a`. 213 | 214 | ```agda 215 | coAp : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {f g : (x : A) → B x} 216 | → f ≡ g → (x : A) → f x ≡ g x 217 | coAp refl x = refl 218 | ``` 219 | 220 | Moreover, to show that two pairs `(a , b)` and `(a' , b')` are equal, it suffices to show that there is an identification `e : a ≡ a'` together with `e' : transp B e b ≡ b'`. 221 | 222 | ```agda 223 | pairEq : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} 224 | → {a a' : A} {b : B a} {b' : B a'} 225 | → (e : a ≡ a') (e' : transp B e b ≡ b') 226 | → (a , b) ≡ (a' , b') 227 | pairEq refl refl = refl 228 | ``` 229 | 230 | ### Truncation, Bracket Types & Factorization 231 | 232 | We say that a type `A` is: 233 | 234 | 1. *contractible* (aka (-2)-truncated) if `A` is uniquely inhabited 235 | 2. a (mere) *proposition* (aka (-1)-truncated) if any two elements of `A` are identical 236 | 3. a *set* (aka 0-truncated) if for any `a,b : A`, the type `a ≡ b` is a proposition. 237 | 238 | ```agda 239 | isContr : ∀ {ℓ} → Type ℓ → Type ℓ 240 | isContr A = Σ A (λ a → (b : A) → a ≡ b) 241 | 242 | isProp : ∀ {ℓ} → Type ℓ → Type ℓ 243 | isProp A = {a b : A} → a ≡ b 244 | 245 | isSet : ∀ {ℓ} → Type ℓ → Type ℓ 246 | isSet A = (a b : A) → isProp (a ≡ b) 247 | ``` 248 | 249 | We additionally postulate the existence of a *propositional truncation,* or *bracket type* operation, that takes a type `A` to the least proposition (wrt entailment) entailed by inhabitation of `A`. 250 | 251 | ```agda 252 | postulate 253 | ∥_∥ : ∀ {ℓ} (A : Type ℓ) → Type lzero 254 | in∥-∥ : ∀ {ℓ} {A : Type ℓ} → A → ∥ A ∥ 255 | ∥-∥IsProp : ∀ {ℓ} {A : Type ℓ} → isProp (∥ A ∥) 256 | ∥-∥Rec : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} 257 | → isProp B → (A → B) → ∥ A ∥ → B 258 | ``` 259 | 260 | When the type `∥ A ∥` is inhabited, we say that `A` is *merely* inhabited. 261 | 262 | From this operation on types, we straightforwardly obtain the higher analogue of the usual epi-mono factorization system on functions between sets, as follows: 263 | 264 | Given a function `f : A → B` and an element `b : B`, the *fibre* of `f` at `b` is the type of elements of `a` equipped with a proof of `f a ≡ b`: 265 | 266 | ```agda 267 | Fibre : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} → (A → B) → B → Type (ℓ ⊔ κ) 268 | Fibre {A = A} f b = Σ A (λ a → f a ≡ b) 269 | ``` 270 | 271 | By the same token, given such an `f`, its *image* is the type of elements of `B` whose fibres are merely inhabited. 272 | 273 | ```agda 274 | Im : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} → (A → B) → Type κ 275 | Im {B = B} f = Σ B (λ b → ∥ Fibre f b ∥) 276 | ``` 277 | 278 | We say that `f` is *(-1)-truncated* (i.e. a monomorphism), if for each `b : B`, the fibre of `f` at `b` is a proposition. 279 | 280 | ```agda 281 | isMono : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} → (A → B) → Type (ℓ ⊔ κ) 282 | isMono {B = B} f = (b : B) → isProp (Fibre f b) 283 | ``` 284 | 285 | Likewise, we say that `f` is *(-1)-connected* (i.e. an epimorphism), if all of its fibres are merely inhabited. 286 | 287 | ```agda 288 | isEpi : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} → (A → B) → Type κ 289 | isEpi {B = B} f = (b : B) → ∥ Fibre f b ∥ 290 | ``` 291 | 292 | Every function `f` can then be factored into a (-1)-connected map onto its image followed by a (-1)-truncated map onto its codomain: 293 | 294 | ```agda 295 | factor1 : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} → (f : A → B) → A → Im f 296 | factor1 f a = (f a) , in∥-∥ (a , refl) 297 | 298 | factor2 : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} → (f : A → B) → Im f → B 299 | factor2 f (b , _) = b 300 | 301 | factor≡ : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} 302 | → (f : A → B) (a : A) → factor2 f (factor1 f a) ≡ f a 303 | factor≡ f a = refl 304 | 305 | factor1IsEpi : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} 306 | → (f : A → B) → isEpi (factor1 f) 307 | factor1IsEpi f (b , x) = 308 | ∥-∥Rec ∥-∥IsProp 309 | (λ {(a , refl) → in∥-∥ (a , pairEq refl ∥-∥IsProp)}) 310 | x 311 | 312 | factor2IsMono : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} 313 | → (f : A → B) → isMono (factor2 f) 314 | factor2IsMono f b {a = ((b' , x) , refl)} {b = ((b'' , x') , refl)} = 315 | pairEq (pairEq refl ∥-∥IsProp) (lemma ∥-∥IsProp) 316 | where lemma : (e : x ≡ x') → transp (λ a → factor2 f a ≡ b) 317 | (pairEq refl e) refl ≡ refl 318 | lemma refl = refl 319 | ``` 320 | 321 | ### Equivalences 322 | 323 | A pivotal notion, both for HoTT in general, and for the content of this paper, is that of a function `f : A → B` being an *equivalence* of types. The reader familiar with HoTT will know that there are several definitions – all equivalent – of this concept appearing in the HoTT literature. For present purposes, we make use of the *bi-invertible maps* notion of equivalence. Hence we say that a function `f : A → B` is an equivalence if it has both a left inverse and a right inverse: 324 | 325 | ```agda 326 | isEquiv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} → (A → B) → Type (ℓ ⊔ κ) 327 | isEquiv {A = A} {B = B} f = 328 | (Σ (B → A) (λ g → (a : A) → g (f a) ≡ a)) 329 | × (Σ (B → A) (λ h → (b : B) → f (h b) ≡ b)) 330 | ``` 331 | 332 | A closely-related notion is that of a function `f` being an *isomorphism*, i.e. having a single two-sided inverse: 333 | 334 | ```agda 335 | Iso : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} → (A → B) → Type (ℓ ⊔ κ) 336 | Iso {A = A} {B = B} f = 337 | (Σ (B → A) (λ g → ((a : A) → g (f a) ≡ a) 338 | × ((b : B) → f (g b) ≡ b))) 339 | ``` 340 | 341 | One might be inclined to wonder, then, why we bother to define equivalence via the seemingly more complicated notion of having both a left and a right inverse when the familiar notion of isomorphism can just as well be defined, as above. The full reasons for this are beyond the scope of this paper, though see \cite{hottbook} for further discussion. Suffice it to say that, for subtle reasons due to the higher-categorical structure of types in HoTT, the plain notion of isomorphism given above is not a *good* notion of equivalence, whereas that of bi-invertible maps is. In particular, the type `Iso f` is not necessarily a proposition for arbitrary `f`, whereas `isEquiv f` is. 342 | 343 | We may nonetheless move more-or-less freely back and forth between the notions of equivalence and isomorphism given above, thanks to the following functions, which allow us to convert isomorphisms to equivalences and vice versa: 344 | 345 | ```agda 346 | Iso→isEquiv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 347 | → Iso f → isEquiv f 348 | Iso→isEquiv (g , l , r) = ((g , l) , (g , r)) 349 | 350 | isEquiv→Iso : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 351 | → isEquiv f → Iso f 352 | isEquiv→Iso {f = f} ((g , l) , (h , r)) = 353 | h , (λ x → (h (f x)) ≡〈 sym (l (h (f x))) 〉 354 | (g (f (h (f x))) ≡〈 ap g (r (f x)) 〉 355 | ((g (f x)) ≡〈 l x 〉 356 | (x □)))) , r 357 | ``` 358 | 359 | Straightforwardly, the identity function at each type is an equivalence, and equivalences are closed under composition: 360 | 361 | ```agda 362 | idIsEquiv : ∀ {ℓ} {A : Type ℓ} → isEquiv {A = A} (λ x → x) 363 | idIsEquiv = ((λ x → x) , (λ x → refl)) , ((λ x → x) , (λ x → refl)) 364 | 365 | compIsEquiv : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} 366 | → (g : B → C) (f : A → B) → isEquiv g → isEquiv f 367 | → isEquiv (λ a → g (f a)) 368 | compIsEquiv g f ((g' , lg) , (g'' , rg)) ((f' , lf) , (f'' , rf)) = 369 | ( (λ c → f' (g' c)) 370 | , λ a → (f' (g' (g (f a)))) ≡〈 ap f' (lg (f a)) 〉 371 | (f' (f a) ≡〈 lf a 〉 372 | (a □))) 373 | , ((λ c → f'' (g'' c)) 374 | , λ c → (g (f (f'' (g'' c)))) ≡〈 ap g (rf (g'' c)) 〉 375 | (g (g'' c) ≡〈 rg c 〉 376 | (c □))) 377 | ``` 378 | 379 | And by the above translation between equivalences and isomorphisms, each equivalence has a corresponding inverse map in the opposite direction, which is itself an equivalence: 380 | 381 | ```agda 382 | inv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} → isEquiv f → B → A 383 | inv (_ , (h , _)) = h 384 | 385 | isoInv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 386 | → (isof : Iso f) → Iso (fst isof) 387 | isoInv {f = f} (g , l , r) = (f , r , l) 388 | 389 | invIsEquiv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 390 | → (ef : isEquiv f) → isEquiv (inv ef) 391 | invIsEquiv ef = Iso→isEquiv (isoInv (isEquiv→Iso ef)) 392 | ``` 393 | 394 | We close this section by noting that, for each type family `B : A → Type`, the map `B a → B a'` induced by transport along `e : a ≡ a'` for any `a, a' : A` is an equivalence with inverse given by transport along `sym e`, as follows: 395 | 396 | ```agda 397 | syml : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {a b : A} 398 | → (e : a ≡ b) (x : B a) → transp B (sym e) (transp B e x) ≡ x 399 | syml refl x = refl 400 | 401 | symr : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {a b : A} 402 | → (e : a ≡ b) (y : B b) → transp B e (transp B (sym e) y) ≡ y 403 | symr refl x = refl 404 | 405 | transpIsEquiv : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {a b : A} (e : a ≡ b) 406 | → isEquiv {A = B a} {B = B b} (λ x → transp B e x) 407 | transpIsEquiv {B = B} e = Iso→isEquiv ((λ x → transp B (sym e) x) , (syml e , symr e)) 408 | ``` 409 | 410 | And... 411 | 412 | ```agda 413 | transpAp : ∀ {ℓ ℓ' κ} {A : Type ℓ} {A' : Type ℓ'} {a b : A} 414 | → (B : A' → Type κ) (f : A → A') (e : a ≡ b) (x : B (f a)) 415 | → transp (λ x → B (f x)) e x ≡ transp B (ap f e) x 416 | transpAp B f refl x = refl 417 | 418 | ≡siml : ∀ {ℓ} {A : Type ℓ} {a b : A} 419 | → (e : a ≡ b) → refl ≡ (b ≡〈 sym e 〉 e) 420 | ≡siml refl = refl 421 | 422 | ≡idr : ∀ {ℓ} {A : Type ℓ} {a b : A} 423 | → (e : a ≡ b) → e ≡ (a ≡〈 refl 〉 e) 424 | ≡idr refl = refl 425 | 426 | conj : ∀ {ℓ} {A : Type ℓ} {a b c d : A} 427 | → (e1 : a ≡ b) (e2 : a ≡ c) (e3 : b ≡ d) (e4 : c ≡ d) 428 | → (a ≡〈 e1 〉 e3) ≡ (a ≡〈 e2 〉 e4) 429 | → e3 ≡ (b ≡〈 sym e1 〉(a ≡〈 e2 〉 e4)) 430 | conj e1 e2 refl refl refl = ≡siml e1 431 | 432 | nat : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f g : A → B} {a b : A} 433 | → (α : (x : A) → f x ≡ g x) (e : a ≡ b) 434 | → ((f a) ≡〈 α a 〉 (ap g e)) ≡ ((f a) ≡〈 ap f e 〉 (α b)) 435 | nat {a = a} α refl = ≡idr (α a) 436 | 437 | cancel : ∀ {ℓ} {A : Type ℓ} {a b c : A} 438 | → (e1 e2 : a ≡ b) (e3 : b ≡ c) 439 | → (a ≡〈 e1 〉 e3) ≡ (a ≡〈 e2 〉 e3) 440 | → e1 ≡ e2 441 | cancel e1 e2 refl refl = refl 442 | 443 | apId : ∀ {ℓ} {A : Type ℓ} {a b : A} 444 | → (e : a ≡ b) → ap (λ x → x) e ≡ e 445 | apId refl = refl 446 | 447 | apComp : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {a b : A} 448 | → (f : A → B) (g : B → C) (e : a ≡ b) 449 | → ap (λ x → g (f x)) e ≡ ap g (ap f e) 450 | apComp f g refl = refl 451 | 452 | apHtpy : ∀ {ℓ} {A : Type ℓ} {a : A} 453 | → (i : A → A) (α : (x : A) → i x ≡ x) 454 | → ap i (α a) ≡ α (i a) 455 | apHtpy {a = a} i α = 456 | cancel (ap i (α a)) (α (i a)) (α a) 457 | ((i (i a) ≡〈 ap i (α a) 〉 α a) 458 | ≡〈 sym (nat α (α a)) 〉 459 | ((i (i a) ≡〈 α (i a) 〉 ap (λ z → z) (α a)) 460 | ≡〈 ap (λ e → i (i a) ≡〈 α (i a) 〉 e) (apId (α a)) 〉 461 | ((i (i a) ≡〈 α (i a) 〉 α a) □))) 462 | 463 | HAdj : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} 464 | → (A → B) → Set (ℓ ⊔ κ) 465 | HAdj {A = A} {B = B} f = 466 | Σ (B → A) (λ g → 467 | Σ ((x : A) → g (f x) ≡ x) (λ η → 468 | Σ ((y : B) → f (g y) ≡ y) (λ ε → 469 | (x : A) → ap f (η x) ≡ ε (f x)))) 470 | 471 | Iso→HAdj : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 472 | → Iso f → HAdj f 473 | Iso→HAdj {f = f} (g , η , ε) = 474 | g , (η 475 | , ( (λ y → 476 | f (g y) ≡〈 sym (ε (f (g y))) 〉 477 | (f (g (f (g y))) ≡〈 ap f (η (g y)) 〉 478 | (f (g y) ≡〈 ε y 〉 479 | (y □)))) 480 | , λ x → conj (ε (f (g (f x)))) (ap f (η (g (f x)))) 481 | (ap f (η x)) (ε (f x)) 482 | (((f (g (f (g (f x)))) ≡〈 ε (f (g (f x))) 〉 ap f (η x))) 483 | ≡〈 nat (λ z → ε (f z)) (η x) 〉 484 | (((f (g (f (g (f x)))) ≡〈 ap (λ z → f (g (f z))) (η x) 〉 ε (f x))) 485 | ≡〈 ap (λ e → (f (g (f (g (f x)))) ≡〈 e 〉 ε (f x))) 486 | ((ap (λ z → f (g (f z))) (η x)) 487 | ≡〈 apComp (λ z → g (f z)) f (η x) 〉 488 | ((ap f (ap (λ z → g (f z)) (η x))) 489 | ≡〈 ap (ap f) (apHtpy (λ z → g (f z)) η) 〉 490 | (ap f (η (g (f x))) □))) 〉 491 | (((f (g (f (g (f x)))) ≡〈 ap f (η (g (f x))) 〉 ε (f x))) □))))) 492 | 493 | pairEquiv1 : ∀ {ℓ ℓ' κ} {A : Type ℓ} {A' : Type ℓ'} {B : A' → Type κ} 494 | → (f : A → A') → isEquiv f 495 | → isEquiv {A = Σ A (λ x → B (f x))} {B = Σ A' B} 496 | (λ (x , y) → (f x , y)) 497 | pairEquiv1 {A = A} {A' = A'} {B = B} f ef = 498 | Iso→isEquiv 499 | ( (λ (x , y) → (g x , transp B (sym (ε x)) y)) 500 | , ( (λ (x , y) → pairEq (η x) (lemma x y)) 501 | , λ (x , y) → pairEq (ε x) (symr (ε x) y) ) ) 502 | where 503 | g : A' → A 504 | g = fst (Iso→HAdj (isEquiv→Iso ef)) 505 | η : (x : A) → g (f x) ≡ x 506 | η = fst (snd (Iso→HAdj (isEquiv→Iso ef))) 507 | ε : (y : A') → f (g y) ≡ y 508 | ε = fst (snd (snd (Iso→HAdj (isEquiv→Iso ef)))) 509 | ρ : (x : A) → ap f (η x) ≡ ε (f x) 510 | ρ = snd (snd (snd (Iso→HAdj (isEquiv→Iso ef)))) 511 | lemma : (x : A) (y : B (f x)) 512 | → transp (λ z → B (f z)) (η x) 513 | (transp B (sym (ε (f x))) y) 514 | ≡ y 515 | lemma x y = (transp (λ z → B (f z)) (η x) 516 | (transp B (sym (ε (f x))) y)) 517 | ≡〈 transpAp B f (η x) 518 | (transp B (sym (ε (f x))) y) 〉 519 | ( transp B (ap f (η x)) 520 | (transp B (sym (ε (f x))) y) 521 | ≡〈 ap (λ e → transp B e 522 | (transp B (sym (ε (f x))) y)) 523 | (ρ x) 〉 524 | ( (transp B (ε (f x)) 525 | (transp B (sym (ε (f x))) y)) 526 | ≡〈 (symr (ε (f x)) y) 〉 527 | (y □))) 528 | 529 | pairEquiv2 : ∀ {ℓ κ κ'} {A : Type ℓ} {B : A → Type κ} {B' : A → Type κ'} 530 | → (g : (x : A) → B x → B' x) → ((x : A) → isEquiv (g x)) 531 | → isEquiv {A = Σ A B} {B = Σ A B'} 532 | (λ (x , y) → (x , g x y)) 533 | pairEquiv2 g eg = 534 | let isog = (λ x → isEquiv→Iso (eg x)) 535 | in Iso→isEquiv ( (λ (x , y) → (x , fst (isog x) y)) 536 | , ( (λ (x , y) → 537 | pairEq refl (fst (snd (isog x)) y)) 538 | , λ (x , y) → 539 | pairEq refl (snd (snd (isog x)) y))) 540 | 541 | pairEquiv : ∀ {ℓ ℓ' κ κ'} {A : Type ℓ} {A' : Type ℓ'} 542 | → {B : A → Type κ} {B' : A' → Type κ'} 543 | → (f : A → A') (g : (x : A) → B x → B' (f x)) 544 | → isEquiv f → ((x : A) → isEquiv (g x)) 545 | → isEquiv {A = Σ A B} {B = Σ A' B'} 546 | (λ (x , y) → (f x , g x y)) 547 | pairEquiv f g ef eg = 548 | compIsEquiv (λ (x , y) → (f x , y)) 549 | (λ (x , y) → (x , g x y)) 550 | (pairEquiv1 f ef) 551 | (pairEquiv2 g eg) 552 | 553 | 554 | transpComp : ∀ {ℓ κ} {A : Type ℓ} {a b c : A} {B : A → Type κ} 555 | → (e1 : a ≡ b) (e2 : b ≡ c) (x : B a) 556 | → transp B e2 (transp B e1 x) 557 | ≡ transp B (a ≡〈 e1 〉 e2) x 558 | transpComp refl refl x = refl 559 | 560 | _•_ : ∀ {ℓ} {A : Type ℓ} {a b c : A} 561 | → (a ≡ b) → (b ≡ c) → (a ≡ c) 562 | refl • refl = refl 563 | 564 | comprewrite : ∀ {ℓ} {A : Type ℓ} {a b c : A} 565 | → (e1 : a ≡ b) (e2 : b ≡ c) 566 | → (a ≡〈 e1 〉 e2) ≡ (e1 • e2) 567 | comprewrite refl refl = refl 568 | 569 | {-# REWRITE comprewrite #-} 570 | 571 | transpCompSymr : ∀ {ℓ κ} {A : Type ℓ} {a b : A} {B : A → Type κ} 572 | → (e : a ≡ b) (x : B b) 573 | → (transpComp (sym e) e x) • 574 | (ap (λ e' → transp B e' x) 575 | (sym (≡siml e))) 576 | ≡ symr e x 577 | transpCompSymr refl x = refl 578 | ``` -------------------------------------------------------------------------------- /part1v2.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/part1v2.agdai -------------------------------------------------------------------------------- /part1v2.lagda.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Polynomial Universes and Dependent Types 3 | author: 4 | - C.B. Aberlé 5 | - David I. Spivak 6 | documentclass: memoir 7 | classoption: 8 | - 11pt 9 | - oneside 10 | - article 11 | --- 12 | 13 | \begin{abstract} 14 | 15 | Awodey, later with Newstead, showed how polynomial pseudomonads $(u,\1,\Sigma)$ with extra structure (termed "natural models" by Awodey) hold within them the categorical semantics for dependent type theory. Their work presented these ideas clearly but ultimately led them outside of the category of polynomial functors in order to explain all of the structure possessed by such models of type theory. 16 | 17 | This paper builds off that work---explicating the categorical semantics of dependent type theory by axiomatizing them \emph{entirely} in the language of polynomial functors. In order to handle the higher-categorical coherences required for such an explanation, we work with polynomial functors internally in the language of Homotopy Type Theory, which allows for higher-dimensional structures such as pseudomonads, etc. to be expressed purely in terms of the structure of a suitably-chosen $\infty$-category of polynomial functors. The move from set theory to Homotopy Type Theory thus has a twofold effect of enabling a simpler exposition of natural models, which is at the same time amenable to formalization in a proof assistant, such as Agda. 18 | 19 | Moreover, the choice to remain firmly within the setting of polynomial functors reveals many additional structures of natural models that were otherwise left implicit or not considered by Awodey \& Newstead. Chief among these, we highlight the fact that every polynomial pseudomonad $(u,\1,\Sigma)$ as above that is also equipped with structure to interpret dependent product types gives rise to a self-distributive law $u\tri u\to u\tri u$, which witnesses the usual distributive law of dependent products over dependent sums. 20 | 21 | \end{abstract} 22 | 23 | # Introduction 24 | 25 | The central idea of dependent type theory (c.f. \cite{martin-lof1975intuitionistic}) is that \emph{order of events} is fundamental to the mathematical story arc: when playing out any specific example story within that arc, the beginning of the story affects not only the later events, but even the very terms with which the later events will be described. For example, in the story arc of conditional probability, one may say ``now if the set $P$ that we are asked to condition on happens to have measure zero, we must stop; but assuming that's not the case then the result will be a new probability measure.'' Here the story teller is saying that no terms will describe what happens if $P$ has measure zero, whereas otherwise the terms of standard probability will apply. 26 | 27 | Dependent types form a logical system with syntax, rules of computation, and robust categorical semantics. In \cite{awodey2014natural,awodey2018polynomial}, Awodey and later Newstead show that there is a strong connection between dependent type theory and polynomial functors, via their concept of *natural models*, which cleanly solve the problem of *strictififying* certain identities that typically hold only up to isomorphism in arbitrary categories, but must hold *strictly* in order for these to soundly model dependent type theory. The solution to this problem offered by Awodey and Newstead makes use of the type-theoretic concept of a *universe*. Such universes then turn out to naturally be regarded as polynomial functors on a suitably-chosen category of presheaves, satisfying a certain *representability* condition. 28 | 29 | Although the elementary structure of natural models is thus straightforwardly described by considering them as objects in a category of polynomial functors, Awodey and Newstead were ultimately led outside of this category in order to fully explicate those parts of natural models that require identities to hold only *up to isomorphism*, rather than strictly. There is thus an evident tension between *strict* and *weak* identities that has not yet been fully resolved in the story of natural models. In the present work, we build on Awodey and Newstead's work to fully resolve this impasse by showing how type universes can be fully axiomatized in terms of polynomial functors, by working with polynomial functors internally in the language of *Homotopy Type Theory* (HoTT). We thus come full circle from Awodey's original motivation to develop natural models *of* Homotopy Type Theory, to describing natural models *in* Homotopy Type Theory. 30 | 31 | The ability for us to tell the story of natural models as set entirely in the category of polynomial functors has a great simplifying effect upon the resultant theory, and reveals many additional structures, both of polynomial universes, and of the category of polynomial functors as a whole. As an illustration of this, we show how every polynomial universe $u$, regarded as a polynomial pseudomonad with additional structure, gives rise to self-distributive law $u\tri u\to u\tri u$, which in particular witnesses the usual distributive law of dependent products over dependent sums. 32 | 33 | Moreover, the move from set theory to HoTT as a setting in which to tell this story enables new tools to be applied for its telling. In particular, the account of polynomial universes we develop is well-suited to formalization in a proof assistant, and we present such a formalization in Agda. This paper is thus itself a literate Agda document in which all results have been fully formalized and checked for validity. 34 | 35 | ```agda 36 | {-# OPTIONS --without-K --rewriting #-} 37 | module part1v2 where 38 | ``` 39 | 40 | The structure of this paper is as follows: 41 | 42 | * In Section 2, we give an introductory presentation of dependent type theory and natural models, followed by a recap the basics of HoTT that will be used throughout the rest of the paper. 43 | * In Section 3, we outline the basic theory of polynomial functors in HoTT, culminating in a demonstration of how to model dependent pair types using polynomial functors. In order to show that these polynomial functors are in fact monads, however, we will need some additional technology, to which we devote the following section. 44 | * In Section 4, we introduce the key concept of a *polynomial universe* as a polynomial functor satisfying a certain *univalence* condition, that allows us to straightforwardly derive the monad laws for polynomial universes equipped with the structure to interpret dependent pair types. 45 | * In Section 5, building on the ideas of the previous sections, we show how to model dependent function types with polynomial functors, and demonstrate that any polynomial universe equipped with this structure -- along with the aforementioned structure for interpreting dependent pair types -- gives rise to a self-distributive law of the corresponding monad. 46 | * In Section 6, we conclude the paper by sketching how this theory may be further developed to handle identity types, inductive types, and other key concepts from dependent type theory. -------------------------------------------------------------------------------- /part2.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/part2.agdai -------------------------------------------------------------------------------- /part2.lagda.md: -------------------------------------------------------------------------------- 1 | ```agda 2 | {-# OPTIONS --without-K --rewriting #-} 3 | module part2 where 4 | 5 | open import Agda.Primitive 6 | open import Agda.Builtin.Unit 7 | open import Agda.Builtin.Sigma 8 | open import Agda.Builtin.Equality 9 | open import Agda.Builtin.Equality.Rewrite 10 | open import part1 11 | ``` 12 | 13 | # Polynomials in HoTT 14 | 15 | ## Basics 16 | 17 | **Remark:** for the sake of concision, since essentially all of the categorical structures treated in this paper will be infinite-dimensional, we shall generally omit the prefix "$\infty$-" from our descriptions these structures. Hence hereafter "category" generally means $\infty$-category, "functor" means $\infty$-functor, etc. 18 | 19 | Let $\mathbf{Type}$ be the category of types and functions between them. Given a type `A`, let $y^A$ denote the corresponding representable functor $\mathbf{Type} \to \mathbf{Type}$. 20 | 21 | A *polynomial functor* is a coproduct of representable functors $\mathbf{Type} \to \mathbf{Type}$, i.e. an endofunctor on $\mathbf{Type}$ of the form $$ 22 | \sum_{a : A} y^{B(a)} 23 | $$ for some type `A` and family of types `B : A → Type`. The data of a polynomial functor is thus uniquely determined by the choice of `A` and `B`. Hence we may represent such functors in Agda simply as pairs (A , B) of this form: 24 | 25 | ```agda 26 | Poly : (ℓ κ : Level) → Type ((lsuc ℓ) ⊔ (lsuc κ)) 27 | Poly ℓ κ = Σ (Set ℓ) (λ A → A → Set κ) 28 | ``` 29 | 30 | A basic example of such a polynomial functor is the identity functor `𝕪` consisting of a single term of unit arity – hence represented by the pair `(⊤ , λ _ → ⊤)`. 31 | 32 | ```agda 33 | 𝕪 : Poly lzero lzero 34 | 𝕪 = (⊤ , λ _ → ⊤) 35 | ``` 36 | 37 | The observant reader may note the striking similarity of the above-given formula for a polynomial functor and the endofunctor on $\mathbf{Set}^{\mathcal{C}^{op}}$ defined in the previous section on natural models. Indeed, this is no accident, given a type `𝓤` and a function `u : 𝓤 → Type` corresponding to a natural model as described previously, we obtain the corresponding polynomial `𝔲 : Poly` as the pair `(𝓤 , u)`. Hence we can study the structure of `𝓤` and `u` in terms of `𝔲`, and this, as we shall see, allows for some significant simplifications in the theory of natural models. 38 | 39 | Given polynomial functors $p = \sum_{a : A} y^{B(a)}$ and $q = \sum_{c : C} y^{D(c)}$, a natural transformation $p \Rightarrow q$ is equivalently given by the data of a *forward* map `f : A → B` and a *backward* map `g : (a : A) → D (f a) → B a`, as can be seen from the following argument via Yoneda: $$ 40 | \begin{array}{rl} 41 | & \int_{y \in \mathbf{Type}} \left( \sum_{a : A} y^{B(a)} \right) \to \sum_{c : C} y^{D(c)}\\ 42 | \simeq & \prod_{a : A} \int_{y \in \mathbf{Type}} y^{B(a)} \to \sum_{c : C} y^{D(c)}\\ 43 | \simeq & \prod_{a : A} \sum_{c : C} B(a)^{D(c)}\\ 44 | \simeq & \sum_{f : A \to C} \prod_{a : A} B(a)^{D(f(c))} 45 | \end{array} 46 | $$ We use the notation $p \leftrightarrows q$ to denote the type of natural transformations from $p$ to $q$ (aka *lenses* from $p$ to $q$), which may be written in Agda as follows: 47 | 48 | ```agda 49 | _⇆_ : ∀ {ℓ ℓ' κ κ'} → Poly ℓ κ → Poly ℓ' κ' → Type (ℓ ⊔ ℓ' ⊔ κ ⊔ κ') 50 | (A , B) ⇆ (C , D) = Σ (A → C) (λ f → (a : A) → D (f a) → B a) 51 | ``` 52 | 53 | By application of function extensionality, we derive the following type for proofs of equality between lenses: 54 | 55 | ```agda 56 | EqLens : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 57 | → (p ⇆ q) → (p ⇆ q) → Set (ℓ ⊔ ℓ' ⊔ κ ⊔ κ') 58 | EqLens (A , B) (C , D) (f , g) (f' , g') = 59 | (a : A) → Σ (f a ≡ f' a) 60 | (λ e → (b : D (f a)) → g a b ≡ g' a (transp D e b)) 61 | ``` 62 | 63 | For each polynomial $p$, the correspnding *identity* lens is given by the following data: 64 | 65 | ```agda 66 | id : ∀ {ℓ κ} (p : Poly ℓ κ) → p ⇆ p 67 | id p = ( (λ a → a) , λ a b → b ) 68 | ``` 69 | 70 | And given lenses $p \leftrightarrows q$ and $q \leftrightarrows r$, their composition may be computed as follows: 71 | 72 | ```agda 73 | comp : ∀ {ℓ ℓ' ℓ'' κ κ' κ''} 74 | → (p : Poly ℓ κ) (q : Poly ℓ' κ') (r : Poly ℓ'' κ'') 75 | → p ⇆ q → q ⇆ r → p ⇆ r 76 | comp p q r (f , g) (h , k) = 77 | ( (λ a → h (f a)) , λ a z → g a (k (f a) z) ) 78 | ``` 79 | 80 | Hence we have a category $\mathbf{Poly}$ of polynomial functors and lenses between them. Our goal, then, is to show how the type-theoretic structure of a natural model naturally arises from the structure of this category. In fact, $\mathbf{Poly}$ is replete with categorical structures of all kinds, of which we now mention but a few: 81 | 82 | ## The Vertical-Cartesian Factorization System on $\mathbf{Poly}$ 83 | 84 | We say that a lens `(f , f♯) : (A , B) ⇆ (C , D)` is *vertical* if `f : A → C` is an equivalence, and Cartesian if for every `a : A`, the map `f♯ a : D[f a] → B a` is an equivalence. 85 | 86 | ```agda 87 | isVertical : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 88 | → p ⇆ q → Set (ℓ ⊔ ℓ') 89 | isVertical p q (f , f♯) = isEquiv f 90 | 91 | isCartesian : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 92 | → p ⇆ q → Set (ℓ ⊔ κ ⊔ κ') 93 | isCartesian (A , B) q (f , f♯) = (a : A) → isEquiv (f♯ a) 94 | ``` 95 | 96 | Every lens `(A , B) ⇆ (C , D)` can then be factored as a vertical lens followed by a Cartesian lens: 97 | 98 | ```agda 99 | vertfactor : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 100 | → (f : p ⇆ q) → p ⇆ (fst p , λ x → snd q (fst f x)) 101 | vertfactor p q (f , f♯) = (λ x → x) , (λ a x → f♯ a x) 102 | 103 | vertfactorIsVert : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) 104 | → (q : Poly ℓ' κ') (f : p ⇆ q) 105 | → isVertical p (fst p , λ x → snd q (fst f x)) 106 | (vertfactor p q f) 107 | vertfactorIsVert p q f = idIsEquiv 108 | 109 | cartfactor : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 110 | → (f : p ⇆ q) → (fst p , λ x → snd q (fst f x)) ⇆ q 111 | cartfactor p q (f , f♯) = f , λ a x → x 112 | 113 | cartfactorIsCart : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) 114 | → (q : Poly ℓ' κ') (f : p ⇆ q) 115 | → isCartesian (fst p , λ x → snd q (fst f x)) q 116 | (cartfactor p q f) 117 | cartfactorIsCart p q f x = idIsEquiv 118 | 119 | vertcartfactor≡ : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) 120 | → (q : Poly ℓ' κ') (f : p ⇆ q) 121 | → EqLens p q f 122 | (comp p (fst p , λ x → snd q (fst f x)) q 123 | (vertfactor p q f) 124 | (cartfactor p q f)) 125 | vertcartfactor≡ p q f a = refl , (λ b → refl) 126 | ``` 127 | 128 | Of these two classes of morphisms in $\mathbf{Poly}$, it is *Cartesian* lenses that shall be of principal interest to us. If we view a polynomial `p = (A , B)` as an `A`-indexed family of types, given by `B`, then given a lens `(f , f♯) : p ⇆ 𝔲`, we can think of the map `f♯ a : u (f a) → B a`, as an *elimination form* for the type `u (f a)`, i.e. a way of *using* elements of the type `u (f a)`. If we then ask that `(f , f♯)` isCartesian, this implies that the type `u (f a)` is completely characterized (up to equivalence) by this elimination form, and in this sense, `𝔲` *contains* the type `B a`, for all `a : A`.[^3] 129 | 130 | [^3]: Those familiar with type theory may recognize this practice of defining types in terms of their elimination forms as characteristic of so-called *negative* types (in opposition to *positive* types, which are characterized by their introduction forms). Indeed, there are good reasons for this, having to do with the fact that negative types are equivalently those whose universal property is given by a *representable* functor, rather than a *co-representable* functor, which reflects the fact that natural models are defined in terms of *presheaves* on a category of contexts, rather than *co-presheaves.* 131 | 132 | We can therefore use Cartesian lenses to detect which types are contained in a natural model `𝔲`. 133 | 134 | A further fact about Cartesian lenses is that they are closed under identity and composition, as a direct consequence of the closure of equivalences under identity and composition: 135 | 136 | ```agda 137 | idCart : ∀ {ℓ κ} (p : Poly ℓ κ) 138 | → isCartesian p p (id p) 139 | idCart p a = idIsEquiv 140 | 141 | compCartesian : ∀ {ℓ ℓ' ℓ'' κ κ' κ''} 142 | → (p : Poly ℓ κ) (q : Poly ℓ' κ') (r : Poly ℓ'' κ'') 143 | → (f : p ⇆ q) (g : q ⇆ r) 144 | → isCartesian p q f → isCartesian q r g 145 | → isCartesian p r (comp p q r f g) 146 | compCartesian p q r f g cf cg a = 147 | compIsEquiv (snd f a) (snd g (fst f a)) (cf a) (cg (fst f a)) 148 | ``` 149 | 150 | Hence there is a category $\mathbf{Poly^{Cart}}$ defined as the wide subcategory of $\mathbf{Poly}$ whose morphisms are precisely Cartesian lenses. As we shall see, much of the categorical structure of natural models qua polynomial functors can be derived from the subtle interplay between $\mathbf{Poly^{Cart}}$ and $\mathbf{Poly}$. 151 | 152 | ### Epi-Mono Factorization on $\mathbf{Poly^{Cart}}$ 153 | 154 | In fact, $\mathbf{Poly^{Cart}}$ itself inherits a factorization system from the epi-mono factorization on types considered previously. 155 | 156 | Define a Cartesian lens `(f , f♯) : p ⇆ q` to be a *Cartesian embedding* if `f` is a monomorphism, and a *Cartesian surjection* if `f` is an epimorphism. 157 | 158 | ```agda 159 | isCartesianEmbedding : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 160 | → (f : p ⇆ q) → isCartesian p q f → Set (ℓ ⊔ ℓ') 161 | isCartesianEmbedding p q (f , f♯) cf = isMono f 162 | 163 | isCartesianSurjection : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 164 | → (f : p ⇆ q) → isCartesian p q f → Set ℓ' 165 | isCartesianSurjection p q (f , f♯) cf = isEpi f 166 | ``` 167 | 168 | Then every Cartesian lens can be factored into a Cartesian surjection followed by a Cartesian embedding. 169 | 170 | ```agda 171 | factorcart1 : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 172 | → (f : p ⇆ q) → isCartesian p q f 173 | → p ⇆ (Im (fst f) , λ (x , _) → snd q x) 174 | factorcart1 p q (f , f♯) cf = 175 | (factor1 f) , f♯ 176 | 177 | factorcart1IsCart : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 178 | → (f : p ⇆ q) (cf : isCartesian p q f) 179 | → isCartesian p 180 | (Im (fst f) , λ (x , _) → snd q x) 181 | (factorcart1 p q f cf) 182 | factorcart1IsCart p q (f , f♯) cf = cf 183 | 184 | factorcart1IsEpi : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 185 | → (f : p ⇆ q) (cf : isCartesian p q f) 186 | → isCartesianSurjection p 187 | (Im (fst f) , λ (x , _) → snd q x) 188 | (factorcart1 p q f cf) 189 | (factorcart1IsCart p q f cf) 190 | factorcart1IsEpi p q (f , f♯) cf = factor1IsEpi f 191 | 192 | factorcart2 : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 193 | → (f : p ⇆ q) → isCartesian p q f 194 | → (Im (fst f) , λ (x , _) → snd q x) ⇆ q 195 | factorcart2 p q (f , f♯) cf = (factor2 f) , λ (x , _) y → y 196 | 197 | factorcart2IsCart : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 198 | → (f : p ⇆ q) (cf : isCartesian p q f) 199 | → isCartesian (Im (fst f) , λ (x , _) → snd q x) q 200 | (factorcart2 p q f cf) 201 | factorcart2IsCart p q (f , f♯) cf x = idIsEquiv 202 | 203 | factorcart2IsMono : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 204 | → (f : p ⇆ q) (cf : isCartesian p q f) 205 | → isCartesianEmbedding 206 | (Im (fst f) , λ (x , _) → snd q x) q 207 | (factorcart2 p q f cf) 208 | (factorcart2IsCart p q f cf) 209 | factorcart2IsMono p q (f , f♯) cf = factor2IsMono f 210 | 211 | factorcart≡ : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 212 | → (f : p ⇆ q) (cf : isCartesian p q f) 213 | → EqLens p q f 214 | (comp p (Im (fst f) , λ (x , _) → snd q x) q 215 | (factorcart1 p q f cf) 216 | (factorcart2 p q f cf)) 217 | factorcart≡ p q f cf x = refl , λ y → refl 218 | ``` 219 | 220 | ## Composition of Polynomial Functors 221 | 222 | As endofunctors on $\mathbf{Type}$, polynomial functors may straightforwardly be composed. To show that the resulting composite is itself (equivalent to) a polynomial functor, we can reason via the following chain of equivalences: given polynomials `(A , B)` and `(C , D)`, their composite, evaluated at a type `y` is $$ 223 | \begin{array}{rl} 224 | & \sum_{a : A} \prod_{b : B(a)} \sum_{c : C} y^{D(c)}\\ 225 | \simeq & \sum_{a : A} \sum_{f : B(a) \to C} \prod_{b : B(a)} y^{D(f(b))}\\ 226 | \simeq & \sum_{(a , f) : \sum_{a : A} C^{B(a)}} y^{\sum_{b : B(a)} D(f(b))} 227 | \end{array} 228 | $$ This then defines a monoidal product $◃$ on $\mathbf{Poly}$ with monoidal unit given by the identity functor `𝕪`: 229 | 230 | ```agda 231 | _◃_ : ∀ {ℓ ℓ' κ κ'} → Poly ℓ κ → Poly ℓ' κ' → Poly (ℓ ⊔ κ ⊔ ℓ') (κ ⊔ κ') 232 | (A , B) ◃ (C , D) = (Σ A (λ a → B a → C) , λ (a , f) → Σ (B a) (λ b → D (f b))) 233 | 234 | ◃Lens : ∀ {ℓ ℓ' ℓ'' ℓ''' κ κ' κ'' κ'''} 235 | → (p : Poly ℓ κ) (p' : Poly ℓ' κ') 236 | → (q : Poly ℓ'' κ'') (q' : Poly ℓ''' κ''') 237 | → p ⇆ p' → q ⇆ q' → (p ◃ q) ⇆ (p' ◃ q') 238 | ◃Lens p p' q q' (f , g) (h , k) = 239 | ((λ (a , c) → (f a , λ b' → h (c (g a b')))) 240 | , λ (a , c) (b' , d') → ((g a b') , k (c (g a b')) d')) 241 | ``` 242 | 243 | where `◃Lens` is the action of `◃` on lenses. 244 | 245 | By construction, the existence of a Cartesian lens `(σ , σ♯) : 𝔲 ◃ 𝔲 ⇆ 𝔲` effectively shows that `𝔲` is closed under `Σ`-types, since: 246 | 247 | * `σ` maps a pair (A , B) consisting of `A : 𝓤` and `B : (u A) → 𝓤` to a term `σ(A,B)` representing the `Σ` type. This corresponds to the type formation rule $$ \inferrule{\Gamma \vdash A : \mathsf{Type}\\ \Gamma, x : A \vdash B[x] ~ \mathsf{Type}}{\Gamma \vdash \Sigma x : A . B[x] ~ \mathsf{Type}} $$ 248 | * For all `(A , B)` as above, `σ♯ (A , B)` takes a term of type `σ (A , B)` and yields a term `fst (σ♯ (A , B)) : A` along with a term `snd (σ♯ (A , B)) : B (fst (σ♯ (A , B)))`, corresponding to the elimination rules $$ 249 | \inferrule{\Gamma \vdash p : \Sigma x : A . B[x]}{\Gamma \vdash \pi_1(p) : A} \quad \inferrule{\Gamma \vdash p : \Sigma x : A . B[x]}{\Gamma \vdash \pi_2(p) : B[\pi_1(p)]} $$ 250 | * The fact that `σ♯ (A , B)` has is an equivalence implies it has an inverse `σ♯⁻¹ (A , B) : Σ (u A) (λ x → u (B x)) → u (σ (A , B))`, which takes a pair of terms to a term of the corresponding pair type, and thus corresponds to the introduction rule $$ \inferrule{\Gamma \vdash a : A\\ \Gamma \vdash b : B[a]}{\Gamma \vdash (a , b) : \Sigma x : A . B[x]} $$ 251 | * The fact that $σ♯⁻¹ (A , B)$ is both a left and a right inverse to $σ♯$ then implies the usual $β$ and $η$ laws for dependent pair types $$ \pi_1(a , b) = a \quad \pi_2(a , b) = b \quad p = (\pi_1(p) , \pi_2(p)) $$ 252 | 253 | Similarly, the existence of a Cartesian lens $(η , η♯) : 𝕪 ⇆ 𝔲$ implies that $𝔲$ contains (a type equivalent to) the unit type, in that: 254 | 255 | * There is an element `η tt : 𝓤` which represents the unit type. This corresponds to the type formation rule $$ \inferrule{~}{\Gamma \vdash \top : \mathsf{Type}}$$ 256 | * The "elimination rule" `η♯ tt : u(η tt) → ⊤`, applied to an element `x : u(η tt)` is trivial, in that it simply discards `x`. This corresponds to the fact that, in the ordinary type-theoretic presentation, $\top$ does not have an elimination rule. 257 | * However, since this trivial elimination rule has an inverse `η♯⁻¹ tt : ⊤ → u (η tt)`, it follows that there is a (unique) element `η♯⁻¹ tt tt : u (η tt)`, which corresponds to the introduction rule for $\top$: $$\inferrule{~}{\Gamma \vdash \mathsf{tt} : \top}$$ 258 | * Moreover, the uniqueness of this element corresponds to the $\eta$-law for $\top$: $$\frac{\Gamma \vdash x : \top}{\Gamma \vdash x = \mathsf{tt}}$$ 259 | 260 | But then, what sorts of laws can we expect Cartesian lenses as above to obey, and is the existence of such a lens all that is needed to ensure that the natural model $𝔲$ has dependent pair types in the original sense of Awodey & Newstead's definition in terms of Cartesian (pseudo)monads, or is some further data required? And what about `Π` types, or other type formers? To answer these questions, we will need to study the structure of `◃`, along with some closely related functors, in a bit more detail. In particular, we shall see that the structure of `◃` as a monoidal product on $\mathbf{Poly}$ reflects many of the basic identities one expects to hold of `Σ` types. 261 | 262 | For instance, the associativity of `◃` corresponds to the associativity of `Σ`-types, 263 | 264 | ```agda 265 | ◃assoc : ∀ {ℓ ℓ' ℓ'' κ κ' κ''} 266 | → (p : Poly ℓ κ) (q : Poly ℓ' κ') (r : Poly ℓ'' κ'') 267 | → ((p ◃ q) ◃ r) ⇆ (p ◃ (q ◃ r)) 268 | ◃assoc p q r = 269 | ((λ ((a , f) , g) → (a , (λ b → (f b , λ d → g (b , d))))) 270 | , λ ((a , f) , g) (b , (d , x)) → ((b , d) , x)) 271 | 272 | ◃assocCart : ∀ {ℓ ℓ' ℓ'' κ κ' κ''} 273 | → (p : Poly ℓ κ) (q : Poly ℓ' κ') (r : Poly ℓ'' κ'') 274 | → isCartesian ((p ◃ q) ◃ r) (p ◃ (q ◃ r)) (◃assoc p q r) 275 | ◃assocCart p q r (a , f) = 276 | Iso→isEquiv ( (λ ((b , d) , x) → b , d , x) 277 | , ( (λ (b , d , x) → refl) 278 | , λ ((b , d) , x) → refl)) 279 | 280 | ◃assoc⁻¹ : ∀ {ℓ ℓ' ℓ'' κ κ' κ''} 281 | → (p : Poly ℓ κ) (q : Poly ℓ' κ') (r : Poly ℓ'' κ'') 282 | → (p ◃ (q ◃ r)) ⇆ ((p ◃ q) ◃ r) 283 | ◃assoc⁻¹ p q r = 284 | ( (λ (a , h) → ( (a , (λ x → fst (h x))) 285 | , (λ (x , y) → snd (h x) y) )) 286 | , λ (a , h) ((x , y) , z) → (x , (y , z)) ) 287 | ``` 288 | 289 | while the left and right unitors of `◃` correspond to the fact that `⊤` is both a left and a right unit for `Σ`-types. 290 | 291 | ```agda 292 | ◃unitl : ∀ {ℓ κ} (p : Poly ℓ κ) → (𝕪 ◃ p) ⇆ p 293 | ◃unitl p = (λ (tt , a) → a tt) , λ (tt , a) x → tt , x 294 | 295 | ◃unitlCart : ∀ {ℓ κ} (p : Poly ℓ κ) 296 | → isCartesian (𝕪 ◃ p) p (◃unitl p) 297 | ◃unitlCart p (tt , a) = 298 | Iso→isEquiv ( (λ (tt , b) → b) 299 | , (λ b' → refl) 300 | , (λ b' → refl) ) 301 | 302 | ◃unitr : ∀ {ℓ κ} (p : Poly ℓ κ) → (p ◃ 𝕪) ⇆ p 303 | ◃unitr p = (λ (a , f) → a) , λ (a , f) b → b , tt 304 | 305 | ◃unitrCart : ∀ {ℓ κ} (p : Poly ℓ κ) 306 | → isCartesian (p ◃ 𝕪) p (◃unitr p) 307 | ◃unitrCart p (a , f) = 308 | Iso→isEquiv ( (λ (b , tt) → b) 309 | , (λ b → refl) 310 | , (λ (b , tt) → refl) ) 311 | 312 | ◃unitr⁻¹ : ∀ {ℓ κ} (p : Poly ℓ κ) → p ⇆ (p ◃ 𝕪) 313 | ◃unitr⁻¹ p = (λ x → x , (λ _ → tt)) , (λ a (x , y) → x) 314 | ``` 315 | 316 | In fact, `◃` restricts to a monoidal product on $\mathbf{Poly^{Cart}}$, since the functorial action of `◃` on lenses preserves Cartesian lenses: 317 | 318 | ```agda 319 | ◃LensCart : ∀ {ℓ ℓ' ℓ'' ℓ''' κ κ' κ'' κ'''} 320 | → (p : Poly ℓ κ) (q : Poly ℓ' κ') 321 | → (r : Poly ℓ'' κ'') (s : Poly ℓ''' κ''') 322 | → (f : p ⇆ q) (g : r ⇆ s) 323 | → isCartesian p q f → isCartesian r s g 324 | → isCartesian (p ◃ r) (q ◃ s) 325 | (◃Lens p q r s f g) 326 | ◃LensCart p q r s (f , f♯) (g , g♯) cf cg (a , h) = 327 | pairEquiv (f♯ a) (λ x → g♯ (h (f♯ a x))) 328 | (cf a) (λ x → cg (h (f♯ a x))) 329 | ``` 330 | 331 | We should expect, then, for these equivalences to be somehow reflected in the structure of a Cartesian lenses `η : 𝕪 ⇆ 𝔲` and `μ : 𝔲 ◃ 𝔲 ⇆ 𝔲`. This would be the case, e.g., if the following diagrams in $\mathbf{Poly^{Cart}}$ were to commute $$ 332 | \begin{tikzcd} 333 | {y \triangleleft \mathfrak{u}} & {\mathfrak{u} \triangleleft \mathfrak{u} } & {\mathfrak{u} \triangleleft y} \\ 334 | & {\mathfrak{u}} 335 | \arrow["{\eta \triangleleft \mathfrak{u}}", from=1-1, to=1-2] 336 | \arrow["{\mathsf{\triangleleft unitl}}"{description}, from=1-1, to=2-2] 337 | \arrow["\mu", from=1-2, to=2-2] 338 | \arrow["{\mathfrak{u} \triangleleft \eta}"', from=1-3, to=1-2] 339 | \arrow["{\mathsf{\triangleleft unitr}}"{description}, from=1-3, to=2-2] 340 | \end{tikzcd} \qquad \begin{tikzcd} 341 | {(\mathfrak{u} \triangleleft \mathfrak{u}) \triangleleft \mathfrak{u}} & {\mathfrak{u} \triangleleft (\mathfrak{u} \triangleleft \mathfrak{u})} & {\mathfrak{u} \triangleleft \mathfrak{u}} \\ 342 | {\mathfrak{u} \triangleleft \mathfrak{u}} && {\mathfrak{u}} 343 | \arrow["{\mathsf{\triangleleft assoc}}", from=1-1, to=1-2] 344 | \arrow["{\mu \triangleleft \mathfrak{u}}"', from=1-1, to=2-1] 345 | \arrow["{\mathfrak{u} \triangleleft \mu}", from=1-2, to=1-3] 346 | \arrow["\mu", from=1-3, to=2-3] 347 | \arrow["\mu"', from=2-1, to=2-3] 348 | \end{tikzcd} 349 | $$ 350 | 351 | One may recognize these as the usual diagrams for a monoid in a monoidal category, hence (since `◃` corresponds to composition of polynomial endofunctors) for a *monad* as typically defined. However, because of the higher-categorical structure of types in HoTT, we should not only ask for these diagrams to commute, but for the cells exhibiting that these diagrams commute to themselves be subject to higher coherences, and so on, giving `𝔲` not the structure of a (Cartesian) monad, but rather of a (Cartesian) *$\infty$-monad*. 352 | 353 | Yet demonstrating that $𝔲$ is an $\infty$-monad involves specifying a potentially infinite amount of coherence data. Have we therefore traded both the Scylla of equality-up-to-isomorphism and the Charybdis of strictness for an even worse fate of higher coherence hell? The answer to this question, surprisingly, is negative, as there is a way to implicitly derive all of this data from a single axiom, which corresponds to the characteristic axiom of HoTT itself: univalence. To show this, we now introduce the central concept of this paper – that of a *polynomial universe*. -------------------------------------------------------------------------------- /part2v2.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/part2v2.agdai -------------------------------------------------------------------------------- /part2v2.lagda.md: -------------------------------------------------------------------------------- 1 | ```agda 2 | {-# OPTIONS --without-K --rewriting #-} 3 | module part2v2 where 4 | 5 | open import part1v2 6 | open import Agda.Primitive 7 | open import Agda.Builtin.Sigma 8 | open import Agda.Builtin.Unit 9 | ``` 10 | 11 | # Background on Type Theory, Natural Models & HoTT 12 | 13 | We begin with a recap of natural models, dependent type theory, and HoTT, taking this also as an opportunity to introduce the basics of our Agda formalization. 14 | 15 | ## Dependent Types and their Categorical Semantics 16 | 17 | The question "what is a type" is as deep as it is philosophically fraught. For present purposes, however, we need not concern ourselves so much directly with what (dependent) type *are*, as with what they can *do*, and how best to mathematically model this behavior. Suffice it to say, then, that a type specifies rules for both constructing and using the *inhabitants* of that type in arbitrary contexts of usage. Following standard conventions, we use the notation `a : A` to mean that `a` is an inhabitant of type `A`. 18 | 19 | In Agda, one example of such a type is the *unit type* `⊤`, which is defined to have a single inhabitant `tt : ⊤`, such that for any other inhabitant `x : ⊤` we must have `x = tt`. 20 | 21 | Another type (or rather, family of types) of particular importance is the *universe* of types `Type`, whose inhabitants themsleves represent types.[^1] So e.g. to say that `⊤`, as defined above, is a type, we may simply write `⊤ : Type`. 22 | 23 | [^1]: For consistency with the usage of the term "set" in HoTT (whereby sets are types satisfying a certain *truncation* condition, to be explained shortly,) we relabel Agda's universes of types as `Type`, rather than the default `Set`. We also note in passing that, due to size issues, the universe `Type` is not in fact one type, but rather a whole family of types, stratified by a hierarchy of *levels.* However, this structure of levels is not of much concern to us in this paper, so we shall do our best to ignore it. 24 | 25 | ```agda 26 | Type : (ℓ : Level) → Set (lsuc ℓ) 27 | Type ℓ = Set ℓ 28 | ``` 29 | 30 | Given a type `A`, one may in turn consider families of types `B x` indexed by, or *dependent* upon aribtrary inhabitants `x : A`. In agda, we represent such a type family `B` as a function `A → Type`. 31 | 32 | Given a type `A : Type` and a family of types `B : A → Type` as above, two key examples of types we may construct are: 33 | 34 | * The *dependent function type* `(x : A) → B x`, whose inhabitants are functions `λ x → f x` such that, for all `a : A`, we have `f a : B a`. 35 | * The *dependent pair type* `Σ A B`, whose inhabitants are of the form `(a , b)` for `a : A` and `b : B a`, such that there are functions `fst : Σ A B → A` and `snd : (p : Σ A B) → B (fst p)`. 36 | 37 | Note that in the case where `B` does not depend upon `x : A` (i.e. the variable `x` does not appear in the expression for `B`), these correspond to the more familiar function type `A → B` and pair type `A × B`, respectively. E.g. we can define the Cartesian product of two types `A` and `B` as follows: 38 | 39 | ```agda 40 | _×_ : ∀ {ℓ κ} (A : Type ℓ) (B : Type κ) → Type (ℓ ⊔ κ) 41 | A × B = Σ A (λ _ → B) 42 | ``` 43 | 44 | In more traditional type-theoretic notation, one might see the rules for these types written as follows: $$ 45 | \inferrule{}{\Gamma \vdash \top : \mathsf{Type}} \qquad \inferrule{}{\Gamma \vdash \mathsf{tt} : \top} \qquad \inferrule{\Gamma \vdash x : \top}{\Gamma \vdash x = tt} 46 | $$ $$ 47 | \inferrule{\Gamma \vdash A : \mathsf{Type}\\ \Gamma, x : A \vdash B[x] : \mathsf{Type}}{\Gamma \vdash \Pi x : A . B[x] : \mathsf{Type}} \qquad \inferrule{\Gamma \vdash A : \mathsf{Type}\\ \Gamma, x : A \vdash B[x] : \mathsf{Type}}{\Gamma \vdash \Sigma x : A . B[x] : \mathsf{Type}} 48 | $$ $$ 49 | \inferrule{\Gamma, x : A \vdash f[x] : B[x]}{\Gamma \vdash \lambda x . f[x] : \Pi x : A . B[x]} \qquad \inferrule{\Gamma \vdash a : A\\ \Gamma \vdash b : B[a]}{\Gamma \vdash (a , b) : \Sigma x : A . B[x]} 50 | $$ $$ 51 | \inferrule{\Gamma \vdash f : \Pi x : A . B[x]\\ \Gamma \vdash a : A}{\Gamma \vdash f a : B[a]} \qquad \inferrule{\Gamma \vdash p : \Sigma x : A . B[x]}{\Gamma \vdash \pi_1(p) : A} \quad \inferrule{\Gamma \vdash p : \Sigma x : A . B[x]}{\Gamma \vdash \pi_2(p) : B[\pi_1(p)]} 52 | $$ $$ 53 | (\lambda x . f[x]) a = f[a] \qquad \pi_1(a , b) = a \quad \pi_2(a , b) = b 54 | $$ $$ 55 | f = \lambda x . fx \qquad p = (\pi_1(p) , \pi_2(p)) 56 | $$ 57 | 58 | The constructors $\lambda$ and $(- , -)$ are called the *introduction* forms of $\Pi x : A . B[x]$ and $\Sigma x : A . B[x]$, while $f a$ and $\pi_1(p), ~ \pi_2(p)$ are called the *elimination* forms of these types, respectively. One may wonder why all typing judgments in the above rules have been decorated with annotations of the form $\Gamma \vdash$, for some $\Gamma$. In these cases, $\Gamma$ is the *context* of the corresponding judgment, used to keep track of the types of variables that may appear in that judgment. 59 | 60 | Although contexts may seem rather trivial from a syntactic perspective, they are key to understanding the categorical semantics of dependent type theory. In particular, when modelling a dependent type theory as a category, it is the *contexts* which form the objects of this category, with morphisms between contexts being *substitutions* of terms in the domain context for the variables of the codomain context. A type $A$ dependent upon variables in a context $\Gamma$ is then interpreted as a morphism (i.e. substitution) $\Gamma, x : A \to \Gamma$, whose domain represents the context $\Gamma$ extended with a variable of type $A$. We then interpret a term $a$ of type $A$ in context $\Gamma$ as a *section* of the display map representing $A$, i.e. $$ 61 | \begin{tikzcd} 62 | \Gamma & {\Gamma, x : A} \\ 63 | & \Gamma 64 | \arrow["a", from=1-1, to=1-2] 65 | \arrow[Rightarrow, no head, from=1-1, to=2-2] 66 | \arrow["A", from=1-2, to=2-2] 67 | \end{tikzcd} 68 | $$ Hence for each context $\Gamma$, there is a category $\mathbf{Ty}[\Gamma]$, which is the full subcategory of the slice category $\mathcal{C}/\Gamma$ consisting of all display maps, wherein objects correspond to types in context $\Gamma$, and morphisms correspond to terms. 69 | 70 | In typical categorical semantics, given a substitution $f : \Gamma \to \Delta$, and a type $A : \Delta, x : A \to \Delta$, we then interpret the action of $f$ on $A$ as a pullback: $$ 71 | \begin{tikzcd} 72 | {\Gamma, x : A[f]} & {\Delta, x : A} \\ 73 | \Gamma & \Delta 74 | \arrow[from=1-1, to=1-2] 75 | \arrow["{A[f]}"', from=1-1, to=2-1] 76 | \arrow["\lrcorner"{anchor=center, pos=0.125}, draw=none, from=1-1, to=2-2] 77 | \arrow["A", from=1-2, to=2-2] 78 | \arrow["f"', from=2-1, to=2-2] 79 | \end{tikzcd} 80 | $$ In particular, then, any display map $A : \Gamma, x : A \to \Gamma$ induces a functor $\mathbf{Ty}[\Gamma] \to \mathbf{Ty}[\Gamma, x : A]$ by substitution along $A$. The left and right adjoints to this functor (if they exist) then correspond to dependent pair and dependent function types, respectively. 81 | 82 | So far, we have told a pleasingly straightforward story of how to interpret the syntax of dependent type theory categorically. Unfortunately, this story is a fantasy, and the interpretation of type-theoretic syntax into categorical semantics sketched above is unsound, as it stands. The problem in essentials is that, in the syntax of type theory, substitution is strictly associative – i.e. given substitutions $f : \Gamma \to \Delta$ and $g : \Delta \to \Theta$ and a type `A`, we have $A[g][f] = A[g[f]]$; however, in the above categorical semantics, such iterated substitution is interpreted via successively taking pullbacks, which is in general only associative up to isomorphism. It seems, then, that something more is needed to account for this kind of *strictness* in the semantics of dependent type theory. It is precisely this problem which natural models exist to solve. 83 | 84 | ## Natural Models 85 | 86 | The key insight of Awodey in formulating the notion of a natural model is that the problem of strictness in the semantics of type theory has, in a sense, already been solved by the notion of *type universes*, such as `Type` as introduced above. Given a universe of types $\mathcal{U}$, rather than representing dependent types as display maps, and substitution as pullback, we can simply represent a family of types $B[x]$ dependent upon a type $A$ as a function $A \to \mathcal{U}$, with substitution then given by precomposition, which is automatically strictly associative. 87 | 88 | To interpret the syntax of dependent type theory in a category $\mathcal{C}$ of contexts and substitutions, it therefore suffices to *embed* $\mathcal{C}$ into a category whose type-theoretic internal language posesses such a universe whose types correspond to those of $\mathcal{C}$. For this purpose, we work in the category of *prehseaves* $\mathbf{Set}^{\mathcal{C}^{op}}$, with the embedding $\mathcal{C} \hookrightarrow \mathbf{Set}^{\mathcal{C}^{op}}$ being nothing other than the Yoneda embedding. 89 | 90 | The universe $\mathcal{U}$ is then given by an object of $\mathbf{Set}^{\mathcal{C}^{op}}$, i.e. an assignment, to each context $\Gamma$, of a set $\mathsf{Ty}[\Gamma]$ of types in context $\Gamma$, with functions $\mathsf{Ty}[\Delta] \to \mathsf{Ty}[\Gamma]$ for each substitution $f : \Gamma \to \Delta$ that compose associatively, together with a $\mathcal{U}$-indexed family of objects $u \in \mathbf{Set}^{\mathcal{C}^{op}}/\mathcal{U}$, i.e. a natural transformation $u : \mathcal{U}_\bullet \Rightarrow \mathcal{U}$, where for each context $\Gamma$ and type $A \in \mathsf{Ty}[\Gamma]$, the fibre of $u_\Gamma$ over $A$ is the set $\mathsf{Tm}[\Gamma,A]$ of inhabitants of $A$ in context $\Gamma$. 91 | 92 | The condition that all types in $\mathcal{U}$ "belong to $\mathcal{C}$", in an appropriate sense, can then be expressed by requiring $u$ to be *representable*, i.e. for any representable $\gamma \in \mathbf{Set}^{\mathcal{C}^{op}}$ with a natural transformation $\alpha : \gamma \Rightarrow \mathcal{U}$, the pullback $$ 93 | \begin{tikzcd} 94 | {\mathcal{\gamma} \times_{\alpha, u} \mathcal{U}_\bullet} & {\mathcal{U}_\bullet} \\ 95 | \gamma & {\mathcal{U}} 96 | \arrow[Rightarrow, from=1-1, to=1-2] 97 | \arrow["{u[\alpha]}"', Rightarrow, from=1-1, to=2-1] 98 | \arrow["\lrcorner"{anchor=center, pos=0.125}, draw=none, from=1-1, to=2-2] 99 | \arrow["u", Rightarrow, from=1-2, to=2-2] 100 | \arrow["\alpha"', Rightarrow, from=2-1, to=2-2] 101 | \end{tikzcd} 102 | $$ of $u$ along $\alpha$ is representable. 103 | 104 | The question, then, is how to express that $\mathcal{C}$ has dependent pair types, dependent function types, etc., in terms of the structure of $u$. A further insight of Awodey, toward answering this question, is that $u$ gives rise to a functor (indeed, a *polynomial functor*) $\overline{u} : \mathbf{Set}^{\mathcal{C}^{op}} \to \mathbf{Set}^{\mathcal{C}^{op}}$, defined as follows $$ 105 | \overline{u}(P)(\Gamma) = \sum_{A : \mathsf{Ty}[\Gamma]} P(\Gamma)^{\mathsf{Tm}[\Gamma, A]} 106 | $$ and much of the type-theoretic structure of $u$ can be accounted for in terms of this functor. For instance (for reasons to be explained shortly), dependent pair types are given by a natural transformation $\sigma : \overline{u} \circ \overline{u} \Rightarrow \overline{u}$, that is *Cartesian* in that, for every $\alpha : P \Rightarrow Q$, the following naturality square is a pullback $$ 107 | \begin{tikzcd} 108 | {\overline{u}(\overline{u}(P))} & {\overline{u}(\overline{u}(Q))} \\ 109 | {\overline{u}(P)} & {\overline{u}(Q)} 110 | \arrow["{\overline{u}(\overline{u}(\alpha))}", Rightarrow, from=1-1, to=1-2] 111 | \arrow["{\sigma_P}"', Rightarrow, from=1-1, to=2-1] 112 | \arrow["\lrcorner"{anchor=center, pos=0.125}, draw=none, from=1-1, to=2-2] 113 | \arrow["{\sigma_Q}", Rightarrow, from=1-2, to=2-2] 114 | \arrow["{\overline{u}(\alpha)}"', Rightarrow, from=2-1, to=2-2] 115 | \end{tikzcd} 116 | $$ 117 | 118 | A question that arises, then, is what structure such a natural transformation interpreting dependent pair types must possess. It is natural to think that $\sigma$, along with a suitably-chosen natural transformation $Id \Rightarrow \overline{u}$, ought to give $\overline{u}$ the structure of a monad. However, this turns out to be too strong a requirement, as it amounts to asking that $\Sigma x : A . (\Sigma y : B[x] . C[x,y]) = \Sigma (x,y) : (\Sigma x : A . B[x]) . C[x,y]$, when in general this identity only holds up to isomorphism. Hence we seem to have crossed over from Scylla of our semantics for dependent type theory not being strict enough to interpret those identities we expect to hold strictly, to the Charybdis of them now being too strict to interpret the identities we expect to hold only up to isomorphism. It was for this reason that Awodey & Newstead were forced to ultimately go beyond Polynomial functors in their accounts of natural models. 119 | 120 | However, another possibility exists to solve this dilemma – to use the language of HoTT itself to reason about such equality-up-to-isomorphism in natural models. For this purpose, rather than taking natural models to be certain (representable) morphisms in $\mathbf{Set}^{\mathcal{C}^{op}}$, we can instead expand the mathematical universe in which these models live to $\mathbf{\infty Grpd}^{\mathcal{C}^{op}}$, which, as an $\infty$-topos, has HoTT as its internal language. Taking advantage of this fact, we can use HoTT itself as a language for studying the semantics of type theory, by postulating an abstract type $\mathcal{U}$ together with a type family $u : \mathcal{U} \to \mathsf{Type}$, corresponding to a representable natural transformation $u : \mathcal{U}_\bullet \Rightarrow \mathcal{U}$ as above. 121 | 122 | What remains, then, is to show how the various type-theoretic properties of such natural models can be expressed in terms of polynomial functors in the language of HoTT, and the complex identities to which these give rise. For this purpose, we begin with a recap of the basics of HoTT, before launching into a development of the theory of polynomial functors within HoTT, with an eye toward the latter's use in the study of natural models. 123 | 124 | ## Homotopy Type Theory 125 | 126 | ### The Identity Type 127 | 128 | Given elements `a,b : A` for some type `A`, the identity type `a ≡ b` is inductively generated from the single constructor `refl : {x : A} → x ≡ x`, witnessing reflexivity of equality. 129 | 130 | ```agda 131 | open import Agda.Builtin.Equality 132 | open import Agda.Builtin.Equality.Rewrite 133 | ``` 134 | 135 | The core insight of Homotopy Type Theory is that the presence of (intensional) identity types in a system of dependent type theory endows each type with the structure of an $\infty$-groupoid, and endows each function between types with the structure of a functor between $\infty$-groupoids, etc. This allows a wealth of higher-categorical properties and structures to be defined and studied *internally* in the language of dependent type theory. 136 | 137 | Since an invocation of reflexivity typically occurs at the end of an equality proof, we introduce the notation `□` as a shorthand for `refl` as follows: 138 | 139 | ```agda 140 | _□ : ∀ {ℓ} {A : Type ℓ} (a : A) → a ≡ a 141 | a □ = refl 142 | ``` 143 | 144 | The inductive generation of `a ≡ b` from `refl` then gives rise to the operation of *transport* that allows an inhabitant of the type `B a` to be converted to an inhabitant of `B b` for any type family `B : (x : A) → Type`. 145 | 146 | ```agda 147 | transp : ∀ {ℓ κ} {A : Type ℓ} (B : A → Type κ) {a a' : A} 148 | → (e : a ≡ a') → B a → B a' 149 | transp B refl b = b 150 | ``` 151 | 152 | Transitivity of equality then follows in the usual way.[^1]: 153 | 154 | ```agda 155 | _•_ : ∀ {ℓ} {A : Type ℓ} {a b c : A} 156 | → (a ≡ b) → (b ≡ c) → (a ≡ c) 157 | e • refl = e 158 | ``` 159 | 160 | [^1]: We also take advantage of Agda's support for mixfix notation to present transitivity in such a way as to streamline both the reading and writing of equality proofs: 161 | 162 | ```agda 163 | _≡〈_〉_ : ∀ {ℓ} {A : Type ℓ} (a : A) {b c : A} 164 | → a ≡ b → b ≡ c → a ≡ c 165 | a ≡〈 e 〉 refl = e 166 | 167 | comprewrite : ∀ {ℓ} {A : Type ℓ} {a b c : A} 168 | → (e1 : a ≡ b) (e2 : b ≡ c) 169 | → (a ≡〈 e1 〉 e2) ≡ (e1 • e2) 170 | comprewrite refl refl = refl 171 | 172 | {-# REWRITE comprewrite #-} 173 | ``` 174 | 175 | Symmetry of equality follows similarly: 176 | 177 | ```agda 178 | sym : ∀ {ℓ} {A : Type ℓ} {a a' : A} → a ≡ a' → a' ≡ a 179 | sym refl = refl 180 | ``` 181 | 182 | As mentioned above, each function `f : A → B` in HoTT is canonically endowed with the structure of a functor between $\infty$-groupoids, where the action of such a function `f` on paths (i.e. elements of the identity type) is as follows: 183 | 184 | ```agda 185 | ap : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {a a' : A} 186 | → (f : A → B) → a ≡ a' → (f a) ≡ (f a') 187 | ap f refl = refl 188 | ``` 189 | 190 | By the same token, given a proof `f ≡ g` for two functions `f,g : (x : A) → B x`, it follows that for any `a : A` we have `f a ≡ g a`. 191 | 192 | ```agda 193 | coAp : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {f g : (x : A) → B x} 194 | → f ≡ g → (x : A) → f x ≡ g x 195 | coAp refl x = refl 196 | ``` 197 | 198 | We additionally have the following "dependent" form of `ap` as above, allowing us to apply a dependent function to both sides of an identity, in a suitable manner: 199 | 200 | ```agda 201 | apd : ∀ {ℓ0 ℓ1 κ} {A : Type ℓ0} {B : Type ℓ1} {f : A → B} 202 | → (C : B → Type κ) {a a' : A} 203 | → (g : (x : A) → C (f x)) → (e : a ≡ a') → transp C (ap f e) (g a) ≡ g a' 204 | apd B f refl = refl 205 | ``` 206 | 207 | To show that two pairs `(a , b)` and `(a' , b')` are equal, it suffices to show that there is an identification `e : a ≡ a'` together with `e' : transp B e b ≡ b'`. 208 | 209 | ```agda 210 | module PairEq {ℓ κ} {A : Type ℓ} {B : A → Type κ} 211 | {a a' : A} {b : B a} {b' : B a'} where 212 | 213 | pairEq : (e : a ≡ a') (e' : transp B e b ≡ b') → (a , b) ≡ (a' , b') 214 | pairEq refl refl = refl 215 | ``` 216 | 217 | We then have the following laws governing equality proofs for pairs. 218 | 219 | ```agda 220 | pairEqβ1 : (e : a ≡ a') (e' : transp B e b ≡ b') → ap fst (pairEq e e') ≡ e 221 | pairEqβ1 refl refl = refl 222 | 223 | pairEqη : (e : (a , b) ≡ (a' , b')) → pairEq (ap fst e) (apd B snd e) ≡ e 224 | pairEqη refl = refl 225 | 226 | open PairEq public 227 | ``` 228 | 229 | ### Equivalences 230 | 231 | A pivotal notion, both for HoTT in general, and for the content of this paper, is that of a function `f : A → B` being an *equivalence* of types. The reader familiar with HoTT will know that there are several definitions – all equivalent – of this concept appearing in the HoTT literature. For present purposes, we make use of the *bi-invertible maps* notion of equivalence. Hence we say that a function `f : A → B` is an equivalence if it has both a left inverse and a right inverse: 232 | 233 | ```agda 234 | isEquiv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} → (A → B) → Type (ℓ ⊔ κ) 235 | isEquiv {A = A} {B = B} f = 236 | (Σ (B → A) (λ g → (a : A) → g (f a) ≡ a)) 237 | × (Σ (B → A) (λ h → (b : B) → f (h b) ≡ b)) 238 | ``` 239 | 240 | Straightforwardly, the identity function at each type is an equivalence, and equivalences are closed under composition: 241 | 242 | ```agda 243 | idIsEquiv : ∀ {ℓ} {A : Type ℓ} → isEquiv {A = A} (λ x → x) 244 | idIsEquiv = ((λ x → x) , (λ x → refl)) , ((λ x → x) , (λ x → refl)) 245 | 246 | compIsEquiv : ∀ {ℓ0 ℓ1 ℓ2} {A : Type ℓ0} {B : Type ℓ1} {C : Type ℓ2} 247 | → {g : B → C} {f : A → B} → isEquiv g → isEquiv f 248 | → isEquiv (λ a → g (f a)) 249 | compIsEquiv {g = g} {f = f} 250 | ((g' , lg) , (g'' , rg)) 251 | ((f' , lf) , (f'' , rf)) = 252 | ( (λ c → f' (g' c)) 253 | , λ a → (f' (g' (g (f a)))) ≡〈 ap f' (lg (f a)) 〉 254 | (f' (f a) ≡〈 lf a 〉 255 | (a □))) 256 | , ((λ c → f'' (g'' c)) 257 | , λ c → (g (f (f'' (g'' c)))) ≡〈 ap g (rf (g'' c)) 〉 258 | (g (g'' c) ≡〈 rg c 〉 259 | (c □))) 260 | ``` 261 | 262 | A closely-related notion to equivalence is that of a function `f` being an *isomorphism*, i.e. having a single two-sided inverse: 263 | 264 | ```agda 265 | Iso : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} → (A → B) → Type (ℓ ⊔ κ) 266 | Iso {A = A} {B = B} f = 267 | (Σ (B → A) (λ g → ((a : A) → g (f a) ≡ a) 268 | × ((b : B) → f (g b) ≡ b))) 269 | ``` 270 | 271 | One might be inclined to wonder, then, why we bother to define equivalence via the seemingly more complicated notion of having both a left and a right inverse when the familiar notion of isomorphism can just as well be defined, as above. The full reasons for this are beyond the scope of this paper, though see \cite{hottbook} for further discussion. Suffice it to say that, for subtle reasons due to the higher-categorical structure of types in HoTT, the plain notion of isomorphism given above is not a *good* notion of equivalence, whereas that of bi-invertible maps is. In particular, the type `Iso f` is not necessarily a proposition for arbitrary `f`, whereas `isEquiv f` is. 272 | 273 | We may nonetheless move more-or-less freely back and forth between the notions of equivalence and isomorphism given above, thanks to the following functions, which allow us to convert isomorphisms to equivalences and vice versa: 274 | 275 | ```agda 276 | module Iso↔Equiv {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} where 277 | 278 | Iso→isEquiv : Iso f → isEquiv f 279 | Iso→isEquiv (g , l , r) = ((g , l) , (g , r)) 280 | 281 | isEquiv→Iso : isEquiv f → Iso f 282 | isEquiv→Iso ((g , l) , (h , r)) = 283 | h , (λ x → (h (f x)) ≡〈 sym (l (h (f x))) 〉 284 | (g (f (h (f x))) ≡〈 ap g (r (f x)) 〉 285 | ((g (f x)) ≡〈 l x 〉 286 | (x □)))) , r 287 | 288 | open Iso↔Equiv public 289 | ``` 290 | 291 | And by the above translation between equivalences and isomorphisms, each equivalence has a corresponding inverse map in the opposite direction, which is itself an equivalence: 292 | 293 | ```agda 294 | module InvEquiv {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} where 295 | 296 | inv : isEquiv f → B → A 297 | inv (_ , (h , _)) = h 298 | 299 | isoInv : (isof : Iso f) → Iso (fst isof) 300 | isoInv (g , l , r) = (f , r , l) 301 | 302 | invIsEquiv : (ef : isEquiv f) → isEquiv (inv ef) 303 | invIsEquiv ef = Iso→isEquiv (isoInv (isEquiv→Iso ef)) 304 | 305 | open InvEquiv public 306 | ``` 307 | 308 | We note that, for each type family `B : A → Type`, the map `B a → B a'` induced by transport along `e : a ≡ a'` for any `a, a' : A` is an equivalence with inverse given by transport along `sym e`, as follows: 309 | 310 | ```agda 311 | module TranspEquiv {ℓ κ} {A : Type ℓ} {B : A → Type κ} {a b : A} (e : a ≡ b) where 312 | 313 | syml : (x : B a) → transp B (sym e) (transp B e x) ≡ x 314 | syml x rewrite e = refl 315 | 316 | symr : (y : B b) → transp B e (transp B (sym e) y) ≡ y 317 | symr y rewrite e = refl 318 | 319 | transpIsEquiv : isEquiv {A = B a} {B = B b} (λ x → transp B e x) 320 | transpIsEquiv = Iso→isEquiv ((λ x → transp B (sym e) x) , (syml , symr)) 321 | 322 | open TranspEquiv public 323 | ``` 324 | 325 | ### Truncation, Bracket Types & Factorization 326 | 327 | We say that a type `A` is: 328 | 329 | 1. *contractible* (aka (-2)-truncated) if `A` is uniquely inhabited 330 | 2. a (mere) *proposition* (aka (-1)-truncated) if any two elements of `A` are identical 331 | 3. a *set* (aka 0-truncated) if for any `a,b : A`, the type `a ≡ b` is a proposition. 332 | 333 | ```agda 334 | isContr : ∀ {ℓ} → Type ℓ → Type ℓ 335 | isContr A = Σ A (λ a → (b : A) → a ≡ b) 336 | 337 | isProp : ∀ {ℓ} → Type ℓ → Type ℓ 338 | isProp A = {a b : A} → a ≡ b 339 | 340 | isSet : ∀ {ℓ} → Type ℓ → Type ℓ 341 | isSet A = (a b : A) → isProp (a ≡ b) 342 | ``` 343 | 344 | We additionally postulate the existence of a *propositional truncation,* or *bracket type* operation, that takes a type `A` to the least proposition (wrt entailment) entailed by inhabitation of `A`. 345 | 346 | ```agda 347 | postulate 348 | ∥_∥ : ∀ {ℓ} (A : Type ℓ) → Type lzero 349 | in∥-∥ : ∀ {ℓ} {A : Type ℓ} → A → ∥ A ∥ 350 | ∥-∥IsProp : ∀ {ℓ} {A : Type ℓ} → isProp (∥ A ∥) 351 | ∥-∥≡Contr : ∀ {ℓ} {A : Type ℓ} {a b : ∥ A ∥} {e : a ≡ b} → ∥-∥IsProp ≡ e 352 | ∥-∥Rec : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} 353 | → isProp B → (A → B) → ∥ A ∥ → B 354 | ``` 355 | 356 | When the type `∥ A ∥` is inhabited, we say that `A` is *merely* inhabited. 357 | 358 | From this operation on types, we straightforwardly obtain the higher analogue of the usual epi-mono factorization system on functions between sets, as follows: 359 | 360 | ```agda 361 | module Epi-Mono {ℓ κ} {A : Type ℓ} {B : Type κ} (f : A → B) where 362 | ``` 363 | 364 | We say that a function `f : A → B` is *injective* (i.e. a monomorphism), if for all `a , b : A` the map `ap f : a ≡ b → f a ≡ f b` is an equivalence 365 | 366 | ```agda 367 | isMono : Type (ℓ ⊔ κ) 368 | isMono = {a b : A} → isEquiv (ap {a = a} {a' = b} f) 369 | ``` 370 | 371 | Given an element `b : B`, the *fibre* of `f` at `b` is the type of elements of `a` equipped with a proof of `f a ≡ b`: 372 | 373 | ```agda 374 | Fibre : B → Type (ℓ ⊔ κ) 375 | Fibre b = Σ A (λ a → f a ≡ b) 376 | ``` 377 | 378 | We then say that `f` is *surjective* (i.e. an epimorphism), if all of its fibres are merely inhabited. 379 | 380 | ```agda 381 | isEpi : Type κ 382 | isEpi = (b : B) → ∥ Fibre b ∥ 383 | 384 | open Epi-Mono public 385 | 386 | module EMFactor {ℓ κ} {A : Type ℓ} {B : Type κ} (f : A → B) where 387 | ``` 388 | 389 | Given a function `f`, its *image* is the type of elements of `B` whose fibres are merely inhabited. 390 | 391 | ```agda 392 | Im : Type κ 393 | Im = Σ B (λ b → ∥ Fibre f b ∥) 394 | ``` 395 | 396 | Every function `f` can then be factored into a (-1)-connected map onto its image followed by a (-1)-truncated map onto its codomain: 397 | 398 | ```agda 399 | factor1 : A → Im 400 | factor1 a = (f a) , in∥-∥ (a , refl) 401 | 402 | factor2 : Im → B 403 | factor2 (b , _) = b 404 | 405 | factor≡ : (a : A) → factor2 (factor1 a) ≡ f a 406 | factor≡ a = refl 407 | 408 | factor1IsEpi : isEpi factor1 409 | factor1IsEpi (b , x) = 410 | ∥-∥Rec ∥-∥IsProp 411 | (λ {(a , refl) → in∥-∥ (a , pairEq refl ∥-∥IsProp)}) 412 | x 413 | 414 | factor2IsMono : isMono factor2 415 | factor2IsMono {a = (a , α)} {b = (b , β)} = 416 | Iso→isEquiv ( (λ e → pairEq e ∥-∥IsProp) 417 | , ( (λ e → (pairEq (ap factor2 e) ∥-∥IsProp) 418 | ≡〈 (ap (pairEq (ap factor2 e)) ∥-∥≡Contr) 〉 419 | ( _ 420 | ≡〈 pairEqη e 〉 421 | (e □))) 422 | , λ e → pairEqβ1 e ∥-∥IsProp)) 423 | 424 | open EMFactor public 425 | ``` 426 | 427 | Some additional facts about the identity type, that will be used in formalizing the results of this paper, are given in Appendix A. -------------------------------------------------------------------------------- /part3.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/part3.agdai -------------------------------------------------------------------------------- /part3.lagda.md: -------------------------------------------------------------------------------- 1 | ```agda 2 | {-# OPTIONS --without-K --rewriting #-} 3 | module part3 where 4 | 5 | open import Agda.Primitive 6 | open import Agda.Builtin.Unit 7 | open import Agda.Builtin.Sigma 8 | open import Agda.Builtin.Equality 9 | open import Agda.Builtin.Equality.Rewrite 10 | open import part1 11 | open import part2 12 | ``` 13 | 14 | # Polynomial Universes 15 | 16 | ## Univalence 17 | 18 | For any polynomial `𝔲 = (A , B)` and elements `a,b : A`, we may define a function that takes a proof of `a ≡ b` to an equivalence `B a ≃ B b`. 19 | 20 | ```agda 21 | idToEquiv : ∀ {ℓ κ} (p : Poly ℓ κ) (a b : fst p) 22 | → a ≡ b → Σ (snd p a → snd p b) isEquiv 23 | idToEquiv p a b e = 24 | transp (snd p) e 25 | , Iso→isEquiv (transp (snd p) (sym e) , (syml e , symr e)) 26 | ``` 27 | 28 | We say that a polynomial `𝔲` is *univalent* if for all `a,b : A`, this function is an equivalence. 29 | 30 | ```agda 31 | isUnivalent : ∀ {ℓ κ} → Poly ℓ κ → Type (ℓ ⊔ κ) 32 | isUnivalent (A , B) = 33 | (a b : A) → isEquiv (idToEquiv (A , B) a b) 34 | ``` 35 | 36 | We call this property of polynomials univalence by analogy with the usual univalence axiom of HoTT. Indeed, the univalence axiom simply states that the polynomial functor `(Type , λ X → X)` is itself univalent. 37 | 38 | ```agda 39 | postulate 40 | ua : ∀ {ℓ} → isUnivalent (Type ℓ , λ X → X) 41 | ``` 42 | 43 | A key property of polynomial universes – qua polynomial functors – is that every polynomial universe `𝔲` is a *subterminal object* in $\mathbf{Poly^{Cart}}$, i.e. for any other polynomial `p`, the type of Cartesian lenses `p ⇆ 𝔲` is a proposition, i.e. any two Cartesian lenses with codomain `𝔲` are equal. 44 | 45 | ```agda 46 | isSubterminal : ∀ {ℓ κ} (u : Poly ℓ κ) → Setω 47 | isSubterminal u = ∀ {ℓ' κ'} (p : Poly ℓ' κ') 48 | → (f g : p ⇆ u) 49 | → isCartesian p u f 50 | → isCartesian p u g 51 | → EqLens p u f g 52 | ``` 53 | 54 | To show this, we first prove the following *transport lemma*, which says that transporting along an identity `a ≡ b` induced by an equivalence `f : B a ≃ B b` in a univalent polynomial `p = (A , B)` is equivalent to applying `f`. 55 | 56 | ```agda 57 | transpLemma : ∀ {ℓ κ} {𝔲 : Poly ℓ κ} 58 | → (univ : isUnivalent 𝔲) 59 | → {a b : fst 𝔲} (f : snd 𝔲 a → snd 𝔲 b) 60 | → (ef : isEquiv f) (x : snd 𝔲 a) 61 | → transp (snd 𝔲) (inv (univ a b) (f , ef)) x ≡ f x 62 | transpLemma {𝔲 = 𝔲} univ {a = a} {b = b} f ef x = 63 | coAp (ap fst (snd (snd (univ a b)) ((f , ef)))) x 64 | ``` 65 | 66 | The result then follows: 67 | 68 | ```agda 69 | univ→Subterminal : ∀ {ℓ κ} (u : Poly ℓ κ) 70 | → isUnivalent u 71 | → isSubterminal u 72 | univ→Subterminal u univ p f g cf cg a = 73 | ( inv univfg (fg⁻¹ , efg⁻¹) 74 | , (λ b → sym ((snd g a (transp (snd u) (inv univfg (fg⁻¹ , efg⁻¹)) b)) 75 | ≡〈 (ap (snd g a) (transpLemma univ fg⁻¹ efg⁻¹ b)) 〉 76 | ((snd g a (fg⁻¹ b)) 77 | ≡〈 snd (snd (cg a)) (snd f a b) 〉 78 | ((snd f a b) □))))) 79 | where univfg : isEquiv (idToEquiv u (fst f a) (fst g a)) 80 | univfg = univ (fst f a) (fst g a) 81 | fg⁻¹ : snd u (fst f a) → snd u (fst g a) 82 | fg⁻¹ x = inv (cg a) (snd f a x) 83 | efg⁻¹ : isEquiv fg⁻¹ 84 | efg⁻¹ = compIsEquiv (inv (cg a)) (snd f a) 85 | (invIsEquiv (cg a)) (cf a) 86 | ``` 87 | 88 | We shall refer to polynomial functors with this property of being subterminal objects in $\mathbf{Poly^{Cart}}$ as *polynomial universes.* As we shall see, such polynomial universes have many desirable properties as models of type theory. 89 | 90 | If we think of a polynomial `p` as representing a family of types, then what this tells us is that if `𝔲` is a polynomial universe, there is essentially at most one way for `𝔲` to contain the types represented by `p`, where Containment is here understood as existence of a Cartesian lens `p ⇆ 𝔲`. In this case, we say that `𝔲` *classifies* the types represented by `p`. 91 | 92 | As a direct consequence of this fact, it follows that every diagram consisting of parallel Cartesian lenses into a polynomial universe automatically commutes, and moreover, every higher diagram that can be formed between the cells exhibiting such commutation must also commute, etc. 93 | 94 | Hence the fact that `𝔲` must satisfy the laws of a monad if there are Cartesian lenses `η : 𝕪 ⇆ 𝔲` and `μ : 𝔲 ◃ 𝔲 ⇆ 𝔲` follows immediately from the above theorem and the closure of Cartesian lenses under composition: 95 | 96 | ```agda 97 | univ◃unitl : ∀ {ℓ κ} (𝔲 : Poly ℓ κ) → isUnivalent 𝔲 98 | → (η : 𝕪 ⇆ 𝔲) (μ : (𝔲 ◃ 𝔲) ⇆ 𝔲) 99 | → isCartesian 𝕪 𝔲 η → isCartesian (𝔲 ◃ 𝔲) 𝔲 μ 100 | → EqLens (𝕪 ◃ 𝔲) 𝔲 101 | (◃unitl 𝔲) 102 | (comp (𝕪 ◃ 𝔲) (𝔲 ◃ 𝔲) 𝔲 103 | (◃Lens 𝕪 𝔲 𝔲 𝔲 η (id 𝔲)) μ) 104 | univ◃unitl 𝔲 univ η μ cη cμ = 105 | univ→Subterminal 106 | 𝔲 univ (𝕪 ◃ 𝔲) (◃unitl 𝔲) 107 | (comp (𝕪 ◃ 𝔲) (𝔲 ◃ 𝔲) 𝔲 108 | (◃Lens 𝕪 𝔲 𝔲 𝔲 η (id 𝔲)) μ) 109 | (◃unitlCart 𝔲) 110 | (compCartesian (𝕪 ◃ 𝔲) (𝔲 ◃ 𝔲) 𝔲 111 | (◃Lens 𝕪 𝔲 𝔲 𝔲 η (id 𝔲)) μ 112 | (◃LensCart 𝕪 𝔲 𝔲 𝔲 η (id 𝔲) 113 | cη (idCart 𝔲)) cμ) 114 | 115 | univ◃unitr : ∀ {ℓ κ} (𝔲 : Poly ℓ κ) → isUnivalent 𝔲 116 | → (η : 𝕪 ⇆ 𝔲) (μ : (𝔲 ◃ 𝔲) ⇆ 𝔲) 117 | → isCartesian 𝕪 𝔲 η → isCartesian (𝔲 ◃ 𝔲) 𝔲 μ 118 | → EqLens (𝔲 ◃ 𝕪) 𝔲 119 | (◃unitr 𝔲) 120 | (comp (𝔲 ◃ 𝕪) (𝔲 ◃ 𝔲) 𝔲 121 | (◃Lens 𝔲 𝔲 𝕪 𝔲 (id 𝔲) η) μ) 122 | univ◃unitr 𝔲 univ η μ cη cμ = 123 | univ→Subterminal 124 | 𝔲 univ (𝔲 ◃ 𝕪) (◃unitr 𝔲) 125 | (comp (𝔲 ◃ 𝕪) (𝔲 ◃ 𝔲) 𝔲 126 | (◃Lens 𝔲 𝔲 𝕪 𝔲 (id 𝔲) η) μ) 127 | (◃unitrCart 𝔲) 128 | (compCartesian (𝔲 ◃ 𝕪) (𝔲 ◃ 𝔲) 𝔲 129 | (◃Lens 𝔲 𝔲 𝕪 𝔲 (id 𝔲) η) μ 130 | (◃LensCart 𝔲 𝔲 𝕪 𝔲 (id 𝔲) η 131 | (idCart 𝔲) cη) cμ) 132 | 133 | 134 | univ◃assoc : ∀ {ℓ κ} (𝔲 : Poly ℓ κ) → isUnivalent 𝔲 135 | → (η : 𝕪 ⇆ 𝔲) (μ : (𝔲 ◃ 𝔲) ⇆ 𝔲) 136 | → isCartesian 𝕪 𝔲 η → isCartesian (𝔲 ◃ 𝔲) 𝔲 μ 137 | → EqLens ((𝔲 ◃ 𝔲) ◃ 𝔲) 𝔲 138 | (comp ((𝔲 ◃ 𝔲) ◃ 𝔲) (𝔲 ◃ 𝔲) 𝔲 139 | (◃Lens (𝔲 ◃ 𝔲) 𝔲 𝔲 𝔲 μ (id 𝔲)) μ) 140 | (comp ((𝔲 ◃ 𝔲) ◃ 𝔲) (𝔲 ◃ (𝔲 ◃ 𝔲)) 𝔲 141 | (◃assoc 𝔲 𝔲 𝔲) 142 | (comp (𝔲 ◃ (𝔲 ◃ 𝔲)) (𝔲 ◃ 𝔲) 𝔲 143 | (◃Lens 𝔲 𝔲 (𝔲 ◃ 𝔲) 𝔲 144 | (id 𝔲) μ) μ)) 145 | univ◃assoc 𝔲 univ η μ cη cμ = 146 | univ→Subterminal 147 | 𝔲 univ ((𝔲 ◃ 𝔲) ◃ 𝔲) 148 | (comp ((𝔲 ◃ 𝔲) ◃ 𝔲) (𝔲 ◃ 𝔲) 𝔲 149 | (◃Lens (𝔲 ◃ 𝔲) 𝔲 𝔲 𝔲 μ (id 𝔲)) μ) 150 | (comp ((𝔲 ◃ 𝔲) ◃ 𝔲) (𝔲 ◃ (𝔲 ◃ 𝔲)) 𝔲 151 | (◃assoc 𝔲 𝔲 𝔲) 152 | (comp (𝔲 ◃ (𝔲 ◃ 𝔲)) (𝔲 ◃ 𝔲) 𝔲 153 | (◃Lens 𝔲 𝔲 (𝔲 ◃ 𝔲) 𝔲 (id 𝔲) μ) μ)) 154 | (compCartesian ((𝔲 ◃ 𝔲) ◃ 𝔲) (𝔲 ◃ 𝔲) 𝔲 155 | (◃Lens (𝔲 ◃ 𝔲) 𝔲 𝔲 𝔲 μ (id 𝔲)) μ 156 | (◃LensCart (𝔲 ◃ 𝔲) 𝔲 𝔲 𝔲 μ (id 𝔲) 157 | cμ (idCart 𝔲)) cμ) 158 | (compCartesian ((𝔲 ◃ 𝔲) ◃ 𝔲) (𝔲 ◃ (𝔲 ◃ 𝔲)) 𝔲 159 | (◃assoc 𝔲 𝔲 𝔲) 160 | (comp (𝔲 ◃ (𝔲 ◃ 𝔲)) (𝔲 ◃ 𝔲) 𝔲 161 | (◃Lens 𝔲 𝔲 (𝔲 ◃ 𝔲) 𝔲 162 | (id 𝔲) μ) μ) 163 | (◃assocCart 𝔲 𝔲 𝔲) 164 | (compCartesian 165 | (𝔲 ◃ (𝔲 ◃ 𝔲)) (𝔲 ◃ 𝔲) 𝔲 166 | (◃Lens 𝔲 𝔲 (𝔲 ◃ 𝔲) 𝔲 (id 𝔲) μ) μ 167 | (◃LensCart 𝔲 𝔲 (𝔲 ◃ 𝔲) 𝔲 (id 𝔲) μ 168 | (idCart 𝔲) cμ) cμ)) 169 | ``` 170 | 171 | And more generally, all the higher coherences of an $\infty$-monad should follow from the contractibility of the types of Cartesian lenses `p ⇆ 𝔲` that can be formed using `μ` and `η`. 172 | 173 | ### Rezk Completion of Polynomial Functors 174 | 175 | We have so far seen that polynomial universes are quite special objects in the theory of polynomial functors in HoTT, but what good would such special objects do us if they turned out to be exceedingly rare or difficult to construct? In fact, we can show that for *any* polynomial functor, there exists a corresponding polynomial universe, using a familiar construct from the theory of categories in HoTT – the *Rezk Completion.* We will show that this construction allows us to quotient any polynomial functor to a corresponding polynomial universe. 176 | 177 | By our assumption of the univalence axiom, every polynomial functor `p` is classified by *some* univalent polynomial: 178 | 179 | ```agda 180 | classifier : ∀ {ℓ κ} (p : Poly ℓ κ) → p ⇆ (Type κ , λ X → X) 181 | classifier (A , B) = (B , λ a b → b) 182 | 183 | classifierCart : ∀ {ℓ κ} (p : Poly ℓ κ) 184 | → isCartesian p (Type κ , λ X → X) 185 | (classifier p) 186 | classifierCart p a = idIsEquiv 187 | ``` 188 | 189 | We then obtain the Rezk completion of `p` as the image factorization in $\mathbf{Poly^{Cart}}$ of this classifying lens: 190 | 191 | ```agda 192 | Rezk : ∀ {ℓ κ} (p : Poly ℓ κ) → Poly (lsuc κ) κ 193 | Rezk (A , B) = (Im B) , (λ (X , _) → X) 194 | 195 | →Rezk : ∀ {ℓ κ} (p : Poly ℓ κ) → p ⇆ (Rezk p) 196 | →Rezk {κ = κ} p = 197 | factorcart1 p (Type κ , λ X → X) 198 | (classifier p) 199 | (classifierCart p) 200 | 201 | Rezk→ : ∀ {ℓ κ} (p : Poly ℓ κ) → (Rezk p) ⇆ (Type κ , λ X → X) 202 | Rezk→ {κ = κ} p = 203 | factorcart2 p (Type κ , λ X → X) 204 | (classifier p) 205 | (classifierCart p) 206 | ``` 207 | 208 | Because the map `Rezk→` defined above is a Cartesian embedding, and the polynomial `(Type κ , λ X → X)` is univalent, it follows that `Rezk p` is a polynomial universe: 209 | 210 | ```agda 211 | RezkSubterminal : ∀ {ℓ κ} (p : Poly ℓ κ) → isSubterminal (Rezk p) 212 | RezkSubterminal {κ = κ} p q (f , f♯) (g , g♯) cf cg x = 213 | ( pairEq (inv (ua (fst (f x)) (fst (g x))) 214 | ( (λ y → inv (cg x) (f♯ x y)) 215 | , compIsEquiv (inv (cg x)) 216 | (f♯ x) 217 | (invIsEquiv (cg x)) 218 | (cf x))) ∥-∥IsProp 219 | , λ y → f♯ x y 220 | ≡〈 sym (g♯ x (transp (λ X → X) 221 | (inv (ua (fst (f x)) (fst (g x))) 222 | ((λ z → inv (cg x) (f♯ x z)) , (compIsEquiv (inv (cg x)) (f♯ x) 223 | (invIsEquiv (cg x)) 224 | (cf x)))) y) 225 | ≡〈 (ap (g♯ x) 226 | (transpLemma ua 227 | (λ z → inv (cg x) (f♯ x z)) 228 | (compIsEquiv (inv (cg x)) (f♯ x) 229 | (invIsEquiv (cg x)) (cf x)) 230 | y)) 〉 231 | snd (snd (cg x)) (f♯ x y)) 〉 232 | ap (g♯ x) (sym (lemma1 ∥-∥IsProp y)) ) 233 | where lemma1 : {a b : fst (Rezk p)} 234 | → {e : fst a ≡ fst b} 235 | → (e' : transp (λ c → ∥ (Fibre (snd p) c) ∥) 236 | e (snd a) 237 | ≡ (snd b)) 238 | → (z : fst a) 239 | → transp (snd (Rezk p)) (pairEq e e') z 240 | ≡ transp (λ X → X) e z 241 | lemma1 {e = refl} refl z = refl 242 | ``` -------------------------------------------------------------------------------- /part3v2.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/part3v2.agdai -------------------------------------------------------------------------------- /part3v2.lagda.md: -------------------------------------------------------------------------------- 1 | ```agda 2 | {-# OPTIONS --without-K --rewriting --lossy-unification #-} 3 | module part3v2 where 4 | 5 | open import part1v2 6 | open import Agda.Primitive 7 | open import Agda.Builtin.Sigma 8 | open import Agda.Builtin.Unit 9 | open import Agda.Builtin.Equality 10 | open import Agda.Builtin.Equality.Rewrite 11 | open import part2v2 12 | open import appendixA 13 | ``` 14 | 15 | # Polynomials in HoTT 16 | 17 | ## Basics 18 | 19 | **Remark:** for the sake of concision, since essentially all of the categorical structures treated in this paper will be infinite-dimensional, we shall generally omit the prefix "$\infty$-" from our descriptions these structures. Hence hereafter "category" generally means $\infty$-category, "functor" means $\infty$-functor, etc. 20 | 21 | Let $\mathbf{Type}$ be the category of types and functions between them. Given a type `A`, let $y^A$ denote the corresponding representable functor $\mathbf{Type} \to \mathbf{Type}$. 22 | 23 | A *polynomial functor* is a coproduct of representable functors $\mathbf{Type} \to \mathbf{Type}$, i.e. an endofunctor on $\mathbf{Type}$ of the form $$ 24 | \sum_{a : A} y^{B(a)} 25 | $$ for some type `A` and family of types `B : A → Type`. The data of a polynomial functor is thus uniquely determined by the choice of `A` and `B`. Hence we may represent such functors in Agda simply as pairs (A , B) of this form: 26 | 27 | ```agda 28 | Poly : (ℓ κ : Level) → Type ((lsuc ℓ) ⊔ (lsuc κ)) 29 | Poly ℓ κ = Σ (Type ℓ) (λ A → A → Type κ) 30 | ``` 31 | 32 | A basic example of such a polynomial functor is the identity functor `𝕪` consisting of a single term of unit arity – hence represented by the pair `(⊤ , λ _ → ⊤)`. 33 | 34 | ```agda 35 | 𝕪 : Poly lzero lzero 36 | 𝕪 = (⊤ , λ _ → ⊤) 37 | ``` 38 | 39 | The observant reader may note the striking similarity of the above-given formula for a polynomial functor and the endofunctor on $\mathbf{Set}^{\mathcal{C}^{op}}$ defined in the previous section on natural models. Indeed, this is no accident, given a type `𝓤` and a function `u : 𝓤 → Type` corresponding to a natural model as described previously, we obtain the corresponding polynomial `𝔲 : Poly` as the pair `(𝓤 , u)`. Hence we can study the structure of `𝓤` and `u` in terms of `𝔲`, and this, as we shall see, allows for some significant simplifications in the theory of natural models. 40 | 41 | Given polynomial functors $p = \sum_{a : A} y^{B(a)}$ and $q = \sum_{c : C} y^{D(c)}$, a natural transformation $p \Rightarrow q$ is equivalently given by the data of a *forward* map `f : A → B` and a *backward* map `g : (a : A) → D (f a) → B a`, as can be seen from the following argument via Yoneda: $$ 42 | \begin{array}{rl} 43 | & \int_{y \in \mathbf{Type}} \left( \sum_{a : A} y^{B(a)} \right) \to \sum_{c : C} y^{D(c)}\\ 44 | \simeq & \prod_{a : A} \int_{y \in \mathbf{Type}} y^{B(a)} \to \sum_{c : C} y^{D(c)}\\ 45 | \simeq & \prod_{a : A} \sum_{c : C} B(a)^{D(c)}\\ 46 | \simeq & \sum_{f : A \to C} \prod_{a : A} B(a)^{D(f(c))} 47 | \end{array} 48 | $$ We use the notation $p \leftrightarrows q$ to denote the type of natural transformations from $p$ to $q$ (aka *lenses* from $p$ to $q$), which may be written in Agda as follows: 49 | 50 | ```agda 51 | _⇆_ : ∀ {ℓ0 ℓ1 κ0 κ1} → Poly ℓ0 κ0 → Poly ℓ1 κ1 → Type (ℓ0 ⊔ ℓ1 ⊔ κ0 ⊔ κ1) 52 | (A , B) ⇆ (C , D) = Σ (A → C) (λ f → (a : A) → D (f a) → B a) 53 | ``` 54 | 55 | By application of function extensionality, we derive the following type for proofs of equality between lenses: 56 | 57 | ```agda 58 | EqLens : ∀ {ℓ0 ℓ1 κ0 κ1} 59 | → {p : Poly ℓ0 κ0} (q : Poly ℓ1 κ1) 60 | → (f g : p ⇆ q) → Type (ℓ0 ⊔ ℓ1 ⊔ κ0 ⊔ κ1) 61 | EqLens {p = (A , B)} (C , D) (f , f♯) (g , g♯) = 62 | Σ ((a : A) → f a ≡ g a) 63 | (λ e → (a : A) (d : D (f a)) 64 | → f♯ a d ≡ g♯ a (transp D (e a) d)) 65 | ``` 66 | 67 | For each polynomial $p$, the correspnding identity lens is given by the following data: 68 | 69 | ```agda 70 | id : ∀ {ℓ κ} (p : Poly ℓ κ) → p ⇆ p 71 | id p = ( (λ a → a) , λ a b → b ) 72 | ``` 73 | 74 | And given lenses $p \leftrightarrows q$ and $q \leftrightarrows r$, their composition may be computed as follows: 75 | 76 | ```agda 77 | comp : ∀ {ℓ0 ℓ1 ℓ2 κ0 κ1 κ2} 78 | → {p : Poly ℓ0 κ0} {q : Poly ℓ1 κ1} (r : Poly ℓ2 κ2) 79 | → p ⇆ q → q ⇆ r → p ⇆ r 80 | comp r (f , f♯) (g , g♯) = 81 | ( (λ a → g (f a)) , λ a z → f♯ a (g♯ (f a) z) ) 82 | ``` 83 | 84 | Hence we have a category $\mathbf{Poly}$ of polynomial functors and lenses between them. Our goal, then, is to show how the type-theoretic structure of a natural model naturally arises from the structure of this category. In fact, $\mathbf{Poly}$ is replete with categorical structures of all kinds, of which we now mention but a few: 85 | 86 | ## The Vertical-Cartesian Factorization System on $\mathbf{Poly}$ 87 | 88 | We say that a lens `(f , f♯) : (A , B) ⇆ (C , D)` is *vertical* if `f : A → C` is an equivalence, and Cartesian if for every `a : A`, the map `f♯ a : D[f a] → B a` is an equivalence. 89 | 90 | ```agda 91 | module Vert-Cart {ℓ0 ℓ1 κ0 κ1} {p : Poly ℓ0 κ0} 92 | (q : Poly ℓ1 κ1) (f : p ⇆ q) where 93 | 94 | isVertical : Set (ℓ0 ⊔ ℓ1) 95 | isVertical = isEquiv (fst f) 96 | 97 | isCartesian : Set (ℓ0 ⊔ κ0 ⊔ κ1) 98 | isCartesian = (a : fst p) → isEquiv (snd f a) 99 | 100 | open Vert-Cart public 101 | ``` 102 | 103 | Every lens `(A , B) ⇆ (C , D)` can then be factored as a vertical lens followed by a Cartesian lens: 104 | 105 | ```agda 106 | module VertCartFactor {ℓ0 ℓ1 κ0 κ1} {p : Poly ℓ0 κ0} 107 | (q : Poly ℓ1 κ1) (f : p ⇆ q) where 108 | 109 | vcIm : Poly ℓ0 κ1 110 | vcIm = (fst p , λ x → snd q (fst f x)) 111 | 112 | vertfactor : p ⇆ vcIm 113 | vertfactor = ( (λ x → x) , (λ a x → snd f a x) ) 114 | 115 | vertfactorIsVert : isVertical vcIm vertfactor 116 | vertfactorIsVert = idIsEquiv 117 | 118 | cartfactor : vcIm ⇆ q 119 | cartfactor = ( fst f , (λ a x → x) ) 120 | 121 | cartfactorIsCart : isCartesian q cartfactor 122 | cartfactorIsCart x = idIsEquiv 123 | 124 | vertcartfactor≡ : EqLens q f (comp q vertfactor cartfactor) 125 | vertcartfactor≡ = ( (λ a → refl) , (λ a b → refl) ) 126 | 127 | open VertCartFactor public 128 | ``` 129 | 130 | Of these two classes of morphisms in $\mathbf{Poly}$, it is *Cartesian* lenses that shall be of principal interest to us. If we view a polynomial `p = (A , B)` as an `A`-indexed family of types, given by `B`, then given a lens `(f , f♯) : p ⇆ 𝔲`, we can think of the map `f♯ a : u (f a) → B a`, as an *elimination form* for the type `u (f a)`, i.e. a way of *using* elements of the type `u (f a)`. If we then ask that `(f , f♯)` isCartesian, this implies that the type `u (f a)` is completely characterized (up to equivalence) by this elimination form, and in this sense, `𝔲` *contains* the type `B a`, for all `a : A`.[^3] 131 | 132 | [^3]: Those familiar with type theory may recognize this practice of defining types in terms of their elimination forms as characteristic of so-called *negative* types (in opposition to *positive* types, which are characterized by their introduction forms). Indeed, there are good reasons for this, having to do with the fact that negative types are equivalently those whose universal property is given by a *representable* functor, rather than a *co-representable* functor, which reflects the fact that natural models are defined in terms of *presheaves* on a category of contexts, rather than *co-presheaves.* 133 | 134 | We can therefore use Cartesian lenses to detect which types are contained in a natural model `𝔲`. 135 | 136 | A further fact about Cartesian lenses is that they are closed under identity and composition, as a direct consequence of the closure of equivalences under identity and composition: 137 | 138 | ```agda 139 | idCart : ∀ {ℓ κ} (p : Poly ℓ κ) 140 | → isCartesian p (id p) 141 | idCart p a = idIsEquiv 142 | 143 | compCartesian : ∀ {ℓ0 ℓ1 ℓ2 κ0 κ1 κ2} 144 | → {p : Poly ℓ0 κ0} {q : Poly ℓ1 κ1} (r : Poly ℓ2 κ2) 145 | → {f : p ⇆ q} {g : q ⇆ r} 146 | → isCartesian q f → isCartesian r g 147 | → isCartesian r (comp r f g) 148 | compCartesian r {f = (f , f♯)} {g = (g , g♯)} cf cg a = 149 | compIsEquiv (cf a) (cg (f a)) 150 | ``` 151 | 152 | Hence there is a category $\mathbf{Poly^{Cart}}$ defined as the wide subcategory of $\mathbf{Poly}$ whose morphisms are precisely Cartesian lenses. As we shall see, much of the categorical structure of natural models qua polynomial functors can be derived from the subtle interplay between $\mathbf{Poly^{Cart}}$ and $\mathbf{Poly}$. 153 | 154 | ### Epi-Mono Factorization on $\mathbf{Poly^{Cart}}$ 155 | 156 | In fact, $\mathbf{Poly^{Cart}}$ itself inherits a factorization system from the epi-mono factorization on types considered previously. 157 | 158 | Define a lens `(f , f♯) : p ⇆ q` to be a *vertical embedding* if `f` is a monomorphism, and a *vertical surjection* if `f` is an epimorphism. 159 | 160 | ```agda 161 | module VertEpi-Mono {ℓ0 ℓ1 κ0 κ1} {p : Poly ℓ0 κ0} 162 | (q : Poly ℓ1 κ1) (f : p ⇆ q) where 163 | 164 | isVerticalEmbedding : Set (ℓ0 ⊔ ℓ1) 165 | isVerticalEmbedding = isMono (fst f) 166 | 167 | isVerticalSurjection : Set ℓ1 168 | isVerticalSurjection = isEpi (fst f) 169 | 170 | open VertEpi-Mono public 171 | ``` 172 | 173 | Then every Cartesian lens can be factored into a vertical surjection followed by a vertical embedding, both of which are Cartesian. 174 | 175 | ```agda 176 | module CartEMFactorization {ℓ0 ℓ1 κ0 κ1} {p : Poly ℓ0 κ0} 177 | (q : Poly ℓ1 κ1) (f : p ⇆ q) (cf : isCartesian q f) where 178 | 179 | cartIm : Poly ℓ1 κ1 180 | cartIm = (Im (fst f) , λ (x , _) → snd q x) 181 | 182 | factorcart1 : p ⇆ cartIm 183 | factorcart1 = ( factor1 (fst f) , snd f ) 184 | 185 | factorcart1IsCart : isCartesian cartIm factorcart1 186 | factorcart1IsCart = cf 187 | 188 | factorcart1IsEpi : isVerticalSurjection cartIm factorcart1 189 | factorcart1IsEpi = factor1IsEpi (fst f) 190 | 191 | factorcart2 : cartIm ⇆ q 192 | factorcart2 = ( factor2 (fst f) , (λ _ y → y) ) 193 | 194 | factorcart2IsCart : isCartesian q factorcart2 195 | factorcart2IsCart _ = idIsEquiv 196 | 197 | factorcart2IsMono : isVerticalEmbedding q factorcart2 198 | factorcart2IsMono = factor2IsMono (fst f) 199 | 200 | factorcart≡ : EqLens q f (comp q factorcart1 factorcart2) 201 | factorcart≡ = ( (λ x → refl) , (λ x y → refl) ) 202 | 203 | open CartEMFactorization public 204 | ``` 205 | 206 | We note in passing that the vertical embeddings are indeed the monomorphisms in $\mathbf{Poly}^{\mathbf{Cart}}$, i.e. if `f : q ⇆ r` is a both Cartesian and a vertical embedding, then for any Cartesian `g h : p ⇆ q` such that `f ∘ g ≡ f ∘ h`, we have `g = h`.[^1] 207 | 208 | ```agda 209 | VertEmbedding→PolyCartMono : ∀ {ℓ0 ℓ1 ℓ2 κ0 κ1 κ2} {p : Poly ℓ0 κ0} 210 | {q : Poly ℓ1 κ1} (r : Poly ℓ2 κ2) {f : q ⇆ r} 211 | → isCartesian r f → isVerticalEmbedding r f 212 | → {g h : p ⇆ q} → isCartesian q g → isCartesian q h 213 | → EqLens r (comp r g f) (comp r h f) 214 | → EqLens q g h 215 | VertEmbedding→PolyCartMono {p = p} {q = q} r {f = (f , f♯)} cf vef 216 | {g = (g , g♯)} {h = (h , h♯)} cg ch (e , e♯) = 217 | ( (λ a → inv vef (e a)) 218 | , (λ a d → (g♯ a d) 219 | ≡〈 ap (g♯ a) (sym (snd (snd (cf (g a))) d)) 〉 220 | ( _ ≡〈 (e♯ a (inv (cf (g a)) d)) 〉 221 | ( _ ≡〈 (ap (h♯ a) 222 | ( _ ≡〈 (ap (f♯ (h a)) 223 | (transpPre vef 224 | (λ x y → inv (cf x) y) 225 | (e a))) 〉 226 | ( _ ≡〈 snd (snd (cf (h a))) _ 〉 227 | ( _ □)))) 〉 228 | ((h♯ a (transp (snd q) (inv vef (e a)) d)) □)))) ) 229 | ``` 230 | 231 | ## Composition of Polynomial Functors 232 | 233 | As endofunctors on $\mathbf{Type}$, polynomial functors may straightforwardly be composed. To show that the resulting composite is itself (equivalent to) a polynomial functor, we can reason via the following chain of equivalences: given polynomials `(A , B)` and `(C , D)`, their composite, evaluated at a type `y` is $$ 234 | \begin{array}{rl} 235 | & \sum_{a : A} \prod_{b : B(a)} \sum_{c : C} y^{D(c)}\\ 236 | \simeq & \sum_{a : A} \sum_{f : B(a) \to C} \prod_{b : B(a)} y^{D(f(b))}\\ 237 | \simeq & \sum_{(a , f) : \sum_{a : A} C^{B(a)}} y^{\sum_{b : B(a)} D(f(b))} 238 | \end{array} 239 | $$ This then defines a monoidal product $◃$ on $\mathbf{Poly}$ with monoidal unit given by the identity functor `𝕪`: 240 | 241 | ```agda 242 | _◃_ : ∀ {ℓ0 ℓ1 κ0 κ1} → Poly ℓ0 κ0 → Poly ℓ1 κ1 → Poly (ℓ0 ⊔ κ0 ⊔ ℓ1) (κ0 ⊔ κ1) 243 | (A , B) ◃ (C , D) = (Σ A (λ a → B a → C) , λ (a , f) → Σ (B a) (λ b → D (f b))) 244 | 245 | _◃◃[_]_ : ∀ {ℓ0 ℓ1 ℓ2 ℓ3 κ0 κ1 κ2 κ3} 246 | → {p : Poly ℓ0 κ0} {q : Poly ℓ2 κ2} → p ⇆ q 247 | → {r : Poly ℓ1 κ1} (s : Poly ℓ3 κ3) → r ⇆ s 248 | → (p ◃ r) ⇆ (q ◃ s) 249 | (f , f♯) ◃◃[ s ] (g , g♯) = 250 | ((λ (a , γ) → (f a , λ b' → g (γ (f♯ a b')))) 251 | , λ (a , γ) (b' , d') → ((f♯ a b') , g♯ (γ (f♯ a b')) d')) 252 | 253 | ``` 254 | 255 | where `◃Lens` is the action of `◃` on lenses. 256 | 257 | By construction, the existence of a Cartesian lens `(σ , σ♯) : 𝔲 ◃ 𝔲 ⇆ 𝔲` effectively shows that `𝔲` is closed under `Σ`-types, since: 258 | 259 | * `σ` maps a pair (A , B) consisting of `A : 𝓤` and `B : (u A) → 𝓤` to a term `σ(A,B)` representing the `Σ` type. This corresponds to the type formation rule $$ \inferrule{\Gamma \vdash A : \mathsf{Type}\\ \Gamma, x : A \vdash B[x] ~ \mathsf{Type}}{\Gamma \vdash \Sigma x : A . B[x] ~ \mathsf{Type}} $$ 260 | * For all `(A , B)` as above, `σ♯ (A , B)` takes a term of type `σ (A , B)` and yields a term `fst (σ♯ (A , B)) : A` along with a term `snd (σ♯ (A , B)) : B (fst (σ♯ (A , B)))`, corresponding to the elimination rules $$ 261 | \inferrule{\Gamma \vdash p : \Sigma x : A . B[x]}{\Gamma \vdash \pi_1(p) : A} \quad \inferrule{\Gamma \vdash p : \Sigma x : A . B[x]}{\Gamma \vdash \pi_2(p) : B[\pi_1(p)]} $$ 262 | * The fact that `σ♯ (A , B)` has is an equivalence implies it has an inverse `σ♯⁻¹ (A , B) : Σ (u A) (λ x → u (B x)) → u (σ (A , B))`, which takes a pair of terms to a term of the corresponding pair type, and thus corresponds to the introduction rule $$ \inferrule{\Gamma \vdash a : A\\ \Gamma \vdash b : B[a]}{\Gamma \vdash (a , b) : \Sigma x : A . B[x]} $$ 263 | * The fact that $σ♯⁻¹ (A , B)$ is both a left and a right inverse to $σ♯$ then implies the usual $β$ and $η$ laws for dependent pair types $$ \pi_1(a , b) = a \quad \pi_2(a , b) = b \quad p = (\pi_1(p) , \pi_2(p)) $$ 264 | 265 | Similarly, the existence of a Cartesian lens $(η , η♯) : 𝕪 ⇆ 𝔲$ implies that $𝔲$ contains (a type equivalent to) the unit type, in that: 266 | 267 | * There is an element `η tt : 𝓤` which represents the unit type. This corresponds to the type formation rule $$ \inferrule{~}{\Gamma \vdash \top : \mathsf{Type}}$$ 268 | * The "elimination rule" `η♯ tt : u(η tt) → ⊤`, applied to an element `x : u(η tt)` is trivial, in that it simply discards `x`. This corresponds to the fact that, in the ordinary type-theoretic presentation, $\top$ does not have an elimination rule. 269 | * However, since this trivial elimination rule has an inverse `η♯⁻¹ tt : ⊤ → u (η tt)`, it follows that there is a (unique) element `η♯⁻¹ tt tt : u (η tt)`, which corresponds to the introduction rule for $\top$: $$\inferrule{~}{\Gamma \vdash \mathsf{tt} : \top}$$ 270 | * Moreover, the uniqueness of this element corresponds to the $\eta$-law for $\top$: $$\frac{\Gamma \vdash x : \top}{\Gamma \vdash x = \mathsf{tt}}$$ 271 | 272 | But then, what sorts of laws can we expect Cartesian lenses as above to obey, and is the existence of such a lens all that is needed to ensure that the natural model $𝔲$ has dependent pair types in the original sense of Awodey & Newstead's definition in terms of Cartesian (pseudo)monads, or is some further data required? And what about `Π` types, or other type formers? To answer these questions, we will need to study the structure of `◃`, along with some closely related functors, in a bit more detail. In particular, we shall see that the structure of `◃` as a monoidal product on $\mathbf{Poly}$ reflects many of the basic identities one expects to hold of `Σ` types. 273 | 274 | For instance, the associativity of `◃` corresponds to the associativity of `Σ`-types. 275 | 276 | ```agda 277 | module ◃Assoc {ℓ0 ℓ1 ℓ2 κ0 κ1 κ2} (p : Poly ℓ0 κ0) 278 | (q : Poly ℓ1 κ1) (r : Poly ℓ2 κ2) where 279 | 280 | ◃assoc : ((p ◃ q) ◃ r) ⇆ (p ◃ (q ◃ r)) 281 | ◃assoc = ( (λ ((a , γ) , δ) 282 | → (a , (λ b → (γ b , λ d → δ (b , d))))) 283 | , (λ _ (b , (d , x)) → ((b , d) , x)) ) 284 | 285 | ◃assoc⁻¹ : (p ◃ (q ◃ r)) ⇆ ((p ◃ q) ◃ r) 286 | ◃assoc⁻¹ = ( (λ (a , γ) → ( (a , (λ x → fst (γ x))) 287 | , (λ (x , y) → snd (γ x) y) )) 288 | , λ _ ((x , y) , z) → (x , (y , z)) ) 289 | 290 | open ◃Assoc public 291 | ``` 292 | 293 | while the left and right unitors of `◃` correspond to the fact that `⊤` is both a left and a right unit for `Σ`-types. 294 | 295 | ```agda 296 | module ◃LRUnit {ℓ κ} (p : Poly ℓ κ) where 297 | 298 | ◃unitl : (𝕪 ◃ p) ⇆ p 299 | ◃unitl = ( (λ (_ , a) → a tt) , λ (_ , a) x → (tt , x) ) 300 | 301 | ◃unitl⁻¹ : p ⇆ (𝕪 ◃ p) 302 | ◃unitl⁻¹ = ( (λ a → (tt , λ _ → a)) , (λ a (_ , b) → b ) ) 303 | 304 | ◃unitr : (p ◃ 𝕪) ⇆ p 305 | ◃unitr = ( (λ (a , γ) → a) , (λ (a , γ) b → (b , tt)) ) 306 | 307 | ◃unitr⁻¹ : p ⇆ (p ◃ 𝕪) 308 | ◃unitr⁻¹ = ( (λ a → a , (λ _ → tt)) , (λ a (b , _) → b) ) 309 | 310 | open ◃LRUnit public 311 | ``` 312 | 313 | n fact, `◃` restricts to a monoidal product on $\mathbf{Poly^{Cart}}$, since the functorial action of `◃` on lenses preserves Cartesian lenses, 314 | 315 | ```agda 316 | ◃◃Cart : ∀ {ℓ0 ℓ1 ℓ2 ℓ3 κ0 κ1 κ2 κ3} 317 | → {p : Poly ℓ0 κ0} (q : Poly ℓ2 κ2) {f : p ⇆ q} 318 | → {r : Poly ℓ1 κ1} (s : Poly ℓ3 κ3) {g : r ⇆ s} 319 | → isCartesian q f → isCartesian s g 320 | → isCartesian (q ◃ s) (f ◃◃[ s ] g) 321 | ◃◃Cart q {f = (f , f♯)} s {g = (g , g♯)} cf cg (a , γ) = 322 | pairEquiv (f♯ a) (λ x → g♯ (γ (f♯ a x))) 323 | (cf a) (λ x → cg (γ (f♯ a x))) 324 | ``` 325 | 326 | and all of the above-defined structure morphisms for `◃` are Cartesian. 327 | 328 | ```agda 329 | module ◃AssocCart {ℓ0 ℓ1 ℓ2 κ0 κ1 κ2} (p : Poly ℓ0 κ0) 330 | (q : Poly ℓ1 κ1) (r : Poly ℓ2 κ2) where 331 | 332 | ◃assocCart : isCartesian (p ◃ (q ◃ r)) (◃assoc p q r) 333 | ◃assocCart _ = 334 | Iso→isEquiv (snd (◃assoc⁻¹ p q r) _ , ((λ _ → refl) , (λ _ → refl))) 335 | 336 | ◃assoc⁻¹Cart : isCartesian ((p ◃ q) ◃ r) (◃assoc⁻¹ p q r) 337 | ◃assoc⁻¹Cart _ = 338 | Iso→isEquiv (snd (◃assoc p q r) _ , ((λ _ → refl) , (λ _ → refl))) 339 | 340 | open ◃AssocCart public 341 | 342 | module ◃LRUnitCart {ℓ κ} (p : Poly ℓ κ) where 343 | 344 | ◃unitlCart : isCartesian p (◃unitl p) 345 | ◃unitlCart _ = Iso→isEquiv (snd (◃unitl⁻¹ p) _ , ((λ _ → refl) , (λ _ → refl))) 346 | 347 | ◃unitl⁻¹Cart : isCartesian (𝕪 ◃ p) (◃unitl⁻¹ p) 348 | ◃unitl⁻¹Cart _ = Iso→isEquiv (snd (◃unitl p) _ , ((λ _ → refl) , (λ _ → refl))) 349 | 350 | ◃unitrCart : isCartesian p (◃unitr p) 351 | ◃unitrCart _ = Iso→isEquiv (snd (◃unitr⁻¹ p) _ , ((λ _ → refl) , (λ _ → refl))) 352 | 353 | ◃unitr⁻¹Cart : isCartesian (p ◃ 𝕪) (◃unitr⁻¹ p) 354 | ◃unitr⁻¹Cart _ = Iso→isEquiv (snd (◃unitr p) _ , ((λ _ → refl) , (λ _ → refl))) 355 | 356 | open ◃LRUnitCart public 357 | ``` 358 | 359 | We should expect, then, for these equivalences to be somehow reflected in the structure of a Cartesian lenses `η : 𝕪 ⇆ 𝔲` and `μ : 𝔲 ◃ 𝔲 ⇆ 𝔲`. This would be the case, e.g., if the following diagrams in $\mathbf{Poly^{Cart}}$ were to commute $$ 360 | \begin{tikzcd} 361 | {y \triangleleft \mathfrak{u}} & {\mathfrak{u} \triangleleft \mathfrak{u} } & {\mathfrak{u} \triangleleft y} \\ 362 | & {\mathfrak{u}} 363 | \arrow["{\eta \triangleleft \mathfrak{u}}", from=1-1, to=1-2] 364 | \arrow["{\mathsf{\triangleleft unitl}}"{description}, from=1-1, to=2-2] 365 | \arrow["\mu", from=1-2, to=2-2] 366 | \arrow["{\mathfrak{u} \triangleleft \eta}"', from=1-3, to=1-2] 367 | \arrow["{\mathsf{\triangleleft unitr}}"{description}, from=1-3, to=2-2] 368 | \end{tikzcd} \qquad \begin{tikzcd} 369 | {(\mathfrak{u} \triangleleft \mathfrak{u}) \triangleleft \mathfrak{u}} & {\mathfrak{u} \triangleleft (\mathfrak{u} \triangleleft \mathfrak{u})} & {\mathfrak{u} \triangleleft \mathfrak{u}} \\ 370 | {\mathfrak{u} \triangleleft \mathfrak{u}} && {\mathfrak{u}} 371 | \arrow["{\mathsf{\triangleleft assoc}}", from=1-1, to=1-2] 372 | \arrow["{\mu \triangleleft \mathfrak{u}}"', from=1-1, to=2-1] 373 | \arrow["{\mathfrak{u} \triangleleft \mu}", from=1-2, to=1-3] 374 | \arrow["\mu", from=1-3, to=2-3] 375 | \arrow["\mu"', from=2-1, to=2-3] 376 | \end{tikzcd} 377 | $$ 378 | 379 | One may recognize these as the usual diagrams for a monoid in a monoidal category, hence (since `◃` corresponds to composition of polynomial endofunctors) for a *monad* as typically defined. However, because of the higher-categorical structure of types in HoTT, we should not only ask for these diagrams to commute, but for the cells exhibiting that these diagrams commute to themselves be subject to higher coherences, and so on, giving `𝔲` not the structure of a (Cartesian) monad, but rather of a (Cartesian) *$\infty$-monad*. 380 | 381 | Yet demonstrating that $𝔲$ is an $\infty$-monad involves specifying a potentially infinite amount of coherence data. Have we therefore traded both the Scylla of equality-up-to-isomorphism and the Charybdis of strictness for an even worse fate of higher coherence hell? The answer to this question, surprisingly, is negative, as there is a way to implicitly derive all of this data from a single axiom, which corresponds to the characteristic axiom of HoTT itself: univalence. To show this, we now introduce the central concept of this paper – that of a *polynomial universe*. -------------------------------------------------------------------------------- /part4.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/part4.agdai -------------------------------------------------------------------------------- /part4v2.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/part4v2.agdai -------------------------------------------------------------------------------- /part4v2.lagda.md: -------------------------------------------------------------------------------- 1 | ```agda 2 | {-# OPTIONS --without-K --rewriting --lossy-unification #-} 3 | module part4v2 where 4 | 5 | open import part1v2 6 | open import Agda.Primitive 7 | open import Agda.Builtin.Sigma 8 | open import Agda.Builtin.Unit 9 | open import Agda.Builtin.Equality 10 | open import Agda.Builtin.Equality.Rewrite 11 | open import part2v2 12 | open import appendixA 13 | open import part3v2 14 | ``` 15 | 16 | # Polynomial Universes 17 | 18 | ## Univalence 19 | 20 | For any polynomial `𝔲 = (𝓤 , El)`, we say that `𝔲` is *univalent* if `𝔲` is a *subterminal object* in $\mathbf{Poly^{Cart}}$, i.e. for any other polynomial `p`, the type of Cartesian lenses `p ⇆ 𝔲` is a proposition, i.e. any two Cartesian lenses with codomain `𝔲` are equal. 21 | 22 | ```agda 23 | isUnivalent : ∀ {ℓ κ} → Poly ℓ κ → Setω 24 | isUnivalent u = 25 | ∀ {ℓ' κ'} {p : Poly ℓ' κ'} 26 | → {f g : p ⇆ u} 27 | → isCartesian u f 28 | → isCartesian u g 29 | → EqLens u f g 30 | 31 | ``` 32 | 33 | We call this property of polynomials univalence in analogy with the usual univalence axiom of HoTT. Indeed, the univalence axiom can be equivalently stated as the fact that the polynomial functor `(Type , λ X → X)` is itself univalent. 34 | 35 | ```agda 36 | postulate 37 | ua : ∀ {ℓ} → isUnivalent (Type ℓ , λ X → X) 38 | ``` 39 | 40 | We shall refer to univalent polynomial functors as *polynomial universes.* f we think of a polynomial `p` as representing a family of types, then what this tells us is that if `𝔲` is a polynomial universe, there is essentially at most one way for `𝔲` to contain the types represented by `p`, where Containment is here understood as existence of a Cartesian lens `p ⇆ 𝔲`. In this case, we say that `𝔲` *classifies* the types represented by `p`. 41 | 42 | As a direct consequence of this fact, it follows that every diagram consisting of parallel Cartesian lenses into a polynomial universe automatically commutes, and moreover, every higher diagram that can be formed between the cells exhibiting such commutation must also commute, etc. 43 | 44 | Hence the fact that `𝔲` must satisfy the laws of a monad if there are Cartesian lenses `η : 𝕪 ⇆ 𝔲` and `μ : 𝔲 ◃ 𝔲 ⇆ 𝔲` follows immediately from the above theorem and the closure of Cartesian lenses under composition: 45 | 46 | ```agda 47 | module UnivMonad {ℓ κ} (𝔲 : Poly ℓ κ) (univ : isUnivalent 𝔲) 48 | (η : 𝕪 ⇆ 𝔲) (μ : (𝔲 ◃ 𝔲) ⇆ 𝔲) 49 | (cη : isCartesian 𝔲 η) (cμ : isCartesian 𝔲 μ) where 50 | 51 | univ◃unitl : EqLens 𝔲 (◃unitl 𝔲) (comp 𝔲 (η ◃◃[ 𝔲 ] (id 𝔲)) μ) 52 | univ◃unitl = univ (◃unitlCart 𝔲) 53 | (compCartesian 𝔲 (◃◃Cart 𝔲 𝔲 cη (idCart 𝔲)) cμ) 54 | 55 | univ◃unitr : EqLens 𝔲 (◃unitr 𝔲) (comp 𝔲 ((id 𝔲) ◃◃[ 𝔲 ] η) μ) 56 | univ◃unitr = univ (◃unitrCart 𝔲) 57 | (compCartesian 𝔲 (◃◃Cart 𝔲 𝔲 (idCart 𝔲) cη) cμ) 58 | 59 | 60 | univ◃assoc : EqLens 𝔲 (comp 𝔲 (μ ◃◃[ 𝔲 ] (id 𝔲)) μ) 61 | (comp 𝔲 (◃assoc 𝔲 𝔲 𝔲) 62 | (comp 𝔲 ((id 𝔲) ◃◃[ 𝔲 ] μ) μ)) 63 | univ◃assoc = univ (compCartesian 𝔲 (◃◃Cart 𝔲 𝔲 cμ (idCart 𝔲)) cμ) 64 | (compCartesian 𝔲 (◃assocCart 𝔲 𝔲 𝔲) 65 | (compCartesian 𝔲 (◃◃Cart 𝔲 𝔲 (idCart 𝔲) cμ) cμ)) 66 | 67 | open UnivMonad public 68 | ``` 69 | 70 | And more generally, all the higher coherences of an $\infty$-monad would follow -- if we bothered to write them out -- from the contractibility of the types of Cartesian lenses `p ⇆ 𝔲` that can be formed using `μ` and `η`. 71 | 72 | ### Examples of Polynomial Universes 73 | 74 | We have so far seen that polynomial universes are quite special objects in the theory of polynomial functors in HoTT, but what good would such special objects do us if they turned out to be exceedingly rare or difficult to construct? 75 | 76 | In fact, polynomial universes are surprisingly plentiful in univalent type theory. We have already seen how the univalence axiom implies that `(Type , λ X → X)` is a polynomial universe. From this single example, a plethora of others can be seen to follow, many of which encompass familiar constructs from programming and mathematics. 77 | 78 | In a sense, the polynomial `(Type , λ X → X)` is *universal* among polynomials in $\mathbf{Poly}^{\mathbf{Cart}}$ in that, for any polynomial `p`, there is a (necessarily unique, by univalence) Cartesian morphism `p ⇆ (Type , λ X → X)`. Or rather, there would be, were it not for the size issues preventing `(Type , λ X → X)` from being a single object. Instead, it can more accurately be said that the family of polynomials `(Type ℓ , λ X → X)` for all `ℓ : Level` is universal among polynomials in $\mathbf{Poly}^{\mathbf{Cart}}$ – this can be shown straightforwardly as follows: 79 | 80 | ```agda 81 | module PolyCartUniv {ℓ κ} (p : Poly ℓ κ) where 82 | 83 | classifier : p ⇆ (Type κ , λ X → X) 84 | classifier = (snd p , λ _ b → b) 85 | 86 | classifierCart : isCartesian (Type κ , λ X → X) classifier 87 | classifierCart _ = idIsEquiv 88 | ``` 89 | 90 | In other words, every polynomial functor `p` is classified by some polynomial universe. Moreover, if the classifying morphism `p ⇆ (Type κ , λ X → X)` is a Vertical embedding (i.e. a monomorphism in $\mathbf{Poly}^{\mathbf{Cart}}$), then `p` itself is also a polynomial universe – for any pair of Cartesian morphisms `f g : q ⇆ p`, since `(Type κ , λ X → X)` is univalent, we have `classifier ∘ f ≡ classifier ∘ g`, but then since `classifier` is assumed to be a monomorphism, this implies that `f ≡ g`. 91 | 92 | ```agda 93 | polyCartUniv : isVerticalEmbedding (Type κ , λ X → X) classifier → isUnivalent p 94 | polyCartUniv veclassifier cf cg = 95 | VertEmbedding→PolyCartMono 96 | (Type κ , λ X → X) 97 | classifierCart 98 | veclassifier 99 | cf cg 100 | (ua (compCartesian _ cf classifierCart) 101 | (compCartesian _ cg classifierCart)) 102 | 103 | open PolyCartUniv public 104 | ``` 105 | 106 | It follows that, for any type family `P : Type → Type`, we can create a polynomial *sub-universe* of `(Type , λ X → X)` by restricting to those types `X` for which there *merely* exists an inhabitant of `P X`. 107 | 108 | ```agda 109 | module SubUniv {ℓ κ} (P : Type ℓ → Type κ) where 110 | 111 | subUniv : Poly (lsuc ℓ) ℓ 112 | subUniv = (Σ (Type ℓ) (λ X → ∥ P X ∥) , λ (X , _) → X) 113 | 114 | subUnivClassifierIsVerticalEmbedding : 115 | isVerticalEmbedding (Type ℓ , λ X → X) (classifier subUniv) 116 | subUnivClassifierIsVerticalEmbedding = 117 | Iso→isEquiv ( (λ e → pairEq e ∥-∥IsProp) 118 | , ( (λ e → (pairEq (ap (fst (classifier subUniv)) e) ∥-∥IsProp) 119 | ≡〈 ap (λ e' → pairEq (ap (fst (classifier subUniv)) e) e') ∥-∥≡Contr 〉 120 | ( _ 121 | ≡〈 (pairEqη e) 〉 122 | (e □))) 123 | , (λ e → pairEqβ1 e ∥-∥IsProp) ) ) 124 | 125 | subUnivIsUniv : isUnivalent subUniv 126 | subUnivIsUniv = polyCartUniv subUniv subUnivClassifierIsVerticalEmbedding 127 | 128 | open SubUniv public 129 | ``` 130 | 131 | As a first example of a polynomial universe other than `(Type , λ X → X)`, then, we may consider the polynomial universe of *propositions* `ℙ`: 132 | 133 | ```agda 134 | module PropUniv where 135 | 136 | ℙ : Poly (lsuc lzero) lzero 137 | ℙ = subUniv isProp 138 | ``` 139 | 140 | If we write out explicitly the polynomial endofunctor defined by `ℙ` we see that it has the following form: $$ 141 | y \mapsto \sum_{\phi : \mathbf{Prop}} y^\phi 142 | $$ This endofunctor (in fact it is a monad) is well-known in type theory by another name – the *partiality* monad. Specifically, this is the monad `M` whose kleisli morphisms `A → M B` correspond to *partial functions* from `A` to `B`, that associate to each element `a : A`, a proposition `def f a` indicating whether or not the value of `f` is defined at `a`, and a function `val : def f a → B` that takes a proof that `f` is defined at `a` to its value at `a`. 143 | 144 | If we return to the original example of the polynomial universe `(Type , λ X → X)` we see that the associated polynomial endofunctor (which, by the above argument, is also a monad) has a similar form. $$ 145 | y \mapsto \sum_{X : \mathbf{Type}} y^X 146 | $$ In this case, we can think of this as a "proof relevant" partiality monad `M`, such that a function `f : A → M B` associates to each element `a : A` a *type* `Def f a` of proofs that `f` is defined at `a`, and a function `val : Def f a → B`.[^1] 147 | 148 | [^1]: the conception of the monad determined by `(Type , λ X → X)` as a "proof relevant" partiality monad was communicated to the first author during private conversations with Jonathan Sterling. 149 | 150 | More generally, we can say that, for any polynomial universe closed under dependent pair types, the associated monad will be a kind of (potentially proof-relevant) partiality monad, where the structure of the polynomial universe serves to dictate which types can count as *evidence* for whether or not a value is defined. 151 | 152 | #### Rezk Completion 153 | 154 | In fact, we can show that for *any* polynomial functor, there exists a corresponding polynomial universe, using a familiar construct from the theory of categories in HoTT – the *Rezk Completion.* We will show that this construction allows us to quotient any polynomial functor to a corresponding polynomial universe. 155 | 156 | We obtain the Rezk completion of `p` as the image factorization in $\mathbf{Poly^{Cart}}$ of the classifying morphism of `p`: 157 | 158 | ```agda 159 | module RezkCompletion {ℓ κ} (p : Poly ℓ κ) where 160 | 161 | Rezk : Poly (lsuc κ) κ 162 | Rezk = cartIm (Type κ , λ X → X) (classifier p) (classifierCart p) 163 | 164 | →Rezk : p ⇆ Rezk 165 | →Rezk = factorcart1 (Type κ , λ X → X) (classifier p) (classifierCart p) 166 | 167 | Rezk→ : Rezk ⇆ (Type κ , λ X → X) 168 | Rezk→ = factorcart2 (Type κ , λ X → X) (classifier p) (classifierCart p) 169 | ``` 170 | 171 | The polynomial `Rezk` defined above can be seen to have the same form as a subuniverse of `(Type , λ X → X)`; hence it is a polynomial universe, as desired. 172 | 173 | ```agda 174 | RezkUniv : isUnivalent Rezk 175 | RezkUniv = subUnivIsUniv (λ X → Σ (fst p) (λ a → (snd p a) ≡ X)) 176 | 177 | open RezkCompletion public 178 | ``` 179 | 180 | As an example of how the Rezk completion allows us to "upgrade" a polynomial functor (a polynomial monad, even) into a polynomial universe, consider the following definition of the finite ordinals as a family of types indexed by the type `Nat` of natural numbers: 181 | 182 | ```agda 183 | module FinUniv where 184 | open import Agda.Builtin.Nat 185 | ``` 186 | 187 | We first define the standard ordering on natural numbers: 188 | 189 | ```agda 190 | data _≺_ : Nat → Nat → Type lzero where 191 | zero< : {n : Nat} → zero ≺ suc n 192 | succ< : {n m : Nat} → n ≺ m → (suc n) ≺ (suc m) 193 | ``` 194 | 195 | We then define the `n`th finite ordinal as the subtype of `Nat` consisting of all numbers `m` strictly less than `n`: 196 | 197 | ```agda 198 | Fin : Nat → Type lzero 199 | Fin n = Σ Nat (λ m → m ≺ n) 200 | ``` 201 | 202 | From these data, we can straightforwardly define a polynomial as follows 203 | 204 | ```agda 205 | ω : Poly lzero lzero 206 | ω = (Nat , Fin) 207 | ``` 208 | 209 | If we once again write out the polynomial endofunctor determined by these data $$ 210 | y \mapsto \sum_{n \in \mathbb{N}} y^{\{m \in \mathbb{N} \mid m < n\}} 211 | $$ we see that this functor has a familiar form – it is the *list monad* that maps a type $y$ to the disjoint union of the types of $n$-tuples of elements of $y$, for all $n \in \mathbb{N}$. 212 | 213 | As defined, $\omega$ is not a polynomial universe; the type `Nat` is a set, and so for any `n : Nat`, the type `n ≡ n` is contractible, i.e. it has a single inhabitant, while the type of equivalences `Fin n ≃ Fin n` consists of all permutations of `n` elements, so these two types cannot be equivalent. However, we can now use the Rezk completion to obtain a polynomial universe from `ω`. 214 | 215 | ```agda 216 | 𝔽in : Poly (lsuc lzero) lzero 217 | 𝔽in = Rezk ω 218 | ``` 219 | 220 | If we write out an explicit description of `𝔽in`, we see that it is the subuniverse of types `X` that are merely equivalent to some `Fin n`. In constructive mathematics, these types (they are necessarily sets) are known as *Bishop finite sets*. Hence the polynomial universe obtained by Rezk completion of the list monad is precisely the subuniverse of types spanned by (Bishop) finite sets. -------------------------------------------------------------------------------- /part5v2.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/part5v2.agdai -------------------------------------------------------------------------------- /part6v2.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/part6v2.agdai -------------------------------------------------------------------------------- /part6v2.lagda.md: -------------------------------------------------------------------------------- 1 | ```agda 2 | {-# OPTIONS --without-K --rewriting #-} 3 | module part6v2 where 4 | 5 | open import part1v2 6 | open import Agda.Primitive 7 | open import Agda.Builtin.Sigma 8 | open import Agda.Builtin.Unit 9 | open import Agda.Builtin.Equality 10 | open import Agda.Builtin.Equality.Rewrite 11 | open import part2v2 12 | open import appendixA 13 | open import part3v2 14 | open import Agda.Builtin.Nat 15 | open import part4v2 16 | open import part5v2 17 | ``` 18 | 19 | # Further Structures on Polynomial Universes 20 | 21 | In closing, we turn to briefly consider whether and how some additional type-theoretic constructs may be defined for natural models / polynomial universes in the language of polynomial functors, starting with the concept of a universe itself. 22 | 23 | ## The Shift Operator & Universes 24 | 25 | Throughout this paper, we have made extensive use of universes of types. A natural question to ask, then, is when the type theory presented by a polynomial universe itself contains another such universe as a type within itself. 26 | 27 | For this purpose, let `𝔳 , 𝔲` be polynomial universes with `𝔳 = (𝓥 , El𝓥)` and `𝔲 = (𝓤 , El)`. If there is a (necessarily unique) Cartesian morphism `𝔳 ⇆ 𝔲`, then it follows that every type family classified by `𝔳` is also classified by `𝔲`, by composition of Cartesian morphisms. However, what we want in this case is the stronger property that `𝔳` is somehow represented as a type within `𝔲`. 28 | 29 | For this purpose, we define the following *shift* functor $\poly^{op} \to \poly$ that takes a polynomial `p = (A , B)` to the polynomial `shift p = (⊤ , λ _ → A)`n`: 30 | 31 | ```agda 32 | shift : ∀ {ℓ κ} → Poly ℓ κ → Poly lzero ℓ 33 | shift (A , _) = (⊤ , λ _ → A) 34 | 35 | shiftFunctor : ∀ {ℓ0 κ0 ℓ1 κ1} {p : Poly ℓ0 κ0} {q : Poly ℓ1 κ1} 36 | → p ⇆ q → shift q ⇆ shift p 37 | shiftFunctor (f , _) = ( (λ _ → tt) , (λ _ → f) ) 38 | ``` 39 | 40 | By construction, then, if there is a Cartesian morphism `(v , v♯) : shift (𝓥 , El𝓥) ⇆ (𝓤 , El𝓤)`, it follows that: 41 | 42 | * There is a type `v tt : 𝓤`; type theoretically, this corresponds to a type formation rule of the form $$ 43 | \inferrule{~}{\Gamma \vdash \mathcal{V} ~ \mathsf{Type}} 44 | $$ We think of `𝓥` as a type whose elements are "codes" for other types. 45 | * There is a function `v♯ tt : El𝓤 (v tt) → 𝓥`, corresponding to the rule $$ 46 | \inferrule{\Gamma \vdash e : 𝓥}{\Gamma \vdash \lceil e \rceil ~ \mathsf{Type}} 47 | $$ which decodes a code contained in `𝓥` to its corresponding type. 48 | * There is a function `v♯⁻¹ tt : 𝓥 → El𝓤 (v tt)`, corresponding to the rule $$ 49 | \inferrule{\Gamma \vdash T ~ \mathsf{Type}\\ T ~ \text{is classifed by} ~ \mathfrak{v}}{\Gamma \vdash \lfloor T \rfloor : \mathcal{V}} 50 | $$ that assigns a code to each type classified by `𝔳` (note that this restriction to types classified by `𝔳` is necessary to avoid the paradoxes that would arise from having a type universe that contained itself.) 51 | * Such that the following equations hold $$ 52 | \lceil \lfloor T \rfloor \rceil = T \qquad e = \lfloor \lceil e \rceil \rfloor 53 | $$ 54 | 55 | \footnote{Following Gratzer et al., we refer to a universe defined in this way as a universe *a la Coquand.*} 56 | 57 | ## The $(-)^=$ Operator & Extensional Identity Types 58 | 59 | Another key construct of dependent type theory which has figured prominently in the foregoing development of polynomial universes, but which we have not yet shown how to internalize in such universes, is the construction of *identity types*. To some extent, this choice has been deliberate, as the theory of identity types is arguably one of the most complex aspects of dependent type theory, as evidenced by the fact that research into this topic ultimately precipitated the development of homotopy type theory. For this very reason, however, an account of the semantics of dependent type theory without at least some indication of its application to the theory of identity types would be incomplete. 60 | 61 | Readers familiar with dependent type theory may be aware that an initial complication posed by the theory of identity types is that these types come in two flavors: extensional and intensional. Extensional identity types reflect propositional equality (i.e. the existence of an inhabitant for the type `a ≡ b`) into judgmental equality (i.e. the metatheoretic proposition that `a = b`) and additionally regard all such proofs of identity as themselves identical. It follows that these identity types carry none of the homotopical information afforded by the alternative – intensional identity types, which are the sort which we have so far used in this paper. However, when working within such a homotopical framework, wherein metatheoretic equality need not be a mere proposition, there exists the possibility of defining extensional identity types in a polynomial universe so as to enable the aforementioned reflection while still allowing proofs of identity to carry higher-dimensional data. 62 | 63 | For this purpose, let `p = (A , B)` be some polynomial classified by a polynomial universe `𝔲 = (𝓤 , El)`, i.e. there exists a Cartesian morphism `p ⇆ 𝔲`. We wish to establish under what conditions `𝔲` would also contain "identity types" for `p` allowing a reflection-rule as above. Solving this problem in essentially the same manner as led to the definiiton of the `⇈` functor in the previous section yields the following construction, that maps `p = (A , B)` to the polynomial `p⁼ = (Σ A (λ a → B a × B a) , λ (_ , (b1 , b2)) → b1 ≡ b2)`. 64 | 65 | ```agda 66 | _⁼ : ∀ {ℓ κ} → Poly ℓ κ → Poly (ℓ ⊔ κ) κ 67 | (A , B)⁼ = (Σ A (λ a → B a × B a) , λ (_ , (b1 , b2)) → b1 ≡ b2) 68 | ``` 69 | 70 | If there is a Cartesian morphism `(ε , ε♯) : (A , B)⁼ ⇆ (𝓤 , El)` then: 71 | 72 | * For each type represented by some `a : A` with elements `b1 , b2 : B a`, there is a type `Eq(b1 , b2) : 𝓤`. Type theoretically, this corresponds to the type formation rule $$ 73 | \inferrule{\Gamma \vdash T ~ \mathsf{Type}\\ \Gamma \vdash t_1 : T\\ \Gamma \vdash t_2 : T}{\Gamma \vdash t_1 \equiv_A t_2 ~ \mathsf{Type}} 74 | $$ 75 | * For each `a : A` and `b1 , b2 : B a` as above, there is a function `El (Eq(b1 , b2)) → b1 ≡ b2` corresponding to the *reflection rule* $$ 76 | \inferrule{\Gamma \vdash e : a_0 \equiv_A a_1}{\Gamma \vdash a_0 = a_1} 77 | $$ that converts an inhabitant of the propositional equality into the corresponding judgmental equality. 78 | * ... 79 | * Such that the above two rules are mutually inverse. 80 | 81 | What is missing from the above description of extensional identity types is the following rule $$ 82 | \inferrule{\Gamma \vdash e_1 : a \equiv_A b\\ \Gamma \vdash e_2 : a \equiv_A b}{\Gamma \vdash e_1 = e_2} 83 | $$ which says that all inhabitants of the identity type are themselves identical (i.e. the identity type is a *mere proposition*). This rule would be validated if we additionally required `𝔲` to have the property that, for all types `A : 𝓤`, the type `El A` is a set (hence for any `a b : El A`, the type `a ≡ b` is a mere proposition.) However, if we do not make this requirement, this opens the possibility of having a model of extensional type theory, modulo the above rule, wherein proofs of equality still carry homotopical information – a potentially new direction in research on the semantics of identity types. 84 | 85 | ### A Note on Intensional Identity Types & Inductive Types 86 | 87 | Attempting to account for *intensional* rather than *extensional* identity types in the language of polynomial functors is rather more complicated, however. As mentioned in Section 2, the inhabitants of intensional identity types are inductively generated from the constructor `refl`, corresponding to reflexivity. The problem with such inductive generation of data from constructors -- from the point of view taken in this paper -- is that it characterizes types in terms of their introduction forms, rather than their elimination forms. In type theoretic jargon, we say that intensional identity types, and inductive types more generally are *positive,* whereas all of the types we have considered so far are *negative,* in that they are characterized by their elimination forms. The universal properties of such negative types are therefore *mapping-in* properties, which are naturally described in terms of presheaves, which we have taken as our intended model for the development of this paper. By contrast, however, the universal properties of positive types are given by *mapping-out* properties, which are rather described in terms of (the opposite category of) *co-presheaves.* 88 | 89 | As an illustrative example, let us consider the rather simpler case of (binary) coproducts, which are naturally regarded as positive types characterized by the left and right injections `A → A + B` and `B → A + B`. one might think to define binary coproducts on a polynomial universe `𝔲` in the following way: 90 | 91 | The *product* of two polynomial functors $p = \sum_{a : A} y^{B[a]}$ and $q = \sum_{c : C} y^{D[c]}$ can be calculated as follows: $$ 92 | \begin{array}{rl} & \left( \sum_{a : A} y^{B[a]} \right) \times \left( \sum_{c : C} y^{D[c]} \right)\\ 93 | \simeq & \sum_{(a , c) : A \times C} y^{B[a]} \times y^{D[c]}\\ 94 | \simeq & \sum_{(a , c) : A \times C} y^{B[a] + D[c]} 95 | \end{array} 96 | $$ Hence one might think to define binary coproducts on a polynomial universe `𝔲 = (𝓤 , El)` by asking there to be a Cartesian morphism `𝔲 × 𝔲 ⇆ 𝔲`, since this would mean that for every pair of types `(A , B) : 𝓤 × 𝓤`, there is a type `plus(A , B) : 𝓤` such that `El(plus(A , B)) ≃ El A + El B`. 97 | 98 | However, from the perspective of natural models, this condition is too strong. Given a category of contexts $\mathcal{C}$, the category $\widehat{\mathcal{C}}$ of presheaves on $\mathcal{C}$ is the free cocompletion of $\mathcal{C}$, which means that requiring $\mathcal{C}$ to be closed under taking binary coproducts in $\widehat{\mathcal{C}}$ means not only that $\mathcal{C}$ has all binary coproducts, but that in fact all such coproducts in $\mathcal{C}$ are *free.* 99 | 100 | Hence it remains to be seen if there can be found a general way of correctly expressing such "positive" type-theoretic concepts as for polynomial universes and natural models in the language of polynomial functors. We hope to continue investigations into these and related questions in future work. 101 | 102 | ## Conclusion 103 | 104 | In this paper, we have advanced a simplified and unified account of the categorical semantics of dependent type theory by expressing the core concepts of natural models entirely within the framework of polynomial functors in HoTT. By utilizing HoTT, we have been able strike an ideal balance between issues of strictness and higher-dimensional coherence that have bedeviled previous accounts. This shift not only streamlines the presentation of the semantics of dependent type theory, but also reveals additional structures thereof, such as the self-distributive law governing the interaction between dependent products and sums. 105 | 106 | However, there remain many open questions regarding the further development of this framework, particularly with respect to *positive* type-theoretic constructs such as coproducts, inductive types, and intensional identity types. Further work is needed to explore whether polynomial functors can provide a fully general account of these concepts. We look forward to continuing these investigations, with the aim of extending the unification presented here to encompass a wider range of type-theoretic phenomena. -------------------------------------------------------------------------------- /poly-dependent-types.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/poly-dependent-types.pdf -------------------------------------------------------------------------------- /poly-universes.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/poly-universes.agdai -------------------------------------------------------------------------------- /poly-universes.bbl.bbl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/poly-universes.bbl.bbl -------------------------------------------------------------------------------- /poly-universes.bbl.blg: -------------------------------------------------------------------------------- 1 | [0] Config.pm:307> INFO - This is Biber 2.19 2 | [0] Config.pm:310> INFO - Logfile is 'poly-universes.bbl.blg' 3 | [37] biber-darwin:340> INFO - === Fri Sep 27, 2024, 22:41:26 4 | [127] Utils.pm:410> ERROR - Cannot find 'poly-universes.bbl.bcf'! 5 | [128] Biber.pm:136> INFO - ERRORS: 1 6 | -------------------------------------------------------------------------------- /quiver.sty: -------------------------------------------------------------------------------- 1 | % *** quiver *** 2 | % A package for drawing commutative diagrams exported from https://q.uiver.app. 3 | % 4 | % This package is currently a wrapper around the `tikz-cd` package, importing necessary TikZ 5 | % libraries, and defining a new TikZ style for curves of a fixed height. 6 | % 7 | % Version: 1.5.2 8 | % Authors: 9 | % - varkor (https://github.com/varkor) 10 | % - AndréC (https://tex.stackexchange.com/users/138900/andr%C3%A9c) 11 | 12 | \NeedsTeXFormat{LaTeX2e} 13 | \ProvidesPackage{quiver}[2021/01/11 quiver] 14 | 15 | % `tikz-cd` is necessary to draw commutative diagrams. 16 | \RequirePackage{tikz-cd} 17 | % `amssymb` is necessary for `\lrcorner` and `\ulcorner`. 18 | \RequirePackage{amssymb} 19 | % `calc` is necessary to draw curved arrows. 20 | \usetikzlibrary{calc} 21 | % `pathmorphing` is necessary to draw squiggly arrows. 22 | \usetikzlibrary{decorations.pathmorphing} 23 | 24 | % A TikZ style for curved arrows of a fixed height, due to AndréC. 25 | \tikzset{curve/.style={settings={#1},to path={(\tikztostart) 26 | .. controls ($(\tikztostart)!\pv{pos}!(\tikztotarget)!\pv{height}!270:(\tikztotarget)$) 27 | and ($(\tikztostart)!1-\pv{pos}!(\tikztotarget)!\pv{height}!270:(\tikztotarget)$) 28 | .. (\tikztotarget)\tikztonodes}}, 29 | settings/.code={\tikzset{quiver/.cd,#1} 30 | \def\pv##1{\pgfkeysvalueof{/tikz/quiver/##1}}}, 31 | quiver/.cd,pos/.initial=0.35,height/.initial=0} 32 | 33 | % TikZ arrowhead/tail styles. 34 | \tikzset{tail reversed/.code={\pgfsetarrowsstart{tikzcd to}}} 35 | \tikzset{2tail/.code={\pgfsetarrowsstart{Implies[reversed]}}} 36 | \tikzset{2tail reversed/.code={\pgfsetarrowsstart{Implies}}} 37 | % TikZ arrow styles. 38 | \tikzset{no body/.style={/tikz/dash pattern=on 0 off 1mm}} 39 | 40 | \endinput -------------------------------------------------------------------------------- /sketching.agda: -------------------------------------------------------------------------------- 1 | {-# OPTIONS --without-K --rewriting #-} 2 | module sketching where 3 | 4 | open import Agda.Primitive 5 | open import Agda.Builtin.Equality 6 | open import Agda.Builtin.Equality.Rewrite 7 | open import Agda.Builtin.Sigma 8 | open import Agda.Builtin.Unit 9 | 10 | Type : (ℓ : Level) → Set (lsuc ℓ) 11 | Type ℓ = Set ℓ 12 | 13 | _×_ : ∀ {ℓ κ} (A : Type ℓ) (B : Type κ) → Type (ℓ ⊔ κ) 14 | A × B = Σ A (λ _ → B) 15 | 16 | _□ : ∀ {ℓ} {A : Type ℓ} (a : A) → a ≡ a 17 | a □ = refl 18 | 19 | _≡〈_〉_ : ∀ {ℓ} {A : Type ℓ} (a : A) {b c : A} 20 | → a ≡ b → b ≡ c → a ≡ c 21 | a ≡〈 refl 〉 refl = refl 22 | 23 | sym : ∀ {ℓ} {A : Type ℓ} {a a' : A} 24 | → a ≡ a' → a' ≡ a 25 | sym refl = refl 26 | 27 | ap : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {a a' : A} 28 | → (f : A → B) → a ≡ a' → (f a) ≡ (f a') 29 | ap f refl = refl 30 | 31 | coAp : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f g : A → B} 32 | → f ≡ g → (x : A) → f x ≡ g x 33 | coAp refl x = refl 34 | 35 | transp : ∀ {ℓ κ} {A : Type ℓ} (B : A → Type κ) 36 | → {a a' : A} (e : a ≡ a') (b : B a) 37 | → B a' 38 | transp B refl b = b 39 | 40 | syml : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {a b : A} 41 | → (e : a ≡ b) (x : B a) → transp B (sym e) (transp B e x) ≡ x 42 | syml refl x = refl 43 | 44 | syml' : ∀ {ℓ κ} {A : Type ℓ} (B : A → Type κ) {a b : A} 45 | → (e : a ≡ b) {x : B a} → transp B (sym e) (transp B e x) ≡ x 46 | syml' B refl = refl 47 | 48 | symr : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {a b : A} 49 | → (e : a ≡ b) (y : B b) → transp B e (transp B (sym e) y) ≡ y 50 | symr refl x = refl 51 | 52 | J : ∀ {ℓ κ} {A : Type ℓ} {a : A} (B : (a' : A) → a' ≡ a → Set κ) 53 | → {a' : A} → (e : a' ≡ a) → B a refl → B a' e 54 | J B refl b = b 55 | 56 | pairEq : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {a a' : A} {b : B a} {b' : B a'} 57 | → (e : a ≡ a') → transp B e b ≡ b' → (a , b) ≡ (a' , b') 58 | pairEq refl refl = refl 59 | 60 | isContr : ∀ {ℓ} → Type ℓ → Type ℓ 61 | isContr A = Σ A (λ a → (b : A) → a ≡ b) 62 | 63 | singletonIsContr : ∀ {ℓ} {A : Type ℓ} (a : A) 64 | → isContr (Σ A (λ b → b ≡ a)) 65 | singletonIsContr a = (a , refl) , λ {(b , refl) → refl} 66 | 67 | singletonIsContr2 : ∀ {ℓ} {A : Type ℓ} (a : A) 68 | → (b : A) (e : a ≡ b) 69 | → _≡_ {ℓ} {Σ A (λ x → a ≡ x)} (b , e) (a , refl) 70 | singletonIsContr2 a b refl = refl 71 | 72 | isProp : ∀ {ℓ} → Type ℓ → Type ℓ 73 | isProp A = (a b : A) → a ≡ b 74 | 75 | isSet : ∀ {ℓ} → Type ℓ → Type ℓ 76 | isSet A = (a b : A) → isProp (a ≡ b) 77 | 78 | isGrpd : ∀ {ℓ} → Type ℓ → Type ℓ 79 | isGrpd A = (a b : A) → isSet (a ≡ b) 80 | 81 | isEquiv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} 82 | → (A → B) → Set (ℓ ⊔ κ) 83 | isEquiv {A = A} {B = B} f = (b : B) → isContr (Σ A (λ a → f a ≡ b)) 84 | 85 | inv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 86 | → isEquiv f → B → A 87 | inv e b = fst (fst (e b)) 88 | 89 | pairEq1 : ∀ {ℓ κ} {A : Type ℓ} {B : A → Type κ} {a a' : A} {b : B a} 90 | → (e : a ≡ a') → (a , b) ≡ (a' , transp B e b) 91 | pairEq1 refl = refl 92 | 93 | isIso : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} 94 | → (A → B) → Type (ℓ ⊔ κ) 95 | isIso {A = A} {B = B} f = 96 | Σ (B → A) (λ g → 97 | ((x : A) → g (f x) ≡ x) 98 | × ((y : B) → f (g y) ≡ y)) 99 | 100 | {- isIso→isEquiv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 101 | → isIso f → isEquiv f 102 | isIso→isEquiv {f = f} (g , l , r) b = 103 | (g b , r b) 104 | , λ {(a , refl) → 105 | ((g (f a) , r (f a))) 106 | ≡〈 pairEq1 (l a) 〉 {! !}} -} 107 | 108 | idIsEquiv : ∀ {ℓ} {A : Type ℓ} → isEquiv {A = A} (λ x → x) 109 | idIsEquiv a = (a , refl) , λ {(a' , refl) → refl} 110 | 111 | {- compIsEquiv : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} 112 | → (g : B → C) (f : A → B) 113 | → isEquiv g → isEquiv f 114 | → isEquiv (λ x → g (f x)) 115 | compIsEquiv g f eg ef c = 116 | (inv ef (inv eg c) 117 | , (g (f (inv ef (inv eg c))) 118 | ≡〈 ap g (snd (fst (ef (inv eg c)))) 〉 119 | (g (inv eg c) 120 | ≡〈 snd (fst (eg c)) 〉 121 | (c □)))) 122 | , λ {(a , refl) → 123 | {! !}} -} 124 | 125 | isHalfAdj : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} 126 | → (A → B) → Type (ℓ ⊔ κ) 127 | isHalfAdj {A = A} {B = B} f = 128 | Σ (B → A) (λ g → 129 | Σ ((x : A) → g (f x) ≡ x) (λ l → 130 | Σ ((y : B) → f (g y) ≡ y) (λ r → 131 | (a : A) → transp (λ a' → f a' ≡ f a) (l a) (r (f a)) ≡ refl))) 132 | 133 | idIsHalfAdj : ∀ {ℓ} {A : Type ℓ} → isHalfAdj {A = A} (λ x → x) 134 | idIsHalfAdj = (λ x → x) , ((λ x → refl) , (λ y → refl) , (λ a → refl)) 135 | 136 | {- compIsHalfAdj : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} 137 | → {g : B → C} {f : A → B} → isHalfAdj g → isHalfAdj f 138 | → isHalfAdj (λ x → g (f x)) 139 | compIsHalfAdj {g = g} {f = f} (g' , lg , rg , eg) (f' , lf , rf , ef) = 140 | (λ c → f' (g' c)) 141 | , ((λ x → 142 | f' (g' (g (f x))) 143 | ≡〈 ap f' (lg (f x)) 〉 144 | ((f' (f x)) 145 | ≡〈 lf x 〉 146 | (x □))) 147 | , (λ y → 148 | g (f (f' (g' y))) 149 | ≡〈 ap g (rf (g' y)) 〉 150 | (g (g' y) 151 | ≡〈 rg y 〉 152 | (y □))) 153 | , λ a → 154 | {! !}) -} 155 | 156 | isBiInv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} 157 | → (A → B) → Type (ℓ ⊔ κ) 158 | isBiInv {A = A} {B = B} f = 159 | (Σ (B → A) (λ g → (a : A) → g (f a) ≡ a)) 160 | × (Σ (B → A) (λ g → (b : B) → f (g b) ≡ b)) 161 | 162 | mkInv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 163 | → isBiInv f → B → A 164 | mkInv (_ , (h , _)) = h 165 | 166 | idIsBiInv : ∀ {ℓ} {A : Type ℓ} → isBiInv {A = A} (λ x → x) 167 | idIsBiInv = ((λ x → x) , (λ x → refl)) , ((λ x → x) , (λ x → refl)) 168 | 169 | compIsBiInv : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} 170 | → (g : B → C) (f : A → B) → isBiInv g → isBiInv f 171 | → isBiInv (λ a → g (f a)) 172 | compIsBiInv g f ((g' , lg) , (g'' , rg)) ((f' , lf) , (f'' , rf)) = 173 | ( (λ c → f' (g' c)) 174 | , λ a → (f' (g' (g (f a)))) ≡〈 ap f' (lg (f a)) 〉 175 | (f' (f a) ≡〈 lf a 〉 176 | (a □))) 177 | , ((λ c → f'' (g'' c)) 178 | , λ c → (g (f (f'' (g'' c)))) ≡〈 ap g (rf (g'' c)) 〉 179 | (g (g'' c) ≡〈 rg c 〉 180 | (c □))) 181 | 182 | isIso→isBiInv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 183 | → isIso f → isBiInv f 184 | isIso→isBiInv (g , l , r) = ((g , l) , (g , r)) 185 | 186 | isBiInv→isIso : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 187 | → isBiInv f → isIso f 188 | isBiInv→isIso {f = f} ((g , l) , (h , r)) = 189 | h , (λ x → 190 | (h (f x)) ≡〈 sym (l (h (f x))) 〉 191 | (g (f (h (f x))) ≡〈 ap g (r (f x)) 〉 192 | ((g (f x)) ≡〈 l x 〉 193 | (x □)))) 194 | , r 195 | 196 | isoInv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 197 | → (isof : isIso f) → isIso (fst isof) 198 | isoInv {f = f} (g , l , r) = (f , r , l) 199 | 200 | invIsBiInv : ∀ {ℓ κ} {A : Type ℓ} {B : Type κ} {f : A → B} 201 | → (ef : isBiInv f) → isBiInv (mkInv ef) 202 | invIsBiInv ef = isIso→isBiInv (isoInv (isBiInv→isIso ef)) 203 | 204 | Poly : (ℓ κ : Level) → Type ((lsuc ℓ) ⊔ (lsuc κ)) 205 | Poly ℓ κ = Σ (Set ℓ) (λ A → A → Set κ) 206 | 207 | _⇆_ : ∀ {ℓ ℓ' κ κ'} → Poly ℓ κ → Poly ℓ' κ' → Type (ℓ ⊔ ℓ' ⊔ κ ⊔ κ') 208 | (A , B) ⇆ (C , D) = 209 | Σ (A → C) 210 | (λ f → (a : A) → D (f a) → B a) 211 | 212 | _∼_ : ∀ {ℓ ℓ' κ κ'} {p : Poly ℓ κ} {q : Poly ℓ' κ'} 213 | → (p ⇆ q) → (p ⇆ q) → Set (ℓ ⊔ ℓ' ⊔ κ ⊔ κ') 214 | _∼_ {p = (A , B)} {q = (C , D)} (f , g) (f' , g') = 215 | (a : A) → Σ (f a ≡ f' a) (λ e → (b : D (f a)) → g a b ≡ g' a (transp D e b)) 216 | 217 | id : ∀ {ℓ κ} {A : Type ℓ} (B : A → Type κ) → (A , B) ⇆ (A , B) 218 | id B = ( (λ a → a) 219 | , λ a b → b) 220 | 221 | comp : ∀ {ℓ ℓ' ℓ'' κ κ' κ''} 222 | → (p : Poly ℓ κ) (q : Poly ℓ' κ') (r : Poly ℓ'' κ'') 223 | → p ⇆ q → q ⇆ r → p ⇆ r 224 | comp p q r (f , g) (h , k) = 225 | ( (λ a → h (f a)) 226 | , λ a z → g a (k (f a) z)) 227 | 228 | compAssoc : ∀ {ℓ ℓ' ℓ'' ℓ''' κ κ' κ'' κ'''} 229 | → {p : Poly ℓ κ} {q : Poly ℓ' κ'} {r : Poly ℓ'' κ''} {s : Poly ℓ''' κ'''} 230 | → (f : p ⇆ q) (g : q ⇆ r) (h : r ⇆ s) 231 | → comp p q s f (comp q r s g h) ≡ comp p r s (comp p q r f g) h 232 | compAssoc f g h = refl 233 | 234 | idToEquiv : ∀ {ℓ κ} (p : Poly ℓ κ) (a b : fst p) 235 | → a ≡ b → Σ (snd p a → snd p b) isBiInv 236 | idToEquiv p a b e = 237 | transp (snd p) e 238 | , isIso→isBiInv (transp (snd p) (sym e) , (syml e , symr e)) 239 | 240 | isUnivalent : ∀ {ℓ κ} → Poly ℓ κ → Type (ℓ ⊔ κ) 241 | isUnivalent (A , B) = 242 | (a b : A) → isBiInv (idToEquiv (A , B) a b) 243 | 244 | transpLemma : ∀ {ℓ κ} {u : Poly ℓ κ} 245 | → (univ : isUnivalent u) → {a b : fst u} (f : snd u a → snd u b) 246 | → (ef : isBiInv f) (x : snd u a) 247 | → transp (snd u) (mkInv (univ a b) (f , ef)) x ≡ f x 248 | transpLemma {u = u} univ {a = a} {b = b} f ef x = coAp (ap fst (snd (snd (univ a b)) ((f , ef)))) x 249 | 250 | isVertical : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 251 | → p ⇆ q → Set (ℓ ⊔ ℓ') 252 | isVertical p q (f , g) = isBiInv f 253 | 254 | isCartesian : ∀ {ℓ ℓ' κ κ'} (p : Poly ℓ κ) (q : Poly ℓ' κ') 255 | → p ⇆ q → Set (ℓ ⊔ κ ⊔ κ') 256 | isCartesian (A , B) q (f , g) = (a : A) → isBiInv (g a) 257 | 258 | compCartesian : ∀ {ℓ ℓ' ℓ'' κ κ' κ''} 259 | → {p : Poly ℓ κ} {q : Poly ℓ' κ'} {r : Poly ℓ'' κ''} 260 | → (f : p ⇆ q) (g : q ⇆ r) 261 | → isCartesian p q f → isCartesian q r g 262 | → isCartesian p r (comp p q r f g) 263 | compCartesian f g cf cg a = 264 | compIsBiInv (snd f a) (snd g (fst f a)) (cf a) (cg (fst f a)) 265 | 266 | univ→Thin : ∀ {ℓ ℓ' κ κ'} {p : Poly ℓ κ} {u : Poly ℓ' κ'} 267 | → isUnivalent u → (f g : p ⇆ u) 268 | → isCartesian p u f → isCartesian p u g → (a : fst p) 269 | → Σ (fst f a ≡ fst g a) 270 | (λ e → (b : snd u (fst f a)) → 271 | snd f a b ≡ snd g a (transp (λ x → snd u x) e b)) 272 | univ→Thin {u = u} univ f g cf cg a = 273 | mkInv (univ (fst f a) (fst g a)) 274 | ( (λ x → mkInv (cg a) (snd f a x)) 275 | , compIsBiInv (λ x → mkInv (cg a) x) 276 | (snd f a) 277 | (invIsBiInv (cg a)) 278 | (cf a)) 279 | , λ b → sym (snd g a 280 | (transp (snd u) 281 | (fst (snd (univ (fst f a) 282 | (fst g a))) 283 | ((λ x → mkInv (cg a) 284 | (snd f a x)) 285 | , compIsBiInv (λ x → mkInv (cg a) x) 286 | (snd f a) 287 | (invIsBiInv (cg a)) 288 | (cf a))) 289 | b) ≡〈 ap (snd g a) 290 | (transpLemma univ 291 | (λ x → mkInv (cg a) (snd f a x)) 292 | (compIsBiInv (λ x → mkInv (cg a) x) 293 | (snd f a) 294 | (invIsBiInv (cg a)) 295 | (cf a)) 296 | b) 〉 297 | ((snd g a 298 | (mkInv (cg a) 299 | (snd f a b))) ≡〈 snd (snd (cg a)) (snd f a b) 〉 300 | (snd f a b □))) 301 | 302 | 303 | 𝐲 : Poly lzero lzero 304 | 𝐲 = ⊤ , λ _ → ⊤ 305 | 306 | _◃_ : ∀ {ℓ ℓ' κ κ'} → Poly ℓ κ → Poly ℓ' κ' → Poly (ℓ ⊔ κ ⊔ ℓ') (κ ⊔ κ') 307 | (A , B) ◃ (C , D) = (Σ A (λ a → B a → C) , λ (a , f) → Σ (B a) (λ b → D (f b))) 308 | 309 | _◃◃_ : ∀ {ℓ ℓ' ℓ'' ℓ''' κ κ' κ'' κ'''} 310 | → {p : Poly ℓ κ} {p' : Poly ℓ' κ'} {q : Poly ℓ'' κ''} {q' : Poly ℓ''' κ'''} 311 | → p ⇆ p' → q ⇆ q' → (p ◃ q) ⇆ (p' ◃ q') 312 | (f , g) ◃◃ (h , k) = 313 | ((λ (a , c) → (f a , λ b' → h (c (g a b')))) 314 | , λ (a , c) (b' , d') → ((g a b') , k (c (g a b')) d')) 315 | 316 | ◃assoc : ∀ {ℓ ℓ' ℓ'' κ κ' κ''} 317 | → {p : Poly ℓ κ} {q : Poly ℓ' κ'} {r : Poly ℓ'' κ''} 318 | → ((p ◃ q) ◃ r) ⇆ (p ◃ (q ◃ r)) 319 | ◃assoc = 320 | ((λ ((a , f) , g) → (a , (λ b → (f b , λ d → g (b , d))))) 321 | , λ ((a , f) , g) (b , (d , x)) → ((b , d) , x)) 322 | 323 | ◃assocVert : ∀ {ℓ ℓ' ℓ'' κ κ' κ''} 324 | → {p : Poly ℓ κ} {q : Poly ℓ' κ'} {r : Poly ℓ'' κ''} 325 | → isVertical ((p ◃ q) ◃ r) 326 | (p ◃ (q ◃ r)) 327 | (◃assoc {p = p} {q = q} {r = r}) 328 | ◃assocVert = 329 | isIso→isBiInv ( (λ (a , f) → 330 | (a , λ b → fst (f b)) 331 | , (λ (b , d) → snd (f b) d)) 332 | , ( (λ (a , f) → refl) 333 | , λ (a , f) → refl)) 334 | 335 | ◃assocCart : ∀ {ℓ ℓ' ℓ'' κ κ' κ''} 336 | → {p : Poly ℓ κ} {q : Poly ℓ' κ'} {r : Poly ℓ'' κ''} 337 | → isCartesian ((p ◃ q) ◃ r) 338 | (p ◃ (q ◃ r)) 339 | (◃assoc {p = p} {q = q} {r = r}) 340 | ◃assocCart = 341 | λ (a , f) → 342 | isIso→isBiInv ( (λ ((b , d) , x) → b , d , x) 343 | , ( (λ (b , d , x) → refl) 344 | , λ ((b , d) , x) → refl)) 345 | 346 | EqJump1 : ∀ {ℓ ℓ' ℓ'' κ κ' κ''} 347 | → (p : Poly ℓ κ) (q : Poly ℓ' κ') (r : Poly ℓ'' κ'') 348 | → (f g : p ⇆ (q ◃ r)) 349 | → Type (ℓ ⊔ ℓ' ⊔ ℓ'' ⊔ κ ⊔ κ' ⊔ κ'') 350 | EqJump1 (A , B) (C , D) (X , Y) (f , f') (g , g') = 351 | (a : A) → Σ (fst (f a) ≡ fst (g a)) 352 | λ e → Σ ( (d : D (fst (f a))) 353 | → snd (f a) d ≡ snd (g a) (transp D e d)) 354 | λ e' → (d : D (fst (f a))) (y : Y (snd (f a) d)) 355 | → (f' a (d , y) ≡ g' a (transp D e d , transp Y (e' d) y)) 356 | 357 | Jump : ∀ {ℓ ℓ' ℓ'' ℓ''' κ κ' κ'' κ'''} 358 | → (p : Poly ℓ κ) (q : Poly ℓ' κ') (r : Poly ℓ'' κ'') (s : Poly ℓ''' κ''') 359 | → (f : p ⇆ q) → (g : (p ◃ r) ⇆ (s ◃ q)) → Type (ℓ ⊔ ℓ' ⊔ ℓ'' ⊔ κ ⊔ κ' ⊔ κ''') 360 | Jump (A , B) (C , D) (A' , B') (C' , D') (f , f') (g , g') = 361 | Σ ((x : Σ A (λ a → B a → A')) → (y : D' (fst (g x))) → f (fst x) ≡ snd (g x) y) 362 | λ e → (x : Σ A (λ a → B a → A')) 363 | → (y : D' (fst (g x))) 364 | → (z : D (f (fst x))) 365 | → fst (g' x (y , transp D (e x y) z)) ≡ f' (fst x) z 366 | 367 | _⇈[_][_]_ : ∀ {ℓ ℓ' ℓ'' κ κ' κ''} 368 | → (p : Poly ℓ κ) (r : Poly ℓ'' κ'') (f : p ⇆ r) 369 | → (q : Poly ℓ' κ') → Poly (ℓ ⊔ κ ⊔ ℓ') (κ' ⊔ κ'') 370 | _⇈[_][_]_ (A , B) (X , Y) (f , g) (C , D) = 371 | ( Σ A (λ a → B a → C)) 372 | , λ (a , γ) → (y : Y (f a)) → D (γ (g a y)) 373 | 374 | Jump→⇈ : ∀ {ℓ ℓ' ℓ'' ℓ''' κ κ' κ'' κ'''} 375 | → (p : Poly ℓ κ) (q : Poly ℓ' κ') (r : Poly ℓ'' κ'') (s : Poly ℓ''' κ''') 376 | → (f : p ⇆ q) (g : (p ◃ r) ⇆ (s ◃ q)) 377 | → Jump p q r s f g → (p ⇈[ q ][ f ] r) ⇆ s 378 | Jump→⇈ p q r s (f , f') (g , g') (e , e') = 379 | ( λ x → fst (g x)) 380 | , λ x y z → transp (snd r) (ap (snd x) (e' x y z)) 381 | (snd (g' x (y , transp (snd q) (e x y) z))) 382 | 383 | ⇈→Jump1 : ∀ {ℓ ℓ' ℓ'' ℓ''' κ κ' κ'' κ'''} 384 | → (p : Poly ℓ κ) (q : Poly ℓ'' κ'') (f : p ⇆ q) 385 | → (r : Poly ℓ' κ') (s : Poly ℓ''' κ''') 386 | → ((p ⇈[ q ][ f ] r) ⇆ s) → ((p ◃ r) ⇆ (s ◃ q)) 387 | ⇈→Jump1 p q (f , f') r s (g , g') = 388 | (λ (a , γ) → g (a , γ) , λ b → f a) 389 | , λ (a , γ) (x , y) → f' a y , g' ((a , γ)) x y 390 | 391 | ⇈→Jump2 : ∀ {ℓ ℓ' ℓ'' ℓ''' κ κ' κ'' κ'''} 392 | → (p : Poly ℓ κ) (q : Poly ℓ'' κ'') (f : p ⇆ q) 393 | → (r : Poly ℓ' κ') (s : Poly ℓ''' κ''') 394 | → (g : (p ⇈[ q ][ f ] r) ⇆ s) 395 | → Jump p q r s f (⇈→Jump1 p q f r s g) 396 | ⇈→Jump2 p q f r s g = (λ x y → refl) , (λ x y z → refl) 397 | 398 | ⇈→JumpLeftInv : ∀ {ℓ ℓ' ℓ'' ℓ''' κ κ' κ'' κ'''} 399 | → (p : Poly ℓ κ) (q : Poly ℓ'' κ'') (f : p ⇆ q) 400 | → (r : Poly ℓ' κ') (s : Poly ℓ''' κ''') 401 | → (g : (p ⇈[ q ][ f ] r) ⇆ s) 402 | → Jump→⇈ p q r s f (⇈→Jump1 p q f r s g) 403 | (⇈→Jump2 p q f r s g) 404 | ≡ g 405 | ⇈→JumpLeftInv p q f r s g = refl 406 | 407 | apSymLemma : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : B → Type ℓ''} {f : A → B} 408 | → {a a' : A} (e : a ≡ a') {c : C (f a)} 409 | → transp (λ b → C (f b)) (sym e) 410 | (transp C (ap f e) c) 411 | ≡ c 412 | apSymLemma refl = refl 413 | 414 | ⇈→JumpRightInv1 : ∀ {ℓ ℓ' ℓ'' ℓ''' κ κ' κ'' κ'''} 415 | → (p : Poly ℓ κ) (q : Poly ℓ'' κ'') 416 | → (r : Poly ℓ' κ') (s : Poly ℓ''' κ''') (f : p ⇆ q) 417 | → (g : (p ◃ r) ⇆ (s ◃ q)) (j : Jump p q r s f g) 418 | → EqJump1 (p ◃ r) s q 419 | (⇈→Jump1 p q f r s (Jump→⇈ p q r s f g j)) 420 | g 421 | ⇈→JumpRightInv1 p q r s f (g , g') (e , e') a = 422 | refl , ( (λ d → e a d) 423 | , λ d y → pairEq (sym (e' a d y)) 424 | (apSymLemma (e' a d y))) -------------------------------------------------------------------------------- /sketching.agdai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dspivak/dependent-types/409c88ad0c7b400e0b0a1e9c1ef22ee818fdc038/sketching.agdai --------------------------------------------------------------------------------