src/HOL/Library/Old_Datatype.thy
 author Manuel Eberl Mon Mar 26 16:14:16 2018 +0200 (18 months ago) changeset 67951 655aa11359dc parent 67613 ce654b0e6d69 child 69605 a96320074298 permissions -rw-r--r--
Removed some uses of deprecated _tac methods. (Patch from Viorel Preoteasa)
```     1 (*  Title:      HOL/Library/Old_Datatype.thy
```
```     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
```
```     3     Author:     Stefan Berghofer and Markus Wenzel, TU Muenchen
```
```     4 *)
```
```     5
```
```     6 section \<open>Old Datatype package: constructing datatypes from Cartesian Products and Disjoint Sums\<close>
```
```     7
```
```     8 theory Old_Datatype
```
```     9 imports Main
```
```    10 begin
```
```    11
```
```    12
```
```    13 subsection \<open>The datatype universe\<close>
```
```    14
```
```    15 definition "Node = {p. \<exists>f x k. p = (f :: nat => 'b + nat, x ::'a + nat) \<and> f k = Inr 0}"
```
```    16
```
```    17 typedef ('a, 'b) node = "Node :: ((nat => 'b + nat) * ('a + nat)) set"
```
```    18   morphisms Rep_Node Abs_Node
```
```    19   unfolding Node_def by auto
```
```    20
```
```    21 text\<open>Datatypes will be represented by sets of type \<open>node\<close>\<close>
```
```    22
```
```    23 type_synonym 'a item        = "('a, unit) node set"
```
```    24 type_synonym ('a, 'b) dtree = "('a, 'b) node set"
```
```    25
```
```    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)"
```
```    29
```
```    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)))"
```
```    32
```
```    33
```
```    34 (** operations on S-expressions -- sets of nodes **)
```
```    35
```
```    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)"
```
```    41
```
```    42 (*Leaf nodes, with arbitrary or nat labels*)
```
```    43 definition Leaf :: "'a => ('a, 'b) dtree"
```
```    44   where "Leaf == Atom \<circ> Inl"
```
```    45 definition Numb :: "nat => ('a, 'b) dtree"
```
```    46   where "Numb == Atom \<circ> Inr"
```
```    47
```
```    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"
```
```    53
```
```    54 (*Function spaces*)
```
```    55 definition Lim :: "('b => ('a, 'b) dtree) => ('a, 'b) dtree"
```
```    56   where "Lim f == \<Union>{z. \<exists>x. z = Push_Node (Inl x) ` (f x)}"
```
```    57
```
```    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"
```
```    62   where "ntrunc k N == {n. n\<in>N \<and> ndepth(n)<k}"
```
```    63
```
```    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"
```
```    69
```
```    70 (*the corresponding eliminators*)
```
```    71 definition Split :: "[[('a, 'b) dtree, ('a, 'b) dtree]=>'c, ('a, 'b) dtree] => 'c"
```
```    72   where "Split c M == THE u. \<exists>x y. M = Scons x y \<and> u = c x y"
```
```    73
```
```    74 definition Case :: "[[('a, 'b) dtree]=>'c, [('a, 'b) dtree]=>'c, ('a, 'b) dtree] => 'c"
```
```    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))"
```
```    76
```
```    77
```
```    78 (** equality for the "universe" **)
```
```    79
```
```    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')}"
```
```    83
```
```    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'))})"
```
```    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"
```
```    97 apply (simp add: Push_def fun_eq_iff)
```
```    98 apply (drule_tac x=0 in spec, simp)
```
```    99 done
```
```   100
```
```   101 lemma Push_inject2: "Push i f = Push j g  ==> f=g"
```
```   102 apply (auto simp add: Push_def fun_eq_iff)
```
```   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"
```
```   111 by (auto simp add: Push_def fun_eq_iff split: nat.split_asm)
```
```   112
```
```   113 lemmas Abs_Node_inj = Abs_Node_inject [THEN [2] rev_iffD1]
```
```   114
```
```   115
```
```   116 (*** Introduction rules for Node ***)
```
```   117
```
```   118 lemma Node_K0_I: "(\<lambda>k. Inr 0, a) \<in> Node"
```
```   119 by (simp add: Node_def)
```
```   120
```
```   121 lemma Node_Push_I: "p \<in> Node \<Longrightarrow> apfst (Push i) p \<in> Node"
```
```   122 apply (simp add: Node_def Push_def)
```
```   123 apply (fast intro!: apfst_conv nat.case(2)[THEN trans])
```
```   124 done
```
```   125
```
```   126
```
```   127 subsection\<open>Freeness: Distinctness of Constructors\<close>
```
```   128
```
```   129 (** Scons vs Atom **)
```
```   130
```
```   131 lemma Scons_not_Atom [iff]: "Scons M N \<noteq> Atom(a)"
```
```   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]
```
```   134          dest!: Abs_Node_inj
```
```   135          elim!: apfst_convE sym [THEN Push_neq_K0])
```
```   136
```
```   137 lemmas Atom_not_Scons [iff] = Scons_not_Atom [THEN not_sym]
```
```   138
```
```   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
```
```   148 lemmas Atom_inject = inj_Atom [THEN injD]
```
```   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
```
```   159 lemmas Leaf_inject [dest!] = inj_Leaf [THEN injD]
```
```   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
```
```   167 lemmas Numb_inject [dest!] = inj_Numb [THEN injD]
```
```   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'"
```
```   186 unfolding Scons_def One_nat_def
```
```   187 by (blast dest!: Push_Node_inject)
```
```   188
```
```   189 lemma Scons_inject_lemma2: "Scons M N <= Scons M' N' ==> N<=N'"
```
```   190 unfolding Scons_def One_nat_def
```
```   191 by (blast dest!: Push_Node_inject)
```
```   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
```
```   207 lemma Scons_Scons_eq [iff]: "(Scons M N = Scons M' N') = (M=M' \<and> N=N')"
```
```   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)"
```
```   215 unfolding Leaf_def o_def by (rule Scons_not_Atom)
```
```   216
```
```   217 lemmas Leaf_not_Scons  [iff] = Scons_not_Leaf [THEN not_sym]
```
```   218
```
```   219 (** Scons vs Numb **)
```
```   220
```
```   221 lemma Scons_not_Numb [iff]: "Scons M N \<noteq> Numb(k)"
```
```   222 unfolding Numb_def o_def by (rule Scons_not_Atom)
```
```   223
```
```   224 lemmas Numb_not_Scons [iff] = Scons_not_Numb [THEN not_sym]
```
```   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
```
```   232 lemmas Numb_not_Leaf [iff] = Leaf_not_Numb [THEN not_sym]
```
```   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:
```
```   241      "case_nat (Inr (Suc i)) f k = Inr 0 \<longrightarrow> Suc(LEAST x. f x = Inr 0) \<le> k"
```
```   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)"
```
```   266 unfolding Leaf_def o_def by (rule ntrunc_Atom)
```
```   267
```
```   268 lemma ntrunc_Numb [simp]: "ntrunc (Suc k) (Numb i) = Numb(i)"
```
```   269 unfolding Numb_def o_def by (rule ntrunc_Atom)
```
```   270
```
```   271 lemma ntrunc_Scons [simp]:
```
```   272     "ntrunc (Suc k) (Scons M N) = Scons (ntrunc k M) (ntrunc k N)"
```
```   273 unfolding Scons_def ntrunc_def One_nat_def
```
```   274 by (auto simp add: ndepth_Push_Node)
```
```   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
```
```   297 subsection\<open>Set Constructions\<close>
```
```   298
```
```   299
```
```   300 (*** Cartesian Product ***)
```
```   301
```
```   302 lemma uprodI [intro!]: "\<lbrakk>M\<in>A; N\<in>B\<rbrakk> \<Longrightarrow> Scons M N \<in> uprod A B"
```
```   303 by (simp add: uprod_def)
```
```   304
```
```   305 (*The general elimination rule*)
```
```   306 lemma uprodE [elim!]:
```
```   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"
```
```   310 by (auto simp add: uprod_def)
```
```   311
```
```   312
```
```   313 (*Elimination of a pair -- introduces no eigenvariables*)
```
```   314 lemma uprodE2: "\<lbrakk>Scons M N \<in> uprod A B; \<lbrakk>M \<in> A; N \<in> B\<rbrakk> \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
```
```   315 by (auto simp add: uprod_def)
```
```   316
```
```   317
```
```   318 (*** Disjoint Sum ***)
```
```   319
```
```   320 lemma usum_In0I [intro]: "M \<in> A \<Longrightarrow> In0(M) \<in> usum A B"
```
```   321 by (simp add: usum_def)
```
```   322
```
```   323 lemma usum_In1I [intro]: "N \<in> B \<Longrightarrow> In1(N) \<in> usum A B"
```
```   324 by (simp add: usum_def)
```
```   325
```
```   326 lemma usumE [elim!]:
```
```   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"
```
```   331 by (auto simp add: usum_def)
```
```   332
```
```   333
```
```   334 (** Injection **)
```
```   335
```
```   336 lemma In0_not_In1 [iff]: "In0(M) \<noteq> In1(N)"
```
```   337 unfolding In0_def In1_def One_nat_def by auto
```
```   338
```
```   339 lemmas In1_not_In0 [iff] = In0_not_In1 [THEN not_sym]
```
```   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:
```
```   385     "[| !!k. (ntrunc(k) \<circ> h1) = (ntrunc(k) \<circ> h2) |] ==> h1=h2"
```
```   386 apply (rule ntrunc_equality [THEN ext])
```
```   387 apply (simp add: fun_eq_iff)
```
```   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)"
```
```   403 by (simp add: In0_def Scons_mono)
```
```   404
```
```   405 lemma In1_mono: "M<=N ==> In1(M) <= In1(N)"
```
```   406 by (simp add: In1_def Scons_mono)
```
```   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!]:
```
```   443     "\<lbrakk>(M,M') \<in> r; (N,N') \<in> s\<rbrakk> \<Longrightarrow> (Scons M N, Scons M' N') \<in> dprod r s"
```
```   444 by (auto simp add: dprod_def)
```
```   445
```
```   446 (*The general elimination rule*)
```
```   447 lemma dprodE [elim!]:
```
```   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"
```
```   452 by (auto simp add: dprod_def)
```
```   453
```
```   454
```
```   455 (*** Equality for Disjoint Sum ***)
```
```   456
```
```   457 lemma dsum_In0I [intro]: "(M,M') \<in> r \<Longrightarrow> (In0(M), In0(M')) \<in> dsum r s"
```
```   458 by (auto simp add: dsum_def)
```
```   459
```
```   460 lemma dsum_In1I [intro]: "(N,N') \<in> s \<Longrightarrow> (In1(N), In1(N')) \<in> dsum r s"
```
```   461 by (auto simp add: dsum_def)
```
```   462
```
```   463 lemma dsumE [elim!]:
```
```   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"
```
```   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
```
```   482 lemma dprod_Sigma: "(dprod (A \<times> B) (C \<times> D)) <= (uprod A C) \<times> (uprod B D)"
```
```   483 by blast
```
```   484
```
```   485 lemmas dprod_subset_Sigma = subset_trans [OF dprod_mono dprod_Sigma]
```
```   486
```
```   487 (*Dependent version*)
```
```   488 lemma dprod_subset_Sigma2:
```
```   489     "(dprod (Sigma A B) (Sigma C D)) <= Sigma (uprod A C) (Split (%x y. uprod (B x) (D y)))"
```
```   490 by auto
```
```   491
```
```   492 lemma dsum_Sigma: "(dsum (A \<times> B) (C \<times> D)) <= (usum A C) \<times> (usum B D)"
```
```   493 by blast
```
```   494
```
```   495 lemmas dsum_subset_Sigma = subset_trans [OF dsum_mono dsum_Sigma]
```
```   496
```
```   497
```
```   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
```
```   507 text \<open>hides popular names\<close>
```
```   508 hide_type (open) node item
```
```   509 hide_const (open) Push Node Atom Leaf Numb Lim Split Case
```
```   510
```
```   511 ML_file "~~/src/HOL/Tools/Old_Datatype/old_datatype.ML"
```
```   512
```
```   513 end
```