| 104 |      1 | %% $Id$
 | 
| 313 |      2 | \chapter{First-Order Logic}
 | 
|  |      3 | \index{first-order logic|(}
 | 
|  |      4 | 
 | 
|  |      5 | Isabelle implements Gentzen's natural deduction systems {\sc nj} and {\sc
 | 
|  |      6 |   nk}.  Intuitionistic first-order logic is defined first, as theory
 | 
|  |      7 | \thydx{IFOL}.  Classical logic, theory \thydx{FOL}, is
 | 
| 104 |      8 | obtained by adding the double negation rule.  Basic proof procedures are
 | 
|  |      9 | provided.  The intuitionistic prover works with derived rules to simplify
 | 
| 313 |     10 | implications in the assumptions.  Classical~{\tt FOL} employs Isabelle's
 | 
|  |     11 | classical reasoner, which simulates a sequent calculus.
 | 
| 104 |     12 | 
 | 
|  |     13 | \section{Syntax and rules of inference}
 | 
| 313 |     14 | The logic is many-sorted, using Isabelle's type classes.  The class of
 | 
|  |     15 | first-order terms is called \cldx{term} and is a subclass of {\tt logic}.
 | 
|  |     16 | No types of individuals are provided, but extensions can define types such
 | 
|  |     17 | as {\tt nat::term} and type constructors such as {\tt list::(term)term}
 | 
|  |     18 | (see the examples directory, {\tt FOL/ex}).  Below, the type variable
 | 
|  |     19 | $\alpha$ ranges over class {\tt term}; the equality symbol and quantifiers
 | 
|  |     20 | are polymorphic (many-sorted).  The type of formulae is~\tydx{o}, which
 | 
|  |     21 | belongs to class~\cldx{logic}.  Figure~\ref{fol-syntax} gives the syntax.
 | 
|  |     22 | Note that $a$\verb|~=|$b$ is translated to $\neg(a=b)$.
 | 
| 104 |     23 | 
 | 
| 313 |     24 | Figure~\ref{fol-rules} shows the inference rules with their~\ML\ names.
 | 
|  |     25 | Negation is defined in the usual way for intuitionistic logic; $\neg P$
 | 
|  |     26 | abbreviates $P\imp\bot$.  The biconditional~($\bimp$) is defined through
 | 
|  |     27 | $\conj$ and~$\imp$; introduction and elimination rules are derived for it.
 | 
| 104 |     28 | 
 | 
|  |     29 | The unique existence quantifier, $\exists!x.P(x)$, is defined in terms
 | 
|  |     30 | of~$\exists$ and~$\forall$.  An Isabelle binder, it admits nested
 | 
|  |     31 | quantifications.  For instance, $\exists!x y.P(x,y)$ abbreviates
 | 
|  |     32 | $\exists!x. \exists!y.P(x,y)$; note that this does not mean that there
 | 
|  |     33 | exists a unique pair $(x,y)$ satisfying~$P(x,y)$.
 | 
|  |     34 | 
 | 
|  |     35 | Some intuitionistic derived rules are shown in
 | 
| 287 |     36 | Fig.\ts\ref{fol-int-derived}, again with their \ML\ names.  These include
 | 
| 104 |     37 | rules for the defined symbols $\neg$, $\bimp$ and $\exists!$.  Natural
 | 
| 333 |     38 | deduction typically involves a combination of forward and backward
 | 
| 104 |     39 | reasoning, particularly with the destruction rules $(\conj E)$,
 | 
| 333 |     40 | $({\imp}E)$, and~$(\forall E)$.  Isabelle's backward style handles these
 | 
| 104 |     41 | rules badly, so sequent-style rules are derived to eliminate conjunctions,
 | 
|  |     42 | implications, and universal quantifiers.  Used with elim-resolution,
 | 
| 313 |     43 | \tdx{allE} eliminates a universal quantifier while \tdx{all_dupE}
 | 
| 104 |     44 | re-inserts the quantified formula for later use.  The rules {\tt
 | 
|  |     45 | conj_impE}, etc., support the intuitionistic proof procedure
 | 
|  |     46 | (see~\S\ref{fol-int-prover}).
 | 
|  |     47 | 
 | 
| 333 |     48 | See the files {\tt FOL/IFOL.thy}, {\tt FOL/IFOL.ML} and
 | 
| 287 |     49 | {\tt FOL/intprover.ML} for complete listings of the rules and
 | 
| 104 |     50 | derived rules.
 | 
|  |     51 | 
 | 
|  |     52 | \begin{figure} 
 | 
|  |     53 | \begin{center}
 | 
|  |     54 | \begin{tabular}{rrr} 
 | 
| 111 |     55 |   \it name      &\it meta-type  & \it description \\ 
 | 
| 313 |     56 |   \cdx{Trueprop}& $o\To prop$           & coercion to $prop$\\
 | 
|  |     57 |   \cdx{Not}     & $o\To o$              & negation ($\neg$) \\
 | 
|  |     58 |   \cdx{True}    & $o$                   & tautology ($\top$) \\
 | 
|  |     59 |   \cdx{False}   & $o$                   & absurdity ($\bot$)
 | 
| 104 |     60 | \end{tabular}
 | 
|  |     61 | \end{center}
 | 
|  |     62 | \subcaption{Constants}
 | 
|  |     63 | 
 | 
|  |     64 | \begin{center}
 | 
|  |     65 | \begin{tabular}{llrrr} 
 | 
| 313 |     66 |   \it symbol &\it name     &\it meta-type & \it priority & \it description \\
 | 
|  |     67 |   \sdx{ALL}  & \cdx{All}  & $(\alpha\To o)\To o$ & 10 & 
 | 
| 111 |     68 |         universal quantifier ($\forall$) \\
 | 
| 313 |     69 |   \sdx{EX}   & \cdx{Ex}   & $(\alpha\To o)\To o$ & 10 & 
 | 
| 111 |     70 |         existential quantifier ($\exists$) \\
 | 
| 313 |     71 |   {\tt EX!}  & \cdx{Ex1}  & $(\alpha\To o)\To o$ & 10 & 
 | 
| 111 |     72 |         unique existence ($\exists!$)
 | 
| 104 |     73 | \end{tabular}
 | 
