src/HOL/Datatype_Universe.thy
author paulson
Thu Dec 09 12:03:06 2004 +0100 (2004-12-09)
changeset 15388 aa785cea8fff
parent 13636 fdf7e9388be7
child 15413 901d1bfedf09
permissions -rw-r--r--
converted Datatype_Universe to new-style theory
nipkow@10213
     1
(*  Title:      HOL/Datatype_Universe.thy
nipkow@10213
     2
    ID:         $Id$
nipkow@10213
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
nipkow@10213
     4
    Copyright   1993  University of Cambridge
nipkow@10213
     5
nipkow@10213
     6
Could <*> be generalized to a general summation (Sigma)?
nipkow@10213
     7
*)
nipkow@10213
     8
paulson@15388
     9
header{*Analogues of the Cartesian Product and Disjoint Sum for Datatypes*}
nipkow@10213
    10
paulson@15388
    11
theory Datatype_Universe
paulson@15388
    12
imports NatArith Sum_Type
paulson@15388
    13
begin
nipkow@10213
    14
nipkow@10213
    15
nipkow@10213
    16
typedef (Node)
paulson@11483
    17
  ('a,'b) node = "{p. EX f x k. p = (f::nat=>'b+nat, x::'a+nat) & f k = Inr 0}"
paulson@15388
    18
    --{*it is a subtype of @{text "(nat=>'b+nat) * ('a+nat)"}*}
paulson@15388
    19
  by auto
nipkow@10213
    20
paulson@15388
    21
text{*Datatypes will be represented by sets of type @{text node}*}
paulson@15388
    22
paulson@15388
    23
types 'a item        = "('a, unit) node set"
paulson@15388
    24
      ('a, 'b) dtree = "('a, 'b) node set"
nipkow@10213
    25
nipkow@10213
    26
consts
nipkow@10213
    27
  apfst     :: "['a=>'c, 'a*'b] => 'c*'b"
nipkow@10213
    28
  Push      :: "[('b + nat), nat => ('b + nat)] => (nat => ('b + nat))"
nipkow@10213
    29
nipkow@10213
    30
  Push_Node :: "[('b + nat), ('a, 'b) node] => ('a, 'b) node"
paulson@15388
    31
  ndepth    :: "('a, 'b) node => nat"
nipkow@10213
    32
nipkow@10213
    33
  Atom      :: "('a + nat) => ('a, 'b) dtree"
paulson@15388
    34
  Leaf      :: "'a => ('a, 'b) dtree"
paulson@15388
    35
  Numb      :: "nat => ('a, 'b) dtree"
paulson@15388
    36
  Scons     :: "[('a, 'b) dtree, ('a, 'b) dtree] => ('a, 'b) dtree"
paulson@15388
    37
  In0       :: "('a, 'b) dtree => ('a, 'b) dtree"
paulson@15388
    38
  In1       :: "('a, 'b) dtree => ('a, 'b) dtree"
paulson@15388
    39
  Lim       :: "('b => ('a, 'b) dtree) => ('a, 'b) dtree"
nipkow@10213
    40
paulson@15388
    41
  ntrunc    :: "[nat, ('a, 'b) dtree] => ('a, 'b) dtree"
nipkow@10213
    42
paulson@15388
    43
  uprod     :: "[('a, 'b) dtree set, ('a, 'b) dtree set]=> ('a, 'b) dtree set"
paulson@15388
    44
  usum      :: "[('a, 'b) dtree set, ('a, 'b) dtree set]=> ('a, 'b) dtree set"
nipkow@10213
    45
paulson@15388
    46
  Split     :: "[[('a, 'b) dtree, ('a, 'b) dtree]=>'c, ('a, 'b) dtree] => 'c"
paulson@15388
    47
  Case      :: "[[('a, 'b) dtree]=>'c, [('a, 'b) dtree]=>'c, ('a, 'b) dtree] => 'c"
nipkow@10213
    48
paulson@15388
    49
  dprod     :: "[(('a, 'b) dtree * ('a, 'b) dtree)set, (('a, 'b) dtree * ('a, 'b) dtree)set]
nipkow@10213
    50
                => (('a, 'b) dtree * ('a, 'b) dtree)set"
paulson@15388
    51
  dsum      :: "[(('a, 'b) dtree * ('a, 'b) dtree)set, (('a, 'b) dtree * ('a, 'b) dtree)set]
nipkow@10213
    52
                => (('a, 'b) dtree * ('a, 'b) dtree)set"
nipkow@10213
    53
nipkow@10213
    54
nipkow@10213
    55
defs
nipkow@10213
    56
paulson@15388
    57
  Push_Node_def:  "Push_Node == (%n x. Abs_Node (apfst (Push n) (Rep_Node x)))"
nipkow@10213
    58
nipkow@10213
    59
  (*crude "lists" of nats -- needed for the constructions*)
paulson@15388
    60
  apfst_def:  "apfst == (%f (x,y). (f(x),y))"
paulson@15388
    61
  Push_def:   "Push == (%b h. nat_case b h)"
nipkow@10213
    62
nipkow@10213
    63
  (** operations on S-expressions -- sets of nodes **)
nipkow@10213
    64
nipkow@10213
    65
  (*S-expression constructors*)
paulson@15388
    66
  Atom_def:   "Atom == (%x. {Abs_Node((%k. Inr 0, x))})"
