Efficiently finding all numbers in two sets defined by each other

42 Views Asked by At

In my recreational endeavours of metamethematics, I've come across two sets $\mathbb{A}$ and $\mathbb{B}$ whose elements are defined recursively by eachother.

Initially, we are given a countable infinite set of "seeds" in $\mathbb{A}$.

$$\forall (n,k)\in\mathbb{N}_0^2\Big[g(n)+3^{n+1}\phi(k,k)\in\mathbb{A}\Big]$$

where $g(n)=\frac{1}{2}(3^n(3n(n-1)+7)-3)$, and $\phi:\mathbb{N}_0^2\to\mathbb{N}_0$, is a bijection, defined by $$\phi(m,n)=\begin{cases}m^2+2n & m\geq n\\ n^2+2m+1 & m < n \\ \end{cases}.$$

For example, $(n,k)=(0,0)\implies 2\in\mathbb{A}.$

Then, we are given a curious set of 5 rules which "generate" other integers in $\mathbb{A}$ and $\mathbb{B}$:

$$ \begin{align} &\forall a\in\mathbb{A}\Big[3a+1\in\mathbb{B}\Big]\\ &\forall b\in\mathbb{B}\Big[3b+1\in\mathbb{A}\Big]\\ &\forall (a,b,n)\in(\mathbb{A}\times\mathbb{B}\times\mathbb{N}_0)\Big[g(n)+3^{n+1}\phi(a,b)\in\mathbb{B}\Big]\\ &\forall (a,n,k)\in(\mathbb{A}\times\mathbb{N}_0\times\mathbb{N}_0)\Big[g(n)+3^{n+1}\phi(k,a)\in\mathbb{A}\Big]\\ &\forall (b,n,k)\in(\mathbb{B}\times\mathbb{N}_0\times\mathbb{N}_0)\Big[g(n)+3^{n+1}\phi(b,k)\in\mathbb{A}\Big]\\ \end{align} $$

I wrote a few python scripts that, when given a number $M$, inefficently apply all these rules iteratively until no new numbers less than $M$ appear within either $\mathbb{A}$ or $\mathbb{B}$. However, my code takes on the order of an hour to calculate all the entries less than $M=2^{16}$. I would like to go to much larger orders of magnitudes, but the method I employ seems to take exponentially longer as I increase $M$.

Hence, besides using a faster language than python, what theorems or methods can I use to efficiently calculate all elements in $\mathbb{A}$ and $\mathbb{B}$ less than a given $M$? Can this be done in polynomial time?

Although I am unfamiliar with the area, my intuition tells me that this may boil down to a set of diophantine equations.

If it's relevant, I should point out that $\mathbb{A}\cap\mathbb{B}=\emptyset\wedge\mathbb{A}\cup\mathbb{B}\subset\mathbb{N}_0$.

Note: I am at a bit of a loss for what tags this question relates to best, so please feel free add any you deem relevent.