Categorize - Maple Help

ListTools

 Categorize
 categorize the elements of a list according to a given routine

 Calling Sequence Categorize(f, L, opts, ...)

Parameters

 f - a reflexive procedure of two arguments L - list opts - (optional) options to procedure f

Description

 • The Categorize( 'f', 'L', 'opts' ) function categorizes the list L into lists $\mathrm{M1},\mathrm{M2},\dots$ 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).

Examples

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$
 > $L≔\left[\mathrm{seq}\left(1..12\right)\right]$
 ${L}{≔}\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}{,}{6}{,}{7}{,}{8}{,}{9}{,}{10}{,}{11}{,}{12}\right]$ (1)
 > $f≔\left(x,y\right)→x-y\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}4=0$
 ${f}{≔}\left({x}{,}{y}\right){↦}{x}{-}{y}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{4}{=}{0}$ (2)
 > $\mathrm{Categorize}\left(f,L\right)$
 $\left[{1}{,}{5}{,}{9}\right]{,}\left[{2}{,}{6}{,}{10}\right]{,}\left[{3}{,}{7}{,}{11}\right]{,}\left[{4}{,}{8}{,}{12}\right]$ (3)
 > $L≔\left[{x}^{2}-1,{x}^{2}+1,\left(x-1\right)\left(x+1\right),{x}^{2}-2x+1,{\left(x-1\right)}^{2}\right]$
 ${L}{≔}\left[{{x}}^{{2}}{-}{1}{,}{{x}}^{{2}}{+}{1}{,}\left({x}{-}{1}\right){}\left({x}{+}{1}\right){,}{{x}}^{{2}}{-}{2}{}{x}{+}{1}{,}{\left({x}{-}{1}\right)}^{{2}}\right]$ (4)
 > $\mathrm{Categorize}\left(\mathrm{verify},L,\mathrm{expand}\right)$
 $\left[{{x}}^{{2}}{-}{1}{,}\left({x}{-}{1}\right){}\left({x}{+}{1}\right)\right]{,}\left[{{x}}^{{2}}{+}{1}\right]{,}\left[{{x}}^{{2}}{-}{2}{}{x}{+}{1}{,}{\left({x}{-}{1}\right)}^{{2}}\right]$ (5)