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