# How to evaluate this indefinite integral $\csc(4x)\sin(x)$

I tried to integrate the following integral using Integrate[Sin[x]Csc[4x],x] and I am getting a strange result. $$\frac{1}{8 \sqrt{2}}\left(-2 i \text{ArcTan}\left[\frac{\text{Cos}\left[\frac{x}{2}\right]-\left(-1+\sqrt{2}\right) \text{Sin}\left[\frac{x}{2}\right]}{\left(1+\sqrt{2}\right) \text{Cos}\left[\frac{x}{2}\right]-\text{Sin}\left[\frac{x}{2}\right]}\right]-2 i \text{ArcTan}\left[\frac{\text{Cos}\left[\frac{x}{2}\right]-\left(1+\sqrt{2}\right) \text{Sin}\left[\frac{x}{2}\right]}{\left(-1+\sqrt{2}\right) \text{Cos}\left[\frac{x}{2}\right]-\text{Sin}\left[\frac{x}{2}\right]}\right]+2 \sqrt{2} \text{Log}\left[\text{Cos}\left[\frac{x}{2}\right]-\text{Sin}\left[\frac{x}{2}\right]\right]-2 \sqrt{2} \text{Log}\left[\text{Cos}\left[\frac{x}{2}\right]+\text{Sin}\left[\frac{x}{2}\right]\right]+2 \text{Log}\left[\sqrt{2}+2 \text{Sin}[x]\right]-\text{Log}\left[2-\sqrt{2} \text{Cos}[x]-\sqrt{2} \text{Sin}[x]\right]-\text{Log}\left[2+\sqrt{2} \text{Cos}[x]-\sqrt{2} \text{Sin}[x]\right]\right)$$

(1/8) Log[Sin[x] - 1] + (1/4) Sqrt[2] ArcTanh[Sin[x] Sqrt[2]] - (1/8) Log[1 + Sin[x]] $$\frac{\text{ArcTanh}\left[\sqrt{2} \text{Sin}[x]\right]}{2 \sqrt{2}}+\frac{1}{8} \text{Log}[-1+\text{Sin}[x]]-\frac{1}{8} \text{Log}[1+\text{Sin}[x]]$$

Why am I getting this strange result? Are those two answers equivalent? How to avoid such strange results?

• if you compare, say Integrate[Sin[x] Csc[4 x], {x, 0, 1/2}] and NIntegrate[Sin[x] Csc[4 x], {x, 0, 1/2}] they seem to agree which is a good sign. – chris Dec 23 '12 at 20:55
• I didn't check, but I'm willing to bet 2 dollars that they're equivalent. – yohbs Dec 23 '12 at 20:59
• @yohbs Why do you think so? – Dr. belisarius Dec 23 '12 at 21:19
• @belisarius I thought so because I thought that the OP was comparing two outputs of MMA. Now that I see this is not the case, I withdraw my bet like a coward. – yohbs Dec 23 '12 at 22:02
• There is one more error in the coefficient before the atanh. Please try to be more careful – Dr. belisarius Dec 23 '12 at 22:51

Just playing around, Mathematica gives the correct solution :

int2 = FullSimplify[Integrate[TrigExpand[Sin[x] Csc[4 x]], x]];

FullSimplify@D[TrigToExp[int2], x]
(* Csc[4 x] Sin[x] *)


The real part of the two solutions match but the imaginary parts do not :

check = 1/8 Log[Sin[x] - 1] - 1/8 Log[Sin[x] + 1] + Sqrt[2]/4 ArcTanh[Sqrt[2] Sin[x]];

FullSimplify@D[check - int2, x]
(* 0 *)


and

SeedRandom[6];
FullSimplify[check - int2 /. x -> RandomReal[]]
(* 2.77556*10^-17 + 0.670379 I *)

