src/HOL/Tools/ATP_Manager/atp_problem.ML
changeset 38297 ee7c3c0b0d13
parent 38277 ac704f1c8dde
parent 38296 0511f2e62363
child 38302 6f89490e8eea
child 38307 685d1f0f75b3
     1.1 --- a/src/HOL/Tools/ATP_Manager/atp_problem.ML	Wed Jul 28 11:42:48 2010 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,152 +0,0 @@
     1.4 -(*  Title:      HOL/Tools/ATP_Manager/atp_problem.ML
     1.5 -    Author:     Jia Meng, Cambridge University Computer Laboratory and NICTA
     1.6 -    Author:     Jasmin Blanchette, TU Muenchen
     1.7 -
     1.8 -TPTP syntax.
     1.9 -*)
    1.10 -
    1.11 -signature ATP_PROBLEM =
    1.12 -sig
    1.13 -  datatype 'a fo_term = ATerm of 'a * 'a fo_term list
    1.14 -  datatype quantifier = AForall | AExists
    1.15 -  datatype connective = ANot | AAnd | AOr | AImplies | AIf | AIff | ANotIff
    1.16 -  datatype ('a, 'b) formula =
    1.17 -    AQuant of quantifier * 'a list * ('a, 'b) formula |
    1.18 -    AConn of connective * ('a, 'b) formula list |
    1.19 -    APred of 'b
    1.20 -
    1.21 -  datatype kind = Axiom | Conjecture
    1.22 -  datatype 'a problem_line = Fof of string * kind * ('a, 'a fo_term) formula
    1.23 -  type 'a problem = (string * 'a problem_line list) list
    1.24 -
    1.25 -  val timestamp : unit -> string
    1.26 -  val is_tptp_variable : string -> bool
    1.27 -  val strings_for_tptp_problem :
    1.28 -    (string * string problem_line list) list -> string list
    1.29 -  val nice_tptp_problem :
    1.30 -    bool -> ('a * (string * string) problem_line list) list
    1.31 -    -> ('a * string problem_line list) list
    1.32 -       * (string Symtab.table * string Symtab.table) option
    1.33 -end;
    1.34 -
    1.35 -structure ATP_Problem : ATP_PROBLEM =
    1.36 -struct
    1.37 -
    1.38 -(** ATP problem **)
    1.39 -
    1.40 -datatype 'a fo_term = ATerm of 'a * 'a fo_term list
    1.41 -datatype quantifier = AForall | AExists
    1.42 -datatype connective = ANot | AAnd | AOr | AImplies | AIf | AIff | ANotIff
    1.43 -datatype ('a, 'b) formula =
    1.44 -  AQuant of quantifier * 'a list * ('a, 'b) formula |
    1.45 -  AConn of connective * ('a, 'b) formula list |
    1.46 -  APred of 'b
    1.47 -
    1.48 -datatype kind = Axiom | Conjecture
    1.49 -datatype 'a problem_line = Fof of string * kind * ('a, 'a fo_term) formula
    1.50 -type 'a problem = (string * 'a problem_line list) list
    1.51 -
    1.52 -val timestamp = Date.fmt "%Y-%m-%d %H:%M:%S" o Date.fromTimeLocal o Time.now
    1.53 -
    1.54 -fun string_for_term (ATerm (s, [])) = s
    1.55 -  | string_for_term (ATerm (s, ts)) =
    1.56 -    if s = "equal" then space_implode " = " (map string_for_term ts)
    1.57 -    else s ^ "(" ^ commas (map string_for_term ts) ^ ")"
    1.58 -fun string_for_quantifier AForall = "!"
    1.59 -  | string_for_quantifier AExists = "?"
    1.60 -fun string_for_connective ANot = "~"
    1.61 -  | string_for_connective AAnd = "&"
    1.62 -  | string_for_connective AOr = "|"
    1.63 -  | string_for_connective AImplies = "=>"
    1.64 -  | string_for_connective AIf = "<="
    1.65 -  | string_for_connective AIff = "<=>"
    1.66 -  | string_for_connective ANotIff = "<~>"
    1.67 -fun string_for_formula (AQuant (q, xs, phi)) =
    1.68 -    string_for_quantifier q ^ "[" ^ commas xs ^ "] : " ^
    1.69 -    string_for_formula phi
    1.70 -  | string_for_formula (AConn (ANot, [APred (ATerm ("equal", ts))])) =
    1.71 -    space_implode " != " (map string_for_term ts)
    1.72 -  | string_for_formula (AConn (c, [phi])) =
    1.73 -    string_for_connective c ^ " " ^ string_for_formula phi
    1.74 -  | string_for_formula (AConn (c, phis)) =
    1.75 -    "(" ^ space_implode (" " ^ string_for_connective c ^ " ")
    1.76 -                        (map string_for_formula phis) ^ ")"
    1.77 -  | string_for_formula (APred tm) = string_for_term tm
    1.78 -
    1.79 -fun string_for_problem_line (Fof (ident, kind, phi)) =
    1.80 -  "fof(" ^ ident ^ ", " ^
    1.81 -  (case kind of Axiom => "axiom" | Conjecture => "conjecture") ^ ",\n" ^
    1.82 -  "    (" ^ string_for_formula phi ^ ")).\n"
    1.83 -fun strings_for_tptp_problem problem =
    1.84 -  "% This file was generated by Isabelle (most likely Sledgehammer)\n\
    1.85 -  \% " ^ timestamp () ^ "\n" ::
    1.86 -  maps (fn (_, []) => []
    1.87 -         | (heading, lines) =>
    1.88 -           "\n% " ^ heading ^ " (" ^ Int.toString (length lines) ^ ")\n" ::
    1.89 -           map string_for_problem_line lines) problem
    1.90 -
    1.91 -fun is_tptp_variable s = Char.isUpper (String.sub (s, 0))
    1.92 -
    1.93 -
    1.94 -(** Nice names **)
    1.95 -
    1.96 -fun empty_name_pool readable_names =
    1.97 -  if readable_names then SOME (Symtab.empty, Symtab.empty) else NONE
    1.98 -
    1.99 -fun pool_fold f xs z = pair z #> fold_rev (fn x => uncurry (f x)) xs
   1.100 -fun pool_map f xs =
   1.101 -  pool_fold (fn x => fn ys => fn pool => f x pool |>> (fn y => y :: ys)) xs []
   1.102 -
   1.103 -(* "equal" is reserved by some ATPs. "op" is also reserved, to avoid the
   1.104 -   unreadable "op_1", "op_2", etc., in the problem files. *)
   1.105 -val reserved_nice_names = ["equal", "op"]
   1.106 -fun readable_name full_name s =
   1.107 -  if s = full_name then
   1.108 -    s
   1.109 -  else
   1.110 -    let
   1.111 -      val s = s |> Long_Name.base_name
   1.112 -                |> Name.desymbolize (Char.isUpper (String.sub (full_name, 0)))
   1.113 -    in if member (op =) reserved_nice_names s then full_name else s end
   1.114 -
   1.115 -fun nice_name (full_name, _) NONE = (full_name, NONE)
   1.116 -  | nice_name (full_name, desired_name) (SOME the_pool) =
   1.117 -    case Symtab.lookup (fst the_pool) full_name of
   1.118 -      SOME nice_name => (nice_name, SOME the_pool)
   1.119 -    | NONE =>
   1.120 -      let
   1.121 -        val nice_prefix = readable_name full_name desired_name
   1.122 -        fun add j =
   1.123 -          let
   1.124 -            val nice_name = nice_prefix ^
   1.125 -                            (if j = 0 then "" else "_" ^ Int.toString j)
   1.126 -          in
   1.127 -            case Symtab.lookup (snd the_pool) nice_name of
   1.128 -              SOME full_name' =>
   1.129 -              if full_name = full_name' then (nice_name, the_pool)
   1.130 -              else add (j + 1)
   1.131 -            | NONE =>
   1.132 -              (nice_name,
   1.133 -               (Symtab.update_new (full_name, nice_name) (fst the_pool),
   1.134 -                Symtab.update_new (nice_name, full_name) (snd the_pool)))
   1.135 -          end
   1.136 -      in add 0 |> apsnd SOME end
   1.137 -
   1.138 -
   1.139 -fun nice_term (ATerm (name, ts)) =
   1.140 -  nice_name name ##>> pool_map nice_term ts #>> ATerm
   1.141 -fun nice_formula (AQuant (q, xs, phi)) =
   1.142 -    pool_map nice_name xs ##>> nice_formula phi
   1.143 -    #>> (fn (xs, phi) => AQuant (q, xs, phi))
   1.144 -  | nice_formula (AConn (c, phis)) =
   1.145 -    pool_map nice_formula phis #>> curry AConn c
   1.146 -  | nice_formula (APred tm) = nice_term tm #>> APred
   1.147 -fun nice_problem_line (Fof (ident, kind, phi)) =
   1.148 -  nice_formula phi #>> (fn phi => Fof (ident, kind, phi))
   1.149 -fun nice_problem problem =
   1.150 -  pool_map (fn (heading, lines) =>
   1.151 -               pool_map nice_problem_line lines #>> pair heading) problem
   1.152 -fun nice_tptp_problem readable_names problem =
   1.153 -  nice_problem problem (empty_name_pool readable_names)
   1.154 -
   1.155 -end;