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