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