/- Copyright 2025 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ import FormalConjecturesUtil

Erdős Problem 409

Reference: erdosproblems.com/409

open scoped Topology ArithmeticFunction.sigma Natopen Filter namespace Erdos409

How many iterations of $n\mapsto\phi(n) + 1$ are needed before a prime is reached?

-- Formalisation note: the sequence of iterates always terminates if `n > 0` -- since it is strictly decreasing unless the input is prime, at which point -- it becomes static. See also https://oeis.org/A39651 @[category research open, AMS 11] theorem declaration uses 'sorry'erdos_409.parts.i (n : ) (hn : 0 < n) : IsLeast { i | (φ · + 1)^[i] n |>.Prime } answer(sorry) := n:hn:0 < nIsLeast {i | Nat.Prime ((fun x => φ x + 1)^[i] n)} sorry All goals completed! 🐙

If $n > 0$, then the iteration $n\mapsto\phi(n) + 1$ necessarily reaches a prime.

@[category test, AMS 11] theorem erdos_409.variants.termination (n : ) (hn : 0 < n) : i, (φ · + 1)^[i] n |>.Prime := n:hn:0 < n i, Nat.Prime ((fun x => φ x + 1)^[i] n) induction n using Nat.strong_induction_on with n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < n i, Nat.Prime ((fun x => φ x + 1)^[i] n) n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:Nat.Prime n i, Nat.Prime ((fun x => φ x + 1)^[i] n)n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:¬Nat.Prime n i, Nat.Prime ((fun x => φ x + 1)^[i] n) n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:Nat.Prime n i, Nat.Prime ((fun x => φ x + 1)^[i] n) exact 0, n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:Nat.Prime nNat.Prime ((fun x => φ x + 1)^[0] n) All goals completed! 🐙 n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:¬Nat.Prime n i, Nat.Prime ((fun x => φ x + 1)^[i] n) have h1 : n = 1 1 < n := n:hn:0 < n i, Nat.Prime ((fun x => φ x + 1)^[i] n) All goals completed! 🐙 n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:¬Nat.Prime nh1:n = 1 i, Nat.Prime ((fun x => φ x + 1)^[i] n)n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:¬Nat.Prime nh1:1 < n i, Nat.Prime ((fun x => φ x + 1)^[i] n) n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:¬Nat.Prime nh1:n = 1 i, Nat.Prime ((fun x => φ x + 1)^[i] n) ih: m < 1, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < 1hp:¬Nat.Prime 1 i, Nat.Prime ((fun x => φ x + 1)^[i] 1) ih: m < 1, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < 1hp:¬Nat.Prime 1Nat.Prime ((fun x => φ x + 1)^[1] 1) All goals completed! 🐙 n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:¬Nat.Prime nh1:1 < n i, Nat.Prime ((fun x => φ x + 1)^[i] n) n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:¬Nat.Prime nh1:1 < nhlt:φ n < n := Nat.totient_lt n h1 i, Nat.Prime ((fun x => φ x + 1)^[i] n) have hne : φ n n - 1 := n:hn:0 < n i, Nat.Prime ((fun x => φ x + 1)^[i] n) n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:¬Nat.Prime nh1:1 < nhlt:φ n < n := Nat.totient_lt n h1h:φ n = n - 1False All goals completed! 🐙 have hdec : φ n + 1 < n := n:hn:0 < n i, Nat.Prime ((fun x => φ x + 1)^[i] n) All goals completed! 🐙 have hpos : 0 < φ n + 1 := n:hn:0 < n i, Nat.Prime ((fun x => φ x + 1)^[i] n) All goals completed! 🐙 n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:¬Nat.Prime nh1:1 < nhlt:φ n < n := Nat.totient_lt n h1hne:φ n n - 1 := fun h => hp ((Nat.totient_eq_iff_prime hn).mp h)hdec:φ n + 1 < n := Decidable.byContradiction fun a => termination._proof_2 n h1 hlt hne ahpos:0 < φ n + 1 := add_pos' (Nat.totient_pos.mpr hn) (Mathlib.Meta.Positivity.pos_of_isNat (Mathlib.Meta.NormNum.isNat_ofNat (Eq.refl 1)) (Eq.refl (Nat.ble 1 1)))i:hi:Nat.Prime ((fun x => φ x + 1)^[i] (φ n + 1)) i, Nat.Prime ((fun x => φ x + 1)^[i] n) n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:¬Nat.Prime nh1:1 < nhlt:φ n < n := Nat.totient_lt n h1hne:φ n n - 1 := fun h => hp ((Nat.totient_eq_iff_prime hn).mp h)hdec:φ n + 1 < n := Decidable.byContradiction fun a => termination._proof_2 n h1 hlt hne ahpos:0 < φ n + 1 := add_pos' (Nat.totient_pos.mpr hn) (Mathlib.Meta.Positivity.pos_of_isNat (Mathlib.Meta.NormNum.isNat_ofNat (Eq.refl 1)) (Eq.refl (Nat.ble 1 1)))i:hi:Nat.Prime ((fun x => φ x + 1)^[i] (φ n + 1))Nat.Prime ((fun x => φ x + 1)^[i + 1] n) n:ih: m < n, 0 < m i, Nat.Prime ((fun x => φ x + 1)^[i] m)hn:0 < nhp:¬Nat.Prime nh1:1 < nhlt:φ n < n := Nat.totient_lt n h1hne:φ n n - 1 := fun h => hp ((Nat.totient_eq_iff_prime hn).mp h)hdec:φ n + 1 < n := Decidable.byContradiction fun a => termination._proof_2 n h1 hlt hne ahpos:0 < φ n + 1 := add_pos' (Nat.totient_pos.mpr hn) (Mathlib.Meta.Positivity.pos_of_isNat (Mathlib.Meta.NormNum.isNat_ofNat (Eq.refl 1)) (Eq.refl (Nat.ble 1 1)))i:hi:Nat.Prime ((fun x => φ x + 1)^[i] (φ n + 1))Nat.Prime ((fun x => φ x + 1)^[i] (φ n + 1)) All goals completed! 🐙

Let $c(n)$ be the minimum number of iterations of $n\mapsto\phi(n) + 1$ before a prime is reached. What is $\Theta(c(n))$?

@[category research open, AMS 11] theorem declaration uses 'sorry'erdos_409.parts.i.isTheta (c : ) (h : n > 0, IsLeast { i | (φ · + 1)^[i] n |>.Prime } (c n)) : (fun n => (c n : )) =Θ[atTop] (answer(sorry) : ) := c: h: n > 0, IsLeast {i | Nat.Prime ((fun x => φ x + 1)^[i] n)} (c n)(fun n => (c n)) =Θ[atTop] sorry All goals completed! 🐙

Let $c(n)$ be the minimum number of iterations of $n\mapsto\phi(n) + 1$ before a prime is reached. Find the simplest function $g(n)$ such that $c(n) = O(g(n))$?

@[category research open, AMS 11] theorem declaration uses 'sorry'erdos_409.parts.i.isBigO (c : ) (h : n > 0, IsLeast { i | (φ · + 1)^[i] n |>.Prime } (c n)) : (fun n => (c n : )) =O[atTop] (answer(sorry) : ) := c: h: n > 0, IsLeast {i | Nat.Prime ((fun x => φ x + 1)^[i] n)} (c n)(fun n => (c n)) =O[atTop] sorry All goals completed! 🐙

Let $c(n)$ be the minimum number of iterations of $n\mapsto\phi(n) + 1$ before a prime is reached. Find the simplest function $g(n)$ such that $c(n) = o(g(n))$?

@[category research open, AMS 11] theorem declaration uses 'sorry'erdos_409.parts.i.isLittleO (c : ) (h : n > 0, IsLeast { i | (φ · + 1)^[i] n |>.Prime } (c n)) : (fun n => (c n : )) =o[atTop] (answer(sorry) : ) := c: h: n > 0, IsLeast {i | Nat.Prime ((fun x => φ x + 1)^[i] n)} (c n)(fun n => (c n)) =o[atTop] sorry All goals completed! 🐙

Can infinitely many $n$ reach the same prime under the iteration $n\mapsto\phi(n) + 1$?

@[category research open, AMS 11] theorem declaration uses 'sorry'erdos_409.parts.ii : answer(sorry) (p : ) (hp : p.Prime), { n | i, (φ · + 1)^[i] n = p }.Infinite := True p, (_ : Nat.Prime p), {n | i, (fun x => φ x + 1)^[i] n = p}.Infinite All goals completed! 🐙

