[math-fun] Wolfram Alpha large factorial bug
MRob> I discovered a calculation error problem in Wolfram Alpha. When given "20000!" (the factorial of 20000) it gives the answer in two forms: * a "Decimal approximation", 1.8192063202303451348276... x 10^77337 * a "Power of 10 representation", 10^(10^4.888364627124846). My own calculations (using the Stirling series for the log Gamma function) indicate that the first answer is correct. One can see that the second answer disagrees with the first, by computing log(77337+log(1.81920632023)) using base-10 logarithms. The exponent should be 4.888388... not 4.888364... For "LogGamma[20001]", Wolfram Alpha gives 178075.621737198700312867928177..., which agrees with its first 20000! answer and with my calculations. I also checked this in GP/PARI, which of course gives all the digits of 20000!, but you can multiply by 1.0 to put it in the more familiar scientific notation, and it agrees with Wolfram Alpha's first answer. I'd be curious to find out what Mathematica gives (I suspect it will be the correct first answer). I sent feedback to WoldramAlpha to report the problem. -- Robert Munafo -- mrob.com Follow me at: gplus.to/mrob - fb.com/mrob27 - twitter.com/mrob_27 -mrob27.wordpress.com - youtube.com/user/mrob143 - rilybot.blogspot.com In[487]:= N[20000!, 22] Out[487]= 1.819206320230345134828*10^77337 In[488]:= Log[10, Log[10, %]] Out[488]= 4.888388780625234145206724465 In[489]:= N[Log[10, Log[10, 20000!]], 23] Out[489]= 4.8883887806252341452067 --rwg
the 'error' is in giving 20000! for the 'decimal representation', but Gamma[20000]=(20000-1)! for the form 10^(10^4.888364627124846) Wouter -----Original Message----- From: math-fun-bounces+wouter.meeussen=vandemoortele.com@mailman.xmission.com [mailto:math-fun-bounces+wouter.meeussen=vandemoortele.com@mailman.xmission.com] On Behalf Of Bill Gosper Sent: donderdag 28 februari 2013 6:17 To: math-fun@mailman.xmission.com Subject: [math-fun] Wolfram Alpha large factorial bug MRob> I discovered a calculation error problem in Wolfram Alpha. When given "20000!" (the factorial of 20000) it gives the answer in two forms: * a "Decimal approximation", 1.8192063202303451348276... x 10^77337 * a "Power of 10 representation", 10^(10^4.888364627124846). My own calculations (using the Stirling series for the log Gamma function) indicate that the first answer is correct. One can see that the second answer disagrees with the first, by computing log(77337+log(1.81920632023)) using base-10 logarithms. The exponent should be 4.888388... not 4.888364... For "LogGamma[20001]", Wolfram Alpha gives 178075.621737198700312867928177..., which agrees with its first 20000! answer and with my calculations. I also checked this in GP/PARI, which of course gives all the digits of 20000!, but you can multiply by 1.0 to put it in the more familiar scientific notation, and it agrees with Wolfram Alpha's first answer. I'd be curious to find out what Mathematica gives (I suspect it will be the correct first answer). I sent feedback to WoldramAlpha to report the problem. -- Robert Munafo -- mrob.com Follow me at: gplus.to/mrob - fb.com/mrob27 - twitter.com/mrob_27 -mrob27.wordpress.com - youtube.com/user/mrob143 - rilybot.blogspot.com In[487]:= N[20000!, 22] Out[487]= 1.819206320230345134828*10^77337 In[488]:= Log[10, Log[10, %]] Out[488]= 4.888388780625234145206724465 In[489]:= N[Log[10, Log[10, 20000!]], 23] Out[489]= 4.8883887806252341452067 --rwg _______________________________________________ math-fun mailing list math-fun@mailman.xmission.com http://mailman.xmission.com/cgi-bin/mailman/listinfo/math-fun =============================== This email is confidential and intended solely for the use of the individual to whom it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. You are explicitly requested to notify the sender of this email that the intended recipient was not reached.
Thanks to each of you for the help. Meeussen Wouter had the great idea of actually figuring out what Wolfram's "wrong answer" was. In fact it's easy to divide one answer by the other and see the ratio is 20000, which makes it clear what happened. That means that the internals of Wolfram Alpha are actually computing those two results separately, rather than just computing one and then converting it into the other representation. Quite odd. I had other saved results from Wolfram Alpha for larger factorials, and I can see now that their wrong answers for 30000! and 100000! fit the same pattern: they're computing Gamma[N] when they should be computing Gamma[N+1]. There's another bug for factorials of even larger numbers. In the case of (10^10)! they give only the "power of 10 representation", and their answer is too big rather than being too small, and by a far greater amount. They give 10^10^10^1.0413926851582..., but the correct answer (by GP/PARI and my own implementation) is 10^10^10^1.0406306991294... In this case it's easy to see that Wolfram's answer is exactly 10^10^11. They are approximating n! as n^n, which "isn't even close" to the truth. Using two terms of the factorial form of the Stirling series [1] and expressing everything as a power of 10: (10^10)! ~ 10^(0.5*ln(2*pi)/ln(10) + 5 + 10^11 - 10^10/ln(10) + 1/(12*ln(10)*10^10)) (where "ln" is natural logarithm). You can see the dominant term 10^11 in there, but WolframAlpha is ignoring all the rest, which makes a big difference. They are doing the same thing for larger values, for example if you put in (10^20)!, their answer is equivalent to (10^20)^(10^20) = 10^(20*10^20) = 10^10^(21+log(2)/log(10)) = 10^10^10^1.328400603937241. I have reported this to Wolfram as a separate problem. This started when I was investigating the difference between my computed value of (10^100)! (the factorial of a googol) and the value on someone else's webpage. Googol factorial has been discussed at least as early as 1996; see [2]. - Robert [1] http://mathworld.wolfram.com/StirlingsSeries.html [2] http://mathforum.org/library/drmath/view/57903.html On Thu, Feb 28, 2013 at 3:52 AM, Meeussen Wouter (bkarnd) < wouter.meeussen@vandemoortele.com> wrote:
the 'error' is in giving 20000! for the 'decimal representation', but Gamma[20000]=(20000-1)! for the form 10^(10^4.888364627124846)
Charles Greathouse wrote:
20000!*1. is slow. Use gamma(20001) instead. (OK, so both are fast here but there's still a factor of 400 in runtime, 9 milliseconds vs. 22 microseconds.) gp agrees with you, by the way:
log(lngamma(20001)/log(10))/log(10) time = 0 ms. %1 = 4.888388780625234145206724465
From: Bill Gosper
In[487]:= N[20000!, 22] Out[487]= 1.819206320230345134828*10^77337 [...]
-- Robert Munafo -- mrob.com Follow me at: gplus.to/mrob - fb.com/mrob27 - twitter.com/mrob_27 - mrob27.wordpress.com - youtube.com/user/mrob143 - rilybot.blogspot.com
a small aside, as well in Mathematica as in Excel (yes, even them) you can find the function "Loggamma"; this improves on your expansion of Gamma(x) around infinity, alias the Stirling approximation. If you like big integers and googol and such, then play with loggamma(loggamma(..)) (grin) Wouter. -----Original Message----- From: math-fun-bounces@mailman.xmission.com [mailto:math-fun-bounces@mailman.xmission.com] On Behalf Of Robert Munafo Sent: donderdag 28 februari 2013 18:30 To: math-fun Subject: Re: [math-fun] Wolfram Alpha large factorial bug Thanks to each of you for the help. Meeussen Wouter had the great idea of actually figuring out what Wolfram's "wrong answer" was. In fact it's easy to divide one answer by the other and see the ratio is 20000, which makes it clear what happened. That means that the internals of Wolfram Alpha are actually computing those two results separately, rather than just computing one and then converting it into the other representation. Quite odd. I had other saved results from Wolfram Alpha for larger factorials, and I can see now that their wrong answers for 30000! and 100000! fit the same pattern: they're computing Gamma[N] when they should be computing Gamma[N+1]. There's another bug for factorials of even larger numbers. In the case of (10^10)! they give only the "power of 10 representation", and their answer is too big rather than being too small, and by a far greater amount. They give 10^10^10^1.0413926851582..., but the correct answer (by GP/PARI and my own implementation) is 10^10^10^1.0406306991294... In this case it's easy to see that Wolfram's answer is exactly 10^10^11. They are approximating n! as n^n, which "isn't even close" to the truth. Using two terms of the factorial form of the Stirling series [1] and expressing everything as a power of 10: (10^10)! ~ 10^(0.5*ln(2*pi)/ln(10) + 5 + 10^11 - 10^10/ln(10) + 1/(12*ln(10)*10^10)) (where "ln" is natural logarithm). You can see the dominant term 10^11 in there, but WolframAlpha is ignoring all the rest, which makes a big difference. They are doing the same thing for larger values, for example if you put in (10^20)!, their answer is equivalent to (10^20)^(10^20) = 10^(20*10^20) = 10^10^(21+log(2)/log(10)) = 10^10^10^1.328400603937241. I have reported this to Wolfram as a separate problem. This started when I was investigating the difference between my computed value of (10^100)! (the factorial of a googol) and the value on someone else's webpage. Googol factorial has been discussed at least as early as 1996; see [2]. - Robert [1] http://mathworld.wolfram.com/StirlingsSeries.html [2] http://mathforum.org/library/drmath/view/57903.html On Thu, Feb 28, 2013 at 3:52 AM, Meeussen Wouter (bkarnd) < wouter.meeussen@vandemoortele.com> wrote:
the 'error' is in giving 20000! for the 'decimal representation', but Gamma[20000]=(20000-1)! for the form 10^(10^4.888364627124846)
Charles Greathouse wrote:
20000!*1. is slow. Use gamma(20001) instead. (OK, so both are fast here but there's still a factor of 400 in runtime, 9 milliseconds vs. 22 microseconds.) gp agrees with you, by the way:
log(lngamma(20001)/log(10))/log(10) time = 0 ms. %1 = 4.888388780625234145206724465
From: Bill Gosper
In[487]:= N[20000!, 22] Out[487]= 1.819206320230345134828*10^77337 [...]
-- Robert Munafo -- mrob.com Follow me at: gplus.to/mrob - fb.com/mrob27 - twitter.com/mrob_27 - mrob27.wordpress.com - youtube.com/user/mrob143 - rilybot.blogspot.com _______________________________________________ math-fun mailing list math-fun@mailman.xmission.com http://mailman.xmission.com/cgi-bin/mailman/listinfo/math-fun =============================== This email is confidential and intended solely for the use of the individual to whom it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. You are explicitly requested to notify the sender of this email that the intended recipient was not reached.
Robert Munafo:
This started when I was investigating the difference between my computed value of (10^100)! (the factorial of a googol) and the value on someone else's webpage.
Robert's highly accurate computed value is here: http://mrob.com/pub/math/numbers-21.html#lp1_e101_995 All we need now is the number of trailing zeros and some of the digits preceding them. ;)
participants (4)
-
Bill Gosper -
Hans Havermann -
Meeussen Wouter (bkarnd) -
Robert Munafo