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