3.1.2 \(\int \frac {1+\cos (x)+2 \sin (x)}{3+\cos ^2(x)+2 \sin (x)-2 \cos (x) \sin (x)} \, dx\) [2]

Optimal. Leaf size=19 \[ -\tan ^{-1}\left (\frac {2 \cos (x)-\sin (x)}{2+\sin (x)}\right ) \]

[Out]

-arctan((2*cos(x)-sin(x))/(2+sin(x)))

________________________________________________________________________________________

Rubi [A]
time = 1.98, antiderivative size = 38, normalized size of antiderivative = 2.00, number of steps used = 43, number of rules used = 12, integrand size = 27, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.444, Rules used = {4486, 2727, 12, 6874, 1694, 1687, 1108, 648, 632, 210, 642, 1121} \begin {gather*} \cot \left (\frac {x}{2}\right )-\frac {\sin (x)}{1-\cos (x)}-\tan ^{-1}\left (\frac {2 \cos (x)-\sin (x)}{\sin (x)+2}\right ) \end {gather*}

Antiderivative was successfully verified.

[In]

Int[(1 + Cos[x] + 2*Sin[x])/(3 + Cos[x]^2 + 2*Sin[x] - 2*Cos[x]*Sin[x]),x]

[Out]

-ArcTan[(2*Cos[x] - Sin[x])/(2 + Sin[x])] + Cot[x/2] - Sin[x]/(1 - Cos[x])

Rule 12

Int[(a_)*(u_), x_Symbol] :> Dist[a, Int[u, x], x] /; FreeQ[a, x] &&  !MatchQ[u, (b_)*(v_) /; FreeQ[b, x]]

Rule 210

Int[((a_) + (b_.)*(x_)^2)^(-1), x_Symbol] :> Simp[(-(Rt[-a, 2]*Rt[-b, 2])^(-1))*ArcTan[Rt[-b, 2]*(x/Rt[-a, 2])
], x] /; FreeQ[{a, b}, x] && PosQ[a/b] && (LtQ[a, 0] || LtQ[b, 0])

Rule 632

Int[((a_.) + (b_.)*(x_) + (c_.)*(x_)^2)^(-1), x_Symbol] :> Dist[-2, Subst[Int[1/Simp[b^2 - 4*a*c - x^2, x], x]
, x, b + 2*c*x], x] /; FreeQ[{a, b, c}, x] && NeQ[b^2 - 4*a*c, 0]

Rule 642

Int[((d_) + (e_.)*(x_))/((a_.) + (b_.)*(x_) + (c_.)*(x_)^2), x_Symbol] :> Simp[d*(Log[RemoveContent[a + b*x +
c*x^2, x]]/b), x] /; FreeQ[{a, b, c, d, e}, x] && EqQ[2*c*d - b*e, 0]

Rule 648

Int[((d_.) + (e_.)*(x_))/((a_) + (b_.)*(x_) + (c_.)*(x_)^2), x_Symbol] :> Dist[(2*c*d - b*e)/(2*c), Int[1/(a +
 b*x + c*x^2), x], x] + Dist[e/(2*c), Int[(b + 2*c*x)/(a + b*x + c*x^2), x], x] /; FreeQ[{a, b, c, d, e}, x] &
& NeQ[2*c*d - b*e, 0] && NeQ[b^2 - 4*a*c, 0] &&  !NiceSqrtQ[b^2 - 4*a*c]

Rule 1108

Int[((a_) + (b_.)*(x_)^2 + (c_.)*(x_)^4)^(-1), x_Symbol] :> With[{q = Rt[a/c, 2]}, With[{r = Rt[2*q - b/c, 2]}
, Dist[1/(2*c*q*r), Int[(r - x)/(q - r*x + x^2), x], x] + Dist[1/(2*c*q*r), Int[(r + x)/(q + r*x + x^2), x], x
]]] /; FreeQ[{a, b, c}, x] && NeQ[b^2 - 4*a*c, 0] && NegQ[b^2 - 4*a*c]

Rule 1121

Int[(x_)*((a_) + (b_.)*(x_)^2 + (c_.)*(x_)^4)^(p_.), x_Symbol] :> Dist[1/2, Subst[Int[(a + b*x + c*x^2)^p, x],
 x, x^2], x] /; FreeQ[{a, b, c, p}, x]

Rule 1687

Int[(Pq_)*((a_) + (b_.)*(x_)^2 + (c_.)*(x_)^4)^(p_), x_Symbol] :> Module[{q = Expon[Pq, x], k}, Int[Sum[Coeff[
Pq, x, 2*k]*x^(2*k), {k, 0, q/2}]*(a + b*x^2 + c*x^4)^p, x] + Int[x*Sum[Coeff[Pq, x, 2*k + 1]*x^(2*k), {k, 0,
(q - 1)/2}]*(a + b*x^2 + c*x^4)^p, x]] /; FreeQ[{a, b, c, p}, x] && PolyQ[Pq, x] &&  !PolyQ[Pq, x^2]

Rule 1694

Int[(Pq_)*(Q4_)^(p_), x_Symbol] :> With[{a = Coeff[Q4, x, 0], b = Coeff[Q4, x, 1], c = Coeff[Q4, x, 2], d = Co
eff[Q4, x, 3], e = Coeff[Q4, x, 4]}, Subst[Int[SimplifyIntegrand[(Pq /. x -> -d/(4*e) + x)*(a + d^4/(256*e^3)
- b*(d/(8*e)) + (c - 3*(d^2/(8*e)))*x^2 + e*x^4)^p, x], x], x, d/(4*e) + x] /; EqQ[d^3 - 4*c*d*e + 8*b*e^2, 0]
 && NeQ[d, 0]] /; FreeQ[p, x] && PolyQ[Pq, x] && PolyQ[Q4, x, 4] &&  !IGtQ[p, 0]

Rule 2727

Int[((a_) + (b_.)*sin[(c_.) + (d_.)*(x_)])^(-1), x_Symbol] :> Simp[-Cos[c + d*x]/(d*(b + a*Sin[c + d*x])), x]
/; FreeQ[{a, b, c, d}, x] && EqQ[a^2 - b^2, 0]

Rule 4486

Int[u_, x_Symbol] :> With[{v = ExpandTrig[u, x]}, Int[v, x] /; SumQ[v]] /;  !InertTrigFreeQ[u]

Rule 6874

Int[u_, x_Symbol] :> With[{v = ExpandIntegrand[u, x]}, Int[v, x] /; SumQ[v]]

Rubi steps

\begin {align*} \int \frac {1+\cos (x)+2 \sin (x)}{3+\cos ^2(x)+2 \sin (x)-2 \cos (x) \sin (x)} \, dx &=\int \left (\frac {1}{1-\cos (x)}+\frac {2 \left (1+\cos ^2(x)\right )}{(-1+\cos (x)) \left (3+\cos ^2(x)+2 \sin (x)-2 \cos (x) \sin (x)\right )}\right ) \, dx\\ &=2 \int \frac {1+\cos ^2(x)}{(-1+\cos (x)) \left (3+\cos ^2(x)+2 \sin (x)-2 \cos (x) \sin (x)\right )} \, dx+\int \frac {1}{1-\cos (x)} \, dx\\ &=-\frac {\sin (x)}{1-\cos (x)}+2 \int \left (\frac {1}{(-1+\cos (x)) \left (3+\cos ^2(x)+2 \sin (x)-2 \cos (x) \sin (x)\right )}+\frac {\cos ^2(x)}{(-1+\cos (x)) \left (3+\cos ^2(x)+2 \sin (x)-2 \cos (x) \sin (x)\right )}\right ) \, dx\\ &=-\frac {\sin (x)}{1-\cos (x)}+2 \int \frac {1}{(-1+\cos (x)) \left (3+\cos ^2(x)+2 \sin (x)-2 \cos (x) \sin (x)\right )} \, dx+2 \int \frac {\cos ^2(x)}{(-1+\cos (x)) \left (3+\cos ^2(x)+2 \sin (x)-2 \cos (x) \sin (x)\right )} \, dx\\ &=-\frac {\sin (x)}{1-\cos (x)}+4 \text {Subst}\left (\int \frac {\left (1-x^2\right )^2}{8 x^2 \left (-1-x^2-2 x^3-x^4\right )} \, dx,x,\tan \left (\frac {x}{2}\right )\right )+4 \text {Subst}\left (\int \frac {\left (1+x^2\right )^2}{8 x^2 \left (-1-x^2-2 x^3-x^4\right )} \, dx,x,\tan \left (\frac {x}{2}\right )\right )\\ &=-\frac {\sin (x)}{1-\cos (x)}+\frac {1}{2} \text {Subst}\left (\int \frac {\left (1-x^2\right )^2}{x^2 \left (-1-x^2-2 x^3-x^4\right )} \, dx,x,\tan \left (\frac {x}{2}\right )\right )+\frac {1}{2} \text {Subst}\left (\int \frac {\left (1+x^2\right )^2}{x^2 \left (-1-x^2-2 x^3-x^4\right )} \, dx,x,\tan \left (\frac {x}{2}\right )\right )\\ &=-\frac {\sin (x)}{1-\cos (x)}+\frac {1}{2} \text {Subst}\left (\int \left (-\frac {1}{x^2}+\frac {-1+2 x}{1+x^2+2 x^3+x^4}\right ) \, dx,x,\tan \left (\frac {x}{2}\right )\right )+\frac {1}{2} \text {Subst}\left (\int \left (-\frac {1}{x^2}+\frac {3+2 x}{1+x^2+2 x^3+x^4}\right ) \, dx,x,\tan \left (\frac {x}{2}\right )\right )\\ &=\cot \left (\frac {x}{2}\right )-\frac {\sin (x)}{1-\cos (x)}+\frac {1}{2} \text {Subst}\left (\int \frac {-1+2 x}{1+x^2+2 x^3+x^4} \, dx,x,\tan \left (\frac {x}{2}\right )\right )+\frac {1}{2} \text {Subst}\left (\int \frac {3+2 x}{1+x^2+2 x^3+x^4} \, dx,x,\tan \left (\frac {x}{2}\right )\right )\\ &=\cot \left (\frac {x}{2}\right )-\frac {\sin (x)}{1-\cos (x)}+\frac {1}{2} \text {Subst}\left (\int \frac {32 (-1+x)}{17-8 x^2+16 x^4} \, dx,x,\frac {1}{2}+\tan \left (\frac {x}{2}\right )\right )+\frac {1}{2} \text {Subst}\left (\int \frac {32 (1+x)}{17-8 x^2+16 x^4} \, dx,x,\frac {1}{2}+\tan \left (\frac {x}{2}\right )\right )\\ &=\cot \left (\frac {x}{2}\right )-\frac {\sin (x)}{1-\cos (x)}+16 \text {Subst}\left (\int \frac {-1+x}{17-8 x^2+16 x^4} \, dx,x,\frac {1}{2}+\tan \left (\frac {x}{2}\right )\right )+16 \text {Subst}\left (\int \frac {1+x}{17-8 x^2+16 x^4} \, dx,x,\frac {1}{2}+\tan \left (\frac {x}{2}\right )\right )\\ &=\cot \left (\frac {x}{2}\right )-\frac {\sin (x)}{1-\cos (x)}+2 \left (16 \text {Subst}\left (\int \frac {x}{17-8 x^2+16 x^4} \, dx,x,\frac {1}{2}+\tan \left (\frac {x}{2}\right )\right )\right )\\ &=\cot \left (\frac {x}{2}\right )-\frac {\sin (x)}{1-\cos (x)}+2 \left (8 \text {Subst}\left (\int \frac {1}{17-8 x+16 x^2} \, dx,x,\left (\frac {1}{2}+\tan \left (\frac {x}{2}\right )\right )^2\right )\right )\\ &=\cot \left (\frac {x}{2}\right )-\frac {\sin (x)}{1-\cos (x)}-2 \left (16 \text {Subst}\left (\int \frac {1}{-1024-x^2} \, dx,x,-8+32 \left (\frac {1}{2}+\tan \left (\frac {x}{2}\right )\right )^2\right )\right )\\ &=\tan ^{-1}\left (\frac {1}{4} \left (-1+\left (1+2 \tan \left (\frac {x}{2}\right )\right )^2\right )\right )+\cot \left (\frac {x}{2}\right )-\frac {\sin (x)}{1-\cos (x)}\\ \end {align*}

________________________________________________________________________________________

Mathematica [B] Leaf count is larger than twice the leaf count of optimal. \(46\) vs. \(2(19)=38\).
time = 0.08, size = 46, normalized size = 2.42 \begin {gather*} \frac {1}{2} \tan ^{-1}\left (\frac {1+\cos (x)}{-1+\cos (x)-\sin (x)}\right )-\frac {1}{2} \tan ^{-1}\left (\frac {1}{2} \sec ^2\left (\frac {x}{2}\right ) (-1+\cos (x)-\sin (x))\right ) \end {gather*}

Antiderivative was successfully verified.

[In]

Integrate[(1 + Cos[x] + 2*Sin[x])/(3 + Cos[x]^2 + 2*Sin[x] - 2*Cos[x]*Sin[x]),x]

[Out]

ArcTan[(1 + Cos[x])/(-1 + Cos[x] - Sin[x])]/2 - ArcTan[(Sec[x/2]^2*(-1 + Cos[x] - Sin[x]))/2]/2

________________________________________________________________________________________

Mathics [F(-2)]
time = 0.00, size = 0, normalized size = 0.00 \begin {gather*} \text {cought exception: maximum recursion depth exceeded} \end {gather*}

Warning: Unable to verify antiderivative.

[In]

mathics('Integrate[(Cos[x] + 2*Sin[x] + 1)/(Cos[x]^2 - 2*Sin[x]*Cos[x] + 2*Sin[x] + 3),x]')

[Out]

cought exception: maximum recursion depth exceeded

________________________________________________________________________________________

Maple [A]
time = 0.13, size = 13, normalized size = 0.68

method result size
default \(\arctan \left (\tan ^{2}\left (\frac {x}{2}\right )+\tan \left (\frac {x}{2}\right )\right )\) \(13\)
risch \(-\frac {i \ln \left ({\mathrm e}^{2 i x}+\left (\frac {2}{5}+\frac {6 i}{5}\right ) {\mathrm e}^{i x}+\frac {1}{5}-\frac {2 i}{5}\right )}{2}+\frac {i \ln \left ({\mathrm e}^{2 i x}+\left (-2-2 i\right ) {\mathrm e}^{i x}+1-2 i\right )}{2}\) \(46\)

Verification of antiderivative is not currently implemented for this CAS.

[In]

int((1+cos(x)+2*sin(x))/(3+cos(x)^2+2*sin(x)-2*cos(x)*sin(x)),x,method=_RETURNVERBOSE)

[Out]

arctan(tan(1/2*x)^2+tan(1/2*x))

________________________________________________________________________________________

Maxima [F]
time = 0.00, size = 0, normalized size = 0.00 \begin {gather*} \text {Failed to integrate} \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

integrate((1+cos(x)+2*sin(x))/(3+cos(x)^2+2*sin(x)-2*cos(x)*sin(x)),x, algorithm="maxima")

[Out]

integrate((cos(x) + 2*sin(x) + 1)/(cos(x)^2 - 2*cos(x)*sin(x) + 2*sin(x) + 3), x)

________________________________________________________________________________________

Fricas [B] Leaf count of result is larger than twice the leaf count of optimal. 48 vs. \(2 (19) = 38\).
time = 0.32, size = 48, normalized size = 2.53 \begin {gather*} \frac {1}{2} \, \arctan \left (-\frac {3 \, \cos \left (x\right )^{2} - 2 \, {\left (3 \, \cos \left (x\right ) + 1\right )} \sin \left (x\right ) - 4 \, \cos \left (x\right ) - 3}{2 \, {\left (2 \, \cos \left (x\right )^{2} + {\left (\cos \left (x\right ) - 3\right )} \sin \left (x\right ) + 4 \, \cos \left (x\right ) - 2\right )}}\right ) \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

integrate((1+cos(x)+2*sin(x))/(3+cos(x)^2+2*sin(x)-2*cos(x)*sin(x)),x, algorithm="fricas")

[Out]

1/2*arctan(-1/2*(3*cos(x)^2 - 2*(3*cos(x) + 1)*sin(x) - 4*cos(x) - 3)/(2*cos(x)^2 + (cos(x) - 3)*sin(x) + 4*co
s(x) - 2))

________________________________________________________________________________________

Sympy [F]
time = 0.00, size = 0, normalized size = 0.00 \begin {gather*} \int \frac {2 \sin {\left (x \right )} + \cos {\left (x \right )} + 1}{- 2 \sin {\left (x \right )} \cos {\left (x \right )} + 2 \sin {\left (x \right )} + \cos ^{2}{\left (x \right )} + 3}\, dx \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

integrate((1+cos(x)+2*sin(x))/(3+cos(x)**2+2*sin(x)-2*cos(x)*sin(x)),x)

[Out]

Integral((2*sin(x) + cos(x) + 1)/(-2*sin(x)*cos(x) + 2*sin(x) + cos(x)**2 + 3), x)

________________________________________________________________________________________

Giac [A]
time = 0.03, size = 21, normalized size = 1.11 \begin {gather*} -\frac {2}{2} \arctan \left (-\tan ^{2}\left (\frac {x}{2}\right )-\tan \left (\frac {x}{2}\right )\right ) \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

integrate((1+cos(x)+2*sin(x))/(3+cos(x)^2+2*sin(x)-2*cos(x)*sin(x)),x)

[Out]

-arctan(-tan(1/2*x)^2 - tan(1/2*x))

________________________________________________________________________________________

Mupad [B]
time = 0.31, size = 12, normalized size = 0.63 \begin {gather*} \mathrm {atan}\left ({\mathrm {tan}\left (\frac {x}{2}\right )}^2+\mathrm {tan}\left (\frac {x}{2}\right )\right ) \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

int((cos(x) + 2*sin(x) + 1)/(2*sin(x) - 2*cos(x)*sin(x) + cos(x)^2 + 3),x)

[Out]

atan(tan(x/2) + tan(x/2)^2)

________________________________________________________________________________________