Introduction to Sets
====================

Maxima provides set functions, such as intersection and union, for finite sets that are defined by explicit enumeration. Maxima treats lists and sets as distinct objects. This feature makes it possible to work with sets that have members that are either lists or sets.

In addition to functions for finite sets, Maxima provides some functions related to combinatorics; these include the Stirling numbers of the first and second kind, the Bell numbers, multinomial coefficients, partitions of nonnegative integers, and a few others. Maxima also defines a Kronecker delta function.

Usage
-----

To construct a set with members a_1, ..., a_n, write set(a_1, ..., a_n) or {a_1, ..., a_n}; to construct the empty set, write set() or {}. In input, set(...) and { ... } are equivalent. Sets are always displayed with curly braces.

If a member is listed more than once, simplification eliminates the redundant member.

     (%i1) set();
     (%o1)                          {}
     (%i2) set(a, b, a);
     (%o2)                        {a, b}
     (%i3) set(a, set(b));
     (%o3)                       {a, {b}}
     (%i4) set(a, [b]);
     (%o4)                       {a, [b]}
     (%i5) {};
     (%o5)                          {}
     (%i6) {a, b, a};
     (%o6)                        {a, b}
     (%i7) {a, {b}};
     (%o7)                       {a, {b}}
     (%i8) {a, [b]};
     (%o8)                       {a, [b]}

Two would-be elements X and Y are redundant (i.e., considered the same for the purpose of set construction) if and only if is(X = Y) yields true. Note that is(equal(X, Y)) can yield true while is(X = Y) yields false; in that case the elements X and Y are considered distinct.

     (%i1) x: a/c + b/c;
                                   b   a
     (%o1)                         - + -
                                   c   c
     (%i2) y: a/c + b/c;
                                   b   a
     (%o2)                         - + -
                                   c   c
     (%i3) z: (a + b)/c;
                                   b + a
     (%o3)                         -----
                                     c
     (%i4) is (x = y);
     (%o4)                         true
     (%i5) is (y = z);
     (%o5)                         false
     (%i6) is (equal (y, z));
     (%o6)                         true
     (%i7) y - z;
                                b + a   b   a
     (%o7)                    - ----- + - + -
                                  c     c   c
     (%i8) ratsimp (%);
     (%o8)                           0
     (%i9) {x, y, z};
                               b + a  b   a
     (%o9)                    {-----, - + -}
                                 c    c   c

To construct a set from the elements of a list, use setify.

     (%i1) setify ([b, a]);
     (%o1)                        {a, b}

Set members x and y are equal provided is(x = y) evaluates to true. Thus rat(x) and x are equal as set members; consequently,

     (%i1) {x, rat(x)};
     (%o1)                          {x}

Further, since is((x - 1)*(x + 1) = x^2 - 1) evaluates to false, (x - 1)*(x + 1) and x^2 - 1 are distinct set members; thus

     (%i1) {(x - 1)*(x + 1), x^2 - 1};
                                            2
     (%o1)               {(x - 1) (x + 1), x  - 1}

To reduce this set to a singleton set, apply rat to each set member:

     (%i1) {(x - 1)*(x + 1), x^2 - 1};
                                            2
     (%o1)               {(x - 1) (x + 1), x  - 1}
     (%i2) map (rat, %);
                                   2
     (%o2)/R/                    {x  - 1}

To remove redundancies from other sets, you may need to use other simplification functions. Here is an example that uses trigsimp:

     (%i1) {1, cos(x)^2 + sin(x)^2};
                                 2         2
     (%o1)                {1, sin (x) + cos (x)}
     (%i2) map (trigsimp, %);
     (%o2)                          {1}

A set is simplified when its members are non-redundant and sorted. The current version of the set functions uses the Maxima function orderlessp to order sets; however, future versions of the set functions might use a different ordering function.

Some operations on sets, such as substitution, automatically force a re-simplification; for example,

     (%i1) s: {a, b, c}$
     (%i2) subst (c=a, s);
     (%o2)                        {a, b}
     (%i3) subst ([a=x, b=x, c=x], s);
     (%o3)                          {x}
     (%i4) map (lambda ([x], x^2), set (-1, 0, 1));
     (%o4)                        {0, 1}

Maxima treats lists and sets as distinct objects; functions such as union and intersection complain if any argument is not a set. If you need to apply a set function to a list, use the setify function to convert it to a set. Thus

     (%i1) union ([1, 2], {a, b});
     Function union expects a set, instead found [1,2]
      -- an error.  Quitting.  To debug this try debugmode(true);
     (%i2) union (setify ([1, 2]), {a, b});
     (%o2)                     {1, 2, a, b}

To extract all set elements of a set s that satisfy a predicate f, use subset(s, f). (A predicate is a boolean-valued function.) For example, to find the equations in a given set that do not depend on a variable z, use

     (%i1) subset ({x + y + z, x - y + 4, x + y - 5},
                                         lambda ([e], freeof (z, e)));
     (%o1)               {- y + x + 4, y + x - 5}

The section Functions and Variables for Sets has a complete list of the set functions in Maxima.

Set Member Iteration
--------------------

There two ways to to iterate over set members. One way is the use map; for example:

     (%i1) map (f, {a, b, c});
     (%o1)                  {f(a), f(b), f(c)}

The other way is to use for X in S do

     (%i1) s: {a, b, c};
     (%o1)                       {a, b, c}
     (%i2) for si in s do print (concat (si, 1));
     a1
     b1
     c1
     (%o2)                         done

The Maxima functions first and rest work correctly on sets. Applied to a set, first returns the first displayed element of a set; which element that is may be implementation-dependent. If s is a set, then rest(s) is equivalent to disjoin(first(s), s). Currently, there are other Maxima functions that work correctly on sets. In future versions of the set functions, first and rest may function differently or not at all.

Bugs
----

The set functions use the Maxima function orderlessp to order set members and the (Lisp-level) function like to test for set member equality. Both of these functions have known bugs that may manifest if you attempt to use sets with members that are lists or matrices that contain expressions in canonical rational expression (CRE) form. An example is

     (%i1) {[x], [rat (x)]};
     Maxima encountered a Lisp error:

       The value #:X1440 is not of type LIST.

     Automatically continuing.
     To reenable the Lisp debugger set *debugger-hook* to nil.

This expression causes Maxima to halt with an error (the error message depends on which version of Lisp your Maxima uses). Another example is

     (%i1) setify ([[rat(a)], [rat(b)]]);
     Maxima encountered a Lisp error:

       The value #:A1440 is not of type LIST.

     Automatically continuing.
     To reenable the Lisp debugger set *debugger-hook* to nil.

These bugs are caused by bugs in orderlessp and like; they are not caused by bugs in the set functions. To illustrate, try the expressions

     (%i1) orderlessp ([rat(a)], [rat(b)]);
     Maxima encountered a Lisp error:

       The value #:B1441 is not of type LIST.

     Automatically continuing.
     To reenable the Lisp debugger set *debugger-hook* to nil.
     (%i2) is ([rat(a)] = [rat(a)]);
     (%o2)                         false

Until these bugs are fixed, do not construct sets with members that are lists or matrices containing expressions in CRE form; a set with a member in CRE form, however, shouldn't be a problem:

     (%i1) {x, rat (x)};
     (%o1)                          {x}

Maxima's orderlessp has another bug that can cause problems with set functions, namely that the ordering predicate orderlessp is not transitive. The simplest known example that shows this is

     (%i1) q: x^2$
     (%i2) r: (x + 1)^2$
     (%i3) s: x*(x + 2)$
     (%i4) orderlessp (q, r);
     (%o4)                         true
     (%i5) orderlessp (r, s);
     (%o5)                         true
     (%i6) orderlessp (q, s);
     (%o6)                         false

This bug can cause trouble with all set functions as well as with Maxima functions in general. It is probable, but not certain, that this bug can be avoided if all set members are either in CRE form or have been simplified using ratsimp.

Maxima's orderless and ordergreat mechanisms are incompatible with the set functions. If you need to use either orderless or ordergreat, call those functions before constructing any sets, and do not call unorder.

If you find something that you think might be a set function bug, please report it to the Maxima bug database. See bug_report.

Authors
-------

Stavros Macrakis of Cambridge, Massachusetts and Barton Willis of the University of Nebraska at Kearney (UNK) wrote the Maxima set functions and their documentation.

