Closed GiacomoPope closed 1 month ago
the mul mod seems to not offer much speed up.
As far as I can tell all positive characteristic poly types have a mulmod function but in all cases it does literally just compute the multiplication followed by divrem apart from a minor optimisation to not bother with divrem if the degrees are small enough. In python-flint's case that would save a memory allocation over (f * g) % h
.
I expect that it is a little faster for very small polynomials by saving the allocation. Probably in the context of python-flint though any saving here really comes from reducing the general Python overhead though:
In [5]: ctx = fmpz_mod_poly_ctx(127)
In [6]: f = ctx([1, 2])
In [7]: g = ctx([3, 4])
In [8]: h = ctx([1, 2, 3])
In [9]: %timeit (f*g)%h
3.11 µs ± 154 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
In [10]: %timeit f.mulmod(g, h)
1.23 µs ± 3.54 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
A more important question is how useful these functions actually are. There are many functions in flint that make a lot of sense for Flint's internal use but are perhaps not so useful to a user of python-flint especially if it they are trivially implemented using the features already provided.
For each of these functions we should consider what it means for all other types like if we have mulmod for fmpz_mod_poly are we going to have it for fmpq_poly as well?
Ideally we add methods to each type in such a way that there is a consistent set of methods across the different types. Currently fmpz_mod_poly
has many more methods than the other poly types.
Currently fmpz_mod_poly has many more methods than the other poly types.
So my plan was to "finish" methods for this type and then use this as a start for fq_default_poly
and also updating nmod_poly
.
I'm happy to not include some of these methods, but you mentioned about the truncation ones in another PR so I threw them all in
my plan was to "finish" methods for this type and then use this as a start for
fq_default_poly
and also updatingnmod_poly
That seems reasonable.
For each operation now we need to consider if it makes sense for the other types though. Also we are probably already beginning to see diminishing returns from adding further methods to fmpz_mod_poly
.
The _trunc
and _mullow
etc methods are actually already exposed in some sense in python-flint because they are used in the series types. That doesn't mean we can't add them to the poly types as well though.
If you're happy with the methods available for fmpz_mod_poly as presented here in this PR my next contribution will be fq_default_poly
which will hopefully have all these features as well
This looks good. Thanks
my next contribution will be
fq_default_poly
Excellent!
This PR adds:
However, the output from
mul_high()
doesnt match my expectation... I'm not sure it's worth including, unless I'm being stupid.The truncate pow is definitely nice, the mul mod seems to not offer much speed up.