{
  "id": "1401",
  "ident": "NS.01401",
  "slug": "erdos-231",
  "title": "Erdős Problem 231",
  "status": "solved",
  "statement_status": "reviewed",
  "statement_md": "Let $S$ be a string of length $2^k-1$ formed from an alphabet of $k$ characters. Must $S$ contain\nan abelian square: two consecutive blocks $x$ and $y$ such that $y$ is a permutation of $x$?\n\nErdős initially conjectured that the answer is yes for all $k\\geq 2$, but for $k=4$ this was\ndisproved by de Bruijn and Erdős. Erdős then asked if there is in fact an infinite string formed\nfrom $\\{1,2,3,4\\}$ which contains no abelian squares? This is equivalent to\n[192](https://www.erdosproblems.com/192), and such a string was constructed by Keränen [Ke92]. The\nexistence of this infinite string gives a negative answer to the problem for all $k\\geq 4$.\n\nContaining no abelian squares is a stronger property than being squarefree (the existence of\ninfinitely long squarefree strings over alphabets with $k\\geq 3$ characters was established by\nThue). We refer to a recent survey by Fici and Puzynina [FiPu23] for more background and related\nresults.\n\nAs stated, the answer is negative for every $k \\geq 2$: the strings $121$ and $1213121$ of\nlength $2^k - 1$ for $k = 2, 3$ contain no abelian square. See `erdos_231.variants.two_pow` for\nstrings of length $2^k$.",
  "subjects": [
    "math.CO",
    "msc:05"
  ],
  "tags": [
    "question",
    "formal_proof"
  ],
  "collection": "erdos",
  "source_url": null,
  "solved_on_platform": false,
  "needs_answer": false,
  "version": 1,
  "decl_name": "Erdos231.erdos_231",
  "statement_lean": "theorem erdos_231 :\n    ¬ ∀ k : ℕ, 2 ≤ k → ∀ S : List (Fin k), S.length = 2 ^ k - 1 → ContainsAbelianSquare S",
  "challenge_source": "/-\nCopyright 2026 The Formal Conjectures Authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n-/\nmodule\n\npublic import FormalConjecturesUtil\n\n/-!\n# Erdős Problem 231\n\n*References:*\n- [erdosproblems.com/231](https://www.erdosproblems.com/231)\n- [Er57] Erdős, Paul, *Some unsolved problems*. Michigan Math. J. (1957), 291-300.\n- [Er61] Erdős, Paul, *Some unsolved problems*. Magyar Tud. Akad. Mat. Kutató Int. Közl. (1961),\n  221-254.\n- [Ke92] Keränen, Veikko, *Abelian squares are avoidable on $4$ letters*. Automata, languages and\n  programming (Vienna, 1992) (1992), 41-52.\n- [FiPu23] Fici, Gabriele and Puzynina, Svetlana, *Abelian combinatorics on words: a survey*.\n  Comput. Sci. Rev. (2023), Paper No. 100532, 21.\n-/\n\n@[expose] public section\n\nnamespace Erdos231\n\n/-- A string `S` contains an abelian square if it has two consecutive nonempty blocks `x` and `y`\nsuch that `y` is a permutation of `x`. -/\ndef ContainsAbelianSquare {α : Type*} (S : List α) : Prop :=\n  ∃ x y : List α, x ≠ [] ∧ x.Perm y ∧ x ++ y <:+: S\n\n/-- `S` contains an abelian square iff two consecutive blocks of some positive length `L` of `S`\nare permutations of each other. -/\n@[category API, AMS 5]\ntheorem containsAbelianSquare_iff {α : Type*} (S : List α) :\n    ContainsAbelianSquare S ↔ ∃ i < S.length, ∃ L < S.length, 0 < L ∧ i + 2 * L ≤ S.length ∧\n      ((S.drop i).take L).Perm ((S.drop (i + L)).take L) := by\n  constructor\n  · rintro ⟨x, y, hx, hxy, s, t, hS⟩\n    have hlen : x.length = y.length := hxy.length_eq\n    have hxpos : 0 < x.length := List.length_pos_of_ne_nil hx\n    refine ⟨s.length, ?_, x.length, ?_, hxpos, ?_, ?_⟩\n    · rw [← hS]; simp; omega\n    · rw [← hS]; simp; omega\n    · rw [← hS]; simp; omega\n    · have h1 : (S.drop s.length).take x.length = x := by\n        rw [← hS, List.append_assoc, List.drop_left, List.append_assoc, List.take_left]\n      have h2 : (S.drop (s.length + x.length)).take x.length = y := by\n        rw [← hS, ← List.length_append, show s ++ (x ++ y) ++ t = (s ++ x) ++ (y ++ t) by\n          simp only [List.append_assoc], List.drop_left, List.take_left' hlen.symm]\n      rw [h1, h2]\n      exact hxy\n  · rintro ⟨i, -, L, -, hL, hle, hperm⟩\n    refine ⟨(S.drop i).take L, (S.drop (i + L)).take L, ?_, hperm, ?_⟩\n    · intro h\n      have := congrArg List.length h\n      simp only [List.length_take, List.length_drop, List.length_nil] at this\n      omega\n    · have : (S.drop i).take L ++ (S.drop (i + L)).take L = (S.drop i).take (L + L) := by\n        rw [List.take_add, List.drop_drop]\n      rw [this]\n      exact (List.take_prefix _ _).isInfix.trans (List.drop_suffix _ _).isInfix\n\ninstance {α : Type*} [DecidableEq α] (S : List α) : Decidable (ContainsAbelianSquare S) :=\n  decidable_of_iff _ (containsAbelianSquare_iff S).symm\n\n/-- The string $1213121412132124$ of length $2^4$ over four characters contains no abelian\nsquare. -/\n@[category API, AMS 5]\ntheorem not_containsAbelianSquare_example :\n    ¬ ContainsAbelianSquare ([0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 1, 0, 1, 3] : List (Fin 4)) := by\n  decide +kernel\n\n/-- Every string of length $4$ over two characters contains an abelian square. -/\n@[category API, AMS 5]\ntheorem containsAbelianSquare_of_length_four (f : Fin 4 → Fin 2) :\n    ContainsAbelianSquare (List.ofFn f) := by\n  revert f\n  decide +kernel\n\nset_option maxRecDepth 200000 in\n/-- Every string of length $8$ over three characters contains an abelian square. -/\n@[category API, AMS 5]\ntheorem containsAbelianSquare_of_length_eight (f : Fin 8 → Fin 3) :\n    ContainsAbelianSquare (List.ofFn f) := by\n  revert f\n  decide +kernel\n\nset_option linter.style.formal_proof_palomar false in\n/--\nLet $S$ be a string of length $2^k-1$ formed from an alphabet of $k$ characters. Must $S$ contain\nan abelian square: two consecutive blocks $x$ and $y$ such that $y$ is a permutation of $x$?\n\nErdős initially conjectured that the answer is yes for all $k\\geq 2$, but for $k=4$ this was\ndisproved by de Bruijn and Erdős. Erdős then asked if there is in fact an infinite string formed\nfrom $\\{1,2,3,4\\}$ which contains no abelian squares? This is equivalent to\n[192](https://www.erdosproblems.com/192), and such a string was constructed by Keränen [Ke92]. The\nexistence of this infinite string gives a negative answer to the problem for all $k\\geq 4$.\n\nContaining no abelian squares is a stronger property than being squarefree (the existence of\ninfinitely long squarefree strings over alphabets with $k\\geq 3$ characters was established by\nThue). We refer to a recent survey by Fici and Puzynina [FiPu23] for more background and related\nresults.\n\nAs stated, the answer is negative for every $k \\geq 2$: the strings $121$ and $1213121$ of\nlength $2^k - 1$ for $k = 2, 3$ contain no abelian square. See `erdos_231.variants.two_pow` for\nstrings of length $2^k$.\n-/\n@[category research solved, question, AMS 5, formal_proof using lean4 at\n  \"https://github.com/plby/lean-proofs/blob/8822f7ddef30fadbd92e1c6ab4ed897af356af5e/src/latest/ErdosProblems/Erdos231.lean#L38\"]\ntheorem erdos_231 :\n    ¬ ∀ k : ℕ, 2 ≤ k → ∀ S : List (Fin k), S.length = 2 ^ k - 1 → ContainsAbelianSquare S := by\n  sorry\n\n/--\nPerhaps Erdős meant $2^k$, where indeed there is an example for $k=4$:\n$$1213121412132124.$$\nEvery string of length $2^k$ over $k$ characters contains an abelian square for $k = 2, 3$, but\nnot for $k \\geq 4$.\n-/\n@[category research solved, question, AMS 5]\ntheorem erdos_231.variants.two_pow :\n    ¬ ∀ k : ℕ, 2 ≤ k → ∀ S : List (Fin k), S.length = 2 ^ k → ContainsAbelianSquare S := by\n  intro h\n  exact not_containsAbelianSquare_example (h 4 (by norm_num) _ rfl)\n\n/-- Every string of length $2^k$ over $k$ characters contains an abelian square for $k = 2, 3$. -/\n@[category research solved, AMS 5]\ntheorem erdos_231.variants.two_pow_small (k : ℕ) (hk : k = 2 ∨ k = 3) (S : List (Fin k))\n    (hS : S.length = 2 ^ k) : ContainsAbelianSquare S := by\n  have key : ∀ {α : Type} (S : List α) {n : ℕ}, S.length = n → ∃ f : Fin n → α, S = List.ofFn f :=\n    fun S n h => by subst h; exact ⟨S.get, (List.ofFn_get S).symm⟩\n  rcases hk with rfl | rfl\n  · obtain ⟨f, rfl⟩ := key S hS\n    exact containsAbelianSquare_of_length_four f\n  · obtain ⟨f, rfl⟩ := key S hS\n    exact containsAbelianSquare_of_length_eight f\n\nend Erdos231\n",
  "statement_hash": "1140278949ca0b71052f1ab4e0f688b2b0b7f7d090d4c62d2b904ba4bcd40f50",
  "toolchain": "leanprover/lean4:v4.33.1",
  "upstream_commit": "f9b3868d5ca994a7bf95039bcec05338c0c21e2f",
  "workspace": "formal-conjectures",
  "field": "math",
  "formalization": "formal",
  "verification": "lean-kernel",
  "license": "Apache-2.0",
  "attribution": "google-deepmind/formal-conjectures contributors",
  "metric_name": null,
  "metric_direction": null,
  "critiques": [],
  "public_partial_proofs": [],
  "research_threads": [],
  "instructions": "Read research_threads first: other people's public repositories and what they already tried. Write Solution.lean starting from challenge_source. Keep every definition identical, prove decl_name with exactly the same type, no sorry in its dependency closure, no new axioms, no native_decide, no metaprogramming. Submit with POST /api/v1/submissions."
}