op874_cycle_difference_labels_integrate
On any nonempty cycle, assign one of the three nonzero two-bit differences to each position. If every difference occurs with the same parity as the cycle length, these differences integrate to a cyclic assignment of four two-bit colors, with neighboring colors distinct and with the prescribed difference at every position.
Statement
theorem op874_cycle_difference_labels_integrate (n : ℕ) [NeZero n] (d : Fin n → Fin 3) (hparity : ∀ t : Fin 3, ((Finset.univ : Finset (Fin n)).filter fun i => d i = t).card % 2 = n % 2) : ∃ h : Fin n → Fin 4, ∀ i : Fin n, h i ≠ h (i + 1) ∧ Nat.xor (h i).val (h (i + 1)).val = (d i).val + 1
- Source
- OP-874: four high colors represented as two-bit vectors
- Verified
- 22 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext
The proof, explained
The theorem identifies the four colors with the elements of (Z/2Z)^2 (modeled as Bool × Bool) and their binary encodings in Fin 4, where vector addition corresponds to bitwise XOR. Grouping the difference labels fiberwise shows that the total sum of differences along the cycle vanishes in (Z/2Z)^2, because the sum of all three nonzero differences is zero and every label appears with the same parity as the cycle length. The desired coloring is then constructed by integrating the differences as prefix sums: adjacent colors differ by the prescribed nonzero difference (both within the cycle and across the wrap-around boundary), which in turn guarantees that neighboring colors are distinct.
The formula (v.1 ? 1 : 0) + 2 * (v.2 ? 1 : 0) evaluates to an integer strictly less than 4 for any pair of booleans v, defining a valid map into Fin 4.
Case analysis on the two boolean components false and true shows the expression always lies in {0, 1, 2, 3}, which is less than 4.
⟨(if v.1 then 1 else 0) + 2 * (if v.2 then 1 else 0), by cases v.1 <;> cases v.2 <;> decide⟩
For each label t ∈ Fin 3, the integer encoding of the difference vector op874_cycle_diffBB t equals t.val + 1.
Case exhaustion over t ∈ {0, 1, 2} confirms by direct computation that the difference vectors (true, false), (false, true), and (true, true) encode to 1, 2, and 3 respectively.
lemma op874_cycle_fromBB_diffBB (t : Fin 3) : (op874_cycle_fromBB (op874_cycle_diffBB t)).val = t.val + 1 := by fin_cases t <;> rfl
Vector addition in Bool × Bool corresponds to bitwise XOR on the integer encodings: val(fromBB v) ^^^ val(fromBB (v + w)) = val(fromBB w).
Exhaustive case analysis on all 16 boolean assignments for the components of v and w confirms the algebraic identity by direct evaluation.
lemma op874_cycle_xor_fromBB (v w : Bool × Bool) : Nat.xor (op874_cycle_fromBB v).val (op874_cycle_fromBB (v + w)).val = (op874_cycle_fromBB w).val := by cases v; cases w; rename_i a b c d cases a <;> cases b <;> cases c <;> cases d <;> rfl
Bitwise XOR of the integer encoding of v with that of the zero vector leaves the value unchanged.
Evaluating all four boolean pairs confirms that the zero vector encodes as 0, and XOR with 0 is the identity.
lemma op874_cycle_xor_fromBB_zero (v : Bool × Bool) : Nat.xor (op874_cycle_fromBB v).val (op874_cycle_fromBB 0).val = (op874_cycle_fromBB v).val := by cases v; rename_i a b cases a <;> cases b <;> rfl
In Bool × Bool, if v + w = 0, then v = w.
Addition in Bool × Bool is componentwise XOR, where every element is its own inverse; verified by finite boolean exhaustion.
lemma op874_cycle_bool_prod_eq_of_add_eq_zero {v w : Bool × Bool} (h : v + w = 0) : v = w := by cases v; cases w; rename_i a b c d ext <;> (revert a b c d; decide)
For any natural number c and vector x ∈ Bool × Bool, scalar multiplication satisfies c • x = (c % 2) • x.
Because 2 • x = 0 for any x, writing c = 2 * (c / 2) + c % 2 via Euclidean division causes the even part to vanish, leaving (c % 2) • x.
uses
add_smul,mul_smul,smul_zero,zero_addlemma op874_cycle_smul_bool_prod (c : ℕ) (x : Bool × Bool) : c • x = (c % 2) • x := by have h2 : (2 : ℕ) • x = 0 := by cases x; rename_i a b ext <;> (cases a <;> cases b <;> rfl) have hd : c = c / 2 * 2 + c % 2 := by omega nth_rw 1 [hd] rw [add_smul, mul_smul, h2, smul_zero, zero_add]
The sum of all three nonzero difference vectors in Bool × Bool is (0, 0).
The sum (true, false) + (false, true) + (true, true) equals (false, false) in both boolean coordinates by direct evaluation.
lemma op874_cycle_sum_diffBB : ∑ t : Fin 3, op874_cycle_diffBB t = 0 := by change op874_cycle_diffBB 0 + op874_cycle_diffBB 1 + op874_cycle_diffBB 2 = 0 ext <;> decide
The total sum of difference vectors along the cycle ∑ i, diff(d i) equals (0, 0).
Grouping the cycle sum fiberwise by difference label j ∈ Fin 3 gives ∑ j, |d⁻¹(j)| • diff(j). Since each fiber size has the same parity as n by hypothesis, this becomes (n % 2) • ∑ j, diff(j). The sum of all three differences is 0, so the entire sum vanishes.
uses
Finset.sum_fiberwise',Finset.sum_const,op874_cycle_smul_bool_prod,Finset.smul_sum,op874_cycle_sum_diffBB,smul_zerolemma op874_cycle_sum_d_zero (n : ℕ) [NeZero n] (d : Fin n → Fin 3) (hparity : ∀ t : Fin 3, ((Finset.univ : Finset (Fin n)).filter fun i => d i = t).card % 2 = n % 2) : ∑ i : Fin n, op874_cycle_diffBB (d i) = 0 := by rw [← Finset.sum_fiberwise' (Finset.univ : Finset (Fin n)) d op874_cycle_diffBB] have h_const : ∀ j : Fin 3, (∑ i ∈ Finset.univ with d i = j, op874_cycle_diffBB j) = (((Finset.univ : Finset (Fin n)).filter fun i => d i = j).card % 2) • op874_cycle_diffBB j := by intro j rw [Finset.sum_const, op874_cycle_smul_bool_prod] simp_rw [h_const, hparity] rw [← Finset.smul_sum, op874_cycle_sum_diffBB, smul_zero]
The prefix sum sequence S(k) = ∑ j < k, F(j) satisfies S(0) = 0 and S(n) = 0.
Extending the differences to F on ℕ by setting F(j) = 0 for j ≥ n, the range sum S(0) is trivially empty, while S(n) matches the total cycle sum ∑ i, diff(d i), which is zero by op874_cycle_sum_d_zero.
uses
Finset.sum_fin_eq_sum_range,op874_cycle_sum_d_zero,Finset.sum_range_zerotheorem op874_cycle_difference_labels_integrate (n : ℕ) [NeZero n] (d : Fin n → Fin 3) (hparity : ∀ t : Fin 3, ((Finset.univ : Finset (Fin n)).filter fun i => d i = t).card % 2 = n % 2) : ∃ h : Fin n → Fin 4, ∀ i : Fin n, h i ≠ h (i + 1) ∧ Nat.xor (h i).val (h (i + 1)).val = (d i).val + 1 := by let F : ℕ → Bool × Bool := fun j => if h : j < n then op874_cycle_diffBB (d ⟨j, h⟩) else 0 let S : ℕ → Bool × Bool := fun k => ∑ j ∈ Finset.range k, F j have hSn : S n = 0 := by have h1 : S n = ∑ i : Fin n, op874_cycle_diffBB (d i) := by exact (Finset.sum_fin_eq_sum_range (fun i => op874_cycle_diffBB (d i))).symm rw [h1, op874_cycle_sum_d_zero n d hparity] have hS0 : S 0 = 0 := Finset.sum_range_zero F
The candidate coloring h(i) = fromBB(S(i.val)) satisfies the single-step recurrence S(i.val + 1) = S(i.val) + diff(d i).
Splitting the last term from the prefix sum S(i.val + 1) yields S(i.val) + F(i.val), and F(i.val) simplifies to diff(d i) because i.val < n.
uses
if_pos,Finset.sum_range_succuse fun i => op874_cycle_fromBB (S i.val) intro i have hF : F i.val = op874_cycle_diffBB (d i) := by dsimp [F] exact if_pos i.isLt have hS_succ : S (i.val + 1) = S i.val + op874_cycle_diffBB (d i) := by dsimp [S] rw [Finset.sum_range_succ, hF]
For every non-wrap-around step i.val + 1 < n, the XOR difference of adjacent colors is (d i).val + 1.
When i.val + 1 < n, the successor index in Fin n has numerical value i.val + 1. Rewriting with the recurrence S(i.val + 1) = S(i.val) + diff(d i) and using op874_cycle_xor_fromBB reduces the color XOR to the encoding of diff(d i), which equals (d i).val + 1.
uses
Fin.val_add,Fin.val_one',Nat.mod_eq_of_lt,op874_cycle_xor_fromBB,op874_cycle_fromBB_diffBBhave hxor : Nat.xor (op874_cycle_fromBB (S i.val)).val (op874_cycle_fromBB (S (i + 1).val)).val = (d i).val + 1 := by by_cases hlt : i.val + 1 < n · have h_succ : (i + 1).val = i.val + 1 := by have hn : 1 < n := by omega rw [Fin.val_add, Fin.val_one' n, Nat.mod_eq_of_lt hn, Nat.mod_eq_of_lt hlt] rw [h_succ, hS_succ, op874_cycle_xor_fromBB, op874_cycle_fromBB_diffBB]
For the wrap-around step i.val + 1 = n, the XOR difference of adjacent colors is also (d i).val + 1.
At the boundary, the successor index wraps around to 0, so h(i + 1) is fromBB(S(0)) = fromBB(0). Since S(n) = 0 and S(n) = S(i.val) + diff(d i), self-inversion in Bool × Bool implies S(i.val) = diff(d i). The XOR difference is then val(fromBB(diff(d i))) ^^^ val(fromBB(0)), which equals (d i).val + 1.
uses
Subsingleton.elim,Fin.val_add,Fin.val_one',Nat.mod_eq_of_lt,Nat.mod_self,op874_cycle_bool_prod_eq_of_add_eq_zero,op874_cycle_xor_fromBB_zero,op874_cycle_fromBB_diffBB· have heq : i.val + 1 = n := by have := i.isLt omega have h_zero : (i + 1).val = 0 := by by_cases hn : n = 1 · subst hn have : i = 0 := Subsingleton.elim _ _ subst this rfl · have hn1 : 1 < n := by omega rw [Fin.val_add, Fin.val_one' n, Nat.mod_eq_of_lt hn1, heq, Nat.mod_self] rw [h_zero, hS0] have hS_eq : S i.val = op874_cycle_diffBB (d i) := by have htmp := hS_succ rw [heq, hSn] at htmp exact op874_cycle_bool_prod_eq_of_add_eq_zero htmp.symm rw [hS_eq, op874_cycle_xor_fromBB_zero, op874_cycle_fromBB_diffBB]
Adjacent colors are distinct (h(i) ≠ h(i + 1)) for all i, completing the proof.
If h(i) = h(i + 1), their values would be equal, so their bitwise XOR would be 0 by Nat.xor_self. But the XOR was proven to be (d i).val + 1 ≥ 1 > 0, an immediate arithmetic contradiction.
uses
congrArg,Nat.xor_selfrefine ⟨?_, hxor⟩ intro h_eq have h_val_eq : (op874_cycle_fromBB (S i.val)).val = (op874_cycle_fromBB (S (i + 1).val)).val := congrArg Fin.val h_eq have h_contr := hxor rw [h_val_eq] at h_contr have h_zero_xor : Nat.xor (op874_cycle_fromBB (S (i + 1).val)).val (op874_cycle_fromBB (S (i + 1).val)).val = 0 := Nat.xor_self _ rw [h_zero_xor] at h_contr omega
add_smul- Scalar multiplication distributes over addition of scalars: (r + s) • x = r • x + s • x.
mul_smul- Scalar multiplication by a product is iterated scalar multiplication: (x * y) • b = x • y • b.
smul_zero- Scalar multiplication of the zero vector by any scalar yields zero: a • 0 = 0.
zero_add- Adding zero on the left is the identity: 0 + a = a.
Finset.sum_fiberwise'- Summing a function over the fibers of a map partition equals summing the function over the entire set.
Finset.sum_const- The sum of a constant value b over a finite set s is equal to |s| • b.
op874_cycle_smul_bool_prod- In Bool × Bool, scalar multiplication by a natural number c depends only on c mod 2: c • x = (c % 2) • x.
Finset.smul_sum- Scalar multiplication distributes over a finite sum: r • ∑ x ∈ s, f x = ∑ x ∈ s, r • f x.
op874_cycle_sum_diffBB- The sum of the three nonzero difference vectors in Bool × Bool is (0, 0).
Finset.sum_fin_eq_sum_range- A sum over Fin n equals the sum over the integer range {0, ..., n-1} of the function extended by zero.
op874_cycle_sum_d_zero- If every difference label occurs with the same parity as the cycle length n, the sum of all difference vectors along the cycle is zero.
Finset.sum_range_zero- The sum over the empty range {0, ..., -1} is zero.
if_pos- An if-then-else expression evaluates to the then-branch when the condition is true.
Finset.sum_range_succ- A range sum over {0, ..., n} equals the sum over {0, ..., n-1} plus the term at n.
Fin.val_add- The numerical value of the sum of two elements in Fin n is the sum of their values modulo n.
Fin.val_one'- The numerical value of 1 in Fin n is 1 mod n when n is positive.
Nat.mod_eq_of_lt- A natural number strictly less than a modulus equals its remainder modulo that modulus.
op874_cycle_xor_fromBB- Bitwise XOR of the integer encodings of two vectors v and v + w equals the integer encoding of w.
op874_cycle_fromBB_diffBB- The integer encoding of the difference vector for label t is t.val + 1.
Subsingleton.elim- Any two elements of a subsingleton type are equal.
Nat.mod_self- Any natural number modulo itself is zero.
op874_cycle_bool_prod_eq_of_add_eq_zero- In Bool × Bool, if v + w = 0, then v = w.
op874_cycle_xor_fromBB_zero- Bitwise XOR of the integer encoding of v with the encoding of zero leaves the value unchanged.
congrArg- Applying a function to equal arguments produces equal results.
Nat.xor_self- The bitwise XOR of any natural number with itself is zero.
- The proof models the Klein four-group (Z/2Z)^2 formally as the product Bool × Bool under componentwise addition (XOR), and identifies it with Fin 4 via binary encoding.
- The cycle sum is handled by extending the difference sequence to a function F on the natural numbers that is zero outside [0, n), expressing cycle integration via standard prefix sums over Finset.range.
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.
open BigOperatorsdef op874_cycle_diffBB (t : Fin 3) : Bool × Bool := match t with | 0 => (true, false) | 1 => (false, true) | 2 => (true, true)def op874_cycle_fromBB (v : Bool × Bool) : Fin 4 := ⟨(if v.1 then 1 else 0) + 2 * (if v.2 then 1 else 0), by cases v.1 <;> cases v.2 <;> decide⟩lemma op874_cycle_fromBB_diffBB (t : Fin 3) : (op874_cycle_fromBB (op874_cycle_diffBB t)).val = t.val + 1 := by fin_cases t <;> rfllemma op874_cycle_xor_fromBB (v w : Bool × Bool) : Nat.xor (op874_cycle_fromBB v).val (op874_cycle_fromBB (v + w)).val = (op874_cycle_fromBB w).val := by cases v; cases w; rename_i a b c d cases a <;> cases b <;> cases c <;> cases d <;> rfllemma op874_cycle_xor_fromBB_zero (v : Bool × Bool) : Nat.xor (op874_cycle_fromBB v).val (op874_cycle_fromBB 0).val = (op874_cycle_fromBB v).val := by cases v; rename_i a b cases a <;> cases b <;> rfllemma op874_cycle_bool_prod_eq_of_add_eq_zero {v w : Bool × Bool} (h : v + w = 0) : v = w := by cases v; cases w; rename_i a b c d ext <;> (revert a b c d; decide)lemma op874_cycle_smul_bool_prod (c : ℕ) (x : Bool × Bool) : c • x = (c % 2) • x := by have h2 : (2 : ℕ) • x = 0 := by cases x; rename_i a b ext <;> (cases a <;> cases b <;> rfl) have hd : c = c / 2 * 2 + c % 2 := by omega nth_rw 1 [hd] rw [add_smul, mul_smul, h2, smul_zero, zero_add]lemma op874_cycle_sum_diffBB : ∑ t : Fin 3, op874_cycle_diffBB t = 0 := by change op874_cycle_diffBB 0 + op874_cycle_diffBB 1 + op874_cycle_diffBB 2 = 0 ext <;> decidelemma op874_cycle_sum_d_zero (n : ℕ) [NeZero n] (d : Fin n → Fin 3) (hparity : ∀ t : Fin 3, ((Finset.univ : Finset (Fin n)).filter fun i => d i = t).card % 2 = n % 2) : ∑ i : Fin n, op874_cycle_diffBB (d i) = 0 := by rw [← Finset.sum_fiberwise' (Finset.univ : Finset (Fin n)) d op874_cycle_diffBB] have h_const : ∀ j : Fin 3, (∑ i ∈ Finset.univ with d i = j, op874_cycle_diffBB j) = (((Finset.univ : Finset (Fin n)).filter fun i => d i = j).card % 2) • op874_cycle_diffBB j := by intro j rw [Finset.sum_const, op874_cycle_smul_bool_prod] simp_rw [h_const, hparity] rw [← Finset.smul_sum, op874_cycle_sum_diffBB, smul_zero]theorem op874_cycle_difference_labels_integrate (n : ℕ) [NeZero n] (d : Fin n → Fin 3) (hparity : ∀ t : Fin 3, ((Finset.univ : Finset (Fin n)).filter fun i => d i = t).card % 2 = n % 2) : ∃ h : Fin n → Fin 4, ∀ i : Fin n, h i ≠ h (i + 1) ∧ Nat.xor (h i).val (h (i + 1)).val = (d i).val + 1 := by let F : ℕ → Bool × Bool := fun j => if h : j < n then op874_cycle_diffBB (d ⟨j, h⟩) else 0 let S : ℕ → Bool × Bool := fun k => ∑ j ∈ Finset.range k, F j have hSn : S n = 0 := by have h1 : S n = ∑ i : Fin n, op874_cycle_diffBB (d i) := by exact (Finset.sum_fin_eq_sum_range (fun i => op874_cycle_diffBB (d i))).symm rw [h1, op874_cycle_sum_d_zero n d hparity] have hS0 : S 0 = 0 := Finset.sum_range_zero F use fun i => op874_cycle_fromBB (S i.val) intro i have hF : F i.val = op874_cycle_diffBB (d i) := by dsimp [F] exact if_pos i.isLt have hS_succ : S (i.val + 1) = S i.val + op874_cycle_diffBB (d i) := by dsimp [S] rw [Finset.sum_range_succ, hF] have hxor : Nat.xor (op874_cycle_fromBB (S i.val)).val (op874_cycle_fromBB (S (i + 1).val)).val = (d i).val + 1 := by by_cases hlt : i.val + 1 < n · have h_succ : (i + 1).val = i.val + 1 := by have hn : 1 < n := by omega rw [Fin.val_add, Fin.val_one' n, Nat.mod_eq_of_lt hn, Nat.mod_eq_of_lt hlt] rw [h_succ, hS_succ, op874_cycle_xor_fromBB, op874_cycle_fromBB_diffBB] · have heq : i.val + 1 = n := by have := i.isLt omega have h_zero : (i + 1).val = 0 := by by_cases hn : n = 1 · subst hn have : i = 0 := Subsingleton.elim _ _ subst this rfl · have hn1 : 1 < n := by omega rw [Fin.val_add, Fin.val_one' n, Nat.mod_eq_of_lt hn1, heq, Nat.mod_self] rw [h_zero, hS0] have hS_eq : S i.val = op874_cycle_diffBB (d i) := by have htmp := hS_succ rw [heq, hSn] at htmp exact op874_cycle_bool_prod_eq_of_add_eq_zero htmp.symm rw [hS_eq, op874_cycle_xor_fromBB_zero, op874_cycle_fromBB_diffBB] refine ⟨?_, hxor⟩ intro h_eq have h_val_eq : (op874_cycle_fromBB (S i.val)).val = (op874_cycle_fromBB (S (i + 1).val)).val := congrArg Fin.val h_eq have h_contr := hxor rw [h_val_eq] at h_contr have h_zero_xor : Nat.xor (op874_cycle_fromBB (S (i + 1).val)).val (op874_cycle_fromBB (S (i + 1).val)).val = 0 := Nat.xor_self _ rw [h_zero_xor] at h_contr omega