paulson@15388
    67
  Scons_def:  "Scons M N == (Push_Node (Inr 1) ` M) Un (Push_Node (Inr (Suc 1)) ` N)"
nipkow@10213
    68
nipkow@10213
    69
  (*Leaf nodes, with arbitrary or nat labels*)
paulson@15388
    70
  Leaf_def:   "Leaf == Atom o Inl"
paulson@15388
    71
  Numb_def:   "Numb == Atom o Inr"
nipkow@10213
    72
nipkow@10213
    73
  (*Injections of the "disjoint sum"*)
paulson@15388
    74
  In0_def:    "In0(M) == Scons (Numb 0) M"
paulson@15388
    75
  In1_def:    "In1(M) == Scons (Numb 1) M"
nipkow@10213
    76
nipkow@10213
    77
  (*Function spaces*)
paulson@15388
    78
  Lim_def: "Lim f == Union {z. ? x. z = Push_Node (Inl x) ` (f x)}"
nipkow@10213
    79
nipkow@10213
    80
  (*the set of nodes with depth less than k*)
paulson@15388
    81
  ndepth_def: "ndepth(n) == (%(f,x). LEAST k. f k = Inr 0) (Rep_Node n)"
paulson@15388
    82
  ntrunc_def: "ntrunc k N == {n. n:N & ndepth(n)<k}"
nipkow@10213
    83
nipkow@10213
    84
  (*products and sums for the "universe"*)
paulson@15388
    85
  uprod_def:  "uprod A B == UN x:A. UN y:B. { Scons x y }"
paulson@15388
    86
  usum_def:   "usum A B == In0`A Un In1`B"
nipkow@10213
    87
nipkow@10213
    88
  (*the corresponding eliminators*)
paulson@15388
    89
  Split_def:  "Split c M == THE u. EX x y. M = Scons x y & u = c x y"
nipkow@10213
    90
paulson@15388
    91
  Case_def:   "Case c d M == THE u.  (EX x . M = In0(x) & u = c(x))
paulson@11451
    92
                                  | (EX y . M = In1(y) & u = d(y))"
nipkow@10213
    93
nipkow@10213
    94
nipkow@10213
    95
  (** equality for the "universe" **)
nipkow@10213
    96
paulson@15388
    97
  dprod_def:  "dprod r s == UN (x,x'):r. UN (y,y'):s. {(Scons x y, Scons x' y')}"
nipkow@10213
    98
paulson@15388
    99
  dsum_def:   "dsum r s == (UN (x,x'):r. {(In0(x),In0(x'))}) Un
nipkow@10213
   100
                          (UN (y,y'):s. {(In1(y),In1(y'))})"
nipkow@10213
   101
paulson@15388
   102
paulson@15388
   103
paulson@15388
   104
(** apfst -- can be used in similar type definitions **)
paulson@15388
   105
paulson@15388
   106
lemma apfst_conv [simp]: "apfst f (a,b) = (f(a),b)"
paulson@15388
   107
by (simp add: apfst_def)
paulson@15388
   108
paulson@15388
   109
paulson@15388
   110
lemma apfst_convE: 
paulson@15388
   111
    "[| q = apfst f p;  !!x y. [| p = (x,y);  q = (f(x),y) |] ==> R  
paulson@15388
   112
     |] ==> R"
paulson@15388
   113
by (force simp add: apfst_def)
paulson@15388
   114
paulson@15388
   115
(** Push -- an injection, analogous to Cons on lists **)
paulson@15388
   116
paulson@15388
   117
lemma Push_inject1: "Push i f = Push j g  ==> i=j"
paulson@15388
   118
apply (simp add: Push_def expand_fun_eq) 
paulson@15388
   119
apply (drule_tac x=0 in spec, simp) 
paulson@15388
   120
done
paulson@15388
   121
paulson@15388
   122
lemma Push_inject2: "Push i f = Push j g  ==> f=g"
paulson@15388
   123
apply (auto simp add: Push_def expand_fun_eq) 
paulson@15388
   124
apply (drule_tac x="Suc x" in spec, simp) 
paulson@15388
   125
done
paulson@15388
   126
paulson@15388
   127
lemma Push_inject:
paulson@15388
   128
    "[| Push i f =Push j g;  [| i=j;  f=g |] ==> P |] ==> P"
paulson@15388
   129
by (blast dest: Push_inject1 Push_inject2) 
paulson@15388
   130
paulson@15388
   131
lemma Push_neq_K0: "Push (Inr (Suc k)) f = (%z. Inr 0) ==> P"
paulson@15388
   132
by (auto simp add: Push_def expand_fun_eq split: nat.split_asm)
paulson@15388
   133
paulson@15388
   134
(*** Isomorphisms ***)
paulson@15388
   135
paulson@15388
   136
lemma inj_Rep_Node: "inj(Rep_Node)"
paulson@15388
   137
apply (rule inj_on_inverseI) 
paulson@15388
   138
apply (rule Rep_Node_inverse)
paulson@15388
   139
done
paulson@15388
   140
paulson@15388
   141
lemma inj_on_Abs_Node: "inj_on Abs_Node Node"
paulson@15388
   142
apply (rule inj_on_inverseI)
paulson@15388
   143
apply (erule Abs_Node_inverse)
paulson@15388
   144
done
paulson@15388
   145
paulson@15388
   146
