Visual walkthrough — Implementing root-finding from scratch — Newton-Raphson, bisection
Step 1 — What is a "root", as a picture?
WHAT. We draw a wiggly curve. The horizontal line is where height . A root is any place where the curve touches or crosses that zero-line.
WHY. Every root-finding method is a hunt for one specific value: the one directly below (or above) a crossing point. If we cannot see what we are hunting, the algebra later is just noise. So we anchor the whole page to this one picture: root = the x-coordinate of a crossing.
PICTURE. In the figure the curve is drawn in black; the single red dot sits exactly where it pierces the zero-line. Call that dot's horizontal position (read "x-star" — the star means the true answer we don't yet know).

Step 2 — What is a sign change, and why it traps a root
WHAT. Pick two points (left) and (right). Read off the two heights and . If one is below the zero-line (negative) and the other is above (positive), we have a sign change.
WHY. A continuous curve cannot jump from below the line to above the line without touching the line somewhere in between — that "somewhere" is a root. This is the Intermediate Value Theorem said in plain words. It is the only guarantee we get for free, and bisection is built entirely on it.
PICTURE. points down (negative, black arrow below the axis); points up (positive). The red segment marks the region that is now guaranteed to contain a crossing.

Step 3 — Bisection: cut the trapped region in half
WHAT. Take the midpoint and measure its height . Compare the sign of to the sign of .
WHY. The root is somewhere in . The midpoint splits that region into two equal halves. The root lives in whichever half still shows a sign change. We keep that half, throw the other away — and the uncertainty is now exactly half what it was.
PICTURE. The full bracket is black. The midpoint is the red tick. The kept half (still opposite-signed at its ends) is shaded; the discarded half is faded.

Now let us name what shrinks. Call the length of the surviving interval its width. We do the cut over and over — first cut, second cut, third cut — so let count how many cuts we have made so far, and write for the width after those cuts. So is the starting width (zero cuts yet), is the width after one cut, and so on. This is exactly the loop running times.
- Which half survives a cut? ::: The one whose two endpoint heights still have opposite signs.
- Why is bisection unbeatable at reliability? ::: It never lets the root escape the shrinking bracket — the trap only tightens.
Step 4 — Newton's idea: replace the curve with its tangent
WHAT. Stand at a guess on the curve. Draw the straight line that just grazes the curve there — the tangent line. Its steepness is called (read "f-prime"), the slope of the curve at that spot.
WHY. Finding where a curve hits zero is hard. Finding where a straight line hits zero is grade-school algebra. So Newton's trick is a swap: pretend, just for one step, that the curve IS its tangent line, and use the line's easy zero as the next guess. Near the tangent hugs the curve, so its zero lands close to the real root.
PICTURE. Black curve, red tangent line touching at the guess . Notice the red line dives down to cross the zero-line at a new point — that crossing is our next guess.

Step 5 — Derive the update from the tangent, term by term
WHAT. Write the equation of that red tangent line and ask: where does it hit height zero?
WHY. That zero-crossing is the next guess . Solving for it gives the exact Newton formula — no magic, just line-crossing algebra.
PICTURE. The same tangent, now with the two moving parts labelled: the current height (vertical black drop) and the horizontal jump (red arrow along the axis).

Line through the point with slope :
We want the crossing, so set and rename the special as :
Isolate the horizontal walk (subtract, then divide by the slope):
Step 6 — The degenerate case: a flat tangent ()
WHAT. Suppose the tangent at is horizontal — slope .
WHY. A horizontal line never crosses the zero-line (unless it is the zero-line). Algebraically we'd divide by zero in . The step is undefined — the method has no next guess.
PICTURE. Red horizontal tangent shooting off to the sides, never meeting the axis; the "next guess" flies to infinity.

- What goes wrong when ? ::: The tangent is horizontal, has no zero-crossing, and the update divides by zero — the step is undefined / infinite.
Step 7 — The other degenerate case: endpoint already a root
WHAT. In bisection a caller might hand you where (or ) exactly.
WHY. Then , which is not . The strict bracket test fails, the loop never runs, and you'd throw away a perfectly good root sitting right at the endpoint.
PICTURE. The curve grazes the zero-line exactly at — the red dot sits on the boundary, not inside.

- What goes wrong if exactly and you skip the endpoint check? ::: The product is not , the loop never runs, and the real root at is discarded.
Step 8 — Why Newton doubles your digits (quadratic convergence)
WHAT. Let be the error — how far the guess is from the true root. We track how depends on .
WHY. This is the payoff picture: Newton's error turns out to be proportional to the square of the previous error. Squaring a small number makes it tiny — that's why correct digits roughly double each step. But to earn that claim we must derive it, and to derive it we need one more tool: the second derivative.
PICTURE. Two nested red gaps: a wide gap at step , and a dramatically narrower gap at step .

The derivation, term by term. We use the Taylor Series — the recipe that rebuilds a curve near a point out of its height, slope, and bending. Expand and about the true root , assuming is twice differentiable so that exists. Write everything in terms of the error :
The first term is because is a root. So .
Now form the Newton correction and subtract from both sides. Since and :
Now the key move — WHY the leading terms cancel. Factor out of top and bottom of the fraction so we can see its shape clearly. Let (a fixed number: bending divided by slope). Then
The messy part is . For a small we expand as a geometric series (this is the binomial/geometric expansion; it is valid because is tiny, so squared-and-higher terms are negligible). Multiplying out and keeping only up to :
So the whole correction is
Subtract this from — and here the terms cancel exactly, which is the whole point: the and the annihilate, leaving only the squared piece:
Everything we dropped (the "") is proportional to or smaller — for tiny those are utterly negligible next to , which is why we may throw them away. The boxed line quietly assumes (otherwise divides by zero — Newton's flat-spot disease from Step 6, now at the root itself) and twice differentiable (otherwise has no meaning and the expansion collapses).
If (3 good digits), then — 6 good digits. 3 → 6 → 12, matching the parent's worked example for . Compare bisection: it multiplies the error by each step, buying only one bit — this is the linear-vs-quadratic speed gap, and why scipy.optimize's brentq blends a bracket (safety) with fast interpolation (the Secant method idea).
The one-picture summary

One canvas, both methods on the same curve: bisection's shrinking red bracket crawls in from both sides; Newton's red tangents leap toward the root. Slow-but-safe versus fast-but-fragile.
Recall Feynman retelling — say it back in plain words
A root is just where a curve touches the zero-line. If the curve is below the line at one point and above it at another, it had to cross somewhere between — that's a trap for the root. Bisection exploits the trap: check the middle, keep the half that still straddles the line, and the trap shrinks by half every single time. Dead slow, never fails.
Newton is impatient. It stands on the curve, draws the straight line that grazes it there, and slides down that line to where the line hits zero — because a straight line's zero is trivial to compute. That landing spot is the new guess. The formula "current height ÷ steepness, stepped backwards" is just that line-crossing solved on paper. When the slope is healthy, each jump roughly squares the error (because the only thing the tangent misses is the curve's bending, measured by ), so the number of correct digits doubles — but if the slope goes flat, the line never meets the axis, the step blows up, and Newton runs away. That's the whole story: bisection tightens a trap; Newton rides a tangent; one is safe, the other is fast, and the pros glue them together.