src/HOL/Datatype_Universe.thy
author haftmann
Mon Aug 14 13:46:06 2006 +0200 (2006-08-14)
changeset 20380 14f9f2a1caa6
parent 17589 58eeffd73be1
child 20799 46694b230cfb
permissions -rw-r--r--
simplified code generator setup
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@15413
   134
lemmas Abs_Node_inj = Abs_Node_inject [THEN [2] rev_iffD1, standard]
paulson@15388
   135
paulson@15388
   136
paulson@15388
   137
(*** Introduction rules for Node ***)
paulson@15388
   138
paulson@15388
   139
lemma Node_K0_I: "(%k. Inr 0, a) : Node"
paulson@15388
   140
by (simp add: Node_def)
paulson@15388
   141
paulson@15413
   142
lemma Node_Push_I: "p: Node ==> apfst (Push i) p : Node"
paulson@15388
   143
apply (simp add: Node_def Push_def) 
paulson@15388
   144
apply (fast intro!: apfst_conv nat_case_Suc [THEN trans])
paulson@15388
   145
done
paulson@15388
   146
paulson@15388
   147
wenzelm@17472
   148
subsection{*Freeness: Distinctness of Constructors*}
paulson@15388
   149
paulson@15388
   150
(** Scons vs Atom **)
paulson@15388
   151
paulson@15388
   152
lemma Scons_not_Atom [iff]: "Scons M N \<noteq> Atom(a)"
paulson@15388
   153
apply (simp add: Atom_def Scons_def Push_Node_def One_nat_def)
paulson@15388
   154
apply (blast intro: Node_K0_I Rep_Node [THEN Node_Push_I] 
paulson@15388
   155
         dest!: Abs_Node_inj 
paulson@15388
   156
         elim!: apfst_convE sym [THEN Push_neq_K0])  
paulson@15388
   157
done
paulson@15388
   158
paulson@17084
   159
lemmas Atom_not_Scons = Scons_not_Atom [THEN not_sym, standard]
paulson@17084
   160
declare Atom_not_Scons [iff]
paulson@15388
   161
paulson@15388
   162
(*** Injectiveness ***)
paulson@15388
   163
paulson@15388
   164
(** Atomic nodes **)
paulson@15388
   165
paulson@15388
   166
lemma inj_Atom: "inj(Atom)"
paulson@15388
   167
apply (simp add: Atom_def)
paulson@15388
   168
apply (blast intro!: inj_onI Node_K0_I dest!: Abs_Node_inj)
paulson@15388
   169
done
paulson@15388
   170
lemmas Atom_inject = inj_Atom [THEN injD, standard]
paulson@15388
   171
paulson@15388
   172
lemma Atom_Atom_eq [iff]: "(Atom(a)=Atom(b)) = (a=b)"
paulson@15388
   173
by (blast dest!: Atom_inject)
paulson@15388
   174
paulson@15388
   175
lemma inj_Leaf: "inj(Leaf)"
paulson@15388
   176
apply (simp add: Leaf_def o_def)
paulson@15388
   177
apply (rule inj_onI)
paulson@15388
   178
apply (erule Atom_inject [THEN Inl_inject])
paulson@15388
   179
done
paulson@15388
   180
paulson@17084
   181
lemmas Leaf_inject = inj_Leaf [THEN injD, standard]
paulson@17084
   182
declare Leaf_inject [dest!]
paulson@15388
   183
paulson@15388
   184
lemma inj_Numb: "inj(Numb)"
paulson@15388
   185
apply (simp add: Numb_def o_def)
paulson@15388
   186
apply (rule inj_onI)
paulson@15388
   187
apply (erule Atom_inject [THEN Inr_inject])
paulson@15388
   188
done
paulson@15388
   189
paulson@17084
   190
lemmas Numb_inject = inj_Numb [THEN injD, standard]
paulson@17084
   191
declare Numb_inject [dest!]
paulson@15388
   192
paulson@15388
   193
paulson@15388
   194
(** Injectiveness of Push_Node **)
paulson@15388
   195
paulson@15388
   196
