ListTools - Maple Programming Help

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

ListTools

 Group
 group a list into an expression sequence of lists

 Calling Sequence Group(f, L, opts, ...) Group[N](f, opt[1], ..., opt[N-1], L, opts, ...)

Parameters

 L - list f - procedure N - positive integer opts - (optional) options to procedure f

Description

 • The Group(f, L) function groups list L into sublists where procedure f returns either true or false. The value of procedure f is determined by the expression $f\left(x\right)$ evaluated for each element x of list L.
 The Group(f, L, opts) function performs in a similar manner, except that the value of procedure f is determined by the expression $f\left(x,\mathrm{opts}\right)$.
 • If Group is indexed by a positive integer N, the expression $f\left({\mathrm{opt}}_{1},...,{\mathrm{opt}}_{N-1},x,\mathrm{opts}\right)$ is evaluated for each list element x.

Examples

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$
 > $L≔\left[\mathrm{}\left(1..10\right)\right]$
 ${L}{:=}\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}{,}{6}{,}{7}{,}{8}{,}{9}{,}{10}\right]$ (1)
 > $\mathrm{Group}\left(\mathrm{isprime},L\right)$
 $\left[{1}\right]{,}\left[{2}{,}{3}\right]{,}\left[{4}\right]{,}\left[{5}\right]{,}\left[{6}\right]{,}\left[{7}\right]{,}\left[{8}{,}{9}{,}{10}\right]$ (2)
 > $\mathrm{Group}\left(\mathrm{type},L,'\mathrm{even}'\right)$
 $\left[{1}\right]{,}\left[{2}\right]{,}\left[{3}\right]{,}\left[{4}\right]{,}\left[{5}\right]{,}\left[{6}\right]{,}\left[{7}\right]{,}\left[{8}\right]{,}\left[{9}\right]{,}\left[{10}\right]$ (3)
 > $\mathrm{Digits}≔5$
 ${\mathrm{Digits}}{:=}{5}$ (4)
 > $\mathrm{Group}\left(\mathrm{>},\left[\mathrm{seq}\left(\mathrm{sin}\left(2.0x\right),x=1..12\right)\right],-\frac{1}{2}\right)$
 $\left[{0.90930}\right]{,}\left[{-}{0.75680}\right]{,}\left[{-}{0.27942}{,}{0.98936}\right]{,}\left[{-}{0.54402}{,}{-}{0.53657}\right]{,}\left[{0.99061}{,}{-}{0.28790}\right]{,}\left[{-}{0.75099}\right]{,}\left[{0.91295}{,}{-}{0.0088513}\right]{,}\left[{-}{0.90558}\right]$ (5)
 > $\mathrm{Group}\left(\mathrm{evalb}@\mathrm{>},\left[\mathrm{seq}\left(\mathrm{sin}\left(2.0x\right),x=1..12\right)\right],-\frac{1}{2}\right)$
 $\left[{0.90930}\right]{,}\left[{-}{0.75680}\right]{,}\left[{-}{0.27942}{,}{0.98936}\right]{,}\left[{-}{0.54402}{,}{-}{0.53657}\right]{,}\left[{0.99061}{,}{-}{0.28790}\right]{,}\left[{-}{0.75099}\right]{,}\left[{0.91295}{,}{-}{0.0088513}\right]{,}\left[{-}{0.90558}\right]$ (6)
 > $\mathrm{Group}[2]\left(\mathrm{verify},-\frac{1}{2},\left[\mathrm{seq}\left(\mathrm{sin}\left(2x\right),x=1..12\right)\right],\mathrm{less_than}\right)$
 $\left[{\mathrm{sin}}{}\left({2}\right)\right]{,}\left[{\mathrm{sin}}{}\left({4}\right)\right]{,}\left[{\mathrm{sin}}{}\left({6}\right){,}{\mathrm{sin}}{}\left({8}\right)\right]{,}\left[{\mathrm{sin}}{}\left({10}\right){,}{\mathrm{sin}}{}\left({12}\right)\right]{,}\left[{\mathrm{sin}}{}\left({14}\right){,}{\mathrm{sin}}{}\left({16}\right)\right]{,}\left[{\mathrm{sin}}{}\left({18}\right)\right]{,}\left[{\mathrm{sin}}{}\left({20}\right){,}{\mathrm{sin}}{}\left({22}\right)\right]{,}\left[{\mathrm{sin}}{}\left({24}\right)\right]$ (7)