Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way to tell Mathematica to replace $\kappa^2 + k_z^2 \rightarrow k^2$ in an expression? I want to make a result more readable, e.g. something like this:

$$\frac{2 k_z^3 \sqrt{k_z^2 + \kappa^2} + 2 k_z \kappa^2 \sqrt{k_z^2 + \kappa^2} + k_z \sqrt{k_z^2 + \kappa^2} \mu^2}{2 (k_z^4 + 2 k_z^2 \kappa^2 + \kappa^4)}$$

(2 kz^3 Sqrt[kz^2 + κ^2] + 2 kz κ^2 Sqrt[kz^2 + κ^2] + kz Sqrt[kz^2 + κ^2] μ^2)/
 (2 (kz^4 + 2 kz^2 κ^2 + κ^4))

Which can be simplified to:

$$k_z \frac{ (2k^2 + \mu^2) }{2k^3}$$

But I can't get Mathematica to perform this substitution. I have made sure to use the proper assumptions for this to work:


Yet it seems to not see the (arguably trivial) patterns. Does anyone know how to trick Mathematica into doing what I want :-)?

share|improve this question
Related: [(… – eldo Jun 6 '14 at 11:53
Generally speaking this is in a class problem that is difficult, and has many variations. I collected links to related questions here: Can I simplify an expression into form which uses my own definitions? – Mr.Wizard Jun 6 '14 at 11:56
@rubenvb - please provide your formulas in Mathematica InputForm so that others can copy them. – eldo Jun 6 '14 at 12:00

This is your expression:

expr = (2 kz^3 Sqrt[kz^2 + \[Kappa]^2] + 
 2 kz \[Kappa]^2 Sqrt[kz^2 + \[Kappa]^2] + 
 kz Sqrt[kz^2 + \[Kappa]^2] \[Mu]^2)/(2 (kz^4 + 
   2 kz^2 \[Kappa]^2 + \[Kappa]^4));

This gives us the substitution:

    sl = Solve[kz^2 + \[Kappa]^2 == k^2, \[Kappa]][[2, 1]]

(*  \[Kappa] -> Sqrt[k^2 - kz^2]   *)

An here it acts on your expression yielding the desired result:

 Simplify[expr /. sl, {k > 0, \[Kappa] > 0}]

(*  (kz (2 k^2 + \[Mu]^2))/(2 k^3)   *)

It is basically almost the same as in the eldo's answer, but has the advantage that when one takes the replacement kz^2 + \[Kappa]^2 -> k^2Mma in some situations understands it, but may miss in some others. So, it may require some additional efforts. In contrast with the above substitution everything goes smooth.

share|improve this answer

The following will work, but it's probably not the best way

PowerExpand[FullSimplify[(2 kz^3 Sqrt[kz^2 + κ^2] + 2 kz κ^2 Sqrt[kz^2 + κ^2] + 
      kz Sqrt[kz^2 + κ^2] μ^2)/(2 (kz^4 + 2 kz^2 κ^2 + κ^4)) /. 
      kz^(2 a__) -> (k^2 - κ^2)^a] /. (kz^2 + κ^2) -> k^2]


(kz (2 k^2 + μ^2))/(2 k^3)
share|improve this answer

Well, in exploring the physics of my result, I got an idea that helps to get What I Want™:

thing:=(2 kz^3 Sqrt[kz^2 + κ^2] + 2 kz κ^2 Sqrt[kz^2 + κ^2] + kz Sqrt[kz^2 + κ^2] μ^2)/(2 (kz^4 + 2 kz^2 κ^2 + κ^4));

thing /. kz->k Cos[α] /. κ->k Sin[α]//Simplify
% /. α->ArcCos[kz/k]

It's literally a workaround, but it does the trick quite nicely in this and probably similar cases.

share|improve this answer

no doubt covered in the above links, but since I worked it out:

 thing = (2 kz^3 Sqrt[kz^2 + kappa^2] + 
      2 kz kappa^2 Sqrt[kz^2 + kappa^2] + 
         kz Sqrt[kz^2 + kappa^2] mu^2)/(2 (kz^4 + 2 kz^2 kappa^2 + 
 f = # /. Table[ (kz^2)^n -> (K^2 - kappa^2)^n , {n, 1, 2}] &;
 cpx[e_] := 100 Count[e, kz, {0, Infinity}] + LeafCount[e] 
 Simplify[ thing , TransformationFunctions -> {Automatic, f}, 
                   ComplexityFunction -> cpx, Assumptions -> K > 0] 

(kz (2 K^2 + mu^2))/(2 K^3)

The ComplexityFunction is a not-so-obvious key here. The intermediate results of the transformation are evidently deemed more complex by the default and not applied.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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