| 104 |      1 | %% $Id$
 | 
|  |      2 | \chapter{Theorems and Forward Proof}
 | 
|  |      3 | \index{theorems|(}
 | 
| 326 |      4 | 
 | 
| 104 |      5 | Theorems, which represent the axioms, theorems and rules of object-logics,
 | 
| 326 |      6 | have type \mltydx{thm}.  This chapter begins by describing operations that
 | 
|  |      7 | print theorems and that join them in forward proof.  Most theorem
 | 
|  |      8 | operations are intended for advanced applications, such as programming new
 | 
|  |      9 | proof procedures.  Many of these operations refer to signatures, certified
 | 
|  |     10 | terms and certified types, which have the \ML{} types {\tt Sign.sg}, {\tt
 | 
|  |     11 |   Sign.cterm} and {\tt Sign.ctyp} and are discussed in
 | 
| 104 |     12 | Chapter~\ref{theories}.  Beginning users should ignore such complexities
 | 
|  |     13 | --- and skip all but the first section of this chapter.
 | 
|  |     14 | 
 | 
|  |     15 | The theorem operations do not print error messages.  Instead, they raise
 | 
| 326 |     16 | exception~\xdx{THM}\@.  Use \ttindex{print_exn} to display
 | 
| 104 |     17 | exceptions nicely:
 | 
|  |     18 | \begin{ttbox} 
 | 
|  |     19 | allI RS mp  handle e => print_exn e;
 | 
|  |     20 | {\out Exception THM raised:}
 | 
|  |     21 | {\out RSN: no unifiers -- premise 1}
 | 
|  |     22 | {\out (!!x. ?P(x)) ==> ALL x. ?P(x)}
 | 
|  |     23 | {\out [| ?P --> ?Q; ?P |] ==> ?Q}
 | 
|  |     24 | {\out}
 | 
|  |     25 | {\out uncaught exception THM}
 | 
|  |     26 | \end{ttbox}
 | 
|  |     27 | 
 | 
|  |     28 | 
 | 
|  |     29 | \section{Basic operations on theorems}
 | 
|  |     30 | \subsection{Pretty-printing a theorem}
 | 
| 326 |     31 | \index{theorems!printing of}
 | 
| 104 |     32 | \begin{ttbox} 
 | 
| 326 |     33 | prth          : thm -> thm
 | 
|  |     34 | prths         : thm list -> thm list
 | 
|  |     35 | prthq         : thm Sequence.seq -> thm Sequence.seq
 | 
|  |     36 | print_thm     : thm -> unit
 | 
|  |     37 | print_goals   : int -> thm -> unit
 | 
|  |     38 | string_of_thm : thm -> string
 | 
| 104 |     39 | \end{ttbox}
 | 
| 326 |     40 | The first three commands are for interactive use.  They are identity
 | 
|  |     41 | functions that display, then return, their argument.  The \ML{} identifier
 | 
|  |     42 | {\tt it} will refer to the value just displayed.
 | 
|  |     43 | 
 | 
|  |     44 | The others are for use in programs.  Functions with result type {\tt unit}
 | 
|  |     45 | are convenient for imperative programming.
 | 
|  |     46 | 
 | 
|  |     47 | \begin{ttdescription}
 | 
| 104 |     48 | \item[\ttindexbold{prth} {\it thm}]  
 | 
|  |     49 | prints {\it thm\/} at the terminal.
 | 
|  |     50 | 
 | 
|  |     51 | \item[\ttindexbold{prths} {\it thms}]  
 | 
|  |     52 | prints {\it thms}, a list of theorems.
 | 
|  |     53 | 
 | 
|  |     54 | \item[\ttindexbold{prthq} {\it thmq}]  
 | 
|  |     55 | prints {\it thmq}, a sequence of theorems.  It is useful for inspecting
 | 
|  |     56 | the output of a tactic.
 | 
|  |     57 | 
 | 
|  |     58 | \item[\ttindexbold{print_thm} {\it thm}]  
 | 
|  |     59 | prints {\it thm\/} at the terminal.
 | 
|  |     60 | 
 | 
|  |     61 | \item[\ttindexbold{print_goals} {\it limit\/} {\it thm}]  
 | 
|  |     62 | prints {\it thm\/} in goal style, with the premises as subgoals.  It prints
 | 
|  |     63 | at most {\it limit\/} subgoals.  The subgoal module calls {\tt print_goals}
 | 
|  |     64 | to display proof states.
 | 
|  |     65 | 
 | 
|  |     66 | \item[\ttindexbold{string_of_thm} {\it thm}]  
 | 
|  |     67 | converts {\it thm\/} to a string.
 | 
| 326 |     68 | \end{ttdescription}
 | 
| 104 |     69 | 
 | 
|  |     70 | 
 | 
| 326 |     71 | \subsection{Forward proof: joining rules by resolution}
 | 
|  |     72 | \index{theorems!joining by resolution}
 | 
|  |     73 | \index{resolution}\index{forward proof}
 | 
| 104 |     74 | \begin{ttbox} 
 | 
|  |     75 | RSN : thm * (int * thm) -> thm                 \hfill{\bf infix}
 | 
|  |     76 | RS  : thm * thm -> thm                         \hfill{\bf infix}
 | 
|  |     77 | MRS : thm list * thm -> thm                    \hfill{\bf infix}
 | 
|  |     78 | RLN : thm list * (int * thm list) -> thm list  \hfill{\bf infix}
 | 
|  |     79 | RL  : thm list * thm list -> thm list          \hfill{\bf infix}
 | 
| 326 |     80 | MRL : thm list list * thm list -> thm list     \hfill{\bf infix}
 | 
| 104 |     81 | \end{ttbox}
 | 
| 326 |     82 | Joining rules together is a simple way of deriving new rules.  These
 | 
| 104 |     83 | functions are especially useful with destruction rules.
 | 
| 326 |     84 | \begin{ttdescription}
 | 
| 104 |     85 | \item[\tt$thm@1$ RSN $(i,thm@2)$] \indexbold{*RSN} 
 | 
| 326 |     86 |   resolves the conclusion of $thm@1$ with the $i$th premise of~$thm@2$.
 | 
|  |     87 |   Unless there is precisely one resolvent it raises exception
 | 
|  |     88 |   \xdx{THM}; in that case, use {\tt RLN}.
 | 
| 104 |     89 | 
 | 
|  |     90 | \item[\tt$thm@1$ RS $thm@2$] \indexbold{*RS} 
 | 
|  |     91 | abbreviates \hbox{\tt$thm@1$ RSN $(1,thm@2)$}.  Thus, it resolves the
 | 
|  |     92 | conclusion of $thm@1$ with the first premise of~$thm@2$.
 | 
|  |     93 | 
 | 
|  |     94 | \item[\tt {$[thm@1,\ldots,thm@n]$} MRS $thm$] \indexbold{*MRS} 
 | 
| 332 |     95 |   uses {\tt RSN} to resolve $thm@i$ against premise~$i$ of $thm$, for
 | 
| 104 |     96 |   $i=n$, \ldots,~1.  This applies $thm@n$, \ldots, $thm@1$ to the first $n$
 | 
|  |     97 |   premises of $thm$.  Because the theorems are used from right to left, it
 | 
|  |     98 |   does not matter if the $thm@i$ create new premises.  {\tt MRS} is useful
 | 
|  |     99 |   for expressing proof trees.
 | 
|  |    100 | 
 | 
| 151 |    101 | \item[\tt$thms@1$ RLN $(i,thms@2)$] \indexbold{*RLN} 
 | 
| 326 |    102 |   joins lists of theorems.  For every $thm@1$ in $thms@1$ and $thm@2$ in
 | 
|  |    103 |   $thms@2$, it resolves the conclusion of $thm@1$ with the $i$th premise
 | 
|  |    104 |   of~$thm@2$, accumulating the results. 
 | 
| 104 |    105 | 
 | 
| 151 |    106 | \item[\tt$thms@1$ RL $thms@2$] \indexbold{*RL} 
 | 
|  |    107 | abbreviates \hbox{\tt$thms@1$ RLN $(1,thms@2)$}. 
 | 
| 104 |    108 | 
 | 
|  |    109 | \item[\tt {$[thms@1,\ldots,thms@n]$} MRL $thms$] \indexbold{*MRL} 
 | 
|  |    110 | is analogous to {\tt MRS}, but combines theorem lists rather than theorems.
 | 
|  |    111 | It too is useful for expressing proof trees.
 | 
| 326 |    112 | \end{ttdescription}
 | 
| 104 |    113 | 
 | 
|  |    114 | 
 | 
|  |    115 | \subsection{Expanding definitions in theorems}
 | 
| 326 |    116 | \index{meta-rewriting!in theorems}
 | 
| 104 |    117 | \begin{ttbox} 
 | 
|  |    118 | rewrite_rule       : thm list -> thm -> thm
 | 
|  |    119 | rewrite_goals_rule : thm list -> thm -> thm
 | 
|  |    120 | \end{ttbox}
 | 
| 326 |    121 | \begin{ttdescription}
 | 
| 104 |    122 | \item[\ttindexbold{rewrite_rule} {\it defs} {\it thm}]  
 | 
|  |    123 | unfolds the {\it defs} throughout the theorem~{\it thm}.
 | 
|  |    124 | 
 | 
|  |    125 | \item[\ttindexbold{rewrite_goals_rule} {\it defs} {\it thm}]  
 | 
|  |    126 | unfolds the {\it defs} in the premises of~{\it thm}, but leaves the
 | 
|  |    127 | conclusion unchanged.  This rule underlies \ttindex{rewrite_goals_tac}, but 
 | 
|  |    128 | serves little purpose in forward proof.
 | 
| 326 |    129 | \end{ttdescription}
 | 
| 104 |    130 | 
 | 
|  |    131 | 
 | 
| 326 |    132 | \subsection{Instantiating a theorem}
 | 
|  |    133 | \index{instantiation}
 | 
| 286 |    134 | \begin{ttbox}
 | 
| 104 |    135 | read_instantiate    :            (string*string)list -> thm -> thm
 | 
|  |    136 | read_instantiate_sg : Sign.sg -> (string*string)list -> thm -> thm
 | 
|  |    137 | cterm_instantiate   :    (Sign.cterm*Sign.cterm)list -> thm -> thm
 | 
|  |    138 | \end{ttbox}
 | 
|  |    139 | These meta-rules instantiate type and term unknowns in a theorem.  They are
 | 
|  |    140 | occasionally useful.  They can prevent difficulties with higher-order
 | 
|  |    141 | unification, and define specialized versions of rules.
 | 
| 326 |    142 | \begin{ttdescription}
 | 
| 104 |    143 | \item[\ttindexbold{read_instantiate} {\it insts} {\it thm}] 
 | 
|  |    144 | processes the instantiations {\it insts} and instantiates the rule~{\it
 | 
|  |    145 | thm}.  The processing of instantiations is described
 | 
| 326 |    146 | in \S\ref{res_inst_tac}, under {\tt res_inst_tac}.  
 | 
| 104 |    147 | 
 | 
|  |    148 | Use {\tt res_inst_tac}, not {\tt read_instantiate}, to instantiate a rule
 | 
|  |    149 | and refine a particular subgoal.  The tactic allows instantiation by the
 | 
|  |    150 | subgoal's parameters, and reads the instantiations using the signature
 | 
| 326 |    151 | associated with the proof state.
 | 
|  |    152 | 
 | 
|  |    153 | Use {\tt read_instantiate_sg} below if {\it insts\/} appears to be treated
 | 
|  |    154 | incorrectly.
 | 
| 104 |    155 | 
 | 
| 326 |    156 | \item[\ttindexbold{read_instantiate_sg} {\it sg} {\it insts} {\it thm}]
 | 
|  |    157 |   resembles \hbox{\tt read_instantiate {\it insts} {\it thm}}, but reads
 | 
|  |    158 |   the instantiations under signature~{\it sg}.  This is necessary to
 | 
|  |    159 |   instantiate a rule from a general theory, such as first-order logic,
 | 
|  |    160 |   using the notation of some specialized theory.  Use the function {\tt
 | 
|  |    161 |     sign_of} to get a theory's signature.
 | 
| 104 |    162 | 
 | 
|  |    163 | \item[\ttindexbold{cterm_instantiate} {\it ctpairs} {\it thm}] 
 | 
|  |    164 | is similar to {\tt read_instantiate}, but the instantiations are provided
 | 
|  |    165 | as pairs of certified terms, not as strings to be read.
 | 
| 326 |    166 | \end{ttdescription}
 | 
| 104 |    167 | 
 | 
|  |    168 | 
 | 
|  |    169 | \subsection{Miscellaneous forward rules}
 | 
| 326 |    170 | \index{theorems!standardizing}
 | 
| 104 |    171 | \begin{ttbox} 
 | 
| 332 |    172 | standard         :           thm -> thm
 | 
|  |    173 | zero_var_indexes :           thm -> thm
 | 
|  |    174 | make_elim        :           thm -> thm
 | 
| 104 |    175 | rule_by_tactic   : tactic -> thm -> thm
 | 
|  |    176 | \end{ttbox}
 | 
| 326 |    177 | \begin{ttdescription}
 | 
| 104 |    178 | \item[\ttindexbold{standard} $thm$]  
 | 
|  |    179 | puts $thm$ into the standard form of object-rules.  It discharges all
 | 
| 332 |    180 | meta-assumptions, replaces free variables by schematic variables, and
 | 
| 104 |    181 | renames schematic variables to have subscript zero.
 | 
|  |    182 | 
 | 
|  |    183 | \item[\ttindexbold{zero_var_indexes} $thm$] 
 | 
|  |    184 | makes all schematic variables have subscript zero, renaming them to avoid
 | 
|  |    185 | clashes. 
 | 
|  |    186 | 
 | 
|  |    187 | \item[\ttindexbold{make_elim} $thm$] 
 | 
|  |    188 | \index{rules!converting destruction to elimination}
 | 
|  |    189 | converts $thm$, a destruction rule of the form $\List{P@1;\ldots;P@m}\Imp
 | 
|  |    190 | Q$, to the elimination rule $\List{P@1; \ldots; P@m; Q\Imp R}\Imp R$.  This
 | 
|  |    191 | is the basis for destruct-resolution: {\tt dresolve_tac}, etc.
 | 
|  |    192 | 
 | 
|  |    193 | \item[\ttindexbold{rule_by_tactic} {\it tac} {\it thm}] 
 | 
|  |    194 |   applies {\it tac\/} to the {\it thm}, freezing its variables first, then
 | 
|  |    195 |   yields the proof state returned by the tactic.  In typical usage, the
 | 
|  |    196 |   {\it thm\/} represents an instance of a rule with several premises, some
 | 
|  |    197 |   with contradictory assumptions (because of the instantiation).  The
 | 
|  |    198 |   tactic proves those subgoals and does whatever else it can, and returns
 | 
|  |    199 |   whatever is left.
 | 
| 326 |    200 | \end{ttdescription}
 | 
| 104 |    201 | 
 | 
|  |    202 | 
 | 
|  |    203 | \subsection{Taking a theorem apart}
 | 
| 326 |    204 | \index{theorems!taking apart}
 | 
| 104 |    205 | \index{flex-flex constraints}
 | 
|  |    206 | \begin{ttbox} 
 | 
|  |    207 | concl_of      : thm -> term
 | 
|  |    208 | prems_of      : thm -> term list
 | 
|  |    209 | nprems_of     : thm -> int
 | 
|  |    210 | tpairs_of     : thm -> (term*term)list
 | 
|  |    211 | stamps_of_thy : thm -> string ref list
 | 
| 286 |    212 | dest_state    : thm*int -> (term*term)list*term list*term*term
 | 
| 104 |    213 | rep_thm       : thm -> \{prop:term, hyps:term list, 
 | 
|  |    214 |                         maxidx:int, sign:Sign.sg\}
 | 
|  |    215 | \end{ttbox}
 | 
| 326 |    216 | \begin{ttdescription}
 | 
| 104 |    217 | \item[\ttindexbold{concl_of} $thm$] 
 | 
|  |    218 | returns the conclusion of $thm$ as a term.
 | 
|  |    219 | 
 | 
|  |    220 | \item[\ttindexbold{prems_of} $thm$] 
 | 
|  |    221 | returns the premises of $thm$ as a list of terms.
 | 
|  |    222 | 
 | 
|  |    223 | \item[\ttindexbold{nprems_of} $thm$] 
 | 
| 286 |    224 | returns the number of premises in $thm$, and is equivalent to {\tt
 | 
|  |    225 |   length(prems_of~$thm$)}.
 | 
| 104 |    226 | 
 | 
|  |    227 | \item[\ttindexbold{tpairs_of} $thm$] 
 | 
|  |    228 | returns the flex-flex constraints of $thm$.
 | 
|  |    229 | 
 | 
|  |    230 | \item[\ttindexbold{stamps_of_thm} $thm$] 
 | 
| 332 |    231 | returns the \rmindex{stamps} of the signature associated with~$thm$.
 | 
| 104 |    232 | 
 | 
|  |    233 | \item[\ttindexbold{dest_state} $(thm,i)$] 
 | 
|  |    234 | decomposes $thm$ as a tuple containing a list of flex-flex constraints, a
 | 
|  |    235 | list of the subgoals~1 to~$i-1$, subgoal~$i$, and the rest of the theorem
 | 
|  |    236 | (this will be an implication if there are more than $i$ subgoals).
 | 
|  |    237 | 
 | 
|  |    238 | \item[\ttindexbold{rep_thm} $thm$] 
 | 
|  |    239 | decomposes $thm$ as a record containing the statement of~$thm$, its list of
 | 
| 332 |    240 | meta-assumptions, the maximum subscript of its unknowns, and its signature.
 | 
| 326 |    241 | \end{ttdescription}
 | 
| 104 |    242 | 
 | 
|  |    243 | 
 | 
|  |    244 | \subsection{Tracing flags for unification}
 | 
| 326 |    245 | \index{tracing!of unification}
 | 
| 104 |    246 | \begin{ttbox} 
 | 
|  |    247 | Unify.trace_simp   : bool ref \hfill{\bf initially false}
 | 
|  |    248 | Unify.trace_types  : bool ref \hfill{\bf initially false}
 | 
|  |    249 | Unify.trace_bound  : int ref \hfill{\bf initially 10}
 | 
|  |    250 | Unify.search_bound : int ref \hfill{\bf initially 20}
 | 
|  |    251 | \end{ttbox}
 | 
|  |    252 | Tracing the search may be useful when higher-order unification behaves
 | 
|  |    253 | unexpectedly.  Letting {\tt res_inst_tac} circumvent the problem is easier,
 | 
|  |    254 | though.
 | 
| 326 |    255 | \begin{ttdescription}
 | 
|  |    256 | \item[Unify.trace_simp := true;] 
 | 
| 104 |    257 | causes tracing of the simplification phase.
 | 
|  |    258 | 
 | 
| 326 |    259 | \item[Unify.trace_types := true;] 
 | 
| 104 |    260 | generates warnings of incompleteness, when unification is not considering
 | 
|  |    261 | all possible instantiations of type unknowns.
 | 
|  |    262 | 
 | 
| 326 |    263 | \item[Unify.trace_bound := $n$;] 
 | 
| 104 |    264 | causes unification to print tracing information once it reaches depth~$n$.
 | 
|  |    265 | Use $n=0$ for full tracing.  At the default value of~10, tracing
 | 
|  |    266 | information is almost never printed.
 | 
|  |    267 | 
 | 
| 326 |    268 | \item[Unify.search_bound := $n$;] 
 | 
| 104 |    269 | causes unification to limit its search to depth~$n$.  Because of this
 | 
|  |    270 | bound, higher-order unification cannot return an infinite sequence, though
 | 
|  |    271 | it can return a very long one.  The search rarely approaches the default
 | 
|  |    272 | value of~20.  If the search is cut off, unification prints {\tt
 | 
|  |    273 | ***Unification bound exceeded}.
 | 
| 326 |    274 | \end{ttdescription}
 | 
| 104 |    275 | 
 | 
|  |    276 | 
 | 
|  |    277 | \section{Primitive meta-level inference rules}
 | 
|  |    278 | \index{meta-rules|(}
 | 
|  |    279 | These implement the meta-logic in {\sc lcf} style, as functions from theorems
 | 
|  |    280 | to theorems.  They are, rarely, useful for deriving results in the pure
 | 
|  |    281 | theory.  Mainly, they are included for completeness, and most users should
 | 
| 326 |    282 | not bother with them.  The meta-rules raise exception \xdx{THM} to signal
 | 
| 104 |    283 | malformed premises, incompatible signatures and similar errors.
 | 
|  |    284 | 
 | 
| 326 |    285 | \index{meta-assumptions}
 | 
| 104 |    286 | The meta-logic uses natural deduction.  Each theorem may depend on
 | 
| 332 |    287 | meta-level assumptions.  Certain rules, such as $({\Imp}I)$,
 | 
| 104 |    288 | discharge assumptions; in most other rules, the conclusion depends on all
 | 
|  |    289 | of the assumptions of the premises.  Formally, the system works with
 | 
|  |    290 | assertions of the form
 | 
|  |    291 | \[ \phi \quad [\phi@1,\ldots,\phi@n], \]
 | 
| 332 |    292 | where $\phi@1$,~\ldots,~$\phi@n$ are the assumptions.  Do not confuse
 | 
| 104 |    293 | meta-level assumptions with the object-level assumptions in a subgoal,
 | 
|  |    294 | which are represented in the meta-logic using~$\Imp$.
 | 
|  |    295 | 
 | 
|  |    296 | Each theorem has a signature.  Certified terms have a signature.  When a
 | 
|  |    297 | rule takes several premises and certified terms, it merges the signatures
 | 
|  |    298 | to make a signature for the conclusion.  This fails if the signatures are
 | 
|  |    299 | incompatible. 
 | 
|  |    300 | 
 | 
| 326 |    301 | \index{meta-implication}
 | 
| 332 |    302 | The {\bf implication} rules are $({\Imp}I)$
 | 
| 104 |    303 | and $({\Imp}E)$:
 | 
|  |    304 | \[ \infer[({\Imp}I)]{\phi\Imp \psi}{\infer*{\psi}{[\phi]}}  \qquad
 | 
|  |    305 |    \infer[({\Imp}E)]{\psi}{\phi\Imp \psi & \phi}  \]
 | 
|  |    306 | 
 | 
| 326 |    307 | \index{meta-equality}
 | 
| 104 |    308 | Equality of truth values means logical equivalence:
 | 
|  |    309 | \[ \infer[({\equiv}I)]{\phi\equiv\psi}{\infer*{\psi}{[\phi]} &
 | 
| 286 |    310 |                                        \infer*{\phi}{[\psi]}}  
 | 
| 104 |    311 |    \qquad
 | 
|  |    312 |    \infer[({\equiv}E)]{\psi}{\phi\equiv \psi & \phi}   \]
 | 
|  |    313 | 
 | 
| 332 |    314 | The {\bf equality} rules are reflexivity, symmetry, and transitivity:
 | 
| 104 |    315 | \[ {a\equiv a}\,(refl)  \qquad
 | 
|  |    316 |    \infer[(sym)]{b\equiv a}{a\equiv b}  \qquad
 | 
|  |    317 |    \infer[(trans)]{a\equiv c}{a\equiv b & b\equiv c}   \]
 | 
|  |    318 | 
 | 
| 326 |    319 | \index{lambda calc@$\lambda$-calculus}
 | 
| 104 |    320 | The $\lambda$-conversions are $\alpha$-conversion, $\beta$-conversion, and
 | 
|  |    321 | extensionality:\footnote{$\alpha$-conversion holds if $y$ is not free
 | 
|  |    322 | in~$a$; $(ext)$ holds if $x$ is not free in the assumptions, $f$, or~$g$.}
 | 
|  |    323 | \[ {(\lambda x.a) \equiv (\lambda y.a[y/x])}    \qquad
 | 
|  |    324 |    {((\lambda x.a)(b)) \equiv a[b/x]}           \qquad
 | 
|  |    325 |    \infer[(ext)]{f\equiv g}{f(x) \equiv g(x)}   \]
 | 
|  |    326 | 
 | 
| 332 |    327 | The {\bf abstraction} and {\bf combination} rules let conversions be
 | 
|  |    328 | applied to subterms:\footnote{Abstraction holds if $x$ is not free in the
 | 
| 104 |    329 | assumptions.}
 | 
|  |    330 | \[  \infer[(abs)]{(\lambda x.a) \equiv (\lambda x.b)}{a\equiv b}   \qquad
 | 
|  |    331 |     \infer[(comb)]{f(a)\equiv g(b)}{f\equiv g & a\equiv b}   \]
 | 
|  |    332 | 
 | 
| 326 |    333 | \index{meta-quantifiers}
 | 
| 332 |    334 | The {\bf universal quantification} rules are $(\Forall I)$ and $(\Forall
 | 
| 104 |    335 | E)$:\footnote{$(\Forall I)$ holds if $x$ is not free in the assumptions.}
 | 
|  |    336 | \[ \infer[(\Forall I)]{\Forall x.\phi}{\phi}        \qquad
 | 
| 286 |    337 |    \infer[(\Forall E)]{\phi[b/x]}{\Forall x.\phi}   \]
 | 
| 104 |    338 | 
 | 
|  |    339 | 
 | 
| 326 |    340 | \subsection{Assumption rule}
 | 
|  |    341 | \index{meta-assumptions}
 | 
| 104 |    342 | \begin{ttbox} 
 | 
|  |    343 | assume: Sign.cterm -> thm
 | 
|  |    344 | \end{ttbox}
 | 
| 326 |    345 | \begin{ttdescription}
 | 
| 104 |    346 | \item[\ttindexbold{assume} $ct$] 
 | 
| 332 |    347 | makes the theorem \(\phi \;[\phi]\), where $\phi$ is the value of~$ct$.
 | 
| 104 |    348 | The rule checks that $ct$ has type $prop$ and contains no unknowns, which
 | 
| 332 |    349 | are not allowed in assumptions.
 | 
| 326 |    350 | \end{ttdescription}
 | 
| 104 |    351 | 
 | 
| 326 |    352 | \subsection{Implication rules}
 | 
|  |    353 | \index{meta-implication}
 | 
| 104 |    354 | \begin{ttbox} 
 | 
|  |    355 | implies_intr      : Sign.cterm -> thm -> thm
 | 
|  |    356 | implies_intr_list : Sign.cterm list -> thm -> thm
 | 
|  |    357 | implies_intr_hyps : thm -> thm
 | 
|  |    358 | implies_elim      : thm -> thm -> thm
 | 
|  |    359 | implies_elim_list : thm -> thm list -> thm
 | 
|  |    360 | \end{ttbox}
 | 
| 326 |    361 | \begin{ttdescription}
 | 
| 104 |    362 | \item[\ttindexbold{implies_intr} $ct$ $thm$] 
 | 
|  |    363 | is $({\Imp}I)$, where $ct$ is the assumption to discharge, say~$\phi$.  It
 | 
| 332 |    364 | maps the premise~$\psi$ to the conclusion $\phi\Imp\psi$, removing all
 | 
|  |    365 | occurrences of~$\phi$ from the assumptions.  The rule checks that $ct$ has
 | 
|  |    366 | type $prop$. 
 | 
| 104 |    367 | 
 | 
|  |    368 | \item[\ttindexbold{implies_intr_list} $cts$ $thm$] 
 | 
|  |    369 | applies $({\Imp}I)$ repeatedly, on every element of the list~$cts$.
 | 
|  |    370 | 
 | 
|  |    371 | \item[\ttindexbold{implies_intr_hyps} $thm$] 
 | 
| 332 |    372 | applies $({\Imp}I)$ to discharge all the hypotheses (assumptions) of~$thm$.
 | 
|  |    373 | It maps the premise $\phi \; [\phi@1,\ldots,\phi@n]$ to the conclusion
 | 
| 104 |    374 | $\List{\phi@1,\ldots,\phi@n}\Imp\phi$.
 | 
|  |    375 | 
 | 
|  |    376 | \item[\ttindexbold{implies_elim} $thm@1$ $thm@2$] 
 | 
|  |    377 | applies $({\Imp}E)$ to $thm@1$ and~$thm@2$.  It maps the premises $\phi\Imp
 | 
|  |    378 | \psi$ and $\phi$ to the conclusion~$\psi$.
 | 
|  |    379 | 
 | 
|  |    380 | \item[\ttindexbold{implies_elim_list} $thm$ $thms$] 
 | 
|  |    381 | applies $({\Imp}E)$ repeatedly to $thm$, using each element of~$thms$ in
 | 
| 151 |    382 | turn.  It maps the premises $\List{\phi@1,\ldots,\phi@n}\Imp\psi$ and
 | 
| 104 |    383 | $\phi@1$,\ldots,$\phi@n$ to the conclusion~$\psi$.
 | 
| 326 |    384 | \end{ttdescription}
 | 
| 104 |    385 | 
 | 
| 326 |    386 | \subsection{Logical equivalence rules}
 | 
|  |    387 | \index{meta-equality}
 | 
| 104 |    388 | \begin{ttbox} 
 | 
| 326 |    389 | equal_intr : thm -> thm -> thm 
 | 
|  |    390 | equal_elim : thm -> thm -> thm
 | 
| 104 |    391 | \end{ttbox}
 | 
| 326 |    392 | \begin{ttdescription}
 | 
| 104 |    393 | \item[\ttindexbold{equal_intr} $thm@1$ $thm@2$] 
 | 
| 332 |    394 | applies $({\equiv}I)$ to $thm@1$ and~$thm@2$.  It maps the premises~$\psi$
 | 
|  |    395 | and~$\phi$ to the conclusion~$\phi\equiv\psi$; the assumptions are those of
 | 
|  |    396 | the first premise with~$\phi$ removed, plus those of
 | 
|  |    397 | the second premise with~$\psi$ removed.
 | 
| 104 |    398 | 
 | 
|  |    399 | \item[\ttindexbold{equal_elim} $thm@1$ $thm@2$] 
 | 
|  |    400 | applies $({\equiv}E)$ to $thm@1$ and~$thm@2$.  It maps the premises
 | 
|  |    401 | $\phi\equiv\psi$ and $\phi$ to the conclusion~$\psi$.
 | 
| 326 |    402 | \end{ttdescription}
 | 
| 104 |    403 | 
 | 
|  |    404 | 
 | 
|  |    405 | \subsection{Equality rules}
 | 
| 326 |    406 | \index{meta-equality}
 | 
| 104 |    407 | \begin{ttbox} 
 | 
|  |    408 | reflexive  : Sign.cterm -> thm
 | 
|  |    409 | symmetric  : thm -> thm
 | 
|  |    410 | transitive : thm -> thm -> thm
 | 
|  |    411 | \end{ttbox}
 | 
| 326 |    412 | \begin{ttdescription}
 | 
| 104 |    413 | \item[\ttindexbold{reflexive} $ct$] 
 | 
| 151 |    414 | makes the theorem \(ct\equiv ct\). 
 | 
| 104 |    415 | 
 | 
|  |    416 | \item[\ttindexbold{symmetric} $thm$] 
 | 
|  |    417 | maps the premise $a\equiv b$ to the conclusion $b\equiv a$.
 | 
|  |    418 | 
 | 
|  |    419 | \item[\ttindexbold{transitive} $thm@1$ $thm@2$] 
 | 
|  |    420 | maps the premises $a\equiv b$ and $b\equiv c$ to the conclusion~${a\equiv c}$.
 | 
| 326 |    421 | \end{ttdescription}
 | 
| 104 |    422 | 
 | 
|  |    423 | 
 | 
|  |    424 | \subsection{The $\lambda$-conversion rules}
 | 
| 326 |    425 | \index{lambda calc@$\lambda$-calculus}
 | 
| 104 |    426 | \begin{ttbox} 
 | 
|  |    427 | beta_conversion : Sign.cterm -> thm
 | 
|  |    428 | extensional     : thm -> thm
 | 
|  |    429 | abstract_rule   : string -> Sign.cterm -> thm -> thm
 | 
|  |    430 | combination     : thm -> thm -> thm
 | 
|  |    431 | \end{ttbox} 
 | 
| 326 |    432 | There is no rule for $\alpha$-conversion because Isabelle regards
 | 
|  |    433 | $\alpha$-convertible theorems as equal.
 | 
|  |    434 | \begin{ttdescription}
 | 
| 104 |    435 | \item[\ttindexbold{beta_conversion} $ct$] 
 | 
|  |    436 | makes the theorem $((\lambda x.a)(b)) \equiv a[b/x]$, where $ct$ is the
 | 
|  |    437 | term $(\lambda x.a)(b)$.
 | 
|  |    438 | 
 | 
|  |    439 | \item[\ttindexbold{extensional} $thm$] 
 | 
|  |    440 | maps the premise $f(x) \equiv g(x)$ to the conclusion $f\equiv g$.
 | 
|  |    441 | Parameter~$x$ is taken from the premise.  It may be an unknown or a free
 | 
| 332 |    442 | variable (provided it does not occur in the assumptions); it must not occur
 | 
| 104 |    443 | in $f$ or~$g$.
 | 
|  |    444 | 
 | 
|  |    445 | \item[\ttindexbold{abstract_rule} $v$ $x$ $thm$] 
 | 
|  |    446 | maps the premise $a\equiv b$ to the conclusion $(\lambda x.a) \equiv
 | 
|  |    447 | (\lambda x.b)$, abstracting over all occurrences (if any!) of~$x$.
 | 
|  |    448 | Parameter~$x$ is supplied as a cterm.  It may be an unknown or a free
 | 
| 332 |    449 | variable (provided it does not occur in the assumptions).  In the
 | 
| 104 |    450 | conclusion, the bound variable is named~$v$.
 | 
|  |    451 | 
 | 
|  |    452 | \item[\ttindexbold{combination} $thm@1$ $thm@2$] 
 | 
|  |    453 | maps the premises $f\equiv g$ and $a\equiv b$ to the conclusion~$f(a)\equiv
 | 
|  |    454 | g(b)$.
 | 
| 326 |    455 | \end{ttdescription}
 | 
| 104 |    456 | 
 | 
|  |    457 | 
 | 
| 326 |    458 | \subsection{Forall introduction rules}
 | 
|  |    459 | \index{meta-quantifiers}
 | 
| 104 |    460 | \begin{ttbox} 
 | 
|  |    461 | forall_intr       : Sign.cterm      -> thm -> thm
 | 
|  |    462 | forall_intr_list  : Sign.cterm list -> thm -> thm
 | 
|  |    463 | forall_intr_frees :                    thm -> thm
 | 
|  |    464 | \end{ttbox}
 | 
|  |    465 | 
 | 
| 326 |    466 | \begin{ttdescription}
 | 
| 104 |    467 | \item[\ttindexbold{forall_intr} $x$ $thm$] 
 | 
|  |    468 | applies $({\Forall}I)$, abstracting over all occurrences (if any!) of~$x$.
 | 
|  |    469 | The rule maps the premise $\phi$ to the conclusion $\Forall x.\phi$.
 | 
|  |    470 | Parameter~$x$ is supplied as a cterm.  It may be an unknown or a free
 | 
| 332 |    471 | variable (provided it does not occur in the assumptions).
 | 
| 104 |    472 | 
 | 
|  |    473 | \item[\ttindexbold{forall_intr_list} $xs$ $thm$] 
 | 
|  |    474 | applies $({\Forall}I)$ repeatedly, on every element of the list~$xs$.
 | 
|  |    475 | 
 | 
|  |    476 | \item[\ttindexbold{forall_intr_frees} $thm$] 
 | 
|  |    477 | applies $({\Forall}I)$ repeatedly, generalizing over all the free variables
 | 
|  |    478 | of the premise.
 | 
| 326 |    479 | \end{ttdescription}
 | 
| 104 |    480 | 
 | 
|  |    481 | 
 | 
| 326 |    482 | \subsection{Forall elimination rules}
 | 
| 104 |    483 | \begin{ttbox} 
 | 
|  |    484 | forall_elim       : Sign.cterm      -> thm -> thm
 | 
|  |    485 | forall_elim_list  : Sign.cterm list -> thm -> thm
 | 
|  |    486 | forall_elim_var   :             int -> thm -> thm
 | 
|  |    487 | forall_elim_vars  :             int -> thm -> thm
 | 
|  |    488 | \end{ttbox}
 | 
|  |    489 | 
 | 
| 326 |    490 | \begin{ttdescription}
 | 
| 104 |    491 | \item[\ttindexbold{forall_elim} $ct$ $thm$] 
 | 
|  |    492 | applies $({\Forall}E)$, mapping the premise $\Forall x.\phi$ to the conclusion
 | 
|  |    493 | $\phi[ct/x]$.  The rule checks that $ct$ and $x$ have the same type.
 | 
|  |    494 | 
 | 
|  |    495 | \item[\ttindexbold{forall_elim_list} $cts$ $thm$] 
 | 
|  |    496 | applies $({\Forall}E)$ repeatedly, on every element of the list~$cts$.
 | 
|  |    497 | 
 | 
|  |    498 | \item[\ttindexbold{forall_elim_var} $k$ $thm$] 
 | 
|  |    499 | applies $({\Forall}E)$, mapping the premise $\Forall x.\phi$ to the conclusion
 | 
|  |    500 | $\phi[\Var{x@k}/x]$.  Thus, it replaces the outermost $\Forall$-bound
 | 
|  |    501 | variable by an unknown having subscript~$k$.
 | 
|  |    502 | 
 | 
|  |    503 | \item[\ttindexbold{forall_elim_vars} $ks$ $thm$] 
 | 
|  |    504 | applies {\tt forall_elim_var} repeatedly, for every element of the list~$ks$.
 | 
| 326 |    505 | \end{ttdescription}
 | 
| 104 |    506 | 
 | 
| 326 |    507 | \subsection{Instantiation of unknowns}
 | 
|  |    508 | \index{instantiation}
 | 
| 104 |    509 | \begin{ttbox} 
 | 
| 286 |    510 | instantiate: (indexname*Sign.ctyp)list * 
 | 
|  |    511 |              (Sign.cterm*Sign.cterm)list  -> thm -> thm
 | 
| 104 |    512 | \end{ttbox}
 | 
| 326 |    513 | \begin{ttdescription}
 | 
|  |    514 | \item[\ttindexbold{instantiate} ($tyinsts$, $insts$) $thm$] 
 | 
|  |    515 | simultaneously substitutes types for type unknowns (the
 | 
| 104 |    516 | $tyinsts$) and terms for term unknowns (the $insts$).  Instantiations are
 | 
|  |    517 | given as $(v,t)$ pairs, where $v$ is an unknown and $t$ is a term (of the
 | 
|  |    518 | same type as $v$) or a type (of the same sort as~$v$).  All the unknowns
 | 
|  |    519 | must be distinct.  The rule normalizes its conclusion.
 | 
| 326 |    520 | \end{ttdescription}
 | 
| 104 |    521 | 
 | 
|  |    522 | 
 | 
| 326 |    523 | \subsection{Freezing/thawing type unknowns}
 | 
|  |    524 | \index{type unknowns!freezing/thawing of}
 | 
| 104 |    525 | \begin{ttbox} 
 | 
|  |    526 | freezeT: thm -> thm
 | 
|  |    527 | varifyT: thm -> thm
 | 
|  |    528 | \end{ttbox}
 | 
| 326 |    529 | \begin{ttdescription}
 | 
| 104 |    530 | \item[\ttindexbold{freezeT} $thm$] 
 | 
|  |    531 | converts all the type unknowns in $thm$ to free type variables.
 | 
|  |    532 | 
 | 
|  |    533 | \item[\ttindexbold{varifyT} $thm$] 
 | 
|  |    534 | converts all the free type variables in $thm$ to type unknowns.
 | 
| 326 |    535 | \end{ttdescription}
 | 
| 104 |    536 | 
 | 
|  |    537 | 
 | 
|  |    538 | \section{Derived rules for goal-directed proof}
 | 
|  |    539 | Most of these rules have the sole purpose of implementing particular
 | 
|  |    540 | tactics.  There are few occasions for applying them directly to a theorem.
 | 
|  |    541 | 
 | 
|  |    542 | \subsection{Proof by assumption}
 | 
| 326 |    543 | \index{meta-assumptions}
 | 
| 104 |    544 | \begin{ttbox} 
 | 
|  |    545 | assumption    : int -> thm -> thm Sequence.seq
 | 
|  |    546 | eq_assumption : int -> thm -> thm
 | 
|  |    547 | \end{ttbox}
 | 
| 326 |    548 | \begin{ttdescription}
 | 
| 104 |    549 | \item[\ttindexbold{assumption} {\it i} $thm$] 
 | 
|  |    550 | attempts to solve premise~$i$ of~$thm$ by assumption.
 | 
|  |    551 | 
 | 
|  |    552 | \item[\ttindexbold{eq_assumption}] 
 | 
|  |    553 | is like {\tt assumption} but does not use unification.
 | 
| 326 |    554 | \end{ttdescription}
 | 
| 104 |    555 | 
 | 
|  |    556 | 
 | 
|  |    557 | \subsection{Resolution}
 | 
| 326 |    558 | \index{resolution}
 | 
| 104 |    559 | \begin{ttbox} 
 | 
|  |    560 | biresolution : bool -> (bool*thm)list -> int -> thm
 | 
|  |    561 |                -> thm Sequence.seq
 | 
|  |    562 | \end{ttbox}
 | 
| 326 |    563 | \begin{ttdescription}
 | 
| 104 |    564 | \item[\ttindexbold{biresolution} $match$ $rules$ $i$ $state$] 
 | 
| 326 |    565 | performs bi-resolution on subgoal~$i$ of $state$, using the list of $\it
 | 
| 104 |    566 | (flag,rule)$ pairs.  For each pair, it applies resolution if the flag
 | 
|  |    567 | is~{\tt false} and elim-resolution if the flag is~{\tt true}.  If $match$
 | 
|  |    568 | is~{\tt true}, the $state$ is not instantiated.
 | 
| 326 |    569 | \end{ttdescription}
 | 
| 104 |    570 | 
 | 
|  |    571 | 
 | 
|  |    572 | \subsection{Composition: resolution without lifting}
 | 
| 326 |    573 | \index{resolution!without lifting}
 | 
| 104 |    574 | \begin{ttbox}
 | 
|  |    575 | compose   : thm * int * thm -> thm list
 | 
|  |    576 | COMP      : thm * thm -> thm
 | 
|  |    577 | bicompose : bool -> bool * thm * int -> int -> thm
 | 
|  |    578 |             -> thm Sequence.seq
 | 
|  |    579 | \end{ttbox}
 | 
|  |    580 | In forward proof, a typical use of composition is to regard an assertion of
 | 
|  |    581 | the form $\phi\Imp\psi$ as atomic.  Schematic variables are not renamed, so
 | 
|  |    582 | beware of clashes!
 | 
| 326 |    583 | \begin{ttdescription}
 | 
| 104 |    584 | \item[\ttindexbold{compose} ($thm@1$, $i$, $thm@2$)] 
 | 
|  |    585 | uses $thm@1$, regarded as an atomic formula, to solve premise~$i$
 | 
|  |    586 | of~$thm@2$.  Let $thm@1$ and $thm@2$ be $\psi$ and $\List{\phi@1; \ldots;
 | 
|  |    587 | \phi@n} \Imp \phi$.  For each $s$ that unifies~$\psi$ and $\phi@i$, the
 | 
|  |    588 | result list contains the theorem
 | 
|  |    589 | \[ (\List{\phi@1; \ldots; \phi@{i-1}; \phi@{i+1}; \ldots; \phi@n} \Imp \phi)s.
 | 
|  |    590 | \]
 | 
|  |    591 | 
 | 
|  |    592 | \item[\tt $thm@1$ COMP $thm@2$] 
 | 
|  |    593 | calls \hbox{\tt compose ($thm@1$, 1, $thm@2$)} and returns the result, if
 | 
| 326 |    594 | unique; otherwise, it raises exception~\xdx{THM}\@.  It is
 | 
| 104 |    595 | analogous to {\tt RS}\@.  
 | 
|  |    596 | 
 | 
|  |    597 | For example, suppose that $thm@1$ is $a=b\Imp b=a$, a symmetry rule, and
 | 
| 332 |    598 | that $thm@2$ is $\List{P\Imp Q; \neg Q} \Imp\neg P$, which is the
 | 
| 104 |    599 | principle of contrapositives.  Then the result would be the
 | 
|  |    600 | derived rule $\neg(b=a)\Imp\neg(a=b)$.
 | 
|  |    601 | 
 | 
|  |    602 | \item[\ttindexbold{bicompose} $match$ ($flag$, $rule$, $m$) $i$ $state$]
 | 
|  |    603 | refines subgoal~$i$ of $state$ using $rule$, without lifting.  The $rule$
 | 
|  |    604 | is taken to have the form $\List{\psi@1; \ldots; \psi@m} \Imp \psi$, where
 | 
| 326 |    605 | $\psi$ need not be atomic; thus $m$ determines the number of new
 | 
| 104 |    606 | subgoals.  If $flag$ is {\tt true} then it performs elim-resolution --- it
 | 
|  |    607 | solves the first premise of~$rule$ by assumption and deletes that
 | 
|  |    608 | assumption.  If $match$ is~{\tt true}, the $state$ is not instantiated.
 | 
| 326 |    609 | \end{ttdescription}
 | 
| 104 |    610 | 
 | 
|  |    611 | 
 | 
|  |    612 | \subsection{Other meta-rules}
 | 
|  |    613 | \begin{ttbox} 
 | 
|  |    614 | trivial            : Sign.cterm -> thm
 | 
|  |    615 | lift_rule          : (thm * int) -> thm -> thm
 | 
|  |    616 | rename_params_rule : string list * int -> thm -> thm
 | 
|  |    617 | rewrite_cterm      : thm list -> Sign.cterm -> thm
 | 
|  |    618 | flexflex_rule      : thm -> thm Sequence.seq
 | 
|  |    619 | \end{ttbox}
 | 
| 326 |    620 | \begin{ttdescription}
 | 
| 104 |    621 | \item[\ttindexbold{trivial} $ct$] 
 | 
|  |    622 | makes the theorem \(\phi\Imp\phi\), where $\phi$ is the value of~$ct$.
 | 
|  |    623 | This is the initial state for a goal-directed proof of~$\phi$.  The rule
 | 
|  |    624 | checks that $ct$ has type~$prop$.
 | 
|  |    625 | 
 | 
|  |    626 | \item[\ttindexbold{lift_rule} ($state$, $i$) $rule$] \index{lifting}
 | 
|  |    627 | prepares $rule$ for resolution by lifting it over the parameters and
 | 
|  |    628 | assumptions of subgoal~$i$ of~$state$.
 | 
|  |    629 | 
 | 
|  |    630 | \item[\ttindexbold{rename_params_rule} ({\it names}, {\it i}) $thm$] 
 | 
|  |    631 | uses the $names$ to rename the parameters of premise~$i$ of $thm$.  The
 | 
|  |    632 | names must be distinct.  If there are fewer names than parameters, then the
 | 
|  |    633 | rule renames the innermost parameters and may modify the remaining ones to
 | 
|  |    634 | ensure that all the parameters are distinct.
 | 
|  |    635 | \index{parameters!renaming}
 | 
|  |    636 | 
 | 
|  |    637 | \item[\ttindexbold{rewrite_cterm} $defs$ $ct$]
 | 
|  |    638 | transforms $ct$ to $ct'$ by repeatedly applying $defs$ as rewrite rules; it
 | 
|  |    639 | returns the conclusion~$ct\equiv ct'$.  This underlies the meta-rewriting
 | 
|  |    640 | tactics and rules.
 | 
| 326 |    641 | \index{meta-rewriting!in terms}
 | 
| 104 |    642 | 
 | 
|  |    643 | \item[\ttindexbold{flexflex_rule} $thm$]  \index{flex-flex constraints}
 | 
|  |    644 | removes all flex-flex pairs from $thm$ using the trivial unifier.
 | 
| 326 |    645 | \end{ttdescription}
 | 
| 104 |    646 | \index{theorems|)}
 | 
|  |    647 | \index{meta-rules|)}
 |