# Charlie Harvey

#574

#### Infinity and identity

hey allthetime, Anon,...wtf? -- allthetimeNow, as to why those were the decisions they made, your guess is as good as mine - but I guess they're just as reasonable as any other decision for when you ask for the max or min of an undefined value. -- Anon It's actually more sensible than you might think. It is because Math.min() and Math.max() can be used as functions over an array. Think of it as being a bit like the sum and product functions (I implement these in a later comment). If you've ever done any group theory the following should be familiar.

If you call sum on an empty collection, you'd expect it to return 0, which is the "identity" for + or "additive identity". That is

`a + 0 == a and 0 + a == a`

If you call product on an empty collection you want it to return 1, which is the "multiplicative" identity. That didn't seem obvious until I thought about it like this

`a * 1 == 1 and 1 * a == a`

In the same way you want max to return an identity function for "max-ness" so that

`max a ? == a and max ? a == a`

I find it easier to compare with + and * if I shift the max to the middle thus

`a `max` ? == a and ? `max` a == a`

In order for this to always be true, max() has to return something guaranteed to be smaller than any other number — hence negative Infinity (aka -∞, ⧞ or -Infinity). -∞ is the identity of max in the same way that 0 is the identity of + or 1 the identity of *.

So now we have

`a `max` -∞ == a and -∞ `max` a == a`

In the same way the identity for min has to be bigger than any other number so we get

`a `min` ∞ == a and ∞ `min` a == a`
Continued in next comment…