# How to replace an expression with a variable?

Given the following expresion

expr = (I Gr0 theta Sqrt[1 - theta^2])/((2 Gr0Mz (-1 + theta^2) (1 - 2 coff1*theta trMz wn + coff1^2 trMz^2 wn^2)) + Sin[a] + Cos[b]) + (Exp[c] + Log[d])/((2 Gr0Mz (-1 + theta^2) (1 - 2 coff1 theta trMz wn + coff1^2 trMz^2 wn^2)) + Exp[c]
);


I want to do the following replacement：

(2 Gr0Mz (-1 + theta^2) (1 - 2 coff1 theta trMz wn + coff1^2 trMz^2 wn^2))->Tp


How to do?

• expr /. (2 Gr0Mz (-1 + theta^2) (1 - 2 coff1 theta trMz wn + coff1^2 trMz^2 wn^2)) -> Tp – Bill Jul 1 '18 at 16:35
• Or expr /. Gr0Mz -> Tp/ (2 (-1 + theta^2) (1 - 2 coff1 theta trMz wn + coff1^2 trMz^2 wn^2)) – Jens Jul 1 '18 at 16:37

In addition to the suggestions by Bill and Jens in the comments, you can do:

Replace[expr, (2 Gr0Mz (-1 + theta^2) (1 - 2 coff1 theta trMz wn +
coff1^2 trMz^2 wn^2)) -> Tp, {0, Infinity}]


(E^c + Log[d])/(E^c + Tp) + (I Gr0 theta Sqrt[1 - theta^2])/( Tp + Cos[b] + Sin[a])

or

Apart @ Simplify[expr, {(2 Gr0Mz (-1 + theta^2) (1 - 2 coff1 theta trMz wn +
coff1^2 trMz^2 wn^2)) == Tp}]


1 + (-Tp + Log[d])/(E^c + Tp) + (I Gr0 theta Sqrt[1 - theta^2])/( Tp + Cos[b] + Sin[a])

Simplify[Equal[%, %%]]


True