Theorem: Finset.card_sq_le_card_mul_mulEnergy
File: Mathlib/Combinatorics/Additive/Energy.lean

tactic: calc
  _ = (∑ c ∈ u, ((s ×ˢ t).filter fun (a, b) ↦ a * b = c).card) ^ 2 := by
      rw [← sum_card_fiberwise_eq_card_filter]
  _ ≤ u.card * ∑ c ∈ u, ((s ×ˢ t).filter fun (a, b) ↦ a * b = c).card ^ 2 := by
      simpa using sum_mul_sq_le_sq_mul_sq (R := ℕ) _ 1 _
  _ ≤ u.card * ∑ c ∈ s * t, ((s ×ˢ t).filter fun (a, b) ↦ a * b = c).card ^ 2 := by
      refine mul_le_mul_left' (sum_le_sum_of_ne_zero ?_) _
      aesop (add simp [filter_eq_empty_iff]) (add unsafe mul_mem_mul)
  _ = u.card * Eₘ[s, t] := by rw [mulEnergy_eq_sum_sq']
state_before: α : Type u_1
inst✝¹ : DecidableEq α
inst✝ : Mul α
s✝ s₁ s₂ t✝ t₁ t₂ s t u : Finset α
⊢ (filter
          (fun x =>
            match x with
            | (a, b) => a * b ∈ u)
          (s ×ˢ t)).card ^
      2 ≤
    u.card * Eₘ[s, t]
state_after: no goals

tactic: rw [← sum_card_fiberwise_eq_card_filter]
state_before: α : Type u_1
inst✝¹ : DecidableEq α
inst✝ : Mul α
s✝ s₁ s₂ t✝ t₁ t₂ s t u : Finset α
⊢ (filter
          (fun x =>
            match x with
            | (a, b) => a * b ∈ u)
          (s ×ˢ t)).card ^
      2 =
    (∑ c ∈ u,
        (filter
            (fun x =>
              match x with
              | (a, b) => a * b = c)
            (s ×ˢ t)).card) ^
      2
state_after: no goals

tactic: simpa using sum_mul_sq_le_sq_mul_sq (R := ℕ) _ 1 _
state_before: α : Type u_1
inst✝¹ : DecidableEq α
inst✝ : Mul α
s✝ s₁ s₂ t✝ t₁ t₂ s t u : Finset α
⊢ (∑ c ∈ u,
        (filter
            (fun x =>
              match x with
              | (a, b) => a * b = c)
            (s ×ˢ t)).card) ^
      2 ≤
    u.card *
      ∑ c ∈ u,
        (filter
              (fun x =>
                match x with
                | (a, b) => a * b = c)
              (s ×ˢ t)).card ^
          2
state_after: no goals

tactic: refine mul_le_mul_left' (sum_le_sum_of_ne_zero ?_) _
state_before: α : Type u_1
inst✝¹ : DecidableEq α
inst✝ : Mul α
s✝ s₁ s₂ t✝ t₁ t₂ s t u : Finset α
⊢ u.card *
      ∑ c ∈ u,
        (filter
              (fun x =>
                match x with
                | (a, b) => a * b = c)
              (s ×ˢ t)).card ^
          2 ≤
    u.card *
      ∑ c ∈ s * t,
        (filter
              (fun x =>
                match x with
                | (a, b) => a * b = c)
              (s ×ˢ t)).card ^
          2
state_after: α : Type u_1
inst✝¹ : DecidableEq α
inst✝ : Mul α
s✝ s₁ s₂ t✝ t₁ t₂ s t u : Finset α
⊢ ∀ x ∈ u,
    (filter
              (fun x_1 =>
                match x_1 with
                | (a, b) => a * b = x)
              (s ×ˢ t)).card ^
          2 ≠
        0 →
      x ∈ s * t

tactic: aesop (add simp [filter_eq_empty_iff]) (add unsafe mul_mem_mul)
state_before: α : Type u_1
inst✝¹ : DecidableEq α
inst✝ : Mul α
s✝ s₁ s₂ t✝ t₁ t₂ s t u : Finset α
⊢ ∀ x ∈ u,
    (filter
              (fun x_1 =>
                match x_1 with
                | (a, b) => a * b = x)
              (s ×ˢ t)).card ^
          2 ≠
        0 →
      x ∈ s * t
state_after: no goals

tactic: rw [mulEnergy_eq_sum_sq']
state_before: α : Type u_1
inst✝¹ : DecidableEq α
inst✝ : Mul α
s✝ s₁ s₂ t✝ t₁ t₂ s t u : Finset α
⊢ u.card *
      ∑ c ∈ s * t,
        (filter
              (fun x =>
                match x with
                | (a, b) => a * b = c)
              (s ×ˢ t)).card ^
          2 =
    u.card * Eₘ[s, t]
state_after: no goals