src/HOL/TPTP/atp_problem_import.ML
changeset 47794 4ad62c5f9f88
parent 47793 02bdd591eb8f
child 47811 1e8eb643540d
equal deleted inserted replaced
47793:02bdd591eb8f 47794:4ad62c5f9f88
     5 Import TPTP problems as Isabelle terms or goals.
     5 Import TPTP problems as Isabelle terms or goals.
     6 *)
     6 *)
     7 
     7 
     8 signature ATP_PROBLEM_IMPORT =
     8 signature ATP_PROBLEM_IMPORT =
     9 sig
     9 sig
    10   val nitpick_tptp_file : int -> string -> unit
    10   val nitpick_tptp_file : theory -> int -> string -> unit
    11   val refute_tptp_file : int -> string -> unit
    11   val refute_tptp_file : theory -> int -> string -> unit
    12   val sledgehammer_tptp_file : int -> string -> unit
    12   val sledgehammer_tptp_file : theory -> int -> string -> unit
    13   val isabelle_tptp_file : int -> string -> unit
    13   val isabelle_tptp_file : theory -> int -> string -> unit
    14   val translate_tptp_file : string -> string -> string -> unit
    14   val translate_tptp_file : string -> string -> string -> unit
    15 end;
    15 end;
    16 
    16 
    17 structure ATP_Problem_Import : ATP_PROBLEM_IMPORT =
    17 structure ATP_Problem_Import : ATP_PROBLEM_IMPORT =
    18 struct
    18 struct
    57 (** Nitpick (alias Nitrox) **)
    57 (** Nitpick (alias Nitrox) **)
    58 
    58 
    59 fun aptrueprop f ((t0 as @{const Trueprop}) $ t1) = t0 $ f t1
    59 fun aptrueprop f ((t0 as @{const Trueprop}) $ t1) = t0 $ f t1
    60   | aptrueprop f t = f t
    60   | aptrueprop f t = f t
    61 
    61 
    62 fun nitpick_tptp_file timeout file_name =
    62 fun nitpick_tptp_file thy timeout file_name =
    63   let
    63   let
    64     val (conjs, (defs, nondefs), ctxt) = read_tptp_file @{theory} I file_name
    64     val (conjs, (defs, nondefs), ctxt) = read_tptp_file thy I file_name
    65     val thy = Proof_Context.theory_of ctxt
    65     val thy = Proof_Context.theory_of ctxt
    66     val defs = defs |> map (ATP_Util.extensionalize_term ctxt
    66     val defs = defs |> map (ATP_Util.extensionalize_term ctxt
    67                             #> aptrueprop (open_form I))
    67                             #> aptrueprop (open_form I))
    68     val state = Proof.init ctxt
    68     val state = Proof.init ctxt
    69     val params =
    69     val params =
    93   end
    93   end
    94 
    94 
    95 
    95 
    96 (** Refute **)
    96 (** Refute **)
    97 
    97 
    98 fun refute_tptp_file timeout file_name =
    98 fun refute_tptp_file thy timeout file_name =
    99   let
    99   let
   100     fun print_szs_from_outcome falsify s =
   100     fun print_szs_from_outcome falsify s =
   101       "% SZS status " ^
   101       "% SZS status " ^
   102       (if s = "genuine" then
   102       (if s = "genuine" then
   103          if falsify then "CounterSatisfiable" else "Satisfiable"
   103          if falsify then "CounterSatisfiable" else "Satisfiable"
   104        else
   104        else
   105          "Unknown")
   105          "Unknown")
   106       |> Output.urgent_message
   106       |> Output.urgent_message
   107     val (conjs, (defs, nondefs), ctxt) = read_tptp_file @{theory} I file_name
   107     val (conjs, (defs, nondefs), ctxt) = read_tptp_file thy I file_name
   108     val params =
   108     val params =
   109       [("maxtime", string_of_int timeout),
   109       [("maxtime", string_of_int timeout),
   110        ("maxvars", "100000")]
   110        ("maxvars", "100000")]
   111   in
   111   in
   112     Refute.refute_term ctxt params (defs @ nondefs)
   112     Refute.refute_term ctxt params (defs @ nondefs)
   114     |> print_szs_from_outcome (not (null conjs))
   114     |> print_szs_from_outcome (not (null conjs))
   115   end
   115   end
   116 
   116 
   117 
   117 
   118 (** Sledgehammer and Isabelle (combination of provers) **)
   118 (** Sledgehammer and Isabelle (combination of provers) **)
   119 
       
   120 val cvc3N = "cvc3"
       
   121 val z3N = "z3"
       
   122 
   119 
   123 fun can_tac ctxt tactic conj = can (Goal.prove ctxt [] [] conj) (K tactic)
   120 fun can_tac ctxt tactic conj = can (Goal.prove ctxt [] [] conj) (K tactic)
   124 
   121 
   125 fun SOLVE_TIMEOUT seconds name tac st =
   122 fun SOLVE_TIMEOUT seconds name tac st =
   126   let
   123   let
   147 
   144 
   148 fun sledgehammer_tac ctxt timeout i =
   145 fun sledgehammer_tac ctxt timeout i =
   149   let
   146   let
   150     fun slice overload_params fraq prover =
   147     fun slice overload_params fraq prover =
   151       SOLVE_TIMEOUT (timeout div fraq) prover
   148       SOLVE_TIMEOUT (timeout div fraq) prover
   152                     (atp_tac ctxt overload_params timeout prover i)
   149                     (atp_tac ctxt overload_params (timeout div fraq) prover i)
   153   in
   150   in
   154     slice [] 7 ATP_Systems.satallaxN
   151     slice [] 5 ATP_Systems.satallaxN
   155     ORELSE slice [] 7 ATP_Systems.leo2N
   152     ORELSE slice [] 5 ATP_Systems.leo2N
   156     ORELSE slice [] 7 ATP_Systems.spassN
   153     ORELSE slice [] 5 ATP_Systems.spassN
   157     ORELSE slice [] 7 z3N
   154     ORELSE slice [] 5 ATP_Systems.vampireN
   158     ORELSE slice [] 7 ATP_Systems.vampireN
   155     ORELSE slice [] 5 ATP_Systems.eN
   159     ORELSE slice [] 7 ATP_Systems.eN
       
   160     ORELSE slice [] 7 cvc3N
       
   161   end
   156   end
   162 
   157 
   163 fun auto_etc_tac ctxt timeout i =
   158 fun auto_etc_tac ctxt timeout i =
   164   SOLVE_TIMEOUT (timeout div 10) "simp" (asm_full_simp_tac (simpset_of ctxt) i)
   159   SOLVE_TIMEOUT (timeout div 10) "simp" (asm_full_simp_tac (simpset_of ctxt) i)
   165   ORELSE SOLVE_TIMEOUT (timeout div 10) "blast" (blast_tac ctxt i)
   160   ORELSE SOLVE_TIMEOUT (timeout div 10) "blast" (blast_tac ctxt i)
   166   ORELSE SOLVE_TIMEOUT (timeout div 20) "auto+spass"
   161   ORELSE SOLVE_TIMEOUT (timeout div 5) "auto+spass"
   167       (auto_tac ctxt
   162       (auto_tac ctxt
   168        THEN ALLGOALS (atp_tac ctxt [] (timeout div 20) ATP_Systems.spassN))
   163        THEN ALLGOALS (atp_tac ctxt [] (timeout div 5) ATP_Systems.spassN))
   169   ORELSE SOLVE_TIMEOUT (timeout div 20) "fast" (fast_tac ctxt i)
   164   ORELSE SOLVE_TIMEOUT (timeout div 5) "smt" (SMT_Solver.smt_tac ctxt [] i)
   170   ORELSE SOLVE_TIMEOUT (timeout div 20) "best" (best_tac ctxt i)
   165   ORELSE SOLVE_TIMEOUT (timeout div 10) "fast" (fast_tac ctxt i)
   171   ORELSE SOLVE_TIMEOUT (timeout div 20) "force" (force_tac ctxt i)
   166   ORELSE SOLVE_TIMEOUT (timeout div 10) "best" (best_tac ctxt i)
   172   ORELSE SOLVE_TIMEOUT (timeout div 20) "arith" (Arith_Data.arith_tac ctxt i)
   167   ORELSE SOLVE_TIMEOUT (timeout div 10) "force" (force_tac ctxt i)
       
   168   ORELSE SOLVE_TIMEOUT (timeout div 10) "arith" (Arith_Data.arith_tac ctxt i)
   173   ORELSE SOLVE_TIMEOUT timeout "fastforce" (fast_force_tac ctxt i)
   169   ORELSE SOLVE_TIMEOUT timeout "fastforce" (fast_force_tac ctxt i)
   174 
   170 
   175 val problem_const_prefix = Context.theory_name @{theory} ^ Long_Name.separator
   171 fun problem_const_prefix thy = Context.theory_name thy ^ Long_Name.separator
   176 
   172 
   177 (* Isabelle's standard automatic tactics ("auto", etc.) are more eager to
   173 (* Isabelle's standard automatic tactics ("auto", etc.) are more eager to
   178    unfold "definitions" of free variables than of constants (cf. PUZ107^5). *)
   174    unfold "definitions" of free variables than of constants (cf. PUZ107^5). *)
   179 val freeze_problem_consts =
   175 fun freeze_problem_consts thy =
   180   map_aterms (fn t as Const (s, T) =>
   176   let val is_problem_const = String.isPrefix (problem_const_prefix thy) in
   181                  if String.isPrefix problem_const_prefix s then
   177     map_aterms (fn t as Const (s, T) =>
   182                    Free (Long_Name.base_name s, T)
   178                    if is_problem_const s then Free (Long_Name.base_name s, T)
   183                  else
   179                    else t
   184                    t
   180                  | t => t)
   185                | t => t)
   181   end
   186 
   182 
   187 fun make_conj (defs, nondefs) conjs =
   183 fun make_conj (defs, nondefs) conjs =
   188   Logic.list_implies (rev defs @ rev nondefs,
   184   Logic.list_implies (rev defs @ rev nondefs,
   189                       case conjs of conj :: _ => conj | [] => @{prop False})
   185                       case conjs of conj :: _ => conj | [] => @{prop False})
   190 
   186 
   191 fun print_szs_from_success conjs success =
   187 fun print_szs_from_success conjs success =
   192   Output.urgent_message ("% SZS status " ^
   188   Output.urgent_message ("% SZS status " ^
   193                          (if success then
   189                          (if success then
   194                             if null conjs then "Unsatisfiable" else "Theorem"
   190                             if null conjs then "Unsatisfiable" else "Theorem"
   195                           else
   191                           else
   196                             "% SZS status Unknown"))
   192                             "Unknown"))
   197 
   193 
   198 fun sledgehammer_tptp_file timeout file_name =
   194 fun sledgehammer_tptp_file thy timeout file_name =
   199   let
   195   let
   200     val (conjs, assms, ctxt) =
   196     val (conjs, assms, ctxt) =
   201       read_tptp_file @{theory} freeze_problem_consts file_name
   197       read_tptp_file thy (freeze_problem_consts thy) file_name
   202     val conj = make_conj assms conjs
   198     val conj = make_conj assms conjs
   203   in
   199   in
   204     can_tac ctxt (sledgehammer_tac ctxt timeout 1) conj
   200     can_tac ctxt (sledgehammer_tac ctxt timeout 1) conj
   205     |> print_szs_from_success conjs
   201     |> print_szs_from_success conjs
   206   end
   202   end
   207 
   203 
   208 fun isabelle_tptp_file timeout file_name =
   204 fun isabelle_tptp_file thy timeout file_name =
   209   let
   205   let
   210     val (conjs, assms, ctxt) =
   206     val (conjs, assms, ctxt) =
   211       read_tptp_file @{theory} freeze_problem_consts file_name
   207       read_tptp_file thy (freeze_problem_consts thy) file_name
   212     val conj = make_conj assms conjs
   208     val conj = make_conj assms conjs
   213   in
   209   in
   214     (can_tac ctxt (sledgehammer_tac ctxt (timeout div 2) 1) conj orelse
   210     (can_tac ctxt (sledgehammer_tac ctxt (timeout div 2) 1) conj orelse
   215      can_tac ctxt (auto_etc_tac ctxt (timeout div 2) 1) conj orelse
   211      can_tac ctxt (auto_etc_tac ctxt (timeout div 2) 1) conj orelse
   216      can_tac ctxt (atp_tac ctxt [] timeout ATP_Systems.satallaxN 1) conj)
   212      can_tac ctxt (atp_tac ctxt [] timeout ATP_Systems.satallaxN 1) conj)