Opened 6 years ago
Last modified 6 years ago
#17922 new enhancement
coefficients() function more consistent between Expressions and polynomial rings
Reported by: | JoalHeagney | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | sage-6.6 |
Component: | algebra | Keywords: | coeffs, rings, polynomials, expression, symbolic |
Cc: | Merged in: | ||
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
The different behaviour between the two rings consists of
- the
coefficients(sparse=True)
(which is default) method returns a list of pairs inSR
, and a list inPolynomialRing
, Expression.dict()
does not exist.
Example:
y = 3*x^3 + 2*x^2 - 4*x print(y) type(y)
Gives:
3*x^3 + 2*x^2 - 4*x <type 'sage.symbolic.expression.Expression'>
And
M = matrix(SR,[[1,2],[0,-2]]) ch = M.charpoly() print(ch) type(ch)
gives
x^2 + x - 2 <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field'>
But:
y.coeffs()
returns
[[−4,1],[2,2],[3,3]]
and
ch.coeffs()
returns
[−2,1,1]
I'd prefer if these two functions returned the same format, preferably the Expression format, as having access to the index allows list comprehension tastiness.
Change History (5)
comment:1 Changed 6 years ago by
- Keywords rings polynomials expression symbolic added
- Type changed from PLEASE CHANGE to enhancement
comment:2 Changed 6 years ago by
comment:3 follow-up: ↓ 5 Changed 6 years ago by
That works for polynomial rings, are there plans to add that to sage.symbolic.expression.Expressions?
comment:4 Changed 6 years ago by
- Description modified (diff)
- Summary changed from coeffs() function more consistent between Expressions and polynomial rings to coefficients() function more consistent between Expressions and polynomial rings
Clarified the ticket description.
comment:5 in reply to: ↑ 3 Changed 6 years ago by
Replying to JoalHeagney:
That works for polynomial rings, are there plans to add that to sage.symbolic.expression.Expressions?
That would not be difficult (in comparison). If you expect it then to behave identically you will be disappointed however, because symbolics have no default generator (although Expression.coefficients()
has the lexically first occuring var hard-wired when no varname is given).
sage: var('a,b,c') (a, b, c) sage: (a+2*a^2+3*b).list() [3*b, 1, 2] sage: (3*b+a+2*a^2).list() [3*b, 1, 2] sage: (3*b+c+2*c^2).list() [2*c^2 + c, 3]
so you could never have true polymorphism.
Have list comprehension tastiness with
dict
:In #17518 we started being more consistent by deprecating
coeffs
.