int_rules_4_1_8 = @theory begin

    #= ::Subsection::Closed:: =#
    #= 4.1.8*trig^m*(a+b*cos^p+c*sin^q)^n =#
    @apply_utils Antiderivative(sin(~(d') + ~(e') * ~x) ^ ~m * (~a + ~(b') * cos(~(d') + ~(e') * ~x) ^ ~p + ~(c') * sin(~(d') + ~(e') * ~x) ^ ~q) ^ ~n, ~x) => Module([f = FreeFactors(cot(~d + ~e * ~x), ~x)], (-f / ~e) * Subst(Antiderivative(ExpandToSum(~c + ~b * (1 + f ^ 2 * (~x) ^ 2) ^ (~q / 2 - ~p / 2) + ~a * (1 + f ^ 2 * (~x) ^ 2) ^ (~q / 2), ~x) ^ ~n / (1 + f ^ 2 * (~x) ^ 2) ^ (~m / 2 + (~n * ~q) / 2 + 1), ~x), ~x, cot(~d + ~e * ~x) / f)) <-- FreeQ([~a, ~b, ~c, ~d, ~e], ~x) && (IntegerQ(~m / 2) && (IntegerQ(~p / 2) && (IntegerQ(~q / 2) && (IntegerQ(~n) && (GtQ(~p, 0) && LeQ(~p, ~q))))))
    @apply_utils Antiderivative(cos(~(d') + ~(e') * ~x) ^ ~m * (~a + ~(b') * sin(~(d') + ~(e') * ~x) ^ ~p + ~(c') * cos(~(d') + ~(e') * ~x) ^ ~q) ^ ~n, ~x) => Module([f = FreeFactors(tan(~d + ~e * ~x), ~x)], (f / ~e) * Subst(Antiderivative(ExpandToSum(~c + ~b * (1 + f ^ 2 * (~x) ^ 2) ^ (~q / 2 - ~p / 2) + ~a * (1 + f ^ 2 * (~x) ^ 2) ^ (~q / 2), ~x) ^ ~n / (1 + f ^ 2 * (~x) ^ 2) ^ (~m / 2 + (~n * ~q) / 2 + 1), ~x), ~x, tan(~d + ~e * ~x) / f)) <-- FreeQ([~a, ~b, ~c, ~d, ~e], ~x) && (IntegerQ(~m / 2) && (IntegerQ(~p / 2) && (IntegerQ(~q / 2) && (IntegerQ(~n) && (GtQ(~p, 0) && LeQ(~p, ~q))))))
    @apply_utils Antiderivative(sin(~(d') + ~(e') * ~x) ^ ~m * (~a + ~(b') * cos(~(d') + ~(e') * ~x) ^ ~p + ~(c') * sin(~(d') + ~(e') * ~x) ^ ~q) ^ ~n, ~x) => Module([f = FreeFactors(cot(~d + ~e * ~x), ~x)], (-f / ~e) * Subst(Antiderivative(ExpandToSum(~a * (1 + f ^ 2 * (~x) ^ 2) ^ (~p / 2) + ~b * f ^ ~p * (~x) ^ ~p + ~c * (1 + f ^ 2 * (~x) ^ 2) ^ (~p / 2 - ~q / 2), ~x) ^ ~n / (1 + f ^ 2 * (~x) ^ 2) ^ (~m / 2 + (~n * ~p) / 2 + 1), ~x), ~x, cot(~d + ~e * ~x) / f)) <-- FreeQ([~a, ~b, ~c, ~d, ~e], ~x) && (IntegerQ(~m / 2) && (IntegerQ(~p / 2) && (IntegerQ(~q / 2) && (IntegerQ(~n) && LtQ(0, ~q, ~p)))))
    @apply_utils Antiderivative(cos(~(d') + ~(e') * ~x) ^ ~m * (~a + ~(b') * sin(~(d') + ~(e') * ~x) ^ ~p + ~(c') * cos(~(d') + ~(e') * ~x) ^ ~q) ^ ~n, ~x) => Module([f = FreeFactors(tan(~d + ~e * ~x), ~x)], (f / ~e) * Subst(Antiderivative(ExpandToSum(~a * (1 + f ^ 2 * (~x) ^ 2) ^ (~p / 2) + ~b * f ^ ~p * (~x) ^ ~p + ~c * (1 + f ^ 2 * (~x) ^ 2) ^ (~p / 2 - ~q / 2), ~x) ^ ~n / (1 + f ^ 2 * (~x) ^ 2) ^ (~m / 2 + (~n * ~p) / 2 + 1), ~x), ~x, tan(~d + ~e * ~x) / f)) <-- FreeQ([~a, ~b, ~c, ~d, ~e], ~x) && (IntegerQ(~m / 2) && (IntegerQ(~p / 2) && (IntegerQ(~q / 2) && (IntegerQ(~n) && LtQ(0, ~q, ~p)))))
    @apply_utils Antiderivative(sin(~(d') + ~(e') * ~x) ^ ~m * (~a + ~(b') * cos(~(d') + ~(e') * ~x) ^ ~p + ~(c') * sin(~(d') + ~(e') * ~x) ^ ~q) ^ ~n, ~x) => Module([f = FreeFactors(cot(~d + ~e * ~x), ~x)], (-f / ~e) * Subst(Antiderivative(ExpandToSum(~c + ~b * (1 + f ^ 2 * (~x) ^ 2) ^ (~q / 2 - ~p / 2) + ~a * (1 + f ^ 2 * (~x) ^ 2) ^ (~q / 2), ~x) ^ ~n / (1 + f ^ 2 * (~x) ^ 2) ^ (~m / 2 + (~n * ~q) / 2 + 1), ~x), ~x, cot(~d + ~e * ~x) / f)) <-- FreeQ([~a, ~b, ~c, ~d, ~e], ~x) && (IntegerQ(~m / 2) && (IntegerQ(~p / 2) && (IntegerQ(~q / 2) && (IntegerQ(~n) && (GtQ(~p, 0) && LeQ(~p, ~q))))))
    @apply_utils Antiderivative(cos(~(d') + ~(e') * ~x) ^ ~m * (~a + ~(b') * sin(~(d') + ~(e') * ~x) ^ ~p + ~(c') * cos(~(d') + ~(e') * ~x) ^ ~q) ^ ~n, ~x) => Module([f = FreeFactors(tan(~d + ~e * ~x), ~x)], (f / ~e) * Subst(Antiderivative(ExpandToSum(~c + ~b * (1 + f ^ 2 * (~x) ^ 2) ^ (~q / 2 - ~p / 2) + ~a * (1 + f ^ 2 * (~x) ^ 2) ^ (~q / 2), ~x) ^ ~n / (1 + f ^ 2 * (~x) ^ 2) ^ (~m / 2 + (~n * ~q) / 2 + 1), ~x), ~x, tan(~d + ~e * ~x) / f)) <-- FreeQ([~a, ~b, ~c, ~d, ~e], ~x) && (IntegerQ(~m / 2) && (IntegerQ(~p / 2) && (IntegerQ(~q / 2) && (IntegerQ(~n) && (GtQ(~p, 0) && LeQ(~p, ~q))))))
    @apply_utils Antiderivative(sin(~(d') + ~(e') * ~x) ^ ~m * (~a + ~(b') * cos(~(d') + ~(e') * ~x) ^ ~p + ~(c') * sin(~(d') + ~(e') * ~x) ^ ~q) ^ ~n, ~x) => Module([f = FreeFactors(cot(~d + ~e * ~x), ~x)], (-f / ~e) * Subst(Antiderivative(ExpandToSum(~a * (1 + f ^ 2 * (~x) ^ 2) ^ (~p / 2) + ~b * f ^ ~p * (~x) ^ ~p + ~c * (1 + f ^ 2 * (~x) ^ 2) ^ (~p / 2 - ~q / 2), ~x) ^ ~n / (1 + f ^ 2 * (~x) ^ 2) ^ (~m / 2 + (~n * ~p) / 2 + 1), ~x), ~x, cot(~d + ~e * ~x) / f)) <-- FreeQ([~a, ~b, ~c, ~d, ~e], ~x) && (IntegerQ(~m / 2) && (IntegerQ(~p / 2) && (IntegerQ(~q / 2) && (IntegerQ(~n) && LtQ(0, ~q, ~p)))))
    @apply_utils Antiderivative(cos(~(d') + ~(e') * ~x) ^ ~m * (~a + ~(b') * sin(~(d') + ~(e') * ~x) ^ ~p + ~(c') * cos(~(d') + ~(e') * ~x) ^ ~q) ^ ~n, ~x) => Module([f = FreeFactors(tan(~d + ~e * ~x), ~x)], (f / ~e) * Subst(Antiderivative(ExpandToSum(~a * (1 + f ^ 2 * (~x) ^ 2) ^ (~p / 2) + ~b * f ^ ~p * (~x) ^ ~p + ~c * (1 + f ^ 2 * (~x) ^ 2) ^ (~p / 2 - ~q / 2), ~x) ^ ~n / (1 + f ^ 2 * (~x) ^ 2) ^ (~m / 2 + (~n * ~p) / 2 + 1), ~x), ~x, tan(~d + ~e * ~x) / f)) <-- FreeQ([~a, ~b, ~c, ~d, ~e], ~x) && (IntegerQ(~m / 2) && (IntegerQ(~p / 2) && (IntegerQ(~q / 2) && (IntegerQ(~n) && LtQ(0, ~q, ~p)))))
end
