# GeometricMean definition

According to the documentation for GeometricMean

GeometricMean[Table[x[i],{i,1,n}]]==Product[x[i],{i,1,n}]^(1/n)


Presumably this is correct for x[i] positive real.

However, GeometricMean returns answers for some negative and complex inputs that are not consistent with this definition.

For example

GeometricMean[{-4, -4}]
(* -4 *)


(Perhaps it simply recognises a constant list as a special case, and shortcuts the definition to give an incorrect answer?)

• Exp[Mean[Log[{-4, -4}]]] yields -4. The definition stated in the documentation doesn't seem to be the one used for numeric input. – Coolwater Mar 4 '19 at 20:43
• @Coolwater, but note that FullSimplify[Exp[Mean[Log[#]]] == GeometricMean[#]] &@{-4, -5} returns False, so I don't think your explanation generalises. – mikado Mar 4 '19 at 20:47
• "The geometric mean applies only to positive numbers." (Wiki (Times @@ #)^(1/Length@#) == Exp@Mean@Log@# &@ RandomReal[10, 100] evaluates to True – Bob Hanlon Mar 4 '19 at 21:19
• GeometricMean[{-4, -4.}] yields positive 4., and GeometricMean[{-4, Unevaluated[-2^2]}] yields positive 4. Apparently a shortcut is taken when input is a list of identical elements, namely GeometricMean[{a, a,...}] is assumed to be a. (And GeometricMean[{-4, -4, -4, -4, -4.}] illustrates one of @Somos's points.) – Michael E2 Mar 5 '19 at 1:08

Similar to many other means, the geometric mean is homogenous. This means that

GeometricMean[ c data ] == c GeometricMean[ data ]


should be true for any number c. However, the problem is that $$n$$th roots are multi-valued in general and this causes no end of confusion. This is usually no problem for positive reals, but for negative reals it can be confusing. Do you want odd roots of negative reals be negative? Sometimes yes and sometimes no. For example, in version 10.2 the result of your example is $$4$$. Thus, the behavior has changed somewhat over time and there is no way to satisfy all expectations. The documentation for GeometricMean[] should be more clear in this regard. In particular it probably makes little sense to take the Geomtric mean of numbers which do not all all have the same sign..

For lists of positive values, all of the usual ways of calculating the GeometricMean are equivalent.

test[list_] := Simplify[
Equal @@
(#[list] & /@ {
GeometricMean,
(Times @@ #)^(1/Length[#]) &,
E^Mean[Log[#]] &,
Limit[Mean[#^t]^(1/t), t -> 0] &})]

Simplify[test[#], Thread[# > 0]] &@{a, b, c, d}

(* True *)

SeedRandom
test /@ RandomReal[{10^-10, 10}, {10, 10}]

(* {True, True, True, True, True, True, True, True, True, True} *)

• My hope, based on the initial observation that GeometricMean[{-4,-4}] gave -4 was that Mathematica implemented a sensible generalisation of GeometricMean to values other than positive reals (in particular, complex numbers). – mikado Mar 6 '19 at 20:26