ListTools - Maple Programming Help

Home : Support : Online Help : Programming : Data Types : Tables, lists, and sets : ListTools Package : ListTools/Classify

ListTools

 Classify
 classify the elements of a list, set, table, or rtable using a characteristic property

 Calling Sequence Classify(p, L, b1, ..., bn)

Parameters

 p - characteristic property defining a class L - list, set, table, or rtable; the object containing elements to be classified b1, ..., bn - (optional) extra arguments passed to p

Description

 • The Classify(p, L, b1, ..., bn) function groups the elements of L into sets according to the characteristic property p. That is, it returns a table T with indices i such that T[i] is the set of elements e of L having value p(e, b1, ..., bn) = i.
 • If L is a table or rtable (such as an Array, Matrix, or Vector), the result is equivalent to applying this function to convert(L,list) with all other arguments the same.  (See convert/list.)
 • The call Classify(p, L, b1, ..., bn) is mostly equivalent to ListTools[Categorize]((x, y) -> p(x)=p(y), L, b1, ..., bn) but more efficient. The form of the output is also different: Categorize returns a sequence of lists, while Classify returns a table of sets. On the other hand, Categorize is more general in that it accepts two-argument relations which can not necessarily be written in the form (x, y) -> p(x)=p(y) for some property p.

Examples

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$
 > $\mathrm{types}≔\mathrm{Classify}\left(\mathrm{whattype},\left["Hello",1,2.,\mathrm{π},x,x+y,\mathrm{exp},"world!"\right]\right):$
 > $\mathrm{map}\left(\mathrm{print},\mathrm{op}\left(\mathrm{eval}\left(\mathrm{types}\right)\right)\right):$
 ${\mathrm{string}}{=}\left\{{"Hello"}{,}{"world!"}\right\}$
 ${\mathrm{float}}{=}\left\{{2.}\right\}$
 ${\mathrm{symbol}}{=}\left\{{\mathrm{π}}{,}{\mathrm{exp}}{,}{x}\right\}$
 ${\mathrm{integer}}{=}\left\{{1}\right\}$
 ${\mathrm{+}}{=}\left\{{x}{+}{y}\right\}$ (1)
 > $\mathrm{number_of_distinct_prime_factors}≔n→\mathrm{nops}\left({\mathrm{ifactors}\left(n\right)}_{2}\right):$
 > $\mathrm{npf30}≔\mathrm{Classify}\left(\mathrm{number_of_distinct_prime_factors},\left[\mathrm{}\left(1..30\right)\right]\right):$
 > $\mathrm{indices}\left(\mathrm{npf30},\mathrm{nolist}\right)$
 ${0}{,}{1}{,}{2}{,}{3}$ (2)
 > ${\mathrm{npf30}}_{0}$
 $\left\{{1}\right\}$ (3)
 > ${\mathrm{npf30}}_{1}$
 $\left\{{2}{,}{3}{,}{4}{,}{5}{,}{7}{,}{8}{,}{9}{,}{11}{,}{13}{,}{16}{,}{17}{,}{19}{,}{23}{,}{25}{,}{27}{,}{29}\right\}$ (4)
 > ${\mathrm{npf30}}_{2}$
 $\left\{{6}{,}{10}{,}{12}{,}{14}{,}{15}{,}{18}{,}{20}{,}{21}{,}{22}{,}{24}{,}{26}{,}{28}\right\}$ (5)
 > ${\mathrm{npf30}}_{3}$
 $\left\{{30}\right\}$ (6)

Compatibility

 • The ListTools[Classify] command was introduced in Maple 16.
 • For more information on Maple 16 changes, see Updates in Maple 16.