Open In App

Python | sympy.expand_pow_exp() method

Improve
Improve
Like Article
Like
Save
Share
Report

With the help of sympy.expand_pow_exp() method, we can expand mathematical expression using following identity – 

 x(a+b) = xa.xb

Syntax: expand_pow_exp(expression) 
Parameters: 
expression – It is the mathematical expression which needs to be expanded.
Returns: Returns an expanded mathematical expression corresponding to the input expression. 

Example #1: 
In this example we can see that by using sympy.expand_pow_exp() method, we can expand a mathematical expression in terms of power. 

Python3




# import sympy
from sympy import *
 
x, a, b = symbols('x a b')
expr = x**(a + b)
 
print("Before Expansion : {}".format(expr))
   
# Use sympy.expand_pow_exp() method
smpl = expand_pow_exp(expr)
   
print("After Expansion : {}".format(smpl))


Output: 

Before Expansion : x**(a + b)
After Expansion : x**a*x**b

Example #2: 

Python3




# import sympy
from sympy import *
 
x, a, b = symbols('x a b')
expr = x**(2 * a + 3 * b)
 
print("Before Expansion : {}".format(expr))
   
# Use sympy.expand_pow_exp() method
smpl = expand_pow_exp(expr)
   
print("After Expansion : {}".format(smpl))


Output: 

Before Expansion : x**(2*a + 3*b)
After Expansion : x**(2*a)*x**(3*b) 


Last Updated : 23 Dec, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads