src/Doc/Isar_Ref/Proof.thy
author wenzelm
Wed, 14 Oct 2015 15:10:32 +0200
changeset 61439 2bf52eec4e8a
parent 61421 e0825405d398
child 61458 987533262fc2
permissions -rw-r--r--
more symbols;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26869
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     1
theory Proof
42651
e3fdb7c96be5 formal Base theory;
wenzelm
parents: 42626
diff changeset
     2
imports Base Main
26869
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     3
begin
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     4
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
     5
chapter \<open>Proofs \label{ch:proofs}\<close>
26869
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     6
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
     7
text \<open>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
     8
  Proof commands perform transitions of Isar/VM machine
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
     9
  configurations, which are block-structured, consisting of a stack of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    10
  nodes with three main components: logical proof context, current
29741
wenzelm
parents: 29723
diff changeset
    11
  facts, and open goals.  Isar/VM transitions are typed according to
wenzelm
parents: 29723
diff changeset
    12
  the following three different modes of operation:
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    13
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
    14
  \begin{description}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    15
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
    16
  \<^descr> @{text "proof(prove)"} means that a new goal has just been
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    17
  stated that is now to be \emph{proven}; the next command may refine
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    18
  it by some proof method, and enter a sub-proof to establish the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    19
  actual result.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    20
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
    21
  \<^descr> @{text "proof(state)"} is like a nested theory mode: the
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    22
  context may be augmented by \emph{stating} additional assumptions,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    23
  intermediate results etc.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    24
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
    25
  \<^descr> @{text "proof(chain)"} is intermediate between @{text
60480
wenzelm
parents: 60459
diff changeset
    26
  "proof(state)"} and @{text "proof(prove)"}: existing facts (i.e.\ the
wenzelm
parents: 60459
diff changeset
    27
  contents of the special @{fact_ref this} register) have been just picked
wenzelm
parents: 60459
diff changeset
    28
  up in order to be used when refining the goal claimed next.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    29
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
    30
  \end{description}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    31
29741
wenzelm
parents: 29723
diff changeset
    32
  The proof mode indicator may be understood as an instruction to the
wenzelm
parents: 29723
diff changeset
    33
  writer, telling what kind of operation may be performed next.  The
wenzelm
parents: 29723
diff changeset
    34
  corresponding typings of proof commands restricts the shape of
wenzelm
parents: 29723
diff changeset
    35
  well-formed proof texts to particular command sequences.  So dynamic
wenzelm
parents: 29723
diff changeset
    36
  arrangements of commands eventually turn out as static texts of a
wenzelm
parents: 29723
diff changeset
    37
  certain structure.
wenzelm
parents: 29723
diff changeset
    38
wenzelm
parents: 29723
diff changeset
    39
  \Appref{ap:refcard} gives a simplified grammar of the (extensible)
wenzelm
parents: 29723
diff changeset
    40
  language emerging that way from the different types of proof
wenzelm
parents: 29723
diff changeset
    41
  commands.  The main ideas of the overall Isar framework are
wenzelm
parents: 29723
diff changeset
    42
  explained in \chref{ch:isar-framework}.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    43
\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    44
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    45
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    46
section \<open>Proof structure\<close>
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    47
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    48
subsection \<open>Formal notepad\<close>
36356
5ab0f8859f9f command 'example_proof' opens an empty proof body;
wenzelm
parents: 36320
diff changeset
    49
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    50
text \<open>
36356
5ab0f8859f9f command 'example_proof' opens an empty proof body;
wenzelm
parents: 36320
diff changeset
    51
  \begin{matharray}{rcl}
40965
54b6c9e1c157 command 'notepad' replaces former 'example_proof';
wenzelm
parents: 40255
diff changeset
    52
    @{command_def "notepad"} & : & @{text "local_theory \<rightarrow> proof(state)"} \\
36356
5ab0f8859f9f command 'example_proof' opens an empty proof body;
wenzelm
parents: 36320
diff changeset
    53
  \end{matharray}
5ab0f8859f9f command 'example_proof' opens an empty proof body;
wenzelm
parents: 36320
diff changeset
    54
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
    55
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
    56
    @@{command notepad} @'begin'
40965
54b6c9e1c157 command 'notepad' replaces former 'example_proof';
wenzelm
parents: 40255
diff changeset
    57
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
    58
    @@{command end}
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
    59
  \<close>}
40965
54b6c9e1c157 command 'notepad' replaces former 'example_proof';
wenzelm
parents: 40255
diff changeset
    60
36356
5ab0f8859f9f command 'example_proof' opens an empty proof body;
wenzelm
parents: 36320
diff changeset
    61
  \begin{description}
5ab0f8859f9f command 'example_proof' opens an empty proof body;
wenzelm
parents: 36320
diff changeset
    62
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
    63
  \<^descr> @{command "notepad"}~@{keyword "begin"} opens a proof state without
60482
wenzelm
parents: 60480
diff changeset
    64
  any goal statement. This allows to experiment with Isar, without producing
wenzelm
parents: 60480
diff changeset
    65
  any persistent result. The notepad is closed by @{command "end"}.
36356
5ab0f8859f9f command 'example_proof' opens an empty proof body;
wenzelm
parents: 36320
diff changeset
    66
5ab0f8859f9f command 'example_proof' opens an empty proof body;
wenzelm
parents: 36320
diff changeset
    67
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    68
\<close>
36356
5ab0f8859f9f command 'example_proof' opens an empty proof body;
wenzelm
parents: 36320
diff changeset
    69
