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

expose fplll enumeration routines in IntegralLattice #38492

Merged

Conversation

yyyyx4
Copy link
Member

@yyyyx4 yyyyx4 commented Aug 9, 2024

This is useful for situations where we'd like to iterate over short-ish or close-ish vectors without necessarily requiring the shortest/closest solution, and without knowing a priori how many vectors we need to try. Among other things, it shows up in some algorithms for solving (quaternion) norm equations.

@yyyyx4
Copy link
Member Author

yyyyx4 commented Aug 9, 2024

(Cc: @GiacomoPope)

basis = L.basis_matrix()

import fpylll
gmat = fpylll.IntegerMatrix(dim, dim)
Copy link
Contributor

@GiacomoPope GiacomoPope Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's the IntegerMatrix.from_matrix() method, could you not do

gmat = fpyll.IntegerMatrix.from_matrix(gram)
gso = fpylll.GSO.Mat(gmat, gram=True)

Copy link
Contributor

@GiacomoPope GiacomoPope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some very small comments which could be ignored. Thank you for adding this to Sage, I should have done it ages ago.

coord = None
if target is not None:
coord = basis.solve_left(target)
Mu = 1 + matrix([gso.get_mu(i,j) for j in range(dim)] for i in range(dim))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a to_matrix() method, so something like:

Mu = 1 + matrix(gso.to_matrix())

might work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work for me https://sagecell.sagemath.org/?q=yduvls (10.3)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh for the MatGSO type it's the property .gso.G

Mu = 1 + matrix(gso.G)

https://sagecell.sagemath.org/?q=qifgtc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahha yes. I think this should be added before it's merged, seems quicker :-)

if len(combs) < count:
bound *= 2
continue
for length,comb in combs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for length,comb in combs:
for length, comb in combs:

Copy link

github-actions bot commented Aug 9, 2024

Documentation preview for this PR (built with commit f2c4e22; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@yyyyx4
Copy link
Member Author

yyyyx4 commented Aug 10, 2024

Thanks for the reviews! I think this is now already in the process of getting merged. Perhaps your suggested changes would best be done as a (small) follow-up?

@GiacomoPope
Copy link
Contributor

Sure I'll make a PR for those two. It's essentially meaningless tho!

@vbraun vbraun merged commit b178c10 into sagemath:develop Aug 10, 2024
25 of 27 checks passed
@mkoeppe mkoeppe added this to the sage-10.5 milestone Aug 10, 2024
@yyyyx4 yyyyx4 deleted the public/enumeration_for_integral_lattices branch August 10, 2024 21:56
@jhpalmieri
Copy link
Member

This seems to be causing doctest failures for me on OS X 14.6:

sage -t --random-seed=64986521010388899927548704615315435332 src/sage/modules/free_quadratic_module_integer_symmetric.py
**********************************************************************
File "src/sage/modules/free_quadratic_module_integer_symmetric.py", line 1544, in sage.modules.free_quadratic_module_integer_symmetric.FreeQuadraticModule_integer_symmetric._fplll_enumerate
Failed example:
    [next(close) for _ in range(10)]
Expected:
    [(1, 0, 6, -9), (1, -1, 5, -9), (2, 0, 6, -9), (1, 0, 5, -9), (1, -1, 5, -10),
     (2, 1, 6, -9), (1, 0, 5, -10), (2, 0, 5, -9), (1, 0, 6, -8), (1, -1, 6, -9)]
Got:
    [(1, 0, 6, -9),
     (1, -1, 5, -9),
     (2, 0, 6, -9),
     (1, 0, 5, -9),
     (1, -1, 5, -10),
     (2, 1, 6, -9),
     (1, 0, 5, -10),
     (1, 0, 6, -8),
     (2, 0, 5, -9),
     (1, -1, 6, -9)]
**********************************************************************
File "src/sage/modules/free_quadratic_module_integer_symmetric.py", line 1601, in sage.modules.free_quadratic_module_integer_symmetric.FreeQuadraticModule_integer_symmetric.enumerate_short_vectors
Failed example:
    [next(short) for _ in range(20)]
Expected:
    [(1, -1, 1, 0), (2, -2, 2, 0), (3, -3, 3, 0), (0, 3, 2, 4), (1, 2, 3, 4),
     (4, 4, 1, 0), (3, 2, -2, -4), (3, 5, 0, 0), (4, 1, -1, -4), (-1, 4, 1, 4),
     (2, 1, 4, 4), (5, 3, 2, 0), (2, 3, -3, -4), (2, 6, -1, 0), (5, 0, 0, -4),
     (-2, 5, 0, 4), (4, -4, 4, 0), (6, 2, 3, 0), (1, 4, -4, -4), (3, 0, 5, 4)]
Got:
    [(1, -1, 1, 0),
     (2, -2, 2, 0),
     (3, -3, 3, 0),
     (0, 3, 2, 4),
     (1, 2, 3, 4),
     (4, 4, 1, 0),
     (3, 2, -2, -4),
     (3, 5, 0, 0),
     (4, 1, -1, -4),
     (-1, 4, 1, 4),
     (2, 1, 4, 4),
     (5, 3, 2, 0),
     (2, 3, -3, -4),
     (5, 0, 0, -4),
     (2, 6, -1, 0),
     (-2, 5, 0, 4),
     (4, -4, 4, 0),
     (6, 2, 3, 0),
     (1, 4, -4, -4),
     (3, 0, 5, 4)]
**********************************************************************
2 items had failures:
   1 of   7 in sage.modules.free_quadratic_module_integer_symmetric.FreeQuadraticModule_integer_symmetric._fplll_enumerate
   1 of   4 in sage.modules.free_quadratic_module_integer_symmetric.FreeQuadraticModule_integer_symmetric.enumerate_short_vectors
    [238 tests, 2 failures, 3.93 s]

Can you please open up a follow-up to fix this?

@GMS103
Copy link
Member

GMS103 commented Aug 18, 2024

FWIW, here is what I get on Apple Silicon for make ptestlong (SageMath 10.5.beta2).

macOS 12.7.6: All tests passed!
macOS 13.6.9: This failure (among others).
macOS 14.6.1: This failure (among others).

@videlec
Copy link
Contributor

videlec commented Aug 18, 2024

Is the enumeration order relevant? The only difference in the output is the transposition of the two vectors (5, 0, 0, -4) and (2, 6, -1, 0).

@grhkm21
Copy link
Contributor

grhkm21 commented Aug 18, 2024

Yeah I don't think the output order is/should be deterministic for any reason. I can make a PR and add a sorted.

@grhkm21
Copy link
Contributor

grhkm21 commented Aug 18, 2024

Actually, since the norm of the vectors aren't necessarily non-decreasing, the first n outputs of the iterator might not be the same. So I think it's best to mark it #random.

vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 27, 2024
…andomness

    
Reported at
sagemath#38492 (comment) by
@jhpalmieri and @GMS103. Added an extra test because why not.
    
URL: sagemath#38524
Reported by: grhkm21
Reviewer(s): Lorenz Panny
vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 28, 2024
…andomness

    
Reported at
sagemath#38492 (comment) by
@jhpalmieri and @GMS103. Added an extra test because why not.
    
URL: sagemath#38524
Reported by: grhkm21
Reviewer(s): Lorenz Panny
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants