src/Tools/Metis/src/Tptp.sml
author wenzelm
Sat, 07 Apr 2012 16:41:59 +0200
changeset 47389 e8552cba702d
parent 45778 df6e210fb44c
child 72004 913162a47d9f
permissions -rw-r--r--
explicit checks stable_finished_theory/stable_command allow parallel asynchronous command transactions; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     1
(* ========================================================================= *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     2
(* THE TPTP PROBLEM FILE FORMAT                                              *)
39502
cffceed8e7fa fix license
blanchet
parents: 39501
diff changeset
     3
(* Copyright (c) 2001 Joe Hurd, distributed under the BSD License            *)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     4
(* ========================================================================= *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     5
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     6
structure Tptp :> Tptp =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     7
struct
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     8
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     9
open Useful;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    10
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    11
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    12
(* Default TPTP function and relation name mapping.                          *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    13
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    14
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    15
val defaultFunctionMapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    16
    [(* Mapping TPTP functions to infix symbols *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    17
     {name = "~", arity = 1, tptp = "negate"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    18
     {name = "*", arity = 2, tptp = "multiply"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    19
     {name = "/", arity = 2, tptp = "divide"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    20
     {name = "+", arity = 2, tptp = "add"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    21
     {name = "-", arity = 2, tptp = "subtract"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    22
     {name = "::", arity = 2, tptp = "cons"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    23
     {name = "@", arity = 2, tptp = "append"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    24
     {name = ",", arity = 2, tptp = "pair"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    25
     (* Expanding HOL symbols to TPTP alphanumerics *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    26
     {name = ":", arity = 2, tptp = "has_type"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    27
     {name = ".", arity = 2, tptp = "apply"}];
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    28
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    29
val defaultRelationMapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    30
    [(* Mapping TPTP relations to infix symbols *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    31
     {name = "=", arity = 2, tptp = "="},  (* this preserves the = symbol *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    32
     {name = "==", arity = 2, tptp = "equalish"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    33
     {name = "<=", arity = 2, tptp = "less_equal"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    34
     {name = "<", arity = 2, tptp = "less_than"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    35
     {name = ">=", arity = 2, tptp = "greater_equal"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    36
     {name = ">", arity = 2, tptp = "greater_than"},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    37
     (* Expanding HOL symbols to TPTP alphanumerics *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    38
     {name = "{}", arity = 1, tptp = "bool"}];
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    39
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    40
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    41
(* Interpreting TPTP functions and relations in a finite model.              *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    42
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    43
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    44
val defaultFunctionModel =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    45
    [{name = "~", arity = 1, model = Model.negName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    46
     {name = "*", arity = 2, model = Model.multName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    47
     {name = "/", arity = 2, model = Model.divName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    48
     {name = "+", arity = 2, model = Model.addName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    49
     {name = "-", arity = 2, model = Model.subName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    50
     {name = "::", arity = 2, model = Model.consName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    51
     {name = "@", arity = 2, model = Model.appendName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    52
     {name = ":", arity = 2, model = Term.hasTypeFunctionName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    53
     {name = "additive_identity", arity = 0, model = Model.numeralName 0},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    54
     {name = "app", arity = 2, model = Model.appendName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    55
     {name = "complement", arity = 1, model = Model.complementName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    56
     {name = "difference", arity = 2, model = Model.differenceName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    57
     {name = "divide", arity = 2, model = Model.divName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    58
     {name = "empty_set", arity = 0, model = Model.emptyName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    59
     {name = "identity", arity = 0, model = Model.numeralName 1},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    60
     {name = "identity_map", arity = 1, model = Model.projectionName 1},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    61
     {name = "intersection", arity = 2, model = Model.intersectName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    62
     {name = "minus", arity = 1, model = Model.negName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    63
     {name = "multiplicative_identity", arity = 0, model = Model.numeralName 1},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    64
     {name = "n0", arity = 0, model = Model.numeralName 0},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    65
     {name = "n1", arity = 0, model = Model.numeralName 1},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    66
     {name = "n2", arity = 0, model = Model.numeralName 2},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    67
     {name = "n3", arity = 0, model = Model.numeralName 3},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    68
     {name = "n4", arity = 0, model = Model.numeralName 4},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    69
     {name = "n5", arity = 0, model = Model.numeralName 5},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    70
     {name = "n6", arity = 0, model = Model.numeralName 6},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    71
     {name = "n7", arity = 0, model = Model.numeralName 7},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    72
     {name = "n8", arity = 0, model = Model.numeralName 8},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    73
     {name = "n9", arity = 0, model = Model.numeralName 9},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    74
     {name = "nil", arity = 0, model = Model.nilName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    75
     {name = "null_class", arity = 0, model = Model.emptyName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    76
     {name = "singleton", arity = 1, model = Model.singletonName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    77
     {name = "successor", arity = 1, model = Model.sucName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    78
     {name = "symmetric_difference", arity = 2,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    79
      model = Model.symmetricDifferenceName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    80
     {name = "union", arity = 2, model = Model.unionName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    81
     {name = "universal_class", arity = 0, model = Model.universeName}];
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    82
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    83
val defaultRelationModel =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    84
    [{name = "=", arity = 2, model = Atom.eqRelationName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    85
     {name = "==", arity = 2, model = Atom.eqRelationName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    86
     {name = "<=", arity = 2, model = Model.leName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    87
     {name = "<", arity = 2, model = Model.ltName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    88
     {name = ">=", arity = 2, model = Model.geName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    89
     {name = ">", arity = 2, model = Model.gtName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    90
     {name = "divides", arity = 2, model = Model.dividesName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    91
     {name = "element_of_set", arity = 2, model = Model.memberName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    92
     {name = "equal", arity = 2, model = Atom.eqRelationName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    93
     {name = "equal_elements", arity = 2, model = Atom.eqRelationName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    94
     {name = "equal_sets", arity = 2, model = Atom.eqRelationName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    95
     {name = "equivalent", arity = 2, model = Atom.eqRelationName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    96
     {name = "less", arity = 2, model = Model.ltName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    97
     {name = "less_or_equal", arity = 2, model = Model.leName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    98
     {name = "member", arity = 2, model = Model.memberName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    99
     {name = "subclass", arity = 2, model = Model.subsetName},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   100
     {name = "subset", arity = 2, model = Model.subsetName}];
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   101
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   102
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   103
(* Helper functions.                                                         *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   104
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   105
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   106
fun isHdTlString hp tp s =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   107
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   108
      fun ct 0 = true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   109
        | ct i = tp (String.sub (s,i)) andalso ct (i - 1)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   110
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   111
      val n = size s
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   112
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   113
      n > 0 andalso hp (String.sub (s,0)) andalso ct (n - 1)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   114
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   115
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   116
fun stripSuffix pred s =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   117
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   118
      fun f 0 = ""
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   119
        | f n =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   120
          let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   121
            val n' = n - 1
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   122
          in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   123
            if pred (String.sub (s,n')) then f n'
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   124
            else String.substring (s,0,n)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   125
          end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   126
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   127
      f (size s)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   128
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   129
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   130
fun variant avoid s =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   131
    if not (StringSet.member s avoid) then s
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   132
    else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   133
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   134
        val s = stripSuffix Char.isDigit s
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   135
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   136
        fun var i =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   137
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   138
              val s_i = s ^ Int.toString i
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   139
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   140
              if not (StringSet.member s_i avoid) then s_i else var (i + 1)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   141
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   142
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   143
        var 0
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   144
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   145
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   146
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   147
(* Mapping to legal TPTP names.                                              *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   148
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   149
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   150
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   151
  fun nonEmptyPred p l =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   152
      case l of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   153
        [] => false
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   154
      | c :: cs => p (c,cs);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   155
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   156
  fun existsPred l x = List.exists (fn p => p x) l;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   157
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   158
  fun isTptpChar #"_" = true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   159
    | isTptpChar c = Char.isAlphaNum c;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   160
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   161
  fun isTptpName l s = nonEmptyPred (existsPred l) (String.explode s);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   162
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   163
  fun isRegular (c,cs) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   164
      Char.isLower c andalso List.all isTptpChar cs;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   165
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   166
  fun isNumber (c,cs) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   167
      Char.isDigit c andalso List.all Char.isDigit cs;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   168
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   169
  fun isDefined (c,cs) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   170
      c = #"$" andalso nonEmptyPred isRegular cs;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   171
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   172
  fun isSystem (c,cs) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   173
      c = #"$" andalso nonEmptyPred isDefined cs;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   174
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   175
  fun mkTptpVarName s =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   176
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   177
        val s =
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   178
            case List.filter isTptpChar (String.explode s) of
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   179
              [] => [#"X"]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   180
            | l as c :: cs =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   181
              if Char.isUpper c then l
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   182
              else if Char.isLower c then Char.toUpper c :: cs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   183
              else #"X" :: l
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   184
      in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   185
        String.implode s
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   186
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   187
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   188
  val isTptpConstName = isTptpName [isRegular,isNumber,isDefined,isSystem]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   189
  and isTptpFnName = isTptpName [isRegular,isDefined,isSystem]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   190
  and isTptpPropName = isTptpName [isRegular,isDefined,isSystem]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   191
  and isTptpRelName = isTptpName [isRegular,isDefined,isSystem];
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   192
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   193
  val isTptpFormulaName = isTptpName [isRegular,isNumber];
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   194
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   195
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   196
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   197
(* Mapping to legal TPTP variable names.                                     *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   198
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   199
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   200
datatype varToTptp = VarToTptp of StringSet.set * string NameMap.map;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   201
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   202
val emptyVarToTptp = VarToTptp (StringSet.empty, NameMap.new ());
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   203
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   204
fun addVarToTptp vm v =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   205
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   206
      val VarToTptp (avoid,mapping) = vm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   207
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   208
      if NameMap.inDomain v mapping then vm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   209
      else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   210
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   211
          val s = variant avoid (mkTptpVarName (Name.toString v))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   212
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   213
          val avoid = StringSet.add avoid s
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   214
          and mapping = NameMap.insert mapping (v,s)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   215
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   216
          VarToTptp (avoid,mapping)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   217
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   218
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   219
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   220
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   221
  fun add (v,vm) = addVarToTptp vm v;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   222
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   223
  val addListVarToTptp = List.foldl add;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   224
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   225
  val addSetVarToTptp = NameSet.foldl add;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   226
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   227
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   228
val fromListVarToTptp = addListVarToTptp emptyVarToTptp;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   229
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   230
val fromSetVarToTptp = addSetVarToTptp emptyVarToTptp;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   231
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   232
fun getVarToTptp vm v =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   233
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   234
      val VarToTptp (_,mapping) = vm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   235
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   236
      case NameMap.peek mapping v of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   237
        SOME s => s
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   238
      | NONE => raise Bug "Tptp.getVarToTptp: unknown var"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   239
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   240
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   241
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   242
(* Mapping from TPTP variable names.                                         *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   243
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   244
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   245
fun getVarFromTptp s = Name.fromString s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   246
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   247
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   248
(* Mapping to TPTP function and relation names.                              *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   249
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   250
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   251
datatype nameToTptp = NameToTptp of string NameArityMap.map;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   252
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   253
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   254
  val emptyNames : string NameArityMap.map = NameArityMap.new ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   255
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   256
  fun addNames ({name,arity,tptp},mapping) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   257
      NameArityMap.insert mapping ((name,arity),tptp);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   258
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   259
  val fromListNames = List.foldl addNames emptyNames;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   260
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   261
  fun mkNameToTptp mapping = NameToTptp (fromListNames mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   262
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   263
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   264
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   265
  fun escapeChar c =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   266
      case c of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   267
        #"\\" => "\\\\"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   268
      | #"'" => "\\'"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   269
      | #"\n" => "\\n"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   270
      | #"\t" => "\\t"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   271
      | _ => str c;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   272
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   273
  val escapeString = String.translate escapeChar;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   274
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   275
  fun singleQuote s = "'" ^ escapeString s ^ "'";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   276
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   277
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   278
fun getNameToTptp isTptp s = if isTptp s then s else singleQuote s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   279
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   280
fun getNameArityToTptp isZeroTptp isPlusTptp (NameToTptp mapping) na =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   281
    case NameArityMap.peek mapping na of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   282
      SOME s => s
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   283
    | NONE =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   284
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   285
        val (n,a) = na
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   286
        val isTptp = if a = 0 then isZeroTptp else isPlusTptp
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   287
        val s = Name.toString n
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   288
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   289
        getNameToTptp isTptp s
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   290
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   291
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   292
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   293
(* Mapping from TPTP function and relation names.                            *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   294
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   295
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   296
datatype nameFromTptp = NameFromTptp of (string * int, Name.name) Map.map;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   297
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   298
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   299
  val stringArityCompare = prodCompare String.compare Int.compare;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   300
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   301
  val emptyStringArityMap = Map.new stringArityCompare;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   302
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   303
  fun addStringArityMap ({name,arity,tptp},mapping) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   304
      Map.insert mapping ((tptp,arity),name);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   305
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   306
  val fromListStringArityMap =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   307
      List.foldl addStringArityMap emptyStringArityMap;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   308
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   309
  fun mkNameFromTptp mapping = NameFromTptp (fromListStringArityMap mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   310
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   311
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   312
fun getNameFromTptp (NameFromTptp mapping) sa =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   313
    case Map.peek mapping sa of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   314
      SOME n => n
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   315
    | NONE =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   316
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   317
        val (s,_) = sa
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   318
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   319
        Name.fromString s
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   320
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   321
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   322
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   323
(* Mapping to and from TPTP variable, function and relation names.           *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   324
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   325
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   326
datatype mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   327
    Mapping of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   328
      {varTo : varToTptp,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   329
       fnTo : nameToTptp,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   330
       relTo : nameToTptp,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   331
       fnFrom : nameFromTptp,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   332
       relFrom : nameFromTptp};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   333
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   334
fun mkMapping mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   335
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   336
      val {functionMapping,relationMapping} = mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   337
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   338
      val varTo = emptyVarToTptp
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   339
      val fnTo = mkNameToTptp functionMapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   340
      val relTo = mkNameToTptp relationMapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   341
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   342
      val fnFrom = mkNameFromTptp functionMapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   343
      val relFrom = mkNameFromTptp relationMapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   344
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   345
      Mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   346
        {varTo = varTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   347
         fnTo = fnTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   348
         relTo = relTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   349
         fnFrom = fnFrom,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   350
         relFrom = relFrom}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   351
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   352
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   353
fun addVarListMapping mapping vs =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   354
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   355
      val Mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   356
            {varTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   357
             fnTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   358
             relTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   359
             fnFrom,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   360
             relFrom} = mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   361
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   362
      val varTo = addListVarToTptp varTo vs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   363
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   364
      Mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   365
        {varTo = varTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   366
         fnTo = fnTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   367
         relTo = relTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   368
         fnFrom = fnFrom,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   369
         relFrom = relFrom}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   370
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   371
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   372
fun addVarSetMapping mapping vs =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   373
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   374
      val Mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   375
            {varTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   376
             fnTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   377
             relTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   378
             fnFrom,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   379
             relFrom} = mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   380
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   381
      val varTo = addSetVarToTptp varTo vs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   382
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   383
      Mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   384
        {varTo = varTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   385
         fnTo = fnTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   386
         relTo = relTo,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   387
         fnFrom = fnFrom,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   388
         relFrom = relFrom}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   389
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   390
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   391
fun varToTptp mapping v =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   392
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   393
      val Mapping {varTo,...} = mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   394
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   395
      getVarToTptp varTo v
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   396
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   397
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   398
fun fnToTptp mapping fa =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   399
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   400
      val Mapping {fnTo,...} = mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   401
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   402
      getNameArityToTptp isTptpConstName isTptpFnName fnTo fa
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   403
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   404
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   405
fun relToTptp mapping ra =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   406
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   407
      val Mapping {relTo,...} = mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   408
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   409
      getNameArityToTptp isTptpPropName isTptpRelName relTo ra
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   410
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   411
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   412
fun varFromTptp (_ : mapping) v = getVarFromTptp v;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   413
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   414
fun fnFromTptp mapping fa =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   415
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   416
      val Mapping {fnFrom,...} = mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   417
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   418
      getNameFromTptp fnFrom fa
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   419
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   420
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   421
fun relFromTptp mapping ra =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   422
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   423
      val Mapping {relFrom,...} = mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   424
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   425
      getNameFromTptp relFrom ra
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   426
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   427
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   428
val defaultMapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   429
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   430
      fun lift {name,arity,tptp} =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   431
          {name = Name.fromString name, arity = arity, tptp = tptp}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   432
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   433
      val functionMapping = List.map lift defaultFunctionMapping
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   434
      and relationMapping = List.map lift defaultRelationMapping
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   435
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   436
      val mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   437
          {functionMapping = functionMapping,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   438
           relationMapping = relationMapping}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   439
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   440
      mkMapping mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   441
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   442
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   443
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   444
(* Interpreting TPTP functions and relations in a finite model.              *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   445
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   446
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   447
fun mkFixedMap funcModel relModel =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   448
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   449
      fun mkEntry {name,arity,model} = ((Name.fromString name, arity), model)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   450
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   451
      fun mkMap l = NameArityMap.fromList (List.map mkEntry l)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   452
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   453
      {functionMap = mkMap funcModel,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   454
       relationMap = mkMap relModel}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   455
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   456
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   457
val defaultFixedMap = mkFixedMap defaultFunctionModel defaultRelationModel;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   458
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   459
val defaultModel =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   460
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   461
      val {size = N, fixed = fix} = Model.default
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   462
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   463
      val fix = Model.mapFixed defaultFixedMap fix
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   464
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   465
      {size = N, fixed = fix}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   466
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   467
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   468
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   469
  fun toTptpMap toTptp =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   470
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   471
        fun add ((src,arity),dest,m) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   472
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   473
              val src = Name.fromString (toTptp (src,arity))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   474
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   475
              NameArityMap.insert m ((src,arity),dest)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   476
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   477
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   478
        fn m => NameArityMap.foldl add (NameArityMap.new ()) m
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   479
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   480
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   481
  fun toTptpFixedMap mapping fixMap =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   482
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   483
        val {functionMap = fnMap, relationMap = relMap} = fixMap
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   484
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   485
        val fnMap = toTptpMap (fnToTptp mapping) fnMap
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   486
        and relMap = toTptpMap (relToTptp mapping) relMap
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   487
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   488
        {functionMap = fnMap,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   489
         relationMap = relMap}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   490
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   491
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   492
  fun ppFixedMap mapping fixMap =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   493
      Model.ppFixedMap (toTptpFixedMap mapping fixMap);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   494
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   495
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   496
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   497
(* TPTP roles.                                                               *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   498
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   499
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   500
datatype role =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   501
    AxiomRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   502
  | ConjectureRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   503
  | DefinitionRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   504
  | NegatedConjectureRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   505
  | PlainRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   506
  | TheoremRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   507
  | OtherRole of string;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   508
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   509
fun isCnfConjectureRole role =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   510
    case role of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   511
      NegatedConjectureRole => true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   512
    | _ => false;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   513
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   514
fun isFofConjectureRole role =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   515
    case role of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   516
      ConjectureRole => true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   517
    | _ => false;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   518
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   519
fun toStringRole role =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   520
    case role of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   521
      AxiomRole => "axiom"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   522
    | ConjectureRole => "conjecture"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   523
    | DefinitionRole => "definition"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   524
    | NegatedConjectureRole => "negated_conjecture"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   525
    | PlainRole => "plain"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   526
    | TheoremRole => "theorem"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   527
    | OtherRole s => s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   528
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   529
fun fromStringRole s =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   530
    case s of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   531
      "axiom" => AxiomRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   532
    | "conjecture" => ConjectureRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   533
    | "definition" => DefinitionRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   534
    | "negated_conjecture" => NegatedConjectureRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   535
    | "plain" => PlainRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   536
    | "theorem" => TheoremRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   537
    | _ => OtherRole s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   538
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   539
val ppRole = Print.ppMap toStringRole Print.ppString;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   540
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   541
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   542
(* SZS statuses.                                                             *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   543
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   544
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   545
datatype status =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   546
    CounterSatisfiableStatus
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   547
  | TheoremStatus
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   548
  | SatisfiableStatus
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   549
  | UnknownStatus
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   550
  | UnsatisfiableStatus;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   551
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   552
fun toStringStatus status =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   553
    case status of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   554
      CounterSatisfiableStatus => "CounterSatisfiable"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   555
    | TheoremStatus => "Theorem"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   556
    | SatisfiableStatus => "Satisfiable"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   557
    | UnknownStatus => "Unknown"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   558
    | UnsatisfiableStatus => "Unsatisfiable";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   559
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   560
val ppStatus = Print.ppMap toStringStatus Print.ppString;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   561
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   562
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   563
(* TPTP literals.                                                            *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   564
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   565
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   566
datatype literal =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   567
    Boolean of bool
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   568
  | Literal of Literal.literal;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   569
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   570
fun destLiteral lit =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   571
    case lit of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   572
      Literal l => l
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   573
    | _ => raise Error "Tptp.destLiteral";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   574
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   575
fun isBooleanLiteral lit =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   576
    case lit of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   577
      Boolean _ => true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   578
    | _ => false;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   579
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   580
fun equalBooleanLiteral b lit =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   581
    case lit of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   582
      Boolean b' => b = b'
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   583
    | _ => false;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   584
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   585
fun negateLiteral (Boolean b) = (Boolean (not b))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   586
  | negateLiteral (Literal l) = (Literal (Literal.negate l));
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   587
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   588
fun functionsLiteral (Boolean _) = NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   589
  | functionsLiteral (Literal lit) = Literal.functions lit;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   590
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   591
fun relationLiteral (Boolean _) = NONE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   592
  | relationLiteral (Literal lit) = SOME (Literal.relation lit);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   593
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   594
fun literalToFormula (Boolean true) = Formula.True
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   595
  | literalToFormula (Boolean false) = Formula.False
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   596
  | literalToFormula (Literal lit) = Literal.toFormula lit;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   597
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   598
fun literalFromFormula Formula.True = Boolean true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   599
  | literalFromFormula Formula.False = Boolean false
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   600
  | literalFromFormula fm = Literal (Literal.fromFormula fm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   601
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   602
fun freeVarsLiteral (Boolean _) = NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   603
  | freeVarsLiteral (Literal lit) = Literal.freeVars lit;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   604
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   605
fun literalSubst sub lit =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   606
    case lit of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   607
      Boolean _ => lit
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   608
    | Literal l => Literal (Literal.subst sub l);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   609
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   610
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   611
(* Printing formulas using TPTP syntax.                                      *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   612
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   613
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   614
fun ppVar mapping v =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   615
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   616
      val s = varToTptp mapping v
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   617
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   618
      Print.ppString s
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   619
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   620
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   621
fun ppFnName mapping fa = Print.ppString (fnToTptp mapping fa);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   622
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   623
fun ppConst mapping c = ppFnName mapping (c,0);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   624
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   625
fun ppTerm mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   626
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   627
      fun term tm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   628
          case tm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   629
            Term.Var v => ppVar mapping v
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   630
          | Term.Fn (f,tms) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   631
            case length tms of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   632
              0 => ppConst mapping f
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   633
            | a =>
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   634
              Print.inconsistentBlock 2
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   635
                [ppFnName mapping (f,a),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   636
                 Print.ppString "(",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   637
                 Print.ppOpList "," term tms,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   638
                 Print.ppString ")"]
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   639
    in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   640
      fn tm => Print.inconsistentBlock 0 [term tm]
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   641
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   642
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   643
fun ppRelName mapping ra = Print.ppString (relToTptp mapping ra);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   644
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   645
fun ppProp mapping p = ppRelName mapping (p,0);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   646
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   647
fun ppAtom mapping (r,tms) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   648
    case length tms of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   649
      0 => ppProp mapping r
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   650
    | a =>
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   651
      Print.inconsistentBlock 2
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   652
        [ppRelName mapping (r,a),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   653
         Print.ppString "(",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   654
         Print.ppOpList "," (ppTerm mapping) tms,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   655
         Print.ppString ")"];
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   656
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   657
local
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   658
  val neg = Print.sequence (Print.ppString "~") Print.break;
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   659
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   660
  fun fof mapping fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   661
      case fm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   662
        Formula.And _ => assoc_binary mapping ("&", Formula.stripConj fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   663
      | Formula.Or _ => assoc_binary mapping ("|", Formula.stripDisj fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   664
      | Formula.Imp a_b => nonassoc_binary mapping ("=>",a_b)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   665
      | Formula.Iff a_b => nonassoc_binary mapping ("<=>",a_b)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   666
      | _ => unitary mapping fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   667
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   668
  and nonassoc_binary mapping (s,a_b) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   669
      Print.ppOp2 (" " ^ s) (unitary mapping) (unitary mapping) a_b
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   670
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   671
  and assoc_binary mapping (s,l) = Print.ppOpList (" " ^ s) (unitary mapping) l
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   672
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   673
  and unitary mapping fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   674
      case fm of
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   675
        Formula.True => Print.ppString "$true"
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   676
      | Formula.False => Print.ppString "$false"
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   677
      | Formula.Forall _ => quantified mapping ("!", Formula.stripForall fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   678
      | Formula.Exists _ => quantified mapping ("?", Formula.stripExists fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   679
      | Formula.Not _ =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   680
        (case total Formula.destNeq fm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   681
           SOME a_b => Print.ppOp2 " !=" (ppTerm mapping) (ppTerm mapping) a_b
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   682
         | NONE =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   683
           let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   684
             val (n,fm) = Formula.stripNeg fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   685
           in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   686
             Print.inconsistentBlock 2
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   687
               [Print.duplicate n neg,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   688
                unitary mapping fm]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   689
           end)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   690
      | Formula.Atom atm =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   691
        (case total Formula.destEq fm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   692
           SOME a_b => Print.ppOp2 " =" (ppTerm mapping) (ppTerm mapping) a_b
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   693
         | NONE => ppAtom mapping atm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   694
      | _ =>
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   695
        Print.inconsistentBlock 1
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   696
          [Print.ppString "(",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   697
           fof mapping fm,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   698
           Print.ppString ")"]
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   699
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   700
  and quantified mapping (q,(vs,fm)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   701
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   702
        val mapping = addVarListMapping mapping vs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   703
      in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   704
        Print.inconsistentBlock 2
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   705
          [Print.ppString q,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   706
           Print.ppString " ",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   707
           Print.inconsistentBlock (String.size q)
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   708
             [Print.ppString "[",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   709
              Print.ppOpList "," (ppVar mapping) vs,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   710
              Print.ppString "] :"],
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   711
           Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   712
           unitary mapping fm]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   713
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   714
in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   715
  fun ppFof mapping fm = Print.inconsistentBlock 0 [fof mapping fm];
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   716
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   717
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   718
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   719
(* Lexing TPTP files.                                                        *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   720
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   721
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   722
datatype token =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   723
    AlphaNum of string
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   724
  | Punct of char
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   725
  | Quote of string;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   726
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   727
fun isAlphaNum #"_" = true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   728
  | isAlphaNum c = Char.isAlphaNum c;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   729
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   730
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   731
  open Parse;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   732
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   733
  infixr 9 >>++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   734
  infixr 8 ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   735
  infixr 7 >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   736
  infixr 6 ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   737
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   738
  val alphaNumToken =
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   739
      atLeastOne (some isAlphaNum) >> (AlphaNum o String.implode);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   740
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   741
  val punctToken =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   742
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   743
        val punctChars = "<>=-*+/\\?@|!$%&#^:;~()[]{}.,"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   744
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   745
        some (Char.contains punctChars) >> Punct
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   746
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   747
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   748
  val quoteToken =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   749
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   750
        val escapeParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   751
            some (equal #"'") >> singleton ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   752
            some (equal #"\\") >> singleton
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   753
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   754
        fun stopOn #"'" = true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   755
          | stopOn #"\n" = true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   756
          | stopOn _ = false
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   757
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   758
        val quotedParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   759
            some (equal #"\\") ++ escapeParser >> op:: ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   760
            some (not o stopOn) >> singleton
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   761
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   762
        exactChar #"'" ++ many quotedParser ++ exactChar #"'" >>
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   763
        (fn (_,(l,_)) => Quote (String.implode (List.concat l)))
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   764
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   765
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   766
  val lexToken = alphaNumToken || punctToken || quoteToken;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   767
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   768
  val space = many (some Char.isSpace) >> K ();
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   769
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   770
  val space1 = atLeastOne (some Char.isSpace) >> K ();
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   771
in
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   772
  val lexer =
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   773
      (space ++ lexToken) >> (fn ((),tok) => [tok]) ||
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   774
      space1 >> K [];
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   775
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   776
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   777
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   778
(* TPTP clauses.                                                             *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   779
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   780
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   781
type clause = literal list;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   782
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   783
val clauseFunctions =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   784
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   785
      fun funcs (lit,acc) = NameAritySet.union (functionsLiteral lit) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   786
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   787
      List.foldl funcs NameAritySet.empty
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   788
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   789
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   790
val clauseRelations =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   791
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   792
      fun rels (lit,acc) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   793
          case relationLiteral lit of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   794
            NONE => acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   795
          | SOME r => NameAritySet.add acc r
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   796
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   797
      List.foldl rels NameAritySet.empty
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   798
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   799
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   800
val clauseFreeVars =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   801
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   802
      fun fvs (lit,acc) = NameSet.union (freeVarsLiteral lit) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   803
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   804
      List.foldl fvs NameSet.empty
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   805
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   806
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   807
fun clauseSubst sub lits = List.map (literalSubst sub) lits;
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   808
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   809
fun clauseToFormula lits = Formula.listMkDisj (List.map literalToFormula lits);
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   810
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   811
fun clauseFromFormula fm = List.map literalFromFormula (Formula.stripDisj fm);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   812
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   813
fun clauseFromLiteralSet cl =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   814
    clauseFromFormula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   815
      (Formula.listMkDisj (LiteralSet.transform Literal.toFormula cl));
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   816
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   817
fun clauseFromThm th = clauseFromLiteralSet (Thm.clause th);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   818
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   819
fun ppClause mapping = Print.ppMap clauseToFormula (ppFof mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   820
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   821
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   822
(* TPTP formula names.                                                       *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   823
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   824
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   825
datatype formulaName = FormulaName of string;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   826
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   827
datatype formulaNameSet = FormulaNameSet of formulaName Set.set;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   828
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   829
fun compareFormulaName (FormulaName s1, FormulaName s2) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   830
    String.compare (s1,s2);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   831
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   832
fun toTptpFormulaName (FormulaName s) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   833
    getNameToTptp isTptpFormulaName s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   834
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   835
val ppFormulaName = Print.ppMap toTptpFormulaName Print.ppString;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   836
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   837
val emptyFormulaNameSet = FormulaNameSet (Set.empty compareFormulaName);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   838
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   839
fun memberFormulaNameSet n (FormulaNameSet s) = Set.member n s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   840
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   841
fun addFormulaNameSet (FormulaNameSet s) n = FormulaNameSet (Set.add s n);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   842
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   843
fun addListFormulaNameSet (FormulaNameSet s) l =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   844
    FormulaNameSet (Set.addList s l);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   845
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   846
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   847
(* TPTP formula bodies.                                                      *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   848
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   849
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   850
datatype formulaBody =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   851
    CnfFormulaBody of literal list
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   852
  | FofFormulaBody of Formula.formula;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   853
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   854
fun destCnfFormulaBody body =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   855
    case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   856
      CnfFormulaBody x => x
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   857
    | _ => raise Error "destCnfFormulaBody";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   858
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   859
val isCnfFormulaBody = can destCnfFormulaBody;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   860
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   861
fun destFofFormulaBody body =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   862
    case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   863
      FofFormulaBody x => x
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   864
    | _ => raise Error "destFofFormulaBody";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   865
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   866
val isFofFormulaBody = can destFofFormulaBody;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   867
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   868
fun formulaBodyFunctions body =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   869
    case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   870
      CnfFormulaBody cl => clauseFunctions cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   871
    | FofFormulaBody fm => Formula.functions fm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   872
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   873
fun formulaBodyRelations body =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   874
    case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   875
      CnfFormulaBody cl => clauseRelations cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   876
    | FofFormulaBody fm => Formula.relations fm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   877
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   878
fun formulaBodyFreeVars body =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   879
    case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   880
      CnfFormulaBody cl => clauseFreeVars cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   881
    | FofFormulaBody fm => Formula.freeVars fm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   882
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   883
fun ppFormulaBody mapping body =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   884
    case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   885
      CnfFormulaBody cl => ppClause mapping cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   886
    | FofFormulaBody fm => ppFof mapping (Formula.generalize fm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   887
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   888
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   889
(* TPTP formula sources.                                                     *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   890
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   891
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   892
datatype formulaSource =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   893
    NoFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   894
  | StripFormulaSource of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   895
      {inference : string,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   896
       parents : formulaName list}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   897
  | NormalizeFormulaSource of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   898
      {inference : Normalize.inference,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   899
       parents : formulaName list}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   900
  | ProofFormulaSource of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   901
      {inference : Proof.inference,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   902
       parents : formulaName list};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   903
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   904
fun isNoFormulaSource source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   905
    case source of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   906
      NoFormulaSource => true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   907
    | _ => false;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   908
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   909
fun functionsFormulaSource source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   910
    case source of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   911
      NoFormulaSource => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   912
    | StripFormulaSource _ => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   913
    | NormalizeFormulaSource data =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   914
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   915
        val {inference = inf, parents = _} = data
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   916
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   917
        case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   918
          Normalize.Axiom fm => Formula.functions fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   919
        | Normalize.Definition (_,fm) => Formula.functions fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   920
        | _ => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   921
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   922
    | ProofFormulaSource data =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   923
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   924
        val {inference = inf, parents = _} = data
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   925
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   926
        case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   927
          Proof.Axiom cl => LiteralSet.functions cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   928
        | Proof.Assume atm => Atom.functions atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   929
        | Proof.Subst (sub,_) => Subst.functions sub
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   930
        | Proof.Resolve (atm,_,_) => Atom.functions atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   931
        | Proof.Refl tm => Term.functions tm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   932
        | Proof.Equality (lit,_,tm) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   933
          NameAritySet.union (Literal.functions lit) (Term.functions tm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   934
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   935
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   936
fun relationsFormulaSource source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   937
    case source of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   938
      NoFormulaSource => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   939
    | StripFormulaSource _ => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   940
    | NormalizeFormulaSource data =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   941
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   942
        val {inference = inf, parents = _} = data
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   943
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   944
        case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   945
          Normalize.Axiom fm => Formula.relations fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   946
        | Normalize.Definition (_,fm) => Formula.relations fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   947
        | _ => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   948
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   949
    | ProofFormulaSource data =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   950
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   951
        val {inference = inf, parents = _} = data
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   952
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   953
        case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   954
          Proof.Axiom cl => LiteralSet.relations cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   955
        | Proof.Assume atm => NameAritySet.singleton (Atom.relation atm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   956
        | Proof.Subst _ => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   957
        | Proof.Resolve (atm,_,_) => NameAritySet.singleton (Atom.relation atm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   958
        | Proof.Refl tm => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   959
        | Proof.Equality (lit,_,_) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   960
          NameAritySet.singleton (Literal.relation lit)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   961
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   962
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   963
fun freeVarsFormulaSource source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   964
    case source of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   965
      NoFormulaSource => NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   966
    | StripFormulaSource _ => NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   967
    | NormalizeFormulaSource data => NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   968
    | ProofFormulaSource data =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   969
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   970
        val {inference = inf, parents = _} = data
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   971
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   972
        case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   973
          Proof.Axiom cl => LiteralSet.freeVars cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   974
        | Proof.Assume atm => Atom.freeVars atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   975
        | Proof.Subst (sub,_) => Subst.freeVars sub
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   976
        | Proof.Resolve (atm,_,_) => Atom.freeVars atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   977
        | Proof.Refl tm => Term.freeVars tm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   978
        | Proof.Equality (lit,_,tm) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   979
          NameSet.union (Literal.freeVars lit) (Term.freeVars tm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   980
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   981
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   982
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   983
  val GEN_INFERENCE = "inference"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   984
  and GEN_INTRODUCED = "introduced";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   985
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   986
  fun nameStrip inf = inf;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   987
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   988
  fun ppStrip mapping inf = Print.skip;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   989
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   990
  fun nameNormalize inf =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   991
      case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   992
        Normalize.Axiom _ => "canonicalize"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   993
      | Normalize.Definition _ => "canonicalize"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   994
      | Normalize.Simplify _ => "simplify"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   995
      | Normalize.Conjunct _ => "conjunct"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   996
      | Normalize.Specialize _ => "specialize"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   997
      | Normalize.Skolemize _ => "skolemize"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   998
      | Normalize.Clausify _ => "clausify";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   999
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1000
  fun ppNormalize mapping inf = Print.skip;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1001
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1002
  fun nameProof inf =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1003
      case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1004
        Proof.Axiom _ => "canonicalize"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1005
      | Proof.Assume _ => "assume"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1006
      | Proof.Subst _ => "subst"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1007
      | Proof.Resolve _ => "resolve"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1008
      | Proof.Refl _ => "refl"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1009
      | Proof.Equality _ => "equality";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1010
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1011
  local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1012
    fun ppTermInf mapping = ppTerm mapping;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1013
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1014
    fun ppAtomInf mapping atm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1015
        case total Atom.destEq atm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1016
          SOME (a,b) => ppAtom mapping (Name.fromString "$equal", [a,b])
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1017
        | NONE => ppAtom mapping atm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1018
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1019
    fun ppLiteralInf mapping (pol,atm) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1020
        Print.sequence
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1021
          (if pol then Print.skip else Print.ppString "~ ")
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1022
          (ppAtomInf mapping atm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1023
  in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1024
    fun ppProofTerm mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1025
        Print.ppBracket "$fot(" ")" (ppTermInf mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1026
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1027
    fun ppProofAtom mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1028
        Print.ppBracket "$cnf(" ")" (ppAtomInf mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1029
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1030
    fun ppProofLiteral mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1031
        Print.ppBracket "$cnf(" ")" (ppLiteralInf mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1032
  end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1033
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1034
  val ppProofVar = ppVar;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1035
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1036
  val ppProofPath = Term.ppPath;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1037
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1038
  fun ppProof mapping inf =
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1039
      Print.inconsistentBlock 1
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1040
        [Print.ppString "[",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1041
         (case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1042
            Proof.Axiom _ => Print.skip
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1043
          | Proof.Assume atm => ppProofAtom mapping atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1044
          | Proof.Subst _ => Print.skip
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1045
          | Proof.Resolve (atm,_,_) => ppProofAtom mapping atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1046
          | Proof.Refl tm => ppProofTerm mapping tm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1047
          | Proof.Equality (lit,path,tm) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1048
            Print.program
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1049
              [ppProofLiteral mapping lit,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1050
               Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1051
               Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1052
               ppProofPath path,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1053
               Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1054
               Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1055
               ppProofTerm mapping tm]),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1056
         Print.ppString "]"];
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1057
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1058
  val ppParent = ppFormulaName;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1059
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1060
  fun ppProofSubst mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1061
      Print.ppMap Subst.toList
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1062
        (Print.ppList
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1063
           (Print.ppBracket "bind(" ")"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1064
              (Print.ppOp2 "," (ppProofVar mapping)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1065
                 (ppProofTerm mapping))));
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1066
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1067
  fun ppProofParent mapping (p,s) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1068
      if Subst.null s then ppParent p
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1069
      else Print.ppOp2 " :" ppParent (ppProofSubst mapping) (p,s);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1070
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1071
  fun ppFormulaSource mapping source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1072
      case source of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1073
        NoFormulaSource => Print.skip
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1074
      | StripFormulaSource {inference,parents} =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1075
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1076
          val gen = GEN_INFERENCE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1077
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1078
          val name = nameStrip inference
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1079
        in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1080
          Print.inconsistentBlock (size gen + 1)
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1081
            [Print.ppString gen,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1082
             Print.ppString "(",
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1083
             Print.ppString name,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1084
             Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1085
             Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1086
             Print.ppBracket "[" "]" (ppStrip mapping) inference,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1087
             Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1088
             Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1089
             Print.ppList ppParent parents,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1090
             Print.ppString ")"]
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1091
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1092
      | NormalizeFormulaSource {inference,parents} =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1093
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1094
          val gen = GEN_INFERENCE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1095
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1096
          val name = nameNormalize inference
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1097
        in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1098
          Print.inconsistentBlock (size gen + 1)
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1099
            [Print.ppString gen,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1100
             Print.ppString "(",
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1101
             Print.ppString name,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1102
             Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1103
             Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1104
             Print.ppBracket "[" "]" (ppNormalize mapping) inference,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1105
             Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1106
             Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1107
             Print.ppList ppParent parents,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1108
             Print.ppString ")"]
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1109
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1110
      | ProofFormulaSource {inference,parents} =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1111
        let
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  1112
          val isTaut = List.null parents
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1113
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1114
          val gen = if isTaut then GEN_INTRODUCED else GEN_INFERENCE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1115
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1116
          val name = nameProof inference
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1117
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1118
          val parents =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1119
              let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1120
                val sub =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1121
                    case inference of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1122
                      Proof.Subst (s,_) => s
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1123
                    | _ => Subst.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1124
              in
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  1125
                List.map (fn parent => (parent,sub)) parents
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1126
              end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1127
        in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1128
          Print.inconsistentBlock (size gen + 1)
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1129
            ([Print.ppString gen,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1130
              Print.ppString "("] @
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1131
             (if isTaut then
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1132
                [Print.ppString "tautology",
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1133
                 Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1134
                 Print.break,
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1135
                 Print.inconsistentBlock 1
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1136
                   [Print.ppString "[",
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1137
                    Print.ppString name,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1138
                    Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1139
                    Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1140
                    ppProof mapping inference,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1141
                    Print.ppString "]"]]
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1142
              else
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1143
                [Print.ppString name,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1144
                 Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1145
                 Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1146
                 ppProof mapping inference,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1147
                 Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1148
                 Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1149
                 Print.ppList (ppProofParent mapping) parents]) @
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1150
             [Print.ppString ")"])
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1151
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1152
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1153
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1154
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1155
(* TPTP formulas.                                                            *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1156
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1157
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1158
datatype formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1159
    Formula of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1160
      {name : formulaName,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1161
       role : role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1162
       body : formulaBody,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1163
       source : formulaSource};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1164
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1165
fun nameFormula (Formula {name,...}) = name;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1166
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1167
fun roleFormula (Formula {role,...}) = role;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1168
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1169
fun bodyFormula (Formula {body,...}) = body;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1170
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1171
fun sourceFormula (Formula {source,...}) = source;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1172
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1173
fun destCnfFormula fm = destCnfFormulaBody (bodyFormula fm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1174
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1175
val isCnfFormula = can destCnfFormula;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1176
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1177
fun destFofFormula fm = destFofFormulaBody (bodyFormula fm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1178
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1179
val isFofFormula = can destFofFormula;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1180
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1181
fun functionsFormula fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1182
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1183
      val bodyFns = formulaBodyFunctions (bodyFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1184
      and sourceFns = functionsFormulaSource (sourceFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1185
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1186
      NameAritySet.union bodyFns sourceFns
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1187
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1188
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1189
fun relationsFormula fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1190
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1191
      val bodyRels = formulaBodyRelations (bodyFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1192
      and sourceRels = relationsFormulaSource (sourceFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1193
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1194
      NameAritySet.union bodyRels sourceRels
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1195
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1196
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1197
fun freeVarsFormula fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1198
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1199
      val bodyFvs = formulaBodyFreeVars (bodyFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1200
      and sourceFvs = freeVarsFormulaSource (sourceFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1201
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1202
      NameSet.union bodyFvs sourceFvs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1203
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1204
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1205
val freeVarsListFormula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1206
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1207
      fun add (fm,vs) = NameSet.union vs (freeVarsFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1208
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1209
      List.foldl add NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1210
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1211
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1212
val formulasFunctions =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1213
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1214
      fun funcs (fm,acc) = NameAritySet.union (functionsFormula fm) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1215
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1216
      List.foldl funcs NameAritySet.empty
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1217
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1218
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1219
val formulasRelations =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1220
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1221
      fun rels (fm,acc) = NameAritySet.union (relationsFormula fm) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1222
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1223
      List.foldl rels NameAritySet.empty
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1224
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1225
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1226
fun isCnfConjectureFormula fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1227
    case fm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1228
      Formula {role, body = CnfFormulaBody _, ...} => isCnfConjectureRole role
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1229
    | _ => false;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1230
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1231
fun isFofConjectureFormula fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1232
    case fm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1233
      Formula {role, body = FofFormulaBody _, ...} => isFofConjectureRole role
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1234
    | _ => false;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1235
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1236
fun isConjectureFormula fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1237
    isCnfConjectureFormula fm orelse
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1238
    isFofConjectureFormula fm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1239
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1240
(* Parsing and pretty-printing *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1241
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1242
fun ppFormula mapping fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1243
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1244
      val Formula {name,role,body,source} = fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1245
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1246
      val gen =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1247
          case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1248
            CnfFormulaBody _ => "cnf"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1249
          | FofFormulaBody _ => "fof"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1250
    in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1251
      Print.inconsistentBlock (size gen + 1)
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1252
        ([Print.ppString gen,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1253
          Print.ppString "(",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1254
          ppFormulaName name,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1255
          Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1256
          Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1257
          ppRole role,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1258
          Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1259
          Print.break,
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1260
          Print.consistentBlock 1
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1261
            [Print.ppString "(",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1262
             ppFormulaBody mapping body,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1263
             Print.ppString ")"]] @
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1264
         (if isNoFormulaSource source then []
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1265
          else
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1266
            [Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1267
             Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1268
             ppFormulaSource mapping source]) @
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1269
         [Print.ppString ")."])
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1270
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1271
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1272
fun formulaToString mapping = Print.toString (ppFormula mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1273
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1274
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1275
  open Parse;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1276
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1277
  infixr 9 >>++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1278
  infixr 8 ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1279
  infixr 7 >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1280
  infixr 6 ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1281
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1282
  fun someAlphaNum p =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1283
      maybe (fn AlphaNum s => if p s then SOME s else NONE | _ => NONE);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1284
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1285
  fun alphaNumParser s = someAlphaNum (equal s) >> K ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1286
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1287
  val lowerParser = someAlphaNum (fn s => Char.isLower (String.sub (s,0)));
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1288
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1289
  val upperParser = someAlphaNum (fn s => Char.isUpper (String.sub (s,0)));
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1290
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1291
  val stringParser = lowerParser || upperParser;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1292
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1293
  val numberParser = someAlphaNum (List.all Char.isDigit o String.explode);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1294
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1295
  fun somePunct p =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1296
      maybe (fn Punct c => if p c then SOME c else NONE | _ => NONE);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1297
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1298
  fun punctParser c = somePunct (equal c) >> K ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1299
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1300
  val quoteParser = maybe (fn Quote s => SOME s | _ => NONE);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1301
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1302
  local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1303
    fun f [] = raise Bug "symbolParser"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1304
      | f [x] = x
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1305
      | f (h :: t) = (h ++ f t) >> K ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1306
  in
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  1307
    fun symbolParser s = f (List.map punctParser (String.explode s));
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1308
  end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1309
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1310
  val definedParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1311
      punctParser #"$" ++ someAlphaNum (K true) >> (fn ((),s) => "$" ^ s);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1312
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1313
  val systemParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1314
      punctParser #"$" ++ punctParser #"$" ++ someAlphaNum (K true) >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1315
      (fn ((),((),s)) => "$$" ^ s);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1316
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1317
  val nameParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1318
      (stringParser || numberParser || quoteParser) >> FormulaName;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1319
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1320
  val roleParser = lowerParser >> fromStringRole;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1321
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1322
  local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1323
    fun isProposition s = isHdTlString Char.isLower isAlphaNum s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1324
  in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1325
    val propositionParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1326
        someAlphaNum isProposition ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1327
        definedParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1328
        systemParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1329
        quoteParser;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1330
  end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1331
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1332
  local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1333
    fun isFunction s = isHdTlString Char.isLower isAlphaNum s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1334
  in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1335
    val functionParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1336
        someAlphaNum isFunction ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1337
        definedParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1338
        systemParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1339
        quoteParser;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1340
  end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1341
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1342
  local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1343
    fun isConstant s = isHdTlString Char.isLower isAlphaNum s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1344
  in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1345
    val constantParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1346
        someAlphaNum isConstant ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1347
        definedParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1348
        numberParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1349
        systemParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1350
        quoteParser;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1351
  end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1352
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1353
  val varParser = upperParser;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1354
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1355
  val varListParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1356
      (punctParser #"[" ++ varParser ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1357
       many ((punctParser #"," ++ varParser) >> snd) ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1358
       punctParser #"]") >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1359
      (fn ((),(h,(t,()))) => h :: t);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1360
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1361
  fun mkVarName mapping v = varFromTptp mapping v;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1362
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1363
  fun mkVar mapping v =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1364
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1365
        val v = mkVarName mapping v
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1366
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1367
        Term.Var v
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1368
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1369
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1370
  fun mkFn mapping (f,tms) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1371
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1372
        val f = fnFromTptp mapping (f, length tms)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1373
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1374
        Term.Fn (f,tms)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1375
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1376
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1377
  fun mkConst mapping c = mkFn mapping (c,[]);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1378
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1379
  fun mkAtom mapping (r,tms) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1380
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1381
        val r = relFromTptp mapping (r, length tms)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1382
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1383
        (r,tms)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1384
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1385
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1386
  fun termParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1387
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1388
        val fnP = functionArgumentsParser mapping >> mkFn mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1389
        val nonFnP = nonFunctionArgumentsTermParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1390
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1391
        fnP || nonFnP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1392
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1393
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1394
  and functionArgumentsParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1395
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1396
        val commaTmP = (punctParser #"," ++ termParser mapping) >> snd
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1397
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1398
        (functionParser ++ punctParser #"(" ++ termParser mapping ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1399
         many commaTmP ++ punctParser #")") >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1400
        (fn (f,((),(t,(ts,())))) => (f, t :: ts))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1401
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1402
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1403
  and nonFunctionArgumentsTermParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1404
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1405
        val varP = varParser >> mkVar mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1406
        val constP = constantParser >> mkConst mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1407
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1408
        varP || constP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1409
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1410
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1411
  fun binaryAtomParser mapping tm input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1412
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1413
        val eqP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1414
            (punctParser #"=" ++ termParser mapping) >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1415
            (fn ((),r) => (true,("$equal",[tm,r])))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1416
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1417
        val neqP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1418
            (symbolParser "!=" ++ termParser mapping) >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1419
            (fn ((),r) => (false,("$equal",[tm,r])))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1420
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1421
        eqP || neqP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1422
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1423
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1424
  fun maybeBinaryAtomParser mapping (s,tms) input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1425
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1426
        val tm = mkFn mapping (s,tms)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1427
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1428
        optional (binaryAtomParser mapping tm) >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1429
        (fn SOME lit => lit
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1430
          | NONE => (true,(s,tms)))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1431
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1432
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1433
  fun literalAtomParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1434
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1435
        val fnP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1436
            functionArgumentsParser mapping >>++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1437
            maybeBinaryAtomParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1438
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1439
        val nonFnP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1440
            nonFunctionArgumentsTermParser mapping >>++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1441
            binaryAtomParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1442
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1443
        val propP = propositionParser >> (fn s => (true,(s,[])))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1444
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1445
        fnP || nonFnP || propP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1446
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1447
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1448
  fun atomParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1449
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1450
        fun mk (pol,rel) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1451
          case rel of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1452
            ("$true",[]) => Boolean pol
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1453
          | ("$false",[]) => Boolean (not pol)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1454
          | ("$equal",[l,r]) => Literal (pol, Atom.mkEq (l,r))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1455
          | (r,tms) => Literal (pol, mkAtom mapping (r,tms))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1456
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1457
        literalAtomParser mapping >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1458
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1459
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1460
  fun literalParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1461
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1462
        val negP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1463
            (punctParser #"~" ++ atomParser mapping) >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1464
            (negateLiteral o snd)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1465
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1466
        val posP = atomParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1467
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1468
        negP || posP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1469
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1470
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1471
  fun disjunctionParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1472
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1473
        val orLitP = (punctParser #"|" ++ literalParser mapping) >> snd
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1474
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1475
        (literalParser mapping ++ many orLitP) >> (fn (h,t) => h :: t)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1476
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1477
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1478
  fun clauseParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1479
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1480
        val disjP = disjunctionParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1481
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1482
        val bracketDisjP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1483
            (punctParser #"(" ++ disjP ++ punctParser #")") >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1484
            (fn ((),(c,())) => c)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1485
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1486
        bracketDisjP || disjP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1487
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1488
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1489
  val binaryConnectiveParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1490
      (symbolParser "<=>" >> K Formula.Iff) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1491
      (symbolParser "=>" >> K Formula.Imp) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1492
      (symbolParser "<=" >> K (fn (f,g) => Formula.Imp (g,f))) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1493
      (symbolParser "<~>" >> K (Formula.Not o Formula.Iff)) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1494
      (symbolParser "~|" >> K (Formula.Not o Formula.Or)) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1495
      (symbolParser "~&" >> K (Formula.Not o Formula.And));
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1496
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1497
  val quantifierParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1498
      (punctParser #"!" >> K Formula.listMkForall) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1499
      (punctParser #"?" >> K Formula.listMkExists);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1500
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1501
  fun fofFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1502
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1503
        fun mk (f,NONE) = f
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1504
          | mk (f, SOME t) = t f
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1505
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1506
        (unitaryFormulaParser mapping ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1507
         optional (binaryFormulaParser mapping)) >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1508
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1509
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1510
  and binaryFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1511
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1512
        val nonAssocP = nonAssocBinaryFormulaParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1513
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1514
        val assocP = assocBinaryFormulaParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1515
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1516
        nonAssocP || assocP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1517
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1518
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1519
  and nonAssocBinaryFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1520
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1521
        fun mk (c,g) f = c (f,g)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1522
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1523
        (binaryConnectiveParser ++ unitaryFormulaParser mapping) >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1524
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1525
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1526
  and assocBinaryFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1527
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1528
        val orP = orFormulaParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1529
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1530
        val andP = andFormulaParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1531
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1532
        orP || andP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1533
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1534
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1535
  and orFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1536
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1537
        val orFmP = (punctParser #"|" ++ unitaryFormulaParser mapping) >> snd
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1538
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1539
        atLeastOne orFmP >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1540
        (fn fs => fn f => Formula.listMkDisj (f :: fs))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1541
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1542
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1543
  and andFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1544
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1545
        val andFmP = (punctParser #"&" ++ unitaryFormulaParser mapping) >> snd
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1546
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1547
        atLeastOne andFmP >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1548
        (fn fs => fn f => Formula.listMkConj (f :: fs))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1549
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1550
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1551
  and unitaryFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1552
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1553
        val quantP = quantifiedFormulaParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1554
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1555
        val unaryP = unaryFormulaParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1556
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1557
        val brackP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1558
            (punctParser #"(" ++ fofFormulaParser mapping ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1559
             punctParser #")") >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1560
            (fn ((),(f,())) => f)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1561
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1562
        val atomP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1563
            atomParser mapping >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1564
            (fn Boolean b => Formula.mkBoolean b
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1565
              | Literal l => Literal.toFormula l)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1566
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1567
        quantP ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1568
        unaryP ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1569
        brackP ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1570
        atomP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1571
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1572
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1573
  and quantifiedFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1574
      let
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  1575
        fun mk (q,(vs,((),f))) = q (List.map (mkVarName mapping) vs, f)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1576
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1577
        (quantifierParser ++ varListParser ++ punctParser #":" ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1578
         unitaryFormulaParser mapping) >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1579
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1580
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1581
  and unaryFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1582
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1583
        fun mk (c,f) = c f
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1584
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1585
        (unaryConnectiveParser ++ unitaryFormulaParser mapping) >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1586
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1587
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1588
  and unaryConnectiveParser input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1589
      (punctParser #"~" >> K Formula.Not) input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1590
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1591
  fun cnfParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1592
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1593
        fun mk ((),((),(name,((),(role,((),(cl,((),())))))))) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1594
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1595
              val body = CnfFormulaBody cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1596
              val source = NoFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1597
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1598
              Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1599
                {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1600
                 role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1601
                 body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1602
                 source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1603
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1604
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1605
        (alphaNumParser "cnf" ++ punctParser #"(" ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1606
         nameParser ++ punctParser #"," ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1607
         roleParser ++ punctParser #"," ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1608
         clauseParser mapping ++ punctParser #")" ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1609
         punctParser #".") >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1610
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1611
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1612
  fun fofParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1613
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1614
        fun mk ((),((),(name,((),(role,((),(fm,((),())))))))) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1615
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1616
              val body = FofFormulaBody fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1617
              val source = NoFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1618
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1619
              Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1620
                {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1621
                 role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1622
                 body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1623
                 source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1624
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1625
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1626
        (alphaNumParser "fof" ++ punctParser #"(" ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1627
         nameParser ++ punctParser #"," ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1628
         roleParser ++ punctParser #"," ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1629
         fofFormulaParser mapping ++ punctParser #")" ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1630
         punctParser #".") >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1631
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1632
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1633
  fun formulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1634
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1635
        val cnfP = cnfParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1636
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1637
        val fofP = fofParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1638
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1639
        cnfP || fofP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1640
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1641
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1642
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1643
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1644
(* Include declarations.                                                     *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1645
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1646
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1647
fun ppInclude i =
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1648
    Print.inconsistentBlock 2
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1649
      [Print.ppString "include('",
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1650
       Print.ppString i,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1651
       Print.ppString "')."];
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1652
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1653
val includeToString = Print.toString ppInclude;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1654
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1655
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1656
  open Parse;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1657
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1658
  infixr 9 >>++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1659
  infixr 8 ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1660
  infixr 7 >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1661
  infixr 6 ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1662
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1663
  val filenameParser = maybe (fn Quote s => SOME s | _ => NONE);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1664
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1665
  val includeParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1666
      (some (equal (AlphaNum "include")) ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1667
       some (equal (Punct #"(")) ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1668
       filenameParser ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1669
       some (equal (Punct #")")) ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1670
       some (equal (Punct #"."))) >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1671
      (fn (_,(_,(f,(_,_)))) => f);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1672
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1673
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1674
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1675
(* Parsing TPTP files.                                                       *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1676
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1677
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1678
datatype declaration =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1679
    IncludeDeclaration of string
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1680
  | FormulaDeclaration of formula;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1681
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1682
val partitionDeclarations =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1683
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1684
      fun part (d,(il,fl)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1685
          case d of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1686
            IncludeDeclaration i => (i :: il, fl)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1687
          | FormulaDeclaration f => (il, f :: fl)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1688
    in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1689
      fn l => List.foldl part ([],[]) (List.rev l)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1690
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1691
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1692
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1693
  open Parse;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1694
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1695
  infixr 9 >>++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1696
  infixr 8 ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1697
  infixr 7 >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1698
  infixr 6 ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1699
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1700
  fun declarationParser mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1701
      (includeParser >> IncludeDeclaration) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1702
      (formulaParser mapping >> FormulaDeclaration);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1703
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1704
  fun parseChars parser chars =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1705
      let
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  1706
        val tokens = Parse.everything lexer chars
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1707
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1708
        Parse.everything (parser >> singleton) tokens
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1709
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1710
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1711
  fun parseDeclaration mapping = parseChars (declarationParser mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1712
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1713
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1714
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1715
(* Clause information.                                                       *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1716
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1717
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1718
datatype clauseSource =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1719
    CnfClauseSource of formulaName * literal list
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1720
  | FofClauseSource of Normalize.thm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1721
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1722
type 'a clauseInfo = 'a LiteralSetMap.map;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1723
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1724
type clauseNames = formulaName clauseInfo;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1725
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1726
type clauseRoles = role clauseInfo;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1727
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1728
type clauseSources = clauseSource clauseInfo;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1729
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1730
val noClauseNames : clauseNames = LiteralSetMap.new ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1731
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1732
val allClauseNames : clauseNames -> formulaNameSet =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1733
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1734
      fun add (_,n,s) = addFormulaNameSet s n
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1735
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1736
      LiteralSetMap.foldl add emptyFormulaNameSet
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1737
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1738
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1739
val noClauseRoles : clauseRoles = LiteralSetMap.new ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1740
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1741
val noClauseSources : clauseSources = LiteralSetMap.new ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1742
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1743
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1744
(* Comments.                                                                 *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1745
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1746
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1747
fun mkLineComment "" = "%"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1748
  | mkLineComment line = "% " ^ line;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1749
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1750
fun destLineComment cs =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1751
    case cs of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1752
      [] => ""
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1753
    | #"%" :: #" " :: rest => String.implode rest
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1754
    | #"%" :: rest => String.implode rest
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1755
    | _ => raise Error "Tptp.destLineComment";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1756
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1757
val isLineComment = can destLineComment;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1758
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1759
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1760
(* TPTP problems.                                                            *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1761
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1762
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1763
type comments = string list;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1764
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1765
type includes = string list;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1766
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1767
datatype problem =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1768
    Problem of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1769
      {comments : comments,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1770
       includes : includes,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1771
       formulas : formula list};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1772
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1773
fun hasCnfConjecture (Problem {formulas,...}) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1774
    List.exists isCnfConjectureFormula formulas;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1775
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1776
fun hasFofConjecture (Problem {formulas,...}) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1777
    List.exists isFofConjectureFormula formulas;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1778
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1779
fun hasConjecture (Problem {formulas,...}) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1780
    List.exists isConjectureFormula formulas;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1781
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1782
fun freeVars (Problem {formulas,...}) = freeVarsListFormula formulas;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1783
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1784
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1785
  fun bump n avoid =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1786
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1787
        val s = FormulaName (Int.toString n)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1788
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1789
        if memberFormulaNameSet s avoid then bump (n + 1) avoid
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1790
        else (s, n, addFormulaNameSet avoid s)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1791
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1792
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1793
  fun fromClause defaultRole names roles cl (n,avoid) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1794
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1795
        val (name,n,avoid) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1796
            case LiteralSetMap.peek names cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1797
              SOME name => (name,n,avoid)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1798
            | NONE => bump n avoid
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1799
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1800
        val role = Option.getOpt (LiteralSetMap.peek roles cl, defaultRole)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1801
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1802
        val body = CnfFormulaBody (clauseFromLiteralSet cl)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1803
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1804
        val source = NoFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1805
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1806
        val formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1807
            Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1808
              {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1809
               role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1810
               body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1811
               source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1812
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1813
        (formula,(n,avoid))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1814
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1815
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1816
  fun mkProblem {comments,includes,names,roles,problem} =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1817
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1818
        fun fromCl defaultRole = fromClause defaultRole names roles
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1819
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1820
        val {axioms,conjecture} = problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1821
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1822
        val n_avoid = (0, allClauseNames names)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1823
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1824
        val (axiomFormulas,n_avoid) = maps (fromCl AxiomRole) axioms n_avoid
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1825
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1826
        val (conjectureFormulas,_) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1827
            maps (fromCl NegatedConjectureRole) conjecture n_avoid
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1828
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1829
        val formulas = axiomFormulas @ conjectureFormulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1830
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1831
        Problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1832
          {comments = comments,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1833
           includes = includes,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1834
           formulas = formulas}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1835
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1836
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1837
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1838
type normalization =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1839
     {problem : Problem.problem,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1840
      sources : clauseSources};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1841
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1842
val initialNormalization : normalization =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1843
    {problem = {axioms = [], conjecture = []},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1844
     sources = noClauseSources};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1845
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1846
datatype problemGoal =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1847
    NoGoal
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1848
  | CnfGoal of (formulaName * clause) list
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1849
  | FofGoal of (formulaName * Formula.formula) list;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1850
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1851
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1852
  fun partitionFormula (formula,(cnfAxioms,fofAxioms,cnfGoals,fofGoals)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1853
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1854
        val Formula {name,role,body,...} = formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1855
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1856
        case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1857
          CnfFormulaBody cl =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1858
          if isCnfConjectureRole role then
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1859
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1860
              val cnfGoals = (name,cl) :: cnfGoals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1861
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1862
              (cnfAxioms,fofAxioms,cnfGoals,fofGoals)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1863
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1864
          else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1865
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1866
              val cnfAxioms = (name,cl) :: cnfAxioms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1867
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1868
              (cnfAxioms,fofAxioms,cnfGoals,fofGoals)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1869
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1870
        | FofFormulaBody fm =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1871
          if isFofConjectureRole role then
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1872
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1873
              val fofGoals = (name,fm) :: fofGoals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1874
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1875
              (cnfAxioms,fofAxioms,cnfGoals,fofGoals)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1876
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1877
          else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1878
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1879
              val fofAxioms = (name,fm) :: fofAxioms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1880
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1881
              (cnfAxioms,fofAxioms,cnfGoals,fofGoals)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1882
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1883
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1884
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1885
  fun partitionFormulas fms =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1886
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1887
        val (cnfAxioms,fofAxioms,cnfGoals,fofGoals) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1888
            List.foldl partitionFormula ([],[],[],[]) fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1889
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1890
        val goal =
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1891
            case (List.rev cnfGoals, List.rev fofGoals) of
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1892
              ([],[]) => NoGoal
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1893
            | (cnfGoals,[]) => CnfGoal cnfGoals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1894
            | ([],fofGoals) => FofGoal fofGoals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1895
            | (_ :: _, _ :: _) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1896
              raise Error "TPTP problem has both cnf and fof conjecture formulas"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1897
      in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1898
        {cnfAxioms = List.rev cnfAxioms,
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1899
         fofAxioms = List.rev fofAxioms,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1900
         goal = goal}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1901
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1902
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1903
  fun addClauses role clauses acc : normalization =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1904
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1905
        fun addClause (cl_src,sources) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1906
            LiteralSetMap.insert sources cl_src
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1907
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1908
        val {problem,sources} : normalization = acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1909
        val {axioms,conjecture} = problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1910
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  1911
        val cls = List.map fst clauses
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1912
        val (axioms,conjecture) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1913
            if isCnfConjectureRole role then (axioms, cls @ conjecture)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1914
            else (cls @ axioms, conjecture)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1915
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1916
        val problem = {axioms = axioms, conjecture = conjecture}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1917
        and sources = List.foldl addClause sources clauses
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1918
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1919
        {problem = problem,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1920
         sources = sources}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1921
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1922
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1923
  fun addCnf role ((name,clause),(norm,cnf)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1924
      if List.exists (equalBooleanLiteral true) clause then (norm,cnf)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1925
      else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1926
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1927
          val cl = List.mapPartial (total destLiteral) clause
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1928
          val cl = LiteralSet.fromList cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1929
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1930
          val src = CnfClauseSource (name,clause)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1931
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1932
          val norm = addClauses role [(cl,src)] norm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1933
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1934
          (norm,cnf)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1935
        end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1936
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1937
  val addCnfAxiom = addCnf AxiomRole;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1938
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1939
  val addCnfGoal = addCnf NegatedConjectureRole;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1940
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1941
  fun addFof role (th,(norm,cnf)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1942
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1943
        fun sourcify (cl,inf) = (cl, FofClauseSource inf)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1944
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1945
        val (clauses,cnf) = Normalize.addCnf th cnf
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  1946
        val clauses = List.map sourcify clauses
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1947
        val norm = addClauses role clauses norm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1948
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1949
        (norm,cnf)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1950
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1951
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1952
  fun addFofAxiom ((_,fm),acc) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1953
      addFof AxiomRole (Normalize.mkAxiom fm, acc);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1954
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1955
  fun normProblem subgoal (norm,_) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1956
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1957
        val {problem,sources} = norm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1958
        val {axioms,conjecture} = problem
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  1959
        val problem = {axioms = List.rev axioms, conjecture = List.rev conjecture}
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1960
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1961
        {subgoal = subgoal,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1962
         problem = problem,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1963
         sources = sources}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1964
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1965
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1966
  val normProblemFalse = normProblem (Formula.False,[]);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1967
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1968
  fun splitProblem acc =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1969
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1970
        fun mk parents subgoal =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1971
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1972
              val subgoal = Formula.generalize subgoal
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1973
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1974
              val th = Normalize.mkAxiom (Formula.Not subgoal)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1975
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1976
              val acc = addFof NegatedConjectureRole (th,acc)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1977
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1978
              normProblem (subgoal,parents) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1979
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1980
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1981
        fun split (name,goal) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1982
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1983
              val subgoals = Formula.splitGoal goal
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1984
              val subgoals =
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  1985
                  if List.null subgoals then [Formula.True] else subgoals
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1986
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1987
              val parents = [name]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1988
            in
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  1989
              List.map (mk parents) subgoals
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1990
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1991
      in
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  1992
        fn goals => List.concat (List.map split goals)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1993
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1994
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1995
  fun clausesToGoal cls =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1996
      let
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  1997
        val cls = List.map (Formula.generalize o clauseToFormula o snd) cls
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1998
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1999
        Formula.listMkConj cls
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2000
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2001
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2002
  fun formulasToGoal fms =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2003
      let
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  2004
        val fms = List.map (Formula.generalize o snd) fms
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2005
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2006
        Formula.listMkConj fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2007
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2008
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2009
  fun goal (Problem {formulas,...}) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2010
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2011
        val {cnfAxioms,fofAxioms,goal} = partitionFormulas formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2012
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2013
        val fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2014
            case goal of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2015
              NoGoal => Formula.False
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2016
            | CnfGoal cls => Formula.Imp (clausesToGoal cls, Formula.False)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2017
            | FofGoal goals => formulasToGoal goals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2018
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2019
        val fm =
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  2020
            if List.null fofAxioms then fm
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2021
            else Formula.Imp (formulasToGoal fofAxioms, fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2022
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2023
        val fm =
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  2024
            if List.null cnfAxioms then fm
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2025
            else Formula.Imp (clausesToGoal cnfAxioms, fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2026
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2027
        fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2028
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2029
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2030
  fun normalize (Problem {formulas,...}) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2031
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2032
        val {cnfAxioms,fofAxioms,goal} = partitionFormulas formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2033
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2034
        val acc = (initialNormalization, Normalize.initialCnf)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2035
        val acc = List.foldl addCnfAxiom acc cnfAxioms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2036
        val acc = List.foldl addFofAxiom acc fofAxioms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2037
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2038
        case goal of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2039
          NoGoal => [normProblemFalse acc]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2040
        | CnfGoal cls => [normProblemFalse (List.foldl addCnfGoal acc cls)]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2041
        | FofGoal goals => splitProblem acc goals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2042
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2043
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2044
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2045
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2046
  datatype blockComment =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2047
      OutsideBlockComment
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2048
    | EnteringBlockComment
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2049
    | InsideBlockComment
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2050
    | LeavingBlockComment;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2051
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2052
  fun stripLineComments acc strm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2053
      case strm of
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  2054
        Stream.Nil => (List.rev acc, Stream.Nil)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2055
      | Stream.Cons (line,rest) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2056
        case total destLineComment line of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2057
          SOME s => stripLineComments (s :: acc) (rest ())
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  2058
        | NONE => (List.rev acc, Stream.filter (not o isLineComment) strm);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2059
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2060
  fun advanceBlockComment c state =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2061
      case state of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2062
        OutsideBlockComment =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2063
        if c = #"/" then (Stream.Nil, EnteringBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2064
        else (Stream.singleton c, OutsideBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2065
      | EnteringBlockComment =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2066
        if c = #"*" then (Stream.Nil, InsideBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2067
        else if c = #"/" then (Stream.singleton #"/", EnteringBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2068
        else (Stream.fromList [#"/",c], OutsideBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2069
      | InsideBlockComment =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2070
        if c = #"*" then (Stream.Nil, LeavingBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2071
        else (Stream.Nil, InsideBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2072
      | LeavingBlockComment =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2073
        if c = #"/" then (Stream.Nil, OutsideBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2074
        else if c = #"*" then (Stream.Nil, LeavingBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2075
        else (Stream.Nil, InsideBlockComment);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2076
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2077
  fun eofBlockComment state =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2078
      case state of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2079
        OutsideBlockComment => Stream.Nil
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2080
      | EnteringBlockComment => Stream.singleton #"/"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2081
      | _ => raise Error "EOF inside a block comment";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2082
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2083
  val stripBlockComments =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2084
      Stream.mapsConcat advanceBlockComment eofBlockComment
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2085
        OutsideBlockComment;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2086
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2087
  fun read {mapping,filename} =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2088
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2089
        (* Estimating parse error line numbers *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2090
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2091
        val lines = Stream.fromTextFile {filename = filename}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2092
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2093
        val {chars,parseErrorLocation} = Parse.initialize {lines = lines}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2094
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2095
        (let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2096
           (* The character stream *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2097
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2098
           val (comments,chars) = stripLineComments [] chars
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2099
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2100
           val chars = Parse.everything Parse.any chars
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2101
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2102
           val chars = stripBlockComments chars
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2103
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2104
           (* The declaration stream *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2105
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2106
           val declarations = Stream.toList (parseDeclaration mapping chars)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2107
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2108
           val (includes,formulas) = partitionDeclarations declarations
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2109
         in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2110
           Problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2111
             {comments = comments,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2112
              includes = includes,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2113
              formulas = formulas}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2114
         end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2115
         handle Parse.NoParse => raise Error "parse error")
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2116
        handle Error err =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2117
          raise Error ("error in TPTP file \"" ^ filename ^ "\" " ^
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2118
                       parseErrorLocation () ^ "\n" ^ err)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2119
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2120
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2121
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2122
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2123
  val newline = Stream.singleton "\n";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2124
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2125
  fun spacer top = if top then Stream.Nil else newline;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2126
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2127
  fun mkComment comment = mkLineComment comment ^ "\n";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2128
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2129
  fun mkInclude inc = includeToString inc ^ "\n";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2130
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2131
  fun formulaStream _ _ [] = Stream.Nil
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2132
    | formulaStream mapping top (h :: t) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2133
      Stream.append
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2134
        (Stream.concatList
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2135
           [spacer top,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2136
            Stream.singleton (formulaToString mapping h),
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2137
            newline])
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2138
        (fn () => formulaStream mapping false t);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2139
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2140
  fun write {problem,mapping,filename} =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2141
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2142
        val Problem {comments,includes,formulas} = problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2143
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  2144
        val includesTop = List.null comments
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  2145
        val formulasTop = includesTop andalso List.null includes
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2146
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2147
        Stream.toTextFile
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2148
          {filename = filename}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2149
          (Stream.concatList
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2150
             [Stream.map mkComment (Stream.fromList comments),
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2151
              spacer includesTop,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2152
              Stream.map mkInclude (Stream.fromList includes),
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2153
              formulaStream mapping formulasTop formulas])
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2154
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2155
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2156
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2157
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2158
  fun refute {axioms,conjecture} =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2159
      let
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  2160
        val axioms = List.map Thm.axiom axioms
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  2161
        and conjecture = List.map Thm.axiom conjecture
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2162
        val problem = {axioms = axioms, conjecture = conjecture}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2163
        val resolution = Resolution.new Resolution.default problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2164
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2165
        case Resolution.loop resolution of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2166
          Resolution.Contradiction _ => true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2167
        | Resolution.Satisfiable _ => false
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2168
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2169
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2170
  fun prove filename =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2171
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2172
        val problem = read filename
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  2173
        val problems = List.map #problem (normalize problem)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2174
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2175
        List.all refute problems
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2176
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2177
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2178
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2179
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2180
(* TSTP proofs.                                                              *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2181
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2182
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2183
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2184
  fun newName avoid prefix =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2185
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2186
        fun bump i =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2187
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2188
              val name = FormulaName (prefix ^ Int.toString i)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2189
              val i = i + 1
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2190
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2191
              if memberFormulaNameSet name avoid then bump i else (name,i)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2192
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2193
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2194
        bump
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2195
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2196
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2197
  fun lookupClauseSource sources cl =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2198
      case LiteralSetMap.peek sources cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2199
        SOME src => src
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2200
      | NONE => raise Bug "Tptp.lookupClauseSource";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2201
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2202
  fun lookupFormulaName fmNames fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2203
      case FormulaMap.peek fmNames fm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2204
        SOME name => name
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2205
      | NONE => raise Bug "Tptp.lookupFormulaName";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2206
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2207
  fun lookupClauseName clNames cl =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2208
      case LiteralSetMap.peek clNames cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2209
        SOME name => name
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2210
      | NONE => raise Bug "Tptp.lookupClauseName";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2211
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2212
  fun lookupClauseSourceName sources fmNames cl =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2213
      case lookupClauseSource sources cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2214
        CnfClauseSource (name,_) => name
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2215
      | FofClauseSource th =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2216
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2217
          val (fm,_) = Normalize.destThm th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2218
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2219
          lookupFormulaName fmNames fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2220
        end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2221
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2222
  fun collectProofDeps sources ((_,inf),names_ths) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2223
      case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2224
        Proof.Axiom cl =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2225
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2226
          val (names,ths) = names_ths
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2227
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2228
          case lookupClauseSource sources cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2229
            CnfClauseSource (name,_) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2230
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2231
              val names = addFormulaNameSet names name
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2232
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2233
              (names,ths)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2234
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2235
          | FofClauseSource th =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2236
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2237
              val ths = th :: ths
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2238
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2239
              (names,ths)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2240
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2241
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2242
      | _ => names_ths;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2243
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2244
  fun collectNormalizeDeps ((_,inf,_),fofs_defs) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2245
      case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2246
        Normalize.Axiom fm =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2247
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2248
          val (fofs,defs) = fofs_defs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2249
          val fofs = FormulaSet.add fofs fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2250
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2251
          (fofs,defs)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2252
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2253
      | Normalize.Definition n_d =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2254
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2255
          val (fofs,defs) = fofs_defs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2256
          val defs = StringMap.insert defs n_d
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2257
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2258
          (fofs,defs)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2259
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2260
      | _ => fofs_defs;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2261
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2262
  fun collectSubgoalProofDeps subgoalProof (names,fofs,defs) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2263
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2264
        val {subgoal,sources,refutation} = subgoalProof
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2265
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2266
        val names = addListFormulaNameSet names (snd subgoal)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2267
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2268
        val proof = Proof.proof refutation
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2269
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2270
        val (names,ths) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2271
            List.foldl (collectProofDeps sources) (names,[]) proof
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2272
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  2273
        val normalization = Normalize.proveThms (List.rev ths)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2274
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2275
        val (fofs,defs) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2276
            List.foldl collectNormalizeDeps (fofs,defs) normalization
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2277
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2278
        val subgoalProof =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2279
            {subgoal = subgoal,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2280
             normalization = normalization,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2281
             sources = sources,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2282
             proof = proof}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2283
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2284
        (subgoalProof,(names,fofs,defs))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2285
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2286
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2287
  fun addProblemFormula names fofs (formula,(avoid,formulas,fmNames)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2288
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2289
        val name = nameFormula formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2290
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2291
        val avoid = addFormulaNameSet avoid name
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2292
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2293
        val (formulas,fmNames) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2294
            if memberFormulaNameSet name names then
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2295
              (formula :: formulas, fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2296
            else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2297
              case bodyFormula formula of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2298
                CnfFormulaBody _ => (formulas,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2299
              | FofFormulaBody fm =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2300
                if not (FormulaSet.member fm fofs) then (formulas,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2301
                else (formula :: formulas, FormulaMap.insert fmNames (fm,name))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2302
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2303
        (avoid,formulas,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2304
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2305
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2306
  fun addDefinitionFormula avoid (_,def,(formulas,i,fmNames)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2307
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2308
        val (name,i) = newName avoid "definition_" i
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2309
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2310
        val role = DefinitionRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2311
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2312
        val body = FofFormulaBody def
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2313
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2314
        val source = NoFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2315
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2316
        val formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2317
            Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2318
              {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2319
               role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2320
               body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2321
               source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2322
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2323
        val formulas = formula :: formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2324
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2325
        val fmNames = FormulaMap.insert fmNames (def,name)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2326
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2327
        (formulas,i,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2328
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2329
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2330
  fun addSubgoalFormula avoid subgoalProof (formulas,i) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2331
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2332
        val {subgoal,normalization,sources,proof} = subgoalProof
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2333
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2334
        val (fm,pars) = subgoal
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2335
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2336
        val (name,i) = newName avoid "subgoal_" i
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2337
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2338
        val number = i - 1
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2339
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2340
        val (subgoal,formulas) =
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  2341
            if List.null pars then (NONE,formulas)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2342
            else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2343
              let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2344
                val role = PlainRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2345
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2346
                val body = FofFormulaBody fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2347
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2348
                val source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2349
                    StripFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2350
                      {inference = "strip",
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2351
                       parents = pars}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2352
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2353
                val formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2354
                    Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2355
                      {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2356
                       role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2357
                       body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2358
                       source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2359
              in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2360
                (SOME (name,fm), formula :: formulas)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2361
              end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2362
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2363
        val subgoalProof =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2364
            {number = number,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2365
             subgoal = subgoal,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2366
             normalization = normalization,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2367
             sources = sources,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2368
             proof = proof}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2369
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2370
        (subgoalProof,(formulas,i))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2371
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2372
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2373
  fun mkNormalizeFormulaSource fmNames inference fms =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2374
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2375
        val fms =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2376
            case inference of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2377
              Normalize.Axiom fm => fm :: fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2378
            | Normalize.Definition (_,fm) => fm :: fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2379
            | _ => fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2380
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  2381
        val parents = List.map (lookupFormulaName fmNames) fms
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2382
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2383
        NormalizeFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2384
          {inference = inference,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2385
           parents = parents}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2386
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2387
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2388
  fun mkProofFormulaSource sources fmNames clNames inference =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2389
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2390
        val parents =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2391
            case inference of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2392
              Proof.Axiom cl => [lookupClauseSourceName sources fmNames cl]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2393
            | _ =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2394
              let
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  2395
                val cls = List.map Thm.clause (Proof.parents inference)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2396
              in
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
  2397
                List.map (lookupClauseName clNames) cls
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2398
              end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2399
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2400
        ProofFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2401
          {inference = inference,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2402
           parents = parents}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2403
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2404
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2405
  fun addNormalizeFormula avoid prefix ((fm,inf,fms),acc) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2406
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2407
        val (formulas,i,fmNames) = acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2408
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2409
        val (name,i) = newName avoid prefix i
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2410
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2411
        val role = PlainRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2412
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2413
        val body = FofFormulaBody fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2414
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2415
        val source = mkNormalizeFormulaSource fmNames inf fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2416
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2417
        val formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2418
            Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2419
              {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2420
               role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2421
               body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2422
               source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2423
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2424
        val formulas = formula :: formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2425
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2426
        val fmNames = FormulaMap.insert fmNames (fm,name)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2427
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2428
        (formulas,i,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2429
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2430
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2431
  fun isSameClause sources formulas inf =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2432
      case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2433
        Proof.Axiom cl =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2434
          (case lookupClauseSource sources cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2435
             CnfClauseSource (name,lits) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2436
             if List.exists isBooleanLiteral lits then NONE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2437
             else SOME name
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2438
           | _ => NONE)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2439
      | _ => NONE;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2440
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2441
  fun addProofFormula avoid sources fmNames prefix ((th,inf),acc) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2442
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2443
        val (formulas,i,clNames) = acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2444
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2445
        val cl = Thm.clause th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2446
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2447
        case isSameClause sources formulas inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2448
          SOME name =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2449
          let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2450
            val clNames = LiteralSetMap.insert clNames (cl,name)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2451
          in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2452
            (formulas,i,clNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2453
          end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2454
        | NONE =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2455
          let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2456
            val (name,i) = newName avoid prefix i
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2457
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2458
            val role = PlainRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2459
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2460
            val body = CnfFormulaBody (clauseFromLiteralSet cl)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2461
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2462
            val source = mkProofFormulaSource sources fmNames clNames inf
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2463
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2464
            val formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2465
                Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2466
                  {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2467
                   role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2468
                   body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2469
                   source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2470
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2471
            val formulas = formula :: formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2472
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2473
            val clNames = LiteralSetMap.insert clNames (cl,name)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2474
          in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2475
            (formulas,i,clNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2476
          end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2477
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2478
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2479
  fun addSubgoalProofFormulas avoid fmNames (subgoalProof,formulas) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2480
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2481
        val {number,subgoal,normalization,sources,proof} = subgoalProof
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2482
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2483
        val (formulas,fmNames) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2484
            case subgoal of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2485
              NONE => (formulas,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2486
            | SOME (name,fm) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2487
              let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2488
                val source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2489
                    StripFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2490
                      {inference = "negate",
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2491
                       parents = [name]}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2492
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2493
                val prefix = "negate_" ^ Int.toString number ^ "_"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2494
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2495
                val (name,_) = newName avoid prefix 0
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2496
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2497
                val role = PlainRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2498
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2499
                val fm = Formula.Not fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2500
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2501
                val body = FofFormulaBody fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2502
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2503
                val formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2504
                    Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2505
                      {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2506
                       role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2507
                       body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2508
                       source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2509
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2510
                val formulas = formula :: formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2511
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2512
                val fmNames = FormulaMap.insert fmNames (fm,name)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2513
              in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2514
                (formulas,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2515
              end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2516
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2517
        val prefix = "normalize_" ^ Int.toString number ^ "_"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2518
        val (formulas,_,fmNames) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2519
            List.foldl (addNormalizeFormula avoid prefix)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2520
              (formulas,0,fmNames) normalization
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2521
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2522
        val prefix = "refute_" ^ Int.toString number ^ "_"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2523
        val clNames : formulaName LiteralSetMap.map = LiteralSetMap.new ()
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2524
        val (formulas,_,_) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2525
            List.foldl (addProofFormula avoid sources fmNames prefix)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2526
              (formulas,0,clNames) proof
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2527
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2528
        formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2529
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2530
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2531
  fun fromProof {problem,proofs} =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2532
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2533
        val names = emptyFormulaNameSet
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2534
        and fofs = FormulaSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2535
        and defs : Formula.formula StringMap.map = StringMap.new ()
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2536
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2537
        val (proofs,(names,fofs,defs)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2538
            maps collectSubgoalProofDeps proofs (names,fofs,defs)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2539
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2540
        val Problem {formulas,...} = problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2541
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2542
        val fmNames : formulaName FormulaMap.map = FormulaMap.new ()
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2543
        val (avoid,formulas,fmNames) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2544
            List.foldl (addProblemFormula names fofs)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2545
              (emptyFormulaNameSet,[],fmNames) formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2546
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2547
        val (formulas,_,fmNames) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2548
            StringMap.foldl (addDefinitionFormula avoid)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2549
              (formulas,0,fmNames) defs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2550
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2551
        val (proofs,(formulas,_)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2552
            maps (addSubgoalFormula avoid) proofs (formulas,0)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2553
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2554
        val formulas =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2555
            List.foldl (addSubgoalProofFormulas avoid fmNames) formulas proofs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2556
      in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
  2557
        List.rev formulas
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2558
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2559
(*MetisDebug
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2560
      handle Error err => raise Bug ("Tptp.fromProof: shouldn't fail:\n" ^ err);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2561
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2562
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2563
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2564
end