doc-src/Ref/thm.tex
author Walther Neuper <neuper@ist.tugraz.at>
Thu, 12 Aug 2010 15:03:34 +0200
branchisac-from-Isabelle2009-2
changeset 37913 20e3616b2d9c
parent 30184 37969710e61f
child 44136 34ed34804d90
permissions -rw-r--r--
prepare reactivation of isac-update-Isa09-2
wenzelm@30184
     1
lcp@104
     2
\chapter{Theorems and Forward Proof}
lcp@104
     3
\index{theorems|(}
lcp@326
     4
wenzelm@3108
     5
Theorems, which represent the axioms, theorems and rules of
wenzelm@3108
     6
object-logics, have type \mltydx{thm}.  This chapter begins by
wenzelm@3108
     7
describing operations that print theorems and that join them in
wenzelm@3108
     8
forward proof.  Most theorem operations are intended for advanced
wenzelm@3108
     9
applications, such as programming new proof procedures.  Many of these
wenzelm@3108
    10
operations refer to signatures, certified terms and certified types,
wenzelm@3108
    11
which have the \ML{} types {\tt Sign.sg}, {\tt cterm} and {\tt ctyp}
wenzelm@3108
    12
and are discussed in Chapter~\ref{theories}.  Beginning users should
wenzelm@3108
    13
ignore such complexities --- and skip all but the first section of
wenzelm@3108
    14
this chapter.
lcp@104
    15
lcp@104
    16
lcp@104
    17
\section{Basic operations on theorems}
lcp@104
    18
\subsection{Pretty-printing a theorem}
lcp@326
    19
\index{theorems!printing of}
lcp@104
    20
\begin{ttbox} 
lcp@326
    21
prth          : thm -> thm
lcp@326
    22
prths         : thm list -> thm list
wenzelm@4276
    23
prthq         : thm Seq.seq -> thm Seq.seq
lcp@326
    24
print_thm     : thm -> unit
lcp@326
    25
print_goals   : int -> thm -> unit
lcp@326
    26
string_of_thm : thm -> string
lcp@104
    27
\end{ttbox}
lcp@326
    28
The first three commands are for interactive use.  They are identity
lcp@326
    29
functions that display, then return, their argument.  The \ML{} identifier
lcp@326
    30
{\tt it} will refer to the value just displayed.
lcp@326
    31
lcp@326
    32
The others are for use in programs.  Functions with result type {\tt unit}
lcp@326
    33
are convenient for imperative programming.
lcp@326
    34
lcp@326
    35
\begin{ttdescription}
lcp@104
    36
\item[\ttindexbold{prth} {\it thm}]  
lcp@104
    37
prints {\it thm\/} at the terminal.
lcp@104
    38
lcp@104
    39
\item[\ttindexbold{prths} {\it thms}]  
lcp@104
    40
prints {\it thms}, a list of theorems.
lcp@104
    41
lcp@104
    42
\item[\ttindexbold{prthq} {\it thmq}]  
lcp@104
    43
prints {\it thmq}, a sequence of theorems.  It is useful for inspecting
lcp@104
    44
the output of a tactic.
lcp@104
    45
lcp@104
    46
\item[\ttindexbold{print_thm} {\it thm}]  
lcp@104
    47
prints {\it thm\/} at the terminal.
lcp@104
    48
lcp@104
    49
\item[\ttindexbold{print_goals} {\it limit\/} {\it thm}]  
lcp@104
    50
prints {\it thm\/} in goal style, with the premises as subgoals.  It prints
lcp@104
    51
at most {\it limit\/} subgoals.  The subgoal module calls {\tt print_goals}
lcp@104
    52
to display proof states.
lcp@104
    53
lcp@104
    54
\item[\ttindexbold{string_of_thm} {\it thm}]  
lcp@104
    55
converts {\it thm\/} to a string.
lcp@326
    56
\end{ttdescription}
lcp@104
    57
lcp@104
    58
lcp@326
    59
\subsection{Forward proof: joining rules by resolution}
lcp@326
    60
\index{theorems!joining by resolution}
lcp@326
    61
\index{resolution}\index{forward proof}
lcp@104
    62
\begin{ttbox} 
paulson@8136
    63
RSN : thm * (int * thm) -> thm                 \hfill\textbf{infix}
paulson@8136
    64
RS  : thm * thm -> thm                         \hfill\textbf{infix}
paulson@8136
    65
MRS : thm list * thm -> thm                    \hfill\textbf{infix}
wenzelm@9288
    66
OF  : thm * thm list -> thm                    \hfill\textbf{infix}
paulson@8136
    67
RLN : thm list * (int * thm list) -> thm list  \hfill\textbf{infix}
paulson@8136
    68
RL  : thm list * thm list -> thm list          \hfill\textbf{infix}
paulson@8136
    69
MRL : thm list list * thm list -> thm list     \hfill\textbf{infix}
lcp@104
    70
\end{ttbox}
lcp@326
    71
Joining rules together is a simple way of deriving new rules.  These
lcp@876
    72
functions are especially useful with destruction rules.  To store
lcp@876
    73
the result in the theorem database, use \ttindex{bind_thm}
lcp@876
    74
(\S\ref{ExtractingAndStoringTheProvedTheorem}). 
lcp@326
    75
\begin{ttdescription}
lcp@104
    76
\item[\tt$thm@1$ RSN $(i,thm@2)$] \indexbold{*RSN} 
lcp@326
    77
  resolves the conclusion of $thm@1$ with the $i$th premise of~$thm@2$.
lcp@326
    78
  Unless there is precisely one resolvent it raises exception
lcp@326
    79
  \xdx{THM}; in that case, use {\tt RLN}.
lcp@104
    80
lcp@104
    81
\item[\tt$thm@1$ RS $thm@2$] \indexbold{*RS} 
lcp@104
    82
abbreviates \hbox{\tt$thm@1$ RSN $(1,thm@2)$}.  Thus, it resolves the
lcp@104
    83
conclusion of $thm@1$ with the first premise of~$thm@2$.
lcp@104
    84
lcp@104
    85
\item[\tt {$[thm@1,\ldots,thm@n]$} MRS $thm$] \indexbold{*MRS} 
lcp@332
    86
  uses {\tt RSN} to resolve $thm@i$ against premise~$i$ of $thm$, for
lcp@104
    87
  $i=n$, \ldots,~1.  This applies $thm@n$, \ldots, $thm@1$ to the first $n$
lcp@104
    88
  premises of $thm$.  Because the theorems are used from right to left, it
lcp@104
    89
  does not matter if the $thm@i$ create new premises.  {\tt MRS} is useful
lcp@104
    90
  for expressing proof trees.
wenzelm@9288
    91
  
wenzelm@9288
    92
\item[\tt {$thm$ OF $[thm@1,\ldots,thm@n]$}] \indexbold{*OF} is the same as
wenzelm@9288
    93
  \texttt{$[thm@1,\ldots,thm@n]$ MRS $thm$}, with slightly more readable
wenzelm@9288
    94
  argument order, though.
lcp@104
    95
wenzelm@151
    96
\item[\tt$thms@1$ RLN $(i,thms@2)$] \indexbold{*RLN} 
lcp@326
    97
  joins lists of theorems.  For every $thm@1$ in $thms@1$ and $thm@2$ in
lcp@326
    98
  $thms@2$, it resolves the conclusion of $thm@1$ with the $i$th premise
lcp@326
    99
  of~$thm@2$, accumulating the results. 
lcp@104
   100
wenzelm@151
   101
\item[\tt$thms@1$ RL $thms@2$] \indexbold{*RL} 
wenzelm@151
   102
abbreviates \hbox{\tt$thms@1$ RLN $(1,thms@2)$}. 
lcp@104
   103
lcp@104
   104
\item[\tt {$[thms@1,\ldots,thms@n]$} MRL $thms$] \indexbold{*MRL} 
lcp@104
   105
is analogous to {\tt MRS}, but combines theorem lists rather than theorems.
lcp@104
   106
It too is useful for expressing proof trees.
lcp@326
   107
\end{ttdescription}
lcp@104
   108
lcp@104
   109
lcp@104
   110
\subsection{Expanding definitions in theorems}
lcp@326
   111
\index{meta-rewriting!in theorems}
lcp@104
   112
\begin{ttbox} 
lcp@104
   113
rewrite_rule       : thm list -> thm -> thm
lcp@104
   114
rewrite_goals_rule : thm list -> thm -> thm
lcp@104
   115
\end{ttbox}
lcp@326
   116
\begin{ttdescription}
lcp@104
   117
\item[\ttindexbold{rewrite_rule} {\it defs} {\it thm}]  
lcp@104
   118
unfolds the {\it defs} throughout the theorem~{\it thm}.
lcp@104
   119
lcp@104
   120
\item[\ttindexbold{rewrite_goals_rule} {\it defs} {\it thm}]  
paulson@8136
   121
unfolds the {\it defs} in the premises of~{\it thm}, but it leaves the
paulson@8136
   122
conclusion unchanged.  This rule is the basis for \ttindex{rewrite_goals_tac},
paulson@8136
   123
but it serves little purpose in forward proof.
lcp@326
   124
\end{ttdescription}
lcp@104
   125
lcp@104
   126
paulson@4383
   127
\subsection{Instantiating unknowns in a theorem} \label{sec:instantiate}
lcp@326
   128
\index{instantiation}
paulson@8136
   129
\begin{alltt}\footnotesize
paulson@4383
   130
read_instantiate    :                (string*string) list -> thm -> thm
paulson@4383
   131
read_instantiate_sg :     Sign.sg -> (string*string) list -> thm -> thm
paulson@4383
   132
cterm_instantiate   :                  (cterm*cterm) list -> thm -> thm
paulson@4383
   133
instantiate'      : ctyp option list -> cterm option list -> thm -> thm
paulson@8136
   134
\end{alltt}
lcp@104
   135
These meta-rules instantiate type and term unknowns in a theorem.  They are
lcp@104
   136
occasionally useful.  They can prevent difficulties with higher-order
lcp@104
   137
unification, and define specialized versions of rules.
lcp@326
   138
\begin{ttdescription}
lcp@104
   139
\item[\ttindexbold{read_instantiate} {\it insts} {\it thm}] 
lcp@104
   140
processes the instantiations {\it insts} and instantiates the rule~{\it
lcp@104
   141
thm}.  The processing of instantiations is described
lcp@326
   142
in \S\ref{res_inst_tac}, under {\tt res_inst_tac}.  
lcp@104
   143
lcp@104
   144
Use {\tt res_inst_tac}, not {\tt read_instantiate}, to instantiate a rule
lcp@104
   145
and refine a particular subgoal.  The tactic allows instantiation by the
lcp@104
   146
subgoal's parameters, and reads the instantiations using the signature
lcp@326
   147
associated with the proof state.
lcp@104
   148
lcp@326
   149
Use {\tt read_instantiate_sg} below if {\it insts\/} appears to be treated
lcp@326
   150
incorrectly.
lcp@326
   151
lcp@326
   152
\item[\ttindexbold{read_instantiate_sg} {\it sg} {\it insts} {\it thm}]
paulson@4597
   153
  is like \texttt{read_instantiate {\it insts}~{\it thm}}, but it reads
lcp@326
   154
  the instantiations under signature~{\it sg}.  This is necessary to
lcp@326
   155
  instantiate a rule from a general theory, such as first-order logic,
lcp@326
   156
  using the notation of some specialized theory.  Use the function {\tt
lcp@326
   157
    sign_of} to get a theory's signature.
lcp@104
   158
lcp@104
   159
\item[\ttindexbold{cterm_instantiate} {\it ctpairs} {\it thm}] 
lcp@104
   160
is similar to {\tt read_instantiate}, but the instantiations are provided
lcp@104
   161
as pairs of certified terms, not as strings to be read.
wenzelm@4317
   162
wenzelm@4317
   163
\item[\ttindexbold{instantiate'} {\it ctyps} {\it cterms} {\it thm}]
wenzelm@4317
   164
  instantiates {\it thm} according to the positional arguments {\it
wenzelm@4317
   165
    ctyps} and {\it cterms}.  Counting from left to right, schematic
wenzelm@4317
   166
  variables $?x$ are either replaced by $t$ for any argument
wenzelm@4317
   167
  \texttt{Some\(\;t\)}, or left unchanged in case of \texttt{None} or
wenzelm@4317
   168
  if the end of the argument list is encountered.  Types are
wenzelm@4317
   169
  instantiated before terms.
wenzelm@4317
   170
lcp@326
   171
\end{ttdescription}
lcp@104
   172
lcp@104
   173
clasohm@866
   174
\subsection{Miscellaneous forward rules}\label{MiscellaneousForwardRules}
lcp@326
   175
\index{theorems!standardizing}
lcp@104
   176
\begin{ttbox} 
paulson@8969
   177
standard         :               thm -> thm
paulson@8969
   178
zero_var_indexes :               thm -> thm
paulson@8969
   179
make_elim        :               thm -> thm
paulson@8969
   180
rule_by_tactic   :     tactic -> thm -> thm
paulson@8969
   181
rotate_prems     :        int -> thm -> thm
paulson@8969
   182
permute_prems    : int -> int -> thm -> thm
oheimb@11163
   183
rearrange_prems  :   int list -> thm -> thm
lcp@104
   184
\end{ttbox}
lcp@326
   185
\begin{ttdescription}
wenzelm@3108
   186
\item[\ttindexbold{standard} $thm$] puts $thm$ into the standard form
wenzelm@3108
   187
  of object-rules.  It discharges all meta-assumptions, replaces free
wenzelm@3108
   188
  variables by schematic variables, renames schematic variables to
wenzelm@3108
   189
  have subscript zero, also strips outer (meta) quantifiers and
wenzelm@3108
   190
  removes dangling sort hypotheses.
lcp@104
   191
lcp@104
   192
\item[\ttindexbold{zero_var_indexes} $thm$] 
lcp@104
   193
makes all schematic variables have subscript zero, renaming them to avoid
lcp@104
   194
clashes. 
lcp@104
   195
lcp@104
   196
\item[\ttindexbold{make_elim} $thm$] 
lcp@104
   197
\index{rules!converting destruction to elimination}
paulson@8136
   198
converts $thm$, which should be  a destruction rule of the form
paulson@8136
   199
$\List{P@1;\ldots;P@m}\Imp 
lcp@104
   200
Q$, to the elimination rule $\List{P@1; \ldots; P@m; Q\Imp R}\Imp R$.  This
lcp@104
   201
is the basis for destruct-resolution: {\tt dresolve_tac}, etc.
lcp@104
   202
lcp@104
   203
\item[\ttindexbold{rule_by_tactic} {\it tac} {\it thm}] 
lcp@104
   204
  applies {\it tac\/} to the {\it thm}, freezing its variables first, then
lcp@104
   205
  yields the proof state returned by the tactic.  In typical usage, the
lcp@104
   206
  {\it thm\/} represents an instance of a rule with several premises, some
lcp@104
   207
  with contradictory assumptions (because of the instantiation).  The
lcp@104
   208
  tactic proves those subgoals and does whatever else it can, and returns
lcp@104
   209
  whatever is left.
paulson@4607
   210
  
paulson@4607
   211
\item[\ttindexbold{rotate_prems} $k$ $thm$] rotates the premises of $thm$ to
paulson@8969
   212
  the left by~$k$ positions (to the right if $k<0$).  It simply calls
paulson@8969
   213
  \texttt{permute_prems}, below, with $j=0$.  Used with
paulson@8969
   214
  \texttt{eresolve_tac}\index{*eresolve_tac!on other than first premise}, it
paulson@8969
   215
  gives the effect of applying the tactic to some other premise of $thm$ than
paulson@8969
   216
  the first.
paulson@8969
   217
paulson@8969
   218
\item[\ttindexbold{permute_prems} $j$ $k$ $thm$] rotates the premises of $thm$
paulson@8969
   219
  leaving the first $j$ premises unchanged.  It
paulson@8969
   220
  requires $0\leq j\leq n$, where $n$ is the number of premises.  If $k$ is
paulson@8969
   221
  positive then it rotates the remaining $n-j$ premises to the left; if $k$ is
paulson@8969
   222
  negative then it rotates the premises to the right.
oheimb@11163
   223
oheimb@11163
   224
\item[\ttindexbold{rearrange_prems} $ps$ $thm$] permutes the premises of $thm$
oheimb@11163
   225
   where the value at the $i$-th position (counting from $0$) in the list $ps$
oheimb@11163
   226
   gives the position within the original thm to be transferred to position $i$.
oheimb@11163
   227
   Any remaining trailing positions are left unchanged.
lcp@326
   228
\end{ttdescription}
lcp@104
   229
lcp@104
   230
lcp@104
   231
\subsection{Taking a theorem apart}
lcp@326
   232
\index{theorems!taking apart}
lcp@104
   233
\index{flex-flex constraints}
lcp@104
   234
\begin{ttbox} 
wenzelm@4317
   235
cprop_of      : thm -> cterm
lcp@104
   236
concl_of      : thm -> term
lcp@104
   237
prems_of      : thm -> term list
wenzelm@4317
   238
cprems_of     : thm -> cterm list
lcp@104
   239
nprems_of     : thm -> int
paulson@4383
   240
tpairs_of     : thm -> (term*term) list
wenzelm@4317
   241
sign_of_thm   : thm -> Sign.sg
clasohm@866
   242
theory_of_thm : thm -> theory
paulson@8136
   243
dest_state : thm * int -> (term*term) list * term list * term * term
wenzelm@9499
   244
rep_thm    : thm -> \{sign_ref: Sign.sg_ref, der: bool * deriv, maxidx: int,
paulson@8136
   245
                     shyps: sort list, hyps: term list, prop: term\}
wenzelm@9499
   246
crep_thm   : thm -> \{sign_ref: Sign.sg_ref, der: bool * deriv, maxidx: int,
paulson@8136
   247
                     shyps: sort list, hyps: cterm list, prop:{\ts}cterm\}
lcp@104
   248
\end{ttbox}
lcp@326
   249
\begin{ttdescription}
wenzelm@4317
   250
\item[\ttindexbold{cprop_of} $thm$] returns the statement of $thm$ as
wenzelm@4317
   251
  a certified term.
wenzelm@4317
   252
  
wenzelm@4317
   253
\item[\ttindexbold{concl_of} $thm$] returns the conclusion of $thm$ as
wenzelm@4317
   254
  a term.
wenzelm@4317
   255
  
wenzelm@4317
   256
\item[\ttindexbold{prems_of} $thm$] returns the premises of $thm$ as a
wenzelm@4317
   257
  list of terms.
wenzelm@4317
   258
  
wenzelm@4317
   259
\item[\ttindexbold{cprems_of} $thm$] returns the premises of $thm$ as
wenzelm@4317
   260
  a list of certified terms.
lcp@104
   261
lcp@104
   262
\item[\ttindexbold{nprems_of} $thm$] 
lcp@286
   263
returns the number of premises in $thm$, and is equivalent to {\tt
wenzelm@4317
   264
  length~(prems_of~$thm$)}.
lcp@104
   265
wenzelm@4317
   266
\item[\ttindexbold{tpairs_of} $thm$] returns the flex-flex constraints
wenzelm@4317
   267
  of $thm$.
wenzelm@4317
   268
  
wenzelm@4317
   269
\item[\ttindexbold{sign_of_thm} $thm$] returns the signature
wenzelm@4317
   270
  associated with $thm$.
wenzelm@4317
   271
  
wenzelm@4317
   272
\item[\ttindexbold{theory_of_thm} $thm$] returns the theory associated
wenzelm@4317
   273
  with $thm$.  Note that this does a lookup in Isabelle's global
wenzelm@4317
   274
  database of loaded theories.
clasohm@866
   275
lcp@104
   276
\item[\ttindexbold{dest_state} $(thm,i)$] 
lcp@104
   277
decomposes $thm$ as a tuple containing a list of flex-flex constraints, a
lcp@104
   278
list of the subgoals~1 to~$i-1$, subgoal~$i$, and the rest of the theorem
lcp@104
   279
(this will be an implication if there are more than $i$ subgoals).
lcp@104
   280
wenzelm@4317
   281
\item[\ttindexbold{rep_thm} $thm$] decomposes $thm$ as a record
wenzelm@4317
   282
  containing the statement of~$thm$ ({\tt prop}), its list of
wenzelm@4317
   283
  meta-assumptions ({\tt hyps}), its derivation ({\tt der}), a bound
wenzelm@4317
   284
  on the maximum subscript of its unknowns ({\tt maxidx}), and a
wenzelm@4317
   285
  reference to its signature ({\tt sign_ref}).  The {\tt shyps} field
wenzelm@4317
   286
  is discussed below.
wenzelm@4317
   287
  
wenzelm@4317
   288
\item[\ttindexbold{crep_thm} $thm$] like \texttt{rep_thm}, but returns
wenzelm@4317
   289
  the hypotheses and statement as certified terms.
wenzelm@4317
   290
lcp@326
   291
\end{ttdescription}
lcp@104
   292
lcp@104
   293
wenzelm@5777
   294
\subsection{*Sort hypotheses} \label{sec:sort-hyps}
paulson@2040
   295
\index{sort hypotheses}
paulson@2040
   296
\begin{ttbox} 
wenzelm@7644
   297
strip_shyps         : thm -> thm
wenzelm@7644
   298
strip_shyps_warning : thm -> thm
paulson@2040
   299
\end{ttbox}
paulson@2040
   300
paulson@2044
   301
Isabelle's type variables are decorated with sorts, constraining them to
paulson@2044
   302
certain ranges of types.  This has little impact when sorts only serve for
paulson@2044
   303
syntactic classification of types --- for example, FOL distinguishes between
paulson@2044
   304
terms and other types.  But when type classes are introduced through axioms,
paulson@2044
   305
this may result in some sorts becoming {\em empty\/}: where one cannot exhibit
wenzelm@4317
   306
a type belonging to it because certain sets of axioms are unsatisfiable.
paulson@2040
   307
wenzelm@3108
   308
If a theorem contains a type variable that is constrained by an empty
paulson@3485
   309
sort, then that theorem has no instances.  It is basically an instance
wenzelm@3108
   310
of {\em ex falso quodlibet}.  But what if it is used to prove another
wenzelm@3108
   311
theorem that no longer involves that sort?  The latter theorem holds
wenzelm@3108
   312
only if under an additional non-emptiness assumption.
paulson@2040
   313
paulson@3485
   314
Therefore, Isabelle's theorems carry around sort hypotheses.  The {\tt
paulson@2044
   315
shyps} field is a list of sorts occurring in type variables in the current
paulson@2044
   316
{\tt prop} and {\tt hyps} fields.  It may also includes sorts used in the
paulson@2044
   317
theorem's proof that no longer appear in the {\tt prop} or {\tt hyps}
paulson@3485
   318
fields --- so-called {\em dangling\/} sort constraints.  These are the
paulson@2044
   319
critical ones, asserting non-emptiness of the corresponding sorts.
paulson@2044
   320
 
wenzelm@7644
   321
Isabelle automatically removes extraneous sorts from the {\tt shyps} field at
wenzelm@7644
   322
the end of a proof, provided that non-emptiness can be established by looking
wenzelm@7644
   323
at the theorem's signature: from the {\tt classes} and {\tt arities}
wenzelm@7644
   324
information.  This operation is performed by \texttt{strip_shyps} and
wenzelm@7644
   325
\texttt{strip_shyps_warning}.
wenzelm@7644
   326
wenzelm@7644
   327
\begin{ttdescription}
wenzelm@7644
   328
  
wenzelm@7644
   329
\item[\ttindexbold{strip_shyps} $thm$] removes any extraneous sort hypotheses
wenzelm@7644
   330
  that can be witnessed from the type signature.
wenzelm@7644
   331
  
wenzelm@7644
   332
\item[\ttindexbold{strip_shyps_warning}] is like \texttt{strip_shyps}, but
wenzelm@7644
   333
  issues a warning message of any pending sort hypotheses that do not have a
wenzelm@7644
   334
  (syntactic) witness.
wenzelm@7644
   335
wenzelm@7644
   336
\end{ttdescription}
paulson@2040
   337
paulson@2040
   338
lcp@104
   339
\subsection{Tracing flags for unification}
lcp@326
   340
\index{tracing!of unification}
lcp@104
   341
\begin{ttbox} 
paulson@8136
   342
Unify.trace_simp   : bool ref \hfill\textbf{initially false}
paulson@8136
   343
Unify.trace_types  : bool ref \hfill\textbf{initially false}
paulson@8136
   344
Unify.trace_bound  : int ref \hfill\textbf{initially 10}
paulson@8136
   345
Unify.search_bound : int ref \hfill\textbf{initially 20}
lcp@104
   346
\end{ttbox}
lcp@104
   347
Tracing the search may be useful when higher-order unification behaves
lcp@104
   348
unexpectedly.  Letting {\tt res_inst_tac} circumvent the problem is easier,
lcp@104
   349
though.
lcp@326
   350
\begin{ttdescription}
wenzelm@4317
   351
\item[set Unify.trace_simp;] 
lcp@104
   352
causes tracing of the simplification phase.
lcp@104
   353
wenzelm@4317
   354
\item[set Unify.trace_types;] 
lcp@104
   355
generates warnings of incompleteness, when unification is not considering
lcp@104
   356
all possible instantiations of type unknowns.
lcp@104
   357
lcp@326
   358
\item[Unify.trace_bound := $n$;] 
lcp@104
   359
causes unification to print tracing information once it reaches depth~$n$.
lcp@104
   360
Use $n=0$ for full tracing.  At the default value of~10, tracing
lcp@104
   361
information is almost never printed.
lcp@104
   362
paulson@8136
   363
\item[Unify.search_bound := $n$;] prevents unification from
paulson@8136
   364
  searching past the depth~$n$.  Because of this bound, higher-order
wenzelm@4317
   365
  unification cannot return an infinite sequence, though it can return
paulson@8136
   366
  an exponentially long one.  The search rarely approaches the default value
wenzelm@4317
   367
  of~20.  If the search is cut off, unification prints a warning
wenzelm@4317
   368
  \texttt{Unification bound exceeded}.
lcp@326
   369
\end{ttdescription}
lcp@104
   370
lcp@104
   371
wenzelm@4317
   372
\section{*Primitive meta-level inference rules}
lcp@104
   373
\index{meta-rules|(}
wenzelm@4317
   374
These implement the meta-logic in the style of the {\sc lcf} system,
wenzelm@4317
   375
as functions from theorems to theorems.  They are, rarely, useful for
wenzelm@4317
   376
deriving results in the pure theory.  Mainly, they are included for
wenzelm@4317
   377
completeness, and most users should not bother with them.  The
wenzelm@4317
   378
meta-rules raise exception \xdx{THM} to signal malformed premises,
wenzelm@4317
   379
incompatible signatures and similar errors.
lcp@104
   380
lcp@326
   381
\index{meta-assumptions}
lcp@104
   382
The meta-logic uses natural deduction.  Each theorem may depend on
lcp@332
   383
meta-level assumptions.  Certain rules, such as $({\Imp}I)$,
lcp@104
   384
discharge assumptions; in most other rules, the conclusion depends on all
lcp@104
   385
of the assumptions of the premises.  Formally, the system works with
lcp@104
   386
assertions of the form
lcp@104
   387
\[ \phi \quad [\phi@1,\ldots,\phi@n], \]
wenzelm@3108
   388
where $\phi@1$,~\ldots,~$\phi@n$ are the assumptions.  This can be
wenzelm@3108
   389
also read as a single conclusion sequent $\phi@1,\ldots,\phi@n \vdash
paulson@3485
   390
\phi$.  Do not confuse meta-level assumptions with the object-level
wenzelm@3108
   391
assumptions in a subgoal, which are represented in the meta-logic
wenzelm@3108
   392
using~$\Imp$.
lcp@104
   393
lcp@104
   394
Each theorem has a signature.  Certified terms have a signature.  When a
lcp@104
   395
rule takes several premises and certified terms, it merges the signatures
lcp@104
   396
to make a signature for the conclusion.  This fails if the signatures are
lcp@104
   397
incompatible. 
lcp@104
   398
wenzelm@5777
   399
\medskip
wenzelm@5777
   400
wenzelm@5777
   401
The following presentation of primitive rules ignores sort
wenzelm@5777
   402
hypotheses\index{sort hypotheses} (see also \S\ref{sec:sort-hyps}).  These are
wenzelm@5777
   403
handled transparently by the logic implementation.
wenzelm@5777
   404
wenzelm@5777
   405
\bigskip
wenzelm@5777
   406
lcp@326
   407
\index{meta-implication}
paulson@8136
   408
The \textbf{implication} rules are $({\Imp}I)$
lcp@104
   409
and $({\Imp}E)$:
lcp@104
   410
\[ \infer[({\Imp}I)]{\phi\Imp \psi}{\infer*{\psi}{[\phi]}}  \qquad
lcp@104
   411
   \infer[({\Imp}E)]{\psi}{\phi\Imp \psi & \phi}  \]
lcp@104
   412
lcp@326
   413
\index{meta-equality}
lcp@104
   414
Equality of truth values means logical equivalence:
wenzelm@3524
   415
\[ \infer[({\equiv}I)]{\phi\equiv\psi}{\phi\Imp\psi &
wenzelm@3524
   416
                                       \psi\Imp\phi}
lcp@104
   417
   \qquad
lcp@104
   418
   \infer[({\equiv}E)]{\psi}{\phi\equiv \psi & \phi}   \]
lcp@104
   419
paulson@8136
   420
The \textbf{equality} rules are reflexivity, symmetry, and transitivity:
lcp@104
   421
\[ {a\equiv a}\,(refl)  \qquad
lcp@104
   422
   \infer[(sym)]{b\equiv a}{a\equiv b}  \qquad
lcp@104
   423
   \infer[(trans)]{a\equiv c}{a\equiv b & b\equiv c}   \]
lcp@104
   424
lcp@326
   425
\index{lambda calc@$\lambda$-calculus}
lcp@104
   426
The $\lambda$-conversions are $\alpha$-conversion, $\beta$-conversion, and
lcp@104
   427
extensionality:\footnote{$\alpha$-conversion holds if $y$ is not free
lcp@104
   428
in~$a$; $(ext)$ holds if $x$ is not free in the assumptions, $f$, or~$g$.}
lcp@104
   429
\[ {(\lambda x.a) \equiv (\lambda y.a[y/x])}    \qquad
lcp@104
   430
   {((\lambda x.a)(b)) \equiv a[b/x]}           \qquad
lcp@104
   431
   \infer[(ext)]{f\equiv g}{f(x) \equiv g(x)}   \]
lcp@104
   432
paulson@8136
   433
The \textbf{abstraction} and \textbf{combination} rules let conversions be
lcp@332
   434
applied to subterms:\footnote{Abstraction holds if $x$ is not free in the
lcp@104
   435
assumptions.}
lcp@104
   436
\[  \infer[(abs)]{(\lambda x.a) \equiv (\lambda x.b)}{a\equiv b}   \qquad
lcp@104
   437
    \infer[(comb)]{f(a)\equiv g(b)}{f\equiv g & a\equiv b}   \]
lcp@104
   438
lcp@326
   439
\index{meta-quantifiers}
paulson@8136
   440
The \textbf{universal quantification} rules are $(\Forall I)$ and $(\Forall
lcp@104
   441
E)$:\footnote{$(\Forall I)$ holds if $x$ is not free in the assumptions.}
lcp@104
   442
\[ \infer[(\Forall I)]{\Forall x.\phi}{\phi}        \qquad
lcp@286
   443
   \infer[(\Forall E)]{\phi[b/x]}{\Forall x.\phi}   \]
lcp@104
   444
lcp@104
   445
lcp@326
   446
\subsection{Assumption rule}
lcp@326
   447
\index{meta-assumptions}
lcp@104
   448
\begin{ttbox} 
wenzelm@3108
   449
assume: cterm -> thm
lcp@104
   450
\end{ttbox}
lcp@326
   451
\begin{ttdescription}
lcp@104
   452
\item[\ttindexbold{assume} $ct$] 
lcp@332
   453
makes the theorem \(\phi \;[\phi]\), where $\phi$ is the value of~$ct$.
lcp@104
   454
The rule checks that $ct$ has type $prop$ and contains no unknowns, which
lcp@332
   455
are not allowed in assumptions.
lcp@326
   456
\end{ttdescription}
lcp@104
   457
lcp@326
   458
\subsection{Implication rules}
lcp@326
   459
\index{meta-implication}
lcp@104
   460
\begin{ttbox} 
wenzelm@3108
   461
implies_intr      : cterm -> thm -> thm
wenzelm@3108
   462
implies_intr_list : cterm list -> thm -> thm
lcp@104
   463
implies_intr_hyps : thm -> thm
lcp@104
   464
implies_elim      : thm -> thm -> thm
lcp@104
   465
implies_elim_list : thm -> thm list -> thm
lcp@104
   466
\end{ttbox}
lcp@326
   467
\begin{ttdescription}
lcp@104
   468
\item[\ttindexbold{implies_intr} $ct$ $thm$] 
lcp@104
   469
is $({\Imp}I)$, where $ct$ is the assumption to discharge, say~$\phi$.  It
lcp@332
   470
maps the premise~$\psi$ to the conclusion $\phi\Imp\psi$, removing all
lcp@332
   471
occurrences of~$\phi$ from the assumptions.  The rule checks that $ct$ has
lcp@332
   472
type $prop$. 
lcp@104
   473
lcp@104
   474
\item[\ttindexbold{implies_intr_list} $cts$ $thm$] 
lcp@104
   475
applies $({\Imp}I)$ repeatedly, on every element of the list~$cts$.
lcp@104
   476
lcp@104
   477
\item[\ttindexbold{implies_intr_hyps} $thm$] 
lcp@332
   478
applies $({\Imp}I)$ to discharge all the hypotheses (assumptions) of~$thm$.
lcp@332
   479
It maps the premise $\phi \; [\phi@1,\ldots,\phi@n]$ to the conclusion
lcp@104
   480
$\List{\phi@1,\ldots,\phi@n}\Imp\phi$.
lcp@104
   481
lcp@104
   482
\item[\ttindexbold{implies_elim} $thm@1$ $thm@2$] 
lcp@104
   483
applies $({\Imp}E)$ to $thm@1$ and~$thm@2$.  It maps the premises $\phi\Imp
lcp@104
   484
\psi$ and $\phi$ to the conclusion~$\psi$.
lcp@104
   485
lcp@104
   486
\item[\ttindexbold{implies_elim_list} $thm$ $thms$] 
lcp@104
   487
applies $({\Imp}E)$ repeatedly to $thm$, using each element of~$thms$ in
wenzelm@151
   488
turn.  It maps the premises $\List{\phi@1,\ldots,\phi@n}\Imp\psi$ and
lcp@104
   489
$\phi@1$,\ldots,$\phi@n$ to the conclusion~$\psi$.
lcp@326
   490
\end{ttdescription}
lcp@104
   491
lcp@326
   492
\subsection{Logical equivalence rules}
lcp@326
   493
\index{meta-equality}
lcp@104
   494
\begin{ttbox} 
lcp@326
   495
equal_intr : thm -> thm -> thm 
lcp@326
   496
equal_elim : thm -> thm -> thm
lcp@104
   497
\end{ttbox}
lcp@326
   498
\begin{ttdescription}
lcp@104
   499
\item[\ttindexbold{equal_intr} $thm@1$ $thm@2$] 
lcp@332
   500
applies $({\equiv}I)$ to $thm@1$ and~$thm@2$.  It maps the premises~$\psi$
lcp@332
   501
and~$\phi$ to the conclusion~$\phi\equiv\psi$; the assumptions are those of
lcp@332
   502
the first premise with~$\phi$ removed, plus those of
lcp@332
   503
the second premise with~$\psi$ removed.
lcp@104
   504
lcp@104
   505
\item[\ttindexbold{equal_elim} $thm@1$ $thm@2$] 
lcp@104
   506
applies $({\equiv}E)$ to $thm@1$ and~$thm@2$.  It maps the premises
lcp@104
   507
$\phi\equiv\psi$ and $\phi$ to the conclusion~$\psi$.
lcp@326
   508
\end{ttdescription}
lcp@104
   509
lcp@104
   510
lcp@104
   511
\subsection{Equality rules}
lcp@326
   512
\index{meta-equality}
lcp@104
   513
\begin{ttbox} 
wenzelm@3108
   514
reflexive  : cterm -> thm
lcp@104
   515
symmetric  : thm -> thm
lcp@104
   516
transitive : thm -> thm -> thm
lcp@104
   517
\end{ttbox}
lcp@326
   518
\begin{ttdescription}
lcp@104
   519
\item[\ttindexbold{reflexive} $ct$] 
wenzelm@151
   520
makes the theorem \(ct\equiv ct\). 
lcp@104
   521
lcp@104
   522
\item[\ttindexbold{symmetric} $thm$] 
lcp@104
   523
maps the premise $a\equiv b$ to the conclusion $b\equiv a$.
lcp@104
   524
lcp@104
   525
\item[\ttindexbold{transitive} $thm@1$ $thm@2$] 
lcp@104
   526
maps the premises $a\equiv b$ and $b\equiv c$ to the conclusion~${a\equiv c}$.
lcp@326
   527
\end{ttdescription}
lcp@104
   528
lcp@104
   529
lcp@104
   530
\subsection{The $\lambda$-conversion rules}
lcp@326
   531
\index{lambda calc@$\lambda$-calculus}
lcp@104
   532
\begin{ttbox} 
wenzelm@3108
   533
beta_conversion : cterm -> thm
lcp@104
   534
extensional     : thm -> thm
wenzelm@3108
   535
abstract_rule   : string -> cterm -> thm -> thm
lcp@104
   536
combination     : thm -> thm -> thm
lcp@104
   537
\end{ttbox} 
lcp@326
   538
There is no rule for $\alpha$-conversion because Isabelle regards
lcp@326
   539
$\alpha$-convertible theorems as equal.
lcp@326
   540
\begin{ttdescription}
lcp@104
   541
\item[\ttindexbold{beta_conversion} $ct$] 
lcp@104
   542
makes the theorem $((\lambda x.a)(b)) \equiv a[b/x]$, where $ct$ is the
lcp@104
   543
term $(\lambda x.a)(b)$.
lcp@104
   544
lcp@104
   545
\item[\ttindexbold{extensional} $thm$] 
lcp@104
   546
maps the premise $f(x) \equiv g(x)$ to the conclusion $f\equiv g$.
lcp@104
   547
Parameter~$x$ is taken from the premise.  It may be an unknown or a free
lcp@332
   548
variable (provided it does not occur in the assumptions); it must not occur
lcp@104
   549
in $f$ or~$g$.
lcp@104
   550
lcp@104
   551
\item[\ttindexbold{abstract_rule} $v$ $x$ $thm$] 
lcp@104
   552
maps the premise $a\equiv b$ to the conclusion $(\lambda x.a) \equiv
lcp@104
   553
(\lambda x.b)$, abstracting over all occurrences (if any!) of~$x$.
lcp@104
   554
Parameter~$x$ is supplied as a cterm.  It may be an unknown or a free
lcp@332
   555
variable (provided it does not occur in the assumptions).  In the
lcp@104
   556
conclusion, the bound variable is named~$v$.
lcp@104
   557
lcp@104
   558
\item[\ttindexbold{combination} $thm@1$ $thm@2$] 
lcp@104
   559
maps the premises $f\equiv g$ and $a\equiv b$ to the conclusion~$f(a)\equiv
lcp@104
   560
g(b)$.
lcp@326
   561
\end{ttdescription}
lcp@104
   562
lcp@104
   563
lcp@326
   564
\subsection{Forall introduction rules}
lcp@326
   565
\index{meta-quantifiers}
lcp@104
   566
\begin{ttbox} 
wenzelm@3108
   567
forall_intr       : cterm      -> thm -> thm
wenzelm@3108
   568
forall_intr_list  : cterm list -> thm -> thm
wenzelm@3108
   569
forall_intr_frees :               thm -> thm
lcp@104
   570
\end{ttbox}
lcp@104
   571
lcp@326
   572
\begin{ttdescription}
lcp@104
   573
\item[\ttindexbold{forall_intr} $x$ $thm$] 
lcp@104
   574
applies $({\Forall}I)$, abstracting over all occurrences (if any!) of~$x$.
lcp@104
   575
The rule maps the premise $\phi$ to the conclusion $\Forall x.\phi$.
lcp@104
   576
Parameter~$x$ is supplied as a cterm.  It may be an unknown or a free
lcp@332
   577
variable (provided it does not occur in the assumptions).
lcp@104
   578
lcp@104
   579
\item[\ttindexbold{forall_intr_list} $xs$ $thm$] 
lcp@104
   580
applies $({\Forall}I)$ repeatedly, on every element of the list~$xs$.
lcp@104
   581
lcp@104
   582
\item[\ttindexbold{forall_intr_frees} $thm$] 
lcp@104
   583
applies $({\Forall}I)$ repeatedly, generalizing over all the free variables
lcp@104
   584
of the premise.
lcp@326
   585
\end{ttdescription}
lcp@104
   586
lcp@104
   587
lcp@326
   588
\subsection{Forall elimination rules}
lcp@104
   589
\begin{ttbox} 
wenzelm@3108
   590
forall_elim       : cterm      -> thm -> thm
wenzelm@3108
   591
forall_elim_list  : cterm list -> thm -> thm
wenzelm@3108
   592
forall_elim_var   :        int -> thm -> thm
wenzelm@3108
   593
forall_elim_vars  :        int -> thm -> thm
lcp@104
   594
\end{ttbox}
lcp@104
   595
lcp@326
   596
\begin{ttdescription}
lcp@104
   597
\item[\ttindexbold{forall_elim} $ct$ $thm$] 
lcp@104
   598
applies $({\Forall}E)$, mapping the premise $\Forall x.\phi$ to the conclusion
lcp@104
   599
$\phi[ct/x]$.  The rule checks that $ct$ and $x$ have the same type.
lcp@104
   600
lcp@104
   601
\item[\ttindexbold{forall_elim_list} $cts$ $thm$] 
lcp@104
   602
applies $({\Forall}E)$ repeatedly, on every element of the list~$cts$.
lcp@104
   603
lcp@104
   604
\item[\ttindexbold{forall_elim_var} $k$ $thm$] 
lcp@104
   605
applies $({\Forall}E)$, mapping the premise $\Forall x.\phi$ to the conclusion
lcp@104
   606
$\phi[\Var{x@k}/x]$.  Thus, it replaces the outermost $\Forall$-bound
lcp@104
   607
variable by an unknown having subscript~$k$.
lcp@104
   608
paulson@9258
   609
\item[\ttindexbold{forall_elim_vars} $k$ $thm$] 
paulson@9258
   610
applies {\tt forall_elim_var}~$k$ repeatedly until the theorem no longer has
paulson@9258
   611
the form $\Forall x.\phi$.
lcp@326
   612
\end{ttdescription}
lcp@104
   613
paulson@8135
   614
lcp@326
   615
\subsection{Instantiation of unknowns}
lcp@326
   616
\index{instantiation}
paulson@8136
   617
\begin{alltt}\footnotesize
wenzelm@3135
   618
instantiate: (indexname * ctyp){\thinspace}list * (cterm * cterm){\thinspace}list -> thm -> thm
paulson@8136
   619
\end{alltt}
paulson@8135
   620
There are two versions of this rule.  The primitive one is
paulson@8135
   621
\ttindexbold{Thm.instantiate}, which merely performs the instantiation and can
paulson@8135
   622
produce a conclusion not in normal form.  A derived version is  
paulson@8135
   623
\ttindexbold{Drule.instantiate}, which normalizes its conclusion.
paulson@8135
   624
lcp@326
   625
\begin{ttdescription}
paulson@8136
   626
\item[\ttindexbold{instantiate} ($tyinsts$,$insts$) $thm$] 
lcp@326
   627
simultaneously substitutes types for type unknowns (the
lcp@104
   628
$tyinsts$) and terms for term unknowns (the $insts$).  Instantiations are
lcp@104
   629
given as $(v,t)$ pairs, where $v$ is an unknown and $t$ is a term (of the
lcp@104
   630
same type as $v$) or a type (of the same sort as~$v$).  All the unknowns
paulson@8135
   631
must be distinct.  
wenzelm@4376
   632
paulson@8135
   633
In some cases, \ttindex{instantiate'} (see \S\ref{sec:instantiate})
wenzelm@4376
   634
provides a more convenient interface to this rule.
lcp@326
   635
\end{ttdescription}
lcp@104
   636
lcp@104
   637
paulson@8135
   638
paulson@8135
   639
lcp@326
   640
\subsection{Freezing/thawing type unknowns}
lcp@326
   641
\index{type unknowns!freezing/thawing of}
lcp@104
   642
\begin{ttbox} 
lcp@104
   643
freezeT: thm -> thm
lcp@104
   644
varifyT: thm -> thm
lcp@104
   645
\end{ttbox}
lcp@326
   646
\begin{ttdescription}
lcp@104
   647
\item[\ttindexbold{freezeT} $thm$] 
lcp@104
   648
converts all the type unknowns in $thm$ to free type variables.
lcp@104
   649
lcp@104
   650
\item[\ttindexbold{varifyT} $thm$] 
lcp@104
   651
converts all the free type variables in $thm$ to type unknowns.
lcp@326
   652
\end{ttdescription}
lcp@104
   653
lcp@104
   654
lcp@104
   655
\section{Derived rules for goal-directed proof}
lcp@104
   656
Most of these rules have the sole purpose of implementing particular
lcp@104
   657
tactics.  There are few occasions for applying them directly to a theorem.
lcp@104
   658
lcp@104
   659
\subsection{Proof by assumption}
lcp@326
   660
\index{meta-assumptions}
lcp@104
   661
\begin{ttbox} 
wenzelm@4276
   662
assumption    : int -> thm -> thm Seq.seq
lcp@104
   663
eq_assumption : int -> thm -> thm
lcp@104
   664
\end{ttbox}
lcp@326
   665
\begin{ttdescription}
lcp@104
   666
\item[\ttindexbold{assumption} {\it i} $thm$] 
lcp@104
   667
attempts to solve premise~$i$ of~$thm$ by assumption.
lcp@104
   668
lcp@104
   669
\item[\ttindexbold{eq_assumption}] 
lcp@104
   670
is like {\tt assumption} but does not use unification.
lcp@326
   671
\end{ttdescription}
lcp@104
   672
lcp@104
   673
lcp@104
   674
\subsection{Resolution}
lcp@326
   675
\index{resolution}
lcp@104
   676
\begin{ttbox} 
lcp@104
   677
biresolution : bool -> (bool*thm)list -> int -> thm
wenzelm@4276
   678
               -> thm Seq.seq
lcp@104
   679
\end{ttbox}
lcp@326
   680
\begin{ttdescription}
lcp@104
   681
\item[\ttindexbold{biresolution} $match$ $rules$ $i$ $state$] 
lcp@326
   682
performs bi-resolution on subgoal~$i$ of $state$, using the list of $\it
lcp@104
   683
(flag,rule)$ pairs.  For each pair, it applies resolution if the flag
lcp@104
   684
is~{\tt false} and elim-resolution if the flag is~{\tt true}.  If $match$
lcp@104
   685
is~{\tt true}, the $state$ is not instantiated.
lcp@326
   686
\end{ttdescription}
lcp@104
   687
lcp@104
   688
lcp@104
   689
\subsection{Composition: resolution without lifting}
lcp@326
   690
\index{resolution!without lifting}
lcp@104
   691
\begin{ttbox}
lcp@104
   692
compose   : thm * int * thm -> thm list
lcp@104
   693
COMP      : thm * thm -> thm
lcp@104
   694
bicompose : bool -> bool * thm * int -> int -> thm
wenzelm@4276
   695
            -> thm Seq.seq
lcp@104
   696
\end{ttbox}
lcp@104
   697
In forward proof, a typical use of composition is to regard an assertion of
lcp@104
   698
the form $\phi\Imp\psi$ as atomic.  Schematic variables are not renamed, so
lcp@104
   699
beware of clashes!
lcp@326
   700
\begin{ttdescription}
lcp@104
   701
\item[\ttindexbold{compose} ($thm@1$, $i$, $thm@2$)] 
lcp@104
   702
uses $thm@1$, regarded as an atomic formula, to solve premise~$i$
lcp@104
   703
of~$thm@2$.  Let $thm@1$ and $thm@2$ be $\psi$ and $\List{\phi@1; \ldots;
lcp@104
   704
\phi@n} \Imp \phi$.  For each $s$ that unifies~$\psi$ and $\phi@i$, the
lcp@104
   705
result list contains the theorem
lcp@104
   706
\[ (\List{\phi@1; \ldots; \phi@{i-1}; \phi@{i+1}; \ldots; \phi@n} \Imp \phi)s.
lcp@104
   707
\]
lcp@104
   708
lcp@1119
   709
\item[$thm@1$ \ttindexbold{COMP} $thm@2$] 
lcp@104
   710
calls \hbox{\tt compose ($thm@1$, 1, $thm@2$)} and returns the result, if
lcp@326
   711
unique; otherwise, it raises exception~\xdx{THM}\@.  It is
lcp@104
   712
analogous to {\tt RS}\@.  
lcp@104
   713
lcp@104
   714
For example, suppose that $thm@1$ is $a=b\Imp b=a$, a symmetry rule, and
lcp@332
   715
that $thm@2$ is $\List{P\Imp Q; \neg Q} \Imp\neg P$, which is the
lcp@104
   716
principle of contrapositives.  Then the result would be the
lcp@104
   717
derived rule $\neg(b=a)\Imp\neg(a=b)$.
lcp@104
   718
lcp@104
   719
\item[\ttindexbold{bicompose} $match$ ($flag$, $rule$, $m$) $i$ $state$]
lcp@104
   720
refines subgoal~$i$ of $state$ using $rule$, without lifting.  The $rule$
lcp@104
   721
is taken to have the form $\List{\psi@1; \ldots; \psi@m} \Imp \psi$, where
lcp@326
   722
$\psi$ need not be atomic; thus $m$ determines the number of new
lcp@104
   723
subgoals.  If $flag$ is {\tt true} then it performs elim-resolution --- it
lcp@104
   724
solves the first premise of~$rule$ by assumption and deletes that
lcp@104
   725
assumption.  If $match$ is~{\tt true}, the $state$ is not instantiated.
lcp@326
   726
\end{ttdescription}
lcp@104
   727
lcp@104
   728
lcp@104
   729
\subsection{Other meta-rules}
lcp@104
   730
\begin{ttbox} 
wenzelm@3108
   731
trivial            : cterm -> thm
lcp@104
   732
lift_rule          : (thm * int) -> thm -> thm
lcp@104
   733
rename_params_rule : string list * int -> thm -> thm
wenzelm@4276
   734
flexflex_rule      : thm -> thm Seq.seq
lcp@104
   735
\end{ttbox}
lcp@326
   736
\begin{ttdescription}
lcp@104
   737
\item[\ttindexbold{trivial} $ct$] 
lcp@104
   738
makes the theorem \(\phi\Imp\phi\), where $\phi$ is the value of~$ct$.
lcp@104
   739
This is the initial state for a goal-directed proof of~$\phi$.  The rule
lcp@104
   740
checks that $ct$ has type~$prop$.
lcp@104
   741
lcp@104
   742
\item[\ttindexbold{lift_rule} ($state$, $i$) $rule$] \index{lifting}
lcp@104
   743
prepares $rule$ for resolution by lifting it over the parameters and
lcp@104
   744
assumptions of subgoal~$i$ of~$state$.
lcp@104
   745
lcp@104
   746
\item[\ttindexbold{rename_params_rule} ({\it names}, {\it i}) $thm$] 
lcp@104
   747
uses the $names$ to rename the parameters of premise~$i$ of $thm$.  The
lcp@104
   748
names must be distinct.  If there are fewer names than parameters, then the
lcp@104
   749
rule renames the innermost parameters and may modify the remaining ones to
lcp@104
   750
ensure that all the parameters are distinct.
lcp@104
   751
\index{parameters!renaming}
lcp@104
   752
lcp@104
   753
\item[\ttindexbold{flexflex_rule} $thm$]  \index{flex-flex constraints}
lcp@104
   754
removes all flex-flex pairs from $thm$ using the trivial unifier.
lcp@326
   755
\end{ttdescription}
paulson@1590
   756
\index{meta-rules|)}
paulson@1590
   757
paulson@1590
   758
berghofe@11622
   759
\section{Proof terms}\label{sec:proofObjects}
berghofe@11622
   760
\index{proof terms|(} Isabelle can record the full meta-level proof of each
berghofe@11622
   761
theorem.  The proof term contains all logical inferences in detail.
berghofe@11622
   762
%while
berghofe@11622
   763
%omitting bookkeeping steps that have no logical meaning to an outside
berghofe@11622
   764
%observer.  Rewriting steps are recorded in similar detail as the output of
berghofe@11622
   765
%simplifier tracing. 
berghofe@11622
   766
Resolution and rewriting steps are broken down to primitive rules of the
berghofe@11622
   767
meta-logic. The proof term can be inspected by a separate proof-checker,
berghofe@11622
   768
for example.
paulson@1590
   769
berghofe@11622
   770
According to the well-known {\em Curry-Howard isomorphism}, a proof can
berghofe@11622
   771
be viewed as a $\lambda$-term. Following this idea, proofs
berghofe@11622
   772
in Isabelle are internally represented by a datatype similar to the one for
berghofe@11622
   773
terms described in \S\ref{sec:terms}.
berghofe@11622
   774
\begin{ttbox}
berghofe@11622
   775
infix 8 % %%;
paulson@1590
   776
berghofe@11622
   777
datatype proof =
berghofe@11622
   778
   PBound of int
berghofe@11622
   779
 | Abst of string * typ option * proof
berghofe@11622
   780
 | AbsP of string * term option * proof
berghofe@11622
   781
 | op % of proof * term option
berghofe@11622
   782
 | op %% of proof * proof
berghofe@11622
   783
 | Hyp of term
berghofe@11622
   784
 | PThm of (string * (string * string list) list) *
berghofe@11622
   785
           proof * term * typ list option
berghofe@11622
   786
 | PAxm of string * term * typ list option
berghofe@11622
   787
 | Oracle of string * term * typ list option
berghofe@11622
   788
 | MinProof of proof list;
berghofe@11622
   789
\end{ttbox}
paulson@1590
   790
berghofe@11622
   791
\begin{ttdescription}
berghofe@11622
   792
\item[\ttindexbold{Abst} ($a$, $\tau$, $prf$)] is the abstraction over
berghofe@11622
   793
a {\it term variable} of type $\tau$ in the body $prf$. Logically, this
berghofe@11622
   794
corresponds to $\bigwedge$ introduction. The name $a$ is used only for
berghofe@11622
   795
parsing and printing.
berghofe@11622
   796
\item[\ttindexbold{AbsP} ($a$, $\varphi$, $prf$)] is the abstraction
berghofe@11622
   797
over a {\it proof variable} standing for a proof of proposition $\varphi$
berghofe@11622
   798
in the body $prf$. This corresponds to $\Longrightarrow$ introduction.
berghofe@11622
   799
\item[$prf$ \% $t$] \index{\%@{\tt\%}|bold}
berghofe@11622
   800
is the application of proof $prf$ to term $t$
berghofe@11622
   801
which corresponds to $\bigwedge$ elimination.
berghofe@11622
   802
\item[$prf@1$ \%\% $prf@2$] \index{\%\%@{\tt\%\%}|bold}
berghofe@11622
   803
is the application of proof $prf@1$ to
berghofe@11622
   804
proof $prf@2$ which corresponds to $\Longrightarrow$ elimination.
berghofe@11622
   805
\item[\ttindexbold{PBound} $i$] is a {\em proof variable} with de Bruijn
berghofe@11622
   806
\cite{debruijn72} index $i$.
berghofe@11622
   807
\item[\ttindexbold{Hyp} $\varphi$] corresponds to the use of a meta level
berghofe@11622
   808
hypothesis $\varphi$.
berghofe@11622
   809
\item[\ttindexbold{PThm} (($name$, $tags$), $prf$, $\varphi$, $\overline{\tau}$)]
berghofe@11622
   810
stands for a pre-proved theorem, where $name$ is the name of the theorem,
berghofe@11622
   811
$prf$ is its actual proof, $\varphi$ is the proven proposition,
berghofe@11622
   812
and $\overline{\tau}$ is
berghofe@11622
   813
a type assignment for the type variables occurring in the proposition.
berghofe@11622
   814
\item[\ttindexbold{PAxm} ($name$, $\varphi$, $\overline{\tau}$)]
berghofe@11622
   815
corresponds to the use of an axiom with name $name$ and proposition
berghofe@11622
   816
$\varphi$, where $\overline{\tau}$ is a type assignment for the type
berghofe@11622
   817
variables occurring in the proposition.
berghofe@11622
   818
\item[\ttindexbold{Oracle} ($name$, $\varphi$, $\overline{\tau}$)]
berghofe@11622
   819
denotes the invocation of an oracle with name $name$ which produced
berghofe@11622
   820
a proposition $\varphi$, where $\overline{\tau}$ is a type assignment
berghofe@11622
   821
for the type variables occurring in the proposition.
berghofe@11622
   822
\item[\ttindexbold{MinProof} $prfs$]
berghofe@11622
   823
represents a {\em minimal proof} where $prfs$ is a list of theorems,
berghofe@11622
   824
axioms or oracles.
berghofe@11622
   825
\end{ttdescription}
berghofe@11622
   826
Note that there are no separate constructors
berghofe@11622
   827
for abstraction and application on the level of {\em types}, since
berghofe@11622
   828
instantiation of type variables is accomplished via the type assignments
berghofe@11622
   829
attached to {\tt Thm}, {\tt Axm} and {\tt Oracle}.
berghofe@11622
   830
paulson@1590
   831
Each theorem's derivation is stored as the {\tt der} field of its internal
paulson@1590
   832
record: 
paulson@1590
   833
\begin{ttbox} 
berghofe@11622
   834
#2 (#der (rep_thm conjI));
berghofe@11622
   835
{\out PThm (("HOL.conjI", []),}
berghofe@11622
   836
{\out   AbsP ("H", None, AbsP ("H", None, \dots)), \dots, None) %}
berghofe@11622
   837
{\out     None % None : Proofterm.proof}
paulson@1590
   838
\end{ttbox}
berghofe@11622
   839
This proof term identifies a labelled theorem, {\tt conjI} of theory
berghofe@11622
   840
\texttt{HOL}, whose underlying proof is
berghofe@11622
   841
{\tt AbsP ("H", None, AbsP ("H", None, $\dots$))}. 
berghofe@11622
   842
The theorem is applied to two (implicit) term arguments, which correspond
berghofe@11622
   843
to the two variables occurring in its proposition.
paulson@1590
   844
berghofe@11622
   845
Isabelle's inference kernel can produce proof objects with different
berghofe@11622
   846
levels of detail. This is controlled via the global reference variable
berghofe@11622
   847
\ttindexbold{proofs}:
paulson@1590
   848
\begin{ttdescription}
berghofe@11622
   849
\item[proofs := 0;] only record uses of oracles
berghofe@11622
   850
\item[proofs := 1;] record uses of oracles as well as dependencies
berghofe@11622
   851
  on other theorems and axioms
berghofe@11622
   852
\item[proofs := 2;] record inferences in full detail
paulson@1590
   853
\end{ttdescription}
berghofe@11622
   854
Reconstruction and checking of proofs as described in \S\ref{sec:reconstruct_proofs}
berghofe@11622
   855
will not work for proofs constructed with {\tt proofs} set to
berghofe@11622
   856
{\tt 0} or {\tt 1}.
berghofe@11622
   857
Theorems involving oracles will be printed with a
berghofe@11622
   858
suffixed \verb|[!]| to point out the different quality of confidence achieved.
wenzelm@5371
   859
berghofe@7871
   860
\medskip
berghofe@7871
   861
berghofe@11622
   862
The dependencies of theorems can be viewed using the function
berghofe@11622
   863
\ttindexbold{thm_deps}\index{theorems!dependencies}:
berghofe@7871
   864
\begin{ttbox}
berghofe@7871
   865
thm_deps [\(thm@1\), \(\ldots\), \(thm@n\)];
berghofe@7871
   866
\end{ttbox}
berghofe@7871
   867
generates the dependency graph of the theorems $thm@1$, $\ldots$, $thm@n$ and
berghofe@11622
   868
displays it using Isabelle's graph browser. For this to work properly,
berghofe@11622
   869
the theorems in question have to be proved with {\tt proofs} set to a value
berghofe@11622
   870
greater than {\tt 0}. You can use
berghofe@7871
   871
\begin{ttbox}
berghofe@11622
   872
ThmDeps.enable : unit -> unit
berghofe@11622
   873
ThmDeps.disable : unit -> unit
berghofe@7871
   874
\end{ttbox}
berghofe@11622
   875
to set \texttt{proofs} appropriately.
berghofe@11622
   876
berghofe@11622
   877
\subsection{Reconstructing and checking proof terms}\label{sec:reconstruct_proofs}
berghofe@11622
   878
\index{proof terms!reconstructing}
berghofe@11622
   879
\index{proof terms!checking}
berghofe@11622
   880
berghofe@11622
   881
When looking at the above datatype of proofs more closely, one notices that
berghofe@11622
   882
some arguments of constructors are {\it optional}. The reason for this is that
berghofe@11622
   883
keeping a full proof term for each theorem would result in enormous memory
berghofe@11622
   884
requirements. Fortunately, typical proof terms usually contain quite a lot of
berghofe@11622
   885
redundant information that can be reconstructed from the context. Therefore,
berghofe@11622
   886
Isabelle's inference kernel creates only {\em partial} (or {\em implicit})
berghofe@11622
   887
\index{proof terms!partial} proof terms, in which
berghofe@11622
   888
all typing information in terms, all term and type labels of abstractions
berghofe@11622
   889
{\tt AbsP} and {\tt Abst}, and (if possible) some argument terms of
berghofe@11622
   890
\verb!%! are omitted. The following functions are available for
berghofe@11622
   891
reconstructing and checking proof terms:
berghofe@11622
   892
\begin{ttbox}
berghofe@11622
   893
Reconstruct.reconstruct_proof :
berghofe@11622
   894
  Sign.sg -> term -> Proofterm.proof -> Proofterm.proof
berghofe@11622
   895
Reconstruct.expand_proof :
berghofe@11622
   896
  Sign.sg -> string list -> Proofterm.proof -> Proofterm.proof
berghofe@11622
   897
ProofChecker.thm_of_proof : theory -> Proofterm.proof -> thm
berghofe@11622
   898
\end{ttbox}
berghofe@11622
   899
berghofe@11622
   900
\begin{ttdescription}
berghofe@11622
   901
\item[Reconstruct.reconstruct_proof $sg$ $t$ $prf$]
berghofe@11622
   902
turns the partial proof $prf$ into a full proof of the
berghofe@11622
   903
proposition denoted by $t$, with respect to signature $sg$.
berghofe@11622
   904
Reconstruction will fail with an error message if $prf$
berghofe@11622
   905
is not a proof of $t$, is ill-formed, or does not contain
berghofe@11622
   906
sufficient information for reconstruction by
berghofe@11622
   907
{\em higher order pattern unification}
berghofe@11622
   908
\cite{nipkow-patterns, Berghofer-Nipkow:2000:TPHOL}.
berghofe@11622
   909
The latter may only happen for proofs
berghofe@11622
   910
built up ``by hand'' but not for those produced automatically
berghofe@11622
   911
by Isabelle's inference kernel.
berghofe@11622
   912
\item[Reconstruct.expand_proof $sg$
berghofe@11622
   913
  \ttlbrack$name@1$, $\ldots$, $name@n${\ttrbrack} $prf$]
berghofe@11622
   914
expands and reconstructs the proofs of all theorems with names
berghofe@11622
   915
$name@1$, $\ldots$, $name@n$ in the (full) proof $prf$.
berghofe@11622
   916
\item[ProofChecker.thm_of_proof $thy$ $prf$] turns the (full) proof
berghofe@11622
   917
$prf$ into a theorem with respect to theory $thy$ by replaying
berghofe@11622
   918
it using only primitive rules from Isabelle's inference kernel.
berghofe@11622
   919
\end{ttdescription}
berghofe@11622
   920
berghofe@11622
   921
\subsection{Parsing and printing proof terms}
berghofe@11622
   922
\index{proof terms!parsing}
berghofe@11622
   923
\index{proof terms!printing}
berghofe@11622
   924
berghofe@11622
   925
Isabelle offers several functions for parsing and printing
berghofe@11622
   926
proof terms. The concrete syntax for proof terms is described
berghofe@11622
   927
in Fig.\ts\ref{fig:proof_gram}.
berghofe@11622
   928
Implicit term arguments in partial proofs are indicated
berghofe@11622
   929
by ``{\tt _}''.
berghofe@11622
   930
Type arguments for theorems and axioms may be specified using
berghofe@11622
   931
\verb!%! or ``$\cdot$'' with an argument of the form {\tt TYPE($type$)}
berghofe@11622
   932
(see \S\ref{sec:basic_syntax}).
berghofe@11622
   933
They must appear before any other term argument of a theorem
berghofe@11622
   934
or axiom. In contrast to term arguments, type arguments may
berghofe@11622
   935
be completely omitted.
berghofe@11622
   936
\begin{ttbox}
berghofe@11625
   937
ProofSyntax.read_proof : theory -> bool -> string -> Proofterm.proof
berghofe@11625
   938
ProofSyntax.pretty_proof : Sign.sg -> Proofterm.proof -> Pretty.T
berghofe@11625
   939
ProofSyntax.pretty_proof_of : bool -> thm -> Pretty.T
berghofe@11625
   940
ProofSyntax.print_proof_of : bool -> thm -> unit
berghofe@11622
   941
\end{ttbox}
berghofe@11622
   942
\begin{figure}
berghofe@11622
   943
\begin{center}
berghofe@11622
   944
\begin{tabular}{rcl}
berghofe@11622
   945
$proof$  & $=$ & {\tt Lam} $params${\tt .} $proof$ ~~$|$~~
berghofe@11622
   946
                 $\Lambda params${\tt .} $proof$ \\
berghofe@11622
   947
         & $|$ & $proof$ \verb!%! $any$ ~~$|$~~
berghofe@11622
   948
                 $proof$ $\cdot$ $any$ \\
berghofe@11622
   949
         & $|$ & $proof$ \verb!%%! $proof$ ~~$|$~~
berghofe@11622
   950
                 $proof$ {\boldmath$\cdot$} $proof$ \\
berghofe@11622
   951
         & $|$ & $id$ ~~$|$~~ $longid$ \\\\
berghofe@11622
   952
$param$  & $=$ & $idt$ ~~$|$~~ $idt$ {\tt :} $prop$ ~~$|$~~
berghofe@11622
   953
                 {\tt (} $param$ {\tt )} \\\\
berghofe@11622
   954
$params$ & $=$ & $param$ ~~$|$~~ $param$ $params$
berghofe@11622
   955
\end{tabular}
berghofe@11622
   956
\end{center}
berghofe@11622
   957
\caption{Proof term syntax}\label{fig:proof_gram}
berghofe@11622
   958
\end{figure}
berghofe@11622
   959
The function {\tt read_proof} reads in a proof term with
berghofe@11622
   960
respect to a given theory. The boolean flag indicates whether
berghofe@11622
   961
the proof term to be parsed contains explicit typing information
berghofe@11622
   962
to be taken into account.
berghofe@11622
   963
Usually, typing information is left implicit and
berghofe@11622
   964
is inferred during proof reconstruction. The pretty printing
berghofe@11622
   965
functions operating on theorems take a boolean flag as an
berghofe@11622
   966
argument which indicates whether the proof term should
berghofe@11622
   967
be reconstructed before printing.
berghofe@11622
   968
berghofe@11622
   969
The following example (based on Isabelle/HOL) illustrates how
berghofe@11622
   970
to parse and check proof terms. We start by parsing a partial
berghofe@11622
   971
proof term
berghofe@11622
   972
\begin{ttbox}
berghofe@11622
   973
val prf = ProofSyntax.read_proof Main.thy false
berghofe@11622
   974
  "impI % _ % _ %% (Lam H : _. conjE % _ % _ % _ %% H %%
berghofe@11622
   975
     (Lam (H1 : _) H2 : _. conjI % _ % _ %% H2 %% H1))";
berghofe@11622
   976
{\out val prf = PThm (("HOL.impI", []), \dots, \dots, None) % None % None %%}
berghofe@11622
   977
{\out   AbsP ("H", None, PThm (("HOL.conjE", []), \dots, \dots, None) %}
berghofe@11622
   978
{\out     None % None % None %% PBound 0 %%}
berghofe@11622
   979
{\out     AbsP ("H1", None, AbsP ("H2", None, \dots))) : Proofterm.proof}
berghofe@11622
   980
\end{ttbox}
berghofe@11622
   981
The statement to be established by this proof is
berghofe@11622
   982
\begin{ttbox}
berghofe@11622
   983
val t = term_of
berghofe@11622
   984
  (read_cterm (sign_of Main.thy) ("A & B --> B & A", propT));
berghofe@11622
   985
{\out val t = Const ("Trueprop", "bool => prop") $}
berghofe@11622
   986
{\out   (Const ("op -->", "[bool, bool] => bool") $}
berghofe@11622
   987
{\out     \dots $ \dots : Term.term}
berghofe@11622
   988
\end{ttbox}
berghofe@11622
   989
Using {\tt t} we can reconstruct the full proof
berghofe@11622
   990
\begin{ttbox}
berghofe@11622
   991
val prf' = Reconstruct.reconstruct_proof (sign_of Main.thy) t prf;
berghofe@11622
   992
{\out val prf' = PThm (("HOL.impI", []), \dots, \dots, Some []) %}
berghofe@11622
   993
{\out   Some (Const ("op &", \dots) $ Free ("A", \dots) $ Free ("B", \dots)) %}
berghofe@11622
   994
{\out   Some (Const ("op &", \dots) $ Free ("B", \dots) $ Free ("A", \dots)) %%}
berghofe@11622
   995
{\out   AbsP ("H", Some (Const ("Trueprop", \dots) $ \dots), \dots)}
berghofe@11622
   996
{\out     : Proofterm.proof}
berghofe@11622
   997
\end{ttbox}
berghofe@11622
   998
This proof can finally be turned into a theorem
berghofe@11622
   999
\begin{ttbox}
berghofe@11622
  1000
val thm = ProofChecker.thm_of_proof Main.thy prf';
berghofe@11622
  1001
{\out val thm = "A & B --> B & A" : Thm.thm}
berghofe@11622
  1002
\end{ttbox}
berghofe@11622
  1003
berghofe@11622
  1004
\index{proof terms|)}
berghofe@11622
  1005
\index{theorems|)}
berghofe@7871
  1006
wenzelm@5371
  1007
wenzelm@5371
  1008
%%% Local Variables: 
wenzelm@5371
  1009
%%% mode: latex
wenzelm@5371
  1010
%%% TeX-master: "ref"
wenzelm@5371
  1011
%%% End: