-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Finite Field Types and Conversion to SageMath #50
Comments
I am sure that we would, but can you be a bit more explicit about what it is that you would like to add? I'm not familiar with the references to Sage features so references to Flint features/types/functions are easier (for me) to understand. Python-flint already has |
I shouldn't comment so late at night. Looking at this now I see obviously you mean finite fields like Absolutely it would be good to expose those in python-flint but we need to consider exactly what the interface should be. As for multivariate polynomials the question for finite fields is how to represent the context object in python-flint and what the user interface should be for creating the context and then for creating polynomials and matrices over that field. I also wonder to what extent it makes sense for python-flint's interface to parallel the Flint interface as a low level wrapper or whether it is better to try to develop a more Python-style interface that can smooth over some of the internal details of exactly which representation or algorithm is being used. For example at the C level it clearly makes sense to distinguish between |
I discuss the context issue in gh-53 in more general terms. I don't think it is necessary to solve all the problems mentioned there just to get finite fields added in python-flint but the ideas there are worth considering when designing how Flint contexts could be wrapped for finite fields. |
I am not aware of anyone working on adding finite fields. I recently met with David Einstein (not sure what his GitHub moniker is) who is working on adding multivariate polynomials like
Um... not really. I guess there could be some discussion about exactly how the contexts should work but otherwise generally following the existing design of python-flint's current types is a good guideline. Tests and documentation should be added. If you have any questions about how to build python-flint or get a development environment set up then ask here. |
Hey, sorry for being slow to reply over the weekend. Yes, I was thinking at first just trying to get As for the interface, I think what you suggest is very sensible. For example, we could implement a single This would store things such as the characteristic, the modulus of the extension (if there is one) etc. Then, if the characteristic is small enough, then functions built from Then, building a
This is quite similar to what you suggest with
Then, if a Then, elements of the polynomial ring I'll keep thinking about this and also try and read more of the flint documentation, but for the next few weeks I'll be busy either working or on vacation so will make slower than usual progress. |
Thinking about For now though I think that the best thing would be to just forget about A higher level interface like At that level probably the context object should just have the same name as it does in Flint so it ends up being: from flint import *
ctx = fq_nmod_ctx(163, 2, "y")
p = fq_nmod_poly([1, 2, 3], ctx) I think that just exposing Flint's functionality in this relatively raw way is the quickest way to make something usable. Designing a higher-level interface is something that needs to be thought through more completely. Implementing the higher-level interface is also something that can be done very easily once the lower level pieces are there e.g. if we want |
Ahh yes, ok. So for At a selfish level, I need Edit: cloned the repo and successfully built |
Also I imagined that if I imagine that you will find that once you have added one type it will be a lot easier to add more. Especially in the cases like To add class nmod_base:
...
def __add__(self, other):
# all the tedious coercion etc logic here
return self._add(other)
class nmod(nmod_base):
cdef nmod_t val
cdef _add(nmod self, nmod other):
# Call the actual C functions here Then for class fmpz_mod(nmod_base):
cdef fmpz_mod_t val
cdef _add(fmpz_mod self, fmpz_mod other):
# Call different C functions The same approach can be used for all |
Yeah I have a heavy bias to large characteristic because I'm often writing proof of concept cryptographic code, but this is certainly niche and the Agree re: |
I guess so for now. I discussed scraping the flint headers in gh-54. In general it would be better to refactor some things so feel free to come up with a better design if you want. Don't feel that you need to do that just to get some new types in though. Also the use of include here causes problems (gh-15): python-flint/src/flint/pyflint.pyx Lines 296 to 325 in 99fa557
Code coverage testing does not work for example (without patching Cython - see bin/coverage.sh ).
|
Thought this was interesting: sage: p = random_prime(2**64)
sage: F = GF(p)
sage: a = F.random_element()
sage: b = F.random_element()
sage:
sage: %timeit a*b
182 ns ± 3.52 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
sage:
sage: apy, bpy = int(a), int(b)
sage: ppy = int(p)
sage:
sage: %timeit (apy * bpy) % ppy
181 ns ± 4.27 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
sage:
sage: from flint import nmod
sage: af = nmod(apy, ppy)
sage: bf = nmod(bpy, ppy)
sage:
sage: %timeit af * bf
47.2 ns ± 0.723 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each) Seems really motivating for me to then keep working on these things for future projects |
We have finite field scalars and univariate polynomials now after gh-182 and gh-97. These are based on Looking at the headers in the flint docs for
We have all of these except There is no An alternative could be to use So the situation for finite fields will be a big improvement in python-flint 0.7.0. It would be good to have matrices which could be added fairly easily now if anyone is interested. Perhaps for multivariate polynomials The title of this issue mentions conversions to SageMath. Is that something that still needs doing somehow? |
I think this isn't something we need to do now and is a remnant of my lack of understanding about the project originally.
I agree this is the obvious next think to add. It should be very very similar to the
I think the |
Hi!
I've been working on some projects recently where the majority of my work is python, but I'm calling to SageMath to get the polynomial rings of finite fields, which currently uses the NTL bindings.
I'm really interested in instead experimenting with flint, for a variety of reasons, and the two main options I see are:
PolynomialRing
to also allow flint implementations by writing new bindings within Sagepython-flint
and try and help cross off some TODO from your README by implementing the bindings for finite field types etc.Because the SageMath Polynomial Ring classes are wildly out of control, option two feels much more manageable and I was wondering whether the python-flint team would be interested in having these features added.
Also, if I was to start, is anyone else is interested in working on this or is there some partial progress? Are there guidelines I should follow if I was to try and add new features?
The text was updated successfully, but these errors were encountered: