Fix #4352: elliptic_e(1,1.23) signals lisp error on complex number
[maxima.git] / archive / share / unknown / sets.dmo
blob498cd5a723e7b18e87738395358e7f872faa6a0d
1 /*-*-macsyma-*-*/
3 SETUP_AUTOLOAD(SETS,MAKE_UNIVERSE)$
5 KILL(LABELS)$
7 /* Get a fresh UNIVERSE */
9 UNIVERSE:MAKE_UNIVERSE();
11 X:{1,2,3,4,5,6,7};
12 Y:{2,3,4,10,20};
14 UNION(X,Y);
16 INTERSECTION(X,Y);
18 SETDIFF(Y,X);
20 /* to get the elements of the universe */
21 SETDIFF();
23 /* to get the complement */
25 SETDIFF(X);
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);
34 ELEMENTP(3,IZ);
36 Z:{2,3,4};
38 SUBSETP(X,Y);
40 SUBSETP(Z,X);
42 /* representation conversion */
44 ELEMENTS(X);
46 MAPSET(LAMBDA([ELEM],ELEM^2),{1,2,3});
48 CARDINAL({A,B,C,D});
50 /* To each expression ever interned in a set there is a associated
51    Goedel number. (On a per-universe basis) */
53 ORDINAL('A);
55 ORDINAL('FOOBAR);
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) )$
71 POWERSET(S):=
72  IF EMPTYP(S) THEN {{}}
73  ELSE BLOCK([AN_ELEMENT:ELEMENTOF(S), POWER_REST],
74             POWER_REST:POWERSET(SETDIFF(S,{AN_ELEMENT})),
75             UNION(POWER_REST,
76                   MAPSET(LAMBDA([X],ADJOIN(AN_ELEMENT,X)),
77                          POWER_REST)))$
80 POWERSET({});
81 POWERSET({A,B,C});
83 /* TRANSLATE before we try this on a big set. */
84 (TRANSLATE(POWERSET), /* twice for good recursion */ TRANSLATE(POWERSET))$
85 X8:{1,2,3,4,5,6,7,8};
87 POWERSET(X8);