4.4 More subtractive methods
4.4.1 Sums with varying signs
Let \(n\in \mathbb {N}\) and \(d\in \mathbb {N}\). An \(n\)-tuple \(\left( x_{1},x_{2},\ldots ,x_{n}\right) \in \left[ d\right] ^{n}\) is said to be all-even if each element of \(\left[ d\right] \) occurs an even number of times in this \(n\)-tuple (i.e., if for each \(k\in \left[ d\right] \), the number of all \(i\in \left[ n\right] \) satisfying \(x_{i}=k\) is even).
In the Lean formalization, sign tuples \(\left(e_1, e_2, \ldots , e_d\right) \in \{ 1, -1\} ^d\) are represented as functions \(e : \operatorname {Fin} d \to \mathbb {Z}/2\mathbb {Z}\), where \(0\) represents \(+1\) and \(1\) represents \(-1\). The conversion is performed by a sign conversion function. The product \(e_{x_1} e_{x_2} \cdots e_{x_n}\) is represented by a sign product function, and the sum \(e_1 + e_2 + \cdots + e_d\) (in \(\mathbb {Z}\)) by a sign sum function.
For an \(n\)-tuple \(x : \operatorname {Fin} n \to \operatorname {Fin} d\) and \(k \in \operatorname {Fin} d\), the multiplicity of \(k\) in \(x\) is the number of all \(i \in \operatorname {Fin} n\) satisfying \(x(i) = k\).
The function \(\operatorname {toSign} : \mathbb {Z}/2\mathbb {Z} \to \mathbb {Z}\) converts elements of \(\mathbb {Z}/2\mathbb {Z}\) to signs: \(\operatorname {toSign}(0) = 1\) and \(\operatorname {toSign}(1) = -1\).
For a sign tuple \(e : \operatorname {Fin} d \to \mathbb {Z}/2\mathbb {Z}\) and an index tuple \(x : \operatorname {Fin} n \to \operatorname {Fin} d\), the sign product is
For a sign tuple \(e : \operatorname {Fin} d \to \mathbb {Z}/2\mathbb {Z}\), the sign sum is the integer
The set of all-even \(n\)-tuples in \([d]^n\) is
Let \(n\in \mathbb {N}\) and \(d\in \mathbb {N}\). Then, the number of all all-even \(n\)-tuples \(\left( x_{1},x_{2},\ldots ,x_{n}\right) \in \left[ d\right] ^{n}\) is
More precisely (avoiding division), the number of all-even \(n\)-tuples multiplied by \(2^d\) equals \(\sum _{k=0}^{d}\binom {d}{k}(d-2k)^n\).
Lemma 4.80 yields
By Lemma 4.90 (which splits according to whether each tuple is all-even or not, using Lemma 4.88 and Lemma 4.89), the right-hand side equals \((\text{\# of all-even tuples}) \cdot 2^d\).
On the other hand, a \(d\)-tuple \(\left( e_{1},e_{2},\ldots ,e_{d}\right) \in \left\{ 1,-1\right\} ^{d}\) is uniquely determined by the set \(S = \left\{ i\in \left[ d\right] \ \mid \ e_{i}=-1\right\} \), and for this tuple we have \(e_{1}+e_{2}+\cdots +e_{d}=d-2\left\vert S\right\vert \). By Lemma 4.96, we can rewrite the sum over sign tuples as a sum over subsets. By Lemma 4.97, grouping by cardinality \(|S| = k\) yields
Comparing the two expressions gives
4.4.2 Lemmas for the proof
Let \(n,d\in \mathbb {N}\). Let \(e = (e_1, \ldots , e_d) \in \{ 1,-1\} ^d\) and \(x = (x_1, \ldots , x_n) \in [d]^n\). For each \(k \in [d]\), let \(m_k\) be the multiplicity of \(k\) in \(x\). Then
Each factor of the product \(e_{x_{1}}e_{x_{2}}\cdots e_{x_{n}}\) is one of the \(d\) entries \(e_{1},e_{2},\ldots ,e_{d}\). Moreover, each given entry \(e_{k}\) appears exactly \(m_{k}\) times in the product \(e_{x_{1}}e_{x_{2}}\cdots e_{x_{n}}\), because \(k\) appears exactly \(m_{k}\) times among the subscripts \(x_{1},x_{2},\ldots ,x_{n}\). Thus the product equals \(e_{1}^{m_{1}}e_{2}^{m_{2}}\cdots e_{d}^{m_{d}}\).
Let \(n,d\in \mathbb {N}\). Then,
For each \(\left( e_{1},e_{2},\ldots ,e_{d}\right) \in \left\{ 1,-1\right\} ^{d}\), we have
(by the generalized distributive law / product rule). Summing over all \(\left( e_{1},e_{2},\ldots ,e_{d}\right) \in \left\{ 1,-1\right\} ^{d}\) and interchanging the order of summation yields the result.
Let \(n,d\in \mathbb {N}\). Let \(\left( x_{1},x_{2},\ldots ,x_{n}\right) \in \left[ d\right] ^{n}\).
(a) If the \(n\)-tuple \(\left( x_{1},x_{2},\ldots ,x_{n}\right)\) is not all-even, then \(\sum _{\left( e_{1},\ldots ,e_{d}\right) \in \left\{ 1,-1\right\} ^{d}} e_{x_{1}}e_{x_{2}}\cdots e_{x_{n}}=0\).
(b) If the \(n\)-tuple \(\left( x_{1},x_{2},\ldots ,x_{n}\right)\) is all-even, then \(\sum _{\left( e_{1},\ldots ,e_{d}\right) \in \left\{ 1,-1\right\} ^{d}} e_{x_{1}}e_{x_{2}}\cdots e_{x_{n}}=2^{d}\).
This combines parts (a) and (b).
4.4.3 Involution argument for part (a)
For \(k \in [d]\), the map \(\operatorname {flipSign}_k : \{ 1,-1\} ^d \to \{ 1,-1\} ^d\) sends a \(d\)-tuple \((e_1, \ldots , e_d)\) to the tuple obtained by flipping the sign of the \(k\)-th entry: i.e., replacing \(e_k\) by \(-e_k\) and leaving all other entries unchanged.
- AlgebraicCombinatorics.SubtractiveMethods.flipSign k e = Function.update e k (e k + 1)
For any \(k \in [d]\), the map \(\operatorname {flipSign}_k\) is an involution.
Flipping the sign of the \(k\)-th entry twice restores the original sign.
For any \(k \in [d]\) and \(e \in \{ 1,-1\} ^d\), we have \(\operatorname {flipSign}_k(e) \neq e\).
Since \(e_k \in \{ 1, -1\} \), flipping the sign of \(e_k\) produces a different value (\(-e_k \neq e_k\)), so the resulting tuple differs from the original.
For any \(k \in [d]\) and \(e \in \{ 1,-1\} ^d\), \((\operatorname {flipSign}_k(e))_k = e_k + 1\) (in \(\mathbb {Z}/2\mathbb {Z}\)).
By definition of \(\operatorname {flipSign}\), which updates position \(k\).
For any \(k, j \in [d]\) with \(j \neq k\) and \(e \in \{ 1,-1\} ^d\), \((\operatorname {flipSign}_k(e))_j = e_j\).
The update only affects position \(k\), so all other positions are unchanged.
Let \(e \in \{ 1,-1\} ^d\), \(x \in [d]^n\), and \(k \in [d]\) such that the multiplicity \(m_k\) of \(k\) in \(x\) is odd. Then
Using the product-of-powers representation (Lemma 4.79), flipping the \(k\)-th entry multiplies the product by \((-1)^{m_k} = -1\) (since \(m_k\) is odd), while all other factors remain unchanged.
Let \(n,d\in \mathbb {N}\). Let \(\left( x_{1},x_{2},\ldots ,x_{n}\right) \in \left[ d\right] ^{n}\). If the \(n\)-tuple \(\left( x_{1},x_{2},\ldots ,x_{n}\right) \) is not all-even, then
Since the tuple is not all-even, there exists some \(k\in \left[ d\right] \) such that \(m_{k}\) is odd.
Define \(f:\left\{ 1,-1\right\} ^{d}\rightarrow \left\{ 1,-1\right\} ^{d}\) as \(\operatorname {flipSign}_k\) (flipping the sign of the \(k\)-th entry). By Lemma 4.83, \(f\) is an involution. By Lemma 4.84, \(f\) has no fixed points. By Lemma 4.87, \(\operatorname {signProduct}(f(e), x) = -\operatorname {signProduct}(e, x)\).
Hence, the terms cancel in pairs, giving
The Lean proof uses the involution summation lemma from Mathlib.
Let \(n,d\in \mathbb {N}\). Let \(\left( x_{1},x_{2},\ldots ,x_{n}\right) \in \left[ d\right] ^{n}\). If the \(n\)-tuple \(\left( x_{1},x_{2},\ldots ,x_{n}\right) \) is all-even, then
Since the tuple is all-even, all the multiplicities \(m_{1},m_{2},\ldots ,m_{d}\) are even.
Let \(\left( e_{1},e_{2},\ldots ,e_{d}\right) \in \left\{ 1,-1\right\} ^{d}\). For each \(k\in \left[ d\right] \), we have \(e_{k}\in \left\{ 1,-1\right\} \) and \(m_{k}\) is even, so \(e_{k}^{m_{k}}=1\). By Lemma 4.79, \(e_{x_{1}}e_{x_{2}}\cdots e_{x_{n}} = e_{1}^{m_{1}}e_{2}^{m_{2}}\cdots e_{d}^{m_{d}} = 1\).
Since every sign product equals \(1\) and there are \(2^d\) sign tuples,
Let \(n,d\in \mathbb {N}\). Then
4.4.4 Computing the left-hand side
For a sign tuple \(e \in \{ 1,-1\} ^d\), let \(S = \{ i \in [d] \mid e_i = -1\} \). Then
Each entry \(e_i\) equals \(-1\) if \(i \in S\) and \(1\) if \(i \notin S\). The sum has \(|S|\) addends equal to \(-1\) and \(d - |S|\) addends equal to \(1\), giving \(|S| \cdot (-1) + (d - |S|) \cdot 1 = d - 2|S|\).
The map \(\operatorname {signTupleToSubset} : (\operatorname {Fin} d \to \mathbb {Z}/2\mathbb {Z}) \to \mathcal{P}(\operatorname {Fin} d)\) sends a sign tuple \(e\) to the set \(S = \{ k \in \operatorname {Fin} d \mid e_k = 1\} \) (i.e., the positions where \(\operatorname {toSign}(e_k) = -1\)).
The inverse map \(\operatorname {subsetToSignTuple} : \mathcal{P}(\operatorname {Fin} d) \to (\operatorname {Fin} d \to \mathbb {Z}/2\mathbb {Z})\) sends a subset \(S \subseteq \operatorname {Fin} d\) to the sign tuple where position \(k\) has value \(1\) (representing \(-1\)) if \(k \in S\), and \(0\) (representing \(+1\)) otherwise.
There is a bijection between sign tuples \(\{ 1,-1\} ^d\) and subsets of \([d]\), sending each tuple \(e\) to the set \(S = \{ i \in [d] \mid e_i = -1\} \).
The inverse sends a subset \(S \subseteq [d]\) to the sign tuple where position \(k\) has \(e_k = -1\) if \(k \in S\) and \(e_k = 1\) otherwise.
For a subset \(S \subseteq [d]\), the sign sum of the corresponding sign tuple is
By Lemma 4.91, the sign sum equals \(d - 2|T|\) where \(T = \operatorname {signTupleToSubset}(\operatorname {subsetToSignTuple}(S)) = S\).
Let \(n,d\in \mathbb {N}\). Then
Let \(n,d\in \mathbb {N}\). Then
Split the sum over subsets \(S\) according to the value of \(|S| = k\). For each \(k\), all subsets of size \(k\) contribute the same summand \((d-2k)^n\), and the number of \(k\)-element subsets of \([d]\) is \(\binom {d}{k}\).
4.4.5 Helper lemmas for toSign
For any \(b \in \mathbb {Z}/2\mathbb {Z}\), we have \((\operatorname {toSign} b)^2 = 1\).
By case analysis: both \(1^2 = 1\) and \((-1)^2 = 1\).
For any \(b \in \mathbb {Z}/2\mathbb {Z}\) and even \(m \in \mathbb {N}\), we have \((\operatorname {toSign} b)^m = 1\).
Write \(m = 2k\). Then \((\operatorname {toSign} b)^m = ((\operatorname {toSign} b)^2)^k = 1^k = 1\).
For any \(b \in \mathbb {Z}/2\mathbb {Z}\) and odd \(m \in \mathbb {N}\), we have \((\operatorname {toSign} b)^m = \operatorname {toSign} b\).
Write \(m = 2k + 1\). Then \((\operatorname {toSign} b)^m = ((\operatorname {toSign} b)^2)^k \cdot \operatorname {toSign} b = 1^k \cdot \operatorname {toSign} b = \operatorname {toSign} b\).
For any \(b \in \mathbb {Z}/2\mathbb {Z}\), we have \(\operatorname {toSign}(b+1) = -\operatorname {toSign}(b)\).
By case analysis on \(b \in \{ 0, 1\} \): adding \(1\) in \(\mathbb {Z}/2\mathbb {Z}\) toggles between \(0\) and \(1\), and \(\operatorname {toSign}(0) = 1 = -(-1) = -\operatorname {toSign}(1)\) while \(\operatorname {toSign}(1) = -1 = -(1) = -\operatorname {toSign}(0)\).
4.4.6 Corollaries of the counting formula
For any \(n, d \in \mathbb {N}\), we have
By Theorem 4.78, the sum equals \((\text{\# of all-even tuples}) \cdot 2^d\), which is divisible by \(2^d\).
For any \(n, d \in \mathbb {N}\), we have
This is not obvious from the formula when \(n\) is odd, since the summands can be negative.
By Theorem 4.78, the sum equals \((\text{\# of all-even tuples}) \cdot 2^d\), which is a product of two nonnegative integers.