Replacing complicated variables in an equation

My goal is to simplify the expressions for Eigenvalues obtained from the following 3x3 matrix:

M3 = {{-I*ω + Γ/2, -I*g1,
0}, {-I*g1, -I*ω + κ1/2, -I*g2}, {0, - I*
g2, -I*ω + κ2/2}};


Finding eigenvalues and eigenvectors

valsM3 = Eigenvalues[M3, Cubics -> True];
vecsM3 = Simplify[
Eigenvectors[M3 /. Complex[0, -1] -> mi, Cubics -> True] /.
mi -> -I];


Now if I print the first eigenvalue

valsM3[[1]]


I get a long expression with variables of κ1, κ2, Γ etc. I intend to simplify the expression by redefining certain variables. However, the simple replacement won't do the trick. For example:

valsM3[[1]] /. {(g1^2 + g2^2) -> p} // Simplify


won't replace said variables g1^2+g2^2. It will work if i only replace g1^2 or g2^2.

After I did some homework, I found out I could do Simplify:

Simplify[valsM3[[1]],
p == g1^2 + g2^2]


This works but there are a lot more simplifications left to be done and redefining new variables and adding them to the third argument of simplify clearly doesn't work:

Simplify[valsM3[[1]],
p == g1^2 + g2^2,
f1 == κ1 + κ2 + Γ]


Nesting many loops of Simplify makes the problem intractable since the expressions are really long. And i intend to redefine the variables for the other two eigenvalues as well. What is the best approach here to redefine certain combinations of variables in the eigenvalues?

Thank you in advance for the help.

• Sometimes it may help to simply eliminate a variable with valsM3[[1]] /. {g1^2 -> p - g2^2} // Simplify. But I doubt that there will be a concensus on the "best" method. Such simplifcations are always a matter of taste and a keen eye. If computers could do that automatically, there would be a bit less demand for mathemagicians in the world... – Henrik Schumacher Aug 15 '18 at 21:33
• Your question is not quite clear, since in some places of your expression there are, indeed, combinations like a*g1^2 + a*g2^2 with some numerical factor a, but in other places there are a*g1^2 + b*g2^2 where a differs from b. You should write, what to do with such a situation? Leave as it is, or transform into a*p +(b-a)g^2, or what? If you only want to replace the combination a*g1^2 + a*g2^2 you might try the rule a_*g1^2 + a_*g2^2 -> a*p. In the second case try a_*g1^2 + b_*g2^2 -> a*p + (b - a) g2^2 or the one offered by @Henrik Schumacher – Alexei Boulbitch Aug 16 '18 at 11:37