Functions and Variables for Sets
================================

 -- Function: adjoin (X, A)

     Returns the union of the set A with {X}.

     adjoin complains if A is not a literal set.

     adjoin(X, A) and union(set(X), A) are equivalent; however, adjoin may be somewhat faster than union.

     See also disjoin.

     Examples:

          (%i1) adjoin (c, {a, b});
          (%o1)                       {a, b, c}
          (%i2) adjoin (a, {a, b});
          (%o2)                        {a, b}

 -- Function: belln (N)

     Represents the n-th Bell number. belln(n) is the number of partitions of a set with N members.

     For nonnegative integers N, belln(N) simplifies to the n-th Bell number. belln does not simplify for any other arguments.

     belln distributes over equations, lists, matrices, and sets.

     Examples:

     belln applied to nonnegative integers.

          (%i1) makelist (belln (i), i, 0, 6);
          (%o1)               [1, 1, 2, 5, 15, 52, 203]
          (%i2) is (cardinality (set_partitions ({})) = belln (0));
          (%o2)                         true
          (%i3) is (cardinality (set_partitions ({1, 2, 3, 4, 5, 6})) =
                                 belln (6));
          (%o3)                         true

     belln applied to arguments which are not nonnegative integers.

          (%i1) [belln (x), belln (sqrt(3)), belln (-9)];
          (%o1)        [belln(x), belln(sqrt(3)), belln(- 9)]

 -- Function: cardinality (A)

     Returns the number of distinct elements of the set A.

     cardinality ignores redundant elements even when simplification is disabled.

     Examples:

          (%i1) cardinality ({});
          (%o1)                           0
          (%i2) cardinality ({a, a, b, c});
          (%o2)                           3
          (%i3) simp : false;
          (%o3)                         false
          (%i4) cardinality ({a, a, b, c});
          (%o4)                           3

 -- Function: cartesian_product (B_1, ... , B_N)
     Returns a set of lists of the form [X_1, ..., X_N], where X_1, ..., X_N are elements of the sets B_1, ... , B_N, respectively.

     cartesian_product complains if any argument is not a literal set.

     Examples:

          (%i1) cartesian_product ({0, 1});
          (%o1)                      {[0], [1]}
          (%i2) cartesian_product ({0, 1}, {0, 1});
          (%o2)           {[0, 0], [0, 1], [1, 0], [1, 1]}
          (%i3) cartesian_product ({x}, {y}, {z});
          (%o3)                      {[x, y, z]}
          (%i4) cartesian_product ({x}, {-1, 0, 1});
          (%o4)              {[x, - 1], [x, 0], [x, 1]}

 -- Function: disjoin (X, A)
     Returns the set A without the member X. If X is not a member of A, return A unchanged.

     disjoin complains if A is not a literal set.

     disjoin(X, A), delete(X, A), and setdifference(A, set(X)) are all equivalent. Of these, disjoin is generally faster than the others.

     Examples:

          (%i1) disjoin (a, {a, b, c, d});
          (%o1)                       {b, c, d}
          (%i2) disjoin (a + b, {5, z, a + b, %pi});
          (%o2)                      {5, %pi, z}
          (%i3) disjoin (a - b, {5, z, a + b, %pi});
          (%o3)                  {5, %pi, b + a, z}

 -- Function: disjointp (A, B)
     Returns true if and only if the sets A and B are disjoint.

     disjointp complains if either A or B is not a literal set.

     Examples:

          (%i1) disjointp ({a, b, c}, {1, 2, 3});
          (%o1)                         true
          (%i2) disjointp ({a, b, 3}, {1, 2, 3});
          (%o2)                         false

 -- Function: divisors (N)

     Represents the set of divisors of N.

     divisors(N) simplifies to a set of integers when N is a nonzero integer. The set of divisors includes the members 1 and N. The divisors of a negative integer are the divisors of its absolute value.

     divisors distributes over equations, lists, matrices, and sets.

     Examples:

     We can verify that 28 is a perfect number: the sum of its divisors (except for itself) is 28.

          (%i1) s: divisors(28);
          (%o1)                 {1, 2, 4, 7, 14, 28}
          (%i2) lreduce ("+", args(s)) - 28;
          (%o2)                          28

     divisors is a simplifying function. Substituting 8 for a in divisors(a) yields the divisors without reevaluating divisors(8).

          (%i1) divisors (a);
          (%o1)                      divisors(a)
          (%i2) subst (8, a, %);
          (%o2)                     {1, 2, 4, 8}

     divisors distributes over equations, lists, matrices, and sets.

          (%i1) divisors (a = b);
          (%o1)               divisors(a) = divisors(b)
          (%i2) divisors ([a, b, c]);
          (%o2)        [divisors(a), divisors(b), divisors(c)]
          (%i3) divisors (matrix ([a, b], [c, d]));
                            [ divisors(a)  divisors(b) ]
          (%o3)             [                          ]
                            [ divisors(c)  divisors(d) ]
          (%i4) divisors ({a, b, c});
          (%o4)        {divisors(a), divisors(b), divisors(c)}

 -- Function: elementp (X, A)
     Returns true if and only if X is a member of the set A.

     elementp complains if A is not a literal set.

     Examples:

          (%i1) elementp (sin(1), {sin(1), sin(2), sin(3)});
          (%o1)                         true
          (%i2) elementp (sin(1), {cos(1), cos(2), cos(3)});
          (%o2)                         false

 -- Function: emptyp (A)
     Return true if and only if A is the empty set or the empty list.

     Examples:

          (%i1) map (emptyp, [{}, []]);
          (%o1)                     [true, true]
          (%i2) map (emptyp, [a + b, {{}}, %pi]);
          (%o2)                 [false, false, false]

 -- Function: equiv_classes (S, F)
     Returns a set of the equivalence classes of the set S with respect to the equivalence relation F.

     F is a function of two variables defined on the Cartesian product of S with S. The return value of F is either true or false, or an expression EXPR such that is(EXPR) is either true or false.

     When F is not an equivalence relation, equiv_classes accepts it without complaint, but the result is generally incorrect in that case.

     Examples:

     The equivalence relation is a lambda expression which returns true or false.

          (%i1) equiv_classes ({1, 1.0, 2, 2.0, 3, 3.0},
                                  lambda ([x, y], is (equal (x, y))));
          (%o1)            {{1, 1.0}, {2, 2.0}, {3, 3.0}}

     The equivalence relation is the name of a relational function which is evaluates to true or false.

          (%i1) equiv_classes ({1, 1.0, 2, 2.0, 3, 3.0}, equal);
          (%o1)            {{1, 1.0}, {2, 2.0}, {3, 3.0}}

     The equivalence classes are numbers which differ by a multiple of 3.

          (%i1) equiv_classes ({1, 2, 3, 4, 5, 6, 7},
                               lambda ([x, y], remainder (x - y, 3) = 0));
          (%o1)              {{1, 4, 7}, {2, 5}, {3, 6}}

 -- Function: every (F, S)
 -- Function: every (F, L_1, ..., L_N)

     Returns true if the predicate F is true for all given arguments.

     Given one set as the second argument, every(F, S) returns true if is(F(A_I)) returns true for all A_I in S. every may or may not evaluate F for all A_I in S. Since sets are unordered, every may evaluate F(A_I) in any order.

     Given one or more lists as arguments, every(F, L_1, ..., L_N) returns true if is(F(X_1, ..., X_N)) returns true for all X_1, ..., X_N in L_1, ..., L_N, respectively. every may or may not evaluate F for every combination X_1, ..., X_N. every evaluates lists in the order of increasing index.

     Given an empty set {} or empty lists [] as arguments, every returns false.

     When the global flag maperror is true, all lists L_1, ..., L_N must have equal lengths. When maperror is false, list arguments are effectively truncated to the length of the shortest list.

     Return values of the predicate F which evaluate (via is) to something other than true or false are governed by the global flag prederror. When prederror is true, such values are treated as false, and the return value from every is false. When prederror is false, such values are treated as unknown, and the return value from every is unknown.

     Examples:

     every applied to a single set. The predicate is a function of one argument.

          (%i1) every (integerp, {1, 2, 3, 4, 5, 6});
          (%o1)                         true
          (%i2) every (atom, {1, 2, sin(3), 4, 5 + y, 6});
          (%o2)                         false

     every applied to two lists. The predicate is a function of two arguments.

          (%i1) every ("=", [a, b, c], [a, b, c]);
          (%o1)                         true
          (%i2) every ("#", [a, b, c], [a, b, c]);
          (%o2)                         false

     Return values of the predicate F which evaluate to something other than true or false are governed by the global flag prederror.

          (%i1) prederror : false;
          (%o1)                         false
          (%i2) map (lambda ([a, b], is (a < b)), [x, y, z],
                             [x^2, y^2, z^2]);
          (%o2)              [unknown, unknown, unknown]
          (%i3) every ("<", [x, y, z], [x^2, y^2, z^2]);
          (%o3)                        unknown
          (%i4) prederror : true;
          (%o4)                         true
          (%i5) every ("<", [x, y, z], [x^2, y^2, z^2]);
          (%o5)                         false

 -- Function: extremal_subset (S, F, max)
 -- Function: extremal_subset (S, F, min)

     Returns the subset of S for which the function F takes on maximum or minimum values.

     extremal_subset(S, F, max) returns the subset of the set or list S for which the real-valued function F takes on its maximum value.

     extremal_subset(S, F, min) returns the subset of the set or list S for which the real-valued function F takes on its minimum value.

     Examples:

          (%i1) extremal_subset ({-2, -1, 0, 1, 2}, abs, max);
          (%o1)                       {- 2, 2}
          (%i2) extremal_subset ({sqrt(2), 1.57, %pi/2}, sin, min);
          (%o2)                       {sqrt(2)}

 -- Function: flatten (EXPR)

     Collects arguments of subexpressions which have the same operator as EXPR and constructs an expression from these collected arguments.

     Subexpressions in which the operator is different from the main operator of expr are copied without modification, even if they, in turn, contain some subexpressions in which the operator is the same as for expr.

     It may be possible for flatten to construct expressions in which the number of arguments differs from the declared arguments for an operator; this may provoke an error message from the simplifier or evaluator. flatten does not try to detect such situations.

     Expressions with special representations, for example, canonical rational expressions (CRE), cannot be flattened; in such cases, flatten returns its argument unchanged.

     Examples:

     Applied to a list, flatten gathers all list elements that are lists.

          (%i1) flatten ([a, b, [c, [d, e], f], [[g, h]], i, j]);
          (%o1)            [a, b, c, d, e, f, g, h, i, j]

     Applied to a set, flatten gathers all members of set elements that are sets.

          (%i1) flatten ({a, {b}, {{c}}});
          (%o1)                       {a, b, c}
          (%i2) flatten ({a, {[a], {a}}});
          (%o2)                       {a, [a]}

     flatten is similar to the effect of declaring the main operator n-ary. However, flatten has no effect on subexpressions which have an operator different from the main operator, while an n-ary declaration affects those.

          (%i1) expr: flatten (f (g (f (f (x)))));
          (%o1)                     f(g(f(f(x))))
          (%i2) declare (f, nary);
          (%o2)                         done
          (%i3) ev (expr);
          (%o3)                      f(g(f(x)))

     flatten treats subscripted functions the same as any other operator.

          (%i1) flatten (f[5] (f[5] (x, y), z));
          (%o1)                      f (x, y, z)
                                      5

     It may be possible for flatten to construct expressions in which the number of arguments differs from the declared arguments for an operator;

          (%i1) 'mod (5, 'mod (7, 4));
          (%o1)                   mod(5, mod(7, 4))
          (%i2) flatten (%);
          (%o2)                     mod(5, 7, 4)
          (%i3) ''%, nouns;
          Wrong number of arguments to mod
           -- an error.  Quitting.  To debug this try debugmode(true);

 -- Function: full_listify (A)
     Replaces every set operator in A by a list operator, and returns the result. full_listify replaces set operators in nested subexpressions, even if the main operator is not set.

     listify replaces only the main operator.

     Examples:

          (%i1) full_listify ({a, b, {c, {d, e, f}, g}});
          (%o1)               [a, b, [c, [d, e, f], g]]
          (%i2) full_listify (F (G ({a, b, H({c, d, e})})));
          (%o2)              F(G([a, b, H([c, d, e])]))

 -- Function: fullsetify (A)
     When A is a list, replaces the list operator with a set operator, and applies fullsetify to each member which is a set. When A is not a list, it is returned unchanged.

     setify replaces only the main operator.

     Examples:

     In line (%o2), the argument of f isn't converted to a set because the main operator of f([b]) isn't a list.

          (%i1) fullsetify ([a, [a]]);
          (%o1)                       {a, {a}}
          (%i2) fullsetify ([a, f([b])]);
          (%o2)                      {a, f([b])}

 -- Function: identity (X)

     Returns X for any argument X.

     Examples:

     identity may be used as a predicate when the arguments are already Boolean values.

          (%i1) every (identity, [true, true]);
          (%o1)                         true

 -- Function: integer_partitions (N)
 -- Function: integer_partitions (N, LEN)

     Returns integer partitions of N, that is, lists of integers which sum to N.

     integer_partitions(N) returns the set of all partitions of the integer N. Each partition is a list sorted from greatest to least.

     integer_partitions(N, LEN) returns all partitions that have length LEN or less; in this case, zeros are appended to each partition with fewer than LEN terms to make each partition have exactly LEN terms. Each partition is a list sorted from greatest to least.

     A list [a_1, ..., a_m] is a partition of a nonnegative integer n when (1) each a_i is a nonzero integer, and (2) a_1 + ... + a_m = n. Thus 0 has no partitions.

     Examples:

          (%i1) integer_partitions (3);
          (%o1)               {[1, 1, 1], [2, 1], [3]}
          (%i2) s: integer_partitions (25)$
          (%i3) cardinality (s);
          (%o3)                         1958
          (%i4) map (lambda ([x], apply ("+", x)), s);
          (%o4)                         {25}
          (%i5) integer_partitions (5, 3);
          (%o5) {[2, 2, 1], [3, 1, 1], [3, 2, 0], [4, 1, 0], [5, 0, 0]}
          (%i6) integer_partitions (5, 2);
          (%o6)               {[3, 2], [4, 1], [5, 0]}

     To find all partitions that satisfy a condition, use the function subset; here is an example that finds all partitions of 10 that consist of prime numbers.

          (%i1) s: integer_partitions (10)$
          (%i2) cardinality (s);
          (%o2)                          42
          (%i3) xprimep(x) := integerp(x) and (x > 1) and primep(x)$
          (%i4) subset (s, lambda ([x], every (xprimep, x)));
          (%o4) {[2, 2, 2, 2, 2], [3, 3, 2, 2], [5, 3, 2], [5, 5], [7, 3]}

 -- Function: intersect (A_1, ..., A_N)

     intersect is the same as intersection, which see.

 -- Function: intersection (A_1, ..., A_N)
     Returns a set containing the elements that are common to the sets A_1 through A_N.

     intersection complains if any argument is not a literal set.

     Examples:

          (%i1) S_1 : {a, b, c, d};
          (%o1)                     {a, b, c, d}
          (%i2) S_2 : {d, e, f, g};
          (%o2)                     {d, e, f, g}
          (%i3) S_3 : {c, d, e, f};
          (%o3)                     {c, d, e, f}
          (%i4) S_4 : {u, v, w};
          (%o4)                       {u, v, w}
          (%i5) intersection (S_1, S_2);
          (%o5)                          {d}
          (%i6) intersection (S_2, S_3);
          (%o6)                       {d, e, f}
          (%i7) intersection (S_1, S_2, S_3);
          (%o7)                          {d}
          (%i8) intersection (S_1, S_2, S_3, S_4);
          (%o8)                          {}

 -- Function: kron_delta (X, Y)

     Represents the Kronecker delta function.

     kron_delta simplifies to 1 when X and Y are identical or demonstrably equivalent, and it simplifies to 0 when X and Y are demonstrably not equivalent. Otherwise, it is not certain whether X and Y are equivalent, and kron_delta simplifies to a noun expression. kron_delta implements a cautious policy with respect to floating point expressions: if the difference X - Y is a floating point number, kron_delta simplifies to a noun expression when X is apparently equivalent to Y.

     Specifically, kron_delta(X, Y) simplifies to 1 when is(x = y) is true. kron_delta also simplifies to 1 when sign(abs(X - Y)) is zero and X - Y is not a floating point number (neither an ordinary float nor a bigfloat). kron_delta simplifies to 0 when sign(abs(X - Y)) is pos.

     Otherwise, sign(abs(X - Y)) is something other than pos or zero, or it is zero and X - Y is a floating point number. In these cases, kron_delta returns a noun expression.

     kron_delta is declared to be symmetric. That is, kron_delta(X, Y) is equal to kron_delta(Y, X).

     Examples:

     The arguments of kron_delta are identical. kron_delta simplifies to 1.

          (%i1) kron_delta (a, a);
          (%o1)                           1
          (%i2) kron_delta (x^2 - y^2, x^2 - y^2);
          (%o2)                           1
          (%i3) float (kron_delta (1/10, 0.1));
          (%o3)                           1

     The arguments of kron_delta are equivalent, and their difference is not a floating point number. kron_delta simplifies to 1.

          (%i1) assume (equal (x, y));
          (%o1)                     [equal(x, y)]
          (%i2) kron_delta (x, y);
          (%o2)                           1

     The arguments of kron_delta are not equivalent. kron_delta simplifies to 0.

          (%i1) kron_delta (a + 1, a);
          (%o1)                           0
          (%i2) assume (a > b)$
          (%i3) kron_delta (a, b);
          (%o3)                           0
          (%i4) kron_delta (1/5, 0.7);
          (%o4)                           0

     The arguments of kron_delta might or might not be equivalent. kron_delta simplifies to a noun expression.

          (%i1) kron_delta (a, b);
          (%o1)                   kron_delta(a, b)
          (%i2) assume(x >= y)$
          (%i3) kron_delta (x, y);
          (%o3)                   kron_delta(x, y)

     The arguments of kron_delta are equivalent, but their difference is a floating point number. kron_delta simplifies to a noun expression.

          (%i1) 1/4 - 0.25;
          (%o1)                          0.0
          (%i2) 1/10 - 0.1;
          (%o2)                          0.0
          (%i3) 0.25 - 0.25b0;
          Warning:  Float to bigfloat conversion of 0.25
          (%o3)                         0.0b0
          (%i4) kron_delta (1/4, 0.25);
                                            1
          (%o4)                  kron_delta(-, 0.25)
                                            4
          (%i5) kron_delta (1/10, 0.1);
                                            1
          (%o5)                  kron_delta(--, 0.1)
                                            10
          (%i6) kron_delta (0.25, 0.25b0);
          Warning:  Float to bigfloat conversion of 0.25
          (%o6)               kron_delta(0.25, 2.5b-1)

     kron_delta is symmetric.

          (%i1) kron_delta (x, y);
          (%o1)                   kron_delta(x, y)
          (%i2) kron_delta (y, x);
          (%o2)                   kron_delta(x, y)
          (%i3) kron_delta (x, y) - kron_delta (y, x);
          (%o3)                           0
          (%i4) is (equal (kron_delta (x, y), kron_delta (y, x)));
          (%o4)                         true
          (%i5) is (kron_delta (x, y) = kron_delta (y, x));
          (%o5)                         true

 -- Function: listify (A)

     Returns a list containing the members of A when A is a set. Otherwise, listify returns A.

     full_listify replaces all set operators in A by list operators.

     Examples:

          (%i1) listify ({a, b, c, d});
          (%o1)                     [a, b, c, d]
          (%i2) listify (F ({a, b, c, d}));
          (%o2)                    F({a, b, c, d})

 -- Function: lreduce (F, S)
 -- Function: lreduce (F, S, S_0)

     Extends the binary function F to an n-ary function by composition, where S is a list.

     lreduce(F, S) returns F(... F(F(s_1, s_2), s_3), ... s_n). When the optional argument S_0 is present, the result is equivalent to lreduce(F, cons(S_0, S)).

     The function F is first applied to the leftmost list elements, thus the name "lreduce".

     See also rreduce, xreduce, and tree_reduce.

     Examples:

     lreduce without the optional argument.

          (%i1) lreduce (f, [1, 2, 3]);
          (%o1)                     f(f(1, 2), 3)
          (%i2) lreduce (f, [1, 2, 3, 4]);
          (%o2)                  f(f(f(1, 2), 3), 4)

     lreduce with the optional argument.

          (%i1) lreduce (f, [1, 2, 3], 4);
          (%o1)                  f(f(f(4, 1), 2), 3)

     lreduce applied to built-in binary operators. // is the division operator.

          (%i1) lreduce ("^", args ({a, b, c, d}));
                                         b c d
          (%o1)                       ((a ) )
          (%i2) lreduce ("//", args ({a, b, c, d}));
                                          a
          (%o2)                         -----
                                        b c d

 -- Function: makeset (EXPR, X, S)

     Returns a set with members generated from the expression EXPR, where X is a list of variables in EXPR, and S is a set or list of lists. To generate each set member, EXPR is evaluated with the variables X bound in parallel to a member of S.

     Each member of S must have the same length as X. The list of variables X must be a list of symbols, without subscripts. Even if there is only one symbol, X must be a list of one element, and each member of S must be a list of one element.

     See also makelist.

     Examples:

          (%i1) makeset (i/j, [i, j], [[1, a], [2, b], [3, c], [4, d]]);
                                     1  2  3  4
          (%o1)                     {-, -, -, -}
                                     a  b  c  d
          (%i2) S : {x, y, z}$
          (%i3) S3 : cartesian_product (S, S, S);
          (%o3) {[x, x, x], [x, x, y], [x, x, z], [x, y, x], [x, y, y],
          [x, y, z], [x, z, x], [x, z, y], [x, z, z], [y, x, x],
          [y, x, y], [y, x, z], [y, y, x], [y, y, y], [y, y, z],
          [y, z, x], [y, z, y], [y, z, z], [z, x, x], [z, x, y],
          [z, x, z], [z, y, x], [z, y, y], [z, y, z], [z, z, x],
          [z, z, y], [z, z, z]}
          (%i4) makeset (i + j + k, [i, j, k], S3);
          (%o4) {3 x, 3 y, y + 2 x, 2 y + x, 3 z, z + 2 x, z + y + x,
                                                 z + 2 y, 2 z + x, 2 z + y}
          (%i5) makeset (sin(x), [x], {[1], [2], [3]});
          (%o5)               {sin(1), sin(2), sin(3)}

 -- Function: moebius (N)

     Represents the Moebius function.

     When N is product of k distinct primes, moebius(N) simplifies to (-1)^k; when N = 1, it simplifies to 1; and it simplifies to 0 for all other positive integers.

     moebius distributes over equations, lists, matrices, and sets.

     Examples:

          (%i1) moebius (1);
          (%o1)                           1
          (%i2) moebius (2 * 3 * 5);
          (%o2)                          - 1
          (%i3) moebius (11 * 17 * 29 * 31);
          (%o3)                           1
          (%i4) moebius (2^32);
          (%o4)                           0
          (%i5) moebius (n);
          (%o5)                      moebius(n)
          (%i6) moebius (n = 12);
          (%o6)                    moebius(n) = 0
          (%i7) moebius ([11, 11 * 13, 11 * 13 * 15]);
          (%o7)                      [- 1, 1, 1]
          (%i8) moebius (matrix ([11, 12], [13, 14]));
                                     [ - 1  0 ]
          (%o8)                      [        ]
                                     [ - 1  1 ]
          (%i9) moebius ({21, 22, 23, 24});
          (%o9)                      {- 1, 0, 1}

 -- Function: multinomial_coeff (A_1, ..., A_N)
 -- Function: multinomial_coeff ()

     Returns the multinomial coefficient.

     When each A_K is a nonnegative integer, the multinomial coefficient gives the number of ways of placing A_1 + ... + A_N distinct objects into n boxes with A_K elements in the k'th box. In general, multinomial_coeff (A_1, ..., A_N) evaluates to (A_1 + ... + A_N)!/(A_1! ... A_N!).

     multinomial_coeff() (with no arguments) evaluates to 1.

     minfactorial may be able to simplify the value returned by multinomial_coeff.

     Examples:

          (%i1) multinomial_coeff (1, 2, x);
                                      (x + 3)!
          (%o1)                       --------
                                        2 x!
          (%i2) minfactorial (%);
                               (x + 1) (x + 2) (x + 3)
          (%o2)                -----------------------
                                          2
          (%i3) multinomial_coeff (-6, 2);
                                       (- 4)!
          (%o3)                       --------
                                      2 (- 6)!
          (%i4) minfactorial (%);
          (%o4)                          10

 -- Function: num_distinct_partitions (N)
 -- Function: num_distinct_partitions (N, list)

     Returns the number of distinct integer partitions of N when N is a nonnegative integer. Otherwise, num_distinct_partitions returns a noun expression.

     num_distinct_partitions(N, list) returns a list of the number of distinct partitions of 1, 2, 3, ..., N.

     A distinct partition of N is a list of distinct positive integers k_1, ..., k_m such that N = k_1 + ... + k_m.

     Examples:

          (%i1) num_distinct_partitions (12);
          (%o1)                          15
          (%i2) num_distinct_partitions (12, list);
          (%o2)      [1, 1, 1, 2, 2, 3, 4, 5, 6, 8, 10, 12, 15]
          (%i3) num_distinct_partitions (n);
          (%o3)              num_distinct_partitions(n)

 -- Function: num_partitions (N)
 -- Function: num_partitions (N, list)

     Returns the number of integer partitions of N when N is a nonnegative integer. Otherwise, num_partitions returns a noun expression.

     num_partitions(N, list) returns a list of the number of integer partitions of 1, 2, 3, ..., N.

     For a nonnegative integer N, num_partitions(N) is equal to cardinality(integer_partitions(N)); however, num_partitions does not actually construct the set of partitions, so it is much faster.

     Examples:

          (%i1) num_partitions (5) = cardinality (integer_partitions (5));
          (%o1)                         7 = 7
          (%i2) num_partitions (8, list);
          (%o2)            [1, 1, 2, 3, 5, 7, 11, 15, 22]
          (%i3) num_partitions (n);
          (%o3)                   num_partitions(n)

 -- Function: partition_set (A, F)

     Partitions the set A according to the predicate F.

     partition_set returns a list of two sets. The first set comprises the elements of A for which F evaluates to false, and the second comprises any other elements of A. partition_set does not apply is to the return value of F.

     partition_set complains if A is not a literal set.

     See also subset.

     Examples:

          (%i1) partition_set ({2, 7, 1, 8, 2, 8}, evenp);
          (%o1)                   [{1, 7}, {2, 8}]
          (%i2) partition_set ({x, rat(y), rat(y) + z, 1},
                               lambda ([x], ratp(x)));
          (%o2)/R/              [{1, x}, {y, y + z}]

 -- Function: permutations (A)

     Returns a set of all distinct permutations of the members of the list or set A. Each permutation is a list, not a set.

     When A is a list, duplicate members of A are included in the permutations.

     permutations complains if A is not a literal list or set.

     See also random_permutation.

     Examples:

          (%i1) permutations ([a, a]);
          (%o1)                       {[a, a]}
          (%i2) permutations ([a, a, b]);
          (%o2)           {[a, a, b], [a, b, a], [b, a, a]}

 -- Function: powerset (A)
 -- Function: powerset (A, N)

     Returns the set of all subsets of A, or a subset of that set.

     powerset(A) returns the set of all subsets of the set A. powerset(A) has 2^cardinality(A) members.

     powerset(A, N) returns the set of all subsets of A that have cardinality N.

     powerset complains if A is not a literal set, or if N is not a nonnegative integer.

     Examples:

          (%i1) powerset ({a, b, c});
          (%o1) {{}, {a}, {a, b}, {a, b, c}, {a, c}, {b}, {b, c}, {c}}
          (%i2) powerset ({w, x, y, z}, 4);
          (%o2)                    {{w, x, y, z}}
          (%i3) powerset ({w, x, y, z}, 3);
          (%o3)     {{w, x, y}, {w, x, z}, {w, y, z}, {x, y, z}}
          (%i4) powerset ({w, x, y, z}, 2);
          (%o4)   {{w, x}, {w, y}, {w, z}, {x, y}, {x, z}, {y, z}}
          (%i5) powerset ({w, x, y, z}, 1);
          (%o5)                 {{w}, {x}, {y}, {z}}
          (%i6) powerset ({w, x, y, z}, 0);
          (%o6)                         {{}}

 -- Function: random_permutation (A)

     Returns a random permutation of the set or list A, as constructed by the Knuth shuffle algorithm.

     The return value is a new list, which is distinct from the argument even if all elements happen to be the same. However, the elements of the argument are not copied.

     Examples:

          (%i1) random_permutation ([a, b, c, 1, 2, 3]);
          (%o1)                  [c, 1, 2, 3, a, b]
          (%i2) random_permutation ([a, b, c, 1, 2, 3]);
          (%o2)                  [b, 3, 1, c, a, 2]
          (%i3) random_permutation ({x + 1, y + 2, z + 3});
          (%o3)                 [y + 2, z + 3, x + 1]
          (%i4) random_permutation ({x + 1, y + 2, z + 3});
          (%o4)                 [x + 1, y + 2, z + 3]

 -- Function: rreduce (F, S)
 -- Function: rreduce (F, S, S_{N + 1})

     Extends the binary function F to an n-ary function by composition, where S is a list.

     rreduce(F, S) returns F(s_1, ... F(s_{n - 2}, F(s_{n - 1}, s_n))). When the optional argument S_{N + 1} is present, the result is equivalent to rreduce(F, endcons(S_{N + 1}, S)).

     The function F is first applied to the rightmost list elements, thus the name "rreduce".

     See also lreduce, tree_reduce, and xreduce.

     Examples:

     rreduce without the optional argument.

          (%i1) rreduce (f, [1, 2, 3]);
          (%o1)                     f(1, f(2, 3))
          (%i2) rreduce (f, [1, 2, 3, 4]);
          (%o2)                  f(1, f(2, f(3, 4)))

     rreduce with the optional argument.

          (%i1) rreduce (f, [1, 2, 3], 4);
          (%o1)                  f(1, f(2, f(3, 4)))

     rreduce applied to built-in binary operators. // is the division operator.

          (%i1) rreduce ("^", args ({a, b, c, d}));
                                           d
                                          c
                                         b
          (%o1)                         a
          (%i2) rreduce ("//", args ({a, b, c, d}));
                                         a c
          (%o2)                          ---
                                         b d

 -- Function: setdifference (A, B)

     Returns a set containing the elements in the set A that are not in the set B.

     setdifference complains if either A or B is not a literal set.

     Examples:

          (%i1) S_1 : {a, b, c, x, y, z};
          (%o1)                  {a, b, c, x, y, z}
          (%i2) S_2 : {aa, bb, c, x, y, zz};
          (%o2)                 {aa, bb, c, x, y, zz}
          (%i3) setdifference (S_1, S_2);
          (%o3)                       {a, b, z}
          (%i4) setdifference (S_2, S_1);
          (%o4)                     {aa, bb, zz}
          (%i5) setdifference (S_1, S_1);
          (%o5)                          {}
          (%i6) setdifference (S_1, {});
          (%o6)                  {a, b, c, x, y, z}
          (%i7) setdifference ({}, S_1);
          (%o7)                          {}

 -- Function: setequalp (A, B)

     Returns true if sets A and B have the same number of elements and is(X = Y) is true for x in the elements of A and y in the elements of B, considered in the order determined by listify. Otherwise, setequalp returns false.

     Examples:

          (%i1) setequalp ({1, 2, 3}, {1, 2, 3});
          (%o1)                         true
          (%i2) setequalp ({a, b, c}, {1, 2, 3});
          (%o2)                         false
          (%i3) setequalp ({x^2 - y^2}, {(x + y) * (x - y)});
          (%o3)                         false

 -- Function: setify (A)

     Constructs a set from the elements of the list A. Duplicate elements of the list A are deleted and the elements are sorted according to the predicate orderlessp.

     setify complains if A is not a literal list.

     Examples:

          (%i1) setify ([1, 2, 3, a, b, c]);
          (%o1)                  {1, 2, 3, a, b, c}
          (%i2) setify ([a, b, c, a, b, c]);
          (%o2)                       {a, b, c}
          (%i3) setify ([7, 13, 11, 1, 3, 9, 5]);
          (%o3)                {1, 3, 5, 7, 9, 11, 13}

 -- Function: setp (A)

     Returns true if and only if A is a Maxima set.

     setp returns true for unsimplified sets (that is, sets with redundant members) as well as simplified sets.

     setp is equivalent to the Maxima function setp(a) := not atom(a) and op(a) = 'set.

     Examples:

          (%i1) simp : false;
          (%o1)                         false
          (%i2) {a, a, a};
          (%o2)                       {a, a, a}
          (%i3) setp (%);
          (%o3)                         true

 -- Function: set_partitions (A)
 -- Function: set_partitions (A, N)

     Returns the set of all partitions of A, or a subset of that set.

     set_partitions(A, N) returns a set of all decompositions of A into N nonempty disjoint subsets.

     set_partitions(A) returns the set of all partitions.

     stirling2 returns the cardinality of the set of partitions of a set.

     A set of sets P is a partition of a set S when

      1. each member of P is a nonempty set,

      2. distinct members of P are disjoint,

      3. the union of the members of P equals S.

     Examples:

     The empty set is a partition of itself, the conditions 1 and 2 being vacuously true.

          (%i1) set_partitions ({});
          (%o1)                         {{}}

     The cardinality of the set of partitions of a set can be found using stirling2.

          (%i1) s: {0, 1, 2, 3, 4, 5}$
          (%i2) p: set_partitions (s, 3)$
          (%o3)                        90 = 90
          (%i4) cardinality(p) = stirling2 (6, 3);

     Each member of p should have N = 3 members; let's check.

          (%i1) s: {0, 1, 2, 3, 4, 5}$
          (%i2) p: set_partitions (s, 3)$
          (%o3)                          {3}
          (%i4) map (cardinality, p);

     Finally, for each member of p, the union of its members should equal s; again let's check.

          (%i1) s: {0, 1, 2, 3, 4, 5}$
          (%i2) p: set_partitions (s, 3)$
          (%o3)                 {{0, 1, 2, 3, 4, 5}}
          (%i4) map (lambda ([x], apply (union, listify (x))), p);

 -- Function: some (F, A)
 -- Function: some (F, L_1, ..., L_N)

     Returns true if the predicate F is true for one or more given arguments.

     Given one set as the second argument, some(F, S) returns true if is(F(A_I)) returns true for one or more A_I in S. some may or may not evaluate F for all A_I in S. Since sets are unordered, some may evaluate F(A_I) in any order.

     Given one or more lists as arguments, some(F, L_1, ..., L_N) returns true if is(F(X_1, ..., X_N)) returns true for one or more X_1, ..., X_N in L_1, ..., L_N, respectively. some may or may not evaluate F for some combinations X_1, ..., X_N. some evaluates lists in the order of increasing index.

     Given an empty set {} or empty lists [] as arguments, some returns false.

     When the global flag maperror is true, all lists L_1, ..., L_N must have equal lengths. When maperror is false, list arguments are effectively truncated to the length of the shortest list.

     Return values of the predicate F which evaluate (via is) to something other than true or false are governed by the global flag prederror. When prederror is true, such values are treated as false. When prederror is false, such values are treated as unknown.

     Examples:

     some applied to a single set. The predicate is a function of one argument.

          (%i1) some (integerp, {1, 2, 3, 4, 5, 6});
          (%o1)                         true
          (%i2) some (atom, {1, 2, sin(3), 4, 5 + y, 6});
          (%o2)                         true

     some applied to two lists. The predicate is a function of two arguments.

          (%i1) some ("=", [a, b, c], [a, b, c]);
          (%o1)                         true
          (%i2) some ("#", [a, b, c], [a, b, c]);
          (%o2)                         false

     Return values of the predicate F which evaluate to something other than true or false are governed by the global flag prederror.

          (%i1) prederror : false;
          (%o1)                         false
          (%i2) map (lambda ([a, b], is (a < b)), [x, y, z],
                     [x^2, y^2, z^2]);
          (%o2)              [unknown, unknown, unknown]
          (%i3) some ("<", [x, y, z], [x^2, y^2, z^2]);
          (%o3)                        unknown
          (%i4) some ("<", [x, y, z], [x^2, y^2, z + 1]);
          (%o4)                         true
          (%i5) prederror : true;
          (%o5)                         true
          (%i6) some ("<", [x, y, z], [x^2, y^2, z^2]);
          (%o6)                         false
          (%i7) some ("<", [x, y, z], [x^2, y^2, z + 1]);
          (%o7)                         true

 -- Function: stirling1 (N, M)

     Represents the Stirling number of the first kind.

     When N and M are nonnegative integers, the magnitude of stirling1 (N, M) is the number of permutations of a set with N members that have M cycles. For details, see Graham, Knuth and Patashnik Concrete Mathematics. Maxima uses a recursion relation to define stirling1 (N, M) for M less than 0; it is undefined for N less than 0 and for non-integer arguments.

     stirling1 is a simplifying function. Maxima knows the following identities.

      1. stirling1(0, n) = kron_delta(0, n) (Ref. [1])

      2. stirling1(n, n) = 1 (Ref. [1])

      3. stirling1(n, n - 1) = binomial(n, 2) (Ref. [1])

      4. stirling1(n + 1, 0) = 0 (Ref. [1])

      5. stirling1(n + 1, 1) = n! (Ref. [1])

      6. stirling1(n + 1, 2) = 2^n  - 1 (Ref. [1])

     These identities are applied when the arguments are literal integers or symbols declared as integers, and the first argument is nonnegative. stirling1 does not simplify for non-integer arguments.

     References:

     [1] Donald Knuth, The Art of Computer Programming, third edition, Volume 1, Section 1.2.6, Equations 48, 49, and 50.

     Examples:

          (%i1) declare (n, integer)$
          (%i2) assume (n >= 0)$
          (%i3) stirling1 (n, n);
          (%o3)                           1

     stirling1 does not simplify for non-integer arguments.

          (%i1) stirling1 (sqrt(2), sqrt(2));
          (%o1)              stirling1(sqrt(2), sqrt(2))

     Maxima applies identities to stirling1.

          (%i1) declare (n, integer)$
          (%i2) assume (n >= 0)$
          (%i3) stirling1 (n + 1, n);
                                      n (n + 1)
          (%o3)                       ---------
                                          2
          (%i4) stirling1 (n + 1, 1);
          (%o4)                          n!

 -- Function: stirling2 (N, M)

     Represents the Stirling number of the second kind.

     When N and M are nonnegative integers, stirling2 (N, M) is the number of ways a set with cardinality N can be partitioned into M disjoint subsets. Maxima uses a recursion relation to define stirling2 (N, M) for M less than 0; it is undefined for N less than 0 and for non-integer arguments.

     stirling2 is a simplifying function. Maxima knows the following identities.

      1. stirling2(0, n) = kron_delta(0, n) (Ref. [1])

      2. stirling2(n, n) = 1 (Ref. [1])

      3. stirling2(n, n - 1) = binomial(n, 2) (Ref. [1])

      4. stirling2(n + 1, 1) = 1 (Ref. [1])

      5. stirling2(n + 1, 2) = 2^n  - 1 (Ref. [1])

      6. stirling2(n, 0) = kron_delta(n, 0) (Ref. [2])

      7. stirling2(n, m) = 0 when m > n (Ref. [2])

      8. stirling2(n, m) = sum((-1)^(m - k) binomial(m k) k^n,i,1,m) / m! when m and n are integers, and n is nonnegative. (Ref. [3])

     These identities are applied when the arguments are literal integers or symbols declared as integers, and the first argument is nonnegative. stirling2 does not simplify for non-integer arguments.

     References:

     [1] Donald Knuth. The Art of Computer Programming, third edition, Volume 1, Section 1.2.6, Equations 48, 49, and 50.

     [2] Graham, Knuth, and Patashnik. Concrete Mathematics, Table 264.

     [3] Abramowitz and Stegun. Handbook of Mathematical Functions, Section 24.1.4.

     Examples:

          (%i1) declare (n, integer)$
          (%i2) assume (n >= 0)$
          (%i3) stirling2 (n, n);
          (%o3)                           1

     stirling2 does not simplify for non-integer arguments.

          (%i1) stirling2 (%pi, %pi);
          (%o1)                  stirling2(%pi, %pi)

     Maxima applies identities to stirling2.

          (%i1) declare (n, integer)$
          (%i2) assume (n >= 0)$
          (%i3) stirling2 (n + 9, n + 8);
                                   (n + 8) (n + 9)
          (%o3)                    ---------------
                                          2
          (%i4) stirling2 (n + 1, 2);
                                        n
          (%o4)                        2  - 1

 -- Function: subset (A, F)

     Returns the subset of the set A that satisfies the predicate F.

     subset returns a set which comprises the elements of A for which F returns anything other than false. subset does not apply is to the return value of F.

     subset complains if A is not a literal set.

     See also partition_set.

     Examples:

          (%i1) subset ({1, 2, x, x + y, z, x + y + z}, atom);
          (%o1)                     {1, 2, x, z}
          (%i2) subset ({1, 2, 7, 8, 9, 14}, evenp);
          (%o2)                      {2, 8, 14}

 -- Function: subsetp (A, B)

     Returns true if and only if the set A is a subset of B.

     subsetp complains if either A or B is not a literal set.

     Examples:

          (%i1) subsetp ({1, 2, 3}, {a, 1, b, 2, c, 3});
          (%o1)                         true
          (%i2) subsetp ({a, 1, b, 2, c, 3}, {1, 2, 3});
          (%o2)                         false

 -- Function: symmdifference (A_1, ..., A_N)

     Returns the symmetric difference, that is, the set of members that occur in exactly one set A_K.

     Given two arguments, symmdifference ( A, B) is the same as union ( setdifference ( A, B), setdifference(B, A)).

     symmdifference complains if any argument is not a literal set.

     Examples:

          (%i1) S_1 : {a, b, c};
          (%o1)                       {a, b, c}
          (%i2) S_2 : {1, b, c};
          (%o2)                       {1, b, c}
          (%i3) S_3 : {a, b, z};
          (%o3)                       {a, b, z}
          (%i4) symmdifference ();
          (%o4)                          {}
          (%i5) symmdifference (S_1);
          (%o5)                       {a, b, c}
          (%i6) symmdifference (S_1, S_2);
          (%o6)                        {1, a}
          (%i7) symmdifference (S_1, S_2, S_3);
          (%o7)                        {1, z}
          (%i8) symmdifference ({}, S_1, S_2, S_3);
          (%o8)                        {1, z}

 -- Function: tree_reduce (F, S)
 -- Function: tree_reduce (F, S, S_0)

     Extends the binary function F to an n-ary function by composition, where S is a set or list.

     tree_reduce is equivalent to the following: Apply F to successive pairs of elements to form a new list [F(S_1, S_2), F(S_3, S_4), ...], carrying the final element unchanged if there are an odd number of elements. Then repeat until the list is reduced to a single element, which is the return value.

     When the optional argument S_0 is present, the result is equivalent tree_reduce(F, cons(S_0, S).

     For addition of floating point numbers, tree_reduce may return a sum that has a smaller rounding error than either rreduce or lreduce.

     The elements of S and the partial results may be arranged in a minimum-depth binary tree, thus the name "tree_reduce".

     Examples:

     tree_reduce applied to a list with an even number of elements.

          (%i1) tree_reduce (f, [a, b, c, d]);
          (%o1)                  f(f(a, b), f(c, d))

     tree_reduce applied to a list with an odd number of elements.

          (%i1) tree_reduce (f, [a, b, c, d, e]);
          (%o1)               f(f(f(a, b), f(c, d)), e)

 -- Function: union (A_1, ..., A_N)
     Returns the union of the sets A_1 through A_N.

     union() (with no arguments) returns the empty set.

     union complains if any argument is not a literal set.

     Examples:

          (%i1) S_1 : {a, b, c + d, %e};
          (%o1)                   {%e, a, b, d + c}
          (%i2) S_2 : {%pi, %i, %e, c + d};
          (%o2)                 {%e, %i, %pi, d + c}
          (%i3) S_3 : {17, 29, 1729, %pi, %i};
          (%o3)                {17, 29, 1729, %i, %pi}
          (%i4) union ();
          (%o4)                          {}
          (%i5) union (S_1);
          (%o5)                   {%e, a, b, d + c}
          (%i6) union (S_1, S_2);
          (%o6)              {%e, %i, %pi, a, b, d + c}
          (%i7) union (S_1, S_2, S_3);
          (%o7)       {17, 29, 1729, %e, %i, %pi, a, b, d + c}
          (%i8) union ({}, S_1, S_2, S_3);
          (%o8)       {17, 29, 1729, %e, %i, %pi, a, b, d + c}

 -- Function: xreduce (F, S)
 -- Function: xreduce (F, S, S_0)

     Extends the function F to an n-ary function by composition, or, if F is already n-ary, applies F to S. When F is not n-ary, xreduce is the same as lreduce. The argument S is a list.

     Functions known to be n-ary include addition +, multiplication *, and, or, max, min, and append. Functions may also be declared n-ary by declare(F, nary). For these functions, xreduce is expected to be faster than either rreduce or lreduce.

     When the optional argument S_0 is present, the result is equivalent to xreduce(S, cons(S_0, S)).

     Floating point addition is not exactly associative; be that as it may, xreduce applies Maxima's n-ary addition when S contains floating point numbers.

     Examples:

     xreduce applied to a function known to be n-ary. F is called once, with all arguments.

          (%i1) declare (F, nary);
          (%o1)                         done
          (%i2) F ([L]) := L;
          (%o2)                      F([L]) := L
          (%i3) xreduce (F, [a, b, c, d, e]);
          (%o3)         [[[[[("[", simp), a], b], c], d], e]

     xreduce applied to a function not known to be n-ary. G is called several times, with two arguments each time.

          (%i1) G ([L]) := L;
          (%o1)                      G([L]) := L
          (%i2) xreduce (G, [a, b, c, d, e]);
          (%o2)         [[[[[("[", simp), a], b], c], d], e]
          (%i3) lreduce (G, [a, b, c, d, e]);
          (%o3)                 [[[[a, b], c], d], e]