The Museum of HP Calculators

HP Forum Archive 17

 MultiFactorial using 19BII SolverMessage #1 Posted by Bill (Smithville, NJ) on 1 Mar 2007, 3:23 p.m. Yesterday, Egan posted how to calculate multiFactorials, which I had never even heard of before his post. See following link Egan had posted a HP-15C program that would calculate it. I've been playing around with the solver on the HP-19BII and thought I'd give a try at translating his 15C program to a solver equation. I came up with the following: ```MF = SIGMA(K:1: IF(X=N OR N=1:1:(X/N)+1):1: IF(K=1:0*L(M:X):0*L(X:X-N)+0*L(M:G(M)*X))) + IF(N=1:FACT(X):G(M)) ``` Just enter X and N and press MF to solve. I'm still trying to learn how to use the solver, and this is my first try with the SIGMA function. So would appreciate any suggestions, comments, etc on how to do it better. Thanks, Bill Edited: 2 Mar 2007, 8:40 a.m.

 Re: MultiFactorial using 19BII SolverMessage #2 Posted by Bill (Smithville, NJ) on 2 Mar 2007, 8:48 a.m.,in response to message #1 by Bill (Smithville, NJ) After a little more thinking and reading, I have come up with the following solver equation: ```MF = IF (N=1:FACT(X): IF (X<=N:X: SIGMA(K:1:(X/N)+1):1: IF(K=1:0*L(M:X):0*L(X:X-N)+0*L(M:G(M)*X))) + G(M))) ``` It now checks for the simple cases of N=1 or where X <= N outside the SIGMA function. Is there anyway to get rid of the Temporary Variable M? Thanks, Bill Edited: 2 Mar 2007, 1:50 p.m. after one or more responses were posted

 Re: MultiFactorial using 19BII SolverMessage #3 Posted by Bill (Smithville, NJ) on 2 Mar 2007, 10:22 a.m.,in response to message #2 by Bill (Smithville, NJ) Ooops... Just noticed that if N is a multiple of X, then the solver always returns zero for MF, since the the final pass through the SIGMA loop would have X=0. I could change the final index from (X/N)+1 to (X/N)+0.99 which would be correct for most cases, but would still fail under certain conditions. If the 19BII had the MOD fuction, then I could do IF (MOD(X/N)=0:X/N:(X/N)+1 which would then add one more pass ONLY if N wasn't a multiple of X. I could also add an IF statement to check for when X=0 inside the SIGMA function and ignore multiplication. Not very elegant. Anybody have any other suggestions? Thanks, Bill

 Re: MultiFactorial using 19BII SolverMessage #4 Posted by Bob Wang on 2 Mar 2007, 12:14 p.m.,in response to message #3 by Bill (Smithville, NJ) Bill: The 19BII does have a modulo function, MOD(X:Y) Bob

 Re: MultiFactorial using 19BII SolverMessage #5 Posted by Bill (Smithville, NJ) on 2 Mar 2007, 12:32 p.m.,in response to message #4 by Bob Wang Hi Bob, Quote: The 19BII does have a modulo function, MOD(X:Y) Boy do I feel stupid - that's what I get for not checking the manual first. Thanks. I just made the correction and it now works great. Corrected version follows: ```MF = IF (N=1:FACT(X): IF (X<=N:X: SIGMA(K:1:IF (MOD(X:N):X/N:(X/N)+1):1: IF(K=1:0*L(M:X):0*L(X:X-N)+0*L(M:G(M)*X))) + G(M))) ``` Thanks, Bill Edited: 2 Mar 2007, 2:47 p.m.

Go back to the main exhibit hall