# Documentation

Mathlib.Analysis.SpecialFunctions.Bernstein

# Bernstein approximations and Weierstrass' theorem #

We prove that the Bernstein approximations

∑ k : Fin (n+1), f (k/n : ℝ) * n.choose k * x^k * (1-x)^(n-k)


for a continuous function f : C([0,1], ℝ) converge uniformly to f as n tends to infinity.

Our proof follows [Richard Beals' Analysis, an introduction][beals-analysis], §7D. The original proof, due to Bernstein in 1912, is probabilistic, and relies on Bernoulli's theorem, which gives bounds for how quickly the observed frequencies in a Bernoulli trial approach the underlying probability.

The proof here does not directly rely on Bernoulli's theorem, but can also be given a probabilistic account.

• Consider a weighted coin which with probability x produces heads, and with probability 1-x produces tails.
• The value of bernstein n k x is the probability that such a coin gives exactly k heads in a sequence of n tosses.
• If such an appearance of k heads results in a payoff of f(k / n), the n-th Bernstein approximation for f evaluated at x is the expected payoff.
• The main estimate in the proof bounds the probability that the observed frequency of heads differs from x by more than some δ, obtaining a bound of (4 * n * δ^2)⁻¹, irrespective of x.
• This ensures that for n large, the Bernstein approximation is (uniformly) close to the payoff function f.

(You don't need to think in these terms to follow the proof below: it's a giant calc block!)

This result proves Weierstrass' theorem that polynomials are dense in C([0,1], ℝ), although we defer an abstract statement of this until later.

def bernstein (n : ) (ν : ) :

The Bernstein polynomials, as continuous functions on [0,1].

Instances For
@[simp]
theorem bernstein_apply (n : ) (ν : ) (x : ) :
↑() x = ↑() * x ^ ν * (1 - x) ^ (n - ν)
theorem bernstein_nonneg {n : } {ν : } {x : } :
0 ↑() x

We now give a slight reformulation of bernsteinPolynomial.variance.

def bernstein.z {n : } (k : Fin (n + 1)) :

Send k : Fin (n+1) to the equally spaced points k/n in the unit interval.

Instances For
theorem bernstein.probability (n : ) (x : ) :
(Finset.sum Finset.univ fun k => ↑(bernstein n k) x) = 1
theorem bernstein.variance {n : } (h : 0 < n) (x : ) :
(Finset.sum Finset.univ fun k => (x - ↑()) ^ 2 * ↑(bernstein n k) x) = x * (1 - x) / n
def bernsteinApproximation (n : ) (f : ) :

The n-th approximation of a continuous function on [0,1] by Bernstein polynomials, given by ∑ k, f (k/n) * bernstein n k x.

Instances For

We now set up some of the basic machinery of the proof that the Bernstein approximations converge uniformly.

A key player is the set S f ε h n x, for some function f : C(I, ℝ), h : 0 < ε, n : ℕ and x : I.

This is the set of points k in Fin (n+1) such that k/n is within δ of x, where δ is the modulus of uniform continuity for f, chosen so |f x - f y| < ε/2 when |x - y| < δ.

We show that if k ∉ S, then 1 ≤ δ^-2 * (x - k/n)^2.

@[simp]
theorem bernsteinApproximation.apply (n : ) (f : ) (x : ) :
↑() x = Finset.sum Finset.univ fun k => f () * ↑(bernstein n k) x
def bernsteinApproximation.δ (f : ) (ε : ) (h : 0 < ε) :

The modulus of (uniform) continuity for f, chosen so |f x - f y| < ε/2 when |x - y| < δ.

Instances For
theorem bernsteinApproximation.δ_pos {f : } {ε : } {h : 0 < ε} :
0 <
def bernsteinApproximation.S (f : ) (ε : ) (h : 0 < ε) (n : ) (x : ) :
Finset (Fin (n + 1))

The set of points k so k/n is within δ of x.

Instances For
theorem bernsteinApproximation.lt_of_mem_S {f : } {ε : } {h : 0 < ε} {n : } {x : } {k : Fin (n + 1)} (m : k ) :
|f () - f x| < ε / 2

If k ∈ S, then f(k/n) is close to f x.

theorem bernsteinApproximation.le_of_mem_S_compl {f : } {ε : } {h : 0 < ε} {n : } {x : } {k : Fin (n + 1)} (m : k ()) :
1 ^ (-2) * (x - ↑()) ^ 2

If k ∉ S, then as δ ≤ |x - k/n|, we have the inequality 1 ≤ δ^-2 * (x - k/n)^2. This particular formulation will be helpful later.

theorem bernsteinApproximation_uniform (f : ) :
Filter.Tendsto (fun n => ) Filter.atTop (nhds f)

The Bernstein approximations

∑ k : Fin (n+1), f (k/n : ℝ) * n.choose k * x^k * (1-x)^(n-k)


for a continuous function f : C([0,1], ℝ) converge uniformly to f as n tends to infinity.

This is the proof given in [Richard Beals' Analysis, an introduction][beals-analysis], §7D, and reproduced on wikipedia.