/- Copyright 2026 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. -/ module public import FormalConjecturesUtil

Rowland's GCD prime-generating recurrence

Define $a(1) = 7$ and $a(n) = a(n - 1) + \gcd(n, a(n - 1))$ for $n \ge 2$ (OEIS A106108), with step increments $d(n) = a(n) - a(n - 1) = \gcd(n, a(n - 1))$ (OEIS A132199 lists $d(n + 1)$ for $n \ge 1$). Eric S. Rowland established in 2008 that every $d(n)$ with $n \ge 2$ equals $1$ or an odd prime, and conjectured that every odd prime arises as $d(n)$ for some $n \ge 2$.

References:

@[expose] public sectionnamespace RowlandSequence

Rowland's sequence (OEIS A106108), starting at $a(1) = 7$ with recurrence $a(n) = a(n - 1) + \gcd(n, a(n - 1))$ for $n \ge 2$ (and $a(0) = 0$).

def rowlandSeq : ℕ → ℕ | 0 => 0 | 1 => 7 | n + 2 => let prev := rowlandSeq (n + 1) prev + Nat.gcd (n + 2) prev

Step increment $d(n) = a(n) - a(n - 1)$ of rowlandSeq (meaningful for $n \ge 2$; shifted by one from OEIS A132199, where A132199(n) = rowlandDiff (n + 1)).

def rowlandDiff (n : ℕ) : ℕ := rowlandSeq n - rowlandSeq (n - 1)

Checks the initial values $a(1), \dots, a(6) = 7, 8, 9, 10, 15, 18$ of rowlandSeq.

@[category test, AMS 11] theorem rowlandSeq_initial_values : rowlandSeq 1 = 7 ∧ rowlandSeq 2 = 8 ∧ rowlandSeq 3 = 9 ∧ rowlandSeq 4 = 10 ∧ rowlandSeq 5 = 15 ∧ rowlandSeq 6 = 18 := ⊢ rowlandSeq 1 = 7 ∧ rowlandSeq 2 = 8 ∧ rowlandSeq 3 = 9 ∧ rowlandSeq 4 = 10 ∧ rowlandSeq 5 = 15 ∧ rowlandSeq 6 = 18 All goals completed! 🐙

Checks $d(2) = 1$ alongside the odd-prime increments $d(5) = 5$, $d(6) = 3$, and $d(11) = 11$.

@[category test, AMS 11] theorem rowlandDiff_small_witnesses : rowlandDiff 2 = 1 ∧ rowlandDiff 5 = 5 ∧ rowlandDiff 6 = 3 ∧ rowlandDiff 11 = 11 := ⊢ rowlandDiff 2 = 1 ∧ rowlandDiff 5 = 5 ∧ rowlandDiff 6 = 3 ∧ rowlandDiff 11 = 11 All goals completed! 🐙

Rowland's theorem (2008): for every $n \ge 2$, the step $d(n) = a(n) - a(n - 1)$ equals $1$ or is prime.

@[category research solved, AMS 11] theorem rowland_diff_eq_one_or_prime {n : ℕ} (hn : 2 ≤ n) : rowlandDiff n = 1 ∨ (rowlandDiff n).Prime := n:ℕhn:2 ≤ n⊢ rowlandDiff n = 1 ∨ Nat.Prime (rowlandDiff n) All goals completed! 🐙

Rowland's conjecture (2008): every odd prime $p$ occurs as $d(n) = a(n) - a(n - 1)$ at some index $n \ge 2$. The prime $2$ is excluded because $n$ and $a(n - 1)$ always have opposite parity, and $n \ge 2$ excludes the artifact rowlandDiff 1 = 7.

@[category research open, AMS 11] theorem rowland_generates_all_odd_primes {p : ℕ} (hp : p.Prime) (hodd : Odd p) : ∃ n : ℕ, 2 ≤ n ∧ rowlandDiff n = p := p:ℕhp:Nat.Prime phodd:Odd p⊢ ∃ n, 2 ≤ n ∧ rowlandDiff n = p All goals completed! 🐙end RowlandSequence