# Square root

In mathematics, a **square root** of a number *x* is a number *y* such that *y*^{2} = *x*; in other words, a number *y* whose *square* (the result of multiplying the number by itself, or *y* ⋅ *y*) is *x*.^{[1]} For example, 4 and −4 are square roots of 16, because 4^{2} = (−4)^{2} = 16.

Square roots of negative numbers can be discussed within the framework of complex numbers. More generally, square roots can be considered in any context in which a notion of the "square" of a mathematical object is defined. These include function spaces and square matrices, among other mathematical structures.

The Rhind Mathematical Papyrus is a copy from 1650 BC of an earlier Berlin Papyrus and other texts – possibly the Kahun Papyrus – that shows how the Egyptians extracted square roots by an inverse proportion method.^{[6]}

In Ancient India, the knowledge of theoretical and applied aspects of square and square root was at least as old as the *Sulba Sutras*, dated around 800–500 BC (possibly much earlier).^{[citation needed]} A method for finding very good approximations to the square roots of 2 and 3 are given in the *Baudhayana Sulba Sutra*.^{[7]} Aryabhata, in the *Aryabhatiya* (section 2.4), has given a method for finding the square root of numbers having many digits.

It was known to the ancient Greeks that square roots of positive integers that are not perfect squares are always irrational numbers: numbers not expressible as a ratio of two integers (that is, they cannot be written exactly as *m/n*, where *m* and *n* are integers). This is the theorem *Euclid X, 9*, almost certainly due to Theaetetus dating back to circa 380 BC.^{[8]}
The particular case of the square root of 2 is assumed to date back earlier to the Pythagoreans, and is traditionally attributed to Hippasus.^{[citation needed]} It is exactly the length of the diagonal of a square with side length 1.

In the Chinese mathematical work *Writings on Reckoning*, written between 202 BC and 186 BC during the early Han Dynasty, the square root is approximated by using an "excess and deficiency" method, which says to "...combine the excess and deficiency as the divisor; (taking) the deficiency numerator multiplied by the excess denominator and the excess numerator times the deficiency denominator, combine them as the dividend."^{[9]}

A symbol for square roots, written as an elaborate R, was invented by Regiomontanus (1436–1476). An R was also used for radix to indicate square roots in Gerolamo Cardano's *Ars Magna*.^{[10]}

According to historian of mathematics D.E. Smith, Aryabhata's method for finding the square root was first introduced in Europe by Cataneo—in 1546.

According to Jeffrey A. Oaks, Arabs used the letter *jīm/ĝīm* (ج), the first letter of the word "جذر" (variously transliterated as *jaḏr*, *jiḏr*, *ǧaḏr* or *ǧiḏr*, "root"), placed in its initial form (ﺟ) over a number to indicate its square root. The letter *jīm* resembles the present square root shape. Its usage goes as far as the end of the twelfth century in the works of the Moroccan mathematician Ibn al-Yasamin.^{[11]}

The symbol "√" for the square root was first used in print in 1525, in Christoph Rudolff's *Coss*.^{[12]}

The square root of *x* is rational if and only if *x* is a rational number that can be represented as a ratio of two perfect squares. (See square root of 2 for proofs that this is an irrational number, and quadratic irrational for a proof for all non-square natural numbers.) The square root function maps rational numbers into algebraic numbers, the latter being a superset of the rational numbers).

The square root function is continuous for all nonnegative *x*, and differentiable for all positive *x*. If *f* denotes the square root function, whose derivative is given by:

The square root of a nonnegative number is used in the definition of Euclidean norm (and distance), as well as in generalizations such as Hilbert spaces. It defines an important concept of standard deviation used in probability theory and statistics. It has a major use in the formula for roots of a quadratic equation; quadratic fields and rings of quadratic integers, which are based on square roots, are important in algebra and have uses in geometry. Square roots frequently appear in mathematical formulas elsewhere, as well as in many physical laws.

A positive number has two square roots, one positive, and one negative, which are opposite to each other. When talking of *the* square root of a positive integer, it is usually the positive square root that is meant.

The square roots of an integer are algebraic integers—more specifically quadratic integers.

The square roots of the perfect squares (e.g., 0, 1, 4, 9, 16) are integers. In all other cases, the square roots of positive integers are irrational numbers, and hence have non-repeating decimals in their decimal representations. Decimal approximations of the square roots of the first few natural numbers are given in the following table.

As with before, the square roots of the perfect squares (e.g., 0, 1, 4, 9, 16) are integers. In all other cases, the square roots of positive integers are irrational numbers, and therefore have non-repeating digits in any standard positional notation system.

The square roots of small integers are used in both the SHA-1 and SHA-2 hash function designs to provide nothing up my sleeve numbers.

One of the most intriguing results from the study of irrational numbers as continued fractions was obtained by Joseph Louis Lagrange c. 1780. Lagrange found that the representation of the square root of any non-square positive integer as a continued fraction is periodic. That is, a certain pattern of partial denominators repeats indefinitely in the continued fraction. In a sense these square roots are the very simplest irrational numbers, because they can be represented with a simple repeating pattern of integers.

The square bracket notation used above is a short form for a continued fraction. Written in the more suggestive algebraic form, the simple continued fraction for the square root of 11, [3; 3, 6, 3, 6, ...], looks like this:

Square roots of positive numbers are not in general rational numbers, and so cannot be written as a terminating or recurring decimal expression. Therefore in general any attempt to compute a square root expressed in decimal form can only yield an approximation, though a sequence of increasingly accurate approximations can be obtained.

Most pocket calculators have a square root key. Computer spreadsheets and other software are also frequently used to calculate square roots. Pocket calculators typically implement efficient routines, such as the Newton's method (frequently with an initial guess of 1), to compute the square root of a positive real number.^{[13]}^{[14]} When computing square roots with logarithm tables or slide rules, one can exploit the identities

