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