Algosim documentation: max

max

Finds the greatest of all real numbers in a container or in a sequence.

Syntax

Description

The greatest of two numbers

If a and b are real numbers, then max(a, b) is the greatest of them.

Finding the greatest number in a container

Finding the greatest number in a sequence

max(expr, var, a, b) is the greatest value of expr as var takes all integer values from a to b, inclusively. expr must return a real value for every value of var in [a, b] ∩ ℤ. The number of elements in the sequence, b − a + 1, must be at least 1.

Examples

The greatest of two numbers

f ≔ x ↦ 5⋅max(x, 2)
custom function

Finding the greatest number in a container

max('(10/51, 49/256, 5/27, 6/29, 3/14, 24/121))
0.214285714286	(=3/14)
max(RandomVector(100))
0.991129796952
max(RandomIntMatrix(100, 100, 1000000))
999960
max(size(❨❨1, 2❩, ❨4, 1❩, ❨0, 1❩❩))
3
f ≔ n ↦ if(even(n), n/2, 3⋅n + 1);
n ≔ 27; L ≔ IteratedImages(f, n, 100); '(min(L), max(L))
23
9232
st ≔ n ↦ (c ≔ 0; k ≔ n; while(k ≠ 1, (k ≔ f(k); inc(c))); c);
max(SequenceVector(100) @ st)
118
max(compute(prime(succ(n)) − prime(n), n, 1, 1000000))
154

Finding the greatest number in a sequence

max(sin(k/2) + 5⋅cos(k/3) − sin(k/4), k, −10, 10)
5
f ≔ n ↦ if(even(n), n/2, 3⋅n + 1);
st ≔ n ↦ (c ≔ 0; k ≔ n; while(k ≠ 1, (k ≔ f(k); inc(c))); c);
max(st(n), n, 1, 100)
118

See also