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