lemma Push_Node_inject:
paulson@15388
   197
    "[| Push_Node i m =Push_Node j n;  [| i=j;  m=n |] ==> P  
paulson@15388
   198
     |] ==> P"
paulson@15388
   199
apply (simp add: Push_Node_def)
paulson@15388
   200
apply (erule Abs_Node_inj [THEN apfst_convE])
paulson@15388
   201
apply (rule Rep_Node [THEN Node_Push_I])+
paulson@15388
   202
apply (erule sym [THEN apfst_convE]) 
paulson@15413
   203
apply (blast intro: Rep_Node_inject [THEN iffD1] trans sym elim!: Push_inject)
paulson@15388
   204
done
paulson@15388
   205
paulson@15388
   206
paulson@15388
   207
(** Injectiveness of Scons **)
paulson@15388
   208
paulson@15388
   209
lemma Scons_inject_lemma1: "Scons M N <= Scons M' N' ==> M<=M'"
paulson@15388
   210
apply (simp add: Scons_def One_nat_def)
paulson@15388
   211
apply (blast dest!: Push_Node_inject)
paulson@15388
   212
done
paulson@15388
   213
paulson@15388
   214
lemma Scons_inject_lemma2: "Scons M N <= Scons M' N' ==> N<=N'"
paulson@15388
   215
apply (simp add: Scons_def One_nat_def)
paulson@15388
   216
apply (blast dest!: Push_Node_inject)
paulson@15388
   217
done
paulson@15388
   218
paulson@15388
   219
lemma Scons_inject1: "Scons M N = Scons M' N' ==> M=M'"
paulson@15388
   220
apply (erule equalityE)
nipkow@17589
   221
apply (iprover intro: equalityI Scons_inject_lemma1)
paulson@15388
   222
done
paulson@15388
   223
paulson@15388
   224
lemma Scons_inject2: "Scons M N = Scons M' N' ==> N=N'"
paulson@15388
   225
apply (erule equalityE)
nipkow@17589
   226
apply (iprover intro: equalityI Scons_inject_lemma2)
paulson@15388
   227
done
paulson@15388
   228
paulson@15388
   229
lemma Scons_inject:
paulson@15388
   230
    "[| Scons M N = Scons M' N';  [| M=M';  N=N' |] ==> P |] ==> P"
nipkow@17589
   231
by (iprover dest: Scons_inject1 Scons_inject2)
paulson@15388
   232
paulson@15388
   233
lemma Scons_Scons_eq [iff]: "(Scons M N = Scons M' N') = (M=M' & N=N')"
paulson@15388
   234
by (blast elim!: Scons_inject)
paulson@15388
   235
paulson@15388
   236
(*** Distinctness involving Leaf and Numb ***)
paulson@15388
   237
paulson@15388
   238
(** Scons vs Leaf **)
paulson@15388
   239
paulson@15388
   240
lemma Scons_not_Leaf [iff]: "Scons M N \<noteq> Leaf(a)"
paulson@15388
   241
by (simp add: Leaf_def o_def Scons_not_Atom)
paulson@15388
   242
paulson@17084
   243
lemmas Leaf_not_Scons = Scons_not_Leaf [THEN not_sym, standard]
paulson@17084
   244
declare Leaf_not_Scons [iff]
paulson@15388
   245
paulson@15388
   246
(** Scons vs Numb **)
paulson@15388
   247
paulson@15388
   248
lemma Scons_not_Numb [iff]: "Scons M N \<noteq> Numb(k)"
paulson@15388
   249
by (simp add: Numb_def o_def Scons_not_Atom)
paulson@15388
   250
paulson@17084
   251
lemmas Numb_not_Scons = Scons_not_Numb [THEN not_sym, standard]
paulson@17084
   252
declare Numb_not_Scons [iff]
paulson@15388
   253
paulson@15388
   254
paulson@15388
   255
(** Leaf vs Numb **)
paulson@15388
   256
paulson@15388
   257
lemma Leaf_not_Numb [iff]: "Leaf(a) \<noteq> Numb(k)"
paulson@15388
   258
by (simp add: Leaf_def Numb_def)
paulson@15388
   259
