Sunday, November 17, 2024
Google search engine
HomeLanguagesPython | sympy.expand_pow_exp() method

Python | sympy.expand_pow_exp() method

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) 

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments