nops - Maple Help

op

extract operands from an expression

nops

number of operands of an expression

 Calling Sequence op(i, e) op(i..j, e) op(e) op(list, e) nops(e)

Parameters

 i, j - integers indicating positions of operands e - expression list - list of integers indicating positions of operands at increasing nesting levels of an expression

Description

 • The op function extracts operands from an expression. The nops function returns the number of operands in an expression.
 • If the first argument to the op function is a positive integer i, then the ith operand of e is returned. If the operand does not exist, an error occurs.
 • If the first argument to op is a negative integer i, then the result is $\mathrm{op}\left(\mathrm{nops}\left(e\right)+i+1,e\right)$.
 • For some data structures, op(0, e) is defined as a special case (for more information, see the particular data structure help page). For an unevaluated function call, op(0, e) is the name of the function. For an indexed name, op(0, e) is the name without the index.  For a series, op(0, e) is x-a where x is the variable and a is the expansion point of the series.  If calculating op(0, series(exp(x), x=a)), x-a returns rather than a. For all other data structures, op(0, e) returns the type of e.
 • If the values of the operand selectors are not in the range $-\mathrm{nops}\left(e\right)-1..\mathrm{nops}\left(e\right)$, an error occurs.
 • If the first argument to op is a range i..j, then the result is a sequence of the ith to jth operands of e. Negative integers in the range are treated as described above; nops(e)+1 is added to them.
 • If the op function has only one argument, this is equivalent to op(1..nops(e), e).
 • If the first argument to op is a list, then the elements of the list refer to a sub-operand of e at increasing levels of nesting. This is merely a short-form notation. The expression op([a1, a2, ..., an], e) returns the same result as op(an, op(..., op(a2, op(a1, e))...)), but is more efficient to execute.
 • When the first argument is a list, the last element of the list can be a range. As stated above, this is merely a short-form notation. The expression op([a1, a2, ..., an1..an2], e) returns the same result as op(an1..an2, op(..., op(a2, op(a1, e))...)), but is more efficient to execute.

 • The op and nops commands are thread-safe as of Maple 15.

Examples

 > $u≔\left[1,4,9\right]$
 ${u}{≔}\left[{1}{,}{4}{,}{9}\right]$ (1)
 > $\mathrm{nops}\left(u\right)$
 ${3}$ (2)
 > $\mathrm{op}\left(2,u\right)$
 ${4}$ (3)
 > $\mathrm{op}\left(2..3,u\right)$
 ${4}{,}{9}$ (4)
 > $\mathrm{op}\left(u\right)$
 ${1}{,}{4}{,}{9}$ (5)
 > $\mathrm{op}\left(-1,u\right)$
 ${9}$ (6)
 > $\mathrm{op}\left(0,u\right)$
 ${\mathrm{list}}$ (7)
 > $\left[\mathrm{op}\left(u\right),16\right]$
 $\left[{1}{,}{4}{,}{9}{,}{16}\right]$ (8)
 > $v≔f\left(x,y,z\right)$
 ${v}{≔}{f}{}\left({x}{,}{y}{,}{z}\right)$ (9)
 > $\mathrm{nops}\left(v\right)$
 ${3}$ (10)
 > $\mathrm{op}\left(0,v\right)$
 ${f}$ (11)
 > $\mathrm{op}\left(2,v\right)$
 ${y}$ (12)

If you try to refer to an operand that is not there, an error is returned

 > $\mathrm{op}\left(4,v\right)$
 > $\mathrm{op}\left(v\right)$
 ${x}{,}{y}{,}{z}$ (13)
 > $\mathrm{op}\left(-1,v\right)$
 ${z}$ (14)
 > $y≔1.2$
 ${y}{≔}{1.2}$ (15)
 > $\mathrm{op}\left(0,y\right)$
 ${\mathrm{Float}}$ (16)
 > $\mathrm{op}\left(1,y\right)$
 ${12}$ (17)
 > $\mathrm{op}\left(2,y\right)$
 ${-1}$ (18)
 > $w≔f\left(g\left(a,b\right),h\left(c,d,e,j,k,l\right)\right)$
 ${w}{≔}{f}{}\left({g}{}\left({a}{,}{b}\right){,}{h}{}\left({c}{,}{d}{,}{e}{,}{j}{,}{k}{,}{l}\right)\right)$ (19)
 > $\mathrm{op}\left(1,\mathrm{op}\left(2,w\right)\right)$
 ${c}$ (20)
 > $\mathrm{op}\left(\left[2,1\right],w\right)$
 ${c}$ (21)
 > $\mathrm{op}\left(\left[2,2..4\right],w\right)$
 ${d}{,}{e}{,}{j}$ (22)
 > $\mathrm{op}\left(\left[-1,-1\right],w\right)$
 ${l}$ (23)
 > $z≔f\left[13,15\right]$
 ${z}{≔}{{f}}_{{13}{,}{15}}$ (24)
 > $\mathrm{op}\left(0,z\right)$
 ${f}$ (25)
 > $\mathrm{nops}\left(z\right)$
 ${2}$ (26)
 > $\mathrm{op}\left(1,z\right)$
 ${13}$ (27)
 > $s≔\mathrm{series}\left(\mathrm{sin}\left(x\right),x=2,6\right)$
 ${s}{≔}{\mathrm{sin}}{}\left({2}\right){+}{\mathrm{cos}}{}\left({2}\right){}\left({x}{-}{2}\right){-}\frac{{1}}{{2}}{}{\mathrm{sin}}{}\left({2}\right){}{\left({x}{-}{2}\right)}^{{2}}{-}\frac{{1}}{{6}}{}{\mathrm{cos}}{}\left({2}\right){}{\left({x}{-}{2}\right)}^{{3}}{+}\frac{{1}}{{24}}{}{\mathrm{sin}}{}\left({2}\right){}{\left({x}{-}{2}\right)}^{{4}}{+}\frac{{1}}{{120}}{}{\mathrm{cos}}{}\left({2}\right){}{\left({x}{-}{2}\right)}^{{5}}{+}{O}{}\left({\left({x}{-}{2}\right)}^{{6}}\right)$ (28)
 > $\mathrm{op}\left(0,s\right)$
 ${x}{-}{2}$ (29)
 > $\mathrm{op}\left(1,s\right)$
 ${\mathrm{sin}}{}\left({2}\right)$ (30)
 > $g≔{x}^{3}+3{x}^{2}+5x-6$
 ${g}{≔}{{x}}^{{3}}{+}{3}{}{{x}}^{{2}}{+}{5}{}{x}{-}{6}$ (31)
 > $\mathrm{nops}\left(g\right)$
 ${4}$ (32)
 > $\mathrm{nops}\left(\mathrm{op}\left(1,g\right)\right)$
 ${2}$ (33)
 > $\mathrm{op}\left(1,\mathrm{op}\left(2,g\right)\right)$
 ${3}$ (34)

In this case, the coeff command is more efficient.

 > $\mathrm{coeff}\left(g,{x}^{2}\right)$
 ${3}$ (35)