author | wenzelm |
Sun, 20 Nov 2011 21:07:10 +0100 | |
changeset 45607 | 16b4f5774621 |
parent 42163 | 392fd6c4669c |
child 45694 | 4a8743618257 |
permissions | -rw-r--r-- |
5181
4ba3787d9709
New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff
changeset
|
1 |
(* Title: HOL/Datatype.thy |
20819 | 2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
11954 | 3 |
Author: Stefan Berghofer and Markus Wenzel, TU Muenchen |
5181
4ba3787d9709
New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff
changeset
|
4 |
*) |
4ba3787d9709
New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff
changeset
|
5 |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
6 |
header {* Datatype package: constructing datatypes from Cartesian Products and Disjoint Sums *} |
11954 | 7 |
|
15131 | 8 |
theory Datatype |
33959
2afc55e8ed27
bootstrap datatype_rep_proofs in Datatype.thy (avoids unchecked dynamic name references)
haftmann
parents:
33633
diff
changeset
|
9 |
imports Product_Type Sum_Type Nat |
2afc55e8ed27
bootstrap datatype_rep_proofs in Datatype.thy (avoids unchecked dynamic name references)
haftmann
parents:
33633
diff
changeset
|
10 |
uses |
33963
977b94b64905
renamed former datatype.ML to datatype_data.ML; datatype.ML provides uniform view on datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33959
diff
changeset
|
11 |
("Tools/Datatype/datatype.ML") |
33959
2afc55e8ed27
bootstrap datatype_rep_proofs in Datatype.thy (avoids unchecked dynamic name references)
haftmann
parents:
33633
diff
changeset
|
12 |
("Tools/inductive_realizer.ML") |
2afc55e8ed27
bootstrap datatype_rep_proofs in Datatype.thy (avoids unchecked dynamic name references)
haftmann
parents:
33633
diff
changeset
|
13 |
("Tools/Datatype/datatype_realizer.ML") |
15131 | 14 |
begin |
11954 | 15 |
|
40969 | 16 |
subsection {* Prelude: lifting over function space *} |
17 |
||
41505
6d19301074cf
"enriched_type" replaces less specific "type_lifting"
haftmann
parents:
41372
diff
changeset
|
18 |
enriched_type map_fun: map_fun |
40969 | 19 |
by (simp_all add: fun_eq_iff) |
20 |
||
21 |
||
33959
2afc55e8ed27
bootstrap datatype_rep_proofs in Datatype.thy (avoids unchecked dynamic name references)
haftmann
parents:
33633
diff
changeset
|
22 |
subsection {* The datatype universe *} |
2afc55e8ed27
bootstrap datatype_rep_proofs in Datatype.thy (avoids unchecked dynamic name references)
haftmann
parents:
33633
diff
changeset
|
23 |
|
20819 | 24 |
typedef (Node) |
25 |
('a,'b) node = "{p. EX f x k. p = (f::nat=>'b+nat, x::'a+nat) & f k = Inr 0}" |
|
26 |
--{*it is a subtype of @{text "(nat=>'b+nat) * ('a+nat)"}*} |
|
27 |
by auto |
|
28 |
||
29 |
text{*Datatypes will be represented by sets of type @{text node}*} |
|
30 |
||
42163
392fd6c4669c
renewing specifications in HOL: replacing types by type_synonym
bulwahn
parents:
41505
diff
changeset
|
31 |
type_synonym 'a item = "('a, unit) node set" |
392fd6c4669c
renewing specifications in HOL: replacing types by type_synonym
bulwahn
parents:
41505
diff
changeset
|
32 |
type_synonym ('a, 'b) dtree = "('a, 'b) node set" |
20819 | 33 |
|
34 |
consts |
|
35 |
Push :: "[('b + nat), nat => ('b + nat)] => (nat => ('b + nat))" |
|
36 |
||
37 |
Push_Node :: "[('b + nat), ('a, 'b) node] => ('a, 'b) node" |
|
38 |
ndepth :: "('a, 'b) node => nat" |
|
39 |
||
40 |
Atom :: "('a + nat) => ('a, 'b) dtree" |
|
41 |
Leaf :: "'a => ('a, 'b) dtree" |
|
42 |
Numb :: "nat => ('a, 'b) dtree" |
|
43 |
Scons :: "[('a, 'b) dtree, ('a, 'b) dtree] => ('a, 'b) dtree" |
|
44 |
In0 :: "('a, 'b) dtree => ('a, 'b) dtree" |
|
45 |
In1 :: "('a, 'b) dtree => ('a, 'b) dtree" |
|
46 |
Lim :: "('b => ('a, 'b) dtree) => ('a, 'b) dtree" |
|
47 |
||
48 |
ntrunc :: "[nat, ('a, 'b) dtree] => ('a, 'b) dtree" |
|
49 |
||
50 |
uprod :: "[('a, 'b) dtree set, ('a, 'b) dtree set]=> ('a, 'b) dtree set" |
|
51 |
usum :: "[('a, 'b) dtree set, ('a, 'b) dtree set]=> ('a, 'b) dtree set" |
|
52 |
||
53 |
Split :: "[[('a, 'b) dtree, ('a, 'b) dtree]=>'c, ('a, 'b) dtree] => 'c" |
|
54 |
Case :: "[[('a, 'b) dtree]=>'c, [('a, 'b) dtree]=>'c, ('a, 'b) dtree] => 'c" |
|
55 |
||
56 |
dprod :: "[(('a, 'b) dtree * ('a, 'b) dtree)set, (('a, 'b) dtree * ('a, 'b) dtree)set] |
|
57 |
=> (('a, 'b) dtree * ('a, 'b) dtree)set" |
|
58 |
dsum :: "[(('a, 'b) dtree * ('a, 'b) dtree)set, (('a, 'b) dtree * ('a, 'b) dtree)set] |
|
59 |
=> (('a, 'b) dtree * ('a, 'b) dtree)set" |
|
60 |
||
61 |
||
62 |
defs |
|
63 |
||
64 |
Push_Node_def: "Push_Node == (%n x. Abs_Node (apfst (Push n) (Rep_Node x)))" |
|
65 |
||
66 |
(*crude "lists" of nats -- needed for the constructions*) |
|
67 |
Push_def: "Push == (%b h. nat_case b h)" |
|
68 |
||
69 |
(** operations on S-expressions -- sets of nodes **) |
|
70 |
||
71 |
(*S-expression constructors*) |
|
72 |
Atom_def: "Atom == (%x. {Abs_Node((%k. Inr 0, x))})" |
|
73 |
Scons_def: "Scons M N == (Push_Node (Inr 1) ` M) Un (Push_Node (Inr (Suc 1)) ` N)" |
|
74 |
||
75 |
(*Leaf nodes, with arbitrary or nat labels*) |
|
76 |
Leaf_def: "Leaf == Atom o Inl" |
|
77 |
Numb_def: "Numb == Atom o Inr" |
|
78 |
||
79 |
(*Injections of the "disjoint sum"*) |
|
80 |
In0_def: "In0(M) == Scons (Numb 0) M" |
|
81 |
In1_def: "In1(M) == Scons (Numb 1) M" |
|
82 |
||
83 |
(*Function spaces*) |
|
84 |
Lim_def: "Lim f == Union {z. ? x. z = Push_Node (Inl x) ` (f x)}" |
|
85 |
||
86 |
(*the set of nodes with depth less than k*) |
|
87 |
ndepth_def: "ndepth(n) == (%(f,x). LEAST k. f k = Inr 0) (Rep_Node n)" |
|
88 |
ntrunc_def: "ntrunc k N == {n. n:N & ndepth(n)<k}" |
|
89 |
||
90 |
(*products and sums for the "universe"*) |
|
91 |
uprod_def: "uprod A B == UN x:A. UN y:B. { Scons x y }" |
|
92 |
usum_def: "usum A B == In0`A Un In1`B" |
|
93 |
||
94 |
(*the corresponding eliminators*) |
|
95 |
Split_def: "Split c M == THE u. EX x y. M = Scons x y & u = c x y" |
|
96 |
||
97 |
Case_def: "Case c d M == THE u. (EX x . M = In0(x) & u = c(x)) |
|
98 |
| (EX y . M = In1(y) & u = d(y))" |
|
99 |
||
100 |
||
101 |
(** equality for the "universe" **) |
|
102 |
||
103 |
dprod_def: "dprod r s == UN (x,x'):r. UN (y,y'):s. {(Scons x y, Scons x' y')}" |
|
104 |
||
105 |
dsum_def: "dsum r s == (UN (x,x'):r. {(In0(x),In0(x'))}) Un |
|
106 |
(UN (y,y'):s. {(In1(y),In1(y'))})" |
|
107 |
||
108 |
||
109 |
||
110 |
lemma apfst_convE: |
|
111 |
"[| q = apfst f p; !!x y. [| p = (x,y); q = (f(x),y) |] ==> R |
|
112 |
|] ==> R" |
|
113 |
by (force simp add: apfst_def) |
|
114 |
||
115 |
(** Push -- an injection, analogous to Cons on lists **) |
|
116 |
||
117 |
lemma Push_inject1: "Push i f = Push j g ==> i=j" |
|
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
118 |
apply (simp add: Push_def fun_eq_iff) |
20819 | 119 |
apply (drule_tac x=0 in spec, simp) |
120 |
done |
|
121 |
||
122 |
lemma Push_inject2: "Push i f = Push j g ==> f=g" |
|
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
123 |
apply (auto simp add: Push_def fun_eq_iff) |
20819 | 124 |
apply (drule_tac x="Suc x" in spec, simp) |
125 |
done |
|
126 |
||
127 |
lemma Push_inject: |
|
128 |
"[| Push i f =Push j g; [| i=j; f=g |] ==> P |] ==> P" |
|
129 |
by (blast dest: Push_inject1 Push_inject2) |
|
130 |
||
131 |
lemma Push_neq_K0: "Push (Inr (Suc k)) f = (%z. Inr 0) ==> P" |
|
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
132 |
by (auto simp add: Push_def fun_eq_iff split: nat.split_asm) |
20819 | 133 |
|
45607 | 134 |
lemmas Abs_Node_inj = Abs_Node_inject [THEN [2] rev_iffD1] |
20819 | 135 |
|
136 |
||
137 |
(*** Introduction rules for Node ***) |
|
138 |
||
139 |
lemma Node_K0_I: "(%k. Inr 0, a) : Node" |
|
140 |
by (simp add: Node_def) |
|
141 |
||
142 |
lemma Node_Push_I: "p: Node ==> apfst (Push i) p : Node" |
|
143 |
apply (simp add: Node_def Push_def) |
|
144 |
apply (fast intro!: apfst_conv nat_case_Suc [THEN trans]) |
|
145 |
done |
|
146 |
||
147 |
||
148 |
subsection{*Freeness: Distinctness of Constructors*} |
|
149 |
||
150 |
(** Scons vs Atom **) |
|
151 |
||
152 |
lemma Scons_not_Atom [iff]: "Scons M N \<noteq> Atom(a)" |
|
35216 | 153 |
unfolding Atom_def Scons_def Push_Node_def One_nat_def |
154 |
by (blast intro: Node_K0_I Rep_Node [THEN Node_Push_I] |
|
20819 | 155 |
dest!: Abs_Node_inj |
156 |
elim!: apfst_convE sym [THEN Push_neq_K0]) |
|
157 |
||
45607 | 158 |
lemmas Atom_not_Scons [iff] = Scons_not_Atom [THEN not_sym] |
21407 | 159 |
|
20819 | 160 |
|
161 |
(*** Injectiveness ***) |
|
162 |
||
163 |
(** Atomic nodes **) |
|
164 |
||
165 |
lemma inj_Atom: "inj(Atom)" |
|
166 |
apply (simp add: Atom_def) |
|
167 |
apply (blast intro!: inj_onI Node_K0_I dest!: Abs_Node_inj) |
|
168 |
done |
|
45607 | 169 |
lemmas Atom_inject = inj_Atom [THEN injD] |
20819 | 170 |
|
171 |
lemma Atom_Atom_eq [iff]: "(Atom(a)=Atom(b)) = (a=b)" |
|
172 |
by (blast dest!: Atom_inject) |
|
173 |
||
174 |
lemma inj_Leaf: "inj(Leaf)" |
|
175 |
apply (simp add: Leaf_def o_def) |
|
176 |
apply (rule inj_onI) |
|
177 |
apply (erule Atom_inject [THEN Inl_inject]) |
|
178 |
done |
|
179 |
||
45607 | 180 |
lemmas Leaf_inject [dest!] = inj_Leaf [THEN injD] |
20819 | 181 |
|
182 |
lemma inj_Numb: "inj(Numb)" |
|
183 |
apply (simp add: Numb_def o_def) |
|
184 |
apply (rule inj_onI) |
|
185 |
apply (erule Atom_inject [THEN Inr_inject]) |
|
186 |
done |
|
187 |
||
45607 | 188 |
lemmas Numb_inject [dest!] = inj_Numb [THEN injD] |
20819 | 189 |
|
190 |
||
191 |
(** Injectiveness of Push_Node **) |
|
192 |
||
193 |
lemma Push_Node_inject: |
|
194 |
"[| Push_Node i m =Push_Node j n; [| i=j; m=n |] ==> P |
|
195 |
|] ==> P" |
|
196 |
apply (simp add: Push_Node_def) |
|
197 |
apply (erule Abs_Node_inj [THEN apfst_convE]) |
|
198 |
apply (rule Rep_Node [THEN Node_Push_I])+ |
|
199 |
apply (erule sym [THEN apfst_convE]) |
|
200 |
apply (blast intro: Rep_Node_inject [THEN iffD1] trans sym elim!: Push_inject) |
|
201 |
done |
|
202 |
||
203 |
||
204 |
(** Injectiveness of Scons **) |
|
205 |
||
206 |
lemma Scons_inject_lemma1: "Scons M N <= Scons M' N' ==> M<=M'" |
|
35216 | 207 |
unfolding Scons_def One_nat_def |
208 |
by (blast dest!: Push_Node_inject) |
|
20819 | 209 |
|
210 |
lemma Scons_inject_lemma2: "Scons M N <= Scons M' N' ==> N<=N'" |
|
35216 | 211 |
unfolding Scons_def One_nat_def |
212 |
by (blast dest!: Push_Node_inject) |
|
20819 | 213 |
|
214 |
lemma Scons_inject1: "Scons M N = Scons M' N' ==> M=M'" |
|
215 |
apply (erule equalityE) |
|
216 |
apply (iprover intro: equalityI Scons_inject_lemma1) |
|
217 |
done |
|
218 |
||
219 |
lemma Scons_inject2: "Scons M N = Scons M' N' ==> N=N'" |
|
220 |
apply (erule equalityE) |
|
221 |
apply (iprover intro: equalityI Scons_inject_lemma2) |
|
222 |
done |
|
223 |
||
224 |
lemma Scons_inject: |
|
225 |
"[| Scons M N = Scons M' N'; [| M=M'; N=N' |] ==> P |] ==> P" |
|
226 |
by (iprover dest: Scons_inject1 Scons_inject2) |
|
227 |
||
228 |
lemma Scons_Scons_eq [iff]: "(Scons M N = Scons M' N') = (M=M' & N=N')" |
|
229 |
by (blast elim!: Scons_inject) |
|
230 |
||
231 |
(*** Distinctness involving Leaf and Numb ***) |
|
232 |
||
233 |
(** Scons vs Leaf **) |
|
234 |
||
235 |
lemma Scons_not_Leaf [iff]: "Scons M N \<noteq> Leaf(a)" |
|
35216 | 236 |
unfolding Leaf_def o_def by (rule Scons_not_Atom) |
20819 | 237 |
|
45607 | 238 |
lemmas Leaf_not_Scons [iff] = Scons_not_Leaf [THEN not_sym] |
20819 | 239 |
|
240 |
(** Scons vs Numb **) |
|
241 |
||
242 |
lemma Scons_not_Numb [iff]: "Scons M N \<noteq> Numb(k)" |
|
35216 | 243 |
unfolding Numb_def o_def by (rule Scons_not_Atom) |
20819 | 244 |
|
45607 | 245 |
lemmas Numb_not_Scons [iff] = Scons_not_Numb [THEN not_sym] |
20819 | 246 |
|
247 |
||
248 |
(** Leaf vs Numb **) |
|
249 |
||
250 |
lemma Leaf_not_Numb [iff]: "Leaf(a) \<noteq> Numb(k)" |
|
251 |
by (simp add: Leaf_def Numb_def) |
|
252 |
||
45607 | 253 |
lemmas Numb_not_Leaf [iff] = Leaf_not_Numb [THEN not_sym] |
20819 | 254 |
|
255 |
||
256 |
(*** ndepth -- the depth of a node ***) |
|
257 |
||
258 |
lemma ndepth_K0: "ndepth (Abs_Node(%k. Inr 0, x)) = 0" |
|
259 |
by (simp add: ndepth_def Node_K0_I [THEN Abs_Node_inverse] Least_equality) |
|
260 |
||
261 |
lemma ndepth_Push_Node_aux: |
|
262 |
"nat_case (Inr (Suc i)) f k = Inr 0 --> Suc(LEAST x. f x = Inr 0) <= k" |
|
263 |
apply (induct_tac "k", auto) |
|
264 |
apply (erule Least_le) |
|
265 |
done |
|
266 |
||
267 |
lemma ndepth_Push_Node: |
|
268 |
"ndepth (Push_Node (Inr (Suc i)) n) = Suc(ndepth(n))" |
|
269 |
apply (insert Rep_Node [of n, unfolded Node_def]) |
|
270 |
apply (auto simp add: ndepth_def Push_Node_def |
|
271 |
Rep_Node [THEN Node_Push_I, THEN Abs_Node_inverse]) |
|
272 |
apply (rule Least_equality) |
|
273 |
apply (auto simp add: Push_def ndepth_Push_Node_aux) |
|
274 |
apply (erule LeastI) |
|
275 |
done |
|
276 |
||
277 |
||
278 |
(*** ntrunc applied to the various node sets ***) |
|
279 |
||
280 |
lemma ntrunc_0 [simp]: "ntrunc 0 M = {}" |
|
281 |
by (simp add: ntrunc_def) |
|
282 |
||
283 |
lemma ntrunc_Atom [simp]: "ntrunc (Suc k) (Atom a) = Atom(a)" |
|
284 |
by (auto simp add: Atom_def ntrunc_def ndepth_K0) |
|
285 |
||
286 |
lemma ntrunc_Leaf [simp]: "ntrunc (Suc k) (Leaf a) = Leaf(a)" |
|
35216 | 287 |
unfolding Leaf_def o_def by (rule ntrunc_Atom) |
20819 | 288 |
|
289 |
lemma ntrunc_Numb [simp]: "ntrunc (Suc k) (Numb i) = Numb(i)" |
|
35216 | 290 |
unfolding Numb_def o_def by (rule ntrunc_Atom) |
20819 | 291 |
|
292 |
lemma ntrunc_Scons [simp]: |
|
293 |
"ntrunc (Suc k) (Scons M N) = Scons (ntrunc k M) (ntrunc k N)" |
|
35216 | 294 |
unfolding Scons_def ntrunc_def One_nat_def |
295 |
by (auto simp add: ndepth_Push_Node) |
|
20819 | 296 |
|
297 |
||
298 |
||
299 |
(** Injection nodes **) |
|
300 |
||
301 |
lemma ntrunc_one_In0 [simp]: "ntrunc (Suc 0) (In0 M) = {}" |
|
302 |
apply (simp add: In0_def) |
|
303 |
apply (simp add: Scons_def) |
|
304 |
done |
|
305 |
||
306 |
lemma ntrunc_In0 [simp]: "ntrunc (Suc(Suc k)) (In0 M) = In0 (ntrunc (Suc k) M)" |
|
307 |
by (simp add: In0_def) |
|
308 |
||
309 |
lemma ntrunc_one_In1 [simp]: "ntrunc (Suc 0) (In1 M) = {}" |
|
310 |
apply (simp add: In1_def) |
|
311 |
apply (simp add: Scons_def) |
|
312 |
done |
|
313 |
||
314 |
lemma ntrunc_In1 [simp]: "ntrunc (Suc(Suc k)) (In1 M) = In1 (ntrunc (Suc k) M)" |
|
315 |
by (simp add: In1_def) |
|
316 |
||
317 |
||
318 |
subsection{*Set Constructions*} |
|
319 |
||
320 |
||
321 |
(*** Cartesian Product ***) |
|
322 |
||
323 |
lemma uprodI [intro!]: "[| M:A; N:B |] ==> Scons M N : uprod A B" |
|
324 |
by (simp add: uprod_def) |
|
325 |
||
326 |
(*The general elimination rule*) |
|
327 |
lemma uprodE [elim!]: |
|
328 |
"[| c : uprod A B; |
|
329 |
!!x y. [| x:A; y:B; c = Scons x y |] ==> P |
|
330 |
|] ==> P" |
|
331 |
by (auto simp add: uprod_def) |
|
332 |
||
333 |
||
334 |
(*Elimination of a pair -- introduces no eigenvariables*) |
|
335 |
lemma uprodE2: "[| Scons M N : uprod A B; [| M:A; N:B |] ==> P |] ==> P" |
|
336 |
by (auto simp add: uprod_def) |
|
337 |
||
338 |
||
339 |
(*** Disjoint Sum ***) |
|
340 |
||
341 |
lemma usum_In0I [intro]: "M:A ==> In0(M) : usum A B" |
|
342 |
by (simp add: usum_def) |
|
343 |
||
344 |
lemma usum_In1I [intro]: "N:B ==> In1(N) : usum A B" |
|
345 |
by (simp add: usum_def) |
|
346 |
||
347 |
lemma usumE [elim!]: |
|
348 |
"[| u : usum A B; |
|
349 |
!!x. [| x:A; u=In0(x) |] ==> P; |
|
350 |
!!y. [| y:B; u=In1(y) |] ==> P |
|
351 |
|] ==> P" |
|
352 |
by (auto simp add: usum_def) |
|
353 |
||
354 |
||
355 |
(** Injection **) |
|
356 |
||
357 |
lemma In0_not_In1 [iff]: "In0(M) \<noteq> In1(N)" |
|
35216 | 358 |
unfolding In0_def In1_def One_nat_def by auto |
20819 | 359 |
|
45607 | 360 |
lemmas In1_not_In0 [iff] = In0_not_In1 [THEN not_sym] |
20819 | 361 |
|
362 |
lemma In0_inject: "In0(M) = In0(N) ==> M=N" |
|
363 |
by (simp add: In0_def) |
|
364 |
||
365 |
lemma In1_inject: "In1(M) = In1(N) ==> M=N" |
|
366 |
by (simp add: In1_def) |
|
367 |
||
368 |
lemma In0_eq [iff]: "(In0 M = In0 N) = (M=N)" |
|
369 |
by (blast dest!: In0_inject) |
|
370 |
||
371 |
lemma In1_eq [iff]: "(In1 M = In1 N) = (M=N)" |
|
372 |
by (blast dest!: In1_inject) |
|
373 |
||
374 |
lemma inj_In0: "inj In0" |
|
375 |
by (blast intro!: inj_onI) |
|
376 |
||
377 |
lemma inj_In1: "inj In1" |
|
378 |
by (blast intro!: inj_onI) |
|
379 |
||
380 |
||
381 |
(*** Function spaces ***) |
|
382 |
||
383 |
lemma Lim_inject: "Lim f = Lim g ==> f = g" |
|
384 |
apply (simp add: Lim_def) |
|
385 |
apply (rule ext) |
|
386 |
apply (blast elim!: Push_Node_inject) |
|
387 |
done |
|
388 |
||
389 |
||
390 |
(*** proving equality of sets and functions using ntrunc ***) |
|
391 |
||
392 |
lemma ntrunc_subsetI: "ntrunc k M <= M" |
|
393 |
by (auto simp add: ntrunc_def) |
|
394 |
||
395 |
lemma ntrunc_subsetD: "(!!k. ntrunc k M <= N) ==> M<=N" |
|
396 |
by (auto simp add: ntrunc_def) |
|
397 |
||
398 |
(*A generalized form of the take-lemma*) |
|
399 |
lemma ntrunc_equality: "(!!k. ntrunc k M = ntrunc k N) ==> M=N" |
|
400 |
apply (rule equalityI) |
|
401 |
apply (rule_tac [!] ntrunc_subsetD) |
|
402 |
apply (rule_tac [!] ntrunc_subsetI [THEN [2] subset_trans], auto) |
|
403 |
done |
|
404 |
||
405 |
lemma ntrunc_o_equality: |
|
406 |
"[| !!k. (ntrunc(k) o h1) = (ntrunc(k) o h2) |] ==> h1=h2" |
|
407 |
apply (rule ntrunc_equality [THEN ext]) |
|
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
408 |
apply (simp add: fun_eq_iff) |
20819 | 409 |
done |
410 |
||
411 |
||
412 |
(*** Monotonicity ***) |
|
413 |
||
414 |
lemma uprod_mono: "[| A<=A'; B<=B' |] ==> uprod A B <= uprod A' B'" |
|
415 |
by (simp add: uprod_def, blast) |
|
416 |
||
417 |
lemma usum_mono: "[| A<=A'; B<=B' |] ==> usum A B <= usum A' B'" |
|
418 |
by (simp add: usum_def, blast) |
|
419 |
||
420 |
lemma Scons_mono: "[| M<=M'; N<=N' |] ==> Scons M N <= Scons M' N'" |
|
421 |
by (simp add: Scons_def, blast) |
|
422 |
||
423 |
lemma In0_mono: "M<=N ==> In0(M) <= In0(N)" |
|
35216 | 424 |
by (simp add: In0_def Scons_mono) |
20819 | 425 |
|
426 |
lemma In1_mono: "M<=N ==> In1(M) <= In1(N)" |
|
35216 | 427 |
by (simp add: In1_def Scons_mono) |
20819 | 428 |
|
429 |
||
430 |
(*** Split and Case ***) |
|
431 |
||
432 |
lemma Split [simp]: "Split c (Scons M N) = c M N" |
|
433 |
by (simp add: Split_def) |
|
434 |
||
435 |
lemma Case_In0 [simp]: "Case c d (In0 M) = c(M)" |
|
436 |
by (simp add: Case_def) |
|
437 |
||
438 |
lemma Case_In1 [simp]: "Case c d (In1 N) = d(N)" |
|
439 |
by (simp add: Case_def) |
|
440 |
||
441 |
||
442 |
||
443 |
(**** UN x. B(x) rules ****) |
|
444 |
||
445 |
lemma ntrunc_UN1: "ntrunc k (UN x. f(x)) = (UN x. ntrunc k (f x))" |
|
446 |
by (simp add: ntrunc_def, blast) |
|
447 |
||
448 |
lemma Scons_UN1_x: "Scons (UN x. f x) M = (UN x. Scons (f x) M)" |
|
449 |
by (simp add: Scons_def, blast) |
|
450 |
||
451 |
lemma Scons_UN1_y: "Scons M (UN x. f x) = (UN x. Scons M (f x))" |
|
452 |
by (simp add: Scons_def, blast) |
|
453 |
||
454 |
lemma In0_UN1: "In0(UN x. f(x)) = (UN x. In0(f(x)))" |
|
455 |
by (simp add: In0_def Scons_UN1_y) |
|
456 |
||
457 |
lemma In1_UN1: "In1(UN x. f(x)) = (UN x. In1(f(x)))" |
|
458 |
by (simp add: In1_def Scons_UN1_y) |
|
459 |
||
460 |
||
461 |
(*** Equality for Cartesian Product ***) |
|
462 |
||
463 |
lemma dprodI [intro!]: |
|
464 |
"[| (M,M'):r; (N,N'):s |] ==> (Scons M N, Scons M' N') : dprod r s" |
|
465 |
by (auto simp add: dprod_def) |
|
466 |
||
467 |
(*The general elimination rule*) |
|
468 |
lemma dprodE [elim!]: |
|
469 |
"[| c : dprod r s; |
|
470 |
!!x y x' y'. [| (x,x') : r; (y,y') : s; |
|
471 |
c = (Scons x y, Scons x' y') |] ==> P |
|
472 |
|] ==> P" |
|
473 |
by (auto simp add: dprod_def) |
|
474 |
||
475 |
||
476 |
(*** Equality for Disjoint Sum ***) |
|
477 |
||
478 |
lemma dsum_In0I [intro]: "(M,M'):r ==> (In0(M), In0(M')) : dsum r s" |
|
479 |
by (auto simp add: dsum_def) |
|
480 |
||
481 |
lemma dsum_In1I [intro]: "(N,N'):s ==> (In1(N), In1(N')) : dsum r s" |
|
482 |
by (auto simp add: dsum_def) |
|
483 |
||
484 |
lemma dsumE [elim!]: |
|
485 |
"[| w : dsum r s; |
|
486 |
!!x x'. [| (x,x') : r; w = (In0(x), In0(x')) |] ==> P; |
|
487 |
!!y y'. [| (y,y') : s; w = (In1(y), In1(y')) |] ==> P |
|
488 |
|] ==> P" |
|
489 |
by (auto simp add: dsum_def) |
|
490 |
||
491 |
||
492 |
(*** Monotonicity ***) |
|
493 |
||
494 |
lemma dprod_mono: "[| r<=r'; s<=s' |] ==> dprod r s <= dprod r' s'" |
|
495 |
by blast |
|
496 |
||
497 |
lemma dsum_mono: "[| r<=r'; s<=s' |] ==> dsum r s <= dsum r' s'" |
|
498 |
by blast |
|
499 |
||
500 |
||
501 |
(*** Bounding theorems ***) |
|
502 |
||
503 |
lemma dprod_Sigma: "(dprod (A <*> B) (C <*> D)) <= (uprod A C) <*> (uprod B D)" |
|
504 |
by blast |
|
505 |
||
45607 | 506 |
lemmas dprod_subset_Sigma = subset_trans [OF dprod_mono dprod_Sigma] |
20819 | 507 |
|
508 |
(*Dependent version*) |
|
509 |
lemma dprod_subset_Sigma2: |
|
510 |
"(dprod (Sigma A B) (Sigma C D)) <= |
|
511 |
Sigma (uprod A C) (Split (%x y. uprod (B x) (D y)))" |
|
512 |
by auto |
|
513 |
||
514 |
lemma dsum_Sigma: "(dsum (A <*> B) (C <*> D)) <= (usum A C) <*> (usum B D)" |
|
515 |
by blast |
|
516 |
||
45607 | 517 |
lemmas dsum_subset_Sigma = subset_trans [OF dsum_mono dsum_Sigma] |
20819 | 518 |
|
519 |
||
24162
8dfd5dd65d82
split off theory Option for benefit of code generator
haftmann
parents:
22886
diff
changeset
|
520 |
text {* hides popular names *} |
36176
3fe7e97ccca8
replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents:
35216
diff
changeset
|
521 |
hide_type (open) node item |
3fe7e97ccca8
replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents:
35216
diff
changeset
|
522 |
hide_const (open) Push Node Atom Leaf Numb Lim Split Case |
20819 | 523 |
|
33963
977b94b64905
renamed former datatype.ML to datatype_data.ML; datatype.ML provides uniform view on datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33959
diff
changeset
|
524 |
use "Tools/Datatype/datatype.ML" |
12918 | 525 |
|
33959
2afc55e8ed27
bootstrap datatype_rep_proofs in Datatype.thy (avoids unchecked dynamic name references)
haftmann
parents:
33633
diff
changeset
|
526 |
use "Tools/inductive_realizer.ML" |
2afc55e8ed27
bootstrap datatype_rep_proofs in Datatype.thy (avoids unchecked dynamic name references)
haftmann
parents:
33633
diff
changeset
|
527 |
setup InductiveRealizer.setup |
13635
c41e88151b54
Added functions Suml and Sumr which are useful for constructing
berghofe
parents:
12918
diff
changeset
|
528 |
|
33959
2afc55e8ed27
bootstrap datatype_rep_proofs in Datatype.thy (avoids unchecked dynamic name references)
haftmann
parents:
33633
diff
changeset
|
529 |
use "Tools/Datatype/datatype_realizer.ML" |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
530 |
setup Datatype_Realizer.setup |
13635
c41e88151b54
Added functions Suml and Sumr which are useful for constructing
berghofe
parents:
12918
diff
changeset
|
531 |
|
5181
4ba3787d9709
New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff
changeset
|
532 |
end |