The Museum of HP Calculators

HP Forum Archive 21

 Factorial misbehaviorMessage #1 Posted by Han on 2 Oct 2013, 8:16 p.m. Is there a built-in limit on the size of the result of factorial() ? It seems that the limit is 254! and 255! is just "infinity." I was hoping it would be limited only by available memory (32MB RAM and 256MB Flash).... ...and perhaps got a little more than what I bargained for. I typed in 250! through 254! and then converted the result for 254! into a string (length is 503 chars). With those results on the CAS screen, I proceed to create a new program and lo and behold: Insufficient Memory! Say what?! I check my memory with [Shift][Mem] and see that I have only used up 4KB in the CAS. Edited: 2 Oct 2013, 10:18 p.m. after one or more responses were posted

 Re: Insufficient memoryMessage #2 Posted by Clayton Workman on 2 Oct 2013, 8:54 p.m.,in response to message #1 by Han Maybe similar reason why you can't do more than 1000 elements in a summation series? Hopefully, they can change this behaviour. -Clayton

 Re: Insufficient memoryMessage #3 Posted by Han on 2 Oct 2013, 9:21 p.m.,in response to message #2 by Clayton Workman Quote: Maybe similar reason why you can't do more than 1000 elements in a summation series? Hopefully, they can change this behaviour. -Clayton Were you able to confirm with your own calculator? I checked on the emulator and I can do up to 946! If I then copy the number (in CAS mode) and do + "" (cheap conversion to string) then the emulator crashes. 947! returns infinity. On the actual HP Prime, 255! returns infinity whereas 254! is ok. Edited: 2 Oct 2013, 9:26 p.m.

 Re: Insufficient memoryMessage #4 Posted by Mark Hardman on 2 Oct 2013, 9:46 p.m.,in response to message #1 by Han It would seem that the upper limit on factorial is artificial. In CAS mode, 254!*255*256*257*258 returns a valid, non-infinite value. In fact, 254!*254!*254!*254! returns an integer with 2,009 digits. Mark Hardman

 Re: Insufficient memoryMessage #5 Posted by Han on 2 Oct 2013, 10:05 p.m.,in response to message #4 by Mark Hardman Quote: It would seem that the upper limit on factorial is artificial. In CAS mode, 254!*255*256*257*258 returns a valid, non-infinite value. In fact, 254!*254!*254!*254! returns an integer with 2,009 digits. Mark Hardman Thanks for verifying. If you are daring enough to try to take one of those results and add an empty string to it, and then try to create a new program, that would be greatly appreciated too. (If you run into an insufficient memory error, a soft reset via [ON][APPS] should fix it). I created my own factorial program in CAS mode and was able to get up to 946! without issues. However, 947! again returns infinity. 946! is 2407 digits -- not sure if there is any significance there. Edit: cannot seem to duplicate the insufficient memory error any more, though. Edited: 2 Oct 2013, 10:07 p.m.

 Re: Insufficient memoryMessage #6 Posted by Mark Hardman on 2 Oct 2013, 10:15 p.m.,in response to message #5 by Han I'm unable to reproduce the Insufficient Memory bug as you described. Mark Hardman

 Re: Insufficient memoryMessage #7 Posted by Han on 2 Oct 2013, 10:18 p.m.,in response to message #6 by Mark Hardman Thanks for the response and testing. I think I may have found the cause of the insufficient memory. If you do happen to create a really large integer (say 946!), the screen stutters when redrawing. E.G. press [Apps] and then go back to [CAS] with the result for 946! on the history. Edit: the ins. mem. error is not related to factorials, but had to do with an invalid matrix that managed to stay resident in memory. Edited: 3 Oct 2013, 1:06 p.m.

 Re: Factorial misbehaviorMessage #8 Posted by Gilles Carpentier on 3 Oct 2013, 2:11 p.m.,in response to message #1 by Han Curious... I noted that there is no such limitation with the emulator Edited: 3 Oct 2013, 2:13 p.m.

 Re: Factorial misbehaviorMessage #9 Posted by Mark Hardman on 3 Oct 2013, 2:52 p.m.,in response to message #8 by Gilles Carpentier A limitation still exists in the emulator. There, the maximum allowed value is is 946! This is the same limit Han reached using his own CAS based factorial program on the actual hardware. Mark Hardman Edited: 3 Oct 2013, 3:07 p.m.

 Re: Factorial misbehaviorMessage #10 Posted by Ed Hodapp on 8 Oct 2013, 9:55 a.m.,in response to message #1 by Han The reason is that somewhere, something is converting to floating point instead of multi-precision integers. It appears that HP was a little careless in dealing with object types this time around. Even in CAS mode, various things will get converted. Here's a little test program: ```EXPORT IFACT(n) BEGIN LOCAL i,f; {1}->f; IF n>1 THEN FOR i FROM 2 TO n DO CONCAT(f,i)->f; END; RETURN f; END; ``` If I run IFACT(255) in CAS mode, and then do LIST(Ans), I get the exact value of 255!. If I change the RETURN statement to RETURN LIST(f), I get Inf (which is annoying in itself - how many representations of infinity does HP require?).

 Re: Factorial misbehaviorMessage #11 Posted by Ed Hodapp on 9 Oct 2013, 2:36 a.m.,in response to message #10 by Ed Hodapp Oops, that was wrong - using a float, 253! is the largest that can be represented. Looks like someone arbitrarily decided that 255! is just too big. "Why would anyone need more than 640k?" they must have Bill Gates helping them.

Go back to the main exhibit hall