src/HOL/simpdata.ML
author paulson
Thu Oct 10 10:46:14 1996 +0200 (1996-10-10)
changeset 2082 8659e3063a30
parent 2054 bf3891343aa5
child 2097 076a8d2f972b
permissions -rw-r--r--
Addition of de Morgan laws
clasohm@1465
     1
(*  Title:      HOL/simpdata.ML
clasohm@923
     2
    ID:         $Id$
clasohm@1465
     3
    Author:     Tobias Nipkow
clasohm@923
     4
    Copyright   1991  University of Cambridge
clasohm@923
     5
clasohm@923
     6
Instantiation of the generic simplifier
clasohm@923
     7
*)
clasohm@923
     8
paulson@1984
     9
section "Simplifier";
paulson@1984
    10
clasohm@923
    11
open Simplifier;
clasohm@923
    12
paulson@1922
    13
(*** Integration of simplifier with classical reasoner ***)
paulson@1922
    14
paulson@1922
    15
(*Add a simpset to a classical set!*)
paulson@1922
    16
infix 4 addss;
paulson@1922
    17
fun cs addss ss = cs addbefore asm_full_simp_tac ss 1;
paulson@1922
    18
paulson@1922
    19
fun Addss ss = (claset := !claset addbefore asm_full_simp_tac ss 1);
paulson@1922
    20
paulson@1968
    21
(*Designed to be idempotent, except if best_tac instantiates variables
paulson@1968
    22
  in some of the subgoals*)
paulson@1922
    23
fun auto_tac (cs,ss) = 
paulson@1922
    24
    ALLGOALS (asm_full_simp_tac ss) THEN
paulson@1968
    25
    REPEAT (safe_tac cs THEN ALLGOALS (asm_full_simp_tac ss)) THEN
paulson@2036
    26
    REPEAT (FIRSTGOAL (best_tac (cs addss ss))) THEN
paulson@2036
    27
    prune_params_tac;
paulson@1922
    28
paulson@1922
    29
fun Auto_tac() = auto_tac (!claset, !simpset);
paulson@1922
    30
paulson@1922
    31
fun auto() = by (Auto_tac());
paulson@1922
    32
paulson@1922
    33
paulson@1984
    34
(*** Addition of rules to simpsets and clasets simultaneously ***)
paulson@1984
    35
paulson@1984
    36
(*Takes UNCONDITIONAL theorems of the form A<->B to 
paulson@2031
    37
        the Safe Intr     rule B==>A and 
paulson@2031
    38
        the Safe Destruct rule A==>B.
paulson@1984
    39
  Also ~A goes to the Safe Elim rule A ==> ?R
paulson@1984
    40
  Failing other cases, A is added as a Safe Intr rule*)
paulson@1984
    41
local
paulson@1984
    42
  val iff_const = HOLogic.eq_const HOLogic.boolT;
paulson@1984
    43
paulson@1984
    44
  fun addIff th = 
paulson@1984
    45
      (case HOLogic.dest_Trueprop (#prop(rep_thm th)) of
paulson@2031
    46
                (Const("not",_) $ A) =>
paulson@2031
    47
                    AddSEs [zero_var_indexes (th RS notE)]
paulson@2031
    48
              | (con $ _ $ _) =>
paulson@2031
    49
                    if con=iff_const
paulson@2031
    50
                    then (AddSIs [zero_var_indexes (th RS iffD2)];  
paulson@2031
    51
                          AddSDs [zero_var_indexes (th RS iffD1)])
paulson@2031
    52
                    else  AddSIs [th]
paulson@2031
    53
              | _ => AddSIs [th];
paulson@1984
    54
       Addsimps [th])
paulson@1984
    55
      handle _ => error ("AddIffs: theorem must be unconditional\n" ^ 
paulson@2031
    56
                         string_of_thm th)
paulson@1984
    57
paulson@1984
    58
  fun delIff th = 
paulson@1984
    59
      (case HOLogic.dest_Trueprop (#prop(rep_thm th)) of
paulson@2031
    60
                (Const("not",_) $ A) =>
paulson@2031
    61
                    Delrules [zero_var_indexes (th RS notE)]
paulson@2031
    62
              | (con $ _ $ _) =>
paulson@2031
    63
                    if con=iff_const
paulson@2031
    64
                    then Delrules [zero_var_indexes (th RS iffD2),
paulson@2031
    65
                                   zero_var_indexes (th RS iffD1)]
paulson@2031
    66
                    else Delrules [th]
paulson@2031
    67
              | _ => Delrules [th];
paulson@1984
    68
       Delsimps [th])
paulson@1984
    69
      handle _ => warning("DelIffs: ignoring conditional theorem\n" ^ 
paulson@2031
    70
                          string_of_thm th)
paulson@1984
    71
in
paulson@1984
    72
val AddIffs = seq addIff
paulson@1984
    73
val DelIffs = seq delIff
paulson@1984
    74
end;
paulson@1984
    75
paulson@1984
    76
clasohm@923
    77
local
clasohm@923
    78
paulson@1922
    79
  fun prover s = prove_goal HOL.thy s (fn _ => [fast_tac HOL_cs 1]);
clasohm@923
    80
paulson@1922
    81
  val P_imp_P_iff_True = prover "P --> (P = True)" RS mp;
paulson@1922
    82
  val P_imp_P_eq_True = P_imp_P_iff_True RS eq_reflection;
clasohm@923
    83
paulson@1922
    84
  val not_P_imp_P_iff_F = prover "~P --> (P = False)" RS mp;
paulson@1922
    85
  val not_P_imp_P_eq_False = not_P_imp_P_iff_F RS eq_reflection;
clasohm@923
    86
paulson@1922
    87
  fun atomize pairs =
paulson@1922
    88
    let fun atoms th =
paulson@2031
    89
          (case concl_of th of
paulson@2031
    90
             Const("Trueprop",_) $ p =>
paulson@2031
    91
               (case head_of p of
paulson@2031
    92
                  Const(a,_) =>
paulson@2031
    93
                    (case assoc(pairs,a) of
paulson@2031
    94
                       Some(rls) => flat (map atoms ([th] RL rls))
paulson@2031
    95
                     | None => [th])
paulson@2031
    96
                | _ => [th])
paulson@2031
    97
           | _ => [th])
paulson@1922
    98
    in atoms end;
clasohm@923
    99
paulson@1922
   100
  fun mk_meta_eq r = case concl_of r of
paulson@2031
   101
          Const("==",_)$_$_ => r
paulson@1922
   102
      |   _$(Const("op =",_)$_$_) => r RS eq_reflection
paulson@1922
   103
      |   _$(Const("not",_)$_) => r RS not_P_imp_P_eq_False
paulson@1922
   104
      |   _ => r RS P_imp_P_eq_True;
paulson@1922
   105
  (* last 2 lines requires all formulae to be of the from Trueprop(.) *)
clasohm@923
   106
paulson@1922
   107
  fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th;
clasohm@923
   108
paulson@2082
   109
in
clasohm@923
   110
paulson@2082
   111
val simp_thms = map prover
paulson@2082
   112
 [ "(x=x) = True",
paulson@2082
   113
   "(~True) = False", "(~False) = True", "(~ ~ P) = P",
paulson@2082
   114
   "(~P) ~= P", "P ~= (~P)", "(P ~= Q) = (P = (~Q))",
paulson@2082
   115
   "(True=P) = P", "(P=True) = P",
paulson@2082
   116
   "(True --> P) = P", "(False --> P) = True", 
paulson@2082
   117
   "(P --> True) = True", "(P --> P) = True",
paulson@2082
   118
   "(P --> False) = (~P)", "(P --> ~P) = (~P)",
paulson@2082
   119
   "(P & True) = P", "(True & P) = P", 
paulson@2082
   120
   "(P & False) = False", "(False & P) = False", "(P & P) = P",
paulson@2082
   121
   "(P | True) = True", "(True | P) = True", 
paulson@2082
   122
   "(P | False) = P", "(False | P) = P", "(P | P) = P",
paulson@2082
   123
   "((~P) = (~Q)) = (P=Q)",
paulson@2082
   124
   "(!x.P) = P", "(? x.P) = P", "? x. x=t", 
paulson@2082
   125
   "(? x. x=t & P(x)) = P(t)", "(? x. t=x & P(x)) = P(t)", 
paulson@2082
   126
   "(! x. x=t --> P(x)) = P(t)", "(! x. t=x --> P(x)) = P(t)" ];
clasohm@923
   127
clasohm@923
   128
val meta_eq_to_obj_eq = prove_goal HOL.thy "x==y ==> x=y"
clasohm@923
   129
  (fn [prem] => [rewtac prem, rtac refl 1]);
clasohm@923
   130
clasohm@923
   131
val eq_sym_conv = prover "(x=y) = (y=x)";
clasohm@923
   132
clasohm@923
   133
val conj_assoc = prover "((P&Q)&R) = (P&(Q&R))";
clasohm@923
   134
paulson@1922
   135
val disj_assoc = prover "((P|Q)|R) = (P|(Q|R))";
paulson@1922
   136
paulson@1922
   137
val imp_disj   = prover "(P|Q --> R) = ((P-->R)&(Q-->R))";
paulson@1922
   138
paulson@1948
   139
(*Avoids duplication of subgoals after expand_if, when the true and false 
paulson@1948
   140
  cases boil down to the same thing.*) 
paulson@1948
   141
val cases_simp = prover "((P --> Q) & (~P --> Q)) = Q";
paulson@1922
   142
clasohm@965
   143
val if_True = prove_goalw HOL.thy [if_def] "(if True then x else y) = x"
clasohm@923
   144
 (fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]);
clasohm@923
   145
clasohm@965
   146
val if_False = prove_goalw HOL.thy [if_def] "(if False then x else y) = y"
clasohm@923
   147
 (fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]);
clasohm@923
   148
clasohm@965
   149
val if_P = prove_goal HOL.thy "P ==> (if P then x else y) = x"
clasohm@923
   150
 (fn [prem] => [ stac (prem RS eqTrueI) 1, rtac if_True 1 ]);
clasohm@923
   151
clasohm@965
   152
val if_not_P = prove_goal HOL.thy "~P ==> (if P then x else y) = y"
clasohm@923
   153
 (fn [prem] => [ stac (prem RS not_P_imp_P_iff_F) 1, rtac if_False 1 ]);
clasohm@923
   154
clasohm@923
   155
val expand_if = prove_goal HOL.thy
clasohm@965
   156
    "P(if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
clasohm@923
   157
 (fn _=> [ (res_inst_tac [("Q","Q")] (excluded_middle RS disjE) 1),
paulson@2031
   158
         stac if_P 2,
paulson@2031
   159
         stac if_not_P 1,
clasohm@1465
   160
         REPEAT(fast_tac HOL_cs 1) ]);
clasohm@923
   161
clasohm@965
   162
val if_bool_eq = prove_goal HOL.thy
clasohm@965
   163
                   "(if P then Q else R) = ((P-->Q) & (~P-->R))"
clasohm@965
   164
                   (fn _ => [rtac expand_if 1]);
clasohm@923
   165
lcp@988
   166
(*Add congruence rules for = (instead of ==) *)
lcp@988
   167
infix 4 addcongs;
clasohm@923
   168
fun ss addcongs congs = ss addeqcongs (congs RL [eq_reflection]);
clasohm@923
   169
clasohm@1264
   170
fun Addcongs congs = (simpset := !simpset addcongs congs);
clasohm@1264
   171
clasohm@923
   172
val mksimps_pairs =
clasohm@923
   173
  [("op -->", [mp]), ("op &", [conjunct1,conjunct2]),
clasohm@923
   174
   ("All", [spec]), ("True", []), ("False", []),
clasohm@965
   175
   ("If", [if_bool_eq RS iffD1])];
clasohm@923
   176
clasohm@923
   177
fun mksimps pairs = map mk_meta_eq o atomize pairs o gen_all;
clasohm@923
   178
paulson@1922
   179
val imp_cong = impI RSN
paulson@1922
   180
    (2, prove_goal HOL.thy "(P=P')--> (P'--> (Q=Q'))--> ((P-->Q) = (P'-->Q'))"
paulson@1922
   181
        (fn _=> [fast_tac HOL_cs 1]) RS mp RS mp);
paulson@1922
   182
paulson@1922
   183
val o_apply = prove_goalw HOL.thy [o_def] "(f o g)(x) = f(g(x))"
paulson@1922
   184
 (fn _ => [rtac refl 1]);
paulson@1922
   185
paulson@1948
   186
(*Miniscoping: pushing in existential quantifiers*)
paulson@1948
   187
val ex_simps = map prover 
paulson@2031
   188
                ["(EX x. P x & Q)   = ((EX x.P x) & Q)",
paulson@2031
   189
                 "(EX x. P & Q x)   = (P & (EX x.Q x))",
paulson@2031
   190
                 "(EX x. P x | Q)   = ((EX x.P x) | Q)",
paulson@2031
   191
                 "(EX x. P | Q x)   = (P | (EX x.Q x))",
paulson@2031
   192
                 "(EX x. P x --> Q) = ((ALL x.P x) --> Q)",
paulson@2031
   193
                 "(EX x. P --> Q x) = (P --> (EX x.Q x))"];
paulson@1948
   194
paulson@1948
   195
(*Miniscoping: pushing in universal quantifiers*)
paulson@1948
   196
val all_simps = map prover
paulson@2031
   197
                ["(ALL x. P x & Q)   = ((ALL x.P x) & Q)",
paulson@2031
   198
                 "(ALL x. P & Q x)   = (P & (ALL x.Q x))",
paulson@2031
   199
                 "(ALL x. P x | Q)   = ((ALL x.P x) | Q)",
paulson@2031
   200
                 "(ALL x. P | Q x)   = (P | (ALL x.Q x))",
paulson@2031
   201
                 "(ALL x. P x --> Q) = ((EX x.P x) --> Q)",
paulson@2031
   202
                 "(ALL x. P --> Q x) = (P --> (ALL x.Q x))"];
paulson@1948
   203
paulson@1922
   204
(*In general it seems wrong to add distributive laws by default: they
paulson@1948
   205
  might cause exponential blow-up.  But imp_disj has been in for a while
paulson@1922
   206
  and cannot be removed without affecting existing proofs.  Moreover, 
paulson@1922
   207
  rewriting by "(P|Q --> R) = ((P-->R)&(Q-->R))" might be justified on the
paulson@1922
   208
  grounds that it allows simplification of R in the two cases.*)
paulson@1922
   209
paulson@1922
   210
nipkow@941
   211
local val mktac = mk_case_split_tac (meta_eq_to_obj_eq RS iffD2)
nipkow@941
   212
in
nipkow@941
   213
fun split_tac splits = mktac (map mk_meta_eq splits)
nipkow@941
   214
end;
nipkow@941
   215
berghofe@1722
   216
local val mktac = mk_case_split_inside_tac (meta_eq_to_obj_eq RS iffD2)
berghofe@1722
   217
in
berghofe@1722
   218
fun split_inside_tac splits = mktac (map mk_meta_eq splits)
berghofe@1722
   219
end;
berghofe@1722
   220
clasohm@923
   221
paulson@2022
   222
(* elimination of existential quantifiers in assumptions *)
clasohm@923
   223
clasohm@923
   224
val ex_all_equiv =
clasohm@923
   225
  let val lemma1 = prove_goal HOL.thy
clasohm@923
   226
        "(? x. P(x) ==> PROP Q) ==> (!!x. P(x) ==> PROP Q)"
clasohm@923
   227
        (fn prems => [resolve_tac prems 1, etac exI 1]);
clasohm@923
   228
      val lemma2 = prove_goalw HOL.thy [Ex_def]
clasohm@923
   229
        "(!!x. P(x) ==> PROP Q) ==> (? x. P(x) ==> PROP Q)"
clasohm@923
   230
        (fn prems => [REPEAT(resolve_tac prems 1)])
clasohm@923
   231
  in equal_intr lemma1 lemma2 end;
clasohm@923
   232
clasohm@923
   233
(* '&' congruence rule: not included by default!
clasohm@923
   234
   May slow rewrite proofs down by as much as 50% *)
clasohm@923
   235
paulson@2022
   236
val conj_cong = 
paulson@2022
   237
  let val th = prove_goal HOL.thy 
paulson@2022
   238
                "(P=P')--> (P'--> (Q=Q'))--> ((P&Q) = (P'&Q'))"
paulson@2031
   239
                (fn _=> [fast_tac HOL_cs 1])
paulson@2022
   240
  in  standard (impI RSN (2, th RS mp RS mp))  end;
clasohm@923
   241
paulson@2022
   242
val rev_conj_cong =
paulson@2022
   243
  let val th = prove_goal HOL.thy 
paulson@2022
   244
                "(Q=Q')--> (Q'--> (P=P'))--> ((P&Q) = (P'&Q'))"
paulson@2031
   245
                (fn _=> [fast_tac HOL_cs 1])
