Bisection, fixed-point and Newton iterations
DefinitionMetodosNumericos_zerosDefsThe four constructions used throughout Chapter 3. For a function and a starting interval , the bisection construction produces the brackets : at each step the midpoint replaces when and replaces otherwise; its midpoint is the approximation . For an iteration function , the sequence , is the Método Iterativo Linear. For a function and a function playing the role of its derivative, the Newton sequence is .
import Mathlib namespace MetodosNumericos /-- One step of the bisection method (Método da Bissecção) for a function `f` on a bracketing interval `p = (a, b)` with `f a < 0 < f b`: the midpoint `m = (a + b) / 2` replaces the endpoint whose sign it matches. -/ noncomputable def bisectStep (f : ℝ → ℝ) (p : ℝ × ℝ) : ℝ × ℝ := if f ((p.1 + p.2) / 2) < 0 then ((p.1 + p.2) / 2, p.2) else (p.1, (p.1 + p.2) / 2) /-- The `n`-th bracketing interval `(aₙ, bₙ)` produced by the bisection method started from `(a, b)`. -/ noncomputable def bisect (f : ℝ → ℝ) (a b : ℝ) : ℕ → ℝ × ℝ | 0 => (a, b) | n + 1 => bisectStep f (bisect f a b n) /-- The bisection approximation `xₙ₊₁ = (aₙ + bₙ) / 2`, the midpoint of the `n`-th bracketing interval. -/ noncomputable def bisectMid (f : ℝ → ℝ) (a b : ℝ) (n : ℕ) : ℝ := ((bisect f a b n).1 + (bisect f a b n).2) / 2 /-- The successive-approximation sequence of the linear iterative method (Método Iterativo Linear): `x₀` arbitrary and `xₙ₊₁ = g xₙ`. -/ noncomputable def iterSeq (g : ℝ → ℝ) (x0 : ℝ) : ℕ → ℝ | 0 => x0 | n + 1 => g (iterSeq g x0 n) /-- The Newton sequence: `x₀` arbitrary and `xₙ₊₁ = xₙ - f xₙ / f' xₙ`, where `f'` is a function playing the role of the derivative of `f`. -/ noncomputable def newtonSeq (f f' : ℝ → ℝ) (x0 : ℝ) : ℕ → ℝ | 0 => x0 | n + 1 => newtonSeq f f' x0 n - f (newtonSeq f f' x0 n) / f' (newtonSeq f f' x0 n) end MetodosNumericos
Read-back
What the Lean code literally says, in plain math · self-authored-by-drafting-agent (non-blind)
Disclosure: this read-back is not blind. It was written by the same agent that drafted the Lean statement, at the explicit instruction of the mission's human owner, and not by an independent auditor with fresh context. It is therefore an author's self-description rather than independent testimony, and should be audited against the Lean code directly.
The file introduces five definitions over the real numbers.
The first takes a function and an ordered pair of reals, and returns if , and otherwise. The case falls into the second branch, and nothing requires or any sign condition on .
The second takes and two reals and defines a sequence of pairs indexed by the natural numbers: the value at is , and the value at is the previous value with one step of the above applied to it.
The third takes , , and a natural number and returns the arithmetic mean of the two components of the -th pair.
The fourth takes a function and a real and defines the sequence with value at index and value at index .
The fifth takes two functions — independent arguments, with no relation between them imposed by the definition — and a real , and defines the sequence with value at index and value at index . Division is total: if the quotient is , so the next iterate equals .