Previous Page Next Page Contents

nops -- the number of operands

Introduction

nops(object) returns the number of operands of the object.

Call(s)

nops(object)

Parameters

object - an arbitrary MuPAD object

Returns

a nonnegative integer.

Overloadable:

object

Related Functions

extnops, extop, extsubsop, length, op, subsop

Details

Example 1

The 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 2

Integers 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 3

Expression 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]

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000