src/HOL/Datatype.thy
author haftmann
Mon Oct 16 14:07:31 2006 +0200 (2006-10-16)
changeset 21046 fe1db2f991a7
parent 20847 7e8c724339e0
child 21060 bc1fa6f47ced
permissions -rw-r--r--
moved HOL code generator setup to Code_Generator
berghofe@5181
     1
(*  Title:      HOL/Datatype.thy
berghofe@5181
     2
    ID:         $Id$
wenzelm@20819
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
wenzelm@11954
     4
    Author:     Stefan Berghofer and Markus Wenzel, TU Muenchen
wenzelm@20819
     5
wenzelm@20819
     6
Could <*> be generalized to a general summation (Sigma)?
berghofe@5181
     7
*)
berghofe@5181
     8
wenzelm@20819
     9
header{*Analogues of the Cartesian Product and Disjoint Sum for Datatypes*}
wenzelm@11954
    10
nipkow@15131
    11
theory Datatype
wenzelm@20819
    12
imports NatArith Sum_Type
nipkow@15131
    13
begin
wenzelm@11954
    14
wenzelm@20819
    15
typedef (Node)
wenzelm@20819
    16
  ('a,'b) node = "{p. EX f x k. p = (f::nat=>'b+nat, x::'a+nat) & f k = Inr 0}"
wenzelm@20819
    17
    --{*it is a subtype of @{text "(nat=>'b+nat) * ('a+nat)"}*}
wenzelm@20819
    18
  by auto
wenzelm@20819
    19
wenzelm@20819
    20
text{*Datatypes will be represented by sets of type @{text node}*}
wenzelm@20819
    21
wenzelm@20819
    22
types 'a item        = "('a, unit) node set"
wenzelm@20819
    23
      ('a, 'b) dtree = "('a, 'b) node set"
wenzelm@20819
    24
wenzelm@20819
    25
consts
wenzelm@20819
    26
  apfst     :: "['a=>'c, 'a*'b] => 'c*'b"
wenzelm@20819
    27
  Push      :: "[('b + nat), nat => ('b + nat)] => (nat => ('b + nat))"
wenzelm@20819
    28
wenzelm@20819
    29
  Push_Node :: "[('b + nat), ('a, 'b) node] => ('a, 'b) node"
wenzelm@20819
    30
  ndepth    :: "('a, 'b) node => nat"
wenzelm@20819
    31
wenzelm@20819
    32
  Atom      :: "('a + nat) => ('a, 'b) dtree"
wenzelm@20819
    33
  Leaf      :: "'a => ('a, 'b) dtree"
wenzelm@20819
    34
  Numb      :: "nat => ('a, 'b) dtree"
wenzelm@20819
    35
  Scons     :: "[('a, 'b) dtree, ('a, 'b) dtree] => ('a, 'b) dtree"
wenzelm@20819
    36
  In0       :: "('a, 'b) dtree => ('a, 'b) dtree"
wenzelm@20819
    37
  In1       :: "('a, 'b) dtree => ('a, 'b) dtree"
wenzelm@20819
    38
  Lim       :: "('b => ('a, 'b) dtree) => ('a, 'b) dtree"
wenzelm@20819
    39
wenzelm@20819
    40
  ntrunc    :: "[nat, ('a, 'b) dtree] => ('a, 'b) dtree"
wenzelm@20819
    41
wenzelm@20819
    42
  uprod     :: "[('a, 'b) dtree set, ('a, 'b) dtree set]=> ('a, 'b) dtree set"
wenzelm@20819
    43
  usum      :: "[('a, 'b) dtree set, ('a, 'b) dtree set]=> ('a, 'b) dtree set"
wenzelm@20819
    44
wenzelm@20819
    45
  Split     :: "[[('a, 'b) dtree, ('a, 'b) dtree]=>'c, ('a, 'b) dtree] => 'c"
wenzelm@20819
    46
  Case      :: "[[('a, 'b) dtree]=>'c, [('a, 'b) dtree]=>'c, ('a, 'b) dtree] => 'c"
wenzelm@20819
    47
wenzelm@20819
    48
  dprod     :: "[(('a, 'b) dtree * ('a, 'b) dtree)set, (('a, 'b) dtree * ('a, 'b) dtree)set]
wenzelm@20819
    49
                => (('a, 'b) dtree * ('a, 'b) dtree)set"
wenzelm@20819
    50
  dsum      :: "[(('a, 'b) dtree * ('a, 'b) dtree)set, (('a, 'b) dtree * ('a, 'b) dtree)set]
wenzelm@20819
    51
                => (('a, 'b) dtree * ('a, 'b) dtree)set"
wenzelm@20819
    52
wenzelm@20819
    53
wenzelm@20819
    54
defs
wenzelm@20819
    55
wenzelm@20819
    56
  Push_Node_def:  "Push_Node == (%n x. Abs_Node (apfst (Push n) (Rep_Node x)))"
wenzelm@20819
    57
wenzelm@20819
    58
  (*crude "lists" of nats -- needed for the constructions*)
wenzelm@20819
    59
  apfst_def:  "apfst == (%f (x,y). (f(x),y))"
wenzelm@20819
    60
  Push_def:   "Push == (%b h. nat_case b h)"
wenzelm@20819
    61
wenzelm@20819
    62
  (** operations on S-expressions -- sets of nodes **)
wenzelm@20819
    63
wenzelm@20819
    64
  (*S-expression constructors*)
wenzelm@20819
    65
  Atom_def:   "Atom == (%x. {Abs_Node((%k. Inr 0, x))})"
wenzelm@20819
    66
  Scons_def:  "Scons M N == (Push_Node (Inr 1) ` M) Un (Push_Node (Inr (Suc 1)) ` N)"
wenzelm@20819
    67
wenzelm@20819
    68
  (*Leaf nodes, with arbitrary or nat labels*)
wenzelm@20819
    69
  Leaf_def:   "Leaf == Atom o Inl"
wenzelm@20819
    70
  Numb_def:   "Numb == Atom o Inr"
wenzelm@20819
    71
wenzelm@20819
    72
  (*Injections of the "disjoint sum"*)
wenzelm@20819
    73
  In0_def:    "In0(M) == Scons (Numb 0) M"
wenzelm@20819
    74
  In1_def:    "In1(M) == Scons (Numb 1) M"
wenzelm@20819
    75
wenzelm@20819
    76
  (*Function spaces*)
wenzelm@20819
    77
  Lim_def: "Lim f == Union {z. ? x. z = Push_Node (Inl x) ` (f x)}"
wenzelm@20819
    78
wenzelm@20819
    79
  (*the set of nodes with depth less than k*)
wenzelm@20819
    80
  ndepth_def: "ndepth(n) == (%(f,x). LEAST k. f k = Inr 0) (Rep_Node n)"
wenzelm@20819
    81
  ntrunc_def: "ntrunc k N == {n. n:N & ndepth(n)<k}"
wenzelm@20819
    82
wenzelm@20819
    83
  (*products and sums for the "universe"*)
wenzelm@20819
    84
  uprod_def:  "uprod A B == UN x:A. UN y:B. { Scons x y }"
wenzelm@20819
    85
  usum_def:   "usum A B == In0`A Un In1`B"
wenzelm@20819
    86
wenzelm@20819
    87
  (*the corresponding eliminators*)
wenzelm@20819
    88
  Split_def:  "Split c M == THE u. EX x y. M = Scons x y & u = c x y"
wenzelm@20819
    89
wenzelm@20819
    90
  Case_def:   "Case c d M == THE u.  (EX x . M = In0(x) & u = c(x))
wenzelm@20819
    91
                                  | (EX y . M = In1(y) & u = d(y))"
wenzelm@20819
    92