| 313 |     74 | \index{*"E"X"! symbol}
 | 
| 104 |     75 | \end{center}
 | 
|  |     76 | \subcaption{Binders} 
 | 
|  |     77 | 
 | 
|  |     78 | \begin{center}
 | 
| 313 |     79 | \index{*"= symbol}
 | 
|  |     80 | \index{&@{\tt\&} symbol}
 | 
|  |     81 | \index{*"| symbol}
 | 
|  |     82 | \index{*"-"-"> symbol}
 | 
|  |     83 | \index{*"<"-"> symbol}
 | 
| 104 |     84 | \begin{tabular}{rrrr} 
 | 
| 313 |     85 |   \it symbol    & \it meta-type         & \it priority & \it description \\ 
 | 
| 111 |     86 |   \tt =         & $[\alpha,\alpha]\To o$ & Left 50 & equality ($=$) \\
 | 
|  |     87 |   \tt \&        & $[o,o]\To o$          & Right 35 & conjunction ($\conj$) \\
 | 
|  |     88 |   \tt |         & $[o,o]\To o$          & Right 30 & disjunction ($\disj$) \\
 | 
|  |     89 |   \tt -->       & $[o,o]\To o$          & Right 25 & implication ($\imp$) \\
 | 
|  |     90 |   \tt <->       & $[o,o]\To o$          & Right 25 & biconditional ($\bimp$) 
 | 
| 104 |     91 | \end{tabular}
 | 
|  |     92 | \end{center}
 | 
|  |     93 | \subcaption{Infixes}
 | 
|  |     94 | 
 | 
|  |     95 | \dquotes
 | 
|  |     96 | \[\begin{array}{rcl}
 | 
|  |     97 |  formula & = & \hbox{expression of type~$o$} \\
 | 
| 111 |     98 |          & | & term " = " term \\
 | 
|  |     99 |          & | & term " \ttilde= " term \\
 | 
|  |    100 |          & | & "\ttilde\ " formula \\
 | 
|  |    101 |          & | & formula " \& " formula \\
 | 
|  |    102 |          & | & formula " | " formula \\
 | 
|  |    103 |          & | & formula " --> " formula \\
 | 
|  |    104 |          & | & formula " <-> " formula \\
 | 
|  |    105 |          & | & "ALL~" id~id^* " . " formula \\
 | 
|  |    106 |          & | & "EX~~" id~id^* " . " formula \\
 | 
|  |    107 |          & | & "EX!~" id~id^* " . " formula
 | 
| 104 |    108 |   \end{array}
 | 
|  |    109 | \]
 | 
|  |    110 | \subcaption{Grammar}
 | 
|  |    111 | \caption{Syntax of {\tt FOL}} \label{fol-syntax}
 | 
|  |    112 | \end{figure}
 | 
|  |    113 | 
 | 
|  |    114 | 
 | 
|  |    115 | \begin{figure} 
 | 
|  |    116 | \begin{ttbox}
 | 
| 313 |    117 | \tdx{refl}        a=a
 | 
|  |    118 | \tdx{subst}       [| a=b;  P(a) |] ==> P(b)
 | 
| 104 |    119 | \subcaption{Equality rules}
 | 
|  |    120 | 
 | 
| 313 |    121 | \tdx{conjI}       [| P;  Q |] ==> P&Q
 | 
|  |    122 | \tdx{conjunct1}   P&Q ==> P
 | 
|  |    123 | \tdx{conjunct2}   P&Q ==> Q
 | 
| 104 |    124 | 
 | 
| 313 |    125 | \tdx{disjI1}      P ==> P|Q
 | 
|  |    126 | \tdx{disjI2}      Q ==> P|Q
 | 
|  |    127 | \tdx{disjE}       [| P|Q;  P ==> R;  Q ==> R |] ==> R
 | 
| 104 |    128 | 
 | 
| 313 |    129 | \tdx{impI}        (P ==> Q) ==> P-->Q
 | 
|  |    130 | \tdx{mp}          [| P-->Q;  P |] ==> Q
 | 
| 104 |    131 | 
 | 
| 313 |    132 | \tdx{FalseE}      False ==> P
 | 
| 104 |    133 | \subcaption{Propositional rules}
 | 
|  |    134 | 
 | 
| 313 |    135 | \tdx{allI}        (!!x. P(x))  ==> (ALL x.P(x))
 | 
|  |    136 | \tdx{spec}        (ALL x.P(x)) ==> P(x)
 | 
| 104 |    137 | 
 | 
| 313 |    138 | \tdx{exI}         P(x) ==> (EX x.P(x))
 | 
|  |    139 | \tdx{exE}         [| EX x.P(x);  !!x. P(x) ==> R |] ==> R
 | 
| 104 |    140 | \subcaption{Quantifier rules}
 | 
|  |    141 | 
 | 
| 313 |    142 | \tdx{True_def}    True        == False-->False
 | 
|  |    143 | \tdx{not_def}     ~P          == P-->False
 | 
|  |    144 | \tdx{iff_def}     P<->Q       == (P-->Q) & (Q-->P)
 | 
|  |    145 | \tdx{ex1_def}     EX! x. P(x) == EX x. P(x) & (ALL y. P(y) --> y=x)
 | 
| 104 |    146 | \subcaption{Definitions}
 | 
|  |    147 | \end{ttbox}
 | 
|  |    148 | 
 | 
| 313 |    149 | \caption{Rules of intuitionistic logic} \label{fol-rules}
 | 
| 104 |    150 | \end{figure}
 | 
|  |    151 | 
 | 
|  |    152 | 
 | 
|  |    153 | \begin{figure} 
 | 
|  |    154 | \begin{ttbox}
 | 
| 313 |    155 | \tdx{sym}       a=b ==> b=a
 | 
|  |    156 | \tdx{trans}     [| a=b;  b=c |] ==> a=c
 | 
|  |    157 | \tdx{ssubst}    [| b=a;  P(a) |] ==> P(b)
 | 
| 104 |    158 | \subcaption{Derived equality rules}
 | 
|  |    159 | 
 | 
| 313 |    160 | \tdx{TrueI}     True
 | 
| 104 |    161 | 
 | 
| 313 |    162 | \tdx{notI}      (P ==> False) ==> ~P
 | 
|  |    163 | \tdx{notE}      [| ~P;  P |] ==> R
 | 
| 104 |    164 | 
 | 
| 313 |    165 | \tdx{iffI}      [| P ==> Q;  Q ==> P |] ==> P<->Q
 | 
|  |    166 | \tdx{iffE}      [| P <-> Q;  [| P-->Q; Q-->P |] ==> R |] ==> R
 | 
|  |    167 | \tdx{iffD1}     [| P <-> Q;  P |] ==> Q            
 | 
|  |    168 | \tdx{iffD2}     [| P <-> Q;  Q |] ==> P
 | 
| 104 |    169 | 
 | 
| 313 |    170 | \tdx{ex1I}      [| P(a);  !!x. P(x) ==> x=a |]  ==>  EX! x. P(x)
 | 
|  |    171 | \tdx{ex1E}      [| EX! x.P(x);  !!x.[| P(x);  ALL y. P(y) --> y=x |] ==> R 
 | 
| 104 |    172 |           |] ==> R
 | 
|  |    173 | \subcaption{Derived rules for \(\top\), \(\neg\), \(\bimp\) and \(\exists!\)}
 | 
|  |    174 | 
 | 
| 313 |    175 | \tdx{conjE}     [| P&Q;  [| P; Q |] ==> R |] ==> R
 | 
|  |    176 | \tdx{impE}      [| P-->Q;  P;  Q ==> R |] ==> R
 | 
|  |    177 | \tdx{allE}      [| ALL x.P(x);  P(x) ==> R |] ==> R
 | 
|  |    178 | \tdx{all_dupE}  [| ALL x.P(x);  [| P(x); ALL x.P(x) |] ==> R |] ==> R
 | 
| 104 |    179 | \subcaption{Sequent-style elimination rules}
 | 
|  |    180 | 
 | 
| 313 |    181 | \tdx{conj_impE} [| (P&Q)-->S;  P-->(Q-->S) ==> R |] ==> R
 | 
|  |    182 | \tdx{disj_impE} [| (P|Q)-->S;  [| P-->S; Q-->S |] ==> R |] ==> R
 | 
|  |    183 | \tdx{imp_impE}  [| (P-->Q)-->S;  [| P; Q-->S |] ==> Q;  S ==> R |] ==> R
 | 
|  |    184 | \tdx{not_impE}  [| ~P --> S;  P ==> False;  S ==> R |] ==> R
 | 
|  |    185 | \tdx{iff_impE}  [| (P<->Q)-->S; [| P; Q-->S |] ==> Q; [| Q; P-->S |] ==> P;
 | 
| 104 |    186 |              S ==> R |] ==> R
 | 
| 313 |    187 | \tdx{all_impE}  [| (ALL x.P(x))-->S;  !!x.P(x);  S ==> R |] ==> R
 | 
|  |    188 | \tdx{ex_impE}   [| (EX x.P(x))-->S;  P(a)-->S ==> R |] ==> R
 | 
| 104 |    189 | \end{ttbox}
 | 
|  |    190 | \subcaption{Intuitionistic simplification of implication}
 | 
| 313 |    191 | \caption{Derived rules for intuitionistic logic} \label{fol-int-derived}
 | 
| 104 |    192 | \end{figure}
 | 
|  |    193 | 
 | 
|  |    194 | 
 | 
|  |    195 | \section{Generic packages}
 | 
| 2495 |    196 | \FOL{} instantiates most of Isabelle's generic packages.
 | 
| 104 |    197 | \begin{itemize}
 | 
|  |    198 | \item 
 | 
|  |    199 | Because it includes a general substitution rule, \FOL{} instantiates the
 | 
|  |    200 | tactic \ttindex{hyp_subst_tac}, which substitutes for an equality
 | 
|  |    201 | throughout a subgoal and its hypotheses.
 | 
| 2495 |    202 | (See {\tt FOL/ROOT.ML} for details.)
 | 
| 104 |    203 | \item 
 | 
| 2495 |    204 | It instantiates the simplifier.  Both equality ($=$) and the biconditional
 | 
|  |    205 | ($\bimp$) may be used for rewriting.  Tactics such as {\tt Asm_simp_tac} and
 | 
|  |    206 | {\tt Full_simp_tac} use the default simpset ({\tt!simpset}), which works for
 | 
|  |    207 | most purposes.  Named simplification sets include \ttindexbold{IFOL_ss},
 | 
|  |    208 | for intuitionistic first-order logic, and \ttindexbold{FOL_ss},
 | 
|  |    209 | for classical logic.  See the file
 | 
| 287 |    210 | {\tt FOL/simpdata.ML} for a complete listing of the simplification
 | 
| 313 |    211 | rules%
 | 
|  |    212 | \iflabelundefined{sec:setting-up-simp}{}%
 | 
|  |    213 |         {, and \S\ref{sec:setting-up-simp} for discussion}.
 | 
|  |    214 | 
 | 
| 104 |    215 | \item 
 | 
| 313 |    216 | It instantiates the classical reasoner.  See~\S\ref{fol-cla-prover}
 | 
| 104 |    217 | for details. 
 | 
|  |    218 | \end{itemize}
 | 
|  |    219 | 
 | 
|  |    220 | 
 | 
|  |    221 | \section{Intuitionistic proof procedures} \label{fol-int-prover}
 | 
|  |    222 | Implication elimination (the rules~{\tt mp} and~{\tt impE}) pose
 | 
| 313 |    223 | difficulties for automated proof.  In intuitionistic logic, the assumption
 | 
|  |    224 | $P\imp Q$ cannot be treated like $\neg P\disj Q$.  Given $P\imp Q$, we may
 | 
|  |    225 | use~$Q$ provided we can prove~$P$; the proof of~$P$ may require repeated
 | 
|  |    226 | use of $P\imp Q$.  If the proof of~$P$ fails then the whole branch of the
 | 
|  |    227 | proof must be abandoned.  Thus intuitionistic propositional logic requires
 | 
|  |    228 | backtracking.  
 | 
|  |    229 | 
 | 
|  |    230 | For an elementary example, consider the intuitionistic proof of $Q$ from
 | 
|  |    231 | $P\imp Q$ and $(P\imp Q)\imp P$.  The implication $P\imp Q$ is needed
 | 
|  |    232 | twice:
 | 
| 104 |    233 | \[ \infer[({\imp}E)]{Q}{P\imp Q &
 | 
|  |    234 |        \infer[({\imp}E)]{P}{(P\imp Q)\imp P & P\imp Q}} 
 | 
|  |    235 | \]
 | 
|  |    236 | The theorem prover for intuitionistic logic does not use~{\tt impE}.\@
 | 
|  |    237 | Instead, it simplifies implications using derived rules
 | 
| 287 |    238 | (Fig.\ts\ref{fol-int-derived}).  It reduces the antecedents of implications
 | 
| 313 |    239 | to atoms and then uses Modus Ponens: from $P\imp Q$ and~$P$ deduce~$Q$.
 | 
|  |    240 | The rules \tdx{conj_impE} and \tdx{disj_impE} are 
 | 
| 104 |    241 | straightforward: $(P\conj Q)\imp S$ is equivalent to $P\imp (Q\imp S)$, and
 | 
|  |    242 | $(P\disj Q)\imp S$ is equivalent to the conjunction of $P\imp S$ and $Q\imp
 | 
|  |    243 | S$.  The other \ldots{\tt_impE} rules are unsafe; the method requires
 | 
| 313 |    244 | backtracking.  All the rules are derived in the same simple manner.
 | 
| 104 |    245 | 
 | 
|  |    246 | Dyckhoff has independently discovered similar rules, and (more importantly)
 | 
|  |    247 | has demonstrated their completeness for propositional
 | 
|  |    248 | logic~\cite{dyckhoff}.  However, the tactics given below are not complete
 | 
|  |    249 | for first-order logic because they discard universally quantified
 | 
|  |    250 | assumptions after a single use.
 | 
|  |    251 | \begin{ttbox} 
 | 
|  |    252 | mp_tac            : int -> tactic
 | 
|  |    253 | eq_mp_tac         : int -> tactic
 | 
|  |    254 | Int.safe_step_tac : int -> tactic
 | 
|  |    255 | Int.safe_tac      :        tactic
 | 
| 313 |    256 | Int.inst_step_tac : int -> tactic
 | 
| 104 |    257 | Int.step_tac      : int -> tactic
 | 
|  |    258 | Int.fast_tac      : int -> tactic
 | 
|  |    259 | Int.best_tac      : int -> tactic
 | 
|  |    260 | \end{ttbox}
 | 
| 313 |    261 | Most of these belong to the structure {\tt Int} and resemble the
 | 
|  |    262 | tactics of Isabelle's classical reasoner.
 | 
| 104 |    263 | 
 | 
| 313 |    264 | \begin{ttdescription}
 | 
| 104 |    265 | \item[\ttindexbold{mp_tac} {\it i}] 
 | 
| 313 |    266 | attempts to use \tdx{notE} or \tdx{impE} within the assumptions in
 | 
| 104 |    267 | subgoal $i$.  For each assumption of the form $\neg P$ or $P\imp Q$, it
 | 
|  |    268 | searches for another assumption unifiable with~$P$.  By
 | 
|  |    269 | contradiction with $\neg P$ it can solve the subgoal completely; by Modus
 | 
|  |    270 | Ponens it can replace the assumption $P\imp Q$ by $Q$.  The tactic can
 | 
|  |    271 | produce multiple outcomes, enumerating all suitable pairs of assumptions.
 | 
|  |    272 | 
 | 
|  |    273 | \item[\ttindexbold{eq_mp_tac} {\it i}] 
 | 
|  |    274 | is like {\tt mp_tac} {\it i}, but may not instantiate unknowns --- thus, it
 | 
|  |    275 | is safe.
 | 
|  |    276 | 
 | 
|  |    277 | \item[\ttindexbold{Int.safe_step_tac} $i$] performs a safe step on
 | 
| 313 |    278 | subgoal~$i$.  This may include proof by assumption or Modus Ponens (taking
 | 
|  |    279 | care not to instantiate unknowns), or {\tt hyp_subst_tac}. 
 | 
| 104 |    280 | 
 | 
|  |    281 | \item[\ttindexbold{Int.safe_tac}] repeatedly performs safe steps on all 
 | 
|  |    282 | subgoals.  It is deterministic, with at most one outcome.
 | 
|  |    283 | 
 | 
|  |    284 | \item[\ttindexbold{Int.inst_step_tac} $i$] is like {\tt safe_step_tac},
 | 
|  |    285 | but allows unknowns to be instantiated.
 | 
|  |    286 | 
 | 
| 313 |    287 | \item[\ttindexbold{Int.step_tac} $i$] tries {\tt safe_tac} or {\tt
 | 
|  |    288 |     inst_step_tac}, or applies an unsafe rule.  This is the basic step of
 | 
|  |    289 |   the intuitionistic proof procedure.
 | 
| 104 |    290 | 
 | 
|  |    291 | \item[\ttindexbold{Int.fast_tac} $i$] applies {\tt step_tac}, using
 | 
|  |    292 | depth-first search, to solve subgoal~$i$.
 | 
|  |    293 | 
 | 
|  |    294 | \item[\ttindexbold{Int.best_tac} $i$] applies {\tt step_tac}, using
 | 
|  |    295 | best-first search (guided by the size of the proof state) to solve subgoal~$i$.
 | 
| 313 |    296 | \end{ttdescription}
 | 
| 104 |    297 | Here are some of the theorems that {\tt Int.fast_tac} proves
 | 
|  |    298 | automatically.  The latter three date from {\it Principia Mathematica}
 | 
|  |    299 | (*11.53, *11.55, *11.61)~\cite{principia}.
 | 
|  |    300 | \begin{ttbox}
 | 
|  |    301 | ~~P & ~~(P --> Q) --> ~~Q
 | 
|  |    302 | (ALL x y. P(x) --> Q(y)) <-> ((EX x. P(x)) --> (ALL y. Q(y)))
 | 
|  |    303 | (EX x y. P(x) & Q(x,y)) <-> (EX x. P(x) & (EX y. Q(x,y)))
 | 
|  |    304 | (EX y. ALL x. P(x) --> Q(x,y)) --> (ALL x. P(x) --> (EX y. Q(x,y)))
 | 
|  |    305 | \end{ttbox}
 | 
|  |    306 | 
 | 
|  |    307 | 
 | 
|  |    308 | 
 | 
|  |    309 | \begin{figure} 
 | 
|  |    310 | \begin{ttbox}
 | 
| 313 |    311 | \tdx{excluded_middle}    ~P | P
 | 
| 104 |    312 | 
 | 
| 313 |    313 | \tdx{disjCI}    (~Q ==> P) ==> P|Q
 | 
|  |    314 | \tdx{exCI}      (ALL x. ~P(x) ==> P(a)) ==> EX x.P(x)
 | 
|  |    315 | \tdx{impCE}     [| P-->Q; ~P ==> R; Q ==> R |] ==> R
 | 
|  |    316 | \tdx{iffCE}     [| P<->Q;  [| P; Q |] ==> R;  [| ~P; ~Q |] ==> R |] ==> R
 | 
|  |    317 | \tdx{notnotD}   ~~P ==> P
 | 
|  |    318 | \tdx{swap}      ~P ==> (~Q ==> P) ==> Q
 | 
| 104 |    319 | \end{ttbox}
 | 
|  |    320 | \caption{Derived rules for classical logic} \label{fol-cla-derived}
 | 
|  |    321 | \end{figure}
 | 
|  |    322 | 
 | 
|  |    323 | 
 | 
|  |    324 | \section{Classical proof procedures} \label{fol-cla-prover}
 | 
| 313 |    325 | The classical theory, \thydx{FOL}, consists of intuitionistic logic plus
 | 
|  |    326 | the rule
 | 
| 104 |    327 | $$ \vcenter{\infer{P}{\infer*{P}{[\neg P]}}} \eqno(classical) $$
 | 
|  |    328 | \noindent
 | 
|  |    329 | Natural deduction in classical logic is not really all that natural.
 | 
|  |    330 | {\FOL} derives classical introduction rules for $\disj$ and~$\exists$, as
 | 
|  |    331 | well as classical elimination rules for~$\imp$ and~$\bimp$, and the swap
 | 
| 287 |    332 | rule (see Fig.\ts\ref{fol-cla-derived}).
 | 
| 104 |    333 | 
 | 
| 2495 |    334 | The classical reasoner is installed.  Tactics such as {\tt Fast_tac} and {\tt
 | 
|  |    335 | Best_tac} use the default claset ({\tt!claset}), which works for most
 | 
|  |    336 | purposes.  Named clasets include \ttindexbold{prop_cs}, which includes the
 | 
|  |    337 | propositional rules, and \ttindexbold{FOL_cs}, which also includes quantifier
 | 
|  |    338 | rules.  See the file {\tt FOL/cladata.ML} for lists of the
 | 
| 313 |    339 | classical rules, and 
 | 
|  |    340 | \iflabelundefined{chap:classical}{the {\em Reference Manual\/}}%
 | 
|  |    341 |         {Chap.\ts\ref{chap:classical}} 
 | 
|  |    342 | for more discussion of classical proof methods.
 | 
| 104 |    343 | 
 | 
|  |    344 | 
 | 
|  |    345 | \section{An intuitionistic example}
 | 
|  |    346 | Here is a session similar to one in {\em Logic and Computation}
 | 
|  |    347 | \cite[pages~222--3]{paulson87}.  Isabelle treats quantifiers differently
 | 
|  |    348 | from {\sc lcf}-based theorem provers such as {\sc hol}.  The proof begins
 | 
|  |    349 | by entering the goal in intuitionistic logic, then applying the rule
 | 
|  |    350 | $({\imp}I)$.
 | 
|  |    351 | \begin{ttbox}
 | 
|  |    352 | goal IFOL.thy "(EX y. ALL x. Q(x,y)) -->  (ALL x. EX y. Q(x,y))";
 | 
|  |    353 | {\out Level 0}
 | 
|  |    354 | {\out (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    355 | {\out  1. (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    356 | \ttbreak
 | 
|  |    357 | by (resolve_tac [impI] 1);
 | 
|  |    358 | {\out Level 1}
 | 
|  |    359 | {\out (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    360 | {\out  1. EX y. ALL x. Q(x,y) ==> ALL x. EX y. Q(x,y)}
 | 
|  |    361 | \end{ttbox}
 | 
| 313 |    362 | In this example, we shall never have more than one subgoal.  Applying
 | 
| 104 |    363 | $({\imp}I)$ replaces~\verb|-->| by~\verb|==>|, making
 | 
|  |    364 | \(\ex{y}\all{x}Q(x,y)\) an assumption.  We have the choice of
 | 
|  |    365 | $({\exists}E)$ and $({\forall}I)$; let us try the latter.
 | 
|  |    366 | \begin{ttbox}
 | 
|  |    367 | by (resolve_tac [allI] 1);
 | 
|  |    368 | {\out Level 2}
 | 
|  |    369 | {\out (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    370 | {\out  1. !!x. EX y. ALL x. Q(x,y) ==> EX y. Q(x,y)}
 | 
|  |    371 | \end{ttbox}
 | 
|  |    372 | Applying $({\forall}I)$ replaces the \hbox{\tt ALL x} by \hbox{\tt!!x},
 | 
|  |    373 | changing the universal quantifier from object~($\forall$) to
 | 
| 313 |    374 | meta~($\Forall$).  The bound variable is a {\bf parameter} of the
 | 
| 104 |    375 | subgoal.  We now must choose between $({\exists}I)$ and $({\exists}E)$.  What
 | 
|  |    376 | happens if the wrong rule is chosen?
 | 
|  |    377 | \begin{ttbox}
 | 
|  |    378 | by (resolve_tac [exI] 1);
 | 
|  |    379 | {\out Level 3}
 | 
|  |    380 | {\out (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    381 | {\out  1. !!x. EX y. ALL x. Q(x,y) ==> Q(x,?y2(x))}
 | 
|  |    382 | \end{ttbox}
 | 
|  |    383 | The new subgoal~1 contains the function variable {\tt?y2}.  Instantiating
 | 
|  |    384 | {\tt?y2} can replace~{\tt?y2(x)} by a term containing~{\tt x}, even
 | 
|  |    385 | though~{\tt x} is a bound variable.  Now we analyse the assumption
 | 
|  |    386 | \(\exists y.\forall x. Q(x,y)\) using elimination rules:
 | 
|  |    387 | \begin{ttbox}
 | 
|  |    388 | by (eresolve_tac [exE] 1);
 | 
|  |    389 | {\out Level 4}
 | 
|  |    390 | {\out (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    391 | {\out  1. !!x y. ALL x. Q(x,y) ==> Q(x,?y2(x))}
 | 
|  |    392 | \end{ttbox}
 | 
|  |    393 | Applying $(\exists E)$ has produced the parameter {\tt y} and stripped the
 | 
| 313 |    394 | existential quantifier from the assumption.  But the subgoal is unprovable:
 | 
|  |    395 | there is no way to unify {\tt ?y2(x)} with the bound variable~{\tt y}.
 | 
|  |    396 | Using {\tt choplev} we can return to the critical point.  This time we
 | 
|  |    397 | apply $({\exists}E)$:
 | 
| 104 |    398 | \begin{ttbox}
 | 
|  |    399 | choplev 2;
 | 
|  |    400 | {\out Level 2}
 | 
|  |    401 | {\out (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    402 | {\out  1. !!x. EX y. ALL x. Q(x,y) ==> EX y. Q(x,y)}
 | 
|  |    403 | \ttbreak
 | 
|  |    404 | by (eresolve_tac [exE] 1);
 | 
|  |    405 | {\out Level 3}
 | 
|  |    406 | {\out (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    407 | {\out  1. !!x y. ALL x. Q(x,y) ==> EX y. Q(x,y)}
 | 
|  |    408 | \end{ttbox}
 | 
| 313 |    409 | We now have two parameters and no scheme variables.  Applying
 | 
|  |    410 | $({\exists}I)$ and $({\forall}E)$ produces two scheme variables, which are
 | 
|  |    411 | applied to those parameters.  Parameters should be produced early, as this
 | 
|  |    412 | example demonstrates.
 | 
| 104 |    413 | \begin{ttbox}
 | 
|  |    414 | by (resolve_tac [exI] 1);
 | 
|  |    415 | {\out Level 4}
 | 
|  |    416 | {\out (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    417 | {\out  1. !!x y. ALL x. Q(x,y) ==> Q(x,?y3(x,y))}
 | 
|  |    418 | \ttbreak
 | 
|  |    419 | by (eresolve_tac [allE] 1);
 | 
|  |    420 | {\out Level 5}
 | 
|  |    421 | {\out (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    422 | {\out  1. !!x y. Q(?x4(x,y),y) ==> Q(x,?y3(x,y))}
 | 
|  |    423 | \end{ttbox}
 | 
|  |    424 | The subgoal has variables {\tt ?y3} and {\tt ?x4} applied to both
 | 
|  |    425 | parameters.  The obvious projection functions unify {\tt?x4(x,y)} with~{\tt
 | 
|  |    426 | x} and \verb|?y3(x,y)| with~{\tt y}.
 | 
|  |    427 | \begin{ttbox}
 | 
|  |    428 | by (assume_tac 1);
 | 
|  |    429 | {\out Level 6}
 | 
|  |    430 | {\out (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    431 | {\out No subgoals!}
 | 
|  |    432 | \end{ttbox}
 | 
|  |    433 | The theorem was proved in six tactic steps, not counting the abandoned
 | 
| 313 |    434 | ones.  But proof checking is tedious; \ttindex{Int.fast_tac} proves the
 | 
| 104 |    435 | theorem in one step.
 | 
|  |    436 | \begin{ttbox}
 | 
|  |    437 | goal IFOL.thy "(EX y. ALL x. Q(x,y)) -->  (ALL x. EX y. Q(x,y))";
 | 
|  |    438 | {\out Level 0}
 | 
|  |    439 | {\out (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    440 | {\out  1. (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    441 | by (Int.fast_tac 1);
 | 
|  |    442 | {\out Level 1}
 | 
|  |    443 | {\out (EX y. ALL x. Q(x,y)) --> (ALL x. EX y. Q(x,y))}
 | 
|  |    444 | {\out No subgoals!}
 | 
|  |    445 | \end{ttbox}
 | 
|  |    446 | 
 | 
|  |    447 | 
 | 
|  |    448 | \section{An example of intuitionistic negation}
 | 
|  |    449 | The following example demonstrates the specialized forms of implication
 | 
|  |    450 | elimination.  Even propositional formulae can be difficult to prove from
 | 
|  |    451 | the basic rules; the specialized rules help considerably.  
 | 
|  |    452 | 
 | 
| 313 |    453 | Propositional examples are easy to invent.  As Dummett notes~\cite[page
 | 
| 104 |    454 | 28]{dummett}, $\neg P$ is classically provable if and only if it is
 | 
| 313 |    455 | intuitionistically provable;  therefore, $P$ is classically provable if and
 | 
|  |    456 | only if $\neg\neg P$ is intuitionistically provable.%
 | 
|  |    457 | \footnote{Of course this holds only for propositional logic, not if $P$ is
 | 
|  |    458 |   allowed to contain quantifiers.} Proving $\neg\neg P$ intuitionistically is
 | 
|  |    459 | much harder than proving~$P$ classically.
 | 
| 104 |    460 | 
 | 
| 313 |    461 | Our example is the double negation of the classical tautology $(P\imp
 | 
|  |    462 | Q)\disj (Q\imp P)$.  When stating the goal, we command Isabelle to expand
 | 
|  |    463 | negations to implications using the definition $\neg P\equiv P\imp\bot$.
 | 
|  |    464 | This allows use of the special implication rules.
 | 
| 104 |    465 | \begin{ttbox}
 | 
|  |    466 | goalw IFOL.thy [not_def] "~ ~ ((P-->Q) | (Q-->P))";
 | 
|  |    467 | {\out Level 0}
 | 
|  |    468 | {\out ~ ~ ((P --> Q) | (Q --> P))}
 | 
|  |    469 | {\out  1. ((P --> Q) | (Q --> P) --> False) --> False}
 | 
|  |    470 | \end{ttbox}
 | 
|  |    471 | The first step is trivial.
 | 
|  |    472 | \begin{ttbox}
 | 
|  |    473 | by (resolve_tac [impI] 1);
 | 
|  |    474 | {\out Level 1}
 | 
|  |    475 | {\out ~ ~ ((P --> Q) | (Q --> P))}
 | 
|  |    476 | {\out  1. (P --> Q) | (Q --> P) --> False ==> False}
 | 
|  |    477 | \end{ttbox}
 | 
| 313 |    478 | By $(\imp E)$ it would suffice to prove $(P\imp Q)\disj (Q\imp P)$, but
 | 
|  |    479 | that formula is not a theorem of intuitionistic logic.  Instead we apply
 | 
|  |    480 | the specialized implication rule \tdx{disj_impE}.  It splits the
 | 
|  |    481 | assumption into two assumptions, one for each disjunct.
 | 
| 104 |    482 | \begin{ttbox}
 | 
|  |    483 | by (eresolve_tac [disj_impE] 1);
 | 
|  |    484 | {\out Level 2}
 | 
|  |    485 | {\out ~ ~ ((P --> Q) | (Q --> P))}
 | 
|  |    486 | {\out  1. [| (P --> Q) --> False; (Q --> P) --> False |] ==> False}
 | 
|  |    487 | \end{ttbox}
 | 
|  |    488 | We cannot hope to prove $P\imp Q$ or $Q\imp P$ separately, but
 | 
| 313 |    489 | their negations are inconsistent.  Applying \tdx{imp_impE} breaks down
 | 
| 104 |    490 | the assumption $\neg(P\imp Q)$, asking to show~$Q$ while providing new
 | 
|  |    491 | assumptions~$P$ and~$\neg Q$.
 | 
|  |    492 | \begin{ttbox}
 | 
|  |    493 | by (eresolve_tac [imp_impE] 1);
 | 
|  |    494 | {\out Level 3}
 | 
|  |    495 | {\out ~ ~ ((P --> Q) | (Q --> P))}
 | 
|  |    496 | {\out  1. [| (Q --> P) --> False; P; Q --> False |] ==> Q}
 | 
|  |    497 | {\out  2. [| (Q --> P) --> False; False |] ==> False}
 | 
|  |    498 | \end{ttbox}
 | 
|  |    499 | Subgoal~2 holds trivially; let us ignore it and continue working on
 | 
|  |    500 | subgoal~1.  Thanks to the assumption~$P$, we could prove $Q\imp P$;
 | 
| 313 |    501 | applying \tdx{imp_impE} is simpler.
 | 
| 104 |    502 | \begin{ttbox}
 | 
|  |    503 | by (eresolve_tac [imp_impE] 1);
 | 
|  |    504 | {\out Level 4}
 | 
|  |    505 | {\out ~ ~ ((P --> Q) | (Q --> P))}
 | 
|  |    506 | {\out  1. [| P; Q --> False; Q; P --> False |] ==> P}
 | 
|  |    507 | {\out  2. [| P; Q --> False; False |] ==> Q}
 | 
|  |    508 | {\out  3. [| (Q --> P) --> False; False |] ==> False}
 | 
|  |    509 | \end{ttbox}
 | 
|  |    510 | The three subgoals are all trivial.
 | 
|  |    511 | \begin{ttbox}
 | 
|  |    512 | by (REPEAT (eresolve_tac [FalseE] 2));
 | 
|  |    513 | {\out Level 5}
 | 
|  |    514 | {\out ~ ~ ((P --> Q) | (Q --> P))}
 | 
|  |    515 | {\out  1. [| P; Q --> False; Q; P --> False |] ==> P}
 | 
| 287 |    516 | \ttbreak
 | 
| 104 |    517 | by (assume_tac 1);
 | 
|  |    518 | {\out Level 6}
 | 
|  |    519 | {\out ~ ~ ((P --> Q) | (Q --> P))}
 | 
|  |    520 | {\out No subgoals!}
 | 
|  |    521 | \end{ttbox}
 | 
|  |    522 | This proof is also trivial for {\tt Int.fast_tac}.
 | 
|  |    523 | 
 | 
|  |    524 | 
 | 
|  |    525 | \section{A classical example} \label{fol-cla-example}
 | 
|  |    526 | To illustrate classical logic, we shall prove the theorem
 | 
| 313 |    527 | $\ex{y}\all{x}P(y)\imp P(x)$.  Informally, the theorem can be proved as
 | 
| 104 |    528 | follows.  Choose~$y$ such that~$\neg P(y)$, if such exists; otherwise
 | 
|  |    529 | $\all{x}P(x)$ is true.  Either way the theorem holds.
 | 
|  |    530 | 
 | 
|  |    531 | The formal proof does not conform in any obvious way to the sketch given
 | 
| 313 |    532 | above.  The key inference is the first one, \tdx{exCI}; this classical
 | 
| 104 |    533 | version of~$(\exists I)$ allows multiple instantiation of the quantifier.
 | 
|  |    534 | \begin{ttbox}
 | 
|  |    535 | goal FOL.thy "EX y. ALL x. P(y)-->P(x)";
 | 
|  |    536 | {\out Level 0}
 | 
|  |    537 | {\out EX y. ALL x. P(y) --> P(x)}
 | 
|  |    538 | {\out  1. EX y. ALL x. P(y) --> P(x)}
 | 
|  |    539 | \ttbreak
 | 
|  |    540 | by (resolve_tac [exCI] 1);
 | 
|  |    541 | {\out Level 1}
 | 
|  |    542 | {\out EX y. ALL x. P(y) --> P(x)}
 | 
|  |    543 | {\out  1. ALL y. ~ (ALL x. P(y) --> P(x)) ==> ALL x. P(?a) --> P(x)}
 | 
|  |    544 | \end{ttbox}
 | 
| 313 |    545 | We can either exhibit a term {\tt?a} to satisfy the conclusion of
 | 
| 104 |    546 | subgoal~1, or produce a contradiction from the assumption.  The next
 | 
| 313 |    547 | steps are routine.
 | 
| 104 |    548 | \begin{ttbox}
 | 
|  |    549 | by (resolve_tac [allI] 1);
 | 
|  |    550 | {\out Level 2}
 | 
|  |    551 | {\out EX y. ALL x. P(y) --> P(x)}
 | 
|  |    552 | {\out  1. !!x. ALL y. ~ (ALL x. P(y) --> P(x)) ==> P(?a) --> P(x)}
 | 
|  |    553 | \ttbreak
 | 
|  |    554 | by (resolve_tac [impI] 1);
 | 
|  |    555 | {\out Level 3}
 | 
|  |    556 | {\out EX y. ALL x. P(y) --> P(x)}
 | 
|  |    557 | {\out  1. !!x. [| ALL y. ~ (ALL x. P(y) --> P(x)); P(?a) |] ==> P(x)}
 | 
| 313 |    558 | \end{ttbox}
 | 
|  |    559 | By the duality between $\exists$ and~$\forall$, applying~$(\forall E)$
 | 
| 333 |    560 | in effect applies~$(\exists I)$ again.
 | 
| 313 |    561 | \begin{ttbox}
 | 
| 104 |    562 | by (eresolve_tac [allE] 1);
 | 
|  |    563 | {\out Level 4}
 | 
|  |    564 | {\out EX y. ALL x. P(y) --> P(x)}
 | 
|  |    565 | {\out  1. !!x. [| P(?a); ~ (ALL xa. P(?y3(x)) --> P(xa)) |] ==> P(x)}
 | 
|  |    566 | \end{ttbox}
 | 
|  |    567 | In classical logic, a negated assumption is equivalent to a conclusion.  To
 | 
| 313 |    568 | get this effect, we create a swapped version of~$(\forall I)$ and apply it
 | 
| 104 |    569 | using \ttindex{eresolve_tac}; we could equivalently have applied~$(\forall
 | 
|  |    570 | I)$ using \ttindex{swap_res_tac}.
 | 
|  |    571 | \begin{ttbox}
 | 
|  |    572 | allI RSN (2,swap);
 | 
|  |    573 | {\out val it = "[| ~ (ALL x. ?P1(x)); !!x. ~ ?Q ==> ?P1(x) |] ==> ?Q" : thm}
 | 
|  |    574 | by (eresolve_tac [it] 1);
 | 
|  |    575 | {\out Level 5}
 | 
|  |    576 | {\out EX y. ALL x. P(y) --> P(x)}
 | 
|  |    577 | {\out  1. !!x xa. [| P(?a); ~ P(x) |] ==> P(?y3(x)) --> P(xa)}
 | 
|  |    578 | \end{ttbox}
 | 
| 313 |    579 | The previous conclusion, {\tt P(x)}, has become a negated assumption.
 | 
| 104 |    580 | \begin{ttbox}
 | 
|  |    581 | by (resolve_tac [impI] 1);
 | 
|  |    582 | {\out Level 6}
 | 
|  |    583 | {\out EX y. ALL x. P(y) --> P(x)}
 | 
|  |    584 | {\out  1. !!x xa. [| P(?a); ~ P(x); P(?y3(x)) |] ==> P(xa)}
 | 
|  |    585 | \end{ttbox}
 | 
|  |    586 | The subgoal has three assumptions.  We produce a contradiction between the
 | 
| 313 |    587 | \index{assumptions!contradictory} assumptions~\verb|~P(x)| and~{\tt
 | 
|  |    588 |   P(?y3(x))}.  The proof never instantiates the unknown~{\tt?a}.
 | 
| 104 |    589 | \begin{ttbox}
 | 
|  |    590 | by (eresolve_tac [notE] 1);
 | 
|  |    591 | {\out Level 7}
 | 
|  |    592 | {\out EX y. ALL x. P(y) --> P(x)}
 | 
|  |    593 | {\out  1. !!x xa. [| P(?a); P(?y3(x)) |] ==> P(x)}
 | 
|  |    594 | \ttbreak
 | 
|  |    595 | by (assume_tac 1);
 | 
|  |    596 | {\out Level 8}
 | 
|  |    597 | {\out EX y. ALL x. P(y) --> P(x)}
 | 
|  |    598 | {\out No subgoals!}
 | 
|  |    599 | \end{ttbox}
 | 
| 874 |    600 | The civilised way to prove this theorem is through \ttindex{deepen_tac},
 | 
|  |    601 | which automatically uses the classical version of~$(\exists I)$:
 | 
| 104 |    602 | \begin{ttbox}
 | 
|  |    603 | goal FOL.thy "EX y. ALL x. P(y)-->P(x)";
 | 
|  |    604 | {\out Level 0}
 | 
|  |    605 | {\out EX y. ALL x. P(y) --> P(x)}
 | 
|  |    606 | {\out  1. EX y. ALL x. P(y) --> P(x)}
 | 
| 2495 |    607 | by (Deepen_tac 0 1);
 | 
| 874 |    608 | {\out Depth = 0}
 | 
|  |    609 | {\out Depth = 2}
 | 
| 104 |    610 | {\out Level 1}
 | 
|  |    611 | {\out EX y. ALL x. P(y) --> P(x)}
 | 
|  |    612 | {\out No subgoals!}
 | 
|  |    613 | \end{ttbox}
 | 
|  |    614 | If this theorem seems counterintuitive, then perhaps you are an
 | 
|  |    615 | intuitionist.  In constructive logic, proving $\ex{y}\all{x}P(y)\imp P(x)$
 | 
|  |    616 | requires exhibiting a particular term~$t$ such that $\all{x}P(t)\imp P(x)$,
 | 
|  |    617 | which we cannot do without further knowledge about~$P$.
 | 
|  |    618 | 
 | 
|  |    619 | 
 | 
|  |    620 | \section{Derived rules and the classical tactics}
 | 
|  |    621 | Classical first-order logic can be extended with the propositional
 | 
|  |    622 | connective $if(P,Q,R)$, where 
 | 
|  |    623 | $$ if(P,Q,R) \equiv P\conj Q \disj \neg P \conj R. \eqno(if) $$
 | 
|  |    624 | Theorems about $if$ can be proved by treating this as an abbreviation,
 | 
|  |    625 | replacing $if(P,Q,R)$ by $P\conj Q \disj \neg P \conj R$ in subgoals.  But
 | 
|  |    626 | this duplicates~$P$, causing an exponential blowup and an unreadable
 | 
|  |    627 | formula.  Introducing further abbreviations makes the problem worse.
 | 
|  |    628 | 
 | 
|  |    629 | Natural deduction demands rules that introduce and eliminate $if(P,Q,R)$
 | 
|  |    630 | directly, without reference to its definition.  The simple identity
 | 
| 313 |    631 | \[ if(P,Q,R) \,\bimp\, (P\imp Q)\conj (\neg P\imp R) \]
 | 
| 104 |    632 | suggests that the
 | 
|  |    633 | $if$-introduction rule should be
 | 
| 157 |    634 | \[ \infer[({if}\,I)]{if(P,Q,R)}{\infer*{Q}{[P]}  &  \infer*{R}{[\neg P]}} \]
 | 
| 104 |    635 | The $if$-elimination rule reflects the definition of $if(P,Q,R)$ and the
 | 
|  |    636 | elimination rules for~$\disj$ and~$\conj$.
 | 
|  |    637 | \[ \infer[({if}\,E)]{S}{if(P,Q,R) & \infer*{S}{[P,Q]}
 | 
|  |    638 |                                   & \infer*{S}{[\neg P,R]}} 
 | 
|  |    639 | \]
 | 
|  |    640 | Having made these plans, we get down to work with Isabelle.  The theory of
 | 
| 313 |    641 | classical logic, {\tt FOL}, is extended with the constant
 | 
|  |    642 | $if::[o,o,o]\To o$.  The axiom \tdx{if_def} asserts the
 | 
| 104 |    643 | equation~$(if)$.
 | 
|  |    644 | \begin{ttbox}
 | 
|  |    645 | If = FOL +
 | 
| 1388 |    646 | consts  if     :: [o,o,o]=>o
 | 
| 104 |    647 | rules   if_def "if(P,Q,R) == P&Q | ~P&R"
 | 
|  |    648 | end
 | 
|  |    649 | \end{ttbox}
 | 
|  |    650 | The derivations of the introduction and elimination rules demonstrate the
 | 
|  |    651 | methods for rewriting with definitions.  Classical reasoning is required,
 | 
| 313 |    652 | so we use {\tt fast_tac}.
 | 
| 104 |    653 | 
 | 
|  |    654 | 
 | 
|  |    655 | \subsection{Deriving the introduction rule}
 | 
|  |    656 | The introduction rule, given the premises $P\Imp Q$ and $\neg P\Imp R$,
 | 
|  |    657 | concludes $if(P,Q,R)$.  We propose the conclusion as the main goal
 | 
|  |    658 | using~\ttindex{goalw}, which uses {\tt if_def} to rewrite occurrences
 | 
|  |    659 | of $if$ in the subgoal.
 | 
|  |    660 | \begin{ttbox}
 | 
|  |    661 | val prems = goalw If.thy [if_def]
 | 
|  |    662 |     "[| P ==> Q; ~ P ==> R |] ==> if(P,Q,R)";
 | 
|  |    663 | {\out Level 0}
 | 
|  |    664 | {\out if(P,Q,R)}
 | 
|  |    665 | {\out  1. P & Q | ~ P & R}
 | 
|  |    666 | \end{ttbox}
 | 
|  |    667 | The premises (bound to the {\ML} variable {\tt prems}) are passed as
 | 
| 2495 |    668 | introduction rules to \ttindex{fast_tac}.  Remember that {\tt!claset} refers
 | 
|  |    669 | to the default classical set.
 | 
| 104 |    670 | \begin{ttbox}
 | 
| 2495 |    671 | by (fast_tac (!claset addIs prems) 1);
 | 
| 104 |    672 | {\out Level 1}
 | 
|  |    673 | {\out if(P,Q,R)}
 | 
|  |    674 | {\out No subgoals!}
 | 
|  |    675 | val ifI = result();
 | 
|  |    676 | \end{ttbox}
 | 
|  |    677 | 
 | 
|  |    678 | 
 | 
|  |    679 | \subsection{Deriving the elimination rule}
 | 
|  |    680 | The elimination rule has three premises, two of which are themselves rules.
 | 
|  |    681 | The conclusion is simply $S$.
 | 
|  |    682 | \begin{ttbox}
 | 
|  |    683 | val major::prems = goalw If.thy [if_def]
 | 
|  |    684 |    "[| if(P,Q,R);  [| P; Q |] ==> S; [| ~ P; R |] ==> S |] ==> S";
 | 
|  |    685 | {\out Level 0}
 | 
|  |    686 | {\out S}
 | 
|  |    687 | {\out  1. S}
 | 
|  |    688 | \end{ttbox}
 | 
|  |    689 | The major premise contains an occurrence of~$if$, but the version returned
 | 
|  |    690 | by \ttindex{goalw} (and bound to the {\ML} variable~{\tt major}) has the
 | 
|  |    691 | definition expanded.  Now \ttindex{cut_facts_tac} inserts~{\tt major} as an
 | 
|  |    692 | assumption in the subgoal, so that \ttindex{fast_tac} can break it down.
 | 
|  |    693 | \begin{ttbox}
 | 
|  |    694 | by (cut_facts_tac [major] 1);
 | 
|  |    695 | {\out Level 1}
 | 
|  |    696 | {\out S}
 | 
|  |    697 | {\out  1. P & Q | ~ P & R ==> S}
 | 
|  |    698 | \ttbreak
 | 
| 2495 |    699 | by (fast_tac (!claset addIs prems) 1);
 | 
| 104 |    700 | {\out Level 2}
 | 
|  |    701 | {\out S}
 | 
|  |    702 | {\out No subgoals!}
 | 
|  |    703 | val ifE = result();
 | 
|  |    704 | \end{ttbox}
 | 
| 313 |    705 | As you may recall from
 | 
|  |    706 | \iflabelundefined{definitions}{{\em Introduction to Isabelle}}%
 | 
|  |    707 |         {\S\ref{definitions}}, there are other
 | 
| 104 |    708 | ways of treating definitions when deriving a rule.  We can start the
 | 
| 313 |    709 | proof using {\tt goal}, which does not expand definitions, instead of
 | 
| 2495 |    710 | {\tt goalw}.  We can use \ttindex{rew_tac}
 | 
| 104 |    711 | to expand definitions in the subgoals --- perhaps after calling
 | 
|  |    712 | \ttindex{cut_facts_tac} to insert the rule's premises.  We can use
 | 
|  |    713 | \ttindex{rewrite_rule}, which is a meta-inference rule, to expand
 | 
|  |    714 | definitions in the premises directly.
 | 
|  |    715 | 
 | 
|  |    716 | 
 | 
|  |    717 | \subsection{Using the derived rules}
 | 
| 313 |    718 | The rules just derived have been saved with the {\ML} names \tdx{ifI}
 | 
|  |    719 | and~\tdx{ifE}.  They permit natural proofs of theorems such as the
 | 
| 104 |    720 | following:
 | 
|  |    721 | \begin{eqnarray*}
 | 
| 111 |    722 |     if(P, if(Q,A,B), if(Q,C,D)) & \bimp & if(Q,if(P,A,C),if(P,B,D)) \\
 | 
|  |    723 |     if(if(P,Q,R), A, B)         & \bimp & if(P,if(Q,A,B),if(R,A,B))
 | 
| 104 |    724 | \end{eqnarray*}
 | 
|  |    725 | Proofs also require the classical reasoning rules and the $\bimp$
 | 
| 313 |    726 | introduction rule (called~\tdx{iffI}: do not confuse with~{\tt ifI}). 
 | 
| 104 |    727 | 
 | 
|  |    728 | To display the $if$-rules in action, let us analyse a proof step by step.
 | 
|  |    729 | \begin{ttbox}
 | 
|  |    730 | goal If.thy
 | 
|  |    731 |     "if(P, if(Q,A,B), if(Q,C,D)) <-> if(Q, if(P,A,C), if(P,B,D))";
 | 
|  |    732 | {\out Level 0}
 | 
|  |    733 | {\out if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    734 | {\out  1. if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    735 | \ttbreak
 | 
|  |    736 | by (resolve_tac [iffI] 1);
 | 
|  |    737 | {\out Level 1}
 | 
|  |    738 | {\out if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    739 | {\out  1. if(P,if(Q,A,B),if(Q,C,D)) ==> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    740 | {\out  2. if(Q,if(P,A,C),if(P,B,D)) ==> if(P,if(Q,A,B),if(Q,C,D))}
 | 
|  |    741 | \end{ttbox}
 | 
|  |    742 | The $if$-elimination rule can be applied twice in succession.
 | 
|  |    743 | \begin{ttbox}
 | 
|  |    744 | by (eresolve_tac [ifE] 1);
 | 
|  |    745 | {\out Level 2}
 | 
|  |    746 | {\out if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    747 | {\out  1. [| P; if(Q,A,B) |] ==> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    748 | {\out  2. [| ~ P; if(Q,C,D) |] ==> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    749 | {\out  3. if(Q,if(P,A,C),if(P,B,D)) ==> if(P,if(Q,A,B),if(Q,C,D))}
 | 
|  |    750 | \ttbreak
 | 
|  |    751 | by (eresolve_tac [ifE] 1);
 | 
|  |    752 | {\out Level 3}
 | 
|  |    753 | {\out if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    754 | {\out  1. [| P; Q; A |] ==> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    755 | {\out  2. [| P; ~ Q; B |] ==> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    756 | {\out  3. [| ~ P; if(Q,C,D) |] ==> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    757 | {\out  4. if(Q,if(P,A,C),if(P,B,D)) ==> if(P,if(Q,A,B),if(Q,C,D))}
 | 
|  |    758 | \end{ttbox}
 | 
| 333 |    759 | %
 | 
|  |    760 | In the first two subgoals, all assumptions have been reduced to atoms.  Now
 | 
| 104 |    761 | $if$-introduction can be applied.  Observe how the $if$-rules break down
 | 
|  |    762 | occurrences of $if$ when they become the outermost connective.
 | 
|  |    763 | \begin{ttbox}
 | 
|  |    764 | by (resolve_tac [ifI] 1);
 | 
|  |    765 | {\out Level 4}
 | 
|  |    766 | {\out if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    767 | {\out  1. [| P; Q; A; Q |] ==> if(P,A,C)}
 | 
|  |    768 | {\out  2. [| P; Q; A; ~ Q |] ==> if(P,B,D)}
 | 
|  |    769 | {\out  3. [| P; ~ Q; B |] ==> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    770 | {\out  4. [| ~ P; if(Q,C,D) |] ==> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    771 | {\out  5. if(Q,if(P,A,C),if(P,B,D)) ==> if(P,if(Q,A,B),if(Q,C,D))}
 | 
|  |    772 | \ttbreak
 | 
|  |    773 | by (resolve_tac [ifI] 1);
 | 
|  |    774 | {\out Level 5}
 | 
|  |    775 | {\out if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    776 | {\out  1. [| P; Q; A; Q; P |] ==> A}
 | 
|  |    777 | {\out  2. [| P; Q; A; Q; ~ P |] ==> C}
 | 
|  |    778 | {\out  3. [| P; Q; A; ~ Q |] ==> if(P,B,D)}
 | 
|  |    779 | {\out  4. [| P; ~ Q; B |] ==> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    780 | {\out  5. [| ~ P; if(Q,C,D) |] ==> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    781 | {\out  6. if(Q,if(P,A,C),if(P,B,D)) ==> if(P,if(Q,A,B),if(Q,C,D))}
 | 
|  |    782 | \end{ttbox}
 | 
|  |    783 | Where do we stand?  The first subgoal holds by assumption; the second and
 | 
| 2495 |    784 | third, by contradiction.  This is getting tedious.  We could use the classical
 | 
|  |    785 | reasoner, but first let us extend the default claset with the derived rules
 | 
| 104 |    786 | for~$if$.
 | 
|  |    787 | \begin{ttbox}
 | 
| 2495 |    788 | AddSIs [ifI];
 | 
|  |    789 | AddSEs [ifE];
 | 
|  |    790 | \end{ttbox}
 | 
|  |    791 | Now we can revert to the
 | 
|  |    792 | initial proof state and let \ttindex{fast_tac} solve it.  
 | 
|  |    793 | \begin{ttbox}
 | 
| 104 |    794 | choplev 0;
 | 
|  |    795 | {\out Level 0}
 | 
|  |    796 | {\out if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    797 | {\out  1. if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))}
 | 
| 2495 |    798 | by (Fast_tac 1);
 | 
| 104 |    799 | {\out Level 1}
 | 
|  |    800 | {\out if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))}
 | 
|  |    801 | {\out No subgoals!}
 | 
|  |    802 | \end{ttbox}
 | 
|  |    803 | This tactic also solves the other example.
 | 
|  |    804 | \begin{ttbox}
 | 
|  |    805 | goal If.thy "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,A,B))";
 | 
|  |    806 | {\out Level 0}
 | 
|  |    807 | {\out if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))}
 | 
|  |    808 | {\out  1. if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))}
 | 
|  |    809 | \ttbreak
 | 
| 2495 |    810 | by (Fast_tac 1);
 | 
| 104 |    811 | {\out Level 1}
 | 
|  |    812 | {\out if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))}
 | 
|  |    813 | {\out No subgoals!}
 | 
|  |    814 | \end{ttbox}
 | 
|  |    815 | 
 | 
|  |    816 | 
 | 
|  |    817 | \subsection{Derived rules versus definitions}
 | 
|  |    818 | Dispensing with the derived rules, we can treat $if$ as an
 | 
|  |    819 | abbreviation, and let \ttindex{fast_tac} prove the expanded formula.  Let
 | 
|  |    820 | us redo the previous proof:
 | 
|  |    821 | \begin{ttbox}
 | 
|  |    822 | choplev 0;
 | 
|  |    823 | {\out Level 0}
 | 
|  |    824 | {\out if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))}
 | 
|  |    825 | {\out  1. if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))}
 | 
| 287 |    826 | \end{ttbox}
 | 
|  |    827 | This time, simply unfold using the definition of $if$:
 | 
|  |    828 | \begin{ttbox}
 | 
| 2495 |    829 | by (rewtac if_def);
 | 
| 104 |    830 | {\out Level 1}
 | 
|  |    831 | {\out if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))}
 | 
|  |    832 | {\out  1. (P & Q | ~ P & R) & A | ~ (P & Q | ~ P & R) & B <->}
 | 
|  |    833 | {\out     P & (Q & A | ~ Q & B) | ~ P & (R & A | ~ R & B)}
 | 
| 287 |    834 | \end{ttbox}
 | 
| 2495 |    835 | We are left with a subgoal in pure first-order logic, which is why the 
 | 
|  |    836 | classical reasoner can prove it given {\tt FOL_cs} alone.  (We could, of 
 | 
|  |    837 | course, have used {\tt Fast_tac}.)
 | 
| 287 |    838 | \begin{ttbox}
 | 
| 104 |    839 | by (fast_tac FOL_cs 1);
 | 
|  |    840 | {\out Level 2}
 | 
|  |    841 | {\out if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))}
 | 
|  |    842 | {\out No subgoals!}
 | 
|  |    843 | \end{ttbox}
 | 
|  |    844 | Expanding definitions reduces the extended logic to the base logic.  This
 | 
|  |    845 | approach has its merits --- especially if the prover for the base logic is
 | 
| 2495 |    846 | good --- but can be slow.  In these examples, proofs using the default
 | 
|  |    847 | claset (which includes the derived rules) run about six times faster 
 | 
|  |    848 | than proofs using {\tt FOL_cs}.
 | 
| 104 |    849 | 
 | 
|  |    850 | Expanding definitions also complicates error diagnosis.  Suppose we are having
 | 
|  |    851 | difficulties in proving some goal.  If by expanding definitions we have
 | 
|  |    852 | made it unreadable, then we have little hope of diagnosing the problem.
 | 
|  |    853 | 
 | 
|  |    854 | Attempts at program verification often yield invalid assertions.
 | 
|  |    855 | Let us try to prove one:
 | 
|  |    856 | \begin{ttbox}
 | 
|  |    857 | goal If.thy "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,B,A))";
 | 
|  |    858 | {\out Level 0}
 | 
|  |    859 | {\out if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))}
 | 
|  |    860 | {\out  1. if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))}
 | 
| 2495 |    861 | by (Fast_tac 1);
 | 
| 104 |    862 | {\out by: tactic failed}
 | 
|  |    863 | \end{ttbox}
 | 
|  |    864 | This failure message is uninformative, but we can get a closer look at the
 | 
|  |    865 | situation by applying \ttindex{step_tac}.
 | 
|  |    866 | \begin{ttbox}
 | 
| 2495 |    867 | by (REPEAT (Step_tac 1));
 | 
| 104 |    868 | {\out Level 1}
 | 
|  |    869 | {\out if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))}
 | 
|  |    870 | {\out  1. [| A; ~ P; R; ~ P; R |] ==> B}
 | 
|  |    871 | {\out  2. [| B; ~ P; ~ R; ~ P; ~ R |] ==> A}
 | 
|  |    872 | {\out  3. [| ~ P; R; B; ~ P; R |] ==> A}
 | 
|  |    873 | {\out  4. [| ~ P; ~ R; A; ~ B; ~ P |] ==> R}
 | 
|  |    874 | \end{ttbox}
 | 
|  |    875 | Subgoal~1 is unprovable and yields a countermodel: $P$ and~$B$ are false
 | 
|  |    876 | while~$R$ and~$A$ are true.  This truth assignment reduces the main goal to
 | 
|  |    877 | $true\bimp false$, which is of course invalid.
 | 
|  |    878 | 
 | 
|  |    879 | We can repeat this analysis by expanding definitions, using just
 | 
|  |    880 | the rules of {\FOL}:
 | 
|  |    881 | \begin{ttbox}
 | 
|  |    882 | choplev 0;
 | 
|  |    883 | {\out Level 0}
 | 
|  |    884 | {\out if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))}
 | 
|  |    885 | {\out  1. if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))}
 | 
|  |    886 | \ttbreak
 | 
| 2495 |    887 | by (rewtac if_def);
 | 
| 104 |    888 | {\out Level 1}
 | 
|  |    889 | {\out if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))}
 | 
|  |    890 | {\out  1. (P & Q | ~ P & R) & A | ~ (P & Q | ~ P & R) & B <->}
 | 
|  |    891 | {\out     P & (Q & A | ~ Q & B) | ~ P & (R & B | ~ R & A)}
 | 
|  |    892 | by (fast_tac FOL_cs 1);
 | 
|  |    893 | {\out by: tactic failed}
 | 
|  |    894 | \end{ttbox}
 | 
|  |    895 | Again we apply \ttindex{step_tac}:
 | 
|  |    896 | \begin{ttbox}
 | 
|  |    897 | by (REPEAT (step_tac FOL_cs 1));
 | 
|  |    898 | {\out Level 2}
 | 
|  |    899 | {\out if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))}
 | 
|  |    900 | {\out  1. [| A; ~ P; R; ~ P; R; ~ False |] ==> B}
 | 
|  |    901 | {\out  2. [| A; ~ P; R; R; ~ False; ~ B; ~ B |] ==> Q}
 | 
|  |    902 | {\out  3. [| B; ~ P; ~ R; ~ P; ~ A |] ==> R}
 | 
|  |    903 | {\out  4. [| B; ~ P; ~ R; ~ Q; ~ A |] ==> R}
 | 
|  |    904 | {\out  5. [| B; ~ R; ~ P; ~ A; ~ R; Q; ~ False |] ==> A}
 | 
|  |    905 | {\out  6. [| ~ P; R; B; ~ P; R; ~ False |] ==> A}
 | 
|  |    906 | {\out  7. [| ~ P; ~ R; A; ~ B; ~ R |] ==> P}
 | 
|  |    907 | {\out  8. [| ~ P; ~ R; A; ~ B; ~ R |] ==> Q}
 | 
|  |    908 | \end{ttbox}
 | 
|  |    909 | Subgoal~1 yields the same countermodel as before.  But each proof step has
 | 
|  |    910 | taken six times as long, and the final result contains twice as many subgoals.
 | 
|  |    911 | 
 | 
|  |    912 | Expanding definitions causes a great increase in complexity.  This is why
 | 
|  |    913 | the classical prover has been designed to accept derived rules.
 | 
| 313 |    914 | 
 | 
|  |    915 | \index{first-order logic|)}
 |