text:
using Rubin
using Tests
using Elliptic
using HypergeometricFunctions
using Polylogarithms
using SpecialFunctions

@test integrate(x^3*(d+-1*d*c^2*x^2)^-1*(a+b*arccos(c*x)), x) == :(-1*c^-4*d^-1*(a+b*arccos(c*x))*log(1+-1*exp(2*im*arccos(c*x)))+-1//2*c^-2*d^-1*x^2*(a+b*arccos(c*x))+-1//4*b*c^-4*d^-1*arcsin(c*x)+(1/2)*im*b*c^-4*d^-1*Polylogarithms.polylog(2,exp(2*im*arccos(c*x)))+(1/2)*im*b^-1*c^-4*d^-1*(a+b*arccos(c*x))^2+1//4*b*x*c^-3*d^-1*(1+-1*c^2*x^2)^(1/2))
@test integrate(x^2*(d+-1*d*c^2*x^2)^-1*(a+b*arccos(c*x)), x) == :(b*c^-3*d^-1*(1+-1*c^2*x^2)^(1/2)+c^-3*d^-1*(2a+2*b*arccos(c*x))*arctanh(exp(im*arccos(c*x)))+-1*x*c^-2*d^-1*(a+b*arccos(c*x))+im*b*c^-3*d^-1*Polylogarithms.polylog(2,exp(im*arccos(c*x)))+-1*im*b*c^-3*d^-1*Polylogarithms.polylog(2,-1*exp(im*arccos(c*x))))
@test integrate(x*(d+-1*d*c^2*x^2)^-1*(a+b*arccos(c*x)), x) == :(-1*c^-2*d^-1*(a+b*arccos(c*x))*log(1+-1*exp(2*im*arccos(c*x)))+(1/2)*im*b*c^-2*d^-1*Polylogarithms.polylog(2,exp(2*im*arccos(c*x)))+(1/2)*im*b^-1*c^-2*d^-1*(a+b*arccos(c*x))^2)
@test integrate((d+-1*d*c^2*x^2)^-1*(a+b*arccos(c*x)), x) == :(c^-1*d^-1*(2a+2*b*arccos(c*x))*arctanh(exp(im*arccos(c*x)))+im*b*c^-1*d^-1*Polylogarithms.polylog(2,exp(im*arccos(c*x)))+-1*im*b*c^-1*d^-1*Polylogarithms.polylog(2,-1*exp(im*arccos(c*x))))
@test integrate(x^-1*(d+-1*d*c^2*x^2)^-1*(a+b*arccos(c*x)), x) == :(d^-1*(2a+2*b*arccos(c*x))*arctanh(exp(2*im*arccos(c*x)))+(1/2)*im*b*d^-1*Polylogarithms.polylog(2,exp(2*im*arccos(c*x)))+-1//2*im*b*d^-1*Polylogarithms.polylog(2,-1*exp(2*im*arccos(c*x))))
@test integrate(x^-2*(d+-1*d*c^2*x^2)^-1*(a+b*arccos(c*x)), x) == :(-1*d^-1*x^-1*(a+b*arccos(c*x))+b*c*d^-1*arctanh((1+-1*c^2*x^2)^(1/2))+2*c*d^-1*(a+b*arccos(c*x))*arctanh(exp(im*arccos(c*x)))+im*b*c*d^-1*Polylogarithms.polylog(2,exp(im*arccos(c*x)))+-1*im*b*c*d^-1*Polylogarithms.polylog(2,-1*exp(im*arccos(c*x))))
@test integrate(x^-3*(d+-1*d*c^2*x^2)^-1*(a+b*arccos(c*x)), x) == :(-1//2*d^-1*x^-2*(a+b*arccos(c*x))+2*c^2*d^-1*(a+b*arccos(c*x))*arctanh(exp(2*im*arccos(c*x)))+(1/2)*im*b*c^2*d^-1*Polylogarithms.polylog(2,exp(2*im*arccos(c*x)))+(1/2)*b*c*d^-1*x^-1*(1+-1*c^2*x^2)^(1/2)+-1//2*im*b*c^2*d^-1*Polylogarithms.polylog(2,-1*exp(2*im*arccos(c*x))))
@test integrate(x^4*(d+-1*d*c^2*x^2)^-2*(a+b*arccos(c*x)), x) == :((1/2)*b*c^-5*d^-2*(1+-1*c^2*x^2)^-1//2+-1*b*c^-5*d^-2*(1+-1*c^2*x^2)^(1/2)+-1*c^-5*d^-2*(3a+3*b*arccos(c*x))*arctanh(exp(im*arccos(c*x)))+3//2*x*c^-4*d^-2*(a+b*arccos(c*x))+(1/2)*c^-2*d^-2*x^3*(1+-1*c^2*x^2)^-1*(a+b*arccos(c*x))+-3//2*im*b*c^-5*d^-2*Polylogarithms.polylog(2,exp(im*arccos(c*x)))+3//2*im*b*c^-5*d^-2*Polylogarithms.polylog(2,-1*exp(im*arccos(c*x))))
@test integrate(x^3*(d+-1*d*c^2*x^2)^-2*(a+b*arccos(c*x)), x) == :(c^-4*d^-2*(a+b*arccos(c*x))*log(1+-1*exp(2*im*arccos(c*x)))+-1//2*b*c^-4*d^-2*arcsin(c*x)+(1/2)*b*x*c^-3*d^-2*(1+-1*c^2*x^2)^-1//2+(1/2)*c^-2*d^-2*x^2*(1+-1*c^2*x^2)^-1*(a+b*arccos(c*x))+-1//2*im*b*c^-4*d^-2*Polylogarithms.polylog(2,exp(2*im*arccos(c*x)))+-1//2*im*b^-1*c^-4*d^-2*(a+b*arccos(c*x))^2)
@test integrate(x^2*(d+-1*d*c^2*x^2)^-2*(a+b*arccos(c*x)), x) == :((1/2)*b*c^-3*d^-2*(1+-1*c^2*x^2)^-1//2+-1*c^-3*d^-2*(a+b*arccos(c*x))*arctanh(exp(im*arccos(c*x)))+(1/2)*im*b*c^-3*d^-2*Polylogarithms.polylog(2,-1*exp(im*arccos(c*x)))+(1/2)*x*c^-2*d^-2*(1+-1*c^2*x^2)^-1*(a+b*arccos(c*x))+-1//2*im*b*c^-3*d^-2*Polylogarithms.polylog(2,exp(im*arccos(c*x))))
@test integrate(x*(d+-1*d*c^2*x^2)^-2*(a+b*arccos(c*x)), x) == :((1/2)*c^-2*d^-2*(1+-1*c^2*x^2)^-1*(a+b*arccos(c*x))+(1/2)*b*x*c^-1*d^-2*(1+-1*c^2*x^2)^-1//2)
@test integrate((d+-1*d*c^2*x^2)^-2*(a+b*arccos(c*x)), x) == :(c^-1*d^-2*(a+b*arccos(c*x))*arctanh(exp(im*arccos(c*x)))+(1/2)*b*c^-1*d^-2*(1+-1*c^2*x^2)^-1//2+(1/2)*x*d^-2*(1+-1*c^2*x^2)^-1*(a+b*arccos(c*x))+(1/2)*im*b*c^-1*d^-2*Polylogarithms.polylog(2,exp(im*arccos(c*x)))+-1//2*im*b*c^-1*d^-2*Polylogarithms.polylog(2,-1*exp(im*arccos(c*x))))
@test integrate(x^-1*(d+-1*d*c^2*x^2)^-2*(a+b*arccos(c*x)), x) == :(d^-2*(2a+2*b*arccos(c*x))*arctanh(exp(2*im*arccos(c*x)))+(1/2)*d^-2*(1+-1*c^2*x^2)^-1*(a+b*arccos(c*x))+(1/2)*im*b*d^-2*Polylogarithms.polylog(2,exp(2*im*arccos(c*x)))+-1//2*im*b*d^-2*Polylogarithms.polylog(2,-1*exp(2*im*arccos(c*x)))+(1/2)*b*c*x*d^-2*(1+-1*c^2*x^2)^-1//2)
@test integrate(x^-2*(d+-1*d*c^2*x^2)^-2*(a+b*arccos(c*x)), x) == :(b*c*d^-2*arctanh((1+-1*c^2*x^2)^(1/2))+(1/2)*b*c*d^-2*(1+-1*c^2*x^2)^-1//2+-1*d^-2*x^-1*(1+-1*c^2*x^2)^-1*(a+b*arccos(c*x))+3*c*d^-2*(a+b*arccos(c*x))*arctanh(exp(im*arccos(c*x)))+-3//2*im*b*c*d^-2*Polylogarithms.polylog(2,-1*exp(im*arccos(c*x)))+3//2*im*b*c*d^-2*Polylogarithms.polylog(2,exp(im*arccos(c*x)))+3//2*x*c^2*d^-2*(1+-1*c^2*x^2)^-1*(a+b*arccos(c*x)))
@test integrate(x^-3*(d+-1*d*c^2*x^2)^-2*(a+b*arccos(c*x)), x) == :(c^2*d^-2*(1+-1*c^2*x^2)^-1*(a+b*arccos(c*x))+4*c^2*d^-2*(a+b*arccos(c*x))*arctanh(exp(2*im*arccos(c*x)))+-1//2*d^-2*x^-2*(1+-1*c^2*x^2)^-1*(a+b*arccos(c*x))+im*b*c^2*d^-2*Polylogarithms.polylog(2,exp(2*im*arccos(c*x)))+(1/2)*b*c*d^-2*x^-1*(1+-1*c^2*x^2)^-1//2+-1*im*b*c^2*d^-2*Polylogarithms.polylog(2,-1*exp(2*im*arccos(c*x))))
@test integrate((d+-1*d*c^2*x^2)^(1/2)*(f+g*x)^3*(a+b*arccos(c*x)), x) == :((1/2)*x*f^3*(d+-1*d*c^2*x^2)^(1/2)*(a+b*arccos(c*x))+-1//3*c^-4*g^3*(d+-1*d*c^2*x^2)^(1/2)*(1+-1*c^2*x^2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exp(im*arccos(c*x)))+-1//2*b^-1*c^-1*(1+-1*c^2*x^2)^-1//2*(a+b*arccos(c*x))^2*(d+-1*d*c^2*x^2)^(1/2)*(f+g*x)^-2*(g+f*x*c^2)^2*(-1*g^2+c^2*f^2)^-1+im*b*f*c^2*g^-2*(1+-1*c^2*x^2)^-1//2*(d+-1*d*c^2*x^2)^(1/2)*(-1*g^2+c^2*f^2)^-1//2*arccos(c*x)*log(1+g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+-1*im*b*f*c^2*g^-2*(1+-1*c^2*x^2)^-1//2*(d+-1*d*c^2*x^2)^(1/2)*(-1*g^2+c^2*f^2)^-1//2*arccos(c*x)*log(1+g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x))))
@test integrate((d+-1*d*c^2*x^2)^3//2*(f+g*x)^3*(a+b*arccos(c*x)), x) == :(3//8*d*x*f^3*(d+-1*d*c^2*x^2)^(1/2)*(a+b*arccos(c*x))+-1//5*d*c^-4*g^3*(1+-1*c^2*x^2)^2*(d+-1*d*c^2*x^2)^(1/2)*(a+b*arccos(c*x))+1//4*d*x*f^3*(d+-1*d*c^2*x^2)^(1/2)*(1+-1*c^2*x^2)*(a+b*arccos(c*x))+1//7*d*c^-4*g^3*(1+-1*c^2*x^2)^3*(d+-1*d*c^2*x^2)^(1/2)*(a+b*arccos(c*x))+3//8*d*f*g^2*x^3*(d+-1*d*c^2*x^2)^(1/2)*(a+b*arccos(c*x))+(1/2)*d*f*g^2*x^3*(d+-1*d*c^2*x^2)^(1/2)*(1+-1*c^2*x^2)*(a+b*arccos(c*x))+-3//5*d*g*c^-2*f^2*(1+-1*c^2*x^2)^2*(d+-1*d*c^2*x^2)^(1/2)*(a+b*arccos(c*x))+-3//16*d*f*x*c^-2*g^2*(d+-1*d*c^2*x^2)^(1/2)*(a+b*arccos(c*x))+-3//16*d*b^-1*c^-1*f^3*(1+-1*c^2*x^2)^-1//2*(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+-1*d*c^2*x^2)^-1//2)
@test integrate((d+-1*d*c^2*x^2)^-1//2*(f+g*x)^-1*(a+b*arccos(c*x)), x) == :(b*(1+-1*c^2*x^2)^(1/2)*(d+-1*d*c^2*x^2)^-1//2*(-1*g^2+c^2*f^2)^-1//2*Polylogarithms.polylog(2,-1*g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+-1*b*(1+-1*c^2*x^2)^(1/2)*(d+-1*d*c^2*x^2)^-1//2*(-1*g^2+c^2*f^2)^-1//2*Polylogarithms.polylog(2,-1*g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+im*(1+-1*c^2*x^2)^(1/2)*(d+-1*d*c^2*x^2)^-1//2*(-1*g^2+c^2*f^2)^-1//2*(a+b*arccos(c*x))*log(1+g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+-1*im*(1+-1*c^2*x^2)^(1/2)*(d+-1*d*c^2*x^2)^-1//2*(-1*g^2+c^2*f^2)^-1//2*(a+b*arccos(c*x))*log(1+g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x))))
@test integrate((d+-1*d*c^2*x^2)^-1//2*(f+g*x)^-2*(a+b*arccos(c*x)), x) == :(b*c*(1+-1*c^2*x^2)^(1/2)*(d+-1*d*c^2*x^2)^-1//2*(-1*g^2+c^2*f^2)^-1*log(f+g*x)+g*(d+-1*d*c^2*x^2)^-1//2*(f+g*x)^-1*(-1*g^2+c^2*f^2)^-1*(1+-1*c^2*x^2)*(a+b*arccos(c*x))+b*f*c^2*(1+-1*c^2*x^2)^(1/2)*(d+-1*d*c^2*x^2)^-1//2*(-1*g^2+c^2*f^2)^-3//2*Polylogarithms.polylog(2,-1*g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+-1*b*f*c^2*(1+-1*c^2*x^2)^(1/2)*(d+-1*d*c^2*x^2)^-1//2*(-1*g^2+c^2*f^2)^-3//2*Polylogarithms.polylog(2,-1*g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+im*f*c^2*(1+-1*c^2*x^2)^(1/2)*(d+-1*d*c^2*x^2)^-1//2*(-1*g^2+c^2*f^2)^-3//2*(a+b*arccos(c*x))*log(1+g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+-1*im*f*c^2*(1+-1*c^2*x^2)^(1/2)*(d+-1*d*c^2*x^2)^-1//2*(-1*g^2+c^2*f^2)^-3//2*(a+b*arccos(c*x))*log(1+g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x))))
@test integrate((1+-1*c^2*x^2)^-1//2*(a+b*arccos(c*x))^2*log(h*(f+g*x)^m), x) == :(-1//3*b^-1*c^-1*(a+b*arccos(c*x))^3*log(h*(f+g*x)^m)+-1*im*m*c^-1*(a+b*arccos(c*x))^2*Polylogarithms.polylog(2,-1*g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+-1*im*m*c^-1*(a+b*arccos(c*x))^2*Polylogarithms.polylog(2,-1*g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+2*im*m*b^2*c^-1*Polylogarithms.polylog(4,-1*g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+2*im*m*b^2*c^-1*Polylogarithms.polylog(4,-1*g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+2*b*m*c^-1*(a+b*arccos(c*x))*Polylogarithms.polylog(3,-1*g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+2*b*m*c^-1*(a+b*arccos(c*x))*Polylogarithms.polylog(3,-1*g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+-1//12*im*m*b^-2*c^-1*(a+b*arccos(c*x))^4+1//3*m*b^-1*c^-1*(a+b*arccos(c*x))^3*log(1+g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+1//3*m*b^-1*c^-1*(a+b*arccos(c*x))^3*log(1+g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x))))
@test integrate((1+-1*c^2*x^2)^-1//2*(a+b*arccos(c*x))*log(h*(f+g*x)^m), x) == :(b*m*c^-1*Polylogarithms.polylog(3,-1*g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+b*m*c^-1*Polylogarithms.polylog(3,-1*g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+-1//2*b^-1*c^-1*(a+b*arccos(c*x))^2*log(h*(f+g*x)^m)+(1/2)*m*b^-1*c^-1*(a+b*arccos(c*x))^2*log(1+g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+(1/2)*m*b^-1*c^-1*(a+b*arccos(c*x))^2*log(1+g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+-1*im*m*c^-1*(a+b*arccos(c*x))*Polylogarithms.polylog(2,-1*g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+-1*im*m*c^-1*(a+b*arccos(c*x))*Polylogarithms.polylog(2,-1*g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arccos(c*x)))+-1//6*im*m*b^-2*c^-1*(a+b*arccos(c*x))^3)
@test integrate((1+-1*c^2*x^2)^-1//2*log(h*(f+g*x)^m), x) == :(c^-1*arcsin(c*x)*log(h*(f+g*x)^m)+im*m*c^-1*Polylogarithms.polylog(2,im*g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arcsin(c*x)))+im*m*c^-1*Polylogarithms.polylog(2,im*g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arcsin(c*x)))+(1/2)*im*m*c^-1*arcsin(c*x)^2+-1*m*c^-1*arcsin(c*x)*log(1+-1*im*g*((-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arcsin(c*x)))+-1*m*c^-1*arcsin(c*x)*log(1+-1*im*g*(-1*(-1*g^2+c^2*f^2)^(1/2)+c*f)^-1*exp(im*arcsin(c*x))))
@test integrate(x^3*(a+b*arccos(c*x))*(d+e*x^2), x) == :(1//4*d*x^4*(a+b*arccos(c*x))+1//6*e*x^6*(a+b*arccos(c*x))+1//96*b*c^-6*(5*e+9*d*c^2)*arcsin(c*x)+-1//36*b*e*c^-1*x^5*(1+-1*c^2*x^2)^(1/2)+-1//96*b*x*c^-5*(1+-1*c^2*x^2)^(1/2)*(5*e+9*d*c^2)+-1//144*b*c^-3*x^3*(1+-1*c^2*x^2)^(1/2)*(5*e+9*d*c^2))
@test integrate(x^2*(a+b*arccos(c*x))*(d+e*x^2), x) == :(1//3*d*x^3*(a+b*arccos(c*x))+1//5*e*x^5*(a+b*arccos(c*x))+-1//15*b*c^-5*(1+-1*c^2*x^2)^(1/2)*(3*e+5*d*c^2)+-1//25*b*e*c^-5*(1+-1*c^2*x^2)^5//2+1//45*b*c^-5*(1+-1*c^2*x^2)^3//2*(6*e+5*d*c^2))
@test integrate(x*(a+b*arccos(c*x))*(d+e*x^2), x) == :(1//4*e^-1*(d+e*x^2)^2*(a+b*arccos(c*x))+-3//32*b*x*c^-3*(1+-1*c^2*x^2)^(1/2)*(e+2*d*c^2)+-1//16*b*x*c^-1*(1+-1*c^2*x^2)^(1/2)*(d+e*x^2)+1//32*b*c^-4*e^-1*(3*e^2+8*c^4*d^2+8*d*e*c^2)*arcsin(c*x))
@test integrate((a+b*arccos(c*x))*(d+e*x^2), x) == :(d*x*(a+b*arccos(c*x))+1//3*e*x^3*(a+b*arccos(c*x))+-1//3*b*c^-3*(1+-1*c^2*x^2)^(1/2)*(e+3*d*c^2)+1//9*b*e*c^-3*(1+-1*c^2*x^2)^3//2)
@test integrate(x^-1*(a+b*arccos(c*x))*(d+e*x^2), x) == :(d*(a+b*arccos(c*x))*log(x)+(1/2)*e*x^2*(a+b*arccos(c*x))+b*d*arcsin(c*x)*log(x)+(1/2)*im*b*d*arcsin(c*x)^2+(1/2)*im*b*d*Polylogarithms.polylog(2,exp(2*im*arcsin(c*x)))+-1*b*d*arcsin(c*x)*log(1+-1*exp(2*im*arcsin(c*x)))+1//4*b*e*c^-2*arcsin(c*x)+-1//4*b*e*x*c^-1*(1+-1*c^2*x^2)^(1/2))
@test integrate(x^-2*(a+b*arccos(c*x))*(d+e*x^2), x) == :(e*x*(a+b*arccos(c*x))+-1*d*x^-1*(a+b*arccos(c*x))+b*c*d*arctanh((1+-1*c^2*x^2)^(1/2))+-1*b*e*c^-1*(1+-1*c^2*x^2)^(1/2))
@test integrate(x^-3*(a+b*arccos(c*x))*(d+e*x^2), x) == :(e*(a+b*arccos(c*x))*log(x)+-1//2*d*x^-2*(a+b*arccos(c*x))+b*e*arcsin(c*x)*log(x)+(1/2)*im*b*e*arcsin(c*x)^2+(1/2)*im*b*e*Polylogarithms.polylog(2,exp(2*im*arcsin(c*x)))+-1*b*e*arcsin(c*x)*log(1+-1*exp(2*im*arcsin(c*x)))+(1/2)*b*c*d*x^-1*(1+-1*c^2*x^2)^(1/2))
@test integrate(x^-4*(a+b*arccos(c*x))*(d+e*x^2), x) == :(-1*e*x^-1*(a+b*arccos(c*x))+-1//3*d*x^-3*(a+b*arccos(c*x))+1//6*b*c*(6*e+d*c^2)*arctanh((1+-1*c^2*x^2)^(1/2))+1//6*b*c*d*x^-2*(1+-1*c^2*x^2)^(1/2))
@test integrate((c+d*x^2)^2*arccos(a*x), x) == :(x*c^2*arccos(a*x)+-1//15*a^-5*(1+-1*a^2*x^2)^(1/2)*(3*d^2+15*a^4*c^2+10*c*d*a^2)+-1//25*a^-5*d^2*(1+-1*a^2*x^2)^5//2+1//5*d^2*x^5*arccos(a*x)+2//3*c*d*x^3*arccos(a*x)+2//45*d*a^-5*(1+-1*a^2*x^2)^3//2*(3d+5*c*a^2))
@test integrate((c+d*x^2)^3*arccos(a*x), x) == :(x*c^3*arccos(a*x)+-1//35*a^-7*(1+-1*a^2*x^2)^(1/2)*(5*d^3+35*a^6*c^3+21*c*a^2*d^2+35*d*a^4*c^2)+1//7*d^3*x^7*arccos(a*x)+1//49*a^-7*d^3*(1+-1*a^2*x^2)^7//2+d*c^2*x^3*arccos(a*x)+-3//175*a^-7*d^2*(1+-1*a^2*x^2)^5//2*(5d+7*c*a^2)+1//105*d*a^-7*(1+-1*a^2*x^2)^3//2*(15*d^2+35*a^4*c^2+42*c*d*a^2)+3//5*c*d^2*x^5*arccos(a*x))
@test integrate((c+d*x^2)^4*arccos(a*x), x) == :(x*c^4*arccos(a*x)+-1//81*a^-9*d^4*(1+-1*a^2*x^2)^9//2+-1//315*a^-9*(1+-1*a^2*x^2)^(1/2)*(35*d^4+315*a^8*c^4+180*c*a^2*d^3+378*a^4*c^2*d^2+420*d*a^6*c^3)+1//9*d^4*x^9*arccos(a*x)+-2//525*a^-9*d^2*(1+-1*a^2*x^2)^5//2*(35*d^2+63*a^4*c^2+90*c*d*a^2)+4//3*d*c^3*x^3*arccos(a*x)+4//7*c*d^3*x^7*arccos(a*x)+4//441*a^-9*d^3*(1+-1*a^2*x^2)^7//2*(7d+9*c*a^2)+4//945*d*a^-9*(1+-1*a^2*x^2)^3//2*(35*d^3+105*a^6*c^3+135*c*a^2*d^2+189*d*a^4*c^2)+6//5*c^2*d^2*x^5*arccos(a*x))
@test integrate((c+d*x^2)^-1*arccos(a*x), x) == :((1/2)*im*d^-1//2*(-1c)^-1//2*Polylogarithms.polylog(2,-1*d^(1/2)*(im*(d+c*a^2)^(1/2)+a*(-1c)^(1/2))^-1*exp(im*arccos(a*x)))+(1/2)*im*d^-1//2*(-1c)^-1//2*Polylogarithms.polylog(2,-1*d^(1/2)*(a*(-1c)^(1/2)+-1*im*(d+c*a^2)^(1/2))^-1*exp(im*arccos(a*x)))+(1/2)*d^-1//2*(-1c)^-1//2*arccos(a*x)*log(1+-1*d^(1/2)*(im*(d+c*a^2)^(1/2)+a*(-1c)^(1/2))^-1*exp(im*arccos(a*x)))+(1/2)*d^-1//2*(-1c)^-1//2*arccos(a*x)*log(1+-1*d^(1/2)*(a*(-1c)^(1/2)+-1*im*(d+c*a^2)^(1/2))^-1*exp(im*arccos(a*x)))+-1//2*im*d^-1//2*(-1c)^-1//2*Polylogarithms.polylog(2,d^(1/2)*(im*(d+c*a^2)^(1/2)+a*(-1c)^(1/2))^-1*exp(im*arccos(a*x)))+-1//2*im*d^-1//2*(-1c)^-1//2*Polylogarithms.polylog(2,d^(1/2)*(a*(-1c)^(1/2)+-1*im*(d+c*a^2)^(1/2))^-1*exp(im*arccos(a*x)))+-1//2*d^-1//2*(-1c)^-1//2*arccos(a*x)*log(1+d^(1/2)*(im*(d+c*a^2)^(1/2)+a*(-1c)^(1/2))^-1*exp(im*arccos(a*x)))+-1//2*d^-1//2*(-1c)^-1//2*arccos(a*x)*log(1+d^(1/2)*(a*(-1c)^(1/2)+-1*im*(d+c*a^2)^(1/2))^-1*exp(im*arccos(a*x))))
@test integrate((c+d*x^2)^-2*arccos(a*x), x) == :(-1//4*im*d^-1//2*(-1c)^-3//2*Polylogarithms.polylog(2,-1*d^(1/2)*(im*(d+c*a^2)^(1/2)+a*(-1c)^(1/2))^-1*exp(im*arccos(a*x)))+-1//4*im*d^-1//2*(-1c)^-3//2*Polylogarithms.polylog(2,-1*d^(1/2)*(a*(-1c)^(1/2)+-1*im*(d+c*a^2)^(1/2))^-1*exp(im*arccos(a*x)))+-1//4*c^-1*d^-1//2*((-1c)^(1/2)+-1*x*d^(1/2))^-1*arccos(a*x)+-1//4*d^-1//2*(-1c)^-3//2*arccos(a*x)*log(1+-1*d^(1/2)*(im*(d+c*a^2)^(1/2)+a*(-1c)^(1/2))^-1*exp(im*arccos(a*x)))+-1//4*d^-1//2*(-1c)^-3//2*arccos(a*x)*log(1+-1*d^(1/2)*(a*(-1c)^(1/2)+-1*im*(d+c*a^2)^(1/2))^-1*exp(im*arccos(a*x)))+1//4*im*d^-1//2*(-1c)^-3//2*Polylogarithms.polylog(2,d^(1/2)*(im*(d+c*a^2)^(1/2)+a*(-1c)^(1/2))^-1*exp(im*arccos(a*x)))+1//4*im*d^-1//2*(-1c)^-3//2*Polylogarithms.polylog(2,d^(1/2)*(a*(-1c)^(1/2)+-1*im*(d+c*a^2)^(1/2))^-1*exp(im*arccos(a*x)))+1//4*c^-1*d^-1//2*((-1c)^(1/2)+x*d^(1/2))^-1*arccos(a*x)+1//4*d^-1//2*(-1c)^-3//2*arccos(a*x)*log(1+d^(1/2)*(im*(d+c*a^2)^(1/2)+a*(-1c)^(1/2))^-1*exp(im*arccos(a*x)))+1//4*d^-1//2*(-1c)^-3//2*arccos(a*x)*log(1+d^(1/2)*(a*(-1c)^(1/2)+-1*im*(d+c*a^2)^(1/2))^-1*exp(im*arccos(a*x)))+-1//4*a*c^-1*d^-1//2*(d+c*a^2)^-1//2*arctanh((1+-1*a^2*x^2)^-1//2*(d+c*a^2)^-1//2*(d^(1/2)+x*a^2*(-1c)^(1/2)))+-1//4*a*c^-1*d^-1//2*(d+c*a^2)^-1//2*arctanh((1+-1*a^2*x^2)^-1//2*(d+c*a^2)^-1//2*(d^(1/2)+-1*x*a^2*(-1c)^(1/2))))
@test integrate((c+d*x^2)^-3//2*arccos(a*x), x) == :(-1*c^-1*d^-1//2*arctan(a^-1*d^(1/2)*(1+-1*a^2*x^2)^(1/2)*(c+d*x^2)^-1//2)+x*c^-1*(c+d*x^2)^-1//2*arccos(a*x))
@test integrate((c+d*x^2)^-5//2*arccos(a*x), x) == :(-2//3*c^-2*d^-1//2*arctan(a^-1*d^(1/2)*(1+-1*a^2*x^2)^(1/2)*(c+d*x^2)^-1//2)+1//3*x*c^-1*(c+d*x^2)^-3//2*arccos(a*x)+2//3*x*c^-2*(c+d*x^2)^-1//2*arccos(a*x)+-1//3*a*c^-1*(1+-1*a^2*x^2)^(1/2)*(c+d*x^2)^-1//2*(d+c*a^2)^-1)
@test integrate((c+d*x^2)^-7//2*arccos(a*x), x) == :(-8//15*c^-3*d^-1//2*arctan(a^-1*d^(1/2)*(1+-1*a^2*x^2)^(1/2)*(c+d*x^2)^-1//2)+1//5*x*c^-1*(c+d*x^2)^-5//2*arccos(a*x)+4//15*x*c^-2*(c+d*x^2)^-3//2*arccos(a*x)+8//15*x*c^-3*(c+d*x^2)^-1//2*arccos(a*x)+-1//15*a*c^-1*(1+-1*a^2*x^2)^(1/2)*(c+d*x^2)^-3//2*(d+c*a^2)^-1+-2//15*a*c^-2*(1+-1*a^2*x^2)^(1/2)*(c+d*x^2)^-1//2*(d+c*a^2)^-2*(2d+3*c*a^2))
@test integrate(x^3*arccos(a+b*x), x) == :(1//4*x^4*arccos(a+b*x)+-1//16*b^-1*x^3*(1+-1*(a+b*x)^2)^(1/2)+1//32*b^-4*(3+8*a^4+24*a^2)*arcsin(a+b*x)+1//96*b^-4*(1+-1*(a+b*x)^2)^(1/2)*(-1*(9+26*a^2)*(a+b*x)+4*a*(16+19*a^2))+7//48*a*b^-2*x^2*(1+-1*(a+b*x)^2)^(1/2))
@test integrate(x^2*arccos(a+b*x), x) == :(1//3*x^3*arccos(a+b*x)+-1//9*b^-1*x^2*(1+-1*(a+b*x)^2)^(1/2)+-1//18*b^-3*(1+-1*(a+b*x)^2)^(1/2)*(4+11*a^2+-5*a*b*x)+-1//6*a*b^-3*(3+2*a^2)*arcsin(a+b*x))
@test integrate(x*arccos(a+b*x), x) == :((1/2)*x^2*arccos(a+b*x)+-1//4*x*b^-1*(1+-1*(a+b*x)^2)^(1/2)+1//4*b^-2*(1+2*a^2)*arcsin(a+b*x)+3//4*a*b^-2*(1+-1*(a+b*x)^2)^(1/2))
@test integrate(arccos(a+b*x), x) == :(-1*b^-1*(1+-1*(a+b*x)^2)^(1/2)+b^-1*(a+b*x)*arccos(a+b*x))
@test integrate(x^-1*arccos(a+b*x), x) == :(arccos(a+b*x)*log(1+-1*(a+im*(1+-1*a^2)^(1/2))^-1*exp(im*arccos(a+b*x)))+arccos(a+b*x)*log(1+-1*(a+-1*im*(1+-1*a^2)^(1/2))^-1*exp(im*arccos(a+b*x)))+-1*im*Polylogarithms.polylog(2,(a+im*(1+-1*a^2)^(1/2))^-1*exp(im*arccos(a+b*x)))+-1*im*Polylogarithms.polylog(2,(a+-1*im*(1+-1*a^2)^(1/2))^-1*exp(im*arccos(a+b*x)))+-1//2*im*arccos(a+b*x)^2)
@test integrate(x^-2*arccos(a+b*x), x) == :(-1*x^-1*arccos(a+b*x)+b*(1+-1*a^2)^-1//2*arctanh((1+-1*a^2)^-1//2*(1+-1*(a+b*x)^2)^-1//2*(1+-1*a*(a+b*x))))
@test integrate(x^-3*arccos(a+b*x), x) == :(-1//2*x^-2*arccos(a+b*x)+b*x^-1*(1+-1*(a+b*x)^2)^(1/2)*(2+-2*a^2)^-1+(1/2)*a*b^2*(1+-1*a^2)^-3//2*arctanh((1+-1*a^2)^-1//2*(1+-1*(a+b*x)^2)^-1//2*(1+-1*a*(a+b*x))))
@test integrate(x^-4*arccos(a+b*x), x) == :(-1//3*x^-3*arccos(a+b*x)+b*x^-2*(1+-1*(a+b*x)^2)^(1/2)*(6+-6*a^2)^-1+1//6*b^3*(1+-1*a^2)^-5//2*(1+2*a^2)*arctanh((1+-1*a^2)^-1//2*(1+-1*(a+b*x)^2)^-1//2*(1+-1*a*(a+b*x)))+(1/2)*a*b^2*x^-1*(1+-1*a^2)^-2*(1+-1*(a+b*x)^2)^(1/2))
@test integrate(arccos(a+b*x)^3, x) == :(6*b^-1*(1+-1*(a+b*x)^2)^(1/2)+b^-1*arccos(a+b*x)^3*(a+b*x)+-1*b^-1*(6a+6*b*x)*arccos(a+b*x)+-3*b^-1*(1+-1*(a+b*x)^2)^(1/2)*arccos(a+b*x)^2)
@test integrate(arccos(a+b*x)^2, x) == :(-2x+b^-1*arccos(a+b*x)^2*(a+b*x)+-2*b^-1*(1+-1*(a+b*x)^2)^(1/2)*arccos(a+b*x))
@test integrate(arccos(a+b*x)^-1, x) == :(-1*b^-1*sinintegral(arccos(a+b*x)))
@test integrate(arccos(a+b*x)^-2, x) == :(-1*b^-1*cosintegral(arccos(a+b*x))+b^-1*(1+-1*(a+b*x)^2)^(1/2)*arccos(a+b*x)^-1)
@test integrate(arccos(a+b*x)^-3, x) == :((1/2)*b^-1*sinintegral(arccos(a+b*x))+(1/2)*b^-1*(1+-1*(a+b*x)^2)^(1/2)*arccos(a+b*x)^-2+(1/2)*b^-1*arccos(a+b*x)^-1*(a+b*x))
@test integrate(arccos(a+b*x)^5//2, x) == :(b^-1*arccos(a+b*x)^5//2*(a+b*x)+-5//2*b^-1*(1+-1*(a+b*x)^2)^(1/2)*arccos(a+b*x)^3//2+-1//4*b^-1*arccos(a+b*x)^(1/2)*(15a+15*b*x)+15//8*2^(1/2)*pi^(1/2)*b^-1*fresnelc(2^(1/2)*pi^-1//2*arccos(a+b*x)^(1/2)))
@test integrate(arccos(a+b*x)^3//2, x) == :(b^-1*arccos(a+b*x)^3//2*(a+b*x)+-3//2*b^-1*(1+-1*(a+b*x)^2)^(1/2)*arccos(a+b*x)^(1/2)+3//4*2^(1/2)*pi^(1/2)*b^-1*fresnels(2^(1/2)*pi^-1//2*arccos(a+b*x)^(1/2)))
@test integrate(arccos(a+b*x)^(1/2), x) == :(b^-1*arccos(a+b*x)^(1/2)*(a+b*x)+-1//2*2^(1/2)*pi^(1/2)*b^-1*fresnelc(2^(1/2)*pi^-1//2*arccos(a+b*x)^(1/2)))
@test integrate(arccos(a+b*x)^-1//2, x) == :(-1*2^(1/2)*pi^(1/2)*b^-1*fresnels(2^(1/2)*pi^-1//2*arccos(a+b*x)^(1/2)))
@test integrate(arccos(a+b*x)^-3//2, x) == :(2*b^-1*(1+-1*(a+b*x)^2)^(1/2)*arccos(a+b*x)^-1//2+-2*2^(1/2)*pi^(1/2)*b^-1*fresnelc(2^(1/2)*pi^-1//2*arccos(a+b*x)^(1/2)))
@test integrate(arccos(a+b*x)^-5//2, x) == :(1//3*b^-1*arccos(a+b*x)^-1//2*(4a+4*b*x)+2//3*b^-1*(1+-1*(a+b*x)^2)^(1/2)*arccos(a+b*x)^-3//2+4//3*2^(1/2)*pi^(1/2)*b^-1*fresnels(2^(1/2)*pi^-1//2*arccos(a+b*x)^(1/2)))
@test integrate((a+b*arccos(c+d*x))^-1//2, x) == :(2^(1/2)*pi^(1/2)*b^-1//2*d^-1*fresnelc(2^(1/2)*pi^-1//2*b^-1//2*(a+b*arccos(c+d*x))^(1/2))*sin(a*b^-1)+-1*2^(1/2)*pi^(1/2)*b^-1//2*d^-1*cos(a*b^-1)*fresnels(2^(1/2)*pi^-1//2*b^-1//2*(a+b*arccos(c+d*x))^(1/2)))
@test integrate((a+-1*b*arccos(c+d*x))^-1//2, x) == :(2^(1/2)*pi^(1/2)*b^-1//2*d^-1*fresnelc(2^(1/2)*pi^-1//2*b^-1//2*(a+-1*b*arccos(c+d*x))^(1/2))*sin(a*b^-1)+-1*2^(1/2)*pi^(1/2)*b^-1//2*d^-1*cos(a*b^-1)*fresnels(2^(1/2)*pi^-1//2*b^-1//2*(a+-1*b*arccos(c+d*x))^(1/2)))
@test integrate((d*x+a*d*b^-1)^-1*arccos(a+b*x), x) == :(d^-1*arccos(a+b*x)*log(1+exp(2*im*arccos(a+b*x)))+-1//2*im*d^-1*arccos(a+b*x)^2+-1//2*im*d^-1*Polylogarithms.polylog(2,-1*exp(2*im*arccos(a+b*x))))
@test integrate((1+-1*x^2)^(1/2)*arccos(x), x) == :(-1//4*arccos(x)^2+1//4*x^2+(1/2)*x*(1+-1*x^2)^(1/2)*arccos(x))
@test integrate(x^3*arccos(a*x^2), x) == :(1//4*x^4*arccos(a*x^2)+1//8*a^-2*arcsin(a*x^2)+-1//8*a^-1*x^2*(1+-1*a^2*x^4)^(1/2))
@test integrate(x^2*arccos(a*x^2), x) == :(1//3*x^3*arccos(a*x^2)+2//9*a^-3//2*Elliptic.F(arcsin(x*a^(1/2)),-1)+-2//9*x*a^-1*(1+-1*a^2*x^4)^(1/2))
@test integrate(x*arccos(a*x^2), x) == :((1/2)*x^2*arccos(a*x^2)+-1//2*a^-1*(1+-1*a^2*x^4)^(1/2))
@test integrate(arccos(a*x^2), x) == :(x*arccos(a*x^2)+-2*a^-1//2*Elliptic.F(arcsin(x*a^(1/2)),-1)+2*a^-1//2*Elliptic.E(arcsin(x*a^(1/2)),-1))
@test integrate(x^-1*arccos(a*x^2), x) == :((1/2)*arccos(a*x^2)*log(1+exp(2*im*arccos(a*x^2)))+-1//4*im*arccos(a*x^2)^2+-1//4*im*Polylogarithms.polylog(2,-1*exp(2*im*arccos(a*x^2))))
@test integrate(x^-2*arccos(a*x^2), x) == :(-1*x^-1*arccos(a*x^2)+-2*a^(1/2)*Elliptic.F(arcsin(x*a^(1/2)),-1))
@test integrate(x^2*arccos(a*x^-1), x) == :(-1//6*a^3*arctanh((1+-1*a^2*x^-2)^(1/2))+1//3*x^3*arcsec(x*a^-1)+-1//6*a*x^2*(1+-1*a^2*x^-2)^(1/2))
@test integrate(x*arccos(a*x^-1), x) == :((1/2)*x^2*arcsec(x*a^-1)+-1//2*a*x*(1+-1*a^2*x^-2)^(1/2))
@test integrate(arccos(a*x^-1), x) == :(x*arcsec(x*a^-1)+-1*a*arctanh((1+-1*a^2*x^-2)^(1/2)))
@test integrate(x^-1*arccos(a*x^-1), x) == :((1/2)*im*arccos(a*x^-1)^2+(1/2)*im*Polylogarithms.polylog(2,-1*exp(2*im*arccos(a*x^-1)))+-1*arccos(a*x^-1)*log(1+exp(2*im*arccos(a*x^-1))))
@test integrate(x^-2*arccos(a*x^-1), x) == :(a^-1*(1+-1*a^2*x^-2)^(1/2)+-1*x^-1*arcsec(x*a^-1))
@test integrate(x^-3*arccos(a*x^-1), x) == :(-1//2*x^-2*arcsec(x*a^-1)+-1//4*a^-2*arccsc(x*a^-1)+1//4*a^-1*x^-1*(1+-1*a^2*x^-2)^(1/2))
@test integrate(x^-4*arccos(a*x^-1), x) == :(-1//3*x^-3*arcsec(x*a^-1)+-1//9*a^-3*(1+-1*a^2*x^-2)^3//2+1//3*a^-3*(1+-1*a^2*x^-2)^(1/2))
@test integrate(x^2*arccos(x^(1/2)), x) == :(-5//96*arcsin(1+-2x)+-5//48*x^(1/2)*(1+-1x)^(1/2)+-5//72*x^3//2*(1+-1x)^(1/2)+-1//18*x^5//2*(1+-1x)^(1/2)+1//3*x^3*arccos(x^(1/2)))
@test integrate(x*arccos(x^(1/2)), x) == :(-3//32*arcsin(1+-2x)+(1/2)*x^2*arccos(x^(1/2))+-3//16*x^(1/2)*(1+-1x)^(1/2)+-1//8*x^3//2*(1+-1x)^(1/2))
@test integrate(arccos(x^(1/2)), x) == :(-1//4*arcsin(1+-2x)+x*arccos(x^(1/2))+-1//2*x^(1/2)*(1+-1x)^(1/2))
@test integrate(x^-1*arccos(x^(1/2)), x) == :(-1*im*arccos(x^(1/2))^2+-1*im*Polylogarithms.polylog(2,-1*exp(2*im*arccos(x^(1/2))))+2*arccos(x^(1/2))*log(1+exp(2*im*arccos(x^(1/2)))))
@test integrate(x^-2*arccos(x^(1/2)), x) == :(x^-1//2*(1+-1x)^(1/2)+-1*x^-1*arccos(x^(1/2)))
@test integrate(x^-3*arccos(x^(1/2)), x) == :(-1//2*x^-2*arccos(x^(1/2))+1//3*x^-1//2*(1+-1x)^(1/2)+1//6*x^-3//2*(1+-1x)^(1/2))
@test integrate(x^-4*arccos(x^(1/2)), x) == :(-1//3*x^-3*arccos(x^(1/2))+1//15*x^-5//2*(1+-1x)^(1/2)+4//45*x^-3//2*(1+-1x)^(1/2)+8//45*x^-1//2*(1+-1x)^(1/2))
@test integrate(x^-5*arccos(x^(1/2)), x) == :(-1//4*x^-4*arccos(x^(1/2))+1//28*x^-7//2*(1+-1x)^(1/2)+2//35*x^-3//2*(1+-1x)^(1/2)+3//70*x^-5//2*(1+-1x)^(1/2)+4//35*x^-1//2*(1+-1x)^(1/2))
@test integrate(x^-1//2*arccos(x^(1/2)), x) == :(-2*(1+-1x)^(1/2)+2*x^(1/2)*arccos(x^(1/2)))
@test integrate(x^-1*arccos(a*x^n), x) == :(n^-1*arccos(a*x^n)*log(1+exp(2*im*arccos(a*x^n)))+-1//2*im*n^-1*arccos(a*x^n)^2+-1//2*im*n^-1*Polylogarithms.polylog(2,-1*exp(2*im*arccos(a*x^n))))
@test integrate(x^-1*arccos(a*x^5), x) == :(-1//10*im*arccos(a*x^5)^2+-1//10*im*Polylogarithms.polylog(2,-1*exp(2*im*arccos(a*x^5)))+1//5*arccos(a*x^5)*log(1+exp(2*im*arccos(a*x^5))))
@test integrate(x^3*arccos(a+b*x^4), x) == :(-1//4*b^-1*(1+-1*(a+b*x^4)^2)^(1/2)+1//4*b^-1*(a+b*x^4)*arccos(a+b*x^4))
@test integrate(x^(-1+n)*arccos(a+b*x^n), x) == :(-1*b^-1*n^-1*(1+-1*(a+b*x^n)^2)^(1/2)+b^-1*n^-1*(a+b*x^n)*arccos(a+b*x^n))
@test integrate((a+b*arccos(1+d*x^2))^4, x) == :(x*(a+b*arccos(1+d*x^2))^4+384*x*b^4+-48*x*b^2*(a+b*arccos(1+d*x^2))^2+-8*b*d^-1*x^-1*(a+b*arccos(1+d*x^2))^3*(-1*d^2*x^4+-2*d*x^2)^(1/2)+192*b^3*d^-1*x^-1*(-1*d^2*x^4+-2*d*x^2)^(1/2)*(a+b*arccos(1+d*x^2)))
@test integrate((a+b*arccos(1+d*x^2))^3, x) == :(x*(a+b*arccos(1+d*x^2))^3+-24*a*x*b^2+-24*x*b^3*arccos(1+d*x^2)+48*b^3*d^-1*x^-1*(-1*d^2*x^4+-2*d*x^2)^(1/2)+-6*b*d^-1*x^-1*(a+b*arccos(1+d*x^2))^2*(-1*d^2*x^4+-2*d*x^2)^(1/2))
@test integrate((a+b*arccos(1+d*x^2))^2, x) == :(x*(a+b*arccos(1+d*x^2))^2+-8*x*b^2+-4*b*d^-1*x^-1*(-1*d^2*x^4+-2*d*x^2)^(1/2)*(a+b*arccos(1+d*x^2)))
@test integrate(a+b*arccos(1+d*x^2), x) == :(a*x+b*x*arccos(1+d*x^2)+-2*b*d^-1*x^-1*(-1*d^2*x^4+-2*d*x^2)^(1/2))
@test integrate((a+b*arccos(1+d*x^2))^-1, x) == :((1/2)*x*2^(1/2)*b^-1*(-1*d*x^2)^-1//2*cos((1/2)*a*b^-1)*cosintegral((1/2)*b^-1*(a+b*arccos(1+d*x^2)))+(1/2)*x*2^(1/2)*b^-1*(-1*d*x^2)^-1//2*sin((1/2)*a*b^-1)*sinintegral((1/2)*b^-1*(a+b*arccos(1+d*x^2))))
@test integrate((a+b*arccos(1+d*x^2))^-2, x) == :((1/2)*b^-1*d^-1*x^-1*(a+b*arccos(1+d*x^2))^-1*(-1*d^2*x^4+-2*d*x^2)^(1/2)+-1//4*x*2^(1/2)*b^-2*(-1*d*x^2)^-1//2*cos((1/2)*a*b^-1)*sinintegral((1/2)*b^-1*(a+b*arccos(1+d*x^2)))+1//4*x*2^(1/2)*b^-2*(-1*d*x^2)^-1//2*cosintegral((1/2)*b^-1*(a+b*arccos(1+d*x^2)))*sin((1/2)*a*b^-1))
@test integrate((a+b*arccos(1+d*x^2))^-3, x) == :(1//8*x*b^-2*(a+b*arccos(1+d*x^2))^-1+1//4*b^-1*d^-1*x^-1*(a+b*arccos(1+d*x^2))^-2*(-1*d^2*x^4+-2*d*x^2)^(1/2)+-1//16*x*2^(1/2)*b^-3*(-1*d*x^2)^-1//2*cos((1/2)*a*b^-1)*cosintegral((1/2)*b^-1*(a+b*arccos(1+d*x^2)))+-1//16*x*2^(1/2)*b^-3*(-1*d*x^2)^-1//2*sin((1/2)*a*b^-1)*sinintegral((1/2)*b^-1*(a+b*arccos(1+d*x^2))))
@test integrate((a+b*arccos(-1+d*x^2))^4, x) == :(x*(a+b*arccos(-1+d*x^2))^4+384*x*b^4+-48*x*b^2*(a+b*arccos(-1+d*x^2))^2+-8*b*d^-1*x^-1*(a+b*arccos(-1+d*x^2))^3*(-1*d^2*x^4+2*d*x^2)^(1/2)+192*b^3*d^-1*x^-1*(-1*d^2*x^4+2*d*x^2)^(1/2)*(a+b*arccos(-1+d*x^2)))
@test integrate((a+b*arccos(-1+d*x^2))^3, x) == :(x*(a+b*arccos(-1+d*x^2))^3+-24*a*x*b^2+-24*x*b^3*arccos(-1+d*x^2)+48*b^3*d^-1*x^-1*(-1*d^2*x^4+2*d*x^2)^(1/2)+-6*b*d^-1*x^-1*(a+b*arccos(-1+d*x^2))^2*(-1*d^2*x^4+2*d*x^2)^(1/2))
@test integrate((a+b*arccos(-1+d*x^2))^2, x) == :(x*(a+b*arccos(-1+d*x^2))^2+-8*x*b^2+-4*b*d^-1*x^-1*(-1*d^2*x^4+2*d*x^2)^(1/2)*(a+b*arccos(-1+d*x^2)))
@test integrate(a+b*arccos(-1+d*x^2), x) == :(a*x+b*x*arccos(-1+d*x^2)+-2*b*d^-1*x^-1*(-1*d^2*x^4+2*d*x^2)^(1/2))
@test integrate((a+b*arccos(-1+d*x^2))^-1, x) == :((1/2)*x*2^(1/2)*b^-1*(d*x^2)^-1//2*cosintegral((1/2)*b^-1*(a+b*arccos(-1+d*x^2)))*sin((1/2)*a*b^-1)+-1//2*x*2^(1/2)*b^-1*(d*x^2)^-1//2*cos((1/2)*a*b^-1)*sinintegral((1/2)*b^-1*(a+b*arccos(-1+d*x^2))))
@test integrate((a+b*arccos(-1+d*x^2))^-2, x) == :((1/2)*b^-1*d^-1*x^-1*(a+b*arccos(-1+d*x^2))^-1*(-1*d^2*x^4+2*d*x^2)^(1/2)+-1//4*x*2^(1/2)*b^-2*(d*x^2)^-1//2*cos((1/2)*a*b^-1)*cosintegral((1/2)*b^-1*(a+b*arccos(-1+d*x^2)))+-1//4*x*2^(1/2)*b^-2*(d*x^2)^-1//2*sin((1/2)*a*b^-1)*sinintegral((1/2)*b^-1*(a+b*arccos(-1+d*x^2))))
@test integrate((a+b*arccos(-1+d*x^2))^-3, x) == :(1//8*x*b^-2*(a+b*arccos(-1+d*x^2))^-1+1//4*b^-1*d^-1*x^-1*(a+b*arccos(-1+d*x^2))^-2*(-1*d^2*x^4+2*d*x^2)^(1/2)+-1//16*x*2^(1/2)*b^-3*(d*x^2)^-1//2*cosintegral((1/2)*b^-1*(a+b*arccos(-1+d*x^2)))*sin((1/2)*a*b^-1)+1//16*x*2^(1/2)*b^-3*(d*x^2)^-1//2*cos((1/2)*a*b^-1)*sinintegral((1/2)*b^-1*(a+b*arccos(-1+d*x^2))))
@test integrate((a+b*arccos(1+d*x^2))^5//2, x) == :(x*(a+b*arccos(1+d*x^2))^5//2+-5*b*d^-1*x^-1*(a+b*arccos(1+d*x^2))^3//2*(-1*d^2*x^4+-2*d*x^2)^(1/2)+30*b^2*d^-1*x^-1*(a+b*arccos(1+d*x^2))^(1/2)*sin((1/2)*arccos(1+d*x^2))^2+-30*pi^(1/2)*d^-1*x^-1*(b^-1)^-5//2*cos((1/2)*a*b^-1)*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2))+30*pi^(1/2)*d^-1*x^-1*(b^-1)^-5//2*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2))*sin((1/2)*a*b^-1))
@test integrate((a+b*arccos(1+d*x^2))^3//2, x) == :(x*(a+b*arccos(1+d*x^2))^3//2+-3*b*d^-1*x^-1*(a+b*arccos(1+d*x^2))^(1/2)*(-1*d^2*x^4+-2*d*x^2)^(1/2)+6*pi^(1/2)*d^-1*x^-1*(b^-1)^-3//2*cos((1/2)*a*b^-1)*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2))+6*pi^(1/2)*d^-1*x^-1*(b^-1)^-3//2*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2))*sin((1/2)*a*b^-1))
@test integrate((a+b*arccos(1+d*x^2))^(1/2), x) == :(-2*d^-1*x^-1*(a+b*arccos(1+d*x^2))^(1/2)*sin((1/2)*arccos(1+d*x^2))^2+-2*pi^(1/2)*d^-1*x^-1*(b^-1)^-1//2*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2))*sin((1/2)*a*b^-1)+2*pi^(1/2)*d^-1*x^-1*(b^-1)^-1//2*cos((1/2)*a*b^-1)*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2)))
@test integrate((a+b*arccos(1+d*x^2))^-1//2, x) == :(-2*pi^(1/2)*d^-1*x^-1*(b^-1)^(1/2)*cos((1/2)*a*b^-1)*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2))+-2*pi^(1/2)*d^-1*x^-1*(b^-1)^(1/2)*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2))*sin((1/2)*a*b^-1))
@test integrate((a+b*arccos(1+d*x^2))^-3//2, x) == :(b^-1*d^-1*x^-1*(a+b*arccos(1+d*x^2))^-1//2*(-1*d^2*x^4+-2*d*x^2)^(1/2)+-2*pi^(1/2)*d^-1*x^-1*(b^-1)^3//2*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2))*sin((1/2)*a*b^-1)+2*pi^(1/2)*d^-1*x^-1*(b^-1)^3//2*cos((1/2)*a*b^-1)*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2)))
@test integrate((a+b*arccos(1+d*x^2))^-5//2, x) == :(1//3*x*b^-2*(a+b*arccos(1+d*x^2))^-1//2+1//3*b^-1*d^-1*x^-1*(a+b*arccos(1+d*x^2))^-3//2*(-1*d^2*x^4+-2*d*x^2)^(1/2)+2//3*pi^(1/2)*d^-1*x^-1*(b^-1)^5//2*cos((1/2)*a*b^-1)*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2))+2//3*pi^(1/2)*d^-1*x^-1*(b^-1)^5//2*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2))*sin((1/2)*a*b^-1))
@test integrate((a+b*arccos(1+d*x^2))^-7//2, x) == :(1//15*x*b^-2*(a+b*arccos(1+d*x^2))^-3//2+-1//15*b^-3*d^-1*x^-1*(a+b*arccos(1+d*x^2))^-1//2*(-1*d^2*x^4+-2*d*x^2)^(1/2)+1//5*b^-1*d^-1*x^-1*(a+b*arccos(1+d*x^2))^-5//2*(-1*d^2*x^4+-2*d*x^2)^(1/2)+-2//15*pi^(1/2)*d^-1*x^-1*(b^-1)^7//2*cos((1/2)*a*b^-1)*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2))+2//15*pi^(1/2)*d^-1*x^-1*(b^-1)^7//2*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(1+d*x^2))^(1/2))*sin((1/2)*arccos(1+d*x^2))*sin((1/2)*a*b^-1))
@test integrate((a+b*arccos(-1+d*x^2))^5//2, x) == :(x*(a+b*arccos(-1+d*x^2))^5//2+-30*b^2*d^-1*x^-1*(a+b*arccos(-1+d*x^2))^(1/2)*cos((1/2)*arccos(-1+d*x^2))^2+-5*b*d^-1*x^-1*(a+b*arccos(-1+d*x^2))^3//2*(-1*d^2*x^4+2*d*x^2)^(1/2)+30*pi^(1/2)*d^-1*x^-1*(b^-1)^-5//2*cos((1/2)*arccos(-1+d*x^2))*cos((1/2)*a*b^-1)*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2))+30*pi^(1/2)*d^-1*x^-1*(b^-1)^-5//2*cos((1/2)*arccos(-1+d*x^2))*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2))*sin((1/2)*a*b^-1))
@test integrate((a+b*arccos(-1+d*x^2))^3//2, x) == :(x*(a+b*arccos(-1+d*x^2))^3//2+-3*b*d^-1*x^-1*(a+b*arccos(-1+d*x^2))^(1/2)*(-1*d^2*x^4+2*d*x^2)^(1/2)+-6*pi^(1/2)*d^-1*x^-1*(b^-1)^-3//2*cos((1/2)*arccos(-1+d*x^2))*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2))*sin((1/2)*a*b^-1)+6*pi^(1/2)*d^-1*x^-1*(b^-1)^-3//2*cos((1/2)*arccos(-1+d*x^2))*cos((1/2)*a*b^-1)*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2)))
@test integrate((a+b*arccos(-1+d*x^2))^(1/2), x) == :(2*d^-1*x^-1*(a+b*arccos(-1+d*x^2))^(1/2)*cos((1/2)*arccos(-1+d*x^2))^2+-2*pi^(1/2)*d^-1*x^-1*(b^-1)^-1//2*cos((1/2)*arccos(-1+d*x^2))*cos((1/2)*a*b^-1)*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2))+-2*pi^(1/2)*d^-1*x^-1*(b^-1)^-1//2*cos((1/2)*arccos(-1+d*x^2))*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2))*sin((1/2)*a*b^-1))
@test integrate((a+b*arccos(-1+d*x^2))^-1//2, x) == :(-2*pi^(1/2)*d^-1*x^-1*(b^-1)^(1/2)*cos((1/2)*arccos(-1+d*x^2))*cos((1/2)*a*b^-1)*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2))+2*pi^(1/2)*d^-1*x^-1*(b^-1)^(1/2)*cos((1/2)*arccos(-1+d*x^2))*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2))*sin((1/2)*a*b^-1))
@test integrate((a+b*arccos(-1+d*x^2))^-3//2, x) == :(b^-1*d^-1*x^-1*(a+b*arccos(-1+d*x^2))^-1//2*(-1*d^2*x^4+2*d*x^2)^(1/2)+-2*pi^(1/2)*d^-1*x^-1*(b^-1)^3//2*cos((1/2)*arccos(-1+d*x^2))*cos((1/2)*a*b^-1)*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2))+-2*pi^(1/2)*d^-1*x^-1*(b^-1)^3//2*cos((1/2)*arccos(-1+d*x^2))*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2))*sin((1/2)*a*b^-1))
@test integrate((a+b*arccos(-1+d*x^2))^-5//2, x) == :(1//3*x*b^-2*(a+b*arccos(-1+d*x^2))^-1//2+1//3*b^-1*d^-1*x^-1*(a+b*arccos(-1+d*x^2))^-3//2*(-1*d^2*x^4+2*d*x^2)^(1/2)+-2//3*pi^(1/2)*d^-1*x^-1*(b^-1)^5//2*cos((1/2)*arccos(-1+d*x^2))*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2))*sin((1/2)*a*b^-1)+2//3*pi^(1/2)*d^-1*x^-1*(b^-1)^5//2*cos((1/2)*arccos(-1+d*x^2))*cos((1/2)*a*b^-1)*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2)))
@test integrate((a+b*arccos(-1+d*x^2))^-7//2, x) == :(1//15*x*b^-2*(a+b*arccos(-1+d*x^2))^-3//2+-1//15*b^-3*d^-1*x^-1*(a+b*arccos(-1+d*x^2))^-1//2*(-1*d^2*x^4+2*d*x^2)^(1/2)+1//5*b^-1*d^-1*x^-1*(a+b*arccos(-1+d*x^2))^-5//2*(-1*d^2*x^4+2*d*x^2)^(1/2)+2//15*pi^(1/2)*d^-1*x^-1*(b^-1)^7//2*cos((1/2)*arccos(-1+d*x^2))*cos((1/2)*a*b^-1)*fresnelc(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2))+2//15*pi^(1/2)*d^-1*x^-1*(b^-1)^7//2*cos((1/2)*arccos(-1+d*x^2))*fresnels(pi^-1//2*(b^-1)^(1/2)*(a+b*arccos(-1+d*x^2))^(1/2))*sin((1/2)*a*b^-1))
@test integrate((1+-1*c^2*x^2)^-1*(a+b*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))^3, x) == :(-1*c^-1*(a+b*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))^3*log(1+exp(2*im*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2))))+-3//2*b^2*c^-1*(a+b*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))*Polylogarithms.polylog(3,-1*exp(2*im*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2))))+-3//4*im*b^3*c^-1*Polylogarithms.polylog(4,-1*exp(2*im*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2))))+1//4*im*b^-1*c^-1*(a+b*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))^4+3//2*im*b*c^-1*(a+b*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))^2*Polylogarithms.polylog(2,-1*exp(2*im*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))))
@test integrate((1+-1*c^2*x^2)^-1*(a+b*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))^2, x) == :(-1*c^-1*(a+b*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))^2*log(1+exp(2*im*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2))))+-1//2*b^2*c^-1*Polylogarithms.polylog(3,-1*exp(2*im*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2))))+1//3*im*b^-1*c^-1*(a+b*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))^3+im*b*c^-1*(a+b*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))*Polylogarithms.polylog(2,-1*exp(2*im*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))))
@test integrate((1+-1*c^2*x^2)^-1*(a+b*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2))), x) == :(-1*c^-1*(a+b*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))*log(1+exp(2*im*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2))))+(1/2)*im*b*c^-1*Polylogarithms.polylog(2,-1*exp(2*im*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2))))+(1/2)*im*b^-1*c^-1*(a+b*arccos((1+c*x)^-1//2*(1+-1*c*x)^(1/2)))^2)
@test integrate(arccos(c*exp(a+b*x)), x) == :(b^-1*arccos(c*exp(a+b*x))*log(1+exp(2*im*arccos(c*exp(a+b*x))))+-1//2*im*b^-1*arccos(c*exp(a+b*x))^2+-1//2*im*b^-1*Polylogarithms.polylog(2,-1*exp(2*im*arccos(c*exp(a+b*x)))))
@test integrate(x^3*exp(arccos(a*x)), x) == :(-1//20*a^-4*exp(arccos(a*x))*sin(2*arccos(a*x))+-1//136*a^-4*exp(arccos(a*x))*sin(4*arccos(a*x))+1//10*a^-4*cos(2*arccos(a*x))*exp(arccos(a*x))+1//34*a^-4*cos(4*arccos(a*x))*exp(arccos(a*x)))
@test integrate(x^2*exp(arccos(a*x)), x) == :(-1//8*a^-3*(1+-1*a^2*x^2)^(1/2)*exp(arccos(a*x))+-1//40*a^-3*exp(arccos(a*x))*sin(3*arccos(a*x))+1//8*x*a^-2*exp(arccos(a*x))+3//40*a^-3*cos(3*arccos(a*x))*exp(arccos(a*x)))
@test integrate(x*exp(arccos(a*x)), x) == :(-1//10*a^-2*exp(arccos(a*x))*sin(2*arccos(a*x))+1//5*a^-2*cos(2*arccos(a*x))*exp(arccos(a*x)))
@test integrate(exp(arccos(a*x)), x) == :((1/2)*x*exp(arccos(a*x))+-1//2*a^-1*(1+-1*a^2*x^2)^(1/2)*exp(arccos(a*x)))
@test integrate(arccos(c*(a+b*x)^-1), x) == :(b^-1*(a+b*x)*arcsec(a*c^-1+b*x*c^-1)+-1*c*b^-1*arctanh((1+-1*c^2*(a+b*x)^-2)^(1/2)))
@test integrate(x*(1+-1*x^2)^-1//2*arccos(x)^-1//2, x) == :(-1*2^(1/2)*pi^(1/2)*fresnelc(2^(1/2)*pi^-1//2*arccos(x)^(1/2)))
@test integrate(x*(1+-1*x^2)^-1//2*arccos(x)^-1, x) == :(-1*cosintegral(arccos(x)))
@test integrate((1+b*x^2)^-1//2*arccos((1+b*x^2)^(1/2))^n, x) == :(-1*b^-1*x^-1*(-1*b*x^2)^(1/2)*(1+n)^-1*arccos((1+b*x^2)^(1/2))^(1+n))
@test integrate((1+b*x^2)^-1//2*arccos((1+b*x^2)^(1/2))^-1, x) == :(-1*b^-1*x^-1*(-1*b*x^2)^(1/2)*log(arccos((1+b*x^2)^(1/2))))

max_stars_repo_path: test/5 Inverse trig functions/5.2 Inverse cosine/5.2.5 Inverse cosine functions.jl


text:
using Interpolations
using Plots
pyplot()

f(x) = 2 .* cos(6x) .+ sin(14x) .+ 2.5
c_grid = 0:.2:1
n = length(c_grid)

Af = interpolate((c_grid, ), f(c_grid), Gridded(Linear()))

f_grid = linspace(0, 1, 150)

plot(f_grid, f, color=:blue, linewidth=2, alpha=0.8, label="true function")
plot!(f_grid, Af[f_grid], color=:green, linewidth=2, alpha=0.8,
      label="linear approximation", legend=:top, grid=false)
N = repmat(c_grid, 1, 2)'
heights = [zeros(1,n); f(c_grid)']
plot!(N, heights, color=:black, linestyle=:dash, alpha=0.5, label="")

ext: jl

max_stars_repo_name: mwhchen/quantecon

max_issues_repo_name: mwhchen/quantecon

max_forks_repo_name: mwhchen/quantecon


text:
# Common stuff

## convenient types and type conversion functions

const GChars          = Union{Cchar, Char}
const IVec            = Vector{Cint}
const FVec            = Vector{Float64}
const CVec            = Vector{Cchar}

const GCharOrVec      = Union{Cchar, Char, Vector{Cchar}, Vector{Char}}

const Bounds{T<:Real} = Union{T, Vector{T}}
const CoeffMat        = Union{Matrix{Float64}, SparseMatrixCSC{Float64}}

cchar(c::Cchar) = c
cchar(c::Char) = convert(Cchar, c)

ivec(v::IVec) = v
fvec(v::FVec) = v
cvec(v::CVec) = v

ivec(v::AbstractVector) = convert(IVec, v)
fvec(v::AbstractVector) = convert(FVec, v)
cvec(v::AbstractVector) = convert(CVec, v)

ivec(s::Integer) = Cint[s]

# cvecx(v, n) and fvecx(v, n)
# converts v into a vector of Cchar or Float64 of length n,
# where v can be either a scalar or a vector of length n.

_chklen(v, n::Integer) = (length(v) == n || error("Inconsistent argument dimensions."))

cvecx(c::GChars, n::Integer) = fill(cchar(c), n)
cvecx(c::Vector{Cchar}, n::Integer) = (_chklen(c, n); c)
cvecx(c::Vector{Char}, n::Integer) = (_chklen(c, n); convert(Vector{Cchar}, c))

fvecx(v::Real, n::Integer) = fill(Float64(v), n)
fvecx(v::Vector{Float64}, n::Integer) = (_chklen(v, n); v)
fvecx(v::Vector{T}, n::Integer) where {T<:Real} = (_chklen(v, n); convert(Vector{Float64}, v))

# empty vector & matrix (for the purpose of supplying default arguments)

const emptyfvec = Array{Float64}(undef, 0)
const emptyfmat = Array{Float64}(undef, 0, 0)

# macro to call a Gurobi C function
macro grb_ccall(func, args...)
    f = "GRB$(func)"
    args = map(esc,args)
    if Compat.Sys.isunix()
        return quote
            ccall(($f,libgurobi), $(args...))
        end
    elseif Compat.Sys.iswindows()
        return quote
            ccall(($f,libgurobi), $(esc(:stdcall)), $(args...))
        end
    end
    error("System not recognised.s")
end

# Gurobi library version
function getlibversion()
    _major = Cint[0]
    _minor = Cint[0]
    _tech = Cint[0]
    @grb_ccall(version, Nothing, (Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), _major, _minor, _tech)
    return VersionNumber(_major[1], _minor[1], _tech[1])
end

# version need not be export
# one can write Gurobi.version to get the version numbers
const version = getlibversion()

const GRB_INFINITY = 1e100
const GRB_BOUNDMAX = 1e30
function checkvalue(x::Real, bound)
    abs(x) > bound && abs(x) != Inf
end
checkvalue(x::Vector, bound) = any(checkvalue(c, bound) for c in x)

_objwarning(c) = Compat.@warn("Gurobi will silently silently truncate " *
    "objective coefficients >$(GRB_INFINITY) or <-$(GRB_INFINITY). Current " *
    "objective coefficient extrema: $(extrema(c))")

_boundwarning(lb, ub) = Compat.@warn("Gurobi has implicit variable bounds of " *
    "[-1e30, 1e30]. Settings variable bounds outside this can cause " *
    "infeasibility or unboundedness. Current lower bound extrema: " *
    "$(extrema(lb)). Current upper bound extrema: $(extrema(ub))")


text:
using BSplines

function gen_traj(t, via_points; order=3, basis=nothing)
    @assert length(t) == size(points)[1]
    x = via_points[:,1]
    y = via_points[:,2]
    z = via_points[:,3]

    if basis === nothing
        basis = averagebasis(order, t)
    end
    xspline = BSplines.interpolate(basis, t, x)
    yspline = BSplines.interpolate(basis, t, y)
    zspline = BSplines.interpolate(basis, t, z)

    xspline, yspline, zspline
end

max_stars_repo_name: zborffs/Delta

max_issues_repo_name: zborffs/Delta

max_forks_repo_name: zborffs/Delta


text: fib(n,p=1,a=0)=n==0 ? a : fib(n-1,a,p+a)

max_stars_repo_name: idrougge/ple

max_issues_repo_name: idrougge/ple

max_forks_repo_name: idrougge/ple


text:
export Unitary, is_unitary

"""
    is_unitary( U :: Matrix; atol=ATOL :: Float64 ) :: Bool

Returns `true` if matrix `U` is unitary. The hermitian adjoint of a unitary matrix
is its inverse:
* `U' * U == I` where `I` is the identity matrix.
"""
function is_unitary(U::AbstractMatrix; atol=ATOL :: Float64) :: Bool
    if !isequal(size(U)...)
        return false
    end
    dim = size(U,1)

    isapprox(U'*U, Matrix(I,dim,dim), atol=atol)
end

"""
    Unitary( U :: AbstractMatrix ) <: Operator{T}

Unitary matrices represent the physical evolution of quantum states. The Constructor,
`Unitary(U)`, throws a `DomainError` if the provided matrix, `U` is not unitary.
"""
struct Unitary{T<:Number} <: Operator{T}
    M :: Matrix{T}
    atol :: Float64
    Unitary(
        U :: AbstractMatrix{<:Number};
        atol=ATOL :: Float64
    ) = is_unitary(U, atol=atol) ? new{eltype(U)}(U, atol) : throw(DomainError(U, "matrix U is not unitary"))
end
is_unitary(U :: Unitary) = true

"""
    *(unitaries :: Vararg{Unitary}; atol=ATOL :: Float64) :: Unitary
"""
*(unitaries :: Vararg{Unitary}; atol=ATOL :: Float64) :: Unitary = Unitary(*(map(U -> U.M, unitaries)...), atol=atol)

"""
    kron(unitaries :: Vararg{Unitary}; atol=ATOL :: Float64) :: Unitary
"""
kron(unitaries :: Vararg{Unitary}; atol=ATOL :: Float64) :: Unitary = Unitary(kron(map(U -> U.M, unitaries)...), atol=atol)

"""
    adjoint(U :: Unitary) :: Unitary
"""
adjoint(U :: Unitary) :: Unitary = Unitary(U.M', atol=U.atol)


text:
module AutoGIS

include("Exercise01.jl")

end

max_stars_repo_name: Auto-GIS-with-X/Auto-GIS-with-Julia

max_issues_repo_name: Auto-GIS-with-X/Auto-GIS-with-Julia

max_forks_repo_name: Auto-GIS-with-X/Auto-GIS-with-Julia


text: println("Hello testing!")


text:
random_bool(s::State) =
  randbool()

random_integer(s::State) =
  rand(s.parameters.min_random_integer:s.parameters.max_random_integer)

random_float(s::State) =
  rand(s.parameters.min_random_float:eps(Float32):s.parameters.max_random_float)

random_name(s::State) =
  random_name(s, s.parameters.new_erc_name_probability, s.parameters.min_random_name_length, s.parameters.max_random_name_length)
random_name(s::State, p_new::FloatingPoint, minl::Integer, maxl::Integer) =
  rand() <= p_new ? randstring(rand(minl:maxl)) : random_bound_name(s)
random_name(s::State, ins::Vector{Symbol}) =
  ins[rand(1:end)]
random_bound_name(s::State) =
  random_name(s, list_instructions(s))

# Generates a random atom for `random_code`.
# If the atom is an ERC instruction, then a new ERC is generated and returned
# instead.
function random_atom(s::State)
  atom = random_bound_name(s)
  atom == symbol("FLOAT.ERC") && return random_float(s)
  atom == symbol("INTEGER.ERC") && return random_integer(s)
  atom == symbol("BOOLEAN.ERC") && return random_bool(s)
  atom == symbol("NAME.ERC") && return random_name(s)
  return atom
end

# Very inefficient.
# Should implement an iterative version without overheads and type issues.
random_code(s::State) =
  random_code(s, s.parameters.max_points_in_random_expressions)
random_code(s::State, mx::Integer) =
  random_code_with_size(s, rand(1:mx), mx)
random_code_with_size(s::State, ln::Integer, mx::Integer) =
  ln == 1 ? random_atom(s) : [random_code_with_size(s, i, mx) for i in decompose(ln, mx)]

function decompose(i::Integer, mx::Integer)
  (i == 1 || mx == 1) && return [1]
  this_part = rand(1:i - 1)
  push!(decompose(i - this_part, mx - 1), this_part)
end


text:
fname = :TRSpectral_abs
c = Combi(hessian_dense,PDataSpectral,solve_modelTRDiagAbs,preprocessSpectral,decreaseFact,Tparam())
include("Template.jl")


text:
"""
    reroot!(tree, c)

Reroot a `tree` on node `c`.

If the current root has a branch, that branch will be attached to `c` after rerooting.
"""
function reroot!(tree, c)
    c ≡ getroot(tree) && return nothing

    br_root = getroot(tree).branch

    prev = nothing
    this = c
    next = parent(this)
    brA = this.branch

    while true
        cut!(this)
        if ! isnothing(prev)
            link!(prev => this)
        end
        brB = this.branch
        this.branch = brA
        brA = brB

        prev = this
        p = parent(next)
        isnothing(p) && break
        this = next
        next = p
    end
    @assert next ≡ getroot(tree)
    link!(this => next)
    next.branch = brA

    tree.root = c
    tree.root.branch = br_root

    return nothing
end

max_stars_repo_name: eascarrunz/RootedTrees

max_issues_repo_name: eascarrunz/RootedTrees

max_forks_repo_name: eascarrunz/RootedTrees


text:
# Finite-core model
function bound_leg_velocity(a, b, Γ, ε)
    na, nb, σ = norm(a), norm(b), dot(a, b)
    term_1    = (na^2 - σ) / √(na^2 + ε^2) + (nb^2 - σ) / √(nb^2 + ε^2)
    term_2    = a × b / (na^2 * nb^2 - σ^2 + ε^2 * (na^2 + nb^2 - 2 * na * nb))

    Γ/4π * term_1 * term_2
end

trailing_leg_velocity(r, Γ, u, ε) = Γ/4π * normalize(r) × u / (norm(r) - dot(r, u) + ε^2 / (norm(r) + dot(r, u)))
trailing_legs_velocities(a, b, Γ, u, ε) = trailing_leg_velocity(a, Γ, u, ε) - trailing_leg_velocity(b, Γ, u, ε)
total_horseshoe_velocity(a, b, Γ, u, ε) = bound_leg_velocity(a, b, Γ, ε) + trailing_legs_velocities(a, b, Γ, u, ε)

horseshoe_velocity(r, line :: Line, Γ, direction, ε) = total_horseshoe_velocity(r1(r, line), r2(r, line), Γ, direction, ε)

max_forks_repo_name: GodotMisogi/AeroMDAO


text:
using Test, ModelConstructors, DSGE, Dates, FileIO, Random, JLD2, HDF5

generate_fulldist_forecast_data = false
generate_time_varying_system_for_SSR = false

if VERSION < v"1.5"
    ver = "111"
elseif VERSION < v"1.6"
    ver = "150"
else
    ver = "160"
end

Random.seed!(1793)
@testset "Test regime switching" begin
    n_reg_temp = 14

    m = Model1002("ss10", custom_settings = Dict{Symbol, Setting}(:add_altpolicy_pgap => Setting(:add_altpolicy_pgap, true)))
    m <= Setting(:forecast_smoother, :koopman)
    m <= Setting(:date_forecast_start, Date(2020, 6, 30))
    m <= Setting(:date_conditional_end, Date(2020, 6, 30))
    m <= Setting(:regime_switching, true)
    m <= Setting(:regime_dates, Dict{Int, Date}(1 => date_presample_start(m),
                                                2 => Date(2020, 3, 31),
                                                3 => Date(2020, 6, 30)))
    m = setup_regime_switching_inds!(m)

    t_s, r_s, c_s = solve(m, regimes = Int[3])

    regime_dates = Dict{Int, Date}()
    regime_dates[1] = date_presample_start(m)
    for (i, date) in zip(2:n_reg_temp, Date(2020,3,31):Dates.Month(3):Date(3000,3,31))
        regime_dates[i] = date
    end
    m <= Setting(:regime_dates, regime_dates)

    m <= Setting(:regime_switching, true)

    m = setup_regime_switching_inds!(m)

    # Use gensy2 for temporary rule
    m <= Setting(:gensys2, true)
    # Replace eqcond with temp rule
    m <= Setting(:replace_eqcond, true)
    # Which rule to replace with in which periods
    replace_eqcond = Dict{Int, DSGE.EqcondEntry}()
    for i in 3:(n_reg_temp - 1)
        replace_eqcond[i] = DSGE.EqcondEntry(DSGE.ngdp(), [1., 0.])
    end
    replace_eqcond[n_reg_temp] = DSGE.EqcondEntry(AltPolicy(:historical, eqcond, solve), [1., 0.])

    m <= Setting(:regime_eqcond_info, replace_eqcond)

    m <= Setting(:pgap_value, 12.0 : 0.0)
    m <= Setting(:pgap_type, :ngdp)
    m = setup_regime_switching_inds!(m)

    sys_temp = solve(m, regime_switching = true, regimes = collect(1:n_reg_temp),
                     gensys_regimes = UnitRange{Int}[1:2],
                     gensys2_regimes = UnitRange{Int}[2:n_reg_temp])#, apply_altpolicy=false)
    Γ0s = Vector{Matrix{Float64}}(undef, n_reg_temp - 2)
    Γ1s = Vector{Matrix{Float64}}(undef, n_reg_temp - 2)
    Cs = Vector{Vector{Float64}}(undef,  n_reg_temp - 2)
    Ψs = Vector{Matrix{Float64}}(undef, n_reg_temp - 2)
    Πs = Vector{Matrix{Float64}}(undef, n_reg_temp - 2)
    n_endo = length(collect(keys(m.endogenous_states)))
    for i in (3 - 2):(n_reg_temp - 2)
        global Γ0s[i], Γ1s[i], Cs[i], Ψs[i], Πs[i] = haskey(replace_eqcond, i+2) ? replace_eqcond[i+2].alternative_policy.eqcond(m, i+2) : eqcond(m, i + 2)
    end
    Tcal, Rcal, Ccal = DSGE.gensys2(m, Γ0s, Γ1s, Cs, Ψs, Πs, t_s[1:n_endo, 1:n_endo], r_s[1:n_endo, :], c_s[1:n_endo], 12)
    @test Tcal[1] ≈ sys_temp[1][3][1:n_endo, 1:n_endo]

    # Then when start recrusion with rule, should get same TTTs in every perod
    t, r, c = DSGE.ngdp_solve(m, regime_switching = false, regimes = Int[3])

    get_setting(m, :regime_eqcond_info)[n_reg_temp].alternative_policy = DSGE.ngdp()
    Γ0s[end], Γ1s[end], Cs[end], Ψs[end], Πs[end] = eqcond(m, n_reg_temp)
    Tcal, Rcal, Ccal = DSGE.gensys2(m, Γ0s, Γ1s, Cs, Ψs, Πs, t[1:n_endo, 1:n_endo], r[1:n_endo, :], c[1:n_endo], n_reg_temp - 2)
    for i in 1:length(Tcal)
        @test Tcal[i] ≈ t[1:n_endo, 1:n_endo]
    end
end

@testset "Test regime switching IRFs match Forward Guidance method IRFs" begin
    horizon = 60
    m = Model1002("ss10")
    m <= Setting(:forecast_smoother, :koopman)
    m <= Setting(:date_forecast_start, Date(2020, 6, 30))
    m <= Setting(:date_conditional_end, Date(2020, 6, 30))
    m <= Setting(:replace_eqcond, false)
    m <= Setting(:gensys2, false)
    m <= Setting(:regime_switching, false)
    m[:ρ_rm] = 0.0

    system = compute_system(m)
    H = 2
    nstates = size(system[:TTT], 1)
    nshocks = size(system[:RRR], 2)
    nobs         = size(system[:ZZ], 1)
    npseudo      = size(system[:ZZ_pseudo], 1)

    shocks = m.exogenous_shocks

    states = zeros(nstates, horizon) #, nshocks)
    obs    = zeros(nobs,    horizon) #, nshocks)
    pseudo = zeros(npseudo, horizon) #, nshocks)

    s_0 = zeros(nstates)
    ### IRFs to FFR peg for H periods
    # Set anticipated shocks to peg FFR from t+1 to t+H
    FFRpeg = -m[:Rstarn].value #-0.25/4 #/400

    PsiR1 = 0 #constant
    # ZZ matrix
    PsiR2 = zeros(nstates)
    PsiR2[m.endogenous_states[:R_t]] = 1

    Rht = system[:RRR][:,vcat(shocks[:rm_sh], shocks[:rm_shl1]:shocks[Symbol("rm_shl$H")])]

    bb = zeros(H+1,1)
    MH = zeros(H+1,H+1)
    for hh = 1:H+1
        bb[hh,1] = (FFRpeg - PsiR1 - PsiR2'*(system[:TTT])^hh*s_0)
        MH[hh,:] = PsiR2'*(system[:TTT])^(hh-1)*Rht
    end
    monshocks = MH\bb
    #% Simulate the model
    etpeg = zeros(nshocks,horizon)
    etpeg[vcat(shocks[:rm_sh], shocks[:rm_shl1]:shocks[Symbol("rm_shl$H")]),1] = monshocks
    states[:, :], obs[:, :], pseudo[:, :] = forecast(system, s_0, etpeg, enforce_zlb = false)

    m = Model1002("ss10")
    m <= Setting(:date_forecast_start, Date(2020, 6, 30))
    m <= Setting(:gensys2, true)
    m <= Setting(:replace_eqcond, true)
    replace_eqcond = Dict{Int, DSGE.EqcondEntry}()
    for i in 3:5
        replace_eqcond[i] = DSGE.EqcondEntry(zlb_rule(), [1., 0.])
    end
    m <= Setting(:regime_eqcond_info, replace_eqcond)

    m <= Setting(:regime_switching, true)
    m <= Setting(:regime_dates, Dict{Int, Date}(1 => date_presample_start(m),
                                                2 => Date(1990, 3, 31),
                                                3 => Date(2020, 6, 30),
                                                4 => Date(2020, 9, 30),
                                                5 => Date(2020, 12, 31),
                                                6 => Date(2021, 3, 31)))

    m = setup_regime_switching_inds!(m)

    sys = compute_system(m)
    @test !isapprox(sys[4, :TTT], system[:TTT], atol = 1e-5) # Matrix in regime 4 should not match the matrix w/out regime-switching

    s, o, p = forecast(m, sys, zeros(84), zeros(24, 60),  enforce_zlb = false)

    @test all(isapprox.(s[1:20, :], states[1:20, :], atol = 1e-3))
    @test all(isapprox.(o[1:9, :], obs[1:9, :], atol = 1e-3))
    @test all(isapprox.(p[1:10, :], pseudo[1:10, :], atol = 1e-3))
end

@testset "Temporary alternative policies with non-trivial conditional forecasting" begin
    output_vars = [:forecastobs]

    m = Model1002("ss10", custom_settings = Dict{Symbol, Setting}(:add_altpolicy_pgap =>
                                                                  Setting(:add_altpolicy_pgap, true)))
    m <= Setting(:forecast_smoother, :koopman)

    m <= Setting(:regime_switching, true)
    m <= Setting(:regime_dates, Dict{Int, Date}(1 => date_presample_start(m),
                                                2 => Date(2020, 3, 31),
                                                3 => Date(2020, 6, 30),
                                                4 => Date(2020, 9, 30),
                                                5 => Date(2020, 12, 31),
                                                6 => Date(2021, 3, 31)))
    m <= Setting(:date_conditional_end, Date(2020, 6, 30))
    m <= Setting(:date_forecast_start, Date(2020, 6, 30))
    m <= Setting(:forecast_horizons, 10)
    setup_regime_switching_inds!(m; cond_type = :full)

    fp = dirname(@__FILE__)
    df = load(joinpath(fp, "../reference/regime_switch_data.jld2"), "regime_switch_df_full")
    date_ind = findfirst(df[!, :date] .== Date(2020, 6, 30))
    df[date_ind, :obs_nominalrate] = .3 / 4.
    m <= Setting(:replace_eqcond, true)
    m <= Setting(:regime_eqcond_info, Dict{Int, DSGE.EqcondEntry}(3 => DSGE.EqcondEntry(DSGE.zlb_rule(), [1., 0.])))
    m <= Setting(:pgap_type, :ngdp)
    m <= Setting(:pgap_value, 12.0)
    m <= Setting(:gensys2, true)

    # Check zero rate rule causes an error if specified in a conditional period
    m <= Setting(:regime_eqcond_info, Dict{Int, DSGE.EqcondEntry}(4 => DSGE.EqcondEntry(zlb_rule(), [1., 0.]), 5 => DSGE.EqcondEntry(zlb_rule(), [1., 0.])))
    fcast = DSGE.forecast_one_draw(m, :mode, :full, output_vars, map(x -> x.value, m.parameters),
                                   df; regime_switching = true, n_regimes = get_setting(m, :n_regimes))
    @test fcast[:forecastobs][m.observables[:obs_nominalrate], 1] > .01
    @test abs(fcast[:forecastobs][m.observables[:obs_nominalrate], 2]) < 1e-14
    @test abs(fcast[:forecastobs][m.observables[:obs_nominalrate], 3]) < 1e-14
    @test all(abs.(fcast[:forecastobs][m.observables[:obs_nominalrate], 4:end]) .> .01)

    m <= Setting(:date_conditional_end, Date(2020, 6, 30))
    m <= Setting(:date_forecast_start, Date(2020, 3, 31))
    fcast = DSGE.forecast_one_draw(m, :mode, :full, output_vars, map(x -> x.value, m.parameters),
                                   df; regime_switching = true, n_regimes = get_setting(m, :n_regimes))
    @test fcast[:forecastobs][m.observables[:obs_nominalrate], 1] > .01
    @test abs(fcast[:forecastobs][m.observables[:obs_nominalrate], 2]) > .01
    @test abs(fcast[:forecastobs][m.observables[:obs_nominalrate], 3]) < 1e-14
    @test abs(fcast[:forecastobs][m.observables[:obs_nominalrate], 4]) < 1e-14
    @test all(abs.(fcast[:forecastobs][m.observables[:obs_nominalrate], 5:end]) .> .01)

    m <= Setting(:date_conditional_end, Date(2020, 3, 31))
    m <= Setting(:date_forecast_start, Date(2020, 3, 31))
    fcast = DSGE.forecast_one_draw(m, :mode, :full, output_vars, map(x -> x.value, m.parameters),
                                   df; regime_switching = true, n_regimes = get_setting(m, :n_regimes))
    @test fcast[:forecastobs][m.observables[:obs_nominalrate], 1] > 0.
    @test abs(fcast[:forecastobs][m.observables[:obs_nominalrate], 2]) < 1e-14
    @test abs(fcast[:forecastobs][m.observables[:obs_nominalrate], 3]) < 1e-14
    @test abs(fcast[:forecastobs][m.observables[:obs_nominalrate], 4]) < 1e-14
    @test all(abs.(fcast[:forecastobs][m.observables[:obs_nominalrate], 5:end]) .> 0.)
end

@testset "Calculation of regime indices" begin
    m = AnSchorfheide("ss0")
    m <= Setting(:forecast_smoother, :koopman)

    rss = Vector{Dict{Int, Date}}(undef, 0)
    fss = Vector{Date}(undef, 0)
    ces = Vector{Date}(undef, 0)
    answers = Dict()
    answers[:full] = []
    answers[:none] = []

    push!(rss, Dict{Int, Date}(1 => date_presample_start(m), 2 => Date(2020, 3, 31), 3 => Date(2020, 6, 30), 4 => Date(2020, 9, 30)))
    push!(fss, Date(2020, 6, 30))
    push!(ces, Date(2020, 6, 30))
    push!(answers[:none], [1:1, 2:60])
    push!(answers[:full], [1:59])

    push!(rss, Dict{Int, Date}(1 => date_presample_start(m), 2 => Date(2020, 3, 31), 3 => Date(2020, 6, 30),
                               4 => Date(2021, 12, 31)))
    push!(fss, Date(2020, 6, 30))
    push!(ces, Date(2020, 6, 30))
    push!(answers[:none], [1:6, 7:60])
    push!(answers[:full], [1:5, 6:59])

    push!(rss, Dict{Int, Date}(1 => date_presample_start(m), 2 => Date(2020, 3, 31), 3 => Date(2020, 12, 31),
                               4 => Date(2021, 12, 31)))
    push!(fss, Date(2020, 6, 30))
    push!(ces, Date(2020, 12, 31))
    push!(answers[:none], [1:2, 3:6, 7:60])
    push!(answers[:full], [1:3, 4:57])

    push!(rss, Dict{Int, Date}(1 => date_presample_start(m), 2 => Date(2020, 3, 31), 3 => Date(2021, 12, 31),
                               4 => Date(2022, 12, 31)))
    push!(fss, Date(2020, 6, 30))
    push!(ces, Date(2020, 12, 31))
    push!(answers[:none], [1:6, 7:10, 11:60])
    push!(answers[:full], [1:3, 4:7, 8:57])

    push!(rss, Dict{Int, Date}(1 => date_presample_start(m), 2 => Date(2020, 6, 30), 3 => Date(2021, 12, 31),
                               4 => Date(2022, 12, 31)))
    push!(fss, Date(2020, 6, 30))
    push!(ces, Date(2020, 12, 31))
    push!(answers[:none], [1:6, 7:10, 11:60])
    push!(answers[:full], [1:3, 4:7, 8:57])

    for cond_type in [:full, :none]
        for (i, rs, fs, ce) in zip(1:length(rss), rss, fss, ces)
            m <= Setting(:regime_dates, rs)
            m <= Setting(:date_forecast_start, fs)
            m <= Setting(:date_conditional_end, ce)
            setup_regime_switching_inds!(m)
            fcast_reg_inds = DSGE.get_fcast_regime_inds(m, forecast_horizons(m; cond_type = cond_type), cond_type)
            @test fcast_reg_inds == answers[cond_type][i]
        end
    end
end

@testset "Full-distribution forecast with conditioning and regime switching during forecast horizon" begin
    # Now we check regime switching properly draws shocks
    mtest = AnSchorfheide(;testing = true)
    m = Model1002("ss10")
    # m <= Setting(:forecast_smoother, :koopman)
    m <= Setting(:saveroot, saveroot(mtest))
    m <= Setting(:dataroot, dataroot(mtest))
    m <= Setting(:regime_switching, true)
    m <= Setting(:use_parallel_workers, false)
    fp = dirname(@__FILE__)
    overrides = forecast_input_file_overrides(m)
    overrides[:full] = "$(fp)/../reference/mhsave_vint=181115.h5"
    θ = load_draws(m, :full)[1:3, :]
    m <= Setting(:forecast_jstep, 1)
    m <= Setting(:forecast_block_size, 3)
    m <= Setting(:forecast_horizons, 12)

    rss = Vector{Dict{Int, Date}}(undef, 0)
    fss = Vector{Date}(undef, 0)
    ces = Vector{Date}(undef, 0)
    fcast_out = Dict()

    push!(rss, Dict{Int, Date}(1 => date_presample_start(m), 2 => Date(2020, 3, 31), 3 => Date(2020, 6, 30), 4 => Date(2020, 9, 30)))
    push!(fss, Date(2020, 6, 30))
    push!(ces, Date(2020, 6, 30))

    push!(rss, Dict{Int, Date}(1 => date_presample_start(m), 2 => Date(2020, 3, 31), 3 => Date(2020, 6, 30)))
    push!(fss, Date(2020, 6, 30))
    push!(ces, Date(2020, 6, 30))

    push!(rss, Dict{Int, Date}(1 => date_presample_start(m), 2 => Date(2020, 3, 31), 3 => Date(2020, 12, 31)))
    push!(fss, Date(2020, 6, 30))
    push!(ces, Date(2020, 12, 31))

    push!(rss, Dict{Int, Date}(1 => date_presample_start(m), 2 => Date(2020, 3, 31), 3 => Date(2021, 12, 31)))
    push!(fss, Date(2020, 6, 30))
    push!(ces, Date(2020, 12, 31))

    push!(rss, Dict{Int, Date}(1 => date_presample_start(m), 2 => Date(2020, 6, 30), 3 => Date(2021, 12, 31)))
    push!(fss, Date(2020, 6, 30))
    push!(ces, Date(2020, 12, 31))

    output_vars = [:forecastobs, :forecast4qobs, :forecastpseudo, :histpseudo]
    dfs = Dict()
    fp = dirname(@__FILE__)
    dfs[:full] = load(joinpath(fp, "../reference/regime_switch_data.jld2"), "regime_switch_df_full")
    dfs[:semi] = load(joinpath(fp, "../reference/regime_switch_data.jld2"), "regime_switch_df_semi")
    dfs[:none] = load(joinpath(fp, "../reference/regime_switch_data.jld2"), "regime_switch_df_none")

    if !generate_fulldist_forecast_data
        check_results = load(joinpath(fp, "../reference/regime_switching_fulldist_forecast_version=" * ver * ".jld2"), "fcast_out")
    end

    for (i, rs, fs, ce) in zip(1:length(rss), rss, fss, ces)
        # Set up regime switching
        m <= Setting(:regime_dates, rs)
        m <= Setting(:date_forecast_start, fs)
        m <= Setting(:date_conditional_end, ce)
        for i in 1:length(rs)
            adj = (i == 2) ? .9 : 1.
            ModelConstructors.set_regime_val!(m[:σ_g], i, adj * m[:σ_g].value)
            ModelConstructors.set_regime_val!(m[:σ_b], i, adj * m[:σ_b].value)
            ModelConstructors.set_regime_val!(m[:σ_μ], i, adj * m[:σ_μ].value)
            ModelConstructors.set_regime_val!(m[:σ_ztil], i, adj * m[:σ_ztil].value)
            ModelConstructors.set_regime_val!(m[:σ_λ_f], i, adj * m[:σ_λ_f].value)
            ModelConstructors.set_regime_val!(m[:σ_λ_w], i, adj * m[:σ_λ_w].value)
            ModelConstructors.set_regime_val!(m[:σ_r_m], i, adj * m[:σ_r_m].value)
            ModelConstructors.set_regime_val!(m[:σ_σ_ω], i, adj * m[:σ_σ_ω].value)
            ModelConstructors.set_regime_val!(m[:σ_π_star], i, adj * m[:σ_π_star].value)
            ModelConstructors.set_regime_val!(m[:σ_z_p], i, adj * m[:σ_z_p].value)
        end
        setup_regime_switching_inds!(m)

        # Construct parameter matrix
        θ_rs = zeros(size(θ, 1), ModelConstructors.n_parameters_regime_switching(m))
        n_pvec = DSGE.n_parameters(m)
        for i in 1:size(θ_rs, 1)
            θ_rs[i, 1:n_pvec] = map(x -> (abs(x) < 1e-14) ? 0. : x, θ[i, :])
            j = n_pvec
            for para in DSGE.get_parameters(m)
                if !isempty(para.regimes)
                    for (k, v) in para.regimes[:value]
                        if k > 1
                            j += 1
                            drawv = θ[i, m.keys[para.key]]
                            θ_rs[i, j] = (k  == 2) ? .9 * drawv : drawv
                            if abs(θ_rs[i, j]) < 1e-14
                                θ_rs[i, j] = 0.
                            end
                        end
                    end
                end
            end
        end

        fcast_out[i] = Dict()
        if date_conditional_end(m) == Date(2020, 12, 31) && i == 3
            lastrow = deepcopy(dfs[:full][end, :])
            push!(dfs[:full], vcat(Date(2020, 9, 30), lastrow[2:end]...))
            push!(dfs[:full], vcat(Date(2020, 12, 31), lastrow[2:end]...))
            lastrow = deepcopy(dfs[:semi][end, :])
            push!(dfs[:semi], vcat(Date(2020, 9, 30), lastrow[2:end]...))
            push!(dfs[:semi], vcat(Date(2020, 12, 31), lastrow[2:end]...))
        end
        for cond_type in [:full, :none, :semi]
            if i > 2 && cond_type == :none
                continue
            end
            forecast_one(m, :full, cond_type, output_vars, check_empty_columns = false,
                         params = θ_rs, df = dfs[cond_type], verbose = :none)
            output_files = get_forecast_output_files(m, :full, cond_type, output_vars)

            fcast_out[i][cond_type] = Dict()
            for var in keys(output_files)
                fcast_out[i][cond_type][var] = load(output_files[var], "arr")
            end

            if !generate_fulldist_forecast_data
                for var in keys(output_files)
                    @test maximum(abs.(check_results[i][cond_type][var] - fcast_out[i][cond_type][var])) < 5e-5
                end
            end
        end
    end

    if generate_fulldist_forecast_data
        fp = dirname(@__FILE__)
        JLD2.jldopen(joinpath(fp, "../reference/regime_switching_fulldist_forecast_version=" * ver * ".jld2"), true, true, true, IOStream) do file
            write(file, "fcast_out", fcast_out)
        end
    end
end

@testset "Test smoothing with regime switching and gensys2 matches plain Kalman filtering and conditional data" begin
    n_reg_temp = 16

    m = Model1002("ss10", custom_settings = Dict{Symbol, Setting}(:add_pgap => Setting(:add_pgap, true),
                                                                  :add_ygap => Setting(:add_ygap, true),
                                                                  :add_anticipated_obs_gdp => Setting(:add_anticipated_obs_gdp, true),
                                                                  :n_anticipated_obs_gdp => Setting(:n_anticipated_obs_gdp, true)))
    m <= Setting(:date_forecast_start, Date(2020, 3, 31))
    m <= Setting(:date_conditional_end, Date(2020, 3, 31))
    m <= Setting(:regime_switching, true)
    m <= Setting(:regime_dates, Dict{Int, Date}(1 => date_presample_start(m),
                                                2 => Date(2019, 3, 31),
                                                3 => Date(2019, 6, 30),
                                                4 => Date(2019, 9, 30),
                                                5 => Date(2019, 12, 31),
                                                6 => Date(2020, 3, 31)))
    m = setup_regime_switching_inds!(m)

    regime_dates = Dict{Int, Date}()
    regime_dates[1] = date_presample_start(m)
    for (i, date) in zip(2:n_reg_temp, DSGE.quarter_range(Date(2019, 3, 31), Date(3000,3,31)))
        regime_dates[i] = date
    end
    m <= Setting(:regime_dates, regime_dates)

    m <= Setting(:regime_switching, true)

    m = setup_regime_switching_inds!(m)

    # Use gensy2 for temporary rule
    m <= Setting(:gensys2, true)
    # Replace eqcond with temp rule
    m <= Setting(:replace_eqcond, true)
    # Which rule to replace with in which periods
    replace_eqcond = Dict{Int, DSGE.EqcondEntry}()

    for prob_weights in [[1., 0.], [.5, .5]]
        for i in 3:n_reg_temp-1
            replace_eqcond[i] = DSGE.EqcondEntry(zlb_rule(), prob_weights)
        end
        replace_eqcond[n_reg_temp] = DSGE.EqcondEntry(flexible_ait(), prob_weights)
        m <= Setting(:regime_eqcond_info, replace_eqcond)

        if prob_weights[1] < .5
            m <= Setting(:uncertain_altpolicy, true)
            m <= Setting(:uncertain_temporary_altpolicy, true)
            m <= Setting(:alternative_policies, [DSGE.default_policy()])
            m <= Setting(:temporary_altpolicy_length, (n_reg_temp - 1 - 3 + 1))
        end
        m <= Setting(:remove_rm_shocks, 3)
        m <= Setting(:pgap_value, 0.0)
        m <= Setting(:pgap_type, :flexible_ait)
        m <= Setting(:ygap_value, 12.)
        m <= Setting(:ygap_type, :flexible_ait)
        setup_regime_switching_inds!(m; cond_type = :full)
        m <= Setting(:tvis_information_set, [1:1, 2:2, [i:get_setting(m, :n_regimes) for i in 3:get_setting(m, :n_regimes)]...])

        sys = compute_system(m; tvis = true)
        df = load(joinpath(dirname(@__FILE__), "../reference/regime_switch_data.jld2"), "regime_switch_df_none")
        df[end, :obs_hours] = NaN
        df[end, :obs_wages] = NaN
        df[end, :obs_consumption] = NaN
        df[end - 3:end, :obs_nominalrate] .= NaN
        df[!, :obs_gdp1] .= NaN

        data = df_to_matrix(m, df; cond_type = :full)
        regime_inds, i_zlb_start, splice_zlb_regime = DSGE.zlb_plus_regime_indices(m, data, date_presample_start(m))
        TTTs, RRRs, CCCs, QQs, ZZs, DDs, EEs = DSGE.zlb_plus_regime_matrices(m, sys, length(regime_inds),
                                                                             date_presample_start(m);
                                                                             ind_zlb_start = i_zlb_start,
                                                                             splice_zlb_regime = splice_zlb_regime)

        # Add anticipated data to df
        df[!, :obs_longinflation] = convert(Vector{Union{Float64, Missing}}, df[!, :obs_longinflation])
        df[!, :obs_longrate] = convert(Vector{Union{Float64, Missing}}, df[!, :obs_longrate])
        for i in 1:6
            df[!, Symbol("obs_nominalrate$i")] = convert(Vector{Union{Float64, Missing}}, df[!, Symbol("obs_nominalrate$i")])
        end
        df[end, :obs_longinflation] = .5
        df[end, :obs_longrate] = .5
        df[end - 1, :obs_longinflation] = .5
        df[end - 5, :obs_longinflation] = .5
        df[end - 6, :obs_longinflation] = .5
        df[end - 10, :obs_longinflation] = .5
        df[end - 6:end, :obs_longrate] .= .5
        df[end - 10, :obs_longrate] = .5
        df[end - 5, :obs_nominalrate1] = .5475
        df[end - 10, :obs_nominalrate1] = .5475
        df[end - 11, :obs_nominalrate1] = .2
        df[end - 11, :obs_nominalrate2] = .2
        df[end - 12, :obs_nominalrate3] = .25
        df[end - 13, :obs_nominalrate4] = .22
        df[end - 14, :obs_nominalrate5] = .18
        df[end - 15, :obs_nominalrate6] = .19
        df[end - 10, :obs_gdp1] = .65
        df[end - 5:end, :obs_gdp1] = [.5, .3, .3, .3, -1., -.5]

        histstates = Dict()
        histobs = Dict()
        condobs = Dict()
        for k in [:koopman, :hamilton, :carter_kohn, :durbin_koopman]
            m <= Setting(:forecast_smoother, k)
            histstates[k], _, _, _ = smooth(m, df, sys; cond_type = :full, draw_states = false)
        end

        kal = DSGE.filter(m, df, sys; cond_type = :full)

        for k in [:koopman, :hamilton, :durbin_koopman, :carter_kohn]
            condobs[k] = sys[6, :ZZ] * histstates[k][:, end] + sys[6, :DD]
            histobs[k] = zeros(n_observables(m), size(histstates[k][:, 1:end - 1], 2))
            histobs[k][:, 1:end - 4] = sys[1, :ZZ] * histstates[k][:, 1:end - 5] .+ sys[1, :DD]
            histobs[k][:, end - 3] = sys[2, :ZZ] * histstates[k][:, end - 4] + sys[2, :DD]
            histobs[k][:, end - 2] = sys[3, :ZZ] * histstates[k][:, end - 3] + sys[3, :DD]
            histobs[k][:, end - 1] = sys[4, :ZZ] * histstates[k][:, end - 2] + sys[4, :DD]
            histobs[k][:, end] = sys[5, :ZZ] * histstates[k][:, end - 1] + sys[5, :DD]
            @test histstates[k][:, end] ≈ kal[:s_T]

            # Check the implied observables matches conditional data
            for (i, j) in zip([1, 4, 5, 8, 10], [:obs_gdp, :obs_gdpdeflator, :obs_corepce, :obs_investment, :obs_longinflation])
                @test condobs[k][i] ≈ df[end, j]
            end
            @test histobs[k][m.observables[:obs_nominalrate1], end - 9] ≈ df[end - 10, :obs_nominalrate1]
        end

        # Check states match among the different smoothers
        @test histobs[:durbin_koopman] ≈ histobs[:koopman]
        @test histobs[:carter_kohn] ≈ histobs[:hamilton]
        @test histstates[:durbin_koopman] ≈ histstates[:koopman]
        @test histstates[:carter_kohn] ≈ histstates[:hamilton]
        for k in [:carter_kohn, :hamilton]
            @test maximum(abs.(histobs[:durbin_koopman] - histobs[k])) < 1.5e-3 # should the approximately the same
            @test maximum(abs.(histstates[:durbin_koopman] - histstates[k])) < 1e-2
        end

        # Check drawing states still matches observables
        Random.seed!(1793)
        histstates_draw, _, _, _ = smooth(m, df, sys; cond_type = :full, draw_states = true)
        condobs_draw = sys[6, :ZZ] * histstates_draw[:, end] + sys[6, :DD]
        histobs_draw = zeros(n_observables(m), size(histstates_draw[:, 1:end - 1], 2))
        histobs_draw[:, 1:end - 4] = sys[1, :ZZ] * histstates_draw[:, 1:end - 5] .+ sys[1, :DD]
        histobs_draw[:, end - 3] = sys[2, :ZZ] * histstates_draw[:, end - 4] + sys[2, :DD]
        histobs_draw[:, end - 2] = sys[3, :ZZ] * histstates_draw[:, end - 3] + sys[3, :DD]
        histobs_draw[:, end - 1] = sys[4, :ZZ] * histstates_draw[:, end - 2] + sys[4, :DD]
        histobs_draw[:, end] = sys[5, :ZZ] * histstates_draw[:, end - 1] + sys[5, :DD]

        # Check the implied observables matches conditional data
        for (i, j) in zip([1, 4, 5, 8, 10], [:obs_gdp, :obs_gdpdeflator, :obs_corepce, :obs_investment, :obs_longinflation])
            @test condobs_draw[i] ≈ df[end, j]
        end
        @test histobs_draw[m.observables[:obs_nominalrate1], end - 9] ≈ df[end - 10, :obs_nominalrate1]

        inds = vcat(1:9, 13:13) # can't check other variables b/c they're missing, so drawing states would generate uncertainty
        @test histobs_draw[inds, 19:end-1] ≈ histobs[:durbin_koopman][inds, 19:end-1]
        @test histobs_draw[1:9, end] ≈ histobs[:durbin_koopman][1:9, end] # data is missing for hours at end, so check non-missing obs
        @test !(histobs_draw[2, 1:18] ≈ histobs[:durbin_koopman][2, 1:18]) # hours data is missing, so this shouldn't match
        for i in 14:19
            @test !(histobs_draw[i, :] ≈ histobs[:durbin_koopman][i, :])
        end

        if generate_time_varying_system_for_SSR
            h5open("time_varying_system.h5", "w") do file
                for i in 1:length(TTTs)
                    write(file, "T$(i)", TTTs[i])
                    write(file, "R$(i)", RRRs[i])
                    write(file, "C$(i)", CCCs[i])
                    write(file, "Z$(i)", ZZs[i])
                    write(file, "D$(i)", DDs[i])
                    write(file, "Q$(i)", QQs[i])
                    write(file, "E$(i)", EEs[i])
                    write(file, "regime_inds$(i)", collect(regime_inds[i]))
                end
                write(file, "data", df_to_matrix(m, df; cond_type = :full))
            end
        end
    end
end

nothing


text:
using Test
using JSExpr
using JSExpr: @crawl, deparse, JSTerminal, JSString

@testset "function" begin

    @testset "function keyword" begin
        @test string(@js function add(x, y)
            return x + y
        end) == "function add(x, y) { return x + y; }"

        @test string(@js function log(message)
            console.log(message)
        end) == "function log(message) { console.log(message); }"

        @test string(@js function foo() end) == "function foo() {}"
        @test string(@js function () end) == "(function () {})"
    end

    @testset "anonymous function-keyword function" begin
        @test string(@js(
            function (x, y) console.log(x + y) end
        )) == "(function (x, y) { console.log(x + y); })"
    end

    @testset "anonymous arrow function" begin
        jsstr = @js x -> x + 3
        @test jsstr == JSString("(x) => { return x + 3; }")

        jsstr = @js (x, y) -> x + y
        @test jsstr == JSString("(x, y) => { return x + y; }")
    end

    @testset "automatic return insertion" begin
        @test string(@js(
            (x, y) -> if x > y
                x
            else
                y
            end
        )) == "(x, y) => { if (x > y) { return x; } else { return y; }; }"
    end
end