Skip to content

Commit

Permalink
sort vectors by lattice norm AND the vector
Browse files Browse the repository at this point in the history
  • Loading branch information
grhkm21 committed Aug 21, 2024
1 parent c707255 commit 4c18be7
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/sage/modules/free_quadratic_module_integer_symmetric.py
Original file line number Diff line number Diff line change
Expand Up @@ -1538,12 +1538,12 @@ def _fplll_enumerate(self, target=None):
sage: t = vector([1.2, -3/11, 5.5, -9.1])
sage: short = L.enumerate_short_vectors() # implicit doctest
sage: vecs = [next(short) for _ in range(10)]
sage: sorted(vecs, key=lambda v: L(v).inner_product(L(v)))
[(0, 0, 0, 1), (0, 0, 1, 1), (0, 1, 1, 1), (1, 1, 1, 1), (0, 0, 1, 0),
(1, 1, 1, 0), (0, 1, 1, 0), (0, 1, 0, 0), (1, 1, 0, 0), (1, 0, 0, 0)]
sage: sorted(vecs, key=lambda v: (L(v).inner_product(L(v)), v))
[(0, 0, 0, 1), (0, 0, 1, 0), (0, 0, 1, 1), (0, 1, 0, 0), (0, 1, 1, 0),
(0, 1, 1, 1), (1, 0, 0, 0), (1, 1, 0, 0), (1, 1, 1, 0), (1, 1, 1, 1)]
sage: close = L.enumerate_close_vectors(t) # implicit doctest
sage: vecs = [next(close) for _ in range(10)]
sage: sorted(vecs, key=lambda v: L(v).inner_product(L(v)))
sage: sorted(vecs, key=lambda v: (L(v).inner_product(L(v)), v))
[(1, 0, 6, -8), (1, 0, 5, -9), (2, 0, 5, -9), (1, -1, 5, -9), (2, 1, 6, -9),
(1, 0, 6, -9), (2, 0, 6, -9), (1, 0, 5, -10), (1, -1, 6, -9), (1, -1, 5, -10)]
"""
Expand Down Expand Up @@ -1601,11 +1601,11 @@ def enumerate_short_vectors(self):
sage: L = IntegralLattice(4, [[1,2,3,4], [7,7,8,8], [1,-1,1,0]])
sage: short = L.enumerate_short_vectors()
sage: vecs = [next(short) for _ in range(20)]
sage: sorted(vecs, key=lambda v: L(v).inner_product(L(v)))
sage: sorted(vecs, key=lambda v: (L(v).inner_product(L(v)), v))
[(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)]
(3, 2, -2, -4), (4, 4, 1, 0), (-1, 4, 1, 4), (3, 5, 0, 0), (4, 1, -1, -4),
(2, 1, 4, 4), (2, 3, -3, -4), (5, 3, 2, 0), (2, 6, -1, 0), (5, 0, 0, -4),
(-2, 5, 0, 4), (4, -4, 4, 0), (1, 4, -4, -4), (6, 2, 3, 0), (3, 0, 5, 4)]
This example demonstrates that the lattice inner product is used for the norm::
Expand All @@ -1614,7 +1614,7 @@ def enumerate_short_vectors(self):
sage: L = IntegralLattice(Q, basis=B)
sage: short = L.enumerate_short_vectors()
sage: vecs = [next(short) for _ in range(20)]
sage: sorted(vecs, key=lambda v: L(v).inner_product(L(v)))
sage: sorted(vecs, key=lambda v: (L(v).inner_product(L(v)), v))
[(0, -2), (0, -4), (0, -6), (0, -8), (0, -10), (0, -12), (0, -14), (0, -16),
(0, -18), (0, -20), (0, -22), (0, -24), (0, -26), (0, -28), (0, -30), (-1, -1),
(-1, 1), (-1, -3), (-1, 3), (0, -32)]
Expand All @@ -1637,7 +1637,7 @@ def enumerate_close_vectors(self, target):
sage: t = vector([1/2, -133/7, 123.44, -11])
sage: close = L.enumerate_close_vectors(t)
sage: vecs = [next(close) for _ in range(10)]
sage: sorted(vecs, key=lambda v: L(v).inner_product(L(v)))
sage: sorted(vecs, key=lambda v: (L(v).inner_product(L(v)), v))
[(-1, -16, 121, 148), (0, -17, 122, 148), (-3, -22, 122, 148), (1, -18, 123, 148), (-2, -23, 123, 148),
(2, -19, 124, 148), (3, -20, 125, 148), (4, -21, 126, 148), (-3, -19, 124, 152), (-2, -20, 125, 152)]
"""
Expand Down

0 comments on commit 4c18be7

Please sign in to comment.