User:Esquivalience/sandbox4

In mathematics, particularly numerical analysis, multiple methods to compute, either precisely or approximately, the principal square root of a nonnegative real number have been developed. The square root of a number is the number that, when squared, equals that number. In other words, the square root of a number $$S$$, denoted by $$\sqrt{S}$$, is the number $$n$$ such that $$n^2 = S$$. Each positive number has two square roots, the positive or principal square root $$n$$ ($$n^2 = S$$), and the negative square root which is the negative of $$n$$, $$-n$$ ($$-n^2 = S$$), as the square of a negative number is positive.

Numerous methods with the sole purpose of computing the square root of a number, some of which rely on certain representations of numbers, such as IEEE floating point representation. However, the problem can also be solved with root-finding algorithms, methods that compute, for a function $$f$$, at what $$x$$ does $$f(x) = 0$$, which is its root. The square root problem of finding $$\sqrt{S}$$ can be reduced to finding the root of the function $$f(x) = x^2 - S$$. Square root-finding methods typically compute approximate results, but typically converge to the actual square root of a number as the number of iterations increase.

The square root of a negative number, which has a solution in the complex numbers, need not be computed by a dedicated method, as they can be computed by computing the square root of its absolute value $$\sqrt{|S|}$$, and then multiplying it by the imaginary unit $$i$$, the square root of $$-1$$ (so that $$i^2 = 1$$).

Root-finding
It is possible to reduce the square root problem of finding $$\sqrt{S}$$ to computing the root (or zero) of the function $$f(x) = x^2 - S$$, that is, finding $$x$$ such that $$f(x) = 0$$. Thus, root-finding algorithms can be used to approximate $$\sqrt{S}$$.

Newton's method is commonly used, the Babylonian method described below being a special case of Newton's; given an initial guess, it approximates the root of a function $$f$$ by using its derivative $$f'(x)$$ to generate a better estimate of the root. It can be applied successively to generate increasingly precise estimates. Newton's method can be described as follows, where $$x_n$$ is the $$n^\text{th}$$ estimate generated. $$x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}$$

Babylonian method
The Babylonian method was among the first algorithms used to estimate square roots. The method generates a better estimate $$x_{n+1}$$ of $$\sqrt{S}$$ from the initial guess or previous estimate by taking the arithmetic mean of $$S$$ and $$\frac{S}{x_{n}}$$. The Babylonian method can be derived from Newton's method as follows.