Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transformation feature to BKZ #39203

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ title: SageMath
abstract: SageMath is a free open-source mathematics software system.
authors:
- name: "The SageMath Developers"
version: 10.6.rc0
version: 10.6.rc1
doi: 10.5281/zenodo.8042260
date-released: 2025-03-22
date-released: 2025-03-27
repository-code: "https://github.com/sagemath/sage"
url: "https://www.sagemath.org/"
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SageMath version 10.6.rc0, Release Date: 2025-03-22
SageMath version 10.6.rc1, Release Date: 2025-03-27
4 changes: 2 additions & 2 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tarball=configure-VERSION.tar.gz
sha1=9743f84f12c5cef218137fc45ee258620ded9fe5
sha256=7b2b9d2fef25fa69918ecb1f5b6eca1fccf22960ce2a235e0baf99d096e625b7
sha1=b864ca0eb94c01c9e724699ac6d797a65b5acbb0
sha256=5aa6946e6a99eeac2b829f2146338eeef8537a3134b4289078c8417092ecaaf2
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9320452a3de4e261d779f159315c25d3dbe8f57d
8dab37468c9feb4a5a1fcc22bbccc12321aaa475
2 changes: 1 addition & 1 deletion build/pkgs/fpylll/distros/conda.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fpylll>=0.5.9
fpylll>=0.6.3
2 changes: 1 addition & 1 deletion build/pkgs/fpylll/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fpylll >=0.5.9
fpylll >=0.6.3
2 changes: 1 addition & 1 deletion build/pkgs/sage_conf/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sage-conf ~= 10.6rc0
sage-conf ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sage_docbuild/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sage-docbuild ~= 10.6rc0
sage-docbuild ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sage_setup/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sage-setup ~= 10.6rc0
sage-setup ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sage_sws2rst/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sage-sws2rst ~= 10.6rc0
sage-sws2rst ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sagelib/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sagemath-standard ~= 10.6rc0
sagemath-standard ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sagemath_bliss/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sagemath-bliss ~= 10.6rc0
sagemath-bliss ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sagemath_categories/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sagemath-categories ~= 10.6rc0
sagemath-categories ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sagemath_coxeter3/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sagemath-coxeter3 ~= 10.6rc0
sagemath-coxeter3 ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sagemath_environment/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sagemath-environment ~= 10.6rc0
sagemath-environment ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sagemath_mcqd/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sagemath-mcqd ~= 10.6rc0
sagemath-mcqd ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sagemath_meataxe/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sagemath-meataxe ~= 10.6rc0
sagemath-meataxe ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sagemath_objects/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sagemath-objects ~= 10.6rc0
sagemath-objects ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sagemath_repl/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sagemath-repl ~= 10.6rc0
sagemath-repl ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sagemath_sirocco/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sagemath-sirocco ~= 10.6rc0
sagemath-sirocco ~= 10.6rc1
2 changes: 1 addition & 1 deletion build/pkgs/sagemath_tdlib/version_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is updated on every release by the sage-update-version script
sagemath-tdlib ~= 10.6rc0
sagemath-tdlib ~= 10.6rc1
2 changes: 1 addition & 1 deletion environment-3.11-linux-aarch64.yml
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ dependencies:
- fonttools=4.56.0=py311h58d527c_0
- fortran-compiler=1.9.0=h25a59a9_0
- fplll=5.5.0=h45c7457_0
- fpylll=0.6.2=py311h2dc1a0e_0
- fpylll=0.6.3=py311h2dc1a0e_0
- freetype=2.13.3=he93130f_0
- furo=2024.8.6=pyhd8ed1ab_2
- gap-core=4.14.0=h1754e88_2
2 changes: 1 addition & 1 deletion environment-3.11-linux.yml
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ dependencies:
- fonttools=4.56.0=py311h2dc5d0c_0
- fortran-compiler=1.9.0=h36df796_0
- fplll=5.5.0=hd20a173_0
- fpylll=0.6.2=py311hf0b6740_0
- fpylll=0.6.3=py311hf0b6740_0
- freetype=2.13.3=h48d6fc4_0
- furo=2024.8.6=pyhd8ed1ab_2
- gap-core=4.14.0=h3b03731_2
2 changes: 1 addition & 1 deletion environment-3.11-macos-x86_64.yml
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ dependencies:
- fonttools=4.56.0=py311ha3cf9ac_0
- fortran-compiler=1.9.0=h02557f8_0
- fplll=5.5.0=h6ede486_0
- fpylll=0.6.2=py311h793c761_0
- fpylll=0.6.3=py311h793c761_0
- freetype=2.13.3=h40dfd5c_0
- furo=2024.8.6=pyhd8ed1ab_2
- gap-core=4.14.0=hb9686a1_2
2 changes: 1 addition & 1 deletion environment-3.11-macos.yml
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ dependencies:
- fonttools=4.56.0=py311h4921393_0
- fortran-compiler=1.9.0=h5692697_0
- fplll=5.5.0=h2a2278a_0
- fpylll=0.6.2=py311h4044dbd_0
- fpylll=0.6.3=py311h4044dbd_0
- freetype=2.13.3=h1d14073_0
- furo=2024.8.6=pyhd8ed1ab_2
- gap-core=4.14.0=h25f1785_2
2 changes: 1 addition & 1 deletion environment-3.12-linux-aarch64.yml
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ dependencies:
- fonttools=4.56.0=py312hcc812fe_0
- fortran-compiler=1.9.0=h25a59a9_0
- fplll=5.5.0=h45c7457_0
- fpylll=0.6.2=py312h37c3976_0
- fpylll=0.6.3=py312h37c3976_0
- freetype=2.13.3=he93130f_0
- furo=2024.8.6=pyhd8ed1ab_2
- gap-core=4.14.0=h1754e88_2
2 changes: 1 addition & 1 deletion environment-3.12-linux.yml
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ dependencies:
- fonttools=4.56.0=py312h178313f_0
- fortran-compiler=1.9.0=h36df796_0
- fplll=5.5.0=hd20a173_0
- fpylll=0.6.2=py312ha4ee43a_0
- fpylll=0.6.3=py312ha4ee43a_0
- freetype=2.13.3=h48d6fc4_0
- furo=2024.8.6=pyhd8ed1ab_2
- gap-core=4.14.0=h3b03731_2
2 changes: 1 addition & 1 deletion environment-3.12-macos-x86_64.yml
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ dependencies:
- fonttools=4.56.0=py312h3520af0_0
- fortran-compiler=1.9.0=h02557f8_0
- fplll=5.5.0=h6ede486_0
- fpylll=0.6.2=py312hfffdf69_0
- fpylll=0.6.3=py312hfffdf69_0
- freetype=2.13.3=h40dfd5c_0
- furo=2024.8.6=pyhd8ed1ab_2
- gap-core=4.14.0=hb9686a1_2
2 changes: 1 addition & 1 deletion environment-3.12-macos.yml
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ dependencies:
- fonttools=4.56.0=py312h998013c_0
- fortran-compiler=1.9.0=h5692697_0
- fplll=5.5.0=h2a2278a_0
- fpylll=0.6.2=py312h03fe13c_0
- fpylll=0.6.3=py312h03fe13c_0
- freetype=2.13.3=h1d14073_0
- furo=2024.8.6=pyhd8ed1ab_2
- gap-core=4.14.0=h25f1785_2
2 changes: 1 addition & 1 deletion pkgs/sage-conf/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sage-conf_conda/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sage-conf_pypi/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sage-docbuild/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sage-setup/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sage-sws2rst/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sagemath-bliss/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sagemath-categories/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sagemath-coxeter3/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sagemath-environment/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sagemath-mcqd/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sagemath-meataxe/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sagemath-objects/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sagemath-repl/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sagemath-sirocco/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pkgs/sagemath-tdlib/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ dependencies = [
'ipykernel >=5.2.1',
'jupyter-client',
'ipywidgets >=7.5.1',
'fpylll >=0.5.9',
'fpylll >=0.6.3',
'ptyprocess > 0.5',
# TODO: Remove this once the migration to meson is complete
'pkgconfig'
2 changes: 1 addition & 1 deletion src/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.6.rc0
10.6.rc1
6 changes: 3 additions & 3 deletions src/bin/sage-version.sh
Original file line number Diff line number Diff line change
@@ -4,6 +4,6 @@
# which stops "setup.py develop" from rewriting it as a Python file.
:
# This file is auto-generated by the sage-update-version script, do not edit!
SAGE_VERSION='10.6.rc0'
SAGE_RELEASE_DATE='2025-03-22'
SAGE_VERSION_BANNER='SageMath version 10.6.rc0, Release Date: 2025-03-22'
SAGE_VERSION='10.6.rc1'
SAGE_RELEASE_DATE='2025-03-27'
SAGE_VERSION_BANNER='SageMath version 10.6.rc1, Release Date: 2025-03-27'
60 changes: 46 additions & 14 deletions src/sage/matrix/matrix_integer_dense.pyx
Original file line number Diff line number Diff line change
@@ -2729,7 +2729,7 @@ 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):
use_givens=False, precision=0, proof=None, transformation=False, **kwds):
"""
Return the result of running Block Korkin-Zolotarev reduction on
``self`` interpreted as a lattice.
@@ -2795,6 +2795,8 @@ cdef class Matrix_integer_dense(Matrix_dense):
- ``precision`` -- (default: ``0`` for automatic choice) bit
precision to use if ``fp='rr'`` is set

- ``transformation`` -- boolean (default: ``False``); also return transformation

- ``**kwds`` -- keywords to be passed to :mod:`fpylll`; see
:class:`fpylll.BKZ.Param` for details

@@ -2821,6 +2823,13 @@ cdef class Matrix_integer_dense(Matrix_dense):
[ 2 1 0]
[-1 1 3]

We return the transformation matrix::

sage: A = random_matrix(ZZ, 10, 20)
sage: R, U = A.BKZ(transformation=True)
sage: U * A == R
True

ALGORITHM:

Calls either NTL or fpLLL.
@@ -2859,48 +2868,59 @@ cdef class Matrix_integer_dense(Matrix_dense):
raise TypeError("fp parameter not understood.")

A = self._ntl_()
UNTL = None
if transformation:
import sage.libs.ntl.ntl_mat_ZZ
_I = matrix_space.MatrixSpace(ZZ, self.nrows()).identity_matrix()
UNTL = sage.libs.ntl.ntl_mat_ZZ.ntl_mat_ZZ(self.nrows(),
self.nrows(), _I.list())

if algorithm == "BKZ_FP":
if not use_givens:
r = A.BKZ_FP(U=None, delta=delta, BlockSize=block_size,
r = A.BKZ_FP(U=UNTL, delta=delta, BlockSize=block_size,
prune=prune, verbose=verbose)
else:
r = A.G_BKZ_FP(U=None, delta=delta, BlockSize=block_size,
r = A.G_BKZ_FP(U=UNTL, delta=delta, BlockSize=block_size,
prune=prune, verbose=verbose)

elif algorithm == "BKZ_QP":
if not use_givens:
r = A.BKZ_QP(U=None, delta=delta, BlockSize=block_size,
r = A.BKZ_QP(U=UNTL, delta=delta, BlockSize=block_size,
prune=prune, verbose=verbose)
else:
r = A.G_BKZ_QP(U=None, delta=delta, BlockSize=block_size,
r = A.G_BKZ_QP(U=UNTL, delta=delta, BlockSize=block_size,
prune=prune, verbose=verbose)

elif algorithm == "BKZ_QP1":
if not use_givens:
r = A.BKZ_QP1(U=None, delta=delta, BlockSize=block_size,
r = A.BKZ_QP1(U=UNTL, delta=delta, BlockSize=block_size,
prune=prune, verbose=verbose)
else:
r = A.G_BKZ_QP1(U=None, delta=delta, BlockSize=block_size,
r = A.G_BKZ_QP1(U=UNTL, delta=delta, BlockSize=block_size,
prune=prune, verbose=verbose)

elif algorithm == "BKZ_XD":
if not use_givens:
r = A.BKZ_XD(U=None, delta=delta, BlockSize=block_size,
r = A.BKZ_XD(U=UNTL, delta=delta, BlockSize=block_size,
prune=prune, verbose=verbose)
else:
r = A.G_BKZ_XD(U=None, delta=delta, BlockSize=block_size,
r = A.G_BKZ_XD(U=UNTL, delta=delta, BlockSize=block_size,
prune=prune, verbose=verbose)

elif algorithm == "BKZ_RR":
if not use_givens:
r = A.BKZ_RR(U=None, delta=delta, BlockSize=block_size,
r = A.BKZ_RR(U=UNTL, delta=delta, BlockSize=block_size,
prune=prune, verbose=verbose)
else:
r = A.G_BKZ_RR(U=None, delta=delta, BlockSize=block_size,
r = A.G_BKZ_RR(U=UNTL, delta=delta, BlockSize=block_size,
prune=prune, verbose=verbose)

self.cache("rank",ZZ(r))

if transformation:
U = self.new_matrix(self.nrows(), self.nrows(),
entries=[ZZ(z) for z in UNTL.list()])

R = <Matrix_integer_dense>self.new_matrix(
entries=[ZZ(z) for z in A.list()])

@@ -2929,12 +2949,23 @@ cdef class Matrix_integer_dense(Matrix_dense):
kwds["auto_abort"] = True

A = IntegerMatrix.from_matrix(self)
BKZ.reduction(A, BKZ.Param(block_size=block_size, delta=delta, **kwds),
Ufplll = None
if transformation:
_I = matrix_space.MatrixSpace(ZZ, self.nrows()).identity_matrix()
Ufplll = IntegerMatrix.from_matrix(_I)
BKZ.reduction(A,
BKZ.Param(block_size=block_size, delta=delta, **kwds),
U=Ufplll,
float_type=fp_,
precision=precision)

R = A.to_matrix(self.new_matrix())
return R
if transformation:
U = Ufplll.to_matrix(self.new_matrix(Ufplll.nrows, Ufplll.ncols))
if transformation:
return R, U
else:
return R

def LLL(self, delta=None, eta=None, algorithm='fpLLL:wrapper', fp=None, prec=0, early_red=False, use_givens=False, use_siegel=False, transformation=False, **kwds):
r"""
@@ -3260,7 +3291,8 @@ cdef class Matrix_integer_dense(Matrix_dense):
A = IntegerMatrix.from_matrix(self)
Ufplll = None
if transformation:
Ufplll = IntegerMatrix(A.nrows, A.nrows)
_I = matrix_space.MatrixSpace(ZZ, self.nrows()).identity_matrix()
Ufplll = IntegerMatrix.from_matrix(_I)

method = algorithm.replace("fpLLL:","")
if verb:
6 changes: 6 additions & 0 deletions src/sage/matrix/matrix_rational_dense.pyx
Original file line number Diff line number Diff line change
@@ -2930,13 +2930,19 @@ cdef class Matrix_rational_dense(Matrix_dense):
[ 1/28 -1/40 -1/18]
[ 1/28 -1/40 1/18]
[-1/14 -1/40 0]
sage: L, U = A.BKZ(transformation=True)
sage: U * A == L
True

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()
if kwargs.get('transformation', False):
L, U = A.BKZ(*args, **kwargs)
return L / d, U
return A.BKZ(*args, **kwargs) / d

def LLL(self, *args, **kwargs):
6 changes: 3 additions & 3 deletions src/sage/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Sage version information for Python scripts
# This file is auto-generated by the sage-update-version script, do not edit!
version = '10.6.rc0'
date = '2025-03-22'
banner = 'SageMath version 10.6.rc0, Release Date: 2025-03-22'
version = '10.6.rc1'
date = '2025-03-27'
banner = 'SageMath version 10.6.rc1, Release Date: 2025-03-27'