On Sun, 5 Nov 2023 at 15:04, T-Rex <[email protected]> wrote: > > According to https://oscarbenjamin.github.io/blog/czi/post2.html sympy > now has LLL, but when I consulted the sympy documentation I could not find > actual commands that produces an LLL-reduced basis.
SymPy has a new matrix type called DomainMatrix for which the LLL-algorithm is implemented. Ideally the LLL-algorithm would be exposed through the ordinary Matrix type but it is not. The DomainMatrix.lll method is documented here: https://docs.sympy.org/latest/modules/polys/domainmatrix.html#sympy.polys.matrices.domainmatrix.DomainMatrix.lll Starting with an ordinary Matrix M the command to get an LLL-reduced basis in SymPy 1.12 is: In [1]: from sympy.polys.matrices import DomainMatrix In [2]: M = randMatrix(5) # make a random 5x5 Matrix In [3]: M Out[3]: ⎡74 3 71 3 27⎤ ⎢ ⎥ ⎢86 74 14 89 26⎥ ⎢ ⎥ ⎢58 2 14 54 17⎥ ⎢ ⎥ ⎢35 53 17 58 31⎥ ⎢ ⎥ ⎣72 83 33 61 85⎦ In [4]: dM = DomainMatrix.from_Matrix(M) # Convert to DomainMatrix In [5]: dM.lll().to_Matrix() # Compute LLL-basis and convert back to Matrix Out[5]: ⎡ 7 -19 17 23 22⎤ ⎢ ⎥ ⎢51 21 -3 31 -5⎥ ⎢ ⎥ ⎢-23 51 3 4 14⎥ ⎢ ⎥ ⎢53 -2 -4 -24 18⎥ ⎢ ⎥ ⎣-14 -24 -58 -4 13⎦ In SymPy 1.13 there will be a to_DM() method to make this a bit easier so it is just: M.to_DM().lll().to_Matrix() Ideally we should add an .lll() method directly to Matrix to do this without users needing to perform the conversion explicitly. Also SymPy 1.13 will be able to use python-flint for this. If you have python-flint installed (pip install python-flint) and then set the environment variable SYMPY_GROUND_TYPES=flint then the DomainMatrix.lll method will automatically use Flint which is a lot faster for this operation. -- Oscar -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxQ53qHTttMcGjBEED6TqXR57FDLew4jbQXtLBdqtQ58zQ%40mail.gmail.com.