paulson@17084
   260
lemmas Numb_not_Leaf = Leaf_not_Numb [THEN not_sym, standard]
paulson@17084
   261
declare Numb_not_Leaf [iff]
paulson@15388
   262
paulson@15388
   263
paulson@15388
   264
(*** ndepth -- the depth of a node ***)
paulson@15388
   265
paulson@15388
   266
lemma ndepth_K0: "ndepth (Abs_Node(%k. Inr 0, x)) = 0"
paulson@15388
   267
by (simp add: ndepth_def  Node_K0_I [THEN Abs_Node_inverse] Least_equality)
paulson@15388
   268
paulson@15388
   269
lemma ndepth_Push_Node_aux:
paulson@15388
   270
     "nat_case (Inr (Suc i)) f k = Inr 0 --> Suc(LEAST x. f x = Inr 0) <= k"
paulson@15388
   271
apply (induct_tac "k", auto)
paulson@15388
   272
apply (erule Least_le)
paulson@15388
   273
done
paulson@15388
   274
paulson@15388
   275
lemma ndepth_Push_Node: 
paulson@15388
   276
    "ndepth (Push_Node (Inr (Suc i)) n) = Suc(ndepth(n))"
paulson@15388
   277
apply (insert Rep_Node [of n, unfolded Node_def])
paulson@15388
   278
apply (auto simp add: ndepth_def Push_Node_def
paulson@15388
   279
                 Rep_Node [THEN Node_Push_I, THEN Abs_Node_inverse])
paulson@15388
   280
apply (rule Least_equality)
paulson@15388
   281
apply (auto simp add: Push_def ndepth_Push_Node_aux)
paulson@15388
   282
apply (erule LeastI)
paulson@15388
   283
done
paulson@15388
   284
paulson@15388
   285
paulson@15388
   286
(*** ntrunc applied to the various node sets ***)
paulson@15388
   287
paulson@15388
   288
lemma ntrunc_0 [simp]: "ntrunc 0 M = {}"
paulson@15388
   289
by (simp add: ntrunc_def)
paulson@15388
   290
paulson@15388
   291
lemma ntrunc_Atom [simp]: "ntrunc (Suc k) (Atom a) = Atom(a)"
paulson@15388
   292
by (auto simp add: Atom_def ntrunc_def ndepth_K0)
paulson@15388
   293
paulson@15388
   294
lemma ntrunc_Leaf [simp]: "ntrunc (Suc k) (Leaf a) = Leaf(a)"
paulson@15388
   295
by (simp add: Leaf_def o_def ntrunc_Atom)
paulson@15388
   296
paulson@15388
   297
lemma ntrunc_Numb [simp]: "ntrunc (Suc k) (Numb i) = Numb(i)"
paulson@15388
   298
by (simp add: Numb_def o_def ntrunc_Atom)
paulson@15388
   299
paulson@15388
   300
lemma ntrunc_Scons [simp]: 
paulson@15388
   301
    "ntrunc (Suc k) (Scons M N) = Scons (ntrunc k M) (ntrunc k N)"
paulson@15388
   302
by (auto simp add: Scons_def ntrunc_def One_nat_def ndepth_Push_Node) 
paulson@15388
   303
paulson@15388
   304
paulson@15388
   305
paulson@15388
   306
(** Injection nodes **)
paulson@15388
   307
paulson@15388
   308
lemma ntrunc_one_In0 [simp]: "ntrunc (Suc 0) (In0 M) = {}"
paulson@15388
   309
apply (simp add: In0_def)
paulson@15388
   310
apply (simp add: Scons_def)
paulson@15388
   311
done
paulson@15388
   312
paulson@15388
   313
lemma ntrunc_In0 [simp]: "ntrunc (Suc(Suc k)) (In0 M) = In0 (ntrunc (Suc k) M)"
paulson@15388
   314
by (simp add: In0_def)
paulson@15388
   315
paulson@15388
   316
lemma ntrunc_one_In1 [simp]: "ntrunc (Suc 0) (In1 M) = {}"
paulson@15388
   317
apply (simp add: In1_def)
paulson@15388
   318
