What command makes Tan[A+B] expand to (Tan[A]+Tan[B])/(1-Tan[A]Tan[B])? TrigExpand does not give it directly.


5 Answers 5


I think the easiest way is the following:

tansum = Tan[a_ + b_] :> (Tan[a] + Tan[b])/(1 - Tan[a] Tan[b]); 

Then we run

Tan[A + B] /. tansum

(Tan[A] + Tan[B])/(1 - Tan[A] Tan[B])

Likewise for other trigonometric identities

Edit: after the comment for generalization for $n$-angles.

If we try to do it like this for the case $n=3$ it seems to be working

Tan[a1 + a2 + a3] /. tansum /. tansum // Factor

(-Tan[a1] - Tan[a2] - Tan[a3] + Tan[a1] Tan[a2] Tan[a3])/(-1 + Tan[a1] Tan[a2] + Tan[a1] Tan[a3] + Tan[a2] Tan[a3])

  • $\begingroup$ Thanks. This is close to what I want. Can we write a code to express Tan[a1+a2+...+an] purely in terms of Tan[a1], Tan[a2], Tan[a3], .... $\endgroup$ Mar 12, 2022 at 6:15
  • $\begingroup$ @QuasarSupernova I don't know the formula in terms of sums of Tan[a1],...,Tan[an] by heart. If you can post it, I am happy to give it a go. Otherwise I will try it tomorrow, as it's pretty late here $\endgroup$
    – user49048
    Mar 12, 2022 at 6:18
  • $\begingroup$ @QuasarSupernova please see the edit I added to the answer, and let me know. If I remember there's a general formula in terms of sums of products in the numerator and denominator, but I am not quite sure what you are after :-) $\endgroup$
    – user49048
    Mar 12, 2022 at 6:26
  • $\begingroup$ @kcr you can also use //. tansum instead of /. tansum /.tansum $\endgroup$ Aug 3, 2022 at 4:04

It is in the Wolfram Knowledgebase


Entity["MathematicalFunction", "Tan"]["AdditionFormulas"][[1]][
  A, B] // Activate

(* Tan[A + B] == (Tan[A] + Tan[B])/(1 - Tan[A] Tan[B]) *)


% // Simplify

(* True *)

EDIT: Converting the equality into a rule

rule = Tan[A_ + B_] :> Evaluate[%%[[-1]]]

(* Tan[A_ + B_] :> (Tan[A] + Tan[B])/(1 - Tan[A] Tan[B]) *)

Handling multiple addends in argument to Tan,

Simplify[Tan[a + b + c + d] //. rule, ExcludedForms -> _Tan]

(* (Tan[b] + Tan[c] + Tan[d] - Tan[b] Tan[c] Tan[d] - 
   Tan[a] (-1 + Tan[c] Tan[d] + Tan[b] (Tan[c] + Tan[d])))/(1 - 
   Tan[c] Tan[d] - Tan[b] (Tan[c] + Tan[d]) + 
   Tan[a] (-Tan[c] - Tan[d] + Tan[b] (-1 + Tan[c] Tan[d]))) *)


% // Simplify

(* Tan[a + b + c + d] *)
  • $\begingroup$ I want to be able to finally Expand Tan[a1 + a2 + ..... + an ] only in terms of Tan[a1], Tan[a2], ... for a variable "n" $\endgroup$ Mar 12, 2022 at 6:13
  • $\begingroup$ @Bob Hanlon, An extension of Tan[a+b] is interesting, but explain how you arrive at those steps.? $\endgroup$
    – janhardo
    Mar 13, 2022 at 0:28
  • $\begingroup$ @janhardo - ReplaceRepeated with the rule transforms the original expression into one with only Tan of atomic arguments; however, it needs to be simplified. Simple application of Simplify would just return the original expression. Consequently, the option ExcludedForms is used to prevent the Tan terms from being recombined. $\endgroup$
    – Bob Hanlon
    Mar 13, 2022 at 0:46
  • $\begingroup$ @Bob Hanlon thanks,This is not immediately so easy to fathom, although some of the terms are familiar. $\endgroup$
    – janhardo
    Mar 13, 2022 at 9:58

You can do a step-by-step derivation, suppressing the evaluation using a change of case.

expr0 = Tan[a + b]

$$\tan (a+b)$$

expr1 = TrigExpand[expr0] /. {Cos -> cos, Sin -> sin}

$$\frac{\sin (a) \cos (b)}{\cos (a) \cos (b)-\sin (a) \sin (b)}+\frac{\cos (a) \sin (b)}{\cos (a) \cos (b)-\sin (a) \sin (b)}$$

expr2 = expr1 /. {sin[a_] -> tan[a] cos[a] }

$$\frac{\cos (a) \tan (a) \cos (b)}{\cos (a) \cos (b)-\cos (a) \tan (a) \cos (b) \tan (b)}+\frac{\cos (a) \cos (b) \tan (b)}{\cos (a) \cos (b)-\cos (a) \tan (a) \cos (b) \tan (b)}$$

expr3 = Factor[expr2] /. tan -> Tan

$$-\frac{\tan (a)+\tan (b)}{\tan (a) \tan (b)-1}$$

expr3 // Simplify


The same procedure for Tan[a+b+c+d] results in:

$$-\frac{\tan (a) \tan (b) \tan (c)+\tan (a) \tan (b) \tan (d)+\tan (a) \tan (c) \tan (d)-\tan (a)+\tan (b) \tan (c) \tan (d)-\tan (b)-\tan (c)-\tan (d)}{\tan (a) \tan (b) \tan (c) \tan (d)-\tan (a) \tan (b)-\tan (a) \tan (c)-\tan (a) \tan (d)-\tan (b) \tan (c)-\tan (b) \tan (d)-\tan (c) \tan (d)+1}$$


If the question concerns the derivation, not the application, of the "high school formula" one can derive it , similar to @Syed's answer, in a direct way :

((Tan[a + b] // TrigExpand) /. {a ->  ArcTan[ua], b ->  ArcTan[ub]} //TrigExpand // Simplify) /. {ua -> Tan[a ], ub -> Tan[b ]}
(*(Tan[a] + Tan[b])/(1 - Tan[a] Tan[b])*)

Lots of good answers, but here's a trick I think is worth knowing

TrigExpand[Tan[x + y]] /. Sin[u_] -> Cos[u] HoldForm[Tan[u]] //
   Simplify // ReleaseHold
(* (Tan[x] + Tan[y])/(1 - Tan[x] Tan[y]) *)

This works by making the (obviously valid) replacement

Sin[u_] -> Cos[u] Tan[u]

In itself, this would achieve little as (I guess) that Mathematica would simplify the result back to the unwanted form. However, wrapping HoldForm round the tangents means that Mathematica will not change them. Consequently, the simplest form is the one that we seek.

ReleaseHold removes the HoldForm wrapper. In this case, this doesn't change the appearance of the result, but means that the Tan terms will behave as expected in subsequent processing.

  • $\begingroup$ Its a good trick , can you explain how this trick works? $\endgroup$
    – janhardo
    Mar 13, 2022 at 18:32

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