How do I force Simplify to use half angle identities?

Suppose I have (x is in the Reals)

f = ArcTan[1/x^2];
expr = Cos[f/2];

notice that

Cos[f] == 1/Sqrt[1 + 1/x^4]


and using the half-angle identity $$\cos\frac{\vartheta}{2} = \pm \sqrt{\frac{1+\cos\vartheta}{2}}$$

we can write (I only need the positive root; expr>0 for all real x):

FullSimplify[expr == Sqrt[(1 + Cos[f])/2]]


How can I get Simplify[expr] to output Sqrt[(1 + Cos[f])/2] (with f expanded out) instead of Cos[1/2 ArcTan[1/x^2]]?

My suspicion is that this is because the LeafCount of Sqrt[(1 + Cos[f])/2] (with f expanded out) would be higher than Cos[1/2 ArcTan[1/x^2]]. Is there maybe a way to modify the ComplexityFunction so that it is rewarded for using these half angle formulas?

Right now I am doing the half-angle substitutions with functions I wrote and replacement rules, but I'd rather Simplify just do it for me.


Maybe it's not relevant, but I probably should've at least posted the replacement rule I am doing for now so others can see it. I have a long formula compEx and I find everywhere that I see something like Cos[1/2___(something)], and there I use the half angle formula for cosine:

fun = ArcTan[(1 - x)/Sqrt[-I - x^2]]/Sqrt[-I - x^2];
compEx = 
 Simplify[ComplexExpand[Re[fun], TargetFunctions -> {Re, Im}], 
  1/2 < x < 1];

halfAngleCos[k_] = Sqrt[(1 + Cos[2 k])/2];
subbed = compEx /. Cos[1/2 k__] -> halfAngleCos[1/2 k];

I do the same thing with half angle formula for Sin also.

  • 1
    $\begingroup$ why not use Replace intead of Simplify? As in expr=Cos[f/2]; expr/.Cos[x_/2]:> Sqrt[(1+Cos[x])/2] !Mathematica graphics or do you need to use Simplify only? $\endgroup$
    – Nasser
    Commented Aug 12, 2023 at 4:24
  • $\begingroup$ @Nasser I am doing pretty much that (I added what I'm currently doing to the bottom), but I got stuck up on wanting Simplify to do it for me. Now that I think about it though, the way I'm doing it is pretty clean. So maybe I shouldn't worry about how to do this with Simplify? $\endgroup$
    – ydd
    Commented Aug 12, 2023 at 4:35
  • $\begingroup$ The part that annoyed me was just that I had to write out the half-angle formulas :( But I am slow typer, need to work on my typing skills (home keys!!!) $\endgroup$
    – ydd
    Commented Aug 12, 2023 at 4:37
  • 2
    $\begingroup$ sometimes making your own transformation rules and using them explicitly on expressions using Replace or ReplaceAll or Cases, is simpler than teaching Simplify to use them. But I am sure this can be done using Simplify, but need to adjust also the complexity function I think. $\endgroup$
    – Nasser
    Commented Aug 12, 2023 at 4:54
  • 1
    $\begingroup$ You cannot force the half angle formula to be applied, because they are not True. The same problem arises with TrigToExp. You get sums of Log functions, that have to combined into logs of products. As a rule, all these identities imply equality of square roots. So its often simpler to Simplify the equality of their squares, because thats the goal. The complex phases of the root expression in these identities have to be tabulated by hand or a complex Arg Plot, normally. $\endgroup$
    – Roland F
    Commented Aug 12, 2023 at 6:13

1 Answer 1


Just let FullSimplify know that you really don't like trigonometric functions in your output by providing a custom ComplexityFunction with a large weight on unwanted function(s).

 ComplexityFunction -> (LeafCount[#] + 50 Count[#, Cos[_], All] &)]
(* Sqrt[1 + 1/Sqrt[1 + 1/x^4]]/Sqrt[2] *)
  • $\begingroup$ Thanks. I was scratching my head a little with the documentation examples in ComplexityFunction, but this makes sense now $\endgroup$
    – ydd
    Commented Aug 12, 2023 at 20:43

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.