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

Commit

Permalink
17400: symbolic series simplification methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Mar 5, 2015
1 parent b22c33b commit 73cd5bf
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/doc/en/reference/calculus/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Symbolic Calculus
sage/symbolic/function
sage/symbolic/function_factory
sage/calculus/functional
sage/symbolic/series
sage/symbolic/integration/integral
sage/calculus/test_sympy
sage/calculus/tests
Expand Down
43 changes: 20 additions & 23 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ import sage.rings.integer
import sage.rings.rational
from sage.structure.element cimport ModuleElement, RingElement, Element
from sage.symbolic.getitem cimport OperandsWrapper
from sage.symbolic.series cimport SymbolicSeries
from sage.symbolic.complexity_measures import string_length
from sage.symbolic.function import get_sfunction_from_serial, SymbolicFunction
from sage.rings.rational import Rational # Used for sqrt.
Expand Down Expand Up @@ -1772,12 +1773,7 @@ cdef class Expression(CommutativeRingElement):

def is_series(self):
"""
Return True if ``self`` is a series.
Series are special kinds of symbolic expressions that are
constructed via the :meth:`series` method. They usually have
an ``Order()`` term unless the series representation is exact,
see :meth:`is_terminating_series`.
Return True if ``self`` is a :class:`~sage.symbolic.series.SymbolicSeries`.
OUTPUT:
Expand Down Expand Up @@ -1817,7 +1813,7 @@ cdef class Expression(CommutativeRingElement):
sage: sum_expr.is_series()
False
"""
return is_a_series(self._gobj)
return False

def is_terminating_series(self):
"""
Expand Down Expand Up @@ -1849,7 +1845,7 @@ cdef class Expression(CommutativeRingElement):
sage: exp(x).series(x,10).is_terminating_series()
False
"""
return g_is_a_terminating_series(self._gobj)
return False

cpdef bint is_polynomial(self, var):
"""
Expand Down Expand Up @@ -3611,6 +3607,7 @@ cdef class Expression(CommutativeRingElement):
"""
cdef Expression symbol0 = self.coerce_in(symbol)
cdef GEx x
cdef SymbolicSeries nex
cdef int prec
if order is None:
from sage.misc.defaults import series_precision
Expand All @@ -3620,9 +3617,12 @@ cdef class Expression(CommutativeRingElement):
sig_on()
try:
x = self._gobj.series(symbol0._gobj, prec, 0)
nex = <SymbolicSeries>PY_NEW(SymbolicSeries)
nex._parent = self._parent
GEx_construct_ex(&nex._gobj, x)
finally:
sig_off()
return new_Expression_from_GEx(self._parent, x)
return nex

def residue(self, symbol):
"""
Expand Down Expand Up @@ -3782,9 +3782,7 @@ cdef class Expression(CommutativeRingElement):
sage: f.series(x==1,3).truncate().expand()
-2*x^2*cos(1) + 5/2*x^2*sin(1) + 5*x*cos(1) - 7*x*sin(1) - 3*cos(1) + 11/2*sin(1)
"""
if not is_a_series(self._gobj):
return self
return new_Expression_from_GEx(self._parent, series_to_poly(self._gobj))
return self

def expand(Expression self, side=None):
"""
Expand Down Expand Up @@ -5258,6 +5256,7 @@ cdef class Expression(CommutativeRingElement):
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()
Expand All @@ -5278,19 +5277,16 @@ cdef class Expression(CommutativeRingElement):
[[t, 0], [3, 1], [1, 2]]
"""
f = self._maxima_()
maxima = f.parent()
maxima._eval_line('load(coeflist)')
if x is None:
x = self.default_variable()
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:]

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 sparse is True:
return l
else:
Expand Down Expand Up @@ -11139,3 +11135,4 @@ cdef operators compatible_relation(operators lop, operators rop) except <operato
return greater
else:
raise TypeError("incompatible relations")

1 change: 1 addition & 0 deletions src/sage/symbolic/ginac.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ cdef extern from "ginac_wrap.h":
bint is_a_series "is_a<pseries>" (GEx e)
# you must ensure that is_a_series(e) is true before calling this:
bint g_is_a_terminating_series(GEx e) except +
GEx g_series_var(GEx e) except +

# Relations
ctypedef enum operators "relational::operators":
Expand Down
7 changes: 7 additions & 0 deletions src/sage/symbolic/ginac_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ bool g_is_a_terminating_series(const ex& e) {
return false;
}

ex g_series_var(const ex& e) {
if (is_a<pseries>(e)) {
return (ex_to<pseries>(e)).get_var();
}
return NULL;
}

relational::operators relational_operator(const ex& e) {
// unsafe cast -- be damn sure the input is a relational.
return (ex_to<relational>(e)).the_operator();
Expand Down
4 changes: 4 additions & 0 deletions src/sage/symbolic/series.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from sage.symbolic.expression cimport Expression

cdef class SymbolicSeries(Expression):
pass
Loading

0 comments on commit 73cd5bf

Please sign in to comment.