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

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

[Out]

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

________________________________________________________________________________________

Rubi [A]  time = 3.09, 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 = {4401, 2648, 12, 6742, 1680, 1673, 1094, 634, 618, 204, 628, 1107} \[ \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 ) \]

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 204

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

Rule 618

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 628

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 634

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 1094

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 1107

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 1673

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 1680

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 2648

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 4401

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

Rule 6742

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 \operatorname {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 \operatorname {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} \operatorname {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} \operatorname {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} \operatorname {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} \operatorname {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} \operatorname {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} \operatorname {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} \operatorname {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} \operatorname {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 \operatorname {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 \operatorname {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 \operatorname {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 \operatorname {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 \operatorname {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]  time = 0.14, size = 46, normalized size = 2.42 \[ \frac {1}{2} \tan ^{-1}\left (\frac {\cos (x)+1}{-\sin (x)+\cos (x)-1}\right )-\frac {1}{2} \tan ^{-1}\left (\frac {1}{2} \sec ^2\left (\frac {x}{2}\right ) (-\sin (x)+\cos (x)-1)\right ) \]

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

________________________________________________________________________________________

fricas [B]  time = 0.47, size = 48, normalized size = 2.53 \[ \frac {1}{2} \, \arctan \left (-\frac {3 \, \cos \relax (x)^{2} - 2 \, {\left (3 \, \cos \relax (x) + 1\right )} \sin \relax (x) - 4 \, \cos \relax (x) - 3}{2 \, {\left (2 \, \cos \relax (x)^{2} + {\left (\cos \relax (x) - 3\right )} \sin \relax (x) + 4 \, \cos \relax (x) - 2\right )}}\right ) \]

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))

________________________________________________________________________________________

giac [A]  time = 1.23, size = 18, normalized size = 0.95 \[ -\arctan \left (-\tan \left (\frac {1}{2} \, x\right )^{2} - \tan \left (\frac {1}{2} \, x\right )\right ) \]

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="giac")

[Out]

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

________________________________________________________________________________________

maple [A]  time = 0.18, size = 13, normalized size = 0.68 \[ \arctan \left (\tan ^{2}\left (\frac {x}{2}\right )+\tan \left (\frac {x}{2}\right )\right ) \]

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)

[Out]

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

________________________________________________________________________________________

maxima [F]  time = 0.00, size = 0, normalized size = 0.00 \[ \int \frac {\cos \relax (x) + 2 \, \sin \relax (x) + 1}{\cos \relax (x)^{2} - 2 \, \cos \relax (x) \sin \relax (x) + 2 \, \sin \relax (x) + 3}\,{d x} \]

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)

________________________________________________________________________________________

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

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)

________________________________________________________________________________________

sympy [C]  time = 47.01, size = 94, normalized size = 4.95 \[ \frac {i \log {\left (\tan {\left (\frac {x}{2} \right )} + \frac {1}{2} - \frac {\sqrt {1 - 4 i}}{2} \right )}}{2} + \frac {i \log {\left (\tan {\left (\frac {x}{2} \right )} + \frac {1}{2} + \frac {\sqrt {1 - 4 i}}{2} \right )}}{2} - \frac {i \log {\left (\tan {\left (\frac {x}{2} \right )} + \frac {1}{2} - \frac {\sqrt {1 + 4 i}}{2} \right )}}{2} - \frac {i \log {\left (\tan {\left (\frac {x}{2} \right )} + \frac {1}{2} + \frac {\sqrt {1 + 4 i}}{2} \right )}}{2} \]

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]

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

________________________________________________________________________________________