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
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] it is related to the quadratic mean or "root mean square".
Repeated Pythagorean addition can find the diameter of a rectangular cuboid.
This is the longest distance between two points, the length of the body diagonal of the cuboid.
digital numbers,[6] showing the dominance of larger sources of noise.
The root mean square of a finite set of
can never produce a negative number as its result, whereas each element of a group must be the result of applying the group operation to itself and the identity element.
Instead, it forms a commutative monoid on the non-negative numbers, with zero as its identity.
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 avoids problems that occur when squaring very large or very small numbers.
the squares of very large or small values of
may exceed the range of machine precision when calculated on a computer, leading to an inaccurate result caused by arithmetic underflow and overflow.
The hypot function was designed to calculate the result without causing this problem.
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).
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
underflows, the final result is equal to
The square root is computed of a value between 1 and 2.
cannot underflow, and overflows only when the result is too large to represent.
[8] 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.
Typically, the implementation is slower by a factor of 2.5 to 3.
[11] More complex implementations avoid this by dividing the inputs into more cases: However, this implementation is extremely slow when it causes incorrect jump predictions due to different cases.
Additional techniques allow the result to be computed more accurately, e.g. to less than one ulp.
[8] Pythagorean addition function is present as the hypot function in many programming languages and libraries, including
Python,[23] Ruby,[24] Rust,[25] and Scala.
[26] Metafont has Pythagorean addition and subtraction as built-in operations, under the names ++ and +-+ respectively.