text:
int_rules_1_2_1_7 = @theory begin

    #= ::Subsection::Closed:: =#
    #= 1.2.1.7*(a+b*x+c*x^2)^p*(d+e*x+f*x^2)^q*(A+B*x+C*x^2) =#
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p') * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~(q') * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => (~c / ~f) ^ ~p * Antiderivative((~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~p + ~q) * (~A + ~B * ~x + ~C * (~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~B, ~C, ~p, ~q], ~x) && (EqQ(~c * ~d - ~a * ~f, 0) && (EqQ(~b * ~d - ~a * ~e, 0) && ((IntegerQ(~p) || GtQ(~c / ~f, 0)) && (Not(IntegerQ(~q)) || LeafCount(~d + ~e * ~x + ~f * (~x) ^ 2) <= LeafCount(~a + ~b * ~x + ~c * (~x) ^ 2)))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p') * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~(q') * (~(A') + ~(C') * (~x) ^ 2), ~x) => (~c / ~f) ^ ~p * Antiderivative((~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~p + ~q) * (~A + ~C * (~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~C, ~p, ~q], ~x) && (EqQ(~c * ~d - ~a * ~f, 0) && (EqQ(~b * ~d - ~a * ~e, 0) && ((IntegerQ(~p) || GtQ(~c / ~f, 0)) && (Not(IntegerQ(~q)) || LeafCount(~d + ~e * ~x + ~f * (~x) ^ 2) <= LeafCount(~a + ~b * ~x + ~c * (~x) ^ 2)))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p') * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~(q') * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => (((~a) ^ IntPart(~p) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ FracPart(~p)) / ((~d) ^ IntPart(~p) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ FracPart(~p))) * Antiderivative((~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~p + ~q) * (~A + ~B * ~x + ~C * (~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~B, ~C, ~p, ~q], ~x) && (EqQ(~c * ~d - ~a * ~f, 0) && (EqQ(~b * ~d - ~a * ~e, 0) && (Not(IntegerQ(~p)) && (Not(IntegerQ(~q)) && Not(GtQ(~c / ~f, 0))))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p') * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~(q') * (~(A') + ~(C') * (~x) ^ 2), ~x) => (((~a) ^ IntPart(~p) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ FracPart(~p)) / ((~d) ^ IntPart(~p) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ FracPart(~p))) * Antiderivative((~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~p + ~q) * (~A + ~C * (~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~C, ~p, ~q], ~x) && (EqQ(~c * ~d - ~a * ~f, 0) && (EqQ(~b * ~d - ~a * ~e, 0) && (Not(IntegerQ(~p)) && (Not(IntegerQ(~q)) && Not(GtQ(~c / ~f, 0))))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p') * (~(d') + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~(q') * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => ((~a + ~b * ~x + ~c * (~x) ^ 2) ^ FracPart(~p) / ((4 * ~c) ^ IntPart(~p) * (~b + 2 * ~c * ~x) ^ (2 * FracPart(~p)))) * Antiderivative((~b + 2 * ~c * ~x) ^ (2 * ~p) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * (~A + ~B * ~x + ~C * (~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~B, ~C, ~p, ~q], ~x) && EqQ((~b) ^ 2 - 4 * ~a * ~c, 0)
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p') * (~(d') + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~(q') * (~(A') + ~(C') * (~x) ^ 2), ~x) => ((~a + ~b * ~x + ~c * (~x) ^ 2) ^ FracPart(~p) / ((4 * ~c) ^ IntPart(~p) * (~b + 2 * ~c * ~x) ^ (2 * FracPart(~p)))) * Antiderivative((~b + 2 * ~c * ~x) ^ (2 * ~p) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * (~A + ~C * (~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~C, ~p, ~q], ~x) && EqQ((~b) ^ 2 - 4 * ~a * ~c, 0)
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p') * (~(d') + ~(f') * (~x) ^ 2) ^ ~(q') * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => ((~a + ~b * ~x + ~c * (~x) ^ 2) ^ FracPart(~p) / ((4 * ~c) ^ IntPart(~p) * (~b + 2 * ~c * ~x) ^ (2 * FracPart(~p)))) * Antiderivative((~b + 2 * ~c * ~x) ^ (2 * ~p) * (~d + ~f * (~x) ^ 2) ^ ~q * (~A + ~B * ~x + ~C * (~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~f, ~A, ~B, ~C, ~p, ~q], ~x) && EqQ((~b) ^ 2 - 4 * ~a * ~c, 0)
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p') * (~(d') + ~(f') * (~x) ^ 2) ^ ~(q') * (~(A') + ~(C') * (~x) ^ 2), ~x) => ((~a + ~b * ~x + ~c * (~x) ^ 2) ^ FracPart(~p) / ((4 * ~c) ^ IntPart(~p) * (~b + 2 * ~c * ~x) ^ (2 * FracPart(~p)))) * Antiderivative((~b + 2 * ~c * ~x) ^ (2 * ~p) * (~d + ~f * (~x) ^ 2) ^ ~q * (~A + ~C * (~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~f, ~A, ~C, ~p, ~q], ~x) && EqQ((~b) ^ 2 - 4 * ~a * ~c, 0)
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => ((((~A * ~b * ~c - 2 * ~a * ~B * ~c) + ~a * ~b * ~C) - (~c * (~b * ~B - 2 * ~A * ~c) - ~C * ((~b) ^ 2 - 2 * ~a * ~c)) * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q) / (~c * ((~b) ^ 2 - 4 * ~a * ~c) * (~p + 1)) - (1 / (~c * ((~b) ^ 2 - 4 * ~a * ~c) * (~p + 1))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~q - 1) * Simp(((~e * ~q * ((~A * ~b * ~c - 2 * ~a * ~B * ~c) + ~a * ~b * ~C) - ~d * (~c * (~b * ~B - 2 * ~A * ~c) * (2 * ~p + 3) + ~C * (2 * ~a * ~c - (~b) ^ 2 * (~p + 2)))) + (2 * ~f * ~q * ((~A * ~b * ~c - 2 * ~a * ~B * ~c) + ~a * ~b * ~C) - ~e * (~c * (~b * ~B - 2 * ~A * ~c) * (2 * ~p + ~q + 3) + ~C * (2 * ~a * ~c * (~q + 1) - (~b) ^ 2 * (~p + ~q + 2)))) * ~x) - ~f * (~c * (~b * ~B - 2 * ~A * ~c) * (2 * ~p + 2 * ~q + 3) + ~C * (2 * ~a * ~c * (2 * ~q + 1) - (~b) ^ 2 * (~p + 2 * ~q + 2))) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~B, ~C], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~e) ^ 2 - 4 * ~d * ~f, 0) && (LtQ(~p, -1) && (GtQ(~q, 0) && Not(IGtQ(~q, 0))))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(C') * (~x) ^ 2), ~x) => ((~A * ~b * ~c + ~a * ~b * ~C + (2 * ~A * (~c) ^ 2 + ~C * ((~b) ^ 2 - 2 * ~a * ~c)) * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q) / (~c * ((~b) ^ 2 - 4 * ~a * ~c) * (~p + 1)) - (1 / (~c * ((~b) ^ 2 - 4 * ~a * ~c) * (~p + 1))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~q - 1) * Simp(((~A * ~c * (2 * ~c * ~d * (2 * ~p + 3) + ~b * ~e * ~q) - ~C * ((2 * ~a * ~c * ~d - (~b) ^ 2 * ~d * (~p + 2)) - ~a * ~b * ~e * ~q)) + (~C * ((2 * ~a * ~b * ~f * ~q - 2 * ~a * ~c * ~e * (~q + 1)) + (~b) ^ 2 * ~e * (~p + ~q + 2)) + 2 * ~A * ~c * (~b * ~f * ~q + ~c * ~e * (2 * ~p + ~q + 3))) * ~x) - ~f * (-2 * ~A * (~c) ^ 2 * (2 * ~p + 2 * ~q + 3) + ~C * (2 * ~a * ~c * (2 * ~q + 1) - (~b) ^ 2 * (~p + 2 * ~q + 2))) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~C], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~e) ^ 2 - 4 * ~d * ~f, 0) && (LtQ(~p, -1) && (GtQ(~q, 0) && Not(IGtQ(~q, 0))))))
    @apply_utils Antiderivative((~a + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => ((~a * ~B - (~A * ~c - ~a * ~C) * ~x) * (~a + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q) / (2 * ~a * ~c * (~p + 1)) - (2 / ((-4 * ~a * ~c) * (~p + 1))) * Antiderivative((~a + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~q - 1) * Simp(((~A * ~c * ~d * (2 * ~p + 3) - ~a * (~C * ~d + ~B * ~e * ~q)) + (~A * ~c * ~e * (2 * ~p + ~q + 3) - ~a * (2 * ~B * ~f * ~q + ~C * ~e * (~q + 1))) * ~x) - ~f * (~a * ~C * (2 * ~q + 1) - ~A * ~c * (2 * ~p + 2 * ~q + 3)) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~A, ~B, ~C], ~x) && (NeQ((~e) ^ 2 - 4 * ~d * ~f, 0) && (LtQ(~p, -1) && (GtQ(~q, 0) && Not(IGtQ(~q, 0)))))
    @apply_utils Antiderivative((~a + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(C') * (~x) ^ 2), ~x) => (-((~A * ~c - ~a * ~C)) * ~x * (~a + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q) / (2 * ~a * ~c * (~p + 1)) + (2 / (4 * ~a * ~c * (~p + 1))) * Antiderivative((~a + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~q - 1) * Simp(((~A * ~c * ~d * (2 * ~p + 3) - ~a * ~C * ~d) + (~A * ~c * ~e * (2 * ~p + ~q + 3) - ~a * ~C * ~e * (~q + 1)) * ~x) - ~f * (~a * ~C * (2 * ~q + 1) - ~A * ~c * (2 * ~p + 2 * ~q + 3)) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~A, ~C], ~x) && (NeQ((~e) ^ 2 - 4 * ~d * ~f, 0) && (LtQ(~p, -1) && (GtQ(~q, 0) && Not(IGtQ(~q, 0)))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => ((((~A * ~b * ~c - 2 * ~a * ~B * ~c) + ~a * ~b * ~C) - (~c * (~b * ~B - 2 * ~A * ~c) - ~C * ((~b) ^ 2 - 2 * ~a * ~c)) * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~f * (~x) ^ 2) ^ ~q) / (~c * ((~b) ^ 2 - 4 * ~a * ~c) * (~p + 1)) - (1 / (~c * ((~b) ^ 2 - 4 * ~a * ~c) * (~p + 1))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~f * (~x) ^ 2) ^ (~q - 1) * Simp((-(~d) * (~c * (~b * ~B - 2 * ~A * ~c) * (2 * ~p + 3) + ~C * (2 * ~a * ~c - (~b) ^ 2 * (~p + 2))) + (2 * ~f * ~q * ((~A * ~b * ~c - 2 * ~a * ~B * ~c) + ~a * ~b * ~C)) * ~x) - ~f * (~c * (~b * ~B - 2 * ~A * ~c) * (2 * ~p + 2 * ~q + 3) + ~C * (2 * ~a * ~c * (2 * ~q + 1) - (~b) ^ 2 * (~p + 2 * ~q + 2))) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~f, ~A, ~B, ~C], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (LtQ(~p, -1) && (GtQ(~q, 0) && Not(IGtQ(~q, 0)))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(C') * (~x) ^ 2), ~x) => ((~A * ~b * ~c + ~a * ~b * ~C + (2 * ~A * (~c) ^ 2 + ~C * ((~b) ^ 2 - 2 * ~a * ~c)) * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~f * (~x) ^ 2) ^ ~q) / (~c * ((~b) ^ 2 - 4 * ~a * ~c) * (~p + 1)) - (1 / (~c * ((~b) ^ 2 - 4 * ~a * ~c) * (~p + 1))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~f * (~x) ^ 2) ^ (~q - 1) * Simp(((~A * ~c * (2 * ~c * ~d * (2 * ~p + 3)) - ~C * (2 * ~a * ~c * ~d - (~b) ^ 2 * ~d * (~p + 2))) + (~C * (2 * ~a * ~b * ~f * ~q) + 2 * ~A * ~c * (~b * ~f * ~q)) * ~x) - ~f * (-2 * ~A * (~c) ^ 2 * (2 * ~p + 2 * ~q + 3) + ~C * (2 * ~a * ~c * (2 * ~q + 1) - (~b) ^ 2 * (~p + 2 * ~q + 2))) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~f, ~A, ~C], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (LtQ(~p, -1) && (GtQ(~q, 0) && Not(IGtQ(~q, 0)))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => (((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~q + 1)) / (((~b) ^ 2 - 4 * ~a * ~c) * ((~c * ~d - ~a * ~f) ^ 2 - (~b * ~d - ~a * ~e) * (~c * ~e - ~b * ~f)) * (~p + 1))) * ((~A * ~c - ~a * ~C) * (2 * ~a * ~c * ~e - ~b * (~c * ~d + ~a * ~f)) + (~A * ~b - ~a * ~B) * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (~b * ~e + 2 * ~a * ~f)) + ~c * ((~A * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (~b * ~e + 2 * ~a * ~f)) - ~B * ((~b * ~c * ~d - 2 * ~a * ~c * ~e) + ~a * ~b * ~f)) + ~C * (((~b) ^ 2 * ~d - ~a * ~b * ~e) - 2 * ~a * (~c * ~d - ~a * ~f))) * ~x) + (1 / (((~b) ^ 2 - 4 * ~a * ~c) * ((~c * ~d - ~a * ~f) ^ 2 - (~b * ~d - ~a * ~e) * (~c * ~e - ~b * ~f)) * (~p + 1))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * Simp((((((~b * ~B - 2 * ~A * ~c) - 2 * ~a * ~C) * ((~c * ~d - ~a * ~f) ^ 2 - (~b * ~d - ~a * ~e) * (~c * ~e - ~b * ~f)) * (~p + 1) + (((~b) ^ 2 * (~C * ~d + ~A * ~f) - ~b * (~B * ~c * ~d + ~A * ~c * ~e + ~a * ~C * ~e + ~a * ~B * ~f)) + 2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * ((~c * ~C * ~d - ~B * ~c * ~e) - ~a * ~C * ~f))) * (~a * ~f * (~p + 1) - ~c * ~d * (~p + 2))) - ~e * ((~A * ~c - ~a * ~C) * (2 * ~a * ~c * ~e - ~b * (~c * ~d + ~a * ~f)) + (~A * ~b - ~a * ~B) * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (~b * ~e + 2 * ~a * ~f))) * (~p + ~q + 2)) - (2 * ~f * ((~A * ~c - ~a * ~C) * (2 * ~a * ~c * ~e - ~b * (~c * ~d + ~a * ~f)) + (~A * ~b - ~a * ~B) * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (~b * ~e + 2 * ~a * ~f))) * (~p + ~q + 2) - (((~b) ^ 2 * (~C * ~d + ~A * ~f) - ~b * (~B * ~c * ~d + ~A * ~c * ~e + ~a * ~C * ~e + ~a * ~B * ~f)) + 2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * ((~c * ~C * ~d - ~B * ~c * ~e) - ~a * ~C * ~f))) * (~b * ~f * (~p + 1) - ~c * ~e * (2 * ~p + ~q + 4))) * ~x) - ~c * ~f * (((~b) ^ 2 * (~C * ~d + ~A * ~f) - ~b * (~B * ~c * ~d + ~A * ~c * ~e + ~a * ~C * ~e + ~a * ~B * ~f)) + 2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * ((~c * ~C * ~d - ~B * ~c * ~e) - ~a * ~C * ~f))) * (2 * ~p + 2 * ~q + 5) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~B, ~C, ~q], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~e) ^ 2 - 4 * ~d * ~f, 0) && (LtQ(~p, -1) && (NeQ((~c * ~d - ~a * ~f) ^ 2 - (~b * ~d - ~a * ~e) * (~c * ~e - ~b * ~f), 0) && (Not(Not(IntegerQ(~p)) && ILtQ(~q, -1)) && Not(IGtQ(~q, 0)))))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(C') * (~x) ^ 2), ~x) => (((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~q + 1)) / (((~b) ^ 2 - 4 * ~a * ~c) * ((~c * ~d - ~a * ~f) ^ 2 - (~b * ~d - ~a * ~e) * (~c * ~e - ~b * ~f)) * (~p + 1))) * ((~A * ~c - ~a * ~C) * (2 * ~a * ~c * ~e - ~b * (~c * ~d + ~a * ~f)) + (~A * ~b) * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (~b * ~e + 2 * ~a * ~f)) + ~c * (~A * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (~b * ~e + 2 * ~a * ~f)) + ~C * (((~b) ^ 2 * ~d - ~a * ~b * ~e) - 2 * ~a * (~c * ~d - ~a * ~f))) * ~x) + (1 / (((~b) ^ 2 - 4 * ~a * ~c) * ((~c * ~d - ~a * ~f) ^ 2 - (~b * ~d - ~a * ~e) * (~c * ~e - ~b * ~f)) * (~p + 1))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * Simp(((((-2 * ~A * ~c - 2 * ~a * ~C) * ((~c * ~d - ~a * ~f) ^ 2 - (~b * ~d - ~a * ~e) * (~c * ~e - ~b * ~f)) * (~p + 1) + (((~b) ^ 2 * (~C * ~d + ~A * ~f) - ~b * (+(~A) * ~c * ~e + ~a * ~C * ~e)) + 2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * (~c * ~C * ~d - ~a * ~C * ~f))) * (~a * ~f * (~p + 1) - ~c * ~d * (~p + 2))) - ~e * ((~A * ~c - ~a * ~C) * (2 * ~a * ~c * ~e - ~b * (~c * ~d + ~a * ~f)) + (~A * ~b) * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (~b * ~e + 2 * ~a * ~f))) * (~p + ~q + 2)) - (2 * ~f * ((~A * ~c - ~a * ~C) * (2 * ~a * ~c * ~e - ~b * (~c * ~d + ~a * ~f)) + (~A * ~b) * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (~b * ~e + 2 * ~a * ~f))) * (~p + ~q + 2) - (((~b) ^ 2 * (~C * ~d + ~A * ~f) - ~b * (~A * ~c * ~e + ~a * ~C * ~e)) + 2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * (~c * ~C * ~d - ~a * ~C * ~f))) * (~b * ~f * (~p + 1) - ~c * ~e * (2 * ~p + ~q + 4))) * ~x) - ~c * ~f * (((~b) ^ 2 * (~C * ~d + ~A * ~f) - ~b * (~A * ~c * ~e + ~a * ~C * ~e)) + 2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * (~c * ~C * ~d - ~a * ~C * ~f))) * (2 * ~p + 2 * ~q + 5) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~C, ~q], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~e) ^ 2 - 4 * ~d * ~f, 0) && (LtQ(~p, -1) && (NeQ((~c * ~d - ~a * ~f) ^ 2 - (~b * ~d - ~a * ~e) * (~c * ~e - ~b * ~f), 0) && (Not(Not(IntegerQ(~p)) && ILtQ(~q, -1)) && Not(IGtQ(~q, 0)))))))
    @apply_utils Antiderivative((~a + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => (((~a + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~q + 1)) / ((-4 * ~a * ~c) * (~a * ~c * (~e) ^ 2 + (~c * ~d - ~a * ~f) ^ 2) * (~p + 1))) * ((~A * ~c - ~a * ~C) * (2 * ~a * ~c * ~e) + (-(~a) * ~B) * (2 * (~c) ^ 2 * ~d - ~c * (2 * ~a * ~f)) + ~c * ((~A * (2 * (~c) ^ 2 * ~d - ~c * (2 * ~a * ~f)) - ~B * (-2 * ~a * ~c * ~e)) + ~C * (-2 * ~a * (~c * ~d - ~a * ~f))) * ~x) + (1 / ((-4 * ~a * ~c) * (~a * ~c * (~e) ^ 2 + (~c * ~d - ~a * ~f) ^ 2) * (~p + 1))) * Antiderivative((~a + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * Simp(((((-2 * ~A * ~c - 2 * ~a * ~C) * ((~c * ~d - ~a * ~f) ^ 2 - (-(~a) * ~e) * (~c * ~e)) * (~p + 1) + (2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * ((~c * ~C * ~d - ~B * ~c * ~e) - ~a * ~C * ~f))) * (~a * ~f * (~p + 1) - ~c * ~d * (~p + 2))) - ~e * ((~A * ~c - ~a * ~C) * (2 * ~a * ~c * ~e) + (-(~a) * ~B) * (2 * (~c) ^ 2 * ~d - ~c * (2 * ~a * ~f))) * (~p + ~q + 2)) - (2 * ~f * ((~A * ~c - ~a * ~C) * (2 * ~a * ~c * ~e) + (-(~a) * ~B) * (2 * (~c) ^ 2 * ~d + -(~c) * (2 * ~a * ~f))) * (~p + ~q + 2) - (2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * ((~c * ~C * ~d - ~B * ~c * ~e) - ~a * ~C * ~f))) * (-(~c) * ~e * (2 * ~p + ~q + 4))) * ~x) - ~c * ~f * (2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * ((~c * ~C * ~d - ~B * ~c * ~e) - ~a * ~C * ~f))) * (2 * ~p + 2 * ~q + 5) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~A, ~B, ~C, ~q], ~x) && (NeQ((~e) ^ 2 - 4 * ~d * ~f, 0) && (LtQ(~p, -1) && (NeQ(~a * ~c * (~e) ^ 2 + (~c * ~d - ~a * ~f) ^ 2, 0) && (Not(Not(IntegerQ(~p)) && ILtQ(~q, -1)) && Not(IGtQ(~q, 0))))))
    @apply_utils Antiderivative((~a + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(C') * (~x) ^ 2), ~x) => (((~a + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~q + 1)) / ((-4 * ~a * ~c) * (~a * ~c * (~e) ^ 2 + (~c * ~d - ~a * ~f) ^ 2) * (~p + 1))) * ((~A * ~c - ~a * ~C) * (2 * ~a * ~c * ~e) + ~c * (~A * (2 * (~c) ^ 2 * ~d - ~c * (2 * ~a * ~f)) + ~C * (-2 * ~a * (~c * ~d - ~a * ~f))) * ~x) + (1 / ((-4 * ~a * ~c) * (~a * ~c * (~e) ^ 2 + (~c * ~d - ~a * ~f) ^ 2) * (~p + 1))) * Antiderivative((~a + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * Simp(((((-2 * ~A * ~c - 2 * ~a * ~C) * ((~c * ~d - ~a * ~f) ^ 2 - (-(~a) * ~e) * (~c * ~e)) * (~p + 1) + (2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * (~c * ~C * ~d - ~a * ~C * ~f))) * (~a * ~f * (~p + 1) - ~c * ~d * (~p + 2))) - ~e * ((~A * ~c - ~a * ~C) * (2 * ~a * ~c * ~e)) * (~p + ~q + 2)) - (2 * ~f * ((~A * ~c - ~a * ~C) * (2 * ~a * ~c * ~e)) * (~p + ~q + 2) - (2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * (~c * ~C * ~d - ~a * ~C * ~f))) * (-(~c) * ~e * (2 * ~p + ~q + 4))) * ~x) - ~c * ~f * (2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * (~c * ~C * ~d - ~a * ~C * ~f))) * (2 * ~p + 2 * ~q + 5) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~A, ~C, ~q], ~x) && (NeQ((~e) ^ 2 - 4 * ~d * ~f, 0) && (LtQ(~p, -1) && (NeQ(~a * ~c * (~e) ^ 2 + (~c * ~d - ~a * ~f) ^ 2, 0) && (Not(Not(IntegerQ(~p)) && ILtQ(~q, -1)) && Not(IGtQ(~q, 0))))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => (((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~f * (~x) ^ 2) ^ (~q + 1)) / (((~b) ^ 2 - 4 * ~a * ~c) * ((~b) ^ 2 * ~d * ~f + (~c * ~d - ~a * ~f) ^ 2) * (~p + 1))) * ((~A * ~c - ~a * ~C) * (-(~b) * (~c * ~d + ~a * ~f)) + (~A * ~b - ~a * ~B) * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (2 * ~a * ~f)) + ~c * ((~A * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (2 * ~a * ~f)) - ~B * (~b * ~c * ~d + ~a * ~b * ~f)) + ~C * ((~b) ^ 2 * ~d - 2 * ~a * (~c * ~d - ~a * ~f))) * ~x) + (1 / (((~b) ^ 2 - 4 * ~a * ~c) * ((~b) ^ 2 * ~d * ~f + (~c * ~d - ~a * ~f) ^ 2) * (~p + 1))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~f * (~x) ^ 2) ^ ~q * Simp(((((~b * ~B - 2 * ~A * ~c) - 2 * ~a * ~C) * ((~c * ~d - ~a * ~f) ^ 2 - (~b * ~d) * (-(~b) * ~f)) * (~p + 1) + (((~b) ^ 2 * (~C * ~d + ~A * ~f) - ~b * (~B * ~c * ~d + ~a * ~B * ~f)) + 2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * (~c * ~C * ~d - ~a * ~C * ~f))) * (~a * ~f * (~p + 1) - ~c * ~d * (~p + 2))) - (2 * ~f * ((~A * ~c - ~a * ~C) * (-(~b) * (~c * ~d + ~a * ~f)) + (~A * ~b - ~a * ~B) * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (2 * ~a * ~f))) * (~p + ~q + 2) - (((~b) ^ 2 * (~C * ~d + ~A * ~f) - ~b * (~B * ~c * ~d + ~a * ~B * ~f)) + 2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * (~c * ~C * ~d - ~a * ~C * ~f))) * (~b * ~f * (~p + 1))) * ~x) - ~c * ~f * (((~b) ^ 2 * (~C * ~d + ~A * ~f) - ~b * (~B * ~c * ~d + ~a * ~B * ~f)) + 2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * (~c * ~C * ~d - ~a * ~C * ~f))) * (2 * ~p + 2 * ~q + 5) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~f, ~A, ~B, ~C, ~q], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (LtQ(~p, -1) && (NeQ((~b) ^ 2 * ~d * ~f + (~c * ~d - ~a * ~f) ^ 2, 0) && (Not(Not(IntegerQ(~p)) && ILtQ(~q, -1)) && Not(IGtQ(~q, 0))))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(C') * (~x) ^ 2), ~x) => (((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~f * (~x) ^ 2) ^ (~q + 1)) / (((~b) ^ 2 - 4 * ~a * ~c) * ((~b) ^ 2 * ~d * ~f + (~c * ~d - ~a * ~f) ^ 2) * (~p + 1))) * ((~A * ~c - ~a * ~C) * (-(~b) * (~c * ~d + ~a * ~f)) + (~A * ~b) * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (2 * ~a * ~f)) + ~c * (~A * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (2 * ~a * ~f)) + ~C * ((~b) ^ 2 * ~d - 2 * ~a * (~c * ~d - ~a * ~f))) * ~x) + (1 / (((~b) ^ 2 - 4 * ~a * ~c) * ((~b) ^ 2 * ~d * ~f + (~c * ~d - ~a * ~f) ^ 2) * (~p + 1))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * (~d + ~f * (~x) ^ 2) ^ ~q * Simp((((-2 * ~A * ~c - 2 * ~a * ~C) * ((~c * ~d - ~a * ~f) ^ 2 - (~b * ~d) * (-(~b) * ~f)) * (~p + 1) + ((~b) ^ 2 * (~C * ~d + ~A * ~f) + 2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * (~c * ~C * ~d - ~a * ~C * ~f))) * (~a * ~f * (~p + 1) - ~c * ~d * (~p + 2))) - (2 * ~f * ((~A * ~c - ~a * ~C) * (-(~b) * (~c * ~d + ~a * ~f)) + (~A * ~b) * ((2 * (~c) ^ 2 * ~d + (~b) ^ 2 * ~f) - ~c * (2 * ~a * ~f))) * (~p + ~q + 2) - ((~b) ^ 2 * (~C * ~d + ~A * ~f) + 2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * (~c * ~C * ~d - ~a * ~C * ~f))) * (~b * ~f * (~p + 1))) * ~x) - ~c * ~f * ((~b) ^ 2 * (~C * ~d + ~A * ~f) + 2 * (~A * ~c * (~c * ~d - ~a * ~f) - ~a * (~c * ~C * ~d - ~a * ~C * ~f))) * (2 * ~p + 2 * ~q + 5) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~f, ~A, ~C, ~q], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (LtQ(~p, -1) && (NeQ((~b) ^ 2 * ~d * ~f + (~c * ~d - ~a * ~f) ^ 2, 0) && (Not(Not(IntegerQ(~p)) && ILtQ(~q, -1)) && Not(IGtQ(~q, 0))))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => ((~B * ~c * ~f * (2 * ~p + 2 * ~q + 3) + ~C * (~b * ~f * ~p - ~c * ~e * (2 * ~p + ~q + 2)) + 2 * ~c * ~C * ~f * (~p + ~q + 1) * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~q + 1)) / (2 * ~c * (~f) ^ 2 * (~p + ~q + 1) * (2 * ~p + 2 * ~q + 3)) - (1 / (2 * ~c * (~f) ^ 2 * (~p + ~q + 1) * (2 * ~p + 2 * ~q + 3))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p - 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * Simp(~p * (~b * ~d - ~a * ~e) * (~C * (~c * ~e - ~b * ~f) * (~q + 1) - ~c * (~C * ~e - ~B * ~f) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * ((~b) ^ 2 * ~C * ~d * ~f * ~p + ~a * ~c * (~C * (2 * ~d * ~f - (~e) ^ 2 * (2 * ~p + ~q + 2)) + ~f * (~B * ~e - 2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3))) + (2 * ~p * (~c * ~d - ~a * ~f) * (~C * (~c * ~e - ~b * ~f) * (~q + 1) - ~c * (~C * ~e - ~B * ~f) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * (~C * ~e * ~f * ~p * ((~b) ^ 2 - 4 * ~a * ~c) - ~b * ~c * (~C * ((~e) ^ 2 - 4 * ~d * ~f) * (2 * ~p + ~q + 2) + ~f * ((2 * ~C * ~d - ~B * ~e) + 2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3)))) * ~x + (~p * (~c * ~e - ~b * ~f) * (~C * (~c * ~e - ~b * ~f) * (~q + 1) - ~c * (~C * ~e - ~B * ~f) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * (~C * (~f) ^ 2 * ~p * ((~b) ^ 2 - 4 * ~a * ~c) - (~c) ^ 2 * (~C * ((~e) ^ 2 - 4 * ~d * ~f) * (2 * ~p + ~q + 2) + ~f * ((2 * ~C * ~d - ~B * ~e) + 2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3)))) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~B, ~C, ~q], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~e) ^ 2 - 4 * ~d * ~f, 0) && (GtQ(~p, 0) && (NeQ(~p + ~q + 1, 0) && (NeQ(2 * ~p + 2 * ~q + 3, 0) && (Not(IGtQ(~p, 0)) && Not(IGtQ(~q, 0))))))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(C') * (~x) ^ 2), ~x) => ((~C * (~b * ~f * ~p - ~c * ~e * (2 * ~p + ~q + 2)) + 2 * ~c * ~C * ~f * (~p + ~q + 1) * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~q + 1)) / (2 * ~c * (~f) ^ 2 * (~p + ~q + 1) * (2 * ~p + 2 * ~q + 3)) - (1 / (2 * ~c * (~f) ^ 2 * (~p + ~q + 1) * (2 * ~p + 2 * ~q + 3))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p - 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * Simp(~p * (~b * ~d - ~a * ~e) * (~C * (~c * ~e - ~b * ~f) * (~q + 1) - ~c * (~C * ~e) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * ((~b) ^ 2 * ~C * ~d * ~f * ~p + ~a * ~c * (~C * (2 * ~d * ~f - (~e) ^ 2 * (2 * ~p + ~q + 2)) + ~f * (-2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3))) + (2 * ~p * (~c * ~d - ~a * ~f) * (~C * (~c * ~e - ~b * ~f) * (~q + 1) - ~c * (~C * ~e) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * (~C * ~e * ~f * ~p * ((~b) ^ 2 - 4 * ~a * ~c) - ~b * ~c * (~C * ((~e) ^ 2 - 4 * ~d * ~f) * (2 * ~p + ~q + 2) + ~f * (2 * ~C * ~d + 2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3)))) * ~x + (~p * (~c * ~e - ~b * ~f) * (~C * (~c * ~e - ~b * ~f) * (~q + 1) - ~c * (~C * ~e) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * (~C * (~f) ^ 2 * ~p * ((~b) ^ 2 - 4 * ~a * ~c) - (~c) ^ 2 * (~C * ((~e) ^ 2 - 4 * ~d * ~f) * (2 * ~p + ~q + 2) + ~f * (2 * ~C * ~d + 2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3)))) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~C, ~q], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~e) ^ 2 - 4 * ~d * ~f, 0) && (GtQ(~p, 0) && (NeQ(~p + ~q + 1, 0) && (NeQ(2 * ~p + 2 * ~q + 3, 0) && (Not(IGtQ(~p, 0)) && Not(IGtQ(~q, 0))))))))
    @apply_utils Antiderivative((~a + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => ((~B * ~c * ~f * (2 * ~p + 2 * ~q + 3) + ~C * (-(~c) * ~e * (2 * ~p + ~q + 2)) + 2 * ~c * ~C * ~f * (~p + ~q + 1) * ~x) * (~a + ~c * (~x) ^ 2) ^ ~p * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~q + 1)) / (2 * ~c * (~f) ^ 2 * (~p + ~q + 1) * (2 * ~p + 2 * ~q + 3)) - (1 / (2 * ~c * (~f) ^ 2 * (~p + ~q + 1) * (2 * ~p + 2 * ~q + 3))) * Antiderivative((~a + ~c * (~x) ^ 2) ^ (~p - 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * Simp(~p * (-(~a) * ~e) * (~C * (~c * ~e) * (~q + 1) - ~c * (~C * ~e - ~B * ~f) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * (~a * ~c * (~C * (2 * ~d * ~f - (~e) ^ 2 * (2 * ~p + ~q + 2)) + ~f * (~B * ~e - 2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3))) + (2 * ~p * (~c * ~d - ~a * ~f) * (~C * (~c * ~e) * (~q + 1) - ~c * (~C * ~e - ~B * ~f) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * (~C * ~e * ~f * ~p * (-4 * ~a * ~c))) * ~x + (~p * (~c * ~e) * (~C * (~c * ~e) * (~q + 1) - ~c * (~C * ~e - ~B * ~f) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * (~C * (~f) ^ 2 * ~p * (-4 * ~a * ~c) - (~c) ^ 2 * (~C * ((~e) ^ 2 - 4 * ~d * ~f) * (2 * ~p + ~q + 2) + ~f * ((2 * ~C * ~d - ~B * ~e) + 2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3)))) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~A, ~B, ~C, ~q], ~x) && (NeQ((~e) ^ 2 - 4 * ~d * ~f, 0) && (GtQ(~p, 0) && (NeQ(~p + ~q + 1, 0) && (NeQ(2 * ~p + 2 * ~q + 3, 0) && (Not(IGtQ(~p, 0)) && Not(IGtQ(~q, 0)))))))
    @apply_utils Antiderivative((~a + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(C') * (~x) ^ 2), ~x) => ((~C * (-(~c) * ~e * (2 * ~p + ~q + 2)) + 2 * ~c * ~C * ~f * (~p + ~q + 1) * ~x) * (~a + ~c * (~x) ^ 2) ^ ~p * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ (~q + 1)) / (2 * ~c * (~f) ^ 2 * (~p + ~q + 1) * (2 * ~p + 2 * ~q + 3)) - (1 / (2 * ~c * (~f) ^ 2 * (~p + ~q + 1) * (2 * ~p + 2 * ~q + 3))) * Antiderivative((~a + ~c * (~x) ^ 2) ^ (~p - 1) * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * Simp(~p * (-(~a) * ~e) * (~C * (~c * ~e) * (~q + 1) - ~c * (~C * ~e) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * (~a * ~c * (~C * (2 * ~d * ~f - (~e) ^ 2 * (2 * ~p + ~q + 2)) + ~f * (-2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3))) + (2 * ~p * (~c * ~d - ~a * ~f) * (~C * (~c * ~e) * (~q + 1) - ~c * (~C * ~e) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * (~C * ~e * ~f * ~p * (-4 * ~a * ~c))) * ~x + (~p * (~c * ~e) * (~C * (~c * ~e) * (~q + 1) - ~c * (~C * ~e) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * (~C * (~f) ^ 2 * ~p * (-4 * ~a * ~c) - (~c) ^ 2 * (~C * ((~e) ^ 2 - 4 * ~d * ~f) * (2 * ~p + ~q + 2) + ~f * (2 * ~C * ~d + 2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3)))) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~A, ~C, ~q], ~x) && (NeQ((~e) ^ 2 - 4 * ~d * ~f, 0) && (GtQ(~p, 0) && (NeQ(~p + ~q + 1, 0) && (NeQ(2 * ~p + 2 * ~q + 3, 0) && (Not(IGtQ(~p, 0)) && Not(IGtQ(~q, 0)))))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2), ~x) => ((~B * ~c * ~f * (2 * ~p + 2 * ~q + 3) + ~C * (~b * ~f * ~p) + 2 * ~c * ~C * ~f * (~p + ~q + 1) * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p * (~d + ~f * (~x) ^ 2) ^ (~q + 1)) / (2 * ~c * (~f) ^ 2 * (~p + ~q + 1) * (2 * ~p + 2 * ~q + 3)) - (1 / (2 * ~c * (~f) ^ 2 * (~p + ~q + 1) * (2 * ~p + 2 * ~q + 3))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p - 1) * (~d + ~f * (~x) ^ 2) ^ ~q * Simp(~p * (~b * ~d) * (~C * (-(~b) * ~f) * (~q + 1) - ~c * (-(~B) * ~f) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * ((~b) ^ 2 * ~C * ~d * ~f * ~p + ~a * ~c * (~C * (2 * ~d * ~f) + ~f * (-2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3))) + (2 * ~p * (~c * ~d - ~a * ~f) * (~C * (-(~b) * ~f) * (~q + 1) - ~c * (-(~B) * ~f) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * (-(~b) * ~c * (~C * (-4 * ~d * ~f) * (2 * ~p + ~q + 2) + ~f * (2 * ~C * ~d + 2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3)))) * ~x + (~p * (-(~b) * ~f) * (~C * (-(~b) * ~f) * (~q + 1) - ~c * (-(~B) * ~f) * (2 * ~p + 2 * ~q + 3)) + (~p + ~q + 1) * (~C * (~f) ^ 2 * ~p * ((~b) ^ 2 - 4 * ~a * ~c) - (~c) ^ 2 * (~C * (-4 * ~d * ~f) * (2 * ~p + ~q + 2) + ~f * (2 * ~C * ~d + 2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3)))) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~f, ~A, ~B, ~C, ~q], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (GtQ(~p, 0) && (NeQ(~p + ~q + 1, 0) && (NeQ(2 * ~p + 2 * ~q + 3, 0) && (Not(IGtQ(~p, 0)) && Not(IGtQ(~q, 0)))))))
    @apply_utils Antiderivative((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p * (~d + ~(f') * (~x) ^ 2) ^ ~q * (~(A') + ~(C') * (~x) ^ 2), ~x) => ((~C * (~b * ~f * ~p) + 2 * ~c * ~C * ~f * (~p + ~q + 1) * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p * (~d + ~f * (~x) ^ 2) ^ (~q + 1)) / (2 * ~c * (~f) ^ 2 * (~p + ~q + 1) * (2 * ~p + 2 * ~q + 3)) - (1 / (2 * ~c * (~f) ^ 2 * (~p + ~q + 1) * (2 * ~p + 2 * ~q + 3))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p - 1) * (~d + ~f * (~x) ^ 2) ^ ~q * Simp(~p * (~b * ~d) * (~C * (-(~b) * ~f) * (~q + 1)) + (~p + ~q + 1) * ((~b) ^ 2 * ~C * ~d * ~f * ~p + ~a * ~c * (~C * (2 * ~d * ~f) + ~f * (-2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3))) + (2 * ~p * (~c * ~d - ~a * ~f) * (~C * (-(~b) * ~f) * (~q + 1)) + (~p + ~q + 1) * (-(~b) * ~c * (~C * (-4 * ~d * ~f) * (2 * ~p + ~q + 2) + ~f * (2 * ~C * ~d + 2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3)))) * ~x + (~p * (-(~b) * ~f) * (~C * (-(~b) * ~f) * (~q + 1)) + (~p + ~q + 1) * (~C * (~f) ^ 2 * ~p * ((~b) ^ 2 - 4 * ~a * ~c) - (~c) ^ 2 * (~C * (-4 * ~d * ~f) * (2 * ~p + ~q + 2) + ~f * (2 * ~C * ~d + 2 * ~A * ~f) * (2 * ~p + 2 * ~q + 3)))) * (~x) ^ 2, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~f, ~A, ~C, ~q], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (GtQ(~p, 0) && (NeQ(~p + ~q + 1, 0) && (NeQ(2 * ~p + 2 * ~q + 3, 0) && (Not(IGtQ(~p, 0)) && Not(IGtQ(~q, 0)))))))
    @apply_utils Antiderivative((~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2) / ((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2)), ~x) => With([q = (((((~c) ^ 2 * (~d) ^ 2 - ~b * ~c * ~d * ~e) + ~a * ~c * (~e) ^ 2 + (~b) ^ 2 * ~d * ~f) - 2 * ~a * ~c * ~d * ~f) - ~a * ~b * ~e * ~f) + (~a) ^ 2 * (~f) ^ 2], (1 / q) * Antiderivative(((((((~A * (~c) ^ 2 * ~d - ~a * ~c * ~C * ~d) - ~A * ~b * ~c * ~e) + ~a * ~B * ~c * ~e + ~A * (~b) ^ 2 * ~f) - ~a * ~b * ~B * ~f) - ~a * ~A * ~c * ~f) + (~a) ^ 2 * ~C * ~f + ~c * ((((~B * ~c * ~d - ~b * ~C * ~d) - ~A * ~c * ~e) + ~a * ~C * ~e + ~A * ~b * ~f) - ~a * ~B * ~f) * ~x) / (~a + ~b * ~x + ~c * (~x) ^ 2), ~x) + (1 / q) * Antiderivative((((((((~c * ~C * (~d) ^ 2 - ~B * ~c * ~d * ~e) + ~A * ~c * (~e) ^ 2 + ~b * ~B * ~d * ~f) - ~A * ~c * ~d * ~f) - ~a * ~C * ~d * ~f) - ~A * ~b * ~e * ~f) + ~a * ~A * (~f) ^ 2) - ~f * ((((~B * ~c * ~d - ~b * ~C * ~d) - ~A * ~c * ~e) + ~a * ~C * ~e + ~A * ~b * ~f) - ~a * ~B * ~f) * ~x) / (~d + ~e * ~x + ~f * (~x) ^ 2), ~x) <-- NeQ(q, 0)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~B, ~C], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && NeQ((~e) ^ 2 - 4 * ~d * ~f, 0))
    @apply_utils Antiderivative((~(A') + ~(C') * (~x) ^ 2) / ((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) * (~d + ~(e') * ~x + ~(f') * (~x) ^ 2)), ~x) => With([q = (((((~c) ^ 2 * (~d) ^ 2 - ~b * ~c * ~d * ~e) + ~a * ~c * (~e) ^ 2 + (~b) ^ 2 * ~d * ~f) - 2 * ~a * ~c * ~d * ~f) - ~a * ~b * ~e * ~f) + (~a) ^ 2 * (~f) ^ 2], (1 / q) * Antiderivative((((((~A * (~c) ^ 2 * ~d - ~a * ~c * ~C * ~d) - ~A * ~b * ~c * ~e) + ~A * (~b) ^ 2 * ~f) - ~a * ~A * ~c * ~f) + (~a) ^ 2 * ~C * ~f + ~c * ((-(~b) * ~C * ~d - ~A * ~c * ~e) + ~a * ~C * ~e + ~A * ~b * ~f) * ~x) / (~a + ~b * ~x + ~c * (~x) ^ 2), ~x) + (1 / q) * Antiderivative(((((((~c * ~C * (~d) ^ 2 + ~A * ~c * (~e) ^ 2) - ~A * ~c * ~d * ~f) - ~a * ~C * ~d * ~f) - ~A * ~b * ~e * ~f) + ~a * ~A * (~f) ^ 2) - ~f * ((-(~b) * ~C * ~d - ~A * ~c * ~e) + ~a * ~C * ~e + ~A * ~b * ~f) * ~x) / (~d + ~e * ~x + ~f * (~x) ^ 2), ~x) <-- NeQ(q, 0)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~C], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && NeQ((~e) ^ 2 - 4 * ~d * ~f, 0))
    @apply_utils Antiderivative((~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2) / ((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) * (~d + ~(f') * (~x) ^ 2)), ~x) => With([q = (((~c) ^ 2 * (~d) ^ 2 + (~b) ^ 2 * ~d * ~f) - 2 * ~a * ~c * ~d * ~f) + (~a) ^ 2 * (~f) ^ 2], (1 / q) * Antiderivative((((((~A * (~c) ^ 2 * ~d - ~a * ~c * ~C * ~d) + ~A * (~b) ^ 2 * ~f) - ~a * ~b * ~B * ~f) - ~a * ~A * ~c * ~f) + (~a) ^ 2 * ~C * ~f + ~c * (((~B * ~c * ~d - ~b * ~C * ~d) + ~A * ~b * ~f) - ~a * ~B * ~f) * ~x) / (~a + ~b * ~x + ~c * (~x) ^ 2), ~x) + (1 / q) * Antiderivative((((((~c * ~C * (~d) ^ 2 + ~b * ~B * ~d * ~f) - ~A * ~c * ~d * ~f) - ~a * ~C * ~d * ~f) + ~a * ~A * (~f) ^ 2) - ~f * (((~B * ~c * ~d - ~b * ~C * ~d) + ~A * ~b * ~f) - ~a * ~B * ~f) * ~x) / (~d + ~f * (~x) ^ 2), ~x) <-- NeQ(q, 0)) <-- FreeQ([~a, ~b, ~c, ~d, ~f, ~A, ~B, ~C], ~x) && NeQ((~b) ^ 2 - 4 * ~a * ~c, 0)
    @apply_utils Antiderivative((~(A') + ~(C') * (~x) ^ 2) / ((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) * (~d + ~(f') * (~x) ^ 2)), ~x) => With([q = (((~c) ^ 2 * (~d) ^ 2 + (~b) ^ 2 * ~d * ~f) - 2 * ~a * ~c * ~d * ~f) + (~a) ^ 2 * (~f) ^ 2], (1 / q) * Antiderivative(((((~A * (~c) ^ 2 * ~d - ~a * ~c * ~C * ~d) + ~A * (~b) ^ 2 * ~f) - ~a * ~A * ~c * ~f) + (~a) ^ 2 * ~C * ~f + ~c * (-(~b) * ~C * ~d + ~A * ~b * ~f) * ~x) / (~a + ~b * ~x + ~c * (~x) ^ 2), ~x) + (1 / q) * Antiderivative(((((~c * ~C * (~d) ^ 2 - ~A * ~c * ~d * ~f) - ~a * ~C * ~d * ~f) + ~a * ~A * (~f) ^ 2) - ~f * (-(~b) * ~C * ~d + ~A * ~b * ~f) * ~x) / (~d + ~f * (~x) ^ 2), ~x) <-- NeQ(q, 0)) <-- FreeQ([~a, ~b, ~c, ~d, ~f, ~A, ~C], ~x) && NeQ((~b) ^ 2 - 4 * ~a * ~c, 0)
    @apply_utils Antiderivative((~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2) / ((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) * sqrt(~(d') + ~(e') * ~x + ~(f') * (~x) ^ 2)), ~x) => (~C / ~c) * Antiderivative(1 / sqrt(~d + ~e * ~x + ~f * (~x) ^ 2), ~x) + (1 / ~c) * Antiderivative(((~A * ~c - ~a * ~C) + (~B * ~c - ~b * ~C) * ~x) / ((~a + ~b * ~x + ~c * (~x) ^ 2) * sqrt(~d + ~e * ~x + ~f * (~x) ^ 2)), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~B, ~C], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && NeQ((~e) ^ 2 - 4 * ~d * ~f, 0))
    @apply_utils Antiderivative((~(A') + ~(C') * (~x) ^ 2) / ((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) * sqrt(~(d') + ~(e') * ~x + ~(f') * (~x) ^ 2)), ~x) => (~C / ~c) * Antiderivative(1 / sqrt(~d + ~e * ~x + ~f * (~x) ^ 2), ~x) + (1 / ~c) * Antiderivative(((~A * ~c - ~a * ~C) - ~b * ~C * ~x) / ((~a + ~b * ~x + ~c * (~x) ^ 2) * sqrt(~d + ~e * ~x + ~f * (~x) ^ 2)), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~C], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && NeQ((~e) ^ 2 - 4 * ~d * ~f, 0))
    @apply_utils Antiderivative((~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2) / ((~a + ~(c') * (~x) ^ 2) * sqrt(~(d') + ~(e') * ~x + ~(f') * (~x) ^ 2)), ~x) => (~C / ~c) * Antiderivative(1 / sqrt(~d + ~e * ~x + ~f * (~x) ^ 2), ~x) + (1 / ~c) * Antiderivative(((~A * ~c - ~a * ~C) + ~B * ~c * ~x) / ((~a + ~c * (~x) ^ 2) * sqrt(~d + ~e * ~x + ~f * (~x) ^ 2)), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~A, ~B, ~C], ~x) && NeQ((~e) ^ 2 - 4 * ~d * ~f, 0)
    @apply_utils Antiderivative((~(A') + ~(C') * (~x) ^ 2) / ((~a + ~(c') * (~x) ^ 2) * sqrt(~(d') + ~(e') * ~x + ~(f') * (~x) ^ 2)), ~x) => (~C / ~c) * Antiderivative(1 / sqrt(~d + ~e * ~x + ~f * (~x) ^ 2), ~x) + ((~A * ~c - ~a * ~C) / ~c) * Antiderivative(1 / ((~a + ~c * (~x) ^ 2) * sqrt(~d + ~e * ~x + ~f * (~x) ^ 2)), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~A, ~C], ~x) && NeQ((~e) ^ 2 - 4 * ~d * ~f, 0)
    @apply_utils Antiderivative((~(A') + ~(B') * ~x + ~(C') * (~x) ^ 2) / ((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) * sqrt(~(d') + ~(f') * (~x) ^ 2)), ~x) => (~C / ~c) * Antiderivative(1 / sqrt(~d + ~f * (~x) ^ 2), ~x) + (1 / ~c) * Antiderivative(((~A * ~c - ~a * ~C) + (~B * ~c - ~b * ~C) * ~x) / ((~a + ~b * ~x + ~c * (~x) ^ 2) * sqrt(~d + ~f * (~x) ^ 2)), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~f, ~A, ~B, ~C], ~x) && NeQ((~b) ^ 2 - 4 * ~a * ~c, 0)
    @apply_utils Antiderivative((~(A') + ~(C') * (~x) ^ 2) / ((~a + ~(b') * ~x + ~(c') * (~x) ^ 2) * sqrt(~(d') + ~(f') * (~x) ^ 2)), ~x) => (~C / ~c) * Antiderivative(1 / sqrt(~d + ~f * (~x) ^ 2), ~x) + (1 / ~c) * Antiderivative(((~A * ~c - ~a * ~C) - ~b * ~C * ~x) / ((~a + ~b * ~x + ~c * (~x) ^ 2) * sqrt(~d + ~f * (~x) ^ 2)), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~f, ~A, ~C], ~x) && NeQ((~b) ^ 2 - 4 * ~a * ~c, 0)
    @apply_utils Antiderivative((~(a') + ~(b') * ~u + ~(c') * (~u) ^ 2) ^ ~(p') * (~(d') + ~(e') * ~u + ~(f') * (~u) ^ 2) ^ ~(q') * (~(A') + ~(B') * ~u + ~(C') * (~u) ^ 2), ~x) => (1 / Coefficient(~u, ~x, 1)) * Subst(Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * (~A + ~B * ~x + ~C * (~x) ^ 2), ~x), ~x, ~u) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~B, ~C, ~p, ~q], ~x) && (LinearQ(~u, ~x) && NeQ(~u, ~x))
    @apply_utils Antiderivative((~(a') + ~(b') * ~u + ~(c') * (~u) ^ 2) ^ ~(p') * (~(d') + ~(e') * ~u + ~(f') * (~u) ^ 2) ^ ~(q') * (~(A') + ~(B') * ~u), ~x) => (1 / Coefficient(~u, ~x, 1)) * Subst(Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * (~A + ~B * ~x), ~x), ~x, ~u) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~B, C, ~p, ~q], ~x) && (LinearQ(~u, ~x) && NeQ(~u, ~x))
    @apply_utils Antiderivative((~(a') + ~(b') * ~u + ~(c') * (~u) ^ 2) ^ ~(p') * (~(d') + ~(e') * ~u + ~(f') * (~u) ^ 2) ^ ~(q') * (~(A') + ~(C') * (~u) ^ 2), ~x) => (1 / Coefficient(~u, ~x, 1)) * Subst(Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * (~A + ~C * (~x) ^ 2), ~x), ~x, ~u) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~A, ~C, ~p, ~q], ~x) && (LinearQ(~u, ~x) && NeQ(~u, ~x))
    @apply_utils Antiderivative((~(a') + ~(c') * (~u) ^ 2) ^ ~(p') * (~(d') + ~(e') * ~u + ~(f') * (~u) ^ 2) ^ ~(q') * (~(A') + ~(B') * ~u + ~(C') * (~u) ^ 2), ~x) => (1 / Coefficient(~u, ~x, 1)) * Subst(Antiderivative((~a + ~c * (~x) ^ 2) ^ ~p * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * (~A + ~B * ~x + ~C * (~x) ^ 2), ~x), ~x, ~u) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~A, ~B, ~C, ~p, ~q], ~x) && (LinearQ(~u, ~x) && NeQ(~u, ~x))
    @apply_utils Antiderivative((~(a') + ~(c') * (~u) ^ 2) ^ ~(p') * (~(d') + ~(e') * ~u + ~(f') * (~u) ^ 2) ^ ~(q') * (~(A') + ~(B') * ~u), ~x) => (1 / Coefficient(~u, ~x, 1)) * Subst(Antiderivative((~a + ~c * (~x) ^ 2) ^ ~p * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * (~A + ~B * ~x), ~x), ~x, ~u) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~A, ~B, C, ~p, ~q], ~x) && (LinearQ(~u, ~x) && NeQ(~u, ~x))
    @apply_utils Antiderivative((~(a') + ~(c') * (~u) ^ 2) ^ ~(p') * (~(d') + ~(e') * ~u + ~(f') * (~u) ^ 2) ^ ~(q') * (~(A') + ~(C') * (~u) ^ 2), ~x) => (1 / Coefficient(~u, ~x, 1)) * Subst(Antiderivative((~a + ~c * (~x) ^ 2) ^ ~p * (~d + ~e * ~x + ~f * (~x) ^ 2) ^ ~q * (~A + ~C * (~x) ^ 2), ~x), ~x, ~u) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~A, ~C, ~p, ~q], ~x) && (LinearQ(~u, ~x) && NeQ(~u, ~x))
end

max_stars_repo_path: src/rules/1 Algebraic functions/1.2 Trinomial products/1.2.1 Quadratic/1.2.1.7 (a+b x+c x^2)^p (d+e x+f x^2)^q (A+B x+C x^2).jl


text:
ENV["PYCALL_JL_RUNTIME_PYTHON"] = "venv/bin/python3"
using PyCall
py"""
from julia import Julia
Julia(init_julia=False)
from examples.experiments_HSCC2021 import run_all
run_all()
"""

ext: jl

max_stars_repo_name: HySynth/HySynth

max_issues_repo_name: HySynth/HySynth

max_forks_repo_name: HySynth/HySynth


text:
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

# Simple data provider that load text
using Iterators
using MXNet

function build_vocabulary(corpus_fn::AbstractString, vocab_fn::AbstractString; max_vocab=10000)
  if isfile(vocab_fn)
    info("Vocabulary already exists, reusing $vocab_fn...")
    vocab = Dict{Char,Int}(w => i for (i,w) in enumerate(readstring(vocab_fn)))
  else
    # count symbol frequency
    dict = Dict{Char,Int}()
    open(corpus_fn) do io
      for line in eachline(io)
        for c in line
          dict[c] = get(dict, c, 0) + 1
        end
      end
    end

    vocab = sort(collect(dict), by=x->-x.second)
    vocab = vocab[1:min(max_vocab,length(vocab))]
    open(vocab_fn, "w") do io
      for x in vocab
        print(io, x.first)
      end
    end

    vocab = Dict(x.first => i for (i,x) in enumerate(vocab))
  end
  vocab[UNKNOWN_CHAR] = length(vocab)
  return vocab
end

#--CharSeqProvider
mutable struct CharSeqProvider <: mx.AbstractDataProvider
  text       :: AbstractString
  batch_size :: Int
  seq_len    :: Int
  vocab      :: Dict{Char,Int}

  prefix     :: Symbol
  n_layer    :: Int
  dim_hidden :: Int
end
#--/CharSeqProvider

function mx.get_batch_size(p :: CharSeqProvider)
  p.batch_size
end

#--provide
function mx.provide_data(p :: CharSeqProvider)
  [(Symbol(p.prefix, "_data_$t"), (length(p.vocab), p.batch_size)) for t = 1:p.seq_len] ∪
  [(Symbol(p.prefix, "_l$(l)_init_c"), (p.dim_hidden, p.batch_size)) for l=1:p.n_layer] ∪
  [(Symbol(p.prefix, "_l$(l)_init_h"), (p.dim_hidden, p.batch_size)) for l=1:p.n_layer]
end
function mx.provide_label(p :: CharSeqProvider)
  [(Symbol(p.prefix, "_label_$t"), (p.batch_size,)) for t = 1:p.seq_len]
end
#--/provide

#--eachbatch-part1
function mx.eachbatch(p::CharSeqProvider)
  data_all  = [mx.zeros(shape) for (name, shape) in mx.provide_data(p)]
  label_all = [mx.zeros(shape) for (name, shape) in mx.provide_label(p)]

  data_jl = [copy(x) for x in data_all]
  label_jl= [copy(x) for x in label_all]

  batch = mx.DataBatch(data_all, label_all, p.batch_size)
  #...
  #--/eachbatch-part1

  #--eachbatch-part2
  #...
  function _text_iter(c::Channel)
    text = p.text

    n_batch = floor(Int, length(text) / p.batch_size / p.seq_len)
    text = text[1:n_batch*p.batch_size*p.seq_len] # discard tailing
    idx_all = 1:length(text)

    for idx_batch in partition(idx_all, p.batch_size*p.seq_len)
      for i = 1:p.seq_len
        data_jl[i][:] = 0
        label_jl[i][:] = 0
      end

      for (i, idx_seq) in enumerate(partition(idx_batch, p.seq_len))
        for (j, idx) in enumerate(idx_seq)
          c_this = text[idx]
          c_next = idx == length(text) ? UNKNOWN_CHAR : text[idx+1]
          data_jl[j][char_idx(vocab,c_this),i] = 1
          label_jl[j][i] = char_idx(vocab,c_next)-1
        end
      end

      for i = 1:p.seq_len
        copy!(data_all[i], data_jl[i])
        copy!(label_all[i], label_jl[i])
      end

      put!(c, batch)
    end
  end

  return Channel(_text_iter)
end
#--/eachbatch-part2

# helper function to convert a char into index in vocabulary
function char_idx(vocab :: Dict{Char,Int}, c :: Char)
  if haskey(vocab, c)
    vocab[c]
  else
    vocab[UNKNOWN_CHAR]
  end
end

max_stars_repo_name: Vikas-kum/incubator-mxnet

max_issues_repo_name: Vikas-kum/incubator-mxnet

max_forks_repo_name: Vikas-kum/incubator-mxnet


text:
# Parser helper functions.
mutable struct Parser
    ptr::Ptr{Cvoid}
    language::Ptr{TSLanguage}
    function Parser()
        obj = new(ts_parser_new())
        finalizer(obj) do x
            ts_parser_delete(x.ptr)
        end
        return obj
    end
end

function set_language(P::Parser, language)
    if ts_parser_set_language(P.ptr, language)
        P.language = language
    else
        error("Error setting the parser language.")
    end
end

function Parser(language::Ptr{TSLanguage})
    p = Parser()
    set_language(p, language)
    return p
end

function parse_filewith(parser::Parser, filename::AbstractString)
    s = read(filename)
    parser.buffer = deepcopy(s)
    news = String(s)
    ts_parser_parse_string(parser.ptr, C_NULL, news, length(news))
end

function parse_string(parser::Parser, codestring)
    treeptr = ts_parser_parse_string(parser.ptr, Ptr{Cvoid}(), codestring, length(codestring))
    tree = Tree()
    tree.root_node = node_rootof(treeptr)
    tree.ptr = treeptr
    tree.language = parser.language
    return tree
end


text:
# Test projective.jl
using Test, Statistics, LinearAlgebra

println("testing projective")

tol = 1e-8

# Camera
# cameraproject, camera2projmatrix, imagept2plane, decomposecamera, rq3
# makehomogeneous, makeinhomogeneous, hnormalise
# homography1d, homography2d, normalise1dpts, normalise2dpts
# skew, hcross
# fundmatrix, affinefundmatrix, fundfromcameras
# idealimagepts, solvestereopt
# hline, plotcamera

# Generate Camera with some odd paraeters
f = 4000
rows = 3000;  cols = 4000
ppx = cols*0.3; ppy = rows*0.6;
skew = 0.3
k1 = 0.0
k3 = 0.0
X = 0; Y = 100; Z = 1000
Rc_w = rotx(pi-0.1)[1:3,1:3]     # camera points down(ish)

Cam = Camera(P=[X, Y, Z], Rc_w=Rc_w, fx=f, fy=f, ppx=ppx, ppy=ppy,
          skew=skew, k1=k1, k3=k3, rows=rows, cols=cols)

# ground points
gpt1 = [0.0, 0.0, 0.0]
gpt2 = [100.0, -200.0, 0.0]

(xy, visible) = cameraproject(Cam, [gpt1 gpt2], computevisibility=true)  # project to image

# Then project image points to ground plane to see if we reconstruct them
# ** Note this does not seem to work with lens distortion
planeP = [0.0,0.0,0.0]
planeN = [0.0,0.0,1.0]
planept = imagept2plane(Cam, xy, planeP, planeN)
@test maximum(abs.(planept - [gpt1 gpt2])) < f*tol

# Convert Cam structure to projection matrix and decompose to see if we get the same parameters back
P = camera2projmatrix(Cam)

(K, Rc_w_d, Pc_d, pp_d, pv) = decomposecamera(P)

@test abs(K[1,1] - f) < f*tol
@test abs(K[2,2] - f) < f*tol
@test abs(K[1,2] - skew) < f*tol
@test abs(K[1,3] - ppx) < rows*tol
@test abs(K[2,3] - ppy) < rows*tol

# makehomogeneous makeinhomoheneous hnormalise
x = rand(2,4)
hx = makehomogeneous(x)
x2 = makeinhomogeneous(3*hx)
@test maximum(abs.(x-x2)) < tol

# normalise1dpts
hx = hnormalise(100*rand(2,10))
(xn, T) = normalise1dpts(hx)
@test abs(mean(xn[1,:])) < tol  # mean 0
@test abs(mean(abs.(xn[1,:])) - 1) < tol  # mean deviation 1

#  normalise2dpts
hx = hnormalise(100*rand(3,10))
(xn, T) = normalise2dpts(hx)
@test abs(mean(xn[1,:])) < tol  # mean 0
@test abs(mean(xn[2,:])) < tol

# mean distance from origin is sqrt(2)
@test abs(mean(sqrt.(sum(xn[1:2,:].^2, dims=1))) - sqrt(2)) < tol

# check transform works
@test maximum(abs.(xn - T*hx)) < tol

# skew, hcross
a = rand(3)
b = rand(3)
aXb = ImageProjectiveGeometry.skew(a)*b
@test maximum(abs.(aXb .- cross(a,b))) < tol

@test maximum(abs.(hnormalise(aXb) .- hcross(a,b))) < tol

# homography1d, homography2d

# Define a 1D homography
a = 1; b = 2; c = 3
H = [a b
     c 1.]

x1 = [1 2 3 4 5
      1 1 1 1 1.]
x2 = hnormalise(H*x1)

Hfit = homography1d(x1,x2)
Hfit = Hfit/Hfit[2,2]
@test maximum(abs.(Hfit - H)) < tol

# Define a 2D homography
a = 1; b = 2; c = 3; d = -1; e = -2; f = -3; g = 2; h = -1
H = [a b c
     d e f
     g h 1.]

x1 = makehomogeneous(rand(2, 6))
x2 = hnormalise(H*x1)
Hfit = homography2d(x1,x2)
Hfit = Hfit/Hfit[3,3]
@test maximum(abs.(Hfit - H)) < tol

# fundmatrix, affinefundmatrix, fundfromcameras

# Generate a set of 3D points
pts = rand(3,12)

# Define 2 Cameras
f = 4000
rows = 3000;  cols = 4000
ppx = cols/2; ppy = rows/2;
X = 0; Y = 0; Z = 10
Rc_w = (rotx(pi)*roty(0.1))[1:3,1:3]

Cam1 = Camera(P=[X, Y, Z], Rc_w=Rc_w, fx=f, fy=f, ppx=ppx, ppy=ppy,
                         rows=rows, cols=cols)
Rc_w = (rotx(pi-.1)*roty(-0.1))[1:3,1:3]
Cam2 = Camera(P=[X+2, Y, Z], Rc_w=Rc_w, fx=f, fy=f, ppx=ppx, ppy=ppy,
                         rows=rows, cols=cols)

xy1 = cameraproject(Cam1, pts)  # Project points into images
xy2 = cameraproject(Cam2, pts)

# Form fundamental matrix from corresponding image points
F1 = fundmatrix(makehomogeneous(xy1), makehomogeneous(xy2))

# Form fundamental matrix from the camera projection matrices
F2 = fundfromcameras(Cam1, Cam2)

F1 = F1/F1[3,3]  # Adjust matrices to the same scale
F2 = F2/F2[3,3]

@test maximum(abs.(F1 - F2)) < tol


text:
####################################
#
# symmetric KLIEP loss
#
####################################

struct CDSymKLIEPLoss <: CoordinateDifferentiableFunction
    μx::Vector{Float64}   # mean(Ψx, dims = 2)
    μy::Vector{Float64}   # mean(Ψy, dims = 2)
    Ψx::Matrix{Float64}
    Ψy::Matrix{Float64}
    rx::Vector{Float64}    # nx dim vector --- stores -θ'Ψx(i)
    ry::Vector{Float64}    # ny dim vector --- stores  θ'Ψy(j)
    p::Int64
end

function CDSymKLIEPLoss(Ψx::Matrix{Float64}, Ψy::Matrix{Float64})
    (p = size(Ψx, 1)) == size(Ψy, 1) || throw(DimensionMismatch())

    CDSymKLIEPLoss(vec(mean(Ψx, dims=2)), vec(mean(Ψy, dims=2)), Ψx, Ψy, zeros(size(Ψx, 2)), zeros(size(Ψy, 2)), p)
end

CoordinateDescent.numCoordinates(f::CDSymKLIEPLoss) = f.p

function CoordinateDescent.initialize!(f::CDSymKLIEPLoss, x::SparseIterate)
    mul!(f.rx, transpose(f.Ψx), x)
    f.rx .*= -1.

    mul!(f.ry, transpose(f.Ψy), x)

    nothing
end

function CoordinateDescent.gradient(
    f::CDSymKLIEPLoss,
    x::SparseIterate,
    j::Int64)

    μx, Ψx, rx = f.μx, f.Ψx, f.rx
    μy, Ψy, ry = f.μy, f.Ψy, f.ry

    -μx[j] + μy[j] - mean( exp.(rx) .* Ψx[j, :] ) / mean(exp, rx) + mean( exp.(ry) .* Ψy[j, :] ) / mean(exp, ry)
end

function CoordinateDescent.descendCoordinate!(
    f::CDSymKLIEPLoss,
    g::Union{ProxL1, ProxZero},
    x::SparseIterate,
    j::Int64)

    μx, Ψx, rx = f.μx, f.Ψx, f.rx
    μy, Ψy, ry = f.μy, f.Ψy, f.ry

    mean_exp_rx = mean(exp, rx)
    mean_exp_rx_Ψx = mean( exp.(rx) .* Ψx[j, :] )
    mean_exp_rx_Ψx2 = mean( exp.(rx) .* Ψx[j, :].^2 )

    mean_exp_ry = mean(exp, ry)
    mean_exp_ry_Ψy = mean( exp.(ry) .* Ψy[j, :] )
    mean_exp_ry_Ψy2 = mean( exp.(ry) .* Ψy[j, :].^2 )

    @inbounds grad = -μx[j] + μy[j] - mean_exp_rx_Ψx / mean_exp_rx + mean_exp_ry_Ψy / mean_exp_ry
    H = mean_exp_rx_Ψx2 / mean_exp_rx - mean_exp_rx_Ψx^2 / mean_exp_rx^2 + mean_exp_ry_Ψy2 / mean_exp_ry - mean_exp_ry_Ψy^2 / mean_exp_ry^2

    @inbounds oldVal = x[j]
    @inbounds x[j] -= grad / H
    newVal = cdprox!(g, x, j, 1. / H)
    h = newVal - oldVal

    # update internals
    for i=1:length(rx)
        @inbounds rx[i] -= h*Ψx[j, i]
    end
    for i=1:length(ry)
        @inbounds ry[i] += h*Ψy[j, i]
    end
    h
end

# symmetric KLIEP solver
struct CD_SymKLIEP <: KLIEPSolver end

SymKLIEP(Ψx, Ψy, ::CD_SymKLIEP) = SymKLIEP!(SparseIterate(size(Ψx, 1)), Ψx, Ψy)

function SymKLIEP!(x::SparseIterate, Ψx, Ψy)
    f = CDSymKLIEPLoss(Ψx, Ψy)
    g = ProxZero()
    coordinateDescent!(x, f, g)
end

spSymKLIEP(Ψx, Ψy, λ, ::CD_SymKLIEP) = spSymKLIEP!(SparseIterate(size(Ψx, 1)), Ψx, Ψy, λ)

function spSymKLIEP!(x::SparseIterate, Ψx, Ψy, λ)
    f = CDSymKLIEPLoss(Ψx, Ψy)
    g = ProxL1(λ)
    coordinateDescent!(x, f, g)
end

# Computes the Hessian of the SymKLIEP loss
SymKLIEP_Hessian(θ, Ψx, Ψy) = StatsBase.cov(Ψx, weights(KLIEPInference.rhat(-θ, Ψx)), 2; corrected=false) + StatsBase.cov(Ψy, weights(KLIEPInference.rhat(θ, Ψy)), 2; corrected=false)

# debiasing
function SymKLIEP_debias1(Ψx, Ψy, θ, ω, θ_ind::Int)
    μx = vec(mean(Ψx, dims=2))
    μy = vec(mean(Ψy, dims=2))

    supp = KLIEPInference._find_supp(θ_ind, θ)
    θk = SymKLIEP(Ψx[supp, :], Ψy[supp, :], CD_SymKLIEP())

    rx = KLIEPInference.rhat(-θk, Ψx[supp, :])
    ry = KLIEPInference.rhat( θk, Ψy[supp, :])
    θ1 = θk[end]
    for l in findall(!iszero, ω)
        θ1 += ω[l] * ( μx[l] - μy[l] + mean( rx .* Ψx[l, :] ) - mean( ry .* Ψy[l, :] ) )
    end
    θ1
end

function SymKLIEP_debias2(Ψx, Ψy, θ, ω, θ_ind::Int)
    supp = KLIEPInference._find_supp(θ_ind, θ, ω)
    θk = SymKLIEP(Ψx[supp,:], Ψy[supp,:], CD_SymKLIEP())
    θk[end]
end

# standard error
function SymKLIEP_stderr(Ψx, Ψy, θ, ω)
    nx = size(Ψx, 2)
    ny = size(Ψy, 2)
    supp = findall(!iszero, ω)
    S = (cov(transpose(Ψx[supp, :]), corrected=false) ./ nx) .+ (cov(transpose(Ψy[supp, :]), corrected=false) ./ ny) .+ (cov(KLIEPInference.rhat(-θ, Ψx) .* transpose(Ψx[supp, :]), corrected=false) ./ nx) .+ (cov(KLIEPInference.rhat(θ, Ψy) .* transpose(Ψy[supp, :]), corrected=false) ./ ny)
    σ2 = 0.
    for k in 1:length(supp)
        for l in 1:length(supp)
            σ2 += S[k,l] * ω[supp][k] * ω[supp][l]
        end
    end
    sqrt(σ2)
end


text:
using Test
using TestSetExtensions

include("../src/Groebner.jl")

using .Groebner
using .Groebner.AbstractAlgebra

# Taken from JuMP/test/solvers.jl
function try_import(name::Symbol)
    try
        @eval import $name
        return true
    catch e
        return false
    end
end

⊂(xs, ys) = all(in(ys), xs)
# set equality
≂(xs, ys) = ⊂(xs, ys) && ⊂(ys, xs)

@testset "All tests" begin

    @includetests ["commons", "io", "io_consistency",
                    "univariate_aa"]

    @includetests ["crt_reconstruction"] # "mod_reconstruction"]#,

    @includetests ["f4_reduce", "f4_stress",
                    "f4", "rational_f4", "groebner_certify"]

    @includetests ["isgroebner", "isgroebner_stress",
                    "isgroebner_certify"]

    @includetests ["normalform", "normalform_stress"]

    @includetests ["hard_problems_f4", "large_problems_f4"]

    @includetests ["probabilistic_linalg"]

    if try_import(:DynamicPolynomials)
        @includetests ["io_dynamic", "dynamic"]
    end

    @includetests ["onthefly_order_change"]

    @includetests ["fglm", "kbase"]

    @includetests ["benchmark_systems"]

end


text:
# helper.jl

using BenchmarkTools: @btime
using SPECTrecon: padzero!, padrepl!, pad2sizezero!, pad_it!
using SPECTrecon: fftshift!, ifftshift!, fftshift2!
using SPECTrecon: plus1di!, plus1dj!, plus2di!, plus2dj!
using SPECTrecon: plus3di!, plus3dj!, plus3dk!, scale3dj!, mul3dj!
using SPECTrecon: copy3dj!

function padzero_time()
    T = Float32
    x = randn(T, 7, 5)
    y = randn(T, 3, 3)
    println("padzero")
    @btime padzero!($x, $y, (2, 2, 1, 1)) # 10.648 ns (0 allocations: 0 bytes)
    nothing
end

function padrepl_time()
    T = Float32
    x = randn(T, 10, 9)
    y = randn(T, 5, 4)
    println("padrepl")
    @btime padrepl!($x, $y, (1, 4, 3, 2)) # 61.129 ns (0 allocations: 0 bytes)
    nothing
end

function pad2size_time()
    T = Float32
    ker = reshape(Int16(1):Int16(9), 3, 3)
    padsize = (8, 8)
    z = randn(T, padsize)
    println("pad2sizezero")
    @btime pad2sizezero!($z, $ker, $padsize) # 16.899 ns (0 allocations: 0 bytes)
    println("pad_it")
    @btime pad_it!($ker, $padsize) #32.320 ns (0 allocations: 0 bytes)
    nothing
end

function fft_time()
    b = [1 2;3 4]
    x = [b 2*b;3*b 4*b]
    y = similar(x)
    println("fftshift")
    @btime fftshift!($y, $x) # 76.447 ns (0 allocations: 0 bytes)
    println("ifftshift")
    @btime ifftshift!($x, $y) # 82.149 ns (0 allocations: 0 bytes)
    nothing
end

function fft2_time()
    T = Float32
    x = randn(T, 120, 128)
    z = similar(x)
    println("fftshift")
    @btime fftshift!($z, $x) # 3.095 μs (0 allocations: 0 bytes)
    println("fftshift2")
    @btime fftshift2!($z, $x) # 2.776 μs (0 allocations: 0 bytes)
    nothing
end

function plus1di_time()
    T = Float32
    x = randn(T, 4, 64)
    v = randn(T, 64)
    println("plus1di")
    @btime plus1di!($x, $v, 2) # 28.569 ns (0 allocations: 0 bytes)
    nothing
end

function plus1dj_time()
    T = Float32
    x = randn(T, 64, 4)
    v = randn(T, 64)
    println("plus1dj")
    @btime plus1dj!($x, $v, 2) # 5.257 ns (0 allocations: 0 bytes)
    nothing
end

function plus2di_time()
    T = Float32
    x = randn(64)
    v = randn(4, 64)
    println("plus2di")
    @btime plus2di!($x, $v, 2) # 28.383 ns (0 allocations: 0 bytes)
    nothing
end

function plus2dj_time()
    T = Float32
    x = randn(T, 64)
    v = randn(T, 64, 4)
    println("plus2dj")
    @btime plus2dj!($x, $v, 2) # 6.207 ns (0 allocations: 0 bytes)
    nothing
end

function plus3di_time()
    T = Float32
    x = randn(T, 64, 64)
    v = randn(T, 4, 64, 64)
    println("plus3di")
    @btime plus3di!($x, $v, 2) # 1.711 μs (0 allocations: 0 bytes)
    nothing
end

function plus3dj_time()
    T = Float32
    x = randn(T, 64, 64)
    v = randn(T, 64, 4, 64)
    println("plus3dj")
    @btime plus3dj!($x, $v, 2) # 304.141 ns (0 allocations: 0 bytes)
    nothing
end

function plus3dk_time()
    T = Float32
    x = randn(T, 64, 64)
    v = randn(T, 64, 64, 4)
    println("plus3dk")
    @btime plus3dk!($x, $v, 2) # 279.628 ns (0 allocations: 0 bytes)
    nothing
end

function scale3dj_time()
    T = Float32
    x = randn(T, 64, 64)
    v = randn(T, 64, 4, 64)
    s = -0.5
    println("scale3dj")
    @btime scale3dj!($x, $v, 2, $s) # 408.392 ns (0 allocations: 0 bytes)
    nothing
end

function mul3dj_time()
    T = Float32
    x = randn(T, 64, 4, 64)
    v = randn(T, 64, 64)
    println("mul3dj")
    @btime mul3dj!($x, $v, 2) # 15.197 μs (0 allocations: 0 bytes)
    nothing
end

function copy3dj_time()
    T = Float32
    x = randn(T, 64, 64)
    v = randn(T, 64, 4, 64)
    println("copy3dj")
    @btime copy3dj!($x, $v, 2) # 226.772 ns (0 allocations: 0 bytes)
    nothing
end

# run all functions, time may vary on different machines, but should be all zero allocation.
padzero_time()
padrepl_time()
pad2size_time()
fft_time()
fft2_time()
plus1di_time()
plus1dj_time()
plus2di_time()
plus2dj_time()
plus3di_time()
plus3dj_time()
plus3dk_time()
scale3dj_time()
mul3dj_time()
copy3dj_time()


text:
# Script to check that all mmCIF dictionary entries are the same as those from Biopython
# Requires a Python installation with Biopython and NumPy installed

using BioStructures
using PyCall

version = pyimport("Bio").__version__
@info "Biopython version is $version"

MMCIF2Dict_python = pyimport("Bio.PDB.MMCIF2Dict").MMCIF2Dict

pdbids = pdbentrylist()

for pdbid in pdbids
    filepath = downloadpdb(pdbid, format=MMCIF)
    if isfile(filepath)
        dict_julia = MMCIFDict(filepath).dict
        dict_python = MMCIF2Dict_python(filepath)
        rm(filepath)
        status = "identical"
        if convert(Array{String, 1}, sort(collect(keys(dict_python)))) == sort(collect(keys(dict_julia)))
            for key in keys(dict_julia)
                if key == "data_"
                    value_python = [dict_python[key]]
                else
                    value_python = dict_python[key]
                end
                if dict_julia[key] != value_python
                    status = "different $key"
                    break
                end
            end
        else
            status = "different keys"
        end
    else
        status = "download_failed"
    end
    println(pdbid, " ", status)
end


text:
module FiniteHorizonPOMDPs

using POMDPs
using POMDPModelTools
import POMDPs: Policy, action

export
    stage_states,
    stage_stateindex,
    HorizonLength,
    FiniteHorizon,
    InfiniteHorizon,
    horizon

include("interface.jl")

export
    FiniteHorizonPolicy,
    solve,
    action

include("valueiteration.jl")
include("solver.jl")

end


text:
######################################################################
# initializer.jl
# different ways to initalize a trajectory
######################################################################
export ConstantInitializer
export RandomInitializer
export SampleInitializer
export CornerInitializer

include("constant_initializer.jl")
include("random_initializer.jl")
include("sample_initializer.jl")
include("corner_initializer.jl")

"""
`xd, ud = initialize(em::ErgodicManager, tm::TrajectoryManager)`

Runs `tm`'s initializer to return a trajectory.
"""
function initialize(em::ErgodicManager, tm::TrajectoryManager)
	initialize(tm.initializer, em, tm)
end
function initialize(em::ErgodicManager, vtm::Vector{TrajectoryManager})
	num_agents = length(vtm)
	xd0s = VVVF()
	ud0s = VVVF()
	for j = 1:num_agents
		xd0, ud0 = initialize(em, vtm[j])
		push!(xd0s, xd0)
		push!(ud0s, ud0)
	end
	return vvvf2vvf(xd0s, ud0s)
end

# TODO: finish this one
"""
`cci = CornerConstantInitializer(action::Vector{Float64})`

Just takes a constant action.
"""
mutable struct CornerConstantInitializer <: Initializer
	magnitude::Float64
end

"""
`gi = GreedyInitializer()`

Greedily goes to spot with maximum phi.
Assumes phi decreases at a constant rate.
"""
mutable struct GreedyInitializer <: Initializer end

"""
`poi = PointInitializer(xd::Vector{Float64})`

Moves to point `xd`.
"""
mutable struct PointInitializer <: Initializer
	xd::Vector{Float64}
end

"""
`di = DirectionInitializer(xd::Vector{Float64}, mag::Float64)`

Moves in the direction of point `xd` with magnitude `mag`.
"""
mutable struct DirectionInitializer <: Initializer
	xd::Vector{Float64}
	mag::Float64
end

# TODO: actually finish this
function initialize(cci::CornerConstantInitializer, em::ErgodicManager, tm::TrajectoryManager)
	xd = Array(Vector{Float64}, tm.N+1)
	ud = Array(Vector{Float64}, tm.N)
	xd[1] = deepcopy(tm.x0)
	ud[1] = deepcopy(ci.action)
	for i = 1:(tm.N-1)
		xd[i+1] = tm.A*xd[i] + tm.B*ud[i]
		ud[i+1] = deepcopy(ci.action)
	end
	xd[tm.N+1] = tm.A*xd[tm.N] + tm.B*ud[tm.N]

	return xd, ud
end

export greedy_trajectory
function greedy_trajectory(em::ErgodicManager, tm::TrajectoryManager)
	return initialize(GreedyInitializer(), em, tm)
end
function initialize(gi::GreedyInitializer, em::ErgodicManager, tm::TrajectoryManager)
	d_rate = sum(em.phi)/tm.N
	num_cells = em.bins*em.bins
	total_info = 0.0
	xd = Array(Vector{Float64}, tm.N+1)
	xd[1] = deepcopy(tm.x0)
	temp_phi = deepcopy(em.phi)
	size_tuple = (em.bins, em.bins)
	for n = 1:tm.N
		bi = indmax(temp_phi)
		xi, yi = ind2sub(size_tuple, bi)
		xd[n+1] = [(xi-0.5)*em.cell_size, (yi-0.5)*em.cell_size]
		temp_phi[bi] -= min(temp_phi[bi], d_rate)
	end
	ud = compute_controls(xd, tm.h)
	return xd,ud
end

# moves to a point with a constant control input
function initialize(initializer::PointInitializer, em::ErgodicManager, tm::TrajectoryManager)

	# compute the direction and action we most go towards
	dx = initializer.xd[1] - tm.x0[1]
	dy = initializer.xd[2] - tm.x0[2]
	#x_step = (initializer.xd[1] - tm.x0[1]) / (tm.N * tm.h)
	#y_step = (initializer.xd[2] - tm.x0[2]) / (tm.N * tm.h)
	#u = [x_step, y_step]

	# if we are double integrator, only apply the input once
	ud = Array(Vector{Float64}, tm.N)
	if tm.dynamics.n > 2
		den = tm.h * tm.h * (tm.N-1)
		ud[1] = [dx/den, dy/den]
		for i = 1:(tm.N-1)
			ud[i+1] = zeros(2)
		end
	else  # single integrator
		den = tm.h * tm.N
		u = [dx / den, dy / den]
		for i = 1:tm.N
			ud[i] = deepcopy(u)
		end
	end

	xd = integrate(tm, ud)

	return xd, ud
end

# moves to a point with a constant control input
function initialize(initializer::DirectionInitializer, em::ErgodicManager, tm::TrajectoryManager)
	xd = Array(Vector{Float64}, tm.N+1)
	ud = Array(Vector{Float64}, tm.N)

	# compute the direction and action we most go towards
	dx = initializer.xd[1] - tm.x0[1]
	dy = initializer.xd[2] - tm.x0[2]
	u = initializer.mag * [dx, dy] / sqrt(dx*dx + dy*dy)

	xd[1] = deepcopy(tm.x0)
	ud[1] = deepcopy(u)
	for i = 1:(tm.N-1)
		xd[i+1] = tm.A*xd[i] + tm.B*ud[i]
		ud[i+1] = deepcopy(u)
	end
	xd[tm.N+1] = tm.A*xd[tm.N] + tm.B*ud[tm.N]

	return xd, ud
end


text:
using CSV, DataFrames,FreqTables, Plots, StatsPlots, StatsBase, Missings, StatsBase;

# setup filepaths
path_source = string(@__DIR__,"\\..\\source");
path_dev = string(@__DIR__,"\\..\\dev");

df = DataFrame(CSV.read(joinpath(path_dev, "19-21VAERSCOMB_clean.csv", DataFrame));

# Adrew's code starts here
# Convert SYMPTOMS strings back to an array of strings
a = fill([], size(df,1));

for rownumber in 1:size(df, 1)
    str_symptoms = df[rownumber,:SYMPTOMS]
    str_index_start = findfirst(isequal('['), str_symptoms)+2
    str_index_end = findfirst(isequal(']'), str_symptoms)-2
    a[rownumber] = split(df[rownumber,:SYMPTOMS][str_index_start:str_index_end], "\", \"")
end;

df.SYMPTOMS = a;

# Create dictionary for VAX_NAME:SYMPTOM
# Step 1: create the dict
vax_to_symptoms_dict = Dict{String, Set{String}}()
# Step 2: populate the keys (VAERS_ID) of the dict
for rownumber in 1:size(df, 1)
    vax_name = df[rownumber, :VAX_NAME]
    if !haskey(vax_to_symptoms_dict, vax_name)
        # this is the set where we will store all of the symptoms for this VAX_NAME
        vax_to_symptoms_dict[vax_name] = Set{String}()
    end
end
# Step 3: populate the values (SYMPTOMS) of the dict
for rownumber in 1:size(df, 1)
    vax_name = df[rownumber, :VAX_NAME]
    symptoms = df[rownumber, :SYMPTOMS]
    for symptom in symptoms
        push!(vax_to_symptoms_dict[vax_name], symptom)
    end
end
# View dict
vax_to_symptoms_dict

function get_freqtable(df, vax_name, symptom)
    temp = select(df, ["VAX_NAME", "SYMPTOMS"])
    # Create dummy variable for vax_name
    temp.TARGET_VAX= (temp.VAX_NAME .== vax_name)
    # Create dummy variable for symptom
    temp.TARGET_SYMPTOM = zeros(size(temp, 1))
    for rownumber in 1:size(temp, 1)
        if symptom in temp[rownumber,:SYMPTOMS]
            temp[rownumber,:TARGET_SYMPTOM] = 1
        end
    end

    # Create frequency table
    tbl = freqtable(temp, :TARGET_VAX, :TARGET_SYMPTOM)
    return tbl
end;

function get_PRR(tbl)
    # Calculate PRR
    a = tbl[2,2]
    b = tbl[2,1]
    c = tbl[1,2]
    d = tbl[1,1]
    PRR = (a/(a+b))/(c/(c+d))

    return PRR
end;

# Andrews code ends here

#=
Analysing top 5 symptoms in top 5 vaccines
COVID19 (COVID19 (PFIZER-BIONTECH)), ZOSTER (SHINGRIX), COVID19 (COVID19 (MODERNA)),
PNEUMO (PNEUMOVAX), COVID19 (COVID19 (JANSSEN))
=#

list_symptoms_mostlikely = Dict{String, Vector{String}}()

for vax in ["COVID19 (COVID19 (PFIZER-BIONTECH))",
            "ZOSTER (SHINGRIX)",
            "COVID19 (COVID19 (MODERNA))",
            "PNEUMO (PNEUMOVAX)",
            "COVID19 (COVID19 (JANSSEN))"]
    # Create dict of most reported symptoms for each vaccine
    df_vax = filter(row -> row.VAX_NAME == vax, df)

    symptoms_all_dupes = reduce(vcat, df_vax.SYMPTOMS)
    symptoms_freq_dict = StatsBase.countmap(symptoms_all_dupes)
    list_symptoms = unique(reduce(vcat, df_vax.SYMPTOMS))
    freq_per_symptom = [symptoms_freq_dict[val] for val in list_symptoms]
    perm = sortperm(freq_per_symptom; rev=true)
    # only pick the top 5 symptoms for each of the vaccine
    list_symptoms_mostlikely[vax] = list_symptoms[perm[1:5]]
end

prr_dict = Dict()

for (vax, symptoms) in list_symptoms_mostlikely
    symp_prr = []
    for symptom in symptoms
        push!(symp_prr, string(symptom, "(PRR: ",
                round(get_PRR(get_freqtable(df, vax, symptom)); digits=2), ")"))
    end
    prr_dict[vax] = symp_prr
end
prr_dict


text:
using Base.Profile;

function print_sudoku(m, n, sudoku)
    println(m, " ", n);
    println(sudoku);
end

function find_empty(m, n, sudoku)
    for i in 1:m*n, j in 1:m*n
        if sudoku[i, j] == 0
            return (i, j);
        end
    end
    return (m * n + 1, m * n + 1);
end

# Finds an empty cell using the most constrained variable heuristic
function smart_find_empty(m, n, sudoku, used_row, used_col, used_box)
    besti = m * n + 1;
    bestj = m * n + 1;
    best = m * n + 1;
    remaining = 0;
    for i in 1:m*n, j in 1:m*n
        if sudoku[i, j] == 0
            remaining += 1;
            box = div(i-1, m) * m + div(j-1, n) + 1;
            options = 0;
            for v in 1:m*n
                if used_row[i, v] == 0 && used_col[j, v] == 0 &&
                        used_box[box, v] == 0
                    options += 1;
                end
            end
            if options == 0
                return (0, 0);
            end
            if options < best
                besti = i;
                bestj = j;
                best = options;
            end
        end
    end
    if remaining == 0
        return (m * n + 1, m * n + 1);
    end

    return (besti, bestj)
end

# Basic backtracking using the arrays storing whether certain digits
# have already appeared to speed up checking.
function smart_solve(m, n, sudoku, used_row, used_col, used_box)

    i, j = smart_find_empty(m, n, sudoku, used_row, used_col, used_box);
    if i == 0
        return false;
    end
    if i > m * n
        return true;
    end

    bi = div(i-1, m);
    bj = div(j-1, n) + 1;
    box = bi * m + bj;

    for v in 1:m*n
        if used_row[i, v] == 0 && used_col[j, v] == 0 &&
                used_box[box, v] == 0
            sudoku[i, j] = v;
            used_row[i, v] = 1;
            used_col[j, v] = 1;
            used_box[box, v] = 1;
            if smart_solve(m, n, sudoku, used_row, used_col, used_box)
                return true;
            end
            sudoku[i, j] = 0;
            used_row[i, v] = 0;
            used_col[j, v] = 0;
            used_box[box, v] = 0;
        end
    end

    return false;
end

# Setup for the slightly smarter solve
# Initialises arrays storing whether each type of digit has occurred in
# each row, column and box and then passes this into the main function
function smart_solve(m, n, sudoku)
    used_row = zeros(Int64, m*n, m*n);
    used_col = zeros(Int64, m*n, m*n);
    used_box = zeros(Int64, m*n, m*n);

    for i in 1:m*n, j in 1:m*n
        if sudoku[i, j] > 0
            used_row[i, sudoku[i, j]] = 1;
            used_col[j, sudoku[i, j]] = 1;
        end
    end
    for i in 1:n, j in 1:m
        bi = (i-1) * m + 1;
        bj = (j-1) * n + 1;
        box = (i - 1) * m + j;
        for k in bi:bi+m-1, l in bj:bj+n-1
            if sudoku[k, l] > 0
                used_box[box, sudoku[k, l]] = 1;
            end
        end
    end

    if smart_solve(m, n, sudoku, used_row, used_col, used_box)
        return true;
    end
    return false;
end

# Dumbest backtracking solver
# Passes over all neighbours each time to check for a colliding value
function solve(m, n, sudoku)
    i, j = find_empty(m, n, sudoku);

    if i > m * n
        return true;
    end

    for v in 1:m*n

        # Determine if v is a valid option for this cell
        valid = true;
        for k in 1:m*n
            if (k != j && sudoku[i, k] == v) ||
                    (k != i && sudoku[k, j] == v)
                valid = false;
                break;
            end
        end
        # Check if v has been used in this box
        if valid
            bi = div(i-1, m) * m + 1;
            bj = div(j-1, n) * n + 1;
            for k in bi:bi+m-1, l in bj:bj+n-1
                if sudoku[k, l] == v
                    valid = false;
                    break;
                end
            end
        end

        if valid
            sudoku[i, j] = v
            if (solve(m, n, sudoku))
                return true;
            end
        end

    end

    sudoku[i, j] = 0;
    return false;
end

function try_solve(m, n, sudoku)
    s = copy(sudoku);
    smart_solve(m, n, s);
end

f = open("sudokus/2.sudoku");
m, n = [parse(Int64, s) for s = split(readline(f), " ")];

sudoku_raw = round(Int64, readdlm(f));
close(f);
sudoku = copy(sudoku_raw);

print_sudoku(m, n, sudoku);

x = smart_solve(m, n, sudoku);
println(x);

print_sudoku(m, n, sudoku);

# Actual sudoku solve
f = open("sudokus/4.sudoku");
m, n = [parse(Int64, s) for s = split(readline(f), " ")];

sudoku_raw = round(Int64, readdlm(f));
close(f);

print_sudoku(m, n, sudoku_raw);
sudoku = copy(sudoku_raw);

x = smart_solve(m, n, sudoku);
println(x);
print_sudoku(m, n, sudoku);

max_stars_repo_name: nick-hiebl/n-doku

max_issues_repo_name: nick-hiebl/n-doku

max_forks_repo_name: nick-hiebl/n-doku


text:
# Copyright 2018 Erik Edin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

using Behavior:
    ExecutorEngine, ColorConsolePresenter, Driver,
    readstepdefinitions!, runfeatures!, issuccess,
    FromSourceExecutionEnvironment, NoExecutionEnvironment
import Behavior:
    findfileswithextension, readfile, fileexists

using Behavior.Gherkin
using Behavior.Gherkin.Experimental
using Glob

struct OSAL <: Behavior.OSAbstraction end
function findfileswithextension(::OSAL, path::String, extension::String)
    return rglob("*$extension", path)
end

readfile(::OSAL, path::String) = read(path, String)
fileexists(::OSAL, path::String) = isfile(path)

"""
    rglob(pattern, path)

Find files recursively.
"""
rglob(pattern, path) = Base.Iterators.flatten(map(d -> glob(pattern, d[1]), walkdir(path)))

function parseonly(featurepath::String; parseoptions::ParseOptions=ParseOptions())

    # -----------------------------------------------------------------------------
    # borrowed code from runspec; should be refactored later
    os = OSAL()
    engine = ExecutorEngine(ColorConsolePresenter(); executionenv=NoExecutionEnvironment())
    driver = Driver(os, engine)
    # -----------------------------------------------------------------------------

    featurefiles = rglob("*.feature", featurepath)

    # Parse all feature files and collect results to an array of named tuples
    results = []
    for featurefile in featurefiles
        if parseoptions.use_experimental
            try
                input = Experimental.ParserInput(read(featurefile, String))
                featureparser = Experimental.FeatureFileParser()
                result = featureparser(input)
                if Experimental.isparseok(result)
                    push!(results, (filename = featurefile, success = true, result = result.value))
                else
                    push!(results, (filename = featurefile, success = false, result = result))
                end
            catch ex
                push!(results, (filename = featurefile, success = false, result = Experimental.BadExceptionParseResult{Feature}(ex)))
            end
        else
            try
                parseddata = parsefeature(readfile(driver.os, featurefile), options=parseoptions)
                isbad = parseddata isa BadParseResult
                push!(results, (filename = featurefile, success = !isbad, result = parseddata))
            catch ex
                push!(results, (filename = featurefile, success = false, result = Gherkin.BadParseResult{Feature}(:exception, :nothing, Symbol("$ex"), 0, "")))
            end
        end
    end
    return results
end

"""
    printbadparseresult(error::BadParseResult{T})

Print parse errors.
"""
function printbadparseresult(featurefile::String, err::Gherkin.BadParseResult{T}) where {T}
    println("ERROR: $(featurefile):$(err.linenumber)")
    println("      Line: $(err.line)")
    println("    Reason: $(err.reason)")
    println("  Expected: $(err.expected)")
    println("    Actual: $(err.actual)")
end

"""
    runspec(rootpath; featurepath, stepspath, execenvpath, parseoptions, presenter, tags)

Execute all features found from the `rootpath`.

By default, it looks for feature files in `<rootpath>/features` and step files
`<rootpath>/features/steps`. An `environment.jl` file may be added to
`<rootpath>/features` directory for running certain before/after code.
You may override the default locations by specifying `featurepath`,
`stepspath`, or `execenvpath`.

The `tagselector` option is an expression you can use to select which scenarios to run
based on tags. For instance, the tag selector `@foo` will run only those scenarios that
have the tag `@foo`, while `not @ignore` will run only that scenarios that _do not_ have
the `@ignore` tag.

See also: [Gherkin.ParseOptions](@ref).
"""
function runspec(
    rootpath::String = ".";
    featurepath = joinpath(rootpath, "features"),
    stepspath = joinpath(featurepath, "steps"),
    execenvpath = joinpath(featurepath, "environment.jl"),
    parseoptions::ParseOptions=ParseOptions(),
    presenter::RealTimePresenter=ColorConsolePresenter(),
    tags::String = "",
)
    os = OSAL()

    executionenv = if fileexists(os, execenvpath)
        FromSourceExecutionEnvironment(readfile(os, execenvpath))
    else
        NoExecutionEnvironment()
    end

    if parseoptions.use_experimental
        println("WARNING: Experimental parser used for feature files!")
        println()
    end

    # TODO: Handle tag selector errors once the syntax is more complex.
    selector = Selection.parsetagselector(tags)

    engine = ExecutorEngine(presenter; executionenv=executionenv, selector=selector)
    driver = Driver(os, engine)

    readstepdefinitions!(driver, stepspath)
    resultaccumulator = runfeatures!(driver, featurepath, parseoptions=parseoptions)

    if isempty(resultaccumulator)
        println("No features found.")
        return true
    end

    #
    # Present number of scenarios that succeeded and failed for each feature
    #
    results = featureresults(resultaccumulator)

    # Find the longest feature name, so we can align the result table.
    maxfeature = maximum(length(r.feature.header.description) for r in results)

    featureprefix = "  Feature: "
    printstyled(" " ^ (length(featureprefix) + maxfeature + 1), "| Success | Failure\n"; color=:white)
    for r in results
        linecolor = r.n_failure == 0 ? :green : :red
        printstyled(featureprefix, rpad(r.feature.header.description, maxfeature); color=linecolor)
        printstyled(" | "; color=:white)
        printstyled(rpad("$(r.n_success)", 7); color=:green)
        printstyled(" | "; color=:white)
        printstyled(rpad("$(r.n_failure)", 7), "\n"; color=linecolor)
    end

    println()

    #
    # Present any syntax errors
    #
    for (featurefile, err) in resultaccumulator.errors
        println()
        printbadparseresult(featurefile, err)
    end

    println()

    istotalsuccess = issuccess(resultaccumulator)
    if istotalsuccess
        println("SUCCESS")
    else
        println("FAILURE")
    end

    istotalsuccess
end

"""
    suggestmissingsteps(featurepath::String, stepspath::String; parseoptions::ParseOptions=ParseOptions(), tagselector::String = "")

Find missing steps from the feature and print suggestions on step implementations to
match those missing steps.
"""
function suggestmissingsteps(
    featurepath::String,
    stepspath = joinpath(dirname(featurepath), "steps");
    parseoptions::ParseOptions=ParseOptions())

    # All of the below is quite hacky, which I'm motivating by the fact that
    # I just want something working. It most definitely indicates that I need to rework the whole
    # Driver/ExecutorEngine design.

    # -----------------------------------------------------------------------------
    # borrowed code from runspec; should be refactored later
    os = OSAL()

    engine = ExecutorEngine(QuietRealTimePresenter(); executionenv=NoExecutionEnvironment())
    driver = Driver(os, engine)

    readstepdefinitions!(driver, stepspath)
    # Parse the feature file and suggest missing steps.
    BadParseResultTypes = Union{Gherkin.BadParseResult{Feature}, Experimental.BadParseResult{Feature}}

    parseresult = if parseoptions.use_experimental
        println("WARNING: suggestmissingsteps is using the experimental Gherkin parser")
        input = ParserInput(read(featurepath, String))
        parser = Experimental.FeatureFileParser()
        parser(input)
    else
        parsefeature(read(featurepath, String), options=parseoptions)
    end
    if parseresult isa BadParseResultTypes
        println("Failed to parse feature file $featurepath")
        println(parseresult)
        return
    end

    feature = parseresult.value

    suggestedcode = suggestmissingsteps(driver.engine.executor, feature)
    println(suggestedcode)
end


text:
## utility functions ##

function valid_pvalues(x::AbstractVector{T}) where T <: AbstractFloat
    if !isin(x)
        throw(DomainError("p-values must all be in [0, 1]"))
    end
end

function isin(x::Real, lower::Real = 0., upper::Real = 1.)
    x >= lower && x <= upper
end

function isin(x::AbstractVector{T}, lower::Real = 0., upper::Real = 1.) where T <: Real
    ex = extrema(x)
    ex[1] >= lower && ex[2] <= upper
end

function isotonic_regression(y::AbstractVector{T}, weights::AbstractVector{T}) where T <: AbstractFloat
    n = length(y)
    if n <= 1
        return y
    end
    if n != length(weights)
        throw(DimensionMismatch("Lengths of values and weights mismatch"))
    end
    @inbounds begin
        n -= 1
        while true
            i = 1
            is_pooled = false
            while i <= n
                k = i
                while k <= n && y[k] >= y[k + 1]
                    k += 1
                end
                if y[i] != y[k]
                    numerator = 0.0
                    denominator = 0.0
                    for j in i:k
                        numerator += y[j] * weights[j]
                        denominator += weights[j]
                    end
                    m = numerator / denominator
                    for j in i:k
                        y[j] = m
                    end
                    is_pooled = true
                end
                i = k + 1
            end
            if !is_pooled
                break
            end
        end
    end
    return y
end

function isotonic_regression(y::AbstractVector{T}) where T <: AbstractFloat
    isotonic_regression(y, fill(1.0, size(y)))
end

function grenander(pv::AbstractVector{T}) where T <: AbstractFloat
    pv_sorted = sort(pv)
    # ecdf that handles duplicated values
    pv_sorted_unique, counts = rle(pv_sorted)
    ecdf_value = cumsum(counts)
    ecdf_value = ecdf_value ./ ecdf_value[end]

    Δx = diff(pv_sorted_unique)
    Δy = diff(ecdf_value)

    f = Δy ./ Δx
    f = -isotonic_regression(-f, Δx)
    F  = ecdf_value[1] .+ vcat(0, cumsum(f .* Δx))
    f = push!(f, f[end])

    return pv_sorted_unique, f, F
end


text:
module TestRainbowBrackets
using OhMyREPL

import OhMyREPL.Passes.RainbowBrackets.RAINBOWBRACKETS_SETTINGS

str = "(([[]] [[  {{ }}]])) ]] )) }}"
OhMyREPL.Passes.RainbowBrackets.activate_256colors()

OhMyREPL.test_pass(STDOUT, RAINBOWBRACKETS_SETTINGS, str)
println()
OhMyREPL.Passes.RainbowBrackets.activate_16colors()
OhMyREPL.test_pass(STDOUT, RAINBOWBRACKETS_SETTINGS, str)

end


text:
@testset "dist DSL (untyped)" begin
  # Test transformed distributions
  @dist f(x) = exp(normal(x, 0.001))
  @test isapprox(1, f(0); atol = 5)

  # Test relabeled distributions with labels provided as an Array
  @dist labeled_cat(labels, probs) = labels[categorical(probs)]
  @test labeled_cat([:a, :b], [0., 1.]) == :b
  @test isapprox(logpdf(labeled_cat, :b, [:a, :b], [0.5, 0.5]), log(0.5))
  @test logpdf(labeled_cat, :c, [:a, :b], [0.5, 0.5]) == -Inf

  # Test relabeled distributions with labels provided in a Dict
  dict = Dict(1 => :a, 2 => :b)
  @dist dict_cat(probs) = dict[categorical(probs)]
  @test dict_cat([0., 1.]) == :b
  @test isapprox(logpdf(dict_cat, :b, [0.5, 0.5]), log(0.5))
  @test logpdf(dict_cat, :c, [0.5, 0.5]) == -Inf

  # Test relabeled distributions with Enum labels
  @enum Fruit apple orange
  @dist enum_cat(probs) = Fruit(categorical(probs) - 1)
  @test enum_cat([0., 1.]) == orange
  @test isapprox(logpdf(enum_cat, orange, [0.5, 0.5]), log(0.5))
  @test logpdf(enum_cat, orange, [1.0]) == -Inf

  # Regression test for https://github.com/probcomp/Gen/issues/253
  @dist real_minus_uniform(a, b) = 1 - Gen.uniform(a, b)
  @test real_minus_uniform(1, 2) < 0
  @test logpdf(real_minus_uniform, -0.5, 1, 2) == 0.0
end

# User-defined type for testing purposes
struct MyLabel
  name::Symbol
end

@testset "dist DSL (typed)" begin
  # Test typed relabeled distributions
  @dist symbol_cat(labels::Vector{Symbol}, probs) = labels[categorical(probs)]
  @test symbol_cat([:a, :b], [0., 1.]) == :b
  @test_throws MethodError symbol_cat(["a", "b"], [0., 1.])
  @test logpdf(symbol_cat, :c, [:a, :b], [0.5, 0.5]) == -Inf
  @test_throws MethodError logpdf(symbol_cat, "c", [:a, :b], [0.5, 0.5])

  # Test typed parameters
  @dist int_bounded_uniform(low::Int, high::Int) = uniform(low, high)
  @test 0.0 <= int_bounded_uniform(0, 1) <= 1
  @test_throws MethodError int_bounded_uniform(-0.5, 0.5)
  @test logpdf(int_bounded_uniform, 0.5, 0, 1) == 0
  @test_throws MethodError logpdf(int_bounded_uniform, 0.0, -0.5, 0.5)

  # Test relabeled distributions with user-defined types
  @dist mylabel_cat(labels::Vector{MyLabel}, probs) = labels[categorical(probs)]
  @test mylabel_cat([MyLabel(:a), MyLabel(:b)], [0., 1.]) == MyLabel(:b)
  @test_throws MethodError mylabel_cat([:a, :b], [0., 1.])
  @test logpdf(mylabel_cat, MyLabel(:a), [MyLabel(:a)], [1.0]) == 0
  @test_throws MethodError logpdf(mylabel_cat, :a, [MyLabel(:a)], [1.0])
end