-
Notifications
You must be signed in to change notification settings - Fork 30
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
Initial bindings for generic rings #218
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I've just added the gr poly, mpoly and series types. This gives e.g. multivariate polynomials over the Gaussian integers: In [4]: from flint.types import _gr
In [5]: R = _gr.gr_gr_mpoly_ctx.new(_gr.gr_fmpzi_ctx, 2)
In [6]: R
Out[6]: gr_gr_mpoly_ctx(gr_fmpzi_ctx, 2, 0)
In [7]: R.gens_recursive()
Out[7]: [I, x1, x2]
In [8]: i, x1, x2 = R.gens_recursive()
In [9]: (x1 + x2 + i)**3
Out[9]: x1^3 + 3*x1^2*x2 + (3*I)*x1^2 + 3*x1*x2^2 + (6*I)*x1*x2 - 3*x1 + x2^3 + (3*I)*x2^2 - 3*x2 - I |
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This needs a lot more thought about how to design things but I thought it would be useful to put this up and maybe just merge as is on the basis that it is unstable/private.
The changes here are:
gr_*
types and functions.flint.types._gr
.gr
type that can represent the elements of any of the scalar contexts.What I haven't added are polynomials and matrices (
gr_mat
,gr_poly
,gr_mpoly
) and also series (gr_series
). I also haven't added many functions beyond arithmetic.I don't think that the design here is really exactly what we would want because it uses the same
gr
type at the Python level for everything (fmpz
,arb
, ...) whereas I think that we want these to be different types at the Python level with different methods/attributes. More work is needed to figure out the right design but I think it might be like this:gr_ctx
contexts and designed around the same structure as the generic rings code.gr_
functions could be made available in a base class from which non-generic types likefmpz
etc inherit.Introducing a context based interface provides an opportunity to change the interface of many things and to solve many problems simultaneously:
And of course the big one is that the generic rings code allows constructing new rings like a ring of matrices of multivariate polynomials etc.
I haven't added tests etc because I expect the design here to change a lot but I think it is worth just adding this as a private/unstable module so that people can test it out and we can work out the full design over time. I think that it would be worth fleshing this out with matrices, polynomials, special functions etc, figuring all the types, conversions and coercions and so on before making it "public". It can also be fine for people to use this as long as they understand that the interfaces are subject to change in future.
These are the scalar types that can be created through the generic system with this PR:
Note that some of these are just abstract classes e.g. there are no polynomials or matrices here. Some of these duplicate things that already exist like
fmpz
,nmod
etc.Some examples of things this allows that are not currently accessible through python-flint are:
Having contexts for all objects opens the possibility that it could be
R.gcd(2*a, 4*a)
or even that it could begcd(2*a, 4*a)
wheregcd
is a function that can find the context.