agda.tex 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. \NeedsTeXFormat{LaTeX2e}
  2. \documentclass[25pt,dvips,fleqn]{foils}
  3. \usepackage[a4paper,landscape,margin=25pt]{geometry}
  4. \usepackage{alltt}
  5. \usepackage[dvips]{color}
  6. \usepackage{proof}
  7. \title{Agda2 Core Language Proposal}
  8. \author{}
  9. % foiltex parameters
  10. \date{2006-03-22}
  11. \MyLogo{}
  12. \leftheader{}
  13. \rightheader{}
  14. \rightfooter{}
  15. % foiltex modification for possibly tighter lineskip.
  16. \makeatletter
  17. \setlength\foilheadskip{-30pt}
  18. \setlength\parskip{18\p@ \@plus 4\p@ \@minus 18\p@}
  19. \renewcommand\@listIa{\leftmargin\leftmargini
  20. \topsep 14\p@ \@plus 2\p@ \@minus 14\p@
  21. \parsep 14\p@ \@plus 4\p@ \@minus 14\p@
  22. \itemsep 14\p@ \@plus 4\p@ \@minus 14\p@}
  23. %
  24. \def\normalsize{\@setfontsize\normalsize\@xxvpt{32}%
  25. \abovedisplayskip 30\p@ \@plus 3\p@ \@minus 30\p@
  26. \belowdisplayskip \abovedisplayskip
  27. \abovedisplayshortskip \z@ \@plus 3\p@
  28. \belowdisplayshortskip 7\p@ \@plus 3\p@ \@minus 7\p@
  29. \let\@listi\@listIa}
  30. %\normalsize
  31. \def\small{\@setfontsize\small\@xxpt\@xxvpt
  32. \abovedisplayskip 30\p@ \@plus 3\p@ \@minus 30\p@
  33. \belowdisplayskip \abovedisplayskip
  34. \abovedisplayshortskip \z@ \@plus 3\p@
  35. \belowdisplayshortskip 7\p@ \@plus 3\p@ \@minus 7\p@
  36. \if@compatibility
  37. \let\@listi\@listIb
  38. \else
  39. \let\@listi\@listIa\fi
  40. }
  41. \makeatother
  42. % proof.sty parameter
  43. \inferLineSkip=8pt
  44. % latex parameter
  45. \def\arraystretch{1.2}
  46. % colors
  47. \newcommand\blue{\color{blue}}
  48. \newcommand\red{\color{red}}
  49. \newcommand\gray{\color[gray]{0.4}}
  50. \newcommand{\lbr}{\lbrack\!\lbrack}
  51. \newcommand{\rbr}{\rbrack\!\rbrack}
  52. \newcommand{\sem}[1]{\mbox{$\lbr #1 \rbr$}}
  53. % abbreviations
  54. \newcommand\ar{\mathop{\mathrm{ar}}}
  55. \newcommand\add{\mathop{\mathsf{add}}}
  56. \newcommand\suc{\mathop{\mathsf{suc}}}
  57. \newcommand\Label{\mathop{\mathsf{Label}}}
  58. \newcommand\SN{\mathop{\mathsf{SN}}}
  59. \newcommand\DD{\sf D}
  60. \newcommand\El{\mathop{\mathsf{El}}}
  61. \newcommand\Fun{\mathop{\mathsf{Fun}}}
  62. \newcommand\Sum{\mathop{\mathsf{Sum}}}
  63. \newcommand\E{\mathop{\mathsf{E}}}%{\sf E}
  64. \newcommand\len{\mathop{\mathrm{length}}}
  65. \newcommand\llet{\mathop{\mathrm{let}}}
  66. \newcommand\Nat{\mathsf{Nat}}
  67. \newcommand\Unit{\mathsf{Unit}}
  68. \newcommand\Prop{\mathsf{Prop}}
  69. \newcommand\Prf{\mathsf{Proof}}
  70. \newcommand\Set{\mathsf{Set}}
  71. \newcommand\where{\mathsf{where}}
  72. \newcommand\type{\mathsf{type}}
  73. \newcommand\Kind{\mathsf{Kind}}
  74. \newcommand\data{\mbox{\sffamily\slshape data}}
  75. \newcommand\fun{\mbox{\sffamily\slshape fun}}
  76. \newcommand\with{\mbox{\sffamily\slshape with}}
  77. %\newcommand\where{\mbox{\sffamily\slshape where}}
  78. \newcommand\correct{\mathrm{correct}}
  79. \newcommand\Type{\mathrm{Type}}
  80. \newcommand\lam{}\let\lam\lambda
  81. \newcommand\Down{}\let\Down\Downarrow
  82. \newcommand\down{}\let\down\downarrow
  83. \newcommand\Up{}\let\Up\Uparrow
  84. \newcommand\up{}\let\up\uparrow
  85. \newcommand\hdrs{\mathrel{\succ}^*}
  86. \newcommand\hdr{\mathrel{\succ}}
  87. \newcommand\redQ{{\red ???}}
  88. \newcommand\mbf[1]{\textbf{\slshape #1}}
  89. \newcommand\Tparam{\mbf T_{\mathrm{param}}}
  90. \newcommand\Tindex{\mbf T_{\mathrm{index}}}
  91. \newcommand\Mparam{\mbf M_{\mathrm{param}}}
  92. \newcommand\Mindex{\mbf M_{\mathrm{index}}}
  93. \begin{document}
  94. %\begin{abstract}
  95. %\end{abstract}
  96. \maketitle
  97. \rm
  98. %\rightfooter{}
  99. \foilhead{Untyped Programming Language}
  100. Untyped $\lambda$-calculus
  101. + primitive constants $c$ + defined constants $f$
  102. $$
  103. M,N ~::= ~n ~|~ M\,N ~|~ \lambda x.M ~~~~~~ n ::= x ~|~ c ~|~ f
  104. $$
  105. Fixed arities for constants:
  106. \tabular[t]l $\ar(0)=0$, $\ar(\suc)=1$, $\ar(\add)=2$, $\cdots$ \endtabular
  107. \foilhead{Untyped Programming Language}
  108. We write $p,q,\dots$ for vectors of variables. Each $f$ is defined
  109. by left-linear mutually-disjoint pattern-matching clauses:
  110. $$f~p~(c_i~q_i) = M_i$$
  111. $\lambda (x,p).M = \lambda x.\lambda p.M$
  112. $\lambda ().M = M$
  113. We have also non-recursive abreviations $f=M$
  114. \foilhead{Telescopes}
  115. $$\Delta~::=~()~|~(x:A,\Delta)$$
  116. We define the context $p:\Delta$
  117. $(x,p):(x:A,\Delta)$ is $x:A,p:\Delta$
  118. Telescopes (as types) and vectors (of elements) form a model
  119. of type theory with $\Sigma$-types
  120. $(M,u):(x:A,\Delta)$ iff $M:A$ and $u:\Delta(x=M)$
  121. \foilhead{Telescopes}
  122. If $p:\Delta\vdash A$ we define $(p:\Delta)\rightarrow A$ by induction on $\Delta$
  123. If $\Delta$ is $()$ this is $A$
  124. $((y,q):(y:B,V))\rightarrow A = (y:B)\rightarrow (q:V)\rightarrow A$
  125. We define $(p:\Delta)\rightarrow U$ by
  126. $(p:\Delta)\rightarrow () = ()$
  127. $(p:\Delta)\rightarrow (y:B,V) = (g:(p:\Delta)\rightarrow B,(p:\Delta)\rightarrow V(y=g~p))$
  128. If $v:(p:\Delta)\rightarrow U$ and $u:\Delta$ then $v~u:U(p=u)$
  129. \foilhead{Telescopes}
  130. We define $(p:\Delta,V)$ by induction on $\Delta$
  131. If $\Delta = ()$ this is $V$ and if $((x,q):(x:A,U),V) = (x:A,(q:U,V))$
  132. We then have $((p,q):(p:\Delta,V))\rightarrow W = (p:\Delta)\rightarrow (q:V)\rightarrow W$
  133. \foilhead{Telescopes}
  134. If we have $p:\Delta\vdash u:U$ then $\lambda p.u :(p:\Delta)\rightarrow U$
  135. $\lambda p.() = ()$
  136. $\lambda p.(M,u) = (\lambda p.M,\lambda p.u)$
  137. We define also $()~v = ()$ and $(M,u)~v = (M~v,u~v)$
  138. We have $(\lambda p.u)~v = u(p=v)$
  139. \foilhead{Terms in $\beta$-normal form}
  140. $N~::=~\lambda x.N~|~h~u,~~~~~~~h~::=~x|~c~|~d~|~f$
  141. Type-checking
  142. $$\frac{\Gamma,x:A\vdash N:B}{\Gamma\vdash \lambda x.N\uparrow (x:A)\rightarrow B}$$
  143. $$\frac{\Gamma\vdash u\uparrow \Delta~~~~\Gamma\vdash B = A(p=u)}{\Gamma\vdash h~u\uparrow B}
  144. {~~~h:(p:\Delta)\rightarrow A}$$
  145. $$\frac{\Gamma\vdash u\uparrow \Delta_i(q=v)}{\Gamma\vdash c_i~u\uparrow d~v}$$
  146. with $d = \lambda q.(c_1~\Delta_1,\dots,c_k~\Delta_k)$
  147. \foilhead{Type-checking}
  148. $$\frac{\Gamma\vdash A~\type _0~~~~~\Gamma,x:A\vdash B~\type _0}
  149. {\Gamma\vdash (x:A)\rightarrow B~\type _0}$$
  150. $$\frac{\Gamma\vdash N\uparrow \Set}{\Gamma\vdash N~\type _0}$$
  151. \foilhead{Conversion algorithm}
  152. $$\frac{\Gamma,x:A\vdash M_1~x = M_2~x\uparrow B}{\Gamma\vdash M_1=M_2\uparrow (x:A)\rightarrow B}$$
  153. $$\frac{\Gamma\vdash u=u'\uparrow \Delta}{\Gamma\vdash h~u=h~u'}~~~{h:\Delta\rightarrow A}$$
  154. $$\frac{\Gamma\vdash u=u'\uparrow \Delta_i(q=v)}{\Gamma\vdash c_i~u = c_i~u'\uparrow d~v}$$
  155. with $d = \lambda q.(c_1~\Delta_1,\dots,c_k~\Delta_k)$
  156. $$\frac{\Gamma\vdash M=M'\uparrow A~~~~~\Gamma\vdash u=u'\uparrow \Delta(x=M)}
  157. {\Gamma\vdash (M,u)=(M',u')\uparrow (x:A,\Delta)}~~~~~~~
  158. \frac{}{\Gamma\vdash () = ()\uparrow ()}$$
  159. \foilhead{Signature}
  160. Collection of constants with types $c:A$ and definitions
  161. We can add
  162. (1) new constant $c:A$ if $\vdash A$, $c$ fresh name
  163. (2) new definition for a constant $d:A$ or $f:A$ already declared
  164. 2 kind of definitions: constants for {\em data types} and for
  165. {\em recursively defined functions} over these data types
  166. \foilhead{Signature}
  167. Constants for data types
  168. For $d:\Delta\rightarrow\Set$, and $p:\Delta\vdash \Delta_i~\type _0$
  169. $d = \lambda p.(c_1~\Delta_1,\dots,c_k~\Delta_k)$
  170. Typing rules
  171. $$\frac{}{\Gamma\vdash d:\Delta\rightarrow\Set}$$
  172. $$\frac{\Gamma\vdash u:\Delta~~~~~\Gamma\vdash v:\Delta_i(p=u)}{\Gamma\vdash c_i~v:d~v}$$
  173. %This definition adds also $c_i:(p:\Delta)\rightarrow \Delta_i\rightarrow c~p$
  174. \foilhead{Signature}
  175. Constants for recursively defined functions
  176. If we have $d:U\rightarrow\Set$
  177. and $d = \lambda q.(c_1~\Delta_1,\dots,c_k~\Delta_k)$ and
  178. $f:(p:\Delta)\rightarrow (x:d~u)\rightarrow A$
  179. Notice that $p:\Delta\vdash u:U$
  180. We can add the definition
  181. $f = \lambda p.(c_1~p_1\rightarrow M_1,\dots,c_k~p_k\rightarrow M_k)$
  182. provided $p:\Delta,p_i:\Delta_i(q=u)\vdash M_i:A(x=c_i~p_i)$
  183. \foilhead{Signature}
  184. New conversion rule
  185. $$\frac{\Gamma\vdash v:\Delta~~~~~\Gamma\vdash w:\Delta_i(q=u(p=v))}
  186. {\Gamma\vdash f~v~(c_i~w) = M_i(p=v,p_i=w):A(p=v,x=c_i~w)}$$
  187. This can be also interpreted as an untyped reduction rule
  188. $f~v~(c_i~w)\rightarrow M_i(p=v,p_i=w)$
  189. \foilhead{Signature}
  190. {\bf Example}: universe
  191. $U:\Set,~T:U\rightarrow\Set$
  192. We can define $U = (\hat{n},\hat{\pi}~(x:U,f:T~x\rightarrow U))$
  193. After this, we can define
  194. $T = (\hat{n}\rightarrow N,\hat{\pi}~x~f\rightarrow \Pi~(T~x)~(\lambda y.T~(f~y)))$
  195. $T~\hat{n} = N$
  196. $T~(\hat{\pi}~x~f) = \Pi~(T~x)~(\lambda y.T~(f~y))$
  197. \foilhead{Type-checking}
  198. $$\frac{\Gamma\vdash A~\type _m~~~~~\Gamma,x:A\vdash B~\type _m}
  199. {\Gamma\vdash (x:A)\rightarrow B~\type _m}$$
  200. $$\frac{\Gamma\vdash N\uparrow \Set _l~~~l\leq m}
  201. {\Gamma\vdash N~\type _m}$$
  202. $$\frac{l<m}{\Gamma\vdash \Set _l~\type _m}$$
  203. \foilhead{Where clause}
  204. $$N~::=~\lambda x.N~|~n~u~|~N~\where~D$$
  205. $$D~::=~p:\Delta = u$$
  206. The simplest typing rule is
  207. $$\frac{\Gamma\vdash~\Delta~~~~~~\Gamma\vdash u:\Delta~~~~~~\Gamma,p:\Delta\vdash N:A}
  208. {\Gamma\vdash N~\where~p:\Delta=u~:~A}$$
  209. \foilhead{Example}
  210. $V:\Set,~a_0:V,~comp:V\rightarrow (V\rightarrow\Set)\rightarrow V,
  211. ~(\epsilon):V\rightarrow V\rightarrow\Set$
  212. $h:(a,x:V)\rightarrow (P:V\rightarrow\Set)\rightarrow
  213. x\epsilon (comp~a~P)\Leftrightarrow x\epsilon a\wedge P~x$
  214. We can then compute a witness for the telescopes
  215. $\emptyset:V,h_0:(x:V)\rightarrow \neg x\epsilon \emptyset$
  216. $\emptyset = comp~ a_0~ (\lambda x.\perp),~~~h_0=\dots$
  217. $(\cap):V\rightarrow V\rightarrow\Set,
  218. h_1:(x,y,z:V)\rightarrow x\epsilon y\cap z\Leftrightarrow x\epsilon y\wedge x\epsilon z$
  219. $(\cap) = \lambda x.\lambda y.comp~x~(\lambda z.z\epsilon y),~h_1=\dots$
  220. \foilhead{Where clause}
  221. The proof development has the following structure
  222. $p_1:\Delta_1,p_2:\Delta_2,p_3:\Delta_3,\dots$
  223. At each level we have $p_1:\Delta_1,\dots,p_{n-1}:\Delta_{n-1}\vdash u_{n}:\Delta_{n}$
  224. $\Delta_n$ should be an abstract specification of $u_n$
  225. \foilhead{Where clause}
  226. So far, we have tried (like in Automath $\lambda\Delta$) a more complicated
  227. type-checking for the where-clause
  228. $p_1:\Delta_1=u_1,\dots$
  229. The type-checking of $\dots$ depends not only on the {\em type}
  230. of $p_1$ but also on its {\em definition} $u_1$
  231. It may be that $\dots$ is not correct in the context $p_1:\Delta_1$
  232. \foilhead{Where clause}
  233. {\bf Example}: give the data type $N_2=(0,1)$
  234. If we declare $Bool:\Set = N_2$ we don't have
  235. $Bool:\Set\vdash 0:Bool$
  236. but $(N_2,0)$ is of type $(Bool:\Set,x:Bool)$
  237. In $\lambda\Delta$ we have
  238. $Bool:\Set=N_2\vdash 0:Bool$
  239. One can argue that this is not {\em modular}: further type-checking
  240. depends not only on the types (the interface), but also on the actual
  241. {\em definition}
  242. \foilhead{Example}
  243. Danko Ilik has formalised Zermelo's 1904 proof of the well-ordering
  244. theorem in type theory extended with the extensional axiom of choice
  245. From type theory, one needs $\Pi,\Sigma,N_2,N_1,N_0$ and the function
  246. $T:N_2\rightarrow\Set$ with $T~0=N_0,~T~1 = N_1$
  247. It would be very interesting to see if this proof can be represented
  248. with this primitive $\where$ mechanism
  249. \end{document}