src/Tools/Metis/src/Literal.sml
author blanchet
Mon, 13 Sep 2010 21:09:43 +0200
changeset 39348 6f9c9899f99f
child 39349 2d0a4361c3ef
permissions -rw-r--r--
new version of the Metis files
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
(* FIRST ORDER LOGIC LITERALS                                                *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     3
(* Copyright (c) 2001-2006 Joe Hurd, distributed under the GNU GPL version 2 *)
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 Literal :> Literal =
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
(* A type for storing first order logic literals.                            *)
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
type polarity = bool;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    16
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    17
type literal = polarity * Atom.atom;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    18
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    19
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    20
(* Constructors and destructors.                                             *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    21
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    22
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    23
fun polarity ((pol,_) : literal) = pol;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    24
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    25
fun atom ((_,atm) : literal) = atm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    26
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    27
fun name lit = Atom.name (atom lit);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    28
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    29
fun arguments lit = Atom.arguments (atom lit);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    30
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    31
fun arity lit = Atom.arity (atom lit);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    32
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    33
fun positive lit = polarity lit;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    34
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    35
fun negative lit = not (polarity lit);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    36
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    37
fun negate (pol,atm) : literal = (not pol, atm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    38
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    39
fun relation lit = Atom.relation (atom lit);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    40
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    41
fun functions lit = Atom.functions (atom lit);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    42
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    43
fun functionNames lit = Atom.functionNames (atom lit);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    44
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    45
(* Binary relations *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    46
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    47
fun mkBinop rel (pol,a,b) : literal = (pol, Atom.mkBinop rel (a,b));
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    48
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    49
fun destBinop rel ((pol,atm) : literal) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    50
    case Atom.destBinop rel atm of (a,b) => (pol,a,b);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    51
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    52
fun isBinop rel = can (destBinop rel);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    53
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    54
(* Formulas *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    55
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    56
fun toFormula (true,atm) = Formula.Atom atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    57
  | toFormula (false,atm) = Formula.Not (Formula.Atom atm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    58
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    59
fun fromFormula (Formula.Atom atm) = (true,atm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    60
  | fromFormula (Formula.Not (Formula.Atom atm)) = (false,atm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    61
  | fromFormula _ = raise Error "Literal.fromFormula";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    62
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    63
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    64
(* The size of a literal in symbols.                                         *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    65
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    66
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    67
fun symbols ((_,atm) : literal) = Atom.symbols atm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    68
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    69
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    70
(* A total comparison function for literals.                                 *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    71
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    72
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    73
val compare = prodCompare boolCompare Atom.compare;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    74
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    75
fun equal (p1,atm1) (p2,atm2) = p1 = p2 andalso Atom.equal atm1 atm2;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    76
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    77
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    78
(* Subterms.                                                                 *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    79
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    80
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    81
fun subterm lit path = Atom.subterm (atom lit) path;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    82
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    83
fun subterms lit = Atom.subterms (atom lit);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    84
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    85
fun replace (lit as (pol,atm)) path_tm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    86
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    87
      val atm' = Atom.replace atm path_tm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    88
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    89
      if Portable.pointerEqual (atm,atm') then lit else (pol,atm')
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    90
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    91
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    92
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    93
(* Free variables.                                                           *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    94
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    95
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    96
fun freeIn v lit = Atom.freeIn v (atom lit);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    97
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    98
fun freeVars lit = Atom.freeVars (atom lit);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    99
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   100
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   101
(* Substitutions.                                                            *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   102
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   103
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   104
fun subst sub (lit as (pol,atm)) : literal =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   105
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   106
      val atm' = Atom.subst sub atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   107
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   108
      if Portable.pointerEqual (atm',atm) then lit else (pol,atm')
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   109
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   110
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   111
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   112
(* Matching.                                                                 *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   113
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   114
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   115
fun match sub ((pol1,atm1) : literal) (pol2,atm2) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   116
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   117
      val _ = pol1 = pol2 orelse raise Error "Literal.match"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   118
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   119
      Atom.match sub atm1 atm2
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   120
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   121
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   122
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   123
(* Unification.                                                              *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   124
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   125
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   126
fun unify sub ((pol1,atm1) : literal) (pol2,atm2) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   127
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   128
      val _ = pol1 = pol2 orelse raise Error "Literal.unify"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   129
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   130
      Atom.unify sub atm1 atm2
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   131
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   132
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   133
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   134
(* The equality relation.                                                    *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   135
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   136
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   137
fun mkEq l_r : literal = (true, Atom.mkEq l_r);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   138
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   139
fun destEq ((true,atm) : literal) = Atom.destEq atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   140
  | destEq (false,_) = raise Error "Literal.destEq";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   141
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   142
val isEq = can destEq;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   143
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   144
fun mkNeq l_r : literal = (false, Atom.mkEq l_r);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   145
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   146
fun destNeq ((false,atm) : literal) = Atom.destEq atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   147
  | destNeq (true,_) = raise Error "Literal.destNeq";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   148
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   149
val isNeq = can destNeq;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   150
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   151
fun mkRefl tm = (true, Atom.mkRefl tm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   152
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   153
fun destRefl (true,atm) = Atom.destRefl atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   154
  | destRefl (false,_) = raise Error "Literal.destRefl";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   155
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   156
val isRefl = can destRefl;
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 mkIrrefl tm = (false, Atom.mkRefl tm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   159
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   160
fun destIrrefl (true,_) = raise Error "Literal.destIrrefl"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   161
  | destIrrefl (false,atm) = Atom.destRefl atm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   162
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   163
val isIrrefl = can destIrrefl;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   164
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   165
fun sym (pol,atm) : literal = (pol, Atom.sym atm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   166
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   167
fun lhs ((_,atm) : literal) = Atom.lhs atm;
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 rhs ((_,atm) : literal) = Atom.rhs atm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   170
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   171
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   172
(* Special support for terms with type annotations.                          *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   173
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   174
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   175
fun typedSymbols ((_,atm) : literal) = Atom.typedSymbols atm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   176
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   177
fun nonVarTypedSubterms ((_,atm) : literal) = Atom.nonVarTypedSubterms atm;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   178
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   179
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   180
(* Parsing and pretty-printing.                                              *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   181
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   182
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   183
val pp = Print.ppMap toFormula Formula.pp;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   184
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   185
val toString = Print.toString pp;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   186
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   187
fun fromString s = fromFormula (Formula.fromString s);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   188
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   189
val parse = Parse.parseQuotation Term.toString fromString;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   190
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   191
end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   192
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   193
structure LiteralOrdered =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   194
struct type t = Literal.literal val compare = Literal.compare 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
structure LiteralMap = KeyMap (LiteralOrdered);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   197
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   198
structure LiteralSet =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   199
struct
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   200
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   201
  local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   202
    structure S = ElementSet (LiteralMap);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   203
  in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   204
    open S;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   205
  end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   206
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   207
  fun negateMember lit set = member (Literal.negate lit) set;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   208
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   209
  val negate =
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
        fun f (lit,set) = add set (Literal.negate lit)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   212
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   213
        foldl f empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   214
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   215
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   216
  val relations =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   217
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   218
        fun f (lit,set) = NameAritySet.add set (Literal.relation lit)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   219
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   220
        foldl f NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   221
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   222
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   223
  val functions =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   224
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   225
        fun f (lit,set) = NameAritySet.union set (Literal.functions lit)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   226
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   227
        foldl f NameAritySet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   228
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   229
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   230
  fun freeIn v = exists (Literal.freeIn v);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   231
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   232
  val freeVars =
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
        fun f (lit,set) = NameSet.union set (Literal.freeVars lit)
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
        foldl f NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   237
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   238
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   239
  val freeVarsList =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   240
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   241
        fun f (lits,set) = NameSet.union set (freeVars lits)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   242
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   243
        List.foldl f NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   244
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   245
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   246
  val symbols =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   247
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   248
        fun f (lit,z) = Literal.symbols lit + z
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   249
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   250
        foldl f 0
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   251
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   252
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   253
  val typedSymbols =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   254
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   255
        fun f (lit,z) = Literal.typedSymbols lit + z
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   256
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   257
        foldl f 0
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   258
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   259
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   260
  fun subst sub lits =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   261
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   262
        fun substLit (lit,(eq,lits')) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   263
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   264
              val lit' = Literal.subst sub lit
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   265
              val eq = eq andalso Portable.pointerEqual (lit,lit')
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   266
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   267
              (eq, add lits' lit')
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   268
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   269
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   270
        val (eq,lits') = foldl substLit (true,empty) lits
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   271
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   272
        if eq then lits else lits'
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   273
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   274
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   275
  fun conjoin set =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   276
      Formula.listMkConj (List.map Literal.toFormula (toList set));
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 disjoin set =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   279
      Formula.listMkDisj (List.map Literal.toFormula (toList set));
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   280
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   281
  val pp =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   282
      Print.ppMap
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   283
        toList
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   284
        (Print.ppBracket "{" "}" (Print.ppOpList "," Literal.pp));
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   285
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   286
end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   287
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   288
structure LiteralSetOrdered =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   289
struct type t = LiteralSet.set val compare = LiteralSet.compare end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   290
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   291
structure LiteralSetMap = KeyMap (LiteralSetOrdered);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   292
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   293
structure LiteralSetSet = ElementSet (LiteralSetMap);