apply (simp add: Scons_def)
paulson@15388
   319
done
paulson@15388
   320
paulson@15388
   321
lemma ntrunc_In1 [simp]: "ntrunc (Suc(Suc k)) (In1 M) = In1 (ntrunc (Suc k) M)"
paulson@15388
   322
by (simp add: In1_def)
paulson@15388
   323
paulson@15388
   324
paulson@15388
   325
subsection{*Set Constructions*}
paulson@15388
   326
paulson@15388
   327
paulson@15388
   328
(*** Cartesian Product ***)
paulson@15388
   329
paulson@15388
   330
lemma uprodI [intro!]: "[| M:A;  N:B |] ==> Scons M N : uprod A B"
paulson@15388
   331
by (simp add: uprod_def)
paulson@15388
   332
paulson@15388
   333
(*The general elimination rule*)
paulson@15388
   334
lemma uprodE [elim!]:
paulson@15388
   335
    "[| c : uprod A B;   
paulson@15388
   336
        !!x y. [| x:A;  y:B;  c = Scons x y |] ==> P  
paulson@15388
   337
     |] ==> P"
paulson@15388
   338
by (auto simp add: uprod_def) 
paulson@15388
   339
paulson@15388
   340
paulson@15388
   341
(*Elimination of a pair -- introduces no eigenvariables*)
paulson@15388
   342
lemma uprodE2: "[| Scons M N : uprod A B;  [| M:A;  N:B |] ==> P |] ==> P"
paulson@15388
   343
by (auto simp add: uprod_def)
paulson@15388
   344
paulson@15388
   345
paulson@15388
   346
(*** Disjoint Sum ***)
paulson@15388
   347
paulson@15388
   348
lemma usum_In0I [intro]: "M:A ==> In0(M) : usum A B"
paulson@15388
   349
by (simp add: usum_def)
paulson@15388
   350
paulson@15388
   351
lemma usum_In1I [intro]: "N:B ==> In1(N) : usum A B"
paulson@15388
   352
by (simp add: usum_def)
paulson@15388
   353
paulson@15388
   354
lemma usumE [elim!]: 
paulson@15388
   355
    "[| u : usum A B;   
paulson@15388
   356
        !!x. [| x:A;  u=In0(x) |] ==> P;  
paulson@15388
   357
        !!y. [| y:B;  u=In1(y) |] ==> P  
paulson@15388
   358
     |] ==> P"
paulson@15388
   359
by (auto simp add: usum_def)
paulson@15388
   360
paulson@15388
   361
paulson@15388
   362
(** Injection **)
paulson@15388
   363
paulson@15388
   364
lemma In0_not_In1 [iff]: "In0(M) \<noteq> In1(N)"
paulson@15388
   365
by (auto simp add: In0_def In1_def One_nat_def)
paulson@15388
   366
paulson@17084
   367
lemmas In1_not_In0 = In0_not_In1 [THEN not_sym, standard]
paulson@17084
   368
declare In1_not_In0 [iff]
paulson@15388
   369
paulson@15388
   370
lemma In0_inject: "In0(M) = In0(N) ==>  M=N"
paulson@15388
   371
by (simp add: In0_def)
paulson@15388
   372
paulson@15388
   373
lemma In1_inject: "In1(M) = In1(N) ==>  M=N"
paulson@15388
   374
by (simp add: In1_def)
paulson@15388
   375
paulson@15388
   376
lemma In0_eq [iff]: "(In0 M = In0 N) = (M=N)"
paulson@15388
   377
by (blast dest!: In0_inject)
paulson@15388
   378
paulson@15388
   379
lemma In1_eq [iff]: "(In1 M = In1 N) = (M=N)"
paulson@15388
   380
by (blast dest!: In1_inject)
paulson@15388
   381
paulson@15388
   382
lemma inj_In0: "inj In0"
paulson@15388
   383
by (blast intro!: inj_onI)
paulson@15388
   384
paulson@15388
   385
lemma inj_In1: "inj In1"
paulson@15388
   386
by (blast intro!: inj_onI)
paulson@15388
   387
paulson@15388
   388
