a1b2419ca7bc50da5bb4739d1f0d54e704a1d8a5
[bitonic-mengthesis.git] / presentation.tex
1 \documentclass{beamer}
2 \usepackage[sc,slantedGreek]{mathpazo}
3
4
5 % Comment these out if you don't want a slide with just the
6 % part/section/subsection/subsubsection title:
7 \AtBeginPart{\frame{\partpage}}
8 \AtBeginSection{\frame{\sectionpage}}
9 \AtBeginSubsection{\frame{\subsectionpage}}
10 \AtBeginSubsubsection{\frame{\subsubsectionpage}}
11 \beamertemplatenavigationsymbolsempty
12
13 \usepackage{centernot}
14 \usepackage{cancel}
15
16 \setlength{\parindent}{0pt}
17 \setlength{\parskip}{6pt plus 2pt minus 1pt}
18 \setlength{\emergencystretch}{3em}  % prevent overfull lines
19 \setcounter{secnumdepth}{0}
20
21 \usepackage[english]{babel}
22 \usepackage[conor]{agda}
23 \renewcommand{\AgdaKeywordFontStyle}[1]{\ensuremath{\mathrm{\underline{#1}}}}
24 \renewcommand{\AgdaFunction}[1]{\textbf{\textcolor{AgdaFunction}{#1}}}
25 \renewcommand{\AgdaField}{\AgdaFunction}
26 % \definecolor{AgdaBound} {HTML}{000000}
27 \definecolor{AgdaHole} {HTML} {FFFF33}
28
29 \DeclareUnicodeCharacter{9665}{\ensuremath{\lhd}}
30 \DeclareUnicodeCharacter{964}{\ensuremath{\tau}}
31 \DeclareUnicodeCharacter{963}{\ensuremath{\sigma}}
32 \DeclareUnicodeCharacter{915}{\ensuremath{\Gamma}}
33 \DeclareUnicodeCharacter{8799}{\ensuremath{\stackrel{?}{=}}}
34 \DeclareUnicodeCharacter{9655}{\ensuremath{\rhd}}
35
36 \newcommand{\mysmall}{}
37 \newcommand{\mysyn}{\AgdaKeyword}
38 \newcommand{\mytyc}[1]{\textup{\AgdaDatatype{#1}}}
39 \newcommand{\mydc}[1]{\textup{\AgdaInductiveConstructor{#1}}}
40 \newcommand{\myfld}[1]{\textup{\AgdaField{#1}}}
41 \newcommand{\myfun}[1]{\textup{\AgdaFunction{#1}}}
42 \newcommand{\myb}[1]{\AgdaBound{$#1$}}
43 \newcommand{\myfield}{\AgdaField}
44 \newcommand{\myind}{\AgdaIndent}
45 \newcommand{\mykant}{{\rmfamily\scshape Bertus}}
46 \newcommand{\mysynel}[1]{#1}
47 \newcommand{\myse}{\mysynel}
48 \newcommand{\mytmsyn}{\langle t \rangle}
49 \newcommand{\mysp}{\ }
50 \newcommand{\myabs}[2]{\mydc{$\lambda$} #1 \mathrel{\mydc{$\mapsto$}} #2}
51 \newcommand{\myappsp}{\hspace{0.07cm}}
52 \newcommand{\myapp}[2]{#1 \myappsp #2}
53 \newcommand{\mysynsep}{\ \ |\ \ }
54 \newcommand{\myITE}[3]{\myfun{If}\, #1\, \myfun{Then}\, #2\, \myfun{Else}\, #3}
55 \newcommand{\mycumul}{\preceq}
56
57 \newcommand{\mydesc}[3]{
58   \noindent
59   \mbox{
60     \parbox{\textwidth}{
61       {\mysmall
62         \vspace{0.2cm}
63         \hfill \textup{\phantom{ygp}\textbf{#1}} $#2$
64         \framebox[\textwidth]{
65           \parbox{\textwidth}{
66             \vspace{0.1cm}
67             \centering{
68               #3
69             }
70             \vspace{0.2cm}
71           }
72         }
73         \vspace{0.2cm}
74       }
75     }
76   }
77 }
78
79 \newcommand{\mytmt}{\mysynel{t}}
80 \newcommand{\mytmm}{\mysynel{m}}
81 \newcommand{\mytmn}{\mysynel{n}}
82 \newcommand{\myred}{\leadsto}
83 \newcommand{\myredd}{\stackrel{*}{\leadsto}}
84 \newcommand{\myreddd}{\stackrel{*}{\reflectbox{$\leadsto$}}}
85 \newcommand{\mysub}[3]{#1[#3 / #2]}
86 \newcommand{\mytysyn}{\langle ty \rangle}
87 \newcommand{\mybasetys}{K}
88 \newcommand{\mybasety}[1]{B_{#1}}
89 \newcommand{\mytya}{\myse{A}}
90 \newcommand{\mytyb}{\myse{B}}
91 \newcommand{\mytycc}{\myse{C}}
92 \newcommand{\myarr}{\mathrel{\textcolor{AgdaDatatype}{\to}}}
93 \newcommand{\myprod}{\mathrel{\textcolor{AgdaDatatype}{\times}}}
94 \newcommand{\myctx}{\Gamma}
95 \newcommand{\myvalid}[1]{#1 \vdash \underline{\mathrm{valid}}}
96 \newcommand{\myjudd}[3]{#1 \vdash #2 : #3}
97 \newcommand{\myjud}[2]{\myjudd{\myctx}{#1}{#2}}
98 \newcommand{\myabss}[3]{\mydc{$\lambda$} #1 {:} #2 \mathrel{\mydc{$\mapsto$}} #3}
99 \newcommand{\mytt}{\mydc{$\langle\rangle$}}
100 \newcommand{\myunit}{\mytyc{Unit}}
101 \newcommand{\mypair}[2]{\mathopen{\mydc{$\langle$}}#1\mathpunct{\mydc{,}} #2\mathclose{\mydc{$\rangle$}}}
102 \newcommand{\myfst}{\myfld{fst}}
103 \newcommand{\mysnd}{\myfld{snd}}
104 \newcommand{\myconst}{\myse{c}}
105 \newcommand{\myemptyctx}{\varepsilon}
106 \newcommand{\myhole}{\AgdaHole}
107 \newcommand{\myfix}[3]{\mysyn{fix} \myappsp #1 {:} #2 \mapsto #3}
108 \newcommand{\mysum}{\mathbin{\textcolor{AgdaDatatype}{+}}}
109 \newcommand{\myleft}[1]{\mydc{left}_{#1}}
110 \newcommand{\myright}[1]{\mydc{right}_{#1}}
111 \newcommand{\myempty}{\mytyc{Empty}}
112 \newcommand{\mycase}[2]{\mathopen{\myfun{[}}#1\mathpunct{\myfun{,}} #2 \mathclose{\myfun{]}}}
113 \newcommand{\myabsurd}[1]{\myfun{absurd}_{#1}}
114 \newcommand{\myarg}{\_}
115 \newcommand{\myderivsp}{}
116 \newcommand{\myderivspp}{\vspace{0.3cm}}
117 \newcommand{\mytyp}{\mytyc{Type}}
118 \newcommand{\myneg}{\myfun{$\neg$}}
119 \newcommand{\myar}{\,}
120 \newcommand{\mybool}{\mytyc{Bool}}
121 \newcommand{\mytrue}{\mydc{true}}
122 \newcommand{\myfalse}{\mydc{false}}
123 \newcommand{\myitee}[5]{\myfun{if}\,#1 / {#2.#3}\,\myfun{then}\,#4\,\myfun{else}\,#5}
124 \newcommand{\mynat}{\mytyc{$\mathbb{N}$}}
125 \newcommand{\myrat}{\mytyc{$\mathbb{R}$}}
126 \newcommand{\myite}[3]{\myfun{if}\,#1\,\myfun{then}\,#2\,\myfun{else}\,#3}
127 \newcommand{\myfora}[3]{(#1 {:} #2) \myarr #3}
128 \newcommand{\myexi}[3]{(#1 {:} #2) \myprod #3}
129 \newcommand{\mypairr}[4]{\mathopen{\mydc{$\langle$}}#1\mathpunct{\mydc{,}} #4\mathclose{\mydc{$\rangle$}}_{#2{.}#3}}
130 \newcommand{\mynil}{\mydc{[]}}
131 \newcommand{\mycons}{\mathbin{\mydc{∷}}}
132 \newcommand{\myfoldr}{\myfun{foldr}}
133 \newcommand{\myw}[3]{\myapp{\myapp{\mytyc{W}}{(#1 {:} #2)}}{#3}}
134 \newcommand{\mynodee}{\mathbin{\mydc{$\lhd$}}}
135 \newcommand{\mynode}[2]{\mynodee_{#1.#2}}
136 \newcommand{\myrec}[4]{\myfun{rec}\,#1 / {#2.#3}\,\myfun{with}\,#4}
137 \newcommand{\mylub}{\sqcup}
138 \newcommand{\mydefeq}{\cong}
139 \newcommand{\myrefl}{\mydc{refl}}
140 \newcommand{\mypeq}{\mytyc{=}}
141 \newcommand{\myjeqq}{\myfun{$=$-elim}}
142 \newcommand{\myjeq}[3]{\myapp{\myapp{\myapp{\myjeqq}{#1}}{#2}}{#3}}
143 \newcommand{\mysubst}{\myfun{subst}}
144 \newcommand{\myprsyn}{\myse{prop}}
145 \newcommand{\myprdec}[1]{\mathopen{\mytyc{$\llbracket$}} #1 \mathclose{\mytyc{$\rrbracket$}}}
146 \newcommand{\myand}{\mathrel{\mytyc{$\wedge$}}}
147 \newcommand{\mybigand}{\mathrel{\mytyc{$\bigwedge$}}}
148 \newcommand{\myprfora}[3]{\forall #1 {:} #2.\, #3}
149 \newcommand{\myimpl}{\mathrel{\mytyc{$\Rightarrow$}}}
150 \newcommand{\mybot}{\mytyc{$\bot$}}
151 \newcommand{\mytop}{\mytyc{$\top$}}
152 \newcommand{\mycoe}{\myfun{coe}}
153 \newcommand{\mycoee}[4]{\myapp{\myapp{\myapp{\myapp{\mycoe}{#1}}{#2}}{#3}}{#4}}
154 \newcommand{\mycoh}{\myfun{coh}}
155 \newcommand{\mycohh}[4]{\myapp{\myapp{\myapp{\myapp{\mycoh}{#1}}{#2}}{#3}}{#4}}
156 \newcommand{\myjm}[4]{(#1 {:} #2) \mathrel{\mytyc{=}} (#3 {:} #4)}
157 \newcommand{\myeq}{\mathrel{\mytyc{=}}}
158 \newcommand{\myprop}{\mytyc{Prop}}
159 \newcommand{\mytmup}{\mytmsyn\uparrow}
160 \newcommand{\mydefs}{\Delta}
161 \newcommand{\mynf}{\Downarrow}
162 \newcommand{\myinff}[3]{#1 \vdash #2 \Uparrow #3}
163 \newcommand{\myinf}[2]{\myinff{\myctx}{#1}{#2}}
164 \newcommand{\mychkk}[3]{#1 \vdash #2 \Downarrow #3}
165 \newcommand{\mychk}[2]{\mychkk{\myctx}{#1}{#2}}
166 \newcommand{\myann}[2]{#1 : #2}
167 \newcommand{\mydeclsyn}{\myse{decl}}
168 \newcommand{\myval}[3]{#1 : #2 \mapsto #3}
169 \newcommand{\mypost}[2]{\mysyn{abstract}\ #1 : #2}
170 \newcommand{\myadt}[4]{\mysyn{data}\ #1 #2\ \mysyn{where}\ #3\{ #4 \}}
171 \newcommand{\myreco}[4]{\mysyn{record}\ #1 #2\ \mysyn{where}\ #3\{ #4 \}}
172 \newcommand{\myelabt}{\vdash}
173 \newcommand{\myelabf}{\rhd}
174 \newcommand{\myelab}[2]{\myctx \myelabt #1 \myelabf #2}
175 \newcommand{\mytele}{\Delta}
176 \newcommand{\mytelee}{\delta}
177 \newcommand{\mydcctx}{\Gamma}
178 \newcommand{\mynamesyn}{\myse{name}}
179 \newcommand{\myvec}{\overrightarrow}
180 \newcommand{\mymeta}{\textsc}
181 \newcommand{\myhyps}{\mymeta{hyps}}
182 \newcommand{\mycc}{;}
183 \newcommand{\myemptytele}{\varepsilon}
184 \newcommand{\mymetagoes}{\Longrightarrow}
185 % \newcommand{\mytesctx}{\
186 \newcommand{\mytelesyn}{\myse{telescope}}
187 \newcommand{\myrecs}{\mymeta{recs}}
188 \newcommand{\myle}{\mathrel{\lcfun{$\le$}}}
189 \newcommand{\mylet}{\mysyn{let}}
190 \newcommand{\myhead}{\mymeta{head}}
191 \newcommand{\mytake}{\mymeta{take}}
192 \newcommand{\myix}{\mymeta{ix}}
193 \newcommand{\myapply}{\mymeta{apply}}
194 \newcommand{\mydataty}{\mymeta{datatype}}
195 \newcommand{\myisreco}{\mymeta{record}}
196 \newcommand{\mydcsep}{\ |\ }
197 \newcommand{\mytree}{\mytyc{Tree}}
198 \newcommand{\myproj}[1]{\myfun{$\pi_{#1}$}}
199 \newcommand{\mysigma}{\mytyc{$\Sigma$}}
200 \newcommand{\mynegder}{\vspace{-0.3cm}}
201 \newcommand{\myquot}{\Uparrow}
202 \newcommand{\mynquot}{\, \Downarrow}
203 \newcommand{\mycanquot}{\ensuremath{\textsc{quote}{\Downarrow}}}
204 \newcommand{\myneuquot}{\ensuremath{\textsc{quote}{\Uparrow}}}
205 \newcommand{\mymetaguard}{\ |\ }
206 \newcommand{\mybox}{\Box}
207 \newcommand{\mytermi}[1]{\text{\texttt{#1}}}
208 \newcommand{\mysee}[1]{\langle\myse{#1}\rangle}
209 \newcommand{\mycomp}{\mathbin{\myfun{$\circ$}}}
210 \newcommand{\mylist}[1]{\mytyc{List}\myappsp #1}
211 \newcommand{\mylistt}[1]{\mathopen{\mydc{$[$}} #1 \mathclose{\mydc{$]$}}}
212 \newcommand{\myplus}{\mathbin{\myfun{$+$}}}
213 \newcommand{\mytimes}{\mathbin{\myfun{$*$}}}
214 \newcommand{\mysuc}{\mydc{suc}}
215 \newcommand{\myzero}{\mydc{zero}}
216
217 \renewcommand{\[}{\begin{equation*}}
218 \renewcommand{\]}{\end{equation*}}
219 \newcommand{\mymacol}[2]{\text{\textcolor{#1}{$#2$}}}
220
221 \title{\mykant: Implementing Observational Equality}
222 \author{Francesco Mazzoli \texttt{<fm2209@ic.ac.uk>}}
223 \date{June 2013}
224
225 \begin{document}
226 \frame{\titlepage}
227
228 \begin{frame}
229   \frametitle{\mykant?}
230
231   \mykant\ is an \emph{interactive theorem prover}, implemented in
232   Haskell.
233
234   It is similar in scope to Agda or Coq, but with a more powerful notion
235   of \emph{equality}.
236 \end{frame}
237
238 \begin{frame}
239   \frametitle{Theorem provers are short-sighted}
240
241   Two functions dear to the Haskell practitioner:
242   \[
243   \begin{array}{@{}l}
244     \myfun{map} : (\myb{a} \myarr \myb{b}) \myarr \mylist{\myb{a}} \myarr \mylist{\myb{b}} \\
245       \begin{array}{@{}l@{\myappsp}c@{\myappsp}c@{\ }c@{\ }l}
246         \myfun{map} & \myb{f} & \mynil & = & \mynil \\
247         \myfun{map} & \myb{f} & (\myb{x} \mycons \myb{xs}) & = & \myapp{\myb{f}}{\myb{x}} \mycons \myfun{map} \myappsp \myb{f} \myappsp \myb{xs} \\
248       \end{array}
249       \\
250       \ \\
251     (\myfun{${\circ}$}) : (\myb{b} \myarr \myb{c}) \myarr (\myb{a} \myarr \myb{b}) \myarr (\myb{a} \myarr \myb{c}) \\
252     (\myb{f} \mathbin{\myfun{$\circ$}} \myb{g}) \myappsp \myb{x} = \myapp{\myb{g}}{(\myapp{\myb{f}}{\myb{x}})}
253   \end{array}
254   \]
255 \end{frame}
256
257 \begin{frame}
258   \frametitle{Theorem provers are short-sighted}
259   $\myfun{map}$'s composition law states that:
260   \[
261     \forall \myb{f} {:} (\myb{b} \myarr \myb{c}), \myb{g} {:} (\myb{a} \myarr \myb{b}). \myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g} \myeq \myfun{map}\myappsp (\myb{f} \mycomp \myb{g})
262   \]
263   We can convince Coq or Agda that
264   \[
265     \forall \myb{f} {:} (\myb{b} \myarr \myb{c}), \myb{g} {:} (\myb{a} \myarr \myb{b}), \myb{l} {:} \mylist{\myb{a}}. (\myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g}) \myappsp \myb{l} \myeq \myfun{map}\myappsp (\myb{f} \mycomp \myb{g}) \myappsp \myb{l}    
266   \]
267   But we cannot get rid of the $\myb{l}$.  Why?
268 \end{frame}
269
270 \begin{frame}
271   \frametitle{\mykant\ and observational equality}
272
273   \emph{Observational} equality solves this and other annoyances.
274
275   \mykant\ is a system aiming at making observational equality more
276   usable.
277 \end{frame}
278
279 \begin{frame}
280   \frametitle{Theorem provers, dependent types}
281   \begin{center}
282     \Huge
283     types $\leftrightarrow$ propositions
284
285     programs $\leftrightarrow$ proofs
286   \end{center}
287 \end{frame}
288
289 \begin{frame}
290   \frametitle{Theorem provers, dependent types} First class types: we
291   can return them, have them as arguments, etc.
292   \[
293   \begin{array}{@{}l@{\ \ \ }l}
294     \mysyn{data}\ \myempty & \text{No members.} \\
295     \mysyn{data}\ \myunit \mapsto \mytt & \text{One member.}
296   \end{array}
297   \]
298   $\myempty : \mytyp$, $\myunit : \mytyp$.
299
300   $\myunit$ is trivially inhabitable: it corresponds to $\top$ in
301   logic.
302   \[
303   \mytt : \myunit
304   \]
305   $\myempty$ is \emph{not} inhabitable: it corresponds to $\bot$.
306   \[
307   \myfun{absurd} : \myempty \myarr \myb{A}
308   \]
309 \end{frame}
310
311 \begin{frame}
312   \frametitle{Theorem provers, dependent types}
313   \[ \mysyn{data}\ \mylist{\myb{A}} \mapsto \mynil \mydcsep \myb{A} \mycons \mylist{\myb{A}} \]
314   We want to express a `non-emptiness' property for lists:
315   \[
316   \begin{array}{@{}l}
317     \myfun{non-empty} : \mylist{\myb{A}} \myarr \mytyp \\
318     \begin{array}{@{}l@{\myappsp}c@{\ }l}    
319     \myfun{non-empty} & \mynil & \mapsto \myempty \\
320     \myfun{non-empty} & (\myb{x} \mycons \myb{l}) & \mapsto \myunit
321     \end{array}
322   \end{array}
323   \]
324
325   A term of type $\myfun{non-empty} \myappsp \myb{l}$ represents a
326   \emph{proof} that $\myb{l}$ is indeed not empty.
327   \[
328   \begin{array}{@{}l@{\ \ \ }l}
329     \text{Can't prove} & \myfun{non-empty}\myappsp \mynil \myred \myempty \\
330     \text{Trivial to prove}  & \myfun{non-empty}\myappsp(2 \mycons \mynil) \myred \myunit
331   \end{array}
332   \]
333 \end{frame}
334
335 \begin{frame}
336   \frametitle{Example: safe $\myfun{head}$ function}
337   \only<3>{We can eliminate the `empty list' case:}
338   \[
339   \begin{array}{@{}l}
340     \myfun{head} : \myfora{\myb{l}}{\mytyc{List}\myappsp\myb{A}}{ \myfun{non-empty}\myappsp\myb{l} \myarr \myb{A}} \\
341     \begin{array}{@{}l@{\myappsp}c@{\myappsp}c@{\ }c@{\ }l}
342       \myfun{head} & \mynil & \myb{p} & \mapsto & \only<1,2>{\myhole{?}}\only<3>{\myabsurd\myappsp\myb{p}} \\
343       \myfun{head} & (\myb{x} \mycons \myb{xs}) & \myb{p} & \mapsto & \myb{x}
344     \end{array}
345   \end{array}
346   \]
347
348   \only<1>{
349     The logic equivalent would be
350     \[
351     \forall \myb{l} {:} \mylist{\myb{A}}.\ \myfun{non-empty}\myappsp\myb{l} \myarr \myb{A}
352     \]
353     `For all non-empty lists of type $\myb{A}$, we can get an element of $\myb{A}$.'
354   }
355   \only<2>{
356   The type of $\myb{p}$ in the $\myhole{?}$ is $\myempty$, since
357   \[\myfun{non-empty}\myappsp\mynil \myred \myempty \]}
358   \only<3>{
359     Remember:
360     \[ \myfun{absurd} : \myempty \myarr \myb{A} \]
361   }
362 \end{frame}
363
364 \begin{frame}
365   \frametitle{How do we type check this thing?}
366   \[
367   \myfun{head} \myappsp (3 \mycons \mynil) : \myfun{non-empty}\myappsp(3 \mycons \mynil) \myarr \mynat
368   \]
369   Is it the case that
370   \[ \mytt : \myfun{non-empty}\myappsp(3 \mycons \mynil) \]
371   Or
372   \[ \myfun{head} \myappsp (3 \mycons \mynil) : \myunit \myarr \mynat \]
373
374   Yes: to typecheck, we reduce terms fully (to their \emph{normal} form)
375   before comparing:
376   \[
377   \begin{array}{@{}r@{\ }c@{\ }c@{\ }c@{\ }c@{\ }c@{\ }l}
378     \myunit & \myredd & \myunit & \mydefeq & \myunit & \myreddd & \myfun{non-empty}\myappsp(3 \mycons \mynil) \\
379     (\myabs{\myb{x}\, \myb{y}}{\myb{y}}) \myappsp \myunit \myappsp \myappsp \mynat & \myredd & \mynat & \mydefeq & \mynat & \myreddd & (\myabs{\myb{x}\, \myb{y}}{\myb{x}}) \myappsp \mynat \myappsp \myunit \\
380     & & & \vdots & & & 
381   \end{array}
382   \]
383   \[
384   \mydefeq\ \text{takes the name of \textbf{definitional equality}.}
385   \]
386 \end{frame}
387
388 \begin{frame}
389   \frametitle{Propositional equality} Using definitional equality, we
390   can give the user a type-level notion of term equality.
391   \[
392   (\myeq) : \myb{A} \myarr \myb{A} \myarr \mytyp\ \ \ \text{internalises equality \textbf{as a type}}
393   \]
394   We introduce members of $\myeq$ by reflexivity, for example
395   \[
396   \myrefl\myappsp5 : 5 \myeq 5
397   \]
398   But also
399   \[
400   \begin{array}{@{}l}
401   \myrefl\myappsp 5 : (3 + 2) \myeq (1 + 4)\text{, since}\\
402   (3 + 2) \myeq (1 + 4) \myredd 5 \myeq 5
403   \end{array}
404   \]
405   Then we can use a substitution law to derive other
406   laws---transitivity, congruence, etc.
407   \[ \myeq\ \text{takes the name of \textbf{propositional equality}} \]
408 \end{frame}
409
410 \begin{frame}
411 \frametitle{The problem with prop. equality}
412 Going back to $\myfun{map}$, we can prove that
413 \[    \forall \myb{f} {:} (\myb{b} \myarr \myb{c}), \myb{g} {:} (\myb{a} \myarr \myb{b}), \myb{l} {:} \mylist{\myb{a}}.\ (\myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g}) \myappsp \myb{l} \myeq \myfun{map}\myappsp (\myb{f} \mycomp \myb{g}) \myappsp \myb{l}    \]
414 Because
415 \[
416 (\myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g})\myappsp \myb{l} \mydefeq \myfun{map}\myappsp (\myb{f} \mycomp \myb{g}) \myappsp \myb{l}
417 \]
418 By induction on $\myb{l}$.
419
420 Without the $\myb{l}$ we cannot compute, so we are stuck with
421 \[
422 \myfun{map}\myappsp \myb{f} \mycomp \myfun{map}\myappsp \myb{g} \not\mydefeq \myfun{map}\myappsp (\myb{f} \mycomp \myb{g})
423 \]
424 \end{frame}
425
426 \begin{frame}
427   \frametitle{Observational equality}
428
429   Instead of basing its equality on definitional equality, look at the
430   structure of the type to decide.
431
432   For functions this will mean that proving
433   \[
434     \myfun{map}\myappsp \myse{f} \mycomp \myfun{map}\myappsp \myse{g} \myeq \myfun{map}\myappsp (\myse{f} \mycomp \myse{g})
435   \]
436   Will reduce to proving that
437   \[
438   (\myb{l} : \mylist{\myb{A}}) \myarr 
439     (\myfun{map}\myappsp \myse{f} \mycomp \myfun{map}\myappsp \myse{g})\myappsp\myb{l} \myeq \myfun{map}\myappsp (\myse{f} \mycomp \myse{g})\myappsp \myb{l}
440   \]
441   Which is what we want.  The interesting part is how to make the system
442   compute nicely.
443   
444   This extends to other structures (tuples, inductive types, \dots).
445   Moreover, if we can deem two \emph{types} equal, we can \emph{coerce}
446   values from one to the other.
447 \end{frame}
448
449 \begin{frame}
450   \begin{center}
451     {\huge \mykant' features}
452   \end{center}
453 \end{frame}
454
455 \begin{frame}
456   \frametitle{Inductive data}
457   \[
458   \mysyn{data}\ \mytyc{List}\myappsp (\myb{A} : \mytyp) \mapsto \mynil \mydcsep \myb{A} \mycons \mytyc{List}\myappsp\myb{A}
459   \]
460   Each with an induction principle:
461   \[
462   \begin{array}{@{}l@{\ }l}
463     \mytyc{List}.\myfun{elim} : & \AgdaComment{-{}- The property that we want to prove:} \\
464      & (\myb{P} : \mytyc{List}\myappsp\myb{A} \myarr \mytyp) \myarr \\
465      & \AgdaComment{-{}- If it holds for the base case:} \\
466     & \myb{P} \myappsp \mynil \myarr \\
467     & \AgdaComment{-{}- And for the inductive step:} \\
468     & ((\myb{x} : \myb{A}) \myarr (\myb{l} : \mytyc{List}\myappsp \myb{A}) \myarr \myb{P} \myappsp \myb{l} \myarr \myb{P} \myappsp (\myb{x} \mycons \myb{l})) \myarr \\
469     & \AgdaComment{-{}- Then it holds for every list:} \\
470     & (\myb{l} : \mytyc{List}\myappsp\myb{A}) \myarr \myb{P} \myappsp \myb{l}
471   \end{array}
472   \]
473   Induction is also computation, via structural recursion:
474   \[
475   \begin{array}{@{}l@{\ }l}
476     \mytyc{List}.\myfun{elim} \myappsp \myse{P} \myappsp \myse{pn} \myappsp \myse{pc} \myappsp \mynil & \myred \myse{pn} \\
477     \mytyc{List}.\myfun{elim} \myappsp \myse{P} \myappsp \myse{pn} \myappsp \myse{pc} \myappsp (\mytmm \mycons \mytmn) & \myred \myse{pc} \myappsp \mytmm \myappsp \mytmn \myappsp (\mytyc{List}.\myfun{elim} \myappsp \myse{P} \myappsp \myse{pn} \myappsp \myse{ps} \myappsp \mytmt )
478   \end{array}
479   \]
480 \end{frame}
481
482 \begin{frame}
483   \frametitle{Dependent defined types} \emph{Unlike} Haskell, we can
484   have fields of a data constructor to depend on earlier fields:
485   \[
486   \begin{array}{@{}l}
487     \mysyn{record}\ \mytyc{Tuple}\myappsp(\myb{A} : \mytyp)\myappsp\myhole{$(\myb{B} : \myb{A} \myarr \mytyp)$} \mapsto \\
488     \myind{2}\mydc{tuple}\ \{ \myfun{fst} : \myb{A}, \myfun{snd} : \myb{B}\myappsp\myb{fst} \}
489   \end{array}
490   \]
491
492   The \emph{type} of the second element depends on the \emph{value} of
493   the first:
494   \[
495   \begin{array}{@{}l@{\ }l}
496     \myfun{fst} & : \mytyc{Tuple}\myappsp\myb{A}\myappsp\myb{B} \myarr \myb{A} \\
497     \myfun{snd} & : (\myb{x} : \mytyc{Tuple}\myappsp\myb{A}\myappsp\myb{B}) \myarr \myb{B} \myappsp (\myfun{fst} \myappsp \myb{x})
498   \end{array}
499   \]
500   Where the projection's reduction rules are predictably
501   \[
502   \begin{array}{@{}l@{\ }l}
503     \myfun{fst}\myappsp&(\mydc{tuple}\myappsp\mytmm\myappsp\mytmn) \myred \mytmm \\
504     \myfun{snd}\myappsp&(\mydc{tuple}\myappsp\mytmm\myappsp\mytmn) \myred \mytmn \\
505   \end{array}
506   \]
507 \end{frame}
508
509 \begin{frame}
510   \frametitle{Example: the type of even numbers}
511   For example we can define the type of even numbers:
512   % TODO fix
513   \[
514   \begin{array}{@{}l}
515     \myfun{even} : \mynat \myarr \mytyp \\
516     \begin{array}{@{}l@{\myappsp}c@{\ }l}
517       \myfun{even} & \myzero & \mapsto \myunit \\
518       \myfun{even} & (\mysuc \myappsp \myzero) & \mapsto \myempty \\
519       \myfun{even} & (\mysuc \myappsp (\mysuc \myappsp \myb{n})) & \mapsto \myfun{even} \myappsp \myb{n}
520     \end{array} \\
521     \ \\
522     \mytyc{Even} : \mytyp \\
523     \mytyc{Even} \mapsto \mytyc{Tuple}\ \mynat\ \myfun{even}
524   \end{array}
525   \]
526 \end{frame}
527
528 \begin{frame}
529   \frametitle{Type hierarchy}
530   \[\{\mynat, \mybool, \mytyc{List}\myappsp\mynat, \cdots\} : \mytyp\]
531   What is the type of $\mytyp$?
532   \[
533   \cancel{\mytyp : \mytyp}\ \ \ \text{\textbf{inconsistent}}
534   \]
535   Much like na{\"i}ve set theory is (Girard's paradox).
536
537   Instead, we have a hierarchy:
538   \[
539   \{\mynat, \mybool, \mytyc{List}\myappsp\mynat, \cdots\} : \mytyp_0 : \mytyp_1 : \cdots
540   \]
541   We talk of types in $\mytyp_0$ as `smaller' than types in $\mytyp_1$.
542 \end{frame}
543
544 \begin{frame}
545   \frametitle{Cumulativity and typical ambiguity}
546   Instead of:
547   \[ \mytyp_0 : \mytyp_1 \ \ \ \text{but}\ \ \ \mytyp_0 \centernot{:} \mytyp_2\]
548   We have a cumulative hierarchy, so that
549   \[ \mytyp_n : \mytyp_m \ \ \ \text{iff}\ \ \ n < m \]
550   For example
551   \[ \mynat : \mytyp_0\ \ \ \text{and}\ \ \ \mynat : \mytyp_1\ \ \ \text{and}\ \ \ \mynat : \mytyp_{50} \]
552
553   But in \mykant, you can forget about levels: the consistency is
554   checked automatically---a mechanised version of what Russell called
555   \emph{typical ambiguity}.
556 \end{frame}
557
558 \begin{frame}
559   \frametitle{Bidirectional type checking}
560   \[
561   \mysyn{data}\ \mytyc{List}\myappsp (\myb{A} : \mytyp) \mapsto \mydc{nil} \mydcsep \mydc{cons} \myappsp \myb{A}\myappsp (\mytyc{List}\myappsp\myb{A})
562   \]
563
564   With no type inference, we have explicit types for the constructors:
565   \[
566   \begin{array}{@{}l@{\ }l}
567     \mydc{nil} & : (\myb{A} : \mytyp) \myarr \mytyc{List}\myappsp\myb{A} \\
568     \mydc{cons} &: (\myb{A} : \mytyp) \myarr \myb{A} \myarr \mytyc{List}\myappsp\myb{A} \myarr \mytyc{List}\myappsp\myb{A}\\
569   \end{array}
570   \]
571   ...ugh:
572   \[
573   \mydc{cons}\myappsp \mynat\myappsp 1 \myappsp (\mydc{cons}\myappsp \mynat \myappsp 2 \myappsp (\mydc{cons}\myappsp \mynat \myappsp 3 \myappsp (\mydc{nil}\myappsp \mynat)))
574   \]
575   Instead, annotate terms and propagate the type:
576   \[
577   \mydc{cons}\myappsp 1 \myappsp (\mydc{cons}\myappsp 2 \myappsp (\mydc{cons} \myappsp 3 \myappsp \mydc{nil})) : \mytyc{List}\myappsp\mynat
578   \]
579   Conversely, when we use eliminators the type can be inferred.
580 \end{frame}
581
582 \begin{frame}
583   \frametitle{Bidirectional type checking}
584
585   This technique is known as \emph{bidirectional} type checking---some
586   terms get \emph{checked}, some terms \emph{infer} types.
587
588   Usually used for pre-defined types or core calculi, \mykant\ extends
589   to user-defined types.
590 \end{frame}
591
592 \begin{frame}
593   \frametitle{OTT + user defined types}
594
595   For each type, we need to:
596   \begin{itemize}
597   \item Describe when two types formed by the defined type constructors
598     are equal;
599     \[ \mylist{\mytya_1} \myeq \mylist{\mytya_2} \]
600   \item Describe when two values of the defined type are equal;
601     \[
602     \begin{array}{@{}c@{\ \ \ \ \ \ }c}
603       \mynil \myeq \mynil & \mynil \myeq \mytmm \mycons \mytmn \\
604       \mytmm \mycons \mytmn \myeq \mynil & \mytmm_1 \mycons \mytmn_1 \myeq \mytmm_2 \mycons \mytmn_2
605     \end{array}
606     \]
607   \item Describe how to transport values of the defined type.
608   \end{itemize}
609 \end{frame}
610
611 \begin{frame}
612   \frametitle{OTT + hierarchy}
613
614   Since equalities reduce to functions abstracting over various things,
615   we need to make sure that the hierarchy is respected.
616
617   For example we have that
618   \[
619   \begin{array}{@{}l}
620     (\myb{x_1} {:} \mytya_1) \myarr \mytyb_1 \myeq (\myb{x_2} {:} \mytya_2) \myarr \mytyb_2 \myred \\
621     \myind{2} \mytya_1 \myeq \mytya_2 \myand 
622     ((\myb{x_1} : \mytya_1) \myarr (\myb{x_2} : \mytya_2) \myarr \mytyb_1[\myb{x_1}] \myeq \mytyb_2[\myb{x_2}])
623   \end{array}
624   \]
625
626   Subtle point---I discovered a problem in the theory after
627   submitting... but I have a fix.
628 \end{frame}
629
630 \begin{frame}
631 \begin{center}
632 {\Huge Demo}
633 \end{center}
634 \end{frame}
635
636 \begin{frame}
637   \frametitle{Further work}
638
639   \begin{itemize}
640     \item Pattern matching and explicit recursion
641     \item More expressive data types
642     \item Inference via unification
643     \item Codata
644   \end{itemize}
645 \end{frame}
646
647 \begin{frame}
648 \begin{center}
649 {\Huge Questions?}
650 \end{center}
651 \end{frame}
652
653 \end{document}