HP-71B Enhanced Math LEX
01-27-2020, 11:35 AM (This post was last modified: 01-27-2020 12:38 PM by Albert Chan.)
Post: #16
 Albert Chan Senior Member Posts: 2,100 Joined: Jul 2018
RE: HP-71B Enhanced Math LEX
(01-27-2020 08:05 AM)J-F Garnier Wrote:  I understand that the alternate formula (x+y)*(x-y) saves a multiplication, but does it guarantee that the result will be *always* better?

Yes, I believe (x*x-y*y) is better calculated as (x+y)*(x-y)

|x| + |y| always accurate to whatever the system precision (unless it overflows)
|x| − |y| is exact if ratio of |x| and |y| = 1/2 to 2. (unless it underflows)
(see Kahans Miscalculating Area and Angles of a Needle-like Triangle, Section 4, Why Cancellation Cannot Hurt)

Below code searched bad REPT(Z*Z), for X = 0.1 to 1/3, 1 ≤ Y/X < 2
Code:
10 COMPLEX Z,Z1,Z2 20 X=.1+7/30*RND @ Y=X+RND*X @ Z=(X,Y) 30 Z1=Z*Z @ Z2=Z^(2,0) @ R=(X+Y)*(X-Y) 40 IF Z1=Z2 OR REPT(Z1)=R THEN 20 60 DISP "Z=";Z 70 DISP "Z*Z=";Z1 80 DISP "Z^2=";Z2 90 DISP "OK =";(R,2*X*Y)

>RANDOMIZE 1
>RUN
Z= (.235285090644,.236095767159)
Z*Z= (-3.82137391042E-4,.111099627953)
Z^2= (-3.82137391039E-4,.111099627953)
OK ﻿ = (-3.82137391041E-4,.111099627953)
>RUN
Z= (.180255457178,.190657390504)
Z*Z= (-3.85821071135E-3,6.87340701793E-2)
Z^2= (-3.85821071134E-3,6.87340701793E-2)
OK ﻿ = (-3.85821071134E-3,6.87340701793E-2)
>RUN
Z= (.1084548287,.127000096548)
Z*Z= (-4.36657465486E-3,.027547547432)
Z^2= (-4.36657465485E-3,.027547547432)
OK ﻿ = (-4.36657465485E-3,.027547547432)

Error (both Z*Z and Z^2) increases if |X| ≈ |Y|. After more runs, we have:

