GeometricMean definition

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












4












$begingroup$


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?)










share|improve this question











$endgroup$











  • $begingroup$
    Exp[Mean[Log[-4, -4]]] yields -4. The definition stated in the documentation doesn't seem to be the one used for numeric input.
    $endgroup$
    – Coolwater
    Mar 4 at 20:43











  • $begingroup$
    @Coolwater, but note that FullSimplify[Exp[Mean[Log[#]]] == GeometricMean[#]] &@-4, -5 returns False, so I don't think your explanation generalises.
    $endgroup$
    – mikado
    Mar 4 at 20:47






  • 2




    $begingroup$
    "The geometric mean applies only to positive numbers." (Wiki (Times @@ #)^(1/Length@#) == Exp@Mean@Log@# &@ RandomReal[10, 100] evaluates to True
    $endgroup$
    – Bob Hanlon
    Mar 4 at 21:19










  • $begingroup$
    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.)
    $endgroup$
    – Michael E2
    Mar 5 at 1:08
















4












$begingroup$


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?)










share|improve this question











$endgroup$











  • $begingroup$
    Exp[Mean[Log[-4, -4]]] yields -4. The definition stated in the documentation doesn't seem to be the one used for numeric input.
    $endgroup$
    – Coolwater
    Mar 4 at 20:43











  • $begingroup$
    @Coolwater, but note that FullSimplify[Exp[Mean[Log[#]]] == GeometricMean[#]] &@-4, -5 returns False, so I don't think your explanation generalises.
    $endgroup$
    – mikado
    Mar 4 at 20:47






  • 2




    $begingroup$
    "The geometric mean applies only to positive numbers." (Wiki (Times @@ #)^(1/Length@#) == Exp@Mean@Log@# &@ RandomReal[10, 100] evaluates to True
    $endgroup$
    – Bob Hanlon
    Mar 4 at 21:19










  • $begingroup$
    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.)
    $endgroup$
    – Michael E2
    Mar 5 at 1:08














4












4








4





$begingroup$


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?)










share|improve this question











$endgroup$




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?)







functions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 4 at 21:03







mikado

















asked Mar 4 at 20:35









mikadomikado

6,8421929




6,8421929











  • $begingroup$
    Exp[Mean[Log[-4, -4]]] yields -4. The definition stated in the documentation doesn't seem to be the one used for numeric input.
    $endgroup$
    – Coolwater
    Mar 4 at 20:43











  • $begingroup$
    @Coolwater, but note that FullSimplify[Exp[Mean[Log[#]]] == GeometricMean[#]] &@-4, -5 returns False, so I don't think your explanation generalises.
    $endgroup$
    – mikado
    Mar 4 at 20:47






  • 2




    $begingroup$
    "The geometric mean applies only to positive numbers." (Wiki (Times @@ #)^(1/Length@#) == Exp@Mean@Log@# &@ RandomReal[10, 100] evaluates to True
    $endgroup$
    – Bob Hanlon
    Mar 4 at 21:19










  • $begingroup$
    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.)
    $endgroup$
    – Michael E2
    Mar 5 at 1:08

















  • $begingroup$
    Exp[Mean[Log[-4, -4]]] yields -4. The definition stated in the documentation doesn't seem to be the one used for numeric input.
    $endgroup$
    – Coolwater
    Mar 4 at 20:43











  • $begingroup$
    @Coolwater, but note that FullSimplify[Exp[Mean[Log[#]]] == GeometricMean[#]] &@-4, -5 returns False, so I don't think your explanation generalises.
    $endgroup$
    – mikado
    Mar 4 at 20:47






  • 2




    $begingroup$
    "The geometric mean applies only to positive numbers." (Wiki (Times @@ #)^(1/Length@#) == Exp@Mean@Log@# &@ RandomReal[10, 100] evaluates to True
    $endgroup$
    – Bob Hanlon
    Mar 4 at 21:19










  • $begingroup$
    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.)
    $endgroup$
    – Michael E2
    Mar 5 at 1:08
















$begingroup$
Exp[Mean[Log[-4, -4]]] yields -4. The definition stated in the documentation doesn't seem to be the one used for numeric input.
$endgroup$
– Coolwater
Mar 4 at 20:43





$begingroup$
Exp[Mean[Log[-4, -4]]] yields -4. The definition stated in the documentation doesn't seem to be the one used for numeric input.
$endgroup$
– Coolwater
Mar 4 at 20:43













$begingroup$
@Coolwater, but note that FullSimplify[Exp[Mean[Log[#]]] == GeometricMean[#]] &@-4, -5 returns False, so I don't think your explanation generalises.
$endgroup$
– mikado
Mar 4 at 20:47




$begingroup$
@Coolwater, but note that FullSimplify[Exp[Mean[Log[#]]] == GeometricMean[#]] &@-4, -5 returns False, so I don't think your explanation generalises.
$endgroup$
– mikado
Mar 4 at 20:47




2




2




$begingroup$
"The geometric mean applies only to positive numbers." (Wiki (Times @@ #)^(1/Length@#) == Exp@Mean@Log@# &@ RandomReal[10, 100] evaluates to True
$endgroup$
– Bob Hanlon
Mar 4 at 21:19




$begingroup$
"The geometric mean applies only to positive numbers." (Wiki (Times @@ #)^(1/Length@#) == Exp@Mean@Log@# &@ RandomReal[10, 100] evaluates to True
$endgroup$
– Bob Hanlon
Mar 4 at 21:19












$begingroup$
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.)
$endgroup$
– Michael E2
Mar 5 at 1:08





$begingroup$
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.)
$endgroup$
– Michael E2
Mar 5 at 1:08











2 Answers
2






active

oldest

votes


















7












$begingroup$

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..






share|improve this answer











$endgroup$




















    1












    $begingroup$

    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[0]
    test /@ RandomReal[10^-10, 10, 10, 10]

    (* True, True, True, True, True, True, True, True, True, True *)





    share|improve this answer









    $endgroup$












    • $begingroup$
      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).
      $endgroup$
      – mikado
      Mar 6 at 20:26











    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192613%2fgeometricmean-definition%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7












    $begingroup$

    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..






    share|improve this answer











    $endgroup$

















      7












      $begingroup$

      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..






      share|improve this answer











      $endgroup$















        7












        7








        7





        $begingroup$

        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..






        share|improve this answer











        $endgroup$



        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..







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 6 at 15:07

























        answered Mar 4 at 21:09









        SomosSomos

        1,670110




        1,670110





















            1












            $begingroup$

            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[0]
            test /@ RandomReal[10^-10, 10, 10, 10]

            (* True, True, True, True, True, True, True, True, True, True *)





            share|improve this answer









            $endgroup$












            • $begingroup$
              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).
              $endgroup$
              – mikado
              Mar 6 at 20:26















            1












            $begingroup$

            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[0]
            test /@ RandomReal[10^-10, 10, 10, 10]

            (* True, True, True, True, True, True, True, True, True, True *)





            share|improve this answer









            $endgroup$












            • $begingroup$
              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).
              $endgroup$
              – mikado
              Mar 6 at 20:26













            1












            1








            1





            $begingroup$

            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[0]
            test /@ RandomReal[10^-10, 10, 10, 10]

            (* True, True, True, True, True, True, True, True, True, True *)





            share|improve this answer









            $endgroup$



            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[0]
            test /@ RandomReal[10^-10, 10, 10, 10]

            (* True, True, True, True, True, True, True, True, True, True *)






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 6 at 17:33









            Bob HanlonBob Hanlon

            61.1k33598




            61.1k33598











            • $begingroup$
              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).
              $endgroup$
              – mikado
              Mar 6 at 20:26
















            • $begingroup$
              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).
              $endgroup$
              – mikado
              Mar 6 at 20:26















            $begingroup$
            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).
            $endgroup$
            – mikado
            Mar 6 at 20:26




            $begingroup$
            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).
            $endgroup$
            – mikado
            Mar 6 at 20:26

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192613%2fgeometricmean-definition%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay