Python sympy.powdenest() Method

Python SymPy Module:

SymPy is a Python symbolic mathematics library. It aims to be a full-featured computer algebra system (CAS) while keeping the code as basic(simple) as possible in order to be understandable and easily expandable. SymPy is entirely written in Python. SymPy is simple to use because it only depends on mpmath, a pure Python library for arbitrary floating-point arithmetic.

Rational and Integer are the numerical types defined by SymPy. A rational number is represented by the Rational class as a pair of two Integers, numerator and denominator, therefore Rational(1, 2) is 1/2, Rational(3, 2) is 3/2, and so on. Integer numbers are represented by the Integer class.

SymPy uses mpmath in the background, allowing it to execute arbitrary-precision arithmetic computations. Some special constants, such as exp, pi, and oo (Infinity), are thus considered as symbols and can be evaluated with arbitrary precision.

Installation:

pip install sympy

Python sympy.powdenest() Method:

Using the sympy.powdenest() function, we can simplify the powers of mathematical expressions by using identity, (x^a)^b=x^ab.

Syntax:

sympy.powdenest()

Return Value:

The simplified mathematical expression using identity (x^a)^b=x^ab is returned by the powdenest() function.

sympy.powdenest() Method in Python

Method #1: Using powdenest() Function (Static Input)

Approach:

  • Import all the functions from sympy module using the import keyword
  • Pass the symbols to be used as arguments to the symbols() function and store them in corresponding variables.
  • Give the mathematical expression as static input and store it in a variable.
  • Pass the given mathematical expression as an argument to the powdenest() function to simplify the powers of the given mathematical expression using the identity (x^a)^b=x^ab.
  • Store it in another variable.
  • Print the simplified expression.
  • The Exit of the Program.

Below is the implementation:

# Import all the functions from sympy module using the import keyword
from sympy import *

# Pass the symbols to be used as arguments to the symbols() function
# and store them in corresponding variables.
x, y = symbols('x y')

# Give the mathematical expression as static input and store it in a variable.
gvn_expression = (x**4)**2

# Pass the given mathematical expression as an argument to the powdenest() function
# to simplify the powers of the given mathematical expression using the identity
# (x^a)^b=x^ab.
# Store it in another variable.
rslt = powdenest(gvn_expression)

# Print the simplified expression
print(rslt)

Output:

x**8

Method #2: Using powdenest() Function (User Input)

Approach:

  • Import all the functions from sympy module using the import keyword
  • Pass the symbols to be used as arguments to the symbols() function and store them in corresponding variables.
  • Give the mathematical expression as user input using the input() function and store it in a variable.
  • Pass the given mathematical expression as an argument to the powdenest() function to simplify the powers of the given mathematical expression using the identity (x^a)^b=x^ab.
  • Store it in another variable.
  • Print the simplified expression.
  • The Exit of the Program.

Below is the implementation:

# Import all the functions from sympy module using the import keyword
from sympy import *

# Pass the symbols to be used as arguments to the symbols() function
# and store them in corresponding variables.
x, y = symbols('x y')

# Give the mathematical expression as user input using the input() function 
# and store it in a variable.
gvn_expression = input("Enter some random Expression:\n")

# Pass the given mathematical expression as an argument to the powdenest() function
# to simplify the powers of the given mathematical expression using the identity
# (x^a)^b=x^ab.
# Store it in another variable.
rslt = powdenest(gvn_expression)

# Print the simplified expression
print("The simplified Expression is:")
print(rslt)

Output:

Enter some random Expression:
(x**(y + z))**2
The simplified Expression is:
x**(2*y + 2*z)