[Math] Linear Diophantine Equations in Three Variables

diophantine equationselementary-number-theory

$$
3x+6y+5z=7
$$
The general solution to this linear Diophantine equation is as described
here (Page 7-8) is:

$$
x = 5k+2l+14
$$
$$
y = -l
$$
$$
z = -7-k
$$
$$
k,l \in \mathbb{Z}
$$

If I plug the original equation into Wolframalpha the solution is:
$$
y = 5n+2x+2
$$
$$
z =-6n-3x-1
$$
$$
n \in \mathbb{Z}
$$

I can rewrite this as:

$$
x = l
$$
$$
y = 5k+2l+2
$$
$$
z = -6k-3l-1
$$
$$
k,l \in \mathbb{Z}
$$

However now two equations depend on two variables ($k,l$) and one on one variable $l$.
In the first solution one equation depends on two variables and two on one variable.

Questions:

How can I come from a representation like the one from wolfram alpha for the general solution to one where all equations depend on one distinct variable except one equation.

Is there always such a representation?

Best Answer

One way to solve this is to note that $(3,6)=3$ and solve, for $w=x+2y$, $$ 3w+5z=7\tag{1} $$ Using the Extended Euclidean Algorithm as implemented in this answer $$ \begin{array}{r} &&1&1&2\\\hline 1&0&1&-1&3\\ 0&1&-1&2&-5\\ 5&3&2&1&0\\ \end{array}\tag{2} $$ Thus, the second to last column gives a particular solution: $$ 3(2)+5(-1)=1\stackrel{\times7}{\implies}3(14)+5(-7)=7\tag{3} $$ and the last column gives the homogenous solution, which we add to get the general solution: $$ 3(\overbrace{14-5k}^w)+5(\overbrace{-7+3k}^z)=7\tag{4} $$ Now, we solve for $w=1x+2y=14-5k$ in the same manner we got from $(1)$ to $(4)$: $$ 1(\overbrace{14-5k+2j}^x)+2(\overbrace{0-j}^y)=\overbrace{14-5k}^w\tag{5} $$ Multiply $(5)$ by $3$ and plug into $(4)$: $$ 3(\overbrace{14-5k+2j}^x)+6(\overbrace{-j}^y)+5(\overbrace{-7+3k}^z)=7\tag{6} $$


Other answers will come from a reversible change of variables. The answer in $(6)$ is $$ \begin{bmatrix} x\\ y\\ z \end{bmatrix} = \color{#C000FF} {\begin{bmatrix} 14&2&-5\\ 0&-1&0\\ -7&0&3 \end{bmatrix}} \begin{bmatrix} 1\\ j'\\ k' \end{bmatrix}\tag{7} $$ The first "solution" above does not work (mapping $l\leftrightarrow j$): $$ \begin{align} 3x+6y+5z &=3(5k+2j+14)+6(-j)+5(-7-k)\\ &=7+10k\tag{8} \end{align} $$

If we change $z$ to $-7-3k$, the first solution above is $$ \begin{align} \begin{bmatrix} x\\ y\\ z \end{bmatrix} &= \begin{bmatrix} 14&2&5\\ 0&-1&0\\ -7&0&-3 \end{bmatrix} \begin{bmatrix} 1\\ j\\ k \end{bmatrix}\\ &= \color{#C000FF} {\begin{bmatrix} 14&2&-5\\ 0&-1&0\\ -7&0&3 \end{bmatrix}} \begin{bmatrix} 1&0&0\\ 0&1&0\\ 0&0&-1 \end{bmatrix} \begin{bmatrix} 1\\ j\\ k \end{bmatrix}\tag{9} \end{align} $$ which is the solution in $(6)$ under the reversible change $(j,k)=(j',-k')$.

The solution from Wolfram Alpha is $$ \begin{align} \begin{bmatrix} x\\ y\\ z \end{bmatrix} &= \begin{bmatrix} 0&1&0\\ 2&2&5\\ -1&-3&-6 \end{bmatrix} \begin{bmatrix} 1\\ j\\ k \end{bmatrix}\\ &= \color{#C000FF} {\begin{bmatrix} 14&2&-5\\ 0&-1&0\\ -7&0&3 \end{bmatrix}} \begin{bmatrix} 1&0&0\\ -2&-2&-5\\ 2&-1&-2 \end{bmatrix} \begin{bmatrix} 1\\ j\\ k \end{bmatrix}\tag{10} \end{align} $$ which is the solution in $(6)$ under the change $(j',k')=(-2-2j-5k,2-j-2k)$ and since $$ \begin{bmatrix} 1&0&0\\ -2&-2&-5\\ 2&-1&-2 \end{bmatrix}^{-1} = \begin{bmatrix} 1&0&0\\ 14&2&-5\\ -6&-1&2 \end{bmatrix}\tag{11} $$ the change of variables is reversible: $(j,k)=(14+2j'-5k',-6-j'+2k')$.