Skip to content

Commit 4cc5f12

Browse files
Merge pull request #452 from Parsnip37/docs/integer-kernel-bases
Introduce integer matrices and kernel bases
2 parents ad6f9c5 + 2627f25 commit 4cc5f12

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

‎doc/source/fmpz_mat.rst‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,117 @@
11
**fmpz_mat** -- matrices over integers
22
===============================================================================
33

4+
An :class:`~flint.fmpz_mat` represents a dense rectangular matrix over
5+
:math:`\mathbb{Z}`, with arbitrary-precision integer entries.
6+
7+
Construction and arithmetic
8+
---------------------------
9+
10+
Construct a matrix from a list of rows, all of the same length::
11+
12+
>>> from flint import fmpz_mat
13+
>>> A = fmpz_mat([[1, 2], [3, 4]])
14+
>>> A
15+
[1, 2]
16+
[3, 4]
17+
18+
Equivalently, ``fmpz_mat(2, 2, [1, 2, 3, 4])`` lists the entries row by
19+
row. For nonnegative dimensions ``m`` and ``n``, ``fmpz_mat(m, n)``
20+
constructs the zero matrix with ``m`` rows and ``n`` columns.
21+
22+
The dimensions are given by :meth:`~flint.fmpz_mat.nrows` and
23+
:meth:`~flint.fmpz_mat.ncols`. Row and column indices start at zero;
24+
``A[i, j]`` reads an entry, and ``A[i, j] = value`` changes it::
25+
26+
>>> A.nrows(), A.ncols()
27+
(2, 2)
28+
>>> A[0, 1]
29+
2
30+
31+
Use ``+`` and ``-`` for entrywise addition and subtraction of matrices
32+
with the same dimensions. ``A * B`` is the usual matrix product,
33+
requiring the number of columns of ``A`` to equal the number of rows
34+
of ``B``; multiplication by an integer scales every entry::
35+
36+
>>> 2 * A
37+
[2, 4]
38+
[6, 8]
39+
>>> A * A
40+
[ 7, 10]
41+
[15, 22]
42+
43+
:meth:`~flint.fmpz_mat.transpose` interchanges rows and columns.
44+
For square matrices, :meth:`~flint.fmpz_mat.det` returns the determinant;
45+
:meth:`~flint.fmpz_mat.rank` computes the rank over :math:`\mathbb{Q}`
46+
for any matrix shape. These calculations are exact::
47+
48+
>>> A.transpose()
49+
[1, 3]
50+
[2, 4]
51+
>>> A.det(), A.rank()
52+
(-2, 2)
53+
54+
Rational nullspaces and integer kernels
55+
---------------------------------------
56+
57+
For an integer matrix :math:`A` with :math:`m` rows and :math:`n` columns,
58+
:meth:`~flint.fmpz_mat.nullspace` computes a basis of the right nullspace
59+
60+
.. math::
61+
62+
\ker_{\mathbb{Q}}(A) = \{x \in \mathbb{Q}^n : Ax = 0\}.
63+
64+
It returns ``(X, nullity)``, where ``X`` is an :math:`n \times n` integer
65+
matrix whose first ``nullity`` columns form this basis. The remaining
66+
columns are zero. The basis vectors span the nullspace over
67+
:math:`\mathbb{Q}`; they need not generate every integer solution by
68+
integer linear combinations.
69+
70+
For example, the matrix in the :meth:`~flint.fmpz_mat.nullspace` example is
71+
72+
.. math::
73+
74+
A = \begin{pmatrix}
75+
1 & 2 & 3 & 4 & 5 \\
76+
6 & 7 & 8 & 9 & 10 \\
77+
11 & 12 & 13 & 14 & 15
78+
\end{pmatrix}.
79+
80+
The vector :math:`v = (1,-2,1,0,0)^T` satisfies :math:`Av = 0`, and the
81+
first displayed column of ``X`` is :math:`5v`. Every entry of that
82+
``X`` is divisible by five, so :math:`v` is not an integer linear
83+
combination of its columns.
84+
85+
To obtain a basis of the integer kernel
86+
:math:`\{x \in \mathbb{Z}^n : Ax = 0\}`, use the Hermite normal form of
87+
:math:`A^T` with a transformation matrix:
88+
89+
.. code-block:: python
90+
91+
A = fmpz_mat([[1, 2, 3, 4, 5],
92+
[6, 7, 8, 9, 10],
93+
[11, 12, 13, 14, 15]])
94+
H, U = A.transpose().hnf(transform=True)
95+
96+
Here :meth:`~flint.fmpz_mat.hnf` gives :math:`H = U A^T`, where
97+
:math:`U` is unimodular. If :math:`r` is the rank of :math:`A`, the last
98+
:math:`n-r` rows of :math:`H` are zero. The transposes of the corresponding
99+
rows of :math:`U` form a basis of the integer kernel.
100+
101+
Indeed, since :math:`U` is unimodular, every integer vector can be written
102+
uniquely as :math:`x = U^T y` with :math:`y` integral. Then :math:`Ax = 0`
103+
is equivalent to :math:`H^T y = 0`. The first :math:`r` rows of :math:`H`
104+
are linearly independent, so this holds exactly when the first :math:`r`
105+
coordinates of :math:`y` are zero. This proves both generation and
106+
independence of the stated integer kernel basis.
107+
108+
LLL reduction preserves the integer span of a basis; applying it to a
109+
rational nullspace basis cannot recover integer vectors missing from that
110+
span.
111+
112+
API reference
113+
-------------
114+
4115
.. autoclass :: flint.fmpz_mat
5116
:members:
6117
:inherited-members:

0 commit comments

Comments
 (0)