Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Are there any techniques to improve the results of `simplify` or `full_simplify`?

I have the following long expression, which I want to simplify for non-negative integer values of n:

var('A, B, C, D, E, α, β, γ')
D = A + E if E < 0 else A
fn = (
   (8*A + 6*B + 4*C + 4*D + 2*abs(E) + 4*α + 2*β + γ)^n
 - (7*A + 6*B + 4*C + 4*D + 2*abs(E) + 4*α + 2*β + γ)^n
 - (7*A + 5*B + 4*C + 4*D + 2*abs(E) + 4*α + 2*β + γ)^n
 + (6*A + 5*B + 4*C + 4*D + 2*abs(E) + 4*α + 2*β + γ)^n
 - (6*A + 5*B + 3*C + 4*D + 2*abs(E) + 4*α + 2*β + γ)^n
 + (5*A + 5*B + 3*C + 4*D + 2*abs(E) + 4*α + 2*β + γ)^n
 + (5*A + 4*B + 3*C + 4*D + 2*abs(E) + 4*α + 2*β + γ)^n
 - (5*A + 4*B + 3*C + 3*D + 2*abs(E) + 4*α + 2*β + γ)^n
 - (5*A + 4*B + 3*C + 3*D + abs(E) + 4*α + 2*β + γ)^n
 + (5*A + 4*B + 3*C + 2*D + abs(E) + 4*α + 2*β + γ)^n
 + (5*A + 3*B + 3*C + 2*D + abs(E) + 4*α + 2*β + γ)^n
 - (4*A + 3*B + 3*C + 2*D + abs(E) + 4*α + 2*β + γ)^n
 + (4*A + 3*B + 2*C + 2*D + abs(E) + 4*α + 2*β + γ)^n
 - (4*A + 3*B + 2*C + 2*D + abs(E) + 3*α + 2*β + γ)^n
 - (4*A + 3*B + 2*C + 2*D + abs(E) + 3*α + β + γ)^n
 + (4*A + 3*B + 2*C + 2*D + abs(E) + 2*α + β + γ)^n
 - (4*A + 3*B + 2*C + 2*D + abs(E) + 2*α + β)^n
 + (4*A + 3*B + 2*C + 2*D + abs(E) + α + β)^n
 + (4*A + 3*B + 2*C + 2*D + abs(E) + α)^n
 - (4*A + 3*B + 2*C + 2*D + abs(E))^n
 + (4*A + 3*B + C + 2*D + abs(E))^n
 - (3*A + 3*B + C + 2*D + abs(E))^n
 - (3*A + 2*B + C + 2*D + abs(E))^n
 + (3*A + 2*B + C + D + abs(E))^n
 + (3*A + 2*B + C + D)^n
 - (3*A + 2*B + C)^n
 - (3*A + B + C)^n
 + (2*A + B + C)^n
 - (2*A + B)^n
 + (A + B)^n
 + A^n
)/factorial(n)

After replacing all ns with 0s, the command f0.full_simplify() returns the correct result of 1. After replacing all ns with 1s or 2s, the commands f1.full_simplify() or f2.full_simplify() return the correct result of 0.

However, for higher integer values of n, the output is no longer fully simplified. The command f3.full_simplify() returns the result

4*A^3 + 5*A^2*B + A*B^2 + 2*A^2*C - 2*(A - B - C)*D^2 + 2*D^3 - (A - D)*E^2 + 2*α^3 + α*β^2 - 2*(A^2 + 2*A*B + 2*A*C)*D - 4*(A*B + 2*A*D - D^2 + (A - D)*abs(E))*α - (2*A*B + 4*A*D - 2*D^2 - 3*α^2 + 2*(A - D)*abs(E))*β - (A*B + 2*A*D - D^2 - α^2 - α*β + (A - D)*abs(E))*γ - (A^2 + 2*A*B + 2*A*C + 2*(A - B - C)*D - 3*D^2)*abs(E)