paulson@2022
   246
  in  standard (impI RSN (2, th RS mp RS mp))  end;
paulson@2022
   247
paulson@2022
   248
(* '|' congruence rule: not included by default! *)
paulson@2022
   249
paulson@2022
   250
val disj_cong = 
paulson@2022
   251
  let val th = prove_goal HOL.thy 
paulson@2022
   252
                "(P=P')--> (~P'--> (Q=Q'))--> ((P|Q) = (P'|Q'))"
paulson@2031
   253
                (fn _=> [fast_tac HOL_cs 1])
paulson@2022
   254
  in  standard (impI RSN (2, th RS mp RS mp))  end;
nipkow@1548
   255
clasohm@923
   256
(** 'if' congruence rules: neither included by default! *)
clasohm@923
   257
clasohm@923
   258
(*Simplifies x assuming c and y assuming ~c*)
clasohm@923
   259
val if_cong = prove_goal HOL.thy
clasohm@965
   260
  "[| b=c; c ==> x=u; ~c ==> y=v |] ==>\
clasohm@965
   261
\  (if b then x else y) = (if c then u else v)"
clasohm@923
   262
  (fn rew::prems =>
clasohm@923
   263
   [stac rew 1, stac expand_if 1, stac expand_if 1,
clasohm@923
   264
    fast_tac (HOL_cs addDs prems) 1]);
clasohm@923
   265
clasohm@923
   266
(*Prevents simplification of x and y: much faster*)
clasohm@923
   267
val if_weak_cong = prove_goal HOL.thy
clasohm@965
   268
  "b=c ==> (if b then x else y) = (if c then x else y)"
clasohm@923
   269
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
clasohm@923
   270
clasohm@923
   271
(*Prevents simplification of t: much faster*)
clasohm@923
   272
val let_weak_cong = prove_goal HOL.thy
clasohm@923
   273
  "a = b ==> (let x=a in t(x)) = (let x=b in t(x))"
clasohm@923
   274
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
clasohm@923
   275
clasohm@923
   276
end;
clasohm@923
   277
clasohm@923
   278
fun prove nm thm  = qed_goal nm HOL.thy thm (fn _ => [fast_tac HOL_cs 1]);
clasohm@923
   279
clasohm@923
   280
prove "conj_commute" "(P&Q) = (Q&P)";
clasohm@923
   281
prove "conj_left_commute" "(P&(Q&R)) = (Q&(P&R))";
clasohm@923
   282
val conj_comms = [conj_commute, conj_left_commute];
clasohm@923
   283
paulson@1922
   284
prove "disj_commute" "(P|Q) = (Q|P)";
paulson@1922
   285
prove "disj_left_commute" "(P|(Q|R)) = (Q|(P|R))";
paulson@1922
   286
val disj_comms = [disj_commute, disj_left_commute];
paulson@1922
   287
clasohm@923
   288
prove "conj_disj_distribL" "(P&(Q|R)) = (P&Q | P&R)";
clasohm@923
   289
prove "conj_disj_distribR" "((P|Q)&R) = (P&R | Q&R)";
nipkow@1485
   290
paulson@1892
   291
prove "disj_conj_distribL" "(P|(Q&R)) = ((P|Q) & (P|R))";
paulson@1892
   292
prove "disj_conj_distribR" "((P&Q)|R) = ((P|R) & (Q|R))";
paulson@1892
   293
paulson@1892
   294
prove "imp_conj_distrib" "(P --> (Q&R)) = ((P-->Q) & (P-->R))";
paulson@1922
   295
prove "imp_conj"         "((P&Q)-->R)   = (P --> (Q --> R))";
paulson@1892
   296
nipkow@1485
   297
prove "de_Morgan_disj" "(~(P | Q)) = (~P & ~Q)";
nipkow@1485
   298
prove "de_Morgan_conj" "(~(P & Q)) = (~P | ~Q)";
paulson@1922
   299
prove "not_iff" "(P~=Q) = (P = (~Q))";
nipkow@1485
   300
oheimb@1660
   301
prove "not_all" "(~ (! x.P(x))) = (? x.~P(x))";
paulson@1922
   302
prove "imp_all" "((! x. P x) --> Q) = (? x. P x --> Q)";
oheimb@1660
   303
