﻿ length – Algosim documentation
Algosim documentation: length

# length

The length function.

## Syntax

• `length(X)`

• `X` is a string, vector, matrix, list, set, or pixmap

## Description

In general, if `X` is a container, then `length(X)` is the number of elements it contains. Depending on the type of `X`, this number is typically referred to as the “cardinality”, “dimension”, “length”, or “size” of `X`.

• If `s` is a string, then `length(s)` is the length of `s`, that is, the number of characters in `s`.

• If `v` is a vector, then `length(v)` is the dimension of `v`, that is, the number of entries, or components, of `v`.

• If `A` is a matrix, then `length(A)` is the number of entries in `A`.

• If `L` is a list, then `length(L)` is the number of elements of `L`.

• If `S` is a set, then `length(S)` is the cardinality of `S`, that is, the number of elements of `S`.

• If `pm` is a pixmap, then `length(pm)` is the number of pixels in `pm`.

## Notes

The prefix operator `#` is mapped to the `length` function.

card and cardinality are synonyms of length.

## Examples

`P ≔ filter(SequenceList(1000), IsPrime); #P`
`168`
`#functions()`
`781`
`f ≔ n ↦ if(even(n), n/2, 3⋅n + 1);`
`#orbit(f, 1000)`
`112`
`A ≔ ❨❨6, 3, 2, 0, 4, 5❩, ❨7, 0, 2, 1, 4, 2❩, ❨6, 2, 3, 1, 4, 2❩, ❨8, 0, 2, 3, 3, 5❩, ❨4, 2, 6, 3, 2, 0❩❩`
```⎛6  3  2  0  4  5⎞
⎜7  0  2  1  4  2⎟
⎜6  2  3  1  4  2⎟
⎜8  0  2  3  3  5⎟
⎝4  2  6  3  2  0⎠
```
`#A`
`30`