src/HOL/Tools/Sledgehammer/sledgehammer_fact.ML
author blanchet
Wed May 15 17:43:42 2013 +0200 (2013-05-15 ago)
changeset 51998 f732a674db1b
parent 51160 599ff65b85e2
child 52031 9a9238342963
permissions -rw-r--r--
renamed Sledgehammer functions with 'for' in their names to 'of'
     1 (*  Title:      HOL/Tools/Sledgehammer/sledgehammer_fact.ML
     2     Author:     Jia Meng, Cambridge University Computer Laboratory and NICTA
     3     Author:     Jasmin Blanchette, TU Muenchen
     4 
     5 Sledgehammer fact handling.
     6 *)
     7 
     8 signature SLEDGEHAMMER_FACT =
     9 sig
    10   type status = ATP_Problem_Generate.status
    11   type stature = ATP_Problem_Generate.stature
    12 
    13   type raw_fact = ((unit -> string) * stature) * thm
    14   type fact = (string * stature) * thm
    15 
    16   type fact_override =
    17     {add : (Facts.ref * Attrib.src list) list,
    18      del : (Facts.ref * Attrib.src list) list,
    19      only : bool}
    20 
    21   val ignore_no_atp : bool Config.T
    22   val instantiate_inducts : bool Config.T
    23   val no_fact_override : fact_override
    24   val fact_from_ref :
    25     Proof.context -> unit Symtab.table -> thm list -> status Termtab.table
    26     -> Facts.ref * Attrib.src list -> ((string * stature) * thm) list
    27   val backquote_thm : Proof.context -> thm -> string
    28   val is_blacklisted_or_something : Proof.context -> bool -> string -> bool
    29   val clasimpset_rule_table_of : Proof.context -> status Termtab.table
    30   val build_name_tables :
    31     (thm -> string) -> ('a * thm) list
    32     -> string Symtab.table * string Symtab.table
    33   val maybe_instantiate_inducts :
    34     Proof.context -> term list -> term -> (((unit -> string) * 'a) * thm) list
    35     -> (((unit -> string) * 'a) * thm) list
    36   val maybe_filter_no_atps : Proof.context -> ('a * thm) list -> ('a * thm) list
    37   val fact_of_raw_fact : raw_fact -> fact
    38   val all_facts :
    39     Proof.context -> bool -> bool -> unit Symtab.table -> thm list -> thm list
    40     -> status Termtab.table -> raw_fact list
    41   val nearly_all_facts :
    42     Proof.context -> bool -> fact_override -> unit Symtab.table
    43     -> status Termtab.table -> thm list -> term list -> term -> raw_fact list
    44 end;
    45 
    46 structure Sledgehammer_Fact : SLEDGEHAMMER_FACT =
    47 struct
    48 
    49 open ATP_Util
    50 open ATP_Problem_Generate
    51 open Metis_Tactic
    52 open Sledgehammer_Util
    53 
    54 type raw_fact = ((unit -> string) * stature) * thm
    55 type fact = (string * stature) * thm
    56 
    57 type fact_override =
    58   {add : (Facts.ref * Attrib.src list) list,
    59    del : (Facts.ref * Attrib.src list) list,
    60    only : bool}
    61 
    62 (* experimental features *)
    63 val ignore_no_atp =
    64   Attrib.setup_config_bool @{binding sledgehammer_ignore_no_atp} (K false)
    65 val instantiate_inducts =
    66   Attrib.setup_config_bool @{binding sledgehammer_instantiate_inducts} (K false)
    67 
    68 val no_fact_override = {add = [], del = [], only = false}
    69 
    70 fun needs_quoting reserved s =
    71   Symtab.defined reserved s orelse
    72   exists (not o Symbol_Pos.is_identifier) (Long_Name.explode s)
    73 
    74 fun make_name reserved multi j name =
    75   (name |> needs_quoting reserved name ? quote) ^
    76   (if multi then "(" ^ string_of_int j ^ ")" else "")
    77 
    78 fun explode_interval _ (Facts.FromTo (i, j)) = i upto j
    79   | explode_interval max (Facts.From i) = i upto i + max - 1
    80   | explode_interval _ (Facts.Single i) = [i]
    81 
    82 val backquote =
    83   raw_explode #> map (fn "`" => "\\`" | s => s) #> implode #> enclose "`" "`"
    84 
    85 (* unfolding these can yield really huge terms *)
    86 val risky_defs = @{thms Bit0_def Bit1_def}
    87 
    88 fun is_rec_eq lhs = Term.exists_subterm (curry (op =) (head_of lhs))
    89 fun is_rec_def (@{const Trueprop} $ t) = is_rec_def t
    90   | is_rec_def (@{const ==>} $ _ $ t2) = is_rec_def t2
    91   | is_rec_def (Const (@{const_name "=="}, _) $ t1 $ t2) = is_rec_eq t1 t2
    92   | is_rec_def (Const (@{const_name HOL.eq}, _) $ t1 $ t2) = is_rec_eq t1 t2
    93   | is_rec_def _ = false
    94 
    95 fun is_assum assms th = exists (fn ct => prop_of th aconv term_of ct) assms
    96 fun is_chained chained = member Thm.eq_thm_prop chained
    97 
    98 fun scope_of_thm global assms chained th =
    99   if is_chained chained th then Chained
   100   else if global then Global
   101   else if is_assum assms th then Assum
   102   else Local
   103 
   104 val may_be_induction =
   105   exists_subterm (fn Var (_, Type (@{type_name fun}, [_, T])) =>
   106                      body_type T = @{typ bool}
   107                    | _ => false)
   108 
   109 fun status_of_thm css name th =
   110   (* FIXME: use structured name *)
   111   if (String.isSubstring ".induct" name orelse
   112       String.isSubstring ".inducts" name) andalso
   113      may_be_induction (prop_of th) then
   114     Induction
   115   else case Termtab.lookup css (prop_of th) of
   116     SOME status => status
   117   | NONE => General
   118 
   119 fun stature_of_thm global assms chained css name th =
   120   (scope_of_thm global assms chained th, status_of_thm css name th)
   121 
   122 fun fact_from_ref ctxt reserved chained css (xthm as (xref, args)) =
   123   let
   124     val ths = Attrib.eval_thms ctxt [xthm]
   125     val bracket =
   126       map (enclose "[" "]" o Pretty.str_of o Args.pretty_src ctxt) args
   127       |> implode
   128     fun nth_name j =
   129       case xref of
   130         Facts.Fact s => backquote s ^ bracket
   131       | Facts.Named (("", _), _) => "[" ^ bracket ^ "]"
   132       | Facts.Named ((name, _), NONE) =>
   133         make_name reserved (length ths > 1) (j + 1) name ^ bracket
   134       | Facts.Named ((name, _), SOME intervals) =>
   135         make_name reserved true
   136                  (nth (maps (explode_interval (length ths)) intervals) j) name ^
   137         bracket
   138     fun add_nth th (j, rest) =
   139       let val name = nth_name j in
   140         (j + 1, ((name, stature_of_thm false [] chained css name th), th)
   141                 :: rest)
   142       end
   143   in (0, []) |> fold add_nth ths |> snd end
   144 
   145 (* Reject theorems with names like "List.filter.filter_list_def" or
   146   "Accessible_Part.acc.defs", as these are definitions arising from packages. *)
   147 fun is_package_def s =
   148   let val ss = Long_Name.explode s in
   149     length ss > 2 andalso not (hd ss = "local") andalso
   150     exists (fn suf => String.isSuffix suf s)
   151            ["_case_def", "_rec_def", "_size_def", "_size_overloaded_def"]
   152   end
   153 
   154 (* FIXME: put other record thms here, or declare as "no_atp" *)
   155 fun multi_base_blacklist ctxt ho_atp =
   156   ["defs", "select_defs", "update_defs", "split", "splits", "split_asm",
   157    "ext_cases", "eq.simps", "eq.refl", "nchotomy", "case_cong",
   158    "weak_case_cong", "nat_of_char_simps", "nibble.simps",
   159    "nibble.distinct"]
   160   |> not (ho_atp orelse (Config.get ctxt instantiate_inducts)) ?
   161         append ["induct", "inducts"]
   162   |> map (prefix Long_Name.separator)
   163 
   164 val max_lambda_nesting = 5 (*only applies if not ho_atp*)
   165 
   166 fun term_has_too_many_lambdas max (t1 $ t2) =
   167     exists (term_has_too_many_lambdas max) [t1, t2]
   168   | term_has_too_many_lambdas max (Abs (_, _, t)) =
   169     max = 0 orelse term_has_too_many_lambdas (max - 1) t
   170   | term_has_too_many_lambdas _ _ = false
   171 
   172 (* Don't count nested lambdas at the level of formulas, since they are
   173    quantifiers. *)
   174 fun formula_has_too_many_lambdas Ts (Abs (_, T, t)) =
   175     formula_has_too_many_lambdas (T :: Ts) t
   176   | formula_has_too_many_lambdas Ts t =
   177     if member (op =) [HOLogic.boolT, propT] (fastype_of1 (Ts, t)) then
   178       exists (formula_has_too_many_lambdas Ts) (#2 (strip_comb t))
   179     else
   180       term_has_too_many_lambdas max_lambda_nesting t
   181 
   182 (* The maximum apply depth of any "metis" call in "Metis_Examples" (on
   183    2007-10-31) was 11. *)
   184 val max_apply_depth = 18
   185 
   186 fun apply_depth (f $ t) = Int.max (apply_depth f, apply_depth t + 1)
   187   | apply_depth (Abs (_, _, t)) = apply_depth t
   188   | apply_depth _ = 0
   189 
   190 fun is_too_complex ho_atp t =
   191   apply_depth t > max_apply_depth orelse
   192   (not ho_atp andalso formula_has_too_many_lambdas [] t)
   193 
   194 (* FIXME: Ad hoc list *)
   195 val technical_prefixes =
   196   ["ATP", "Code_Evaluation", "Datatype", "Enum", "Lazy_Sequence",
   197    "Limited_Sequence", "Meson", "Metis", "Nitpick",
   198    "Quickcheck_Random", "Quickcheck_Exhaustive", "Quickcheck_Narrowing",
   199    "Random_Sequence", "Sledgehammer", "SMT"]
   200   |> map (suffix Long_Name.separator)
   201 
   202 fun has_technical_prefix s =
   203   exists (fn pref => String.isPrefix pref s) technical_prefixes
   204 val exists_technical_const = exists_Const (has_technical_prefix o fst)
   205 
   206 (* FIXME: make more reliable *)
   207 val exists_low_level_class_const =
   208   exists_Const (fn (s, _) =>
   209      s = @{const_name equal_class.equal} orelse
   210      String.isSubstring (Long_Name.separator ^ "class" ^ Long_Name.separator) s)
   211 
   212 fun is_that_fact th =
   213   String.isSuffix (Long_Name.separator ^ Obtain.thatN) (Thm.get_name_hint th)
   214   andalso exists_subterm (fn Free (s, _) => s = Name.skolem Auto_Bind.thesisN
   215                            | _ => false) (prop_of th)
   216 
   217 fun is_likely_tautology_too_meta_or_too_technical th =
   218   let
   219     fun is_interesting_subterm (Const (s, _)) =
   220         not (member (op =) atp_widely_irrelevant_consts s)
   221       | is_interesting_subterm (Free _) = true
   222       | is_interesting_subterm _ = false
   223     fun is_boring_bool t =
   224       not (exists_subterm is_interesting_subterm t) orelse
   225       exists_type (exists_subtype (curry (op =) @{typ prop})) t
   226     fun is_boring_prop _ (@{const Trueprop} $ t) = is_boring_bool t
   227       | is_boring_prop Ts (@{const "==>"} $ t $ u) =
   228         is_boring_prop Ts t andalso is_boring_prop Ts u
   229       | is_boring_prop Ts (Const (@{const_name all}, _) $ Abs (_, T, t)) =
   230         is_boring_prop (T :: Ts) t
   231       | is_boring_prop Ts ((t as Const (@{const_name all}, _)) $ u) =
   232         is_boring_prop Ts (t $ eta_expand Ts u 1)
   233       | is_boring_prop _ (Const (@{const_name "=="}, _) $ t $ u) =
   234         is_boring_bool t andalso is_boring_bool u
   235       | is_boring_prop _ _ = true
   236     val t = prop_of th
   237   in
   238     (is_boring_prop [] (prop_of th) andalso
   239      not (Thm.eq_thm_prop (@{thm ext}, th))) orelse
   240     exists_type type_has_top_sort t orelse exists_technical_const t orelse
   241     exists_low_level_class_const t orelse is_that_fact th
   242   end
   243 
   244 fun is_blacklisted_or_something ctxt ho_atp name =
   245   (not (Config.get ctxt ignore_no_atp) andalso is_package_def name) orelse
   246   exists (fn s => String.isSuffix s name) (multi_base_blacklist ctxt ho_atp)
   247 
   248 fun hackish_string_of_term ctxt =
   249   with_vanilla_print_mode (Syntax.string_of_term ctxt) #> simplify_spaces
   250 
   251 (* This is a terrible hack. Free variables are sometimes coded as "M__" when
   252    they are displayed as "M" and we want to avoid clashes with these. But
   253    sometimes it's even worse: "Ma__" encodes "M". So we simply reserve all
   254    prefixes of all free variables. In the worse case scenario, where the fact
   255    won't be resolved correctly, the user can fix it manually, e.g., by giving a
   256    name to the offending fact. *)
   257 fun all_prefixes_of s =
   258   map (fn i => String.extract (s, 0, SOME i)) (1 upto size s - 1)
   259 
   260 fun close_form t =
   261   (t, [] |> Term.add_free_names t |> maps all_prefixes_of)
   262   |> fold (fn ((s, i), T) => fn (t', taken) =>
   263               let val s' = singleton (Name.variant_list taken) s in
   264                 ((if fastype_of t' = HOLogic.boolT then HOLogic.all_const
   265                   else Logic.all_const) T
   266                  $ Abs (s', T, abstract_over (Var ((s, i), T), t')),
   267                  s' :: taken)
   268               end)
   269           (Term.add_vars t [] |> sort_wrt (fst o fst))
   270   |> fst
   271 
   272 fun backquote_term ctxt = close_form #> hackish_string_of_term ctxt #> backquote
   273 fun backquote_thm ctxt = backquote_term ctxt o prop_of
   274 
   275 fun clasimpset_rule_table_of ctxt =
   276   let
   277     val thy = Proof_Context.theory_of ctxt
   278     val atomize = HOLogic.mk_Trueprop o Object_Logic.atomize_term thy
   279     fun add stature normalizers get_th =
   280       fold (fn rule =>
   281                let
   282                  val th = rule |> get_th
   283                  val t =
   284                    th |> Thm.maxidx_of th > 0 ? zero_var_indexes |> prop_of
   285                in
   286                  fold (fn normalize => Termtab.update (normalize t, stature))
   287                       (I :: normalizers)
   288                end)
   289     val {safeIs, (* safeEs, *) hazIs, (* hazEs, *) ...} =
   290       ctxt |> claset_of |> Classical.rep_cs
   291     val intros = Item_Net.content safeIs @ Item_Net.content hazIs
   292 (* Add once it is used:
   293     val elims =
   294       Item_Net.content safeEs @ Item_Net.content hazEs
   295       |> map Classical.classical_rule
   296 *)
   297     val simps = ctxt |> simpset_of |> dest_ss |> #simps
   298     val specs = ctxt |> Spec_Rules.get
   299     val (rec_defs, nonrec_defs) =
   300       specs |> filter (curry (op =) Spec_Rules.Equational o fst)
   301             |> maps (snd o snd)
   302             |> filter_out (member Thm.eq_thm_prop risky_defs)
   303             |> List.partition (is_rec_def o prop_of)
   304     val spec_intros =
   305       specs |> filter (member (op =) [Spec_Rules.Inductive,
   306                                       Spec_Rules.Co_Inductive] o fst)
   307             |> maps (snd o snd)
   308   in
   309     Termtab.empty |> add Simp [atomize] snd simps
   310                   |> add Rec_Def [] I rec_defs
   311                   |> add Non_Rec_Def [] I nonrec_defs
   312 (* Add once it is used:
   313                   |> add Elim [] I elims
   314 *)
   315                   |> add Intro [] I intros
   316                   |> add Inductive [] I spec_intros
   317   end
   318 
   319 fun normalize_eq (t as @{const Trueprop}
   320         $ ((t0 as Const (@{const_name HOL.eq}, _)) $ t1 $ t2)) =
   321     if Term_Ord.fast_term_ord (t1, t2) <> GREATER then t
   322     else HOLogic.mk_Trueprop (t0 $ t2 $ t1)
   323   | normalize_eq (t as @{const Trueprop} $ (@{const Not}
   324         $ ((t0 as Const (@{const_name HOL.eq}, _)) $ t1 $ t2))) =
   325     if Term_Ord.fast_term_ord (t1, t2) <> GREATER then t
   326     else HOLogic.mk_Trueprop (HOLogic.mk_not (t0 $ t2 $ t1))
   327   | normalize_eq t = t
   328 
   329 val normalize_eq_etc = normalize_eq o Term_Subst.zero_var_indexes
   330 
   331 fun if_thm_before th th' =
   332   if Theory.subthy (pairself Thm.theory_of_thm (th, th')) then th else th'
   333 
   334 (* Hack: Conflate the facts about a class as seen from the outside with the
   335    corresponding low-level facts, so that MaSh can learn from the low-level
   336    proofs. *)
   337 fun un_class_ify s =
   338   case first_field "_class" s of
   339     SOME (pref, suf) => [s, pref ^ suf]
   340   | NONE => [s]
   341 
   342 fun build_name_tables name_of facts =
   343   let
   344     fun cons_thm (_, th) = Termtab.cons_list (normalize_eq_etc (prop_of th), th)
   345     fun add_plain canon alias =
   346       Symtab.update (Thm.get_name_hint alias,
   347                      name_of (if_thm_before canon alias))
   348     fun add_plains (_, aliases as canon :: _) = fold (add_plain canon) aliases
   349     fun add_inclass (name, target) =
   350       fold (fn s => Symtab.update (s, target)) (un_class_ify name)
   351     val prop_tab = fold cons_thm facts Termtab.empty
   352     val plain_name_tab = Termtab.fold add_plains prop_tab Symtab.empty
   353     val inclass_name_tab = Symtab.fold add_inclass plain_name_tab Symtab.empty
   354   in (plain_name_tab, inclass_name_tab) end
   355 
   356 fun uniquify facts =
   357   Termtab.fold (cons o snd)
   358       (fold (Termtab.default o `(normalize_eq_etc o prop_of o snd)) facts
   359             Termtab.empty) []
   360 
   361 fun struct_induct_rule_on th =
   362   case Logic.strip_horn (prop_of th) of
   363     (prems, @{const Trueprop}
   364             $ ((p as Var ((p_name, 0), _)) $ (a as Var (_, ind_T)))) =>
   365     if not (is_TVar ind_T) andalso length prems > 1 andalso
   366        exists (exists_subterm (curry (op aconv) p)) prems andalso
   367        not (exists (exists_subterm (curry (op aconv) a)) prems) then
   368       SOME (p_name, ind_T)
   369     else
   370       NONE
   371   | _ => NONE
   372 
   373 val instantiate_induct_timeout = seconds 0.01
   374 
   375 fun instantiate_induct_rule ctxt concl_prop p_name ((name, stature), th) ind_x =
   376   let
   377     fun varify_noninducts (t as Free (s, T)) =
   378         if (s, T) = ind_x orelse can dest_funT T then t else Var ((s, 0), T)
   379       | varify_noninducts t = t
   380     val p_inst =
   381       concl_prop |> map_aterms varify_noninducts |> close_form
   382                  |> lambda (Free ind_x)
   383                  |> hackish_string_of_term ctxt
   384   in
   385     ((fn () => name () ^ "[where " ^ p_name ^ " = " ^ quote p_inst ^ "]",
   386       stature), th |> read_instantiate ctxt [((p_name, 0), p_inst)])
   387   end
   388 
   389 fun type_match thy (T1, T2) =
   390   (Sign.typ_match thy (T2, T1) Vartab.empty; true)
   391   handle Type.TYPE_MATCH => false
   392 
   393 fun instantiate_if_induct_rule ctxt stmt stmt_xs (ax as (_, th)) =
   394   case struct_induct_rule_on th of
   395     SOME (p_name, ind_T) =>
   396     let val thy = Proof_Context.theory_of ctxt in
   397       stmt_xs |> filter (fn (_, T) => type_match thy (T, ind_T))
   398               |> map_filter (try (TimeLimit.timeLimit instantiate_induct_timeout
   399                      (instantiate_induct_rule ctxt stmt p_name ax)))
   400     end
   401   | NONE => [ax]
   402 
   403 fun external_frees t =
   404   [] |> Term.add_frees t |> filter_out (can Name.dest_internal o fst)
   405 
   406 fun maybe_instantiate_inducts ctxt hyp_ts concl_t =
   407   if Config.get ctxt instantiate_inducts then
   408     let
   409       val thy = Proof_Context.theory_of ctxt
   410       val ind_stmt =
   411         (hyp_ts |> filter_out (null o external_frees), concl_t)
   412         |> Logic.list_implies |> Object_Logic.atomize_term thy
   413       val ind_stmt_xs = external_frees ind_stmt
   414     in maps (instantiate_if_induct_rule ctxt ind_stmt ind_stmt_xs) end
   415   else
   416     I
   417 
   418 fun maybe_filter_no_atps ctxt =
   419   not (Config.get ctxt ignore_no_atp) ? filter_out (No_ATPs.member ctxt o snd)
   420 
   421 fun fact_of_raw_fact ((name, stature), th) = ((name (), stature), th)
   422 
   423 fun all_facts ctxt generous ho_atp reserved add_ths chained css =
   424   let
   425     val thy = Proof_Context.theory_of ctxt
   426     val global_facts = Global_Theory.facts_of thy
   427     val local_facts = Proof_Context.facts_of ctxt
   428     val named_locals = local_facts |> Facts.dest_static []
   429     val assms = Assumption.all_assms_of ctxt
   430     fun is_good_unnamed_local th =
   431       not (Thm.has_name_hint th) andalso
   432       forall (fn (_, ths) => not (member Thm.eq_thm_prop ths th)) named_locals
   433     val unnamed_locals =
   434       union Thm.eq_thm_prop (Facts.props local_facts) chained
   435       |> filter is_good_unnamed_local |> map (pair "" o single)
   436     val full_space =
   437       Name_Space.merge (Facts.space_of global_facts, Facts.space_of local_facts)
   438     fun add_facts global foldx facts =
   439       foldx (fn (name0, ths) =>
   440         if name0 <> "" andalso
   441            forall (not o member Thm.eq_thm_prop add_ths) ths andalso
   442            (Facts.is_concealed facts name0 orelse
   443             not (can (Proof_Context.get_thms ctxt) name0) orelse
   444             (not generous andalso
   445              is_blacklisted_or_something ctxt ho_atp name0)) then
   446           I
   447         else
   448           let
   449             val n = length ths
   450             val multi = n > 1
   451             fun check_thms a =
   452               case try (Proof_Context.get_thms ctxt) a of
   453                 NONE => false
   454               | SOME ths' => eq_list Thm.eq_thm_prop (ths, ths')
   455           in
   456             pair n
   457             #> fold_rev (fn th => fn (j, accum) =>
   458                    (j - 1,
   459                     if not (member Thm.eq_thm_prop add_ths th) andalso
   460                        (is_likely_tautology_too_meta_or_too_technical th orelse
   461                         (not generous andalso
   462                          is_too_complex ho_atp (prop_of th))) then
   463                       accum
   464                     else
   465                       let
   466                         val new =
   467                           (((fn () =>
   468                                 if name0 = "" then
   469                                   backquote_thm ctxt th
   470                                 else
   471                                   [Facts.extern ctxt facts name0,
   472                                    Name_Space.extern ctxt full_space name0]
   473                                   |> distinct (op =)
   474                                   |> find_first check_thms
   475                                   |> the_default name0
   476                                   |> make_name reserved multi j),
   477                              stature_of_thm global assms chained css name0 th),
   478                            th)
   479                       in
   480                         accum |> (if multi then apsnd else apfst) (cons new)
   481                       end)) ths
   482             #> snd
   483           end)
   484   in
   485     (* The single-theorem names go before the multiple-theorem ones (e.g.,
   486        "xxx" vs. "xxx(3)"), so that single names are preferred when both are
   487        available. *)
   488     `I [] |> add_facts false fold local_facts (unnamed_locals @ named_locals)
   489           |> add_facts true Facts.fold_static global_facts global_facts
   490           |> op @
   491   end
   492 
   493 fun nearly_all_facts ctxt ho_atp {add, del, only} reserved css chained hyp_ts
   494                      concl_t =
   495   if only andalso null add then
   496     []
   497   else
   498     let
   499       val chained =
   500         chained
   501         |> maps (fn th => insert Thm.eq_thm_prop (zero_var_indexes th) [th])
   502     in
   503       (if only then
   504          maps (map (fn ((name, stature), th) => ((K name, stature), th))
   505                o fact_from_ref ctxt reserved chained css) add
   506        else
   507          let val (add, del) = pairself (Attrib.eval_thms ctxt) (add, del) in
   508            all_facts ctxt false ho_atp reserved add chained css
   509            |> filter_out (member Thm.eq_thm_prop del o snd)
   510            |> maybe_filter_no_atps ctxt
   511            |> uniquify
   512          end)
   513       |> maybe_instantiate_inducts ctxt hyp_ts concl_t
   514     end
   515 
   516 end;