3.1.22 \(\int \frac {1}{(1+\cos (x)+\sin (x))^2} \, dx\) [22]

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

[Out]

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

________________________________________________________________________________________

Rubi [A]
time = 0.01, antiderivative size = 29, normalized size of antiderivative = 1.00, number of steps used = 3, number of rules used = 3, integrand size = 8, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.375, Rules used = {3208, 3203, 31} \begin {gather*} -\log \left (\tan \left (\frac {x}{2}\right )+1\right )-\frac {\cos (x)-\sin (x)}{\sin (x)+\cos (x)+1} \end {gather*}

Antiderivative was successfully verified.

[In]

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

[Out]

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

Rule 31

Int[((a_) + (b_.)*(x_))^(-1), x_Symbol] :> Simp[Log[RemoveContent[a + b*x, x]]/b, x] /; FreeQ[{a, b}, x]

Rule 3203

Int[(cos[(d_.) + (e_.)*(x_)]*(b_.) + (a_) + (c_.)*sin[(d_.) + (e_.)*(x_)])^(-1), x_Symbol] :> Module[{f = Free
Factors[Tan[(d + e*x)/2], x]}, Dist[2*(f/e), Subst[Int[1/(a + b + 2*c*f*x + (a - b)*f^2*x^2), x], x, Tan[(d +
e*x)/2]/f], x]] /; FreeQ[{a, b, c, d, e}, x] && NeQ[a^2 - b^2 - c^2, 0]

Rule 3208

Int[(cos[(d_.) + (e_.)*(x_)]*(b_.) + (a_) + (c_.)*sin[(d_.) + (e_.)*(x_)])^(n_), x_Symbol] :> Simp[((-c)*Cos[d
 + e*x] + b*Sin[d + e*x])*((a + b*Cos[d + e*x] + c*Sin[d + e*x])^(n + 1)/(e*(n + 1)*(a^2 - b^2 - c^2))), x] +
Dist[1/((n + 1)*(a^2 - b^2 - c^2)), Int[(a*(n + 1) - b*(n + 2)*Cos[d + e*x] - c*(n + 2)*Sin[d + e*x])*(a + b*C
os[d + e*x] + c*Sin[d + e*x])^(n + 1), x], x] /; FreeQ[{a, b, c, d, e}, x] && NeQ[a^2 - b^2 - c^2, 0] && LtQ[n
, -1] && NeQ[n, -3/2]

Rubi steps

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

________________________________________________________________________________________

Mathematica [A]
time = 0.02, size = 56, normalized size = 1.93 \begin {gather*} \log \left (\cos \left (\frac {x}{2}\right )\right )-\log \left (\cos \left (\frac {x}{2}\right )+\sin \left (\frac {x}{2}\right )\right )+\frac {\sin \left (\frac {x}{2}\right )}{\cos \left (\frac {x}{2}\right )+\sin \left (\frac {x}{2}\right )}+\frac {1}{2} \tan \left (\frac {x}{2}\right ) \end {gather*}

Antiderivative was successfully verified.

[In]

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

[Out]

Log[Cos[x/2]] - Log[Cos[x/2] + Sin[x/2]] + Sin[x/2]/(Cos[x/2] + Sin[x/2]) + Tan[x/2]/2

________________________________________________________________________________________

Mathics [A]
time = 2.70, size = 33, normalized size = 1.14 \begin {gather*} \frac {-3+\text {Tan}\left [\frac {x}{2}\right ]^2-2 \text {Log}\left [1+\text {Tan}\left [\frac {x}{2}\right ]\right ] \left (1+\text {Tan}\left [\frac {x}{2}\right ]\right )}{2+2 \text {Tan}\left [\frac {x}{2}\right ]} \end {gather*}

Antiderivative was successfully verified.

[In]

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

[Out]

(-3 + Tan[x / 2] ^ 2 - 2 Log[1 + Tan[x / 2]] (1 + Tan[x / 2])) / (2 (1 + Tan[x / 2]))

________________________________________________________________________________________

Maple [A]
time = 0.09, size = 27, normalized size = 0.93

