src/HOL/TPTP/atp_problem_import.ML
author blanchet
Sun, 29 Apr 2012 11:44:33 +0200
changeset 47832 7df66b448c4a
parent 47812 bb477988edb4
child 47845 2a2bc13669bd
permissions -rw-r--r--
split into demo and competitive version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46324
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
     1
(*  Title:      HOL/TPTP/atp_problem_import.ML
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
     3
    Copyright   2012
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
     4
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
     5
Import TPTP problems as Isabelle terms or goals.
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
     6
*)
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
     7
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
     8
signature ATP_PROBLEM_IMPORT =
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
     9
sig
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
    10
  val nitpick_tptp_file : theory -> int -> string -> unit
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
    11
  val refute_tptp_file : theory -> int -> string -> unit
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
    12
  val sledgehammer_tptp_file : theory -> int -> string -> unit
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
    13
  val isabelle_demo_tptp_file : theory -> int -> string -> unit
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
    14
  val isabelle_comp_tptp_file : theory -> int -> string -> unit
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    15
  val translate_tptp_file : string -> string -> string -> unit
46324
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
    16
end;
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
    17
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
    18
structure ATP_Problem_Import : ATP_PROBLEM_IMPORT =
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
    19
struct
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
    20
47643
e33c2be488fe reintroduced old FOF and CNF parsers, to work around TPTP_Parser failures
blanchet
parents: 47565
diff changeset
    21
open ATP_Util
e33c2be488fe reintroduced old FOF and CNF parsers, to work around TPTP_Parser failures
blanchet
parents: 47565
diff changeset
    22
open ATP_Problem
e33c2be488fe reintroduced old FOF and CNF parsers, to work around TPTP_Parser failures
blanchet
parents: 47565
diff changeset
    23
open ATP_Proof
e33c2be488fe reintroduced old FOF and CNF parsers, to work around TPTP_Parser failures
blanchet
parents: 47565
diff changeset
    24
47776
024cf0f7fb6d further tweaking for Satallax, so that TPTP problems before parsing and after generation are as similar as possible/practical
blanchet
parents: 47771
diff changeset
    25
val debug = false
024cf0f7fb6d further tweaking for Satallax, so that TPTP problems before parsing and after generation are as similar as possible/practical
blanchet
parents: 47771
diff changeset
    26
val overlord = false
024cf0f7fb6d further tweaking for Satallax, so that TPTP problems before parsing and after generation are as similar as possible/practical
blanchet
parents: 47771
diff changeset
    27
47643
e33c2be488fe reintroduced old FOF and CNF parsers, to work around TPTP_Parser failures
blanchet
parents: 47565
diff changeset
    28
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
    29
(** TPTP parsing **)
47643
e33c2be488fe reintroduced old FOF and CNF parsers, to work around TPTP_Parser failures
blanchet
parents: 47565
diff changeset
    30
47565
762eb0dacaa6 remove old TPTP CNF/FOF parser; always use Nik's new parser
blanchet
parents: 47562
diff changeset
    31
(* cf. "close_form" in "refute.ML" *)
762eb0dacaa6 remove old TPTP CNF/FOF parser; always use Nik's new parser
blanchet
parents: 47562
diff changeset
    32
