Skip to content
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

coefficients() function more consistent between Expressions and polynomial rings #17922

Open
sagetrac-JoalHeagney mannequin opened this issue Mar 10, 2015 · 6 comments
Open

Comments

@sagetrac-JoalHeagney
Copy link
Mannequin

sagetrac-JoalHeagney mannequin commented Mar 10, 2015

The different behaviour between the two rings consists of

  1. the coefficients(sparse=True) (which is default) method returns a list of pairs in SR, and a list in PolynomialRing,
  2. 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.

Component: algebra

Keywords: coeffs, rings, polynomials, expression, symbolic

Issue created by migration from https://trac.sagemath.org/ticket/17922

@sagetrac-JoalHeagney sagetrac-JoalHeagney mannequin added this to the sage-6.6 milestone Mar 10, 2015
@sagetrac-JoalHeagney
Copy link
Mannequin Author

sagetrac-JoalHeagney mannequin commented Mar 10, 2015

Changed keywords from coeffs to coeffs, rings, polynomials, expression, symbolic

@rwst
Copy link
Contributor

rwst commented Mar 11, 2015

comment:2

Have list comprehension tastiness with dict:

sage: ch.dict().values()
[-2, 1, 1]

In #17518 we started being more consistent by deprecating coeffs.

@sagetrac-JoalHeagney
Copy link
Mannequin Author

sagetrac-JoalHeagney mannequin commented Mar 11, 2015

comment:3

That works for polynomial rings, are there plans to add that to sage.symbolic.expression.Expressions?

@rwst
Copy link
Contributor

rwst commented Mar 12, 2015

comment:4

Clarified the ticket description.

@rwst

This comment has been minimized.

@rwst rwst changed the title coeffs() function more consistent between Expressions and polynomial rings coefficients() function more consistent between Expressions and polynomial rings Mar 12, 2015
@rwst
Copy link
Contributor

rwst commented Mar 12, 2015

comment:5

Replying to @sagetrac-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.

@mkoeppe mkoeppe removed this from the sage-6.6 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants