src/HOL/simpdata.ML
author nipkow
Mon Oct 28 15:36:18 1996 +0100 (1996-10-28)
changeset 2134 04a71407089d
parent 2129 2ffe6e24f38d
child 2234 041bf27011b1
permissions -rw-r--r--
Renamed and shuffled a few thms.
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
nipkow@2134
   100
  fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th;
nipkow@2134
   101
nipkow@2134
   102
in
nipkow@2134
   103
paulson@1922
   104
  fun mk_meta_eq r = case concl_of r of
paulson@2031
   105
          Const("==",_)$_$_ => r
paulson@1922
   106
      |   _$(Const("op =",_)$_$_) => r RS eq_reflection
paulson@1922
   107
      |   _$(Const("not",_)$_) => r RS not_P_imp_P_eq_False
paulson@1922
   108
      |   _ => r RS P_imp_P_eq_True;
paulson@1922
   109
  (* last 2 lines requires all formulae to be of the from Trueprop(.) *)
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)",
nipkow@2129
   124
   "(!x.P) = P", "(? x.P) = P", "? x. x=t", "? x. t=x", 
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
lcp@988
   128
(*Add congruence rules for = (instead of ==) *)
lcp@988
   129
infix 4 addcongs;
clasohm@923
   130
fun ss addcongs congs = ss addeqcongs (congs RL [eq_reflection]);
clasohm@923
   131
clasohm@1264
   132
fun Addcongs congs = (simpset := !simpset addcongs congs);
clasohm@1264
   133
clasohm@923
   134
fun mksimps pairs = map mk_meta_eq o atomize pairs o gen_all;
clasohm@923
   135
paulson@1922
   136
val imp_cong = impI RSN
paulson@1922
   137
    (2, prove_goal HOL.thy "(P=P')--> (P'--> (Q=Q'))--> ((P-->Q) = (P'-->Q'))"
paulson@1922
   138
        (fn _=> [fast_tac HOL_cs 1]) RS mp RS mp);
paulson@1922
   139
paulson@1948
   140
(*Miniscoping: pushing in existential quantifiers*)
paulson@1948
   141
val ex_simps = map prover 
paulson@2031
   142
                ["(EX x. P x & Q)   = ((EX x.P x) & Q)",
paulson@2031
   143
                 "(EX x. P & Q x)   = (P & (EX x.Q x))",
paulson@2031
   144
                 "(EX x. P x | Q)   = ((EX x.P x) | Q)",
paulson@2031
   145
                 "(EX x. P | Q x)   = (P | (EX x.Q x))",
paulson@2031
   146
                 "(EX x. P x --> Q) = ((ALL x.P x) --> Q)",
paulson@2031
   147
                 "(EX x. P --> Q x) = (P --> (EX x.Q x))"];
paulson@1948
   148
paulson@1948
   149
(*Miniscoping: pushing in universal quantifiers*)
paulson@1948
   150
val all_simps = map prover
paulson@2031
   151
                ["(ALL x. P x & Q)   = ((ALL x.P x) & Q)",
paulson@2031
   152
                 "(ALL x. P & Q x)   = (P & (ALL x.Q x))",
paulson@2031
   153
                 "(ALL x. P x | Q)   = ((ALL x.P x) | Q)",
paulson@2031
   154
                 "(ALL x. P | Q x)   = (P | (ALL x.Q x))",
paulson@2031
   155
                 "(ALL x. P x --> Q) = ((EX x.P x) --> Q)",
paulson@2031
   156
                 "(ALL x. P --> Q x) = (P --> (ALL x.Q x))"];
paulson@1948
   157
berghofe@1722
   158
clasohm@923
   159
paulson@2022
   160
(* elimination of existential quantifiers in assumptions *)
clasohm@923
   161
clasohm@923
   162
val ex_all_equiv =
clasohm@923
   163
  let val lemma1 = prove_goal HOL.thy
clasohm@923
   164
        "(? x. P(x) ==> PROP Q) ==> (!!x. P(x) ==> PROP Q)"
clasohm@923
   165
        (fn prems => [resolve_tac prems 1, etac exI 1]);
clasohm@923
   166
      val lemma2 = prove_goalw HOL.thy [Ex_def]
clasohm@923
   167
        "(!!x. P(x) ==> PROP Q) ==> (? x. P(x) ==> PROP Q)"
clasohm@923
   168
        (fn prems => [REPEAT(resolve_tac prems 1)])
clasohm@923
   169
  in equal_intr lemma1 lemma2 end;
clasohm@923
   170
clasohm@923
   171
end;
clasohm@923
   172
clasohm@923
   173
