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