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.

Like the more familiar addition and multiplication operations of arithmetic, it is both associative and commutative.

In its applications to signal processing and propagation of measurement uncertainty, the same operation is also called addition in quadrature.

[1] 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.

This formula defines the Pythagorean addition operation, denoted here as

For instance, the special right triangle based on the Pythagorean triple

On numbers that can be negative, the Pythagorean sum with zero gives the absolute value:[3]

Repeated Pythagorean addition can also find the diagonal length of a rectangle and the diameter of a rectangular cuboid.

[17] If the engineering tolerances of different parts of an assembly are treated as independent noise, they can be combined using a Pythagorean sum.

[18] In experimental sciences such as physics, addition in quadrature is often used to combine different sources of measurement uncertainty.

[21] The energy-momentum relation in physics, describing the energy of a moving particle, can be expressed as the Pythagorean sum

[23][24] 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.

[25] Other recent applications of this idea include improved efficiency in the frequency conversion of lasers.

[26] 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] In a 1983 paper, Cleve Moler and Donald Morrison described an iterative method for computing Pythagorean sums, without taking square roots.

[3] This was soon recognized to be an instance of Halley's method,[8] and extended to analogous operations on matrices.

[7] 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.

[28][29][30] 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.

may overflow or underflow, unless the intermediate result is computed with extended precision.

More complex implementations avoid these costs by dividing the inputs into more cases: Additional techniques allow the result to be computed more accurately than the naive algorithm, e.g. to less than one ulp.

[31] Researchers have also developed analogous algorithms for computing Pythagorean sums of more than two values.

[33] 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.

[43] The Java implementation of hypot[44] can be used by its interoperable JVM-based languages including Apache Groovy, Clojure, Kotlin, and Scala.

[45] Similarly, the version of hypot included with Ruby extends to Ruby-based domain-specific languages such as Progress Chef.

[46] In Rust, hypot is implemented as a method of floating point objects rather than as a two-argument function.

[47] Metafont has Pythagorean addition and subtraction as built-in operations, under the symbols ++ and +-+ respectively.

[23] 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.

[51][52][53] Researchers have also investigated analog circuits for approximating the value of Pythagorean sums.

The hypotenuse c of a right triangle with sides a and b is the Pythagorean sum of a and b .
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 energy-momentum relation , visualized as a right triangle