Python | sympy.combsimp() method
With the help of sympy.combsimp() method, we can simplify combinatorial expressions.
Syntax: combsimp(expression)
Parameter:
expression – It is combinatorial expression which needs to be simplified.
Returns: Returns a simplified mathematical expression corresponding to the input.
Example #1:
from sympy import *
n = symbols( 'n' , integer = True )
expr = factorial(n) / factorial(n - 3 )
print ( "Expression = {}" . format (expr))
simple_expr = combsimp(expr)
print ( "Simplified Expression : {}" . format (simple_expr))
|
Output:
Expression = factorial(n)/factorial(n - 3)
Simplified Expression : n*(n - 2)*(n - 1)
Example #2:
from sympy import *
n, k = symbols( 'n k' , integer = True )
expr = binomial(n + 1 , k + 1 ) / binomial(n, k)
print ( "Expression = {}" . format (expr))
simple_expr = combsimp(expr)
print ( "Simplified Expression : {}" . format (simple_expr))
|
Output:
Expression = binomial(n+1, k+1)/binomial(n, k)
Simplified Expression : (n + 1)/(k + 1)
Last Updated :
07 Jul, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...