paulson@15388
   389
(*** Function spaces ***)
paulson@15388
   390
paulson@15388
   391
lemma Lim_inject: "Lim f = Lim g ==> f = g"
paulson@15388
   392
apply (simp add: Lim_def)
paulson@15388
   393
apply (rule ext)
paulson@15388
   394
apply (blast elim!: Push_Node_inject)
paulson@15388
   395
done
paulson@15388
   396
paulson@15388
   397
paulson@15388
   398
(*** proving equality of sets and functions using ntrunc ***)
paulson@15388
   399
paulson@15388
   400
lemma ntrunc_subsetI: "ntrunc k M <= M"
paulson@15388
   401
by (auto simp add: ntrunc_def)
paulson@15388
   402
paulson@15388
   403
lemma ntrunc_subsetD: "(!!k. ntrunc k M <= N) ==> M<=N"
paulson@15388
   404
by (auto simp add: ntrunc_def)
paulson@15388
   405
paulson@15388
   406
(*A generalized form of the take-lemma*)
paulson@15388
   407
lemma ntrunc_equality: "(!!k. ntrunc k M = ntrunc k N) ==> M=N"
paulson@15388
   408
apply (rule equalityI)
paulson@15388
   409
apply (rule_tac [!] ntrunc_subsetD)
paulson@15388
   410
apply (rule_tac [!] ntrunc_subsetI [THEN [2] subset_trans], auto) 
paulson@15388
   411
done
paulson@15388
   412
paulson@15388
   413
lemma ntrunc_o_equality: 
paulson@15388
   414
    "[| !!k. (ntrunc(k) o h1) = (ntrunc(k) o h2) |] ==> h1=h2"
paulson@15388
   415
apply (rule ntrunc_equality [THEN ext])
paulson@15388
   416
apply (simp add: expand_fun_eq) 
paulson@15388
   417
done
paulson@15388
   418
paulson@15388
   419
paulson@15388
   420
(*** Monotonicity ***)
paulson@15388
   421
paulson@15388
   422
lemma uprod_mono: "[| A<=A';  B<=B' |] ==> uprod A B <= uprod A' B'"
paulson@15388
   423
by (simp add: uprod_def, blast)
paulson@15388
   424
paulson@15388
   425
lemma usum_mono: "[| A<=A';  B<=B' |] ==> usum A B <= usum A' B'"
paulson@15388
   426
by (simp add: usum_def, blast)
paulson@15388
   427
paulson@15388
   428
lemma Scons_mono: "[| M<=M';  N<=N' |] ==> Scons M N <= Scons M' N'"
paulson@15388
   429
by (simp add: Scons_def, blast)
paulson@15388
   430
paulson@15388
   431
lemma In0_mono: "M<=N ==> In0(M) <= In0(N)"
paulson@15388
   432
by (simp add: In0_def subset_refl Scons_mono)
paulson@15388
   433
paulson@15388
   434
lemma In1_mono: "M<=N ==> In1(M) <= In1(N)"
paulson@15388
   435
by (simp add: In1_def subset_refl Scons_mono)
paulson@15388
   436
paulson@15388
   437
paulson@15388
   438
(*** Split and Case ***)
paulson@15388
   439
paulson@15388
   440
lemma Split [simp]: "Split c (Scons M N) = c M N"
paulson@15388
   441
by (simp add: Split_def)
paulson@15388
   442
paulson@15388
   443
lemma Case_In0 [simp]: "Case c d (In0 M) = c(M)"
paulson@15388
   444
by (simp add: Case_def)
paulson@15388
   445
paulson@15388
   446
lemma Case_In1 [simp]: "Case c d (In1 N) = d(N)"
paulson@15388
   447
by (simp add: Case_def)
paulson@15388
   448
paulson@15388
   449
paulson@15388
   450
paulson@15388
   451
(**** UN x. B(x) rules ****)
paulson@15388
   452
paulson@15388
   453
lemma ntrunc_UN1: "ntrunc k (UN x. f(x)) = (UN x. ntrunc k (f x))"
paulson@15388
   454
