Pythagorean addition

In mathematics, Pythagorean addition is a binary operation on the real numbers that computes the length of the hypotenuse of a right triangle, given its two sides. According to the Pythagorean theorem, for a triangle with sides and , this length can be calculated as

where denotes the Pythagorean addition operation.[1]

This operation can be used in the conversion of Cartesian coordinates to polar coordinates. It also provides a simple notation and terminology for some formulas when its 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. In its applications to signal processing and propagation of measurement uncertainty, the same operation is also called addition in quadrature.[2]

ApplicationsEdit

Pythagorean addition (and its implementation as the hypot function) is often used together with the atan2 function to convert from Cartesian coordinates   to polar coordinates  :[3][4]

 

If measurements   have independent errors   respectively, the quadrature method gives the overall error,

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

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 six digital numbers of shot noise, three of dark current noise and twp of Johnson–Nyquist noise under a specific condition, the overall noise is

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

PropertiesEdit

The operation   is associative and commutative,[7] and

 
This is enough to form the real numbers under   into a commutative semigroup.

The real numbers under   are not a group, because   can never produce a negative number as its result, whereas each element of a group must be the result of multiplication of itself by the identity element. On the non-negative numbers, it is still not a group, because Pythagorean addition of one number by a second positive number can only increase the first number, so no positive number can have an inverse element. Instead, it forms a commutative monoid on the non-negative numbers, with zero as its identity.

ImplementationEdit

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.

If either input is infinite, the result is infinite. Because this is true for all possible values of the other input, the IEEE 754 floating-point standard requires that this remains true even when the other input is not a number (NaN).[8]

Calculation orderEdit

The difficulty with the naive implementation is that   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  , and then to use the equivalent form

 

The computation of   cannot overflow unless both   and   are zero. If   underflows, the final result is equal to  , 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   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:

  • When   is much larger than  ,  , to within machine precision.
  • When   overflows, multiply both   and   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).
  • When   underflows, scale 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.[9]

Programming language supportEdit

The function is present in many programming languages and libraries, including CSS,[10]C++11,[11]D,[12]Go,[13]JavaScript (since ES2015),[14]Julia,[15]Java (since version 1.5),[16]Kotlin,[17]MATLAB,[18]PHP,[19]Python,[20]Ruby,[21]Rust,[22] and Scala.[23]

See alsoEdit

ReferencesEdit

  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. ^ "SIN (3M): Trigonometric functions and their inverses". Unix Programmer's Manual: Reference Guide (4.3 Berkeley Software Distribution Virtual VAX-11 Version ed.). Department of Electrical Engineering and Computer Science, University of California, Berkeley. April 1986.
  4. ^ Beebe, Nelson H. F. (2017). The Mathematical-Function Computation Handbook: Programming Using the MathCW Portable Software Library. Springer. p. 70. ISBN 9783319641102.
  5. ^ D.B. Schneider, Error Analysis in Measuring Systems, Proceedings of the 1962 Standards Laboratory Conference, page 94
  6. ^ J.T. Bushberg et al, The Essential Physics of Medical Imaging, section 10.2.7, Wolters Kluwer Health
  7. ^ 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.
  8. ^ Fog, Agner (2020-04-27). "Floating point exception tracking and NAN propagation" (PDF). p. 6.
  9. ^ Borges, Carlos F. (14 June 2019). "An Improved Algorithm for hypot(a,b)". arXiv:1904.09481 [math.NA].
  10. ^ Cimpanu, Catalin. "CSS to get support for trigonometry functions". ZDNet. Retrieved 2019-11-01.
  11. ^ "Hypot - C++ Reference".
  12. ^ "STD.math - D Programming Language".
  13. ^ "Math package - math - PKG.go.dev".
  14. ^ "Math.hypot() - JavaScript | MDN".
  15. ^ "Mathematics · the Julia Language".
  16. ^ "Math (Java 2 Platform SE 5.0)".
  17. ^ "hypot - Kotlin Programming Language". Kotlin. Retrieved 2018-03-19.
  18. ^ "Square root of sum of squares (Hypotenuse) - MATLAB hypot - MathWorks Benelux".
  19. ^ "PHP: Hypot - Manual".
  20. ^ "Math — Mathematical functions — Python 3.9.7 documentation".
  21. ^ "Module: Math (Ruby 3.0.2)".
  22. ^ "F64 - Rust".
  23. ^ "Scala Standard Library 2.13.6 - scala.math".

Further readingEdit