5
$\begingroup$

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:

enter image description here

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}
$\endgroup$
5
  • $\begingroup$ 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. $\endgroup$ – Michael E2 Apr 30 '20 at 0:31
  • 1
    $\begingroup$ Possible duplicate: mathematica.stackexchange.com/a/29219/4999 $\endgroup$ – Michael E2 Apr 30 '20 at 0:44
  • 1
    $\begingroup$ 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 $\endgroup$ – Michael E2 Apr 30 '20 at 0:46
  • $\begingroup$ 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.. $\endgroup$ – Danvil Apr 30 '20 at 2:23
  • $\begingroup$ 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. $\endgroup$ – Michael E2 Apr 30 '20 at 2:46
3
$\begingroup$

Another way:

Sin[Sqrt[x + y]]/Sqrt[x + y] /. (x + y)^(r_) :> z^(2 r)
(*  Sin[z]/z  *)
$\endgroup$
5
$\begingroup$

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
$\endgroup$
1
  • 1
    $\begingroup$ Note that Surd[z, 2] is equivalent to Sqrt[z] only if z is nonnegative real. $\endgroup$ – Michael E2 Apr 30 '20 at 1:32
5
$\begingroup$

Another option is to help it a little

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

Mathematica graphics

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

Mathematica graphics

$\endgroup$
1
  • 1
    $\begingroup$ +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. $\endgroup$ – Michael E2 Apr 30 '20 at 12:14
3
$\begingroup$

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   *)
$\endgroup$
1
  • $\begingroup$ In an expression that had other occurrences of x, this would produce additional substitutions that the OP might well not want. $\endgroup$ – Greg Martin Apr 30 '20 at 21:14
3
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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*)
Experimental`OptimizeExpression[Sin[x + y]/Sqrt[x + y]]

gives

Experimental`OptimizedExpression[Block[{$1}, 
  $1 = x + y;  
  Sin[$1]/Sqrt[$1]
]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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