doc-src/Logics/CTT.tex
changeset 5151 1e944fe5ce96
parent 3136 7d940ceb25b5
child 6072 5583261db33d
equal deleted inserted replaced
5150:6e2e9b92c301 5151:1e944fe5ce96
   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 
   456 roughly equivalent to~{\tt SumE} with the advantage of creating no
   456 roughly equivalent to~{\tt SumE} with the advantage of creating no
   457 parameters.  Section~\ref{ctt-choice} below demonstrates these rules in a
   457 parameters.  Section~\ref{ctt-choice} below demonstrates these rules in a
   458 proof of the Axiom of Choice.
   458 proof of the Axiom of Choice.
   459 
   459 
   460 All the rules are given in $\eta$-expanded form.  For instance, every
   460 All the rules are given in $\eta$-expanded form.  For instance, every
   461 occurrence of $\lambda u\,v.b(u,v)$ could be abbreviated to~$b$ in the
   461 occurrence of $\lambda u\,v. b(u,v)$ could be abbreviated to~$b$ in the
   462 rules for~$N$.  The expanded form permits Isabelle to preserve bound
   462 rules for~$N$.  The expanded form permits Isabelle to preserve bound
   463 variable names during backward proof.  Names of bound variables in the
   463 variable names during backward proof.  Names of bound variables in the
   464 conclusion (here, $u$ and~$v$) are matched with corresponding bound
   464 conclusion (here, $u$ and~$v$) are matched with corresponding bound
   465 variables in the premises.
   465 variables in the premises.
   466 
   466 
   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 
   749 is a term and $\Var{A}$ is an unknown standing for its type.  The type,
   749 is a term and $\Var{A}$ is an unknown standing for its type.  The type,
   750 initially
   750 initially
   751 unknown, takes shape in the course of the proof.  Our example is the
   751 unknown, takes shape in the course of the proof.  Our example is the
   752 predecessor function on the natural numbers.
   752 predecessor function on the natural numbers.
   753 \begin{ttbox}
   753 \begin{ttbox}
   754 goal CTT.thy "lam n. rec(n, 0, \%x y.x) : ?A";
   754 Goal "lam n. rec(n, 0, \%x y. x) : ?A";
   755 {\out Level 0}
   755 {\out Level 0}
   756 {\out lam n. rec(n,0,\%x y. x) : ?A}
   756 {\out lam n. rec(n,0,\%x y. x) : ?A}
   757 {\out  1. lam n. rec(n,0,\%x y. x) : ?A}
   757 {\out  1. lam n. rec(n,0,\%x y. x) : ?A}
   758 \end{ttbox}
   758 \end{ttbox}
   759 Since the term is a Constructive Type Theory $\lambda$-abstraction (not to
   759 Since the term is a Constructive Type Theory $\lambda$-abstraction (not to
   811 
   811 
   812 Even if the original term is ill-typed, one can infer a type for it, but
   812 Even if the original term is ill-typed, one can infer a type for it, but
   813 unprovable subgoals will be left.  As an exercise, try to prove the
   813 unprovable subgoals will be left.  As an exercise, try to prove the
   814 following invalid goal:
   814 following invalid goal:
   815 \begin{ttbox}
   815 \begin{ttbox}
   816 goal CTT.thy "lam n. rec(n, 0, \%x y.tt) : ?A";
   816 Goal "lam n. rec(n, 0, \%x y. tt) : ?A";
   817 \end{ttbox}
   817 \end{ttbox}
   818 
   818 
   819 
   819 
   820 
   820 
   821 \section{An example of logical reasoning}
   821 \section{An example of logical reasoning}
   841           p\in \sum@{x\in A} B(x)+C(x)} 
   841           p\in \sum@{x\in A} B(x)+C(x)} 
   842 \]
   842 \]
   843 To begin, we bind the rule's premises --- returned by the~{\tt goal}
   843 To begin, we bind the rule's premises --- returned by the~{\tt goal}
   844 command --- to the {\ML} variable~{\tt prems}.
   844 command --- to the {\ML} variable~{\tt prems}.
   845 \begin{ttbox}
   845 \begin{ttbox}
   846 val prems = goal CTT.thy
   846 val prems = Goal
   847     "[| A type;                       \ttback
   847     "[| A type;                       \ttback
   848 \ttback       !!x. x:A ==> B(x) type;       \ttback
   848 \ttback       !!x. x:A ==> B(x) type;       \ttback
   849 \ttback       !!x. x:A ==> C(x) type;       \ttback
   849 \ttback       !!x. x:A ==> C(x) type;       \ttback
   850 \ttback       p: SUM x:A. B(x) + C(x)       \ttback
   850 \ttback       p: SUM x:A. B(x) + C(x)       \ttback
   851 \ttback    |] ==>  ?a : (SUM x:A. B(x)) + (SUM x:A. C(x))";
   851 \ttback    |] ==>  ?a : (SUM x:A. B(x)) + (SUM x:A. C(x))";
   992 $\Sigma(A,B)$.  The goal is expressed using \hbox{\tt PROD f} to ensure
   992 $\Sigma(A,B)$.  The goal is expressed using \hbox{\tt PROD f} to ensure
   993 that the parameter corresponding to the functional's argument is really
   993 that the parameter corresponding to the functional's argument is really
   994 called~$f$; Isabelle echoes the type using \verb|-->| because there is no
   994 called~$f$; Isabelle echoes the type using \verb|-->| because there is no
   995 explicit dependence upon~$f$.
   995 explicit dependence upon~$f$.
   996 \begin{ttbox}
   996 \begin{ttbox}
   997 val prems = goal CTT.thy
   997 val prems = Goal
   998     "[| A type; !!x. x:A ==> B(x) type;                           \ttback
   998     "[| A type; !!x. x:A ==> B(x) type;                           \ttback
   999 \ttback               !!z. z: (SUM x:A. B(x)) ==> C(z) type             \ttback
   999 \ttback               !!z. z: (SUM x:A. B(x)) ==> C(z) type             \ttback
  1000 \ttback    |] ==> ?a : PROD f: (PROD z : (SUM x:A . B(x)) . C(z)).      \ttback
  1000 \ttback    |] ==> ?a : PROD f: (PROD z : (SUM x:A . B(x)) . C(z)).      \ttback
  1001 \ttback                     (PROD x:A . PROD y:B(x) . C(<x,y>))";
  1001 \ttback                     (PROD x:A . PROD y:B(x) . C(<x,y>))";
  1002 \ttbreak
  1002 \ttbreak
  1072 countless ways, yielding many higher-order unifiers.  The proof can get
  1072 countless ways, yielding many higher-order unifiers.  The proof can get
  1073 bogged down in the details.  But with a careful selection of derived rules
  1073 bogged down in the details.  But with a careful selection of derived rules
  1074 (recall Fig.\ts\ref{ctt-derived}) and the type checking tactics, we can
  1074 (recall Fig.\ts\ref{ctt-derived}) and the type checking tactics, we can
  1075 prove the theorem in nine steps.
  1075 prove the theorem in nine steps.
  1076 \begin{ttbox}
  1076 \begin{ttbox}
  1077 val prems = goal CTT.thy
  1077 val prems = Goal
  1078     "[| A type;  !!x. x:A ==> B(x) type;                    \ttback
  1078     "[| A type;  !!x. x:A ==> B(x) type;                    \ttback
  1079 \ttback       !!x y.[| x:A;  y:B(x) |] ==> C(x,y) type            \ttback
  1079 \ttback       !!x y.[| x:A;  y:B(x) |] ==> C(x,y) type            \ttback
  1080 \ttback    |] ==> ?a : PROD h: (PROD x:A. SUM y:B(x). C(x,y)).    \ttback
  1080 \ttback    |] ==> ?a : PROD h: (PROD x:A. SUM y:B(x). C(x,y)).    \ttback
  1081 \ttback                     (SUM f: (PROD x:A. B(x)). PROD x:A. C(x, f`x))";
  1081 \ttback                     (SUM f: (PROD x:A. B(x)). PROD x:A. C(x, f`x))";
  1082 {\out Level 0}
  1082 {\out Level 0}