-
Notifications
You must be signed in to change notification settings - Fork 3
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
Exporting polynomials #1
Comments
+1 to polynomial ring import and export (at some point we will want to
handle the term order, but we can do without it for now).
Polynomials
Export
Any object p of class
sage.rings.polynomial.polynomial_element.Polynomial
is exported as
OMA(
OMS(sage.rings.polynomial.polynomial_element.Polynomial),
p.parent(),
p.dict()
)
where p.parent() is the polynomial ring and p.dict() returns the map
from exponent-tuples to coefficients.
+1; remains to decide whether to keep ETuples as keys of the
dictionary, or plain tuples of ints.
The symbol OMS(sage.rings.polynomial.polynomial_element.Polynomial),
is imported as the function lambda R, dict: ???
***@***.*** What is the canonical function to build a polynomial from a
polynomial ring and a dictionary of coefficients?
```
sage: R = PolynomialRing(QQ, 'x,y,z')
sage: p = R.random_element()
sage: p.dict()
{(0, 0, 0): -1/5, (0, 1, 1): -5, (1, 0, 1): 1}
sage: t = p.dict()
sage: R(t)
x*z - 5*y*z - 1/5
```
|
@nthiery I think you misunderstood the question about the canonical function to build a polynomial. I need a function f such that f(R, d) returns a polynomial in polynomial ring R with coefficient dictionary d. |
Sorry if I have not made my point clear. Up to curyfication, R is that function:
|
I've added the code as envisioned, but there are still some issues. Nicolas recommends hooking directly into the pickling. The necessary code would be
We should also double-check what common base class Sage polynomials have. I received different results at two different times. |
See also https://github.com/OpenDreamKit/MitM-Sage/blob/master/sage/Sage%20polynomials.ipynb
@nthiery Does the following make sense for importing/exporting polynomials?
Polynomial Rings
Export
Any object R of class
sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base or
sage.rings.polynomial.polynomial_ring.PolynomialRing_general
is exported as
OMA(
OMS(sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing),
R.base_ring(),
R.variable_names()
)
Import
Works directly, i.e., we apply PolynomialRing to base ring and variable names.
Polynomials
Export
Any object p of class sage.rings.polynomial.polynomial_element.Polynomial
is exported as
OMA(
OMS(sage.rings.polynomial.polynomial_element.Polynomial),
p.parent(),
p.dict()
)
where p.parent() is the polynomial ring and p.dict() returns the map from exponent-tuples to coefficients.
Import
The symbol OMS(sage.rings.polynomial.polynomial_element.Polynomial),
is imported as the function lambda R, dict: R(dict)
@nthiery What is the canonical function to build a polynomial from a polynomial ring and a dictionary of coefficients?Edit: added the functions according to Nicolas's answer.cc @tkw1536 @Jazzpirate
The text was updated successfully, but these errors were encountered: