src/HOL/TPTP/TPTP_Parser/tptp_syntax.ML
author sultana
Thu, 19 Apr 2012 07:25:41 +0100
changeset 48440 fce9d97a3258
parent 48325 479b4d6b9562
child 48563 3d76c81b5ed2
permissions -rw-r--r--
exceptions related to interpreting tptp problems now mention the relevant position in the tptp file;
sultana@47715
     1
(*  Title:      HOL/TPTP/TPTP_Parser/tptp_syntax.ML
sultana@47715
     2
    Author:     Nik Sultana, Cambridge University Computer Laboratory
sultana@47715
     3
sultana@47715
     4
TPTP abstract syntax and parser-related definitions.
sultana@47715
     5
*)
sultana@47715
     6
sultana@47715
     7
signature TPTP_SYNTAX =
sultana@47715
     8
sig
sultana@47715
     9
  exception TPTP_SYNTAX of string
sultana@47715
    10
  val debug: ('a -> unit) -> 'a -> unit
sultana@47715
    11
sultana@47715
    12
(*Note that in THF "^ [X] : ^ [Y] : f @ g" should parse
sultana@47715
    13
  as "(^ [X] : (^ [Y] : f)) @ g"
sultana@47715
    14
*)
sultana@47715
    15
sultana@47715
    16
  datatype number_kind = Int_num | Real_num | Rat_num
sultana@47715
    17
sultana@47715
    18
  datatype status_value =
sultana@47715
    19
      Suc | Unp | Sap | Esa | Sat | Fsa
sultana@47715
    20
    | Thm | Eqv | Tac | Wec | Eth | Tau
sultana@47715
    21
    | Wtc | Wth | Cax | Sca | Tca | Wca
sultana@47715
    22
    | Cup | Csp | Ecs | Csa | Cth | Ceq
sultana@47715
    23
    | Unc | Wcc | Ect | Fun | Uns | Wuc
sultana@47715
    24
    | Wct | Scc | Uca | Noc
sultana@47715
    25
sultana@47715
    26
  type name = string
sultana@47715
    27
  type atomic_word = string
sultana@47715
    28
  type inference_rule = atomic_word
sultana@47715
    29
  type file_info = name option
sultana@47715
    30
  type single_quoted = string
sultana@47715
    31
  type file_name = single_quoted
sultana@47715
    32
  type creator_name = atomic_word
sultana@47715
    33
  type variable = string
sultana@47715
    34
  type upper_word = string
sultana@47715
    35
sultana@47715
    36
  datatype language = FOF | CNF | TFF | THF | FOT | TFF_with_arithmetic
sultana@47715
    37
  and role =
sultana@47715
    38
     Role_Axiom | Role_Hypothesis | Role_Definition | Role_Assumption |
sultana@47715
    39
     Role_Lemma | Role_Theorem | Role_Conjecture | Role_Negated_Conjecture |
sultana@47715
    40
     Role_Plain | Role_Fi_Domain | Role_Fi_Functors | Role_Fi_Predicates |
sultana@47715
    41
     Role_Type | Role_Unknown
sultana@47715
    42
sultana@47715
    43
  and general_data = (*Bind of variable * formula_data*)
sultana@47715
    44
     Atomic_Word of string
sultana@47715
    45
   | Application of string * general_term list (*general_function*)
sultana@47715
    46
   | V of upper_word (*variable*)
sultana@47715
    47
   | Number of number_kind * string
sultana@47715
    48
   | Distinct_Object of string
sultana@47715
    49
   | (*formula_data*) Formula_Data of language * tptp_formula (* $thf(<thf_formula>) *)
sultana@47715
    50
   | (*formula_data*) Term_Data of tptp_term
sultana@47715
    51
sultana@47715
    52
  and interpreted_symbol =
sultana@47715
    53
    UMinus | Sum | Difference | Product | Quotient | Quotient_E |
sultana@47715
    54
    Quotient_T | Quotient_F | Remainder_E | Remainder_T | Remainder_F |
sultana@47715
    55
    Floor | Ceiling | Truncate | Round | To_Int | To_Rat | To_Real |
sultana@48218
    56
    (*FIXME these should be in defined_pred, but that's not being used in TPTP*)
sultana@47715
    57
    Less | LessEq | Greater | GreaterEq | EvalEq | Is_Int | Is_Rat |
sultana@48218
    58
    Distinct | Apply
sultana@47715
    59
sultana@47715
    60
  and logic_symbol = Equals | NEquals | Or | And | Iff | If | Fi | Xor |
sultana@47715
    61
    Nor | Nand | Not | Op_Forall | Op_Exists |
sultana@48218
    62
    (*FIXME these should be in defined_pred, but that's not being used in TPTP*)
sultana@47715
    63
    True | False
sultana@47715
    64
sultana@47715
    65
  and quantifier = (*interpreted binders*)
sultana@47715
    66
    Forall | Exists | Epsilon | Iota | Lambda | Dep_Prod | Dep_Sum
sultana@47715
    67
sultana@47715
    68
  and tptp_base_type =
sultana@47715
    69
    Type_Ind | Type_Bool | Type_Type | Type_Int | Type_Rat | Type_Real
sultana@47715
    70
sultana@47715
    71
  and symbol =
sultana@47715
    72
      Uninterpreted of string
sultana@47715
    73
    | Interpreted_ExtraLogic of interpreted_symbol
sultana@47715
    74
    | Interpreted_Logic of logic_symbol
sultana@47715
    75
    | TypeSymbol of tptp_base_type
sultana@47715
    76
    | System of string
sultana@47715
    77
sultana@47715
    78
  and general_term =
sultana@47715
    79
      General_Data of general_data (*general_data*)
sultana@47715
    80
    | General_Term of general_data * general_term (*general_data : general_term*)
sultana@47715
    81
    | General_List of general_term list
sultana@47715
    82
sultana@47715
    83
  and tptp_term =
sultana@47715
    84
      Term_Func of symbol * tptp_term list
sultana@47715
    85
    | Term_Var of string
sultana@47715
    86
    | Term_Conditional of tptp_formula * tptp_term * tptp_term
sultana@47715
    87
    | Term_Num of number_kind * string
sultana@47715
    88
    | Term_Distinct_Object of string
sultana@48215
    89
    | Term_Let of tptp_let list * tptp_term (*FIXME remove list?*)
sultana@47715
    90
sultana@47715
    91
  and tptp_atom =
sultana@47715
    92
      TFF_Typed_Atom of symbol * tptp_type option (*only TFF*)
sultana@47715
    93
    | THF_Atom_term of tptp_term   (*from here on, only THF*)
sultana@47715
    94
    | THF_Atom_conn_term of symbol
sultana@47715
    95
sultana@47715
    96
  and tptp_formula =
sultana@47715
    97
      Pred of symbol * tptp_term list
sultana@47715
    98
    | Fmla of symbol * tptp_formula list
sultana@47715
    99
    | Sequent of tptp_formula list * tptp_formula list
sultana@47715
   100
    | Quant of quantifier * (string * tptp_type option) list * tptp_formula
sultana@47715
   101
    | Conditional of tptp_formula * tptp_formula * tptp_formula
sultana@48215
   102
    | Let of tptp_let list * tptp_formula (*FIXME remove list?*)
sultana@47715
   103
    | Atom of tptp_atom
sultana@48218
   104
    | Type_fmla of tptp_type
sultana@47715
   105
    | THF_typing of tptp_formula * tptp_type (*only THF*)
sultana@47715
   106
sultana@47715
   107
  and tptp_let =
sultana@47715
   108
      Let_fmla of (string * tptp_type option) * tptp_formula
sultana@48215
   109
    | Let_term of (string * tptp_type option) * tptp_term (*only TFF*)
sultana@47715
   110
sultana@47715
   111
  and tptp_type =
sultana@47715
   112
      Prod_type of tptp_type * tptp_type
sultana@47715
   113
    | Fn_type of tptp_type * tptp_type
sultana@47715
   114
    | Atom_type of string
sultana@47715
   115
    | Defined_type of tptp_base_type
sultana@47715
   116
    | Sum_type of tptp_type * tptp_type (*only THF*)
sultana@48215
   117
    | Fmla_type of tptp_formula
sultana@47715
   118
    | Subtype of symbol * symbol (*only THF*)
sultana@47715
   119
sultana@47715
   120
  type general_list = general_term list
sultana@47715
   121
  type parent_details = general_list
sultana@47715
   122
  type useful_info = general_term list
sultana@47715
   123
  type info = useful_info
sultana@47715
   124
sultana@47715
   125
  type annotation = general_term * general_term list
sultana@47715
   126
sultana@47715
   127
  exception DEQUOTE of string
sultana@47715
   128
sultana@47715
   129
  type position = string * int * int
sultana@47715
   130
sultana@47715
   131
  datatype tptp_line =
sultana@48218
   132
      Annotated_Formula of position * language * string * role *
sultana@48218
   133
        tptp_formula * annotation option
sultana@48440
   134
   |  Include of position * string * string list
sultana@47715
   135
sultana@47715
   136
  type tptp_problem = tptp_line list
sultana@47715
   137
sultana@47715
   138
  val dequote : single_quoted -> single_quoted
sultana@47715
   139
sultana@47715
   140
  val role_to_string : role -> string
sultana@47715
   141
sultana@47715
   142
  val status_to_string : status_value -> string
sultana@47715
   143
sultana@47715
   144
  val nameof_tff_atom_type : tptp_type -> string
sultana@47715
   145
sultana@48440
   146
  val pos_of_line : tptp_line -> position
sultana@48440
   147
sultana@47715
   148
  (*Returns the list of all files included in a directory and its
sultana@47715
   149
  subdirectories. This is only used for testing the parser/interpreter against
sultana@47715
   150
  all THF problems.*)
sultana@47715
   151
  val get_file_list : Path.T -> Path.T list
sultana@47715
   152
sultana@47715
   153
  val string_of_tptp_term : tptp_term -> string
sultana@47715
   154
  val string_of_tptp_formula : tptp_formula -> string
sultana@47715
   155
sultana@47715
   156
end
sultana@47715
   157
sultana@47715
   158
sultana@47715
   159
structure TPTP_Syntax : TPTP_SYNTAX =
sultana@47715
   160
struct
sultana@47715
   161
sultana@47715
   162
exception TPTP_SYNTAX of string
sultana@47715
   163
sultana@47715
   164
datatype number_kind = Int_num | Real_num | Rat_num
sultana@47715
   165
sultana@47715
   166
datatype status_value =
sultana@47715
   167
    Suc | Unp | Sap | Esa | Sat | Fsa
sultana@47715
   168
  | Thm | Eqv | Tac | Wec | Eth | Tau
sultana@47715
   169
  | Wtc | Wth | Cax | Sca | Tca | Wca
sultana@47715
   170
  | Cup | Csp | Ecs | Csa | Cth | Ceq
sultana@47715
   171
  | Unc | Wcc | Ect | Fun | Uns | Wuc
sultana@47715
   172
  | Wct | Scc | Uca | Noc
sultana@47715
   173
sultana@47715
   174
type name = string
sultana@47715
   175
type atomic_word = string
sultana@47715
   176
type inference_rule = atomic_word
sultana@47715
   177
type file_info = name option
sultana@47715
   178
type single_quoted = string
sultana@47715
   179
type file_name = single_quoted
sultana@47715
   180
type creator_name = atomic_word
sultana@47715
   181
type variable = string
sultana@47715
   182
type upper_word = string
sultana@47715
   183
sultana@47715
   184
datatype language = FOF | CNF | TFF | THF | FOT | TFF_with_arithmetic
sultana@47715
   185
and role =
sultana@47715
   186
  Role_Axiom | Role_Hypothesis | Role_Definition | Role_Assumption |
sultana@47715
   187
  Role_Lemma | Role_Theorem | Role_Conjecture | Role_Negated_Conjecture |
sultana@47715
   188
  Role_Plain | Role_Fi_Domain | Role_Fi_Functors | Role_Fi_Predicates |
sultana@47715
   189
  Role_Type | Role_Unknown
sultana@47715
   190
and general_data = (*Bind of variable * formula_data*)
sultana@47715
   191
    Atomic_Word of string
sultana@47715
   192
  | Application of string * (general_term list)
sultana@47715
   193
  | V of upper_word (*variable*)
sultana@47715
   194
  | Number of number_kind * string
sultana@47715
   195
  | Distinct_Object of string
sultana@47715
   196
  | (*formula_data*) Formula_Data of language * tptp_formula (* $thf(<thf_formula>) *)
sultana@47715
   197
  | (*formula_data*) Term_Data of tptp_term
sultana@47715
   198
sultana@47715
   199
  and interpreted_symbol =
sultana@47715
   200
    UMinus | Sum | Difference | Product | Quotient | Quotient_E |
sultana@47715
   201
    Quotient_T | Quotient_F | Remainder_E | Remainder_T | Remainder_F |
sultana@47715
   202
    Floor | Ceiling | Truncate | Round | To_Int | To_Rat | To_Real |
sultana@47715
   203
    Less | LessEq | Greater | GreaterEq | EvalEq | Is_Int | Is_Rat |
sultana@48215
   204
    Distinct |
sultana@48218
   205
    Apply
sultana@47715
   206
sultana@47715
   207
  and logic_symbol = Equals | NEquals | Or | And | Iff | If | Fi | Xor |
sultana@47715
   208
    Nor | Nand | Not | Op_Forall | Op_Exists |
sultana@47715
   209
    True | False
sultana@47715
   210
sultana@47715
   211
  and quantifier = (*interpreted binders*)
sultana@47715
   212
    Forall | Exists | Epsilon | Iota | Lambda | Dep_Prod | Dep_Sum
sultana@47715
   213
sultana@47715
   214
  and tptp_base_type =
sultana@47715
   215
    Type_Ind | Type_Bool | Type_Type | Type_Int | Type_Rat | Type_Real
sultana@47715
   216
sultana@47715
   217
  and symbol =
sultana@47715
   218
      Uninterpreted of string
sultana@47715
   219
    | Interpreted_ExtraLogic of interpreted_symbol
sultana@47715
   220
    | Interpreted_Logic of logic_symbol
sultana@47715
   221
    | TypeSymbol of tptp_base_type
sultana@47715
   222
    | System of string
sultana@47715
   223
sultana@47715
   224
  and general_term =
sultana@47715
   225
      General_Data of general_data (*general_data*)
sultana@47715
   226
    | General_Term of general_data * general_term (*general_data : general_term*)
sultana@47715
   227
    | General_List of general_term list
sultana@47715
   228
sultana@47715
   229
  and tptp_term =
sultana@47715
   230
      Term_Func of symbol * tptp_term list
sultana@47715
   231
    | Term_Var of string
sultana@47715
   232
    | Term_Conditional of tptp_formula * tptp_term * tptp_term
sultana@47715
   233
    | Term_Num of number_kind * string
sultana@47715
   234
    | Term_Distinct_Object of string
sultana@48215
   235
    | Term_Let of tptp_let list * tptp_term (*FIXME remove list?*)
sultana@47715
   236
sultana@47715
   237
  and tptp_atom =
sultana@47715
   238
      TFF_Typed_Atom of symbol * tptp_type option (*only TFF*)
sultana@47715
   239
    | THF_Atom_term of tptp_term   (*from here on, only THF*)
sultana@47715
   240
    | THF_Atom_conn_term of symbol
sultana@47715
   241
sultana@47715
   242
  and tptp_formula =
sultana@47715
   243
      Pred of symbol * tptp_term list
sultana@47715
   244
    | Fmla of symbol * tptp_formula list
sultana@47715
   245
    | Sequent of tptp_formula list * tptp_formula list
sultana@47715
   246
    | Quant of quantifier * (string * tptp_type option) list * tptp_formula
sultana@47715
   247
    | Conditional of tptp_formula * tptp_formula * tptp_formula
sultana@47715
   248
    | Let of tptp_let list * tptp_formula
sultana@47715
   249
    | Atom of tptp_atom
sultana@48218
   250
    | Type_fmla of tptp_type
sultana@47715
   251
    | THF_typing of tptp_formula * tptp_type
sultana@47715
   252
sultana@47715
   253
  and tptp_let =
sultana@48218
   254
      Let_fmla of (string * tptp_type option) * tptp_formula
sultana@48218
   255
    | Let_term of (string * tptp_type option) * tptp_term
sultana@47715
   256
sultana@47715
   257
  and tptp_type =
sultana@47715
   258
      Prod_type of tptp_type * tptp_type
sultana@47715
   259
    | Fn_type of tptp_type * tptp_type
sultana@47715
   260
    | Atom_type of string
sultana@47715
   261
    | Defined_type of tptp_base_type
sultana@48218
   262
    | Sum_type of tptp_type * tptp_type
sultana@48218
   263
    | Fmla_type of tptp_formula
sultana@48218
   264
    | Subtype of symbol * symbol
sultana@47715
   265
sultana@47715
   266
type general_list = general_term list
sultana@47715
   267
type parent_details = general_list
sultana@47715
   268
type useful_info = general_term list
sultana@47715
   269
type info = useful_info
sultana@47715
   270
sultana@47715
   271
(*type annotation = (source * info option)*)
sultana@47715
   272
type annotation = general_term * general_term list
sultana@47715
   273
sultana@47715
   274
exception DEQUOTE of string
sultana@47715
   275
sultana@47715
   276
type position = string * int * int
sultana@47715
   277
sultana@47715
   278
datatype tptp_line =
sultana@47715
   279
    Annotated_Formula of position * language * string * role * tptp_formula * annotation option
sultana@48440
   280
 |  Include of position * string * string list
sultana@47715
   281
sultana@47715
   282
type tptp_problem = tptp_line list
sultana@47715
   283
sultana@47715
   284
fun debug f x = if !Runtime.debug then (f x; ()) else ()
sultana@47715
   285
sultana@47715
   286
fun nameof_tff_atom_type (Atom_type str) = str
sultana@47715
   287
  | nameof_tff_atom_type _ = raise TPTP_SYNTAX "nameof_tff_atom_type called on non-atom type"
sultana@47715
   288
sultana@48440
   289
fun pos_of_line tptp_line =
sultana@48440
   290
  case tptp_line of
sultana@48440
   291
      Annotated_Formula (position, _, _, _, _, _) => position
sultana@48440
   292
   |  Include (position, _, _) => position
sultana@48440
   293
sultana@47715
   294
(*Used for debugging. Returns all files contained within a directory or its
sultana@47715
   295
subdirectories. Follows symbolic links, filters away directories.*)
sultana@47715
   296
fun get_file_list path =
sultana@47715
   297
  let
sultana@47715
   298
    fun check_file_entry f rest =
sultana@47715
   299
      let
sultana@47715
   300
        (*NOTE needed since no File.is_link and File.read_link*)
sultana@47715
   301
        val f_str = Path.implode f
sultana@47715
   302
      in
sultana@47715
   303
        if File.is_dir f then
sultana@47715
   304
          rest @ get_file_list f
sultana@47715
   305
        else if OS.FileSys.isLink f_str then
sultana@47715
   306
          (*follow links -- NOTE this breaks if links are relative paths*)
sultana@47715
   307
          check_file_entry (Path.explode (OS.FileSys.readLink f_str)) rest
sultana@47715
   308
        else f :: rest
sultana@47715
   309
      end
sultana@47715
   310
  in
sultana@47715
   311
    File.read_dir path
sultana@47715
   312
    |> map
sultana@47715
   313
        (Path.explode
sultana@47715
   314
        #> Path.append path)
sultana@47715
   315
    |> (fn l => fold check_file_entry l [])
sultana@47715
   316
  end
sultana@47715
   317
sultana@47715
   318
fun role_to_string role =
sultana@47715
   319
  case role of
sultana@47715
   320
      Role_Axiom => "axiom"
sultana@47715
   321
    | Role_Hypothesis => "hypothesis"
sultana@47715
   322
    | Role_Definition => "definition"
sultana@47715
   323
    | Role_Assumption => "assumption"
sultana@47715
   324
    | Role_Lemma => "lemma"
sultana@47715
   325
    | Role_Theorem => "theorem"
sultana@47715
   326
    | Role_Conjecture => "conjecture"
sultana@47715
   327
    | Role_Negated_Conjecture => "negated_conjecture"
sultana@47715
   328
    | Role_Plain => "plain"
sultana@47715
   329
    | Role_Fi_Domain => "fi_domain"
sultana@47715
   330
    | Role_Fi_Functors => "fi_functors"
sultana@47715
   331
    | Role_Fi_Predicates => "fi_predicates"
sultana@47715
   332
    | Role_Type => "type"
sultana@47715
   333
    | Role_Unknown => "unknown"
sultana@47715
   334
sultana@47715
   335
(*accepts a string "'abc'" and returns "abc"*)
sultana@47715
   336
fun dequote str : single_quoted =
sultana@47715
   337
  if str = "" then
sultana@47715
   338
    raise (DEQUOTE "empty string")
sultana@47715
   339
  else
sultana@47715
   340
    (unprefix "'" str
sultana@47715
   341
    |> unsuffix "'"
sultana@47715
   342
    handle (Fail str) =>
sultana@47715
   343
      if str = "unprefix" then
sultana@47715
   344
        raise DEQUOTE ("string doesn't open with quote:" ^ str)
sultana@47715
   345
      else if str = "unsuffix" then
sultana@47715
   346
        raise DEQUOTE ("string doesn't close with quote:" ^ str)
sultana@47715
   347
      else raise Fail str)
sultana@47715
   348
sultana@47715
   349
sultana@47715
   350
(* Printing parsed TPTP formulas *)
sultana@47715
   351
(*FIXME this is not pretty-printing, just printing*)
sultana@47715
   352
sultana@47715
   353
fun status_to_string status_value =
sultana@47715
   354
  case status_value of
wenzelm@48325
   355
      Suc => "suc"  | Unp => "unp"
sultana@47715
   356
    | Sap => "sap"  | Esa => "esa"
sultana@47715
   357
    | Sat => "sat"  | Fsa => "fsa"
sultana@47715
   358
    | Thm => "thm"  | Wuc => "wuc"
wenzelm@48325
   359
    | Eqv => "eqv"  | Tac => "tac"
wenzelm@48325
   360
    | Wec => "wec"  | Eth => "eth"
wenzelm@48325
   361
    | Tau => "tau"  | Wtc => "wtc"
wenzelm@48325
   362
    | Wth => "wth"  | Cax => "cax"
wenzelm@48325
   363
    | Sca => "sca"  | Tca => "tca"
wenzelm@48325
   364
    | Wca => "wca"  | Cup => "cup"
wenzelm@48325
   365
    | Csp => "csp"  | Ecs => "ecs"
wenzelm@48325
   366
    | Csa => "csa"  | Cth => "cth"
wenzelm@48325
   367
    | Ceq => "ceq"  | Unc => "unc"
wenzelm@48325
   368
    | Wcc => "wcc"  | Ect => "ect"
wenzelm@48325
   369
    | Fun => "fun"  | Uns => "uns"
wenzelm@48325
   370
    | Wct => "wct"  | Scc => "scc"
wenzelm@48325
   371
    | Uca => "uca"  | Noc => "noc"
sultana@47715
   372
sultana@47715
   373
fun string_of_tptp_term x =
sultana@47715
   374
  case x of
sultana@47715
   375
      Term_Func (symbol, tptp_term_list) =>
sultana@47715
   376
        "(" ^ string_of_symbol symbol ^ " " ^
wenzelm@48297
   377
        space_implode " " (map string_of_tptp_term tptp_term_list) ^ ")"
sultana@47715
   378
    | Term_Var str => str
sultana@47715
   379
    | Term_Conditional (tptp_formula, tptp_term1, tptp_term2) => "" (*FIXME*)
sultana@47715
   380
    | Term_Num (_, str) => str
sultana@47715
   381
    | Term_Distinct_Object str => str
sultana@47715
   382
sultana@47715
   383
and string_of_symbol (Uninterpreted str) = str
sultana@47715
   384
  | string_of_symbol (Interpreted_ExtraLogic interpreted_symbol) = string_of_interpreted_symbol interpreted_symbol
sultana@47715
   385
  | string_of_symbol (Interpreted_Logic logic_symbol) = string_of_logic_symbol logic_symbol
sultana@47715
   386
  | string_of_symbol (TypeSymbol tptp_base_type) = string_of_tptp_base_type tptp_base_type
sultana@47715
   387
  | string_of_symbol (System str) = str
sultana@47715
   388
sultana@47715
   389
and string_of_tptp_base_type Type_Ind = "$i"
sultana@47715
   390
  | string_of_tptp_base_type Type_Bool = "$o"
sultana@47715
   391
  | string_of_tptp_base_type Type_Type = "$tType"
sultana@47715
   392
  | string_of_tptp_base_type Type_Int = "$int"
sultana@47715
   393
  | string_of_tptp_base_type Type_Rat = "$rat"
sultana@47715
   394
  | string_of_tptp_base_type Type_Real = "$real"
sultana@47715
   395
sultana@47715
   396
and string_of_interpreted_symbol x =
sultana@47715
   397
  case x of
sultana@47715
   398
      UMinus => "$uminus"
sultana@47715
   399
    | Sum => "$sum"
sultana@47715
   400
    | Difference => "$difference"
sultana@47715
   401
    | Product => "$product"
sultana@47715
   402
    | Quotient => "$quotient"
sultana@47715
   403
    | Quotient_E => "$quotient_e"
sultana@47715
   404
    | Quotient_T => "$quotient_t"
sultana@47715
   405
    | Quotient_F => "$quotient_f"
sultana@47715
   406
    | Remainder_E => "$remainder_e"
sultana@47715
   407
    | Remainder_T => "$remainder_t"
sultana@47715
   408
    | Remainder_F => "$remainder_f"
sultana@47715
   409
    | Floor => "$floor"
sultana@47715
   410
    | Ceiling => "$ceiling"
sultana@47715
   411
    | Truncate => "$truncate"
sultana@47715
   412
    | Round => "$round"
sultana@47715
   413
    | To_Int => "$to_int"
sultana@47715
   414
    | To_Rat => "$to_rat"
sultana@47715
   415
    | To_Real => "$to_real"
sultana@47715
   416
    | Less => "$less"
sultana@47715
   417
    | LessEq => "$lesseq"
sultana@47715
   418
    | Greater => "$greater"
sultana@47715
   419
    | GreaterEq => "$greatereq"
sultana@47715
   420
    | EvalEq => "$evaleq"
sultana@47715
   421
    | Is_Int => "$is_int"
sultana@47715
   422
    | Is_Rat => "$is_rat"
sultana@47715
   423
    | Apply => "@"
sultana@47715
   424
sultana@47715
   425
and string_of_logic_symbol Equals = "="
sultana@47715
   426
  | string_of_logic_symbol NEquals = "!="
sultana@47715
   427
  | string_of_logic_symbol Or = "|"
sultana@47715
   428
  | string_of_logic_symbol And = "&"
sultana@47715
   429
  | string_of_logic_symbol Iff = "<=>"
sultana@47715
   430
  | string_of_logic_symbol If = "=>"
sultana@47715
   431
  | string_of_logic_symbol Fi = "<="
sultana@47715
   432
  | string_of_logic_symbol Xor = "<~>"
sultana@47715
   433
  | string_of_logic_symbol Nor = "~|"
sultana@47715
   434
  | string_of_logic_symbol Nand = "~&"
sultana@47715
   435
  | string_of_logic_symbol Not = "~"
sultana@47715
   436
  | string_of_logic_symbol Op_Forall = "!!"
sultana@47715
   437
  | string_of_logic_symbol Op_Exists = "??"
sultana@47715
   438
  | string_of_logic_symbol True = "$true"
sultana@47715
   439
  | string_of_logic_symbol False = "$false"
sultana@47715
   440
sultana@47715
   441
and string_of_quantifier Forall = "!"
sultana@47715
   442
  | string_of_quantifier Exists  = "?"
sultana@47715
   443
  | string_of_quantifier Epsilon  = "@+"
sultana@47715
   444
  | string_of_quantifier Iota  = "@-"
sultana@47715
   445
  | string_of_quantifier Lambda  = "^"
sultana@47715
   446
  | string_of_quantifier Dep_Prod = "!>"
sultana@47715
   447
  | string_of_quantifier Dep_Sum  = "?*"
sultana@47715
   448
sultana@47715
   449
and string_of_tptp_atom (TFF_Typed_Atom (symbol, tptp_type_option)) =
sultana@47715
   450
    (case tptp_type_option of
sultana@47715
   451
       NONE => string_of_symbol symbol
sultana@47715
   452
     | SOME tptp_type =>
sultana@47715
   453
         string_of_symbol symbol ^ " : " ^ string_of_tptp_type tptp_type)
sultana@47715
   454
  | string_of_tptp_atom (THF_Atom_term tptp_term) = string_of_tptp_term tptp_term
sultana@47715
   455
  | string_of_tptp_atom (THF_Atom_conn_term symbol) = string_of_symbol symbol
sultana@47715
   456
sultana@47715
   457
and string_of_tptp_formula (Pred (symbol, tptp_term_list)) =
sultana@47715
   458
      "(" ^ string_of_symbol symbol ^
wenzelm@48297
   459
      space_implode " " (map string_of_tptp_term tptp_term_list) ^ ")"
sultana@47715
   460
  | string_of_tptp_formula (Fmla (symbol, tptp_formula_list)) =
sultana@47715
   461
      "(" ^
sultana@47715
   462
      string_of_symbol symbol ^
wenzelm@48297
   463
      space_implode " " (map string_of_tptp_formula tptp_formula_list) ^ ")"
sultana@47715
   464
  | string_of_tptp_formula (Sequent (tptp_formula_list1, tptp_formula_list2)) = "" (*FIXME*)
sultana@47715
   465
  | string_of_tptp_formula (Quant (quantifier, varlist, tptp_formula)) =
sultana@47715
   466
      string_of_quantifier quantifier ^ "[" ^
wenzelm@48297
   467
      space_implode ", " (map (fn (n, ty) =>
sultana@47715
   468
        case ty of
sultana@47715
   469
          NONE => n
sultana@47715
   470
        | SOME ty => n ^ " : " ^ string_of_tptp_type ty) varlist) ^ "] : (" ^
sultana@47715
   471
      string_of_tptp_formula tptp_formula ^ ")"
sultana@47715
   472
  | string_of_tptp_formula (Conditional _) = "" (*FIXME*)
sultana@47715
   473
  | string_of_tptp_formula (Let _) = "" (*FIXME*)
sultana@47715
   474
  | string_of_tptp_formula (Atom tptp_atom) = string_of_tptp_atom tptp_atom
sultana@48218
   475
  | string_of_tptp_formula (Type_fmla tptp_type) = string_of_tptp_type tptp_type
sultana@47715
   476
  | string_of_tptp_formula (THF_typing (tptp_formula, tptp_type)) =
sultana@47715
   477
      string_of_tptp_formula tptp_formula ^ " : " ^ string_of_tptp_type tptp_type
sultana@47715
   478
sultana@47715
   479
and string_of_tptp_type (Prod_type (tptp_type1, tptp_type2)) =
sultana@47715
   480
      string_of_tptp_type tptp_type1 ^ " * " ^ string_of_tptp_type tptp_type2
sultana@47715
   481
  | string_of_tptp_type (Fn_type (tptp_type1, tptp_type2)) =
sultana@47715
   482
      string_of_tptp_type tptp_type1 ^ " > " ^ string_of_tptp_type tptp_type2
sultana@47715
   483
  | string_of_tptp_type (Atom_type str) = str
sultana@47715
   484
  | string_of_tptp_type (Defined_type tptp_base_type) =
sultana@47715
   485
      string_of_tptp_base_type tptp_base_type
sultana@47715
   486
  | string_of_tptp_type (Sum_type (tptp_type1, tptp_type2)) = ""
sultana@47715
   487
  | string_of_tptp_type (Fmla_type tptp_formula) = string_of_tptp_formula tptp_formula
sultana@47715
   488
  | string_of_tptp_type (Subtype (symbol1, symbol2)) =
sultana@47715
   489
      string_of_symbol symbol1 ^ " << " ^ string_of_symbol symbol2
sultana@47715
   490
sultana@47715
   491
end