Skip to content

Max ​

The largest of its arguments.

✓ checked against that system · ! checked, with disagreements (hover a chip)FungrimMaxFungrim entry632d1cbfe28bWolfram LanguageMax!SageMathenumeratio_max($*,)SymPyenumeratio_max($*,)Juliaenumeratio_max($*,)
Max(a, b, …)the largest of two or more values.
Max(list)the largest value in a list.
Max(finset)the largest member of a Finset.
Typed signatures
TypePackageApplies
(value*) -> numberanalyticreplaces compute-enginealways
(value*) -> numbercompute-enginealways
(any*) -> anycombinatoricsreplaces structureson Finset
(any*) -> anystructuresreplaces analyticalways

Domain: Arithmetic

Details
  • The largest of its arguments, or of a single list argument.
  • Multiple arguments -- lists included -- are flattened into one pool rather than compared pairwise or threaded element-wise. See Min.
  • Commutative and associative: order and grouping don't matter.
  • NaN poisons the result: it beats every other comparison, even +∞+\infty.
  • With no arguments, compute-engine returns NaN rather than −∞-\infty, the true identity element.
  • Takes a Finset too: its largest member, and NaN for the empty one, as for an empty list.

Examples

1 more kept as data, checked against the oracles
Basic #
live ↗
Inmax⁡(3,1,4,1,5)\max(3, 1, 4, 1, 5)Out55

Also accepts a single list argument

live ↗
Inmax⁡([3,1,4])\max(\bigl\lbrack3, 1, 4\bigr\rbrack)Out44
live ↗
Inmax⁡(−1,−5)\max(-1, -5)Out−1-1

A single argument is returned unchanged

live ↗
Inmax⁡(3)\max(3)Out33
live ↗
Inmax⁡(9,2)\max(9, 2)Out99
live ↗
Inmax⁡([4,1,7,2])\max(\bigl\lbrack4, 1, 7, 2\bigr\rbrack)Out77
live ↗
Inmax⁡(5.56,−4.8,7.3)\max(5.56, -4.8, 7.3)Out7.37.3
Scope #

Nested lists are flattened into the pool

live ↗
Inmax⁡(2,3,[[12,−1],[−53,12]])\max(2, 3, \bigl\lbrack\bigl\lbrack\frac{1}{2}, -1\bigr\rbrack, \bigl\lbrack-\frac{5}{3}, \frac{1}{2}\bigr\rbrack\bigr\rbrack)Out33

Exact numbers are compared numerically

live ↗
Inmax⁡(2,32)\max(\sqrt{2}, \frac{3}{2})Out32\frac{3}{2}
live ↗
Inmax⁡(1,∞)\max(1, ∞)Out∞∞

The numeric arguments collapse to their maximum; symbolic ones stay

live ↗
Inmax⁡(3,x,5)\max(3, x, 5)Outmax⁡(5,x)\max(5, x)

Compares exact constants numerically: max⁡(e,π,2)=π\max(e, \pi, 2) = \pi

live ↗
Inmax⁡([e,π,2])\max(\bigl\lbrack e, π, 2\bigr\rbrack)Outππ

The max of two Intervals is the interval of possible maxima, [1,5][1, 5]

live ↗
Inmax⁡(Interval(1,3),Interval(−3,5))\max(\mathrm{Interval}(1, 3), \mathrm{Interval}(-3, 5))OutInterval(1,5)\mathrm{Interval}(1, 5)

A Finset has a largest member: the subset {1,3,4}\{1,3,4\} of {1,…,6}\{1,\dots,6\}

live ↗
Inmax⁡(Finset⁡(Tuple⁡(6,[1,3,4])))\max(\operatorname{Finset}(\operatorname{Tuple}(6,\bigl\lbrack1, 3, 4\bigr\rbrack)))Out44
Applications #

The day's high from a handful of hourly readings. See Min

live ↗
Inmax⁡(68,72,65,80,74)\max(68, 72, 65, 80, 74)Out8080
Properties #

Commutative: order doesn't matter

live ↗
Inmax⁡(3,7)=max⁡(7,3)\max(3, 7)=\max(7, 3)OutTrue\mathrm{True}

Multiple list arguments are flattened into one pool rather than compared pairwise

live ↗
Inmax⁡([3,1,4],[9,2])=9\max(\bigl\lbrack3, 1, 4\bigr\rbrack, \bigl\lbrack9, 2\bigr\rbrack)=9OutTrue\mathrm{True}

Idempotent: max⁡(x,x)=x\max(x, x) = x

live ↗
Inmax⁡(x,x)\max(x, x)Outxx
Possible issues #

With no arguments, compute-engine returns NaN rather than −∞-\infty, the true identity element

live ↗
Inmax⁡()\max()OutNaN⁡\operatorname{NaN}

NaN poisons the result, overriding every other argument

live ↗
Inmax⁡(NaN⁡,3)\max(\operatorname{NaN}, 3)OutNaN⁡\operatorname{NaN}

The max of an empty list is NaN too

live ↗
Inmax⁡([])\max(\bigl\lbrack\bigr\rbrack)OutNaN⁡\operatorname{NaN}

ComplexInfinity is unordered, so Max cannot compare it: the call stays unevaluated, as in Wolfram

live ↗
Inmax⁡(∞~,1)\max(\tilde∞, 1)Outmax⁡(1,∞~)\max(1, \tilde∞)

The empty Finset answers as an empty list does: NaN

live ↗
Inmax⁡(Finset⁡((3,[])))\max(\operatorname{Finset}((3,\bigl\lbrack\bigr\rbrack)))OutNaN⁡\operatorname{NaN}
About
Examples24
Checked againstWolfram Language 19 agree5 differSageMath 18 agree1 differ1 unevaluated3 errorSymPy 17 agree4 differ3 errormathlib4 9 agree6 errorJulia 15 agree1 unevaluated4 errorRust 4 agree2 error
CrosswalkFungrimFungrim entry ×2Wolfram LanguageSageMathSymPyJuliaRust

Implementation

mappedmathlib4packages/oracle/src/mappings.ts

The largest of the arguments as exact rationals. Several arguments are the pool; a lone argument is a list of numbers. The empty pool (ours is NaN) and a nested list (ours flattens it) fail to elaborate rather than defaulting.

mappedmathlib4packages/oracle/src/mappings.ts

A single list of numbers; a lone number fails to elaborate.

mappedwolframpackages/oracle/src/mappings.ts

Wolfram (and our Max) flattens nested lists into one pool; bare SymPy Max()/Sage max() on a list (or a list of lists) either raise or compare lexicographically instead, so both go through a flattening helper (run.ts's SYMPY_PREAMBLE / SAGE_PREAMBLE).

mappedsympypackages/oracle/src/mappings.ts

Wolfram (and our Max) flattens nested lists into one pool; bare SymPy Max()/Sage max() on a list (or a list of lists) either raise or compare lexicographically instead, so both go through a flattening helper (run.ts's SYMPY_PREAMBLE / SAGE_PREAMBLE).

mappedsagepackages/oracle/src/mappings.ts

Wolfram (and our Max) flattens nested lists into one pool; bare SymPy Max()/Sage max() on a list (or a list of lists) either raise or compare lexicographically instead, so both go through a flattening helper (run.ts's SYMPY_PREAMBLE / SAGE_PREAMBLE).

mappedjuliapackages/oracle/src/mappings.ts
mappedrustpackages/oracle/src/mappings.ts

Two operands.

See also: Min, Clamp