blanchet@49265: (* Title: HOL/Tools/Sledgehammer/sledgehammer_fact.ML blanchet@49265: Author: Jia Meng, Cambridge University Computer Laboratory and NICTA blanchet@49265: Author: Jasmin Blanchette, TU Muenchen blanchet@49265: blanchet@49265: Sledgehammer fact handling. blanchet@49265: *) blanchet@49265: blanchet@49265: signature SLEDGEHAMMER_FACT = blanchet@49265: sig blanchet@49265: type status = ATP_Problem_Generate.status blanchet@49265: type stature = ATP_Problem_Generate.stature blanchet@49265: blanchet@49311: type fact = ((unit -> string) * stature) * thm blanchet@49311: blanchet@49307: type fact_override = blanchet@49265: {add : (Facts.ref * Attrib.src list) list, blanchet@49265: del : (Facts.ref * Attrib.src list) list, blanchet@49265: only : bool} blanchet@49265: blanchet@49265: val ignore_no_atp : bool Config.T blanchet@49265: val instantiate_inducts : bool Config.T blanchet@49307: val no_fact_override : fact_override blanchet@49265: val fact_from_ref : blanchet@49265: Proof.context -> unit Symtab.table -> thm list -> status Termtab.table blanchet@49265: -> Facts.ref * Attrib.src list -> ((string * stature) * thm) list blanchet@49421: val is_likely_tautology_or_too_meta : thm -> bool blanchet@49409: val backquote_thm : thm -> string blanchet@49265: val clasimpset_rule_table_of : Proof.context -> status Termtab.table blanchet@49265: val maybe_instantiate_inducts : blanchet@49265: Proof.context -> term list -> term -> (((unit -> string) * 'a) * thm) list blanchet@49265: -> (((unit -> string) * 'a) * thm) list blanchet@49265: val maybe_filter_no_atps : Proof.context -> ('a * thm) list -> ('a * thm) list blanchet@49409: val all_facts_of : Proof.context -> status Termtab.table -> fact list blanchet@49265: val nearly_all_facts : blanchet@49314: Proof.context -> bool -> fact_override -> unit Symtab.table blanchet@49314: -> status Termtab.table -> thm list -> term list -> term -> fact list blanchet@49265: end; blanchet@49265: blanchet@49265: structure Sledgehammer_Fact : SLEDGEHAMMER_FACT = blanchet@49265: struct blanchet@49265: blanchet@49265: open ATP_Problem_Generate blanchet@49265: open Metis_Tactic blanchet@49265: open Sledgehammer_Util blanchet@49265: blanchet@49311: type fact = ((unit -> string) * stature) * thm blanchet@49311: blanchet@49307: type fact_override = blanchet@49265: {add : (Facts.ref * Attrib.src list) list, blanchet@49265: del : (Facts.ref * Attrib.src list) list, blanchet@49265: only : bool} blanchet@49265: blanchet@49265: val sledgehammer_prefix = "Sledgehammer" ^ Long_Name.separator blanchet@49265: blanchet@49265: (* experimental features *) blanchet@49265: val ignore_no_atp = blanchet@49265: Attrib.setup_config_bool @{binding sledgehammer_ignore_no_atp} (K false) blanchet@49265: val instantiate_inducts = blanchet@49265: Attrib.setup_config_bool @{binding sledgehammer_instantiate_inducts} (K false) blanchet@49265: blanchet@49307: val no_fact_override = {add = [], del = [], only = false} blanchet@49265: blanchet@49265: fun needs_quoting reserved s = blanchet@49265: Symtab.defined reserved s orelse blanchet@49265: exists (not o Lexicon.is_identifier) (Long_Name.explode s) blanchet@49265: blanchet@49265: fun make_name reserved multi j name = blanchet@49265: (name |> needs_quoting reserved name ? quote) ^ blanchet@49265: (if multi then "(" ^ string_of_int j ^ ")" else "") blanchet@49265: blanchet@49265: fun explode_interval _ (Facts.FromTo (i, j)) = i upto j blanchet@49265: | explode_interval max (Facts.From i) = i upto i + max - 1 blanchet@49265: | explode_interval _ (Facts.Single i) = [i] blanchet@49265: blanchet@49265: val backquote = blanchet@49265: raw_explode #> map (fn "`" => "\\`" | s => s) #> implode #> enclose "`" "`" blanchet@49265: blanchet@49265: (* unfolding these can yield really huge terms *) blanchet@49265: val risky_defs = @{thms Bit0_def Bit1_def} blanchet@49265: blanchet@49265: fun is_rec_eq lhs = Term.exists_subterm (curry (op =) (head_of lhs)) blanchet@49265: fun is_rec_def (@{const Trueprop} $ t) = is_rec_def t blanchet@49265: | is_rec_def (@{const ==>} $ _ $ t2) = is_rec_def t2 blanchet@49265: | is_rec_def (Const (@{const_name "=="}, _) $ t1 $ t2) = is_rec_eq t1 t2 blanchet@49265: | is_rec_def (Const (@{const_name HOL.eq}, _) $ t1 $ t2) = is_rec_eq t1 t2 blanchet@49265: | is_rec_def _ = false blanchet@49265: blanchet@49265: fun is_assum assms th = exists (fn ct => prop_of th aconv term_of ct) assms blanchet@49411: fun is_chained chained = member Thm.eq_thm_prop chained blanchet@49265: blanchet@49411: fun scope_of_thm global assms chained th = blanchet@49411: if is_chained chained th then Chained blanchet@49265: else if global then Global blanchet@49265: else if is_assum assms th then Assum blanchet@49265: else Local blanchet@49265: blanchet@49265: val may_be_induction = blanchet@49265: exists_subterm (fn Var (_, Type (@{type_name fun}, [_, T])) => blanchet@49265: body_type T = @{typ bool} blanchet@49265: | _ => false) blanchet@49265: blanchet@49411: fun status_of_thm css name th = blanchet@49265: (* FIXME: use structured name *) blanchet@49265: if (String.isSubstring ".induct" name orelse blanchet@49265: String.isSubstring ".inducts" name) andalso blanchet@49265: may_be_induction (prop_of th) then blanchet@49265: Induction blanchet@49411: else case Termtab.lookup css (prop_of th) of blanchet@49265: SOME status => status blanchet@49265: | NONE => General blanchet@49265: blanchet@49411: fun stature_of_thm global assms chained css name th = blanchet@49411: (scope_of_thm global assms chained th, status_of_thm css name th) blanchet@49265: blanchet@49411: fun fact_from_ref ctxt reserved chained css (xthm as (xref, args)) = blanchet@49265: let blanchet@49265: val ths = Attrib.eval_thms ctxt [xthm] blanchet@49265: val bracket = blanchet@49265: map (enclose "[" "]" o Pretty.str_of o Args.pretty_src ctxt) args blanchet@49265: |> implode blanchet@49265: fun nth_name j = blanchet@49265: case xref of blanchet@49265: Facts.Fact s => backquote s ^ bracket blanchet@49265: | Facts.Named (("", _), _) => "[" ^ bracket ^ "]" blanchet@49265: | Facts.Named ((name, _), NONE) => blanchet@49265: make_name reserved (length ths > 1) (j + 1) name ^ bracket blanchet@49265: | Facts.Named ((name, _), SOME intervals) => blanchet@49265: make_name reserved true blanchet@49265: (nth (maps (explode_interval (length ths)) intervals) j) name ^ blanchet@49265: bracket blanchet@49411: fun add_nth th (j, rest) = blanchet@49411: let val name = nth_name j in blanchet@49411: (j + 1, ((name, stature_of_thm false [] chained css name th), th) blanchet@49411: :: rest) blanchet@49411: end blanchet@49411: in (0, []) |> fold add_nth ths |> snd end blanchet@49265: blanchet@49265: (* Reject theorems with names like "List.filter.filter_list_def" or blanchet@49265: "Accessible_Part.acc.defs", as these are definitions arising from packages. *) blanchet@49265: fun is_package_def a = blanchet@49265: let val names = Long_Name.explode a in blanchet@49265: (length names > 2 andalso not (hd names = "local") andalso blanchet@49265: String.isSuffix "_def" a) orelse String.isSuffix "_defs" a blanchet@49265: end blanchet@49265: blanchet@49265: (* FIXME: put other record thms here, or declare as "no_atp" *) blanchet@49265: fun multi_base_blacklist ctxt ho_atp = blanchet@49265: ["defs", "select_defs", "update_defs", "split", "splits", "split_asm", blanchet@49265: "cases", "ext_cases", "eq.simps", "eq.refl", "nchotomy", "case_cong", blanchet@49265: "weak_case_cong"] blanchet@49265: |> not (ho_atp orelse (Config.get ctxt instantiate_inducts)) ? blanchet@49265: append ["induct", "inducts"] blanchet@49265: |> map (prefix ".") blanchet@49265: blanchet@49265: val max_lambda_nesting = 3 (*only applies if not ho_atp*) blanchet@49265: blanchet@49265: fun term_has_too_many_lambdas max (t1 $ t2) = blanchet@49265: exists (term_has_too_many_lambdas max) [t1, t2] blanchet@49265: | term_has_too_many_lambdas max (Abs (_, _, t)) = blanchet@49265: max = 0 orelse term_has_too_many_lambdas (max - 1) t blanchet@49265: | term_has_too_many_lambdas _ _ = false blanchet@49265: blanchet@49265: (* Don't count nested lambdas at the level of formulas, since they are blanchet@49265: quantifiers. *) blanchet@49452: fun formula_has_too_many_lambdas Ts (Abs (_, T, t)) = blanchet@49452: formula_has_too_many_lambdas (T :: Ts) t blanchet@49452: | formula_has_too_many_lambdas Ts t = blanchet@49265: if member (op =) [HOLogic.boolT, propT] (fastype_of1 (Ts, t)) then blanchet@49452: exists (formula_has_too_many_lambdas Ts) (#2 (strip_comb t)) blanchet@49265: else blanchet@49265: term_has_too_many_lambdas max_lambda_nesting t blanchet@49265: blanchet@49265: (* The max apply depth of any "metis" call in "Metis_Examples" (on 2007-10-31) blanchet@49265: was 11. *) blanchet@49265: val max_apply_depth = 15 blanchet@49265: blanchet@49265: fun apply_depth (f $ t) = Int.max (apply_depth f, apply_depth t + 1) blanchet@49265: | apply_depth (Abs (_, _, t)) = apply_depth t blanchet@49265: | apply_depth _ = 0 blanchet@49265: blanchet@49265: fun is_formula_too_complex ho_atp t = blanchet@49452: apply_depth t > max_apply_depth orelse blanchet@49452: (not ho_atp andalso formula_has_too_many_lambdas [] t) blanchet@49265: blanchet@49265: (* FIXME: Extend to "Meson" and "Metis" *) blanchet@49265: val exists_sledgehammer_const = blanchet@49265: exists_Const (fn (s, _) => String.isPrefix sledgehammer_prefix s) blanchet@49265: blanchet@49265: (* FIXME: make more reliable *) blanchet@49265: val exists_low_level_class_const = blanchet@49265: exists_Const (fn (s, _) => blanchet@49265: s = @{const_name equal_class.equal} orelse blanchet@49265: String.isSubstring (Long_Name.separator ^ "class" ^ Long_Name.separator) s) blanchet@49265: blanchet@49265: fun is_metastrange_theorem th = blanchet@49265: case head_of (concl_of th) of blanchet@49265: Const (s, _) => (s <> @{const_name Trueprop} andalso blanchet@49265: s <> @{const_name "=="}) blanchet@49265: | _ => false blanchet@49265: blanchet@49265: fun is_that_fact th = blanchet@49265: String.isSuffix (Long_Name.separator ^ Obtain.thatN) (Thm.get_name_hint th) blanchet@49265: andalso exists_subterm (fn Free (s, _) => s = Name.skolem Auto_Bind.thesisN blanchet@49265: | _ => false) (prop_of th) blanchet@49265: blanchet@49342: fun is_theorem_bad_for_atps ho_atp thm = blanchet@49265: is_metastrange_theorem thm orelse blanchet@49342: let val t = prop_of thm in blanchet@49342: is_formula_too_complex ho_atp t orelse exists_type type_has_top_sort t orelse blanchet@49342: exists_sledgehammer_const t orelse exists_low_level_class_const t orelse blanchet@49342: is_that_fact thm blanchet@49342: end blanchet@49265: blanchet@49421: fun is_likely_tautology_or_too_meta th = blanchet@49421: let blanchet@49421: val is_boring_const = member (op =) atp_widely_irrelevant_consts blanchet@49421: fun is_boring_bool t = blanchet@49421: not (exists_Const (not o is_boring_const o fst) t) orelse blanchet@49421: exists_type (exists_subtype (curry (op =) @{typ prop})) t blanchet@49421: fun is_boring_prop (@{const Trueprop} $ t) = is_boring_bool t blanchet@49421: | is_boring_prop (@{const "==>"} $ t $ u) = blanchet@49421: is_boring_prop t andalso is_boring_prop u blanchet@49421: | is_boring_prop (Const (@{const_name all}, _) $ (Abs (_, _, t)) $ u) = blanchet@49421: is_boring_prop t andalso is_boring_prop u blanchet@49421: | is_boring_prop (Const (@{const_name "=="}, _) $ t $ u) = blanchet@49421: is_boring_bool t andalso is_boring_bool u blanchet@49421: | is_boring_prop _ = true blanchet@49421: in blanchet@49421: is_boring_prop (prop_of th) andalso not (Thm.eq_thm_prop (@{thm ext}, th)) blanchet@49421: end blanchet@49421: blanchet@49409: fun hackish_string_for_term thy t = blanchet@49265: Print_Mode.setmp (filter (curry (op =) Symbol.xsymbolsN) blanchet@49409: (print_mode_value ())) (Syntax.string_of_term_global thy) t blanchet@49265: |> String.translate (fn c => if Char.isPrint c then str c else "") blanchet@49265: |> simplify_spaces blanchet@49265: blanchet@49265: (* This is a terrible hack. Free variables are sometimes coded as "M__" when blanchet@49265: they are displayed as "M" and we want to avoid clashes with these. But blanchet@49265: sometimes it's even worse: "Ma__" encodes "M". So we simply reserve all blanchet@49265: prefixes of all free variables. In the worse case scenario, where the fact blanchet@49265: won't be resolved correctly, the user can fix it manually, e.g., by naming blanchet@49265: the fact in question. Ideally we would need nothing of it, but backticks blanchet@49265: simply don't work with schematic variables. *) blanchet@49265: fun all_prefixes_of s = blanchet@49265: map (fn i => String.extract (s, 0, SOME i)) (1 upto size s - 1) blanchet@49265: blanchet@49265: fun close_form t = blanchet@49265: (t, [] |> Term.add_free_names t |> maps all_prefixes_of) blanchet@49265: |> fold (fn ((s, i), T) => fn (t', taken) => blanchet@49265: let val s' = singleton (Name.variant_list taken) s in blanchet@49265: ((if fastype_of t' = HOLogic.boolT then HOLogic.all_const blanchet@49265: else Logic.all_const) T blanchet@49265: $ Abs (s', T, abstract_over (Var ((s, i), T), t')), blanchet@49265: s' :: taken) blanchet@49265: end) blanchet@49265: (Term.add_vars t [] |> sort_wrt (fst o fst)) blanchet@49265: |> fst blanchet@49265: blanchet@49415: fun backquote_term thy t = blanchet@49415: t |> close_form blanchet@49415: |> hackish_string_for_term thy blanchet@49415: |> backquote blanchet@49415: blanchet@49415: fun backquote_thm th = backquote_term (theory_of_thm th) (prop_of th) blanchet@49409: blanchet@49265: fun clasimpset_rule_table_of ctxt = blanchet@49265: let blanchet@49265: val thy = Proof_Context.theory_of ctxt blanchet@49265: val atomize = HOLogic.mk_Trueprop o Object_Logic.atomize_term thy blanchet@49265: fun add stature normalizers get_th = blanchet@49265: fold (fn rule => blanchet@49265: let blanchet@49265: val th = rule |> get_th blanchet@49265: val t = blanchet@49265: th |> Thm.maxidx_of th > 0 ? zero_var_indexes |> prop_of blanchet@49265: in blanchet@49265: fold (fn normalize => Termtab.update (normalize t, stature)) blanchet@49265: (I :: normalizers) blanchet@49265: end) blanchet@49265: val {safeIs, (* safeEs, *) hazIs, (* hazEs, *) ...} = blanchet@49265: ctxt |> claset_of |> Classical.rep_cs blanchet@49265: val intros = Item_Net.content safeIs @ Item_Net.content hazIs blanchet@49265: (* Add once it is used: blanchet@49265: val elims = blanchet@49265: Item_Net.content safeEs @ Item_Net.content hazEs blanchet@49265: |> map Classical.classical_rule blanchet@49265: *) blanchet@49265: val simps = ctxt |> simpset_of |> dest_ss |> #simps blanchet@49265: val specs = ctxt |> Spec_Rules.get blanchet@49265: val (rec_defs, nonrec_defs) = blanchet@49265: specs |> filter (curry (op =) Spec_Rules.Equational o fst) blanchet@49265: |> maps (snd o snd) blanchet@49265: |> filter_out (member Thm.eq_thm_prop risky_defs) blanchet@49265: |> List.partition (is_rec_def o prop_of) blanchet@49265: val spec_intros = blanchet@49265: specs |> filter (member (op =) [Spec_Rules.Inductive, blanchet@49265: Spec_Rules.Co_Inductive] o fst) blanchet@49265: |> maps (snd o snd) blanchet@49265: in blanchet@49265: Termtab.empty |> add Simp [atomize] snd simps blanchet@49265: |> add Simp [] I rec_defs blanchet@49265: |> add Def [] I nonrec_defs blanchet@49265: (* Add once it is used: blanchet@49265: |> add Elim [] I elims blanchet@49265: *) blanchet@49265: |> add Intro [] I intros blanchet@49265: |> add Inductive [] I spec_intros blanchet@49265: end blanchet@49265: blanchet@49265: fun uniquify xs = blanchet@49265: Termtab.fold (cons o snd) blanchet@49265: (fold (Termtab.update o `(prop_of o snd)) xs Termtab.empty) [] blanchet@49265: blanchet@49265: fun struct_induct_rule_on th = blanchet@49265: case Logic.strip_horn (prop_of th) of blanchet@49265: (prems, @{const Trueprop} blanchet@49265: $ ((p as Var ((p_name, 0), _)) $ (a as Var (_, ind_T)))) => blanchet@49265: if not (is_TVar ind_T) andalso length prems > 1 andalso blanchet@49265: exists (exists_subterm (curry (op aconv) p)) prems andalso blanchet@49265: not (exists (exists_subterm (curry (op aconv) a)) prems) then blanchet@49265: SOME (p_name, ind_T) blanchet@49265: else blanchet@49265: NONE blanchet@49265: | _ => NONE blanchet@49265: blanchet@49265: fun instantiate_induct_rule ctxt concl_prop p_name ((name, stature), th) ind_x = blanchet@49265: let blanchet@49409: val thy = Proof_Context.theory_of ctxt blanchet@49265: fun varify_noninducts (t as Free (s, T)) = blanchet@49265: if (s, T) = ind_x orelse can dest_funT T then t else Var ((s, 0), T) blanchet@49265: | varify_noninducts t = t blanchet@49265: val p_inst = blanchet@49265: concl_prop |> map_aterms varify_noninducts |> close_form blanchet@49265: |> lambda (Free ind_x) blanchet@49409: |> hackish_string_for_term thy blanchet@49265: in blanchet@49265: ((fn () => name () ^ "[where " ^ p_name ^ " = " ^ quote p_inst ^ "]", blanchet@49265: stature), th |> read_instantiate ctxt [((p_name, 0), p_inst)]) blanchet@49265: end blanchet@49265: blanchet@49265: fun type_match thy (T1, T2) = blanchet@49265: (Sign.typ_match thy (T2, T1) Vartab.empty; true) blanchet@49265: handle Type.TYPE_MATCH => false blanchet@49265: blanchet@49265: fun instantiate_if_induct_rule ctxt stmt stmt_xs (ax as (_, th)) = blanchet@49265: case struct_induct_rule_on th of blanchet@49265: SOME (p_name, ind_T) => blanchet@49265: let val thy = Proof_Context.theory_of ctxt in blanchet@49265: stmt_xs |> filter (fn (_, T) => type_match thy (T, ind_T)) blanchet@49265: |> map_filter (try (instantiate_induct_rule ctxt stmt p_name ax)) blanchet@49265: end blanchet@49265: | NONE => [ax] blanchet@49265: blanchet@49265: fun external_frees t = blanchet@49265: [] |> Term.add_frees t |> filter_out (can Name.dest_internal o fst) blanchet@49265: blanchet@49265: fun maybe_instantiate_inducts ctxt hyp_ts concl_t = blanchet@49265: if Config.get ctxt instantiate_inducts then blanchet@49265: let blanchet@49265: val thy = Proof_Context.theory_of ctxt blanchet@49265: val ind_stmt = blanchet@49265: (hyp_ts |> filter_out (null o external_frees), concl_t) blanchet@49265: |> Logic.list_implies |> Object_Logic.atomize_term thy blanchet@49265: val ind_stmt_xs = external_frees ind_stmt blanchet@49265: in maps (instantiate_if_induct_rule ctxt ind_stmt ind_stmt_xs) end blanchet@49265: else blanchet@49265: I blanchet@49265: blanchet@49265: fun maybe_filter_no_atps ctxt = blanchet@49265: not (Config.get ctxt ignore_no_atp) ? filter_out (No_ATPs.member ctxt o snd) blanchet@49265: blanchet@49411: fun all_facts ctxt ho_atp reserved add_ths chained css = blanchet@49266: let blanchet@49266: val thy = Proof_Context.theory_of ctxt blanchet@49266: val global_facts = Global_Theory.facts_of thy blanchet@49266: val local_facts = Proof_Context.facts_of ctxt blanchet@49266: val named_locals = local_facts |> Facts.dest_static [] blanchet@49266: val assms = Assumption.all_assms_of ctxt blanchet@49266: fun is_good_unnamed_local th = blanchet@49266: not (Thm.has_name_hint th) andalso blanchet@49266: forall (fn (_, ths) => not (member Thm.eq_thm_prop ths th)) named_locals blanchet@49266: val unnamed_locals = blanchet@49411: union Thm.eq_thm_prop (Facts.props local_facts) chained blanchet@49266: |> filter is_good_unnamed_local |> map (pair "" o single) blanchet@49266: val full_space = blanchet@49266: Name_Space.merge (Facts.space_of global_facts, Facts.space_of local_facts) blanchet@49266: fun add_facts global foldx facts = blanchet@49266: foldx (fn (name0, ths) => blanchet@49342: if name0 <> "" andalso blanchet@49266: forall (not o member Thm.eq_thm_prop add_ths) ths andalso blanchet@49266: (Facts.is_concealed facts name0 orelse blanchet@49342: not (can (Proof_Context.get_thms ctxt) name0) orelse blanchet@49266: (not (Config.get ctxt ignore_no_atp) andalso blanchet@49266: is_package_def name0) orelse blanchet@49266: exists (fn s => String.isSuffix s name0) blanchet@49266: (multi_base_blacklist ctxt ho_atp)) then blanchet@49266: I blanchet@49266: else blanchet@49266: let blanchet@49266: val multi = length ths > 1 blanchet@49266: fun check_thms a = blanchet@49266: case try (Proof_Context.get_thms ctxt) a of blanchet@49266: NONE => false blanchet@49266: | SOME ths' => eq_list Thm.eq_thm_prop (ths, ths') blanchet@49266: in blanchet@49266: pair 1 blanchet@49266: #> fold (fn th => fn (j, (multis, unis)) => blanchet@49266: (j + 1, blanchet@49266: if not (member Thm.eq_thm_prop add_ths th) andalso blanchet@49342: is_theorem_bad_for_atps ho_atp th then blanchet@49266: (multis, unis) blanchet@49266: else blanchet@49266: let blanchet@49266: val new = blanchet@49266: (((fn () => blanchet@49342: if name0 = "" then blanchet@49409: backquote_thm th blanchet@49342: else blanchet@49342: [Facts.extern ctxt facts name0, blanchet@49342: Name_Space.extern ctxt full_space name0] blanchet@49342: |> find_first check_thms blanchet@49342: |> the_default name0 blanchet@49342: |> make_name reserved multi j), blanchet@49411: stature_of_thm global assms chained css name0 blanchet@49411: th), th) blanchet@49266: in blanchet@49266: if multi then (new :: multis, unis) blanchet@49266: else (multis, new :: unis) blanchet@49266: end)) ths blanchet@49266: #> snd blanchet@49266: end) blanchet@49266: in blanchet@49266: (* The single-name theorems go after the multiple-name ones, so that single blanchet@49266: names are preferred when both are available. *) blanchet@49266: ([], []) |> add_facts false fold local_facts (unnamed_locals @ named_locals) blanchet@49266: |> add_facts true Facts.fold_static global_facts global_facts blanchet@49266: |> op @ blanchet@49266: end blanchet@49266: blanchet@49411: fun all_facts_of ctxt css = blanchet@49411: all_facts ctxt false Symtab.empty [] [] css blanchet@49411: |> rev (* partly restore the original order of facts, for MaSh *) blanchet@49266: blanchet@49411: fun nearly_all_facts ctxt ho_atp {add, del, only} reserved css chained hyp_ts blanchet@49411: concl_t = blanchet@49265: if only andalso null add then blanchet@49265: [] blanchet@49265: else blanchet@49265: let blanchet@49411: val chained = blanchet@49411: chained blanchet@49307: |> maps (fn th => insert Thm.eq_thm_prop (zero_var_indexes th) [th]) blanchet@49265: in blanchet@49265: (if only then blanchet@49265: maps (map (fn ((name, stature), th) => ((K name, stature), th)) blanchet@49411: o fact_from_ref ctxt reserved chained css) add blanchet@49265: else blanchet@49307: let val (add, del) = pairself (Attrib.eval_thms ctxt) (add, del) in blanchet@49411: all_facts ctxt ho_atp reserved add chained css blanchet@49421: |> filter_out (is_likely_tautology_or_too_meta o snd) blanchet@49307: |> filter_out (member Thm.eq_thm_prop del o snd) blanchet@49307: |> maybe_filter_no_atps ctxt blanchet@49347: |> uniquify blanchet@49307: end) blanchet@49265: |> maybe_instantiate_inducts ctxt hyp_ts concl_t blanchet@49265: end blanchet@49265: blanchet@49265: end;