ListTools
Categorize
categorize the elements of a list according to a given routine
Calling Sequence
Parameters
Description
Examples
Categorize(f, L, opts, ...)
f
-
a reflexive procedure of two arguments
L
list
opts
(optional) options to procedure f
The Categorize( 'f', 'L', 'opts' ) function categorizes the list L into lists M1,M2,… such that f(Mi[1], j, opts) returns true for each element j in the ith list Mi. The procedure f must return a value of type truefalse, and it must be reflexive: f(x, x, opts) must return true for each x in L.
If f defines an equivalence relation, then the result is a partition of L into equivalence classes.
If f can be written in the form (x,y) -> g(x) = g(y), then the call ListTools[Classify](g, L, opts) is more efficient, and equivalent except in the form of the output (Classify returns a table of sets).
with⁡ListTools:
L≔seq⁡1..12
L≔1,2,3,4,5,6,7,8,9,10,11,12
f≔x,y↦x−ymod4=0
Categorize⁡f,L
1,5,9,2,6,10,3,7,11,4,8,12
L≔x2−1,x2+1,x−1⁢x+1,x2−2⁢x+1,x−12
Categorize⁡verify,L,expand
x2−1,x−1⁢x+1,x2+1,x2−2⁢x+1,x−12
See Also
ListTools[Classify]
seq
type/list
type/truefalse
verify/expand
Download Help Document