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