Algosim documentation: cardinality

cardinality

Gives the cardinality of a set.

Syntax

Description

If S is a set, then cardinality(S) is the cardinality of S.

Notes

card and cardinality are synonyms of length, which is the function implementing the # prefix operator. Hence, if S is a set (or any other container), the following are equivalent expressions:

Naturally, however, card and cardinality are function names that are semantically pleasant to apply to sets specifically. (We talk about the “cardinality” of a set, the “length” of a string, and the “dimension” of a vector.)

Examples

cardinality({2, 1, 0, −3, 8, 5})
6
f ≔ n ↦ if(even(n), n/2, 3⋅n + 1);
cardinality(orbit(f, 1000))
112

See also