op1525_class_imbalance_flip_bilinear_sum
For a finite set of vertices colored by signs and partitioned into classes, sum the product of the class-a and class-b sign imbalances after flipping each vertex once. The result is (n−4) times the original product, plus four times the size of class a if a=b.
Statement
theorem op1525_class_imbalance_flip_bilinear_sum {V J : Type*} [DecidableEq J] [Fintype V] (cl : V → J) (f : V → ℤ) (hsgn : ∀ v, f v = 1 ∨ f v = -1) (a b : J) : let D : J → ℤ := fun j => ∑ u : V, if cl u = j then f u else 0 (∑ v : V, (D a - 2 * (if cl v = a then f v else 0)) * (D b - 2 * (if cl v = b then f v else 0))) = ((Fintype.card V : ℤ) - 4) * D a * D b + if a = b then 4 * (((Finset.univ : Finset V).filter (fun v => cl v = a)).card : ℤ) else 0
- Source
- The class-imbalance Gram-matrix reconstruction identity in the multipartite route for OP-1525.
- Verified
- 17 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext
The proof, explained
The proof expands each product in the sum algebraically into four terms: the constant product D(a) D(b), two linear terms in f(v), and a quadratic cross term. Summing over all vertices yields |V| D(a) D(b) from the constant, while the linear terms sum to -4 D(a) D(b) by definition of the class imbalances. Because f(v)² = 1 and the classes partition V, the cross terms vanish when a ≠ b and sum to four times the size of class a when a = b, which ring arithmetic simplifies to the desired expression.
Set up the definition of the class sign imbalance D and express the goal sum.
We enable classical logic and define the class imbalance function D(j) = ∑_{u : V, cl(u) = j} f(u). The sum on the left-hand side is restated in terms of D.
classical dsimp only let D : J → ℤ := fun j => ∑ u : V, if cl u = j then f u else 0 change (∑ v : V, (D a - 2 * (if cl v = a then f v else 0)) * (D b - 2 * (if cl v = b then f v else 0))) = _
For every vertex v, f(v)² = 1.
By assumption, f(v) is either 1 or -1. In either case, squaring gives 1.
have hs (v : V) : f v * f v = 1 := by rcases hsgn v with h | h <;> rw [h] <;> norm_num
The cross-term sum ∑_{v : V} [cl(v) = a] f(v) · [cl(v) = b] f(v) equals |{v : cl(v) = a}| when a = b, and 0 when a ≠ b.
We split on whether a = b. When a = b, the product simplifies to ([cl(v) = a] f(v))² = [cl(v) = a] f(v)² = [cl(v) = a] · 1; summing 1 over all vertices in class a yields the cardinality of that class. When a ≠ b, no vertex belongs to both classes simultaneously, so every term in the sum is 0, and the sum vanishes by Finset.sum_eq_zero.
uses
if_true,if_false,Finset.sum_eq_zerohave hcross : (∑ v : V, (if cl v = a then f v else 0) * (if cl v = b then f v else 0)) = if a = b then (((Finset.univ : Finset V).filter (fun v => cl v = a)).card : ℤ) else 0 := by by_cases hab : a = b · subst b simp only [if_true] have heq (v : V) : (if cl v = a then f v else 0) * (if cl v = a then f v else 0) = if cl v = a then 1 else 0 := by split_ifs <;> simp_all simp only [heq] simp · simp only [hab, if_false] apply Finset.sum_eq_zero intro v _ split_ifs with ha hb <;> simp_all
Each summand expands as D(a) D(b) - 2 D(b) [cl(v) = a] f(v) - 2 D(a) [cl(v) = b] f(v) + 4 [cl(v) = a] f(v) [cl(v) = b] f(v).
This is the standard algebraic expansion of a product of two binomials (D(a) - 2X)(D(b) - 2Y), verified by ring arithmetic.
have hterm (v : V) : (D a - 2 * (if cl v = a then f v else 0)) * (D b - 2 * (if cl v = b then f v else 0)) = D a * D b - 2 * D b * (if cl v = a then f v else 0) - 2 * D a * (if cl v = b then f v else 0) + 4 * ((if cl v = a then f v else 0) * (if cl v = b then f v else 0)) := by ring
The sum distributes to |V| D(a) D(b) - 4 D(a) D(b) + 4 ∑_{v : V} [cl(v) = a] f(v) · [cl(v) = b] f(v).
We substitute the pointwise expansion and distribute the summation over addition and subtraction, pulling out constant factors. The sum of the constant D(a) D(b) over V equals |V| D(a) D(b). The linear sums over [cl(v) = a] f(v) and [cl(v) = b] f(v) evaluate to D(a) and D(b) respectively by definition, combining to -2 D(b) D(a) - 2 D(a) D(b) = -4 D(a) D(b).
uses
Finset.sum_add_distrib,Finset.sum_sub_distrib,Finset.mul_sum,Finset.sum_const,Finset.card_univ,nsmul_eq_mulsimp_rw [hterm, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum] simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] change D a * ((Fintype.card V : ℤ) * D b) - 2 * D b * D a - 2 * D a * D b + 4 * (∑ v : V, (if cl v = a then f v else 0) * (if cl v = b then f v else 0)) = _
The total sum equals (|V| - 4) D(a) D(b) + 4 |{v : cl(v) = a}| when a = b, and (|V| - 4) D(a) D(b) when a ≠ b.
We substitute the evaluated cross-term sum into the simplified expression. Case-splitting on whether a = b, both cases reduce to polynomial identities in ℤ and are verified by ring arithmetic.
rw [hcross] split_ifs <;> ring
if_true- An if-then-else expression whose condition is True simplifies to the then-branch.
if_false- An if-then-else expression whose condition is False simplifies to the else-branch.
Finset.sum_eq_zero- If every term of a finite sum is zero, the sum is zero.
Finset.sum_add_distrib- A sum of sums over a finite set distributes into the sum of the two individual sums.
Finset.sum_sub_distrib- A sum of differences over a finite set distributes into the difference of the two individual sums.
Finset.mul_sum- Multiplication by a scalar distributes over a finite sum.
Finset.sum_const- The sum of a constant value over a finite set equals the cardinality of the set times the constant.
Finset.card_univ- The cardinality of the universal finset of a finite type equals the cardinality of the type.
nsmul_eq_mul- Scalar multiplication by a natural number n in a semiring is equal to multiplication by n.
Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.
Lean source view module on GitHub
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
theorem op1525_class_imbalance_flip_bilinear_sum {V J : Type*} [DecidableEq J] [Fintype V] (cl : V → J) (f : V → ℤ) (hsgn : ∀ v, f v = 1 ∨ f v = -1) (a b : J) : let D : J → ℤ := fun j => ∑ u : V, if cl u = j then f u else 0 (∑ v : V, (D a - 2 * (if cl v = a then f v else 0)) * (D b - 2 * (if cl v = b then f v else 0))) = ((Fintype.card V : ℤ) - 4) * D a * D b + if a = b then 4 * (((Finset.univ : Finset V).filter (fun v => cl v = a)).card : ℤ) else 0 := by classical dsimp only let D : J → ℤ := fun j => ∑ u : V, if cl u = j then f u else 0 change (∑ v : V, (D a - 2 * (if cl v = a then f v else 0)) * (D b - 2 * (if cl v = b then f v else 0))) = _ have hs (v : V) : f v * f v = 1 := by rcases hsgn v with h | h <;> rw [h] <;> norm_num have hcross : (∑ v : V, (if cl v = a then f v else 0) * (if cl v = b then f v else 0)) = if a = b then (((Finset.univ : Finset V).filter (fun v => cl v = a)).card : ℤ) else 0 := by by_cases hab : a = b · subst b simp only [if_true] have heq (v : V) : (if cl v = a then f v else 0) * (if cl v = a then f v else 0) = if cl v = a then 1 else 0 := by split_ifs <;> simp_all simp only [heq] simp · simp only [hab, if_false] apply Finset.sum_eq_zero intro v _ split_ifs with ha hb <;> simp_all have hterm (v : V) : (D a - 2 * (if cl v = a then f v else 0)) * (D b - 2 * (if cl v = b then f v else 0)) = D a * D b - 2 * D b * (if cl v = a then f v else 0) - 2 * D a * (if cl v = b then f v else 0) + 4 * ((if cl v = a then f v else 0) * (if cl v = b then f v else 0)) := by ring simp_rw [hterm, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum] simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] change D a * ((Fintype.card V : ℤ) * D b) - 2 * D b * D a - 2 * D a * D b + 4 * (∑ v : V, (if cl v = a then f v else 0) * (if cl v = b then f v else 0)) = _ rw [hcross] split_ifs <;> ring