Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How can I express a trigonometric equation / identity in terms of a given trigonometric function?

using following trigonometric identities



$$\text{convert}(\sin x,\cos)\Rightarrow \pm\sqrt{1-\cos^2(x)}$$ $$\text{convert}(\cos x,\sin)\Rightarrow \pm\sqrt{1-\sin^2(x)}$$ $$\text{convert}\left(\frac{\cos x}{\sin x},\tan\right)\Rightarrow\frac{1}{\tan x}$$

share|improve this question
But Sin[x] only equals Sqrt[1-Cos[x]^2] for half of its period. Are you sure that is the answer you want? –  Simon Jan 21 '12 at 11:46
@NasserM.Abbasi basically what I want is to replace all trigonometric functions in an equation with given single Trig function, knowing the fact that each one can be expressed in terms of another,and Simplifying equation to the smallest form possible. –  Prashant Bhate Jan 21 '12 at 13:35
@Simon its ± , I have edited the Question –  Prashant Bhate Jan 21 '12 at 13:35
@Prashant: I just noticed that you have asked 5 questions on this site and accepted answers for none. Since you are still active on stackoverflow, do you want to come back to Mma.SE and either accept some answers or say why the answers you received are not acceptable? –  Simon May 5 '12 at 23:57

1 Answer 1

up vote 19 down vote accepted

This is a new version of my answer in response to the edited question (the first version is here).

It is based on the same idea, but the Weierstrass substitution rules are now generated by Mathematica (instead of entered by hand) and results with $\pm$ solutions are correctly returned.

First, generate the Weierstrass substitution rules

$TrigFns = {Sin, Cos, Tan, Csc, Sec, Cot};
(WRules = $TrigFns == (Through[$TrigFns[x]] /. x -> 2 ArcTan[t] // 
      TrigExpand // Together) // Thread)

Then, Partition[WRules /. Thread[$TrigFns -> Through[$TrigFns[x]]], 2] // TeXForm returns $$ \begin{align} \sin (x)&=\frac{2 t}{t^2+1}\,, & \cos (x)&=\frac{1-t^2}{t^2+1}\,, \\ \tan (x)&=-\frac{2 t}{t^2-1}\,, & \csc (x)&=\frac{t^2+1}{2 t}\,, \\ \sec (x)&=\frac{-t^2-1}{t^2-1}\,, & \cot (x)&=\frac{1-t^2}{2 t} \ . \end{align} $$

Then, we invert the rules using

invWRules = #[[1]] -> Solve[#, t, Reals] & /@ WRules

which we can finally use in the convert function:

convert[expr_, (trig : Alternatives@@$TrigFns)[x_]] := 
 Block[{temp, t},
  temp = expr /. x -> 2 ArcTan[t] // TrigExpand // Factor;    
  temp = temp /. (trig /. invWRules) // FullSimplify // Union;
  Or @@ temp /. trig -> HoldForm[trig][x] /. ConditionalExpression -> (#1 &)]

Note that the final line has HoldForm to prevent things like 1/Sin[x] automatically being rewritten as Csc[x], etc...

Here are some test cases - it is straight forward to check that the answers are correct (but don't forget to use RelaseHold):

In[6]:= convert[Sin[x], Cos[x]]
Out[6]= - Sqrt[1 - Cos[x]^2] || Sqrt[1 - Cos[x]^2]

In[7]:= convert[Sin[x]Cos[x], Tan[x]]
Out[7]= Tan[x]/(1 + Tan[x]^2)

In[8]:= convert[Sin[x]Cos[x], Cos[x]]
Out[8]= -Cos[x] Sqrt[1 - Cos[x]^2] || Cos[x] Sqrt[1 - Cos[x]^2]

In[9]:= convert[Sin[2x]Cos[x], Sin[x]]
Out[9]= -2 Sin[x] (-1 + Sin[x]^2)

In[10]:= convert[Sin[2x]Tan[x]^3, Cos[x]]
Out[10]= 2 (-2 + 1/Cos[x]^2 + Cos[x]^2)

A couple of quick thoughts about the above solution:

  1. It assumes real arguments for the trig functions. It would be nice if it didn't do this and could be extended to hyperbolic trig and exponential functions.

  2. When two solutions are given, it should return the domains of validity - or combine the appropriate terms using Abs[].

  3. It should be extended to handle things like convert[Sin[x], Cos[2x]].

If anyone feels like implementing any of these things, please feel free!

share|improve this answer
Note that you can get some nice looking wave-packets with this code: Plot[Evaluate[# - ReleaseHold[convert[#, Tan[x]]] &[ Sin[16 x] Cos[x]]], {x, 0, 4 Pi}] –  Simon Jan 21 '12 at 12:47
@Nasser. Actually, I just looked at the maple link you supplied, and the functionality it gives is quite simple. I don't think it is even capable of the examples provided in the question (and my answer). convert(expr, tan) just uses the Weierstrass substitution step. convert(expr, sincos) just rewrites exp, tan, cot, etc as sin and cos. It does not simplify down to one function like the OP asked for. And so on with the other converts. –  Simon Jan 21 '12 at 12:58
That said, the non-trig rules in Maple's convert family of functions do seem like a useful collection. Even if they all can (maybe) be written as families of replacement rules. –  Simon Jan 21 '12 at 13:06
I find this really useful. Many thanks Simon! I wonder why it isn't built-in in Mathematica! –  stupidity Jun 17 '14 at 19:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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