12
$\begingroup$

I would like to replace every possible $A+B$ and $AB$ in expansion of $(A+B)^{10}-A^{10}-B^{10}$ with
$x$ and $y$, respectively. How to do it with the simplest code in Mathematica?

For example,

\begin{align*} (A+B)^3-A^3-B^3 &= 3AB(A+B)\\ &= 3xy \end{align*}

In other words, having $A+B=x$ and $AB=y$, how do I express $(A+B)^{10}-A^{10}-B^{10}$ in terms of $x$ and $y$.

Bonus question

Rather than creating a new question for it, I think I should ask here. If I want to find $a^{10}+b^{10}$ in terms of $x$ and $y$, why does

Simplify[(a + b)^10 - Expand[(a + b)^10 - a^10 - b^10],a b == x && a + b == y] 

not produce the expected result?

$\endgroup$
1

4 Answers 4

17
$\begingroup$

You can use GroebnerBasis:

eq = (a + b)^10 - a^10 - b^10; eqXY = GroebnerBasis[{eq, a + b - x, a b - y}, {x, y}, {a, b}]; (*out*){10 x^8 y - 35 x^6 y^2 + 50 x^4 y^3 - 25 x^2 y^4 + 2 y^5} 

Check:

First@Expand[eqXY /. x -> (a + b) /. y -> a b] === Expand[eq] (*out*)True 

--EDIT--

Following @DanielLichtblau's suggestion, it's better to do this in two steps: first find a Groebner basis (of the polynomials corresponding to the transformation equations) and then reduce your polynomial in terms of the basis to account for the case where not all variables get eliminated. I trust he knows what he's talking about having written parts of the function :). So,

With[{ vars = {a, b}, relations = {a + b - x, a b - y}, poly = (a + b)^10 - a^10 - b^10}, PolynomialReduce[poly, GroebnerBasis[relations, vars], vars]] // Last (*out*){10 x^8 y - 35 x^6 y^2 + 50 x^4 y^3 - 25 x^2 y^4 + 2 y^5} 

is safer. In fact, I realised your question is answered by one of the examples in the "Applications" section of the documentation for PolynomialReduce

$\endgroup$
4
  • $\begingroup$ If I want to find $a^{10}+b^{10}$ in terms of $x$ and $y$, why does Simplify[(a + b)^10 - Expand[(a + b)^10 - a^10 - b^10], a b == x && a + b == y] not produce the expected result? $\endgroup$ Commented Oct 4, 2013 at 13:38
  • $\begingroup$ GroebnerBasis[{a^10 + b^10, a + b - x, a b - y}, {x, y}, {a, b}] produces the expected result. $\endgroup$ Commented Oct 4, 2013 at 13:42
  • 3
    $\begingroup$ This is reasonable (I upvoted..) I'd recommend separating into a GB followed by polynomial reduction though. In[607]:= vars = {a, b, x, y}; In[608]:= PolynomialReduce[(a + b)^3 - (a^3 + b^3), GroebnerBasis[{a + b - x, a*b - y}, vars], vars][[2]] Out[608]= 3 x y Reason being that the replacement will not in general result in certain variables being eliminated, so a GB alone might not suffice. $\endgroup$ Commented Oct 4, 2013 at 14:06
  • $\begingroup$ Thanks a lot - I edited to match the example in the documentation. $\endgroup$ Commented Oct 4, 2013 at 18:24
9
$\begingroup$

You can use Simplify and give your replacements as assumptions:

Simplify[(a + b)^3 - a^3 - b^3, a + b == x && a b == y] (* 3 x y *) (* For higher n seems like you have to Expand first *) Simplify[(a + b)^10 - a^10 - b^10 // Expand, a + b == x && a b == y] (* y (10 x^8 - 35 x^6 y + 50 x^4 y^2 - 25 x^2 y^3 + 2 y^4) *) (* Or alternatively use a custom ComplexityFunction *) Simplify[ (a + b)^n - a^n - b^n, a + b == x && a b == y, ComplexityFunction -> (Count[#, a | b, Infinity] &)] // Simplify 
$\endgroup$
2
  • $\begingroup$ If I want to find $a^{10}+b^{10}$ in terms of $x$ and $y$, why does Simplify[(a + b)^10 - Expand[(a + b)^10 - a^10 - b^10], a b == x && a + b == y] not produce the expected result? $\endgroup$ Commented Oct 4, 2013 at 13:34
  • $\begingroup$ @PGFTricks The goal of Simplify is to minimize its ComplexityFunction the default one is similar to LeafCount and a^10 + b^10 is pretty darn simple as far as it is concerned. You can search ComplexityFunction on this site for examples with adding penalty to expressions you don't want when simplifying. $\endgroup$ Commented Oct 4, 2013 at 13:36
6
$\begingroup$

A very simple approach is the following :

el[n_] := Eliminate[ {r == (A + B)^n - A^n - B^n , x == A + B , y == A*B}, {A,B}]//First Expand[Array[el, 10]] // TableForm 
$\endgroup$
4
$\begingroup$

An approach:

pol[n_] := Expand[(a + b)^n - a^n - b^n] sol = Solve[{a + b == x, a b == y}, {a, b}][[1]]; fun[n_] := Expand@Simplify[pol[n] /. sol] 

Tabulating:

Table[{(a + b)^j - a^j - b^j, fun[j]}, {j, 2, 10}] // Grid 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.