Which function is more accurate?

  • Thread starter Thread starter blalien
  • Start date Start date
  • Tags Tags
    Function
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
blalien
Messages
31
Reaction score
0

Homework Statement


You have a number system in base 10 with a precision of 5 digits. Which function is more accurate: x^2-y^2 or (x-y)(x+y)?

Homework Equations


None really.

The Attempt at a Solution


My intuition would tell me that (x-y)(x+y) is more accurate, since multiplication is less accurate than addition or subtraction (unless the two numbers are very close). But look at x = 1.0000, y = 0.00001:

Actual value: 0.999999999

x^2 = 1, y^2 = 1e-10 ~ 0
x^2-y^2=1

x-y = 0.99999
x+y = 1.00001 ~ 1
(x-y)(x+y) = 0.99999

So x^2-y^2 is more accurate, at least in this situation. I have no idea why, though.
 
Physics news on Phys.org
blalien said:
So x^2-y^2 is more accurate, at least in this situation. I have no idea why, though.
Which class is this for? If it's a programming class/computer architecture class/etc. the answer probably has to do with floating point errors and accumulated rounding errors.