Constructing invertible matrix with entries in a principal ideal domain Am trying to solve this exercise in S. Bosch's book Algebra. From the Viewpoint of Galois Theory (Exercise 5, page 81). 

Assume that $A$ is a principal ideal domain, and assume that $({a_{11}},\dots,{a_{1n}})$ is a set elements in $A$ for which $\gcd{({a_{11}},\dots,{a_{1n}})}=1.$ Find an $n\times n$ square matrix with entries in $A$ having $({a_{11}},\dots,{a_{1n}})$ as its first row, and which is invertible in $A$. 

I may be missing something completely obvious here (sorry!) but my approach is as follows. Since $\gcd{({a_{11}},\dots,{a_{1n}})}=1,$ we have an $n$-tuple of elements of $A$, ${({x_{1}},\dots,{x_{n}})}$ such that $${\sum^n_{i=1}{x_{i}{a_{1i}}}}=1.$$
So I want to construct an $n\times n$ square matrix whose first row is $({a_{11}},\dots,{a_{1n}})$, and whose determinant is ${\sum^n_{i=1}{x_{i}{a_{1i}}}}$. In the case $n = 2$ this seems straight forward. If ${a_{11}}x+{a_{12}}y=1$, then consider the $2\times 2$ matrix whose first row is $({a_{11}},{a_{12}}),$ and the second row is $(-y,x)$. But I have no way of treating the case $n&gt;2$. Is it in general possible to construct a matrix having determinant ${\sum^n_{i=1}{x_{i}{a_{1i}}}}$ having $({a_{11}},\dots,{a_{1n}})$ as its first row (even forgetting the condition ${\sum^n_{i=1}{x_{i}{a_{1i}}}}=1$)?
Because we are working over a PID, all matrices have a Smith normal form. Let's apply that to the $1\times n$ matrix $R=(a_{11},\ldots,a_{1n})$. 

The existence of a Smith normal form implies that there exists a $1\times 1$ matrix $P$ and and an $n\times n$ $Q$, both with determinant $1$, such that 
$$
PRQ=\left(d_1,0,0,\ldots,0\right),\tag{1}
$$
where $d_1$ is the first invariant factor of $R$ (and this the only invariant factor given that $R$ has a single row only). Furthermore, $d_1$ is the gcd of the $1\times1$-minors of $R$. 

In our special case we can immediately deduce that $d_1=1$ and that the factor $P$ really isn't there. Recalling that $\det Q=1$ we know that $Q^{-1}$ exists and has entries in our PID $A$. Therefore we can rewrite $(1)$ in the form
$$
R=\left(\begin{array}{cccc}1&amp;0&amp;\cdots&amp;0\end{array}\right)Q^{-1}.\tag{2}
$$

But, expanding the right hand side of $(2)$, we see immediately that the first row $Q^{-1}$ is equal to $R$.


  Therefore $Q^{-1}$ is the sought after matrix and we are done.




The argument generalizes to the following:


  A $k\times n$ matrix $R$ with entries in a PID $A$ and all its invariant factors $d_1=d_2=\cdots=d_k=1$ can be completed to an $n\times n$ matrix $B$ with entries from $A$ and $\det B=1$




For the purpose of the task at hand invoking the full power of Smith normal forms is a bit overkill. We can build the required matrix $Q$ in stages using the following observation as an inductive step.

Assume that at least one of $a,b\in A$ is non-zero. Because $A$ is a PID, $d=\gcd(a,b)$ exists. Furthermore, by Bezout's identity we can find elements $u,v\in A$ such that $d=ua+vb$. As $d$ is a factor of both $a$ and $b$, we can find $x,y\in A$ such that $a=dx$, $b=dy$. To this data we associate the $2\times2$ matrix
$$
Q(a,b)=\left(\begin{array}{rr}u&amp;-y\\ v&amp;x\end{array}\right).
$$
This matrix has the following key properties:


As $d\cdot\det Q(a,b)=d(ux+vy)=ua+vb=d$ and the cancellation law holds in $A$, we see that $\det Q(a,b)=1$.
We have the matrix product identity
$$
(a\quad b) Q(a,b)=(d\quad 0).\tag{3}
$$
We then prove by the following


Claim. For any natural number $n$ and any vector $(a_1,a_2,\ldots,a_n)\in A^n$ there exists an $n\times n$ matrix $Q\in M_n(A)$ such that $\det Q=1$ and
$$
(a_1\quad a_2\quad\cdots\quad a_n)Q=(d\quad 0\quad\cdots\quad0),
$$
where $d=\gcd(a_1,a_2,\ldots,a_n)$.

Proof. An induction on $n$. The base case $n=1$ is trivial as we can use $Q=I_1$. Assume then that $n\ge2$. Let's write $d_2=\gcd(a_2,a_3,\ldots,a_n)$.
The induction hypothesis implies that we can find a matrix $Q_2\in M_{n-1}(A)$ with determinant $1$ such that
$$
(a_2\quad a_3\quad\cdots\quad a_n)Q_2=(d_2\quad 0\quad\cdots\quad0).\tag{4}
$$
Let 
$$
\tilde{Q}_2=\left(\begin{array}{c|c}
1&amp;\mathbf{0}\\ 
\hline
\mathbf{0}&amp;Q_2\end{array}\right)
$$
be the $n\times n$ matrix gotten by adding an extra row and a column to $Q_2$ with all the other new entries equal to zero save for a single $1$ at position $(1,1)$. Obviously $\det\tilde{Q}_2=1$ also. In view of identity $(4)$ we have
$$
(a_1\quad a_2\quad\cdots\quad a_n)\tilde{Q}_2=(a_1\quad d_2\quad 0\quad\cdots\quad0).\tag{5}
$$
By basic properties of gcds we have $d=\gcd(a_1,d_2)$. The claim thus follows by multiplying $(5)$ from the right with the matrix
$$
Q_1=\left(\begin{array}{c|c}
Q(a_1,d_2)&amp;\mathbf{0}\\ 
\hline
\mathbf{0}&amp;I_{n-2}\end{array}\right),
$$
where $Q(a_1,d_2)$ is the $2\times2$ matrix from our earlier considerations, and the zero blocks have sizes $2\times (n-2)$ and $(n-2)\times 2$ respectively. Clearly $\det Q_1=1$, so $\det Q=1$ also. QED.
Expanding for the determinant along the first row (consisting of $a_{1,i}$'s) gives you $n$ inter-related conditions on $n$ $(n-1 \times n-1)$-subdeterminants where the $i^\text{th}$ subdeterminant must be  $(-1)^{i + 1} \cdot x_i$.Well, this gets arbitrarily complicated for $n &gt; 2$, but it is exactly what you (implicitly) did for the basic $2$-by-$2$ case. It is enough to get $n\times n-1$ independent equations which shall impose conditions on our  $n\times n-1$ unknowns ( since we already know the first row or equivalently, $n$ entries). We thus have less equations than unknowns and we can thus strategically impose some values on some entries to reduce the number of unknowns.This strategy might be the core of the solution.