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
a
b
⊕
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 becomesIt 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; it is related to the quadratic mean or "root mean square".
(x,y)
(r,\theta)
If measurements
X,Y,Z,...
\DeltaX,\DeltaY,\DeltaZ,...
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 two of Johnson–Nyquist noise under a specific condition, the overall noise isdigital numbers, showing the dominance of larger sources of noise.
The root mean square of a finite set of
n
\sqrtn
The operation
⊕
⊕
The real numbers under
⊕
⊕
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. If calculated using the natural formula,the squares of very large or small values of
x
y
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).
Since C++17, there has been an additional hypot function for 3D calculations:[1]
The difficulty with the naive implementation is that
x2+y2
|x|\ge|y|
The computation of
y/x
x
y
y/x
|x|
|x|
More complex implementations avoid this by dividing the inputs into more cases:
x
y
x ⊕ y ≈ |x|
x2
x
y
y2
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.
The function is present in many programming languages and libraries, includingCSS,C++11,D,Fortran (since Fortran 2008),Go,JavaScript (since ES2015),Julia,Java (since version 1.5),Kotlin,MATLAB,PHP,Python,Ruby,Rust,and Scala.
++
and +-+
respectively.