Python | sympy.primitive () method

Python Methods and Functions

Using the sympy.primitive() method, we can find the common part of a mathematical expression using sympy.primitive () .

Syntax: sympy.primitive ()
Return: Return a tuple having common part separated from mathematical expression.

Example # 1:
In this example, we see that with sympy.primitive () we we can find the common part from the math expression.

# import sympy

from sympy import *  

 

x, y = symbols ( 'xy ' )

  
# Using the sympy.primitive () method

gfg = ( 3 * x + 9 * y) .primitive ()

 

print (gfg)

Exit:

(3, x + 3 * y)

Example # 2:

< / table>

Output:

(2/7, x + y)





Get Solution for free from DataCamp guru

# import sympy

from sympy import *  

  

x, y = symbols ( 'xy ' )

  
# Using the sympy.primitive () method

gfg = ( 2 * x / 7 + 4 * y / 14 ). primitive ()

 

print (gfg)