author | wenzelm |
Mon, 06 Jul 2015 20:07:41 +0200 | |
changeset 60673 | 91d36d6a6a88 |
parent 60672 | ac02ff182f46 |
child 60675 | a997fcb75d08 |
permissions | -rw-r--r-- |
26840 | 1 |
theory HOL_Specific |
60654 | 2 |
imports |
3 |
Base |
|
4 |
"~~/src/HOL/Library/Old_Datatype" |
|
5 |
"~~/src/HOL/Library/Old_Recdef" |
|
6 |
"~~/src/Tools/Adhoc_Overloading" |
|
7 |
"~~/src/HOL/Library/Dlist" |
|
8 |
"~~/src/HOL/Library/FSet" |
|
26840 | 9 |
begin |
10 |
||
60654 | 11 |
|
58618 | 12 |
chapter \<open>Higher-Order Logic\<close> |
13 |
||
14 |
text \<open>Isabelle/HOL is based on Higher-Order Logic, a polymorphic |
|
42914 | 15 |
version of Church's Simple Theory of Types. HOL can be best |
16 |
understood as a simply-typed version of classical set theory. The |
|
17 |
logic was first implemented in Gordon's HOL system |
|
58552 | 18 |
@{cite "mgordon-hol"}. It extends Church's original logic |
19 |
@{cite "church40"} by explicit type variables (naive polymorphism) and |
|
42914 | 20 |
a sound axiomatization scheme for new types based on subsets of |
21 |
existing types. |
|
22 |
||
58552 | 23 |
Andrews's book @{cite andrews86} is a full description of the |
42914 | 24 |
original Church-style higher-order logic, with proofs of correctness |
25 |
and completeness wrt.\ certain set-theoretic interpretations. The |
|
26 |
particular extensions of Gordon-style HOL are explained semantically |
|
58552 | 27 |
in two chapters of the 1993 HOL book @{cite pitts93}. |
42914 | 28 |
|
29 |
Experience with HOL over decades has demonstrated that higher-order |
|
30 |
logic is widely applicable in many areas of mathematics and computer |
|
31 |
science. In a sense, Higher-Order Logic is simpler than First-Order |
|
32 |
Logic, because there are fewer restrictions and special cases. Note |
|
33 |
that HOL is \emph{weaker} than FOL with axioms for ZF set theory, |
|
34 |
which is traditionally considered the standard foundation of regular |
|
35 |
mathematics, but for most applications this does not matter. If you |
|
36 |
prefer ML to Lisp, you will probably prefer HOL to ZF. |
|
37 |
||
38 |
\medskip The syntax of HOL follows @{text "\<lambda>"}-calculus and |
|
39 |
functional programming. Function application is curried. To apply |
|
40 |
the function @{text f} of type @{text "\<tau>\<^sub>1 \<Rightarrow> \<tau>\<^sub>2 \<Rightarrow> \<tau>\<^sub>3"} to the |
|
41 |
arguments @{text a} and @{text b} in HOL, you simply write @{text "f |
|
42 |
a b"} (as in ML or Haskell). There is no ``apply'' operator; the |
|
43 |
existing application of the Pure @{text "\<lambda>"}-calculus is re-used. |
|
44 |
Note that in HOL @{text "f (a, b)"} means ``@{text "f"} applied to |
|
45 |
the pair @{text "(a, b)"} (which is notation for @{text "Pair a |
|
46 |
b"}). The latter typically introduces extra formal efforts that can |
|
47 |
be avoided by currying functions by default. Explicit tuples are as |
|
48 |
infrequent in HOL formalizations as in good ML or Haskell programs. |
|
49 |
||
50 |
\medskip Isabelle/HOL has a distinct feel, compared to other |
|
51 |
object-logics like Isabelle/ZF. It identifies object-level types |
|
52 |
with meta-level types, taking advantage of the default |
|
53 |
type-inference mechanism of Isabelle/Pure. HOL fully identifies |
|
54 |
object-level functions with meta-level functions, with native |
|
55 |
abstraction and application. |
|
56 |
||
57 |
These identifications allow Isabelle to support HOL particularly |
|
58 |
nicely, but they also mean that HOL requires some sophistication |
|
59 |
from the user. In particular, an understanding of Hindley-Milner |
|
60 |
type-inference with type-classes, which are both used extensively in |
|
60655 | 61 |
the standard libraries and applications.\<close> |
58618 | 62 |
|
63 |
||
64 |
chapter \<open>Derived specification elements\<close> |
|
65 |
||
66 |
section \<open>Inductive and coinductive definitions \label{sec:hol-inductive}\<close> |
|
67 |
||
68 |
text \<open> |
|
46280 | 69 |
\begin{matharray}{rcl} |
70 |
@{command_def (HOL) "inductive"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
71 |
@{command_def (HOL) "inductive_set"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
72 |
@{command_def (HOL) "coinductive"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
73 |
@{command_def (HOL) "coinductive_set"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
50302 | 74 |
@{command_def "print_inductives"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
46280 | 75 |
@{attribute_def (HOL) mono} & : & @{text attribute} \\ |
76 |
\end{matharray} |
|
77 |
||
78 |
An \emph{inductive definition} specifies the least predicate or set |
|
79 |
@{text R} closed under given rules: applying a rule to elements of |
|
80 |
@{text R} yields a result within @{text R}. For example, a |
|
81 |
structural operational semantics is an inductive definition of an |
|
82 |
evaluation relation. |
|
42908 | 83 |
|
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
84 |
Dually, a \emph{coinductive definition} specifies the greatest |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
85 |
predicate or set @{text R} that is consistent with given rules: |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
86 |
every element of @{text R} can be seen as arising by applying a rule |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
87 |
to elements of @{text R}. An important example is using |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
88 |
bisimulation relations to formalise equivalence of processes and |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
89 |
infinite data structures. |
47859 | 90 |
|
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
91 |
Both inductive and coinductive definitions are based on the |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
92 |
Knaster-Tarski fixed-point theorem for complete lattices. The |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
93 |
collection of introduction rules given by the user determines a |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
94 |
functor on subsets of set-theoretic relations. The required |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
95 |
monotonicity of the recursion scheme is proven as a prerequisite to |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
96 |
the fixed-point definition and the resulting consequences. This |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
97 |
works by pushing inclusion through logical connectives and any other |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
98 |
operator that might be wrapped around recursive occurrences of the |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
99 |
defined relation: there must be a monotonicity theorem of the form |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
100 |
@{text "A \<le> B \<Longrightarrow> \<M> A \<le> \<M> B"}, for each premise @{text "\<M> R t"} in an |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
101 |
introduction rule. The default rule declarations of Isabelle/HOL |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
102 |
already take care of most common situations. |
42907
dfd4ef8e73f6
updated and re-unified HOL typedef, with some live examples;
wenzelm
parents:
42705
diff
changeset
|
103 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
104 |
@{rail \<open> |
42908 | 105 |
(@@{command (HOL) inductive} | @@{command (HOL) inductive_set} | |
59785 | 106 |
@@{command (HOL) coinductive} | @@{command (HOL) coinductive_set}) |
107 |
@{syntax "fixes"} @{syntax "for_fixes"} \<newline> |
|
108 |
(@'where' clauses)? (@'monos' @{syntax thmrefs})? |
|
42908 | 109 |
; |
110 |
clauses: (@{syntax thmdecl}? @{syntax prop} + '|') |
|
111 |
; |
|
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59905
diff
changeset
|
112 |
@@{command print_inductives} ('!'?) |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59905
diff
changeset
|
113 |
; |
42908 | 114 |
@@{attribute (HOL) mono} (() | 'add' | 'del') |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
115 |
\<close>} |
42908 | 116 |
|
117 |
\begin{description} |
|
118 |
||
119 |
\item @{command (HOL) "inductive"} and @{command (HOL) |
|
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
120 |
"coinductive"} define (co)inductive predicates from the introduction |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
121 |
rules. |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
122 |
|
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
123 |
The propositions given as @{text "clauses"} in the @{keyword |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
124 |
"where"} part are either rules of the usual @{text "\<And>/\<Longrightarrow>"} format |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
125 |
(with arbitrary nesting), or equalities using @{text "\<equiv>"}. The |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
126 |
latter specifies extra-logical abbreviations in the sense of |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
127 |
@{command_ref abbreviation}. Introducing abstract syntax |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
128 |
simultaneously with the actual introduction rules is occasionally |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
129 |
useful for complex specifications. |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
130 |
|
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
131 |
The optional @{keyword "for"} part contains a list of parameters of |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
132 |
the (co)inductive predicates that remain fixed throughout the |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
133 |
definition, in contrast to arguments of the relation that may vary |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
134 |
in each occurrence within the given @{text "clauses"}. |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
135 |
|
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
136 |
The optional @{keyword "monos"} declaration contains additional |
42908 | 137 |
\emph{monotonicity theorems}, which are required for each operator |
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
138 |
applied to a recursive set in the introduction rules. |
42908 | 139 |
|
140 |
\item @{command (HOL) "inductive_set"} and @{command (HOL) |
|
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
141 |
"coinductive_set"} are wrappers for to the previous commands for |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
142 |
native HOL predicates. This allows to define (co)inductive sets, |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
143 |
where multiple arguments are simulated via tuples. |
42908 | 144 |
|
50302 | 145 |
\item @{command "print_inductives"} prints (co)inductive definitions and |
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59905
diff
changeset
|
146 |
monotonicity rules; the ``@{text "!"}'' option indicates extra verbosity. |
50302 | 147 |
|
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
148 |
\item @{attribute (HOL) mono} declares monotonicity rules in the |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
149 |
context. These rule are involved in the automated monotonicity |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
150 |
proof of the above inductive and coinductive definitions. |
42908 | 151 |
|
152 |
\end{description} |
|
58618 | 153 |
\<close> |
154 |
||
155 |
||
156 |
subsection \<open>Derived rules\<close> |
|
157 |
||
158 |
text \<open>A (co)inductive definition of @{text R} provides the following |
|
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
159 |
main theorems: |
42908 | 160 |
|
161 |
\begin{description} |
|
162 |
||
163 |
\item @{text R.intros} is the list of introduction rules as proven |
|
164 |
theorems, for the recursive predicates (or sets). The rules are |
|
165 |
also available individually, using the names given them in the |
|
166 |
theory file; |
|
167 |
||
168 |
\item @{text R.cases} is the case analysis (or elimination) rule; |
|
169 |
||
170 |
\item @{text R.induct} or @{text R.coinduct} is the (co)induction |
|
44273
336752fb25df
adding documentation about simps equation in the inductive package
bulwahn
parents:
44055
diff
changeset
|
171 |
rule; |
336752fb25df
adding documentation about simps equation in the inductive package
bulwahn
parents:
44055
diff
changeset
|
172 |
|
336752fb25df
adding documentation about simps equation in the inductive package
bulwahn
parents:
44055
diff
changeset
|
173 |
\item @{text R.simps} is the equation unrolling the fixpoint of the |
336752fb25df
adding documentation about simps equation in the inductive package
bulwahn
parents:
44055
diff
changeset
|
174 |
predicate one step. |
47859 | 175 |
|
42908 | 176 |
\end{description} |
177 |
||
60654 | 178 |
When several predicates @{text "R\<^sub>1, \<dots>, R\<^sub>n"} are defined simultaneously, |
179 |
the list of introduction rules is called @{text "R\<^sub>1_\<dots>_R\<^sub>n.intros"}, the |
|
180 |
case analysis rules are called @{text "R\<^sub>1.cases, \<dots>, R\<^sub>n.cases"}, and the |
|
181 |
list of mutual induction rules is called @{text "R\<^sub>1_\<dots>_R\<^sub>n.inducts"}. |
|
58618 | 182 |
\<close> |
183 |
||
184 |
||
185 |
subsection \<open>Monotonicity theorems\<close> |
|
186 |
||
187 |
text \<open>The context maintains a default set of theorems that are used |
|
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
188 |
in monotonicity proofs. New rules can be declared via the |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
189 |
@{attribute (HOL) mono} attribute. See the main Isabelle/HOL |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
190 |
sources for some examples. The general format of such monotonicity |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
191 |
theorems is as follows: |
42908 | 192 |
|
193 |
\begin{itemize} |
|
194 |
||
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
195 |
\item Theorems of the form @{text "A \<le> B \<Longrightarrow> \<M> A \<le> \<M> B"}, for proving |
42908 | 196 |
monotonicity of inductive definitions whose introduction rules have |
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
197 |
premises involving terms such as @{text "\<M> R t"}. |
42908 | 198 |
|
199 |
\item Monotonicity theorems for logical operators, which are of the |
|
200 |
general form @{text "(\<dots> \<longrightarrow> \<dots>) \<Longrightarrow> \<dots> (\<dots> \<longrightarrow> \<dots>) \<Longrightarrow> \<dots> \<longrightarrow> \<dots>"}. For example, in |
|
201 |
the case of the operator @{text "\<or>"}, the corresponding theorem is |
|
202 |
\[ |
|
203 |
\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"}} |
|
204 |
\] |
|
205 |
||
206 |
\item De Morgan style equations for reasoning about the ``polarity'' |
|
207 |
of expressions, e.g. |
|
208 |
\[ |
|
209 |
@{prop "\<not> \<not> P \<longleftrightarrow> P"} \qquad\qquad |
|
210 |
@{prop "\<not> (P \<and> Q) \<longleftrightarrow> \<not> P \<or> \<not> Q"} |
|
211 |
\] |
|
212 |
||
213 |
\item Equations for reducing complex operators to more primitive |
|
214 |
ones whose monotonicity can easily be proved, e.g. |
|
215 |
\[ |
|
216 |
@{prop "(P \<longrightarrow> Q) \<longleftrightarrow> \<not> P \<or> Q"} \qquad\qquad |
|
217 |
@{prop "Ball A P \<equiv> \<forall>x. x \<in> A \<longrightarrow> P x"} |
|
218 |
\] |
|
219 |
||
220 |
\end{itemize} |
|
58618 | 221 |
\<close> |
222 |
||
223 |
subsubsection \<open>Examples\<close> |
|
224 |
||
225 |
text \<open>The finite powerset operator can be defined inductively like this:\<close> |
|
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
226 |
|
59905 | 227 |
(*<*)experiment begin(*>*) |
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
228 |
inductive_set Fin :: "'a set \<Rightarrow> 'a set set" for A :: "'a set" |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
229 |
where |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
230 |
empty: "{} \<in> Fin A" |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
231 |
| insert: "a \<in> A \<Longrightarrow> B \<in> Fin A \<Longrightarrow> insert a B \<in> Fin A" |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
232 |
|
58618 | 233 |
text \<open>The accessible part of a relation is defined as follows:\<close> |
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
234 |
|
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
235 |
inductive acc :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool" |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
236 |
for r :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<prec>" 50) |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
237 |
where acc: "(\<And>y. y \<prec> x \<Longrightarrow> acc r y) \<Longrightarrow> acc r x" |
59905 | 238 |
(*<*)end(*>*) |
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
239 |
|
58618 | 240 |
text \<open>Common logical connectives can be easily characterized as |
60654 | 241 |
non-recursive inductive definitions with parameters, but without |
242 |
arguments.\<close> |
|
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
243 |
|
59905 | 244 |
(*<*)experiment begin(*>*) |
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
245 |
inductive AND for A B :: bool |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
246 |
where "A \<Longrightarrow> B \<Longrightarrow> AND A B" |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
247 |
|
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
248 |
inductive OR for A B :: bool |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
249 |
where "A \<Longrightarrow> OR A B" |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
250 |
| "B \<Longrightarrow> OR A B" |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
251 |
|
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
252 |
inductive EXISTS for B :: "'a \<Rightarrow> bool" |
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
253 |
where "B a \<Longrightarrow> EXISTS B" |
59905 | 254 |
(*<*)end(*>*) |
42913
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
wenzelm
parents:
42912
diff
changeset
|
255 |
|
60654 | 256 |
text \<open>Here the @{text "cases"} or @{text "induct"} rules produced by the |
257 |
@{command inductive} package coincide with the expected elimination rules |
|
258 |
for Natural Deduction. Already in the original article by Gerhard Gentzen |
|
259 |
@{cite "Gentzen:1935"} there is a hint that each connective can be |
|
260 |
characterized by its introductions, and the elimination can be constructed |
|
261 |
systematically.\<close> |
|
58618 | 262 |
|
263 |
||
264 |
section \<open>Recursive functions \label{sec:recursion}\<close> |
|
265 |
||
266 |
text \<open> |
|
42908 | 267 |
\begin{matharray}{rcl} |
268 |
@{command_def (HOL) "primrec"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
269 |
@{command_def (HOL) "fun"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
270 |
@{command_def (HOL) "function"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\ |
|
271 |
@{command_def (HOL) "termination"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\ |
|
54017
2a3c07f49615
basic documentation for function elimination rules and fun_cases
krauss
parents:
53982
diff
changeset
|
272 |
@{command_def (HOL) "fun_cases"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
42908 | 273 |
\end{matharray} |
274 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
275 |
@{rail \<open> |
59783
00b62aa9f430
tuned syntax diagrams -- no duplication of "target";
wenzelm
parents:
59487
diff
changeset
|
276 |
@@{command (HOL) primrec} @{syntax "fixes"} @'where' equations |
42908 | 277 |
; |
59783
00b62aa9f430
tuned syntax diagrams -- no duplication of "target";
wenzelm
parents:
59487
diff
changeset
|
278 |
(@@{command (HOL) fun} | @@{command (HOL) function}) functionopts? |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
279 |
@{syntax "fixes"} \<newline> @'where' equations |
26849 | 280 |
; |
281 |
||
42908 | 282 |
equations: (@{syntax thmdecl}? @{syntax prop} + '|') |
26849 | 283 |
; |
42908 | 284 |
functionopts: '(' (('sequential' | 'domintros') + ',') ')' |
26849 | 285 |
; |
42908 | 286 |
@@{command (HOL) termination} @{syntax term}? |
54017
2a3c07f49615
basic documentation for function elimination rules and fun_cases
krauss
parents:
53982
diff
changeset
|
287 |
; |
2a3c07f49615
basic documentation for function elimination rules and fun_cases
krauss
parents:
53982
diff
changeset
|
288 |
@@{command (HOL) fun_cases} (@{syntax thmdecl}? @{syntax prop} + @'and') |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
289 |
\<close>} |
26849 | 290 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
291 |
\begin{description} |
42123 | 292 |
|
60654 | 293 |
\item @{command (HOL) "primrec"} defines primitive recursive functions |
294 |
over datatypes (see also @{command_ref (HOL) datatype}). The given @{text |
|
295 |
equations} specify reduction rules that are produced by instantiating the |
|
296 |
generic combinator for primitive recursion that is available for each |
|
297 |
datatype. |
|
42912 | 298 |
|
299 |
Each equation needs to be of the form: |
|
300 |
||
301 |
@{text [display] "f x\<^sub>1 \<dots> x\<^sub>m (C y\<^sub>1 \<dots> y\<^sub>k) z\<^sub>1 \<dots> z\<^sub>n = rhs"} |
|
302 |
||
60654 | 303 |
such that @{text C} is a datatype constructor, @{text rhs} contains only |
304 |
the free variables on the left-hand side (or from the context), and all |
|
305 |
recursive occurrences of @{text "f"} in @{text "rhs"} are of the form |
|
306 |
@{text "f \<dots> y\<^sub>i \<dots>"} for some @{text i}. At most one reduction rule for |
|
307 |
each constructor can be given. The order does not matter. For missing |
|
308 |
constructors, the function is defined to return a default value, but this |
|
309 |
equation is made difficult to access for users. |
|
310 |
||
311 |
The reduction rules are declared as @{attribute simp} by default, which |
|
312 |
enables standard proof methods like @{method simp} and @{method auto} to |
|
313 |
normalize expressions of @{text "f"} applied to datatype constructions, by |
|
314 |
simulating symbolic computation via rewriting. |
|
315 |
||
316 |
\item @{command (HOL) "function"} defines functions by general wellfounded |
|
317 |
recursion. A detailed description with examples can be found in @{cite |
|
318 |
"isabelle-function"}. The function is specified by a set of (possibly |
|
319 |
conditional) recursive equations with arbitrary pattern matching. The |
|
320 |
command generates proof obligations for the completeness and the |
|
321 |
compatibility of patterns. |
|
42907
dfd4ef8e73f6
updated and re-unified HOL typedef, with some live examples;
wenzelm
parents:
42705
diff
changeset
|
322 |
|
42908 | 323 |
The defined function is considered partial, and the resulting |
60654 | 324 |
simplification rules (named @{text "f.psimps"}) and induction rule (named |
325 |
@{text "f.pinduct"}) are guarded by a generated domain predicate @{text |
|
326 |
"f_dom"}. The @{command (HOL) "termination"} command can then be used to |
|
327 |
establish that the function is total. |
|
328 |
||
329 |
\item @{command (HOL) "fun"} is a shorthand notation for ``@{command (HOL) |
|
330 |
"function"}~@{text "(sequential)"}'', followed by automated proof attempts |
|
331 |
regarding pattern matching and termination. See @{cite |
|
332 |
"isabelle-function"} for further details. |
|
333 |
||
334 |
\item @{command (HOL) "termination"}~@{text f} commences a termination |
|
335 |
proof for the previously defined function @{text f}. If this is omitted, |
|
336 |
the command refers to the most recent function definition. After the proof |
|
337 |
is closed, the recursive equations and the induction principle is |
|
338 |
established. |
|
339 |
||
340 |
\item @{command (HOL) "fun_cases"} generates specialized elimination rules |
|
341 |
for function equations. It expects one or more function equations and |
|
342 |
produces rules that eliminate the given equalities, following the cases |
|
54017
2a3c07f49615
basic documentation for function elimination rules and fun_cases
krauss
parents:
53982
diff
changeset
|
343 |
given in the function definition. |
60654 | 344 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
345 |
\end{description} |
42907
dfd4ef8e73f6
updated and re-unified HOL typedef, with some live examples;
wenzelm
parents:
42705
diff
changeset
|
346 |
|
42908 | 347 |
Recursive definitions introduced by the @{command (HOL) "function"} |
60654 | 348 |
command accommodate reasoning by induction (cf.\ @{method induct}): rule |
349 |
@{text "f.induct"} refers to a specific induction rule, with parameters |
|
350 |
named according to the user-specified equations. Cases are numbered |
|
351 |
starting from 1. For @{command (HOL) "primrec"}, the induction principle |
|
352 |
coincides with structural recursion on the datatype where the recursion is |
|
353 |
carried out. |
|
354 |
||
355 |
The equations provided by these packages may be referred later as theorem |
|
356 |
list @{text "f.simps"}, where @{text f} is the (collective) name of the |
|
357 |
functions defined. Individual equations may be named explicitly as well. |
|
358 |
||
359 |
The @{command (HOL) "function"} command accepts the following options. |
|
42908 | 360 |
|
361 |
\begin{description} |
|
362 |
||
363 |
\item @{text sequential} enables a preprocessor which disambiguates |
|
60654 | 364 |
overlapping patterns by making them mutually disjoint. Earlier equations |
365 |
take precedence over later ones. This allows to give the specification in |
|
366 |
a format very similar to functional programming. Note that the resulting |
|
367 |
simplification and induction rules correspond to the transformed |
|
368 |
specification, not the one given originally. This usually means that each |
|
369 |
equation given by the user may result in several theorems. Also note that |
|
370 |
this automatic transformation only works for ML-style datatype patterns. |
|
371 |
||
372 |
\item @{text domintros} enables the automated generation of introduction |
|
373 |
rules for the domain predicate. While mostly not needed, they can be |
|
374 |
helpful in some proofs about partial functions. |
|
42908 | 375 |
|
376 |
\end{description} |
|
58618 | 377 |
\<close> |
378 |
||
60654 | 379 |
|
58618 | 380 |
subsubsection \<open>Example: evaluation of expressions\<close> |
381 |
||
60654 | 382 |
text \<open>Subsequently, we define mutual datatypes for arithmetic and boolean |
383 |
expressions, and use @{command primrec} for evaluation functions that |
|
384 |
follow the same recursive structure.\<close> |
|
42912 | 385 |
|
59905 | 386 |
(*<*)experiment begin(*>*) |
58310 | 387 |
datatype 'a aexp = |
42912 | 388 |
IF "'a bexp" "'a aexp" "'a aexp" |
389 |
| Sum "'a aexp" "'a aexp" |
|
390 |
| Diff "'a aexp" "'a aexp" |
|
391 |
| Var 'a |
|
392 |
| Num nat |
|
393 |
and 'a bexp = |
|
394 |
Less "'a aexp" "'a aexp" |
|
395 |
| And "'a bexp" "'a bexp" |
|
396 |
| Neg "'a bexp" |
|
397 |
||
398 |
||
58618 | 399 |
text \<open>\medskip Evaluation of arithmetic and boolean expressions\<close> |
42912 | 400 |
|
401 |
primrec evala :: "('a \<Rightarrow> nat) \<Rightarrow> 'a aexp \<Rightarrow> nat" |
|
402 |
and evalb :: "('a \<Rightarrow> nat) \<Rightarrow> 'a bexp \<Rightarrow> bool" |
|
403 |
where |
|
404 |
"evala env (IF b a1 a2) = (if evalb env b then evala env a1 else evala env a2)" |
|
405 |
| "evala env (Sum a1 a2) = evala env a1 + evala env a2" |
|
406 |
| "evala env (Diff a1 a2) = evala env a1 - evala env a2" |
|
407 |
| "evala env (Var v) = env v" |
|
408 |
| "evala env (Num n) = n" |
|
409 |
| "evalb env (Less a1 a2) = (evala env a1 < evala env a2)" |
|
410 |
| "evalb env (And b1 b2) = (evalb env b1 \<and> evalb env b2)" |
|
411 |
| "evalb env (Neg b) = (\<not> evalb env b)" |
|
412 |
||
58618 | 413 |
text \<open>Since the value of an expression depends on the value of its |
42912 | 414 |
variables, the functions @{const evala} and @{const evalb} take an |
60654 | 415 |
additional parameter, an \emph{environment} that maps variables to their |
416 |
values. |
|
417 |
||
418 |
\medskip Substitution on expressions can be defined similarly. The mapping |
|
419 |
@{text f} of type @{typ "'a \<Rightarrow> 'a aexp"} given as a parameter is lifted |
|
420 |
canonically on the types @{typ "'a aexp"} and @{typ "'a bexp"}, |
|
421 |
respectively. |
|
58618 | 422 |
\<close> |
42912 | 423 |
|
424 |
primrec substa :: "('a \<Rightarrow> 'b aexp) \<Rightarrow> 'a aexp \<Rightarrow> 'b aexp" |
|
425 |
and substb :: "('a \<Rightarrow> 'b aexp) \<Rightarrow> 'a bexp \<Rightarrow> 'b bexp" |
|
426 |
where |
|
427 |
"substa f (IF b a1 a2) = IF (substb f b) (substa f a1) (substa f a2)" |
|
428 |
| "substa f (Sum a1 a2) = Sum (substa f a1) (substa f a2)" |
|
429 |
| "substa f (Diff a1 a2) = Diff (substa f a1) (substa f a2)" |
|
430 |
| "substa f (Var v) = f v" |
|
431 |
| "substa f (Num n) = Num n" |
|
432 |
| "substb f (Less a1 a2) = Less (substa f a1) (substa f a2)" |
|
433 |
| "substb f (And b1 b2) = And (substb f b1) (substb f b2)" |
|
434 |
| "substb f (Neg b) = Neg (substb f b)" |
|
435 |
||
60654 | 436 |
text \<open>In textbooks about semantics one often finds substitution theorems, |
437 |
which express the relationship between substitution and evaluation. For |
|
438 |
@{typ "'a aexp"} and @{typ "'a bexp"}, we can prove such a theorem by |
|
439 |
mutual induction, followed by simplification. |
|
58618 | 440 |
\<close> |
42912 | 441 |
|
442 |
lemma subst_one: |
|
443 |
"evala env (substa (Var (v := a')) a) = evala (env (v := evala env a')) a" |
|
444 |
"evalb env (substb (Var (v := a')) b) = evalb (env (v := evala env a')) b" |
|
445 |
by (induct a and b) simp_all |
|
446 |
||
447 |
lemma subst_all: |
|
448 |
"evala env (substa s a) = evala (\<lambda>x. evala env (s x)) a" |
|
449 |
"evalb env (substb s b) = evalb (\<lambda>x. evala env (s x)) b" |
|
450 |
by (induct a and b) simp_all |
|
59905 | 451 |
(*<*)end(*>*) |
42912 | 452 |
|
453 |
||
58618 | 454 |
subsubsection \<open>Example: a substitution function for terms\<close> |
455 |
||
456 |
text \<open>Functions on datatypes with nested recursion are also defined |
|
457 |
by mutual primitive recursion.\<close> |
|
42912 | 458 |
|
59905 | 459 |
(*<*)experiment begin(*>*) |
58310 | 460 |
datatype ('a, 'b) "term" = Var 'a | App 'b "('a, 'b) term list" |
42912 | 461 |
|
58618 | 462 |
text \<open>A substitution function on type @{typ "('a, 'b) term"} can be |
42912 | 463 |
defined as follows, by working simultaneously on @{typ "('a, 'b) |
58618 | 464 |
term list"}:\<close> |
42912 | 465 |
|
466 |
primrec subst_term :: "('a \<Rightarrow> ('a, 'b) term) \<Rightarrow> ('a, 'b) term \<Rightarrow> ('a, 'b) term" and |
|
467 |
subst_term_list :: "('a \<Rightarrow> ('a, 'b) term) \<Rightarrow> ('a, 'b) term list \<Rightarrow> ('a, 'b) term list" |
|
468 |
where |
|
469 |
"subst_term f (Var a) = f a" |
|
470 |
| "subst_term f (App b ts) = App b (subst_term_list f ts)" |
|
471 |
| "subst_term_list f [] = []" |
|
472 |
| "subst_term_list f (t # ts) = subst_term f t # subst_term_list f ts" |
|
473 |
||
58618 | 474 |
text \<open>The recursion scheme follows the structure of the unfolded |
42912 | 475 |
definition of type @{typ "('a, 'b) term"}. To prove properties of this |
476 |
substitution function, mutual induction is needed: |
|
58618 | 477 |
\<close> |
42912 | 478 |
|
59905 | 479 |
lemma "subst_term (subst_term f1 \<circ> f2) t = |
480 |
subst_term f1 (subst_term f2 t)" and |
|
481 |
"subst_term_list (subst_term f1 \<circ> f2) ts = |
|
482 |
subst_term_list f1 (subst_term_list f2 ts)" |
|
58305
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
blanchet
parents:
58100
diff
changeset
|
483 |
by (induct t and ts rule: subst_term.induct subst_term_list.induct) simp_all |
59905 | 484 |
(*<*)end(*>*) |
42912 | 485 |
|
486 |
||
58618 | 487 |
subsubsection \<open>Example: a map function for infinitely branching trees\<close> |
488 |
||
60654 | 489 |
text \<open>Defining functions on infinitely branching datatypes by primitive |
490 |
recursion is just as easy.\<close> |
|
42912 | 491 |
|
59905 | 492 |
(*<*)experiment begin(*>*) |
58310 | 493 |
datatype 'a tree = Atom 'a | Branch "nat \<Rightarrow> 'a tree" |
42912 | 494 |
|
495 |
primrec map_tree :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a tree \<Rightarrow> 'b tree" |
|
496 |
where |
|
497 |
"map_tree f (Atom a) = Atom (f a)" |
|
498 |
| "map_tree f (Branch ts) = Branch (\<lambda>x. map_tree f (ts x))" |
|
499 |
||
60654 | 500 |
text \<open>Note that all occurrences of functions such as @{text ts} above must |
501 |
be applied to an argument. In particular, @{term "map_tree f \<circ> ts"} is not |
|
502 |
allowed here. |
|
503 |
||
504 |
\medskip Here is a simple composition lemma for @{term map_tree}: |
|
505 |
\<close> |
|
42912 | 506 |
|
507 |
lemma "map_tree g (map_tree f t) = map_tree (g \<circ> f) t" |
|
508 |
by (induct t) simp_all |
|
59905 | 509 |
(*<*)end(*>*) |
42912 | 510 |
|
42907
dfd4ef8e73f6
updated and re-unified HOL typedef, with some live examples;
wenzelm
parents:
42705
diff
changeset
|
511 |
|
58618 | 512 |
subsection \<open>Proof methods related to recursive definitions\<close> |
513 |
||
514 |
text \<open> |
|
26849 | 515 |
\begin{matharray}{rcl} |
42908 | 516 |
@{method_def (HOL) pat_completeness} & : & @{text method} \\ |
517 |
@{method_def (HOL) relation} & : & @{text method} \\ |
|
518 |
@{method_def (HOL) lexicographic_order} & : & @{text method} \\ |
|
519 |
@{method_def (HOL) size_change} & : & @{text method} \\ |
|
45944
e586f6d136b7
added some basic documentation about method induction_schema extracted from old NEWS
bulwahn
parents:
45943
diff
changeset
|
520 |
@{method_def (HOL) induction_schema} & : & @{text method} \\ |
26849 | 521 |
\end{matharray} |
522 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
523 |
@{rail \<open> |
42908 | 524 |
@@{method (HOL) relation} @{syntax term} |
525 |
; |
|
526 |
@@{method (HOL) lexicographic_order} (@{syntax clasimpmod} * ) |
|
527 |
; |
|
528 |
@@{method (HOL) size_change} ( orders (@{syntax clasimpmod} * ) ) |
|
529 |
; |
|
45944
e586f6d136b7
added some basic documentation about method induction_schema extracted from old NEWS
bulwahn
parents:
45943
diff
changeset
|
530 |
@@{method (HOL) induction_schema} |
e586f6d136b7
added some basic documentation about method induction_schema extracted from old NEWS
bulwahn
parents:
45943
diff
changeset
|
531 |
; |
42908 | 532 |
orders: ( 'max' | 'min' | 'ms' ) * |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
533 |
\<close>} |
42908 | 534 |
|
535 |
\begin{description} |
|
536 |
||
537 |
\item @{method (HOL) pat_completeness} is a specialized method to |
|
538 |
solve goals regarding the completeness of pattern matching, as |
|
539 |
required by the @{command (HOL) "function"} package (cf.\ |
|
58552 | 540 |
@{cite "isabelle-function"}). |
42908 | 541 |
|
542 |
\item @{method (HOL) relation}~@{text R} introduces a termination |
|
543 |
proof using the relation @{text R}. The resulting proof state will |
|
544 |
contain goals expressing that @{text R} is wellfounded, and that the |
|
545 |
arguments of recursive calls decrease with respect to @{text R}. |
|
546 |
Usually, this method is used as the initial proof step of manual |
|
547 |
termination proofs. |
|
548 |
||
549 |
\item @{method (HOL) "lexicographic_order"} attempts a fully |
|
550 |
automated termination proof by searching for a lexicographic |
|
551 |
combination of size measures on the arguments of the function. The |
|
552 |
method accepts the same arguments as the @{method auto} method, |
|
42930 | 553 |
which it uses internally to prove local descents. The @{syntax |
554 |
clasimpmod} modifiers are accepted (as for @{method auto}). |
|
42908 | 555 |
|
556 |
In case of failure, extensive information is printed, which can help |
|
58552 | 557 |
to analyse the situation (cf.\ @{cite "isabelle-function"}). |
42908 | 558 |
|
559 |
\item @{method (HOL) "size_change"} also works on termination goals, |
|
560 |
using a variation of the size-change principle, together with a |
|
58552 | 561 |
graph decomposition technique (see @{cite krauss_phd} for details). |
42908 | 562 |
Three kinds of orders are used internally: @{text max}, @{text min}, |
563 |
and @{text ms} (multiset), which is only available when the theory |
|
564 |
@{text Multiset} is loaded. When no order kinds are given, they are |
|
565 |
tried in order. The search for a termination proof uses SAT solving |
|
566 |
internally. |
|
567 |
||
42930 | 568 |
For local descent proofs, the @{syntax clasimpmod} modifiers are |
569 |
accepted (as for @{method auto}). |
|
42908 | 570 |
|
45944
e586f6d136b7
added some basic documentation about method induction_schema extracted from old NEWS
bulwahn
parents:
45943
diff
changeset
|
571 |
\item @{method (HOL) induction_schema} derives user-specified |
46283 | 572 |
induction rules from well-founded induction and completeness of |
573 |
patterns. This factors out some operations that are done internally |
|
574 |
by the function package and makes them available separately. See |
|
575 |
@{file "~~/src/HOL/ex/Induction_Schema.thy"} for examples. |
|
45944
e586f6d136b7
added some basic documentation about method induction_schema extracted from old NEWS
bulwahn
parents:
45943
diff
changeset
|
576 |
|
42908 | 577 |
\end{description} |
58618 | 578 |
\<close> |
579 |
||
580 |
||
581 |
subsection \<open>Functions with explicit partiality\<close> |
|
582 |
||
583 |
text \<open> |
|
42908 | 584 |
\begin{matharray}{rcl} |
585 |
@{command_def (HOL) "partial_function"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
586 |
@{attribute_def (HOL) "partial_function_mono"} & : & @{text attribute} \\ |
|
587 |
\end{matharray} |
|
588 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
589 |
@{rail \<open> |
59783
00b62aa9f430
tuned syntax diagrams -- no duplication of "target";
wenzelm
parents:
59487
diff
changeset
|
590 |
@@{command (HOL) partial_function} '(' @{syntax nameref} ')' @{syntax "fixes"} \<newline> |
42908 | 591 |
@'where' @{syntax thmdecl}? @{syntax prop} |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
592 |
\<close>} |
26849 | 593 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
594 |
\begin{description} |
42123 | 595 |
|
42908 | 596 |
\item @{command (HOL) "partial_function"}~@{text "(mode)"} defines |
597 |
recursive functions based on fixpoints in complete partial |
|
598 |
orders. No termination proof is required from the user or |
|
599 |
constructed internally. Instead, the possibility of non-termination |
|
600 |
is modelled explicitly in the result type, which contains an |
|
601 |
explicit bottom element. |
|
602 |
||
603 |
Pattern matching and mutual recursion are currently not supported. |
|
604 |
Thus, the specification consists of a single function described by a |
|
605 |
single recursive equation. |
|
606 |
||
607 |
There are no fixed syntactic restrictions on the body of the |
|
608 |
function, but the induced functional must be provably monotonic |
|
52895
a806aa7a5370
some documentation for adhoc overloading;
Christian Sternagel
parents:
52637
diff
changeset
|
609 |
wrt.\ the underlying order. The monotonicity proof is performed |
42908 | 610 |
internally, and the definition is rejected when it fails. The proof |
611 |
can be influenced by declaring hints using the |
|
612 |
@{attribute (HOL) partial_function_mono} attribute. |
|
613 |
||
614 |
The mandatory @{text mode} argument specifies the mode of operation |
|
615 |
of the command, which directly corresponds to a complete partial |
|
616 |
order on the result type. By default, the following modes are |
|
617 |
defined: |
|
26849 | 618 |
|
42908 | 619 |
\begin{description} |
46283 | 620 |
|
42908 | 621 |
\item @{text option} defines functions that map into the @{type |
622 |
option} type. Here, the value @{term None} is used to model a |
|
623 |
non-terminating computation. Monotonicity requires that if @{term |
|
46283 | 624 |
None} is returned by a recursive call, then the overall result must |
625 |
also be @{term None}. This is best achieved through the use of the |
|
626 |
monadic operator @{const "Option.bind"}. |
|
42908 | 627 |
|
628 |
\item @{text tailrec} defines functions with an arbitrary result |
|
629 |
type and uses the slightly degenerated partial order where @{term |
|
630 |
"undefined"} is the bottom element. Now, monotonicity requires that |
|
631 |
if @{term undefined} is returned by a recursive call, then the |
|
632 |
overall result must also be @{term undefined}. In practice, this is |
|
633 |
only satisfied when each recursive call is a tail call, whose result |
|
634 |
is directly returned. Thus, this mode of operation allows the |
|
635 |
definition of arbitrary tail-recursive functions. |
|
46283 | 636 |
|
42908 | 637 |
\end{description} |
638 |
||
639 |
Experienced users may define new modes by instantiating the locale |
|
640 |
@{const "partial_function_definitions"} appropriately. |
|
641 |
||
642 |
\item @{attribute (HOL) partial_function_mono} declares rules for |
|
52895
a806aa7a5370
some documentation for adhoc overloading;
Christian Sternagel
parents:
52637
diff
changeset
|
643 |
use in the internal monotonicity proofs of partial function |
42908 | 644 |
definitions. |
26849 | 645 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
646 |
\end{description} |
58618 | 647 |
\<close> |
648 |
||
649 |
||
650 |
subsection \<open>Old-style recursive function definitions (TFL)\<close> |
|
651 |
||
652 |
text \<open> |
|
42908 | 653 |
\begin{matharray}{rcl} |
654 |
@{command_def (HOL) "recdef"} & : & @{text "theory \<rightarrow> theory)"} \\ |
|
655 |
\end{matharray} |
|
656 |
||
60523 | 657 |
The old TFL command @{command (HOL) "recdef"} for defining recursive is |
658 |
mostly obsolete; @{command (HOL) "function"} or @{command (HOL) "fun"} |
|
659 |
should be used instead. |
|
46280 | 660 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
661 |
@{rail \<open> |
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
662 |
@@{command (HOL) recdef} ('(' @'permissive' ')')? \<newline> |
42908 | 663 |
@{syntax name} @{syntax term} (@{syntax prop} +) hints? |
664 |
; |
|
665 |
hints: '(' @'hints' ( recdefmod * ) ')' |
|
666 |
; |
|
667 |
recdefmod: (('recdef_simp' | 'recdef_cong' | 'recdef_wf') |
|
668 |
(() | 'add' | 'del') ':' @{syntax thmrefs}) | @{syntax clasimpmod} |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
669 |
\<close>} |
42908 | 670 |
|
671 |
\begin{description} |
|
672 |
||
673 |
\item @{command (HOL) "recdef"} defines general well-founded |
|
674 |
recursive functions (using the TFL package), see also |
|
58552 | 675 |
@{cite "isabelle-HOL"}. The ``@{text "(permissive)"}'' option tells |
42908 | 676 |
TFL to recover from failed proof attempts, returning unfinished |
677 |
results. The @{text recdef_simp}, @{text recdef_cong}, and @{text |
|
678 |
recdef_wf} hints refer to auxiliary rules to be used in the internal |
|
679 |
automated proof process of TFL. Additional @{syntax clasimpmod} |
|
42930 | 680 |
declarations may be given to tune the context of the Simplifier |
681 |
(cf.\ \secref{sec:simplifier}) and Classical reasoner (cf.\ |
|
682 |
\secref{sec:classical}). |
|
42908 | 683 |
|
684 |
\end{description} |
|
685 |
||
686 |
\medskip Hints for @{command (HOL) "recdef"} may be also declared |
|
687 |
globally, using the following attributes. |
|
688 |
||
689 |
\begin{matharray}{rcl} |
|
690 |
@{attribute_def (HOL) recdef_simp} & : & @{text attribute} \\ |
|
691 |
@{attribute_def (HOL) recdef_cong} & : & @{text attribute} \\ |
|
692 |
@{attribute_def (HOL) recdef_wf} & : & @{text attribute} \\ |
|
693 |
\end{matharray} |
|
694 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
695 |
@{rail \<open> |
42908 | 696 |
(@@{attribute (HOL) recdef_simp} | @@{attribute (HOL) recdef_cong} | |
697 |
@@{attribute (HOL) recdef_wf}) (() | 'add' | 'del') |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
698 |
\<close>} |
58618 | 699 |
\<close> |
700 |
||
701 |
||
60657 | 702 |
section \<open>Adhoc overloading of constants\<close> |
703 |
||
704 |
text \<open> |
|
705 |
\begin{tabular}{rcll} |
|
706 |
@{command_def "adhoc_overloading"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
707 |
@{command_def "no_adhoc_overloading"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
708 |
@{attribute_def "show_variants"} & : & @{text "attribute"} & default @{text false} \\ |
|
709 |
\end{tabular} |
|
710 |
||
711 |
\medskip |
|
712 |
||
713 |
Adhoc overloading allows to overload a constant depending on |
|
714 |
its type. Typically this involves the introduction of an |
|
715 |
uninterpreted constant (used for input and output) and the addition |
|
716 |
of some variants (used internally). For examples see |
|
717 |
@{file "~~/src/HOL/ex/Adhoc_Overloading_Examples.thy"} and |
|
718 |
@{file "~~/src/HOL/Library/Monad_Syntax.thy"}. |
|
719 |
||
720 |
@{rail \<open> |
|
721 |
(@@{command adhoc_overloading} | @@{command no_adhoc_overloading}) |
|
722 |
(@{syntax nameref} (@{syntax term} + ) + @'and') |
|
723 |
\<close>} |
|
724 |
||
725 |
\begin{description} |
|
726 |
||
727 |
\item @{command "adhoc_overloading"}~@{text "c v\<^sub>1 ... v\<^sub>n"} |
|
728 |
associates variants with an existing constant. |
|
729 |
||
730 |
\item @{command "no_adhoc_overloading"} is similar to |
|
731 |
@{command "adhoc_overloading"}, but removes the specified variants |
|
732 |
from the present context. |
|
733 |
||
734 |
\item @{attribute "show_variants"} controls printing of variants |
|
735 |
of overloaded constants. If enabled, the internally used variants |
|
736 |
are printed instead of their respective overloaded constants. This |
|
737 |
is occasionally useful to check whether the system agrees with a |
|
738 |
user's expectations about derived variants. |
|
739 |
||
740 |
\end{description} |
|
741 |
\<close> |
|
742 |
||
743 |
||
744 |
section \<open>Definition by specification \label{sec:hol-specification}\<close> |
|
745 |
||
746 |
text \<open> |
|
747 |
\begin{matharray}{rcl} |
|
748 |
@{command_def (HOL) "specification"} & : & @{text "theory \<rightarrow> proof(prove)"} \\ |
|
749 |
\end{matharray} |
|
750 |
||
751 |
@{rail \<open> |
|
752 |
@@{command (HOL) specification} '(' (decl +) ')' \<newline> |
|
753 |
(@{syntax thmdecl}? @{syntax prop} +) |
|
754 |
; |
|
755 |
decl: (@{syntax name} ':')? @{syntax term} ('(' @'overloaded' ')')? |
|
756 |
\<close>} |
|
757 |
||
758 |
\begin{description} |
|
759 |
||
760 |
\item @{command (HOL) "specification"}~@{text "decls \<phi>"} sets up a |
|
761 |
goal stating the existence of terms with the properties specified to |
|
762 |
hold for the constants given in @{text decls}. After finishing the |
|
763 |
proof, the theory will be augmented with definitions for the given |
|
764 |
constants, as well as with theorems stating the properties for these |
|
765 |
constants. |
|
766 |
||
767 |
@{text decl} declares a constant to be defined by the |
|
768 |
specification given. The definition for the constant @{text c} is |
|
769 |
bound to the name @{text c_def} unless a theorem name is given in |
|
770 |
the declaration. Overloaded constants should be declared as such. |
|
771 |
||
772 |
\end{description} |
|
773 |
\<close> |
|
774 |
||
775 |
||
58618 | 776 |
section \<open>Old-style datatypes \label{sec:hol-datatype}\<close> |
777 |
||
778 |
text \<open> |
|
42908 | 779 |
\begin{matharray}{rcl} |
58305
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
blanchet
parents:
58100
diff
changeset
|
780 |
@{command_def (HOL) "old_datatype"} & : & @{text "theory \<rightarrow> theory"} \\ |
58306
117ba6cbe414
renamed 'rep_datatype' to 'old_rep_datatype' (HOL)
blanchet
parents:
58305
diff
changeset
|
781 |
@{command_def (HOL) "old_rep_datatype"} & : & @{text "theory \<rightarrow> proof(prove)"} \\ |
42908 | 782 |
\end{matharray} |
783 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
784 |
@{rail \<open> |
58305
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
blanchet
parents:
58100
diff
changeset
|
785 |
@@{command (HOL) old_datatype} (spec + @'and') |
42908 | 786 |
; |
58306
117ba6cbe414
renamed 'rep_datatype' to 'old_rep_datatype' (HOL)
blanchet
parents:
58305
diff
changeset
|
787 |
@@{command (HOL) old_rep_datatype} ('(' (@{syntax name} +) ')')? (@{syntax term} +) |
42908 | 788 |
; |
789 |
||
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45768
diff
changeset
|
790 |
spec: @{syntax typespec_sorts} @{syntax mixfix}? '=' (cons + '|') |
42908 | 791 |
; |
792 |
cons: @{syntax name} (@{syntax type} * ) @{syntax mixfix}? |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
793 |
\<close>} |
42908 | 794 |
|
795 |
\begin{description} |
|
796 |
||
58305
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
blanchet
parents:
58100
diff
changeset
|
797 |
\item @{command (HOL) "old_datatype"} defines old-style inductive |
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
blanchet
parents:
58100
diff
changeset
|
798 |
datatypes in HOL. |
42908 | 799 |
|
58306
117ba6cbe414
renamed 'rep_datatype' to 'old_rep_datatype' (HOL)
blanchet
parents:
58305
diff
changeset
|
800 |
\item @{command (HOL) "old_rep_datatype"} represents existing types as |
58305
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
blanchet
parents:
58100
diff
changeset
|
801 |
old-style datatypes. |
42908 | 802 |
|
803 |
\end{description} |
|
804 |
||
58305
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
blanchet
parents:
58100
diff
changeset
|
805 |
These commands are mostly obsolete; @{command (HOL) "datatype"} |
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
blanchet
parents:
58100
diff
changeset
|
806 |
should be used instead. |
42908 | 807 |
|
58552 | 808 |
See @{cite "isabelle-HOL"} for more details on datatypes, but beware of |
42908 | 809 |
the old-style theory syntax being used there! Apart from proper |
810 |
proof methods for case-analysis and induction, there are also |
|
811 |
emulations of ML tactics @{method (HOL) case_tac} and @{method (HOL) |
|
812 |
induct_tac} available, see \secref{sec:hol-induct-tac}; these admit |
|
813 |
to refer directly to the internal structure of subgoals (including |
|
814 |
internally bound parameters). |
|
58618 | 815 |
\<close> |
816 |
||
817 |
||
818 |
subsubsection \<open>Examples\<close> |
|
819 |
||
60654 | 820 |
text \<open>We define a type of finite sequences, with slightly different names |
821 |
than the existing @{typ "'a list"} that is already in @{theory Main}:\<close> |
|
42910
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
822 |
|
59905 | 823 |
(*<*)experiment begin(*>*) |
58310 | 824 |
datatype 'a seq = Empty | Seq 'a "'a seq" |
42910
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
825 |
|
58618 | 826 |
text \<open>We can now prove some simple lemma by structural induction:\<close> |
42910
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
827 |
|
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
828 |
lemma "Seq x xs \<noteq> xs" |
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
829 |
proof (induct xs arbitrary: x) |
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
830 |
case Empty |
58618 | 831 |
txt \<open>This case can be proved using the simplifier: the freeness |
42910
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
832 |
properties of the datatype are already declared as @{attribute |
58618 | 833 |
simp} rules.\<close> |
42910
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
834 |
show "Seq x Empty \<noteq> Empty" |
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
835 |
by simp |
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
836 |
next |
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
837 |
case (Seq y ys) |
58618 | 838 |
txt \<open>The step case is proved similarly.\<close> |
42910
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
839 |
show "Seq x (Seq y ys) \<noteq> Seq y ys" |
58618 | 840 |
using \<open>Seq y ys \<noteq> ys\<close> by simp |
42910
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
841 |
qed |
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
842 |
|
58618 | 843 |
text \<open>Here is a more succinct version of the same proof:\<close> |
42910
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
844 |
|
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
845 |
lemma "Seq x xs \<noteq> xs" |
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
846 |
by (induct xs arbitrary: x) simp_all |
59905 | 847 |
(*<*)end(*>*) |
42910
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
848 |
|
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
wenzelm
parents:
42909
diff
changeset
|
849 |
|
58618 | 850 |
section \<open>Records \label{sec:hol-record}\<close> |
851 |
||
852 |
text \<open> |
|
26849 | 853 |
In principle, records merely generalize the concept of tuples, where |
854 |
components may be addressed by labels instead of just position. The |
|
855 |
logical infrastructure of records in Isabelle/HOL is slightly more |
|
856 |
advanced, though, supporting truly extensible record schemes. This |
|
857 |
admits operations that are polymorphic with respect to record |
|
858 |
extension, yielding ``object-oriented'' effects like (single) |
|
58552 | 859 |
inheritance. See also @{cite "NaraschewskiW-TPHOLs98"} for more |
26849 | 860 |
details on object-oriented verification and record subtyping in HOL. |
58618 | 861 |
\<close> |
862 |
||
863 |
||
864 |
subsection \<open>Basic concepts\<close> |
|
865 |
||
866 |
text \<open> |
|
26849 | 867 |
Isabelle/HOL supports both \emph{fixed} and \emph{schematic} records |
868 |
at the level of terms and types. The notation is as follows: |
|
869 |
||
870 |
\begin{center} |
|
871 |
\begin{tabular}{l|l|l} |
|
872 |
& record terms & record types \\ \hline |
|
873 |
fixed & @{text "\<lparr>x = a, y = b\<rparr>"} & @{text "\<lparr>x :: A, y :: B\<rparr>"} \\ |
|
874 |
schematic & @{text "\<lparr>x = a, y = b, \<dots> = m\<rparr>"} & |
|
875 |
@{text "\<lparr>x :: A, y :: B, \<dots> :: M\<rparr>"} \\ |
|
876 |
\end{tabular} |
|
877 |
\end{center} |
|
878 |
||
879 |
\noindent The ASCII representation of @{text "\<lparr>x = a\<rparr>"} is @{text |
|
880 |
"(| x = a |)"}. |
|
881 |
||
882 |
A fixed record @{text "\<lparr>x = a, y = b\<rparr>"} has field @{text x} of value |
|
883 |
@{text a} and field @{text y} of value @{text b}. The corresponding |
|
884 |
type is @{text "\<lparr>x :: A, y :: B\<rparr>"}, assuming that @{text "a :: A"} |
|
885 |
and @{text "b :: B"}. |
|
886 |
||
887 |
A record scheme like @{text "\<lparr>x = a, y = b, \<dots> = m\<rparr>"} contains fields |
|
888 |
@{text x} and @{text y} as before, but also possibly further fields |
|
889 |
as indicated by the ``@{text "\<dots>"}'' notation (which is actually part |
|
890 |
of the syntax). The improper field ``@{text "\<dots>"}'' of a record |
|
891 |
scheme is called the \emph{more part}. Logically it is just a free |
|
892 |
variable, which is occasionally referred to as ``row variable'' in |
|
893 |
the literature. The more part of a record scheme may be |
|
894 |
instantiated by zero or more further components. For example, the |
|
895 |
previous scheme may get instantiated to @{text "\<lparr>x = a, y = b, z = |
|
26852 | 896 |
c, \<dots> = m'\<rparr>"}, where @{text m'} refers to a different more part. |
26849 | 897 |
Fixed records are special instances of record schemes, where |
898 |
``@{text "\<dots>"}'' is properly terminated by the @{text "() :: unit"} |
|
899 |
element. In fact, @{text "\<lparr>x = a, y = b\<rparr>"} is just an abbreviation |
|
900 |
for @{text "\<lparr>x = a, y = b, \<dots> = ()\<rparr>"}. |
|
42123 | 901 |
|
26849 | 902 |
\medskip Two key observations make extensible records in a simply |
903 |
typed language like HOL work out: |
|
904 |
||
905 |
\begin{enumerate} |
|
906 |
||
907 |
\item the more part is internalized, as a free term or type |
|
908 |
variable, |
|
909 |
||
26852 | 910 |
\item field names are externalized, they cannot be accessed within |
911 |
the logic as first-class values. |
|
26849 | 912 |
|
913 |
\end{enumerate} |
|
914 |
||
915 |
\medskip In Isabelle/HOL record types have to be defined explicitly, |
|
916 |
fixing their field names and types, and their (optional) parent |
|
917 |
record. Afterwards, records may be formed using above syntax, while |
|
918 |
obeying the canonical order of fields as given by their declaration. |
|
919 |
The record package provides several standard operations like |
|
920 |
selectors and updates. The common setup for various generic proof |
|
921 |
tools enable succinct reasoning patterns. See also the Isabelle/HOL |
|
58552 | 922 |
tutorial @{cite "isabelle-hol-book"} for further instructions on using |
26849 | 923 |
records in practice. |
58618 | 924 |
\<close> |
925 |
||
926 |
||
927 |
subsection \<open>Record specifications\<close> |
|
928 |
||
929 |
text \<open> |
|
26849 | 930 |
\begin{matharray}{rcl} |
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
931 |
@{command_def (HOL) "record"} & : & @{text "theory \<rightarrow> theory"} \\ |
26849 | 932 |
\end{matharray} |
933 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
934 |
@{rail \<open> |
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
935 |
@@{command (HOL) record} @{syntax typespec_sorts} '=' \<newline> |
46494
ea2ae63336f3
clarified outer syntax "constdecl", which is only local to some rail diagrams;
wenzelm
parents:
46457
diff
changeset
|
936 |
(@{syntax type} '+')? (constdecl +) |
ea2ae63336f3
clarified outer syntax "constdecl", which is only local to some rail diagrams;
wenzelm
parents:
46457
diff
changeset
|
937 |
; |
ea2ae63336f3
clarified outer syntax "constdecl", which is only local to some rail diagrams;
wenzelm
parents:
46457
diff
changeset
|
938 |
constdecl: @{syntax name} '::' @{syntax type} @{syntax mixfix}? |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
939 |
\<close>} |
26849 | 940 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
941 |
\begin{description} |
26849 | 942 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
943 |
\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
|
944 |
\<dots> c\<^sub>n :: \<sigma>\<^sub>n"} defines extensible record type @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m) t"}, |
26849 | 945 |
derived from the optional parent record @{text "\<tau>"} by adding new |
946 |
field components @{text "c\<^sub>i :: \<sigma>\<^sub>i"} etc. |
|
947 |
||
948 |
The type variables of @{text "\<tau>"} and @{text "\<sigma>\<^sub>i"} need to be |
|
949 |
covered by the (distinct) parameters @{text "\<alpha>\<^sub>1, \<dots>, |
|
950 |
\<alpha>\<^sub>m"}. Type constructor @{text t} has to be new, while @{text |
|
951 |
\<tau>} needs to specify an instance of an existing record type. At |
|
952 |
least one new field @{text "c\<^sub>i"} has to be specified. |
|
953 |
Basically, field names need to belong to a unique record. This is |
|
954 |
not a real restriction in practice, since fields are qualified by |
|
955 |
the record name internally. |
|
956 |
||
957 |
The parent record specification @{text \<tau>} is optional; if omitted |
|
958 |
@{text t} becomes a root record. The hierarchy of all records |
|
959 |
declared within a theory context forms a forest structure, i.e.\ a |
|
960 |
set of trees starting with a root record each. There is no way to |
|
961 |
merge multiple parent records! |
|
962 |
||
963 |
For convenience, @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m) t"} is made a |
|
964 |
type abbreviation for the fixed record type @{text "\<lparr>c\<^sub>1 :: |
|
965 |
\<sigma>\<^sub>1, \<dots>, c\<^sub>n :: \<sigma>\<^sub>n\<rparr>"}, likewise is @{text |
|
966 |
"(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m, \<zeta>) t_scheme"} made an abbreviation for |
|
967 |
@{text "\<lparr>c\<^sub>1 :: \<sigma>\<^sub>1, \<dots>, c\<^sub>n :: \<sigma>\<^sub>n, \<dots> :: |
|
968 |
\<zeta>\<rparr>"}. |
|
969 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
970 |
\end{description} |
58618 | 971 |
\<close> |
972 |
||
973 |
||
974 |
subsection \<open>Record operations\<close> |
|
975 |
||
60654 | 976 |
text \<open>Any record definition of the form presented above produces certain |
977 |
standard operations. Selectors and updates are provided for any field, |
|
978 |
including the improper one ``@{text more}''. There are also cumulative |
|
979 |
record constructor functions. To simplify the presentation below, we |
|
980 |
assume for now that @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m) t"} is a root record with fields |
|
981 |
@{text "c\<^sub>1 :: \<sigma>\<^sub>1, \<dots>, c\<^sub>n :: \<sigma>\<^sub>n"}. |
|
982 |
||
983 |
\medskip \textbf{Selectors} and \textbf{updates} are available for any |
|
984 |
field (including ``@{text more}''): |
|
26849 | 985 |
|
986 |
\begin{matharray}{lll} |
|
26852 | 987 |
@{text "c\<^sub>i"} & @{text "::"} & @{text "\<lparr>\<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> \<sigma>\<^sub>i"} \\ |
988 |
@{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 | 989 |
\end{matharray} |
990 |
||
60654 | 991 |
There is special syntax for application of updates: @{text "r\<lparr>x := a\<rparr>"} |
992 |
abbreviates term @{text "x_update a r"}. Further notation for repeated |
|
993 |
updates is also available: @{text "r\<lparr>x := a\<rparr>\<lparr>y := b\<rparr>\<lparr>z := c\<rparr>"} may be |
|
994 |
written @{text "r\<lparr>x := a, y := b, z := c\<rparr>"}. Note that because of postfix |
|
995 |
notation the order of fields shown here is reverse than in the actual |
|
996 |
term. Since repeated updates are just function applications, fields may be |
|
997 |
freely permuted in @{text "\<lparr>x := a, y := b, z := c\<rparr>"}, as far as logical |
|
998 |
equality is concerned. Thus commutativity of independent updates can be |
|
999 |
proven within the logic for any two fields, but not as a general theorem. |
|
26849 | 1000 |
|
1001 |
\medskip The \textbf{make} operation provides a cumulative record |
|
1002 |
constructor function: |
|
1003 |
||
1004 |
\begin{matharray}{lll} |
|
26852 | 1005 |
@{text "t.make"} & @{text "::"} & @{text "\<sigma>\<^sub>1 \<Rightarrow> \<dots> \<sigma>\<^sub>n \<Rightarrow> \<lparr>\<^vec>c :: \<^vec>\<sigma>\<rparr>"} \\ |
26849 | 1006 |
\end{matharray} |
1007 |
||
60654 | 1008 |
\medskip We now reconsider the case of non-root records, which are derived |
1009 |
of some parent. In general, the latter may depend on another parent as |
|
1010 |
well, resulting in a list of \emph{ancestor records}. Appending the lists |
|
1011 |
of fields of all ancestors results in a certain field prefix. The record |
|
1012 |
package automatically takes care of this by lifting operations over this |
|
1013 |
context of ancestor fields. Assuming that @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m) t"} has |
|
1014 |
ancestor fields @{text "b\<^sub>1 :: \<rho>\<^sub>1, \<dots>, b\<^sub>k :: \<rho>\<^sub>k"}, the above record |
|
1015 |
operations will get the following types: |
|
26849 | 1016 |
|
26852 | 1017 |
\medskip |
1018 |
\begin{tabular}{lll} |
|
1019 |
@{text "c\<^sub>i"} & @{text "::"} & @{text "\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> \<sigma>\<^sub>i"} \\ |
|
42123 | 1020 |
@{text "c\<^sub>i_update"} & @{text "::"} & @{text "\<sigma>\<^sub>i \<Rightarrow> |
26852 | 1021 |
\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> |
1022 |
\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr>"} \\ |
|
1023 |
@{text "t.make"} & @{text "::"} & @{text "\<rho>\<^sub>1 \<Rightarrow> \<dots> \<rho>\<^sub>k \<Rightarrow> \<sigma>\<^sub>1 \<Rightarrow> \<dots> \<sigma>\<^sub>n \<Rightarrow> |
|
1024 |
\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>\<rparr>"} \\ |
|
1025 |
\end{tabular} |
|
1026 |
\medskip |
|
26849 | 1027 |
|
26852 | 1028 |
\noindent Some further operations address the extension aspect of a |
60654 | 1029 |
derived record scheme specifically: @{text "t.fields"} produces a record |
1030 |
fragment consisting of exactly the new fields introduced here (the result |
|
1031 |
may serve as a more part elsewhere); @{text "t.extend"} takes a fixed |
|
1032 |
record and adds a given more part; @{text "t.truncate"} restricts a record |
|
1033 |
scheme to a fixed record. |
|
26849 | 1034 |
|
26852 | 1035 |
\medskip |
1036 |
\begin{tabular}{lll} |
|
1037 |
@{text "t.fields"} & @{text "::"} & @{text "\<sigma>\<^sub>1 \<Rightarrow> \<dots> \<sigma>\<^sub>n \<Rightarrow> \<lparr>\<^vec>c :: \<^vec>\<sigma>\<rparr>"} \\ |
|
1038 |
@{text "t.extend"} & @{text "::"} & @{text "\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>\<rparr> \<Rightarrow> |
|
1039 |
\<zeta> \<Rightarrow> \<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr>"} \\ |
|
1040 |
@{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>"} \\ |
|
1041 |
\end{tabular} |
|
1042 |
\medskip |
|
26849 | 1043 |
|
60654 | 1044 |
\noindent Note that @{text "t.make"} and @{text "t.fields"} coincide for |
1045 |
root records. |
|
58618 | 1046 |
\<close> |
1047 |
||
1048 |
||
1049 |
subsection \<open>Derived rules and proof tools\<close> |
|
1050 |
||
1051 |
text \<open> |
|
26849 | 1052 |
The record package proves several results internally, declaring |
1053 |
these facts to appropriate proof tools. This enables users to |
|
1054 |
reason about record structures quite conveniently. Assume that |
|
1055 |
@{text t} is a record type as specified above. |
|
1056 |
||
1057 |
\begin{enumerate} |
|
42123 | 1058 |
|
60654 | 1059 |
\item Standard conversions for selectors or updates applied to record |
1060 |
constructor terms are made part of the default Simplifier context; thus |
|
1061 |
proofs by reduction of basic operations merely require the @{method simp} |
|
1062 |
method without further arguments. These rules are available as @{text |
|
1063 |
"t.simps"}, too. |
|
1064 |
||
1065 |
\item Selectors applied to updated records are automatically reduced by an |
|
1066 |
internal simplification procedure, which is also part of the standard |
|
1067 |
Simplifier setup. |
|
1068 |
||
1069 |
\item Inject equations of a form analogous to @{prop "(x, y) = (x', y') \<equiv> |
|
1070 |
x = x' \<and> y = y'"} are declared to the Simplifier and Classical Reasoner as |
|
1071 |
@{attribute iff} rules. These rules are available as @{text "t.iffs"}. |
|
1072 |
||
1073 |
\item The introduction rule for record equality analogous to @{text "x r = |
|
1074 |
x r' \<Longrightarrow> y r = y r' \<dots> \<Longrightarrow> r = r'"} is declared to the Simplifier, and as the |
|
1075 |
basic rule context as ``@{attribute intro}@{text "?"}''. The rule is |
|
1076 |
called @{text "t.equality"}. |
|
26849 | 1077 |
|
1078 |
\item Representations of arbitrary record expressions as canonical |
|
1079 |
constructor terms are provided both in @{method cases} and @{method |
|
1080 |
induct} format (cf.\ the generic proof methods of the same name, |
|
60654 | 1081 |
\secref{sec:cases-induct}). Several variations are available, for fixed |
1082 |
records, record schemes, more parts etc. |
|
1083 |
||
1084 |
The generic proof methods are sufficiently smart to pick the most sensible |
|
1085 |
rule according to the type of the indicated record expression: users just |
|
1086 |
need to apply something like ``@{text "(cases r)"}'' to a certain proof |
|
1087 |
problem. |
|
1088 |
||
1089 |
\item The derived record operations @{text "t.make"}, @{text "t.fields"}, |
|
1090 |
@{text "t.extend"}, @{text "t.truncate"} are \emph{not} treated |
|
1091 |
automatically, but usually need to be expanded by hand, using the |
|
1092 |
collective fact @{text "t.defs"}. |
|
26849 | 1093 |
|
1094 |
\end{enumerate} |
|
58618 | 1095 |
\<close> |
1096 |
||
1097 |
||
1098 |
subsubsection \<open>Examples\<close> |
|
1099 |
||
1100 |
text \<open>See @{file "~~/src/HOL/ex/Records.thy"}, for example.\<close> |
|
1101 |
||
60654 | 1102 |
|
58618 | 1103 |
section \<open>Typedef axiomatization \label{sec:hol-typedef}\<close> |
1104 |
||
1105 |
text \<open> |
|
46280 | 1106 |
\begin{matharray}{rcl} |
1107 |
@{command_def (HOL) "typedef"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\ |
|
1108 |
\end{matharray} |
|
1109 |
||
1110 |
A Gordon/HOL-style type definition is a certain axiom scheme that |
|
1111 |
identifies a new type with a subset of an existing type. More |
|
42908 | 1112 |
precisely, the new type is defined by exhibiting an existing type |
1113 |
@{text \<tau>}, a set @{text "A :: \<tau> set"}, and a theorem that proves |
|
1114 |
@{prop "\<exists>x. x \<in> A"}. Thus @{text A} is a non-empty subset of @{text |
|
1115 |
\<tau>}, and the new type denotes this subset. New functions are |
|
1116 |
postulated that establish an isomorphism between the new type and |
|
1117 |
the subset. In general, the type @{text \<tau>} may involve type |
|
1118 |
variables @{text "\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n"} which means that the type definition |
|
1119 |
produces a type constructor @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"} depending on |
|
1120 |
those type arguments. |
|
1121 |
||
57480
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1122 |
The axiomatization can be considered a ``definition'' in the sense of the |
58552 | 1123 |
particular set-theoretic interpretation of HOL @{cite pitts93}, where the |
57480
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1124 |
universe of types is required to be downwards-closed wrt.\ arbitrary |
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1125 |
non-empty subsets. Thus genuinely new types introduced by @{command |
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1126 |
"typedef"} stay within the range of HOL models by construction. |
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1127 |
|
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1128 |
In contrast, the command @{command_ref type_synonym} from Isabelle/Pure |
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1129 |
merely introduces syntactic abbreviations, without any logical |
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1130 |
significance. Thus it is more faithful to the idea of a genuine type |
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1131 |
definition, but less powerful in practice. |
47859 | 1132 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1133 |
@{rail \<open> |
49836
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
wenzelm
parents:
49834
diff
changeset
|
1134 |
@@{command (HOL) typedef} abs_type '=' rep_set |
26849 | 1135 |
; |
42908 | 1136 |
abs_type: @{syntax typespec_sorts} @{syntax mixfix}? |
1137 |
; |
|
1138 |
rep_set: @{syntax term} (@'morphisms' @{syntax name} @{syntax name})? |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1139 |
\<close>} |
26849 | 1140 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1141 |
\begin{description} |
26849 | 1142 |
|
57480
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1143 |
\item @{command (HOL) "typedef"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t = A"} produces an |
57487 | 1144 |
axiomatization (\secref{sec:axiomatizations}) for a type definition in the |
57480
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1145 |
background theory of the current context, depending on a non-emptiness |
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1146 |
result of the set @{text A} that needs to be proven here. The set @{text |
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1147 |
A} may contain type variables @{text "\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n"} as specified on the |
d256f49b4799
clarified "axiomatization" -- minor rewording of this delicate concept;
wenzelm
parents:
56929
diff
changeset
|
1148 |
LHS, but no term variables. |
42908 | 1149 |
|
1150 |
Even though a local theory specification, the newly introduced type |
|
1151 |
constructor cannot depend on parameters or assumptions of the |
|
1152 |
context: this is structurally impossible in HOL. In contrast, the |
|
1153 |
non-emptiness proof may use local assumptions in unusual situations, |
|
1154 |
which could result in different interpretations in target contexts: |
|
1155 |
the meaning of the bijection between the representing set @{text A} |
|
1156 |
and the new type @{text t} may then change in different application |
|
1157 |
contexts. |
|
1158 |
||
49836
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
wenzelm
parents:
49834
diff
changeset
|
1159 |
For @{command (HOL) "typedef"}~@{text "t = A"} the newly introduced |
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
wenzelm
parents:
49834
diff
changeset
|
1160 |
type @{text t} is accompanied by a pair of morphisms to relate it to |
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
wenzelm
parents:
49834
diff
changeset
|
1161 |
the representing set over the old type. By default, the injection |
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
wenzelm
parents:
49834
diff
changeset
|
1162 |
from type to set is called @{text Rep_t} and its inverse @{text |
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
wenzelm
parents:
49834
diff
changeset
|
1163 |
Abs_t}: An explicit @{keyword (HOL) "morphisms"} specification |
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
wenzelm
parents:
49834
diff
changeset
|
1164 |
allows to provide alternative names. |
26849 | 1165 |
|
42908 | 1166 |
The core axiomatization uses the locale predicate @{const |
1167 |
type_definition} as defined in Isabelle/HOL. Various basic |
|
1168 |
consequences of that are instantiated accordingly, re-using the |
|
1169 |
locale facts with names derived from the new type constructor. Thus |
|
1170 |
the generic @{thm type_definition.Rep} is turned into the specific |
|
1171 |
@{text "Rep_t"}, for example. |
|
1172 |
||
1173 |
Theorems @{thm type_definition.Rep}, @{thm |
|
1174 |
type_definition.Rep_inverse}, and @{thm type_definition.Abs_inverse} |
|
1175 |
provide the most basic characterization as a corresponding |
|
1176 |
injection/surjection pair (in both directions). The derived rules |
|
1177 |
@{thm type_definition.Rep_inject} and @{thm |
|
1178 |
type_definition.Abs_inject} provide a more convenient version of |
|
1179 |
injectivity, suitable for automated proof tools (e.g.\ in |
|
1180 |
declarations involving @{attribute simp} or @{attribute iff}). |
|
1181 |
Furthermore, the rules @{thm type_definition.Rep_cases}~/ @{thm |
|
1182 |
type_definition.Rep_induct}, and @{thm type_definition.Abs_cases}~/ |
|
1183 |
@{thm type_definition.Abs_induct} provide alternative views on |
|
1184 |
surjectivity. These rules are already declared as set or type rules |
|
1185 |
for the generic @{method cases} and @{method induct} methods, |
|
1186 |
respectively. |
|
1187 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
1188 |
\end{description} |
58618 | 1189 |
\<close> |
1190 |
||
59905 | 1191 |
|
58618 | 1192 |
subsubsection \<open>Examples\<close> |
1193 |
||
1194 |
text \<open>Type definitions permit the introduction of abstract data |
|
42908 | 1195 |
types in a safe way, namely by providing models based on already |
1196 |
existing types. Given some abstract axiomatic description @{text P} |
|
1197 |
of a type, this involves two steps: |
|
1198 |
||
1199 |
\begin{enumerate} |
|
1200 |
||
1201 |
\item Find an appropriate type @{text \<tau>} and subset @{text A} which |
|
1202 |
has the desired properties @{text P}, and make a type definition |
|
1203 |
based on this representation. |
|
1204 |
||
1205 |
\item Prove that @{text P} holds for @{text \<tau>} by lifting @{text P} |
|
1206 |
from the representation. |
|
26849 | 1207 |
|
42908 | 1208 |
\end{enumerate} |
1209 |
||
1210 |
You can later forget about the representation and work solely in |
|
1211 |
terms of the abstract properties @{text P}. |
|
1212 |
||
1213 |
\medskip The following trivial example pulls a three-element type |
|
58618 | 1214 |
into existence within the formal logical environment of HOL.\<close> |
42908 | 1215 |
|
59905 | 1216 |
(*<*)experiment begin(*>*) |
49834 | 1217 |
typedef three = "{(True, True), (True, False), (False, True)}" |
42908 | 1218 |
by blast |
1219 |
||
1220 |
definition "One = Abs_three (True, True)" |
|
1221 |
definition "Two = Abs_three (True, False)" |
|
1222 |
definition "Three = Abs_three (False, True)" |
|
1223 |
||
1224 |
lemma three_distinct: "One \<noteq> Two" "One \<noteq> Three" "Two \<noteq> Three" |
|
49812
e3945ddcb9aa
eliminated some remaining uses of typedef with implicit set definition;
wenzelm
parents:
48985
diff
changeset
|
1225 |
by (simp_all add: One_def Two_def Three_def Abs_three_inject) |
42908 | 1226 |
|
1227 |
lemma three_cases: |
|
1228 |
fixes x :: three obtains "x = One" | "x = Two" | "x = Three" |
|
49812
e3945ddcb9aa
eliminated some remaining uses of typedef with implicit set definition;
wenzelm
parents:
48985
diff
changeset
|
1229 |
by (cases x) (auto simp: One_def Two_def Three_def Abs_three_inject) |
59905 | 1230 |
(*<*)end(*>*) |
42908 | 1231 |
|
58618 | 1232 |
text \<open>Note that such trivial constructions are better done with |
1233 |
derived specification mechanisms such as @{command datatype}:\<close> |
|
58310 | 1234 |
|
59905 | 1235 |
(*<*)experiment begin(*>*) |
1236 |
datatype three = One | Two | Three |
|
1237 |
(*<*)end(*>*) |
|
42908 | 1238 |
|
58618 | 1239 |
text \<open>This avoids re-doing basic definitions and proofs from the |
1240 |
primitive @{command typedef} above.\<close> |
|
1241 |
||
1242 |
||
1243 |
||
1244 |
section \<open>Functorial structure of types\<close> |
|
1245 |
||
1246 |
text \<open> |
|
41396 | 1247 |
\begin{matharray}{rcl} |
55467
a5c9002bc54d
renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
blanchet
parents:
55372
diff
changeset
|
1248 |
@{command_def (HOL) "functor"} & : & @{text "local_theory \<rightarrow> proof(prove)"} |
41396 | 1249 |
\end{matharray} |
1250 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1251 |
@{rail \<open> |
55467
a5c9002bc54d
renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
blanchet
parents:
55372
diff
changeset
|
1252 |
@@{command (HOL) functor} (@{syntax name} ':')? @{syntax term} |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1253 |
\<close>} |
41396 | 1254 |
|
1255 |
\begin{description} |
|
1256 |
||
60654 | 1257 |
\item @{command (HOL) "functor"}~@{text "prefix: m"} allows to prove and |
1258 |
register properties about the functorial structure of type constructors. |
|
1259 |
These properties then can be used by other packages to deal with those |
|
1260 |
type constructors in certain type constructions. Characteristic theorems |
|
1261 |
are noted in the current local theory. By default, they are prefixed with |
|
1262 |
the base name of the type constructor, an explicit prefix can be given |
|
1263 |
alternatively. |
|
41396 | 1264 |
|
1265 |
The given term @{text "m"} is considered as \emph{mapper} for the |
|
60654 | 1266 |
corresponding type constructor and must conform to the following type |
1267 |
pattern: |
|
41396 | 1268 |
|
1269 |
\begin{matharray}{lll} |
|
1270 |
@{text "m"} & @{text "::"} & |
|
53015
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents:
52895
diff
changeset
|
1271 |
@{text "\<sigma>\<^sub>1 \<Rightarrow> \<dots> \<sigma>\<^sub>k \<Rightarrow> (\<^vec>\<alpha>\<^sub>n) t \<Rightarrow> (\<^vec>\<beta>\<^sub>n) t"} \\ |
41396 | 1272 |
\end{matharray} |
1273 |
||
60654 | 1274 |
\noindent where @{text t} is the type constructor, @{text "\<^vec>\<alpha>\<^sub>n"} |
1275 |
and @{text "\<^vec>\<beta>\<^sub>n"} are distinct type variables free in the local |
|
1276 |
theory and @{text "\<sigma>\<^sub>1"}, \ldots, @{text "\<sigma>\<^sub>k"} is a subsequence of @{text |
|
1277 |
"\<alpha>\<^sub>1 \<Rightarrow> \<beta>\<^sub>1"}, @{text "\<beta>\<^sub>1 \<Rightarrow> \<alpha>\<^sub>1"}, \ldots, @{text "\<alpha>\<^sub>n \<Rightarrow> \<beta>\<^sub>n"}, @{text |
|
1278 |
"\<beta>\<^sub>n \<Rightarrow> \<alpha>\<^sub>n"}. |
|
41396 | 1279 |
|
1280 |
\end{description} |
|
58618 | 1281 |
\<close> |
1282 |
||
1283 |
||
60671 | 1284 |
section \<open>Quotient types with lifting and transfer\<close> |
1285 |
||
1286 |
text \<open>The quotient package defines a new quotient type given a raw type and |
|
1287 |
a partial equivalence relation (\secref{sec:quotient-type}). The package |
|
1288 |
also historically includes automation for transporting definitions and |
|
1289 |
theorems (\secref{sec:old-quotient}), but most of this automation was |
|
1290 |
superseded by the Lifting (\secref{sec:lifting}) and Transfer |
|
1291 |
(\secref{sec:transfer}) packages.\<close> |
|
1292 |
||
1293 |
||
1294 |
subsection \<open>Quotient type definition \label{sec:quotient-type}\<close> |
|
58618 | 1295 |
|
1296 |
text \<open> |
|
50109 | 1297 |
\begin{matharray}{rcl} |
1298 |
@{command_def (HOL) "quotient_type"} & : & @{text "local_theory \<rightarrow> proof(prove)"}\\ |
|
1299 |
\end{matharray} |
|
1300 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1301 |
@{rail \<open> |
60658 | 1302 |
@@{command (HOL) quotient_type} @{syntax typespec} @{syntax mixfix}? '=' |
1303 |
quot_type \<newline> quot_morphisms? quot_parametric? |
|
1304 |
; |
|
1305 |
quot_type: @{syntax type} '/' ('partial' ':')? @{syntax term} |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1306 |
; |
60658 | 1307 |
quot_morphisms: @'morphisms' @{syntax name} @{syntax name} |
1308 |
; |
|
1309 |
quot_parametric: @'parametric' @{syntax thmref} |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1310 |
\<close>} |
50109 | 1311 |
|
1312 |
\begin{description} |
|
1313 |
||
60659 | 1314 |
\item @{command (HOL) "quotient_type"} defines a new quotient type @{text |
1315 |
\<tau>}. The injection from a quotient type to a raw type is called @{text |
|
54334
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
kuncar
parents:
54017
diff
changeset
|
1316 |
rep_\<tau>}, its inverse @{text abs_\<tau>} unless explicit @{keyword (HOL) |
60659 | 1317 |
"morphisms"} specification provides alternative names. @{command (HOL) |
1318 |
"quotient_type"} requires the user to prove that the relation is an |
|
1319 |
equivalence relation (predicate @{text equivp}), unless the user specifies |
|
1320 |
explicitly @{text partial} in which case the obligation is @{text |
|
1321 |
part_equivp}. A quotient defined with @{text partial} is weaker in the |
|
1322 |
sense that less things can be proved automatically. |
|
50109 | 1323 |
|
54334
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
kuncar
parents:
54017
diff
changeset
|
1324 |
The command internally proves a Quotient theorem and sets up the Lifting |
60657 | 1325 |
package by the command @{command (HOL) setup_lifting}. Thus the Lifting |
54334
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
kuncar
parents:
54017
diff
changeset
|
1326 |
and Transfer packages can be used also with quotient types defined by |
60659 | 1327 |
@{command (HOL) "quotient_type"} without any extra set-up. The |
1328 |
parametricity theorem for the equivalence relation R can be provided as an |
|
1329 |
extra argument of the command and is passed to the corresponding internal |
|
1330 |
call of @{command (HOL) setup_lifting}. This theorem allows the Lifting |
|
1331 |
package to generate a stronger transfer rule for equality. |
|
60657 | 1332 |
|
54334
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
kuncar
parents:
54017
diff
changeset
|
1333 |
\end{description} |
58618 | 1334 |
\<close> |
1335 |
||
1336 |
||
60671 | 1337 |
subsection \<open>Lifting package \label{sec:lifting}\<close> |
58618 | 1338 |
|
1339 |
text \<open> |
|
60660 | 1340 |
The Lifting package allows users to lift terms of the raw type to the |
1341 |
abstract type, which is a necessary step in building a library for an |
|
1342 |
abstract type. Lifting defines a new constant by combining coercion |
|
60662 | 1343 |
functions (@{term Abs} and @{term Rep}) with the raw term. It also proves |
1344 |
an appropriate transfer rule for the Transfer (\secref{sec:transfer}) |
|
1345 |
package and, if possible, an equation for the code generator. |
|
60660 | 1346 |
|
1347 |
The Lifting package provides two main commands: @{command (HOL) |
|
1348 |
"setup_lifting"} for initializing the package to work with a new type, and |
|
1349 |
@{command (HOL) "lift_definition"} for lifting constants. The Lifting |
|
1350 |
package works with all four kinds of type abstraction: type copies, |
|
1351 |
subtypes, total quotients and partial quotients. |
|
1352 |
||
1353 |
Theoretical background can be found in @{cite |
|
1354 |
"Huffman-Kuncar:2013:lifting_transfer"}. |
|
1355 |
||
60671 | 1356 |
\begin{matharray}{rcl} |
1357 |
@{command_def (HOL) "setup_lifting"} & : & @{text "local_theory \<rightarrow> local_theory"}\\ |
|
1358 |
@{command_def (HOL) "lift_definition"} & : & @{text "local_theory \<rightarrow> proof(prove)"}\\ |
|
1359 |
@{command_def (HOL) "lifting_forget"} & : & @{text "local_theory \<rightarrow> local_theory"}\\ |
|
1360 |
@{command_def (HOL) "lifting_update"} & : & @{text "local_theory \<rightarrow> local_theory"}\\ |
|
1361 |
@{command_def (HOL) "print_quot_maps"} & : & @{text "context \<rightarrow>"}\\ |
|
1362 |
@{command_def (HOL) "print_quotients"} & : & @{text "context \<rightarrow>"}\\ |
|
1363 |
@{attribute_def (HOL) "quot_map"} & : & @{text attribute} \\ |
|
1364 |
@{attribute_def (HOL) "relator_eq_onp"} & : & @{text attribute} \\ |
|
1365 |
@{attribute_def (HOL) "relator_mono"} & : & @{text attribute} \\ |
|
1366 |
@{attribute_def (HOL) "relator_distr"} & : & @{text attribute} \\ |
|
1367 |
@{attribute_def (HOL) "quot_del"} & : & @{text attribute} \\ |
|
1368 |
@{attribute_def (HOL) "lifting_restore"} & : & @{text attribute} \\ |
|
1369 |
\end{matharray} |
|
1370 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1371 |
@{rail \<open> |
59783
00b62aa9f430
tuned syntax diagrams -- no duplication of "target";
wenzelm
parents:
59487
diff
changeset
|
1372 |
@@{command (HOL) setup_lifting} @{syntax thmref} @{syntax thmref}? \<newline> |
00b62aa9f430
tuned syntax diagrams -- no duplication of "target";
wenzelm
parents:
59487
diff
changeset
|
1373 |
(@'parametric' @{syntax thmref})? |
60661 | 1374 |
; |
1375 |
@@{command (HOL) lift_definition} ('(' 'code_dt' ')')? \<newline> |
|
1376 |
@{syntax name} '::' @{syntax type} @{syntax mixfix}? 'is' @{syntax term} \<newline> |
|
1377 |
(@'parametric' (@{syntax thmref}+))? |
|
1378 |
; |
|
59783
00b62aa9f430
tuned syntax diagrams -- no duplication of "target";
wenzelm
parents:
59487
diff
changeset
|
1379 |
@@{command (HOL) lifting_forget} @{syntax nameref} |
60661 | 1380 |
; |
59783
00b62aa9f430
tuned syntax diagrams -- no duplication of "target";
wenzelm
parents:
59487
diff
changeset
|
1381 |
@@{command (HOL) lifting_update} @{syntax nameref} |
60661 | 1382 |
; |
60670 | 1383 |
@@{attribute (HOL) lifting_restore} |
1384 |
@{syntax thmref} (@{syntax thmref} @{syntax thmref})? |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1385 |
\<close>} |
47802 | 1386 |
|
1387 |
\begin{description} |
|
1388 |
||
60660 | 1389 |
\item @{command (HOL) "setup_lifting"} Sets up the Lifting package to work |
1390 |
with a user-defined type. The command supports two modes. The first one is |
|
1391 |
a low-level mode when the user must provide as a first argument of |
|
1392 |
@{command (HOL) "setup_lifting"} a quotient theorem @{term "Quotient R Abs |
|
1393 |
Rep T"}. The package configures a transfer rule for equality, a domain |
|
1394 |
transfer rules and sets up the @{command_def (HOL) "lift_definition"} |
|
1395 |
command to work with the abstract type. An optional theorem @{term "reflp |
|
1396 |
R"}, which certifies that the equivalence relation R is total, can be |
|
1397 |
provided as a second argument. This allows the package to generate |
|
60670 | 1398 |
stronger transfer rules. And finally, the parametricity theorem for @{term |
1399 |
R} can be provided as a third argument. This allows the package to |
|
1400 |
generate a stronger transfer rule for equality. |
|
60660 | 1401 |
|
1402 |
Users generally will not prove the @{text Quotient} theorem manually for |
|
1403 |
new types, as special commands exist to automate the process. |
|
1404 |
||
60670 | 1405 |
\medskip When a new subtype is defined by @{command (HOL) typedef}, |
1406 |
@{command (HOL) "lift_definition"} can be used in its second mode, where |
|
1407 |
only the @{term type_definition} theorem @{term "type_definition Rep Abs |
|
1408 |
A"} is used as an argument of the command. The command internally proves |
|
1409 |
the corresponding @{term Quotient} theorem and registers it with @{command |
|
1410 |
(HOL) setup_lifting} using its first mode. |
|
60660 | 1411 |
|
1412 |
For quotients, the command @{command (HOL) quotient_type} can be used. The |
|
1413 |
command defines a new quotient type and similarly to the previous case, |
|
1414 |
the corresponding Quotient theorem is proved and registered by @{command |
|
1415 |
(HOL) setup_lifting}. |
|
1416 |
||
60670 | 1417 |
\medskip The command @{command (HOL) "setup_lifting"} also sets up the |
1418 |
code generator for the new type. Later on, when a new constant is defined |
|
1419 |
by @{command (HOL) "lift_definition"}, the Lifting package proves and |
|
60660 | 1420 |
registers a code equation (if there is one) for the new constant. |
1421 |
||
1422 |
\item @{command (HOL) "lift_definition"} @{text "f :: \<tau>"} @{keyword (HOL) |
|
1423 |
"is"} @{text t} Defines a new function @{text f} with an abstract type |
|
1424 |
@{text \<tau>} in terms of a corresponding operation @{text t} on a |
|
1425 |
representation type. More formally, if @{text "t :: \<sigma>"}, then the command |
|
1426 |
builds a term @{text "F"} as a corresponding combination of abstraction |
|
1427 |
and representation functions such that @{text "F :: \<sigma> \<Rightarrow> \<tau>" } and defines |
|
60670 | 1428 |
@{text "f \<equiv> F t"}. The term @{text t} does not have to be necessarily a |
1429 |
constant but it can be any term. |
|
1430 |
||
1431 |
The command opens a proof and the user must discharge a respectfulness |
|
1432 |
proof obligation. For a type copy, i.e.\ a typedef with @{text UNIV}, the |
|
1433 |
obligation is discharged automatically. The proof goal is presented in a |
|
1434 |
user-friendly, readable form. A respectfulness theorem in the standard |
|
1435 |
format @{text f.rsp} and a transfer rule @{text f.transfer} for the |
|
1436 |
Transfer package are generated by the package. |
|
60660 | 1437 |
|
1438 |
The user can specify a parametricity theorems for @{text t} after the |
|
1439 |
keyword @{keyword "parametric"}, which allows the command to generate |
|
1440 |
parametric transfer rules for @{text f}. |
|
1441 |
||
1442 |
For each constant defined through trivial quotients (type copies or |
|
1443 |
subtypes) @{text f.rep_eq} is generated. The equation is a code |
|
1444 |
certificate that defines @{text f} using the representation function. |
|
1445 |
||
1446 |
For each constant @{text f.abs_eq} is generated. The equation is |
|
1447 |
unconditional for total quotients. The equation defines @{text f} using |
|
1448 |
the abstraction function. |
|
1449 |
||
60670 | 1450 |
\medskip Integration with [@{attribute code} abstract]: For subtypes |
1451 |
(e.g.\ corresponding to a datatype invariant, such as @{typ "'a dlist"}), |
|
60660 | 1452 |
@{command (HOL) "lift_definition"} uses a code certificate theorem @{text |
1453 |
f.rep_eq} as a code equation. Because of the limitation of the code |
|
1454 |
generator, @{text f.rep_eq} cannot be used as a code equation if the |
|
60670 | 1455 |
subtype occurs inside the result type rather than at the top level (e.g.\ |
1456 |
function returning @{typ "'a dlist option"} vs. @{typ "'a dlist"}). |
|
1457 |
||
1458 |
In this case, an extension of @{command (HOL) "lift_definition"} can be |
|
60660 | 1459 |
invoked by specifying the flag @{text "code_dt"}. This extension enables |
1460 |
code execution through series of internal type and lifting definitions if |
|
1461 |
the return type @{text "\<tau>"} meets the following inductive conditions: |
|
60670 | 1462 |
|
1463 |
\begin{description} |
|
1464 |
||
1465 |
\item @{text "\<tau>"} is a type variable \item @{text "\<tau> = \<tau>\<^sub>1 \<dots> \<tau>\<^sub>n \<kappa>"}, |
|
1466 |
where @{text "\<kappa>"} is an abstract type constructor and @{text "\<tau>\<^sub>1 \<dots> \<tau>\<^sub>n"} |
|
1467 |
do not contain abstract types (i.e.\ @{typ "int dlist"} is allowed whereas |
|
1468 |
@{typ "int dlist dlist"} not) |
|
1469 |
||
1470 |
\item @{text "\<tau> = \<tau>\<^sub>1 \<dots> \<tau>\<^sub>n \<kappa>"}, @{text "\<kappa>"} is a type constructor that |
|
1471 |
was defined as a (co)datatype whose constructor argument types do not |
|
1472 |
contain either non-free datatypes or the function type. |
|
1473 |
||
1474 |
\end{description} |
|
60660 | 1475 |
|
1476 |
Integration with [@{attribute code} equation]: For total quotients, |
|
1477 |
@{command (HOL) "lift_definition"} uses @{text f.abs_eq} as a code |
|
1478 |
equation. |
|
1479 |
||
1480 |
\item @{command (HOL) lifting_forget} and @{command (HOL) lifting_update} |
|
1481 |
These two commands serve for storing and deleting the set-up of the |
|
1482 |
Lifting package and corresponding transfer rules defined by this package. |
|
1483 |
This is useful for hiding of type construction details of an abstract type |
|
1484 |
when the construction is finished but it still allows additions to this |
|
1485 |
construction when this is later necessary. |
|
1486 |
||
1487 |
Whenever the Lifting package is set up with a new abstract type @{text |
|
1488 |
"\<tau>"} by @{command_def (HOL) "lift_definition"}, the package defines a new |
|
1489 |
bundle that is called @{text "\<tau>.lifting"}. This bundle already includes |
|
1490 |
set-up for the Lifting package. The new transfer rules introduced by |
|
1491 |
@{command (HOL) "lift_definition"} can be stored in the bundle by the |
|
1492 |
command @{command (HOL) "lifting_update"} @{text "\<tau>.lifting"}. |
|
1493 |
||
1494 |
The command @{command (HOL) "lifting_forget"} @{text "\<tau>.lifting"} deletes |
|
1495 |
set-up of the Lifting package for @{text \<tau>} and deletes all the transfer |
|
1496 |
rules that were introduced by @{command (HOL) "lift_definition"} using |
|
1497 |
@{text \<tau>} as an abstract type. |
|
1498 |
||
1499 |
The stored set-up in a bundle can be reintroduced by the Isar commands for |
|
1500 |
including a bundle (@{command "include"}, @{keyword "includes"} and |
|
1501 |
@{command "including"}). |
|
54334
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
kuncar
parents:
54017
diff
changeset
|
1502 |
|
53219
ca237b9e4542
use only one data slot; rename print_quotmaps to print_quot_maps; tuned
kuncar
parents:
53015
diff
changeset
|
1503 |
\item @{command (HOL) "print_quot_maps"} prints stored quotient map |
60660 | 1504 |
theorems. |
1505 |
||
1506 |
\item @{command (HOL) "print_quotients"} prints stored quotient theorems. |
|
1507 |
||
1508 |
\item @{attribute (HOL) quot_map} registers a quotient map theorem, a |
|
60672 | 1509 |
theorem showing how to ``lift'' quotients over type constructors. E.g.\ |
60660 | 1510 |
@{term "Quotient R Abs Rep T \<Longrightarrow> Quotient (rel_set R) (image Abs) (image |
1511 |
Rep) (rel_set T)"}. For examples see @{file "~~/src/HOL/Lifting_Set.thy"} |
|
1512 |
or @{file "~~/src/HOL/Lifting.thy"}. This property is proved automatically |
|
1513 |
if the involved type is BNF without dead variables. |
|
1514 |
||
1515 |
\item @{attribute (HOL) relator_eq_onp} registers a theorem that shows |
|
1516 |
that a relator applied to an equality restricted by a predicate @{term P} |
|
60670 | 1517 |
(i.e.\ @{term "eq_onp P"}) is equal to a predicator applied to the @{term |
60660 | 1518 |
P}. The combinator @{const eq_onp} is used for internal encoding of proper |
1519 |
subtypes. Such theorems allows the package to hide @{text eq_onp} from a |
|
1520 |
user in a user-readable form of a respectfulness theorem. For examples see |
|
1521 |
@{file "~~/src/HOL/Lifting_Set.thy"} or @{file "~~/src/HOL/Lifting.thy"}. |
|
1522 |
This property is proved automatically if the involved type is BNF without |
|
1523 |
dead variables. |
|
1524 |
||
1525 |
\item @{attribute (HOL) "relator_mono"} registers a property describing a |
|
60670 | 1526 |
monotonicity of a relator. E.g.\ @{prop "A \<le> B \<Longrightarrow> rel_set A \<le> rel_set B"}. |
60660 | 1527 |
This property is needed for proving a stronger transfer rule in |
1528 |
@{command_def (HOL) "lift_definition"} when a parametricity theorem for |
|
1529 |
the raw term is specified and also for the reflexivity prover. For |
|
1530 |
examples see @{file "~~/src/HOL/Lifting_Set.thy"} or @{file |
|
1531 |
"~~/src/HOL/Lifting.thy"}. This property is proved automatically if the |
|
1532 |
involved type is BNF without dead variables. |
|
1533 |
||
1534 |
\item @{attribute (HOL) "relator_distr"} registers a property describing a |
|
60670 | 1535 |
distributivity of the relation composition and a relator. E.g.\ @{text |
60660 | 1536 |
"rel_set R \<circ>\<circ> rel_set S = rel_set (R \<circ>\<circ> S)"}. This property is needed for |
1537 |
proving a stronger transfer rule in @{command_def (HOL) "lift_definition"} |
|
1538 |
when a parametricity theorem for the raw term is specified. When this |
|
60670 | 1539 |
equality does not hold unconditionally (e.g.\ for the function type), the |
60660 | 1540 |
user can specified each direction separately and also register multiple |
1541 |
theorems with different set of assumptions. This attribute can be used |
|
1542 |
only after the monotonicity property was already registered by @{attribute |
|
1543 |
(HOL) "relator_mono"}. For examples see @{file |
|
1544 |
"~~/src/HOL/Lifting_Set.thy"} or @{file "~~/src/HOL/Lifting.thy"}. This |
|
1545 |
property is proved automatically if the involved type is BNF without dead |
|
1546 |
variables. |
|
50877 | 1547 |
|
1548 |
\item @{attribute (HOL) quot_del} deletes a corresponding Quotient theorem |
|
60660 | 1549 |
from the Lifting infrastructure and thus de-register the corresponding |
1550 |
quotient. This effectively causes that @{command (HOL) lift_definition} |
|
1551 |
will not do any lifting for the corresponding type. This attribute is |
|
1552 |
rather used for low-level manipulation with set-up of the Lifting package |
|
1553 |
because @{command (HOL) lifting_forget} is preferred for normal usage. |
|
1554 |
||
1555 |
\item @{attribute (HOL) lifting_restore} @{text "Quotient_thm pcr_def |
|
1556 |
pcr_cr_eq_thm"} registers the Quotient theorem @{text Quotient_thm} in the |
|
1557 |
Lifting infrastructure and thus sets up lifting for an abstract type |
|
1558 |
@{text \<tau>} (that is defined by @{text Quotient_thm}). Optional theorems |
|
1559 |
@{text pcr_def} and @{text pcr_cr_eq_thm} can be specified to register the |
|
60670 | 1560 |
parametrized correspondence relation for @{text \<tau>}. E.g.\ for @{typ "'a |
60660 | 1561 |
dlist"}, @{text pcr_def} is @{text "pcr_dlist A \<equiv> list_all2 A \<circ>\<circ> |
60672 | 1562 |
cr_dlist"} and @{text pcr_cr_eq_thm} is @{text "pcr_dlist (op =) = (op |
1563 |
=)"}. This attribute is rather used for low-level manipulation with set-up |
|
1564 |
of the Lifting package because using of the bundle @{text \<tau>.lifting} |
|
1565 |
together with the commands @{command (HOL) lifting_forget} and @{command |
|
1566 |
(HOL) lifting_update} is preferred for normal usage. |
|
60660 | 1567 |
|
1568 |
\item Integration with the BNF package @{cite "isabelle-datatypes"}: As |
|
1569 |
already mentioned, the theorems that are registered by the following |
|
1570 |
attributes are proved and registered automatically if the involved type is |
|
1571 |
BNF without dead variables: @{attribute (HOL) quot_map}, @{attribute (HOL) |
|
1572 |
relator_eq_onp}, @{attribute (HOL) "relator_mono"}, @{attribute (HOL) |
|
1573 |
"relator_distr"}. Also the definition of a relator and predicator is |
|
1574 |
provided automatically. Moreover, if the BNF represents a datatype, |
|
1575 |
simplification rules for a predicator are again proved automatically. |
|
60657 | 1576 |
|
47802 | 1577 |
\end{description} |
58618 | 1578 |
\<close> |
1579 |
||
1580 |
||
60671 | 1581 |
subsection \<open>Transfer package \label{sec:transfer}\<close> |
60660 | 1582 |
|
1583 |
text \<open> |
|
1584 |
\begin{matharray}{rcl} |
|
1585 |
@{method_def (HOL) "transfer"} & : & @{text method} \\ |
|
1586 |
@{method_def (HOL) "transfer'"} & : & @{text method} \\ |
|
1587 |
@{method_def (HOL) "transfer_prover"} & : & @{text method} \\ |
|
1588 |
@{attribute_def (HOL) "Transfer.transferred"} & : & @{text attribute} \\ |
|
1589 |
@{attribute_def (HOL) "untransferred"} & : & @{text attribute} \\ |
|
1590 |
@{attribute_def (HOL) "transfer_rule"} & : & @{text attribute} \\ |
|
1591 |
@{attribute_def (HOL) "transfer_domain_rule"} & : & @{text attribute} \\ |
|
1592 |
@{attribute_def (HOL) "relator_eq"} & : & @{text attribute} \\ |
|
1593 |
@{attribute_def (HOL) "relator_domain"} & : & @{text attribute} \\ |
|
1594 |
\end{matharray} |
|
1595 |
||
1596 |
\begin{description} |
|
1597 |
||
1598 |
\item @{method (HOL) "transfer"} method replaces the current subgoal with |
|
1599 |
a logically equivalent one that uses different types and constants. The |
|
1600 |
replacement of types and constants is guided by the database of transfer |
|
1601 |
rules. Goals are generalized over all free variables by default; this is |
|
1602 |
necessary for variables whose types change, but can be overridden for |
|
1603 |
specific variables with e.g. @{text "transfer fixing: x y z"}. |
|
1604 |
||
1605 |
\item @{method (HOL) "transfer'"} is a variant of @{method (HOL) transfer} |
|
1606 |
that allows replacing a subgoal with one that is logically stronger |
|
1607 |
(rather than equivalent). For example, a subgoal involving equality on a |
|
1608 |
quotient type could be replaced with a subgoal involving equality (instead |
|
1609 |
of the corresponding equivalence relation) on the underlying raw type. |
|
1610 |
||
1611 |
\item @{method (HOL) "transfer_prover"} method assists with proving a |
|
1612 |
transfer rule for a new constant, provided the constant is defined in |
|
1613 |
terms of other constants that already have transfer rules. It should be |
|
1614 |
applied after unfolding the constant definitions. |
|
1615 |
||
1616 |
\item @{attribute (HOL) "untransferred"} proves the same equivalent |
|
1617 |
theorem as @{method (HOL) "transfer"} internally does. |
|
1618 |
||
1619 |
\item @{attribute (HOL) Transfer.transferred} works in the opposite |
|
60670 | 1620 |
direction than @{method (HOL) "transfer'"}. E.g.\ given the transfer |
60660 | 1621 |
relation @{text "ZN x n \<equiv> (x = int n)"}, corresponding transfer rules and |
1622 |
the theorem @{text "\<forall>x::int \<in> {0..}. x < x + 1"}, the attribute would |
|
1623 |
prove @{text "\<forall>n::nat. n < n + 1"}. The attribute is still in experimental |
|
1624 |
phase of development. |
|
1625 |
||
1626 |
\item @{attribute (HOL) "transfer_rule"} attribute maintains a collection |
|
1627 |
of transfer rules, which relate constants at two different types. Typical |
|
1628 |
transfer rules may relate different type instances of the same polymorphic |
|
1629 |
constant, or they may relate an operation on a raw type to a corresponding |
|
1630 |
operation on an abstract type (quotient or subtype). For example: |
|
1631 |
||
1632 |
@{text "((A ===> B) ===> list_all2 A ===> list_all2 B) map map"} \\ |
|
1633 |
@{text "(cr_int ===> cr_int ===> cr_int) (\<lambda>(x,y) (u,v). (x+u, y+v)) plus"} |
|
1634 |
||
1635 |
Lemmas involving predicates on relations can also be registered using the |
|
1636 |
same attribute. For example: |
|
1637 |
||
1638 |
@{text "bi_unique A \<Longrightarrow> (list_all2 A ===> op =) distinct distinct"} \\ |
|
1639 |
@{text "\<lbrakk>bi_unique A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (rel_prod A B)"} |
|
1640 |
||
1641 |
Preservation of predicates on relations (@{text "bi_unique, bi_total, |
|
1642 |
right_unique, right_total, left_unique, left_total"}) with the respect to |
|
1643 |
a relator is proved automatically if the involved type is BNF @{cite |
|
1644 |
"isabelle-datatypes"} without dead variables. |
|
1645 |
||
1646 |
\item @{attribute (HOL) "transfer_domain_rule"} attribute maintains a |
|
1647 |
collection of rules, which specify a domain of a transfer relation by a |
|
60670 | 1648 |
predicate. E.g.\ given the transfer relation @{text "ZN x n \<equiv> (x = int |
60660 | 1649 |
n)"}, one can register the following transfer domain rule: @{text "Domainp |
1650 |
ZN = (\<lambda>x. x \<ge> 0)"}. The rules allow the package to produce more readable |
|
60670 | 1651 |
transferred goals, e.g.\ when quantifiers are transferred. |
60660 | 1652 |
|
1653 |
\item @{attribute (HOL) relator_eq} attribute collects identity laws for |
|
1654 |
relators of various type constructors, e.g. @{term "rel_set (op =) = (op |
|
1655 |
=)"}. The @{method (HOL) transfer} method uses these lemmas to infer |
|
1656 |
transfer rules for non-polymorphic constants on the fly. For examples see |
|
1657 |
@{file "~~/src/HOL/Lifting_Set.thy"} or @{file "~~/src/HOL/Lifting.thy"}. |
|
1658 |
This property is proved automatically if the involved type is BNF without |
|
1659 |
dead variables. |
|
1660 |
||
1661 |
\item @{attribute_def (HOL) "relator_domain"} attribute collects rules |
|
60670 | 1662 |
describing domains of relators by predicators. E.g.\ @{term "Domainp |
60660 | 1663 |
(rel_set T) = (\<lambda>A. Ball A (Domainp T))"}. This allows the package to lift |
1664 |
transfer domain rules through type constructors. For examples see @{file |
|
1665 |
"~~/src/HOL/Lifting_Set.thy"} or @{file "~~/src/HOL/Lifting.thy"}. This |
|
1666 |
property is proved automatically if the involved type is BNF without dead |
|
1667 |
variables. |
|
1668 |
||
1669 |
\end{description} |
|
1670 |
||
1671 |
Theoretical background can be found in @{cite |
|
1672 |
"Huffman-Kuncar:2013:lifting_transfer"}. |
|
1673 |
\<close> |
|
1674 |
||
1675 |
||
60671 | 1676 |
subsection \<open>Old-style definitions for quotient types \label{sec:old-quotient}\<close> |
1677 |
||
1678 |
text \<open> |
|
1679 |
\begin{matharray}{rcl} |
|
1680 |
@{command_def (HOL) "quotient_definition"} & : & @{text "local_theory \<rightarrow> proof(prove)"}\\ |
|
1681 |
@{command_def (HOL) "print_quotmapsQ3"} & : & @{text "context \<rightarrow>"}\\ |
|
1682 |
@{command_def (HOL) "print_quotientsQ3"} & : & @{text "context \<rightarrow>"}\\ |
|
1683 |
@{command_def (HOL) "print_quotconsts"} & : & @{text "context \<rightarrow>"}\\ |
|
1684 |
@{method_def (HOL) "lifting"} & : & @{text method} \\ |
|
1685 |
@{method_def (HOL) "lifting_setup"} & : & @{text method} \\ |
|
1686 |
@{method_def (HOL) "descending"} & : & @{text method} \\ |
|
1687 |
@{method_def (HOL) "descending_setup"} & : & @{text method} \\ |
|
1688 |
@{method_def (HOL) "partiality_descending"} & : & @{text method} \\ |
|
1689 |
@{method_def (HOL) "partiality_descending_setup"} & : & @{text method} \\ |
|
1690 |
@{method_def (HOL) "regularize"} & : & @{text method} \\ |
|
1691 |
@{method_def (HOL) "injection"} & : & @{text method} \\ |
|
1692 |
@{method_def (HOL) "cleaning"} & : & @{text method} \\ |
|
1693 |
@{attribute_def (HOL) "quot_thm"} & : & @{text attribute} \\ |
|
1694 |
@{attribute_def (HOL) "quot_lifted"} & : & @{text attribute} \\ |
|
1695 |
@{attribute_def (HOL) "quot_respect"} & : & @{text attribute} \\ |
|
1696 |
@{attribute_def (HOL) "quot_preserve"} & : & @{text attribute} \\ |
|
1697 |
\end{matharray} |
|
1698 |
||
1699 |
@{rail \<open> |
|
1700 |
@@{command (HOL) quotient_definition} constdecl? @{syntax thmdecl}? \<newline> |
|
1701 |
@{syntax term} 'is' @{syntax term} |
|
1702 |
; |
|
1703 |
constdecl: @{syntax name} ('::' @{syntax type})? @{syntax mixfix}? |
|
1704 |
; |
|
1705 |
@@{method (HOL) lifting} @{syntax thmrefs}? |
|
1706 |
; |
|
1707 |
@@{method (HOL) lifting_setup} @{syntax thmrefs}? |
|
1708 |
\<close>} |
|
1709 |
||
1710 |
\begin{description} |
|
1711 |
||
1712 |
\item @{command (HOL) "quotient_definition"} defines a constant on the |
|
1713 |
quotient type. |
|
1714 |
||
1715 |
\item @{command (HOL) "print_quotmapsQ3"} prints quotient map functions. |
|
1716 |
||
1717 |
\item @{command (HOL) "print_quotientsQ3"} prints quotients. |
|
1718 |
||
1719 |
\item @{command (HOL) "print_quotconsts"} prints quotient constants. |
|
1720 |
||
1721 |
\item @{method (HOL) "lifting"} and @{method (HOL) "lifting_setup"} |
|
1722 |
methods match the current goal with the given raw theorem to be lifted |
|
1723 |
producing three new subgoals: regularization, injection and cleaning |
|
1724 |
subgoals. @{method (HOL) "lifting"} tries to apply the heuristics for |
|
1725 |
automatically solving these three subgoals and leaves only the subgoals |
|
1726 |
unsolved by the heuristics to the user as opposed to @{method (HOL) |
|
1727 |
"lifting_setup"} which leaves the three subgoals unsolved. |
|
1728 |
||
1729 |
\item @{method (HOL) "descending"} and @{method (HOL) "descending_setup"} |
|
1730 |
try to guess a raw statement that would lift to the current subgoal. Such |
|
1731 |
statement is assumed as a new subgoal and @{method (HOL) "descending"} |
|
1732 |
continues in the same way as @{method (HOL) "lifting"} does. @{method |
|
1733 |
(HOL) "descending"} tries to solve the arising regularization, injection |
|
1734 |
and cleaning subgoals with the analogous method @{method (HOL) |
|
1735 |
"descending_setup"} which leaves the four unsolved subgoals. |
|
1736 |
||
1737 |
\item @{method (HOL) "partiality_descending"} finds the regularized |
|
1738 |
theorem that would lift to the current subgoal, lifts it and leaves as a |
|
1739 |
subgoal. This method can be used with partial equivalence quotients where |
|
1740 |
the non regularized statements would not be true. @{method (HOL) |
|
1741 |
"partiality_descending_setup"} leaves the injection and cleaning subgoals |
|
1742 |
unchanged. |
|
1743 |
||
1744 |
\item @{method (HOL) "regularize"} applies the regularization heuristics |
|
1745 |
to the current subgoal. |
|
1746 |
||
1747 |
\item @{method (HOL) "injection"} applies the injection heuristics to the |
|
1748 |
current goal using the stored quotient respectfulness theorems. |
|
1749 |
||
1750 |
\item @{method (HOL) "cleaning"} applies the injection cleaning heuristics |
|
1751 |
to the current subgoal using the stored quotient preservation theorems. |
|
1752 |
||
1753 |
\item @{attribute (HOL) quot_lifted} attribute tries to automatically |
|
1754 |
transport the theorem to the quotient type. The attribute uses all the |
|
1755 |
defined quotients types and quotient constants often producing undesired |
|
1756 |
results or theorems that cannot be lifted. |
|
1757 |
||
1758 |
\item @{attribute (HOL) quot_respect} and @{attribute (HOL) quot_preserve} |
|
1759 |
attributes declare a theorem as a respectfulness and preservation theorem |
|
1760 |
respectively. These are stored in the local theory store and used by the |
|
1761 |
@{method (HOL) "injection"} and @{method (HOL) "cleaning"} methods |
|
1762 |
respectively. |
|
1763 |
||
1764 |
\item @{attribute (HOL) quot_thm} declares that a certain theorem is a |
|
1765 |
quotient extension theorem. Quotient extension theorems allow for |
|
1766 |
quotienting inside container types. Given a polymorphic type that serves |
|
1767 |
as a container, a map function defined for this container using @{command |
|
1768 |
(HOL) "functor"} and a relation map defined for for the container type, |
|
1769 |
the quotient extension theorem should be @{term "Quotient3 R Abs Rep \<Longrightarrow> |
|
1770 |
Quotient3 (rel_map R) (map Abs) (map Rep)"}. Quotient extension theorems |
|
1771 |
are stored in a database and are used all the steps of lifting theorems. |
|
1772 |
||
1773 |
\end{description} |
|
1774 |
\<close> |
|
1775 |
||
1776 |
||
1777 |
chapter \<open>Proof tools\<close> |
|
1778 |
||
58618 | 1779 |
section \<open>Proving propositions\<close> |
1780 |
||
1781 |
text \<open> |
|
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1782 |
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
|
1783 |
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
|
1784 |
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
|
1785 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1786 |
\begin{matharray}{rcl} |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1787 |
@{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
|
1788 |
@{command_def (HOL) "try"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\ |
46641 | 1789 |
@{command_def (HOL) "try0"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\ |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1790 |
@{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
|
1791 |
@{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
|
1792 |
\end{matharray} |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1793 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1794 |
@{rail \<open> |
43040 | 1795 |
@@{command (HOL) try} |
1796 |
; |
|
1797 |
||
46641 | 1798 |
@@{command (HOL) try0} ( ( ( 'simp' | 'intro' | 'elim' | 'dest' ) ':' @{syntax thmrefs} ) + ) ? |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1799 |
@{syntax nat}? |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1800 |
; |
43040 | 1801 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1802 |
@@{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
|
1803 |
; |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1804 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1805 |
@@{command (HOL) sledgehammer_params} ( ( '[' args ']' ) ? ) |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1806 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1807 |
args: ( @{syntax name} '=' value + ',' ) |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1808 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1809 |
facts: '(' ( ( ( ( 'add' | 'del' ) ':' ) ? @{syntax thmrefs} ) + ) ? ')' |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1810 |
\<close>} % FIXME check args "value" |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1811 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1812 |
\begin{description} |
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1813 |
|
46283 | 1814 |
\item @{command (HOL) "solve_direct"} checks whether the current |
1815 |
subgoals can be solved directly by an existing theorem. Duplicate |
|
1816 |
lemmas can be detected in this way. |
|
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1817 |
|
46641 | 1818 |
\item @{command (HOL) "try0"} attempts to prove a subgoal |
46283 | 1819 |
using a combination of standard proof methods (@{method auto}, |
1820 |
@{method simp}, @{method blast}, etc.). Additional facts supplied |
|
1821 |
via @{text "simp:"}, @{text "intro:"}, @{text "elim:"}, and @{text |
|
1822 |
"dest:"} are passed to the appropriate proof methods. |
|
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1823 |
|
43914
64819f353c53
updating documentation about quickcheck; adding information about try
bulwahn
parents:
43578
diff
changeset
|
1824 |
\item @{command (HOL) "try"} attempts to prove or disprove a subgoal |
46283 | 1825 |
using a combination of provers and disprovers (@{command (HOL) |
1826 |
"solve_direct"}, @{command (HOL) "quickcheck"}, @{command (HOL) |
|
46641 | 1827 |
"try0"}, @{command (HOL) "sledgehammer"}, @{command (HOL) |
46283 | 1828 |
"nitpick"}). |
43914
64819f353c53
updating documentation about quickcheck; adding information about try
bulwahn
parents:
43578
diff
changeset
|
1829 |
|
46283 | 1830 |
\item @{command (HOL) "sledgehammer"} attempts to prove a subgoal |
1831 |
using external automatic provers (resolution provers and SMT |
|
58552 | 1832 |
solvers). See the Sledgehammer manual @{cite "isabelle-sledgehammer"} |
46283 | 1833 |
for details. |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1834 |
|
46283 | 1835 |
\item @{command (HOL) "sledgehammer_params"} changes @{command (HOL) |
1836 |
"sledgehammer"} configuration options persistently. |
|
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1837 |
|
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
1838 |
\end{description} |
58618 | 1839 |
\<close> |
1840 |
||
1841 |
||
1842 |
section \<open>Checking and refuting propositions\<close> |
|
1843 |
||
1844 |
text \<open> |
|
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1845 |
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
|
1846 |
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
|
1847 |
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
|
1848 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1849 |
\begin{matharray}{rcl} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1850 |
@{command_def (HOL) "value"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
45409
5abb0e738b00
adding some documentation about the values command to the isar reference
bulwahn
parents:
45408
diff
changeset
|
1851 |
@{command_def (HOL) "values"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1852 |
@{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
|
1853 |
@{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
|
1854 |
@{command_def (HOL) "quickcheck_params"} & : & @{text "theory \<rightarrow> theory"} \\ |
45943
8c4a5e664fbc
adding documentation about the quickcheck_generator command in the IsarRef
bulwahn
parents:
45839
diff
changeset
|
1855 |
@{command_def (HOL) "nitpick_params"} & : & @{text "theory \<rightarrow> theory"} \\ |
46592
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
1856 |
@{command_def (HOL) "quickcheck_generator"} & : & @{text "theory \<rightarrow> theory"} \\ |
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
1857 |
@{command_def (HOL) "find_unused_assms"} & : & @{text "context \<rightarrow>"} |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1858 |
\end{matharray} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1859 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1860 |
@{rail \<open> |
58100
f54a8a4134d3
restored generic value slot, retaining default behaviour and separate approximate command
haftmann
parents:
57829
diff
changeset
|
1861 |
@@{command (HOL) value} ( '[' @{syntax 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
|
1862 |
; |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1863 |
|
45409
5abb0e738b00
adding some documentation about the values command to the isar reference
bulwahn
parents:
45408
diff
changeset
|
1864 |
@@{command (HOL) values} modes? @{syntax nat}? @{syntax term} |
5abb0e738b00
adding some documentation about the values command to the isar reference
bulwahn
parents:
45408
diff
changeset
|
1865 |
; |
5abb0e738b00
adding some documentation about the values command to the isar reference
bulwahn
parents:
45408
diff
changeset
|
1866 |
|
49993
80402e0e78e3
removed "refute" command from Isar manual, now that it has been moved outside "Main"
blanchet
parents:
49836
diff
changeset
|
1867 |
(@@{command (HOL) quickcheck} | @@{command (HOL) nitpick}) |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1868 |
( '[' args ']' )? @{syntax nat}? |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1869 |
; |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1870 |
|
49993
80402e0e78e3
removed "refute" command from Isar manual, now that it has been moved outside "Main"
blanchet
parents:
49836
diff
changeset
|
1871 |
(@@{command (HOL) quickcheck_params} | |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1872 |
@@{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
|
1873 |
; |
46592
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
1874 |
|
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
1875 |
@@{command (HOL) quickcheck_generator} @{syntax nameref} \<newline> |
45943
8c4a5e664fbc
adding documentation about the quickcheck_generator command in the IsarRef
bulwahn
parents:
45839
diff
changeset
|
1876 |
'operations:' ( @{syntax term} +) |
8c4a5e664fbc
adding documentation about the quickcheck_generator command in the IsarRef
bulwahn
parents:
45839
diff
changeset
|
1877 |
; |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1878 |
|
46628 | 1879 |
@@{command (HOL) find_unused_assms} @{syntax name}? |
46592
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
1880 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1881 |
modes: '(' (@{syntax name} +) ')' |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1882 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
1883 |
args: ( @{syntax name} '=' value + ',' ) |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1884 |
\<close>} % FIXME check "value" |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1885 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1886 |
\begin{description} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1887 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1888 |
\item @{command (HOL) "value"}~@{text t} evaluates and prints a |
46283 | 1889 |
term; optionally @{text modes} can be specified, which are appended |
1890 |
to the current print mode; see \secref{sec:print-modes}. |
|
56927 | 1891 |
Evaluation is tried first using ML, falling |
1892 |
back to normalization by evaluation if this fails. |
|
58100
f54a8a4134d3
restored generic value slot, retaining default behaviour and separate approximate command
haftmann
parents:
57829
diff
changeset
|
1893 |
Alternatively a specific evaluator can be selected using square |
f54a8a4134d3
restored generic value slot, retaining default behaviour and separate approximate command
haftmann
parents:
57829
diff
changeset
|
1894 |
brackets; typical evaluators use the current set of code equations |
f54a8a4134d3
restored generic value slot, retaining default behaviour and separate approximate command
haftmann
parents:
57829
diff
changeset
|
1895 |
to normalize and include @{text simp} for fully symbolic evaluation |
f54a8a4134d3
restored generic value slot, retaining default behaviour and separate approximate command
haftmann
parents:
57829
diff
changeset
|
1896 |
using the simplifier, @{text nbe} for \emph{normalization by |
f54a8a4134d3
restored generic value slot, retaining default behaviour and separate approximate command
haftmann
parents:
57829
diff
changeset
|
1897 |
evaluation} 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
|
1898 |
|
46283 | 1899 |
\item @{command (HOL) "values"}~@{text t} enumerates a set |
1900 |
comprehension by evaluation and prints its values up to the given |
|
1901 |
number of solutions; optionally @{text modes} can be specified, |
|
1902 |
which are appended to the current print mode; see |
|
1903 |
\secref{sec:print-modes}. |
|
45409
5abb0e738b00
adding some documentation about the values command to the isar reference
bulwahn
parents:
45408
diff
changeset
|
1904 |
|
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1905 |
\item @{command (HOL) "quickcheck"} tests the current goal for |
46283 | 1906 |
counterexamples using a series of assignments for its free |
1907 |
variables; by default the first subgoal is tested, an other can be |
|
1908 |
selected explicitly using an optional goal index. Assignments can |
|
52895
a806aa7a5370
some documentation for adhoc overloading;
Christian Sternagel
parents:
52637
diff
changeset
|
1909 |
be chosen exhausting the search space up to a given size, or using a |
46283 | 1910 |
fixed number of random assignments in the search space, or exploring |
1911 |
the search space symbolically using narrowing. By default, |
|
1912 |
quickcheck uses exhaustive testing. A number of configuration |
|
1913 |
options are supported for @{command (HOL) "quickcheck"}, notably: |
|
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1914 |
|
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1915 |
\begin{description} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1916 |
|
43914
64819f353c53
updating documentation about quickcheck; adding information about try
bulwahn
parents:
43578
diff
changeset
|
1917 |
\item[@{text tester}] specifies which testing approach to apply. |
46283 | 1918 |
There are three testers, @{text exhaustive}, @{text random}, and |
1919 |
@{text narrowing}. An unknown configuration option is treated as |
|
1920 |
an argument to tester, making @{text "tester ="} optional. When |
|
1921 |
multiple testers are given, these are applied in parallel. If no |
|
1922 |
tester is specified, quickcheck uses the testers that are set |
|
60670 | 1923 |
active, i.e.\ configurations @{attribute |
46283 | 1924 |
quickcheck_exhaustive_active}, @{attribute |
1925 |
quickcheck_random_active}, @{attribute |
|
1926 |
quickcheck_narrowing_active} are set to true. |
|
1927 |
||
40254 | 1928 |
\item[@{text size}] specifies the maximum size of the search space |
1929 |
for assignment values. |
|
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1930 |
|
45758
6210c350d88b
documenting the genuine_only option in quickcheck;
bulwahn
parents:
45701
diff
changeset
|
1931 |
\item[@{text genuine_only}] sets quickcheck only to return genuine |
46283 | 1932 |
counterexample, but not potentially spurious counterexamples due |
1933 |
to underspecified functions. |
|
46498
2754784e9153
adding documentation for abort_potential option in quickcheck
bulwahn
parents:
46494
diff
changeset
|
1934 |
|
2754784e9153
adding documentation for abort_potential option in quickcheck
bulwahn
parents:
46494
diff
changeset
|
1935 |
\item[@{text abort_potential}] sets quickcheck to abort once it |
2754784e9153
adding documentation for abort_potential option in quickcheck
bulwahn
parents:
46494
diff
changeset
|
1936 |
found a potentially spurious counterexample and to not continue |
2754784e9153
adding documentation for abort_potential option in quickcheck
bulwahn
parents:
46494
diff
changeset
|
1937 |
to search for a further genuine counterexample. |
2754784e9153
adding documentation for abort_potential option in quickcheck
bulwahn
parents:
46494
diff
changeset
|
1938 |
For this option to be effective, the @{text genuine_only} option |
2754784e9153
adding documentation for abort_potential option in quickcheck
bulwahn
parents:
46494
diff
changeset
|
1939 |
must be set to false. |
47859 | 1940 |
|
42092
f07b373f25d3
adding documentation about the eval option in quickcheck
bulwahn
parents:
41846
diff
changeset
|
1941 |
\item[@{text eval}] takes a term or a list of terms and evaluates |
46283 | 1942 |
these terms under the variable assignment found by quickcheck. |
48159 | 1943 |
This option is currently only supported by the default |
1944 |
(exhaustive) tester. |
|
42123 | 1945 |
|
40254 | 1946 |
\item[@{text iterations}] sets how many sets of assignments are |
1947 |
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
|
1948 |
|
40254 | 1949 |
\item[@{text no_assms}] specifies whether assumptions in |
1950 |
structured proofs should be ignored. |
|
35331 | 1951 |
|
47349
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
bulwahn
parents:
46641
diff
changeset
|
1952 |
\item[@{text locale}] specifies how to process conjectures in |
60670 | 1953 |
a locale context, i.e.\ they can be interpreted or expanded. |
47349
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
bulwahn
parents:
46641
diff
changeset
|
1954 |
The option is a whitespace-separated list of the two words |
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
bulwahn
parents:
46641
diff
changeset
|
1955 |
@{text interpret} and @{text expand}. The list determines the |
47859 | 1956 |
order they are employed. The default setting is to first use |
47349
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
bulwahn
parents:
46641
diff
changeset
|
1957 |
interpretations and then test the expanded conjecture. |
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
bulwahn
parents:
46641
diff
changeset
|
1958 |
The option is only provided as attribute declaration, but not |
47859 | 1959 |
as parameter to the command. |
47349
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
bulwahn
parents:
46641
diff
changeset
|
1960 |
|
40254 | 1961 |
\item[@{text timeout}] sets the time limit in seconds. |
40245
59f011c1877a
updating documentation on quickcheck in the Isar reference
bulwahn
parents:
40171
diff
changeset
|
1962 |
|
40254 | 1963 |
\item[@{text default_type}] sets the type(s) generally used to |
1964 |
instantiate type variables. |
|
40245
59f011c1877a
updating documentation on quickcheck in the Isar reference
bulwahn
parents:
40171
diff
changeset
|
1965 |
|
40254 | 1966 |
\item[@{text report}] if set quickcheck reports how many tests |
1967 |
fulfilled the preconditions. |
|
40245
59f011c1877a
updating documentation on quickcheck in the Isar reference
bulwahn
parents:
40171
diff
changeset
|
1968 |
|
46592
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
1969 |
\item[@{text use_subtype}] if set quickcheck automatically lifts |
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
1970 |
conjectures to registered subtypes if possible, and tests the |
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
1971 |
lifted conjecture. |
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
1972 |
|
45766
46046d8e9659
updating documentation about quiet and verbose options in quickcheck
bulwahn
parents:
45758
diff
changeset
|
1973 |
\item[@{text quiet}] if set quickcheck does not output anything |
46046d8e9659
updating documentation about quiet and verbose options in quickcheck
bulwahn
parents:
45758
diff
changeset
|
1974 |
while testing. |
47859 | 1975 |
|
46283 | 1976 |
\item[@{text verbose}] if set quickcheck informs about the current |
1977 |
size and cardinality while testing. |
|
40245
59f011c1877a
updating documentation on quickcheck in the Isar reference
bulwahn
parents:
40171
diff
changeset
|
1978 |
|
40254 | 1979 |
\item[@{text expect}] can be used to check if the user's |
1980 |
expectation was met (@{text no_expectation}, @{text |
|
1981 |
no_counterexample}, or @{text counterexample}). |
|
40245
59f011c1877a
updating documentation on quickcheck in the Isar reference
bulwahn
parents:
40171
diff
changeset
|
1982 |
|
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1983 |
\end{description} |
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1984 |
|
46283 | 1985 |
These option can be given within square brackets. |
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
1986 |
|
56363
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
1987 |
Using the following type classes, the testers generate values and convert |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
1988 |
them back into Isabelle terms for displaying counterexamples. |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
1989 |
\begin{description} |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
1990 |
\item[@{text exhaustive}] The parameters of the type classes @{class exhaustive} |
60657 | 1991 |
and @{class full_exhaustive} implement the testing. They take a |
56363
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
1992 |
testing function as a parameter, which takes a value of type @{typ "'a"} |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
1993 |
and optionally produces a counterexample, and a size parameter for the test values. |
60657 | 1994 |
In @{class full_exhaustive}, the testing function parameter additionally |
56363
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
1995 |
expects a lazy term reconstruction in the type @{typ Code_Evaluation.term} |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
1996 |
of the tested value. |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
1997 |
|
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
1998 |
The canonical implementation for @{text exhaustive} testers calls the given |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
1999 |
testing function on all values up to the given size and stops as soon |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2000 |
as a counterexample is found. |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2001 |
|
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2002 |
\item[@{text random}] The operation @{const Quickcheck_Random.random} |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2003 |
of the type class @{class random} generates a pseudo-random |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2004 |
value of the given size and a lazy term reconstruction of the value |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2005 |
in the type @{typ Code_Evaluation.term}. A pseudo-randomness generator |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2006 |
is defined in theory @{theory Random}. |
60657 | 2007 |
|
58552 | 2008 |
\item[@{text narrowing}] implements Haskell's Lazy Smallcheck @{cite "runciman-naylor-lindblad"} |
56363
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2009 |
using the type classes @{class narrowing} and @{class partial_term_of}. |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2010 |
Variables in the current goal are initially represented as symbolic variables. |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2011 |
If the execution of the goal tries to evaluate one of them, the test engine |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2012 |
replaces it with refinements provided by @{const narrowing}. |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2013 |
Narrowing views every value as a sum-of-products which is expressed using the operations |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2014 |
@{const Quickcheck_Narrowing.cons} (embedding a value), |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2015 |
@{const Quickcheck_Narrowing.apply} (product) and @{const Quickcheck_Narrowing.sum} (sum). |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2016 |
The refinement should enable further evaluation of the goal. |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2017 |
|
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2018 |
For example, @{const narrowing} for the list type @{typ "'a :: narrowing list"} |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2019 |
can be recursively defined as |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2020 |
@{term "Quickcheck_Narrowing.sum (Quickcheck_Narrowing.cons []) |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2021 |
(Quickcheck_Narrowing.apply |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2022 |
(Quickcheck_Narrowing.apply |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2023 |
(Quickcheck_Narrowing.cons (op #)) |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2024 |
narrowing) |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2025 |
narrowing)"}. |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2026 |
If a symbolic variable of type @{typ "_ list"} is evaluated, it is replaced by (i)~the empty |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2027 |
list @{term "[]"} and (ii)~by a non-empty list whose head and tail can then be recursively |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2028 |
refined if needed. |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2029 |
|
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2030 |
To reconstruct counterexamples, the operation @{const partial_term_of} transforms |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2031 |
@{text narrowing}'s deep representation of terms to the type @{typ Code_Evaluation.term}. |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2032 |
The deep representation models symbolic variables as |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2033 |
@{const Quickcheck_Narrowing.Narrowing_variable}, which are normally converted to |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2034 |
@{const Code_Evaluation.Free}, and refined values as |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2035 |
@{term "Quickcheck_Narrowing.Narrowing_constructor i args"}, where @{term "i :: integer"} |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2036 |
denotes the index in the sum of refinements. In the above example for lists, |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2037 |
@{term "0"} corresponds to @{term "[]"} and @{term "1"} |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2038 |
to @{term "op #"}. |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2039 |
|
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2040 |
The command @{command (HOL) "code_datatype"} sets up @{const partial_term_of} |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2041 |
such that the @{term "i"}-th refinement is interpreted as the @{term "i"}-th constructor, |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2042 |
but it does not ensures consistency with @{const narrowing}. |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2043 |
\end{description} |
89e0264adf79
document value generation for quickcheck's testers
Andreas Lochbihler
parents:
56270
diff
changeset
|
2044 |
|
46283 | 2045 |
\item @{command (HOL) "quickcheck_params"} changes @{command (HOL) |
2046 |
"quickcheck"} configuration options persistently. |
|
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
2047 |
|
45943
8c4a5e664fbc
adding documentation about the quickcheck_generator command in the IsarRef
bulwahn
parents:
45839
diff
changeset
|
2048 |
\item @{command (HOL) "quickcheck_generator"} creates random and |
46283 | 2049 |
exhaustive value generators for a given type and operations. It |
2050 |
generates values by using the operations as if they were |
|
2051 |
constructors of that type. |
|
45943
8c4a5e664fbc
adding documentation about the quickcheck_generator command in the IsarRef
bulwahn
parents:
45839
diff
changeset
|
2052 |
|
46283 | 2053 |
\item @{command (HOL) "nitpick"} tests the current goal for |
2054 |
counterexamples using a reduction to first-order relational |
|
58552 | 2055 |
logic. See the Nitpick manual @{cite "isabelle-nitpick"} for details. |
42215
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
blanchet
parents:
42123
diff
changeset
|
2056 |
|
46283 | 2057 |
\item @{command (HOL) "nitpick_params"} changes @{command (HOL) |
2058 |
"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
|
2059 |
|
46592
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
2060 |
\item @{command (HOL) "find_unused_assms"} finds potentially superfluous |
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
2061 |
assumptions in theorems using quickcheck. |
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
2062 |
It takes the theory name to be checked for superfluous assumptions as |
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
2063 |
optional argument. If not provided, it checks the current theory. |
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
2064 |
Options to the internal quickcheck invocations can be changed with |
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
2065 |
common configuration declarations. |
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
bulwahn
parents:
46498
diff
changeset
|
2066 |
|
31912
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
haftmann
parents:
31254
diff
changeset
|
2067 |
\end{description} |
58618 | 2068 |
\<close> |
2069 |
||
2070 |
||
60673 | 2071 |
section \<open>Coercive subtyping\<close> |
2072 |
||
2073 |
text \<open> |
|
2074 |
\begin{matharray}{rcl} |
|
2075 |
@{attribute_def (HOL) coercion} & : & @{text attribute} \\ |
|
2076 |
@{attribute_def (HOL) coercion_enabled} & : & @{text attribute} \\ |
|
2077 |
@{attribute_def (HOL) coercion_map} & : & @{text attribute} \\ |
|
2078 |
\end{matharray} |
|
2079 |
||
2080 |
Coercive subtyping allows the user to omit explicit type |
|
2081 |
conversions, also called \emph{coercions}. Type inference will add |
|
2082 |
them as necessary when parsing a term. See |
|
2083 |
@{cite "traytel-berghofer-nipkow-2011"} for details. |
|
2084 |
||
2085 |
@{rail \<open> |
|
2086 |
@@{attribute (HOL) coercion} (@{syntax term})? |
|
2087 |
; |
|
2088 |
@@{attribute (HOL) coercion_map} (@{syntax term})? |
|
2089 |
\<close>} |
|
2090 |
||
2091 |
\begin{description} |
|
2092 |
||
2093 |
\item @{attribute (HOL) "coercion"}~@{text "f"} registers a new |
|
2094 |
coercion function @{text "f :: \<sigma>\<^sub>1 \<Rightarrow> \<sigma>\<^sub>2"} where @{text "\<sigma>\<^sub>1"} and |
|
2095 |
@{text "\<sigma>\<^sub>2"} are type constructors without arguments. Coercions are |
|
2096 |
composed by the inference algorithm if needed. Note that the type |
|
2097 |
inference algorithm is complete only if the registered coercions |
|
2098 |
form a lattice. |
|
2099 |
||
2100 |
\item @{attribute (HOL) "coercion_map"}~@{text "map"} registers a |
|
2101 |
new map function to lift coercions through type constructors. The |
|
2102 |
function @{text "map"} must conform to the following type pattern |
|
2103 |
||
2104 |
\begin{matharray}{lll} |
|
2105 |
@{text "map"} & @{text "::"} & |
|
2106 |
@{text "f\<^sub>1 \<Rightarrow> \<dots> \<Rightarrow> f\<^sub>n \<Rightarrow> (\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t \<Rightarrow> (\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n) t"} \\ |
|
2107 |
\end{matharray} |
|
2108 |
||
2109 |
where @{text "t"} is a type constructor and @{text "f\<^sub>i"} is of type |
|
2110 |
@{text "\<alpha>\<^sub>i \<Rightarrow> \<beta>\<^sub>i"} or @{text "\<beta>\<^sub>i \<Rightarrow> \<alpha>\<^sub>i"}. Registering a map function |
|
2111 |
overwrites any existing map function for this particular type |
|
2112 |
constructor. |
|
2113 |
||
2114 |
\item @{attribute (HOL) "coercion_enabled"} enables the coercion |
|
2115 |
inference algorithm. |
|
2116 |
||
2117 |
\end{description} |
|
2118 |
\<close> |
|
2119 |
||
2120 |
||
2121 |
section \<open>Arithmetic proof support\<close> |
|
2122 |
||
2123 |
text \<open> |
|
2124 |
\begin{matharray}{rcl} |
|
2125 |
@{method_def (HOL) arith} & : & @{text method} \\ |
|
2126 |
@{attribute_def (HOL) arith} & : & @{text attribute} \\ |
|
2127 |
@{attribute_def (HOL) arith_split} & : & @{text attribute} \\ |
|
2128 |
\end{matharray} |
|
2129 |
||
2130 |
\begin{description} |
|
2131 |
||
2132 |
\item @{method (HOL) arith} decides linear arithmetic problems (on |
|
2133 |
types @{text nat}, @{text int}, @{text real}). Any current facts |
|
2134 |
are inserted into the goal before running the procedure. |
|
2135 |
||
2136 |
\item @{attribute (HOL) arith} declares facts that are supplied to |
|
2137 |
the arithmetic provers implicitly. |
|
2138 |
||
2139 |
\item @{attribute (HOL) arith_split} attribute declares case split |
|
2140 |
rules to be expanded before @{method (HOL) arith} is invoked. |
|
2141 |
||
2142 |
\end{description} |
|
2143 |
||
2144 |
Note that a simpler (but faster) arithmetic prover is already |
|
2145 |
invoked by the Simplifier. |
|
2146 |
\<close> |
|
2147 |
||
2148 |
||
2149 |
section \<open>Intuitionistic proof search\<close> |
|
2150 |
||
2151 |
text \<open> |
|
2152 |
\begin{matharray}{rcl} |
|
2153 |
@{method_def (HOL) iprover} & : & @{text method} \\ |
|
2154 |
\end{matharray} |
|
2155 |
||
2156 |
@{rail \<open> |
|
2157 |
@@{method (HOL) iprover} (@{syntax rulemod} *) |
|
2158 |
\<close>} |
|
2159 |
||
2160 |
\begin{description} |
|
2161 |
||
2162 |
\item @{method (HOL) iprover} performs intuitionistic proof search, |
|
2163 |
depending on specifically declared rules from the context, or given |
|
2164 |
as explicit arguments. Chained facts are inserted into the goal |
|
2165 |
before commencing proof search. |
|
2166 |
||
2167 |
Rules need to be classified as @{attribute (Pure) intro}, |
|
2168 |
@{attribute (Pure) elim}, or @{attribute (Pure) dest}; here the |
|
2169 |
``@{text "!"}'' indicator refers to ``safe'' rules, which may be |
|
2170 |
applied aggressively (without considering back-tracking later). |
|
2171 |
Rules declared with ``@{text "?"}'' are ignored in proof search (the |
|
2172 |
single-step @{method (Pure) rule} method still observes these). An |
|
2173 |
explicit weight annotation may be given as well; otherwise the |
|
2174 |
number of rule premises will be taken into account here. |
|
2175 |
||
2176 |
\end{description} |
|
2177 |
\<close> |
|
2178 |
||
2179 |
||
2180 |
section \<open>Model Elimination and Resolution\<close> |
|
2181 |
||
2182 |
text \<open> |
|
2183 |
\begin{matharray}{rcl} |
|
2184 |
@{method_def (HOL) "meson"} & : & @{text method} \\ |
|
2185 |
@{method_def (HOL) "metis"} & : & @{text method} \\ |
|
2186 |
\end{matharray} |
|
2187 |
||
2188 |
@{rail \<open> |
|
2189 |
@@{method (HOL) meson} @{syntax thmrefs}? |
|
2190 |
; |
|
2191 |
@@{method (HOL) metis} |
|
2192 |
('(' ('partial_types' | 'full_types' | 'no_types' | @{syntax name}) ')')? |
|
2193 |
@{syntax thmrefs}? |
|
2194 |
\<close>} |
|
2195 |
||
2196 |
\begin{description} |
|
2197 |
||
2198 |
\item @{method (HOL) meson} implements Loveland's model elimination |
|
2199 |
procedure @{cite "loveland-78"}. See @{file |
|
2200 |
"~~/src/HOL/ex/Meson_Test.thy"} for examples. |
|
2201 |
||
2202 |
\item @{method (HOL) metis} combines ordered resolution and ordered |
|
2203 |
paramodulation to find first-order (or mildly higher-order) proofs. |
|
2204 |
The first optional argument specifies a type encoding; see the |
|
2205 |
Sledgehammer manual @{cite "isabelle-sledgehammer"} for details. The |
|
2206 |
directory @{file "~~/src/HOL/Metis_Examples"} contains several small |
|
2207 |
theories developed to a large extent using @{method (HOL) metis}. |
|
2208 |
||
2209 |
\end{description} |
|
2210 |
\<close> |
|
2211 |
||
2212 |
||
2213 |
section \<open>Algebraic reasoning via Gr\"obner bases\<close> |
|
2214 |
||
2215 |
text \<open> |
|
2216 |
\begin{matharray}{rcl} |
|
2217 |
@{method_def (HOL) "algebra"} & : & @{text method} \\ |
|
2218 |
@{attribute_def (HOL) algebra} & : & @{text attribute} \\ |
|
2219 |
\end{matharray} |
|
2220 |
||
2221 |
@{rail \<open> |
|
2222 |
@@{method (HOL) algebra} |
|
2223 |
('add' ':' @{syntax thmrefs})? |
|
2224 |
('del' ':' @{syntax thmrefs})? |
|
2225 |
; |
|
2226 |
@@{attribute (HOL) algebra} (() | 'add' | 'del') |
|
2227 |
\<close>} |
|
2228 |
||
2229 |
\begin{description} |
|
2230 |
||
2231 |
\item @{method (HOL) algebra} performs algebraic reasoning via |
|
2232 |
Gr\"obner bases, see also @{cite "Chaieb-Wenzel:2007"} and |
|
2233 |
@{cite \<open>\S3.2\<close> "Chaieb-thesis"}. The method handles deals with two main |
|
2234 |
classes of problems: |
|
2235 |
||
2236 |
\begin{enumerate} |
|
2237 |
||
2238 |
\item Universal problems over multivariate polynomials in a |
|
2239 |
(semi)-ring/field/idom; the capabilities of the method are augmented |
|
2240 |
according to properties of these structures. For this problem class |
|
2241 |
the method is only complete for algebraically closed fields, since |
|
2242 |
the underlying method is based on Hilbert's Nullstellensatz, where |
|
2243 |
the equivalence only holds for algebraically closed fields. |
|
2244 |
||
2245 |
The problems can contain equations @{text "p = 0"} or inequations |
|
2246 |
@{text "q \<noteq> 0"} anywhere within a universal problem statement. |
|
2247 |
||
2248 |
\item All-exists problems of the following restricted (but useful) |
|
2249 |
form: |
|
2250 |
||
2251 |
@{text [display] "\<forall>x\<^sub>1 \<dots> x\<^sub>n. |
|
2252 |
e\<^sub>1(x\<^sub>1, \<dots>, x\<^sub>n) = 0 \<and> \<dots> \<and> e\<^sub>m(x\<^sub>1, \<dots>, x\<^sub>n) = 0 \<longrightarrow> |
|
2253 |
(\<exists>y\<^sub>1 \<dots> y\<^sub>k. |
|
2254 |
p\<^sub>1\<^sub>1(x\<^sub>1, \<dots> ,x\<^sub>n) * y\<^sub>1 + \<dots> + p\<^sub>1\<^sub>k(x\<^sub>1, \<dots>, x\<^sub>n) * y\<^sub>k = 0 \<and> |
|
2255 |
\<dots> \<and> |
|
2256 |
p\<^sub>t\<^sub>1(x\<^sub>1, \<dots>, x\<^sub>n) * y\<^sub>1 + \<dots> + p\<^sub>t\<^sub>k(x\<^sub>1, \<dots>, x\<^sub>n) * y\<^sub>k = 0)"} |
|
2257 |
||
2258 |
Here @{text "e\<^sub>1, \<dots>, e\<^sub>n"} and the @{text "p\<^sub>i\<^sub>j"} are multivariate |
|
2259 |
polynomials only in the variables mentioned as arguments. |
|
2260 |
||
2261 |
\end{enumerate} |
|
2262 |
||
2263 |
The proof method is preceded by a simplification step, which may be |
|
2264 |
modified by using the form @{text "(algebra add: ths\<^sub>1 del: ths\<^sub>2)"}. |
|
2265 |
This acts like declarations for the Simplifier |
|
2266 |
(\secref{sec:simplifier}) on a private simpset for this tool. |
|
2267 |
||
2268 |
\item @{attribute algebra} (as attribute) manages the default |
|
2269 |
collection of pre-simplification rules of the above proof method. |
|
2270 |
||
2271 |
\end{description} |
|
2272 |
\<close> |
|
2273 |
||
2274 |
||
2275 |
subsubsection \<open>Example\<close> |
|
2276 |
||
2277 |
text \<open>The subsequent example is from geometry: collinearity is |
|
2278 |
invariant by rotation.\<close> |
|
2279 |
||
2280 |
(*<*)experiment begin(*>*) |
|
2281 |
type_synonym point = "int \<times> int" |
|
2282 |
||
2283 |
fun collinear :: "point \<Rightarrow> point \<Rightarrow> point \<Rightarrow> bool" where |
|
2284 |
"collinear (Ax, Ay) (Bx, By) (Cx, Cy) \<longleftrightarrow> |
|
2285 |
(Ax - Bx) * (By - Cy) = (Ay - By) * (Bx - Cx)" |
|
2286 |
||
2287 |
lemma collinear_inv_rotation: |
|
2288 |
assumes "collinear (Ax, Ay) (Bx, By) (Cx, Cy)" and "c\<^sup>2 + s\<^sup>2 = 1" |
|
2289 |
shows "collinear (Ax * c - Ay * s, Ay * c + Ax * s) |
|
2290 |
(Bx * c - By * s, By * c + Bx * s) (Cx * c - Cy * s, Cy * c + Cx * s)" |
|
2291 |
using assms by (algebra add: collinear.simps) |
|
2292 |
(*<*)end(*>*) |
|
2293 |
||
2294 |
text \<open> |
|
2295 |
See also @{file "~~/src/HOL/ex/Groebner_Examples.thy"}. |
|
2296 |
\<close> |
|
2297 |
||
2298 |
||
2299 |
section \<open>Coherent Logic\<close> |
|
2300 |
||
2301 |
text \<open> |
|
2302 |
\begin{matharray}{rcl} |
|
2303 |
@{method_def (HOL) "coherent"} & : & @{text method} \\ |
|
2304 |
\end{matharray} |
|
2305 |
||
2306 |
@{rail \<open> |
|
2307 |
@@{method (HOL) coherent} @{syntax thmrefs}? |
|
2308 |
\<close>} |
|
2309 |
||
2310 |
\begin{description} |
|
2311 |
||
2312 |
\item @{method (HOL) coherent} solves problems of \emph{Coherent |
|
2313 |
Logic} @{cite "Bezem-Coquand:2005"}, which covers applications in |
|
2314 |
confluence theory, lattice theory and projective geometry. See |
|
2315 |
@{file "~~/src/HOL/ex/Coherent.thy"} for some examples. |
|
2316 |
||
2317 |
\end{description} |
|
2318 |
\<close> |
|
2319 |
||
2320 |
||
58618 | 2321 |
section \<open>Unstructured case analysis and induction \label{sec:hol-induct-tac}\<close> |
2322 |
||
2323 |
text \<open> |
|
27123
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
2324 |
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
|
2325 |
induction in unstructured tactic scripts; see also |
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
2326 |
\secref{sec:cases-induct} for proper Isar versions of similar ideas. |
26849 | 2327 |
|
2328 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
2329 |
@{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
|
2330 |
@{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
|
2331 |
@{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
|
2332 |
@{command_def (HOL) "inductive_cases"}@{text "\<^sup>*"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
26849 | 2333 |
\end{matharray} |
2334 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
2335 |
@{rail \<open> |
42705 | 2336 |
@@{method (HOL) case_tac} @{syntax goal_spec}? @{syntax term} rule? |
26849 | 2337 |
; |
42705 | 2338 |
@@{method (HOL) induct_tac} @{syntax goal_spec}? (@{syntax insts} * @'and') rule? |
26849 | 2339 |
; |
59845 | 2340 |
@@{method (HOL) ind_cases} (@{syntax prop}+) @{syntax for_fixes} |
26849 | 2341 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
2342 |
@@{command (HOL) inductive_cases} (@{syntax thmdecl}? (@{syntax prop}+) + @'and') |
26849 | 2343 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
2344 |
rule: 'rule' ':' @{syntax thmref} |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
2345 |
\<close>} |
26849 | 2346 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
2347 |
\begin{description} |
26849 | 2348 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
2349 |
\item @{method (HOL) case_tac} and @{method (HOL) induct_tac} admit |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
2350 |
to reason about inductive types. Rules are selected according to |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
2351 |
the declarations by the @{attribute cases} and @{attribute induct} |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
2352 |
attributes, cf.\ \secref{sec:cases-induct}. The @{command (HOL) |
58310 | 2353 |
datatype} package already takes care of this. |
27123
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
2354 |
|
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
wenzelm
parents:
27103
diff
changeset
|
2355 |
These unstructured tactics feature both goal addressing and dynamic |
26849 | 2356 |
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
|
2357 |
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
|
2358 |
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
|
2359 |
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
|
2360 |
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
|
2361 |
being addressed. |
42123 | 2362 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
2363 |
\item @{method (HOL) ind_cases} and @{command (HOL) |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
2364 |
"inductive_cases"} provide an interface to the internal @{ML_text |
26860 | 2365 |
mk_cases} operation. Rules are simplified in an unrestricted |
2366 |
forward manner. |
|
26849 | 2367 |
|
2368 |
While @{method (HOL) ind_cases} is a proof method to apply the |
|
2369 |
result immediately as elimination rules, @{command (HOL) |
|
2370 |
"inductive_cases"} provides case split theorems at the theory level |
|
2371 |
for later use. The @{keyword "for"} argument of the @{method (HOL) |
|
2372 |
ind_cases} method allows to specify a list of variables that should |
|
2373 |
be generalized before applying the resulting rule. |
|
2374 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28752
diff
changeset
|
2375 |
\end{description} |
58618 | 2376 |
\<close> |
2377 |
||
2378 |
||
60657 | 2379 |
|
2380 |
section \<open>Adhoc tuples\<close> |
|
2381 |
||
2382 |
text \<open> |
|
2383 |
\begin{matharray}{rcl} |
|
2384 |
@{attribute_def (HOL) split_format}@{text "\<^sup>*"} & : & @{text attribute} \\ |
|
2385 |
\end{matharray} |
|
2386 |
||
2387 |
@{rail \<open> |
|
2388 |
@@{attribute (HOL) split_format} ('(' 'complete' ')')? |
|
2389 |
\<close>} |
|
2390 |
||
2391 |
\begin{description} |
|
2392 |
||
2393 |
\item @{attribute (HOL) split_format}\ @{text "(complete)"} causes |
|
2394 |
arguments in function applications to be represented canonically |
|
2395 |
according to their tuple type structure. |
|
2396 |
||
2397 |
Note that this operation tends to invent funny names for new local |
|
2398 |
parameters introduced. |
|
2399 |
||
2400 |
\end{description} |
|
2401 |
\<close> |
|
2402 |
||
2403 |
||
58618 | 2404 |
chapter \<open>Executable code\<close> |
2405 |
||
2406 |
text \<open>For validation purposes, it is often useful to \emph{execute} |
|
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
2407 |
specifications. In principle, execution could be simulated by |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
2408 |
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
|
2409 |
simplification. Unfortunately, this approach is rather inefficient. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
2410 |
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
|
2411 |
them into a functional programming language such as ML. |
26849 | 2412 |
|
45192 | 2413 |
Isabelle provides a generic framework to support code generation |
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
2414 |
from executable specifications. Isabelle/HOL instantiates these |
45192 | 2415 |
mechanisms in a way that is amenable to end-user applications. Code |
2416 |
can be generated for functional programs (including overloading |
|
58552 | 2417 |
using type classes) targeting SML @{cite SML}, OCaml @{cite OCaml}, |
2418 |
Haskell @{cite "haskell-revised-report"} and Scala |
|
2419 |
@{cite "scala-overview-tech-report"}. Conceptually, code generation is |
|
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
2420 |
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
|
2421 |
\emph{translation} into an abstract executable view and |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
2422 |
\emph{serialization} to a specific \emph{target language}. |
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
2423 |
Inductive specifications can be executed using the predicate |
58552 | 2424 |
compiler which operates within HOL. See @{cite "isabelle-codegen"} for |
42627
8749742785b8
moved material about old codegen to isar-ref manual;
wenzelm
parents:
42626
diff
changeset
|
2425 |
an introduction. |
37422 | 2426 |
|
2427 |
\begin{matharray}{rcl} |
|
2428 |
@{command_def (HOL) "export_code"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
2429 |
@{attribute_def (HOL) code} & : & @{text attribute} \\ |
|
2430 |
@{command_def (HOL) "code_datatype"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
2431 |
@{command_def (HOL) "print_codesetup"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
45232
eb56e1774c26
updating documentation: code_inline -> code_unfold; added documentation about attribute code_unfold_post
bulwahn
parents:
45192
diff
changeset
|
2432 |
@{attribute_def (HOL) code_unfold} & : & @{text attribute} \\ |
37422 | 2433 |
@{attribute_def (HOL) code_post} & : & @{text attribute} \\ |
46028
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
haftmann
parents:
45944
diff
changeset
|
2434 |
@{attribute_def (HOL) code_abbrev} & : & @{text attribute} \\ |
37422 | 2435 |
@{command_def (HOL) "print_codeproc"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
2436 |
@{command_def (HOL) "code_thms"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
2437 |
@{command_def (HOL) "code_deps"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2438 |
@{command_def (HOL) "code_reserved"} & : & @{text "theory \<rightarrow> theory"} \\ |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2439 |
@{command_def (HOL) "code_printing"} & : & @{text "theory \<rightarrow> theory"} \\ |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2440 |
@{command_def (HOL) "code_identifier"} & : & @{text "theory \<rightarrow> theory"} \\ |
37422 | 2441 |
@{command_def (HOL) "code_monad"} & : & @{text "theory \<rightarrow> theory"} \\ |
45408
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
bulwahn
parents:
45232
diff
changeset
|
2442 |
@{command_def (HOL) "code_reflect"} & : & @{text "theory \<rightarrow> theory"} \\ |
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
bulwahn
parents:
45232
diff
changeset
|
2443 |
@{command_def (HOL) "code_pred"} & : & @{text "theory \<rightarrow> proof(prove)"} |
37422 | 2444 |
\end{matharray} |
2445 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
2446 |
@{rail \<open> |
55686
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
haftmann
parents:
55677
diff
changeset
|
2447 |
@@{command (HOL) export_code} ( @'open' ) ? ( constexpr + ) \<newline> |
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2448 |
( ( @'in' target ( @'module_name' @{syntax string} ) ? \<newline> |
52435
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
52378
diff
changeset
|
2449 |
( @'file' @{syntax string} ) ? ( '(' args ')' ) ?) + ) ? |
37422 | 2450 |
; |
2451 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
2452 |
const: @{syntax term} |
37422 | 2453 |
; |
2454 |
||
40711
81bc73585eec
globbing constant expressions use more idiomatic underscore rather than star
haftmann
parents:
40709
diff
changeset
|
2455 |
constexpr: ( const | 'name._' | '_' ) |
37422 | 2456 |
; |
2457 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
2458 |
typeconstructor: @{syntax nameref} |
37422 | 2459 |
; |
2460 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
2461 |
class: @{syntax nameref} |
37422 | 2462 |
; |
2463 |
||
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2464 |
target: 'SML' | 'OCaml' | 'Haskell' | 'Scala' | 'Eval' |
37422 | 2465 |
; |
2466 |
||
54890
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
haftmann
parents:
54338
diff
changeset
|
2467 |
@@{attribute (HOL) code} ( 'del' | 'equation' | 'abstype' | 'abstract' |
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
haftmann
parents:
54338
diff
changeset
|
2468 |
| 'drop:' ( const + ) | 'abort:' ( const + ) )? |
37422 | 2469 |
; |
2470 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
2471 |
@@{command (HOL) code_datatype} ( const + ) |
37422 | 2472 |
; |
2473 |
||
45232
eb56e1774c26
updating documentation: code_inline -> code_unfold; added documentation about attribute code_unfold_post
bulwahn
parents:
45192
diff
changeset
|
2474 |
@@{attribute (HOL) code_unfold} ( 'del' ) ? |
37422 | 2475 |
; |
2476 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
2477 |
@@{attribute (HOL) code_post} ( 'del' ) ? |
37422 | 2478 |
; |
2479 |
||
46028
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
haftmann
parents:
45944
diff
changeset
|
2480 |
@@{attribute (HOL) code_abbrev} |
45232
eb56e1774c26
updating documentation: code_inline -> code_unfold; added documentation about attribute code_unfold_post
bulwahn
parents:
45192
diff
changeset
|
2481 |
; |
eb56e1774c26
updating documentation: code_inline -> code_unfold; added documentation about attribute code_unfold_post
bulwahn
parents:
45192
diff
changeset
|
2482 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
2483 |
@@{command (HOL) code_thms} ( constexpr + ) ? |
37422 | 2484 |
; |
2485 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
2486 |
@@{command (HOL) code_deps} ( constexpr + ) ? |
37422 | 2487 |
; |
2488 |
||
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2489 |
@@{command (HOL) code_reserved} target ( @{syntax string} + ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2490 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2491 |
|
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2492 |
symbol_const: ( @'constant' const ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2493 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2494 |
|
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2495 |
symbol_typeconstructor: ( @'type_constructor' typeconstructor ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2496 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2497 |
|
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2498 |
symbol_class: ( @'type_class' class ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2499 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2500 |
|
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2501 |
symbol_class_relation: ( @'class_relation' class ( '<' | '\<subseteq>' ) class ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2502 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2503 |
|
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2504 |
symbol_class_instance: ( @'class_instance' typeconstructor @'::' class ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2505 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2506 |
|
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2507 |
symbol_module: ( @'code_module' name ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2508 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2509 |
|
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2510 |
syntax: @{syntax string} | ( @'infix' | @'infixl' | @'infixr' ) @{syntax nat} @{syntax string} |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2511 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2512 |
|
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2513 |
printing_const: symbol_const ( '\<rightharpoonup>' | '=>' ) \<newline> |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2514 |
( '(' target ')' syntax ? + @'and' ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2515 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2516 |
|
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2517 |
printing_typeconstructor: symbol_typeconstructor ( '\<rightharpoonup>' | '=>' ) \<newline> |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2518 |
( '(' target ')' syntax ? + @'and' ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2519 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2520 |
|
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2521 |
printing_class: symbol_class ( '\<rightharpoonup>' | '=>' ) \<newline> |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2522 |
( '(' target ')' @{syntax string} ? + @'and' ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2523 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2524 |
|
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2525 |
printing_class_relation: symbol_class_relation ( '\<rightharpoonup>' | '=>' ) \<newline> |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2526 |
( '(' target ')' @{syntax string} ? + @'and' ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2527 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2528 |
|
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2529 |
printing_class_instance: symbol_class_instance ( '\<rightharpoonup>' | '=>' ) \<newline> |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2530 |
( '(' target ')' '-' ? + @'and' ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2531 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2532 |
|
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2533 |
printing_module: symbol_module ( '\<rightharpoonup>' | '=>' ) \<newline> |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2534 |
( '(' target ')' ( @{syntax string} ( @'attach' ( const + ) ) ? ) ? + @'and' ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2535 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2536 |
|
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2537 |
@@{command (HOL) code_printing} ( ( printing_const | printing_typeconstructor |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2538 |
| printing_class | printing_class_relation | printing_class_instance |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2539 |
| printing_module ) + '|' ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2540 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2541 |
|
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2542 |
@@{command (HOL) code_identifier} ( ( symbol_const | symbol_typeconstructor |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2543 |
| symbol_class | symbol_class_relation | symbol_class_instance |
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2544 |
| symbol_module ) ( '\<rightharpoonup>' | '=>' ) \<newline> |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2545 |
( '(' target ')' @{syntax string} ? + @'and' ) + '|' ) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2546 |
; |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2547 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
2548 |
@@{command (HOL) code_monad} const const target |
37422 | 2549 |
; |
2550 |
||
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2551 |
@@{command (HOL) code_reflect} @{syntax string} \<newline> |
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2552 |
( @'datatypes' ( @{syntax string} '=' ( '_' | ( @{syntax string} + '|' ) + @'and' ) ) ) ? \<newline> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42215
diff
changeset
|
2553 |
( @'functions' ( @{syntax string} + ) ) ? ( @'file' @{syntax string} ) ? |
37422 | 2554 |
; |
2555 |
||
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2556 |
@@{command (HOL) code_pred} \<newline> ('(' @'modes' ':' modedecl ')')? \<newline> const |
45408
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
bulwahn
parents:
45232
diff
changeset
|
2557 |
; |
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
bulwahn
parents:
45232
diff
changeset
|
2558 |
|
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2559 |
modedecl: (modes | ((const ':' modes) \<newline> |
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54890
diff
changeset
|
2560 |
(@'and' ((const ':' modes @'and') +))?)) |
45408
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
bulwahn
parents:
45232
diff
changeset
|
2561 |
; |
47859 | 2562 |
|
45408
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
bulwahn
parents:
45232
diff
changeset
|
2563 |
modes: mode @'as' const |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
2564 |
\<close>} |
37422 | 2565 |
|
2566 |
\begin{description} |
|
2567 |
||
2568 |
\item @{command (HOL) "export_code"} generates code for a given list |
|
39608 | 2569 |
of constants in the specified target language(s). If no |
2570 |
serialization instruction is given, only abstract code is generated |
|
2571 |
internally. |
|
37422 | 2572 |
|
2573 |
Constants may be specified by giving them literally, referring to |
|
52895
a806aa7a5370
some documentation for adhoc overloading;
Christian Sternagel
parents:
52637
diff
changeset
|
2574 |
all executable constants within a certain theory by giving @{text |
55686
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
haftmann
parents:
55677
diff
changeset
|
2575 |
"name._"}, or referring to \emph{all} executable constants currently |
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
haftmann
parents:
55677
diff
changeset
|
2576 |
available by giving @{text "_"}. |
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
haftmann
parents:
55677
diff
changeset
|
2577 |
|
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
haftmann
parents:
55677
diff
changeset
|
2578 |
By default, exported identifiers are minimized per module. This |
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
haftmann
parents:
55677
diff
changeset
|
2579 |
can be suppressed by prepending @{keyword "open"} before the list |
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
haftmann
parents:
55677
diff
changeset
|
2580 |
of contants. |
37422 | 2581 |
|
2582 |
By default, for each involved theory one corresponding name space |
|
52895
a806aa7a5370
some documentation for adhoc overloading;
Christian Sternagel
parents:
52637
diff
changeset
|
2583 |
module is generated. Alternatively, a module name may be specified |
37422 | 2584 |
after the @{keyword "module_name"} keyword; then \emph{all} code is |
2585 |
placed in this module. |
|
2586 |
||
39608 | 2587 |
For \emph{SML}, \emph{OCaml} and \emph{Scala} the file specification |
2588 |
refers to a single file; for \emph{Haskell}, it refers to a whole |
|
2589 |
directory, where code is generated in multiple files reflecting the |
|
2590 |
module hierarchy. Omitting the file specification denotes standard |
|
37749 | 2591 |
output. |
37422 | 2592 |
|
55677 | 2593 |
Serializers take an optional list of arguments in parentheses. |
39608 | 2594 |
For \emph{Haskell} a module name prefix may be given using the |
2595 |
``@{text "root:"}'' argument; ``@{text string_classes}'' adds a |
|
2596 |
``@{verbatim "deriving (Read, Show)"}'' clause to each appropriate |
|
2597 |
datatype declaration. |
|
37422 | 2598 |
|
52637
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
haftmann
parents:
52476
diff
changeset
|
2599 |
\item @{attribute (HOL) code} declare code equations for code |
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
haftmann
parents:
52476
diff
changeset
|
2600 |
generation. Variant @{text "code equation"} declares a conventional |
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
haftmann
parents:
52476
diff
changeset
|
2601 |
equation as code equation. Variants @{text "code abstype"} and |
38462
34d3de1254cd
formally document `code abstype` and `code abstract` attributes
haftmann
parents:
37820
diff
changeset
|
2602 |
@{text "code abstract"} declare abstract datatype certificates or |
34d3de1254cd
formally document `code abstype` and `code abstract` attributes
haftmann
parents:
37820
diff
changeset
|
2603 |
code equations on abstract datatype representations respectively. |
52637
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
haftmann
parents:
52476
diff
changeset
|
2604 |
Vanilla @{text "code"} falls back to @{text "code equation"} |
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
haftmann
parents:
52476
diff
changeset
|
2605 |
or @{text "code abstype"} depending on the syntactic shape |
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
haftmann
parents:
52476
diff
changeset
|
2606 |
of the underlying equation. Variant @{text "code del"} |
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
haftmann
parents:
52476
diff
changeset
|
2607 |
deselects a code equation for code generation. |
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
haftmann
parents:
52476
diff
changeset
|
2608 |
|
54890
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
haftmann
parents:
54338
diff
changeset
|
2609 |
Variants @{text "code drop:"} and @{text "code abort:"} take |
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
haftmann
parents:
54338
diff
changeset
|
2610 |
a list of constant as arguments and drop all code equations declared |
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
haftmann
parents:
54338
diff
changeset
|
2611 |
for them. In the case of {text abort}, these constants then are |
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
haftmann
parents:
54338
diff
changeset
|
2612 |
are not required to have a definition by means of code equations; |
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
haftmann
parents:
54338
diff
changeset
|
2613 |
if needed these are implemented by program abort (exception) instead. |
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
haftmann
parents:
54338
diff
changeset
|
2614 |
|
52637
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
haftmann
parents:
52476
diff
changeset
|
2615 |
Usually packages introducing code equations provide a reasonable |
60657 | 2616 |
default setup for selection. |
37422 | 2617 |
|
2618 |
\item @{command (HOL) "code_datatype"} specifies a constructor set |
|
2619 |
for a logical type. |
|
2620 |
||
2621 |
\item @{command (HOL) "print_codesetup"} gives an overview on |
|
2622 |
selected code equations and code generator datatypes. |
|
2623 |
||
45232
eb56e1774c26
updating documentation: code_inline -> code_unfold; added documentation about attribute code_unfold_post
bulwahn
parents:
45192
diff
changeset
|
2624 |
\item @{attribute (HOL) code_unfold} declares (or with option |
46028
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
haftmann
parents:
45944
diff
changeset
|
2625 |
``@{text "del"}'' removes) theorems which during preprocessing |
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
haftmann
parents:
45944
diff
changeset
|
2626 |
are applied as rewrite rules to any code equation or evaluation |
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
haftmann
parents:
45944
diff
changeset
|
2627 |
input. |
37422 | 2628 |
|
39608 | 2629 |
\item @{attribute (HOL) code_post} declares (or with option ``@{text |
2630 |
"del"}'' removes) theorems which are applied as rewrite rules to any |
|
2631 |
result of an evaluation. |
|
37422 | 2632 |
|
56929 | 2633 |
\item @{attribute (HOL) code_abbrev} declares (or with option ``@{text |
2634 |
"del"}'' removes) equations which are |
|
46028
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
haftmann
parents:
45944
diff
changeset
|
2635 |
applied as rewrite rules to any result of an evaluation and |
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
haftmann
parents:
45944
diff
changeset
|
2636 |
symmetrically during preprocessing to any code equation or evaluation |
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
haftmann
parents:
45944
diff
changeset
|
2637 |
input. |
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
haftmann
parents:
45944
diff
changeset
|
2638 |
|
39608 | 2639 |
\item @{command (HOL) "print_codeproc"} prints the setup of the code |
2640 |
generator preprocessor. |
|
37422 | 2641 |
|
2642 |
\item @{command (HOL) "code_thms"} prints a list of theorems |
|
2643 |
representing the corresponding program containing all given |
|
2644 |
constants after preprocessing. |
|
2645 |
||
2646 |
\item @{command (HOL) "code_deps"} visualizes dependencies of |
|
2647 |
theorems representing the corresponding program containing all given |
|
2648 |
constants after preprocessing. |
|
2649 |
||
2650 |
\item @{command (HOL) "code_reserved"} declares a list of names as |
|
2651 |
reserved for a given target, preventing it to be shadowed by any |
|
2652 |
generated code. |
|
2653 |
||
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2654 |
\item @{command (HOL) "code_printing"} associates a series of symbols |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2655 |
(constants, type constructors, classes, class relations, instances, |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2656 |
module names) with target-specific serializations; omitting a serialization |
55372 | 2657 |
deletes an existing serialization. |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2658 |
|
37422 | 2659 |
\item @{command (HOL) "code_monad"} provides an auxiliary mechanism |
2660 |
to generate monadic code for Haskell. |
|
2661 |
||
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2662 |
\item @{command (HOL) "code_identifier"} associates a a series of symbols |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2663 |
(constants, type constructors, classes, class relations, instances, |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
50879
diff
changeset
|
2664 |
module names) with target-specific hints how these symbols shall be named. |
55293
42cf5802d36a
code generation: explicitly declared identifiers gain predence over implicit ones
haftmann
parents:
55112
diff
changeset
|
2665 |
These hints gain precedence over names for symbols with no hints at all. |
42cf5802d36a
code generation: explicitly declared identifiers gain predence over implicit ones
haftmann
parents:
55112
diff
changeset
|
2666 |
Conflicting hints are subject to name disambiguation. |
42cf5802d36a
code generation: explicitly declared identifiers gain predence over implicit ones
haftmann
parents:
55112
diff
changeset
|
2667 |
\emph{Warning:} It is at the discretion |
52476 | 2668 |
of the user to ensure that name prefixes of identifiers in compound |
2669 |
statements like type classes or datatypes are still the same. |
|
37422 | 2670 |
|
39608 | 2671 |
\item @{command (HOL) "code_reflect"} without a ``@{text "file"}'' |
2672 |
argument compiles code into the system runtime environment and |
|
2673 |
modifies the code generator setup that future invocations of system |
|
2674 |
runtime code generation referring to one of the ``@{text |
|
47859 | 2675 |
"datatypes"}'' or ``@{text "functions"}'' entities use these |
2676 |
precompiled entities. With a ``@{text "file"}'' argument, the |
|
2677 |
corresponding code is generated into that specified file without |
|
2678 |
modifying the code generator setup. |
|
2679 |
||
2680 |
\item @{command (HOL) "code_pred"} creates code equations for a |
|
2681 |
predicate given a set of introduction rules. Optional mode |
|
2682 |
annotations determine which arguments are supposed to be input or |
|
2683 |
output. If alternative introduction rules are declared, one must |
|
2684 |
prove a corresponding elimination rule. |
|
45408
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
bulwahn
parents:
45232
diff
changeset
|
2685 |
|
37422 | 2686 |
\end{description} |
58618 | 2687 |
\<close> |
37422 | 2688 |
|
26840 | 2689 |
end |