Description
I've been struggling with some unexpected results in my computations with polynomials over the symbolic ring. Eventually, I came to the conclusion that it should not be possible to coerce polynomials to the symbolic ring. (Note: I'm not saying that you can't convert to the symbolic ring!) Here's some reasons for disallowing it.
I've also attached an initial patch implementing this. It needs more work though, because the same thing holds for LaurentSeries
and PowerSeries
.
Reasons for not allowing PolynomialRing -> SR coercion:
- This inconsistency:
sage: R.<t> = QQ[]
sage: SR(t^2)
t^2
sage: R.<t> = SR[]
sage: SR(t^2)
Traceback (most recent call last):
...
TypeError: not a constant polynomial
I think the first one should raise a TypeError, too.
- This one:
sage: R.<t> = ZZ[]
sage: (t + 1/2).parent() # automatic base extension
Univariate Polynomial Ring in t over Rational Field
sage: R.<t> = ZZ[]
sage: (t + pi).parent() # expect base extension SR[t]
Symbolic Ring
It is not hard to imagine that this gives all kinds of unexpected results when trying to manipulate these kind of rings programmatically. This must have cost me days and days.
- There is also a better way to convert a polynomial to the symbolic ring,
namely just substituting a symbolic variable:
sage: R.<t> = PolynomialRing(ZZ,'t')
sage: f = t^2 - t
sage: t = var('t')
sage: f(t)
(t - 1)*t
sage: f(t).parent()
Symbolic Ring
This has the advantage that the conversion is explicit.
- Philosophically, I would say that the name of the variable is just a display label, but as it is, it has the side effect of determining what variable to coerce to. Then if you want to return a polynomial from a library routine, you can't be sure that it won't collide with a user-defined variable upon coercion.
Component: algebra
Work Issues: address review
Issue created by migration from https://trac.sagemath.org/ticket/13360