doc-src/IsarRef/Thy/Proof.thy
author wenzelm
Sat, 10 May 2008 00:14:00 +0200
changeset 26870 94bedbb34b92
parent 26869 3bc332135aa7
child 26888 9942cd184c48
permissions -rw-r--r--
misc reorganization;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26869
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     1
(* $Id$ *)
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     2
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     3
theory Proof
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     4
imports Main
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     5
begin
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     6
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     7
chapter {* Proofs *}
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     8
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
     9
text {*
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    10
  Proof commands perform transitions of Isar/VM machine
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    11
  configurations, which are block-structured, consisting of a stack of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    12
  nodes with three main components: logical proof context, current
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    13
  facts, and open goals.  Isar/VM transitions are \emph{typed}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    14
  according to the following three different modes of operation:
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    15
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    16
  \begin{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    17
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    18
  \item [@{text "proof(prove)"}] means that a new goal has just been
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    19
  stated that is now to be \emph{proven}; the next command may refine
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    20
  it by some proof method, and enter a sub-proof to establish the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    21
  actual result.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    22
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    23
  \item [@{text "proof(state)"}] is like a nested theory mode: the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    24
  context may be augmented by \emph{stating} additional assumptions,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    25
  intermediate results etc.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    26
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    27
  \item [@{text "proof(chain)"}] is intermediate between @{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    28
  "proof(state)"} and @{text "proof(prove)"}: existing facts (i.e.\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    29
  the contents of the special ``@{fact_ref this}'' register) have been
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    30
  just picked up in order to be used when refining the goal claimed
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    31
  next.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    32
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    33
  \end{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    34
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    35
  The proof mode indicator may be read as a verb telling the writer
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    36
  what kind of operation may be performed next.  The corresponding
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    37
  typings of proof commands restricts the shape of well-formed proof
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    38
  texts to particular command sequences.  So dynamic arrangements of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    39
  commands eventually turn out as static texts of a certain structure.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    40
  \Appref{ap:refcard} gives a simplified grammar of the overall
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    41
  (extensible) language emerging that way.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    42
*}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    43
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    44
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    45
section {* Context elements \label{sec:proof-context} *}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    46
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    47
text {*
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    48
  \begin{matharray}{rcl}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    49
    @{command_def "fix"} & : & \isartrans{proof(state)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    50
    @{command_def "assume"} & : & \isartrans{proof(state)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    51
    @{command_def "presume"} & : & \isartrans{proof(state)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    52
    @{command_def "def"} & : & \isartrans{proof(state)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    53
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    54
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    55
  The logical proof context consists of fixed variables and
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    56
  assumptions.  The former closely correspond to Skolem constants, or
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    57
  meta-level universal quantification as provided by the Isabelle/Pure
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    58
  logical framework.  Introducing some \emph{arbitrary, but fixed}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    59
  variable via ``@{command "fix"}~@{text x}'' results in a local value
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    60
  that may be used in the subsequent proof as any other variable or
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    61
  constant.  Furthermore, any result @{text "\<turnstile> \<phi>[x]"} exported from
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    62
  the context will be universally closed wrt.\ @{text x} at the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    63
  outermost level: @{text "\<turnstile> \<And>x. \<phi>[x]"} (this is expressed in normal
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    64
  form using Isabelle's meta-variables).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    65
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    66
  Similarly, introducing some assumption @{text \<chi>} has two effects.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    67
  On the one hand, a local theorem is created that may be used as a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    68
  fact in subsequent proof steps.  On the other hand, any result
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    69
  @{text "\<chi> \<turnstile> \<phi>"} exported from the context becomes conditional wrt.\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    70
  the assumption: @{text "\<turnstile> \<chi> \<Longrightarrow> \<phi>"}.  Thus, solving an enclosing goal
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    71
  using such a result would basically introduce a new subgoal stemming
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    72
  from the assumption.  How this situation is handled depends on the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    73
  version of assumption command used: while @{command "assume"}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    74
  insists on solving the subgoal by unification with some premise of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    75
  the goal, @{command "presume"} leaves the subgoal unchanged in order
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    76
  to be proved later by the user.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    77
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    78
  Local definitions, introduced by ``@{command "def"}~@{text "x \<equiv>
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    79
  t"}'', are achieved by combining ``@{command "fix"}~@{text x}'' with
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    80
  another version of assumption that causes any hypothetical equation
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    81
  @{text "x \<equiv> t"} to be eliminated by the reflexivity rule.  Thus,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    82
  exporting some result @{text "x \<equiv> t \<turnstile> \<phi>[x]"} yields @{text "\<turnstile>
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    83
  \<phi>[t]"}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    84
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    85
  \begin{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    86
    'fix' (vars + 'and')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    87
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    88
    ('assume' | 'presume') (props + 'and')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    89
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    90
    'def' (def + 'and')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    91
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    92
    def: thmdecl? \\ name ('==' | equiv) term termpat?
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    93
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    94
  \end{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    95
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    96
  \begin{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    97
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    98
  \item [@{command "fix"}~@{text x}] introduces a local variable
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    99
  @{text x} that is \emph{arbitrary, but fixed.}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   100
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   101
  \item [@{command "assume"}~@{text "a: \<phi>"} and @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   102
  "presume"}~@{text "a: \<phi>"}] introduce a local fact @{text "\<phi> \<turnstile> \<phi>"} by
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   103
  assumption.  Subsequent results applied to an enclosing goal (e.g.\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   104
  by @{command_ref "show"}) are handled as follows: @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   105
  "assume"} expects to be able to unify with existing premises in the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   106
  goal, while @{command "presume"} leaves @{text \<phi>} as new subgoals.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   107
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   108
  Several lists of assumptions may be given (separated by
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   109
  @{keyword_ref "and"}; the resulting list of current facts consists
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   110
  of all of these concatenated.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   111
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   112
  \item [@{command "def"}~@{text "x \<equiv> t"}] introduces a local
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   113
  (non-polymorphic) definition.  In results exported from the context,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   114
  @{text x} is replaced by @{text t}.  Basically, ``@{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   115
  "def"}~@{text "x \<equiv> t"}'' abbreviates ``@{command "fix"}~@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   116
  x}~@{command "assume"}~@{text "x \<equiv> t"}'', with the resulting
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   117
  hypothetical equation solved by reflexivity.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   118
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   119
  The default name for the definitional equation is @{text x_def}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   120
  Several simultaneous definitions may be given at the same time.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   121
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   122
  \end{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   123
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   124
  The special name @{fact_ref prems} refers to all assumptions of the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   125
  current context as a list of theorems.  This feature should be used
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   126
  with great care!  It is better avoided in final proof texts.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   127
*}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   128
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   129
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   130
section {* Facts and forward chaining *}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   131
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   132
text {*
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   133
  \begin{matharray}{rcl}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   134
    @{command_def "note"} & : & \isartrans{proof(state)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   135
    @{command_def "then"} & : & \isartrans{proof(state)}{proof(chain)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   136
    @{command_def "from"} & : & \isartrans{proof(state)}{proof(chain)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   137
    @{command_def "with"} & : & \isartrans{proof(state)}{proof(chain)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   138
    @{command_def "using"} & : & \isartrans{proof(prove)}{proof(prove)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   139
    @{command_def "unfolding"} & : & \isartrans{proof(prove)}{proof(prove)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   140
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   141
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   142
  New facts are established either by assumption or proof of local
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   143
  statements.  Any fact will usually be involved in further proofs,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   144
  either as explicit arguments of proof methods, or when forward
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   145
  chaining towards the next goal via @{command "then"} (and variants);
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   146
  @{command "from"} and @{command "with"} are composite forms
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   147
  involving @{command "note"}.  The @{command "using"} elements
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   148
  augments the collection of used facts \emph{after} a goal has been
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   149
  stated.  Note that the special theorem name @{fact_ref this} refers
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   150
  to the most recently established facts, but only \emph{before}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   151
  issuing a follow-up claim.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   152
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   153
  \begin{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   154
    'note' (thmdef? thmrefs + 'and')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   155
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   156
    ('from' | 'with' | 'using' | 'unfolding') (thmrefs + 'and')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   157
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   158
  \end{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   159
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   160
  \begin{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   161
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   162
  \item [@{command "note"}~@{text "a = b\<^sub>1 \<dots> b\<^sub>n"}]
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   163
  recalls existing facts @{text "b\<^sub>1, \<dots>, b\<^sub>n"}, binding
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   164
  the result as @{text a}.  Note that attributes may be involved as
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   165
  well, both on the left and right hand sides.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   166
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   167
  \item [@{command "then"}] indicates forward chaining by the current
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   168
  facts in order to establish the goal to be claimed next.  The
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   169
  initial proof method invoked to refine that will be offered the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   170
  facts to do ``anything appropriate'' (see also
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   171
  \secref{sec:proof-steps}).  For example, method @{method_ref rule}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   172
  (see \secref{sec:pure-meth-att}) would typically do an elimination
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   173
  rather than an introduction.  Automatic methods usually insert the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   174
  facts into the goal state before operation.  This provides a simple
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   175
  scheme to control relevance of facts in automated proof search.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   176
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   177
  \item [@{command "from"}~@{text b}] abbreviates ``@{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   178
  "note"}~@{text b}~@{command "then"}''; thus @{command "then"} is
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   179
  equivalent to ``@{command "from"}~@{text this}''.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   180
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   181
  \item [@{command "with"}~@{text "b\<^sub>1 \<dots> b\<^sub>n"}]
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   182
  abbreviates ``@{command "from"}~@{text "b\<^sub>1 \<dots> b\<^sub>n \<AND>
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   183
  this"}''; thus the forward chaining is from earlier facts together
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   184
  with the current ones.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   185
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   186
  \item [@{command "using"}~@{text "b\<^sub>1 \<dots> b\<^sub>n"}] augments
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   187
  the facts being currently indicated for use by a subsequent
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   188
  refinement step (such as @{command_ref "apply"} or @{command_ref
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   189
  "proof"}).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   190
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   191
  \item [@{command "unfolding"}~@{text "b\<^sub>1 \<dots> b\<^sub>n"}] is
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   192
  structurally similar to @{command "using"}, but unfolds definitional
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   193
  equations @{text "b\<^sub>1, \<dots> b\<^sub>n"} throughout the goal state
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   194
  and facts.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   195
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   196
  \end{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   197
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   198
  Forward chaining with an empty list of theorems is the same as not
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   199
  chaining at all.  Thus ``@{command "from"}~@{text nothing}'' has no
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   200
  effect apart from entering @{text "prove(chain)"} mode, since
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   201
  @{fact_ref nothing} is bound to the empty list of theorems.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   202
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   203
  Basic proof methods (such as @{method_ref rule}) expect multiple
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   204
  facts to be given in their proper order, corresponding to a prefix
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   205
  of the premises of the rule involved.  Note that positions may be
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   206
  easily skipped using something like @{command "from"}~@{text "_
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   207
  \<AND> a \<AND> b"}, for example.  This involves the trivial rule
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   208
  @{text "PROP \<psi> \<Longrightarrow> PROP \<psi>"}, which is bound in Isabelle/Pure as
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   209
  ``@{fact_ref "_"}'' (underscore).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   210
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   211
  Automated methods (such as @{method simp} or @{method auto}) just
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   212
  insert any given facts before their usual operation.  Depending on
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   213
  the kind of procedure involved, the order of facts is less
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   214
  significant here.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   215
*}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   216
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   217
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   218
section {* Goal statements \label{sec:goals} *}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   219
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   220
text {*
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   221
  \begin{matharray}{rcl}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   222
    @{command_def "lemma"} & : & \isartrans{local{\dsh}theory}{proof(prove)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   223
    @{command_def "theorem"} & : & \isartrans{local{\dsh}theory}{proof(prove)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   224
    @{command_def "corollary"} & : & \isartrans{local{\dsh}theory}{proof(prove)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   225
    @{command_def "have"} & : & \isartrans{proof(state) ~|~ proof(chain)}{proof(prove)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   226
    @{command_def "show"} & : & \isartrans{proof(state) ~|~ proof(chain)}{proof(prove)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   227
    @{command_def "hence"} & : & \isartrans{proof(state)}{proof(prove)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   228
    @{command_def "thus"} & : & \isartrans{proof(state)}{proof(prove)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   229
    @{command_def "print_statement"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   230
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   231
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   232
  From a theory context, proof mode is entered by an initial goal
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   233
  command such as @{command "lemma"}, @{command "theorem"}, or
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   234
  @{command "corollary"}.  Within a proof, new claims may be
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   235
  introduced locally as well; four variants are available here to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   236
  indicate whether forward chaining of facts should be performed
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   237
  initially (via @{command_ref "then"}), and whether the final result
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   238
  is meant to solve some pending goal.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   239
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   240
  Goals may consist of multiple statements, resulting in a list of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   241
  facts eventually.  A pending multi-goal is internally represented as
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   242
  a meta-level conjunction (printed as @{text "&&"}), which is usually
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   243
  split into the corresponding number of sub-goals prior to an initial
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   244
  method application, via @{command_ref "proof"}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   245
  (\secref{sec:proof-steps}) or @{command_ref "apply"}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   246
  (\secref{sec:tactic-commands}).  The @{method_ref induct} method
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   247
  covered in \secref{sec:cases-induct} acts on multiple claims
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   248
  simultaneously.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   249
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   250
  Claims at the theory level may be either in short or long form.  A
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   251
  short goal merely consists of several simultaneous propositions
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   252
  (often just one).  A long goal includes an explicit context
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   253
  specification for the subsequent conclusion, involving local
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   254
  parameters and assumptions.  Here the role of each part of the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   255
  statement is explicitly marked by separate keywords (see also
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   256
  \secref{sec:locale}); the local assumptions being introduced here
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   257
  are available as @{fact_ref assms} in the proof.  Moreover, there
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   258
  are two kinds of conclusions: @{element_def "shows"} states several
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   259
  simultaneous propositions (essentially a big conjunction), while
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   260
  @{element_def "obtains"} claims several simultaneous simultaneous
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   261
  contexts of (essentially a big disjunction of eliminated parameters
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   262
  and assumptions, cf.\ \secref{sec:obtain}).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   263
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   264
  \begin{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   265
    ('lemma' | 'theorem' | 'corollary') target? (goal | longgoal)
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   266
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   267
    ('have' | 'show' | 'hence' | 'thus') goal
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   268
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   269
    'print\_statement' modes? thmrefs
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   270
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   271
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   272
    goal: (props + 'and')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   273
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   274
    longgoal: thmdecl? (contextelem *) conclusion
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   275
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   276
    conclusion: 'shows' goal | 'obtains' (parname? case + '|')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   277
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   278
    case: (vars + 'and') 'where' (props + 'and')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   279
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   280
  \end{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   281
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   282
  \begin{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   283
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   284
  \item [@{command "lemma"}~@{text "a: \<phi>"}] enters proof mode with
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   285
  @{text \<phi>} as main goal, eventually resulting in some fact @{text "\<turnstile>
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   286
  \<phi>"} to be put back into the target context.  An additional
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   287
  \railnonterm{context} specification may build up an initial proof
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   288
  context for the subsequent claim; this includes local definitions
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   289
  and syntax as well, see the definition of @{syntax contextelem} in
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   290
  \secref{sec:locale}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   291
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   292
  \item [@{command "theorem"}~@{text "a: \<phi>"} and @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   293
  "corollary"}~@{text "a: \<phi>"}] are essentially the same as @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   294
  "lemma"}~@{text "a: \<phi>"}, but the facts are internally marked as
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   295
  being of a different kind.  This discrimination acts like a formal
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   296
  comment.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   297
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   298
  \item [@{command "have"}~@{text "a: \<phi>"}] claims a local goal,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   299
  eventually resulting in a fact within the current logical context.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   300
  This operation is completely independent of any pending sub-goals of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   301
  an enclosing goal statements, so @{command "have"} may be freely
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   302
  used for experimental exploration of potential results within a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   303
  proof body.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   304
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   305
  \item [@{command "show"}~@{text "a: \<phi>"}] is like @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   306
  "have"}~@{text "a: \<phi>"} plus a second stage to refine some pending
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   307
  sub-goal for each one of the finished result, after having been
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   308
  exported into the corresponding context (at the head of the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   309
  sub-proof of this @{command "show"} command).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   310
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   311
  To accommodate interactive debugging, resulting rules are printed
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   312
  before being applied internally.  Even more, interactive execution
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   313
  of @{command "show"} predicts potential failure and displays the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   314
  resulting error as a warning beforehand.  Watch out for the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   315
  following message:
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   316
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   317
  %FIXME proper antiquitation
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   318
  \begin{ttbox}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   319
  Problem! Local statement will fail to solve any pending goal
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   320
  \end{ttbox}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   321
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   322
  \item [@{command "hence"}] abbreviates ``@{command "then"}~@{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   323
  "have"}'', i.e.\ claims a local goal to be proven by forward
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   324
  chaining the current facts.  Note that @{command "hence"} is also
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   325
  equivalent to ``@{command "from"}~@{text this}~@{command "have"}''.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   326
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   327
  \item [@{command "thus"}] abbreviates ``@{command "then"}~@{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   328
  "show"}''.  Note that @{command "thus"} is also equivalent to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   329
  ``@{command "from"}~@{text this}~@{command "show"}''.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   330
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   331
  \item [@{command "print_statement"}~@{text a}] prints facts from the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   332
  current theory or proof context in long statement form, according to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   333
  the syntax for @{command "lemma"} given above.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   334
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   335
  \end{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   336
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   337
  Any goal statement causes some term abbreviations (such as
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   338
  @{variable_ref "?thesis"}) to be bound automatically, see also
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   339
  \secref{sec:term-abbrev}.  Furthermore, the local context of a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   340
  (non-atomic) goal is provided via the @{case_ref rule_context} case.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   341
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   342
  The optional case names of @{element_ref "obtains"} have a twofold
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   343
  meaning: (1) during the of this claim they refer to the the local
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   344
  context introductions, (2) the resulting rule is annotated
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   345
  accordingly to support symbolic case splits when used with the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   346
  @{method_ref cases} method (cf.  \secref{sec:cases-induct}).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   347
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   348
  \medskip
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   349
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   350
  \begin{warn}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   351
    Isabelle/Isar suffers theory-level goal statements to contain
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   352
    \emph{unbound schematic variables}, although this does not conform
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   353
    to the aim of human-readable proof documents!  The main problem
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   354
    with schematic goals is that the actual outcome is usually hard to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   355
    predict, depending on the behavior of the proof methods applied
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   356
    during the course of reasoning.  Note that most semi-automated
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   357
    methods heavily depend on several kinds of implicit rule
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   358
    declarations within the current theory context.  As this would
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   359
    also result in non-compositional checking of sub-proofs,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   360
    \emph{local goals} are not allowed to be schematic at all.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   361
    Nevertheless, schematic goals do have their use in Prolog-style
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   362
    interactive synthesis of proven results, usually by stepwise
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   363
    refinement via emulation of traditional Isabelle tactic scripts
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   364
    (see also \secref{sec:tactic-commands}).  In any case, users
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   365
    should know what they are doing.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   366
  \end{warn}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   367
*}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   368
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   369
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   370
section {* Initial and terminal proof steps \label{sec:proof-steps} *}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   371
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   372
text {*
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   373
  \begin{matharray}{rcl}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   374
    @{command_def "proof"} & : & \isartrans{proof(prove)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   375
    @{command_def "qed"} & : & \isartrans{proof(state)}{proof(state) ~|~ theory} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   376
    @{command_def "by"} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   377
    @{command_def ".."} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   378
    @{command_def "."} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   379
    @{command_def "sorry"} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   380
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   381
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   382
  Arbitrary goal refinement via tactics is considered harmful.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   383
  Structured proof composition in Isar admits proof methods to be
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   384
  invoked in two places only.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   385
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   386
  \begin{enumerate}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   387
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   388
  \item An \emph{initial} refinement step @{command_ref
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   389
  "proof"}~@{text "m\<^sub>1"} reduces a newly stated goal to a number
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   390
  of sub-goals that are to be solved later.  Facts are passed to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   391
  @{text "m\<^sub>1"} for forward chaining, if so indicated by @{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   392
  "proof(chain)"} mode.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   393
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   394
  \item A \emph{terminal} conclusion step @{command_ref "qed"}~@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   395
  "m\<^sub>2"} is intended to solve remaining goals.  No facts are
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   396
  passed to @{text "m\<^sub>2"}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   397
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   398
  \end{enumerate}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   399
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   400
  The only other (proper) way to affect pending goals in a proof body
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   401
  is by @{command_ref "show"}, which involves an explicit statement of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   402
  what is to be solved eventually.  Thus we avoid the fundamental
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   403
  problem of unstructured tactic scripts that consist of numerous
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   404
  consecutive goal transformations, with invisible effects.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   405
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   406
  \medskip As a general rule of thumb for good proof style, initial
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   407
  proof methods should either solve the goal completely, or constitute
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   408
  some well-understood reduction to new sub-goals.  Arbitrary
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   409
  automatic proof tools that are prone leave a large number of badly
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   410
  structured sub-goals are no help in continuing the proof document in
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   411
  an intelligible manner.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   412
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   413
  Unless given explicitly by the user, the default initial method is
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   414
  ``@{method_ref rule}'', which applies a single standard elimination
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   415
  or introduction rule according to the topmost symbol involved.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   416
  There is no separate default terminal method.  Any remaining goals
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   417
  are always solved by assumption in the very last step.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   418
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   419
  \begin{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   420
    'proof' method?
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   421
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   422
    'qed' method?
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   423
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   424
    'by' method method?
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   425
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   426
    ('.' | '..' | 'sorry')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   427
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   428
  \end{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   429
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   430
  \begin{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   431
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   432
  \item [@{command "proof"}~@{text "m\<^sub>1"}] refines the goal by
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   433
  proof method @{text "m\<^sub>1"}; facts for forward chaining are
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   434
  passed if so indicated by @{text "proof(chain)"} mode.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   435
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   436
  \item [@{command "qed"}~@{text "m\<^sub>2"}] refines any remaining
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   437
  goals by proof method @{text "m\<^sub>2"} and concludes the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   438
  sub-proof by assumption.  If the goal had been @{text "show"} (or
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   439
  @{text "thus"}), some pending sub-goal is solved as well by the rule
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   440
  resulting from the result \emph{exported} into the enclosing goal
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   441
  context.  Thus @{text "qed"} may fail for two reasons: either @{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   442
  "m\<^sub>2"} fails, or the resulting rule does not fit to any
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   443
  pending goal\footnote{This includes any additional ``strong''
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   444
  assumptions as introduced by @{command "assume"}.} of the enclosing
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   445
  context.  Debugging such a situation might involve temporarily
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   446
  changing @{command "show"} into @{command "have"}, or weakening the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   447
  local context by replacing occurrences of @{command "assume"} by
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   448
  @{command "presume"}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   449
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   450
  \item [@{command "by"}~@{text "m\<^sub>1 m\<^sub>2"}] is a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   451
  \emph{terminal proof}\index{proof!terminal}; it abbreviates
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   452
  @{command "proof"}~@{text "m\<^sub>1"}~@{text "qed"}~@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   453
  "m\<^sub>2"}, but with backtracking across both methods.  Debugging
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   454
  an unsuccessful @{command "by"}~@{text "m\<^sub>1 m\<^sub>2"}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   455
  command can be done by expanding its definition; in many cases
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   456
  @{command "proof"}~@{text "m\<^sub>1"} (or even @{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   457
  "apply"}~@{text "m\<^sub>1"}) is already sufficient to see the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   458
  problem.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   459
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   460
  \item [``@{command ".."}''] is a \emph{default
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   461
  proof}\index{proof!default}; it abbreviates @{command "by"}~@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   462
  "rule"}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   463
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   464
  \item [``@{command "."}''] is a \emph{trivial
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   465
  proof}\index{proof!trivial}; it abbreviates @{command "by"}~@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   466
  "this"}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   467
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   468
  \item [@{command "sorry"}] is a \emph{fake proof}\index{proof!fake}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   469
  pretending to solve the pending claim without further ado.  This
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   470
  only works in interactive development, or if the @{ML
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   471
  quick_and_dirty} flag is enabled (in ML).  Facts emerging from fake
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   472
  proofs are not the real thing.  Internally, each theorem container
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   473
  is tainted by an oracle invocation, which is indicated as ``@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   474
  "[!]"}'' in the printed result.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   475
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   476
  The most important application of @{command "sorry"} is to support
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   477
  experimentation and top-down proof development.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   478
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   479
  \end{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   480
*}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   481
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   482
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   483
section {* Fundamental methods and attributes \label{sec:pure-meth-att} *}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   484
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   485
text {*
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   486
  The following proof methods and attributes refer to basic logical
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   487
  operations of Isar.  Further methods and attributes are provided by
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   488
  several generic and object-logic specific tools and packages (see
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   489
  \chref{ch:gen-tools} and \chref{ch:hol}).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   490
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   491
  \begin{matharray}{rcl}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   492
    @{method_def "-"} & : & \isarmeth \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   493
    @{method_def "fact"} & : & \isarmeth \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   494
    @{method_def "assumption"} & : & \isarmeth \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   495
    @{method_def "this"} & : & \isarmeth \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   496
    @{method_def "rule"} & : & \isarmeth \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   497
    @{method_def "iprover"} & : & \isarmeth \\[0.5ex]
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   498
    @{attribute_def "intro"} & : & \isaratt \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   499
    @{attribute_def "elim"} & : & \isaratt \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   500
    @{attribute_def "dest"} & : & \isaratt \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   501
    @{attribute_def "rule"} & : & \isaratt \\[0.5ex]
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   502
    @{attribute_def "OF"} & : & \isaratt \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   503
    @{attribute_def "of"} & : & \isaratt \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   504
    @{attribute_def "where"} & : & \isaratt \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   505
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   506
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   507
  \begin{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   508
    'fact' thmrefs?
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   509
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   510
    'rule' thmrefs?
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   511
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   512
    'iprover' ('!' ?) (rulemod *)
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   513
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   514
    rulemod: ('intro' | 'elim' | 'dest') ((('!' | () | '?') nat?) | 'del') ':' thmrefs
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   515
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   516
    ('intro' | 'elim' | 'dest') ('!' | () | '?') nat?
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   517
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   518
    'rule' 'del'
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   519
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   520
    'OF' thmrefs
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   521
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   522
    'of' insts ('concl' ':' insts)?
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   523
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   524
    'where' ((name | var | typefree | typevar) '=' (type | term) * 'and')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   525
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   526
  \end{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   527
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   528
  \begin{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   529
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   530
  \item [``@{method "-"}'' (minus)] does nothing but insert the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   531
  forward chaining facts as premises into the goal.  Note that command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   532
  @{command_ref "proof"} without any method actually performs a single
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   533
  reduction step using the @{method_ref rule} method; thus a plain
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   534
  \emph{do-nothing} proof step would be ``@{command "proof"}~@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   535
  "-"}'' rather than @{command "proof"} alone.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   536
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   537
  \item [@{method "fact"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] composes
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   538
  some fact from @{text "a\<^sub>1, \<dots>, a\<^sub>n"} (or implicitly from
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   539
  the current proof context) modulo unification of schematic type and
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   540
  term variables.  The rule structure is not taken into account, i.e.\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   541
  meta-level implication is considered atomic.  This is the same
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   542
  principle underlying literal facts (cf.\ \secref{sec:syn-att}):
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   543
  ``@{command "have"}~@{text "\<phi>"}~@{command "by"}~@{text fact}'' is
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   544
  equivalent to ``@{command "note"}~@{verbatim "`"}@{text \<phi>}@{verbatim
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   545
  "`"}'' provided that @{text "\<turnstile> \<phi>"} is an instance of some known
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   546
  @{text "\<turnstile> \<phi>"} in the proof context.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   547
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   548
  \item [@{method assumption}] solves some goal by a single assumption
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   549
  step.  All given facts are guaranteed to participate in the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   550
  refinement; this means there may be only 0 or 1 in the first place.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   551
  Recall that @{command "qed"} (\secref{sec:proof-steps}) already
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   552
  concludes any remaining sub-goals by assumption, so structured
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   553
  proofs usually need not quote the @{method assumption} method at
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   554
  all.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   555
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   556
  \item [@{method this}] applies all of the current facts directly as
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   557
  rules.  Recall that ``@{command "."}'' (dot) abbreviates ``@{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   558
  "by"}~@{text this}''.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   559
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   560
  \item [@{method rule}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] applies some
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   561
  rule given as argument in backward manner; facts are used to reduce
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   562
  the rule before applying it to the goal.  Thus @{method rule}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   563
  without facts is plain introduction, while with facts it becomes
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   564
  elimination.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   565
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   566
  When no arguments are given, the @{method rule} method tries to pick
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   567
  appropriate rules automatically, as declared in the current context
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   568
  using the @{attribute intro}, @{attribute elim}, @{attribute dest}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   569
  attributes (see below).  This is the default behavior of @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   570
  "proof"} and ``@{command ".."}'' (double-dot) steps (see
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   571
  \secref{sec:proof-steps}).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   572
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   573
  \item [@{method iprover}] performs intuitionistic proof search,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   574
  depending on specifically declared rules from the context, or given
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   575
  as explicit arguments.  Chained facts are inserted into the goal
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   576
  before commencing proof search; ``@{method iprover}@{text "!"}'' 
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   577
  means to include the current @{fact prems} as well.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   578
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   579
  Rules need to be classified as @{attribute intro}, @{attribute
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   580
  elim}, or @{attribute dest}; here the ``@{text "!"}'' indicator
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   581
  refers to ``safe'' rules, which may be applied aggressively (without
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   582
  considering back-tracking later).  Rules declared with ``@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   583
  "?"}'' are ignored in proof search (the single-step @{method rule}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   584
  method still observes these).  An explicit weight annotation may be
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   585
  given as well; otherwise the number of rule premises will be taken
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   586
  into account here.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   587
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   588
  \item [@{attribute intro}, @{attribute elim}, and @{attribute dest}]
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   589
  declare introduction, elimination, and destruct rules, to be used
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   590
  with the @{method rule} and @{method iprover} methods.  Note that
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   591
  the latter will ignore rules declared with ``@{text "?"}'', while
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   592
  ``@{text "!"}''  are used most aggressively.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   593
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   594
  The classical reasoner (see \secref{sec:classical}) introduces its
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   595
  own variants of these attributes; use qualified names to access the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   596
  present versions of Isabelle/Pure, i.e.\ @{attribute "Pure.intro"}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   597
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   598
  \item [@{attribute rule}~@{text del}] undeclares introduction,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   599
  elimination, or destruct rules.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   600
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   601
  \item [@{attribute OF}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] applies some
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   602
  theorem to all of the given rules @{text "a\<^sub>1, \<dots>, a\<^sub>n"}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   603
  (in parallel).  This corresponds to the @{ML "op MRS"} operation in
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   604
  ML, but note the reversed order.  Positions may be effectively
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   605
  skipped by including ``@{text _}'' (underscore) as argument.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   606
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   607
  \item [@{attribute of}~@{text "t\<^sub>1 \<dots> t\<^sub>n"}] performs
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   608
  positional instantiation of term variables.  The terms @{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   609
  "t\<^sub>1, \<dots>, t\<^sub>n"} are substituted for any schematic
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   610
  variables occurring in a theorem from left to right; ``@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   611
  _}'' (underscore) indicates to skip a position.  Arguments following
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   612
  a ``@{keyword "concl"}@{text ":"}'' specification refer to positions
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   613
  of the conclusion of a rule.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   614
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   615
  \item [@{attribute "where"}~@{text "x\<^sub>1 = t\<^sub>1 \<AND> \<dots>
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   616
  x\<^sub>n = t\<^sub>n"}] performs named instantiation of schematic
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   617
  type and term variables occurring in a theorem.  Schematic variables
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   618
  have to be specified on the left-hand side (e.g.\ @{text "?x1.3"}).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   619
  The question mark may be omitted if the variable name is a plain
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   620
  identifier without index.  As type instantiations are inferred from
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   621
  term instantiations, explicit type instantiations are seldom
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   622
  necessary.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   623
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   624
  \end{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   625
*}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   626
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   627
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   628
section {* Term abbreviations \label{sec:term-abbrev} *}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   629
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   630
text {*
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   631
  \begin{matharray}{rcl}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   632
    @{command_def "let"} & : & \isartrans{proof(state)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   633
    @{keyword_def "is"} & : & syntax \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   634
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   635
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   636
  Abbreviations may be either bound by explicit @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   637
  "let"}~@{text "p \<equiv> t"} statements, or by annotating assumptions or
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   638
  goal statements with a list of patterns ``@{text "(\<IS> p\<^sub>1 \<dots>
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   639
  p\<^sub>n)"}''.  In both cases, higher-order matching is invoked to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   640
  bind extra-logical term variables, which may be either named
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   641
  schematic variables of the form @{text ?x}, or nameless dummies
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   642
  ``@{variable _}'' (underscore). Note that in the @{command "let"}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   643
  form the patterns occur on the left-hand side, while the @{keyword
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   644
  "is"} patterns are in postfix position.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   645
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   646
  Polymorphism of term bindings is handled in Hindley-Milner style,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   647
  similar to ML.  Type variables referring to local assumptions or
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   648
  open goal statements are \emph{fixed}, while those of finished
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   649
  results or bound by @{command "let"} may occur in \emph{arbitrary}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   650
  instances later.  Even though actual polymorphism should be rarely
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   651
  used in practice, this mechanism is essential to achieve proper
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   652
  incremental type-inference, as the user proceeds to build up the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   653
  Isar proof text from left to right.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   654
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   655
  \medskip Term abbreviations are quite different from local
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   656
  definitions as introduced via @{command "def"} (see
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   657
  \secref{sec:proof-context}).  The latter are visible within the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   658
  logic as actual equations, while abbreviations disappear during the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   659
  input process just after type checking.  Also note that @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   660
  "def"} does not support polymorphism.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   661
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   662
  \begin{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   663
    'let' ((term + 'and') '=' term + 'and')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   664
    ;  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   665
  \end{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   666
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   667
  The syntax of @{keyword "is"} patterns follows \railnonterm{termpat}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   668
  or \railnonterm{proppat} (see \secref{sec:term-decls}).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   669
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   670
  \begin{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   671
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   672
  \item [@{command "let"}~@{text "p\<^sub>1 = t\<^sub>1 \<AND> \<dots>
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   673
  p\<^sub>n = t\<^sub>n"}] binds any text variables in patterns @{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   674
  "p\<^sub>1, \<dots>, p\<^sub>n"} by simultaneous higher-order matching
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   675
  against terms @{text "t\<^sub>1, \<dots>, t\<^sub>n"}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   676
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   677
  \item [@{text "(\<IS> p\<^sub>1 \<dots> p\<^sub>n)"}] resembles @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   678
  "let"}, but matches @{text "p\<^sub>1, \<dots>, p\<^sub>n"} against the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   679
  preceding statement.  Also note that @{keyword "is"} is not a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   680
  separate command, but part of others (such as @{command "assume"},
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   681
  @{command "have"} etc.).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   682
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   683
  \end{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   684
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   685
  Some \emph{implicit} term abbreviations\index{term abbreviations}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   686
  for goals and facts are available as well.  For any open goal,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   687
  @{variable_ref thesis} refers to its object-level statement,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   688
  abstracted over any meta-level parameters (if present).  Likewise,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   689
  @{variable_ref this} is bound for fact statements resulting from
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   690
  assumptions or finished goals.  In case @{variable this} refers to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   691
  an object-logic statement that is an application @{text "f t"}, then
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   692
  @{text t} is bound to the special text variable ``@{variable "\<dots>"}''
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   693
  (three dots).  The canonical application of this convenience are
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   694
  calculational proofs (see \secref{sec:calculation}).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   695
*}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   696
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   697
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   698
section {* Block structure *}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   699
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   700
text {*
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   701
  \begin{matharray}{rcl}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   702
    @{command_def "next"} & : & \isartrans{proof(state)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   703
    @{command_def "{"} & : & \isartrans{proof(state)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   704
    @{command_def "}"} & : & \isartrans{proof(state)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   705
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   706
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   707
  While Isar is inherently block-structured, opening and closing
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   708
  blocks is mostly handled rather casually, with little explicit
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   709
  user-intervention.  Any local goal statement automatically opens
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   710
  \emph{two} internal blocks, which are closed again when concluding
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   711
  the sub-proof (by @{command "qed"} etc.).  Sections of different
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   712
  context within a sub-proof may be switched via @{command "next"},
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   713
  which is just a single block-close followed by block-open again.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   714
  The effect of @{command "next"} is to reset the local proof context;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   715
  there is no goal focus involved here!
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   716
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   717
  For slightly more advanced applications, there are explicit block
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   718
  parentheses as well.  These typically achieve a stronger forward
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   719
  style of reasoning.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   720
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   721
  \begin{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   722
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   723
  \item [@{command "next"}] switches to a fresh block within a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   724
  sub-proof, resetting the local context to the initial one.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   725
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   726
  \item [@{command "{"} and @{command "}"}] explicitly open and close
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   727
  blocks.  Any current facts pass through ``@{command "{"}''
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   728
  unchanged, while ``@{command "}"}'' causes any result to be
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   729
  \emph{exported} into the enclosing context.  Thus fixed variables
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   730
  are generalized, assumptions discharged, and local definitions
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   731
  unfolded (cf.\ \secref{sec:proof-context}).  There is no difference
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   732
  of @{command "assume"} and @{command "presume"} in this mode of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   733
  forward reasoning --- in contrast to plain backward reasoning with
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   734
  the result exported at @{command "show"} time.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   735
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   736
  \end{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   737
*}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   738
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   739
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   740
section {* Emulating tactic scripts \label{sec:tactic-commands} *}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   741
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   742
text {*
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   743
  The Isar provides separate commands to accommodate tactic-style
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   744
  proof scripts within the same system.  While being outside the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   745
  orthodox Isar proof language, these might come in handy for
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   746
  interactive exploration and debugging, or even actual tactical proof
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   747
  within new-style theories (to benefit from document preparation, for
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   748
  example).  See also \secref{sec:tactics} for actual tactics, that
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   749
  have been encapsulated as proof methods.  Proper proof methods may
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   750
  be used in scripts, too.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   751
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   752
  \begin{matharray}{rcl}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   753
    @{command_def "apply"}@{text "\<^sup>*"} & : & \isartrans{proof(prove)}{proof(prove)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   754
    @{command_def "apply_end"}@{text "\<^sup>*"} & : & \isartrans{proof(state)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   755
    @{command_def "done"}@{text "\<^sup>*"} & : & \isartrans{proof(prove)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   756
    @{command_def "defer"}@{text "\<^sup>*"} & : & \isartrans{proof}{proof} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   757
    @{command_def "prefer"}@{text "\<^sup>*"} & : & \isartrans{proof}{proof} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   758
    @{command_def "back"}@{text "\<^sup>*"} & : & \isartrans{proof}{proof} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   759
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   760
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   761
  \begin{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   762
    ( 'apply' | 'apply\_end' ) method
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   763
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   764
    'defer' nat?
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   765
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   766
    'prefer' nat
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   767
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   768
  \end{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   769
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   770
  \begin{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   771
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   772
  \item [@{command "apply"}~@{text m}] applies proof method @{text m}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   773
  in initial position, but unlike @{command "proof"} it retains
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   774
  ``@{text "proof(prove)"}'' mode.  Thus consecutive method
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   775
  applications may be given just as in tactic scripts.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   776
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   777
  Facts are passed to @{text m} as indicated by the goal's
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   778
  forward-chain mode, and are \emph{consumed} afterwards.  Thus any
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   779
  further @{command "apply"} command would always work in a purely
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   780
  backward manner.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   781
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   782
  \item [@{command "apply_end"}~@{text "m"}] applies proof method
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   783
  @{text m} as if in terminal position.  Basically, this simulates a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   784
  multi-step tactic script for @{command "qed"}, but may be given
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   785
  anywhere within the proof body.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   786
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   787
  No facts are passed to @{method m} here.  Furthermore, the static
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   788
  context is that of the enclosing goal (as for actual @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   789
  "qed"}).  Thus the proof method may not refer to any assumptions
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   790
  introduced in the current body, for example.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   791
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   792
  \item [@{command "done"}] completes a proof script, provided that
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   793
  the current goal state is solved completely.  Note that actual
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   794
  structured proof commands (e.g.\ ``@{command "."}'' or @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   795
  "sorry"}) may be used to conclude proof scripts as well.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   796
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   797
  \item [@{command "defer"}~@{text n} and @{command "prefer"}~@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   798
  n}] shuffle the list of pending goals: @{command "defer"} puts off
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   799
  sub-goal @{text n} to the end of the list (@{text "n = 1"} by
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   800
  default), while @{command "prefer"} brings sub-goal @{text n} to the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   801
  front.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   802
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   803
  \item [@{command "back"}] does back-tracking over the result
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   804
  sequence of the latest proof command.  Basically, any proof command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   805
  may return multiple results.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   806
  
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   807
  \end{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   808
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   809
  Any proper Isar proof method may be used with tactic script commands
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   810
  such as @{command "apply"}.  A few additional emulations of actual
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   811
  tactics are provided as well; these would be never used in actual
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   812
  structured proofs, of course.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   813
*}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   814
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   815
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   816
section {* Omitting proofs *}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   817
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   818
text {*
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   819
  \begin{matharray}{rcl}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   820
    @{command_def "oops"} & : & \isartrans{proof}{theory} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   821
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   822
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   823
  The @{command "oops"} command discontinues the current proof
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   824
  attempt, while considering the partial proof text as properly
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   825
  processed.  This is conceptually quite different from ``faking''
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   826
  actual proofs via @{command_ref "sorry"} (see
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   827
  \secref{sec:proof-steps}): @{command "oops"} does not observe the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   828
  proof structure at all, but goes back right to the theory level.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   829
  Furthermore, @{command "oops"} does not produce any result theorem
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   830
  --- there is no intended claim to be able to complete the proof
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   831
  anyhow.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   832
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   833
  A typical application of @{command "oops"} is to explain Isar proofs
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   834
  \emph{within} the system itself, in conjunction with the document
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   835
  preparation tools of Isabelle described in \cite{isabelle-sys}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   836
  Thus partial or even wrong proof attempts can be discussed in a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   837
  logically sound manner.  Note that the Isabelle {\LaTeX} macros can
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   838
  be easily adapted to print something like ``@{text "\<dots>"}'' instead of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   839
  the keyword ``@{command "oops"}''.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   840
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   841
  \medskip The @{command "oops"} command is undo-able, unlike
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   842
  @{command_ref "kill"} (see \secref{sec:history}).  The effect is to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   843
  get back to the theory just before the opening of the proof.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   844
*}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   845
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   846
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   847
section {* Generalized elimination \label{sec:obtain} *}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   848
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   849
text {*
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   850
  \begin{matharray}{rcl}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   851
    @{command_def "obtain"} & : & \isartrans{proof(state)}{proof(prove)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   852
    @{command_def "guess"}@{text "\<^sup>*"} & : & \isartrans{proof(state)}{proof(prove)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   853
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   854
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   855
  Generalized elimination means that additional elements with certain
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   856
  properties may be introduced in the current context, by virtue of a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   857
  locally proven ``soundness statement''.  Technically speaking, the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   858
  @{command "obtain"} language element is like a declaration of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   859
  @{command "fix"} and @{command "assume"} (see also see
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   860
  \secref{sec:proof-context}), together with a soundness proof of its
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   861
  additional claim.  According to the nature of existential reasoning,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   862
  assumptions get eliminated from any result exported from the context
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   863
  later, provided that the corresponding parameters do \emph{not}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   864
  occur in the conclusion.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   865
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   866
  \begin{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   867
    'obtain' parname? (vars + 'and') 'where' (props + 'and')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   868
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   869
    'guess' (vars + 'and')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   870
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   871
  \end{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   872
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   873
  The derived Isar command @{command "obtain"} is defined as follows
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   874
  (where @{text "b\<^sub>1, \<dots>, b\<^sub>k"} shall refer to (optional)
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   875
  facts indicated for forward chaining).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   876
  \begin{matharray}{l}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   877
    @{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]
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   878
    \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"} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   879
    \quad @{command "proof"}~@{text succeed} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   880
    \qquad @{command "fix"}~@{text thesis} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   881
    \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"} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   882
    \qquad @{command "then"}~@{command "show"}~@{text thesis} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   883
    \quad\qquad @{command "apply"}~@{text -} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   884
    \quad\qquad @{command "using"}~@{text "b\<^sub>1 \<dots> b\<^sub>k  \<langle>proof\<rangle>"} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   885
    \quad @{command "qed"} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   886
    \quad @{command "fix"}~@{text "x\<^sub>1 \<dots> x\<^sub>m"}~@{command "assume"}@{text "\<^sup>* a: \<phi>\<^sub>1 \<dots> \<phi>\<^sub>n"} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   887
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   888
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   889
  Typically, the soundness proof is relatively straight-forward, often
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   890
  just by canonical automated tools such as ``@{command "by"}~@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   891
  simp}'' or ``@{command "by"}~@{text blast}''.  Accordingly, the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   892
  ``@{text that}'' reduction above is declared as simplification and
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   893
  introduction rule.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   894
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   895
  In a sense, @{command "obtain"} represents at the level of Isar
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   896
  proofs what would be meta-logical existential quantifiers and
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   897
  conjunctions.  This concept has a broad range of useful
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   898
  applications, ranging from plain elimination (or introduction) of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   899
  object-level existential and conjunctions, to elimination over
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   900
  results of symbolic evaluation of recursive definitions, for
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   901
  example.  Also note that @{command "obtain"} without parameters acts
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   902
  much like @{command "have"}, where the result is treated as a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   903
  genuine assumption.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   904
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   905
  An alternative name to be used instead of ``@{text that}'' above may
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   906
  be given in parentheses.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   907
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   908
  \medskip The improper variant @{command "guess"} is similar to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   909
  @{command "obtain"}, but derives the obtained statement from the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   910
  course of reasoning!  The proof starts with a fixed goal @{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   911
  thesis}.  The subsequent proof may refine this to anything of the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   912
  form like @{text "\<And>x\<^sub>1 \<dots> x\<^sub>m. \<phi>\<^sub>1 \<Longrightarrow> \<dots>
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   913
  \<phi>\<^sub>n \<Longrightarrow> thesis"}, but must not introduce new subgoals.  The
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   914
  final goal state is then used as reduction rule for the obtain
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   915
  scheme described above.  Obtained parameters @{text "x\<^sub>1, \<dots>,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   916
  x\<^sub>m"} are marked as internal by default, which prevents the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   917
  proof context from being polluted by ad-hoc variables.  The variable
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   918
  names and type constraints given as arguments for @{command "guess"}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   919
  specify a prefix of obtained parameters explicitly in the text.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   920
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   921
  It is important to note that the facts introduced by @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   922
  "obtain"} and @{command "guess"} may not be polymorphic: any
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   923
  type-variables occurring here are fixed in the present context!
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   924
*}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   925
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   926
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   927
section {* Calculational reasoning \label{sec:calculation} *}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   928
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   929
text {*
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   930
  \begin{matharray}{rcl}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   931
    @{command_def "also"} & : & \isartrans{proof(state)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   932
    @{command_def "finally"} & : & \isartrans{proof(state)}{proof(chain)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   933
    @{command_def "moreover"} & : & \isartrans{proof(state)}{proof(state)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   934
    @{command_def "ultimately"} & : & \isartrans{proof(state)}{proof(chain)} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   935
    @{command_def "print_trans_rules"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   936
    @{attribute trans} & : & \isaratt \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   937
    @{attribute sym} & : & \isaratt \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   938
    @{attribute symmetric} & : & \isaratt \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   939
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   940
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   941
  Calculational proof is forward reasoning with implicit application
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   942
  of transitivity rules (such those of @{text "="}, @{text "\<le>"},
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   943
  @{text "<"}).  Isabelle/Isar maintains an auxiliary fact register
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   944
  @{fact_ref calculation} for accumulating results obtained by
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   945
  transitivity composed with the current result.  Command @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   946
  "also"} updates @{fact calculation} involving @{fact this}, while
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   947
  @{command "finally"} exhibits the final @{fact calculation} by
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   948
  forward chaining towards the next goal statement.  Both commands
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   949
  require valid current facts, i.e.\ may occur only after commands
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   950
  that produce theorems such as @{command "assume"}, @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   951
  "note"}, or some finished proof of @{command "have"}, @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   952
  "show"} etc.  The @{command "moreover"} and @{command "ultimately"}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   953
  commands are similar to @{command "also"} and @{command "finally"},
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   954
  but only collect further results in @{fact calculation} without
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   955
  applying any rules yet.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   956
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   957
  Also note that the implicit term abbreviation ``@{text "\<dots>"}'' has
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   958
  its canonical application with calculational proofs.  It refers to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   959
  the argument of the preceding statement. (The argument of a curried
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   960
  infix expression happens to be its right-hand side.)
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   961
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   962
  Isabelle/Isar calculations are implicitly subject to block structure
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   963
  in the sense that new threads of calculational reasoning are
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   964
  commenced for any new block (as opened by a local goal, for
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   965
  example).  This means that, apart from being able to nest
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   966
  calculations, there is no separate \emph{begin-calculation} command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   967
  required.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   968
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   969
  \medskip The Isar calculation proof commands may be defined as
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   970
  follows:\footnote{We suppress internal bookkeeping such as proper
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   971
  handling of block-structure.}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   972
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   973
  \begin{matharray}{rcl}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   974
    @{command "also"}@{text "\<^sub>0"} & \equiv & @{command "note"}~@{text "calculation = this"} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   975
    @{command "also"}@{text "\<^sub>n\<^sub>+\<^sub>1"} & \equiv & @{command "note"}~@{text "calculation = trans [OF calculation this]"} \\[0.5ex]
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   976
    @{command "finally"} & \equiv & @{command "also"}~@{command "from"}~@{text calculation} \\[0.5ex]
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   977
    @{command "moreover"} & \equiv & @{command "note"}~@{text "calculation = calculation this"} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   978
    @{command "ultimately"} & \equiv & @{command "moreover"}~@{command "from"}~@{text calculation} \\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   979
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   980
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   981
  \begin{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   982
    ('also' | 'finally') ('(' thmrefs ')')?
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   983
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   984
    'trans' (() | 'add' | 'del')
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   985
    ;
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   986
  \end{rail}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   987
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   988
  \begin{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   989
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   990
  \item [@{command "also"}~@{text "(a\<^sub>1 \<dots> a\<^sub>n)"}]
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   991
  maintains the auxiliary @{fact calculation} register as follows.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   992
  The first occurrence of @{command "also"} in some calculational
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   993
  thread initializes @{fact calculation} by @{fact this}. Any
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   994
  subsequent @{command "also"} on the same level of block-structure
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   995
  updates @{fact calculation} by some transitivity rule applied to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   996
  @{fact calculation} and @{fact this} (in that order).  Transitivity
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   997
  rules are picked from the current context, unless alternative rules
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   998
  are given as explicit arguments.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   999
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1000
  \item [@{command "finally"}~@{text "(a\<^sub>1 \<dots> a\<^sub>n)"}]
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1001
  maintaining @{fact calculation} in the same way as @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1002
  "also"}, and concludes the current calculational thread.  The final
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1003
  result is exhibited as fact for forward chaining towards the next
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1004
  goal. Basically, @{command "finally"} just abbreviates @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1005
  "also"}~@{command "from"}~@{fact calculation}.  Typical idioms for
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1006
  concluding calculational proofs are ``@{command "finally"}~@{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1007
  "show"}~@{text ?thesis}~@{command "."}'' and ``@{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1008
  "finally"}~@{command "have"}~@{text \<phi>}~@{command "."}''.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1009
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1010
  \item [@{command "moreover"} and @{command "ultimately"}] are
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1011
  analogous to @{command "also"} and @{command "finally"}, but collect
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1012
  results only, without applying rules.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1013
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1014
  \item [@{command "print_trans_rules"}] prints the list of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1015
  transitivity rules (for calculational commands @{command "also"} and
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1016
  @{command "finally"}) and symmetry rules (for the @{attribute
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1017
  symmetric} operation and single step elimination patters) of the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1018
  current context.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1019
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1020
  \item [@{attribute trans}] declares theorems as transitivity rules.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1021
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1022
  \item [@{attribute sym}] declares symmetry rules, as well as
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1023
  @{attribute "Pure.elim?"} rules.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1024
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1025
  \item [@{attribute symmetric}] resolves a theorem with some rule
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1026
  declared as @{attribute sym} in the current context.  For example,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1027
  ``@{command "assume"}~@{text "[symmetric]: x = y"}'' produces a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1028
  swapped fact derived from that assumption.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1029
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1030
  In structured proof texts it is often more appropriate to use an
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1031
  explicit single-step elimination proof, such as ``@{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1032
  "assume"}~@{text "x = y"}~@{command "then"}~@{command "have"}~@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1033
  "y = x"}~@{command ".."}''.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1034
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1035
  \end{descr}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1036
*}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1037
26869
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
  1038
end