wenzelm@20819
    93
wenzelm@20819
    94
  (** equality for the "universe" **)
wenzelm@20819
    95
wenzelm@20819
    96
  dprod_def:  "dprod r s == UN (x,x'):r. UN (y,y'):s. {(Scons x y, Scons x' y')}"
wenzelm@20819
    97
wenzelm@20819
    98
  dsum_def:   "dsum r s == (UN (x,x'):r. {(In0(x),In0(x'))}) Un
wenzelm@20819
    99
                          (UN (y,y'):s. {(In1(y),In1(y'))})"
wenzelm@20819
   100
wenzelm@20819
   101
wenzelm@20819
   102
wenzelm@20819
   103
(** apfst -- can be used in similar type definitions **)
wenzelm@20819
   104
wenzelm@20819
   105
lemma apfst_conv [simp]: "apfst f (a,b) = (f(a),b)"
wenzelm@20819
   106
by (simp add: apfst_def)
wenzelm@20819
   107
wenzelm@20819
   108
wenzelm@20819
   109
lemma apfst_convE: 
wenzelm@20819
   110
    "[| q = apfst f p;  !!x y. [| p = (x,y);  q = (f(x),y) |] ==> R  
wenzelm@20819
   111
     |] ==> R"
wenzelm@20819
   112
by (force simp add: apfst_def)
wenzelm@20819
   113
wenzelm@20819
   114
(** Push -- an injection, analogous to Cons on lists **)
wenzelm@20819
   115
wenzelm@20819
   116
lemma Push_inject1: "Push i f = Push j g  ==> i=j"
wenzelm@20819
   117
apply (simp add: Push_def expand_fun_eq) 
wenzelm@20819
   118
apply (drule_tac x=0 in spec, simp) 
wenzelm@20819
   119
done
wenzelm@20819
   120
wenzelm@20819
   121
lemma Push_inject2: "Push i f = Push j g  ==> f=g"
wenzelm@20819
   122
apply (auto simp add: Push_def expand_fun_eq) 
wenzelm@20819
   123
apply (drule_tac x="Suc x" in spec, simp) 
wenzelm@20819
   124
done
wenzelm@20819
   125
wenzelm@20819
   126
lemma Push_inject:
wenzelm@20819
   127
    "[| Push i f =Push j g;  [| i=j;  f=g |] ==> P |] ==> P"
wenzelm@20819
   128
by (blast dest: Push_inject1 Push_inject2) 
wenzelm@20819
   129
wenzelm@20819
   130
lemma Push_neq_K0: "Push (Inr (Suc k)) f = (%z. Inr 0) ==> P"
wenzelm@20819
   131
by (auto simp add: Push_def expand_fun_eq split: nat.split_asm)
wenzelm@20819
   132
wenzelm@20819
   133
lemmas Abs_Node_inj = Abs_Node_inject [THEN [2] rev_iffD1, standard]
wenzelm@20819
   134
wenzelm@20819
   135
wenzelm@20819
   136
(*** Introduction rules for Node ***)
wenzelm@20819
   137
wenzelm@20819
   138
lemma Node_K0_I: "(%k. Inr 0, a) : Node"
wenzelm@20819
   139
by (simp add: Node_def)
wenzelm@20819
   140
wenzelm@20819
   141
lemma Node_Push_I: "p: Node ==> apfst (Push i) p : Node"
wenzelm@20819
   142
apply (simp add: Node_def Push_def) 
wenzelm@20819
   143
apply (fast intro!: apfst_conv nat_case_Suc [THEN trans])
wenzelm@20819
   144
done
wenzelm@20819
   145
wenzelm@20819
   146
wenzelm@20819
   147
subsection{*Freeness: Distinctness of Constructors*}
wenzelm@20819
   148
wenzelm@20819
   149
(** Scons vs Atom **)
wenzelm@20819
   150
wenzelm@20819
   151
lemma Scons_not_Atom [iff]: "Scons M N \<noteq> Atom(a)"
wenzelm@20819
   152
apply (simp add: Atom_def Scons_def Push_Node_def One_nat_def)
wenzelm@20819
   153
apply (blast intro: Node_K0_I Rep_Node [THEN Node_Push_I] 
wenzelm@20819
   154
         dest!: Abs_Node_inj 
wenzelm@20819
   155
         elim!: apfst_convE sym [THEN Push_neq_K0])  
wenzelm@20819
   156
done
wenzelm@20819
   157
wenzelm@20819
   158
lemmas Atom_not_Scons = Scons_not_Atom [THEN not_sym, standard]
wenzelm@20819
   159
declare Atom_not_Scons [iff]
wenzelm@20819
   160
wenzelm@20819
   161
(*** Injectiveness ***)
wenzelm@20819
   162
wenzelm@20819
   163
(** Atomic nodes **)
wenzelm@20819
   164
wenzelm@20819
   165
lemma inj_Atom: "inj(Atom)"
wenzelm@20819
   166
apply (simp add: Atom_def)
wenzelm@20819
   167
apply (blast intro!: inj_onI Node_K0_I dest!: Abs_Node_inj)
wenzelm@20819
   168
done
wenzelm@20819
   169
lemmas Atom_inject = inj_Atom [THEN injD, standard]
wenzelm@20819
   170
wenzelm@20819
   171
lemma Atom_Atom_eq [iff]: "(Atom(a)=Atom(b)) = (a=b)"
wenzelm@20819
   172
by (blast dest!: Atom_inject)
wenzelm@20819
   173
wenzelm@20819
   174
lemma inj_Leaf: "inj(Leaf)"
wenzelm@20819
   175
apply (simp add: Leaf_def o_def)
wenzelm@20819
   176
apply (rule inj_onI)
wenzelm@20819
   177
apply (erule Atom_inject [THEN Inl_inject])
wenzelm@20819
   178
done
wenzelm@20819
   179
wenzelm@20819
   180
lemmas Leaf_inject = inj_Leaf [THEN injD, standard]
wenzelm@20819
   181
declare Leaf_inject [dest!]
wenzelm@20819
   182
wenzelm@20819
   183
lemma inj_Numb: "inj(Numb)"
wenzelm@20819
   184
apply (simp add: Numb_def o_def)
wenzelm@20819
   185
apply (rule inj_onI)
wenzelm@20819
   186
apply (erule Atom_inject [THEN Inr_inject])
wenzelm@20819
   187
done
wenzelm@20819
   188
wenzelm@20819
   189
lemmas Numb_inject = inj_Numb [THEN injD, standard]
wenzelm@20819
   190
declare Numb_inject [dest!]
wenzelm@20819
   191
wenzelm@20819
   192
wenzelm@20819
   193
(** Injectiveness of Push_Node **)
wenzelm@20819
   194
wenzelm@20819
   195
lemma Push_Node_inject:
wenzelm@20819
   196
    "[| Push_Node i m =Push_Node j n;  [| i=j;  m=n |] ==> P  
wenzelm@20819
   197
     |] ==> P"
wenzelm@20819
   198
apply (simp add: Push_Node_def)
wenzelm@20819
   199
apply (erule Abs_Node_inj [THEN apfst_convE])
wenzelm@20819
   200
apply (rule Rep_Node [THEN Node_Push_I])+
wenzelm@20819
   201
apply (erule sym [THEN apfst_convE]) 
wenzelm@20819
   202
apply (blast intro: Rep_Node_inject [THEN iffD1] trans sym elim!: Push_inject)
wenzelm@20819
   203
done
wenzelm@20819
   204
wenzelm@20819
   205
wenzelm@20819
   206
(** Injectiveness of Scons **)
wenzelm@20819
   207
wenzelm@20819
   208
lemma Scons_inject_lemma1: "Scons M N <= Scons M' N' ==> M<=M'"
wenzelm@20819
   209
