{
  "id": "6710",
  "ident": "NS.06710",
  "slug": "oeis-6697",
  "title": "Subword complexity of the morphism a → aab, b → b",
  "status": "solved",
  "statement_status": "reviewed",
  "statement_md": "**Conjecture (A6697)**: The generating function for the number of subwords of length $n$\nin the infinite word generated by $a \\mapsto aab, b \\mapsto b$ is\n$$\\sum_{n \\geq 0} a_n x^n = 1 + \\frac{1}{1-x} + \\frac{1}{(1-x)^2}\\left(\\frac{1}{1-x} -\n  \\sum_{k \\geq 0} x^{2^{k+1} + k}\\right).$$\n\nEquivalently, a(n) equals the n-th coefficient of this generating function.\n\nHowever, the reference quoted in the OEIS sequence\n\n> J.-P. Allouche and J. Shallit, \"On the subword complexity of the fixed point of a → aab, b → b,\n> and generalizations,\" arXiv:1605.02361 [math.CO], 2016.\n\nprovides an explicit formula\n$$ a_n = \\sum_{i=0}^{n} \\min(2^i,n-i+1). $$\n\nIf one takes this as a definition of a(n) instead,\nit becomes straightforward to prove the conjecture.\nSee https://github.com/AxiomMath/gdm-formal-conjectures/blob/main/docs/OeisA6697.md\nfor a formal proof of the generating function using this definition.\n\nHence, a formalization of [arXiv:1605.02361](https://arxiv.org/abs/1605.02361)\nwould complete a formal proof as below.",
  "subjects": [
    "math.CO",
    "msc:68"
  ],
  "tags": [
    "formal_proof"
  ],
  "collection": "oeis",
  "source_url": null,
  "solved_on_platform": false,
  "needs_answer": false,
  "version": 1,
  "decl_name": "OeisA6697.conjecture",
  "statement_lean": "theorem conjecture (n : ℕ) :\n    a n = coeff (R := ℚ) n\n      ((1 - X)⁻¹ + X * (1 - X)⁻¹ ^ 2 * ((1 - X)⁻¹ - ∑' k, X ^ (2 ^ (k + 1) + k)))",
  "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# Subword complexity of the morphism a → aab, b → b\n\nLet $a_n$ be the number of distinct subwords (contiguous factors) of length $n$ in the infinite\nword generated by the morphism $\\sigma: a \\mapsto aab, b \\mapsto b$, starting from $a$.\nAs shown in the references, $a_n$ is given by the formula\n$$ a_n = \\sum_{i=0}^{n} \\min(2^i,n-i+1). $$\n\nThe conjectured generating function is:\n$$\\sum_{n \\geq 0} a_n x^n = \\frac{1}{1-x} + \\frac{x}{(1-x)^2}\\left(\\frac{1}{1-x} -\n  \\sum_{k \\geq 1} x^{2^k + k - 1}\\right).$$\n\n*References:*\n- [A6697](https://oeis.org/A6697)\n- J.-P. Allouche and J. Shallit, \"On the subword complexity of the fixed point of a → aab, b → b,\n  and generalizations,\" arXiv:1605.02361 [math.CO], 2016.\n- N. J. A. Sloane and Simon Plouffe, *The Encyclopedia of Integer Sequences*, Academic Press, 1995.\n-/\n\n@[expose] public section\n\nnamespace OeisA6697\n\nopen PowerSeries WithPiTopology List\n\n/-- The morphism σ on {a, b} defined by a ↦ aab, b ↦ b, represented on Bool where\n`false` = a and `true` = b. -/\ndef morphism : Bool → List Bool\n  | false => [false, false, true]  -- a ↦ aab\n  | true => [true]                -- b ↦ b\n\n/-- The n-th iterate of the morphism applied to [a]. -/\ndef finiteWord : ℕ → List Bool\n  | 0 => [false]\n  | n + 1 => (finiteWord n).flatMap morphism\n\n@[simp, category API, AMS 68]\nlemma count_false_morphism (b : Bool) : count false (morphism b) = if b then 0 else 2 := by\n  cases b <;> simp [morphism]\n\n@[simp, category API, AMS 68]\nlemma count_true_morphism (b : Bool) : count true (morphism b) = 1 := by\n  cases b <;> simp [morphism]\n\n@[simp, category API, AMS 68]\nlemma count_false_finiteWord : ∀ n, (finiteWord n).count false = 2 ^ n\n  | 0 => rfl\n  | n + 1 => by\n    simp [finiteWord, count_flatMap, Function.comp_def, sum_map_ite, ← Bool.beq_eq_decide_eq,\n      -beq_false, ← count_eq_length_filter, count_false_finiteWord, pow_succ]\n\n@[simp, category API, AMS 68]\nlemma count_true_finiteWord : ∀ n, (finiteWord n).count true = 2 ^ n - 1\n  | 0 => rfl\n  | n + 1 => by\n    simp [finiteWord, List.count_flatMap, Function.comp_def, ← count_true_add_count_false,\n      count_true_finiteWord, pow_succ]; omega\n\n@[simp, category API, AMS 68]\nlemma length_finiteWord (n : ℕ) : (finiteWord n).length = 2 ^ (n + 1) - 1 := by\n  simp [← count_true_add_count_false, count_true_finiteWord, pow_succ]; omega\n\n/-- The infinite word w is the fixed point of the morphism starting from 'a'.\nWe define it as the limit: w(i) is the i-th symbol, which stabilizes after\nsufficiently many iterations. -/\nnoncomputable def infiniteWord (i : ℕ) : Bool :=\n  (finiteWord (i + 1))[i]'(by grw [length_finiteWord, ← Nat.lt_two_pow_self] <;> lia)\n\n/-- A subword (factor) of length n starting at position i. -/\nnoncomputable def subwordAt (i n : ℕ) : List Bool :=\n  (List.range n).map fun j => infiniteWord (i + j)\n\n/-- The set of all distinct subwords of length n in the infinite word. -/\ndef subwordsOfLength (n : ℕ) : Set (List Bool) :=\n  {w | ∃ i, w = subwordAt i n}\n\n/-- The subword complexity function: a(n) is the number of distinct subwords of length n. -/\nnoncomputable def a (n : ℕ) : ℕ := (subwordsOfLength n).ncard\n\nset_option linter.style.formal_proof_palomar false in\n/--\n**Conjecture (A6697)**: The generating function for the number of subwords of length $n$\nin the infinite word generated by $a \\mapsto aab, b \\mapsto b$ is\n$$\\sum_{n \\geq 0} a_n x^n = 1 + \\frac{1}{1-x} + \\frac{1}{(1-x)^2}\\left(\\frac{1}{1-x} -\n  \\sum_{k \\geq 0} x^{2^{k+1} + k}\\right).$$\n\nEquivalently, a(n) equals the n-th coefficient of this generating function.\n\nHowever, the reference quoted in the OEIS sequence\n\n> J.-P. Allouche and J. Shallit, \"On the subword complexity of the fixed point of a → aab, b → b,\n> and generalizations,\" arXiv:1605.02361 [math.CO], 2016.\n\nprovides an explicit formula\n$$ a_n = \\sum_{i=0}^{n} \\min(2^i,n-i+1). $$\n\nIf one takes this as a definition of a(n) instead,\nit becomes straightforward to prove the conjecture.\nSee https://github.com/AxiomMath/gdm-formal-conjectures/blob/main/docs/OeisA6697.md\nfor a formal proof of the generating function using this definition.\n\nHence, a formalization of [arXiv:1605.02361](https://arxiv.org/abs/1605.02361)\nwould complete a formal proof as below.\n-/\n@[category research solved, formal_proof using lean4 at \"https://github.com/AxiomMath/gdm-formal-conjectures/blob/main/OeisA6697/solution.lean\", AMS 68]\ntheorem conjecture (n : ℕ) :\n    a n = coeff (R := ℚ) n\n      ((1 - X)⁻¹ + X * (1 - X)⁻¹ ^ 2 * ((1 - X)⁻¹ - ∑' k, X ^ (2 ^ (k + 1) + k))) := by\n  sorry\n\nend OeisA6697\n",
  "statement_hash": "036fde34dad74ba69a5c5a734c7b0d7d413a4e8e94b9e4e06dcab82de1fd9d49",
  "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."
}