by (simp add: ntrunc_def, blast)
paulson@15388
   455
paulson@15388
   456
lemma Scons_UN1_x: "Scons (UN x. f x) M = (UN x. Scons (f x) M)"
paulson@15388
   457
by (simp add: Scons_def, blast)
paulson@15388
   458
paulson@15388
   459
lemma Scons_UN1_y: "Scons M (UN x. f x) = (UN x. Scons M (f x))"
paulson@15388
   460
by (simp add: Scons_def, blast)
paulson@15388
   461
paulson@15388
   462
lemma In0_UN1: "In0(UN x. f(x)) = (UN x. In0(f(x)))"
paulson@15388
   463
by (simp add: In0_def Scons_UN1_y)
paulson@15388
   464
paulson@15388
   465
lemma In1_UN1: "In1(UN x. f(x)) = (UN x. In1(f(x)))"
paulson@15388
   466
by (simp add: In1_def Scons_UN1_y)
paulson@15388
   467
paulson@15388
   468
paulson@15388
   469
(*** Equality for Cartesian Product ***)
paulson@15388
   470
paulson@15388
   471
lemma dprodI [intro!]: 
paulson@15388
   472
    "[| (M,M'):r;  (N,N'):s |] ==> (Scons M N, Scons M' N') : dprod r s"
paulson@15388
   473
by (auto simp add: dprod_def)
paulson@15388
   474
paulson@15388
   475
(*The general elimination rule*)
paulson@15388
   476
lemma dprodE [elim!]: 
paulson@15388
   477
    "[| c : dprod r s;   
paulson@15388
   478
        !!x y x' y'. [| (x,x') : r;  (y,y') : s;  
paulson@15388
   479
                        c = (Scons x y, Scons x' y') |] ==> P  
paulson@15388
   480
     |] ==> P"
paulson@15388
   481
by (auto simp add: dprod_def)
paulson@15388
   482
paulson@15388
   483
paulson@15388
   484
(*** Equality for Disjoint Sum ***)
paulson@15388
   485
paulson@15388
   486
lemma dsum_In0I [intro]: "(M,M'):r ==> (In0(M), In0(M')) : dsum r s"
paulson@15388
   487
by (auto simp add: dsum_def)
paulson@15388
   488
paulson@15388
   489
lemma dsum_In1I [intro]: "(N,N'):s ==> (In1(N), In1(N')) : dsum r s"
paulson@15388
   490
by (auto simp add: dsum_def)
paulson@15388
   491
paulson@15388
   492
lemma dsumE [elim!]: 
paulson@15388
   493
    "[| w : dsum r s;   
