I'm trying to coax Mathematica into rewriting $ x\sqrt{1-y^2/x^2} = \text{sgn}(x)\sqrt{x^2-y^2} $ for $ x $ and $ y $ real. I have tried all combinations of FullSimplify and Refine with the appropriate assumptions. Mathematica refuses to cooperate.

With the additional assumption $ x>0 $, I can get Mathematica to simplify to $ \sqrt{x^2-y^2} $, but I don't want to assume this. I want the general result with the $ \text{sgn}(x) $.

  • 1
    $\begingroup$ Sometimes, it is actually hard to tell if one form is simpler than another. But if *Simplify etc. refuse to carry out further transformations, that means, Mathematica determines, according to its own built-in principles, that the "simplest" form has already been reached. $\endgroup$ – Αλέξανδρος Ζεγγ Nov 18 '18 at 14:13

For this particular expression you can use

ComplexExpand[Re[x Sqrt[1 - y^2/x^2]], {x, y}] // 
    FunctionDomain[x Sqrt[1 - y^2/x^2], {x, y}, Reals]] & // ExpandAll

(*Sqrt[x^2 - y^2] Sign[x]*)

You can also use TargetFunctions with Sign or RealSign as an option to ComplexExpand for more complicated expressions.


It is not clear, why do you need to make such a replacement by Mathematica, when it is much faster to straightforwardly type the desired expression.

However, if you are insisting, try this

expr = x*Sqrt[1 - y^2/x^2];
expr1 = expr /. x -> Sign[z]*Abs[z]

(*  Abs[z] Sqrt[1 - y^2/(Abs[z]^2 Sign[z]^2)] Sign[z]  *)

and then

(expr1 // Simplify[#, z ∈ Reals && z != 0] &) /. z -> x

(*  Sqrt[x^2 - y^2] Sign[x]  *)

Done. Have fun!

  • $\begingroup$ I just gave a simplified example for the purposes of asking the question. I don't need to simplify this expression in particular. I need to be able to give Mathematica an expression of unknown form and allow it to perform the simplification using $\text{sgn}$, if it's possible. $\endgroup$ – Donjon Oct 22 '18 at 8:14
  • $\begingroup$ So, I gave you an example. There are, however, several methods. One chooses the best one according to the expression. $\endgroup$ – Alexei Boulbitch Oct 23 '18 at 18:29

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.