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 n
s with 0
s, the command f0.full_simplify()
returns the correct result of 1
. After replacing all n
s with 1
s or 2
s, 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?