src/HOL/Tools/Sledgehammer/sledgehammer_isar.ML
changeset 55244 12e1a5d8ee48
parent 55223 3c593bad6b31
child 55245 c402981f74c1
equal deleted inserted replaced
55243:66709d41601e 55244:12e1a5d8ee48
   108     end
   108     end
   109 
   109 
   110 type isar_params =
   110 type isar_params =
   111   bool * string * string * Time.time * real * bool * (term, string) atp_step list * thm
   111   bool * string * string * Time.time * real * bool * (term, string) atp_step list * thm
   112 
   112 
   113 val arith_methodss =
   113 val arith_methods =
   114   [[Arith_Method, Simp_Method, Auto_Method, Fastforce_Method, Blast_Method, Force_Method,
   114   [Arith_Method, Simp_Method, Auto_Method, Fastforce_Method, Blast_Method, Force_Method,
   115     Algebra_Method], [Metis_Method], [Meson_Method]]
   115    Algebra_Method, Metis_Method, Meson_Method]
   116 val datatype_methodss = [[Simp_Method], [Simp_Size_Method]]
   116 val datatype_methods = [Simp_Method, Simp_Size_Method]
   117 val metislike_methodss =
   117 val metislike_methods =
   118   [[Metis_Method, Simp_Method, Auto_Method, Arith_Method, Blast_Method, Fastforce_Method,
   118   [Metis_Method, Simp_Method, Auto_Method, Arith_Method, Blast_Method, Fastforce_Method,
   119     Force_Method, Algebra_Method], [Meson_Method]]
   119    Force_Method, Algebra_Method, Meson_Method]
   120 val rewrite_methodss =
   120 val rewrite_methods =
   121   [[Auto_Method, Simp_Method, Fastforce_Method, Force_Method, Metis_Method], [Meson_Method]]
   121   [Auto_Method, Simp_Method, Fastforce_Method, Force_Method, Metis_Method, Meson_Method]
   122 val skolem_methodss = [[Metis_Method, Blast_Method], [Meson_Method]]
   122 val skolem_methods = [Metis_Method, Blast_Method, Meson_Method]
   123 
   123 
   124 fun isar_proof_text ctxt debug isar_proofs isar_params
   124 fun isar_proof_text ctxt debug isar_proofs isar_params
   125     (one_line_params as (_, _, _, _, subgoal, subgoal_count)) =
   125     (one_line_params as (_, _, _, _, subgoal, subgoal_count)) =
   126   let
   126   let
   127     fun isar_proof_of () =
   127     fun isar_proof_of () =
   156         val assms = map_filter (Option.map fst o get_role (curry (op =) Hypothesis)) atp_proof
   156         val assms = map_filter (Option.map fst o get_role (curry (op =) Hypothesis)) atp_proof
   157         val lems =
   157         val lems =
   158           map_filter (get_role (curry (op =) Lemma)) atp_proof
   158           map_filter (get_role (curry (op =) Lemma)) atp_proof
   159           |> map (fn ((l, t), rule) =>
   159           |> map (fn ((l, t), rule) =>
   160             let
   160             let
   161               val (skos, methss) =
   161               val (skos, meths) =
   162                 if is_skolemize_rule rule then (skolems_of t, skolem_methodss)
   162                 if is_skolemize_rule rule then (skolems_of t, skolem_methods)
   163                 else if is_arith_rule rule then ([], arith_methodss)
   163                 else if is_arith_rule rule then ([], arith_methods)
   164                 else ([], rewrite_methodss)
   164                 else ([], rewrite_methods)
   165             in
   165             in
   166               Prove ([], skos, l, t, [], (([], []), methss))
   166               Prove ([], skos, l, t, [], (([], []), meths))
   167             end)
   167             end)
   168 
   168 
   169         val bot = atp_proof |> List.last |> #1
   169         val bot = atp_proof |> List.last |> #1
   170 
   170 
   171         val refute_graph =
   171         val refute_graph =
   210 
   210 
   211         fun isar_steps outer predecessor accum [] =
   211         fun isar_steps outer predecessor accum [] =
   212             accum
   212             accum
   213             |> (if tainted = [] then
   213             |> (if tainted = [] then
   214                   cons (Prove (if outer then [Show] else [], [], no_label, concl_t, [],
   214                   cons (Prove (if outer then [Show] else [], [], no_label, concl_t, [],
   215                                ((the_list predecessor, []), metislike_methodss)))
   215                                ((the_list predecessor, []), metislike_methods)))
   216                 else
   216                 else
   217                   I)
   217                   I)
   218             |> rev
   218             |> rev
   219           | isar_steps outer _ accum (Have (id, (gamma, c)) :: infs) =
   219           | isar_steps outer _ accum (Have (id, (gamma, c)) :: infs) =
   220             let
   220             let
   225 
   225 
   226               fun prove sub by = Prove (maybe_show outer c [], [], l, t, sub, by)
   226               fun prove sub by = Prove (maybe_show outer c [], [], l, t, sub, by)
   227               fun do_rest l step = isar_steps outer (SOME l) (step :: accum) infs
   227               fun do_rest l step = isar_steps outer (SOME l) (step :: accum) infs
   228 
   228 
   229               val deps = fold add_fact_of_dependencies gamma no_facts
   229               val deps = fold add_fact_of_dependencies gamma no_facts
   230               val methss =
   230               val meths =
   231                 if is_arith_rule rule then arith_methodss
   231                 if is_arith_rule rule then arith_methods
   232                 else if is_datatype_rule rule then datatype_methodss
   232                 else if is_datatype_rule rule then datatype_methods
   233                 else metislike_methodss
   233                 else metislike_methods
   234               val by = (deps, methss)
   234               val by = (deps, meths)
   235             in
   235             in
   236               if is_clause_tainted c then
   236               if is_clause_tainted c then
   237                 (case gamma of
   237                 (case gamma of
   238                   [g] =>
   238                   [g] =>
   239                   if skolem andalso is_clause_tainted g then
   239                   if skolem andalso is_clause_tainted g then
   240                     let val subproof = Proof (skolems_of (prop_of_clause g), [], rev accum) in
   240                     let val subproof = Proof (skolems_of (prop_of_clause g), [], rev accum) in
   241                       isar_steps outer (SOME l) [prove [subproof] (no_facts, skolem_methodss)] infs
   241                       isar_steps outer (SOME l) [prove [subproof] (no_facts, skolem_methods)] infs
   242                     end
   242                     end
   243                   else
   243                   else
   244                     do_rest l (prove [] by)
   244                     do_rest l (prove [] by)
   245                 | _ => do_rest l (prove [] by))
   245                 | _ => do_rest l (prove [] by))
   246               else
   246               else
   254               val l = label_of_clause c
   254               val l = label_of_clause c
   255               val t = prop_of_clause c
   255               val t = prop_of_clause c
   256               val step =
   256               val step =
   257                 Prove (maybe_show outer c [], [], l, t,
   257                 Prove (maybe_show outer c [], [], l, t,
   258                   map isar_case (filter_out (null o snd) cases),
   258                   map isar_case (filter_out (null o snd) cases),
   259                   ((the_list predecessor, []), metislike_methodss))
   259                   ((the_list predecessor, []), metislike_methods))
   260             in
   260             in
   261               isar_steps outer (SOME l) (step :: accum) infs
   261               isar_steps outer (SOME l) (step :: accum) infs
   262             end
   262             end
   263         and isar_proof outer fix assms lems infs =
   263         and isar_proof outer fix assms lems infs =
   264           Proof (fix, assms, lems @ isar_steps outer NONE [] infs)
   264           Proof (fix, assms, lems @ isar_steps outer NONE [] infs)
   284         fun str_of_preplay_outcome outcome =
   284         fun str_of_preplay_outcome outcome =
   285           if Lazy.is_finished outcome then string_of_play_outcome (Lazy.force outcome) else "?"
   285           if Lazy.is_finished outcome then string_of_play_outcome (Lazy.force outcome) else "?"
   286 
   286 
   287         fun str_of_meth l meth =
   287         fun str_of_meth l meth =
   288           string_of_proof_method meth ^ " " ^ str_of_preplay_outcome (preplay_outcome l meth)
   288           string_of_proof_method meth ^ " " ^ str_of_preplay_outcome (preplay_outcome l meth)
   289         fun comment_of l = map (map (str_of_meth l)) #> map commas #> space_implode "; "
   289         fun comment_of l = map (str_of_meth l) #> commas
   290 
   290 
   291         fun trace_isar_proof label proof =
   291         fun trace_isar_proof label proof =
   292           if trace then
   292           if trace then
   293             tracing (timestamp () ^ "\n" ^ label ^ ":\n\n" ^ string_of_isar_proof comment_of proof ^
   293             tracing (timestamp () ^ "\n" ^ label ^ ":\n\n" ^ string_of_isar_proof comment_of proof ^
   294               "\n")
   294               "\n")