paulson@15388
   494
        !!x x'. [| (x,x') : r;  w = (In0(x), In0(x')) |] ==> P;  
paulson@15388
   495
        !!y y'. [| (y,y') : s;  w = (In1(y), In1(y')) |] ==> P  
paulson@15388
   496
     |] ==> P"
paulson@15388
   497
by (auto simp add: dsum_def)
paulson@15388
   498
paulson@15388
   499
paulson@15388
   500
(*** Monotonicity ***)
paulson@15388
   501
paulson@15388
   502
lemma dprod_mono: "[| r<=r';  s<=s' |] ==> dprod r s <= dprod r' s'"
paulson@15388
   503
by blast
paulson@15388
   504
paulson@15388
   505
lemma dsum_mono: "[| r<=r';  s<=s' |] ==> dsum r s <= dsum r' s'"
paulson@15388
   506
by blast
paulson@15388
   507
paulson@15388
   508
paulson@15388
   509
(*** Bounding theorems ***)
paulson@15388
   510
paulson@15388
   511
lemma dprod_Sigma: "(dprod (A <*> B) (C <*> D)) <= (uprod A C) <*> (uprod B D)"
paulson@15388
   512
by blast
paulson@15388
   513
paulson@15388
   514
lemmas dprod_subset_Sigma = subset_trans [OF dprod_mono dprod_Sigma, standard]
paulson@15388
   515
paulson@15388
   516
(*Dependent version*)
paulson@15388
   517
lemma dprod_subset_Sigma2:
paulson@15388
   518
     "(dprod (Sigma A B) (Sigma C D)) <= 
paulson@15388
   519
      Sigma (uprod A C) (Split (%x y. uprod (B x) (D y)))"
paulson@15388
   520
by auto
paulson@15388
   521
paulson@15388
   522
lemma dsum_Sigma: "(dsum (A <*> B) (C <*> D)) <= (usum A C) <*> (usum B D)"
paulson@15388
   523
by blast
paulson@15388
   524
paulson@15388
   525
lemmas dsum_subset_Sigma = subset_trans [OF dsum_mono dsum_Sigma, standard]
paulson@15388
   526
paulson@15388
   527
paulson@15388
   528
(*** Domain ***)
paulson@15388
   529
paulson@15388
   530
lemma Domain_dprod [simp]: "Domain (dprod r s) = uprod (Domain r) (Domain s)"
paulson@15388
   531
by auto
paulson@15388
   532
paulson@15388
   533
lemma Domain_dsum [simp]: "Domain (dsum r s) = usum (Domain r) (Domain s)"
paulson@15388
   534
by auto
paulson@15388
   535
paulson@15388
   536
ML
paulson@15388
   537
{*
paulson@15388
   538
val apfst_conv = thm "apfst_conv";
paulson@15388
   539
val apfst_convE = thm "apfst_convE";
paulson@15388
   540
val Push_inject1 = thm "Push_inject1";
paulson@15388
   541
val Push_inject2 = thm "Push_inject2";
paulson@15388
   542
val Push_inject = thm "Push_inject";
paulson@15388
   543
val Push_neq_K0 = thm "Push_neq_K0";
paulson@15388
   544
val Abs_Node_inj = thm "Abs_Node_inj";
paulson@15388
   545
val Node_K0_I = thm "Node_K0_I";
paulson@15388
   546
val Node_Push_I = thm "Node_Push_I";
paulson@15388
   547
val Scons_not_Atom = thm "Scons_not_Atom";
paulson@15388
   548
val Atom_not_Scons = thm "Atom_not_Scons";
paulson@15388
   549
val inj_Atom = thm "inj_Atom";
paulson@15388
   550
val Atom_inject = thm "Atom_inject";
paulson@15388
   551
val Atom_Atom_eq = thm "Atom_Atom_eq";
paulson@15388
   552
val inj_Leaf = thm "inj_Leaf";
paulson@15388
   553
val Leaf_inject = thm "Leaf_inject";
paulson@15388
   554
val inj_Numb = thm "inj_Numb";
paulson@15388
   555
val Numb_inject = thm "Numb_inject";
paulson@15388
   556
val Push_Node_inject = thm "Push_Node_inject";
paulson@15388
   557
val Scons_inject1 = thm "Scons_inject1";
paulson@15388
   558
val Scons_inject2 = thm "Scons_inject2";
paulson@15388
   559
val Scons_inject = thm "Scons_inject";
paulson@15388
   560
val Scons_Scons_eq = thm "Scons_Scons_eq";
paulson@15388
   561
val Scons_not_Leaf = thm "Scons_not_Leaf";
paulson@15388
   562
val Leaf_not_Scons = thm "Leaf_not_Scons";
paulson@15388
   563
val Scons_not_Numb = thm "Scons_not_Numb";
paulson@15388
   564
val Numb_not_Scons = thm "Numb_not_Scons";
paulson@15388
   565
val Leaf_not_Numb = thm "Leaf_not_Numb";
paulson@15388
   566
val Numb_not_Leaf = thm "Numb_not_Leaf";
paulson@15388
   567
val ndepth_K0 = thm "ndepth_K0";
paulson@15388
   568
val ndepth_Push_Node_aux = thm "ndepth_Push_Node_aux";
paulson@15388
   569
val ndepth_Push_Node = thm "ndepth_Push_Node";
paulson@15388
   570
val ntrunc_0 = thm "ntrunc_0";
paulson@15388
   571
val ntrunc_Atom = thm "ntrunc_Atom";
paulson@15388
   572
val ntrunc_Leaf = thm "ntrunc_Leaf";
paulson@15388
   573
val ntrunc_Numb = thm "ntrunc_Numb";
paulson@15388
   574
val ntrunc_Scons = thm "ntrunc_Scons";
paulson@15388
   575
val ntrunc_one_In0 = thm "ntrunc_one_In0";
paulson@15388
   576
val ntrunc_In0 = thm "ntrunc_In0";
paulson@15388
   577
val ntrunc_one_In1 = thm "ntrunc_one_In1";
paulson@15388
   578
val ntrunc_In1 = thm "ntrunc_In1";
paulson@15388
   579
val uprodI = thm "uprodI";
paulson@15388
   580
val uprodE = thm "uprodE";
paulson@15388
   581
val uprodE2 = thm "uprodE2";
paulson@15388
   582
val usum_In0I = thm "usum_In0I";
paulson@15388
   583
val usum_In1I = thm "usum_In1I";
paulson@15388
   584
val usumE = thm "usumE";
paulson@15388
   585
val In0_not_In1 = thm "In0_not_In1";
paulson@15388
   586
val In1_not_In0 = thm "In1_not_In0";
paulson@15388
   587
val In0_inject = thm "In0_inject";
paulson@15388
   588
val In1_inject = thm "In1_inject";
paulson@15388
   589
val In0_eq = thm "In0_eq";
paulson@15388
   590
val In1_eq = thm "In1_eq";
paulson@15388
   591
val inj_In0 = thm "inj_In0";
paulson@15388
   592
val inj_In1 = thm "inj_In1";
paulson@15388
   593
val Lim_inject = thm "Lim_inject";
paulson@15388
   594
val ntrunc_subsetI = thm "ntrunc_subsetI";
paulson@15388
   595
val ntrunc_subsetD = thm "ntrunc_subsetD";
paulson@15388
   596
val ntrunc_equality = thm "ntrunc_equality";
paulson@15388
   597
val ntrunc_o_equality = thm "ntrunc_o_equality";
paulson@15388
   598
val uprod_mono = thm "uprod_mono";
paulson@15388
   599
val usum_mono = thm "usum_mono";
paulson@15388
   600
val Scons_mono = thm "Scons_mono";
paulson@15388
   601
val In0_mono = thm "In0_mono";
paulson@15388
   602
val In1_mono = thm "In1_mono";
paulson@15388
   603
val Split = thm "Split";
paulson@15388
   604
val Case_In0 = thm "Case_In0";
paulson@15388
   605
val Case_In1 = thm "Case_In1";
paulson@15388
   606
val ntrunc_UN1 = thm "ntrunc_UN1";
paulson@15388
   607
val Scons_UN1_x = thm "Scons_UN1_x";
paulson@15388
   608
val Scons_UN1_y = thm "Scons_UN1_y";
paulson@15388
   609
val In0_UN1 = thm "In0_UN1";
paulson@15388
   610
val In1_UN1 = thm "In1_UN1";
paulson@15388
   611
val dprodI = thm "dprodI";
paulson@15388
   612
val dprodE = thm "dprodE";
paulson@15388
   613
val dsum_In0I = thm "dsum_In0I";
paulson@15388
   614
val dsum_In1I = thm "dsum_In1I";
paulson@15388
   615
val dsumE = thm "dsumE";
paulson@15388
   616
val dprod_mono = thm "dprod_mono";
paulson@15388
   617
val dsum_mono = thm "dsum_mono";
paulson@15388
   618
val dprod_Sigma = thm "dprod_Sigma";
paulson@15388
   619
val dprod_subset_Sigma = thm "dprod_subset_Sigma";
paulson@15388
   620
val dprod_subset_Sigma2 = thm "dprod_subset_Sigma2";
paulson@15388
   621
val dsum_Sigma = thm "dsum_Sigma";
paulson@15388
   622
val dsum_subset_Sigma = thm "dsum_subset_Sigma";
paulson@15388
   623
val Domain_dprod = thm "Domain_dprod";
paulson@15388
   624
val Domain_dsum = thm "Domain_dsum";
paulson@15388
   625
*}
paulson@15388
   626
nipkow@10213
   627
end