/- 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 /-! # A108306: Expansion of $(3x+1)/(1-3x-3x^2)$ This sequence satisfies the linear recurrence relation $a(0)=1$, $a(1)=6$, and $a(n) = 3a(n-1) + 3a(n-2)$ for $n \ge 2$. *References:* - [A108306](https://oeis.org/A108306) -/ @[expose] public section namespace OeisA108306 /-- The primary defining sequence `a`. `a n` is the $n$-th term of the expansion of $(3x+1)/(1-3x-3x^2)$, satisfying $a(0)=1, a(1)=6, a(n)=3a(n-1)+3a(n-2)$. -/ def a : ℕ → ℕ | 0 => 1 | 1 => 6 | k + 2 => 3 * a (k + 1) + 3 * a k @[category test, AMS 11] theorem a_0 : a 0 = 1 := by decide @[category test, AMS 11] theorem a_1 : a 1 = 6 := by decide @[category test, AMS 11] theorem a_2 : a 2 = 21 := by decide @[category test, AMS 11] theorem a_3 : a 3 = 81 := by decide @[category test, AMS 11] theorem a_4 : a 4 = 306 := by decide open Matrix /-- The matrix for the specific case $a=5, b=2$. $$M = \begin{pmatrix} 1 & 5 \cr 1 & 2 \end{pmatrix}$$ -/ def m : Matrix (Fin 2) (Fin 2) ℕ := fun i j => match i, j with | 0, 0 => 1 | 0, 1 => 5 | 1, 0 => 1 | 1, 1 => 2 /-- The sequence is the INVERT transform of (1, 5, 10, 20, 40, 80, 160, ...) and can be obtained by extracting the upper left terms of matrix powers of [(1,5); (1,2)]. These results are a case (a=5, b=2) of the general conjecture below. -/ @[category textbook, AMS 11] theorem a_is_invert_transform_case (n : ℕ) : a n = (m ^ (n + 1)) 0 0 := by -- `m` satisfies `m ^ 2 = 3 m + 3`, so its powers satisfy the recurrence of `a`. have hm : ∀ n, m ^ (n + 2) = 3 • m ^ (n + 1) + 3 • m ^ n := fun n => by rw [pow_add, show m ^ 2 = 3 • m + 3 • (1 : Matrix (Fin 2) (Fin 2) ℕ) by decide, mul_add, mul_smul_comm, mul_smul_comm, mul_one, ← pow_succ] induction n using Nat.twoStepInduction with | zero => decide | one => decide | more k ih1 ih2 => rw [a, ih1, ih2, show k + 2 + 1 = k + 1 + 2 by omega, hm (k + 1)] simp only [Matrix.add_apply, Matrix.smul_apply, smul_eq_mul] /-- The c sequence for the general INVERT transform conjecture. $c(1) = 1$, $c(k)=ab^(k-2)$ for $k \ge 2$. -/ def invertSeqC (a b : ℕ) : ℕ → ℕ | 0 => 0 | 1 => 1 | (k + 2) => a * b^k /-- The INVERT transform of the sequence c. -/ noncomputable def invertSeqD (a b : ℕ) (n : ℕ) : ℕ := Nat.strongRecOn n (fun m ih => if m = 0 then 1 else ∑ i ∈ Finset.range m, if h : i < m then invertSeqC a b (m - i) * ih i h else 0) /-- The general 2x2 matrix [(1,a); (1,b)]. -/ def genMatrix (a b : ℕ) : Matrix (Fin 2) (Fin 2) ℕ := fun i j => match i, j with | 0, 0 => 1 | 0, 1 => a | 1, 0 => 1 | 1, 1 => b set_option linter.style.formal_proof_palomar false in /-- The conjecture: The INVERT transform of a sequence starting $(1, a, ab, ab^2, ab^3, \ldots)$ is equivalent to extracting the upper left terms of powers of the 2x2 matrix [(1,a); (1,b)]. -/ @[category research solved, AMS 11, formal_proof using lean4 at "https://github.com/KitaKen1/oeis-108306/blob/2e01e81b20a56880993e174ee4af0f0d7af37bdd/lean/OeisA108306FC.lean#L101-L106"] theorem conjecture (a_val b_val n : ℕ) : invertSeqD a_val b_val n = (genMatrix a_val b_val ^ n) 0 0 := by sorry end OeisA108306