which I was able to further simplify manually to get A*(A + B)*(2*A + B - 4*α - 2*β - γ) + α*(α + β)*(2*α + β + γ). Similarly, the command f4.full_simplify() returns the result

16*A^4 + 32*A^3*B + 19*A^2*B^2 + 3*A*B^3 + 4*A^2*C^2 + 2*(2*A + 5*B + 4*C)*D^3 + 4*D^4 + 2*(4*A + 3*B + 2*C + 2*D + abs(E))*α^3 + 4*α^4 + α*β^3 - 2*(6*A^2 + 3*A*B - 3*B^2 + (2*A - 5*B)*C - 2*C^2)*D^2 - (5*A^2 + 5*A*B + 4*A*C - (5*B + 4*C)*D - 5*D^2)*E^2 - 8*(A*B + 2*A*D - D^2 + (A - D)*abs(E))*α^2 - (2*A*B + 4*A*D - 2*D^2 - (4*A + 3*B + 2*C + 2*D + abs(E))*α - 5*α^2 + 2*(A - D)*abs(E))*β^2 - 1/2*(A*B + 2*A*D - D^2 - α^2 - α*β + (A - D)*abs(E))*γ^2 + 2*(8*A^3 + 8*A^2*B + A*B^2)*C - 2*(6*A^2*B + 5*A*B^2 + 4*A*C^2 + 2*(4*A^2 + 5*A*B)*C)*D + 2*(4*A^3 - 3*A^2*B - 5*A*B^2 - 2*(A - 4*B - 3*C)*D^2 + 6*D^3 - 3*(A - D)*E^2 + 2*(A^2 - 2*A*B)*C - 2*(9*A^2 + 10*A*B + 6*A*C)*D - (9*A^2 + 10*A*B + 6*A*C + 2*(A - 4*B - 3*C)*D - 9*D^2)*abs(E))*α + (4*A^3 - 3*A^2*B - 5*A*B^2 - 2*(A - 4*B - 3*C)*D^2 + 6*D^3 - 3*(A - D)*E^2 + 3*(4*A + 3*B + 2*C + 2*D + abs(E))*α^2 + 8*α^3 + 2*(A^2 - 2*A*B)*C - 2*(9*A^2 + 10*A*B + 6*A*C)*D - 8*(A*B + 2*A*D - D^2 + (A - D)*abs(E))*α - (9*A^2 + 10*A*B + 6*A*C + 2*(A - 4*B - 3*C)*D - 9*D^2)*abs(E))*β + 1/2*(4*A^3 - 3*A^2*B - 5*A*B^2 - 2*(A - 4*B - 3*C)*D^2 + 6*D^3 - 3*(A - D)*E^2 + 2*(4*A + 3*B + 2*C + 2*D + abs(E))*α^2 + 6*α^3 + 3*α*β^2 + 2*(A^2 - 2*A*B)*C - 2*(9*A^2 + 10*A*B + 6*A*C)*D - 8*(A*B + 2*A*D - D^2 + (A - D)*abs(E))*α - (4*A*B + 8*A*D - 4*D^2 - 2*(4*A + 3*B + 2*C + 2*D + abs(E))*α - 9*α^2 + 4*(A - D)*abs(E))*β - (9*A^2 + 10*A*B + 6*A*C + 2*(A - 4*B - 3*C)*D - 9*D^2)*abs(E))*γ - (6*A^2*B + 5*A*B^2 + 4*A*C^2 - 3*(2*A + 5*B + 4*C)*D^2 - 8*D^3 + (A - D)*E^2 + 2*(4*A^2 + 5*A*B)*C + 2*(6*A^2 + 3*A*B - 3*B^2 + (2*A - 5*B)*C - 2*C^2)*D)*abs(E)

