\(\int \frac {A+B \cos (c+d x)+C \cos ^2(c+d x)}{a+b \cos (c+d x)} \, dx\) [980]

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

Optimal result

Integrand size = 33, antiderivative size = 97 \[ \int \frac {A+B \cos (c+d x)+C \cos ^2(c+d x)}{a+b \cos (c+d x)} \, dx=\frac {(b B-a C) x}{b^2}+\frac {2 \left (A b^2-a (b B-a C)\right ) \arctan \left (\frac {\sqrt {a-b} \tan \left (\frac {1}{2} (c+d x)\right )}{\sqrt {a+b}}\right )}{\sqrt {a-b} b^2 \sqrt {a+b} d}+\frac {C \sin (c+d x)}{b d} \] Output:

(B*b-C*a)*x/b^2+2*(A*b^2-a*(B*b-C*a))*arctan((a-b)^(1/2)*tan(1/2*d*x+1/2*c 
)/(a+b)^(1/2))/(a-b)^(1/2)/b^2/(a+b)^(1/2)/d+C*sin(d*x+c)/b/d
 

Mathematica [A] (verified)

Time = 0.95 (sec) , antiderivative size = 92, normalized size of antiderivative = 0.95 \[ \int \frac {A+B \cos (c+d x)+C \cos ^2(c+d x)}{a+b \cos (c+d x)} \, dx=\frac {(b B-a C) (c+d x)-\frac {2 \left (A b^2+a (-b B+a C)\right ) \text {arctanh}\left (\frac {(a-b) \tan \left (\frac {1}{2} (c+d x)\right )}{\sqrt {-a^2+b^2}}\right )}{\sqrt {-a^2+b^2}}+b C \sin (c+d x)}{b^2 d} \] Input:

Integrate[(A + B*Cos[c + d*x] + C*Cos[c + d*x]^2)/(a + b*Cos[c + d*x]),x]
 

Output:

((b*B - a*C)*(c + d*x) - (2*(A*b^2 + a*(-(b*B) + a*C))*ArcTanh[((a - b)*Ta 
n[(c + d*x)/2])/Sqrt[-a^2 + b^2]])/Sqrt[-a^2 + b^2] + b*C*Sin[c + d*x])/(b 
^2*d)
 

Rubi [A] (verified)

Time = 0.45 (sec) , antiderivative size = 102, normalized size of antiderivative = 1.05, number of steps used = 8, number of rules used = 7, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.212, Rules used = {3042, 3502, 3042, 3214, 3042, 3138, 218}

Below are the steps used by Rubi to obtain the solution. The rule number used for the transformation is given above next to the arrow. The rules definitions used are listed below.

\(\displaystyle \int \frac {A+B \cos (c+d x)+C \cos ^2(c+d x)}{a+b \cos (c+d x)} \, dx\)

\(\Big \downarrow \) 3042

\(\displaystyle \int \frac {A+B \sin \left (c+d x+\frac {\pi }{2}\right )+C \sin \left (c+d x+\frac {\pi }{2}\right )^2}{a+b \sin \left (c+d x+\frac {\pi }{2}\right )}dx\)

\(\Big \downarrow \) 3502

\(\displaystyle \frac {\int \frac {A b+(b B-a C) \cos (c+d x)}{a+b \cos (c+d x)}dx}{b}+\frac {C \sin (c+d x)}{b d}\)

\(\Big \downarrow \) 3042

\(\displaystyle \frac {\int \frac {A b+(b B-a C) \sin \left (c+d x+\frac {\pi }{2}\right )}{a+b \sin \left (c+d x+\frac {\pi }{2}\right )}dx}{b}+\frac {C \sin (c+d x)}{b d}\)

\(\Big \downarrow \) 3214

\(\displaystyle \frac {\frac {\left (A b^2-a (b B-a C)\right ) \int \frac {1}{a+b \cos (c+d x)}dx}{b}+\frac {x (b B-a C)}{b}}{b}+\frac {C \sin (c+d x)}{b d}\)

\(\Big \downarrow \) 3042

\(\displaystyle \frac {\frac {\left (A b^2-a (b B-a C)\right ) \int \frac {1}{a+b \sin \left (c+d x+\frac {\pi }{2}\right )}dx}{b}+\frac {x (b B-a C)}{b}}{b}+\frac {C \sin (c+d x)}{b d}\)

\(\Big \downarrow \) 3138

\(\displaystyle \frac {\frac {2 \left (A b^2-a (b B-a C)\right ) \int \frac {1}{(a-b) \tan ^2\left (\frac {1}{2} (c+d x)\right )+a+b}d\tan \left (\frac {1}{2} (c+d x)\right )}{b d}+\frac {x (b B-a C)}{b}}{b}+\frac {C \sin (c+d x)}{b d}\)

\(\Big \downarrow \) 218

\(\displaystyle \frac {\frac {2 \left (A b^2-a (b B-a C)\right ) \arctan \left (\frac {\sqrt {a-b} \tan \left (\frac {1}{2} (c+d x)\right )}{\sqrt {a+b}}\right )}{b d \sqrt {a-b} \sqrt {a+b}}+\frac {x (b B-a C)}{b}}{b}+\frac {C \sin (c+d x)}{b d}\)

Input:

Int[(A + B*Cos[c + d*x] + C*Cos[c + d*x]^2)/(a + b*Cos[c + d*x]),x]
 

Output:

(((b*B - a*C)*x)/b + (2*(A*b^2 - a*(b*B - a*C))*ArcTan[(Sqrt[a - b]*Tan[(c 
 + d*x)/2])/Sqrt[a + b]])/(Sqrt[a - b]*b*Sqrt[a + b]*d))/b + (C*Sin[c + d* 
x])/(b*d)
 

Defintions of rubi rules used

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

rule 3042
Int[u_, x_Symbol] :> Int[DeactivateTrig[u, x], x] /; FunctionOfTrigOfLinear 
Q[u, x]
 

rule 3138
Int[((a_) + (b_.)*sin[Pi/2 + (c_.) + (d_.)*(x_)])^(-1), x_Symbol] :> With[{ 
e = FreeFactors[Tan[(c + d*x)/2], x]}, Simp[2*(e/d)   Subst[Int[1/(a + b + 
(a - b)*e^2*x^2), x], x, Tan[(c + d*x)/2]/e], x]] /; FreeQ[{a, b, c, d}, x] 
 && NeQ[a^2 - b^2, 0]
 

rule 3214
Int[((a_.) + (b_.)*sin[(e_.) + (f_.)*(x_)])/((c_.) + (d_.)*sin[(e_.) + (f_. 
)*(x_)]), x_Symbol] :> Simp[b*(x/d), x] - Simp[(b*c - a*d)/d   Int[1/(c + d 
*Sin[e + f*x]), x], x] /; FreeQ[{a, b, c, d, e, f}, x] && NeQ[b*c - a*d, 0]
 

rule 3502
Int[((a_.) + (b_.)*sin[(e_.) + (f_.)*(x_)])^(m_.)*((A_.) + (B_.)*sin[(e_.) 
+ (f_.)*(x_)] + (C_.)*sin[(e_.) + (f_.)*(x_)]^2), x_Symbol] :> Simp[(-C)*Co 
s[e + f*x]*((a + b*Sin[e + f*x])^(m + 1)/(b*f*(m + 2))), x] + Simp[1/(b*(m 
+ 2))   Int[(a + b*Sin[e + f*x])^m*Simp[A*b*(m + 2) + b*C*(m + 1) + (b*B*(m 
 + 2) - a*C)*Sin[e + f*x], x], x], x] /; FreeQ[{a, b, e, f, A, B, C, m}, x] 
 &&  !LtQ[m, -1]
 
Maple [A] (verified)

Time = 0.46 (sec) , antiderivative size = 117, normalized size of antiderivative = 1.21

method result size
derivativedivides \(\frac {\frac {2 \left (A \,b^{2}-B a b +a^{2} C \right ) \arctan \left (\frac {\left (a -b \right ) \tan \left (\frac {d x}{2}+\frac {c}{2}\right )}{\sqrt {\left (a -b \right ) \left (a +b \right )}}\right )}{b^{2} \sqrt {\left (a -b \right ) \left (a +b \right )}}+\frac {\frac {2 C b \tan \left (\frac {d x}{2}+\frac {c}{2}\right )}{1+\tan \left (\frac {d x}{2}+\frac {c}{2}\right )^{2}}+2 \left (B b -C a \right ) \arctan \left (\tan \left (\frac {d x}{2}+\frac {c}{2}\right )\right )}{b^{2}}}{d}\) \(117\)
default \(\frac {\frac {2 \left (A \,b^{2}-B a b +a^{2} C \right ) \arctan \left (\frac {\left (a -b \right ) \tan \left (\frac {d x}{2}+\frac {c}{2}\right )}{\sqrt {\left (a -b \right ) \left (a +b \right )}}\right )}{b^{2} \sqrt {\left (a -b \right ) \left (a +b \right )}}+\frac {\frac {2 C b \tan \left (\frac {d x}{2}+\frac {c}{2}\right )}{1+\tan \left (\frac {d x}{2}+\frac {c}{2}\right )^{2}}+2 \left (B b -C a \right ) \arctan \left (\tan \left (\frac {d x}{2}+\frac {c}{2}\right )\right )}{b^{2}}}{d}\) \(117\)
risch \(\frac {x B}{b}-\frac {a C x}{b^{2}}-\frac {i {\mathrm e}^{i \left (d x +c \right )} C}{2 b d}+\frac {i {\mathrm e}^{-i \left (d x +c \right )} C}{2 b d}-\frac {\ln \left ({\mathrm e}^{i \left (d x +c \right )}+\frac {i a^{2}-i b^{2}+\sqrt {-a^{2}+b^{2}}\, a}{b \sqrt {-a^{2}+b^{2}}}\right ) A}{\sqrt {-a^{2}+b^{2}}\, d}+\frac {\ln \left ({\mathrm e}^{i \left (d x +c \right )}+\frac {i a^{2}-i b^{2}+\sqrt {-a^{2}+b^{2}}\, a}{b \sqrt {-a^{2}+b^{2}}}\right ) B a}{\sqrt {-a^{2}+b^{2}}\, d b}-\frac {\ln \left ({\mathrm e}^{i \left (d x +c \right )}+\frac {i a^{2}-i b^{2}+\sqrt {-a^{2}+b^{2}}\, a}{b \sqrt {-a^{2}+b^{2}}}\right ) a^{2} C}{\sqrt {-a^{2}+b^{2}}\, d \,b^{2}}+\frac {\ln \left ({\mathrm e}^{i \left (d x +c \right )}-\frac {i a^{2}-i b^{2}-\sqrt {-a^{2}+b^{2}}\, a}{b \sqrt {-a^{2}+b^{2}}}\right ) A}{\sqrt {-a^{2}+b^{2}}\, d}-\frac {\ln \left ({\mathrm e}^{i \left (d x +c \right )}-\frac {i a^{2}-i b^{2}-\sqrt {-a^{2}+b^{2}}\, a}{b \sqrt {-a^{2}+b^{2}}}\right ) B a}{\sqrt {-a^{2}+b^{2}}\, d b}+\frac {\ln \left ({\mathrm e}^{i \left (d x +c \right )}-\frac {i a^{2}-i b^{2}-\sqrt {-a^{2}+b^{2}}\, a}{b \sqrt {-a^{2}+b^{2}}}\right ) a^{2} C}{\sqrt {-a^{2}+b^{2}}\, d \,b^{2}}\) \(491\)

Input:

int((A+B*cos(d*x+c)+C*cos(d*x+c)^2)/(a+b*cos(d*x+c)),x,method=_RETURNVERBO 
SE)
 

Output:

1/d*(2*(A*b^2-B*a*b+C*a^2)/b^2/((a-b)*(a+b))^(1/2)*arctan((a-b)*tan(1/2*d* 
x+1/2*c)/((a-b)*(a+b))^(1/2))+2/b^2*(C*b*tan(1/2*d*x+1/2*c)/(1+tan(1/2*d*x 
+1/2*c)^2)+(B*b-C*a)*arctan(tan(1/2*d*x+1/2*c))))
 

Fricas [A] (verification not implemented)

