22 May 2026

Heron's Method

An ancient square-root algorithm rediscovered as a special case of Newton-Raphson, with a derivation, convergence analysis, and implementations in Python, TypeScript, and C++.

The Idea

Heron of Alexandria described a method for computing S\sqrt{S} in the first century [1].

xn+1=xn+S/xn2x_{n+1} = \dfrac{x_n + S/x_n}{2}

The iteration is self-correcting: overshoot and undershoot cancel each other, pulling every successive estimate toward S\sqrt{S} from above.

A depiction of Heron of Alexandria, ancient Greek mathematician and engineer
Heron of Alexandria (c. 10-70 AD) — mathematician, engineer, and inventor of the steam engine

Why It Works — The Newton-Raphson Connection

Finding S\sqrt{S} is equivalent to finding the positive root of f(x)=x2Sf(x) = x^2 - S. Newton-Raphson [2] linearises ff at the current guess and solves for the zero of the tangent line:

xn+1=xnf(xn)f(xn)x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}

Substituting f(x)=x2Sf(x) = x^2 - S and f(x)=2xf'(x) = 2x gives exactly Heron's formula:

xn+1=xnxn2S2xn=2xn2xn2+S2xn=xn+S/xn2x_{n+1} = x_n - \frac{x_n^2 - S}{2x_n} = \frac{2x_n^2 - x_n^2 + S}{2x_n} = \frac{x_n + S/x_n}{2}

Convergence

Newton-Raphson converges quadratically when the initial guess is close enough to the root. Letting εn=xnS\varepsilon_n = x_n - \sqrt{S} be the error at step nn, a Taylor expansion of ff around S\sqrt{S} gives the error recurrence:

εn+1=εn22xn\varepsilon_{n+1} = \frac{\varepsilon_n^2}{2x_n}

The number of correct decimal digits doubles with each iteration. The plot below shows this collapse — note how the curve drops off a cliff rather than declining steadily.

Worked Example — 2\sqrt{2}

Start with x0=1x_0 = 1. Applying the recurrence with S=2S = 2:

x1=1+2/12=1.5x2=1.5+2/1.52=1.416x3=1.416+2/1.41621.41421356\begin{aligned} x_1 &= \dfrac{1 + 2/1}{2} = 1.5 \\[6pt] x_2 &= \dfrac{1.5 + 2/1.5}{2} = 1.41\overline{6} \\[6pt] x_3 &= \dfrac{1.41\overline{6} + 2/1.41\overline{6}}{2} \approx 1.41421356\ldots \end{aligned}

After only three steps the result agrees with 2=1.41421356\sqrt{2} = 1.41421356\ldots to eight significant figures. The 3D plot below shows why the iteration works geometrically — the surface h(x,S)=(x+S/x)/2h(x, S) = (x + S/x)/2 and the truth surface z=Sz = \sqrt{S} intersect exactly along the fixed-point curve x=Sx = \sqrt{S}.

Implementation

The loop terminates when consecutive iterates differ by less than a chosen tolerance. A safe initial guess is x0=Sx_0 = S (large SS) or x0=1x_0 = 1 (small SS).

def heron_sqrt(s: float, tolerance: float = 1e-10) -> float:
    if s < 0:
        raise ValueError("Cannot take sqrt of a negative number")
    if s == 0:
        return 0.0
    x = s if s >= 1 else 1.0
    while True:
        x_next = (x + s / x) / 2
        if abs(x_next - x) < tolerance:
            return x_next
        x = x_next

References

  1. [1]Hero of Alexandria. Metrica. c. 60 CE.
  2. [2]Newton, Isaac. Method of Fluxions. 1671.