Composite trapezoidal and Simpson rules
DefinitionMetodosNumericos_integracaoDefsThe composite trapezoidal rule with subintervals and the composite Simpson rule with subintervals on .
import Mathlib
namespace MetodosNumericos
/-- The composite trapezoidal rule (Método dos Trapézios) with `n` subintervals of
length `h = (b - a) / n` on `[a, b]`:
`h (f(x₀)/2 + f(x₁) + ⋯ + f(x_{n-1}) + f(xₙ)/2)`. -/
noncomputable def trapezoidRule (f : ℝ → ℝ) (a b : ℝ) (n : ℕ) : ℝ :=
let h := (b - a) / n
h * ((f a + f b) / 2 + ∑ i ∈ Finset.Ico 1 n, f (a + i * h))
/-- The composite Simpson rule (Método de Simpson) on `[a, b]` with an even number
`n = 2k` of subintervals of length `h = (b - a) / (2k)`:
`(h/3)(f(x₀) + 4f(x₁) + 2f(x₂) + ⋯ + 4f(x_{2k-1}) + f(x_{2k}))`. -/
noncomputable def simpsonRule (f : ℝ → ℝ) (a b : ℝ) (k : ℕ) : ℝ :=
let h := (b - a) / (2 * k)
h / 3 * (f a + f b
+ 4 * ∑ i ∈ Finset.range k, f (a + (2 * i + 1) * h)
+ 2 * ∑ i ∈ Finset.Ico 1 k, f (a + (2 * i) * h))
end MetodosNumericosRead-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 code, at the explicit instruction of the mission's human owner, and not by an independent auditor with fresh context.
Two real-valued quantities are defined, for a function and reals , .
The first takes a natural number , sets (total division, so when ) and returns
the sum ranging over the integers with and being empty when .
The second takes a natural number , sets (again total division) and returns
where the first sum runs over (the odd-indexed nodes) and the second over (the interior even-indexed nodes).
No hypothesis relates and , and no integrability or smoothness of is assumed in the definitions.