lemmas Abs_Node_inj = inj_on_Abs_Node [THEN inj_onD, standard]
paulson@15388
   147
paulson@15388
   148
paulson@15388
   149
(*** Introduction rules for Node ***)
paulson@15388
   150
paulson@15388
   151
lemma Node_K0_I: "(%k. Inr 0, a) : Node"
paulson@15388
   152
by (simp add: Node_def)
paulson@15388
   153
paulson@15388
   154
lemma Node_Push_I: 
paulson@15388
   155
    "p: Node ==> apfst (Push i) p : Node"
paulson@15388
   156
apply (simp add: Node_def Push_def) 
paulson@15388
   157
apply (fast intro!: apfst_conv nat_case_Suc [THEN trans])
paulson@15388
   158
done
paulson@15388
   159
paulson@15388
   160
paulson@15388
   161
subsubsection{*Freeness: Distinctness of Constructors*}
paulson@15388
   162
paulson@15388
   163
(** Scons vs Atom **)
paulson@15388
   164
paulson@15388
   165
lemma Scons_not_Atom [iff]: "Scons M N \<noteq> Atom(a)"
paulson@15388
   166
apply (simp add: Atom_def Scons_def Push_Node_def One_nat_def)
paulson@15388
   167
apply (blast intro: Node_K0_I Rep_Node [THEN Node_Push_I] 
paulson@15388
   168
         dest!: Abs_Node_inj 
paulson@15388
   169
         elim!: apfst_convE sym [THEN Push_neq_K0])  
paulson@15388
   170
done
paulson@15388
   171
paulson@15388
   172
lemmas Atom_not_Scons = Scons_not_Atom [THEN not_sym, standard, iff]
paulson@15388
   173
paulson@15388
   174
paulson@15388
   175
(*** Injectiveness ***)
paulson@15388
   176
paulson@15388
   177
(** Atomic nodes **)
paulson@15388
   178
paulson@15388
   179
lemma inj_Atom: "inj(Atom)"
paulson@15388
   180
apply (simp add: Atom_def)
paulson@15388
   181
apply (blast intro!: inj_onI Node_K0_I dest!: Abs_Node_inj)
paulson@15388
   182
done
paulson@15388
   183
lemmas Atom_inject = inj_Atom [THEN injD, standard]
paulson@15388
   184
paulson@15388
   185
lemma Atom_Atom_eq [iff]: "(Atom(a)=Atom(b)) = (a=b)"
paulson@15388
   186
by (blast dest!: Atom_inject)
paulson@15388
   187
paulson@15388
   188
lemma inj_Leaf: "inj(Leaf)"
paulson@15388
   189
apply (simp add: Leaf_def o_def)
paulson@15388
   190
apply (rule inj_onI)
paulson@15388
   191
apply (erule Atom_inject [THEN Inl_inject])
paulson@15388
   192
done
paulson@15388
   193
paulson@15388
   194
lemmas Leaf_inject = inj_Leaf [THEN injD, standard, dest!]
paulson@15388
   195
paulson@15388
   196
lemma inj_Numb: "inj(Numb)"
paulson@15388
   197
apply (simp add: Numb_def o_def)
paulson@15388
   198
apply (rule inj_onI)
paulson@15388
   199
apply (erule Atom_inject [THEN Inr_inject])
paulson@15388
   200
done
paulson@15388
   201
paulson@15388
   202
lemmas Numb_inject = inj_Numb [THEN injD, standard, dest!]
paulson@15388
   203
paulson@15388
   204
paulson@15388
   205
(** Injectiveness of Push_Node **)
paulson@15388
   206
paulson@15388
   207
lemma Push_Node_inject:
paulson@15388
   208
    "[| Push_Node i m =Push_Node j n;  [| i=j;  m=n |] ==> P  
paulson@15388
   209
     |] ==> P"
paulson@15388
   210
apply (simp add: Push_Node_def)
paulson@15388
   211
apply (erule Abs_Node_inj [THEN apfst_convE])
paulson@15388
   212
apply (rule Rep_Node [THEN Node_Push_I])+
paulson@15388
   213
apply (erule sym [THEN apfst_convE]) 
paulson@15388
   214
apply (blast intro: inj_Rep_Node [THEN injD] trans sym elim!: Push_inject)
paulson@15388
   215
done
paulson@15388
   216
paulson@15388
   217
paulson@15388
   218
(** Injectiveness of Scons **)
paulson@15388
   219
paulson@15388
   220
lemma Scons_inject_lemma1: "Scons M N <= Scons M' N' ==> M<=M'"
paulson@15388
   221
apply (simp add: Scons_def One_nat_def)
paulson@15388
   222
apply (blast dest!: Push_Node_inject)
paulson@15388
   223
done
paulson@15388
   224
paulson@15388
   225
lemma Scons_inject_lemma2: "Scons M N <= Scons M' N' ==> N<=N'"
paulson@15388
   226
apply (simp add: Scons_def One_nat_def)
paulson@15388
   227
apply (blast dest!: Push_Node_inject)
paulson@15388
   228
done
paulson@15388
   229
paulson@15388
   230
lemma Scons_inject1: "Scons M N = Scons M' N' ==> M=M'"
paulson@15388
   231
apply (erule equalityE)
paulson@15388
   232
apply (rules intro: equalityI Scons_inject_lemma1)
paulson@15388
   233
done
paulson@15388
   234
paulson@15388
   235
