src/HOL/Tools/res_atpset.ML
author mengj
Wed Mar 01 05:56:53 2006 +0100 (2006-03-01)
changeset 19159 f737ecbad1c4
child 19170 a55a3464a1de
permissions -rw-r--r--
A new file that sets up rules set used by ATPs. Rules are added to and removed from the set using "atp" attribute.
mengj@19159
     1
(*  ID:         $Id$
mengj@19159
     2
    Author:     Jia Meng, NICTA 
mengj@19159
     3
mengj@19159
     4
Set of rules used for ATPs
mengj@19159
     5
*)
mengj@19159
     6
mengj@19159
     7
structure ResAtpSet =
mengj@19159
     8
mengj@19159
     9
struct
mengj@19159
    10
mengj@19159
    11
datatype atpset = AtpSet of thm list
mengj@19159
    12
mengj@19159
    13
mengj@19159
    14
val mem_thm = member Drule.eq_thm_prop;
mengj@19159
    15
val rem_thm = remove Drule.eq_thm_prop;
mengj@19159
    16
mengj@19159
    17
val empty_atpset = AtpSet [];
mengj@19159
    18
mengj@19159
    19
fun add_atp_rule (thm,AtpSet thms) = 
mengj@19159
    20
    if mem_thm thms thm then (warning ("Ignoring duplicate ATP rules\n" ^ string_of_thm thm); AtpSet thms)
mengj@19159
    21
    else
mengj@19159
    22
	AtpSet (thm::thms);
mengj@19159
    23
mengj@19159
    24
fun add_atp_rule' thm ars = add_atp_rule (thm,ars);
mengj@19159
    25
fun add_atp_rules (ars,thms) =  foldl add_atp_rule ars thms;
mengj@19159
    26
mengj@19159
    27
fun del_atp_rule (thm,AtpSet thms) = 
mengj@19159
    28
    if mem_thm thms thm then AtpSet (rem_thm thm thms)
mengj@19159
    29
    else
mengj@19159
    30
	(warning "Undeclared rule for ATPs"; AtpSet thms);
mengj@19159
    31
mengj@19159
    32
fun del_atp_rule' thm ars = del_atp_rule (thm,ars);
mengj@19159
    33
mengj@19159
    34
fun del_atp_rules (ars,thms) = foldl del_atp_rule ars thms;
mengj@19159
    35
mengj@19159
    36
fun merge_atpset (ars1, AtpSet thms2) = add_atp_rules (ars1,thms2);
mengj@19159
    37
mengj@19159
    38
fun print_atpset (AtpSet thms) =
mengj@19159
    39
    let val pretty_thms = map Display.pretty_thm in
mengj@19159
    40
	[Pretty.big_list "Rules for ATPs:" (pretty_thms thms)]
mengj@19159
    41
	    |> Pretty.chunks |> Pretty.writeln
mengj@19159
    42
    end;
mengj@19159
    43
mengj@19159
    44
mengj@19159
    45
(* global AtpSet *)
mengj@19159
    46
mengj@19159
    47
structure GlobalAtpSet = TheoryDataFun
mengj@19159
    48
(struct
mengj@19159
    49
  val name = "AtpSet";
mengj@19159
    50
  type T = atpset ref;
mengj@19159
    51
  
mengj@19159
    52
  val empty = ref empty_atpset;
mengj@19159
    53
  fun copy (ref atpst) = ref atpst : T;
mengj@19159
    54
  val extend = copy;
mengj@19159
    55
  fun merge _ (ref atpst1, ref atpst2) =
mengj@19159
    56
      ref (merge_atpset (atpst1, atpst2));
mengj@19159
    57
  fun print (thy: Theory.theory) (ref atpst) = print_atpset atpst;
mengj@19159
    58
end);
mengj@19159
    59
mengj@19159
    60
val print_AtpSet = GlobalAtpSet.print; 
mengj@19159
    61
val get_AtpSet = ! o GlobalAtpSet.get;
mengj@19159
    62
mengj@19159
    63
val change_AtpSet_of = change o GlobalAtpSet.get;
mengj@19159
    64
fun change_AtpSet f = change_AtpSet_of (Context.the_context ()) f;
mengj@19159
    65
mengj@19159
    66
mengj@19159
    67
fun AtpSet_of thy = get_AtpSet thy;
mengj@19159
    68
mengj@19159
    69
fun Add_AtpRs args = change_AtpSet (fn ars => add_atp_rules (ars,args));
mengj@19159
    70
mengj@19159
    71
fun Del_AtpRs args = change_AtpSet (fn ars => del_atp_rules (ars,args));
mengj@19159
    72
mengj@19159
    73
mengj@19159
    74
(* local AtpSet *)
mengj@19159
    75
mengj@19159
    76
structure LocalAtpSet = ProofDataFun
mengj@19159
    77
(struct
mengj@19159
    78
  val name = "AtpSet";
mengj@19159
    79
  type T = atpset;
mengj@19159
    80
  val init = get_AtpSet;
mengj@19159
    81
  fun print _ atpst = print_atpset atpst;
mengj@19159
    82
end);
mengj@19159
    83
mengj@19159
    84
val print_local_AtpSet = LocalAtpSet.print;
mengj@19159
    85
mengj@19159
    86
val get_local_AtpSet = LocalAtpSet.get;
mengj@19159
    87
mengj@19159
    88
val put_local_AtpSet = LocalAtpSet.put;
mengj@19159
    89
mengj@19159
    90
fun local_AtpSet_of ctxt = get_local_AtpSet;
mengj@19159
    91
mengj@19159
    92
mengj@19159
    93
(* attributes *)
mengj@19159
    94
fun attrib f = Thm.declaration_attribute (fn th =>
mengj@19159
    95
   fn Context.Theory thy => (change_AtpSet_of thy (f th); Context.Theory thy)
mengj@19159
    96
    | Context.Proof ctxt => Context.Proof (LocalAtpSet.map (f th) ctxt));
mengj@19159
    97
mengj@19159
    98
mengj@19159
    99
val add_rule = attrib add_atp_rule';
mengj@19159
   100
val del_rule = attrib del_atp_rule';
mengj@19159
   101
mengj@19159
   102
val atpN = "atp";
mengj@19159
   103
mengj@19159
   104
val setup_attrs = Attrib.add_attributes
mengj@19159
   105
[(atpN, Attrib.add_del_args add_rule del_rule, "declaration of ATP rules")];
mengj@19159
   106
mengj@19159
   107
val setup = GlobalAtpSet.init #> LocalAtpSet.init #> setup_attrs;
mengj@19159
   108
mengj@19159
   109
end;