>SCI 12
>RUN
Z= (1.27043248466E-1 ,1.27045908048E-1)
Z*Z= (-6.75770947000E-7, 3.22806497255E-2)
Z^2= (-6.75770946606E-7, 3.22806497255E-2)
OK ﻿ = (-6.75770947060E-7, 3.22806497255E-2)
 « Next Oldest | Next Newest »

 Messages In This Thread HP-71B Enhanced Math LEX - J-F Garnier - 01-09-2020, 07:30 PM RE: HP-71B Enhanced Math LEX - rprosperi - 01-09-2020, 10:36 PM RE: HP-71B Enhanced Math LEX - Valentin Albillo - 01-10-2020, 12:00 AM RE: HP-71B Enhanced Math LEX - charger73 - 01-10-2020, 07:23 AM RE: HP-71B Enhanced Math LEX - Raymond Del Tondo - 01-10-2020, 08:58 AM RE: HP-71B Enhanced Math LEX - Sylvain Cote - 01-10-2020, 04:16 PM RE: HP-71B Enhanced Math LEX - Albert Chan - 01-10-2020, 04:44 PM RE: HP-71B Enhanced Math LEX - Albert Chan - 01-10-2020, 05:01 PM RE: HP-71B Enhanced Math LEX - J-F Garnier - 01-10-2020, 05:40 PM RE: HP-71B Enhanced Math LEX - Albert Chan - 01-10-2020, 06:29 PM RE: HP-71B Enhanced Math LEX - Erwin - 01-13-2020, 06:10 PM RE: HP-71B Enhanced Math LEX - J-F Garnier - 01-13-2020, 07:13 PM RE: HP-71B Enhanced Math LEX - J-F Garnier - 01-26-2020, 10:54 AM RE: HP-71B Enhanced Math LEX - Albert Chan - 01-26-2020, 03:08 PM RE: HP-71B Enhanced Math LEX - J-F Garnier - 01-27-2020, 08:05 AM RE: HP-71B Enhanced Math LEX - Albert Chan - 01-27-2020 11:35 AM RE: HP-71B Enhanced Math LEX - J-F Garnier - 01-27-2020, 12:42 PM RE: HP-71B Enhanced Math LEX - J-F Garnier - 02-12-2020, 07:55 AM RE: HP-71B Enhanced Math LEX - rprosperi - 02-12-2020, 01:55 PM RE: HP-71B Enhanced Math LEX - J-F Garnier - 02-14-2020, 12:23 PM RE: HP-71B Enhanced Math LEX - rprosperi - 02-14-2020, 03:04 PM RE: HP-71B Enhanced Math LEX - J-F Garnier - 03-19-2020, 07:30 PM RE: HP-71B Enhanced Math LEX - J-F Garnier - 04-27-2020, 09:42 AM RE: HP-71B Enhanced Math LEX - Erwin - 04-27-2020, 04:50 PM RE: HP-71B Enhanced Math LEX - Albert Chan - 03-17-2021, 09:00 PM RE: HP-71B Enhanced Math LEX - J-F Garnier - 03-18-2021, 08:22 AM RE: HP-71B Enhanced Math LEX - J-F Garnier - 08-08-2020, 09:37 AM RE: HP-71B Enhanced Math LEX - Valentin Albillo - 08-08-2020, 10:14 PM RE: HP-71B Enhanced Math LEX - Paul Dale - 08-09-2020, 11:15 AM RE: HP-71B Enhanced Math LEX - John Keith - 08-09-2020, 02:16 PM RE: HP-71B Enhanced Math LEX - Valentin Albillo - 08-09-2020, 03:49 PM RE: HP-71B Enhanced Math LEX - Erwin - 08-10-2020, 08:21 PM RE: HP-71B Enhanced Math LEX - rprosperi - 08-10-2020, 09:42 PM RE: HP-71B Enhanced Math LEX - Erwin - 08-11-2020, 02:47 PM RE: HP-71B Enhanced Math LEX - Dave Frederickson - 08-11-2020, 04:24 PM RE: HP-71B Enhanced Math LEX - Erwin - 08-11-2020, 05:06 PM RE: HP-71B Enhanced Math LEX - Gene - 08-09-2020, 01:49 AM RE: HP-71B Enhanced Math LEX - Paul Dale - 08-09-2020, 10:10 AM RE: HP-71B Enhanced Math LEX - John Keith - 08-09-2020, 01:04 PM RE: HP-71B Enhanced Math LEX - Dave Frederickson - 08-11-2020, 05:17 PM RE: HP-71B Enhanced Math LEX - Erwin - 08-13-2020, 07:35 AM RE: HP-71B Enhanced Math LEX - Dave Frederickson - 08-13-2020, 03:27 PM RE: HP-71B Enhanced Math LEX - Erwin - 08-13-2020, 04:00 PM RE: HP-71B Enhanced Math LEX - J-F Garnier - 08-14-2020, 07:53 AM RE: HP-71B Enhanced Math LEX - Dave Frederickson - 08-14-2020, 09:06 PM RE: HP-71B Enhanced Math LEX - Erwin - 08-20-2020, 08:11 PM RE: HP-71B Enhanced Math LEX - Dave Frederickson - 08-20-2020, 08:34 PM RE: HP-71B Enhanced Math LEX - Erwin - 08-21-2020, 05:34 PM RE: HP-71B Enhanced Math LEX - J-F Garnier - 09-27-2020, 06:25 PM RE: HP-71B Enhanced Math LEX - Dave Frederickson - 09-27-2020, 06:52 PM

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