text:
int_rules_1_2_4_4 = @theory begin

    #= ::Subsection::Closed:: =#
    #= 1.2.4.4*(f*x)^m*(d+e*x^(n-q))*(a*x^q+b*x^n+c*x^(2*n-q))^p =#
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(b') * (~x) ^ ~(n') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => Antiderivative((~x) ^ (~m + ~p * ~q) * (~A + ~B * (~x) ^ (~n - ~q)) * (~a + ~b * (~x) ^ (~n - ~q) + ~c * (~x) ^ (2 * (~n - ~q))) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~A, ~B, ~m, ~n, ~q], ~x) && (EqQ(~r, ~n - ~q) && (EqQ(~j, 2 * ~n - ~q) && (IntegerQ(~p) && PosQ(~n - ~q))))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(b') * (~x) ^ ~(n') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => ((~x) ^ (~m + 1) * (~A * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1) + ~B * (~m + ~p * ~q + 1) * (~x) ^ (~n - ~q)) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ ~p) / ((~m + ~p * ~q + 1) * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1)) + (((~n - ~q) * ~p) / ((~m + ~p * ~q + 1) * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1))) * Antiderivative((~x) ^ (~n + ~m) * Simp((2 * ~a * ~B * (~m + ~p * ~q + 1) - ~A * ~b * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1)) + (~b * ~B * (~m + ~p * ~q + 1) - 2 * ~A * ~c * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1)) * (~x) ^ (~n - ~q), ~x) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ (~p - 1), ~x) <-- FreeQ([~a, ~b, ~c, ~A, ~B], ~x) && (EqQ(~r, ~n - ~q) && (EqQ(~j, 2 * ~n - ~q) && (Not(IntegerQ(~p)) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (IGtQ(~n, 0) && (GtQ(~p, 0) && (RationalQ(~m, ~q) && (LeQ(~m + ~p * ~q, -((~n - ~q))) && (NeQ(~m + ~p * ~q + 1, 0) && NeQ(~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1, 0))))))))))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => With([n = ~q + ~r], ((~x) ^ (~m + 1) * (~A * (~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1) + ~B * (~m + ~p * ~q + 1) * (~x) ^ (n - ~q)) * (~a * (~x) ^ ~q + ~c * (~x) ^ (2n - ~q)) ^ ~p) / ((~m + ~p * ~q + 1) * (~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1)) + ((2 * (n - ~q) * ~p) / ((~m + ~p * ~q + 1) * (~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1))) * Antiderivative((~x) ^ (n + ~m) * Simp(~a * ~B * (~m + ~p * ~q + 1) - ~A * ~c * (~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1) * (~x) ^ (n - ~q), ~x) * (~a * (~x) ^ ~q + ~c * (~x) ^ (2n - ~q)) ^ (~p - 1), ~x) <-- EqQ(~j, 2n - ~q) && (IGtQ(n, 0) && (LeQ(~m + ~p * ~q, -((n - ~q))) && (NeQ(~m + ~p * ~q + 1, 0) && NeQ(~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1, 0))))) <-- FreeQ([~a, ~c, ~A, ~B], ~x) && (Not(IntegerQ(~p)) && (RationalQ(~m, ~p, ~q) && GtQ(~p, 0)))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(b') * (~x) ^ ~(n') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => ((~x) ^ ((~m - ~n) + 1) * ((~A * ~b - 2 * ~a * ~B) - (~b * ~B - 2 * ~A * ~c) * (~x) ^ (~n - ~q)) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ (~p + 1)) / ((~n - ~q) * (~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c)) + (1 / ((~n - ~q) * (~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c))) * Antiderivative((~x) ^ (~m - ~n) * Simp((((~m + ~p * ~q) - ~n) + ~q + 1) * (2 * ~a * ~B - ~A * ~b) + (~m + ~p * ~q + 2 * (~n - ~q) * (~p + 1) + 1) * (~b * ~B - 2 * ~A * ~c) * (~x) ^ (~n - ~q), ~x) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ (~p + 1), ~x) <-- FreeQ([~a, ~b, ~c, ~A, ~B], ~x) && (EqQ(~r, ~n - ~q) && (EqQ(~j, 2 * ~n - ~q) && (Not(IntegerQ(~p)) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (IGtQ(~n, 0) && (LtQ(~p, -1) && (RationalQ(~m, ~q) && GtQ(~m + ~p * ~q, (~n - ~q) - 1))))))))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => With([n = ~q + ~r], ((~x) ^ ((~m - n) + 1) * (~a * ~B - ~A * ~c * (~x) ^ (n - ~q)) * (~a * (~x) ^ ~q + ~c * (~x) ^ (2n - ~q)) ^ (~p + 1)) / (2 * ~a * ~c * (n - ~q) * (~p + 1)) - (1 / (2 * ~a * ~c * (n - ~q) * (~p + 1))) * Antiderivative((~x) ^ (~m - n) * Simp(~a * ~B * (((~m + ~p * ~q) - n) + ~q + 1) - ~A * ~c * (~m + ~p * ~q + (n - ~q) * 2 * (~p + 1) + 1) * (~x) ^ (n - ~q), ~x) * (~a * (~x) ^ ~q + ~c * (~x) ^ (2n - ~q)) ^ (~p + 1), ~x) <-- EqQ(~j, 2n - ~q) && (IGtQ(n, 0) && ~m + ~p * ~q > (n - ~q) - 1)) <-- FreeQ([~a, ~c, ~A, ~B], ~x) && (Not(IntegerQ(~p)) && (RationalQ(~m, ~q) && LtQ(~p, -1)))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(b') * (~x) ^ ~(n') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => ((~x) ^ (~m + 1) * (~b * ~B * (~n - ~q) * ~p + ~A * ~c * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1) + ~B * ~c * (~m + ~p * ~q + 2 * (~n - ~q) * ~p + 1) * (~x) ^ (~n - ~q)) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ ~p) / (~c * (~m + ~p * (2 * ~n - ~q) + 1) * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1)) + (((~n - ~q) * ~p) / (~c * (~m + ~p * (2 * ~n - ~q) + 1) * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1))) * Antiderivative((~x) ^ (~m + ~q) * Simp((2 * ~a * ~A * ~c * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1) - ~a * ~b * ~B * (~m + ~p * ~q + 1)) + ((2 * ~a * ~B * ~c * (~m + ~p * ~q + 2 * (~n - ~q) * ~p + 1) + ~A * ~b * ~c * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1)) - (~b) ^ 2 * ~B * (~m + ~p * ~q + (~n - ~q) * ~p + 1)) * (~x) ^ (~n - ~q), ~x) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ (~p - 1), ~x) <-- FreeQ([~a, ~b, ~c, ~A, ~B], ~x) && (EqQ(~r, ~n - ~q) && (EqQ(~j, 2 * ~n - ~q) && (Not(IntegerQ(~p)) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (IGtQ(~n, 0) && (GtQ(~p, 0) && (RationalQ(~m, ~q) && (GtQ(~m + ~p * ~q, -((~n - ~q)) - 1) && (NeQ(~m + ~p * (2 * ~n - ~q) + 1, 0) && NeQ(~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1, 0))))))))))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => With([n = ~q + ~r], ((~x) ^ (~m + 1) * (~A * (~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1) + ~B * (~m + ~p * ~q + 2 * (n - ~q) * ~p + 1) * (~x) ^ (n - ~q)) * (~a * (~x) ^ ~q + ~c * (~x) ^ (2n - ~q)) ^ ~p) / ((~m + ~p * (2n - ~q) + 1) * (~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1)) + (((n - ~q) * ~p) / ((~m + ~p * (2n - ~q) + 1) * (~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1))) * Antiderivative((~x) ^ (~m + ~q) * Simp(2 * ~a * ~A * (~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1) + 2 * ~a * ~B * (~m + ~p * ~q + 2 * (n - ~q) * ~p + 1) * (~x) ^ (n - ~q), ~x) * (~a * (~x) ^ ~q + ~c * (~x) ^ (2n - ~q)) ^ (~p - 1), ~x) <-- EqQ(~j, 2n - ~q) && (IGtQ(n, 0) && (GtQ(~m + ~p * ~q, -((n - ~q))) && (NeQ(~m + ~p * ~q + 2 * (n - ~q) * ~p + 1, 0) && (NeQ(~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1, 0) && NeQ(~m + 1, n)))))) <-- FreeQ([~a, ~c, ~A, ~B], ~x) && (Not(IntegerQ(~p)) && (RationalQ(~m, ~q) && GtQ(~p, 0)))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(b') * (~x) ^ ~(n') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => (-((~x) ^ ((~m - ~q) + 1)) * (((~A * (~b) ^ 2 - ~a * ~b * ~B) - 2 * ~a * ~A * ~c) + (~A * ~b - 2 * ~a * ~B) * ~c * (~x) ^ (~n - ~q)) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ (~p + 1)) / (~a * (~n - ~q) * (~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c)) + (1 / (~a * (~n - ~q) * (~p + 1) * ((~b) ^ 2 - 4 * ~a * ~c))) * Antiderivative((~x) ^ (~m - ~q) * Simp(((~A * (~b) ^ 2 * (~m + ~p * ~q + (~n - ~q) * (~p + 1) + 1) - ~a * ~b * ~B * (~m + ~p * ~q + 1)) - 2 * ~a * ~A * ~c * (~m + ~p * ~q + 2 * (~n - ~q) * (~p + 1) + 1)) + (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 3) + 1) * (~A * ~b - 2 * ~a * ~B) * ~c * (~x) ^ (~n - ~q), ~x) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ (~p + 1), ~x) <-- FreeQ([~a, ~b, ~c, ~A, ~B], ~x) && (EqQ(~r, ~n - ~q) && (EqQ(~j, 2 * ~n - ~q) && (Not(IntegerQ(~p)) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (IGtQ(~n, 0) && (LtQ(~p, -1) && (RationalQ(~m, ~q) && ~m + ~p * ~q < (~n - ~q) - 1)))))))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => With([n = ~q + ~r], (-((~x) ^ ((~m - ~q) + 1)) * (~A * ~c + ~B * ~c * (~x) ^ (n - ~q)) * (~a * (~x) ^ ~q + ~c * (~x) ^ (2n - ~q)) ^ (~p + 1)) / (2 * ~a * ~c * (n - ~q) * (~p + 1)) + (1 / (2 * ~a * ~c * (n - ~q) * (~p + 1))) * Antiderivative((~x) ^ (~m - ~q) * Simp(~A * ~c * (~m + ~p * ~q + 2 * (n - ~q) * (~p + 1) + 1) + ~B * (~m + ~p * ~q + (n - ~q) * (2 * ~p + 3) + 1) * ~c * (~x) ^ (n - ~q), ~x) * (~a * (~x) ^ ~q + ~c * (~x) ^ (2n - ~q)) ^ (~p + 1), ~x) <-- EqQ(~j, 2n - ~q) && (IGtQ(n, 0) && LtQ(~m + ~p * ~q, (n - ~q) - 1))) <-- FreeQ([~a, ~c, ~A, ~B], ~x) && (Not(IntegerQ(~p)) && (RationalQ(~m, ~q) && LtQ(~p, -1)))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(b') * (~x) ^ ~(n') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => (~B * (~x) ^ ((~m - ~n) + 1) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ (~p + 1)) / (~c * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1)) - (1 / (~c * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1))) * Antiderivative((~x) ^ ((~m - ~n) + ~q) * Simp(~a * ~B * (((~m + ~p * ~q) - ~n) + ~q + 1) + (~b * ~B * (~m + ~p * ~q + (~n - ~q) * ~p + 1) - ~A * ~c * (~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1)) * (~x) ^ (~n - ~q), ~x) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~A, ~B], ~x) && (EqQ(~r, ~n - ~q) && (EqQ(~j, 2 * ~n - ~q) && (Not(IntegerQ(~p)) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (IGtQ(~n, 0) && (GeQ(~p, -1) && (LtQ(~p, 0) && (RationalQ(~m, ~q) && (GeQ(~m + ~p * ~q, (~n - ~q) - 1) && NeQ(~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1, 0))))))))))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => With([n = ~q + ~r], (~B * (~x) ^ ((~m - n) + 1) * (~a * (~x) ^ ~q + ~c * (~x) ^ (2n - ~q)) ^ (~p + 1)) / (~c * (~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1)) - (1 / (~c * (~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1))) * Antiderivative((~x) ^ ((~m - n) + ~q) * Simp(~a * ~B * (((~m + ~p * ~q) - n) + ~q + 1) - ~A * ~c * (~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1) * (~x) ^ (n - ~q), ~x) * (~a * (~x) ^ ~q + ~c * (~x) ^ (2n - ~q)) ^ ~p, ~x) <-- EqQ(~j, 2n - ~q) && (IGtQ(n, 0) && (GeQ(~m + ~p * ~q, (n - ~q) - 1) && NeQ(~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1, 0)))) <-- FreeQ([~a, ~c, ~A, ~B], ~x) && (Not(IntegerQ(~p)) && (RationalQ(~m, ~p, ~q) && (GeQ(~p, -1) && LtQ(~p, 0))))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(b') * (~x) ^ ~(n') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => (~A * (~x) ^ ((~m - ~q) + 1) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ (~p + 1)) / (~a * (~m + ~p * ~q + 1)) + (1 / (~a * (~m + ~p * ~q + 1))) * Antiderivative((~x) ^ ((~m + ~n) - ~q) * Simp((~a * ~B * (~m + ~p * ~q + 1) - ~A * ~b * (~m + ~p * ~q + (~n - ~q) * (~p + 1) + 1)) - ~A * ~c * (~m + ~p * ~q + 2 * (~n - ~q) * (~p + 1) + 1) * (~x) ^ (~n - ~q), ~x) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~A, ~B], ~x) && (EqQ(~r, ~n - ~q) && (EqQ(~j, 2 * ~n - ~q) && (Not(IntegerQ(~p)) && (NeQ((~b) ^ 2 - 4 * ~a * ~c, 0) && (IGtQ(~n, 0) && (RationalQ(~m, ~p, ~q) && ((GeQ(~p, -1) && LtQ(~p, 0) || EqQ(~m + ~p * ~q + (~n - ~q) * (2 * ~p + 1) + 1, 0)) && (LeQ(~m + ~p * ~q, -((~n - ~q))) && NeQ(~m + ~p * ~q + 1, 0)))))))))
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(r')) * (~(a') * (~x) ^ ~(q') + ~(c') * (~x) ^ ~(j')) ^ ~(p'), ~x) => With([n = ~q + ~r], (~A * (~x) ^ ((~m - ~q) + 1) * (~a * (~x) ^ ~q + ~c * (~x) ^ (2n - ~q)) ^ (~p + 1)) / (~a * (~m + ~p * ~q + 1)) + (1 / (~a * (~m + ~p * ~q + 1))) * Antiderivative((~x) ^ ((~m + n) - ~q) * Simp(~a * ~B * (~m + ~p * ~q + 1) - ~A * ~c * (~m + ~p * ~q + 2 * (n - ~q) * (~p + 1) + 1) * (~x) ^ (n - ~q), ~x) * (~a * (~x) ^ ~q + ~c * (~x) ^ (2n - ~q)) ^ ~p, ~x) <-- EqQ(~j, 2n - ~q) && (IGtQ(n, 0) && ((GeQ(~p, -1) && LtQ(~p, 0) || EqQ(~m + ~p * ~q + (n - ~q) * (2 * ~p + 1) + 1, 0)) && (LeQ(~m + ~p * ~q, -((n - ~q))) && NeQ(~m + ~p * ~q + 1, 0))))) <-- FreeQ([~a, ~c, ~A, ~B], ~x) && (Not(IntegerQ(~p)) && RationalQ(~m, ~p, ~q))
    @apply_utils Antiderivative(((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~(j'))) / sqrt(~(a') * (~x) ^ ~(q') + ~(b') * (~x) ^ ~(n') + ~(c') * (~x) ^ ~(r')), ~x) => (((~x) ^ (~q / 2) * sqrt(~a + ~b * (~x) ^ (~n - ~q) + ~c * (~x) ^ (2 * (~n - ~q)))) / sqrt(~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q))) * Antiderivative(((~x) ^ (~m - ~q / 2) * (~A + ~B * (~x) ^ (~n - ~q))) / sqrt(~a + ~b * (~x) ^ (~n - ~q) + ~c * (~x) ^ (2 * (~n - ~q))), ~x) <-- FreeQ([~a, ~b, ~c, ~A, ~B, ~m, ~n, ~q], ~x) && (EqQ(~j, ~n - ~q) && (EqQ(~r, 2 * ~n - ~q) && (PosQ(~n - ~q) && ((EqQ(~m, 1 / 2) || EqQ(~m, -1 / 2)) && (EqQ(~n, 3) && EqQ(~q, 1))))))
    #= Antiderivative((~x)^(~m')*((~A)+(~B')*(~x)^(~j'))*((~a')*(~x)^(~q')+(~b')*(~x)^(~n')+(~c')*(~x)^(~r'))^(~p),(~x)*Symbol) :=  sqrt(a*x^q+b*x^n+c*x^(2*n-q))/(x^(q/2)*sqrt(a+b*x^(n-q)+c*x^(2*(n-q))) )* Antiderivative(x^(m+q*p)*(A+B*x^(n-q))*(a+b*x^(n-q)+c*x^(2*(n-q)))^p,x) <--  FreeQ([a,b,c,A,B,m,n,p,q],x) && EqQ(j,n-q) && EqQ(r,2*n-q) &&  IGtQ(p+1/2,0) && PosQ(n-q) =#
    #= Antiderivative((~x)^(~m')*((~A)+(~B')*(~x)^(~j'))*((~a')*(~x)^(~q')+(~b')*(~x)^(~n')+(~c')*(~x)^(~r'))^(~p),(~x)*Symbol) :=  x^(q/2)*sqrt(a+b*x^(n-q)+c*x^(2*(n-q)))/sqrt(a*x^q+b*x^n+c*x^(2*n-q))*  Antiderivative(x^(m+q*p)*(A+B*x^(n-q))*(a+b*x^(n-q)+c*x^(2*(n-q)))^p,x) <--  FreeQ([a,b,c,A,B,m,n,p,q],x) && EqQ(j,n-q) && EqQ(r,2*n-q) &&  ILtQ(p-1/2,0) && PosQ(n-q) =#
    @apply_utils Antiderivative((~x) ^ ~(m') * (~A + ~(B') * (~x) ^ ~q) * (~(a') * (~x) ^ ~(j') + ~(b') * (~x) ^ ~(k') + ~(c') * (~x) ^ ~(n')) ^ ~p, ~x) => ((~a * (~x) ^ ~j + ~b * (~x) ^ ~k + ~c * (~x) ^ ~n) ^ ~p / ((~x) ^ (~j * ~p) * (~a + ~b * (~x) ^ (~k - ~j) + ~c * (~x) ^ (2 * (~k - ~j))) ^ ~p)) * Antiderivative((~x) ^ (~m + ~j * ~p) * (~A + ~B * (~x) ^ (~k - ~j)) * (~a + ~b * (~x) ^ (~k - ~j) + ~c * (~x) ^ (2 * (~k - ~j))) ^ ~p, ~x) <-- FreeQ([~a, ~b, ~c, ~A, ~B, ~j, ~k, ~m, ~p], ~x) && (EqQ(~q, ~k - ~j) && (EqQ(~n, 2 * ~k - ~j) && (Not(IntegerQ(~p)) && PosQ(~k - ~j))))
    @apply_utils Antiderivative((~u) ^ ~(m') * (~A + ~(B') * (~u) ^ ~(j')) * (~(a') * (~u) ^ ~(q') + ~(b') * (~u) ^ ~(n') + ~(c') * (~u) ^ ~(r')) ^ ~(p'), ~x) => (1 / Coefficient(~u, ~x, 1)) * Subst(Antiderivative((~x) ^ ~m * (~A + ~B * (~x) ^ (~n - ~q)) * (~a * (~x) ^ ~q + ~b * (~x) ^ ~n + ~c * (~x) ^ (2 * ~n - ~q)) ^ ~p, ~x), ~x, ~u) <-- FreeQ([~a, ~b, ~c, ~A, ~B, ~m, ~n, ~p, ~q], ~x) && (EqQ(~j, ~n - ~q) && (EqQ(~r, 2 * ~n - ~q) && (LinearQ(~u, ~x) && NeQ(~u, ~x))))
end

max_stars_repo_path: src/rules/1 Algebraic functions/1.2 Trinomial products/1.2.4 Improper/1.2.4.4 (f x)^m (d+e x^(n-q)) (a x^q+b x^n+c x^(2 n-q))^p.jl


text:
using Pkg

if lowercase(get(ENV, "CI", "false")) == "true"
  if Sys.islinux()
    let basepython = get(ENV, "PYTHON", "python3")
        envpath = joinpath(@__DIR__, "env")
        run(`virtualenv --python=$basepython $envpath`)

        # python = joinpath(envpath, "Scripts", "python.exe")
        python = joinpath(envpath, "bin", "python3")

        run(`$python -m pip install scipy`)

        ENV["PYTHON"] = python
        Pkg.build("PyCall")
    end
  end
end

ext: jl


text:
using QuantizedNoise
using Test
using Statistics

@testset "QuantizedNoise.jl" begin
    @testset "real" begin
        @test typeof(randqn(Int8)) == Int8

        z = randqn(Int8, 2)
        @test typeof(z) == Vector{Int8}
        @test size(z) == (2,)

        z = randqn(Int16, 3, 3)
        @test typeof(z) == Array{Int16, 2}
        @test size(z) == (3,3)

        # 8-bit quantiation affects standard deviation least near 31
        z = randqn(Int8, 10^6, σ=31)
        @test std(z) ≈ 31 atol=0.2

        z = randqn(Int8, 10^6, std=31)
        @test std(z) ≈ 31 atol=0.2
    end

    @testset "complex" begin
        @test typeof(randqn(Complex{Int8})) == Complex{Int8}

        z = randqn(Complex{Int8}, 2)
        @test typeof(z) == Vector{Complex{Int8}}
        @test size(z) == (2,)

        z = randqn(Complex{Int16}, 3, 3)
        @test typeof(z) == Array{Complex{Int16}, 2}
        @test size(z) == (3,3)

        # 8-bit quantiation affects standard deviation least near 31
        z = randqn(Complex{Int8}, 10^6, σ=31)
        @test std(z) ≈ 31 atol=0.2

        z = randqn(Complex{Int8}, 10^6, std=31)
        @test std(z) ≈ 31 atol=0.2

        z = randqn(Complex{Int8}, 10^6, std=1+2im, mean=3+4im)
        @test std(real(z)) ≈ 1 atol=0.2
        @test std(imag(z)) ≈ 2 atol=0.2
        @test std(z) ≈ sqrt(5) atol=0.2
        @test mean(real(z)) ≈ 3 atol=0.2
        @test mean(imag(z)) ≈ 4 atol=0.2
    end
end


text:
module TestMemory
using Test, GaussianProcesses
using GaussianProcesses: EmptyData, init_precompute

@testset "Memory Allocation" begin
    @testset "simple" begin
        k = SEIso(0.0, 0.0)
        dim = 5
        nobs = 1000
        X = randn(dim, nobs)
        y = randn(nobs)
        logNoise = 0.1
        m = MeanZero()
        gp = GP(X, y, m, k, logNoise)
        mem = @allocated GP(X, y, m, k, logNoise)
        # there should be 1 allocation of an n×x matrix for the covariance
        # one for its Cholesky decomposition, and one for KernelData
        matrix_bytes = (nobs^2)*64/8
        @test mem/matrix_bytes < 3.1
        buf = init_precompute(gp)
        GaussianProcesses.update_mll_and_dmll!(gp, buf)
        mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
        @test mem/matrix_bytes < 0.1
    end

    @testset "sum kernel" begin
        k = SEIso(0.0, 0.0) + RQIso(1.0, 1.0, 1.0) + SEIso(1.0, 1.0)
        dim = 5
        nobs = 1000
        X = randn(dim, nobs)
        y = randn(nobs)
        logNoise = 0.1
        m = MeanZero()
        gp = GP(X, y, m, k, logNoise)
        mem = @allocated GP(X, y, m, k, logNoise)
        matrix_bytes = (nobs^2)*64/8
        @test mem/matrix_bytes < 3.1
        buf = init_precompute(gp)
        GaussianProcesses.update_mll_and_dmll!(gp, buf)
        mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
        @test mem/matrix_bytes < 0.1
    end

    @testset "sum noise" begin
        k = SEIso(0.0, 0.0) + Noise(1.0)
        dim = 5
        nobs = 1000
        X = randn(dim, nobs)
        y = randn(nobs)
        logNoise = 0.1
        m = MeanZero()
        gp = GP(X, y, m, k, logNoise)
        mem = @allocated GP(X, y, m, k, logNoise)
        matrix_bytes = (nobs^2)*64/8
        @test mem/matrix_bytes < 3.1
        buf = init_precompute(gp)
        GaussianProcesses.update_mll_and_dmll!(gp, buf)
        mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
        @test mem/matrix_bytes < 0.1
    end

    @testset "masked kernel" begin
        k = Masked(SEIso(0.0, 0.0), [2,3])
        dim = 5
        nobs = 1000
        X = randn(dim, nobs)
        y = randn(nobs)
        logNoise = 0.1
        m = MeanZero()
        gp = GP(X, y, m, k, logNoise)
        mem = @allocated GP(X, y, m, k, logNoise)
        matrix_bytes = (nobs^2)*64/8
        @test mem/matrix_bytes < 3.1
        buf = init_precompute(gp)
        GaussianProcesses.update_mll_and_dmll!(gp, buf)
        mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
        @test mem/matrix_bytes < 0.1
    end

    @testset "prod kernel" begin
        k = Mat12Iso(0.0, 0.0) * SEIso(0.0, 0.0) + RQIso(1.0, 1.0, 1.0) * Mat32Iso(1.0, 1.0)
        dim = 5
        nobs = 1000
        X = randn(dim, nobs)
        y = randn(nobs)
        logNoise = 0.1
        m = MeanZero()
        gp = GP(X, y, m, k, logNoise)
        mem = @allocated GP(X, y, m, k, logNoise)
        matrix_bytes = (nobs^2)*64/8
        @test mem/matrix_bytes < 4.1
        buf = init_precompute(gp)
        GaussianProcesses.update_mll_and_dmll!(gp, buf)
        mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
        @test mem/matrix_bytes < 0.1
    end

    @testset "EmptyData" begin
        k = SEIso(0.0, 0.0) + RQIso(1.0, 1.0, 1.0)
        dim = 5
        nobs = 1000
        X = randn(dim, nobs)
        y = randn(nobs)
        logNoise = 0.1
        m = MeanZero()
        gp = GPE(X, y, m, k, logNoise, EmptyData())
        mem = @allocated GPE(X, y, m, k, logNoise, EmptyData())
        matrix_bytes = (nobs^2)*64/8
        @test mem/matrix_bytes < 2.1
        buf = init_precompute(gp)
        GaussianProcesses.update_mll_and_dmll!(gp, buf)
        mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
        @test mem/matrix_bytes < 0.1
    end

    @testset "EmptyData prod kernel" begin
        k = (SEIso(0.0, 0.0) + RQIso(1.0, 1.0, 1.0)) * SEIso(1.0, 1.0)
        dim = 5
        nobs = 1000
        X = randn(dim, nobs)
        y = randn(nobs)
        logNoise = 0.1
        m = MeanZero()
        gp = GPE(X, y, m, k, logNoise, EmptyData())
        mem = @allocated GPE(X, y, m, k, logNoise, EmptyData())
        matrix_bytes = (nobs^2)*64/8
        @test mem/matrix_bytes < 2.1
        buf = init_precompute(gp)
        GaussianProcesses.update_mll_and_dmll!(gp, buf)
        mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
        @test mem/matrix_bytes < 0.1
    end
end
end


text:
# Tensor product polynomials, arbitrary domain

function chebyshev_weights(f::AbstractArray{T,1},nodes_1::Array{T,1},order::Array{S,1},domain=[ones(1);-ones(1)]) where {T<:AbstractFloat,S<:Integer}

  x1 = normalize_node(nodes_1,domain)

  polynomial_1 = chebyshev_polynomial(order[1],x1)

  weights = Array{T}(order[1]+1)

  for i = 1:order[1]+1

    numerator   = zero(T)
    denominator = zero(T)

    for s1 = 1:length(nodes_1)

      numerator   += f[s1]*polynomial_1[s1,i]
      denominator += (polynomial_1[s1,i])^2

    end

    weights[i] = numerator/denominator

  end

  return weights

end

function chebyshev_weights(f::AbstractArray{T,2},nodes_1::Array{T,1},nodes_2::Array{T,1},order::Array{S,1},domain=[ones(1,2);-ones(1,2)]) where {T<:AbstractFloat,S<:Integer}

  x1 = normalize_node(nodes_1,domain[:,1])
  x2 = normalize_node(nodes_2,domain[:,2])

  polynomial_1 = chebyshev_polynomial(order[1],x1)
  polynomial_2 = chebyshev_polynomial(order[2],x2)

  weights = Array{T}(order[1]+1,order[2]+1)

  for j = 1:order[2]+1
    for i = 1:order[1]+1

      numerator   = zero(T)
      denominator = zero(T)

      for s2 = 1:length(nodes_2)
        for s1 = 1:length(nodes_1)

          numerator   += f[s1,s2]*polynomial_1[s1,i]*polynomial_2[s2,j]
          denominator += (polynomial_1[s1,i]*polynomial_2[s2,j])^2

        end
      end

      weights[i,j] = numerator/denominator

    end
  end

  return weights

end

function chebyshev_weights(f::AbstractArray{T,3},nodes_1::Array{T,1},nodes_2::Array{T,1},nodes_3::Array{T,1},order::Array{S,1},domain=[ones(1,3);-ones(1,3)]) where {T<:AbstractFloat,S<:Integer}

  x1 = normalize_node(nodes_1,domain[:,1])
  x2 = normalize_node(nodes_2,domain[:,2])
  x3 = normalize_node(nodes_3,domain[:,3])

  polynomial_1 = chebyshev_polynomial(order[1],x1)
  polynomial_2 = chebyshev_polynomial(order[2],x2)
  polynomial_3 = chebyshev_polynomial(order[3],x3)

  weights = Array{T}(order[1]+1,order[2]+1,order[3]+1)

  for k = 1:order[3]+1
    for j = 1:order[2]+1
      for i = 1:order[1]+1

        numerator   = zero(T)
        denominator = zero(T)

        for s3 = 1:length(nodes_3)
          for s2 = 1:length(nodes_2)
            for s1 = 1:length(nodes_1)

              numerator   += f[s1,s2,s3]*polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]
              denominator += (polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k])^(2)

            end
          end
        end

        weights[i,j,k] = numerator/denominator

      end
    end
  end

  return weights

end

function chebyshev_weights(f::AbstractArray{T,4},nodes_1::Array{T,1},nodes_2::Array{T,1},nodes_3::Array{T,1},nodes_4::Array{T,1},order::Array{S,1},domain=[ones(1,4);-ones(1,4)]) where {T<:AbstractFloat,S<:Integer}

  x1 = normalize_node(nodes_1,domain[:,1])
  x2 = normalize_node(nodes_2,domain[:,2])
  x3 = normalize_node(nodes_3,domain[:,3])
  x4 = normalize_node(nodes_4,domain[:,4])

  polynomial_1 = chebyshev_polynomial(order[1],x1)
  polynomial_2 = chebyshev_polynomial(order[2],x2)
  polynomial_3 = chebyshev_polynomial(order[3],x3)
  polynomial_4 = chebyshev_polynomial(order[4],x4)

  weights = Array{T}(order[1]+1,order[2]+1,order[3]+1,order[4]+1)

  for l = 1:order[4]+1
    for k = 1:order[3]+1
      for j = 1:order[2]+1
        for i = 1:order[1]+1

          numerator   = zero(T)
          denominator = zero(T)

          for s4 = 1:length(nodes_4)
            for s3 = 1:length(nodes_3)
              for s2 = 1:length(nodes_2)
                for s1 = 1:length(nodes_1)

                  numerator   += f[s1,s2,s3,s4]*polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]*polynomial_4[s4,l]
                  denominator += (polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]*polynomial_4[s4,l])^(2.0)

                end
              end
            end
				  end

          weights[i,j,k,l] = numerator/denominator

        end
      end
    end
	 end

   return weights

end

function chebyshev_weights(f::AbstractArray{T,5},nodes_1::Array{T,1},nodes_2::Array{T,1},nodes_3::Array{T,1},nodes_4::Array{T,1},nodes_5::Array{T,1},order::Array{S,1},domain=[ones(1,5);-ones(1,5)]) where {T<:AbstractFloat,S<:Integer}

  x1 = normalize_node(nodes_1,domain[:,1])
  x2 = normalize_node(nodes_2,domain[:,2])
  x3 = normalize_node(nodes_3,domain[:,3])
  x4 = normalize_node(nodes_4,domain[:,4])
  x5 = normalize_node(nodes_5,domain[:,5])

  polynomial_1 = chebyshev_polynomial(order[1],x1)
  polynomial_2 = chebyshev_polynomial(order[2],x2)
  polynomial_3 = chebyshev_polynomial(order[3],x3)
  polynomial_4 = chebyshev_polynomial(order[4],x4)
  polynomial_5 = chebyshev_polynomial(order[5],x5)

  weights = Array{T}(order[1]+1,order[2]+1,order[3]+1,order[4]+1,order[5]+1)

	for m = 1:order[5]+1
	  for l = 1:order[4]+1
      for k = 1:order[3]+1
        for j = 1:order[2]+1
          for i = 1:order[1]+1

            numerator   = zero(T)
            denominator = zero(T)

            for s5 = 1:length(nodes_5)
              for s4 = 1:length(nodes_4)
                for s3 = 1:length(nodes_3)
                  for s2 = 1:length(nodes_2)
                    for s1 = 1:length(nodes_1)

                      numerator   += f[s1,s2,s3,s4,s5]*polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]*polynomial_4[s4,l]*polynomial_5[s5,m]
                      denominator += (polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]*polynomial_4[s4,l]*polynomial_5[s5,m])^(2.0)

                    end
                  end
                end
              end
						end

            weights[i,j,k,l,m] = numerator/denominator

          end
        end
      end
    end
	end

  return weights

