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