powsimp does not combine exponents correctly in the following case, for example: exp(x)/(1 + exp(x)*exp(y)). This is because the exponentials to be combined are inside of a larger exponential ( (1 + exp(x)exp(y))*(-1) ), and powsimp doesn't handle that correctly.
I have fixed it. Please pull from http://github.com/asmeurer/sympy/tree/powsimp-fix.
Note that you need to use deep=True to combine the above example.
Unfortunately, powsimp() no longer calls separate(), so x**n * (x*n)(-n) * n will be simplified into n*n-n rather than n**(1 - n). This is because separate() was messing up simplification of expressions like (z**x*z**y)**x. See the log for more info.
Comment #1
Posted on Aug 1, 2009 by Happy Elephant(No comment was entered for this change.)
Comment #2
Posted on Aug 10, 2009 by Quick KangarooIs this (e.g. powsimp no longer calling separate) why you changed powsimp to separate in the test?
- assert powsimp(r0[0]) == powsimp(r1[0])
- assert powsimp(r0[1]) == powsimp(r1[1])
- assert separate(r0[0]) == separate(r1[0])
- assert separate(r0[1]) == separate(r1[1])
If so, then +1, I'll push it in.
Comment #3
Posted on Aug 10, 2009 by Happy ElephantYes it is. Those tests should have used separate in the first place (they have no bearing on what powsimp does), but it looks whoever wrote them found that powsimp, which used separate, did what he wanted and so used it instead.
Comment #4
Posted on Aug 10, 2009 by Happy ElephantThis can be pushed in.
Comment #5
Posted on Oct 7, 2009 by Quick KangarooI get some conflicts when merging your branch. I apologize for forgetting about this. do you know how to fix this easily?
$ git di diff --cc sympy/simplify/simplify.py index 027f1cf,efc7da5..0000000 --- a/sympy/simplify/simplify.py +++ b/sympy/simplify/simplify.py @@@ -1042,32 -934,33 +1042,55 @@@ def powsimp(expr, deep=False, combine=' combine='exp' will strictly only combine exponents in the way that use to be automatic. Also use deep=True if you need the old behavior.
- When combine='all', 'exp' is evaluated first. Consider the first
- example below for when there could be an ambiguity relating to this.
- This is done so things like the second example can be completely
- combined. If you want 'base' combined first, do something like
- powsimp(powsimp(expr, combine='base'), combine='exp').
- == Examples ==
from sympy import * ++<<<<<<< HEAD:sympy/simplify/simplify.py
x,n = symbols('xn')
e = x**n * (x*n)**(-n) * n
powsimp(e)
- n**(1 - n) +
powsimp(log(e))
- log(n*x**n*(n*x)**(-n)) +
powsimp(log(e), deep=True)
- log(n**(1 - n)) +
powsimp(e, combine='exp')
- n*x**n*(n*x)**(-n)
powsimp(e, combine='base')
- n*(1/n)**n +
y, z = symbols('yz')
a = x**y*x**z*n**z*n**y
powsimp(a, combine='exp') ++=======
x, y, z, n = symbols('xyzn')
powsimp(x**y*x**z*y**z, combine='all')
- x**(y + z)*y**z
powsimp(x**y*x**z*y**z, combine='exp')
- x**(y + z)*y**z
powsimp(x**y*x**z*y**z, combine='base')
- x**y*(x*y)**z
powsimp(x**z*x**y*n**z*n**y, combine='all')
- (n*x)**(y + z)
powsimp(x**z*x**y*n**z*n**y, combine='exp') ++>>>>>>> aaron/powsimp-fix:sympy/simplify/simplify.py n**(y + z)x*(y + z)
powsimp(a, combine='base')
powsimp(x**z*x**y*n**z*n**y, combine='base') (n*x)**y*(n*x)**z
powsimp(a, combine='all')
- (n*x)**(y + z)
powsimp(log(exp(x)*exp(y)))
- log(exp(x)*exp(y))
powsimp(log(exp(x)*exp(y)), deep=True)
- x + y """ if combine not in ['all', 'exp', 'base']: raise ValueError, "combine must be one of ('all', 'exp', 'base')."
Comment #6
Posted on Oct 8, 2009 by Happy ElephantSorry, I forgot that this branch even existed. I thought that you had pushed it in. Usually when I have a branch ready for review, I keep it rebased over master until it is merged in. I have rebased over master and it should work now.
Comment #7
Posted on Oct 8, 2009 by Quick KangarooIt's in, thanks for the patch. And sorry it took so long to commit it. I'll try to improve. :)
Comment #8
Posted on Mar 5, 2014 by Happy ElephantWe have moved issues to GitHub https://github.com/sympy/sympy/issues.
Comment #9
Posted on Apr 6, 2014 by Happy RabbitMigrated to http://github.com/sympy/sympy/issues/4664
Status: Fixed
Labels:
Type-Defect
Priority-Medium
Simplify
NeedsReview
Restrict-AddIssueComment-Commit