lemma Scons_inject2: "Scons M N = Scons M' N' ==> N=N'"
paulson@15388
   236
apply (erule equalityE)
paulson@15388
   237
apply (rules intro: equalityI Scons_inject_lemma2)
paulson@15388
   238
done
paulson@15388
   239
paulson@15388
   240
lemma Scons_inject:
paulson@15388
   241
    "[| Scons M N = Scons M' N';  [| M=M';  N=N' |] ==> P |] ==> P"
paulson@15388
   242
by (rules dest: Scons_inject1 Scons_inject2)
paulson@15388
   243
paulson@15388
   244
lemma Scons_Scons_eq [iff]: "(Scons M N = Scons M' N') = (M=M' & N=N')"
paulson@15388
   245
by (blast elim!: Scons_inject)
paulson@15388
   246
paulson@15388
   247
(*** Distinctness involving Leaf and Numb ***)
paulson@15388
   248
paulson@15388
   249
(** Scons vs Leaf **)
paulson@15388
   250
paulson@15388
   251
lemma Scons_not_Leaf [iff]: "Scons M N \<noteq> Leaf(a)"
paulson@15388
   252
by (simp add: Leaf_def o_def Scons_not_Atom)
paulson@15388
   253
paulson@15388
   254
lemmas Leaf_not_Scons = Scons_not_Leaf [THEN not_sym, standard, iff]
paulson@15388
   255
paulson@15388
   256
paulson@15388
   257
(** Scons vs Numb **)
paulson@15388
   258
paulson@15388
   259
lemma Scons_not_Numb [iff]: "Scons M N \<noteq> Numb(k)"
paulson@15388
   260
by (simp add: Numb_def o_def Scons_not_Atom)
paulson@15388
   261
paulson@15388
   262
lemmas Numb_not_Scons = Scons_not_Numb [THEN not_sym, standard, iff]
paulson@15388
   263
paulson@15388
   264
paulson@15388
   265
paulson@15388
   266
(** Leaf vs Numb **)
paulson@15388
   267
paulson@15388
   268
lemma Leaf_not_Numb [iff]: "Leaf(a) \<noteq> Numb(k)"
paulson@15388
   269
by (simp add: Leaf_def Numb_def)
paulson@15388
   270
paulson@15388
   271
lemmas Numb_not_Leaf = Leaf_not_Numb [THEN not_sym, standard, iff]
paulson@15388
   272
paulson@15388
   273
paulson@15388
   274
paulson@15388
   275
(*** ndepth -- the depth of a node ***)
paulson@15388
   276
paulson@15388
   277
lemma ndepth_K0: "ndepth (Abs_Node(%k. Inr 0, x)) = 0"
paulson@15388
   278
by (simp add: ndepth_def  Node_K0_I [THEN Abs_Node_inverse] Least_equality)
paulson@15388
   279
paulson@15388
   280
lemma ndepth_Push_Node_aux:
paulson@15388
   281
     "nat_case (Inr (Suc i)) f k = Inr 0 --> Suc(LEAST x. f x = Inr 0) <= k"
paulson@15388
   282
apply (induct_tac "k", auto)
paulson@15388
   283
apply (erule Least_le)
paulson@15388
   284
done
paulson@15388
   285
paulson@15388
   286
lemma ndepth_Push_Node: 
paulson@15388
   287
    "ndepth (Push_Node (Inr (Suc i)) n) = Suc(ndepth(n))"
paulson@15388
   288
apply (insert Rep_Node [of n, unfolded Node_def])
paulson@15388
   289
apply (auto simp add: ndepth_def Push_Node_def
paulson@15388
   290
                 Rep_Node [THEN Node_Push_I, THEN Abs_Node_inverse])
paulson@15388
   291
apply (rule Least_equality)
paulson@15388
   292
apply (auto simp add: Push_def ndepth_Push_Node_aux)
paulson@15388
   293
apply (erule LeastI)
paulson@15388
   294
done
paulson@15388
   295
paulson@15388
   296
paulson@15388
   297
(*** ntrunc applied to the various node sets ***)
paulson@15388
   298
paulson@15388
   299
lemma ntrunc_0 [simp]: "ntrunc 0 M = {}"
paulson@15388
   300
by (simp add: ntrunc_def)
paulson@15388
   301
paulson@15388
   302
lemma ntrunc_Atom [simp]: "ntrunc (Suc k) (Atom a) = Atom(a)"
paulson@15388
   303
by (auto simp add: Atom_def ntrunc_def ndepth_K0)
paulson@15388
   304
paulson@15388
   305
lemma ntrunc_Leaf [simp]: "ntrunc (Suc k) (Leaf a) = Leaf(a)"
paulson@15388
   306
by (simp add: Leaf_def o_def ntrunc_Atom)
paulson@15388
   307
paulson@15388
   308
lemma ntrunc_Numb [simp]: "ntrunc (Suc k) (Numb i) = Numb(i)"
paulson@15388
   309
by (simp add: Numb_def o_def ntrunc_Atom)
paulson@15388
   310
paulson@15388
   311
lemma ntrunc_Scons [simp]: 
paulson@15388
   312
    "ntrunc (Suc k) (Scons M N) = Scons (ntrunc k M) (ntrunc k N)"
paulson@15388
   313
by (auto simp add: Scons_def ntrunc_def One_nat_def ndepth_Push_Node) 
paulson@15388
   314
paulson@15388
   315
paulson@15388
   316
paulson@15388
   317
(** Injection nodes **)
paulson@15388
   318
paulson@15388
   319
lemma ntrunc_one_In0 [simp]: "ntrunc (Suc 0) (In0 M) = {}"
paulson@15388
   320
apply (simp add: In0_def)
paulson@15388
   321
apply (simp add: Scons_def)
paulson@15388
   322
done
paulson@15388
   323
paulson@15388
   324
lemma ntrunc_In0 [simp]: "ntrunc (Suc(Suc k)) (In0 M) = In0 (ntrunc (Suc k) M)"
paulson@15388
   325
by (simp add: In0_def)
paulson@15388
   326
paulson@15388
   327
lemma ntrunc_one_In1 [simp]: "ntrunc (Suc 0) (In1 M) = {}"
paulson@15388
   328
apply (simp add: In1_def)
paulson@15388
   329
apply (simp add: Scons_def)
paulson@15388
   330
done
paulson@15388
   331
paulson@15388
   332
lemma ntrunc_In1 [simp]: "ntrunc (Suc(Suc k)) (In1 M) = In1 (ntrunc (Suc k) M)"
paulson@15388
   333
by (simp add: In1_def)
paulson@15388
   334
paulson@15388
   335
paulson@15388
   336
subsection{*Set Constructions*}
paulson@15388
   337
paulson@15388
   338
paulson@15388
   339
(*** Cartesian Product ***)
paulson@15388
   340
paulson@15388
   341
lemma uprodI [intro!]: "[| M:A;  N:B |] ==> Scons M N : uprod A B"
paulson@15388
   342
by (simp add: uprod_def)
paulson@15388
   343
paulson@15388
   344
(*The general elimination rule*)
paulson@15388
   345
lemma uprodE [elim!]:
paulson@15388
   346
    "[| c : uprod A B;   
paulson@15388
   347
        !!x y. [| x:A;  y:B;  c = Scons x y |] ==> P  
paulson@15388
   348
     |] ==> P"
paulson@15388
   349
by (auto simp add: uprod_def) 
paulson@15388
   350
paulson@15388
   351
paulson@15388
   352
(*Elimination of a pair -- introduces no eigenvariables*)
paulson@15388
   353
lemma uprodE2: "[| Scons M N : uprod A B;  [| M:A;  N:B |] ==> P |] ==> P"
paulson@15388
   354
by (auto simp add: uprod_def)
paulson@15388
   355
paulson@15388
   356
paulson@15388
   357
(*** Disjoint Sum ***)
paulson@15388
   358
paulson@15388
   359
lemma usum_In0I [intro]: "M:A ==> In0(M) : usum A B"
paulson@15388
   360
by (simp add: usum_def)
paulson@15388
   361
paulson@15388
   362
lemma usum_In1I [intro]: "N:B ==> In1(N) : usum A B"
paulson@15388
   363
by (simp add: usum_def)
paulson@15388
   364
paulson@15388
   365
lemma usumE [elim!]: 
paulson@15388
   366
    "[| u : usum A B;   
paulson@15388
   367
        !!x. [| x:A;  u=In0(x) |] ==> P;  
paulson@15388
   368
        !!y. [| y:B;  u=In1(y) |] ==> P  
paulson@15388
   369
     |] ==> P"
paulson@15388
   370
by (auto simp add: usum_def)
paulson@15388
   371
paulson@15388
   372
paulson@15388
   373
(** Injection **)
paulson@15388
   374
paulson@15388
   375
lemma In0_not_In1 [iff]: "In0(M) \<noteq> In1(N)"
paulson@15388
   376
by (auto simp add: In0_def In1_def One_nat_def)
paulson@15388
   377
paulson@15388
   378
lemmas In1_not_In0 = In0_not_In1 [THEN not_sym, standard, iff]
paulson@15388
   379
paulson@15388
   380
lemma In0_inject: "In0(M) = In0(N) ==>  M=N"
paulson@15388
   381
by (simp add: In0_def)
paulson@15388
   382
paulson@15388
   383
lemma In1_inject: "In1(M) = In1(N) ==>  M=N"
paulson@15388
   384
by (simp add: In1_def)
paulson@15388
   385
paulson@15388
   386
lemma In0_eq [iff]: "(In0 M = In0 N) = (M=N)"
paulson@15388
   387
by (blast dest!: In0_inject)
paulson@15388
   388
paulson@15388
   389
lemma In1_eq [iff]: "(In1 M = In1 N) = (M=N)"
paulson@15388
   390
by (blast dest!: In1_inject)
paulson@15388
   391
paulson@15388
   392
lemma inj_In0: "inj In0"
paulson@15388
   393
by (blast intro!: inj_onI)
paulson@15388
   394
paulson@15388
   395
lemma inj_In1: "inj In1"
paulson@15388
   396
by (blast intro!: inj_onI)
paulson@15388
   397
paulson@15388
   398
paulson@15388
   399
(*** Function spaces ***)
paulson@15388
   400
paulson@15388
   401
lemma Lim_inject: "Lim f = Lim g ==> f = g"
paulson@15388
   402
apply (simp add: Lim_def)
paulson@15388
   403
apply (rule ext)
paulson@15388
   404
apply (blast elim!: Push_Node_inject)
paulson@15388
   405
done
paulson@15388
   406
