
op - returns the operands of an expression

Calling sequence:

op(expr)
op(expr, position)
op(expr, [ position ...])

Parameter:
expr       --  expression
position   --  non-negative integer or range

Overloading:

1

Summary:

op returns the operands of the expression expr individually or as a sequence.

op(expr, i) returns the i-th operand of expr.  For this i must be a non-
negative integer. The zero operand op(expr, 0) takes a special role: op(expr,
0) is, for instance, the operator or function in arithmetical expressions or
function calls. For listsor setsop(expr, 0) is not defined.

op(expr, i..j) returns the i-th to j-th operands of expr as an expression sequence.
i and j must be non-negative integers, with i smaller or equal to j.  This
expression is equivalent to op(expr, k) $ k=i..j.

op(expr, [p1,p2,...,pn]) is equivalent to op(...op(op(expr,p1),p2)...pn),
if the pis are numbers.  This expression returns the pn-th operand of the
...  of the p2-th operand of the p1-th operand of expr.  With this the user
can descend on any path along the operands of an expression. Due to this

the expression [p1,p2,...,pn] is also called path expression.  Instead of
numbers, ranges can also be used in a path expression.  In this case the
relevant operands are returned as a sequence.

Finally, op(expr) returns all operands of expr except for the zero one.
op(expr) is equivalent to op(expr, 1..nops(expr)).

op has two further important special cases for rational and complex numbers.
If num is a rational number then op(num) returns the denominator and
numerator.    If num is a complex number then op(num) returns the real
and imaginary parts of the number.

If access to a specific operand is not possible, e.g. in op(expr, nops(expr)
+ 1), then this leads to an error when ERRORLEVEL  = 3. If ERRORLEVEL < 3,
FAIL is the result. In contrast to most other functions, arguments which are
expression sequences, are not flattened. op is a kernel function.

>>  op(a*b+b^d);

      a*b, b^d

>>  expr:= a+e*f+c*F(d+12):
    op(expr, [3,2]), op(expr, [3,2,1,2]);

      F(d+12), 12

>>  op(a*b+b^d, 0..1);

      _plus, a*b

>>  op(f(12,x,y), 0..2);

      f, 12, x

>>  op(a+e*f+c*(d+12), [2..3,2]);

      f, d+12

>>  ERRORLEVEL := 1: op(a+b+c, 4);

      FAIL

See also:  nops, subsop

