Pythagorean addition

From Wikipedia, the free encyclopedia
(Redirected from Pythagorean sum)
Jump to navigation Jump to search

Template:Short description Script error: No such module "Unsubst". Template:Use list-defined references Template:CS1 config

File:Triangle Sides ABC.svg
The hypotenuse Template:Mvar of a right triangle with sides Template:Mvar and Template:Mvar is the Pythagorean sum of Template:Mvar and Template:Mvar.

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. Like the more familiar addition and multiplication operations of arithmetic, it is both associative and commutative.

This operation can be used in the conversion of Cartesian coordinates to polar coordinates, and in the calculation of Euclidean distance. It also provides a simple notation and terminology for the diameter of a cuboid, the energy-momentum relation in physics, and the overall noise from independent sources of noise. In its applications to signal processing and propagation of measurement uncertainty, the same operation is also called addition in quadrature.[1]Template:R/superscript A scaled version of this operation gives the quadratic mean or root mean square.

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. Donald Knuth has written that "Most of the square root operations in computer programs could probably be avoided if [Pythagorean addition] were more widely available, because people seem to want square roots primarily when they are computing distances."[2]Template:R/superscript

Definition

According to the Pythagorean theorem, for a right triangle with side lengths a and b, the length of the hypotenuse can be calculated as a2+b2. This formula defines the Pythagorean addition operation, denoted here as : for any two real numbers a and b, the result of this operation is defined to be[3]Template:R/superscript ab=a2+b2). For instance, the special right triangle based on the Pythagorean triple (3,4,5) gives 34=5.[4] However, the integer result of this example is unusual: for other integer arguments, Pythagorean addition can produce a quadratic irrational number as its result.[5]Template:R/superscript

Properties

The operation is associative[6]Template:R/superscript[7]Template:R/superscript and commutative.[6]Template:R/superscript[8]Template:R/superscript Therefore, if three or more numbers are to be combined with this operation, the order of combination makes no difference to the result: x1x2xn=x12+x22++xn2. Additionally, on the non-negative real numbers, zero is an identity element for Pythagorean addition. On numbers that can be negative, the Pythagorean sum with zero gives the absolute value:[3]Template:R/superscript x0=|x|. The three properties of associativity, commutativity, and having an identity element (on the non-negative numbers) are the defining properties of a commutative monoid.[9]Template:R/superscript[10]Template:R/superscript

Applications

Distance and diameter

File:Add in quadrature.svg
Pythagorean addition finds the length of the body diagonal of a rectangular cuboid, or equivalently the length of the vector sum of orthogonal vectors.

The Euclidean distance between two points in the Euclidean plane, given by their Cartesian coordinates (x1,y1) and (x2,y2), is[11]Template:R/superscript (x1x2)(y1y2). In the same way, the distance between three-dimensional points (x1,y1,z1) and (x2,y2,z2) can be found by repeated Pythagorean addition as[11]Template:R/superscript (x1x2)(y1y2)(z1z2).

Pythagorean addition can also find the length of an interior diagonal of a rectangle or rectangular cuboid. For a rectangle with sides a and b, the diagonal length is ab.[12]Template:R/superscript[13]Template:R/superscript For a cuboid with side lengths a, b, and c, the length of a body diagonal is abc.[13]Template:R/superscript

Coordinate conversion

Pythagorean addition (and its implementation as the hypot function) is often used together with the atan2 function (a two-parameter form of the arctangent) to convert from Cartesian coordinates (x,y) to polar coordinates (r,θ):[14]Template:R/superscript[15]Template:R/superscript r=xy=hypot(x,y)θ=atan2(y,x).

Quadratic mean and spread of deviation

The root mean square or quadratic mean of a finite set of n numbers is 1n times their Pythagorean sum. This is a generalized mean of the numbers.[16]Template:R/superscript

The standard deviation of a collection of observations is the quadratic mean of their individual deviations from the mean. When two or more independent random variables are added, the standard deviation of their sum is the Pythagorean sum of their standard deviations.[16]Template:R/superscript Thus, the Pythagorean sum itself can be interpreted as giving the amount of overall noise when combining independent sources of noise.[17]Template:R/superscript

If the engineering tolerances of different parts of an assembly are treated as independent noise, they can be combined using a Pythagorean sum.[18]Template:R/superscript In experimental sciences such as physics, addition in quadrature is often used to combine different sources of measurement uncertainty.[19]Template:R/superscript However, this method of propagation of uncertainty applies only when there is no correlation between sources of uncertainty,[20]Template:R/superscript and it has been criticized for conflating experimental noise with systematic errors.[21]Template:R/superscript

Other

File:Einstein-triangle-kinetic-energy.svg
The energy-momentum relation, visualized as a right triangle

The energy-momentum relation in physics, describing the energy of a moving particle, can be expressed as the Pythagorean sum E=mc2pc, where m is the rest mass of a particle, p is its momentum, c is the speed of light, and E is the particle's resulting relativistic energy.[22]Template:R/superscript

When combining signals, it can be a useful design technique to arrange for the combined signals to be orthogonal in polarization or phase, so that they add in quadrature.[23]Template:R/superscript[24]Template:R/superscript In early radio engineering, this idea was used to design directional antennas, allowing signals to be received while nullifying the interference from signals coming from other directions.[23]Template:R/superscript When the same technique is applied in software to obtain a directional signal from a radio or ultrasound phased array, Pythagorean addition may be used to combine the signals.[25]Template:R/superscript Other recent applications of this idea include improved efficiency in the frequency conversion of lasers.[24]Template:R/superscript

In the psychophysics of haptic perception, Pythagorean addition has been proposed as a model for the perceived intensity of vibration when two kinds of vibration are combined.[26]Template:R/superscript

In image processing, the Sobel operator for edge detection consists of a convolution step to determine the gradient of an image followed by a Pythagorean sum at each pixel to determine the magnitude of the gradient.[27]Template:R/superscript

Implementation

In a 1983 paper, Cleve Moler and Donald Morrison described an iterative method for computing Pythagorean sums, without taking square roots.[3]Template:R/superscript This was soon recognized to be an instance of Halley's method,[8]Template:R/superscript and extended to analogous operations on matrices.[7]Template:R/superscript

Although many modern implementations of this operation instead compute Pythagorean sums by reducing the problem to the square root function, they do so in a way that has been designed to avoid errors arising from the limited-precision calculations performed on computers. If calculated using the natural formula, r=x2+y2, the squares of very large or small values of x and y may exceed the range of machine precision when calculated on a computer. This may to an inaccurate result caused by arithmetic underflow and overflow, although when overflow and underflow do not occur the output is within two ulp of the exact result.[28]Template:R/superscript[29]Template:R/superscript[30]Template:R/superscript Common implementations of the hypot function rearrange this calculation in a way that avoids the problem of overflow and underflow and are even more precise.[31]Template:R/superscript

If either input to hypot 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).[32]Template:R/superscript

Calculation order

The difficulty with the naive implementation is that x2+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 to use the equivalent form r=|x|1+(yx)2.

The computation of y/x cannot overflow unless both x and y are zero. 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.[31]Template:R/superscript

One drawback of this rearrangement is the additional division by x, which increases both the time and inaccuracy of the computation. More complex implementations avoid these costs by dividing the inputs into more cases:

  • When x is much larger than y, xy|x|, to within machine precision.
  • When 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).
  • When y2 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 than the naive algorithm, e.g. to less than one ulp.[31]Template:R/superscript Researchers have also developed analogous algorithms for computing Pythagorean sums of more than two values.[33]Template:R/superscript

Fast approximation

The alpha max plus beta min algorithm is a high-speed approximation of Pythagorean addition using only comparison, multiplication, and addition, producing a value whose error is less than 4% of the correct result. It is computed as abαmax(a,b)+βmin(a,b) for a careful choice of parameters α and β.[34]Template:R/superscript

Programming language support

Pythagorean addition function is present as the hypot function in many programming languages and their libraries. These include: CSS,[35]Template:R/superscript D,[36]Template:R/superscript Fortran,[37]Template:R/superscript Go,[38]Template:R/superscript JavaScript (since ES2015),[11]Template:R/superscript Julia,[39]Template:R/superscript MATLAB,[40]Template:R/superscript PHP,[41]Template:R/superscript and Python.[42]Template:R/superscript C++11 includes a two-argument version of hypot, and a three-argument version for xyz has been included since C++17.[43]Template:R/superscript The Java implementation of hypot[44]Template:R/superscript can be used by its interoperable JVM-based languages including Apache Groovy, Clojure, Kotlin, and Scala.[45]Template:R/superscript Similarly, the version of hypot included with Ruby extends to Ruby-based domain-specific languages such as Progress Chef.[46]Template:R/superscript In Rust, hypot is implemented as a method of floating point objects rather than as a two-argument function.[47]Template:R/superscript

