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

Question:

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
Asked By: Alan Cristhian

||

Answers:

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

Answered By: Oscar Benjamin
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.