Opened 10 years ago
Last modified 8 years ago
#13360 needs_work defect
Should not allow coercion from polynomials to symbolic ring — at Version 1
Reported by: | tkluck | Owned by: | AlexGhitza |
---|---|---|---|
Priority: | major | Milestone: | sage-6.4 |
Component: | algebra | Keywords: | |
Cc: | Merged in: | ||
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
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:
1) 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.
2) 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.
3) 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^2 - t sage: f(t).parent() Symbolic Ring
This has the advantage that the conversion is explicit.
4) 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.
Change History (3)
Changed 10 years ago by
Changed 10 years ago by
comment:1 Changed 10 years ago by
- Description modified (diff)