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