method result size
default \(\frac {\tan \left (\frac {x}{2}\right )}{2}-\frac {1}{1+\tan \left (\frac {x}{2}\right )}-\ln \left (1+\tan \left (\frac {x}{2}\right )\right )\) \(27\)
norman \(\frac {\frac {\left (\tan ^{2}\left (\frac {x}{2}\right )\right )}{2}-\frac {3}{2}}{1+\tan \left (\frac {x}{2}\right )}-\ln \left (1+\tan \left (\frac {x}{2}\right )\right )\) \(30\)
risch \(\frac {\left (-1+i\right ) \left ({\mathrm e}^{i x}+1+i\right )}{{\mathrm e}^{2 i x}+i+{\mathrm e}^{i x}+i {\mathrm e}^{i x}}+\ln \left (1+{\mathrm e}^{i x}\right )-\ln \left ({\mathrm e}^{i x}+i\right )\) \(57\)

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

1/2*tan(1/2*x)-1/(1+tan(1/2*x))-ln(1+tan(1/2*x))

________________________________________________________________________________________

Maxima [A]
time = 0.27, size = 40, normalized size = 1.38 \begin {gather*} \frac {\sin \left (x\right )}{2 \, {\left (\cos \left (x\right ) + 1\right )}} - \frac {1}{\frac {\sin \left (x\right )}{\cos \left (x\right ) + 1} + 1} - \log \left (\frac {\sin \left (x\right )}{\cos \left (x\right ) + 1} + 1\right ) \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

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

________________________________________________________________________________________

Fricas [A]
time = 0.35, size = 46, normalized size = 1.59 \begin {gather*} \frac {{\left (\cos \left (x\right ) + \sin \left (x\right ) + 1\right )} \log \left (\frac {1}{2} \, \cos \left (x\right ) + \frac {1}{2}\right ) - {\left (\cos \left (x\right ) + \sin \left (x\right ) + 1\right )} \log \left (\sin \left (x\right ) + 1\right ) - 2 \, \cos \left (x\right ) + 2 \, \sin \left (x\right )}{2 \, {\left (\cos \left (x\right ) + \sin \left (x\right ) + 1\right )}} \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

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

________________________________________________________________________________________

Sympy [B] Leaf count of result is larger than twice the leaf count of optimal. 66 vs. \(2 (22) = 44\)
time = 0.37, size = 66, normalized size = 2.28 \begin {gather*} - \frac {2 \log {\left (\tan {\left (\frac {x}{2} \right )} + 1 \right )} \tan {\left (\frac {x}{2} \right )}}{2 \tan {\left (\frac {x}{2} \right )} + 2} - \frac {2 \log {\left (\tan {\left (\frac {x}{2} \right )} + 1 \right )}}{2 \tan {\left (\frac {x}{2} \right )} + 2} + \frac {\tan ^{2}{\left (\frac {x}{2} \right )}}{2 \tan {\left (\frac {x}{2} \right )} + 2} - \frac {3}{2 \tan {\left (\frac {x}{2} \right )} + 2} \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

-2*log(tan(x/2) + 1)*tan(x/2)/(2*tan(x/2) + 2) - 2*log(tan(x/2) + 1)/(2*tan(x/2) + 2) + tan(x/2)**2/(2*tan(x/2
) + 2) - 3/(2*tan(x/2) + 2)

________________________________________________________________________________________

Giac [A]
time = 0.00, size = 40, normalized size = 1.38 \begin {gather*} 2 \left (\frac {\tan \left (\frac {x}{2}\right )}{4}+\frac {\tan \left (\frac {x}{2}\right )}{2 \left (\tan \left (\frac {x}{2}\right )+1\right )}-\frac {\ln \left |\tan \left (\frac {x}{2}\right )+1\right |}{2}\right ) \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

tan(1/2*x)/(tan(1/2*x) + 1) - log(abs(tan(1/2*x) + 1)) + 1/2*tan(1/2*x)

________________________________________________________________________________________

Mupad [B]
time = 0.28, size = 26, normalized size = 0.90 \begin {gather*} \frac {\mathrm {tan}\left (\frac {x}{2}\right )}{2}-\ln \left (\mathrm {tan}\left (\frac {x}{2}\right )+1\right )-\frac {1}{\mathrm {tan}\left (\frac {x}{2}\right )+1} \end {gather*}

Verification of antiderivative is not currently implemented for this CAS.

[In]

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

[Out]

tan(x/2)/2 - log(tan(x/2) + 1) - 1/(tan(x/2) + 1)

________________________________________________________________________________________