1
$\begingroup$

This question already has an answer here:

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$

marked as duplicate by Daniel Lichtblau, Coolwater, m_goldberg, Kuba Jan 19 '18 at 6:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\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$ – Daniel Lichtblau Jan 18 '18 at 17:44
  • $\begingroup$ This sort of thing probably qualifies as an FAQ on this site, by the way. $\endgroup$ – Daniel Lichtblau Jan 18 '18 at 17:44
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$
  • $\begingroup$ I don't think you need expr = Expand[expr], do you? $\endgroup$ – anderstood Jan 18 '18 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$ – Nasser Jan 18 '18 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$ – Mark Jan 18 '18 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$

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