5ab0f8859f9f command 'example_proof' opens an empty proof body;
wenzelm
parents: 36320
diff changeset
    70
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    71
subsection \<open>Blocks\<close>
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    72
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    73
text \<open>
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    74
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
    75
    @{command_def "next"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
    76
    @{command_def "{"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
    77
    @{command_def "}"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    78
  \end{matharray}
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    79
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    80
  While Isar is inherently block-structured, opening and closing
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    81
  blocks is mostly handled rather casually, with little explicit
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    82
  user-intervention.  Any local goal statement automatically opens
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    83
  \emph{two} internal blocks, which are closed again when concluding
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    84
  the sub-proof (by @{command "qed"} etc.).  Sections of different
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    85
  context within a sub-proof may be switched via @{command "next"},
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    86
  which is just a single block-close followed by block-open again.
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    87
  The effect of @{command "next"} is to reset the local proof context;
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    88
  there is no goal focus involved here!
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    89
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    90
  For slightly more advanced applications, there are explicit block
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    91
  parentheses as well.  These typically achieve a stronger forward
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    92
  style of reasoning.
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    93
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
    94
  \begin{description}
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    95
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
    96
  \<^descr> @{command "next"} switches to a fresh block within a
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    97
  sub-proof, resetting the local context to the initial one.
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
    98
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
    99
  \<^descr> @{command "{"} and @{command "}"} explicitly open and close
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   100
  blocks.  Any current facts pass through ``@{command "{"}''
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   101
  unchanged, while ``@{command "}"}'' causes any result to be
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   102
  \emph{exported} into the enclosing context.  Thus fixed variables
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   103
  are generalized, assumptions discharged, and local definitions
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   104
  unfolded (cf.\ \secref{sec:proof-context}).  There is no difference
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   105
  of @{command "assume"} and @{command "presume"} in this mode of
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   106
  forward reasoning --- in contrast to plain backward reasoning with
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   107
  the result exported at @{command "show"} time.
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   108
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   109
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   110
\<close>
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   111
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   112
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   113
subsection \<open>Omitting proofs\<close>
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   114
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   115
text \<open>
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   116
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   117
    @{command_def "oops"} & : & @{text "proof \<rightarrow> local_theory | theory"} \\
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   118
  \end{matharray}
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   119
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   120
  The @{command "oops"} command discontinues the current proof
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   121
  attempt, while considering the partial proof text as properly
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   122
  processed.  This is conceptually quite different from ``faking''
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   123
  actual proofs via @{command_ref "sorry"} (see
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   124
  \secref{sec:proof-steps}): @{command "oops"} does not observe the
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   125
  proof structure at all, but goes back right to the theory level.
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   126
  Furthermore, @{command "oops"} does not produce any result theorem
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   127
  --- there is no intended claim to be able to complete the proof
45103
a45121ffcfcb some amendments due to Jean Pichon;
wenzelm
parents: 45014
diff changeset
   128
  in any way.
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   129
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   130
  A typical application of @{command "oops"} is to explain Isar proofs
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   131
  \emph{within} the system itself, in conjunction with the document
28838
d5db6dfcb34a moved table of standard Isabelle symbols to isar-ref manual;
wenzelm
parents: 28761
diff changeset
   132
  preparation tools of Isabelle described in \chref{ch:document-prep}.
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   133
  Thus partial or even wrong proof attempts can be discussed in a
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   134
  logically sound manner.  Note that the Isabelle {\LaTeX} macros can
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   135
  be easily adapted to print something like ``@{text "\<dots>"}'' instead of
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   136
  the keyword ``@{command "oops"}''.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   137
\<close>
28755
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   138
d5c1b7d67ea9 tuned section arrangement;
wenzelm
parents: 28754
diff changeset
   139
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   140
section \<open>Statements\<close>
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   141
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   142
subsection \<open>Context elements \label{sec:proof-context}\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   143
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   144
text \<open>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   145
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   146
    @{command_def "fix"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   147
    @{command_def "assume"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   148
    @{command_def "presume"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   149
    @{command_def "def"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   150
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   151
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   152
  The logical proof context consists of fixed variables and
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   153
  assumptions.  The former closely correspond to Skolem constants, or
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   154
  meta-level universal quantification as provided by the Isabelle/Pure
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   155
  logical framework.  Introducing some \emph{arbitrary, but fixed}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   156
  variable via ``@{command "fix"}~@{text x}'' results in a local value
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   157
  that may be used in the subsequent proof as any other variable or
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   158
  constant.  Furthermore, any result @{text "\<turnstile> \<phi>[x]"} exported from
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   159
  the context will be universally closed wrt.\ @{text x} at the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   160
  outermost level: @{text "\<turnstile> \<And>x. \<phi>[x]"} (this is expressed in normal
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   161
  form using Isabelle's meta-variables).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   162
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   163
  Similarly, introducing some assumption @{text \<chi>} has two effects.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   164
  On the one hand, a local theorem is created that may be used as a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   165
  fact in subsequent proof steps.  On the other hand, any result
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   166
  @{text "\<chi> \<turnstile> \<phi>"} exported from the context becomes conditional wrt.\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   167
  the assumption: @{text "\<turnstile> \<chi> \<Longrightarrow> \<phi>"}.  Thus, solving an enclosing goal
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   168
  using such a result would basically introduce a new subgoal stemming
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   169
  from the assumption.  How this situation is handled depends on the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   170
  version of assumption command used: while @{command "assume"}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   171
  insists on solving the subgoal by unification with some premise of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   172
  the goal, @{command "presume"} leaves the subgoal unchanged in order
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   173
  to be proved later by the user.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   174
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   175
  Local definitions, introduced by ``@{command "def"}~@{text "x \<equiv>
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   176
  t"}'', are achieved by combining ``@{command "fix"}~@{text x}'' with
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   177
  another version of assumption that causes any hypothetical equation
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   178
  @{text "x \<equiv> t"} to be eliminated by the reflexivity rule.  Thus,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   179
  exporting some result @{text "x \<equiv> t \<turnstile> \<phi>[x]"} yields @{text "\<turnstile>
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   180
  \<phi>[t]"}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   181
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   182
  @{rail \<open>
59785
4e6ab5831cc0 clarified syntax category "fixes";
wenzelm
parents: 59783
diff changeset
   183
    @@{command fix} @{syntax "fixes"}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   184
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   185
    (@@{command assume} | @@{command presume}) (@{syntax props} + @'and')
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   186
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   187
    @@{command def} (def + @'and')
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   188
    ;
55029
61a6bf7d4b02 clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents: 53377
diff changeset
   189
    def: @{syntax thmdecl}? \<newline>
61a6bf7d4b02 clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents: 53377
diff changeset
   190
      @{syntax name} ('==' | '\<equiv>') @{syntax term} @{syntax term_pat}?
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   191
  \<close>}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   192
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   193
  \begin{description}
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   194
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   195
  \<^descr> @{command "fix"}~@{text x} introduces a local variable @{text
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   196
  x} that is \emph{arbitrary, but fixed.}
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   197
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   198
  \<^descr> @{command "assume"}~@{text "a: \<phi>"} and @{command
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   199
  "presume"}~@{text "a: \<phi>"} introduce a local fact @{text "\<phi> \<turnstile> \<phi>"} by
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   200
  assumption.  Subsequent results applied to an enclosing goal (e.g.\
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   201
  by @{command_ref "show"}) are handled as follows: @{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   202
  "assume"} expects to be able to unify with existing premises in the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   203
  goal, while @{command "presume"} leaves @{text \<phi>} as new subgoals.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   204
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   205
  Several lists of assumptions may be given (separated by
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   206
  @{keyword_ref "and"}; the resulting list of current facts consists
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   207
  of all of these concatenated.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   208
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   209
  \<^descr> @{command "def"}~@{text "x \<equiv> t"} introduces a local
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   210
  (non-polymorphic) definition.  In results exported from the context,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   211
  @{text x} is replaced by @{text t}.  Basically, ``@{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   212
  "def"}~@{text "x \<equiv> t"}'' abbreviates ``@{command "fix"}~@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   213
  x}~@{command "assume"}~@{text "x \<equiv> t"}'', with the resulting
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   214
  hypothetical equation solved by reflexivity.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   215
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   216
  The default name for the definitional equation is @{text x_def}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   217
  Several simultaneous definitions may be given at the same time.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   218
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   219
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   220
\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   221
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   222
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   223
subsection \<open>Term abbreviations \label{sec:term-abbrev}\<close>
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   224
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   225
text \<open>
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   226
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   227
    @{command_def "let"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   228
    @{keyword_def "is"} & : & syntax \\
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   229
  \end{matharray}
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   230
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   231
  Abbreviations may be either bound by explicit @{command
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   232
  "let"}~@{text "p \<equiv> t"} statements, or by annotating assumptions or
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   233
  goal statements with a list of patterns ``@{text "(\<IS> p\<^sub>1 \<dots>
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   234
  p\<^sub>n)"}''.  In both cases, higher-order matching is invoked to
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   235
  bind extra-logical term variables, which may be either named
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   236
  schematic variables of the form @{text ?x}, or nameless dummies
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   237
  ``@{variable _}'' (underscore). Note that in the @{command "let"}
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   238
  form the patterns occur on the left-hand side, while the @{keyword
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   239
  "is"} patterns are in postfix position.
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   240
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   241
  Polymorphism of term bindings is handled in Hindley-Milner style,
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   242
  similar to ML.  Type variables referring to local assumptions or
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   243
  open goal statements are \emph{fixed}, while those of finished
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   244
  results or bound by @{command "let"} may occur in \emph{arbitrary}
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   245
  instances later.  Even though actual polymorphism should be rarely
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   246
  used in practice, this mechanism is essential to achieve proper
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   247
  incremental type-inference, as the user proceeds to build up the
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   248
  Isar proof text from left to right.
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   249
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
   250
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
   251
  Term abbreviations are quite different from local
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   252
  definitions as introduced via @{command "def"} (see
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   253
  \secref{sec:proof-context}).  The latter are visible within the
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   254
  logic as actual equations, while abbreviations disappear during the
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   255
  input process just after type checking.  Also note that @{command
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   256
  "def"} does not support polymorphism.
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   257
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   258
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   259
    @@{command let} ((@{syntax term} + @'and') '=' @{syntax term} + @'and')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   260
  \<close>}
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   261
42705
528a2ba8fa74 tuned some syntax names;
wenzelm
parents: 42704
diff changeset
   262
  The syntax of @{keyword "is"} patterns follows @{syntax term_pat} or
528a2ba8fa74 tuned some syntax names;
wenzelm
parents: 42704
diff changeset
   263
  @{syntax prop_pat} (see \secref{sec:term-decls}).
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   264
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   265
  \begin{description}
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   266
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   267
  \<^descr> @{command "let"}~@{text "p\<^sub>1 = t\<^sub>1 \<AND> \<dots> p\<^sub>n = t\<^sub>n"} binds any
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   268
  text variables in patterns @{text "p\<^sub>1, \<dots>, p\<^sub>n"} by simultaneous
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   269
  higher-order matching against terms @{text "t\<^sub>1, \<dots>, t\<^sub>n"}.
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   270
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   271
  \<^descr> @{text "(\<IS> p\<^sub>1 \<dots> p\<^sub>n)"} resembles @{command "let"}, but
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   272
  matches @{text "p\<^sub>1, \<dots>, p\<^sub>n"} against the preceding statement.  Also
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   273
  note that @{keyword "is"} is not a separate command, but part of
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   274
  others (such as @{command "assume"}, @{command "have"} etc.).
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   275
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   276
  \end{description}
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   277
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   278
  Some \emph{implicit} term abbreviations\index{term abbreviations}
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   279
  for goals and facts are available as well.  For any open goal,
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   280
  @{variable_ref thesis} refers to its object-level statement,
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   281
  abstracted over any meta-level parameters (if present).  Likewise,
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   282
  @{variable_ref this} is bound for fact statements resulting from
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   283
  assumptions or finished goals.  In case @{variable this} refers to
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   284
  an object-logic statement that is an application @{text "f t"}, then
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   285
  @{text t} is bound to the special text variable ``@{variable "\<dots>"}''
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   286
  (three dots).  The canonical application of this convenience are
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   287
  calculational proofs (see \secref{sec:calculation}).
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   288
\<close>
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   289
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   290
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   291
subsection \<open>Facts and forward chaining \label{sec:proof-facts}\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   292
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   293
text \<open>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   294
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   295
    @{command_def "note"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   296
    @{command_def "then"} & : & @{text "proof(state) \<rightarrow> proof(chain)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   297
    @{command_def "from"} & : & @{text "proof(state) \<rightarrow> proof(chain)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   298
    @{command_def "with"} & : & @{text "proof(state) \<rightarrow> proof(chain)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   299
    @{command_def "using"} & : & @{text "proof(prove) \<rightarrow> proof(prove)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   300
    @{command_def "unfolding"} & : & @{text "proof(prove) \<rightarrow> proof(prove)"} \\
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   301
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   302
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   303
  New facts are established either by assumption or proof of local
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   304
  statements.  Any fact will usually be involved in further proofs,
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   305
  either as explicit arguments of proof methods, or when forward
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   306
  chaining towards the next goal via @{command "then"} (and variants);
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   307
  @{command "from"} and @{command "with"} are composite forms
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   308
  involving @{command "note"}.  The @{command "using"} elements
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   309
  augments the collection of used facts \emph{after} a goal has been
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   310
  stated.  Note that the special theorem name @{fact_ref this} refers
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   311
  to the most recently established facts, but only \emph{before}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   312
  issuing a follow-up claim.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   313
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   314
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   315
    @@{command note} (@{syntax thmdef}? @{syntax thmrefs} + @'and')
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   316
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   317
    (@@{command from} | @@{command with} | @@{command using} | @@{command unfolding})
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   318
      (@{syntax thmrefs} + @'and')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   319
  \<close>}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   320
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   321
  \begin{description}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   322
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   323
  \<^descr> @{command "note"}~@{text "a = b\<^sub>1 \<dots> b\<^sub>n"} recalls existing facts
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   324
  @{text "b\<^sub>1, \<dots>, b\<^sub>n"}, binding the result as @{text a}.  Note that
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   325
  attributes may be involved as well, both on the left and right hand
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   326
  sides.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   327
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   328
  \<^descr> @{command "then"} indicates forward chaining by the current
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   329
  facts in order to establish the goal to be claimed next.  The
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   330
  initial proof method invoked to refine that will be offered the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   331
  facts to do ``anything appropriate'' (see also
42626
6ac8c55c657e eliminated some duplicate "def" positions;
wenzelm
parents: 42617
diff changeset
   332
  \secref{sec:proof-steps}).  For example, method @{method (Pure) rule}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   333
  (see \secref{sec:pure-meth-att}) would typically do an elimination
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   334
  rather than an introduction.  Automatic methods usually insert the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   335
  facts into the goal state before operation.  This provides a simple
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   336
  scheme to control relevance of facts in automated proof search.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   337
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   338
  \<^descr> @{command "from"}~@{text b} abbreviates ``@{command
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   339
  "note"}~@{text b}~@{command "then"}''; thus @{command "then"} is
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   340
  equivalent to ``@{command "from"}~@{text this}''.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   341
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   342
  \<^descr> @{command "with"}~@{text "b\<^sub>1 \<dots> b\<^sub>n"} abbreviates ``@{command
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   343
  "from"}~@{text "b\<^sub>1 \<dots> b\<^sub>n \<AND> this"}''; thus the forward chaining
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   344
  is from earlier facts together with the current ones.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   345
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   346
  \<^descr> @{command "using"}~@{text "b\<^sub>1 \<dots> b\<^sub>n"} augments the facts being
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   347
  currently indicated for use by a subsequent refinement step (such as
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   348
  @{command_ref "apply"} or @{command_ref "proof"}).
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   349
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   350
  \<^descr> @{command "unfolding"}~@{text "b\<^sub>1 \<dots> b\<^sub>n"} is structurally
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   351
  similar to @{command "using"}, but unfolds definitional equations
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   352
  @{text "b\<^sub>1, \<dots> b\<^sub>n"} throughout the goal state and facts.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   353
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   354
  \end{description}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   355
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   356
  Forward chaining with an empty list of theorems is the same as not
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   357
  chaining at all.  Thus ``@{command "from"}~@{text nothing}'' has no
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   358
  effect apart from entering @{text "prove(chain)"} mode, since
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   359
  @{fact_ref nothing} is bound to the empty list of theorems.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   360
42626
6ac8c55c657e eliminated some duplicate "def" positions;
wenzelm
parents: 42617
diff changeset
   361
  Basic proof methods (such as @{method_ref (Pure) rule}) expect multiple
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   362
  facts to be given in their proper order, corresponding to a prefix
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   363
  of the premises of the rule involved.  Note that positions may be
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   364
  easily skipped using something like @{command "from"}~@{text "_
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   365
  \<AND> a \<AND> b"}, for example.  This involves the trivial rule
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   366
  @{text "PROP \<psi> \<Longrightarrow> PROP \<psi>"}, which is bound in Isabelle/Pure as
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   367
  ``@{fact_ref "_"}'' (underscore).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   368
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   369
  Automated methods (such as @{method simp} or @{method auto}) just
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   370
  insert any given facts before their usual operation.  Depending on
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   371
  the kind of procedure involved, the order of facts is less
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   372
  significant here.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   373
\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   374
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   375
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   376
subsection \<open>Goals \label{sec:goals}\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   377
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   378
text \<open>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   379
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   380
    @{command_def "lemma"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   381
    @{command_def "theorem"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   382
    @{command_def "corollary"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\
61338
de610e8df459 added 'proposition' command;
wenzelm
parents: 61337
diff changeset
   383
    @{command_def "proposition"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\
61337
4645502c3c64 fewer aliases for toplevel theorem statements;
wenzelm
parents: 61166
diff changeset
   384
    @{command_def "schematic_goal"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   385
    @{command_def "have"} & : & @{text "proof(state) | proof(chain) \<rightarrow> proof(prove)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   386
    @{command_def "show"} & : & @{text "proof(state) | proof(chain) \<rightarrow> proof(prove)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   387
    @{command_def "hence"} & : & @{text "proof(state) \<rightarrow> proof(prove)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   388
    @{command_def "thus"} & : & @{text "proof(state) \<rightarrow> proof(prove)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   389
    @{command_def "print_statement"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   390
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   391
61338
de610e8df459 added 'proposition' command;
wenzelm
parents: 61337
diff changeset
   392
  From a theory context, proof mode is entered by an initial goal command
de610e8df459 added 'proposition' command;
wenzelm
parents: 61337
diff changeset
   393
  such as @{command "lemma"}. Within a proof context, new claims may be
de610e8df459 added 'proposition' command;
wenzelm
parents: 61337
diff changeset
   394
  introduced locally; there are variants to interact with the overall proof
de610e8df459 added 'proposition' command;
wenzelm
parents: 61337
diff changeset
   395
  structure specifically, such as @{command have} or @{command show}.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   396
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   397
  Goals may consist of multiple statements, resulting in a list of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   398
  facts eventually.  A pending multi-goal is internally represented as
28856
5e009a80fe6d Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents: 28838
diff changeset
   399
  a meta-level conjunction (@{text "&&&"}), which is usually
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   400
  split into the corresponding number of sub-goals prior to an initial
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   401
  method application, via @{command_ref "proof"}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   402
  (\secref{sec:proof-steps}) or @{command_ref "apply"}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   403
  (\secref{sec:tactic-commands}).  The @{method_ref induct} method
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   404
  covered in \secref{sec:cases-induct} acts on multiple claims
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   405
  simultaneously.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   406
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   407
  Claims at the theory level may be either in short or long form.  A
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   408
  short goal merely consists of several simultaneous propositions
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   409
  (often just one).  A long goal includes an explicit context
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   410
  specification for the subsequent conclusion, involving local
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   411
  parameters and assumptions.  Here the role of each part of the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   412
  statement is explicitly marked by separate keywords (see also
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   413
  \secref{sec:locale}); the local assumptions being introduced here
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   414
  are available as @{fact_ref assms} in the proof.  Moreover, there
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   415
  are two kinds of conclusions: @{element_def "shows"} states several
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   416
  simultaneous propositions (essentially a big conjunction), while
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   417
  @{element_def "obtains"} claims several simultaneous simultaneous
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   418
  contexts of (essentially a big disjunction of eliminated parameters
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   419
  and assumptions, cf.\ \secref{sec:obtain}).
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   420
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   421
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   422
    (@@{command lemma} | @@{command theorem} | @@{command corollary} |
61338
de610e8df459 added 'proposition' command;
wenzelm
parents: 61337
diff changeset
   423
     @@{command proposition} | @@{command schematic_goal}) (stmt | statement)
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   424
    ;
60406
12cc54fac9b0 allow for_fixes for 'have', 'show' etc.;
wenzelm
parents: 60371
diff changeset
   425
    (@@{command have} | @@{command show} | @@{command hence} | @@{command thus})
60555
51a6997b1384 support 'when' statement, which corresponds to 'presume';
wenzelm
parents: 60484
diff changeset
   426
      stmt cond_stmt @{syntax for_fixes}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   427
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   428
    @@{command print_statement} @{syntax modes}? @{syntax thmrefs}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   429
    ;
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   430
60406
12cc54fac9b0 allow for_fixes for 'have', 'show' etc.;
wenzelm
parents: 60371
diff changeset
   431
    stmt: (@{syntax props} + @'and')
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   432
    ;
60555
51a6997b1384 support 'when' statement, which corresponds to 'presume';
wenzelm
parents: 60484
diff changeset
   433
    cond_stmt: ((@'if' | @'when') stmt)?
51a6997b1384 support 'when' statement, which corresponds to 'presume';
wenzelm
parents: 60484
diff changeset
   434
    ;
59786
wenzelm
parents: 59785
diff changeset
   435
    statement: @{syntax thmdecl}? (@{syntax_ref "includes"}?) (@{syntax context_elem} *) \<newline>
wenzelm
parents: 59785
diff changeset
   436
      conclusion
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   437
    ;
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
   438
    conclusion: @'shows' stmt | @'obtains' @{syntax obtain_clauses}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   439
    ;
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
   440
    @{syntax_def obtain_clauses}: (@{syntax par_name}? obtain_case + '|')
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
   441
    ;
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
   442
    @{syntax_def obtain_case}: (@{syntax vars} + @'and') @'where'
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
   443
      (@{syntax thmdecl}? (@{syntax prop}+) + @'and')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   444
  \<close>}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   445
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   446
  \begin{description}
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   447
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   448
  \<^descr> @{command "lemma"}~@{text "a: \<phi>"} enters proof mode with
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   449
  @{text \<phi>} as main goal, eventually resulting in some fact @{text "\<turnstile>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   450
  \<phi>"} to be put back into the target context.  An additional @{syntax
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   451
  context} specification may build up an initial proof context for the
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   452
  subsequent claim; this includes local definitions and syntax as
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 46281
diff changeset
   453
  well, see also @{syntax "includes"} in \secref{sec:bundle} and
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 46281
diff changeset
   454
  @{syntax context_elem} in \secref{sec:locale}.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   455
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   456
  \<^descr> @{command "theorem"}, @{command "corollary"}, and @{command
61338
de610e8df459 added 'proposition' command;
wenzelm
parents: 61337
diff changeset
   457
  "proposition"} are the same as @{command "lemma"}. The different command
de610e8df459 added 'proposition' command;
wenzelm
parents: 61337
diff changeset
   458
  names merely serve as a formal comment in the theory source.
36320
549be64e890f cover 'schematic_lemma' etc.;
wenzelm
parents: 30547
diff changeset
   459
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   460
  \<^descr> @{command "schematic_goal"} is similar to @{command "theorem"},
61337
4645502c3c64 fewer aliases for toplevel theorem statements;
wenzelm
parents: 61166
diff changeset
   461
  but allows the statement to contain unbound schematic variables.
36320
549be64e890f cover 'schematic_lemma' etc.;
wenzelm
parents: 30547
diff changeset
   462
549be64e890f cover 'schematic_lemma' etc.;
wenzelm
parents: 30547
diff changeset
   463
  Under normal circumstances, an Isar proof text needs to specify
549be64e890f cover 'schematic_lemma' etc.;
wenzelm
parents: 30547
diff changeset
   464
  claims explicitly.  Schematic goals are more like goals in Prolog,
549be64e890f cover 'schematic_lemma' etc.;
wenzelm
parents: 30547
diff changeset
   465
  where certain results are synthesized in the course of reasoning.
549be64e890f cover 'schematic_lemma' etc.;
wenzelm
parents: 30547
diff changeset
   466
  With schematic statements, the inherent compositionality of Isar
549be64e890f cover 'schematic_lemma' etc.;
wenzelm
parents: 30547
diff changeset
   467
  proofs is lost, which also impacts performance, because proof
549be64e890f cover 'schematic_lemma' etc.;
wenzelm
parents: 30547
diff changeset
   468
  checking is forced into sequential mode.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   469
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   470
  \<^descr> @{command "have"}~@{text "a: \<phi>"} claims a local goal,
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   471
  eventually resulting in a fact within the current logical context.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   472
  This operation is completely independent of any pending sub-goals of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   473
  an enclosing goal statements, so @{command "have"} may be freely
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   474
  used for experimental exploration of potential results within a
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   475
  proof body.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   476
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   477
  \<^descr> @{command "show"}~@{text "a: \<phi>"} is like @{command
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   478
  "have"}~@{text "a: \<phi>"} plus a second stage to refine some pending
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   479
  sub-goal for each one of the finished result, after having been
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   480
  exported into the corresponding context (at the head of the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   481
  sub-proof of this @{command "show"} command).
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   482
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   483
  To accommodate interactive debugging, resulting rules are printed
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   484
  before being applied internally.  Even more, interactive execution
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   485
  of @{command "show"} predicts potential failure and displays the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   486
  resulting error as a warning beforehand.  Watch out for the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   487
  following message:
61408
9020a3ba6c9a @{verbatim [display]} supersedes old alltt/ttbox;
wenzelm
parents: 61338
diff changeset
   488
  @{verbatim [display] \<open>Local statement fails to refine any pending goal\<close>}
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   489
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   490
  \<^descr> @{command "hence"} abbreviates ``@{command "then"}~@{command
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   491
  "have"}'', i.e.\ claims a local goal to be proven by forward
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   492
  chaining the current facts.  Note that @{command "hence"} is also
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   493
  equivalent to ``@{command "from"}~@{text this}~@{command "have"}''.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   494
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   495
  \<^descr> @{command "thus"} abbreviates ``@{command "then"}~@{command
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   496
  "show"}''.  Note that @{command "thus"} is also equivalent to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   497
  ``@{command "from"}~@{text this}~@{command "show"}''.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   498
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   499
  \<^descr> @{command "print_statement"}~@{text a} prints facts from the
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   500
  current theory or proof context in long statement form, according to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   501
  the syntax for @{command "lemma"} given above.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   502
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   503
  \end{description}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   504
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   505
  Any goal statement causes some term abbreviations (such as
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   506
  @{variable_ref "?thesis"}) to be bound automatically, see also
26922
c795d4b706b1 removed obsolete case rule_context;
wenzelm
parents: 26901
diff changeset
   507
  \secref{sec:term-abbrev}.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   508
60555
51a6997b1384 support 'when' statement, which corresponds to 'presume';
wenzelm
parents: 60484
diff changeset
   509
  Structured goal statements involving @{keyword_ref "if"} or @{keyword_ref
51a6997b1384 support 'when' statement, which corresponds to 'presume';
wenzelm
parents: 60484
diff changeset
   510
  "when"} define the special fact @{fact_ref that} to refer to these
51a6997b1384 support 'when' statement, which corresponds to 'presume';
wenzelm
parents: 60484
diff changeset
   511
  assumptions in the proof body. The user may provide separate names
51a6997b1384 support 'when' statement, which corresponds to 'presume';
wenzelm
parents: 60484
diff changeset
   512
  according to the syntax of the statement.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   513
\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   514
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   515
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   516
section \<open>Calculational reasoning \label{sec:calculation}\<close>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   517
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   518
text \<open>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   519
  \begin{matharray}{rcl}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   520
    @{command_def "also"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   521
    @{command_def "finally"} & : & @{text "proof(state) \<rightarrow> proof(chain)"} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   522
    @{command_def "moreover"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   523
    @{command_def "ultimately"} & : & @{text "proof(state) \<rightarrow> proof(chain)"} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   524
    @{command_def "print_trans_rules"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   525
    @{attribute trans} & : & @{text attribute} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   526
    @{attribute sym} & : & @{text attribute} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   527
    @{attribute symmetric} & : & @{text attribute} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   528
  \end{matharray}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   529
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   530
  Calculational proof is forward reasoning with implicit application
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   531
  of transitivity rules (such those of @{text "="}, @{text "\<le>"},
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   532
  @{text "<"}).  Isabelle/Isar maintains an auxiliary fact register
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   533
  @{fact_ref calculation} for accumulating results obtained by
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   534
  transitivity composed with the current result.  Command @{command
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   535
  "also"} updates @{fact calculation} involving @{fact this}, while
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   536
  @{command "finally"} exhibits the final @{fact calculation} by
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   537
  forward chaining towards the next goal statement.  Both commands
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   538
  require valid current facts, i.e.\ may occur only after commands
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   539
  that produce theorems such as @{command "assume"}, @{command
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   540
  "note"}, or some finished proof of @{command "have"}, @{command
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   541
  "show"} etc.  The @{command "moreover"} and @{command "ultimately"}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   542
  commands are similar to @{command "also"} and @{command "finally"},
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   543
  but only collect further results in @{fact calculation} without
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   544
  applying any rules yet.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   545
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   546
  Also note that the implicit term abbreviation ``@{text "\<dots>"}'' has
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   547
  its canonical application with calculational proofs.  It refers to
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   548
  the argument of the preceding statement. (The argument of a curried
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   549
  infix expression happens to be its right-hand side.)
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   550
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   551
  Isabelle/Isar calculations are implicitly subject to block structure
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   552
  in the sense that new threads of calculational reasoning are
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   553
  commenced for any new block (as opened by a local goal, for
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   554
  example).  This means that, apart from being able to nest
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   555
  calculations, there is no separate \emph{begin-calculation} command
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   556
  required.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   557
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
   558
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
   559
  The Isar calculation proof commands may be defined as
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   560
  follows:\footnote{We suppress internal bookkeeping such as proper
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   561
  handling of block-structure.}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   562
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   563
  \begin{matharray}{rcl}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   564
    @{command "also"}@{text "\<^sub>0"} & \equiv & @{command "note"}~@{text "calculation = this"} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   565
    @{command "also"}@{text "\<^sub>n+1"} & \equiv & @{command "note"}~@{text "calculation = trans [OF calculation this]"} \\[0.5ex]
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   566
    @{command "finally"} & \equiv & @{command "also"}~@{command "from"}~@{text calculation} \\[0.5ex]
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   567
    @{command "moreover"} & \equiv & @{command "note"}~@{text "calculation = calculation this"} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   568
    @{command "ultimately"} & \equiv & @{command "moreover"}~@{command "from"}~@{text calculation} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   569
  \end{matharray}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   570
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   571
  @{rail \<open>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   572
    (@@{command also} | @@{command finally}) ('(' @{syntax thmrefs} ')')?
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   573
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   574
    @@{attribute trans} (() | 'add' | 'del')
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   575
  \<close>}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   576
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   577
  \begin{description}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   578
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   579
  \<^descr> @{command "also"}~@{text "(a\<^sub>1 \<dots> a\<^sub>n)"} maintains the auxiliary
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   580
  @{fact calculation} register as follows.  The first occurrence of
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   581
  @{command "also"} in some calculational thread initializes @{fact
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   582
  calculation} by @{fact this}. Any subsequent @{command "also"} on
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   583
  the same level of block-structure updates @{fact calculation} by
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   584
  some transitivity rule applied to @{fact calculation} and @{fact
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   585
  this} (in that order).  Transitivity rules are picked from the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   586
  current context, unless alternative rules are given as explicit
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   587
  arguments.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   588
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   589
  \<^descr> @{command "finally"}~@{text "(a\<^sub>1 \<dots> a\<^sub>n)"} maintaining @{fact
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   590
  calculation} in the same way as @{command "also"}, and concludes the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   591
  current calculational thread.  The final result is exhibited as fact
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   592
  for forward chaining towards the next goal. Basically, @{command
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   593
  "finally"} just abbreviates @{command "also"}~@{command
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   594
  "from"}~@{fact calculation}.  Typical idioms for concluding
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   595
  calculational proofs are ``@{command "finally"}~@{command
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   596
  "show"}~@{text ?thesis}~@{command "."}'' and ``@{command
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   597
  "finally"}~@{command "have"}~@{text \<phi>}~@{command "."}''.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   598
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   599
  \<^descr> @{command "moreover"} and @{command "ultimately"} are
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   600
  analogous to @{command "also"} and @{command "finally"}, but collect
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   601
  results only, without applying rules.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   602
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   603
  \<^descr> @{command "print_trans_rules"} prints the list of transitivity
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   604
  rules (for calculational commands @{command "also"} and @{command
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   605
  "finally"}) and symmetry rules (for the @{attribute symmetric}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   606
  operation and single step elimination patters) of the current
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   607
  context.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   608
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   609
  \<^descr> @{attribute trans} declares theorems as transitivity rules.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   610
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   611
  \<^descr> @{attribute sym} declares symmetry rules, as well as
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   612
  @{attribute "Pure.elim"}@{text "?"} rules.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   613
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   614
  \<^descr> @{attribute symmetric} resolves a theorem with some rule
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   615
  declared as @{attribute sym} in the current context.  For example,
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   616
  ``@{command "assume"}~@{text "[symmetric]: x = y"}'' produces a
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   617
  swapped fact derived from that assumption.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   618
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   619
  In structured proof texts it is often more appropriate to use an
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   620
  explicit single-step elimination proof, such as ``@{command
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   621
  "assume"}~@{text "x = y"}~@{command "then"}~@{command "have"}~@{text
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   622
  "y = x"}~@{command ".."}''.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   623
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   624
  \end{description}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   625
\<close>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   626
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   627
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   628
section \<open>Refinement steps\<close>
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   629
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   630
subsection \<open>Proof method expressions \label{sec:proof-meth}\<close>
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   631
59660
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   632
text \<open>Proof methods are either basic ones, or expressions composed of
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   633
  methods via ``@{verbatim ","}'' (sequential composition), ``@{verbatim
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   634
  ";"}'' (structural composition), ``@{verbatim "|"}'' (alternative
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   635
  choices), ``@{verbatim "?"}'' (try), ``@{verbatim "+"}'' (repeat at least
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   636
  once), ``@{verbatim "["}@{text n}@{verbatim "]"}'' (restriction to first
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   637
  @{text n} subgoals). In practice, proof methods are usually just a comma
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   638
  separated list of @{syntax nameref}~@{syntax args} specifications. Note
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   639
  that parentheses may be dropped for single method specifications (with no
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   640
  arguments). The syntactic precedence of method combinators is @{verbatim
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   641
  "|"} @{verbatim ";"} @{verbatim ","} @{verbatim "[]"} @{verbatim "+"}
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   642
  @{verbatim "?"} (from low to high).
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   643
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   644
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   645
    @{syntax_def method}:
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   646
      (@{syntax nameref} | '(' methods ')') (() | '?' | '+' | '[' @{syntax nat}? ']')
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   647
    ;
59660
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   648
    methods: (@{syntax nameref} @{syntax args} | @{syntax method}) + (',' | ';' | '|')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   649
  \<close>}
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   650
59660
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   651
  Regular Isar proof methods do \emph{not} admit direct goal addressing, but
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   652
  refer to the first subgoal or to all subgoals uniformly. Nonetheless,
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   653
  the subsequent mechanisms allow to imitate the effect of subgoal
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   654
  addressing that is known from ML tactics.
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   655
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
   656
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
   657
  Goal \emph{restriction} means the proof state is wrapped-up in a
59660
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   658
  way that certain subgoals are exposed, and other subgoals are ``parked''
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   659
  elsewhere. Thus a proof method has no other chance than to operate on the
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   660
  subgoals that are presently exposed.
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   661
59660
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   662
  Structural composition ``@{text m\<^sub>1}@{verbatim ";"}~@{text m\<^sub>2}'' means
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   663
  that method @{text m\<^sub>1} is applied with restriction to the first subgoal,
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   664
  then @{text m\<^sub>2} is applied consecutively with restriction to each subgoal
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   665
  that has newly emerged due to @{text m\<^sub>1}. This is analogous to the tactic
59992
d8db5172c23f make SML/NJ more happy;
wenzelm
parents: 59905
diff changeset
   666
  combinator @{ML_op THEN_ALL_NEW} in Isabelle/ML, see also @{cite
59660
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   667
  "isabelle-implementation"}. For example, @{text "(rule r; blast)"} applies
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   668
  rule @{text "r"} and then solves all new subgoals by @{text blast}.
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   669
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   670
  Moreover, the explicit goal restriction operator ``@{text "[n]"}'' exposes
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   671
  only the first @{text n} subgoals (which need to exist), with default
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   672
  @{text "n = 1"}. For example, the method expression ``@{text
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   673
  "simp_all[3]"}'' simplifies the first three subgoals, while ``@{text
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   674
  "(rule r, simp_all)[]"}'' simplifies all new goals that emerge from
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   675
  applying rule @{text "r"} to the originally first one.
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   676
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
   677
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
   678
  Improper methods, notably tactic emulations, offer low-level goal
59660
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   679
  addressing as explicit argument to the individual tactic being involved.
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   680
  Here ``@{text "[!]"}'' refers to all goals, and ``@{text "[n-]"}'' to all
49e498cedd02 support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents: 58619
diff changeset
   681
  goals starting from @{text "n"}.
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   682
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   683
  @{rail \<open>
42705
528a2ba8fa74 tuned some syntax names;
wenzelm
parents: 42704
diff changeset
   684
    @{syntax_def goal_spec}:
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   685
      '[' (@{syntax nat} '-' @{syntax nat} | @{syntax nat} '-' | @{syntax nat} | '!' ) ']'
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   686
  \<close>}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   687
\<close>
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   688
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27141
diff changeset
   689
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   690
subsection \<open>Initial and terminal proof steps \label{sec:proof-steps}\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   691
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   692
text \<open>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   693
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   694
    @{command_def "proof"} & : & @{text "proof(prove) \<rightarrow> proof(state)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   695
    @{command_def "qed"} & : & @{text "proof(state) \<rightarrow> proof(state) | local_theory | theory"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   696
    @{command_def "by"} & : & @{text "proof(prove) \<rightarrow> proof(state) | local_theory | theory"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   697
    @{command_def ".."} & : & @{text "proof(prove) \<rightarrow> proof(state) | local_theory | theory"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   698
    @{command_def "."} & : & @{text "proof(prove) \<rightarrow> proof(state) | local_theory | theory"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   699
    @{command_def "sorry"} & : & @{text "proof(prove) \<rightarrow> proof(state) | local_theory | theory"} \\
60618
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   700
    @{method_def standard} & : & @{text method} \\
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   701
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   702
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   703
  Arbitrary goal refinement via tactics is considered harmful.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   704
  Structured proof composition in Isar admits proof methods to be
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   705
  invoked in two places only.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   706
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   707
  \begin{enumerate}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   708
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
   709
  \<^enum> An \emph{initial} refinement step @{command_ref
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   710
  "proof"}~@{text "m\<^sub>1"} reduces a newly stated goal to a number
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   711
  of sub-goals that are to be solved later.  Facts are passed to
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   712
  @{text "m\<^sub>1"} for forward chaining, if so indicated by @{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   713
  "proof(chain)"} mode.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   714
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
   715
  \<^enum> A \emph{terminal} conclusion step @{command_ref "qed"}~@{text
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   716
  "m\<^sub>2"} is intended to solve remaining goals.  No facts are
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   717
  passed to @{text "m\<^sub>2"}.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   718
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   719
  \end{enumerate}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   720
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   721
  The only other (proper) way to affect pending goals in a proof body
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   722
  is by @{command_ref "show"}, which involves an explicit statement of
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   723
  what is to be solved eventually.  Thus we avoid the fundamental
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   724
  problem of unstructured tactic scripts that consist of numerous
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   725
  consecutive goal transformations, with invisible effects.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   726
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
   727
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
   728
  As a general rule of thumb for good proof style, initial
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   729
  proof methods should either solve the goal completely, or constitute
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   730
  some well-understood reduction to new sub-goals.  Arbitrary
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   731
  automatic proof tools that are prone leave a large number of badly
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   732
  structured sub-goals are no help in continuing the proof document in
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   733
  an intelligible manner.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   734
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   735
  Unless given explicitly by the user, the default initial method is
60618
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   736
  @{method standard}, which subsumes at least @{method_ref (Pure) rule} or
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   737
  its classical variant @{method_ref (HOL) rule}. These methods apply a
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   738
  single standard elimination or introduction rule according to the topmost
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   739
  logical connective involved. There is no separate default terminal method.
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   740
  Any remaining goals are always solved by assumption in the very last step.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   741
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   742
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   743
    @@{command proof} method?
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   744
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   745
    @@{command qed} method?
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   746
    ;
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   747
    @@{command "by"} method method?
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   748
    ;
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   749
    (@@{command "."} | @@{command ".."} | @@{command sorry})
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   750
  \<close>}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   751
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   752
  \begin{description}
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   753
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   754
  \<^descr> @{command "proof"}~@{text "m\<^sub>1"} refines the goal by proof
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   755
  method @{text "m\<^sub>1"}; facts for forward chaining are passed if so
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   756
  indicated by @{text "proof(chain)"} mode.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   757
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   758
  \<^descr> @{command "qed"}~@{text "m\<^sub>2"} refines any remaining goals by
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   759
  proof method @{text "m\<^sub>2"} and concludes the sub-proof by assumption.
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   760
  If the goal had been @{text "show"} (or @{text "thus"}), some
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   761
  pending sub-goal is solved as well by the rule resulting from the
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   762
  result \emph{exported} into the enclosing goal context.  Thus @{text
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   763
  "qed"} may fail for two reasons: either @{text "m\<^sub>2"} fails, or the
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   764
  resulting rule does not fit to any pending goal\footnote{This
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   765
  includes any additional ``strong'' assumptions as introduced by
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   766
  @{command "assume"}.} of the enclosing context.  Debugging such a
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   767
  situation might involve temporarily changing @{command "show"} into
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   768
  @{command "have"}, or weakening the local context by replacing
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   769
  occurrences of @{command "assume"} by @{command "presume"}.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   770
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   771
  \<^descr> @{command "by"}~@{text "m\<^sub>1 m\<^sub>2"} is a \emph{terminal
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   772
  proof}\index{proof!terminal}; it abbreviates @{command
45135
5ba2f065c6f7 tuned markup
noschinl
parents: 45103
diff changeset
   773
  "proof"}~@{text "m\<^sub>1"}~@{command "qed"}~@{text "m\<^sub>2"}, but with
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   774
  backtracking across both methods.  Debugging an unsuccessful
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   775
  @{command "by"}~@{text "m\<^sub>1 m\<^sub>2"} command can be done by expanding its
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   776
  definition; in many cases @{command "proof"}~@{text "m\<^sub>1"} (or even
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   777
  @{text "apply"}~@{text "m\<^sub>1"}) is already sufficient to see the
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   778
  problem.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   779
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   780
  \<^descr> ``@{command ".."}'' is a \emph{standard
60618
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   781
  proof}\index{proof!standard}; it abbreviates @{command "by"}~@{text
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   782
  "standard"}.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   783
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   784
  \<^descr> ``@{command "."}'' is a \emph{trivial
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   785
  proof}\index{proof!trivial}; it abbreviates @{command "by"}~@{text
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   786
  "this"}.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   787
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   788
  \<^descr> @{command "sorry"} is a \emph{fake proof}\index{proof!fake}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   789
  pretending to solve the pending claim without further ado.  This
52059
2f970c7f722b proper option quick_and_dirty;
wenzelm
parents: 51077
diff changeset
   790
  only works in interactive development, or if the @{attribute
2f970c7f722b proper option quick_and_dirty;
wenzelm
parents: 51077
diff changeset
   791
  quick_and_dirty} is enabled.  Facts emerging from fake
50126
3dec88149176 theorem status about oracles/futures is no longer printed by default;
wenzelm
parents: 50109
diff changeset
   792
  proofs are not the real thing.  Internally, the derivation object is
3dec88149176 theorem status about oracles/futures is no longer printed by default;
wenzelm
parents: 50109
diff changeset
   793
  tainted by an oracle invocation, which may be inspected via the
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 57979
diff changeset
   794
  theorem status @{cite "isabelle-implementation"}.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   795
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   796
  The most important application of @{command "sorry"} is to support
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   797
  experimentation and top-down proof development.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   798
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   799
  \<^descr> @{method standard} refers to the default refinement step of some
60618
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   800
  Isar language elements (notably @{command proof} and ``@{command ".."}'').
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   801
  It is \emph{dynamically scoped}, so the behaviour depends on the
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   802
  application environment.
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   803
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   804
  In Isabelle/Pure, @{method standard} performs elementary introduction~/
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   805
  elimination steps (@{method_ref (Pure) rule}), introduction of type
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   806
  classes (@{method_ref intro_classes}) and locales (@{method_ref
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   807
  intro_locales}).
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   808
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   809
  In Isabelle/HOL, @{method standard} also takes classical rules into
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   810
  account (cf.\ \secref{sec:classical}).
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   811
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   812
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   813
\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   814
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   815
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   816
subsection \<open>Fundamental methods and attributes \label{sec:pure-meth-att}\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   817
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   818
text \<open>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   819
  The following proof methods and attributes refer to basic logical
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   820
  operations of Isar.  Further methods and attributes are provided by
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   821
  several generic and object-logic specific tools and packages (see
50109
c13dc0b1841c tuned structure of Isabelle/HOL;
wenzelm
parents: 48985
diff changeset
   822
  \chref{ch:gen-tools} and \partref{part:hol}).
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   823
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   824
  \begin{matharray}{rcl}
51077
ea0cb5ff5ae7 documentation for 'print_rules';
wenzelm
parents: 50778
diff changeset
   825
    @{command_def "print_rules"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\[0.5ex]
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   826
    @{method_def "-"} & : & @{text method} \\
61166
5976fe402824 renamed method "goals" to "goal_cases" to emphasize its meaning;
wenzelm
parents: 61164
diff changeset
   827
    @{method_def "goal_cases"} & : & @{text method} \\
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   828
    @{method_def "fact"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   829
    @{method_def "assumption"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   830
    @{method_def "this"} & : & @{text method} \\
42626
6ac8c55c657e eliminated some duplicate "def" positions;
wenzelm
parents: 42617
diff changeset
   831
    @{method_def (Pure) "rule"} & : & @{text method} \\
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   832
    @{attribute_def (Pure) "intro"} & : & @{text attribute} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   833
    @{attribute_def (Pure) "elim"} & : & @{text attribute} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   834
    @{attribute_def (Pure) "dest"} & : & @{text attribute} \\
42626
6ac8c55c657e eliminated some duplicate "def" positions;
wenzelm
parents: 42617
diff changeset
   835
    @{attribute_def (Pure) "rule"} & : & @{text attribute} \\[0.5ex]
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   836
    @{attribute_def "OF"} & : & @{text attribute} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   837
    @{attribute_def "of"} & : & @{text attribute} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   838
    @{attribute_def "where"} & : & @{text attribute} \\
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   839
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   840
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   841
  @{rail \<open>
61166
5976fe402824 renamed method "goals" to "goal_cases" to emphasize its meaning;
wenzelm
parents: 61164
diff changeset
   842
    @@{method goal_cases} (@{syntax name}*)
60578
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   843
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   844
    @@{method fact} @{syntax thmrefs}?
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   845
    ;
42626
6ac8c55c657e eliminated some duplicate "def" positions;
wenzelm
parents: 42617
diff changeset
   846
    @@{method (Pure) rule} @{syntax thmrefs}?
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   847
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   848
    rulemod: ('intro' | 'elim' | 'dest')
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   849
      ((('!' | () | '?') @{syntax nat}?) | 'del') ':' @{syntax thmrefs}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   850
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   851
    (@@{attribute intro} | @@{attribute elim} | @@{attribute dest})
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   852
      ('!' | () | '?') @{syntax nat}?
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   853
    ;
42626
6ac8c55c657e eliminated some duplicate "def" positions;
wenzelm
parents: 42617
diff changeset
   854
    @@{attribute (Pure) rule} 'del'
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   855
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
   856
    @@{attribute OF} @{syntax thmrefs}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   857
    ;
59785
4e6ab5831cc0 clarified syntax category "fixes";
wenzelm
parents: 59783
diff changeset
   858
    @@{attribute of} @{syntax insts} ('concl' ':' @{syntax insts})? @{syntax for_fixes}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   859
    ;
59853
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59786
diff changeset
   860
    @@{attribute "where"} @{syntax named_insts} @{syntax for_fixes}
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   861
  \<close>}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   862
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   863
  \begin{description}
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   864
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   865
  \<^descr> @{command "print_rules"} prints rules declared via attributes
51077
ea0cb5ff5ae7 documentation for 'print_rules';
wenzelm
parents: 50778
diff changeset
   866
  @{attribute (Pure) intro}, @{attribute (Pure) elim}, @{attribute
ea0cb5ff5ae7 documentation for 'print_rules';
wenzelm
parents: 50778
diff changeset
   867
  (Pure) dest} of Isabelle/Pure.
ea0cb5ff5ae7 documentation for 'print_rules';
wenzelm
parents: 50778
diff changeset
   868
ea0cb5ff5ae7 documentation for 'print_rules';
wenzelm
parents: 50778
diff changeset
   869
  See also the analogous @{command "print_claset"} command for similar
ea0cb5ff5ae7 documentation for 'print_rules';
wenzelm
parents: 50778
diff changeset
   870
  rule declarations of the classical reasoner
ea0cb5ff5ae7 documentation for 'print_rules';
wenzelm
parents: 50778
diff changeset
   871
  (\secref{sec:classical}).
ea0cb5ff5ae7 documentation for 'print_rules';
wenzelm
parents: 50778
diff changeset
   872
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   873
  \<^descr> ``@{method "-"}'' (minus) inserts the forward chaining facts as
60578
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   874
  premises into the goal, and nothing else.
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   875
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   876
  Note that command @{command_ref "proof"} without any method actually
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   877
  performs a single reduction step using the @{method_ref (Pure) rule}
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   878
  method; thus a plain \emph{do-nothing} proof step would be ``@{command
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   879
  "proof"}~@{text "-"}'' rather than @{command "proof"} alone.
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   880
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   881
  \<^descr> @{method "goal_cases"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} turns the current subgoals
61164
2a03ae772c60 method "goals" ignores facts;
wenzelm
parents: 60618
diff changeset
   882
  into cases within the context (see also \secref{sec:cases-induct}). The
2a03ae772c60 method "goals" ignores facts;
wenzelm
parents: 60618
diff changeset
   883
  specified case names are used if present; otherwise cases are numbered
2a03ae772c60 method "goals" ignores facts;
wenzelm
parents: 60618
diff changeset
   884
  starting from 1.
60578
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   885
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   886
  Invoking cases in the subsequent proof body via the @{command_ref case}
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   887
  command will @{command fix} goal parameters, @{command assume} goal
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   888
  premises, and @{command let} variable @{variable_ref ?case} refer to the
c708dafe2220 added method "goals" for proper subgoal cases;
wenzelm
parents: 60565
diff changeset
   889
  conclusion.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   890
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   891
  \<^descr> @{method "fact"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} composes some fact from
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   892
  @{text "a\<^sub>1, \<dots>, a\<^sub>n"} (or implicitly from the current proof context)
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   893
  modulo unification of schematic type and term variables.  The rule
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   894
  structure is not taken into account, i.e.\ meta-level implication is
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   895
  considered atomic.  This is the same principle underlying literal
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   896
  facts (cf.\ \secref{sec:syn-att}): ``@{command "have"}~@{text
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   897
  "\<phi>"}~@{command "by"}~@{text fact}'' is equivalent to ``@{command
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   898
  "note"}~@{verbatim "`"}@{text \<phi>}@{verbatim "`"}'' provided that
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   899
  @{text "\<turnstile> \<phi>"} is an instance of some known @{text "\<turnstile> \<phi>"} in the
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   900
  proof context.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   901
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   902
  \<^descr> @{method assumption} solves some goal by a single assumption
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   903
  step.  All given facts are guaranteed to participate in the
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   904
  refinement; this means there may be only 0 or 1 in the first place.
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   905
  Recall that @{command "qed"} (\secref{sec:proof-steps}) already
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   906
  concludes any remaining sub-goals by assumption, so structured
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   907
  proofs usually need not quote the @{method assumption} method at
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   908
  all.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   909
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   910
  \<^descr> @{method this} applies all of the current facts directly as
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   911
  rules.  Recall that ``@{command "."}'' (dot) abbreviates ``@{command
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   912
  "by"}~@{text this}''.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   913
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   914
  \<^descr> @{method (Pure) rule}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} applies some rule given as
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   915
  argument in backward manner; facts are used to reduce the rule
42626
6ac8c55c657e eliminated some duplicate "def" positions;
wenzelm
parents: 42617
diff changeset
   916
  before applying it to the goal.  Thus @{method (Pure) rule} without facts
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   917
  is plain introduction, while with facts it becomes elimination.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   918
60618
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   919
  When no arguments are given, the @{method (Pure) rule} method tries to
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   920
  pick appropriate rules automatically, as declared in the current context
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   921
  using the @{attribute (Pure) intro}, @{attribute (Pure) elim}, @{attribute
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   922
  (Pure) dest} attributes (see below). This is included in the standard
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   923
  behaviour of @{command "proof"} and ``@{command ".."}'' (double-dot) steps
4c79543cc376 renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents: 60578
diff changeset
   924
  (see \secref{sec:proof-steps}).
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   925
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   926
  \<^descr> @{attribute (Pure) intro}, @{attribute (Pure) elim}, and
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   927
  @{attribute (Pure) dest} declare introduction, elimination, and
42626
6ac8c55c657e eliminated some duplicate "def" positions;
wenzelm
parents: 42617
diff changeset
   928
  destruct rules, to be used with method @{method (Pure) rule}, and similar
30169
9531eaafd781 moved method "iprover" to HOL specific part;
wenzelm
parents: 29744
diff changeset
   929
  tools.  Note that the latter will ignore rules declared with
9531eaafd781 moved method "iprover" to HOL specific part;
wenzelm
parents: 29744
diff changeset
   930
  ``@{text "?"}'', while ``@{text "!"}''  are used most aggressively.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   931
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   932
  The classical reasoner (see \secref{sec:classical}) introduces its
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   933
  own variants of these attributes; use qualified names to access the
26901
d1694ef6e7a7 fixed some Isar element markups;
wenzelm
parents: 26894
diff changeset
   934
  present versions of Isabelle/Pure, i.e.\ @{attribute (Pure)
d1694ef6e7a7 fixed some Isar element markups;
wenzelm
parents: 26894
diff changeset
   935
  "Pure.intro"}.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   936
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   937
  \<^descr> @{attribute (Pure) rule}~@{text del} undeclares introduction,
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   938
  elimination, or destruct rules.
51077
ea0cb5ff5ae7 documentation for 'print_rules';
wenzelm
parents: 50778
diff changeset
   939
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   940
  \<^descr> @{attribute OF}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} applies some theorem to all
47498
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47484
diff changeset
   941
  of the given rules @{text "a\<^sub>1, \<dots>, a\<^sub>n"} in canonical right-to-left
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47484
diff changeset
   942
  order, which means that premises stemming from the @{text "a\<^sub>i"}
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47484
diff changeset
   943
  emerge in parallel in the result, without interfering with each
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47484
diff changeset
   944
  other.  In many practical situations, the @{text "a\<^sub>i"} do not have
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47484
diff changeset
   945
  premises themselves, so @{text "rule [OF a\<^sub>1 \<dots> a\<^sub>n]"} can be actually
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47484
diff changeset
   946
  read as functional application (modulo unification).
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47484
diff changeset
   947
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47484
diff changeset
   948
  Argument positions may be effectively skipped by using ``@{text _}''
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47484
diff changeset
   949
  (underscore), which refers to the propositional identity rule in the
e3fc50c7da13 updated and clarified OF/MRS;
wenzelm
parents: 47484
diff changeset
   950
  Pure theory.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   951
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   952
  \<^descr> @{attribute of}~@{text "t\<^sub>1 \<dots> t\<^sub>n"} performs positional
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   953
  instantiation of term variables.  The terms @{text "t\<^sub>1, \<dots>, t\<^sub>n"} are
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   954
  substituted for any schematic variables occurring in a theorem from
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   955
  left to right; ``@{text _}'' (underscore) indicates to skip a
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   956
  position.  Arguments following a ``@{text "concl:"}'' specification
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   957
  refer to positions of the conclusion of a rule.
55143
04448228381d explicit eigen-context for attributes "where", "of", and corresponding read_instantiate, instantiate_tac;
wenzelm
parents: 55112
diff changeset
   958
04448228381d explicit eigen-context for attributes "where", "of", and corresponding read_instantiate, instantiate_tac;
wenzelm
parents: 55112
diff changeset
   959
  An optional context of local variables @{text "\<FOR> x\<^sub>1 \<dots> x\<^sub>m"} may
04448228381d explicit eigen-context for attributes "where", "of", and corresponding read_instantiate, instantiate_tac;
wenzelm
parents: 55112
diff changeset
   960
  be specified: the instantiated theorem is exported, and these
04448228381d explicit eigen-context for attributes "where", "of", and corresponding read_instantiate, instantiate_tac;
wenzelm
parents: 55112
diff changeset
   961
  variables become schematic (usually with some shifting of indices).
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
   962
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   963
  \<^descr> @{attribute "where"}~@{text "x\<^sub>1 = t\<^sub>1 \<AND> \<dots> x\<^sub>n = t\<^sub>n"}
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   964
  performs named instantiation of schematic type and term variables
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   965
  occurring in a theorem.  Schematic variables have to be specified on
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   966
  the left-hand side (e.g.\ @{text "?x1.3"}).  The question mark may
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   967
  be omitted if the variable name is a plain identifier without index.
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   968
  As type instantiations are inferred from term instantiations,
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   969
  explicit type instantiations are seldom necessary.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   970
55143
04448228381d explicit eigen-context for attributes "where", "of", and corresponding read_instantiate, instantiate_tac;
wenzelm
parents: 55112
diff changeset
   971
  An optional context of local variables @{text "\<FOR> x\<^sub>1 \<dots> x\<^sub>m"} may
04448228381d explicit eigen-context for attributes "where", "of", and corresponding read_instantiate, instantiate_tac;
wenzelm
parents: 55112
diff changeset
   972
  be specified as for @{attribute "of"} above.
04448228381d explicit eigen-context for attributes "where", "of", and corresponding read_instantiate, instantiate_tac;
wenzelm
parents: 55112
diff changeset
   973
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   974
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   975
\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   976
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   977
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   978
subsection \<open>Defining proof methods\<close>
28757
7f7002ad6289 tuned section "Incorporating ML code";
wenzelm
parents: 28755
diff changeset
   979
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   980
text \<open>
28757
7f7002ad6289 tuned section "Incorporating ML code";
wenzelm
parents: 28755
diff changeset
   981
  \begin{matharray}{rcl}
57941
57200bdc2aa7 localized command 'method_setup' and 'attribute_setup';
wenzelm
parents: 56582
diff changeset
   982
    @{command_def "method_setup"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
28757
7f7002ad6289 tuned section "Incorporating ML code";
wenzelm
parents: 28755
diff changeset
   983
  \end{matharray}
7f7002ad6289 tuned section "Incorporating ML code";
wenzelm
parents: 28755
diff changeset
   984
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   985
  @{rail \<open>
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59660
diff changeset
   986
    @@{command method_setup} @{syntax name} '=' @{syntax text} @{syntax text}?
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   987
  \<close>}
28757
7f7002ad6289 tuned section "Incorporating ML code";
wenzelm
parents: 28755
diff changeset
   988
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
   989
  \begin{description}
28757
7f7002ad6289 tuned section "Incorporating ML code";
wenzelm
parents: 28755
diff changeset
   990
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   991
  \<^descr> @{command "method_setup"}~@{text "name = text description"}
57941
57200bdc2aa7 localized command 'method_setup' and 'attribute_setup';
wenzelm
parents: 56582
diff changeset
   992
  defines a proof method in the current context.  The given @{text
30547
4c2514625873 simplifief 'method_setup' command;
wenzelm
parents: 30510
diff changeset
   993
  "text"} has to be an ML expression of type
4c2514625873 simplifief 'method_setup' command;
wenzelm
parents: 30510
diff changeset
   994
  @{ML_type "(Proof.context -> Proof.method) context_parser"}, cf.\
55837
154855d9a564 clarified names of antiquotations and markup;
wenzelm
parents: 55143
diff changeset
   995
  basic parsers defined in structure @{ML_structure Args} and @{ML_structure
30547
4c2514625873 simplifief 'method_setup' command;
wenzelm
parents: 30510
diff changeset
   996
  Attrib}.  There are also combinators like @{ML METHOD} and @{ML
4c2514625873 simplifief 'method_setup' command;
wenzelm
parents: 30510
diff changeset
   997
  SIMPLE_METHOD} to turn certain tactic forms into official proof
4c2514625873 simplifief 'method_setup' command;
wenzelm
parents: 30510
diff changeset
   998
  methods; the primed versions refer to tactics with explicit goal
4c2514625873 simplifief 'method_setup' command;
wenzelm
parents: 30510
diff changeset
   999
  addressing.
28757
7f7002ad6289 tuned section "Incorporating ML code";
wenzelm
parents: 28755
diff changeset
  1000
30547
4c2514625873 simplifief 'method_setup' command;
wenzelm
parents: 30510
diff changeset
  1001
  Here are some example method definitions:
28757
7f7002ad6289 tuned section "Incorporating ML code";
wenzelm
parents: 28755
diff changeset
  1002
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28757
diff changeset
  1003
  \end{description}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1004
\<close>
28757
7f7002ad6289 tuned section "Incorporating ML code";
wenzelm
parents: 28755
diff changeset
  1005
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59853
diff changeset
  1006
(*<*)experiment begin(*>*)
58619
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1007
  method_setup my_method1 =
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1008
    \<open>Scan.succeed (K (SIMPLE_METHOD' (fn i: int => no_tac)))\<close>
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1009
    "my first method (without any arguments)"
30547
4c2514625873 simplifief 'method_setup' command;
wenzelm
parents: 30510
diff changeset
  1010
58619
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1011
  method_setup my_method2 =
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1012
    \<open>Scan.succeed (fn ctxt: Proof.context =>
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1013
      SIMPLE_METHOD' (fn i: int => no_tac))\<close>
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1014
    "my second method (with context)"
30547
4c2514625873 simplifief 'method_setup' command;
wenzelm
parents: 30510
diff changeset
  1015
58619
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1016
  method_setup my_method3 =
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1017
    \<open>Attrib.thms >> (fn thms: thm list => fn ctxt: Proof.context =>
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1018
      SIMPLE_METHOD' (fn i: int => no_tac))\<close>
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1019
    "my third method (with theorem arguments and context)"
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59853
diff changeset
  1020
(*<*)end(*>*)
30547
4c2514625873 simplifief 'method_setup' command;
wenzelm
parents: 30510
diff changeset
  1021
28757
7f7002ad6289 tuned section "Incorporating ML code";
wenzelm
parents: 28755
diff changeset
  1022
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1023
section \<open>Proof by cases and induction \label{sec:cases-induct}\<close>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1024
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1025
subsection \<open>Rule contexts\<close>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1026
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1027
text \<open>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1028
  \begin{matharray}{rcl}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1029
    @{command_def "case"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1030
    @{command_def "print_cases"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1031
    @{attribute_def case_names} & : & @{text attribute} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1032
    @{attribute_def case_conclusion} & : & @{text attribute} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1033
    @{attribute_def params} & : & @{text attribute} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1034
    @{attribute_def consumes} & : & @{text attribute} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1035
  \end{matharray}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1036
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1037
  The puristic way to build up Isar proof contexts is by explicit
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1038
  language elements like @{command "fix"}, @{command "assume"},
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1039
  @{command "let"} (see \secref{sec:proof-context}).  This is adequate
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1040
  for plain natural deduction, but easily becomes unwieldy in concrete
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1041
  verification tasks, which typically involve big induction rules with
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1042
  several cases.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1043
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1044
  The @{command "case"} command provides a shorthand to refer to a
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1045
  local context symbolically: certain proof methods provide an
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1046
  environment of named ``cases'' of the form @{text "c: x\<^sub>1, \<dots>,
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1047
  x\<^sub>m, \<phi>\<^sub>1, \<dots>, \<phi>\<^sub>n"}; the effect of ``@{command
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1048
  "case"}~@{text c}'' is then equivalent to ``@{command "fix"}~@{text
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1049
  "x\<^sub>1 \<dots> x\<^sub>m"}~@{command "assume"}~@{text "c: \<phi>\<^sub>1 \<dots>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1050
  \<phi>\<^sub>n"}''.  Term bindings may be covered as well, notably
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1051
  @{variable ?case} for the main conclusion.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1052
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1053
  By default, the ``terminology'' @{text "x\<^sub>1, \<dots>, x\<^sub>m"} of
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1054
  a case value is marked as hidden, i.e.\ there is no way to refer to
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1055
  such parameters in the subsequent proof text.  After all, original
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1056
  rule parameters stem from somewhere outside of the current proof
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1057
  text.  By using the explicit form ``@{command "case"}~@{text "(c
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1058
  y\<^sub>1 \<dots> y\<^sub>m)"}'' instead, the proof author is able to
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1059
  chose local names that fit nicely into the current context.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1060
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1061
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1062
  It is important to note that proper use of @{command
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1063
  "case"} does not provide means to peek at the current goal state,
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1064
  which is not directly observable in Isar!  Nonetheless, goal
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1065
  refinement commands do provide named cases @{text "goal\<^sub>i"}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1066
  for each subgoal @{text "i = 1, \<dots>, n"} of the resulting goal state.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1067
  Using this extra feature requires great care, because some bits of
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1068
  the internal tactical machinery intrude the proof text.  In
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1069
  particular, parameter names stemming from the left-over of automated
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1070
  reasoning tools are usually quite unpredictable.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1071
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1072
  Under normal circumstances, the text of cases emerge from standard
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1073
  elimination or induction rules, which in turn are derived from
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1074
  previous theory specifications in a canonical way (say from
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1075
  @{command "inductive"} definitions).
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1076
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1077
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1078
  Proper cases are only available if both the proof method
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1079
  and the rules involved support this.  By using appropriate
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1080
  attributes, case names, conclusions, and parameters may be also
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1081
  declared by hand.  Thus variant versions of rules that have been
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1082
  derived manually become ready to use in advanced case analysis
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1083
  later.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1084
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1085
  @{rail \<open>
60565
b7ee41f72add clarified 'case' command;
wenzelm
parents: 60555
diff changeset
  1086
    @@{command case} @{syntax thmdecl}? (nameref | '(' nameref (('_' | @{syntax name}) *) ')')
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1087
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1088
    @@{attribute case_names} ((@{syntax name} ( '[' (('_' | @{syntax name}) +) ']' ) ? ) +)
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1089
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1090
    @@{attribute case_conclusion} @{syntax name} (@{syntax name} * )
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1091
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1092
    @@{attribute params} ((@{syntax name} * ) + @'and')
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1093
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1094
    @@{attribute consumes} @{syntax int}?
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1095
  \<close>}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1096
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1097
  \begin{description}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1098
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1099
  \<^descr> @{command "case"}~@{text "a: (c x\<^sub>1 \<dots> x\<^sub>m)"} invokes a named local
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1100
  context @{text "c: x\<^sub>1, \<dots>, x\<^sub>m, \<phi>\<^sub>1, \<dots>, \<phi>\<^sub>m"}, as provided by an
60565
b7ee41f72add clarified 'case' command;
wenzelm
parents: 60555
diff changeset
  1101
  appropriate proof method (such as @{method_ref cases} and @{method_ref
b7ee41f72add clarified 'case' command;
wenzelm
parents: 60555
diff changeset
  1102
  induct}). The command ``@{command "case"}~@{text "a: (c x\<^sub>1 \<dots> x\<^sub>m)"}''
b7ee41f72add clarified 'case' command;
wenzelm
parents: 60555
diff changeset
  1103
  abbreviates ``@{command "fix"}~@{text "x\<^sub>1 \<dots> x\<^sub>m"}~@{command
b7ee41f72add clarified 'case' command;
wenzelm
parents: 60555
diff changeset
  1104
  "assume"}~@{text "a.c: \<phi>\<^sub>1 \<dots> \<phi>\<^sub>n"}''. Each local fact is qualified by the
b7ee41f72add clarified 'case' command;
wenzelm
parents: 60555
diff changeset
  1105
  prefix @{text "a"}, and all such facts are collectively bound to the name
b7ee41f72add clarified 'case' command;
wenzelm
parents: 60555
diff changeset
  1106
  @{text a}.
b7ee41f72add clarified 'case' command;
wenzelm
parents: 60555
diff changeset
  1107
b7ee41f72add clarified 'case' command;
wenzelm
parents: 60555
diff changeset
  1108
  The fact name is specification @{text a} is optional, the default is to
b7ee41f72add clarified 'case' command;
wenzelm
parents: 60555
diff changeset
  1109
  re-use @{text c}. So @{command "case"}~@{text "(c x\<^sub>1 \<dots> x\<^sub>m)"} is the same
b7ee41f72add clarified 'case' command;
wenzelm
parents: 60555
diff changeset
  1110
  as @{command "case"}~@{text "c: (c x\<^sub>1 \<dots> x\<^sub>m)"}.
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1111
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1112
  \<^descr> @{command "print_cases"} prints all local contexts of the
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1113
  current state, using Isar proof language notation.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1114
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1115
  \<^descr> @{attribute case_names}~@{text "c\<^sub>1 \<dots> c\<^sub>k"} declares names for
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1116
  the local contexts of premises of a theorem; @{text "c\<^sub>1, \<dots>, c\<^sub>k"}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1117
  refers to the \emph{prefix} of the list of premises. Each of the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1118
  cases @{text "c\<^sub>i"} can be of the form @{text "c[h\<^sub>1 \<dots> h\<^sub>n]"} where
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1119
  the @{text "h\<^sub>1 \<dots> h\<^sub>n"} are the names of the hypotheses in case @{text "c\<^sub>i"}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1120
  from left to right.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1121
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1122
  \<^descr> @{attribute case_conclusion}~@{text "c d\<^sub>1 \<dots> d\<^sub>k"} declares
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1123
  names for the conclusions of a named premise @{text c}; here @{text
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1124
  "d\<^sub>1, \<dots>, d\<^sub>k"} refers to the prefix of arguments of a logical formula
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1125
  built by nesting a binary connective (e.g.\ @{text "\<or>"}).
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1126
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1127
  Note that proof methods such as @{method induct} and @{method
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1128
  coinduct} already provide a default name for the conclusion as a
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1129
  whole.  The need to name subformulas only arises with cases that
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1130
  split into several sub-cases, as in common co-induction rules.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1131
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1132
  \<^descr> @{attribute params}~@{text "p\<^sub>1 \<dots> p\<^sub>m \<AND> \<dots> q\<^sub>1 \<dots> q\<^sub>n"} renames
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1133
  the innermost parameters of premises @{text "1, \<dots>, n"} of some
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1134
  theorem.  An empty list of names may be given to skip positions,
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1135
  leaving the present parameters unchanged.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1136
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1137
  Note that the default usage of case rules does \emph{not} directly
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1138
  expose parameters to the proof context.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1139
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1140
  \<^descr> @{attribute consumes}~@{text n} declares the number of ``major
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1141
  premises'' of a rule, i.e.\ the number of facts to be consumed when
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1142
  it is applied by an appropriate proof method.  The default value of
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1143
  @{attribute consumes} is @{text "n = 1"}, which is appropriate for
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1144
  the usual kind of cases and induction rules for inductive sets (cf.\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1145
  \secref{sec:hol-inductive}).  Rules without any @{attribute
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1146
  consumes} declaration given are treated as if @{attribute
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1147
  consumes}~@{text 0} had been specified.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1148
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1149
  A negative @{text n} is interpreted relatively to the total number
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1150
  of premises of the rule in the target context.  Thus its absolute
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1151
  value specifies the remaining number of premises, after subtracting
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1152
  the prefix of major premises as indicated above. This form of
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1153
  declaration has the technical advantage of being stable under more
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1154
  morphisms, notably those that export the result from a nested
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1155
  @{command_ref context} with additional assumptions.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1156
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1157
  Note that explicit @{attribute consumes} declarations are only
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1158
  rarely needed; this is already taken care of automatically by the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1159
  higher-level @{attribute cases}, @{attribute induct}, and
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1160
  @{attribute coinduct} declarations.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1161
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1162
  \end{description}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1163
\<close>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1164
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1165
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1166
subsection \<open>Proof methods\<close>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1167
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1168
text \<open>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1169
  \begin{matharray}{rcl}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1170
    @{method_def cases} & : & @{text method} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1171
    @{method_def induct} & : & @{text method} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1172
    @{method_def induction} & : & @{text method} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1173
    @{method_def coinduct} & : & @{text method} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1174
  \end{matharray}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1175
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1176
  The @{method cases}, @{method induct}, @{method induction},
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1177
  and @{method coinduct}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1178
  methods provide a uniform interface to common proof techniques over
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1179
  datatypes, inductive predicates (or sets), recursive functions etc.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1180
  The corresponding rules may be specified and instantiated in a
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1181
  casual manner.  Furthermore, these methods provide named local
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1182
  contexts that may be invoked via the @{command "case"} proof command
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1183
  within the subsequent proof text.  This accommodates compact proof
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1184
  texts even when reasoning about large specifications.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1185
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1186
  The @{method induct} method also provides some additional
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1187
  infrastructure in order to be applicable to structure statements
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1188
  (either using explicit meta-level connectives, or including facts
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1189
  and parameters separately).  This avoids cumbersome encoding of
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1190
  ``strengthened'' inductive statements within the object-logic.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1191
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1192
  Method @{method induction} differs from @{method induct} only in
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1193
  the names of the facts in the local context invoked by the @{command "case"}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1194
  command.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1195
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1196
  @{rail \<open>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1197
    @@{method cases} ('(' 'no_simp' ')')? \<newline>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1198
      (@{syntax insts} * @'and') rule?
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1199
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1200
    (@@{method induct} | @@{method induction})
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1201
      ('(' 'no_simp' ')')? (definsts * @'and') \<newline> arbitrary? taking? rule?
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1202
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1203
    @@{method coinduct} @{syntax insts} taking rule?
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1204
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1205
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1206
    rule: ('type' | 'pred' | 'set') ':' (@{syntax nameref} +) | 'rule' ':' (@{syntax thmref} +)
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1207
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1208
    definst: @{syntax name} ('==' | '\<equiv>') @{syntax term} | '(' @{syntax term} ')' | @{syntax inst}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1209
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1210
    definsts: ( definst * )
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1211
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1212
    arbitrary: 'arbitrary' ':' ((@{syntax term} * ) @'and' +)
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1213
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1214
    taking: 'taking' ':' @{syntax insts}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1215
  \<close>}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1216
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1217
  \begin{description}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1218
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1219
  \<^descr> @{method cases}~@{text "insts R"} applies method @{method
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1220
  rule} with an appropriate case distinction theorem, instantiated to
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1221
  the subjects @{text insts}.  Symbolic case names are bound according
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1222
  to the rule's local contexts.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1223
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1224
  The rule is determined as follows, according to the facts and
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1225
  arguments passed to the @{method cases} method:
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1226
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1227
  \<^medskip>
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1228
  \begin{tabular}{llll}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1229
    facts           &                 & arguments   & rule \\\hline
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1230
    @{text "\<turnstile> R"}   & @{method cases} &             & implicit rule @{text R} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1231
                    & @{method cases} &             & classical case split \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1232
                    & @{method cases} & @{text t}   & datatype exhaustion (type of @{text t}) \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1233
    @{text "\<turnstile> A t"} & @{method cases} & @{text "\<dots>"} & inductive predicate/set elimination (of @{text A}) \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1234
    @{text "\<dots>"}     & @{method cases} & @{text "\<dots> rule: R"} & explicit rule @{text R} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1235
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1236
  \<^medskip>
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1237
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1238
  Several instantiations may be given, referring to the \emph{suffix}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1239
  of premises of the case rule; within each premise, the \emph{prefix}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1240
  of variables is instantiated.  In most situations, only a single
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1241
  term needs to be specified; this refers to the first variable of the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1242
  last premise (it is usually the same for all cases).  The @{text
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1243
  "(no_simp)"} option can be used to disable pre-simplification of
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1244
  cases (see the description of @{method induct} below for details).
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1245
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1246
  \<^descr> @{method induct}~@{text "insts R"} and
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1247
  @{method induction}~@{text "insts R"} are analogous to the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1248
  @{method cases} method, but refer to induction rules, which are
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1249
  determined as follows:
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1250
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1251
  \<^medskip>
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1252
  \begin{tabular}{llll}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1253
    facts           &                  & arguments            & rule \\\hline
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1254
                    & @{method induct} & @{text "P x"}        & datatype induction (type of @{text x}) \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1255
    @{text "\<turnstile> A x"} & @{method induct} & @{text "\<dots>"}          & predicate/set induction (of @{text A}) \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1256
    @{text "\<dots>"}     & @{method induct} & @{text "\<dots> rule: R"} & explicit rule @{text R} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1257
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1258
  \<^medskip>
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1259
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1260
  Several instantiations may be given, each referring to some part of
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1261
  a mutual inductive definition or datatype --- only related partial
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1262
  induction rules may be used together, though.  Any of the lists of
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1263
  terms @{text "P, x, \<dots>"} refers to the \emph{suffix} of variables
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1264
  present in the induction rule.  This enables the writer to specify
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1265
  only induction variables, or both predicates and variables, for
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1266
  example.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1267
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1268
  Instantiations may be definitional: equations @{text "x \<equiv> t"}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1269
  introduce local definitions, which are inserted into the claim and
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1270
  discharged after applying the induction rule.  Equalities reappear
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1271
  in the inductive cases, but have been transformed according to the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1272
  induction principle being involved here.  In order to achieve
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1273
  practically useful induction hypotheses, some variables occurring in
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1274
  @{text t} need to be fixed (see below).  Instantiations of the form
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1275
  @{text t}, where @{text t} is not a variable, are taken as a
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1276
  shorthand for \mbox{@{text "x \<equiv> t"}}, where @{text x} is a fresh
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1277
  variable. If this is not intended, @{text t} has to be enclosed in
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1278
  parentheses.  By default, the equalities generated by definitional
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1279
  instantiations are pre-simplified using a specific set of rules,
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1280
  usually consisting of distinctness and injectivity theorems for
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1281
  datatypes. This pre-simplification may cause some of the parameters
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1282
  of an inductive case to disappear, or may even completely delete
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1283
  some of the inductive cases, if one of the equalities occurring in
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1284
  their premises can be simplified to @{text False}.  The @{text
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1285
  "(no_simp)"} option can be used to disable pre-simplification.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1286
  Additional rules to be used in pre-simplification can be declared
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1287
  using the @{attribute_def induct_simp} attribute.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1288
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1289
  The optional ``@{text "arbitrary: x\<^sub>1 \<dots> x\<^sub>m"}''
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1290
  specification generalizes variables @{text "x\<^sub>1, \<dots>,
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1291
  x\<^sub>m"} of the original goal before applying induction.  One can
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1292
  separate variables by ``@{text "and"}'' to generalize them in other
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1293
  goals then the first. Thus induction hypotheses may become
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1294
  sufficiently general to get the proof through.  Together with
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1295
  definitional instantiations, one may effectively perform induction
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1296
  over expressions of a certain structure.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1297
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1298
  The optional ``@{text "taking: t\<^sub>1 \<dots> t\<^sub>n"}''
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1299
  specification provides additional instantiations of a prefix of
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1300
  pending variables in the rule.  Such schematic induction rules
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1301
  rarely occur in practice, though.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1302
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1303
  \<^descr> @{method coinduct}~@{text "inst R"} is analogous to the
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1304
  @{method induct} method, but refers to coinduction rules, which are
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1305
  determined as follows:
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1306
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1307
  \<^medskip>
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1308
  \begin{tabular}{llll}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1309
    goal          &                    & arguments & rule \\\hline
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1310
                  & @{method coinduct} & @{text x} & type coinduction (type of @{text x}) \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1311
    @{text "A x"} & @{method coinduct} & @{text "\<dots>"} & predicate/set coinduction (of @{text A}) \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1312
    @{text "\<dots>"}   & @{method coinduct} & @{text "\<dots> rule: R"} & explicit rule @{text R} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1313
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1314
  \<^medskip>
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1315
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1316
  Coinduction is the dual of induction.  Induction essentially
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1317
  eliminates @{text "A x"} towards a generic result @{text "P x"},
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1318
  while coinduction introduces @{text "A x"} starting with @{text "B
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1319
  x"}, for a suitable ``bisimulation'' @{text B}.  The cases of a
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1320
  coinduct rule are typically named after the predicates or sets being
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1321
  covered, while the conclusions consist of several alternatives being
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1322
  named after the individual destructor patterns.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1323
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1324
  The given instantiation refers to the \emph{suffix} of variables
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1325
  occurring in the rule's major premise, or conclusion if unavailable.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1326
  An additional ``@{text "taking: t\<^sub>1 \<dots> t\<^sub>n"}''
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1327
  specification may be required in order to specify the bisimulation
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1328
  to be used in the coinduction step.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1329
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1330
  \end{description}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1331
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1332
  Above methods produce named local contexts, as determined by the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1333
  instantiated rule as given in the text.  Beyond that, the @{method
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1334
  induct} and @{method coinduct} methods guess further instantiations
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1335
  from the goal specification itself.  Any persisting unresolved
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1336
  schematic variables of the resulting rule will render the the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1337
  corresponding case invalid.  The term binding @{variable ?case} for
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1338
  the conclusion will be provided with each case, provided that term
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1339
  is fully specified.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1340
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1341
  The @{command "print_cases"} command prints all named cases present
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1342
  in the current proof state.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1343
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1344
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1345
  Despite the additional infrastructure, both @{method cases}
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1346
  and @{method coinduct} merely apply a certain rule, after
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1347
  instantiation, while conforming due to the usual way of monotonic
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1348
  natural deduction: the context of a structured statement @{text
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1349
  "\<And>x\<^sub>1 \<dots> x\<^sub>m. \<phi>\<^sub>1 \<Longrightarrow> \<dots> \<phi>\<^sub>n \<Longrightarrow> \<dots>"}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1350
  reappears unchanged after the case split.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1351
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1352
  The @{method induct} method is fundamentally different in this
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1353
  respect: the meta-level structure is passed through the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1354
  ``recursive'' course involved in the induction.  Thus the original
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1355
  statement is basically replaced by separate copies, corresponding to
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1356
  the induction hypotheses and conclusion; the original goal context
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1357
  is no longer available.  Thus local assumptions, fixed parameters
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1358
  and definitions effectively participate in the inductive rephrasing
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1359
  of the original statement.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1360
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1361
  In @{method induct} proofs, local assumptions introduced by cases are split
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1362
  into two different kinds: @{text hyps} stemming from the rule and
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1363
  @{text prems} from the goal statement.  This is reflected in the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1364
  extracted cases accordingly, so invoking ``@{command "case"}~@{text
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1365
  c}'' will provide separate facts @{text c.hyps} and @{text c.prems},
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1366
  as well as fact @{text c} to hold the all-inclusive list.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1367
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1368
  In @{method induction} proofs, local assumptions introduced by cases are
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1369
  split into three different kinds: @{text IH}, the induction hypotheses,
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1370
  @{text hyps}, the remaining hypotheses stemming from the rule, and
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1371
  @{text prems}, the assumptions from the goal statement. The names are
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1372
  @{text c.IH}, @{text c.hyps} and @{text c.prems}, as above.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1373
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1374
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1375
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1376
  Facts presented to either method are consumed according to
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1377
  the number of ``major premises'' of the rule involved, which is
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1378
  usually 0 for plain cases and induction rules of datatypes etc.\ and
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1379
  1 for rules of inductive predicates or sets and the like.  The
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1380
  remaining facts are inserted into the goal verbatim before the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1381
  actual @{text cases}, @{text induct}, or @{text coinduct} rule is
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1382
  applied.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1383
\<close>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1384
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1385
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1386
subsection \<open>Declaring rules\<close>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1387
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1388
text \<open>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1389
  \begin{matharray}{rcl}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1390
    @{command_def "print_induct_rules"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1391
    @{attribute_def cases} & : & @{text attribute} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1392
    @{attribute_def induct} & : & @{text attribute} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1393
    @{attribute_def coinduct} & : & @{text attribute} \\
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1394
  \end{matharray}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1395
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1396
  @{rail \<open>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1397
    @@{attribute cases} spec
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1398
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1399
    @@{attribute induct} spec
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1400
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1401
    @@{attribute coinduct} spec
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1402
    ;
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1403
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1404
    spec: (('type' | 'pred' | 'set') ':' @{syntax nameref}) | 'del'
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1405
  \<close>}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1406
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1407
  \begin{description}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1408
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1409
  \<^descr> @{command "print_induct_rules"} prints cases and induct rules
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1410
  for predicates (or sets) and types of the current context.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1411
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1412
  \<^descr> @{attribute cases}, @{attribute induct}, and @{attribute
60483
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1413
  coinduct} (as attributes) declare rules for reasoning about
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1414
  (co)inductive predicates (or sets) and types, using the
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1415
  corresponding methods of the same name.  Certain definitional
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1416
  packages of object-logics usually declare emerging cases and
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1417
  induction rules as expected, so users rarely need to intervene.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1418
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1419
  Rules may be deleted via the @{text "del"} specification, which
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1420
  covers all of the @{text "type"}/@{text "pred"}/@{text "set"}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1421
  sub-categories simultaneously.  For example, @{attribute
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1422
  cases}~@{text del} removes any @{attribute cases} rules declared for
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1423
  some type, predicate, or set.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1424
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1425
  Manual rule declarations usually refer to the @{attribute
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1426
  case_names} and @{attribute params} attributes to adjust names of
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1427
  cases and parameters of a rule; the @{attribute consumes}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1428
  declaration is taken care of automatically: @{attribute
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1429
  consumes}~@{text 0} is specified for ``type'' rules and @{attribute
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1430
  consumes}~@{text 1} for ``predicate'' / ``set'' rules.
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1431
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1432
  \end{description}
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1433
\<close>
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1434
9a566f4ac20a moved sections;
wenzelm
parents: 60482
diff changeset
  1435
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1436
section \<open>Generalized elimination and case splitting \label{sec:obtain}\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1437
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1438
text \<open>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1439
  \begin{matharray}{rcl}
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1440
    @{command_def "consider"} & : & @{text "proof(state) | proof(chain) \<rightarrow> proof(prove)"} \\
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
  1441
    @{command_def "obtain"} & : & @{text "proof(state) | proof(chain) \<rightarrow> proof(prove)"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
  1442
    @{command_def "guess"}@{text "\<^sup>*"} & : & @{text "proof(state) | proof(chain) \<rightarrow> proof(prove)"} \\
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1443
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1444
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1445
  Generalized elimination means that hypothetical parameters and premises
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1446
  may be introduced in the current context, potentially with a split into
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1447
  cases. This works by virtue of a locally proven rule that establishes the
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1448
  soundness of this temporary context extension. As representative examples,
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1449
  one may think of standard rules from Isabelle/HOL like this:
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1450
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1451
  \<^medskip>
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1452
  \begin{tabular}{ll}
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1453
  @{text "\<exists>x. B x \<Longrightarrow> (\<And>x. B x \<Longrightarrow> thesis) \<Longrightarrow> thesis"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1454
  @{text "A \<and> B \<Longrightarrow> (A \<Longrightarrow> B \<Longrightarrow> thesis) \<Longrightarrow> thesis"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1455
  @{text "A \<or> B \<Longrightarrow> (A \<Longrightarrow> thesis) \<Longrightarrow> (B \<Longrightarrow> thesis) \<Longrightarrow> thesis"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1456
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1457
  \<^medskip>
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1458
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1459
  In general, these particular rules and connectives need to get involved at
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1460
  all: this concept works directly in Isabelle/Pure via Isar commands
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1461
  defined below. In particular, the logic of elimination and case splitting
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1462
  is delegated to an Isar proof, which often involves automated tools.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1463
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1464
  @{rail \<open>
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1465
    @@{command consider} @{syntax obtain_clauses}
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1466
    ;
60448
78f3c67bc35e support for 'consider' command;
wenzelm
parents: 60414
diff changeset
  1467
    @@{command obtain} @{syntax par_name}? (@{syntax "fixes"} + @'and')
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40965
diff changeset
  1468
      @'where' (@{syntax props} + @'and')
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1469
    ;
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1470
    @@{command guess} (@{syntax "fixes"} + @'and')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1471
  \<close>}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1472
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1473
  \begin{description}
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1474
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1475
  \<^descr> @{command consider}~@{text "(a) \<^vec>x \<WHERE> \<^vec>A \<^vec>x
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1476
  | (b) \<^vec>y \<WHERE> \<^vec>B \<^vec>y | \<dots> "} states a rule for case
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1477
  splitting into separate subgoals, such that each case involves new
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1478
  parameters and premises. After the proof is finished, the resulting rule
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1479
  may be used directly with the @{method cases} proof method
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1480
  (\secref{sec:cases-induct}), in order to perform actual case-splitting of
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1481
  the proof text via @{command case} and @{command next} as usual.
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1482
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1483
  Optional names in round parentheses refer to case names: in the proof of
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1484
  the rule this is a fact name, in the resulting rule it is used as
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1485
  annotation with the @{attribute_ref case_names} attribute.
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1486
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1487
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1488
  Formally, the command @{command consider} is defined as derived
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1489
  Isar language element as follows:
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1490
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1491
  \begin{matharray}{l}
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1492
    @{command "consider"}~@{text "(a) \<^vec>x \<WHERE> \<^vec>A \<^vec>x | (b) \<^vec>y \<WHERE> \<^vec>B \<^vec>y | \<dots> \<equiv>"} \\[1ex]
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1493
    \quad @{command "have"}~@{text "[case_names a b \<dots>]: thesis"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1494
    \qquad @{text "\<IF> a [Pure.intro?]: \<And>\<^vec>x. \<^vec>A \<^vec>x \<Longrightarrow> thesis"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1495
    \qquad @{text "\<AND> b [Pure.intro?]: \<And>\<^vec>y. \<^vec>B \<^vec>y \<Longrightarrow> thesis"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1496
    \qquad @{text "\<AND> \<dots>"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1497
    \qquad @{text "\<FOR> thesis"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1498
    \qquad @{command "apply"}~@{text "(insert a b \<dots>)"} \\
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1499
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1500
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1501
  See also \secref{sec:goals} for @{keyword "obtains"} in toplevel goal
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1502
  statements, as well as @{command print_statement} to print existing rules
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1503
  in a similar format.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1504
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1505
  \<^descr> @{command obtain}~@{text "\<^vec>x \<WHERE> \<^vec>A \<^vec>x"}
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1506
  states a generalized elimination rule with exactly one case. After the
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1507
  proof is finished, it is activated for the subsequent proof text: the
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1508
  context is augmented via @{command fix}~@{text "\<^vec>x"} @{command
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1509
  assume}~@{text "\<^vec>A \<^vec>x"}, with special provisions to export
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1510
  later results by discharging these assumptions again.
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1511
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1512
  Note that according to the parameter scopes within the elimination rule,
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1513
  results \emph{must not} refer to hypothetical parameters; otherwise the
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1514
  export will fail! This restriction conforms to the usual manner of
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1515
  existential reasoning in Natural Deduction.
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1516
61421
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1517
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61408
diff changeset
  1518
  Formally, the command @{command obtain} is defined as derived
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1519
  Isar language element as follows, using an instrumented variant of
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1520
  @{command assume}:
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1521
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1522
  \begin{matharray}{l}
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1523
    @{command "obtain"}~@{text "\<^vec>x \<WHERE> a: \<^vec>A \<^vec>x  \<langle>proof\<rangle> \<equiv>"} \\[1ex]
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1524
    \quad @{command "have"}~@{text "thesis"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1525
    \qquad @{text "\<IF> that [Pure.intro?]: \<And>\<^vec>x. \<^vec>A \<^vec>x \<Longrightarrow> thesis"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1526
    \qquad @{text "\<FOR> thesis"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1527
    \qquad @{command "apply"}~@{text "(insert that)"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1528
    \qquad @{text "\<langle>proof\<rangle>"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1529
    \quad @{command "fix"}~@{text "\<^vec>x"}~@{command "assume"}@{text "\<^sup>* a: \<^vec>A \<^vec>x"} \\
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1530
  \end{matharray}
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1531
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1532
  \<^descr> @{command guess} is similar to @{command obtain}, but it derives the
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1533
  obtained context elements from the course of tactical reasoning in the
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1534
  proof. Thus it can considerably obscure the proof: it is classified as
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1535
  \emph{improper}.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1536
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1537
  A proof with @{command guess} starts with a fixed goal @{text thesis}. The
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1538
  subsequent refinement steps may turn this to anything of the form @{text
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1539
  "\<And>\<^vec>x. \<^vec>A \<^vec>x \<Longrightarrow> thesis"}, but without splitting into new
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1540
  subgoals. The final goal state is then used as reduction rule for the
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1541
  obtain pattern described above. Obtained parameters @{text "\<^vec>x"} are
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1542
  marked as internal by default, and thus inaccessible in the proof text.
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1543
  The variable names and type constraints given as arguments for @{command
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1544
  "guess"} specify a prefix of accessible parameters.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1545
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1546
  \end{description}
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1547
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1548
  In the proof of @{command consider} and @{command obtain} the local
60480
wenzelm
parents: 60459
diff changeset
  1549
  premises are always bound to the fact name @{fact_ref that}, according to
60459
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1550
  structured Isar statements involving @{keyword_ref "if"}
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1551
  (\secref{sec:goals}).
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1552
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1553
  Facts that are established by @{command "obtain"} and @{command "guess"}
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1554
  may not be polymorphic: any type-variables occurring here are fixed in the
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1555
  present context. This is a natural consequence of the role of @{command
2761a2249c83 more on 'consider' and related concepts;
wenzelm
parents: 60455
diff changeset
  1556
  fix} and @{command assume} in these constructs.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1557
\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
  1558
26869
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
  1559
end