What is the density of $n$ which reach any fixed prime under the iteration $n\mapsto\phi(n) + 1$?

@[category research open, AMS 11] theorem declaration uses 'sorry'erdos_409.parts.iii (p : ) (h : p.Prime) (α : ) ( : { n | i, (φ · + 1)^[i] n = p }.HasDensity α) : α = answer(sorry) := p:h:Nat.Prime pα::{n | i, (fun x => φ x + 1)^[i] n = p}.HasDensity αα = sorry All goals completed! 🐙

How many iterations of $n\mapsto\sigma(n) - 1$ are needed before a prime is reached?

-- Formalisation note: non-termination of this sequence is less clear since -- it is strictly increasing except at primes. @[category research open, AMS 11] theorem declaration uses 'sorry'erdos_409.variants.sigma (n : ) (hn : n > 1) : IsLeast { i | (σ 1 · - 1)^[i] n |>.Prime } answer(sorry) := n:hn:n > 1IsLeast {i | Nat.Prime ((fun x => (σ 1) x - 1)^[i] n)} sorry All goals completed! 🐙

If $n > 1$ then the iteration $n\mapsto\sigma(n) - 1$ necessarily reaches a prime. Note: this is open — it is not clear that the σ iteration always terminates, since it is non-decreasing (unlike the φ iteration which is strictly decreasing).

@[category research open, AMS 11] theorem declaration uses 'sorry'erdos_409.variants.sigma_termination (n : ) (hn : n > 1) : i, (σ 1 · - 1)^[i] n |>.Prime := n:hn:n > 1 i, Nat.Prime ((fun x => (σ 1) x - 1)^[i] n) All goals completed! 🐙

Let $c(n)$ be the minimum number of iterations of $n\mapsto\sigma(n) - 1$ before a prime is reached. What is $\Theta(c(n))$?

@[category research open, AMS 11] theorem declaration uses 'sorry'erdos_409.variants.sigma_isTheta (c : ) (h : n > 1, IsLeast { i | (σ 1 · - 1)^[i] n |>.Prime } (c n)) : (fun n => (c n : )) =Θ[atTop] (answer(sorry) : ) := c: h: n > 1, IsLeast {i | Nat.Prime ((fun x => (σ 1) x - 1)^[i] n)} (c n)(fun n => (c n)) =Θ[atTop] sorry All goals completed! 🐙

Let $c(n)$ be the minimum number of iterations of $n\mapsto\sigma(n) - 1$ before a prime is reached. Find the simplest function $g(n)$ such that $c(n) = O(g(n))$?

@[category research open, AMS 11] theorem declaration uses 'sorry'erdos_409.variants.sigma_isBigO (c : ) (h : n > 1, IsLeast { i | (σ 1 · - 1)^[i] n |>.Prime } (c n)) : (fun n => (c n : )) =O[atTop] (answer(sorry) : ) := c: h: n > 1, IsLeast {i | Nat.Prime ((fun x => (σ 1) x - 1)^[i] n)} (c n)(fun n => (c n)) =O[atTop] sorry All goals completed! 🐙

Let $c(n)$ be the minimum number of iterations of $n\mapsto\sigma(n) - 1$ before a prime is reached. Find the simplest function $g(n)$ such that $c(n) = o(g(n))$?

@[category research open, AMS 11] theorem declaration uses 'sorry'erdos_409.variants.sigma_isLittleO (c : ) (h : n > 1, IsLeast { i | (σ 1 · - 1)^[i] n |>.Prime } (c n)) : (fun n => (c n : )) =o[atTop] (answer(sorry) : ) := c: h: n > 1, IsLeast {i | Nat.Prime ((fun x => (σ 1) x - 1)^[i] n)} (c n)(fun n => (c n)) =o[atTop] sorry All goals completed! 🐙

Is it true that iterates of $n\mapsto\sigma(n) - 1$ always reach a prime?

@[category research open, AMS 11] theorem declaration uses 'sorry'erdos_409.variants.sigma_prime_termination : answer(sorry) n > 1, i, (σ 1 · - 1)^[i] n |>.Prime := True n > 1, i, Nat.Prime ((fun x => (σ 1) x - 1)^[i] n) All goals completed! 🐙 end Erdos409