Mini-challenge - accurate factorials
|
07-07-2023, 08:40 PM
Post: #1
|
|||
|
|||
Mini-challenge - accurate factorials
.
A factorial, in decimal, will generally have a number of trailing zeros. For example 7! = 5040 has 4 digits in total, one trailing zero, and so we can say it has 3 significant digits. So, given a calculator with some number of digits it can display, we might ask what's the largest factorial that will fit? (For example, consider calculators with 8, 10, 12, 14 digit displays, we ask what value of n would give rise to the large displayable n!) And, given a calculator which has a scientific notation, such that the trailing zeros can be implicit, and needing only to display the significant digits, we can display even larger factorials. How large is the largest n, such that n! is accurately displayed with 8, 10, 12 or 14 significant digits? Have fun! |
|||
07-08-2023, 02:02 PM
(This post was last modified: 07-08-2023 02:27 PM by J-F Garnier.)
Post: #2
|
|||
|
|||
RE: Mini-challenge - accurate factorials
(07-07-2023 08:40 PM)EdS2 Wrote: given a calculator which has a scientific notation, such that the trailing zeros can be implicit, and needing only to display the significant digits, we can display even larger factorials. How large is the largest n, such that n! is accurately displayed with 8, 10, 12 or 14 significant digits? If by accurate you mean exact, the largest exact factorials we can get are: on a 10-digit machine (e.g. 15C): 15! = 1307674368000 displayed as 1.307674368e12 on a 12-digit machine (e.g. 32S): 17! = 355687428096000 displayed as 3.55687428096e14 Now, if we understand accurate as correctly rounded, then several machines ensure that all factorials are accurate (that is the error is less than 0.5 ULP). For instance, the 71B, the 28S, the series 48. But it's not true for some machines, for instance the 22S/32S/32SII: 159! = 2.94670227249e282 (correct value is 2.94670227250e282) Could you find the other three incorrectly rounded cases on these machines? BTW, the 35S gives all correct values :-) J-F |
|||
07-08-2023, 03:15 PM
Post: #3
|
|||
|
|||
RE: Mini-challenge - accurate factorials
Thanks - I did mean exact. But I, for one, welcome your extra challenge.
|
|||
07-08-2023, 03:23 PM
(This post was last modified: 07-08-2023 03:24 PM by AndiGer.)
Post: #4
|
|||
|
|||
RE: Mini-challenge - accurate factorials
(07-08-2023 02:02 PM)J-F Garnier Wrote: But it's not true for some machines, for instance the 22S/32S/32SII: Interesting. As I'm not very familiar with the 32S I programmed a small routine to calculate factorials. Result: 159! = 2.94670227254e282 Google is your friend and so I found where to calculate with the built-in function. Andi |
|||
07-08-2023, 05:43 PM
(This post was last modified: 07-08-2023 05:48 PM by John Keith.)
Post: #5
|
|||
|
|||
RE: Mini-challenge - accurate factorials
Code:
As an aside, the HP 49 and 50 in Exact mode will give the exact value for n! limited only by the number of digits that will fit in memory. For the 49G+ and 50, the program FFAC is substantially faster than the built-in factorial function. On my HP 50, 1000! (2568 digits) takes about 29 seconds, whereas 1000 FFAC takes about 380 milliseconds. |
|||
07-08-2023, 06:55 PM
(This post was last modified: 07-08-2023 07:08 PM by DA74254.)
Post: #6
|
|||
|
|||
RE: Mini-challenge - accurate factorials
WP43 can do 40!
Which displays 815915283247897734345611269596115894272e9 where the last trailing 9 0's are seen in "show", thus it can display the 39 digits before all the trailing 0's. Full number in "show" is: 815915283247897734345611269596115894272000000000 (If I understood your challenge right). Esben 15C CE, 28s, 35s, 49G+, 50G, Prime G2 HW D, SwissMicros DM32, DM42, DM42n, WP43 Pilot Elektronika MK-52 & MK-61 |
|||
07-09-2023, 06:02 AM
Post: #7
|
|||
|
|||
RE: Mini-challenge - accurate factorials
Yes, that's what I was getting at - whether or not we choose to do SHOW changes the conditions a bit of course.
Similarly, it looks like Free42 can give us 36! - all the significant digits show up in SHOW mode, whereas 37! is too big and misses a few. Thanks for the OEIS entries John! |
|||
07-09-2023, 08:06 AM
(This post was last modified: 07-09-2023 08:29 AM by J-F Garnier.)
Post: #8
|
|||
|
|||
RE: Mini-challenge - accurate factorials
(07-08-2023 06:55 PM)DA74254 Wrote: WP43 can do 40! (07-09-2023 06:02 AM)EdS2 Wrote: Yes, that's what I was getting at - whether or not we choose to do SHOW changes the conditions a bit of course. Yes, 36! is exact in Free42, but surprisingly 40! = 8.159152832478977343456112695961164e47 has 5 ULP error. That's a lot for just 4 additional multiplications, unless Free42 doesn't use guard digits in the factorial code, which I can't believe. Edit: even more weird (on Free42): 39! = 2.039788208119744335864028173990290e46 (correct) 39! * 40 = 8.159152832478977343456112695961160e47 (just 1 ULP error, that's normal here). So what is going on with the direct 40! calculation ? J-F |
|||
07-09-2023, 11:04 AM
Post: #9
|
|||
|
|||
RE: Mini-challenge - accurate factorials
(07-07-2023 08:40 PM)EdS2 Wrote: . The above factorial has four significant digits since the trailing zero is not to the right of a decimal. You can say that a factorial has zeros as the least significant digits, like 5040. Namir |
|||
07-09-2023, 11:25 AM
Post: #10
|
|||
|
|||
RE: Mini-challenge - accurate factorials
(Yes, I could and perhaps should have chosen a different adjective. Allow me temporarily to be Humpty Dumpty, for whom a word means exactly what it's intended to mean.)
|
|||
07-09-2023, 05:15 PM
(This post was last modified: 07-13-2023 06:09 AM by Werner.)
Post: #11
|
|||
|
|||
RE: Mini-challenge - accurate factorials
(07-09-2023 08:06 AM)J-F Garnier Wrote: Yes, 36! is exact in Free42, but surprisingly 40! =Hi J-F, Free42 does not use guard digits, since the intel decimal library has no provisions for extended precision for the 34-digit format. The factorial is likely calculated as 40*39*..*2, not as 2*3*4..*39*40. Doing it manually shows the results you obtained. Cheers, Werner (that's *nine* full hours Bob! I'm slipping) 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
07-09-2023, 11:11 PM
Post: #12
|
|||
|
|||
RE: Mini-challenge - accurate factorials
(07-09-2023 05:15 PM)Werner Wrote: Hi J-F, Nah, no slipping here... it's all about quality. You're doing just fine... --Bob Prosperi |
|||
07-11-2023, 08:39 AM
Post: #13
|
|||
|
|||
RE: Mini-challenge - accurate factorials
(07-09-2023 05:15 PM)Werner Wrote: Free42 does not use guard digits, since the intel decimal library has no provisions for extended precision for the 34-digit format. Thanks Werner, I came to the same conclusion. So not a problem as such, but we need to keep in mind that not all 34 digits are correct. Most of the time, the error is just a few ULPs, but I found some worst cases: 61! = 5.075802138772247988008568121766260e83 (correct: 5.07...252e83 : 8 ULPs) 101! = 9.425947759838359420851623124482910e159 (correct: 9.42...937e159 : 27 ULPs) 251! = 8.114469214881860408125244525581122e494 (correct: 8.11...165e494 : 43 ULPs) J-F |
|||
07-12-2023, 09:23 PM
(This post was last modified: 07-12-2023 09:53 PM by Gilles.)
Post: #14
|
|||
|
|||
RE: Mini-challenge - accurate factorials
Brut force search in NewRPL :
Fact0: Code: « → p Nota about NewRPL: - SETPREC : set the number of significant digits. The default is 32 digits of precision. The maximum is 2000 digits of precision (for comparaison, the stock 50g ROM has a fixed precision of 12 digits displayed, 15 digits internally) - EXIT : Exit the current loop Code: 8 Fact0 -> { 13 6227020800 } |
|||
07-13-2023, 07:35 AM
Post: #15
|
|||
|
|||
RE: Mini-challenge - accurate factorials
Nice! And thanks everyone, hope you had fun.
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)