Theorem: Finset.sum_mul_sq_le_sq_mul_sq
File: Mathlib/Algebra/Order/BigOperators/Ring/Finset.lean

tactic: nontriviality R
state_before: ι : Type u_1
R : Type u_2
inst✝¹ : LinearOrderedCommSemiring R
inst✝ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
⊢ (∑ i ∈ s, f i * g i) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2
state_after: ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
⊢ (∑ i ∈ s, f i * g i) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2

tactic: obtain h' | h' := (sum_nonneg fun _ _ ↦ sq_nonneg <| g _).eq_or_lt
state_before: ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
⊢ (∑ i ∈ s, f i * g i) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2
state_after: case inl
ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 = ∑ i ∈ ?m.33978, g (?m.34048 i) ^ 2
⊢ (∑ i ∈ s, f i * g i) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2

case inr
ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 < ∑ i ∈ ?m.33978, g (?m.34048 i) ^ 2
⊢ (∑ i ∈ s, f i * g i) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2

tactic: refine le_of_mul_le_mul_of_pos_left
  (le_of_add_le_add_left (a := (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2) ?_) h'
state_before: case inr
ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 < ∑ i ∈ s, g i ^ 2
⊢ (∑ i ∈ s, f i * g i) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2
state_after: case inr
ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 < ∑ i ∈ s, g i ^ 2
⊢ (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 + (∑ i ∈ s, g i ^ 2) * (∑ i ∈ s, f i * g i) ^ 2 ≤
    (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 + (∑ i ∈ s, g i ^ 2) * ((∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2)

tactic: calc
  _ = ∑ i ∈ s, 2 * (f i * ∑ j ∈ s, g j ^ 2) * (g i * ∑ j ∈ s, f j * g j) := by
      simp_rw [mul_assoc (2 : R), mul_mul_mul_comm, ← mul_sum, ← sum_mul]; ring
  _ ≤ ∑ i ∈ s, ((f i * ∑ j ∈ s, g j ^ 2) ^ 2 + (g i * ∑ j ∈ s, f j * g j) ^ 2) :=
      sum_le_sum fun i _ ↦ two_mul_le_add_sq (f i * ∑ j ∈ s, g j ^ 2) (g i * ∑ j ∈ s, f j * g j)
  _ = _ := by simp_rw [sum_add_distrib, mul_pow, ← sum_mul]; ring
state_before: case inr
ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 < ∑ i ∈ s, g i ^ 2
⊢ (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 + (∑ i ∈ s, g i ^ 2) * (∑ i ∈ s, f i * g i) ^ 2 ≤
    (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 + (∑ i ∈ s, g i ^ 2) * ((∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2)
state_after: no goals

tactic: have h'' : ∀ i ∈ s, g i = 0 := fun i hi ↦ by
  simpa using (sum_eq_zero_iff_of_nonneg fun i _ ↦ sq_nonneg (g i)).1 h'.symm i hi
state_before: case inl
ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 = ∑ i ∈ ?m.33978, g (?m.34048 i) ^ 2
⊢ (∑ i ∈ s, f i * g i) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2
state_after: case inl
ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 = ∑ i ∈ s, g i ^ 2
h'' : ∀ i ∈ s, g i = 0
⊢ (∑ i ∈ s, f i * g i) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2

tactic: rw [← h', sum_congr rfl (show ∀ i ∈ s, f i * g i = 0 from fun i hi ↦ by simp [h'' i hi])]
state_before: case inl
ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 = ∑ i ∈ s, g i ^ 2
h'' : ∀ i ∈ s, g i = 0
⊢ (∑ i ∈ s, f i * g i) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2
state_after: case inl
ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 = ∑ i ∈ s, g i ^ 2
h'' : ∀ i ∈ s, g i = 0
⊢ (∑ x ∈ s, 0) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * 0

tactic: simp
state_before: case inl
ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 = ∑ i ∈ s, g i ^ 2
h'' : ∀ i ∈ s, g i = 0
⊢ (∑ x ∈ s, 0) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * 0
state_after: no goals

tactic: simpa using (sum_eq_zero_iff_of_nonneg fun i _ ↦ sq_nonneg (g i)).1 h'.symm i hi
state_before: ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 = ∑ i ∈ ?m.33978, g (?m.34048 i) ^ 2
i : ι
hi : i ∈ s
⊢ g i = 0
state_after: no goals

tactic: simp [h'' i hi]
state_before: ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 = ∑ i ∈ s, g i ^ 2
h'' : ∀ i ∈ s, g i = 0
i : ι
hi : i ∈ s
⊢ f i * g i = 0
state_after: no goals

tactic: simp_rw [mul_assoc (2 : R), mul_mul_mul_comm, ← mul_sum, ← sum_mul]
state_before: ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 < ∑ i ∈ s, g i ^ 2
⊢ (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 + (∑ i ∈ s, g i ^ 2) * (∑ i ∈ s, f i * g i) ^ 2 =
    ∑ i ∈ s, 2 * (f i * ∑ j ∈ s, g j ^ 2) * (g i * ∑ j ∈ s, f j * g j)
state_after: ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 < ∑ i ∈ s, g i ^ 2
⊢ (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 + (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 =
    2 * ((∑ i ∈ s, f i * g i) * ((∑ i ∈ s, g i ^ 2) * ∑ j ∈ s, f j * g j))

tactic: ring
state_before: ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 < ∑ i ∈ s, g i ^ 2
⊢ (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 + (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 =
    2 * ((∑ i ∈ s, f i * g i) * ((∑ i ∈ s, g i ^ 2) * ∑ j ∈ s, f j * g j))
state_after: no goals

tactic: simp_rw [sum_add_distrib, mul_pow, ← sum_mul]
state_before: ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 < ∑ i ∈ s, g i ^ 2
⊢ ∑ i ∈ s, ((f i * ∑ j ∈ s, g j ^ 2) ^ 2 + (g i * ∑ j ∈ s, f j * g j) ^ 2) =
    (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 + (∑ i ∈ s, g i ^ 2) * ((∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2)
state_after: ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 < ∑ i ∈ s, g i ^ 2
⊢ (∑ i ∈ s, f i ^ 2) * (∑ j ∈ s, g j ^ 2) ^ 2 + (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 =
    (∑ j ∈ s, g j ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 + (∑ j ∈ s, g j ^ 2) * ((∑ i ∈ s, f i ^ 2) * ∑ j ∈ s, g j ^ 2)

tactic: ring
state_before: ι : Type u_1
R : Type u_2
inst✝² : LinearOrderedCommSemiring R
inst✝¹ : ExistsAddOfLE R
s : Finset ι
f g : ι → R
inst✝ : Nontrivial R
h' : 0 < ∑ i ∈ s, g i ^ 2
⊢ (∑ i ∈ s, f i ^ 2) * (∑ j ∈ s, g j ^ 2) ^ 2 + (∑ i ∈ s, g i ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 =
    (∑ j ∈ s, g j ^ 2) * (∑ j ∈ s, f j * g j) ^ 2 + (∑ j ∈ s, g j ^ 2) * ((∑ i ∈ s, f i ^ 2) * ∑ j ∈ s, g j ^ 2)
state_after: no goals