On Mon, 6 Nov 2023 at 03:22, T-Rex <
call...@gmail.com> 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.
It is not possible to do this. It would not be easy to make it work
because using flint for the ground types changes many things starting
with the representation of the lowest level domain types like ZZ, QQ
and GF(p).
There are ways to test the speed of the different representations
though by using explicit conversions between the low-level SDM, DDM
and DFM matrix types:
In [23]: M = randMatrix(50) # 50x50 matrix of 2-digit integers
In [24]: dM = M.to_DM() # DomainMatrix
In [25]: dMd = dM.rep.to_ddm() # internal dense domain matrix rep
In [26]: dMf = dM.rep.to_dfm() # internal dense flint matrix rep
In [27]: %time ok = dMd.lll() # time for SymPy implementation
CPU times: user 1.01 s, sys: 6.95 ms, total: 1.02 s
Wall time: 1.13 s
In [28]: %time ok = dMf.lll() # time when using flint
CPU times: user 18.4 ms, sys: 3.93 ms, total: 22.3 ms
Wall time: 184 ms
The two are not exactly equal because the Flint algorithm is different:
In [34]: dMd.lll() == dMf.lll().to_ddm()
Out[34]: False
There is discussion about the differences in the original pull request
that added LLL:
https://github.com/sympy/sympy/pull/24572
The SymPy implementation uses "classic" LLL with all exact arithmetic
and only has the parameter delta. The Flint version I assume uses
partially approximate arithmetic and has two parameters delta and eta.
I am not sure how exactly to make the output of the Flint version
precisely equal to what the SymPy implementation would return.
Note that you can also use python-flint directly to test what it returns:
In [35]: import flint
In [36]: M = flint.fmpz_mat([[1, 2], [3, 4]])
In [38]: M.lll()
Out[38]:
[1, 0]
[0, 2]
You can see the python-flint code for this method here although it is
calling into Flint for the actual algorithms:
https://github.com/flintlib/python-flint/blob/33e5485bda16339eb334c816639e22e57c4658e2/src/flint/types/fmpz_mat.pyx#L613-L654
The SymPy implementation of the algorithm is here:
https://github.com/sympy/sympy/blob/master/sympy/polys/matrices/lll.py
> Taboo question:  When might Sympy 1.13 be coming out?
Soon, but I am not sure exactly when. There are some issues to be
resolved such as whether or not to use python-flint automatically
rather than requiring the SYMPY_GROUND_TYPES=flint to be set
explicitly.
>  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.
It is very easy to install the current development version of SymPy
(future 1.13) right now if you want to test it out:
pip install git+
https://github.com/sympy/sympy.git
I don't anticipate any changes to the LLL code between now and the
1.13 release except that I might try to add the lll method to Matrix
so that it is not necessary to convert to DomainMatrix explicitly.
Anyone else is also welcome to send a PR to that effect. It would also
be good to add the interface for Hermite and Smith normal forms. Those
are implemented for DomainMatrix but not provided as methods and the
code is not there to call through to flint when available.
--
Oscar