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

Commit

Permalink
17399: handle series in ex.coefficients()
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Dec 4, 2014
1 parent 168b659 commit 6cd5286
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5173,6 +5173,8 @@ cdef class Expression(CommutativeRingElement):
[[2*a^2 + 1, 0], [-2*sqrt(2)*a + 1, 1], [1, 2]]
sage: p.coefficients(x, sparse=False)
[2*a^2 + 1, -2*sqrt(2)*a + 1, 1]
TESTS:
The behaviour is undefined with noninteger or negative exponents::
Expand All @@ -5190,17 +5192,34 @@ cdef class Expression(CommutativeRingElement):
doctest:...: DeprecationWarning: coeffs is deprecated. Please use coefficients instead.
See http://trac.sagemath.org/17438 for details.
[[1, 1]]
Series coefficients are now handled correctly (:trac:`17399`)::
sage: s=(1/(1-x)).series(x,6); s
1 + 1*x + 1*x^2 + 1*x^3 + 1*x^4 + 1*x^5 + Order(x^6)
sage: s.coefficients()
[[1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5]]
sage: s.coefficients(x, sparse=False)
[1, 1, 1, 1, 1, 1]
sage: x,y = var("x,y")
sage: s=(1/(1-y*x-x)).series(x,3); s
1 + (y + 1)*x + ((y + 1)^2)*x^2 + Order(x^3)
sage: s.coefficients(x, sparse=False)
[1, y + 1, (y + 1)^2]
"""
f = self._maxima_()
maxima = f.parent()
maxima._eval_line('load(coeflist)')
if x is None:
x = self.default_variable()
x = self.parent().var(repr(x))
G = f.coeffs(x)
from sage.calculus.calculus import symbolic_expression_from_maxima_string
S = symbolic_expression_from_maxima_string(repr(G))
l = S[1:]
if is_a_series(self._gobj):
l = [[self.coefficient(x, d), d] for d in xrange(self.degree(x))]
else:
f = self._maxima_()
maxima = f.parent()
maxima._eval_line('load(coeflist)')
G = f.coeffs(x)
from sage.calculus.calculus import symbolic_expression_from_maxima_string
S = symbolic_expression_from_maxima_string(repr(G))
l = S[1:]

if sparse is True:
return l
else:
Expand Down Expand Up @@ -5237,16 +5256,17 @@ cdef class Expression(CommutativeRingElement):
(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]
sage: s=(1/(1-x)).series(x,6); s
1 + 1*x + 1*x^2 + 1*x^3 + 1*x^4 + 1*x^5 + Order(x^6)
sage: s.list()
[1, 1, 1, 1, 1, 1]
"""
return self.coefficients(x=x, sparse=False)

Expand Down

0 comments on commit 6cd5286

Please sign in to comment.