Skip to content

Commit

Permalink
sagemathgh-37157: Add additional lattice methods for matrices over QQ
Browse files Browse the repository at this point in the history
    
LLL has long been implemented for matrices over QQ by clearing the
denominator and doing LLL over ZZ, but this was not done for BKZ() or
is_LLL_reduced()

This PR adds BKZ() and is_LLL_reduced() to rational matrices, using the
same techniques as the current LLL method.
    
URL: sagemath#37157
Reported by: TheBlupper
Reviewer(s): grhkm21
  • Loading branch information
Release Manager committed Jan 29, 2024
2 parents 45b8635 + 80a2c2f commit 19f86c2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/sage/matrix/matrix_integer_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2743,7 +2743,8 @@ cdef class Matrix_integer_dense(Matrix_dense):
def BKZ(self, delta=None, algorithm="fpLLL", fp=None, block_size=10, prune=0,
use_givens=False, precision=0, proof=None, **kwds):
"""
Block Korkin-Zolotarev reduction.
Return the result of running Block Korkin-Zolotarev reduction on
``self`` interpreted as a lattice.
INPUT:
Expand Down
53 changes: 51 additions & 2 deletions src/sage/matrix/matrix_rational_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2927,13 +2927,39 @@ cdef class Matrix_rational_dense(Matrix_dense):
# LLL
# ###############################################

def BKZ(self, *args, **kwargs):
"""
Return the result of running Block Korkin-Zolotarev reduction on
``self`` interpreted as a lattice.
The arguments ``*args`` and ``**kwargs`` are passed onto
:meth:`sage.matrix.matrix_integer_dense.Matrix_integer_dense.BKZ`,
see there for more details.
EXAMPLES::
sage: A = Matrix(QQ, 3, 3, [1/n for n in range(1, 10)])
sage: A.BKZ()
[ 1/28 -1/40 -1/18]
[ 1/28 -1/40 1/18]
[-1/14 -1/40 0]
sage: A = random_matrix(QQ, 10, 10)
sage: d = lcm(a.denom() for a in A.list())
sage: A.BKZ() == (A * d).change_ring(ZZ).BKZ() / d
True
"""
A, d = self._clear_denom()
return A.BKZ(*args, **kwargs) / d

def LLL(self, *args, **kwargs):
"""
Return an LLL reduced or approximated LLL reduced lattice for
``self`` interpreted as a lattice.
For details on input parameters, see
:meth:`sage.matrix.matrix_integer_dense.Matrix_integer_dense.LLL`.
The arguments ``*args`` and ``**kwargs`` are passed onto
:meth:`sage.matrix.matrix_integer_dense.Matrix_integer_dense.LLL`,
see there for more details.
EXAMPLES::
Expand All @@ -2942,10 +2968,33 @@ cdef class Matrix_rational_dense(Matrix_dense):
[ 1/28 -1/40 -1/18]
[ 1/28 -1/40 1/18]
[ 0 -3/40 0]
sage: A = random_matrix(QQ, 10, 10)
sage: d = lcm(a.denom() for a in A.list())
sage: A.LLL() == (A * d).change_ring(ZZ).LLL() / d
True
"""
A, d = self._clear_denom()
return A.LLL(*args, **kwargs) / d

def is_LLL_reduced(self, delta=None, eta=None):
r"""
Return ``True`` if this lattice is `(\delta, \eta)`-LLL reduced.
For a definition of LLL reduction, see
:meth:`sage.matrix.matrix_integer_dense.Matrix_integer_dense.LLL`.
EXAMPLES::
sage: A = random_matrix(QQ, 10, 10)
sage: L = A.LLL()
sage: A.is_LLL_reduced()
False
sage: L.is_LLL_reduced()
True
"""
A, _ = self._clear_denom()
return A.is_LLL_reduced(delta, eta)


cdef new_matrix_from_pari_GEN(parent, GEN d) noexcept:
"""
Expand Down

0 comments on commit 19f86c2

Please sign in to comment.