PART INDEX

PART _ _ _ _ _ _ _ _ _ _ _ _ operator

The operator part permits the extraction of various parts or operators of expressions and lists.

syntax:

part(<expression,integer>{,<integer>}*)

<expression> can be any valid REDUCE expression or a list, integer may be an expression that evaluates to a positive or negative integer or 0. A positive integer <n> picks up the n th term, counting from the first term toward the end. A negative integer n picks up the n th term, counting from the back toward the front. The integer 0 picks up the operator (which is LIST when the expression is a list).

examples:


part((x + y)**5,4); 

      2  3
  10*X *Y  


part((x + y)**5,4,2); 

   2
  X  


part((x + y)**5,4,2,1); 

  X 


part((x + y)**5,0); 

  PLUS 


part((x + y)**5,-5); 

        4
  5*X *Y  


part((x + y)**5,4) := sin(x); 

   5      4         3  2                 4    5
  X  + 5*X *Y + 10*X *Y  + SIN(X) + 5*X*Y  + Y  


alist := {x,y,{aa,bb,cc},x**2*sqrt(y)}; 


                                        2
  			 ALIST := {X,Y,{AA,BB,CC},SQRT(Y)*X } 


part(alist,3,2); 

  BB 


part(alist,4,0); 

  TIMES

Additional integer arguments after the first one examine the terms recursively, as shown above. In the third line, the fourth term is picked from the original polynomial, 10x^2y^3, then the second term from that, x^2, and finally the first component, x. If an integer's absolute value is too large for the appropriate expression, a message is given.

partworks on the form of the expression as printed, or as it would have been printed at that point of the calculation, bearing in mind the current switch settings. It is important to realize that the switch settings change the operation of part. pri must be on when part is used.

When part is used on a polynomial expression that has minus signs, the + is always returned as the top-level operator. The minus is found as a unary operator attached to the negative term.

partcan also be used to change the relevant part of the expression or list as shown in the sixth example line. The part operator returns the changed expression, though original expression is not changed. You can also use part to change the operator.