length
The length function.
Syntax
-
length(X)-
Xis 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
sis a string, thenlength(s)is the length ofs, that is, the number of characters ins. -
If
vis a vector, thenlength(v)is the dimension ofv, that is, the number of entries, or components, ofv. -
If
Ais a matrix, thenlength(A)is the number of entries inA. -
If
Lis a list, thenlength(L)is the number of elements ofL. -
If
Sis a set, thenlength(S)is the cardinality ofS, that is, the number of elements ofS. -
If
pmis a pixmap, thenlength(pm)is the number of pixels inpm.
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