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