/-
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.
-/
import FormalConjecturesUtilConjectures associated with A109845
$a(1) = 2$; $a(2n)$ = lcm of all previous terms + 1; $a(2n+1)$ = lcm of all previous terms - 1.
References:
namespace OeisA109845$a(1) = 2$; $a(2n)$ = lcm of all previous terms + 1; $a(2n+1)$ = lcm of all previous terms - 1. The sequence is correctly generated by the recurrence relation $a(1)=2$, $a(2)=3$, and for $n \ge 3$: $$a(n) = a(n-1)^2 + (-1)^n a(n-1) + (-1)^n.$$ We use $0$-based indexing here, so $a(n)$ corresponds to the OEIS sequence $a(n+1)$.
def a : ℕ → ℕ
| 0 => 2
| 1 => 3
| n + 2 =>
let prev := a (n + 1)
if n % 2 = 0 then
prev * prev - (prev + 1)
else
prev * prev + prev + 1@[category test, AMS 11]
theorem a_0 : a 0 = 2 := ⊢ a 0 = 2 All goals completed! 🐙@[category test, AMS 11]
theorem a_1 : a 1 = 3 := ⊢ a 1 = 3 All goals completed! 🐙@[category test, AMS 11]
theorem a_2 : a 2 = 5 := ⊢ a 2 = 5 All goals completed! 🐙@[category test, AMS 11]
theorem a_3 : a 3 = 31 := ⊢ a 3 = 31 All goals completed! 🐙@[category test, AMS 11]
theorem a_4 : a 4 = 929 := ⊢ a 4 = 929 All goals completed! 🐙Conjecture: There are infinitely many primes in this sequence.
@[category research open, AMS 11]
theorem conjecture : Set.Infinite {n : ℕ | (a n).Prime} := ⊢ {n | Nat.Prime (a n)}.Infinite
All goals completed! 🐙end OeisA109845