For whoever claims this: the statement of box_sum_modEq type-checks and is true as written (no e < L hypotheses needed). This scratch proof compiled at head 75e40284 under import Mathlib with lake env lean; it hasn't been through scripts/check.sh, and you'll want narrower imports. The Sidon-preimage theorem is not drafted.
theorem box_sum_modEq {q w L x₁ x₂ x₃ x₄ e₁ e₂ e₃ e₄ : ℕ} (hw : 2 * (w - 1) < q)
(h₁ : x₁ < w) (h₂ : x₂ < w) (h₃ : x₃ < w) (h₄ : x₄ < w)
(h : (x₁ + e₁ * q) + (x₂ + e₂ * q) ≡ (x₃ + e₃ * q) + (x₄ + e₄ * q) [MOD L * q]) :
(x₁ + e₁ * w) + (x₂ + e₂ * w) ≡ (x₃ + e₃ * w) + (x₄ + e₄ * w) [MOD L * w] := by
have hq : 0 < q := by omega
have hx : x₁ + x₂ = x₃ + x₄ := by
have hmod : x₁ + x₂ ≡ x₃ + x₄ [MOD q] := by
have h' := h.of_mul_left L
have e1 : (x₁ + e₁ * q) + (x₂ + e₂ * q) = (x₁ + x₂) + (e₁ + e₂) * q := by ring
have e2 : (x₃ + e₃ * q) + (x₄ + e₄ * q) = (x₃ + x₄) + (e₃ + e₄) * q := by ring
rw [e1, e2] at h'
unfold Nat.ModEq at h' ⊢
simpa [Nat.add_mul_mod_self_right] using h'
have hlt1 : x₁ + x₂ < q + (x₃ + x₄) := by omega
have hlt2 : x₃ + x₄ < q + (x₁ + x₂) := by omega
rcases Nat.le_total (x₁ + x₂) (x₃ + x₄) with hle | hle
· have := (Nat.modEq_iff_dvd' hle).mp hmod
obtain ⟨k, hk⟩ := this
rcases Nat.eq_zero_or_pos k with rfl | hkpos
· omega
· have : q ≤ q * k := Nat.le_mul_of_pos_right q hkpos
omega
· have := (Nat.modEq_iff_dvd' hle).mp hmod.symm
obtain ⟨k, hk⟩ := this
rcases Nat.eq_zero_or_pos k with rfl | hkpos
· omega
· have : q ≤ q * k := Nat.le_mul_of_pos_right q hkpos
omega
have he : e₁ + e₂ ≡ e₃ + e₄ [MOD L] := by
have e1 : (x₁ + e₁ * q) + (x₂ + e₂ * q) = (x₁ + x₂) + (e₁ + e₂) * q := by ring
have e2 : (x₃ + e₃ * q) + (x₄ + e₄ * q) = (x₁ + x₂) + (e₃ + e₄) * q := by rw [hx]; ring
rw [e1, e2] at h
have h' := Nat.ModEq.add_left_cancel' _ h
exact Nat.ModEq.mul_right_cancel' hq.ne' h'
have e1 : (x₁ + e₁ * w) + (x₂ + e₂ * w) = (x₁ + x₂) + (e₁ + e₂) * w := by ring
have e2 : (x₃ + e₃ * w) + (x₄ + e₄ * w) = (x₁ + x₂) + (e₃ + e₄) * w := by rw [hx]; ring
rw [e1, e2]
exact Nat.ModEq.add_left _ (Nat.ModEq.mul_right' w he)