(SQRT 0 1i ) ^2

General discussion about calculators, SwissMicros or otherwise
User avatar
48GX
Posts: 180
Joined: Wed May 20, 2020 4:37 am

(SQRT 0 1i ) ^2

Post by 48GX »

My son is now using a DM42 full-time. He put the 48GX down a few months ago. A big step for an eighth grader.

He brought to my attention tonight that taking the square root of <0 1i> and then squaring it does not give <0 1i> as the answer. <-2E-34 1i>. The HP42S and the 48GX give <0 1i>.

Is this a known thing?
Waiting for SM to release DM42 hardware with one additional row of keys.
DM42, DB48X, DM32, HP42s, DM41X, HP35s, DM41L
Raising a next generation RPN/RPL user.
User avatar
rudi
Posts: 415
Joined: Wed Nov 03, 2021 9:03 am
Location: Denmark
Contact:

Re: (SQRT 0 1i ) ^2

Post by rudi »

I wouldn't worry too much, 2e-34 is pretty much zero for most applications.

And at least, 0.5 SQRT X↑2 yields 0.5 in ALL mode.
But take a look with the SHOW, and it's actually 4.999999999999999999999999999999999e-1
4 suceeded by 33 nines. So the 2e-34 above is simply showing you the accuracy of the DM42 I guess ;-)

In the Free42, Thomas Okken could perhaps decide to loose the last significant digit, and round all results to 33 digits?
But I think that would be a shame, I like all 34 digits ;-)
/Rudi

DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
User avatar
Walter
Posts: 3070
Joined: Tue May 02, 2017 11:13 am
Location: On a mission close to DRS, Germany

Re: (SQRT 0 1i ) ^2

Post by Walter »

48GX wrote:
Tue Jun 21, 2022 3:31 am
... the square root of <0 1i> and then squaring it does not give <0 1i> as the answer. <-2E-34 1i>. The HP42S and the 48GX give <0 1i>.

Is this a known thing?
This is known and rises every once and a while.

Explanation:
Calculators calculate with a finite number of digits. So even 1/3 doesn't really equal 1/3 in any calculator exactly but only (!) 0.333333333333333333333333333 (stopping after a finite number of threes). Hence, 3 x 1/3 results in 0.999999999999999999999 or alike. Now, it depends on the number of digits indicated vs. the number of digits calculated what will happen: if the latter is greater than the first, you can use the extra digits for rounding.

Example:
0.+i×1. SQRT ENTER × returns 0.+i×1. displayed on the WP43S.
Actually, this is 0. + ix0.999 999 999 999 999 999 999 999 999 999 999 9, however, and I know there are 5 digits more under the hood.

As Rudi stated, a relative error of 10^(-34) is irrelevant for all real-world calculations.
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
J-F Garnier
Posts: 47
Joined: Sun Mar 11, 2018 5:37 pm
Location: France

Re: (SQRT 0 1i ) ^2

Post by J-F Garnier »

48GX wrote:
Tue Jun 21, 2022 3:31 am
... taking the square root of <0 1i> and then squaring it does not give <0 1i> as the answer. <-2E-34 1i>.
Nice finding ! This is a minor Free42 accuracy flaw:

Doing SQRT( 0+1i ) is giving:
0.7071067811865475244008443621048490 +
0.7071067811865475244008443621048491 i

Since the real and imag parts are not equal (as they should be), squaring back this number doesn't give exactly 0 for the real part.
The HP42S and the 48GX give <0 1i>.
Some technical background: HP calculators are using degrees (not radians) to convert complex numbers to polar form, for internal operations.
This ensures better results in many cases (like this one).

Edited: my comment just above is not relevant for that particular case.
Here is an example of a similar accuracy flaw on the HP-42S:
SQRT (0 + 0.4652 i) gives:
0.482286222071 +
0.482286222072 i
and squaring it back gives: -9.65E-13 + 0.4652 i

J-F
User avatar
48GX
Posts: 180
Joined: Wed May 20, 2020 4:37 am

Re: (SQRT 0 1i ) ^2

Post by 48GX »

Thank you all for the generous responses. We assumed it was something like this because of the other little things we have caught. There is little boy big on math and RPN reading the responses with much glee this evening.

He has a love for complex numbers to boot.
Waiting for SM to release DM42 hardware with one additional row of keys.
DM42, DB48X, DM32, HP42s, DM41X, HP35s, DM41L
Raising a next generation RPN/RPL user.
Thomas Okken
Posts: 1100
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: (SQRT 0 1i ) ^2

Post by Thomas Okken »

J-F Garnier wrote:
Tue Jun 21, 2022 9:25 am
Nice finding ! This is a minor Free42 accuracy flaw:

Doing SQRT( 0+1i ) is giving:
0.7071067811865475244008443621048490 +
0.7071067811865475244008443621048491 i

Since the real and imag parts are not equal (as they should be), squaring back this number doesn't give exactly 0 for the real part.
Indeed! Complex sqrt is missing special cases for pure real and pure imaginary arguments. That's an oversight.
User avatar
Brianetta
Posts: 23
Joined: Sat Apr 23, 2022 10:00 pm
Location: United Kingdom

Re: (SQRT 0 1i ) ^2

Post by Brianetta »

Taking the square root of a 15 digit integer, then squaring the result, will usually show a loss of precision.
🖩 DM16L, DM42
User avatar
rudi
Posts: 415
Joined: Wed Nov 03, 2021 9:03 am
Location: Denmark
Contact:

Re: (SQRT 0 1i ) ^2

Post by rudi »

My DM42 handles SQRT of an large integer rather fine, no rounding errors in the below, which results in zero.
Try pressing SHOW after entering the 34 digit integer, all digits are there, even though the DM42 displays 1,23456789012E33 in ALL mode.

Code: Select all

1234567890123456789012345678901234
ENTER
SQRT
X^2
-
/Rudi

DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
User avatar
Walter
Posts: 3070
Joined: Tue May 02, 2017 11:13 am
Location: On a mission close to DRS, Germany

Re: (SQRT 0 1i ) ^2

Post by Walter »

My WP43S can handle the square root of a 83-digit integer without any losses. Maybe it works for even longer integers as well but I can't prove it there. 8-)
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
J-F Garnier
Posts: 47
Joined: Sun Mar 11, 2018 5:37 pm
Location: France

Re: (SQRT 0 1i ) ^2

Post by J-F Garnier »

rudi wrote:
Wed Jun 22, 2022 10:10 am
My DM42 handles SQRT of an large integer rather fine, no rounding errors in the below, which results in zero.
Try pressing SHOW after entering the 34 digit integer, all digits are there, even though the DM42 displays 1,23456789012E33 in ALL mode.

Code: Select all

1234567890123456789012345678901234
ENTER
SQRT
X^2
-
A simple counter-example:
3E32 SQRT X^2 -> 299999999999999999999999999999999.9
No bug here, it's just due to the finite representation of SQRT(3E32) with 34 digits.
This is machine-dependent, the usual well-known example on HP Saturn machines is SQRT(2) instead of SQRT(3).

J-F
Post Reply