doc-src/Logics/LK.tex
author paulson
Thu, 16 Jul 1998 11:50:01 +0200
changeset 5151 1e944fe5ce96
parent 3148 f081757ce757
child 6072 5583261db33d
permissions -rw-r--r--
Got rid of obsolete "goal" commands.
Also inserted spaces after all periods
lcp@104
     1
%% $Id$
lcp@291
     2
\chapter{First-Order Sequent Calculus}
lcp@316
     3
\index{sequent calculus|(}
lcp@316
     4
lcp@316
     5
The theory~\thydx{LK} implements classical first-order logic through
lcp@104
     6
Gentzen's sequent calculus (see Gallier~\cite{gallier86} or
lcp@104
     7
Takeuti~\cite{takeuti87}).  Resembling the method of semantic tableaux, the
lcp@104
     8
calculus is well suited for backwards proof.  Assertions have the form
lcp@104
     9
\(\Gamma\turn \Delta\), where \(\Gamma\) and \(\Delta\) are lists of
lcp@104
    10
formulae.  Associative unification, simulated by higher-order unification,
lcp@104
    11
handles lists.
lcp@104
    12
lcp@316
    13
The logic is many-sorted, using Isabelle's type classes.  The class of
lcp@316
    14
first-order terms is called \cldx{term}.  No types of individuals are
lcp@316
    15
provided, but extensions can define types such as {\tt nat::term} and type
lcp@316
    16
constructors such as {\tt list::(term)term}.  Below, the type variable
lcp@316
    17
$\alpha$ ranges over class {\tt term}; the equality symbol and quantifiers
lcp@316
    18
are polymorphic (many-sorted).  The type of formulae is~\tydx{o}, which
lcp@316
    19
belongs to class {\tt logic}.
lcp@104
    20
lcp@104
    21
No generic packages are instantiated, since Isabelle does not provide
lcp@104
    22
packages for sequent calculi at present.  \LK{} implements a classical
lcp@316
    23
logic theorem prover that is as powerful as the generic classical reasoner,
lcp@104
    24
except that it does not perform equality reasoning.
lcp@104
    25
paulson@5151
    26
To work in LK, start up Isabelle specifying  \texttt{Sequents} as the
paulson@5151
    27
object-logic.  Once in Isabelle, change the context to theory \texttt{LK.thy}:
paulson@5151
    28
\begin{ttbox}
paulson@5151
    29
isabelle Sequents
paulson@5151
    30
context LK.thy;
paulson@5151
    31
\end{ttbox}
paulson@5151
    32
Model logic and linear logic are also available, but unfortunately they are
paulson@5151
    33
not documented.
paulson@5151
    34
lcp@104
    35
lcp@104
    36
\begin{figure} 
lcp@104
    37
\begin{center}
lcp@104
    38
\begin{tabular}{rrr} 
lcp@111
    39
  \it name      &\it meta-type          & \it description       \\ 
lcp@316
    40
  \cdx{Trueprop}& $[sobj\To sobj, sobj\To sobj]\To prop$ & coercion to $prop$\\
lcp@316
    41
  \cdx{Seqof}   & $[o,sobj]\To sobj$    & singleton sequence    \\
lcp@316
    42
  \cdx{Not}     & $o\To o$              & negation ($\neg$)     \\
lcp@316
    43
  \cdx{True}    & $o$                   & tautology ($\top$)    \\
lcp@316
    44
  \cdx{False}   & $o$                   & absurdity ($\bot$)
lcp@104
    45
\end{tabular}
lcp@104
    46
\end{center}
lcp@104
    47
\subcaption{Constants}
lcp@104
    48
lcp@104
    49
\begin{center}
lcp@104
    50
\begin{tabular}{llrrr} 
lcp@316
    51
  \it symbol &\it name     &\it meta-type & \it priority & \it description \\
lcp@316
    52
  \sdx{ALL}  & \cdx{All}  & $(\alpha\To o)\To o$ & 10 & 
lcp@111
    53
        universal quantifier ($\forall$) \\
lcp@316
    54
  \sdx{EX}   & \cdx{Ex}   & $(\alpha\To o)\To o$ & 10 & 
lcp@111
    55
        existential quantifier ($\exists$) \\
lcp@316
    56
  \sdx{THE} & \cdx{The}  & $(\alpha\To o)\To \alpha$ & 10 & 
lcp@111
    57
        definite description ($\iota$)
lcp@104
    58
\end{tabular}
lcp@104
    59
\end{center}
lcp@104
    60
\subcaption{Binders} 
lcp@104
    61
lcp@104
    62
\begin{center}
lcp@316
    63
\index{*"= symbol}
lcp@316
    64
\index{&@{\tt\&} symbol}
lcp@316
    65
\index{*"| symbol}
lcp@316
    66
\index{*"-"-"> symbol}
lcp@316
    67
\index{*"<"-"> symbol}
lcp@104
    68
\begin{tabular}{rrrr} 
lcp@316
    69
    \it symbol  & \it meta-type         & \it priority & \it description \\ 
lcp@316
    70
    \tt = &     $[\alpha,\alpha]\To o$  & Left 50 & equality ($=$) \\
lcp@104
    71
    \tt \& &    $[o,o]\To o$ & Right 35 & conjunction ($\conj$) \\
lcp@104
    72
    \tt | &     $[o,o]\To o$ & Right 30 & disjunction ($\disj$) \\
lcp@104
    73
    \tt --> &   $[o,o]\To o$ & Right 25 & implication ($\imp$) \\
lcp@104
    74
    \tt <-> &   $[o,o]\To o$ & Right 25 & biconditional ($\bimp$) 
lcp@104
    75
\end{tabular}
lcp@104
    76
\end{center}
lcp@104
    77
\subcaption{Infixes}
lcp@104
    78
lcp@104
    79
\begin{center}
lcp@104
    80
\begin{tabular}{rrr} 
lcp@111
    81
  \it external          & \it internal  & \it description \\ 
lcp@104
    82
  \tt $\Gamma$ |- $\Delta$  &  \tt Trueprop($\Gamma$, $\Delta$) &
lcp@104
    83
        sequent $\Gamma\turn \Delta$ 
lcp@104
    84
\end{tabular}
lcp@104
    85
\end{center}
lcp@104
    86
\subcaption{Translations} 
lcp@104
    87
\caption{Syntax of {\tt LK}} \label{lk-syntax}
lcp@104
    88
\end{figure}
lcp@104
    89
lcp@104
    90
lcp@104
    91
\begin{figure} 
lcp@104
    92
\dquotes
lcp@104
    93
\[\begin{array}{rcl}
lcp@104
    94
    prop & = & sequence " |- " sequence 
lcp@104
    95
\\[2ex]
lcp@104
    96
sequence & = & elem \quad (", " elem)^* \\
lcp@104
    97
         & | & empty 
lcp@104
    98
\\[2ex]
lcp@104
    99
    elem & = & "\$ " id \\
lcp@104
   100
         & | & "\$ " var \\
lcp@104
   101
         & | & formula 
lcp@104
   102
\\[2ex]
lcp@104
   103
 formula & = & \hbox{expression of type~$o$} \\
lcp@111
   104
         & | & term " = " term \\
lcp@111
   105
         & | & "\ttilde\ " formula \\
lcp@111
   106
         & | & formula " \& " formula \\
lcp@111
   107
         & | & formula " | " formula \\
lcp@111
   108
         & | & formula " --> " formula \\
lcp@111
   109
         & | & formula " <-> " formula \\
lcp@111
   110
         & | & "ALL~" id~id^* " . " formula \\
lcp@111
   111
         & | & "EX~~" id~id^* " . " formula \\
lcp@111
   112
         & | & "THE~" id~     " . " formula
lcp@104
   113
  \end{array}
lcp@104
   114
\]
lcp@104
   115
\caption{Grammar of {\tt LK}} \label{lk-grammar}
lcp@104
   116
\end{figure}
lcp@104
   117
lcp@104
   118
lcp@316
   119
\section{Unification for lists}
lcp@316
   120
Higher-order unification includes associative unification as a special
lcp@316
   121
case, by an encoding that involves function composition
lcp@316
   122
\cite[page~37]{huet78}.  To represent lists, let $C$ be a new constant.
paulson@5151
   123
The empty list is $\lambda x. x$, while $[t@1,t@2,\ldots,t@n]$ is
lcp@316
   124
represented by
paulson@5151
   125
\[ \lambda x. C(t@1,C(t@2,\ldots,C(t@n,x))).  \]
lcp@316
   126
The unifiers of this with $\lambda x.\Var{f}(\Var{g}(x))$ give all the ways
lcp@316
   127
of expressing $[t@1,t@2,\ldots,t@n]$ as the concatenation of two lists.
lcp@316
   128
lcp@316
   129
Unlike orthodox associative unification, this technique can represent certain
lcp@316
   130
infinite sets of unifiers by flex-flex equations.   But note that the term
paulson@5151
   131
$\lambda x. C(t,\Var{a})$ does not represent any list.  Flex-flex constraints
lcp@316
   132
containing such garbage terms may accumulate during a proof.
lcp@316
   133
\index{flex-flex constraints}
lcp@316
   134
lcp@316
   135
This technique lets Isabelle formalize sequent calculus rules,
lcp@316
   136
where the comma is the associative operator:
lcp@316
   137
\[ \infer[(\conj\hbox{-left})]
lcp@316
   138
         {\Gamma,P\conj Q,\Delta \turn \Theta}
lcp@316
   139
         {\Gamma,P,Q,\Delta \turn \Theta}  \] 
lcp@316
   140
Multiple unifiers occur whenever this is resolved against a goal containing
lcp@316
   141
more than one conjunction on the left.  
lcp@316
   142
lcp@316
   143
\LK{} exploits this representation of lists.  As an alternative, the
lcp@316
   144
sequent calculus can be formalized using an ordinary representation of
lcp@316
   145
lists, with a logic program for removing a formula from a list.  Amy Felty
lcp@316
   146
has applied this technique using the language $\lambda$Prolog~\cite{felty91a}.
lcp@316
   147
lcp@316
   148
Explicit formalization of sequents can be tiresome.  But it gives precise
lcp@316
   149
control over contraction and weakening, and is essential to handle relevant
lcp@316
   150
and linear logics.
lcp@316
   151
lcp@316
   152
lcp@104
   153
\begin{figure} 
lcp@104
   154
\begin{ttbox}
lcp@316
   155
\tdx{basic}       $H, P, $G |- $E, P, $F
lcp@316
   156
\tdx{thinR}       $H |- $E, $F ==> $H |- $E, P, $F
lcp@316
   157
\tdx{thinL}       $H, $G |- $E ==> $H, P, $G |- $E
lcp@316
   158
\tdx{cut}         [| $H |- $E, P;  $H, P |- $E |] ==> $H |- $E
lcp@104
   159
\subcaption{Structural rules}
lcp@104
   160
lcp@316
   161
\tdx{refl}        $H |- $E, a=a, $F
lcp@316
   162
\tdx{sym}         $H |- $E, a=b, $F ==> $H |- $E, b=a, $F
lcp@316
   163
\tdx{trans}       [| $H|- $E, a=b, $F;  $H|- $E, b=c, $F |] ==> 
lcp@104
   164
            $H|- $E, a=c, $F
lcp@104
   165
\subcaption{Equality rules}
lcp@104
   166
lcp@316
   167
\tdx{True_def}    True  == False-->False
lcp@316
   168
\tdx{iff_def}     P<->Q == (P-->Q) & (Q-->P)
lcp@104
   169
lcp@316
   170
\tdx{conjR}   [| $H|- $E, P, $F;  $H|- $E, Q, $F |] ==> $H|- $E, P&Q, $F
lcp@316
   171
\tdx{conjL}   $H, P, Q, $G |- $E ==> $H, P & Q, $G |- $E
lcp@104
   172
lcp@316
   173
\tdx{disjR}   $H |- $E, P, Q, $F ==> $H |- $E, P|Q, $F
lcp@316
   174
\tdx{disjL}   [| $H, P, $G |- $E;  $H, Q, $G |- $E |] ==> $H, P|Q, $G |- $E
lcp@104
   175
            
wenzelm@841
   176
\tdx{impR}    $H, P |- $E, Q, $F ==> $H |- $E, P-->Q, $F
lcp@316
   177
\tdx{impL}    [| $H,$G |- $E,P;  $H, Q, $G |- $E |] ==> $H, P-->Q, $G |- $E
lcp@104
   178
            
lcp@316
   179
\tdx{notR}    $H, P |- $E, $F ==> $H |- $E, ~P, $F
lcp@316
   180
\tdx{notL}    $H, $G |- $E, P ==> $H, ~P, $G |- $E
lcp@104
   181
lcp@316
   182
\tdx{FalseL}  $H, False, $G |- $E
lcp@316
   183
paulson@5151
   184
\tdx{allR}    (!!x. $H|- $E, P(x), $F) ==> $H|- $E, ALL x. P(x), $F
paulson@5151
   185
\tdx{allL}    $H, P(x), $G, ALL x. P(x) |- $E ==> $H, ALL x. P(x), $G|- $E
lcp@316
   186
            
paulson@5151
   187
\tdx{exR}     $H|- $E, P(x), $F, EX x. P(x) ==> $H|- $E, EX x. P(x), $F
paulson@5151
   188
\tdx{exL}     (!!x. $H, P(x), $G|- $E) ==> $H, EX x. P(x), $G|- $E
lcp@316
   189
paulson@5151
   190
\tdx{The}     [| $H |- $E, P(a), $F;  !!x. $H, P(x) |- $E, x=a, $F |] ==>
paulson@5151
   191
        $H |- $E, P(THE x. P(x)), $F
lcp@316
   192
\subcaption{Logical rules}
lcp@111
   193
\end{ttbox}
lcp@316
   194
lcp@111
   195
\caption{Rules of {\tt LK}}  \label{lk-rules}
lcp@111
   196
\end{figure}
lcp@104
   197
lcp@104
   198
lcp@104
   199
\section{Syntax and rules of inference}
lcp@316
   200
\index{*sobj type}
lcp@316
   201
lcp@104
   202
Figure~\ref{lk-syntax} gives the syntax for {\tt LK}, which is complicated
lcp@104
   203
by the representation of sequents.  Type $sobj\To sobj$ represents a list
lcp@104
   204
of formulae.
lcp@104
   205
paulson@5151
   206
The {\bf definite description} operator~$\iota x. P[x]$ stands for some~$a$
lcp@316
   207
satisfying~$P[a]$, if one exists and is unique.  Since all terms in \LK{}
lcp@104
   208
denote something, a description is always meaningful, but we do not know
lcp@104
   209
its value unless $P[x]$ defines it uniquely.  The Isabelle notation is
paulson@5151
   210
\hbox{\tt THE $x$. $P[x]$}.  The corresponding rule (Fig.\ts\ref{lk-rules})
lcp@316
   211
does not entail the Axiom of Choice because it requires uniqueness.
lcp@104
   212
lcp@316
   213
Figure~\ref{lk-grammar} presents the grammar of \LK.  Traditionally,
lcp@316
   214
\(\Gamma\) and \(\Delta\) are meta-variables for sequences.  In Isabelle's
lcp@316
   215
notation, the prefix~\verb|$| on a variable makes it range over sequences.
lcp@316
   216
In a sequent, anything not prefixed by \verb|$| is taken as a formula.
lcp@104
   217
lcp@316
   218
Figure~\ref{lk-rules} presents the rules of theory \thydx{LK}.  The
lcp@111
   219
connective $\bimp$ is defined using $\conj$ and $\imp$.  The axiom for
lcp@111
   220
basic sequents is expressed in a form that provides automatic thinning:
lcp@111
   221
redundant formulae are simply ignored.  The other rules are expressed in
lcp@111
   222
the form most suitable for backward proof --- they do not require exchange
lcp@111
   223
or contraction rules.  The contraction rules are actually derivable (via
lcp@111
   224
cut) in this formulation.
lcp@104
   225
lcp@104
   226
Figure~\ref{lk-derived} presents derived rules, including rules for
lcp@104
   227
$\bimp$.  The weakened quantifier rules discard each quantification after a
lcp@104
   228
single use; in an automatic proof procedure, they guarantee termination,
lcp@104
   229
but are incomplete.  Multiple use of a quantifier can be obtained by a
lcp@104
   230
contraction rule, which in backward proof duplicates a formula.  The tactic
lcp@316
   231
{\tt res_inst_tac} can instantiate the variable~{\tt?P} in these rules,
lcp@104
   232
specifying the formula to duplicate.
lcp@104
   233
wenzelm@3148
   234
See theory {\tt Sequents/LK} in the sources for complete listings of
wenzelm@3148
   235
the rules and derived rules.
lcp@104
   236
lcp@104
   237
lcp@316
   238
\begin{figure} 
lcp@316
   239
\begin{ttbox}
lcp@316
   240
\tdx{conR}        $H |- $E, P, $F, P ==> $H |- $E, P, $F
lcp@316
   241
\tdx{conL}        $H, P, $G, P |- $E ==> $H, P, $G |- $E
lcp@316
   242
lcp@316
   243
\tdx{symL}        $H, $G, B = A |- $E ==> $H, A = B, $G |- $E
lcp@316
   244
lcp@316
   245
\tdx{TrueR}       $H |- $E, True, $F
lcp@316
   246
lcp@316
   247
\tdx{iffR}        [| $H, P |- $E, Q, $F;  $H, Q |- $E, P, $F |] ==> 
lcp@316
   248
            $H |- $E, P<->Q, $F
lcp@316
   249
lcp@316
   250
\tdx{iffL}        [| $H, $G |- $E, P, Q;  $H, Q, P, $G |- $E |] ==>
lcp@316
   251
            $H, P<->Q, $G |- $E
lcp@316
   252
paulson@5151
   253
\tdx{allL_thin}   $H, P(x), $G |- $E ==> $H, ALL x. P(x), $G |- $E
paulson@5151
   254
\tdx{exR_thin}    $H |- $E, P(x), $F ==> $H |- $E, EX x. P(x), $F
lcp@316
   255
\end{ttbox}
lcp@316
   256
lcp@316
   257
\caption{Derived rules for {\tt LK}} \label{lk-derived}
lcp@316
   258
\end{figure}
lcp@316
   259
lcp@316
   260
lcp@104
   261
\section{Tactics for the cut rule}
lcp@104
   262
According to the cut-elimination theorem, the cut rule can be eliminated
lcp@104
   263
from proofs of sequents.  But the rule is still essential.  It can be used
lcp@104
   264
to structure a proof into lemmas, avoiding repeated proofs of the same
lcp@104
   265
formula.  More importantly, the cut rule can not be eliminated from
lcp@104
   266
derivations of rules.  For example, there is a trivial cut-free proof of
lcp@104
   267
the sequent \(P\conj Q\turn Q\conj P\).
lcp@104
   268
Noting this, we might want to derive a rule for swapping the conjuncts
lcp@104
   269
in a right-hand formula:
lcp@104
   270
\[ \Gamma\turn \Delta, P\conj Q\over \Gamma\turn \Delta, Q\conj P \]
lcp@104
   271
The cut rule must be used, for $P\conj Q$ is not a subformula of $Q\conj
lcp@104
   272
P$.  Most cuts directly involve a premise of the rule being derived (a
lcp@104
   273
meta-assumption).  In a few cases, the cut formula is not part of any
lcp@104
   274
premise, but serves as a bridge between the premises and the conclusion.
lcp@104
   275
In such proofs, the cut formula is specified by calling an appropriate
lcp@104
   276
tactic.
lcp@104
   277
lcp@104
   278
\begin{ttbox} 
lcp@104
   279
cutR_tac : string -> int -> tactic
lcp@104
   280
cutL_tac : string -> int -> tactic
lcp@104
   281
\end{ttbox}
lcp@104
   282
These tactics refine a subgoal into two by applying the cut rule.  The cut
lcp@104
   283
formula is given as a string, and replaces some other formula in the sequent.
lcp@316
   284
\begin{ttdescription}
lcp@264
   285
\item[\ttindexbold{cutR_tac} {\it P\/} {\it i}] 
lcp@104
   286
reads an \LK{} formula~$P$, and applies the cut rule to subgoal~$i$.  It
lcp@104
   287
then deletes some formula from the right side of subgoal~$i$, replacing
lcp@104
   288
that formula by~$P$.
lcp@104
   289
lcp@264
   290
\item[\ttindexbold{cutL_tac} {\it P\/} {\it i}] 
lcp@104
   291
reads an \LK{} formula~$P$, and applies the cut rule to subgoal~$i$.  It
lcp@291
   292
then deletes some formula from the left side of the new subgoal $i+1$,
lcp@104
   293
replacing that formula by~$P$.
lcp@316
   294
\end{ttdescription}
lcp@104
   295
All the structural rules --- cut, contraction, and thinning --- can be
lcp@316
   296
applied to particular formulae using {\tt res_inst_tac}.
lcp@104
   297
lcp@104
   298
lcp@104
   299
\section{Tactics for sequents}
lcp@104
   300
\begin{ttbox} 
lcp@104
   301
forms_of_seq       : term -> term list
lcp@104
   302
could_res          : term * term -> bool
lcp@104
   303
could_resolve_seq  : term * term -> bool
lcp@104
   304
filseq_resolve_tac : thm list -> int -> int -> tactic
lcp@104
   305
\end{ttbox}
lcp@104
   306
Associative unification is not as efficient as it might be, in part because
lcp@104
   307
the representation of lists defeats some of Isabelle's internal
lcp@333
   308
optimisations.  The following operations implement faster rule application,
lcp@104
   309
and may have other uses.
lcp@316
   310
\begin{ttdescription}
lcp@104
   311
\item[\ttindexbold{forms_of_seq} {\it t}] 
lcp@104
   312
returns the list of all formulae in the sequent~$t$, removing sequence
lcp@104
   313
variables.
lcp@104
   314
lcp@316
   315
\item[\ttindexbold{could_res} ($t$,$u$)] 
lcp@104
   316
tests whether two formula lists could be resolved.  List $t$ is from a
lcp@316
   317
premise or subgoal, while $u$ is from the conclusion of an object-rule.
lcp@104
   318
Assuming that each formula in $u$ is surrounded by sequence variables, it
lcp@104
   319
checks that each conclusion formula is unifiable (using {\tt could_unify})
lcp@104
   320
with some subgoal formula.
lcp@104
   321
lcp@316
   322
\item[\ttindexbold{could_resolve_seq} ($t$,$u$)] 
lcp@291
   323
  tests whether two sequents could be resolved.  Sequent $t$ is a premise
lcp@316
   324
  or subgoal, while $u$ is the conclusion of an object-rule.  It simply
lcp@291
   325
  calls {\tt could_res} twice to check that both the left and the right
lcp@291
   326
  sides of the sequents are compatible.
lcp@104
   327
lcp@104
   328
\item[\ttindexbold{filseq_resolve_tac} {\it thms} {\it maxr} {\it i}] 
lcp@104
   329
uses {\tt filter_thms could_resolve} to extract the {\it thms} that are
lcp@104
   330
applicable to subgoal~$i$.  If more than {\it maxr\/} theorems are
lcp@104
   331
applicable then the tactic fails.  Otherwise it calls {\tt resolve_tac}.
lcp@104
   332
Thus, it is the sequent calculus analogue of \ttindex{filt_resolve_tac}.
lcp@316
   333
\end{ttdescription}
lcp@104
   334
lcp@104
   335
lcp@104
   336
lcp@104
   337
\section{Packaging sequent rules}
lcp@316
   338
Section~\ref{sec:safe} described the distinction between safe and unsafe
lcp@316
   339
rules.  An unsafe rule may reduce a provable goal to an unprovable set of
lcp@316
   340
subgoals, and should only be used as a last resort.  Typical examples are
lcp@316
   341
the weakened quantifier rules {\tt allL_thin} and {\tt exR_thin}.
lcp@104
   342
lcp@316
   343
A {\bf pack} is a pair whose first component is a list of safe rules and
lcp@316
   344
whose second is a list of unsafe rules.  Packs can be extended in an
lcp@316
   345
obvious way to allow reasoning with various collections of rules.  For
lcp@316
   346
clarity, \LK{} declares \mltydx{pack} as an \ML{} datatype, although is
lcp@316
   347
essentially a type synonym:
lcp@104
   348
\begin{ttbox}
lcp@104
   349
datatype pack = Pack of thm list * thm list;
lcp@104
   350
\end{ttbox}
lcp@316
   351
Pattern-matching using constructor {\tt Pack} can inspect a pack's
lcp@316
   352
contents.  Packs support the following operations:
lcp@104
   353
\begin{ttbox} 
lcp@104
   354
empty_pack  : pack
lcp@104
   355
prop_pack   : pack
lcp@104
   356
LK_pack     : pack
lcp@104
   357
LK_dup_pack : pack
lcp@104
   358
add_safes   : pack * thm list -> pack               \hfill{\bf infix 4}
lcp@104
   359
add_unsafes : pack * thm list -> pack               \hfill{\bf infix 4}
lcp@104
   360
\end{ttbox}
lcp@316
   361
\begin{ttdescription}
lcp@104
   362
\item[\ttindexbold{empty_pack}] is the empty pack.
lcp@104
   363
lcp@104
   364
\item[\ttindexbold{prop_pack}] contains the propositional rules, namely
lcp@104
   365
those for $\conj$, $\disj$, $\neg$, $\imp$ and~$\bimp$, along with the
lcp@316
   366
rules {\tt basic} and {\tt refl}.  These are all safe.
lcp@104
   367
lcp@104
   368
\item[\ttindexbold{LK_pack}] 
lcp@316
   369
extends {\tt prop_pack} with the safe rules {\tt allR}
lcp@316
   370
and~{\tt exL} and the unsafe rules {\tt allL_thin} and
lcp@316
   371
{\tt exR_thin}.  Search using this is incomplete since quantified
lcp@104
   372
formulae are used at most once.
lcp@104
   373
lcp@104
   374
\item[\ttindexbold{LK_dup_pack}] 
lcp@316
   375
extends {\tt prop_pack} with the safe rules {\tt allR}
lcp@316
   376
and~{\tt exL} and the unsafe rules \tdx{allL} and~\tdx{exR}.
lcp@104
   377
Search using this is complete, since quantified formulae may be reused, but
lcp@104
   378
frequently fails to terminate.  It is generally unsuitable for depth-first
lcp@104
   379
search.
lcp@104
   380
lcp@104
   381
\item[$pack$ \ttindexbold{add_safes} $rules$] 
lcp@104
   382
adds some safe~$rules$ to the pack~$pack$.
lcp@104
   383
lcp@104
   384
\item[$pack$ \ttindexbold{add_unsafes} $rules$] 
lcp@104
   385
adds some unsafe~$rules$ to the pack~$pack$.
lcp@316
   386
\end{ttdescription}
lcp@104
   387
lcp@104
   388
lcp@104
   389
\section{Proof procedures}
lcp@316
   390
The \LK{} proof procedure is similar to the classical reasoner
lcp@316
   391
described in 
lcp@316
   392
\iflabelundefined{chap:classical}{the {\em Reference Manual\/}}%
lcp@316
   393
            {Chap.\ts\ref{chap:classical}}.  
lcp@316
   394
%
lcp@316
   395
In fact it is simpler, since it works directly with sequents rather than
lcp@316
   396
simulating them.  There is no need to distinguish introduction rules from
lcp@316
   397
elimination rules, and of course there is no swap rule.  As always,
lcp@316
   398
Isabelle's classical proof procedures are less powerful than resolution
lcp@316
   399
theorem provers.  But they are more natural and flexible, working with an
lcp@316
   400
open-ended set of rules.
lcp@104
   401
lcp@104
   402
Backtracking over the choice of a safe rule accomplishes nothing: applying
lcp@104
   403
them in any order leads to essentially the same result.  Backtracking may
lcp@104
   404
be necessary over basic sequents when they perform unification.  Suppose
lcp@104
   405
that~0, 1, 2,~3 are constants in the subgoals
lcp@104
   406
\[  \begin{array}{c}
lcp@104
   407
      P(0), P(1), P(2) \turn P(\Var{a})  \\
lcp@104
   408
      P(0), P(2), P(3) \turn P(\Var{a})  \\
lcp@104
   409
      P(1), P(3), P(2) \turn P(\Var{a})  
lcp@104
   410
    \end{array}
lcp@104
   411
\]
lcp@104
   412
The only assignment that satisfies all three subgoals is $\Var{a}\mapsto 2$,
lcp@104
   413
and this can only be discovered by search.  The tactics given below permit
lcp@316
   414
backtracking only over axioms, such as {\tt basic} and {\tt refl};
lcp@316
   415
otherwise they are deterministic.
lcp@104
   416
lcp@104
   417
lcp@104
   418
\subsection{Method A}
lcp@104
   419
\begin{ttbox} 
lcp@104
   420
reresolve_tac   : thm list -> int -> tactic
lcp@104
   421
repeat_goal_tac : pack -> int -> tactic
lcp@104
   422
pc_tac          : pack -> int -> tactic
lcp@104
   423
\end{ttbox}
lcp@104
   424
These tactics use a method developed by Philippe de Groote.  A subgoal is
lcp@104
   425
refined and the resulting subgoals are attempted in reverse order.  For
lcp@104
   426
some reason, this is much faster than attempting the subgoals in order.
lcp@104
   427
The method is inherently depth-first.
lcp@104
   428
lcp@104
   429
At present, these tactics only work for rules that have no more than two
lcp@316
   430
premises.  They fail --- return no next state --- if they can do nothing.
lcp@316
   431
\begin{ttdescription}
lcp@104
   432
\item[\ttindexbold{reresolve_tac} $thms$ $i$] 
lcp@104
   433
repeatedly applies the $thms$ to subgoal $i$ and the resulting subgoals.
lcp@104
   434
lcp@104
   435
\item[\ttindexbold{repeat_goal_tac} $pack$ $i$] 
lcp@104
   436
applies the safe rules in the pack to a goal and the resulting subgoals.
lcp@104
   437
If no safe rule is applicable then it applies an unsafe rule and continues.
lcp@104
   438
lcp@104
   439
\item[\ttindexbold{pc_tac} $pack$ $i$] 
lcp@104
   440
applies {\tt repeat_goal_tac} using depth-first search to solve subgoal~$i$.
lcp@316
   441
\end{ttdescription}
lcp@104
   442
lcp@104
   443
lcp@104
   444
\subsection{Method B}
lcp@104
   445
\begin{ttbox} 
lcp@104
   446
safe_goal_tac : pack -> int -> tactic
lcp@104
   447
step_tac      : pack -> int -> tactic
lcp@104
   448
fast_tac      : pack -> int -> tactic
lcp@104
   449
best_tac      : pack -> int -> tactic
lcp@104
   450
\end{ttbox}
lcp@104
   451
These tactics are precisely analogous to those of the generic classical
lcp@316
   452
reasoner.  They use `Method~A' only on safe rules.  They fail if they
lcp@104
   453
can do nothing.
lcp@316
   454
\begin{ttdescription}
lcp@104
   455
\item[\ttindexbold{safe_goal_tac} $pack$ $i$] 
lcp@104
   456
applies the safe rules in the pack to a goal and the resulting subgoals.
lcp@104
   457
It ignores the unsafe rules.  
lcp@104
   458
lcp@104
   459
\item[\ttindexbold{step_tac} $pack$ $i$] 
lcp@104
   460
either applies safe rules (using {\tt safe_goal_tac}) or applies one unsafe
lcp@104
   461
rule.
lcp@104
   462
lcp@104
   463
\item[\ttindexbold{fast_tac} $pack$ $i$] 
lcp@104
   464
applies {\tt step_tac} using depth-first search to solve subgoal~$i$.
lcp@316
   465
Despite its name, it is frequently slower than {\tt pc_tac}.
lcp@104
   466
lcp@104
   467
\item[\ttindexbold{best_tac} $pack$ $i$] 
lcp@104
   468
applies {\tt step_tac} using best-first search to solve subgoal~$i$.  It is
lcp@104
   469
particularly useful for quantifier duplication (using \ttindex{LK_dup_pack}).
lcp@316
   470
\end{ttdescription}
lcp@104
   471
lcp@104
   472
lcp@104
   473
lcp@104
   474
\section{A simple example of classical reasoning} 
lcp@104
   475
The theorem $\turn\ex{y}\all{x}P(y)\imp P(x)$ is a standard example of the
lcp@104
   476
classical treatment of the existential quantifier.  Classical reasoning
lcp@104
   477
is easy using~{\LK}, as you can see by comparing this proof with the one
lcp@104
   478
given in~\S\ref{fol-cla-example}.  From a logical point of view, the
lcp@316
   479
proofs are essentially the same; the key step here is to use \tdx{exR}
lcp@316
   480
rather than the weaker~\tdx{exR_thin}.
lcp@104
   481
\begin{ttbox}
paulson@5151
   482
Goal "|- EX y. ALL x. P(y)-->P(x)";
lcp@104
   483
{\out Level 0}
lcp@104
   484
{\out  |- EX y. ALL x. P(y) --> P(x)}
lcp@104
   485
{\out  1.  |- EX y. ALL x. P(y) --> P(x)}
lcp@104
   486
by (resolve_tac [exR] 1);
lcp@104
   487
{\out Level 1}
lcp@104
   488
{\out  |- EX y. ALL x. P(y) --> P(x)}
lcp@104
   489
{\out  1.  |- ALL x. P(?x) --> P(x), EX x. ALL xa. P(x) --> P(xa)}
lcp@104
   490
\end{ttbox}
lcp@104
   491
There are now two formulae on the right side.  Keeping the existential one
lcp@104
   492
in reserve, we break down the universal one.
lcp@104
   493
\begin{ttbox}
lcp@104
   494
by (resolve_tac [allR] 1);
lcp@104
   495
{\out Level 2}
lcp@104
   496
{\out  |- EX y. ALL x. P(y) --> P(x)}
lcp@104
   497
{\out  1. !!x.  |- P(?x) --> P(x), EX x. ALL xa. P(x) --> P(xa)}
lcp@104
   498
by (resolve_tac [impR] 1);
lcp@104
   499
{\out Level 3}
lcp@104
   500
{\out  |- EX y. ALL x. P(y) --> P(x)}
lcp@104
   501
{\out  1. !!x. P(?x) |- P(x), EX x. ALL xa. P(x) --> P(xa)}
lcp@104
   502
\end{ttbox}
lcp@104
   503
Because {\LK} is a sequent calculus, the formula~$P(\Var{x})$ does not
lcp@104
   504
become an assumption;  instead, it moves to the left side.  The
lcp@104
   505
resulting subgoal cannot be instantiated to a basic sequent: the bound
lcp@104
   506
variable~$x$ is not unifiable with the unknown~$\Var{x}$.
lcp@104
   507
\begin{ttbox}
lcp@104
   508
by (resolve_tac [basic] 1);
lcp@104
   509
{\out by: tactic failed}
lcp@104
   510
\end{ttbox}
lcp@316
   511
We reuse the existential formula using~\tdx{exR_thin}, which discards
lcp@316
   512
it; we shall not need it a third time.  We again break down the resulting
lcp@104
   513
formula.
lcp@104
   514
\begin{ttbox}
lcp@104
   515
by (resolve_tac [exR_thin] 1);
lcp@104
   516
{\out Level 4}
lcp@104
   517
{\out  |- EX y. ALL x. P(y) --> P(x)}
lcp@104
   518
{\out  1. !!x. P(?x) |- P(x), ALL xa. P(?x7(x)) --> P(xa)}
lcp@104
   519
by (resolve_tac [allR] 1);
lcp@104
   520
{\out Level 5}
lcp@104
   521
{\out  |- EX y. ALL x. P(y) --> P(x)}
lcp@104
   522
{\out  1. !!x xa. P(?x) |- P(x), P(?x7(x)) --> P(xa)}
lcp@104
   523
by (resolve_tac [impR] 1);
lcp@104
   524
{\out Level 6}
lcp@104
   525
{\out  |- EX y. ALL x. P(y) --> P(x)}
lcp@104
   526
{\out  1. !!x xa. P(?x), P(?x7(x)) |- P(x), P(xa)}
lcp@104
   527
\end{ttbox}
lcp@104
   528
Subgoal~1 seems to offer lots of possibilities.  Actually the only useful
paulson@5151
   529
step is instantiating~$\Var{x@7}$ to $\lambda x. x$,
lcp@104
   530
transforming~$\Var{x@7}(x)$ into~$x$.
lcp@104
   531
\begin{ttbox}
lcp@104
   532
by (resolve_tac [basic] 1);
lcp@104
   533
{\out Level 7}
lcp@104
   534
{\out  |- EX y. ALL x. P(y) --> P(x)}
lcp@104
   535
{\out No subgoals!}
lcp@104
   536
\end{ttbox}
lcp@104
   537
This theorem can be proved automatically.  Because it involves quantifier
lcp@104
   538
duplication, we employ best-first search:
lcp@104
   539
\begin{ttbox}
paulson@5151
   540
Goal "|- EX y. ALL x. P(y)-->P(x)";
lcp@104
   541
{\out Level 0}
lcp@104
   542
{\out  |- EX y. ALL x. P(y) --> P(x)}
lcp@104
   543
{\out  1.  |- EX y. ALL x. P(y) --> P(x)}
lcp@104
   544
by (best_tac LK_dup_pack 1);
lcp@104
   545
{\out Level 1}
lcp@104
   546
{\out  |- EX y. ALL x. P(y) --> P(x)}
lcp@104
   547
{\out No subgoals!}
lcp@104
   548
\end{ttbox}
lcp@104
   549
lcp@104
   550
lcp@104
   551
lcp@104
   552
\section{A more complex proof}
lcp@104
   553
Many of Pelletier's test problems for theorem provers \cite{pelletier86}
lcp@104
   554
can be solved automatically.  Problem~39 concerns set theory, asserting
lcp@104
   555
that there is no Russell set --- a set consisting of those sets that are
lcp@104
   556
not members of themselves:
lcp@104
   557
\[  \turn \neg (\exists x. \forall y. y\in x \bimp y\not\in y) \]
lcp@104
   558
This does not require special properties of membership; we may
lcp@104
   559
generalize $x\in y$ to an arbitrary predicate~$F(x,y)$.  The theorem has a
lcp@291
   560
short manual proof.  See the directory {\tt LK/ex} for many more
lcp@104
   561
examples.
lcp@104
   562
lcp@104
   563
We set the main goal and move the negated formula to the left.
lcp@104
   564
\begin{ttbox}
paulson@5151
   565
Goal "|- ~ (EX x. ALL y. F(y,x) <-> ~F(y,y))";
lcp@104
   566
{\out Level 0}
lcp@104
   567
{\out  |- ~ (EX x. ALL y. F(y,x) <-> ~ F(y,y))}
lcp@104
   568
{\out  1.  |- ~ (EX x. ALL y. F(y,x) <-> ~ F(y,y))}
lcp@104
   569
by (resolve_tac [notR] 1);
lcp@104
   570
{\out Level 1}
lcp@104
   571
{\out  |- ~ (EX x. ALL y. F(y,x) <-> ~ F(y,y))}
lcp@104
   572
{\out  1. EX x. ALL y. F(y,x) <-> ~ F(y,y) |-}
lcp@104
   573
\end{ttbox}
lcp@104
   574
The right side is empty; we strip both quantifiers from the formula on the
lcp@104
   575
left.
lcp@104
   576
\begin{ttbox}
lcp@316
   577
by (resolve_tac [exL] 1);
lcp@104
   578
{\out Level 2}
lcp@104
   579
{\out  |- ~ (EX x. ALL y. F(y,x) <-> ~ F(y,y))}
lcp@104
   580
{\out  1. !!x. ALL y. F(y,x) <-> ~ F(y,y) |-}
lcp@104
   581
by (resolve_tac [allL_thin] 1);
lcp@104
   582
{\out Level 3}
lcp@104
   583
{\out  |- ~ (EX x. ALL y. F(y,x) <-> ~ F(y,y))}
lcp@104
   584
{\out  1. !!x. F(?x2(x),x) <-> ~ F(?x2(x),?x2(x)) |-}
lcp@104
   585
\end{ttbox}
lcp@316
   586
The rule \tdx{iffL} says, if $P\bimp Q$ then $P$ and~$Q$ are either
lcp@104
   587
both true or both false.  It yields two subgoals.
lcp@104
   588
\begin{ttbox}
lcp@104
   589
by (resolve_tac [iffL] 1);
lcp@104
   590
{\out Level 4}
lcp@104
   591
{\out  |- ~ (EX x. ALL y. F(y,x) <-> ~ F(y,y))}
lcp@104
   592
{\out  1. !!x.  |- F(?x2(x),x), ~ F(?x2(x),?x2(x))}
lcp@104
   593
{\out  2. !!x. ~ F(?x2(x),?x2(x)), F(?x2(x),x) |-}
lcp@104
   594
\end{ttbox}
lcp@104
   595
We must instantiate~$\Var{x@2}$, the shared unknown, to satisfy both
lcp@104
   596
subgoals.  Beginning with subgoal~2, we move a negated formula to the left
lcp@104
   597
and create a basic sequent.
lcp@104
   598
\begin{ttbox}
lcp@104
   599
by (resolve_tac [notL] 2);
lcp@104
   600
{\out Level 5}
lcp@104
   601
{\out  |- ~ (EX x. ALL y. F(y,x) <-> ~ F(y,y))}
lcp@104
   602
{\out  1. !!x.  |- F(?x2(x),x), ~ F(?x2(x),?x2(x))}
lcp@104
   603
{\out  2. !!x. F(?x2(x),x) |- F(?x2(x),?x2(x))}
lcp@104
   604
by (resolve_tac [basic] 2);
lcp@104
   605
{\out Level 6}
lcp@104
   606
{\out  |- ~ (EX x. ALL y. F(y,x) <-> ~ F(y,y))}
lcp@104
   607
{\out  1. !!x.  |- F(x,x), ~ F(x,x)}
lcp@104
   608
\end{ttbox}
lcp@104
   609
Thanks to the instantiation of~$\Var{x@2}$, subgoal~1 is obviously true.
lcp@104
   610
\begin{ttbox}
lcp@104
   611
by (resolve_tac [notR] 1);
lcp@104
   612
{\out Level 7}
lcp@104
   613
{\out  |- ~ (EX x. ALL y. F(y,x) <-> ~ F(y,y))}
lcp@104
   614
{\out  1. !!x. F(x,x) |- F(x,x)}
lcp@104
   615
by (resolve_tac [basic] 1);
lcp@104
   616
{\out Level 8}
lcp@104
   617
{\out  |- ~ (EX x. ALL y. F(y,x) <-> ~ F(y,y))}
lcp@104
   618
{\out No subgoals!}
lcp@104
   619
\end{ttbox}
lcp@316
   620
lcp@316
   621
\index{sequent calculus|)}