Is there a way to get SageMath to completely simplify this family of expressions, particularly for $n = 5$?

168 Views Asked by At

I am using SageMath for the first time. I have the following long expression, which I want to simplify for integer values of n from 0 to 5:

var('A, B, C, E, d, α, β, γ')
f = lambda n : (
   (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)

The command f(0).full_simplify() returns the correct result of 1. The commands f(1).full_simplify() and f(2).full_simplify() return the correct result of 0.

However, for higher integer values of n, the output is no longer fully simplified. The command f(3).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

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

The command f(5).full_simplify() returns the substantially-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 haven't simplified it further yet because I'm getting tired of manually slogging through these rapidly-increasingly-long expressions to completely simplify them.

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

I did try asking Sage to factor f(5), hoping it could pull out a factor of A*(A + B)*(2*A + B - 4*α - 2*β - γ) + α*(α + β)*(2*α + β + γ) or 6*A + 3*B + 2*C + E + (4*α + 2*β + γ)/2 since f(4) is equivalent to f(3) multiplied by the latter term and I hoped that a similar relationship might hold for f(5) as well, but with no luck. I also asked Sage to divide f(5) by those terms and simplify, but it just tacked the divisor on the end of the expression with no further simplification.

1

There are 1 best solutions below

0
On

I "simplified" your $f(5)$ in my answer to your later question where I sorted-through the expanded form looking for patterns and groupings. I was going to amend that answer with some notes about looking at the un-expanded form of $f(5)$, but since it's already quite long, and this question asks about it directly, I thought I'd answer separately here.

As mentioned in that other answer, the substitutions are convenient: $$A\to a \qquad B\to b-a \qquad C\to c-(a+b) \qquad E\to d-(a+b+c)$$ $$\alpha\to e \qquad \beta\to f-e \qquad \gamma\to g-(e+f)$$ Your "$E$" in this question is "$D$" there. And your "$d$" in this question is unused, so there should be no confusion in my using "$d$" here. Finally, your "$\alpha$", "$\beta$", "$\gamma$" here are "$E$", "$F$", "$G$" there, which helps explain the $e$, $f$, $g$ in the substitutions.)

Also, as per my previous answer, I'll define $$p := e+f+g$$ Here, I'll introduce $$u := a+b \qquad v := c+d$$ In the context of the function $f(n)$, the terms look slightly more compact after the substitutions. With a bit of re-ordering to put like terms together, we have

$$\begin{align} + &\;a^n + (-a - c)^n + (-a - d)^n \\ + &\;(-a + 2 c + d + p)^n + (-a + c + 2 d + p)^n + (a - 2 c - 2 d - p )^n \\ \\ + &\;b^n + (-b - c)^n + (-b - d)^n \\ + &\;(-b + 2 c +d + p)^n + (-b + c + 2 d + p)^n + (b - 2 c - 2 d - p)^n \\ \\ + &\;(-a - b)^n \\ + &\;(a + b + c)^n+(a + b + d)^n \\ + &\;(-a - b + 2 c + 2 d + p)^n + ( a + b - c - 2 d - p)^n + ( a + b - 2 c - d - p)^n \\ \\ + &\;c^n + d^n \\ + &\;( -c - d)^n\\ + &\;( c + d + e )^n + ( c + d + f )^n +( c + d + g)^n \\ + &\;(-c - d - f - g)^n + (-c - d - e - g)^n +(-c - d - e - f)^n \\ + &\;( c + d + p)^n + (-c - 2 d - p)^n + (-2 c - d - p)^n + ( 2 c + 2 d + p)^n \end{align}$$

In this form, we clearly see that the expression is symmetric in $a$ and $b$, in $c$ and $d$, and in $e$, $f$, $g$.

For an attempt to simplify $f(n)$ for $n$ odd, we can consider leveraging the factorization $$x^{2m+1} + y^{2m+1} \;=\; (x+y)\;\left(x^{2m} - x^{2m-1} y + x^{2m-2} y^2 - \cdots + x y^{2m-1} + y^{2m} \right)$$ The salient point here is the factor $x+y$; conveniently pairing terms of $f(n)$ gives us some common factors, thusly:

$$\begin{align} a^n + ( b - 2 v - p )^n \;&= \phantom{-}(u-2v-p)\;(\;\cdots\;)\\ b^n + ( a - 2 v - p )^n \;&= \phantom{-}(u-2v-p)\;(\;\cdots\;) \\ (-u)^n + (2 v + p )^n \;&=-(u-2v-p)\;(\;\cdots\;) \\ (-u + 2 v + p )^n \;&=-(u-2v-p)\;(\;\cdots\;) \\ \\ (- c - 2d - p)^n + (u+d)^n \;&= \phantom{-}(u - v - p )\;(\;\cdots\;)\\ (- 2c-d - p)^n + (u + c)^n \;&= \phantom{-}( u - v - p )\;(\;\cdots\;) \\ (u - 2 c - d - p)^n + c^n \;&= \phantom{-}( u - v - p )\;(\;\cdots\;) \\ (u - c - 2 d - p)^n + d^n \;&= \phantom{-}( u - v - p )\;(\;\cdots\;) \\ (- a + 2 c + d + p)^n + (-b - c)^n \;&=-(u-v-p)\;(\;\cdots\;) \\ (- b + 2 c + d + p)^n + (-a - d)^n \;&=-(u-v-p)\;(\;\cdots\;) \\ (- b + c + 2 d + p)^n + (-a - c)^n \;&=-(u-v-p)\;(\;\cdots\;) \\ (- a + c + 2 d + p)^n + (-b - d)^n \;&=-(u-v-p)\;(\;\cdots\;) \end{align}$$

Expanding all of the "$(\;\cdots\;)$"s and combining the results is still quite an ordeal. (Maybe re-grouping everything into "multiples of $p-u$" and "multiples of $v$" would help. I haven't looked into that.) So is expanding the remaining terms to get $$\begin{align} &\;\phantom{+}(-v)^5 + (v+ e)^5 + (v+ f)^5 + (v+ g)^5 \\ &+(-v-f - g)^5 + (-v- e - g)^5 + (-v- e - f)^5 + (v +p)^5 \\ &= \;10 e f g(\;\cdots\;) \end{align}$$

It's not at all obvious that the final form can be written as in my previous answer.

Anyway, it's clear —especially after the substitutions— that there's a good bit of structure to these expressions, so there may yet be a way to get from the original form to a "reduced" form that reflects that structure.