nops -- the number of operands
Introductionnops(object) returns the number of
operands of the object.
Call(s)nops(object)
Parametersobject |
- | an arbitrary MuPAD object |
Returnsa nonnegative integer.
object
Related
Functionsextnops, extop, extsubsop, length, op, subsop
Detailsop
for details on MuPAD's concept of ``operands''.nops returns the number of elements or entries,
respectively. Note that expressions of type DOM_EXPR and arrays have a 0-th operand which is
not counted by nops. For arrays, also
non-initialized elements are counted by nops.null() of type DOM_NULL, the empty list [ ], the empty set { }, and the empty table table() have no operands:
nops returns 0. Cf. example 1.DOM_INT, real floating point numbers
of domain type DOM_FLOAT, Boolean constants of
domain type DOM_BOOL,
identifiers of domain type DOM_IDENT, and strings of domain
type DOM_STRING are
`atomic' objects having only 1 operand: the object itself. Rational
numbers of domain type DOM_RAT and complex numbers of
domain type DOM_COMPLEX have 2 operands: the
numerator and denominator and the real part and imaginary part,
respectively. Cf. example 2.nops
does not flatten expression sequences. Cf. example 3.nops is a function of the system kernel.
Example
1The following expression has the type "_plus" and the three operands
a*b, 3*c, and d:
>> nops(a*b + 3*c + d)
3
For sets and lists, nops returns the number
of elements. Note that the sublist [1, 2, 3] and the
subset {1, 2} each count as one operand in the following
examples:
>> nops({a, 1, [1, 2, 3], {1, 2}})
4
>> nops([[1, 2, 3], 4, 5, {1, 2}])
4
Empty objects have no operands:
>> nops(null()), nops([ ]), nops({}), nops(table())
0, 0, 0, 0
The number of operands of a symbolic function call is the number of arguments:
>> nops(f(3*x, 4, y + 2)), nops(f())
3, 0
Example
2Integers and real floating point numbers only have one operand:
>> nops(12), nops(1.41)
1, 1
The same holds true for strings; use length to query the length of a
string:
>> nops("MuPAD"), length("MuPAD")
1, 5
The number of operands of a rational number or a complex
number is 2, even if the real part is zero:
>> nops(-3/2), nops(1 + I), nops(2*I)
2, 2, 2
A function environment
has 3 and a procedure has
13 operands:
>> nops(sin), nops(op(sin, 1))
3, 13
Example
3Expression sequences are not flattened by nops:
>> nops((1, 2, 3))
3
In contrast to the previous call, the following command
calls nops with three arguments:
>> nops(1, 2, 3)
Error: Wrong number of arguments [nops]