{
  "id": "4364",
  "ident": "NS.04364",
  "slug": "mathoverflow-75792--complexity-three-pow",
  "title": "Mathoverflow 75792 · complexity_three_pow",
  "status": "solved",
  "statement_status": "reviewed",
  "statement_md": "Is `3n` the complexity of `3^n` for `0 < n`? Answer: Yes, by John Selfridge.\n\nReference: https://arxiv.org/abs/1207.4841",
  "subjects": [
    "math.NT",
    "msc:11"
  ],
  "tags": [
    "question"
  ],
  "collection": "mathoverflow",
  "source_url": null,
  "solved_on_platform": false,
  "needs_answer": false,
  "version": 1,
  "decl_name": "Mathoverflow75792.complexity_three_pow",
  "statement_lean": "theorem complexity_three_pow : ∀ n : ℕ, 0 < n → complexity (3 ^ n) = 3 * n",
  "challenge_source": "/-\nCopyright 2025 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# Mathoverflow 75792\n\nVarious questions about integer complexity, which is the minimum number of `1`s needed to express a natural number using addition, multiplication, and parentheses.\n\nLet `‖n‖` denote the integer complexity of `n > 0`.\n* It is known that `‖3^n‖ = 3n` for `n > 0`.\n* Is it true that `‖2^n‖ = 2n` for `n > 0`?\n* The corresponding conjecture for `5` is false, because\n  `5^6 = 15625 = 1 + 2^3 * 3^2 * (1 + 2^3 * 3^3)`!\n\nWe have chosen to formalise this using an inductive type.\n\n*References:*\n - [mathoverflow/75792](https://mathoverflow.net/a/75792) by user [Harry Altman](https://mathoverflow.net/users/5583)\n - http://arxiv.org/abs/1203.6462 by Jānis Iraids, Kaspars Balodis, Juris Čerņenoks, Mārtiņš Opmanis, Rihards Opmanis, Kārlis Podnieks\n - http://arxiv.org/abs/1207.4841 by Harry Altman, Joshua Zelinsky\n - https://oeis.org/A5245 : Mahler-Popken complexity.\n-/\n\n@[expose] public section\n\nnamespace Mathoverflow75792\n\n/-- The inductively defined predicate that `m` is reachable in `n` steps. -/\ninductive Reachable : ℕ → ℕ → Prop\n  | one : Reachable 1 1\n  | add {m n a b} : Reachable m a → Reachable n b → Reachable (m + n) (a + b)\n  | mul {m n a b} : Reachable m a → Reachable n b → Reachable (m * n) (a + b)\n\n@[category test, AMS 11]\ntheorem Reachable.self (n : ℕ) (hn : 0 < n) : Reachable n n :=\n  Nat.le_induction .one (fun _ _ ih ↦ .add ih .one) n hn\n\n@[category test, AMS 11]\ntheorem not_reachable_zero_fst (n : ℕ) : ¬ Reachable 0 n := by\n  intro h; generalize hm : 0 = m at h; induction h with\n  | one => exact absurd hm (by decide)\n  | add h₁ h₂ => rw [eq_comm, add_eq_zero] at hm; aesop\n  | mul h₁ h₂ => rw [eq_comm, mul_eq_zero] at hm; aesop\n\n@[category test, AMS 11]\ntheorem not_reachable_zero_snd (m : ℕ) : ¬ Reachable m 0 := by\n  intro h; generalize hn : 0 = n at h; induction h with\n  | one => exact absurd hn (by decide)\n  | add h₁ h₂ => rw [eq_comm, add_eq_zero] at hn; aesop\n  | mul h₁ h₂ => rw [eq_comm, add_eq_zero] at hn; aesop\n\n@[category test, AMS 11]\ntheorem Reachable.dec {m n : ℕ} (h : Reachable m n) :\n    ∃ m' n', m' + 1 = m ∧ n' + 1 = n := by\n  obtain _ | m := m\n  · exact absurd h (not_reachable_zero_fst _)\n  obtain _ | n := n\n  · exact absurd h (not_reachable_zero_snd _)\n  exact ⟨_, _, rfl, rfl⟩\n\n@[category test, AMS 11]\ntheorem Reachable.le {m n₁ n₂ : ℕ} (hn : n₁ ≤ n₂) (hm : Reachable m n₁) : Reachable m n₂ := by\n  induction hn with\n  | refl => exact hm\n  | step h ih => convert ih.mul .one; simp\n\n@[category test, AMS 11]\ntheorem reachable_iff_of_two_le (m n : ℕ) (hm : 2 ≤ m) :\n    Reachable m n ↔ ∃ m₁, ∃ _ : m₁ < m, ∃ m₂, ∃ _ : m₂ < m, ∃ n₁, ∃ _ : n₁ < n, ∃ n₂, ∃ _ : n₂ < n,\n      n₁ + n₂ = n ∧ Reachable m₁ n₁ ∧ Reachable m₂ n₂ ∧ (m₁ + m₂ = m ∨ m₁ * m₂ = m) := by\n  refine ⟨fun hmn ↦ ?_, fun ⟨m₁, hm₁, m₂, hm₂, n₁, hn₁, n₂, hn₂, h₁, h₂, h₃, h₄⟩ ↦\n    h₁ ▸ h₄.casesOn (· ▸ .add h₂ h₃) (· ▸ .mul h₂ h₃)⟩\n  induction hmn with\n  | one => exact absurd hm (by decide)\n  | @add m₃ m₄ n₃ n₄ h₁ h₂ ih₁ ih₂ =>\n      obtain ⟨m₃, n₃, rfl, rfl⟩ := h₁.dec\n      obtain ⟨m₄, n₄, rfl, rfl⟩ := h₂.dec\n      refine ⟨m₃ + 1, ?_, m₄ + 1, ?_, n₃ + 1, ?_, n₄ + 1, ?_, rfl, h₁, h₂, .inl rfl⟩ <;> omega\n  | @mul m₃ m₄ n₃ n₄ h₁ h₂ ih₁ ih₂ =>\n      obtain ⟨m₃, n₃, rfl, rfl⟩ := h₁.dec\n      obtain ⟨m₄, n₄, rfl, rfl⟩ := h₂.dec\n      obtain _ | m₃ := m₃\n      · obtain ⟨m₅, hm₅, m₆, hm₆, n₅, hn₅, n₆, hn₆, h₃, h₄, h₅, h₆⟩ := ih₂ (by omega)\n        refine ⟨m₅, ?_, m₆, ?_, n₅+n₃+1, ?_, n₆, ?_, by rw [← h₃]; ring, h₄.le ?_, h₅, ?_⟩\n        all_goals omega\n      obtain _ | m₄ := m₄\n      · obtain ⟨m₅, hm₅, m₆, hm₆, n₅, hn₅, n₆, hn₆, h₃, h₄, h₅, h₆⟩ := ih₁ (by omega)\n        refine ⟨m₅, ?_, m₆, ?_, n₅, ?_, n₆+n₄+1, ?_, by rw [← h₃]; ring, h₄, h₅.le ?_, ?_⟩\n        all_goals omega\n      refine ⟨m₃+2, ?_, m₄+2, ?_, _, ?_, _, ?_, rfl, h₁, h₂, .inr rfl⟩\n      · refine (Nat.lt_mul_iff_one_lt_right ?_).2 ?_ <;> omega\n      · refine (Nat.lt_mul_iff_one_lt_left ?_).2 ?_ <;> omega\n      all_goals omega\n\n/-- Auxiliary decision procedure for `Reachable`, taking a fuel argument `f` bounding `m`.\n\n`reachable_iff_of_two_le` reduces `Reachable m n` for `2 ≤ m` to statements `Reachable m' n'` with\n`m' < m`, so one unit of fuel per unit of `m` always suffices. Recursing on the fuel rather than on\n`m` makes this structural, so `Reachable.decide` below avoids well-founded recursion. -/\ndef Reachable.decAux : ∀ (f m n : ℕ), m ≤ f → Decidable (Reachable m n)\n  |     _,     0,     n,  _ => isFalse (not_reachable_zero_fst n)\n  |     _,     1,     0,  _ => isFalse (not_reachable_zero_snd 1)\n  |     _,     1, _ + 1,  _ => isTrue (Reachable.one.le (by lia))\n  |     0, _ + 2,     _, hf => absurd hf (by lia)\n  | f + 1, m + 2,     n, hf => by\n      let d : ∀ {m₁} (h : m₁ < m + 2) {n}, Decidable (Reachable m₁ n) :=\n        fun h ↦ Reachable.decAux f _ _ (by lia)\n      refine @decidable_of_iff' _ _ (reachable_iff_of_two_le (m+2) n (by lia)) ?_\n      refine Nat.decidableExistsLT' (I := fun m₁ hm₁ ↦ ?_)\n      refine Nat.decidableExistsLT' (I := fun m₂ hm₂ ↦ ?_)\n      refine Nat.decidableExistsLT' (I := fun n₁ hn₁ ↦ ?_)\n      refine Nat.decidableExistsLT' (I := fun n₂ hn₂ ↦ ?_)\n      refine instDecidableAnd (dq := ?_)\n      refine instDecidableAnd (dp := d hm₁) (dq := ?_)\n      exact instDecidableAnd (dp := d hm₂)\n  termination_by structural f => f\n\ninstance Reachable.decide (m n : ℕ) : Decidable (Reachable m n) := Reachable.decAux m m n le_rfl\n\n/--\nThe [(Mahler-Popken) complexity of `n`](https://en.wikipedia.org/wiki/Integer_complexity):\nthe minimum number of `1`s needed to express a given number using only addition and\nmultiplication. E.g. `2 = 1 + 1`, so `complexity 2 = 2`.\n-/\ndef complexity (n : ℕ) : ℕ :=\n  if h : n = 0 then 0 else Nat.find ⟨n, Reachable.self n <| n.pos_of_ne_zero h⟩\n\n@[category test, AMS 11]\ntheorem Reachable.complexity_le {m n : ℕ} (h : Reachable m n) : complexity m ≤ n := by\n  unfold complexity\n  split_ifs with h'\n  · subst h'; exact absurd h (not_reachable_zero_fst n)\n  exact Nat.find_min' _ h\n\n@[category test, AMS 11]\ntheorem Reachable.complexity_eq {m n : ℕ} (h : Reachable m n)\n    (min : ∀ n' < n, ¬ Reachable m n') : complexity m = n := by\n  refine le_antisymm h.complexity_le ?_\n  unfold complexity\n  split_ifs with h'\n  · subst h'; exact absurd h (not_reachable_zero_fst n)\n  exact (Nat.le_find_iff _ _).2 min\n\n@[category test, AMS 11]\ntheorem Reachable.complexity {n : ℕ} (hn : 0 < n) : Reachable n (complexity n) := by\n  unfold Mathoverflow75792.complexity\n  rw [dif_neg (ne_of_gt hn)]\n  exact Nat.find_spec _\n\n@[category test, AMS 11]\ntheorem complexity_zero : complexity 0 = 0 := rfl\n\n@[category test, AMS 11]\ntheorem complexity_one : complexity 1 = 1 :=\n  Reachable.one.complexity_eq fun n' hn' ↦ by\n    have : n' = 0 := by omega\n    subst this; exact not_reachable_zero_snd 1\n\n@[category test, AMS 11]\ntheorem complexity_two : complexity 2 = 2 :=\n  (Reachable.add .one .one).complexity_eq fun n' hn' ↦ by\n    interval_cases n'\n    · exact not_reachable_zero_snd 2\n    · rw [reachable_iff_of_two_le 2 1 (by omega)]\n      rintro ⟨m₁, hm₁, m₂, hm₂, n₁, hn₁, n₂, hn₂, h₁, -⟩\n      omega\n\n@[category test, AMS 11]\ntheorem Reachable.pow (m n : ℕ) (hm : 0 < m) (hn : 0 < n) : Reachable (m ^ n) (m * n) := by\n  induction hn with\n  | refl => convert Reachable.self m hm <;> simp\n  | step hn ih => exact .mul ih (.self m hm)\n\n@[category test, AMS 11]\ntheorem Reachable.pow' (m n : ℕ+) : Reachable (m ^ (n : ℕ) : ℕ) (m * n) :=\n  .pow _ _ m.pos n.pos\n\n/-- `5^6 = 15625 = 1 + 2^3 * 3^2 * (1 + 2^3 * 3^3)`! -/\n@[category test, AMS 11]\ntheorem Reachable.five_pow_six : Reachable (5^6) 29 :=\n  have h8 : Reachable 8 6 := .pow' 2 3\n  have h9 : Reachable 9 6 := .pow' 3 2\n  have h27 : Reachable 27 9 := .pow' 3 3\n  .add .one <| .mul h8 <| .mul h9 <| .add .one <| .mul h8 h27\n\n/-- Is `5n` the complexity of `5^n` for `0 < n`? Answer: No. -/\n@[category research solved, question, AMS 11]\ntheorem complexity_five_pow : ¬ ∀ n : ℕ, 0 < n → complexity (5 ^ n) = 5 * n := by\n  simp [not_forall]\n  exact ⟨6, by decide, fun h ↦ absurd (h ▸ Reachable.five_pow_six.complexity_le) (by decide)⟩\n\n/-- Is `3n` the complexity of `3^n` for `0 < n`? Answer: Yes, by John Selfridge.\n\nReference: https://arxiv.org/abs/1207.4841\n-/\n@[category research solved, question, AMS 11]\ntheorem complexity_three_pow : ∀ n : ℕ, 0 < n → complexity (3 ^ n) = 3 * n := by\n  sorry\n\n/-- Is `2n` the complexity of `2^n` for `0 < n`? -/\n@[category research open, question, AMS 11]\ntheorem complexity_two_pow : ∀ n : ℕ, 0 < n → complexity (2 ^ n) = 2 * n := by\n  sorry\n\nend Mathoverflow75792\n",
  "statement_hash": "4a73aa79ccc157ba16b112ed7471f465042117a76844ff572cba9310dac6c625",
  "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."
}