[Math] Is it possible to compute factorials by converting to matrix multiplications

factorialmatricesrecurrence-relations

An $n$-th term of the Fibonacci sequence can be computed by a nice trick by converting the recurrence relation in a matrix form. Then we compute $M^n$ in $O(\log n)$ steps using exponentiation by squaring.

Would it be possible to use such a trick to compute factorials? If not, can it be proved? I figured out how to compute any polynomial in $n$ using this approach, but for factorials I wasn't able to express the factorial's recurrence relation as a linear transformation.

Best Answer

The Fibonacci recurrence relation:

$$F_{n+1} = F_n + F_{n-1}$$

is linear. By that I mean it gives the next term as a linear combination of previous terms. Other recurrences having this feature are:

$$A_{n+1} = 3A_n + A_{n-1}$$ $$B_{n+1} = -4B_n$$ $$C_{n+1} = C_n + C_{n-1} + C_{n-2}$$

so any of those could be represented by matrices. Here they are!

$$ \begin{aligned} M_A &= \begin{bmatrix}3 & 1\\1& 0\end{bmatrix}\\ M_B &= \begin{bmatrix}-4\end{bmatrix} \end{aligned} $$

And the last one is a challenge to the reader.

The Fibonacci matrix

$$\begin{bmatrix}1&1\\0&1\end{bmatrix}$$

maps a vector

$$\begin{bmatrix}F_n\\F_{n-1}\end{bmatrix} \rightarrow \begin{bmatrix}F_{n+1}\\F_n\end{bmatrix}$$

and these work analogously.

But the factorial recurrence relation:

$$n! = n(n-1!)$$

is not a linear combination (with constant coefficients) of previous arguments, so we can't represent it as a matrix. That is, we can't represent it by the same matrix, no matter what $n$ we're trying to compute. When the coefficents are constant, we can, which lets us do exponentiation by squaring, etc.

Matrices are a convenient shorthand for representing linear functions on vectors. (They're not only a shorthand, but often I find it useful to think of them this way).

Related Question