0

I have a problem similar in some ways to this one:

(Diophantine?) Equations With Multiple Variables

Where I need to find all $x$ for

$$a_1x_1+a_2x_2+\cdots+a_kx_k = 0$$

with the following constraints: $a_i \in \mathbb{Z}, x_i \in \mathbb{Z}, 0 \le x_i \lt 10, 0 \lt k \le 10$ . $x$ are chosen uniquely from the range [0, 10) but I might have to brute-force that part.

An example of a brute-force solution to this equation form is

$$ \begin{pmatrix} 10000& 1000& 200& 100& 20& 2& 0& -100& -1000& -10000 \end{pmatrix} \begin{pmatrix} 2\\ 4\\ 7\\ 8\\ 5\\ 0\\ 9\\ 3\\ 6 \end{pmatrix} = 0 $$

I tried to follow along with the solution in the linked question, but I don't think it applies since "dividing into [the right-hand side]" doesn't make much sense when the right-hand side is zero. Perhaps this isn't actually a Diophantine equation? Another way of putting it is that I need to find roots of a polynomial of order one in $x$ subject to the above constraints; or that I need to solve for the right-hand side of the dot product $0 = A \cdot x$ .

1 Answers1

1

(EDITED) You can use dynamical programming.

Let $F(k, v)$ be the number of solutions to $a_1 x_1 + \ldots + a_k x_k = v$ with $x_k \in \{0, \ldots, 9\}$, where $v \in \mathbb Z$. Of course $F(k,v) = 0$ if $v > 9 \sum_{i=1}^k \max(a_i, 0)$ or $v < 9 \sum_{i=1}^k \min(a_i, 0)$, and $F(1,v) = 1$ if $v \in \{a_1, 2a_1, \ldots, 9 a_1\}$, $0$ otherwise. By conditioning on the value of $x_k$, $$F(k,v) = \sum_{t=0}^9 F(k-1,v-t a_k)$$ We compute and remember each $F(k,v)$ for each $k$ starting at $1$, and each $v$ in the interval where it can be nonzero.

Then work backwards: assuming $F(k,v) \ne 0$, there are solutions where $x_k$ is each $t$ from $0$ to $9$ such that $F(k-1,v-a_k t) \ne 0$.

Robert Israel
  • 470,583