Add Groebner basis related functions for fmpz_mpoly_vec#191
Add Groebner basis related functions for fmpz_mpoly_vec#191oscarbenjamin merged 6 commits intoflintlib:masterfrom
Conversation
|
Thanks for such a detailed reply! Funny you say this because this is exactly what I'm currently working on measuring but with profiling and more benchmarks over (some of) the PHCpack database of polynomial systems. I'm making use of the functions added in this PR and thought best to just upstream them. |
|
Have you tried anything else besides SymPy and python-flint in your benchmarks? I would be interested to know how these things compare for asymptotic scaling like if there are any systems that can go a lot higher than SymPy can. Note that a 20x speedup in this area might sound like a lot but it also potentially doesn't by you much like maybe you can go from |
Not on these benchmarks in particular. I compared sympys dmp_python, python-flint, and Mathematica a while back with gcd and factoring on a rather pathological polynomial (5 generators, 18k terms, 6mb in text form) and both python-flint and Mathematica beat sympy by about 280x (~100ms compared to ~29s). I've attempted to get access to Maple but my university denied my application for a license.
As would I, I'm not aware of any personally |
That doesn't surprise me. It is possible that Mathematica actually uses Flint for this. You should probably expect a good algorithm well implemented in pure Python in SymPy to be at least 20x slower than Flint anyway but also different algorithms make a big difference in different cases. It is probably not difficult to make some basic improvements to this in SymPy but the main thing is that you need a few different algorithms and good heuristics for choosing between them. I am sure that there are cases where the difference is a lot worse than 280x slower. |
|
Sage wraps a bunch of different libraries. I assume it has several different implementations and algorithms for computing Groebner bases although I don't know how you can choose between them. The docs claim that Singular is mostly used and that
|
|
msolve is another library which is supported by sagemath, which was added mroe recently: https://doc.sagemath.org/html/en/reference/polynomial_rings/sage/rings/polynomial/msolve.html I think the "winner" of CAS for these computations is Magma, which is very sad as it's closed source so all the magic is essentially hidden behind licenses. |
|
I've just turned the doc examples and the example shown here into tests as well as add equality comparison. |
|
I'll mark this as ready for review, CI should pass |
Thank you both, I will check those out. |
|
I left a few comments but we can just merge if you prefer. |
As a total aside, would you be interested in adding some linting to the CI? I think something like https://docs.astral.sh/ruff/ (ruff) has been designed to work with cython (indeed, they measure performance against the cython repository). If we decided on some config then we could quite easily automatically format with |
That's fine by me if others are happy with it. I haven't used ruff much and didn't realise that it works on Cython. If you run ruff now does it completely transform the entire codebase? Perhaps a first step would be to use ruff's checking functionality rather than the auto-formatting part. Does it reveal any errors? It might need some configuration to limit things like reformatting auto-generated files. |
|
I just checked and it indeed finds some small things. I have a few minutes now, let me run |
|
For formatting, maybe cython still isn't supported, but at least the linter is For cython formatting, I don't know what's best, but there must be some kind of solution... |
There might not be. Cython is not such a mainstream language as Python is. Some basic linting would be good though. |
I don't believe there to be. Theres cython-lint which can catch common errors, unused variables/imports, and line lengths but it can't format. It's what I use and have a small config in But it can do a bit more that just that. |
It sounds like we're all on board with using a linter then so maybe we should just commit it. Or would it throw up the whole codebase? |
It does indeed, I get ~1200 lines of warnings from with this config [tool.cython-lint]
max-line-length = 120
ignore = ['E225', 'E231']most of which are line length warnings (~800). |
|
I think we at least want this in the config: Those files are all automatically generated and have long lines. It is not worth trying to format the auto-generated code nicely I think. That brings the number of complaints down to about 500 already. Of those E501 (line too long) is only 35 lines. Reducing the line length limit to 88 gives 480 lines too long though. There are 73 E701 which is multiple statements on one line like: I prefer to see this split onto multiple lines myself but don't have strong feelings about it. There are 57 W605 (invalid escape sequence). This is something like: That is a valid complaint: it should be a raw string for embedded LaTeX. Many of the complaints are about whitespace and indentation which I think are mostly reasonable although I haven't looked through what it wants for indentation. There are also a lot of complaints about things being defined or imported but not being used anywhere which definitely seem like reasonable complaints to me. The only fixer it has is apparently changing single quote to double quotes which seems like the least useful kind of fixer. It should be trivially possible to implement fixers for things like Maybe we can just add something: #!/usr/bin/env python
# bin/strip_whitespace.py
from pathlib import Path
def clean(filename):
with open(filename) as fin:
lines = fin.readlines()
lines = [line.rstrip() + '\n' for line in lines]
while lines and lines[-1] == "\n":
lines.pop()
with open(filename, 'w') as fout:
fout.writelines(lines)
src_dir = Path('src')
for root, dirs, files in src_dir.walk():
for file in files:
path = root / file
if path.suffix in ('.py', '.pyx', '.pxd'):
clean(path)That script removes 50 of the complaints from current code. |
|
Okay, looks good to me. Thanks! |

Actual tests (only doctests present) are missing currently only because it is late here, I'll write some up tomorrow.
I'm not entirely confident with Groebner bases, so I've lifted the Groebner, auto-reduction, and BuckBerger examples from Wikipedia, and used similar polynomials in the S-poly and
reduction_primitive_partexamples, though they may not be motivating.