HP Forums
HP prime: derivatives - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: HP prime: derivatives (/thread-257267.html)

HP prime: derivatives - Alberto Candel - 11-28-2013


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.

Re: HP prime: derivatives - Dieter - 11-28-2013

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.

Re: HP prime: derivatives - Alberto Candel - 11-28-2013

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

I obtain (if not mistaken)

Re: HP prime: derivatives - Dieter - 11-28-2013

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.

Re: HP prime: derivatives - Alberto Candel - 11-28-2013

Ah! Thank you for the clarification.
But then

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

It may be something with xcas algorithms for derivatives.

Re: HP prime: derivatives - Tim Wessman - 11-28-2013


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.

Re: HP prime: derivatives - parisse - 11-29-2013

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 - Alberto Candel - 11-29-2013

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 - Dieter - 11-29-2013

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.

Re: HP prime: derivatives - Alberto Candel - 11-29-2013

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?