doc-src/Ref/classical.tex
author wenzelm
Sun, 05 Jun 2011 22:02:54 +0200
changeset 44134 41394a61cca9
parent 44132 9d946de41120
child 44135 ac4094f30a44
permissions -rw-r--r--
updated and re-unified classical proof methods;
tuned;
wenzelm@30184
     1
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
lcp@104
     6
\section{Classical rule sets}
lcp@319
     7
\index{classical sets}
lcp@104
     8
oheimb@5550
     9
For elimination and destruction rules there are variants of the add operations
oheimb@5550
    10
adding a rule in a way such that it is applied only if also its second premise
oheimb@5550
    11
can be unified with an assumption of the current proof state:
oheimb@5576
    12
\indexbold{*addSE2}\indexbold{*addSD2}\indexbold{*addE2}\indexbold{*addD2}
oheimb@5550
    13
\begin{ttbox}
oheimb@5550
    14
addSE2      : claset * (string * thm) -> claset           \hfill{\bf infix 4}
oheimb@5550
    15
addSD2      : claset * (string * thm) -> claset           \hfill{\bf infix 4}
oheimb@5550
    16
addE2       : claset * (string * thm) -> claset           \hfill{\bf infix 4}
oheimb@5550
    17
addD2       : claset * (string * thm) -> claset           \hfill{\bf infix 4}
oheimb@5550
    18
\end{ttbox}
oheimb@5550
    19
\begin{warn}
oheimb@5550
    20
  A rule to be added in this special way must be given a name, which is used 
oheimb@5550
    21
  to delete it again -- when desired -- using \texttt{delSWrappers} or 
oheimb@5550
    22
  \texttt{delWrappers}, respectively. This is because these add operations
oheimb@5550
    23
  are implemented as wrappers (see \ref{sec:modifying-search} below).
oheimb@5550
    24
\end{warn}
oheimb@5550
    25
lcp@1099
    26
lcp@1099
    27
\subsection{Modifying the search step}
oheimb@4665
    28
\label{sec:modifying-search}
paulson@3716
    29
For a given classical set, the proof strategy is simple.  Perform as many safe
paulson@3716
    30
inferences as possible; or else, apply certain safe rules, allowing
paulson@3716
    31
instantiation of unknowns; or else, apply an unsafe rule.  The tactics also
paulson@3716
    32
eliminate assumptions of the form $x=t$ by substitution if they have been set
oheimb@11181
    33
up to do so (see \texttt{hyp_subst_tacs} in~{\S}\ref{sec:classical-setup} below).
paulson@3716
    34
They may perform a form of Modus Ponens: if there are assumptions $P\imp Q$
paulson@3716
    35
and~$P$, then replace $P\imp Q$ by~$Q$.
lcp@104
    36
paulson@3720
    37
The classical reasoning tactics --- except \texttt{blast_tac}! --- allow
oheimb@4649
    38
you to modify this basic proof strategy by applying two lists of arbitrary 
oheimb@4649
    39
{\bf wrapper tacticals} to it. 
oheimb@4649
    40
The first wrapper list, which is considered to contain safe wrappers only, 
oheimb@4649
    41
affects \ttindex{safe_step_tac} and all the tactics that call it.  
oheimb@5550
    42
The second one, which may contain unsafe wrappers, affects the unsafe parts
oheimb@5550
    43
of \ttindex{step_tac}, \ttindex{slow_step_tac}, and the tactics that call them.
oheimb@4649
    44
A wrapper transforms each step of the search, for example 
oheimb@5550
    45
by attempting other tactics before or after the original step tactic. 
oheimb@4649
    46
All members of a wrapper list are applied in turn to the respective step tactic.
oheimb@4649
    47
oheimb@4649
    48
Initially the two wrapper lists are empty, which means no modification of the
oheimb@4649
    49
step tactics. Safe and unsafe wrappers are added to a claset 
oheimb@4649
    50
with the functions given below, supplying them with wrapper names. 
oheimb@4649
    51
These names may be used to selectively delete wrappers.
lcp@1099
    52
lcp@1099
    53
\begin{ttbox} 
oheimb@4649
    54
type wrapper = (int -> tactic) -> (int -> tactic);
oheimb@4881
    55
oheimb@4881
    56
addSWrapper  : claset * (string *  wrapper       ) -> claset \hfill{\bf infix 4}
oheimb@4649
    57
addSbefore   : claset * (string * (int -> tactic)) -> claset \hfill{\bf infix 4}
oheimb@11181
    58
addSafter    : claset * (string * (int -> tactic)) -> claset \hfill{\bf infix 4}
oheimb@4649
    59
delSWrapper  : claset *  string                    -> claset \hfill{\bf infix 4}
oheimb@4881
    60
oheimb@4881
    61
addWrapper   : claset * (string *  wrapper       ) -> claset \hfill{\bf infix 4}
oheimb@4649
    62
addbefore    : claset * (string * (int -> tactic)) -> claset \hfill{\bf infix 4}
oheimb@11181
    63
addafter     : claset * (string * (int -> tactic)) -> claset \hfill{\bf infix 4}
oheimb@4649
    64
delWrapper   : claset *  string                    -> claset \hfill{\bf infix 4}
oheimb@4649
    65
oheimb@4881
    66
addSss       : claset * simpset -> claset                 \hfill{\bf infix 4}
oheimb@2632
    67
addss        : claset * simpset -> claset                 \hfill{\bf infix 4}
lcp@1099
    68
\end{ttbox}
lcp@1099
    69
%
lcp@1099
    70
lcp@1099
    71
\begin{ttdescription}
oheimb@4881
    72
\item[$cs$ addSWrapper $(name,wrapper)$] \indexbold{*addSWrapper}
oheimb@4881
    73
adds a new wrapper, which should yield a safe tactic, 
oheimb@4881
    74
to modify the existing safe step tactic.
oheimb@4881
    75
oheimb@4881
    76
\item[$cs$ addSbefore $(name,tac)$] \indexbold{*addSbefore}
oheimb@5550
    77
adds the given tactic as a safe wrapper, such that it is tried 
oheimb@5550
    78
{\em before} each safe step of the search.
oheimb@4881
    79
oheimb@11181
    80
\item[$cs$ addSafter $(name,tac)$] \indexbold{*addSafter}
oheimb@5550
    81
adds the given tactic as a safe wrapper, such that it is tried 
oheimb@5550
    82
when a safe step of the search would fail.
oheimb@4881
    83
oheimb@4881
    84
\item[$cs$ delSWrapper $name$] \indexbold{*delSWrapper}
oheimb@4881
    85
deletes the safe wrapper with the given name.
oheimb@4881
    86
oheimb@4881
    87
\item[$cs$ addWrapper $(name,wrapper)$] \indexbold{*addWrapper}
oheimb@4881
    88
adds a new wrapper to modify the existing (unsafe) step tactic.
oheimb@4881
    89
oheimb@4881
    90
\item[$cs$ addbefore $(name,tac)$] \indexbold{*addbefore}
oheimb@5550
    91
adds the given tactic as an unsafe wrapper, such that it its result is 
oheimb@5550
    92
concatenated {\em before} the result of each unsafe step.
oheimb@4881
    93
oheimb@11181
    94
\item[$cs$ addafter $(name,tac)$] \indexbold{*addafter}
oheimb@5550
    95
adds the given tactic as an unsafe wrapper, such that it its result is 
oheimb@5550
    96
concatenated {\em after} the result of each unsafe step.
oheimb@4881
    97
oheimb@4881
    98
\item[$cs$ delWrapper $name$] \indexbold{*delWrapper}
oheimb@4881
    99
deletes the unsafe wrapper with the given name.
oheimb@4881
   100
oheimb@4881
   101
\item[$cs$ addSss $ss$] \indexbold{*addss}
oheimb@4881
   102
adds the simpset~$ss$ to the classical set.  The assumptions and goal will be
oheimb@4881
   103
simplified, in a rather safe way, after each safe step of the search.
oheimb@4881
   104
lcp@1099
   105
\item[$cs$ addss $ss$] \indexbold{*addss}
paulson@3485
   106
adds the simpset~$ss$ to the classical set.  The assumptions and goal will be
oheimb@4881
   107
simplified, before the each unsafe step of the search.
oheimb@2631
   108
oheimb@4881
   109
\end{ttdescription}
oheimb@2631
   110
oheimb@5550
   111
\index{simplification!from classical reasoner} 
oheimb@5550
   112
Strictly speaking, the operators \texttt{addss} and \texttt{addSss}
oheimb@5550
   113
are not part of the classical reasoner.
oheimb@5550
   114
, which are used as primitives 
oheimb@11181
   115
for the automatic tactics described in {\S}\ref{sec:automatic-tactics}, are
oheimb@5550
   116
implemented as wrapper tacticals.
oheimb@5550
   117
they  
oheimb@4881
   118
\begin{warn}
oheimb@4881
   119
Being defined as wrappers, these operators are inappropriate for adding more 
oheimb@4881
   120
than one simpset at a time: the simpset added last overwrites any earlier ones.
oheimb@4881
   121
When a simpset combined with a claset is to be augmented, this should done 
oheimb@4881
   122
{\em before} combining it with the claset.
oheimb@4881
   123
\end{warn}
lcp@1099
   124
lcp@104
   125
lcp@104
   126
\section{The classical tactics}
oheimb@5576
   127
oheimb@5576
   128
\subsection{Semi-automatic tactics}
oheimb@5576
   129
\begin{ttbox} 
oheimb@5576
   130
clarify_step_tac : claset -> int -> tactic
oheimb@5576
   131
\end{ttbox}
wenzelm@44134
   132
oheimb@5576
   133
\begin{ttdescription}
oheimb@5576
   134
\item[\ttindexbold{clarify_step_tac} $cs$ $i$] performs a safe step on
oheimb@5576
   135
  subgoal~$i$.  No splitting step is applied; for example, the subgoal $A\conj
oheimb@5576
   136
  B$ is left as a conjunction.  Proof by assumption, Modus Ponens, etc., may be
oheimb@5576
   137
  performed provided they do not instantiate unknowns.  Assumptions of the
oheimb@5576
   138
  form $x=t$ may be eliminated.  The user-supplied safe wrapper tactical is
oheimb@5576
   139
  applied.
oheimb@5576
   140
\end{ttdescription}
oheimb@5576
   141
oheimb@5576
   142
paulson@3224
   143
\subsection{Other classical tactics}
lcp@332
   144
\begin{ttbox} 
lcp@875
   145
slow_best_tac : claset -> int -> tactic
lcp@332
   146
\end{ttbox}
lcp@875
   147
lcp@332
   148
\begin{ttdescription}
paulson@8136
   149
\item[\ttindexbold{slow_best_tac} $cs$ $i$] applies \texttt{slow_step_tac} with
paulson@8136
   150
best-first search to prove subgoal~$i$.
lcp@875
   151
\end{ttdescription}
lcp@875
   152
lcp@875
   153
paulson@3716
   154
\subsection{Depth-limited automatic tactics}
lcp@875
   155
\begin{ttbox} 
lcp@875
   156
depth_tac  : claset -> int -> int -> tactic
lcp@875
   157
deepen_tac : claset -> int -> int -> tactic
lcp@875
   158
\end{ttbox}
lcp@875
   159
These work by exhaustive search up to a specified depth.  Unsafe rules are
lcp@875
   160
modified to preserve the formula they act on, so that it be used repeatedly.
paulson@3720
   161
They can prove more goals than \texttt{fast_tac} can but are much
lcp@875
   162
slower, for example if the assumptions have many universal quantifiers.
lcp@875
   163
lcp@875
   164
The depth limits the number of unsafe steps.  If you can estimate the minimum
lcp@875
   165
number of unsafe steps needed, supply this value as~$m$ to save time.
lcp@875
   166
\begin{ttdescription}
lcp@875
   167
\item[\ttindexbold{depth_tac} $cs$ $m$ $i$] 
paulson@3089
   168
tries to prove subgoal~$i$ by exhaustive search up to depth~$m$.
lcp@875
   169
lcp@875
   170
\item[\ttindexbold{deepen_tac} $cs$ $m$ $i$] 
paulson@3720
   171
tries to prove subgoal~$i$ by iterative deepening.  It calls \texttt{depth_tac}
lcp@875
   172
repeatedly with increasing depths, starting with~$m$.
lcp@332
   173
\end{ttdescription}
lcp@332
   174
lcp@332
   175
lcp@104
   176
\subsection{Single-step tactics}
lcp@104
   177
\begin{ttbox} 
lcp@104
   178
safe_step_tac : claset -> int -> tactic
lcp@104
   179
inst_step_tac : claset -> int -> tactic
lcp@104
   180
step_tac      : claset -> int -> tactic
lcp@104
   181
slow_step_tac : claset -> int -> tactic
lcp@104
   182
\end{ttbox}
lcp@104
   183
The automatic proof procedures call these tactics.  By calling them
lcp@104
   184
yourself, you can execute these procedures one step at a time.
lcp@308
   185
\begin{ttdescription}
lcp@104
   186
\item[\ttindexbold{safe_step_tac} $cs$ $i$] performs a safe step on
oheimb@4881
   187
  subgoal~$i$.  The safe wrapper tacticals are applied to a tactic that may
paulson@3716
   188
  include proof by assumption or Modus Ponens (taking care not to instantiate
paulson@3716
   189
  unknowns), or substitution.
lcp@104
   190
paulson@3720
   191
\item[\ttindexbold{inst_step_tac} $cs$ $i$] is like \texttt{safe_step_tac},
lcp@104
   192
but allows unknowns to be instantiated.
lcp@104
   193
lcp@1099
   194
\item[\ttindexbold{step_tac} $cs$ $i$] is the basic step of the proof
paulson@8136
   195
  procedure.  The unsafe wrapper tacticals are applied to a tactic that tries
paulson@8136
   196
  \texttt{safe_tac}, \texttt{inst_step_tac}, or applies an unsafe rule
paulson@8136
   197
  from~$cs$.
lcp@104
   198
lcp@104
   199
\item[\ttindexbold{slow_step_tac}] 
paulson@3720
   200
  resembles \texttt{step_tac}, but allows backtracking between using safe
paulson@3720
   201
  rules with instantiation (\texttt{inst_step_tac}) and using unsafe rules.
lcp@875
   202
  The resulting search space is larger.
lcp@308
   203
\end{ttdescription}
lcp@104
   204
oheimb@5576
   205
lcp@104
   206
\subsection{Other useful tactics}
lcp@319
   207
\index{tactics!for contradiction}
lcp@319
   208
\index{tactics!for Modus Ponens}
lcp@104
   209
\begin{ttbox} 
lcp@104
   210
contr_tac    :             int -> tactic
lcp@104
   211
mp_tac       :             int -> tactic
lcp@104
   212
eq_mp_tac    :             int -> tactic
lcp@104
   213
swap_res_tac : thm list -> int -> tactic
lcp@104
   214
\end{ttbox}
lcp@104
   215
These can be used in the body of a specialized search.
lcp@308
   216
\begin{ttdescription}
lcp@319
   217
\item[\ttindexbold{contr_tac} {\it i}]\index{assumptions!contradictory}
lcp@319
   218
  solves subgoal~$i$ by detecting a contradiction among two assumptions of
lcp@319
   219
  the form $P$ and~$\neg P$, or fail.  It may instantiate unknowns.  The
lcp@319
   220
  tactic can produce multiple outcomes, enumerating all possible
lcp@319
   221
  contradictions.
lcp@104
   222
lcp@104
   223
\item[\ttindexbold{mp_tac} {\it i}] 
paulson@3720
   224
is like \texttt{contr_tac}, but also attempts to perform Modus Ponens in
lcp@104
   225
subgoal~$i$.  If there are assumptions $P\imp Q$ and~$P$, then it replaces
lcp@104
   226
$P\imp Q$ by~$Q$.  It may instantiate unknowns.  It fails if it can do
lcp@104
   227
nothing.
lcp@104
   228
lcp@104
   229
\item[\ttindexbold{eq_mp_tac} {\it i}] 
paulson@3720
   230
is like \texttt{mp_tac} {\it i}, but may not instantiate unknowns --- thus, it
lcp@104
   231
is safe.
lcp@104
   232
lcp@104
   233
\item[\ttindexbold{swap_res_tac} {\it thms} {\it i}] refines subgoal~$i$ of
lcp@104
   234
the proof state using {\it thms}, which should be a list of introduction
paulson@3720
   235
rules.  First, it attempts to prove the goal using \texttt{assume_tac} or
paulson@3720
   236
\texttt{contr_tac}.  It then attempts to apply each rule in turn, attempting
lcp@104
   237
resolution and also elim-resolution with the swapped form.
lcp@308
   238
\end{ttdescription}
lcp@104
   239
lcp@104
   240
\subsection{Creating swapped rules}
lcp@104
   241
\begin{ttbox} 
lcp@104
   242
swapify   : thm list -> thm list
lcp@104
   243
joinrules : thm list * thm list -> (bool * thm) list
lcp@104
   244
\end{ttbox}
lcp@308
   245
\begin{ttdescription}
lcp@104
   246
\item[\ttindexbold{swapify} {\it thms}] returns a list consisting of the
lcp@104
   247
swapped versions of~{\it thms}, regarded as introduction rules.
lcp@104
   248
lcp@308
   249
\item[\ttindexbold{joinrules} ({\it intrs}, {\it elims})]
lcp@104
   250
joins introduction rules, their swapped versions, and elimination rules for
paulson@3720
   251
use with \ttindex{biresolve_tac}.  Each rule is paired with~\texttt{false}
paulson@3720
   252
(indicating ordinary resolution) or~\texttt{true} (indicating
lcp@104
   253
elim-resolution).
lcp@308
   254
\end{ttdescription}
lcp@104
   255
lcp@104
   256
paulson@3716
   257
\section{Setting up the classical reasoner}\label{sec:classical-setup}
lcp@319
   258
\index{classical reasoner!setting up}
oheimb@5550
   259
Isabelle's classical object-logics, including \texttt{FOL} and \texttt{HOL}, 
oheimb@5550
   260
have the classical reasoner already set up.  
oheimb@5550
   261
When defining a new classical logic, you should set up the reasoner yourself.  
oheimb@5550
   262
It consists of the \ML{} functor \ttindex{ClassicalFun}, which takes the 
oheimb@5550
   263
argument signature \texttt{CLASSICAL_DATA}:
lcp@104
   264
\begin{ttbox} 
lcp@104
   265
signature CLASSICAL_DATA =
lcp@104
   266
  sig
lcp@104
   267
  val mp             : thm
lcp@104
   268
  val not_elim       : thm
lcp@104
   269
  val swap           : thm
lcp@104
   270
  val sizef          : thm -> int
lcp@104
   271
  val hyp_subst_tacs : (int -> tactic) list
lcp@104
   272
  end;
lcp@104
   273
\end{ttbox}
lcp@104
   274
Thus, the functor requires the following items:
lcp@308
   275
\begin{ttdescription}
lcp@319
   276
\item[\tdxbold{mp}] should be the Modus Ponens rule
lcp@104
   277
$\List{\Var{P}\imp\Var{Q};\; \Var{P}} \Imp \Var{Q}$.
lcp@104
   278
lcp@319
   279
\item[\tdxbold{not_elim}] should be the contradiction rule
lcp@104
   280
$\List{\neg\Var{P};\; \Var{P}} \Imp \Var{R}$.
lcp@104
   281
lcp@319
   282
\item[\tdxbold{swap}] should be the swap rule
lcp@104
   283
$\List{\neg \Var{P}; \; \neg \Var{R}\Imp \Var{P}} \Imp \Var{R}$.
lcp@104
   284
lcp@104
   285
\item[\ttindexbold{sizef}] is the heuristic function used for best-first
lcp@104
   286
search.  It should estimate the size of the remaining subgoals.  A good
lcp@104
   287
heuristic function is \ttindex{size_of_thm}, which measures the size of the
lcp@104
   288
proof state.  Another size function might ignore certain subgoals (say,
paulson@6170
   289
those concerned with type-checking).  A heuristic function might simply
lcp@104
   290
count the subgoals.
lcp@104
   291
lcp@319
   292
\item[\ttindexbold{hyp_subst_tacs}] is a list of tactics for substitution in
lcp@104
   293
the hypotheses, typically created by \ttindex{HypsubstFun} (see
lcp@104
   294
Chapter~\ref{substitution}).  This list can, of course, be empty.  The
lcp@104
   295
tactics are assumed to be safe!
lcp@308
   296
\end{ttdescription}
lcp@104
   297
The functor is not at all sensitive to the formalization of the
wenzelm@3108
   298
object-logic.  It does not even examine the rules, but merely applies
wenzelm@3108
   299
them according to its fixed strategy.  The functor resides in {\tt
wenzelm@3108
   300
  Provers/classical.ML} in the Isabelle sources.
lcp@104
   301
lcp@319
   302
\index{classical reasoner|)}
wenzelm@5371
   303
wenzelm@5371
   304
%%% Local Variables: 
wenzelm@5371
   305
%%% mode: latex
wenzelm@5371
   306
%%% TeX-master: "ref"
wenzelm@5371
   307
%%% End: