select - Maple Programming Help

select

selection from an expression

remove

removal from an expression

selectremove

selection or removal from an expression

 Calling Sequence select(f, e, b1, ..., bn) select[flatten](f, e, b1, ..., bn) remove(f, e, b1, ..., bn) remove[flatten](f, e, b1, ..., bn) selectremove(f, e, b1, ..., bn) selectremove[flatten](f, e, b1, ..., bn)

Parameters

 f - Boolean-valued procedure e - any expression b1, ..., bn - (optional) extra arguments

Description

 • The select function selects the operands of the expression e which satisfy the Boolean-valued procedure f, and creates a new object of the same type as e. Those operands for which f does not return true are discarded in the newly created object.
 • When e is an ordered expression, such as a list or unevaluated function call, the operands of the output retain their relative order. If the expression e is an expression of type ^ and the result consists only of an exponent with a null base, then the output is undefined.
 • The remove function does the opposite of select. It removes the operands of e which satisfy f and creates a new object.
 • The selectremove function behaves in the same manner as select(..) and remove(..), except that the result is computed efficiently, in a single pass over expression e.
 • Additional arguments b1, ..., bn are passed to f.
 • When e is an Array, Matrix, or Vector, the select[flatten] form can be used.  This will cause the result to be flattened to a one-dimensional structure with all discarded elements removed (as opposed to having the discarded elements replaced with NULL).
 • A typical application that uses select and remove is to split the factors of a product, e, into those which depend on a variable x and those which do not (that is, constants). This can be accomplished by using  v := select(has,e,x); followed by  $c≔\mathrm{remove}\left(\mathrm{has},e,x\right)$. It is more efficient, however, to use $v,c≔\mathrm{selectremove}\left(\mathrm{has},e,x\right)$. Do not try to compute $c≔\frac{e}{v}$. Because of the way Maple simplifies expressions, factors do not cancel out in general. See the last example below.

 • The select, remove and selectremove commands are thread-safe as of Maple 15.

Examples

 > $\mathrm{integers}≔\left[\mathrm{}\left(10..20\right)\right]$
 ${\mathrm{integers}}{≔}\left[{10}{,}{11}{,}{12}{,}{13}{,}{14}{,}{15}{,}{16}{,}{17}{,}{18}{,}{19}{,}{20}\right]$ (1)
 > $\mathrm{select}\left(\mathrm{isprime},\mathrm{integers}\right)$
 $\left[{11}{,}{13}{,}{17}{,}{19}\right]$ (2)
 > $\mathrm{remove}\left(\mathrm{isprime},\mathrm{integers}\right)$
 $\left[{10}{,}{12}{,}{14}{,}{15}{,}{16}{,}{18}{,}{20}\right]$ (3)
 > $\mathrm{selectremove}\left(\mathrm{isprime},\mathrm{integers}\right)$
 $\left[{11}{,}{13}{,}{17}{,}{19}\right]{,}\left[{10}{,}{12}{,}{14}{,}{15}{,}{16}{,}{18}{,}{20}\right]$ (4)
 > $f≔2{ⅇ}^{ax}\mathrm{sin}\left(x\right)\mathrm{ln}\left(y\right)$
 ${f}{≔}{2}{}{{ⅇ}}^{{a}{}{x}}{}{\mathrm{sin}}{}\left({x}\right){}{\mathrm{ln}}{}\left({y}\right)$ (5)
 > $\mathrm{select}\left(\mathrm{has},f,x\right)$
 ${{ⅇ}}^{{a}{}{x}}{}{\mathrm{sin}}{}\left({x}\right)$ (6)
 > $\mathrm{remove}\left(\mathrm{has},f,x\right)$
 ${2}{}{\mathrm{ln}}{}\left({y}\right)$ (7)
 > $\mathrm{selectremove}\left(\mathrm{has},f,x\right)$
 ${{ⅇ}}^{{a}{}{x}}{}{\mathrm{sin}}{}\left({x}\right){,}{2}{}{\mathrm{ln}}{}\left({y}\right)$ (8)
 > $f≔{y}^{x}$
 ${f}{≔}{{y}}^{{x}}$ (9)
 > $\mathrm{selectremove}\left(\mathrm{has},f,x\right)$
 ${\mathrm{undefined}}{,}{y}$ (10)
 > $f≔\mathrm{indets}\left(f\right)$
 ${f}{≔}\left\{{x}{,}{y}{,}{{y}}^{{x}}\right\}$ (11)
 > $\mathrm{select}\left(\mathrm{type},f,'\mathrm{name}'\right)$
 $\left\{{x}{,}{y}\right\}$ (12)
 > $\mathrm{remove}\left(\mathrm{type},f,'\mathrm{name}'\right)$
 $\left\{{{y}}^{{x}}\right\}$ (13)
 > $\mathrm{selectremove}\left(\mathrm{type},f,'\mathrm{name}'\right)$
 $\left\{{x}{,}{y}\right\}{,}\left\{{{y}}^{{x}}\right\}$ (14)
 > $f≔2\mathrm{ln}\left(x\right)\left(y+1\right)$
 ${f}{≔}{2}{}{\mathrm{ln}}{}\left({x}\right){}\left({y}{+}{1}\right)$ (15)
 > $c≔\mathrm{remove}\left(\mathrm{has},f,x\right)$
 ${c}{≔}{2}{}{y}{+}{2}$ (16)
 > $\frac{f}{c}$
 $\frac{{2}{}{\mathrm{ln}}{}\left({x}\right){}\left({y}{+}{1}\right)}{{2}{}{y}{+}{2}}$ (17)
 > $\mathrm{select}\left(\mathrm{has},f,x\right)$
 ${\mathrm{ln}}{}\left({x}\right)$ (18)
 > $\mathrm{remove}\left(x→2
 $\left[\begin{array}{c}{1}\\ {2}\\ {\mathrm{NULL}}\end{array}\right]$ (19)
 > $\mathrm{remove}[\mathrm{flatten}]\left(x→2
 $\left[\begin{array}{r}{1}\\ {2}\end{array}\right]$ (20)

The following example selects any entries of a matrix matching a certain criteria, showing NULL for any entries that do not match. To see an example of removing any rows or columns that do not match a given criteria, see the Working with Subsections of Data - Extracting Data section in the LA_syntax_shortcuts page.

 > $\mathrm{select}\left(x→2
 $\left[\begin{array}{cc}{\mathrm{NULL}}& {\mathrm{NULL}}\\ {3}& {4}\end{array}\right]$ (21)
 > $\mathrm{select}[\mathrm{flatten}]\left(x→2
 $\left[\begin{array}{cc}{3}& {4}\end{array}\right]$ (22)

Compatibility

 • The flatten option was introduced in Maple 17.
 • For more information on Maple 17 changes, see Updates in Maple 17.