src/Tools/Metis/src/Tptp.sml
author blanchet
Fri, 17 Sep 2010 01:56:19 +0200
changeset 39501 aaa7078fff55
parent 39444 beabb8443ee4
child 39502 cffceed8e7fa
permissions -rw-r--r--
updated source files with Metis 2.3 (timestamp: 16 Sept. 2010)
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                                              *)
39501
aaa7078fff55 updated source files with Metis 2.3 (timestamp: 16 Sept. 2010)
blanchet
parents: 39444
diff changeset
     3
(* Copyright (c) 2001 Joe Hurd, distributed under the MIT 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
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   433
      val functionMapping = map lift defaultFunctionMapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   434
      and relationMapping = map lift defaultRelationMapping
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
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   451
      fun mkMap l = NameArityMap.fromList (map mkEntry l)
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 =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   634
              Print.blockProgram Print.Inconsistent 2
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
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   640
      Print.block Print.Inconsistent 0 o term
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 =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   651
      Print.blockProgram Print.Inconsistent 2
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
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   658
  val neg = Print.sequence (Print.ppString "~") (Print.addBreak 1);
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
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   686
             Print.blockProgram Print.Inconsistent 2
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
      | _ =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   695
        Print.blockProgram Print.Inconsistent 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
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   704
        Print.blockProgram Print.Inconsistent 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 " ",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   707
           Print.blockProgram Print.Inconsistent (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 "] :"],
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   711
           Print.addBreak 1,
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
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   715
  fun ppFof mapping fm = Print.block Print.Inconsistent 0 (fof mapping fm);
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 ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   769
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   770
  val lexer = (space ++ lexToken ++ space) >> (fn ((),(tok,())) => tok);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   771
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   772
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   773
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   774
(* TPTP clauses.                                                             *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   775
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   776
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   777
type clause = literal list;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   778
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   779
val clauseFunctions =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   780
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   781
      fun funcs (lit,acc) = NameAritySet.union (functionsLiteral lit) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   782
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   783
      List.foldl funcs NameAritySet.empty
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   784
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   785
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   786
val clauseRelations =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   787
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   788
      fun rels (lit,acc) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   789
          case relationLiteral lit of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   790
            NONE => acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   791
          | SOME r => NameAritySet.add acc r
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   792
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   793
      List.foldl rels NameAritySet.empty
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   794
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   795
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   796
val clauseFreeVars =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   797
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   798
      fun fvs (lit,acc) = NameSet.union (freeVarsLiteral lit) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   799
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   800
      List.foldl fvs NameSet.empty
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   801
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   802
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   803
fun clauseSubst sub lits = map (literalSubst sub) lits;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   804
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   805
fun clauseToFormula lits = Formula.listMkDisj (map literalToFormula lits);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   806
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   807
fun clauseFromFormula fm = map literalFromFormula (Formula.stripDisj fm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   808
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   809
fun clauseFromLiteralSet cl =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   810
    clauseFromFormula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   811
      (Formula.listMkDisj (LiteralSet.transform Literal.toFormula cl));
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 clauseFromThm th = clauseFromLiteralSet (Thm.clause th);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   814
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   815
fun ppClause mapping = Print.ppMap clauseToFormula (ppFof mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   816
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   817
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   818
(* TPTP formula names.                                                       *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   819
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   820
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   821
datatype formulaName = FormulaName of string;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   822
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   823
datatype formulaNameSet = FormulaNameSet of formulaName Set.set;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   824
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   825
fun compareFormulaName (FormulaName s1, FormulaName s2) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   826
    String.compare (s1,s2);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   827
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   828
fun toTptpFormulaName (FormulaName s) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   829
    getNameToTptp isTptpFormulaName s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   830
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   831
val ppFormulaName = Print.ppMap toTptpFormulaName Print.ppString;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   832
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   833
val emptyFormulaNameSet = FormulaNameSet (Set.empty compareFormulaName);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   834
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   835
fun memberFormulaNameSet n (FormulaNameSet s) = Set.member n s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   836
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   837
fun addFormulaNameSet (FormulaNameSet s) n = FormulaNameSet (Set.add s n);
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 addListFormulaNameSet (FormulaNameSet s) l =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   840
    FormulaNameSet (Set.addList s l);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   841
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   842
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   843
(* TPTP formula bodies.                                                      *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   844
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   845
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   846
datatype formulaBody =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   847
    CnfFormulaBody of literal list
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   848
  | FofFormulaBody of Formula.formula;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   849
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   850
fun destCnfFormulaBody body =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   851
    case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   852
      CnfFormulaBody x => x
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   853
    | _ => raise Error "destCnfFormulaBody";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   854
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   855
val isCnfFormulaBody = can destCnfFormulaBody;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   856
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   857
fun destFofFormulaBody body =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   858
    case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   859
      FofFormulaBody x => x
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   860
    | _ => raise Error "destFofFormulaBody";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   861
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   862
val isFofFormulaBody = can destFofFormulaBody;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   863
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   864
fun formulaBodyFunctions body =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   865
    case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   866
      CnfFormulaBody cl => clauseFunctions cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   867
    | FofFormulaBody fm => Formula.functions fm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   868
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   869
fun formulaBodyRelations body =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   870
    case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   871
      CnfFormulaBody cl => clauseRelations cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   872
    | FofFormulaBody fm => Formula.relations fm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   873
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   874
fun formulaBodyFreeVars body =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   875
    case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   876
      CnfFormulaBody cl => clauseFreeVars cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   877
    | FofFormulaBody fm => Formula.freeVars fm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   878
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   879
fun ppFormulaBody mapping body =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   880
    case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   881
      CnfFormulaBody cl => ppClause mapping cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   882
    | FofFormulaBody fm => ppFof mapping (Formula.generalize fm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   883
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   884
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   885
(* TPTP formula sources.                                                     *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   886
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   887
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   888
datatype formulaSource =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   889
    NoFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   890
  | StripFormulaSource of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   891
      {inference : string,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   892
       parents : formulaName list}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   893
  | NormalizeFormulaSource of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   894
      {inference : Normalize.inference,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   895
       parents : formulaName list}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   896
  | ProofFormulaSource of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   897
      {inference : Proof.inference,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   898
       parents : formulaName list};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   899
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   900
fun isNoFormulaSource source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   901
    case source of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   902
      NoFormulaSource => true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   903
    | _ => false;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   904
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   905
fun functionsFormulaSource source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   906
    case source of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   907
      NoFormulaSource => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   908
    | StripFormulaSource _ => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   909
    | NormalizeFormulaSource data =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   910
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   911
        val {inference = inf, parents = _} = data
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   912
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   913
        case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   914
          Normalize.Axiom fm => Formula.functions fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   915
        | Normalize.Definition (_,fm) => Formula.functions fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   916
        | _ => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   917
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   918
    | ProofFormulaSource data =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   919
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   920
        val {inference = inf, parents = _} = data
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   921
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   922
        case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   923
          Proof.Axiom cl => LiteralSet.functions cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   924
        | Proof.Assume atm => Atom.functions atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   925
        | Proof.Subst (sub,_) => Subst.functions sub
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   926
        | Proof.Resolve (atm,_,_) => Atom.functions atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   927
        | Proof.Refl tm => Term.functions tm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   928
        | Proof.Equality (lit,_,tm) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   929
          NameAritySet.union (Literal.functions lit) (Term.functions tm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   930
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   931
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   932
fun relationsFormulaSource source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   933
    case source of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   934
      NoFormulaSource => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   935
    | StripFormulaSource _ => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   936
    | NormalizeFormulaSource data =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   937
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   938
        val {inference = inf, parents = _} = data
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   939
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   940
        case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   941
          Normalize.Axiom fm => Formula.relations fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   942
        | Normalize.Definition (_,fm) => Formula.relations fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   943
        | _ => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   944
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   945
    | ProofFormulaSource data =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   946
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   947
        val {inference = inf, parents = _} = data
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   948
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   949
        case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   950
          Proof.Axiom cl => LiteralSet.relations cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   951
        | Proof.Assume atm => NameAritySet.singleton (Atom.relation atm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   952
        | Proof.Subst _ => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   953
        | Proof.Resolve (atm,_,_) => NameAritySet.singleton (Atom.relation atm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   954
        | Proof.Refl tm => NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   955
        | Proof.Equality (lit,_,_) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   956
          NameAritySet.singleton (Literal.relation lit)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   957
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   958
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   959
fun freeVarsFormulaSource source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   960
    case source of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   961
      NoFormulaSource => NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   962
    | StripFormulaSource _ => NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   963
    | NormalizeFormulaSource data => NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   964
    | ProofFormulaSource data =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   965
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   966
        val {inference = inf, parents = _} = data
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   967
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   968
        case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   969
          Proof.Axiom cl => LiteralSet.freeVars cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   970
        | Proof.Assume atm => Atom.freeVars atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   971
        | Proof.Subst (sub,_) => Subst.freeVars sub
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   972
        | Proof.Resolve (atm,_,_) => Atom.freeVars atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   973
        | Proof.Refl tm => Term.freeVars tm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   974
        | Proof.Equality (lit,_,tm) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   975
          NameSet.union (Literal.freeVars lit) (Term.freeVars tm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   976
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   977
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   978
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   979
  val GEN_INFERENCE = "inference"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   980
  and GEN_INTRODUCED = "introduced";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   981
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   982
  fun nameStrip inf = inf;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   983
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   984
  fun ppStrip mapping inf = Print.skip;
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 nameNormalize inf =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   987
      case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   988
        Normalize.Axiom _ => "canonicalize"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   989
      | Normalize.Definition _ => "canonicalize"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   990
      | Normalize.Simplify _ => "simplify"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   991
      | Normalize.Conjunct _ => "conjunct"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   992
      | Normalize.Specialize _ => "specialize"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   993
      | Normalize.Skolemize _ => "skolemize"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   994
      | Normalize.Clausify _ => "clausify";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   995
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   996
  fun ppNormalize mapping inf = Print.skip;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   997
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   998
  fun nameProof inf =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   999
      case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1000
        Proof.Axiom _ => "canonicalize"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1001
      | Proof.Assume _ => "assume"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1002
      | Proof.Subst _ => "subst"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1003
      | Proof.Resolve _ => "resolve"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1004
      | Proof.Refl _ => "refl"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1005
      | Proof.Equality _ => "equality";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1006
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1007
  local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1008
    fun ppTermInf mapping = ppTerm mapping;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1009
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1010
    fun ppAtomInf mapping atm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1011
        case total Atom.destEq atm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1012
          SOME (a,b) => ppAtom mapping (Name.fromString "$equal", [a,b])
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1013
        | NONE => ppAtom mapping atm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1014
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1015
    fun ppLiteralInf mapping (pol,atm) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1016
        Print.sequence
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1017
          (if pol then Print.skip else Print.ppString "~ ")
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1018
          (ppAtomInf mapping atm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1019
  in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1020
    fun ppProofTerm mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1021
        Print.ppBracket "$fot(" ")" (ppTermInf mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1022
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1023
    fun ppProofAtom mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1024
        Print.ppBracket "$cnf(" ")" (ppAtomInf mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1025
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1026
    fun ppProofLiteral mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1027
        Print.ppBracket "$cnf(" ")" (ppLiteralInf mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1028
  end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1029
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1030
  val ppProofVar = ppVar;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1031
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1032
  val ppProofPath = Term.ppPath;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1033
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1034
  fun ppProof mapping inf =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1035
      Print.blockProgram Print.Inconsistent 1
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1036
        [Print.ppString "[",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1037
         (case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1038
            Proof.Axiom _ => Print.skip
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1039
          | Proof.Assume atm => ppProofAtom mapping atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1040
          | Proof.Subst _ => Print.skip
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1041
          | Proof.Resolve (atm,_,_) => ppProofAtom mapping atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1042
          | Proof.Refl tm => ppProofTerm mapping tm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1043
          | Proof.Equality (lit,path,tm) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1044
            Print.program
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1045
              [ppProofLiteral mapping lit,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1046
               Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1047
               Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1048
               ppProofPath path,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1049
               Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1050
               Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1051
               ppProofTerm mapping tm]),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1052
         Print.ppString "]"];
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1053
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1054
  val ppParent = ppFormulaName;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1055
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1056
  fun ppProofSubst mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1057
      Print.ppMap Subst.toList
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1058
        (Print.ppList
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1059
           (Print.ppBracket "bind(" ")"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1060
              (Print.ppOp2 "," (ppProofVar mapping)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1061
                 (ppProofTerm mapping))));
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1062
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1063
  fun ppProofParent mapping (p,s) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1064
      if Subst.null s then ppParent p
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1065
      else Print.ppOp2 " :" ppParent (ppProofSubst mapping) (p,s);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1066
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1067
  fun ppFormulaSource mapping source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1068
      case source of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1069
        NoFormulaSource => Print.skip
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1070
      | StripFormulaSource {inference,parents} =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1071
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1072
          val gen = GEN_INFERENCE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1073
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1074
          val name = nameStrip inference
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1075
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1076
          Print.blockProgram Print.Inconsistent (size gen + 1)
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1077
            [Print.ppString gen,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1078
             Print.ppString "(",
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1079
             Print.ppString name,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1080
             Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1081
             Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1082
             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
  1083
             Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1084
             Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1085
             Print.ppList ppParent parents,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1086
             Print.ppString ")"]
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1087
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1088
      | NormalizeFormulaSource {inference,parents} =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1089
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1090
          val gen = GEN_INFERENCE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1091
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1092
          val name = nameNormalize inference
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1093
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1094
          Print.blockProgram Print.Inconsistent (size gen + 1)
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1095
            [Print.ppString gen,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1096
             Print.ppString "(",
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1097
             Print.ppString name,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1098
             Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1099
             Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1100
             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
  1101
             Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1102
             Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1103
             Print.ppList ppParent parents,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1104
             Print.ppString ")"]
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1105
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1106
      | ProofFormulaSource {inference,parents} =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1107
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1108
          val isTaut = null parents
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1109
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1110
          val gen = if isTaut then GEN_INTRODUCED else GEN_INFERENCE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1111
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1112
          val name = nameProof inference
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 parents =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1115
              let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1116
                val sub =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1117
                    case inference of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1118
                      Proof.Subst (s,_) => s
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1119
                    | _ => Subst.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1120
              in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1121
                map (fn parent => (parent,sub)) parents
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1122
              end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1123
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1124
          Print.blockProgram Print.Inconsistent (size gen + 1)
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1125
            ([Print.ppString gen,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1126
              Print.ppString "("] @
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1127
             (if isTaut then
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1128
                [Print.ppString "tautology",
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1129
                 Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1130
                 Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1131
                 Print.blockProgram Print.Inconsistent 1
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1132
                   [Print.ppString "[",
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1133
                    Print.ppString name,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1134
                    Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1135
                    Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1136
                    ppProof mapping inference,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1137
                    Print.ppString "]"]]
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1138
              else
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1139
                [Print.ppString name,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1140
                 Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1141
                 Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1142
                 ppProof mapping inference,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1143
                 Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1144
                 Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1145
                 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
  1146
             [Print.ppString ")"])
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1147
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1148
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1149
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1150
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1151
(* TPTP formulas.                                                            *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1152
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1153
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1154
datatype formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1155
    Formula of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1156
      {name : formulaName,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1157
       role : role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1158
       body : formulaBody,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1159
       source : formulaSource};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1160
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1161
fun nameFormula (Formula {name,...}) = name;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1162
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1163
fun roleFormula (Formula {role,...}) = role;
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 bodyFormula (Formula {body,...}) = body;
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 sourceFormula (Formula {source,...}) = source;
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 destCnfFormula fm = destCnfFormulaBody (bodyFormula fm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1170
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1171
val isCnfFormula = can destCnfFormula;
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 destFofFormula fm = destFofFormulaBody (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 isFofFormula = can destFofFormula;
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 functionsFormula fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1178
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1179
      val bodyFns = formulaBodyFunctions (bodyFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1180
      and sourceFns = functionsFormulaSource (sourceFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1181
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1182
      NameAritySet.union bodyFns sourceFns
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1183
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1184
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1185
fun relationsFormula fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1186
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1187
      val bodyRels = formulaBodyRelations (bodyFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1188
      and sourceRels = relationsFormulaSource (sourceFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1189
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1190
      NameAritySet.union bodyRels sourceRels
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1191
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1192
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1193
fun freeVarsFormula fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1194
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1195
      val bodyFvs = formulaBodyFreeVars (bodyFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1196
      and sourceFvs = freeVarsFormulaSource (sourceFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1197
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1198
      NameSet.union bodyFvs sourceFvs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1199
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1200
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1201
val freeVarsListFormula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1202
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1203
      fun add (fm,vs) = NameSet.union vs (freeVarsFormula fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1204
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1205
      List.foldl add NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1206
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1207
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1208
val formulasFunctions =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1209
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1210
      fun funcs (fm,acc) = NameAritySet.union (functionsFormula fm) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1211
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1212
      List.foldl funcs NameAritySet.empty
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1213
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1214
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1215
val formulasRelations =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1216
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1217
      fun rels (fm,acc) = NameAritySet.union (relationsFormula fm) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1218
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1219
      List.foldl rels NameAritySet.empty
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1220
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1221
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1222
fun isCnfConjectureFormula fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1223
    case fm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1224
      Formula {role, body = CnfFormulaBody _, ...} => isCnfConjectureRole role
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1225
    | _ => false;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1226
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1227
fun isFofConjectureFormula fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1228
    case fm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1229
      Formula {role, body = FofFormulaBody _, ...} => isFofConjectureRole role
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1230
    | _ => false;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1231
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1232
fun isConjectureFormula fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1233
    isCnfConjectureFormula fm orelse
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1234
    isFofConjectureFormula fm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1235
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1236
(* Parsing and pretty-printing *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1237
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1238
fun ppFormula mapping fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1239
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1240
      val Formula {name,role,body,source} = fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1241
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1242
      val gen =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1243
          case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1244
            CnfFormulaBody _ => "cnf"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1245
          | FofFormulaBody _ => "fof"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1246
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1247
      Print.blockProgram Print.Inconsistent (size gen + 1)
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1248
        ([Print.ppString gen,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1249
          Print.ppString "(",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1250
          ppFormulaName name,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1251
          Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1252
          Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1253
          ppRole role,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1254
          Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1255
          Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1256
          Print.blockProgram Print.Consistent 1
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1257
            [Print.ppString "(",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1258
             ppFormulaBody mapping body,
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1259
             Print.ppString ")"]] @
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1260
         (if isNoFormulaSource source then []
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1261
          else
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1262
            [Print.ppString ",",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1263
             Print.addBreak 1,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1264
             ppFormulaSource mapping source]) @
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1265
         [Print.ppString ")."])
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1266
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1267
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1268
fun formulaToString mapping = Print.toString (ppFormula mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1269
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1270
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1271
  open Parse;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1272
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1273
  infixr 9 >>++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1274
  infixr 8 ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1275
  infixr 7 >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1276
  infixr 6 ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1277
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1278
  fun someAlphaNum p =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1279
      maybe (fn AlphaNum s => if p s then SOME s else NONE | _ => NONE);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1280
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1281
  fun alphaNumParser s = someAlphaNum (equal s) >> K ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1282
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1283
  val lowerParser = someAlphaNum (fn s => Char.isLower (String.sub (s,0)));
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1284
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1285
  val upperParser = someAlphaNum (fn s => Char.isUpper (String.sub (s,0)));
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 stringParser = lowerParser || upperParser;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1288
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1289
  val numberParser = someAlphaNum (List.all Char.isDigit o String.explode);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1290
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1291
  fun somePunct p =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1292
      maybe (fn Punct c => if p c then SOME c else NONE | _ => NONE);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1293
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1294
  fun punctParser c = somePunct (equal c) >> K ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1295
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1296
  val quoteParser = maybe (fn Quote s => SOME s | _ => 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
  local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1299
    fun f [] = raise Bug "symbolParser"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1300
      | f [x] = x
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1301
      | f (h :: t) = (h ++ f t) >> K ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1302
  in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1303
    fun symbolParser s = f (map punctParser (String.explode s));
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1304
  end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1305
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1306
  val definedParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1307
      punctParser #"$" ++ someAlphaNum (K true) >> (fn ((),s) => "$" ^ s);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1308
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1309
  val systemParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1310
      punctParser #"$" ++ punctParser #"$" ++ someAlphaNum (K true) >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1311
      (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 nameParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1314
      (stringParser || numberParser || quoteParser) >> FormulaName;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1315
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1316
  val roleParser = lowerParser >> fromStringRole;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1317
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1318
  local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1319
    fun isProposition s = isHdTlString Char.isLower isAlphaNum s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1320
  in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1321
    val propositionParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1322
        someAlphaNum isProposition ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1323
        definedParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1324
        systemParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1325
        quoteParser;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1326
  end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1327
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1328
  local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1329
    fun isFunction s = isHdTlString Char.isLower isAlphaNum s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1330
  in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1331
    val functionParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1332
        someAlphaNum isFunction ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1333
        definedParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1334
        systemParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1335
        quoteParser;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1336
  end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1337
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1338
  local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1339
    fun isConstant s = isHdTlString Char.isLower isAlphaNum s;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1340
  in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1341
    val constantParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1342
        someAlphaNum isConstant ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1343
        definedParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1344
        numberParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1345
        systemParser ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1346
        quoteParser;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1347
  end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1349
  val varParser = upperParser;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1350
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1351
  val varListParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1352
      (punctParser #"[" ++ varParser ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1353
       many ((punctParser #"," ++ varParser) >> snd) ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1354
       punctParser #"]") >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1355
      (fn ((),(h,(t,()))) => h :: t);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1356
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1357
  fun mkVarName mapping v = varFromTptp mapping v;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1358
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1359
  fun mkVar mapping v =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1360
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1361
        val v = mkVarName mapping v
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1362
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1363
        Term.Var v
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1364
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1365
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1366
  fun mkFn mapping (f,tms) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1367
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1368
        val f = fnFromTptp mapping (f, length tms)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1369
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1370
        Term.Fn (f,tms)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1371
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1372
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1373
  fun mkConst mapping c = mkFn mapping (c,[]);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1374
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1375
  fun mkAtom mapping (r,tms) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1376
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1377
        val r = relFromTptp mapping (r, length tms)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1378
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1379
        (r,tms)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1380
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1381
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1382
  fun termParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1383
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1384
        val fnP = functionArgumentsParser mapping >> mkFn mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1385
        val nonFnP = nonFunctionArgumentsTermParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1386
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1387
        fnP || nonFnP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1388
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1389
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1390
  and functionArgumentsParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1391
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1392
        val commaTmP = (punctParser #"," ++ termParser mapping) >> snd
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1393
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1394
        (functionParser ++ punctParser #"(" ++ termParser mapping ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1395
         many commaTmP ++ punctParser #")") >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1396
        (fn (f,((),(t,(ts,())))) => (f, t :: ts))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1397
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1398
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1399
  and nonFunctionArgumentsTermParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1400
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1401
        val varP = varParser >> mkVar mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1402
        val constP = constantParser >> mkConst mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1403
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1404
        varP || constP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1405
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1406
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1407
  fun binaryAtomParser mapping tm input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1408
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1409
        val eqP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1410
            (punctParser #"=" ++ termParser mapping) >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1411
            (fn ((),r) => (true,("$equal",[tm,r])))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1412
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1413
        val neqP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1414
            (symbolParser "!=" ++ termParser mapping) >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1415
            (fn ((),r) => (false,("$equal",[tm,r])))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1416
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1417
        eqP || neqP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1418
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1419
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1420
  fun maybeBinaryAtomParser mapping (s,tms) input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1421
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1422
        val tm = mkFn mapping (s,tms)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1423
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1424
        optional (binaryAtomParser mapping tm) >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1425
        (fn SOME lit => lit
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1426
          | NONE => (true,(s,tms)))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1427
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1428
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1429
  fun literalAtomParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1430
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1431
        val fnP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1432
            functionArgumentsParser mapping >>++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1433
            maybeBinaryAtomParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1434
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1435
        val nonFnP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1436
            nonFunctionArgumentsTermParser mapping >>++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1437
            binaryAtomParser 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 propP = propositionParser >> (fn s => (true,(s,[])))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1440
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1441
        fnP || nonFnP || propP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1442
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1443
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1444
  fun atomParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1445
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1446
        fun mk (pol,rel) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1447
          case rel of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1448
            ("$true",[]) => Boolean pol
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1449
          | ("$false",[]) => Boolean (not pol)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1450
          | ("$equal",[l,r]) => Literal (pol, Atom.mkEq (l,r))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1451
          | (r,tms) => Literal (pol, mkAtom mapping (r,tms))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1452
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1453
        literalAtomParser mapping >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1454
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1455
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1456
  fun literalParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1457
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1458
        val negP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1459
            (punctParser #"~" ++ atomParser mapping) >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1460
            (negateLiteral o snd)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1461
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1462
        val posP = atomParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1463
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1464
        negP || posP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1465
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1466
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1467
  fun disjunctionParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1468
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1469
        val orLitP = (punctParser #"|" ++ literalParser mapping) >> snd
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1470
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1471
        (literalParser mapping ++ many orLitP) >> (fn (h,t) => h :: t)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1472
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1473
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1474
  fun clauseParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1475
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1476
        val disjP = disjunctionParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1477
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1478
        val bracketDisjP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1479
            (punctParser #"(" ++ disjP ++ punctParser #")") >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1480
            (fn ((),(c,())) => c)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1481
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1482
        bracketDisjP || disjP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1483
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1484
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1485
  val binaryConnectiveParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1486
      (symbolParser "<=>" >> K Formula.Iff) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1487
      (symbolParser "=>" >> K Formula.Imp) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1488
      (symbolParser "<=" >> K (fn (f,g) => Formula.Imp (g,f))) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1489
      (symbolParser "<~>" >> K (Formula.Not o Formula.Iff)) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1490
      (symbolParser "~|" >> K (Formula.Not o Formula.Or)) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1491
      (symbolParser "~&" >> K (Formula.Not o Formula.And));
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1492
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1493
  val quantifierParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1494
      (punctParser #"!" >> K Formula.listMkForall) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1495
      (punctParser #"?" >> K Formula.listMkExists);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1496
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1497
  fun fofFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1498
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1499
        fun mk (f,NONE) = f
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1500
          | mk (f, SOME t) = t f
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1501
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1502
        (unitaryFormulaParser mapping ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1503
         optional (binaryFormulaParser mapping)) >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1504
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1505
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1506
  and binaryFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1507
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1508
        val nonAssocP = nonAssocBinaryFormulaParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1509
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1510
        val assocP = assocBinaryFormulaParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1511
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1512
        nonAssocP || assocP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1513
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1514
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1515
  and nonAssocBinaryFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1516
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1517
        fun mk (c,g) f = c (f,g)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1518
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1519
        (binaryConnectiveParser ++ unitaryFormulaParser mapping) >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1520
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1521
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1522
  and assocBinaryFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1523
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1524
        val orP = orFormulaParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1525
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1526
        val andP = andFormulaParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1527
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1528
        orP || andP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1529
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1530
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1531
  and orFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1532
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1533
        val orFmP = (punctParser #"|" ++ unitaryFormulaParser mapping) >> snd
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1534
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1535
        atLeastOne orFmP >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1536
        (fn fs => fn f => Formula.listMkDisj (f :: fs))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1537
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1538
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1539
  and andFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1540
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1541
        val andFmP = (punctParser #"&" ++ unitaryFormulaParser mapping) >> snd
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1542
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1543
        atLeastOne andFmP >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1544
        (fn fs => fn f => Formula.listMkConj (f :: fs))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1545
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1546
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1547
  and unitaryFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1548
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1549
        val quantP = quantifiedFormulaParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1550
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1551
        val unaryP = unaryFormulaParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1552
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1553
        val brackP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1554
            (punctParser #"(" ++ fofFormulaParser mapping ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1555
             punctParser #")") >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1556
            (fn ((),(f,())) => f)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1557
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1558
        val atomP =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1559
            atomParser mapping >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1560
            (fn Boolean b => Formula.mkBoolean b
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1561
              | Literal l => Literal.toFormula l)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1562
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1563
        quantP ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1564
        unaryP ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1565
        brackP ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1566
        atomP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1567
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1568
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1569
  and quantifiedFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1570
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1571
        fun mk (q,(vs,((),f))) = q (map (mkVarName mapping) vs, f)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1572
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1573
        (quantifierParser ++ varListParser ++ punctParser #":" ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1574
         unitaryFormulaParser mapping) >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1575
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1576
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1577
  and unaryFormulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1578
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1579
        fun mk (c,f) = c f
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1580
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1581
        (unaryConnectiveParser ++ unitaryFormulaParser mapping) >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1582
      end input
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1583
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1584
  and unaryConnectiveParser input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1585
      (punctParser #"~" >> K Formula.Not) input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1586
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1587
  fun cnfParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1588
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1589
        fun mk ((),((),(name,((),(role,((),(cl,((),())))))))) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1590
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1591
              val body = CnfFormulaBody cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1592
              val source = NoFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1593
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1594
              Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1595
                {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1596
                 role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1597
                 body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1598
                 source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1599
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1600
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1601
        (alphaNumParser "cnf" ++ punctParser #"(" ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1602
         nameParser ++ punctParser #"," ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1603
         roleParser ++ punctParser #"," ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1604
         clauseParser mapping ++ punctParser #")" ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1605
         punctParser #".") >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1606
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1607
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1608
  fun fofParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1609
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1610
        fun mk ((),((),(name,((),(role,((),(fm,((),())))))))) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1611
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1612
              val body = FofFormulaBody fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1613
              val source = NoFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1614
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1615
              Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1616
                {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1617
                 role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1618
                 body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1619
                 source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1620
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1621
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1622
        (alphaNumParser "fof" ++ punctParser #"(" ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1623
         nameParser ++ punctParser #"," ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1624
         roleParser ++ punctParser #"," ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1625
         fofFormulaParser mapping ++ punctParser #")" ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1626
         punctParser #".") >> mk
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1627
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1628
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1629
  fun formulaParser mapping input =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1630
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1631
        val cnfP = cnfParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1632
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1633
        val fofP = fofParser mapping
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1634
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1635
        cnfP || fofP
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1636
      end input;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1637
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1638
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1639
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1640
(* Include declarations.                                                     *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1641
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1642
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1643
fun ppInclude i =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1644
    Print.blockProgram Print.Inconsistent 2
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1645
      [Print.ppString "include('",
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1646
       Print.ppString i,
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1647
       Print.ppString "')."];
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1648
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1649
val includeToString = Print.toString ppInclude;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1650
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1651
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1652
  open Parse;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1653
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1654
  infixr 9 >>++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1655
  infixr 8 ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1656
  infixr 7 >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1657
  infixr 6 ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1658
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1659
  val filenameParser = maybe (fn Quote s => SOME s | _ => NONE);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1660
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1661
  val includeParser =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1662
      (some (equal (AlphaNum "include")) ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1663
       some (equal (Punct #"(")) ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1664
       filenameParser ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1665
       some (equal (Punct #")")) ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1666
       some (equal (Punct #"."))) >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1667
      (fn (_,(_,(f,(_,_)))) => f);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1668
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1669
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1670
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1671
(* Parsing TPTP files.                                                       *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1672
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1673
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1674
datatype declaration =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1675
    IncludeDeclaration of string
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1676
  | FormulaDeclaration of formula;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1677
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1678
val partitionDeclarations =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1679
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1680
      fun part (d,(il,fl)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1681
          case d of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1682
            IncludeDeclaration i => (i :: il, fl)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1683
          | FormulaDeclaration f => (il, f :: fl)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1684
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1685
      fn l => List.foldl part ([],[]) (rev l)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1686
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1687
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1688
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1689
  open Parse;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1690
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1691
  infixr 9 >>++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1692
  infixr 8 ++
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1693
  infixr 7 >>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1694
  infixr 6 ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1695
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1696
  fun declarationParser mapping =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1697
      (includeParser >> IncludeDeclaration) ||
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1698
      (formulaParser mapping >> FormulaDeclaration);
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 parseChars parser chars =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1701
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1702
        val tokens = Parse.everything (lexer >> singleton) chars
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1703
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1704
        Parse.everything (parser >> singleton) tokens
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1705
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1706
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1707
  fun parseDeclaration mapping = parseChars (declarationParser mapping);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1708
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1709
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1710
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1711
(* Clause information.                                                       *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1712
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1713
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1714
datatype clauseSource =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1715
    CnfClauseSource of formulaName * literal list
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1716
  | FofClauseSource of Normalize.thm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1717
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1718
type 'a clauseInfo = 'a LiteralSetMap.map;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1719
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1720
type clauseNames = formulaName clauseInfo;
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 clauseRoles = role clauseInfo;
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 clauseSources = clauseSource 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
val noClauseNames : clauseNames = LiteralSetMap.new ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1727
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1728
val allClauseNames : clauseNames -> formulaNameSet =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1729
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1730
      fun add (_,n,s) = addFormulaNameSet s n
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1731
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1732
      LiteralSetMap.foldl add emptyFormulaNameSet
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1733
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1734
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1735
val noClauseRoles : clauseRoles = LiteralSetMap.new ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1736
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1737
val noClauseSources : clauseSources = LiteralSetMap.new ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1738
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1739
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1740
(* Comments.                                                                 *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1741
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1742
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1743
fun mkLineComment "" = "%"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1744
  | mkLineComment line = "% " ^ line;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1745
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1746
fun destLineComment cs =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1747
    case cs of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1748
      [] => ""
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1749
    | #"%" :: #" " :: rest => String.implode rest
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
  1750
    | #"%" :: rest => String.implode rest
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1751
    | _ => raise Error "Tptp.destLineComment";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1752
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1753
val isLineComment = can destLineComment;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1754
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1755
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1756
(* TPTP problems.                                                            *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1757
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1758
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1759
type comments = string list;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1760
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1761
type includes = string list;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1762
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1763
datatype problem =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1764
    Problem of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1765
      {comments : comments,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1766
       includes : includes,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1767
       formulas : formula list};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1768
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1769
fun hasCnfConjecture (Problem {formulas,...}) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1770
    List.exists isCnfConjectureFormula formulas;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1771
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1772
fun hasFofConjecture (Problem {formulas,...}) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1773
    List.exists isFofConjectureFormula formulas;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1774
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1775
fun hasConjecture (Problem {formulas,...}) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1776
    List.exists isConjectureFormula formulas;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1777
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1778
fun freeVars (Problem {formulas,...}) = freeVarsListFormula formulas;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1779
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1780
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1781
  fun bump n avoid =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1782
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1783
        val s = FormulaName (Int.toString n)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1784
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1785
        if memberFormulaNameSet s avoid then bump (n + 1) avoid
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1786
        else (s, n, addFormulaNameSet avoid s)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1787
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1788
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1789
  fun fromClause defaultRole names roles cl (n,avoid) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1790
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1791
        val (name,n,avoid) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1792
            case LiteralSetMap.peek names cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1793
              SOME name => (name,n,avoid)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1794
            | NONE => bump n avoid
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1795
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1796
        val role = Option.getOpt (LiteralSetMap.peek roles cl, defaultRole)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1797
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1798
        val body = CnfFormulaBody (clauseFromLiteralSet cl)
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 source = NoFormulaSource
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 formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1803
            Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1804
              {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1805
               role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1806
               body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1807
               source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1808
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1809
        (formula,(n,avoid))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1810
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1811
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1812
  fun mkProblem {comments,includes,names,roles,problem} =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1813
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1814
        fun fromCl defaultRole = fromClause defaultRole names roles
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1815
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1816
        val {axioms,conjecture} = problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1817
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1818
        val n_avoid = (0, allClauseNames names)
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 (axiomFormulas,n_avoid) = maps (fromCl AxiomRole) axioms n_avoid
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 (conjectureFormulas,_) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1823
            maps (fromCl NegatedConjectureRole) conjecture n_avoid
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1824
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1825
        val formulas = axiomFormulas @ conjectureFormulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1826
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1827
        Problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1828
          {comments = comments,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1829
           includes = includes,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1830
           formulas = formulas}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1831
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1832
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1833
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1834
type normalization =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1835
     {problem : Problem.problem,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1836
      sources : clauseSources};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1837
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1838
val initialNormalization : normalization =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1839
    {problem = {axioms = [], conjecture = []},
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1840
     sources = noClauseSources};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1841
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1842
datatype problemGoal =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1843
    NoGoal
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1844
  | CnfGoal of (formulaName * clause) list
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1845
  | FofGoal of (formulaName * Formula.formula) list;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1846
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1847
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1848
  fun partitionFormula (formula,(cnfAxioms,fofAxioms,cnfGoals,fofGoals)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1849
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1850
        val Formula {name,role,body,...} = formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1851
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1852
        case body of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1853
          CnfFormulaBody cl =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1854
          if isCnfConjectureRole role then
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1855
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1856
              val cnfGoals = (name,cl) :: cnfGoals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1857
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1858
              (cnfAxioms,fofAxioms,cnfGoals,fofGoals)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1859
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1860
          else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1861
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1862
              val cnfAxioms = (name,cl) :: cnfAxioms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1863
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1864
              (cnfAxioms,fofAxioms,cnfGoals,fofGoals)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1865
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1866
        | FofFormulaBody fm =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1867
          if isFofConjectureRole role then
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1868
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1869
              val fofGoals = (name,fm) :: fofGoals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1870
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1871
              (cnfAxioms,fofAxioms,cnfGoals,fofGoals)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1872
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1873
          else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1874
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1875
              val fofAxioms = (name,fm) :: fofAxioms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1876
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1877
              (cnfAxioms,fofAxioms,cnfGoals,fofGoals)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1878
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1879
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1880
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1881
  fun partitionFormulas fms =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1882
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1883
        val (cnfAxioms,fofAxioms,cnfGoals,fofGoals) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1884
            List.foldl partitionFormula ([],[],[],[]) fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1885
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1886
        val goal =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1887
            case (rev cnfGoals, rev fofGoals) of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1888
              ([],[]) => NoGoal
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1889
            | (cnfGoals,[]) => CnfGoal cnfGoals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1890
            | ([],fofGoals) => FofGoal fofGoals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1891
            | (_ :: _, _ :: _) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1892
              raise Error "TPTP problem has both cnf and fof conjecture formulas"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1893
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1894
        {cnfAxioms = rev cnfAxioms,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1895
         fofAxioms = rev fofAxioms,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1896
         goal = goal}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1897
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1898
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1899
  fun addClauses role clauses acc : normalization =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1900
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1901
        fun addClause (cl_src,sources) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1902
            LiteralSetMap.insert sources cl_src
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1903
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1904
        val {problem,sources} : normalization = acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1905
        val {axioms,conjecture} = problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1906
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1907
        val cls = map fst clauses
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1908
        val (axioms,conjecture) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1909
            if isCnfConjectureRole role then (axioms, cls @ conjecture)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1910
            else (cls @ axioms, conjecture)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1911
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1912
        val problem = {axioms = axioms, conjecture = conjecture}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1913
        and sources = List.foldl addClause sources clauses
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1914
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1915
        {problem = problem,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1916
         sources = sources}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1917
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1918
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1919
  fun addCnf role ((name,clause),(norm,cnf)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1920
      if List.exists (equalBooleanLiteral true) clause then (norm,cnf)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1921
      else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1922
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1923
          val cl = List.mapPartial (total destLiteral) clause
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1924
          val cl = LiteralSet.fromList cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1925
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1926
          val src = CnfClauseSource (name,clause)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1927
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1928
          val norm = addClauses role [(cl,src)] norm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1929
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1930
          (norm,cnf)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1931
        end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1932
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1933
  val addCnfAxiom = addCnf AxiomRole;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1934
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1935
  val addCnfGoal = addCnf NegatedConjectureRole;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1936
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1937
  fun addFof role (th,(norm,cnf)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1938
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1939
        fun sourcify (cl,inf) = (cl, FofClauseSource inf)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1940
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1941
        val (clauses,cnf) = Normalize.addCnf th cnf
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1942
        val clauses = map sourcify clauses
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1943
        val norm = addClauses role clauses norm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1944
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1945
        (norm,cnf)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1946
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1947
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1948
  fun addFofAxiom ((_,fm),acc) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1949
      addFof AxiomRole (Normalize.mkAxiom fm, acc);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1950
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1951
  fun normProblem subgoal (norm,_) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1952
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1953
        val {problem,sources} = norm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1954
        val {axioms,conjecture} = problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1955
        val problem = {axioms = rev axioms, conjecture = rev conjecture}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1956
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1957
        {subgoal = subgoal,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1958
         problem = problem,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1959
         sources = sources}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1960
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1961
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1962
  val normProblemFalse = normProblem (Formula.False,[]);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1963
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1964
  fun splitProblem acc =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1965
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1966
        fun mk parents subgoal =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1967
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1968
              val subgoal = Formula.generalize subgoal
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1969
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1970
              val th = Normalize.mkAxiom (Formula.Not subgoal)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1971
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1972
              val acc = addFof NegatedConjectureRole (th,acc)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1973
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1974
              normProblem (subgoal,parents) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1975
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1976
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1977
        fun split (name,goal) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1978
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1979
              val subgoals = Formula.splitGoal goal
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1980
              val subgoals =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1981
                  if null subgoals then [Formula.True] else subgoals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1982
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1983
              val parents = [name]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1984
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1985
              map (mk parents) subgoals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1986
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1987
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1988
        fn goals => List.concat (map split goals)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1989
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1990
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1991
  fun clausesToGoal cls =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1992
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1993
        val cls = map (Formula.generalize o clauseToFormula o snd) cls
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1994
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1995
        Formula.listMkConj cls
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1996
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1997
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1998
  fun formulasToGoal fms =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  1999
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2000
        val fms = map (Formula.generalize o snd) fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2001
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2002
        Formula.listMkConj fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2003
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2004
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2005
  fun goal (Problem {formulas,...}) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2006
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2007
        val {cnfAxioms,fofAxioms,goal} = partitionFormulas formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2008
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2009
        val fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2010
            case goal of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2011
              NoGoal => Formula.False
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2012
            | CnfGoal cls => Formula.Imp (clausesToGoal cls, Formula.False)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2013
            | FofGoal goals => formulasToGoal goals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2014
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2015
        val fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2016
            if null fofAxioms then fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2017
            else Formula.Imp (formulasToGoal fofAxioms, fm)
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 =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2020
            if null cnfAxioms then fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2021
            else Formula.Imp (clausesToGoal cnfAxioms, fm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2022
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2023
        fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2024
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2025
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2026
  fun normalize (Problem {formulas,...}) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2027
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2028
        val {cnfAxioms,fofAxioms,goal} = partitionFormulas formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2029
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2030
        val acc = (initialNormalization, Normalize.initialCnf)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2031
        val acc = List.foldl addCnfAxiom acc cnfAxioms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2032
        val acc = List.foldl addFofAxiom acc fofAxioms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2033
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2034
        case goal of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2035
          NoGoal => [normProblemFalse acc]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2036
        | CnfGoal cls => [normProblemFalse (List.foldl addCnfGoal acc cls)]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2037
        | FofGoal goals => splitProblem acc goals
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2038
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2039
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2040
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2041
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2042
  datatype blockComment =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2043
      OutsideBlockComment
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2044
    | EnteringBlockComment
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2045
    | InsideBlockComment
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2046
    | LeavingBlockComment;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2047
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2048
  fun stripLineComments acc strm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2049
      case strm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2050
        Stream.Nil => (rev acc, Stream.Nil)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2051
      | Stream.Cons (line,rest) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2052
        case total destLineComment line of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2053
          SOME s => stripLineComments (s :: acc) (rest ())
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2054
        | NONE => (rev acc, Stream.filter (not o isLineComment) strm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2055
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2056
  fun advanceBlockComment c state =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2057
      case state of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2058
        OutsideBlockComment =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2059
        if c = #"/" then (Stream.Nil, EnteringBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2060
        else (Stream.singleton c, OutsideBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2061
      | EnteringBlockComment =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2062
        if c = #"*" then (Stream.Nil, InsideBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2063
        else if c = #"/" then (Stream.singleton #"/", EnteringBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2064
        else (Stream.fromList [#"/",c], OutsideBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2065
      | InsideBlockComment =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2066
        if c = #"*" then (Stream.Nil, LeavingBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2067
        else (Stream.Nil, InsideBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2068
      | LeavingBlockComment =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2069
        if c = #"/" then (Stream.Nil, OutsideBlockComment)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2070
        else 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
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2073
  fun eofBlockComment state =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2074
      case state of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2075
        OutsideBlockComment => Stream.Nil
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2076
      | EnteringBlockComment => Stream.singleton #"/"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2077
      | _ => raise Error "EOF inside a block comment";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2078
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2079
  val stripBlockComments =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2080
      Stream.mapsConcat advanceBlockComment eofBlockComment
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2081
        OutsideBlockComment;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2082
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2083
  fun read {mapping,filename} =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2084
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2085
        (* Estimating parse error line numbers *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2086
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2087
        val lines = Stream.fromTextFile {filename = filename}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2088
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2089
        val {chars,parseErrorLocation} = Parse.initialize {lines = lines}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2090
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2091
        (let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2092
           (* The character stream *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2093
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2094
           val (comments,chars) = stripLineComments [] chars
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2095
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2096
           val chars = Parse.everything Parse.any chars
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 chars = stripBlockComments 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
           (* The declaration stream *)
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 declarations = Stream.toList (parseDeclaration mapping 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
           val (includes,formulas) = partitionDeclarations declarations
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2105
         in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2106
           Problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2107
             {comments = comments,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2108
              includes = includes,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2109
              formulas = formulas}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2110
         end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2111
         handle Parse.NoParse => raise Error "parse error")
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2112
        handle Error err =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2113
          raise Error ("error in TPTP file \"" ^ filename ^ "\" " ^
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2114
                       parseErrorLocation () ^ "\n" ^ err)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2115
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2116
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2117
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2118
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2119
  val newline = Stream.singleton "\n";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2120
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2121
  fun spacer top = if top then Stream.Nil else newline;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2122
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2123
  fun mkComment comment = mkLineComment comment ^ "\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 mkInclude inc = includeToString inc ^ "\n";
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 formulaStream _ _ [] = Stream.Nil
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2128
    | formulaStream mapping top (h :: t) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2129
      Stream.append
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2130
        (Stream.concatList
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2131
           [spacer top,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2132
            Stream.singleton (formulaToString mapping h),
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2133
            newline])
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2134
        (fn () => formulaStream mapping false t);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2135
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2136
  fun write {problem,mapping,filename} =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2137
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2138
        val Problem {comments,includes,formulas} = problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2139
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2140
        val includesTop = null comments
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2141
        val formulasTop = includesTop andalso null includes
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2142
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2143
        Stream.toTextFile
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2144
          {filename = filename}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2145
          (Stream.concatList
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2146
             [Stream.map mkComment (Stream.fromList comments),
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2147
              spacer includesTop,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2148
              Stream.map mkInclude (Stream.fromList includes),
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2149
              formulaStream mapping formulasTop formulas])
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2150
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2151
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2152
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2153
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2154
  fun refute {axioms,conjecture} =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2155
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2156
        val axioms = map Thm.axiom axioms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2157
        and conjecture = map Thm.axiom conjecture
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2158
        val problem = {axioms = axioms, conjecture = conjecture}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2159
        val resolution = Resolution.new Resolution.default problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2160
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2161
        case Resolution.loop resolution of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2162
          Resolution.Contradiction _ => true
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2163
        | Resolution.Satisfiable _ => false
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2164
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2165
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2166
  fun prove filename =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2167
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2168
        val problem = read filename
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2169
        val problems = map #problem (normalize problem)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2170
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2171
        List.all refute problems
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2172
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2173
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2174
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2175
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2176
(* TSTP proofs.                                                              *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2177
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2178
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2179
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2180
  fun newName avoid prefix =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2181
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2182
        fun bump i =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2183
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2184
              val name = FormulaName (prefix ^ Int.toString i)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2185
              val i = i + 1
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2186
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2187
              if memberFormulaNameSet name avoid then bump i else (name,i)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2188
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2189
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2190
        bump
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2191
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2192
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2193
  fun lookupClauseSource sources cl =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2194
      case LiteralSetMap.peek sources cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2195
        SOME src => src
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2196
      | NONE => raise Bug "Tptp.lookupClauseSource";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2197
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2198
  fun lookupFormulaName fmNames fm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2199
      case FormulaMap.peek fmNames fm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2200
        SOME name => name
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2201
      | NONE => raise Bug "Tptp.lookupFormulaName";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2202
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2203
  fun lookupClauseName clNames cl =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2204
      case LiteralSetMap.peek clNames cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2205
        SOME name => name
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2206
      | NONE => raise Bug "Tptp.lookupClauseName";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2207
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2208
  fun lookupClauseSourceName sources fmNames cl =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2209
      case lookupClauseSource sources cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2210
        CnfClauseSource (name,_) => name
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2211
      | FofClauseSource th =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2212
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2213
          val (fm,_) = Normalize.destThm th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2214
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2215
          lookupFormulaName fmNames fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2216
        end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2217
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2218
  fun collectProofDeps sources ((_,inf),names_ths) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2219
      case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2220
        Proof.Axiom cl =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2221
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2222
          val (names,ths) = names_ths
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2223
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2224
          case lookupClauseSource sources cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2225
            CnfClauseSource (name,_) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2226
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2227
              val names = addFormulaNameSet names name
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2228
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2229
              (names,ths)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2230
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2231
          | FofClauseSource th =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2232
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2233
              val ths = th :: ths
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2234
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2235
              (names,ths)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2236
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2237
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2238
      | _ => names_ths;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2239
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2240
  fun collectNormalizeDeps ((_,inf,_),fofs_defs) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2241
      case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2242
        Normalize.Axiom fm =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2243
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2244
          val (fofs,defs) = fofs_defs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2245
          val fofs = FormulaSet.add fofs fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2246
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2247
          (fofs,defs)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2248
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2249
      | Normalize.Definition n_d =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2250
        let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2251
          val (fofs,defs) = fofs_defs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2252
          val defs = StringMap.insert defs n_d
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2253
        in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2254
          (fofs,defs)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2255
        end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2256
      | _ => fofs_defs;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2257
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2258
  fun collectSubgoalProofDeps subgoalProof (names,fofs,defs) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2259
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2260
        val {subgoal,sources,refutation} = subgoalProof
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2261
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2262
        val names = addListFormulaNameSet names (snd subgoal)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2263
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2264
        val proof = Proof.proof refutation
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,ths) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2267
            List.foldl (collectProofDeps sources) (names,[]) proof
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2268
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2269
        val normalization = Normalize.proveThms (rev ths)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2270
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2271
        val (fofs,defs) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2272
            List.foldl collectNormalizeDeps (fofs,defs) normalization
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2273
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2274
        val subgoalProof =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2275
            {subgoal = subgoal,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2276
             normalization = normalization,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2277
             sources = sources,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2278
             proof = proof}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2279
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2280
        (subgoalProof,(names,fofs,defs))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2281
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2282
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2283
  fun addProblemFormula names fofs (formula,(avoid,formulas,fmNames)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2284
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2285
        val name = nameFormula formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2286
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2287
        val avoid = addFormulaNameSet avoid name
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2288
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2289
        val (formulas,fmNames) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2290
            if memberFormulaNameSet name names then
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2291
              (formula :: formulas, fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2292
            else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2293
              case bodyFormula formula of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2294
                CnfFormulaBody _ => (formulas,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2295
              | FofFormulaBody fm =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2296
                if not (FormulaSet.member fm fofs) then (formulas,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2297
                else (formula :: formulas, FormulaMap.insert fmNames (fm,name))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2298
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2299
        (avoid,formulas,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2300
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2301
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2302
  fun addDefinitionFormula avoid (_,def,(formulas,i,fmNames)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2303
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2304
        val (name,i) = newName avoid "definition_" i
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2305
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2306
        val role = DefinitionRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2307
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2308
        val body = FofFormulaBody def
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 source = NoFormulaSource
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 formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2313
            Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2314
              {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2315
               role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2316
               body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2317
               source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2318
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2319
        val formulas = formula :: formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2320
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2321
        val fmNames = FormulaMap.insert fmNames (def,name)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2322
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2323
        (formulas,i,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2324
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2325
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2326
  fun addSubgoalFormula avoid subgoalProof (formulas,i) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2327
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2328
        val {subgoal,normalization,sources,proof} = subgoalProof
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2329
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2330
        val (fm,pars) = subgoal
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2331
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2332
        val (name,i) = newName avoid "subgoal_" i
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 number = i - 1
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 (subgoal,formulas) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2337
            if null pars then (NONE,formulas)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2338
            else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2339
              let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2340
                val role = PlainRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2341
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2342
                val body = FofFormulaBody fm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2343
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2344
                val source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2345
                    StripFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2346
                      {inference = "strip",
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2347
                       parents = pars}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2349
                val formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2350
                    Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2351
                      {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2352
                       role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2353
                       body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2354
                       source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2355
              in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2356
                (SOME (name,fm), formula :: formulas)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2357
              end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2358
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2359
        val subgoalProof =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2360
            {number = number,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2361
             subgoal = subgoal,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2362
             normalization = normalization,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2363
             sources = sources,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2364
             proof = proof}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2365
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2366
        (subgoalProof,(formulas,i))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2367
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2368
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2369
  fun mkNormalizeFormulaSource fmNames inference fms =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2370
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2371
        val fms =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2372
            case inference of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2373
              Normalize.Axiom fm => fm :: fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2374
            | Normalize.Definition (_,fm) => fm :: fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2375
            | _ => fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2376
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2377
        val parents = map (lookupFormulaName fmNames) fms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2378
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2379
        NormalizeFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2380
          {inference = inference,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2381
           parents = parents}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2382
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2383
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2384
  fun mkProofFormulaSource sources fmNames clNames inference =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2385
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2386
        val parents =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2387
            case inference of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2388
              Proof.Axiom cl => [lookupClauseSourceName sources fmNames cl]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2389
            | _ =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2390
              let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2391
                val cls = map Thm.clause (Proof.parents inference)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2392
              in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2393
                map (lookupClauseName clNames) cls
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2394
              end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2395
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2396
        ProofFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2397
          {inference = inference,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2398
           parents = parents}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2399
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2400
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2401
  fun addNormalizeFormula avoid prefix ((fm,inf,fms),acc) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2402
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2403
        val (formulas,i,fmNames) = acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2404
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2405
        val (name,i) = newName avoid prefix i
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2406
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2407
        val role = PlainRole
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 body = FofFormulaBody fm
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 source = mkNormalizeFormulaSource fmNames inf fms
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 formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2414
            Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2415
              {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2416
               role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2417
               body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2418
               source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2419
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2420
        val formulas = formula :: formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2421
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2422
        val fmNames = FormulaMap.insert fmNames (fm,name)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2423
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2424
        (formulas,i,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2425
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2426
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2427
  fun isSameClause sources formulas inf =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2428
      case inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2429
        Proof.Axiom cl =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2430
          (case lookupClauseSource sources cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2431
             CnfClauseSource (name,lits) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2432
             if List.exists isBooleanLiteral lits then NONE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2433
             else SOME name
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2434
           | _ => NONE)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2435
      | _ => NONE;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2436
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2437
  fun addProofFormula avoid sources fmNames prefix ((th,inf),acc) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2438
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2439
        val (formulas,i,clNames) = acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2440
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2441
        val cl = Thm.clause th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2442
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2443
        case isSameClause sources formulas inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2444
          SOME name =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2445
          let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2446
            val clNames = LiteralSetMap.insert clNames (cl,name)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2447
          in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2448
            (formulas,i,clNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2449
          end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2450
        | NONE =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2451
          let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2452
            val (name,i) = newName avoid prefix i
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2453
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2454
            val role = PlainRole
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2455
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2456
            val body = CnfFormulaBody (clauseFromLiteralSet cl)
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 source = mkProofFormulaSource sources fmNames clNames inf
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 formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2461
                Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2462
                  {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2463
                   role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2464
                   body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2465
                   source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2466
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2467
            val formulas = formula :: formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2468
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2469
            val clNames = LiteralSetMap.insert clNames (cl,name)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2470
          in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2471
            (formulas,i,clNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2472
          end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2473
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2474
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2475
  fun addSubgoalProofFormulas avoid fmNames (subgoalProof,formulas) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2476
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2477
        val {number,subgoal,normalization,sources,proof} = subgoalProof
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2478
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2479
        val (formulas,fmNames) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2480
            case subgoal of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2481
              NONE => (formulas,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2482
            | SOME (name,fm) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2483
              let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2484
                val source =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2485
                    StripFormulaSource
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2486
                      {inference = "negate",
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2487
                       parents = [name]}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2488
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2489
                val prefix = "negate_" ^ Int.toString number ^ "_"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2490
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2491
                val (name,_) = newName avoid prefix 0
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 role = PlainRole
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 fm = Formula.Not fm
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 body = FofFormulaBody fm
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 formula =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2500
                    Formula
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2501
                      {name = name,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2502
                       role = role,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2503
                       body = body,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2504
                       source = source}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2505
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2506
                val formulas = formula :: formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2507
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2508
                val fmNames = FormulaMap.insert fmNames (fm,name)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2509
              in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2510
                (formulas,fmNames)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2511
              end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2512
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2513
        val prefix = "normalize_" ^ Int.toString number ^ "_"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2514
        val (formulas,_,fmNames) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2515
            List.foldl (addNormalizeFormula avoid prefix)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2516
              (formulas,0,fmNames) normalization
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2517
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2518
        val prefix = "refute_" ^ Int.toString number ^ "_"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2519
        val clNames : formulaName LiteralSetMap.map = LiteralSetMap.new ()
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2520
        val (formulas,_,_) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2521
            List.foldl (addProofFormula avoid sources fmNames prefix)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2522
              (formulas,0,clNames) proof
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2523
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2524
        formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2525
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2526
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2527
  fun fromProof {problem,proofs} =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2528
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2529
        val names = emptyFormulaNameSet
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2530
        and fofs = FormulaSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2531
        and defs : Formula.formula StringMap.map = StringMap.new ()
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2532
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2533
        val (proofs,(names,fofs,defs)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2534
            maps collectSubgoalProofDeps proofs (names,fofs,defs)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2535
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2536
        val Problem {formulas,...} = problem
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2537
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2538
        val fmNames : formulaName FormulaMap.map = FormulaMap.new ()
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2539
        val (avoid,formulas,fmNames) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2540
            List.foldl (addProblemFormula names fofs)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2541
              (emptyFormulaNameSet,[],fmNames) formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2542
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2543
        val (formulas,_,fmNames) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2544
            StringMap.foldl (addDefinitionFormula avoid)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2545
              (formulas,0,fmNames) defs
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 (proofs,(formulas,_)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2548
            maps (addSubgoalFormula avoid) proofs (formulas,0)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2549
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2550
        val formulas =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2551
            List.foldl (addSubgoalProofFormulas avoid fmNames) formulas proofs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2552
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2553
        rev formulas
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2554
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2555
(*MetisDebug
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2556
      handle Error err => raise Bug ("Tptp.fromProof: shouldn't fail:\n" ^ err);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2557
*)
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
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
  2560
end