Plot[Im[int2 - check], {x, -2 \[Pi], 2 \[Pi]},
Ticks -> {{#, #} & /@ Range[-2 \[Pi], 2 \[Pi], \[Pi]/2], Automatic},
GridLines -> {Range[-2 \[Pi], 2 \[Pi], \[Pi]/4], None}]


Why am I getting this strange result?

Mathematica's symbolic integration methods are more complicated that first-year calculus methods, and can turn out to involve complex-valued functions. See for instance How does Mathematica integrate?

1. Yes-but. The term Log[-1+Sin[x]], which is equivalent to Log[1-Sin[x]] + Pi I, is an undefined real-valued function for almost all $x$ -- might want to use Log[1-Sin[x]] instead if you're looking for a standard real analysis function. The term is fine as a complex-valued function.

2. Yes, they're equivalent. From calculus we know that over an interval over which a function is continuous, any two antiderivatives differ by a constant, which in fact may be a complex number. Over disjoint intervals, the constants may differ. Your function $\sin x \csc 4x$ is continuous over intervals of the form ${n\pi \over 4}<x<{(n+1)\pi\over4}$. If you examine b.gatessucks' and Nasser M. Abbasi's plots you can see that the answers differ by constant throughout each such interval. (In fact, your integrand has a removable discontinuity at $n\pi$ and so the constant does not change at those values.)

How to avoid such strange results?

1. Learn to love them, then they won't be strange. ;-) Seriously, they usually work as is, although in this case, for instance, you have to use the real part to graph it.

2. Try simplifying the real part, which will always be an antiderivative if the integrand is real:

i = Integrate[Sin[x] Csc[4 x], x];
FullSimplify[Re[i], x \[Element] Reals]
(* 1/32 (-8 ArcTanh[Sin[x]] + Sqrt[2] (2 Log[(Sqrt[2] + 2 Sin[x])^2] +
Log[1/(4 (-2 + Cos[2 x] + 2 Sqrt[2] Sin[x])^2)]))*)

• thanks for an instructive answer. Can your FullSimplify[Re[i], x \[Element] Reals] answer always be considered a good anti-derivative throughout all values of x. If so why does mathematica and maple not pick up this solution rather than the complex one above? – chris Dec 24 '12 at 8:54
• You can assume Re[i] will always be a valid antiderivative if your integrand is real-valued. I do not know that FullSimplify will always give a result you seek, though it should always give a correct one. Many people are surprised when they first learn Sin[x]^2, -Cos[x]^2, and -Cos[2x]/2 are all antiderivatives of 2 Sin[x] Cos[x]. Even in a simple integral, one can't say definitively which is the best, and all are right. All one can expect is that Mathematica, Maple, etc. give correct answers, but not always the same answer. – Michael E2 Dec 24 '12 at 17:40

Taking derivatives of your "correct answer" and comparing with the integrand, shows they are not that equal:

While taking derivatives of Mma's result gives:

• @experimentX I think there is an 'Atanh[] whose h is missing in your question – Dr. belisarius Dec 23 '12 at 22:33
• I am extremely sorry for my mistake in Question. – Santosh Linkha Dec 23 '12 at 22:42

The function (the answer) gives complex values at different x. A plot of the real part is an exact match. For the complex part there is constant piecewise shift and the Abs of the solutions also agree up to piecewise constant so the answer seems to be correct. The solution are plotted for x=-10..10

Here is Maple result

This answer was typed into Mathematica and compared it with Mathematica's Integrate answer:

maple=(1/4)Sqrt[2] ArcTanh[Sin[x] Sqrt[2]]-(1/8) Log[1 + Sin[x]] + (1/8) Log[Sin[x]- 1]
mma = Integrate[Sin[x] Csc[4 x], x];


plot the real part

Plot[Evaluate[Re[{maple, mma}]], {x, -10, 10},PlotLegends -> {"maple", "mma"}]


Plot the complex part

Plot[Evaluate[Im[{maple, mma}]], {x, -10, 10},PlotLegends -> {"maple", "mma"}]


plot the magnitude

Plot[Evaluate[Abs[{maple, mma}]], {x, -10, 10},PlotLegends -> {"maple", "mma"}]


One can instantly recognize that the integrand can be expressed in terms of the Chebyshev polynomial of the second kind:

$$\int\frac{\sin x}{\sin 4x}\mathrm dx=\int\frac1{U_3(\cos x)}\mathrm dx$$

and thus, by letting $t=\cos x$,

FullSimplify[PowerExpand[(Integrate[-1/(Sqrt[1 - t^2] ChebyshevU[3, t]), t] /.
t -> Cos[x]) /. Sqrt[tmp_] :> Sqrt[TrigFactor[tmp]]]]
(-Sqrt[2] Log[Sqrt[2] - 2 Cos[x]] + 2 Log[Cos[x]] - Sqrt[2] Log[Sqrt[2] + 2 Cos[x]] -
2 Log[1 + Sin[x]] + Sqrt[2] (Log[2 - Sqrt[2] Cos[x] + Sqrt[2] Sin[x]] +
Log[2 + Sqrt[2] Cos[x] + Sqrt[2] Sin[x]]))/8


Check by differentiating the result:

Simplify[D[%, x] == Sin[x] Csc[4 x]]
True

expr0 = Sin[x] Csc[4 x];

expr1 = Integrate[expr0, x] // FullSimplify

(* (1/(8 Sqrt[2]))(-I π + 2 Sqrt[2] Log[Cos[x/2] - Sin[x/2]] -
2 Sqrt[2] Log[Cos[x/2] + Sin[x/2]] + 2 Log[Sqrt[2] + 2 Sin[x]] -
Log[2 - Sqrt[2] Cos[x] - Sqrt[2] Sin[x]] -
Log[2 + Sqrt[2] Cos[x] - Sqrt[2] Sin[x]]) *)


expr1 is an antiderivative of expr0

expr0 == D[expr1, x] // FullSimplify

(* True *)

expr2 = (1/8) Log[Sin[x] - 1] + (1/4) Sqrt[2] ArcTanh[
Sin[x] Sqrt[2]] - (1/8) Log[1 + Sin[x]];


expr2 is also ** an ** antiderivative of expr0

expr0 == D[expr2, x] // FullSimplify

(* True *)


Antiderivatives can differ by an arbitrary numeric constant (perhaps complex)

Assuming[Element[x, Reals],
Series[expr1 - expr2 // FullSimplify, {x, 0, 10}] // Simplify] // Normal

(* -(1/16) I (2 + Sqrt[2]) π *)


As expected, they differ by a numeric constant.

The Rubi package for Mathematica (available at http://www.apmaths.uwo.ca/~arich/) often gives antiderivatives in a nicer form:

Int[Sin[x] Csc[4 x], x]


$\frac{\tanh ^{-1}\left(\sqrt{2} \sin (x)\right)}{2 \sqrt{2}}-\frac{1}{4} \tanh ^{-1}(\sin (x))$

Letting t = Tan[x/2], we can get a simpler result.

Integrate[Sin[x] Csc[4 x] D[2 ArcTan[t], t] /. x -> 2 ArcTan[t] // TrigExpand, t] /.
t -> Tan[x/2] // FullSimplify // PowerExpand
FullSimplify[%, 0 < x < Pi/2]
D[%, x] // Simplify


$\frac{1}{8} \left(\sqrt{2} \left(\log \left(\sqrt{2} \sin (x)+1\right)-\log \left(\sqrt{2} \sin (x)-1\right)\right)-4 \tanh ^{-1}\left(\tan \left(\frac{x}{2}\right)\right)\right)$

$\frac{1}{4} \left(\sqrt{2} \tanh ^{-1}\left(\frac{\csc (x)}{\sqrt{2}}\right)-2 \tanh ^{-1}\left(\tan \left(\frac{x}{2}\right)\right)\right)$

$\sin (x) \csc (4 x)$

Alternatively, letting t = Sin[x]

Integrate[Sin[x] Csc[4 x] D[ArcSin[t], t] /. x -> ArcSin[t] // TrigExpand, t] /.
t -> Sin[x] // FullSimplify
`

$\frac{1}{4} \left(\sqrt{2} \tanh ^{-1}\left(\sqrt{2} \sin (x)\right)-\tanh ^{-1}(\sin (x))\right)$