REDUCE

7.15 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(U:function,V:list)

Function can be one of the following forms:

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

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

The result of evaluating function 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