doc-src/IsarRef/Thy/document/Proof.tex
author wenzelm
Sun, 15 Feb 2009 18:56:13 +0100
changeset 30072 533c27b43ee1
parent 30057 efcbbd7baa02
child 30172 afdf7808cfd0
permissions -rw-r--r--
updated generated files;
     1 %
     2 \begin{isabellebody}%
     3 \def\isabellecontext{Proof}%
     4 %
     5 \isadelimtheory
     6 %
     7 \endisadelimtheory
     8 %
     9 \isatagtheory
    10 \isacommand{theory}\isamarkupfalse%
    11 \ Proof\isanewline
    12 \isakeyword{imports}\ Main\isanewline
    13 \isakeyword{begin}%
    14 \endisatagtheory
    15 {\isafoldtheory}%
    16 %
    17 \isadelimtheory
    18 %
    19 \endisadelimtheory
    20 %
    21 \isamarkupchapter{Proofs \label{ch:proofs}%
    22 }
    23 \isamarkuptrue%
    24 %
    25 \begin{isamarkuptext}%
    26 Proof commands perform transitions of Isar/VM machine
    27   configurations, which are block-structured, consisting of a stack of
    28   nodes with three main components: logical proof context, current
    29   facts, and open goals.  Isar/VM transitions are typed according to
    30   the following three different modes of operation:
    31 
    32   \begin{description}
    33 
    34   \item \isa{{\isachardoublequote}proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} means that a new goal has just been
    35   stated that is now to be \emph{proven}; the next command may refine
    36   it by some proof method, and enter a sub-proof to establish the
    37   actual result.
    38 
    39   \item \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} is like a nested theory mode: the
    40   context may be augmented by \emph{stating} additional assumptions,
    41   intermediate results etc.
    42 
    43   \item \isa{{\isachardoublequote}proof{\isacharparenleft}chain{\isacharparenright}{\isachardoublequote}} is intermediate between \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} and \isa{{\isachardoublequote}proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}}: existing facts (i.e.\
    44   the contents of the special ``\indexref{}{fact}{this}\hyperlink{fact.this}{\mbox{\isa{this}}}'' register) have been
    45   just picked up in order to be used when refining the goal claimed
    46   next.
    47 
    48   \end{description}
    49 
    50   The proof mode indicator may be understood as an instruction to the
    51   writer, telling what kind of operation may be performed next.  The
    52   corresponding typings of proof commands restricts the shape of
    53   well-formed proof texts to particular command sequences.  So dynamic
    54   arrangements of commands eventually turn out as static texts of a
    55   certain structure.
    56 
    57   \Appref{ap:refcard} gives a simplified grammar of the (extensible)
    58   language emerging that way from the different types of proof
    59   commands.  The main ideas of the overall Isar framework are
    60   explained in \chref{ch:isar-framework}.%
    61 \end{isamarkuptext}%
    62 \isamarkuptrue%
    63 %
    64 \isamarkupsection{Proof structure%
    65 }
    66 \isamarkuptrue%
    67 %
    68 \isamarkupsubsection{Blocks%
    69 }
    70 \isamarkuptrue%
    71 %
    72 \begin{isamarkuptext}%
    73 \begin{matharray}{rcl}
    74     \indexdef{}{command}{next}\hypertarget{command.next}{\hyperlink{command.next}{\mbox{\isa{\isacommand{next}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
    75     \indexdef{}{command}{\{}\hypertarget{command.braceleft}{\hyperlink{command.braceleft}{\mbox{\isa{\isacommand{{\isacharbraceleft}}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
    76     \indexdef{}{command}{\}}\hypertarget{command.braceright}{\hyperlink{command.braceright}{\mbox{\isa{\isacommand{{\isacharbraceright}}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
    77   \end{matharray}
    78 
    79   While Isar is inherently block-structured, opening and closing
    80   blocks is mostly handled rather casually, with little explicit
    81   user-intervention.  Any local goal statement automatically opens
    82   \emph{two} internal blocks, which are closed again when concluding
    83   the sub-proof (by \hyperlink{command.qed}{\mbox{\isa{\isacommand{qed}}}} etc.).  Sections of different
    84   context within a sub-proof may be switched via \hyperlink{command.next}{\mbox{\isa{\isacommand{next}}}},
    85   which is just a single block-close followed by block-open again.
    86   The effect of \hyperlink{command.next}{\mbox{\isa{\isacommand{next}}}} is to reset the local proof context;
    87   there is no goal focus involved here!
    88 
    89   For slightly more advanced applications, there are explicit block
    90   parentheses as well.  These typically achieve a stronger forward
    91   style of reasoning.
    92 
    93   \begin{description}
    94 
    95   \item \hyperlink{command.next}{\mbox{\isa{\isacommand{next}}}} switches to a fresh block within a
    96   sub-proof, resetting the local context to the initial one.
    97 
    98   \item \hyperlink{command.braceleft}{\mbox{\isa{\isacommand{{\isacharbraceleft}}}}} and \hyperlink{command.braceright}{\mbox{\isa{\isacommand{{\isacharbraceright}}}}} explicitly open and close
    99   blocks.  Any current facts pass through ``\hyperlink{command.braceleft}{\mbox{\isa{\isacommand{{\isacharbraceleft}}}}}''
   100   unchanged, while ``\hyperlink{command.braceright}{\mbox{\isa{\isacommand{{\isacharbraceright}}}}}'' causes any result to be
   101   \emph{exported} into the enclosing context.  Thus fixed variables
   102   are generalized, assumptions discharged, and local definitions
   103   unfolded (cf.\ \secref{sec:proof-context}).  There is no difference
   104   of \hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}} and \hyperlink{command.presume}{\mbox{\isa{\isacommand{presume}}}} in this mode of
   105   forward reasoning --- in contrast to plain backward reasoning with
   106   the result exported at \hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}} time.
   107 
   108   \end{description}%
   109 \end{isamarkuptext}%
   110 \isamarkuptrue%
   111 %
   112 \isamarkupsubsection{Omitting proofs%
   113 }
   114 \isamarkuptrue%
   115 %
   116 \begin{isamarkuptext}%
   117 \begin{matharray}{rcl}
   118     \indexdef{}{command}{oops}\hypertarget{command.oops}{\hyperlink{command.oops}{\mbox{\isa{\isacommand{oops}}}}} & : & \isa{{\isachardoublequote}proof\ {\isasymrightarrow}\ local{\isacharunderscore}theory\ {\isacharbar}\ theory{\isachardoublequote}} \\
   119   \end{matharray}
   120 
   121   The \hyperlink{command.oops}{\mbox{\isa{\isacommand{oops}}}} command discontinues the current proof
   122   attempt, while considering the partial proof text as properly
   123   processed.  This is conceptually quite different from ``faking''
   124   actual proofs via \indexref{}{command}{sorry}\hyperlink{command.sorry}{\mbox{\isa{\isacommand{sorry}}}} (see
   125   \secref{sec:proof-steps}): \hyperlink{command.oops}{\mbox{\isa{\isacommand{oops}}}} does not observe the
   126   proof structure at all, but goes back right to the theory level.
   127   Furthermore, \hyperlink{command.oops}{\mbox{\isa{\isacommand{oops}}}} does not produce any result theorem
   128   --- there is no intended claim to be able to complete the proof
   129   anyhow.
   130 
   131   A typical application of \hyperlink{command.oops}{\mbox{\isa{\isacommand{oops}}}} is to explain Isar proofs
   132   \emph{within} the system itself, in conjunction with the document
   133   preparation tools of Isabelle described in \chref{ch:document-prep}.
   134   Thus partial or even wrong proof attempts can be discussed in a
   135   logically sound manner.  Note that the Isabelle {\LaTeX} macros can
   136   be easily adapted to print something like ``\isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}'' instead of
   137   the keyword ``\hyperlink{command.oops}{\mbox{\isa{\isacommand{oops}}}}''.
   138 
   139   \medskip The \hyperlink{command.oops}{\mbox{\isa{\isacommand{oops}}}} command is undo-able, unlike
   140   \indexref{}{command}{kill}\hyperlink{command.kill}{\mbox{\isa{\isacommand{kill}}}} (see \secref{sec:history}).  The effect is to
   141   get back to the theory just before the opening of the proof.%
   142 \end{isamarkuptext}%
   143 \isamarkuptrue%
   144 %
   145 \isamarkupsection{Statements%
   146 }
   147 \isamarkuptrue%
   148 %
   149 \isamarkupsubsection{Context elements \label{sec:proof-context}%
   150 }
   151 \isamarkuptrue%
   152 %
   153 \begin{isamarkuptext}%
   154 \begin{matharray}{rcl}
   155     \indexdef{}{command}{fix}\hypertarget{command.fix}{\hyperlink{command.fix}{\mbox{\isa{\isacommand{fix}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
   156     \indexdef{}{command}{assume}\hypertarget{command.assume}{\hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
   157     \indexdef{}{command}{presume}\hypertarget{command.presume}{\hyperlink{command.presume}{\mbox{\isa{\isacommand{presume}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
   158     \indexdef{}{command}{def}\hypertarget{command.def}{\hyperlink{command.def}{\mbox{\isa{\isacommand{def}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
   159   \end{matharray}
   160 
   161   The logical proof context consists of fixed variables and
   162   assumptions.  The former closely correspond to Skolem constants, or
   163   meta-level universal quantification as provided by the Isabelle/Pure
   164   logical framework.  Introducing some \emph{arbitrary, but fixed}
   165   variable via ``\hyperlink{command.fix}{\mbox{\isa{\isacommand{fix}}}}~\isa{x}'' results in a local value
   166   that may be used in the subsequent proof as any other variable or
   167   constant.  Furthermore, any result \isa{{\isachardoublequote}{\isasymturnstile}\ {\isasymphi}{\isacharbrackleft}x{\isacharbrackright}{\isachardoublequote}} exported from
   168   the context will be universally closed wrt.\ \isa{x} at the
   169   outermost level: \isa{{\isachardoublequote}{\isasymturnstile}\ {\isasymAnd}x{\isachardot}\ {\isasymphi}{\isacharbrackleft}x{\isacharbrackright}{\isachardoublequote}} (this is expressed in normal
   170   form using Isabelle's meta-variables).
   171 
   172   Similarly, introducing some assumption \isa{{\isasymchi}} has two effects.
   173   On the one hand, a local theorem is created that may be used as a
   174   fact in subsequent proof steps.  On the other hand, any result
   175   \isa{{\isachardoublequote}{\isasymchi}\ {\isasymturnstile}\ {\isasymphi}{\isachardoublequote}} exported from the context becomes conditional wrt.\
   176   the assumption: \isa{{\isachardoublequote}{\isasymturnstile}\ {\isasymchi}\ {\isasymLongrightarrow}\ {\isasymphi}{\isachardoublequote}}.  Thus, solving an enclosing goal
   177   using such a result would basically introduce a new subgoal stemming
   178   from the assumption.  How this situation is handled depends on the
   179   version of assumption command used: while \hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}
   180   insists on solving the subgoal by unification with some premise of
   181   the goal, \hyperlink{command.presume}{\mbox{\isa{\isacommand{presume}}}} leaves the subgoal unchanged in order
   182   to be proved later by the user.
   183 
   184   Local definitions, introduced by ``\hyperlink{command.def}{\mbox{\isa{\isacommand{def}}}}~\isa{{\isachardoublequote}x\ {\isasymequiv}\ t{\isachardoublequote}}'', are achieved by combining ``\hyperlink{command.fix}{\mbox{\isa{\isacommand{fix}}}}~\isa{x}'' with
   185   another version of assumption that causes any hypothetical equation
   186   \isa{{\isachardoublequote}x\ {\isasymequiv}\ t{\isachardoublequote}} to be eliminated by the reflexivity rule.  Thus,
   187   exporting some result \isa{{\isachardoublequote}x\ {\isasymequiv}\ t\ {\isasymturnstile}\ {\isasymphi}{\isacharbrackleft}x{\isacharbrackright}{\isachardoublequote}} yields \isa{{\isachardoublequote}{\isasymturnstile}\ {\isasymphi}{\isacharbrackleft}t{\isacharbrackright}{\isachardoublequote}}.
   188 
   189   \begin{rail}
   190     'fix' (vars + 'and')
   191     ;
   192     ('assume' | 'presume') (props + 'and')
   193     ;
   194     'def' (def + 'and')
   195     ;
   196     def: thmdecl? \\ name ('==' | equiv) term termpat?
   197     ;
   198   \end{rail}
   199 
   200   \begin{description}
   201   
   202   \item \hyperlink{command.fix}{\mbox{\isa{\isacommand{fix}}}}~\isa{x} introduces a local variable \isa{x} that is \emph{arbitrary, but fixed.}
   203   
   204   \item \hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}~\isa{{\isachardoublequote}a{\isacharcolon}\ {\isasymphi}{\isachardoublequote}} and \hyperlink{command.presume}{\mbox{\isa{\isacommand{presume}}}}~\isa{{\isachardoublequote}a{\isacharcolon}\ {\isasymphi}{\isachardoublequote}} introduce a local fact \isa{{\isachardoublequote}{\isasymphi}\ {\isasymturnstile}\ {\isasymphi}{\isachardoublequote}} by
   205   assumption.  Subsequent results applied to an enclosing goal (e.g.\
   206   by \indexref{}{command}{show}\hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}}) are handled as follows: \hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}} expects to be able to unify with existing premises in the
   207   goal, while \hyperlink{command.presume}{\mbox{\isa{\isacommand{presume}}}} leaves \isa{{\isasymphi}} as new subgoals.
   208   
   209   Several lists of assumptions may be given (separated by
   210   \indexref{}{keyword}{and}\hyperlink{keyword.and}{\mbox{\isa{\isakeyword{and}}}}; the resulting list of current facts consists
   211   of all of these concatenated.
   212   
   213   \item \hyperlink{command.def}{\mbox{\isa{\isacommand{def}}}}~\isa{{\isachardoublequote}x\ {\isasymequiv}\ t{\isachardoublequote}} introduces a local
   214   (non-polymorphic) definition.  In results exported from the context,
   215   \isa{x} is replaced by \isa{t}.  Basically, ``\hyperlink{command.def}{\mbox{\isa{\isacommand{def}}}}~\isa{{\isachardoublequote}x\ {\isasymequiv}\ t{\isachardoublequote}}'' abbreviates ``\hyperlink{command.fix}{\mbox{\isa{\isacommand{fix}}}}~\isa{x}~\hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}~\isa{{\isachardoublequote}x\ {\isasymequiv}\ t{\isachardoublequote}}'', with the resulting
   216   hypothetical equation solved by reflexivity.
   217   
   218   The default name for the definitional equation is \isa{x{\isacharunderscore}def}.
   219   Several simultaneous definitions may be given at the same time.
   220 
   221   \end{description}
   222 
   223   The special name \indexref{}{fact}{prems}\hyperlink{fact.prems}{\mbox{\isa{prems}}} refers to all assumptions of the
   224   current context as a list of theorems.  This feature should be used
   225   with great care!  It is better avoided in final proof texts.%
   226 \end{isamarkuptext}%
   227 \isamarkuptrue%
   228 %
   229 \isamarkupsubsection{Term abbreviations \label{sec:term-abbrev}%
   230 }
   231 \isamarkuptrue%
   232 %
   233 \begin{isamarkuptext}%
   234 \begin{matharray}{rcl}
   235     \indexdef{}{command}{let}\hypertarget{command.let}{\hyperlink{command.let}{\mbox{\isa{\isacommand{let}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
   236     \indexdef{}{keyword}{is}\hypertarget{keyword.is}{\hyperlink{keyword.is}{\mbox{\isa{\isakeyword{is}}}}} & : & syntax \\
   237   \end{matharray}
   238 
   239   Abbreviations may be either bound by explicit \hyperlink{command.let}{\mbox{\isa{\isacommand{let}}}}~\isa{{\isachardoublequote}p\ {\isasymequiv}\ t{\isachardoublequote}} statements, or by annotating assumptions or
   240   goal statements with a list of patterns ``\isa{{\isachardoublequote}{\isacharparenleft}{\isasymIS}\ p\isactrlsub {\isadigit{1}}\ {\isasymdots}\ p\isactrlsub n{\isacharparenright}{\isachardoublequote}}''.  In both cases, higher-order matching is invoked to
   241   bind extra-logical term variables, which may be either named
   242   schematic variables of the form \isa{{\isacharquery}x}, or nameless dummies
   243   ``\hyperlink{variable.underscore}{\mbox{\isa{{\isacharunderscore}}}}'' (underscore). Note that in the \hyperlink{command.let}{\mbox{\isa{\isacommand{let}}}}
   244   form the patterns occur on the left-hand side, while the \hyperlink{keyword.is}{\mbox{\isa{\isakeyword{is}}}} patterns are in postfix position.
   245 
   246   Polymorphism of term bindings is handled in Hindley-Milner style,
   247   similar to ML.  Type variables referring to local assumptions or
   248   open goal statements are \emph{fixed}, while those of finished
   249   results or bound by \hyperlink{command.let}{\mbox{\isa{\isacommand{let}}}} may occur in \emph{arbitrary}
   250   instances later.  Even though actual polymorphism should be rarely
   251   used in practice, this mechanism is essential to achieve proper
   252   incremental type-inference, as the user proceeds to build up the
   253   Isar proof text from left to right.
   254 
   255   \medskip Term abbreviations are quite different from local
   256   definitions as introduced via \hyperlink{command.def}{\mbox{\isa{\isacommand{def}}}} (see
   257   \secref{sec:proof-context}).  The latter are visible within the
   258   logic as actual equations, while abbreviations disappear during the
   259   input process just after type checking.  Also note that \hyperlink{command.def}{\mbox{\isa{\isacommand{def}}}} does not support polymorphism.
   260 
   261   \begin{rail}
   262     'let' ((term + 'and') '=' term + 'and')
   263     ;  
   264   \end{rail}
   265 
   266   The syntax of \hyperlink{keyword.is}{\mbox{\isa{\isakeyword{is}}}} patterns follows \railnonterm{termpat}
   267   or \railnonterm{proppat} (see \secref{sec:term-decls}).
   268 
   269   \begin{description}
   270 
   271   \item \hyperlink{command.let}{\mbox{\isa{\isacommand{let}}}}~\isa{{\isachardoublequote}p\isactrlsub {\isadigit{1}}\ {\isacharequal}\ t\isactrlsub {\isadigit{1}}\ {\isasymAND}\ {\isasymdots}\ p\isactrlsub n\ {\isacharequal}\ t\isactrlsub n{\isachardoublequote}} binds any
   272   text variables in patterns \isa{{\isachardoublequote}p\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ p\isactrlsub n{\isachardoublequote}} by simultaneous
   273   higher-order matching against terms \isa{{\isachardoublequote}t\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ t\isactrlsub n{\isachardoublequote}}.
   274 
   275   \item \isa{{\isachardoublequote}{\isacharparenleft}{\isasymIS}\ p\isactrlsub {\isadigit{1}}\ {\isasymdots}\ p\isactrlsub n{\isacharparenright}{\isachardoublequote}} resembles \hyperlink{command.let}{\mbox{\isa{\isacommand{let}}}}, but
   276   matches \isa{{\isachardoublequote}p\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ p\isactrlsub n{\isachardoublequote}} against the preceding statement.  Also
   277   note that \hyperlink{keyword.is}{\mbox{\isa{\isakeyword{is}}}} is not a separate command, but part of
   278   others (such as \hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}, \hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}} etc.).
   279 
   280   \end{description}
   281 
   282   Some \emph{implicit} term abbreviations\index{term abbreviations}
   283   for goals and facts are available as well.  For any open goal,
   284   \indexref{}{variable}{thesis}\hyperlink{variable.thesis}{\mbox{\isa{thesis}}} refers to its object-level statement,
   285   abstracted over any meta-level parameters (if present).  Likewise,
   286   \indexref{}{variable}{this}\hyperlink{variable.this}{\mbox{\isa{this}}} is bound for fact statements resulting from
   287   assumptions or finished goals.  In case \hyperlink{variable.this}{\mbox{\isa{this}}} refers to
   288   an object-logic statement that is an application \isa{{\isachardoublequote}f\ t{\isachardoublequote}}, then
   289   \isa{t} is bound to the special text variable ``\hyperlink{variable.dots}{\mbox{\isa{{\isasymdots}}}}''
   290   (three dots).  The canonical application of this convenience are
   291   calculational proofs (see \secref{sec:calculation}).%
   292 \end{isamarkuptext}%
   293 \isamarkuptrue%
   294 %
   295 \isamarkupsubsection{Facts and forward chaining%
   296 }
   297 \isamarkuptrue%
   298 %
   299 \begin{isamarkuptext}%
   300 \begin{matharray}{rcl}
   301     \indexdef{}{command}{note}\hypertarget{command.note}{\hyperlink{command.note}{\mbox{\isa{\isacommand{note}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
   302     \indexdef{}{command}{then}\hypertarget{command.then}{\hyperlink{command.then}{\mbox{\isa{\isacommand{then}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}chain{\isacharparenright}{\isachardoublequote}} \\
   303     \indexdef{}{command}{from}\hypertarget{command.from}{\hyperlink{command.from}{\mbox{\isa{\isacommand{from}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}chain{\isacharparenright}{\isachardoublequote}} \\
   304     \indexdef{}{command}{with}\hypertarget{command.with}{\hyperlink{command.with}{\mbox{\isa{\isacommand{with}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}chain{\isacharparenright}{\isachardoublequote}} \\
   305     \indexdef{}{command}{using}\hypertarget{command.using}{\hyperlink{command.using}{\mbox{\isa{\isacommand{using}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}prove{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} \\
   306     \indexdef{}{command}{unfolding}\hypertarget{command.unfolding}{\hyperlink{command.unfolding}{\mbox{\isa{\isacommand{unfolding}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}prove{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} \\
   307   \end{matharray}
   308 
   309   New facts are established either by assumption or proof of local
   310   statements.  Any fact will usually be involved in further proofs,
   311   either as explicit arguments of proof methods, or when forward
   312   chaining towards the next goal via \hyperlink{command.then}{\mbox{\isa{\isacommand{then}}}} (and variants);
   313   \hyperlink{command.from}{\mbox{\isa{\isacommand{from}}}} and \hyperlink{command.with}{\mbox{\isa{\isacommand{with}}}} are composite forms
   314   involving \hyperlink{command.note}{\mbox{\isa{\isacommand{note}}}}.  The \hyperlink{command.using}{\mbox{\isa{\isacommand{using}}}} elements
   315   augments the collection of used facts \emph{after} a goal has been
   316   stated.  Note that the special theorem name \indexref{}{fact}{this}\hyperlink{fact.this}{\mbox{\isa{this}}} refers
   317   to the most recently established facts, but only \emph{before}
   318   issuing a follow-up claim.
   319 
   320   \begin{rail}
   321     'note' (thmdef? thmrefs + 'and')
   322     ;
   323     ('from' | 'with' | 'using' | 'unfolding') (thmrefs + 'and')
   324     ;
   325   \end{rail}
   326 
   327   \begin{description}
   328 
   329   \item \hyperlink{command.note}{\mbox{\isa{\isacommand{note}}}}~\isa{{\isachardoublequote}a\ {\isacharequal}\ b\isactrlsub {\isadigit{1}}\ {\isasymdots}\ b\isactrlsub n{\isachardoublequote}} recalls existing facts
   330   \isa{{\isachardoublequote}b\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ b\isactrlsub n{\isachardoublequote}}, binding the result as \isa{a}.  Note that
   331   attributes may be involved as well, both on the left and right hand
   332   sides.
   333 
   334   \item \hyperlink{command.then}{\mbox{\isa{\isacommand{then}}}} indicates forward chaining by the current
   335   facts in order to establish the goal to be claimed next.  The
   336   initial proof method invoked to refine that will be offered the
   337   facts to do ``anything appropriate'' (see also
   338   \secref{sec:proof-steps}).  For example, method \indexref{}{method}{rule}\hyperlink{method.rule}{\mbox{\isa{rule}}}
   339   (see \secref{sec:pure-meth-att}) would typically do an elimination
   340   rather than an introduction.  Automatic methods usually insert the
   341   facts into the goal state before operation.  This provides a simple
   342   scheme to control relevance of facts in automated proof search.
   343   
   344   \item \hyperlink{command.from}{\mbox{\isa{\isacommand{from}}}}~\isa{b} abbreviates ``\hyperlink{command.note}{\mbox{\isa{\isacommand{note}}}}~\isa{b}~\hyperlink{command.then}{\mbox{\isa{\isacommand{then}}}}''; thus \hyperlink{command.then}{\mbox{\isa{\isacommand{then}}}} is
   345   equivalent to ``\hyperlink{command.from}{\mbox{\isa{\isacommand{from}}}}~\isa{this}''.
   346   
   347   \item \hyperlink{command.with}{\mbox{\isa{\isacommand{with}}}}~\isa{{\isachardoublequote}b\isactrlsub {\isadigit{1}}\ {\isasymdots}\ b\isactrlsub n{\isachardoublequote}} abbreviates ``\hyperlink{command.from}{\mbox{\isa{\isacommand{from}}}}~\isa{{\isachardoublequote}b\isactrlsub {\isadigit{1}}\ {\isasymdots}\ b\isactrlsub n\ {\isasymAND}\ this{\isachardoublequote}}''; thus the forward chaining
   348   is from earlier facts together with the current ones.
   349   
   350   \item \hyperlink{command.using}{\mbox{\isa{\isacommand{using}}}}~\isa{{\isachardoublequote}b\isactrlsub {\isadigit{1}}\ {\isasymdots}\ b\isactrlsub n{\isachardoublequote}} augments the facts being
   351   currently indicated for use by a subsequent refinement step (such as
   352   \indexref{}{command}{apply}\hyperlink{command.apply}{\mbox{\isa{\isacommand{apply}}}} or \indexref{}{command}{proof}\hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}}).
   353   
   354   \item \hyperlink{command.unfolding}{\mbox{\isa{\isacommand{unfolding}}}}~\isa{{\isachardoublequote}b\isactrlsub {\isadigit{1}}\ {\isasymdots}\ b\isactrlsub n{\isachardoublequote}} is structurally
   355   similar to \hyperlink{command.using}{\mbox{\isa{\isacommand{using}}}}, but unfolds definitional equations
   356   \isa{{\isachardoublequote}b\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}\ b\isactrlsub n{\isachardoublequote}} throughout the goal state and facts.
   357 
   358   \end{description}
   359 
   360   Forward chaining with an empty list of theorems is the same as not
   361   chaining at all.  Thus ``\hyperlink{command.from}{\mbox{\isa{\isacommand{from}}}}~\isa{nothing}'' has no
   362   effect apart from entering \isa{{\isachardoublequote}prove{\isacharparenleft}chain{\isacharparenright}{\isachardoublequote}} mode, since
   363   \indexref{}{fact}{nothing}\hyperlink{fact.nothing}{\mbox{\isa{nothing}}} is bound to the empty list of theorems.
   364 
   365   Basic proof methods (such as \indexref{}{method}{rule}\hyperlink{method.rule}{\mbox{\isa{rule}}}) expect multiple
   366   facts to be given in their proper order, corresponding to a prefix
   367   of the premises of the rule involved.  Note that positions may be
   368   easily skipped using something like \hyperlink{command.from}{\mbox{\isa{\isacommand{from}}}}~\isa{{\isachardoublequote}{\isacharunderscore}\ {\isasymAND}\ a\ {\isasymAND}\ b{\isachardoublequote}}, for example.  This involves the trivial rule
   369   \isa{{\isachardoublequote}PROP\ {\isasympsi}\ {\isasymLongrightarrow}\ PROP\ {\isasympsi}{\isachardoublequote}}, which is bound in Isabelle/Pure as
   370   ``\indexref{}{fact}{\_}\hyperlink{fact.underscore}{\mbox{\isa{{\isacharunderscore}}}}'' (underscore).
   371 
   372   Automated methods (such as \hyperlink{method.simp}{\mbox{\isa{simp}}} or \hyperlink{method.auto}{\mbox{\isa{auto}}}) just
   373   insert any given facts before their usual operation.  Depending on
   374   the kind of procedure involved, the order of facts is less
   375   significant here.%
   376 \end{isamarkuptext}%
   377 \isamarkuptrue%
   378 %
   379 \isamarkupsubsection{Goals \label{sec:goals}%
   380 }
   381 \isamarkuptrue%
   382 %
   383 \begin{isamarkuptext}%
   384 \begin{matharray}{rcl}
   385     \indexdef{}{command}{lemma}\hypertarget{command.lemma}{\hyperlink{command.lemma}{\mbox{\isa{\isacommand{lemma}}}}} & : & \isa{{\isachardoublequote}local{\isacharunderscore}theory\ {\isasymrightarrow}\ proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} \\
   386     \indexdef{}{command}{theorem}\hypertarget{command.theorem}{\hyperlink{command.theorem}{\mbox{\isa{\isacommand{theorem}}}}} & : & \isa{{\isachardoublequote}local{\isacharunderscore}theory\ {\isasymrightarrow}\ proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} \\
   387     \indexdef{}{command}{corollary}\hypertarget{command.corollary}{\hyperlink{command.corollary}{\mbox{\isa{\isacommand{corollary}}}}} & : & \isa{{\isachardoublequote}local{\isacharunderscore}theory\ {\isasymrightarrow}\ proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} \\
   388     \indexdef{}{command}{have}\hypertarget{command.have}{\hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isacharbar}\ proof{\isacharparenleft}chain{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} \\
   389     \indexdef{}{command}{show}\hypertarget{command.show}{\hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isacharbar}\ proof{\isacharparenleft}chain{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} \\
   390     \indexdef{}{command}{hence}\hypertarget{command.hence}{\hyperlink{command.hence}{\mbox{\isa{\isacommand{hence}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} \\
   391     \indexdef{}{command}{thus}\hypertarget{command.thus}{\hyperlink{command.thus}{\mbox{\isa{\isacommand{thus}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} \\
   392     \indexdef{}{command}{print\_statement}\hypertarget{command.print-statement}{\hyperlink{command.print-statement}{\mbox{\isa{\isacommand{print{\isacharunderscore}statement}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
   393   \end{matharray}
   394 
   395   From a theory context, proof mode is entered by an initial goal
   396   command such as \hyperlink{command.lemma}{\mbox{\isa{\isacommand{lemma}}}}, \hyperlink{command.theorem}{\mbox{\isa{\isacommand{theorem}}}}, or
   397   \hyperlink{command.corollary}{\mbox{\isa{\isacommand{corollary}}}}.  Within a proof, new claims may be
   398   introduced locally as well; four variants are available here to
   399   indicate whether forward chaining of facts should be performed
   400   initially (via \indexref{}{command}{then}\hyperlink{command.then}{\mbox{\isa{\isacommand{then}}}}), and whether the final result
   401   is meant to solve some pending goal.
   402 
   403   Goals may consist of multiple statements, resulting in a list of
   404   facts eventually.  A pending multi-goal is internally represented as
   405   a meta-level conjunction (\isa{{\isachardoublequote}{\isacharampersand}{\isacharampersand}{\isacharampersand}{\isachardoublequote}}), which is usually
   406   split into the corresponding number of sub-goals prior to an initial
   407   method application, via \indexref{}{command}{proof}\hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}}
   408   (\secref{sec:proof-steps}) or \indexref{}{command}{apply}\hyperlink{command.apply}{\mbox{\isa{\isacommand{apply}}}}
   409   (\secref{sec:tactic-commands}).  The \indexref{}{method}{induct}\hyperlink{method.induct}{\mbox{\isa{induct}}} method
   410   covered in \secref{sec:cases-induct} acts on multiple claims
   411   simultaneously.
   412 
   413   Claims at the theory level may be either in short or long form.  A
   414   short goal merely consists of several simultaneous propositions
   415   (often just one).  A long goal includes an explicit context
   416   specification for the subsequent conclusion, involving local
   417   parameters and assumptions.  Here the role of each part of the
   418   statement is explicitly marked by separate keywords (see also
   419   \secref{sec:locale}); the local assumptions being introduced here
   420   are available as \indexref{}{fact}{assms}\hyperlink{fact.assms}{\mbox{\isa{assms}}} in the proof.  Moreover, there
   421   are two kinds of conclusions: \indexdef{}{element}{shows}\hypertarget{element.shows}{\hyperlink{element.shows}{\mbox{\isa{\isakeyword{shows}}}}} states several
   422   simultaneous propositions (essentially a big conjunction), while
   423   \indexdef{}{element}{obtains}\hypertarget{element.obtains}{\hyperlink{element.obtains}{\mbox{\isa{\isakeyword{obtains}}}}} claims several simultaneous simultaneous
   424   contexts of (essentially a big disjunction of eliminated parameters
   425   and assumptions, cf.\ \secref{sec:obtain}).
   426 
   427   \begin{rail}
   428     ('lemma' | 'theorem' | 'corollary') target? (goal | longgoal)
   429     ;
   430     ('have' | 'show' | 'hence' | 'thus') goal
   431     ;
   432     'print\_statement' modes? thmrefs
   433     ;
   434   
   435     goal: (props + 'and')
   436     ;
   437     longgoal: thmdecl? (contextelem *) conclusion
   438     ;
   439     conclusion: 'shows' goal | 'obtains' (parname? case + '|')
   440     ;
   441     case: (vars + 'and') 'where' (props + 'and')
   442     ;
   443   \end{rail}
   444 
   445   \begin{description}
   446   
   447   \item \hyperlink{command.lemma}{\mbox{\isa{\isacommand{lemma}}}}~\isa{{\isachardoublequote}a{\isacharcolon}\ {\isasymphi}{\isachardoublequote}} enters proof mode with
   448   \isa{{\isasymphi}} as main goal, eventually resulting in some fact \isa{{\isachardoublequote}{\isasymturnstile}\ {\isasymphi}{\isachardoublequote}} to be put back into the target context.  An additional
   449   \railnonterm{context} specification may build up an initial proof
   450   context for the subsequent claim; this includes local definitions
   451   and syntax as well, see the definition of \hyperlink{syntax.contextelem}{\mbox{\isa{contextelem}}} in
   452   \secref{sec:locale}.
   453   
   454   \item \hyperlink{command.theorem}{\mbox{\isa{\isacommand{theorem}}}}~\isa{{\isachardoublequote}a{\isacharcolon}\ {\isasymphi}{\isachardoublequote}} and \hyperlink{command.corollary}{\mbox{\isa{\isacommand{corollary}}}}~\isa{{\isachardoublequote}a{\isacharcolon}\ {\isasymphi}{\isachardoublequote}} are essentially the same as \hyperlink{command.lemma}{\mbox{\isa{\isacommand{lemma}}}}~\isa{{\isachardoublequote}a{\isacharcolon}\ {\isasymphi}{\isachardoublequote}}, but the facts are internally marked as
   455   being of a different kind.  This discrimination acts like a formal
   456   comment.
   457   
   458   \item \hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}}~\isa{{\isachardoublequote}a{\isacharcolon}\ {\isasymphi}{\isachardoublequote}} claims a local goal,
   459   eventually resulting in a fact within the current logical context.
   460   This operation is completely independent of any pending sub-goals of
   461   an enclosing goal statements, so \hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}} may be freely
   462   used for experimental exploration of potential results within a
   463   proof body.
   464   
   465   \item \hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}}~\isa{{\isachardoublequote}a{\isacharcolon}\ {\isasymphi}{\isachardoublequote}} is like \hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}}~\isa{{\isachardoublequote}a{\isacharcolon}\ {\isasymphi}{\isachardoublequote}} plus a second stage to refine some pending
   466   sub-goal for each one of the finished result, after having been
   467   exported into the corresponding context (at the head of the
   468   sub-proof of this \hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}} command).
   469   
   470   To accommodate interactive debugging, resulting rules are printed
   471   before being applied internally.  Even more, interactive execution
   472   of \hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}} predicts potential failure and displays the
   473   resulting error as a warning beforehand.  Watch out for the
   474   following message:
   475 
   476   %FIXME proper antiquitation
   477   \begin{ttbox}
   478   Problem! Local statement will fail to solve any pending goal
   479   \end{ttbox}
   480   
   481   \item \hyperlink{command.hence}{\mbox{\isa{\isacommand{hence}}}} abbreviates ``\hyperlink{command.then}{\mbox{\isa{\isacommand{then}}}}~\hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}}'', i.e.\ claims a local goal to be proven by forward
   482   chaining the current facts.  Note that \hyperlink{command.hence}{\mbox{\isa{\isacommand{hence}}}} is also
   483   equivalent to ``\hyperlink{command.from}{\mbox{\isa{\isacommand{from}}}}~\isa{this}~\hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}}''.
   484   
   485   \item \hyperlink{command.thus}{\mbox{\isa{\isacommand{thus}}}} abbreviates ``\hyperlink{command.then}{\mbox{\isa{\isacommand{then}}}}~\hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}}''.  Note that \hyperlink{command.thus}{\mbox{\isa{\isacommand{thus}}}} is also equivalent to
   486   ``\hyperlink{command.from}{\mbox{\isa{\isacommand{from}}}}~\isa{this}~\hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}}''.
   487   
   488   \item \hyperlink{command.print-statement}{\mbox{\isa{\isacommand{print{\isacharunderscore}statement}}}}~\isa{a} prints facts from the
   489   current theory or proof context in long statement form, according to
   490   the syntax for \hyperlink{command.lemma}{\mbox{\isa{\isacommand{lemma}}}} given above.
   491 
   492   \end{description}
   493 
   494   Any goal statement causes some term abbreviations (such as
   495   \indexref{}{variable}{?thesis}\hyperlink{variable.?thesis}{\mbox{\isa{{\isacharquery}thesis}}}) to be bound automatically, see also
   496   \secref{sec:term-abbrev}.
   497 
   498   The optional case names of \indexref{}{element}{obtains}\hyperlink{element.obtains}{\mbox{\isa{\isakeyword{obtains}}}} have a twofold
   499   meaning: (1) during the of this claim they refer to the the local
   500   context introductions, (2) the resulting rule is annotated
   501   accordingly to support symbolic case splits when used with the
   502   \indexref{}{method}{cases}\hyperlink{method.cases}{\mbox{\isa{cases}}} method (cf.\ \secref{sec:cases-induct}).
   503 
   504   \medskip
   505 
   506   \begin{warn}
   507     Isabelle/Isar suffers theory-level goal statements to contain
   508     \emph{unbound schematic variables}, although this does not conform
   509     to the aim of human-readable proof documents!  The main problem
   510     with schematic goals is that the actual outcome is usually hard to
   511     predict, depending on the behavior of the proof methods applied
   512     during the course of reasoning.  Note that most semi-automated
   513     methods heavily depend on several kinds of implicit rule
   514     declarations within the current theory context.  As this would
   515     also result in non-compositional checking of sub-proofs,
   516     \emph{local goals} are not allowed to be schematic at all.
   517     Nevertheless, schematic goals do have their use in Prolog-style
   518     interactive synthesis of proven results, usually by stepwise
   519     refinement via emulation of traditional Isabelle tactic scripts
   520     (see also \secref{sec:tactic-commands}).  In any case, users
   521     should know what they are doing.
   522   \end{warn}%
   523 \end{isamarkuptext}%
   524 \isamarkuptrue%
   525 %
   526 \isamarkupsection{Refinement steps%
   527 }
   528 \isamarkuptrue%
   529 %
   530 \isamarkupsubsection{Proof method expressions \label{sec:proof-meth}%
   531 }
   532 \isamarkuptrue%
   533 %
   534 \begin{isamarkuptext}%
   535 Proof methods are either basic ones, or expressions composed of
   536   methods via ``\verb|,|'' (sequential composition),
   537   ``\verb||\verb,|,\verb||'' (alternative choices), ``\verb|?|'' 
   538   (try), ``\verb|+|'' (repeat at least once), ``\verb|[|\isa{n}\verb|]|'' (restriction to first \isa{n}
   539   sub-goals, with default \isa{{\isachardoublequote}n\ {\isacharequal}\ {\isadigit{1}}{\isachardoublequote}}).  In practice, proof
   540   methods are usually just a comma separated list of
   541   \railqtok{nameref}~\railnonterm{args} specifications.  Note that
   542   parentheses may be dropped for single method specifications (with no
   543   arguments).
   544 
   545   \indexouternonterm{method}
   546   \begin{rail}
   547     method: (nameref | '(' methods ')') (() | '?' | '+' | '[' nat? ']')
   548     ;
   549     methods: (nameref args | method) + (',' | '|')
   550     ;
   551   \end{rail}
   552 
   553   Proper Isar proof methods do \emph{not} admit arbitrary goal
   554   addressing, but refer either to the first sub-goal or all sub-goals
   555   uniformly.  The goal restriction operator ``\isa{{\isachardoublequote}{\isacharbrackleft}n{\isacharbrackright}{\isachardoublequote}}''
   556   evaluates a method expression within a sandbox consisting of the
   557   first \isa{n} sub-goals (which need to exist).  For example, the
   558   method ``\isa{{\isachardoublequote}simp{\isacharunderscore}all{\isacharbrackleft}{\isadigit{3}}{\isacharbrackright}{\isachardoublequote}}'' simplifies the first three
   559   sub-goals, while ``\isa{{\isachardoublequote}{\isacharparenleft}rule\ foo{\isacharcomma}\ simp{\isacharunderscore}all{\isacharparenright}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequote}}'' simplifies all
   560   new goals that emerge from applying rule \isa{{\isachardoublequote}foo{\isachardoublequote}} to the
   561   originally first one.
   562 
   563   Improper methods, notably tactic emulations, offer a separate
   564   low-level goal addressing scheme as explicit argument to the
   565   individual tactic being involved.  Here ``\isa{{\isachardoublequote}{\isacharbrackleft}{\isacharbang}{\isacharbrackright}{\isachardoublequote}}'' refers to
   566   all goals, and ``\isa{{\isachardoublequote}{\isacharbrackleft}n{\isacharminus}{\isacharbrackright}{\isachardoublequote}}'' to all goals starting from \isa{{\isachardoublequote}n{\isachardoublequote}}.
   567 
   568   \indexouternonterm{goalspec}
   569   \begin{rail}
   570     goalspec: '[' (nat '-' nat | nat '-' | nat | '!' ) ']'
   571     ;
   572   \end{rail}%
   573 \end{isamarkuptext}%
   574 \isamarkuptrue%
   575 %
   576 \isamarkupsubsection{Initial and terminal proof steps \label{sec:proof-steps}%
   577 }
   578 \isamarkuptrue%
   579 %
   580 \begin{isamarkuptext}%
   581 \begin{matharray}{rcl}
   582     \indexdef{}{command}{proof}\hypertarget{command.proof}{\hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}prove{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
   583     \indexdef{}{command}{qed}\hypertarget{command.qed}{\hyperlink{command.qed}{\mbox{\isa{\isacommand{qed}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}\ {\isacharbar}\ local{\isacharunderscore}theory\ {\isacharbar}\ theory{\isachardoublequote}} \\
   584     \indexdef{}{command}{by}\hypertarget{command.by}{\hyperlink{command.by}{\mbox{\isa{\isacommand{by}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}prove{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}\ {\isacharbar}\ local{\isacharunderscore}theory\ {\isacharbar}\ theory{\isachardoublequote}} \\
   585     \indexdef{}{command}{..}\hypertarget{command.ddot}{\hyperlink{command.ddot}{\mbox{\isa{\isacommand{{\isachardot}{\isachardot}}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}prove{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}\ {\isacharbar}\ local{\isacharunderscore}theory\ {\isacharbar}\ theory{\isachardoublequote}} \\
   586     \indexdef{}{command}{.}\hypertarget{command.dot}{\hyperlink{command.dot}{\mbox{\isa{\isacommand{{\isachardot}}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}prove{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}\ {\isacharbar}\ local{\isacharunderscore}theory\ {\isacharbar}\ theory{\isachardoublequote}} \\
   587     \indexdef{}{command}{sorry}\hypertarget{command.sorry}{\hyperlink{command.sorry}{\mbox{\isa{\isacommand{sorry}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}prove{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}\ {\isacharbar}\ local{\isacharunderscore}theory\ {\isacharbar}\ theory{\isachardoublequote}} \\
   588   \end{matharray}
   589 
   590   Arbitrary goal refinement via tactics is considered harmful.
   591   Structured proof composition in Isar admits proof methods to be
   592   invoked in two places only.
   593 
   594   \begin{enumerate}
   595 
   596   \item An \emph{initial} refinement step \indexref{}{command}{proof}\hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}}~\isa{{\isachardoublequote}m\isactrlsub {\isadigit{1}}{\isachardoublequote}} reduces a newly stated goal to a number
   597   of sub-goals that are to be solved later.  Facts are passed to
   598   \isa{{\isachardoublequote}m\isactrlsub {\isadigit{1}}{\isachardoublequote}} for forward chaining, if so indicated by \isa{{\isachardoublequote}proof{\isacharparenleft}chain{\isacharparenright}{\isachardoublequote}} mode.
   599   
   600   \item A \emph{terminal} conclusion step \indexref{}{command}{qed}\hyperlink{command.qed}{\mbox{\isa{\isacommand{qed}}}}~\isa{{\isachardoublequote}m\isactrlsub {\isadigit{2}}{\isachardoublequote}} is intended to solve remaining goals.  No facts are
   601   passed to \isa{{\isachardoublequote}m\isactrlsub {\isadigit{2}}{\isachardoublequote}}.
   602 
   603   \end{enumerate}
   604 
   605   The only other (proper) way to affect pending goals in a proof body
   606   is by \indexref{}{command}{show}\hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}}, which involves an explicit statement of
   607   what is to be solved eventually.  Thus we avoid the fundamental
   608   problem of unstructured tactic scripts that consist of numerous
   609   consecutive goal transformations, with invisible effects.
   610 
   611   \medskip As a general rule of thumb for good proof style, initial
   612   proof methods should either solve the goal completely, or constitute
   613   some well-understood reduction to new sub-goals.  Arbitrary
   614   automatic proof tools that are prone leave a large number of badly
   615   structured sub-goals are no help in continuing the proof document in
   616   an intelligible manner.
   617 
   618   Unless given explicitly by the user, the default initial method is
   619   ``\indexref{}{method}{rule}\hyperlink{method.rule}{\mbox{\isa{rule}}}'', which applies a single standard elimination
   620   or introduction rule according to the topmost symbol involved.
   621   There is no separate default terminal method.  Any remaining goals
   622   are always solved by assumption in the very last step.
   623 
   624   \begin{rail}
   625     'proof' method?
   626     ;
   627     'qed' method?
   628     ;
   629     'by' method method?
   630     ;
   631     ('.' | '..' | 'sorry')
   632     ;
   633   \end{rail}
   634 
   635   \begin{description}
   636   
   637   \item \hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}}~\isa{{\isachardoublequote}m\isactrlsub {\isadigit{1}}{\isachardoublequote}} refines the goal by proof
   638   method \isa{{\isachardoublequote}m\isactrlsub {\isadigit{1}}{\isachardoublequote}}; facts for forward chaining are passed if so
   639   indicated by \isa{{\isachardoublequote}proof{\isacharparenleft}chain{\isacharparenright}{\isachardoublequote}} mode.
   640   
   641   \item \hyperlink{command.qed}{\mbox{\isa{\isacommand{qed}}}}~\isa{{\isachardoublequote}m\isactrlsub {\isadigit{2}}{\isachardoublequote}} refines any remaining goals by
   642   proof method \isa{{\isachardoublequote}m\isactrlsub {\isadigit{2}}{\isachardoublequote}} and concludes the sub-proof by assumption.
   643   If the goal had been \isa{{\isachardoublequote}show{\isachardoublequote}} (or \isa{{\isachardoublequote}thus{\isachardoublequote}}), some
   644   pending sub-goal is solved as well by the rule resulting from the
   645   result \emph{exported} into the enclosing goal context.  Thus \isa{{\isachardoublequote}qed{\isachardoublequote}} may fail for two reasons: either \isa{{\isachardoublequote}m\isactrlsub {\isadigit{2}}{\isachardoublequote}} fails, or the
   646   resulting rule does not fit to any pending goal\footnote{This
   647   includes any additional ``strong'' assumptions as introduced by
   648   \hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}.} of the enclosing context.  Debugging such a
   649   situation might involve temporarily changing \hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}} into
   650   \hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}}, or weakening the local context by replacing
   651   occurrences of \hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}} by \hyperlink{command.presume}{\mbox{\isa{\isacommand{presume}}}}.
   652   
   653   \item \hyperlink{command.by}{\mbox{\isa{\isacommand{by}}}}~\isa{{\isachardoublequote}m\isactrlsub {\isadigit{1}}\ m\isactrlsub {\isadigit{2}}{\isachardoublequote}} is a \emph{terminal
   654   proof}\index{proof!terminal}; it abbreviates \hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}}~\isa{{\isachardoublequote}m\isactrlsub {\isadigit{1}}{\isachardoublequote}}~\isa{{\isachardoublequote}qed{\isachardoublequote}}~\isa{{\isachardoublequote}m\isactrlsub {\isadigit{2}}{\isachardoublequote}}, but with
   655   backtracking across both methods.  Debugging an unsuccessful
   656   \hyperlink{command.by}{\mbox{\isa{\isacommand{by}}}}~\isa{{\isachardoublequote}m\isactrlsub {\isadigit{1}}\ m\isactrlsub {\isadigit{2}}{\isachardoublequote}} command can be done by expanding its
   657   definition; in many cases \hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}}~\isa{{\isachardoublequote}m\isactrlsub {\isadigit{1}}{\isachardoublequote}} (or even
   658   \isa{{\isachardoublequote}apply{\isachardoublequote}}~\isa{{\isachardoublequote}m\isactrlsub {\isadigit{1}}{\isachardoublequote}}) is already sufficient to see the
   659   problem.
   660 
   661   \item ``\hyperlink{command.ddot}{\mbox{\isa{\isacommand{{\isachardot}{\isachardot}}}}}'' is a \emph{default
   662   proof}\index{proof!default}; it abbreviates \hyperlink{command.by}{\mbox{\isa{\isacommand{by}}}}~\isa{{\isachardoublequote}rule{\isachardoublequote}}.
   663 
   664   \item ``\hyperlink{command.dot}{\mbox{\isa{\isacommand{{\isachardot}}}}}'' is a \emph{trivial
   665   proof}\index{proof!trivial}; it abbreviates \hyperlink{command.by}{\mbox{\isa{\isacommand{by}}}}~\isa{{\isachardoublequote}this{\isachardoublequote}}.
   666   
   667   \item \hyperlink{command.sorry}{\mbox{\isa{\isacommand{sorry}}}} is a \emph{fake proof}\index{proof!fake}
   668   pretending to solve the pending claim without further ado.  This
   669   only works in interactive development, or if the \verb|quick_and_dirty| flag is enabled (in ML).  Facts emerging from fake
   670   proofs are not the real thing.  Internally, each theorem container
   671   is tainted by an oracle invocation, which is indicated as ``\isa{{\isachardoublequote}{\isacharbrackleft}{\isacharbang}{\isacharbrackright}{\isachardoublequote}}'' in the printed result.
   672   
   673   The most important application of \hyperlink{command.sorry}{\mbox{\isa{\isacommand{sorry}}}} is to support
   674   experimentation and top-down proof development.
   675 
   676   \end{description}%
   677 \end{isamarkuptext}%
   678 \isamarkuptrue%
   679 %
   680 \isamarkupsubsection{Fundamental methods and attributes \label{sec:pure-meth-att}%
   681 }
   682 \isamarkuptrue%
   683 %
   684 \begin{isamarkuptext}%
   685 The following proof methods and attributes refer to basic logical
   686   operations of Isar.  Further methods and attributes are provided by
   687   several generic and object-logic specific tools and packages (see
   688   \chref{ch:gen-tools} and \chref{ch:hol}).
   689 
   690   \begin{matharray}{rcl}
   691     \indexdef{}{method}{-}\hypertarget{method.-}{\hyperlink{method.-}{\mbox{\isa{{\isacharminus}}}}} & : & \isa{method} \\
   692     \indexdef{}{method}{fact}\hypertarget{method.fact}{\hyperlink{method.fact}{\mbox{\isa{fact}}}} & : & \isa{method} \\
   693     \indexdef{}{method}{assumption}\hypertarget{method.assumption}{\hyperlink{method.assumption}{\mbox{\isa{assumption}}}} & : & \isa{method} \\
   694     \indexdef{}{method}{this}\hypertarget{method.this}{\hyperlink{method.this}{\mbox{\isa{this}}}} & : & \isa{method} \\
   695     \indexdef{}{method}{rule}\hypertarget{method.rule}{\hyperlink{method.rule}{\mbox{\isa{rule}}}} & : & \isa{method} \\
   696     \indexdef{}{method}{iprover}\hypertarget{method.iprover}{\hyperlink{method.iprover}{\mbox{\isa{iprover}}}} & : & \isa{method} \\[0.5ex]
   697     \indexdef{Pure}{attribute}{intro}\hypertarget{attribute.Pure.intro}{\hyperlink{attribute.Pure.intro}{\mbox{\isa{intro}}}} & : & \isa{attribute} \\
   698     \indexdef{Pure}{attribute}{elim}\hypertarget{attribute.Pure.elim}{\hyperlink{attribute.Pure.elim}{\mbox{\isa{elim}}}} & : & \isa{attribute} \\
   699     \indexdef{Pure}{attribute}{dest}\hypertarget{attribute.Pure.dest}{\hyperlink{attribute.Pure.dest}{\mbox{\isa{dest}}}} & : & \isa{attribute} \\
   700     \indexdef{}{attribute}{rule}\hypertarget{attribute.rule}{\hyperlink{attribute.rule}{\mbox{\isa{rule}}}} & : & \isa{attribute} \\[0.5ex]
   701     \indexdef{}{attribute}{OF}\hypertarget{attribute.OF}{\hyperlink{attribute.OF}{\mbox{\isa{OF}}}} & : & \isa{attribute} \\
   702     \indexdef{}{attribute}{of}\hypertarget{attribute.of}{\hyperlink{attribute.of}{\mbox{\isa{of}}}} & : & \isa{attribute} \\
   703     \indexdef{}{attribute}{where}\hypertarget{attribute.where}{\hyperlink{attribute.where}{\mbox{\isa{where}}}} & : & \isa{attribute} \\
   704   \end{matharray}
   705 
   706   \begin{rail}
   707     'fact' thmrefs?
   708     ;
   709     'rule' thmrefs?
   710     ;
   711     'iprover' ('!' ?) (rulemod *)
   712     ;
   713     rulemod: ('intro' | 'elim' | 'dest') ((('!' | () | '?') nat?) | 'del') ':' thmrefs
   714     ;
   715     ('intro' | 'elim' | 'dest') ('!' | () | '?') nat?
   716     ;
   717     'rule' 'del'
   718     ;
   719     'OF' thmrefs
   720     ;
   721     'of' insts ('concl' ':' insts)?
   722     ;
   723     'where' ((name | var | typefree | typevar) '=' (type | term) * 'and')
   724     ;
   725   \end{rail}
   726 
   727   \begin{description}
   728   
   729   \item ``\hyperlink{method.-}{\mbox{\isa{{\isacharminus}}}}'' (minus) does nothing but insert the forward
   730   chaining facts as premises into the goal.  Note that command
   731   \indexref{}{command}{proof}\hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}} without any method actually performs a single
   732   reduction step using the \indexref{}{method}{rule}\hyperlink{method.rule}{\mbox{\isa{rule}}} method; thus a plain
   733   \emph{do-nothing} proof step would be ``\hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}}~\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}'' rather than \hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}} alone.
   734   
   735   \item \hyperlink{method.fact}{\mbox{\isa{fact}}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}} composes some fact from
   736   \isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ a\isactrlsub n{\isachardoublequote}} (or implicitly from the current proof context)
   737   modulo unification of schematic type and term variables.  The rule
   738   structure is not taken into account, i.e.\ meta-level implication is
   739   considered atomic.  This is the same principle underlying literal
   740   facts (cf.\ \secref{sec:syn-att}): ``\hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}}~\isa{{\isachardoublequote}{\isasymphi}{\isachardoublequote}}~\hyperlink{command.by}{\mbox{\isa{\isacommand{by}}}}~\isa{fact}'' is equivalent to ``\hyperlink{command.note}{\mbox{\isa{\isacommand{note}}}}~\verb|`|\isa{{\isasymphi}}\verb|`|'' provided that
   741   \isa{{\isachardoublequote}{\isasymturnstile}\ {\isasymphi}{\isachardoublequote}} is an instance of some known \isa{{\isachardoublequote}{\isasymturnstile}\ {\isasymphi}{\isachardoublequote}} in the
   742   proof context.
   743   
   744   \item \hyperlink{method.assumption}{\mbox{\isa{assumption}}} solves some goal by a single assumption
   745   step.  All given facts are guaranteed to participate in the
   746   refinement; this means there may be only 0 or 1 in the first place.
   747   Recall that \hyperlink{command.qed}{\mbox{\isa{\isacommand{qed}}}} (\secref{sec:proof-steps}) already
   748   concludes any remaining sub-goals by assumption, so structured
   749   proofs usually need not quote the \hyperlink{method.assumption}{\mbox{\isa{assumption}}} method at
   750   all.
   751   
   752   \item \hyperlink{method.this}{\mbox{\isa{this}}} applies all of the current facts directly as
   753   rules.  Recall that ``\hyperlink{command.dot}{\mbox{\isa{\isacommand{{\isachardot}}}}}'' (dot) abbreviates ``\hyperlink{command.by}{\mbox{\isa{\isacommand{by}}}}~\isa{this}''.
   754   
   755   \item \hyperlink{method.rule}{\mbox{\isa{rule}}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}} applies some rule given as
   756   argument in backward manner; facts are used to reduce the rule
   757   before applying it to the goal.  Thus \hyperlink{method.rule}{\mbox{\isa{rule}}} without facts
   758   is plain introduction, while with facts it becomes elimination.
   759   
   760   When no arguments are given, the \hyperlink{method.rule}{\mbox{\isa{rule}}} method tries to pick
   761   appropriate rules automatically, as declared in the current context
   762   using the \hyperlink{attribute.Pure.intro}{\mbox{\isa{intro}}}, \hyperlink{attribute.Pure.elim}{\mbox{\isa{elim}}},
   763   \hyperlink{attribute.Pure.dest}{\mbox{\isa{dest}}} attributes (see below).  This is the
   764   default behavior of \hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}} and ``\hyperlink{command.ddot}{\mbox{\isa{\isacommand{{\isachardot}{\isachardot}}}}}'' 
   765   (double-dot) steps (see \secref{sec:proof-steps}).
   766   
   767   \item \hyperlink{method.iprover}{\mbox{\isa{iprover}}} performs intuitionistic proof search,
   768   depending on specifically declared rules from the context, or given
   769   as explicit arguments.  Chained facts are inserted into the goal
   770   before commencing proof search; ``\hyperlink{method.iprover}{\mbox{\isa{iprover}}}\isa{{\isachardoublequote}{\isacharbang}{\isachardoublequote}}''
   771   means to include the current \hyperlink{fact.prems}{\mbox{\isa{prems}}} as well.
   772   
   773   Rules need to be classified as \hyperlink{attribute.Pure.intro}{\mbox{\isa{intro}}},
   774   \hyperlink{attribute.Pure.elim}{\mbox{\isa{elim}}}, or \hyperlink{attribute.Pure.dest}{\mbox{\isa{dest}}}; here the
   775   ``\isa{{\isachardoublequote}{\isacharbang}{\isachardoublequote}}'' indicator refers to ``safe'' rules, which may be
   776   applied aggressively (without considering back-tracking later).
   777   Rules declared with ``\isa{{\isachardoublequote}{\isacharquery}{\isachardoublequote}}'' are ignored in proof search (the
   778   single-step \hyperlink{method.rule}{\mbox{\isa{rule}}} method still observes these).  An
   779   explicit weight annotation may be given as well; otherwise the
   780   number of rule premises will be taken into account here.
   781   
   782   \item \hyperlink{attribute.Pure.intro}{\mbox{\isa{intro}}}, \hyperlink{attribute.Pure.elim}{\mbox{\isa{elim}}}, and
   783   \hyperlink{attribute.Pure.dest}{\mbox{\isa{dest}}} declare introduction, elimination, and
   784   destruct rules, to be used with the \hyperlink{method.rule}{\mbox{\isa{rule}}} and \hyperlink{method.iprover}{\mbox{\isa{iprover}}} methods.  Note that the latter will ignore rules declared
   785   with ``\isa{{\isachardoublequote}{\isacharquery}{\isachardoublequote}}'', while ``\isa{{\isachardoublequote}{\isacharbang}{\isachardoublequote}}''  are used most
   786   aggressively.
   787   
   788   The classical reasoner (see \secref{sec:classical}) introduces its
   789   own variants of these attributes; use qualified names to access the
   790   present versions of Isabelle/Pure, i.e.\ \hyperlink{attribute.Pure.Pure.intro}{\mbox{\isa{Pure{\isachardot}intro}}}.
   791   
   792   \item \hyperlink{attribute.rule}{\mbox{\isa{rule}}}~\isa{del} undeclares introduction,
   793   elimination, or destruct rules.
   794   
   795   \item \hyperlink{attribute.OF}{\mbox{\isa{OF}}}~\isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isachardoublequote}} applies some theorem to all
   796   of the given rules \isa{{\isachardoublequote}a\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ a\isactrlsub n{\isachardoublequote}} (in parallel).  This
   797   corresponds to the \verb|op MRS| operation in ML,
   798   but note the reversed order.  Positions may be effectively skipped
   799   by including ``\isa{{\isacharunderscore}}'' (underscore) as argument.
   800   
   801   \item \hyperlink{attribute.of}{\mbox{\isa{of}}}~\isa{{\isachardoublequote}t\isactrlsub {\isadigit{1}}\ {\isasymdots}\ t\isactrlsub n{\isachardoublequote}} performs positional
   802   instantiation of term variables.  The terms \isa{{\isachardoublequote}t\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ t\isactrlsub n{\isachardoublequote}} are
   803   substituted for any schematic variables occurring in a theorem from
   804   left to right; ``\isa{{\isacharunderscore}}'' (underscore) indicates to skip a
   805   position.  Arguments following a ``\isa{{\isachardoublequote}concl{\isacharcolon}{\isachardoublequote}}'' specification
   806   refer to positions of the conclusion of a rule.
   807   
   808   \item \hyperlink{attribute.where}{\mbox{\isa{where}}}~\isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}\ {\isacharequal}\ t\isactrlsub {\isadigit{1}}\ {\isasymAND}\ {\isasymdots}\ x\isactrlsub n\ {\isacharequal}\ t\isactrlsub n{\isachardoublequote}}
   809   performs named instantiation of schematic type and term variables
   810   occurring in a theorem.  Schematic variables have to be specified on
   811   the left-hand side (e.g.\ \isa{{\isachardoublequote}{\isacharquery}x{\isadigit{1}}{\isachardot}{\isadigit{3}}{\isachardoublequote}}).  The question mark may
   812   be omitted if the variable name is a plain identifier without index.
   813   As type instantiations are inferred from term instantiations,
   814   explicit type instantiations are seldom necessary.
   815 
   816   \end{description}%
   817 \end{isamarkuptext}%
   818 \isamarkuptrue%
   819 %
   820 \isamarkupsubsection{Emulating tactic scripts \label{sec:tactic-commands}%
   821 }
   822 \isamarkuptrue%
   823 %
   824 \begin{isamarkuptext}%
   825 The Isar provides separate commands to accommodate tactic-style
   826   proof scripts within the same system.  While being outside the
   827   orthodox Isar proof language, these might come in handy for
   828   interactive exploration and debugging, or even actual tactical proof
   829   within new-style theories (to benefit from document preparation, for
   830   example).  See also \secref{sec:tactics} for actual tactics, that
   831   have been encapsulated as proof methods.  Proper proof methods may
   832   be used in scripts, too.
   833 
   834   \begin{matharray}{rcl}
   835     \indexdef{}{command}{apply}\hypertarget{command.apply}{\hyperlink{command.apply}{\mbox{\isa{\isacommand{apply}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}prove{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} \\
   836     \indexdef{}{command}{apply\_end}\hypertarget{command.apply-end}{\hyperlink{command.apply-end}{\mbox{\isa{\isacommand{apply{\isacharunderscore}end}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
   837     \indexdef{}{command}{done}\hypertarget{command.done}{\hyperlink{command.done}{\mbox{\isa{\isacommand{done}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}prove{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}\ {\isacharbar}\ local{\isacharunderscore}theory\ {\isacharbar}\ theory{\isachardoublequote}} \\
   838     \indexdef{}{command}{defer}\hypertarget{command.defer}{\hyperlink{command.defer}{\mbox{\isa{\isacommand{defer}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}proof\ {\isasymrightarrow}\ proof{\isachardoublequote}} \\
   839     \indexdef{}{command}{prefer}\hypertarget{command.prefer}{\hyperlink{command.prefer}{\mbox{\isa{\isacommand{prefer}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}proof\ {\isasymrightarrow}\ proof{\isachardoublequote}} \\
   840     \indexdef{}{command}{back}\hypertarget{command.back}{\hyperlink{command.back}{\mbox{\isa{\isacommand{back}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}proof\ {\isasymrightarrow}\ proof{\isachardoublequote}} \\
   841   \end{matharray}
   842 
   843   \begin{rail}
   844     ( 'apply' | 'apply\_end' ) method
   845     ;
   846     'defer' nat?
   847     ;
   848     'prefer' nat
   849     ;
   850   \end{rail}
   851 
   852   \begin{description}
   853 
   854   \item \hyperlink{command.apply}{\mbox{\isa{\isacommand{apply}}}}~\isa{m} applies proof method \isa{m} in
   855   initial position, but unlike \hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}} it retains ``\isa{{\isachardoublequote}proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}}'' mode.  Thus consecutive method applications may be
   856   given just as in tactic scripts.
   857   
   858   Facts are passed to \isa{m} as indicated by the goal's
   859   forward-chain mode, and are \emph{consumed} afterwards.  Thus any
   860   further \hyperlink{command.apply}{\mbox{\isa{\isacommand{apply}}}} command would always work in a purely
   861   backward manner.
   862   
   863   \item \hyperlink{command.apply-end}{\mbox{\isa{\isacommand{apply{\isacharunderscore}end}}}}~\isa{{\isachardoublequote}m{\isachardoublequote}} applies proof method \isa{m} as if in terminal position.  Basically, this simulates a
   864   multi-step tactic script for \hyperlink{command.qed}{\mbox{\isa{\isacommand{qed}}}}, but may be given
   865   anywhere within the proof body.
   866   
   867   No facts are passed to \isa{m} here.  Furthermore, the static
   868   context is that of the enclosing goal (as for actual \hyperlink{command.qed}{\mbox{\isa{\isacommand{qed}}}}).  Thus the proof method may not refer to any assumptions
   869   introduced in the current body, for example.
   870   
   871   \item \hyperlink{command.done}{\mbox{\isa{\isacommand{done}}}} completes a proof script, provided that the
   872   current goal state is solved completely.  Note that actual
   873   structured proof commands (e.g.\ ``\hyperlink{command.dot}{\mbox{\isa{\isacommand{{\isachardot}}}}}'' or \hyperlink{command.sorry}{\mbox{\isa{\isacommand{sorry}}}}) may be used to conclude proof scripts as well.
   874 
   875   \item \hyperlink{command.defer}{\mbox{\isa{\isacommand{defer}}}}~\isa{n} and \hyperlink{command.prefer}{\mbox{\isa{\isacommand{prefer}}}}~\isa{n}
   876   shuffle the list of pending goals: \hyperlink{command.defer}{\mbox{\isa{\isacommand{defer}}}} puts off
   877   sub-goal \isa{n} to the end of the list (\isa{{\isachardoublequote}n\ {\isacharequal}\ {\isadigit{1}}{\isachardoublequote}} by
   878   default), while \hyperlink{command.prefer}{\mbox{\isa{\isacommand{prefer}}}} brings sub-goal \isa{n} to the
   879   front.
   880   
   881   \item \hyperlink{command.back}{\mbox{\isa{\isacommand{back}}}} does back-tracking over the result sequence
   882   of the latest proof command.  Basically, any proof command may
   883   return multiple results.
   884   
   885   \end{description}
   886 
   887   Any proper Isar proof method may be used with tactic script commands
   888   such as \hyperlink{command.apply}{\mbox{\isa{\isacommand{apply}}}}.  A few additional emulations of actual
   889   tactics are provided as well; these would be never used in actual
   890   structured proofs, of course.%
   891 \end{isamarkuptext}%
   892 \isamarkuptrue%
   893 %
   894 \isamarkupsubsection{Defining proof methods%
   895 }
   896 \isamarkuptrue%
   897 %
   898 \begin{isamarkuptext}%
   899 \begin{matharray}{rcl}
   900     \indexdef{}{command}{method\_setup}\hypertarget{command.method-setup}{\hyperlink{command.method-setup}{\mbox{\isa{\isacommand{method{\isacharunderscore}setup}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
   901   \end{matharray}
   902 
   903   \begin{rail}
   904     'method\_setup' name '=' text text
   905     ;
   906   \end{rail}
   907 
   908   \begin{description}
   909 
   910   \item \hyperlink{command.method-setup}{\mbox{\isa{\isacommand{method{\isacharunderscore}setup}}}}~\isa{{\isachardoublequote}name\ {\isacharequal}\ text\ description{\isachardoublequote}}
   911   defines a proof method in the current theory.  The given \isa{{\isachardoublequote}text{\isachardoublequote}} has to be an ML expression of type \verb|Args.src -> Proof.context -> Proof.method|.  Parsing concrete
   912   method syntax from \verb|Args.src| input can be quite tedious in
   913   general.  The following simple examples are for methods without any
   914   explicit arguments, or a list of theorems, respectively.
   915 
   916 %FIXME proper antiquotations
   917 {\footnotesize
   918 \begin{verbatim}
   919  Method.no_args (Method.METHOD (fn facts => foobar_tac))
   920  Method.thms_args (fn thms => Method.METHOD (fn facts => foobar_tac))
   921  Method.ctxt_args (fn ctxt => Method.METHOD (fn facts => foobar_tac))
   922  Method.thms_ctxt_args (fn thms => fn ctxt =>
   923     Method.METHOD (fn facts => foobar_tac))
   924 \end{verbatim}
   925 }
   926 
   927   Note that mere tactic emulations may ignore the \isa{facts}
   928   parameter above.  Proper proof methods would do something
   929   appropriate with the list of current facts, though.  Single-rule
   930   methods usually do strict forward-chaining (e.g.\ by using \verb|Drule.multi_resolves|), while automatic ones just insert the facts
   931   using \verb|Method.insert_tac| before applying the main tactic.
   932 
   933   \end{description}%
   934 \end{isamarkuptext}%
   935 \isamarkuptrue%
   936 %
   937 \isamarkupsection{Generalized elimination \label{sec:obtain}%
   938 }
   939 \isamarkuptrue%
   940 %
   941 \begin{isamarkuptext}%
   942 \begin{matharray}{rcl}
   943     \indexdef{}{command}{obtain}\hypertarget{command.obtain}{\hyperlink{command.obtain}{\mbox{\isa{\isacommand{obtain}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isacharbar}\ proof{\isacharparenleft}chain{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} \\
   944     \indexdef{}{command}{guess}\hypertarget{command.guess}{\hyperlink{command.guess}{\mbox{\isa{\isacommand{guess}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isacharbar}\ proof{\isacharparenleft}chain{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}prove{\isacharparenright}{\isachardoublequote}} \\
   945   \end{matharray}
   946 
   947   Generalized elimination means that additional elements with certain
   948   properties may be introduced in the current context, by virtue of a
   949   locally proven ``soundness statement''.  Technically speaking, the
   950   \hyperlink{command.obtain}{\mbox{\isa{\isacommand{obtain}}}} language element is like a declaration of
   951   \hyperlink{command.fix}{\mbox{\isa{\isacommand{fix}}}} and \hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}} (see also see
   952   \secref{sec:proof-context}), together with a soundness proof of its
   953   additional claim.  According to the nature of existential reasoning,
   954   assumptions get eliminated from any result exported from the context
   955   later, provided that the corresponding parameters do \emph{not}
   956   occur in the conclusion.
   957 
   958   \begin{rail}
   959     'obtain' parname? (vars + 'and') 'where' (props + 'and')
   960     ;
   961     'guess' (vars + 'and')
   962     ;
   963   \end{rail}
   964 
   965   The derived Isar command \hyperlink{command.obtain}{\mbox{\isa{\isacommand{obtain}}}} is defined as follows
   966   (where \isa{{\isachardoublequote}b\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ b\isactrlsub k{\isachardoublequote}} shall refer to (optional)
   967   facts indicated for forward chaining).
   968   \begin{matharray}{l}
   969     \isa{{\isachardoublequote}{\isasymlangle}using\ b\isactrlsub {\isadigit{1}}\ {\isasymdots}\ b\isactrlsub k{\isasymrangle}{\isachardoublequote}}~~\hyperlink{command.obtain}{\mbox{\isa{\isacommand{obtain}}}}~\isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m\ {\isasymWHERE}\ a{\isacharcolon}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymdots}\ {\isasymphi}\isactrlsub n\ \ {\isasymlangle}proof{\isasymrangle}\ {\isasymequiv}{\isachardoublequote}} \\[1ex]
   970     \quad \hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}}~\isa{{\isachardoublequote}{\isasymAnd}thesis{\isachardot}\ {\isacharparenleft}{\isasymAnd}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardot}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymphi}\isactrlsub n\ {\isasymLongrightarrow}\ thesis{\isacharparenright}\ {\isasymLongrightarrow}\ thesis{\isachardoublequote}} \\
   971     \quad \hyperlink{command.proof}{\mbox{\isa{\isacommand{proof}}}}~\hyperlink{method.succeed}{\mbox{\isa{succeed}}} \\
   972     \qquad \hyperlink{command.fix}{\mbox{\isa{\isacommand{fix}}}}~\isa{thesis} \\
   973     \qquad \hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}~\isa{{\isachardoublequote}that\ {\isacharbrackleft}Pure{\isachardot}intro{\isacharquery}{\isacharbrackright}{\isacharcolon}\ {\isasymAnd}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardot}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymphi}\isactrlsub n\ {\isasymLongrightarrow}\ thesis{\isachardoublequote}} \\
   974     \qquad \hyperlink{command.then}{\mbox{\isa{\isacommand{then}}}}~\hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}}~\isa{thesis} \\
   975     \quad\qquad \hyperlink{command.apply}{\mbox{\isa{\isacommand{apply}}}}~\isa{{\isacharminus}} \\
   976     \quad\qquad \hyperlink{command.using}{\mbox{\isa{\isacommand{using}}}}~\isa{{\isachardoublequote}b\isactrlsub {\isadigit{1}}\ {\isasymdots}\ b\isactrlsub k\ \ {\isasymlangle}proof{\isasymrangle}{\isachardoublequote}} \\
   977     \quad \hyperlink{command.qed}{\mbox{\isa{\isacommand{qed}}}} \\
   978     \quad \hyperlink{command.fix}{\mbox{\isa{\isacommand{fix}}}}~\isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardoublequote}}~\hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}\ a{\isacharcolon}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymdots}\ {\isasymphi}\isactrlsub n{\isachardoublequote}} \\
   979   \end{matharray}
   980 
   981   Typically, the soundness proof is relatively straight-forward, often
   982   just by canonical automated tools such as ``\hyperlink{command.by}{\mbox{\isa{\isacommand{by}}}}~\isa{simp}'' or ``\hyperlink{command.by}{\mbox{\isa{\isacommand{by}}}}~\isa{blast}''.  Accordingly, the
   983   ``\isa{that}'' reduction above is declared as simplification and
   984   introduction rule.
   985 
   986   In a sense, \hyperlink{command.obtain}{\mbox{\isa{\isacommand{obtain}}}} represents at the level of Isar
   987   proofs what would be meta-logical existential quantifiers and
   988   conjunctions.  This concept has a broad range of useful
   989   applications, ranging from plain elimination (or introduction) of
   990   object-level existential and conjunctions, to elimination over
   991   results of symbolic evaluation of recursive definitions, for
   992   example.  Also note that \hyperlink{command.obtain}{\mbox{\isa{\isacommand{obtain}}}} without parameters acts
   993   much like \hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}}, where the result is treated as a
   994   genuine assumption.
   995 
   996   An alternative name to be used instead of ``\isa{that}'' above may
   997   be given in parentheses.
   998 
   999   \medskip The improper variant \hyperlink{command.guess}{\mbox{\isa{\isacommand{guess}}}} is similar to
  1000   \hyperlink{command.obtain}{\mbox{\isa{\isacommand{obtain}}}}, but derives the obtained statement from the
  1001   course of reasoning!  The proof starts with a fixed goal \isa{thesis}.  The subsequent proof may refine this to anything of the
  1002   form like \isa{{\isachardoublequote}{\isasymAnd}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardot}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymphi}\isactrlsub n\ {\isasymLongrightarrow}\ thesis{\isachardoublequote}}, but must not introduce new subgoals.  The
  1003   final goal state is then used as reduction rule for the obtain
  1004   scheme described above.  Obtained parameters \isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub m{\isachardoublequote}} are marked as internal by default, which prevents the
  1005   proof context from being polluted by ad-hoc variables.  The variable
  1006   names and type constraints given as arguments for \hyperlink{command.guess}{\mbox{\isa{\isacommand{guess}}}}
  1007   specify a prefix of obtained parameters explicitly in the text.
  1008 
  1009   It is important to note that the facts introduced by \hyperlink{command.obtain}{\mbox{\isa{\isacommand{obtain}}}} and \hyperlink{command.guess}{\mbox{\isa{\isacommand{guess}}}} may not be polymorphic: any
  1010   type-variables occurring here are fixed in the present context!%
  1011 \end{isamarkuptext}%
  1012 \isamarkuptrue%
  1013 %
  1014 \isamarkupsection{Calculational reasoning \label{sec:calculation}%
  1015 }
  1016 \isamarkuptrue%
  1017 %
  1018 \begin{isamarkuptext}%
  1019 \begin{matharray}{rcl}
  1020     \indexdef{}{command}{also}\hypertarget{command.also}{\hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
  1021     \indexdef{}{command}{finally}\hypertarget{command.finally}{\hyperlink{command.finally}{\mbox{\isa{\isacommand{finally}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}chain{\isacharparenright}{\isachardoublequote}} \\
  1022     \indexdef{}{command}{moreover}\hypertarget{command.moreover}{\hyperlink{command.moreover}{\mbox{\isa{\isacommand{moreover}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
  1023     \indexdef{}{command}{ultimately}\hypertarget{command.ultimately}{\hyperlink{command.ultimately}{\mbox{\isa{\isacommand{ultimately}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}chain{\isacharparenright}{\isachardoublequote}} \\
  1024     \indexdef{}{command}{print\_trans\_rules}\hypertarget{command.print-trans-rules}{\hyperlink{command.print-trans-rules}{\mbox{\isa{\isacommand{print{\isacharunderscore}trans{\isacharunderscore}rules}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
  1025     \hyperlink{attribute.trans}{\mbox{\isa{trans}}} & : & \isa{attribute} \\
  1026     \hyperlink{attribute.sym}{\mbox{\isa{sym}}} & : & \isa{attribute} \\
  1027     \hyperlink{attribute.symmetric}{\mbox{\isa{symmetric}}} & : & \isa{attribute} \\
  1028   \end{matharray}
  1029 
  1030   Calculational proof is forward reasoning with implicit application
  1031   of transitivity rules (such those of \isa{{\isachardoublequote}{\isacharequal}{\isachardoublequote}}, \isa{{\isachardoublequote}{\isasymle}{\isachardoublequote}},
  1032   \isa{{\isachardoublequote}{\isacharless}{\isachardoublequote}}).  Isabelle/Isar maintains an auxiliary fact register
  1033   \indexref{}{fact}{calculation}\hyperlink{fact.calculation}{\mbox{\isa{calculation}}} for accumulating results obtained by
  1034   transitivity composed with the current result.  Command \hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}} updates \hyperlink{fact.calculation}{\mbox{\isa{calculation}}} involving \hyperlink{fact.this}{\mbox{\isa{this}}}, while
  1035   \hyperlink{command.finally}{\mbox{\isa{\isacommand{finally}}}} exhibits the final \hyperlink{fact.calculation}{\mbox{\isa{calculation}}} by
  1036   forward chaining towards the next goal statement.  Both commands
  1037   require valid current facts, i.e.\ may occur only after commands
  1038   that produce theorems such as \hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}, \hyperlink{command.note}{\mbox{\isa{\isacommand{note}}}}, or some finished proof of \hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}}, \hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}} etc.  The \hyperlink{command.moreover}{\mbox{\isa{\isacommand{moreover}}}} and \hyperlink{command.ultimately}{\mbox{\isa{\isacommand{ultimately}}}}
  1039   commands are similar to \hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}} and \hyperlink{command.finally}{\mbox{\isa{\isacommand{finally}}}},
  1040   but only collect further results in \hyperlink{fact.calculation}{\mbox{\isa{calculation}}} without
  1041   applying any rules yet.
  1042 
  1043   Also note that the implicit term abbreviation ``\isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}'' has
  1044   its canonical application with calculational proofs.  It refers to
  1045   the argument of the preceding statement. (The argument of a curried
  1046   infix expression happens to be its right-hand side.)
  1047 
  1048   Isabelle/Isar calculations are implicitly subject to block structure
  1049   in the sense that new threads of calculational reasoning are
  1050   commenced for any new block (as opened by a local goal, for
  1051   example).  This means that, apart from being able to nest
  1052   calculations, there is no separate \emph{begin-calculation} command
  1053   required.
  1054 
  1055   \medskip The Isar calculation proof commands may be defined as
  1056   follows:\footnote{We suppress internal bookkeeping such as proper
  1057   handling of block-structure.}
  1058 
  1059   \begin{matharray}{rcl}
  1060     \hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}}\isa{{\isachardoublequote}\isactrlsub {\isadigit{0}}{\isachardoublequote}} & \equiv & \hyperlink{command.note}{\mbox{\isa{\isacommand{note}}}}~\isa{{\isachardoublequote}calculation\ {\isacharequal}\ this{\isachardoublequote}} \\
  1061     \hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}}\isa{{\isachardoublequote}\isactrlsub n\isactrlsub {\isacharplus}\isactrlsub {\isadigit{1}}{\isachardoublequote}} & \equiv & \hyperlink{command.note}{\mbox{\isa{\isacommand{note}}}}~\isa{{\isachardoublequote}calculation\ {\isacharequal}\ trans\ {\isacharbrackleft}OF\ calculation\ this{\isacharbrackright}{\isachardoublequote}} \\[0.5ex]
  1062     \hyperlink{command.finally}{\mbox{\isa{\isacommand{finally}}}} & \equiv & \hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}}~\hyperlink{command.from}{\mbox{\isa{\isacommand{from}}}}~\isa{calculation} \\[0.5ex]
  1063     \hyperlink{command.moreover}{\mbox{\isa{\isacommand{moreover}}}} & \equiv & \hyperlink{command.note}{\mbox{\isa{\isacommand{note}}}}~\isa{{\isachardoublequote}calculation\ {\isacharequal}\ calculation\ this{\isachardoublequote}} \\
  1064     \hyperlink{command.ultimately}{\mbox{\isa{\isacommand{ultimately}}}} & \equiv & \hyperlink{command.moreover}{\mbox{\isa{\isacommand{moreover}}}}~\hyperlink{command.from}{\mbox{\isa{\isacommand{from}}}}~\isa{calculation} \\
  1065   \end{matharray}
  1066 
  1067   \begin{rail}
  1068     ('also' | 'finally') ('(' thmrefs ')')?
  1069     ;
  1070     'trans' (() | 'add' | 'del')
  1071     ;
  1072   \end{rail}
  1073 
  1074   \begin{description}
  1075 
  1076   \item \hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}}~\isa{{\isachardoublequote}{\isacharparenleft}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isacharparenright}{\isachardoublequote}} maintains the auxiliary
  1077   \hyperlink{fact.calculation}{\mbox{\isa{calculation}}} register as follows.  The first occurrence of
  1078   \hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}} in some calculational thread initializes \hyperlink{fact.calculation}{\mbox{\isa{calculation}}} by \hyperlink{fact.this}{\mbox{\isa{this}}}. Any subsequent \hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}} on
  1079   the same level of block-structure updates \hyperlink{fact.calculation}{\mbox{\isa{calculation}}} by
  1080   some transitivity rule applied to \hyperlink{fact.calculation}{\mbox{\isa{calculation}}} and \hyperlink{fact.this}{\mbox{\isa{this}}} (in that order).  Transitivity rules are picked from the
  1081   current context, unless alternative rules are given as explicit
  1082   arguments.
  1083 
  1084   \item \hyperlink{command.finally}{\mbox{\isa{\isacommand{finally}}}}~\isa{{\isachardoublequote}{\isacharparenleft}a\isactrlsub {\isadigit{1}}\ {\isasymdots}\ a\isactrlsub n{\isacharparenright}{\isachardoublequote}} maintaining \hyperlink{fact.calculation}{\mbox{\isa{calculation}}} in the same way as \hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}}, and concludes the
  1085   current calculational thread.  The final result is exhibited as fact
  1086   for forward chaining towards the next goal. Basically, \hyperlink{command.finally}{\mbox{\isa{\isacommand{finally}}}} just abbreviates \hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}}~\hyperlink{command.from}{\mbox{\isa{\isacommand{from}}}}~\hyperlink{fact.calculation}{\mbox{\isa{calculation}}}.  Typical idioms for concluding
  1087   calculational proofs are ``\hyperlink{command.finally}{\mbox{\isa{\isacommand{finally}}}}~\hyperlink{command.show}{\mbox{\isa{\isacommand{show}}}}~\isa{{\isacharquery}thesis}~\hyperlink{command.dot}{\mbox{\isa{\isacommand{{\isachardot}}}}}'' and ``\hyperlink{command.finally}{\mbox{\isa{\isacommand{finally}}}}~\hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}}~\isa{{\isasymphi}}~\hyperlink{command.dot}{\mbox{\isa{\isacommand{{\isachardot}}}}}''.
  1088 
  1089   \item \hyperlink{command.moreover}{\mbox{\isa{\isacommand{moreover}}}} and \hyperlink{command.ultimately}{\mbox{\isa{\isacommand{ultimately}}}} are
  1090   analogous to \hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}} and \hyperlink{command.finally}{\mbox{\isa{\isacommand{finally}}}}, but collect
  1091   results only, without applying rules.
  1092 
  1093   \item \hyperlink{command.print-trans-rules}{\mbox{\isa{\isacommand{print{\isacharunderscore}trans{\isacharunderscore}rules}}}} prints the list of transitivity
  1094   rules (for calculational commands \hyperlink{command.also}{\mbox{\isa{\isacommand{also}}}} and \hyperlink{command.finally}{\mbox{\isa{\isacommand{finally}}}}) and symmetry rules (for the \hyperlink{attribute.symmetric}{\mbox{\isa{symmetric}}}
  1095   operation and single step elimination patters) of the current
  1096   context.
  1097 
  1098   \item \hyperlink{attribute.trans}{\mbox{\isa{trans}}} declares theorems as transitivity rules.
  1099 
  1100   \item \hyperlink{attribute.sym}{\mbox{\isa{sym}}} declares symmetry rules, as well as
  1101   \hyperlink{attribute.Pure.elim}{\mbox{\isa{Pure{\isachardot}elim}}}\isa{{\isachardoublequote}{\isacharquery}{\isachardoublequote}} rules.
  1102 
  1103   \item \hyperlink{attribute.symmetric}{\mbox{\isa{symmetric}}} resolves a theorem with some rule
  1104   declared as \hyperlink{attribute.sym}{\mbox{\isa{sym}}} in the current context.  For example,
  1105   ``\hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}~\isa{{\isachardoublequote}{\isacharbrackleft}symmetric{\isacharbrackright}{\isacharcolon}\ x\ {\isacharequal}\ y{\isachardoublequote}}'' produces a
  1106   swapped fact derived from that assumption.
  1107 
  1108   In structured proof texts it is often more appropriate to use an
  1109   explicit single-step elimination proof, such as ``\hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}~\isa{{\isachardoublequote}x\ {\isacharequal}\ y{\isachardoublequote}}~\hyperlink{command.then}{\mbox{\isa{\isacommand{then}}}}~\hyperlink{command.have}{\mbox{\isa{\isacommand{have}}}}~\isa{{\isachardoublequote}y\ {\isacharequal}\ x{\isachardoublequote}}~\hyperlink{command.ddot}{\mbox{\isa{\isacommand{{\isachardot}{\isachardot}}}}}''.
  1110 
  1111   \end{description}%
  1112 \end{isamarkuptext}%
  1113 \isamarkuptrue%
  1114 %
  1115 \isamarkupsection{Proof by cases and induction \label{sec:cases-induct}%
  1116 }
  1117 \isamarkuptrue%
  1118 %
  1119 \isamarkupsubsection{Rule contexts%
  1120 }
  1121 \isamarkuptrue%
  1122 %
  1123 \begin{isamarkuptext}%
  1124 \begin{matharray}{rcl}
  1125     \indexdef{}{command}{case}\hypertarget{command.case}{\hyperlink{command.case}{\mbox{\isa{\isacommand{case}}}}} & : & \isa{{\isachardoublequote}proof{\isacharparenleft}state{\isacharparenright}\ {\isasymrightarrow}\ proof{\isacharparenleft}state{\isacharparenright}{\isachardoublequote}} \\
  1126     \indexdef{}{command}{print\_cases}\hypertarget{command.print-cases}{\hyperlink{command.print-cases}{\mbox{\isa{\isacommand{print{\isacharunderscore}cases}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
  1127     \indexdef{}{attribute}{case\_names}\hypertarget{attribute.case-names}{\hyperlink{attribute.case-names}{\mbox{\isa{case{\isacharunderscore}names}}}} & : & \isa{attribute} \\
  1128     \indexdef{}{attribute}{case\_conclusion}\hypertarget{attribute.case-conclusion}{\hyperlink{attribute.case-conclusion}{\mbox{\isa{case{\isacharunderscore}conclusion}}}} & : & \isa{attribute} \\
  1129     \indexdef{}{attribute}{params}\hypertarget{attribute.params}{\hyperlink{attribute.params}{\mbox{\isa{params}}}} & : & \isa{attribute} \\
  1130     \indexdef{}{attribute}{consumes}\hypertarget{attribute.consumes}{\hyperlink{attribute.consumes}{\mbox{\isa{consumes}}}} & : & \isa{attribute} \\
  1131   \end{matharray}
  1132 
  1133   The puristic way to build up Isar proof contexts is by explicit
  1134   language elements like \hyperlink{command.fix}{\mbox{\isa{\isacommand{fix}}}}, \hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}},
  1135   \hyperlink{command.let}{\mbox{\isa{\isacommand{let}}}} (see \secref{sec:proof-context}).  This is adequate
  1136   for plain natural deduction, but easily becomes unwieldy in concrete
  1137   verification tasks, which typically involve big induction rules with
  1138   several cases.
  1139 
  1140   The \hyperlink{command.case}{\mbox{\isa{\isacommand{case}}}} command provides a shorthand to refer to a
  1141   local context symbolically: certain proof methods provide an
  1142   environment of named ``cases'' of the form \isa{{\isachardoublequote}c{\isacharcolon}\ x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub m{\isacharcomma}\ {\isasymphi}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymphi}\isactrlsub n{\isachardoublequote}}; the effect of ``\hyperlink{command.case}{\mbox{\isa{\isacommand{case}}}}~\isa{c}'' is then equivalent to ``\hyperlink{command.fix}{\mbox{\isa{\isacommand{fix}}}}~\isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardoublequote}}~\hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}~\isa{{\isachardoublequote}c{\isacharcolon}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymdots}\ {\isasymphi}\isactrlsub n{\isachardoublequote}}''.  Term bindings may be covered as well, notably
  1143   \hyperlink{variable.?case}{\mbox{\isa{{\isacharquery}case}}} for the main conclusion.
  1144 
  1145   By default, the ``terminology'' \isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub m{\isachardoublequote}} of
  1146   a case value is marked as hidden, i.e.\ there is no way to refer to
  1147   such parameters in the subsequent proof text.  After all, original
  1148   rule parameters stem from somewhere outside of the current proof
  1149   text.  By using the explicit form ``\hyperlink{command.case}{\mbox{\isa{\isacommand{case}}}}~\isa{{\isachardoublequote}{\isacharparenleft}c\ y\isactrlsub {\isadigit{1}}\ {\isasymdots}\ y\isactrlsub m{\isacharparenright}{\isachardoublequote}}'' instead, the proof author is able to
  1150   chose local names that fit nicely into the current context.
  1151 
  1152   \medskip It is important to note that proper use of \hyperlink{command.case}{\mbox{\isa{\isacommand{case}}}} does not provide means to peek at the current goal state,
  1153   which is not directly observable in Isar!  Nonetheless, goal
  1154   refinement commands do provide named cases \isa{{\isachardoublequote}goal\isactrlsub i{\isachardoublequote}}
  1155   for each subgoal \isa{{\isachardoublequote}i\ {\isacharequal}\ {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ n{\isachardoublequote}} of the resulting goal state.
  1156   Using this extra feature requires great care, because some bits of
  1157   the internal tactical machinery intrude the proof text.  In
  1158   particular, parameter names stemming from the left-over of automated
  1159   reasoning tools are usually quite unpredictable.
  1160 
  1161   Under normal circumstances, the text of cases emerge from standard
  1162   elimination or induction rules, which in turn are derived from
  1163   previous theory specifications in a canonical way (say from
  1164   \hyperlink{command.inductive}{\mbox{\isa{\isacommand{inductive}}}} definitions).
  1165 
  1166   \medskip Proper cases are only available if both the proof method
  1167   and the rules involved support this.  By using appropriate
  1168   attributes, case names, conclusions, and parameters may be also
  1169   declared by hand.  Thus variant versions of rules that have been
  1170   derived manually become ready to use in advanced case analysis
  1171   later.
  1172 
  1173   \begin{rail}
  1174     'case' (caseref | '(' caseref ((name | underscore) +) ')')
  1175     ;
  1176     caseref: nameref attributes?
  1177     ;
  1178 
  1179     'case\_names' (name +)
  1180     ;
  1181     'case\_conclusion' name (name *)
  1182     ;
  1183     'params' ((name *) + 'and')
  1184     ;
  1185     'consumes' nat?
  1186     ;
  1187   \end{rail}
  1188 
  1189   \begin{description}
  1190   
  1191   \item \hyperlink{command.case}{\mbox{\isa{\isacommand{case}}}}~\isa{{\isachardoublequote}{\isacharparenleft}c\ x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isacharparenright}{\isachardoublequote}} invokes a named local
  1192   context \isa{{\isachardoublequote}c{\isacharcolon}\ x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub m{\isacharcomma}\ {\isasymphi}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymphi}\isactrlsub m{\isachardoublequote}}, as provided by an
  1193   appropriate proof method (such as \indexref{}{method}{cases}\hyperlink{method.cases}{\mbox{\isa{cases}}} and
  1194   \indexref{}{method}{induct}\hyperlink{method.induct}{\mbox{\isa{induct}}}).  The command ``\hyperlink{command.case}{\mbox{\isa{\isacommand{case}}}}~\isa{{\isachardoublequote}{\isacharparenleft}c\ x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isacharparenright}{\isachardoublequote}}'' abbreviates ``\hyperlink{command.fix}{\mbox{\isa{\isacommand{fix}}}}~\isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardoublequote}}~\hyperlink{command.assume}{\mbox{\isa{\isacommand{assume}}}}~\isa{{\isachardoublequote}c{\isacharcolon}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymdots}\ {\isasymphi}\isactrlsub n{\isachardoublequote}}''.
  1195 
  1196   \item \hyperlink{command.print-cases}{\mbox{\isa{\isacommand{print{\isacharunderscore}cases}}}} prints all local contexts of the
  1197   current state, using Isar proof language notation.
  1198   
  1199   \item \hyperlink{attribute.case-names}{\mbox{\isa{case{\isacharunderscore}names}}}~\isa{{\isachardoublequote}c\isactrlsub {\isadigit{1}}\ {\isasymdots}\ c\isactrlsub k{\isachardoublequote}} declares names for
  1200   the local contexts of premises of a theorem; \isa{{\isachardoublequote}c\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ c\isactrlsub k{\isachardoublequote}}
  1201   refers to the \emph{suffix} of the list of premises.
  1202   
  1203   \item \hyperlink{attribute.case-conclusion}{\mbox{\isa{case{\isacharunderscore}conclusion}}}~\isa{{\isachardoublequote}c\ d\isactrlsub {\isadigit{1}}\ {\isasymdots}\ d\isactrlsub k{\isachardoublequote}} declares
  1204   names for the conclusions of a named premise \isa{c}; here \isa{{\isachardoublequote}d\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ d\isactrlsub k{\isachardoublequote}} refers to the prefix of arguments of a logical formula
  1205   built by nesting a binary connective (e.g.\ \isa{{\isachardoublequote}{\isasymor}{\isachardoublequote}}).
  1206   
  1207   Note that proof methods such as \hyperlink{method.induct}{\mbox{\isa{induct}}} and \hyperlink{method.coinduct}{\mbox{\isa{coinduct}}} already provide a default name for the conclusion as a
  1208   whole.  The need to name subformulas only arises with cases that
  1209   split into several sub-cases, as in common co-induction rules.
  1210 
  1211   \item \hyperlink{attribute.params}{\mbox{\isa{params}}}~\isa{{\isachardoublequote}p\isactrlsub {\isadigit{1}}\ {\isasymdots}\ p\isactrlsub m\ {\isasymAND}\ {\isasymdots}\ q\isactrlsub {\isadigit{1}}\ {\isasymdots}\ q\isactrlsub n{\isachardoublequote}} renames
  1212   the innermost parameters of premises \isa{{\isachardoublequote}{\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ n{\isachardoublequote}} of some
  1213   theorem.  An empty list of names may be given to skip positions,
  1214   leaving the present parameters unchanged.
  1215   
  1216   Note that the default usage of case rules does \emph{not} directly
  1217   expose parameters to the proof context.
  1218   
  1219   \item \hyperlink{attribute.consumes}{\mbox{\isa{consumes}}}~\isa{n} declares the number of ``major
  1220   premises'' of a rule, i.e.\ the number of facts to be consumed when
  1221   it is applied by an appropriate proof method.  The default value of
  1222   \hyperlink{attribute.consumes}{\mbox{\isa{consumes}}} is \isa{{\isachardoublequote}n\ {\isacharequal}\ {\isadigit{1}}{\isachardoublequote}}, which is appropriate for
  1223   the usual kind of cases and induction rules for inductive sets (cf.\
  1224   \secref{sec:hol-inductive}).  Rules without any \hyperlink{attribute.consumes}{\mbox{\isa{consumes}}} declaration given are treated as if \hyperlink{attribute.consumes}{\mbox{\isa{consumes}}}~\isa{{\isadigit{0}}} had been specified.
  1225   
  1226   Note that explicit \hyperlink{attribute.consumes}{\mbox{\isa{consumes}}} declarations are only
  1227   rarely needed; this is already taken care of automatically by the
  1228   higher-level \hyperlink{attribute.cases}{\mbox{\isa{cases}}}, \hyperlink{attribute.induct}{\mbox{\isa{induct}}}, and
  1229   \hyperlink{attribute.coinduct}{\mbox{\isa{coinduct}}} declarations.
  1230 
  1231   \end{description}%
  1232 \end{isamarkuptext}%
  1233 \isamarkuptrue%
  1234 %
  1235 \isamarkupsubsection{Proof methods%
  1236 }
  1237 \isamarkuptrue%
  1238 %
  1239 \begin{isamarkuptext}%
  1240 \begin{matharray}{rcl}
  1241     \indexdef{}{method}{cases}\hypertarget{method.cases}{\hyperlink{method.cases}{\mbox{\isa{cases}}}} & : & \isa{method} \\
  1242     \indexdef{}{method}{induct}\hypertarget{method.induct}{\hyperlink{method.induct}{\mbox{\isa{induct}}}} & : & \isa{method} \\
  1243     \indexdef{}{method}{coinduct}\hypertarget{method.coinduct}{\hyperlink{method.coinduct}{\mbox{\isa{coinduct}}}} & : & \isa{method} \\
  1244   \end{matharray}
  1245 
  1246   The \hyperlink{method.cases}{\mbox{\isa{cases}}}, \hyperlink{method.induct}{\mbox{\isa{induct}}}, and \hyperlink{method.coinduct}{\mbox{\isa{coinduct}}}
  1247   methods provide a uniform interface to common proof techniques over
  1248   datatypes, inductive predicates (or sets), recursive functions etc.
  1249   The corresponding rules may be specified and instantiated in a
  1250   casual manner.  Furthermore, these methods provide named local
  1251   contexts that may be invoked via the \hyperlink{command.case}{\mbox{\isa{\isacommand{case}}}} proof command
  1252   within the subsequent proof text.  This accommodates compact proof
  1253   texts even when reasoning about large specifications.
  1254 
  1255   The \hyperlink{method.induct}{\mbox{\isa{induct}}} method also provides some additional
  1256   infrastructure in order to be applicable to structure statements
  1257   (either using explicit meta-level connectives, or including facts
  1258   and parameters separately).  This avoids cumbersome encoding of
  1259   ``strengthened'' inductive statements within the object-logic.
  1260 
  1261   \begin{rail}
  1262     'cases' (insts * 'and') rule?
  1263     ;
  1264     'induct' (definsts * 'and') \\ arbitrary? taking? rule?
  1265     ;
  1266     'coinduct' insts taking rule?
  1267     ;
  1268 
  1269     rule: ('type' | 'pred' | 'set') ':' (nameref +) | 'rule' ':' (thmref +)
  1270     ;
  1271     definst: name ('==' | equiv) term | inst
  1272     ;
  1273     definsts: ( definst *)
  1274     ;
  1275     arbitrary: 'arbitrary' ':' ((term *) 'and' +)
  1276     ;
  1277     taking: 'taking' ':' insts
  1278     ;
  1279   \end{rail}
  1280 
  1281   \begin{description}
  1282 
  1283   \item \hyperlink{method.cases}{\mbox{\isa{cases}}}~\isa{{\isachardoublequote}insts\ R{\isachardoublequote}} applies method \hyperlink{method.rule}{\mbox{\isa{rule}}} with an appropriate case distinction theorem, instantiated to
  1284   the subjects \isa{insts}.  Symbolic case names are bound according
  1285   to the rule's local contexts.
  1286 
  1287   The rule is determined as follows, according to the facts and
  1288   arguments passed to the \hyperlink{method.cases}{\mbox{\isa{cases}}} method:
  1289 
  1290   \medskip
  1291   \begin{tabular}{llll}
  1292     facts           &                 & arguments   & rule \\\hline
  1293                     & \hyperlink{method.cases}{\mbox{\isa{cases}}} &             & classical case split \\
  1294                     & \hyperlink{method.cases}{\mbox{\isa{cases}}} & \isa{t}   & datatype exhaustion (type of \isa{t}) \\
  1295     \isa{{\isachardoublequote}{\isasymturnstile}\ A\ t{\isachardoublequote}} & \hyperlink{method.cases}{\mbox{\isa{cases}}} & \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}} & inductive predicate/set elimination (of \isa{A}) \\
  1296     \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}     & \hyperlink{method.cases}{\mbox{\isa{cases}}} & \isa{{\isachardoublequote}{\isasymdots}\ rule{\isacharcolon}\ R{\isachardoublequote}} & explicit rule \isa{R} \\
  1297   \end{tabular}
  1298   \medskip
  1299 
  1300   Several instantiations may be given, referring to the \emph{suffix}
  1301   of premises of the case rule; within each premise, the \emph{prefix}
  1302   of variables is instantiated.  In most situations, only a single
  1303   term needs to be specified; this refers to the first variable of the
  1304   last premise (it is usually the same for all cases).
  1305 
  1306   \item \hyperlink{method.induct}{\mbox{\isa{induct}}}~\isa{{\isachardoublequote}insts\ R{\isachardoublequote}} is analogous to the
  1307   \hyperlink{method.cases}{\mbox{\isa{cases}}} method, but refers to induction rules, which are
  1308   determined as follows:
  1309 
  1310   \medskip
  1311   \begin{tabular}{llll}
  1312     facts           &                  & arguments            & rule \\\hline
  1313                     & \hyperlink{method.induct}{\mbox{\isa{induct}}} & \isa{{\isachardoublequote}P\ x{\isachardoublequote}}        & datatype induction (type of \isa{x}) \\
  1314     \isa{{\isachardoublequote}{\isasymturnstile}\ A\ x{\isachardoublequote}} & \hyperlink{method.induct}{\mbox{\isa{induct}}} & \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}          & predicate/set induction (of \isa{A}) \\
  1315     \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}     & \hyperlink{method.induct}{\mbox{\isa{induct}}} & \isa{{\isachardoublequote}{\isasymdots}\ rule{\isacharcolon}\ R{\isachardoublequote}} & explicit rule \isa{R} \\
  1316   \end{tabular}
  1317   \medskip
  1318   
  1319   Several instantiations may be given, each referring to some part of
  1320   a mutual inductive definition or datatype --- only related partial
  1321   induction rules may be used together, though.  Any of the lists of
  1322   terms \isa{{\isachardoublequote}P{\isacharcomma}\ x{\isacharcomma}\ {\isasymdots}{\isachardoublequote}} refers to the \emph{suffix} of variables
  1323   present in the induction rule.  This enables the writer to specify
  1324   only induction variables, or both predicates and variables, for
  1325   example.
  1326   
  1327   Instantiations may be definitional: equations \isa{{\isachardoublequote}x\ {\isasymequiv}\ t{\isachardoublequote}}
  1328   introduce local definitions, which are inserted into the claim and
  1329   discharged after applying the induction rule.  Equalities reappear
  1330   in the inductive cases, but have been transformed according to the
  1331   induction principle being involved here.  In order to achieve
  1332   practically useful induction hypotheses, some variables occurring in
  1333   \isa{t} need to be fixed (see below).
  1334   
  1335   The optional ``\isa{{\isachardoublequote}arbitrary{\isacharcolon}\ x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardoublequote}}''
  1336   specification generalizes variables \isa{{\isachardoublequote}x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub m{\isachardoublequote}} of the original goal before applying induction.  Thus
  1337   induction hypotheses may become sufficiently general to get the
  1338   proof through.  Together with definitional instantiations, one may
  1339   effectively perform induction over expressions of a certain
  1340   structure.
  1341   
  1342   The optional ``\isa{{\isachardoublequote}taking{\isacharcolon}\ t\isactrlsub {\isadigit{1}}\ {\isasymdots}\ t\isactrlsub n{\isachardoublequote}}''
  1343   specification provides additional instantiations of a prefix of
  1344   pending variables in the rule.  Such schematic induction rules
  1345   rarely occur in practice, though.
  1346 
  1347   \item \hyperlink{method.coinduct}{\mbox{\isa{coinduct}}}~\isa{{\isachardoublequote}inst\ R{\isachardoublequote}} is analogous to the
  1348   \hyperlink{method.induct}{\mbox{\isa{induct}}} method, but refers to coinduction rules, which are
  1349   determined as follows:
  1350 
  1351   \medskip
  1352   \begin{tabular}{llll}
  1353     goal          &                    & arguments & rule \\\hline
  1354                   & \hyperlink{method.coinduct}{\mbox{\isa{coinduct}}} & \isa{x} & type coinduction (type of \isa{x}) \\
  1355     \isa{{\isachardoublequote}A\ x{\isachardoublequote}} & \hyperlink{method.coinduct}{\mbox{\isa{coinduct}}} & \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}} & predicate/set coinduction (of \isa{A}) \\
  1356     \isa{{\isachardoublequote}{\isasymdots}{\isachardoublequote}}   & \hyperlink{method.coinduct}{\mbox{\isa{coinduct}}} & \isa{{\isachardoublequote}{\isasymdots}\ rule{\isacharcolon}\ R{\isachardoublequote}} & explicit rule \isa{R} \\
  1357   \end{tabular}
  1358   
  1359   Coinduction is the dual of induction.  Induction essentially
  1360   eliminates \isa{{\isachardoublequote}A\ x{\isachardoublequote}} towards a generic result \isa{{\isachardoublequote}P\ x{\isachardoublequote}},
  1361   while coinduction introduces \isa{{\isachardoublequote}A\ x{\isachardoublequote}} starting with \isa{{\isachardoublequote}B\ x{\isachardoublequote}}, for a suitable ``bisimulation'' \isa{B}.  The cases of a
  1362   coinduct rule are typically named after the predicates or sets being
  1363   covered, while the conclusions consist of several alternatives being
  1364   named after the individual destructor patterns.
  1365   
  1366   The given instantiation refers to the \emph{suffix} of variables
  1367   occurring in the rule's major premise, or conclusion if unavailable.
  1368   An additional ``\isa{{\isachardoublequote}taking{\isacharcolon}\ t\isactrlsub {\isadigit{1}}\ {\isasymdots}\ t\isactrlsub n{\isachardoublequote}}''
  1369   specification may be required in order to specify the bisimulation
  1370   to be used in the coinduction step.
  1371 
  1372   \end{description}
  1373 
  1374   Above methods produce named local contexts, as determined by the
  1375   instantiated rule as given in the text.  Beyond that, the \hyperlink{method.induct}{\mbox{\isa{induct}}} and \hyperlink{method.coinduct}{\mbox{\isa{coinduct}}} methods guess further instantiations
  1376   from the goal specification itself.  Any persisting unresolved
  1377   schematic variables of the resulting rule will render the the
  1378   corresponding case invalid.  The term binding \hyperlink{variable.?case}{\mbox{\isa{{\isacharquery}case}}} for
  1379   the conclusion will be provided with each case, provided that term
  1380   is fully specified.
  1381 
  1382   The \hyperlink{command.print-cases}{\mbox{\isa{\isacommand{print{\isacharunderscore}cases}}}} command prints all named cases present
  1383   in the current proof state.
  1384 
  1385   \medskip Despite the additional infrastructure, both \hyperlink{method.cases}{\mbox{\isa{cases}}}
  1386   and \hyperlink{method.coinduct}{\mbox{\isa{coinduct}}} merely apply a certain rule, after
  1387   instantiation, while conforming due to the usual way of monotonic
  1388   natural deduction: the context of a structured statement \isa{{\isachardoublequote}{\isasymAnd}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ x\isactrlsub m{\isachardot}\ {\isasymphi}\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymphi}\isactrlsub n\ {\isasymLongrightarrow}\ {\isasymdots}{\isachardoublequote}}
  1389   reappears unchanged after the case split.
  1390 
  1391   The \hyperlink{method.induct}{\mbox{\isa{induct}}} method is fundamentally different in this
  1392   respect: the meta-level structure is passed through the
  1393   ``recursive'' course involved in the induction.  Thus the original
  1394   statement is basically replaced by separate copies, corresponding to
  1395   the induction hypotheses and conclusion; the original goal context
  1396   is no longer available.  Thus local assumptions, fixed parameters
  1397   and definitions effectively participate in the inductive rephrasing
  1398   of the original statement.
  1399 
  1400   In induction proofs, local assumptions introduced by cases are split
  1401   into two different kinds: \isa{hyps} stemming from the rule and
  1402   \isa{prems} from the goal statement.  This is reflected in the
  1403   extracted cases accordingly, so invoking ``\hyperlink{command.case}{\mbox{\isa{\isacommand{case}}}}~\isa{c}'' will provide separate facts \isa{c{\isachardot}hyps} and \isa{c{\isachardot}prems},
  1404   as well as fact \isa{c} to hold the all-inclusive list.
  1405 
  1406   \medskip Facts presented to either method are consumed according to
  1407   the number of ``major premises'' of the rule involved, which is
  1408   usually 0 for plain cases and induction rules of datatypes etc.\ and
  1409   1 for rules of inductive predicates or sets and the like.  The
  1410   remaining facts are inserted into the goal verbatim before the
  1411   actual \isa{cases}, \isa{induct}, or \isa{coinduct} rule is
  1412   applied.%
  1413 \end{isamarkuptext}%
  1414 \isamarkuptrue%
  1415 %
  1416 \isamarkupsubsection{Declaring rules%
  1417 }
  1418 \isamarkuptrue%
  1419 %
  1420 \begin{isamarkuptext}%
  1421 \begin{matharray}{rcl}
  1422     \indexdef{}{command}{print\_induct\_rules}\hypertarget{command.print-induct-rules}{\hyperlink{command.print-induct-rules}{\mbox{\isa{\isacommand{print{\isacharunderscore}induct{\isacharunderscore}rules}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
  1423     \indexdef{}{attribute}{cases}\hypertarget{attribute.cases}{\hyperlink{attribute.cases}{\mbox{\isa{cases}}}} & : & \isa{attribute} \\
  1424     \indexdef{}{attribute}{induct}\hypertarget{attribute.induct}{\hyperlink{attribute.induct}{\mbox{\isa{induct}}}} & : & \isa{attribute} \\
  1425     \indexdef{}{attribute}{coinduct}\hypertarget{attribute.coinduct}{\hyperlink{attribute.coinduct}{\mbox{\isa{coinduct}}}} & : & \isa{attribute} \\
  1426   \end{matharray}
  1427 
  1428   \begin{rail}
  1429     'cases' spec
  1430     ;
  1431     'induct' spec
  1432     ;
  1433     'coinduct' spec
  1434     ;
  1435 
  1436     spec: (('type' | 'pred' | 'set') ':' nameref) | 'del'
  1437     ;
  1438   \end{rail}
  1439 
  1440   \begin{description}
  1441 
  1442   \item \hyperlink{command.print-induct-rules}{\mbox{\isa{\isacommand{print{\isacharunderscore}induct{\isacharunderscore}rules}}}} prints cases and induct rules
  1443   for predicates (or sets) and types of the current context.
  1444   
  1445   \item \hyperlink{attribute.cases}{\mbox{\isa{cases}}}, \hyperlink{attribute.induct}{\mbox{\isa{induct}}}, and \hyperlink{attribute.coinduct}{\mbox{\isa{coinduct}}} (as attributes) declare rules for reasoning about
  1446   (co)inductive predicates (or sets) and types, using the
  1447   corresponding methods of the same name.  Certain definitional
  1448   packages of object-logics usually declare emerging cases and
  1449   induction rules as expected, so users rarely need to intervene.
  1450 
  1451   Rules may be deleted via the \isa{{\isachardoublequote}del{\isachardoublequote}} specification, which
  1452   covers all of the \isa{{\isachardoublequote}type{\isachardoublequote}}/\isa{{\isachardoublequote}pred{\isachardoublequote}}/\isa{{\isachardoublequote}set{\isachardoublequote}}
  1453   sub-categories simultaneously.  For example, \hyperlink{attribute.cases}{\mbox{\isa{cases}}}~\isa{del} removes any \hyperlink{attribute.cases}{\mbox{\isa{cases}}} rules declared for
  1454   some type, predicate, or set.
  1455   
  1456   Manual rule declarations usually refer to the \hyperlink{attribute.case-names}{\mbox{\isa{case{\isacharunderscore}names}}} and \hyperlink{attribute.params}{\mbox{\isa{params}}} attributes to adjust names of
  1457   cases and parameters of a rule; the \hyperlink{attribute.consumes}{\mbox{\isa{consumes}}}
  1458   declaration is taken care of automatically: \hyperlink{attribute.consumes}{\mbox{\isa{consumes}}}~\isa{{\isadigit{0}}} is specified for ``type'' rules and \hyperlink{attribute.consumes}{\mbox{\isa{consumes}}}~\isa{{\isadigit{1}}} for ``predicate'' / ``set'' rules.
  1459 
  1460   \end{description}%
  1461 \end{isamarkuptext}%
  1462 \isamarkuptrue%
  1463 %
  1464 \isadelimtheory
  1465 %
  1466 \endisadelimtheory
  1467 %
  1468 \isatagtheory
  1469 \isacommand{end}\isamarkupfalse%
  1470 %
  1471 \endisatagtheory
  1472 {\isafoldtheory}%
  1473 %
  1474 \isadelimtheory
  1475 %
  1476 \endisadelimtheory
  1477 \isanewline
  1478 \end{isabellebody}%
  1479 %%% Local Variables:
  1480 %%% mode: latex
  1481 %%% TeX-master: "root"
  1482 %%% End: