Re: [sympy] LLL and sympy
On Sun, Nov 5, 2023 at 8:22 PM T-Rex wrote: > > Thanks @oscar! I didn't think I would get a reply from the blog's owner :-) > > Re setting of the environment variable SYMPY_GROUND_TYPES=flint: (1) Would > that be in conflict with other parts of sympy/numpy/scipy? (2) After it is > set to flint, is there a way to turn it back to the default? I can see > scenarios where I need to bench mark various options, and it would be really > nice to be able to change the flag as I go along in my jupyter notebook, as > oppsed to restarting the program from scratch. NumPy, SciPy, and other libraries do not use flint, only SymPy. Other parts of SymPy do use flint, but it's all completely transparent. The only difference is the output. Right now, there's no way to change the option after SymPy is imported, which is why it is set as an environment variable. So if you want to test different things, you'll have to restart the notebook. > > Taboo question: When might Sympy 1.13 be coming out? I am know that such > questions are taboo, but my project has various stages/steps, and depending > on the availability of 1.1.3 I might want to work on the LLL-parts first > while waiting for 1.1.3 to become available. There's no reason to not ask this question. And anyways, Oscar mentioned to me that he wants to make a release soon so (hopefully) it should be out before the end of the year, if not month. Aaron Meurer > > MANY THANKS for your help and advice. > > On Sunday, November 5, 2023 at 10:23:54 AM UTC-5 Oscar wrote: >> >> On Sun, 5 Nov 2023 at 15:04, T-Rex 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 sympy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/54713a7c-886f-46dd-965e-0e288e61d901n%40googlegroups.com. -- 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 sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6LAkNZFfd3QqaMMjreAH2YqYWpPC-%2B6Eg8627As_R1i5A%40mail.gmail.com.
Re: [sympy] LLL and sympy
Thanks @oscar! I didn't think I would get a reply from the blog's owner :-) Re setting of the environment variable SYMPY_GROUND_TYPES=flint: (1) Would that be in conflict with other parts of sympy/numpy/scipy? (2) After it is set to flint, is there a way to turn it back to the default? I can see scenarios where I need to bench mark various options, and it would be really nice to be able to change the flag as I go along in my jupyter notebook, as oppsed to restarting the program from scratch. Taboo question: When might Sympy 1.13 be coming out? I am know that such questions are taboo, but my project has various stages/steps, and depending on the availability of 1.1.3 I might want to work on the LLL-parts first while waiting for 1.1.3 to become available. MANY THANKS for your help and advice. On Sunday, November 5, 2023 at 10:23:54 AM UTC-5 Oscar wrote: > On Sun, 5 Nov 2023 at 15:04, T-Rex 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 sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/54713a7c-886f-46dd-965e-0e288e61d901n%40googlegroups.com.
Re: [sympy] LLL and sympy
On Sun, 5 Nov 2023 at 15:04, T-Rex wrote: > > According to https://oscarbenjamin.github.io/blog/czi/post2.htmlsympy > 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 5134 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 sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxQ53qHTttMcGjBEED6TqXR57FDLew4jbQXtLBdqtQ58zQ%40mail.gmail.com.
[sympy] LLL and sympy
Greetings from a sympy newbie. I have used other symboic algebra packages like pari-gp, and I'll teaching myself python and sympy now. According to https://oscarbenjamin.github.io/blog/czi/post2.htmlsympy now has LLL, but when I consulted the sympy documentation I could not find actual commands that produces an LLL-reduced basis. I'm a newbie so mostly I overlooked something obvious; I'd be most appreciative for your help and references. And if this is not the correct avenue for posting such questions, apologies and please let me know where I should post my questions. I know that I can do this in e.g. sage, but for now I'd like to stick to standard python/sympy. Thanks for your help and for making available this amazing package! -- 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 sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/6fd2530a-5c3d-48df-b651-ad398404ea01n%40googlegroups.com.