paulson@15388
   407
paulson@15388
   408
(*** proving equality of sets and functions using ntrunc ***)
paulson@15388
   409
paulson@15388
   410
lemma ntrunc_subsetI: "ntrunc k M <= M"
paulson@15388
   411
by (auto simp add: ntrunc_def)
paulson@15388
   412
paulson@15388
   413
lemma ntrunc_subsetD: "(!!k. ntrunc k M <= N) ==> M<=N"
paulson@15388
   414
by (auto simp add: ntrunc_def)
paulson@15388
   415
paulson@15388
   416
(*A generalized form of the take-lemma*)
paulson@15388
   417
lemma ntrunc_equality: "(!!k. ntrunc k M = ntrunc k N) ==> M=N"
paulson@15388
   418
apply (rule equalityI)
paulson@15388
   419
apply (rule_tac [!] ntrunc_subsetD)
paulson@15388
   420
apply (rule_tac [!] ntrunc_subsetI [THEN [2] subset_trans], auto) 
paulson@15388
   421
done
paulson@15388
   422
paulson@15388
   423
lemma ntrunc_o_equality: 
paulson@15388
   424
    "[| !!k. (ntrunc(k) o h1) = (ntrunc(k) o h2) |] ==> h1=h2"
paulson@15388
   425
apply (rule ntrunc_equality [THEN ext])
paulson@15388
   426
apply (simp add: expand_fun_eq) 
paulson@15388
   427
done
paulson@15388
   428
paulson@15388
   429
paulson@15388
   430
(*** Monotonicity ***)
paulson@15388
   431
paulson@15388
   432
lemma uprod_mono: "[| A<=A';  B<=B' |] ==> uprod A B <= uprod A' B'"
paulson@15388
   433
by (simp add: uprod_def, blast)
paulson@15388
   434
paulson@15388
   435
lemma usum_mono: "[| A<=A';  B<=B' |] ==> usum A B <= usum A' B'"
paulson@15388
   436
by (simp add: usum_def, blast)
paulson@15388
   437
paulson@15388
   438
lemma Scons_mono: "[| M<=M';  N<=N' |] ==> Scons M N <= Scons M' N'"
paulson@15388
   439
by (simp add: Scons_def, blast)
paulson@15388
   440
paulson@15388
   441
lemma In0_mono: "M<=N ==> In0(M) <= In0(N)"
paulson@15388
   442
by (simp add: In0_def subset_refl Scons_mono)
paulson@15388
   443
paulson@15388
   444
lemma In1_mono: "M<=N ==> In1(M) <= In1(N)"
paulson@15388
   445
by (simp add: In1_def subset_refl Scons_mono)
paulson@15388
   446
paulson@15388
   447
paulson@15388
   448
(*** Split and Case ***)
paulson@15388
   449
paulson@15388
   450
lemma Split [simp]: "Split c (Scons M N) = c M N"
paulson@15388
   451
by (simp add: Split_def)
paulson@15388
   452
paulson@15388
   453
lemma Case_In0 [simp]: "Case c d (In0 M) = c(M)"
paulson@15388
   454
by (simp add: Case_def)
paulson@15388
   455
paulson@15388
   456
lemma Case_In1 [simp]: "Case c d (In1 N) = d(N)"
paulson@15388
   457
by (simp add: Case_def)
paulson@15388
   458
paulson@15388
   459
paulson@15388
   460
paulson@15388
   461
(**** UN x. B(x) rules ****)
paulson@15388
   462
paulson@15388
   463
lemma ntrunc_UN1: "ntrunc k (UN x. f(x)) = (UN x. ntrunc k (f x))"
paulson@15388
   464
by (simp add: ntrunc_def, blast)
paulson@15388
   465
paulson@15388
   466
lemma Scons_UN1_x: "Scons (UN x. f x) M = (UN x. Scons (f x) M)"
paulson@15388
   467
by (simp add: Scons_def, blast)
paulson@15388
   468
paulson@15388
   469
lemma Scons_UN1_y: "Scons M (UN x. f x) = (UN x. Scons M (f x))"
paulson@15388
   470
by (simp add: Scons_def, blast)
paulson@15388
   471
paulson@15388
   472
lemma In0_UN1: "In0(UN x. f(x)) = (UN x. In0(f(x)))"
paulson@15388
   473
by (simp add: In0_def Scons_UN1_y)
paulson@15388
   474
paulson@15388
   475
lemma In1_UN1: "In1(UN x. f(x)) = (UN x. In1(f(x)))"
paulson@15388
   476
by (simp add: In1_def Scons_UN1_y)
paulson@15388
   477
paulson@15388
   478
paulson@15388
   479
(*** Equality for Cartesian Product ***)
paulson@15388
   480
paulson@15388
   481
lemma dprodI [intro!]: 
paulson@15388
   482
    "[| (M,M'):r;  (N,N'):s |] ==> (Scons M N, Scons M' N') : dprod r s"
paulson@15388
   483
by (auto simp add: dprod_def)
paulson@15388
   484
paulson@15388
   485
(*The general elimination rule*)
paulson@15388
   486
lemma dprodE [elim!]: 
paulson@15388
   487
    "[| c : dprod r s;   
paulson@15388
   488
        !!x y x' y'. [| (x,x') : r;  (y,y') : s;  
paulson@15388
   489
                        c = (Scons x y, Scons x' y') |] ==> P  
paulson@15388
   490
     |] ==> P"
paulson@15388
   491
by (auto simp add: dprod_def)
paulson@15388
   492
paulson@15388
   493
paulson@15388
   494
(*** Equality for Disjoint Sum ***)
paulson@15388
   495
paulson@15388
   496
lemma dsum_In0I [intro]: "(M,M'):r ==> (In0(M), In0(M')) : dsum r s"
paulson@15388
   497
by (auto simp add: dsum_def)
paulson@15388
   498
paulson@15388
   499
lemma dsum_In1I [intro]: "(N,N'):s ==> (In1(N), In1(N')) : dsum r s"
paulson@15388
   500
by (auto simp add: dsum_def)
paulson@15388
   501
paulson@15388
   502
lemma dsumE [elim!]: 
paulson@15388
   503
    "[| w : dsum r s;   
paulson@15388
   504
        !!x x'. [| (x,x') : r;  w = (In0(x), In0(x')) |] ==> P;  
paulson@15388
   505
        !!y y'. [| (y,y') : s;  w = (In1(y), In1(y')) |] ==> P  
paulson@15388
   506
     |] ==> P"
paulson@15388
   507
by (auto simp add: dsum_def)
paulson@15388
   508
paulson@15388
   509
paulson@15388
   510
(*** Monotonicity ***)
paulson@15388
   511
paulson@15388
   512
lemma dprod_mono: "[| r<=r';  s<=s' |] ==> dprod r s <= dprod r' s'"
paulson@15388
   513
by blast
paulson@15388
   514
paulson@15388
   515
lemma dsum_mono: "[| r<=r';  s<=s' |] ==> dsum r s <= dsum r' s'"
paulson@15388
   516
by blast
paulson@15388
   517
paulson@15388
   518
paulson@15388
   519
(*** Bounding theorems ***)
paulson@15388
   520
paulson@15388
   521
lemma dprod_Sigma: "(dprod (A <*> B) (C <*> D)) <= (uprod A C) <*> (uprod B D)"
paulson@15388
   522
by blast
paulson@15388
   523
paulson@15388
   524
lemmas dprod_subset_Sigma = subset_trans [OF dprod_mono dprod_Sigma, standard]
paulson@15388
   525
paulson@15388
   526
(*Dependent version*)
paulson@15388
   527
lemma dprod_subset_Sigma2:
paulson@15388
   528
     "(dprod (Sigma A B) (Sigma C D)) <= 
paulson@15388
   529
      Sigma (uprod A C) (Split (%x y. uprod (B x) (D y)))"
paulson@15388
   530
by auto
paulson@15388
   531
paulson@15388
   532
lemma dsum_Sigma: "(dsum (A <*> B) (C <*> D)) <= (usum A C) <*> (usum B D)"
paulson@15388
   533
by blast
paulson@15388
   534
paulson@15388
   535
lemmas dsum_subset_Sigma = subset_trans [OF dsum_mono dsum_Sigma, standard]
paulson@15388
   536
paulson@15388
   537
paulson@15388
   538
(*** Domain ***)
paulson@15388
   539
paulson@15388
   540
lemma Domain_dprod [simp]: "Domain (dprod r s) = uprod (Domain r) (Domain s)"
paulson@15388
   541
by auto
paulson@15388
   542
paulson@15388
   543
lemma Domain_dsum [simp]: "Domain (dsum r s) = usum (Domain r) (Domain s)"
paulson@15388
   544
by auto
paulson@15388
   545
paulson@15388
   546
ML
paulson@15388
   547
{*
paulson@15388
   548
val apfst_conv = thm "apfst_conv";
paulson@15388
   549
val apfst_convE = thm "apfst_convE";
paulson@15388
   550
val Push_inject1 = thm "Push_inject1";
paulson@15388
   551
val Push_inject2 = thm "Push_inject2";
paulson@15388
   552
val Push_inject = thm "Push_inject";
paulson@15388
   553
val Push_neq_K0 = thm "Push_neq_K0";
paulson@15388
   554
val inj_Rep_Node = thm "inj_Rep_Node";
paulson@15388
   555
val inj_on_Abs_Node = thm "inj_on_Abs_Node";
paulson@15388
   556
val Abs_Node_inj = thm "Abs_Node_inj";
paulson@15388
   557
val Node_K0_I = thm "Node_K0_I";
paulson@15388
   558
val Node_Push_I = thm "Node_Push_I";
paulson@15388
   559
val Scons_not_Atom = thm "Scons_not_Atom";
paulson@15388
   560
val Atom_not_Scons = thm "Atom_not_Scons";
paulson@15388
   561
val inj_Atom = thm "inj_Atom";
paulson@15388
   562
val Atom_inject = thm "Atom_inject";
paulson@15388
   563
val Atom_Atom_eq = thm "Atom_Atom_eq";
paulson@15388
   564
val inj_Leaf = thm "inj_Leaf";
paulson@15388
   565
val Leaf_inject = thm "Leaf_inject";
paulson@15388
   566
val inj_Numb = thm "inj_Numb";
paulson@15388
   567
val Numb_inject = thm "Numb_inject";
paulson@15388
   568
val Push_Node_inject = thm "Push_Node_inject";
paulson@15388
   569
val Scons_inject1 = thm "Scons_inject1";
paulson@15388
   570
val Scons_inject2 = thm "Scons_inject2";
paulson@15388
   571
val Scons_inject = thm "Scons_inject";
paulson@15388
   572
val Scons_Scons_eq = thm "Scons_Scons_eq";
paulson@15388
   573
val Scons_not_Leaf = thm "Scons_not_Leaf";
paulson@15388
   574
val Leaf_not_Scons = thm "Leaf_not_Scons";
paulson@15388
   575
val Scons_not_Numb = thm "Scons_not_Numb";
paulson@15388
   576
val Numb_not_Scons = thm "Numb_not_Scons";
paulson@15388
   577
val Leaf_not_Numb = thm "Leaf_not_Numb";
paulson@15388
   578
val Numb_not_Leaf = thm "Numb_not_Leaf";
paulson@15388
   579
val ndepth_K0 = thm "ndepth_K0";
paulson@15388
   580
val ndepth_Push_Node_aux = thm "ndepth_Push_Node_aux";
paulson@15388
   581
val ndepth_Push_Node = thm "ndepth_Push_Node";
paulson@15388
   582
val ntrunc_0 = thm "ntrunc_0";
paulson@15388
   583
val ntrunc_Atom = thm "ntrunc_Atom";
paulson@15388
   584
val ntrunc_Leaf = thm "ntrunc_Leaf";
paulson@15388
   585
val ntrunc_Numb = thm "ntrunc_Numb";
paulson@15388
   586
val ntrunc_Scons = thm "ntrunc_Scons";
paulson@15388
   587
val ntrunc_one_In0 = thm "ntrunc_one_In0";
paulson@15388
   588
val ntrunc_In0 = thm "ntrunc_In0";
paulson@15388
   589
val ntrunc_one_In1 = thm "ntrunc_one_In1";
paulson@15388
   590
val ntrunc_In1 = thm "ntrunc_In1";
paulson@15388
   591
val uprodI = thm "uprodI";
paulson@15388
   592
val uprodE = thm "uprodE";
paulson@15388
   593
val uprodE2 = thm "uprodE2";
paulson@15388
   594
val usum_In0I = thm "usum_In0I";
paulson@15388
   595
val usum_In1I = thm "usum_In1I";
paulson@15388
   596
val usumE = thm "usumE";
paulson@15388
   597
val In0_not_In1 = thm "In0_not_In1";
paulson@15388
   598
val In1_not_In0 = thm "In1_not_In0";
paulson@15388
   599
val In0_inject = thm "In0_inject";
paulson@15388
   600
val In1_inject = thm "In1_inject";
paulson@15388
   601
val In0_eq = thm "In0_eq";
paulson@15388
   602
val In1_eq = thm "In1_eq";
paulson@15388
   603
val inj_In0 = thm "inj_In0";
paulson@15388
   604
val inj_In1 = thm "inj_In1";
paulson@15388
   605
val Lim_inject = thm "Lim_inject";
paulson@15388
   606
val ntrunc_subsetI = thm "ntrunc_subsetI";
paulson@15388
   607
val ntrunc_subsetD = thm "ntrunc_subsetD";
paulson@15388
   608
val ntrunc_equality = thm "ntrunc_equality";
paulson@15388
   609
val ntrunc_o_equality = thm "ntrunc_o_equality";
paulson@15388
   610
val uprod_mono = thm "uprod_mono";
paulson@15388
   611
val usum_mono = thm "usum_mono";
paulson@15388
   612
val Scons_mono = thm "Scons_mono";
paulson@15388
   613
val In0_mono = thm "In0_mono";
paulson@15388
   614
val In1_mono = thm "In1_mono";
paulson@15388
   615
val Split = thm "Split";
paulson@15388
   616
val Case_In0 = thm "Case_In0";
paulson@15388
   617
val Case_In1 = thm "Case_In1";
paulson@15388
   618
val ntrunc_UN1 = thm "ntrunc_UN1";
paulson@15388
   619
val Scons_UN1_x = thm "Scons_UN1_x";
paulson@15388
   620
val Scons_UN1_y = thm "Scons_UN1_y";
paulson@15388
   621
val In0_UN1 = thm "In0_UN1";
paulson@15388
   622
val In1_UN1 = thm "In1_UN1";
paulson@15388
   623
val dprodI = thm "dprodI";
paulson@15388
   624
val dprodE = thm "dprodE";
paulson@15388
   625
val dsum_In0I = thm "dsum_In0I";
paulson@15388
   626
val dsum_In1I = thm "dsum_In1I";
paulson@15388
   627
val dsumE = thm "dsumE";
paulson@15388
   628
val dprod_mono = thm "dprod_mono";
paulson@15388
   629
val dsum_mono = thm "dsum_mono";
paulson@15388
   630
val dprod_Sigma = thm "dprod_Sigma";
paulson@15388
   631
val dprod_subset_Sigma = thm "dprod_subset_Sigma";
paulson@15388
   632
val dprod_subset_Sigma2 = thm "dprod_subset_Sigma2";
paulson@15388
   633
val dsum_Sigma = thm "dsum_Sigma";
paulson@15388
   634
val dsum_subset_Sigma = thm "dsum_subset_Sigma";
paulson@15388
   635
val Domain_dprod = thm "Domain_dprod";
paulson@15388
   636
val Domain_dsum = thm "Domain_dsum";
paulson@15388
   637
*}
paulson@15388
   638
nipkow@10213
   639
end