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