Pythagorean addition

From Wikipedia, the free encyclopedia
  (Redirected from )

In mathematics, Pythagorean addition is the following binary operation on the real numbers:

The name recalls the Pythagorean theorem, which states that the length of the hypotenuse of a right triangle is ab, where a and b are the lengths of the other sides.[1] In its applications to signal processing and propagation of measurement uncertainty, the same operation is also called addition in quadrature.[2]

This operation provides a simple notation and terminology when the summands are complicated; for example, the energy-momentum relation in physics becomes

It is implemented in many programming libraries as the hypot function, in a way designed to avoid errors arising due to limited-precision calculations performed on computers.

Applications[]

If measurements X, Y, Z, ... have independent errors ΔX, ΔY, ΔZ, ..., respectively, the quadrature method gives the overall error,

whereas the upper limit of the overall error is
if the errors were not independent.[3]

This is equivalent of finding the magnitude of the resultant of adding orthogonal vectors, each with magnitude equal to the uncertainty, using the Pythagorean theorem.

In signal processing, addition in quadrature is used to find the overall noise from independent sources of noise. For example, if an image sensor gives 6 digital numbers of shot noise, 3 of dark current noise and 2 of Johnson–Nyquist noise under a specific condition, the overall noise,

digital numbers,[4] showing the dominance of larger sources of noise.

Properties[]

The operation ⊕ is associative and commutative,[5] and

This is enough to form the real numbers into a commutative semigroup. However, ⊕ is not a group operation for the following reasons.

The only element which could potentially act as an identity element is 0, since an identity e must satisfy ee = e. This yields the equation , but if e is nonzero that implies , so e could only be zero. Unfortunately 0 does not work as an identity element after all, since 0⊕(−1) = 1. This does indicate, however, that if the operation ⊕ is restricted to nonnegative real numbers, then 0 does act as an identity. Consequently, the operation ⊕ acting on the nonnegative real numbers forms a commutative monoid.

Implementation[]

Hypot is a mathematical function defined to calculate the length of the hypotenuse of a right-angle triangle. It was designed to avoid errors arising due to limited-precision calculations performed on computers. Calculating the length of the hypotenuse of a triangle is possible using the square-root function on the sum of two squares, but hypot(xy) avoids problems that occur when squaring very large or very small numbers. If calculated using the natural formula,

the squares of very large or small values of x and y may exceed the range of machine precision when calculated on a computer, leading to an inaccurate result caused by arithmetic underflow and/or arithmetic overflow. The hypot function was designed to calculate the result without causing this problem.

The hypot function is often used together with the atan2 function to convert from Cartesian coordinates to polar coordinates:

r = hypot(xy),
θ = atan2(yx).

If either input is infinite, the result is infinite, i.e.

hypot(x, ±∞) = hypot(±∞, x) = +∞

Because this is true for all possible values of x, including infinity, the IEEE 754 floating-point standard requires that this definition also applies if x is not a number (NaN).[6]

Implementation[]

The difficulty with the naive implementation is that x2 or y2 may overflow or underflow, unless the intermediate result is computed with extended precision. A common implementation technique is to exchange the values, if necessary, so that |x| ≥ |y|, and then use the equivalent form[7]

The computation of y/x cannot overflow unless both x and y are 0. If y/x underflows, the final result is equal to |x|, which is correct within the precision of the calculation. The square root is computed of a value between 1 and 2. Finally, the multiplication by |x| cannot underflow, and overflows only when the result is too large to represent.

This implementation has the downside that it requires an additional floating-point division, which can double the cost of the naive implementation, as multiplication and addition are typically far faster than division and square root.

More complex implementations avoid this by dividing the inputs into more cases:

  • xy: hypot(x, y) = |x|, to within machine precision.
  • x2 overflows: Multiply both x and y by a small scaling factor (e.g. 2−64 for IEEE single precision), use the naive algorithm which will now not overflow, and multiply the result by the (large) inverse (e.g. 264).
  • y2 underflows: As above, but reverse the scaling factors to scale up the intermediate values.
  • Otherwise: The naive algorithm is safe to use.

Additional techniques allow the result to be computed more accurately, e.g. to less than one ulp.[8]

Programming language support[]

The function is present in several programming languages:

See also[]

References[]

  1. ^ Moler, Cleve; Morrison, Donald (1983). "Replacing square roots by Pythagorean sums". IBM Journal of Research and Development. 27 (6): 577–581. CiteSeerX 10.1.1.90.5651. doi:10.1147/rd.276.0577.
  2. ^ Johnson, David L. (2017). "12.2.3 Addition in Quadrature". Statistical Tools for the Comprehensive Practice of Industrial Hygiene and Environmental Health Sciences. John Wiley & Sons. p. 289. ISBN 9781119143017.
  3. ^ D.B. Schneider, Error Analysis in Measuring Systems, Proceedings of the 1962 Standards Laboratory Conference, page 94
  4. ^ J.T. Bushberg et al, The Essential Physics of Medical Imaging, section 10.2.7, Wolters Kluwer Health
  5. ^ Falmagne, Jean-Claude (2015). "Deriving meaningful scientific laws from abstract, "gedanken" type, axioms: five examples". Aequationes Mathematicae. 89 (2): 393–435. doi:10.1007/s00010-015-0339-1. MR 3340218. S2CID 121424613.
  6. ^ Fog, Agner (2020-04-27). "Floating point exception tracking and NAN propagation" (PDF). p. 6.
  7. ^ In some situations, last form reduces calculation errors (in ULPs).
  8. ^ Borges, Carlos F. (14 June 2019). "An Improved Algorithm for hypot(a,b)". arXiv:1904.09481 [math.NA].
  9. ^ Cimpanu, Catalin. "CSS to get support for trigonometry functions". ZDNet. Retrieved 2019-11-01.
  10. ^ "Hypot - C++ Reference".
  11. ^ "STD.math - D Programming Language".
  12. ^ "Mathematics · the Julia Language".
  13. ^ "Math — Mathematical functions — Python 3.9.7 documentation".
  14. ^ https://developer.apple.com/DOCUMENTATION/mac/PPCNumerics/PPCNumerics-141.html
  15. ^ "Square root of sum of squares (Hypotenuse) - MATLAB hypot - MathWorks Benelux".
  16. ^ "Hypot function".
  17. ^ "PHP: Hypot - Manual".
  18. ^ "Math (Java 2 Platform SE 5.0)".
  19. ^ "hypot - Kotlin Programming Language". Kotlin. Retrieved 2018-03-19.
  20. ^ "Module: Math (Ruby 3.0.2)".
  21. ^ "Math package - math - PKG.go.dev".
  22. ^ "F64 - Rust".
  23. ^ "Math.hypot() - JavaScript | MDN".
  24. ^ Single Unix Specification, Open Group, http://www.opengroup.org/onlinepubs/007908799/xsh/hypot.html
  25. ^ IBM, ILE C/C++ Run-Time Library Functions, http://publib.boulder.ibm.com/infocenter/iadthelp/v7r0/index.jsp?topic=/com.ibm.etools.iseries.langref.doc/rzan5mst144.htm
  26. ^ The GNU C Library, Mathematics, http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_17.html Archived 2009-03-05 at the Wayback Machine
  27. ^ "Scala Standard Library 2.13.6 - scala.math".

Further reading[]

Retrieved from ""