2
$\begingroup$

I would like to know whether there is a way in Mathematica to simplify an expression including the introduction of symbols for repeated terms, like so:

SimplifyWithSubstitution[(a+b)^7+(a+b)^3+(a+b)^2-a-b]

should yield

C^7+C^3+C^2-C, C=a+b

Note that I do want Mathematica to figure out that the expression can be shortened by substituting a+b.

$\endgroup$
  • $\begingroup$ Shouldn't that be - a - b in the last part? Anyway: Eliminate[{res == (a + b)^7 + (a + b)^3 + (a + b)^2 - a - b, c == a + b}, {a, b}] $\endgroup$ – J. M. is in limbo Nov 14 '17 at 13:09
  • $\begingroup$ Of course there was a sign error, thanks! Your proposal requires the user to recognize that a+b is repeated and may be replaced, I want MMA to do this. $\endgroup$ – Rainer Glüge Nov 14 '17 at 13:42
  • $\begingroup$ Experimental`OptimizeExpression[] gets pretty close: Experimental`OptimizeExpression[(a + b)^7 + (a + b)^3 + (a + b)^2 - a - b] $\endgroup$ – J. M. is in limbo Nov 14 '17 at 13:44
  • $\begingroup$ Well thanks, thats what I needed! $\endgroup$ – Rainer Glüge Nov 14 '17 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.