Mode of #cas

rsolve

The general solution of a linear recurrence with constant coefficients, or the sequence with given initial values, with a theorem.

#cas [rsolve a n] eq
gives the general solution of the linear recurrence eq for the sequence a, and proves that every solution has this form.
#cas [rsolve a n, a 0 = v₀, …] eq
gives the sequence with these initial values, and proves that it is the only one.

rsolve finds a closed form for a linear recurrence, such as Binet’s formula for the Fibonacci numbers. I wanted more than a formula that matches the first few terms, so the theorem is an equivalence about every sequence a : ℕ → ℝ: it satisfies the recurrence, and the initial values when they are given, exactly when it has the printed form.

The closed form comes from the roots of the characteristic polynomial. Rational roots and the roots of quadratic factors are written exactly, and the other roots are certified enclosures. When the right side has terms cnjrn, we find a particular solution by undetermined coefficients.

Details and Options

  • Without initial values, for a recurrence of order d and the printed general solution y, the theorem is ∀ a : ℕ → ℝ, (∀ n, eq) ↔ ∃ c₁ … c_d, ∀ n, a n = y n. With initial values it is ∀ a : ℕ → ℝ, (∀ n, eq) ∧ initial values ↔ ∀ n, a n = Y n for the printed sequence Y.
  • The recurrence is linear in a with constant rational coefficients. The sequence enters as a n and as shifts a (n + k) with a numeral k, and the coefficient of a n is not zero. The right side may contain terms c * n ^ j * r ^ n.
  • An enclosed real root is named r₁, r₂, …, and a pair of complex roots z₁, conj z₁ gives the real terms re(z₁^n) and im(z₁^n). The theorem states their enclosures first.
  • A recurrence of order d takes d initial values at consecutive indices, such as a 0 = 0, a 1 = 1 or a 1 = 1, a 2 = 1.
  • There are no options. The tactic cas does not prove the statements of rsolve, and the closed form follows from the recurrence by induction, as in the example under Applications.

Examples (20)#

Basic Examples (2)

The Fibonacci numbers. Binet’s formula is the only sequence with the recurrence and these initial values:

In[1]:=
#cas [rsolve a n, a 0 = 0, a 1 = 1] (a (n + 2) = a (n + 1) + a n)
Out[1]=

the sequence with these initial values

a(n)=(1+52)n−(1−52)n5
a n = (((1 + sqrt(5))/2)^n - ((1 - sqrt(5))/2)^n)/sqrt(5)
Domain
a : ℕ → ℝ
Input (recurrence with initial values)
a (n + 2) = a (n + 1) + a n, a 0 = 0, a 1 = 1

Checked by Lean’s kernel: A sequence has the recurrence and the initial values exactly when it is the closed form

∀ (a : ℕ → ℝ),
  (∀ (n : ℕ), a (n + 2) = a (n + 1) + a n) ∧ a 0 = 0 ∧ a 1 = 1 ↔
    ∀ (n : ℕ), a n = (((1 + √5) / 2) ^ n - ((1 - √5) / 2) ^ n) / √5
The certificate: 1 checked step
  1. A sequence has the recurrence and the initial values exactly when it is the closed form

    ∀ (a : ℕ → ℝ),
      (∀ (n : ℕ), a (n + 2) = a (n + 1) + a n) ∧ a 0 = 0 ∧ a 1 = 1 ↔
        ∀ (n : ℕ), a n = (((1 + √5) / 2) ^ n - ((1 - √5) / 2) ^ n) / √5

    Checked by Lean’s kernel


Without initial values, the general solution of this recurrence of order 2 has two constants:

In[2]:=
#cas [rsolve a n] (a (n + 2) = a (n + 1) + a n)
Out[2]=

general solution

a(n)=c1(1+52)n+c2(1−52)n
a n = c₁*((1 + sqrt(5))/2)^n + c₂*((1 - sqrt(5))/2)^n
Domain
a : ℕ → ℝ
Input (recurrence)
a (n + 2) = a (n + 1) + a n

Checked by Lean’s kernel: Closed form of every solution

∀ (a : ℕ → ℝ),
  (∀ (n : ℕ), a (n + 2) = a (n + 1) + a n) ↔
    ∃ c₁ c₂, ∀ (n : ℕ), a n = c₁ * ((1 + √5) / 2) ^ n + c₂ * ((1 - √5) / 2) ^ n
The certificate: 1 checked step
  1. Closed form of every solution

    ∀ (a : ℕ → ℝ),
      (∀ (n : ℕ), a (n + 2) = a (n + 1) + a n) ↔
        ∃ c₁ c₂, ∀ (n : ℕ), a n = c₁ * ((1 + √5) / 2) ^ n + c₂ * ((1 - √5) / 2) ^ n

    Checked by Lean’s kernel

Scope (8)

A first-order recurrence with a constant term:

In[3]:=
#cas [rsolve a n, a 0 = 1] (a (n + 1) = 2 * a n + 1)
Out[3]=

the sequence with these initial values

a(n)=−1+2·2n
a n = -1 + 2*2^n
Domain
a : ℕ → ℝ
Input (recurrence with initial values)
a (n + 1) = 2 * a n + 1, a 0 = 1

Checked by Lean’s kernel: A sequence has the recurrence and the initial values exactly when it is the closed form

∀ (a : ℕ → ℝ), (∀ (n : ℕ), a (n + 1) = 2 * a n + 1) ∧ a 0 = 1 ↔ ∀ (n : ℕ), a n = -1 + 2 * 2 ^ n
The certificate: 1 checked step
  1. A sequence has the recurrence and the initial values exactly when it is the closed form

    ∀ (a : ℕ → ℝ), (∀ (n : ℕ), a (n + 1) = 2 * a n + 1) ∧ a 0 = 1 ↔ ∀ (n : ℕ), a n = -1 + 2 * 2 ^ n

    Checked by Lean’s kernel


Two rational characteristic roots, in the general solution and with initial values:

In[4]:=
#cas [rsolve a n] (a (n + 2) = 5 * a (n + 1) - 6 * a n)
Out[4]=

general solution

a(n)=c1·2n+c2·3n
a n = c₁*2^n + c₂*3^n
Domain
a : ℕ → ℝ
Input (recurrence)
a (n + 2) = 5 * a (n + 1) - 6 * a n

Checked by Lean’s kernel: Closed form of every solution

∀ (a : ℕ → ℝ),
  (∀ (n : ℕ), a (n + 2) = 5 * a (n + 1) - 6 * a n) ↔ ∃ c₁ c₂, ∀ (n : ℕ), a n = c₁ * 2 ^ n + c₂ * 3 ^ n
The certificate: 1 checked step
  1. Closed form of every solution

    ∀ (a : ℕ → ℝ),
      (∀ (n : ℕ), a (n + 2) = 5 * a (n + 1) - 6 * a n) ↔ ∃ c₁ c₂, ∀ (n : ℕ), a n = c₁ * 2 ^ n + c₂ * 3 ^ n

    Checked by Lean’s kernel

In[5]:=
#cas [rsolve a n, a 0 = 2, a 1 = 3] (a (n + 2) = 3 * a (n + 1) - 2 * a n)
Out[5]=

the sequence with these initial values

a(n)=1+2n
a n = 1 + 2^n
Domain
a : ℕ → ℝ
Input (recurrence with initial values)
a (n + 2) = 3 * a (n + 1) - 2 * a n, a 0 = 2, a 1 = 3

Checked by Lean’s kernel: A sequence has the recurrence and the initial values exactly when it is the closed form

∀ (a : ℕ → ℝ),
  (∀ (n : ℕ), a (n + 2) = 3 * a (n + 1) - 2 * a n) ∧ a 0 = 2 ∧ a 1 = 3 ↔ ∀ (n : ℕ), a n = 1 + 2 ^ n
