REDUCE

7.16 SELECT Operator

The select operator extracts from a list, or from the arguments of an n–ary operator, elements corresponding to a boolean predicate. It is used with the syntax:

select(\(\langle \)fnc:function\(\rangle \), \(\langle \)lst:list\(\rangle \))

fnc can be one of the following forms:

1.
the name of an operator with a single argument: the operator is evaluated once on each element of lst;
2.
an algebraic expression with exactly one free variable, i.e. a variable preceded by the tilde symbol. The expression is evaluated for each element of \(\langle \)lst\(\rangle \), with the element substituted for the free variable;
3.
a replacement rule of the form \(\langle \)var\(\rangle \) =>\(\langle \)rep\(\rangle \) where \(\langle \)var\(\rangle \) is a variable (a kernel without subscript) and \(\langle \)rep\(\rangle \) is an expression that contains \(\langle \)var\(\rangle \). \(\langle \)rep\(\rangle \) is evaluated for each element of LST with the element substituted for \(\langle \)var\(\rangle \). \(\langle \)var\(\rangle \) may be optionally preceded by a tilde.

The rule form for fnc is needed when more than one free variable occurs.

The result of evaluating fnc is interpreted as a boolean value corresponding to the conventions of REDUCE. These values are composed with the leading operator of the input expression.

Examples:

    select( ~w>0 , {1,-1,2,-3,3}) -> {1,2,3}
    select(evenp deg(~w,y),part((x+y)^5,0):=list)
           -> {X^5 ,10*X^3*Y^2 ,5*X*Y^4}
    select(evenp deg(~w,x),2x^2+3x^3+4x^4)
           -> 4X^4 + 2X^2


Hosted by Download REDUCE Powered by MathJax