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