The certificate: 1 checked step
  1. A sequence has the recurrence and the initial values exactly when it is the closed form

    ∀ (a : ℕ → ℝ),
      (∀ (n : ℕ), a (n + 2) = 3 * a (n + 1) - 2 * a n) ∧ a 0 = 2 ∧ a 1 = 3 ↔ ∀ (n : ℕ), a n = 1 + 2 ^ n

    Checked by Lean’s kernel


A double root gives the terms 1 and n:

In[6]:=
#cas [rsolve a n] (a (n + 2) = 2 * a (n + 1) - a n)
Out[6]=

general solution

a(n)=c1+c2n
a n = c₁ + c₂*n
Domain
a : ℕ → ℝ
Input (recurrence)
a (n + 2) = 2 * a (n + 1) - a n

Checked by Lean’s kernel: Closed form of every solution

∀ (a : ℕ → ℝ),
  (∀ (n : ℕ), a (n + 2) = 2 * a (n + 1) - a n) ↔ ∃ c₁ c₂, ∀ (n : ℕ), a n = c₁ + c₂ * ↑n
The certificate: 1 checked step
  1. Closed form of every solution

    ∀ (a : ℕ → ℝ),
      (∀ (n : ℕ), a (n + 2) = 2 * a (n + 1) - a n) ↔ ∃ c₁ c₂, ∀ (n : ℕ), a n = c₁ + c₂ * ↑n

    Checked by Lean’s kernel


A polynomial right side, by undetermined coefficients:

In[7]:=
#cas [rsolve a n, a 0 = 0, a 1 = 0] (a (n + 2) - 2 * a (n + 1) + a n = 1)
Out[7]=

the sequence with these initial values

a(n)=12n2−12n
a n = 1/2*n^2 - 1/2*n
Domain
a : ℕ → ℝ
Input (recurrence with initial values)
a (n + 2) - 2 * a (n + 1) + a n = 1, a 0 = 0, a 1 = 0

Checked by Lean’s kernel: A sequence has the recurrence and the initial values exactly when it is the closed form

∀ (a : ℕ → ℝ),
  (∀ (n : ℕ), a (n + 2) - 2 * a (n + 1) + a n = 1) ∧ a 0 = 0 ∧ a 1 = 0 ↔
    ∀ (n : ℕ), a n = 1 / 2 * ↑n ^ 2 - 1 / 2 * ↑n
The certificate: 1 checked step
  1. A sequence has the recurrence and the initial values exactly when it is the closed form

    ∀ (a : ℕ → ℝ),
      (∀ (n : ℕ), a (n + 2) - 2 * a (n + 1) + a n = 1) ∧ a 0 = 0 ∧ a 1 = 0 ↔
        ∀ (n : ℕ), a n = 1 / 2 * ↑n ^ 2 - 1 / 2 * ↑n

    Checked by Lean’s kernel

In[8]:=
#cas [rsolve a n, a 0 = 1] (a (n + 1) = a n + n)
Out[8]=

the sequence with these initial values

a(n)=−12n+12n2+1
a n = -(1/2*n) + 1/2*n^2 + 1
Domain
a : ℕ → ℝ
Input (recurrence with initial values)
a (n + 1) = a n + n, a 0 = 1

Checked by Lean’s kernel: A sequence has the recurrence and the initial values exactly when it is the closed form

∀ (a : ℕ → ℝ),
  (∀ (n : ℕ), a (n + 1) = a n + ↑n) ∧ a 0 = 1 ↔ ∀ (n : ℕ), a n = -(1 / 2 * ↑n) + 1 / 2 * ↑n ^ 2 + 1
