Kernel of an integer matrix, modulo the integers. I have an integer matrix $A$, such as
\begin{pmatrix}
-2 & 2  \\
-2 & 2  \\
\end{pmatrix}
I'm looking for solutions $(x_1,x_2) \in (\mathbb{Q}/\mathbb{Z})^2$ such that $Ax=0\mod\mathbb{Z}$.
In this case this is easy: the condition is $2(x_2-x_1)\equiv0\mod\mathbb{Z}$, so either $x_1\equiv x_2$ or $x_1 \equiv x_2+1/2$. In other words, the kernel of $A$ as a map from $(\mathbb{Q}/\mathbb{Z})^2$ to itself has two "components" $(x,x)$ and $(x,x+1/2)$.
Is there a way to find the "components" of solutions in the above sense, for a general $n\times n$ integer matrix of rank $n-1$? What about other ranks?
I thought about finding the $\mathbb{Q}$-kernel of $A-\mathrm{diag}(b_1,...,b_n)$ for each tuple of integers $(b_i)$ and then ignoring duplicates mod $\mathbb{Z}$. However there are infinitely many such tuples, so it's not clear when this terminates, even if it does terminate at some point.
 A: An integer matrix $A$ (not necessarily square) represents a linear map $\alpha\colon\mathbb{Q}^m \to \mathbb{Q}^n$.   Let $K$ be the kernel of $\alpha$, and let $S$ be the set $\{x\in \mathbb{Q}^m|\,\, \alpha(x)=0 \mod \mathbb{Z}\}$.
Let $\hat{K}$ be $K/(K\cap\mathbb{Z}^m)$ and let $\hat{S}$ be $S/\mathbb{Z}^m$.  That is, $\hat{S}$ is the set of solutions you are looking for.
Clearly $K\subseteq S$ so $\hat{K}\subseteq \hat{S}$.  Your 'components' are then elements of the group $\hat{S}/ \hat{K}$.
The map $\alpha$ restricts to a linear map $\alpha'\colon\mathbb{Z}^m \to \mathbb{Z}^n$.  The cokernel of $\alpha'$ is a finitely generated abelian group, which will be isomorphic to $\mathbb{Z}^r\oplus T$ for some integer $r$ and finite abelian group $T$.
We claim: $$\hat{S}/ \hat{K}\cong T.$$
Proof:   Elements of $S/{K}$ are in one to one correspondence with their images under $\alpha$, which lie in $\mathbb{Z}^n$.  Given $y\in \mathbb{Z}^n$, we have $y\in$Im$(\alpha)$ if and only if $jy\in$Im$(\alpha')$ for some integer $j$.  In other words, $y\in \mathbb{Z}^n$ is in the image of $S/K$ precisely when $y$ represents an element in $T$.
Thus we may identify $S/K$ with the $y\in \mathbb{Z}^n$ which represent elements of $T$.  The integer points of $S/K$ map to the image of $\alpha'$.  Thus we have induced an isomorphism $\hat{S}/\hat{K}\cong T$.  $\qquad\qquad\Box$
In practice this means your problem is equivalent to taking a presentation matrix for a finite abelian group, and computing a basis for the torsion $T$ with respect to standard form $\bigoplus_{i=1}^l \mathbb{Z}/k_i\mathbb{Z}$.
