doc-src/Ref/classical.tex
author wenzelm
Tue, 06 May 1997 12:50:16 +0200
changeset 3108 335efc3f5632
parent 3089 32dad29d4666
child 3224 4ea2aa9f93a5
permissions -rw-r--r--
misc updates, tuning, cleanup;
lcp@104
     1
%% $Id$
lcp@319
     2
\chapter{The Classical Reasoner}\label{chap:classical}
lcp@286
     3
\index{classical reasoner|(}
lcp@308
     4
\newcommand\ainfer[2]{\begin{array}{r@{\,}l}#2\\ \hline#1\end{array}}
lcp@308
     5
wenzelm@3108
     6
Although Isabelle is generic, many users will be working in some
wenzelm@3108
     7
extension of classical first-order logic.  Isabelle's set theory~{\tt
wenzelm@3108
     8
  ZF} is built upon theory~{\tt FOL}, while higher-order logic
wenzelm@3108
     9
conceptually contains first-order logic as a fragment.
wenzelm@3108
    10
Theorem-proving in predicate logic is undecidable, but many
lcp@308
    11
researchers have developed strategies to assist in this task.
lcp@104
    12
lcp@286
    13
Isabelle's classical reasoner is an \ML{} functor that accepts certain
lcp@104
    14
information about a logic and delivers a suite of automatic tactics.  Each
lcp@104
    15
tactic takes a collection of rules and executes a simple, non-clausal proof
lcp@104
    16
procedure.  They are slow and simplistic compared with resolution theorem
lcp@104
    17
provers, but they can save considerable time and effort.  They can prove
lcp@104
    18
theorems such as Pelletier's~\cite{pelletier86} problems~40 and~41 in
lcp@104
    19
seconds:
lcp@104
    20
\[ (\exists y. \forall x. J(y,x) \bimp \neg J(x,x))  
lcp@104
    21
   \imp  \neg (\forall x. \exists y. \forall z. J(z,y) \bimp \neg J(z,x)) \]
lcp@104
    22
\[ (\forall z. \exists y. \forall x. F(x,y) \bimp F(x,z) \conj \neg F(x,x))
lcp@104
    23
   \imp \neg (\exists z. \forall x. F(x,z))  
lcp@104
    24
\]
lcp@308
    25
%
lcp@308
    26
The tactics are generic.  They are not restricted to first-order logic, and
lcp@308
    27
have been heavily used in the development of Isabelle's set theory.  Few
lcp@308
    28
interactive proof assistants provide this much automation.  The tactics can
lcp@308
    29
be traced, and their components can be called directly; in this manner,
lcp@308
    30
any proof can be viewed interactively.
lcp@104
    31
paulson@2479
    32
The simplest way to apply the classical reasoner (to subgoal~$i$) is as
paulson@2479
    33
follows:
paulson@2479
    34
\begin{ttbox}
paulson@3089
    35
by (Blast_tac \(i\));
paulson@2479
    36
\end{ttbox}
paulson@2479
    37
If the subgoal is a simple formula of the predicate calculus or set theory,
paulson@2479
    38
then it should be proved quickly.  However, to use the classical reasoner
paulson@3089
    39
effectively, you need to know how it works and how to choose among the many
paulson@3089
    40
tactics available, including {\tt Fast_tac} and {\tt Best_tac}.
paulson@2479
    41
wenzelm@3108
    42
We shall first discuss the underlying principles, then present the
wenzelm@3108
    43
classical reasoner.  Finally, we shall see how to instantiate it for
wenzelm@3108
    44
new logics.  The logics \FOL, \ZF, {\HOL} and {\HOLCF} have it already
wenzelm@3108
    45
installed.
lcp@104
    46
lcp@104
    47
lcp@104
    48
\section{The sequent calculus}
lcp@104
    49
\index{sequent calculus}
lcp@104
    50
Isabelle supports natural deduction, which is easy to use for interactive
lcp@104
    51
proof.  But natural deduction does not easily lend itself to automation,
lcp@104
    52
and has a bias towards intuitionism.  For certain proofs in classical
lcp@104
    53
logic, it can not be called natural.  The {\bf sequent calculus}, a
lcp@104
    54
generalization of natural deduction, is easier to automate.
lcp@104
    55
lcp@104
    56
A {\bf sequent} has the form $\Gamma\turn\Delta$, where $\Gamma$
lcp@308
    57
and~$\Delta$ are sets of formulae.%
lcp@308
    58
\footnote{For first-order logic, sequents can equivalently be made from
lcp@308
    59
  lists or multisets of formulae.} The sequent
lcp@104
    60
\[ P@1,\ldots,P@m\turn Q@1,\ldots,Q@n \]
lcp@104
    61
is {\bf valid} if $P@1\conj\ldots\conj P@m$ implies $Q@1\disj\ldots\disj
lcp@104
    62
Q@n$.  Thus $P@1,\ldots,P@m$ represent assumptions, each of which is true,
lcp@104
    63
while $Q@1,\ldots,Q@n$ represent alternative goals.  A sequent is {\bf
lcp@104
    64
basic} if its left and right sides have a common formula, as in $P,Q\turn
lcp@104
    65
Q,R$; basic sequents are trivially valid.
lcp@104
    66
lcp@104
    67
Sequent rules are classified as {\bf right} or {\bf left}, indicating which
lcp@104
    68
side of the $\turn$~symbol they operate on.  Rules that operate on the
lcp@104
    69
right side are analogous to natural deduction's introduction rules, and
lcp@308
    70
left rules are analogous to elimination rules.  
lcp@308
    71
Recall the natural deduction rules for
lcp@308
    72
  first-order logic, 
lcp@308
    73
\iflabelundefined{fol-fig}{from {\it Introduction to Isabelle}}%
lcp@308
    74
                          {Fig.\ts\ref{fol-fig}}.
lcp@308
    75
The sequent calculus analogue of~$({\imp}I)$ is the rule
wenzelm@3108
    76
$$
wenzelm@3108
    77
\ainfer{\Gamma &\turn \Delta, P\imp Q}{P,\Gamma &\turn \Delta,Q}
wenzelm@3108
    78
\eqno({\imp}R)
wenzelm@3108
    79
$$
lcp@104
    80
This breaks down some implication on the right side of a sequent; $\Gamma$
lcp@104
    81
and $\Delta$ stand for the sets of formulae that are unaffected by the
lcp@104
    82
inference.  The analogue of the pair~$({\disj}I1)$ and~$({\disj}I2)$ is the
lcp@104
    83
single rule 
wenzelm@3108
    84
$$
wenzelm@3108
    85
\ainfer{\Gamma &\turn \Delta, P\disj Q}{\Gamma &\turn \Delta,P,Q}
wenzelm@3108
    86
\eqno({\disj}R)
wenzelm@3108
    87
$$
lcp@104
    88
This breaks down some disjunction on the right side, replacing it by both
lcp@104
    89
disjuncts.  Thus, the sequent calculus is a kind of multiple-conclusion logic.
lcp@104
    90
lcp@104
    91
To illustrate the use of multiple formulae on the right, let us prove
lcp@104
    92
the classical theorem $(P\imp Q)\disj(Q\imp P)$.  Working backwards, we
lcp@104
    93
reduce this formula to a basic sequent:
lcp@104
    94
\[ \infer[(\disj)R]{\turn(P\imp Q)\disj(Q\imp P)}
lcp@104
    95
   {\infer[(\imp)R]{\turn(P\imp Q), (Q\imp P)\;}
lcp@104
    96
    {\infer[(\imp)R]{P \turn Q, (Q\imp P)\qquad}
lcp@104
    97
                    {P, Q \turn Q, P\qquad\qquad}}}
lcp@104
    98
\]
lcp@104
    99
This example is typical of the sequent calculus: start with the desired
lcp@104
   100
theorem and apply rules backwards in a fairly arbitrary manner.  This yields a
lcp@104
   101
surprisingly effective proof procedure.  Quantifiers add few complications,
lcp@104
   102
since Isabelle handles parameters and schematic variables.  See Chapter~10
lcp@104
   103
of {\em ML for the Working Programmer}~\cite{paulson91} for further
lcp@104
   104
discussion.
lcp@104
   105
lcp@104
   106
lcp@104
   107
\section{Simulating sequents by natural deduction}
lcp@308
   108
Isabelle can represent sequents directly, as in the object-logic~{\tt LK}\@.
lcp@104
   109
But natural deduction is easier to work with, and most object-logics employ
lcp@104
   110
it.  Fortunately, we can simulate the sequent $P@1,\ldots,P@m\turn
lcp@104
   111
Q@1,\ldots,Q@n$ by the Isabelle formula
lcp@104
   112
\[ \List{P@1;\ldots;P@m; \neg Q@2;\ldots; \neg Q@n}\Imp Q@1, \]
lcp@104
   113
where the order of the assumptions and the choice of~$Q@1$ are arbitrary.
lcp@104
   114
Elim-resolution plays a key role in simulating sequent proofs.
lcp@104
   115
lcp@104
   116
We can easily handle reasoning on the left.
lcp@308
   117
As discussed in
lcp@308
   118
\iflabelundefined{destruct}{{\it Introduction to Isabelle}}{\S\ref{destruct}}, 
lcp@104
   119
elim-resolution with the rules $(\disj E)$, $(\bot E)$ and $(\exists E)$
lcp@104
   120
achieves a similar effect as the corresponding sequent rules.  For the
lcp@104
   121
other connectives, we use sequent-style elimination rules instead of
lcp@308
   122
destruction rules such as $({\conj}E1,2)$ and $(\forall E)$.  But note that
lcp@308
   123
the rule $(\neg L)$ has no effect under our representation of sequents!
wenzelm@3108
   124
$$
wenzelm@3108
   125
\ainfer{\neg P,\Gamma &\turn \Delta}{\Gamma &\turn \Delta,P}\eqno({\neg}L)
wenzelm@3108
   126
$$
lcp@104
   127
What about reasoning on the right?  Introduction rules can only affect the
lcp@308
   128
formula in the conclusion, namely~$Q@1$.  The other right-side formulae are
lcp@319
   129
represented as negated assumptions, $\neg Q@2$, \ldots,~$\neg Q@n$.  
lcp@319
   130
\index{assumptions!negated}
lcp@319
   131
In order to operate on one of these, it must first be exchanged with~$Q@1$.
lcp@104
   132
Elim-resolution with the {\bf swap} rule has this effect:
wenzelm@3108
   133
$$ \List{\neg P; \; \neg R\Imp P} \Imp R   \eqno(swap)  $$
lcp@104
   134
To ensure that swaps occur only when necessary, each introduction rule is
lcp@104
   135
converted into a swapped form: it is resolved with the second premise
lcp@104
   136
of~$(swap)$.  The swapped form of~$({\conj}I)$, which might be
lcp@104
   137
called~$({\neg\conj}E)$, is
lcp@104
   138
\[ \List{\neg(P\conj Q); \; \neg R\Imp P; \; \neg R\Imp Q} \Imp R. \]
lcp@104
   139
Similarly, the swapped form of~$({\imp}I)$ is
lcp@104
   140
\[ \List{\neg(P\imp Q); \; \List{\neg R;P}\Imp Q} \Imp R  \]
lcp@104
   141
Swapped introduction rules are applied using elim-resolution, which deletes
lcp@104
   142
the negated formula.  Our representation of sequents also requires the use
lcp@104
   143
of ordinary introduction rules.  If we had no regard for readability, we
lcp@104
   144
could treat the right side more uniformly by representing sequents as
lcp@104
   145
\[ \List{P@1;\ldots;P@m; \neg Q@1;\ldots; \neg Q@n}\Imp \bot. \]
lcp@104
   146
lcp@104
   147
lcp@104
   148
\section{Extra rules for the sequent calculus}
lcp@104
   149
As mentioned, destruction rules such as $({\conj}E1,2)$ and $(\forall E)$
lcp@104
   150
must be replaced by sequent-style elimination rules.  In addition, we need
lcp@104
   151
rules to embody the classical equivalence between $P\imp Q$ and $\neg P\disj
lcp@104
   152
Q$.  The introduction rules~$({\disj}I1,2)$ are replaced by a rule that
lcp@104
   153
simulates $({\disj}R)$:
lcp@104
   154
\[ (\neg Q\Imp P) \Imp P\disj Q \]
lcp@104
   155
The destruction rule $({\imp}E)$ is replaced by
lcp@332
   156
\[ \List{P\imp Q;\; \neg P\Imp R;\; Q\Imp R} \Imp R. \]
lcp@104
   157
Quantifier replication also requires special rules.  In classical logic,
lcp@308
   158
$\exists x{.}P$ is equivalent to $\neg\forall x{.}\neg P$; the rules
lcp@308
   159
$(\exists R)$ and $(\forall L)$ are dual:
lcp@104
   160
\[ \ainfer{\Gamma &\turn \Delta, \exists x{.}P}
lcp@104
   161
          {\Gamma &\turn \Delta, \exists x{.}P, P[t/x]} \; (\exists R)
lcp@104
   162
   \qquad
lcp@104
   163
   \ainfer{\forall x{.}P, \Gamma &\turn \Delta}
lcp@104
   164
          {P[t/x], \forall x{.}P, \Gamma &\turn \Delta} \; (\forall L)
lcp@104
   165
\]
lcp@104
   166
Thus both kinds of quantifier may be replicated.  Theorems requiring
lcp@104
   167
multiple uses of a universal formula are easy to invent; consider 
lcp@308
   168
\[ (\forall x.P(x)\imp P(f(x))) \conj P(a) \imp P(f^n(a)), \]
lcp@308
   169
for any~$n>1$.  Natural examples of the multiple use of an existential
lcp@308
   170
formula are rare; a standard one is $\exists x.\forall y. P(x)\imp P(y)$.
lcp@104
   171
lcp@104
   172
Forgoing quantifier replication loses completeness, but gains decidability,
lcp@104
   173
since the search space becomes finite.  Many useful theorems can be proved
lcp@104
   174
without replication, and the search generally delivers its verdict in a
lcp@104
   175
reasonable time.  To adopt this approach, represent the sequent rules
lcp@104
   176
$(\exists R)$, $(\exists L)$ and $(\forall R)$ by $(\exists I)$, $(\exists
lcp@104
   177
E)$ and $(\forall I)$, respectively, and put $(\forall E)$ into elimination
lcp@104
   178
form:
lcp@104
   179
$$ \List{\forall x{.}P(x); P(t)\Imp Q} \Imp Q    \eqno(\forall E@2) $$
lcp@104
   180
Elim-resolution with this rule will delete the universal formula after a
lcp@104
   181
single use.  To replicate universal quantifiers, replace the rule by
wenzelm@3108
   182
$$
wenzelm@3108
   183
\List{\forall x{.}P(x);\; \List{P(t); \forall x{.}P(x)}\Imp Q} \Imp Q.
wenzelm@3108
   184
\eqno(\forall E@3)
wenzelm@3108
   185
$$
lcp@104
   186
To replicate existential quantifiers, replace $(\exists I)$ by
lcp@332
   187
\[ \List{\neg(\exists x{.}P(x)) \Imp P(t)} \Imp \exists x{.}P(x). \]
lcp@104
   188
All introduction rules mentioned above are also useful in swapped form.
lcp@104
   189
lcp@104
   190
Replication makes the search space infinite; we must apply the rules with
lcp@286
   191
care.  The classical reasoner distinguishes between safe and unsafe
lcp@104
   192
rules, applying the latter only when there is no alternative.  Depth-first
lcp@104
   193
search may well go down a blind alley; best-first search is better behaved
lcp@104
   194
in an infinite search space.  However, quantifier replication is too
lcp@104
   195
expensive to prove any but the simplest theorems.
lcp@104
   196
lcp@104
   197
lcp@104
   198
\section{Classical rule sets}
lcp@319
   199
\index{classical sets}
lcp@319
   200
Each automatic tactic takes a {\bf classical set} --- a collection of
lcp@104
   201
rules, classified as introduction or elimination and as {\bf safe} or {\bf
lcp@104
   202
unsafe}.  In general, safe rules can be attempted blindly, while unsafe
lcp@104
   203
rules must be used with care.  A safe rule must never reduce a provable
lcp@308
   204
goal to an unprovable set of subgoals.  
lcp@104
   205
lcp@308
   206
The rule~$({\disj}I1)$ is unsafe because it reduces $P\disj Q$ to~$P$.  Any
lcp@308
   207
rule is unsafe whose premises contain new unknowns.  The elimination
lcp@308
   208
rule~$(\forall E@2)$ is unsafe, since it is applied via elim-resolution,
lcp@308
   209
which discards the assumption $\forall x{.}P(x)$ and replaces it by the
lcp@308
   210
weaker assumption~$P(\Var{t})$.  The rule $({\exists}I)$ is unsafe for
lcp@308
   211
similar reasons.  The rule~$(\forall E@3)$ is unsafe in a different sense:
lcp@308
   212
since it keeps the assumption $\forall x{.}P(x)$, it is prone to looping.
lcp@308
   213
In classical first-order logic, all rules are safe except those mentioned
lcp@308
   214
above.
lcp@104
   215
lcp@104
   216
The safe/unsafe distinction is vague, and may be regarded merely as a way
lcp@104
   217
of giving some rules priority over others.  One could argue that
lcp@104
   218
$({\disj}E)$ is unsafe, because repeated application of it could generate
lcp@104
   219
exponentially many subgoals.  Induction rules are unsafe because inductive
lcp@104
   220
proofs are difficult to set up automatically.  Any inference is unsafe that
lcp@104
   221
instantiates an unknown in the proof state --- thus \ttindex{match_tac}
lcp@104
   222
must be used, rather than \ttindex{resolve_tac}.  Even proof by assumption
lcp@104
   223
is unsafe if it instantiates unknowns shared with other subgoals --- thus
lcp@104
   224
\ttindex{eq_assume_tac} must be used, rather than \ttindex{assume_tac}.
lcp@104
   225
lcp@1099
   226
\subsection{Adding rules to classical sets}
lcp@319
   227
Classical rule sets belong to the abstract type \mltydx{claset}, which
lcp@286
   228
supports the following operations (provided the classical reasoner is
lcp@104
   229
installed!):
lcp@104
   230
\begin{ttbox} 
lcp@1099
   231
empty_cs    : claset
lcp@1099
   232
print_cs    : claset -> unit
lcp@1099
   233
addSIs      : claset * thm list -> claset                 \hfill{\bf infix 4}
lcp@1099
   234
addSEs      : claset * thm list -> claset                 \hfill{\bf infix 4}
lcp@1099
   235
addSDs      : claset * thm list -> claset                 \hfill{\bf infix 4}
lcp@1099
   236
addIs       : claset * thm list -> claset                 \hfill{\bf infix 4}
lcp@1099
   237
addEs       : claset * thm list -> claset                 \hfill{\bf infix 4}
lcp@1099
   238
addDs       : claset * thm list -> claset                 \hfill{\bf infix 4}
berghofe@1869
   239
delrules    : claset * thm list -> claset                 \hfill{\bf infix 4}
lcp@104
   240
\end{ttbox}
paulson@3089
   241
The add operations ignore any rule already present in the claset with the same
paulson@3089
   242
classification (such as Safe Introduction).  They print a warning if the rule
paulson@3089
   243
has already been added with some other classification, but add the rule
paulson@3089
   244
anyway.  Calling {\tt delrules} deletes all occurrences of a rule from the
paulson@3089
   245
claset, but see the warning below concerning destruction rules.
lcp@308
   246
\begin{ttdescription}
lcp@104
   247
\item[\ttindexbold{empty_cs}] is the empty classical set.
lcp@104
   248
lcp@1099
   249
\item[\ttindexbold{print_cs} $cs$] prints the rules of~$cs$.
lcp@1099
   250
lcp@308
   251
\item[$cs$ addSIs $rules$] \indexbold{*addSIs}
lcp@308
   252
adds safe introduction~$rules$ to~$cs$.
lcp@104
   253
lcp@308
   254
\item[$cs$ addSEs $rules$] \indexbold{*addSEs}
lcp@308
   255
adds safe elimination~$rules$ to~$cs$.
lcp@104
   256
lcp@308
   257
\item[$cs$ addSDs $rules$] \indexbold{*addSDs}
lcp@308
   258
adds safe destruction~$rules$ to~$cs$.
lcp@104
   259
lcp@308
   260
\item[$cs$ addIs $rules$] \indexbold{*addIs}
lcp@308
   261
adds unsafe introduction~$rules$ to~$cs$.
lcp@104
   262
lcp@308
   263
\item[$cs$ addEs $rules$] \indexbold{*addEs}
lcp@308
   264
adds unsafe elimination~$rules$ to~$cs$.
lcp@104
   265
lcp@308
   266
\item[$cs$ addDs $rules$] \indexbold{*addDs}
lcp@308
   267
adds unsafe destruction~$rules$ to~$cs$.
berghofe@1869
   268
berghofe@1869
   269
\item[$cs$ delrules $rules$] \indexbold{*delrules}
paulson@3089
   270
deletes~$rules$ from~$cs$.  It prints a warning for those rules that are not
paulson@3089
   271
in~$cs$.
lcp@308
   272
\end{ttdescription}
lcp@308
   273
paulson@3089
   274
\begin{warn}
paulson@3089
   275
  If you added $rule$ using {\tt addSDs} or {\tt addDs}, then you must delete
paulson@3089
   276
  it as follows:
paulson@3089
   277
\begin{ttbox}
paulson@3089
   278
\(cs\) delrules [make_elim \(rule\)]
paulson@3089
   279
\end{ttbox}
paulson@3089
   280
\par\noindent
paulson@3089
   281
This is necessary because the operators {\tt addSDs} and {\tt addDs} convert
paulson@3089
   282
the destruction rules to elimination rules by applying \ttindex{make_elim},
paulson@3089
   283
and then insert them using {\tt addSEs} and {\tt addEs}, respectively.
paulson@3089
   284
\end{warn}
paulson@3089
   285
lcp@104
   286
Introduction rules are those that can be applied using ordinary resolution.
lcp@104
   287
The classical set automatically generates their swapped forms, which will
lcp@104
   288
be applied using elim-resolution.  Elimination rules are applied using
lcp@286
   289
elim-resolution.  In a classical set, rules are sorted by the number of new
lcp@286
   290
subgoals they will yield; rules that generate the fewest subgoals will be
lcp@286
   291
tried first (see \S\ref{biresolve_tac}).
lcp@104
   292
lcp@1099
   293
lcp@1099
   294
\subsection{Modifying the search step}
lcp@104
   295
For a given classical set, the proof strategy is simple.  Perform as many
lcp@104
   296
safe inferences as possible; or else, apply certain safe rules, allowing
lcp@104
   297
instantiation of unknowns; or else, apply an unsafe rule.  The tactics may
lcp@319
   298
also apply {\tt hyp_subst_tac}, if they have been set up to do so (see
lcp@104
   299
below).  They may perform a form of Modus Ponens: if there are assumptions
lcp@104
   300
$P\imp Q$ and~$P$, then replace $P\imp Q$ by~$Q$.
lcp@104
   301
wenzelm@3108
   302
The classical reasoning tactics --- except {\tt blast_tac}! --- allow
wenzelm@3108
   303
you to modify this basic proof strategy by applying two arbitrary {\bf
wenzelm@3108
   304
  wrapper tacticals} to it. This affects each step of the search.
wenzelm@3108
   305
Usually they are the identity tacticals, but they could apply another
wenzelm@3108
   306
tactic before or after the step tactic. The first one, which is
wenzelm@3108
   307
considered to be safe, affects \ttindex{safe_step_tac} and all the
wenzelm@3108
   308
tactics that call it. The the second one, which may be unsafe, affects
wenzelm@3108
   309
\ttindex{step_tac}, \ttindex{slow_step_tac} and the tactics that call
wenzelm@3108
   310
them.
lcp@1099
   311
lcp@1099
   312
\begin{ttbox} 
oheimb@2632
   313
addss        : claset * simpset -> claset                 \hfill{\bf infix 4}
oheimb@2632
   314
addSbefore   : claset *  (int -> tactic)  -> claset       \hfill{\bf infix 4}
oheimb@2632
   315
addSaltern   : claset *  (int -> tactic)  -> claset       \hfill{\bf infix 4}
oheimb@2632
   316
setSWrapper  : claset * ((int -> tactic) -> 
oheimb@2632
   317
                         (int -> tactic)) -> claset       \hfill{\bf infix 4}
oheimb@2632
   318
compSWrapper : claset * ((int -> tactic) -> 
oheimb@2632
   319
                         (int -> tactic)) -> claset       \hfill{\bf infix 4}
oheimb@2632
   320
addbefore    : claset *  (int -> tactic)  -> claset       \hfill{\bf infix 4}
oheimb@2632
   321
addaltern    : claset *  (int -> tactic)  -> claset       \hfill{\bf infix 4}
oheimb@2632
   322
setWrapper   : claset * ((int -> tactic) -> 
oheimb@2632
   323
                         (int -> tactic)) -> claset       \hfill{\bf infix 4}
oheimb@2632
   324
compWrapper  : claset * ((int -> tactic) -> 
oheimb@2632
   325
                         (int -> tactic)) -> claset       \hfill{\bf infix 4}
lcp@1099
   326
\end{ttbox}
lcp@1099
   327
%
wenzelm@3108
   328
\index{simplification!from classical reasoner} The wrapper tacticals
wenzelm@3108
   329
underly the operator addss, which combines each search step by
wenzelm@3108
   330
simplification.  Strictly speaking, {\tt addss} is not part of the
wenzelm@3108
   331
classical reasoner.  It should be defined (using {\tt addSaltern
wenzelm@3108
   332
  (CHANGED o (safe_asm_more_full_simp_tac ss)}) when the simplifier is
wenzelm@3108
   333
installed.
lcp@1099
   334
lcp@1099
   335
\begin{ttdescription}
lcp@1099
   336
\item[$cs$ addss $ss$] \indexbold{*addss}
oheimb@2631
   337
adds the simpset~$ss$ to the classical set. The assumptions and goal will be
oheimb@2631
   338
simplified, in a safe way, after the safe steps of the search.
oheimb@2631
   339
oheimb@2631
   340
\item[$cs$ addSbefore $tac$] \indexbold{*addSbefore}
oheimb@2631
   341
changes the safe wrapper tactical to apply the given tactic {\em before}
oheimb@2631
   342
each safe step of the search.
oheimb@2631
   343
oheimb@2631
   344
\item[$cs$ addSaltern $tac$] \indexbold{*addSaltern}
oheimb@2631
   345
changes the safe wrapper tactical to apply the given tactic when a safe step 
oheimb@2631
   346
of the search would fail.
oheimb@2631
   347
oheimb@2631
   348
\item[$cs$ setSWrapper $tactical$] \indexbold{*setSWrapper}
oheimb@2631
   349
specifies a new safe wrapper tactical.  
oheimb@2631
   350
oheimb@2631
   351
\item[$cs$ compSWrapper $tactical$] \indexbold{*compSWrapper}
oheimb@2631
   352
composes the $tactical$ with the existing safe wrapper tactical, 
oheimb@2631
   353
to combine their effects. 
lcp@1099
   354
lcp@1099
   355
\item[$cs$ addbefore $tac$] \indexbold{*addbefore}
oheimb@2631
   356
changes the (unsafe) wrapper tactical to apply the given tactic, which should
oheimb@2631
   357
be safe, {\em before} each step of the search.
lcp@1099
   358
oheimb@2631
   359
\item[$cs$ addaltern $tac$] \indexbold{*addaltern}
oheimb@2631
   360
changes the (unsafe) wrapper tactical to apply the given tactic 
oheimb@2631
   361
{\em alternatively} after each step of the search.
lcp@1099
   362
oheimb@2631
   363
\item[$cs$ setWrapper $tactical$] \indexbold{*setWrapper}
oheimb@2631
   364
specifies a new (unsafe) wrapper tactical.  
lcp@1099
   365
oheimb@2631
   366
\item[$cs$ compWrapper $tactical$] \indexbold{*compWrapper}
oheimb@2631
   367
composes the $tactical$ with the existing (unsafe) wrapper tactical, 
oheimb@2631
   368
to combine their effects. 
lcp@1099
   369
\end{ttdescription}
lcp@1099
   370
lcp@104
   371
lcp@104
   372
\section{The classical tactics}
lcp@319
   373
\index{classical reasoner!tactics}
lcp@104
   374
If installed, the classical module provides several tactics (and other
lcp@104
   375
operations) for simulating the classical sequent calculus.
lcp@104
   376
paulson@3089
   377
\subsection{The automatic tableau prover}
paulson@3089
   378
The tactic {\tt blast_tac} finds a proof rapidly using a separate tableau
paulson@3089
   379
prover and then reconstructs the proof using Isabelle tactics.  It is much
paulson@3089
   380
faster and more powerful than the other classical reasoning tactics, but has
paulson@3089
   381
major limitations too.  
paulson@3089
   382
\begin{itemize}
paulson@3089
   383
\item It does not use the wrapper tacticals described above, such as
paulson@3089
   384
  \ttindex{addss}.
paulson@3089
   385
\item It ignores types, which can cause problems in \HOL.  If it applies a rule
paulson@3089
   386
  whose types are inappropriate, then proof reconstruction will fail.
paulson@3089
   387
\item It does not perform higher-order unification, as needed by the rule {\tt
paulson@3089
   388
    rangeI} in {\HOL} and {\tt RepFunI} in {\ZF}.  There are often
paulson@3089
   389
    alternatives to such rules, for example {\tt
paulson@3089
   390
    range_eqI} and {\tt RepFun_eqI}.
paulson@3089
   391
\item The message {\small\tt Function Var's argument not a bound variable\ }
paulson@3089
   392
relates to the lack of higher-order unification.  Function variables
paulson@3089
   393
may only be applied to parameters of the subgoal.
paulson@3089
   394
\item Its proof strategy is more general than {\tt fast_tac}'s but can be
paulson@3089
   395
  slower.  If {\tt blast_tac} fails or seems to be running forever, try {\tt
paulson@3089
   396
  fast_tac} and the other tactics described below.
paulson@3089
   397
\end{itemize}
paulson@3089
   398
%
paulson@3089
   399
\begin{ttbox} 
paulson@3089
   400
blast_tac        : claset -> int -> tactic
paulson@3089
   401
Blast.depth_tac  : claset -> int -> int -> tactic
paulson@3089
   402
Blast.trace      : bool ref \hfill{\bf initially false}
paulson@3089
   403
\end{ttbox}
paulson@3089
   404
The two tactics differ on how they bound the number of unsafe steps used in a
paulson@3089
   405
proof.  While {\tt blast_tac} starts with a bound of zero and increases it
paulson@3089
   406
successively to~20, {\tt Blast.depth_tac} applies a user-supplied search bound.
paulson@3089
   407
\begin{ttdescription}
paulson@3089
   408
\item[\ttindexbold{blast_tac} $cs$ $i$] tries to prove
paulson@3089
   409
  subgoal~$i$ using iterative deepening to increase the search bound.
paulson@3089
   410
  
paulson@3089
   411
\item[\ttindexbold{Blast.depth_tac} $cs$ $lim$ $i$] tries
paulson@3089
   412
  to prove subgoal~$i$ using a search bound of $lim$.  Often a slow
paulson@3089
   413
  proof using {\tt blast_tac} can be made much faster by supplying the
paulson@3089
   414
  successful search bound to this tactic instead.
paulson@3089
   415
  
paulson@3089
   416
\item[\ttindexbold{Blast.trace} := true;] \index{tracing!of classical prover}
paulson@3089
   417
  causes the tableau prover to print a trace of its search.  At each step it
paulson@3089
   418
  displays the formula currently being examined and reports whether the branch
paulson@3089
   419
  has been closed, extended or split.
paulson@3089
   420
\end{ttdescription}
paulson@3089
   421
lcp@332
   422
\subsection{The automatic tactics}
lcp@332
   423
\begin{ttbox} 
lcp@875
   424
fast_tac      : claset -> int -> tactic
lcp@875
   425
best_tac      : claset -> int -> tactic
lcp@875
   426
slow_tac      : claset -> int -> tactic
lcp@875
   427
slow_best_tac : claset -> int -> tactic
lcp@332
   428
\end{ttbox}
lcp@875
   429
These tactics work by applying {\tt step_tac} or {\tt slow_step_tac}
lcp@875
   430
repeatedly.  Their effect is restricted (by {\tt SELECT_GOAL}) to one subgoal;
paulson@3089
   431
they either prove this subgoal or fail.  The {\tt slow_} versions are more
lcp@875
   432
powerful but can be much slower.  
lcp@875
   433
lcp@875
   434
The best-first tactics are guided by a heuristic function: typically, the
lcp@875
   435
total size of the proof state.  This function is supplied in the functor call
lcp@875
   436
that sets up the classical reasoner.
lcp@332
   437
\begin{ttdescription}
lcp@332
   438
\item[\ttindexbold{fast_tac} $cs$ $i$] applies {\tt step_tac} using
paulson@3089
   439
depth-first search, to prove subgoal~$i$.
lcp@332
   440
lcp@332
   441
\item[\ttindexbold{best_tac} $cs$ $i$] applies {\tt step_tac} using
paulson@3089
   442
best-first search, to prove subgoal~$i$.
lcp@875
   443
lcp@875
   444
\item[\ttindexbold{slow_tac} $cs$ $i$] applies {\tt slow_step_tac} using
paulson@3089
   445
depth-first search, to prove subgoal~$i$.
lcp@875
   446
lcp@875
   447
\item[\ttindexbold{slow_best_tac} $cs$ $i$] applies {\tt slow_step_tac} using
paulson@3089
   448
best-first search, to prove subgoal~$i$.
lcp@875
   449
\end{ttdescription}
lcp@875
   450
lcp@875
   451
lcp@875
   452
\subsection{Depth-limited tactics}
lcp@875
   453
\begin{ttbox} 
lcp@875
   454
depth_tac  : claset -> int -> int -> tactic
lcp@875
   455
deepen_tac : claset -> int -> int -> tactic
lcp@875
   456
\end{ttbox}
lcp@875
   457
These work by exhaustive search up to a specified depth.  Unsafe rules are
lcp@875
   458
modified to preserve the formula they act on, so that it be used repeatedly.
lcp@1099
   459
They can prove more goals than {\tt fast_tac} can but are much
lcp@875
   460
slower, for example if the assumptions have many universal quantifiers.
lcp@875
   461
lcp@875
   462
The depth limits the number of unsafe steps.  If you can estimate the minimum
lcp@875
   463
number of unsafe steps needed, supply this value as~$m$ to save time.
lcp@875
   464
\begin{ttdescription}
lcp@875
   465
\item[\ttindexbold{depth_tac} $cs$ $m$ $i$] 
paulson@3089
   466
tries to prove subgoal~$i$ by exhaustive search up to depth~$m$.
lcp@875
   467
lcp@875
   468
\item[\ttindexbold{deepen_tac} $cs$ $m$ $i$] 
paulson@3089
   469
tries to prove subgoal~$i$ by iterative deepening.  It calls {\tt depth_tac}
lcp@875
   470
repeatedly with increasing depths, starting with~$m$.
lcp@332
   471
\end{ttdescription}
lcp@332
   472
lcp@332
   473
lcp@104
   474
\subsection{Single-step tactics}
lcp@104
   475
\begin{ttbox} 
lcp@104
   476
safe_step_tac : claset -> int -> tactic
lcp@104
   477
safe_tac      : claset        -> tactic
lcp@104
   478
inst_step_tac : claset -> int -> tactic
lcp@104
   479
step_tac      : claset -> int -> tactic
lcp@104
   480
slow_step_tac : claset -> int -> tactic
lcp@104
   481
\end{ttbox}
lcp@104
   482
The automatic proof procedures call these tactics.  By calling them
lcp@104
   483
yourself, you can execute these procedures one step at a time.
lcp@308
   484
\begin{ttdescription}
lcp@104
   485
\item[\ttindexbold{safe_step_tac} $cs$ $i$] performs a safe step on
oheimb@2631
   486
subgoal~$i$. The safe wrapper tactical is applied to a tactic that may include 
oheimb@2631
   487
proof by assumption or Modus Ponens (taking care not to instantiate unknowns), 
oheimb@2631
   488
or {\tt hyp_subst_tac}.
lcp@104
   489
lcp@104
   490
\item[\ttindexbold{safe_tac} $cs$] repeatedly performs safe steps on all 
lcp@104
   491
subgoals.  It is deterministic, with at most one outcome.  If the automatic
lcp@104
   492
tactics fail, try using {\tt safe_tac} to open up your formula; then you
lcp@104
   493
can replicate certain quantifiers explicitly by applying appropriate rules.
lcp@104
   494
lcp@104
   495
\item[\ttindexbold{inst_step_tac} $cs$ $i$] is like {\tt safe_step_tac},
lcp@104
   496
but allows unknowns to be instantiated.
lcp@104
   497
lcp@1099
   498
\item[\ttindexbold{step_tac} $cs$ $i$] is the basic step of the proof
oheimb@2631
   499
  procedure.  The (unsafe) wrapper tactical is applied to a tactic that tries
oheimb@2631
   500
 {\tt safe_tac}, {\tt inst_step_tac}, or applies an unsafe rule from~$cs$.
lcp@104
   501
lcp@104
   502
\item[\ttindexbold{slow_step_tac}] 
lcp@104
   503
  resembles {\tt step_tac}, but allows backtracking between using safe
lcp@104
   504
  rules with instantiation ({\tt inst_step_tac}) and using unsafe rules.
lcp@875
   505
  The resulting search space is larger.
lcp@308
   506
\end{ttdescription}
lcp@104
   507
berghofe@1869
   508
\subsection{The current claset}
paulson@2479
   509
Some logics (\FOL, {\HOL} and \ZF) support the concept of a current
paulson@2479
   510
claset\index{claset!current}.  This is a default set of classical rules.  The
paulson@2479
   511
underlying idea is quite similar to that of a current simpset described in
paulson@2479
   512
\S\ref{sec:simp-for-dummies}; please read that section, including its
paulson@2479
   513
warnings.  Just like simpsets, clasets can be associated with theories.  The
paulson@2479
   514
tactics
berghofe@1869
   515
\begin{ttbox}
wenzelm@3108
   516
Blast_tac    : int -> tactic
berghofe@1869
   517
Fast_tac     : int -> tactic
berghofe@1869
   518
Best_tac     : int -> tactic
berghofe@1869
   519
Deepen_tac   : int -> int -> tactic
paulson@3089
   520
Step_tac     : int -> tactic
berghofe@1869
   521
\end{ttbox}
paulson@3089
   522
\indexbold{*Blast_tac}\indexbold{*Best_tac}\indexbold{*Fast_tac}%
paulson@3089
   523
\indexbold{*Deepen_tac}\indexbold{*Step_tac}
paulson@3089
   524
make use of the current claset. E.g. {\tt Blast_tac} is defined as follows:
berghofe@1869
   525
\begin{ttbox}
paulson@3089
   526
fun Blast_tac i = fast_tac (!claset) i;
berghofe@1869
   527
\end{ttbox}
berghofe@1869
   528
where \ttindex{!claset} is the current claset.
berghofe@1869
   529
The functions
berghofe@1869
   530
\begin{ttbox}
berghofe@1869
   531
AddSIs, AddSEs, AddSDs, AddIs, AddEs, AddDs: thm list -> unit
berghofe@1869
   532
\end{ttbox}
berghofe@1869
   533
\indexbold{*AddSIs} \indexbold{*AddSEs} \indexbold{*AddSDs}
berghofe@1869
   534
\indexbold{*AddIs} \indexbold{*AddEs} \indexbold{*AddDs}
berghofe@1869
   535
are used to add rules to the current claset. They work exactly like their
berghofe@1869
   536
lower case counterparts {\tt addSIs} etc.
berghofe@1869
   537
\begin{ttbox}
berghofe@1869
   538
Delrules : thm list -> unit
berghofe@1869
   539
\end{ttbox}
berghofe@1869
   540
deletes rules from the current claset. You do not need to worry via which of
berghofe@1869
   541
the above {\tt Add} functions the rule was initially added.
lcp@104
   542
lcp@104
   543
\subsection{Other useful tactics}
lcp@319
   544
\index{tactics!for contradiction}
lcp@319
   545
\index{tactics!for Modus Ponens}
lcp@104
   546
\begin{ttbox} 
lcp@104
   547
contr_tac    :             int -> tactic
lcp@104
   548
mp_tac       :             int -> tactic
lcp@104
   549
eq_mp_tac    :             int -> tactic
lcp@104
   550
swap_res_tac : thm list -> int -> tactic
lcp@104
   551
\end{ttbox}
lcp@104
   552
These can be used in the body of a specialized search.
lcp@308
   553
\begin{ttdescription}
lcp@319
   554
\item[\ttindexbold{contr_tac} {\it i}]\index{assumptions!contradictory}
lcp@319
   555
  solves subgoal~$i$ by detecting a contradiction among two assumptions of
lcp@319
   556
  the form $P$ and~$\neg P$, or fail.  It may instantiate unknowns.  The
lcp@319
   557
  tactic can produce multiple outcomes, enumerating all possible
lcp@319
   558
  contradictions.
lcp@104
   559
lcp@104
   560
\item[\ttindexbold{mp_tac} {\it i}] 
lcp@104
   561
is like {\tt contr_tac}, but also attempts to perform Modus Ponens in
lcp@104
   562
subgoal~$i$.  If there are assumptions $P\imp Q$ and~$P$, then it replaces
lcp@104
   563
$P\imp Q$ by~$Q$.  It may instantiate unknowns.  It fails if it can do
lcp@104
   564
nothing.
lcp@104
   565
lcp@104
   566
\item[\ttindexbold{eq_mp_tac} {\it i}] 
lcp@104
   567
is like {\tt mp_tac} {\it i}, but may not instantiate unknowns --- thus, it
lcp@104
   568
is safe.
lcp@104
   569
lcp@104
   570
\item[\ttindexbold{swap_res_tac} {\it thms} {\it i}] refines subgoal~$i$ of
lcp@104
   571
the proof state using {\it thms}, which should be a list of introduction
paulson@3089
   572
rules.  First, it attempts to prove the goal using {\tt assume_tac} or
lcp@104
   573
{\tt contr_tac}.  It then attempts to apply each rule in turn, attempting
lcp@104
   574
resolution and also elim-resolution with the swapped form.
lcp@308
   575
\end{ttdescription}
lcp@104
   576
lcp@104
   577
\subsection{Creating swapped rules}
lcp@104
   578
\begin{ttbox} 
lcp@104
   579
swapify   : thm list -> thm list
lcp@104
   580
joinrules : thm list * thm list -> (bool * thm) list
lcp@104
   581
\end{ttbox}
lcp@308
   582
\begin{ttdescription}
lcp@104
   583
\item[\ttindexbold{swapify} {\it thms}] returns a list consisting of the
lcp@104
   584
swapped versions of~{\it thms}, regarded as introduction rules.
lcp@104
   585
lcp@308
   586
\item[\ttindexbold{joinrules} ({\it intrs}, {\it elims})]
lcp@104
   587
joins introduction rules, their swapped versions, and elimination rules for
lcp@104
   588
use with \ttindex{biresolve_tac}.  Each rule is paired with~{\tt false}
lcp@104
   589
(indicating ordinary resolution) or~{\tt true} (indicating
lcp@104
   590
elim-resolution).
lcp@308
   591
\end{ttdescription}
lcp@104
   592
lcp@104
   593
lcp@286
   594
\section{Setting up the classical reasoner}
lcp@319
   595
\index{classical reasoner!setting up}
lcp@104
   596
Isabelle's classical object-logics, including {\tt FOL} and {\tt HOL}, have
lcp@286
   597
the classical reasoner already set up.  When defining a new classical logic,
lcp@286
   598
you should set up the reasoner yourself.  It consists of the \ML{} functor
lcp@104
   599
\ttindex{ClassicalFun}, which takes the argument
lcp@319
   600
signature {\tt CLASSICAL_DATA}:
lcp@104
   601
\begin{ttbox} 
lcp@104
   602
signature CLASSICAL_DATA =
lcp@104
   603
  sig
lcp@104
   604
  val mp             : thm
lcp@104
   605
  val not_elim       : thm
lcp@104
   606
  val swap           : thm
lcp@104
   607
  val sizef          : thm -> int
lcp@104
   608
  val hyp_subst_tacs : (int -> tactic) list
lcp@104
   609
  end;
lcp@104
   610
\end{ttbox}
lcp@104
   611
Thus, the functor requires the following items:
lcp@308
   612
\begin{ttdescription}
lcp@319
   613
\item[\tdxbold{mp}] should be the Modus Ponens rule
lcp@104
   614
$\List{\Var{P}\imp\Var{Q};\; \Var{P}} \Imp \Var{Q}$.
lcp@104
   615
lcp@319
   616
\item[\tdxbold{not_elim}] should be the contradiction rule
lcp@104
   617
$\List{\neg\Var{P};\; \Var{P}} \Imp \Var{R}$.
lcp@104
   618
lcp@319
   619
\item[\tdxbold{swap}] should be the swap rule
lcp@104
   620
$\List{\neg \Var{P}; \; \neg \Var{R}\Imp \Var{P}} \Imp \Var{R}$.
lcp@104
   621
lcp@104
   622
\item[\ttindexbold{sizef}] is the heuristic function used for best-first
lcp@104
   623
search.  It should estimate the size of the remaining subgoals.  A good
lcp@104
   624
heuristic function is \ttindex{size_of_thm}, which measures the size of the
lcp@104
   625
proof state.  Another size function might ignore certain subgoals (say,
lcp@104
   626
those concerned with type checking).  A heuristic function might simply
lcp@104
   627
count the subgoals.
lcp@104
   628
lcp@319
   629
\item[\ttindexbold{hyp_subst_tacs}] is a list of tactics for substitution in
lcp@104
   630
the hypotheses, typically created by \ttindex{HypsubstFun} (see
lcp@104
   631
Chapter~\ref{substitution}).  This list can, of course, be empty.  The
lcp@104
   632
tactics are assumed to be safe!
lcp@308
   633
\end{ttdescription}
lcp@104
   634
The functor is not at all sensitive to the formalization of the
wenzelm@3108
   635
object-logic.  It does not even examine the rules, but merely applies
wenzelm@3108
   636
them according to its fixed strategy.  The functor resides in {\tt
wenzelm@3108
   637
  Provers/classical.ML} in the Isabelle sources.
lcp@104
   638
lcp@319
   639
\index{classical reasoner|)}