# Reverse substitution [duplicate]

If you apply rules and then simplify you may get something like.

(25 A^2 hbar Sqrt[π])/Sqrt[hbar m w]


How would you get mathematica to rewrite this in terms of E where

E -> Sqrt[ m w/ hbar ] x


It's very easy to plug E into things, but I don't know how to get it back out. Further, I keep running into situations where I wish I could do this, and then end up having to finish what I am doing on paper. Any ideas?

Clear["Global*"]

expr = (25 A^2 hbar Sqrt[π])/Sqrt[hbar m w];


Presumably, your E is not intended to be the numeric constant 2.71828... Using \[DoubleStruckCapitalE] instead

rule = \[DoubleStruckCapitalE] -> Sqrt[m w/hbar] x;


Assuming that {m > 0, w > 0, x > 0, \[DoubleStruckCapitalE] > 0}

expr /. Solve[Equal @@ rule, hbar][[1]] //
Simplify[#, {m > 0, w > 0, x > 0, \[DoubleStruckCapitalE] > 0}] &

(* (25 A^2 Sqrt[π] x)/\[DoubleStruckCapitalE] *)
`