Theorem: bernsteinPolynomial.variance
File: Mathlib/RingTheory/Polynomial/Bernstein.lean

tactic: have p : ((((Finset.range (n + 1)).sum fun ν => (ν * (ν - 1)) • bernsteinPolynomial R n ν) +
    (1 - (2 * n) • Polynomial.X) * (Finset.range (n + 1)).sum fun ν =>
      ν • bernsteinPolynomial R n ν) + n ^ 2 • X ^ 2 *
        (Finset.range (n + 1)).sum fun ν => bernsteinPolynomial R n ν) = _ :=
  rfl
state_before: R : Type u_1
inst✝ : CommRing R
n : ℕ
⊢ ∑ ν in Finset.range (n + 1), (n • X - ↑ν) ^ 2 * bernsteinPolynomial R n ν = n • X * (1 - X)

tactic: conv at p =>
  lhs
  rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_add_distrib]
  simp only [← nat_cast_mul]
  simp only [← mul_assoc]
  simp only [← add_mul]
state_before: R : Type u_1
inst✝ : CommRing R
n : ℕ
p :
  ∑ ν in Finset.range (n + 1), (ν * (ν - 1)) • bernsteinPolynomial R n ν +
        (↑1 - (2 * n) • X) * ∑ ν in Finset.range (n + 1), ν • bernsteinPolynomial R n ν +
      n ^ 2 • X ^ 2 * ∑ ν in Finset.range (n + 1), bernsteinPolynomial R n ν =
    ∑ ν in Finset.range (n + 1), (ν * (ν - 1)) • bernsteinPolynomial R n ν +
        (↑1 - (2 * n) • X) * ∑ ν in Finset.range (n + 1), ν • bernsteinPolynomial R n ν +
      n ^ 2 • X ^ 2 * ∑ ν in Finset.range (n + 1), bernsteinPolynomial R n ν
⊢ ∑ ν in Finset.range (n + 1), (n • X - ↑ν) ^ 2 * bernsteinPolynomial R n ν = n • X * (1 - X)

tactic: conv at p =>
  rhs
  rw [sum, sum_smul, sum_mul_smul, ← nat_cast_mul]
