text:
int_rules_4_1_2_2 = @theory begin

    #= ::Subsection::Closed:: =#
    #= 4.1.2.2*(g*cos)^p*(a+b*sin)^m*(c+d*sin)^n =#
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~(n'), ~x) => (1 / (~b * ~f)) * Subst(Antiderivative((~a + ~x) ^ ~m * (~c + (~d / ~b) * ~x) ^ ~n, ~x), ~x, ~b * sin(~e + ~f * ~x)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~m, ~n], ~x)
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~(n') * (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => ~a * Antiderivative(cos(~e + ~f * ~x) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ ~n, ~x) + (~b / ~d) * Antiderivative(cos(~e + ~f * ~x) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ (~n + 1), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~n, ~p], ~x) && (IntegerQ((~p - 1) / 2) && (IntegerQ(~n) && (LtQ(~p, 0) && NeQ((~a) ^ 2 - (~b) ^ 2, 0) || (LtQ(0, ~n, ~p - 1) || LtQ(~p + 1, -(~n), 2 * ~p + 1)))))
    @apply_utils Antiderivative((cos(~(e') + ~(f') * ~x) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~(n')) / (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => (1 / ~a) * Antiderivative(cos(~e + ~f * ~x) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ ~n, ~x) - (1 / (~b * ~d)) * Antiderivative(cos(~e + ~f * ~x) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~n, ~p], ~x) && (IntegerQ((~p - 1) / 2) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegerQ(~n) && (LtQ(0, ~n, (~p + 1) / 2) || (LeQ(~p, -(~n)) && LtQ(-(~n), 2 * ~p - 3) || GtQ(~n, 0) && LeQ(~n, -(~p)))))))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~(n'), ~x) => (1 / ((~b) ^ ~p * ~f)) * Subst(Antiderivative((~a + ~x) ^ (~m + (~p - 1) / 2) * (~a - ~x) ^ ((~p - 1) / 2) * (~c + (~d / ~b) * ~x) ^ ~n, ~x), ~x, ~b * sin(~e + ~f * ~x)) <-- FreeQ([~a, ~b, ~e, ~f, ~c, ~d, ~m, ~n], ~x) && (IntegerQ((~p - 1) / 2) && EqQ((~a) ^ 2 - (~b) ^ 2, 0))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~(n'), ~x) => (1 / ((~b) ^ ~p * ~f)) * Subst(Antiderivative((~a + ~x) ^ ~m * (~c + (~d / ~b) * ~x) ^ ~n * ((~b) ^ 2 - (~x) ^ 2) ^ ((~p - 1) / 2), ~x), ~x, ~b * sin(~e + ~f * ~x)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~m, ~n], ~x) && (IntegerQ((~p - 1) / 2) && NeQ((~a) ^ 2 - (~b) ^ 2, 0))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~(n') * (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => ~a * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ ~n, ~x) + (~b / ~d) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ (~n + 1), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g, ~n, ~p], ~x)
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~(n')) / (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => ((~g) ^ 2 / ~a) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ ~n, ~x) - ((~g) ^ 2 / (~b * ~d)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g, ~n, ~p], ~x) && EqQ((~a) ^ 2 - (~b) ^ 2, 0)
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~(n'), ~x) => (((~a) ^ ~m * (~c) ^ ~m) / (~g) ^ (2 * ~m)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (2 * ~m + ~p) * (~c + ~d * sin(~e + ~f * ~x)) ^ (~n - ~m), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~n, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegerQ(~m) && Not(IntegerQ(~n) && LtQ((~n) ^ 2, (~m) ^ 2)))))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~(n'), ~x) => (1 / ((~a) ^ (~p / 2) * (~c) ^ (~p / 2))) * Antiderivative((~a + ~b * sin(~e + ~f * ~x)) ^ (~m + ~p / 2) * (~c + ~d * sin(~e + ~f * ~x)) ^ (~n + ~p / 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~n, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && IntegerQ(~p / 2)))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p / (sqrt(~a + ~(b') * sin(~(e') + ~(f') * ~x)) * sqrt(~c + ~(d') * sin(~(e') + ~(f') * ~x))), ~x) => ((~g * cos(~e + ~f * ~x)) / (sqrt(~a + ~b * sin(~e + ~f * ~x)) * sqrt(~c + ~d * sin(~e + ~f * ~x)))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p - 1), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && EqQ((~a) ^ 2 - (~b) ^ 2, 0))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (((~a) ^ IntPart(~m) * (~c) ^ IntPart(~m) * (~a + ~b * sin(~e + ~f * ~x)) ^ FracPart(~m) * (~c + ~d * sin(~e + ~f * ~x)) ^ FracPart(~m)) / ((~g) ^ (2 * IntPart(~m)) * (~g * cos(~e + ~f * ~x)) ^ (2 * FracPart(~m)))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (2 * ~m + ~p) / (~c + ~d * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~n, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (EqQ((2 * ~m + ~p) - 1, 0) && EqQ((~m - ~n) - 1, 0))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (~b * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1) * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n) / (~f * ~g * ((~m - ~n) - 1)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~n, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (EqQ((2 * ~m + ~p) - 1, 0) && NeQ((~m - ~n) - 1, 0))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (-2 * ~b * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1) * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n) / (~f * ~g * (2 * ~n + ~p + 1)) - ((~b * ((2 * ~m + ~p) - 1)) / (~d * (2 * ~n + ~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1) * (~c + ~d * sin(~e + ~f * ~x)) ^ (~n + 1), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IGtQ(Simplify((~m + ~p / 2) - 1 / 2), 0) && (LtQ(~n, -1) && (NeQ(2 * ~n + ~p + 1, 0) && Not(ILtQ(Simplify(~m + ~n + ~p), 0) && GtQ(Simplify(2 * ~m + ~n + (3 * ~p) / 2 + 1), 0)))))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (-(~b) * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1) * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n) / (~f * ~g * (~m + ~n + ~p)) + ((~a * ((2 * ~m + ~p) - 1)) / (~m + ~n + ~p)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1) * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~n, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IGtQ(Simplify((~m + ~p / 2) - 1 / 2), 0) && (Not(LtQ(~n, -1)) && (Not(IGtQ(Simplify((~n + ~p / 2) - 1 / 2), 0) && GtQ(~m - ~n, 0)) && Not(ILtQ(Simplify(~m + ~n + ~p), 0) && GtQ(Simplify(2 * ~m + ~n + (3 * ~p) / 2 + 1), 0)))))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (((~a) ^ IntPart(~m) * (~c) ^ IntPart(~m) * (~a + ~b * sin(~e + ~f * ~x)) ^ FracPart(~m) * (~c + ~d * sin(~e + ~f * ~x)) ^ FracPart(~m)) / ((~g) ^ (2 * IntPart(~m)) * (~g * cos(~e + ~f * ~x)) ^ (2 * FracPart(~m)))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (2 * ~m + ~p), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && EqQ(2 * ~m + ~p + 1, 0)))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (~b * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n) / (~a * ~f * ~g * (~m - ~n)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~n, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (EqQ(~m + ~n + ~p + 1, 0) && NeQ(~m, ~n))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (~b * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n) / (~a * ~f * ~g * (2 * ~m + ~p + 1)) + ((~m + ~n + ~p + 1) / (~a * (2 * ~m + ~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~n, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (ILtQ(Simplify(~m + ~n + ~p + 1), 0) && (NeQ(2 * ~m + ~p + 1, 0) && (SumSimplerQ(~m, 1) || Not(SumSimplerQ(~n, 1)))))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (-2 * ~b * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1) * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n) / (~f * ~g * (2 * ~n + ~p + 1)) - ((~b * ((2 * ~m + ~p) - 1)) / (~d * (2 * ~n + ~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1) * (~c + ~d * sin(~e + ~f * ~x)) ^ (~n + 1), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (GtQ(~m, 0) && (LtQ(~n, -1) && (NeQ(2 * ~n + ~p + 1, 0) && IntegersQ(2 * ~m, 2 * ~n, 2 * ~p))))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (-(~b) * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1) * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n) / (~f * ~g * (~m + ~n + ~p)) + ((~a * ((2 * ~m + ~p) - 1)) / (~m + ~n + ~p)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1) * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~n, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (GtQ(~m, 0) && (NeQ(~m + ~n + ~p, 0) && (Not(LtQ(0, ~n, ~m)) && IntegersQ(2 * ~m, 2 * ~n, 2 * ~p))))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (~b * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n) / (~a * ~f * ~g * (2 * ~m + ~p + 1)) + ((~m + ~n + ~p + 1) / (~a * (2 * ~m + ~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~n, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (LtQ(~m, -1) && (NeQ(2 * ~m + ~p + 1, 0) && (Not(LtQ(~m, ~n, -1)) && IntegersQ(2 * ~m, 2 * ~n, 2 * ~p))))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (((~a) ^ IntPart(~m) * (~c) ^ IntPart(~m) * (~a + ~b * sin(~e + ~f * ~x)) ^ FracPart(~m) * (~c + ~d * sin(~e + ~f * ~x)) ^ FracPart(~m)) / ((~g) ^ (2 * IntPart(~m)) * (~g * cos(~e + ~f * ~x)) ^ (2 * FracPart(~m)))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (2 * ~m + ~p) * (~c + ~d * sin(~e + ~f * ~x)) ^ (~n - ~m), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~n, ~p], ~x) && (EqQ(~b * ~c + ~a * ~d, 0) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (FractionQ(~m) || Not(FractionQ(~n)))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (-(~d) * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m) / (~f * ~g * (~m + ~p + 1)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && EqQ(~a * ~d * ~m + ~b * ~c * (~m + ~p + 1), 0))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (-((~b * ~c + ~a * ~d)) * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m) / (~a * ~f * ~g * (~p + 1)) + ((~b * (~a * ~d * ~m + ~b * ~c * (~m + ~p + 1))) / (~a * (~g) ^ 2 * (~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p + 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (GtQ(~m, -1) && LtQ(~p, -1)))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (-(~d) * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m) / (~f * ~g * (~m + ~p + 1)) + ((~a * ~d * ~m + ~b * ~c * (~m + ~p + 1)) / (~b * (~m + ~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IGtQ(Simplify((2 * ~m + ~p + 1) / 2), 0) && NeQ(~m + ~p + 1, 0)))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 2 * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (2 * (~b * ~c - ~a * ~d) * cos(~e + ~f * ~x) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / ((~b) ^ 2 * ~f * (2 * ~m + 3)) + (1 / ((~b) ^ 3 * (2 * ~m + 3))) * Antiderivative((~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 2) * ((~b * ~c + 2 * ~a * ~d * (~m + 1)) - ~b * ~d * (2 * ~m + 3) * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && LtQ(~m, -3 / 2))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 2 * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (~d * cos(~e + ~f * ~x) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 2)) / ((~b) ^ 2 * ~f * (~m + 3)) - (1 / ((~b) ^ 2 * (~m + 3))) * Antiderivative((~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * ((~b * ~d * (~m + 2) - ~a * ~c * (~m + 3)) + (~b * ~c * (~m + 3) - ~a * ~d * (~m + 4)) * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (GeQ(~m, -3 / 2) && LtQ(~m, 0)))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => ((~b * ~c - ~a * ~d) * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m) / (~a * ~f * ~g * (2 * ~m + ~p + 1)) + ((~a * ~d * ~m + ~b * ~c * (~m + ~p + 1)) / (~a * ~b * (2 * ~m + ~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && ((LtQ(~m, -1) || ILtQ(Simplify(~m + ~p), 0)) && NeQ(2 * ~m + ~p + 1, 0)))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (-(~d) * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m) / (~f * ~g * (~m + ~p + 1)) + ((~a * ~d * ~m + ~b * ~c * (~m + ~p + 1)) / (~b * (~m + ~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && NeQ(~m + ~p + 1, 0))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (-((~g * cos(~e + ~f * ~x)) ^ (~p + 1)) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~d + ~c * sin(~e + ~f * ~x))) / (~f * ~g * (~p + 1)) + (1 / ((~g) ^ 2 * (~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p + 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1) * Simp(~a * ~c * (~p + 2) + ~b * ~d * ~m + ~b * ~c * (~m + ~p + 2) * sin(~e + ~f * ~x), ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (GtQ(~m, 0) && (LtQ(~p, -1) && (IntegerQ(2 * ~m) && Not(EqQ(~m, 1) && (NeQ((~c) ^ 2 - (~d) ^ 2, 0) && SimplerQ(~c + ~d * ~x, ~a + ~b * ~x)))))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (-(~d) * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m) / (~f * ~g * (~m + ~p + 1)) + (1 / (~m + ~p + 1)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1) * Simp(~a * ~c * (~m + ~p + 1) + ~b * ~d * ~m + (~a * ~d * ~m + ~b * ~c * (~m + ~p + 1)) * sin(~e + ~f * ~x), ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (GtQ(~m, 0) && (Not(LtQ(~p, -1)) && (IntegerQ(2 * ~m) && Not(EqQ(~m, 1) && (NeQ((~c) ^ 2 - (~d) ^ 2, 0) && SimplerQ(~c + ~d * ~x, ~a + ~b * ~x)))))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (~g * (~g * cos(~e + ~f * ~x)) ^ (~p - 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * ((~b * ~c * (~m + ~p + 1) - ~a * ~d * ~p) + ~b * ~d * (~m + 1) * sin(~e + ~f * ~x))) / ((~b) ^ 2 * ~f * (~m + 1) * (~m + ~p + 1)) + (((~g) ^ 2 * (~p - 1)) / ((~b) ^ 2 * (~m + 1) * (~m + ~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * Simp(~b * ~d * (~m + 1) + (~b * ~c * (~m + ~p + 1) - ~a * ~d * ~p) * sin(~e + ~f * ~x), ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (LtQ(~m, -1) && (GtQ(~p, 1) && (NeQ(~m + ~p + 1, 0) && IntegerQ(2 * ~m)))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (-((~b * ~c - ~a * ~d)) * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / (~f * ~g * ((~a) ^ 2 - (~b) ^ 2) * (~m + 1)) + (1 / (((~a) ^ 2 - (~b) ^ 2) * (~m + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * Simp((~a * ~c - ~b * ~d) * (~m + 1) - (~b * ~c - ~a * ~d) * (~m + ~p + 2) * sin(~e + ~f * ~x), ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (LtQ(~m, -1) && IntegerQ(2 * ~m)))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (~g * (~g * cos(~e + ~f * ~x)) ^ (~p - 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * ((~b * ~c * (~m + ~p + 1) - ~a * ~d * ~p) + ~b * ~d * (~m + ~p) * sin(~e + ~f * ~x))) / ((~b) ^ 2 * ~f * (~m + ~p) * (~m + ~p + 1)) + (((~g) ^ 2 * (~p - 1)) / ((~b) ^ 2 * (~m + ~p) * (~m + ~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * Simp(~b * (~a * ~d * ~m + ~b * ~c * (~m + ~p + 1)) + (~a * ~b * ~c * (~m + ~p + 1) - ~d * ((~a) ^ 2 * ~p - (~b) ^ 2 * (~m + ~p))) * sin(~e + ~f * ~x), ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (GtQ(~p, 1) && (NeQ(~m + ~p, 0) && (NeQ(~m + ~p + 1, 0) && IntegerQ(2 * ~m)))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => ((~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * ((~b * ~c - ~a * ~d) - (~a * ~c - ~b * ~d) * sin(~e + ~f * ~x))) / (~f * ~g * ((~a) ^ 2 - (~b) ^ 2) * (~p + 1)) + (1 / ((~g) ^ 2 * ((~a) ^ 2 - (~b) ^ 2) * (~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p + 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * Simp(~c * ((~a) ^ 2 * (~p + 2) - (~b) ^ 2 * (~m + ~p + 2)) + ~a * ~b * ~d * ~m + ~b * (~a * ~c - ~b * ~d) * (~m + ~p + 3) * sin(~e + ~f * ~x), ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (LtQ(~p, -1) && IntegerQ(2 * ~m)))
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x))) / (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => (~d / ~b) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p, ~x) + ((~b * ~c - ~a * ~d) / ~b) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p / (~a + ~b * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && NeQ((~a) ^ 2 - (~b) ^ 2, 0)
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)), ~x) => ((~c * ~g * (~g * cos(~e + ~f * ~x)) ^ (~p - 1)) / (~f * (1 + sin(~e + ~f * ~x)) ^ ((~p - 1) / 2) * (1 - sin(~e + ~f * ~x)) ^ ((~p - 1) / 2))) * Subst(Antiderivative((1 + (~d / ~c) * ~x) ^ ((~p + 1) / 2) * (1 - (~d / ~c) * ~x) ^ ((~p - 1) / 2) * (~a + ~b * ~x) ^ ~m, ~x), ~x, sin(~e + ~f * ~x)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~m, ~p], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && EqQ((~c) ^ 2 - (~d) ^ 2, 0))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (~a) ^ (2 * ~m) * Antiderivative((~d * sin(~e + ~f * ~x)) ^ ~n / (~a - ~b * sin(~e + ~f * ~x)) ^ ~m, ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(~m, ~p) && EqQ(2 * ~m + ~p, 0)))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * sin(~(e') + ~(f') * ~x) ^ 2 * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (-((~g * cos(~e + ~f * ~x)) ^ (~p + 1)) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / (2 * ~b * ~f * ~g * (~m + 1)) + (~a / (2 * (~g) ^ 2)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p + 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1), ~x) <-- FreeQ([~a, ~b, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && EqQ(~m - ~p, 0))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * sin(~(e') + ~(f') * ~x) ^ 2 * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (~b * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m) / (~a * ~f * ~g * ~m) - (1 / (~g) ^ 2) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p + 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m, ~x) <-- FreeQ([~a, ~b, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && EqQ(~m + ~p + 1, 0))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (1 / (~a) ^ ~p) * Antiderivative(ExpandTrig((~d * sin(~e + ~f * ~x)) ^ ~n * (~a - ~b * sin(~e + ~f * ~x)) ^ (~p / 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + ~p / 2), ~x), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(~m, ~n, ~p / 2) && (GtQ(~m, 0) && (GtQ(~p, 0) && LtQ(-(~m) - ~p, ~n, -1)) || GtQ(~m, 2) && (LtQ(~p, 0) && GtQ(~m + ~p / 2, 0)))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => Antiderivative(ExpandTrig((~g * cos(~e + ~f * ~x)) ^ ~p, (~d * sin(~e + ~f * ~x)) ^ ~n * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m, ~x), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g, ~n, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && IGtQ(~m, 0))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 2 * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (1 / (~b) ^ 2) * Antiderivative((~d * sin(~e + ~f * ~x)) ^ ~n * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~a - ~b * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~m, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (ILtQ(~m, 0) || Not(IGtQ(~n, 0))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (~a / ~g) ^ (2 * ~m) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ (2 * ~m + ~p) * (~d * sin(~e + ~f * ~x)) ^ ~n) / (~a - ~b * sin(~e + ~f * ~x)) ^ ~m, ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g, ~n, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && ILtQ(~m, 0))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (~a / ~g) ^ (2 * ~m) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ (2 * ~m + ~p) * (~d * sin(~e + ~f * ~x)) ^ ~n) / (~a - ~b * sin(~e + ~f * ~x)) ^ ~m, ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegerQ(~m) && (RationalQ(~p) && (EqQ(2 * ~m + ~p, 0) || GtQ(2 * ~m + ~p, 0) && LtQ(~p, -1)))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * sin(~(e') + ~(f') * ~x) ^ 2 * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (~b * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m) / (~a * ~f * ~g * (2 * ~m + ~p + 1)) - (1 / ((~a) ^ 2 * (2 * ~m + ~p + 1))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~a * ~m - ~b * (2 * ~m + ~p + 1) * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~e, ~f, ~g, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (LeQ(~m, -1 / 2) && NeQ(2 * ~m + ~p + 1, 0)))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * sin(~(e') + ~(f') * ~x) ^ 2 * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (-((~g * cos(~e + ~f * ~x)) ^ (~p + 1)) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / (~b * ~f * ~g * (~m + ~p + 2)) + (1 / (~b * (~m + ~p + 2))) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~b * (~m + 1) - ~a * (~p + 1) * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && NeQ(~m + ~p + 2, 0))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 2 * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (1 / (~b) ^ 2) * Antiderivative((~d * sin(~e + ~f * ~x)) ^ ~n * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~a - ~b * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~m, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && IntegersQ(2 * ~m, 2 * ~n))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 4 * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (-2 / (~a * ~b * ~d)) * Antiderivative((~d * sin(~e + ~f * ~x)) ^ (~n + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 2), ~x) + (1 / (~a) ^ 2) * Antiderivative((~d * sin(~e + ~f * ~x)) ^ ~n * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 2) * (1 + sin(~e + ~f * ~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && LtQ(~m, -1))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 4 * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (1 / (~d) ^ 4) * Antiderivative((~d * sin(~e + ~f * ~x)) ^ (~n + 4) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m, ~x) + Antiderivative((~d * sin(~e + ~f * ~x)) ^ ~n * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (1 - 2 * sin(~e + ~f * ~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~m, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && Not(IGtQ(~m, 0)))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (((~a) ^ ~m * cos(~e + ~f * ~x)) / (~f * sqrt(1 + sin(~e + ~f * ~x)) * sqrt(1 - sin(~e + ~f * ~x)))) * Subst(Antiderivative((~d * ~x) ^ ~n * (1 + (~b / ~a) * ~x) ^ (~m + (~p - 1) / 2) * (1 - (~b / ~a) * ~x) ^ ((~p - 1) / 2), ~x), ~x, sin(~e + ~f * ~x)) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegerQ(~p / 2) && IntegerQ(~m)))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (cos(~e + ~f * ~x) / ((~a) ^ (~p - 2) * ~f * sqrt(~a + ~b * sin(~e + ~f * ~x)) * sqrt(~a - ~b * sin(~e + ~f * ~x)))) * Subst(Antiderivative((~d * ~x) ^ ~n * (~a + ~b * ~x) ^ ((~m + ~p / 2) - 1 / 2) * (~a - ~b * ~x) ^ (~p / 2 - 1 / 2), ~x), ~x, sin(~e + ~f * ~x)) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~m, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegerQ(~p / 2) && Not(IntegerQ(~m))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => Antiderivative(ExpandTrig((~g * cos(~e + ~f * ~x)) ^ ~p, (~d * sin(~e + ~f * ~x)) ^ ~n * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m, ~x), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g, ~n, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IGtQ(~m, 0) && (IntegerQ(~p) || IGtQ(~n, 0))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (((~a) ^ ~m * ~g * (~g * cos(~e + ~f * ~x)) ^ (~p - 1)) / (~f * (1 + sin(~e + ~f * ~x)) ^ ((~p - 1) / 2) * (1 - sin(~e + ~f * ~x)) ^ ((~p - 1) / 2))) * Subst(Antiderivative((~d * ~x) ^ ~n * (1 + (~b / ~a) * ~x) ^ (~m + (~p - 1) / 2) * (1 - (~b / ~a) * ~x) ^ ((~p - 1) / 2), ~x), ~x, sin(~e + ~f * ~x)) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~n, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && IntegerQ(~m))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => ((~g * (~g * cos(~e + ~f * ~x)) ^ (~p - 1)) / (~f * (~a + ~b * sin(~e + ~f * ~x)) ^ ((~p - 1) / 2) * (~a - ~b * sin(~e + ~f * ~x)) ^ ((~p - 1) / 2))) * Subst(Antiderivative((~d * ~x) ^ ~n * (~a + ~b * ~x) ^ (~m + (~p - 1) / 2) * (~a - ~b * ~x) ^ ((~p - 1) / 2), ~x), ~x, sin(~e + ~f * ~x)) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~m, ~n, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && Not(IntegerQ(~m)))
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m) / sqrt(~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (-(~g) * (~g * cos(~e + ~f * ~x)) ^ (~p - 1) * sqrt(~d * sin(~e + ~f * ~x)) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / (~a * ~d * ~f * (~m + 1)) + (((~g) ^ 2 * (2 * ~m + 3)) / (2 * ~a * (~m + 1))) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / sqrt(~d * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (LtQ(~m, -1) && EqQ(~m + ~p + 1 / 2, 0)))
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m) / sqrt(~(d') * sin(~(e') + ~(f') * ~x)), ~x) => (2 * (~g * cos(~e + ~f * ~x)) ^ (~p + 1) * sqrt(~d * sin(~e + ~f * ~x)) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m) / (~d * ~f * ~g * (2 * ~m + 1)) + ((2 * ~a * ~m) / ((~g) ^ 2 * (2 * ~m + 1))) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ (~p + 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m - 1)) / sqrt(~d * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (GtQ(~m, 0) && EqQ(~m + ~p + 3 / 2, 0)))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 2 * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => Antiderivative((~d * sin(~e + ~f * ~x)) ^ ~n * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (1 - sin(~e + ~f * ~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~m, ~n], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IGtQ(~m, 0) || IntegersQ(2 * ~m, 2 * ~n)))
    #= Antiderivative(cos((~e')+(~f')*(~x))^4*sin((~e')+(~f')*(~x))^(~n)*((~a)+(~b')*sin((~e')+(~f')*(~x)))^ (~m),~x) :=  (a^2-b^2)*cos(e+f*x)*sin(e+f*x)^(n+1)*(a+b*sin(e+f*x))^(m+1)/(a*b^2*d* (m+1)) - (a^2*(n+1)-b^2*(m+n+2))*cos(e+f*x)*sin(e+f*x)^(n+1)*(a+b*sin(e+f*x)) ^(m+2)/(a^2*b^2*d*(n+1)*(m+1)) + 1/(a^2*b*(n+1)*(m+1))*Antiderivative(sin(e+f*x)^(n+1)*(a+b*sin(e+f*x))^(m+1)* Simp(a^2*(n+1)*(n+2)-b^2*(m+n+2)*(m+n+3)+a*b*(m+1)*sin(e+f*x)-(a^ 2*(n+1)*(n+3)-b^2*(m+n+2)*(m+n+4))*sin(e+f*x)^2,x),x) <--  FreeQ([a,b,d,e,f],x) && NeQ(a^2-b^2,0) && IntegersQ(2*m,2*n) &&  LtQ(m,-1) && LtQ(n,-1) =#
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 4 * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => ((cos(~e + ~f * ~x) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / (~a * ~d * ~f * (~n + 1)) - (((~a) ^ 2 * (~n + 1) - (~b) ^ 2 * (~m + ~n + 2)) * cos(~e + ~f * ~x) * (~d * sin(~e + ~f * ~x)) ^ (~n + 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / ((~a) ^ 2 * ~b * (~d) ^ 2 * ~f * (~n + 1) * (~m + 1))) + (1 / ((~a) ^ 2 * ~b * ~d * (~n + 1) * (~m + 1))) * Antiderivative((~d * sin(~e + ~f * ~x)) ^ (~n + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * Simp((((~a) ^ 2 * (~n + 1) * (~n + 2) - (~b) ^ 2 * (~m + ~n + 2) * (~m + ~n + 3)) + ~a * ~b * (~m + 1) * sin(~e + ~f * ~x)) - ((~a) ^ 2 * (~n + 1) * (~n + 3) - (~b) ^ 2 * (~m + ~n + 2) * (~m + ~n + 4)) * sin(~e + ~f * ~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(2 * ~m, 2 * ~n) && (LtQ(~m, -1) && LtQ(~n, -1))))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 4 * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => ((((~a) ^ 2 - (~b) ^ 2) * cos(~e + ~f * ~x) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1)) / (~a * (~b) ^ 2 * ~d * ~f * (~m + 1)) + (((~a) ^ 2 * ((~n - ~m) + 1) - (~b) ^ 2 * (~m + ~n + 2)) * cos(~e + ~f * ~x) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 2) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1)) / ((~a) ^ 2 * (~b) ^ 2 * ~d * ~f * (~m + 1) * (~m + 2))) - (1 / ((~a) ^ 2 * (~b) ^ 2 * (~m + 1) * (~m + 2))) * Antiderivative((~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 2) * (~d * sin(~e + ~f * ~x)) ^ ~n * Simp((((~a) ^ 2 * (~n + 1) * (~n + 3) - (~b) ^ 2 * (~m + ~n + 2) * (~m + ~n + 3)) + ~a * ~b * (~m + 2) * sin(~e + ~f * ~x)) - ((~a) ^ 2 * (~n + 2) * (~n + 3) - (~b) ^ 2 * (~m + ~n + 2) * (~m + ~n + 4)) * sin(~e + ~f * ~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~n], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(2 * ~m, 2 * ~n) && (LtQ(~m, -1) && (Not(LtQ(~n, -1)) && (LtQ(~m, -2) || EqQ(~m + ~n + 4, 0))))))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 4 * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => ((((~a) ^ 2 - (~b) ^ 2) * cos(~e + ~f * ~x) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1)) / (~a * (~b) ^ 2 * ~d * ~f * (~m + 1)) - (cos(~e + ~f * ~x) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 2) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1)) / ((~b) ^ 2 * ~d * ~f * (~m + ~n + 4))) - (1 / (~a * (~b) ^ 2 * (~m + 1) * (~m + ~n + 4))) * Antiderivative((~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~d * sin(~e + ~f * ~x)) ^ ~n * Simp((((~a) ^ 2 * (~n + 1) * (~n + 3) - (~b) ^ 2 * (~m + ~n + 2) * (~m + ~n + 4)) + ~a * ~b * (~m + 1) * sin(~e + ~f * ~x)) - ((~a) ^ 2 * (~n + 2) * (~n + 3) - (~b) ^ 2 * (~m + ~n + 3) * (~m + ~n + 4)) * sin(~e + ~f * ~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~n], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(2 * ~m, 2 * ~n) && (LtQ(~m, -1) && (Not(LtQ(~n, -1)) && NeQ(~m + ~n + 4, 0)))))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 4 * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => ((cos(~e + ~f * ~x) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1)) / (~a * ~d * ~f * (~n + 1)) - (~b * (~m + ~n + 2) * cos(~e + ~f * ~x) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~d * sin(~e + ~f * ~x)) ^ (~n + 2)) / ((~a) ^ 2 * (~d) ^ 2 * ~f * (~n + 1) * (~n + 2))) - (1 / ((~a) ^ 2 * (~d) ^ 2 * (~n + 1) * (~n + 2))) * Antiderivative((~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~d * sin(~e + ~f * ~x)) ^ (~n + 2) * Simp((((~a) ^ 2 * ~n * (~n + 2) - (~b) ^ 2 * (~m + ~n + 2) * (~m + ~n + 3)) + ~a * ~b * ~m * sin(~e + ~f * ~x)) - ((~a) ^ 2 * (~n + 1) * (~n + 2) - (~b) ^ 2 * (~m + ~n + 2) * (~m + ~n + 4)) * sin(~e + ~f * ~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~m], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && ((IGtQ(~m, 0) || IntegersQ(2 * ~m, 2 * ~n)) && (Not(~m < -1) && (LtQ(~n, -1) && (LtQ(~n, -2) || EqQ(~m + ~n + 4, 0))))))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 4 * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => ((cos(~e + ~f * ~x) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1)) / (~a * ~d * ~f * (~n + 1)) - (cos(~e + ~f * ~x) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~d * sin(~e + ~f * ~x)) ^ (~n + 2)) / (~b * (~d) ^ 2 * ~f * (~m + ~n + 4))) + (1 / (~a * ~b * ~d * (~n + 1) * (~m + ~n + 4))) * Antiderivative((~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~d * sin(~e + ~f * ~x)) ^ (~n + 1) * Simp((((~a) ^ 2 * (~n + 1) * (~n + 2) - (~b) ^ 2 * (~m + ~n + 2) * (~m + ~n + 4)) + ~a * ~b * (~m + 3) * sin(~e + ~f * ~x)) - ((~a) ^ 2 * (~n + 1) * (~n + 3) - (~b) ^ 2 * (~m + ~n + 3) * (~m + ~n + 4)) * sin(~e + ~f * ~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~m], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && ((IGtQ(~m, 0) || IntegersQ(2 * ~m, 2 * ~n)) && (Not(~m < -1) && (LtQ(~n, -1) && NeQ(~m + ~n + 4, 0)))))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 4 * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => ((~a * (~n + 3) * cos(~e + ~f * ~x) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / ((~b) ^ 2 * ~d * ~f * (~m + ~n + 3) * (~m + ~n + 4)) - (cos(~e + ~f * ~x) * (~d * sin(~e + ~f * ~x)) ^ (~n + 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / (~b * (~d) ^ 2 * ~f * (~m + ~n + 4))) - (1 / ((~b) ^ 2 * (~m + ~n + 3) * (~m + ~n + 4))) * Antiderivative((~d * sin(~e + ~f * ~x)) ^ ~n * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * Simp((((~a) ^ 2 * (~n + 1) * (~n + 3) - (~b) ^ 2 * (~m + ~n + 3) * (~m + ~n + 4)) + ~a * ~b * ~m * sin(~e + ~f * ~x)) - ((~a) ^ 2 * (~n + 2) * (~n + 3) - (~b) ^ 2 * (~m + ~n + 3) * (~m + ~n + 5)) * sin(~e + ~f * ~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~m, ~n], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && ((IGtQ(~m, 0) || IntegersQ(2 * ~m, 2 * ~n)) && (Not(~m < -1) && (Not(LtQ(~n, -1)) && (NeQ(~m + ~n + 3, 0) && NeQ(~m + ~n + 4, 0))))))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 6 * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (((cos(~e + ~f * ~x) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / (~a * ~d * ~f * (~n + 1)) - (~b * (~m + ~n + 2) * cos(~e + ~f * ~x) * (~d * sin(~e + ~f * ~x)) ^ (~n + 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / ((~a) ^ 2 * (~d) ^ 2 * ~f * (~n + 1) * (~n + 2))) - (~a * (~n + 5) * cos(~e + ~f * ~x) * (~d * sin(~e + ~f * ~x)) ^ (~n + 3) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / ((~b) ^ 2 * (~d) ^ 3 * ~f * (~m + ~n + 5) * (~m + ~n + 6))) + (cos(~e + ~f * ~x) * (~d * sin(~e + ~f * ~x)) ^ (~n + 4) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1)) / (~b * (~d) ^ 4 * ~f * (~m + ~n + 6)) + (1 / ((~a) ^ 2 * (~b) ^ 2 * (~d) ^ 2 * (~n + 1) * (~n + 2) * (~m + ~n + 5) * (~m + ~n + 6))) * Antiderivative((~d * sin(~e + ~f * ~x)) ^ (~n + 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * Simp((((~a) ^ 4 * (~n + 1) * (~n + 2) * (~n + 3) * (~n + 5) - (~a) ^ 2 * (~b) ^ 2 * (~n + 2) * (2 * ~n + 1) * (~m + ~n + 5) * (~m + ~n + 6)) + (~b) ^ 4 * (~m + ~n + 2) * (~m + ~n + 3) * (~m + ~n + 5) * (~m + ~n + 6) + ~a * ~b * ~m * ((~a) ^ 2 * (~n + 1) * (~n + 2) - (~b) ^ 2 * (~m + ~n + 5) * (~m + ~n + 6)) * sin(~e + ~f * ~x)) - (((~a) ^ 4 * (~n + 1) * (~n + 2) * (4 + ~n) * (~n + 5) + (~b) ^ 4 * (~m + ~n + 2) * (~m + ~n + 4) * (~m + ~n + 5) * (~m + ~n + 6)) - (~a) ^ 2 * (~b) ^ 2 * (~n + 1) * (~n + 2) * (~m + ~n + 5) * (2 * ~n + 2 * ~m + 13)) * sin(~e + ~f * ~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~m, ~n], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(2 * ~m, 2 * ~n) && (NeQ(~n, -1) && (NeQ(~n, -2) && (NeQ(~m + ~n + 5, 0) && (NeQ(~m + ~n + 6, 0) && Not(IGtQ(~m, 0))))))))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => Antiderivative(ExpandTrig((~d * sin(~e + ~f * ~x)) ^ ~n * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (1 - sin(~e + ~f * ~x) ^ 2) ^ (~p / 2), ~x), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(~m, 2 * ~n, ~p / 2) && (LtQ(~m, -1) || EqQ(~m, -1) && GtQ(~p, 0))))
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * sin(~(e') + ~(f') * ~x) ^ ~n) / (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => Antiderivative(ExpandTrig((~g * cos(~e + ~f * ~x)) ^ ~p, sin(~e + ~f * ~x) ^ ~n / (~a + ~b * sin(~e + ~f * ~x)), ~x), ~x) <-- FreeQ([~a, ~b, ~e, ~f, ~g, ~p], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegerQ(~n) && (LtQ(~n, 0) || IGtQ(~p + 1 / 2, 0))))
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n) / (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => (((~g) ^ 2 / ~a) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ ~n, ~x) - ((~b * (~g) ^ 2) / ((~a) ^ 2 * ~d)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1), ~x)) - (((~g) ^ 2 * ((~a) ^ 2 - (~b) ^ 2)) / ((~a) ^ 2 * (~d) ^ 2)) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ (~n + 2)) / (~a + ~b * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(2 * ~n, 2 * ~p) && (GtQ(~p, 1) && (LeQ(~n, -2) || EqQ(~n, -3 / 2) && EqQ(~p, 3 / 2)))))
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n) / (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => ((~g) ^ 2 / (~a * ~b)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ ~n * (~b - ~a * sin(~e + ~f * ~x)), ~x) + (((~g) ^ 2 * ((~a) ^ 2 - (~b) ^ 2)) / (~a * ~b * ~d)) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1)) / (~a + ~b * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(2 * ~n, 2 * ~p) && (GtQ(~p, 1) && (LtQ(~n, -1) || EqQ(~p, 3 / 2) && EqQ(~n, -1 / 2)))))
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n) / (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => ((~g) ^ 2 / (~b) ^ 2) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ ~n * (~a - ~b * sin(~e + ~f * ~x)), ~x) - (((~g) ^ 2 * ((~a) ^ 2 - (~b) ^ 2)) / (~b) ^ 2) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ ~n) / (~a + ~b * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(2 * ~n, 2 * ~p) && GtQ(~p, 1)))
    #= Antiderivative(((~g')*cos((~e')+(~f')*(~x)))^(~p)*((~d')*sin((~e')+(~f')*(~x)))^(~n)/((~a)+(~b')*sin( (~e')+(~f')*(~x))),~x) :=  g^2*Antiderivative((g*cos(e+f*x))^(p-2)*(d*sin(e+f*x))^n/(a+b*sin(e+f*x)),x) - g^2/d^2*Antiderivative((g*cos(e+f*x))^(p-2)*(d*sin(e+f*x))^(n+2)/(a+b*sin(e+f* x)),x) <-- FreeQ([a,b,d,e,f,g],x) && NeQ(a^2-b^2,0) &&  IntegersQ(2*n,2*p) && GtQ(p,1) =#
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n) / (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => (((~a * (~d) ^ 2) / ((~a) ^ 2 - (~b) ^ 2)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ (~n - 2), ~x) - ((~b * ~d) / ((~a) ^ 2 - (~b) ^ 2)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ (~n - 1), ~x)) - (((~a) ^ 2 * (~d) ^ 2) / ((~g) ^ 2 * ((~a) ^ 2 - (~b) ^ 2))) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ (~p + 2) * (~d * sin(~e + ~f * ~x)) ^ (~n - 2)) / (~a + ~b * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(2 * ~n, 2 * ~p) && (LtQ(~p, -1) && GtQ(~n, 1))))
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n) / (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => (-(~d) / ((~a) ^ 2 - (~b) ^ 2)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ (~n - 1) * (~b - ~a * sin(~e + ~f * ~x)), ~x) + ((~a * ~b * ~d) / ((~g) ^ 2 * ((~a) ^ 2 - (~b) ^ 2))) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ (~p + 2) * (~d * sin(~e + ~f * ~x)) ^ (~n - 1)) / (~a + ~b * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(2 * ~n, 2 * ~p) && (LtQ(~p, -1) && GtQ(~n, 0))))
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n) / (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => (1 / ((~a) ^ 2 - (~b) ^ 2)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ ~n * (~a - ~b * sin(~e + ~f * ~x)), ~x) - ((~b) ^ 2 / ((~g) ^ 2 * ((~a) ^ 2 - (~b) ^ 2))) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ (~p + 2) * (~d * sin(~e + ~f * ~x)) ^ ~n) / (~a + ~b * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(2 * ~n, 2 * ~p) && LtQ(~p, -1)))
    @apply_utils Antiderivative(sqrt(~(g') * cos(~(e') + ~(f') * ~x)) / (sqrt(sin(~(e') + ~(f') * ~x)) * (~a + ~(b') * sin(~(e') + ~(f') * ~x))), ~x) => ((-4 * sqrt(2) * ~g) / ~f) * Subst(Antiderivative((~x) ^ 2 / (((~a + ~b) * (~g) ^ 2 + (~a - ~b) * (~x) ^ 4) * sqrt(1 - (~x) ^ 4 / (~g) ^ 2)), ~x), ~x, sqrt(~g * cos(~e + ~f * ~x)) / sqrt(1 + sin(~e + ~f * ~x))) <-- FreeQ([~a, ~b, ~e, ~f, ~g], ~x) && NeQ((~a) ^ 2 - (~b) ^ 2, 0)
    @apply_utils Antiderivative(sqrt(~(g') * cos(~(e') + ~(f') * ~x)) / (sqrt(~d * sin(~(e') + ~(f') * ~x)) * (~a + ~(b') * sin(~(e') + ~(f') * ~x))), ~x) => (sqrt(sin(~e + ~f * ~x)) / sqrt(~d * sin(~e + ~f * ~x))) * Antiderivative(sqrt(~g * cos(~e + ~f * ~x)) / (sqrt(sin(~e + ~f * ~x)) * (~a + ~b * sin(~e + ~f * ~x))), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g], ~x) && NeQ((~a) ^ 2 - (~b) ^ 2, 0)
    @apply_utils Antiderivative(sqrt(~(d') * sin(~(e') + ~(f') * ~x)) / (sqrt(cos(~(e') + ~(f') * ~x)) * (~a + ~(b') * sin(~(e') + ~(f') * ~x))), ~x) => With([q = Rt(-((~a) ^ 2) + (~b) ^ 2, 2)], ((2 * sqrt(2) * ~d * (~b + q)) / (~f * q)) * Subst(Antiderivative(1 / ((~d * (~b + q) + ~a * (~x) ^ 2) * sqrt(1 - (~x) ^ 4 / (~d) ^ 2)), ~x), ~x, sqrt(~d * sin(~e + ~f * ~x)) / sqrt(1 + cos(~e + ~f * ~x))) - ((2 * sqrt(2) * ~d * (~b - q)) / (~f * q)) * Subst(Antiderivative(1 / ((~d * (~b - q) + ~a * (~x) ^ 2) * sqrt(1 - (~x) ^ 4 / (~d) ^ 2)), ~x), ~x, sqrt(~d * sin(~e + ~f * ~x)) / sqrt(1 + cos(~e + ~f * ~x)))) <-- FreeQ([~a, ~b, ~d, ~e, ~f], ~x) && NeQ((~a) ^ 2 - (~b) ^ 2, 0)
    @apply_utils Antiderivative(sqrt(~(d') * sin(~(e') + ~(f') * ~x)) / (sqrt(~(g') * cos(~(e') + ~(f') * ~x)) * (~a + ~(b') * sin(~(e') + ~(f') * ~x))), ~x) => (sqrt(cos(~e + ~f * ~x)) / sqrt(~g * cos(~e + ~f * ~x))) * Antiderivative(sqrt(~d * sin(~e + ~f * ~x)) / (sqrt(cos(~e + ~f * ~x)) * (~a + ~b * sin(~e + ~f * ~x))), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g], ~x) && NeQ((~a) ^ 2 - (~b) ^ 2, 0)
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n) / (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => (~d / ~b) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ (~n - 1), ~x) - ((~a * ~d) / ~b) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ (~n - 1)) / (~a + ~b * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(2 * ~n, 2 * ~p) && (LtQ(-1, ~p, 1) && GtQ(~n, 0))))
    @apply_utils Antiderivative(((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n) / (~a + ~(b') * sin(~(e') + ~(f') * ~x)), ~x) => (1 / ~a) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ ~n, ~x) - (~b / (~a * ~d)) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ (~n + 1)) / (~a + ~b * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(2 * ~n, 2 * ~p) && (LtQ(-1, ~p, 1) && LtQ(~n, 0))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ 2, ~x) => ((2 * ~a * ~b) / ~d) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ (~n + 1), ~x) + Antiderivative((~g * cos(~e + ~f * ~x)) ^ ~p * (~d * sin(~e + ~f * ~x)) ^ ~n * ((~a) ^ 2 + (~b) ^ 2 * sin(~e + ~f * ~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g, ~n, ~p], ~x) && NeQ((~a) ^ 2 - (~b) ^ 2, 0)
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => Antiderivative(ExpandTrig((~g * cos(~e + ~f * ~x)) ^ ~p, (~d * sin(~e + ~f * ~x)) ^ ~n * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m, ~x), ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g, ~n, ~p], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegerQ(~m) && (GtQ(~m, 0) || IntegerQ(~n))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m, ~x) => (((~g) ^ 2 / ~a) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ ~n * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1), ~x) - ((~b * (~g) ^ 2) / ((~a) ^ 2 * ~d)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ (~n + 1) * (~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1), ~x)) - (((~g) ^ 2 * ((~a) ^ 2 - (~b) ^ 2)) / ((~a) ^ 2 * (~d) ^ 2)) * Antiderivative((~g * cos(~e + ~f * ~x)) ^ (~p - 2) * (~d * sin(~e + ~f * ~x)) ^ (~n + 2) * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m, ~x) <-- FreeQ([~a, ~b, ~d, ~e, ~f, ~g], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(~m, 2 * ~n, 2 * ~p) && (LtQ(~m, 0) && (GtQ(~p, 1) && (LeQ(~n, -2) || EqQ(~m, -1) && (EqQ(~n, -3 / 2) && EqQ(~p, 3 / 2)))))))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (~a) ^ (2 * ~m) * Antiderivative((~c + ~d * sin(~e + ~f * ~x)) ^ ~n / (~a - ~b * sin(~e + ~f * ~x)) ^ ~m, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegersQ(~m, ~p) && EqQ(2 * ~m + ~p, 0)))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (~a / ~g) ^ (2 * ~m) * Antiderivative(((~g * cos(~e + ~f * ~x)) ^ (2 * ~m + ~p) * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n) / (~a - ~b * sin(~e + ~f * ~x)) ^ ~m, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegerQ(~m) && (EqQ(2 * ~m + ~p, 0) || GtQ(2 * ~m + ~p, 0) && LtQ(~p, -1))))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 2 * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (1 / (~b) ^ 2) * Antiderivative((~a + ~b * sin(~e + ~f * ~x)) ^ (~m + 1) * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n * (~a - ~b * sin(~e + ~f * ~x)), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~m, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && IntegersQ(2 * ~m, 2 * ~n))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (((~a) ^ ~m * cos(~e + ~f * ~x)) / (~f * sqrt(1 + sin(~e + ~f * ~x)) * sqrt(1 - sin(~e + ~f * ~x)))) * Subst(Antiderivative((1 + (~b / ~a) * ~x) ^ (~m + (~p - 1) / 2) * (1 - (~b / ~a) * ~x) ^ ((~p - 1) / 2) * (~c + ~d * ~x) ^ ~n, ~x), ~x, sin(~e + ~f * ~x)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegerQ(~p / 2) && IntegerQ(~m)))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (cos(~e + ~f * ~x) / ((~a) ^ (~p - 2) * ~f * sqrt(~a + ~b * sin(~e + ~f * ~x)) * sqrt(~a - ~b * sin(~e + ~f * ~x)))) * Subst(Antiderivative((~a + ~b * ~x) ^ ((~m + ~p / 2) - 1 / 2) * (~a - ~b * ~x) ^ (~p / 2 - 1 / 2) * (~c + ~d * ~x) ^ ~n, ~x), ~x, sin(~e + ~f * ~x)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~m, ~n], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IntegerQ(~p / 2) && Not(IntegerQ(~m))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => Antiderivative(ExpandTrig((~g * cos(~e + ~f * ~x)) ^ ~p, (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~n, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && (IGtQ(~m, 0) && (IntegerQ(~p) || IGtQ(~n, 0))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => (((~a) ^ ~m * ~g * (~g * cos(~e + ~f * ~x)) ^ (~p - 1)) / (~f * (1 + sin(~e + ~f * ~x)) ^ ((~p - 1) / 2) * (1 - sin(~e + ~f * ~x)) ^ ((~p - 1) / 2))) * Subst(Antiderivative((1 + (~b / ~a) * ~x) ^ (~m + (~p - 1) / 2) * (1 - (~b / ~a) * ~x) ^ ((~p - 1) / 2) * (~c + ~d * ~x) ^ ~n, ~x), ~x, sin(~e + ~f * ~x)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~n, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && IntegerQ(~m))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => ((~g * (~g * cos(~e + ~f * ~x)) ^ (~p - 1)) / (~f * (~a + ~b * sin(~e + ~f * ~x)) ^ ((~p - 1) / 2) * (~a - ~b * sin(~e + ~f * ~x)) ^ ((~p - 1) / 2))) * Subst(Antiderivative((~a + ~b * ~x) ^ (~m + (~p - 1) / 2) * (~a - ~b * ~x) ^ ((~p - 1) / 2) * (~c + ~d * ~x) ^ ~n, ~x), ~x, sin(~e + ~f * ~x)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~m, ~n, ~p], ~x) && (EqQ((~a) ^ 2 - (~b) ^ 2, 0) && Not(IntegerQ(~m)))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ 2 * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => Antiderivative((~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n * (1 - sin(~e + ~f * ~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~m, ~n], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IGtQ(~m, 0) || IntegersQ(2 * ~m, 2 * ~n)))
    @apply_utils Antiderivative(cos(~(e') + ~(f') * ~x) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => Antiderivative(ExpandTrig((~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n * (1 - sin(~e + ~f * ~x) ^ 2) ^ (~p / 2), ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~m, ~n], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && (IGtQ(~p / 2, 0) && (IGtQ(~m, 0) || IntegersQ(2 * ~m, 2 * ~n))))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~m * (~c + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~n, ~x) => Antiderivative(ExpandTrig((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (NeQ((~a) ^ 2 - (~b) ^ 2, 0) && IntegersQ(2 * ~m, 2 * ~n))
    @apply_utils Antiderivative((~(g') * cos(~(e') + ~(f') * ~x)) ^ ~p * (~a + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~(n'), ~x) => Unintegrable((~g * cos(~e + ~f * ~x)) ^ ~p * (~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~n, ~p], ~x) && NeQ((~a) ^ 2 - (~b) ^ 2, 0)
    @apply_utils Antiderivative((~(g') * sec(~(e') + ~(f') * ~x)) ^ ~p * (~(a') + ~(b') * sin(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * sin(~(e') + ~(f') * ~x)) ^ ~(n'), ~x) => (~g) ^ (2 * IntPart(~p)) * (~g * cos(~e + ~f * ~x)) ^ FracPart(~p) * (~g * sec(~e + ~f * ~x)) ^ FracPart(~p) * Antiderivative(((~a + ~b * sin(~e + ~f * ~x)) ^ ~m * (~c + ~d * sin(~e + ~f * ~x)) ^ ~n) / (~g * cos(~e + ~f * ~x)) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~n, ~p], ~x) && Not(IntegerQ(~p))
    @apply_utils Antiderivative((~(g') * csc(~(e') + ~(f') * ~x)) ^ ~p * (~(a') + ~(b') * cos(~(e') + ~(f') * ~x)) ^ ~(m') * (~(c') + ~(d') * cos(~(e') + ~(f') * ~x)) ^ ~(n'), ~x) => (~g) ^ (2 * IntPart(~p)) * (~g * sin(~e + ~f * ~x)) ^ FracPart(~p) * (~g * csc(~e + ~f * ~x)) ^ FracPart(~p) * Antiderivative(((~a + ~b * cos(~e + ~f * ~x)) ^ ~m * (~c + ~d * cos(~e + ~f * ~x)) ^ ~n) / (~g * sin(~e + ~f * ~x)) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~n, ~p], ~x) && Not(IntegerQ(~p))
end

max_stars_repo_path: src/rules/4 Trig functions/4.1 Sine/4.1.2.2 (g cos)^p (a+b sin)^m (c+d sin)^n.jl


text:
@testset "initialise_arg_names" begin
    test_dict = Dict(
        "arg1" => 1,
        "arg2" => "str",
        "arg3" => [1,2,3],
        "arg4" => Dict(
            "arg1" => 2,
            "arg2" => [
                Dict(
                    "arg3" => 1,
                    "arg5" => 5.0,
                ),
                Dict(
                    "arg3" => 1,
                    "arg5" => 5.0,
                ),
            ]
        )
    )
    initialised_dict = GraphQLClient.initialise_arg_names(test_dict)
    @test keys(test_dict) == keys(initialised_dict)
    @test keys(test_dict["arg4"]) == keys(initialised_dict["arg4"])
    @test keys(test_dict["arg4"]["arg2"][1]) == keys(initialised_dict["arg4"]["arg2"][1])
    @test keys(test_dict["arg4"]["arg2"][2]) == keys(initialised_dict["arg4"]["arg2"][2])
end

@testset "get_query_args_str" begin
    # Basic test
    args = Dict(
        "A" => 1.0,
        "B" => "word"
    )
    str, arg_names = GraphQLClient.get_query_args_str(args)
    @test occursin("B:\$B,", str)
    @test occursin("A:\$A,", str)
    @test all(keys(arg_names) .== values(arg_names))

    # Nested dictionary
    args = Dict(
        "A" => 1.0,
        "B" => Dict("C" => true)
    )
    str, arg_names = GraphQLClient.get_query_args_str(args)
    @test occursin("A:\$A,", str)
    @test occursin("B:{C:\$C,},", str)

    # Vector of dictionaries with same keys
    args = Dict("vec" => [
        Dict(
            "A" => 1.0,
            "B" => true,
        ),
        Dict(
            "A" => 3.0,
            "B" => false,
        ),
    ])
    str, arg_names = GraphQLClient.get_query_args_str(args)
    @test length(unique(vcat(collect(values(arg_names["vec"][1])), collect(values(arg_names["vec"][2]))))) == 4 # four unique names
    @test all(key -> occursin(key, str), keys(arg_names["vec"][1]))  # Check all arg_names are in str
    @test all(key -> occursin(key, str), keys(arg_names["vec"][2]))  # Check all arg_names are in str

    # Different fields with same keys
    args = Dict(
        "arg1" => 1,
        "arg2" => Dict(
            "arg1" => 2,
            "arg2" => [
                Dict(
                    "arg1" => 6,
                    "arg2" => 5.0,
                ),
                Dict(
                    "arg1" => 5,
                    "arg2" => 2.0,
                ),
            ]
        )
    )
    str, arg_names = GraphQLClient.get_query_args_str(args)
    all_names = vcat(
        arg_names["arg1"],
        arg_names["arg2"]["arg1"],
        collect(values(arg_names["arg2"]["arg2"][1])),
        collect(values(arg_names["arg2"]["arg2"][2])),
    )
    @test length(all_names) == length(unique(all_names))
end

@testset "directly_write_query_args" begin
    @test GraphQLClient.directly_write_query_args(Dict("a"=>1)) == "a:1"
    @test GraphQLClient.directly_write_query_args(Dict("a"=>"string")) == "a:\"string\""
    @test GraphQLClient.directly_write_query_args(Dict("a"=>GQLEnum("enum"))) == "a:enum"
    @test GraphQLClient.directly_write_query_args(Dict("a"=>true)) == "a:true"
    @test GraphQLClient.directly_write_query_args(Dict("a"=>[1])) == "a:[1]"
    str = GraphQLClient.directly_write_query_args(Dict("a"=>1, "b"=>1.0))
    @test occursin("a:1", str)
    @test occursin("b:1.0", str)
    @test GraphQLClient.directly_write_query_args(Dict("a"=>Dict("b"=>[1]))) == "a:{b:[1]}"
    @test GraphQLClient.directly_write_query_args(Dict()) == ""
end

ext: jl


text:
@doc raw"""
    Circle{𝔽} <: Manifold{𝔽}

The circle $𝕊^1$ is a manifold here represented by
real-valued points in $[-π,π)$ or complex-valued points $z ∈ ℂ$ of absolute value
$\lvert z\rvert = 1$.
# Constructor

    Circle(𝔽=ℝ)

Generate the `ℝ`-valued Circle represented by angles, which
alternatively can be set to use the [`AbstractNumbers`](@ref) `𝔽=ℂ` to obtain the circle
represented by `ℂ`-valued circle of unit numbers.
"""
struct Circle{𝔽} <: Manifold{𝔽} end

Circle(𝔽::AbstractNumbers = ℝ) = Circle{𝔽}()

@doc raw"""
    check_manifold_point(M::Circle, p)

Check whether `p` is a point on the [`Circle`](@ref) `M`.
For the real-valued case, `x` is an angle and hence it checks that $p  ∈ [-π,π)$.
for the complex-valued case, it is a unit number, $p ∈ ℂ$ with $\lvert p \rvert = 1$.
"""
check_manifold_point(::Circle, ::Any...)

function check_manifold_point(M::Circle{ℝ}, p; kwargs...)
    if !isapprox(sym_rem(p), p; kwargs...)
        return DomainError(
            p,
            "The point $(p) does not lie on $(M), since its is not in [-π,π).",
        )
    end
    return nothing
end
function check_manifold_point(M::Circle{ℂ}, p; kwargs...)
    if !isapprox(sum(abs.(p)), 1.0; kwargs...)
        return DomainError(
            abs(p),
            "The point $(p) does not lie on the $(M) since its norm is not 1.",
        )
    end
    return nothing
end

"""
    check_tangent_vector(M::Circle, p, X; check_base_point, kwargs...)

Check whether `X` is a tangent vector in the tangent space of `p` on the
[`Circle`](@ref) `M`.
For the real-valued case represented by angles, all `X` are valid, since the tangent space is the whole real line.
For the complex-valued case `X` has to lie on the line parallel to the tangent line at `p`
in the complex plane, i.e. their inner product has to be zero.
The optional parameter `check_base_point` indicates, whether to call [`check_manifold_point`](@ref)  for `p`.
"""
check_tangent_vector(::Circle{ℝ}, ::Any...; ::Any...)

function check_tangent_vector(M::Circle{ℝ}, p, X; check_base_point = true, kwargs...)
    if check_base_point
        perr = check_manifold_point(M, p; kwargs...)
        return perr # if x is valid all v that are real numbers are valid
    end
    return nothing
end
function check_tangent_vector(M::Circle{ℂ}, p, X; check_base_point = true, kwargs...)
    if check_base_point
        perr = check_manifold_point(M, p)
        perr === nothing || return perr
    end
    if !isapprox(abs(complex_dot(p, X)), 0.0; kwargs...)
        return DomainError(
            abs(complex_dot(p, X)),
            "The value $(X) is not a tangent vector to $(p) on $(M), since it is not orthogonal in the embedding.",
        )
    end
    return nothing
end

@doc raw"""
    complex_dot(a, b)

Compute the inner product of two (complex) numbers with in the complex plane.
"""
complex_dot(a, b) = dot(map(real, a), map(real, b)) + dot(map(imag, a), map(imag, b))
complex_dot(a::Number, b::Number) = (real(a) * real(b) + imag(a) * imag(b))

@doc raw"""
    distance(M::Circle, p, q)

Compute the distance on the [`Circle`](@ref) `M`, which is
the absolute value of the symmetric remainder of `p` and `q` for the real-valued
case and the angle between both complex numbers in the Gaussian plane for the
complex-valued case.
"""
distance(::Circle, ::Any...)
distance(::Circle{ℝ}, p::Real, q::Real) = abs(sym_rem(p - q))
distance(::Circle{ℝ}, p, q) = abs(sum(sym_rem.(p - q)))
distance(::Circle{ℂ}, p, q) = acos(clamp(complex_dot(p, q), -1, 1))

@doc raw"""
    exp(M::Circle, p, X)

Compute the exponential map on the [`Circle`](@ref).
````math
\exp_p X = (p+X)_{2π},
````
where $(\cdot)_{2π}$ is the (symmetric) remainder with respect to division by $2π$, i.e. in $[-π,π)$.

For the complex-valued case, the same formula as for the [`Sphere`](@ref) $𝕊^1$ is applied to values in the
complex plane.
"""
exp(::Circle, ::Any...)
Base.exp(::Circle{ℝ}, p::Real, X::Real) = sym_rem(p + X)
function Base.exp(M::Circle{ℂ}, x::Number, v::Number)
    θ = norm(M, x, v)
    return cos(θ) * x + usinc(θ) * v
end

exp!(::Circle{ℝ}, q, p, X) = (q .= sym_rem(p + X))
function exp!(M::Circle{ℂ}, q, p, X)
    θ = norm(M, p, X)
    q .= cos(θ) * p + usinc(θ) * X
    return q
end

flat(::Circle, ::Number, X::TFVector) = FVector(CotangentSpace, X.data)

flat!(::Circle, ξ::CoTFVector, p, X::TFVector) = copyto!(ξ, X)

function get_basis(M::Circle{ℝ}, p, B::DiagonalizingOrthonormalBasis)
    sbv = sign(B.frame_direction[])
    vs = @SVector [@SVector [sbv == 0 ? one(sbv) : sbv]]
    return CachedBasis(B, (@SVector [0]), vs)
end
get_coordinates(M::Circle{ℝ}, p, X, B::DefaultOrthonormalBasis) = X
function get_coordinates(M::Circle{ℝ}, p, X, B::DiagonalizingOrthonormalBasis)
    sbv = sign(B.frame_direction[])
    return X .* (sbv == 0 ? 1 : sbv)
end
"""
    get_coordinates(M::Circle{ℂ}, p, X, B::DefaultOrthonormalBasis)

Return tangent vector coordinates in the Lie algebra of the [`Circle`](@ref).
"""
function get_coordinates(M::Circle{ℂ}, p, X, B::DefaultOrthonormalBasis)
    X, p = X[1], p[1]
    Xⁱ = imag(X) * real(p) - real(X) * imag(p)
    return @SVector [Xⁱ]
end

eval(
    quote
        @invoke_maker 1 Manifold get_coordinates(
            M::Circle,
            e::Identity,
            X,
            B::VeeOrthogonalBasis,
        )
    end,
)

function get_coordinates!(M::Circle, Y::AbstractArray, p, X, B::DefaultOrthonormalBasis)
    Y[] = get_coordinates(M, p, X, B)[]
    return Y
end
function get_coordinates!(
    M::Circle,
    Y::AbstractArray,
    p,
    X,
    B::DiagonalizingOrthonormalBasis,
)
    Y[] = get_coordinates(M, p, X, B)[]
    return Y
end

eval(
    quote
        @invoke_maker 1 Manifold get_coordinates!(
            M::Circle,
            Y::AbstractArray,
            p,
            X,
            B::VeeOrthogonalBasis,
        )
    end,
)

get_vector(::Circle{ℝ}, p, X, ::AbstractBasis) = X
function get_vector(M::Circle{ℝ}, p, X, B::DiagonalizingOrthonormalBasis)
    sbv = sign(B.frame_direction[])
    return X .* (sbv == 0 ? 1 : sbv)
end
"""
    get_vector(M::Circle{ℂ}, p, X, B::DefaultOrthonormalBasis)

Return tangent vector from the coordinates in the Lie algebra of the [`Circle`](@ref).
"""
get_vector(M::Circle{ℂ}, p, X, B::AbstractBasis) = @SVector [1im * X[1] * p[1]]

function get_vector!(M::Circle, Y::AbstractArray, p, X, B::AbstractBasis)
    Y[] = get_vector(M, p, X, B)[]
    return Y
end
for BT in ManifoldsBase.DISAMBIGUATION_BASIS_TYPES
    eval(
        quote
            @invoke_maker 5 $(supertype(BT)) get_vector!(
                M::Circle,
                Y::AbstractArray,
                p,
                X,
                B::$BT,
            )
        end,
    )
end

@doc raw"""
    injectivity_radius(M::Circle[, p])

Return the injectivity radius on the [`Circle`](@ref) `M`, i.e. $π$.
"""
injectivity_radius(::Circle) = π
injectivity_radius(::Circle, ::ExponentialRetraction) = π
injectivity_radius(::Circle, ::Any) = π
injectivity_radius(::Circle, ::Any, ::ExponentialRetraction) = π
eval(
    quote
        @invoke_maker 1 Manifold injectivity_radius(
            M::Circle,
            rm::AbstractRetractionMethod,
        )
    end,
)

@doc raw"""
    inner(M::Circle, p, X, Y)

Compute the inner product of the two tangent vectors `X,Y` from the tangent plane at `p` on
the [`Circle`](@ref) `M` using the restriction of the metric from the embedding,
i.e.

````math
g_p(X,Y) = X*Y
````

for the real case and

````math
g_p(X,Y) = Y^\mathrm{T}X
````

for the complex case interpreting complex numbers in the Gaussian plane.
"""
inner(::Circle, ::Any...)
@inline inner(::Circle{ℝ}, p, X, Y) = dot(X, Y)
@inline inner(::Circle{ℝ}, p::Real, X::Real, Y::Real) = X * Y
@inline inner(::Circle{ℂ}, p, X, Y) = complex_dot(X, Y)

function inverse_retract(M::Circle, x::Number, y::Number)
    return inverse_retract(M, x, y, LogarithmicInverseRetraction())
end
function inverse_retract(M::Circle, x::Number, y::Number, ::LogarithmicInverseRetraction)
    return log(M, x, y)
end

@doc raw"""
    log(M::Circle, p, q)

Compute the logarithmic map on the [`Circle`](@ref) `M`.
````math
\log_p q = (q-p)_{2π},
````
where $(\cdot)_{2π}$ is the (symmetric) remainder with respect to division by $2π$, i.e. in $[-π,π)$.

For the complex-valued case, the same formula as for the [`Sphere`](@ref) $𝕊^1$ is applied to values in the
complex plane.
"""
log(::Circle, ::Any...)
Base.log(::Circle{ℝ}, p::Real, q::Real) = sym_rem(q - p)
function Base.log(M::Circle{ℂ}, p::Number, q::Number)
    cosθ = complex_dot(p, q)
    if cosθ ≈ -1  # appr. opposing points, return deterministic choice from set-valued log
        X = real(p) ≈ 1 ? 1im : 1 + 0im
        X = X - complex_dot(p, X) * p
        X *= π / norm(X)
    else
        cosθ = cosθ > 1 ? one(cosθ) : cosθ
        θ = acos(cosθ)
        X = (q - cosθ * p) / usinc(θ)
    end
    return project(M, p, X)
end

log!(::Circle{ℝ}, X, p, q) = (X .= sym_rem(q - p))
function log!(M::Circle{ℂ}, X, p, q)
    cosθ = complex_dot(p, q)
    if cosθ ≈ -1
        X .= sum(real.(p)) ≈ 1 ? 1.0im : 1.0 + 0.0im
        X .= X - complex_dot(p, X) * p
        X .*= π / norm(X)
    else
        cosθ = cosθ > 1 ? one(cosθ) : cosθ
        θ = acos(cosθ)
        X .= (q - cosθ * p) / usinc(θ)
    end
    return project!(M, X, p, X)
end

@doc raw"""
    manifold_dimension(M::Circle)

Return the dimension of the [`Circle`](@ref) `M`,
i.e. $\dim(𝕊^1) = 1$.
"""
manifold_dimension(::Circle) = 1

@doc raw"""
    mean(M::Circle{ℝ}, x::AbstractVector[, w::AbstractWeights])

Compute the Riemannian [`mean`](@ref mean(M::Manifold, args...)) of `x` of points on
the [`Circle`](@ref) $𝕊^1$, reprsented by real numbers, i.e. the angular mean
````math
\operatorname{atan}\Bigl( \sum_{i=1}^n w_i\sin(x_i),  \sum_{i=1}^n w_i\sin(x_i) \Bigr).
````
"""
mean(::Circle{ℝ}, ::Any)
function Statistics.mean(::Circle{ℝ}, x::AbstractVector{<:Real}; kwargs...)
    return atan(1 / length(x) * sum(sin, x), 1 / length(x) * sum(cos, x))
end
function Statistics.mean(
    ::Circle{ℝ},
    x::AbstractVector{<:Real},
    w::AbstractVector;
    kwargs...,
)
    return atan(sum(w .* sin.(x)), sum(w .* cos.(x)))
end
@doc raw"""
    mean(M::Circle{ℂ}, x::AbstractVector[, w::AbstractWeights])

Compute the Riemannian [`mean`](@ref mean(M::Manifold, args...)) of `x` of points on
the [`Circle`](@ref) $𝕊^1$, reprsented by complex numbers, i.e. embedded in the complex plade.
Comuting the sum
````math
s = \sum_{i=1}^n x_i
````
the mean is the angle of the complex number $s$, so represented in the complex plane as
$\frac{s}{\lvert s \rvert}$, whenever $s \neq 0$.

If the sum $s=0$, the mean is not unique. For example for opposite points or equally spaced
angles.
"""
mean(::Circle{ℂ}, ::Any)
function Statistics.mean(M::Circle{ℂ}, x::AbstractVector{<:Complex}; kwargs...)
    s = sum(x)
    abs(s) == 0 &&
        return error("The mean for $(x) on $(M) is not defined/unique, since the sum of the complex numbers is zero")
    return s / abs(s)
end
function Statistics.mean(
    M::Circle{ℂ},
    x::AbstractVector{<:Complex},
    w::AbstractVector;
    kwargs...,
)
    s = sum(w .* x)
    abs(s) == 0 &&
        error("The mean for $(x) on $(M) is not defined/unique, since the sum of the complex numbers is zero")
    return s /= abs(s)
end

mid_point(M::Circle{ℝ}, p1, p2) = exp(M, p1, 0.5 * log(M, p1, p2))
mid_point(::Circle{ℂ}, p1::Complex, p2::Complex) = exp(im * (angle(p1) + angle(p2)) / 2)
mid_point(M::Circle{ℂ}, p1::StaticArray, p2::StaticArray) = SA[mid_point(M, p1[], p2[])]

@inline LinearAlgebra.norm(::Circle, p, X) = sum(abs, X)

number_of_coordinates(::Circle, ::AbstractBasis) = 1

@doc raw"""
    project(M::Circle, p)

Project a point `p` onto the [`Circle`](@ref) `M`.
For the real-valued case this is the remainder with respect to modulus $2π$.
For the complex-valued case the result is the projection of `p` onto the unit circle in the
complex plane.
"""
project(::Circle, ::Any)
project(::Circle{ℝ}, p::Real) = sym_rem(p)
project(::Circle{ℂ}, p::Number) = p / abs(p)

project!(::Circle{ℝ}, q, p) = copyto!(q, sym_rem(p))
project!(::Circle{ℂ}, q, p) = copyto!(q, p / sum(abs.(p)))

@doc raw"""
    project(M::Circle, p, X)

Project a value `X` onto the tangent space of the point `p` on the [`Circle`](@ref) `M`.

For the real-valued case this is just the identity.
For the complex valued case `X` is projected onto the line in the complex plane
that is parallel to the tangent to `p` on the unit circle and contains `0`.
"""
project(::Circle, ::Any, ::Any)
project(::Circle{ℝ}, p::Real, X::Real) = X
project(::Circle{ℂ}, p::Number, X::Number) = X - complex_dot(p, X) * p

project!(::Circle{ℝ}, Y, p, X) = (Y .= X)
project!(::Circle{ℂ}, Y, p, X) = (Y .= X - complex_dot(p, X) * p)

retract(M::Circle, p, q) = retract(M, p, q, ExponentialRetraction())
retract(M::Circle, p, q, m::ExponentialRetraction) = exp(M, p, q)

representation_size(::Circle) = ()

sharp(::Circle, p::Number, ξ::CoTFVector) = FVector(TangentSpace, ξ.data)

sharp!(::Circle, X::TFVector, p, ξ::CoTFVector) = copyto!(X, ξ)

Base.show(io::IO, ::Circle{𝔽}) where {𝔽} = print(io, "Circle($(𝔽))")

@doc raw"""
    sym_rem(x,[T=π])

Compute symmetric remainder of `x` with respect to the interall 2*`T`, i.e.
`(x+T)%2T`, where the default for `T` is $π$
"""
function sym_rem(x::N, T = π) where {N<:Number}
    return (x ≈ T ? convert(N, -T) : rem(x, convert(N, 2 * T), RoundNearest))
end
sym_rem(x, T = π) where {N} = map(sym_rem, x, Ref(T))

@doc raw"""
    vector_transport_to(M::Circle, p, X, q, ::ParallelTransport)

Compute the parallel transport of `X` from the tangent space at `p` to the tangent space at
`q` on the [`Circle`](@ref) `M`.
For the real-valued case this results in the identity.
For the complex-valud case, the formula is the same as for the [`Sphere`](@ref)`(1)` in the
complex plane.
````math
\mathcal P_{q←p} X = X - \frac{⟨\log_p q,X⟩_p}{d^2_{ℂ}(p,q)}
\bigl(\log_p q + \log_q p \bigr),
````
where [`log`](@ref) denotes the logarithmic map on `M`.
"""
vector_transport_to(::Circle, ::Any, ::Any, ::Any, ::ParallelTransport)
vector_transport_to(::Circle{ℝ}, p::Real, X::Real, q::Real, ::ParallelTransport) = X
function vector_transport_to(
    M::Circle{ℂ},
    p::Number,
    X::Number,
    q::Number,
    ::ParallelTransport,
)
    X_pq = log(M, p, q)
    Xnorm = norm(M, p, X_pq)
    Y = X
    if Xnorm > 0
        factor = 2 * complex_dot(X, q) / (abs(p + q)^2)
        Y -= factor .* (p + q)
    end
    return Y
end

vector_transport_to!(::Circle{ℝ}, Y, p, X, q, ::ParallelTransport) = (Y .= X)
function vector_transport_to!(M::Circle{ℂ}, Y, p, X, q, ::ParallelTransport)
    X_pq = log(M, p, q)
    Xnorm = norm(M, p, X_pq)
    Y .= X
    if Xnorm > 0
        factor = 2 * complex_dot(X, q) / (sum(abs.(p + q) .^ 2))
        Y .-= factor .* (p + q)
    end
    return Y
end

function vector_transport_direction(
    M::Circle,
    p::Number,
    X::Number,
    Y::Number,
    m::AbstractVectorTransportMethod,
)
    q = exp(M, p, Y)
    return vector_transport_to(M, p, X, q, m)
end

zero_tangent_vector(::Circle, p::Number) = zero(p)
zero_tangent_vector!(::Circle, X, p) = fill!(X, 0)


text:
include("sec_6_2.jl")
using Printf

r = 3
Mmax = ppImax = 10
M = 10
ppI = 5
store = Store(α, r+1, M, ppImax)

nrows = 6
N0 = 8
four = parse(T, "4")
qvals = T[1, 3, 5, 6]
ncols = length(qvals)
Nvals = Integer[ N0 * 2^i for i = 0:nrows-1 ]
err = Array{T}(undef, nrows, ncols)
@printf("%5s ", "N")
for q in qvals
    @printf("       q = %1d    ", q)
end
@printf("\n\n")
for row = 1:nrows
    N = Nvals[row]
    @printf("%5d ", N)
    for col = 1:ncols
        q = qvals[col]
        t = OffsetArray(T[ (n/N)^q * tmax/2 for n = 0:N ], 0:N)
        U = FODEdG!(λ, f, u0, t, r, M, store)
        Uhat = reconstruction(U, u0, store)
        pcwise_t, pcwise_Uhat = evaluate_pcwise_poly!(Uhat, t, ppI, store)
        pcwise_u = T[ u(t, λ, u0, f, 20, store) for t in pcwise_t ]
        pcwise_err = pcwise_Uhat - pcwise_u
        err[row,col] = maximum(abs.(pcwise_err))
        if row == 1
            @printf("&%8.1e&%5s ", err[row,col], "")
        else
            N_ratio = Nvals[row] / Nvals[row-1]
            err_ratio = err[row-1,col] / err[row,col]
            rate = log(err_ratio) / log(N_ratio)
            @printf("&%8.1e&%5.2f ", err[row,col], rate)
        end
    end
    @printf("\\\\\n")
end


text:
module B_structs

using JuMP
using O_structs

# */ --------------------------------------------------------------------------------------------- /* #
# */ --- structures of data : on main core ------------------------------------------------------- /* #
# */ --------------------------------------------------------------------------------------------- /* #

export D__type
export R__type
export T1_type
export T2_type
export H__type
export M__type
export B1_type
export B2_type

mutable struct D__type
    ms::ms_type
    mp::mp_type
    ps::ps_type
    pp::pp_type
   unc::u_type
  case::Int64
  algm::Int64
  wrks::Int64
  kidx::Array{BitArray{1},1}
  iidx::Array{Array{Int64,1},1}
     J::Int64
     δ::Float64
end

mutable struct R__type
     m::JuMP.Model
  vars::Array{JuMP.VariableRef,2}
  cons::Array{JuMP.ConstraintRef,2}
end

mutable struct T1_type
     x::Array{Float64,2}
     c::Array{Float64,2}
     β::Array{Float64,1}
     θ::Array{Float64,1}
     λ::Array{Float64,2}
    re::Array{Tuple{Float64,Array{Float64,1}},1}
     Δ::Float64
end

mutable struct T2_type
     x::Array{Float64,2}
     c::Array{Float64,2}
     β::Array{Float64,1}
    θl::Array{Float64,1}
    λl::Array{Float64,2}
    θu::Array{Float64,1}
    ϕu::Array{Float64,2}
    re::Array{Tuple{Float64,Array{Float64,1},Array{Float64,1}},1}
    ro::Array{Tuple{Float64,Float64,Array{Float64,1},Array{Float64,1}},1}
    Ie::Array{Int64,1}
     Δ::Float64
end

mutable struct H__type
     L::Array{Float64,1}
     U::Array{Float64,1}
     t::Array{Float64,1}
     T::Array{Float64,2}
     k::Int64
end

mutable struct M__type
      n::Int64
      θ::Array{Float64,1}
      λ::Array{Float64,2}
      ϕ::Array{Float64,2}
      x::Array{Float64,2}
      c::Array{Float64,2}
end

mutable struct B1_type
   rmp::R__type
  temp::T1_type
  hist::H__type
  data::D__type
end

mutable struct B2_type
    rmp::R__type
   temp::T2_type
   hist::H__type
     m0::M__type
   data::D__type
end

# */ --------------------------------------------------------------------------------------------- /* #
# */ --- structures of data : everywhere --------------------------------------------------------- /* #
# */ --------------------------------------------------------------------------------------------- /* #

export E__type
export O__type
export d__type
export t__type
export S1_type
export S2_type

mutable struct E__type
      m::JuMP.Model
   vars::Array{JuMP.VariableRef,1}
   objf::GenericAffExpr{Float64,VariableRef}
end

mutable struct O__type
      m::JuMP.Model
   cons::Array{JuMP.ConstraintRef,1}
   vars::Array{JuMP.VariableRef,1}
   objf::GenericAffExpr{Float64,VariableRef}
   cexp::GenericAffExpr{Float64,VariableRef}
   help::Array{Float64,1}
      n::Int64
end

mutable struct d__type
     ps::ps_type
     pp::pp_type
    unc::u_type
      w::Int64
     Jw::Int64
end

mutable struct t__type
      x::Array{Float64,2}
      c::Array{Float64,2}
end

mutable struct S1_type
     ex::E__type
   data::d__type
   temp::t__type
end

mutable struct S2_type
     ex::E__type
    olb::O__type
    oub::O__type
      m::M__type
   data::d__type
   temp::t__type
end

# */ --------------------------------------------------------------------------------------------- /* #
# */ --------------------------------------------------------------------------------------------- /* #

end


text:
using Documenter, Interpolations
makedocs(
sitename="Interpolations.jl",
modules=[Interpolations],
format=Documenter.HTML(prettyurls = get(ENV, "CI", nothing)=="true"),
pages=["Home" => "index.md",
        "General usage" => "interpolations.md",
        "Interpolation algorithms" => "control.md",
        "Extrapolation" => "extrapolation.md",
        "Convenience Constructors" => "convenience-construction.md",
        "Library" => "api.md"]
)

deploydocs(repo="github.com/JuliaMath/Interpolations.jl")


text:
module TestModel

using Test
using TMLE
using MLJ
using StableRNGs
using StatsBase
using Distributions

LinearBinaryClassifier = @load LinearBinaryClassifier pkg=GLM verbosity=0

@testset "Test sub machines have been fitted correctly" begin
    rng = StableRNG(123)
    n = 100
    T = (t₁=categorical(sample(rng, ["CG", "CC"], Weights([0.7, 0.3]), n)),
         t₂=categorical(sample(rng, ["AT", "AA"], Weights([0.6, 0.4]), n)))
    W = (w₁=rand(rng, n), w₂=rand(rng, n))
    y = categorical(rand(rng, Bernoulli(0.3), n))

    query = (t₁=["CC", "CG"], t₂=["AT", "AA"])
    Q̅ = ConstantClassifier()
    G = FullCategoricalJoint(ConstantClassifier())
    F = LinearBinaryClassifier(fit_intercept=false, offsetcol=:offset)

    tmle = TMLEstimator(Q̅, G, query)

    mach = machine(tmle, T, W, y)
    fit!(mach, verbosity=0)

    # Fit outside of tmle
    Hmach = machine(OneHotEncoder(drop_last=true), T)
    fit!(Hmach, verbosity=0)
    Thot = transform(Hmach, T)
    X = merge(Thot, W)
    Q̅mach = machine(Q̅, X, y)
    fit!(Q̅mach, verbosity=0)
    @test Q̅mach.fitresult == fitted_params(mach).Q̅.target_distribution

    Gmach = machine(G, W, T)
    fit!(Gmach, verbosity=0)
    @test Gmach.fitresult == fitted_params(mach).G.fitresult
end

@testset "Test 4-points estimation non regression" begin
    rng = StableRNG(123)
    n = 100
    T = (t₁=categorical(sample(rng, ["CG", "CC"], Weights([0.7, 0.3]), n)),
         t₂=categorical(sample(rng, ["AT", "AA", "TT"], Weights([0.5, 0.4, 0.1]), n)),
         t₃=categorical(sample(rng, ["CC", "GG", "CG"], Weights([0.6, 0.2, 0.2]), n)),
         t₄=categorical(sample(rng, ["TT", "AA"], Weights([0.6, 0.4]), n))
         )
    W = (w₁=rand(rng, n), w₂=rand(rng, n))
    y = categorical(rand(rng, Bernoulli(0.3), n))

    query = (t₁=["CC", "CG"], t₂=["AT", "AA"], t₃=["CC", "GG"], t₄=["TT", "AA"])
    Q̅ = ConstantClassifier()
    G = FullCategoricalJoint(ConstantClassifier())
    tmle = TMLEstimator(Q̅, G, query)

    mach = machine(tmle, T, W, y)
    fit!(mach, verbosity=0)

    # Test the various api results functions

    res = briefreport(mach)[1]
    @test res.estimate ≈ -1.59 atol=1e-2
    @test res.stderror ≈ 1.32 atol=1e-2
    @test res.mean_inf_curve ≈ -1.52e-8 atol=1e-2
    @test res.pvalue ≈ 0.23 atol=1e-2
    @test res.confint[1] ≈ -4.18 atol=1e-2
    @test res.confint[2] ≈ 1.01 atol=1e-2
end

end;

true

max_stars_repo_name: olivierlabayle/TMLE

max_issues_repo_name: olivierlabayle/TMLE

max_forks_repo_name: olivierlabayle/TMLE


text:
module FilteringWrapper

using JavaCall

include("KalmanWrapper/KalmanWrapper.jl")

end


text:
using Plots, LaTeXStrings, Statistics

function Deposition(;len, tot_time, time_steps)
    Time = exp.(0:tot_time/(time_steps-1):tot_time)
    surf = [0 for i=1:len]
    VarList = [0.0 for i=1:time_steps]
    for n in 1:time_steps
        randsurf = rand(1:len,floor(Int,Time[n]*1000 + 1000))
        for i in randsurf
            surf[i] += 1
        end
        VarList[n] = std(surf)
    end
    return Time, VarList
end

function Linear_fit(;len, tot_time, time_steps)
    A = [hcat(log.(Time)) reshape(ones(time_steps), time_steps, 1)]
    b = reshape(log.(VarList), time_steps, 1)
    line = (A \ b)
    x = 0:tot_time
    y = x .* line[1] .+ line[2]
    return x, y, line
end

Parameters = Dict(
                :len => 200,
                :tot_time => 10,
                :time_steps => 20
                    )

Time, VarList = Deposition(;Parameters...)
X, Y, Line = Linear_fit(;Parameters...)

theme(:dark)
gr()

scatter(log.(Time),log.(VarList),
    xlabel= L"Log\ Time",
    ylabel= L"Log\ W_{(t)}",
    title= L"Log-Log\ Plot\ of\ ~W_{(t)}-Time~",
    label = L"Data\ point")
plot!(X,Y,label = L"y = %$(round(Line[1],digits= 2))x + %$(round(Line[2],digits= 2))")
savefig("C:\\Users\\Yaghoub\\Documents\\GitHub\\Ballistic-Deposition\\Deposition\\Random-Ballistic-Deposition\\Fig\\log-log.png")

max_stars_repo_name: shahmari/Ballistic-Deposition

max_issues_repo_name: shahmari/Ballistic-Deposition

max_forks_repo_name: shahmari/Ballistic-Deposition


text:
export vague
export mean, median, mode, shape, scale, rate, var, std, cov, invcov, entropy, pdf, logpdf, logdetcov
export mean_cov, mean_var, mean_std, mean_invcov, mean_precision, weightedmean_cov, weightedmean_var, weightedmean_std, weightedmean_invcov, weightedmean_precision
export weightedmean, probvec, logmean, meanlogmean, inversemean, mirroredlogmean, loggammamean
export variate_form, value_support, promote_variate_type, convert_eltype

import Distributions: mean, median, mode, shape, scale, rate, var, std, cov, invcov, entropy, pdf, logpdf, logdetcov
import Distributions: VariateForm, ValueSupport, Distribution

import Base: prod

"""
    vague(distribution_type, [ dims... ])

`vague` function returns uninformative probability distribution of a given type and can be used to set an uninformative priors in a model.
"""
function vague end

mean_cov(something)         = (mean(something), cov(something))
mean_var(something)         = (mean(something), var(something))
mean_std(something)         = (mean(something), std(something))
mean_invcov(something)      = (mean(something), invcov(something))
mean_precision(something)   = mean_invcov(something)

weightedmean_cov(something)       = (weightedmean(something), cov(something))
weightedmean_var(something)       = (weightedmean(something), var(something))
weightedmean_std(something)       = (weightedmean(something), std(something))
weightedmean_invcov(something)    = (weightedmean(something), invcov(something))
weightedmean_precision(something) = weightedmean_invcov(something)

probvec(something)         = error("Probability vector function probvec() is not defined for $(something)")
weightedmean(something)    = error("Weighted mean is not defined for $(something)")
inversemean(something)     = error("Inverse expectation is not defined for $(something)")
logmean(something)         = error("Logarithmic expectation is not defined for $(something)")
meanlogmean(something)     = error("xlog(x) expectation is not defined for $(something)")
mirroredlogmean(something) = error("Mirrored Logarithmic expectation is not defined for $(something)")
loggammamean(something)    = error("E[logГ(x)] is not defined for $(something)")

"""
    variate_form(distribution_or_type)

Returns the `VariateForm` sub-type (defined in `Distributions.jl`):

- `Univariate`, a scalar number
- `Multivariate`, a numeric vector
- `Matrixvariate`, a numeric matrix
"""
variate_form(::Distribution{F, S})            where { F <: VariateForm, S <: ValueSupport } = F
variate_form(::Type{ <: Distribution{F, S} }) where { F <: VariateForm, S <: ValueSupport } = F

"""
    value_support(distribution_or_type)

Returns the `ValueSupport` sub-type (defined in `Distributions.jl`):

- `Discrete`, samples take discrete values
- `Continuous`, samples take continuous real values
"""
value_support(::Distribution{F, S})            where { F <: VariateForm, S <: ValueSupport } = S
value_support(::Type{ <: Distribution{F, S} }) where { F <: VariateForm, S <: ValueSupport } = S

"""
    promote_variate_type(::Type{ <: VariateForm }, distribution_type)

Promotes a `distribution_type` to be of the specified variate form (if possible)
"""
function promote_variate_type end

promote_variate_type(::D, T)         where { D <: Distribution } = promote_variate_type(variate_form(D), T)
promote_variate_type(::Type{ D }, T) where { D <: Distribution } = promote_variate_type(variate_form(D), T)

function convert_eltype end

convert_eltype(::Type{ D }, ::Type{ E }, distribution::Distribution) where { D <: Distribution, E } = convert(D{E}, distribution)

"""
    logpdf_sample_friendly(distribution)

`logpdf_sample_friendly` function takes as an input a `distribution` and returns corresponding optimized two versions
for taking `logpdf()` and sampling with `rand!` respectively. By default returns the same distribution, but some distributions
may override default behaviour for better efficiency.

# Example

```jldoctest
julia> d = vague(MvNormalMeanPrecision, 2)
MvNormalMeanPrecision(
μ: [0.0, 0.0]
Λ: [1.0e-12 0.0; 0.0 1.0e-12]
)

julia> ReactiveMP.logpdf_sample_friendly(d)
(FullNormal(
dim: 2
μ: [0.0, 0.0]
Σ: [1.0e12 -0.0; -0.0 1.0e12]
)
, FullNormal(
dim: 2
μ: [0.0, 0.0]
Σ: [1.0e12 -0.0; -0.0 1.0e12]
)
)
```
"""
logpdf_sample_friendly(something) = (something, something)


text:
@testset "logeqn" begin
    let m = Model()
        m.tol = 1e-15
        @variables m @log(X), Y
        @shocks m Ex Ey
        @parameters m rate = 1.015
        @equations m begin
            @log X[t] = rate * X[t - 1] + Ex[t]
            Y[t] = Y[t - 1] + rate + Ey[t]
        end

        @initialize m
        @steadystate m X = 1.0
        @steadystate m Y = 0.0

        clear_sstate!(m)
        sssolve!(m)
        @test m.sstate.X.level ≈ 1.0
        @test m.sstate.X.slope ≈ m.rate
        @test m.sstate.Y.level + 1 ≈ 0.0 + 1
        @test m.sstate.Y.slope + 1 ≈ m.rate + 1

        p = Plan(m, 1U:10U)

        # make sure the steadystate data is built correctly
        a = steadystatearray(m, p)
        d = steadystatedict(m, p)
        k = steadystatedata(m, p)

        @test a == k
        for s in Symbol.(m.allvars)
            @test k.:($s) == d[string(s)]
        end
        @test k.X[1U] ≈ 1.0
        @test k.Y[1U] + 1 ≈ 1.0
        @test pct(k.X, -1) ≈ TSeries(p.range, (m.rate - 1) * 100)
        @test diff(k.Y) ≈ TSeries(p.range, m.rate)

        # make sure simulations do as expected

        # this model has no final conditions (maxlag == 0)
        ed = SimData(firstdate(p), m.allvars, rand(Float64, (length(p), length(m.allvars))))
        # no shocks
        ed.Ex .= 0.0
        ed.Ey .= 0.0
        # initial
        ed[firstdate(p)] = k[firstdate(p)]

        for fc in instances(FCType)
            @test simulate(m, ed, p, fctype=fc) ≈ k
        end

    end

    let m = Model()
        m.tol = 1e-15
        @variables m @log(X), Y
        @shocks m Ex Ey
        @parameters m rate = 1.015
        @equations m begin
            @log X[t + 1] = rate * X[t] + Ex[t]
            Y[t + 1] = Y[t] + rate + Ey[t]
        end

        @initialize m
        @steadystate m X = 1.0
        @steadystate m Y = 0.0

        clear_sstate!(m)
        sssolve!(m)
        @test m.sstate.X.level + 1 ≈ 1.0 + 1
        @test m.sstate.X.slope + 1 ≈ m.rate + 1
        @test m.sstate.Y.level + 1 ≈ 0.0 + 1
        @test m.sstate.Y.slope + 1 ≈ m.rate + 1

        p = Plan(m, 1U:10U)

        # make sure the steadystate data is built correctly
        a = steadystatearray(m, p)
        d = steadystatedict(m, p)
        k = steadystatedata(m, p)

        @test a == k
        for s in Symbol.(m.allvars)
            @test k.:($s) == d[string(s)]
        end
        @test k.X[1U] + 1 ≈ 1.0 + 1
        @test k.Y[1U] + 1 ≈ 0.0 + 1
        @test pct(k.X, -1) ≈ TSeries(p.range, (m.rate - 1) * 100)
        @test diff(k.Y) ≈ TSeries(p.range, m.rate)

        # make sure simulations do as expected

        # this model has no final conditions (maxlag == 0)
        ed = SimData(firstdate(p), m.allvars, rand(Float64, (length(p), length(m.allvars))))
        # no shocks
        ed.Ex .= 0.0
        ed.Ey .= 0.0
        # Initial conditions don't matter. We set final conditions
        ed[lastdate(p)] = k[lastdate(p)]

        @test simulate(m, ed, p, fctype=fcgiven) ≈ k
        @test simulate(m, ed, p, fctype=fclevel) ≈ k

        # system is inconsistent for fcslope and fcnatural
        # we do some exo-endo juggling to get unique solution

        # we need exogenous variables somewhere
        exogenize!(p, m.variables, firstdate(p))
        # we need endogenous shocks on the last simulation period
        endogenize!(p, m.shocks, lastdate(p) - 1)

        # update exogenous data accordingly
        ed[firstdate(p)] = k[firstdate(p)]
        ed[lastdate(p),1:2] .= rand(2)

        @test simulate(m, ed, p, fctype=fcslope) ≈ k
        @test simulate(m, ed, p, fctype=fcnatural) ≈ k

    end

end