pythonsympysimplification

Is there a way to add my own identities to simplify a system of polynomial equations in sympy?


I have the following identity:

1 = a + b + c

Supose that I have the expression:

expr = x*(a + b + c)

It can be simplified as x.

Is there a way to declare it to SymPy so it can simplify them? Actually I do the job mannualy:

>>> import sympy
>>> sympy.vars("x a b c")
>>> expr = x*(a + b + c)
>>> expr.subs(a + b + c, 1)
x

Solution

  • The ratsimpmodprime function will work in your case. It simplifies a rational function with respect to some polynomials that are assumed to be equal to zero:

    In [13]: a, b, c, x = symbols('a, b, c, x')
    
    In [14]: polys = [a + b + c - 1]
    
    In [15]: basis = groebner(polys).polys
    
    In [16]: ratsimpmodprime(x*(a + b + c), basis)
    Out[16]: x
    

    https://docs.sympy.org/latest/modules/simplify/simplify.html#ratsimpmodprime