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

Commit

Permalink
Merge commit '0b9914f8b6cd4cb0f885f0550bfd375d80495a71' of trac.sagem…
Browse files Browse the repository at this point in the history
…ath.org:sage into t/17400/simplify_full_returns_odd_result_from_symbolic_series_input

* trac.sagemath.org:sage:
  17399: remove whitespace changes
  17399: handle series in ex.coefficients()
  17399: roll back previous commit to allow merge of 17428
  17399: do not let maxima handle ex.series coefficients
  • Loading branch information
rwst committed Jan 23, 2015
2 parents ed003f0 + 0b9914f commit 2e74911
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5117,9 +5117,9 @@ cdef class Expression(CommutativeRingElement):
Traceback (most recent call last):
...
TypeError: n != 1 only allowed for s being a variable
Using ``coeff()`` is now deprecated (:trac:`17438`)::
sage: x.coeff(x)
doctest:...: DeprecationWarning: coeff is deprecated. Please use coefficient instead.
See http://trac.sagemath.org/17438 for details.
Expand Down Expand Up @@ -5148,12 +5148,12 @@ 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 (``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``).
Expand Down Expand Up @@ -5182,6 +5182,8 @@ cdef class Expression(CommutativeRingElement):
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::
sage: p = (17/3*a)*x^(3/2) + x*y + 1/x + x^x
Expand All @@ -5191,24 +5193,41 @@ cdef class Expression(CommutativeRingElement):
Traceback (most recent call last):
...
ValueError: Cannot return dense coefficient list with noninteger exponents.
Using ``coeffs()`` is now deprecated (:trac:`17438`)::
sage: x.coeffs()
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 All @@ -5225,7 +5244,7 @@ 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.
Expand All @@ -5245,16 +5264,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 2e74911

Please sign in to comment.