state_before: R : Type u_1
inst✝ : CommRing R
n : ℕ
p :
  ∑ x in Finset.range (n + 1),
      (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x =
    ∑ ν in Finset.range (n + 1), (ν * (ν - 1)) • bernsteinPolynomial R n ν +
        (↑1 - (2 * n) • X) * ∑ ν in Finset.range (n + 1), ν • bernsteinPolynomial R n ν +
      n ^ 2 • X ^ 2 * ∑ ν in Finset.range (n + 1), bernsteinPolynomial R n ν
⊢ ∑ ν in Finset.range (n + 1), (n • X - ↑ν) ^ 2 * bernsteinPolynomial R n ν = n • X * (1 - X)

tactic: calc
  _ = _ := Finset.sum_congr rfl fun k m => ?_
  _ = _ := p
  _ = _ := ?_
state_before: R : Type u_1
inst✝ : CommRing R
n : ℕ
p :
  ∑ x in Finset.range (n + 1),
      (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x =
    ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1
⊢ ∑ ν in Finset.range (n + 1), (n • X - ↑ν) ^ 2 * bernsteinPolynomial R n ν = n • X * (1 - X)

tactic: congr 1
state_before: case calc_1
R : Type u_1
inst✝ : CommRing R
n : ℕ
p :
  ∑ x in Finset.range (n + 1),
      (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x =
    ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1
k : ℕ
m : k ∈ Finset.range (n + 1)
⊢ (n • X - ↑k) ^ 2 * bernsteinPolynomial R n k =
    (↑(k * (k - 1)) + (↑1 - ↑(2 * n) * X) * ↑k + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n k

tactic: simp only [← nat_cast_mul, push_cast]
state_before: case calc_1.e_a
R : Type u_1
inst✝ : CommRing R
n : ℕ
p :
  ∑ x in Finset.range (n + 1),
      (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x =
    ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1
k : ℕ
m : k ∈ Finset.range (n + 1)
⊢ (n • X - ↑k) ^ 2 = ↑(k * (k - 1)) + (↑1 - ↑(2 * n) * X) * ↑k + ↑(n ^ 2) * X ^ 2

tactic: simp
state_before: case calc_1.e_a.succ
R : Type u_1
inst✝ : CommRing R
n : ℕ
p :
  ∑ x in Finset.range (n + 1),
      (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x =
    ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1
n✝ : ℕ
m : Nat.succ n✝ ∈ Finset.range (n + 1)
⊢ (↑n * X - ↑(Nat.succ n✝)) ^ 2 =
    ↑(Nat.succ n✝) * ↑(Nat.succ n✝ - 1) + (1 - 2 * ↑n * X) * ↑(Nat.succ n✝) + ↑n ^ 2 * X ^ 2

tactic: ring
state_before: case calc_1.e_a.succ
R : Type u_1
inst✝ : CommRing R
n : ℕ
p :
  ∑ x in Finset.range (n + 1),
      (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x =
    ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1
n✝ : ℕ
m : Nat.succ n✝ ∈ Finset.range (n + 1)
⊢ (↑n * X - (↑n✝ + 1)) ^ 2 = (↑n✝ + 1) * ↑n✝ + (1 - 2 * ↑n * X) * (↑n✝ + 1) + ↑n ^ 2 * X ^ 2

tactic: simp only [← nat_cast_mul, push_cast]
state_before: case calc_2
R : Type u_1
inst✝ : CommRing R
n : ℕ
p :
  ∑ x in Finset.range (n + 1),
      (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x =
    ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1
⊢ ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 = n • X * (1 - X)

tactic: cases n
state_before: case calc_2
R : Type u_1
inst✝ : CommRing R
n : ℕ
p :
  ∑ x in Finset.range (n + 1),
      (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x =
    ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1
⊢ ↑n * ↑(n - 1) * X ^ 2 + (1 - 2 * ↑n * X) * (↑n * X) + ↑n ^ 2 * X ^ 2 * 1 = ↑n * X * (1 - X)

tactic: simp
state_before: case calc_2.zero
R : Type u_1
inst✝ : CommRing R
p :
  ∑ x in Finset.range (Nat.zero + 1),
      (↑(x * (x - 1)) + (↑1 - ↑(2 * Nat.zero) * X) * ↑x + ↑(Nat.zero ^ 2) * X ^ 2) * bernsteinPolynomial R Nat.zero x =
    ↑(Nat.zero * (Nat.zero - 1)) * X ^ 2 + (↑1 - (2 * Nat.zero) • X) * Nat.zero • X + Nat.zero ^ 2 • X ^ 2 * 1
⊢ ↑Nat.zero * ↑(Nat.zero - 1) * X ^ 2 + (1 - 2 * ↑Nat.zero * X) * (↑Nat.zero * X) + ↑Nat.zero ^ 2 * X ^ 2 * 1 =
    ↑Nat.zero * X * (1 - X)

tactic: simp
state_before: case calc_2.succ
R : Type u_1
inst✝ : CommRing R
n✝ : ℕ
p :
  ∑ x in Finset.range (Nat.succ n✝ + 1),
      (↑(x * (x - 1)) + (↑1 - ↑(2 * Nat.succ n✝) * X) * ↑x + ↑(Nat.succ n✝ ^ 2) * X ^ 2) *
        bernsteinPolynomial R (Nat.succ n✝) x =
    ↑(Nat.succ n✝ * (Nat.succ n✝ - 1)) * X ^ 2 + (↑1 - (2 * Nat.succ n✝) • X) * Nat.succ n✝ • X +
      Nat.succ n✝ ^ 2 • X ^ 2 * 1
⊢ ↑(Nat.succ n✝) * ↑(Nat.succ n✝ - 1) * X ^ 2 + (1 - 2 * ↑(Nat.succ n✝) * X) * (↑(Nat.succ n✝) * X) +
      ↑(Nat.succ n✝) ^ 2 * X ^ 2 * 1 =
    ↑(Nat.succ n✝) * X * (1 - X)

tactic: ring
state_before: case calc_2.succ
R : Type u_1
inst✝ : CommRing R
n✝ : ℕ
p :
  ∑ x in Finset.range (Nat.succ n✝ + 1),
      (↑(x * (x - 1)) + (↑1 - ↑(2 * Nat.succ n✝) * X) * ↑x + ↑(Nat.succ n✝ ^ 2) * X ^ 2) *
        bernsteinPolynomial R (Nat.succ n✝) x =
    ↑(Nat.succ n✝ * (Nat.succ n✝ - 1)) * X ^ 2 + (↑1 - (2 * Nat.succ n✝) • X) * Nat.succ n✝ • X +
      Nat.succ n✝ ^ 2 • X ^ 2 * 1
⊢ (↑n✝ + 1) * ↑n✝ * X ^ 2 + (1 - 2 * (↑n✝ + 1) * X) * ((↑n✝ + 1) * X) + (↑n✝ + 1) ^ 2 * X ^ 2 = (↑n✝ + 1) * X * (1 - X)