src/HOL/Datatype.thy
author haftmann
Wed, 21 Jan 2009 23:40:23 +0100
changeset 29609 a010aab5bed0
parent 29580 117b88da143c
child 30235 58d147683393
permissions -rw-r--r--
changed import hierarchy
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
20819
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
     4
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
     5
Could <*> be generalized to a general summation (Sigma)?
5181
4ba3787d9709 New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff changeset
     6
*)
4ba3787d9709 New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff changeset
     7
21669
c68717c16013 removed legacy ML bindings;
wenzelm
parents: 21454
diff changeset
     8
header {* Analogues of the Cartesian Product and Disjoint Sum for Datatypes *}
11954
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
     9
15131
c69542757a4d New theory header syntax.
nipkow
parents: 14981
diff changeset
    10
theory Datatype
29609
a010aab5bed0 changed import hierarchy
haftmann
parents: 29580
diff changeset
    11
imports Nat Product_Type
15131
c69542757a4d New theory header syntax.
nipkow
parents: 14981
diff changeset
    12
begin
11954
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    13
20819
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    14
typedef (Node)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    15
  ('a,'b) node = "{p. EX f x k. p = (f::nat=>'b+nat, x::'a+nat) & f k = Inr 0}"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    16
    --{*it is a subtype of @{text "(nat=>'b+nat) * ('a+nat)"}*}
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    17
  by auto
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    18
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    19
text{*Datatypes will be represented by sets of type @{text node}*}
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    20
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    21
types 'a item        = "('a, unit) node set"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    22
      ('a, 'b) dtree = "('a, 'b) node set"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    23
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    24
consts
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    25
  Push      :: "[('b + nat), nat => ('b + nat)] => (nat => ('b + nat))"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    26
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    27
  Push_Node :: "[('b + nat), ('a, 'b) node] => ('a, 'b) node"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    28
  ndepth    :: "('a, 'b) node => nat"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    29
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    30
  Atom      :: "('a + nat) => ('a, 'b) dtree"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    31
  Leaf      :: "'a => ('a, 'b) dtree"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    32
  Numb      :: "nat => ('a, 'b) dtree"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    33
  Scons     :: "[('a, 'b) dtree, ('a, 'b) dtree] => ('a, 'b) dtree"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    34
  In0       :: "('a, 'b) dtree => ('a, 'b) dtree"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    35
  In1       :: "('a, 'b) dtree => ('a, 'b) dtree"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    36
  Lim       :: "('b => ('a, 'b) dtree) => ('a, 'b) dtree"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    37
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    38
  ntrunc    :: "[nat, ('a, 'b) dtree] => ('a, 'b) dtree"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    39
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    40
  uprod     :: "[('a, 'b) dtree set, ('a, 'b) dtree set]=> ('a, 'b) dtree set"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    41
  usum      :: "[('a, 'b) dtree set, ('a, 'b) dtree set]=> ('a, 'b) dtree set"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    42
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    43
  Split     :: "[[('a, 'b) dtree, ('a, 'b) dtree]=>'c, ('a, 'b) dtree] => 'c"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    44
  Case      :: "[[('a, 'b) dtree]=>'c, [('a, 'b) dtree]=>'c, ('a, 'b) dtree] => 'c"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    45
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    46
  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
    47
                => (('a, 'b) dtree * ('a, 'b) dtree)set"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    48
  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
    49
                => (('a, 'b) dtree * ('a, 'b) dtree)set"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    50
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    51
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    52
defs
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    53
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    54
  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
    55
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    56
  (*crude "lists" of nats -- needed for the constructions*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    57
  Push_def:   "Push == (%b h. nat_case b h)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    58
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    59
  (** operations on S-expressions -- sets of nodes **)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    60
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    61
  (*S-expression constructors*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    62
  Atom_def:   "Atom == (%x. {Abs_Node((%k. Inr 0, x))})"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    63
  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
    64
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    65
  (*Leaf nodes, with arbitrary or nat labels*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    66
  Leaf_def:   "Leaf == Atom o Inl"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    67
  Numb_def:   "Numb == Atom o Inr"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    68
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    69
  (*Injections of the "disjoint sum"*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    70
  In0_def:    "In0(M) == Scons (Numb 0) M"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    71
  In1_def:    "In1(M) == Scons (Numb 1) M"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    72
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    73
  (*Function spaces*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    74
  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
    75
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    76
  (*the set of nodes with depth less than k*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    77
  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
    78
  ntrunc_def: "ntrunc k N == {n. n:N & ndepth(n)<k}"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    79
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    80
  (*products and sums for the "universe"*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    81
  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
    82
  usum_def:   "usum A B == In0`A Un In1`B"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    83
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    84
  (*the corresponding eliminators*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    85
  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
    86
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    87
  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
    88
                                  | (EX y . M = In1(y) & u = d(y))"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    89
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    90
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    91
  (** equality for the "universe" **)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    92
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    93
  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
    94
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    95
  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
    96
                          (UN (y,y'):s. {(In1(y),In1(y'))})"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    97
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    98
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
    99
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   100
lemma apfst_convE: 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   101
    "[| 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
   102
     |] ==> R"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   103
by (force simp add: apfst_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   104
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   105
(** Push -- an injection, analogous to Cons on lists **)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   106
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   107
lemma Push_inject1: "Push i f = Push j g  ==> i=j"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   108
apply (simp add: Push_def expand_fun_eq) 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   109
apply (drule_tac x=0 in spec, simp) 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   110
done
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 Push_inject2: "Push i f = Push j g  ==> f=g"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   113
apply (auto simp add: Push_def expand_fun_eq) 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   114
apply (drule_tac x="Suc x" in spec, simp) 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   115
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   116
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   117
lemma Push_inject:
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   118
    "[| Push i f =Push j g;  [| i=j;  f=g |] ==> P |] ==> P"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   119
by (blast dest: Push_inject1 Push_inject2) 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   120
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   121
lemma Push_neq_K0: "Push (Inr (Suc k)) f = (%z. Inr 0) ==> P"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   122
by (auto simp add: Push_def expand_fun_eq split: nat.split_asm)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   123
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   124
lemmas Abs_Node_inj = Abs_Node_inject [THEN [2] rev_iffD1, standard]
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   125
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   126
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   127
(*** Introduction rules for Node ***)
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 Node_K0_I: "(%k. Inr 0, a) : Node"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   130
by (simp add: Node_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   131
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   132
lemma Node_Push_I: "p: Node ==> apfst (Push i) p : Node"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   133
apply (simp add: Node_def Push_def) 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   134
apply (fast intro!: apfst_conv nat_case_Suc [THEN trans])
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   135
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   136
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   137
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   138
subsection{*Freeness: Distinctness of Constructors*}
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   139
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   140
(** Scons vs Atom **)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   141
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   142
lemma Scons_not_Atom [iff]: "Scons M N \<noteq> Atom(a)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   143
apply (simp add: Atom_def Scons_def Push_Node_def One_nat_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   144
apply (blast intro: Node_K0_I Rep_Node [THEN Node_Push_I] 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   145
         dest!: Abs_Node_inj 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   146
         elim!: apfst_convE sym [THEN Push_neq_K0])  
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
21407
af60523da908 reduced verbosity
haftmann
parents: 21404
diff changeset
   149
lemmas Atom_not_Scons [iff] = Scons_not_Atom [THEN not_sym, standard]
af60523da908 reduced verbosity
haftmann
parents: 21404
diff changeset
   150
20819
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   151
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   152
(*** Injectiveness ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   153
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   154
(** Atomic nodes **)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   155
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   156
lemma inj_Atom: "inj(Atom)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   157
apply (simp add: Atom_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   158
apply (blast intro!: inj_onI Node_K0_I dest!: Abs_Node_inj)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   159
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   160
lemmas Atom_inject = inj_Atom [THEN injD, standard]
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   161
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   162
lemma Atom_Atom_eq [iff]: "(Atom(a)=Atom(b)) = (a=b)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   163
by (blast dest!: Atom_inject)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   164
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   165
lemma inj_Leaf: "inj(Leaf)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   166
apply (simp add: Leaf_def o_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   167
apply (rule inj_onI)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   168
apply (erule Atom_inject [THEN Inl_inject])
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   169
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   170
21407
af60523da908 reduced verbosity
haftmann
parents: 21404
diff changeset
   171
lemmas Leaf_inject [dest!] = inj_Leaf [THEN injD, standard]
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 inj_Numb: "inj(Numb)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   174
apply (simp add: Numb_def o_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   175
apply (rule inj_onI)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   176
apply (erule Atom_inject [THEN Inr_inject])
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   177
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   178
21407
af60523da908 reduced verbosity
haftmann
parents: 21404
diff changeset
   179
lemmas Numb_inject [dest!] = inj_Numb [THEN injD, standard]
20819
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   180
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   181
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   182
(** Injectiveness of Push_Node **)
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 Push_Node_inject:
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   185
    "[| Push_Node i m =Push_Node j n;  [| i=j;  m=n |] ==> P  
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   186
     |] ==> P"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   187
apply (simp add: Push_Node_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   188
apply (erule Abs_Node_inj [THEN apfst_convE])
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   189
apply (rule Rep_Node [THEN Node_Push_I])+
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   190
apply (erule sym [THEN apfst_convE]) 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   191
apply (blast intro: Rep_Node_inject [THEN iffD1] trans sym elim!: Push_inject)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   192
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   193
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   194
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   195
(** Injectiveness of Scons **)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   196
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   197
lemma Scons_inject_lemma1: "Scons M N <= Scons M' N' ==> M<=M'"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   198
apply (simp add: Scons_def One_nat_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   199
apply (blast dest!: Push_Node_inject)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   200
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   201
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   202
lemma Scons_inject_lemma2: "Scons M N <= Scons M' N' ==> N<=N'"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   203
apply (simp add: Scons_def One_nat_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   204
apply (blast dest!: Push_Node_inject)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   205
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   206
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   207
lemma Scons_inject1: "Scons M N = Scons M' N' ==> M=M'"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   208
apply (erule equalityE)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   209
apply (iprover intro: equalityI Scons_inject_lemma1)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   210
done
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_inject2: "Scons M N = Scons M' N' ==> N=N'"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   213
apply (erule equalityE)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   214
apply (iprover intro: equalityI Scons_inject_lemma2)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   215
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   216
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   217
lemma Scons_inject:
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   218
    "[| Scons M N = Scons M' N';  [| M=M';  N=N' |] ==> P |] ==> P"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   219
by (iprover dest: Scons_inject1 Scons_inject2)
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_Scons_eq [iff]: "(Scons M N = Scons M' N') = (M=M' & N=N')"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   222
by (blast elim!: Scons_inject)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   223
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   224
(*** Distinctness involving Leaf and Numb ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   225
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   226
(** Scons vs Leaf **)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   227
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   228
lemma Scons_not_Leaf [iff]: "Scons M N \<noteq> Leaf(a)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   229
by (simp add: Leaf_def o_def Scons_not_Atom)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   230
21407
af60523da908 reduced verbosity
haftmann
parents: 21404
diff changeset
   231
lemmas Leaf_not_Scons  [iff] = Scons_not_Leaf [THEN not_sym, standard]
20819
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   232
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   233
(** Scons vs 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
lemma Scons_not_Numb [iff]: "Scons M N \<noteq> Numb(k)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   236
by (simp add: Numb_def o_def Scons_not_Atom)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   237
21407
af60523da908 reduced verbosity
haftmann
parents: 21404
diff changeset
   238
lemmas Numb_not_Scons [iff] = Scons_not_Numb [THEN not_sym, standard]
20819
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   239
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   240
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   241
(** Leaf vs Numb **)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   242
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   243
lemma Leaf_not_Numb [iff]: "Leaf(a) \<noteq> Numb(k)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   244
by (simp add: Leaf_def Numb_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   245
21407
af60523da908 reduced verbosity
haftmann
parents: 21404
diff changeset
   246
lemmas Numb_not_Leaf [iff] = Leaf_not_Numb [THEN not_sym, standard]
20819
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   247
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   248
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   249
(*** ndepth -- the depth of a node ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   250
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   251
lemma ndepth_K0: "ndepth (Abs_Node(%k. Inr 0, x)) = 0"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   252
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
   253
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   254
lemma ndepth_Push_Node_aux:
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   255
     "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
   256
apply (induct_tac "k", auto)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   257
apply (erule Least_le)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   258
done
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_Push_Node: 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   261
    "ndepth (Push_Node (Inr (Suc i)) n) = Suc(ndepth(n))"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   262
apply (insert Rep_Node [of n, unfolded Node_def])
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   263
apply (auto simp add: ndepth_def Push_Node_def
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   264
                 Rep_Node [THEN Node_Push_I, THEN Abs_Node_inverse])
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   265
apply (rule Least_equality)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   266
apply (auto simp add: Push_def ndepth_Push_Node_aux)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   267
apply (erule LeastI)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   268
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   269
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   270
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   271
(*** ntrunc applied to the various node sets ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   272
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   273
lemma ntrunc_0 [simp]: "ntrunc 0 M = {}"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   274
by (simp add: ntrunc_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   275
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   276
lemma ntrunc_Atom [simp]: "ntrunc (Suc k) (Atom a) = Atom(a)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   277
by (auto simp add: Atom_def ntrunc_def ndepth_K0)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   278
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   279
lemma ntrunc_Leaf [simp]: "ntrunc (Suc k) (Leaf a) = Leaf(a)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   280
by (simp add: Leaf_def o_def ntrunc_Atom)
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_Numb [simp]: "ntrunc (Suc k) (Numb i) = Numb(i)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   283
by (simp add: Numb_def o_def ntrunc_Atom)
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_Scons [simp]: 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   286
    "ntrunc (Suc k) (Scons M N) = Scons (ntrunc k M) (ntrunc k N)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   287
by (auto simp add: Scons_def ntrunc_def One_nat_def ndepth_Push_Node) 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   288
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   289
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   290
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   291
(** Injection nodes **)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   292
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   293
lemma ntrunc_one_In0 [simp]: "ntrunc (Suc 0) (In0 M) = {}"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   294
apply (simp add: In0_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   295
apply (simp add: Scons_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   296
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   297
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   298
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
   299
by (simp add: In0_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   300
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   301
lemma ntrunc_one_In1 [simp]: "ntrunc (Suc 0) (In1 M) = {}"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   302
apply (simp add: In1_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   303
apply (simp add: Scons_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   304
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   305
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   306
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
   307
by (simp add: In1_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   308
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   309
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   310
subsection{*Set Constructions*}
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   311
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   312
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   313
(*** Cartesian Product ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   314
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   315
lemma uprodI [intro!]: "[| M:A;  N:B |] ==> Scons M N : uprod A B"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   316
by (simp add: uprod_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   317
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   318
(*The general elimination rule*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   319
lemma uprodE [elim!]:
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   320
    "[| c : uprod A B;   
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   321
        !!x y. [| x:A;  y:B;  c = Scons x y |] ==> P  
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   322
     |] ==> P"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   323
by (auto simp add: uprod_def) 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   324
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   325
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   326
(*Elimination of a pair -- introduces no eigenvariables*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   327
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
   328
by (auto simp add: uprod_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   329
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   330
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   331
(*** Disjoint Sum ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   332
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   333
lemma usum_In0I [intro]: "M:A ==> In0(M) : usum A B"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   334
by (simp add: usum_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   335
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   336
lemma usum_In1I [intro]: "N:B ==> In1(N) : usum A B"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   337
by (simp add: usum_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   338
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   339
lemma usumE [elim!]: 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   340
    "[| u : usum A B;   
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   341
        !!x. [| x:A;  u=In0(x) |] ==> P;  
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   342
        !!y. [| y:B;  u=In1(y) |] ==> P  
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   343
     |] ==> P"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   344
by (auto 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
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   347
(** Injection **)
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 In0_not_In1 [iff]: "In0(M) \<noteq> In1(N)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   350
by (auto simp add: In0_def In1_def One_nat_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   351
21407
af60523da908 reduced verbosity
haftmann
parents: 21404
diff changeset
   352
lemmas In1_not_In0 [iff] = In0_not_In1 [THEN not_sym, standard]
20819
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   353
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   354
lemma In0_inject: "In0(M) = In0(N) ==>  M=N"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   355
by (simp add: In0_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   356
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   357
lemma In1_inject: "In1(M) = In1(N) ==>  M=N"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   358
by (simp add: In1_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   359
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   360
lemma In0_eq [iff]: "(In0 M = In0 N) = (M=N)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   361
by (blast dest!: In0_inject)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   362
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   363
lemma In1_eq [iff]: "(In1 M = In1 N) = (M=N)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   364
by (blast dest!: In1_inject)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   365
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   366
lemma inj_In0: "inj In0"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   367
by (blast intro!: inj_onI)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   368
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   369
lemma inj_In1: "inj In1"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   370
by (blast intro!: inj_onI)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   371
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   372
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   373
(*** Function spaces ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   374
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   375
lemma Lim_inject: "Lim f = Lim g ==> f = g"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   376
apply (simp add: Lim_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   377
apply (rule ext)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   378
apply (blast elim!: Push_Node_inject)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   379
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   380
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   381
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   382
(*** proving equality of sets and functions using ntrunc ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   383
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   384
lemma ntrunc_subsetI: "ntrunc k M <= M"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   385
by (auto simp add: ntrunc_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   386
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   387
lemma ntrunc_subsetD: "(!!k. ntrunc k M <= N) ==> M<=N"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   388
by (auto simp add: ntrunc_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   389
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   390
(*A generalized form of the take-lemma*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   391
lemma ntrunc_equality: "(!!k. ntrunc k M = ntrunc k N) ==> M=N"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   392
apply (rule equalityI)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   393
apply (rule_tac [!] ntrunc_subsetD)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   394
apply (rule_tac [!] ntrunc_subsetI [THEN [2] subset_trans], auto) 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   395
done
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_o_equality: 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   398
    "[| !!k. (ntrunc(k) o h1) = (ntrunc(k) o h2) |] ==> h1=h2"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   399
apply (rule ntrunc_equality [THEN ext])
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   400
apply (simp add: expand_fun_eq) 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   401
done
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   402
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   403
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   404
(*** Monotonicity ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   405
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   406
lemma uprod_mono: "[| A<=A';  B<=B' |] ==> uprod A B <= uprod A' B'"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   407
by (simp add: uprod_def, blast)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   408
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   409
lemma usum_mono: "[| A<=A';  B<=B' |] ==> usum A B <= usum A' B'"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   410
by (simp add: usum_def, blast)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   411
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   412
lemma Scons_mono: "[| M<=M';  N<=N' |] ==> Scons M N <= Scons M' N'"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   413
by (simp add: Scons_def, blast)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   414
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   415
lemma In0_mono: "M<=N ==> In0(M) <= In0(N)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   416
by (simp add: In0_def subset_refl Scons_mono)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   417
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   418
lemma In1_mono: "M<=N ==> In1(M) <= In1(N)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   419
by (simp add: In1_def subset_refl Scons_mono)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   420
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   421
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   422
(*** Split and Case ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   423
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   424
lemma Split [simp]: "Split c (Scons M N) = c M N"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   425
by (simp add: Split_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   426
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   427
lemma Case_In0 [simp]: "Case c d (In0 M) = c(M)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   428
by (simp add: Case_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   429
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   430
lemma Case_In1 [simp]: "Case c d (In1 N) = d(N)"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   431
by (simp add: Case_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   432
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   433
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   434
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   435
(**** UN x. B(x) rules ****)
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 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
   438
by (simp add: ntrunc_def, blast)
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 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
   441
by (simp add: Scons_def, blast)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   442
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   443
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
   444
by (simp add: Scons_def, blast)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   445
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   446
lemma In0_UN1: "In0(UN x. f(x)) = (UN x. In0(f(x)))"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   447
by (simp add: In0_def Scons_UN1_y)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   448
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   449
lemma In1_UN1: "In1(UN x. f(x)) = (UN x. In1(f(x)))"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   450
by (simp add: In1_def Scons_UN1_y)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   451
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   452
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   453
(*** Equality for Cartesian Product ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   454
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   455
lemma dprodI [intro!]: 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   456
    "[| (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
   457
by (auto simp add: dprod_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   458
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   459
(*The general elimination rule*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   460
lemma dprodE [elim!]: 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   461
    "[| c : dprod r s;   
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   462
        !!x y x' y'. [| (x,x') : r;  (y,y') : s;  
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   463
                        c = (Scons x y, Scons x' y') |] ==> P  
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   464
     |] ==> P"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   465
by (auto simp add: dprod_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   466
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   467
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   468
(*** Equality for Disjoint Sum ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   469
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   470
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
   471
by (auto simp add: dsum_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   472
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   473
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
   474
by (auto simp add: dsum_def)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   475
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   476
lemma dsumE [elim!]: 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   477
    "[| w : dsum r s;   
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   478
        !!x x'. [| (x,x') : r;  w = (In0(x), In0(x')) |] ==> P;  
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   479
        !!y y'. [| (y,y') : s;  w = (In1(y), In1(y')) |] ==> P  
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   480
     |] ==> P"
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
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   484
(*** Monotonicity ***)
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 dprod_mono: "[| r<=r';  s<=s' |] ==> dprod r s <= dprod r' s'"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   487
by blast
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   488
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   489
lemma dsum_mono: "[| r<=r';  s<=s' |] ==> dsum r s <= dsum r' s'"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   490
by blast
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   491
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   492
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   493
(*** Bounding theorems ***)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   494
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   495
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
   496
by blast
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   497
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   498
lemmas dprod_subset_Sigma = subset_trans [OF dprod_mono dprod_Sigma, standard]
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   499
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   500
(*Dependent version*)
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   501
lemma dprod_subset_Sigma2:
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   502
     "(dprod (Sigma A B) (Sigma C D)) <= 
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   503
      Sigma (uprod A C) (Split (%x y. uprod (B x) (D y)))"
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   504
by auto
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   505
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   506
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
   507
by blast
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   508
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   509
lemmas dsum_subset_Sigma = subset_trans [OF dsum_mono dsum_Sigma, standard]
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   510
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   511
24162
8dfd5dd65d82 split off theory Option for benefit of code generator
haftmann
parents: 22886
diff changeset
   512
text {* hides popular names *}
8dfd5dd65d82 split off theory Option for benefit of code generator
haftmann
parents: 22886
diff changeset
   513
hide (open) type node item
20819
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   514
hide (open) const Push Node Atom Leaf Numb Lim Split Case
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   515
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   516
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   517
section {* Datatypes *}
cb6ae81dd0be merged with theory Datatype_Universe;
wenzelm
parents: 20798
diff changeset
   518
24699
c6674504103f datatype interpretators for size and datatype_realizer
haftmann
parents: 24286
diff changeset
   519
subsection {* Representing sums *}
12918
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   520
27104
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   521
rep_datatype (sum) Inl Inr
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   522
proof -
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   523
  fix P
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   524
  fix s :: "'a + 'b"
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   525
  assume x: "\<And>x\<Colon>'a. P (Inl x)" and y: "\<And>y\<Colon>'b. P (Inr y)"
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   526
  then show "P s" by (auto intro: sumE [of s])
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   527
qed simp_all
24194
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   528
22230
bdec4a82f385 a few additions and deletions
nipkow
parents: 21905
diff changeset
   529
lemma sum_case_KK[simp]: "sum_case (%x. a) (%x. a) = (%x. a)"
bdec4a82f385 a few additions and deletions
nipkow
parents: 21905
diff changeset
   530
  by (rule ext) (simp split: sum.split)
bdec4a82f385 a few additions and deletions
nipkow
parents: 21905
diff changeset
   531
12918
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   532
lemma surjective_sum: "sum_case (%x::'a. f (Inl x)) (%y::'b. f (Inr y)) s = f(s)"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   533
  apply (rule_tac s = s in sumE)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   534
   apply (erule ssubst)
20798
3275b03e2fff removed obsolete sum_case_Inl/Inr;
wenzelm
parents: 20588
diff changeset
   535
   apply (rule sum.cases(1))
12918
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   536
  apply (erule ssubst)
20798
3275b03e2fff removed obsolete sum_case_Inl/Inr;
wenzelm
parents: 20588
diff changeset
   537
  apply (rule sum.cases(2))
12918
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   538
  done
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   539
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   540
lemma sum_case_weak_cong: "s = t ==> sum_case f g s = sum_case f g t"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   541
  -- {* Prevents simplification of @{text f} and @{text g}: much faster. *}
20798
3275b03e2fff removed obsolete sum_case_Inl/Inr;
wenzelm
parents: 20588
diff changeset
   542
  by simp
12918
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   543
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   544
lemma sum_case_inject:
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   545
  "sum_case f1 f2 = sum_case g1 g2 ==> (f1 = g1 ==> f2 = g2 ==> P) ==> P"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   546
proof -
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   547
  assume a: "sum_case f1 f2 = sum_case g1 g2"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   548
  assume r: "f1 = g1 ==> f2 = g2 ==> P"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   549
  show P
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   550
    apply (rule r)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   551
     apply (rule ext)
14208
144f45277d5a misc tidying
paulson
parents: 14187
diff changeset
   552
     apply (cut_tac x = "Inl x" in a [THEN fun_cong], simp)
12918
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   553
    apply (rule ext)
14208
144f45277d5a misc tidying
paulson
parents: 14187
diff changeset
   554
    apply (cut_tac x = "Inr x" in a [THEN fun_cong], simp)
12918
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   555
    done
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   556
qed
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   557
13635
c41e88151b54 Added functions Suml and Sumr which are useful for constructing
berghofe
parents: 12918
diff changeset
   558
constdefs
c41e88151b54 Added functions Suml and Sumr which are useful for constructing
berghofe
parents: 12918
diff changeset
   559
  Suml :: "('a => 'c) => 'a + 'b => 'c"
28524
644b62cf678f arbitrary is undefined
haftmann
parents: 28346
diff changeset
   560
  "Suml == (%f. sum_case f undefined)"
13635
c41e88151b54 Added functions Suml and Sumr which are useful for constructing
berghofe
parents: 12918
diff changeset
   561
c41e88151b54 Added functions Suml and Sumr which are useful for constructing
berghofe
parents: 12918
diff changeset
   562
  Sumr :: "('b => 'c) => 'a + 'b => 'c"
28524
644b62cf678f arbitrary is undefined
haftmann
parents: 28346
diff changeset
   563
  "Sumr == sum_case undefined"
13635
c41e88151b54 Added functions Suml and Sumr which are useful for constructing
berghofe
parents: 12918
diff changeset
   564
c41e88151b54 Added functions Suml and Sumr which are useful for constructing
berghofe
parents: 12918
diff changeset
   565
lemma Suml_inject: "Suml f = Suml g ==> f = g"
c41e88151b54 Added functions Suml and Sumr which are useful for constructing
berghofe
parents: 12918
diff changeset
   566
  by (unfold Suml_def) (erule sum_case_inject)
c41e88151b54 Added functions Suml and Sumr which are useful for constructing
berghofe
parents: 12918
diff changeset
   567
c41e88151b54 Added functions Suml and Sumr which are useful for constructing
berghofe
parents: 12918
diff changeset
   568
lemma Sumr_inject: "Sumr f = Sumr g ==> f = g"
c41e88151b54 Added functions Suml and Sumr which are useful for constructing
berghofe
parents: 12918
diff changeset
   569
  by (unfold Sumr_def) (erule sum_case_inject)
c41e88151b54 Added functions Suml and Sumr which are useful for constructing
berghofe
parents: 12918
diff changeset
   570
29183
f1648e009dc1 removed duplicate sum_case used only by function package;
krauss
parents: 29025
diff changeset
   571
primrec Projl :: "'a + 'b => 'a"
f1648e009dc1 removed duplicate sum_case used only by function package;
krauss
parents: 29025
diff changeset
   572
where Projl_Inl: "Projl (Inl x) = x"
f1648e009dc1 removed duplicate sum_case used only by function package;
krauss
parents: 29025
diff changeset
   573
f1648e009dc1 removed duplicate sum_case used only by function package;
krauss
parents: 29025
diff changeset
   574
primrec Projr :: "'a + 'b => 'b"
f1648e009dc1 removed duplicate sum_case used only by function package;
krauss
parents: 29025
diff changeset
   575
where Projr_Inr: "Projr (Inr x) = x"
f1648e009dc1 removed duplicate sum_case used only by function package;
krauss
parents: 29025
diff changeset
   576
f1648e009dc1 removed duplicate sum_case used only by function package;
krauss
parents: 29025
diff changeset
   577
hide (open) const Suml Sumr Projl Projr
13635
c41e88151b54 Added functions Suml and Sumr which are useful for constructing
berghofe
parents: 12918
diff changeset
   578
12918
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   579
24194
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   580
subsection {* The option datatype *}
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   581
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   582
datatype 'a option = None | Some 'a
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   583
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   584
lemma not_None_eq [iff]: "(x ~= None) = (EX y. x = Some y)"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   585
  by (induct x) auto
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   586
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   587
lemma not_Some_eq [iff]: "(ALL y. x ~= Some y) = (x = None)"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   588
  by (induct x) auto
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   589
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   590
text{*Although it may appear that both of these equalities are helpful
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   591
only when applied to assumptions, in practice it seems better to give
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   592
them the uniform iff attribute. *}
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   593
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   594
lemma option_caseE:
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   595
  assumes c: "(case x of None => P | Some y => Q y)"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   596
  obtains
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   597
    (None) "x = None" and P
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   598
  | (Some) y where "x = Some y" and "Q y"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   599
  using c by (cases x) simp_all
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   600
24728
e2b3a1065676 moved Finite_Set before Datatype
haftmann
parents: 24699
diff changeset
   601
lemma insert_None_conv_UNIV: "insert None (range Some) = UNIV"
e2b3a1065676 moved Finite_Set before Datatype
haftmann
parents: 24699
diff changeset
   602
  by (rule set_ext, case_tac x) auto
e2b3a1065676 moved Finite_Set before Datatype
haftmann
parents: 24699
diff changeset
   603
29025
8c8859c0d734 move lemmas from Numeral_Type.thy to other theories
huffman
parents: 28689
diff changeset
   604
lemma inj_Some [simp]: "inj_on Some A"
8c8859c0d734 move lemmas from Numeral_Type.thy to other theories
huffman
parents: 28689
diff changeset
   605
  by (rule inj_onI) simp
8c8859c0d734 move lemmas from Numeral_Type.thy to other theories
huffman
parents: 28689
diff changeset
   606
24194
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   607
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   608
subsubsection {* Operations *}
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   609
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   610
consts
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   611
  the :: "'a option => 'a"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   612
primrec
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   613
  "the (Some x) = x"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   614
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   615
consts
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   616
  o2s :: "'a option => 'a set"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   617
primrec
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   618
  "o2s None = {}"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   619
  "o2s (Some x) = {x}"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   620
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   621
lemma ospec [dest]: "(ALL x:o2s A. P x) ==> A = Some x ==> P x"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   622
  by simp
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   623
26339
7825c83c9eff eliminated change_claset/simpset;
wenzelm
parents: 26146
diff changeset
   624
declaration {* fn _ =>
7825c83c9eff eliminated change_claset/simpset;
wenzelm
parents: 26146
diff changeset
   625
  Classical.map_cs (fn cs => cs addSD2 ("ospec", thm "ospec"))
7825c83c9eff eliminated change_claset/simpset;
wenzelm
parents: 26146
diff changeset
   626
*}
24194
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   627
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   628
lemma elem_o2s [iff]: "(x : o2s xo) = (xo = Some x)"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   629
  by (cases xo) auto
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   630
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   631
lemma o2s_empty_eq [simp]: "(o2s xo = {}) = (xo = None)"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   632
  by (cases xo) auto
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   633
25511
54db9b5080b8 more canonical attribute application
haftmann
parents: 24845
diff changeset
   634
definition
54db9b5080b8 more canonical attribute application
haftmann
parents: 24845
diff changeset
   635
  option_map :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a option \<Rightarrow> 'b option"
54db9b5080b8 more canonical attribute application
haftmann
parents: 24845
diff changeset
   636
where
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28524
diff changeset
   637
  [code del]: "option_map = (%f y. case y of None => None | Some x => Some (f x))"
24194
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   638
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   639
lemma option_map_None [simp, code]: "option_map f None = None"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   640
  by (simp add: option_map_def)
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   641
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   642
lemma option_map_Some [simp, code]: "option_map f (Some x) = Some (f x)"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   643
  by (simp add: option_map_def)
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   644
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   645
lemma option_map_is_None [iff]:
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   646
    "(option_map f opt = None) = (opt = None)"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   647
  by (simp add: option_map_def split add: option.split)
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   648
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   649
lemma option_map_eq_Some [iff]:
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   650
    "(option_map f xo = Some y) = (EX z. xo = Some z & f z = y)"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   651
  by (simp add: option_map_def split add: option.split)
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   652
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   653
lemma option_map_comp:
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   654
    "option_map f (option_map g opt) = option_map (f o g) opt"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   655
  by (simp add: option_map_def split add: option.split)
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   656
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   657
lemma option_map_o_sum_case [simp]:
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   658
    "option_map f o sum_case g h = sum_case (option_map f o g) (option_map f o h)"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   659
  by (rule ext) (simp split: sum.split)
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   660
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   661
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   662
subsubsection {* Code generator setup *}
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   663
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   664
definition
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   665
  is_none :: "'a option \<Rightarrow> bool" where
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   666
  is_none_none [code post, symmetric, code inline]: "is_none x \<longleftrightarrow> x = None"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   667
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   668
lemma is_none_code [code]:
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   669
  shows "is_none None \<longleftrightarrow> True"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   670
    and "is_none (Some x) \<longleftrightarrow> False"
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   671
  unfolding is_none_none [symmetric] by simp_all
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   672
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   673
hide (open) const is_none
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   674
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   675
code_type option
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   676
  (SML "_ option")
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   677
  (OCaml "_ option")
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   678
  (Haskell "Maybe _")
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   679
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   680
code_const None and Some
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   681
  (SML "NONE" and "SOME")
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   682
  (OCaml "None" and "Some _")
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   683
  (Haskell "Nothing" and "Just")
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   684
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   685
code_instance option :: eq
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   686
  (Haskell -)
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   687
28346
b8390cd56b8f discontinued special treatment of op = vs. eq_class.eq
haftmann
parents: 27981
diff changeset
   688
code_const "eq_class.eq \<Colon> 'a\<Colon>eq option \<Rightarrow> 'a option \<Rightarrow> bool"
24194
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   689
  (Haskell infixl 4 "==")
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   690
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   691
code_reserved SML
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   692
  option NONE SOME
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   693
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   694
code_reserved OCaml
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   695
  option None Some
96013f81faef re-eliminated Option.thy
haftmann
parents: 24162
diff changeset
   696
5181
4ba3787d9709 New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff changeset
   697
end