{
  "id": "5232",
  "ident": "NS.05232",
  "slug": "oeis-2",
  "title": "Density of ones in the Kolakoski sequence",
  "status": "open",
  "statement_status": "reviewed",
  "statement_md": "\"It is an unsolved problem to show that the density of 1's is equal to 1/2.\"\n— [A000002](https://oeis.org/A000002)",
  "subjects": [
    "math.NT",
    "math.CO",
    "msc:11",
    "msc:68"
  ],
  "tags": [],
  "collection": "oeis",
  "source_url": null,
  "solved_on_platform": false,
  "needs_answer": false,
  "version": 1,
  "decl_name": "OeisA2.density_one",
  "statement_lean": "theorem density_one : {n : ℕ | a n = 1}.HasDensity (1 / 2 : ℝ)",
  "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-/\n\nmodule\n\npublic import FormalConjecturesUtil\n\n/-!\n# Density of ones in the Kolakoski sequence\n\nThe Kolakoski sequence is the self-describing sequence of ones and twos whose terms are the\nlengths of its successive runs. Its official indexing begins with $a(1) = 1$; here it is extended\nby $a(0) = 0$.\n\n*References:*\n- [A000002](https://oeis.org/A000002)\n- E. S. Kupin and E. S. Rowland,\n  [\"Bounds on the frequency of 1 in the Kolakoski word\"](https://arxiv.org/abs/0809.2776),\n  arXiv:0809.2776 [math.CO] (2008).\n-/\n\n@[expose] public section\n\nnamespace OeisA2\n\n/--\n`wordPrefix n` is the finite Kolakoski word after expanding `n` runs beyond the seed `[1, 2, 2]`.\nAt stage $n$, position $n+2$ supplies the next run length, and the emitted symbol is $1$ for\neven $n$ and $2$ for odd $n$.\n-/\ndef wordPrefix : ℕ → List ℕ\n  | 0 => [1, 2, 2]\n  | n + 1 =>\n      let xs := wordPrefix n\n      let runLength := if xs.getD (n + 2) 1 = 2 then 2 else 1\n      let nextSymbol := if n % 2 = 0 then 1 else 2\n      xs ++ List.replicate runLength nextSymbol\n\n/-- Every generated prefix is long enough for the next unread run length. -/\n@[category API, AMS 11 68]\ntheorem prefix_length (n : ℕ) : n + 3 ≤ (wordPrefix n).length := by\n  induction n with\n  | zero => norm_num [wordPrefix]\n  | succ n ih =>\n      simp only [wordPrefix, List.length_append, List.length_replicate]\n      split <;> omega\n\n/-- The read cursor used to generate the next run is always inside the generated prefix. -/\n@[category API, AMS 11 68]\ntheorem cursor_lt_prefix_length (n : ℕ) : n + 2 < (wordPrefix n).length := by\n  have h := prefix_length n\n  omega\n\n/-- Every symbol in every generated prefix is either `1` or `2`. -/\n@[category API, AMS 11 68]\ntheorem prefix_mem_one_or_two (n : ℕ) : ∀ x ∈ wordPrefix n, x = 1 ∨ x = 2 := by\n  induction n with\n  | zero => simp [wordPrefix]\n  | succ n ih =>\n      intro x hx\n      simp only [wordPrefix, List.mem_append] at hx\n      rcases hx with hx | hx\n      · exact ih x hx\n      · rw [List.eq_of_mem_replicate hx]\n        by_cases h : n % 2 = 0 <;> simp [h]\n\n/-- The Kolakoski sequence, using its official one-based indexing and extended by `a 0 = 0`. -/\ndef a : ℕ → ℕ\n  | 0 => 0\n  | n + 1 => (wordPrefix n).getD n 0\n\n/-- Every positive-index term of the public sequence is one or two. -/\n@[category API, AMS 11 68]\ntheorem a_one_or_two {n : ℕ} (hn : 0 < n) : a n = 1 ∨ a n = 2 := by\n  obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : n ≠ 0)\n  have hlt : n < (wordPrefix n).length := by\n    have h := prefix_length n\n    omega\n  apply prefix_mem_one_or_two n\n  rw [a]\n  have hget : (wordPrefix n).getD n 0 = (wordPrefix n)[n] :=\n    List.getD_eq_getElem (l := wordPrefix n) (d := 0) hlt\n  rw [hget]\n  exact List.getElem_mem hlt\n\n@[category test, AMS 11 68]\ntheorem a_0 : a 0 = 0 := by rfl\n\n@[category test, AMS 11 68]\ntheorem a_1 : a 1 = 1 := by norm_num [a, wordPrefix]\n\n@[category test, AMS 11 68]\ntheorem a_2 : a 2 = 2 := by norm_num [a, wordPrefix]\n\n@[category test, AMS 11 68]\ntheorem a_3 : a 3 = 2 := by norm_num [a, wordPrefix]\n\n@[category test, AMS 11 68]\ntheorem a_4 : a 4 = 1 := by norm_num [a, wordPrefix]\n\n@[category test, AMS 11 68]\ntheorem a_5 : a 5 = 1 := by norm_num [a, wordPrefix]\n\n@[category test, AMS 11 68]\ntheorem a_6 : a 6 = 2 := by norm_num [a, wordPrefix]\n\n@[category test, AMS 11 68]\ntheorem a_7 : a 7 = 1 := by norm_num [a, wordPrefix]\n\n@[category test, AMS 11 68]\ntheorem a_8 : a 8 = 2 := by norm_num [a, wordPrefix]\n\n@[category test, AMS 11 68]\ntheorem a_9 : a 9 = 2 := by norm_num [a, wordPrefix]\n\n@[category test, AMS 11 68]\ntheorem a_10 : a 10 = 1 := by norm_num [a, wordPrefix]\n\n/--\n\"It is an unsolved problem to show that the density of 1's is equal to 1/2.\"\n— [A000002](https://oeis.org/A000002)\n-/\n@[category research open, AMS 11 68]\ntheorem density_one : {n : ℕ | a n = 1}.HasDensity (1 / 2 : ℝ) := by\n  sorry\n\nend OeisA2\n",
  "statement_hash": "d37fd2f16d59539e88f76a3c0693a31a093105547bb8c1168ad916686df8150d",
  "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."
}