Pythagorean addition
   HOME

TheInfoList



OR:

In mathematics, Pythagorean addition is a binary operation on the
real number In mathematics, a real number is a number that can be used to measure a ''continuous'' one-dimensional quantity such as a distance, duration or temperature. Here, ''continuous'' means that values can have arbitrarily small variations. Every ...
s that computes the length of the
hypotenuse In geometry, a hypotenuse is the longest side of a right-angled triangle, the side opposite the right angle. The length of the hypotenuse can be found using the Pythagorean theorem, which states that the square of the length of the hypotenuse e ...
of a
right triangle A right triangle (American English) or right-angled triangle ( British), or more formally an orthogonal triangle, formerly called a rectangled triangle ( grc, ὀρθόσγωνία, lit=upright angle), is a triangle in which one angle is a right a ...
, given its two sides. According to the Pythagorean theorem, for a
triangle A triangle is a polygon with three edges and three vertices. It is one of the basic shapes in geometry. A triangle with vertices ''A'', ''B'', and ''C'' is denoted \triangle ABC. In Euclidean geometry, any three points, when non- colline ...
with sides a and b, this length can be calculated as a \oplus b = \sqrt, where \oplus denotes the Pythagorean addition operation. This operation can be used in the conversion of Cartesian coordinates to
polar coordinates In mathematics, the polar coordinate system is a two-dimensional coordinate system in which each point on a plane is determined by a distance from a reference point and an angle from a reference direction. The reference point (analogous to th ...
. It also provides a simple notation and terminology for some formulas when its summands are complicated; for example, the energy-momentum relation in
physics Physics is the natural science that studies matter, its fundamental constituents, its motion and behavior through space and time, and the related entities of energy and force. "Physical science is that department of knowledge which r ...
becomes E = mc^2 \oplus pc. 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 Signal processing is an electrical engineering subfield that focuses on analyzing, modifying and synthesizing ''signals'', such as sound, images, and scientific measurements. Signal processing techniques are used to optimize transmissions, ...
and
propagation Propagation can refer to: * Chain propagation in a chemical reaction mechanism *Crack propagation, the growth of a crack during the fracture of materials * Propaganda, non-objective information used to further an agenda * Reproduction, and other fo ...
of measurement uncertainty, the same operation is also called addition in quadrature.


Applications

Pythagorean addition (and its implementation as the hypot function) is often used together with the atan2 function to convert from Cartesian coordinates (x,y) to
polar coordinates In mathematics, the polar coordinate system is a two-dimensional coordinate system in which each point on a plane is determined by a distance from a reference point and an angle from a reference direction. The reference point (analogous to th ...
(r,\theta): \begin r&=x\oplus y=\operatorname(x,y)\\ \theta&=\operatorname(y,x).\\ \end If measurements X,Y,Z,\dots have independent errors \Delta_X, \Delta_Y, \Delta_Z, \dots respectively, the quadrature method gives the overall error, \varDelta_o = \sqrt whereas the upper limit of the overall error is \varDelta_u = \varDelta_X + \varDelta_Y + \varDelta_Z + \cdots if the errors were not independent. This is equivalent of finding the
magnitude Magnitude may refer to: Mathematics *Euclidean vector, a quantity defined by both its magnitude and its direction *Magnitude (mathematics), the relative size of an object *Norm (mathematics), a term for the size or length of a vector *Order of ...
of the resultant of adding
orthogonal vectors In mathematics, an inner product space (or, rarely, a Hausdorff pre-Hilbert space) is a real vector space or a complex vector space with an operation called an inner product. The inner product of two vectors in the space is a scalar, often de ...
, 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 An image sensor or imager is a sensor that detects and conveys information used to make an image. It does so by converting the variable attenuation of light waves (as they pass through or reflect off objects) into signals, small bursts of c ...
gives six digital numbers of shot noise, three of dark current noise and two of
Johnson–Nyquist noise Johnson–Nyquist noise (thermal noise, Johnson noise, or Nyquist noise) is the electronic noise generated by the thermal agitation of the charge carriers (usually the electrons) inside an electrical conductor at equilibrium, which happens reg ...
under a specific condition, the overall noise is \sigma = 6 \oplus 3 \oplus 2 = \sqrt = 7 digital numbers, showing the dominance of larger sources of noise.


Properties

The operation \oplus is associative and
commutative In mathematics, a binary operation is commutative if changing the order of the operands does not change the result. It is a fundamental property of many binary operations, and many mathematical proofs depend on it. Most familiar as the name of ...
, and \sqrt = x_1 \oplus x_2 \oplus \cdots \oplus x_n. This means that the real numbers under \oplus form a commutative semigroup. The real numbers under \oplus are not a
group A group is a number of persons or things that are located, gathered, or classed together. Groups of people * Cultural group, a group whose members share the same cultural identity * Ethnic group, a group whose members share the same ethnic ide ...
, because \oplus 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 In mathematics, an identity element, or neutral element, of a binary operation operating on a set is an element of the set that leaves unchanged every element of the set when the operation is applied. This concept is used in algebraic structures su ...
. 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 In mathematics, the concept of an inverse element generalises the concepts of opposite () and reciprocal () of numbers. Given an operation denoted here , and an identity element denoted , if , one says that is a left inverse of , and that is ...
. Instead, it forms a
commutative monoid In abstract algebra, a branch of mathematics, a monoid is a set equipped with an associative binary operation and an identity element. For example, the nonnegative integers with addition form a monoid, the identity element being 0. Monoids ar ...
on the non-negative numbers, with zero as its identity.


Implementation

Hypot is a mathematical function defined to calculate the length of the
hypotenuse In geometry, a hypotenuse is the longest side of a right-angled triangle, the side opposite the right angle. The length of the hypotenuse can be found using the Pythagorean theorem, which states that the square of the length of the hypotenuse e ...
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 In mathematics, a square root of a number is a number such that ; in other words, a number whose ''square'' (the result of multiplying the number by itself, or  ⋅ ) is . For example, 4 and −4 are square roots of 16, because . ...
function on the sum of two
squares In Euclidean geometry, a square is a regular quadrilateral, which means that it has four equal sides and four equal angles (90- degree angles, π/2 radian angles, or right angles). It can also be defined as a rectangle with two equal-length a ...
, but hypot avoids problems that occur when squaring very large or very small numbers. If calculated using the natural formula, r = \sqrt, the squares of very large or small values of x and y may exceed the range of
machine precision Machine epsilon or machine precision is an upper bound on the relative approximation error due to rounding in floating point arithmetic. This value characterizes computer arithmetic in the field of numerical analysis, and by extension in the subj ...
when calculated on a computer, leading to an inaccurate result caused by
arithmetic underflow The term arithmetic underflow (also floating point underflow, or just underflow) is a condition in a computer program where the result of a calculation is a number of more precise absolute value than the computer can actually represent in memory ...
and/or overflow. The hypot function was designed to calculate the result without causing this problem. 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: r = \sqrt.


Calculation order

The difficulty with the naive implementation is that x^2+y^2 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, \ge, y, , and then to use the equivalent form \begin r &= \sqrt \\ &= \sqrt \\ &= , x, \sqrt \left(= , x, + \frac\frac\right)\!. \end 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. 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.Measured on ARM and x64 (Intel and AMD) for different compilers with maximum optimization for 32 bit and 64 bit floats. More complex implementations avoid this by dividing the inputs into more cases: * When x is much larger than y, x\oplus y\approx, x, , to within
machine precision Machine epsilon or machine precision is an upper bound on the relative approximation error due to rounding in floating point arithmetic. This value characterizes computer arithmetic in the field of numerical analysis, and by extension in the subj ...
. * When x^2 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 y^2 underflows, scale as above but reverse the scaling factors to scale up the intermediate values. * Otherwise, the naive algorithm is safe to use. 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.


Programming language support

The function is present in many
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
s and libraries, including CSS,
C++11 C++11 is a version of the ISO/ IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versions b ...
, D, Go,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
(since ES2015),
Julia Julia is usually a feminine given name. It is a Latinate feminine form of the name Julio and Julius. (For further details on etymology, see the Wiktionary entry "Julius".) The given name ''Julia'' had been in use throughout Late Antiquity (e.g ...
,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mos ...
(since version 1.5), Kotlin,
MATLAB MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementa ...
,
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group. ...
,
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called ...
,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO( ...
, and Scala.


See also

*
Euclidean distance In mathematics, the Euclidean distance between two points in Euclidean space is the length of a line segment between the two points. It can be calculated from the Cartesian coordinates of the points using the Pythagorean theorem, therefor ...
* Alpha max plus beta min algorithm * Metafont has Pythagorean addition and subtraction as built-in operations, under the names ++ and +-+ respectively.


References


Further reading

*{{cite journal , first=Augustin A. , last=Dubrulle , title=A class of numerical methods for the computation of Pythagorean sums , journal=IBM Journal of Research and Development , volume=27 , issue=6 , pages=582–589 , year=1983 , url=http://www.research.ibm.com/journal/rd/276/ibmrd2706Q.pdf , doi=10.1147/rd.276.0582 , citeseerx = 10.1.1.94.3443 . Operations on numbers Addition Numerical analysis Articles with example pseudocode