# Solving trig identities in specific terms

How would you solve a problem like "write csc(x) in terms of sec(x)" in Mathematica? The best I can get is "True."

https://math.stackexchange.com/questions/167935/write-cscx-in-terms-of-secx

I'm asking in order to better understanding of Mathematica, and as a way to verify I'm solving my trig identities correctly. It's been a while since I've done identities, and I'm trying to brush off the cobwebs before its too late. I was told that I'll need this skill later on in Calculus.

• Would these help? 1 2 3 4 :) – dearN Oct 10 '12 at 19:07

Just playing tricks:

Cases[Join @@ Solve[{csc == 1/sin, sec == 1/cos, cos cos + sin sin == 1}, {csc, sin, cos}],
HoldPattern[csc -> _]]
(*
->{csc -> -(sec/Sqrt[-1 + sec^2]), csc -> sec/Sqrt[-1 + sec^2]}
*)


Edit

More generally (by using @J.M's suggestion below):

trigExpress[expr_, inTerms_] :=
Module[
{set = {sin, cos, tan, sec, csc},
rels = {csc sin == 1, cos^2 + sin^2 == 1, 1 == cos sec, tan == sin/cos}},
oneInTermsOf[one_, of_] := Solve[rels, {one}, Complement[set, {one, of}]];
allIntermsOf[of_] :=       Flatten[oneInTermsOf[#, of] & /@ Complement[set, {of}]];
Expand@FullSimplify[expr /. allIntermsOf[inTerms]]
]


so:

trigExpress[(sin + cos)/tan, sec]
(*
-> 1/sec - 1/(sec Sqrt[-1 + sec^2])
*)

• Slightly more compact: Solve[{Csc Sin == 1, Cos^2 + Sin^2 == 1, 1 == Cos Sec}, Csc, {Cos, Sin}] – J. M. will be back soon Oct 11 '12 at 0:59
• @J.M. Thanks. Updated with a little more general thing using yours – Dr. belisarius Oct 11 '12 at 13:43
• Hmmm ... probably one should take in account the negative radicals to get the expressions for all quadrants. – Dr. belisarius Oct 11 '12 at 13:46
• @Dr.belisarius -- I've added a new answer to partially address the issues with different quadrants – Simon May 19 '16 at 4:54

Here's some code that can solve this problem that I wrote a while back for another question.

$TrigFns = {Sin, Cos, Tan, Csc, Sec, Cot}; (WRules =$TrigFns == (Through[$TrigFns[x]] /. x -> 2 ArcTan[t] // TrigExpand // Together) // Thread); invWRules = #[[1]] -> Solve[#, t, Reals] & /@ WRules; 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 &)]


In the example provided in the question:

convert[Csc[x], Sec[x]] // ReleaseHold


$$-\frac{\sec (x)}{\sqrt{\sec (x)-1} \sqrt{\sec (x)+1}} \quad \Big|\Big|\quad \frac{\sec (x) \sqrt{\frac{\sec (x)+1}{\sec (x)-1}}}{\sec (x)+1}$$

These solutions cover both quadrants (although the result could be presented in a nicer form).
To check this, let's plot:

Plot[{Csc[x], -(Sec[x]/(Sqrt[-1 + Sec[x]] Sqrt[1 + Sec[x]])), (
Sec[x] Sqrt[(1 + Sec[x])/(-1 + Sec[x])])/(1 + Sec[x])}, {x, 0, 2 Pi},
PlotStyle -> {Blue, Dotted, Dashed}]