## `length` -- the ``length'' of a MuPAD object (heuristic complexity)

#### Introduction

`length(`object`)` returns an integer indicating the complexity of the object.

#### Call(s)

`length(object)`

#### Parameters

`object` | - | an arbitrary MuPAD object

#### Returns

a nonnegative integer.

#### Related Functions

`nops`, `op`

#### Details

- The (heuristic) complexity of an object may be useful in algorithms that need to predict the complexity and time for manipulating objects. E.g., a symbolic Gaussian algorithm for solving linear equations prefers Pivot elements of small complexity.
- The length of an object is determined as follows:
  - Objects of domain type `DOM_BOOL`, `DOM_DOMAIN`, `DOM_EXEC`, `DOM_FAIL`, `DOM_FLOAT`, `DOM_FUNC_ENV`, `DOM_IDENT`, `DOM_NIL`, `DOM_VAR`, and `DOM_PROC_ENV` are regarded as ``atomic''. They have length 1. In particular, the length of identifiers and real floating point numbers is 1.
  - The length of an integer is the number of decimal digits.
  - The length of a string is the number of its characters.
  - The length of composite objects such as complex numbers, rational numbers, arithmetical expressions, lists, sets, arrays, tables etc. is the sum of the lengths of the operands plus 1.

- `length(``)` yields 0.

- `length` does not return the number of elements or entries in sets, lists or tables. Use `nops` instead!

- `length` is a function of the system kernel.

#### Example 1

Intuitively, the length measures the complexity of an object:

    >> length(1 + x) < length(x^3 + exp(a - b)/ln(45 - t) - 1234*I)

                                      3 < 25

#### Example 2

We compute the lengths of some simple objects:

    >> length(1.2), length(-1234.5), length(123456), length(-123456)

                                    1, 1, 6, 6

    >> length(17), length(123), length(17/123)

                                      2, 3, 6

    >> length(12), length(123), length(12 + 123*I)

                                      2, 3, 6

    >> length(x), length(x^2), length(x^12345)

                                      1, 3, 7

    >> length("123"), length("")

                                       3, 0

    >> length(x), length(a_long_name)

                                       1, 1

#### Example 3

The length of an array is the sum of the lengths of all its elements plus 1:

    >> A := array(1..2, [x, y]): length(A) = length(x) + length(y) + 1

                                       3 = 3

    >> A[1] := 12345: length(A) = length(12345) + length(y) + 1

                                       7 = 7

    >> delete A:

#### Example 4

The operands of a table are the equations associating indices and entries. The length of each operand is the length of the index plus the length of the corresponding entry plus 1:

    >> T[1] := 45: T

                                     table(
                                       1 = 45
                                     )

    >> length(T) = length(1 = 45) + 1

                                       5 = 5

    >> delete T:

#### Changes

- `length` can now be used to determine the length of strings. The corresponding function `strlen` of previous MuPAD versions has become obsolete.

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000