AFTD Auto-Formalizing Theoretical Domains

cycle_square_four_colorable_except_five

theoremverified

Every cycle with at least three vertices except a five-cycle has a four-coloring of its square.

Statement

theorem cycle_square_four_colorable_except_five
    (n : ℕ) [NeZero n] (hn : 3 ≤ n) (hfive : n ≠ 5) :
    ∃ c : Fin n → Fin 4,
      ∀ i, c i ≠ c (i+1) ∧ c i ≠ c (i+2)
Source
Square-coloring input to the cycle demand reduction for OP-874.
Verified
24 Nov 2026
Axioms
Classical.choiceQuot.soundpropext

The proof, explained

To 4-color the square of a cycle C_n for n ≥ 3 and n ≠ 5, we partition n into 3a + 4b using non-negative integers a, b. We then partition the vertices into a block of size 3a colored periodically with 3 colors and a block of size 4b colored periodically with 4 colors. The arithmetic properties of this coloring guarantee that no two vertices at distance 1 or 2 share a color.

  1. The coloring values are strictly less than 4 automation

    Unfolding the definition of the coloring function, each branch evaluates either to k % 3 or (k - 3 * a) % 4, both of which are strictly less than 4 by integer arithmetic.

    lines 6–7

      dsimp [cycle_square_four_colorable_except_five_color_val]
      split_ifs <;> omega
  2. Adjacent vertices receive distinct colors automation

    We unfold the coloring function and split on whether k + 1 < n. If k + 1 < n, (k + 1) % n = k + 1; otherwise k + 1 = n and (k + 1) % n = 0. In all cases, linear arithmetic confirms that the colors of k and (k + 1) % n differ.

    lines 13–22

    uses Nat.mod_eq_of_lt, Nat.mod_self

      dsimp [cycle_square_four_colorable_except_five_color_val]
      by_cases hk1 : k + 1 < n
      · have h1 : (k + 1) % n = k + 1 := Nat.mod_eq_of_lt hk1
        rw [h1]
        split_ifs <;> omega
      · have h1 : (k + 1) % n = 0 := by
          have : k + 1 = n := by omega
          rw [this, Nat.mod_self]
        rw [h1]
        split_ifs <;> omega
  3. Vertices at distance two receive distinct colors automation

    We unfold the coloring function and consider the three cases for k + 2 relative to n: k + 2 < n, k + 2 = n, and k + 2 = n + 1. In each case, the modular reduction is computed and linear integer arithmetic verifies that the colors cannot coincide.

    lines 28–43

    uses Nat.add_mod_right, Nat.mod_eq_of_lt, Nat.mod_self, eq_or_lt_of_le, lt_or_ge

      dsimp [cycle_square_four_colorable_except_five_color_val]
      rcases lt_or_ge (k + 2) n with hk2 | hk2
      · have h1 : (k + 2) % n = k + 2 := Nat.mod_eq_of_lt hk2
        rw [h1]
        split_ifs <;> omega
      · rcases eq_or_lt_of_le hk2 with heq | hgt
        · have h1 : (k + 2) % n = 0 := by
            rw [heq, Nat.mod_self]
          rw [h1]
          split_ifs <;> omega
        · have h1 : (k + 2) % n = 1 := by
            have : k + 2 = 1 + n := by omega
            rw [this, Nat.add_mod_right]
            exact Nat.mod_eq_of_lt (by omega)
          rw [h1]
          split_ifs <;> omega
  4. Every integer n ≥ 3 with n ≠ 5 can be represented as 3a + 4b automation

    We inspect n modulo 3. If n % 3 = 0, choose b = 0 and a = n / 3. If n % 3 = 1, since n ≥ 3 and n ≠ 5 (so n ≥ 4), choose b = 1 and a = (n - 4) / 3. If n % 3 = 2, since n ≥ 3 and n ≠ 5 (so n ≥ 8), choose b = 2 and a = (n - 8) / 3. Linear arithmetic verifies 3a + 4b = n in each branch.

    lines 48–52

      have hmod : n % 3 = 0 ∨ n % 3 = 1 ∨ n % 3 = 2 := by omega
      rcases hmod with h0 | h1 | h2
      · use n / 3, 0; omega
      · use (n - 4) / 3, 1; omega
      · use (n - 8) / 3, 2; omega
  5. We obtain coefficients a and b and define the vertex coloring

    Using the representation lemma, we obtain non-negative integers a and b such that 3a + 4b = n. We then define the coloring function c by assigning to vertex i the color cycle_square_four_colorable_except_five_color_val a i.val, which is valid since its value is bounded by 4.

    lines 58–62

    uses cycle_square_four_colorable_except_five_color_val_lt_four, cycle_square_four_colorable_except_five_exists_rep

      obtain ⟨a, b, hab⟩ := cycle_square_four_colorable_except_five_exists_rep n hn hfive
      let c : Fin n → Fin 4 := fun i =>
        ⟨cycle_square_four_colorable_except_five_color_val a i.val,
         cycle_square_four_colorable_except_five_color_val_lt_four a i.val⟩
      use c
  6. Adjacent vertices on the cycle receive different colors

    Assuming c i = c (i + 1), we equate their values. Since (i + 1 : Fin n).val = (i.val + 1) % n, this contradicts the previously proved lemma that consecutive vertices receive different colors.

    lines 63–73

    uses Fin.val_add, Nat.mod_eq_of_lt, cycle_square_four_colorable_except_five_color_val_ne_add_one

      intro i
      constructor
      · intro h
        have hval : (c i).val = (c (i + 1)).val := by rw [h]
        dsimp [c] at hval
        have h1 : (i + 1 : Fin n).val = (i.val + 1) % n := by
          rw [Fin.val_add]
          have : (1 : Fin n).val = 1 := Nat.mod_eq_of_lt (by show 1 < n; omega)
          rw [this]
        rw [h1] at hval
        exact cycle_square_four_colorable_except_five_color_val_ne_add_one a b n hab i.val i.is_lt hval
  7. Vertices at distance two on the cycle receive different colors

    Assuming c i = c (i + 2), we equate their values. Since (i + 2 : Fin n).val = (i.val + 2) % n, this contradicts the lemma that vertices at distance two receive different colors.

    lines 74–82

    uses Fin.val_add, Nat.mod_eq_of_lt, cycle_square_four_colorable_except_five_color_val_ne_add_two

      · intro h
        have hval : (c i).val = (c (i + 2)).val := by rw [h]
        dsimp [c] at hval
        have h2 : (i + 2 : Fin n).val = (i.val + 2) % n := by
          rw [Fin.val_add]
          have : (2 : Fin n).val = 2 := Nat.mod_eq_of_lt (by show 2 < n; omega)
          rw [this]
        rw [h2] at hval
        exact cycle_square_four_colorable_except_five_color_val_ne_add_two a b n hab hn i.val i.is_lt hval

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

def cycle_square_four_colorable_except_five_color_val (a : ℕ) (k : ℕ) : ℕ :=  if k < 3 * a then k % 3 else (k - 3 * a) % 4lemma cycle_square_four_colorable_except_five_color_val_lt_four (a k : ℕ) :    cycle_square_four_colorable_except_five_color_val a k < 4 := by  dsimp [cycle_square_four_colorable_except_five_color_val]  split_ifs <;> omegalemma cycle_square_four_colorable_except_five_color_val_ne_add_one    (a b n : ℕ) (hn : 3 * a + 4 * b = n) (k : ℕ) (hk : k < n) :    cycle_square_four_colorable_except_five_color_val a k ≠      cycle_square_four_colorable_except_five_color_val a ((k + 1) % n) := by  dsimp [cycle_square_four_colorable_except_five_color_val]  by_cases hk1 : k + 1 < n  · have h1 : (k + 1) % n = k + 1 := Nat.mod_eq_of_lt hk1    rw [h1]    split_ifs <;> omega  · have h1 : (k + 1) % n = 0 := by      have : k + 1 = n := by omega      rw [this, Nat.mod_self]    rw [h1]    split_ifs <;> omegalemma cycle_square_four_colorable_except_five_color_val_ne_add_two    (a b n : ℕ) (hn : 3 * a + 4 * b = n) (hn3 : 3 ≤ n) (k : ℕ) (hk : k < n) :    cycle_square_four_colorable_except_five_color_val a k ≠      cycle_square_four_colorable_except_five_color_val a ((k + 2) % n) := by  dsimp [cycle_square_four_colorable_except_five_color_val]  rcases lt_or_ge (k + 2) n with hk2 | hk2  · have h1 : (k + 2) % n = k + 2 := Nat.mod_eq_of_lt hk2    rw [h1]    split_ifs <;> omega  · rcases eq_or_lt_of_le hk2 with heq | hgt    · have h1 : (k + 2) % n = 0 := by        rw [heq, Nat.mod_self]      rw [h1]      split_ifs <;> omega    · have h1 : (k + 2) % n = 1 := by        have : k + 2 = 1 + n := by omega        rw [this, Nat.add_mod_right]        exact Nat.mod_eq_of_lt (by omega)      rw [h1]      split_ifs <;> omegalemma cycle_square_four_colorable_except_five_exists_rep    (n : ℕ) (hn : 3 ≤ n) (h5 : n ≠ 5) :    ∃ a b : ℕ, 3 * a + 4 * b = n := by  have hmod : n % 3 = 0 ∨ n % 3 = 1 ∨ n % 3 = 2 := by omega  rcases hmod with h0 | h1 | h2  · use n / 3, 0; omega  · use (n - 4) / 3, 1; omega  · use (n - 8) / 3, 2; omegatheorem cycle_square_four_colorable_except_five    (n : ℕ) [NeZero n] (hn : 3 ≤ n) (hfive : n ≠ 5) :    ∃ c : Fin n → Fin 4,      ∀ i, c i ≠ c (i+1) ∧ c i ≠ c (i+2) := by  obtain ⟨a, b, hab⟩ := cycle_square_four_colorable_except_five_exists_rep n hn hfive  let c : Fin n → Fin 4 := fun i =>    ⟨cycle_square_four_colorable_except_five_color_val a i.val,     cycle_square_four_colorable_except_five_color_val_lt_four a i.val⟩  use c  intro i  constructor  · intro h    have hval : (c i).val = (c (i + 1)).val := by rw [h]    dsimp [c] at hval    have h1 : (i + 1 : Fin n).val = (i.val + 1) % n := by      rw [Fin.val_add]      have : (1 : Fin n).val = 1 := Nat.mod_eq_of_lt (by show 1 < n; omega)      rw [this]    rw [h1] at hval    exact cycle_square_four_colorable_except_five_color_val_ne_add_one a b n hab i.val i.is_lt hval  · intro h    have hval : (c i).val = (c (i + 2)).val := by rw [h]    dsimp [c] at hval    have h2 : (i + 2 : Fin n).val = (i.val + 2) % n := by      rw [Fin.val_add]      have : (2 : Fin n).val = 2 := Nat.mod_eq_of_lt (by show 2 < n; omega)      rw [this]    rw [h2] at hval    exact cycle_square_four_colorable_except_five_color_val_ne_add_two a b n hab hn i.val i.is_lt hval
See it in the graphDiscuss this resultChallenge it