The Problem:
I need only the bottom left element of a product of matrices $(\bf{M_1}+\bf{I})(\bf{M_2}+\bf{I})\cdots(\bf{M_N}+\bf{I})$,
where $\bf{I}=\begin{pmatrix}
1 & 0\\
0 & 1\end{pmatrix}$, and $\require{cancel}
\bf{M_i}=
\begin{cases}
\begin{pmatrix}
0 & x_i\\
0 & 0\end{pmatrix} &i\equiv N\pmod{2}\\
\begin{pmatrix}
0 & 0\\
x_i & 0\end{pmatrix} &i\bcancel{\equiv} N\pmod{2}
\end{cases}$.
My attempt so far:
I realized that when you multiply single-element matrices, their product is a matrix with a single element (the product of the matrices' elements) where the first matrix sets the row, and the last matrix sets the column. Update: or a 0 matrix
For example, $\begin{pmatrix} 0 & a\\ 0 & 0\end{pmatrix}\begin{pmatrix} 0 & 0\\ b & 0\end{pmatrix}\begin{pmatrix} 0 & c\\ 0 & 0\end{pmatrix}\begin{pmatrix} 0 & 0\\ d & 0\end{pmatrix}=\begin{pmatrix} abcd & 0\\ 0 & 0\end{pmatrix}$.
Since I only need the bottom left element, I can delete all terms from the expansion of $(\bf{M_1}+\bf{I})(\bf{M_2}+\bf{I})\cdots(\bf{M_N}+\bf{I})$ that begin or end with $\bf{M_i}$ where $i$ has the same parity as $N$, since those will only contribute to the top row and right column. Also, I know the final bottom left element will be the sum of the bottom left elements in each matrix term, so it will be $(x_1 + 1)(x_2+1)\cdots(x_N+1) - 1$ minus all terms that begin or end with $x_i$ where $i$ has the same parity as $N$. Update: minus all terms containing x_ix_j where i,j have the same parity
Is there a way to rewrite $\prod_{i=1}^N(x_i+1)=(x_1 + 1)(x_2+1)\cdots(x_N+1)$ so that it does not produce any terms that begin or end with $x_i$ where $i$ has the same parity as $N$?
Or more generally: I know we can pull out the bottom left element of a 2x2 product of matrices by multiplying it on the left with $\begin{pmatrix}0&1\end{pmatrix}$ and on the right with $\begin{pmatrix}1\\0\end{pmatrix}$. Is there a way to pull out the bottom left element without intermediately calculating all elements?
Motivation for this problem:
I realized the Euclidean algorithm can be written as a matrix multiplication. We can solve the Diophantine equation $a_0n + a_1m = 1$, where coefficients $a_0$ and $a_1$ are positive and coprime and $a_0>a_1$, by writing the above matrix multiplication, where $a_i = a_{i-2}\%a_{i-1}$ until we find $a_N=1$, and where $x_i = -\lfloor\frac{a_{i-1}}{a_i}\rfloor$. The left column of the matrix will give solutions for $n$ and $m$, and the right column of the matrix will give $a_0$ and $a_1$.
The resultant matrix will be
$\bf{E}=\begin{cases}
\begin{pmatrix}
r_n & -a_1\\
r_m & a_0\end{pmatrix} &N\text{ is even}\\
\begin{pmatrix}
r_m & -a_0\\
r_n & a_1\end{pmatrix} &N\text{ is odd}
\end{cases}$,
and we can write our general solution as
$\begin{pmatrix}n\\m\end{pmatrix}=\begin{pmatrix}a_1k+r_n\\a_0(-k)+r_m\end{pmatrix}$, where $k$ is any integer.
Examples:
For example, $13n + 5m = 1$. Here, $a_i = \{13,5,3,2,1\}$, so $N=4$, and $x_i = \{-2, -1, -1, -2\}$. Then we find
$\begin{pmatrix} 1 & 0\\ -2 & 1\end{pmatrix} \begin{pmatrix} 1 & -1\\ 0 & 1\end{pmatrix} \begin{pmatrix} 1 & 0\\ -1 & 1\end{pmatrix} \begin{pmatrix} 1 & -2\\ 0 & 1\end{pmatrix} =\begin{pmatrix} 2 & -5\\ -5 & 13\end{pmatrix}$, so $\begin{pmatrix}n\\m\end{pmatrix}=\begin{pmatrix}5k + 2\\-13k - 5\end{pmatrix}$
For another example, $13n + 7m = 1$. Here, $a_i = \{13,7,6,1\}$, so $N=3$, and $x_i = \{-1, -1, -6\}$. Then we find
$\begin{pmatrix} 1 & -1\\ 0 & 1\end{pmatrix} \begin{pmatrix} 1 & 0\\ -1 & 1\end{pmatrix} \begin{pmatrix} 1 & -6\\ 0 & 1\end{pmatrix} =\begin{pmatrix} 2 & -13\\ -1 & 7\end{pmatrix}$, so $\begin{pmatrix}n\\m\end{pmatrix}=\begin{pmatrix}7k - 1\\-13k + 2\end{pmatrix}$
Motivation for this problem, part II:
I noticed that if I get $r_n$ or $r_m$, I can easily plug it into the Diophantine equation to find the other, so I only need one of them, and settled on just finding the bottom left element of $\bf{E}$.
Motivation for this problem, part III:
I'm actually trying to solve the Diophantine equation $2^nx_n + 3^A(-x_0) = 1$, which arises when I want to determine an $x_0$ that follows a given parity sequence of length $n$ with $A$ odds when recursively applying the shortcut Collatz algorithm $x_{i+1} = C(x_i) = \begin{cases}\frac{3x_i+1}{2}, &x_i\text{ odd}\\\frac{x_i}{2}, &x_i\text{ even}\end{cases}$. I've found $x_0 = 2^nm - 3^{2^{n-1}-A}\%2^n$, where $m$ is any integer, with Euler's totient function, but $3^{2^{n-1}-A}$ is astronomically large, so it's not a convenient stepping stone for finding $r_{-x_0}$. So I went back to the matrix multiplication approach, which I felt had a lot of wasteful operations if we only needed to find one element of it. This brings us to the problem at hand.
Update:
I thought that $(x_1 + 1)(x_2+1)\cdots(x_N+1)$ should be the sum of the elements of the matrix, which is $r_n + r_m + (2\cdot N\%2-1)(a_1-a_0)$. Then $r_n$ and $r_m$ also satisfy the Diophantine equation, so we could solve the system of equations for $r_n$. But I tried it with our examples, and it's not correct. For $13n + 5m = 1$, we get
$\prod_{i=1}^N(x_i+1)=0\neq2-5-5+13$. For $13n+7m=1$, we get $\prod_{i=1}^N(x_i+1)=0\neq2-13-1+7$.
I suspect this means my assertion that "the bottom-left element of $\bf{E}$ is $(x_1 + 1)(x_2 + 1)\cdots(x_N+1) - 1$ minus all terms that begin or end with $x_i$ where $i$ has the same parity as $N$" is wrong too. I may have missed something that happens when the matrices multiply and add. What did I miss?
(I can see the $\bf{I}$ added at the end of the expansion of $\prod_{i=1}^N(\bf{M_i}+\bf{I})$ would add 2 to the total sum of elements, not 1 as $\prod_{i=1}^N(x_i+1)$ would predict, but what else?)
Update: Pranay pointed out M_iM_j with i,j same parity would give 0 for each element, so terms having x_ix_j with i,j same parity should not be in the sum
{\bf M}, as the effect of \bf ends when the grouping it is in ends, or else you can use\mathbf Mas \mathbf only affects the first token after it. – Paul Sinclair Dec 10 '24 at 17:56