src/HOL/Tools/Sledgehammer/sledgehammer_fact_filter.ML
changeset 38652 e063be321438
parent 38644 25bbbaf7ce65
child 38679 2cfd0777580f
equal deleted inserted replaced
38651:8aadda8e1338 38652:e063be321438
    21 end;
    21 end;
    22 
    22 
    23 structure Sledgehammer_Fact_Filter : SLEDGEHAMMER_FACT_FILTER =
    23 structure Sledgehammer_Fact_Filter : SLEDGEHAMMER_FACT_FILTER =
    24 struct
    24 struct
    25 
    25 
       
    26 open Sledgehammer_Util
       
    27 
    26 val trace = Unsynchronized.ref false
    28 val trace = Unsynchronized.ref false
    27 fun trace_msg msg = if !trace then tracing (msg ()) else ()
    29 fun trace_msg msg = if !trace then tracing (msg ()) else ()
    28 
    30 
    29 val respect_no_atp = true
    31 val respect_no_atp = true
    30 
    32 
    41   let
    43   let
    42     val ths = ProofContext.get_fact ctxt xref
    44     val ths = ProofContext.get_fact ctxt xref
    43     val name = Facts.string_of_ref xref
    45     val name = Facts.string_of_ref xref
    44                |> forall (member Thm.eq_thm chained_ths) ths
    46                |> forall (member Thm.eq_thm chained_ths) ths
    45                   ? prefix chained_prefix
    47                   ? prefix chained_prefix
    46   in (name, ths |> map Clausifier.transform_elim_theorem) end
    48   in (name, ths) end
    47 
    49 
    48 
    50 
    49 (***************************************************************)
    51 (***************************************************************)
    50 (* Relevance Filtering                                         *)
    52 (* Relevance Filtering                                         *)
    51 (***************************************************************)
    53 (***************************************************************)
   418   apply_depth t > max_apply_depth orelse formula_has_too_many_lambdas [] t
   420   apply_depth t > max_apply_depth orelse formula_has_too_many_lambdas [] t
   419 
   421 
   420 val exists_sledgehammer_const =
   422 val exists_sledgehammer_const =
   421   exists_Const (fn (s, _) => String.isPrefix sledgehammer_prefix s)
   423   exists_Const (fn (s, _) => String.isPrefix sledgehammer_prefix s)
   422 
   424 
   423 fun is_strange_thm th =
   425 fun is_strange_theorem th =
   424   case head_of (concl_of th) of
   426   case head_of (concl_of th) of
   425       Const (a, _) => (a <> @{const_name Trueprop} andalso
   427       Const (a, _) => (a <> @{const_name Trueprop} andalso
   426                        a <> @{const_name "=="})
   428                        a <> @{const_name "=="})
   427     | _ => false
   429     | _ => false
   428 
   430 
   484 (* Facts containing variables of type "unit" or "bool" or of the form
   486 (* Facts containing variables of type "unit" or "bool" or of the form
   485    "ALL x. x = A | x = B | x = C" are likely to lead to unsound proofs if types
   487    "ALL x. x = A | x = B | x = C" are likely to lead to unsound proofs if types
   486    are omitted. *)
   488    are omitted. *)
   487 fun is_dangerous_term full_types t =
   489 fun is_dangerous_term full_types t =
   488   not full_types andalso
   490   not full_types andalso
   489   (has_bound_or_var_of_type dangerous_types t orelse is_exhaustive_finite t)
   491   ((has_bound_or_var_of_type dangerous_types t andalso
       
   492     has_bound_or_var_of_type dangerous_types (transform_elim_term t))
       
   493    orelse is_exhaustive_finite t)
   490 
   494 
   491 fun is_theorem_bad_for_atps full_types thm =
   495 fun is_theorem_bad_for_atps full_types thm =
   492   let val t = prop_of thm in
   496   let val t = prop_of thm in
   493     is_formula_too_complex t orelse exists_type type_has_top_sort t orelse
   497     is_formula_too_complex t orelse exists_type type_has_top_sort t orelse
   494     is_dangerous_term full_types t orelse exists_sledgehammer_const t orelse
   498     is_dangerous_term full_types t orelse exists_sledgehammer_const t orelse
   495     is_strange_thm thm
   499     is_strange_theorem thm
   496   end
   500   end
   497 
   501 
   498 fun all_name_thms_pairs ctxt full_types add_thms chained_ths =
   502 fun all_name_thms_pairs ctxt full_types add_thms chained_ths =
   499   let
   503   let
   500     val global_facts = PureThy.facts_of (ProofContext.theory_of ctxt);
   504     val global_facts = PureThy.facts_of (ProofContext.theory_of ctxt);
   523                 NONE => false
   527                 NONE => false
   524               | SOME ths1 => Thm.eq_thms (ths0, ths1))
   528               | SOME ths1 => Thm.eq_thms (ths0, ths1))
   525             val name1 = Facts.extern facts name;
   529             val name1 = Facts.extern facts name;
   526             val name2 = Name_Space.extern full_space name;
   530             val name2 = Name_Space.extern full_space name;
   527             val ths =
   531             val ths =
   528               ths0 |> map Clausifier.transform_elim_theorem
   532               ths0 |> filter ((not o is_theorem_bad_for_atps full_types) orf
   529                    |> filter ((not o is_theorem_bad_for_atps full_types) orf
       
   530                               member Thm.eq_thm add_thms)
   533                               member Thm.eq_thm add_thms)
   531             val name' =
   534             val name' =
   532               case find_first check_thms [name1, name2, name] of
   535               case find_first check_thms [name1, name2, name] of
   533                 SOME name' => name'
   536                 SOME name' => name'
   534               | NONE =>
   537               | NONE =>
   536                                "`" ^ Print_Mode.setmp [Print_Mode.input]
   539                                "`" ^ Print_Mode.setmp [Print_Mode.input]
   537                                          (Syntax.string_of_term ctxt)
   540                                          (Syntax.string_of_term ctxt)
   538                                          (prop_of th) ^ "`")
   541                                          (prop_of th) ^ "`")
   539                     |> space_implode " "
   542                     |> space_implode " "
   540           in
   543           in
   541             cons (name' |> forall (member Thm.eq_thm chained_ths) ths
   544             cons (name' |> forall (member Thm.eq_thm chained_ths) ths0
   542                            ? prefix chained_prefix, ths)
   545                            ? prefix chained_prefix, ths)
   543           end)
   546           end)
   544   in
   547   in
   545     valid_facts local_facts (unnamed_locals @ named_locals) @
   548     valid_facts local_facts (unnamed_locals @ named_locals) @
   546     valid_facts global_facts (Facts.dest_static [] global_facts)
   549     valid_facts global_facts (Facts.dest_static [] global_facts)