The certificate: 1 checked step
  1. A sequence has the recurrence and the initial values exactly when it is the closed form

    ∀ (a : ℕ → ℝ),
      (∀ (n : ℕ), a (n + 1) = a n + ↑n) ∧ a 0 = 1 ↔ ∀ (n : ℕ), a n = -(1 / 2 * ↑n) + 1 / 2 * ↑n ^ 2 + 1

    Checked by Lean’s kernel


The initial values may sit at any two consecutive indices:

In[9]:=
#cas [rsolve a n, a 1 = 1, a 2 = 1] (a (n + 2) = a (n + 1) + a n)
Out[9]=

the sequence with these initial values

a(n)=(1+52)n−(1−52)n5
a n = (((1 + sqrt(5))/2)^n - ((1 - sqrt(5))/2)^n)/sqrt(5)
Domain
a : ℕ → ℝ
Input (recurrence with initial values)
a (n + 2) = a (n + 1) + a n, a 1 = 1, a 2 = 1

Checked by Lean’s kernel: A sequence has the recurrence and the initial values exactly when it is the closed form

∀ (a : ℕ → ℝ),
  (∀ (n : ℕ), a (n + 2) = a (n + 1) + a n) ∧ a 1 = 1 ∧ a 2 = 1 ↔
    ∀ (n : ℕ), a n = (((1 + √5) / 2) ^ n - ((1 - √5) / 2) ^ n) / √5
The certificate: 1 checked step
  1. A sequence has the recurrence and the initial values exactly when it is the closed form

    ∀ (a : ℕ → ℝ),
      (∀ (n : ℕ), a (n + 2) = a (n + 1) + a n) ∧ a 1 = 1 ∧ a 2 = 1 ↔
        ∀ (n : ℕ), a n = (((1 + √5) / 2) ^ n - ((1 - √5) / 2) ^ n) / √5

    Checked by Lean’s kernel


The complex characteristic roots ±i, in real form:

In[10]:=
#cas [rsolve a n, a 0 = 1, a 1 = 0] (a (n + 2) = - a n)
Out[10]=

the sequence with these initial values

a n = re(i^n)
Domain
a : ℕ → ℝ
Input (recurrence with initial values)
a (n + 2) = - a n, a 0 = 1, a 1 = 0

Checked by Lean’s kernel: A sequence has the recurrence and the initial values exactly when it is the closed form

∀ (a : ℕ → ℝ),
  (∀ (n : ℕ), a (n + 2) = -a n) ∧ a 0 = 1 ∧ a 1 = 0 ↔ ∀ (n : ℕ), a n = (Complex.I ^ n).re
The certificate: 1 checked step
  1. A sequence has the recurrence and the initial values exactly when it is the closed form

    ∀ (a : ℕ → ℝ),
      (∀ (n : ℕ), a (n + 2) = -a n) ∧ a 0 = 1 ∧ a 1 = 0 ↔ ∀ (n : ℕ), a n = (Complex.I ^ n).re

    Checked by Lean’s kernel


A cubic with one real root and a pair of complex roots, known by enclosures and named r₁ and z₁:

In[11]:=
#cas [rsolve a n] (a (n + 3) = a (n + 1) + a n)
Out[11]=

general solution

a n = c₁*r₁^n + c₂*re(z₁^n) + c₃*im(z₁^n)
Domain
a : ℕ → ℝ
Input (recurrence)
a (n + 3) = a (n + 1) + a n

Checked by Lean’s kernel: Closed form of every solution

let r₁ := CAS.AlgRoot.real [-1, -1, 0, 1] 1.32471795 1.32471797;
let z₁ := CAS.AlgRoot.complex [-1, -1, 0, 1] (-0.66235898) 0.56227951 2e-8;
(r₁ ∈ Set.Ioo 1.32471795 1.32471797 ∧ r₁ ^ 3 - r₁ - 1 = 0) ∧
  (z₁.re ∈ Set.Icc (-0.66235900) (-0.66235896) ∧ z₁.im ∈ Set.Icc 0.56227949 0.56227953 ∧ z₁ ^ 3 - z₁ - 1 = 0) ∧
    ∀ (a : ℕ → ℝ),
      (∀ (n : ℕ), a (n + 3) = a (n + 1) + a n) ↔
        ∃ c₁ c₂ c₃, ∀ (n : ℕ), a n = c₁ * r₁ ^ n + c₂ * (z₁ ^ n).re + c₃ * (z₁ ^ n).im
The certificate: 1 checked step
  1. Closed form of every solution

    let r₁ := CAS.AlgRoot.real [-1, -1, 0, 1] 1.32471795 1.32471797;
    let z₁ := CAS.AlgRoot.complex [-1, -1, 0, 1] (-0.66235898) 0.56227951 2e-8;
    (r₁ ∈ Set.Ioo 1.32471795 1.32471797 ∧ r₁ ^ 3 - r₁ - 1 = 0) ∧
      (z₁.re ∈ Set.Icc (-0.66235900) (-0.66235896) ∧ z₁.im ∈ Set.Icc 0.56227949 0.56227953 ∧ z₁ ^ 3 - z₁ - 1 = 0) ∧
        ∀ (a : ℕ → ℝ),
          (∀ (n : ℕ), a (n + 3) = a (n + 1) + a n) ↔
            ∃ c₁ c₂ c₃, ∀ (n : ℕ), a n = c₁ * r₁ ^ n + c₂ * (z₁ ^ n).re + c₃ * (z₁ ^ n).im

    Checked by Lean’s kernel


The quartic r4−5r2+6 is not split, and its four real roots are enclosed:

In[12]:=
#cas [rsolve a n] (a (n + 4) = 5 * a (n + 2) - 6 * a n)
Out[12]=

general solution

a(n)=c1r1n+c2r2n+c3r3n+c4r4n
a n = c₁*r₁^n + c₂*r₂^n + c₃*r₃^n + c₄*r₄^n
Domain
a : ℕ → ℝ
Input (recurrence)
a (n + 4) = 5 * a (n + 2) - 6 * a n

Checked by Lean’s kernel: Closed form of every solution

let r₁ := CAS.AlgRoot.real [6, 0, -5, 0, 1] (-1.73205082) (-1.73205080);
let r₂ := CAS.AlgRoot.real [6, 0, -5, 0, 1] (-1.41421357) (-1.41421355);
let r₃ := CAS.AlgRoot.real [6, 0, -5, 0, 1] 1.41421355 1.41421357;
let r₄ := CAS.AlgRoot.real [6, 0, -5, 0, 1] 1.73205080 1.73205082;
(r₁ ∈ Set.Ioo (-1.73205082) (-1.73205080) ∧ r₁ ^ 4 - 5 * r₁ ^ 2 + 6 = 0) ∧
  (r₂ ∈ Set.Ioo (-1.41421357) (-1.41421355) ∧ r₂ ^ 4 - 5 * r₂ ^ 2 + 6 = 0) ∧
    (r₃ ∈ Set.Ioo 1.41421355 1.41421357 ∧ r₃ ^ 4 - 5 * r₃ ^ 2 + 6 = 0) ∧
      (r₄ ∈ Set.Ioo 1.73205080 1.73205082 ∧ r₄ ^ 4 - 5 * r₄ ^ 2 + 6 = 0) ∧
        ∀ (a : ℕ → ℝ),
          (∀ (n : ℕ), a (n + 4) = 5 * a (n + 2) - 6 * a n) ↔
            ∃ c₁ c₂ c₃ c₄, ∀ (n : ℕ), a n = c₁ * r₁ ^ n + c₂ * r₂ ^ n + c₃ * r₃ ^ n + c₄ * r₄ ^ n