end

function chebyshev_weights(f::AbstractArray{T,6},nodes_1::Array{T,1},nodes_2::Array{T,1},nodes_3::Array{T,1},nodes_4::Array{T,1},nodes_5::Array{T,1},nodes_6::Array{T,1},order::Array{S,1},domain=[ones(1,6);-ones(1,6)]) where {T<:AbstractFloat,S<:Integer}

  x1 = normalize_node(nodes_1,domain[:,1])
  x2 = normalize_node(nodes_2,domain[:,2])
  x3 = normalize_node(nodes_3,domain[:,3])
  x4 = normalize_node(nodes_4,domain[:,4])
  x5 = normalize_node(nodes_5,domain[:,5])
  x6 = normalize_node(nodes_6,domain[:,6])

  polynomial_1 = chebyshev_polynomial(order[1],x1)
  polynomial_2 = chebyshev_polynomial(order[2],x2)
  polynomial_3 = chebyshev_polynomial(order[3],x3)
  polynomial_4 = chebyshev_polynomial(order[4],x4)
  polynomial_5 = chebyshev_polynomial(order[5],x5)
  polynomial_6 = chebyshev_polynomial(order[6],x6)

  weights = Array{T}(order[1]+1,order[2]+1,order[3]+1,order[4]+1,order[5]+1,order[6]+1)

	for n = 1:order[6]+1
	  for m = 1:order[5]+1
	    for l = 1:order[4]+1
        for k = 1:order[3]+1
          for j = 1:order[2]+1
            for i = 1:order[1]+1

              numerator   = zero(T)
              denominator = zero(T)

              for s6 = 1:length(nodes_6)
                for s5 = 1:length(nodes_5)
                  for s4 = 1:length(nodes_4)
                    for s3 = 1:length(nodes_3)
                      for s2 = 1:length(nodes_2)
                        for s1 = 1:length(nodes_1)

                          numerator   += f[s1,s2,s3,s4,s5,s6]*polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]*polynomial_4[s4,l]*polynomial_5[s5,m]*polynomial_6[s6,n]
                          denominator += (polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]*polynomial_4[s4,l]*polynomial_5[s5,m]*polynomial_6[s6,n])^(2.0)

                        end
                      end
                    end
                  end
                end
						  end

              weights[i,j,k,l,m,n] = numerator/denominator

            end
          end
        end
      end
    end
	end

  return weights

end

# Complete polynomials, arbitrary domain

function chebyshev_weights(f::AbstractArray{T,1},nodes_1::Array{T,1},order::S,domain=[ones(1);-ones(1)]) where {T<:AbstractFloat,S<:Integer}

  x1 = normalize_node(nodes_1,domain)

  polynomial_1 = chebyshev_polynomial(order,x1)

  weights = Array{T}(order+1)

  for i = 1:order+1

    numerator   = zero(T)
    denominator = zero(T)

    for s1 = 1:length(nodes_1)

      numerator   += f[s1]*polynomial_1[s1,i]
      denominator += (polynomial_1[s1,i])^2

    end

    weights[i] = numerator/denominator

  end

  return weights

end

function chebyshev_weights(f::AbstractArray{T,2},nodes_1::Array{T,1},nodes_2::Array{T,1},order::S,domain=[ones(1,2);-ones(1,2)]) where {T<:AbstractFloat,S<:Integer}

  x1 = normalize_node(nodes_1,domain[:,1])
  x2 = normalize_node(nodes_2,domain[:,2])

  polynomial_1 = chebyshev_polynomial(order,x1)
  polynomial_2 = chebyshev_polynomial(order,x2)

  weights = zeros(order+1,order+1)

  for j = 1:order+1
    for i = 1:order+1

      numerator   = zero(T)
      denominator = zero(T)

      if (i+j <= order+2)

        for s2 = 1:length(nodes_2)
          for s1 = 1:length(nodes_1)

            numerator   += f[s1,s2]*polynomial_1[s1,i]*polynomial_2[s2,j]
            denominator += (polynomial_1[s1,i]*polynomial_2[s2,j])^(2)

          end
        end

        weights[i,j] = numerator/denominator

      end

    end
  end

  return weights

end

function chebyshev_weights(f::AbstractArray{T,3},nodes_1::Array{T,1},nodes_2::Array{T,1},nodes_3::Array{T,1},order::S,domain=[ones(1,3);-ones(1,3)]) where {T<:AbstractFloat,S<:Integer}

  x1 = normalize_node(nodes_1,domain[:,1])
  x2 = normalize_node(nodes_2,domain[:,2])
  x3 = normalize_node(nodes_3,domain[:,3])

  polynomial_1 = chebyshev_polynomial(order,x1)
  polynomial_2 = chebyshev_polynomial(order,x2)
  polynomial_3 = chebyshev_polynomial(order,x3)

  weights = zeros(order+1,order+1,order+1)

  for k = 1:order+1
    for j = 1:order+1
      for i = 1:order+1

        numerator   = zero(T)
        denominator = zero(T)

        if (i+j+k <= order+3)

          for s3 = 1:length(nodes_3)
            for s2 = 1:length(nodes_2)
              for s1 = 1:length(nodes_1)

                numerator   += f[s1,s2,s3]*polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]
                denominator += (polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k])^2

              end
            end
          end

          weights[i,j,k] = numerator/denominator

        end

      end
    end
  end

  return weights

end

function chebyshev_weights(f::AbstractArray{T,4},nodes_1::Array{T,1},nodes_2::Array{T,1},nodes_3::Array{T,1},nodes_4::Array{T,1},order::S,domain=[ones(1,4);-ones(1,4)]) where {T<:AbstractFloat,S<:Integer}

  x1 = normalize_node(nodes_1,domain[:,1])
  x2 = normalize_node(nodes_2,domain[:,2])
  x3 = normalize_node(nodes_3,domain[:,3])
  x4 = normalize_node(nodes_4,domain[:,4])

  polynomial_1 = chebyshev_polynomial(order,x1)
  polynomial_2 = chebyshev_polynomial(order,x2)
  polynomial_3 = chebyshev_polynomial(order,x3)
  polynomial_4 = chebyshev_polynomial(order,x4)

  weights = zeros(order+1,order+1,order+1,order+1)

  for l = 1:order+1
    for k = 1:order+1
      for j = 1:order+1
        for i = 1:order+1

          numerator   = zero(T)
          denominator = zero(T)

          if (i+j+k+l <= order+4)

            for s4 = 1:length(nodes_4)
              for s3 = 1:length(nodes_3)
                for s2 = 1:length(nodes_2)
                  for s1 = 1:length(nodes_1)

                    numerator   += f[s1,s2,s3,s4]*polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]*polynomial_4[s4,l]
                    denominator += (polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]*polynomial_4[s4,l])^2

                  end
                end
              end
            end

            weights[i,j,k,l] = numerator/denominator

          end

        end
      end
    end
  end

  return weights

end

function chebyshev_weights(f::AbstractArray{T,5},nodes_1::Array{T,1},nodes_2::Array{T,1},nodes_3::Array{T,1},nodes_4::Array{T,1},nodes_5::Array{T,1},order::S,domain=[ones(1,5);-ones(1,5)]) where {T<:AbstractFloat,S<:Integer}

  x1 = normalize_node(nodes_1,domain[:,1])
  x2 = normalize_node(nodes_2,domain[:,2])
  x3 = normalize_node(nodes_3,domain[:,3])
  x4 = normalize_node(nodes_4,domain[:,4])
  x5 = normalize_node(nodes_5,domain[:,5])

  polynomial_1 = chebyshev_polynomial(order,x1)
  polynomial_2 = chebyshev_polynomial(order,x2)
  polynomial_3 = chebyshev_polynomial(order,x3)
  polynomial_4 = chebyshev_polynomial(order,x4)
  polynomial_5 = chebyshev_polynomial(order,x5)

  weights = zeros(order+1,order+1,order+1,order+1,order+1)

  for m = 1:order+1
    for l = 1:order+1
      for k = 1:order+1
        for j = 1:order+1
          for i = 1:order+1

            numerator   = zero(T)
            denominator = zero(T)

            if (i+j+k+l+m <= order+5)

              for s5 = 1:length(nodes_5)
                for s4 = 1:length(nodes_4)
                  for s3 = 1:length(nodes_3)
                    for s2 = 1:length(nodes_2)
                      for s1 = 1:length(nodes_1)

                        numerator   += f[s1,s2,s3,s4,s5]*polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]*polynomial_4[s4,l]*polynomial_5[s5,m]
                        denominator += (polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]*polynomial_4[s4,l]*polynomial_5[s5,m])^2

                      end
                    end
                  end
                end
              end

              weights[i,j,k,l,m] = numerator/denominator

            end

          end
        end
      end
    end
  end

  return weights

end

function chebyshev_weights(f::AbstractArray{T,6},nodes_1::Array{T,1},nodes_2::Array{T,1},nodes_3::Array{T,1},nodes_4::Array{T,1},nodes_5::Array{T,1},nodes_6::Array{T,1},order::S,domain=[ones(1,6);-ones(1,6)]) where {T<:AbstractFloat,S<:Integer}

  x1 = normalize_node(nodes_1,domain[:,1])
  x2 = normalize_node(nodes_2,domain[:,2])
  x3 = normalize_node(nodes_3,domain[:,3])
  x4 = normalize_node(nodes_4,domain[:,4])
  x5 = normalize_node(nodes_5,domain[:,5])
  x6 = normalize_node(nodes_6,domain[:,6])

  polynomial_1 = chebyshev_polynomial(order,x1)
  polynomial_2 = chebyshev_polynomial(order,x2)
  polynomial_3 = chebyshev_polynomial(order,x3)
  polynomial_4 = chebyshev_polynomial(order,x4)
  polynomial_5 = chebyshev_polynomial(order,x5)
  polynomial_6 = chebyshev_polynomial(order,x6)

  weights = zeros(order+1,order+1,order+1,order+1,order+1,order+1)

  for n = 1:order+1
    for m = 1:order+1
      for l = 1:order+1
        for k = 1:order+1
          for j = 1:order+1
            for i = 1:order+1

              numerator   = zero(T)
              denominator = zero(T)

              if (i+j+k+l+m+n <= order+6)

                for s6 = 1:length(nodes_6)
                  for s5 = 1:length(nodes_5)
                    for s4 = 1:length(nodes_4)
                      for s3 = 1:length(nodes_3)
                        for s2 = 1:length(nodes_2)
                          for s1 = 1:length(nodes_1)

                            numerator   += f[s1,s2,s3,s4,s5,s6]*polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]*polynomial_4[s4,l]*polynomial_5[s5,m]*polynomial_6[s6,n]
                            denominator += (polynomial_1[s1,i]*polynomial_2[s2,j]*polynomial_3[s3,k]*polynomial_4[s4,l]*polynomial_5[s5,m]*polynomial_6[s6,n])^2.0

                          end
                        end
                      end
                    end
                  end
                end

                weights[i,j,k,l,m,n] = numerator/denominator

              end

            end
          end
        end
      end
    end
  end

  return weights

end

max_issues_repo_name: RJDennis/ChebyshevApprox

max_forks_repo_name: RJDennis/ChebyshevApprox


text:
using SparseArrays

function row_order_reshape(A, reshape_dims)
    #I dont think Julia natively supports row based reshape
    # https://github.com/JuliaLang/julia/issues/20311
    return transpose(reshape(transpose(A), reshape_dims...))
end

max_stars_repo_name: MatthewMcLeod/curiosity

max_issues_repo_name: MatthewMcLeod/curiosity

max_forks_repo_name: MatthewMcLeod/curiosity


text:
using MomentClosure, Test, Latexify

@parameters t, k_on, k_off, k_p, γ_p, b
@variables p(t), g(t)

vars = [g, p]
ps = [k_on, k_off, k_p, γ_p, b]
S = [1 -1 0 0;
   0 0 b -1]
as = [k_on*(1-g),    # 0 -> g
    k_off*g*(p^2), # g -> 0
    k_p*g,         # 0 -> mP, m ~ Geometric(mean=b)
    γ_p*p]         # p -> 0
binary_vars = [1]
rn = ReactionSystemMod(t, vars, ps, as, S)

raw_eqs = generate_raw_moment_eqs(rn, 2)
closed_raw_eqs = moment_closure(raw_eqs, "conditional gaussian", binary_vars)

expr = replace(raw"\begin{align*}
\frac{d\mu{_{10}}}{dt} =& k_{on} - k_{on} \mu{_{10}} - k_{off} \mu{_{10}}^{-1} \mu{_{11}}^{2} \\
\frac{d\mu{_{01}}}{dt} =& b k_{p} \mu{_{10}} - \gamma_{p} \mu{_{01}} \\
\frac{d\mu{_{11}}}{dt} =& k_{on} \mu{_{01}} + b k_{p} \mu{_{10}} - k_{on} \mu{_{11}} - \gamma_{p} \mu{_{11}} - k_{off} \mu{_{10}}^{-2} \mu{_{11}}^{3} \\
\frac{d\mu{_{02}}}{dt} =& \gamma_{p} \mu{_{01}} + b k_{p} \mu{_{10}} + 2 b k_{p} \mu{_{11}} + 2 k_{p} b^{2} \mu{_{10}} - 2 \gamma_{p} \mu{_{02}}
\end{align*}
", "\r\n"=>"\n")
@test latexify(closed_raw_eqs) == expr

expr = replace(raw"\begin{align*}
\mu{_{12}} =& \mu{_{10}}^{-1} \mu{_{11}}^{2} \\
\mu{_{13}} =& 3 \mu{_{10}}^{-1} \mu{_{11}} \mu{_{12}} - 2 \mu{_{10}}^{-2} \mu{_{11}}^{3}
\end{align*}
", "\r\n"=>"\n")
@test latexify(closed_raw_eqs, :closure) == expr

@test_throws MethodError latexify(raw_eqs, :closure)


text:
# Bio.Intervals
# =============
#
# Module for genomic intervals.
#
# This file is a part of BioJulia.
# License is MIT: https://github.com/BioJulia/Bio.jl/blob/master/LICENSE.md

module Intervals

export
    Strand,
    Interval,
    leftposition,
    rightposition,
    IntervalCollection,
    IntervalStream,
    STRAND_NA,
    STRAND_POS,
    STRAND_NEG,
    STRAND_BOTH,
    coverage,
    isoverlapping,
    seqname,
    metadata,
    strand,
    BEDReader,
    BEDWriter,
    BEDMetadata,
    BEDInterval,
    BigBedReader,
    BigBedWriter,
    Tabix,
    overlapchunks

import ..Ragel: tryread!
export tryread!

import Bio
using
    BufferedStreams,
    Colors,
    IntervalTrees,
    Libz,
    Bio.Ragel,
    Bio.StringFields,
    Bio.Seq

using Base.Collections:
    heappush!,
    heappop!

import Iterators

include("strand.jl")
include("interval.jl")
include("stream_buffer.jl")
include("intervalcollection.jl")
include("intervalstream.jl")
include("index/index.jl")

# Parsing file types
include("bed/bed.jl")
include("bbi/bbi.jl")

include("deprecated.jl")

end # module Intervals


text:
using HaploSoup
using Test

@testset "HaploSoup.jl" begin
    H =  Array{Int8, 2}([0 1 0 1 0 1; 1 1 0 0 0 1; 1 1 1 1 1 1; 0 1 1 1 1 0; 0 0 0 0 0 0; 1 0 0 0 1 0; 1 1 0 0 0 1; 0 1 0 1 1 0])
    ppa = Array{Int32, 2}([1 1 5 5 5 5 5; 2 4 6 6 6 2 6; 3 5 1 1 2 7 8; 4 8 4 8 7 1 4; 5 2 8 2 1 6 2; 6 3 2 7 8 8 7; 7 6 3 4 4 4 1; 8 7 7 3 3 3 3])
    div = Array{Int32, 2}([1 2 3 4 5 6 7; 1 1 2 2 2 3 6; 1 1 3 3 3 1 5; 1 1 1 1 1 5 4; 1 2 1 2 5 6 7; 1 1 2 1 1 5 1; 1 1 1 4 4 4 5; 1 1 1 2 2 2 6])
    @test build_prefix_and_divergence_arrays(H) == (ppa, div)
end


text:
#計算の前提条件読込み
"""
    readprerequisite(ExcelFilePath::String,parameters::String,schedule::String;schedulcolumn::Int=6)

# 処理概要
スケジュール作成

# 引数
* `ExcelFilePath`:スケジュール作成に必要な情報が記載されたExcelファイルのフルパスを指定。
* `parameters`:パラメーターが記載されたシート名を指定
* `schedule`:ジョブ作成に必要な情報が記載されたシート名を指定
* `schedulcolumn`:スケジュールON,OFF開始列を指定（デフォルト：６）

# 結果（戻り値）
パラメータの読込み結果を出力
"""
function readprerequisite(ExcelFilePath::String,parameters::String,schedule::String;schedulcolumn::Int=6)
  parameters=DataFrames.DataFrame(XLSX.readtable(ExcelFilePath, parameters)...)
  scheduleplan=DataFrames.DataFrame(XLSX.readtable(ExcelFilePath, schedule)...)

  # 前提条件設定
  robotn=parameters[parameters[:,:parameter] .== "all_run_robot",:Int][1] #ロボット
  run_unit_time=parameters[parameters[:,:parameter] .== "run_unit_time",:Int][1] #実行単位時間、コマ割時間
  jobn=size(scheduleplan)[1] #ジョブ数
  timen=size(scheduleplan)[2]-schedulcolumn #時間コマ数

  return scheduleplan,robotn,run_unit_time,jobn,timen
end


text:
import FileIO
using Printf: @sprintf
using Geometry: CameraIntrinsics, TriangleMesh, SceneGraphNode, Pose6D, to_matrix, I4

using DepthRenderer

width = 100
height = 100

cam = CameraIntrinsics(
    width=width, height=height,
    fx=width, fy=height, cx=div(width, 2), cy=div(height, 2),
    near=0.001, far=5.0)

renderer = Renderer(cam)

# triangle 1
a = Float32[-1, -1, -2.0]
b = Float32[1, -1, -2.0]
c = Float32[0, 1, -2.0]
vertices = hcat(a, b, c)
indices = hcat(UInt32[0, 1, 2])
triangle1 = TriangleMesh(vertices, indices)
register_mesh!(renderer, triangle1)

# triangle 2
a = Float32[1.5, 2, -4]
b = Float32[2, 2, -4]
c = Float32[2, 1.5, -4]
vertices = hcat(a, b, c)
indices = hcat(UInt32[0, 1, 2])
triangle2 = TriangleMesh(vertices, indices)
register_mesh!(renderer, triangle2)

# mug
mug = TriangleMesh("mug.obj")
register_mesh!(renderer, mug)

# scene graph
root = SceneGraphNode(
    children=[
        SceneGraphNode(mesh=triangle1),
        SceneGraphNode(mesh=triangle2),
        SceneGraphNode(mesh=mug, transform=to_matrix(Pose6D(0, 0, -0.5, 0, 0, 0)))])

model = I4(Float32)
view = I4(Float32)

function do_render_test(n::Int)
    for i=1:n
        println("i: $i")
        draw!(renderer, root, model, view)
        depths = get_depth_image!(renderer; show_in_window=true)
        normalize_and_save_depth_image(depths, 5.0, @sprintf("imgs/depth-%04d.png", i))
    end
end

@time do_render_test(10000)
@time do_render_test(10000)

# NOTE: This is commented out, so that ProfileView is not a dependency
#using Profile
#using ProfileView
#Profile.clear()
#@profile do_render_test(10000)
#li, lidict = Profile.retrieve()
#using JLD
#@save "profdata.jld" li lidict

destroy!(renderer)

max_stars_repo_name: probcomp/DepthRenderer

max_issues_repo_name: probcomp/DepthRenderer

max_forks_repo_name: probcomp/DepthRenderer