src/HOL/Tools/ATP/res_clasimpset.ML
author mengj
Sat Feb 11 14:25:23 2006 +0100 (2006-02-11)
changeset 19010 fef9e4881e83
parent 18985 bc23b1d1ddea
child 19156 bdaa8a980431
permissions -rw-r--r--
Changed some code due to changes in reduce_axiomsN.ML.
     1 (*  ID:      $Id$
     2     Author:     Claire Quigley
     3     Copyright   2004  University of Cambridge
     4 *)
     5 
     6 signature RES_CLASIMP = 
     7   sig
     8   val blacklist : string list ref (*Theorems forbidden in the output*)
     9   val theory_blacklist : string list ref (*entire blacklisted theories*)
    10   val relevant : int ref
    11   val use_simpset: bool ref
    12   val get_clasimp_lemmas : 
    13          Proof.context -> term list -> 
    14          (ResClause.clause * thm) Array.array * ResClause.clause list 
    15   end;
    16 
    17 structure ResClasimp : RES_CLASIMP =
    18 struct
    19 val use_simpset = ref false;   (*Performance is much better without simprules*)
    20 
    21 (*In general, these produce clauses that are prolific (match too many equality or
    22   membership literals) and relate to seldom-used facts. Some duplicate other rules.
    23   FIXME: this blacklist needs to be maintained using theory data and added to using
    24   an attribute.*)
    25 val blacklist = ref
    26   ["Datatype.not_None_eq",    (*Says everything is None or Some. Probably prolific.*)
    27    "Datatype.not_Some_eq_D",  (*Says everything is None or Some. Probably prolific.*)
    28    "Datatype.not_Some_eq",    (*Says everything is None or Some. Probably prolific.*)
    29    "Datatype.option.size_1",
    30    "Datatype.option.size_2",
    31    "Datatype.prod.size",
    32    "Datatype.sum.size_1",
    33    "Datatype.sum.size_2",
    34    "Datatype.unit.size",
    35    "Divides.dvd_0_left_iff",
    36    "Finite_Set.card_0_eq",
    37    "Finite_Set.card_infinite",
    38    "Finite_Set.Max_ge",
    39    "Finite_Set.Max_in",
    40    "Finite_Set.Max_le_iff",
    41    "Finite_Set.Max_less_iff",
    42    "Finite_Set.max.f_below_strict_below.below_f_conv", (*duplicates in Orderings.*)
    43    "Finite_Set.max.f_below_strict_below.strict_below_f_conv", (*duplicates in Orderings.*)
    44    "Finite_Set.Min_ge_iff",
    45    "Finite_Set.Min_gr_iff",
    46    "Finite_Set.Min_in",
    47    "Finite_Set.Min_le",
    48    "Finite_Set.min_max.below_inf_sup_Inf_Sup.inf_Sup_absorb", 
    49    "Finite_Set.min_max.below_inf_sup_Inf_Sup.sup_Inf_absorb", 
    50    "Finite_Set.min.f_below_strict_below.below_f_conv",        (*duplicates in Orderings.*)
    51    "Finite_Set.min.f_below_strict_below.strict_below_f_conv", (*duplicates in Orderings.*)
    52    "Infinite_Set.atmost_one_unique",
    53    "IntArith.zabs_less_one_iff",
    54    "IntDef.Integ.Abs_Integ_inject",
    55    "IntDef.Integ.Abs_Integ_inverse",
    56    "IntDiv.zdvd_0_left",
    57    "IntDiv.zero_less_zpower_abs_iff",
    58    "List.append_eq_append_conv",
    59    "List.Cons_in_lex",
    60    "List.hd_Cons_tl",   (*Says everything is [] or Cons. Probably prolific.*)
    61    "List.in_listsD",
    62    "List.in_listsI",
    63    "List.lists.Cons",
    64    "List.listsE",
    65    "List.take_eq_Nil",
    66    "Nat.less_one",
    67    "Nat.less_one", (*not directional? obscure*)
    68    "Nat.not_gr0",
    69    "Nat.one_eq_mult_iff", (*duplicate by symmetry*)
    70    "NatArith.of_nat_0_eq_iff",
    71    "NatArith.of_nat_eq_0_iff",
    72    "NatArith.of_nat_le_0_iff",
    73    "NatSimprocs.divide_le_0_iff_number_of",  (*seldom used; often prolific*)
    74    "NatSimprocs.divide_le_0_iff_number_of",  (*too many clauses*)
    75    "NatSimprocs.divide_less_0_iff_number_of",
    76    "NatSimprocs.divide_less_0_iff_number_of",   (*too many clauses*)
    77    "NatSimprocs.equation_minus_iff_1",  (*not directional*)
    78    "NatSimprocs.equation_minus_iff_number_of", (*not directional*)
    79    "NatSimprocs.le_minus_iff_1", (*not directional*)
    80    "NatSimprocs.le_minus_iff_number_of",  (*not directional*)
    81    "NatSimprocs.less_minus_iff_1", (*not directional*)
    82    "NatSimprocs.less_minus_iff_number_of", (*not directional*)
    83    "NatSimprocs.minus_equation_iff_number_of", (*not directional*)
    84    "NatSimprocs.minus_le_iff_1", (*not directional*)
    85    "NatSimprocs.minus_le_iff_number_of", (*not directional*)
    86    "NatSimprocs.minus_less_iff_1", (*not directional*)
    87    "NatSimprocs.mult_le_cancel_left_number_of", (*excessive case analysis*)
    88    "NatSimprocs.mult_le_cancel_right_number_of", (*excessive case analysis*)
    89    "NatSimprocs.mult_less_cancel_left_number_of", (*excessive case analysis*)
    90    "NatSimprocs.mult_less_cancel_right_number_of", (*excessive case analysis*)
    91    "NatSimprocs.zero_le_divide_iff_number_of",
    92    "NatSimprocs.zero_le_divide_iff_number_of", (*excessive case analysis*)
    93    "NatSimprocs.zero_less_divide_iff_number_of",
    94    "NatSimprocs.zero_less_divide_iff_number_of", (*excessive case analysis*)
    95    "OrderedGroup.abs_0_eq",
    96    "OrderedGroup.abs_0_eq", (*duplicate by symmetry*)
    97    "OrderedGroup.diff_eq_0_iff_eq", (*prolific?*)
    98    "OrderedGroup.join_0_eq_0",
    99    "OrderedGroup.meet_0_eq_0",
   100    "OrderedGroup.pprt_eq_0",   (*obscure*)
   101    "OrderedGroup.pprt_eq_id",   (*obscure*)
   102    "OrderedGroup.pprt_mono",   (*obscure*)
   103    "Parity.even_nat_power",   (*obscure, somewhat prolilfic*)
   104    "Parity.power_eq_0_iff_number_of",
   105    "Parity.power_eq_0_iff_number_of",
   106    "Parity.power_le_zero_eq_number_of",
   107    "Parity.power_le_zero_eq_number_of",   (*obscure and prolific*)
   108    "Parity.power_less_zero_eq_number_of",
   109    "Parity.zero_le_power_eq_number_of",   (*obscure and prolific*)
   110    "Parity.zero_less_power_eq_number_of",   (*obscure and prolific*)
   111    "Power.zero_less_power_abs_iff",
   112    "Relation.diagI",
   113    "Relation.ImageI",
   114    "Ring_and_Field.divide_cancel_left", (*fields are seldom used & often prolific*)
   115    "Ring_and_Field.divide_cancel_right",
   116    "Ring_and_Field.divide_divide_eq_left",
   117    "Ring_and_Field.divide_divide_eq_right",
   118    "Ring_and_Field.divide_eq_0_iff",
   119    "Ring_and_Field.divide_eq_1_iff",
   120    "Ring_and_Field.divide_eq_eq_1",
   121    "Ring_and_Field.divide_le_0_1_iff",
   122    "Ring_and_Field.divide_le_eq_1_neg",
   123    "Ring_and_Field.divide_le_eq_1_neg",  (*obscure and prolific*)
   124    "Ring_and_Field.divide_le_eq_1_pos",
   125    "Ring_and_Field.divide_le_eq_1_pos",  (*obscure and prolific*)
   126    "Ring_and_Field.divide_less_0_1_iff",
   127    "Ring_and_Field.divide_less_eq_1_neg",  (*obscure and prolific*)
   128    "Ring_and_Field.divide_less_eq_1_pos",
   129    "Ring_and_Field.divide_less_eq_1_pos",  (*obscure and prolific*)
   130    "Ring_and_Field.eq_divide_eq_1",
   131    "Ring_and_Field.eq_divide_eq_1", (*duplicate by symmetry*)
   132    "Ring_and_Field.field_mult_cancel_left",
   133    "Ring_and_Field.field_mult_cancel_right",
   134    "Ring_and_Field.inverse_le_iff_le_neg",
   135    "Ring_and_Field.inverse_le_iff_le",
   136    "Ring_and_Field.inverse_less_iff_less_neg",
   137    "Ring_and_Field.inverse_less_iff_less",
   138    "Ring_and_Field.le_divide_eq_1_neg",
   139    "Ring_and_Field.le_divide_eq_1_neg", (*obscure and prolific*)
   140    "Ring_and_Field.le_divide_eq_1_pos",
   141    "Ring_and_Field.le_divide_eq_1_pos", (*obscure and prolific*)
   142    "Ring_and_Field.less_divide_eq_1_neg",
   143    "Ring_and_Field.less_divide_eq_1_neg", (*obscure and prolific*)
   144    "Ring_and_Field.less_divide_eq_1_pos",
   145    "Ring_and_Field.less_divide_eq_1_pos", (*obscure and prolific*)
   146    "Ring_and_Field.one_eq_divide_iff",  (*duplicate by symmetry*)
   147    "Set.Diff_eq_empty_iff", (*redundant with paramodulation*)
   148    "Set.Diff_insert0",
   149    "Set.disjoint_insert_1",
   150    "Set.disjoint_insert_2",
   151    "Set.empty_Union_conv", (*redundant with paramodulation*)
   152    "Set.insert_disjoint_1",
   153    "Set.insert_disjoint_2",
   154    "Set.Int_UNIV", (*redundant with paramodulation*)
   155    "Set.Inter_iff",              (*We already have InterI, InterE*)
   156    "Set.Inter_UNIV_conv_1",
   157    "Set.Inter_UNIV_conv_2",
   158    "Set.psubsetE",    (*too prolific and obscure*)
   159    "Set.psubsetI",
   160    "Set.singleton_insert_inj_eq'",
   161    "Set.singleton_insert_inj_eq",
   162    "Set.singletonD",  (*these two duplicate some "insert" lemmas*)
   163    "Set.singletonI",
   164    "Set.Un_empty", (*redundant with paramodulation*)
   165    "Set.Union_empty_conv", (*redundant with paramodulation*)
   166    "Set.Union_iff",              (*We already have UnionI, UnionE*)
   167    "SetInterval.atLeastAtMost_iff", (*obscure and prolific*)
   168    "SetInterval.atLeastLessThan_iff", (*obscure and prolific*)
   169    "SetInterval.greaterThanAtMost_iff", (*obscure and prolific*)
   170    "SetInterval.greaterThanLessThan_iff", (*obscure and prolific*)
   171    "SetInterval.ivl_subset", (*excessive case analysis*)
   172    "Sum_Type.InlI",
   173    "Sum_Type.InrI"];
   174    
   175 (*These might be prolific but are probably OK, and min and max are basic.
   176    "Orderings.max_less_iff_conj", 
   177    "Orderings.min_less_iff_conj",
   178    "Orderings.min_max.below_inf.below_inf_conv",
   179    "Orderings.min_max.below_sup.above_sup_conv",
   180 Very prolific and somewhat obscure:
   181    "Set.InterD",
   182    "Set.UnionI",
   183 *)
   184 
   185 val theory_blacklist = ref
   186   ["Datatype_Universe.",    (*unnecessary in virtually all proofs*)
   187    "Equiv_Relations."]  
   188 
   189 
   190 val relevant = ref 0;  (*Relevance filtering is off by default*)
   191 
   192 (*The "name" of a theorem is its statement, if nothing else is available.*)
   193 val plain_string_of_thm =
   194     setmp show_question_marks false 
   195       (setmp print_mode [] 
   196 	(Pretty.setmp_margin 999 string_of_thm));
   197 	
   198 (*Returns the first substring enclosed in quotation marks, typically omitting 
   199   the [.] of meta-level assumptions.*)
   200 val firstquoted = hd o (String.tokens (fn c => c = #"\""))
   201 	
   202 fun fake_thm_name th = 
   203     Context.theory_name (theory_of_thm th) ^ "." ^ firstquoted (plain_string_of_thm th);
   204 
   205 fun put_name_pair ("",th) = (fake_thm_name th, th)
   206   | put_name_pair (a,th)  = (a,th);
   207 
   208 (*Hashing to detect duplicate and variant clauses, e.g. from the [iff] attribute*)
   209 
   210 exception HASH_CLAUSE and HASH_STRING;
   211 
   212 (*Catches (for deletion) theorems automatically generated from other theorems*)
   213 fun insert_suffixed_names ht x = 
   214      (Polyhash.insert ht (x^"_iff1", ()); 
   215       Polyhash.insert ht (x^"_iff2", ()); 
   216       Polyhash.insert ht (x^"_dest", ())); 
   217 
   218 fun banned_theory s = exists (fn thy => String.isPrefix thy s) (!theory_blacklist);
   219 
   220 fun make_banned_test xs = 
   221   let val ht = Polyhash.mkTable (Polyhash.hash_string, op =)
   222                                 (6000, HASH_STRING)
   223       fun banned s = isSome (Polyhash.peek ht s) orelse banned_theory s
   224   in  app (fn x => Polyhash.insert ht (x,())) (!blacklist);
   225       app (insert_suffixed_names ht) (!blacklist @ xs); 
   226       banned
   227   end;
   228 
   229 (*Create a hash table for clauses, of the given size*)
   230 fun mk_clause_table n =
   231       Polyhash.mkTable (ResClause.hash_clause, ResClause.clause_eq)
   232                        (n, HASH_CLAUSE);
   233 
   234 (*Use a hash table to eliminate duplicates from xs*)
   235 fun make_unique ht xs = 
   236       (app (ignore o Polyhash.peekInsert ht) xs;  Polyhash.listItems ht);
   237 
   238 (*Write out the claset and simpset rules of the supplied theory.
   239   FIXME: argument "goal" is a hack to allow relevance filtering.
   240   To reduce the number of clauses produced, set ResClasimp.relevant:=1*)
   241 fun get_clasimp_lemmas ctxt goals = 
   242   let val claset_thms =
   243 	  map put_name_pair (ResAxioms.claset_rules_of_ctxt ctxt)
   244       val simpset_thms = 
   245 	    if !use_simpset then 
   246 		map put_name_pair (ResAxioms.simpset_rules_of_ctxt ctxt)
   247 	    else []
   248       val banned = make_banned_test (map #1 (claset_thms@simpset_thms))
   249       fun ok (a,_) = not (banned a)
   250       val claset_cls_thms = ResAxioms.clausify_rules_pairs (filter ok claset_thms)
   251       val simpset_cls_thms = ResAxioms.clausify_rules_pairs (filter ok simpset_thms)
   252  
   253       val cls_thms_list = make_unique (mk_clause_table 2200) 
   254                                       (List.concat (simpset_cls_thms@claset_cls_thms))
   255       val relevant_cls_thms_list = ReduceAxiomsN.relevance_filter (ProofContext.theory_of ctxt) cls_thms_list goals
   256   in  (* create array of put clausename, number pairs into it *)
   257       (Array.fromList relevant_cls_thms_list, map #1 (relevant_cls_thms_list))
   258   end;
   259 
   260 
   261 end;
   262 
   263 
   264