text:
int_rules_1_2_1_3 = @theory begin

    #= ::Subsection::Closed:: =#
    #= 1.2.1.3*(d+e*x)^m*(f+g*x)*(a+b*x+c*x^2)^p =#
    @apply_utils Antiderivative((~(e') * ~x) ^ ~(m') * (~f + ~(g') * ~x) * (~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => (~g * (~e * ~x) ^ ~m * (~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (~c * (~m + 2 * ~p + 2)) <-- FreeQ([~b, ~c, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ(~b * ~g * (~m + ~p + 1) - ~c * ~f * (~m + 2 * ~p + 2), 0) && NeQ(~m + 2 * ~p + 2, 0))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~f + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => ~f * Antiderivative((~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ ~p, ~x) + ~g * Antiderivative((~x) ^ (~m + 1) * (~a + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~c, ~f, ~g, ~p], ~x) && (IntegerQ(~m) && Not(IntegerQ(2 * ~p)))
    @apply_utils Antiderivative((~(e') * ~x) ^ ~(m') * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => Antiderivative(ExpandIntegrand((~e * ~x) ^ ~m * (~f + ~g * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~e, ~f, ~g, ~m], ~x) && (IntegerQ(~p) && (GtQ(~p, 0) || EqQ(~a, 0) && IntegerQ(~m)))
    @apply_utils Antiderivative((~(e') * ~x) ^ ~(m') * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => Antiderivative(ExpandIntegrand((~e * ~x) ^ ~m * (~f + ~g * ~x) * (~a + ~c * (~x) ^ 2) ^ ~p, ~x), ~x) <-- FreeQ([~a, ~c, ~e, ~f, ~g, ~m], ~x) && IGtQ(~p, 0)
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~(m') * (~f + ~(g') * ~x) * (~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => (-(~f) * ~g * (~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (~b * (~p + 1) * (~e * ~f - ~d * ~g)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (EqQ(~m + 2 * ~p + 3, 0) && EqQ(2 * ~c * ~f - ~b * ~g, 0)))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~(m') * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (~g * (~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * ~c * (~p + 1)) - ((~e * ~g * ~m) / (2 * ~c * (~p + 1))) * Antiderivative((~d + ~e * ~x) ^ (~m - 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (EqQ(2 * ~c * ~f - ~b * ~g, 0) && (LtQ(~p, -1) && GtQ(~m, 0)))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~(m') * (~(f') + ~(g') * ~x) * (~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (-2 * ~c * (~e * ~f - ~d * ~g) * (~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / ((~p + 1) * (2 * ~c * ~d - ~b * ~e) ^ 2) + ((2 * ~c * ~f - ~b * ~g) / (2 * ~c * ~d - ~b * ~e)) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (EqQ(~m + 2 * ~p + 3, 0) && (NeQ(2 * ~c * ~f - ~b * ~g, 0) && NeQ(2 * ~c * ~d - ~b * ~e, 0))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~(m') * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~a + ~b * ~x + ~c * (~x) ^ 2) ^ FracPart(~p) / ((~c) ^ IntPart(~p) * (~b / 2 + ~c * ~x) ^ (2 * FracPart(~p)))) * Antiderivative((~d + ~e * ~x) ^ ~m * (~f + ~g * ~x) * (~b / 2 + ~c * ~x) ^ (2 * ~p), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && EqQ((~b) ^ 2 - 4 * ~a * ~c, 0)
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~(m') * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => Antiderivative(ExpandIntegrand((~d + ~e * ~x) ^ ~m * (~f + ~g * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (IntegerQ(~p) && (GtQ(~p, 0) || EqQ(~a, 0) && IntegerQ(~m))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~(m') * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => Antiderivative(ExpandIntegrand((~d + ~e * ~x) ^ ~m * (~f + ~g * ~x) * (~a + ~c * (~x) ^ 2) ^ ~p, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && IGtQ(~p, 0)
    @apply_utils Antiderivative(((~(d') + ~(e') * ~x) * (~f + ~(g') * ~x)) / (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2), ~x) => (~e * ~g * ~x) / ~c + (1 / ~c) * Antiderivative(((~c * ~d * ~f - ~a * ~e * ~g) + ((~c * ~e * ~f + ~c * ~d * ~g) - ~b * ~e * ~g) * ~x) / (~a + ~b * ~x + ~c * (~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && NeQ((~b) ^ 2 - 4 * ~a * ~c, 0)
    @apply_utils Antiderivative(((~(d') + ~(e') * ~x) * (~f + ~(g') * ~x)) / (~a + ~(c') * (~x) ^ 2), ~x) => (~e * ~g * ~x) / ~c + (1 / ~c) * Antiderivative(((~c * ~d * ~f - ~a * ~e * ~g) + ~c * (~e * ~f + ~d * ~g) * ~x) / (~a + ~c * (~x) ^ 2), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x)
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (-(((~b * ~e * ~g * (~p + 2) - ~c * (~e * ~f + ~d * ~g) * (2 * ~p + 3)) - 2 * ~c * ~e * ~g * (~p + 1) * ~x)) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * (~c) ^ 2 * (~p + 1) * (2 * ~p + 3)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (EqQ(((~b) ^ 2 * ~e * ~g * (~p + 2) - 2 * ~a * ~c * ~e * ~g) + ~c * (2 * ~c * ~d * ~f - ~b * (~e * ~f + ~d * ~g)) * (2 * ~p + 3), 0) && NeQ(~p, -1)))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (((~e * ~f + ~d * ~g) * (2 * ~p + 3) + 2 * ~e * ~g * (~p + 1) * ~x) * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * ~c * (~p + 1) * (2 * ~p + 3)) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (EqQ(~a * ~e * ~g - ~c * ~d * ~f * (2 * ~p + 3), 0) && NeQ(~p, -1))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (-(((2 * ~a * ~c * (~e * ~f + ~d * ~g) - ~b * (~c * ~d * ~f + ~a * ~e * ~g)) - (((~b) ^ 2 * ~e * ~g - ~b * ~c * (~e * ~f + ~d * ~g)) + 2 * ~c * (~c * ~d * ~f - ~a * ~e * ~g)) * ~x)) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (~c * (~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c)) - ((((~b) ^ 2 * ~e * ~g * (~p + 2) - 2 * ~a * ~c * ~e * ~g) + ~c * (2 * ~c * ~d * ~f - ~b * (~e * ~f + ~d * ~g)) * (2 * ~p + 3)) / (~c * (~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && LtQ(~p, -1))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~a * (~e * ~f + ~d * ~g) - (~c * ~d * ~f - ~a * ~e * ~g) * ~x) * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * ~a * ~c * (~p + 1)) - ((~a * ~e * ~g - ~c * ~d * ~f * (2 * ~p + 3)) / (2 * ~a * ~c * (~p + 1))) * Antiderivative((~a + ~c * (~x) ^ 2) ^ (~p + 1), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x) && LtQ(~p, -1)
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (-(((~b * ~e * ~g * (~p + 2) - ~c * (~e * ~f + ~d * ~g) * (2 * ~p + 3)) - 2 * ~c * ~e * ~g * (~p + 1) * ~x)) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * (~c) ^ 2 * (~p + 1) * (2 * ~p + 3)) + ((((~b) ^ 2 * ~e * ~g * (~p + 2) - 2 * ~a * ~c * ~e * ~g) + ~c * (2 * ~c * ~d * ~f - ~b * (~e * ~f + ~d * ~g)) * (2 * ~p + 3)) / (2 * (~c) ^ 2 * (2 * ~p + 3))) * Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && Not(LeQ(~p, -1)))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (((~e * ~f + ~d * ~g) * (2 * ~p + 3) + 2 * ~e * ~g * (~p + 1) * ~x) * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * ~c * (~p + 1) * (2 * ~p + 3)) - ((~a * ~e * ~g - ~c * ~d * ~f * (2 * ~p + 3)) / (~c * (2 * ~p + 3))) * Antiderivative((~a + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && Not(LeQ(~p, -1))
    @apply_utils Antiderivative((~(e') * ~x) ^ ~(m') * (~(f') + ~(g') * ~x) * (~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => (1 / (~e) ^ ~p) * Antiderivative((~e * ~x) ^ (~m + ~p) * (~f + ~g * ~x) * (~b + ~c * ~x) ^ ~p, ~x) <-- FreeQ([~b, ~c, ~e, ~f, ~g, ~m], ~x) && IntegerQ(~p)
    @apply_utils Antiderivative((~d + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => Antiderivative((~d + ~e * ~x) ^ (~m + ~p) * (~f + ~g * ~x) * (~a / ~d + (~c / ~e) * ~x) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (EqQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && IntegerQ(~p)))
    @apply_utils Antiderivative((~d + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => Antiderivative((~d + ~e * ~x) ^ (~m + ~p) * (~f + ~g * ~x) * (~a / ~d + (~c / ~e) * ~x) ^ ~p, ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (EqQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (IntegerQ(~p) || GtQ(~a, 0) && (GtQ(~d, 0) && EqQ(~m + ~p, 0))))
    @apply_utils Antiderivative((~d + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (~d) ^ ~m * (~e) ^ ~m * Antiderivative(((~f + ~g * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~m + ~p)) / (~a * ~e + ~c * ~d * ~x) ^ ~m, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (EqQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (Not(IntegerQ(2 * ~p)) && ILtQ(~m, 0))))
    @apply_utils Antiderivative(~x * (~d + ~(e') * ~x) ^ ~m * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (~d) ^ ~m * (~e) ^ ~m * Antiderivative((~x * (~a + ~c * (~x) ^ 2) ^ (~m + ~p)) / (~a * ~e + ~c * ~d * ~x) ^ ~m, ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~p], ~x) && (EqQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (Not(IntegerQ(~p)) && (ILtQ(~m, 0) && (EqQ(~m, -1) && Not(ILtQ(~p - 1 / 2, 0))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (~g * (~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (~c * (~m + 2 * ~p + 2)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (EqQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && EqQ(~m * (~g * (~c * ~d - ~b * ~e) + ~c * ~e * ~f) + ~e * (~p + 1) * (2 * ~c * ~f - ~b * ~g), 0)))
    @apply_utils Antiderivative((~d + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (~g * (~d + ~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (~c * (~m + 2 * ~p + 2)) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && EqQ(~m * (~d * ~g + ~e * ~f) + 2 * ~e * ~f * (~p + 1), 0))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~g * (~c * ~d - ~b * ~e) + ~c * ~e * ~f) * (~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (~c * (~p + 1) * (2 * ~c * ~d - ~b * ~e)) - ((~e * (~m * (~g * (~c * ~d - ~b * ~e) + ~c * ~e * ~f) + ~e * (~p + 1) * (2 * ~c * ~f - ~b * ~g))) / (~c * (~p + 1) * (2 * ~c * ~d - ~b * ~e))) * Antiderivative((~d + ~e * ~x) ^ (~m - 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (EqQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (LtQ(~p, -1) && GtQ(~m, 0))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~d * ~g + ~e * ~f) * (~d + ~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * ~c * ~d * (~p + 1)) - ((~e * (~m * (~d * ~g + ~e * ~f) + 2 * ~e * ~f * (~p + 1))) / (2 * ~c * ~d * (~p + 1))) * Antiderivative((~d + ~e * ~x) ^ (~m - 1) * (~a + ~c * (~x) ^ 2) ^ (~p + 1), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x) && (EqQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (LtQ(~p, -1) && GtQ(~m, 0)))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~g * (~c * ~d - ~b * ~e) + ~c * ~e * ~f) * (~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (~c * (~p + 1) * (2 * ~c * ~d - ~b * ~e)) - ((~e * (~m * (~g * (~c * ~d - ~b * ~e) + ~c * ~e * ~f) + ~e * (~p + 1) * (2 * ~c * ~f - ~b * ~g))) / (~c * (~p + 1) * (2 * ~c * ~d - ~b * ~e))) * Antiderivative((~d + ~e * ~x) ^ Simplify(~m - 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ Simplify(~p + 1), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (EqQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (SumSimplerQ(~p, 1) && (SumSimplerQ(~m, -1) && NeQ(~p, -1)))))
    @apply_utils Antiderivative((~d + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~d * ~g + ~e * ~f) * (~d + ~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * ~c * ~d * (~p + 1)) - ((~e * (~m * (~d * ~g + ~e * ~f) + 2 * ~e * ~f * (~p + 1))) / (2 * ~c * ~d * (~p + 1))) * Antiderivative((~d + ~e * ~x) ^ Simplify(~m - 1) * (~a + ~c * (~x) ^ 2) ^ Simplify(~p + 1), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (SumSimplerQ(~p, 1) && (SumSimplerQ(~m, -1) && (NeQ(~p, -1) && Not(IGtQ(~m, 0))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~d * ~g - ~e * ~f) * (~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / ((2 * ~c * ~d - ~b * ~e) * (~m + ~p + 1)) + ((~m * (~g * (~c * ~d - ~b * ~e) + ~c * ~e * ~f) + ~e * (~p + 1) * (2 * ~c * ~f - ~b * ~g)) / (~e * (2 * ~c * ~d - ~b * ~e) * (~m + ~p + 1))) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (EqQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && ((LtQ(~m, -1) && Not(IGtQ(~m + ~p + 1, 0)) || (LtQ(~m, 0) && LtQ(~p, -1) || EqQ(~m + 2 * ~p + 2, 0))) && NeQ(~m + ~p + 1, 0))))
    @apply_utils Antiderivative((~d + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~d * ~g - ~e * ~f) * (~d + ~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * ~c * ~d * (~m + ~p + 1)) + ((~m * (~g * ~c * ~d + ~c * ~e * ~f) + 2 * ~e * ~c * ~f * (~p + 1)) / (~e * (2 * ~c * ~d) * (~m + ~p + 1))) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && ((LtQ(~m, -1) && Not(IGtQ(~m + ~p + 1, 0)) || (LtQ(~m, 0) && LtQ(~p, -1) || EqQ(~m + 2 * ~p + 2, 0))) && NeQ(~m + ~p + 1, 0)))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (~g * (~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (~c * (~m + 2 * ~p + 2)) + ((~m * (~g * (~c * ~d - ~b * ~e) + ~c * ~e * ~f) + ~e * (~p + 1) * (2 * ~c * ~f - ~b * ~g)) / (~c * ~e * (~m + 2 * ~p + 2))) * Antiderivative((~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (EqQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (NeQ(~m + 2 * ~p + 2, 0) && (NeQ(~m, 2) || EqQ(~d, 0)))))
    @apply_utils Antiderivative((~d + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (~g * (~d + ~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (~c * (~m + 2 * ~p + 2)) + ((~m * (~d * ~g + ~e * ~f) + 2 * ~e * ~f * (~p + 1)) / (~e * (~m + 2 * ~p + 2))) * Antiderivative((~d + ~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (NeQ(~m + 2 * ~p + 2, 0) && NeQ(~m, 2)))
    @apply_utils Antiderivative((~x) ^ 2 * (~f + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~x) ^ 2 * (~a * ~g - ~c * ~f * ~x) * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * ~a * ~c * (~p + 1)) - (1 / (2 * ~a * ~c * (~p + 1))) * Antiderivative(~x * Simp(2 * ~a * ~g - ~c * ~f * (2 * ~p + 5) * ~x, ~x) * (~a + ~c * (~x) ^ 2) ^ (~p + 1), ~x) <-- FreeQ([~a, ~c, ~f, ~g], ~x) && (EqQ(~a * (~g) ^ 2 + (~f) ^ 2 * ~c, 0) && LtQ(~p, -2))
    @apply_utils Antiderivative((~x) ^ 2 * (~f + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (1 / ~c) * Antiderivative((~f + ~g * ~x) * (~a + ~c * (~x) ^ 2) ^ (~p + 1), ~x) - (~a / ~c) * Antiderivative((~f + ~g * ~x) * (~a + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~c, ~f, ~g, ~p], ~x) && EqQ(~a * (~g) ^ 2 + (~f) ^ 2 * ~c, 0)
    @apply_utils Antiderivative((~d + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => Antiderivative((~d + ~e * ~x) ^ ~m * (~f + ~g * ~x) ^ (~p + 1) * (~a / ~f + (~c / ~g) * ~x) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (EqQ((~c * (~f) ^ 2 - ~b * ~f * ~g) + ~a * (~g) ^ 2, 0) && IntegerQ(~p)))
    @apply_utils Antiderivative((~d + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => Antiderivative((~d + ~e * ~x) ^ ~m * (~f + ~g * ~x) ^ (~p + 1) * (~a / ~f + (~c / ~g) * ~x) ^ ~p, ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (EqQ(~c * (~f) ^ 2 + ~a * (~g) ^ 2, 0) && (IntegerQ(~p) || GtQ(~a, 0) && (GtQ(~f, 0) && EqQ(~p, -1))))
    @apply_utils Antiderivative(((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x)) / (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2), ~x) => Antiderivative(ExpandIntegrand(((~d + ~e * ~x) ^ ~m * (~f + ~g * ~x)) / (~a + ~b * ~x + ~c * (~x) ^ 2), ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && IntegerQ(~m)))
    @apply_utils Antiderivative(((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x)) / (~a + ~(c') * (~x) ^ 2), ~x) => Antiderivative(ExpandIntegrand(((~d + ~e * ~x) ^ ~m * (~f + ~g * ~x)) / (~a + ~c * (~x) ^ 2), ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && IntegerQ(~m))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => (-((~e * ~f - ~d * ~g)) * (~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * (~p + 1) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (EqQ(Simplify(~m + 2 * ~p + 3), 0) && EqQ(~b * (~e * ~f + ~d * ~g) - 2 * (~c * ~d * ~f + ~a * ~e * ~g), 0))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => (-((~e * ~f - ~d * ~g)) * (~d + ~e * ~x) ^ (~m + 1) * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * (~p + 1) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2)) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (EqQ(Simplify(~m + 2 * ~p + 3), 0) && EqQ(~c * ~d * ~f + ~a * ~e * ~g, 0)))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * ((~b * ~f - 2 * ~a * ~g) + (2 * ~c * ~f - ~b * ~g) * ~x)) / ((~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c)) - ((~m * (~b * (~e * ~f + ~d * ~g) - 2 * (~c * ~d * ~f + ~a * ~e * ~g))) / ((~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c))) * Antiderivative((~d + ~e * ~x) ^ (~m - 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (EqQ(Simplify(~m + 2 * ~p + 3), 0) && LtQ(~p, -1))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~d + ~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ (~p + 1) * (~a * ~g - ~c * ~f * ~x)) / (2 * ~a * ~c * (~p + 1)) - ((~m * (~c * ~d * ~f + ~a * ~e * ~g)) / (2 * ~a * ~c * (~p + 1))) * Antiderivative((~d + ~e * ~x) ^ (~m - 1) * (~a + ~c * (~x) ^ 2) ^ (~p + 1), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (EqQ(Simplify(~m + 2 * ~p + 3), 0) && LtQ(~p, -1)))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => (-((~e * ~f - ~d * ~g)) * (~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * (~p + 1) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2)) - ((~b * (~e * ~f + ~d * ~g) - 2 * (~c * ~d * ~f + ~a * ~e * ~g)) / (2 * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2))) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && EqQ(Simplify(~m + 2 * ~p + 3), 0)))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => (-((~e * ~f - ~d * ~g)) * (~d + ~e * ~x) ^ (~m + 1) * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * (~p + 1) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2)) + ((~c * ~d * ~f + ~a * ~e * ~g) / (~c * (~d) ^ 2 + ~a * (~e) ^ 2)) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && EqQ(Simplify(~m + 2 * ~p + 3), 0))
    @apply_utils Antiderivative((~(e') * ~x) ^ ~m * (~f + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ~f * Antiderivative((~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ ~p, ~x) + (~g / ~e) * Antiderivative((~e * ~x) ^ (~m + 1) * (~a + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~c, ~e, ~f, ~g, ~p], ~x) && (Not(RationalQ(~m)) && Not(IGtQ(~p, 0)))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (((~d + ~e * ~x) ^ FracPart(~p) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ FracPart(~p)) / (~a * ~d + ~c * ~e * (~x) ^ 3) ^ FracPart(~p)) * Antiderivative((~f + ~g * ~x) * (~a * ~d + ~c * ~e * (~x) ^ 3) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (EqQ(~m, ~p) && (EqQ(~b * ~d + ~a * ~e, 0) && EqQ(~c * ~d + ~b * ~e, 0)))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => ((-((~d + ~e * ~x) ^ (~m + 1)) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p) / ((~e) ^ 2 * (~m + 1) * (~m + 2) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2))) * (((~d * ~g - ~e * ~f * (~m + 2)) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2) - ~d * ~p * (2 * ~c * ~d - ~b * ~e) * (~e * ~f - ~d * ~g)) - ~e * (~g * (~m + 1) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2) + ~p * (2 * ~c * ~d - ~b * ~e) * (~e * ~f - ~d * ~g)) * ~x) - (~p / ((~e) ^ 2 * (~m + 1) * (~m + 2) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2))) * Antiderivative((~d + ~e * ~x) ^ (~m + 2) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p - 1) * Simp((2 * ~a * ~c * ~e * (~e * ~f - ~d * ~g) * (~m + 2) + (~b) ^ 2 * ~e * (~d * ~g * (~p + 1) - ~e * ~f * (~m + ~p + 2)) + ~b * (~a * (~e) ^ 2 * ~g * (~m + 1) - ~c * ~d * (~d * ~g * (2 * ~p + 1) - ~e * ~f * (~m + 2 * ~p + 2)))) - ~c * (2 * ~c * ~d * (~d * ~g * (2 * ~p + 1) - ~e * ~f * (~m + 2 * ~p + 2)) - ~e * (2 * ~a * ~e * ~g * (~m + 1) - ~b * (~d * ~g * (~m - 2 * ~p) + ~e * ~f * (~m + 2 * ~p + 2)))) * ~x, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (GtQ(~p, 0) && (LtQ(~m, -2) && (LtQ(~m + 2 * ~p, 0) && Not(ILtQ(~m + 2 * ~p + 3, 0)))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => ((-((~d + ~e * ~x) ^ (~m + 1)) * (~a + ~c * (~x) ^ 2) ^ ~p) / ((~e) ^ 2 * (~m + 1) * (~m + 2) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2))) * (((~d * ~g - ~e * ~f * (~m + 2)) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2) - 2 * ~c * (~d) ^ 2 * ~p * (~e * ~f - ~d * ~g)) - ~e * (~g * (~m + 1) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2) + 2 * ~c * ~d * ~p * (~e * ~f - ~d * ~g)) * ~x) - (~p / ((~e) ^ 2 * (~m + 1) * (~m + 2) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2))) * Antiderivative((~d + ~e * ~x) ^ (~m + 2) * (~a + ~c * (~x) ^ 2) ^ (~p - 1) * Simp(2 * ~a * ~c * ~e * (~e * ~f - ~d * ~g) * (~m + 2) - ~c * (2 * ~c * ~d * (~d * ~g * (2 * ~p + 1) - ~e * ~f * (~m + 2 * ~p + 2)) - 2 * ~a * (~e) ^ 2 * ~g * (~m + 1)) * ~x, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (GtQ(~p, 0) && (LtQ(~m, -2) && (LtQ(~m + 2 * ~p, 0) && Not(ILtQ(~m + 2 * ~p + 3, 0))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => ((~d + ~e * ~x) ^ (~m + 1) * ((~e * ~f * (~m + 2 * ~p + 2) - ~d * ~g * (2 * ~p + 1)) + ~e * ~g * (~m + 1) * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p) / ((~e) ^ 2 * (~m + 1) * (~m + 2 * ~p + 2)) + (~p / ((~e) ^ 2 * (~m + 1) * (~m + 2 * ~p + 2))) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p - 1) * Simp((~g * (~b * ~d + 2 * ~a * ~e + 2 * ~a * ~e * ~m + 2 * ~b * ~d * ~p) - ~f * ~b * ~e * (~m + 2 * ~p + 2)) + (~g * (2 * ~c * ~d + ~b * ~e + ~b * ~e * ~m + 4 * ~c * ~d * ~p) - 2 * ~c * ~e * ~f * (~m + 2 * ~p + 2)) * ~x, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (RationalQ(~p) && (~p > 0 && ((LtQ(~m, -1) || (EqQ(~p, 1) || IntegerQ(~p) && Not(RationalQ(~m)))) && (NeQ(~m, -1) && (Not(ILtQ(~m + 2 * ~p + 1, 0)) && (IntegerQ(~m) || (IntegerQ(~p) || IntegersQ(2 * ~m, 2 * ~p))))))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => ((~d + ~e * ~x) ^ (~m + 1) * ((~e * ~f * (~m + 2 * ~p + 2) - ~d * ~g * (2 * ~p + 1)) + ~e * ~g * (~m + 1) * ~x) * (~a + ~c * (~x) ^ 2) ^ ~p) / ((~e) ^ 2 * (~m + 1) * (~m + 2 * ~p + 2)) + (~p / ((~e) ^ 2 * (~m + 1) * (~m + 2 * ~p + 2))) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~c * (~x) ^ 2) ^ (~p - 1) * Simp(~g * (2 * ~a * ~e + 2 * ~a * ~e * ~m) + (~g * (2 * ~c * ~d + 4 * ~c * ~d * ~p) - 2 * ~c * ~e * ~f * (~m + 2 * ~p + 2)) * ~x, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (RationalQ(~p) && (~p > 0 && ((LtQ(~m, -1) || (EqQ(~p, 1) || IntegerQ(~p) && Not(RationalQ(~m)))) && (NeQ(~m, -1) && (Not(ILtQ(~m + 2 * ~p + 1, 0)) && (IntegerQ(~m) || (IntegerQ(~p) || IntegersQ(2 * ~m, 2 * ~p)))))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => ((~d + ~e * ~x) ^ (~m + 1) * ((~c * ~e * ~f * (~m + 2 * ~p + 2) - ~g * ((~c * ~d + 2 * ~c * ~d * ~p) - ~b * ~e * ~p)) + ~g * ~c * ~e * (~m + 2 * ~p + 1) * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p) / (~c * (~e) ^ 2 * (~m + 2 * ~p + 1) * (~m + 2 * ~p + 2)) - (~p / (~c * (~e) ^ 2 * (~m + 2 * ~p + 1) * (~m + 2 * ~p + 2))) * Antiderivative((~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p - 1) * Simp(~c * ~e * ~f * (~b * ~d - 2 * ~a * ~e) * (~m + 2 * ~p + 2) + ~g * (~a * ~e * ((~b * ~e - 2 * ~c * ~d * ~m) + ~b * ~e * ~m) + ~b * ~d * ((~b * ~e * ~p - ~c * ~d) - 2 * ~c * ~d * ~p)) + (~c * ~e * ~f * (2 * ~c * ~d - ~b * ~e) * (~m + 2 * ~p + 2) + ~g * (((~b) ^ 2 * (~e) ^ 2 * (~p + ~m + 1) - 2 * (~c) ^ 2 * (~d) ^ 2 * (1 + 2 * ~p)) - ~c * ~e * (~b * ~d * (~m - 2 * ~p) + 2 * ~a * ~e * (~m + 2 * ~p + 1)))) * ~x, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (GtQ(~p, 0) && ((IntegerQ(~p) || (Not(RationalQ(~m)) || GeQ(~m, -1) && LtQ(~m, 0))) && (Not(ILtQ(~m + 2 * ~p, 0)) && (IntegerQ(~m) || (IntegerQ(~p) || IntegersQ(2 * ~m, 2 * ~p))))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => ((~d + ~e * ~x) ^ (~m + 1) * ((~c * ~e * ~f * (~m + 2 * ~p + 2) - ~g * ~c * ~d * (2 * ~p + 1)) + ~g * ~c * ~e * (~m + 2 * ~p + 1) * ~x) * (~a + ~c * (~x) ^ 2) ^ ~p) / (~c * (~e) ^ 2 * (~m + 2 * ~p + 1) * (~m + 2 * ~p + 2)) + ((2 * ~p) / (~c * (~e) ^ 2 * (~m + 2 * ~p + 1) * (~m + 2 * ~p + 2))) * Antiderivative((~d + ~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ (~p - 1) * Simp((~f * ~a * ~c * (~e) ^ 2 * (~m + 2 * ~p + 2) + ~a * ~c * ~d * ~e * ~g * ~m) - ((~c) ^ 2 * ~f * ~d * ~e * (~m + 2 * ~p + 2) - ~g * ((~c) ^ 2 * (~d) ^ 2 * (2 * ~p + 1) + ~a * ~c * (~e) ^ 2 * (~m + 2 * ~p + 1))) * ~x, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (GtQ(~p, 0) && ((IntegerQ(~p) || (Not(RationalQ(~m)) || GeQ(~m, -1) && LtQ(~m, 0))) && (Not(ILtQ(~m + 2 * ~p, 0)) && (IntegerQ(~m) || (IntegerQ(~p) || IntegersQ(2 * ~m, 2 * ~p)))))))
    @apply_utils Antiderivative((~d + ~(e') * ~x) ^ ~m * (~f + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => Antiderivative((~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p * ExpandIntegrand((~d + ~e * ~x) ^ ~m * (~f + ~g * ~x), ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (ILtQ(~p, -1) && (IGtQ(~m, 0) && RationalQ(~a, ~b, ~c, ~d, ~e, ~f, ~g)))))
    @apply_utils Antiderivative((~d + ~(e') * ~x) ^ ~m * (~f + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => Antiderivative((~a + ~c * (~x) ^ 2) ^ ~p * ExpandIntegrand((~d + ~e * ~x) ^ ~m * (~f + ~g * ~x), ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (ILtQ(~p, -1) && (IGtQ(~m, 0) && RationalQ(~a, ~c, ~d, ~e, ~f, ~g))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => (-((~d + ~e * ~x) ^ (~m - 1)) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * ((2 * ~a * ~c * (~e * ~f + ~d * ~g) - ~b * (~c * ~d * ~f + ~a * ~e * ~g)) - ((2 * (~c) ^ 2 * ~d * ~f + (~b) ^ 2 * ~e * ~g) - ~c * (~b * ~e * ~f + ~b * ~d * ~g + 2 * ~a * ~e * ~g)) * ~x)) / (~c * (~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c)) - (1 / (~c * (~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c))) * Antiderivative((~d + ~e * ~x) ^ (~m - 2) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * Simp(((2 * (~c) ^ 2 * (~d) ^ 2 * ~f * (2 * ~p + 3) + ~b * ~e * ~g * (~a * ~e * (~m - 1) + ~b * ~d * (~p + 2))) - ~c * (2 * ~a * ~e * (~e * ~f * (~m - 1) + ~d * ~g * ~m) + ~b * ~d * (~d * ~g * (2 * ~p + 3) - ~e * ~f * ((~m - 2 * ~p) - 4)))) + ~e * (((~b) ^ 2 * ~e * ~g * (~m + ~p + 1) + 2 * (~c) ^ 2 * ~d * ~f * (~m + 2 * ~p + 2)) - ~c * (2 * ~a * ~e * ~g * ~m + ~b * (~e * ~f + ~d * ~g) * (~m + 2 * ~p + 2))) * ~x, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (LtQ(~p, -1) && (GtQ(~m, 1) && (EqQ(~m, 2) && (EqQ(~p, -3) && RationalQ(~a, ~b, ~c, ~d, ~e, ~f, ~g)) || Not(ILtQ(~m + 2 * ~p + 3, 0)))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => ((~d + ~e * ~x) ^ (~m - 1) * (~a + ~c * (~x) ^ 2) ^ (~p + 1) * (~a * (~e * ~f + ~d * ~g) - (~c * ~d * ~f - ~a * ~e * ~g) * ~x)) / (2 * ~a * ~c * (~p + 1)) - (1 / (2 * ~a * ~c * (~p + 1))) * Antiderivative((~d + ~e * ~x) ^ (~m - 2) * (~a + ~c * (~x) ^ 2) ^ (~p + 1) * Simp((~a * ~e * (~e * ~f * (~m - 1) + ~d * ~g * ~m) - ~c * (~d) ^ 2 * ~f * (2 * ~p + 3)) + ~e * (~a * ~e * ~g * ~m - ~c * ~d * ~f * (~m + 2 * ~p + 2)) * ~x, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (LtQ(~p, -1) && (GtQ(~m, 1) && (EqQ(~d, 0) || (EqQ(~m, 2) && (EqQ(~p, -3) && RationalQ(~a, ~c, ~d, ~e, ~f, ~g)) || Not(ILtQ(~m + 2 * ~p + 3, 0)))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * ((~f * ~b - 2 * ~a * ~g) + (2 * ~c * ~f - ~b * ~g) * ~x)) / ((~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c)) + (1 / ((~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c))) * Antiderivative((~d + ~e * ~x) ^ (~m - 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * Simp((~g * (2 * ~a * ~e * ~m + ~b * ~d * (2 * ~p + 3)) - ~f * (~b * ~e * ~m + 2 * ~c * ~d * (2 * ~p + 3))) - ~e * (2 * ~c * ~f - ~b * ~g) * (~m + 2 * ~p + 3) * ~x, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (LtQ(~p, -1) && (GtQ(~m, 0) && (IntegerQ(~m) || (IntegerQ(~p) || IntegersQ(2 * ~m, 2 * ~p)))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~d + ~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ (~p + 1) * (~a * ~g - ~c * ~f * ~x)) / (2 * ~a * ~c * (~p + 1)) - (1 / (2 * ~a * ~c * (~p + 1))) * Antiderivative((~d + ~e * ~x) ^ (~m - 1) * (~a + ~c * (~x) ^ 2) ^ (~p + 1) * Simp((~a * ~e * ~g * ~m - ~c * ~d * ~f * (2 * ~p + 3)) - ~c * ~e * ~f * (~m + 2 * ~p + 3) * ~x, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (LtQ(~p, -1) && (GtQ(~m, 0) && (IntegerQ(~m) || (IntegerQ(~p) || IntegersQ(2 * ~m, 2 * ~p))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~p, ~x) => ((~d + ~e * ~x) ^ (~m + 1) * ((~f * ((~b * ~c * ~d - (~b) ^ 2 * ~e) + 2 * ~a * ~c * ~e) - ~a * ~g * (2 * ~c * ~d - ~b * ~e)) + ~c * (~f * (2 * ~c * ~d - ~b * ~e) - ~g * (~b * ~d - 2 * ~a * ~e)) * ~x) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / ((~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2)) + (1 / ((~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2))) * Antiderivative((~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1) * Simp((~f * (((~b * ~c * ~d * ~e * ((2 * ~p - ~m) + 2) + (~b) ^ 2 * (~e) ^ 2 * (~p + ~m + 2)) - 2 * (~c) ^ 2 * (~d) ^ 2 * (2 * ~p + 3)) - 2 * ~a * ~c * (~e) ^ 2 * (~m + 2 * ~p + 3)) - ~g * (~a * ~e * ((~b * ~e - 2 * ~c * ~d * ~m) + ~b * ~e * ~m) - ~b * ~d * (((3 * ~c * ~d - ~b * ~e) + 2 * ~c * ~d * ~p) - ~b * ~e * ~p))) + ~c * ~e * (~g * (~b * ~d - 2 * ~a * ~e) - ~f * (2 * ~c * ~d - ~b * ~e)) * (~m + 2 * ~p + 4) * ~x, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (LtQ(~p, -1) && (IntegerQ(~m) || (IntegerQ(~p) || IntegersQ(2 * ~m, 2 * ~p))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~p, ~x) => (-((~d + ~e * ~x) ^ (~m + 1)) * ((~f * ~a * ~c * ~e - ~a * ~g * ~c * ~d) + ~c * (~c * ~d * ~f + ~a * ~e * ~g) * ~x) * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (2 * ~a * ~c * (~p + 1) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2)) + (1 / (2 * ~a * ~c * (~p + 1) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2))) * Antiderivative((~d + ~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ (~p + 1) * Simp((~f * ((~c) ^ 2 * (~d) ^ 2 * (2 * ~p + 3) + ~a * ~c * (~e) ^ 2 * (~m + 2 * ~p + 3)) - ~a * ~c * ~d * ~e * ~g * ~m) + ~c * ~e * (~c * ~d * ~f + ~a * ~e * ~g) * (~m + 2 * ~p + 4) * ~x, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (LtQ(~p, -1) && (IntegerQ(~m) || (IntegerQ(~p) || IntegersQ(2 * ~m, 2 * ~p)))))
    @apply_utils Antiderivative(((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x)) / (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2), ~x) => (~g * (~d + ~e * ~x) ^ ~m) / (~c * ~m) + (1 / ~c) * Antiderivative(((~d + ~e * ~x) ^ (~m - 1) * Simp((~c * ~d * ~f - ~a * ~e * ~g) + ((~g * ~c * ~d - ~b * ~e * ~g) + ~c * ~e * ~f) * ~x, ~x)) / (~a + ~b * ~x + ~c * (~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (FractionQ(~m) && GtQ(~m, 0))))
    @apply_utils Antiderivative(((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x)) / (~a + ~(c') * (~x) ^ 2), ~x) => (~g * (~d + ~e * ~x) ^ ~m) / (~c * ~m) + (1 / ~c) * Antiderivative(((~d + ~e * ~x) ^ (~m - 1) * Simp((~c * ~d * ~f - ~a * ~e * ~g) + (~g * ~c * ~d + ~c * ~e * ~f) * ~x, ~x)) / (~a + ~c * (~x) ^ 2), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (FractionQ(~m) && GtQ(~m, 0)))
    @apply_utils Antiderivative((~(f') + ~(g') * ~x) / (sqrt(~(d') + ~(e') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2)), ~x) => 2 * Subst(Antiderivative(((~e * ~f - ~d * ~g) + ~g * (~x) ^ 2) / ((((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2) - (2 * ~c * ~d - ~b * ~e) * (~x) ^ 2) + ~c * (~x) ^ 4), ~x), ~x, sqrt(~d + ~e * ~x)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0))
    @apply_utils Antiderivative((~(f') + ~(g') * ~x) / (sqrt(~(d') + ~(e') * ~x) * (~a + ~(c') * (~x) ^ 2)), ~x) => 2 * Subst(Antiderivative(((~e * ~f - ~d * ~g) + ~g * (~x) ^ 2) / (((~c * (~d) ^ 2 + ~a * (~e) ^ 2) - 2 * ~c * ~d * (~x) ^ 2) + ~c * (~x) ^ 4), ~x), ~x, sqrt(~d + ~e * ~x)) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x) && NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0)
    @apply_utils Antiderivative(((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x)) / (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2), ~x) => ((~e * ~f - ~d * ~g) * (~d + ~e * ~x) ^ (~m + 1)) / ((~m + 1) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2)) + (1 / ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2)) * Antiderivative(((~d + ~e * ~x) ^ (~m + 1) * Simp(((~c * ~d * ~f - ~f * ~b * ~e) + ~a * ~e * ~g) - ~c * (~e * ~f - ~d * ~g) * ~x, ~x)) / (~a + ~b * ~x + ~c * (~x) ^ 2), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (FractionQ(~m) && LtQ(~m, -1))))
    @apply_utils Antiderivative(((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x)) / (~a + ~(c') * (~x) ^ 2), ~x) => ((~e * ~f - ~d * ~g) * (~d + ~e * ~x) ^ (~m + 1)) / ((~m + 1) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2)) + (1 / (~c * (~d) ^ 2 + ~a * (~e) ^ 2)) * Antiderivative(((~d + ~e * ~x) ^ (~m + 1) * Simp((~c * ~d * ~f + ~a * ~e * ~g) - ~c * (~e * ~f - ~d * ~g) * ~x, ~x)) / (~a + ~c * (~x) ^ 2), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (FractionQ(~m) && LtQ(~m, -1)))
    @apply_utils Antiderivative(((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x)) / (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2), ~x) => Antiderivative(ExpandIntegrand((~d + ~e * ~x) ^ ~m, (~f + ~g * ~x) / (~a + ~b * ~x + ~c * (~x) ^ 2), ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && Not(RationalQ(~m))))
    @apply_utils Antiderivative(((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x)) / (~a + ~(c') * (~x) ^ 2), ~x) => Antiderivative(ExpandIntegrand((~d + ~e * ~x) ^ ~m, (~f + ~g * ~x) / (~a + ~c * (~x) ^ 2), ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && Not(RationalQ(~m)))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => (~g * (~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / (~c * (~m + 2 * ~p + 2)) + (1 / (~c * (~m + 2 * ~p + 2))) * Antiderivative((~d + ~e * ~x) ^ (~m - 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p * Simp(~m * (~c * ~d * ~f - ~a * ~e * ~g) + ~d * (2 * ~c * ~f - ~b * ~g) * (~p + 1) + (~m * ((~c * ~e * ~f + ~c * ~d * ~g) - ~b * ~e * ~g) + ~e * (~p + 1) * (2 * ~c * ~f - ~b * ~g)) * ~x, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (GtQ(~m, 0) && (NeQ(~m + 2 * ~p + 2, 0) && ((IntegerQ(~m) || (IntegerQ(~p) || IntegersQ(2 * ~m, 2 * ~p))) && Not(IGtQ(~m, 0) && EqQ(~f, 0)))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => (~g * (~d + ~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / (~c * (~m + 2 * ~p + 2)) + (1 / (~c * (~m + 2 * ~p + 2))) * Antiderivative((~d + ~e * ~x) ^ (~m - 1) * (~a + ~c * (~x) ^ 2) ^ ~p * Simp((~c * ~d * ~f * (~m + 2 * ~p + 2) - ~a * ~e * ~g * ~m) + ~c * (~e * ~f * (~m + 2 * ~p + 2) + ~d * ~g * ~m) * ~x, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (GtQ(~m, 0) && (NeQ(~m + 2 * ~p + 2, 0) && ((IntegerQ(~m) || (IntegerQ(~p) || IntegersQ(2 * ~m, 2 * ~p))) && Not(IGtQ(~m, 0) && EqQ(~f, 0))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => ((~e * ~f - ~d * ~g) * (~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / ((~m + 1) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2)) + (1 / ((~m + 1) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2))) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p * Simp((((~c * ~d * ~f - ~f * ~b * ~e) + ~a * ~e * ~g) * (~m + 1) + ~b * (~d * ~g - ~e * ~f) * (~p + 1)) - ~c * (~e * ~f - ~d * ~g) * (~m + 2 * ~p + 3) * ~x, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (LtQ(~m, -1) && (IntegerQ(~m) || (IntegerQ(~p) || IntegersQ(2 * ~m, 2 * ~p))))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => ((~e * ~f - ~d * ~g) * (~d + ~e * ~x) ^ (~m + 1) * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / ((~m + 1) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2)) + (1 / ((~m + 1) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2))) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~c * (~x) ^ 2) ^ ~p * Simp((~c * ~d * ~f + ~a * ~e * ~g) * (~m + 1) - ~c * (~e * ~f - ~d * ~g) * (~m + 2 * ~p + 3) * ~x, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~p], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (LtQ(~m, -1) && (IntegerQ(~m) || (IntegerQ(~p) || IntegersQ(2 * ~m, 2 * ~p)))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => ((~e * ~f - ~d * ~g) * (~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ (~p + 1)) / ((~m + 1) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2)) + (1 / ((~m + 1) * ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2))) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p * Simp((((~c * ~d * ~f - ~f * ~b * ~e) + ~a * ~e * ~g) * (~m + 1) + ~b * (~d * ~g - ~e * ~f) * (~p + 1)) - ~c * (~e * ~f - ~d * ~g) * (~m + 2 * ~p + 3) * ~x, ~x), ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && (ILtQ(Simplify(~m + 2 * ~p + 3), 0) && NeQ(~m, -1))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => ((~e * ~f - ~d * ~g) * (~d + ~e * ~x) ^ (~m + 1) * (~a + ~c * (~x) ^ 2) ^ (~p + 1)) / ((~m + 1) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2)) + (1 / ((~m + 1) * (~c * (~d) ^ 2 + ~a * (~e) ^ 2))) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~c * (~x) ^ 2) ^ ~p * Simp((~c * ~d * ~f + ~a * ~e * ~g) * (~m + 1) - ~c * (~e * ~f - ~d * ~g) * (~m + 2 * ~p + 3) * ~x, ~x), ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && (ILtQ(Simplify(~m + 2 * ~p + 3), 0) && NeQ(~m, -1)))
    @apply_utils Antiderivative((~f + ~(g') * ~x) / ((~(d') + ~(e') * ~x) * sqrt(~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2)), ~x) => ((4 * ~f * (~a - ~d)) / (~b * ~d - ~a * ~e)) * Subst(Antiderivative(1 / (4 * (~a - ~d) - (~x) ^ 2), ~x), ~x, (2 * (~a - ~d) + (~b - ~e) * ~x) / sqrt(~a + ~b * ~x + ~c * (~x) ^ 2)) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g], ~x) && (EqQ(4 * ~c * (~a - ~d) - (~b - ~e) ^ 2, 0) && (EqQ(~e * ~f * (~b - ~e) - 2 * ~g * (~b * ~d - ~a * ~e), 0) && NeQ(~b * ~d - ~a * ~e, 0)))
    @apply_utils Antiderivative((~f + ~(g') * ~x) / (sqrt(~x) * sqrt(~a + ~(b') * ~x + ~(c') * (~x) ^ 2)), ~x) => 2 * Subst(Antiderivative((~f + ~g * (~x) ^ 2) / sqrt(~a + ~b * (~x) ^ 2 + ~c * (~x) ^ 4), ~x), ~x, sqrt(~x)) <-- FreeQ([~a, ~b, ~c, ~f, ~g], ~x) && NeQ((~b) ^ 2 - 4 * ~a * ~c, 0)
    @apply_utils Antiderivative((~f + ~(g') * ~x) / (sqrt(~x) * sqrt(~a + ~(c') * (~x) ^ 2)), ~x) => 2 * Subst(Antiderivative((~f + ~g * (~x) ^ 2) / sqrt(~a + ~c * (~x) ^ 4), ~x), ~x, sqrt(~x)) <-- FreeQ([~a, ~c, ~f, ~g], ~x)
    @apply_utils Antiderivative((~f + ~(g') * ~x) / (sqrt(~e * ~x) * sqrt(~a + ~(b') * ~x + ~(c') * (~x) ^ 2)), ~x) => (sqrt(~x) / sqrt(~e * ~x)) * Antiderivative((~f + ~g * ~x) / (sqrt(~x) * sqrt(~a + ~b * ~x + ~c * (~x) ^ 2)), ~x) <-- FreeQ([~a, ~b, ~c, ~e, ~f, ~g], ~x) && NeQ((~b) ^ 2 - 4 * ~a * ~c, 0)
    @apply_utils Antiderivative((~f + ~(g') * ~x) / (sqrt(~e * ~x) * sqrt(~a + ~(c') * (~x) ^ 2)), ~x) => (sqrt(~x) / sqrt(~e * ~x)) * Antiderivative((~f + ~g * ~x) / (sqrt(~x) * sqrt(~a + ~c * (~x) ^ 2)), ~x) <-- FreeQ([~a, ~c, ~e, ~f, ~g], ~x)
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~(a') + ~(b') * ~x + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => (~g / ~e) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p, ~x) + ((~e * ~f - ~d * ~g) / ~e) * Antiderivative((~d + ~e * ~x) ^ ~m * (~a + ~b * ~x + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (NeQ((~c * (~d) ^ 2 - ~b * ~d * ~e) + ~a * (~e) ^ 2, 0) && Not(IGtQ(~m, 0))))
    @apply_utils Antiderivative((~(d') + ~(e') * ~x) ^ ~m * (~(f') + ~(g') * ~x) * (~a + ~(c') * (~x) ^ 2) ^ ~(p'), ~x) => (~g / ~e) * Antiderivative((~d + ~e * ~x) ^ (~m + 1) * (~a + ~c * (~x) ^ 2) ^ ~p, ~x) + ((~e * ~f - ~d * ~g) / ~e) * Antiderivative((~d + ~e * ~x) ^ ~m * (~a + ~c * (~x) ^ 2) ^ ~p, ~x) <-- FreeQ([~a, ~c, ~d, ~e, ~f, ~g, ~m, ~p], ~x) && (NeQ(~c * (~d) ^ 2 + ~a * (~e) ^ 2, 0) && Not(IGtQ(~m, 0)))
end

max_stars_repo_path: src/rules/1 Algebraic functions/1.2 Trinomial products/1.2.1 Quadratic/1.2.1.3 (d+e x)^m (f+g x) (a+b x+c x^2)^p.jl


text:
module Tooltips

Base.Experimental.@optlevel 1

using Redux
using CImGui

# helper
"""
    Tooltip(f::Function)
"""
function Tooltip(f::Function)
    CImGui.BeginTooltip()
        f()
    CImGui.EndTooltip()
    return nothing
end

end # module

ext: jl


text:
struct Scattering1D <: DiabaticFrictionModel
    n_states::UInt
    N::UInt
    a::Float64
    D::Float64
    α::Float64
    β::Float64
    B::Float64
    σ::Float64
end

NQCModels.ndofs(::Scattering1D) = 1
NQCModels.nstates(model::Scattering1D) = model.n_states

function Scattering1D(;N=10, a=1, D=1, α=0, β=1, B=1, σ=0.6u"eV")
    Scattering1D(N+1, N, a, D, α, β, B, austrip(σ))
end

function NQCModels.potential!(model::Scattering1D, V::Hermitian, R::Real)
    V0(R) = model.D*(exp(-2model.a*R) - 2*exp(-model.a*R))
    γ(R) = model.B*exp(-model.a*R^2)

    V₀ = V0(R)
    γᵣ = γ(R)

    V[1,1] = V₀ # Occupied molecule state
    V.data[1,2] = γᵣ # molecule metal coupling
    for i=2:model.N
        V[i,i] = model.α + V₀
        V.data[i,i+1] = model.β
    end
    V.data[2,end] = model.β
    V[end,end] = model.α + V₀
end

function NQCModels.derivative!(model::Scattering1D, D::Hermitian, R::Real)
    D0(R) = 2*model.D*model.a*(exp(-model.a*R)-exp(-2*model.a*R))
    dγ(R) = -2model.a*R*model.B*exp(-model.a*R^2)

    D₀ = D0(R)
    dγᵣ = dγ(R)

    D.data[1,2] = dγᵣ
    for i=1:model.N+1
        D[i,i] = D₀
    end
end


text:
module Options

export read_options, has_comonicon_toml, @asset_str

using TOML
using Configurations
using PackageCompiler: DEFAULT_EMBEDDING_WRAPPER
using Pkg

struct Asset
    package::Union{Nothing,String}
    path::String
end

function Asset(s::String)
    parts = strip.(split(s, ":"))
    if length(parts) == 1
        Asset(nothing, parts[1])
    elseif length(parts) == 2
        Asset(parts[1], parts[2])
    else
        error("invalid syntax for asset string: $s")
    end
end

macro asset_str(s::String)
    return Asset(s)
end

function Base.show(io::IO, ::MIME"text/plain", x::Asset)
    print(io, "asset\"")
    if x.package !== nothing
        printstyled(io, x.package, ": "; color = :green)
    end
    printstyled(io, x.path, "\""; color = :cyan)
end

Base.convert(::Type{Asset}, s::String) = Asset(s)

function get_path(m::Module, x::Asset)
    isnothing(x.package) && return pkgdir(m, x.path)
    ctx = Pkg.Types.Context()
    haskey(ctx.env.project.deps, x.package) || error("asset $x not in current project dependencies")

    uuid = ctx.env.project.deps[x.package]
    pkgid = Base.PkgId(uuid, x.package)
    origin = get(Base.pkgorigins, pkgid, nothing)
    return joinpath(dirname(dirname(origin.path)), x.path)
end

"""
    Install

Installation configurations.

## Keywords

- `path`: installation path.
- `completion`: set to `true` to install shell auto-completion scripts.
- `quiet`: print logs or not, default is `false`.
- `compile`: julia compiler option for CLIs if not built as standalone application, default is "min".
- `optimize`: julia compiler option for CLIs if not built as standalone application, default is `2`.
"""
@option struct Install
    path::String = "~/.julia"
    completion::Bool = true
    quiet::Bool = false
    compile::String = "yes"
    optimize::Int = 2
    nthreads::Int = 1
end

"""
    Precompile

Precompilation files for `PackageCompiler`.

## Keywords

- `execution_file`: precompile execution file.
- `statements_file`: precompile statements file.
"""
@option struct Precompile
    execution_file::Vector{String} = String[]
    statements_file::Vector{String} = String[]
end

# See https://github.com/JuliaCI/julia-buildbot/blob/489ad6dee5f1e8f2ad341397dc15bb4fce436b26/master/inventory.py
function default_app_cpu_target()
    if Sys.ARCH === :i686
        return "pentium4;sandybridge,-xsaveopt,clone_all"
    elseif Sys.ARCH === :x86_64
        return "generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)"
    elseif Sys.ARCH === :arm
        return "armv7-a;armv7-a,neon;armv7-a,neon,vfp4"
    elseif Sys.ARCH === :aarch64
        return "generic" # is this really the best here?
    elseif Sys.ARCH === :powerpc64le
        return "pwr8"
    else
        return "generic"
    end
end

"""
    SysImg

System image build configurations.

## Keywords

- `path`: system image path to generate into, default is "deps/lib".
- `incremental`: set to `true` to build incrementally, default is `true`.
- `filter_stdlibs`: set to `true` to filter out unused stdlibs, default is `false`.
- `cpu_target`: cpu target to build, default is `PackageCompiler.default_app_cpu_target()`.
- `precompile`: precompile configurations, see [`Precompile`](@ref), default is `Precompile()`.
"""
@option struct SysImg
    path::String = "deps"
    incremental::Bool = true
    filter_stdlibs::Bool = false
    cpu_target::String = default_app_cpu_target()
    precompile::Precompile = Precompile()
end

"""
    Download

Download information.

## Keywords

- `host`: where are the tarballs hosted, default is "github.com"
- `user`: required, user name on the host.
- `repo`: required, repo name on the host.

!!! note
    Currently this only supports github, and this is considered experimental.
"""
@option struct Download
    host::String = "github.com"
    user::String
    repo::String
end

"""
    Application

Application build configurations.

## Keywords

- `path`: application build path, default is "build".
- `incremental`: set to `true` to build incrementally, default is `true`.
- `filter_stdlibs`: set to `true` to filter out unused stdlibs, default is `false`.
- `cpu_target`: cpu target to build, default is `PackageCompiler.default_app_cpu_target()`.
- `precompile`: precompile configurations, see [`Precompile`](@ref), default is `Precompile()`.
- `c_driver_program`: driver program.
"""
@option struct Application
    path::String = "build"
    assets::Vector{Asset} = Asset[]
    incremental::Bool = false
    filter_stdlibs::Bool = true
    include_lazy_artifacts::Bool = true
    cpu_target::String = default_app_cpu_target()
    precompile::Precompile = Precompile()
    c_driver_program::String = String(DEFAULT_EMBEDDING_WRAPPER)
    shell_completions::Vector{String} = ["zsh"]
end

"""
    Comonicon

Build configurations for Comonicon. One can set this option
via `Comonicon.toml` under the root path of a Julia
project directory and read in using [`read_configs`](@ref).

## Keywords

- `name`: required, the name of CLI file to install.
- `install`: installation options, see also [`Install`](@ref).
- `sysimg`: system image build options, see also [`SysImg`](@ref).
- `download`: download options, see also [`Download`](@ref).
- `application`: application build options, see also [`Application`](@ref).
"""
@option struct Comonicon
    name::String

    install::Install = Install()
    sysimg::Maybe{SysImg} = nothing
    download::Union{Download,Nothing} = nothing
    application::Union{Application,Nothing} = nothing
end

function validate(options::Comonicon)
    if options.sysimg !== nothing
        isabspath(options.sysimg.path) && error("system image path must be project relative")
    end

    if options.application !== nothing
        isabspath(options.application.path) && error("application build path must project relative")
    end
    return
end

"""
    find_comonicon_toml(path::String, files=["Comonicon.toml", "JuliaComonicon.toml"])

Find `Comonicon.toml` or `JuliaComonicon.toml` in given path.
"""
function find_comonicon_toml(path::String, files = ["Comonicon.toml", "JuliaComonicon.toml"])
    # user input file path
    basename(path) in files && return path

    # user input dir path
    for file in files
        path = joinpath(path, file)
        if ispath(path)
            return path
        end
    end
    return
end

"""
    read_toml(path::String)

Read `Comonicon.toml` or `JuliaComonicon.toml` in given path.
"""
function read_toml(path::String)
    file = find_comonicon_toml(path)
    file === nothing && return Dict{String,Any}()
    return TOML.parsefile(file)
end

"""
    read_toml(mod::Module)

Read `Comonicon.toml` or `JuliaComonicon.toml` in given module's project path.
"""
function read_toml(mod::Module)
    return read_toml(pkgdir(mod))
end

function has_comonicon_toml(m::Module)
    path = pkgdir(m)
    isnothing(path) && return false
    !isnothing(find_comonicon_toml(path))
end

"""
    read_options(comonicon; kwargs...)

Read in Comonicon build options. The argument `comonicon` can be:

- a module of a Comonicon CLI project.
- a path to a Comonicon CLI project that contains either `JuliaComonicon.toml` or `Comonicon.toml`.
- a path to a Comonicon CLI build configuration file named either `JuliaComonicon.toml` or `Comonicon.toml`.

In some cases, you might want to change the configuration written in the TOML file temporarily, e.g for writing
build tests etc. In this case, you can modify the configuration using corresponding keyword arguments.

keyword arguments of [`Application`](@ref) and [`SysImg`](@ref) are the same, thus keys like `filter_stdlibs`
are considered ambiguous in `read_options`, but you can specifiy them by specifiy the specific [`Application`](@ref)
or [`SysImg`](@ref) object, e.g

```julia
read_options(MyCLI; sysimg=SysImg(filter_stdlibs=false))
```

See also [`Comonicon`](@ref), [`Install`](@ref), [`SysImg`](@ref), [`Application`](@ref),
[`Download`](@ref), [`Precompile`](@ref).
"""
function read_options(m::Union{Module,String}; kwargs...)
    d = read_toml(m)
    if !haskey(d, "name")
        d["name"] = default_cmd_name(m)
    end

    options = from_dict(Comonicon, d; kwargs...)
    validate(options)
    return options
end

default_cmd_name(m::Module) = lowercase(string(nameof(m)))
default_cmd_name(m) = error("command name is not specified")

end


text:
module Gopts

export GOpts

mutable struct GOpts
    algo :: Cint
    dim  :: Cint
    x_s  :: Ptr{Cdouble}
    x_l  :: Ptr{Cdouble}
    x_u  :: Ptr{Cdouble}
    iter :: Cint
    retRes :: Ptr{Cdouble}
    retErr :: Ptr{Cdouble}
    func   :: Ptr{Cvoid}
    GOpts() = new(-1,-1,C_NULL,C_NULL,C_NULL,-1,C_NULL,C_NULL,C_NULL)
end

end

max_stars_repo_name: denisbertini/juleva

max_issues_repo_name: denisbertini/juleva

max_forks_repo_name: denisbertini/juleva


text:
abstract type ExactSolutionType end

export ExactSolutionType, calcErrorL2Norm

mutable struct ExactPolynomial <: ExactSolutionType
end
function (obj::ExactPolynomial)(
              xy::AbstractArray{Tmsh},
              params::ParamType{2},
              qe::AbstractArray{Tsol, 1}) where {Tmsh, Tsol}
  sigma = 0.5
  gamma = params.euler_params.gamma
  gamma_1 = params.euler_params.gamma_1
  aoa = params.euler_params.aoa
  rhoInf = 1.0
  TInf = 1.0
  uInf = params.euler_params.Ma*cos(aoa)
  vInf = params.euler_params.Ma*sin(aoa)
  x = xy[1]
  y = xy[2]
  rho = (x-x*x)*(y-y*y)
  u   = (x-x*x)*(y-y*y)
  v   = (x-x*x)*(y-y*y)
  T   = (x-x*x)*(y-y*y)
  rho = (sigma*rho + 1.0)*rhoInf
  u   = (sigma*u + 1.0)*uInf
  v   = (sigma*v + 1.0)*vInf
  T   = (sigma*T + 1.0)*TInf
  qe[1] = rho
  qe[2] = rho*u
  qe[3] = rho*v
  qe[4] = T/(gamma*gamma_1) + 0.5*(u*u + v*v)
  qe[4] = qe[4]*rho

  return nothing
end

mutable struct ExactPolynomial_1 <: ExactSolutionType
end
function (obj::ExactPolynomial_1)(
              xy::AbstractArray{Tmsh},
              params::ParamType{2},
              qe::AbstractArray{Tsol, 1}) where {Tmsh, Tsol}

  sigma = 0.5
  gamma = params.euler_params.gamma
  gamma_1 = params.euler_params.gamma_1
  aoa = params.euler_params.aoa
  rhoInf = 1.0
  uInf = params.euler_params.Ma*cos(aoa)
  vInf = params.euler_params.Ma*sin(aoa)
  TInf = 1.0
  x = xy[1]
  y = xy[2]
  rho = (x-x*x)*(y-y*y)
  u   = 0.0
  v   = 0.0
  T   = 0.0
  rho = (sigma*rho + 1.0)*rhoInf
  u   = (sigma*u + 1.0)*uInf
  v   = (sigma*v + 1.0)*vInf
  T   = (sigma*T + 1.0)*TInf
  qe[1] = rho
  qe[2] = rho*u
  qe[3] = rho*v
  qe[4] = T/(gamma*gamma_1) + 0.5*(u*u + v*v)
  qe[4] = qe[4]*rho

  return nothing
end

mutable struct ExactPolynomial_2 <: ExactSolutionType
end
function (obj::ExactPolynomial_2)(
              xy::AbstractArray{Tmsh},
              params::ParamType{2},
              qe::AbstractArray{Tsol, 1}) where {Tmsh, Tsol}

  sigma = 0.5
  gamma = params.euler_params.gamma
  gamma_1 = params.euler_params.gamma_1
  aoa = params.euler_params.aoa
  rhoInf = 1.0
  uInf = params.euler_params.Ma*cos(aoa)
  vInf = params.euler_params.Ma*sin(aoa)
  TInf = 1.0
  x = xy[1]
  y = xy[2]
  rho = 0.0
  u   = sqrt((x - x*x) * (y - y*y))
  v   = 0.0
  T   = (x - x*x) * (y - y*y)
  rho = (sigma*rho + 1.0)*rhoInf
  u   = (sigma*u + 1.0)*uInf
  v   = (sigma*v + 1.0)*vInf
  T   = (sigma*T + 1.0)*TInf
  qe[1] = rho
  qe[2] = rho*u
  qe[3] = rho*v
  qe[4] = T/(gamma*gamma_1) + 0.5*(u*u + v*v)
  qe[4] = qe[4]*rho

  return nothing
end

mutable struct ExactTrigonometric <: ExactSolutionType
end
function (obj::ExactTrigonometric)(
              xy::AbstractArray{Tmsh},
              params::ParamType{2},
              qe::AbstractArray{Tsol, 1}) where {Tmsh, Tsol}
  sigma = 0.5
  pi = 3.14159265358979323846264338
  gamma = 1.4
  gamma_1 = gamma - 1.0
  aoa = params.euler_params.aoa
  rhoInf = 1.0
  uInf = params.euler_params.Ma*cos(aoa)
  vInf = params.euler_params.Ma*sin(aoa)
  TInf = 1.0
  x2 = 2*xy[1]*pi
  y2 = 2*xy[2]*pi
  x4 = 4*xy[1]*pi
  y4 = 4*xy[2]*pi
  sx2 = sin(x2)
  sy2 = sin(y2)
  sx4 = sin(x4)
  sy4 = sin(y4)
  cx2 = cos(x2)
  cx4 = cos(x4)
  cy2 = cos(y2)
  cy4 = cos(y4)
  #
  # Exact solution in form of primitive variables
  #
  rho = 0.25 * sx2 * sy2
  u   = 0.25 * sx4 * sy4
  v   = 0.25 * (cx4  + 1.0) * (cy4 + 1.0)
  T   = 0.25 * (1.0 - cx4) * (1.0 - cy4)
  rho = (sigma*rho + 1.0)*rhoInf
  u   = (sigma*u + 1.0)*uInf
  v   = (sigma*v + 1.0)*vInf
  T   = (sigma*T + 1.0)*TInf

  qe[1] = rho
  qe[2] = rho*u
  qe[3] = rho*v
  qe[4] = T/(gamma*gamma_1) + 0.5*(u*u + v*v)
  qe[4] = qe[4]*rho

  return nothing
end

global const ExactDict = Dict{String, ExactSolutionType}(
  "ExactTrigonometric" => ExactTrigonometric(),
  "ExactPolynomial"    => ExactPolynomial(),
  "ExactPolynomial_1"  => ExactPolynomial_1(),
  "ExactPolynomial_2"  => ExactPolynomial_2(),
)

function calcErrorL2Norm(mesh::AbstractMesh{Tmsh},
        sbp::AbstractOperator,
        eqn::NSData{Tsol, Tres},
        opts) where {Tmsh, Tsol, Tres}
  l2norm::Float64 = 0.
    lInfnorm::Float64 = 0.
    qe = Array{Tsol}(mesh.numDofPerNode)
    exactFunc = ExactDict[opts["exactSolution"]]

  lInfnorm = -1.0
  elem_with_max_dq = 0
  numDofs_to_sum = mesh.numDofPerNode
    for e = 1:mesh.numEl
        for n = 1:mesh.numNodesPerElement
            xy = sview(mesh.coords, :, n, e)
            exactFunc(xy, eqn.params, qe)
            q = sview(eqn.q, :, n, e)
      jac = mesh.jac[n, e]

            for v = 1 : numDofs_to_sum
                # dq = Real(q[v] - qe[v])
                dq = Float64(q[v] - qe[v])
        l2norm += dq*dq*sbp.w[n]/jac

        if lInfnorm < abs(dq)
          lInfnorm = abs(dq)
        end

        # if abs(dq) > 1.0e-4
          # println(e, ", ", n, ", ", v, ", ", real(dq), ", ", real(q[v]), ", ", real(qe[v]))
        # end
      end
    end
    end

    return sqrt(l2norm), lInfnorm
end


text:
import Dates: year, toprev, firstdayofmonth, Date

export isoutdated, lastupdate

daycomp(last, now, dow) = Date(toprev(now, dow, same=true)) >
    Date(toprev(last, dow, same=true))

const upfun = Dict(
    :never => (last, now) -> false,
    :always => (last, now) -> true,
    :daily => (last, now) -> Date(now) > Date(last),
    :monthly => (last, now) ->
        firstdayofmonth(now) > firstdayofmonth(last),
    :yearly => (last, now) -> year(now) > year(last),
    :mondays => (last, now) -> daycomp(last, now, 1),
    :weekly => (last, now) -> daycomp(last, now, 1),
    :tuesdays => (last, now) -> daycomp(last, now, 2),
    :wednesdays => (last, now) -> daycomp(last, now, 3),
    :thursdays => (last, now) -> daycomp(last, now, 4),
    :fridays => (last, now) -> daycomp(last, now, 5),
    :saturdays => (last, now) -> daycomp(last, now, 6),
    :sundays => (last, now) -> daycomp(last, now, 7),
)

lastupdate(rf::RemoteFile) = unix2datetime(stat(path(rf)).mtime)

function isoutdated(last, now, updates)
    if !haskey(upfun, updates)
        error("Unknown update frequency specification: $updates.")
    end

    upfun[updates](last, now)
end

isoutdated(rf::RemoteFile) = isoutdated(lastupdate(rf), now(), rf.updates)


text:
#=
This file is auto-generated. Do not edit.
=#
"""
    mutable struct PowerLoad <: StaticLoad
        name::String
        available::Bool
        bus::Bus
        model::Union{Nothing, LoadModels}
        active_power::Float64
        reactive_power::Float64
        base_power::Float64
        max_active_power::Float64
        max_reactive_power::Float64
        services::Vector{Service}
        dynamic_injector::Union{Nothing, DynamicInjection}
        ext::Dict{String, Any}
        time_series_container::InfrastructureSystems.TimeSeriesContainer
        internal::InfrastructureSystemsInternal
    end

Data structure for a static power load.

# Arguments
- `name::String`
- `available::Bool`
- `bus::Bus`
- `model::Union{Nothing, LoadModels}`
- `active_power::Float64`
- `reactive_power::Float64`
- `base_power::Float64`: Base power of the unit in MVA, validation range: `(0, nothing)`, action if invalid: `warn`
- `max_active_power::Float64`
- `max_reactive_power::Float64`
- `services::Vector{Service}`: Services that this device contributes to
- `dynamic_injector::Union{Nothing, DynamicInjection}`: corresponding dynamic injection device
- `ext::Dict{String, Any}`
- `time_series_container::InfrastructureSystems.TimeSeriesContainer`: internal time_series storage
- `internal::InfrastructureSystemsInternal`: power system internal reference, do not modify
"""
mutable struct PowerLoad <: StaticLoad
    name::String
    available::Bool
    bus::Bus
    model::Union{Nothing, LoadModels}
    active_power::Float64
    reactive_power::Float64
    "Base power of the unit in MVA"
    base_power::Float64
    max_active_power::Float64
    max_reactive_power::Float64
    "Services that this device contributes to"
    services::Vector{Service}
    "corresponding dynamic injection device"
    dynamic_injector::Union{Nothing, DynamicInjection}
    ext::Dict{String, Any}
    "internal time_series storage"
    time_series_container::InfrastructureSystems.TimeSeriesContainer
    "power system internal reference, do not modify"
    internal::InfrastructureSystemsInternal
end

function PowerLoad(name, available, bus, model, active_power, reactive_power, base_power, max_active_power, max_reactive_power, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), )
    PowerLoad(name, available, bus, model, active_power, reactive_power, base_power, max_active_power, max_reactive_power, services, dynamic_injector, ext, time_series_container, InfrastructureSystemsInternal(), )
end

function PowerLoad(; name, available, bus, model, active_power, reactive_power, base_power, max_active_power, max_reactive_power, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), internal=InfrastructureSystemsInternal(), )
    PowerLoad(name, available, bus, model, active_power, reactive_power, base_power, max_active_power, max_reactive_power, services, dynamic_injector, ext, time_series_container, internal, )
end

# Constructor for demo purposes; non-functional.
function PowerLoad(::Nothing)
    PowerLoad(;
        name="init",
        available=false,
        bus=Bus(nothing),
        model=nothing,
        active_power=0.0,
        reactive_power=0.0,
        base_power=0.0,
        max_active_power=0.0,
        max_reactive_power=0.0,
        services=Device[],
        dynamic_injector=nothing,
        ext=Dict{String, Any}(),
        time_series_container=InfrastructureSystems.TimeSeriesContainer(),
    )
end

InfrastructureSystems.get_name(value::PowerLoad) = value.name
"""Get [`PowerLoad`](@ref) `available`."""
get_available(value::PowerLoad) = value.available
"""Get [`PowerLoad`](@ref) `bus`."""
get_bus(value::PowerLoad) = value.bus
"""Get [`PowerLoad`](@ref) `model`."""
get_model(value::PowerLoad) = value.model
"""Get [`PowerLoad`](@ref) `active_power`."""
get_active_power(value::PowerLoad) = get_value(value, value.active_power)
"""Get [`PowerLoad`](@ref) `reactive_power`."""
get_reactive_power(value::PowerLoad) = get_value(value, value.reactive_power)
"""Get [`PowerLoad`](@ref) `base_power`."""
get_base_power(value::PowerLoad) = value.base_power
"""Get [`PowerLoad`](@ref) `max_active_power`."""
get_max_active_power(value::PowerLoad) = get_value(value, value.max_active_power)
"""Get [`PowerLoad`](@ref) `max_reactive_power`."""
get_max_reactive_power(value::PowerLoad) = get_value(value, value.max_reactive_power)
"""Get [`PowerLoad`](@ref) `services`."""
get_services(value::PowerLoad) = value.services
"""Get [`PowerLoad`](@ref) `dynamic_injector`."""
get_dynamic_injector(value::PowerLoad) = value.dynamic_injector
"""Get [`PowerLoad`](@ref) `ext`."""
get_ext(value::PowerLoad) = value.ext

InfrastructureSystems.get_time_series_container(value::PowerLoad) = value.time_series_container
"""Get [`PowerLoad`](@ref) `internal`."""
get_internal(value::PowerLoad) = value.internal

InfrastructureSystems.set_name!(value::PowerLoad, val) = value.name = val
"""Set [`PowerLoad`](@ref) `available`."""
set_available!(value::PowerLoad, val) = value.available = val
"""Set [`PowerLoad`](@ref) `bus`."""
set_bus!(value::PowerLoad, val) = value.bus = val
"""Set [`PowerLoad`](@ref) `model`."""
set_model!(value::PowerLoad, val) = value.model = val
"""Set [`PowerLoad`](@ref) `active_power`."""
set_active_power!(value::PowerLoad, val) = value.active_power = val
"""Set [`PowerLoad`](@ref) `reactive_power`."""
set_reactive_power!(value::PowerLoad, val) = value.reactive_power = val
"""Set [`PowerLoad`](@ref) `base_power`."""
set_base_power!(value::PowerLoad, val) = value.base_power = val
"""Set [`PowerLoad`](@ref) `max_active_power`."""
set_max_active_power!(value::PowerLoad, val) = value.max_active_power = val
"""Set [`PowerLoad`](@ref) `max_reactive_power`."""
set_max_reactive_power!(value::PowerLoad, val) = value.max_reactive_power = val
"""Set [`PowerLoad`](@ref) `services`."""
set_services!(value::PowerLoad, val) = value.services = val
"""Set [`PowerLoad`](@ref) `ext`."""
set_ext!(value::PowerLoad, val) = value.ext = val

InfrastructureSystems.set_time_series_container!(value::PowerLoad, val) = value.time_series_container = val


text:
using BuildExecutable

if !isinteractive()
    if length(ARGS) < 2 || ("--help" in ARGS || "-h" in ARGS)
        println("Usage: build_executable.jl <exename> <script_file> [targetdir] <cpu_target> [--help]")
        println("   <exename>        is the filename of the resulting executable and the resulting sysimg")
        println("   <script_file>    is the path to a jl file containing a main() function.")
        println("   [targetdir]     (optional) is the path to a directory to put the executable and other")
        println("   <cpu_target>     is an LLVM cpu target to build the system image against")
        println("                    needed files into (default: julia directory structure)")
        println("   --debug          Using julia-debug instead of julia to build the executable")
        println("   --force          Set if you wish to overwrite existing files")
        println("   --help           Print out this help text and exit")
        println()
        println(" Example:")
        println("   julia build_executable.jl standalone_test hello_world.jl targetdir core2")
        return 0
    end

    debug_flag = "--debug" in ARGS
    filter!(x -> x != "--debug", ARGS)
    force_flag = "--force" in ARGS
    filter!(x -> x != "--force", ARGS)
    BuildExecutable.build_executable(ARGS..., force=force_flag, debug=debug_flag)
end


text:
function SeisReadHeaders(filename;group="all",key=[],itrace=1,ntrace=100)

	filename_h = ParseHeaderName(filename)
	stream_h = open(filename_h)
	@compat nhead = length(fieldnames(Header))
	curr = zeros(length(key),1)
	prev = 1*curr
	@compat nx = round(Int,filesize(stream_h)/(4*length(fieldnames(Header)))) - itrace + 1
	if (group == "all")
		ntrace = nx
	elseif (group == "gather")
		for j=itrace:itrace+nx-1
			h1 = GrabHeader(stream_h,j)
			for ikey=1:length(key)
				curr[ikey] = getfield(h1,Symbol(key[ikey]))
			end
			if curr != prev && j > itrace
				nx = j - itrace
				break
			end
			prev = 1*curr
		end
	else
		ntrace = nx > ntrace ? ntrace : nx
	end

	position_h = 4*nhead*(itrace-1)
	seek(stream_h,position_h)

	h1 = read(stream_h,Header32Bits,nhead*ntrace)
	h1 = reshape(h1,nhead,round(Int,ntrace))
	h = Header[]
	for itrace = 1 : ntrace
		h = push!(h,BitsToHeader(h1[:,itrace]))
	end

	close(stream_h)
	return h

end


text:
# MIT License
#
# Copyright (c) 2020 Joshua E Gentry

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# =================================================================================================
# Test writing a (single) TIFF image.
@testset "pix_write_tiff/pix_read_tiff (single/$compression)" for compression in
        [IFF_TIFF, IFF_TIFF_JPEG, IFF_TIFF_LZW, IFF_TIFF_ZIP]
    local pix = pix_with()

    # ---------------------------------------------------------------------------------------------
    # To/From a file.
    local filename = safe_tmp_file()
    @test pix_write_tiff(filename, pix; compression = compression) == true
    @test pix_read_tiff(filename) != nothing
    rm(filename)

    # ---------------------------------------------------------------------------------------------
    # To/From an IOBuffer.
    local buffer = IOBuffer()
    @test pix_write_tiff(buffer, pix; compression = compression) == true
    @test position(buffer) != 0
    seekstart(buffer)
    @test pix_read_tiff(buffer) != nothing

    # ---------------------------------------------------------------------------------------------
    # To/From an IOStream
    local filename = safe_tmp_file()
    local file     = open(filename, read=true, write=true)
    @test pix_write_tiff(file, pix; compression = compression) == true
    @test position(file) != 0
    seekstart(file)
    @test pix_read_tiff(file) != nothing
    close(file)
    rm(filename)

    # ---------------------------------------------------------------------------------------------
    # To/From a byte array.
    local data  = tiff_with()
    local bytes = pix_write_tiff(pix; compression = compression)
    @test length(bytes) > 0
    @test pix_read_tiff(bytes) != nothing
end

# =================================================================================================
# Test reading empty data.
@testset "pix_read_tiff empty data" begin

    @suppress begin
        # -----------------------------------------------------------------------------------------
        # From a file.
        local filename = safe_tmp_file()
        @test pix_read_tiff(filename) == nothing
        @test pix_read_tiff("xyzzy.tiff") == nothing
        rm(filename)

        # -----------------------------------------------------------------------------------------
        # From an IOBuffer.
        local buffer = IOBuffer()
        @test pix_read_tiff(buffer) == nothing

        # -----------------------------------------------------------------------------------------
        # From an IOStream
        local filename = safe_tmp_file()
        local file     = open(filename, read=true, write=true)
        @test pix_read_tiff(file) == nothing
        close(file)
        rm(filename)

        # -----------------------------------------------------------------------------------------
        # To/From a byte array.
        local bytes = Vector{UInt8}()
        @test pix_read_tiff(bytes) == nothing
    end
end

# =================================================================================================
# Test for failure when TIFF compression requires a bit depth of 1.
@testset "pix_write_tiff invalid $compression when bit depth > 1" for compression in
        [IFF_TIFF_RLE, IFF_TIFF_G3, IFF_TIFF_G4, IFF_TIFF_PACKBITS]
    local err = "Invalid compression, bit depth must be 1 for compression $compression."
    local pix = pix_with()

    # ---------------------------------------------------------------------------------------------
    # To/From a file.
    local filename = safe_tmp_file()
    @test (
        @test_logs (:error, err) pix_write_tiff(filename, pix; compression = compression)
        ) == false
    rm(filename)

    # ---------------------------------------------------------------------------------------------
    # To/From an IOBuffer.
    local buffer = IOBuffer()
    @test (
        @test_logs (:error, err) pix_write_tiff(buffer, pix; compression = compression)
        ) == false

    # ---------------------------------------------------------------------------------------------
    # To/From an IOStream
    local filename = safe_tmp_file()
    local file     = open(filename, read=true, write=true)
    @test (
        @test_logs (:error, err) pix_write_tiff(file, pix; compression = compression)
        ) == false
    close(file)
    rm(filename)

    # ---------------------------------------------------------------------------------------------
    # To/From a byte array.
    local data  = tiff_with()
    @test (
        @test_logs (:error, err) pix_write_tiff(pix; compression = compression)
        ) == nothing
end

# =================================================================================================
# Test reading/writing multiple TIFF images to/from a file.
@testset "pix_write_tiff/pix_read_tiff (multiple/$compression)" for compression in
        [IFF_TIFF, IFF_TIFF_LZW, IFF_TIFF_ZIP]
    local pixs = [
        pix_with([Line("The quick brown fox jumped over the lazy dog.")]),
        pix_with([Line("Suzy sells sea shells by the sea shore.", italic=true)]),
        pix_with([Line("The sixth sick sheik's sixth sheep's sick.", bold=true)])
    ]

    function equal(pic, i)
        pic != nothing && pix_write_pam(pic) == pix_write_pam(pixs[i])
    end

    # ---------------------------------------------------------------------------------------------
    # To/From a file.
    local filename = safe_tmp_file()
    @test pix_write_tiff(filename, pixs[1]; compression=compression, append=false) == true
    @test pix_write_tiff(filename, pixs[2]; compression=compression, append=true) == true
    @test pix_write_tiff(filename, pixs[3]; compression=compression, append=true) == true
    @test pix_read_tiff(filename; page=0) == nothing
    @test equal(pix_read_tiff(filename; page=1), 1) == true
    @test equal(pix_read_tiff(filename; page=2), 2) == true
    @test equal(pix_read_tiff(filename; page=3), 3) == true
    @test pix_read_tiff(filename; page=4) == nothing

    # ---------------------------------------------------------------------------------------------
    # From an IOBuffer.
    local buffer = IOBuffer(read(filename))
    @test equal(pix_read_tiff(buffer), 1) == true
    seekstart(buffer)
    @test pix_read_tiff(buffer; page=0) == nothing
    seekstart(buffer)
    @test equal(pix_read_tiff(buffer; page=1), 1) == true
    seekstart(buffer)
    @test equal(pix_read_tiff(buffer; page=2), 2) == true
    seekstart(buffer)
    @test equal(pix_read_tiff(buffer; page=3), 3) == true
    seekstart(buffer)
    @test pix_read_tiff(buffer; page=4) == nothing

    # ---------------------------------------------------------------------------------------------
    # From an IOStream
    local file = open(filename, read=true, write=true)
    @test equal(pix_read_tiff(file), 1) == true
    seekstart(file)
    @test pix_read_tiff(file; page=0) == nothing
    seekstart(file)
    @test equal(pix_read_tiff(file; page=1), 1) == true
    seekstart(file)
    @test equal(pix_read_tiff(file; page=2), 2) == true
    seekstart(file)
    @test equal(pix_read_tiff(file; page=3), 3) == true
    seekstart(file)
    @test pix_read_tiff(file; page=4) == nothing
    close(file)

    # ---------------------------------------------------------------------------------------------
    # From a byte array.
    local data = read(filename)
    @test equal(pix_read_tiff(data), 1) == true
    @test pix_read_tiff(filename; page=0) == nothing
    @test equal(pix_read_tiff(data; page=1), 1) == true
    @test equal(pix_read_tiff(data; page=2), 2) == true
    @test equal(pix_read_tiff(data; page=3), 3) == true
    @test pix_read_tiff(filename; page=4) == nothing

    rm(filename)
end

# =================================================================================================
# Test writing mutliple TIFF images to a file with the IFF_TIFF_JPEG encoding.
@testset "pix_write_tiff/pix_read_tiff (multiple/IFF_TIFF_JPEG)" begin
    local pixs = [
        pix_with([Line("The quick brown fox jumped over the lazy dog.")]),
        pix_with([Line("Suzy sells sea shells by the sea shore.", italic=true)]),
        pix_with([Line("The sixth sick sheik's sixth sheep's sick.", bold=true)])
    ]

    # ---------------------------------------------------------------------------------------------
    # To/From a file.
    local filename = safe_tmp_file()
    @test pix_write_tiff(filename, pixs[1]; compression=IFF_TIFF_JPEG, append=false) == true
    @test pix_write_tiff(filename, pixs[2]; compression=IFF_TIFF_JPEG, append=true) == true
    @test pix_write_tiff(filename, pixs[3]; compression=IFF_TIFF_JPEG, append=true) == true
    @test pix_read_tiff(filename; page=0) == nothing
    @test pix_read_tiff(filename; page=1) != nothing
    @test pix_read_tiff(filename; page=2) != nothing
    @test pix_read_tiff(filename; page=3) != nothing
    @test pix_read_tiff(filename; page=4) == nothing

    # ---------------------------------------------------------------------------------------------
    # From an IOBuffer.
    local buffer = IOBuffer(read(filename))
    @test pix_read_tiff(buffer) != nothing
    seekstart(buffer)
    @test pix_read_tiff(buffer; page=0) == nothing
    seekstart(buffer)
    @test pix_read_tiff(buffer; page=1) != nothing
    seekstart(buffer)
    @test pix_read_tiff(buffer; page=2) != nothing
    seekstart(buffer)
    @test pix_read_tiff(buffer; page=3) != nothing
    seekstart(buffer)
    @test pix_read_tiff(buffer; page=4) == nothing

    # ---------------------------------------------------------------------------------------------
    # From an IOStream
    local file = open(filename, read=true, write=true)
    @test pix_read_tiff(file) != nothing
    seekstart(file)
    @test pix_read_tiff(file; page=0) == nothing
    seekstart(file)
    @test pix_read_tiff(file; page=1) != nothing
    seekstart(file)
    @test pix_read_tiff(file; page=2) != nothing
    seekstart(file)
    @test pix_read_tiff(file; page=3) != nothing
    seekstart(file)
    @test pix_read_tiff(file; page=4) == nothing
    close(file)

    # ---------------------------------------------------------------------------------------------
    # From a byte array.
    local data = read(filename)
    @test pix_read_tiff(data) != nothing
    @test pix_read_tiff(data; page=0) == nothing
    @test pix_read_tiff(data; page=1) != nothing
    @test pix_read_tiff(data; page=2) != nothing
    @test pix_read_tiff(data; page=3) != nothing
    @test pix_read_tiff(data; page=4) == nothing

    rm(filename)
end

# =================================================================================================
# Test writing a Pix that has been freed.
@testset "pix_write_tiff /w freed Pix" begin
    local err = "Pix has been freed."
    local pix = pix_with()
    pix_delete!(pix)

    # ---------------------------------------------------------------------------------------------
    # To a file.
    local filename = safe_tmp_file()
    @test (@test_logs (:error, err) pix_write_tiff(filename, pix)) == false
    rm(filename)

    # ---------------------------------------------------------------------------------------------
    # To an IOBuffer.
    local buffer = IOBuffer()
    @test (@test_logs (:error, err) pix_write_tiff(buffer, pix)) == false

    # ---------------------------------------------------------------------------------------------
    # To a byte array.
    @test (@test_logs (:error, err) pix_write_tiff(pix)) == nothing
end


text:
# ------------------------------------------------------------------------------------------
# # Despacho múltiple / multiple dispatch
# ------------------------------------------------------------------------------------------

# ------------------------------------------------------------------------------------------
# En este notebook vamos a explorar **multiple dispatch**, un concepto fundamental en Julia.
#
# Multiple dispatch permite software:
# - rápido
# - extendible
# - programable
# - divertido para experimentar
# ------------------------------------------------------------------------------------------

# ------------------------------------------------------------------------------------------
# Para entender el despacho múltiple en Julia, observemos el operador `+`.

#
# Si llamamos `methods()` sobre `+`, podemos ver todas las definiciones de `+`
# ------------------------------------------------------------------------------------------

methods(+)

# ------------------------------------------------------------------------------------------
# Podemos usar el macro de `@which` para saber qué método en particular estamos usando de
# `+`.

#
# Distintos métodos se usan en cada uno de estos ejemplos.
# ------------------------------------------------------------------------------------------

@which 3 + 3

@which 3.0 + 3.0

@which 3 + 3.0

# ------------------------------------------------------------------------------------------
# Aún más, pues podemos definir nuevos métodos de `+`.

#
# Primero tenemos que importar `+` de Base.
# ------------------------------------------------------------------------------------------

import Base: +

# ------------------------------------------------------------------------------------------
# Digamos que queremos concatenar elementos con  `+`. Sin extender el método, no funciona
# ------------------------------------------------------------------------------------------

"hello " + "world!"

@which "hello " + "world!"

# ------------------------------------------------------------------------------------------
# Entonces agregamos a `+` un método que toma dos cadenas y las concatena
# ------------------------------------------------------------------------------------------

+(x::String, y::String) = string(x, y)

"hello " + "world!"

# ------------------------------------------------------------------------------------------
# ¡Funciona! Y si queremos más, podemos comprobarnos que Julia ha despachado sobre los tipos
# de "hello" y "world!", sobre el método que acabamos de definir
# ------------------------------------------------------------------------------------------

@which "hello " + "world!"

# ------------------------------------------------------------------------------------------
# Vamos por un ejemplo más
# ------------------------------------------------------------------------------------------

foo(x, y) = println("duck-typed foo!")
foo(x::Int, y::Float64) = println("foo con entero y flotante!")
foo(x::Float64, y::Float64) = println("foo con dos flotantes!")
foo(x::Int, y::Int) = println("foo con dos enteros!")

foo(1, 1)

foo(1., 1.)

foo(1, 1.0)

foo(true, false)

# ------------------------------------------------------------------------------------------
# Nota que el último ejemplo aplica por default el caso de 'duck-typed foo' porque no había
# un método definido exclusivamente para dos booleanos.
# ------------------------------------------------------------------------------------------

# ------------------------------------------------------------------------------------------
# ### Ejercicios
#
# #### 9.1
#
# Agrega un método para `+` que aplique un cifrado de César a una cadena (cómo en el
# notebook 6) tal que
#
# ```julia
# "hello" + 4 == "lipps"
# ```
# ------------------------------------------------------------------------------------------

# ------------------------------------------------------------------------------------------
# #### 9.2
#
# Checa que has extendido propiamente `+` recorriendo la próxima cadena para atrás por 3
# letras:
#
# "Gr#qrw#phggoh#lq#wkh#diidluv#ri#gudjrqv#iru#|rx#duh#fuxqfk|#dqg#wdvwh#jrrg#zlwk#nhwfkxs1"
# ------------------------------------------------------------------------------------------

max_stars_repo_path: .nbexports/introductory-tutorials/intro-to-julia-ES/ 9. Despacho multiple.jl

max_stars_repo_name: grenkoca/JuliaTutorials

max_issues_repo_name: grenkoca/JuliaTutorials

max_forks_repo_name: grenkoca/JuliaTutorials


text:
function mass_matrix_converter_entries!(
    mass_matrix,
    converter::C,
    global_index::Dict{Symbol, Int64},
) where {C <: PSY.Converter}
    @debug "Using default mass matrix entries $C"
end

function mdl_converter_ode!(
    dynamic_device::PSY.DynamicInverter{PSY.AverageConverter, O, IC, DC, P, F},
) where {
    O <: PSY.OuterControl,
    IC <: PSY.InnerControl,
    DC <: PSY.DCSource,
    P <: PSY.FrequencyEstimator,
    F <: PSY.Filter,
}

    #Obtain external states inputs for component

    #Obtain inner variables for component
    md = get_inner_vars(dynamic_device)[md_var]
    mq = get_inner_vars(dynamic_device)[mq_var]
    Vdc = get_inner_vars(dynamic_device)[Vdc_var]
    θ_oc = get_inner_vars(dynamic_device)[θ_oc_var]

    #Transform reference frame to grid reference frame
    m_ri = dq_ri(θ_oc + pi / 2) * [md; mq]

    #Update inner_vars
    get_inner_vars(dynamic_device)[Vr_cnv_var] = m_ri[R] * Vdc
    get_inner_vars(dynamic_device)[Vi_cnv_var] = m_ri[I] * Vdc
end


text:
"""
    SGHMC(n_iters::Int, learning_rate::Float64, momentum_decay::Float64)

Stochastic Gradient Hamiltonian Monte Carlo sampler.

Usage:

```julia
SGHMC(1000, 0.01, 0.1)
```

Example:

```julia
@model example begin
  ...
end

sample(example, SGHMC(1000, 0.01, 0.1))
```
"""
mutable struct SGHMC{T} <: Hamiltonian
    n_iters::Int       # number of samples
    learning_rate::Float64   # learning rate
    momentum_decay::Float64   # momentum decay
    space::Set{T}    # sampling space, emtpy means all
    gid::Int
end
function SGHMC(learning_rate::Float64, momentum_decay::Float64, space...)
    return SGHMC(1, learning_rate, momentum_decay, space..., 0)
end
function SGHMC(n_iters, learning_rate, momentum_decay)
    return SGHMC(n_iters, learning_rate, momentum_decay, Set(), 0)
end
function SGHMC(n_iters, learning_rate, momentum_decay, space...)
    _space = isa(space, Symbol) ? Set([space]) : Set(space)
    return SGHMC(n_iters, learning_rate, momentum_decay, _space, 0)
end
function SGHMC(alg::SGHMC, new_gid::Int)
    return SGHMC(alg.n_iters, alg.learning_rate, alg.momentum_decay, alg.space, new_gid)
end

function step(model, spl::Sampler{<:SGHMC}, vi::VarInfo, is_first::Bool)
    if is_first
        if ~haskey(spl.info, :wum)
            spl.alg.gid != 0 && link!(vi, spl)

            D = length(vi[spl])
            ve = VarEstimator{Float64}(0, zeros(D), zeros(D))
            wum = WarmUpManager(1, Dict(), ve)
            wum[:ϵ] = [spl.alg.learning_rate]
            wum[:stds] = ones(D)
            spl.info[:wum] = wum

            # Initialize velocity
            v = zeros(Float64, size(vi[spl]))
            spl.info[:v] = v

            spl.alg.gid != 0 && invlink!(vi, spl)
        end

        push!(spl.info[:accept_his], true)
    else
        # Set parameters
        η, α = spl.alg.learning_rate, spl.alg.momentum_decay

        @debug "X-> R..."
        if spl.alg.gid != 0
            link!(vi, spl)
            runmodel!(model, vi, spl)
        end

        @debug "recording old variables..."
        θ, v = vi[spl], spl.info[:v]
        _, grad = gradient(θ, vi, model, spl)
        verifygrad(grad)

        # Implements the update equations from (15) of Chen et al. (2014).
        @debug "update latent variables and velocity..."
        θ .+= v
        v .= (1 - α) .* v .- η .* grad .+ rand.(Normal.(zeros(length(θ)), sqrt(2 * η * α)))

        @debug "saving new latent variables..."
        vi[spl] = θ

        @debug "always accept..."
        push!(spl.info[:accept_his], true)

        @debug "R -> X..."
        spl.alg.gid != 0 && invlink!(vi, spl)
    end
    return vi
end


text:
export _build, _get_kernel, funcs, r
using Statistics
using LinearAlgebra
using StaticArrays
#########################################################
#             Radial Basis functions                    #
#########################################################

phi_MQ(r, e) = sqrt(1 + (e .* r) .^ 2)
phi_InvMQ(r, e) = phi_MQ(r, e)^-1
phi_Q(r, e) = phi_MQ(r, e)^-2
phi_Gauss(r, e) = exp(-(e .* r)^2)
phi_Multiquadric(r, e) = -sqrt(1 + r .^ 2)
phi_InvMultiquadric(r, e) = 1 / (-sqrt(1 + r .^ 2))
phi_thin_plate_spline(r, e) = r .^ 2 .* log(r + 1e-5)
phi_cubic(r, e) = (r + 1) .^ -3
phi_quintic(r, e) = (r + 1) .^ -5
funcs = Dict([("MQ", phi_MQ),
    ("InvMQ", phi_InvMQ),
    ("Quadratic", phi_Q),
    ("Gaussian", phi_Gauss),
    ("minusMQ", phi_Multiquadric),
    ("minusInvMQ", phi_InvMultiquadric),
    ("Cubic", phi_cubic),
    ("Quintic", phi_quintic),
    ("ThinPlate", phi_thin_plate_spline)
])

"""
The function to retrive the basis for interpolation
    -> Input:
        :basis: String with the name of the function
                being selected. The available options are:
                ["MQ" , "InvMQ" , "Quadratic , "Gaussian"]
    ->Output:
        :basis function: two float parameters=> e (the epsilopn of the fuction)
                                                r (Distance form center)

"""
function _get_kernel(basis::String = "MQ"; func_dict = funcs)
    if basis ∉ keys(func_dict)
        throw(DomainError(basis, "Basis function not implemented\n If you want your own function set it using φ parameter"))
    end
    func_dict[basis]
end

# Distance calculation function
r(x, xi) = norm(x .- xi)

"""
build the onterpolation matrix

-> Input:
        :basis: ::Matrix with data to be interpolated
->Output:
        :Weights vector: Vector containing the weights of the interpolation
"""
function _build(X, y; φ = _get_kernel["QM"], ϵ = 1.0)
    A = ones((size(X)[1], size(X)[1]))
    for i = 1:size(X)[1], j = 1:size(X)[1]
        A[i, j] = φ(r(X[i, :], X[j, :]), ϵ)
    end
    sigm_y = std(y)
    if std(y) != 0
        newy = (y .- mean(y)) / std(y)
        w = (pinv(A) * newy)
    else
        w = (pinv(A) * y)
    end
    w
end