{
  "id": "7205",
  "ident": "NS.07205",
  "slug": "other-suffixprefixavoidance",
  "title": "Suffix-prefix avoidance bound",
  "status": "solved",
  "statement_status": "reviewed",
  "statement_md": "$A$ and $B$ are sets of words of length $n$ over alphabet with $q \\geq 1$ letters.\nNo suffix of a word in $A$ coincides with a prefix of a word in $B$.\nThen $|A| \\cdot |B|$ is at most $\\frac{q^{2n}}{en}$.\n\nThis problem is from *Maximal sets of strings with no prefix-suffix overlap* and was proved in\n*An isoperimetric inequality for word overlap*.",
  "subjects": [
    "math.CO",
    "msc:05"
  ],
  "tags": [],
  "collection": "other",
  "source_url": null,
  "solved_on_platform": false,
  "needs_answer": false,
  "version": 1,
  "decl_name": "SuffixPrefixAvoidance.suffix_prefix_avoidance_bound",
  "statement_lean": "theorem suffix_prefix_avoidance_bound\n    (A B : Finset (Fin n → Fin q))\n    (hq : 0 < q) (hn : 0 < n)\n    (h : IsSuffixPrefixAvoiding A B) :\n    (A.card : ℝ) * B.card ≤ (q : ℝ) ^ (2 * n) / (exp 1 * n)",
  "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# Suffix-prefix avoidance bound\n\nLet $A$ and $B$ be sets of words of length $n$ over an alphabet with $q$ letters. If no\n(nonempty) suffix of any word in $A$ coincides with a prefix of any word in $B$, then\n$$|A| \\cdot |B| \\leq \\frac{q^{2n}}{en}.$$\n\n*References:*\n- [X post by Dmitry Rybin](https://x.com/DmitryRybin1/status/2027278135847428577)\n- [Maximal sets of strings with no prefix-suffix overlap]\n  (https://mathoverflow.net/questions/508648/maximal-sets-of-strings-with-no-prefix-suffix-overlap)\n  by *Dmitry Rybin*, MathOverflow (2026)\n- [An isoperimetric inequality for word overlap](https://arxiv.org/abs/2602.20143)\n  by *Dmitrii Zakharov* (2026)\n-/\n\n@[expose] public section\n\nopen Finset Real\n\nnamespace SuffixPrefixAvoidance\n\nvariable {n q : ℕ}\n\n/-- The suffix of a word `w : Fin n → Fin q` of length `k + 1` (the last `k + 1` characters). -/\ndef wordSuffix (w : Fin n → Fin q) (k : Fin n) : Fin (k + 1) → Fin q :=\n  fun i => w ⟨n - k - 1 + i, by omega⟩\n\n/-- The prefix of a word `w : Fin n → Fin q` of length `k + 1` (the first `k + 1` characters). -/\ndef wordPrefix (w : Fin n → Fin q) (k : Fin n) : Fin (k + 1) → Fin q :=\n  fun i => w ⟨i, by omega⟩\n\n/-- Two sets of words $A, B$ over `Fin q` of length `n` are suffix-prefix avoiding if no\nnonempty suffix of any word in $A$ equals any prefix of any word in $B$ of the same length. -/\ndef IsSuffixPrefixAvoiding (A B : Finset (Fin n → Fin q)) : Prop :=\n  ∀ a ∈ A, ∀ b ∈ B, ∀ k : Fin n, wordSuffix a k ≠ wordPrefix b k\n\n/--\n$A$ and $B$ are sets of words of length $n$ over alphabet with $q$ letters.\nTrivially then $|A| \\cdot |B|$ is at most $q^{2n}$.\n-/\n@[category test, AMS 5]\ntheorem words_naive_bound\n    (A B : Finset (Fin n → Fin q)) :\n    A.card * B.card ≤ q ^ (2 * n) := by\n  simp [Nat.mul_le_mul, two_mul, pow_add, (Finset.card_le_univ _).trans_eq]\n\n/--\n$A$ and $B$ are sets of words of length $n$ over alphabet with $q \\geq 1$ letters.\nNo suffix of a word in $A$ coincides with a prefix of a word in $B$.\nThen $|A| \\cdot |B|$ is at most $\\frac{q^{2n}}{en}$.\n\nThis problem is from *Maximal sets of strings with no prefix-suffix overlap* and was proved in\n*An isoperimetric inequality for word overlap*.\n-/\n@[category research solved, AMS 5]\ntheorem suffix_prefix_avoidance_bound\n    (A B : Finset (Fin n → Fin q))\n    (hq : 0 < q) (hn : 0 < n)\n    (h : IsSuffixPrefixAvoiding A B) :\n    (A.card : ℝ) * B.card ≤ (q : ℝ) ^ (2 * n) / (exp 1 * n) := by\n  sorry\n\nset_option linter.style.formal_proof_palomar false in\n/--\n$A$ and $B$ are sets of words of length $n$ over alphabet with $q \\geq 1$ letters.\nNo suffix of a word in $A$ coincides with a prefix of a word in $B$.\nThen $|A| \\cdot |B|$ is at most $\\frac{q^{2n}}{n}$.\n-/\n@[category research solved, AMS 5,\n  formal_proof using formal_conjectures at \"https://github.com/google-deepmind/formal-conjectures/blob/102e47fee802d461946e3a4e0b47fdbe7db4c1ed/FormalConjectures/Other/SuffixPrefixAvoidance.lean#L157\"]\ntheorem suffix_prefix_avoidance_weaker_bound\n    (A B : Finset (Fin n → Fin q))\n    (_hq : 0 < q) (hn : 0 < n)\n    (h : IsSuffixPrefixAvoiding A B) :\n    (A.card : ℚ) * B.card ≤ (q : ℚ) ^ (2 * n) / n := by\n  sorry\n\nend SuffixPrefixAvoidance\n",
  "statement_hash": "324c5381593d09056b1e106483324db44bcc97affb19415490961a4d58ddd131",
  "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."
}