10

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

  • Regarding what you missed: take $N=4$ for example. Then expanding the given product, the bottom left entry is nonzero in $M_1 M_2 M_3 + M_1 + M_3$. But, your wrong answer includes an additional term $M_1M_3$. The problem here is that $M_i M_j$ is a nonzero matrix if and only if $i$ and $j$ have opposite parity. Indeed $M_1 M_3$ is the zero matrix, so it shouldn’t contribute to the final answer. If you notice the correct expression has alternating odd-even structure in all the terms. – Pranay Dec 10 '24 at 03:38
  • 1
    I see! I did the mental multiplying wrong when I considered the different placements of the single elements. "when you multiply single-element 2x2 matrices, their product is a 2x2 matrix with a single element" or a 0 matrix. – WeCanDoItGuys Dec 10 '24 at 04:10
  • So, I'll need something like a sum of all forms of x1x2x3...xN with pairs of consecutive letters removed. I guess I have a new insight into David's answer from last time I looked into this (dxiv's answer gave me the matrix approach). – WeCanDoItGuys Dec 10 '24 at 04:57
  • Yep, that’s right. I don’t know if there’s a closed form answer but there’s certainly a recurrence relation for this. – Pranay Dec 10 '24 at 05:46
  • 1
    FYI on formatting: \bf affects all tokens following, not just the first, so in your first product, only the initial open-parenthesis is not in bold face. To affect only the first token after \bf you need to do either {\bf M}, as the effect of \bf ends when the grouping it is in ends, or else you can use \mathbf M as \mathbf only affects the first token after it. – Paul Sinclair Dec 10 '24 at 17:56

2 Answers2

2

Let $Q := \{1,\dots,N\}$ be the set of all indices, and for any $S \subseteq Q$, understand $\prod_{i \in S} \mathbf M_i$ to refer specifically to the product in increasing order of indices: ${\bf M}_{i_1}{\bf M}_{i_2}\cdots{\bf M}_{i_{|S|}}$ where $i_1 < i_2 < \cdots <i_{|S|}$ (with $\prod_{i\in\emptyset} \mathbf M_i = \bf I$).

Then by the distributive law, $$\prod_{i=1}^N\mathbf (M_i + \mathbf I) = \sum_{S\subseteq Q} \prod_{i \in S} \mathbf M_i$$

So we need to examine which of the $\prod_{i \in S} \mathbf M_i$ for various $S$ contribute to the lower left element.

Let

  • $A$ be the class of all matrices of the form $\begin{pmatrix}0&0\\x&0\end{pmatrix}$,
  • $B$ be the class of all matrices of the form $\begin{pmatrix}0&x\\0&0\end{pmatrix}$,
  • $C$ be the class of all matrices of the form $\begin{pmatrix}x&0\\0&0\end{pmatrix}$,
  • $D$ be the class of all matrices of the form $\begin{pmatrix}0&0\\0&x\end{pmatrix}$.

We see then that (where each letter represents an arbitrary element of its class):$$\begin{array}{cccc} AA = \mathbf 0 & AB = D & AC = A & AD = \mathbf 0\\ BA = C & BB = \mathbf 0 & BC = \mathbf 0 & BD = B\\ CA = \mathbf 0 & CB = B & CC = C & CD = \mathbf 0\\ DA = A & DB = \mathbf 0 & DC = \mathbf 0 & DD = D\end{array}$$

So in particular, any product of matrices of classes $A$ and $B$ will be zero if there are adjacent $A$s or adjacent $B$s anywhere in the product. Otherwise, the product will be non-zero, but will have a non-zero lower left element only if the first and last matrices in the product are both of class $A$: $$AB = D; \quad (AB)A = DA = A; \quad (ABA)B = AB = D; \quad \dots$$

So $\prod_{i \in S} \mathbf M_i$ will have non-zero lower left element only for sets $S$ where the both the highest and lowest elements of $S$ are of opposite parity to $N$, and no two adjacent elements of $S$ are of the same parity. Since $N$ itself fails this condition, the highest index in any of these products will be $N-1$. Note that this does not include the empty set, but does include singleton sets where the value has the correct parity. For all such $S$, the lower-left element of the matrix product will be the product of the corresponding $x_i$.

To develop a calculation algorithm, I am going to re-index the $x_i$ by defining $y_i = x_{N-i}, i \in \{0,1,\dots,N-1\}$. So now we want index sets $S$ of alternating parity (i.e., no adjacent elements of the same parity), and whose first and last elements are odd.

Define $O_n$ to be the collection of all such sets of natural numbers $\le n$ of alternating parity and odd first and last elements, and $E_n$ to be the sets of alternating parity with odd first element, but even last element $\le n$. Define $\overline O_n = O_n \setminus O_{n-1}$, $\overline E_n = E_n \setminus E_{n-1}$ ($U\setminus V := \{u \in U : u \notin V\}$). If $n$ is even, then $\overline O_n$ is empty, while every set in $\overline E_n$ will contain $n$. Removing $n$ from each of the sets in $\overline E_n$ results in $O_{n-1}$ (note that $\{n\} \notin \overline E_n$). If $n$ is odd, then $\overline E_n$ is empty, while every set in $\overline O_n$ will contain $n$. Removing $n$ from each of the sets in $\overline O_n$ other than $\{n\}$ results in a set of $E_{n-1}$.

Let $$Q_n = \sum_{S \in O_n} \prod_{i \in S} y_i = \sum_{S \in \overline O_n} \prod_{i \in S} y_i + \sum_{S \in O_{n-1}} \prod_{i \in S} y_i\\R_n = \sum_{S \in E_n} \prod_{i \in S} y_i= \sum_{S \in \overline E_n} \prod_{i \in S} y_i + \sum_{S \in E_{n-1}} \prod_{i \in S} y_i$$

When $n$ is odd, $O_{n-1} = O_{n-2}$ and $\overline O_n = \{ S\cup \{n\} : S \in E_{n-1}\}\cup \big\{\{n\}\big\}$. So $$Q_n = y_n + y_n\sum_{S \in E_{n-1}} \prod_{i \in S}y_i + \sum_{S \in O_{n-2}} \prod_{i \in S} y_i\\ Q_n = y_n(1+R_{n-1}) + Q_{n-2}$$ The case for even $n$ is similar, but there is no added extra $y_n$: $$R_n = y_nQ_{n-1} + R_{n-2}$$

Defining $$T_n = \begin{cases}Q_n&n\text{ odd}\\R_n&n\text{ even}\end{cases}$$ we end up with $$T_{-1} = T_0 = 0\\T_n=\begin{cases}y_nT_{n-1} + T_{n-2},&n \text{ even}\\y_n(T_{n-1}+1) + T_{n-2}, &n\text{ odd}\end{cases} $$ with $\begin{cases}T_{N-2}&N\text{ odd}\\T_{N-1}&N\text{ even}\end{cases}$ as the value you are trying to calculate.

Backing out the re-indexing, let: $$t_{N+1} = t_N = 0\\t_n = \begin{cases}x_nt_{n+1} + t_{n+2},& n \equiv N\mod 2\\x_n(t_{n+1}+1) + t_{n+2},&n\not\equiv N\mod 2\end{cases}$$ with $\begin{cases}t_2&N\text{ odd}\\t_1&N\text{ even}\end{cases}$ as the value you are trying to calculate.

For an algorithm,

   r = 0
   q = x[N-1]
   for(i = N - 2; i > 1; i -= 2) 
   {
      r = r + x[i] * q
      q = q + x[i-1] * (r + 1)
   }
   return q
Paul Sinclair
  • 45,932
  • Nice. I see you start from x_{N-1} because we know it's included, and you build up valid products from there. I see we could also start on the bottom so we don't index backwards. T_{1+N%2} = x_{1+N%2}. T_{i+2} = T_i(1+x_{i+1}x_{i+2}) +x_{i+2}. And T_{N-1} is the desired value. OR, if we want to go up by 1s: T_0=0. T_{i+1} = T_i(1 + x_{2i+N%2}x_{2i+1+N%2}) + x_{2i+1+N%2}. And T_⌊N/2⌋ is the desired value. – WeCanDoItGuys Dec 12 '24 at 06:08
  • It's a systematic way to build up the sum without so many wasted calculations, and gives me a way to write the concept: For odd N, (((x₂[1+x₃x₄]+ x₄)[1+x₅x₆] + x₆)[1+x₇x₈] + x₈)[...] + ...) ... . So it does answer the question: I'll leave off marking it the answer for now in case someone gives an even more closed or more general answer. – WeCanDoItGuys Dec 12 '24 at 06:10
  • Hi, something's wrong. I tried your recursion for x_i={-1,-1,-1,-2,-1,-1,-1,-1,-2} (a_0=128, a_1=81) and got -23. I tried your code and got -34. When I did the matrix multiplication I got -31. – WeCanDoItGuys Dec 14 '24 at 19:35
  • I think the issue is terms like x₂x₅x₈ contribute but are not accounted for in your formula, since it only tacks on consecutive pairs. – WeCanDoItGuys Dec 14 '24 at 19:49
  • You are right. I think I am good up to the point where I tried to come up with that recursion. But in it (for even $n$ as an example) my recursion only includes $x_{2k}$ when $x_{2k+1}$ is also included, which is not always the case. I think the correct calculation can be done most easily with a double recursion (one where the intermediate values end with an even indexed $x_i$ and one where it ends in an odd indexed $x_I$. I'll try to work out the details. – Paul Sinclair Dec 15 '24 at 18:24
  • I've reworked it using a double recursion, but since the even recursion was only used for even indexes and the odd recursion was only used for odd indexes, I was able to recombine them into a single recursion. Try it and see what you get (I haven't). – Paul Sinclair Dec 15 '24 at 20:31
  • I've also been working on it. I hope to still find a closed formula instead of a recurrence relation, but now that you've updated your answer, I'll post what I've written so far and compare. – WeCanDoItGuys Dec 16 '24 at 01:04
  • I've just tested your new recursion for $N=9$. It seems to only give those valid terms that end in $x_8$. To get the rest of the terms, ending in $x_6$, $x_4$, and $x_2$, I suspect we'd have to put your algorithm into a sum. – WeCanDoItGuys Dec 16 '24 at 02:23
  • Or... maybe just add $x_n$ at each opposite-parity-to-$N$ iteration. For $N=9$ we'd get for example, $t_6=x_6+x_6x_7x_8+x_8$ (instead of $t_6=x_6x_7x_8+x_8$), then $t_5=x_5x_6+x_5x_6x_7x_8+x_5x_8+x_7x_8$. – WeCanDoItGuys Dec 16 '24 at 02:31
  • In fact I think I could say that the sum of all elements of the final matrix is $(2+\frac{1}{2}(t_1+t_2+\sum_{n=0}^{N}t_n))$, where $t_n=x_n+x_nt_{n+1}+t_{n+2}$, $t_N=x_N, t_{N-1}=x_{N-1}$. Because each nonzero matrix in the expansion of $\prod_{i=1}^N(\mathbf{M_i}+\mathbf{I})$ will have a single element that is a product of $x_i$s with alternating-parity-indices, the recursion of $t_n$ will discover all of them twice (except $t_1$ and $t_2$), and then there will be a $+\mathbf{I}$ at the end that contributes $2$. – WeCanDoItGuys Dec 16 '24 at 03:10
  • Yes, the fault in my evaluation this time was that removing odd $n$ from the sets of $\overline O_n$ results in $E_{n-1}$". The opposite statement for even $n, \overline E_n$ and $O_{n-1}$ is true, because ${n} \notin \overline E_n$. But odd ${n}$ is in $\overline O_n$, but $E_{n-1}$ does not contain the empty set. All other sets of $\overline O_n$ are sets of $E_{n-1}$ with $n$ added, but not the singleton ${n}$. I'll adjust it again. – Paul Sinclair Dec 16 '24 at 14:08
0

Paul Sinclair found that the bottom left element (hereinafter $e_{10}$) is a sum of products of $x_i$s where the first and last index of each term are of opposite parity to $N$ and no two adjacent terms have indices of the same parity. The singleton $x_{N-1}$ is always in the sum, and we will use this to build up our rule for all allowed terms.
Let us consider $N=9$ to spot the pattern:
$T_8=x_8$ is a term in the sum.
Next let's build the terms that start with $x_6$. It's only $T_6=x_6(1+x_7T_8)$.
The terms that start with $x_4$: $T_4=x_4(1 + x_7T_8 + x_5(T_6+T_8))$.
The terms that start with $x_2$: $T_2=x_2(1 + x_7T_8 + x_5(T_6+T_8) +x_3(T_4+T_6+T_8))$.
Each term is $T_i=x_iP_i$. We can see that $P_i=P_{i+2}+x_{i+1}\sum_{j=i+2, j\text{ even}}^{N-1}x_jP_j$, where $P_{N-1}=1$.
The total sum of allowed terms then (for odd $N$) is:
$e_{10}=\sum_{i=2, i \text{ even}}^{N-1}T_i=\sum_{i=2, i \text{ even}}^{N-1}x_iP_i$.

I'd prefer to normalize this to start at $0$ and increment by $1$.
Let $p_{i}=P_{N-1-2i}$, so $\begin{pmatrix}P_{N-1}\\...\\P_2\end{pmatrix}\rightarrow \begin{pmatrix}p_{0}\\...\\p_{\frac{N-3}{2}}\end{pmatrix}$. We get $p_0=1$, $p_i=p_{i-1}+x_{N-2i}\sum_{j=0}^{i-1}x_{N-1-2j}p_j$, and $e_{10}=\sum_{i=0}^{(N-3)/2}x_{N-1-2i}p_i$.

Let us consider $N=8$ to spot the pattern for even $N$:
$T_7=x_7$
$T_5=x_5(1+x_6T_7)$
$T_3=x_3(1+x_6T_7+x_4(T_5+T_7))$
$T_1=x_1(1+x_6T_7+x_4(T_5+T_7)+x_2(T_3+T_5+T_7))$
Here we have $T_i=x_iP_i$, $P_i=P_{i+2}+x_{i+1}\sum_{j=i+2, j\text{ odd}}^{N-1}x_jP_j$, where $P_{N-1}=1$.
Normalizing this comes out the same way, except it ends at $T_1\Rightarrow P_1\Rightarrow p_{\frac{N-2}{2}}$.

So, we have that the bottom left element of $\prod_{i=1}^N(\mathbf{M_i}+\mathbf{I})$ is:
$$e_{10}=\sum_{i=0}^{\lfloor\frac{N-2}{2}\rfloor}x_{N-1-2i}p_i\text{, where }p_i=p_{i-1}+x_{N-2i}\sum_{j=0}^{i-1}x_{N-1-2j}p_j\text{, and }p_{0}=1$$ I would prefer a closed form of $p_i$. I'll post this for now and perhaps edit later with progress.


Euclidean Algorithm:
In the context of solving $a_0n+a_1m=1$, we have $x_i=−⌊\frac{a_{i−1}}{a_i}⌋$, and $e_{10}=\begin{cases}r_m &N\text{ is even}\\r_n &N\text{ is odd}\end{cases}$.
Since $x_i$ is negative and the terms of $e_{10}$ are products of an odd quantity of $x_i$s, we can replace $x_i$ with $y_i=\lfloor\frac{a_{i−1}}{a_i}\rfloor$ and write a negative sign explicitly before the formula for $e_{10}$.
$\text{Find }p_i=p_{i-1}+y_{N-2i}\sum_{j=0}^{i-1}y_{N-1-2j}p_j\text{, given }p_{0}=1\text{. Then }e_{10}=-\sum_{i=0}^{\lfloor\frac{N-2}{2}\rfloor}y_{N-1-2i}p_i$.

Examples:
For $13n+5m=1$, $a_i=\{13,5,3,2,1\}$, $N=4$, $y_i=\{2,1,1,2\}$, and $p_i=\{1,1+y_2(y_3\cdot1)\}=\{1,2\}$:
$$r_m=-(y_3\cdot1 + y_1\cdot2)=-(1\cdot1 + 2\cdot2)=-5$$

For $13n+7m=1$, $a_i=\{13,7,6,1\}$, $N=3$, $y_i=\{1,1,6\}$, and $p_i=\{1\}$:
$$r_n=-(y_2\cdot1)=-1$$


Collatz Algorithm:
In the context of solving $2^nx_n+3^A(−x_0)=1$ for $x_0$, we have $x_0=2^nm-\begin{cases}e_{10} &N\text{ even, }3^A<2^n\text{; }N\text{ odd, }3^A>2^n\\(1-2^ne_{10})/3^A &N\text{ odd, }3^A<2^n\text{; }N\text{ even, }3^A>2^n\end{cases}$

Example:
Let $n=7, A=4$, so $128x_n + 81(-x_0) = 1$. Then $a_i = \{128,81,47,34,13,8,5,3,2,1\}$, $N=9$, and $y_i=\{1,1,1,2,1,1,1,1,2\}$.
$p_0=1$
$p_1=1+y_7(y_8\cdot1)=2$
$p_2=2+y_5(y_8\cdot1+y_6\cdot2)=5$
$p_3=5+y_3(y_8\cdot1+y_6\cdot2+y_4\cdot5)=18$ $$-e_{10}=y_8\cdot1+y_6\cdot2+y_4\cdot5+y_2\cdot18 = 31$$ $$\Rightarrow x_0 = 128m - \frac{1+128\cdot31}{81}=128m-49$$

Motivation:
The value $x_n$ after the $n$th shortcut Collatz iteration on $x_0$ can be found if $x_0$'s parity sequence is known: $x_n = \frac{3^Ax_0 + S_{k_i}}{2^n}$, where $S_{k_i}=\sum_{i=0}^{A-1}3^{A-1-i}2^{k_i}$, $A$ is the number of $1$s in the parity sequence, and $k_i$ is their index in the sequence.
For example, $11$'s parity sequence for the first $n=7$ iterations is $[1101001]_7$. In this case, $S_{k_i}=3^32^0+3^22^1+3^12^3+3^02^6=133$. So we can say $x_9=\frac{3^4\cdot11+133}{2^7}=8$.

My motivation for this post is finding the $x_0$ that follows a given parity sequence. I've found it amounts to solving $2^nx_n+3^A(−x_0)=S_{k_i}$. Since $2^n$ and $3^A$ are coprime, this amounts to finding a solution for $x_0$ in $2^nx_n+3^A(−x_0)=1$, and multiplying the solution by $S_{k_i}$.
So, in our example, we have found the general form of values that follow the parity sequence $[1101001]_7$ is $x_0=128m-49\cdot133$, or, taking $(-49\cdot133)\%128$ to simplify, $x_0=128m+11$.

  • 1
    I doubt you will find a better closed form than $$\sum_{S\in U}\prod_{i\in S}x_i$$ where U is the set of all subsets of ${1, \dots, N-1}$ of alternating parity and with highest and lowest members of the same parity as $N-1$. But I could be wrong. For actual computation, I can guarantee you will find no faster method than a recursive algorithm such as I have been trying to develop. – Paul Sinclair Dec 16 '24 at 14:30