src/HOL/Tools/ATP/atp_problem.ML
author blanchet
Sun, 22 Aug 2010 09:43:10 +0200
changeset 38631 979a0b37f981
parent 38613 4ca2cae2653f
child 39109 ceee95f41823
permissions -rw-r--r--
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible; the disjunctive view of "conjecture" is nonstandard but taken by E, SPASS, Vampire, etc.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38047
9033c03cc214 consequence of directory renaming
blanchet
parents: 38046
diff changeset
     1
(*  Title:      HOL/Tools/ATP/atp_problem.ML
38027
505657ddb047 standardize "Author" tags
blanchet
parents: 38025
diff changeset
     2
    Author:     Jia Meng, Cambridge University Computer Laboratory and NICTA
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff changeset
     3
    Author:     Jasmin Blanchette, TU Muenchen
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff changeset
     4
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff changeset
     5
TPTP syntax.
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff changeset
     6
*)
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff changeset
     7
38019
e207a64e1e0b complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents: 38018
diff changeset
     8
signature ATP_PROBLEM =
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff changeset
     9
sig
37992
7911e78a7122 renamed internal function
blanchet
parents: 37962
diff changeset
    10
  datatype 'a fo_term = ATerm of 'a * 'a fo_term list
7911e78a7122 renamed internal function
blanchet
parents: 37962
diff changeset
    11
  datatype quantifier = AForall | AExists
7911e78a7122 renamed internal function
blanchet
parents: 37962
diff changeset
    12
  datatype connective = ANot | AAnd | AOr | AImplies | AIf | AIff | ANotIff
37994
b04307085a09 make TPTP generator accept full first-order formulas
blanchet
parents: 37993
diff changeset
    13
  datatype ('a, 'b) formula =
b04307085a09 make TPTP generator accept full first-order formulas
blanchet
parents: 37993
diff changeset
    14
    AQuant of quantifier * 'a list * ('a, 'b) formula |
b04307085a09 make TPTP generator accept full first-order formulas
blanchet
parents: 37993
diff changeset
    15
    AConn of connective * ('a, 'b) formula list |
38034
ecae87b9b9c4 renaming
blanchet
parents: 38027
diff changeset
    16
    AAtom of 'b
37994
b04307085a09 make TPTP generator accept full first-order formulas
blanchet
parents: 37993
diff changeset
    17
38613
4ca2cae2653f use "hypothesis" rather than "conjecture" for hypotheses in TPTP format;
blanchet
parents: 38489
diff changeset
    18
  datatype kind = Axiom | Hypothesis | Conjecture
38017
3ad3e3ca2451 move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents: 38014
diff changeset
    19
  datatype 'a problem_line = Fof of string * kind * ('a, 'a fo_term) formula
3ad3e3ca2451 move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents: 38014
diff changeset
    20
  type 'a problem = (string * 'a problem_line list) list
37992
7911e78a7122 renamed internal function
blanchet
parents: 37962
diff changeset
    21
38019
e207a64e1e0b complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents: 38018
diff changeset
    22
  val timestamp : unit -> string
38017
3ad3e3ca2451 move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents: 38014
diff changeset
    23
  val is_tptp_variable : string -> bool
3ad3e3ca2451 move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents: 38014
diff changeset
    24
  val strings_for_tptp_problem :
38631
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    25
    bool -> (string * string problem_line list) list -> string list
38017
3ad3e3ca2451 move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents: 38014
diff changeset
    26
  val nice_tptp_problem :
