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}$$

  • 2
    $\begingroup$ But Sin[x] only equals Sqrt[1-Cos[x]^2] for half of its period. Are you sure that is the answer you want? $\endgroup$
    – Simon
    Jan 21, 2012 at 11:46
  • $\begingroup$ @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. $\endgroup$ Jan 21, 2012 at 13:35
  • $\begingroup$ @Simon its ± , I have edited the Question $\endgroup$ Jan 21, 2012 at 13:35
  • 1
    $\begingroup$ @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? $\endgroup$
    – Simon
    May 5, 2012 at 23:57
  • $\begingroup$ Use identities to write each expression as a single function of x Cos(60 degrees + x) $\endgroup$
    – Jay
    Mar 7, 2017 at 16:57

2 Answers 2


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!

  • 2
    $\begingroup$ 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}] $\endgroup$
    – Simon
    Jan 21, 2012 at 12:47
  • 1
    $\begingroup$ @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. $\endgroup$
    – Simon
    Jan 21, 2012 at 12:58
  • 2
    $\begingroup$ I find this really useful. Many thanks Simon! I wonder why it isn't built-in in Mathematica! $\endgroup$
    – stupidity
    Jun 17, 2014 at 19:10
  • 1
    $\begingroup$ +1 for using "The world's sneakiest substitution" $\endgroup$
    – Histograms
    May 27, 2015 at 15:35
  • 1
    $\begingroup$ @Histograms, it's really neat for algebra. A mixed bag in calculus, tho; bites the careless. $\endgroup$ May 27, 2015 at 16:28

I would like to share more universal method I use in my scientific manipulations involving trigonomeric expressions of real arguments. It does not require any identities used by hand and is mathematically coincise.

The idea is to convert trigonometric expression to exponents, which in turn will play the role of monomials. Then you can use very powerful Groebner basis manipulation method. Let me ilustrate how it works in your simple cases. First define some help function which translates trigonometric expression to polynomials. The simplified version looks like

ExpToPoly[expr_] := Block[{ex = ExpandAll[TrigToExp[expr]]},
   ex, {Exp[Complex[0, a_Rational | a_Integer]*b_ + c_.] :> 
     Power[b, a]*Exp[c]}]]

Then input expresions you want to manipulate.

expr = Sin[x];
use = Cos[x];

Lets look how it is transformed to polynomial


I/(2 x) - (I x)/2

Now calculate Groebner base and solve the identity you find useful (in your simple cases actually you have no choise)

gb = GroebnerBasis[{myexpr - ExpToPoly[TrigToExp[expr]], 
   myuse - ExpToPoly[TrigToExp[use]]}, {myuse}, {x}, 
  MonomialOrder -> EliminationOrder]

{-1 + myexpr^2 + myuse^2}

From which it follows

Solve[gb[[1]] == 0, myexpr] /. {myuse -> use}

{{myexpr -> -Sqrt[1 - Cos[x]^2]}, {myexpr -> Sqrt[1 - Cos[x]^2]}}

Lets look at one of simple transformation of previous answer.

expr1 = Sin[2 x] Tan[x]^3;
use = Cos[x];

gb1 = GroebnerBasis[{myexpr - ExpToPoly[TrigToExp[expr1]], 
   myuse - ExpToPoly[TrigToExp[use]]}, {myuse}, {x}, 
  MonomialOrder -> EliminationOrder]

{2 - 4 myuse^2 - myexpr myuse^2 + 2 myuse^4}

Now in order to prevent automatic convertion to Sec[] function we Hold solved rezult:

Hold @@ (myexpr /. Solve[gb1[[1]] == 0, myexpr]) /. {myuse -> use}

Hold[(2 (1 - 2 Cos[x]^2 + Cos[x]^4))/Cos[x]^2]

This method can easily be extended to many variables, allows very complicated manipulations of trigonometric expressions (at least of real arguments). And most important: it is based on Groebner basis, so is always mathematically correct.

Just noted that, that using this approach you can easily convert to double, triple, etc... argument as was asked in the wish list:

expr = Sin[x];
use = Cos[2 x];

gb2 = GroebnerBasis[{myexpr - ExpToPoly[TrigToExp[expr]], 
   myuse - ExpToPoly[TrigToExp[use]]}, {myuse}, {x}, 
  MonomialOrder -> EliminationOrder]

{-1 + 2 myexpr^2 + myuse}

The result being

Hold @@ (myexpr /. Solve[gb2[[1]] == 0, myexpr]) /. {myuse -> use}

Hold[-(Sqrt[1 - Cos[2 x]]/Sqrt[2]), Sqrt[1 - Cos[2 x]]/Sqrt[2]]

  • $\begingroup$ Can this method be also used for converting Cos(a+bx) in terms of Cos(c+dx) or Sin(c+d*x) or in terms of both? $\endgroup$
    – Shinrei
    Apr 25, 2017 at 16:03
  • 1
    $\begingroup$ In general not, because with symbolic coefficients your will not get polynomials, i.e. you will get x^d. Then Groebner base elimination will not work. However as a workaround you can try to replace x by some large primitive number and then in principle can try the elimination. I will try to do this when will have more time. $\endgroup$
    – Acus
    Apr 26, 2017 at 7:15

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