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, E, α, β, γ')
fn = (
(12*A + 6*B + 4*C + 2*E + 4*α + 2*β + γ)^n
- (11*A + 6*B + 4*C + 2*E + 4*α + 2*β + γ)^n
- (11*A + 5*B + 4*C + 2*E + 4*α + 2*β + γ)^n
+ (10*A + 5*B + 4*C + 2*E + 4*α + 2*β + γ)^n
- (10*A + 5*B + 3*C + 2*E + 4*α + 2*β + γ)^n
+ ( 9*A + 5*B + 3*C + 2*E + 4*α + 2*β + γ)^n
+ ( 9*A + 4*B + 3*C + 2*E + 4*α + 2*β + γ)^n
- ( 8*A + 4*B + 3*C + 2*E + 4*α + 2*β + γ)^n
- ( 8*A + 4*B + 3*C + E + 4*α + 2*β + γ)^n
+ ( 7*A + 4*B + 3*C + E + 4*α + 2*β + γ)^n
+ ( 7*A + 3*B + 3*C + E + 4*α + 2*β + γ)^n
- ( 6*A + 3*B + 3*C + E + 4*α + 2*β + γ)^n
+ ( 6*A + 3*B + 2*C + E + 4*α + 2*β + γ)^n
- ( 6*A + 3*B + 2*C + E + 3*α + 2*β + γ)^n
- ( 6*A + 3*B + 2*C + E + 3*α + β + γ)^n
+ ( 6*A + 3*B + 2*C + E + 2*α + β + γ)^n
- ( 6*A + 3*B + 2*C + E + 2*α + β)^n
+ ( 6*A + 3*B + 2*C + E + α + β)^n
+ ( 6*A + 3*B + 2*C + E + α)^n
- ( 6*A + 3*B + 2*C + E)^n
+ ( 6*A + 3*B + C + E)^n
- ( 5*A + 3*B + C + E)^n
- ( 5*A + 2*B + C + E)^n
+ ( 4*A + 2*B + C + E)^n
+ ( 4*A + 2*B + C)^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
2*A^3 + 3*A^2*B + A*B^2 + 2*α^3 + α*β^2 - 4*(A^2 + A*B)*α - (2*A^2 + 2*A*B - 3*α^2)*β - (A^2 + A*B - α^2 - α*β)*γ
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
12*A^4 + 24*A^3*B + 15*A^2*B^2 + 3*A*B^3 + 2*(6*A + 3*B + 2*C + E)*α^3 + 4*α^4 + α*β^3 - 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 - α*β)*γ^2 + 2*(2*A^3 + 3*A^2*B + A*B^2)*C + (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^2 + A*B)*C + 2*(A^2 + A*B)*E)*α - (10*A^3 + 15*A^2*B + 5*A*B^2 - 3*(6*A + 3*B + 2*C + E)*α^2 - 8*α^3 + 4*(A^2 + A*B)*C + 2*(A^2 + A*B)*E + 8*(A^2 + A*B)*α)*β - 1/2*(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)*β)*γ
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 the even longer 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 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?
Maybe use polynomial rings instead of the symbolic ring ?
What does that mean? I'm very new to Sage and don't know what rings are.
@FrédéricC can you explain how to use polynomial rings for this? Or do you know of a good resource that explains it? This is my first time using Sage and I can't figure out how to deal with rings.
Replace usage of
var
byA,B,C,D,E,F,G,H=polygens(QQ,'A,B,C,D,E,F,G,H')
.