3ad3e3ca2451 move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents: 38014
diff changeset
    27
    bool -> ('a * (string * string) problem_line list) list
3ad3e3ca2451 move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents: 38014
diff changeset
    28
    -> ('a * string problem_line list) list
3ad3e3ca2451 move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents: 38014
diff changeset
    29
       * (string Symtab.table * string Symtab.table) option
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff changeset
    30
end;
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff changeset
    31
38019
e207a64e1e0b complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents: 38018
diff changeset
    32
structure ATP_Problem : ATP_PROBLEM =
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff changeset
    33
struct
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff changeset
    34
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
    35
(** ATP problem **)
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
    36
37961
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    37
datatype 'a fo_term = ATerm of 'a * 'a fo_term list
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    38
datatype quantifier = AForall | AExists
37992
7911e78a7122 renamed internal function
blanchet
parents: 37962
diff changeset
    39
datatype connective = ANot | AAnd | AOr | AImplies | AIf | AIff | ANotIff
37994
b04307085a09 make TPTP generator accept full first-order formulas
blanchet
parents: 37993
diff changeset
    40
datatype ('a, 'b) formula =
b04307085a09 make TPTP generator accept full first-order formulas
blanchet
parents: 37993
diff changeset
    41
  AQuant of quantifier * 'a list * ('a, 'b) formula |
b04307085a09 make TPTP generator accept full first-order formulas
blanchet
parents: 37993
diff changeset
    42
  AConn of connective * ('a, 'b) formula list |
38034
ecae87b9b9c4 renaming
blanchet
parents: 38027
diff changeset
    43
  AAtom of 'b
37961
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    44
38613
4ca2cae2653f use "hypothesis" rather than "conjecture" for hypotheses in TPTP format;
blanchet
parents: 38489
diff changeset
    45
datatype kind = Axiom | Hypothesis | Conjecture
37994
b04307085a09 make TPTP generator accept full first-order formulas
blanchet
parents: 37993
diff changeset
    46
datatype 'a problem_line = Fof of string * kind * ('a, 'a fo_term) formula
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
    47
type 'a problem = (string * 'a problem_line list) list
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
    48
38019
e207a64e1e0b complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents: 38018
diff changeset
    49
val timestamp = Date.fmt "%Y-%m-%d %H:%M:%S" o Date.fromTimeLocal o Time.now
e207a64e1e0b complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents: 38018
diff changeset
    50
38631
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    51
fun string_for_kind Axiom = "axiom"
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    52
  | string_for_kind Hypothesis = "hypothesis"
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    53
  | string_for_kind Conjecture = "conjecture"
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    54
37961
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    55
fun string_for_term (ATerm (s, [])) = s
38088
a9847fb539dd fix bug with "=" vs. "fequal" introduced by last change (dddb8ba3a1ce)
blanchet
parents: 38047
diff changeset
    56
  | string_for_term (ATerm ("equal", ts)) =
a9847fb539dd fix bug with "=" vs. "fequal" introduced by last change (dddb8ba3a1ce)
blanchet
parents: 38047
diff changeset
    57
    space_implode " = " (map string_for_term ts)
37961
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    58
  | string_for_term (ATerm (s, ts)) =
38088
a9847fb539dd fix bug with "=" vs. "fequal" introduced by last change (dddb8ba3a1ce)
blanchet
parents: 38047
diff changeset
    59
    s ^ "(" ^ commas (map string_for_term ts) ^ ")"
37961
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    60
fun string_for_quantifier AForall = "!"
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    61
  | string_for_quantifier AExists = "?"
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    62
fun string_for_connective ANot = "~"
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    63
  | string_for_connective AAnd = "&"
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    64
  | string_for_connective AOr = "|"
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    65
  | string_for_connective AImplies = "=>"
37992
7911e78a7122 renamed internal function
blanchet
parents: 37962
diff changeset
    66
  | string_for_connective AIf = "<="
37961
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    67
  | string_for_connective AIff = "<=>"
37992
7911e78a7122 renamed internal function
blanchet
parents: 37962
diff changeset
    68
  | string_for_connective ANotIff = "<~>"
37961
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    69
fun string_for_formula (AQuant (q, xs, phi)) =
38489
124193c26751 more parentheses in TPTP formulas, just in case
blanchet
parents: 38088
diff changeset
    70
    "(" ^ string_for_quantifier q ^ "[" ^ commas xs ^ "] : " ^
124193c26751 more parentheses in TPTP formulas, just in case
blanchet
parents: 38088
diff changeset
    71
    string_for_formula phi ^ ")"
38034
ecae87b9b9c4 renaming
blanchet
parents: 38027
diff changeset
    72
  | string_for_formula (AConn (ANot, [AAtom (ATerm ("equal", ts))])) =
38005
b6555e9c5de4 prevent schematic variable clash in combinator-introduction code, when invoked from Sledgehammer (another consequence of the CNF -> FOF transition)
blanchet
parents: 38004
diff changeset
    73
    space_implode " != " (map string_for_term ts)
37961
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    74
  | string_for_formula (AConn (c, [phi])) =
38489
124193c26751 more parentheses in TPTP formulas, just in case
blanchet
parents: 38088
diff changeset
    75
    "(" ^ string_for_connective c ^ " " ^ string_for_formula phi ^ ")"
37961
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    76
  | string_for_formula (AConn (c, phis)) =
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    77
    "(" ^ space_implode (" " ^ string_for_connective c ^ " ")
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    78
                        (map string_for_formula phis) ^ ")"
38034
ecae87b9b9c4 renaming
blanchet
parents: 38027
diff changeset
    79
  | string_for_formula (AAtom tm) = string_for_term tm
37961
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
    80
38631
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    81
fun string_for_problem_line use_conjecture_for_hypotheses
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    82
                            (Fof (ident, kind, phi)) =
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    83
  let
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    84
    val (kind, phi) =
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    85
      if kind = Hypothesis andalso use_conjecture_for_hypotheses then
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    86
        (Conjecture, AConn (ANot, [phi]))
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    87
      else
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    88
        (kind, phi)
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    89
  in
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    90
    "fof(" ^ ident ^ ", " ^ string_for_kind kind ^ ",\n    (" ^
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    91
    string_for_formula phi ^ ")).\n"
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    92
  end
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    93
fun strings_for_tptp_problem use_conjecture_for_hypotheses problem =
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
    94
  "% This file was generated by Isabelle (most likely Sledgehammer)\n\
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
    95
  \% " ^ timestamp () ^ "\n" ::
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
    96
  maps (fn (_, []) => []
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
    97
         | (heading, lines) =>
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
    98
           "\n% " ^ heading ^ " (" ^ Int.toString (length lines) ^ ")\n" ::
38631
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
    99
           map (string_for_problem_line use_conjecture_for_hypotheses) lines)
979a0b37f981 prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents: 38613
diff changeset
   100
       problem
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   101
38017
3ad3e3ca2451 move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents: 38014
diff changeset
   102
fun is_tptp_variable s = Char.isUpper (String.sub (s, 0))
3ad3e3ca2451 move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents: 38014
diff changeset
   103
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   104
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   105
(** Nice names **)
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   106
37624
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   107
fun empty_name_pool readable_names =
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   108
  if readable_names then SOME (Symtab.empty, Symtab.empty) else NONE
37624
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   109
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   110
fun pool_fold f xs z = pair z #> fold_rev (fn x => uncurry (f x)) xs
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   111
fun pool_map f xs =
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   112
  pool_fold (fn x => fn ys => fn pool => f x pool |>> (fn y => y :: ys)) xs []
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   113
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   114
(* "equal" is reserved by some ATPs. "op" is also reserved, to avoid the
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   115
   unreadable "op_1", "op_2", etc., in the problem files. *)
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   116
val reserved_nice_names = ["equal", "op"]
37624
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   117
fun readable_name full_name s =
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   118
  if s = full_name then
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   119
    s
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   120
  else
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   121
    let
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   122
      val s = s |> Long_Name.base_name
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   123
                |> Name.desymbolize (Char.isUpper (String.sub (full_name, 0)))
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   124
    in if member (op =) reserved_nice_names s then full_name else s end
37624
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   125
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   126
fun nice_name (full_name, _) NONE = (full_name, NONE)
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   127
  | nice_name (full_name, desired_name) (SOME the_pool) =
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   128
    case Symtab.lookup (fst the_pool) full_name of
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   129
      SOME nice_name => (nice_name, SOME the_pool)
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   130
    | NONE =>
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   131
      let
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   132
        val nice_prefix = readable_name full_name desired_name
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   133
        fun add j =
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   134
          let
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   135
            val nice_name = nice_prefix ^
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   136
                            (if j = 0 then "" else "_" ^ Int.toString j)
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   137
          in
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   138
            case Symtab.lookup (snd the_pool) nice_name of
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   139
              SOME full_name' =>
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   140
              if full_name = full_name' then (nice_name, the_pool)
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   141
              else add (j + 1)
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   142
            | NONE =>
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   143
              (nice_name,
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   144
               (Symtab.update_new (full_name, nice_name) (fst the_pool),
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   145
                Symtab.update_new (nice_name, full_name) (snd the_pool)))
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   146
          end
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   147
      in add 0 |> apsnd SOME end
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37617
diff changeset
   148
37961
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
   149
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
   150
fun nice_term (ATerm (name, ts)) =
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
   151
  nice_name name ##>> pool_map nice_term ts #>> ATerm
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
   152
fun nice_formula (AQuant (q, xs, phi)) =
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
   153
    pool_map nice_name xs ##>> nice_formula phi
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
   154
    #>> (fn (xs, phi) => AQuant (q, xs, phi))
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
   155
  | nice_formula (AConn (c, phis)) =
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
   156
    pool_map nice_formula phis #>> curry AConn c
38034
ecae87b9b9c4 renaming
blanchet
parents: 38027
diff changeset
   157
  | nice_formula (AAtom tm) = nice_term tm #>> AAtom
37961
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
   158
fun nice_problem_line (Fof (ident, kind, phi)) =
6a48c85a211a first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents: 37931
diff changeset
   159
  nice_formula phi #>> (fn phi => Fof (ident, kind, phi))
37931
7b452ff6bff0 no polymorphic "var"s
blanchet
parents: 37926
diff changeset
   160
fun nice_problem problem =
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37642
diff changeset
   161
  pool_map (fn (heading, lines) =>
37931
7b452ff6bff0 no polymorphic "var"s
blanchet
parents: 37926
diff changeset
   162
               pool_map nice_problem_line lines #>> pair heading) problem
38017
3ad3e3ca2451 move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents: 38014
diff changeset
   163
fun nice_tptp_problem readable_names problem =
3ad3e3ca2451 move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents: 38014
diff changeset
   164
  nice_problem problem (empty_name_pool readable_names)
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff changeset
   165
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff changeset
   166
end;