-- ======================================================================== -- SET: Generic Set -- ======================================================================== -- ======================================================================== -- a comment starts with '-- ' or '** ' and ends at the end of line -- -- a convention for commenting: -- '-- ' is used before the commented CafeOBJ text -- '** ' is used after the commented CafeOBJ text -- ======================================================================== -- ======================================================================== -- generic sets mod! SET(X :: TRIV) {[Elt.X < Set] -- empty set op empty : -> Set {constr} -- assicative and commutative set constructor with identity 'empty' op __ : Set Set -> Set {constr assoc comm id: empty} -- '__' is idempotent with respect to the sort Elt eq (E:Elt E) = E . -- in pred _in_ : Elt Set . eq (E:Elt in empty) = false . eq (E1:Elt in (E2:Elt S:Set)) = ((E1 = E2) or (E1 in S)) . -- _=<_, equal of less than pred _=<_ : Set Set . eq (empty =< S:Set) = true . eq ((E1:Elt S1:Set) =< S2:Set) = (E1 in S2) and (S1 =< S2) . -- _=_ ceq (S1:Set = S2:Set) = ((S1 =< S2) and (S2 =< S1)) if not((S1 :is Elt) and (S2 :is Elt)) . -- fact about _=<_ eq (S:Set =< S) = true . ceq (S1:Set =< (E:Elt S2:Set)) = true if (S1 =< S2) . } -- ======================================================================== provide set -- ======================================================================== eof ** end of file -- test of SET -- three literals of Aid mod AID3lt { -- Aid literals [AidLt < Aid] -- an equation for literals of sort AidLt eq (B1:AidLt = B2:AidLt) = (B1 == B2) . -- arbitrary Aid literals ops b1 b2 b3 : -> AidLt . } open SET(AID3lt{sort Elt -> Aid}) . red b1 =< b2 b1 . red b1 b2 =< b2 b1 . red b1 b2 =< b2 . red b1 b2 = b1 b2 . red b2 b1 = b1 b2 . red b1 b2 b3 = b1 b2 b3 . red b2 b1 b3 = b1 b2 b3 . red `s:Set =< b1 b2 `s . red `s1:Set =< b1 b2 `s2:Set . red b1 `s:Set = b1 `s . red b1 `s:Set = b1 b2 `s . red b1 `s1:Set = b1 `s2:Set . red b1 `s:Set = b2 `s . close