src/HOL/Tools/ATP/atp_problem.ML
changeset 41769 eb2e39555f98
parent 41491 a2ad5b824051
child 42227 662b50b7126f
equal deleted inserted replaced
41768:dd2125fb75f9 41769:eb2e39555f98
    14     AQuant of quantifier * 'a list * ('a, 'b) formula |
    14     AQuant of quantifier * 'a list * ('a, 'b) formula |
    15     AConn of connective * ('a, 'b) formula list |
    15     AConn of connective * ('a, 'b) formula list |
    16     AAtom of 'b
    16     AAtom of 'b
    17   type 'a uniform_formula = ('a, 'a fo_term) formula
    17   type 'a uniform_formula = ('a, 'a fo_term) formula
    18 
    18 
    19   datatype kind = Axiom | Hypothesis | Conjecture
    19   datatype kind = Axiom | Definition | Lemma | Hypothesis | Conjecture
    20   datatype 'a problem_line = Fof of string * kind * ('a, 'a fo_term) formula
    20   datatype 'a problem_line =
       
    21     Fof of string * kind * ('a, 'a fo_term) formula * string fo_term option
    21   type 'a problem = (string * 'a problem_line list) list
    22   type 'a problem = (string * 'a problem_line list) list
    22 
    23 
    23   val timestamp : unit -> string
    24   val timestamp : unit -> string
    24   val is_atp_variable : string -> bool
    25   val is_atp_variable : string -> bool
    25   val tptp_strings_for_atp_problem :
    26   val tptp_strings_for_atp_problem :
    42   AQuant of quantifier * 'a list * ('a, 'b) formula |
    43   AQuant of quantifier * 'a list * ('a, 'b) formula |
    43   AConn of connective * ('a, 'b) formula list |
    44   AConn of connective * ('a, 'b) formula list |
    44   AAtom of 'b
    45   AAtom of 'b
    45 type 'a uniform_formula = ('a, 'a fo_term) formula
    46 type 'a uniform_formula = ('a, 'a fo_term) formula
    46 
    47 
    47 datatype kind = Axiom | Hypothesis | Conjecture
    48 datatype kind = Axiom | Definition | Lemma | Hypothesis | Conjecture
    48 datatype 'a problem_line = Fof of string * kind * ('a, 'a fo_term) formula
    49 datatype 'a problem_line =
       
    50   Fof of string * kind * ('a, 'a fo_term) formula * string fo_term option
    49 type 'a problem = (string * 'a problem_line list) list
    51 type 'a problem = (string * 'a problem_line list) list
    50 
    52 
    51 val timestamp = Date.fmt "%Y-%m-%d %H:%M:%S" o Date.fromTimeLocal o Time.now
    53 val timestamp = Date.fmt "%Y-%m-%d %H:%M:%S" o Date.fromTimeLocal o Time.now
    52 
    54 
    53 fun string_for_kind Axiom = "axiom"
    55 fun string_for_kind Axiom = "axiom"
       
    56   | string_for_kind Definition = "definition"
       
    57   | string_for_kind Lemma = "lemma"
    54   | string_for_kind Hypothesis = "hypothesis"
    58   | string_for_kind Hypothesis = "hypothesis"
    55   | string_for_kind Conjecture = "conjecture"
    59   | string_for_kind Conjecture = "conjecture"
    56 
    60 
    57 fun string_for_term (ATerm (s, [])) = s
    61 fun string_for_term (ATerm (s, [])) = s
    58   | string_for_term (ATerm ("equal", ts)) =
    62   | string_for_term (ATerm ("equal", ts)) =
    59     space_implode " = " (map string_for_term ts)
    63     space_implode " = " (map string_for_term ts)
       
    64   | string_for_term (ATerm ("[]", ts)) =
       
    65     (* used for lists in the optional "source" field of a derivation *)
       
    66     "[" ^ commas (map string_for_term ts) ^ "]"
    60   | string_for_term (ATerm (s, ts)) =
    67   | string_for_term (ATerm (s, ts)) =
    61     s ^ "(" ^ commas (map string_for_term ts) ^ ")"
    68     s ^ "(" ^ commas (map string_for_term ts) ^ ")"
    62 fun string_for_quantifier AForall = "!"
    69 fun string_for_quantifier AForall = "!"
    63   | string_for_quantifier AExists = "?"
    70   | string_for_quantifier AExists = "?"
    64 fun string_for_connective ANot = "~"
    71 fun string_for_connective ANot = "~"
    79     "(" ^ space_implode (" " ^ string_for_connective c ^ " ")
    86     "(" ^ space_implode (" " ^ string_for_connective c ^ " ")
    80                         (map string_for_formula phis) ^ ")"
    87                         (map string_for_formula phis) ^ ")"
    81   | string_for_formula (AAtom tm) = string_for_term tm
    88   | string_for_formula (AAtom tm) = string_for_term tm
    82 
    89 
    83 fun string_for_problem_line use_conjecture_for_hypotheses
    90 fun string_for_problem_line use_conjecture_for_hypotheses
    84                             (Fof (ident, kind, phi)) =
    91                             (Fof (ident, kind, phi, source)) =
    85   let
    92   let
    86     val (kind, phi) =
    93     val (kind, phi) =
    87       if kind = Hypothesis andalso use_conjecture_for_hypotheses then
    94       if kind = Hypothesis andalso use_conjecture_for_hypotheses then
    88         (Conjecture, AConn (ANot, [phi]))
    95         (Conjecture, AConn (ANot, [phi]))
    89       else
    96       else
    90         (kind, phi)
    97         (kind, phi)
    91   in
    98   in
    92     "fof(" ^ ident ^ ", " ^ string_for_kind kind ^ ",\n    (" ^
    99     "fof(" ^ ident ^ ", " ^ string_for_kind kind ^ ",\n    (" ^
    93     string_for_formula phi ^ ")).\n"
   100     string_for_formula phi ^ ")" ^
       
   101     (case source of
       
   102        SOME tm => ", " ^ string_for_term tm
       
   103      | NONE => "") ^ ").\n"
    94   end
   104   end
    95 fun tptp_strings_for_atp_problem use_conjecture_for_hypotheses problem =
   105 fun tptp_strings_for_atp_problem use_conjecture_for_hypotheses problem =
    96   "% This file was generated by Isabelle (most likely Sledgehammer)\n\
   106   "% This file was generated by Isabelle (most likely Sledgehammer)\n\
    97   \% " ^ timestamp () ^ "\n" ::
   107   \% " ^ timestamp () ^ "\n" ::
    98   maps (fn (_, []) => []
   108   maps (fn (_, []) => []
   158     pool_map nice_name xs ##>> nice_formula phi
   168     pool_map nice_name xs ##>> nice_formula phi
   159     #>> (fn (xs, phi) => AQuant (q, xs, phi))
   169     #>> (fn (xs, phi) => AQuant (q, xs, phi))
   160   | nice_formula (AConn (c, phis)) =
   170   | nice_formula (AConn (c, phis)) =
   161     pool_map nice_formula phis #>> curry AConn c
   171     pool_map nice_formula phis #>> curry AConn c
   162   | nice_formula (AAtom tm) = nice_term tm #>> AAtom
   172   | nice_formula (AAtom tm) = nice_term tm #>> AAtom
   163 fun nice_problem_line (Fof (ident, kind, phi)) =
   173 fun nice_problem_line (Fof (ident, kind, phi, source)) =
   164   nice_formula phi #>> (fn phi => Fof (ident, kind, phi))
   174   nice_formula phi #>> (fn phi => Fof (ident, kind, phi, source))
   165 fun nice_problem problem =
   175 fun nice_problem problem =
   166   pool_map (fn (heading, lines) =>
   176   pool_map (fn (heading, lines) =>
   167                pool_map nice_problem_line lines #>> pair heading) problem
   177                pool_map nice_problem_line lines #>> pair heading) problem
   168 fun nice_atp_problem readable_names problem =
   178 fun nice_atp_problem readable_names problem =
   169   nice_problem problem (empty_name_pool readable_names)
   179   nice_problem problem (empty_name_pool readable_names)