src/HOL/Tools/Sledgehammer/sledgehammer_filter_mash.ML
changeset 48312 b40722a81ac9
parent 48311 3c4e10606567
child 48313 0faafdffa662
equal deleted inserted replaced
48311:3c4e10606567 48312:b40722a81ac9
    18   val escape_meta : string -> string
    18   val escape_meta : string -> string
    19   val escape_metas : string list -> string
    19   val escape_metas : string list -> string
    20   val unescape_meta : string -> string
    20   val unescape_meta : string -> string
    21   val unescape_metas : string -> string list
    21   val unescape_metas : string -> string list
    22   val extract_query : string -> string * string list
    22   val extract_query : string -> string * string list
    23   val suggested_facts : string list -> ('a * thm) list -> ('a * thm) list
    23   val suggested_facts : string list -> fact list -> fact list
       
    24   val mesh_facts : int -> fact list -> fact list -> fact list -> fact list
    24   val all_non_tautological_facts_of :
    25   val all_non_tautological_facts_of :
    25     theory -> status Termtab.table -> fact list
    26     theory -> status Termtab.table -> fact list
    26   val theory_ord : theory * theory -> order
    27   val theory_ord : theory * theory -> order
    27   val thm_ord : thm * thm -> order
    28   val thm_ord : thm * thm -> order
    28   val thy_facts_from_thms : ('a * thm) list -> string list Symtab.table
    29   val thy_facts_from_thms : fact list -> string list Symtab.table
    29   val has_thy : theory -> thm -> bool
    30   val has_thy : theory -> thm -> bool
    30   val parent_facts : theory -> string list Symtab.table -> string list
    31   val parent_facts : theory -> string list Symtab.table -> string list
    31   val features_of : theory -> status -> term list -> string list
    32   val features_of : theory -> status -> term list -> string list
    32   val isabelle_dependencies_of : string list -> thm -> string list
    33   val isabelle_dependencies_of : string list -> thm -> string list
    33   val goal_of_thm : theory -> thm -> thm
    34   val goal_of_thm : theory -> thm -> thm
    97 val explode_suggs =
    98 val explode_suggs =
    98   space_explode " " #> filter_out (curry (op =) "") #> map unescape_meta
    99   space_explode " " #> filter_out (curry (op =) "") #> map unescape_meta
    99 fun extract_query line =
   100 fun extract_query line =
   100   case space_explode ":" line of
   101   case space_explode ":" line of
   101     [goal_name, suggs] => (unescape_meta goal_name, explode_suggs suggs)
   102     [goal_name, suggs] => (unescape_meta goal_name, explode_suggs suggs)
   102   | _ => ("", explode_suggs line)
   103   | _ => ("", [])
   103 
   104 
   104 fun find_suggested facts sugg =
   105 fun find_suggested facts sugg =
   105   find_first (fn (_, th) => Thm.get_name_hint th = sugg) facts
   106   find_first (fn (_, th) => Thm.get_name_hint th = sugg) facts
   106 fun suggested_facts suggs facts = map_filter (find_suggested facts) suggs
   107 fun suggested_facts suggs facts = map_filter (find_suggested facts) suggs
       
   108 
       
   109 fun mesh_facts max_facts iter_facts mash_facts mash_rejects =
       
   110   let
       
   111     val fact_eq = Thm.eq_thm o pairself snd
       
   112     val num_iter = length iter_facts
       
   113     val num_mash = length mash_facts
       
   114     fun score_in f fs n =
       
   115       case find_index (curry fact_eq f) fs of
       
   116         ~1 => length fs
       
   117       | j => j
       
   118     fun score_of fact =
       
   119       score_in fact iter_facts num_iter + score_in fact mash_facts num_mash
       
   120   in
       
   121     union fact_eq iter_facts mash_facts
       
   122     |> map (`score_of) |> sort (int_ord o pairself fst) |> map snd
       
   123     |> take max_facts
       
   124   end
   107 
   125 
   108 val thy_feature_prefix = "y_"
   126 val thy_feature_prefix = "y_"
   109 
   127 
   110 val thy_feature_name_of = prefix thy_feature_prefix
   128 val thy_feature_name_of = prefix thy_feature_prefix
   111 val const_name_of = prefix const_prefix
   129 val const_name_of = prefix const_prefix
   504          (accepts |> filter_out (member Thm.eq_thm_prop ths o snd)))
   522          (accepts |> filter_out (member Thm.eq_thm_prop ths o snd)))
   505         |> take max_facts
   523         |> take max_facts
   506       val iter_facts =
   524       val iter_facts =
   507         iterative_relevant_facts ctxt params prover max_facts NONE hyp_ts
   525         iterative_relevant_facts ctxt params prover max_facts NONE hyp_ts
   508                                  concl_t facts
   526                                  concl_t facts
   509       val (mash_facts, mash_antifacts) =
   527       val (mash_facts, mash_rejects) =
   510         facts |> mash_suggest_facts ctxt params prover hyp_ts concl_t
   528         facts |> mash_suggest_facts ctxt params prover hyp_ts concl_t
   511               |> chop max_facts
   529               |> chop max_facts
   512       val mesh_facts = iter_facts (* ### *)
       
   513     in
   530     in
   514       mesh_facts
   531       mesh_facts max_facts iter_facts mash_facts mash_rejects
   515       |> not (null add_ths) ? prepend_facts add_ths
   532       |> not (null add_ths) ? prepend_facts add_ths
   516     end
   533     end
   517 
   534 
   518 end;
   535 end;