Example Program to calculate Factorial

02022018, 08:53 AM
Post: #21




RE: Example Program to calculate Factorial
(02022018 01:16 AM)toml_12953 Wrote: But it's wrong! No, 69! is 1,711224524 E+98. The result calculated by the program is off in its last three digits. This is caused by the summation of the logs (the sum can and will be off in the last digit(s)) and the final exponential which increases the error. Dieter 

02022018, 10:02 AM
(This post was last modified: 02022018 10:03 AM by Csaba Tizedes.)
Post: #22




RE: Example Program to calculate Factorial
(02022018 09:06 AM)Mike (Stgt) Wrote:(02012018 08:06 PM)Csaba Tizedes Wrote: ... and HP12C version in engineer style:...and so on  nice! Hey, I want to crack this joke... Csaba 

02022018, 01:53 PM
Post: #23




RE: Example Program to calculate Factorial
(02022018 08:28 AM)Dieter Wrote:(02022018 02:44 AM)Gene Wrote: For historical purposes and ideas... Except that 1) I cannot find X<Y anywhere on my HP33C; 2) The stack is not properly handled. What calculator was that program written for? Gerson. 

02022018, 03:15 PM
Post: #24




RE: Example Program to calculate Factorial
(02022018 08:44 AM)Dieter Wrote:(02022018 05:05 AM)Thomas Okken Wrote: It is possible that the ROM uses a better algorithm, but in the case of n!, I think the basic multiplication is used everywhere. It sounds like it may have a hardcoded value for 160!, so calculations for n >= 160 would require only n  160 multiplications. That could have been done keep the calculation time from becoming too long, or to keep the error from growing beyond the guard digits. (02022018 01:53 PM)Gerson W. Barbosa Wrote: 1) I cannot find X<Y anywhere on my HP33C; The HP25 has X<Y. (Hmm, was it the only HP to have that function until the 41C?) 

02022018, 03:28 PM
Post: #25




RE: Example Program to calculate Factorial
(02022018 01:53 PM)Gerson W. Barbosa Wrote: Except that V2N10 of PPC Journal dates from December of 1975 and this program was written for the HP 25 as shown on that page. A real shame HP kept flipping the included conditional tests back and forth back then. A real pain and one of the real crossmodel design failures IMO. And... if anyone here does NOT have the full PDF set of the PPC Journals... why not? Contact Jake Schwartz. Tons of good material still there. 

02022018, 06:59 PM
Post: #26




RE: Example Program to calculate Factorial
(02022018 03:28 PM)Gene Wrote: A real shame HP kept flipping the included conditional tests back and forth back then. A real pain and one of the real crossmodel design failures IMO. That's something I never understood. Was ROM space or the number of available opcodes really so limited that the full set of 12 test commands could not be realized? In the late Seventies the standard set had only eight of them. But while x<0? exists there is no x<y?, and while there is an x≤y? the corresponding x≤0? is missing. Eventually the 41C then featured ten tests, but it still lacked the two for "greater or equal". Weird. If there really was room for only eight tests HP better had chosen <, >, = and ≠. From these the missing ≤ and ≥ tests can easily be synthesized: the combination x≠y? x>y? is logically the same as x≥y?. But who cares today? Tempi passati. ;) Dieter 

02022018, 07:20 PM
Post: #27




RE: Example Program to calculate Factorial
(02022018 06:59 PM)Dieter Wrote:(02022018 03:28 PM)Gene Wrote: A real shame HP kept flipping the included conditional tests back and forth back then. A real pain and one of the real crossmodel design failures IMO. ROM space was definitely limited. The HP25 ROM is full to the last byte. This is also the first HP to provide comparisons with zero, which probably explains why it's the only one until the 41C where the set of comparisons with zero exactly matches the set of comparisons with Y... and the lack of ROM space could also explain why the inequalities are each other's logical opposites, because that saves another couple of steps in their implementation. And finally, the full set of 12 as it exists on the 42S would have been hard to fit on the HP25 keyboard. The only thing that the 25 had absolutely no shortage of was opcodes. (02022018 06:59 PM)Dieter Wrote: But who cares today? Well, we do. Duh. 

02022018, 07:28 PM
Post: #28




RE: Example Program to calculate Factorial
(02022018 03:28 PM)Gene Wrote: V2N10 of PPC Journal dates from December of 1975 and this program was written for the HP 25 as shown on that page. A real shame HP kept flipping the included conditional tests back and forth back then. A real pain and one of the real crossmodel design failures IMO. Thanks, Thomas and Gene! Yes, it’s there. Listing title: IMPROVED FACTORIAL FUNCTION (0<=n<=69) I’m sure I have an old version of Jake Schwartz’s DVD, but I don’t know where it is (time for an upgrade, perhaps). But I’ve found it on the “HP41 EXTENDED ARCHIVE DVD”, from TOS. Gerson. 

02022018, 07:52 PM
(This post was last modified: 02022018 07:55 PM by Gerson W. Barbosa.)
Post: #29




RE: Example Program to calculate Factorial  
02022018, 08:16 PM
Post: #30




RE: Example Program to calculate Factorial
7 steps but does not manage 0!
HP 29C Code:
My site http://www.emmella.fr 

02022018, 08:19 PM
(This post was last modified: 02032018 09:36 AM by Dieter.)
Post: #31




RE: Example Program to calculate Factorial
(02022018 07:20 PM)Thomas Okken Wrote: ROM space was definitely limited. The HP25 ROM is full to the last byte. Edit: Full to the last byte? There are 16 (!) NOPs in the listing. Once even five in a row. ;) And finally after 40 years they have been put to good use, fixing a strange behaviour in the HP25 number entry routine. (02022018 07:20 PM)Thomas Okken Wrote: And finally, the full set of 12 as it exists on the 42S would have been hard to fit on the HP25 keyboard. OK, I see the problem with limited ROM space. But there's plenty of room on the keyboard – there are eight (!) unused locations. STO and RCL even do not have any shifted functions at all. But if there is no room for functions to fill these positions... #) Dieter 

02022018, 09:58 PM
(This post was last modified: 02022018 11:02 PM by Gerson W. Barbosa.)
Post: #32




RE: Example Program to calculate Factorial
(02022018 08:16 PM)badaze Wrote: 7 steps but does not manage 0! Try adding EEX as your first step. If it works that’ll make 8 steps. Still pretty good! PS: It will work only for x=0 and x=1. I have a dead 29C in front of me and can’t think of anything better than [ x=0 ] [ e^x ], which makes 9 steps. Still not bad. 

02032018, 01:29 AM
Post: #33




RE: Example Program to calculate Factorial
I think HP15C is the most fully pack functions and features after the 41C.
I don't know why HP didn't put Factorial function for HP 25 since this model have very limited program steps and if your program need factorial that will take up more steps in the process. Why not just put n! instead of x^2 Gamo 

02032018, 03:43 AM
(This post was last modified: 02032018 03:45 AM by Gerson W. Barbosa.)
Post: #34




RE: Example Program to calculate Factorial
(02032018 01:29 AM)Gamo Wrote: I don't know why HP didn't put Factorial function for HP 25 since this model have very limited program steps and if your program need factorial that will take up more steps in the process. Precisely because of the very limited number of program steps in the HP25, as you’ve noticed. The latter is a more frequently used function than the former. Thus, even if the ROM weren’t full, the designers would probably have chosen x^2 instead of n!. If you have only 49 or 50 steps, then [ ENTER ] [ * ] instead of simply [ x^2 ] will make a difference, depending on how many times you have to use that in a program. On the other hand, most of the times we won’t need a full implementation of the factorial function. If you are sure no argument will be zero, then you don’t have to worry about that special case, and save one step or two. I remember once I needed factorial in a 33C program, but I had only five steps left. Luckily enough, the possible arguments lay in the 0 through 4 range, then I could use the following: x^2 5 / e^x INT 

02032018, 08:56 AM
(This post was last modified: 02032018 09:21 AM by Dieter.)
Post: #35




RE: Example Program to calculate Factorial
(02022018 09:58 PM)Gerson W. Barbosa Wrote: Try adding EEX as your first step. If it works that’ll make 8 steps. Still pretty good! On the HP25 it also works for other input. This seems to be related to a bug, err... "special feature" that has been discussed earlier: R/S obviously does not terminate number entry so that the EEX is appended to the entered number. But this only works if you manually type your input. You can't recall it from a register, like [RCL] 2 [R/S]. ;) (02022018 09:58 PM)Gerson W. Barbosa Wrote: I have a dead 29C in front of me and can’t think of anything better than [ x=0 ] [ e^x ], which makes 9 steps. What about this? Code: 01 STO 0 Same number of steps but a tiny bit faster as no transcendental function is required. Dieter 

02042018, 02:52 AM
Post: #36




RE: Example Program to calculate Factorial
(02022018 08:28 AM)Dieter Wrote:(02022018 02:44 AM)Gene Wrote: For historical purposes and ideas... How about this 9step one? Code:
However, for practical purposes I would insert two Rv instructions after GTO 03: Code:
Example: Compute C(15, 4) 15 R/S 4 R/S / 15 ENTER 4  R/S / > 1365 Gerson. 

02082018, 08:04 PM
(This post was last modified: 02082018 10:06 PM by Gene.)
Post: #37




RE: Example Program to calculate Factorial
Slightly OT, but wanted to put this into the factorial thread. Source: A TI SR56 brochure printed in England.
Factorial for the SR56. Takes 14 steps out of 100. Thats' an interesting efficiency aspect vs. the HP 25, etc. versions. Code: LRN (places calculator in program mode) 

02092018, 01:04 AM
(This post was last modified: 02092018 01:05 AM by Gerson W. Barbosa.)
Post: #38




RE: Example Program to calculate Factorial
(02082018 08:04 PM)Gene Wrote: Factorial for the SR56. Takes 14 steps out of 100. Thats' an interesting efficiency aspect vs. the HP 25, etc. When I started using calculators, factorial was not an issue as they all had it builtin. The HP15C which replaced my TI59 even had Gamma! The HP25C is tricky because of the numberentry bug (or feature) and the lack of x<=y test. The only 10step program I came up with is not practical as it won’t work for arguments that are results of an operation. Code:
0 R/S > 1.00 1 R/S > 1.00 5 R/S > 120.00 but 5 ENTER R/S > 1.00 On a 25C, I would use this one instead: Code:
Why is 6 afraid of 7? 6 R/S 7 R/S * 10 R/S  > 0 No, not because of that :) 

02132018, 03:39 PM
Post: #39




RE: Example Program to calculate Factorial
Another entry for historical purposes.
From PPC Journal V10N3P26 by Kendrick Chan in the Philippines. Works for 0 < X < 70 01 INT 02 LASTX 03 1 04  05 x=0? 06 GTO 09 07 * 08 GTO 02 09 Roll Down 

02222018, 01:11 AM
Post: #40




RE: Example Program to calculate Factorial
.
Hi all, A little late but I couldn't resist. This is my attempt at a factorial program which was one of the first programs I wrote some 40+ years ago after I just bought a new, shiny HP25: 01 STO 0 01 23 00 02 STO/ 0 02 23 71 00 03 STOx 0 03 23 61 00 04 1 04 01 05  05 41 06 X#0? 06 15 61 07 GTO 03 07 13 03 08 RCL 0 08 24 00 to run it, and a few selected cases: f PRGM, FIX 0 1 R/S > 1 5 R/S > 120 13 R/S > 6227020800 69 R/S > 1.7112245 98 (1.711224522e98 internally) 0 R/S > Error 70 R/S > OF (Overflow) RCL 0 > 9.9999999 99 There's no need for a 09 GTO 00 step because the HP25 fills up the entire 49step program memory with GTO 00 instructions which are there whether you key them in or not. As can be seen in the examples it will work for N=1 to 69, but not for 0. I found it very easy to remember and so would use it to show off on the fly my new wonderful HP25 to people who would ask me what it could do when programmed (no HP25C back then). They were always extremely amazed that an useful program would be so easily entered and run on the go. V. . Find All My HPrelated Materials here: Valentin Albillo's HP Collection 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)