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