Algorithm Search⌘K

Proofs: Newton's method for square root

These are the human proofs of Newton's method for square root, at full length.

Newton's square root iteration squares the quantity (x - r)/(x + r), converges from every positive start, and terminates in floating point full

This proof shows: correctness, termination, global-convergence, order.

Let a>0a > 0, r=ar = \sqrt a, x0>0x_0 > 0 and xk+1=(xk+a/xk)/2x_{k+1} = (x_k + a/x_k)/2. Write ek=xk−re_k = x_k - r and tk=(xk−r)/(xk+r)t_k = (x_k - r)/(x_k + r). For NEWTON-SQRT, aa is replaced by mm and x0=1x_0 = 1, so the xx of line L3 is x1x_1 and pass kk computes xk+1x_{k+1}.

Lemma (the exact error formula). For every xk>0x_k > 0, xk+1>0x_{k+1} > 0 and

xk+1±r=(xk±r)22xk,soek+1=ek22xk,tk+1=tk2.x_{k+1} \pm r = \frac{(x_k \pm r)^2}{2 x_k}, \qquad\text{so}\qquad e_{k+1} = \frac{e_k^2}{2 x_k}, \qquad t_{k+1} = t_k^2 .

Proof. xk+1±r=(xk2+a±2rxk)/(2xk)=(xk±r)2/(2xk)x_{k+1} \pm r = (x_k^2 + a \pm 2 r x_k)/(2 x_k) = (x_k \pm r)^2/(2x_k), using a=r2a = r^2. Positivity is clear. Divide the two forms; xk+1+r>0x_{k+1} + r > 0, so tk+1t_{k+1} is defined. □\square

Claim 1 (global convergence). For every x0>0x_0 > 0: ∣t0∣<1|t_0| < 1, tk=t02kt_k = t_0^{2^k}, xk≥rx_k \ge r for k≥1k \ge 1, xk+1≤xkx_{k+1} \le x_k for k≥1k \ge 1, xk→rx_k \to r, and if no eke_k is zero, ek+1/ek2→1/(2r)e_{k+1}/e_k^2 \to 1/(2r).

Proof. Since x0>0x_0 > 0 and r>0r > 0, ∣x0−r∣<x0+r|x_0 - r| < x_0 + r, so ∣t0∣<1|t_0| < 1; the lemma gives tk=t02k→0t_k = t_0^{2^k} \to 0. Solving t=(x−r)/(x+r)t = (x - r)/(x + r) for xx gives xk=r(1+tk)/(1−tk)x_k = r (1 + t_k)/(1 - t_k), so xk→rx_k \to r. For k≥1k \ge 1, ek=ek−12/(2xk−1)≥0e_k = e_{k-1}^2/(2 x_{k-1}) \ge 0. Then xk+1−xk=(a−xk2)/(2xk)≤0x_{k+1} - x_k = (a - x_k^2)/(2 x_k) \le 0. Finally ek+1/ek2=1/(2xk)→1/(2r)e_{k+1}/e_k^2 = 1/(2 x_k) \to 1/(2r). □\square

Claim 2 (the reduced start). If 1/2≤m<21/2 \le m < 2 and x0=1x_0 = 1, then ∣t0∣≤3−22<0.1716|t_0| \le 3 - 2\sqrt 2 < 0.1716, and for k≥1k \ge 1 the relative error satisfies

0≤xk−rr=2tk1−tk≤2⋅0.17162k1−0.17162k.0 \le \frac{x_k - r}{r} = \frac{2 t_k}{1 - t_k} \le \frac{2 \cdot 0.1716^{2^k}}{1 - 0.1716^{2^k}} .

For k=5k = 5 the bound is below 1.1⋅10−24<u=2−531.1 \cdot 10^{-24} < u = 2^{-53}.

Proof. ∣t0∣=∣1−m∣/(1+m)|t_0| = |1 - \sqrt m|/(1 + \sqrt m). The function s↦∣1−s∣/(1+s)s \mapsto |1 - s|/(1 + s) decreases on (0,1](0, 1] and increases on [1,∞)[1, \infty), so on [1/2,2][\sqrt{1/2}, \sqrt 2] its maximum is at an end. Both ends give (2−1)/(2+1)=(2−1)2=3−22≈0.17157(\sqrt 2 - 1)/(\sqrt 2 + 1) = (\sqrt 2 - 1)^2 = 3 - 2\sqrt 2 \approx 0.17157. The formula for the relative error follows from xk=r(1+tk)/(1−tk)x_k = r(1 + t_k)/(1 - t_k), with tk=t02k≥0t_k = t_0^{2^k} \ge 0 for k≥1k \ge 1. For k=5k = 5, 0.171632<5.5⋅10−250.1716^{32} < 5.5 \cdot 10^{-25}. □\square

Claim 3 (termination and the range reduction). In binary64, NEWTON-SQRT returns for every input after at most kmax⁡k_{\max} passes, and the loop also ends when kmax⁡=∞k_{\max} = \infty. Line L2 is exact, and a=m⋅2e\sqrt a = \sqrt m \cdot 2^e.

Proof. Line L2: write a=f⋅2Ea = f \cdot 2^E with 1/2≤f<11/2 \le f < 1; if EE is even take m=fm = f, e=E/2e = E/2, otherwise m=2fm = 2f, e=(E−1)/2e = (E - 1)/2. Multiplying by 22 is exact, 1/2≤m<21/2 \le m < 2 and a=m⋅4ea = m \cdot 4^e. In the loop, the computed xx and m/xm/x are positive (the quotient of two positive normal numbers in [1/4,4][1/4, 4] does not underflow), so every xx is a positive floating-point number. Line L7 runs only after line L6 found y<xy < x, so the values of xx in successive passes strictly decrease. There are finitely many floating-point numbers in (0,2](0, 2], so line L6 must eventually return. The final multiplication by 2e2^e is exact because m⋅2e\sqrt m\cdot 2^e lies in the normal range for every finite positive binary64 aa. □\square

What is not proved here. That the returned value is within one unit in the last place of a\sqrt a and that the loop uses at most 5 passes in binary64 are observed on random tests (see the main page), not proved. A proof needs a rounding analysis of the last two passes near m\sqrt m. ■\blacksquare

Back to Newton's method for square root