author | wenzelm |
Wed, 25 May 2011 22:21:38 +0200 | |
changeset 42908 | eb94cfaaf5d4 |
parent 42907 | dfd4ef8e73f6 |
child 42909 | 66b189dc5b83 |
permissions | -rw-r--r-- |
26840 | 1 |
theory HOL_Specific |
42651 | 2 |
imports Base Main |
26840 | 3 |
begin |
4 |
||
26852 | 5 |
chapter {* Isabelle/HOL \label{ch:hol} *} |
26849 | 6 |
|
42908 | 7 |
section {* Inductive and coinductive definitions \label{sec:hol-inductive} *} |
8 |
||
9 |
text {* |
|
10 |
An \textbf{inductive definition} specifies the least predicate (or |
|
11 |
set) @{text R} closed under given rules: applying a rule to elements |
|
12 |
of @{text R} yields a result within @{text R}. For example, a |
|
13 |
structural operational semantics is an inductive definition of an |
|
14 |
evaluation relation. |
|
15 |
||
16 |
Dually, a \textbf{coinductive definition} specifies the greatest |
|
17 |
predicate~/ set @{text R} that is consistent with given rules: every |
|
18 |
element of @{text R} can be seen as arising by applying a rule to |
|
19 |
elements of @{text R}. An important example is using bisimulation |
|
20 |
relations to formalise equivalence of processes and infinite data |
|
21 |
structures. |
|
26849 | 22 |
|
42908 | 23 |
\medskip The HOL package is related to the ZF one, which is |
24 |
described in a separate paper,\footnote{It appeared in CADE |
|
25 |
\cite{paulson-CADE}; a longer version is distributed with Isabelle.} |
|
26 |
which you should refer to in case of difficulties. The package is |
|
27 |
simpler than that of ZF thanks to implicit type-checking in HOL. |
|
28 |
The types of the (co)inductive predicates (or sets) determine the |
|
29 |
domain of the fixedpoint definition, and the package does not have |
|
30 |
to use inference rules for type-checking. |
|
42907
dfd4ef8e73f6
updated and re-unified HOL typedef, with some live examples;
wenzelm
parents:
42705
diff
changeset
|
31 |
|
26849 | 32 |
\begin{matharray}{rcl} |
42908 | 33 |
@{command_def (HOL) "inductive"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
34 |
@{command_def (HOL) "inductive_set"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
35 |
@{command_def (HOL) "coinductive"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
36 |
@{command_def (HOL) "coinductive_set"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
37 |
@{attribute_def (HOL) mono} & : & @{text attribute} \\ |
|
26849 | 38 |
\end{matharray} |
39 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
40 |
@{rail " |
42908 | 41 |
(@@{command (HOL) inductive} | @@{command (HOL) inductive_set} | |
42 |
@@{command (HOL) coinductive} | @@{command (HOL) coinductive_set}) |
|
43 |
@{syntax target}? @{syntax \"fixes\"} (@'for' @{syntax \"fixes\"})? \\ |
|
44 |
(@'where' clauses)? (@'monos' @{syntax thmrefs})? |
|
45 |
; |
|
46 |
clauses: (@{syntax thmdecl}? @{syntax prop} + '|') |
|
47 |
; |
|
48 |
@@{attribute (HOL) mono} (() | 'add' | 'del') |
|
49 |
"} |
|
50 |
||
51 |
\begin{description} |
|
52 |
||
53 |
\item @{command (HOL) "inductive"} and @{command (HOL) |
|
54 |
"coinductive"} define (co)inductive predicates from the |
|
55 |
introduction rules given in the @{keyword "where"} part. The |
|
56 |
optional @{keyword "for"} part contains a list of parameters of the |
|
57 |
(co)inductive predicates that remain fixed throughout the |
|
58 |
definition. The optional @{keyword "monos"} section contains |
|
59 |
\emph{monotonicity theorems}, which are required for each operator |
|
60 |
applied to a recursive set in the introduction rules. There |
|
61 |
\emph{must} be a theorem of the form @{text "A \<le> B \<Longrightarrow> M A \<le> M B"}, |
|
62 |
for each premise @{text "M R\<^sub>i t"} in an introduction rule! |
|
63 |
||
64 |
\item @{command (HOL) "inductive_set"} and @{command (HOL) |
|
65 |
"coinductive_set"} are wrappers for to the previous commands, |
|
66 |
allowing the definition of (co)inductive sets. |
|
67 |
||
68 |
\item @{attribute (HOL) mono} declares monotonicity rules. These |
|
69 |
rule are involved in the automated monotonicity proof of @{command |
|
70 |
(HOL) "inductive"}. |
|
71 |
||
72 |
\end{description} |
|
73 |
*} |
|
74 |
||
75 |
||
76 |
subsection {* Derived rules *} |
|
77 |
||
78 |
text {* |
|
79 |
Each (co)inductive definition @{text R} adds definitions to the |
|
80 |
theory and also proves some theorems: |
|
81 |
||
82 |
\begin{description} |
|
83 |
||
84 |
\item @{text R.intros} is the list of introduction rules as proven |
|
85 |
theorems, for the recursive predicates (or sets). The rules are |
|
86 |
also available individually, using the names given them in the |
|
87 |
theory file; |
|
88 |
||
89 |
\item @{text R.cases} is the case analysis (or elimination) rule; |
|
90 |
||
91 |
\item @{text R.induct} or @{text R.coinduct} is the (co)induction |
|
92 |
rule. |
|
93 |
||
94 |
\end{description} |
|
95 |
||
96 |
When several predicates @{text "R\<^sub>1, \<dots>, R\<^sub>n"} are |
|
97 |
defined simultaneously, the list of introduction rules is called |
|
98 |
@{text "R\<^sub>1_\<dots>_R\<^sub>n.intros"}, the case analysis rules are |
|
99 |
called @{text "R\<^sub>1.cases, \<dots>, R\<^sub>n.cases"}, and the list |
|
100 |
of mutual induction rules is called @{text |
|
101 |
"R\<^sub>1_\<dots>_R\<^sub>n.inducts"}. |
|
102 |
*} |
|
103 |
||
104 |
||
105 |
subsection {* Monotonicity theorems *} |
|
106 |
||
107 |
text {* |
|
108 |
Each theory contains a default set of theorems that are used in |
|
109 |
monotonicity proofs. New rules can be added to this set via the |
|
110 |
@{attribute (HOL) mono} attribute. The HOL theory @{text Inductive} |
|
111 |
shows how this is done. In general, the following monotonicity |
|
112 |
theorems may be added: |
|
113 |
||
114 |
\begin{itemize} |
|
115 |
||
116 |
\item Theorems of the form @{text "A \<le> B \<Longrightarrow> M A \<le> M B"}, for proving |
|
117 |
monotonicity of inductive definitions whose introduction rules have |
|
118 |
premises involving terms such as @{text "M R\<^sub>i t"}. |
|
119 |
||
120 |
\item Monotonicity theorems for logical operators, which are of the |
|
121 |
general form @{text "(\<dots> \<longrightarrow> \<dots>) \<Longrightarrow> \<dots> (\<dots> \<longrightarrow> \<dots>) \<Longrightarrow> \<dots> \<longrightarrow> \<dots>"}. For example, in |
|
122 |
the case of the operator @{text "\<or>"}, the corresponding theorem is |
|
123 |
\[ |
|
124 |
\infer{@{text "P\<^sub>1 \<or> P\<^sub>2 \<longrightarrow> Q\<^sub>1 \<or> Q\<^sub>2"}}{@{text "P\<^sub>1 \<longrightarrow> Q\<^sub>1"} & @{text "P\<^sub>2 \<longrightarrow> Q\<^sub>2"}} |
|
125 |
\] |
|
126 |
||
127 |
\item De Morgan style equations for reasoning about the ``polarity'' |
|
128 |
of expressions, e.g. |
|
129 |
\[ |
|
130 |
@{prop "\<not> \<not> P \<longleftrightarrow> P"} \qquad\qquad |
|
131 |
@{prop "\<not> (P \<and> Q) \<longleftrightarrow> \<not> P \<or> \<not> Q"} |
|
132 |
\] |
|
133 |
||
134 |
\item Equations for reducing complex operators to more primitive |
|
135 |
ones whose monotonicity can easily be proved, e.g. |
|
136 |
\[ |
|
137 |
@{prop "(P \<longrightarrow> Q) \<longleftrightarrow> \<not> P \<or> Q"} \qquad\qquad |
|
138 |
@{prop "Ball A P \<equiv> \<forall>x. x \<in> A \<longrightarrow> P x"} |
|
139 |
\] |
|
140 |
||
141 |
\end{itemize} |
|
142 |
||
143 |
%FIXME: Example of an inductive definition |
|
144 |
*} |
|
145 |
||
146 |
||
147 |
section {* Recursive functions \label{sec:recursion} *} |
|
148 |
||
149 |
text {* |
|
150 |
\begin{matharray}{rcl} |
|
151 |
@{command_def (HOL) "primrec"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
152 |
@{command_def (HOL) "fun"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
153 |
@{command_def (HOL) "function"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\ |
|
154 |
@{command_def (HOL) "termination"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\ |
|
155 |
\end{matharray} |
|
156 |
||
157 |
@{rail " |
|
158 |
@@{command (HOL) primrec} @{syntax target}? @{syntax \"fixes\"} @'where' equations |
|
159 |
; |
|
160 |
(@@{command (HOL) fun} | @@{command (HOL) function}) @{syntax target}? functionopts? |
|
161 |
@{syntax \"fixes\"} \\ @'where' equations |
|
26849 | 162 |
; |
163 |
||
42908 | 164 |
equations: (@{syntax thmdecl}? @{syntax prop} + '|') |
26849 | 165 |
; |
42908 | 166 |
functionopts: '(' (('sequential' | 'domintros') + ',') ')' |
26849 | 167 |
; |
42908 | 168 |
@@{command (HOL) termination} @{syntax term}? |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
169 |
"} |
26849 | 170 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
171 |
\begin{description} |
42123 | 172 |
|
42908 | 173 |
\item @{command (HOL) "primrec"} defines primitive recursive |
174 |
functions over datatypes, see also \cite{isabelle-HOL}. |
|
35744 | 175 |
|
42908 | 176 |
\item @{command (HOL) "function"} defines functions by general |
177 |
wellfounded recursion. A detailed description with examples can be |
|
178 |
found in \cite{isabelle-function}. The function is specified by a |
|
179 |
set of (possibly conditional) recursive equations with arbitrary |
|
180 |
pattern matching. The command generates proof obligations for the |
|
181 |
completeness and the compatibility of patterns. |
|
42907
dfd4ef8e73f6
updated and re-unified HOL typedef, with some live examples;
wenzelm
parents:
42705
diff
changeset
|
182 |
|
42908 | 183 |
The defined function is considered partial, and the resulting |
184 |
simplification rules (named @{text "f.psimps"}) and induction rule |
|
185 |
(named @{text "f.pinduct"}) are guarded by a generated domain |
|
186 |
predicate @{text "f_dom"}. The @{command (HOL) "termination"} |
|
187 |
command can then be used to establish that the function is total. |
|
42123 | 188 |
|
42908 | 189 |
\item @{command (HOL) "fun"} is a shorthand notation for ``@{command |
190 |
(HOL) "function"}~@{text "(sequential)"}, followed by automated |
|
191 |
proof attempts regarding pattern matching and termination. See |
|
192 |
\cite{isabelle-function} for further details. |
|
42123 | 193 |
|
42908 | 194 |
\item @{command (HOL) "termination"}~@{text f} commences a |
195 |
termination proof for the previously defined function @{text f}. If |
|
196 |
this is omitted, the command refers to the most recent function |
|
197 |
definition. After the proof is closed, the recursive equations and |
|
198 |
the induction principle is established. |
|
26849 | 199 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
200 |
\end{description} |
42907
dfd4ef8e73f6
updated and re-unified HOL typedef, with some live examples;
wenzelm
parents:
42705
diff
changeset
|
201 |
|
42908 | 202 |
Recursive definitions introduced by the @{command (HOL) "function"} |
203 |
command accommodate |
|
204 |
reasoning by induction (cf.\ \secref{sec:cases-induct}): rule @{text |
|
205 |
"c.induct"} (where @{text c} is the name of the function definition) |
|
206 |
refers to a specific induction rule, with parameters named according |
|
207 |
to the user-specified equations. Cases are numbered (starting from 1). |
|
208 |
||
209 |
For @{command (HOL) "primrec"}, the induction principle coincides |
|
210 |
with structural recursion on the datatype the recursion is carried |
|
211 |
out. |
|
212 |
||
213 |
The equations provided by these packages may be referred later as |
|
214 |
theorem list @{text "f.simps"}, where @{text f} is the (collective) |
|
215 |
name of the functions defined. Individual equations may be named |
|
216 |
explicitly as well. |
|
217 |
||
218 |
The @{command (HOL) "function"} command accepts the following |
|
219 |
options. |
|
220 |
||
221 |
\begin{description} |
|
222 |
||
223 |
\item @{text sequential} enables a preprocessor which disambiguates |
|
224 |
overlapping patterns by making them mutually disjoint. Earlier |
|
225 |
equations take precedence over later ones. This allows to give the |
|
226 |
specification in a format very similar to functional programming. |
|
227 |
Note that the resulting simplification and induction rules |
|
228 |
correspond to the transformed specification, not the one given |
|
229 |
originally. This usually means that each equation given by the user |
|
230 |
may result in several theorems. Also note that this automatic |
|
231 |
transformation only works for ML-style datatype patterns. |
|
232 |
||
233 |
\item @{text domintros} enables the automated generation of |
|
234 |
introduction rules for the domain predicate. While mostly not |
|
235 |
needed, they can be helpful in some proofs about partial functions. |
|
236 |
||
237 |
\end{description} |
|
26849 | 238 |
*} |
239 |
||
42907
dfd4ef8e73f6
updated and re-unified HOL typedef, with some live examples;
wenzelm
parents:
42705
diff
changeset
|
240 |
|
42908 | 241 |
subsection {* Proof methods related to recursive definitions *} |
26849 | 242 |
|
243 |
text {* |
|
244 |
\begin{matharray}{rcl} |
|
42908 | 245 |
@{method_def (HOL) pat_completeness} & : & @{text method} \\ |
246 |
@{method_def (HOL) relation} & : & @{text method} \\ |
|
247 |
@{method_def (HOL) lexicographic_order} & : & @{text method} \\ |
|
248 |
@{method_def (HOL) size_change} & : & @{text method} \\ |
|
26849 | 249 |
\end{matharray} |
250 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
251 |
@{rail " |
42908 | 252 |
@@{method (HOL) relation} @{syntax term} |
253 |
; |
|
254 |
@@{method (HOL) lexicographic_order} (@{syntax clasimpmod} * ) |
|
255 |
; |
|
256 |
@@{method (HOL) size_change} ( orders (@{syntax clasimpmod} * ) ) |
|
257 |
; |
|
258 |
orders: ( 'max' | 'min' | 'ms' ) * |
|
259 |
"} |
|
260 |
||
261 |
\begin{description} |
|
262 |
||
263 |
\item @{method (HOL) pat_completeness} is a specialized method to |
|
264 |
solve goals regarding the completeness of pattern matching, as |
|
265 |
required by the @{command (HOL) "function"} package (cf.\ |
|
266 |
\cite{isabelle-function}). |
|
267 |
||
268 |
\item @{method (HOL) relation}~@{text R} introduces a termination |
|
269 |
proof using the relation @{text R}. The resulting proof state will |
|
270 |
contain goals expressing that @{text R} is wellfounded, and that the |
|
271 |
arguments of recursive calls decrease with respect to @{text R}. |
|
272 |
Usually, this method is used as the initial proof step of manual |
|
273 |
termination proofs. |
|
274 |
||
275 |
\item @{method (HOL) "lexicographic_order"} attempts a fully |
|
276 |
automated termination proof by searching for a lexicographic |
|
277 |
combination of size measures on the arguments of the function. The |
|
278 |
method accepts the same arguments as the @{method auto} method, |
|
279 |
which it uses internally to prove local descents. The same context |
|
280 |
modifiers as for @{method auto} are accepted, see |
|
281 |
\secref{sec:clasimp}. |
|
282 |
||
283 |
In case of failure, extensive information is printed, which can help |
|
284 |
to analyse the situation (cf.\ \cite{isabelle-function}). |
|
285 |
||
286 |
\item @{method (HOL) "size_change"} also works on termination goals, |
|
287 |
using a variation of the size-change principle, together with a |
|
288 |
graph decomposition technique (see \cite{krauss_phd} for details). |
|
289 |
Three kinds of orders are used internally: @{text max}, @{text min}, |
|
290 |
and @{text ms} (multiset), which is only available when the theory |
|
291 |
@{text Multiset} is loaded. When no order kinds are given, they are |
|
292 |
tried in order. The search for a termination proof uses SAT solving |
|
293 |
internally. |
|
294 |
||
295 |
For local descent proofs, the same context modifiers as for @{method |
|
296 |
auto} are accepted, see \secref{sec:clasimp}. |
|
297 |
||
298 |
\end{description} |
|
299 |
*} |
|
300 |
||
301 |
||
302 |
subsection {* Functions with explicit partiality *} |
|
303 |
||
304 |
text {* |
|
305 |
\begin{matharray}{rcl} |
|
306 |
@{command_def (HOL) "partial_function"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
307 |
@{attribute_def (HOL) "partial_function_mono"} & : & @{text attribute} \\ |
|
308 |
\end{matharray} |
|
309 |
||
310 |
@{rail " |
|
311 |
@@{command (HOL) partial_function} @{syntax target}? |
|
312 |
'(' @{syntax nameref} ')' @{syntax \"fixes\"} \\ |
|
313 |
@'where' @{syntax thmdecl}? @{syntax prop} |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
314 |
"} |
26849 | 315 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
316 |
\begin{description} |
42123 | 317 |
|
42908 | 318 |
\item @{command (HOL) "partial_function"}~@{text "(mode)"} defines |
319 |
recursive functions based on fixpoints in complete partial |
|
320 |
orders. No termination proof is required from the user or |
|
321 |
constructed internally. Instead, the possibility of non-termination |
|
322 |
is modelled explicitly in the result type, which contains an |
|
323 |
explicit bottom element. |
|
324 |
||
325 |
Pattern matching and mutual recursion are currently not supported. |
|
326 |
Thus, the specification consists of a single function described by a |
|
327 |
single recursive equation. |
|
328 |
||
329 |
There are no fixed syntactic restrictions on the body of the |
|
330 |
function, but the induced functional must be provably monotonic |
|
331 |
wrt.\ the underlying order. The monotonicitity proof is performed |
|
332 |
internally, and the definition is rejected when it fails. The proof |
|
333 |
can be influenced by declaring hints using the |
|
334 |
@{attribute (HOL) partial_function_mono} attribute. |
|
335 |
||
336 |
The mandatory @{text mode} argument specifies the mode of operation |
|
337 |
of the command, which directly corresponds to a complete partial |
|
338 |
order on the result type. By default, the following modes are |
|
339 |
defined: |
|
26849 | 340 |
|
42908 | 341 |
\begin{description} |
342 |
\item @{text option} defines functions that map into the @{type |
|
343 |
option} type. Here, the value @{term None} is used to model a |
|
344 |
non-terminating computation. Monotonicity requires that if @{term |
|
345 |
None} is returned by a recursive call, then the overall result |
|
346 |
must also be @{term None}. This is best achieved through the use of |
|
347 |
the monadic operator @{const "Option.bind"}. |
|
348 |
||
349 |
\item @{text tailrec} defines functions with an arbitrary result |
|
350 |
type and uses the slightly degenerated partial order where @{term |
|
351 |
"undefined"} is the bottom element. Now, monotonicity requires that |
|
352 |
if @{term undefined} is returned by a recursive call, then the |
|
353 |
overall result must also be @{term undefined}. In practice, this is |
|
354 |
only satisfied when each recursive call is a tail call, whose result |
|
355 |
is directly returned. Thus, this mode of operation allows the |
|
356 |
definition of arbitrary tail-recursive functions. |
|
357 |
\end{description} |
|
358 |
||
359 |
Experienced users may define new modes by instantiating the locale |
|
360 |
@{const "partial_function_definitions"} appropriately. |
|
361 |
||
362 |
\item @{attribute (HOL) partial_function_mono} declares rules for |
|
363 |
use in the internal monononicity proofs of partial function |
|
364 |
definitions. |
|
26849 | 365 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
366 |
\end{description} |
42908 | 367 |
|
368 |
*} |
|
369 |
||
370 |
||
371 |
subsection {* Old-style recursive function definitions (TFL) *} |
|
372 |
||
373 |
text {* |
|
374 |
The old TFL commands @{command (HOL) "recdef"} and @{command (HOL) |
|
375 |
"recdef_tc"} for defining recursive are mostly obsolete; @{command |
|
376 |
(HOL) "function"} or @{command (HOL) "fun"} should be used instead. |
|
377 |
||
378 |
\begin{matharray}{rcl} |
|
379 |
@{command_def (HOL) "recdef"} & : & @{text "theory \<rightarrow> theory)"} \\ |
|
380 |
@{command_def (HOL) "recdef_tc"}@{text "\<^sup>*"} & : & @{text "theory \<rightarrow> proof(prove)"} \\ |
|
381 |
\end{matharray} |
|
382 |
||
383 |
@{rail " |
|
384 |
@@{command (HOL) recdef} ('(' @'permissive' ')')? \\ |
|
385 |
@{syntax name} @{syntax term} (@{syntax prop} +) hints? |
|
386 |
; |
|
387 |
recdeftc @{syntax thmdecl}? tc |
|
388 |
; |
|
389 |
hints: '(' @'hints' ( recdefmod * ) ')' |
|
390 |
; |
|
391 |
recdefmod: (('recdef_simp' | 'recdef_cong' | 'recdef_wf') |
|
392 |
(() | 'add' | 'del') ':' @{syntax thmrefs}) | @{syntax clasimpmod} |
|
393 |
; |
|
394 |
tc: @{syntax nameref} ('(' @{syntax nat} ')')? |
|
395 |
"} |
|
396 |
||
397 |
\begin{description} |
|
398 |
||
399 |
\item @{command (HOL) "recdef"} defines general well-founded |
|
400 |
recursive functions (using the TFL package), see also |
|
401 |
\cite{isabelle-HOL}. The ``@{text "(permissive)"}'' option tells |
|
402 |
TFL to recover from failed proof attempts, returning unfinished |
|
403 |
results. The @{text recdef_simp}, @{text recdef_cong}, and @{text |
|
404 |
recdef_wf} hints refer to auxiliary rules to be used in the internal |
|
405 |
automated proof process of TFL. Additional @{syntax clasimpmod} |
|
406 |
declarations (cf.\ \secref{sec:clasimp}) may be given to tune the |
|
407 |
context of the Simplifier (cf.\ \secref{sec:simplifier}) and |
|
408 |
Classical reasoner (cf.\ \secref{sec:classical}). |
|
409 |
||
410 |
\item @{command (HOL) "recdef_tc"}~@{text "c (i)"} recommences the |
|
411 |
proof for leftover termination condition number @{text i} (default |
|
412 |
1) as generated by a @{command (HOL) "recdef"} definition of |
|
413 |
constant @{text c}. |
|
414 |
||
415 |
Note that in most cases, @{command (HOL) "recdef"} is able to finish |
|
416 |
its internal proofs without manual intervention. |
|
417 |
||
418 |
\end{description} |
|
419 |
||
420 |
\medskip Hints for @{command (HOL) "recdef"} may be also declared |
|
421 |
globally, using the following attributes. |
|
422 |
||
423 |
\begin{matharray}{rcl} |
|
424 |
@{attribute_def (HOL) recdef_simp} & : & @{text attribute} \\ |
|
425 |
@{attribute_def (HOL) recdef_cong} & : & @{text attribute} \\ |
|
426 |
@{attribute_def (HOL) recdef_wf} & : & @{text attribute} \\ |
|
427 |
\end{matharray} |
|
428 |
||
429 |
@{rail " |
|
430 |
(@@{attribute (HOL) recdef_simp} | @@{attribute (HOL) recdef_cong} | |
|
431 |
@@{attribute (HOL) recdef_wf}) (() | 'add' | 'del') |
|
432 |
"} |
|
433 |
*} |
|
434 |
||
435 |
||
436 |
section {* Datatypes \label{sec:hol-datatype} *} |
|
437 |
||
438 |
text {* |
|
439 |
\begin{matharray}{rcl} |
|
440 |
@{command_def (HOL) "datatype"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
441 |
@{command_def (HOL) "rep_datatype"} & : & @{text "theory \<rightarrow> proof(prove)"} \\ |
|
442 |
\end{matharray} |
|
443 |
||
444 |
@{rail " |
|
445 |
@@{command (HOL) datatype} (spec + @'and') |
|
446 |
; |
|
447 |
@@{command (HOL) rep_datatype} ('(' (@{syntax name} +) ')')? (@{syntax term} +) |
|
448 |
; |
|
449 |
||
450 |
spec: @{syntax parname}? @{syntax typespec} @{syntax mixfix}? '=' (cons + '|') |
|
451 |
; |
|
452 |
cons: @{syntax name} (@{syntax type} * ) @{syntax mixfix}? |
|
453 |
"} |
|
454 |
||
455 |
\begin{description} |
|
456 |
||
457 |
\item @{command (HOL) "datatype"} defines inductive datatypes in |
|
458 |
HOL. |
|
459 |
||
460 |
\item @{command (HOL) "rep_datatype"} represents existing types as |
|
461 |
inductive ones, generating the standard infrastructure of derived |
|
462 |
concepts (primitive recursion etc.). |
|
463 |
||
464 |
\end{description} |
|
465 |
||
466 |
The induction and exhaustion theorems generated provide case names |
|
467 |
according to the constructors involved, while parameters are named |
|
468 |
after the types (see also \secref{sec:cases-induct}). |
|
469 |
||
470 |
See \cite{isabelle-HOL} for more details on datatypes, but beware of |
|
471 |
the old-style theory syntax being used there! Apart from proper |
|
472 |
proof methods for case-analysis and induction, there are also |
|
473 |
emulations of ML tactics @{method (HOL) case_tac} and @{method (HOL) |
|
474 |
induct_tac} available, see \secref{sec:hol-induct-tac}; these admit |
|
475 |
to refer directly to the internal structure of subgoals (including |
|
476 |
internally bound parameters). |
|
26849 | 477 |
*} |
478 |
||
479 |
||
480 |
section {* Records \label{sec:hol-record} *} |
|
481 |
||
482 |
text {* |
|
483 |
In principle, records merely generalize the concept of tuples, where |
|
484 |
components may be addressed by labels instead of just position. The |
|
485 |
logical infrastructure of records in Isabelle/HOL is slightly more |
|
486 |
advanced, though, supporting truly extensible record schemes. This |
|
487 |
admits operations that are polymorphic with respect to record |
|
488 |
extension, yielding ``object-oriented'' effects like (single) |
|
489 |
inheritance. See also \cite{NaraschewskiW-TPHOLs98} for more |
|
490 |
details on object-oriented verification and record subtyping in HOL. |
|
491 |
*} |
|
492 |
||
493 |
||
494 |
subsection {* Basic concepts *} |
|
495 |
||
496 |
text {* |
|
497 |
Isabelle/HOL supports both \emph{fixed} and \emph{schematic} records |
|
498 |
at the level of terms and types. The notation is as follows: |
|
499 |
||
500 |
\begin{center} |
|
501 |
\begin{tabular}{l|l|l} |
|
502 |
& record terms & record types \\ \hline |
|
503 |
fixed & @{text "\<lparr>x = a, y = b\<rparr>"} & @{text "\<lparr>x :: A, y :: B\<rparr>"} \\ |
|
504 |
schematic & @{text "\<lparr>x = a, y = b, \<dots> = m\<rparr>"} & |
|
505 |
@{text "\<lparr>x :: A, y :: B, \<dots> :: M\<rparr>"} \\ |
|
506 |
\end{tabular} |
|
507 |
\end{center} |
|
508 |
||
509 |
\noindent The ASCII representation of @{text "\<lparr>x = a\<rparr>"} is @{text |
|
510 |
"(| x = a |)"}. |
|
511 |
||
512 |
A fixed record @{text "\<lparr>x = a, y = b\<rparr>"} has field @{text x} of value |
|
513 |
@{text a} and field @{text y} of value @{text b}. The corresponding |
|
514 |
type is @{text "\<lparr>x :: A, y :: B\<rparr>"}, assuming that @{text "a :: A"} |
|
515 |
and @{text "b :: B"}. |
|
516 |
||
517 |
A record scheme like @{text "\<lparr>x = a, y = b, \<dots> = m\<rparr>"} contains fields |
|
518 |
@{text x} and @{text y} as before, but also possibly further fields |
|
519 |
as indicated by the ``@{text "\<dots>"}'' notation (which is actually part |
|
520 |
of the syntax). The improper field ``@{text "\<dots>"}'' of a record |
|
521 |
scheme is called the \emph{more part}. Logically it is just a free |
|
522 |
variable, which is occasionally referred to as ``row variable'' in |
|
523 |
the literature. The more part of a record scheme may be |
|
524 |
instantiated by zero or more further components. For example, the |
|
525 |
previous scheme may get instantiated to @{text "\<lparr>x = a, y = b, z = |
|
26852 | 526 |
c, \<dots> = m'\<rparr>"}, where @{text m'} refers to a different more part. |
26849 | 527 |
Fixed records are special instances of record schemes, where |
528 |
``@{text "\<dots>"}'' is properly terminated by the @{text "() :: unit"} |
|
529 |
element. In fact, @{text "\<lparr>x = a, y = b\<rparr>"} is just an abbreviation |
|
530 |
for @{text "\<lparr>x = a, y = b, \<dots> = ()\<rparr>"}. |
|
42123 | 531 |
|
26849 | 532 |
\medskip Two key observations make extensible records in a simply |
533 |
typed language like HOL work out: |
|
534 |
||
535 |
\begin{enumerate} |
|
536 |
||
537 |
\item the more part is internalized, as a free term or type |
|
538 |
variable, |
|
539 |
||
26852 | 540 |
\item field names are externalized, they cannot be accessed within |
541 |
the logic as first-class values. |
|
26849 | 542 |
|
543 |
\end{enumerate} |
|
544 |
||
545 |
\medskip In Isabelle/HOL record types have to be defined explicitly, |
|
546 |
fixing their field names and types, and their (optional) parent |
|
547 |
record. Afterwards, records may be formed using above syntax, while |
|
548 |
obeying the canonical order of fields as given by their declaration. |
|
549 |
The record package provides several standard operations like |
|
550 |
selectors and updates. The common setup for various generic proof |
|
551 |
tools enable succinct reasoning patterns. See also the Isabelle/HOL |
|
552 |
tutorial \cite{isabelle-hol-book} for further instructions on using |
|
553 |
records in practice. |
|
554 |
*} |
|
555 |
||
556 |
||
557 |
subsection {* Record specifications *} |
|
558 |
||
559 |
text {* |
|
560 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
561 |
@{command_def (HOL) "record"} & : & @{text "theory \<rightarrow> theory"} \\ |
26849 | 562 |
\end{matharray} |
563 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
564 |
@{rail " |
42705 | 565 |
@@{command (HOL) record} @{syntax typespec_sorts} '=' \\ |
42704 | 566 |
(@{syntax type} '+')? (@{syntax constdecl} +) |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
567 |
"} |
26849 | 568 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
569 |
\begin{description} |
26849 | 570 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
571 |
\item @{command (HOL) "record"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m) t = \<tau> + c\<^sub>1 :: \<sigma>\<^sub>1 |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
572 |
\<dots> c\<^sub>n :: \<sigma>\<^sub>n"} defines extensible record type @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m) t"}, |
26849 | 573 |
derived from the optional parent record @{text "\<tau>"} by adding new |
574 |
field components @{text "c\<^sub>i :: \<sigma>\<^sub>i"} etc. |
|
575 |
||
576 |
The type variables of @{text "\<tau>"} and @{text "\<sigma>\<^sub>i"} need to be |
|
577 |
covered by the (distinct) parameters @{text "\<alpha>\<^sub>1, \<dots>, |
|
578 |
\<alpha>\<^sub>m"}. Type constructor @{text t} has to be new, while @{text |
|
579 |
\<tau>} needs to specify an instance of an existing record type. At |
|
580 |
least one new field @{text "c\<^sub>i"} has to be specified. |
|
581 |
Basically, field names need to belong to a unique record. This is |
|
582 |
not a real restriction in practice, since fields are qualified by |
|
583 |
the record name internally. |
|
584 |
||
585 |
The parent record specification @{text \<tau>} is optional; if omitted |
|
586 |
@{text t} becomes a root record. The hierarchy of all records |
|
587 |
declared within a theory context forms a forest structure, i.e.\ a |
|
588 |
set of trees starting with a root record each. There is no way to |
|
589 |
merge multiple parent records! |
|
590 |
||
591 |
For convenience, @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m) t"} is made a |
|
592 |
type abbreviation for the fixed record type @{text "\<lparr>c\<^sub>1 :: |
|
593 |
\<sigma>\<^sub>1, \<dots>, c\<^sub>n :: \<sigma>\<^sub>n\<rparr>"}, likewise is @{text |
|
594 |
"(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m, \<zeta>) t_scheme"} made an abbreviation for |
|
595 |
@{text "\<lparr>c\<^sub>1 :: \<sigma>\<^sub>1, \<dots>, c\<^sub>n :: \<sigma>\<^sub>n, \<dots> :: |
|
596 |
\<zeta>\<rparr>"}. |
|
597 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
598 |
\end{description} |
26849 | 599 |
*} |
600 |
||
601 |
||
602 |
subsection {* Record operations *} |
|
603 |
||
604 |
text {* |
|
605 |
Any record definition of the form presented above produces certain |
|
606 |
standard operations. Selectors and updates are provided for any |
|
607 |
field, including the improper one ``@{text more}''. There are also |
|
608 |
cumulative record constructor functions. To simplify the |
|
609 |
presentation below, we assume for now that @{text "(\<alpha>\<^sub>1, \<dots>, |
|
610 |
\<alpha>\<^sub>m) t"} is a root record with fields @{text "c\<^sub>1 :: |
|
611 |
\<sigma>\<^sub>1, \<dots>, c\<^sub>n :: \<sigma>\<^sub>n"}. |
|
612 |
||
613 |
\medskip \textbf{Selectors} and \textbf{updates} are available for |
|
614 |
any field (including ``@{text more}''): |
|
615 |
||
616 |
\begin{matharray}{lll} |
|
26852 | 617 |
@{text "c\<^sub>i"} & @{text "::"} & @{text "\<lparr>\<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> \<sigma>\<^sub>i"} \\ |
618 |
@{text "c\<^sub>i_update"} & @{text "::"} & @{text "\<sigma>\<^sub>i \<Rightarrow> \<lparr>\<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> \<lparr>\<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr>"} \\ |
|
26849 | 619 |
\end{matharray} |
620 |
||
621 |
There is special syntax for application of updates: @{text "r\<lparr>x := |
|
622 |
a\<rparr>"} abbreviates term @{text "x_update a r"}. Further notation for |
|
623 |
repeated updates is also available: @{text "r\<lparr>x := a\<rparr>\<lparr>y := b\<rparr>\<lparr>z := |
|
624 |
c\<rparr>"} may be written @{text "r\<lparr>x := a, y := b, z := c\<rparr>"}. Note that |
|
625 |
because of postfix notation the order of fields shown here is |
|
626 |
reverse than in the actual term. Since repeated updates are just |
|
627 |
function applications, fields may be freely permuted in @{text "\<lparr>x |
|
628 |
:= a, y := b, z := c\<rparr>"}, as far as logical equality is concerned. |
|
629 |
Thus commutativity of independent updates can be proven within the |
|
630 |
logic for any two fields, but not as a general theorem. |
|
631 |
||
632 |
\medskip The \textbf{make} operation provides a cumulative record |
|
633 |
constructor function: |
|
634 |
||
635 |
\begin{matharray}{lll} |
|
26852 | 636 |
@{text "t.make"} & @{text "::"} & @{text "\<sigma>\<^sub>1 \<Rightarrow> \<dots> \<sigma>\<^sub>n \<Rightarrow> \<lparr>\<^vec>c :: \<^vec>\<sigma>\<rparr>"} \\ |
26849 | 637 |
\end{matharray} |
638 |
||
639 |
\medskip We now reconsider the case of non-root records, which are |
|
640 |
derived of some parent. In general, the latter may depend on |
|
641 |
another parent as well, resulting in a list of \emph{ancestor |
|
642 |
records}. Appending the lists of fields of all ancestors results in |
|
643 |
a certain field prefix. The record package automatically takes care |
|
644 |
of this by lifting operations over this context of ancestor fields. |
|
645 |
Assuming that @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m) t"} has ancestor |
|
646 |
fields @{text "b\<^sub>1 :: \<rho>\<^sub>1, \<dots>, b\<^sub>k :: \<rho>\<^sub>k"}, |
|
647 |
the above record operations will get the following types: |
|
648 |
||
26852 | 649 |
\medskip |
650 |
\begin{tabular}{lll} |
|
651 |
@{text "c\<^sub>i"} & @{text "::"} & @{text "\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> \<sigma>\<^sub>i"} \\ |
|
42123 | 652 |
@{text "c\<^sub>i_update"} & @{text "::"} & @{text "\<sigma>\<^sub>i \<Rightarrow> |
26852 | 653 |
\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> |
654 |
\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr>"} \\ |
|
655 |
@{text "t.make"} & @{text "::"} & @{text "\<rho>\<^sub>1 \<Rightarrow> \<dots> \<rho>\<^sub>k \<Rightarrow> \<sigma>\<^sub>1 \<Rightarrow> \<dots> \<sigma>\<^sub>n \<Rightarrow> |
|
656 |
\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>\<rparr>"} \\ |
|
657 |
\end{tabular} |
|
658 |
\medskip |
|
26849 | 659 |
|
26852 | 660 |
\noindent Some further operations address the extension aspect of a |
26849 | 661 |
derived record scheme specifically: @{text "t.fields"} produces a |
662 |
record fragment consisting of exactly the new fields introduced here |
|
663 |
(the result may serve as a more part elsewhere); @{text "t.extend"} |
|
664 |
takes a fixed record and adds a given more part; @{text |
|
665 |
"t.truncate"} restricts a record scheme to a fixed record. |
|
666 |
||
26852 | 667 |
\medskip |
668 |
\begin{tabular}{lll} |
|
669 |
@{text "t.fields"} & @{text "::"} & @{text "\<sigma>\<^sub>1 \<Rightarrow> \<dots> \<sigma>\<^sub>n \<Rightarrow> \<lparr>\<^vec>c :: \<^vec>\<sigma>\<rparr>"} \\ |
|
670 |
@{text "t.extend"} & @{text "::"} & @{text "\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>\<rparr> \<Rightarrow> |
|
671 |
\<zeta> \<Rightarrow> \<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr>"} \\ |
|
672 |
@{text "t.truncate"} & @{text "::"} & @{text "\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> \<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>\<rparr>"} \\ |
|
673 |
\end{tabular} |
|
674 |
\medskip |
|
26849 | 675 |
|
676 |
\noindent Note that @{text "t.make"} and @{text "t.fields"} coincide |
|
677 |
for root records. |
|
678 |
*} |
|
679 |
||
680 |
||
681 |
subsection {* Derived rules and proof tools *} |
|
682 |
||
683 |
text {* |
|
684 |
The record package proves several results internally, declaring |
|
685 |
these facts to appropriate proof tools. This enables users to |
|
686 |
reason about record structures quite conveniently. Assume that |
|
687 |
@{text t} is a record type as specified above. |
|
688 |
||
689 |
\begin{enumerate} |
|
42123 | 690 |
|
26849 | 691 |
\item Standard conversions for selectors or updates applied to |
692 |
record constructor terms are made part of the default Simplifier |
|
693 |
context; thus proofs by reduction of basic operations merely require |
|
694 |
the @{method simp} method without further arguments. These rules |
|
695 |
are available as @{text "t.simps"}, too. |
|
42123 | 696 |
|
26849 | 697 |
\item Selectors applied to updated records are automatically reduced |
698 |
by an internal simplification procedure, which is also part of the |
|
699 |
standard Simplifier setup. |
|
700 |
||
701 |
\item Inject equations of a form analogous to @{prop "(x, y) = (x', |
|
702 |
y') \<equiv> x = x' \<and> y = y'"} are declared to the Simplifier and Classical |
|
703 |
Reasoner as @{attribute iff} rules. These rules are available as |
|
704 |
@{text "t.iffs"}. |
|
705 |
||
706 |
\item The introduction rule for record equality analogous to @{text |
|
707 |
"x r = x r' \<Longrightarrow> y r = y r' \<dots> \<Longrightarrow> r = r'"} is declared to the Simplifier, |
|
708 |
and as the basic rule context as ``@{attribute intro}@{text "?"}''. |
|
709 |
The rule is called @{text "t.equality"}. |
|
710 |
||
711 |
\item Representations of arbitrary record expressions as canonical |
|
712 |
constructor terms are provided both in @{method cases} and @{method |
|
713 |
induct} format (cf.\ the generic proof methods of the same name, |
|
714 |
\secref{sec:cases-induct}). Several variations are available, for |
|
715 |
fixed records, record schemes, more parts etc. |
|
42123 | 716 |
|
26849 | 717 |
The generic proof methods are sufficiently smart to pick the most |
718 |
sensible rule according to the type of the indicated record |
|
719 |
expression: users just need to apply something like ``@{text "(cases |
|
720 |
r)"}'' to a certain proof problem. |
|
721 |
||
722 |
\item The derived record operations @{text "t.make"}, @{text |
|
723 |
"t.fields"}, @{text "t.extend"}, @{text "t.truncate"} are \emph{not} |
|
724 |
treated automatically, but usually need to be expanded by hand, |
|
725 |
using the collective fact @{text "t.defs"}. |
|
726 |
||
727 |
\end{enumerate} |
|
728 |
*} |
|
729 |
||
730 |
||
42908 | 731 |
section {* Adhoc tuples *} |
26849 | 732 |
|
733 |
text {* |
|
734 |
\begin{matharray}{rcl} |
|
42908 | 735 |
@{attribute_def (HOL) split_format}@{text "\<^sup>*"} & : & @{text attribute} \\ |
26849 | 736 |
\end{matharray} |
737 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
738 |
@{rail " |
42908 | 739 |
@@{attribute (HOL) split_format} ('(' 'complete' ')')? |
740 |
"} |
|
741 |
||
742 |
\begin{description} |
|
743 |
||
744 |
\item @{attribute (HOL) split_format}\ @{text "(complete)"} causes |
|
745 |
arguments in function applications to be represented canonically |
|
746 |
according to their tuple type structure. |
|
747 |
||
748 |
Note that this operation tends to invent funny names for new local |
|
749 |
parameters introduced. |
|
750 |
||
751 |
\end{description} |
|
752 |
*} |
|
753 |
||
754 |
||
755 |
section {* Typedef axiomatization \label{sec:hol-typedef} *} |
|
756 |
||
757 |
text {* A Gordon/HOL-style type definition is a certain axiom scheme |
|
758 |
that identifies a new type with a subset of an existing type. More |
|
759 |
precisely, the new type is defined by exhibiting an existing type |
|
760 |
@{text \<tau>}, a set @{text "A :: \<tau> set"}, and a theorem that proves |
|
761 |
@{prop "\<exists>x. x \<in> A"}. Thus @{text A} is a non-empty subset of @{text |
|
762 |
\<tau>}, and the new type denotes this subset. New functions are |
|
763 |
postulated that establish an isomorphism between the new type and |
|
764 |
the subset. In general, the type @{text \<tau>} may involve type |
|
765 |
variables @{text "\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n"} which means that the type definition |
|
766 |
produces a type constructor @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"} depending on |
|
767 |
those type arguments. |
|
768 |
||
769 |
The axiomatization can be considered a ``definition'' in the sense |
|
770 |
of the particular set-theoretic interpretation of HOL |
|
771 |
\cite{pitts93}, where the universe of types is required to be |
|
772 |
downwards-closed wrt.\ arbitrary non-empty subsets. Thus genuinely |
|
773 |
new types introduced by @{command "typedef"} stay within the range |
|
774 |
of HOL models by construction. Note that @{command_ref |
|
775 |
type_synonym} from Isabelle/Pure merely introduces syntactic |
|
776 |
abbreviations, without any logical significance. |
|
777 |
||
778 |
\begin{matharray}{rcl} |
|
779 |
@{command_def (HOL) "typedef"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\ |
|
780 |
\end{matharray} |
|
781 |
||
782 |
@{rail " |
|
783 |
@@{command (HOL) typedef} alt_name? abs_type '=' rep_set |
|
26849 | 784 |
; |
785 |
||
42908 | 786 |
alt_name: '(' (@{syntax name} | @'open' | @'open' @{syntax name}) ')' |
26849 | 787 |
; |
42908 | 788 |
abs_type: @{syntax typespec_sorts} @{syntax mixfix}? |
789 |
; |
|
790 |
rep_set: @{syntax term} (@'morphisms' @{syntax name} @{syntax name})? |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
791 |
"} |
26849 | 792 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
793 |
\begin{description} |
26849 | 794 |
|
42908 | 795 |
\item @{command (HOL) "typedef"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t = A"} |
796 |
axiomatizes a type definition in the background theory of the |
|
797 |
current context, depending on a non-emptiness result of the set |
|
798 |
@{text A} that needs to be proven here. The set @{text A} may |
|
799 |
contain type variables @{text "\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n"} as specified on the LHS, |
|
800 |
but no term variables. |
|
801 |
||
802 |
Even though a local theory specification, the newly introduced type |
|
803 |
constructor cannot depend on parameters or assumptions of the |
|
804 |
context: this is structurally impossible in HOL. In contrast, the |
|
805 |
non-emptiness proof may use local assumptions in unusual situations, |
|
806 |
which could result in different interpretations in target contexts: |
|
807 |
the meaning of the bijection between the representing set @{text A} |
|
808 |
and the new type @{text t} may then change in different application |
|
809 |
contexts. |
|
810 |
||
811 |
By default, @{command (HOL) "typedef"} defines both a type |
|
812 |
constructor @{text t} for the new type, and a term constant @{text |
|
813 |
t} for the representing set within the old type. Use the ``@{text |
|
814 |
"(open)"}'' option to suppress a separate constant definition |
|
815 |
altogether. The injection from type to set is called @{text Rep_t}, |
|
816 |
its inverse @{text Abs_t}, unless explicit @{keyword (HOL) |
|
817 |
"morphisms"} specification provides alternative names. |
|
26849 | 818 |
|
42908 | 819 |
The core axiomatization uses the locale predicate @{const |
820 |
type_definition} as defined in Isabelle/HOL. Various basic |
|
821 |
consequences of that are instantiated accordingly, re-using the |
|
822 |
locale facts with names derived from the new type constructor. Thus |
|
823 |
the generic @{thm type_definition.Rep} is turned into the specific |
|
824 |
@{text "Rep_t"}, for example. |
|
825 |
||
826 |
Theorems @{thm type_definition.Rep}, @{thm |
|
827 |
type_definition.Rep_inverse}, and @{thm type_definition.Abs_inverse} |
|
828 |
provide the most basic characterization as a corresponding |
|
829 |
injection/surjection pair (in both directions). The derived rules |
|
830 |
@{thm type_definition.Rep_inject} and @{thm |
|
831 |
type_definition.Abs_inject} provide a more convenient version of |
|
832 |
injectivity, suitable for automated proof tools (e.g.\ in |
|
833 |
declarations involving @{attribute simp} or @{attribute iff}). |
|
834 |
Furthermore, the rules @{thm type_definition.Rep_cases}~/ @{thm |
|
835 |
type_definition.Rep_induct}, and @{thm type_definition.Abs_cases}~/ |
|
836 |
@{thm type_definition.Abs_induct} provide alternative views on |
|
837 |
surjectivity. These rules are already declared as set or type rules |
|
838 |
for the generic @{method cases} and @{method induct} methods, |
|
839 |
respectively. |
|
840 |
||
841 |
An alternative name for the set definition (and other derived |
|
842 |
entities) may be specified in parentheses; the default is to use |
|
843 |
@{text t} directly. |
|
26849 | 844 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
845 |
\end{description} |
26849 | 846 |
|
42908 | 847 |
\begin{warn} |
848 |
If you introduce a new type axiomatically, i.e.\ via @{command_ref |
|
849 |
typedecl} and @{command_ref axiomatization}, the minimum requirement |
|
850 |
is that it has a non-empty model, to avoid immediate collapse of the |
|
851 |
HOL logic. Moreover, one needs to demonstrate that the |
|
852 |
interpretation of such free-form axiomatizations can coexist with |
|
853 |
that of the regular @{command_def typedef} scheme, and any extension |
|
854 |
that other people might have introduced elsewhere (e.g.\ in HOLCF |
|
855 |
\cite{MuellerNvOS99}). |
|
856 |
\end{warn} |
|
857 |
*} |
|
858 |
||
859 |
subsubsection {* Examples *} |
|
860 |
||
861 |
text {* Type definitions permit the introduction of abstract data |
|
862 |
types in a safe way, namely by providing models based on already |
|
863 |
existing types. Given some abstract axiomatic description @{text P} |
|
864 |
of a type, this involves two steps: |
|
865 |
||
866 |
\begin{enumerate} |
|
867 |
||
868 |
\item Find an appropriate type @{text \<tau>} and subset @{text A} which |
|
869 |
has the desired properties @{text P}, and make a type definition |
|
870 |
based on this representation. |
|
871 |
||
872 |
\item Prove that @{text P} holds for @{text \<tau>} by lifting @{text P} |
|
873 |
from the representation. |
|
26849 | 874 |
|
42908 | 875 |
\end{enumerate} |
876 |
||
877 |
You can later forget about the representation and work solely in |
|
878 |
terms of the abstract properties @{text P}. |
|
879 |
||
880 |
\medskip The following trivial example pulls a three-element type |
|
881 |
into existence within the formal logical environment of HOL. *} |
|
882 |
||
883 |
typedef three = "{(True, True), (True, False), (False, True)}" |
|
884 |
by blast |
|
885 |
||
886 |
definition "One = Abs_three (True, True)" |
|
887 |
definition "Two = Abs_three (True, False)" |
|
888 |
definition "Three = Abs_three (False, True)" |
|
889 |
||
890 |
lemma three_distinct: "One \<noteq> Two" "One \<noteq> Three" "Two \<noteq> Three" |
|
891 |
by (simp_all add: One_def Two_def Three_def Abs_three_inject three_def) |
|
892 |
||
893 |
lemma three_cases: |
|
894 |
fixes x :: three obtains "x = One" | "x = Two" | "x = Three" |
|
895 |
by (cases x) (auto simp: One_def Two_def Three_def Abs_three_inject three_def) |
|
896 |
||
897 |
text {* Note that such trivial constructions are better done with |
|
898 |
derived specification mechanisms such as @{command datatype}: *} |
|
899 |
||
900 |
datatype three' = One' | Two' | Three' |
|
901 |
||
902 |
text {* This avoids re-doing basic definitions and proofs from the |
|
903 |
primitive @{command typedef} above. *} |
|
26849 | 904 |
|
905 |
||
41396 | 906 |
section {* Functorial structure of types *} |
907 |
||
908 |
text {* |
|
909 |
\begin{matharray}{rcl} |
|
41505
6d19301074cf
"enriched_type" replaces less specific "type_lifting"
haftmann
parents:
41396
diff
changeset
|
910 |
@{command_def (HOL) "enriched_type"} & : & @{text "local_theory \<rightarrow> proof(prove)"} |
41396 | 911 |
\end{matharray} |
912 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
913 |
@{rail " |
42617 | 914 |
@@{command (HOL) enriched_type} (@{syntax name} ':')? @{syntax term} |
41396 | 915 |
; |
42617 | 916 |
"} |
41396 | 917 |
|
918 |
\begin{description} |
|
919 |
||
42617 | 920 |
\item @{command (HOL) "enriched_type"}~@{text "prefix: m"} allows to |
921 |
prove and register properties about the functorial structure of type |
|
922 |
constructors. These properties then can be used by other packages |
|
923 |
to deal with those type constructors in certain type constructions. |
|
924 |
Characteristic theorems are noted in the current local theory. By |
|
925 |
default, they are prefixed with the base name of the type |
|
926 |
constructor, an explicit prefix can be given alternatively. |
|
41396 | 927 |
|
928 |
The given term @{text "m"} is considered as \emph{mapper} for the |
|
929 |
corresponding type constructor and must conform to the following |
|
930 |
type pattern: |
|
931 |
||
932 |
\begin{matharray}{lll} |
|
933 |
@{text "m"} & @{text "::"} & |
|
934 |
@{text "\<sigma>\<^isub>1 \<Rightarrow> \<dots> \<sigma>\<^isub>k \<Rightarrow> (\<^vec>\<alpha>\<^isub>n) t \<Rightarrow> (\<^vec>\<beta>\<^isub>n) t"} \\ |
|
935 |
\end{matharray} |
|
936 |
||
937 |
\noindent where @{text t} is the type constructor, @{text |
|
938 |
"\<^vec>\<alpha>\<^isub>n"} and @{text "\<^vec>\<beta>\<^isub>n"} are distinct |
|
939 |
type variables free in the local theory and @{text "\<sigma>\<^isub>1"}, |
|
940 |
\ldots, @{text "\<sigma>\<^isub>k"} is a subsequence of @{text "\<alpha>\<^isub>1 \<Rightarrow> |
|
941 |
\<beta>\<^isub>1"}, @{text "\<beta>\<^isub>1 \<Rightarrow> \<alpha>\<^isub>1"}, \ldots, |
|
942 |
@{text "\<alpha>\<^isub>n \<Rightarrow> \<beta>\<^isub>n"}, @{text "\<beta>\<^isub>n \<Rightarrow> |
|
943 |
\<alpha>\<^isub>n"}. |
|
944 |
||
945 |
\end{description} |
|
946 |
*} |
|
947 |
||
948 |
||
26849 | 949 |
section {* Arithmetic proof support *} |
950 |
||
951 |
text {* |
|
952 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
953 |
@{method_def (HOL) arith} & : & @{text method} \\ |
30863 | 954 |
@{attribute_def (HOL) arith} & : & @{text attribute} \\ |
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
955 |
@{attribute_def (HOL) arith_split} & : & @{text attribute} \\ |
26849 | 956 |
\end{matharray} |
957 |
||
958 |
The @{method (HOL) arith} method decides linear arithmetic problems |
|
959 |
(on types @{text nat}, @{text int}, @{text real}). Any current |
|
960 |
facts are inserted into the goal before running the procedure. |
|
961 |
||
30863 | 962 |
The @{attribute (HOL) arith} attribute declares facts that are |
963 |
always supplied to the arithmetic provers implicitly. |
|
26849 | 964 |
|
30863 | 965 |
The @{attribute (HOL) arith_split} attribute declares case split |
30865 | 966 |
rules to be expanded before @{method (HOL) arith} is invoked. |
30863 | 967 |
|
968 |
Note that a simpler (but faster) arithmetic prover is |
|
969 |
already invoked by the Simplifier. |
|
26849 | 970 |
*} |
971 |
||
972 |
||
30169 | 973 |
section {* Intuitionistic proof search *} |
974 |
||
975 |
text {* |
|
976 |
\begin{matharray}{rcl} |
|
30171 | 977 |
@{method_def (HOL) iprover} & : & @{text method} \\ |
30169 | 978 |
\end{matharray} |
979 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
980 |
@{rail " |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
981 |
@@{method (HOL) iprover} ( @{syntax rulemod} * ) |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
982 |
"} |
30169 | 983 |
|
30171 | 984 |
The @{method (HOL) iprover} method performs intuitionistic proof |
985 |
search, depending on specifically declared rules from the context, |
|
986 |
or given as explicit arguments. Chained facts are inserted into the |
|
35613 | 987 |
goal before commencing proof search. |
988 |
||
30169 | 989 |
Rules need to be classified as @{attribute (Pure) intro}, |
990 |
@{attribute (Pure) elim}, or @{attribute (Pure) dest}; here the |
|
991 |
``@{text "!"}'' indicator refers to ``safe'' rules, which may be |
|
992 |
applied aggressively (without considering back-tracking later). |
|
993 |
Rules declared with ``@{text "?"}'' are ignored in proof search (the |
|
42626 | 994 |
single-step @{method (Pure) rule} method still observes these). An |
30169 | 995 |
explicit weight annotation may be given as well; otherwise the |
996 |
number of rule premises will be taken into account here. |
|
997 |
*} |
|
998 |
||
999 |
||
30171 | 1000 |
section {* Coherent Logic *} |
1001 |
||
1002 |
text {* |
|
1003 |
\begin{matharray}{rcl} |
|
1004 |
@{method_def (HOL) "coherent"} & : & @{text method} \\ |
|
1005 |
\end{matharray} |
|
1006 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1007 |
@{rail " |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1008 |
@@{method (HOL) coherent} @{syntax thmrefs}? |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1009 |
"} |
30171 | 1010 |
|
1011 |
The @{method (HOL) coherent} method solves problems of |
|
1012 |
\emph{Coherent Logic} \cite{Bezem-Coquand:2005}, which covers |
|
1013 |
applications in confluence theory, lattice theory and projective |
|
40800
330eb65c9469
Parse.liberal_name for document antiquotations and attributes;
wenzelm
parents:
40711
diff
changeset
|
1014 |
geometry. See @{file "~~/src/HOL/ex/Coherent.thy"} for some |
30171 | 1015 |
examples. |
1016 |
*} |
|
1017 |
||
1018 |
||
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1019 |
section {* Proving propositions *} |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1020 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1021 |
text {* |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1022 |
In addition to the standard proof methods, a number of diagnosis |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1023 |
tools search for proofs and provide an Isar proof snippet on success. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1024 |
These tools are available via the following commands. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1025 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1026 |
\begin{matharray}{rcl} |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1027 |
@{command_def (HOL) "solve_direct"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\ |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1028 |
@{command_def (HOL) "try"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\ |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1029 |
@{command_def (HOL) "sledgehammer"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\ |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1030 |
@{command_def (HOL) "sledgehammer_params"} & : & @{text "theory \<rightarrow> theory"} |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1031 |
\end{matharray} |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1032 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1033 |
@{rail " |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1034 |
@@{command (HOL) try} ( ( ( 'simp' | 'intro' | 'elim' | 'dest' ) ':' @{syntax thmrefs} ) + ) ? |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1035 |
@{syntax nat}? |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1036 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1037 |
@@{command (HOL) sledgehammer} ( '[' args ']' )? facts? @{syntax nat}? |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1038 |
; |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1039 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1040 |
@@{command (HOL) sledgehammer_params} ( ( '[' args ']' ) ? ) |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1041 |
; |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1042 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1043 |
args: ( @{syntax name} '=' value + ',' ) |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1044 |
; |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1045 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1046 |
facts: '(' ( ( ( ( 'add' | 'del' ) ':' ) ? @{syntax thmrefs} ) + ) ? ')' |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1047 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1048 |
"} % FIXME try: proper clasimpmod!? |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1049 |
% FIXME check args "value" |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1050 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1051 |
\begin{description} |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1052 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1053 |
\item @{command (HOL) "solve_direct"} checks whether the current subgoals can |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1054 |
be solved directly by an existing theorem. Duplicate lemmas can be detected |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1055 |
in this way. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1056 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1057 |
\item @{command (HOL) "try"} attempts to prove a subgoal using a combination |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1058 |
of standard proof methods (@{text auto}, @{text simp}, @{text blast}, etc.). |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1059 |
Additional facts supplied via @{text "simp:"}, @{text "intro:"}, |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1060 |
@{text "elim:"}, and @{text "dest:"} are passed to the appropriate proof |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1061 |
methods. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1062 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1063 |
\item @{command (HOL) "sledgehammer"} attempts to prove a subgoal using external |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1064 |
automatic provers (resolution provers and SMT solvers). See the Sledgehammer |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1065 |
manual \cite{isabelle-sledgehammer} for details. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1066 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1067 |
\item @{command (HOL) "sledgehammer_params"} changes |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1068 |
@{command (HOL) "sledgehammer"} configuration options persistently. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1069 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1070 |
\end{description} |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1071 |
*} |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1072 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1073 |
|
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1074 |
section {* Checking and refuting propositions *} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1075 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1076 |
text {* |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1077 |
Identifying incorrect propositions usually involves evaluation of |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1078 |
particular assignments and systematic counterexample search. This |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1079 |
is supported by the following commands. |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1080 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1081 |
\begin{matharray}{rcl} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1082 |
@{command_def (HOL) "value"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1083 |
@{command_def (HOL) "quickcheck"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\ |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1084 |
@{command_def (HOL) "refute"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\ |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1085 |
@{command_def (HOL) "nitpick"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\ |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1086 |
@{command_def (HOL) "quickcheck_params"} & : & @{text "theory \<rightarrow> theory"} \\ |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1087 |
@{command_def (HOL) "refute_params"} & : & @{text "theory \<rightarrow> theory"} \\ |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1088 |
@{command_def (HOL) "nitpick_params"} & : & @{text "theory \<rightarrow> theory"} |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1089 |
\end{matharray} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1090 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1091 |
@{rail " |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1092 |
@@{command (HOL) value} ( '[' name ']' )? modes? @{syntax term} |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1093 |
; |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1094 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1095 |
(@@{command (HOL) quickcheck} | @@{command (HOL) refute} | @@{command (HOL) nitpick}) |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1096 |
( '[' args ']' )? @{syntax nat}? |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1097 |
; |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1098 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1099 |
(@@{command (HOL) quickcheck_params} | @@{command (HOL) refute_params} | |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1100 |
@@{command (HOL) nitpick_params}) ( '[' args ']' )? |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1101 |
; |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1102 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1103 |
modes: '(' (@{syntax name} +) ')' |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1104 |
; |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1105 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1106 |
args: ( @{syntax name} '=' value + ',' ) |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1107 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1108 |
"} % FIXME check "value" |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1109 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1110 |
\begin{description} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1111 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1112 |
\item @{command (HOL) "value"}~@{text t} evaluates and prints a |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1113 |
term; optionally @{text modes} can be specified, which are |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1114 |
appended to the current print mode (see also \cite{isabelle-ref}). |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1115 |
Internally, the evaluation is performed by registered evaluators, |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1116 |
which are invoked sequentially until a result is returned. |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1117 |
Alternatively a specific evaluator can be selected using square |
37444 | 1118 |
brackets; typical evaluators use the current set of code equations |
1119 |
to normalize and include @{text simp} for fully symbolic evaluation |
|
1120 |
using the simplifier, @{text nbe} for \emph{normalization by evaluation} |
|
1121 |
and \emph{code} for code generation in SML. |
|
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1122 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1123 |
\item @{command (HOL) "quickcheck"} tests the current goal for |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1124 |
counterexamples using a series of assignments for its |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1125 |
free variables; by default the first subgoal is tested, an other |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1126 |
can be selected explicitly using an optional goal index. |
40918
7351c6afb348
explaining quickcheck testers in the documentation
bulwahn
parents:
40800
diff
changeset
|
1127 |
Assignments can be chosen exhausting the search space upto a given |
7351c6afb348
explaining quickcheck testers in the documentation
bulwahn
parents:
40800
diff
changeset
|
1128 |
size or using a fixed number of random assignments in the search space. |
7351c6afb348
explaining quickcheck testers in the documentation
bulwahn
parents:
40800
diff
changeset
|
1129 |
By default, quickcheck uses exhaustive testing. |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1130 |
A number of configuration options are supported for |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1131 |
@{command (HOL) "quickcheck"}, notably: |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1132 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1133 |
\begin{description} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1134 |
|
40918
7351c6afb348
explaining quickcheck testers in the documentation
bulwahn
parents:
40800
diff
changeset
|
1135 |
\item[@{text tester}] specifies how to explore the search space |
7351c6afb348
explaining quickcheck testers in the documentation
bulwahn
parents:
40800
diff
changeset
|
1136 |
(e.g. exhaustive or random). |
7351c6afb348
explaining quickcheck testers in the documentation
bulwahn
parents:
40800
diff
changeset
|
1137 |
An unknown configuration option is treated as an argument to tester, |
7351c6afb348
explaining quickcheck testers in the documentation
bulwahn
parents:
40800
diff
changeset
|
1138 |
making @{text "tester ="} optional. |
40254 | 1139 |
\item[@{text size}] specifies the maximum size of the search space |
1140 |
for assignment values. |
|
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1141 |
|
42092
f07b373f25d3
adding documentation about the eval option in quickcheck
bulwahn
parents:
41846
diff
changeset
|
1142 |
\item[@{text eval}] takes a term or a list of terms and evaluates |
f07b373f25d3
adding documentation about the eval option in quickcheck
bulwahn
parents:
41846
diff
changeset
|
1143 |
these terms under the variable assignment found by quickcheck. |
42123 | 1144 |
|
40254 | 1145 |
\item[@{text iterations}] sets how many sets of assignments are |
1146 |
generated for each particular size. |
|
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1147 |
|
40254 | 1148 |
\item[@{text no_assms}] specifies whether assumptions in |
1149 |
structured proofs should be ignored. |
|
35331 | 1150 |
|
40254 | 1151 |
\item[@{text timeout}] sets the time limit in seconds. |
40245
59f011c1877a
updating documentation on quickcheck in the Isar reference
bulwahn
parents:
40171
diff
changeset
|
1152 |
|
40254 | 1153 |
\item[@{text default_type}] sets the type(s) generally used to |
1154 |
instantiate type variables. |
|
40245
59f011c1877a
updating documentation on quickcheck in the Isar reference
bulwahn
parents:
40171
diff
changeset
|
1155 |
|
40254 | 1156 |
\item[@{text report}] if set quickcheck reports how many tests |
1157 |
fulfilled the preconditions. |
|
40245
59f011c1877a
updating documentation on quickcheck in the Isar reference
bulwahn
parents:
40171
diff
changeset
|
1158 |
|
40254 | 1159 |
\item[@{text quiet}] if not set quickcheck informs about the |
1160 |
current size for assignment values. |
|
40245
59f011c1877a
updating documentation on quickcheck in the Isar reference
bulwahn
parents:
40171
diff
changeset
|
1161 |
|
40254 | 1162 |
\item[@{text expect}] can be used to check if the user's |
1163 |
expectation was met (@{text no_expectation}, @{text |
|
1164 |
no_counterexample}, or @{text counterexample}). |
|
40245
59f011c1877a
updating documentation on quickcheck in the Isar reference
bulwahn
parents:
40171
diff
changeset
|
1165 |
|
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1166 |
\end{description} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1167 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1168 |
These option can be given within square brackets. |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1169 |
|
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1170 |
\item @{command (HOL) "quickcheck_params"} changes |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1171 |
@{command (HOL) "quickcheck"} configuration options persistently. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1172 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1173 |
\item @{command (HOL) "refute"} tests the current goal for |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1174 |
counterexamples using a reduction to SAT. The following configuration |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1175 |
options are supported: |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1176 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1177 |
\begin{description} |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1178 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1179 |
\item[@{text minsize}] specifies the minimum size (cardinality) of the |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1180 |
models to search for. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1181 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1182 |
\item[@{text maxsize}] specifies the maximum size (cardinality) of the |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1183 |
models to search for. Nonpositive values mean $\infty$. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1184 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1185 |
\item[@{text maxvars}] specifies the maximum number of Boolean variables |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1186 |
to use when transforming the term into a propositional formula. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1187 |
Nonpositive values mean $\infty$. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1188 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1189 |
\item[@{text satsolver}] specifies the SAT solver to use. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1190 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1191 |
\item[@{text no_assms}] specifies whether assumptions in |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1192 |
structured proofs should be ignored. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1193 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1194 |
\item[@{text maxtime}] sets the time limit in seconds. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1195 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1196 |
\item[@{text expect}] can be used to check if the user's |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1197 |
expectation was met (@{text genuine}, @{text potential}, |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1198 |
@{text none}, or @{text unknown}). |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1199 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1200 |
\end{description} |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1201 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1202 |
These option can be given within square brackets. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1203 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1204 |
\item @{command (HOL) "refute_params"} changes |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1205 |
@{command (HOL) "refute"} configuration options persistently. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1206 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1207 |
\item @{command (HOL) "nitpick"} tests the current goal for counterexamples |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1208 |
using a reduction to first-order relational logic. See the Nitpick manual |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1209 |
\cite{isabelle-nitpick} for details. |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1210 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1211 |
\item @{command (HOL) "nitpick_params"} changes |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1212 |
@{command (HOL) "nitpick"} configuration options persistently. |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1213 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1214 |
\end{description} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1215 |
*} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1216 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1217 |
|
28752 | 1218 |
section {* Unstructured case analysis and induction \label{sec:hol-induct-tac} *} |
26849 | 1219 |
|
1220 |
text {* |
|
27123
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
1221 |
The following tools of Isabelle/HOL support cases analysis and |
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
1222 |
induction in unstructured tactic scripts; see also |
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
1223 |
\secref{sec:cases-induct} for proper Isar versions of similar ideas. |
26849 | 1224 |
|
1225 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1226 |
@{method_def (HOL) case_tac}@{text "\<^sup>*"} & : & @{text method} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1227 |
@{method_def (HOL) induct_tac}@{text "\<^sup>*"} & : & @{text method} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1228 |
@{method_def (HOL) ind_cases}@{text "\<^sup>*"} & : & @{text method} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1229 |
@{command_def (HOL) "inductive_cases"}@{text "\<^sup>*"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
26849 | 1230 |
\end{matharray} |
1231 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1232 |
@{rail " |
42705 | 1233 |
@@{method (HOL) case_tac} @{syntax goal_spec}? @{syntax term} rule? |
26849 | 1234 |
; |
42705 | 1235 |
@@{method (HOL) induct_tac} @{syntax goal_spec}? (@{syntax insts} * @'and') rule? |
26849 | 1236 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1237 |
@@{method (HOL) ind_cases} (@{syntax prop}+) (@'for' (@{syntax name}+))? |
26849 | 1238 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1239 |
@@{command (HOL) inductive_cases} (@{syntax thmdecl}? (@{syntax prop}+) + @'and') |
26849 | 1240 |
; |
1241 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1242 |
rule: 'rule' ':' @{syntax thmref} |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1243 |
"} |
26849 | 1244 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1245 |
\begin{description} |
26849 | 1246 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1247 |
\item @{method (HOL) case_tac} and @{method (HOL) induct_tac} admit |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1248 |
to reason about inductive types. Rules are selected according to |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1249 |
the declarations by the @{attribute cases} and @{attribute induct} |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1250 |
attributes, cf.\ \secref{sec:cases-induct}. The @{command (HOL) |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1251 |
datatype} package already takes care of this. |
27123
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
1252 |
|
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
1253 |
These unstructured tactics feature both goal addressing and dynamic |
26849 | 1254 |
instantiation. Note that named rule cases are \emph{not} provided |
27123
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
1255 |
as would be by the proper @{method cases} and @{method induct} proof |
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
1256 |
methods (see \secref{sec:cases-induct}). Unlike the @{method |
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
1257 |
induct} method, @{method induct_tac} does not handle structured rule |
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
1258 |
statements, only the compact object-logic conclusion of the subgoal |
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
1259 |
being addressed. |
42123 | 1260 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1261 |
\item @{method (HOL) ind_cases} and @{command (HOL) |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1262 |
"inductive_cases"} provide an interface to the internal @{ML_text |
26860 | 1263 |
mk_cases} operation. Rules are simplified in an unrestricted |
1264 |
forward manner. |
|
26849 | 1265 |
|
1266 |
While @{method (HOL) ind_cases} is a proof method to apply the |
|
1267 |
result immediately as elimination rules, @{command (HOL) |
|
1268 |
"inductive_cases"} provides case split theorems at the theory level |
|
1269 |
for later use. The @{keyword "for"} argument of the @{method (HOL) |
|
1270 |
ind_cases} method allows to specify a list of variables that should |
|
1271 |
be generalized before applying the resulting rule. |
|
1272 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1273 |
\end{description} |
26849 | 1274 |
*} |
1275 |
||
1276 |
||
1277 |
section {* Executable code *} |
|
1278 |
||
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1279 |
text {* For validation purposes, it is often useful to \emph{execute} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1280 |
specifications. In principle, execution could be simulated by |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1281 |
Isabelle's inference kernel, i.e. by a combination of resolution and |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1282 |
simplification. Unfortunately, this approach is rather inefficient. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1283 |
A more efficient way of executing specifications is to translate |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1284 |
them into a functional programming language such as ML. |
26849 | 1285 |
|
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1286 |
Isabelle provides two generic frameworks to support code generation |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1287 |
from executable specifications. Isabelle/HOL instantiates these |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1288 |
mechanisms in a way that is amenable to end-user applications. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1289 |
*} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1290 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1291 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1292 |
subsection {* The new code generator (F. Haftmann) *} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1293 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1294 |
text {* This framework generates code from functional programs |
37422 | 1295 |
(including overloading using type classes) to SML \cite{SML}, OCaml |
38814 | 1296 |
\cite{OCaml}, Haskell \cite{haskell-revised-report} and Scala |
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1297 |
\cite{scala-overview-tech-report}. Conceptually, code generation is |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1298 |
split up in three steps: \emph{selection} of code theorems, |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1299 |
\emph{translation} into an abstract executable view and |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1300 |
\emph{serialization} to a specific \emph{target language}. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1301 |
Inductive specifications can be executed using the predicate |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1302 |
compiler which operates within HOL. See \cite{isabelle-codegen} for |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1303 |
an introduction. |
37422 | 1304 |
|
1305 |
\begin{matharray}{rcl} |
|
1306 |
@{command_def (HOL) "export_code"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
1307 |
@{attribute_def (HOL) code} & : & @{text attribute} \\ |
|
1308 |
@{command_def (HOL) "code_abort"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1309 |
@{command_def (HOL) "code_datatype"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1310 |
@{command_def (HOL) "print_codesetup"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
1311 |
@{attribute_def (HOL) code_inline} & : & @{text attribute} \\ |
|
1312 |
@{attribute_def (HOL) code_post} & : & @{text attribute} \\ |
|
1313 |
@{command_def (HOL) "print_codeproc"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
1314 |
@{command_def (HOL) "code_thms"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
1315 |
@{command_def (HOL) "code_deps"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
1316 |
@{command_def (HOL) "code_const"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1317 |
@{command_def (HOL) "code_type"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1318 |
@{command_def (HOL) "code_class"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1319 |
@{command_def (HOL) "code_instance"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1320 |
@{command_def (HOL) "code_reserved"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1321 |
@{command_def (HOL) "code_monad"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1322 |
@{command_def (HOL) "code_include"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1323 |
@{command_def (HOL) "code_modulename"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
39608 | 1324 |
@{command_def (HOL) "code_reflect"} & : & @{text "theory \<rightarrow> theory"} |
37422 | 1325 |
\end{matharray} |
1326 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1327 |
@{rail " |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1328 |
@@{command (HOL) export_code} ( constexpr + ) \\ |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1329 |
( ( @'in' target ( @'module_name' @{syntax string} ) ? \\ |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1330 |
( @'file' ( @{syntax string} | '-' ) ) ? ( '(' args ')' ) ?) + ) ? |
37422 | 1331 |
; |
1332 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1333 |
const: @{syntax term} |
37422 | 1334 |
; |
1335 |
||
40711
81bc73585eec
globbing constant expressions use more idiomatic underscore rather than star
haftmann
parents:
40709
diff
changeset
|
1336 |
constexpr: ( const | 'name._' | '_' ) |
37422 | 1337 |
; |
1338 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1339 |
typeconstructor: @{syntax nameref} |
37422 | 1340 |
; |
1341 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1342 |
class: @{syntax nameref} |
37422 | 1343 |
; |
1344 |
||
38814 | 1345 |
target: 'SML' | 'OCaml' | 'Haskell' | 'Scala' |
37422 | 1346 |
; |
1347 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1348 |
@@{attribute (HOL) code} ( 'del' | 'abstype' | 'abstract' )? |
37422 | 1349 |
; |
1350 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1351 |
@@{command (HOL) code_abort} ( const + ) |
37422 | 1352 |
; |
1353 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1354 |
@@{command (HOL) code_datatype} ( const + ) |
37422 | 1355 |
; |
1356 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1357 |
@@{attribute (HOL) code_inline} ( 'del' ) ? |
37422 | 1358 |
; |
1359 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1360 |
@@{attribute (HOL) code_post} ( 'del' ) ? |
37422 | 1361 |
; |
1362 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1363 |
@@{command (HOL) code_thms} ( constexpr + ) ? |
37422 | 1364 |
; |
1365 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1366 |
@@{command (HOL) code_deps} ( constexpr + ) ? |
37422 | 1367 |
; |
1368 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1369 |
@@{command (HOL) code_const} (const + @'and') \\ |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1370 |
( ( '(' target ( syntax ? + @'and' ) ')' ) + ) |
37422 | 1371 |
; |
1372 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1373 |
@@{command (HOL) code_type} (typeconstructor + @'and') \\ |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1374 |
( ( '(' target ( syntax ? + @'and' ) ')' ) + ) |
37422 | 1375 |
; |
1376 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1377 |
@@{command (HOL) code_class} (class + @'and') \\ |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1378 |
( ( '(' target \\ ( @{syntax string} ? + @'and' ) ')' ) + ) |
37422 | 1379 |
; |
1380 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1381 |
@@{command (HOL) code_instance} (( typeconstructor '::' class ) + @'and') \\ |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1382 |
( ( '(' target ( '-' ? + @'and' ) ')' ) + ) |
37422 | 1383 |
; |
1384 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1385 |
@@{command (HOL) code_reserved} target ( @{syntax string} + ) |
37422 | 1386 |
; |
1387 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1388 |
@@{command (HOL) code_monad} const const target |
37422 | 1389 |
; |
1390 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1391 |
@@{command (HOL) code_include} target ( @{syntax string} ( @{syntax string} | '-') ) |
37422 | 1392 |
; |
1393 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1394 |
@@{command (HOL) code_modulename} target ( ( @{syntax string} @{syntax string} ) + ) |
39608 | 1395 |
; |
1396 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1397 |
@@{command (HOL) code_reflect} @{syntax string} \\ |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1398 |
( @'datatypes' ( @{syntax string} '=' ( '_' | ( @{syntax string} + '|' ) + @'and' ) ) ) ? \\ |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1399 |
( @'functions' ( @{syntax string} + ) ) ? ( @'file' @{syntax string} ) ? |
37422 | 1400 |
; |
1401 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1402 |
syntax: @{syntax string} | ( @'infix' | @'infixl' | @'infixr' ) @{syntax nat} @{syntax string} |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1403 |
"} |
37422 | 1404 |
|
1405 |
\begin{description} |
|
1406 |
||
1407 |
\item @{command (HOL) "export_code"} generates code for a given list |
|
39608 | 1408 |
of constants in the specified target language(s). If no |
1409 |
serialization instruction is given, only abstract code is generated |
|
1410 |
internally. |
|
37422 | 1411 |
|
1412 |
Constants may be specified by giving them literally, referring to |
|
1413 |
all executable contants within a certain theory by giving @{text |
|
1414 |
"name.*"}, or referring to \emph{all} executable constants currently |
|
1415 |
available by giving @{text "*"}. |
|
1416 |
||
1417 |
By default, for each involved theory one corresponding name space |
|
1418 |
module is generated. Alternativly, a module name may be specified |
|
1419 |
after the @{keyword "module_name"} keyword; then \emph{all} code is |
|
1420 |
placed in this module. |
|
1421 |
||
39608 | 1422 |
For \emph{SML}, \emph{OCaml} and \emph{Scala} the file specification |
1423 |
refers to a single file; for \emph{Haskell}, it refers to a whole |
|
1424 |
directory, where code is generated in multiple files reflecting the |
|
1425 |
module hierarchy. Omitting the file specification denotes standard |
|
37749 | 1426 |
output. |
37422 | 1427 |
|
1428 |
Serializers take an optional list of arguments in parentheses. For |
|
1429 |
\emph{SML} and \emph{OCaml}, ``@{text no_signatures}`` omits |
|
1430 |
explicit module signatures. |
|
42123 | 1431 |
|
39608 | 1432 |
For \emph{Haskell} a module name prefix may be given using the |
1433 |
``@{text "root:"}'' argument; ``@{text string_classes}'' adds a |
|
1434 |
``@{verbatim "deriving (Read, Show)"}'' clause to each appropriate |
|
1435 |
datatype declaration. |
|
37422 | 1436 |
|
1437 |
\item @{attribute (HOL) code} explicitly selects (or with option |
|
38462
34d3de1254cd
formally document `code abstype` and `code abstract` attributes
haftmann
parents:
37820
diff
changeset
|
1438 |
``@{text "del"}'' deselects) a code equation for code generation. |
34d3de1254cd
formally document `code abstype` and `code abstract` attributes
haftmann
parents:
37820
diff
changeset
|
1439 |
Usually packages introducing code equations provide a reasonable |
34d3de1254cd
formally document `code abstype` and `code abstract` attributes
haftmann
parents:
37820
diff
changeset
|
1440 |
default setup for selection. Variants @{text "code abstype"} and |
34d3de1254cd
formally document `code abstype` and `code abstract` attributes
haftmann
parents:
37820
diff
changeset
|
1441 |
@{text "code abstract"} declare abstract datatype certificates or |
34d3de1254cd
formally document `code abstype` and `code abstract` attributes
haftmann
parents:
37820
diff
changeset
|
1442 |
code equations on abstract datatype representations respectively. |
37422 | 1443 |
|
1444 |
\item @{command (HOL) "code_abort"} declares constants which are not |
|
39608 | 1445 |
required to have a definition by means of code equations; if needed |
1446 |
these are implemented by program abort instead. |
|
37422 | 1447 |
|
1448 |
\item @{command (HOL) "code_datatype"} specifies a constructor set |
|
1449 |
for a logical type. |
|
1450 |
||
1451 |
\item @{command (HOL) "print_codesetup"} gives an overview on |
|
1452 |
selected code equations and code generator datatypes. |
|
1453 |
||
39608 | 1454 |
\item @{attribute (HOL) code_inline} declares (or with option |
1455 |
``@{text "del"}'' removes) inlining theorems which are applied as |
|
1456 |
rewrite rules to any code equation during preprocessing. |
|
37422 | 1457 |
|
39608 | 1458 |
\item @{attribute (HOL) code_post} declares (or with option ``@{text |
1459 |
"del"}'' removes) theorems which are applied as rewrite rules to any |
|
1460 |
result of an evaluation. |
|
37422 | 1461 |
|
39608 | 1462 |
\item @{command (HOL) "print_codeproc"} prints the setup of the code |
1463 |
generator preprocessor. |
|
37422 | 1464 |
|
1465 |
\item @{command (HOL) "code_thms"} prints a list of theorems |
|
1466 |
representing the corresponding program containing all given |
|
1467 |
constants after preprocessing. |
|
1468 |
||
1469 |
\item @{command (HOL) "code_deps"} visualizes dependencies of |
|
1470 |
theorems representing the corresponding program containing all given |
|
1471 |
constants after preprocessing. |
|
1472 |
||
1473 |
\item @{command (HOL) "code_const"} associates a list of constants |
|
1474 |
with target-specific serializations; omitting a serialization |
|
1475 |
deletes an existing serialization. |
|
1476 |
||
1477 |
\item @{command (HOL) "code_type"} associates a list of type |
|
1478 |
constructors with target-specific serializations; omitting a |
|
1479 |
serialization deletes an existing serialization. |
|
1480 |
||
1481 |
\item @{command (HOL) "code_class"} associates a list of classes |
|
1482 |
with target-specific class names; omitting a serialization deletes |
|
1483 |
an existing serialization. This applies only to \emph{Haskell}. |
|
1484 |
||
1485 |
\item @{command (HOL) "code_instance"} declares a list of type |
|
1486 |
constructor / class instance relations as ``already present'' for a |
|
1487 |
given target. Omitting a ``@{text "-"}'' deletes an existing |
|
1488 |
``already present'' declaration. This applies only to |
|
1489 |
\emph{Haskell}. |
|
1490 |
||
1491 |
\item @{command (HOL) "code_reserved"} declares a list of names as |
|
1492 |
reserved for a given target, preventing it to be shadowed by any |
|
1493 |
generated code. |
|
1494 |
||
1495 |
\item @{command (HOL) "code_monad"} provides an auxiliary mechanism |
|
1496 |
to generate monadic code for Haskell. |
|
1497 |
||
1498 |
\item @{command (HOL) "code_include"} adds arbitrary named content |
|
1499 |
(``include'') to generated code. A ``@{text "-"}'' as last argument |
|
1500 |
will remove an already added ``include''. |
|
1501 |
||
1502 |
\item @{command (HOL) "code_modulename"} declares aliasings from one |
|
1503 |
module name onto another. |
|
1504 |
||
39608 | 1505 |
\item @{command (HOL) "code_reflect"} without a ``@{text "file"}'' |
1506 |
argument compiles code into the system runtime environment and |
|
1507 |
modifies the code generator setup that future invocations of system |
|
1508 |
runtime code generation referring to one of the ``@{text |
|
1509 |
"datatypes"}'' or ``@{text "functions"}'' entities use these precompiled |
|
1510 |
entities. With a ``@{text "file"}'' argument, the corresponding code |
|
1511 |
is generated into that specified file without modifying the code |
|
1512 |
generator setup. |
|
1513 |
||
37422 | 1514 |
\end{description} |
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1515 |
*} |
37422 | 1516 |
|
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1517 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1518 |
subsection {* The old code generator (S. Berghofer) *} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1519 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1520 |
text {* This framework generates code from both functional and |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1521 |
relational programs to SML, as explained below. |
26849 | 1522 |
|
1523 |
\begin{matharray}{rcl} |
|
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1524 |
@{command_def "code_module"} & : & @{text "theory \<rightarrow> theory"} \\ |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1525 |
@{command_def "code_library"} & : & @{text "theory \<rightarrow> theory"} \\ |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1526 |
@{command_def "consts_code"} & : & @{text "theory \<rightarrow> theory"} \\ |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1527 |
@{command_def "types_code"} & : & @{text "theory \<rightarrow> theory"} \\ |
42626 | 1528 |
@{attribute_def code} & : & @{text attribute} \\ |
26849 | 1529 |
\end{matharray} |
1530 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1531 |
@{rail " |
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1532 |
( @@{command code_module} | @@{command code_library} ) modespec? @{syntax name}? \\ |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1533 |
( @'file' name ) ? ( @'imports' ( @{syntax name} + ) ) ? \\ |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1534 |
@'contains' ( ( @{syntax name} '=' @{syntax term} ) + | @{syntax term} + ) |
26849 | 1535 |
; |
1536 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1537 |
modespec: '(' ( @{syntax name} * ) ')' |
26849 | 1538 |
; |
1539 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1540 |
@@{command (HOL) consts_code} (codespec +) |
26849 | 1541 |
; |
1542 |
||
1543 |
codespec: const template attachment ? |
|
1544 |
; |
|
1545 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1546 |
@@{command (HOL) types_code} (tycodespec +) |
26849 | 1547 |
; |
1548 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1549 |
tycodespec: @{syntax name} template attachment ? |
26849 | 1550 |
; |
1551 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1552 |
const: @{syntax term} |
26849 | 1553 |
; |
1554 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1555 |
template: '(' @{syntax string} ')' |
26849 | 1556 |
; |
1557 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1558 |
attachment: 'attach' modespec? '{' @{syntax text} '}' |
26849 | 1559 |
; |
1560 |
||
42626 | 1561 |
@@{attribute code} name? |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1562 |
"} |
26849 | 1563 |
*} |
1564 |
||
27045 | 1565 |
|
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1566 |
subsubsection {* Invoking the code generator *} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1567 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1568 |
text {* The code generator is invoked via the @{command code_module} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1569 |
and @{command code_library} commands, which correspond to |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1570 |
\emph{incremental} and \emph{modular} code generation, respectively. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1571 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1572 |
\begin{description} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1573 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1574 |
\item [Modular] For each theory, an ML structure is generated, |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1575 |
containing the code generated from the constants defined in this |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1576 |
theory. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1577 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1578 |
\item [Incremental] All the generated code is emitted into the same |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1579 |
structure. This structure may import code from previously generated |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1580 |
structures, which can be specified via @{keyword "imports"}. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1581 |
Moreover, the generated structure may also be referred to in later |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1582 |
invocations of the code generator. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1583 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1584 |
\end{description} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1585 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1586 |
After the @{command code_module} and @{command code_library} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1587 |
keywords, the user may specify an optional list of ``modes'' in |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1588 |
parentheses. These can be used to instruct the code generator to |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1589 |
emit additional code for special purposes, e.g.\ functions for |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1590 |
converting elements of generated datatypes to Isabelle terms, or |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1591 |
test data generators. The list of modes is followed by a module |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1592 |
name. The module name is optional for modular code generation, but |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1593 |
must be specified for incremental code generation. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1594 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1595 |
The code can either be written to a file, in which case a file name |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1596 |
has to be specified after the @{keyword "file"} keyword, or be loaded |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1597 |
directly into Isabelle's ML environment. In the latter case, the |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1598 |
@{command ML} theory command can be used to inspect the results |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1599 |
interactively, for example. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1600 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1601 |
The terms from which to generate code can be specified after the |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1602 |
@{keyword "contains"} keyword, either as a list of bindings, or just |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1603 |
as a list of terms. In the latter case, the code generator just |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1604 |
produces code for all constants and types occuring in the term, but |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1605 |
does not bind the compiled terms to ML identifiers. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1606 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1607 |
Here is an example: |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1608 |
*} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1609 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1610 |
code_module Test |
42652 | 1611 |
contains test = "foldl op + (0 :: int) [1, 2, 3, 4, 5]" |
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1612 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1613 |
text {* \noindent This binds the result of compiling the given term to |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1614 |
the ML identifier @{ML Test.test}. *} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1615 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1616 |
ML {* @{assert} (Test.test = 15) *} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1617 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1618 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1619 |
subsubsection {* Configuring the code generator *} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1620 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1621 |
text {* When generating code for a complex term, the code generator |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1622 |
recursively calls itself for all subterms. When it arrives at a |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1623 |
constant, the default strategy of the code generator is to look up |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1624 |
its definition and try to generate code for it. Constants which |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1625 |
have no definitions that are immediately executable, may be |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1626 |
associated with a piece of ML code manually using the @{command_ref |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1627 |
consts_code} command. It takes a list whose elements consist of a |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1628 |
constant (given in usual term syntax -- an explicit type constraint |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1629 |
accounts for overloading), and a mixfix template describing the ML |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1630 |
code. The latter is very much the same as the mixfix templates used |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1631 |
when declaring new constants. The most notable difference is that |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1632 |
terms may be included in the ML template using antiquotation |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1633 |
brackets @{verbatim "{"}@{verbatim "*"}~@{text "..."}~@{verbatim |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1634 |
"*"}@{verbatim "}"}. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1635 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1636 |
A similar mechanism is available for types: @{command_ref |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1637 |
types_code} associates type constructors with specific ML code. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1638 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1639 |
For example, the following declarations copied from @{file |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1640 |
"~~/src/HOL/Product_Type.thy"} describe how the product type of |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1641 |
Isabelle/HOL should be compiled to ML. *} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1642 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1643 |
typedecl ('a, 'b) prod |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1644 |
consts Pair :: "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b) prod" |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1645 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1646 |
types_code prod ("(_ */ _)") |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1647 |
consts_code Pair ("(_,/ _)") |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1648 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1649 |
text {* Sometimes, the code associated with a constant or type may |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1650 |
need to refer to auxiliary functions, which have to be emitted when |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1651 |
the constant is used. Code for such auxiliary functions can be |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1652 |
declared using @{keyword "attach"}. For example, the @{const wfrec} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1653 |
function can be implemented as follows: |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1654 |
*} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1655 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1656 |
consts_code wfrec ("\<module>wfrec?") (* FIXME !? *) |
42652 | 1657 |
attach {* fun wfrec f x = f (wfrec f) x *} |
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1658 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1659 |
text {* If the code containing a call to @{const wfrec} resides in an |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1660 |
ML structure different from the one containing the function |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1661 |
definition attached to @{const wfrec}, the name of the ML structure |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1662 |
(followed by a ``@{text "."}'') is inserted in place of ``@{text |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1663 |
"\<module>"}'' in the above template. The ``@{text "?"}'' means that |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1664 |
the code generator should ignore the first argument of @{const |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1665 |
wfrec}, i.e.\ the termination relation, which is usually not |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1666 |
executable. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1667 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1668 |
\medskip Another possibility of configuring the code generator is to |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1669 |
register theorems to be used for code generation. Theorems can be |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1670 |
registered via the @{attribute code} attribute. It takes an optional |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1671 |
name as an argument, which indicates the format of the |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1672 |
theorem. Currently supported formats are equations (this is the |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1673 |
default when no name is specified) and horn clauses (this is |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1674 |
indicated by the name \texttt{ind}). The left-hand sides of |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1675 |
equations may only contain constructors and distinct variables, |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1676 |
whereas horn clauses must have the same format as introduction rules |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1677 |
of inductive definitions. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1678 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1679 |
The following example specifies three equations from which to |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1680 |
generate code for @{term "op <"} on natural numbers (see also |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1681 |
@{"file" "~~/src/HOL/Nat.thy"}). *} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1682 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1683 |
lemma [code]: "(Suc m < Suc n) = (m < n)" |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1684 |
and [code]: "((n::nat) < 0) = False" |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1685 |
and [code]: "(0 < Suc n) = True" by simp_all |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1686 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1687 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1688 |
subsubsection {* Specific HOL code generators *} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1689 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1690 |
text {* The basic code generator framework offered by Isabelle/Pure |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1691 |
has already been extended with additional code generators for |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1692 |
specific HOL constructs. These include datatypes, recursive |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1693 |
functions and inductive relations. The code generator for inductive |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1694 |
relations can handle expressions of the form @{text "(t\<^sub>1, \<dots>, t\<^sub>n) \<in> |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1695 |
r"}, where @{text "r"} is an inductively defined relation. If at |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1696 |
least one of the @{text "t\<^sub>i"} is a dummy pattern ``@{text "_"}'', |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1697 |
the above expression evaluates to a sequence of possible answers. If |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1698 |
all of the @{text "t\<^sub>i"} are proper terms, the expression evaluates |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1699 |
to a boolean value. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1700 |
|
42652 | 1701 |
The following example demonstrates this for beta-reduction on lambda |
1702 |
terms (see also @{"file" "~~/src/HOL/Proofs/Lambda/Lambda.thy"}). |
|
1703 |
*} |
|
1704 |
||
1705 |
datatype dB = |
|
1706 |
Var nat |
|
1707 |
| App dB dB (infixl "\<degree>" 200) |
|
1708 |
| Abs dB |
|
1709 |
||
1710 |
primrec lift :: "dB \<Rightarrow> nat \<Rightarrow> dB" |
|
1711 |
where |
|
1712 |
"lift (Var i) k = (if i < k then Var i else Var (i + 1))" |
|
1713 |
| "lift (s \<degree> t) k = lift s k \<degree> lift t k" |
|
1714 |
| "lift (Abs s) k = Abs (lift s (k + 1))" |
|
1715 |
||
1716 |
primrec subst :: "dB \<Rightarrow> dB \<Rightarrow> nat \<Rightarrow> dB" ("_[_'/_]" [300, 0, 0] 300) |
|
1717 |
where |
|
1718 |
"(Var i)[s/k] = |
|
1719 |
(if k < i then Var (i - 1) else if i = k then s else Var i)" |
|
1720 |
| "(t \<degree> u)[s/k] = t[s/k] \<degree> u[s/k]" |
|
1721 |
| "(Abs t)[s/k] = Abs (t[lift s 0 / k+1])" |
|
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1722 |
|
42652 | 1723 |
inductive beta :: "dB \<Rightarrow> dB \<Rightarrow> bool" (infixl "\<rightarrow>\<^sub>\<beta>" 50) |
1724 |
where |
|
1725 |
beta: "Abs s \<degree> t \<rightarrow>\<^sub>\<beta> s[t/0]" |
|
1726 |
| appL: "s \<rightarrow>\<^sub>\<beta> t \<Longrightarrow> s \<degree> u \<rightarrow>\<^sub>\<beta> t \<degree> u" |
|
1727 |
| appR: "s \<rightarrow>\<^sub>\<beta> t \<Longrightarrow> u \<degree> s \<rightarrow>\<^sub>\<beta> u \<degree> t" |
|
1728 |
| abs: "s \<rightarrow>\<^sub>\<beta> t \<Longrightarrow> Abs s \<rightarrow>\<^sub>\<beta> Abs t" |
|
1729 |
||
1730 |
code_module Test |
|
1731 |
contains |
|
1732 |
test1 = "Abs (Var 0) \<degree> Var 0 \<rightarrow>\<^sub>\<beta> Var 0" |
|
1733 |
test2 = "Abs (Abs (Var 0 \<degree> Var 0) \<degree> (Abs (Var 0) \<degree> Var 0)) \<rightarrow>\<^sub>\<beta> _" |
|
1734 |
||
1735 |
text {* |
|
1736 |
In the above example, @{ML Test.test1} evaluates to a boolean, |
|
1737 |
whereas @{ML Test.test2} is a lazy sequence whose elements can be |
|
1738 |
inspected separately. |
|
1739 |
*} |
|
1740 |
||
1741 |
ML {* @{assert} Test.test1 *} |
|
1742 |
ML {* val results = DSeq.list_of Test.test2 *} |
|
1743 |
ML {* @{assert} (length results = 2) *} |
|
1744 |
||
1745 |
text {* |
|
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1746 |
\medskip The theory underlying the HOL code generator is described |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1747 |
more detailed in \cite{Berghofer-Nipkow:2002}. More examples that |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1748 |
illustrate the usage of the code generator can be found e.g.\ in |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1749 |
@{"file" "~~/src/HOL/MicroJava/J/JListExample.thy"} and @{"file" |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1750 |
"~~/src/HOL/MicroJava/JVM/JVMListExample.thy"}. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1751 |
*} |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1752 |
|
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
1753 |
|
27045 | 1754 |
section {* Definition by specification \label{sec:hol-specification} *} |
1755 |
||
1756 |
text {* |
|
1757 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1758 |
@{command_def (HOL) "specification"} & : & @{text "theory \<rightarrow> proof(prove)"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1759 |
@{command_def (HOL) "ax_specification"} & : & @{text "theory \<rightarrow> proof(prove)"} \\ |
27045 | 1760 |
\end{matharray} |
1761 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1762 |
@{rail " |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1763 |
(@@{command (HOL) specification} | @@{command (HOL) ax_specification}) |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1764 |
'(' (decl +) ')' \\ (@{syntax thmdecl}? @{syntax prop} +) |
27045 | 1765 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1766 |
decl: ((@{syntax name} ':')? @{syntax term} '(' @'overloaded' ')'?) |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1767 |
"} |
27045 | 1768 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1769 |
\begin{description} |
27045 | 1770 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1771 |
\item @{command (HOL) "specification"}~@{text "decls \<phi>"} sets up a |
27045 | 1772 |
goal stating the existence of terms with the properties specified to |
1773 |
hold for the constants given in @{text decls}. After finishing the |
|
1774 |
proof, the theory will be augmented with definitions for the given |
|
1775 |
constants, as well as with theorems stating the properties for these |
|
1776 |
constants. |
|
1777 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1778 |
\item @{command (HOL) "ax_specification"}~@{text "decls \<phi>"} sets up |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1779 |
a goal stating the existence of terms with the properties specified |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1780 |
to hold for the constants given in @{text decls}. After finishing |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1781 |
the proof, the theory will be augmented with axioms expressing the |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1782 |
properties given in the first place. |
27045 | 1783 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1784 |
\item @{text decl} declares a constant to be defined by the |
27045 | 1785 |
specification given. The definition for the constant @{text c} is |
1786 |
bound to the name @{text c_def} unless a theorem name is given in |
|
1787 |
the declaration. Overloaded constants should be declared as such. |
|
1788 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1789 |
\end{description} |
27045 | 1790 |
|
1791 |
Whether to use @{command (HOL) "specification"} or @{command (HOL) |
|
1792 |
"ax_specification"} is to some extent a matter of style. @{command |
|
1793 |
(HOL) "specification"} introduces no new axioms, and so by |
|
1794 |
construction cannot introduce inconsistencies, whereas @{command |
|
1795 |
(HOL) "ax_specification"} does introduce axioms, but only after the |
|
1796 |
user has explicitly proven it to be safe. A practical issue must be |
|
1797 |
considered, though: After introducing two constants with the same |
|
1798 |
properties using @{command (HOL) "specification"}, one can prove |
|
1799 |
that the two constants are, in fact, equal. If this might be a |
|
1800 |
problem, one should use @{command (HOL) "ax_specification"}. |
|
1801 |
*} |
|
1802 |
||
26840 | 1803 |
end |