\(\int (\sin (x)+\tan (x))^2 \, dx\) [343]

   Optimal result
   Rubi [A] (verified)
   Mathematica [B] (verified)
   Maple [A] (verified)
   Fricas [B] (verification not implemented)
   Sympy [A] (verification not implemented)
   Maxima [A] (verification not implemented)
   Giac [B] (verification not implemented)
   Mupad [B] (verification not implemented)

Optimal result

Integrand size = 7, antiderivative size = 25 \[ \int (\sin (x)+\tan (x))^2 \, dx=-\frac {x}{2}+2 \text {arctanh}(\sin (x))-2 \sin (x)-\frac {1}{2} \cos (x) \sin (x)+\tan (x) \]

[Out]

-1/2*x+2*arctanh(sin(x))-2*sin(x)-1/2*cos(x)*sin(x)+tan(x)

Rubi [A] (verified)

Time = 0.08 (sec) , antiderivative size = 25, normalized size of antiderivative = 1.00, number of steps used = 9, number of rules used = 7, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 1.000, Rules used = {4482, 2788, 2717, 2715, 8, 3855, 3852} \[ \int (\sin (x)+\tan (x))^2 \, dx=2 \text {arctanh}(\sin (x))-\frac {x}{2}-2 \sin (x)+\tan (x)-\frac {1}{2} \sin (x) \cos (x) \]

[In]

Int[(Sin[x] + Tan[x])^2,x]

[Out]

-1/2*x + 2*ArcTanh[Sin[x]] - 2*Sin[x] - (Cos[x]*Sin[x])/2 + Tan[x]

Rule 8

Int[a_, x_Symbol] :> Simp[a*x, x] /; FreeQ[a, x]

Rule 2715

Int[((b_.)*sin[(c_.) + (d_.)*(x_)])^(n_), x_Symbol] :> Simp[(-b)*Cos[c + d*x]*((b*Sin[c + d*x])^(n - 1)/(d*n))
, x] + Dist[b^2*((n - 1)/n), Int[(b*Sin[c + d*x])^(n - 2), x], x] /; FreeQ[{b, c, d}, x] && GtQ[n, 1] && Integ
erQ[2*n]

Rule 2717

Int[sin[Pi/2 + (c_.) + (d_.)*(x_)], x_Symbol] :> Simp[Sin[c + d*x]/d, x] /; FreeQ[{c, d}, x]

Rule 2788

Int[((a_) + (b_.)*sin[(e_.) + (f_.)*(x_)])^(m_)*tan[(e_.) + (f_.)*(x_)]^(p_), x_Symbol] :> Dist[a^p, Int[Expan
dIntegrand[Sin[e + f*x]^p*((a + b*Sin[e + f*x])^(m - p/2)/(a - b*Sin[e + f*x])^(p/2)), x], x], x] /; FreeQ[{a,
 b, e, f}, x] && EqQ[a^2 - b^2, 0] && IntegersQ[m, p/2] && (LtQ[p, 0] || GtQ[m - p/2, 0])

Rule 3852

Int[csc[(c_.) + (d_.)*(x_)]^(n_), x_Symbol] :> Dist[-d^(-1), Subst[Int[ExpandIntegrand[(1 + x^2)^(n/2 - 1), x]
, x], x, Cot[c + d*x]], x] /; FreeQ[{c, d}, x] && IGtQ[n/2, 0]

Rule 3855

Int[csc[(c_.) + (d_.)*(x_)], x_Symbol] :> Simp[-ArcTanh[Cos[c + d*x]]/d, x] /; FreeQ[{c, d}, x]

Rule 4482

Int[u_, x_Symbol] :> Int[TrigSimplify[u], x] /; TrigSimplifyQ[u]

Rubi steps \begin{align*} \text {integral}& = \int (1+\cos (x))^2 \tan ^2(x) \, dx \\ & = \int \left (-2 \cos (x)-\cos ^2(x)+2 \sec (x)+\sec ^2(x)\right ) \, dx \\ & = -(2 \int \cos (x) \, dx)+2 \int \sec (x) \, dx-\int \cos ^2(x) \, dx+\int \sec ^2(x) \, dx \\ & = 2 \text {arctanh}(\sin (x))-2 \sin (x)-\frac {1}{2} \cos (x) \sin (x)-\frac {\int 1 \, dx}{2}-\text {Subst}(\int 1 \, dx,x,-\tan (x)) \\ & = -\frac {x}{2}+2 \text {arctanh}(\sin (x))-2 \sin (x)-\frac {1}{2} \cos (x) \sin (x)+\tan (x) \\ \end{align*}

Mathematica [B] (verified)

Leaf count is larger than twice the leaf count of optimal. \(60\) vs. \(2(25)=50\).

Time = 0.08 (sec) , antiderivative size = 60, normalized size of antiderivative = 2.40 \[ \int (\sin (x)+\tan (x))^2 \, dx=-\frac {x}{2}-2 \log \left (\cos \left (\frac {x}{2}\right )-\sin \left (\frac {x}{2}\right )\right )+2 \log \left (\cos \left (\frac {x}{2}\right )+\sin \left (\frac {x}{2}\right )\right )-2 \sin (x)-\frac {1}{8} \sec (x) \sin (3 x)+\frac {7 \tan (x)}{8} \]

[In]

Integrate[(Sin[x] + Tan[x])^2,x]

[Out]

-1/2*x - 2*Log[Cos[x/2] - Sin[x/2]] + 2*Log[Cos[x/2] + Sin[x/2]] - 2*Sin[x] - (Sec[x]*Sin[3*x])/8 + (7*Tan[x])
/8

Maple [A] (verified)

Time = 2.95 (sec) , antiderivative size = 25, normalized size of antiderivative = 1.00

method result size
default \(-\frac {\cos \left (x \right ) \sin \left (x \right )}{2}-\frac {x}{2}-2 \sin \left (x \right )+2 \ln \left (\sec \left (x \right )+\tan \left (x \right )\right )+\tan \left (x \right )\) \(25\)
parts \(-\frac {\cos \left (x \right ) \sin \left (x \right )}{2}+\frac {x}{2}+\tan \left (x \right )-\arctan \left (\tan \left (x \right )\right )-2 \sin \left (x \right )+2 \ln \left (\sec \left (x \right )+\tan \left (x \right )\right )\) \(30\)
risch \(-\frac {x}{2}+\frac {i {\mathrm e}^{2 i x}}{8}+i {\mathrm e}^{i x}-i {\mathrm e}^{-i x}-\frac {i {\mathrm e}^{-2 i x}}{8}+\frac {2 i}{{\mathrm e}^{2 i x}+1}+2 \ln \left (i+{\mathrm e}^{i x}\right )-2 \ln \left ({\mathrm e}^{i x}-i\right )\) \(71\)

[In]

int((sin(x)+tan(x))^2,x,method=_RETURNVERBOSE)

[Out]

-1/2*cos(x)*sin(x)-1/2*x-2*sin(x)+2*ln(sec(x)+tan(x))+tan(x)

Fricas [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 44 vs. \(2 (21) = 42\).

Time = 0.25 (sec) , antiderivative size = 44, normalized size of antiderivative = 1.76 \[ \int (\sin (x)+\tan (x))^2 \, dx=-\frac {x \cos \left (x\right ) - 2 \, \cos \left (x\right ) \log \left (\sin \left (x\right ) + 1\right ) + 2 \, \cos \left (x\right ) \log \left (-\sin \left (x\right ) + 1\right ) + {\left (\cos \left (x\right )^{2} + 4 \, \cos \left (x\right ) - 2\right )} \sin \left (x\right )}{2 \, \cos \left (x\right )} \]

[In]

integrate((sin(x)+tan(x))^2,x, algorithm="fricas")

[Out]

-1/2*(x*cos(x) - 2*cos(x)*log(sin(x) + 1) + 2*cos(x)*log(-sin(x) + 1) + (cos(x)^2 + 4*cos(x) - 2)*sin(x))/cos(
x)

Sympy [A] (verification not implemented)

Time = 0.50 (sec) , antiderivative size = 31, normalized size of antiderivative = 1.24 \[ \int (\sin (x)+\tan (x))^2 \, dx=- \frac {x}{2} - \log {\left (\sin {\left (x \right )} - 1 \right )} + \log {\left (\sin {\left (x \right )} + 1 \right )} - 2 \sin {\left (x \right )} - \frac {\sin {\left (2 x \right )}}{4} + \tan {\left (x \right )} \]

[In]

integrate((sin(x)+tan(x))**2,x)

[Out]

-x/2 - log(sin(x) - 1) + log(sin(x) + 1) - 2*sin(x) - sin(2*x)/4 + tan(x)

Maxima [A] (verification not implemented)

none

Time = 0.31 (sec) , antiderivative size = 28, normalized size of antiderivative = 1.12 \[ \int (\sin (x)+\tan (x))^2 \, dx=-\frac {1}{2} \, x + \log \left (\sin \left (x\right ) + 1\right ) - \log \left (\sin \left (x\right ) - 1\right ) - \frac {1}{4} \, \sin \left (2 \, x\right ) - 2 \, \sin \left (x\right ) + \tan \left (x\right ) \]

[In]

integrate((sin(x)+tan(x))^2,x, algorithm="maxima")

[Out]

-1/2*x + log(sin(x) + 1) - log(sin(x) - 1) - 1/4*sin(2*x) - 2*sin(x) + tan(x)

Giac [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 177 vs. \(2 (21) = 42\).

Time = 0.33 (sec) , antiderivative size = 177, normalized size of antiderivative = 7.08 \[ \int (\sin (x)+\tan (x))^2 \, dx=\frac {1}{2} \, x - \frac {x \tan \left (\frac {1}{2} \, x\right )^{2} - \log \left (\frac {2 \, {\left (\tan \left (\frac {1}{2} \, x\right )^{2} + 2 \, \tan \left (\frac {1}{2} \, x\right ) + 1\right )}}{\tan \left (\frac {1}{2} \, x\right )^{2} + 1}\right ) \tan \left (\frac {1}{2} \, x\right )^{2} + \log \left (\frac {2 \, {\left (\tan \left (\frac {1}{2} \, x\right )^{2} - 2 \, \tan \left (\frac {1}{2} \, x\right ) + 1\right )}}{\tan \left (\frac {1}{2} \, x\right )^{2} + 1}\right ) \tan \left (\frac {1}{2} \, x\right )^{2} - \tan \left (\frac {1}{2} \, x\right )^{2} \tan \left (x\right ) + x - \log \left (\frac {2 \, {\left (\tan \left (\frac {1}{2} \, x\right )^{2} + 2 \, \tan \left (\frac {1}{2} \, x\right ) + 1\right )}}{\tan \left (\frac {1}{2} \, x\right )^{2} + 1}\right ) + \log \left (\frac {2 \, {\left (\tan \left (\frac {1}{2} \, x\right )^{2} - 2 \, \tan \left (\frac {1}{2} \, x\right ) + 1\right )}}{\tan \left (\frac {1}{2} \, x\right )^{2} + 1}\right ) + 4 \, \tan \left (\frac {1}{2} \, x\right ) - \tan \left (x\right )}{\tan \left (\frac {1}{2} \, x\right )^{2} + 1} - \frac {1}{4} \, \sin \left (2 \, x\right ) \]

[In]

integrate((sin(x)+tan(x))^2,x, algorithm="giac")

[Out]

1/2*x - (x*tan(1/2*x)^2 - log(2*(tan(1/2*x)^2 + 2*tan(1/2*x) + 1)/(tan(1/2*x)^2 + 1))*tan(1/2*x)^2 + log(2*(ta
n(1/2*x)^2 - 2*tan(1/2*x) + 1)/(tan(1/2*x)^2 + 1))*tan(1/2*x)^2 - tan(1/2*x)^2*tan(x) + x - log(2*(tan(1/2*x)^
2 + 2*tan(1/2*x) + 1)/(tan(1/2*x)^2 + 1)) + log(2*(tan(1/2*x)^2 - 2*tan(1/2*x) + 1)/(tan(1/2*x)^2 + 1)) + 4*ta
n(1/2*x) - tan(x))/(tan(1/2*x)^2 + 1) - 1/4*sin(2*x)

Mupad [B] (verification not implemented)

Time = 28.60 (sec) , antiderivative size = 61, normalized size of antiderivative = 2.44 \[ \int (\sin (x)+\tan (x))^2 \, dx=4\,\mathrm {atanh}\left (\mathrm {tan}\left (\frac {x}{2}\right )\right )-\frac {x}{2}+\frac {5\,{\mathrm {tan}\left (\frac {x}{2}\right )}^5+6\,{\mathrm {tan}\left (\frac {x}{2}\right )}^3-3\,\mathrm {tan}\left (\frac {x}{2}\right )}{-{\mathrm {tan}\left (\frac {x}{2}\right )}^6-{\mathrm {tan}\left (\frac {x}{2}\right )}^4+{\mathrm {tan}\left (\frac {x}{2}\right )}^2+1} \]

[In]

int((sin(x) + tan(x))^2,x)

[Out]

4*atanh(tan(x/2)) - x/2 + (6*tan(x/2)^3 - 3*tan(x/2) + 5*tan(x/2)^5)/(tan(x/2)^2 - tan(x/2)^4 - tan(x/2)^6 + 1
)