Time = 0.11 (sec) , antiderivative size = 331, normalized size of antiderivative = 3.41 \[ \int \frac {A+B \cos (c+d x)+C \cos ^2(c+d x)}{a+b \cos (c+d x)} \, dx=\left [-\frac {2 \, {\left (C a^{3} - B a^{2} b - C a b^{2} + B b^{3}\right )} d x + {\left (C a^{2} - B a b + A b^{2}\right )} \sqrt {-a^{2} + b^{2}} \log \left (\frac {2 \, a b \cos \left (d x + c\right ) + {\left (2 \, a^{2} - b^{2}\right )} \cos \left (d x + c\right )^{2} + 2 \, \sqrt {-a^{2} + b^{2}} {\left (a \cos \left (d x + c\right ) + b\right )} \sin \left (d x + c\right ) - a^{2} + 2 \, b^{2}}{b^{2} \cos \left (d x + c\right )^{2} + 2 \, a b \cos \left (d x + c\right ) + a^{2}}\right ) - 2 \, {\left (C a^{2} b - C b^{3}\right )} \sin \left (d x + c\right )}{2 \, {\left (a^{2} b^{2} - b^{4}\right )} d}, -\frac {{\left (C a^{3} - B a^{2} b - C a b^{2} + B b^{3}\right )} d x - {\left (C a^{2} - B a b + A b^{2}\right )} \sqrt {a^{2} - b^{2}} \arctan \left (-\frac {a \cos \left (d x + c\right ) + b}{\sqrt {a^{2} - b^{2}} \sin \left (d x + c\right )}\right ) - {\left (C a^{2} b - C b^{3}\right )} \sin \left (d x + c\right )}{{\left (a^{2} b^{2} - b^{4}\right )} d}\right ] \] Input:

integrate((A+B*cos(d*x+c)+C*cos(d*x+c)^2)/(a+b*cos(d*x+c)),x, algorithm="f 
ricas")
 

Output:

[-1/2*(2*(C*a^3 - B*a^2*b - C*a*b^2 + B*b^3)*d*x + (C*a^2 - B*a*b + A*b^2) 
*sqrt(-a^2 + b^2)*log((2*a*b*cos(d*x + c) + (2*a^2 - b^2)*cos(d*x + c)^2 + 
 2*sqrt(-a^2 + b^2)*(a*cos(d*x + c) + b)*sin(d*x + c) - a^2 + 2*b^2)/(b^2* 
cos(d*x + c)^2 + 2*a*b*cos(d*x + c) + a^2)) - 2*(C*a^2*b - C*b^3)*sin(d*x 
+ c))/((a^2*b^2 - b^4)*d), -((C*a^3 - B*a^2*b - C*a*b^2 + B*b^3)*d*x - (C* 
a^2 - B*a*b + A*b^2)*sqrt(a^2 - b^2)*arctan(-(a*cos(d*x + c) + b)/(sqrt(a^ 
2 - b^2)*sin(d*x + c))) - (C*a^2*b - C*b^3)*sin(d*x + c))/((a^2*b^2 - b^4) 
*d)]
                                                                                    
                                                                                    
 

Sympy [F(-1)]

Timed out. \[ \int \frac {A+B \cos (c+d x)+C \cos ^2(c+d x)}{a+b \cos (c+d x)} \, dx=\text {Timed out} \] Input:

integrate((A+B*cos(d*x+c)+C*cos(d*x+c)**2)/(a+b*cos(d*x+c)),x)
 

Output:

Timed out
 

Maxima [F(-2)]

Exception generated. \[ \int \frac {A+B \cos (c+d x)+C \cos ^2(c+d x)}{a+b \cos (c+d x)} \, dx=\text {Exception raised: ValueError} \] Input:

integrate((A+B*cos(d*x+c)+C*cos(d*x+c)^2)/(a+b*cos(d*x+c)),x, algorithm="m 
axima")
 

Output:

Exception raised: ValueError >> Computation failed since Maxima requested 
additional constraints; using the 'assume' command before evaluation *may* 
 help (example of legal syntax is 'assume(4*b^2-4*a^2>0)', see `assume?` f 
or more de
 

Giac [A] (verification not implemented)

Time = 0.13 (sec) , antiderivative size = 147, normalized size of antiderivative = 1.52 \[ \int \frac {A+B \cos (c+d x)+C \cos ^2(c+d x)}{a+b \cos (c+d x)} \, dx=-\frac {\frac {{\left (C a - B b\right )} {\left (d x + c\right )}}{b^{2}} - \frac {2 \, C \tan \left (\frac {1}{2} \, d x + \frac {1}{2} \, c\right )}{{\left (\tan \left (\frac {1}{2} \, d x + \frac {1}{2} \, c\right )^{2} + 1\right )} b} + \frac {2 \, {\left (C a^{2} - B a b + A b^{2}\right )} {\left (\pi \left \lfloor \frac {d x + c}{2 \, \pi } + \frac {1}{2} \right \rfloor \mathrm {sgn}\left (-2 \, a + 2 \, b\right ) + \arctan \left (-\frac {a \tan \left (\frac {1}{2} \, d x + \frac {1}{2} \, c\right ) - b \tan \left (\frac {1}{2} \, d x + \frac {1}{2} \, c\right )}{\sqrt {a^{2} - b^{2}}}\right )\right )}}{\sqrt {a^{2} - b^{2}} b^{2}}}{d} \] Input:

integrate((A+B*cos(d*x+c)+C*cos(d*x+c)^2)/(a+b*cos(d*x+c)),x, algorithm="g 
iac")
 

Output:

-((C*a - B*b)*(d*x + c)/b^2 - 2*C*tan(1/2*d*x + 1/2*c)/((tan(1/2*d*x + 1/2 
*c)^2 + 1)*b) + 2*(C*a^2 - B*a*b + A*b^2)*(pi*floor(1/2*(d*x + c)/pi + 1/2 
)*sgn(-2*a + 2*b) + arctan(-(a*tan(1/2*d*x + 1/2*c) - b*tan(1/2*d*x + 1/2* 
c))/sqrt(a^2 - b^2)))/(sqrt(a^2 - b^2)*b^2))/d
 

Mupad [B] (verification not implemented)

Time = 2.77 (sec) , antiderivative size = 4410, normalized size of antiderivative = 45.46 \[ \int \frac {A+B \cos (c+d x)+C \cos ^2(c+d x)}{a+b \cos (c+d x)} \, dx=\text {Too large to display} \] Input:

int((A + B*cos(c + d*x) + C*cos(c + d*x)^2)/(a + b*cos(c + d*x)),x)
 

Output:

(2*B*b^3*atan(sin(c/2 + (d*x)/2)/cos(c/2 + (d*x)/2)))/(d*(b^4 - a^2*b^2)) 
+ (2*C*a^3*atan(sin(c/2 + (d*x)/2)/cos(c/2 + (d*x)/2)))/(d*(b^4 - a^2*b^2) 
) + (C*b^3*sin(c + d*x))/(d*(b^4 - a^2*b^2)) - (C*a^2*b*sin(c + d*x))/(d*( 
b^4 - a^2*b^2)) + (A*b^2*atan((C^2*a^5*sin(c/2 + (d*x)/2)*(b^2 - a^2)^(3/2 
)*2i - B^2*b^7*sin(c/2 + (d*x)/2)*(b^2 - a^2)^(1/2)*1i - A^2*b^7*sin(c/2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*2i - A*B*a^3*b^4*...
 

Reduce [B] (verification not implemented)

Time = 0.18 (sec) , antiderivative size = 129, normalized size of antiderivative = 1.33 \[ \int \frac {A+B \cos (c+d x)+C \cos ^2(c+d x)}{a+b \cos (c+d x)} \, dx=\frac {2 \sqrt {a^{2}-b^{2}}\, \mathit {atan} \left (\frac {\tan \left (\frac {d x}{2}+\frac {c}{2}\right ) a -\tan \left (\frac {d x}{2}+\frac {c}{2}\right ) b}{\sqrt {a^{2}-b^{2}}}\right ) a^{2} c +\sin \left (d x +c \right ) a^{2} b c -\sin \left (d x +c \right ) b^{3} c -a^{3} c d x +a^{2} b^{2} d x +a \,b^{2} c d x -b^{4} d x}{b^{2} d \left (a^{2}-b^{2}\right )} \] Input:

int((A+B*cos(d*x+c)+C*cos(d*x+c)^2)/(a+b*cos(d*x+c)),x)
 

Output:

(2*sqrt(a**2 - b**2)*atan((tan((c + d*x)/2)*a - tan((c + d*x)/2)*b)/sqrt(a 
**2 - b**2))*a**2*c + sin(c + d*x)*a**2*b*c - sin(c + d*x)*b**3*c - a**3*c 
*d*x + a**2*b**2*d*x + a*b**2*c*d*x - b**4*d*x)/(b**2*d*(a**2 - b**2))