src/HOL/Tools/Sledgehammer/sledgehammer_reconstructor.ML
changeset 55285 e88ad20035f4
parent 55269 aae87746f412
child 55286 7bbbd9393ce0
equal deleted inserted replaced
55284:bd27ac6ad1c3 55285:e88ad20035f4
     7 
     7 
     8 signature SLEDGEHAMMER_RECONSTRUCTOR =
     8 signature SLEDGEHAMMER_RECONSTRUCTOR =
     9 sig
     9 sig
    10   type stature = ATP_Problem_Generate.stature
    10   type stature = ATP_Problem_Generate.stature
    11 
    11 
    12   datatype reconstructor =
    12   datatype proof_method =
    13     Metis of string * string |
    13     Metis_Method of string option * string option |
    14     SMT
    14     Meson_Method |
       
    15     SMT_Method |
       
    16     Simp_Method |
       
    17     Simp_Size_Method |
       
    18     Auto_Method |
       
    19     Fastforce_Method |
       
    20     Force_Method |
       
    21     Arith_Method |
       
    22     Blast_Method |
       
    23     Algebra_Method
    15 
    24 
    16   datatype play_outcome =
    25   datatype play_outcome =
    17     Played of Time.time |
    26     Played of Time.time |
    18     Play_Timed_Out of Time.time |
    27     Play_Timed_Out of Time.time |
    19     Play_Failed |
    28     Play_Failed |
    20     Not_Played
    29     Not_Played
    21 
    30 
    22   type minimize_command = string list -> string
    31   type minimize_command = string list -> string
    23   type one_line_params =
    32   type one_line_params =
    24     (reconstructor * play_outcome) * string * (string * stature) list * minimize_command * int * int
    33     (proof_method * play_outcome) * string * (string * stature) list * minimize_command * int * int
    25 
    34 
    26   val smtN : string
    35   val smtN : string
    27 
    36 
    28   val string_of_reconstructor : reconstructor -> string
    37   val string_of_proof_method : proof_method -> string
       
    38   val tac_of_proof_method : Proof.context -> thm list * thm list -> proof_method -> int -> tactic
    29   val string_of_play_outcome : play_outcome -> string
    39   val string_of_play_outcome : play_outcome -> string
    30   val play_outcome_ord : play_outcome * play_outcome -> order
    40   val play_outcome_ord : play_outcome * play_outcome -> order
    31 
    41 
    32   val one_line_proof_text : int -> one_line_params -> string
    42   val one_line_proof_text : int -> one_line_params -> string
    33   val silence_reconstructors : bool -> Proof.context -> Proof.context
    43   val silence_proof_methods : bool -> Proof.context -> Proof.context
    34 end;
    44 end;
    35 
    45 
    36 structure Sledgehammer_Reconstructor : SLEDGEHAMMER_RECONSTRUCTOR =
    46 structure Sledgehammer_Reconstructor : SLEDGEHAMMER_RECONSTRUCTOR =
    37 struct
    47 struct
    38 
    48 
    39 open ATP_Util
    49 open ATP_Util
    40 open ATP_Problem_Generate
    50 open ATP_Problem_Generate
    41 open ATP_Proof_Reconstruct
    51 open ATP_Proof_Reconstruct
    42 
    52 
    43 datatype reconstructor =
    53 datatype proof_method =
    44   Metis of string * string |
    54   Metis_Method of string option * string option |
    45   SMT
    55   Meson_Method |
       
    56   SMT_Method |
       
    57   Simp_Method |
       
    58   Simp_Size_Method |
       
    59   Auto_Method |
       
    60   Fastforce_Method |
       
    61   Force_Method |
       
    62   Arith_Method |
       
    63   Blast_Method |
       
    64   Algebra_Method
    46 
    65 
    47 datatype play_outcome =
    66 datatype play_outcome =
    48   Played of Time.time |
    67   Played of Time.time |
    49   Play_Timed_Out of Time.time |
    68   Play_Timed_Out of Time.time |
    50   Play_Failed |
    69   Play_Failed |
    51   Not_Played
    70   Not_Played
    52 
    71 
    53 type minimize_command = string list -> string
    72 type minimize_command = string list -> string
    54 type one_line_params =
    73 type one_line_params =
    55   (reconstructor * play_outcome) * string * (string * stature) list * minimize_command * int * int
    74   (proof_method * play_outcome) * string * (string * stature) list * minimize_command * int * int
    56 
    75 
    57 val smtN = "smt"
    76 val smtN = "smt"
    58 
    77 
    59 fun string_of_reconstructor (Metis (type_enc, lam_trans)) = metis_call type_enc lam_trans
    78 fun string_of_proof_method meth =
    60   | string_of_reconstructor SMT = smtN
    79   (case meth of
       
    80     Metis_Method (NONE, NONE) => "metis"
       
    81   | Metis_Method (type_enc_opt, lam_trans_opt) =>
       
    82     "metis (" ^ commas (map_filter I [type_enc_opt, lam_trans_opt]) ^ ")"
       
    83   | Meson_Method => "meson"
       
    84   | SMT_Method => "smt"
       
    85   | Simp_Method => "simp"
       
    86   | Simp_Size_Method => "simp add: size_ne_size_imp_ne"
       
    87   | Auto_Method => "auto"
       
    88   | Fastforce_Method => "fastforce"
       
    89   | Force_Method => "force"
       
    90   | Arith_Method => "arith"
       
    91   | Blast_Method => "blast"
       
    92   | Algebra_Method => "algebra")
       
    93 
       
    94 fun tac_of_proof_method ctxt (local_facts, global_facts) meth =
       
    95   Method.insert_tac local_facts THEN'
       
    96   (case meth of
       
    97     Metis_Method (type_enc_opt, lam_trans_opt) =>
       
    98     Metis_Tactic.metis_tac [type_enc_opt |> the_default partial_type_enc]
       
    99       (the_default default_metis_lam_trans lam_trans_opt) ctxt global_facts
       
   100   | SMT_Method => SMT_Solver.smt_tac ctxt global_facts
       
   101   | Meson_Method => Meson.meson_tac ctxt global_facts
       
   102   | _ =>
       
   103     Method.insert_tac global_facts THEN'
       
   104     (case meth of
       
   105       Simp_Method => Simplifier.asm_full_simp_tac ctxt
       
   106     | Simp_Size_Method =>
       
   107       Simplifier.asm_full_simp_tac (Simplifier.add_simp @{thm size_ne_size_imp_ne} ctxt)
       
   108     | Auto_Method => K (Clasimp.auto_tac ctxt)
       
   109     | Fastforce_Method => Clasimp.fast_force_tac ctxt
       
   110     | Force_Method => Clasimp.force_tac ctxt
       
   111     | Arith_Method => Arith_Data.arith_tac ctxt
       
   112     | Blast_Method => blast_tac ctxt
       
   113     | Algebra_Method => Groebner.algebra_tac [] [] ctxt))
    61 
   114 
    62 fun string_of_play_outcome (Played time) = string_of_ext_time (false, time)
   115 fun string_of_play_outcome (Played time) = string_of_ext_time (false, time)
    63   | string_of_play_outcome (Play_Timed_Out time) = string_of_ext_time (true, time) ^ ", timed out"
   116   | string_of_play_outcome (Play_Timed_Out time) = string_of_ext_time (true, time) ^ ", timed out"
    64   | string_of_play_outcome Play_Failed = "failed"
   117   | string_of_play_outcome Play_Failed = "failed"
    65   | string_of_play_outcome _ = "unknown"
   118   | string_of_play_outcome _ = "unknown"
    92 
   145 
    93 fun command_call name [] =
   146 fun command_call name [] =
    94     name |> not (Symbol_Pos.is_identifier name) ? enclose "(" ")"
   147     name |> not (Symbol_Pos.is_identifier name) ? enclose "(" ")"
    95   | command_call name args = "(" ^ name ^ " " ^ space_implode " " args ^ ")"
   148   | command_call name args = "(" ^ name ^ " " ^ space_implode " " args ^ ")"
    96 
   149 
    97 fun reconstructor_command reconstr i n used_chaineds num_chained ss =
   150 (* FIXME *)
       
   151 fun proof_method_command meth i n used_chaineds num_chained ss =
    98   (* unusing_chained_facts used_chaineds num_chained ^ *)
   152   (* unusing_chained_facts used_chaineds num_chained ^ *)
    99   apply_on_subgoal i n ^ command_call (string_of_reconstructor reconstr) ss
   153   apply_on_subgoal i n ^ command_call (string_of_proof_method meth) ss
   100 
   154 
   101 fun show_time NONE = ""
   155 fun show_time NONE = ""
   102   | show_time (SOME ext_time) = " (" ^ string_of_ext_time ext_time ^ ")"
   156   | show_time (SOME ext_time) = " (" ^ string_of_ext_time ext_time ^ ")"
   103 
   157 
   104 fun try_command_line banner time command =
   158 fun try_command_line banner time command =
   114   facts
   168   facts
   115   |> List.partition (fn (_, (sc, _)) => sc = Chained)
   169   |> List.partition (fn (_, (sc, _)) => sc = Chained)
   116   |> pairself (sort_distinct (string_ord o pairself fst))
   170   |> pairself (sort_distinct (string_ord o pairself fst))
   117 
   171 
   118 fun one_line_proof_text num_chained
   172 fun one_line_proof_text num_chained
   119     ((reconstr, play), banner, used_facts, minimize_command, subgoal, subgoal_count) =
   173     ((meth, play), banner, used_facts, minimize_command, subgoal, subgoal_count) =
   120   let
   174   let
   121     val (chained, extra) = split_used_facts used_facts
   175     val (chained, extra) = split_used_facts used_facts
   122 
   176 
   123     val (failed, ext_time) =
   177     val (failed, ext_time) =
   124       (case play of
   178       (case play of
   127       | Play_Failed => (true, NONE)
   181       | Play_Failed => (true, NONE)
   128       | Not_Played => (false, NONE))
   182       | Not_Played => (false, NONE))
   129 
   183 
   130     val try_line =
   184     val try_line =
   131       map fst extra
   185       map fst extra
   132       |> reconstructor_command reconstr subgoal subgoal_count (map fst chained) num_chained
   186       |> proof_method_command meth subgoal subgoal_count (map fst chained) num_chained
   133       |> (if failed then
   187       |> (if failed then
   134             enclose "One-line proof reconstruction failed: "
   188             enclose "One-line proof reconstruction failed: "
   135               ".\n(Invoking \"sledgehammer\" with \"[strict]\" might solve this.)"
   189               ".\n(Invoking \"sledgehammer\" with \"[strict]\" might solve this.)"
   136           else
   190           else
   137             try_command_line banner ext_time)
   191             try_command_line banner ext_time)
   138   in
   192   in
   139     try_line ^ minimize_line minimize_command (map fst (extra @ chained))
   193     try_line ^ minimize_line minimize_command (map fst (extra @ chained))
   140   end
   194   end
   141 
   195 
   142 (* Makes reconstructor tools as silent as possible. The "set_visible" calls suppresses "Unification
   196 (* Makes proof methods as silent as possible. The "set_visible" calls suppresses "Unification bound
   143    bound exceeded" warnings and the like. *)
   197    exceeded" warnings and the like. *)
   144 fun silence_reconstructors debug =
   198 fun silence_proof_methods debug =
   145   Try0.silence_methods debug
   199   Try0.silence_methods debug
   146   #> Config.put SMT_Config.verbose debug
   200   #> Config.put SMT_Config.verbose debug
   147 
   201 
   148 end;
   202 end;