classify the elements of a list, set, table, or rtable using a characteristic property - Maple Help

Online Help

All Products    Maple    MapleSim


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

withListTools:

types:=Classifywhattype,Hello,1,2.,π,x,x+y,exp,world!:

mapprint,opevaltypes:

float=2.

symbol=π,exp,x

`+`=x+y

string=Hello,world!

integer=1

(1)

number_of_distinct_prime_factors:=n→nopsifactorsn2:

npf30:=Classifynumber_of_distinct_prime_factors,`$`1..30:

indicesnpf30,nolist

0,1,2,3

(2)

npf300

1

(3)

npf301

2,3,4,5,7,8,9,11,13,16,17,19,23,25,27,29

(4)

npf302

6,10,12,14,15,18,20,21,22,24,26,28

(5)

npf303

30

(6)

See Also

Array, convert/list, list, ListTools, ListTools[Categorize], Matrix, rtable, set, table, Vector


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam