Rewriting a Difference of Nearly Equal Squares
Equivalent algebraic formulas can use different rounding paths. Factoring can avoid subtracting separately rounded large intermediate terms.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace the exact identity
For \(a,b\), \(a^2-b^2=(a-b)(a+b)\). With \(a=10001,b=10000\), both exact forms yield 20001. The factored form computes a small difference and a sum without first forming two squares. See cancellation and stable formulas.
Check what accuracy is possible
If stored inputs have already rounded to the same value, either computation can return zero. Formula changes cannot recover missing input precision. Conditioning separates input sensitivity from arithmetic behavior.[1][2]
Derive an equivalent expression that avoids squaring first
For \(a=10001,b=10000\), the exact difference \(a^2-b^2\) is 20001. The factorization \((a-b)(a+b)\) gets that result from the small exact difference one and sum 20001. At larger scales, rounding each squared value can discard information before subtraction. See intermediate rounding.
Direct: 100020001 − 100000000 = 20001
Factored: (10001−10000)(10001+10000) = 1×20001
Equal real expressions can incur different floating-point errors
Account for information already lost at input
If both rounded inputs have become the same floating-point value, factorization cannot restore their original difference. Compare against a higher-precision reference and test the scale where the inputs remain distinct.