@@ -1191,7 +1191,7 @@ cdef class Expression(CommutativeRingElement):
1191
1191
except TypeError as err:
1192
1192
# try the evaluation again with the complex field
1193
1193
# corresponding to the parent R
1194
- if R is float :
1194
+ if R in ( float , complex ) :
1195
1195
R_complex = complex
1196
1196
else :
1197
1197
try :
@@ -1387,10 +1387,19 @@ cdef class Expression(CommutativeRingElement):
1387
1387
...
1388
1388
TypeError: unable to simplify to float approximation
1389
1389
"""
1390
+ from sage.functions.other import real, imag
1390
1391
try :
1391
- return float (self ._eval_self(float ))
1392
+ ret = float (self ._eval_self(float ))
1392
1393
except TypeError :
1393
- raise TypeError (" unable to simplify to float approximation" )
1394
+ try :
1395
+ c = (self ._eval_self(complex ))
1396
+ if imag(c) == 0 :
1397
+ ret = real(c)
1398
+ else :
1399
+ raise
1400
+ except TypeError :
1401
+ raise TypeError (" unable to simplify to float approximation" )
1402
+ return ret
1394
1403
1395
1404
def __complex__ (self ):
1396
1405
"""
@@ -3552,8 +3561,6 @@ cdef class Expression(CommutativeRingElement):
3552
3561
INPUT:
3553
3562
3554
3563
- ``exp`` -- something that coerces to a symbolic expression.
3555
- - ``ignored`` -- the second argument that should accept a modulus
3556
- is actually ignored.
3557
3564
3558
3565
OUTPUT:
3559
3566
@@ -8350,11 +8357,14 @@ cdef class Expression(CommutativeRingElement):
8350
8357
else :
8351
8358
return v[0 ]
8352
8359
8353
- def combine (self ):
8360
+ def combine (self , bint deep = False ):
8354
8361
r """
8355
8362
Return a simplified version of this symbolic expression
8356
- by combining all terms with the same denominator into a single
8357
- term.
8363
+ by combining all toplevel terms with the same denominator into
8364
+ a single term.
8365
+
8366
+ Please use the keyword ``deep=True`` to apply the process
8367
+ recursively.
8358
8368
8359
8369
EXAMPLES::
8360
8370
@@ -8364,8 +8374,19 @@ cdef class Expression(CommutativeRingElement):
8364
8374
( x - 1) * x/( x^ 2 - 7) + y^ 2/( x^ 2 - 7) + b/a + c/a + 1/( x + 1)
8365
8375
sage: f. combine( )
8366
8376
(( x - 1) * x + y^ 2) /( x^ 2 - 7) + ( b + c) /a + 1/( x + 1)
8377
+ sage: ( 1/x + 1/x^ 2 + ( x+ 1) /x) . combine( )
8378
+ ( x + 2) /x + 1/x^ 2
8379
+ sage: ex = 1/x + (( x + 1) /x - 1/x) /x^ 2 + ( x+ 1) /x; ex
8380
+ ( x + 1) /x + 1/x + (( x + 1) /x - 1/x) /x^ 2
8381
+ sage: ex. combine( )
8382
+ ( x + 2) /x + (( x + 1) /x - 1/x) /x^ 2
8383
+ sage: ex. combine( deep=True)
8384
+ ( x + 2) /x + 1/x^ 2
8385
+ sage: ( 1+ sin(( x + 1) /x - 1/x)) . combine( deep=True)
8386
+ sin( 1) + 1
8367
8387
"""
8368
- return new_Expression_from_GEx(self ._parent, self ._gobj.combine_fractions())
8388
+ return new_Expression_from_GEx(self ._parent,
8389
+ self ._gobj.combine_fractions(deep))
8369
8390
8370
8391
def normalize (self ):
8371
8392
"""
@@ -8408,7 +8429,7 @@ cdef class Expression(CommutativeRingElement):
8408
8429
ALGORITHM: Uses GiNaC.
8409
8430
8410
8431
"""
8411
- return new_Expression_from_GEx(self ._parent, self ._gobj.normal())
8432
+ return new_Expression_from_GEx(self ._parent, self ._gobj.normal(0 , False , True ))
8412
8433
8413
8434
def numerator (self , bint normalize = True ):
8414
8435
"""
@@ -9351,9 +9372,8 @@ cdef class Expression(CommutativeRingElement):
9351
9372
ALIAS: :meth:`rational_simplify` and :meth:`simplify_rational`
9352
9373
are the same
9353
9374
9354
- DETAILS: We call Maxima functions ratsimp, fullratsimp and
9355
- xthru. If each part of the expression has to be simplified
9356
- separately, we use Maxima function map.
9375
+ DETAILS: We call the Maxima function ``fullratsimp`` and
9376
+ and Pynac's ``normal``, depending on the ``algorithm`` keyword.
9357
9377
9358
9378
EXAMPLES::
9359
9379
@@ -9407,9 +9427,9 @@ cdef class Expression(CommutativeRingElement):
9407
9427
if algorithm == ' full' :
9408
9428
maxima_method = ' fullratsimp'
9409
9429
elif algorithm == ' simple' :
9410
- maxima_method = ' ratsimp '
9430
+ return new_Expression_from_GEx( self ._parent, self ._gobj.normal( 0 , False , False ))
9411
9431
elif algorithm == ' noexpand' :
9412
- maxima_method = ' xthru '
9432
+ return new_Expression_from_GEx( self ._parent, self ._gobj.normal( 0 , True , True ))
9413
9433
else :
9414
9434
raise NotImplementedError (" unknown algorithm, see the help for available algorithms" )
9415
9435
P = self_m.parent()
0 commit comments