Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This can be achieved via using a new variable $y=x+1$:

var('c0 c1 c2 x0 x1 x y')
(c0 * (x+1) + c1*(x+1) + c2*c1*x - c0*c1*(x+1)).subs({x:y-1}).collect(y)

However, if your expressions are polynomial it may be worth to work in polynomial rather than symbolic ring, which provides much advanced functionality with respect to handling polynomials.

This First off, notice the result you request is rather arbitrary - why it's (-c0*c1 + c0 + c1)*(x + 1) + c1*c2*x but not (-c0*c1 + c0 + c1 + c1*c2)*(x + 1) - c1*c2?

The latter can be achieved via using a new variable $y=x+1$:

var('c0 c1 c2 x0 x1 x y')
(c0 * (x+1) + c1*(x+1) + c2*c1*x - c0*c1*(x+1)).subs({x:y-1}).collect(y)

However, if your expressions are polynomial it may be worth to work in polynomial rather than symbolic ring, which provides much advanced functionality with respect to handling polynomials.