fun prove nm thm  = qed_goal nm HOL.thy thm (fn _ => [fast_tac HOL_cs 1]);
clasohm@923
   174
clasohm@923
   175
prove "conj_commute" "(P&Q) = (Q&P)";
clasohm@923
   176
prove "conj_left_commute" "(P&(Q&R)) = (Q&(P&R))";
clasohm@923
   177
val conj_comms = [conj_commute, conj_left_commute];
nipkow@2134
   178
prove "conj_assoc" "((P&Q)&R) = (P&(Q&R))";
clasohm@923
   179
paulson@1922
   180
prove "disj_commute" "(P|Q) = (Q|P)";
paulson@1922
   181
prove "disj_left_commute" "(P|(Q|R)) = (Q|(P|R))";
paulson@1922
   182
val disj_comms = [disj_commute, disj_left_commute];
nipkow@2134
   183
prove "disj_assoc" "((P|Q)|R) = (P|(Q|R))";
paulson@1922
   184
clasohm@923
   185
prove "conj_disj_distribL" "(P&(Q|R)) = (P&Q | P&R)";
clasohm@923
   186
prove "conj_disj_distribR" "((P|Q)&R) = (P&R | Q&R)";
nipkow@1485
   187
paulson@1892
   188
prove "disj_conj_distribL" "(P|(Q&R)) = ((P|Q) & (P|R))";
paulson@1892
   189
prove "disj_conj_distribR" "((P&Q)|R) = ((P|R) & (Q|R))";
paulson@1892
   190
nipkow@2134
   191
prove "imp_conjR" "(P --> (Q&R)) = ((P-->Q) & (P-->R))";
nipkow@2134
   192
prove "imp_conjL" "((P&Q) -->R)  = (P --> (Q --> R))";
nipkow@2134
   193
prove "imp_disjL" "((P|Q) --> R) = ((P-->R)&(Q-->R))";
paulson@1892
   194
nipkow@1485
   195
prove "de_Morgan_disj" "(~(P | Q)) = (~P & ~Q)";
nipkow@1485
   196
prove "de_Morgan_conj" "(~(P & Q)) = (~P | ~Q)";
paulson@1922
   197
prove "not_iff" "(P~=Q) = (P = (~Q))";
nipkow@1485
   198
nipkow@2134
   199
(*Avoids duplication of subgoals after expand_if, when the true and false 
nipkow@2134
   200
  cases boil down to the same thing.*) 
nipkow@2134
   201
prove "cases_simp" "((P --> Q) & (~P --> Q)) = Q";
nipkow@2134
   202
oheimb@1660
   203
prove "not_all" "(~ (! x.P(x))) = (? x.~P(x))";
paulson@1922
   204
prove "imp_all" "((! x. P x) --> Q) = (? x. P x --> Q)";
oheimb@1660
   205
prove "not_ex"  "(~ (? x.P(x))) = (! x.~P(x))";
paulson@1922
   206
prove "imp_ex" "((? x. P x) --> Q) = (! x. P x --> Q)";
oheimb@1660
   207
nipkow@1655
   208
prove "ex_disj_distrib" "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))";
nipkow@1655
   209
prove "all_conj_distrib" "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))";
nipkow@1655
   210
nipkow@2134
   211
(* '&' congruence rule: not included by default!
nipkow@2134
   212
   May slow rewrite proofs down by as much as 50% *)
nipkow@2134
   213
nipkow@2134
   214
let val th = prove_goal HOL.thy 
nipkow@2134
   215
                "(P=P')--> (P'--> (Q=Q'))--> ((P&Q) = (P'&Q'))"
nipkow@2134
   216
                (fn _=> [fast_tac HOL_cs 1])
nipkow@2134
   217
in  bind_thm("conj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
nipkow@2134
   218
nipkow@2134
   219
let val th = prove_goal HOL.thy 
nipkow@2134
   220
                "(Q=Q')--> (Q'--> (P=P'))--> ((P&Q) = (P'&Q'))"
nipkow@2134
   221
                (fn _=> [fast_tac HOL_cs 1])
nipkow@2134
   222
in  bind_thm("rev_conj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
nipkow@2134
   223
nipkow@2134
   224
(* '|' congruence rule: not included by default! *)
nipkow@2134
   225
nipkow@2134
   226
let val th = prove_goal HOL.thy 
nipkow@2134
   227
                "(P=P')--> (~P'--> (Q=Q'))--> ((P|Q) = (P'|Q'))"
nipkow@2134
   228
                (fn _=> [fast_tac HOL_cs 1])
nipkow@2134
   229
in  bind_thm("disj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
nipkow@2134
   230
nipkow@2134
   231
prove "eq_sym_conv" "(x=y) = (y=x)";
nipkow@2134
   232
nipkow@2134
   233
qed_goalw "o_apply" HOL.thy [o_def] "(f o g) x = f (g x)"
nipkow@2134
   234
 (fn _ => [rtac refl 1]);
nipkow@2134
   235
nipkow@2134
   236
qed_goal "meta_eq_to_obj_eq" HOL.thy "x==y ==> x=y"
nipkow@2134
   237
  (fn [prem] => [rewtac prem, rtac refl 1]);
nipkow@2134
   238
nipkow@2134
   239
qed_goalw "if_True" HOL.thy [if_def] "(if True then x else y) = x"
nipkow@2134
   240
 (fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]);
nipkow@2134
   241
nipkow@2134
   242
qed_goalw "if_False" HOL.thy [if_def] "(if False then x else y) = y"
nipkow@2134
   243
 (fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]);
nipkow@2134
   244
nipkow@2134
   245
qed_goal "if_P" HOL.thy "P ==> (if P then x else y) = x"
nipkow@2134
   246
 (fn [prem] => [ stac (prem RS eqTrueI) 1, rtac if_True 1 ]);
nipkow@2134
   247
(*
nipkow@2134
   248
qed_goal "if_not_P" HOL.thy "~P ==> (if P then x else y) = y"
nipkow@2134
   249
 (fn [prem] => [ stac (prem RS not_P_imp_P_iff_F) 1, rtac if_False 1 ]);
nipkow@2134
   250
*)
nipkow@2134
   251
qed_goalw "if_not_P" HOL.thy [if_def] "!!P. ~P ==> (if P then x else y) = y"
nipkow@2134
   252
 (fn _ => [fast_tac (HOL_cs addIs [select_equality]) 1]);
nipkow@2134
   253
nipkow@2134
   254
qed_goal "expand_if" HOL.thy
nipkow@2134
   255
    "P(if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
nipkow@2134
   256
 (fn _=> [ (res_inst_tac [("Q","Q")] (excluded_middle RS disjE) 1),
nipkow@2134
   257
         stac if_P 2,
nipkow@2134
   258
         stac if_not_P 1,
nipkow@2134
   259
         REPEAT(fast_tac HOL_cs 1) ]);
nipkow@2134
   260
nipkow@2134
   261
qed_goal "if_bool_eq" HOL.thy
nipkow@2134
   262
                   "(if P then Q else R) = ((P-->Q) & (~P-->R))"
nipkow@2134
   263
                   (fn _ => [rtac expand_if 1]);
nipkow@2134
   264
nipkow@2134
   265
(** 'if' congruence rules: neither included by default! *)
nipkow@2134
   266
nipkow@2134
   267
(*Simplifies x assuming c and y assuming ~c*)
nipkow@2134
   268
qed_goal "if_cong" HOL.thy
nipkow@2134
   269
  "[| b=c; c ==> x=u; ~c ==> y=v |] ==>\
nipkow@2134
   270
\  (if b then x else y) = (if c then u else v)"
nipkow@2134
   271
  (fn rew::prems =>
nipkow@2134
   272
   [stac rew 1, stac expand_if 1, stac expand_if 1,
nipkow@2134
   273
    fast_tac (HOL_cs addDs prems) 1]);
nipkow@2134
   274
nipkow@2134
   275
(*Prevents simplification of x and y: much faster*)
nipkow@2134
   276
qed_goal "if_weak_cong" HOL.thy
nipkow@2134
   277
  "b=c ==> (if b then x else y) = (if c then x else y)"
nipkow@2134
   278
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
nipkow@2134
   279
nipkow@2134
   280
(*Prevents simplification of t: much faster*)
nipkow@2134
   281
qed_goal "let_weak_cong" HOL.thy
nipkow@2134
   282
  "a = b ==> (let x=a in t(x)) = (let x=b in t(x))"
nipkow@2134
   283
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
nipkow@2134
   284
nipkow@2134
   285
(*In general it seems wrong to add distributive laws by default: they
nipkow@2134
   286
  might cause exponential blow-up.  But imp_disjL has been in for a while
nipkow@2134
   287
  and cannot be removed without affecting existing proofs.  Moreover, 
nipkow@2134
   288
  rewriting by "(P|Q --> R) = ((P-->R)&(Q-->R))" might be justified on the
nipkow@2134
   289
  grounds that it allows simplification of R in the two cases.*)
nipkow@2134
   290
nipkow@2134
   291
val mksimps_pairs =
nipkow@2134
   292
  [("op -->", [mp]), ("op &", [conjunct1,conjunct2]),
nipkow@2134
   293
   ("All", [spec]), ("True", []), ("False", []),
nipkow@2134
   294
   ("If", [if_bool_eq RS iffD1])];
nipkow@1758
   295
paulson@2082
   296
val HOL_ss = empty_ss
paulson@2082
   297
      setmksimps (mksimps mksimps_pairs)
paulson@2082
   298
      setsolver (fn prems => resolve_tac (TrueI::refl::prems) ORELSE' atac
paulson@2082
   299
                             ORELSE' etac FalseE)
paulson@2082
   300
      setsubgoaler asm_simp_tac
nipkow@2134
   301
      addsimps ([if_True, if_False, o_apply, imp_disjL, conj_assoc, disj_assoc,
paulson@2082
   302
                 de_Morgan_conj, de_Morgan_disj, not_all, not_ex, cases_simp]
paulson@2082
   303
        @ ex_simps @ all_simps @ simp_thms)
paulson@2082
   304
      addcongs [imp_cong];
paulson@2082
   305
paulson@2082
   306
nipkow@2134
   307
local val mktac = mk_case_split_tac (meta_eq_to_obj_eq RS iffD2)
nipkow@2134
   308
in
nipkow@2134
   309
fun split_tac splits = mktac (map mk_meta_eq splits)
nipkow@2134
   310
end;
nipkow@2134
   311
nipkow@2134
   312
local val mktac = mk_case_split_inside_tac (meta_eq_to_obj_eq RS iffD2)
nipkow@2134
   313
in
nipkow@2134
   314
fun split_inside_tac splits = mktac (map mk_meta_eq splits)
nipkow@2134
   315
end;
nipkow@2134
   316
nipkow@2134
   317
nipkow@1655
   318
qed_goal "if_cancel" HOL.thy "(if c then x else x) = x"
nipkow@1655
   319
  (fn _ => [simp_tac (HOL_ss setloop (split_tac [expand_if])) 1]);
nipkow@1655
   320
nipkow@1655
   321
qed_goal "if_distrib" HOL.thy
nipkow@1655
   322
  "f(if c then x else y) = (if c then f x else f y)" 
nipkow@1655
   323
  (fn _ => [simp_tac (HOL_ss setloop (split_tac [expand_if])) 1]);
nipkow@1655
   324
oheimb@2097
   325
qed_goalw "o_assoc" HOL.thy [o_def] "f o (g o h) = f o g o h"
oheimb@2098
   326
  (fn _ => [rtac ext 1, rtac refl 1]);
paulson@1984
   327
paulson@1984
   328
paulson@1984
   329
paulson@1984
   330
paulson@1984
   331
(*** Install simpsets and datatypes in theory structure ***)
paulson@1984
   332
paulson@1984
   333
simpset := HOL_ss;
paulson@1984
   334
paulson@1984
   335
exception SS_DATA of simpset;
paulson@1984
   336
paulson@1984
   337
let fun merge [] = SS_DATA empty_ss
paulson@1984
   338
      | merge ss = let val ss = map (fn SS_DATA x => x) ss;
paulson@1984
   339
                   in SS_DATA (foldl merge_ss (hd ss, tl ss)) end;
paulson@1984
   340
paulson@1984
   341
    fun put (SS_DATA ss) = simpset := ss;
paulson@1984
   342
paulson@1984
   343
    fun get () = SS_DATA (!simpset);
paulson@1984
   344
in add_thydata "HOL"
paulson@1984
   345
     ("simpset", ThyMethods {merge = merge, put = put, get = get})
paulson@1984
   346
end;
paulson@1984
   347
paulson@1984
   348
type dtype_info = {case_const:term, case_rewrites:thm list,
paulson@1984
   349
                   constructors:term list, nchotomy:thm, case_cong:thm};
paulson@1984
   350
paulson@1984
   351
exception DT_DATA of (string * dtype_info) list;
paulson@1984
   352
val datatypes = ref [] : (string * dtype_info) list ref;
paulson@1984
   353
paulson@1984
   354
let fun merge [] = DT_DATA []
paulson@1984
   355
      | merge ds =
paulson@1984
   356
          let val ds = map (fn DT_DATA x => x) ds;
paulson@1984
   357
          in DT_DATA (foldl (gen_union eq_fst) (hd ds, tl ds)) end;
paulson@1984
   358
paulson@1984
   359
    fun put (DT_DATA ds) = datatypes := ds;
paulson@1984
   360
paulson@1984
   361
    fun get () = DT_DATA (!datatypes);
paulson@1984
   362
in add_thydata "HOL"
paulson@1984
   363
     ("datatypes", ThyMethods {merge = merge, put = put, get = get})
paulson@1984
   364
end;
paulson@1984
   365
paulson@1984
   366
paulson@1984
   367
add_thy_reader_file "thy_data.ML";