3 SETUP_AUTOLOAD(SETS,MAKE_UNIVERSE)$
7 /* Get a fresh UNIVERSE */
9 UNIVERSE:MAKE_UNIVERSE();
20 /* to get the elements of the universe */
23 /* to get the complement */
27 IZ:{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}$
29 /* A standard set thing to do, the set of all elements of
30 a set such that a predicate is true. */
32 PREDSET(LAMBDA([ELEM],IS(ABS(ELEM-12)<4)),IZ);
42 /* representation conversion */
46 MAPSET(LAMBDA([ELEM],ELEM^2),{1,2,3});
50 /* To each expression ever interned in a set there is a associated
51 Goedel number. (On a per-universe basis) */
58 Sets are represented as BOOLEAN arrays, (bit-vectors to the machine),
59 with element indices given by the Goedel number. Pure-set operations
60 only work on the bit-vectors, and are very fast.
63 /* An example, implementing POWERSET. This is not a useful example,
64 how many elements does the powerset of
65 {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9}
66 contain? More than can fit on any system around. */
69 ADJOIN(X,S) ::= BUILDQ([X,S], UNION({X},S) )$
72 IF EMPTYP(S) THEN {{}}
73 ELSE BLOCK([AN_ELEMENT:ELEMENTOF(S), POWER_REST],
74 POWER_REST:POWERSET(SETDIFF(S,{AN_ELEMENT})),
76 MAPSET(LAMBDA([X],ADJOIN(AN_ELEMENT,X)),
83 /* TRANSLATE before we try this on a big set. */
84 (TRANSLATE(POWERSET), /* twice for good recursion */ TRANSLATE(POWERSET))$