Shouldn't max([])=-inf ?


Matlab seems to follow a rule that iterative reduction operators give appropriate non-empty values to empty inputs. Examples include,
sum([])
ans = 0
prod([])
ans = 1
all([])
ans = logical
1
any([])
ans = logical
0
Is it an oversight not to do something similar for min and max?
max([])
ans = []
For non-empty A and B,
max([A,B])= max(max(A), max(B))
The extension to B=[] should therefore satisfy,
max(A)=max(max(A),max([]))
for any A, which will only be true if we define max([])=-inf.
Dyuman Joshi
Dyuman Joshi on 4 Apr 2026 at 5:41
I believe that would be inconsistent with this -
norm([])
ans = 0
det([])
ans = 1
Paul
Paul on 4 Apr 2026 at 13:31 (Edited on 4 Apr 2026 at 14:46)
Given that
norm([])
ans = 0
I would expect that max(svd([])) == 0, yet
max(svd([]))
ans = 0×1 empty double column vector
It makes sense to me that
svd([]) % svd(blkdiag(A,B)) == sort([svd(A);svd(B)]) == svd(A) w/ B = []
ans = 0×1 empty double column vector
But then to satisfy norm([]) == 0 we'd have to have max(double.empty(0,1)) == 0, which would be troubling.
I wonder why norm([]) == 0, keeping in mind that [] is a matrix, not a vector.
[isvector([]), ismatrix([])]
ans = 1×2 logical array
0 1
de Boor states (reference) that "Further, any norm of an empty matrix is zero, as the supremum of the empty set of nonnegative numbers." which seems like a tautological statement (and should "supremum" be replaced "infimum"?)
Paul
Paul on 30 Mar 2026 at 21:34
Wouldn't the identity hold if max([]) returned realmin (of the precision of the input)?
What should max(empty) return if the empty input is of a datatype that doesn't support inf, like int32 for example?
int32(-inf) % == intmin("int32")
ans = int32 -2147483648
max(int32.empty) % should return -2147483648
ans = 0×0 empty int32 matrix
Matt J
Matt J on 31 Mar 2026 at 0:29 (Edited on 31 Mar 2026 at 0:30)
My preference would be to cast -inf to the requisit type, as is done in concatenation.
cast(-inf,'like',int8([]))
ans = int8 -128
cast(-inf,'like',uint8([]))
ans = uint8 0
cast(-inf,'like',double([]))
ans = -Inf
cast(-inf,'like',single([]))
ans = single -Inf
Rik
Rik on 30 Mar 2026 at 15:33
Perhaps because max is often also used to calculate indices? Even though for the last decades you can use find with more arguments.
Just a minor note: I only understood what you meant by iterative reduction when you showed your example definition at the end. With that in mind, suddently the other outputs also make sense. I can't say I can see a pattern that would explain the results for sum, prod, all, and any, and also explains why max([]) would return an empty answer.
Paul
Paul on 30 Mar 2026 at 21:25
The index returned from max is empty for an empty input
[m,index] = max([])
m = [] index = []
which seems like a reasonable outcome even if m is returned non-empty.

Tags

No tags entered yet.