Tell me more ×
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

Sin[x]^2+Cos[x]^2==1
Sin[x]/Cos[x]==Tan[x]
Csc[x]==1/Sin[x]
Sec[x]==1/Cos[x]
Cot[x]==1/Tan[x]

Examples

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

convert[eqn_,trigFunc_]:=??
share|improve this question
1  
I am confused a little about the question. If A can be rewritten in different forms (such as B,C,D,...) that are mathematically equivalent, then what are you asking? How to convert A to say B? Or to C? but then you know B and C by asking to convert to B and C. Or are you asking how to find all possible combinations of others equivalent forms? Would not there be infinite of those? Or are just asking to simplify a trig expression? But you can use Simplify for that? So I am not clear what is the question. – Nasser Jan 21 '12 at 11:22
....or may be you are asking how to determine if trig form A is mathematically equivalent to trig form B? – Nasser Jan 21 '12 at 11:32
after thinking more about this, I think you are asking for something similar to Maple's covert utility, but I am still not sure. Maple has a convert function, which is really a nice one actually, I never understood why Mathematica does not have such a super function, may be because one can do most of these things using patterns in Mathematica? not sure, but here is a link for one example to convert a trig to tan, maplesoft.com/support/help/Maple/view.aspx?path=convert%2ftan . the convert function does much more that this one case. Is this sort of what you are thinking about? – Nasser Jan 21 '12 at 11:45
2  
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
show 2 more comments

1 Answer

up vote 14 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
2  
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
Simon, do you have any opinion why Mathematica does not have a super function for converting from one form to another similar to Maple's convert() function? Mathematica has only few special conversion functions that I know about: ExpToTrig and TrigToExp and may few more I overlooked, but not a general one like Maple's convert(). – Nasser Jan 21 '12 at 12:49
1  
@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
Yes, patterns in Mathematica are much more powerful than in Maple's which can make these conversions easier, but not everyone is as skilled to write these rules each time to convert from one form to another. That is why I think a super function which does that, similar to what you started above, but much wider scope would be really useful and convenient to have in Mathematica. – Nasser Jan 21 '12 at 13:12

Your Answer

 
discard

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.