src/HOL/Tools/Sledgehammer/sledgehammer_fact.ML
changeset 58919 82a71046dce8
parent 58226 04faf6dc262e
child 58928 23d0ffd48006
equal deleted inserted replaced
58918:8d36bc5eaed3 58919:82a71046dce8
    19      only : bool}
    19      only : bool}
    20 
    20 
    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 
    23 
    24   val fact_of_ref : Proof.context -> unit Symtab.table -> thm list -> status Termtab.table ->
    24   val fact_of_ref : Proof.context -> Keyword.keywords -> thm list -> status Termtab.table ->
    25     Facts.ref * Token.src list -> ((string * stature) * thm) list
    25     Facts.ref * Token.src list -> ((string * stature) * thm) list
    26   val backquote_thm : Proof.context -> thm -> string
    26   val backquote_thm : Proof.context -> thm -> string
    27   val is_blacklisted_or_something : Proof.context -> bool -> string -> bool
    27   val is_blacklisted_or_something : Proof.context -> bool -> string -> bool
    28   val clasimpset_rule_table_of : Proof.context -> status Termtab.table
    28   val clasimpset_rule_table_of : Proof.context -> status Termtab.table
    29   val build_name_tables : (thm -> string) -> ('a * thm) list ->
    29   val build_name_tables : (thm -> string) -> ('a * thm) list ->
    31   val maybe_instantiate_inducts : Proof.context -> term list -> term ->
    31   val maybe_instantiate_inducts : Proof.context -> term list -> term ->
    32     (((unit -> string) * 'a) * thm) list -> (((unit -> string) * 'a) * thm) list
    32     (((unit -> string) * 'a) * thm) list -> (((unit -> string) * 'a) * thm) list
    33   val fact_of_raw_fact : raw_fact -> fact
    33   val fact_of_raw_fact : raw_fact -> fact
    34   val is_useful_unnamed_local_fact : Proof.context -> thm -> bool
    34   val is_useful_unnamed_local_fact : Proof.context -> thm -> bool
    35 
    35 
    36   val all_facts : Proof.context -> bool -> bool -> unit Symtab.table -> thm list -> thm list ->
    36   val all_facts : Proof.context -> bool -> bool -> Keyword.keywords -> thm list -> thm list ->
    37     status Termtab.table -> raw_fact list
    37     status Termtab.table -> raw_fact list
    38   val nearly_all_facts : Proof.context -> bool -> fact_override -> unit Symtab.table ->
    38   val nearly_all_facts : Proof.context -> bool -> fact_override -> Keyword.keywords ->
    39     status Termtab.table -> thm list -> term list -> term -> raw_fact list
    39     status Termtab.table -> thm list -> term list -> term -> raw_fact list
    40   val drop_duplicate_facts : raw_fact list -> raw_fact list
    40   val drop_duplicate_facts : raw_fact list -> raw_fact list
    41 end;
    41 end;
    42 
    42 
    43 structure Sledgehammer_Fact : SLEDGEHAMMER_FACT =
    43 structure Sledgehammer_Fact : SLEDGEHAMMER_FACT =
    64 val instantiate_inducts =
    64 val instantiate_inducts =
    65   Attrib.setup_config_bool @{binding sledgehammer_instantiate_inducts} (K false)
    65   Attrib.setup_config_bool @{binding sledgehammer_instantiate_inducts} (K false)
    66 
    66 
    67 val no_fact_override = {add = [], del = [], only = false}
    67 val no_fact_override = {add = [], del = [], only = false}
    68 
    68 
    69 fun needs_quoting reserved s =
    69 fun needs_quoting keywords s =
    70   Symtab.defined reserved s orelse
    70   Keyword.is_keyword keywords s orelse
    71   exists (not o Symbol_Pos.is_identifier) (Long_Name.explode s)
    71   exists (not o Symbol_Pos.is_identifier) (Long_Name.explode s)
    72 
    72 
    73 fun make_name reserved multi j name =
    73 fun make_name keywords multi j name =
    74   (name |> needs_quoting reserved name ? quote) ^
    74   (name |> needs_quoting keywords name ? quote) ^
    75   (if multi then "(" ^ string_of_int j ^ ")" else "")
    75   (if multi then "(" ^ string_of_int j ^ ")" else "")
    76 
    76 
    77 fun explode_interval _ (Facts.FromTo (i, j)) = i upto j
    77 fun explode_interval _ (Facts.FromTo (i, j)) = i upto j
    78   | explode_interval max (Facts.From i) = i upto i + max - 1
    78   | explode_interval max (Facts.From i) = i upto i + max - 1
    79   | explode_interval _ (Facts.Single i) = [i]
    79   | explode_interval _ (Facts.Single i) = [i]
   155     end
   155     end
   156 
   156 
   157 fun stature_of_thm global assms chained css name th =
   157 fun stature_of_thm global assms chained css name th =
   158   (scope_of_thm global assms chained th, status_of_thm css name th)
   158   (scope_of_thm global assms chained th, status_of_thm css name th)
   159 
   159 
   160 fun fact_of_ref ctxt reserved chained css (xthm as (xref, args)) =
   160 fun fact_of_ref ctxt keywords chained css (xthm as (xref, args)) =
   161   let
   161   let
   162     val ths = Attrib.eval_thms ctxt [xthm]
   162     val ths = Attrib.eval_thms ctxt [xthm]
   163     val bracket = implode (map (enclose "[" "]" o Pretty.str_of o Token.pretty_src ctxt) args)
   163     val bracket = implode (map (enclose "[" "]" o Pretty.str_of o Token.pretty_src ctxt) args)
   164 
   164 
   165     fun nth_name j =
   165     fun nth_name j =
   166       (case xref of
   166       (case xref of
   167         Facts.Fact s => backquote (simplify_spaces (unyxml s)) ^ bracket
   167         Facts.Fact s => backquote (simplify_spaces (unyxml s)) ^ bracket
   168       | Facts.Named (("", _), _) => "[" ^ bracket ^ "]"
   168       | Facts.Named (("", _), _) => "[" ^ bracket ^ "]"
   169       | Facts.Named ((name, _), NONE) => make_name reserved (length ths > 1) (j + 1) name ^ bracket
   169       | Facts.Named ((name, _), NONE) => make_name keywords (length ths > 1) (j + 1) name ^ bracket
   170       | Facts.Named ((name, _), SOME intervals) =>
   170       | Facts.Named ((name, _), SOME intervals) =>
   171         make_name reserved true
   171         make_name keywords true
   172           (nth (maps (explode_interval (length ths)) intervals) j) name ^ bracket)
   172           (nth (maps (explode_interval (length ths)) intervals) j) name ^ bracket)
   173 
   173 
   174     fun add_nth th (j, rest) =
   174     fun add_nth th (j, rest) =
   175       let val name = nth_name j in
   175       let val name = nth_name j in
   176         (j + 1, ((name, stature_of_thm false [] chained css name th), th) :: rest)
   176         (j + 1, ((name, stature_of_thm false [] chained css name th), th) :: rest)
   453     fn th =>
   453     fn th =>
   454       not (Thm.has_name_hint th) andalso
   454       not (Thm.has_name_hint th) andalso
   455       forall (fn (_, ths) => not (member Thm.eq_thm_prop ths th)) named_locals
   455       forall (fn (_, ths) => not (member Thm.eq_thm_prop ths th)) named_locals
   456   end
   456   end
   457 
   457 
   458 fun all_facts ctxt generous ho_atp reserved add_ths chained css =
   458 fun all_facts ctxt generous ho_atp keywords add_ths chained css =
   459   let
   459   let
   460     val thy = Proof_Context.theory_of ctxt
   460     val thy = Proof_Context.theory_of ctxt
   461     val global_facts = Global_Theory.facts_of thy
   461     val global_facts = Global_Theory.facts_of thy
   462     val is_too_complex =
   462     val is_too_complex =
   463       if generous orelse fact_count global_facts >= max_facts_for_complex_check then K false
   463       if generous orelse fact_count global_facts >= max_facts_for_complex_check then K false
   512                                long_name
   512                                long_name
   513                              else
   513                              else
   514                                name0
   514                                name0
   515                            end
   515                            end
   516                        end
   516                        end
   517                        |> make_name reserved multi j
   517                        |> make_name keywords multi j
   518                    val stature = stature_of_thm global assms chained css name0 th
   518                    val stature = stature_of_thm global assms chained css name0 th
   519                    val new = ((get_name, stature), th)
   519                    val new = ((get_name, stature), th)
   520                  in
   520                  in
   521                    (if multi then apsnd else apfst) (cons new) accum
   521                    (if multi then apsnd else apfst) (cons new) accum
   522                  end)) ths (n, accum))
   522                  end)) ths (n, accum))
   528     |> add_facts false fold local_facts (unnamed_locals @ named_locals)
   528     |> add_facts false fold local_facts (unnamed_locals @ named_locals)
   529     |> add_facts true Facts.fold_static global_facts global_facts
   529     |> add_facts true Facts.fold_static global_facts global_facts
   530     |> op @
   530     |> op @
   531   end
   531   end
   532 
   532 
   533 fun nearly_all_facts ctxt ho_atp {add, del, only} reserved css chained hyp_ts concl_t =
   533 fun nearly_all_facts ctxt ho_atp {add, del, only} keywords css chained hyp_ts concl_t =
   534   if only andalso null add then
   534   if only andalso null add then
   535     []
   535     []
   536   else
   536   else
   537     let
   537     let
   538       val chained = chained |> maps (fn th => insert Thm.eq_thm_prop (zero_var_indexes th) [th])
   538       val chained = chained |> maps (fn th => insert Thm.eq_thm_prop (zero_var_indexes th) [th])
   539     in
   539     in
   540       (if only then
   540       (if only then
   541          maps (map (fn ((name, stature), th) => ((K name, stature), th))
   541          maps (map (fn ((name, stature), th) => ((K name, stature), th))
   542            o fact_of_ref ctxt reserved chained css) add
   542            o fact_of_ref ctxt keywords chained css) add
   543        else
   543        else
   544          let
   544          let
   545            val (add, del) = pairself (Attrib.eval_thms ctxt) (add, del)
   545            val (add, del) = pairself (Attrib.eval_thms ctxt) (add, del)
   546            val facts =
   546            val facts =
   547              all_facts ctxt false ho_atp reserved add chained css
   547              all_facts ctxt false ho_atp keywords add chained css
   548              |> filter_out ((member Thm.eq_thm_prop del orf
   548              |> filter_out ((member Thm.eq_thm_prop del orf
   549                (Named_Theorems.member ctxt @{named_theorems no_atp} andf
   549                (Named_Theorems.member ctxt @{named_theorems no_atp} andf
   550                  not o member Thm.eq_thm_prop add)) o snd)
   550                  not o member Thm.eq_thm_prop add)) o snd)
   551          in
   551          in
   552            facts
   552            facts