The question
Take sequences $a_1, \dots, a_N$ that feed into one another,
$$a_i(n) = \alpha_{i1}a_1(n-1) + \alpha_{i2}a_2(n-1) + \cdots + \alpha_{iN}a_N(n-1),$$with the values $a_i(1)$ given. Fix a linear combination $a(n) = k_1a_{i_1}(n) + \cdots + k_ma_{i_m}(n)$. Kagey asks for the smallest order of a linear recurrence that $a$ satisfies. Two related questions come with it: how that order depends on the initial conditions, and what changes when each $a_i$ is allowed to depend on several earlier terms rather than one.
His example has $N = 7$:
$$\begin{aligned} a_1(n) &= a_1 + a_2 + a_4 + 2a_5 + a_7, &\qquad a_2(n) &= a_4 + a_5 + a_6,\\ a_3(n) &= a_2 + a_3 + a_5, &\qquad a_4(n) &= a_2 + a_3 + a_5,\\ a_5(n) &= a_1 + a_2 + a_4 + a_5, &\qquad a_6(n) &= a_4 + a_5 + a_6,\\ a_7(n) &= a_5 + a_7, \end{aligned}$$with every right-hand side evaluated at $n-1$, and $a_1(1) = a_7(1) = 1$ with the rest zero. Then $a_5 + a_7$ runs $1, 2, 5, 15, 50, 175, 625, 2250, \dots$, which counts the subgraphs of the $2 \times n$ grid graph in which no vertex has degree $1$, and it satisfies
$$a(n) = 5a(n-1) - 5a(n-2)$$for $n > 2$. Cayley–Hamilton hands over a recurrence of order $7$ at no cost. Order $2$ is what needs an explanation.
The question has a complete answer, and the answer is classical. None of the mathematics below is new. It is Kronecker's 1881 theorem on Hankel matrices of rational power series, which in state-space language is the minimal realization theorem of Kalman and of Ho and Kalman, with Berlekamp–Massey as the algorithm that recovers the recurrence from the terms. The same facts sit in the theory of linear recurrence sequences and in the transfer-matrix method. The note collects them with proofs, in the order Kagey's three questions ask for them.
The least recurrence
In matrix form the system is $a(n) = c^{\mathsf T}A^{n-1}v$, with $A = [\alpha_{ij}]$, the initial values in $v$ and the coefficients $k_i$ in $c$. Write $s(k) = c^{\mathsf T}A^kv$, so that $a(n) = s(n-1)$. This is the impulse response of a discrete linear system with one input and one output, and the question is the minimal realization problem.
One distinction has to be made first. Kagey's recurrence is stated for $n > 2$, and when $A$ is singular a recurrence valid only for large $n$ can have strictly lower order than any recurrence valid from the first term. Let $\mathcal{I}$ be the set of polynomials $f$ with $\sum_kf_ks(n+k) = 0$ for every $n \ge 0$, and let $\mathcal{I}_\infty$ be the set where this holds for all large $n$. Since $\sum_kf_ks(n+k) = c^{\mathsf T}A^nf(A)v$, both are ideals of $\mathbb{F}[x]$, and both contain the characteristic polynomial of $A$. Let $\mu$ and $\mu_\infty$ be their monic generators and write $\mu = x^eg$ with $g(0) \ne 0$. Then $\mu_\infty = g$, and $g$ annihilates the sequence from index $e$ on, and when $e \ge 1$ not from $e-1$ on. We call $\deg\mu$ the order and $\deg\mu_\infty$ the eventual order. The two agree when $A$ is invertible.
Two subspaces carry the answer:
$$\mathcal{K} = \operatorname{span}\{A^kv : k \ge 0\}, \qquad \mathcal{O} = \{u : c^{\mathsf T}A^ku = 0 \text{ for all } k \ge 0\}.$$$\mathcal{K}$ is what the initial vector reaches and $\mathcal{O}$ is what the combination cannot see. Both are $A$-invariant. Write $H_M = [s(i+j)]_{i,j=0}^{M-1}$ for the Hankel matrix of the sequence.
Let $W = \mathcal{K}/(\mathcal{K} \cap \mathcal{O})$ and let $\bar A$ be the map induced by $A$ on $W$. Then $\mu$ is the minimal polynomial of $\bar A$, which is also its characteristic polynomial, and
$$\deg\mu = \dim\mathcal{K} - \dim(\mathcal{K} \cap \mathcal{O}) = \operatorname{rank}H_M$$for every $M \ge \deg\mu$, in particular for $M = N$.
A polynomial $f$ lies in $\mathcal{I}$ exactly when $f(A)v \in \mathcal{O}$, which says $f(\bar A)\bar v = 0$ in $W$. The vectors $\bar A^k\bar v$ span $W$ and $f(\bar A)$ commutes with $\bar A$, so that is the same as $f(\bar A) = 0$. Hence $\mathcal{I}$ is the annihilator ideal of $\bar A$, and with $d = \deg\mu$ the vectors $\bar v, \bar A\bar v, \dots, \bar A^{d-1}\bar v$ are a basis of $W$. For the rank, $c^{\mathsf T}$ vanishes on $\mathcal{O}$ and so induces $\bar c$ on $W$, giving $s(i+j) = \bar c\,\bar A^i\bar A^j\bar v$. That factors $H_M$ through $W$ as $\Psi_M\Phi_M$, with $\Phi_M$ onto and $\Psi_M$ injective once $M \ge d$.
Three consequences are what one actually uses.
- $\mu$ divides the minimal polynomial $m_A$ of $A$, so $m_A$ may replace the characteristic polynomial in Kagey's own bound, and the order is at most $\deg m_A \le N$.
- The terms $a(1), \dots, a(2N)$ determine $\mu$. Take $d = \operatorname{rank}H_N$ and solve $H_d\gamma = (s(d), \dots, s(2d-1))^{\mathsf T}$, which has a unique solution because $H_d$ is invertible. Berlekamp–Massey does the same in $O(N^2)$ operations.
- A monic $f$ of degree $m$ that annihilates the sequence on the windows $0 \le n \le N-1$ annihilates it on all of them. So a guessed recurrence of order $m$ checked on $N + m$ terms holds forever. This is the certificate that turns a conjectured recurrence into a theorem.
There is a generating function form. $S(t) = \sum_{k \ge 0}s(k)t^k = c^{\mathsf T}(I - tA)^{-1}v$ is rational. Suppose $S \ne 0$ and write $S = P/Q$ in lowest terms with $Q(0) = 1$. Then the order is $d = \max(\deg Q, \deg P + 1)$, the minimal polynomial is $x^dQ(1/x)$, and the transient length is $e = \max(0, \deg P + 1 - \deg Q)$.
Kagey's example
Here $v = e_1 + e_7$ and $c = e_5 + e_7$. The system as printed does what the problem says. The sequence is A093129 with the index shifted by one, and $a(n) = 5a(n-1) - 5a(n-2)$ holds for every $n \ge 3$. So $\mu = x^2 - 5x + 5$, the restriction to $n > 2$ only reflects the need for two earlier terms, and there is no transient. No first-order recurrence holds, because $a(1)a(3) \ne a(2)^2$.
The characteristic polynomial of $A$ is $x^5(x^2 - 5x + 5)$ and its minimal polynomial is $x^2(x^2 - 5x + 5)$. The rank of $A$ is $4$. Rows $2$ and $6$ coincide, rows $3$ and $4$ coincide, and row $1$ is the sum of rows $5$ and $7$. The last relation says $a_1(n) = a_5(n) + a_7(n)$ for $n \ge 2$, and it holds at $n = 1$ too, so Kagey's sequence is $a_1$. The initial vector lies in
$$U = \{x \in \mathbb{Q}^7 : x_1 = x_5 + x_7,\ x_2 = x_3 = x_4 = x_6\},$$which is $A$-invariant and three-dimensional. In the coordinates $(x_2, x_5, x_7)$ on $U$ the matrix acts as
$$M = \begin{pmatrix} 2 & 1 & 0\\ 2 & 2 & 1\\ 0 & 1 & 1\end{pmatrix}, \qquad \det(xI - M) = x(x^2 - 5x + 5).$$The vectors $v, Av, A^2v$ are independent and $A^3v = 5A^2v - 5Av$, so $\mathcal{K} = U$. The vector
$$w = (A^2 - 5A + 5I)v = (0, 1, 1, 1, -2, 1, 2)$$spans $\ker A \cap \mathcal{K}$, and it is the whole of the transient.
Let $c \ne 0$ have nonnegative entries. Then $\mu = x^2 - 5x + 5$ if $c^{\mathsf T}w = 0$, and $\mu = x(x^2 - 5x + 5)$ otherwise. In the second case $a(n) = 5a(n-1) - 5a(n-2)$ holds for $n \ge 4$ and fails at $n = 3$.
Write $q = x^2 - 5x + 5$. Since $Aq(A)v = 0$, $\mu$ divides $xq$, and $q$ is irreducible over $\mathbb{Q}$. All entries of $A^2v = (5,1,1,1,3,1,2)$ are positive and $A$ is nonnegative with no zero row, so $s(k) > 0$ for $k \ge 2$ and $\mu$ is neither $1$ nor $x$. What is left is that $\mu = q$ exactly when $w = q(A)v$ lies in $\mathcal{O}$, and since $Aw = 0$ that is exactly $c^{\mathsf T}w = 0$.
So the fall from $7$ to $2$ happens in three steps, each with its own cause. The eigenvalue $0$ has several Jordan blocks, which bounds the order by $\deg m_A = 4$ for every $c$ and every $v$. The initial vector lies in $U$, which brings it to $3$. The combination $a_5 + a_7$ is blind to the remaining direction $w$, which brings it to $2$.
For subset sums $c = \sum_{i \in S}e_i$ the condition $c^{\mathsf T}w = 0$ reads
$$|S \cap \{2,3,4,6\}| + 2[7 \in S] - 2[5 \in S] = 0,$$with no condition on the index $1$. The solutions are $S \setminus \{1\} = \emptyset$, or $\{5,7\}$, or $\{5\}$ together with two of $2,3,4,6$, which is $2 \cdot 8 - 1 = 15$ nonempty sets. So $15$ of the $127$ subset sums have order $2$ and the other $112$ have order $3$ and eventual order $2$. Among the seven single sequences only $a_1$ has order $2$. The sequence $a_7$ runs $1, 1, 2, 5, 15, 50, \dots$ and satisfies the recurrence from $n = 4$ on but not at $n = 3$, with minimal polynomial $x^3 - 5x^2 + 5x$.
Initial conditions, higher order
The dependence on the initial vector is exact. Enlarging the field does not change $\mu$, so we may assume $\mathbb{F}$ contains the eigenvalues of $A$, and we write $v = \sum_\lambda v_\lambda$ for the decomposition into generalized eigenspaces.
$\mu = \prod_\lambda(x - \lambda)^{e_\lambda}$, where $e_\lambda = 1 + \max\{j \ge 0 : c^{\mathsf T}(A - \lambda I)^jv_\lambda \ne 0\}$, and $e_\lambda = 0$ when there is no such $j$.
So $\lambda$ is absent from the recurrence exactly when $c^{\mathsf T}(A - \lambda I)^jv_\lambda = 0$ for every $j$, each $e_\lambda$ is at most the size of the largest Jordan block of $\lambda$, and the eventual recurrence starts at index $e_0$. In characteristic zero this is the classical expansion $a(n) = \sum_{\lambda \ne 0}p_\lambda(n)\lambda^n$ for $n > e_0$, with $\deg p_\lambda = e_\lambda - 1$.
The generic picture is as clean. Let $m_c$ be the minimal polynomial of $A$ on $V/\mathcal{O}$, of degree the rank of the observability matrix, and $m^v$ that of $A$ on $\mathcal{K}$, of degree $\dim\mathcal{K}$. For all $c$ and $v$, $\mu$ divides both, and both divide $m_A$. The set of pairs with $\deg\mu \le k$ is Zariski closed, being the vanishing of the $(k+1)$-minors of $H_N$, so the order is lower semicontinuous and special choices can only lower it. Over an infinite field, a generic $v$ gives $\mu = m_c$ for fixed $c$, a generic $c$ gives $\mu = m^v$ for fixed $v$, and a generic pair gives $\mu = m_A$.
In Kagey's system the observability matrix for $c = e_5 + e_7$ has rank $3$, so a generic initial vector gives order $3$ and Kagey's $v$ is special. A generic $c$ and $v$ give order $4$, and no choice gives more, although $N = 7$.
Systems of higher order reduce to the first-order case. Let $a_i(n) = \sum_j\sum_{r=1}^{k_j}\alpha_{i,j,r}a_j(n-r)$ for $n > k = \max_jk_j$, with the first $k$ values of each $a_j$ arbitrary, and put $D = k_1 + \cdots + k_t$. Stacking the states gives a $D \times D$ block companion matrix $B$ with $a(n) = c^{\mathsf T}B^{n-k}x_k$ for $n \ge k$. Everything above then applies with $N = D$, and the order is at most $D$. The minimal polynomial of the whole sequence from $n = 1$ and that of its tail from $n = k$ differ by a factor dividing $x^{k-1}$, and the eventual recurrence is the same. Over an infinite field the bound $D$ is attained for every choice of $k_1, \dots, k_t$, by taking the $a_j$ decoupled with coprime characteristic polynomials $(x - \lambda_j)^{k_j}$.
Wider strips
Problem 56 of the collection counts the subgraphs of the $\ell \times n$ grid graph in which no vertex has degree $1$, and Problem 83's example is the case $\ell = 2$. For one column let $L$ and $R$ be the sets of rows whose horizontal edge enters the column from the left and leaves it to the right, and let $T_\ell[R,L]$ count the subsets of the column's $\ell - 1$ vertical edges that leave no vertex of the column with degree $1$. A subgraph is the same thing as a compatible choice of these data for every column, so
$$a_\ell(n) = e_\emptyset^{\mathsf T}T_\ell^{\,n}e_\emptyset,$$a system with $N = 2^\ell$ states. The OEIS lists $\ell = 3, 4, 5$ as A301976, A320097 and A320099, each with a recurrence marked as a conjecture. Computing $\mu$ from the transfer matrix in exact rational arithmetic returns precisely those recurrences. Each therefore holds for every $n$ beyond its own order, which settles the conjecture, and no recurrence of lower order holds, even eventually.
| $\ell$ | states $2^\ell$ | $\deg m_{T}$ | $\dim\mathcal{K}$ | $\dim\mathcal{O}$ | order |
|---|---|---|---|---|---|
| $2$ | 4 | 3 | 3 | 2 | 2 |
| $3$ | 8 | 6 | 5 | 4 | 4 |
| $4$ | 16 | 12 | 7 | 10 | 6 |
| $5$ | 32 | 21 | 11 | 22 | 10 |
In each case the order is $\dim\mathcal{K} - 1$. The minimal polynomials are
$$\begin{aligned} \mu_2 &= x^2 - 5x + 5,\\ \mu_3 &= x^4 - 12x^3 + 6x^2 + 20x + 5,\\ \mu_4 &= x^6 - 36x^5 + 7x^4 + 201x^3 - 49x^2 - 20x + 5,\\ \mu_5 &= x^{10} - 103x^9 - 1063x^8 + 1873x^7 + 20274x^6 - 44071x^5\\ &\qquad {} + 10365x^4 + 20208x^3 - 5959x^2 - 2300x + 500. \end{aligned}$$Each has a nonzero constant term, so the eventual order equals the order. Prepending the empty grid, $a_\ell(0) = 1$, multiplies each by exactly one factor $x$.
The case $\ell = 3$ also settles the other conjecture recorded in A301976, that $a_3(n) \equiv 3 \pmod{10}$ for $n > 2$. Modulo $10$ the recurrence reads $a(n) \equiv 2a(n-1) - 6a(n-2) - 5a(n-4)$, the values $a_3(3), \dots, a_3(6) = 43, 463, 5193, 58653$ are all $\equiv 3$, and $2 \cdot 3 - 6 \cdot 3 - 5 \cdot 3 = -27 \equiv 3$.
What the table does not explain is the size of the drop. The reflection of the strip commutes with $T_\ell$ and fixes $e_\emptyset$, so $\mathcal{K}$ lies in the space of reflection-symmetric vectors, of dimension $3, 6, 10, 20$. That accounts for part of the fall, and for $\ell \ge 3$ the space $\mathcal{K}$ is smaller still. Predicting $\dim\mathcal{K}$ and $\dim\mathcal{O}$ for a transfer matrix of this kind without computing them is open, and it is a question of a different kind from Kagey's.
What was checked
The verification script works in exact rational arithmetic and uses only the Python standard library. It takes about thirty seconds.
- For each triple $(A, c, v)$ the minimal polynomial is computed four ways: as the least monic recurrence consistent with every window of $4N+4$ terms, by Berlekamp–Massey over $\mathbb{Q}$, as the first dependence of $v, Av, A^2v, \dots$ modulo $\mathcal{O}$, and from the reduced generating function by Faddeev–LeVerrier and a polynomial gcd. The four agreed in every case, with $\operatorname{rank}H_N = \operatorname{rank}H_{2N} = \operatorname{rank}H_d = d$ throughout.
- Kagey's system: every number in the worked example above, the criterion $c^{\mathsf T}w = 0$ on all $127$ subset sums, and the generic orders $3$, $3$ and $4$.
- Random systems: $400$ integer systems with $N \le 6$, of which $196$ have order below $N$ and $172$ have a factor $x$ in $\mu$. Then $200$ singular systems for the eventual recurrence, $200$ matrices with prescribed Jordan form for the exponent formula, $160$ systems for the generic statements, and $150$ higher-order systems with $t \le 3$ and $k_j \le 3$, of which $76$ fall below the bound $D$.
- Grids: the transfer-matrix values match the OEIS terms for $\ell = 2, 3, 4, 5$, and match direct enumeration of every edge subset for $(\ell, n)$ up to $(2,7)$, $(3,4)$, $(4,3)$ and $(5,2)$.
Nothing here was fitted to data. The theorems are classical and proved, and the predictions for Kagey's system and for the grids, including the counts $15$ and $112$, the generic orders, the orders $4, 6, 10$ and the extra factor $x$, were derived by hand and written into the ledger before the script was run on those cases. All were confirmed and none was refuted.