I'm sure this has been addressed before, but I can't find it!

I want Mathematica to simplify

Sqrt[1 - Sin[π/6 - θ]^2]


Cos[π/6 - θ]

Just as

PowerExpand[FullSimplify[Sqrt[1 - Sin[θ]^2]]]

Does what you would expect.

Maybe the polite question would be how to transform

Sqrt[1 - Sin[π/6 - θ]^2]


Sqrt[Cos[π/6 - θ]^2]
  • 6
    $\begingroup$ This is not possible because the two expression are not equivalent: Plot[{Sqrt[1 - Sin[\[Pi]/6 - \[Theta]]^2], Cos[\[Pi]/6 - \[Theta]]}, {\[Theta], 0, 3 Pi}] $\endgroup$
    – halirutan
    Commented Aug 10, 2013 at 17:43
  • 1
    $\begingroup$ @halirutan: PolarPlot[{Sqrt[Cos[\[Pi]/6 - \[Theta]]^2], Sqrt[ 1 - Sin[\[Pi]/6 - \[Theta]]^2]}, {\[Theta], 0, 2 \[Pi]}]. I think you are looking at only +ive result from square root solution.Both have same polar plot. $\endgroup$ Commented Aug 10, 2013 at 18:25
  • $\begingroup$ @Blackbird I have indeed only looked at the (real) plot because usually most questions don't assume complex numbers. Thanks for pointing this out! $\endgroup$
    – halirutan
    Commented Aug 10, 2013 at 18:37
  • 2
    $\begingroup$ Perhaps a better question is why does Simplify[Sqrt[1 - Sin[u]^2], Element[u, Reals]] /. u -> π/6 - θ simplify and Simplify[Sqrt[1 - Sin[π/6 - θ]^2], Element[θ, Reals]] does not? Mathematica might apply more identities to the second, but it rejects all of them and returns the original expression. Why does the argument make this sort of difference? $\endgroup$
    – Michael E2
    Commented Aug 11, 2013 at 13:30

4 Answers 4

Sqrt[1 - Sin[π/6 - θ]^2] /. {Sin[x_]^2 -> 1 - Cos[x]^2} // PowerExpand
(*Cos[π/6 - θ]*)

Simplify[Sqrt[1 - Sin[π/6 - θ]^2] /.{1 - Sin[x_]^2 -> Cos[x]^2},
 Element[θ, Reals]]
(*Abs[Cos[π/6 - θ]]*)

Sqrt[1 - Sin[π/6 - θ]^2] /. Sin[x_] -> Sin@ArcCos@Cos[x]
(*Sqrt[Cos[π/6 - θ]^2]*)
  • $\begingroup$ This is OK but ineloquent. $\endgroup$ Commented Aug 10, 2013 at 18:28

First, it's important to realize Sqrt[x^2] will not simplify to Abs[x] unless you specify an assumption that (implies) x is real. But this is interesting:

Simplify[Sqrt[1 - Sin[u]^2], Element[u, Reals]] /. u -> π/6 - θ
(* Abs[Cos[π/6 - θ]] *)

Simplify[Sqrt[1 - Sin[π/6 - θ]^2], Element[θ, Reals]]
(* Sqrt[1 - Sin[π/6 - θ]^2] *)

I don't know why the second one doesn't work (even if the assumption is Element[π/6 - θ, Reals]).

Here's another workaround:

pythag[e_] := e /. Sin[u_]^2 :> 1 - Cos[u]^2;
Simplify[Sqrt[ 1 - Sin[π/6 - θ]^2], Element[θ, Reals],
    TransformationFunctions -> {Automatic, pythag}]
(* Abs[Cos[π/6 - θ]] *)

But clearly, Mathematica knows a transformation equivalent to pythag. In fact if we substitute the grade-school approximation for π (or most other exact numbers), the simplification goes through:

Simplify[Sqrt[1 - Sin[π/6 - θ]^2] /. π -> 22/7, Element[θ, Reals]]
(* Abs[Cos[11/21 - θ]] *)

An odd exception is the substitution π -> GoldenRatio.

I do not understand why there are these differences. Simplify tends to minimize LeafCount, but it's not the only factor. Another is the number of "digits of integers", but it still does not seem to be the complete picture. (See ComplexityFunction.) It is hard to imagine how the digits could account for the differences in these cases. Consider the leaf counts:

LeafCount[Sqrt[1 - Sin[π/6 - θ]^2]]
LeafCount[Sqrt[Cos[π/6 - θ]^2]]
LeafCount[Abs[Cos[π/6 - θ]]]
(* 20 *)
(* 16 *)
(* 11 *)

The workaround above suggests that the transformation of 1 - Sin[π/6 - θ]^2 to Cos[π/6 - θ]^2 is not tried. One surmises this is true from this:

foo[e_] := (Print[e]; e);
Simplify[Sqrt[1 - Sin[π/6 - θ]^2], Element[θ, Reals], 
  TransformationFunctions -> {Automatic, foo}]

The output is somewhat long, but Cos[π/6 - θ]^2 does not appear. On the other hand, in the output of

Simplify[Sqrt[1 - Sin[(22/7)/6 - θ]^2], Element[θ, Reals], 
  TransformationFunctions -> {Automatic, foo}]

Cos[11/21 - θ]^2 appears third.

Perhaps someone else will be able to explain what's going on.


Mathematica is able to confirm your hypothesis after the fact via Reduce if that's any help to you:

Reduce[Sqrt[1 - Sin[π/6 - θ]^2] == Cos[π/6 - θ] && -π/3 < θ < 2 π/3]
(* -(π/3) < θ < (2 π)/3 *)

Let y=π/6 - θ

r = Sqrt[1 - Sin[y]^2]
FullSimplify[r] (*Sqrt[Cos[y]^2]*)
PowerExpand[%]   (*Cos[y]*)
% /. y -> π/6 - θ

which gives Cos[π/6 - θ]

This is same like replacing a long repeated expression.

Reason: I am trying to specify the reason Mathematica doesn't automatically convert some forms into simpler forms.Since Mathematica doesn't support type of variable before assigning any value to it, it considers symbolic manipulations to be having complex quantity.So, all those symbolic manipulations that are not valid for both Real and Complex are not converted automatically.

Sqrt[Exp^2] is not resolved automatically to Exp because if Exp=-1, than it shall resolve to Exp=1 for the result of Sqrtthough we were expecting -1 on canceling Sqrt against Square.

I think having forced Simplification using PowerExpand instructs Mto consider Real domain.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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