The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

HP prime: derivatives
Message #1 Posted by Alberto Candel on 28 Nov 2013, 12:33 p.m.

Hi

Being a holiday here, I had some extra time to play with this instrument.

Here is an issue with how the prime handles derivatives of functions that I do not comprehend. Maybe there is documentation in xcas about it, but ....

I define a function

b(x):=IFTE(x=0,1,x/(exp(x)-1)

This is a nice function that has a power series around 0 whose coefficients are the Bernoulli number B(n) divided by n!

So the derivative b'(0)=-1/2, but the HP prime computes b'(0)=+/- inf.

I cannot figure out how it does that. Thanks!

Edited: 28 Nov 2013, 12:58 p.m.

      
Re: HP prime: derivatives
Message #2 Posted by Dieter on 28 Nov 2013, 1:06 p.m.,
in response to message #1 by Alberto Candel

What happens if you use the more exact and dedicated ex-1 command in the denominator, i.e. EXPM1(x) ?

Dieter

Edited: 28 Nov 2013, 1:09 p.m.

            
Re: HP prime: derivatives
Message #3 Posted by Alberto Candel on 28 Nov 2013, 1:29 p.m.,
in response to message #2 by Dieter

Thanks, I did not know about EXPM1. But if I set

 h(x):=IFTE(x=0,1,x/(EXPM1(x)-1)) 
I obtain (if not mistaken)
h'(0)=-1
                  
Re: HP prime: derivatives
Message #4 Posted by Dieter on 28 Nov 2013, 1:37 p.m.,
in response to message #3 by Alberto Candel

Alberto, EXPM1(x) already subtracts 1. That's why it says M1 (minus one). You must not add another subtraction. ;-)

  h(x):=IFTE(x=0,1,x/EXPM1(x)) 
Compare the results of EXP(x) - 1 with those obtained by using EXPM1(x) for some x close to zero, and you will see why this special command exists.

Dieter

Edited: 28 Nov 2013, 1:40 p.m.

                        
Re: HP prime: derivatives
Message #5 Posted by Alberto Candel on 28 Nov 2013, 1:54 p.m.,
in response to message #4 by Dieter

Ah! Thank you for the clarification. But then

 h(x):=IFTE(x=0,1,x/EXPM1(x))
results in
h'(0)=+/- inf

It may be something with xcas algorithms for derivatives.

                              
Re: HP prime: derivatives
Message #6 Posted by Tim Wessman on 28 Nov 2013, 2:15 p.m.,
in response to message #5 by Alberto Candel

Dunno.

However, you can natively do piecewise functions. I'd use that instead. I suspect that will be easier.

TW

Edited: 28 Nov 2013, 2:15 p.m.

                                    
Re: HP prime: derivatives
Message #7 Posted by parisse on 29 Nov 2013, 7:05 a.m.,
in response to message #6 by Tim Wessman

There is a bug that I'm fixing in the source code, infinity-undef should return undef, not infinity, hence you should have undef as result. You must use limit to find the derivative at a singular point, if you simply evaluate, then x is replaced by 0 in the analytic expression of the derivative (which does not take care of an ifte defined only for one point).

                                          
Re: HP prime: derivatives
Message #8 Posted by Alberto Candel on 29 Nov 2013, 12:02 p.m.,
in response to message #7 by parisse

OK, thanks.

BTW, what is the real difference between exp(x)-1 and EXPM1(x)? The example given in the Help of the prime is EXPM1(0.23) and this is the same as exp(0.23)-1 for the Prime. But even much smaller numbers like x=0.00001 lead to the same result.

                                                
Re: HP prime: derivatives
Message #9 Posted by Dieter on 29 Nov 2013, 3:14 p.m.,
in response to message #8 by Alberto Candel

EXPM1(x) is far more accurate as x approaches zero. Consider a small x-value like 1E-12. With 12-digit accuracy, EXP(x) is evaluated as excactly 1, so EXP(x)-1 becomes zero due to roundoff.

Here EXPM1(x) comes to rescue. It is evaluated differently so that the result is exact. Here are some results for 12 digit working precision:

  x       EXP(x)          EXP(x)-1            EXPM1(x)
---------------------------------------------------------------
 0,23     1,25860000993   0,25860000993       0,258600009929
 0,0022   1,00220242178   2,20242178000 E-3   2,20242177564 E-3
 1 E-5    1,00001000005   1,00000500000 E-5   1,00000500002 E-5
1/9 E-7   1,00000001111   1,11110000000 E-8   1,11111111728 E-8
1/7 E-9   1,00000000014   1,40000000000 E-10  1,42857142867 E-10
1/6 E-11  1,00000000000   0,00000000000       1,66666666667 E-12
So EXPM1(x) (and also its inverse function LNP1(x) = ln(1+x)) allow exact results where their conventional counterparts would return inexact or even useless results. There are extremely useful in many everyday applications.

Dieter

Edited: 29 Nov 2013, 3:17 p.m.

                                                      
Re: HP prime: derivatives
Message #10 Posted by Alberto Candel on 29 Nov 2013, 6:45 p.m.,
in response to message #9 by Dieter

Thank you again, Dieter. The example EXPM1(0.23) given in Help is very misleading. Are there any references to how these functions are evaluated?


[ Return to Index | Top of Index ]

Go back to the main exhibit hall