src/HOL/Tools/Sledgehammer/sledgehammer_fact.ML
changeset 73980 291f7b5fc7c9
parent 73979 e5322146e7e8
child 74379 9ea507f63bcb
equal deleted inserted replaced
73979:e5322146e7e8 73980:291f7b5fc7c9
   174   end
   174   end
   175 
   175 
   176 (* Reject theorems with names like "List.filter.filter_list_def" or "Accessible_Part.acc.defs", as
   176 (* Reject theorems with names like "List.filter.filter_list_def" or "Accessible_Part.acc.defs", as
   177    these are definitions arising from packages. *)
   177    these are definitions arising from packages. *)
   178 fun is_package_def s =
   178 fun is_package_def s =
       
   179   exists (fn suf => String.isSuffix suf s)
       
   180     ["_case_def", "_rec_def", "_size_def", "_size_overloaded_def"]
       
   181   andalso
   179   let val ss = Long_Name.explode s in
   182   let val ss = Long_Name.explode s in
   180     length ss > 2 andalso not (hd ss = "local") andalso
   183     length ss > 2 andalso not (hd ss = "local")
   181     exists (fn suf => String.isSuffix suf s)
       
   182       ["_case_def", "_rec_def", "_size_def", "_size_overloaded_def"]
       
   183   end
   184   end
   184 
   185 
   185 (* FIXME: put other record thms here, or declare as "no_atp" *)
   186 (* FIXME: put other record thms here, or declare as "no_atp" *)
   186 val multi_base_blacklist =
   187 val multi_base_blacklist =
   187   ["defs", "select_defs", "update_defs", "split", "splits", "split_asm", "ext_cases", "eq.simps",
   188   ["defs", "select_defs", "update_defs", "split", "splits", "split_asm", "ext_cases", "eq.simps",
   475              forall (not o member Thm.eq_thm_prop add_ths) ths)) then
   476              forall (not o member Thm.eq_thm_prop add_ths) ths)) then
   476           accum
   477           accum
   477         else
   478         else
   478           let
   479           let
   479             val n = length ths
   480             val n = length ths
   480             val multi = n > 1
   481             val collection = n > 1
       
   482             val dotted_name = length (Long_Name.explode name0) > 2 (* ignore theory name *)
   481 
   483 
   482             fun check_thms a =
   484             fun check_thms a =
   483               (case try (Proof_Context.get_thms ctxt) a of
   485               (case try (Proof_Context.get_thms ctxt) a of
   484                 NONE => false
   486                 NONE => false
   485               | SOME ths' => eq_list Thm.eq_thm_prop (ths, ths'))
   487               | SOME ths' => eq_list Thm.eq_thm_prop (ths, ths'))
   506                                  long_name
   508                                  long_name
   507                                else
   509                                else
   508                                  name0
   510                                  name0
   509                              end
   511                              end
   510                          end
   512                          end
   511                          |> make_name keywords multi j
   513                          |> make_name keywords collection j
   512                      val stature = stature_of_thm global assms chained css name0 th
   514                      val stature = stature_of_thm global assms chained css name0 th
   513                      val new = ((get_name, stature), th)
   515                      val new = ((get_name, stature), th)
   514                    in
   516                    in
   515                      (if multi then apsnd else apfst) (cons new) accum
   517                      (if collection then apsnd o apsnd
       
   518                       else if dotted_name then apsnd o apfst
       
   519                       else apfst) (cons new) accum
   516                    end)
   520                    end)
   517               end) ths (n, accum))
   521               end) ths (n, accum))
   518           end)
   522           end)
   519   in
   523   in
   520     (* The single-theorem names go before the multiple-theorem ones (e.g., "xxx" vs. "xxx(3)"), so
   524     (* Names like "xxx" are preferred to "xxx.yyy", which are preferred to "xxx(666)" and the like.
   521        that single names are preferred when both are available. *)
   525        "Preferred" means put to the front of  the list. *)
   522     ([], [])
   526     ([], ([], []))
   523     |> add_facts false fold local_facts (unnamed_locals @ named_locals)
   527     |> add_facts false fold local_facts (unnamed_locals @ named_locals)
   524     |> add_facts true Facts.fold_static global_facts global_facts
   528     |> add_facts true Facts.fold_static global_facts global_facts
   525     |> op @
   529     ||> op @ |> op @
   526   end
   530   end
   527 
   531 
   528 fun nearly_all_facts ctxt inst_inducts {add, del, only} keywords css chained hyp_ts
   532 fun nearly_all_facts ctxt inst_inducts {add, del, only} keywords css chained hyp_ts
   529     concl_t =
   533     concl_t =
   530   if only andalso null add then
   534   if only andalso null add then