src/HOL/Tools/Sledgehammer/sledgehammer_filter.ML
changeset 41158 8c9c31a757f5
parent 41140 9c68004b8c9d
child 41159 1e12d6495423
equal deleted inserted replaced
41157:7e90d259790b 41158:8c9c31a757f5
   430     pconsts_in_terms thy is_built_in_const false (SOME false)
   430     pconsts_in_terms thy is_built_in_const false (SOME false)
   431         (map_filter (fn ((_, loc'), th) =>
   431         (map_filter (fn ((_, loc'), th) =>
   432                         if loc' = loc then SOME (prop_of th) else NONE) facts)
   432                         if loc' = loc then SOME (prop_of th) else NONE) facts)
   433   else
   433   else
   434     tab
   434     tab
       
   435 
       
   436 fun add_arities is_built_in_const th =
       
   437   let
       
   438     fun aux _ _ NONE = NONE
       
   439       | aux t args (SOME tab) =
       
   440         case t of
       
   441           t1 $ t2 => SOME tab |> aux t1 (t2 :: args) |> aux t2 []
       
   442         | Const (x as (s, _)) =>
       
   443           (if is_built_in_const x args then
       
   444              SOME tab
       
   445            else case Symtab.lookup tab s of
       
   446              NONE => SOME (Symtab.update (s, length args) tab)
       
   447            | SOME n => if n = length args then SOME tab else NONE)
       
   448         | _ => SOME tab
       
   449   in aux (prop_of th) [] end
       
   450 
       
   451 fun needs_ext is_built_in_const facts =
       
   452   fold (add_arities is_built_in_const o snd) facts (SOME Symtab.empty)
       
   453   |> is_none
       
   454 
   435 
   455 
   436 fun relevance_filter ctxt threshold0 decay max_relevant is_built_in_const
   456 fun relevance_filter ctxt threshold0 decay max_relevant is_built_in_const
   437         (fudge as {threshold_divisor, ridiculous_threshold, ...})
   457         (fudge as {threshold_divisor, ridiculous_threshold, ...})
   438         ({add, del, ...} : relevance_override) facts goal_ts =
   458         ({add, del, ...} : relevance_override) facts goal_ts =
   439   let
   459   let
   514               commas (rel_const_tab |> Symtab.dest
   534               commas (rel_const_tab |> Symtab.dest
   515                       |> filter (curry (op <>) [] o snd)
   535                       |> filter (curry (op <>) [] o snd)
   516                       |> map string_for_hyper_pconst));
   536                       |> map string_for_hyper_pconst));
   517           relevant [] [] hopeful
   537           relevant [] [] hopeful
   518         end
   538         end
   519     fun add_add_ths accepts =
   539     fun add_facts ths accepts =
   520       (facts |> filter ((member Thm.eq_thm add_ths
   540       (facts |> filter ((member Thm.eq_thm ths
   521                          andf (not o member (Thm.eq_thm o apsnd snd) accepts))
   541                          andf (not o member (Thm.eq_thm o apsnd snd) accepts))
   522                         o snd))
   542                         o snd))
   523       @ accepts
   543       @ accepts
   524       |> take max_relevant
   544       |> take max_relevant
   525   in
   545   in
   526     facts |> map_filter (pair_consts_fact thy is_built_in_const fudge)
   546     facts |> map_filter (pair_consts_fact thy is_built_in_const fudge)
   527           |> iter 0 max_relevant threshold0 goal_const_tab []
   547           |> iter 0 max_relevant threshold0 goal_const_tab []
   528           |> not (null add_ths) ? add_add_ths
   548           |> not (null add_ths) ? add_facts add_ths
   529           |> tap (fn res => trace_msg (fn () =>
   549           |> (fn accepts =>
   530                                "Total relevant: " ^ Int.toString (length res)))
   550                  accepts |> needs_ext is_built_in_const accepts
       
   551                             ? add_facts @{thms ext})
       
   552           |> tap (fn accepts => trace_msg (fn () =>
       
   553                       "Total relevant: " ^ Int.toString (length accepts)))
   531   end
   554   end
   532 
   555 
   533 
   556 
   534 (***************************************************************)
   557 (***************************************************************)
   535 (* Retrieving and filtering lemmas                             *)
   558 (* Retrieving and filtering lemmas                             *)