# Simplify or rules don't work with square roots

I am trying to simplify a complicated expression and neither Simplify nor rules are working for me.

Here is a very basic example of what I am trying to do:

Simplify doesn't do any simplification and rules somehow don't apply for the denominator.

How can I get Mathematica to simplify the expression to Sin[z]/z?

My Mathematica input:

Simplify[Sin[Sqrt[x + y]]/Sqrt[x + y], Sqrt[x + y] == z]

Sin[Sqrt[x + y]]/Sqrt[x + y] /. {Sqrt[x + y] -> z}

• Try FullForm[Sqrt[x+z]] and FullForm[1/Sqrt[x+z]]. These show the actual expressions you are trying to transform, not the typeset version that you see in the Front End. – Michael E2 Apr 30 '20 at 0:31
• Possible duplicate: mathematica.stackexchange.com/a/29219/4999 – Michael E2 Apr 30 '20 at 0:44
• People here generally like users to post code as Mathematica code instead of just images or TeX, so they can copy-paste it. It makes it convenient for them and more likely you will get someone to help you. You may find this meta Q&A helpful – Michael E2 Apr 30 '20 at 0:46
• Hey Michael, thank you for that link! Is there a way to also paste Mathematica's output? I wanted to show what I tried together with the output to show how my approach was not working.. – Danvil Apr 30 '20 at 2:23
• You can paste output in the same was as input. Note that square-roots will be formatted as Sqrt[..], so sometimes I paste an image of the output when I want to show the typeset form. The principal point of the link is that making input copy-pasteable is a convenience to others that invites their help. – Michael E2 Apr 30 '20 at 2:46

Another way:

Sin[Sqrt[x + y]]/Sqrt[x + y] /. (x + y)^(r_) :> z^(2 r)
(*  Sin[z]/z  *)


You can simplify using Surd[ ,2] instead of Sqrt

Sin[Surd[x + y, 2]]/Surd[x + y, 2] /. Surd[x + y, 2] -> z
Sin[z]/z

• Note that Surd[z, 2] is equivalent to Sqrt[z] only if z is nonnegative real. – Michael E2 Apr 30 '20 at 1:32

Another option is to help it a little

ClearAll[x, y];
expr = Sin[Sqrt[x + y]]/Sqrt[x + y]


expr /. {1/Sqrt[x + y] -> 1/z, Sqrt[x + y] -> z}


• +1. Nice to have an assumption-free alternative. I often do it this way, because copy-paste-edit makes it easy to type both rules. – Michael E2 Apr 30 '20 at 12:14

Yet an other way:

sol = First@Solve[Sqrt[x + y] == z, x]

(*   {x -> -y + z^2}   *)

Sin[Sqrt[x + y]]/Sqrt[x + y] /. sol //
PowerExpand[#, Assumptions -> z > 0] &


Or

Sin[Sqrt[x + y]]/Sqrt[x + y] /. sol //
Simplify[#, Assumptions -> z > 0] &

(*   Sin[z]/z   *)

• In an expression that had other occurrences of x, this would produce additional substitutions that the OP might well not want. – Greg Martin Apr 30 '20 at 21:14

Since I had a similar problem same problem some time ago I'd like to expand on the other answers why mathematica does not simplify the expressions with the initial second attempt. ReplaceAll (/.) does not hold its arguments. That means both arguments will be evaluated before any replacements are performed.

The left hand side of /. after evaluation can be found with

Sin[Sqrt[x + y]]/Sqrt[x + y] // FullForm


which gives

Times[Power[Plus[x,y],Rational[-1,2]],Sin[Power[Plus[x,y],Rational[1,2]]]]


Note the -1 which represents the inverse of the square root. The FullForm of the pattern after evaluation is.

Power[Plus[x,y],Rational[1,2]]


The pattern is clearly different from the expression in the pattern and hence mathematica will (correctly) not replace it.

Multiple suggestions have already been given how to obtain the desired result. I'd like to give two more suggestions.

## Unevaluated

One could wrap both sides in Unevaluated which will shield them from evaluation before replacement is performed.

Unevaluated[Sin[Sqrt[x+y]]/Sqrt[x+y]]/.Unevaluated[{Sqrt[x + y] -> z}]


this gives the desired result

Sin[z]/z


To see the difference to the first attempt use FullForm on the Uneavlated expression.

## Pattern matching

My second attempt would be to improve on the pattern matching. Inspect that according to the output of the first equation the square root can also be written as Power[Plus[x, y], Rational[n_, 2]] with n_ replaced by either -1 or 1.

We will now use a slightly different right hand side of /. which contains the pattern n_ to match both expressions on the evaluated left hand side

Sin[Sqrt[x+y]]/Sqrt[x+y] /. Power[Plus[x,y],Rational[n_,2]] :> Power[z,n]


which again gives the desired output Sin[z]/z.

In conclusion pattern matching and non-standard evaluation can be very helpful features of mathematica. Especially non-standard evaluation is often essential to understand results which look quirky at first glance.

If your ultimate aim is to simplify the equation, you can use OptimizeExpression from Experimental: it works in more general cases as well:

\$Context = "Compile";(*improve formatting for copy*)
ExperimentalOptimizeExpression[Sin[x + y]/Sqrt[x + y]]


gives

ExperimentalOptimizedExpression[Block[{$$1},$$1 = x + y;
Sin[$$1]/Sqrt[$$1]
]]
`