Metafont has Pythagorean addition and subtraction as built-in operations, under the symbols ++ and +-+ respectively.[2]Template:R/superscript

History

The Pythagorean theorem on which this operation is based was studied in ancient Greek mathematics, and may have been known earlier in Egyptian mathematics and Babylonian mathematics; see Template:Slink.[48]Template:R/superscript However, its use for computing distances in Cartesian coordinates could not come until after René Descartes invented these coordinates in 1637; the formula for distance from these coordinates was published by Alexis Clairaut in 1731.Template:Sfnp

The terms "Pythagorean addition" and "Pythagorean sum" for this operation have been used at least since the 1950s,[18]Template:R/superscript[49]Template:R/superscript and its use in signal processing as "addition in quadrature" goes back at least to 1919.[23]Template:R/superscript

From the 1920s to the 1940s, before the widespread use of computers, multiple designers of slide rules included square-root scales in their devices, allowing Pythagorean sums to be calculated mechanically.[50]Template:R/superscript[51]Template:R/superscript[52]Template:R/superscript Researchers have also investigated analog circuits for approximating the value of Pythagorean sums.[53]Template:R/superscript

References

<templatestyles src="Reflist/styles.css" />

  1. Script error: No such module "citation/CS1".
  2. a b Script error: No such module "citation/CS1".
  3. a b c Script error: No such module "Citation/CS1".
  4. This example is from Script error: No such module "Footnotes".. Script error: No such module "Footnotes". uses two more integer Pythagorean triples, (119,120,169) and (19,180,181), as examples.
  5. Script error: No such module "Citation/CS1".
  6. a b Script error: No such module "Citation/CS1".
  7. a b Script error: No such module "Citation/CS1".
  8. a b Script error: No such module "Citation/CS1".
  9. Script error: No such module "citation/CS1".
  10. Script error: No such module "citation/CS1".
  11. a b c Script error: No such module "citation/CS1".
  12. Script error: No such module "citation/CS1".
  13. a b Script error: No such module "citation/CS1".
  14. Script error: No such module "citation/CS1".
  15. Script error: No such module "citation/CS1".
  16. a b Script error: No such module "citation/CS1".
  17. D. B. Schneider, Error Analysis in Measuring Systems, Proceedings of the 1962 Standards Laboratory Conference, page 94
  18. a b Script error: No such module "Citation/CS1".
  19. Script error: No such module "citation/CS1".
  20. Script error: No such module "citation/CS1".
  21. Script error: No such module "citation/CS1".
  22. Script error: No such module "citation/CS1".
  23. a b c Script error: No such module "Citation/CS1". See p. 232.
  24. a b Script error: No such module "Citation/CS1".
  25. Script error: No such module "citation/CS1".
  26. Script error: No such module "Citation/CS1".
  27. Script error: No such module "Citation/CS1".
  28. Script error: No such module "citation/CS1".
  29. Script error: No such module "citation/CS1".
  30. Script error: No such module "Citation/CS1".
  31. a b c Script error: No such module "Citation/CS1".
  32. Script error: No such module "citation/CS1".
  33. Script error: No such module "citation/CS1".
  34. Script error: No such module "citation/CS1".
  35. Script error: No such module "citation/CS1".
  36. Script error: No such module "citation/CS1".
  37. Script error: No such module "citation/CS1".
  38. Script error: No such module "citation/CS1".
  39. Script error: No such module "citation/CS1".
  40. Script error: No such module "citation/CS1".
  41. Script error: No such module "citation/CS1".
  42. Script error: No such module "citation/CS1".
  43. Script error: No such module "citation/CS1".
  44. Script error: No such module "citation/CS1".
  45. Script error: No such module "citation/CS1".
  46. Script error: No such module "citation/CS1".
  47. Script error: No such module "citation/CS1".
  48. Script error: No such module "citation/CS1".
  49. Script error: No such module "Citation/CS1".
  50. Script error: No such module "Citation/CS1".
  51. Script error: No such module "Citation/CS1".
  52. Script error: No such module "Citation/CS1".
  53. Script error: No such module "Citation/CS1".

Script error: No such module "Check for unknown parameters".