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