fun close_form t =
762eb0dacaa6 remove old TPTP CNF/FOF parser; always use Nik's new parser
blanchet
parents: 47562
diff changeset
    33
  fold (fn ((s, i), T) => fn t' =>
762eb0dacaa6 remove old TPTP CNF/FOF parser; always use Nik's new parser
blanchet
parents: 47562
diff changeset
    34
           Logic.all_const T $ Abs (s, T, abstract_over (Var ((s, i), T), t')))
762eb0dacaa6 remove old TPTP CNF/FOF parser; always use Nik's new parser
blanchet
parents: 47562
diff changeset
    35
       (Term.add_vars t []) t
46324
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
    36
47785
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
    37
fun read_tptp_file thy postproc file_name =
47644
2d90e10f61f2 prepend PWD to relative paths
blanchet
parents: 47643
diff changeset
    38
  let
47718
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    39
    fun has_role role (_, role', _, _) = (role' = role)
47785
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
    40
    fun get_prop (_, _, P, _) =
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
    41
      P |> Logic.varify_global |> close_form |> postproc
47644
2d90e10f61f2 prepend PWD to relative paths
blanchet
parents: 47643
diff changeset
    42
    val path =
2d90e10f61f2 prepend PWD to relative paths
blanchet
parents: 47643
diff changeset
    43
      Path.explode file_name
2d90e10f61f2 prepend PWD to relative paths
blanchet
parents: 47643
diff changeset
    44
      |> (fn path =>
2d90e10f61f2 prepend PWD to relative paths
blanchet
parents: 47643
diff changeset
    45
             path |> not (Path.is_absolute path)
2d90e10f61f2 prepend PWD to relative paths
blanchet
parents: 47643
diff changeset
    46
                     ? Path.append (Path.explode "$PWD"))
47714
d6683fe037b1 get rid of old parser, hopefully for good
blanchet
parents: 47670
diff changeset
    47
    val ((_, _, problem), thy) =
d6683fe037b1 get rid of old parser, hopefully for good
blanchet
parents: 47670
diff changeset
    48
      TPTP_Interpret.interpret_file true (Path.explode "$TPTP") path [] [] thy
47718
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    49
    val (conjs, defs_and_nondefs) =
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    50
      problem |> List.partition (has_role TPTP_Syntax.Role_Conjecture)
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    51
              ||> List.partition (has_role TPTP_Syntax.Role_Definition)
47644
2d90e10f61f2 prepend PWD to relative paths
blanchet
parents: 47643
diff changeset
    52
  in
47718
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    53
    (map get_prop conjs, pairself (map get_prop) defs_and_nondefs,
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
    54
     thy |> Theory.checkpoint |> Proof_Context.init_global)
47557
32f35b3d9e42 started integrating Nik's parser into TPTP command-line tools
blanchet
parents: 46325
diff changeset
    55
  end
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    56
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
    57
46324
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
    58
(** Nitpick (alias Nitrox) **)
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
    59
47718
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    60
fun aptrueprop f ((t0 as @{const Trueprop}) $ t1) = t0 $ f t1
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    61
  | aptrueprop f t = f t
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    62
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
    63
fun nitpick_tptp_file thy timeout file_name =
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    64
  let
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
    65
    val (conjs, (defs, nondefs), ctxt) = read_tptp_file thy I file_name
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
    66
    val thy = Proof_Context.theory_of ctxt
47718
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    67
    val defs = defs |> map (ATP_Util.extensionalize_term ctxt
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    68
                            #> aptrueprop (open_form I))
47714
d6683fe037b1 get rid of old parser, hopefully for good
blanchet
parents: 47670
diff changeset
    69
    val state = Proof.init ctxt
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    70
    val params =
47557
32f35b3d9e42 started integrating Nik's parser into TPTP command-line tools
blanchet
parents: 46325
diff changeset
    71
      [("card", "1\<emdash>100"),
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    72
       ("box", "false"),
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    73
       ("max_threads", "1"),
47791
c17cc1380642 smaller batches, to play safe
blanchet
parents: 47788
diff changeset
    74
       ("batch_size", "5"),
47718
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    75
       ("falsify", if null conjs then "false" else "true"),
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    76
       ("verbose", "true"),
47776
024cf0f7fb6d further tweaking for Satallax, so that TPTP problems before parsing and after generation are as similar as possible/practical
blanchet
parents: 47771
diff changeset
    77
       ("debug", if debug then "true" else "false"),
024cf0f7fb6d further tweaking for Satallax, so that TPTP problems before parsing and after generation are as similar as possible/practical
blanchet
parents: 47771
diff changeset
    78
       ("overlord", if overlord then "true" else "false"),
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    79
       ("show_consts", "true"),
47755
df437d1bf8db tweak TPTP Nitpick's output
blanchet
parents: 47718
diff changeset
    80
       ("format", "1"),
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    81
       ("max_potential", "0"),
47718
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    82
       ("timeout", string_of_int timeout),
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    83
       ("tac_timeout", string_of_int ((timeout + 49) div 50))]
47714
d6683fe037b1 get rid of old parser, hopefully for good
blanchet
parents: 47670
diff changeset
    84
      |> Nitpick_Isar.default_params thy
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    85
    val i = 1
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    86
    val n = 1
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    87
    val step = 0
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    88
    val subst = []
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    89
  in
47715
04400144c6fc handle TPTP definitions as definitions in Nitpick rather than as axioms
blanchet
parents: 47714
diff changeset
    90
    Nitpick.pick_nits_in_term state params Nitpick.TPTP i n step subst
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
    91
        defs nondefs (case conjs of conj :: _ => conj | [] => @{prop True});
47718
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
    92
    ()
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    93
  end
46324
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
    94
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
    95
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
    96
(** Refute **)
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
    97
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
    98
fun refute_tptp_file thy timeout file_name =
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
    99
  let
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   100
    fun print_szs_from_outcome falsify s =
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   101
      "% SZS status " ^
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   102
      (if s = "genuine" then
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   103
         if falsify then "CounterSatisfiable" else "Satisfiable"
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   104
       else
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   105
         "Unknown")
47788
blanchet
parents: 47785
diff changeset
   106
      |> Output.urgent_message
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   107
    val (conjs, (defs, nondefs), ctxt) = read_tptp_file thy I file_name
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
   108
    val params =
47714
d6683fe037b1 get rid of old parser, hopefully for good
blanchet
parents: 47670
diff changeset
   109
      [("maxtime", string_of_int timeout),
d6683fe037b1 get rid of old parser, hopefully for good
blanchet
parents: 47670
diff changeset
   110
       ("maxvars", "100000")]
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
   111
  in
47718
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
   112
    Refute.refute_term ctxt params (defs @ nondefs)
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   113
        (case conjs of conj :: _ => conj | [] => @{prop True})
47718
39229c760636 smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
blanchet
parents: 47715
diff changeset
   114
    |> print_szs_from_outcome (not (null conjs))
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
   115
  end
46324
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
   116
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
   117
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   118
(** Sledgehammer and Isabelle (combination of provers) **)
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   119
47785
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
   120
fun can_tac ctxt tactic conj = can (Goal.prove ctxt [] [] conj) (K tactic)
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
   121
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   122
fun SOLVE_TIMEOUT seconds name tac st =
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   123
  let
47788
blanchet
parents: 47785
diff changeset
   124
    val _ = Output.urgent_message ("running " ^ name ^ " for " ^
blanchet
parents: 47785
diff changeset
   125
                                   string_of_int seconds ^ " s")
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   126
    val result =
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   127
      TimeLimit.timeLimit (Time.fromSeconds seconds)
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   128
        (fn () => SINGLE (SOLVE tac) st) ()
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   129
      handle TimeLimit.TimeOut => NONE
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   130
        | ERROR _ => NONE
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   131
  in
47785
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
   132
    case result of
47788
blanchet
parents: 47785
diff changeset
   133
      NONE => (Output.urgent_message ("FAILURE: " ^ name); Seq.empty)
blanchet
parents: 47785
diff changeset
   134
    | SOME st' => (Output.urgent_message ("SUCCESS: " ^ name); Seq.single st')
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   135
  end
46324
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
   136
47812
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   137
fun nitpick_finite_oracle_tac ctxt timeout i th =
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   138
  let
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   139
    fun is_safe (Type (@{type_name fun}, Ts)) = forall is_safe Ts
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   140
      | is_safe @{typ prop} = true
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   141
      | is_safe @{typ bool} = true
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   142
      | is_safe _ = false
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   143
    val conj = Thm.term_of (Thm.cprem_of th i)
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   144
  in
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   145
    if exists_type (not o is_safe) conj then
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   146
      Seq.empty
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   147
    else
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   148
      let
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   149
        val thy = Proof_Context.theory_of ctxt
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   150
        val state = Proof.init ctxt
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   151
        val params =
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   152
          [("box", "false"),
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   153
           ("max_threads", "1"),
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   154
           ("verbose", "true"),
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   155
           ("debug", if debug then "true" else "false"),
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   156
           ("overlord", if overlord then "true" else "false"),
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   157
           ("max_potential", "0"),
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   158
           ("timeout", string_of_int timeout)]
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   159
          |> Nitpick_Isar.default_params thy
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   160
        val i = 1
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   161
        val n = 1
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   162
        val step = 0
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   163
        val subst = []
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   164
        val (outcome, _) =
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   165
          Nitpick.pick_nits_in_term state params Nitpick.Normal i n step subst
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   166
                                    [] [] conj
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   167
      in if outcome = "none" then Skip_Proof.cheat_tac thy th else Seq.empty end
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   168
  end
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   169
47788
blanchet
parents: 47785
diff changeset
   170
fun atp_tac ctxt override_params timeout prover =
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   171
  Sledgehammer_Tactics.sledgehammer_as_oracle_tac ctxt
47788
blanchet
parents: 47785
diff changeset
   172
      ([("debug", if debug then "true" else "false"),
blanchet
parents: 47785
diff changeset
   173
        ("overlord", if overlord then "true" else "false"),
blanchet
parents: 47785
diff changeset
   174
        ("provers", prover),
blanchet
parents: 47785
diff changeset
   175
        ("timeout", string_of_int timeout)] @ override_params)
47811
1e8eb643540d add extensionality to first-order provers
blanchet
parents: 47794
diff changeset
   176
      {add = [(Facts.named (Thm.derivation_name ext), [])],
1e8eb643540d add extensionality to first-order provers
blanchet
parents: 47794
diff changeset
   177
       del = [], only = true}
47765
18f37b7aa6a6 more work on CASC setup
blanchet
parents: 47755
diff changeset
   178
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   179
fun sledgehammer_tac demo ctxt timeout i =
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   180
  let
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   181
    val frac = if demo then 6 else 4
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   182
    fun slice prover =
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   183
      SOLVE_TIMEOUT (timeout div frac) prover
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   184
                    (atp_tac ctxt [] (timeout div frac) prover i)
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   185
  in
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   186
    (if demo then
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   187
       slice ATP_Systems.satallaxN
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   188
       ORELSE slice ATP_Systems.leo2N
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   189
     else
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   190
       no_tac)
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   191
    ORELSE slice ATP_Systems.spassN
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   192
    ORELSE slice ATP_Systems.vampireN
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   193
    ORELSE slice ATP_Systems.eN
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   194
    ORELSE slice ATP_Systems.z3_tptpN
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   195
  end
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   196
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   197
fun smt_solver_tac solver ctxt =
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   198
  let
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   199
    val ctxt = ctxt |> Context.proof_map (SMT_Config.select_solver solver)
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   200
  in SMT_Solver.smt_tac ctxt [] end
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   201
47785
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
   202
fun auto_etc_tac ctxt timeout i =
47812
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   203
  SOLVE_TIMEOUT (timeout div 20) "nitpick"
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   204
      (nitpick_finite_oracle_tac ctxt (timeout div 20) i)
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   205
  ORELSE SOLVE_TIMEOUT (timeout div 20) "simp"
47812
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   206
      (asm_full_simp_tac (simpset_of ctxt) i)
47788
blanchet
parents: 47785
diff changeset
   207
  ORELSE SOLVE_TIMEOUT (timeout div 10) "blast" (blast_tac ctxt i)
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   208
  ORELSE SOLVE_TIMEOUT (timeout div 5) "auto+spass"
47785
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
   209
      (auto_tac ctxt
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   210
       THEN ALLGOALS (atp_tac ctxt [] (timeout div 5) ATP_Systems.spassN))
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   211
  ORELSE SOLVE_TIMEOUT (timeout div 10) "z3" (smt_solver_tac "z3" ctxt i)
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   212
  ORELSE SOLVE_TIMEOUT (timeout div 10) "cvc3" (smt_solver_tac "cvc3" ctxt i)
47812
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   213
  ORELSE SOLVE_TIMEOUT (timeout div 20) "fast" (fast_tac ctxt i)
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   214
  ORELSE SOLVE_TIMEOUT (timeout div 20) "best" (best_tac ctxt i)
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   215
  ORELSE SOLVE_TIMEOUT (timeout div 10) "force" (force_tac ctxt i)
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   216
  ORELSE SOLVE_TIMEOUT (timeout div 10) "meson" (Meson.meson_tac ctxt [] i)
47812
bb477988edb4 use Nitpick as an oracle for finite problems
blanchet
parents: 47811
diff changeset
   217
  ORELSE SOLVE_TIMEOUT (timeout div 10) "fastforce" (fast_force_tac ctxt i)
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
   218
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   219
fun problem_const_prefix thy = Context.theory_name thy ^ Long_Name.separator
47785
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
   220
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
   221
(* Isabelle's standard automatic tactics ("auto", etc.) are more eager to
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
   222
   unfold "definitions" of free variables than of constants (cf. PUZ107^5). *)
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   223
fun freeze_problem_consts thy =
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   224
  let val is_problem_const = String.isPrefix (problem_const_prefix thy) in
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   225
    map_aterms (fn t as Const (s, T) =>
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   226
                   if is_problem_const s then Free (Long_Name.base_name s, T)
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   227
                   else t
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   228
                 | t => t)
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   229
  end
47785
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
   230
47776
024cf0f7fb6d further tweaking for Satallax, so that TPTP problems before parsing and after generation are as similar as possible/practical
blanchet
parents: 47771
diff changeset
   231
fun make_conj (defs, nondefs) conjs =
024cf0f7fb6d further tweaking for Satallax, so that TPTP problems before parsing and after generation are as similar as possible/practical
blanchet
parents: 47771
diff changeset
   232
  Logic.list_implies (rev defs @ rev nondefs,
024cf0f7fb6d further tweaking for Satallax, so that TPTP problems before parsing and after generation are as similar as possible/practical
blanchet
parents: 47771
diff changeset
   233
                      case conjs of conj :: _ => conj | [] => @{prop False})
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
   234
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
   235
fun print_szs_from_success conjs success =
47788
blanchet
parents: 47785
diff changeset
   236
  Output.urgent_message ("% SZS status " ^
blanchet
parents: 47785
diff changeset
   237
                         (if success then
blanchet
parents: 47785
diff changeset
   238
                            if null conjs then "Unsatisfiable" else "Theorem"
blanchet
parents: 47785
diff changeset
   239
                          else
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   240
                            "Unknown"))
47765
18f37b7aa6a6 more work on CASC setup
blanchet
parents: 47755
diff changeset
   241
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   242
fun sledgehammer_tptp_file thy timeout file_name =
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
   243
  let
47785
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
   244
    val (conjs, assms, ctxt) =
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   245
      read_tptp_file thy (freeze_problem_consts thy) file_name
47776
024cf0f7fb6d further tweaking for Satallax, so that TPTP problems before parsing and after generation are as similar as possible/practical
blanchet
parents: 47771
diff changeset
   246
    val conj = make_conj assms conjs
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
   247
  in
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   248
    can_tac ctxt (sledgehammer_tac true ctxt timeout 1) conj
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
   249
    |> print_szs_from_success conjs
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
   250
  end
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47765
diff changeset
   251
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   252
fun isabelle_tptp_file demo thy timeout file_name =
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
   253
  let
47785
d27bb852c430 more tweaking of TPTP/CASC setup
blanchet
parents: 47776
diff changeset
   254
    val (conjs, assms, ctxt) =
47794
4ad62c5f9f88 thread theory cleanly and use "smt" method rather than Sledgehammer for Z3 (because of obscure debilitating bug)
blanchet
parents: 47793
diff changeset
   255
      read_tptp_file thy (freeze_problem_consts thy) file_name
47776
024cf0f7fb6d further tweaking for Satallax, so that TPTP problems before parsing and after generation are as similar as possible/practical
blanchet
parents: 47771
diff changeset
   256
    val conj = make_conj assms conjs
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   257
    val last_hope = if demo then ATP_Systems.satallaxN else ATP_Systems.spassN
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
   258
  in
47811
1e8eb643540d add extensionality to first-order provers
blanchet
parents: 47794
diff changeset
   259
    (can_tac ctxt (auto_etc_tac ctxt (timeout div 2) 1) conj orelse
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   260
     can_tac ctxt (sledgehammer_tac demo ctxt (timeout div 2) 1) conj orelse
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   261
     can_tac ctxt (atp_tac ctxt [] timeout last_hope 1) conj)
47771
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
   262
    |> print_szs_from_success conjs
ba321ce6f344 tuning; no need for relevance filter
blanchet
parents: 47766
diff changeset
   263
  end
46324
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
   264
47832
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   265
val isabelle_demo_tptp_file = isabelle_tptp_file true
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   266
val isabelle_comp_tptp_file = isabelle_tptp_file false
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   267
7df66b448c4a split into demo and competitive version
blanchet
parents: 47812
diff changeset
   268
46324
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
   269
(** Translator between TPTP(-like) file formats **)
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
   270
46325
b170ab46513a implemented "tptp_refute" tool
blanchet
parents: 46324
diff changeset
   271
fun translate_tptp_file format in_file_name out_file_name = ()
46324
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
   272
e4bccf5ec61e added problem importer
blanchet
parents:
diff changeset
   273
end;