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