Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
Related: Am I missing anything? Solving Equations –  Artes Oct 6 '13 at 18:03

4 Answers 4

up vote 16 down vote accepted

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

share|improve this answer
    
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? –  Please don't touch Oct 4 '13 at 13:38
    
GroebnerBasis[{a^10 + b^10, a + b - x, a b - y}, {x, y}, {a, b}] produces the expected result. –  gpap Oct 4 '13 at 13:42
3  
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. –  Daniel Lichtblau Oct 4 '13 at 14:06
    
Thanks a lot - I edited to match the example in the documentation. –  gpap Oct 4 '13 at 18:24

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
share|improve this answer
    
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? –  Please don't touch Oct 4 '13 at 13:34
    
@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. –  ssch Oct 4 '13 at 13:36

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
share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.