src/HOL/Tools/Sledgehammer/sledgehammer_fact.ML
changeset 48394 82fc8c956cdc
parent 48332 271a4a6af734
child 48396 dd82d190c2af
equal deleted inserted replaced
48393:db3db32c9195 48394:82fc8c956cdc
    21   val instantiate_inducts : bool Config.T
    21   val instantiate_inducts : bool Config.T
    22   val no_fact_override : fact_override
    22   val no_fact_override : fact_override
    23   val fact_from_ref :
    23   val fact_from_ref :
    24     Proof.context -> unit Symtab.table -> thm list -> status Termtab.table
    24     Proof.context -> unit Symtab.table -> thm list -> status Termtab.table
    25     -> Facts.ref * Attrib.src list -> ((string * stature) * thm) list
    25     -> Facts.ref * Attrib.src list -> ((string * stature) * thm) list
       
    26   val backquote_thm : thm -> string
    26   val clasimpset_rule_table_of : Proof.context -> status Termtab.table
    27   val clasimpset_rule_table_of : Proof.context -> status Termtab.table
    27   val maybe_instantiate_inducts :
    28   val maybe_instantiate_inducts :
    28     Proof.context -> term list -> term -> (((unit -> string) * 'a) * thm) list
    29     Proof.context -> term list -> term -> (((unit -> string) * 'a) * thm) list
    29     -> (((unit -> string) * 'a) * thm) list
    30     -> (((unit -> string) * 'a) * thm) list
    30   val maybe_filter_no_atps : Proof.context -> ('a * thm) list -> ('a * thm) list
    31   val maybe_filter_no_atps : Proof.context -> ('a * thm) list -> ('a * thm) list
    31   val all_facts_of : theory -> status Termtab.table -> fact list
    32   val all_facts_of : Proof.context -> status Termtab.table -> fact list
    32   val nearly_all_facts :
    33   val nearly_all_facts :
    33     Proof.context -> bool -> fact_override -> unit Symtab.table
    34     Proof.context -> bool -> fact_override -> unit Symtab.table
    34     -> status Termtab.table -> thm list -> term list -> term -> fact list
    35     -> status Termtab.table -> thm list -> term list -> term -> fact list
    35 end;
    36 end;
    36 
    37 
   210     is_formula_too_complex ho_atp t orelse exists_type type_has_top_sort t orelse
   211     is_formula_too_complex ho_atp t orelse exists_type type_has_top_sort t orelse
   211     exists_sledgehammer_const t orelse exists_low_level_class_const t orelse
   212     exists_sledgehammer_const t orelse exists_low_level_class_const t orelse
   212     is_that_fact thm
   213     is_that_fact thm
   213   end
   214   end
   214 
   215 
   215 fun hackish_string_for_term ctxt t =
   216 fun hackish_string_for_term thy t =
   216   Print_Mode.setmp (filter (curry (op =) Symbol.xsymbolsN)
   217   Print_Mode.setmp (filter (curry (op =) Symbol.xsymbolsN)
   217                    (print_mode_value ())) (Syntax.string_of_term ctxt) t
   218                    (print_mode_value ())) (Syntax.string_of_term_global thy) t
   218   |> String.translate (fn c => if Char.isPrint c then str c else "")
   219   |> String.translate (fn c => if Char.isPrint c then str c else "")
   219   |> simplify_spaces
   220   |> simplify_spaces
   220 
   221 
   221 (* This is a terrible hack. Free variables are sometimes coded as "M__" when
   222 (* This is a terrible hack. Free variables are sometimes coded as "M__" when
   222    they are displayed as "M" and we want to avoid clashes with these. But
   223    they are displayed as "M" and we want to avoid clashes with these. But
   237                  $ Abs (s', T, abstract_over (Var ((s, i), T), t')),
   238                  $ Abs (s', T, abstract_over (Var ((s, i), T), t')),
   238                  s' :: taken)
   239                  s' :: taken)
   239               end)
   240               end)
   240           (Term.add_vars t [] |> sort_wrt (fst o fst))
   241           (Term.add_vars t [] |> sort_wrt (fst o fst))
   241   |> fst
   242   |> fst
       
   243 
       
   244 fun backquote_thm th =
       
   245   th |> prop_of |> close_form
       
   246      |> hackish_string_for_term (theory_of_thm th)
       
   247      |> backquote
   242 
   248 
   243 fun clasimpset_rule_table_of ctxt =
   249 fun clasimpset_rule_table_of ctxt =
   244   let
   250   let
   245     val thy = Proof_Context.theory_of ctxt
   251     val thy = Proof_Context.theory_of ctxt
   246     val atomize = HOLogic.mk_Trueprop o Object_Logic.atomize_term thy
   252     val atomize = HOLogic.mk_Trueprop o Object_Logic.atomize_term thy
   300       NONE
   306       NONE
   301   | _ => NONE
   307   | _ => NONE
   302 
   308 
   303 fun instantiate_induct_rule ctxt concl_prop p_name ((name, stature), th) ind_x =
   309 fun instantiate_induct_rule ctxt concl_prop p_name ((name, stature), th) ind_x =
   304   let
   310   let
       
   311     val thy = Proof_Context.theory_of ctxt
   305     fun varify_noninducts (t as Free (s, T)) =
   312     fun varify_noninducts (t as Free (s, T)) =
   306         if (s, T) = ind_x orelse can dest_funT T then t else Var ((s, 0), T)
   313         if (s, T) = ind_x orelse can dest_funT T then t else Var ((s, 0), T)
   307       | varify_noninducts t = t
   314       | varify_noninducts t = t
   308     val p_inst =
   315     val p_inst =
   309       concl_prop |> map_aterms varify_noninducts |> close_form
   316       concl_prop |> map_aterms varify_noninducts |> close_form
   310                  |> lambda (Free ind_x)
   317                  |> lambda (Free ind_x)
   311                  |> hackish_string_for_term ctxt
   318                  |> hackish_string_for_term thy
   312   in
   319   in
   313     ((fn () => name () ^ "[where " ^ p_name ^ " = " ^ quote p_inst ^ "]",
   320     ((fn () => name () ^ "[where " ^ p_name ^ " = " ^ quote p_inst ^ "]",
   314       stature), th |> read_instantiate ctxt [((p_name, 0), p_inst)])
   321       stature), th |> read_instantiate ctxt [((p_name, 0), p_inst)])
   315   end
   322   end
   316 
   323 
   372                    (multi_base_blacklist ctxt ho_atp)) then
   379                    (multi_base_blacklist ctxt ho_atp)) then
   373           I
   380           I
   374         else
   381         else
   375           let
   382           let
   376             val multi = length ths > 1
   383             val multi = length ths > 1
   377             val backquote_thm =
       
   378               backquote o hackish_string_for_term ctxt o close_form o prop_of
       
   379             fun check_thms a =
   384             fun check_thms a =
   380               case try (Proof_Context.get_thms ctxt) a of
   385               case try (Proof_Context.get_thms ctxt) a of
   381                 NONE => false
   386                 NONE => false
   382               | SOME ths' => eq_list Thm.eq_thm_prop (ths, ths')
   387               | SOME ths' => eq_list Thm.eq_thm_prop (ths, ths')
   383           in
   388           in
   390                          else
   395                          else
   391                            let
   396                            let
   392                              val new =
   397                              val new =
   393                                (((fn () =>
   398                                (((fn () =>
   394                                      if name0 = "" then
   399                                      if name0 = "" then
   395                                        th |> backquote_thm
   400                                        backquote_thm th
   396                                      else
   401                                      else
   397                                        [Facts.extern ctxt facts name0,
   402                                        [Facts.extern ctxt facts name0,
   398                                         Name_Space.extern ctxt full_space name0]
   403                                         Name_Space.extern ctxt full_space name0]
   399                                        |> find_first check_thms
   404                                        |> find_first check_thms
   400                                        |> the_default name0
   405                                        |> the_default name0
   413     ([], []) |> add_facts false fold local_facts (unnamed_locals @ named_locals)
   418     ([], []) |> add_facts false fold local_facts (unnamed_locals @ named_locals)
   414              |> add_facts true Facts.fold_static global_facts global_facts
   419              |> add_facts true Facts.fold_static global_facts global_facts
   415              |> op @
   420              |> op @
   416   end
   421   end
   417 
   422 
   418 fun all_facts_of thy css_table =
   423 fun all_facts_of ctxt css_table =
   419   let val ctxt = Proof_Context.init_global thy in
   424   all_facts ctxt false Symtab.empty [] [] css_table
   420     all_facts ctxt false Symtab.empty [] [] css_table
   425   |> rev (* try to restore the original order of facts, for MaSh *)
   421     |> rev (* try to restore the original order of facts, for MaSh *)
       
   422   end
       
   423 
   426 
   424 fun nearly_all_facts ctxt ho_atp {add, del, only} reserved css_table chained_ths
   427 fun nearly_all_facts ctxt ho_atp {add, del, only} reserved css_table chained_ths
   425                      hyp_ts concl_t =
   428                      hyp_ts concl_t =
   426   if only andalso null add then
   429   if only andalso null add then
   427     []
   430     []