prove "not_ex"  "(~ (? x.P(x))) = (! x.~P(x))";
paulson@1922
   304
prove "imp_ex" "((? x. P x) --> Q) = (! x. P x --> Q)";
oheimb@1660
   305
nipkow@1655
   306
prove "ex_disj_distrib" "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))";
nipkow@1655
   307
prove "all_conj_distrib" "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))";
nipkow@1655
   308
nipkow@1758
   309
paulson@2082
   310
val HOL_ss = empty_ss
paulson@2082
   311
      setmksimps (mksimps mksimps_pairs)
paulson@2082
   312
      setsolver (fn prems => resolve_tac (TrueI::refl::prems) ORELSE' atac
paulson@2082
   313
                             ORELSE' etac FalseE)
paulson@2082
   314
      setsubgoaler asm_simp_tac
paulson@2082
   315
      addsimps ([if_True, if_False, o_apply, imp_disj, conj_assoc, disj_assoc,
paulson@2082
   316
                 de_Morgan_conj, de_Morgan_disj, not_all, not_ex, cases_simp]
paulson@2082
   317
        @ ex_simps @ all_simps @ simp_thms)
paulson@2082
   318
      addcongs [imp_cong];
paulson@2082
   319
paulson@2082
   320
nipkow@1655
   321
qed_goal "if_cancel" HOL.thy "(if c then x else x) = x"
nipkow@1655
   322
  (fn _ => [simp_tac (HOL_ss setloop (split_tac [expand_if])) 1]);
nipkow@1655
   323
nipkow@1655
   324
qed_goal "if_distrib" HOL.thy
nipkow@1655
   325
  "f(if c then x else y) = (if c then f x else f y)" 
nipkow@1655
   326
  (fn _ => [simp_tac (HOL_ss setloop (split_tac [expand_if])) 1]);
nipkow@1655
   327
pusch@1874
   328
qed_goalw "o_assoc" HOL.thy [o_def] "f o (g o h) = (f o g o h)"
nipkow@1655
   329
  (fn _=>[rtac ext 1, rtac refl 1]);
paulson@1984
   330
paulson@1984
   331
paulson@1984
   332
paulson@1984
   333
paulson@1984
   334
(*** Install simpsets and datatypes in theory structure ***)
paulson@1984
   335
paulson@1984
   336
simpset := HOL_ss;
paulson@1984
   337
paulson@1984
   338
exception SS_DATA of simpset;
paulson@1984
   339
paulson@1984
   340
let fun merge [] = SS_DATA empty_ss
paulson@1984
   341
      | merge ss = let val ss = map (fn SS_DATA x => x) ss;
paulson@1984
   342
                   in SS_DATA (foldl merge_ss (hd ss, tl ss)) end;
paulson@1984
   343
paulson@1984
   344
    fun put (SS_DATA ss) = simpset := ss;
paulson@1984
   345
paulson@1984
   346
    fun get () = SS_DATA (!simpset);
paulson@1984
   347
in add_thydata "HOL"
paulson@1984
   348
     ("simpset", ThyMethods {merge = merge, put = put, get = get})
paulson@1984
   349
end;
paulson@1984
   350
paulson@1984
   351
type dtype_info = {case_const:term, case_rewrites:thm list,
paulson@1984
   352
                   constructors:term list, nchotomy:thm, case_cong:thm};
paulson@1984
   353
paulson@1984
   354
exception DT_DATA of (string * dtype_info) list;
paulson@1984
   355
val datatypes = ref [] : (string * dtype_info) list ref;
paulson@1984
   356
paulson@1984
   357
let fun merge [] = DT_DATA []
paulson@1984
   358
      | merge ds =
paulson@1984
   359
          let val ds = map (fn DT_DATA x => x) ds;
paulson@1984
   360
          in DT_DATA (foldl (gen_union eq_fst) (hd ds, tl ds)) end;
paulson@1984
   361
paulson@1984
   362
    fun put (DT_DATA ds) = datatypes := ds;
paulson@1984
   363
paulson@1984
   364
    fun get () = DT_DATA (!datatypes);
paulson@1984
   365
in add_thydata "HOL"
paulson@1984
   366
     ("datatypes", ThyMethods {merge = merge, put = put, get = get})
paulson@1984
   367
end;
paulson@1984
   368
paulson@1984
   369
paulson@1984
   370
add_thy_reader_file "thy_data.ML";