HP prime: derivatives



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


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.


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


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


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

I obtain (if not mistaken)


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

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.


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


Ah! Thank you for the clarification.
But then

results in
h'(0)=+/- inf

It may be something with xcas algorithms for derivatives.



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


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


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).


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.


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.


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


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?

Possibly Related Threads…
Thread Author Replies Views Last Post
  HP 35s derivatives/extremums Richard Berler 16 4,456 09-14-2013, 04:55 PM
Last Post: Matt Agajanian
  Derivation of (HP) Derivatives... Matt Agajanian 6 2,165 05-25-2012, 09:46 PM
Last Post: Crawl
  derivatives and indefinate integrals JeffG 3 1,182 03-15-2002, 10:23 AM
Last Post: Thibaut.be
  38G Derivatives and Integrals Brandon 0 818 10-15-1999, 11:24 PM
Last Post: Brandon

Forum Jump: