-
Notifications
You must be signed in to change notification settings - Fork 29
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
Interface for making an mpoly context #195
Comments
Another thing I notice is that there are no docs for the mpoly types: |
Thanks for your patience with this.
I agree, this would be a nicer interface for interacting with python-flint.
Completely agree, it is rather clunky at the moment, and is really just a holdover from the original mpoly PR. I'm looking at starting a revamp on this tonight, though I do have to shift focus to getting a POC of the mpoly types working well in SymPy soon.
I quite like this, nice and simple.
This should be easy to change. The built in
Yeah this is because of the type hints being enforced by Cython. It's not something that I've found spelled out the documentation in bold letters but the I believe the particular type hint was to specificy the argument should be both hashable and iterable. AFAIK this isn't supported by the In [2]: from collections.abc import Hashable, Iterable
In [3]: names: Hashable[Iterable[str]]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[3], line 1
----> 1 names: Hashable[Iterable[str]]
TypeError: type 'Hashable' is not subscriptable And an intersection type is not currently in python. There seems to be some effort on this though https://github.com/CarliJoy/intersection_examples. I don't think this is really an issue though as this will be hidden by the new interface. It will instead be
Agreed, there is nothing to "get" initially. Although |
Just found a minor inconsistency in the What I've found is that since the
|
I'm also looking at implementing some functions to make working with and between contexts a little nicer, in particular for the DMP_Flint integration in sympy. I'm planning on adding functions to increase/decrease the number of generators as well as an interface to the As flint separates generators and their names, I think python-flint could as well, eventually moving it to the "high level" domain interface, and the "low level" existing functions should only have to consider indices. For example from flint import ZZ
# generator names are designated here
R, [x, y] = ZZ.mpoly_ring(['x', 'y'])
# and the "low level" interface only requires specifying the number of variables.
ctx = fmpz_mpoly_ctx(2, order='lex') As it stands the contexts are identified by the One issue I see with this separation is that printing the low level types becomes a little cumbersome as the user would have to specify variable names, or some defaults would have to be used. I'm not sure how this could be solved without introducing wrapper types and printing machinery |
Yeah, maybe "get" is better. Neither is really accurate in all cases.
I would go the other way and add variable names to all univariate and multivariate polynomials at the low level. It is not just about printing but also conversions between different contexts when there are symbols. |
Yes, fair enough. To be clear though, the reason I haven't yet put out a release of python-flint even though lots of new features have been added is that I'm not sure about the call signature for constructing an mpoly context. If that is going to be changed then it should be changed before the next release. The other reason I haven't yet put out a release is because I imagine that the SymPy integration is going to result in some changes to the mpoly types/interface as well. In my mind the sequence is:
|
I think "get" works, it partially mirrors the |
I believe everything mentioned here other than the high level interface and context tools are implemented in the linked PR |
Closing after gh-225 |
CC @Jake-Moss
The idea of higher-level interfaces is discussed in gh-53. I would imagine that ultimately the usual way to create a multivariate polynomial would look something like:
Other options like monomial ordering could be keyword arguments.
In that sense we can think of the current interface as being sort of "low-level" but still I think it can be nicer than it is. This is currently the way to construct and use a multivariate polynomial context:
I think it is reasonable that the generators are not returned by default but the constructor syntax is awkward. It is redundant to specify the number of generators if we are already supplying a list of names. Also most of the time using lex as the default ordering is fine. I doubt many people will ever care about the monomial ordering.
It would be better to change it so that you can do
and get a lex ordered ring by default. I think it would be reasonable to say that the ordering parameter could be a keyword-only argument like:
Another problem is that the monomial ordering has to be passed as an enum which is also awkward e.g.:
It is reasonable to use these enums but it should be possible to just pass a string when calling the constructor. I think that a string should be displayed in the repr as well:
The reason that the first argument to the current constructor is an integer is because it is envisaged that you would do:
I think that a better way of handling that is to allow a symbol name to be a tuple of name and count e.g.:
The docstring for
fmpz_mpoly_ctx
says not to call it directly. I believe this is becauseget_context
manages a cache of contexts. That is reasonable but in that case I think that calling the constructor directly should give an error and then my comments above apply toget_context
as well.The interface for
get_context
is:Again I think that the argument are somewhat backwards in:
Ideally it should be
The name
get_context
is a bit confusing for a method that creates a new context. I would perhaps rename that tonew
like:Also the parameter names are strange because
names
plural is what is used when passing a single string andnametup
is what I would have naturally callednames
. Thetup
emphasises that it needs to be a tuple but really it should be okay to have a list here:I'm not sure we need the
names
andnametup
arguments at all though. This is how I think I would do it:Another option seen in SymPy is:
That looks nice in some situations but it is actually awkward when the number of symbols is a variable because you have to format it into a string:
Also I think it is better to keep things simple at this level and avoid any sort of string parsing.
The text was updated successfully, but these errors were encountered: