Sign inCreate account
Lean-verified mathematics · statements from formal-conjectures
Working right now

Loading…

[Formalized by test on 24 Nov 2026]

Title:Lemma balister_gyori_schelp_of_two_values · The Balister–Győri–Schelp conjecture

Source:Problems from arXiv papers
Proved lemma Checked by Lean. Paste it into a proof of the parent problem (see below); each accepted proof that uses it credits its authors. See the proof by test, 24 Nov 2026.
Statement:reviewed
Reuse this lemma — paste it into your Solution.lean, before the theorem that uses it
/-- Intermediate lemma (nosorry): General two-value case of the Balister-Győri-Schelp conjecture for all s ≥ 3: linear independence of a, c forces even multiplicities 2p, 2q with p + q = 2^(s-2), and decomposing 𝔽₂ s into 2^(s-2) cosets of ⟨a, c⟩ matches p cosets with difference a and q cosets with difference c. -/
theorem balister_gyori_schelp_of_two_values (s : ℕ) (hs : 3 ≤ s)
    (a c : 𝔽₂ s) (ha : a ≠ 0) (hc : c ≠ 0) (hac : a ≠ c)
    (v : Fin (2 ^ (s - 1)) → 𝔽₂ s)
    (hv : ∀ i, v i = a ∨ v i = c)
    (hsum : ∑ i, v i = 0) :
    ∃ e : Fin (2 ^ (s - 1)) × Fin 2 ≃ 𝔽₂ s, ∀ i, e (i, 0) + e (i, 1) = v i := by
  classical
  -- Step 1: Multiplicities of a and c are both even
  let A : Finset (Fin (2 ^ (s - 1))) := Finset.univ.filter fun i => v i = a
  let C : Finset (Fin (2 ^ (s - 1))) := Finset.univ \ A
  have hC_val : ∀ i ∈ C, v i = c := by
    intro i hi
    have hnotA : v i ≠ a := by
      intro hEq
      exact (Finset.mem_sdiff.mp hi).2 (Finset.mem_filter.mpr ⟨Finset.mem_univ i, hEq⟩)
    exact (hv i).resolve_left hnotA
  have hAC_sum : A.card + C.card = 2 ^ (s - 1) := by
    have := Finset.card_sdiff_add_card_eq_card (Finset.subset_univ A)
    rw [Finset.card_univ, Fintype.card_fin] at this
    change A.card + (Finset.univ \ A).card = 2 ^ (s - 1)
    omega
  have hsum_split : A.card • a + C.card • c = 0 := by
    have hunion : A ∪ C = Finset.univ := Finset.union_sdiff_of_subset (Finset.subset_univ A)
    have hdisj : Disjoint A C := Finset.disjoint_sdiff
    have h1 : ∑ i : Fin (2 ^ (s - 1)), v i = (∑ i ∈ A, v i) + (∑ i ∈ C, v i) := by
      rw [← hunion, Finset.sum_union hdisj]
    have hA_s : ∑ i ∈ A, v i = A.card • a := by
      rw [Finset.sum_congr rfl fun i hi => (Finset.mem_filter.mp hi).2, Finset.sum_const]
    have hC_s : ∑ i ∈ C, v i = C.card • c := by
      rw [Finset.sum_congr rfl hC_val, Finset.sum_const]
    rw [h1, hA_s, hC_s] at hsum
    exact hsum
  have hA_even : A.card % 2 = 0 := by
    rw [f2_nsmul_eq, f2_nsmul_eq] at hsum_split
    by_contra hodd
    rw [if_neg hodd] at hsum_split
    by_cases hC_ev : C.card % 2 = 0
    · rw [if_pos hC_ev, add_zero] at hsum_split
      exact ha hsum_split
    · rw [if_neg hC_ev] at hsum_split
      exact hac (f2_eq_of_add_eq_zero hsum_split)
  have hC_even : C.card % 2 = 0 := by
    rw [f2_nsmul_eq, f2_nsmul_eq, if_pos hA_even, zero_add] at hsum_split
    by_contra hodd
    rw [if_neg hodd] at hsum_split
    exact hc hsum_split
  let p := A.card / 2
  let q := C.card / 2
  have hp2 : A.card = 2 * p := by omega
  have hq2 : C.card = 2 * q := by omega
  have hpow1 : 2 ^ (s - 1) = 2 * 2 ^ (s - 2) := by
    have : s - 1 = (s - 2) + 1 := by omega
    conv_lhs => rw [this, pow_succ, mul_comm]
  have hpq : p + q = 2 ^ (s - 2) := by omega
  -- Step 2: Decompose 𝔽₂ s ≃ U × (Bool × Bool) where U has size 2^(s-2)
  have hk1_ex : ∃ k₁ : Fin s, a k₁ = 1 := by
    by_contra hnone; push Not at hnone
    apply ha; ext j
    have : ∀ x : ZMod 2, x ≠ 1 → x = 0 := by decide
    exact this (a j) (hnone j)
  obtain ⟨k₁, hk1⟩ := hk1_ex
  let c' : 𝔽₂ s := if c k₁ = 0 then c else c + a
  have hc'_k1 : c' k₁ = 0 := by
    dsimp only [c']
    split_ifs with h0
    · exact h0
    · have : ∀ x : ZMod 2, x ≠ 0 → x + 1 = 0 := by decide
      simpa [hk1] using this (c k₁) h0
  have hc'_ne : c' ≠ 0 := by
    dsimp only [c']
    split_ifs
    · exact hc
    · intro hEq; exact hac (f2_eq_of_add_eq_zero hEq).symm
  have hk2_ex : ∃ k₂ : Fin s, c' k₂ = 1 := by
    by_contra hnone; push Not at hnone
    apply hc'_ne; ext j
    have : ∀ x : ZMod 2, x ≠ 1 → x = 0 := by decide
    exact this (c' j) (hnone j)
  obtain ⟨k₂, hk2⟩ := hk2_ex
  let U : Finset (𝔽₂ s) := Finset.univ.filter fun x => x k₁ = 0 ∧ x k₂ = 0
  let g : {u : 𝔽₂ s // u ∈ U} × (Bool × Bool) → 𝔽₂ s := fun t =>
    t.1.val + (if t.2.1 then a else 0) + (if t.2.2 then c' else 0)
  have hg_inj : Function.Injective g := by
    intro ⟨⟨u₁, hu₁⟩, b₁, d₁⟩ ⟨⟨u₂, hu₂⟩, b₂, d₂⟩ hEq
    have hu1' := (Finset.mem_filter.mp hu₁).2
    have hu2' := (Finset.mem_filter.mp hu₂).2
    have hb : b₁ = b₂ := by
      have hk := congrFun hEq k₁
      dsimp only [g] at hk
      simp only [Pi.add_apply, hu1'.1, hu2'.1, zero_add] at hk
      have h1 : (if d₁ = true then c' else 0) k₁ = 0 := by cases d₁ <;> simp [hc'_k1]
      have h2 : (if d₂ = true then c' else 0) k₁ = 0 := by cases d₂ <;> simp [hc'_k1]
      rw [h1, h2, add_zero, add_zero] at hk
      cases b₁ <;> cases b₂ <;> simp [hk1] at hk ⊢
    subst hb
    have hEq2 : u₁ + (if d₁ then c' else 0) = u₂ + (if d₂ then c' else 0) := by
      have := congrArg (· + (if b₁ then a else 0)) hEq
      dsimp only [g] at this
      have h1 : ∀ x y z : 𝔽₂ s, x + y + z + y = x + z := by
        intro x y z
        have : x + y + z + y = x + z + (y + y) := by abel
        rw [this, f2_add_self, add_zero]
      rwa [h1, h1] at this
    have hd : d₁ = d₂ := by
      have hk := congrFun hEq2 k₂
      simp only [Pi.add_apply, hu1'.2, hu2'.2, zero_add] at hk
      cases d₁ <;> cases d₂ <;> simp [hk2] at hk ⊢
    subst hd
    have hu : u₁ = u₂ := by
      have := congrArg (· + (if d₁ then c' else 0)) hEq2
      simpa [add_assoc, f2_add_self] using this
    exact Prod.ext (Subtype.ext hu) rfl
  have hg_surj : Function.Surjective g := by
    intro y
    let b₁ : Bool := decide (y k₁ = 1)
    let y₁ : 𝔽₂ s := y + (if b₁ then a else 0)
    have hy1_k1 : y₁ k₁ = 0 := by
      dsimp only [y₁, b₁]
      by_cases h1 : y k₁ = 1
      · simp [h1, hk1]; decide
      · have h0 : y k₁ = 0 := by
          have : ∀ x : ZMod 2, x ≠ 1 → x = 0 := by decide
          exact this (y k₁) h1
        simp [h1, h0]
    let d₁ : Bool := decide (y₁ k₂ = 1)
    let u : 𝔽₂ s := y₁ + (if d₁ then c' else 0)
    have hu_k1 : u k₁ = 0 := by
      dsimp only [u]; simp only [Pi.add_apply, hy1_k1, zero_add]
      cases d₁ <;> simp [hc'_k1]
    have hu_k2 : u k₂ = 0 := by
      dsimp only [u, d₁]
      by_cases h1 : y₁ k₂ = 1
      · simp [h1, hk2]; decide
      · have h0 : y₁ k₂ = 0 := by
          have : ∀ x : ZMod 2, x ≠ 1 → x = 0 := by decide
          exact this (y₁ k₂) h1
        simp [h1, h0]
    have huU : u ∈ U := Finset.mem_filter.mpr ⟨Finset.mem_univ u, hu_k1, hu_k2⟩
    refine ⟨(⟨u, huU⟩, b₁, d₁), ?_⟩
    dsimp only [g, u, y₁]
    have : y + (if b₁ then a else 0) + (if d₁ then c' else 0) + (if b₁ then a else 0) +
        (if d₁ then c' else 0) =
        y + ((if b₁ then a else 0) + (if b₁ then a else 0)) +
        ((if d₁ then c' else 0) + (if d₁ then c' else 0)) := by abel
    rw [this, f2_add_self, f2_add_self, add_zero, add_zero]
  let eG : {u : 𝔽₂ s // u ∈ U} × (Bool × Bool) ≃ 𝔽₂ s := Equiv.ofBijective g ⟨hg_inj, hg_surj⟩
  have hU_card : U.card = 2 ^ (s - 2) := by
    have hcard := Fintype.card_congr eG
    simp only [Fintype.card_prod, Fintype.card_coe, Fintype.card_bool] at hcard
    have htot : Fintype.card (𝔽₂ s) = 2 ^ s := by simp [𝔽₂, 𝔽, ZMod.card]
    rw [htot] at hcard
    have hpow2 : 2 ^ s = 2 ^ (s - 2) * (2 * 2) := by
      have : s = (s - 2) + 2 := by omega
      conv_lhs => rw [this, pow_add]
      rfl
    omega
  -- Step 3: Build equivalence Fin (2^(s-1)) ≃ Fin (2^(s-2)) × Fin 2 respecting A and C
  have eA : Fin (2 * p) ≃ {i // i ∈ A} := (Fintype.equivFinOfCardEq ((Fintype.card_coe A).trans hp2)).symm
  have eC : Fin (2 * q) ≃ {i // i ∈ C} := (Fintype.equivFinOfCardEq ((Fintype.card_coe C).trans hq2)).symm
  let idxToPair : Fin (2 ^ (s - 1)) → Fin (2 ^ (s - 2)) × Fin 2 := fun i =>
    if hi : i ∈ A then
      let k := (eA.symm ⟨i, hi⟩).val
      (⟨k / 2, by have := (eA.symm ⟨i, hi⟩).isLt; omega⟩, ⟨k % 2, by omega⟩)
    else
      let k := (eC.symm ⟨i, Finset.mem_sdiff.mpr ⟨Finset.mem_univ i, hi⟩⟩).val
      (⟨p + k / 2, by have := (eC.symm ⟨i, Finset.mem_sdiff.mpr ⟨Finset.mem_univ i, hi⟩⟩).isLt; omega⟩,
       ⟨k % 2, by omega⟩)
  have hidx_inj : Function.Injective idxToPair := by
    intro i1 i2 hEq
    dsimp only [idxToPair] at hEq
    split_ifs at hEq with h1 h2 h2
    · have hfst := congrArg (fun x => x.1.val) hEq
      have hsnd := congrArg (fun x => x.2.val) hEq
      dsimp at hfst hsnd
      have hk : eA.symm ⟨i1, h1⟩ = eA.symm ⟨i2, h2⟩ := Fin.ext (by omega)
      exact congrArg Subtype.val (eA.symm.injective hk)
    · exfalso
      have hfst := congrArg (fun x => x.1.val) hEq
      dsimp at hfst
      have hlt := (eA.symm ⟨i1, h1⟩).isLt
      omega
    · exfalso
      have hfst := congrArg (fun x => x.1.val) hEq
      dsimp at hfst
      have hlt := (eA.symm ⟨i2, h2⟩).isLt
      omega
    · have hfst := congrArg (fun x => x.1.val) hEq
      have hsnd := congrArg (fun x => x.2.val) hEq
      dsimp at hfst hsnd
      have hk : eC.symm ⟨i1, Finset.mem_sdiff.mpr ⟨Finset.mem_univ i1, h1⟩⟩ =
          eC.symm ⟨i2, Finset.mem_sdiff.mpr ⟨Finset.mem_univ i2, h2⟩⟩ := Fin.ext (by omega)
      exact congrArg Subtype.val (eC.symm.injective hk)
  let eIdx : Fin (2 ^ (s - 1)) ≃ Fin (2 ^ (s - 2)) × Fin 2 :=
    Equiv.ofBijective idxToPair
      ((Fintype.bijective_iff_injective_and_card idxToPair).mpr
        ⟨hidx_inj, by simp [Fintype.card_prod, hpow1, mul_comm]⟩)
  have hU_eq : Fin (2 ^ (s - 2)) ≃ {u : 𝔽₂ s // u ∈ U} :=
    (Fintype.equivFinOfCardEq ((Fintype.card_coe U).trans hU_card)).symm
  -- Coset pairing equivalences Fin 2 × Fin 2 ≃ Bool × Bool:
  -- For difference a: (0,0)↦(F,F), (0,1)↦(T,F), (1,0)↦(F,T), (1,1)↦(T,T)
  -- For difference c when c' = c: (0,0)↦(F,F), (0,1)↦(F,T), (1,0)↦(T,F), (1,1)↦(T,T)
  -- For difference c when c' = c + a: (0,0)↦(F,F), (0,1)↦(T,T), (1,0)↦(T,F), (1,1)↦(F,T)
  let pairA : Fin 2 × Fin 2 → Bool × Bool := fun x => (x.2 == 1, x.1 == 1)
  let pairC : Fin 2 × Fin 2 → Bool × Bool := fun x =>
    if c k₁ = 0 then (x.1 == 1, x.2 == 1)
    else ((x.1 != x.2), x.2 == 1)
  have hpairA_bij : Function.Bijective pairA := by
    have : Function.Injective pairA := by decide
    exact (Fintype.bijective_iff_injective_and_card pairA).mpr ⟨this, by decide⟩
  have hpairC_bij : Function.Bijective pairC := by
    have hinj : Function.Injective pairC := by
      intro x y hxy
      dsimp only [pairC] at hxy
      split_ifs at hxy
      · revert hxy; revert x y; decide
      · revert hxy; revert x y; decide
    exact (Fintype.bijective_iff_injective_and_card pairC).mpr ⟨hinj, by decide⟩
  let ePair : Fin (2 ^ (s - 2)) → (Fin 2 × Fin 2 ≃ Bool × Bool) := fun j =>
    if j.val < p then Equiv.ofBijective pairA hpairA_bij
    else Equiv.ofBijective pairC hpairC_bij
  -- Assemble full equivalence Fin (2^(s-1)) × Fin 2 ≃ 𝔽₂ s
  let fullFun : Fin (2 ^ (s - 1)) × Fin 2 → 𝔽₂ s := fun x =>
    let jb := eIdx x.1
    eG (hU_eq jb.1, ePair jb.1 (jb.2, x.2))
  have hfull_inj : Function.Injective fullFun := by
    intro ⟨i1, t1⟩ ⟨i2, t2⟩ hEq
    dsimp only [fullFun] at hEq
    have h1 := eG.injective hEq
    have hU1 : (eIdx i1).1 = (eIdx i2).1 := hU_eq.injective (congrArg Prod.fst h1)
    have hP1 : ePair (eIdx i1).1 ((eIdx i1).2, t1) = ePair (eIdx i2).1 ((eIdx i2).2, t2) :=
      congrArg Prod.snd h1
    rw [hU1] at hP1
    have h2 := (ePair (eIdx i2).1).injective hP1
    have hIdxEq : eIdx i1 = eIdx i2 := Prod.ext hU1 (congrArg Prod.fst h2)
    have htEq : t1 = t2 := congrArg Prod.snd h2
    exact Prod.ext (eIdx.injective hIdxEq) htEq
  have hfull_card : Fintype.card (Fin (2 ^ (s - 1)) × Fin 2) = Fintype.card (𝔽₂ s) := by
    simp only [Fintype.card_prod, Fintype.card_fin, 𝔽₂, 𝔽, Fintype.card_pi, ZMod.card,
      Finset.prod_const, Finset.card_univ]
    have : s = (s - 1) + 1 := by omega
    conv_rhs => rw [this, pow_succ]
  refine ⟨Equiv.ofBijective fullFun ((Fintype.bijective_iff_injective_and_card fullFun).mpr ⟨hfull_inj, hfull_card⟩), fun i => ?_⟩
  simp only [Equiv.ofBijective_apply, fullFun]
  by_cases hiA : i ∈ A
  · have hvi : v i = a := (Finset.mem_filter.mp hiA).2
    have hlt : (eIdx i).1.val < p := by
      simp only [eIdx, Equiv.ofBijective_apply, idxToPair, dif_pos hiA]
      have := (eA.symm ⟨i, hiA⟩).isLt
      omega
    rw [hvi]
    dsimp only [ePair]
    rw [if_pos hlt]
    change g (hU_eq (eIdx i).1, pairA ((eIdx i).2, 0)) +
      g (hU_eq (eIdx i).1, pairA ((eIdx i).2, 1)) = a
    dsimp only [g, pairA]
    generalize (hU_eq (eIdx i).1).val = u
    generalize (eIdx i).2 = b
    fin_cases b
    · have : (u + 0 + 0) + (u + a + 0) = (u + u) + a := by abel
      simpa using this.trans (by rw [f2_add_self, zero_add])
    · have : (u + 0 + c') + (u + a + c') = (u + u) + (c' + c') + a := by abel
      simpa using this.trans (by rw [f2_add_self, f2_add_self, zero_add, zero_add])
  · have hiC : i ∈ C := Finset.mem_sdiff.mpr ⟨Finset.mem_univ i, hiA⟩
    have hvi : v i = c := hC_val i hiC
    have hge : ¬ (eIdx i).1.val < p := by
      simp only [eIdx, Equiv.ofBijective_apply, idxToPair, dif_neg hiA]
      omega
    rw [hvi]
    dsimp only [ePair]
    rw [if_neg hge]
    change g (hU_eq (eIdx i).1, pairC ((eIdx i).2, 0)) +
      g (hU_eq (eIdx i).1, pairC ((eIdx i).2, 1)) = c
    dsimp only [g, pairC]
    generalize (hU_eq (eIdx i).1).val = u
    generalize (eIdx i).2 = b
    by_cases hck : c k₁ = 0
    · have hc'eq : c' = c := by simp [c', hck]
      rw [if_pos hck, if_pos hck, hc'eq]
      fin_cases b
      · have : (u + 0 + 0) + (u + 0 + c) = (u + u) + c := by abel
        simpa using this.trans (by rw [f2_add_self, zero_add])
      · have : (u + a + 0) + (u + a + c) = (u + u) + (a + a) + c := by abel
        simpa using this.trans (by rw [f2_add_self, f2_add_self, zero_add, zero_add])
    · have hc'eq : c' = c + a := by simp [c', hck]
      rw [if_neg hck, if_neg hck, hc'eq]
      fin_cases b
      · have : (u + 0 + 0) + (u + a + (c + a)) = (u + u) + (a + a) + c := by abel
        simpa using this.trans (by rw [f2_add_self, f2_add_self, zero_add, zero_add])
      · have : (u + a + 0) + (u + 0 + (c + a)) = (u + u) + (a + a) + c := by abel
        simpa using this.trans (by rw [f2_add_self, f2_add_self, zero_add, zero_add])

From the first verified proof, s-c68sbp9ewv (lemma proofs are public). If it relies on helper lemmas, copy them too.

Problem: General two-value case of the Balister-Győri-Schelp conjecture for all s ≥ 3: linear independence of a, c forces even multiplicities 2p, 2q with p + q = 2^(s-2), and decomposing 𝔽₂ s into 2^(s-2) cosets of ⟨a, c⟩ matches p cosets with difference a and q cosets with difference c. … Full statement & Lean theorem →

Show: all ○ connecting…
  1. verifiedVerified proof by test2 d