The certificate: 1 checked step
  1. Closed form of every solution

    let r₁ := CAS.AlgRoot.real [6, 0, -5, 0, 1] (-1.73205082) (-1.73205080);
    let r₂ := CAS.AlgRoot.real [6, 0, -5, 0, 1] (-1.41421357) (-1.41421355);
    let r₃ := CAS.AlgRoot.real [6, 0, -5, 0, 1] 1.41421355 1.41421357;
    let r₄ := CAS.AlgRoot.real [6, 0, -5, 0, 1] 1.73205080 1.73205082;
    (r₁ ∈ Set.Ioo (-1.73205082) (-1.73205080) ∧ r₁ ^ 4 - 5 * r₁ ^ 2 + 6 = 0) ∧
      (r₂ ∈ Set.Ioo (-1.41421357) (-1.41421355) ∧ r₂ ^ 4 - 5 * r₂ ^ 2 + 6 = 0) ∧
        (r₃ ∈ Set.Ioo 1.41421355 1.41421357 ∧ r₃ ^ 4 - 5 * r₃ ^ 2 + 6 = 0) ∧
          (r₄ ∈ Set.Ioo 1.73205080 1.73205082 ∧ r₄ ^ 4 - 5 * r₄ ^ 2 + 6 = 0) ∧
            ∀ (a : ℕ → ℝ),
              (∀ (n : ℕ), a (n + 4) = 5 * a (n + 2) - 6 * a n) ↔
                ∃ c₁ c₂ c₃ c₄, ∀ (n : ℕ), a n = c₁ * r₁ ^ n + c₂ * r₂ ^ n + c₃ * r₃ ^ n + c₄ * r₄ ^ n

    Checked by Lean’s kernel

Applications (1)

The closed form in a proof, by induction from the recurrence. Only the three standard axioms are used:

In[13]:=
theorem rsolve_closed_form (a : ℕ → ℝ) (h : ∀ n, a (n + 1) = 2 * a n + 1) (h₀ : a 0 = 1) :
    ∀ n, a n = -1 + 2 * 2 ^ n := by
  intro n
  induction n with
  | zero =>
    rw [h₀]
    norm_num
  | succ n ih =>
    rw [h, ih]
    ring

#print axioms rsolve_closed_form
Out[13]=

rsolve_closed_form depends on the axioms propext, Classical.choice, Quot.sound.

Properties and Relations (1)

Binet’s formula at n=20 is 6765, the value of the call fibonacci:

In[14]:=
#cas (fibonacci 20)
Out[14]=

fibonacci

6765
Domain
ℕ
Input (natural numbers)
20

Checked by Lean’s kernel: fibonacci

Nat.fib 20 = 6765
The certificate: 1 checked step
  1. fibonacci

    Nat.fib 20 = 6765

    Checked by Lean’s kernel

Possible Issues (7)

The coefficients must be constants. Here the coefficient of a n is n:

In[15]:=
#cas [rsolve a n] (a (n + 1) = n * a n)
Out[15]=

Error

rsolve: recurrences with coefficients that depend on n are not treated (the coefficient of a n is n)

When the coefficient of a n is zero, the recurrence is one of lower order for a (n + 1):

In[16]:=
#cas [rsolve a n] (a (n + 2) = a (n + 1))
Out[16]=

Error

rsolve: the coefficient of a n is zero; this is a recurrence of lower order for a (n + 1)

The recurrence must be linear in the sequence:

In[17]:=
#cas [rsolve a n] (a (n + 1) = a n * a n)
Out[17]=

Error

rsolve: the recurrence must be linear in a

A recurrence of order 2 takes two initial values:

In[18]:=
#cas [rsolve a n, a 0 = 1] (a (n + 2) = a (n + 1) + a n)
Out[18]=

Error

rsolve: give the 2 initial values a k, …, a (k + 1) at consecutive indices

The right side may contain polynomial and exponential terms in n only:

In[19]:=
#cas [rsolve a n] (a (n + 1) = a n + sin n)
Out[19]=

Error

rsolve: the terms in n must be sums of c n^j r^n

The first name in the brackets is the sequence, and the message says how to fix a mismatch:

