src/HOL/TPTP/atp_problem_import.ML
author blanchet
Wed, 18 Apr 2012 23:13:11 +0200
changeset 48436 762eb0dacaa6
parent 48433 a72239723ae8
child 48514 e33c2be488fe
permissions -rw-r--r--
remove old TPTP CNF/FOF parser; always use Nik's new parser
     1 (*  Title:      HOL/TPTP/atp_problem_import.ML
     2     Author:     Jasmin Blanchette, TU Muenchen
     3     Copyright   2012
     4 
     5 Import TPTP problems as Isabelle terms or goals.
     6 *)
     7 
     8 signature ATP_PROBLEM_IMPORT =
     9 sig
    10   val isabelle_tptp_file : string -> unit
    11   val nitpick_tptp_file : string -> unit
    12   val refute_tptp_file : string -> unit
    13   val sledgehammer_tptp_file : string -> unit
    14   val translate_tptp_file : string -> string -> string -> unit
    15 end;
    16 
    17 structure ATP_Problem_Import : ATP_PROBLEM_IMPORT =
    18 struct
    19 
    20 (** TPTP parsing **)
    21 
    22 (* cf. "close_form" in "refute.ML" *)
    23 fun close_form t =
    24   fold (fn ((s, i), T) => fn t' =>
    25            Logic.all_const T $ Abs (s, T, abstract_over (Var ((s, i), T), t')))
    26        (Term.add_vars t []) t
    27 
    28 fun mk_meta_not P = Logic.mk_implies (P, @{prop False})
    29 
    30 fun get_tptp_formula (_, role, P, _) =
    31   P |> Logic.varify_global |> close_form
    32     |> role = TPTP_Syntax.Role_Conjecture ? mk_meta_not
    33 
    34 fun read_tptp_file thy file_name =
    35   let
    36     val path = Path.explode file_name
    37     val problem =
    38       TPTP_Interpret.interpret_file true (Path.explode "$TPTP") path [] [] thy
    39       |> fst |> #3
    40   in
    41     (exists (fn (_, role, _, _) => role = TPTP_Syntax.Role_Conjecture) problem,
    42      map get_tptp_formula problem)
    43   end
    44 
    45 (** Isabelle (combination of provers) **)
    46 
    47 fun isabelle_tptp_file file_name = ()
    48 
    49 
    50 (** Nitpick (alias Nitrox) **)
    51 
    52 fun nitpick_tptp_file file_name =
    53   let
    54     val (falsify, ts) = read_tptp_file @{theory} file_name
    55     val state = Proof.init @{context}
    56     val params =
    57       [("card", "1\<emdash>100"),
    58        ("box", "false"),
    59        ("sat_solver", "smart"),
    60        ("max_threads", "1"),
    61        ("batch_size", "10"),
    62        ("falsify", if falsify then "true" else "false"),
    63        (* ("debug", "true"), *)
    64        ("verbose", "true"),
    65        (* ("overlord", "true"), *)
    66        ("show_consts", "true"),
    67        ("format", "1000"),
    68        ("max_potential", "0"),
    69        ("timeout", "none"),
    70        ("expect", Nitpick.genuineN)]
    71       |> Nitpick_Isar.default_params @{theory}
    72     val i = 1
    73     val n = 1
    74     val step = 0
    75     val subst = []
    76   in
    77     Nitpick.pick_nits_in_term state params Nitpick.TPTP i n step subst ts
    78         (if falsify then @{prop False} else @{prop True}); ()
    79   end
    80 
    81 
    82 (** Refute **)
    83 
    84 fun print_szs_from_outcome falsify s =
    85   "% SZS status " ^
    86   (if s = "genuine" then
    87      if falsify then "CounterSatisfiable" else "Satisfiable"
    88    else
    89      "Unknown")
    90   |> writeln
    91 
    92 fun refute_tptp_file file_name =
    93   let
    94     val (falsify, ts) = read_tptp_file @{theory} file_name
    95     val params =
    96       [("maxtime", "10000"),
    97        ("assms", "true"),
    98        ("expect", Nitpick.genuineN)]
    99   in
   100     Refute.refute_term @{context} params ts @{prop False}
   101     |> print_szs_from_outcome falsify
   102   end
   103 
   104 
   105 (** Sledgehammer **)
   106 
   107 fun sledgehammer_tptp_file file_name = ()
   108 
   109 
   110 (** Translator between TPTP(-like) file formats **)
   111 
   112 fun translate_tptp_file format in_file_name out_file_name = ()
   113 
   114 end;