## Maxima – 194 – Insiemi – 3 Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.588.

`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.

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)`.

``````(%i3) divisors (a);
(%o3)                             divisors(a)
(%i4) subst (8, a, %);
(%o4)                            {1, 2, 4, 8}``````

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

``````(%i5) divisors (a = b);
(%o5)                      divisors(a) = divisors(b)
(%i6) divisors ([a, b, c]);
(%o6)               [divisors(a), divisors(b), divisors(c)]
(%i7) divisors (matrix ([a, b], [c, d]));
[ divisors(a)  divisors(b) ]
(%o7)                    [                          ]
[ divisors(c)  divisors(d) ]
(%i8) divisors ({a, b, c});
(%o8)               {divisors(a), divisors(b), divisors(c)}``````

`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.

``````(%i9) elementp (sin(1), {sin(1), sin(2), sin(3)});
(%o9)                                true
(%i10) elementp (sin(1), {cos(1), cos(2), cos(3)});
(%o10)                               false``````

`emptyp (a)`
Return `true` if and only if `a` is the empty set or the empty list.

``````(%i11) map (emptyp, [{}, []]);
(%o11)                           [true, true]
(%i12) map (emptyp, [a + b, {{}}, %pi]);
(%o12)                       [false, false, false]``````

`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.

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

``````(%i13) equiv_classes ({1, 1.0, 2, 2.0, 3, 3.0}, lambda ([x, y], is (equal (x, y))));
(%o13)                  {{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`.

``````(%i14) equiv_classes ({1, 1.0, 2, 2.0, 3, 3.0}, equal);
(%o14)                  {{1, 1.0}, {2, 2.0}, {3, 3.0}}``````

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

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

`every (f, s)`
`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 `true`.

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`.

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

``````(%i16) every (integerp, {1, 2, 3, 4, 5, 6});
(%o16)                               true
(%i17) every (atom, {1, 2, sin(3), 4, 5 + y, 6});
(%o17)                               false``````

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

``````(%i18) every ("=", [a, b, c], [a, b, c]);
(%o18)                               true
(%i19) every ("#", [a, b, c], [a, b, c]);
(%o19)                               false``````

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

``````(%i20) prederror : false;
(%o20)                               false
(%i21) map (lambda ([a, b], is (a < b)), [x, y, z],
[x^2, y^2, z^2]);
(%o21)                    [unknown, unknown, unknown]
(%i22) every ("<", [x, y, z], [x^2, y^2, z^2]);
(%o22)                              unknown
(%i23) prederror : true;
(%o23)                               true
(%i24) every ("<", [x, y, z], [x^2, y^2, z^2]);
(%o24)                               false``````

Posta un commento o usa questo indirizzo per il trackback.