apply (simp add: Scons_def One_nat_def)
wenzelm@20819
   210
apply (blast dest!: Push_Node_inject)
wenzelm@20819
   211
done
wenzelm@20819
   212
wenzelm@20819
   213
lemma Scons_inject_lemma2: "Scons M N <= Scons M' N' ==> N<=N'"
wenzelm@20819
   214
apply (simp add: Scons_def One_nat_def)
wenzelm@20819
   215
apply (blast dest!: Push_Node_inject)
wenzelm@20819
   216
done
wenzelm@20819
   217
wenzelm@20819
   218
lemma Scons_inject1: "Scons M N = Scons M' N' ==> M=M'"
wenzelm@20819
   219
apply (erule equalityE)
wenzelm@20819
   220
apply (iprover intro: equalityI Scons_inject_lemma1)
wenzelm@20819
   221
done
wenzelm@20819
   222
wenzelm@20819
   223
lemma Scons_inject2: "Scons M N = Scons M' N' ==> N=N'"
wenzelm@20819
   224
apply (erule equalityE)
wenzelm@20819
   225
apply (iprover intro: equalityI Scons_inject_lemma2)
wenzelm@20819
   226
done
wenzelm@20819
   227
wenzelm@20819
   228
lemma Scons_inject:
wenzelm@20819
   229
    "[| Scons M N = Scons M' N';  [| M=M';  N=N' |] ==> P |] ==> P"
wenzelm@20819
   230
by (iprover dest: Scons_inject1 Scons_inject2)
wenzelm@20819
   231
wenzelm@20819
   232
lemma Scons_Scons_eq [iff]: "(Scons M N = Scons M' N') = (M=M' & N=N')"
wenzelm@20819
   233
by (blast elim!: Scons_inject)
wenzelm@20819
   234
wenzelm@20819
   235
(*** Distinctness involving Leaf and Numb ***)
wenzelm@20819
   236
wenzelm@20819
   237
(** Scons vs Leaf **)
wenzelm@20819
   238
wenzelm@20819
   239
lemma Scons_not_Leaf [iff]: "Scons M N \<noteq> Leaf(a)"
wenzelm@20819
   240
by (simp add: Leaf_def o_def Scons_not_Atom)
wenzelm@20819
   241
wenzelm@20819
   242
lemmas Leaf_not_Scons = Scons_not_Leaf [THEN not_sym, standard]
wenzelm@20819
   243
declare Leaf_not_Scons [iff]
wenzelm@20819
   244
wenzelm@20819
   245
(** Scons vs Numb **)
wenzelm@20819
   246
wenzelm@20819
   247
lemma Scons_not_Numb [iff]: "Scons M N \<noteq> Numb(k)"
wenzelm@20819
   248
by (simp add: Numb_def o_def Scons_not_Atom)
wenzelm@20819
   249
wenzelm@20819
   250
lemmas Numb_not_Scons = Scons_not_Numb [THEN not_sym, standard]
wenzelm@20819
   251
declare Numb_not_Scons [iff]
wenzelm@20819
   252
wenzelm@20819
   253
wenzelm@20819
   254
(** Leaf vs Numb **)
wenzelm@20819
   255
wenzelm@20819
   256
lemma Leaf_not_Numb [iff]: "Leaf(a) \<noteq> Numb(k)"
wenzelm@20819
   257
by (simp add: Leaf_def Numb_def)
wenzelm@20819
   258
wenzelm@20819
   259
lemmas Numb_not_Leaf = Leaf_not_Numb [THEN not_sym, standard]
wenzelm@20819
   260
declare Numb_not_Leaf [iff]
wenzelm@20819
   261
wenzelm@20819
   262
wenzelm@20819
   263
(*** ndepth -- the depth of a node ***)
wenzelm@20819
   264
wenzelm@20819
   265
lemma ndepth_K0: "ndepth (Abs_Node(%k. Inr 0, x)) = 0"
wenzelm@20819
   266
by (simp add: ndepth_def  Node_K0_I [THEN Abs_Node_inverse] Least_equality)
wenzelm@20819
   267
wenzelm@20819
   268
lemma ndepth_Push_Node_aux:
wenzelm@20819
   269
     "nat_case (Inr (Suc i)) f k = Inr 0 --> Suc(LEAST x. f x = Inr 0) <= k"
wenzelm@20819
   270
apply (induct_tac "k", auto)
wenzelm@20819
   271
apply (erule Least_le)
wenzelm@20819
   272
done
wenzelm@20819
   273
wenzelm@20819
   274
lemma ndepth_Push_Node: 
wenzelm@20819
   275
    "ndepth (Push_Node (Inr (Suc i)) n) = Suc(ndepth(n))"
wenzelm@20819
   276
apply (insert Rep_Node [of n, unfolded Node_def])
wenzelm@20819
   277
apply (auto simp add: ndepth_def Push_Node_def
wenzelm@20819
   278
                 Rep_Node [THEN Node_Push_I, THEN Abs_Node_inverse])
wenzelm@20819
   279
apply (rule Least_equality)
wenzelm@20819
   280
apply (auto simp add: Push_def ndepth_Push_Node_aux)
wenzelm@20819
   281
apply (erule LeastI)
wenzelm@20819
   282
done
wenzelm@20819
   283
wenzelm@20819
   284
wenzelm@20819
   285
(*** ntrunc applied to the various node sets ***)
wenzelm@20819
   286
wenzelm@20819
   287
lemma ntrunc_0 [simp]: "ntrunc 0 M = {}"
wenzelm@20819
   288
by (simp add: ntrunc_def)
wenzelm@20819
   289
wenzelm@20819
   290
lemma ntrunc_Atom [simp]: "ntrunc (Suc k) (Atom a) = Atom(a)"
wenzelm@20819
   291
by (auto simp add: Atom_def ntrunc_def ndepth_K0)
wenzelm@20819
   292
wenzelm@20819
   293
lemma ntrunc_Leaf [simp]: "ntrunc (Suc k) (Leaf a) = Leaf(a)"
wenzelm@20819
   294
by (simp add: Leaf_def o_def ntrunc_Atom)
wenzelm@20819
   295
wenzelm@20819
   296
lemma ntrunc_Numb [simp]: "ntrunc (Suc k) (Numb i) = Numb(i)"
wenzelm@20819
   297
by (simp add: Numb_def o_def ntrunc_Atom)
wenzelm@20819
   298
wenzelm@20819
   299
lemma ntrunc_Scons [simp]: 
wenzelm@20819
   300
    "ntrunc (Suc k) (Scons M N) = Scons (ntrunc k M) (ntrunc k N)"
wenzelm@20819
   301
by (auto simp add: Scons_def ntrunc_def One_nat_def ndepth_Push_Node) 
wenzelm@20819
   302
wenzelm@20819
   303
wenzelm@20819
   304
wenzelm@20819
   305
(** Injection nodes **)
wenzelm@20819
   306
wenzelm@20819
   307
lemma ntrunc_one_In0 [simp]: "ntrunc (Suc 0) (In0 M) = {}"
wenzelm@20819
   308
apply (simp add: In0_def)
wenzelm@20819
   309
apply (simp add: Scons_def)
wenzelm@20819
   310
done
wenzelm@20819
   311
wenzelm@20819
   312
lemma ntrunc_In0 [simp]: "ntrunc (Suc(Suc k)) (In0 M) = In0 (ntrunc (Suc k) M)"
wenzelm@20819
   313
by (simp add: In0_def)
wenzelm@20819
   314
wenzelm@20819
   315
lemma ntrunc_one_In1 [simp]: "ntrunc (Suc 0) (In1 M) = {}"
wenzelm@20819
   316
