1
$\begingroup$

I am looking for a fast algorithm to find all integer solutions for the following system of linear equations ($c_1,\ldots,c_n \in \mathbb{Z}$ and $r\in \mathbb{N}$ ):

$x_1+x_2=c_1$

$x_3+x_4=c_2$

...

$x_{2n-1}+x_{2n}=c_n$

$|x_1|+|x_2|+\ldots+|x_{2n}|=r$

$x_1,\ldots,x_{2n} \in \mathbb{Z}$

Also can we find the number of solutions before solving the system?

1 Answers 1

1

The variables come in pairs, tied together only by the equation $ |x_1| + |x_2| + \ldots + |x_{2n}| = r$.

Let $|x_{2k-1}| + |x_{2k}| = r_k$. Given integers $r_k$ and $c_k$, consider the integer solutions to $$ \eqalign{ x_{2k-1} + x_{2k} &= c_k\cr |x_{2k-1}| + |x_{2k}| &= r_k\cr}$$ Of course we need $r_k \ge |c_k|$ and $r_k \equiv c_k \mod 2$ to have any hope. There are four cases, according to whether $x_{2k-1}$ and $x_k$ are positive or negative.

  1. If $x_{2k-1} \ge 0$ and $x_{2k} \ge 0$, we need $c_k = r_k \ge 0$, and $x_{2k} = c_k - x_{2k-1}$ for $0 \le x_{2k-1} \le c_k$.
  2. If $x_{2k-1} \ge 0 > x_{2k}$, then $r_k = x_{2k-1} - x_{2k} > c_k$ and $x_{2k} = (c_k - r_k)/2$, $x_{2k-1} = (c_k + r_k)/2$.
  3. Similarly if $x_{2k} \ge 0 > x_{2k-1}$, $r_k > c_k$ and $x_{2k-1} = (c_k - r_k)/2$, $x_{2k} = (c_k + r_k)/2$.
  4. If $x_{2k-1} < 0$ and $x_{2k} < 0$, we need $c_k = -r_k < 0$, and $x_{2k} = c_k - x_{2k-1}$ for $c_k < x_{2k-1} < 0$.

Next do some recursion with respect to $n$.

  • 0
    Thanks. Can we find the number of possible solutions (or a tight upper bound) without actually solving the system?2017-01-16
  • 0
    The questions asks about the number of solutions without requiring to find all of them.2017-01-28