as it allows one to adjust the estimate *x* by some amount *c* and measure the square of the adjustment in terms of the original estimate and its square. Furthermore, (*x* + *c*)^{2} ≈ *x*^{2} + 2*xc* when *c* is close to 0, because the tangent line to the graph of *x*^{2} + 2*xc* + *c*^{2} at *c* = 0, as a function of *c* alone, is *y* = 2*xc* + *x*^{2}. Thus, small adjustments to *x* can be planned out by setting 2*xc* to *a*, or *c* = *a*/(2*x*).

The most common iterative method of square root calculation by hand is known as the "Babylonian method" or "Heron's method" after the first-century Greek philosopher Heron of Alexandria, who first described it.^{[16]}
The method uses the same iterative scheme as the Newton–Raphson method yields when applied to the function y = *f*(*x*) = *x*^{2} − *a*, using the fact that its slope at any point is *dy*/*dx* = *f′*(*x*) = 2*x*, but predates it by many centuries.^{[17]}
The algorithm is to repeat a simple calculation that results in a number closer to the actual square root each time it is repeated with its result as the new input. The motivation is that if *x* is an overestimate to the square root of a nonnegative real number *a* then *a*/*x* will be an underestimate and so the average of these two numbers is a better approximation than either of them. However, the inequality of arithmetic and geometric means shows this average is always an overestimate of the square root (as noted below), and so it can serve as a new overestimate with which to repeat the process, which converges as a consequence of the successive overestimates and underestimates being closer to each other after each iteration. To find *x*:

the computation of the square root of a positive number can be reduced to that of a number in the range [1,4). This simplifies finding a start value for the iterative method that is close to the square root, for which a polynomial or piecewise-linear approximation can be used.

The time complexity for computing a square root with *n* digits of precision is equivalent to that of multiplying two *n*-digit numbers.

Another useful method for calculating the square root is the shifting nth root algorithm, applied for *n* = 2.

The name of the square root function varies from programming language to programming language, with `sqrt`

^{[18]} (often pronounced "squirt" ^{[19]}) being common, used in C, C++, and derived languages like JavaScript, PHP, and Python.

The square of any positive or negative number is positive, and the square of 0 is 0. Therefore, no negative number can have a real square root. However, it is possible to work with a more inclusive set of numbers, called the complex numbers, that does contain solutions to the square root of a negative number. This is done by introducing a new number, denoted by *i* (sometimes *j*, especially in the context of electricity where "*i*" traditionally represents electric current) and called the imaginary unit, which is *defined* such that *i*^{2} = −1. Using this notation, we can think of *i* as the square root of −1, but we also have (−*i*)^{2} = *i*^{2} = −1 and so −*i* is also a square root of −1. By convention, the principal square root of −1 is *i*, or more generally, if *x* is any nonnegative number, then the principal square root of −*x* is

The right side (as well as its negative) is indeed a square root of −*x*, since

For every non-zero complex number *z* there exist precisely two numbers *w* such that *w*^{2} = *z*: the principal square root of *z* (defined below), and its negative.

When the number is expressed using its real and imaginary parts, the following formula can be used for the principal square root:^{[20]}^{[21]}

where sgn(*y*) is the sign of y (except that, here, sgn(0) = 1). In particular, the imaginary parts of the original number and the principal value of its square root have the same sign. The real part of the principal value of the square root is always nonnegative.

Because of the discontinuous nature of the square root function in the complex plane, the following laws are **not true** in general.

A similar problem appears with other complex functions with branch cuts, e.g., the complex logarithm and the relations log*z* + log*w* = log(*zw*) or log(*z*^{*}) = log(*z*)^{*} which are not true in general.

Wrongly assuming one of these laws underlies several faulty "proofs", for instance the following one showing that −1 = 1:

Abel–Ruffini theorem states that, in general, the roots of a polynomial of degree five or higher cannot be expressed in terms of nth roots.

If *A* is a positive-definite matrix or operator, then there exists precisely one positive definite matrix or operator *B* with *B*^{2} = *A*; we then define *A*^{1/2} = *B*. In general matrices may have multiple square roots or even an infinitude of them. For example, the 2 × 2 identity matrix has an infinity of square roots,^{[22]} though only one of them is positive definite.

Each element of an integral domain has no more than 2 square roots. The difference of two squares identity *u*^{2} − *v*^{2} = (*u* − *v*)(*u* + *v*) is proved using the commutativity of multiplication. If u and v are square roots of the same element, then *u*^{2} − *v*^{2} = 0. Because there are no zero divisors this implies *u* = *v* or *u* + *v* = 0, where the latter means that two roots are additive inverses of each other. In other words if an element a square root u of an element a exists, then the only square roots of a are u and −u. The only square root of 0 in an integral domain is 0 itself.

In a field of characteristic 2, an element either has one square root or does not have any at all, because each element is its own additive inverse, so that −*u* = *u*. If the field is finite of characteristic 2 then every element has a unique square root. In a field of any other characteristic, any non-zero element either has two square roots, as explained above, or does not have any.

Given an odd prime number p, let *q* = *p*^{e} for some positive integer e. A non-zero element of the field **F**_{q} with q elements is a quadratic residue if it has a square root in **F**_{q}. Otherwise, it is a quadratic non-residue. There are (*q* − 1)/2 quadratic residues and (*q* − 1)/2 quadratic non-residues; zero is not counted in either class. The quadratic residues form a group under multiplication. The properties of quadratic residues are widely used in number theory.

The construction is also given by Descartes in his *La Géométrie*, see figure 2 on . However, Descartes made no claim to originality and his audience would have been quite familiar with Euclid.