apply (simp add: In1_def)
wenzelm@20819
   317
apply (simp add: Scons_def)
wenzelm@20819
   318
done
wenzelm@20819
   319
wenzelm@20819
   320
lemma ntrunc_In1 [simp]: "ntrunc (Suc(Suc k)) (In1 M) = In1 (ntrunc (Suc k) M)"
wenzelm@20819
   321
by (simp add: In1_def)
wenzelm@20819
   322
wenzelm@20819
   323
wenzelm@20819
   324
subsection{*Set Constructions*}
wenzelm@20819
   325
wenzelm@20819
   326
wenzelm@20819
   327
(*** Cartesian Product ***)
wenzelm@20819
   328
wenzelm@20819
   329
lemma uprodI [intro!]: "[| M:A;  N:B |] ==> Scons M N : uprod A B"
wenzelm@20819
   330
by (simp add: uprod_def)
wenzelm@20819
   331
wenzelm@20819
   332
(*The general elimination rule*)
wenzelm@20819
   333
lemma uprodE [elim!]:
wenzelm@20819
   334
    "[| c : uprod A B;   
wenzelm@20819
   335
        !!x y. [| x:A;  y:B;  c = Scons x y |] ==> P  
wenzelm@20819
   336
     |] ==> P"
wenzelm@20819
   337
by (auto simp add: uprod_def) 
wenzelm@20819
   338
wenzelm@20819
   339
wenzelm@20819
   340
(*Elimination of a pair -- introduces no eigenvariables*)
wenzelm@20819
   341
lemma uprodE2: "[| Scons M N : uprod A B;  [| M:A;  N:B |] ==> P |] ==> P"
wenzelm@20819
   342
by (auto simp add: uprod_def)
wenzelm@20819
   343
wenzelm@20819
   344
wenzelm@20819
   345
(*** Disjoint Sum ***)
wenzelm@20819
   346
wenzelm@20819
   347
lemma usum_In0I [intro]: "M:A ==> In0(M) : usum A B"
wenzelm@20819
   348
by (simp add: usum_def)
wenzelm@20819
   349
wenzelm@20819
   350
lemma usum_In1I [intro]: "N:B ==> In1(N) : usum A B"
wenzelm@20819
   351
by (simp add: usum_def)
wenzelm@20819
   352
wenzelm@20819
   353
lemma usumE [elim!]: 
wenzelm@20819
   354
    "[| u : usum A B;   
wenzelm@20819
   355
        !!x. [| x:A;  u=In0(x) |] ==> P;  
wenzelm@20819
   356
        !!y. [| y:B;  u=In1(y) |] ==> P  
wenzelm@20819
   357
     |] ==> P"
wenzelm@20819
   358
by (auto simp add: usum_def)
wenzelm@20819
   359
wenzelm@20819
   360
wenzelm@20819
   361
(** Injection **)
wenzelm@20819
   362
wenzelm@20819
   363
lemma In0_not_In1 [iff]: "In0(M) \<noteq> In1(N)"
wenzelm@20819
   364
by (auto simp add: In0_def In1_def One_nat_def)
wenzelm@20819
   365
wenzelm@20819
   366
lemmas In1_not_In0 = In0_not_In1 [THEN not_sym, standard]
wenzelm@20819
   367
declare In1_not_In0 [iff]
wenzelm@20819
   368
wenzelm@20819
   369
lemma In0_inject: "In0(M) = In0(N) ==>  M=N"
wenzelm@20819
   370
by (simp add: In0_def)
wenzelm@20819
   371
wenzelm@20819
   372
lemma In1_inject: "In1(M) = In1(N) ==>  M=N"
wenzelm@20819
   373
by (simp add: In1_def)
wenzelm@20819
   374
wenzelm@20819
   375
lemma In0_eq [iff]: "(In0 M = In0 N) = (M=N)"
wenzelm@20819
   376
by (blast dest!: In0_inject)
wenzelm@20819
   377
wenzelm@20819
   378
lemma In1_eq [iff]: "(In1 M = In1 N) = (M=N)"
wenzelm@20819
   379
by (blast dest!: In1_inject)
wenzelm@20819
   380
wenzelm@20819
   381
lemma inj_In0: "inj In0"
wenzelm@20819
   382
by (blast intro!: inj_onI)
wenzelm@20819
   383
wenzelm@20819
   384
lemma inj_In1: "inj In1"
wenzelm@20819
   385
by (blast intro!: inj_onI)
wenzelm@20819
   386
wenzelm@20819
   387
wenzelm@20819
   388
(*** Function spaces ***)
wenzelm@20819
   389
wenzelm@20819
   390
lemma Lim_inject: "Lim f = Lim g ==> f = g"
wenzelm@20819
   391
apply (simp add: Lim_def)
wenzelm@20819
   392
apply (rule ext)
wenzelm@20819
   393
apply (blast elim!: Push_Node_inject)
wenzelm@20819
   394
done
wenzelm@20819
   395
wenzelm@20819
   396
wenzelm@20819
   397
(*** proving equality of sets and functions using ntrunc ***)
wenzelm@20819
   398
wenzelm@20819
   399
lemma ntrunc_subsetI: "ntrunc k M <= M"
wenzelm@20819
   400
by (auto simp add: ntrunc_def)
wenzelm@20819
   401
wenzelm@20819
   402
lemma ntrunc_subsetD: "(!!k. ntrunc k M <= N) ==> M<=N"
wenzelm@20819
   403
by (auto simp add: ntrunc_def)
wenzelm@20819
   404
wenzelm@20819
   405
(*A generalized form of the take-lemma*)
wenzelm@20819
   406
lemma ntrunc_equality: "(!!k. ntrunc k M = ntrunc k N) ==> M=N"
wenzelm@20819
   407
apply (rule equalityI)
wenzelm@20819
   408
apply (rule_tac [!] ntrunc_subsetD)
wenzelm@20819
   409
apply (rule_tac [!] ntrunc_subsetI [THEN [2] subset_trans], auto) 
wenzelm@20819
   410
done
wenzelm@20819
   411
wenzelm@20819
   412
lemma ntrunc_o_equality: 
wenzelm@20819
   413
    "[| !!k. (ntrunc(k) o h1) = (ntrunc(k) o h2) |] ==> h1=h2"
wenzelm@20819
   414
apply (rule ntrunc_equality [THEN ext])
wenzelm@20819
   415
apply (simp add: expand_fun_eq) 
wenzelm@20819
   416
done
wenzelm@20819
   417
wenzelm@20819
   418
wenzelm@20819
   419
(*** Monotonicity ***)
wenzelm@20819
   420
wenzelm@20819
   421
lemma uprod_mono: "[| A<=A';  B<=B' |] ==> uprod A B <= uprod A' B'"
wenzelm@20819
   422
by (simp add: uprod_def, blast)
wenzelm@20819
   423
wenzelm@20819
   424
lemma usum_mono: "[| A<=A';  B<=B' |] ==> usum A B <= usum A' B'"
wenzelm@20819
   425
by (simp add: usum_def, blast)
wenzelm@20819
   426
wenzelm@20819
   427
lemma Scons_mono: "[| M<=M';  N<=N' |] ==> Scons M N <= Scons M' N'"
wenzelm@20819
   428
by (simp add: Scons_def, blast)
wenzelm@20819
   429
wenzelm@20819
   430
lemma In0_mono: "M<=N ==> In0(M) <= In0(N)"
wenzelm@20819
   431
by (simp add: In0_def subset_refl Scons_mono)
wenzelm@20819
   432
wenzelm@20819
   433
lemma In1_mono: "M<=N ==> In1(M) <= In1(N)"
wenzelm@20819
   434
by (simp add: In1_def subset_refl Scons_mono)
wenzelm@20819
   435
