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