124 \index{*"* symbol} |
124 \index{*"* symbol} |
125 \index{*"-"-"> symbol} |
125 \index{*"-"-"> symbol} |
126 \begin{center} \tt\frenchspacing |
126 \begin{center} \tt\frenchspacing |
127 \begin{tabular}{rrr} |
127 \begin{tabular}{rrr} |
128 \it external & \it internal & \it standard notation \\ |
128 \it external & \it internal & \it standard notation \\ |
129 \sdx{PROD} $x$:$A$ . $B[x]$ & Prod($A$, $\lambda x.B[x]$) & |
129 \sdx{PROD} $x$:$A$ . $B[x]$ & Prod($A$, $\lambda x. B[x]$) & |
130 \rm product $\prod@{x\in A}B[x]$ \\ |
130 \rm product $\prod@{x\in A}B[x]$ \\ |
131 \sdx{SUM} $x$:$A$ . $B[x]$ & Sum($A$, $\lambda x.B[x]$) & |
131 \sdx{SUM} $x$:$A$ . $B[x]$ & Sum($A$, $\lambda x. B[x]$) & |
132 \rm sum $\sum@{x\in A}B[x]$ \\ |
132 \rm sum $\sum@{x\in A}B[x]$ \\ |
133 $A$ --> $B$ & Prod($A$, $\lambda x.B$) & |
133 $A$ --> $B$ & Prod($A$, $\lambda x. B$) & |
134 \rm function space $A\to B$ \\ |
134 \rm function space $A\to B$ \\ |
135 $A$ * $B$ & Sum($A$, $\lambda x.B$) & |
135 $A$ * $B$ & Sum($A$, $\lambda x. B$) & |
136 \rm binary product $A\times B$ |
136 \rm binary product $A\times B$ |
137 \end{tabular} |
137 \end{tabular} |
138 \end{center} |
138 \end{center} |
139 \subcaption{Translations} |
139 \subcaption{Translations} |
140 |
140 |
167 \section{Syntax} |
167 \section{Syntax} |
168 The constants are shown in Fig.\ts\ref{ctt-constants}. The infixes include |
168 The constants are shown in Fig.\ts\ref{ctt-constants}. The infixes include |
169 the function application operator (sometimes called `apply'), and the |
169 the function application operator (sometimes called `apply'), and the |
170 2-place type operators. Note that meta-level abstraction and application, |
170 2-place type operators. Note that meta-level abstraction and application, |
171 $\lambda x.b$ and $f(a)$, differ from object-level abstraction and |
171 $\lambda x.b$ and $f(a)$, differ from object-level abstraction and |
172 application, \hbox{\tt lam $x$.$b$} and $b{\tt`}a$. A {\CTT} |
172 application, \hbox{\tt lam $x$. $b$} and $b{\tt`}a$. A {\CTT} |
173 function~$f$ is simply an individual as far as Isabelle is concerned: its |
173 function~$f$ is simply an individual as far as Isabelle is concerned: its |
174 Isabelle type is~$i$, not say $i\To i$. |
174 Isabelle type is~$i$, not say $i\To i$. |
175 |
175 |
176 The notation for~{\CTT} (Fig.\ts\ref{ctt-syntax}) is based on that of |
176 The notation for~{\CTT} (Fig.\ts\ref{ctt-syntax}) is based on that of |
177 Nordstr\"om et al.~\cite{nordstrom90}. The empty type is called $F$ and |
177 Nordstr\"om et al.~\cite{nordstrom90}. The empty type is called $F$ and |
178 the one-element type is $T$; other finite types are built as $T+T+T$, etc. |
178 the one-element type is $T$; other finite types are built as $T+T+T$, etc. |
179 |
179 |
180 \index{*SUM symbol}\index{*PROD symbol} |
180 \index{*SUM symbol}\index{*PROD symbol} |
181 Quantification is expressed using general sums $\sum@{x\in A}B[x]$ and |
181 Quantification is expressed using general sums $\sum@{x\in A}B[x]$ and |
182 products $\prod@{x\in A}B[x]$. Instead of {\tt Sum($A$,$B$)} and {\tt |
182 products $\prod@{x\in A}B[x]$. Instead of {\tt Sum($A$,$B$)} and {\tt |
183 Prod($A$,$B$)} we may write \hbox{\tt SUM $x$:$A$.$B[x]$} and \hbox{\tt |
183 Prod($A$,$B$)} we may write \hbox{\tt SUM $x$:$A$. $B[x]$} and \hbox{\tt |
184 PROD $x$:$A$.$B[x]$}. For example, we may write |
184 PROD $x$:$A$. $B[x]$}. For example, we may write |
185 \begin{ttbox} |
185 \begin{ttbox} |
186 SUM y:B. PROD x:A. C(x,y) {\rm for} Sum(B, \%y. Prod(A, \%x. C(x,y))) |
186 SUM y:B. PROD x:A. C(x,y) {\rm for} Sum(B, \%y. Prod(A, \%x. C(x,y))) |
187 \end{ttbox} |
187 \end{ttbox} |
188 The special cases as \hbox{\tt$A$*$B$} and \hbox{\tt$A$-->$B$} abbreviate |
188 The special cases as \hbox{\tt$A$*$B$} and \hbox{\tt$A$-->$B$} abbreviate |
189 general sums and products over a constant family.\footnote{Unlike normal |
189 general sums and products over a constant family.\footnote{Unlike normal |
230 \tdx{NI_succ} a : N ==> succ(a) : N |
230 \tdx{NI_succ} a : N ==> succ(a) : N |
231 \tdx{NI_succL} a = b : N ==> succ(a) = succ(b) : N |
231 \tdx{NI_succL} a = b : N ==> succ(a) = succ(b) : N |
232 |
232 |
233 \tdx{NE} [| p: N; a: C(0); |
233 \tdx{NE} [| p: N; a: C(0); |
234 !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |
234 !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |
235 |] ==> rec(p, a, \%u v.b(u,v)) : C(p) |
235 |] ==> rec(p, a, \%u v. b(u,v)) : C(p) |
236 |
236 |
237 \tdx{NEL} [| p = q : N; a = c : C(0); |
237 \tdx{NEL} [| p = q : N; a = c : C(0); |
238 !!u v. [| u: N; v: C(u) |] ==> b(u,v)=d(u,v): C(succ(u)) |
238 !!u v. [| u: N; v: C(u) |] ==> b(u,v)=d(u,v): C(succ(u)) |
239 |] ==> rec(p, a, \%u v.b(u,v)) = rec(q,c,d) : C(p) |
239 |] ==> rec(p, a, \%u v. b(u,v)) = rec(q,c,d) : C(p) |
240 |
240 |
241 \tdx{NC0} [| a: C(0); |
241 \tdx{NC0} [| a: C(0); |
242 !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |
242 !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |
243 |] ==> rec(0, a, \%u v.b(u,v)) = a : C(0) |
243 |] ==> rec(0, a, \%u v. b(u,v)) = a : C(0) |
244 |
244 |
245 \tdx{NC_succ} [| p: N; a: C(0); |
245 \tdx{NC_succ} [| p: N; a: C(0); |
246 !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |
246 !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |
247 |] ==> rec(succ(p), a, \%u v.b(u,v)) = |
247 |] ==> rec(succ(p), a, \%u v. b(u,v)) = |
248 b(p, rec(p, a, \%u v.b(u,v))) : C(succ(p)) |
248 b(p, rec(p, a, \%u v. b(u,v))) : C(succ(p)) |
249 |
249 |
250 \tdx{zero_ne_succ} [| a: N; 0 = succ(a) : N |] ==> 0: F |
250 \tdx{zero_ne_succ} [| a: N; 0 = succ(a) : N |] ==> 0: F |
251 \end{ttbox} |
251 \end{ttbox} |
252 \caption{Rules for type~$N$} \label{ctt-N} |
252 \caption{Rules for type~$N$} \label{ctt-N} |
253 \end{figure} |
253 \end{figure} |
254 |
254 |
255 |
255 |
256 \begin{figure} |
256 \begin{figure} |
257 \begin{ttbox} |
257 \begin{ttbox} |
258 \tdx{ProdF} [| A type; !!x. x:A ==> B(x) type |] ==> PROD x:A.B(x) type |
258 \tdx{ProdF} [| A type; !!x. x:A ==> B(x) type |] ==> PROD x:A. B(x) type |
259 \tdx{ProdFL} [| A = C; !!x. x:A ==> B(x) = D(x) |] ==> |
259 \tdx{ProdFL} [| A = C; !!x. x:A ==> B(x) = D(x) |] ==> |
260 PROD x:A.B(x) = PROD x:C.D(x) |
260 PROD x:A. B(x) = PROD x:C. D(x) |
261 |
261 |
262 \tdx{ProdI} [| A type; !!x. x:A ==> b(x):B(x) |
262 \tdx{ProdI} [| A type; !!x. x:A ==> b(x):B(x) |
263 |] ==> lam x.b(x) : PROD x:A.B(x) |
263 |] ==> lam x. b(x) : PROD x:A. B(x) |
264 \tdx{ProdIL} [| A type; !!x. x:A ==> b(x) = c(x) : B(x) |
264 \tdx{ProdIL} [| A type; !!x. x:A ==> b(x) = c(x) : B(x) |
265 |] ==> lam x.b(x) = lam x.c(x) : PROD x:A.B(x) |
265 |] ==> lam x. b(x) = lam x. c(x) : PROD x:A. B(x) |
266 |
266 |
267 \tdx{ProdE} [| p : PROD x:A.B(x); a : A |] ==> p`a : B(a) |
267 \tdx{ProdE} [| p : PROD x:A. B(x); a : A |] ==> p`a : B(a) |
268 \tdx{ProdEL} [| p=q: PROD x:A.B(x); a=b : A |] ==> p`a = q`b : B(a) |
268 \tdx{ProdEL} [| p=q: PROD x:A. B(x); a=b : A |] ==> p`a = q`b : B(a) |
269 |
269 |
270 \tdx{ProdC} [| a : A; !!x. x:A ==> b(x) : B(x) |
270 \tdx{ProdC} [| a : A; !!x. x:A ==> b(x) : B(x) |
271 |] ==> (lam x.b(x)) ` a = b(a) : B(a) |
271 |] ==> (lam x. b(x)) ` a = b(a) : B(a) |
272 |
272 |
273 \tdx{ProdC2} p : PROD x:A.B(x) ==> (lam x. p`x) = p : PROD x:A.B(x) |
273 \tdx{ProdC2} p : PROD x:A. B(x) ==> (lam x. p`x) = p : PROD x:A. B(x) |
274 \end{ttbox} |
274 \end{ttbox} |
275 \caption{Rules for the product type $\prod\sb{x\in A}B[x]$} \label{ctt-prod} |
275 \caption{Rules for the product type $\prod\sb{x\in A}B[x]$} \label{ctt-prod} |
276 \end{figure} |
276 \end{figure} |
277 |
277 |
278 |
278 |
279 \begin{figure} |
279 \begin{figure} |
280 \begin{ttbox} |
280 \begin{ttbox} |
281 \tdx{SumF} [| A type; !!x. x:A ==> B(x) type |] ==> SUM x:A.B(x) type |
281 \tdx{SumF} [| A type; !!x. x:A ==> B(x) type |] ==> SUM x:A. B(x) type |
282 \tdx{SumFL} [| A = C; !!x. x:A ==> B(x) = D(x) |
282 \tdx{SumFL} [| A = C; !!x. x:A ==> B(x) = D(x) |
283 |] ==> SUM x:A.B(x) = SUM x:C.D(x) |
283 |] ==> SUM x:A. B(x) = SUM x:C. D(x) |
284 |
284 |
285 \tdx{SumI} [| a : A; b : B(a) |] ==> <a,b> : SUM x:A.B(x) |
285 \tdx{SumI} [| a : A; b : B(a) |] ==> <a,b> : SUM x:A. B(x) |
286 \tdx{SumIL} [| a=c:A; b=d:B(a) |] ==> <a,b> = <c,d> : SUM x:A.B(x) |
286 \tdx{SumIL} [| a=c:A; b=d:B(a) |] ==> <a,b> = <c,d> : SUM x:A. B(x) |
287 |
287 |
288 \tdx{SumE} [| p: SUM x:A.B(x); |
288 \tdx{SumE} [| p: SUM x:A. B(x); |
289 !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) |
289 !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) |
290 |] ==> split(p, \%x y.c(x,y)) : C(p) |
290 |] ==> split(p, \%x y. c(x,y)) : C(p) |
291 |
291 |
292 \tdx{SumEL} [| p=q : SUM x:A.B(x); |
292 \tdx{SumEL} [| p=q : SUM x:A. B(x); |
293 !!x y. [| x:A; y:B(x) |] ==> c(x,y)=d(x,y): C(<x,y>) |
293 !!x y. [| x:A; y:B(x) |] ==> c(x,y)=d(x,y): C(<x,y>) |
294 |] ==> split(p, \%x y.c(x,y)) = split(q, \%x y.d(x,y)) : C(p) |
294 |] ==> split(p, \%x y. c(x,y)) = split(q, \%x y. d(x,y)) : C(p) |
295 |
295 |
296 \tdx{SumC} [| a: A; b: B(a); |
296 \tdx{SumC} [| a: A; b: B(a); |
297 !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) |
297 !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) |
298 |] ==> split(<a,b>, \%x y.c(x,y)) = c(a,b) : C(<a,b>) |
298 |] ==> split(<a,b>, \%x y. c(x,y)) = c(a,b) : C(<a,b>) |
299 |
299 |
300 \tdx{fst_def} fst(a) == split(a, \%x y.x) |
300 \tdx{fst_def} fst(a) == split(a, \%x y. x) |
301 \tdx{snd_def} snd(a) == split(a, \%x y.y) |
301 \tdx{snd_def} snd(a) == split(a, \%x y. y) |
302 \end{ttbox} |
302 \end{ttbox} |
303 \caption{Rules for the sum type $\sum\sb{x\in A}B[x]$} \label{ctt-sum} |
303 \caption{Rules for the sum type $\sum\sb{x\in A}B[x]$} \label{ctt-sum} |
304 \end{figure} |
304 \end{figure} |
305 |
305 |
306 |
306 |
316 \tdx{PlusI_inrL} [| A type; b = d : B |] ==> inr(b) = inr(d) : A+B |
316 \tdx{PlusI_inrL} [| A type; b = d : B |] ==> inr(b) = inr(d) : A+B |
317 |
317 |
318 \tdx{PlusE} [| p: A+B; |
318 \tdx{PlusE} [| p: A+B; |
319 !!x. x:A ==> c(x): C(inl(x)); |
319 !!x. x:A ==> c(x): C(inl(x)); |
320 !!y. y:B ==> d(y): C(inr(y)) |
320 !!y. y:B ==> d(y): C(inr(y)) |
321 |] ==> when(p, \%x.c(x), \%y.d(y)) : C(p) |
321 |] ==> when(p, \%x. c(x), \%y. d(y)) : C(p) |
322 |
322 |
323 \tdx{PlusEL} [| p = q : A+B; |
323 \tdx{PlusEL} [| p = q : A+B; |
324 !!x. x: A ==> c(x) = e(x) : C(inl(x)); |
324 !!x. x: A ==> c(x) = e(x) : C(inl(x)); |
325 !!y. y: B ==> d(y) = f(y) : C(inr(y)) |
325 !!y. y: B ==> d(y) = f(y) : C(inr(y)) |
326 |] ==> when(p, \%x.c(x), \%y.d(y)) = |
326 |] ==> when(p, \%x. c(x), \%y. d(y)) = |
327 when(q, \%x.e(x), \%y.f(y)) : C(p) |
327 when(q, \%x. e(x), \%y. f(y)) : C(p) |
328 |
328 |
329 \tdx{PlusC_inl} [| a: A; |
329 \tdx{PlusC_inl} [| a: A; |
330 !!x. x:A ==> c(x): C(inl(x)); |
330 !!x. x:A ==> c(x): C(inl(x)); |
331 !!y. y:B ==> d(y): C(inr(y)) |
331 !!y. y:B ==> d(y): C(inr(y)) |
332 |] ==> when(inl(a), \%x.c(x), \%y.d(y)) = c(a) : C(inl(a)) |
332 |] ==> when(inl(a), \%x. c(x), \%y. d(y)) = c(a) : C(inl(a)) |
333 |
333 |
334 \tdx{PlusC_inr} [| b: B; |
334 \tdx{PlusC_inr} [| b: B; |
335 !!x. x:A ==> c(x): C(inl(x)); |
335 !!x. x:A ==> c(x): C(inl(x)); |
336 !!y. y:B ==> d(y): C(inr(y)) |
336 !!y. y:B ==> d(y): C(inr(y)) |
337 |] ==> when(inr(b), \%x.c(x), \%y.d(y)) = d(b) : C(inr(b)) |
337 |] ==> when(inr(b), \%x. c(x), \%y. d(y)) = d(b) : C(inr(b)) |
338 \end{ttbox} |
338 \end{ttbox} |
339 \caption{Rules for the binary sum type $A+B$} \label{ctt-plus} |
339 \caption{Rules for the binary sum type $A+B$} \label{ctt-plus} |
340 \end{figure} |
340 \end{figure} |
341 |
341 |
342 |
342 |
656 \tt - & $[i,i]\To i$ & Left 65 & subtraction\\ |
656 \tt - & $[i,i]\To i$ & Left 65 & subtraction\\ |
657 \verb'|-|' & $[i,i]\To i$ & Left 65 & absolute difference |
657 \verb'|-|' & $[i,i]\To i$ & Left 65 & absolute difference |
658 \end{constants} |
658 \end{constants} |
659 |
659 |
660 \begin{ttbox} |
660 \begin{ttbox} |
661 \tdx{add_def} a#+b == rec(a, b, \%u v.succ(v)) |
661 \tdx{add_def} a#+b == rec(a, b, \%u v. succ(v)) |
662 \tdx{diff_def} a-b == rec(b, a, \%u v.rec(v, 0, \%x y.x)) |
662 \tdx{diff_def} a-b == rec(b, a, \%u v. rec(v, 0, \%x y. x)) |
663 \tdx{absdiff_def} a|-|b == (a-b) #+ (b-a) |
663 \tdx{absdiff_def} a|-|b == (a-b) #+ (b-a) |
664 \tdx{mult_def} a#*b == rec(a, 0, \%u v. b #+ v) |
664 \tdx{mult_def} a#*b == rec(a, 0, \%u v. b #+ v) |
665 |
665 |
666 \tdx{mod_def} a mod b == |
666 \tdx{mod_def} a mod b == |
667 rec(a, 0, \%u v. rec(succ(v) |-| b, 0, \%x y.succ(v))) |
667 rec(a, 0, \%u v. rec(succ(v) |-| b, 0, \%x y. succ(v))) |
668 |
668 |
669 \tdx{div_def} a div b == |
669 \tdx{div_def} a div b == |
670 rec(a, 0, \%u v. rec(succ(u) mod b, succ(v), \%x y.v)) |
670 rec(a, 0, \%u v. rec(succ(u) mod b, succ(v), \%x y. v)) |
671 |
671 |
672 \tdx{add_typing} [| a:N; b:N |] ==> a #+ b : N |
672 \tdx{add_typing} [| a:N; b:N |] ==> a #+ b : N |
673 \tdx{addC0} b:N ==> 0 #+ b = b : N |
673 \tdx{addC0} b:N ==> 0 #+ b = b : N |
674 \tdx{addC_succ} [| a:N; b:N |] ==> succ(a) #+ b = succ(a #+ b) : N |
674 \tdx{addC_succ} [| a:N; b:N |] ==> succ(a) #+ b = succ(a #+ b) : N |
675 |
675 |
712 and~\verb'div' stand for sum, difference, absolute difference, product, |
712 and~\verb'div' stand for sum, difference, absolute difference, product, |
713 remainder and quotient, respectively. Since Type Theory has only primitive |
713 remainder and quotient, respectively. Since Type Theory has only primitive |
714 recursion, some of their definitions may be obscure. |
714 recursion, some of their definitions may be obscure. |
715 |
715 |
716 The difference~$a-b$ is computed by taking $b$ predecessors of~$a$, where |
716 The difference~$a-b$ is computed by taking $b$ predecessors of~$a$, where |
717 the predecessor function is $\lambda v. {\tt rec}(v, 0, \lambda x\,y.x)$. |
717 the predecessor function is $\lambda v. {\tt rec}(v, 0, \lambda x\,y. x)$. |
718 |
718 |
719 The remainder $a\bmod b$ counts up to~$a$ in a cyclic fashion, using 0 |
719 The remainder $a\bmod b$ counts up to~$a$ in a cyclic fashion, using 0 |
720 as the successor of~$b-1$. Absolute difference is used to test the |
720 as the successor of~$b-1$. Absolute difference is used to test the |
721 equality $succ(v)=b$. |
721 equality $succ(v)=b$. |
722 |
722 |