Post Reply 
Error with exp function and imaginary numbers
07-27-2020, 10:08 AM
Post: #1
Error with exp function and imaginary numbers
I have encountered an error, which perhaps detects a bug in HP PRIME G2 (hardware). For example, if I do this calculation with the virtual calculator: "exp (-10^49-10^49*i)", I rightly get zero. If, however, I perform the same operation with my HP PRIME G2 (i.e. hardware version with firmware 20200121), an error is displayed: +Inf. Maybe this depends on the fact that, for my G2 calculator, in "CAS" the operation "exp (-10^49-10^49*i)" is interpreted as "exp (+/- Inf)", which for the calculator corresponds to an undefined value. Is there anyone who, having an HP PRIME G2, can check if the problem is common or depends only on my calculator?

Thanks a lot, Roberto Mioni
Find all posts by this user
Quote this message in a reply
07-27-2020, 01:13 PM
Post: #2
RE: Error with exp function and imaginary numbers
This error, found on the G2, is not of little importance. For example, if I want to calculate the first-kind Bessel-function, BesseJ(n, z) with Arg(z) <Pi / 2, with complex variable "z", I am forced to integrate an exponential from zero to infinity. The error in question prevents me from calculating the integral by "romberg" HP PRIME function.

int(exp(-(2+3*i)*sinh(t)-2.5*t),t,o,+inf) --> 0.152804387425-9.90045195322E-2*i (on virtual PRIME)

int(exp(-(2+3*i)*sinh(t)-2.5*t),t,o,+inf) --> undef-undef*i (on "hardware" G2 PRIME)

I cordially greet, Roberto
Find all posts by this user
Quote this message in a reply
07-28-2020, 01:03 PM
Post: #3
RE: Error with exp function and imaginary numbers
Another error related to the exp() function with imaginary numbers is the inability, by utilizing my HP PRIME G2 calculator, to perform the following operation, which in mathematical terms relates to the exponential function: cos(-1E49) -> 0.70354916584 (virtual calculator), cos(-1E49) -> + Inf (HP PRIME G2 "hardware").
Could anyone point me to a website that lists HP PRIME (also G2) bugs?
Find all posts by this user
Quote this message in a reply
07-28-2020, 02:48 PM
Post: #4
RE: Error with exp function and imaginary numbers
Hi, robmio

What do you get for exp(-1e49) ?
If result underflowed to 0, the bug might be the cos/sin part

exp(-1e49 - 1e49*i)
= exp(-1e49) * exp(-1e49*i)
= 10 ^ (-1e49/ln(10)) * (cos(-1e49) + i * sin(-1e49))


BTW, cos(-1e49) required more digits of pi than HP Prime provided

cos(-1e49 mod (2 pi)) ≈ cos(2.736405887658145) ≈ -0.919028791855494
Find all posts by this user
Quote this message in a reply
07-28-2020, 03:51 PM
Post: #5
RE: Error with exp function and imaginary numbers
Thank you very much for your reply, Albert Chan.
The error is related to the sin and cos functions. Using your example, in "CAS" mode my HP PRIME G2 (firmware 20200121) gives the following result:

cos(-1e49 mod (2 * Pi)) --> 5.26072423308e214

evidently incorrect result, since the cosine of a real variable returns numbers between -1 and 1. The bug is evident only in the HP PRIME G2 calculator (the "physical" version, so to speak, with firmware 20200121) and only in "CAS" mode.
It seems that with the G1-version of HP PRIME the error is not present (see Major's reply)!
Find all posts by this user
Quote this message in a reply
07-28-2020, 05:54 PM
Post: #6
RE: Error with exp function and imaginary numbers
For comparison, I get the following results with HP 50g:

EXP(-1E49) 0.
COS(-1E49) .814097070848


With LongFloat, 50 digits precision:

EXP(-1E49) 0.
COS(-1E49) -.9190287918554938...


Interesting that the 50g gives an erroneous answer for COS but a different one than the Prime.
Find all posts by this user
Quote this message in a reply
07-28-2020, 07:10 PM
Post: #7
RE: Error with exp function and imaginary numbers
The question is another. I wrote a program that calculates the "Bessel function of the first kind Jn (z)", with n ∈ R and "z" ∈ C and with Arg (z <Pi / 2). Below the program:

#cas
//BesselJ_Gen(n,z) Jn(z) n∈ℝ z∈ℂ
//φ, ARG(z), di z < π/2
BesselJ_Gen(n,z):=
BEGIN
LOCAL funzione;
IF ARG(z)<π/2 THEN
funzione:=1/π*int(cos(z*sin(t)-n*t),t,0,π)-sin(n*π)/π*int(e^((−z)*sinh(t)-n*t),t,0,∞);
RETURN approx(funzione);
ELSE
RETURN "Error: ARG(z)≥π/2";
END;
END;
#end

The program does not work with the HP PRIME G2 probably due to an error attributable to the sine and cosine functions or to an error attributable to the complex exponential. In particular, in the calculation of the "Bessel function of the first kind Jn (z)", with n = 2.5, z = -2-3*i, the calculator must integrate the following function: exp((- 2-3*i)*SINH(x)+2.5*x) from zero to infinity. For an error related to the computation of the complex exponential (or for an error related to the sine and the cosine functions that derive from it), this function cannot be integrated by the "romberg" command in the range from zero to infinity.

The virtual HP PRIME calculator, on the other hand, runs the program quickly and correctly (the results have been compared with Wolfram Mathematica).[/php]
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)