Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
17438: implement ex.list()
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Dec 4, 2014
1 parent 9452fa9 commit 0fec129
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/sage/symbolic/expression.pyx
Expand Up @@ -5140,9 +5140,14 @@ cdef class Expression(CommutativeRingElement):
- ``x`` -- optional variable.
OUTPUT:
Depending on the value of ``sparse``,
A list of pairs ``(expr, n)``, where ``expr`` is a symbolic
expression and ``n`` is a power.
- A list of pairs ``(expr, n)``, where ``expr`` is a symbolic
expression and ``n`` is a power (``sparse=True``, default)
- A list of expressions where the ``n``-th element is the coefficient of
``x^n`` when self is seen as polynomial in ``x`` (``sparse=False``).
EXAMPLES::
Expand Down Expand Up @@ -5212,6 +5217,38 @@ cdef class Expression(CommutativeRingElement):
return ret

coeffs = deprecated_function_alias(17438, coefficients)

def list(self, x=None):
r"""
Return the coefficients of this symbolic expression as a polynomial in x.
INPUT:
- ``x`` -- optional variable.
OUTPUT:
A list of expressions where the ``n``-th element is the coefficient of
``x^n`` when self is seen as polynomial in ``x``.
EXAMPLES::
sage: var('x, y, a')
(x, y, a)
sage: (x^5).list()
[0, 0, 0, 0, 0, 1]
sage: p = x^3 - (x-3)*(x^2+x) + 1
sage: p.list()
[1, 3, 2]
sage: p = x - x^3 + 5/7*x^5
sage: p.list()
[0, 1, 0, -1, 0, 5/7]
sage: p = expand((x-a*sqrt(2))^2 + x + 1); p
-2*sqrt(2)*a*x + 2*a^2 + x^2 + x + 1
sage: p.list(a)
[x^2 + x + 1, -2*sqrt(2)*x, 2]
"""
return self.coefficients(x=x, sparse=False)

def leading_coefficient(self, s):
"""
Expand Down

0 comments on commit 0fec129

Please sign in to comment.