26782
|
1 |
(* $Id$ *)
|
|
2 |
|
|
3 |
theory Generic
|
|
4 |
imports CPure
|
|
5 |
begin
|
|
6 |
|
|
7 |
chapter {* Generic tools and packages \label{ch:gen-tools} *}
|
|
8 |
|
|
9 |
section {* Specification commands *}
|
|
10 |
|
|
11 |
subsection {* Derived specifications *}
|
|
12 |
|
|
13 |
text {*
|
|
14 |
\begin{matharray}{rcll}
|
|
15 |
@{command_def "axiomatization"} & : & \isarkeep{local{\dsh}theory} & (axiomatic!)\\
|
|
16 |
@{command_def "definition"} & : & \isarkeep{local{\dsh}theory} \\
|
|
17 |
@{attribute_def "defn"} & : & \isaratt \\
|
|
18 |
@{command_def "abbreviation"} & : & \isarkeep{local{\dsh}theory} \\
|
|
19 |
@{command_def "print_abbrevs"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
|
|
20 |
@{command_def "notation"} & : & \isarkeep{local{\dsh}theory} \\
|
|
21 |
@{command_def "no_notation"} & : & \isarkeep{local{\dsh}theory} \\
|
|
22 |
\end{matharray}
|
|
23 |
|
|
24 |
These specification mechanisms provide a slightly more abstract view
|
|
25 |
than the underlying primitives of @{command "consts"}, @{command
|
|
26 |
"defs"} (see \secref{sec:consts}), and @{command "axioms"} (see
|
|
27 |
\secref{sec:axms-thms}). In particular, type-inference is commonly
|
|
28 |
available, and result names need not be given.
|
|
29 |
|
|
30 |
\begin{rail}
|
|
31 |
'axiomatization' target? fixes? ('where' specs)?
|
|
32 |
;
|
|
33 |
'definition' target? (decl 'where')? thmdecl? prop
|
|
34 |
;
|
|
35 |
'abbreviation' target? mode? (decl 'where')? prop
|
|
36 |
;
|
|
37 |
('notation' | 'no\_notation') target? mode? (nameref structmixfix + 'and')
|
|
38 |
;
|
|
39 |
|
|
40 |
fixes: ((name ('::' type)? mixfix? | vars) + 'and')
|
|
41 |
;
|
|
42 |
specs: (thmdecl? props + 'and')
|
|
43 |
;
|
|
44 |
decl: name ('::' type)? mixfix?
|
|
45 |
;
|
|
46 |
\end{rail}
|
|
47 |
|
|
48 |
\begin{descr}
|
|
49 |
|
|
50 |
\item [@{command "axiomatization"}~@{text "c\<^sub>1 \<dots> c\<^sub>m
|
|
51 |
\<WHERE> \<phi>\<^sub>1 \<dots> \<phi>\<^sub>n"}] introduces several constants
|
|
52 |
simultaneously and states axiomatic properties for these. The
|
|
53 |
constants are marked as being specified once and for all, which
|
|
54 |
prevents additional specifications being issued later on.
|
|
55 |
|
|
56 |
Note that axiomatic specifications are only appropriate when
|
|
57 |
declaring a new logical system. Normal applications should only use
|
|
58 |
definitional mechanisms!
|
|
59 |
|
|
60 |
\item [@{command "definition"}~@{text "c \<WHERE> eq"}] produces an
|
|
61 |
internal definition @{text "c \<equiv> t"} according to the specification
|
|
62 |
given as @{text eq}, which is then turned into a proven fact. The
|
|
63 |
given proposition may deviate from internal meta-level equality
|
|
64 |
according to the rewrite rules declared as @{attribute defn} by the
|
26789
|
65 |
object-logic. This usually covers object-level equality @{text "x =
|
|
66 |
y"} and equivalence @{text "A \<leftrightarrow> B"}. End-users normally need not
|
26782
|
67 |
change the @{attribute defn} setup.
|
|
68 |
|
|
69 |
Definitions may be presented with explicit arguments on the LHS, as
|
|
70 |
well as additional conditions, e.g.\ @{text "f x y = t"} instead of
|
|
71 |
@{text "f \<equiv> \<lambda>x y. t"} and @{text "y \<noteq> 0 \<Longrightarrow> g x y = u"} instead of an
|
|
72 |
unrestricted @{text "g \<equiv> \<lambda>x y. u"}.
|
|
73 |
|
|
74 |
\item [@{command "abbreviation"}~@{text "c \<WHERE> eq"}] introduces
|
|
75 |
a syntactic constant which is associated with a certain term
|
|
76 |
according to the meta-level equality @{text eq}.
|
|
77 |
|
|
78 |
Abbreviations participate in the usual type-inference process, but
|
|
79 |
are expanded before the logic ever sees them. Pretty printing of
|
|
80 |
terms involves higher-order rewriting with rules stemming from
|
|
81 |
reverted abbreviations. This needs some care to avoid overlapping
|
|
82 |
or looping syntactic replacements!
|
|
83 |
|
|
84 |
The optional @{text mode} specification restricts output to a
|
|
85 |
particular print mode; using ``@{text input}'' here achieves the
|
|
86 |
effect of one-way abbreviations. The mode may also include an
|
|
87 |
``@{keyword "output"}'' qualifier that affects the concrete syntax
|
|
88 |
declared for abbreviations, cf.\ @{command "syntax"} in
|
|
89 |
\secref{sec:syn-trans}.
|
|
90 |
|
|
91 |
\item [@{command "print_abbrevs"}] prints all constant abbreviations
|
|
92 |
of the current context.
|
|
93 |
|
|
94 |
\item [@{command "notation"}~@{text "c (mx)"}] associates mixfix
|
|
95 |
syntax with an existing constant or fixed variable. This is a
|
|
96 |
robust interface to the underlying @{command "syntax"} primitive
|
|
97 |
(\secref{sec:syn-trans}). Type declaration and internal syntactic
|
|
98 |
representation of the given entity is retrieved from the context.
|
|
99 |
|
|
100 |
\item [@{command "no_notation"}] is similar to @{command
|
|
101 |
"notation"}, but removes the specified syntax annotation from the
|
|
102 |
present context.
|
|
103 |
|
|
104 |
\end{descr}
|
|
105 |
|
|
106 |
All of these specifications support local theory targets (cf.\
|
|
107 |
\secref{sec:target}).
|
|
108 |
*}
|
|
109 |
|
|
110 |
|
|
111 |
subsection {* Generic declarations *}
|
|
112 |
|
|
113 |
text {*
|
|
114 |
Arbitrary operations on the background context may be wrapped-up as
|
|
115 |
generic declaration elements. Since the underlying concept of local
|
|
116 |
theories may be subject to later re-interpretation, there is an
|
|
117 |
additional dependency on a morphism that tells the difference of the
|
|
118 |
original declaration context wrt.\ the application context
|
|
119 |
encountered later on. A fact declaration is an important special
|
|
120 |
case: it consists of a theorem which is applied to the context by
|
|
121 |
means of an attribute.
|
|
122 |
|
|
123 |
\begin{matharray}{rcl}
|
|
124 |
@{command_def "declaration"} & : & \isarkeep{local{\dsh}theory} \\
|
|
125 |
@{command_def "declare"} & : & \isarkeep{local{\dsh}theory} \\
|
|
126 |
\end{matharray}
|
|
127 |
|
|
128 |
\begin{rail}
|
|
129 |
'declaration' target? text
|
|
130 |
;
|
|
131 |
'declare' target? (thmrefs + 'and')
|
|
132 |
;
|
|
133 |
\end{rail}
|
|
134 |
|
|
135 |
\begin{descr}
|
|
136 |
|
|
137 |
\item [@{command "declaration"}~@{text d}] adds the declaration
|
|
138 |
function @{text d} of ML type @{ML_type declaration}, to the current
|
|
139 |
local theory under construction. In later application contexts, the
|
|
140 |
function is transformed according to the morphisms being involved in
|
|
141 |
the interpretation hierarchy.
|
|
142 |
|
|
143 |
\item [@{command "declare"}~@{text thms}] declares theorems to the
|
|
144 |
current local theory context. No theorem binding is involved here,
|
|
145 |
unlike @{command "theorems"} or @{command "lemmas"} (cf.\
|
|
146 |
\secref{sec:axms-thms}), so @{command "declare"} only has the effect
|
|
147 |
of applying attributes as included in the theorem specification.
|
|
148 |
|
|
149 |
\end{descr}
|
|
150 |
*}
|
|
151 |
|
|
152 |
|
|
153 |
subsection {* Local theory targets \label{sec:target} *}
|
|
154 |
|
|
155 |
text {*
|
|
156 |
A local theory target is a context managed separately within the
|
|
157 |
enclosing theory. Contexts may introduce parameters (fixed
|
|
158 |
variables) and assumptions (hypotheses). Definitions and theorems
|
|
159 |
depending on the context may be added incrementally later on. Named
|
|
160 |
contexts refer to locales (cf.\ \secref{sec:locale}) or type classes
|
|
161 |
(cf.\ \secref{sec:class}); the name ``@{text "-"}'' signifies the
|
|
162 |
global theory context.
|
|
163 |
|
|
164 |
\begin{matharray}{rcll}
|
|
165 |
@{command_def "context"} & : & \isartrans{theory}{local{\dsh}theory} \\
|
|
166 |
@{command_def "end"} & : & \isartrans{local{\dsh}theory}{theory} \\
|
|
167 |
\end{matharray}
|
|
168 |
|
|
169 |
\indexouternonterm{target}
|
|
170 |
\begin{rail}
|
|
171 |
'context' name 'begin'
|
|
172 |
;
|
|
173 |
|
|
174 |
target: '(' 'in' name ')'
|
|
175 |
;
|
|
176 |
\end{rail}
|
|
177 |
|
|
178 |
\begin{descr}
|
|
179 |
|
|
180 |
\item [@{command "context"}~@{text "c \<BEGIN>"}] recommences an
|
|
181 |
existing locale or class context @{text c}. Note that locale and
|
|
182 |
class definitions allow to include the @{keyword_ref "begin"}
|
|
183 |
keyword as well, in order to continue the local theory immediately
|
|
184 |
after the initial specification.
|
|
185 |
|
|
186 |
\item [@{command "end"}] concludes the current local theory and
|
|
187 |
continues the enclosing global theory. Note that a non-local
|
|
188 |
@{command "end"} has a different meaning: it concludes the theory
|
|
189 |
itself (\secref{sec:begin-thy}).
|
|
190 |
|
|
191 |
\item [@{text "(\<IN> c)"}] given after any local theory command
|
|
192 |
specifies an immediate target, e.g.\ ``@{command
|
|
193 |
"definition"}~@{text "(\<IN> c) \<dots>"}'' or ``@{command
|
|
194 |
"theorem"}~@{text "(\<IN> c) \<dots>"}''. This works both in a local or
|
|
195 |
global theory context; the current target context will be suspended
|
26789
|
196 |
for this command only. Note that ``@{text "(\<IN> -)"}'' will
|
|
197 |
always produce a global result independently of the current target
|
|
198 |
context.
|
26782
|
199 |
|
|
200 |
\end{descr}
|
|
201 |
|
|
202 |
The exact meaning of results produced within a local theory context
|
|
203 |
depends on the underlying target infrastructure (locale, type class
|
|
204 |
etc.). The general idea is as follows, considering a context named
|
|
205 |
@{text c} with parameter @{text x} and assumption @{text "A[x]"}.
|
|
206 |
|
|
207 |
Definitions are exported by introducing a global version with
|
|
208 |
additional arguments; a syntactic abbreviation links the long form
|
|
209 |
with the abstract version of the target context. For example,
|
|
210 |
@{text "a \<equiv> t[x]"} becomes @{text "c.a ?x \<equiv> t[?x]"} at the theory
|
|
211 |
level (for arbitrary @{text "?x"}), together with a local
|
|
212 |
abbreviation @{text "c \<equiv> c.a x"} in the target context (for the
|
|
213 |
fixed parameter @{text x}).
|
|
214 |
|
|
215 |
Theorems are exported by discharging the assumptions and
|
|
216 |
generalizing the parameters of the context. For example, @{text "a:
|
26789
|
217 |
B[x]"} becomes @{text "c.a: A[?x] \<Longrightarrow> B[?x]"}, again for arbitrary
|
|
218 |
@{text "?x"}.
|
26782
|
219 |
*}
|
|
220 |
|
|
221 |
|
|
222 |
subsection {* Locales \label{sec:locale} *}
|
|
223 |
|
|
224 |
text {*
|
|
225 |
Locales are named local contexts, consisting of a list of
|
|
226 |
declaration elements that are modeled after the Isar proof context
|
|
227 |
commands (cf.\ \secref{sec:proof-context}).
|
|
228 |
*}
|
|
229 |
|
|
230 |
|
|
231 |
subsubsection {* Locale specifications *}
|
|
232 |
|
|
233 |
text {*
|
|
234 |
\begin{matharray}{rcl}
|
|
235 |
@{command_def "locale"} & : & \isartrans{theory}{local{\dsh}theory} \\
|
|
236 |
@{command_def "print_locale"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
|
|
237 |
@{command_def "print_locales"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
|
|
238 |
@{method_def intro_locales} & : & \isarmeth \\
|
|
239 |
@{method_def unfold_locales} & : & \isarmeth \\
|
|
240 |
\end{matharray}
|
|
241 |
|
|
242 |
\indexouternonterm{contextexpr}\indexouternonterm{contextelem}
|
|
243 |
\indexisarelem{fixes}\indexisarelem{constrains}\indexisarelem{assumes}
|
|
244 |
\indexisarelem{defines}\indexisarelem{notes}\indexisarelem{includes}
|
|
245 |
\begin{rail}
|
|
246 |
'locale' ('(open)')? name ('=' localeexpr)? 'begin'?
|
|
247 |
;
|
|
248 |
'print\_locale' '!'? localeexpr
|
|
249 |
;
|
|
250 |
localeexpr: ((contextexpr '+' (contextelem+)) | contextexpr | (contextelem+))
|
|
251 |
;
|
|
252 |
|
|
253 |
contextexpr: nameref | '(' contextexpr ')' |
|
|
254 |
(contextexpr (name mixfix? +)) | (contextexpr + '+')
|
|
255 |
;
|
|
256 |
contextelem: fixes | constrains | assumes | defines | notes
|
|
257 |
;
|
|
258 |
fixes: 'fixes' ((name ('::' type)? structmixfix? | vars) + 'and')
|
|
259 |
;
|
|
260 |
constrains: 'constrains' (name '::' type + 'and')
|
|
261 |
;
|
|
262 |
assumes: 'assumes' (thmdecl? props + 'and')
|
|
263 |
;
|
|
264 |
defines: 'defines' (thmdecl? prop proppat? + 'and')
|
|
265 |
;
|
|
266 |
notes: 'notes' (thmdef? thmrefs + 'and')
|
|
267 |
;
|
|
268 |
includes: 'includes' contextexpr
|
|
269 |
;
|
|
270 |
\end{rail}
|
|
271 |
|
|
272 |
\begin{descr}
|
|
273 |
|
|
274 |
\item [@{command "locale"}~@{text "loc = import + body"}] defines a
|
|
275 |
new locale @{text loc} as a context consisting of a certain view of
|
|
276 |
existing locales (@{text import}) plus some additional elements
|
|
277 |
(@{text body}). Both @{text import} and @{text body} are optional;
|
|
278 |
the degenerate form @{command "locale"}~@{text loc} defines an empty
|
|
279 |
locale, which may still be useful to collect declarations of facts
|
|
280 |
later on. Type-inference on locale expressions automatically takes
|
|
281 |
care of the most general typing that the combined context elements
|
|
282 |
may acquire.
|
|
283 |
|
|
284 |
The @{text import} consists of a structured context expression,
|
|
285 |
consisting of references to existing locales, renamed contexts, or
|
|
286 |
merged contexts. Renaming uses positional notation: @{text "c
|
|
287 |
x\<^sub>1 \<dots> x\<^sub>n"} means that (a prefix of) the fixed
|
|
288 |
parameters of context @{text c} are named @{text "x\<^sub>1, \<dots>,
|
|
289 |
x\<^sub>n"}; a ``@{text _}'' (underscore) means to skip that
|
|
290 |
position. Renaming by default deletes concrete syntax, but new
|
|
291 |
syntax may by specified with a mixfix annotation. An exeption of
|
|
292 |
this rule is the special syntax declared with ``@{text
|
|
293 |
"(\<STRUCTURE>)"}'' (see below), which is neither deleted nor can it
|
|
294 |
be changed. Merging proceeds from left-to-right, suppressing any
|
|
295 |
duplicates stemming from different paths through the import
|
|
296 |
hierarchy.
|
|
297 |
|
|
298 |
The @{text body} consists of basic context elements, further context
|
|
299 |
expressions may be included as well.
|
|
300 |
|
|
301 |
\begin{descr}
|
|
302 |
|
|
303 |
\item [@{element "fixes"}~@{text "x :: \<tau> (mx)"}] declares a local
|
|
304 |
parameter of type @{text \<tau>} and mixfix annotation @{text mx} (both
|
|
305 |
are optional). The special syntax declaration ``@{text
|
|
306 |
"(\<STRUCTURE>)"}'' means that @{text x} may be referenced
|
|
307 |
implicitly in this context.
|
|
308 |
|
|
309 |
\item [@{element "constrains"}~@{text "x :: \<tau>"}] introduces a type
|
|
310 |
constraint @{text \<tau>} on the local parameter @{text x}.
|
|
311 |
|
|
312 |
\item [@{element "assumes"}~@{text "a: \<phi>\<^sub>1 \<dots> \<phi>\<^sub>n"}]
|
|
313 |
introduces local premises, similar to @{command "assume"} within a
|
|
314 |
proof (cf.\ \secref{sec:proof-context}).
|
|
315 |
|
|
316 |
\item [@{element "defines"}~@{text "a: x \<equiv> t"}] defines a previously
|
26789
|
317 |
declared parameter. This is similar to @{command "def"} within a
|
26782
|
318 |
proof (cf.\ \secref{sec:proof-context}), but @{element "defines"}
|
|
319 |
takes an equational proposition instead of variable-term pair. The
|
|
320 |
left-hand side of the equation may have additional arguments, e.g.\
|
|
321 |
``@{element "defines"}~@{text "f x\<^sub>1 \<dots> x\<^sub>n \<equiv> t"}''.
|
|
322 |
|
|
323 |
\item [@{element "notes"}~@{text "a = b\<^sub>1 \<dots> b\<^sub>n"}]
|
|
324 |
reconsiders facts within a local context. Most notably, this may
|
|
325 |
include arbitrary declarations in any attribute specifications
|
|
326 |
included here, e.g.\ a local @{attribute simp} rule.
|
|
327 |
|
|
328 |
\item [@{element "includes"}~@{text c}] copies the specified context
|
|
329 |
in a statically scoped manner. Only available in the long goal
|
|
330 |
format of \secref{sec:goals}.
|
|
331 |
|
|
332 |
In contrast, the initial @{text import} specification of a locale
|
|
333 |
expression maintains a dynamic relation to the locales being
|
|
334 |
referenced (benefiting from any later fact declarations in the
|
|
335 |
obvious manner).
|
|
336 |
|
|
337 |
\end{descr}
|
|
338 |
|
|
339 |
Note that ``@{text "(\<IS> p\<^sub>1 \<dots> p\<^sub>n)"}'' patterns given
|
|
340 |
in the syntax of @{element "assumes"} and @{element "defines"} above
|
|
341 |
are illegal in locale definitions. In the long goal format of
|
|
342 |
\secref{sec:goals}, term bindings may be included as expected,
|
|
343 |
though.
|
|
344 |
|
|
345 |
\medskip By default, locale specifications are ``closed up'' by
|
|
346 |
turning the given text into a predicate definition @{text
|
|
347 |
loc_axioms} and deriving the original assumptions as local lemmas
|
|
348 |
(modulo local definitions). The predicate statement covers only the
|
|
349 |
newly specified assumptions, omitting the content of included locale
|
|
350 |
expressions. The full cumulative view is only provided on export,
|
|
351 |
involving another predicate @{text loc} that refers to the complete
|
|
352 |
specification text.
|
|
353 |
|
|
354 |
In any case, the predicate arguments are those locale parameters
|
|
355 |
that actually occur in the respective piece of text. Also note that
|
|
356 |
these predicates operate at the meta-level in theory, but the locale
|
|
357 |
packages attempts to internalize statements according to the
|
|
358 |
object-logic setup (e.g.\ replacing @{text \<And>} by @{text \<forall>}, and
|
|
359 |
@{text "\<Longrightarrow>"} by @{text "\<longrightarrow>"} in HOL; see also
|
|
360 |
\secref{sec:object-logic}). Separate introduction rules @{text
|
|
361 |
loc_axioms.intro} and @{text loc.intro} are provided as well.
|
|
362 |
|
|
363 |
The @{text "(open)"} option of a locale specification prevents both
|
|
364 |
the current @{text loc_axioms} and cumulative @{text loc} predicate
|
|
365 |
constructions. Predicates are also omitted for empty specification
|
|
366 |
texts.
|
|
367 |
|
|
368 |
\item [@{command "print_locale"}~@{text "import + body"}] prints the
|
|
369 |
specified locale expression in a flattened form. The notable
|
|
370 |
special case @{command "print_locale"}~@{text loc} just prints the
|
|
371 |
contents of the named locale, but keep in mind that type-inference
|
|
372 |
will normalize type variables according to the usual alphabetical
|
|
373 |
order. The command omits @{element "notes"} elements by default.
|
|
374 |
Use @{command "print_locale"}@{text "!"} to get them included.
|
|
375 |
|
|
376 |
\item [@{command "print_locales"}] prints the names of all locales
|
|
377 |
of the current theory.
|
|
378 |
|
|
379 |
\item [@{method intro_locales} and @{method unfold_locales}]
|
|
380 |
repeatedly expand all introduction rules of locale predicates of the
|
|
381 |
theory. While @{method intro_locales} only applies the @{text
|
|
382 |
loc.intro} introduction rules and therefore does not decend to
|
|
383 |
assumptions, @{method unfold_locales} is more aggressive and applies
|
|
384 |
@{text loc_axioms.intro} as well. Both methods are aware of locale
|
|
385 |
specifications entailed by the context, both from target and
|
|
386 |
@{element "includes"} statements, and from interpretations (see
|
|
387 |
below). New goals that are entailed by the current context are
|
|
388 |
discharged automatically.
|
|
389 |
|
|
390 |
\end{descr}
|
|
391 |
*}
|
|
392 |
|
|
393 |
|
|
394 |
subsubsection {* Interpretation of locales *}
|
|
395 |
|
|
396 |
text {*
|
|
397 |
Locale expressions (more precisely, \emph{context expressions}) may
|
|
398 |
be instantiated, and the instantiated facts added to the current
|
|
399 |
context. This requires a proof of the instantiated specification
|
|
400 |
and is called \emph{locale interpretation}. Interpretation is
|
|
401 |
possible in theories and locales (command @{command
|
26789
|
402 |
"interpretation"}) and also within a proof body (command @{command
|
26782
|
403 |
"interpret"}).
|
|
404 |
|
|
405 |
\begin{matharray}{rcl}
|
|
406 |
@{command_def "interpretation"} & : & \isartrans{theory}{proof(prove)} \\
|
|
407 |
@{command_def "interpret"} & : & \isartrans{proof(state) ~|~ proof(chain)}{proof(prove)} \\
|
|
408 |
@{command_def "print_interps"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
|
|
409 |
\end{matharray}
|
|
410 |
|
|
411 |
\indexouternonterm{interp}
|
|
412 |
\begin{rail}
|
|
413 |
'interpretation' (interp | name ('<' | subseteq) contextexpr)
|
|
414 |
;
|
|
415 |
'interpret' interp
|
|
416 |
;
|
|
417 |
'print\_interps' '!'? name
|
|
418 |
;
|
|
419 |
instantiation: ('[' (inst+) ']')?
|
|
420 |
;
|
|
421 |
interp: thmdecl? \\ (contextexpr instantiation |
|
|
422 |
name instantiation 'where' (thmdecl? prop + 'and'))
|
|
423 |
;
|
|
424 |
\end{rail}
|
|
425 |
|
|
426 |
\begin{descr}
|
|
427 |
|
|
428 |
\item [@{command "interpretation"}~@{text "expr insts \<WHERE> eqns"}]
|
|
429 |
|
|
430 |
The first form of @{command "interpretation"} interprets @{text
|
|
431 |
expr} in the theory. The instantiation is given as a list of terms
|
|
432 |
@{text insts} and is positional. All parameters must receive an
|
|
433 |
instantiation term --- with the exception of defined parameters.
|
|
434 |
These are, if omitted, derived from the defining equation and other
|
|
435 |
instantiations. Use ``@{text _}'' to omit an instantiation term.
|
|
436 |
|
|
437 |
The command generates proof obligations for the instantiated
|
|
438 |
specifications (assumes and defines elements). Once these are
|
|
439 |
discharged by the user, instantiated facts are added to the theory
|
|
440 |
in a post-processing phase.
|
|
441 |
|
|
442 |
Additional equations, which are unfolded in facts during
|
|
443 |
post-processing, may be given after the keyword @{keyword "where"}.
|
|
444 |
This is useful for interpreting concepts introduced through
|
|
445 |
definition specification elements. The equations must be proved.
|
|
446 |
Note that if equations are present, the context expression is
|
|
447 |
restricted to a locale name.
|
|
448 |
|
|
449 |
The command is aware of interpretations already active in the
|
|
450 |
theory. No proof obligations are generated for those, neither is
|
|
451 |
post-processing applied to their facts. This avoids duplication of
|
|
452 |
interpreted facts, in particular. Note that, in the case of a
|
|
453 |
locale with import, parts of the interpretation may already be
|
|
454 |
active. The command will only generate proof obligations and
|
|
455 |
process facts for new parts.
|
|
456 |
|
|
457 |
The context expression may be preceded by a name and/or attributes.
|
|
458 |
These take effect in the post-processing of facts. The name is used
|
|
459 |
to prefix fact names, for example to avoid accidental hiding of
|
|
460 |
other facts. Attributes are applied after attributes of the
|
|
461 |
interpreted facts.
|
|
462 |
|
|
463 |
Adding facts to locales has the effect of adding interpreted facts
|
|
464 |
to the theory for all active interpretations also. That is,
|
|
465 |
interpretations dynamically participate in any facts added to
|
|
466 |
locales.
|
|
467 |
|
|
468 |
\item [@{command "interpretation"}~@{text "name \<subseteq> expr"}]
|
|
469 |
|
|
470 |
This form of the command interprets @{text expr} in the locale
|
|
471 |
@{text name}. It requires a proof that the specification of @{text
|
|
472 |
name} implies the specification of @{text expr}. As in the
|
|
473 |
localized version of the theorem command, the proof is in the
|
|
474 |
context of @{text name}. After the proof obligation has been
|
|
475 |
dischared, the facts of @{text expr} become part of locale @{text
|
|
476 |
name} as \emph{derived} context elements and are available when the
|
|
477 |
context @{text name} is subsequently entered. Note that, like
|
|
478 |
import, this is dynamic: facts added to a locale part of @{text
|
|
479 |
expr} after interpretation become also available in @{text name}.
|
|
480 |
Like facts of renamed context elements, facts obtained by
|
|
481 |
interpretation may be accessed by prefixing with the parameter
|
|
482 |
renaming (where the parameters are separated by ``@{text _}'').
|
|
483 |
|
|
484 |
Unlike interpretation in theories, instantiation is confined to the
|
|
485 |
renaming of parameters, which may be specified as part of the
|
|
486 |
context expression @{text expr}. Using defined parameters in @{text
|
|
487 |
name} one may achieve an effect similar to instantiation, though.
|
|
488 |
|
|
489 |
Only specification fragments of @{text expr} that are not already
|
|
490 |
part of @{text name} (be it imported, derived or a derived fragment
|
|
491 |
of the import) are considered by interpretation. This enables
|
|
492 |
circular interpretations.
|
|
493 |
|
|
494 |
If interpretations of @{text name} exist in the current theory, the
|
|
495 |
command adds interpretations for @{text expr} as well, with the same
|
|
496 |
prefix and attributes, although only for fragments of @{text expr}
|
|
497 |
that are not interpreted in the theory already.
|
|
498 |
|
|
499 |
\item [@{command "interpret"}~@{text "expr insts \<WHERE> eqns"}]
|
|
500 |
interprets @{text expr} in the proof context and is otherwise
|
26789
|
501 |
similar to interpretation in theories.
|
26782
|
502 |
|
|
503 |
\item [@{command "print_interps"}~@{text loc}] prints the
|
|
504 |
interpretations of a particular locale @{text loc} that are active
|
|
505 |
in the current context, either theory or proof context. The
|
|
506 |
exclamation point argument triggers printing of \emph{witness}
|
|
507 |
theorems justifying interpretations. These are normally omitted
|
|
508 |
from the output.
|
|
509 |
|
|
510 |
\end{descr}
|
|
511 |
|
|
512 |
\begin{warn}
|
|
513 |
Since attributes are applied to interpreted theorems,
|
|
514 |
interpretation may modify the context of common proof tools, e.g.\
|
|
515 |
the Simplifier or Classical Reasoner. Since the behavior of such
|
|
516 |
automated reasoning tools is \emph{not} stable under
|
|
517 |
interpretation morphisms, manual declarations might have to be
|
|
518 |
issued.
|
|
519 |
\end{warn}
|
|
520 |
|
|
521 |
\begin{warn}
|
|
522 |
An interpretation in a theory may subsume previous
|
|
523 |
interpretations. This happens if the same specification fragment
|
|
524 |
is interpreted twice and the instantiation of the second
|
|
525 |
interpretation is more general than the interpretation of the
|
|
526 |
first. A warning is issued, since it is likely that these could
|
|
527 |
have been generalized in the first place. The locale package does
|
|
528 |
not attempt to remove subsumed interpretations.
|
|
529 |
\end{warn}
|
|
530 |
*}
|
|
531 |
|
|
532 |
|
|
533 |
subsection {* Classes \label{sec:class} *}
|
|
534 |
|
|
535 |
text {*
|
|
536 |
A class is a particular locale with \emph{exactly one} type variable
|
|
537 |
@{text \<alpha>}. Beyond the underlying locale, a corresponding type class
|
|
538 |
is established which is interpreted logically as axiomatic type
|
|
539 |
class \cite{Wenzel:1997:TPHOL} whose logical content are the
|
|
540 |
assumptions of the locale. Thus, classes provide the full
|
|
541 |
generality of locales combined with the commodity of type classes
|
|
542 |
(notably type-inference). See \cite{isabelle-classes} for a short
|
|
543 |
tutorial.
|
|
544 |
|
|
545 |
\begin{matharray}{rcl}
|
|
546 |
@{command_def "class"} & : & \isartrans{theory}{local{\dsh}theory} \\
|
|
547 |
@{command_def "instantiation"} & : & \isartrans{theory}{local{\dsh}theory} \\
|
|
548 |
@{command_def "instance"} & : & \isartrans{local{\dsh}theory}{local{\dsh}theory} \\
|
|
549 |
@{command_def "subclass"} & : & \isartrans{local{\dsh}theory}{local{\dsh}theory} \\
|
|
550 |
@{command_def "print_classes"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
|
|
551 |
@{method_def intro_classes} & : & \isarmeth \\
|
|
552 |
\end{matharray}
|
|
553 |
|
|
554 |
\begin{rail}
|
|
555 |
'class' name '=' ((superclassexpr '+' (contextelem+)) | superclassexpr | (contextelem+)) \\
|
|
556 |
'begin'?
|
|
557 |
;
|
|
558 |
'instantiation' (nameref + 'and') '::' arity 'begin'
|
|
559 |
;
|
|
560 |
'instance'
|
|
561 |
;
|
|
562 |
'subclass' target? nameref
|
|
563 |
;
|
|
564 |
'print\_classes'
|
|
565 |
;
|
|
566 |
|
|
567 |
superclassexpr: nameref | (nameref '+' superclassexpr)
|
|
568 |
;
|
|
569 |
\end{rail}
|
|
570 |
|
|
571 |
\begin{descr}
|
|
572 |
|
|
573 |
\item [@{command "class"}~@{text "c = superclasses + body"}] defines
|
|
574 |
a new class @{text c}, inheriting from @{text superclasses}. This
|
|
575 |
introduces a locale @{text c} with import of all locales @{text
|
|
576 |
superclasses}.
|
|
577 |
|
|
578 |
Any @{element "fixes"} in @{text body} are lifted to the global
|
|
579 |
theory level (\emph{class operations} @{text "f\<^sub>1, \<dots>,
|
|
580 |
f\<^sub>n"} of class @{text c}), mapping the local type parameter
|
|
581 |
@{text \<alpha>} to a schematic type variable @{text "?\<alpha> :: c"}.
|
|
582 |
|
|
583 |
Likewise, @{element "assumes"} in @{text body} are also lifted,
|
|
584 |
mapping each local parameter @{text "f :: \<tau>[\<alpha>]"} to its
|
|
585 |
corresponding global constant @{text "f :: \<tau>[?\<alpha> :: c]"}. The
|
|
586 |
corresponding introduction rule is provided as @{text
|
|
587 |
c_class_axioms.intro}. This rule should be rarely needed directly
|
|
588 |
--- the @{method intro_classes} method takes care of the details of
|
|
589 |
class membership proofs.
|
|
590 |
|
|
591 |
\item [@{command "instantiation"}~@{text "t :: (s\<^sub>1, \<dots>,
|
|
592 |
s\<^sub>n) s \<BEGIN>"}] opens a theory target (cf.\
|
|
593 |
\secref{sec:target}) which allows to specify class operations @{text
|
|
594 |
"f\<^sub>1, \<dots>, f\<^sub>n"} corresponding to sort @{text s} at the
|
|
595 |
particular type instance @{text "(\<alpha>\<^sub>1 :: s\<^sub>1, \<dots>,
|
26789
|
596 |
\<alpha>\<^sub>n :: s\<^sub>n) t"}. A plain @{command "instance"} command
|
26782
|
597 |
in the target body poses a goal stating these type arities. The
|
|
598 |
target is concluded by an @{command_ref "end"} command.
|
|
599 |
|
|
600 |
Note that a list of simultaneous type constructors may be given;
|
|
601 |
this corresponds nicely to mutual recursive type definitions, e.g.\
|
|
602 |
in Isabelle/HOL.
|
|
603 |
|
|
604 |
\item [@{command "instance"}] in an instantiation target body sets
|
|
605 |
up a goal stating the type arities claimed at the opening @{command
|
|
606 |
"instantiation"}. The proof would usually proceed by @{method
|
|
607 |
intro_classes}, and then establish the characteristic theorems of
|
|
608 |
the type classes involved. After finishing the proof, the
|
|
609 |
background theory will be augmented by the proven type arities.
|
|
610 |
|
|
611 |
\item [@{command "subclass"}~@{text c}] in a class context for class
|
|
612 |
@{text d} sets up a goal stating that class @{text c} is logically
|
|
613 |
contained in class @{text d}. After finishing the proof, class
|
|
614 |
@{text d} is proven to be subclass @{text c} and the locale @{text
|
|
615 |
c} is interpreted into @{text d} simultaneously.
|
|
616 |
|
|
617 |
\item [@{command "print_classes"}] prints all classes in the current
|
|
618 |
theory.
|
|
619 |
|
|
620 |
\item [@{method intro_classes}] repeatedly expands all class
|
|
621 |
introduction rules of this theory. Note that this method usually
|
|
622 |
needs not be named explicitly, as it is already included in the
|
|
623 |
default proof step (e.g.\ of @{command "proof"}). In particular,
|
|
624 |
instantiation of trivial (syntactic) classes may be performed by a
|
|
625 |
single ``@{command ".."}'' proof step.
|
|
626 |
|
|
627 |
\end{descr}
|
|
628 |
*}
|
|
629 |
|
|
630 |
|
|
631 |
subsubsection {* The class target *}
|
|
632 |
|
|
633 |
text {*
|
|
634 |
%FIXME check
|
|
635 |
|
|
636 |
A named context may refer to a locale (cf.\ \secref{sec:target}).
|
|
637 |
If this locale is also a class @{text c}, apart from the common
|
|
638 |
locale target behaviour the following happens.
|
|
639 |
|
|
640 |
\begin{itemize}
|
|
641 |
|
|
642 |
\item Local constant declarations @{text "g[\<alpha>]"} referring to the
|
|
643 |
local type parameter @{text \<alpha>} and local parameters @{text "f[\<alpha>]"}
|
|
644 |
are accompanied by theory-level constants @{text "g[?\<alpha> :: c]"}
|
|
645 |
referring to theory-level class operations @{text "f[?\<alpha> :: c]"}.
|
|
646 |
|
|
647 |
\item Local theorem bindings are lifted as are assumptions.
|
|
648 |
|
|
649 |
\item Local syntax refers to local operations @{text "g[\<alpha>]"} and
|
|
650 |
global operations @{text "g[?\<alpha> :: c]"} uniformly. Type inference
|
|
651 |
resolves ambiguities. In rare cases, manual type annotations are
|
|
652 |
needed.
|
|
653 |
|
|
654 |
\end{itemize}
|
|
655 |
*}
|
|
656 |
|
|
657 |
|
|
658 |
subsection {* Axiomatic type classes \label{sec:axclass} *}
|
|
659 |
|
|
660 |
text {*
|
|
661 |
\begin{matharray}{rcl}
|
|
662 |
@{command_def "axclass"} & : & \isartrans{theory}{theory} \\
|
|
663 |
@{command_def "instance"} & : & \isartrans{theory}{proof(prove)} \\
|
|
664 |
\end{matharray}
|
|
665 |
|
|
666 |
Axiomatic type classes are Isabelle/Pure's primitive
|
|
667 |
\emph{definitional} interface to type classes. For practical
|
|
668 |
applications, you should consider using classes
|
|
669 |
(cf.~\secref{sec:classes}) which provide high level interface.
|
|
670 |
|
|
671 |
\begin{rail}
|
|
672 |
'axclass' classdecl (axmdecl prop +)
|
|
673 |
;
|
|
674 |
'instance' (nameref ('<' | subseteq) nameref | nameref '::' arity)
|
|
675 |
;
|
|
676 |
\end{rail}
|
|
677 |
|
|
678 |
\begin{descr}
|
|
679 |
|
|
680 |
\item [@{command "axclass"}~@{text "c \<subseteq> c\<^sub>1, \<dots>, c\<^sub>n
|
|
681 |
axms"}] defines an axiomatic type class as the intersection of
|
|
682 |
existing classes, with additional axioms holding. Class axioms may
|
|
683 |
not contain more than one type variable. The class axioms (with
|
|
684 |
implicit sort constraints added) are bound to the given names.
|
|
685 |
Furthermore a class introduction rule is generated (being bound as
|
|
686 |
@{text c_class.intro}); this rule is employed by method @{method
|
|
687 |
intro_classes} to support instantiation proofs of this class.
|
|
688 |
|
|
689 |
The ``class axioms'' are stored as theorems according to the given
|
|
690 |
name specifications, adding @{text "c_class"} as name space prefix;
|
|
691 |
the same facts are also stored collectively as @{text
|
|
692 |
c_class.axioms}.
|
|
693 |
|
|
694 |
\item [@{command "instance"}~@{text "c\<^sub>1 \<subseteq> c\<^sub>2"} and
|
|
695 |
@{command "instance"}~@{text "t :: (s\<^sub>1, \<dots>, s\<^sub>n) s"}]
|
|
696 |
setup a goal stating a class relation or type arity. The proof
|
|
697 |
would usually proceed by @{method intro_classes}, and then establish
|
|
698 |
the characteristic theorems of the type classes involved. After
|
|
699 |
finishing the proof, the theory will be augmented by a type
|
|
700 |
signature declaration corresponding to the resulting theorem.
|
|
701 |
|
|
702 |
\end{descr}
|
|
703 |
*}
|
|
704 |
|
|
705 |
|
|
706 |
subsection {* Arbitrary overloading *}
|
|
707 |
|
|
708 |
text {*
|
|
709 |
Isabelle/Pure's definitional schemes support certain forms of
|
|
710 |
overloading (see \secref{sec:consts}). At most occassions
|
|
711 |
overloading will be used in a Haskell-like fashion together with
|
|
712 |
type classes by means of @{command "instantiation"} (see
|
|
713 |
\secref{sec:class}). Sometimes low-level overloading is desirable.
|
|
714 |
The @{command "overloading"} target provides a convenient view for
|
|
715 |
end-users.
|
|
716 |
|
|
717 |
\begin{matharray}{rcl}
|
|
718 |
@{command_def "overloading"} & : & \isartrans{theory}{local{\dsh}theory} \\
|
|
719 |
\end{matharray}
|
|
720 |
|
|
721 |
\begin{rail}
|
|
722 |
'overloading' \\
|
|
723 |
( string ( '==' | equiv ) term ( '(' 'unchecked' ')' )? + ) 'begin'
|
|
724 |
\end{rail}
|
|
725 |
|
|
726 |
\begin{descr}
|
|
727 |
|
|
728 |
\item [@{command "overloading"}~@{text "x\<^sub>1 \<equiv> c\<^sub>1 ::
|
26789
|
729 |
\<tau>\<^sub>1 \<AND> \<dots> x\<^sub>n \<equiv> c\<^sub>n :: \<tau>\<^sub>n \<BEGIN>"}]
|
26782
|
730 |
opens a theory target (cf.\ \secref{sec:target}) which allows to
|
|
731 |
specify constants with overloaded definitions. These are identified
|
|
732 |
by an explicitly given mapping from variable names @{text
|
|
733 |
"x\<^sub>i"} to constants @{text "c\<^sub>i"} at particular type
|
|
734 |
instances. The definitions themselves are established using common
|
|
735 |
specification tools, using the names @{text "x\<^sub>i"} as
|
|
736 |
reference to the corresponding constants. The target is concluded
|
|
737 |
by @{command "end"}.
|
|
738 |
|
|
739 |
A @{text "(unchecked)"} option disables global dependency checks for
|
|
740 |
the corresponding definition, which is occasionally useful for
|
|
741 |
exotic overloading. It is at the discretion of the user to avoid
|
|
742 |
malformed theory specifications!
|
|
743 |
|
|
744 |
\end{descr}
|
|
745 |
*}
|
|
746 |
|
|
747 |
|
|
748 |
subsection {* Configuration options *}
|
|
749 |
|
|
750 |
text {*
|
|
751 |
Isabelle/Pure maintains a record of named configuration options
|
|
752 |
within the theory or proof context, with values of type @{ML_type
|
|
753 |
bool}, @{ML_type int}, or @{ML_type string}. Tools may declare
|
|
754 |
options in ML, and then refer to these values (relative to the
|
|
755 |
context). Thus global reference variables are easily avoided. The
|
|
756 |
user may change the value of a configuration option by means of an
|
|
757 |
associated attribute of the same name. This form of context
|
|
758 |
declaration works particularly well with commands such as @{command
|
|
759 |
"declare"} or @{command "using"}.
|
|
760 |
|
|
761 |
For historical reasons, some tools cannot take the full proof
|
|
762 |
context into account and merely refer to the background theory.
|
|
763 |
This is accommodated by configuration options being declared as
|
|
764 |
``global'', which may not be changed within a local context.
|
|
765 |
|
|
766 |
\begin{matharray}{rcll}
|
|
767 |
@{command_def "print_configs"} & : & \isarkeep{theory~|~proof} \\
|
|
768 |
\end{matharray}
|
|
769 |
|
|
770 |
\begin{rail}
|
|
771 |
name ('=' ('true' | 'false' | int | name))?
|
|
772 |
\end{rail}
|
|
773 |
|
|
774 |
\begin{descr}
|
|
775 |
|
|
776 |
\item [@{command "print_configs"}] prints the available
|
|
777 |
configuration options, with names, types, and current values.
|
|
778 |
|
|
779 |
\item [@{text "name = value"}] as an attribute expression modifies
|
|
780 |
the named option, with the syntax of the value depending on the
|
|
781 |
option's type. For @{ML_type bool} the default value is @{text
|
|
782 |
true}. Any attempt to change a global option in a local context is
|
|
783 |
ignored.
|
|
784 |
|
|
785 |
\end{descr}
|
|
786 |
*}
|
|
787 |
|
|
788 |
|
|
789 |
section {* Proof tools *}
|
|
790 |
|
|
791 |
subsection {* Miscellaneous methods and attributes \label{sec:misc-meth-att} *}
|
|
792 |
|
|
793 |
text {*
|
|
794 |
\begin{matharray}{rcl}
|
|
795 |
@{method_def unfold} & : & \isarmeth \\
|
|
796 |
@{method_def fold} & : & \isarmeth \\
|
|
797 |
@{method_def insert} & : & \isarmeth \\[0.5ex]
|
|
798 |
@{method_def erule}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
799 |
@{method_def drule}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
800 |
@{method_def frule}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
801 |
@{method_def succeed} & : & \isarmeth \\
|
|
802 |
@{method_def fail} & : & \isarmeth \\
|
|
803 |
\end{matharray}
|
|
804 |
|
|
805 |
\begin{rail}
|
|
806 |
('fold' | 'unfold' | 'insert') thmrefs
|
|
807 |
;
|
|
808 |
('erule' | 'drule' | 'frule') ('('nat')')? thmrefs
|
|
809 |
;
|
|
810 |
\end{rail}
|
|
811 |
|
|
812 |
\begin{descr}
|
|
813 |
|
|
814 |
\item [@{method unfold}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} and @{method
|
|
815 |
fold}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] expand (or fold back) the
|
|
816 |
given definitions throughout all goals; any chained facts provided
|
|
817 |
are inserted into the goal and subject to rewriting as well.
|
|
818 |
|
|
819 |
\item [@{method insert}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] inserts
|
|
820 |
theorems as facts into all goals of the proof state. Note that
|
|
821 |
current facts indicated for forward chaining are ignored.
|
|
822 |
|
|
823 |
\item [@{method erule}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}, @{method
|
|
824 |
drule}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}, and @{method frule}~@{text
|
|
825 |
"a\<^sub>1 \<dots> a\<^sub>n"}] are similar to the basic @{method rule}
|
|
826 |
method (see \secref{sec:pure-meth-att}), but apply rules by
|
|
827 |
elim-resolution, destruct-resolution, and forward-resolution,
|
|
828 |
respectively \cite{isabelle-ref}. The optional natural number
|
|
829 |
argument (default 0) specifies additional assumption steps to be
|
|
830 |
performed here.
|
|
831 |
|
|
832 |
Note that these methods are improper ones, mainly serving for
|
|
833 |
experimentation and tactic script emulation. Different modes of
|
|
834 |
basic rule application are usually expressed in Isar at the proof
|
|
835 |
language level, rather than via implicit proof state manipulations.
|
|
836 |
For example, a proper single-step elimination would be done using
|
|
837 |
the plain @{method rule} method, with forward chaining of current
|
|
838 |
facts.
|
|
839 |
|
|
840 |
\item [@{method succeed}] yields a single (unchanged) result; it is
|
|
841 |
the identity of the ``@{text ","}'' method combinator (cf.\
|
|
842 |
\secref{sec:syn-meth}).
|
|
843 |
|
|
844 |
\item [@{method fail}] yields an empty result sequence; it is the
|
|
845 |
identity of the ``@{text "|"}'' method combinator (cf.\
|
|
846 |
\secref{sec:syn-meth}).
|
|
847 |
|
|
848 |
\end{descr}
|
|
849 |
|
|
850 |
\begin{matharray}{rcl}
|
|
851 |
@{attribute_def tagged} & : & \isaratt \\
|
|
852 |
@{attribute_def untagged} & : & \isaratt \\[0.5ex]
|
|
853 |
@{attribute_def THEN} & : & \isaratt \\
|
|
854 |
@{attribute_def COMP} & : & \isaratt \\[0.5ex]
|
|
855 |
@{attribute_def unfolded} & : & \isaratt \\
|
|
856 |
@{attribute_def folded} & : & \isaratt \\[0.5ex]
|
|
857 |
@{attribute_def rotated} & : & \isaratt \\
|
|
858 |
@{attribute_def (Pure) elim_format} & : & \isaratt \\
|
|
859 |
@{attribute_def standard}@{text "\<^sup>*"} & : & \isaratt \\
|
|
860 |
@{attribute_def no_vars}@{text "\<^sup>*"} & : & \isaratt \\
|
|
861 |
\end{matharray}
|
|
862 |
|
|
863 |
\begin{rail}
|
|
864 |
'tagged' nameref
|
|
865 |
;
|
|
866 |
'untagged' name
|
|
867 |
;
|
|
868 |
('THEN' | 'COMP') ('[' nat ']')? thmref
|
|
869 |
;
|
|
870 |
('unfolded' | 'folded') thmrefs
|
|
871 |
;
|
|
872 |
'rotated' ( int )?
|
|
873 |
\end{rail}
|
|
874 |
|
|
875 |
\begin{descr}
|
|
876 |
|
|
877 |
\item [@{attribute tagged}~@{text "name arg"} and @{attribute
|
|
878 |
untagged}~@{text name}] add and remove \emph{tags} of some theorem.
|
|
879 |
Tags may be any list of string pairs that serve as formal comment.
|
|
880 |
The first string is considered the tag name, the second its
|
|
881 |
argument. Note that @{attribute untagged} removes any tags of the
|
|
882 |
same name.
|
|
883 |
|
|
884 |
\item [@{attribute THEN}~@{text a} and @{attribute COMP}~@{text a}]
|
|
885 |
compose rules by resolution. @{attribute THEN} resolves with the
|
|
886 |
first premise of @{text a} (an alternative position may be also
|
|
887 |
specified); the @{attribute COMP} version skips the automatic
|
|
888 |
lifting process that is normally intended (cf.\ @{ML "op RS"} and
|
|
889 |
@{ML "op COMP"} in \cite[\S5]{isabelle-ref}).
|
|
890 |
|
|
891 |
\item [@{attribute unfolded}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} and
|
|
892 |
@{attribute folded}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] expand and fold
|
|
893 |
back again the given definitions throughout a rule.
|
|
894 |
|
|
895 |
\item [@{attribute rotated}~@{text n}] rotate the premises of a
|
|
896 |
theorem by @{text n} (default 1).
|
|
897 |
|
|
898 |
\item [@{attribute Pure.elim_format}] turns a destruction rule into
|
26844
|
899 |
elimination rule format, by resolving with the rule @{prop "PROP A \<Longrightarrow>
|
|
900 |
(PROP A \<Longrightarrow> PROP B) \<Longrightarrow> PROP B"}.
|
26782
|
901 |
|
|
902 |
Note that the Classical Reasoner (\secref{sec:classical}) provides
|
|
903 |
its own version of this operation.
|
|
904 |
|
|
905 |
\item [@{attribute standard}] puts a theorem into the standard form
|
|
906 |
of object-rules at the outermost theory level. Note that this
|
|
907 |
operation violates the local proof context (including active
|
|
908 |
locales).
|
|
909 |
|
|
910 |
\item [@{attribute no_vars}] replaces schematic variables by free
|
|
911 |
ones; this is mainly for tuning output of pretty printed theorems.
|
|
912 |
|
|
913 |
\end{descr}
|
|
914 |
*}
|
|
915 |
|
|
916 |
|
|
917 |
subsection {* Further tactic emulations \label{sec:tactics} *}
|
|
918 |
|
|
919 |
text {*
|
|
920 |
The following improper proof methods emulate traditional tactics.
|
|
921 |
These admit direct access to the goal state, which is normally
|
|
922 |
considered harmful! In particular, this may involve both numbered
|
|
923 |
goal addressing (default 1), and dynamic instantiation within the
|
|
924 |
scope of some subgoal.
|
|
925 |
|
|
926 |
\begin{warn}
|
|
927 |
Dynamic instantiations refer to universally quantified parameters
|
|
928 |
of a subgoal (the dynamic context) rather than fixed variables and
|
|
929 |
term abbreviations of a (static) Isar context.
|
|
930 |
\end{warn}
|
|
931 |
|
|
932 |
Tactic emulation methods, unlike their ML counterparts, admit
|
|
933 |
simultaneous instantiation from both dynamic and static contexts.
|
|
934 |
If names occur in both contexts goal parameters hide locally fixed
|
|
935 |
variables. Likewise, schematic variables refer to term
|
|
936 |
abbreviations, if present in the static context. Otherwise the
|
|
937 |
schematic variable is interpreted as a schematic variable and left
|
|
938 |
to be solved by unification with certain parts of the subgoal.
|
|
939 |
|
|
940 |
Note that the tactic emulation proof methods in Isabelle/Isar are
|
|
941 |
consistently named @{text foo_tac}. Note also that variable names
|
|
942 |
occurring on left hand sides of instantiations must be preceded by a
|
|
943 |
question mark if they coincide with a keyword or contain dots. This
|
|
944 |
is consistent with the attribute @{attribute "where"} (see
|
|
945 |
\secref{sec:pure-meth-att}).
|
|
946 |
|
|
947 |
\begin{matharray}{rcl}
|
|
948 |
@{method_def rule_tac}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
949 |
@{method_def erule_tac}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
950 |
@{method_def drule_tac}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
951 |
@{method_def frule_tac}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
952 |
@{method_def cut_tac}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
953 |
@{method_def thin_tac}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
954 |
@{method_def subgoal_tac}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
955 |
@{method_def rename_tac}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
956 |
@{method_def rotate_tac}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
957 |
@{method_def tactic}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
958 |
\end{matharray}
|
|
959 |
|
|
960 |
\begin{rail}
|
|
961 |
( 'rule\_tac' | 'erule\_tac' | 'drule\_tac' | 'frule\_tac' | 'cut\_tac' | 'thin\_tac' ) goalspec?
|
|
962 |
( insts thmref | thmrefs )
|
|
963 |
;
|
|
964 |
'subgoal\_tac' goalspec? (prop +)
|
|
965 |
;
|
|
966 |
'rename\_tac' goalspec? (name +)
|
|
967 |
;
|
|
968 |
'rotate\_tac' goalspec? int?
|
|
969 |
;
|
|
970 |
'tactic' text
|
|
971 |
;
|
|
972 |
|
|
973 |
insts: ((name '=' term) + 'and') 'in'
|
|
974 |
;
|
|
975 |
\end{rail}
|
|
976 |
|
|
977 |
\begin{descr}
|
|
978 |
|
|
979 |
\item [@{method rule_tac} etc.] do resolution of rules with explicit
|
|
980 |
instantiation. This works the same way as the ML tactics @{ML
|
|
981 |
res_inst_tac} etc. (see \cite[\S3]{isabelle-ref}).
|
|
982 |
|
|
983 |
Multiple rules may be only given if there is no instantiation; then
|
|
984 |
@{method rule_tac} is the same as @{ML resolve_tac} in ML (see
|
|
985 |
\cite[\S3]{isabelle-ref}).
|
|
986 |
|
|
987 |
\item [@{method cut_tac}] inserts facts into the proof state as
|
|
988 |
assumption of a subgoal, see also @{ML cut_facts_tac} in
|
|
989 |
\cite[\S3]{isabelle-ref}. Note that the scope of schematic
|
|
990 |
variables is spread over the main goal statement. Instantiations
|
|
991 |
may be given as well, see also ML tactic @{ML cut_inst_tac} in
|
|
992 |
\cite[\S3]{isabelle-ref}.
|
|
993 |
|
|
994 |
\item [@{method thin_tac}~@{text \<phi>}] deletes the specified
|
|
995 |
assumption from a subgoal; note that @{text \<phi>} may contain schematic
|
|
996 |
variables. See also @{ML thin_tac} in \cite[\S3]{isabelle-ref}.
|
|
997 |
|
|
998 |
\item [@{method subgoal_tac}~@{text \<phi>}] adds @{text \<phi>} as an
|
|
999 |
assumption to a subgoal. See also @{ML subgoal_tac} and @{ML
|
|
1000 |
subgoals_tac} in \cite[\S3]{isabelle-ref}.
|
|
1001 |
|
|
1002 |
\item [@{method rename_tac}~@{text "x\<^sub>1 \<dots> x\<^sub>n"}] renames
|
|
1003 |
parameters of a goal according to the list @{text "x\<^sub>1, \<dots>,
|
|
1004 |
x\<^sub>n"}, which refers to the \emph{suffix} of variables.
|
|
1005 |
|
|
1006 |
\item [@{method rotate_tac}~@{text n}] rotates the assumptions of a
|
|
1007 |
goal by @{text n} positions: from right to left if @{text n} is
|
|
1008 |
positive, and from left to right if @{text n} is negative; the
|
|
1009 |
default value is 1. See also @{ML rotate_tac} in
|
|
1010 |
\cite[\S3]{isabelle-ref}.
|
|
1011 |
|
|
1012 |
\item [@{method tactic}~@{text "text"}] produces a proof method from
|
|
1013 |
any ML text of type @{ML_type tactic}. Apart from the usual ML
|
|
1014 |
environment and the current implicit theory context, the ML code may
|
|
1015 |
refer to the following locally bound values:
|
|
1016 |
|
|
1017 |
%FIXME check
|
|
1018 |
{\footnotesize\begin{verbatim}
|
|
1019 |
val ctxt : Proof.context
|
|
1020 |
val facts : thm list
|
|
1021 |
val thm : string -> thm
|
|
1022 |
val thms : string -> thm list
|
|
1023 |
\end{verbatim}}
|
|
1024 |
|
|
1025 |
Here @{ML_text ctxt} refers to the current proof context, @{ML_text
|
|
1026 |
facts} indicates any current facts for forward-chaining, and @{ML
|
|
1027 |
thm}~/~@{ML thms} retrieve named facts (including global theorems)
|
|
1028 |
from the context.
|
|
1029 |
|
|
1030 |
\end{descr}
|
|
1031 |
*}
|
|
1032 |
|
|
1033 |
|
|
1034 |
subsection {* The Simplifier \label{sec:simplifier} *}
|
|
1035 |
|
|
1036 |
subsubsection {* Simplification methods *}
|
|
1037 |
|
|
1038 |
text {*
|
|
1039 |
\begin{matharray}{rcl}
|
|
1040 |
@{method_def simp} & : & \isarmeth \\
|
|
1041 |
@{method_def simp_all} & : & \isarmeth \\
|
|
1042 |
\end{matharray}
|
|
1043 |
|
|
1044 |
\indexouternonterm{simpmod}
|
|
1045 |
\begin{rail}
|
|
1046 |
('simp' | 'simp\_all') ('!' ?) opt? (simpmod *)
|
|
1047 |
;
|
|
1048 |
|
|
1049 |
opt: '(' ('no\_asm' | 'no\_asm\_simp' | 'no\_asm\_use' | 'asm\_lr' | 'depth\_limit' ':' nat) ')'
|
|
1050 |
;
|
|
1051 |
simpmod: ('add' | 'del' | 'only' | 'cong' (() | 'add' | 'del') |
|
|
1052 |
'split' (() | 'add' | 'del')) ':' thmrefs
|
|
1053 |
;
|
|
1054 |
\end{rail}
|
|
1055 |
|
|
1056 |
\begin{descr}
|
|
1057 |
|
|
1058 |
\item [@{method simp}] invokes the Simplifier, after declaring
|
|
1059 |
additional rules according to the arguments given. Note that the
|
|
1060 |
\railtterm{only} modifier first removes all other rewrite rules,
|
|
1061 |
congruences, and looper tactics (including splits), and then behaves
|
|
1062 |
like \railtterm{add}.
|
|
1063 |
|
|
1064 |
\medskip The \railtterm{cong} modifiers add or delete Simplifier
|
|
1065 |
congruence rules (see also \cite{isabelle-ref}), the default is to
|
|
1066 |
add.
|
|
1067 |
|
|
1068 |
\medskip The \railtterm{split} modifiers add or delete rules for the
|
|
1069 |
Splitter (see also \cite{isabelle-ref}), the default is to add.
|
|
1070 |
This works only if the Simplifier method has been properly setup to
|
|
1071 |
include the Splitter (all major object logics such HOL, HOLCF, FOL,
|
|
1072 |
ZF do this already).
|
|
1073 |
|
|
1074 |
\item [@{method simp_all}] is similar to @{method simp}, but acts on
|
|
1075 |
all goals (backwards from the last to the first one).
|
|
1076 |
|
|
1077 |
\end{descr}
|
|
1078 |
|
|
1079 |
By default the Simplifier methods take local assumptions fully into
|
|
1080 |
account, using equational assumptions in the subsequent
|
|
1081 |
normalization process, or simplifying assumptions themselves (cf.\
|
|
1082 |
@{ML asm_full_simp_tac} in \cite[\S10]{isabelle-ref}). In
|
|
1083 |
structured proofs this is usually quite well behaved in practice:
|
|
1084 |
just the local premises of the actual goal are involved, additional
|
|
1085 |
facts may be inserted via explicit forward-chaining (via @{command
|
|
1086 |
"then"}, @{command "from"}, @{command "using"} etc.). The full
|
|
1087 |
context of premises is only included if the ``@{text "!"}'' (bang)
|
|
1088 |
argument is given, which should be used with some care, though.
|
|
1089 |
|
|
1090 |
Additional Simplifier options may be specified to tune the behavior
|
|
1091 |
further (mostly for unstructured scripts with many accidental local
|
|
1092 |
facts): ``@{text "(no_asm)"}'' means assumptions are ignored
|
|
1093 |
completely (cf.\ @{ML simp_tac}), ``@{text "(no_asm_simp)"}'' means
|
|
1094 |
assumptions are used in the simplification of the conclusion but are
|
|
1095 |
not themselves simplified (cf.\ @{ML asm_simp_tac}), and ``@{text
|
|
1096 |
"(no_asm_use)"}'' means assumptions are simplified but are not used
|
|
1097 |
in the simplification of each other or the conclusion (cf.\ @{ML
|
|
1098 |
full_simp_tac}). For compatibility reasons, there is also an option
|
|
1099 |
``@{text "(asm_lr)"}'', which means that an assumption is only used
|
|
1100 |
for simplifying assumptions which are to the right of it (cf.\ @{ML
|
|
1101 |
asm_lr_simp_tac}).
|
|
1102 |
|
|
1103 |
Giving an option ``@{text "(depth_limit: n)"}'' limits the number of
|
|
1104 |
recursive invocations of the simplifier during conditional
|
|
1105 |
rewriting.
|
|
1106 |
|
|
1107 |
\medskip The Splitter package is usually configured to work as part
|
|
1108 |
of the Simplifier. The effect of repeatedly applying @{ML
|
|
1109 |
split_tac} can be simulated by ``@{text "(simp only: split:
|
|
1110 |
a\<^sub>1 \<dots> a\<^sub>n)"}''. There is also a separate @{text split}
|
|
1111 |
method available for single-step case splitting.
|
|
1112 |
*}
|
|
1113 |
|
|
1114 |
|
|
1115 |
subsubsection {* Declaring rules *}
|
|
1116 |
|
|
1117 |
text {*
|
|
1118 |
\begin{matharray}{rcl}
|
|
1119 |
@{command_def "print_simpset"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
|
|
1120 |
@{attribute_def simp} & : & \isaratt \\
|
|
1121 |
@{attribute_def cong} & : & \isaratt \\
|
|
1122 |
@{attribute_def split} & : & \isaratt \\
|
|
1123 |
\end{matharray}
|
|
1124 |
|
|
1125 |
\begin{rail}
|
|
1126 |
('simp' | 'cong' | 'split') (() | 'add' | 'del')
|
|
1127 |
;
|
|
1128 |
\end{rail}
|
|
1129 |
|
|
1130 |
\begin{descr}
|
|
1131 |
|
|
1132 |
\item [@{command "print_simpset"}] prints the collection of rules
|
|
1133 |
declared to the Simplifier, which is also known as ``simpset''
|
|
1134 |
internally \cite{isabelle-ref}.
|
|
1135 |
|
|
1136 |
\item [@{attribute simp}] declares simplification rules.
|
|
1137 |
|
|
1138 |
\item [@{attribute cong}] declares congruence rules.
|
|
1139 |
|
|
1140 |
\item [@{attribute split}] declares case split rules.
|
|
1141 |
|
|
1142 |
\end{descr}
|
|
1143 |
*}
|
|
1144 |
|
|
1145 |
|
|
1146 |
subsubsection {* Simplification procedures *}
|
|
1147 |
|
|
1148 |
text {*
|
|
1149 |
\begin{matharray}{rcl}
|
|
1150 |
@{command_def "simproc_setup"} & : & \isarkeep{local{\dsh}theory} \\
|
|
1151 |
simproc & : & \isaratt \\
|
|
1152 |
\end{matharray}
|
|
1153 |
|
|
1154 |
\begin{rail}
|
|
1155 |
'simproc\_setup' name '(' (term + '|') ')' '=' text \\ ('identifier' (nameref+))?
|
|
1156 |
;
|
|
1157 |
|
|
1158 |
'simproc' (('add' ':')? | 'del' ':') (name+)
|
|
1159 |
;
|
|
1160 |
\end{rail}
|
|
1161 |
|
|
1162 |
\begin{descr}
|
|
1163 |
|
|
1164 |
\item [@{command "simproc_setup"}] defines a named simplification
|
|
1165 |
procedure that is invoked by the Simplifier whenever any of the
|
|
1166 |
given term patterns match the current redex. The implementation,
|
|
1167 |
which is provided as ML source text, needs to be of type @{ML_type
|
|
1168 |
"morphism -> simpset -> cterm -> thm option"}, where the @{ML_type
|
|
1169 |
cterm} represents the current redex @{text r} and the result is
|
|
1170 |
supposed to be some proven rewrite rule @{text "r \<equiv> r'"} (or a
|
|
1171 |
generalized version), or @{ML NONE} to indicate failure. The
|
|
1172 |
@{ML_type simpset} argument holds the full context of the current
|
|
1173 |
Simplifier invocation, including the actual Isar proof context. The
|
|
1174 |
@{ML_type morphism} informs about the difference of the original
|
|
1175 |
compilation context wrt.\ the one of the actual application later
|
|
1176 |
on. The optional @{keyword "identifier"} specifies theorems that
|
|
1177 |
represent the logical content of the abstract theory of this
|
|
1178 |
simproc.
|
|
1179 |
|
|
1180 |
Morphisms and identifiers are only relevant for simprocs that are
|
|
1181 |
defined within a local target context, e.g.\ in a locale.
|
|
1182 |
|
|
1183 |
\item [@{text "simproc add: name"} and @{text "simproc del: name"}]
|
|
1184 |
add or delete named simprocs to the current Simplifier context. The
|
|
1185 |
default is to add a simproc. Note that @{command "simproc_setup"}
|
|
1186 |
already adds the new simproc to the subsequent context.
|
|
1187 |
|
|
1188 |
\end{descr}
|
|
1189 |
*}
|
|
1190 |
|
|
1191 |
|
|
1192 |
subsubsection {* Forward simplification *}
|
|
1193 |
|
|
1194 |
text {*
|
|
1195 |
\begin{matharray}{rcl}
|
|
1196 |
@{attribute_def simplified} & : & \isaratt \\
|
|
1197 |
\end{matharray}
|
|
1198 |
|
|
1199 |
\begin{rail}
|
|
1200 |
'simplified' opt? thmrefs?
|
|
1201 |
;
|
|
1202 |
|
26789
|
1203 |
opt: '(' ('no\_asm' | 'no\_asm\_simp' | 'no\_asm\_use') ')'
|
26782
|
1204 |
;
|
|
1205 |
\end{rail}
|
|
1206 |
|
|
1207 |
\begin{descr}
|
|
1208 |
|
|
1209 |
\item [@{attribute simplified}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}]
|
|
1210 |
causes a theorem to be simplified, either by exactly the specified
|
|
1211 |
rules @{text "a\<^sub>1, \<dots>, a\<^sub>n"}, or the implicit Simplifier
|
|
1212 |
context if no arguments are given. The result is fully simplified
|
|
1213 |
by default, including assumptions and conclusion; the options @{text
|
|
1214 |
no_asm} etc.\ tune the Simplifier in the same way as the for the
|
|
1215 |
@{text simp} method.
|
|
1216 |
|
|
1217 |
Note that forward simplification restricts the simplifier to its
|
|
1218 |
most basic operation of term rewriting; solver and looper tactics
|
|
1219 |
\cite{isabelle-ref} are \emph{not} involved here. The @{text
|
|
1220 |
simplified} attribute should be only rarely required under normal
|
|
1221 |
circumstances.
|
|
1222 |
|
|
1223 |
\end{descr}
|
|
1224 |
*}
|
|
1225 |
|
|
1226 |
|
|
1227 |
subsubsection {* Low-level equational reasoning *}
|
|
1228 |
|
|
1229 |
text {*
|
|
1230 |
\begin{matharray}{rcl}
|
|
1231 |
@{method_def subst}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
1232 |
@{method_def hypsubst}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
1233 |
@{method_def split}@{text "\<^sup>*"} & : & \isarmeth \\
|
|
1234 |
\end{matharray}
|
|
1235 |
|
|
1236 |
\begin{rail}
|
|
1237 |
'subst' ('(' 'asm' ')')? ('(' (nat+) ')')? thmref
|
|
1238 |
;
|
|
1239 |
'split' ('(' 'asm' ')')? thmrefs
|
|
1240 |
;
|
|
1241 |
\end{rail}
|
|
1242 |
|
|
1243 |
These methods provide low-level facilities for equational reasoning
|
|
1244 |
that are intended for specialized applications only. Normally,
|
|
1245 |
single step calculations would be performed in a structured text
|
|
1246 |
(see also \secref{sec:calculation}), while the Simplifier methods
|
|
1247 |
provide the canonical way for automated normalization (see
|
|
1248 |
\secref{sec:simplifier}).
|
|
1249 |
|
|
1250 |
\begin{descr}
|
|
1251 |
|
|
1252 |
\item [@{method subst}~@{text eq}] performs a single substitution
|
|
1253 |
step using rule @{text eq}, which may be either a meta or object
|
|
1254 |
equality.
|
|
1255 |
|
|
1256 |
\item [@{method subst}~@{text "(asm) eq"}] substitutes in an
|
|
1257 |
assumption.
|
|
1258 |
|
|
1259 |
\item [@{method subst}~@{text "(i \<dots> j) eq"}] performs several
|
|
1260 |
substitutions in the conclusion. The numbers @{text i} to @{text j}
|
|
1261 |
indicate the positions to substitute at. Positions are ordered from
|
|
1262 |
the top of the term tree moving down from left to right. For
|
|
1263 |
example, in @{text "(a + b) + (c + d)"} there are three positions
|
|
1264 |
where commutativity of @{text "+"} is applicable: 1 refers to the
|
|
1265 |
whole term, 2 to @{text "a + b"} and 3 to @{text "c + d"}.
|
|
1266 |
|
|
1267 |
If the positions in the list @{text "(i \<dots> j)"} are non-overlapping
|
|
1268 |
(e.g.\ @{text "(2 3)"} in @{text "(a + b) + (c + d)"}) you may
|
|
1269 |
assume all substitutions are performed simultaneously. Otherwise
|
|
1270 |
the behaviour of @{text subst} is not specified.
|
|
1271 |
|
|
1272 |
\item [@{method subst}~@{text "(asm) (i \<dots> j) eq"}] performs the
|
|
1273 |
substitutions in the assumptions. Positions @{text "1 \<dots> i\<^sub>1"}
|
|
1274 |
refer to assumption 1, positions @{text "i\<^sub>1 + 1 \<dots> i\<^sub>2"}
|
|
1275 |
to assumption 2, and so on.
|
|
1276 |
|
|
1277 |
\item [@{method hypsubst}] performs substitution using some
|
|
1278 |
assumption; this only works for equations of the form @{text "x =
|
|
1279 |
t"} where @{text x} is a free or bound variable.
|
|
1280 |
|
|
1281 |
\item [@{method split}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] performs
|
|
1282 |
single-step case splitting using the given rules. By default,
|
|
1283 |
splitting is performed in the conclusion of a goal; the @{text
|
|
1284 |
"(asm)"} option indicates to operate on assumptions instead.
|
|
1285 |
|
|
1286 |
Note that the @{method simp} method already involves repeated
|
|
1287 |
application of split rules as declared in the current context.
|
|
1288 |
|
|
1289 |
\end{descr}
|
|
1290 |
*}
|
|
1291 |
|
|
1292 |
|
|
1293 |
subsection {* The Classical Reasoner \label{sec:classical} *}
|
|
1294 |
|
|
1295 |
subsubsection {* Basic methods *}
|
|
1296 |
|
|
1297 |
text {*
|
|
1298 |
\begin{matharray}{rcl}
|
|
1299 |
@{method_def rule} & : & \isarmeth \\
|
|
1300 |
@{method_def contradiction} & : & \isarmeth \\
|
|
1301 |
@{method_def intro} & : & \isarmeth \\
|
|
1302 |
@{method_def elim} & : & \isarmeth \\
|
|
1303 |
\end{matharray}
|
|
1304 |
|
|
1305 |
\begin{rail}
|
|
1306 |
('rule' | 'intro' | 'elim') thmrefs?
|
|
1307 |
;
|
|
1308 |
\end{rail}
|
|
1309 |
|
|
1310 |
\begin{descr}
|
|
1311 |
|
|
1312 |
\item [@{method rule}] as offered by the Classical Reasoner is a
|
|
1313 |
refinement over the primitive one (see \secref{sec:pure-meth-att}).
|
|
1314 |
Both versions essentially work the same, but the classical version
|
|
1315 |
observes the classical rule context in addition to that of
|
|
1316 |
Isabelle/Pure.
|
|
1317 |
|
|
1318 |
Common object logics (HOL, ZF, etc.) declare a rich collection of
|
|
1319 |
classical rules (even if these would qualify as intuitionistic
|
|
1320 |
ones), but only few declarations to the rule context of
|
|
1321 |
Isabelle/Pure (\secref{sec:pure-meth-att}).
|
|
1322 |
|
|
1323 |
\item [@{method contradiction}] solves some goal by contradiction,
|
|
1324 |
deriving any result from both @{text "\<not> A"} and @{text A}. Chained
|
|
1325 |
facts, which are guaranteed to participate, may appear in either
|
|
1326 |
order.
|
|
1327 |
|
|
1328 |
\item [@{attribute intro} and @{attribute elim}] repeatedly refine
|
|
1329 |
some goal by intro- or elim-resolution, after having inserted any
|
|
1330 |
chained facts. Exactly the rules given as arguments are taken into
|
|
1331 |
account; this allows fine-tuned decomposition of a proof problem, in
|
|
1332 |
contrast to common automated tools.
|
|
1333 |
|
|
1334 |
\end{descr}
|
|
1335 |
*}
|
|
1336 |
|
|
1337 |
|
|
1338 |
subsubsection {* Automated methods *}
|
|
1339 |
|
|
1340 |
text {*
|
|
1341 |
\begin{matharray}{rcl}
|
|
1342 |
@{method_def blast} & : & \isarmeth \\
|
|
1343 |
@{method_def fast} & : & \isarmeth \\
|
|
1344 |
@{method_def slow} & : & \isarmeth \\
|
|
1345 |
@{method_def best} & : & \isarmeth \\
|
|
1346 |
@{method_def safe} & : & \isarmeth \\
|
|
1347 |
@{method_def clarify} & : & \isarmeth \\
|
|
1348 |
\end{matharray}
|
|
1349 |
|
|
1350 |
\indexouternonterm{clamod}
|
|
1351 |
\begin{rail}
|
|
1352 |
'blast' ('!' ?) nat? (clamod *)
|
|
1353 |
;
|
|
1354 |
('fast' | 'slow' | 'best' | 'safe' | 'clarify') ('!' ?) (clamod *)
|
|
1355 |
;
|
|
1356 |
|
|
1357 |
clamod: (('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del') ':' thmrefs
|
|
1358 |
;
|
|
1359 |
\end{rail}
|
|
1360 |
|
|
1361 |
\begin{descr}
|
|
1362 |
|
|
1363 |
\item [@{method blast}] refers to the classical tableau prover (see
|
|
1364 |
@{ML blast_tac} in \cite[\S11]{isabelle-ref}). The optional
|
|
1365 |
argument specifies a user-supplied search bound (default 20).
|
|
1366 |
|
|
1367 |
\item [@{method fast}, @{method slow}, @{method best}, @{method
|
|
1368 |
safe}, and @{method clarify}] refer to the generic classical
|
|
1369 |
reasoner. See @{ML fast_tac}, @{ML slow_tac}, @{ML best_tac}, @{ML
|
|
1370 |
safe_tac}, and @{ML clarify_tac} in \cite[\S11]{isabelle-ref} for
|
|
1371 |
more information.
|
|
1372 |
|
|
1373 |
\end{descr}
|
|
1374 |
|
|
1375 |
Any of the above methods support additional modifiers of the context
|
|
1376 |
of classical rules. Their semantics is analogous to the attributes
|
|
1377 |
given before. Facts provided by forward chaining are inserted into
|
|
1378 |
the goal before commencing proof search. The ``@{text
|
|
1379 |
"!"}''~argument causes the full context of assumptions to be
|
|
1380 |
included as well.
|
|
1381 |
*}
|
|
1382 |
|
|
1383 |
|
|
1384 |
subsubsection {* Combined automated methods \label{sec:clasimp} *}
|
|
1385 |
|
|
1386 |
text {*
|
|
1387 |
\begin{matharray}{rcl}
|
|
1388 |
@{method_def auto} & : & \isarmeth \\
|
|
1389 |
@{method_def force} & : & \isarmeth \\
|
|
1390 |
@{method_def clarsimp} & : & \isarmeth \\
|
|
1391 |
@{method_def fastsimp} & : & \isarmeth \\
|
|
1392 |
@{method_def slowsimp} & : & \isarmeth \\
|
|
1393 |
@{method_def bestsimp} & : & \isarmeth \\
|
|
1394 |
\end{matharray}
|
|
1395 |
|
|
1396 |
\indexouternonterm{clasimpmod}
|
|
1397 |
\begin{rail}
|
|
1398 |
'auto' '!'? (nat nat)? (clasimpmod *)
|
|
1399 |
;
|
|
1400 |
('force' | 'clarsimp' | 'fastsimp' | 'slowsimp' | 'bestsimp') '!'? (clasimpmod *)
|
|
1401 |
;
|
|
1402 |
|
|
1403 |
clasimpmod: ('simp' (() | 'add' | 'del' | 'only') |
|
|
1404 |
('cong' | 'split') (() | 'add' | 'del') |
|
|
1405 |
'iff' (((() | 'add') '?'?) | 'del') |
|
|
1406 |
(('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del')) ':' thmrefs
|
|
1407 |
\end{rail}
|
|
1408 |
|
|
1409 |
\begin{descr}
|
|
1410 |
|
|
1411 |
\item [@{method auto}, @{method force}, @{method clarsimp}, @{method
|
|
1412 |
fastsimp}, @{method slowsimp}, and @{method bestsimp}] provide
|
|
1413 |
access to Isabelle's combined simplification and classical reasoning
|
|
1414 |
tactics. These correspond to @{ML auto_tac}, @{ML force_tac}, @{ML
|
|
1415 |
clarsimp_tac}, and Classical Reasoner tactics with the Simplifier
|
|
1416 |
added as wrapper, see \cite[\S11]{isabelle-ref} for more
|
|
1417 |
information. The modifier arguments correspond to those given in
|
|
1418 |
\secref{sec:simplifier} and \secref{sec:classical}. Just note that
|
|
1419 |
the ones related to the Simplifier are prefixed by \railtterm{simp}
|
|
1420 |
here.
|
|
1421 |
|
|
1422 |
Facts provided by forward chaining are inserted into the goal before
|
|
1423 |
doing the search. The ``@{text "!"}'' argument causes the full
|
|
1424 |
context of assumptions to be included as well.
|
|
1425 |
|
|
1426 |
\end{descr}
|
|
1427 |
*}
|
|
1428 |
|
|
1429 |
|
|
1430 |
subsubsection {* Declaring rules *}
|
|
1431 |
|
|
1432 |
text {*
|
|
1433 |
\begin{matharray}{rcl}
|
|
1434 |
@{command_def "print_claset"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
|
|
1435 |
@{attribute_def intro} & : & \isaratt \\
|
|
1436 |
@{attribute_def elim} & : & \isaratt \\
|
|
1437 |
@{attribute_def dest} & : & \isaratt \\
|
|
1438 |
@{attribute_def rule} & : & \isaratt \\
|
|
1439 |
@{attribute_def iff} & : & \isaratt \\
|
|
1440 |
\end{matharray}
|
|
1441 |
|
|
1442 |
\begin{rail}
|
|
1443 |
('intro' | 'elim' | 'dest') ('!' | () | '?') nat?
|
|
1444 |
;
|
|
1445 |
'rule' 'del'
|
|
1446 |
;
|
|
1447 |
'iff' (((() | 'add') '?'?) | 'del')
|
|
1448 |
;
|
|
1449 |
\end{rail}
|
|
1450 |
|
|
1451 |
\begin{descr}
|
|
1452 |
|
|
1453 |
\item [@{command "print_claset"}] prints the collection of rules
|
|
1454 |
declared to the Classical Reasoner, which is also known as
|
|
1455 |
``claset'' internally \cite{isabelle-ref}.
|
|
1456 |
|
|
1457 |
\item [@{attribute intro}, @{attribute elim}, and @{attribute dest}]
|
|
1458 |
declare introduction, elimination, and destruction rules,
|
|
1459 |
respectively. By default, rules are considered as \emph{unsafe}
|
|
1460 |
(i.e.\ not applied blindly without backtracking), while ``@{text
|
|
1461 |
"!"}'' classifies as \emph{safe}. Rule declarations marked by
|
|
1462 |
``@{text "?"}'' coincide with those of Isabelle/Pure, cf.\
|
|
1463 |
\secref{sec:pure-meth-att} (i.e.\ are only applied in single steps
|
|
1464 |
of the @{method rule} method). The optional natural number
|
|
1465 |
specifies an explicit weight argument, which is ignored by automated
|
|
1466 |
tools, but determines the search order of single rule steps.
|
|
1467 |
|
|
1468 |
\item [@{attribute rule}~@{text del}] deletes introduction,
|
|
1469 |
elimination, or destruction rules from the context.
|
|
1470 |
|
|
1471 |
\item [@{attribute iff}] declares logical equivalences to the
|
|
1472 |
Simplifier and the Classical reasoner at the same time.
|
|
1473 |
Non-conditional rules result in a ``safe'' introduction and
|
|
1474 |
elimination pair; conditional ones are considered ``unsafe''. Rules
|
|
1475 |
with negative conclusion are automatically inverted (using @{text
|
26789
|
1476 |
"\<not>"}-elimination internally).
|
26782
|
1477 |
|
|
1478 |
The ``@{text "?"}'' version of @{attribute iff} declares rules to
|
|
1479 |
the Isabelle/Pure context only, and omits the Simplifier
|
|
1480 |
declaration.
|
|
1481 |
|
|
1482 |
\end{descr}
|
|
1483 |
*}
|
|
1484 |
|
|
1485 |
|
|
1486 |
subsubsection {* Classical operations *}
|
|
1487 |
|
|
1488 |
text {*
|
|
1489 |
\begin{matharray}{rcl}
|
|
1490 |
@{attribute_def swapped} & : & \isaratt \\
|
|
1491 |
\end{matharray}
|
|
1492 |
|
|
1493 |
\begin{descr}
|
|
1494 |
|
|
1495 |
\item [@{attribute swapped}] turns an introduction rule into an
|
|
1496 |
elimination, by resolving with the classical swap principle @{text
|
|
1497 |
"(\<not> B \<Longrightarrow> A) \<Longrightarrow> (\<not> A \<Longrightarrow> B)"}.
|
|
1498 |
|
|
1499 |
\end{descr}
|
|
1500 |
*}
|
|
1501 |
|
|
1502 |
|
|
1503 |
subsection {* Proof by cases and induction \label{sec:cases-induct} *}
|
|
1504 |
|
|
1505 |
subsubsection {* Rule contexts *}
|
|
1506 |
|
|
1507 |
text {*
|
|
1508 |
\begin{matharray}{rcl}
|
|
1509 |
@{command_def "case"} & : & \isartrans{proof(state)}{proof(state)} \\
|
|
1510 |
@{command_def "print_cases"}@{text "\<^sup>*"} & : & \isarkeep{proof} \\
|
|
1511 |
@{attribute_def case_names} & : & \isaratt \\
|
|
1512 |
@{attribute_def case_conclusion} & : & \isaratt \\
|
|
1513 |
@{attribute_def params} & : & \isaratt \\
|
|
1514 |
@{attribute_def consumes} & : & \isaratt \\
|
|
1515 |
\end{matharray}
|
|
1516 |
|
|
1517 |
The puristic way to build up Isar proof contexts is by explicit
|
|
1518 |
language elements like @{command "fix"}, @{command "assume"},
|
|
1519 |
@{command "let"} (see \secref{sec:proof-context}). This is adequate
|
|
1520 |
for plain natural deduction, but easily becomes unwieldy in concrete
|
|
1521 |
verification tasks, which typically involve big induction rules with
|
|
1522 |
several cases.
|
|
1523 |
|
|
1524 |
The @{command "case"} command provides a shorthand to refer to a
|
|
1525 |
local context symbolically: certain proof methods provide an
|
|
1526 |
environment of named ``cases'' of the form @{text "c: x\<^sub>1, \<dots>,
|
26789
|
1527 |
x\<^sub>m, \<phi>\<^sub>1, \<dots>, \<phi>\<^sub>n"}; the effect of ``@{command
|
|
1528 |
"case"}~@{text c}'' is then equivalent to ``@{command "fix"}~@{text
|
|
1529 |
"x\<^sub>1 \<dots> x\<^sub>m"}~@{command "assume"}~@{text "c: \<phi>\<^sub>1 \<dots>
|
|
1530 |
\<phi>\<^sub>n"}''. Term bindings may be covered as well, notably
|
|
1531 |
@{variable ?case} for the main conclusion.
|
26782
|
1532 |
|
|
1533 |
By default, the ``terminology'' @{text "x\<^sub>1, \<dots>, x\<^sub>m"} of
|
|
1534 |
a case value is marked as hidden, i.e.\ there is no way to refer to
|
|
1535 |
such parameters in the subsequent proof text. After all, original
|
|
1536 |
rule parameters stem from somewhere outside of the current proof
|
|
1537 |
text. By using the explicit form ``@{command "case"}~@{text "(c
|
|
1538 |
y\<^sub>1 \<dots> y\<^sub>m)"}'' instead, the proof author is able to
|
|
1539 |
chose local names that fit nicely into the current context.
|
|
1540 |
|
|
1541 |
\medskip It is important to note that proper use of @{command
|
|
1542 |
"case"} does not provide means to peek at the current goal state,
|
|
1543 |
which is not directly observable in Isar! Nonetheless, goal
|
|
1544 |
refinement commands do provide named cases @{text "goal\<^sub>i"}
|
|
1545 |
for each subgoal @{text "i = 1, \<dots>, n"} of the resulting goal state.
|
|
1546 |
Using this extra feature requires great care, because some bits of
|
|
1547 |
the internal tactical machinery intrude the proof text. In
|
|
1548 |
particular, parameter names stemming from the left-over of automated
|
|
1549 |
reasoning tools are usually quite unpredictable.
|
|
1550 |
|
|
1551 |
Under normal circumstances, the text of cases emerge from standard
|
|
1552 |
elimination or induction rules, which in turn are derived from
|
|
1553 |
previous theory specifications in a canonical way (say from
|
|
1554 |
@{command "inductive"} definitions).
|
|
1555 |
|
|
1556 |
\medskip Proper cases are only available if both the proof method
|
|
1557 |
and the rules involved support this. By using appropriate
|
|
1558 |
attributes, case names, conclusions, and parameters may be also
|
|
1559 |
declared by hand. Thus variant versions of rules that have been
|
|
1560 |
derived manually become ready to use in advanced case analysis
|
|
1561 |
later.
|
|
1562 |
|
|
1563 |
\begin{rail}
|
|
1564 |
'case' (caseref | '(' caseref ((name | underscore) +) ')')
|
|
1565 |
;
|
|
1566 |
caseref: nameref attributes?
|
|
1567 |
;
|
|
1568 |
|
|
1569 |
'case\_names' (name +)
|
|
1570 |
;
|
|
1571 |
'case\_conclusion' name (name *)
|
|
1572 |
;
|
|
1573 |
'params' ((name *) + 'and')
|
|
1574 |
;
|
|
1575 |
'consumes' nat?
|
|
1576 |
;
|
|
1577 |
\end{rail}
|
|
1578 |
|
|
1579 |
\begin{descr}
|
|
1580 |
|
|
1581 |
\item [@{command "case"}~@{text "(c x\<^sub>1 \<dots> x\<^sub>m)"}]
|
|
1582 |
invokes a named local context @{text "c: x\<^sub>1, \<dots>, x\<^sub>m,
|
|
1583 |
\<phi>\<^sub>1, \<dots>, \<phi>\<^sub>m"}, as provided by an appropriate
|
|
1584 |
proof method (such as @{method_ref cases} and @{method_ref induct}).
|
|
1585 |
The command ``@{command "case"}~@{text "(c x\<^sub>1 \<dots>
|
|
1586 |
x\<^sub>m)"}'' abbreviates ``@{command "fix"}~@{text "x\<^sub>1 \<dots>
|
|
1587 |
x\<^sub>m"}~@{command "assume"}~@{text "c: \<phi>\<^sub>1 \<dots>
|
|
1588 |
\<phi>\<^sub>n"}''.
|
|
1589 |
|
|
1590 |
\item [@{command "print_cases"}] prints all local contexts of the
|
|
1591 |
current state, using Isar proof language notation.
|
|
1592 |
|
|
1593 |
\item [@{attribute case_names}~@{text "c\<^sub>1 \<dots> c\<^sub>k"}]
|
|
1594 |
declares names for the local contexts of premises of a theorem;
|
|
1595 |
@{text "c\<^sub>1, \<dots>, c\<^sub>k"} refers to the \emph{suffix} of the
|
|
1596 |
list of premises.
|
|
1597 |
|
|
1598 |
\item [@{attribute case_conclusion}~@{text "c d\<^sub>1 \<dots>
|
|
1599 |
d\<^sub>k"}] declares names for the conclusions of a named premise
|
|
1600 |
@{text c}; here @{text "d\<^sub>1, \<dots>, d\<^sub>k"} refers to the
|
|
1601 |
prefix of arguments of a logical formula built by nesting a binary
|
|
1602 |
connective (e.g.\ @{text "\<or>"}).
|
|
1603 |
|
|
1604 |
Note that proof methods such as @{method induct} and @{method
|
|
1605 |
coinduct} already provide a default name for the conclusion as a
|
|
1606 |
whole. The need to name subformulas only arises with cases that
|
|
1607 |
split into several sub-cases, as in common co-induction rules.
|
|
1608 |
|
|
1609 |
\item [@{attribute params}~@{text "p\<^sub>1 \<dots> p\<^sub>m \<AND> \<dots>
|
|
1610 |
q\<^sub>1 \<dots> q\<^sub>n"}] renames the innermost parameters of
|
|
1611 |
premises @{text "1, \<dots>, n"} of some theorem. An empty list of names
|
|
1612 |
may be given to skip positions, leaving the present parameters
|
|
1613 |
unchanged.
|
|
1614 |
|
|
1615 |
Note that the default usage of case rules does \emph{not} directly
|
|
1616 |
expose parameters to the proof context.
|
|
1617 |
|
|
1618 |
\item [@{attribute consumes}~@{text n}] declares the number of
|
|
1619 |
``major premises'' of a rule, i.e.\ the number of facts to be
|
|
1620 |
consumed when it is applied by an appropriate proof method. The
|
|
1621 |
default value of @{attribute consumes} is @{text "n = 1"}, which is
|
|
1622 |
appropriate for the usual kind of cases and induction rules for
|
|
1623 |
inductive sets (cf.\ \secref{sec:hol-inductive}). Rules without any
|
|
1624 |
@{attribute consumes} declaration given are treated as if
|
|
1625 |
@{attribute consumes}~@{text 0} had been specified.
|
|
1626 |
|
|
1627 |
Note that explicit @{attribute consumes} declarations are only
|
|
1628 |
rarely needed; this is already taken care of automatically by the
|
|
1629 |
higher-level @{attribute cases}, @{attribute induct}, and
|
|
1630 |
@{attribute coinduct} declarations.
|
|
1631 |
|
|
1632 |
\end{descr}
|
|
1633 |
*}
|
|
1634 |
|
|
1635 |
|
|
1636 |
subsubsection {* Proof methods *}
|
|
1637 |
|
|
1638 |
text {*
|
|
1639 |
\begin{matharray}{rcl}
|
|
1640 |
@{method_def cases} & : & \isarmeth \\
|
|
1641 |
@{method_def induct} & : & \isarmeth \\
|
|
1642 |
@{method_def coinduct} & : & \isarmeth \\
|
|
1643 |
\end{matharray}
|
|
1644 |
|
|
1645 |
The @{method cases}, @{method induct}, and @{method coinduct}
|
|
1646 |
methods provide a uniform interface to common proof techniques over
|
|
1647 |
datatypes, inductive predicates (or sets), recursive functions etc.
|
|
1648 |
The corresponding rules may be specified and instantiated in a
|
|
1649 |
casual manner. Furthermore, these methods provide named local
|
|
1650 |
contexts that may be invoked via the @{command "case"} proof command
|
|
1651 |
within the subsequent proof text. This accommodates compact proof
|
|
1652 |
texts even when reasoning about large specifications.
|
|
1653 |
|
|
1654 |
The @{method induct} method also provides some additional
|
|
1655 |
infrastructure in order to be applicable to structure statements
|
|
1656 |
(either using explicit meta-level connectives, or including facts
|
|
1657 |
and parameters separately). This avoids cumbersome encoding of
|
|
1658 |
``strengthened'' inductive statements within the object-logic.
|
|
1659 |
|
|
1660 |
\begin{rail}
|
|
1661 |
'cases' (insts * 'and') rule?
|
|
1662 |
;
|
|
1663 |
'induct' (definsts * 'and') \\ arbitrary? taking? rule?
|
|
1664 |
;
|
|
1665 |
'coinduct' insts taking rule?
|
|
1666 |
;
|
|
1667 |
|
|
1668 |
rule: ('type' | 'pred' | 'set') ':' (nameref +) | 'rule' ':' (thmref +)
|
|
1669 |
;
|
|
1670 |
definst: name ('==' | equiv) term | inst
|
|
1671 |
;
|
|
1672 |
definsts: ( definst *)
|
|
1673 |
;
|
|
1674 |
arbitrary: 'arbitrary' ':' ((term *) 'and' +)
|
|
1675 |
;
|
|
1676 |
taking: 'taking' ':' insts
|
|
1677 |
;
|
|
1678 |
\end{rail}
|
|
1679 |
|
|
1680 |
\begin{descr}
|
|
1681 |
|
|
1682 |
\item [@{method cases}~@{text "insts R"}] applies method @{method
|
|
1683 |
rule} with an appropriate case distinction theorem, instantiated to
|
|
1684 |
the subjects @{text insts}. Symbolic case names are bound according
|
|
1685 |
to the rule's local contexts.
|
|
1686 |
|
|
1687 |
The rule is determined as follows, according to the facts and
|
|
1688 |
arguments passed to the @{method cases} method:
|
|
1689 |
|
|
1690 |
\medskip
|
|
1691 |
\begin{tabular}{llll}
|
26789
|
1692 |
facts & & arguments & rule \\\hline
|
|
1693 |
& @{method cases} & & classical case split \\
|
|
1694 |
& @{method cases} & @{text t} & datatype exhaustion (type of @{text t}) \\
|
26782
|
1695 |
@{text "\<turnstile> A t"} & @{method cases} & @{text "\<dots>"} & inductive predicate/set elimination (of @{text A}) \\
|
26789
|
1696 |
@{text "\<dots>"} & @{method cases} & @{text "\<dots> rule: R"} & explicit rule @{text R} \\
|
26782
|
1697 |
\end{tabular}
|
|
1698 |
\medskip
|
|
1699 |
|
|
1700 |
Several instantiations may be given, referring to the \emph{suffix}
|
|
1701 |
of premises of the case rule; within each premise, the \emph{prefix}
|
|
1702 |
of variables is instantiated. In most situations, only a single
|
|
1703 |
term needs to be specified; this refers to the first variable of the
|
|
1704 |
last premise (it is usually the same for all cases).
|
|
1705 |
|
|
1706 |
\item [@{method induct}~@{text "insts R"}] is analogous to the
|
|
1707 |
@{method cases} method, but refers to induction rules, which are
|
|
1708 |
determined as follows:
|
|
1709 |
|
|
1710 |
\medskip
|
|
1711 |
\begin{tabular}{llll}
|
26789
|
1712 |
facts & & arguments & rule \\\hline
|
|
1713 |
& @{method induct} & @{text "P x"} & datatype induction (type of @{text x}) \\
|
|
1714 |
@{text "\<turnstile> A x"} & @{method induct} & @{text "\<dots>"} & predicate/set induction (of @{text A}) \\
|
|
1715 |
@{text "\<dots>"} & @{method induct} & @{text "\<dots> rule: R"} & explicit rule @{text R} \\
|
26782
|
1716 |
\end{tabular}
|
|
1717 |
\medskip
|
|
1718 |
|
|
1719 |
Several instantiations may be given, each referring to some part of
|
|
1720 |
a mutual inductive definition or datatype --- only related partial
|
|
1721 |
induction rules may be used together, though. Any of the lists of
|
|
1722 |
terms @{text "P, x, \<dots>"} refers to the \emph{suffix} of variables
|
|
1723 |
present in the induction rule. This enables the writer to specify
|
|
1724 |
only induction variables, or both predicates and variables, for
|
|
1725 |
example.
|
|
1726 |
|
|
1727 |
Instantiations may be definitional: equations @{text "x \<equiv> t"}
|
|
1728 |
introduce local definitions, which are inserted into the claim and
|
|
1729 |
discharged after applying the induction rule. Equalities reappear
|
|
1730 |
in the inductive cases, but have been transformed according to the
|
|
1731 |
induction principle being involved here. In order to achieve
|
|
1732 |
practically useful induction hypotheses, some variables occurring in
|
|
1733 |
@{text t} need to be fixed (see below).
|
|
1734 |
|
|
1735 |
The optional ``@{text "arbitrary: x\<^sub>1 \<dots> x\<^sub>m"}''
|
|
1736 |
specification generalizes variables @{text "x\<^sub>1, \<dots>,
|
|
1737 |
x\<^sub>m"} of the original goal before applying induction. Thus
|
|
1738 |
induction hypotheses may become sufficiently general to get the
|
|
1739 |
proof through. Together with definitional instantiations, one may
|
|
1740 |
effectively perform induction over expressions of a certain
|
|
1741 |
structure.
|
|
1742 |
|
|
1743 |
The optional ``@{text "taking: t\<^sub>1 \<dots> t\<^sub>n"}''
|
|
1744 |
specification provides additional instantiations of a prefix of
|
|
1745 |
pending variables in the rule. Such schematic induction rules
|
|
1746 |
rarely occur in practice, though.
|
|
1747 |
|
|
1748 |
\item [@{method coinduct}~@{text "inst R"}] is analogous to the
|
|
1749 |
@{method induct} method, but refers to coinduction rules, which are
|
|
1750 |
determined as follows:
|
|
1751 |
|
|
1752 |
\medskip
|
|
1753 |
\begin{tabular}{llll}
|
26789
|
1754 |
goal & & arguments & rule \\\hline
|
|
1755 |
& @{method coinduct} & @{text x} & type coinduction (type of @{text x}) \\
|
26782
|
1756 |
@{text "A x"} & @{method coinduct} & @{text "\<dots>"} & predicate/set coinduction (of @{text A}) \\
|
26789
|
1757 |
@{text "\<dots>"} & @{method coinduct} & @{text "\<dots> rule: R"} & explicit rule @{text R} \\
|
26782
|
1758 |
\end{tabular}
|
|
1759 |
|
|
1760 |
Coinduction is the dual of induction. Induction essentially
|
|
1761 |
eliminates @{text "A x"} towards a generic result @{text "P x"},
|
|
1762 |
while coinduction introduces @{text "A x"} starting with @{text "B
|
|
1763 |
x"}, for a suitable ``bisimulation'' @{text B}. The cases of a
|
|
1764 |
coinduct rule are typically named after the predicates or sets being
|
|
1765 |
covered, while the conclusions consist of several alternatives being
|
|
1766 |
named after the individual destructor patterns.
|
|
1767 |
|
|
1768 |
The given instantiation refers to the \emph{suffix} of variables
|
|
1769 |
occurring in the rule's major premise, or conclusion if unavailable.
|
|
1770 |
An additional ``@{text "taking: t\<^sub>1 \<dots> t\<^sub>n"}''
|
|
1771 |
specification may be required in order to specify the bisimulation
|
|
1772 |
to be used in the coinduction step.
|
|
1773 |
|
|
1774 |
\end{descr}
|
|
1775 |
|
|
1776 |
Above methods produce named local contexts, as determined by the
|
|
1777 |
instantiated rule as given in the text. Beyond that, the @{method
|
|
1778 |
induct} and @{method coinduct} methods guess further instantiations
|
|
1779 |
from the goal specification itself. Any persisting unresolved
|
|
1780 |
schematic variables of the resulting rule will render the the
|
|
1781 |
corresponding case invalid. The term binding @{variable ?case} for
|
|
1782 |
the conclusion will be provided with each case, provided that term
|
|
1783 |
is fully specified.
|
|
1784 |
|
|
1785 |
The @{command "print_cases"} command prints all named cases present
|
|
1786 |
in the current proof state.
|
|
1787 |
|
|
1788 |
\medskip Despite the additional infrastructure, both @{method cases}
|
|
1789 |
and @{method coinduct} merely apply a certain rule, after
|
|
1790 |
instantiation, while conforming due to the usual way of monotonic
|
|
1791 |
natural deduction: the context of a structured statement @{text
|
|
1792 |
"\<And>x\<^sub>1 \<dots> x\<^sub>m. \<phi>\<^sub>1 \<Longrightarrow> \<dots> \<phi>\<^sub>n \<Longrightarrow> \<dots>"}
|
|
1793 |
reappears unchanged after the case split.
|
|
1794 |
|
|
1795 |
The @{method induct} method is fundamentally different in this
|
|
1796 |
respect: the meta-level structure is passed through the
|
|
1797 |
``recursive'' course involved in the induction. Thus the original
|
|
1798 |
statement is basically replaced by separate copies, corresponding to
|
|
1799 |
the induction hypotheses and conclusion; the original goal context
|
|
1800 |
is no longer available. Thus local assumptions, fixed parameters
|
|
1801 |
and definitions effectively participate in the inductive rephrasing
|
|
1802 |
of the original statement.
|
|
1803 |
|
|
1804 |
In induction proofs, local assumptions introduced by cases are split
|
|
1805 |
into two different kinds: @{text hyps} stemming from the rule and
|
|
1806 |
@{text prems} from the goal statement. This is reflected in the
|
|
1807 |
extracted cases accordingly, so invoking ``@{command "case"}~@{text
|
|
1808 |
c}'' will provide separate facts @{text c.hyps} and @{text c.prems},
|
|
1809 |
as well as fact @{text c} to hold the all-inclusive list.
|
|
1810 |
|
|
1811 |
\medskip Facts presented to either method are consumed according to
|
|
1812 |
the number of ``major premises'' of the rule involved, which is
|
|
1813 |
usually 0 for plain cases and induction rules of datatypes etc.\ and
|
|
1814 |
1 for rules of inductive predicates or sets and the like. The
|
|
1815 |
remaining facts are inserted into the goal verbatim before the
|
|
1816 |
actual @{text cases}, @{text induct}, or @{text coinduct} rule is
|
|
1817 |
applied.
|
|
1818 |
*}
|
|
1819 |
|
|
1820 |
|
|
1821 |
subsubsection {* Declaring rules *}
|
|
1822 |
|
|
1823 |
text {*
|
|
1824 |
\begin{matharray}{rcl}
|
|
1825 |
@{command_def "print_induct_rules"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
|
|
1826 |
@{attribute_def cases} & : & \isaratt \\
|
|
1827 |
@{attribute_def induct} & : & \isaratt \\
|
|
1828 |
@{attribute_def coinduct} & : & \isaratt \\
|
|
1829 |
\end{matharray}
|
|
1830 |
|
|
1831 |
\begin{rail}
|
|
1832 |
'cases' spec
|
|
1833 |
;
|
|
1834 |
'induct' spec
|
|
1835 |
;
|
|
1836 |
'coinduct' spec
|
|
1837 |
;
|
|
1838 |
|
|
1839 |
spec: ('type' | 'pred' | 'set') ':' nameref
|
|
1840 |
;
|
|
1841 |
\end{rail}
|
|
1842 |
|
|
1843 |
\begin{descr}
|
|
1844 |
|
|
1845 |
\item [@{command "print_induct_rules"}] prints cases and induct
|
|
1846 |
rules for predicates (or sets) and types of the current context.
|
|
1847 |
|
|
1848 |
\item [@{attribute cases}, @{attribute induct}, and @{attribute
|
|
1849 |
coinduct}] (as attributes) augment the corresponding context of
|
|
1850 |
rules for reasoning about (co)inductive predicates (or sets) and
|
|
1851 |
types, using the corresponding methods of the same name. Certain
|
|
1852 |
definitional packages of object-logics usually declare emerging
|
|
1853 |
cases and induction rules as expected, so users rarely need to
|
|
1854 |
intervene.
|
|
1855 |
|
|
1856 |
Manual rule declarations usually refer to the @{attribute
|
|
1857 |
case_names} and @{attribute params} attributes to adjust names of
|
|
1858 |
cases and parameters of a rule; the @{attribute consumes}
|
|
1859 |
declaration is taken care of automatically: @{attribute
|
|
1860 |
consumes}~@{text 0} is specified for ``type'' rules and @{attribute
|
|
1861 |
consumes}~@{text 1} for ``predicate'' / ``set'' rules.
|
|
1862 |
|
|
1863 |
\end{descr}
|
|
1864 |
*}
|
|
1865 |
|
26790
|
1866 |
|
|
1867 |
section {* General logic setup \label{sec:object-logic} *}
|
|
1868 |
|
|
1869 |
text {*
|
|
1870 |
\begin{matharray}{rcl}
|
|
1871 |
@{command_def "judgment"} & : & \isartrans{theory}{theory} \\
|
|
1872 |
@{method_def atomize} & : & \isarmeth \\
|
|
1873 |
@{attribute_def atomize} & : & \isaratt \\
|
|
1874 |
@{attribute_def rule_format} & : & \isaratt \\
|
|
1875 |
@{attribute_def rulify} & : & \isaratt \\
|
|
1876 |
\end{matharray}
|
|
1877 |
|
|
1878 |
The very starting point for any Isabelle object-logic is a ``truth
|
|
1879 |
judgment'' that links object-level statements to the meta-logic
|
|
1880 |
(with its minimal language of @{text prop} that covers universal
|
|
1881 |
quantification @{text "\<And>"} and implication @{text "\<Longrightarrow>"}).
|
|
1882 |
|
|
1883 |
Common object-logics are sufficiently expressive to internalize rule
|
|
1884 |
statements over @{text "\<And>"} and @{text "\<Longrightarrow>"} within their own
|
|
1885 |
language. This is useful in certain situations where a rule needs
|
|
1886 |
to be viewed as an atomic statement from the meta-level perspective,
|
|
1887 |
e.g.\ @{text "\<And>x. x \<in> A \<Longrightarrow> P x"} versus @{text "\<forall>x \<in> A. P x"}.
|
|
1888 |
|
|
1889 |
From the following language elements, only the @{method atomize}
|
|
1890 |
method and @{attribute rule_format} attribute are occasionally
|
|
1891 |
required by end-users, the rest is for those who need to setup their
|
|
1892 |
own object-logic. In the latter case existing formulations of
|
|
1893 |
Isabelle/FOL or Isabelle/HOL may be taken as realistic examples.
|
|
1894 |
|
|
1895 |
Generic tools may refer to the information provided by object-logic
|
|
1896 |
declarations internally.
|
|
1897 |
|
|
1898 |
\begin{rail}
|
|
1899 |
'judgment' constdecl
|
|
1900 |
;
|
|
1901 |
'atomize' ('(' 'full' ')')?
|
|
1902 |
;
|
|
1903 |
'rule\_format' ('(' 'noasm' ')')?
|
|
1904 |
;
|
|
1905 |
\end{rail}
|
|
1906 |
|
|
1907 |
\begin{descr}
|
|
1908 |
|
|
1909 |
\item [@{command "judgment"}~@{text "c :: \<sigma> (mx)"}] declares
|
|
1910 |
constant @{text c} as the truth judgment of the current
|
|
1911 |
object-logic. Its type @{text \<sigma>} should specify a coercion of the
|
|
1912 |
category of object-level propositions to @{text prop} of the Pure
|
|
1913 |
meta-logic; the mixfix annotation @{text "(mx)"} would typically
|
|
1914 |
just link the object language (internally of syntactic category
|
|
1915 |
@{text logic}) with that of @{text prop}. Only one @{command
|
|
1916 |
"judgment"} declaration may be given in any theory development.
|
|
1917 |
|
|
1918 |
\item [@{method atomize} (as a method)] rewrites any non-atomic
|
|
1919 |
premises of a sub-goal, using the meta-level equations declared via
|
|
1920 |
@{attribute atomize} (as an attribute) beforehand. As a result,
|
|
1921 |
heavily nested goals become amenable to fundamental operations such
|
|
1922 |
as resolution (cf.\ the @{method rule} method). Giving the ``@{text
|
|
1923 |
"(full)"}'' option here means to turn the whole subgoal into an
|
|
1924 |
object-statement (if possible), including the outermost parameters
|
|
1925 |
and assumptions as well.
|
|
1926 |
|
|
1927 |
A typical collection of @{attribute atomize} rules for a particular
|
|
1928 |
object-logic would provide an internalization for each of the
|
|
1929 |
connectives of @{text "\<And>"}, @{text "\<Longrightarrow>"}, and @{text "\<equiv>"}.
|
|
1930 |
Meta-level conjunction should be covered as well (this is
|
|
1931 |
particularly important for locales, see \secref{sec:locale}).
|
|
1932 |
|
|
1933 |
\item [@{attribute rule_format}] rewrites a theorem by the
|
|
1934 |
equalities declared as @{attribute rulify} rules in the current
|
|
1935 |
object-logic. By default, the result is fully normalized, including
|
|
1936 |
assumptions and conclusions at any depth. The @{text "(no_asm)"}
|
|
1937 |
option restricts the transformation to the conclusion of a rule.
|
|
1938 |
|
|
1939 |
In common object-logics (HOL, FOL, ZF), the effect of @{attribute
|
|
1940 |
rule_format} is to replace (bounded) universal quantification
|
|
1941 |
(@{text "\<forall>"}) and implication (@{text "\<longrightarrow>"}) by the corresponding
|
|
1942 |
rule statements over @{text "\<And>"} and @{text "\<Longrightarrow>"}.
|
|
1943 |
|
|
1944 |
\end{descr}
|
|
1945 |
*}
|
|
1946 |
|
26782
|
1947 |
end
|