src/Tools/Metis/src/Atom.sml
author wenzelm
Sat, 07 Apr 2012 16:41:59 +0200
changeset 47389 e8552cba702d
parent 42102 fcfd07f122d4
child 72004 913162a47d9f
permissions -rw-r--r--
explicit checks stable_finished_theory/stable_command allow parallel asynchronous command transactions; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     1
(* ========================================================================= *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     2
(* FIRST ORDER LOGIC ATOMS                                                   *)
39502
cffceed8e7fa fix license
blanchet
parents: 39501
diff changeset
     3
(* Copyright (c) 2001 Joe Hurd, distributed under the BSD License            *)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     4
(* ========================================================================= *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     5
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     6
structure Atom :> Atom =
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 atoms.                               *)
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 relationName = Name.name;
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 relation = relationName * int;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    18
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    19
type atom = relationName * Term.term list;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    20
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    21
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    22
(* Constructors and destructors.                                             *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    23
(* ------------------------------------------------------------------------- *)
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 name ((rel,_) : atom) = rel;
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 arguments ((_,args) : atom) = args;
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 arity atm = length (arguments atm);
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 relation atm = (name atm, arity atm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    32
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    33
val functions =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    34
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    35
      fun f (tm,acc) = NameAritySet.union (Term.functions tm) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    36
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    37
      fn atm => List.foldl f NameAritySet.empty (arguments atm)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    38
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    39
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    40
val functionNames =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    41
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    42
      fun f (tm,acc) = NameSet.union (Term.functionNames tm) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    43
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    44
      fn atm => List.foldl f NameSet.empty (arguments atm)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    45
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    46
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    47
(* Binary relations *)
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 mkBinop p (a,b) : atom = (p,[a,b]);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    50
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    51
fun destBinop p (x,[a,b]) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    52
    if Name.equal x p then (a,b) else raise Error "Atom.destBinop: wrong binop"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    53
  | destBinop _ _ = raise Error "Atom.destBinop: not a binop";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    54
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    55
fun isBinop p = can (destBinop p);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    56
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    57
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    58
(* The size of an atom in symbols.                                           *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    59
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    60
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    61
fun symbols atm =
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    62
    List.foldl (fn (tm,z) => Term.symbols tm + z) 1 (arguments atm);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    63
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    64
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    65
(* A total comparison function for atoms.                                    *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    66
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    67
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    68
fun compare ((p1,tms1),(p2,tms2)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    69
    case Name.compare (p1,p2) of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    70
      LESS => LESS
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    71
    | EQUAL => lexCompare Term.compare (tms1,tms2)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    72
    | GREATER => GREATER;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    73
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    74
fun equal atm1 atm2 = compare (atm1,atm2) = EQUAL;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    75
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    76
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    77
(* Subterms.                                                                 *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    78
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    79
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    80
fun subterm _ [] = raise Bug "Atom.subterm: empty path"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    81
  | subterm ((_,tms) : atom) (h :: t) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    82
    if h >= length tms then raise Error "Atom.subterm: bad path"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    83
    else Term.subterm (List.nth (tms,h)) t;
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 subterms ((_,tms) : atom) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    86
    let
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
    87
      fun f ((n,tm),l) = List.map (fn (p,s) => (n :: p, s)) (Term.subterms tm) @ l
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    88
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    89
      List.foldl f [] (enumerate tms)
39348
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
fun replace _ ([],_) = raise Bug "Atom.replace: empty path"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    93
  | replace (atm as (rel,tms)) (h :: t, res) : atom =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    94
    if h >= length tms then raise Error "Atom.replace: bad path"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    95
    else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    96
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    97
        val tm = List.nth (tms,h)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    98
        val tm' = Term.replace tm (t,res)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    99
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   100
        if Portable.pointerEqual (tm,tm') then atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   101
        else (rel, updateNth (h,tm') tms)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   102
      end;
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 find pred =
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
      fun f (i,tm) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   107
          case Term.find pred tm of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   108
            SOME path => SOME (i :: path)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   109
          | NONE => NONE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   110
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   111
      fn (_,tms) : atom => first f (enumerate tms)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   112
    end;
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
(* Free variables.                                                           *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   116
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   117
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   118
fun freeIn v atm = List.exists (Term.freeIn v) (arguments atm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   119
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   120
val freeVars =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   121
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   122
      fun f (tm,acc) = NameSet.union (Term.freeVars tm) acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   123
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   124
      fn atm => List.foldl f NameSet.empty (arguments atm)
39348
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
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   127
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   128
(* Substitutions.                                                            *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   129
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   130
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   131
fun subst sub (atm as (p,tms)) : atom =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   132
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   133
      val tms' = Sharing.map (Subst.subst sub) tms
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   134
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   135
      if Portable.pointerEqual (tms',tms) then atm else (p,tms')
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   136
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   137
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   138
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   139
(* Matching.                                                                 *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   140
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   141
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   142
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   143
  fun matchArg ((tm1,tm2),sub) = Subst.match sub tm1 tm2;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   144
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   145
  fun match sub (p1,tms1) (p2,tms2) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   146
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   147
        val _ = (Name.equal p1 p2 andalso length tms1 = length tms2) orelse
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   148
                raise Error "Atom.match"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   149
      in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   150
        List.foldl matchArg sub (zip tms1 tms2)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   151
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   152
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   153
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   154
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   155
(* Unification.                                                              *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   156
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   157
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   158
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   159
  fun unifyArg ((tm1,tm2),sub) = Subst.unify sub tm1 tm2;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   160
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   161
  fun unify sub (p1,tms1) (p2,tms2) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   162
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   163
        val _ = (Name.equal p1 p2 andalso length tms1 = length tms2) orelse
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   164
                raise Error "Atom.unify"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   165
      in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   166
        List.foldl unifyArg sub (zip tms1 tms2)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   167
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   168
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   169
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   170
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   171
(* The equality relation.                                                    *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   172
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   173
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   174
val eqRelationName = Name.fromString "=";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   175
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   176
val eqRelationArity = 2;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   177
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   178
val eqRelation = (eqRelationName,eqRelationArity);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   179
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   180
val mkEq = mkBinop eqRelationName;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   181
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   182
fun destEq x = destBinop eqRelationName x;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   183
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   184
fun isEq x = isBinop eqRelationName x;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   185
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   186
fun mkRefl tm = mkEq (tm,tm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   187
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   188
fun destRefl atm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   189
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   190
      val (l,r) = destEq atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   191
      val _ = Term.equal l r orelse raise Error "Atom.destRefl"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   192
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   193
      l
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
fun isRefl x = can destRefl x;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   197
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   198
fun sym atm =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   199
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   200
      val (l,r) = destEq atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   201
      val _ = not (Term.equal l r) orelse raise Error "Atom.sym: refl"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   202
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   203
      mkEq (r,l)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   204
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   205
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   206
fun lhs atm = fst (destEq atm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   207
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   208
fun rhs atm = snd (destEq atm);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   209
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   210
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   211
(* Special support for terms with type annotations.                          *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   212
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   213
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   214
fun typedSymbols ((_,tms) : atom) =
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   215
    List.foldl (fn (tm,z) => Term.typedSymbols tm + z) 1 tms;
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   216
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   217
fun nonVarTypedSubterms (_,tms) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   218
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   219
      fun addArg ((n,arg),acc) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   220
          let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   221
            fun addTm ((path,tm),acc) = (n :: path, tm) :: acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   222
          in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   223
            List.foldl addTm acc (Term.nonVarTypedSubterms arg)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   224
          end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   225
    in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   226
      List.foldl addArg [] (enumerate tms)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   227
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   228
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   229
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   230
(* Parsing and pretty printing.                                              *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   231
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   232
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   233
val pp = Print.ppMap Term.Fn Term.pp;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   234
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   235
val toString = Print.toString pp;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   236
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   237
fun fromString s = Term.destFn (Term.fromString s);
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 parse = Parse.parseQuotation Term.toString fromString;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   240
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   241
end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   242
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   243
structure AtomOrdered =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   244
struct type t = Atom.atom val compare = Atom.compare 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
structure AtomMap = KeyMap (AtomOrdered);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   247
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   248
structure AtomSet = ElementSet (AtomMap);