which I was able to manually simplify down to (6*A + 3*B + 2*C + E + 1/2*(4*α + 2*β + γ))*(A*(A + B)*(2*A + B - 4*α - 2*β - γ) + α*(α + β)*(2*α + β + γ)). The command f5.full_simplify() returns an even longer result, and I'm getting tired of manually slogging through these extremely long expressions to completely simplify them.

Is there any way to get Sage to do a better job of completely simplifying these expressions?

Are there any techniques to improve the results of `simplify` or `full_simplify`?

(Updated to simplify the starting expression)

I have the following long expression, which I want to simplify for non-negative integer values of n:

var('A, B, C, D, E, α, β, γ')
D = A + E if E < 0 else A
fn = (
   (8*A (12*A + 6*B + 4*C + 4*D + 2*abs(E) 2*E + 4*α + 2*β + γ)^n
 - (7*A (11*A + 6*B + 4*C + 4*D + 2*abs(E) 2*E + 4*α + 2*β + γ)^n
 - (7*A (11*A + 5*B + 4*C + 4*D + 2*abs(E) 2*E + 4*α + 2*β + γ)^n
 + (6*A (10*A + 5*B + 4*C + 4*D + 2*abs(E) 2*E + 4*α + 2*β + γ)^n
 - (6*A (10*A + 5*B + 3*C + 4*D + 2*abs(E) 2*E + 4*α + 2*β + γ)^n
 + (5*A ( 9*A + 5*B + 3*C + 4*D + 2*abs(E) 2*E + 4*α + 2*β + γ)^n
 + (5*A ( 9*A + 4*B + 3*C + 4*D + 2*abs(E) 2*E + 4*α + 2*β + γ)^n
 - (5*A ( 8*A + 4*B + 3*C + 3*D + 2*abs(E) 2*E + 4*α + 2*β + γ)^n
 - (5*A ( 8*A + 4*B + 3*C + 3*D + abs(E)   E + 4*α + 2*β + γ)^n
 + (5*A ( 7*A + 4*B + 3*C + 2*D + abs(E)   E + 4*α + 2*β + γ)^n
 + (5*A ( 7*A + 3*B + 3*C + 2*D + abs(E)   E + 4*α + 2*β + γ)^n
 - (4*A ( 6*A + 3*B + 3*C + 2*D + abs(E)   E + 4*α + 2*β + γ)^n
 + (4*A + 3*B + 2*C + 2*D + abs(E) ( 6*A + 3*B + 2*C +   E + 4*α + 2*β + γ)^n
 - (4*A + 3*B + 2*C + 2*D + abs(E) ( 6*A + 3*B + 2*C +   E + 3*α + 2*β + γ)^n
 - (4*A + 3*B + 2*C + 2*D + abs(E) ( 6*A + 3*B + 2*C +   E + 3*α +  β + γ)^n
 + (4*A + 3*B + 2*C + 2*D + abs(E) ( 6*A + 3*B + 2*C +   E + 2*α +  β + γ)^n
 - (4*A + 3*B + 2*C + 2*D + abs(E) ( 6*A + 3*B + 2*C +   E + 2*α +  β)^n
 + (4*A + 3*B + 2*C + 2*D + abs(E) + ( 6*A + 3*B + 2*C +   E +   α +  β)^n
 + (4*A + 3*B + 2*C + 2*D + abs(E) + ( 6*A + 3*B + 2*C +   E +   α)^n
 - (4*A + 3*B + 2*C + 2*D + abs(E))^n
 + (4*A + 3*B + ( 6*A + 3*B + 2*C +   E)^n
 + ( 6*A + 3*B +   C + 2*D + abs(E))^n
 - (3*A + 3*B +   E)^n
 - ( 5*A + 3*B +   C + 2*D + abs(E))^n
 - (3*A   E)^n
 - ( 5*A + 2*B +  C + 2*D + abs(E))^n
 + (3*A   E)^n
 + ( 4*A + 2*B +  C + D + abs(E))^n
 + (3*A   E)^n
 + ( 4*A + 2*B + C + D)^n
 - (3*A   C)^n
 - ( 3*A + 2*B +  C)^n
 - (3*A + ( 3*A +   B +  C)^n
 + (2*A + ( 2*A +   B +  C)^n
 - (2*A + ( 2*A +   B)^n
 + (A + (   A +   B)^n
 +  A^n
)/factorial(n)

After replacing all ns with 0s, the command f0.full_simplify() returns the correct result of 1. After replacing all ns with 1s or 2s, the commands f1.full_simplify() or f2.full_simplify() return the correct result of 0.

However, for higher integer values of n, the output is no longer fully simplified. The command f3.full_simplify() returns the result

4*A^3 + 5*A^2*B 2*A^3 + 3*A^2*B + A*B^2 + 2*A^2*C - 2*(A - B - C)*D^2 + 2*D^3 - (A - D)*E^2 + 2*α^3 + α*β^2 - 2*(A^2 4*(A^2 + A*B)*α - (2*A^2 + 2*A*B + 2*A*C)*D - 4*(A*B + 2*A*D - D^2 + (A - D)*abs(E))*α - (2*A*B + 4*A*D - 2*D^2 - 3*α^2 + 2*(A - D)*abs(E))*β - (A*B + 2*A*D - D^2 - 3*α^2)*β - (A^2 + A*B - α^2 - α*β + (A - D)*abs(E))*γ - (A^2 + 2*A*B + 2*A*C + 2*(A - B - C)*D - 3*D^2)*abs(E)
α*β)*γ

which I was able to further simplify manually to get get

A*(A + B)*(2*A + B - 4*α - 2*β - γ) + α*(α + β)*(2*α + β + γ). γ)

Similarly, the command f4.full_simplify() returns the result

16*A^4 + 32*A^3*B + 19*A^2*B^2 12*A^4 + 24*A^3*B + 15*A^2*B^2 + 3*A*B^3 + 4*A^2*C^2 + 2*(2*A + 5*B + 4*C)*D^3 + 4*D^4 + 2*(4*A + 3*B + 2*C + 2*D + abs(E))*α^3 2*(6*A + 3*B + 2*C + E)*α^3 + 4*α^4 + α*β^3 - 2*(6*A^2 + 3*A*B - 3*B^2 + (2*A - 5*B)*C - 2*C^2)*D^2 - (5*A^2 + 5*A*B + 4*A*C - (5*B + 4*C)*D - 5*D^2)*E^2 - 8*(A*B + 2*A*D - D^2 + (A - D)*abs(E))*α^2 - (2*A*B + 4*A*D - 2*D^2 - (4*A + 3*B + 2*C + 2*D + abs(E))*α - 5*α^2 + 2*(A - D)*abs(E))*β^2 - 1/2*(A*B + 2*A*D - D^2 8*(A^2 + A*B)*α^2 - (2*A^2 + 2*A*B - (6*A + 3*B + 2*C + E)*α - 5*α^2)*β^2 - 1/2*(A^2 + A*B - α^2 - α*β + (A - D)*abs(E))*γ^2 + 2*(8*A^3 + 8*A^2*B α*β)*γ^2 + 2*(2*A^3 + 3*A^2*B + A*B^2)*C - 2*(6*A^2*B + (2*A^3 + 3*A^2*B + A*B^2)*E - 2*(10*A^3 + 15*A^2*B + 5*A*B^2 + 4*A*C^2 + 2*(4*A^2 + 5*A*B)*C)*D + 2*(4*A^3 - 3*A^2*B - 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E)*α - (10*A^3 + 15*A^2*B + 5*A*B^2 - 2*(A - 4*B - 3*C)*D^2 + 6*D^3 - 3*(A - D)*E^2 3*(6*A + 3*B + 2*C + E)*α^2 - 8*α^3 + 4*(A^2 + A*B)*C + 2*(A^2 - 2*A*B)*C - 2*(9*A^2 + 10*A*B + 6*A*C)*D - (9*A^2 + 10*A*B + 6*A*C + 2*(A - 4*B - 3*C)*D - 9*D^2)*abs(E))*α + (4*A^3 - 3*A^2*B - + A*B)*E + 8*(A^2 + A*B)*α)*β - 1/2*(10*A^3 + 15*A^2*B + 5*A*B^2 - 2*(A - 4*B - 3*C)*D^2 + 6*D^3 - 3*(A - D)*E^2 + 3*(4*A + 3*B + 2*C + 2*D + abs(E))*α^2 + 8*α^3 2*(6*A + 3*B + 2*C + E)*α^2 - 6*α^3 - 3*α*β^2 + 4*(A^2 + A*B)*C + 2*(A^2 - 2*A*B)*C - 2*(9*A^2 + 10*A*B + 6*A*C)*D - 8*(A*B + 2*A*D - D^2 + (A - D)*abs(E))*α - (9*A^2 + 10*A*B + 6*A*C + 2*(A - 4*B - 3*C)*D - 9*D^2)*abs(E))*β + 1/2*(4*A^3 - 3*A^2*B - 5*A*B^2 - 2*(A - 4*B - 3*C)*D^2 + 6*D^3 - 3*(A - D)*E^2 + 2*(4*A + 3*B + 2*C + 2*D + abs(E))*α^2 + 6*α^3 + 3*α*β^2 + 2*(A^2 - 2*A*B)*C - 2*(9*A^2 + 10*A*B + 6*A*C)*D - 8*(A*B + 2*A*D - D^2 + (A - D)*abs(E))*α - (4*A*B + 8*A*D - 4*D^2 - 2*(4*A + 3*B + 2*C + 2*D + abs(E))*α - 9*α^2 + 4*(A - D)*abs(E))*β - (9*A^2 + 10*A*B + 6*A*C + 2*(A - 4*B - 3*C)*D - 9*D^2)*abs(E))*γ - (6*A^2*B + 5*A*B^2 + 4*A*C^2 - 3*(2*A + 5*B + 4*C)*D^2 - 8*D^3 + (A - D)*E^2 + 2*(4*A^2 + 5*A*B)*C + 2*(6*A^2 + 3*A*B - 3*B^2 + (2*A - 5*B)*C - 2*C^2)*D)*abs(E)
+ A*B)*E + 8*(A^2 + A*B)*α + (4*A^2 + 4*A*B - 2*(6*A + 3*B + 2*C + E)*α - 9*α^2)*β)*γ

which I was able to manually simplify down to to

(6*A + 3*B + 2*C + E + 1/2*(4*α + 2*β + γ))*(A*(A + B)*(2*A + B - 4*α - 2*β - γ) + α*(α + β)*(2*α + β + γ)). γ))

The command f5.full_simplify() returns an the even longer result, result

137/2*A^5 + 685/4*A^4*B + 925/6*A^3*B^2 + 60*A^2*B^3 + 103/12*A*B^4 + 4*(6*A + 3*B + 2*C + E)*α^4 + 9/2*α^5 + 7/12*α*β^4 + 2*(A^2 + A*B)*C^3 + 1/3*(76*A^2 + 76*A*B + 27*B^2 + 36*(2*A + B)*C + 12*C^2 + 6*(6*A + 3*B + 2*C)*E + 3*E^2)*α^3 - 1/3*(4*A^2 + 4*A*B - 3*(6*A + 3*B + 2*C + E)*α - 12*α^2)*β^3 - 1/6*(A^2 + A*B - α^2 - α*β)*γ^3 + 10*(2*A^3 + 3*A^2*B + A*B^2)*C^2 + 1/2*(6*A^3 + 9*A^2*B + 3*A*B^2 + 2*(A^2 + A*B)*C)*E^2 - 4*(10*A^3 + 15*A^2*B + 5*A*B^2 + 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E)*α^2 - 1/6*(60*A^3 + 90*A^2*B + 30*A*B^2 - 30*(6*A + 3*B + 2*C + E)*α^2 - 61*α^3 + 24*(A^2 + A*B)*C + 12*(A^2 + A*B)*E - 3*(20*A^2 + 20*A*B + 9*B^2 + 12*(2*A + B)*C + 4*C^2 + 2*(6*A + 3*B + 2*C)*E + E^2)*α)*β^2 - 1/4*(10*A^3 + 15*A^2*B + 5*A*B^2 - 2*(6*A + 3*B + 2*C + E)*α^2 - 6*α^3 - 3*α*β^2 + 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E + 8*(A^2 + A*B)*α + (4*A^2 + 4*A*B - 2*(6*A + 3*B + 2*C + E)*α - 9*α^2)*β)*γ^2 + 16*(4*A^4 + 8*A^3*B + 5*A^2*B^2 + A*B^3)*C + (28*A^4 + 56*A^3*B + 35*A^2*B^2 + 7*A*B^3 + 3*(A^2 + A*B)*C^2 + 9*(2*A^3 + 3*A^2*B + A*B^2)*C)*E - 1/3*(55*A^4 + 110*A^3*B + 69*A^2*B^2 + 14*A*B^3 + 12*(A^2 + A*B)*C^2 + 6*(A^2 + A*B)*E^2 + 24*(2*A^3 + 3*A^2*B + A*B^2)*C + 6*(6*A^3 + 9*A^2*B + 3*A*B^2 + 2*(A^2 + A*B)*C)*E)*α - 1/12*(110*A^4 + 220*A^3*B + 138*A^2*B^2 + 28*A*B^3 - 96*(6*A + 3*B + 2*C + E)*α^3 - 135*α^4 + 24*(A^2 + A*B)*C^2 + 12*(A^2 + A*B)*E^2 - 6*(76*A^2 + 76*A*B + 27*B^2 + 36*(2*A + B)*C + 12*C^2 + 6*(6*A + 3*B + 2*C)*E + 3*E^2)*α^2 + 48*(2*A^3 + 3*A^2*B + A*B^2)*C + 12*(6*A^3 + 9*A^2*B + 3*A*B^2 + 2*(A^2 + A*B)*C)*E + 48*(10*A^3 + 15*A^2*B + 5*A*B^2 + 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E)*α)*β - 1/12*(55*A^4 + 110*A^3*B + 69*A^2*B^2 + 14*A*B^3 - 36*(6*A + 3*B + 2*C + E)*α^3 - 55*α^4 - 14*α*β^3 + 12*(A^2 + A*B)*C^2 + 6*(A^2 + A*B)*E^2 - 6*(20*A^2 + 20*A*B + 9*B^2 + 12*(2*A + B)*C + 4*C^2 + 2*(6*A + 3*B + 2*C)*E + E^2)*α^2 + 3*(8*A^2 + 8*A*B - 6*(6*A + 3*B + 2*C + E)*α - 23*α^2)*β^2 + 24*(2*A^3 + 3*A^2*B + A*B^2)*C + 6*(6*A^3 + 9*A^2*B + 3*A*B^2 + 2*(A^2 + A*B)*C)*E + 24*(10*A^3 + 15*A^2*B + 5*A*B^2 + 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E)*α + 2*(60*A^3 + 90*A^2*B + 30*A*B^2 - 27*(6*A + 3*B + 2*C + E)*α^2 - 55*α^3 + 24*(A^2 + A*B)*C + 12*(A^2 + A*B)*E - 3*(20*A^2 + 20*A*B + 9*B^2 + 12*(2*A + B)*C + 4*C^2 + 2*(6*A + 3*B + 2*C)*E + E^2)*α)*β)*γ

and I'm getting tired of manually slogging through these extremely long rapidly-increasingly-long expressions to completely simplify them.

Is there any way to get Sage to do a better job of completely simplifying these expressions?