Would doing this be a good idea (see patch below)?
It would fix the failed doctest that I uncommented, but it might do
unexpected things with some exponents.
>>> print fraction(exp(y-x))
(exp(y - x), 1)
>>> print fraction(exp(x-y))
(1, exp(y - x))
What do you think? Changing this doesn't seem to fail any tests, so I
am not sure how often fraction is used.
Aaron Meurer
diff --git a/sympy/simplify/simplify.py b/sympy/simplify/simplify.py
index ba349ff..b711f52 100644
--- a/sympy/simplify/simplify.py
+++ b/sympy/simplify/simplify.py
@@ -55,8 +55,8 @@ def fraction(expr, exact=False):
>>> fraction(2*x**(-y))
(2, x**y)
- #>>> fraction(exp(-x))
- #(1, exp(x))
+ >>> fraction(exp(-x))
+ (1, exp(x))
>>> fraction(exp(-x), exact=True)
(exp(-x), 1)
@@ -68,7 +68,8 @@ def fraction(expr, exact=False):
for term in make_list(expr, Mul):
if term.is_Pow:
- if term.exp.is_negative:
+ if term.exp.is_negative or not exact and\
+ term.could_extract_minus_sign():
if term.exp is S.NegativeOne:
denom.append(term.base)
else:
@@ -83,7 +84,8 @@ def fraction(expr, exact=False):
else:
numer.append(term)
elif term.func is C.exp:
- if term.args[0].is_negative:
+ if term.args[0].is_negative or not exact and\
+ term.args[0].could_extract_minus_sign():
denom.append(C.exp(-term.args[0]))
elif not exact and term.args[0].is_Mul:
coeff, tail = term.args[0],
Mul(*term.args[1:])#term.args.getab()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---