doc-src/Logics/CTT.tex
author wenzelm
Tue, 13 Jun 2006 23:41:39 +0200
changeset 19876 11d447d5d68c
parent 12679 8ed660138f83
child 42637 381fdcab0f36
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     1
%% $Id$
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     2
\chapter{Constructive Type Theory}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
     3
\index{Constructive Type Theory|(}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
     4
7159
b009afd1ace5 \underscoreoff needed because of \underscoreon in previous file
paulson
parents: 6170
diff changeset
     5
\underscoreoff %this file contains _ in rule names
b009afd1ace5 \underscoreoff needed because of \underscoreon in previous file
paulson
parents: 6170
diff changeset
     6
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     7
Martin-L\"of's Constructive Type Theory \cite{martinlof84,nordstrom90} can
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     8
be viewed at many different levels.  It is a formal system that embodies
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     9
the principles of intuitionistic mathematics; it embodies the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    10
interpretation of propositions as types; it is a vehicle for deriving
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    11
programs from proofs.  
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    12
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    13
Thompson's book~\cite{thompson91} gives a readable and thorough account of
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    14
Type Theory.  Nuprl is an elaborate implementation~\cite{constable86}.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    15
{\sc alf} is a more recent tool that allows proof terms to be edited
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    16
directly~\cite{alf}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    17
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    18
Isabelle's original formulation of Type Theory was a kind of sequent
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    19
calculus, following Martin-L\"of~\cite{martinlof84}.  It included rules for
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    20
building the context, namely variable bindings with their types.  A typical
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    21
judgement was
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    22
\[   a(x@1,\ldots,x@n)\in A(x@1,\ldots,x@n) \; 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    23
    [ x@1\in A@1, x@2\in A@2(x@1), \ldots, x@n\in A@n(x@1,\ldots,x@{n-1}) ]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    24
\]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    25
This sequent calculus was not satisfactory because assumptions like
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    26
`suppose $A$ is a type' or `suppose $B(x)$ is a type for all $x$ in $A$'
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    27
could not be formalized.  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    28
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    29
The theory~\thydx{CTT} implements Constructive Type Theory, using
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    30
natural deduction.  The judgement above is expressed using $\Forall$ and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    31
$\Imp$:
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    32
\[ \begin{array}{r@{}l}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    33
     \Forall x@1\ldots x@n. &
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
    34
          \List{x@1\in A@1; 
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
    35
                x@2\in A@2(x@1); \cdots \; 
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
    36
                x@n\in A@n(x@1,\ldots,x@{n-1})} \Imp \\
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    37
     &  \qquad\qquad a(x@1,\ldots,x@n)\in A(x@1,\ldots,x@n) 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    38
    \end{array}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    39
\]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    40
Assumptions can use all the judgement forms, for instance to express that
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    41
$B$ is a family of types over~$A$:
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    42
\[ \Forall x . x\in A \Imp B(x)\;{\rm type} \]
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    43
To justify the CTT formulation it is probably best to appeal directly to the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    44
semantic explanations of the rules~\cite{martinlof84}, rather than to the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    45
rules themselves.  The order of assumptions no longer matters, unlike in
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    46
standard Type Theory.  Contexts, which are typical of many modern type
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    47
theories, are difficult to represent in Isabelle.  In particular, it is
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    48
difficult to enforce that all the variables in a context are distinct.
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    49
\index{assumptions!in CTT}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    50
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    51
The theory does not use polymorphism.  Terms in CTT have type~\tydx{i}, the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    52
type of individuals.  Types in CTT have type~\tydx{t}.
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    53
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    54
\begin{figure} \tabcolsep=1em  %wider spacing in tables
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    55
\begin{center}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    56
\begin{tabular}{rrr} 
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    57
  \it name      & \it meta-type         & \it description \\ 
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    58
  \cdx{Type}    & $t \to prop$          & judgement form \\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    59
  \cdx{Eqtype}  & $[t,t]\to prop$       & judgement form\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    60
  \cdx{Elem}    & $[i, t]\to prop$      & judgement form\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    61
  \cdx{Eqelem}  & $[i, i, t]\to prop$   & judgement form\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    62
  \cdx{Reduce}  & $[i, i]\to prop$      & extra judgement form\\[2ex]
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    63
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    64
  \cdx{N}       &     $t$               & natural numbers type\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    65
  \cdx{0}       &     $i$               & constructor\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    66
  \cdx{succ}    & $i\to i$              & constructor\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    67
  \cdx{rec}     & $[i,i,[i,i]\to i]\to i$       & eliminator\\[2ex]
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    68
  \cdx{Prod}    & $[t,i\to t]\to t$     & general product type\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    69
  \cdx{lambda}  & $(i\to i)\to i$       & constructor\\[2ex]
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    70
  \cdx{Sum}     & $[t, i\to t]\to t$    & general sum type\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    71
  \cdx{pair}    & $[i,i]\to i$          & constructor\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    72
  \cdx{split}   & $[i,[i,i]\to i]\to i$ & eliminator\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    73
  \cdx{fst} \cdx{snd} & $i\to i$        & projections\\[2ex]
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    74
  \cdx{inl} \cdx{inr} & $i\to i$        & constructors for $+$\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    75
  \cdx{when}    & $[i,i\to i, i\to i]\to i$    & eliminator for $+$\\[2ex]
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    76
  \cdx{Eq}      & $[t,i,i]\to t$        & equality type\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    77
  \cdx{eq}      & $i$                   & constructor\\[2ex]
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    78
  \cdx{F}       & $t$                   & empty type\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    79
  \cdx{contr}   & $i\to i$              & eliminator\\[2ex]
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    80
  \cdx{T}       & $t$                   & singleton type\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    81
  \cdx{tt}      & $i$                   & constructor
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    82
\end{tabular}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    83
\end{center}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    84
\caption{The constants of CTT} \label{ctt-constants}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    85
\end{figure}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    86
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
    87
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    88
CTT supports all of Type Theory apart from list types, well-ordering types,
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    89
and universes.  Universes could be introduced {\em\`a la Tarski}, adding new
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    90
constants as names for types.  The formulation {\em\`a la Russell}, where
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    91
types denote themselves, is only possible if we identify the meta-types~{\tt
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    92
  i} and~{\tt t}.  Most published formulations of well-ordering types have
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    93
difficulties involving extensionality of functions; I suggest that you use
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    94
some other method for defining recursive types.  List types are easy to
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    95
introduce by declaring new rules.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    96
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    97
CTT uses the 1982 version of Type Theory, with extensional equality.  The
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    98
computation $a=b\in A$ and the equality $c\in Eq(A,a,b)$ are interchangeable.
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
    99
Its rewriting tactics prove theorems of the form $a=b\in A$.  It could be
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   100
modified to have intensional equality, but rewriting tactics would have to
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   101
prove theorems of the form $c\in Eq(A,a,b)$ and the computation rules might
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   102
require a separate simplifier.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   103
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   105
\begin{figure} \tabcolsep=1em  %wider spacing in tables
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   106
\index{lambda abs@$\lambda$-abstractions!in CTT}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   107
\begin{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   108
\begin{tabular}{llrrr} 
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   109
  \it symbol &\it name     &\it meta-type & \it priority & \it description \\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   110
  \sdx{lam} & \cdx{lambda}  & $(i\To o)\To i$ & 10 & $\lambda$-abstraction
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   111
\end{tabular}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   112
\end{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   113
\subcaption{Binders} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   114
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   115
\begin{center}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   116
\index{*"` symbol}\index{function applications!in CTT}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   117
\index{*"+ symbol}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   118
\begin{tabular}{rrrr} 
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   119
  \it symbol & \it meta-type    & \it priority & \it description \\ 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   120
  \tt `         & $[i,i]\to i$  & Left 55       & function application\\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   121
  \tt +         & $[t,t]\to t$  & Right 30      & sum of two types
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   122
\end{tabular}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   123
\end{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   124
\subcaption{Infixes}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   125
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   126
\index{*"* symbol}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   127
\index{*"-"-"> symbol}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   128
\begin{center} \tt\frenchspacing
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   129
\begin{tabular}{rrr} 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   130
  \it external                  & \it internal  & \it standard notation \\ 
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   131
  \sdx{PROD} $x$:$A$ . $B[x]$   &  Prod($A$, $\lambda x. B[x]$) &
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   132
        \rm product $\prod@{x\in A}B[x]$ \\
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   133
  \sdx{SUM} $x$:$A$ . $B[x]$    & Sum($A$, $\lambda x. B[x]$) &
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   134
        \rm sum $\sum@{x\in A}B[x]$ \\
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   135
  $A$ --> $B$     &  Prod($A$, $\lambda x. B$) &
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   136
        \rm function space $A\to B$ \\
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   137
  $A$ * $B$       &  Sum($A$, $\lambda x. B$)  &
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   138
        \rm binary product $A\times B$
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   139
\end{tabular}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   140
\end{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   141
\subcaption{Translations} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   142
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   143
\index{*"= symbol}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   144
\begin{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   145
\dquotes
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   146
\[ \begin{array}{rcl}
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   147
prop    & = &  type " type"       \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   148
        & | & type " = " type     \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   149
        & | & term " : " type        \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   150
        & | & term " = " term " : " type 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   151
\\[2ex]
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   152
type    & = & \hbox{expression of type~$t$} \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   153
        & | & "PROD~" id " : " type " . " type  \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   154
        & | & "SUM~~" id " : " type " . " type 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   155
\\[2ex]
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   156
term    & = & \hbox{expression of type~$i$} \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   157
        & | & "lam " id~id^* " . " term   \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   158
        & | & "< " term " , " term " >"
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   159
\end{array} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   160
\]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   161
\end{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   162
\subcaption{Grammar}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   163
\caption{Syntax of CTT} \label{ctt-syntax}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   164
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   165
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   166
%%%%\section{Generic Packages}  typedsimp.ML????????????????
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   167
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   168
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   169
\section{Syntax}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   170
The constants are shown in Fig.\ts\ref{ctt-constants}.  The infixes include
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   171
the function application operator (sometimes called `apply'), and the 2-place
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   172
type operators.  Note that meta-level abstraction and application, $\lambda
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   173
x.b$ and $f(a)$, differ from object-level abstraction and application,
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   174
\hbox{\tt lam $x$. $b$} and $b{\tt`}a$.  A CTT function~$f$ is simply an
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   175
individual as far as Isabelle is concerned: its Isabelle type is~$i$, not say
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   176
$i\To i$.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   177
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   178
The notation for~CTT (Fig.\ts\ref{ctt-syntax}) is based on that of Nordstr\"om
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   179
et al.~\cite{nordstrom90}.  The empty type is called $F$ and the one-element
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   180
type is $T$; other finite types are built as $T+T+T$, etc.
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   181
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   182
\index{*SUM symbol}\index{*PROD symbol}
6072
5583261db33d removal of FOL, ZF to a separate manual
paulson
parents: 5151
diff changeset
   183
Quantification is expressed by sums $\sum@{x\in A}B[x]$ and
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   184
products $\prod@{x\in A}B[x]$.  Instead of {\tt Sum($A$,$B$)} and {\tt
6072
5583261db33d removal of FOL, ZF to a separate manual
paulson
parents: 5151
diff changeset
   185
  Prod($A$,$B$)} we may write \hbox{\tt SUM $x$:$A$.\ $B[x]$} and \hbox{\tt
5583261db33d removal of FOL, ZF to a separate manual
paulson
parents: 5151
diff changeset
   186
  PROD $x$:$A$.\ $B[x]$}.  For example, we may write
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   187
\begin{ttbox}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   188
SUM y:B. PROD x:A. C(x,y)   {\rm for}   Sum(B, \%y. Prod(A, \%x. C(x,y)))
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   189
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   190
The special cases as \hbox{\tt$A$*$B$} and \hbox{\tt$A$-->$B$} abbreviate
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   191
general sums and products over a constant family.\footnote{Unlike normal
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   192
infix operators, {\tt*} and {\tt-->} merely define abbreviations; there are
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   193
no constants~{\tt op~*} and~\hbox{\tt op~-->}.}  Isabelle accepts these
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   194
abbreviations in parsing and uses them whenever possible for printing.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   195
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   196
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   197
\begin{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   198
\begin{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   199
\tdx{refl_type}         A type ==> A = A
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   200
\tdx{refl_elem}         a : A ==> a = a : A
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   201
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   202
\tdx{sym_type}          A = B ==> B = A
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   203
\tdx{sym_elem}          a = b : A ==> b = a : A
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   204
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   205
\tdx{trans_type}        [| A = B;  B = C |] ==> A = C
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   206
\tdx{trans_elem}        [| a = b : A;  b = c : A |] ==> a = c : A
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   207
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   208
\tdx{equal_types}       [| a : A;  A = B |] ==> a : B
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   209
\tdx{equal_typesL}      [| a = b : A;  A = B |] ==> a = b : B
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   210
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   211
\tdx{subst_type}        [| a : A;  !!z. z:A ==> B(z) type |] ==> B(a) type
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   212
\tdx{subst_typeL}       [| a = c : A;  !!z. z:A ==> B(z) = D(z) 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   213
                  |] ==> B(a) = D(c)
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   214
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   215
\tdx{subst_elem}        [| a : A;  !!z. z:A ==> b(z):B(z) |] ==> b(a):B(a)
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   216
\tdx{subst_elemL}       [| a = c : A;  !!z. z:A ==> b(z) = d(z) : B(z) 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   217
                  |] ==> b(a) = d(c) : B(a)
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   218
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   219
\tdx{refl_red}          Reduce(a,a)
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   220
\tdx{red_if_equal}      a = b : A ==> Reduce(a,b)
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   221
\tdx{trans_red}         [| a = b : A;  Reduce(b,c) |] ==> a = c : A
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   222
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   223
\caption{General equality rules} \label{ctt-equality}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   224
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   225
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   226
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   227
\begin{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   228
\begin{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   229
\tdx{NF}        N type
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   230
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   231
\tdx{NI0}       0 : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   232
\tdx{NI_succ}   a : N ==> succ(a) : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   233
\tdx{NI_succL}  a = b : N ==> succ(a) = succ(b) : N
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   234
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   235
\tdx{NE}        [| p: N;  a: C(0);  
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   236
             !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) 
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   237
          |] ==> rec(p, a, \%u v. b(u,v)) : C(p)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   238
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   239
\tdx{NEL}       [| p = q : N;  a = c : C(0);  
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   240
             !!u v. [| u: N; v: C(u) |] ==> b(u,v)=d(u,v): C(succ(u))
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   241
          |] ==> rec(p, a, \%u v. b(u,v)) = rec(q,c,d) : C(p)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   242
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   243
\tdx{NC0}       [| a: C(0);  
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   244
             !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u))
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   245
          |] ==> rec(0, a, \%u v. b(u,v)) = a : C(0)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   246
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   247
\tdx{NC_succ}   [| p: N;  a: C(0);  
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   248
             !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) 
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   249
          |] ==> rec(succ(p), a, \%u v. b(u,v)) =
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   250
                 b(p, rec(p, a, \%u v. b(u,v))) : C(succ(p))
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   251
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   252
\tdx{zero_ne_succ}      [| a: N;  0 = succ(a) : N |] ==> 0: F
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   253
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   254
\caption{Rules for type~$N$} \label{ctt-N}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   255
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   256
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   257
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   258
\begin{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   259
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   260
\tdx{ProdF}     [| A type; !!x. x:A ==> B(x) type |] ==> PROD x:A. B(x) type
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   261
\tdx{ProdFL}    [| A = C;  !!x. x:A ==> B(x) = D(x) |] ==> 
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   262
          PROD x:A. B(x) = PROD x:C. D(x)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   263
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   264
\tdx{ProdI}     [| A type;  !!x. x:A ==> b(x):B(x)
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   265
          |] ==> lam x. b(x) : PROD x:A. B(x)
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   266
\tdx{ProdIL}    [| A type;  !!x. x:A ==> b(x) = c(x) : B(x)
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   267
          |] ==> lam x. b(x) = lam x. c(x) : PROD x:A. B(x)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   268
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   269
\tdx{ProdE}     [| p : PROD x:A. B(x);  a : A |] ==> p`a : B(a)
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   270
\tdx{ProdEL}    [| p=q: PROD x:A. B(x);  a=b : A |] ==> p`a = q`b : B(a)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   271
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   272
\tdx{ProdC}     [| a : A;  !!x. x:A ==> b(x) : B(x)
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   273
          |] ==> (lam x. b(x)) ` a = b(a) : B(a)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   274
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   275
\tdx{ProdC2}    p : PROD x:A. B(x) ==> (lam x. p`x) = p : PROD x:A. B(x)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   276
\end{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   277
\caption{Rules for the product type $\prod\sb{x\in A}B[x]$} \label{ctt-prod}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   278
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   279
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   280
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   281
\begin{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   282
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   283
\tdx{SumF}      [| A type;  !!x. x:A ==> B(x) type |] ==> SUM x:A. B(x) type
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   284
\tdx{SumFL}     [| A = C;  !!x. x:A ==> B(x) = D(x) 
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   285
          |] ==> SUM x:A. B(x) = SUM x:C. D(x)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   286
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   287
\tdx{SumI}      [| a : A;  b : B(a) |] ==> <a,b> : SUM x:A. B(x)
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   288
\tdx{SumIL}     [| a=c:A;  b=d:B(a) |] ==> <a,b> = <c,d> : SUM x:A. B(x)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   289
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   290
\tdx{SumE}      [| p: SUM x:A. B(x);  
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   291
             !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) 
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   292
          |] ==> split(p, \%x y. c(x,y)) : C(p)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   293
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   294
\tdx{SumEL}     [| p=q : SUM x:A. B(x); 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   295
             !!x y. [| x:A; y:B(x) |] ==> c(x,y)=d(x,y): C(<x,y>)
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   296
          |] ==> split(p, \%x y. c(x,y)) = split(q, \%x y. d(x,y)) : C(p)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   297
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   298
\tdx{SumC}      [| a: A;  b: B(a);
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   299
             !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>)
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   300
          |] ==> split(<a,b>, \%x y. c(x,y)) = c(a,b) : C(<a,b>)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   301
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   302
\tdx{fst_def}   fst(a) == split(a, \%x y. x)
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   303
\tdx{snd_def}   snd(a) == split(a, \%x y. y)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   304
\end{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   305
\caption{Rules for the sum type $\sum\sb{x\in A}B[x]$} \label{ctt-sum}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   306
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   307
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   308
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   309
\begin{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   310
\begin{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   311
\tdx{PlusF}       [| A type;  B type |] ==> A+B type
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   312
\tdx{PlusFL}      [| A = C;  B = D |] ==> A+B = C+D
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   313
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   314
\tdx{PlusI_inl}   [| a : A;  B type |] ==> inl(a) : A+B
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   315
\tdx{PlusI_inlL}  [| a = c : A;  B type |] ==> inl(a) = inl(c) : A+B
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   316
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   317
\tdx{PlusI_inr}   [| A type;  b : B |] ==> inr(b) : A+B
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   318
\tdx{PlusI_inrL}  [| A type;  b = d : B |] ==> inr(b) = inr(d) : A+B
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   319
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   320
\tdx{PlusE}     [| p: A+B;
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   321
             !!x. x:A ==> c(x): C(inl(x));  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   322
             !!y. y:B ==> d(y): C(inr(y))
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   323
          |] ==> when(p, \%x. c(x), \%y. d(y)) : C(p)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   324
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   325
\tdx{PlusEL}    [| p = q : A+B;
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   326
             !!x. x: A ==> c(x) = e(x) : C(inl(x));   
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   327
             !!y. y: B ==> d(y) = f(y) : C(inr(y))
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   328
          |] ==> when(p, \%x. c(x), \%y. d(y)) = 
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   329
                 when(q, \%x. e(x), \%y. f(y)) : C(p)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   330
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   331
\tdx{PlusC_inl} [| a: A;
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   332
             !!x. x:A ==> c(x): C(inl(x));  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   333
             !!y. y:B ==> d(y): C(inr(y))
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   334
          |] ==> when(inl(a), \%x. c(x), \%y. d(y)) = c(a) : C(inl(a))
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   335
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   336
\tdx{PlusC_inr} [| b: B;
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   337
             !!x. x:A ==> c(x): C(inl(x));  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   338
             !!y. y:B ==> d(y): C(inr(y))
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   339
          |] ==> when(inr(b), \%x. c(x), \%y. d(y)) = d(b) : C(inr(b))
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   340
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   341
\caption{Rules for the binary sum type $A+B$} \label{ctt-plus}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   342
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   343
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   344
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   345
\begin{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   346
\begin{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   347
\tdx{FF}        F type
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   348
\tdx{FE}        [| p: F;  C type |] ==> contr(p) : C
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   349
\tdx{FEL}       [| p = q : F;  C type |] ==> contr(p) = contr(q) : C
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   350
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   351
\tdx{TF}        T type
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   352
\tdx{TI}        tt : T
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   353
\tdx{TE}        [| p : T;  c : C(tt) |] ==> c : C(p)
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   354
\tdx{TEL}       [| p = q : T;  c = d : C(tt) |] ==> c = d : C(p)
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   355
\tdx{TC}        p : T ==> p = tt : T)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   356
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   357
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   358
\caption{Rules for types $F$ and $T$} \label{ctt-ft}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   359
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   360
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   361
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   362
\begin{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   363
\begin{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   364
\tdx{EqF}       [| A type;  a : A;  b : A |] ==> Eq(A,a,b) type
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   365
\tdx{EqFL}      [| A=B;  a=c: A;  b=d : A |] ==> Eq(A,a,b) = Eq(B,c,d)
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   366
\tdx{EqI}       a = b : A ==> eq : Eq(A,a,b)
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   367
\tdx{EqE}       p : Eq(A,a,b) ==> a = b : A
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   368
\tdx{EqC}       p : Eq(A,a,b) ==> p = eq : Eq(A,a,b)
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   369
\end{ttbox}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   370
\caption{Rules for the equality type $Eq(A,a,b)$} \label{ctt-eq}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   371
\end{figure}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   372
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   373
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   374
\begin{figure} 
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   375
\begin{ttbox}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   376
\tdx{replace_type}    [| B = A;  a : A |] ==> a : B
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   377
\tdx{subst_eqtyparg}  [| a=c : A;  !!z. z:A ==> B(z) type |] ==> B(a)=B(c)
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   378
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   379
\tdx{subst_prodE}     [| p: Prod(A,B);  a: A;  !!z. z: B(a) ==> c(z): C(z)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   380
                |] ==> c(p`a): C(p`a)
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   381
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   382
\tdx{SumIL2}    [| c=a : A;  d=b : B(a) |] ==> <c,d> = <a,b> : Sum(A,B)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   383
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   384
\tdx{SumE_fst}  p : Sum(A,B) ==> fst(p) : A
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   385
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   386
\tdx{SumE_snd}  [| p: Sum(A,B);  A type;  !!x. x:A ==> B(x) type
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   387
          |] ==> snd(p) : B(fst(p))
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   388
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   389
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   390
\caption{Derived rules for CTT} \label{ctt-derived}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   391
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   392
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   393
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   394
\section{Rules of inference}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   395
The rules obey the following naming conventions.  Type formation rules have
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   396
the suffix~{\tt F}\@.  Introduction rules have the suffix~{\tt I}\@.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   397
Elimination rules have the suffix~{\tt E}\@.  Computation rules, which
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   398
describe the reduction of eliminators, have the suffix~{\tt C}\@.  The
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   399
equality versions of the rules (which permit reductions on subterms) are
333
2ca08f62df33 final Springer copy
lcp
parents: 314
diff changeset
   400
called {\bf long} rules; their names have the suffix~{\tt L}\@.
2ca08f62df33 final Springer copy
lcp
parents: 314
diff changeset
   401
Introduction and computation rules are often further suffixed with
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   402
constructor names.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   403
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   404
Figure~\ref{ctt-equality} presents the equality rules.  Most of them are
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   405
straightforward: reflexivity, symmetry, transitivity and substitution.  The
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   406
judgement \cdx{Reduce} does not belong to Type Theory proper; it has
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   407
been added to implement rewriting.  The judgement ${\tt Reduce}(a,b)$ holds
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   408
when $a=b:A$ holds.  It also holds when $a$ and $b$ are syntactically
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   409
identical, even if they are ill-typed, because rule {\tt refl_red} does
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   410
not verify that $a$ belongs to $A$.  
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   411
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   412
The {\tt Reduce} rules do not give rise to new theorems about the standard
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   413
judgements.  The only rule with {\tt Reduce} in a premise is
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   414
{\tt trans_red}, whose other premise ensures that $a$ and~$b$ (and thus
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   415
$c$) are well-typed.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   416
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   417
Figure~\ref{ctt-N} presents the rules for~$N$, the type of natural numbers.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   418
They include \tdx{zero_ne_succ}, which asserts $0\not=n+1$.  This is
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   419
the fourth Peano axiom and cannot be derived without universes \cite[page
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   420
91]{martinlof84}.  
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   421
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   422
The constant \cdx{rec} constructs proof terms when mathematical
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   423
induction, rule~\tdx{NE}, is applied.  It can also express primitive
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   424
recursion.  Since \cdx{rec} can be applied to higher-order functions,
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   425
it can even express Ackermann's function, which is not primitive recursive
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   426
\cite[page~104]{thompson91}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   427
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   428
Figure~\ref{ctt-prod} shows the rules for general product types, which
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   429
include function types as a special case.  The rules correspond to the
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   430
predicate calculus rules for universal quantifiers and implication.  They
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   431
also permit reasoning about functions, with the rules of a typed
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   432
$\lambda$-calculus.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   433
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   434
Figure~\ref{ctt-sum} shows the rules for general sum types, which
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   435
include binary product types as a special case.  The rules correspond to the
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   436
predicate calculus rules for existential quantifiers and conjunction.  They
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   437
also permit reasoning about ordered pairs, with the projections
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   438
\cdx{fst} and~\cdx{snd}.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   439
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   440
Figure~\ref{ctt-plus} shows the rules for binary sum types.  They
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   441
correspond to the predicate calculus rules for disjunction.  They also
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   442
permit reasoning about disjoint sums, with the injections \cdx{inl}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   443
and~\cdx{inr} and case analysis operator~\cdx{when}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   444
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   445
Figure~\ref{ctt-ft} shows the rules for the empty and unit types, $F$
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   446
and~$T$.  They correspond to the predicate calculus rules for absurdity and
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   447
truth.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   448
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   449
Figure~\ref{ctt-eq} shows the rules for equality types.  If $a=b\in A$ is
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   450
provable then \cdx{eq} is a canonical element of the type $Eq(A,a,b)$,
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   451
and vice versa.  These rules define extensional equality; the most recent
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   452
versions of Type Theory use intensional equality~\cite{nordstrom90}.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   453
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   454
Figure~\ref{ctt-derived} presents the derived rules.  The rule
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   455
\tdx{subst_prodE} is derived from {\tt prodE}, and is easier to use
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   456
in backwards proof.  The rules \tdx{SumE_fst} and \tdx{SumE_snd}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   457
express the typing of~\cdx{fst} and~\cdx{snd}; together, they are
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   458
roughly equivalent to~{\tt SumE} with the advantage of creating no
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   459
parameters.  Section~\ref{ctt-choice} below demonstrates these rules in a
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   460
proof of the Axiom of Choice.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   461
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   462
All the rules are given in $\eta$-expanded form.  For instance, every
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   463
occurrence of $\lambda u\,v. b(u,v)$ could be abbreviated to~$b$ in the
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   464
rules for~$N$.  The expanded form permits Isabelle to preserve bound
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   465
variable names during backward proof.  Names of bound variables in the
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   466
conclusion (here, $u$ and~$v$) are matched with corresponding bound
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   467
variables in the premises.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   468
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   469
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   470
\section{Rule lists}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   471
The Type Theory tactics provide rewriting, type inference, and logical
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   472
reasoning.  Many proof procedures work by repeatedly resolving certain Type
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   473
Theory rules against a proof state.  CTT defines lists --- each with
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   474
type
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   475
\hbox{\tt thm list} --- of related rules. 
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   476
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   477
\item[\ttindexbold{form_rls}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   478
contains formation rules for the types $N$, $\Pi$, $\Sigma$, $+$, $Eq$,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   479
$F$, and $T$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   480
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   481
\item[\ttindexbold{formL_rls}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   482
contains long formation rules for $\Pi$, $\Sigma$, $+$, and $Eq$.  (For
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   483
other types use \tdx{refl_type}.)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   484
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   485
\item[\ttindexbold{intr_rls}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   486
contains introduction rules for the types $N$, $\Pi$, $\Sigma$, $+$, and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   487
$T$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   488
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   489
\item[\ttindexbold{intrL_rls}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   490
contains long introduction rules for $N$, $\Pi$, $\Sigma$, and $+$.  (For
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   491
$T$ use \tdx{refl_elem}.)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   492
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   493
\item[\ttindexbold{elim_rls}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   494
contains elimination rules for the types $N$, $\Pi$, $\Sigma$, $+$, and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   495
$F$.  The rules for $Eq$ and $T$ are omitted because they involve no
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   496
eliminator.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   497
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   498
\item[\ttindexbold{elimL_rls}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   499
contains long elimination rules for $N$, $\Pi$, $\Sigma$, $+$, and $F$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   500
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   501
\item[\ttindexbold{comp_rls}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   502
contains computation rules for the types $N$, $\Pi$, $\Sigma$, and $+$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   503
Those for $Eq$ and $T$ involve no eliminator.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   504
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   505
\item[\ttindexbold{basic_defs}] 
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   506
contains the definitions of {\tt fst} and {\tt snd}.  
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   507
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   508
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   509
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   510
\section{Tactics for subgoal reordering}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   511
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   512
test_assume_tac : int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   513
typechk_tac     : thm list -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   514
equal_tac       : thm list -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   515
intr_tac        : thm list -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   516
\end{ttbox}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   517
Blind application of CTT rules seldom leads to a proof.  The elimination
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   518
rules, especially, create subgoals containing new unknowns.  These subgoals
333
2ca08f62df33 final Springer copy
lcp
parents: 314
diff changeset
   519
unify with anything, creating a huge search space.  The standard tactic
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   520
\ttindex{filt_resolve_tac}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   521
(see \iflabelundefined{filt_resolve_tac}{the {\em Reference Manual\/}}%
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   522
        {\S\ref{filt_resolve_tac}})
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   523
%
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   524
fails for goals that are too flexible; so does the CTT tactic {\tt
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   525
  test_assume_tac}.  Used with the tactical \ttindex{REPEAT_FIRST} they
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   526
achieve a simple kind of subgoal reordering: the less flexible subgoals are
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   527
attempted first.  Do some single step proofs, or study the examples below,
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   528
to see why this is necessary.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   529
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   530
\item[\ttindexbold{test_assume_tac} $i$] 
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   531
uses {\tt assume_tac} to solve the subgoal by assumption, but only if
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   532
subgoal~$i$ has the form $a\in A$ and the head of $a$ is not an unknown.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   533
Otherwise, it fails.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   534
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   535
\item[\ttindexbold{typechk_tac} $thms$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   536
uses $thms$ with formation, introduction, and elimination rules to check
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   537
the typing of constructions.  It is designed to solve goals of the form
975
6c280d1dac35 Corrected faulty reference to Hindley-Milner type inference
lcp
parents: 333
diff changeset
   538
$a\in \Var{A}$, where $a$ is rigid and $\Var{A}$ is flexible; thus it
6c280d1dac35 Corrected faulty reference to Hindley-Milner type inference
lcp
parents: 333
diff changeset
   539
performs type inference.  The tactic can also solve goals of
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   540
the form $A\;\rm type$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   541
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   542
\item[\ttindexbold{equal_tac} $thms$]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   543
uses $thms$ with the long introduction and elimination rules to solve goals
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   544
of the form $a=b\in A$, where $a$ is rigid.  It is intended for deriving
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   545
the long rules for defined constants such as the arithmetic operators.  The
6170
9a59cf8ae9b5 standard spelling: type-checking
paulson
parents: 6072
diff changeset
   546
tactic can also perform type-checking.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   547
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   548
\item[\ttindexbold{intr_tac} $thms$]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   549
uses $thms$ with the introduction rules to break down a type.  It is
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   550
designed for goals like $\Var{a}\in A$ where $\Var{a}$ is flexible and $A$
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   551
rigid.  These typically arise when trying to prove a proposition~$A$,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   552
expressed as a type.
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   553
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   554
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   555
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   556
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   557
\section{Rewriting tactics}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   558
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   559
rew_tac     : thm list -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   560
hyp_rew_tac : thm list -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   561
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   562
Object-level simplification is accomplished through proof, using the {\tt
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   563
  CTT} equality rules and the built-in rewriting functor
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   564
{\tt TSimpFun}.%
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   565
\footnote{This should not be confused with Isabelle's main simplifier; {\tt
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   566
    TSimpFun} is only useful for CTT and similar logics with type inference
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   567
  rules.  At present it is undocumented.}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   568
%
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   569
The rewrites include the computation rules and other equations.  The long
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   570
versions of the other rules permit rewriting of subterms and subtypes.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   571
Also used are transitivity and the extra judgement form \cdx{Reduce}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   572
Meta-level simplification handles only definitional equality.
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   573
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   574
\item[\ttindexbold{rew_tac} $thms$]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   575
applies $thms$ and the computation rules as left-to-right rewrites.  It
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   576
solves the goal $a=b\in A$ by rewriting $a$ to $b$.  If $b$ is an unknown
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   577
then it is assigned the rewritten form of~$a$.  All subgoals are rewritten.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   578
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   579
\item[\ttindexbold{hyp_rew_tac} $thms$]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   580
is like {\tt rew_tac}, but includes as rewrites any equations present in
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   581
the assumptions.
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   582
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   583
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   584
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   585
\section{Tactics for logical reasoning}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   586
Interpreting propositions as types lets CTT express statements of
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   587
intuitionistic logic.  However, Constructive Type Theory is not just another
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   588
syntax for first-order logic.  There are fundamental differences.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   589
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   590
\index{assumptions!in CTT}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   591
Can assumptions be deleted after use?  Not every occurrence of a type
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   592
represents a proposition, and Type Theory assumptions declare variables.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   593
In first-order logic, $\disj$-elimination with the assumption $P\disj Q$
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   594
creates one subgoal assuming $P$ and another assuming $Q$, and $P\disj Q$
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   595
can be deleted safely.  In Type Theory, $+$-elimination with the assumption
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   596
$z\in A+B$ creates one subgoal assuming $x\in A$ and another assuming $y\in
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   597
B$ (for arbitrary $x$ and $y$).  Deleting $z\in A+B$ when other assumptions
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   598
refer to $z$ may render the subgoal unprovable: arguably,
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   599
meaningless.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   600
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   601
Isabelle provides several tactics for predicate calculus reasoning in CTT:
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   602
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   603
mp_tac       : int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   604
add_mp_tac   : int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   605
safestep_tac : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   606
safe_tac     : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   607
step_tac     : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   608
pc_tac       : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   609
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   610
These are loosely based on the intuitionistic proof procedures
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   611
of~\thydx{FOL}.  For the reasons discussed above, a rule that is safe for
6170
9a59cf8ae9b5 standard spelling: type-checking
paulson
parents: 6072
diff changeset
   612
propositional reasoning may be unsafe for type-checking; thus, some of the
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   613
`safe' tactics are misnamed.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   614
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   615
\item[\ttindexbold{mp_tac} $i$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   616
searches in subgoal~$i$ for assumptions of the form $f\in\Pi(A,B)$ and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   617
$a\in A$, where~$A$ may be found by unification.  It replaces
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   618
$f\in\Pi(A,B)$ by $z\in B(a)$, where~$z$ is a new parameter.  The tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   619
can produce multiple outcomes for each suitable pair of assumptions.  In
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   620
short, {\tt mp_tac} performs Modus Ponens among the assumptions.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   621
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   622
\item[\ttindexbold{add_mp_tac} $i$]
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   623
is like {\tt mp_tac}~$i$ but retains the assumption $f\in\Pi(A,B)$.  It
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   624
avoids information loss but obviously loops if repeated.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   625
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   626
\item[\ttindexbold{safestep_tac} $thms$ $i$]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   627
attacks subgoal~$i$ using formation rules and certain other `safe' rules
333
2ca08f62df33 final Springer copy
lcp
parents: 314
diff changeset
   628
(\tdx{FE}, \tdx{ProdI}, \tdx{SumE}, \tdx{PlusE}), calling
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   629
{\tt mp_tac} when appropriate.  It also uses~$thms$,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   630
which are typically premises of the rule being derived.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   631
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   632
\item[\ttindexbold{safe_tac} $thms$ $i$] attempts to solve subgoal~$i$ by
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   633
  means of backtracking, using {\tt safestep_tac}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   634
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   635
\item[\ttindexbold{step_tac} $thms$ $i$]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   636
tries to reduce subgoal~$i$ using {\tt safestep_tac}, then tries unsafe
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   637
rules.  It may produce multiple outcomes.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   638
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   639
\item[\ttindexbold{pc_tac} $thms$ $i$]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   640
tries to solve subgoal~$i$ by backtracking, using {\tt step_tac}.
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   641
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   642
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   643
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   644
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   645
\begin{figure} 
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   646
\index{#+@{\tt\#+} symbol}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   647
\index{*"- symbol}
12679
8ed660138f83 changed the index sort key from |-| to just |- because pdflatex can't cope
paulson
parents: 9695
diff changeset
   648
\index{"|"-@{{\tt"|"-"|} symbol}}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   649
\index{#*@{\tt\#*} symbol}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   650
\index{*div symbol}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   651
\index{*mod symbol}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   652
\begin{constants}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   653
  \it symbol  & \it meta-type & \it priority & \it description \\ 
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   654
  \tt \#*       & $[i,i]\To i$  &  Left 70      & multiplication \\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   655
  \tt div       & $[i,i]\To i$  &  Left 70      & division\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   656
  \tt mod       & $[i,i]\To i$  &  Left 70      & modulus\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   657
  \tt \#+       & $[i,i]\To i$  &  Left 65      & addition\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   658
  \tt -         & $[i,i]\To i$  &  Left 65      & subtraction\\
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   659
  \verb'|-|'    & $[i,i]\To i$  &  Left 65      & absolute difference
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   660
\end{constants}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   661
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   662
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   663
\tdx{add_def}           a#+b  == rec(a, b, \%u v. succ(v))  
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   664
\tdx{diff_def}          a-b   == rec(b, a, \%u v. rec(v, 0, \%x y. x))  
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   665
\tdx{absdiff_def}       a|-|b == (a-b) #+ (b-a)  
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   666
\tdx{mult_def}          a#*b  == rec(a, 0, \%u v. b #+ v)  
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   667
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   668
\tdx{mod_def}           a mod b ==
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   669
                  rec(a, 0, \%u v. rec(succ(v) |-| b, 0, \%x y. succ(v)))
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   670
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   671
\tdx{div_def}           a div b ==
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   672
                  rec(a, 0, \%u v. rec(succ(u) mod b, succ(v), \%x y. v))
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   673
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   674
\tdx{add_typing}        [| a:N;  b:N |] ==> a #+ b : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   675
\tdx{addC0}             b:N ==> 0 #+ b = b : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   676
\tdx{addC_succ}         [| a:N;  b:N |] ==> succ(a) #+ b = succ(a #+ b) : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   677
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   678
\tdx{add_assoc}         [| a:N;  b:N;  c:N |] ==> 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   679
                  (a #+ b) #+ c = a #+ (b #+ c) : N
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   680
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   681
\tdx{add_commute}       [| a:N;  b:N |] ==> a #+ b = b #+ a : N
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   682
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   683
\tdx{mult_typing}       [| a:N;  b:N |] ==> a #* b : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   684
\tdx{multC0}            b:N ==> 0 #* b = 0 : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   685
\tdx{multC_succ}        [| a:N;  b:N |] ==> succ(a) #* b = b #+ (a#*b) : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   686
\tdx{mult_commute}      [| a:N;  b:N |] ==> a #* b = b #* a : N
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   687
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   688
\tdx{add_mult_dist}     [| a:N;  b:N;  c:N |] ==> 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   689
                  (a #+ b) #* c = (a #* c) #+ (b #* c) : N
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   690
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   691
\tdx{mult_assoc}        [| a:N;  b:N;  c:N |] ==> 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   692
                  (a #* b) #* c = a #* (b #* c) : N
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   693
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   694
\tdx{diff_typing}       [| a:N;  b:N |] ==> a - b : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   695
\tdx{diffC0}            a:N ==> a - 0 = a : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   696
\tdx{diff_0_eq_0}       b:N ==> 0 - b = 0 : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   697
\tdx{diff_succ_succ}    [| a:N;  b:N |] ==> succ(a) - succ(b) = a - b : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   698
\tdx{diff_self_eq_0}    a:N ==> a - a = 0 : N
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   699
\tdx{add_inverse_diff}  [| a:N;  b:N;  b-a=0 : N |] ==> b #+ (a-b) = a : N
3136
7d940ceb25b5 fixed caption font;
wenzelm
parents: 3133
diff changeset
   700
\end{ttbox}
3096
ccc2c92bb232 Updated to LaTeX 2e
berghofe
parents: 975
diff changeset
   701
\caption{The theory of arithmetic} \label{ctt_arith}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   702
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   703
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   704
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   705
\section{A theory of arithmetic}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   706
\thydx{Arith} is a theory of elementary arithmetic.  It proves the
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   707
properties of addition, multiplication, subtraction, division, and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   708
remainder, culminating in the theorem
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   709
\[ a \bmod b + (a/b)\times b = a. \]
3096
ccc2c92bb232 Updated to LaTeX 2e
berghofe
parents: 975
diff changeset
   710
Figure~\ref{ctt_arith} presents the definitions and some of the key
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   711
theorems, including commutative, distributive, and associative laws.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   712
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   713
The operators~\verb'#+', \verb'-', \verb'|-|', \verb'#*', \verb'mod'
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   714
and~\verb'div' stand for sum, difference, absolute difference, product,
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   715
remainder and quotient, respectively.  Since Type Theory has only primitive
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   716
recursion, some of their definitions may be obscure.  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   717
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   718
The difference~$a-b$ is computed by taking $b$ predecessors of~$a$, where
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   719
the predecessor function is $\lambda v. {\tt rec}(v, 0, \lambda x\,y. x)$.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   720
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   721
The remainder $a\bmod b$ counts up to~$a$ in a cyclic fashion, using 0
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   722
as the successor of~$b-1$.  Absolute difference is used to test the
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   723
equality $succ(v)=b$.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   724
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   725
The quotient $a/b$ is computed by adding one for every number $x$
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   726
such that $0\leq x \leq a$ and $x\bmod b = 0$.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   727
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   728
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   729
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   730
\section{The examples directory}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 7159
diff changeset
   731
This directory contains examples and experimental proofs in CTT.
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   732
\begin{ttdescription}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   733
\item[CTT/ex/typechk.ML]
6170
9a59cf8ae9b5 standard spelling: type-checking
paulson
parents: 6072
diff changeset
   734
contains simple examples of type-checking and type deduction.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   735
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   736
\item[CTT/ex/elim.ML]
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   737
contains some examples from Martin-L\"of~\cite{martinlof84}, proved using 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   738
{\tt pc_tac}.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   739
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   740
\item[CTT/ex/equal.ML]
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   741
contains simple examples of rewriting.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   742
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   743
\item[CTT/ex/synth.ML]
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   744
demonstrates the use of unknowns with some trivial examples of program
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   745
synthesis. 
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   746
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   747
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   748
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   749
\section{Example: type inference}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   750
Type inference involves proving a goal of the form $a\in\Var{A}$, where $a$
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   751
is a term and $\Var{A}$ is an unknown standing for its type.  The type,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   752
initially
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   753
unknown, takes shape in the course of the proof.  Our example is the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   754
predecessor function on the natural numbers.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   755
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   756
Goal "lam n. rec(n, 0, \%x y. x) : ?A";
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   757
{\out Level 0}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   758
{\out lam n. rec(n,0,\%x y. x) : ?A}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   759
{\out  1. lam n. rec(n,0,\%x y. x) : ?A}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   760
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   761
Since the term is a Constructive Type Theory $\lambda$-abstraction (not to
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   762
be confused with a meta-level abstraction), we apply the rule
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   763
\tdx{ProdI}, for $\Pi$-introduction.  This instantiates~$\Var{A}$ to a
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   764
product type of unknown domain and range.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   765
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   766
by (resolve_tac [ProdI] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   767
{\out Level 1}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   768
{\out lam n. rec(n,0,\%x y. x) : PROD x:?A1. ?B1(x)}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   769
{\out  1. ?A1 type}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   770
{\out  2. !!n. n : ?A1 ==> rec(n,0,\%x y. x) : ?B1(n)}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   771
\end{ttbox}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   772
Subgoal~1 is too flexible.  It can be solved by instantiating~$\Var{A@1}$
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   773
to any type, but most instantiations will invalidate subgoal~2.  We
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   774
therefore tackle the latter subgoal.  It asks the type of a term beginning
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   775
with {\tt rec}, which can be found by $N$-elimination.%
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   776
\index{*NE theorem}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   777
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   778
by (eresolve_tac [NE] 2);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   779
{\out Level 2}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   780
{\out lam n. rec(n,0,\%x y. x) : PROD x:N. ?C2(x,x)}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   781
{\out  1. N type}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   782
{\out  2. !!n. 0 : ?C2(n,0)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   783
{\out  3. !!n x y. [| x : N; y : ?C2(n,x) |] ==> x : ?C2(n,succ(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   784
\end{ttbox}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   785
Subgoal~1 is no longer flexible: we now know~$\Var{A@1}$ is the type of
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   786
natural numbers.  However, let us continue proving nontrivial subgoals.
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   787
Subgoal~2 asks, what is the type of~0?\index{*NIO theorem}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   788
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   789
by (resolve_tac [NI0] 2);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   790
{\out Level 3}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   791
{\out lam n. rec(n,0,\%x y. x) : N --> N}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   792
{\out  1. N type}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   793
{\out  2. !!n x y. [| x : N; y : N |] ==> x : N}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   794
\end{ttbox}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   795
The type~$\Var{A}$ is now fully determined.  It is the product type
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   796
$\prod@{x\in N}N$, which is shown as the function type $N\to N$ because
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   797
there is no dependence on~$x$.  But we must prove all the subgoals to show
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   798
that the original term is validly typed.  Subgoal~2 is provable by
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   799
assumption and the remaining subgoal falls by $N$-formation.%
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   800
\index{*NF theorem}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   801
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   802
by (assume_tac 2);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   803
{\out Level 4}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   804
{\out lam n. rec(n,0,\%x y. x) : N --> N}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   805
{\out  1. N type}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   806
\ttbreak
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   807
by (resolve_tac [NF] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   808
{\out Level 5}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   809
{\out lam n. rec(n,0,\%x y. x) : N --> N}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   810
{\out No subgoals!}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   811
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   812
Calling \ttindex{typechk_tac} can prove this theorem in one step.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   813
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   814
Even if the original term is ill-typed, one can infer a type for it, but
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   815
unprovable subgoals will be left.  As an exercise, try to prove the
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   816
following invalid goal:
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   817
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   818
Goal "lam n. rec(n, 0, \%x y. tt) : ?A";
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   819
\end{ttbox}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   820
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   821
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   822
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   823
\section{An example of logical reasoning}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   824
Logical reasoning in Type Theory involves proving a goal of the form
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   825
$\Var{a}\in A$, where type $A$ expresses a proposition and $\Var{a}$ stands
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   826
for its proof term, a value of type $A$.  The proof term is initially
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   827
unknown and takes shape during the proof.  
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   828
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   829
Our example expresses a theorem about quantifiers in a sorted logic:
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   830
\[ \infer{(\ex{x\in A}P(x)) \disj (\ex{x\in A}Q(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   831
         {\ex{x\in A}P(x)\disj Q(x)} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   832
\]
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   833
By the propositions-as-types principle, this is encoded
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   834
using~$\Sigma$ and~$+$ types.  A special case of it expresses a
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   835
distributive law of Type Theory: 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   836
\[ \infer{(A\times B) + (A\times C)}{A\times(B+C)} \]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   837
Generalizing this from $\times$ to $\Sigma$, and making the typing
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   838
conditions explicit, yields the rule we must derive:
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   839
\[ \infer{\Var{a} \in (\sum@{x\in A} B(x)) + (\sum@{x\in A} C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   840
         {\hbox{$A$ type} &
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   841
          \infer*{\hbox{$B(x)$ type}}{[x\in A]}  &
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   842
          \infer*{\hbox{$C(x)$ type}}{[x\in A]}  &
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   843
          p\in \sum@{x\in A} B(x)+C(x)} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   844
\]
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   845
To begin, we bind the rule's premises --- returned by the~{\tt goal}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   846
command --- to the {\ML} variable~{\tt prems}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   847
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   848
val prems = Goal
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   849
    "[| A type;                       \ttback
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   850
\ttback       !!x. x:A ==> B(x) type;       \ttback
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   851
\ttback       !!x. x:A ==> C(x) type;       \ttback
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   852
\ttback       p: SUM x:A. B(x) + C(x)       \ttback
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   853
\ttback    |] ==>  ?a : (SUM x:A. B(x)) + (SUM x:A. C(x))";
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   854
{\out Level 0}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   855
{\out ?a : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   856
{\out  1. ?a : (SUM x:A. B(x)) + (SUM x:A. C(x))}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
   857
\ttbreak
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   858
{\out val prems = ["A type  [A type]",}
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   859
{\out              "?x : A ==> B(?x) type  [!!x. x : A ==> B(x) type]",}
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   860
{\out              "?x : A ==> C(?x) type  [!!x. x : A ==> C(x) type]",}
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   861
{\out              "p : SUM x:A. B(x) + C(x)  [p : SUM x:A. B(x) + C(x)]"]}
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   862
{\out             : thm list}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   863
\end{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   864
The last premise involves the sum type~$\Sigma$.  Since it is a premise
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   865
rather than the assumption of a goal, it cannot be found by {\tt
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   866
  eresolve_tac}.  We could insert it (and the other atomic premise) by
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   867
calling
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   868
\begin{ttbox}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   869
cut_facts_tac prems 1;
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   870
\end{ttbox}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   871
A forward proof step is more straightforward here.  Let us resolve the
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   872
$\Sigma$-elimination rule with the premises using~\ttindex{RL}.  This
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   873
inference yields one result, which we supply to {\tt
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   874
  resolve_tac}.\index{*SumE theorem}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   875
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   876
by (resolve_tac (prems RL [SumE]) 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   877
{\out Level 1}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   878
{\out split(p,?c1) : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   879
{\out  1. !!x y.}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   880
{\out        [| x : A; y : B(x) + C(x) |] ==>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   881
{\out        ?c1(x,y) : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   882
\end{ttbox}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   883
The subgoal has two new parameters, $x$ and~$y$.  In the main goal,
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   884
$\Var{a}$ has been instantiated with a \cdx{split} term.  The
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   885
assumption $y\in B(x) + C(x)$ is eliminated next, causing a case split and
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   886
creating the parameter~$xa$.  This inference also inserts~\cdx{when}
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   887
into the main goal.\index{*PlusE theorem}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   888
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   889
by (eresolve_tac [PlusE] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   890
{\out Level 2}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   891
{\out split(p,\%x y. when(y,?c2(x,y),?d2(x,y)))}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   892
{\out : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   893
{\out  1. !!x y xa.}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   894
{\out        [| x : A; xa : B(x) |] ==>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   895
{\out        ?c2(x,y,xa) : (SUM x:A. B(x)) + (SUM x:A. C(x))}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
   896
\ttbreak
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   897
{\out  2. !!x y ya.}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   898
{\out        [| x : A; ya : C(x) |] ==>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   899
{\out        ?d2(x,y,ya) : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   900
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   901
To complete the proof object for the main goal, we need to instantiate the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   902
terms $\Var{c@2}(x,y,xa)$ and $\Var{d@2}(x,y,xa)$.  We attack subgoal~1 by
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   903
a~$+$-introduction rule; since the goal assumes $xa\in B(x)$, we take the left
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   904
injection~(\cdx{inl}).
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   905
\index{*PlusI_inl theorem}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   906
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   907
by (resolve_tac [PlusI_inl] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   908
{\out Level 3}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   909
{\out split(p,\%x y. when(y,\%xa. inl(?a3(x,y,xa)),?d2(x,y)))}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   910
{\out : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   911
{\out  1. !!x y xa. [| x : A; xa : B(x) |] ==> ?a3(x,y,xa) : SUM x:A. B(x)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   912
{\out  2. !!x y xa. [| x : A; xa : B(x) |] ==> SUM x:A. C(x) type}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
   913
\ttbreak
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   914
{\out  3. !!x y ya.}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   915
{\out        [| x : A; ya : C(x) |] ==>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   916
{\out        ?d2(x,y,ya) : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   917
\end{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   918
A new subgoal~2 has appeared, to verify that $\sum@{x\in A}C(x)$ is a type.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   919
Continuing to work on subgoal~1, we apply the $\Sigma$-introduction rule.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   920
This instantiates the term $\Var{a@3}(x,y,xa)$; the main goal now contains
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   921
an ordered pair, whose components are two new unknowns.%
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   922
\index{*SumI theorem}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   923
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   924
by (resolve_tac [SumI] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   925
{\out Level 4}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   926
{\out split(p,\%x y. when(y,\%xa. inl(<?a4(x,y,xa),?b4(x,y,xa)>),?d2(x,y)))}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   927
{\out : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   928
{\out  1. !!x y xa. [| x : A; xa : B(x) |] ==> ?a4(x,y,xa) : A}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   929
{\out  2. !!x y xa. [| x : A; xa : B(x) |] ==> ?b4(x,y,xa) : B(?a4(x,y,xa))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   930
{\out  3. !!x y xa. [| x : A; xa : B(x) |] ==> SUM x:A. C(x) type}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   931
{\out  4. !!x y ya.}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   932
{\out        [| x : A; ya : C(x) |] ==>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   933
{\out        ?d2(x,y,ya) : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   934
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   935
The two new subgoals both hold by assumption.  Observe how the unknowns
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   936
$\Var{a@4}$ and $\Var{b@4}$ are instantiated throughout the proof state.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   937
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   938
by (assume_tac 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   939
{\out Level 5}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   940
{\out split(p,\%x y. when(y,\%xa. inl(<x,?b4(x,y,xa)>),?d2(x,y)))}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   941
{\out : (SUM x:A. B(x)) + (SUM x:A. C(x))}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   942
\ttbreak
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   943
{\out  1. !!x y xa. [| x : A; xa : B(x) |] ==> ?b4(x,y,xa) : B(x)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   944
{\out  2. !!x y xa. [| x : A; xa : B(x) |] ==> SUM x:A. C(x) type}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   945
{\out  3. !!x y ya.}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   946
{\out        [| x : A; ya : C(x) |] ==>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   947
{\out        ?d2(x,y,ya) : (SUM x:A. B(x)) + (SUM x:A. C(x))}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   948
\ttbreak
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   949
by (assume_tac 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   950
{\out Level 6}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   951
{\out split(p,\%x y. when(y,\%xa. inl(<x,xa>),?d2(x,y)))}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   952
{\out : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   953
{\out  1. !!x y xa. [| x : A; xa : B(x) |] ==> SUM x:A. C(x) type}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   954
{\out  2. !!x y ya.}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   955
{\out        [| x : A; ya : C(x) |] ==>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   956
{\out        ?d2(x,y,ya) : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   957
\end{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   958
Subgoal~1 is an example of a well-formedness subgoal~\cite{constable86}.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   959
Such subgoals are usually trivial; this one yields to
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   960
\ttindex{typechk_tac}, given the current list of premises.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   961
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   962
by (typechk_tac prems);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   963
{\out Level 7}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   964
{\out split(p,\%x y. when(y,\%xa. inl(<x,xa>),?d2(x,y)))}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   965
{\out : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   966
{\out  1. !!x y ya.}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   967
{\out        [| x : A; ya : C(x) |] ==>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   968
{\out        ?d2(x,y,ya) : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   969
\end{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   970
This subgoal is the other case from the $+$-elimination above, and can be
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   971
proved similarly.  Quicker is to apply \ttindex{pc_tac}.  The main goal
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   972
finally gets a fully instantiated proof object.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   973
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   974
by (pc_tac prems 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   975
{\out Level 8}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   976
{\out split(p,\%x y. when(y,\%xa. inl(<x,xa>),\%y. inr(<x,y>)))}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   977
{\out : (SUM x:A. B(x)) + (SUM x:A. C(x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   978
{\out No subgoals!}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   979
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   980
Calling \ttindex{pc_tac} after the first $\Sigma$-elimination above also
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   981
proves this theorem.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   982
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   983
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   984
\section{Example: deriving a currying functional}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   985
In simply-typed languages such as {\ML}, a currying functional has the type 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   986
\[ (A\times B \to C) \to (A\to (B\to C)). \]
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
   987
Let us generalize this to the dependent types~$\Sigma$ and~$\Pi$.  
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   988
The functional takes a function~$f$ that maps $z:\Sigma(A,B)$
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   989
to~$C(z)$; the resulting function maps $x\in A$ and $y\in B(x)$ to
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   990
$C(\langle x,y\rangle)$.
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   991
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   992
Formally, there are three typing premises.  $A$ is a type; $B$ is an
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   993
$A$-indexed family of types; $C$ is a family of types indexed by
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   994
$\Sigma(A,B)$.  The goal is expressed using \hbox{\tt PROD f} to ensure
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   995
that the parameter corresponding to the functional's argument is really
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   996
called~$f$; Isabelle echoes the type using \verb|-->| because there is no
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
   997
explicit dependence upon~$f$.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   998
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
   999
val prems = Goal
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1000
    "[| A type; !!x. x:A ==> B(x) type;                           \ttback
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1001
\ttback               !!z. z: (SUM x:A. B(x)) ==> C(z) type             \ttback
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1002
\ttback    |] ==> ?a : PROD f: (PROD z : (SUM x:A . B(x)) . C(z)).      \ttback
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1003
\ttback                     (PROD x:A . PROD y:B(x) . C(<x,y>))";
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1004
\ttbreak
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1005
{\out Level 0}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1006
{\out ?a : (PROD z:SUM x:A. B(x). C(z)) -->}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1007
{\out      (PROD x:A. PROD y:B(x). C(<x,y>))}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1008
{\out  1. ?a : (PROD z:SUM x:A. B(x). C(z)) -->}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1009
{\out          (PROD x:A. PROD y:B(x). C(<x,y>))}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1010
\ttbreak
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1011
{\out val prems = ["A type  [A type]",}
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1012
{\out              "?x : A ==> B(?x) type  [!!x. x : A ==> B(x) type]",}
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1013
{\out              "?z : SUM x:A. B(x) ==> C(?z) type}
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1014
{\out               [!!z. z : SUM x:A. B(x) ==> C(z) type]"] : thm list}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1015
\end{ttbox}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1016
This is a chance to demonstrate \ttindex{intr_tac}.  Here, the tactic
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1017
repeatedly applies $\Pi$-introduction and proves the rather
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1018
tiresome typing conditions.  
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1019
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1020
Note that $\Var{a}$ becomes instantiated to three nested
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1021
$\lambda$-abstractions.  It would be easier to read if the bound variable
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1022
names agreed with the parameters in the subgoal.  Isabelle attempts to give
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1023
parameters the same names as corresponding bound variables in the goal, but
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1024
this does not always work.  In any event, the goal is logically correct.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1025
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1026
by (intr_tac prems);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1027
{\out Level 1}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1028
{\out lam x xa xb. ?b7(x,xa,xb)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1029
{\out : (PROD z:SUM x:A. B(x). C(z)) --> (PROD x:A. PROD y:B(x). C(<x,y>))}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1030
{\out  1. !!f x y.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1031
{\out        [| f : PROD z:SUM x:A. B(x). C(z); x : A; y : B(x) |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1032
{\out        ?b7(f,x,y) : C(<x,y>)}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1033
\end{ttbox}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1034
Using $\Pi$-elimination, we solve subgoal~1 by applying the function~$f$.
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1035
\index{*ProdE theorem}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1036
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1037
by (eresolve_tac [ProdE] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1038
{\out Level 2}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1039
{\out lam x xa xb. x ` <xa,xb>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1040
{\out : (PROD z:SUM x:A. B(x). C(z)) --> (PROD x:A. PROD y:B(x). C(<x,y>))}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1041
{\out  1. !!f x y. [| x : A; y : B(x) |] ==> <x,y> : SUM x:A. B(x)}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1042
\end{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1043
Finally, we verify that the argument's type is suitable for the function
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1044
application.  This is straightforward using introduction rules.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1045
\index{*intr_tac}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1046
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1047
by (intr_tac prems);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1048
{\out Level 3}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1049
{\out lam x xa xb. x ` <xa,xb>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1050
{\out : (PROD z:SUM x:A. B(x). C(z)) --> (PROD x:A. PROD y:B(x). C(<x,y>))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1051
{\out No subgoals!}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1052
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1053
Calling~\ttindex{pc_tac} would have proved this theorem in one step; it can
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1054
also prove an example by Martin-L\"of, related to $\disj$-elimination
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1055
\cite[page~58]{martinlof84}.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1056
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1057
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1058
\section{Example: proving the Axiom of Choice} \label{ctt-choice}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1059
Suppose we have a function $h\in \prod@{x\in A}\sum@{y\in B(x)} C(x,y)$,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1060
which takes $x\in A$ to some $y\in B(x)$ paired with some $z\in C(x,y)$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1061
Interpreting propositions as types, this asserts that for all $x\in A$
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1062
there exists $y\in B(x)$ such that $C(x,y)$.  The Axiom of Choice asserts
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1063
that we can construct a function $f\in \prod@{x\in A}B(x)$ such that
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1064
$C(x,f{\tt`}x)$ for all $x\in A$, where the latter property is witnessed by a
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1065
function $g\in \prod@{x\in A}C(x,f{\tt`}x)$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1066
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1067
In principle, the Axiom of Choice is simple to derive in Constructive Type
333
2ca08f62df33 final Springer copy
lcp
parents: 314
diff changeset
  1068
Theory.  The following definitions work:
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1069
\begin{eqnarray*}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1070
    f & \equiv & {\tt fst} \circ h \\
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1071
    g & \equiv & {\tt snd} \circ h
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1072
\end{eqnarray*}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1073
But a completely formal proof is hard to find.  The rules can be applied in
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1074
countless ways, yielding many higher-order unifiers.  The proof can get
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1075
bogged down in the details.  But with a careful selection of derived rules
6170
9a59cf8ae9b5 standard spelling: type-checking
paulson
parents: 6072
diff changeset
  1076
(recall Fig.\ts\ref{ctt-derived}) and the type-checking tactics, we can
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1077
prove the theorem in nine steps.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1078
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 3136
diff changeset
  1079
val prems = Goal
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1080
    "[| A type;  !!x. x:A ==> B(x) type;                    \ttback
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1081
\ttback       !!x y.[| x:A;  y:B(x) |] ==> C(x,y) type            \ttback
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1082
\ttback    |] ==> ?a : PROD h: (PROD x:A. SUM y:B(x). C(x,y)).    \ttback
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1083
\ttback                     (SUM f: (PROD x:A. B(x)). PROD x:A. C(x, f`x))";
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1084
{\out Level 0}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1085
{\out ?a : (PROD x:A. SUM y:B(x). C(x,y)) -->}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1086
{\out      (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1087
{\out  1. ?a : (PROD x:A. SUM y:B(x). C(x,y)) -->}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1088
{\out          (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))}
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1089
\ttbreak
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1090
{\out val prems = ["A type  [A type]",}
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1091
{\out              "?x : A ==> B(?x) type  [!!x. x : A ==> B(x) type]",}
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1092
{\out              "[| ?x : A; ?y : B(?x) |] ==> C(?x, ?y) type}
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1093
{\out               [!!x y. [| x : A; y : B(x) |] ==> C(x, y) type]"]}
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1094
{\out             : thm list}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1095
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1096
First, \ttindex{intr_tac} applies introduction rules and performs routine
6170
9a59cf8ae9b5 standard spelling: type-checking
paulson
parents: 6072
diff changeset
  1097
type-checking.  This instantiates~$\Var{a}$ to a construction involving
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1098
a $\lambda$-abstraction and an ordered pair.  The pair's components are
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1099
themselves $\lambda$-abstractions and there is a subgoal for each.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1100
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1101
by (intr_tac prems);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1102
{\out Level 1}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1103
{\out lam x. <lam xa. ?b7(x,xa),lam xa. ?b8(x,xa)>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1104
{\out : (PROD x:A. SUM y:B(x). C(x,y)) -->}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1105
{\out   (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1106
\ttbreak
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1107
{\out  1. !!h x.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1108
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1109
{\out        ?b7(h,x) : B(x)}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1110
\ttbreak
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1111
{\out  2. !!h x.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1112
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1113
{\out        ?b8(h,x) : C(x,(lam x. ?b7(h,x)) ` x)}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1114
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1115
Subgoal~1 asks to find the choice function itself, taking $x\in A$ to some
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1116
$\Var{b@7}(h,x)\in B(x)$.  Subgoal~2 asks, given $x\in A$, for a proof
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1117
object $\Var{b@8}(h,x)$ to witness that the choice function's argument and
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1118
result lie in the relation~$C$.  This latter task will take up most of the
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1119
proof.
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1120
\index{*ProdE theorem}\index{*SumE_fst theorem}\index{*RS}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1121
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1122
by (eresolve_tac [ProdE RS SumE_fst] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1123
{\out Level 2}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1124
{\out lam x. <lam xa. fst(x ` xa),lam xa. ?b8(x,xa)>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1125
{\out : (PROD x:A. SUM y:B(x). C(x,y)) -->}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1126
{\out   (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1127
\ttbreak
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1128
{\out  1. !!h x. x : A ==> x : A}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1129
{\out  2. !!h x.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1130
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1131
{\out        ?b8(h,x) : C(x,(lam x. fst(h ` x)) ` x)}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1132
\end{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1133
Above, we have composed {\tt fst} with the function~$h$.  Unification
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1134
has deduced that the function must be applied to $x\in A$.  We have our
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1135
choice function.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1136
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1137
by (assume_tac 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1138
{\out Level 3}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1139
{\out lam x. <lam xa. fst(x ` xa),lam xa. ?b8(x,xa)>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1140
{\out : (PROD x:A. SUM y:B(x). C(x,y)) -->}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1141
{\out   (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1142
{\out  1. !!h x.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1143
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1144
{\out        ?b8(h,x) : C(x,(lam x. fst(h ` x)) ` x)}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1145
\end{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1146
Before we can compose {\tt snd} with~$h$, the arguments of $C$ must be
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1147
simplified.  The derived rule \tdx{replace_type} lets us replace a type
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1148
by any equivalent type, shown below as the schematic term $\Var{A@{13}}(h,x)$:
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1149
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1150
by (resolve_tac [replace_type] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1151
{\out Level 4}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1152
{\out lam x. <lam xa. fst(x ` xa),lam xa. ?b8(x,xa)>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1153
{\out : (PROD x:A. SUM y:B(x). C(x,y)) -->}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1154
{\out   (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1155
\ttbreak
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1156
{\out  1. !!h x.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1157
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1158
{\out        C(x,(lam x. fst(h ` x)) ` x) = ?A13(h,x)}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1159
\ttbreak
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1160
{\out  2. !!h x.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1161
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1162
{\out        ?b8(h,x) : ?A13(h,x)}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1163
\end{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1164
The derived rule \tdx{subst_eqtyparg} lets us simplify a type's
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1165
argument (by currying, $C(x)$ is a unary type operator):
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1166
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1167
by (resolve_tac [subst_eqtyparg] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1168
{\out Level 5}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1169
{\out lam x. <lam xa. fst(x ` xa),lam xa. ?b8(x,xa)>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1170
{\out : (PROD x:A. SUM y:B(x). C(x,y)) -->}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1171
{\out   (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1172
\ttbreak
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1173
{\out  1. !!h x.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1174
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1175
{\out        (lam x. fst(h ` x)) ` x = ?c14(h,x) : ?A14(h,x)}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1176
\ttbreak
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1177
{\out  2. !!h x z.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1178
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A;}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1179
{\out           z : ?A14(h,x) |] ==>}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1180
{\out        C(x,z) type}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1181
\ttbreak
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1182
{\out  3. !!h x.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1183
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1184
{\out        ?b8(h,x) : C(x,?c14(h,x))}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1185
\end{ttbox}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1186
Subgoal~1 requires simply $\beta$-contraction, which is the rule
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1187
\tdx{ProdC}.  The term $\Var{c@{14}}(h,x)$ in the last subgoal
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1188
receives the contracted result.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1189
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1190
by (resolve_tac [ProdC] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1191
{\out Level 6}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1192
{\out lam x. <lam xa. fst(x ` xa),lam xa. ?b8(x,xa)>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1193
{\out : (PROD x:A. SUM y:B(x). C(x,y)) -->}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1194
{\out   (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1195
\ttbreak
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1196
{\out  1. !!h x.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1197
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1198
{\out        x : ?A15(h,x)}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1199
\ttbreak
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1200
{\out  2. !!h x xa.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1201
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A;}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1202
{\out           xa : ?A15(h,x) |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1203
{\out        fst(h ` xa) : ?B15(h,x,xa)}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1204
\ttbreak
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1205
{\out  3. !!h x z.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1206
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A;}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1207
{\out           z : ?B15(h,x,x) |] ==>}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1208
{\out        C(x,z) type}
114
96c627d2815e Misc updates
lcp
parents: 111
diff changeset
  1209
\ttbreak
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1210
{\out  4. !!h x.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1211
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1212
{\out        ?b8(h,x) : C(x,fst(h ` x))}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1213
\end{ttbox}
6170
9a59cf8ae9b5 standard spelling: type-checking
paulson
parents: 6072
diff changeset
  1214
Routine type-checking goals proliferate in Constructive Type Theory, but
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1215
\ttindex{typechk_tac} quickly solves them.  Note the inclusion of
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1216
\tdx{SumE_fst} along with the premises.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1217
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1218
by (typechk_tac (SumE_fst::prems));
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1219
{\out Level 7}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1220
{\out lam x. <lam xa. fst(x ` xa),lam xa. ?b8(x,xa)>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1221
{\out : (PROD x:A. SUM y:B(x). C(x,y)) -->}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1222
{\out   (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1223
\ttbreak
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1224
{\out  1. !!h x.}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1225
{\out        [| h : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1226
{\out        ?b8(h,x) : C(x,fst(h ` x))}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1227
\end{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1228
We are finally ready to compose {\tt snd} with~$h$.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1229
\index{*ProdE theorem}\index{*SumE_snd theorem}\index{*RS}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1230
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1231
by (eresolve_tac [ProdE RS SumE_snd] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1232
{\out Level 8}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1233
{\out lam x. <lam xa. fst(x ` xa),lam xa. snd(x ` xa)>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1234
{\out : (PROD x:A. SUM y:B(x). C(x,y)) -->}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1235
{\out   (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))}
284
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1236
\ttbreak
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1237
{\out  1. !!h x. x : A ==> x : A}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1238
{\out  2. !!h x. x : A ==> B(x) type}
1072b18b2caa First draft of Springer book
lcp
parents: 153
diff changeset
  1239
{\out  3. !!h x xa. [| x : A; xa : B(x) |] ==> C(x,xa) type}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1240
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1241
The proof object has reached its final form.  We call \ttindex{typechk_tac}
6170
9a59cf8ae9b5 standard spelling: type-checking
paulson
parents: 6072
diff changeset
  1242
to finish the type-checking.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1243
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1244
by (typechk_tac prems);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1245
{\out Level 9}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1246
{\out lam x. <lam xa. fst(x ` xa),lam xa. snd(x ` xa)>}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1247
{\out : (PROD x:A. SUM y:B(x). C(x,y)) -->}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1248
{\out   (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1249
{\out No subgoals!}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1250
\end{ttbox}
314
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1251
It might be instructive to compare this proof with Martin-L\"of's forward
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1252
proof of the Axiom of Choice \cite[page~50]{martinlof84}.
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1253
d1ef723e943d penultimate Springer draft
lcp
parents: 284
diff changeset
  1254
\index{Constructive Type Theory|)}