This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

← Posts

demoAINumerics

Newton's method doubles the correct digits

Newton's method on , one cell at a time. From the error is after four steps and zero after five; bisection needs 39 halvings to promise as much. Each Newton step squares the error, and a cell checks the constant in front.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

A notebook: the prose between the cells says what each one is for, and each cell's output appears under it. Press Run all, or run a cell with Shift+Enter.

Printed

x1: 1.5

One step

The tangent to at has slope and passes through . It crosses zero at , which is what the cell above printed. Already is close to 2.

Before running the next cell, guess how many steps it takes to get every digit a double can hold, about 16.

Printed

xs: [1, 1.5, 1.41667, 1.41422, 1.41421, 1.41421]
errs: [0.414214, 0.0857864, 0.0024531, 2.1239e-06, 1.59472e-12, 0]

Tests 3 of 3 pass

  • after four steps the error is below 2e-12 (passes)
  • after five steps the error is zero: x is sqrt(2) to the last bit (passes)
  • a double holds about 16 decimal digits: 53 bits, 15.95 digits (passes)

Why the digits double

Write the error as . One step gives

so . Near the root , and the error is squared at every step and scaled by . An error of becomes , then : the number of correct digits doubles.

The cell below measures for the first four steps. Far from the root the ratio is with still far from ; by the fourth step it matches to four digits.

Printed

ratio: 0.5
ratio: 0.333333
ratio: 0.352941
ratio: 0.353522

Tests 3 of 3 pass

  • an error of 1e-3 becomes 3.5e-7, then 4.4e-14 (passes)
  • the first ratio is 1 / (2 x_0) = 1/2, exactly as the algebra says (passes)
  • by the fourth step e_(n+1) / e_n^2 is 1 / (2 sqrt 2) to four digits (passes)

Against bisection

Bisection keeps an interval where changes sign and halves it. After halvings of the midpoint is within of the root, one binary digit per step, and that guarantee is all it has: it never fails, and it never speeds up. The figure plots of Newton's error beside of bisection's guarantee. Newton's curve bends down; bisection's is a straight line.

Printed

match: 39
Error after n steps, x2=2 from x0=110⁻¹²10⁻⁸10⁻⁴10⁰010203040step nerror
Newton, |xn−2|bisection, half the interval

Tests 1 of 1 pass

  • bisection needs 39 halvings to promise what four Newton steps did (passes)

Checked when the site was built: 7 of 7 tests passed, in under 0.1 s. Download 2026-09-24-newton-doubles-the-digits.viv