1
$\begingroup$

I have a complicate expression like this

2 a g12 (b (-1 + b c) g12^2 + b (1 - b c) g11 g22 + c g22^2) + g22 ((-1 + b^2 c^2) g12^2 + c^2 g22 (-b^2 g11 + g22)) + a^2 (g12^2 g22 + b^2 g11 (g12^2 - g11 g22)) 

and would like to expand it and replace g11 a^2 + 2 g12 a c + g22 c^2 with g11. Tried out Expand, Replace, Collect, Sort, etc. but it didn't work. Can anyone help?

$\endgroup$
2
  • $\begingroup$ Maybe In[2980]:= PolynomialReduce[ 2 a g12 (b (-1 + b c) g12^2 + b (1 - b c) g11 g22 + c g22^2) + g22 ((-1 + b^2 c^2) g12^2 + c^2 g22 (-b^2 g11 + g22)) + a^2 (g12^2 g22 + b^2 g11 (g12^2 - g11 g22)), g11 a^2 + 2 g12 a c + g22 c^2 - g11, Join[Complement[Variables[eee], {g11}], {g11}]][[2]] Out[2980]= b^2 g11 g12^2 - 2 a b g12^3 - b^2 g11^2 g22 + 2 a b g11 g12 g22 - g12^2 g22 + a^2 g12^2 g22 + 2 a c g12 g22^2 + c^2 g22^3 ? $\endgroup$ Commented Jan 18, 2018 at 17:44
  • $\begingroup$ This sort of thing probably qualifies as an FAQ on this site, by the way. $\endgroup$ Commented Jan 18, 2018 at 17:44

2 Answers 2

3
$\begingroup$

Is this what you mean?

expr = 2 a g12 (b (-1 + b c) g12^2 + b (1 - b c) g11 g22 + c g22^2) + g22 ((-1 + b^2 c^2) g12^2 + c^2 g22 (-b^2 g11 + g22)) + a^2 (g12^2 g22 + b^2 g11 (g12^2 - g11 g22)); rep = g11 a^2 + 2 g12 a c + g22 c^2; expr = Expand[expr] 

Mathematica graphics

And now

Simplify[expr,rep==g11] 

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ I don't think you need expr = Expand[expr], do you? $\endgroup$ Commented Jan 18, 2018 at 16:39
  • 1
    $\begingroup$ @anderstood no, ofcourse not. But I just wanted to show the expression when expanded on the screen, since OP said he wanted to expand it. But internally, it work without explicit expand ofcourse. Thanks. $\endgroup$ Commented Jan 18, 2018 at 16:45
  • $\begingroup$ Maybe it is what I'm looking for but I'm not sure... Is it possible to see, before it simplifies, how it explicitly collects the expression g11 a^2 + 2 g12 a c + g22 c^2 on one side (or in a parentheses) and only later replaces it? $\endgroup$ Commented Jan 18, 2018 at 17:29
2
$\begingroup$

You could try Eliminate to eliminate either g22 or g12:

Eliminate[{ eq1 == 2 a g12 (b (-1 + b c) g12^2 + b (1 - b c) g11 g22 + c g22^2) + g22 ((-1 + b^2 c^2) g12^2 + c^2 g22 (-b^2 g11 + g22)) + a^2 (g12^2 g22 + b^2 g11 (g12^2 - g11 g22)), g11 a^2 + 2 g12 a c + g22 c^2 == g11 }, g22 ] 

If necessary you can then use Solve and Simplify to solve for the temporary variable eq1:

Simplify[eq1 /. First @ Solve[%, eq1]] 
$\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.