In[20]:=
#cas [rsolve a n] (b (n + 1) = 2 * b n)
Out[20]=

Error

rsolve: the equation is about the sequence b, but the mode names a; write #cas [rsolve b n]

The sequence is written at n and at n + k, not at n - k. Shift the recurrence, here to a (n + 2) = a (n + 1) + a n:

In[21]:=
#cas [rsolve a n] (a n = a (n - 1) + a (n - 2))
Out[21]=

Error

rsolve: expected n or n + k

Neat Examples (1)

The Padovan numbers. Their characteristic polynomial r3−r−1 has the plastic number as its real root, here r₁:

In[22]:=
#cas [rsolve a n, a 0 = 1, a 1 = 1, a 2 = 1] (a (n + 3) = a (n + 1) + a n)
Out[22]=

the sequence with these initial values

a n = (7/23*r₁^2 + 1/23*r₁ + 3/23)*r₁^n + 2*re((7/23*z₁^2 + 1/23*z₁ + 3/23)*z₁^n)
Domain
a : ℕ → ℝ
Input (recurrence with initial values)
a (n + 3) = a (n + 1) + a n, a 0 = 1, a 1 = 1, a 2 = 1

Checked by Lean’s kernel: A sequence has the recurrence and the initial values exactly when it is the closed form

let r₁ := CAS.AlgRoot.real [-1, -1, 0, 1] 1.32471795 1.32471797;
let z₁ := CAS.AlgRoot.complex [-1, -1, 0, 1] (-0.66235898) 0.56227951 2e-8;
(r₁ ∈ Set.Ioo 1.32471795 1.32471797 ∧ r₁ ^ 3 - r₁ - 1 = 0) ∧
  (z₁.re ∈ Set.Icc (-0.66235900) (-0.66235896) ∧ z₁.im ∈ Set.Icc 0.56227949 0.56227953 ∧ z₁ ^ 3 - z₁ - 1 = 0) ∧
    ∀ (a : ℕ → ℝ),
      (∀ (n : ℕ), a (n + 3) = a (n + 1) + a n) ∧ a 0 = 1 ∧ a 1 = 1 ∧ a 2 = 1 ↔
        ∀ (n : ℕ),
          a n =
            (7 / 23 * r₁ ^ 2 + 1 / 23 * r₁ + 3 / 23) * r₁ ^ n +
              2 * ((7 / 23 * z₁ ^ 2 + 1 / 23 * z₁ + 3 / 23) * z₁ ^ n).re
The certificate: 1 checked step
  1. A sequence has the recurrence and the initial values exactly when it is the closed form

    let r₁ := CAS.AlgRoot.real [-1, -1, 0, 1] 1.32471795 1.32471797;
    let z₁ := CAS.AlgRoot.complex [-1, -1, 0, 1] (-0.66235898) 0.56227951 2e-8;
    (r₁ ∈ Set.Ioo 1.32471795 1.32471797 ∧ r₁ ^ 3 - r₁ - 1 = 0) ∧
      (z₁.re ∈ Set.Icc (-0.66235900) (-0.66235896) ∧ z₁.im ∈ Set.Icc 0.56227949 0.56227953 ∧ z₁ ^ 3 - z₁ - 1 = 0) ∧
        ∀ (a : ℕ → ℝ),
          (∀ (n : ℕ), a (n + 3) = a (n + 1) + a n) ∧ a 0 = 1 ∧ a 1 = 1 ∧ a 2 = 1 ↔
            ∀ (n : ℕ),
              a n =
                (7 / 23 * r₁ ^ 2 + 1 / 23 * r₁ + 3 / 23) * r₁ ^ n +
                  2 * ((7 / 23 * z₁ ^ 2 + 1 / 23 * z₁ + 3 / 23) * z₁ ^ n).re

    Checked by Lean’s kernel

See Also

dsolve · sum · product · fibonacci · roots