The Museum of HP Calculators

HP Forum Archive 15

[ Return to Index | Top of Index ]

GAMMA and BETA on the 17BII+
Message #1 Posted by Bob Wang on 5 June 2005, 10:57 p.m.

One very annoying feature of the 17BII+ is that at some point in length of programs, the Solver just returns 0. A straight forward example can be seen using Viktor T. Toth's Calculators and the Gamma Function:

GAMMA:
(75122.6331530+80916.6278952×Z+36308.2951477×Z^2+8687.24529705×Z^3
+1168.92649479×Z^4+83.8676043424×Z^5+2.50662827511×Z^6)
÷Z÷(Z+1)÷(Z+2)÷(Z+3)÷(Z+4)÷(Z+5)÷(Z+6)
×(Z+5.5)^(Z+.5)×EXP(-(Z+5.5))
-GAMMA

Calculated GAMMA Values 1 1.0000000001 2 1 3 2 4 6.0000000002 5 23.9999999999 6 120 7 720 8 5,039.99999998 9 40,320 10 362,880

BETA: 0×L(R:P+Q-1)×L(A:75122.6331530)×L(B:80916.6278952)×L(C:36308.2951477) ×L(D:8687.24529705)×L(E:1168.92649479)×L(F:83.8676043424)×L(G:2.50662827511) +(G(A)+G(B)×P+G(C)×P^2+G(D)×P^3+G(E)×P^4+G(F)×P^5+G(G)×P^6) ÷P÷(P+1)÷(P+2)÷(P+3)÷(P+4)÷(P+5)÷(P+6) ×(P+5.5)^(P+.5)×EXP(-(P+5.5)) ×(G(A)+G(B)×Q+G(C)×Q^2+G(D)×Q^3+G(E)×Q^4+G(F)×Q^5+G(G)×Q^6) ÷Q÷(Q+1)÷(Q+2)÷(Q+3)÷(Q+4)÷(Q+5)÷(Q+6) ×(Q+5.5)^(Q+.5)×EXP(-(Q+5.5)) ÷(G(A)+G(B)×G(R)+G(C)×G(R)^2+G(D)×G(R)^3+G(E)×G(R)^4+G(F)×G(R)^5+G(G)×G(R)^6) ×G(R)×(G(R)+1)×(G(R)+2)×(G(R)+3)×(G(R)+4)×(G(R)+5)×(G(R)+6) ÷((G(R)+5.5)^(G(R)+.5))÷EXP(-(G(R)+5.5)) -BETA

p = 4, q = 5, Exact beta = 1÷35 = .028571428571 Calculated beta = .0285714273948 (15 seconds on 19B) Error = 1.177E-9

beta = 0 on the 17BII+

Bob

P.S. Of course, in defense of the 17BII+, one could ask "WHY would ANYONE need these on a financial calculator?" ;-)

      
Re: GAMMA and BETA on the 17BII+
Message #2 Posted by tony on 6 June 2005, 3:06 a.m.,
in response to message #1 by Bob Wang

Hi Bob,

You can more than halve the size of your GAMMA and BETA Solver equations by using the *original* Lanczos formula given in Victor's article, rather than the form given as suitable for programmable calculators.

Use a SUM list called GAMP, comprising the P1-P6 factors:

Item   Value
1      76.1800917295
2     -86.5053203294
3      24.0140982408
4     -1.23173957245
5      1.20865097387E-3
6     -5.39523938495E-6
Note the GAMP list totals 12.4583333242. Hopefully these equations will work in the 17BII+ Solver:

GAMMA:
SQRT(2*PI)/Z*(Z+5.5)^(Z+.5)/EXP(Z+5.5)
*(1+19E-11+SIGMA(N:1:6:1:ITEM(GAMP:N)/(Z+N)))
-GAMMA

BETA: SQRT(2*PI)*(P+Q)/P/Q*EXP(-5.5) *(P+5.5)^(P+.5)*(Q+5.5)^(Q+.5)/(P+Q+5.5)^(P+Q+.5) *(1+19E-11+SIGMA(N:1:6:1:ITEM(GAMP:N)/(P+N))) *(1+19E-11+SIGMA(N:1:6:1:ITEM(GAMP:N)/(Q+N))) /(1+19E-11+SIGMA(N:1:6:1:ITEM(GAMP:N)/(P+Q+N))) -BETA

The 1+19E-11=1.00000000019 - the Lanczos P0. Note, BETA(4,5)=3!*4!/8!=1/280. The HP19BII solves BETA(4,5) in 4 seconds, giving 3.57142857143E-3 (exact), so it works a lot faster for the shorter formula.

Cheers, Tony

            
Re: GAMMA and BETA on the 17BII+
Message #3 Posted by Bob Wang on 6 June 2005, 12:55 p.m.,
in response to message #2 by tony

The following GAMMA and BETA functions are based on Tony Hutchins' excellent suggestions.

Smaller, faster, AND more accurate!

Who says there's no free lunch.

Use a SUM list called GAMP, comprising the P1-P6 factors:

Item Value 1 76.1800917295 2 -86.5053203294 3 24.0140982408 4 -1.23173957245 5 1.20865097387E-3 6 -5.39523938495E-6

Note the GAMP list totals 12.4583333242.

GAMMA: SQRT(2×PI)÷Z×(Z+5.5)^(Z+.5)÷EXP(Z+5.5) ×(1+19E-11+SIGMA(N:1:6:1:ITEM(GAMP:N)÷(Z+N))) -GAMMA

Calculated GAMMA Values (17BII+) 1 1.0000000001 2 .999999999986 3 2 4 5.99999999998 5 23.9999999999 6 120 7 720.000000002 8 5,039.99999999 9 40,319.9999999 10 362,880.000001

BETA: SQRT(2×PI)×(P+Q)÷P÷Q×EXP(-5.5) ×(P+5.5)^(P+.5)×(Q+5.5)^(Q+.5)÷(P+Q+5.5)^(P+Q+.5) ×(1+19E-11+SIGMA(N:1:6:1:ITEM(GAMP:N)÷(P+N))) ×(1+19E-11+SIGMA(N:1:6:1:ITEM(GAMP:N)÷(Q+N))) ÷(1+19E-11+SIGMA(N:1:6:1:ITEM(GAMP:N)÷(P+Q+N))) -BETA

p = 4 q = 5

Exact Beta = 3!×4!÷8! = 1÷280 Exact Beta = 0.00357142857142857 Calculated = 0.00357142857143 (2.8 seconds on 17BII+) Error = 0

Bob


[ Return to Index | Top of Index ]

Go back to the main exhibit hall