# Large Floating Point Numbers

10 views

### Dima

Jan 31, 2010, 4:54:54 PM1/31/10
to
I defined a function for calculating probabilities of Poisson
distribution. When I try to calculate probability for large numbers
using floating point format I get incorrect results. The file with
screenshots is here: http://pics.livejournal.com/iosaaris/pic/0004w4hk.jpg

The upper left screen shows how the function Poi() was defined. One
below shows the calculation of Poi(300, 200). At first it is
calculated symbolically and then the result is converted to floating
point number. In this case the result is correct. My TI-89 gives the
same result (two screenshots at right).

When I try to calculate the same function using floating point numbers
as input (lower left screen) I get significantly different result.

What is the problem or what am I doing incorrectly?

And one more question. When working in ALG mode with symbolic
expressions, is it there any way to get them simplified upon every
press of ENTER like TI-89 does? For example I enter:
X+5
then
ANS(1)^2-1
and I get
(X+5)^2-1
If I want to simplify it, I have to select it with arrows and press
ENTER again. How can I get it simplified when I enter ANS(1)^2-1
without pressing ENTER once more?

### Virgil

Jan 31, 2010, 7:11:52 PM1/31/10
to
In article
Dima <iosa...@gmail.com> wrote:

In the RPN mode, all you have to do is press the EVAL key.

You might try that in ALG mode and see what happens.

### Dave Hayden

Feb 1, 2010, 10:56:01 AM2/1/10
to
On Jan 31, 4:54 pm, Dima <iosaa...@gmail.com> wrote:
> I defined a function for calculating probabilities of Poisson
> distribution. When I try to calculate probability for large numbers
> using floating point format I get incorrect results. The file with
> screenshots is here:http://pics.livejournal.com/iosaaris/pic/0004w4hk.jpg
>
> The upper left screen shows how the function Poi() was defined. One
> below shows the calculation of Poi(300, 200). At first it is
> calculated symbolically and then the result is converted to floating
> point number. In this case the result is correct. My TI-89 gives the
> same result (two screenshots at right).
>
> When I try to calculate the same function using floating point numbers
> as input (lower left screen) I get significantly different result.
>
> What is the problem or what am I doing incorrectly?

Floating point numbers on the HP can't go higher than 10^499. In
addition, they are limited to 12 significant digits. You're computing
Poi(y,k) = e^(-y)*y^k/k!. So Poi(300,200) = e^-300 * 300^200/200!.
300^200 and 200! are far beyond the limits floating point numbers.

This is a very old problem with computers. The trick is to change the
order of evaluation. Instead of evaluating 300^200 and dividing by
200!, you need to evaluate (300/200)*(300/199)*(300/198)*...(300/2)*
(300/1). Sorry, I don't have the time right now to figure out exactly
how to do this.

It's too bad that HP doesn't supply a LNFACT() function where LNFACT
(x) = ln(x!). This is pretty easy to compute from ln(gamma(x)) which
can be computed directly. If you had LNFACT() then ln(POI(y,k)) = -y
+k*ln(y)-LNFACT(k), which are all reasonably sized numbers that can be
represented in the calculator. So POI(y,k) = e^(-y+k*ln(y)-LNFACT(k))

Dave

### mjc

Feb 1, 2010, 4:10:10 PM2/1/10
to

I have been saying for YEARS that the HP calculators need a lngamma
function.

An easy way to do it yourself in user RPL would be to use ln(gamma(x))
for 0 < x < 100 or so,
and use Stirlings apporximation for larger x.

You can use Lanczos' approximation for all complex values with
positive imaginary part,
but it is more complicated.

Martin Cohen

### data...@gmail.com

Feb 3, 2010, 3:17:08 PM2/3/10
to

then scroll down to message #6. I posted a LogGamma and LambertW for
the 50g. They are written in C with a library front end. The memory
used in the 50g is on the order of bytes. The C programs will need to
be installed on the SD card. Complex values supported.

### Simone...@gmail.com

Feb 4, 2010, 4:42:09 AM2/4/10
to
Il 03/02/2010 21.17, data...@gmail.com ha scritto:
>
> then scroll down to message #6. I posted a LogGamma and LambertW for
> the 50g. They are written in C with a library front end. The memory
> used in the 50g is on the order of bytes. The C programs will need to
> be installed on the SD card. Complex values supported.

There is no special.zip in http://sense.net/~egan/hpgcc/misc/ !

### data...@gmail.com

Feb 4, 2010, 11:58:28 AM2/4/10
to
On Feb 4, 2:42 am, Simone.Cer...@gmail.com wrote:
> Il 03/02/2010 21.17, dataj...@gmail.com ha scritto:
>
>
>

> > then scroll down to message #6.  I posted a LogGamma and LambertW for
> > the 50g.  They are written in C with a library front end.  The memory
> > used in the 50g is on the order of bytes.  The C programs will need to
> > be installed on the SD card.  Complex values supported.
>
> There is no special.zip inhttp://sense.net/~egan/hpgcc/misc/!

Yikes! Thanks. Fixed now. I broke the link with some house cleaning.

### supergems

Feb 4, 2010, 12:28:27 PM2/4/10
to
On 4 Feb, 17:58, "dataj...@gmail.com" <dataj...@gmail.com> wrote:
> Yikes!  Thanks.  Fixed now.  I broke the link with some house cleaning.

Thank you for HPGCC tutorial LambertW and LogGamma :-) .

Best regards,
Simone.