views:

151

answers:

3

how to simplify exponents in equations in sympy

from sympy import symbols 
a,b,c,d,e,f=symbols('abcdef')
j=(a**b**5)**(b**10)
print j 
(a**(b**5))**(b**10) #ans even after using expand simplify 
# desired output 
a**(b**15)

and if it is not possible with sympy which module should i import in python?

edit even if i define 'b' as real,and also all other symbols

b=symbols('b',real=True) not getting simplified exponents it simplifies only if exponents are constants

a=symbols('a',real=True)
b=symbols('b',real=True)
(a**5)**10
 a**50  #simplifies only if exp are numbers
(a**b**5)**b**10


(a**(b**5))**b**10  #no simplification
A: 

This may be related to this bug.

Jesse Dhillon
+7  A: 

(xm)n = xmn is true only if m, n are real.

>>> import math
>>> x = math.e
>>> m = 2j*math.pi
>>> (x**m)**m      # (e^(2πi))^(2πi) = 1^(2πi) = 1
(1.0000000000000016+0j)
>>> x**(m*m)       # e^(2πi×2πi) = e^(-4π²) ≠ 1
(7.157165835186074e-18-0j)

AFAIK, sympy supports complex numbers, so I believe this simplification should not be done unless you can prove b is real.


Edit: It is also false if x is not positive.

>>> x = -2
>>> m = 2
>>> n = 0.5
>>> (x**m)**n
2.0
>>> x**(m*n)
-2.0

Edit(by gnibbler): Here is the original example with Kenny's restrictions applied

>>> from sympy import symbols 
>>> a,b=symbols('ab', real=True, positive=True)
>>> j=(a**b**5)**(b**10)
>>> print j
a**(b**15)
KennyTM
Good answer, but the output is the same for `a,b,c,d,e,f = symbols("abcdef", real=True)`
gnibbler
@gnib: Oops looks like I've missed another restriction (x > 0).
KennyTM
thanx!kenny and gnib ,it works if we define symbol;a=symbols('a',real=True,positive=True)
@jed123, You should accept Kenny's answer
gnibbler
+2  A: 
a,b,c=symbols('abc',real=True,positive=True)
(a**b**5)**b**10
a**(b**15)#ans