Maxima – 193 – Insiemi – 2

sl98

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.585.

Iterazioni tra membri di set

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

(%i2) s: {a, b, c};
(%o2)                              {a, b, c}
(%i3) for si in s do print (concat (si, 1));
a1
b1
c1
(%o3)                                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.

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.

Autori

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

Funzioni e variabili

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.

(%i4) adjoin (c, {a, b});
(%o4)                              {a, b, c}
(%i5) adjoin (a, {a, b});
(%o5)                               {a, b}

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.

belln applied to nonnegative integers.

(%i6) makelist (belln (i), i, 0, 6);
(%o6)                      [1, 1, 2, 5, 15, 52, 203]
(%i7) is (cardinality (set_partitions ({})) = belln (0));
(%o7)                                true
(%i8) is (cardinality (set_partitions ({1, 2, 3, 4, 5, 6})) = belln (6));
(%o8)                                true

belln applied to arguments which are not nonnegative integers.

(%i9) [belln (x), belln (sqrt(3)), belln (-9)];
(%o9)               [belln(x), belln(sqrt(3)), belln(- 9)]

cardinality (a)
Returns the number of distinct elements of the set a.

cardinality ignores redundant elements even when simplification is disabled.

(%i10) cardinality ({});
(%o10)                                 0
(%i11) cardinality ({a, a, b, c});
(%o11)                                 3
(%i12) simp : false;
(%o12)                               false
(%i13) cardinality ({a, a, b, c});
(%o13)                                 3

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.

(%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]}

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.

(%i5) disjoin (a, {a, b, c, d});
(%o5)                              {b, c, d}
(%i6) disjoin (a + b, {5, z, a + b, %pi});
(%o6)                             {5, %pi, z}
(%i7) disjoin (a - b, {5, z, a + b, %pi});
(%o7)                         {5, %pi, b + a, z}

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.

(%i8) disjointp ({a, b, c}, {1, 2, 3});
(%o8)                                true
(%i9) disjointp ({a, b, 3}, {1, 2, 3});
(%o9)                                false

Nota per me: l’istruzione simp: false produce risultati diversi.

Posta un commento o usa questo indirizzo per il trackback.

Trackback

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.

%d blogger hanno fatto clic su Mi Piace per questo: