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

Commit

Permalink
changes affecting Sage behaviour or interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Aug 30, 2016
1 parent b996f4f commit 91a08d2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
50 changes: 35 additions & 15 deletions src/sage/symbolic/expression.pyx
Expand Up @@ -1191,7 +1191,7 @@ cdef class Expression(CommutativeRingElement):
except TypeError as err:
# try the evaluation again with the complex field
# corresponding to the parent R
if R is float:
if R in (float, complex):
R_complex = complex
else:
try:
Expand Down Expand Up @@ -1387,10 +1387,19 @@ cdef class Expression(CommutativeRingElement):
...
TypeError: unable to simplify to float approximation
"""
from sage.functions.other import real, imag
try:
return float(self._eval_self(float))
ret = float(self._eval_self(float))
except TypeError:
raise TypeError("unable to simplify to float approximation")
try:
c = (self._eval_self(complex))
if imag(c) == 0:
ret = real(c)
else:
raise
except TypeError:
raise TypeError("unable to simplify to float approximation")
return ret

def __complex__(self):
"""
Expand Down Expand Up @@ -3552,8 +3561,6 @@ cdef class Expression(CommutativeRingElement):
INPUT:
- ``exp`` -- something that coerces to a symbolic expression.
- ``ignored`` -- the second argument that should accept a modulus
is actually ignored.
OUTPUT:
Expand Down Expand Up @@ -8350,11 +8357,14 @@ cdef class Expression(CommutativeRingElement):
else:
return v[0]

def combine(self):
def combine(self, bint deep=False):
r"""
Return a simplified version of this symbolic expression
by combining all terms with the same denominator into a single
term.
by combining all toplevel terms with the same denominator into
a single term.
Please use the keyword ``deep=True`` to apply the process
recursively.
EXAMPLES::
Expand All @@ -8364,8 +8374,19 @@ cdef class Expression(CommutativeRingElement):
(x - 1)*x/(x^2 - 7) + y^2/(x^2 - 7) + b/a + c/a + 1/(x + 1)
sage: f.combine()
((x - 1)*x + y^2)/(x^2 - 7) + (b + c)/a + 1/(x + 1)
sage: (1/x + 1/x^2 + (x+1)/x).combine()
(x + 2)/x + 1/x^2
sage: ex = 1/x + ((x + 1)/x - 1/x)/x^2 + (x+1)/x; ex
(x + 1)/x + 1/x + ((x + 1)/x - 1/x)/x^2
sage: ex.combine()
(x + 2)/x + ((x + 1)/x - 1/x)/x^2
sage: ex.combine(deep=True)
(x + 2)/x + 1/x^2
sage: (1+sin((x + 1)/x - 1/x)).combine(deep=True)
sin(1) + 1
"""
return new_Expression_from_GEx(self._parent, self._gobj.combine_fractions())
return new_Expression_from_GEx(self._parent,
self._gobj.combine_fractions(deep))

def normalize(self):
"""
Expand Down Expand Up @@ -8408,7 +8429,7 @@ cdef class Expression(CommutativeRingElement):
ALGORITHM: Uses GiNaC.
"""
return new_Expression_from_GEx(self._parent, self._gobj.normal())
return new_Expression_from_GEx(self._parent, self._gobj.normal(0, False, True))

def numerator(self, bint normalize = True):
"""
Expand Down Expand Up @@ -9351,9 +9372,8 @@ cdef class Expression(CommutativeRingElement):
ALIAS: :meth:`rational_simplify` and :meth:`simplify_rational`
are the same
DETAILS: We call Maxima functions ratsimp, fullratsimp and
xthru. If each part of the expression has to be simplified
separately, we use Maxima function map.
DETAILS: We call the Maxima function ``fullratsimp`` and
and Pynac's ``normal``, depending on the ``algorithm`` keyword.
EXAMPLES::
Expand Down Expand Up @@ -9407,9 +9427,9 @@ cdef class Expression(CommutativeRingElement):
if algorithm == 'full':
maxima_method = 'fullratsimp'
elif algorithm == 'simple':
maxima_method = 'ratsimp'
return new_Expression_from_GEx(self._parent, self._gobj.normal(0, False, False))
elif algorithm == 'noexpand':
maxima_method = 'xthru'
return new_Expression_from_GEx(self._parent, self._gobj.normal(0, True, True))
else:
raise NotImplementedError("unknown algorithm, see the help for available algorithms")
P = self_m.parent()
Expand Down
4 changes: 2 additions & 2 deletions src/sage/symbolic/ginac.pxd
Expand Up @@ -106,8 +106,8 @@ cdef extern from "sage/symbolic/ginac_wrap.h":
GEx lcoeff(GEx expr) except +
GEx tcoeff(GEx expr) except +
void coefficients(GEx s, vector[pair[GEx,GEx]]) except +
GEx combine_fractions() except +
GEx normal() except +
GEx combine_fractions(bint deep) except +
GEx normal(int level, bint noexpand_combined, bint noexpand_frac) except +
GEx numer() except +
GEx denom() except +
GEx numer_denom() except +
Expand Down

0 comments on commit 91a08d2

Please sign in to comment.