wenzelm@20819
   436
wenzelm@20819
   437
(*** Split and Case ***)
wenzelm@20819
   438
wenzelm@20819
   439
lemma Split [simp]: "Split c (Scons M N) = c M N"
wenzelm@20819
   440
by (simp add: Split_def)
wenzelm@20819
   441
wenzelm@20819
   442
lemma Case_In0 [simp]: "Case c d (In0 M) = c(M)"
wenzelm@20819
   443
by (simp add: Case_def)
wenzelm@20819
   444
wenzelm@20819
   445
lemma Case_In1 [simp]: "Case c d (In1 N) = d(N)"
wenzelm@20819
   446
by (simp add: Case_def)
wenzelm@20819
   447
wenzelm@20819
   448
wenzelm@20819
   449
wenzelm@20819
   450
(**** UN x. B(x) rules ****)
wenzelm@20819
   451
wenzelm@20819
   452
lemma ntrunc_UN1: "ntrunc k (UN x. f(x)) = (UN x. ntrunc k (f x))"
wenzelm@20819
   453
by (simp add: ntrunc_def, blast)
wenzelm@20819
   454
wenzelm@20819
   455
lemma Scons_UN1_x: "Scons (UN x. f x) M = (UN x. Scons (f x) M)"
wenzelm@20819
   456
by (simp add: Scons_def, blast)
wenzelm@20819
   457
wenzelm@20819
   458
lemma Scons_UN1_y: "Scons M (UN x. f x) = (UN x. Scons M (f x))"
wenzelm@20819
   459
by (simp add: Scons_def, blast)
wenzelm@20819
   460
wenzelm@20819
   461
lemma In0_UN1: "In0(UN x. f(x)) = (UN x. In0(f(x)))"
wenzelm@20819
   462
by (simp add: In0_def Scons_UN1_y)
wenzelm@20819
   463
wenzelm@20819
   464
lemma In1_UN1: "In1(UN x. f(x)) = (UN x. In1(f(x)))"
wenzelm@20819
   465
by (simp add: In1_def Scons_UN1_y)
wenzelm@20819
   466
wenzelm@20819
   467
wenzelm@20819
   468
(*** Equality for Cartesian Product ***)
wenzelm@20819
   469
wenzelm@20819
   470
lemma dprodI [intro!]: 
wenzelm@20819
   471
    "[| (M,M'):r;  (N,N'):s |] ==> (Scons M N, Scons M' N') : dprod r s"
wenzelm@20819
   472
by (auto simp add: dprod_def)
wenzelm@20819
   473
wenzelm@20819
   474
(*The general elimination rule*)
wenzelm@20819
   475
lemma dprodE [elim!]: 
wenzelm@20819
   476
    "[| c : dprod r s;   
wenzelm@20819
   477
        !!x y x' y'. [| (x,x') : r;  (y,y') : s;  
wenzelm@20819
   478
                        c = (Scons x y, Scons x' y') |] ==> P  
wenzelm@20819
   479
     |] ==> P"
wenzelm@20819
   480
by (auto simp add: dprod_def)
wenzelm@20819
   481
wenzelm@20819
   482
wenzelm@20819
   483
(*** Equality for Disjoint Sum ***)
wenzelm@20819
   484
wenzelm@20819
   485
lemma dsum_In0I [intro]: "(M,M'):r ==> (In0(M), In0(M')) : dsum r s"
wenzelm@20819
   486
by (auto simp add: dsum_def)
wenzelm@20819
   487
wenzelm@20819
   488
lemma dsum_In1I [intro]: "(N,N'):s ==> (In1(N), In1(N')) : dsum r s"
wenzelm@20819
   489
by (auto simp add: dsum_def)
wenzelm@20819
   490
wenzelm@20819
   491
lemma dsumE [elim!]: 
wenzelm@20819
   492
    "[| w : dsum r s;   
wenzelm@20819
   493
        !!x x'. [| (x,x') : r;  w = (In0(x), In0(x')) |] ==> P;  
wenzelm@20819
   494
        !!y y'. [| (y,y') : s;  w = (In1(y), In1(y')) |] ==> P  
wenzelm@20819
   495
     |] ==> P"
wenzelm@20819
   496
by (auto simp add: dsum_def)
wenzelm@20819
   497
wenzelm@20819
   498
wenzelm@20819
   499
(*** Monotonicity ***)
wenzelm@20819
   500
wenzelm@20819
   501
lemma dprod_mono: "[| r<=r';  s<=s' |] ==> dprod r s <= dprod r' s'"
wenzelm@20819
   502
by blast
wenzelm@20819
   503
wenzelm@20819
   504
lemma dsum_mono: "[| r<=r';  s<=s' |] ==> dsum r s <= dsum r' s'"
wenzelm@20819
   505
by blast
wenzelm@20819
   506
wenzelm@20819
   507
wenzelm@20819
   508
(*** Bounding theorems ***)
wenzelm@20819
   509
wenzelm@20819
   510
lemma dprod_Sigma: "(dprod (A <*> B) (C <*> D)) <= (uprod A C) <*> (uprod B D)"
wenzelm@20819
   511
by blast
wenzelm@20819
   512
wenzelm@20819
   513
lemmas dprod_subset_Sigma = subset_trans [OF dprod_mono dprod_Sigma, standard]
wenzelm@20819
   514
wenzelm@20819
   515
(*Dependent version*)
wenzelm@20819
   516
lemma dprod_subset_Sigma2:
wenzelm@20819
   517
     "(dprod (Sigma A B) (Sigma C D)) <= 
wenzelm@20819
   518
      Sigma (uprod A C) (Split (%x y. uprod (B x) (D y)))"
wenzelm@20819
   519
by auto
wenzelm@20819
   520
wenzelm@20819
   521
lemma dsum_Sigma: "(dsum (A <*> B) (C <*> D)) <= (usum A C) <*> (usum B D)"
wenzelm@20819
   522
by blast
wenzelm@20819
   523
wenzelm@20819
   524
lemmas dsum_subset_Sigma = subset_trans [OF dsum_mono dsum_Sigma, standard]
wenzelm@20819
   525
wenzelm@20819
   526
wenzelm@20819
   527
(*** Domain ***)
wenzelm@20819
   528
wenzelm@20819
   529
lemma Domain_dprod [simp]: "Domain (dprod r s) = uprod (Domain r) (Domain s)"
wenzelm@20819
   530
by auto
wenzelm@20819
   531
wenzelm@20819
   532
lemma Domain_dsum [simp]: "Domain (dsum r s) = usum (Domain r) (Domain s)"
wenzelm@20819
   533
by auto
wenzelm@20819
   534
wenzelm@20819
   535
wenzelm@20819
   536
subsection {* Finishing the datatype package setup *}
wenzelm@20819
   537
wenzelm@20819
   538
text {* Belongs to theory @{text Datatype_Universe}; hides popular names. *}
haftmann@20847
   539
setup "DatatypeCodegen.setup_hooks"
wenzelm@20819
   540
hide (open) const Push Node Atom Leaf Numb Lim Split Case
wenzelm@20819
   541
hide (open) type node item
wenzelm@20819
   542
wenzelm@20819
   543
wenzelm@20819
   544
section {* Datatypes *}
wenzelm@20819
   545
wenzelm@11954
   546
subsection {* Representing primitive types *}
berghofe@5181
   547
berghofe@5759
   548
rep_datatype bool
wenzelm@11954
   549
  distinct True_not_False False_not_True
wenzelm@11954
   550
  induction bool_induct
wenzelm@11954
   551
wenzelm@11954
   552
declare case_split [cases type: bool]
wenzelm@11954
   553
  -- "prefer plain propositional version"
wenzelm@11954
   554
wenzelm@11954
   555
rep_datatype unit
wenzelm@11954
   556
  induction unit_induct
berghofe@5181
   557
berghofe@5181
   558
rep_datatype prod
wenzelm@11954
   559
  inject Pair_eq
wenzelm@11954
   560
  induction prod_induct
wenzelm@11954
   561
wenzelm@12918
   562
rep_datatype sum
wenzelm@12918
   563
  distinct Inl_not_Inr Inr_not_Inl
wenzelm@12918
   564
  inject Inl_eq Inr_eq
wenzelm@12918
   565
  induction sum_induct
wenzelm@12918
   566
wenzelm@12918
   567
lemma surjective_sum: "sum_case (%x::'a. f (Inl x)) (%y::'b. f (Inr y)) s = f(s)"
wenzelm@12918
   568
  apply (rule_tac s = s in sumE)
wenzelm@12918
   569
   apply (erule ssubst)
wenzelm@20798
   570
   apply (rule sum.cases(1))
wenzelm@12918
   571
  apply (erule ssubst)
wenzelm@20798
   572
  apply (rule sum.cases(2))
wenzelm@12918
   573
  done
wenzelm@12918
   574
wenzelm@12918
   575
lemma sum_case_weak_cong: "s = t ==> sum_case f g s = sum_case f g t"
wenzelm@12918
   576
  -- {* Prevents simplification of @{text f} and @{text g}: much faster. *}
wenzelm@20798
   577
  by simp
wenzelm@12918
   578
wenzelm@12918
   579
lemma sum_case_inject:
wenzelm@12918
   580
  "sum_case f1 f2 = sum_case g1 g2 ==> (f1 = g1 ==> f2 = g2 ==> P) ==> P"
wenzelm@12918
   581
proof -
wenzelm@12918
   582
  assume a: "sum_case f1 f2 = sum_case g1 g2"
wenzelm@12918
   583
  assume r: "f1 = g1 ==> f2 = g2 ==> P"
wenzelm@12918
   584
  show P
wenzelm@12918
   585
    apply (rule r)
wenzelm@12918
   586
     apply (rule ext)
paulson@14208
   587
     apply (cut_tac x = "Inl x" in a [THEN fun_cong], simp)
wenzelm@12918
   588
    apply (rule ext)
paulson@14208
   589
    apply (cut_tac x = "Inr x" in a [THEN fun_cong], simp)
wenzelm@12918
   590
    done
wenzelm@12918
   591
qed
wenzelm@12918
   592
berghofe@13635
   593
constdefs
berghofe@13635
   594
  Suml :: "('a => 'c) => 'a + 'b => 'c"
berghofe@13635
   595
  "Suml == (%f. sum_case f arbitrary)"
berghofe@13635
   596
berghofe@13635
   597
  Sumr :: "('b => 'c) => 'a + 'b => 'c"
berghofe@13635
   598
  "Sumr == sum_case arbitrary"
berghofe@13635
   599
berghofe@13635
   600
lemma Suml_inject: "Suml f = Suml g ==> f = g"
berghofe@13635
   601
  by (unfold Suml_def) (erule sum_case_inject)
berghofe@13635
   602
berghofe@13635
   603
lemma Sumr_inject: "Sumr f = Sumr g ==> f = g"
berghofe@13635
   604
  by (unfold Sumr_def) (erule sum_case_inject)
berghofe@13635
   605
wenzelm@20798
   606
hide (open) const Suml Sumr
berghofe@13635
   607
wenzelm@12918
   608
wenzelm@12918
   609
subsection {* Further cases/induct rules for tuples *}
wenzelm@11954
   610
wenzelm@20798
   611
lemma prod_cases3 [cases type]:
wenzelm@20798
   612
  obtains (fields) a b c where "y = (a, b, c)"
wenzelm@20798
   613
  by (cases y, case_tac b) blast
wenzelm@11954
   614
wenzelm@11954
   615
lemma prod_induct3 [case_names fields, induct type]:
wenzelm@11954
   616
    "(!!a b c. P (a, b, c)) ==> P x"
wenzelm@11954
   617
  by (cases x) blast
wenzelm@11954
   618
wenzelm@20798
   619
lemma prod_cases4 [cases type]:
wenzelm@20798
   620
  obtains (fields) a b c d where "y = (a, b, c, d)"
wenzelm@20798
   621
  by (cases y, case_tac c) blast
wenzelm@11954
   622
wenzelm@11954
   623
lemma prod_induct4 [case_names fields, induct type]:
wenzelm@11954
   624
    "(!!a b c d. P (a, b, c, d)) ==> P x"
wenzelm@11954
   625
  by (cases x) blast
berghofe@5181
   626
wenzelm@20798
   627
lemma prod_cases5 [cases type]:
wenzelm@20798
   628
  obtains (fields) a b c d e where "y = (a, b, c, d, e)"
wenzelm@20798
   629
  by (cases y, case_tac d) blast
wenzelm@11954
   630
wenzelm@11954
   631
lemma prod_induct5 [case_names fields, induct type]:
wenzelm@11954
   632
    "(!!a b c d e. P (a, b, c, d, e)) ==> P x"
wenzelm@11954
   633
  by (cases x) blast
wenzelm@11954
   634
wenzelm@20798
   635
lemma prod_cases6 [cases type]:
wenzelm@20798
   636
  obtains (fields) a b c d e f where "y = (a, b, c, d, e, f)"
wenzelm@20798
   637
  by (cases y, case_tac e) blast
wenzelm@11954
   638
wenzelm@11954
   639
lemma prod_induct6 [case_names fields, induct type]:
wenzelm@11954
   640
    "(!!a b c d e f. P (a, b, c, d, e, f)) ==> P x"
wenzelm@11954
   641
  by (cases x) blast
wenzelm@11954
   642
wenzelm@20798
   643
lemma prod_cases7 [cases type]:
wenzelm@20798
   644
  obtains (fields) a b c d e f g where "y = (a, b, c, d, e, f, g)"
wenzelm@20798
   645
  by (cases y, case_tac f) blast
wenzelm@11954
   646
wenzelm@11954
   647
lemma prod_induct7 [case_names fields, induct type]:
wenzelm@11954
   648
    "(!!a b c d e f g. P (a, b, c, d, e, f, g)) ==> P x"
wenzelm@11954
   649
  by (cases x) blast
berghofe@5759
   650
wenzelm@12918
   651
wenzelm@12918
   652
subsection {* The option type *}
wenzelm@12918
   653
wenzelm@12918
   654
datatype 'a option = None | Some 'a
wenzelm@12918
   655
wenzelm@20798
   656
lemma not_None_eq [iff]: "(x ~= None) = (EX y. x = Some y)"
nipkow@18576
   657
  by (induct x) auto
nipkow@18576
   658
wenzelm@20798
   659
lemma not_Some_eq [iff]: "(ALL y. x ~= Some y) = (x = None)"
paulson@18447
   660
  by (induct x) auto
paulson@18447
   661
nipkow@18576
   662
text{*Although it may appear that both of these equalities are helpful
nipkow@18576
   663
only when applied to assumptions, in practice it seems better to give
nipkow@18576
   664
them the uniform iff attribute. *}
wenzelm@12918
   665
wenzelm@12918
   666
lemma option_caseE:
wenzelm@20798
   667
  assumes c: "(case x of None => P | Some y => Q y)"
wenzelm@20798
   668
  obtains
wenzelm@20798
   669
    (None) "x = None" and P
wenzelm@20798
   670
  | (Some) y where "x = Some y" and "Q y"
wenzelm@20798
   671
  using c by (cases x) simp_all
wenzelm@12918
   672
wenzelm@12918
   673
wenzelm@12918
   674
subsubsection {* Operations *}
wenzelm@12918
   675
wenzelm@12918
   676
consts
wenzelm@12918
   677
  the :: "'a option => 'a"
wenzelm@12918
   678
primrec
wenzelm@12918
   679
  "the (Some x) = x"
wenzelm@12918
   680
wenzelm@12918
   681
consts
wenzelm@12918
   682
  o2s :: "'a option => 'a set"
wenzelm@12918
   683
primrec
wenzelm@12918
   684
  "o2s None = {}"
wenzelm@12918
   685
  "o2s (Some x) = {x}"
wenzelm@12918
   686
wenzelm@12918
   687
lemma ospec [dest]: "(ALL x:o2s A. P x) ==> A = Some x ==> P x"
wenzelm@12918
   688
  by simp
wenzelm@12918
   689
wenzelm@17876
   690
ML_setup {* change_claset (fn cs => cs addSD2 ("ospec", thm "ospec")) *}
wenzelm@12918
   691
wenzelm@12918
   692
lemma elem_o2s [iff]: "(x : o2s xo) = (xo = Some x)"
wenzelm@12918
   693
  by (cases xo) auto
wenzelm@12918
   694
wenzelm@12918
   695
lemma o2s_empty_eq [simp]: "(o2s xo = {}) = (xo = None)"
wenzelm@12918
   696
  by (cases xo) auto
wenzelm@12918
   697
wenzelm@12918
   698
wenzelm@12918
   699
constdefs
wenzelm@12918
   700
  option_map :: "('a => 'b) => ('a option => 'b option)"
wenzelm@12918
   701
  "option_map == %f y. case y of None => None | Some x => Some (f x)"
wenzelm@12918
   702
wenzelm@12918
   703
lemma option_map_None [simp]: "option_map f None = None"
wenzelm@12918
   704
  by (simp add: option_map_def)
wenzelm@12918
   705
wenzelm@12918
   706
lemma option_map_Some [simp]: "option_map f (Some x) = Some (f x)"
wenzelm@12918
   707
  by (simp add: option_map_def)
wenzelm@12918
   708
wenzelm@20798
   709
lemma option_map_is_None [iff]:
wenzelm@20798
   710
    "(option_map f opt = None) = (opt = None)"
wenzelm@20798
   711
  by (simp add: option_map_def split add: option.split)
nipkow@14187
   712
wenzelm@12918
   713
lemma option_map_eq_Some [iff]:
wenzelm@12918
   714
    "(option_map f xo = Some y) = (EX z. xo = Some z & f z = y)"
wenzelm@20798
   715
  by (simp add: option_map_def split add: option.split)
nipkow@14187
   716
nipkow@14187
   717
lemma option_map_comp:
wenzelm@20798
   718
    "option_map f (option_map g opt) = option_map (f o g) opt"
wenzelm@20798
   719
  by (simp add: option_map_def split add: option.split)
wenzelm@12918
   720
wenzelm@12918
   721
lemma option_map_o_sum_case [simp]:
wenzelm@12918
   722
    "option_map f o sum_case g h = sum_case (option_map f o g) (option_map f o h)"
wenzelm@20798
   723
  by (rule ext) (simp split: sum.split)
wenzelm@12918
   724
haftmann@19787
   725
haftmann@19817
   726
subsubsection {* Codegenerator setup *}
haftmann@19817
   727
haftmann@19787
   728
consts
haftmann@19787
   729
  is_none :: "'a option \<Rightarrow> bool"
haftmann@19787
   730
primrec
haftmann@19787
   731
  "is_none None = True"
haftmann@19787
   732
  "is_none (Some x) = False"
haftmann@19787
   733
haftmann@20105
   734
lemma is_none_none [code inline]:
wenzelm@20798
   735
    "(x = None) = (is_none x)" 
wenzelm@20798
   736
  by (cases x) simp_all
haftmann@19787
   737
wenzelm@17458
   738
lemmas [code] = imp_conv_disj
wenzelm@17458
   739
krauss@20523
   740
lemma [code func]:
haftmann@19138
   741
  "(\<not> True) = False" by (rule HOL.simp_thms)
haftmann@19138
   742
krauss@20523
   743
lemma [code func]:
haftmann@19138
   744
  "(\<not> False) = True" by (rule HOL.simp_thms)
haftmann@19138
   745
krauss@20523
   746
lemma [code func]:
nipkow@19179
   747
  shows "(False \<and> x) = False"
wenzelm@20798
   748
    and "(True \<and> x) = x"
wenzelm@20798
   749
    and "(x \<and> False) = False"
wenzelm@20798
   750
    and "(x \<and> True) = x" by simp_all
haftmann@19138
   751
krauss@20523
   752
lemma [code func]:
nipkow@19179
   753
  shows "(False \<or> x) = x"
wenzelm@20798
   754
    and "(True \<or> x) = True"
wenzelm@20798
   755
    and "(x \<or> False) = x"
wenzelm@20798
   756
    and "(x \<or> True) = True" by simp_all
haftmann@19138
   757
haftmann@19138
   758
declare
krauss@20523
   759
  if_True [code func]
krauss@20523
   760
  if_False [code func]
nipkow@19179
   761
  fst_conv [code]
nipkow@19179
   762
  snd_conv [code]
haftmann@19138
   763
haftmann@20105
   764
lemma split_is_prod_case [code inline]:
wenzelm@20798
   765
    "split = prod_case"
wenzelm@20798
   766
  by (simp add: expand_fun_eq split_def prod.cases)
haftmann@20105
   767
haftmann@20453
   768
code_type bool
haftmann@20453
   769
  (SML target_atom "bool")
haftmann@20453
   770
  (Haskell target_atom "Bool")
haftmann@19138
   771
haftmann@20453
   772
code_const True and False and Not and "op &" and "op |" and If
haftmann@20453
   773
  (SML target_atom "true" and target_atom "false" and target_atom "not"
haftmann@20453
   774
    and infixl 1 "andalso" and infixl 0 "orelse"
haftmann@20453
   775
    and target_atom "(if __/ then __/ else __)")
haftmann@20453
   776
  (Haskell target_atom "True" and target_atom "False" and target_atom "not"
haftmann@20453
   777
    and infixl 3 "&&" and infixl 2 "||"
haftmann@20453
   778
    and target_atom "(if __/ then __/ else __)")
haftmann@20453
   779
haftmann@20453
   780
code_type *
haftmann@20453
   781
  (SML infix 2 "*")
haftmann@20453
   782
  (Haskell target_atom "(__,/ __)")
haftmann@19138
   783
haftmann@20453
   784
code_const Pair
haftmann@20453
   785
  (SML target_atom "(__,/ __)")
haftmann@20453
   786
  (Haskell target_atom "(__,/ __)")
haftmann@18702
   787
haftmann@20453
   788
code_type unit
haftmann@20453
   789
  (SML target_atom "unit")
haftmann@20453
   790
  (Haskell target_atom "()")
haftmann@19150
   791
haftmann@20453
   792
code_const Unity
haftmann@20453
   793
  (SML target_atom "()")
haftmann@20453
   794
  (Haskell target_atom "()")
haftmann@19150
   795
haftmann@20453
   796
code_type option
haftmann@20453
   797
  (SML "_ option")
haftmann@20453
   798
  (Haskell "Maybe _")
haftmann@19150
   799
haftmann@20453
   800
code_const None and Some
haftmann@20453
   801
  (SML target_atom "NONE" and target_atom "SOME")
haftmann@20453
   802
  (Haskell target_atom "Nothing" and target_atom "Just")
haftmann@19150
   803
haftmann@20588
   804
code_instance option :: eq
haftmann@20588
   805
  (Haskell -)
haftmann@20588
   806
haftmann@21046
   807
code_const "Code_Generator.eq \<Colon> 'a\<Colon>eq option \<Rightarrow> 'a option \<Rightarrow> bool"
haftmann@20588
   808
  (Haskell infixl 4 "==")
haftmann@20588
   809
wenzelm@20819
   810
ML
wenzelm@20819
   811
{*
wenzelm@20819
   812
val apfst_conv = thm "apfst_conv";
wenzelm@20819
   813
val apfst_convE = thm "apfst_convE";
wenzelm@20819
   814
val Push_inject1 = thm "Push_inject1";
wenzelm@20819
   815
val Push_inject2 = thm "Push_inject2";
wenzelm@20819
   816
val Push_inject = thm "Push_inject";
wenzelm@20819
   817
val Push_neq_K0 = thm "Push_neq_K0";
wenzelm@20819
   818
val Abs_Node_inj = thm "Abs_Node_inj";
wenzelm@20819
   819
val Node_K0_I = thm "Node_K0_I";
wenzelm@20819
   820
val Node_Push_I = thm "Node_Push_I";
wenzelm@20819
   821
val Scons_not_Atom = thm "Scons_not_Atom";
wenzelm@20819
   822
val Atom_not_Scons = thm "Atom_not_Scons";
wenzelm@20819
   823
val inj_Atom = thm "inj_Atom";
wenzelm@20819
   824
val Atom_inject = thm "Atom_inject";
wenzelm@20819
   825
val Atom_Atom_eq = thm "Atom_Atom_eq";
wenzelm@20819
   826
val inj_Leaf = thm "inj_Leaf";
wenzelm@20819
   827
val Leaf_inject = thm "Leaf_inject";
wenzelm@20819
   828
val inj_Numb = thm "inj_Numb";
wenzelm@20819
   829
val Numb_inject = thm "Numb_inject";
wenzelm@20819
   830
val Push_Node_inject = thm "Push_Node_inject";
wenzelm@20819
   831
val Scons_inject1 = thm "Scons_inject1";
wenzelm@20819
   832
val Scons_inject2 = thm "Scons_inject2";
wenzelm@20819
   833
val Scons_inject = thm "Scons_inject";
wenzelm@20819
   834
val Scons_Scons_eq = thm "Scons_Scons_eq";
wenzelm@20819
   835
val Scons_not_Leaf = thm "Scons_not_Leaf";
wenzelm@20819
   836
val Leaf_not_Scons = thm "Leaf_not_Scons";
wenzelm@20819
   837
val Scons_not_Numb = thm "Scons_not_Numb";
wenzelm@20819
   838
val Numb_not_Scons = thm "Numb_not_Scons";
wenzelm@20819
   839
val Leaf_not_Numb = thm "Leaf_not_Numb";
wenzelm@20819
   840
val Numb_not_Leaf = thm "Numb_not_Leaf";
wenzelm@20819
   841
val ndepth_K0 = thm "ndepth_K0";
wenzelm@20819
   842
val ndepth_Push_Node_aux = thm "ndepth_Push_Node_aux";
wenzelm@20819
   843
val ndepth_Push_Node = thm "ndepth_Push_Node";
wenzelm@20819
   844
val ntrunc_0 = thm "ntrunc_0";
wenzelm@20819
   845
val ntrunc_Atom = thm "ntrunc_Atom";
wenzelm@20819
   846
val ntrunc_Leaf = thm "ntrunc_Leaf";
wenzelm@20819
   847
val ntrunc_Numb = thm "ntrunc_Numb";
wenzelm@20819
   848
val ntrunc_Scons = thm "ntrunc_Scons";
wenzelm@20819
   849
val ntrunc_one_In0 = thm "ntrunc_one_In0";
wenzelm@20819
   850
val ntrunc_In0 = thm "ntrunc_In0";
wenzelm@20819
   851
val ntrunc_one_In1 = thm "ntrunc_one_In1";
wenzelm@20819
   852
val ntrunc_In1 = thm "ntrunc_In1";
wenzelm@20819
   853
val uprodI = thm "uprodI";
wenzelm@20819
   854
val uprodE = thm "uprodE";
wenzelm@20819
   855
val uprodE2 = thm "uprodE2";
wenzelm@20819
   856
val usum_In0I = thm "usum_In0I";
wenzelm@20819
   857
val usum_In1I = thm "usum_In1I";
wenzelm@20819
   858
val usumE = thm "usumE";
wenzelm@20819
   859
val In0_not_In1 = thm "In0_not_In1";
wenzelm@20819
   860
val In1_not_In0 = thm "In1_not_In0";
wenzelm@20819
   861
val In0_inject = thm "In0_inject";
wenzelm@20819
   862
val In1_inject = thm "In1_inject";
wenzelm@20819
   863
val In0_eq = thm "In0_eq";
wenzelm@20819
   864
val In1_eq = thm "In1_eq";
wenzelm@20819
   865
val inj_In0 = thm "inj_In0";
wenzelm@20819
   866
val inj_In1 = thm "inj_In1";
wenzelm@20819
   867
val Lim_inject = thm "Lim_inject";
wenzelm@20819
   868
val ntrunc_subsetI = thm "ntrunc_subsetI";
wenzelm@20819
   869
val ntrunc_subsetD = thm "ntrunc_subsetD";
wenzelm@20819
   870
val ntrunc_equality = thm "ntrunc_equality";
wenzelm@20819
   871
val ntrunc_o_equality = thm "ntrunc_o_equality";
wenzelm@20819
   872
val uprod_mono = thm "uprod_mono";
wenzelm@20819
   873
val usum_mono = thm "usum_mono";
wenzelm@20819
   874
val Scons_mono = thm "Scons_mono";
wenzelm@20819
   875
val In0_mono = thm "In0_mono";
wenzelm@20819
   876
val In1_mono = thm "In1_mono";
wenzelm@20819
   877
val Split = thm "Split";
wenzelm@20819
   878
val Case_In0 = thm "Case_In0";
wenzelm@20819
   879
val Case_In1 = thm "Case_In1";
wenzelm@20819
   880
val ntrunc_UN1 = thm "ntrunc_UN1";
wenzelm@20819
   881
val Scons_UN1_x = thm "Scons_UN1_x";
wenzelm@20819
   882
val Scons_UN1_y = thm "Scons_UN1_y";
wenzelm@20819
   883
val In0_UN1 = thm "In0_UN1";
wenzelm@20819
   884
val In1_UN1 = thm "In1_UN1";
wenzelm@20819
   885
val dprodI = thm "dprodI";
wenzelm@20819
   886
val dprodE = thm "dprodE";
wenzelm@20819
   887
val dsum_In0I = thm "dsum_In0I";
wenzelm@20819
   888
val dsum_In1I = thm "dsum_In1I";
wenzelm@20819
   889
val dsumE = thm "dsumE";
wenzelm@20819
   890
val dprod_mono = thm "dprod_mono";
wenzelm@20819
   891
val dsum_mono = thm "dsum_mono";
wenzelm@20819
   892
val dprod_Sigma = thm "dprod_Sigma";
wenzelm@20819
   893
val dprod_subset_Sigma = thm "dprod_subset_Sigma";
wenzelm@20819
   894
val dprod_subset_Sigma2 = thm "dprod_subset_Sigma2";
wenzelm@20819
   895
val dsum_Sigma = thm "dsum_Sigma";
wenzelm@20819
   896
val dsum_subset_Sigma = thm "dsum_subset_Sigma";
wenzelm@20819
   897
val Domain_dprod = thm "Domain_dprod";
wenzelm@20819
   898
val Domain_dsum = thm "Domain_dsum";
wenzelm@20819
   899
*}
wenzelm@20819
   900
berghofe@5181
   901
end