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

@test integrate(sin(2a+2*b*x)^7*sin(a+b*x), x) == :(-384//11*b^-1*sin(a+b*x)^11+-128//15*b^-1*sin(a+b*x)^15+128//9*b^-1*sin(a+b*x)^9+384//13*b^-1*sin(a+b*x)^13)
@test integrate(sin(2a+2*b*x)^6*sin(a+b*x), x) == :(-192//11*b^-1*cos(a+b*x)^11+-64//7*b^-1*cos(a+b*x)^7+64//3*b^-1*cos(a+b*x)^9+64//13*b^-1*cos(a+b*x)^13)
@test integrate(sin(2a+2*b*x)^5*sin(a+b*x), x) == :(-64//9*b^-1*sin(a+b*x)^9+32//7*b^-1*sin(a+b*x)^7+32//11*b^-1*sin(a+b*x)^11)
@test integrate(sin(2a+2*b*x)^4*sin(a+b*x), x) == :(-16//5*b^-1*cos(a+b*x)^5+-16//9*b^-1*cos(a+b*x)^9+32//7*b^-1*cos(a+b*x)^7)
@test integrate(sin(2a+2*b*x)^3*sin(a+b*x), x) == :(-8//7*b^-1*sin(a+b*x)^7+8//5*b^-1*sin(a+b*x)^5)
@test integrate(sin(2a+2*b*x)^2*sin(a+b*x), x) == :(-4//3*b^-1*cos(a+b*x)^3+4//5*b^-1*cos(a+b*x)^5)
@test integrate(sin(a+b*x)*sin(2a+2*b*x), x) == :((1/2)*b^-1*sin(a+b*x)+-1//6*b^-1*sin(3a+3*b*x))
@test integrate(csc(2a+2*b*x)*sin(a+b*x), x) == :((1/2)*b^-1*arctanh(sin(a+b*x)))
@test integrate(csc(2a+2*b*x)^2*sin(a+b*x), x) == :(-1//4*b^-1*arctanh(cos(a+b*x))+1//4*b^-1*sec(a+b*x))
@test integrate(csc(2a+2*b*x)^3*sin(a+b*x), x) == :(-3//16*b^-1*csc(a+b*x)+3//16*b^-1*arctanh(sin(a+b*x))+1//16*b^-1*sec(a+b*x)^2*csc(a+b*x))
@test integrate(csc(2a+2*b*x)^4*sin(a+b*x), x) == :(-5//32*b^-1*arctanh(cos(a+b*x))+5//32*b^-1*sec(a+b*x)+5//96*b^-1*sec(a+b*x)^3+-1//32*b^-1*csc(a+b*x)^2*sec(a+b*x)^3)
@test integrate(csc(2a+2*b*x)^5*sin(a+b*x), x) == :(-35//256*b^-1*csc(a+b*x)+-35//768*b^-1*csc(a+b*x)^3+35//256*b^-1*arctanh(sin(a+b*x))+1//128*b^-1*csc(a+b*x)^3*sec(a+b*x)^4+7//256*b^-1*csc(a+b*x)^3*sec(a+b*x)^2)
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x)^5, x) == :(4*b^-1*sin(a+b*x)^8+-32//5*b^-1*sin(a+b*x)^10+8//3*b^-1*sin(a+b*x)^12)
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x)^4, x) == :(3//16*x+-1//20*b^-1*sin(2a+2*b*x)^5+-3//32*b^-1*cos(2a+2*b*x)*sin(2a+2*b*x)+-1//16*b^-1*sin(2a+2*b*x)^3*cos(2a+2*b*x))
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x)^3, x) == :(-1*b^-1*sin(a+b*x)^8+4//3*b^-1*sin(a+b*x)^6)
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x)^2, x) == :(1//4*x+-1//12*b^-1*sin(2a+2*b*x)^3+-1//8*b^-1*cos(2a+2*b*x)*sin(2a+2*b*x))
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x), x) == :((1/2)*b^-1*sin(a+b*x)^4)
@test integrate(sin(a+b*x)^2*csc(2a+2*b*x), x) == :(-1//2*b^-1*log(cos(a+b*x)))
@test integrate(csc(2a+2*b*x)^2*sin(a+b*x)^2, x) == :(1//4*b^-1*tan(a+b*x))
@test integrate(csc(2a+2*b*x)^3*sin(a+b*x)^2, x) == :(1//8*b^-1*log(tan(a+b*x))+1//16*b^-1*tan(a+b*x)^2)
@test integrate(csc(2a+2*b*x)^4*sin(a+b*x)^2, x) == :(-1//16*b^-1*cot(a+b*x)+1//8*b^-1*tan(a+b*x)+1//48*b^-1*tan(a+b*x)^3)
@test integrate(csc(2a+2*b*x)^5*sin(a+b*x)^2, x) == :(-1//64*b^-1*cot(a+b*x)^2+1//128*b^-1*tan(a+b*x)^4+3//32*b^-1*log(tan(a+b*x))+3//64*b^-1*tan(a+b*x)^2)
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x)^5, x) == :(-64//11*b^-1*sin(a+b*x)^11+32//9*b^-1*sin(a+b*x)^9+32//13*b^-1*sin(a+b*x)^13)
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x)^4, x) == :(-16//3*b^-1*cos(a+b*x)^9+-16//5*b^-1*cos(a+b*x)^5+16//11*b^-1*cos(a+b*x)^11+48//7*b^-1*cos(a+b*x)^7)
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x)^3, x) == :(-8//9*b^-1*sin(a+b*x)^9+8//7*b^-1*sin(a+b*x)^7)
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x)^2, x) == :(-4//3*b^-1*cos(a+b*x)^3+-4//7*b^-1*cos(a+b*x)^7+8//5*b^-1*cos(a+b*x)^5)
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x), x) == :(2//5*b^-1*sin(a+b*x)^5)
@test integrate(sin(a+b*x)^3*csc(2a+2*b*x), x) == :((1/2)*b^-1*arctanh(sin(a+b*x))+-1//2*b^-1*sin(a+b*x))
@test integrate(csc(2a+2*b*x)^2*sin(a+b*x)^3, x) == :(1//4*b^-1*sec(a+b*x))
@test integrate(csc(2a+2*b*x)^3*sin(a+b*x)^3, x) == :(1//16*b^-1*arctanh(sin(a+b*x))+1//16*b^-1*sec(a+b*x)*tan(a+b*x))
@test integrate(csc(2a+2*b*x)^4*sin(a+b*x)^3, x) == :(-1//16*b^-1*arctanh(cos(a+b*x))+1//16*b^-1*sec(a+b*x)+1//48*b^-1*sec(a+b*x)^3)
@test integrate(csc(2a+2*b*x)^5*sin(a+b*x)^3, x) == :(-15//256*b^-1*csc(a+b*x)+15//256*b^-1*arctanh(sin(a+b*x))+1//128*b^-1*sec(a+b*x)^4*csc(a+b*x)+5//256*b^-1*sec(a+b*x)^2*csc(a+b*x))
@test integrate(sin(2a+2*b*x)^8*csc(a+b*x), x) == :(-768//13*b^-1*cos(a+b*x)^13+-256//9*b^-1*cos(a+b*x)^9+256//15*b^-1*cos(a+b*x)^15+768//11*b^-1*cos(a+b*x)^11)
@test integrate(sin(2a+2*b*x)^7*csc(a+b*x), x) == :(-128//3*b^-1*sin(a+b*x)^9+-128//13*b^-1*sin(a+b*x)^13+128//7*b^-1*sin(a+b*x)^7+384//11*b^-1*sin(a+b*x)^11)
@test integrate(sin(2a+2*b*x)^6*csc(a+b*x), x) == :(-64//7*b^-1*cos(a+b*x)^7+-64//11*b^-1*cos(a+b*x)^11+128//9*b^-1*cos(a+b*x)^9)
@test integrate(sin(2a+2*b*x)^5*csc(a+b*x), x) == :(-64//7*b^-1*sin(a+b*x)^7+32//5*b^-1*sin(a+b*x)^5+32//9*b^-1*sin(a+b*x)^9)
@test integrate(sin(2a+2*b*x)^4*csc(a+b*x), x) == :(-16//5*b^-1*cos(a+b*x)^5+16//7*b^-1*cos(a+b*x)^7)
@test integrate(sin(2a+2*b*x)^3*csc(a+b*x), x) == :(-8//5*b^-1*sin(a+b*x)^5+8//3*b^-1*sin(a+b*x)^3)
@test integrate(sin(2a+2*b*x)^2*csc(a+b*x), x) == :(-4//3*b^-1*cos(a+b*x)^3)
@test integrate(csc(a+b*x)*sin(2a+2*b*x), x) == :(2*b^-1*sin(a+b*x))
@test integrate(csc(a+b*x)*csc(2a+2*b*x), x) == :((1/2)*b^-1*arctanh(sin(a+b*x))+-1//2*b^-1*csc(a+b*x))
@test integrate(csc(2a+2*b*x)^2*csc(a+b*x), x) == :(-3//8*b^-1*arctanh(cos(a+b*x))+3//8*b^-1*sec(a+b*x)+-1//8*b^-1*csc(a+b*x)^2*sec(a+b*x))
@test integrate(csc(2a+2*b*x)^3*csc(a+b*x), x) == :(-5//16*b^-1*csc(a+b*x)+-5//48*b^-1*csc(a+b*x)^3+5//16*b^-1*arctanh(sin(a+b*x))+1//16*b^-1*csc(a+b*x)^3*sec(a+b*x)^2)
@test integrate(csc(2a+2*b*x)^4*csc(a+b*x), x) == :(-35//128*b^-1*arctanh(cos(a+b*x))+35//128*b^-1*sec(a+b*x)+35//384*b^-1*sec(a+b*x)^3+-7//128*b^-1*csc(a+b*x)^2*sec(a+b*x)^3+-1//64*b^-1*csc(a+b*x)^4*sec(a+b*x)^3)
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^8, x) == :(5//8*x+-160//21*b^-1*cos(a+b*x)^9*sin(a+b*x)^3+-128//7*b^-1*cos(a+b*x)^9*sin(a+b*x)^5+-16//7*b^-1*cos(a+b*x)^9*sin(a+b*x)+1//3*b^-1*cos(a+b*x)^5*sin(a+b*x)+2//7*b^-1*cos(a+b*x)^7*sin(a+b*x)+5//8*b^-1*cos(a+b*x)*sin(a+b*x)+5//12*b^-1*cos(a+b*x)^3*sin(a+b*x))
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^7, x) == :(-16*b^-1*cos(a+b*x)^8+-32//3*b^-1*cos(a+b*x)^12+128//5*b^-1*cos(a+b*x)^10)
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^6, x) == :(3//4*x+(1/2)*b^-1*cos(a+b*x)^3*sin(a+b*x)+-32//5*b^-1*cos(a+b*x)^7*sin(a+b*x)^3+-12//5*b^-1*cos(a+b*x)^7*sin(a+b*x)+2//5*b^-1*cos(a+b*x)^5*sin(a+b*x)+3//4*b^-1*cos(a+b*x)*sin(a+b*x))
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^5, x) == :(4*b^-1*cos(a+b*x)^8+-16//3*b^-1*cos(a+b*x)^6)
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^4, x) == :(x+b^-1*cos(a+b*x)*sin(a+b*x)+-8//3*b^-1*cos(a+b*x)^5*sin(a+b*x)+2//3*b^-1*cos(a+b*x)^3*sin(a+b*x))
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^3, x) == :(-2*b^-1*cos(a+b*x)^4)
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^2, x) == :(2x+2*b^-1*cos(a+b*x)*sin(a+b*x))
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x), x) == :(2*b^-1*log(sin(a+b*x)))
@test integrate(csc(a+b*x)^2*csc(2a+2*b*x), x) == :((1/2)*b^-1*log(tan(a+b*x))+-1//4*b^-1*cot(a+b*x)^2)
@test integrate(csc(a+b*x)^2*csc(2a+2*b*x)^2, x) == :(-1//2*b^-1*cot(a+b*x)+-1//12*b^-1*cot(a+b*x)^3+1//4*b^-1*tan(a+b*x))
@test integrate(csc(a+b*x)^2*csc(2a+2*b*x)^3, x) == :(-3//16*b^-1*cot(a+b*x)^2+-1//32*b^-1*cot(a+b*x)^4+1//16*b^-1*tan(a+b*x)^2+3//8*b^-1*log(tan(a+b*x)))
@test integrate(csc(a+b*x)^2*csc(2a+2*b*x)^4, x) == :(-3//8*b^-1*cot(a+b*x)+-1//12*b^-1*cot(a+b*x)^3+-1//80*b^-1*cot(a+b*x)^5+1//4*b^-1*tan(a+b*x)+1//48*b^-1*tan(a+b*x)^3)
@test integrate(csc(a+b*x)^2*csc(2a+2*b*x)^5, x) == :(-5//32*b^-1*cot(a+b*x)^2+-5//128*b^-1*cot(a+b*x)^4+-1//192*b^-1*cot(a+b*x)^6+1//128*b^-1*tan(a+b*x)^4+5//16*b^-1*log(tan(a+b*x))+5//64*b^-1*tan(a+b*x)^2)
@test integrate(csc(a+b*x)^2*csc(2a+2*b*x)^6, x) == :(-5//16*b^-1*cot(a+b*x)+-5//64*b^-1*cot(a+b*x)^3+-3//160*b^-1*cot(a+b*x)^5+-1//448*b^-1*cot(a+b*x)^7+1//32*b^-1*tan(a+b*x)^3+1//320*b^-1*tan(a+b*x)^5+15//64*b^-1*tan(a+b*x))
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^10, x) == :(-1024//5*b^-1*cos(a+b*x)^15+-1024//11*b^-1*cos(a+b*x)^11+1024//17*b^-1*cos(a+b*x)^17+3072//13*b^-1*cos(a+b*x)^13)
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^9, x) == :(-2048//9*b^-1*sin(a+b*x)^9+-2048//13*b^-1*sin(a+b*x)^13+512//7*b^-1*sin(a+b*x)^7+512//15*b^-1*sin(a+b*x)^15+3072//11*b^-1*sin(a+b*x)^11)
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^8, x) == :(-256//9*b^-1*cos(a+b*x)^9+-256//13*b^-1*cos(a+b*x)^13+512//11*b^-1*cos(a+b*x)^11)
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^7, x) == :(-384//7*b^-1*sin(a+b*x)^7+-128//11*b^-1*sin(a+b*x)^11+128//3*b^-1*sin(a+b*x)^9+128//5*b^-1*sin(a+b*x)^5)
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^6, x) == :(-64//7*b^-1*cos(a+b*x)^7+64//9*b^-1*cos(a+b*x)^9)
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^5, x) == :(-64//5*b^-1*sin(a+b*x)^5+32//3*b^-1*sin(a+b*x)^3+32//7*b^-1*sin(a+b*x)^7)
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^4, x) == :(-16//5*b^-1*cos(a+b*x)^5)
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^3, x) == :(8*b^-1*sin(a+b*x)+-8//3*b^-1*sin(a+b*x)^3)
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^2, x) == :(-4*b^-1*arctanh(cos(a+b*x))+4*b^-1*cos(a+b*x))
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x), x) == :(-2*b^-1*csc(a+b*x))
@test integrate(csc(a+b*x)^3*csc(2a+2*b*x), x) == :((1/2)*b^-1*arctanh(sin(a+b*x))+-1//2*b^-1*csc(a+b*x)+-1//6*b^-1*csc(a+b*x)^3)
@test integrate(csc(a+b*x)^3*csc(2a+2*b*x)^2, x) == :(-15//32*b^-1*arctanh(cos(a+b*x))+15//32*b^-1*sec(a+b*x)+-5//32*b^-1*csc(a+b*x)^2*sec(a+b*x)+-1//16*b^-1*csc(a+b*x)^4*sec(a+b*x))
@test integrate(csc(a+b*x)^3*csc(2a+2*b*x)^3, x) == :(-7//16*b^-1*csc(a+b*x)+-7//48*b^-1*csc(a+b*x)^3+-7//80*b^-1*csc(a+b*x)^5+7//16*b^-1*arctanh(sin(a+b*x))+1//16*b^-1*csc(a+b*x)^5*sec(a+b*x)^2)
@test integrate(csc(a+b*x)^3*csc(2a+2*b*x)^4, x) == :(-105//256*b^-1*arctanh(cos(a+b*x))+35//256*b^-1*sec(a+b*x)^3+105//256*b^-1*sec(a+b*x)+-21//256*b^-1*csc(a+b*x)^2*sec(a+b*x)^3+-3//128*b^-1*csc(a+b*x)^4*sec(a+b*x)^3+-1//96*b^-1*csc(a+b*x)^6*sec(a+b*x)^3)
@test integrate(sin(2a+2*b*x)^5//2*sin(a+b*x), x) == :(-5//32*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+5//32*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-5//16*b^-1*sin(2a+2*b*x)^(1/2)*cos(a+b*x)+-1//6*b^-1*sin(2a+2*b*x)^5//2*cos(a+b*x)+5//24*b^-1*sin(2a+2*b*x)^3//2*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^3//2*sin(a+b*x), x) == :(-3//16*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+-3//16*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-1//4*b^-1*sin(2a+2*b*x)^3//2*cos(a+b*x)+3//8*b^-1*sin(2a+2*b*x)^(1/2)*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^(1/2)*sin(a+b*x), x) == :(-1//4*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+1//4*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-1//2*b^-1*sin(2a+2*b*x)^(1/2)*cos(a+b*x))
@test integrate(sin(2a+2*b*x)^-1//2*sin(a+b*x), x) == :(-1//2*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+-1//2*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x)))
@test integrate(sin(2a+2*b*x)^-3//2*sin(a+b*x), x) == :(b^-1*sin(2a+2*b*x)^-1//2*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^-5//2*sin(a+b*x), x) == :(-2//3*b^-1*sin(2a+2*b*x)^-1//2*cos(a+b*x)+1//3*b^-1*sin(2a+2*b*x)^-3//2*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^-7//2*sin(a+b*x), x) == :(-4//15*b^-1*sin(2a+2*b*x)^-3//2*cos(a+b*x)+1//5*b^-1*sin(2a+2*b*x)^-5//2*sin(a+b*x)+8//15*b^-1*sin(2a+2*b*x)^-1//2*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^-9//2*sin(a+b*x), x) == :(-16//35*b^-1*sin(2a+2*b*x)^-1//2*cos(a+b*x)+-6//35*b^-1*sin(2a+2*b*x)^-5//2*cos(a+b*x)+1//7*b^-1*sin(2a+2*b*x)^-7//2*sin(a+b*x)+8//35*b^-1*sin(2a+2*b*x)^-3//2*sin(a+b*x))
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x)^7//2, x) == :(-1//18*b^-1*sin(2a+2*b*x)^9//2+5//42*b^-1*Elliptic.F(a+-1//4*pi+b*x,2)+-5//42*b^-1*sin(2a+2*b*x)^(1/2)*cos(2a+2*b*x)+-1//14*b^-1*sin(2a+2*b*x)^5//2*cos(2a+2*b*x))
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x)^5//2, x) == :(-1//14*b^-1*sin(2a+2*b*x)^7//2+3//10*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+-1//10*b^-1*sin(2a+2*b*x)^3//2*cos(2a+2*b*x))
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x)^3//2, x) == :(-1//10*b^-1*sin(2a+2*b*x)^5//2+1//6*b^-1*Elliptic.F(a+-1//4*pi+b*x,2)+-1//6*b^-1*sin(2a+2*b*x)^(1/2)*cos(2a+2*b*x))
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x)^(1/2), x) == :((1/2)*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+-1//6*b^-1*sin(2a+2*b*x)^3//2)
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x)^-1//2, x) == :((1/2)*b^-1*Elliptic.F(a+-1//4*pi+b*x,2)+-1//2*b^-1*sin(2a+2*b*x)^(1/2))
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x)^-3//2, x) == :(-1//2*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+b^-1*sin(a+b*x)^2*sin(2a+2*b*x)^-1//2)
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x)^-5//2, x) == :(1//6*b^-1*Elliptic.F(a+-1//4*pi+b*x,2)+1//3*b^-1*sin(a+b*x)^2*sin(2a+2*b*x)^-3//2)
@test integrate(sin(a+b*x)^2*sin(2a+2*b*x)^-7//2, x) == :(-3//10*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+-3//10*b^-1*sin(2a+2*b*x)^-1//2*cos(2a+2*b*x)+1//5*b^-1*sin(a+b*x)^2*sin(2a+2*b*x)^-5//2)
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x)^3//2, x) == :(-7//64*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+-7//64*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-7//48*b^-1*sin(2a+2*b*x)^3//2*cos(a+b*x)+-1//12*b^-1*sin(2a+2*b*x)^5//2*sin(a+b*x)+7//32*b^-1*sin(2a+2*b*x)^(1/2)*sin(a+b*x))
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x)^(1/2), x) == :(-5//32*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+5//32*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-5//16*b^-1*sin(2a+2*b*x)^(1/2)*cos(a+b*x)+-1//8*b^-1*sin(2a+2*b*x)^3//2*sin(a+b*x))
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x)^-1//2, x) == :(-3//8*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+-3//8*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-1//4*b^-1*sin(2a+2*b*x)^(1/2)*sin(a+b*x))
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x)^-3//2, x) == :(-1//4*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+1//4*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+b^-1*sin(2a+2*b*x)^-1//2*sin(a+b*x))
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x)^-5//2, x) == :(1//3*b^-1*sin(a+b*x)^3*sin(2a+2*b*x)^-3//2)
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x)^-7//2, x) == :(1//5*b^-1*sin(a+b*x)^3*sin(2a+2*b*x)^-5//2+1//5*b^-1*sin(2a+2*b*x)^-1//2*sin(a+b*x))
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x)^-9//2, x) == :(-4//21*b^-1*sin(2a+2*b*x)^-1//2*cos(a+b*x)+1//7*b^-1*sin(a+b*x)^3*sin(2a+2*b*x)^-7//2+2//21*b^-1*sin(2a+2*b*x)^-3//2*sin(a+b*x))
@test integrate(sin(a+b*x)^3*sin(2a+2*b*x)^-11//2, x) == :(-4//45*b^-1*sin(2a+2*b*x)^-3//2*cos(a+b*x)+1//9*b^-1*sin(a+b*x)^3*sin(2a+2*b*x)^-9//2+1//15*b^-1*sin(2a+2*b*x)^-5//2*sin(a+b*x)+8//45*b^-1*sin(2a+2*b*x)^-1//2*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^7//2*csc(a+b*x), x) == :(-5//16*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+-5//16*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-5//12*b^-1*sin(2a+2*b*x)^3//2*cos(a+b*x)+1//3*b^-1*sin(2a+2*b*x)^5//2*sin(a+b*x)+5//8*b^-1*sin(2a+2*b*x)^(1/2)*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^5//2*csc(a+b*x), x) == :(-3//8*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+3//8*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+(1/2)*b^-1*sin(2a+2*b*x)^3//2*sin(a+b*x)+-3//4*b^-1*sin(2a+2*b*x)^(1/2)*cos(a+b*x))
@test integrate(sin(2a+2*b*x)^3//2*csc(a+b*x), x) == :(-1//2*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+-1//2*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+b^-1*sin(2a+2*b*x)^(1/2)*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^(1/2)*csc(a+b*x), x) == :(b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-1*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x)))
@test integrate(sin(2a+2*b*x)^-1//2*csc(a+b*x), x) == :(-1*b^-1*sin(2a+2*b*x)^(1/2)*csc(a+b*x))
@test integrate(sin(2a+2*b*x)^-3//2*csc(a+b*x), x) == :(-2//3*b^-1*sin(2a+2*b*x)^-3//2*cos(a+b*x)+4//3*b^-1*sin(2a+2*b*x)^-1//2*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^-5//2*csc(a+b*x), x) == :(-16//15*b^-1*sin(2a+2*b*x)^-1//2*cos(a+b*x)+-2//5*b^-1*sin(2a+2*b*x)^-5//2*cos(a+b*x)+8//15*b^-1*sin(2a+2*b*x)^-3//2*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^-7//2*csc(a+b*x), x) == :(-16//35*b^-1*sin(2a+2*b*x)^-3//2*cos(a+b*x)+-2//7*b^-1*sin(2a+2*b*x)^-7//2*cos(a+b*x)+12//35*b^-1*sin(2a+2*b*x)^-5//2*sin(a+b*x)+32//35*b^-1*sin(2a+2*b*x)^-1//2*sin(a+b*x))
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^9//2, x) == :(6//5*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+-2//5*b^-1*sin(2a+2*b*x)^3//2*cos(2a+2*b*x)+-2//7*b^-1*sin(2a+2*b*x)^7//2*cos(2a+2*b*x)+1//7*b^-1*csc(a+b*x)^2*sin(2a+2*b*x)^11//2)
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^7//2, x) == :(2//3*b^-1*Elliptic.F(a+-1//4*pi+b*x,2)+-2//3*b^-1*sin(2a+2*b*x)^(1/2)*cos(2a+2*b*x)+-2//5*b^-1*sin(2a+2*b*x)^5//2*cos(2a+2*b*x)+1//5*b^-1*csc(a+b*x)^2*sin(2a+2*b*x)^9//2)
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^5//2, x) == :(2*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+-2//3*b^-1*sin(2a+2*b*x)^3//2*cos(2a+2*b*x)+1//3*b^-1*csc(a+b*x)^2*sin(2a+2*b*x)^7//2)
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^3//2, x) == :(2*b^-1*Elliptic.F(a+-1//4*pi+b*x,2)+b^-1*csc(a+b*x)^2*sin(2a+2*b*x)^5//2+-2*b^-1*sin(2a+2*b*x)^(1/2)*cos(2a+2*b*x))
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^(1/2), x) == :(-2*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+-1*b^-1*csc(a+b*x)^2*sin(2a+2*b*x)^3//2)
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^-1//2, x) == :(2//3*b^-1*Elliptic.F(a+-1//4*pi+b*x,2)+-1//3*b^-1*csc(a+b*x)^2*sin(2a+2*b*x)^(1/2))
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^-3//2, x) == :(-6//5*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+-6//5*b^-1*sin(2a+2*b*x)^-1//2*cos(2a+2*b*x)+-1//5*b^-1*csc(a+b*x)^2*sin(2a+2*b*x)^-1//2)
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^-5//2, x) == :(10//21*b^-1*Elliptic.F(a+-1//4*pi+b*x,2)+-10//21*b^-1*sin(2a+2*b*x)^-3//2*cos(2a+2*b*x)+-1//7*b^-1*csc(a+b*x)^2*sin(2a+2*b*x)^-3//2)
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^-7//2, x) == :(-14//15*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+-14//15*b^-1*sin(2a+2*b*x)^-1//2*cos(2a+2*b*x)+-14//45*b^-1*sin(2a+2*b*x)^-5//2*cos(2a+2*b*x)+-1//9*b^-1*csc(a+b*x)^2*sin(2a+2*b*x)^-5//2)
@test integrate(csc(a+b*x)^2*sin(2a+2*b*x)^-9//2, x) == :(30//77*b^-1*Elliptic.F(a+-1//4*pi+b*x,2)+-30//77*b^-1*sin(2a+2*b*x)^-3//2*cos(2a+2*b*x)+-18//77*b^-1*sin(2a+2*b*x)^-7//2*cos(2a+2*b*x)+-1//11*b^-1*csc(a+b*x)^2*sin(2a+2*b*x)^-7//2)
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^9//2, x) == :(-7//8*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+7//8*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-14//15*b^-1*sin(2a+2*b*x)^5//2*cos(a+b*x)+-7//4*b^-1*sin(2a+2*b*x)^(1/2)*cos(a+b*x)+1//5*b^-1*csc(a+b*x)^3*sin(2a+2*b*x)^11//2+4//5*b^-1*sin(2a+2*b*x)^7//2*sin(a+b*x)+7//6*b^-1*sin(2a+2*b*x)^3//2*sin(a+b*x))
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^7//2, x) == :(-5//4*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+-5//4*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-5//3*b^-1*sin(2a+2*b*x)^3//2*cos(a+b*x)+1//3*b^-1*csc(a+b*x)^3*sin(2a+2*b*x)^9//2+4//3*b^-1*sin(2a+2*b*x)^5//2*sin(a+b*x)+5//2*b^-1*sin(2a+2*b*x)^(1/2)*sin(a+b*x))
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^5//2, x) == :(-3*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+3*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+b^-1*csc(a+b*x)^3*sin(2a+2*b*x)^7//2+-6*b^-1*sin(2a+2*b*x)^(1/2)*cos(a+b*x)+4*b^-1*sin(2a+2*b*x)^3//2*sin(a+b*x))
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^3//2, x) == :(2*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+2*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-1*b^-1*csc(a+b*x)^3*sin(2a+2*b*x)^5//2+-4*b^-1*sin(2a+2*b*x)^(1/2)*sin(a+b*x))
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^(1/2), x) == :(-1//3*b^-1*csc(a+b*x)^3*sin(2a+2*b*x)^3//2)
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^-1//2, x) == :(-4//5*b^-1*sin(2a+2*b*x)^(1/2)*csc(a+b*x)+-1//5*b^-1*csc(a+b*x)^3*sin(2a+2*b*x)^(1/2))
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^-3//2, x) == :(-16//21*b^-1*sin(2a+2*b*x)^-3//2*cos(a+b*x)+-1//7*b^-1*csc(a+b*x)^3*sin(2a+2*b*x)^-1//2+32//21*b^-1*sin(2a+2*b*x)^-1//2*sin(a+b*x))
@test integrate(csc(a+b*x)^3*sin(2a+2*b*x)^-5//2, x) == :(-64//45*b^-1*sin(2a+2*b*x)^-1//2*cos(a+b*x)+-8//15*b^-1*sin(2a+2*b*x)^-5//2*cos(a+b*x)+-1//9*b^-1*csc(a+b*x)^3*sin(2a+2*b*x)^-3//2+32//45*b^-1*sin(2a+2*b*x)^-3//2*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^7*cos(a+b*x), x) == :(-384//13*b^-1*cos(a+b*x)^13+-128//9*b^-1*cos(a+b*x)^9+128//15*b^-1*cos(a+b*x)^15+384//11*b^-1*cos(a+b*x)^11)
@test integrate(sin(2a+2*b*x)^6*cos(a+b*x), x) == :(-64//3*b^-1*sin(a+b*x)^9+-64//13*b^-1*sin(a+b*x)^13+64//7*b^-1*sin(a+b*x)^7+192//11*b^-1*sin(a+b*x)^11)
@test integrate(sin(2a+2*b*x)^5*cos(a+b*x), x) == :(-32//7*b^-1*cos(a+b*x)^7+-32//11*b^-1*cos(a+b*x)^11+64//9*b^-1*cos(a+b*x)^9)
@test integrate(sin(2a+2*b*x)^4*cos(a+b*x), x) == :(-32//7*b^-1*sin(a+b*x)^7+16//5*b^-1*sin(a+b*x)^5+16//9*b^-1*sin(a+b*x)^9)
@test integrate(sin(2a+2*b*x)^3*cos(a+b*x), x) == :(-8//5*b^-1*cos(a+b*x)^5+8//7*b^-1*cos(a+b*x)^7)
@test integrate(sin(2a+2*b*x)^2*cos(a+b*x), x) == :(-4//5*b^-1*sin(a+b*x)^5+4//3*b^-1*sin(a+b*x)^3)
@test integrate(cos(a+b*x)*sin(2a+2*b*x), x) == :(-1//2*b^-1*cos(a+b*x)+-1//6*b^-1*cos(3a+3*b*x))
@test integrate(sin(2a+2*b*x)^-1*cos(a+b*x), x) == :(-1//2*b^-1*arctanh(cos(a+b*x)))
@test integrate(sin(2a+2*b*x)^-2*cos(a+b*x), x) == :(-1//4*b^-1*csc(a+b*x)+1//4*b^-1*arctanh(sin(a+b*x)))
@test integrate(sin(2a+2*b*x)^-3*cos(a+b*x), x) == :(-3//16*b^-1*arctanh(cos(a+b*x))+3//16*b^-1*sec(a+b*x)+-1//16*b^-1*csc(a+b*x)^2*sec(a+b*x))
@test integrate(sin(2a+2*b*x)^-4*cos(a+b*x), x) == :(-5//32*b^-1*csc(a+b*x)+-5//96*b^-1*csc(a+b*x)^3+5//32*b^-1*arctanh(sin(a+b*x))+1//32*b^-1*csc(a+b*x)^3*sec(a+b*x)^2)
@test integrate(sin(2a+2*b*x)^-5*cos(a+b*x), x) == :(-35//256*b^-1*arctanh(cos(a+b*x))+35//256*b^-1*sec(a+b*x)+35//768*b^-1*sec(a+b*x)^3+-7//256*b^-1*csc(a+b*x)^2*sec(a+b*x)^3+-1//128*b^-1*csc(a+b*x)^4*sec(a+b*x)^3)
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^5, x) == :(-4*b^-1*cos(a+b*x)^8+-8//3*b^-1*cos(a+b*x)^12+32//5*b^-1*cos(a+b*x)^10)
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^4, x) == :(3//16*x+1//20*b^-1*sin(2a+2*b*x)^5+-3//32*b^-1*cos(2a+2*b*x)*sin(2a+2*b*x)+-1//16*b^-1*sin(2a+2*b*x)^3*cos(2a+2*b*x))
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^3, x) == :(b^-1*cos(a+b*x)^8+-4//3*b^-1*cos(a+b*x)^6)
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^2, x) == :(1//4*x+1//12*b^-1*sin(2a+2*b*x)^3+-1//8*b^-1*cos(2a+2*b*x)*sin(2a+2*b*x))
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x), x) == :(-1//2*b^-1*cos(a+b*x)^4)
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^-1, x) == :((1/2)*b^-1*log(sin(a+b*x)))
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^-2, x) == :(-1//4*b^-1*cot(a+b*x))
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^-3, x) == :(-1//16*b^-1*cot(a+b*x)^2+1//8*b^-1*log(tan(a+b*x)))
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^-4, x) == :(-1//8*b^-1*cot(a+b*x)+-1//48*b^-1*cot(a+b*x)^3+1//16*b^-1*tan(a+b*x))
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^-5, x) == :(-3//64*b^-1*cot(a+b*x)^2+-1//128*b^-1*cot(a+b*x)^4+1//64*b^-1*tan(a+b*x)^2+3//32*b^-1*log(tan(a+b*x)))
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^5, x) == :(-32//9*b^-1*cos(a+b*x)^9+-32//13*b^-1*cos(a+b*x)^13+64//11*b^-1*cos(a+b*x)^11)
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^4, x) == :(-48//7*b^-1*sin(a+b*x)^7+-16//11*b^-1*sin(a+b*x)^11+16//3*b^-1*sin(a+b*x)^9+16//5*b^-1*sin(a+b*x)^5)
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^3, x) == :(-8//7*b^-1*cos(a+b*x)^7+8//9*b^-1*cos(a+b*x)^9)
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^2, x) == :(-8//5*b^-1*sin(a+b*x)^5+4//3*b^-1*sin(a+b*x)^3+4//7*b^-1*sin(a+b*x)^7)
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x), x) == :(-2//5*b^-1*cos(a+b*x)^5)
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^-1, x) == :((1/2)*b^-1*cos(a+b*x)+-1//2*b^-1*arctanh(cos(a+b*x)))
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^-2, x) == :(-1//4*b^-1*csc(a+b*x))
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^-3, x) == :(-1//16*b^-1*arctanh(cos(a+b*x))+-1//16*b^-1*cot(a+b*x)*csc(a+b*x))
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^-4, x) == :(-1//16*b^-1*csc(a+b*x)+-1//48*b^-1*csc(a+b*x)^3+1//16*b^-1*arctanh(sin(a+b*x)))
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^-5, x) == :(-15//256*b^-1*arctanh(cos(a+b*x))+15//256*b^-1*sec(a+b*x)+-5//256*b^-1*csc(a+b*x)^2*sec(a+b*x)+-1//128*b^-1*csc(a+b*x)^4*sec(a+b*x))
@test integrate(sin(2a+2*b*x)^5//2*cos(a+b*x), x) == :(-5//32*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+-5//32*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-5//24*b^-1*sin(2a+2*b*x)^3//2*cos(a+b*x)+1//6*b^-1*sin(2a+2*b*x)^5//2*sin(a+b*x)+5//16*b^-1*sin(2a+2*b*x)^(1/2)*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^3//2*cos(a+b*x), x) == :(-3//16*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+3//16*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-3//8*b^-1*sin(2a+2*b*x)^(1/2)*cos(a+b*x)+1//4*b^-1*sin(2a+2*b*x)^3//2*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^(1/2)*cos(a+b*x), x) == :(-1//4*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+-1//4*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+(1/2)*b^-1*sin(2a+2*b*x)^(1/2)*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^-1//2*cos(a+b*x), x) == :((1/2)*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-1//2*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x)))
@test integrate(sin(2a+2*b*x)^-3//2*cos(a+b*x), x) == :(-1*b^-1*sin(2a+2*b*x)^-1//2*cos(a+b*x))
@test integrate(sin(2a+2*b*x)^-5//2*cos(a+b*x), x) == :(-1//3*b^-1*sin(2a+2*b*x)^-3//2*cos(a+b*x)+2//3*b^-1*sin(2a+2*b*x)^-1//2*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^-7//2*cos(a+b*x), x) == :(-8//15*b^-1*sin(2a+2*b*x)^-1//2*cos(a+b*x)+-1//5*b^-1*sin(2a+2*b*x)^-5//2*cos(a+b*x)+4//15*b^-1*sin(2a+2*b*x)^-3//2*sin(a+b*x))
@test integrate(sin(2a+2*b*x)^-9//2*cos(a+b*x), x) == :(-8//35*b^-1*sin(2a+2*b*x)^-3//2*cos(a+b*x)+-1//7*b^-1*sin(2a+2*b*x)^-7//2*cos(a+b*x)+6//35*b^-1*sin(2a+2*b*x)^-5//2*sin(a+b*x)+16//35*b^-1*sin(2a+2*b*x)^-1//2*sin(a+b*x))
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^7//2, x) == :(1//18*b^-1*sin(2a+2*b*x)^9//2+5//42*b^-1*Elliptic.F(a+-1//4*pi+b*x,2)+-5//42*b^-1*sin(2a+2*b*x)^(1/2)*cos(2a+2*b*x)+-1//14*b^-1*sin(2a+2*b*x)^5//2*cos(2a+2*b*x))
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^5//2, x) == :(1//14*b^-1*sin(2a+2*b*x)^7//2+3//10*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+-1//10*b^-1*sin(2a+2*b*x)^3//2*cos(2a+2*b*x))
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^3//2, x) == :(1//6*b^-1*Elliptic.F(a+-1//4*pi+b*x,2)+1//10*b^-1*sin(2a+2*b*x)^5//2+-1//6*b^-1*sin(2a+2*b*x)^(1/2)*cos(2a+2*b*x))
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^(1/2), x) == :((1/2)*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+1//6*b^-1*sin(2a+2*b*x)^3//2)
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^-1//2, x) == :((1/2)*b^-1*sin(2a+2*b*x)^(1/2)+(1/2)*b^-1*Elliptic.F(a+-1//4*pi+b*x,2))
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^-3//2, x) == :(-1//2*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+-1*b^-1*cos(a+b*x)^2*sin(2a+2*b*x)^-1//2)
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^-5//2, x) == :(1//6*b^-1*Elliptic.F(a+-1//4*pi+b*x,2)+-1//3*b^-1*cos(a+b*x)^2*sin(2a+2*b*x)^-3//2)
@test integrate(cos(a+b*x)^2*sin(2a+2*b*x)^-7//2, x) == :(-3//10*b^-1*Elliptic.E(a+-1//4*pi+b*x,2)+-3//10*b^-1*sin(2a+2*b*x)^-1//2*cos(2a+2*b*x)+-1//5*b^-1*cos(a+b*x)^2*sin(2a+2*b*x)^-5//2)
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^3//2, x) == :(-7//64*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+7//64*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-7//32*b^-1*sin(2a+2*b*x)^(1/2)*cos(a+b*x)+1//12*b^-1*sin(2a+2*b*x)^5//2*cos(a+b*x)+7//48*b^-1*sin(2a+2*b*x)^3//2*sin(a+b*x))
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^(1/2), x) == :(-5//32*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+-5//32*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+1//8*b^-1*sin(2a+2*b*x)^3//2*cos(a+b*x)+5//16*b^-1*sin(2a+2*b*x)^(1/2)*sin(a+b*x))
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^-1//2, x) == :(-3//8*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+3//8*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+1//4*b^-1*sin(2a+2*b*x)^(1/2)*cos(a+b*x))
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^-3//2, x) == :(1//4*b^-1*arcsin(-1*sin(a+b*x)+cos(a+b*x))+1//4*b^-1*log(sin(2a+2*b*x)^(1/2)+cos(a+b*x)+sin(a+b*x))+-1*b^-1*sin(2a+2*b*x)^-1//2*cos(a+b*x))
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^-5//2, x) == :(-1//3*b^-1*cos(a+b*x)^3*sin(2a+2*b*x)^-3//2)
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^-7//2, x) == :(-1//5*b^-1*cos(a+b*x)^3*sin(2a+2*b*x)^-5//2+-1//5*b^-1*sin(2a+2*b*x)^-1//2*cos(a+b*x))
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^-9//2, x) == :(-2//21*b^-1*sin(2a+2*b*x)^-3//2*cos(a+b*x)+-1//7*b^-1*cos(a+b*x)^3*sin(2a+2*b*x)^-7//2+4//21*b^-1*sin(2a+2*b*x)^-1//2*sin(a+b*x))
@test integrate(cos(a+b*x)^3*sin(2a+2*b*x)^-11//2, x) == :(-8//45*b^-1*sin(2a+2*b*x)^-1//2*cos(a+b*x)+-1//9*b^-1*cos(a+b*x)^3*sin(2a+2*b*x)^-9//2+-1//15*b^-1*sin(2a+2*b*x)^-5//2*cos(a+b*x)+4//45*b^-1*sin(2a+2*b*x)^-3//2*sin(a+b*x))
@test integrate(sin(2x)^-1//2*cos(x), x) == :((1/2)*log(sin(2x)^(1/2)+cos(x)+sin(x))+-1//2*arcsin(-1*sin(x)+cos(x)))
@test integrate(sin(2x)^(1/2)*csc(x), x) == :(-1*arcsin(-1*sin(x)+cos(x))+log(sin(2x)^(1/2)+cos(x)+sin(x)))
@test integrate(cos(a+b*x)^2*sin(a+b*x)^3*sin(2a+2*b*x)^2, x) == :(-4//5*b^-1*cos(a+b*x)^5+-4//9*b^-1*cos(a+b*x)^9+8//7*b^-1*cos(a+b*x)^7)
@test integrate(sin(c+d*x)^3*sin(a+b*x), x) == :((8b+24d)^-1*sin(a+3c+x*(b+3d))+-1*(-24d+8b)^-1*sin(a+-3c+x*(b+-3d))+-3*(8b+8d)^-1*sin(a+c+x*(b+d))+3*(-8d+8b)^-1*sin(a+-1c+x*(b+-1d)))
@test integrate(sin(c+d*x)^2*sin(a+b*x), x) == :((-8d+4b)^-1*cos(a+-2c+x*(b+-2d))+(4b+8d)^-1*cos(a+2c+x*(b+2d))+-1//2*b^-1*cos(a+b*x))
@test integrate(sin(a+b*x)*sin(c+d*x), x) == :((-2d+2b)^-1*sin(a+-1c+x*(b+-1d))+-1*(2b+2d)^-1*sin(a+c+x*(b+d)))
@test integrate(csc(c+b*x)*sin(a+b*x), x) == :(x*cos(a+-1c)+b^-1*log(sin(c+b*x))*sin(a+-1c))
@test integrate(csc(c+b*x)^2*sin(a+b*x), x) == :(-1*b^-1*arctanh(cos(c+b*x))*cos(a+-1c)+-1*b^-1*csc(c+b*x)*sin(a+-1c))
@test integrate(csc(c+b*x)^3*sin(a+b*x), x) == :(-1*b^-1*cos(a+-1c)*cot(c+b*x)+-1//2*b^-1*csc(c+b*x)^2*sin(a+-1c))
@test integrate(csc(c+b*x)^4*sin(a+b*x), x) == :(-1//2*b^-1*arctanh(cos(c+b*x))*cos(a+-1c)+-1//3*b^-1*csc(c+b*x)^3*sin(a+-1c)+-1//2*b^-1*cos(a+-1c)*cot(c+b*x)*csc(c+b*x))
@test integrate(csc(c+b*x)^5*sin(a+b*x), x) == :(-1*b^-1*cos(a+-1c)*cot(c+b*x)+-1//3*b^-1*cot(c+b*x)^3*cos(a+-1c)+-1//4*b^-1*csc(c+b*x)^4*sin(a+-1c))
@test integrate(csc(c+b*x)^6*sin(a+b*x), x) == :(-3//8*b^-1*arctanh(cos(c+b*x))*cos(a+-1c)+-1//5*b^-1*csc(c+b*x)^5*sin(a+-1c)+-3//8*b^-1*cos(a+-1c)*cot(c+b*x)*csc(c+b*x)+-1//4*b^-1*csc(c+b*x)^3*cos(a+-1c)*cot(c+b*x))
@test integrate(sin(a+b*x)^2*sin(c+d*x), x) == :((4d+8b)^-1*cos(c+2a+x*(d+2b))+-1*(-4d+8b)^-1*cos(-1c+2a+x*(-1d+2b))+-1//2*d^-1*cos(c+d*x))
@test integrate(sin(a+b*x)^2*sin(c+d*x)^2, x) == :(1//4*x+(-16d+16b)^-1*sin(-2c+2a+x*(-2d+2b))+(16b+16d)^-1*sin(2a+2c+x*(2b+2d))+-1//8*b^-1*sin(2a+2*b*x)+-1//8*d^-1*sin(2c+2*d*x))
@test integrate(sin(a+b*x)^2*sin(c+d*x)^3, x) == :((-48d+32b)^-1*cos(-3c+2a+x*(-3d+2b))+-1*(32b+48d)^-1*cos(2a+3c+x*(2b+3d))+-3*(-16d+32b)^-1*cos(-1c+2a+x*(-1d+2b))+3*(16d+32b)^-1*cos(c+2a+x*(d+2b))+-3//8*d^-1*cos(c+d*x)+1//24*d^-1*cos(3c+3*d*x))
@test integrate(sin(a+b*x)^3*sin(c+d*x), x) == :((8d+24b)^-1*sin(c+3a+x*(d+3b))+-1*(-8d+24b)^-1*sin(-1c+3a+x*(-1d+3b))+-3*(8b+8d)^-1*sin(a+c+x*(b+d))+3*(-8d+8b)^-1*sin(a+-1c+x*(b+-1d)))
@test integrate(sin(a+b*x)^3*sin(c+d*x)^2, x) == :(-1*(-32d+48b)^-1*cos(-2c+3a+x*(-2d+3b))+-1*(32d+48b)^-1*cos(2c+3a+x*(2d+3b))+3*(-32d+16b)^-1*cos(a+-2c+x*(b+-2d))+3*(16b+32d)^-1*cos(a+2c+x*(b+2d))+-3//8*b^-1*cos(a+b*x)+1//24*b^-1*cos(3a+3*b*x))
@test integrate(sin(a+b*x)^3*sin(c+d*x)^3, x) == :((-96d+96b)^-1*sin(-3c+3a+x*(-3d+3b))+-1*(96b+96d)^-1*sin(3a+3c+x*(3b+3d))+-9*(32b+32d)^-1*sin(a+c+x*(b+d))+-3*(-96d+32b)^-1*sin(a+-3c+x*(b+-3d))+-3*(-32d+96b)^-1*sin(-1c+3a+x*(-1d+3b))+3*(32b+96d)^-1*sin(a+3c+x*(b+3d))+3*(32d+96b)^-1*sin(c+3a+x*(d+3b))+9*(-32d+32b)^-1*sin(a+-1c+x*(b+-1d)))
@test integrate(cos(c+d*x)^3*sin(a+b*x), x) == :(-1*(-24d+8b)^-1*cos(a+-3c+x*(b+-3d))+-1*(8b+24d)^-1*cos(a+3c+x*(b+3d))+-3*(-8d+8b)^-1*cos(a+-1c+x*(b+-1d))+-3*(8b+8d)^-1*cos(a+c+x*(b+d)))
@test integrate(cos(c+d*x)^2*sin(a+b*x), x) == :(-1*(-8d+4b)^-1*cos(a+-2c+x*(b+-2d))+-1*(4b+8d)^-1*cos(a+2c+x*(b+2d))+-1//2*b^-1*cos(a+b*x))
@test integrate(cos(c+d*x)*sin(a+b*x), x) == :(-1*(-2d+2b)^-1*cos(a+-1c+x*(b+-1d))+-1*(2b+2d)^-1*cos(a+c+x*(b+d)))
@test integrate(sec(c+b*x)*sin(a+b*x), x) == :(x*sin(a+-1c)+-1*b^-1*cos(a+-1c)*log(cos(c+b*x)))
@test integrate(sec(c+b*x)^2*sin(a+b*x), x) == :(b^-1*arctanh(sin(c+b*x))*sin(a+-1c)+b^-1*cos(a+-1c)*sec(c+b*x))
@test integrate(sec(c+b*x)^3*sin(a+b*x), x) == :(b^-1*sin(a+-1c)*tan(c+b*x)+(1/2)*b^-1*sec(c+b*x)^2*cos(a+-1c))
@test integrate(sec(c+b*x)^4*sin(a+b*x), x) == :((1/2)*b^-1*arctanh(sin(c+b*x))*sin(a+-1c)+1//3*b^-1*sec(c+b*x)^3*cos(a+-1c)+(1/2)*b^-1*sec(c+b*x)*sin(a+-1c)*tan(c+b*x))
@test integrate(sec(c+b*x)^5*sin(a+b*x), x) == :(b^-1*sin(a+-1c)*tan(c+b*x)+1//3*b^-1*tan(c+b*x)^3*sin(a+-1c)+1//4*b^-1*sec(c+b*x)^4*cos(a+-1c))
@test integrate(sec(c+b*x)^6*sin(a+b*x), x) == :(1//5*b^-1*sec(c+b*x)^5*cos(a+-1c)+3//8*b^-1*arctanh(sin(c+b*x))*sin(a+-1c)+1//4*b^-1*sec(c+b*x)^3*sin(a+-1c)*tan(c+b*x)+3//8*b^-1*sec(c+b*x)*sin(a+-1c)*tan(c+b*x))
@test integrate(sin(a+b*x)^2*cos(c+d*x), x) == :((1/2)*d^-1*sin(c+d*x)+-1*(-4d+8b)^-1*sin(-1c+2a+x*(-1d+2b))+-1*(4d+8b)^-1*sin(c+2a+x*(d+2b)))
@test integrate(cos(c+d*x)^2*sin(a+b*x)^2, x) == :(1//4*x+-1*(-16d+16b)^-1*sin(-2c+2a+x*(-2d+2b))+-1*(16b+16d)^-1*sin(2a+2c+x*(2b+2d))+-1//8*b^-1*sin(2a+2*b*x)+1//8*d^-1*sin(2c+2*d*x))
@test integrate(cos(c+d*x)^3*sin(a+b*x)^2, x) == :(-1*(-48d+32b)^-1*sin(-3c+2a+x*(-3d+2b))+-1*(32b+48d)^-1*sin(2a+3c+x*(2b+3d))+-3*(-16d+32b)^-1*sin(-1c+2a+x*(-1d+2b))+-3*(16d+32b)^-1*sin(c+2a+x*(d+2b))+1//24*d^-1*sin(3c+3*d*x)+3//8*d^-1*sin(c+d*x))
@test integrate(sin(a+b*x)^3*cos(c+d*x), x) == :((-8d+24b)^-1*cos(-1c+3a+x*(-1d+3b))+(8d+24b)^-1*cos(c+3a+x*(d+3b))+-3*(-8d+8b)^-1*cos(a+-1c+x*(b+-1d))+-3*(8b+8d)^-1*cos(a+c+x*(b+d)))
@test integrate(cos(c+d*x)^2*sin(a+b*x)^3, x) == :((-32d+48b)^-1*cos(-2c+3a+x*(-2d+3b))+(32d+48b)^-1*cos(2c+3a+x*(2d+3b))+-3*(-32d+16b)^-1*cos(a+-2c+x*(b+-2d))+-3*(16b+32d)^-1*cos(a+2c+x*(b+2d))+-3//8*b^-1*cos(a+b*x)+1//24*b^-1*cos(3a+3*b*x))
@test integrate(cos(c+d*x)^3*sin(a+b*x)^3, x) == :((-96d+96b)^-1*cos(-3c+3a+x*(-3d+3b))+(96b+96d)^-1*cos(3a+3c+x*(3b+3d))+-9*(-32d+32b)^-1*cos(a+-1c+x*(b+-1d))+-9*(32b+32d)^-1*cos(a+c+x*(b+d))+-3*(-96d+32b)^-1*cos(a+-3c+x*(b+-3d))+-3*(32b+96d)^-1*cos(a+3c+x*(b+3d))+3*(-32d+96b)^-1*cos(-1c+3a+x*(-1d+3b))+3*(32d+96b)^-1*cos(c+3a+x*(d+3b)))
@test integrate(sin(c+b*x)^-1*cos(a+b*x), x) == :(-1*x*sin(a+-1c)+b^-1*cos(a+-1c)*log(sin(c+b*x)))
@test integrate(sin(c+b*x)^-2*cos(a+b*x), x) == :(b^-1*arctanh(cos(c+b*x))*sin(a+-1c)+-1*b^-1*cos(a+-1c)*csc(c+b*x))
@test integrate(sin(c+b*x)^-3*cos(a+b*x), x) == :(b^-1*cot(c+b*x)*sin(a+-1c)+-1//2*b^-1*csc(c+b*x)^2*cos(a+-1c))
@test integrate(tan(c+b*x)^3*sin(a+b*x), x) == :(b^-1*sin(a+b*x)+b^-1*sec(c+b*x)*sin(a+-1c)+-3//2*b^-1*arctanh(sin(c+b*x))*cos(a+-1c)+(1/2)*b^-1*cos(a+-1c)*sec(c+b*x)*tan(c+b*x))
@test integrate(tan(c+b*x)^2*sin(a+b*x), x) == :(b^-1*cos(a+b*x)+b^-1*arctanh(sin(c+b*x))*sin(a+-1c)+b^-1*cos(a+-1c)*sec(c+b*x))
@test integrate(sin(a+b*x)*tan(c+b*x), x) == :(-1*b^-1*sin(a+b*x)+b^-1*arctanh(sin(c+b*x))*cos(a+-1c))
@test integrate(cot(c+b*x)*sin(a+b*x), x) == :(b^-1*sin(a+b*x)+-1*b^-1*arctanh(cos(c+b*x))*sin(a+-1c))
@test integrate(cot(c+b*x)^2*sin(a+b*x), x) == :(b^-1*cos(a+b*x)+-1*b^-1*arctanh(cos(c+b*x))*cos(a+-1c)+-1*b^-1*csc(c+b*x)*sin(a+-1c))
@test integrate(cot(c+b*x)^3*sin(a+b*x), x) == :(-1*b^-1*sin(a+b*x)+-1*b^-1*cos(a+-1c)*csc(c+b*x)+3//2*b^-1*arctanh(cos(c+b*x))*sin(a+-1c)+-1//2*b^-1*cot(c+b*x)*csc(c+b*x)*sin(a+-1c))
@test integrate(cos(c+d*x)^3*cos(a+b*x), x) == :((-24d+8b)^-1*sin(a+-3c+x*(b+-3d))+(8b+24d)^-1*sin(a+3c+x*(b+3d))+3*(-8d+8b)^-1*sin(a+-1c+x*(b+-1d))+3*(8b+8d)^-1*sin(a+c+x*(b+d)))
@test integrate(cos(c+d*x)^2*cos(a+b*x), x) == :((-8d+4b)^-1*sin(a+-2c+x*(b+-2d))+(4b+8d)^-1*sin(a+2c+x*(b+2d))+(1/2)*b^-1*sin(a+b*x))
@test integrate(cos(a+b*x)*cos(c+d*x), x) == :((-2d+2b)^-1*sin(a+-1c+x*(b+-1d))+(2b+2d)^-1*sin(a+c+x*(b+d)))
@test integrate(cos(a+b*x)*sec(c+b*x), x) == :(x*cos(a+-1c)+b^-1*log(cos(c+b*x))*sin(a+-1c))
@test integrate(sec(c+b*x)^2*cos(a+b*x), x) == :(b^-1*arctanh(sin(c+b*x))*cos(a+-1c)+-1*b^-1*sec(c+b*x)*sin(a+-1c))
@test integrate(sec(c+b*x)^3*cos(a+b*x), x) == :(b^-1*cos(a+-1c)*tan(c+b*x)+-1//2*b^-1*sec(c+b*x)^2*sin(a+-1c))
@test integrate(cos(a+b*x)^2*cos(c+d*x)^3, x) == :((-48d+32b)^-1*sin(-3c+2a+x*(-3d+2b))+(32b+48d)^-1*sin(2a+3c+x*(2b+3d))+3*(-16d+32b)^-1*sin(-1c+2a+x*(-1d+2b))+3*(16d+32b)^-1*sin(c+2a+x*(d+2b))+1//24*d^-1*sin(3c+3*d*x)+3//8*d^-1*sin(c+d*x))
@test integrate(cos(a+b*x)^2*cos(c+d*x)^2, x) == :(1//4*x+(-16d+16b)^-1*sin(-2c+2a+x*(-2d+2b))+(16b+16d)^-1*sin(2a+2c+x*(2b+2d))+1//8*b^-1*sin(2a+2*b*x)+1//8*d^-1*sin(2c+2*d*x))
@test integrate(cos(a+b*x)^3*cos(c+d*x)^3, x) == :((-96d+96b)^-1*sin(-3c+3a+x*(-3d+3b))+(96b+96d)^-1*sin(3a+3c+x*(3b+3d))+3*(-96d+32b)^-1*sin(a+-3c+x*(b+-3d))+3*(-32d+96b)^-1*sin(-1c+3a+x*(-1d+3b))+3*(32b+96d)^-1*sin(a+3c+x*(b+3d))+3*(32d+96b)^-1*sin(c+3a+x*(d+3b))+9*(-32d+32b)^-1*sin(a+-1c+x*(b+-1d))+9*(32b+32d)^-1*sin(a+c+x*(b+d)))
@test integrate(tan(c+b*x)^3*cos(a+b*x), x) == :(b^-1*cos(a+b*x)+b^-1*cos(a+-1c)*sec(c+b*x)+3//2*b^-1*arctanh(sin(c+b*x))*sin(a+-1c)+-1//2*b^-1*sec(c+b*x)*sin(a+-1c)*tan(c+b*x))
@test integrate(tan(c+b*x)^2*cos(a+b*x), x) == :(-1*b^-1*sin(a+b*x)+b^-1*arctanh(sin(c+b*x))*cos(a+-1c)+-1*b^-1*sec(c+b*x)*sin(a+-1c))
@test integrate(cos(a+b*x)*tan(c+b*x), x) == :(-1*b^-1*cos(a+b*x)+-1*b^-1*arctanh(sin(c+b*x))*sin(a+-1c))
@test integrate(cos(a+b*x)*cot(c+b*x), x) == :(b^-1*cos(a+b*x)+-1*b^-1*arctanh(cos(c+b*x))*cos(a+-1c))
@test integrate(cot(c+b*x)^2*cos(a+b*x), x) == :(-1*b^-1*sin(a+b*x)+b^-1*arctanh(cos(c+b*x))*sin(a+-1c)+-1*b^-1*cos(a+-1c)*csc(c+b*x))
@test integrate(cot(c+b*x)^3*cos(a+b*x), x) == :(-1*b^-1*cos(a+b*x)+b^-1*csc(c+b*x)*sin(a+-1c)+3//2*b^-1*arctanh(cos(c+b*x))*cos(a+-1c)+-1//2*b^-1*cos(a+-1c)*cot(c+b*x)*csc(c+b*x))

max_stars_repo_path: test/4 Trig functions/4.7 Miscellaneous/4.7.1 (c trig)^m (d trig)^n.jl


text:
mutable struct Board
    values::Array{Int}
    marked::BitArray
    #marked = iszero.(zeros((5,5)))
end

function step(instruction, board)
    for (coord, val) in enumerate(board.values)
        if val == instruction
            board.marked[coord] = true
        end
    end
end

function check(board)
    for row in eachrow(board.marked)
        if all(row .== true)
            return true
        end
    end
    for col in eachcol(board.marked)
        if all(col .== true)
            return true
        end
    end
    return false
end

function computeScore(board, instruction)
    score = 0
    for (coord, val) in enumerate(board.values)
        if board.marked[coord] == false
            score += val
        end
    end
    println("sum: "*string(score))
    println("instruction: "*string(instruction))
    return score * instruction
end

function solve(filename)
    #load txt file
    values = readlines(filename*".txt")
    #first line is instructions
    instructions = values[1]
    instructions = split(instructions,',')
    instructions = parse.(Int, instructions)
    #next line is empty -> board from line 3-7
    start = 3
    stop = 7
    boards = Board[]
    while stop <= length(values)
        boardstring = values[start:stop]
        intboard = fill(0, (5,5))
        i = 1
        for row in boardstring
            row = split(row, ' ')
            row = filter(!isempty, row)
            introw = parse.(Int, row)
            for (j, val) in enumerate(introw)
                intboard[i,j] = val
            end
            i += 1
        end
        marked = iszero.(ones((5,5)))
        board = Board(copy(intboard), copy(marked))
        boards = push!(boards, board)
        start += 6
        stop += 6
    end
    score = nothing
    for ins in instructions
        for b in boards
            step(ins, b)
            if check(b) == true
                score = computeScore(b, ins)
                println("Winning score: "*string(score))
                break
            end
        end
        if !isnothing(score)
            break
        end
    end

end

solve("input")
solve("smalltest")

function solve2(filename)
    #load txt file
    values = readlines(filename*".txt")
    #first line is instructions
    instructions = values[1]
    instructions = split(instructions,',')
    instructions = parse.(Int, instructions)
    #next line is empty -> board from line 3-7
    start = 3
    stop = 7
    boards = Board[]
    while stop <= length(values)
        boardstring = values[start:stop]
        intboard = fill(0, (5,5))
        i = 1
        for row in boardstring
            row = split(row, ' ')
            row = filter(!isempty, row)
            introw = parse.(Int, row)
            for (j, val) in enumerate(introw)
                intboard[i,j] = val
            end
            i += 1
        end
        marked = iszero.(ones((5,5)))
        board = Board(copy(intboard), copy(marked))
        boards = push!(boards, board)
        start += 6
        stop += 6
    end
    scores = Int[]
    winningboards = Board[]
    score = nothing
    boardsMarked = zeros(length(boards))
    for ins in instructions
        for (j,b) in enumerate(boards)
            if boardsMarked[j] == 0
                step(ins, b)
                if check(b) == true
                    score = computeScore(b, ins)
                    winningboards = push!(winningboards, b)
                    scores = push!(scores, score)
                    boardsMarked[j] = 1
                end
            end
        end
    end
    println("Winning score: "*string(score))
    println("All scores: ")
    println(scores)
end

solve2("smalltest")
solve2("input")

ext: jl


text:
using Pkg
Pkg.add(url="https://github.com/lorenzifrancesco/soliton-BEC")
Pkg.checkout("SolitonBEC", "transmission-exploration")
Pkg.activate("SolitonBEC")

max_stars_repo_name: lorenzifrancesco/soliton-BEC

max_issues_repo_name: lorenzifrancesco/soliton-BEC

max_forks_repo_name: lorenzifrancesco/soliton-BEC


text:
using DelimitedFiles
using RollingFunctions

input = joinpath(@__DIR__, "input")
entries = readdlm(input, Int)

function depth(entries)
    return length(filter(n -> n > 0, diff(entries)))
end

p1 = depth(vec(entries))
p2 = depth(rolling(sum, vec(entries), 3))

println("-----------------------------------------------------------------------")
println("sonar sweep -- part one :: $p1")
println("sonar sweep -- part two :: $p2")
println("-----------------------------------------------------------------------")

@assert(p1 == 1154)
@assert(p2 == 1127)


text:
"""
    horner(coefficients, x)

Evaluate the given polynomial at position x using the Horner scheme.

```math
p(x) = \\sum_{n=0}^N c_n x^n
```
"""
function horner(coefficients::Vector{T}, x::Number) where T<:Number
    bn = coefficients[end]
    for n=length(coefficients)-1:-1:1
        bn = coefficients[n] + bn*x
    end
    bn
end

module hermite

"""
    a_nk(N)

Calculate the all coefficients for all Hermite polynomials up to order N.

```math
H_n(x) = \\sum_{k=0}^n a_{n,k} x^k
```

Returns a vector of length N+1 where the n-th entry contains all coefficients
for the n-th Hermite polynomial.
"""
function a(N::Int)
    a = Vector{Vector{Int}}(undef, N+1)
    a[1] = [1]
    a[2] = [0,2]
    am = a[2]
    for n=2:N
        an = zeros(Int, n+1)
        a[n+1] = an
        if iseven(n)
            an[1] = -am[2]
        end
        an[n+1] = 2*am[n]
        if iseven(n)
            for k=3:2:n-1
                an[k] = 2*am[k-1] - am[k+1]*k
            end
        else
            for k=2:2:n-1
                an[k] = 2*am[k-1] - am[k+1]*k
            end
        end
        am = an
    end
    a
end

"""
    A_nk(N)

Calculate the all scaled coefficients for all Hermite polynomials up to order N.

The scaled coefficients `A` are connected to the unscaled coefficients `a` by
the relation ``A_{n,k} = \\frac{a_{n,k}}{\\sqrt{2^n n!}}``

Returns a vector of length N+1 where the n-th entry contains all scaled
coefficients for the n-th Hermite polynomial.
"""
function A(N)
    A = Vector{Vector{Float64}}(undef, N+1)
    A[1] = [1.]
    A[2] = [0., sqrt(2)]
    Am = A[2]
    for n=2:N
        An = zeros(Float64, n+1)
        A[n+1] = An
        if iseven(n)
            An[1] = -Am[2]/sqrt(2*n)
        end
        An[n+1] = Am[n]*sqrt(2/n)
        if iseven(n)
            for k=3:2:n-1
                An[k] = Am[k-1]*sqrt(2/n) - Am[k+1]*k/sqrt(2*n)
            end
        else
            for k=2:2:n-1
                An[k] = Am[k-1]*sqrt(2/n) - Am[k+1]*k/sqrt(2*n)
            end
        end
        Am = An
    end
    A
end

end # module hermite


text:
# This file contains various methods for solving the
# Kolmogorov-Forward equation in the steady state
# computation for HANK models:
# 0 = A' * g
# They can be generally classified as
# methods for well-conditioned A matrices and ill-conditioned A matrices.
# All of these methods return the stacked distribution.

function solve_kfe(A::SparseMatrixCSC{ComplexF64, Int64}, partitions::Vector{Float64},
                   dimensions::Vector{Int64})

    if size(partitions, 1) != 1 || size(dimensions, 1) != 1
        error("Need to enter partitions and/or dimensions as a 1 x n array or as a vector")
    end

    AT       = A'
    dim_prod = prod(dimensions) # Need total size of dimensions

    # Fixing one value to ensure matrix is not singular, may require further generalization later
    i_fix    = 1
    b        = zeros(dim_prod)
    b[i_fix] = .1
    for j = 1:dim_prod
        AT[i_fix,j] = 0
    end
    AT[i_fix, i_fix] = 1

    # Solve linear system for distribution
    gg    = AT \ b
    g_sum = gg'*ones(dim_prod, 1) * prod(partitions)
    gg    = gg ./ g_sum
    return vec(gg)
end

# Iterative method for ill-conditioned A
# g0: initial distribution guess provided by user
# integrate_mat: weights distribution points by some multiple of their Lebesgue measure across wealth
function solve_kfe(A::SparseMatrixCSC{ComplexF64, Int64}, g0::Matrix{Float64},
                   weight_mat::SparseMatrixCSC{Float64, Int64};
                   maxit_kfe::Int64 = 1000, tol_kfe::Float64 = 1e-12,
                   Δ_kfe::Float64 = 1e6)
    if size(weight_mat) != size(A)
        error("Dimension of weight matrix is incorrect.")
    end
    dim_size = size(A, 1)
    gg = vec(g0) # stack distribution matrix into vector

    # Solve linear system
    for ikfe = 1:maxit_kfe
        gg_tilde = weight_mat * gg # weight distribution points by their measure across wealth

        # 0 = A'g -> g = A'g + g -> (I - A')g = g, but possible singularity so perturb from zero
        # by adding g/Δ_KFE, where Δ_KFE is large => g/Δ_KFE ≈ 0. Thus,
        # g/Δ_KFE = A'*g + g/Δ_KFE => g = Δ_KFE A'*g + g
        # => (I - Δ_KFE A')g = g; could also use (I + Δ_KFE A')g = g
        gg1_tilde = (speye(ComplexF64, dim_size) - Δ_kfe * A') \ gg_tilde
        gg1_tilde = gg1_tilde ./ sum(gg1_tilde) # normalize
        gg1       = weight_mat \ gg1_tilde # undo integration over wealth

        # Check iteration for convergence
        err_kfe = maximum(abs.(gg1 - gg))
        if err_kfe < tol_kfe
            break
        end
        gg = gg1
    end

    return vec(gg)
end

# Previous function but for complex g0
function solve_kfe(A::SparseMatrixCSC{ComplexF64, Int64}, g0::Matrix{ComplexF64},
                   weight_mat::SparseMatrixCSC{Float64, Int64};
                   maxit_kfe::Int64 = 1000, tol_kfe::Float64 = 1e-12,
                   Δ_kfe::Float64 = 1e6)
    if size(weight_mat) != size(A)
        error("Dimension of weight matrix is incorrect.")
    end
    dim_size = size(A, 1)
    gg = vec(g0) # stack distribution matrix into vector

    # Solve linear system
    for ikfe = 1:maxit_kfe
        gg_tilde = weight_mat * gg # weight distribution points by their measure across wealth

        # 0 = A'g -> g = A'g + g -> (I - A')g = g, but to avoid issues with small numbers
        # we use a large scalar Delta_KFE such that
        # 0 = A' Delta_KFE g -> (I - Delta_KFE A') g = g
        gg1_tilde = (speye(ComplexF64, dim_size) - Δ_kfe * A') \ gg_tilde # Left divide
        gg1_tilde = gg1_tilde ./ sum(gg1_tilde) # normalize to one to get pdf
        gg1 = weight_mat \ gg1_tilde # undo integration over wealth

        # Check iteration for convergence
        err_kfe = maximum(abs.(gg1 - gg))
        if err_kfe < tol_kfe
            break
        end

        gg = gg1
    end

    return vec(gg)
end

# Iterative methods when weight_mat is (1) not sparse or
# (2) a dense matrix that integrates out non-wealth variables (rather than a diagonal one),
function solve_kfe(A::SparseMatrixCSC{ComplexF64, Int64}, g0::Vector{Float64},
                   weight_mat::Matrix{Float64};
                   maxit_kfe::Int64 = 1000, tol_kfe::Float64 = 1e-12,
                   Δ_kfe::Float64 = 1e6)
    if size(weight_mat) == size(A)
        return solve_kfe(A, g0, sparse(weight_mat); maxit_kfe = maxit_kfe, tol_kfe = tol_kfe, Δ_kfe = Δ_kfe)
    else
        weight_mat = spdiagm(vec(weight_mat), 0)
        return solve_kfe(A, g0, weight_mat; maxit_kfe = maxit_kfe, tol_kfe = tol_kfe, Δ_kfe = Δ_kfe)
    end
end

# Iterative method when weight_mat is a vector of differences of the wealth grid
# e.g. if x = [0 .05, .1, .15], then weight_mat = [.05, .05, .05]
function solve_kfe(A::SparseMatrixCSC{ComplexF64, Int64}, g0::Vector{Float64},
                   grid::Vector{Float64};
                   maxit_kfe::Int64 = 1000, tol_kfe::Float64 = 1e-12,
                   Δ_kfe::Float64 = 1e6)
    reps = size(A, 1) / length(grid)
    if Float64(reps) != Float64(Int64(reps))
        error("Dimension of A does not match dimensions of the grid.")
    end
    diagonal = zeros(size(A, 1))
    for i = 1:reps
        reps[1 + length(grid) * (i - 1): length(grid) * i] = grid
    end
    weight_mat = spdiagm(diagonal, 0)
    return solve_kfe(A, g0, weight_mat; maxit_kfe = maxit_kfe, tol_kfe = tol_kfe, Δ_kfe = Δ_kfe)
end

# Allows for complex g0
function solve_kfe(A::SparseMatrixCSC{ComplexF64, Int64}, g0::Vector{ComplexF64},
                   weight_mat::Matrix{Float64};
                   maxit_kfe::Int64 = 1000, tol_kfe::Float64 = 1e-12,
                   Δ_kfe::Float64 = 1e6)
    if size(weight_mat) == size(A)
        return solve_kfe(A, g0, sparse(weight_mat); maxit_kfe = maxit_kfe, tol_kfe = tol_kfe, Δ_kfe = Δ_kfe)
    else
        weight_mat = spdiagm(vec(weight_mat), 0)
        return solve_kfe(A, g0, weight_mat; maxit_kfe = maxit_kfe, tol_kfe = tol_kfe, Δ_kfe = Δ_kfe)
    end
end

function solve_kfe(A::SparseMatrixCSC{ComplexF64, Int64}, g0::Vector{ComplexF64},
                   grid::Vector{Float64};
                   maxit_kfe::Int64 = 1000, tol_kfe::Float64 = 1e-12,
                   Δ_kfe::Float64 = 1e6)
    reps = size(A, 1) / length(grid)
    if Float64(reps) != Float64(Int64(reps))
        error("Dimension of A does not match dimensions of the grid.")
    end
    diagonal = zeros(size(A, 1))
    for i = 1:reps
        reps[1 + length(grid) * (i - 1): length(grid) * i] = grid
    end
    weight_mat = spdiagm(diagonal, 0)
    return solve_kfe(A, g0, weight_mat; maxit_kfe = maxit_kfe, tol_kfe = tol_kfe, Δ_kfe = Δ_kfe)
end

# Repeats previous code when entries of A are floats.
# Exact method for well-conditioned A
function solve_kfe(A::SparseMatrixCSC{Float64, Int64}, partitions::Vector{Float64},
                   dimensions::Vector{Int64})
    AT = A'
    dim_prod = prod(dimensions)
    # Fixing one value to ensure matrix is not singular
    i_fix = 1
    b = zeros(dim_prod, 1)
    b[i_fix] = .1
    for j = 1:dim_prod
        AT[i_fix,j] = 0
    end
    AT[i_fix, i_fix] = 1

    # Solve linear system for distribution
    gg = AT \ b
    g_sum = gg'*ones(dim_prod, 1) * prod(partitions)
    gg = gg ./ g_sum
    return vec(gg)
end
function solve_kfe(A::SparseMatrixCSC{Float64, Int64}, partitions::Matrix{Float64},
                   dimensions::Matrix{Int64})
    if size(partitions, 1) != 1 || size(dimensions, 1) != 1
        error("Need to enter partitions and/or dimensions as a 1 x n array or as a vector")
    end
    AT = A'
    dim_prod = prod(dimensions)
    # Fixing one value to ensure matrix is not singular
    i_fix = 1
    b = zeros(dim_prod, 1)
    b[i_fix] = .1
    for j = 1:dim_prod
        AT[i_fix,j] = 0
    end
    AT[i_fix, i_fix] = 1

    # Solve linear system for distribution
    gg = AT \ b
    g_sum = gg'*ones(dim_prod, 1) * prod(partitions)
    gg = gg ./ g_sum
    return vec(gg)
end

# Iterative method for ill-conditioned A
function solve_kfe(A::SparseMatrixCSC{Float64, Int64}, g0::Vector{Float64},
                   weight_mat::SparseMatrixCSC{Float64, Int64};
                   maxit_kfe::Int64 = 1000, tol_kfe::Float64 = 1e-12,
                   Δ_kfe::Float64 = 1e6)
    if size(weight_mat) != size(A)
        error("Dimension of weight matrix is incorrect.")
    end
    dim_size = size(A, 1)
    gg = vec(g0) # stack distribution matrix into vector

    # Solve linear system
    for ikfe = 1:maxit_kfe
        gg_tilde = weight_mat * gg # weight distribution points by their measure across wealth

        # 0 = A'g -> g = A'g + g -> (I - A')g = g, but possible singularity so, given scalar Delta_KFE,
        # 0 = A' Delta_KFE g -> (I - Delta_KFE A') g = g
        gg1_tilde = (speye(Float64, dim_size) - Δ_kfe * A') \ gg_tilde
        gg1_tilde = gg1_tilde ./ sum(gg1_tilde) # normalize
        gg1 = weight_mat \ gg1_tilde # undo integration over wealth

        # Check iteration for convergence
        err_kfe = maximum(abs.(gg1 - gg))
        if err_kfe < tol_kfe
            break
        end

        gg = gg1
    end

    return vec(gg)
end
# Other iterative methods when weight_mat is (1) not sparse,
# (2) a matrix that integrates out non-wealth variables,
# (3) a vector of differences over the wealth grid
function solve_kfe(A::SparseMatrixCSC{Float64, Int64}, g0::Vector{Float64},
                   weight_mat::Matrix{Float64};
                   maxit_kfe::Int64 = 1000, tol_kfe::Float64 = 1e-12,
                   Δ_kfe::Float64 = 1e6)
    if size(weight_mat) == size(A)
        return solve_kfe(A, g0, sparse(weight_mat); maxit_kfe = maxit_kfe, tol_kfe = tol_kfe, Δ_kfe = Δ_kfe)
    else
        weight_mat = spdiagm(vec(weight_mat), 0)
        return solve_kfe(A, g0, weight_mat; maxit_kfe = maxit_kfe, tol_kfe = tol_kfe, Δ_kfe = Δ_kfe)
    end
end
function solve_kfe(A::SparseMatrixCSC{Float64, Int64}, g0::Vector{Float64},
                   grid::Vector{Float64};
                   maxit_kfe::Int64 = 1000, tol_kfe::Float64 = 1e-12,
                   Δ_kfe::Float64 = 1e6)
    reps = size(A, 1) / length(grid)
    if Float64(reps) != Float64(Int64(reps))
        error("Dimension of A does not match dimensions of the grid.")
    end
    diagonal = zeros(size(A, 1))
    for i = 1:reps
        reps[1 + length(grid) * (i - 1): length(grid) * i] = grid
    end
    weight_mat = spdiagm(diagonal, 0)
    return solve_kfe(A, g0, weight_mat; maxit_kfe = maxit_kfe, tol_kfe = tol_kfe, Δ_kfe = Δ_kfe)
end


text:
struct PlainTextPrinter <: FlatModelPrinter
    buf::IO
    prevctx::SGRContext
    ctx::SGRContext
    function PlainTextPrinter(buf::IO)
        new(buf, SGRContext(), SGRContext())
    end
end

"""
    PlainTextPrinter(buf::IO)

Creates a printer for `MIME"text/plain"` output.

# Arguments
- `buf`: A source `IO` object containing a text with ANSI escape codes.
"""
function PlainTextPrinter end

Base.showable(::MIME"text/plain", printer::PlainTextPrinter) = isreadable(printer.buf)

function Base.show(io::IO, ::MIME"text/plain", printer::PlainTextPrinter)
    show_body(io, printer)
end

function change_state(io::IO, printer::PlainTextPrinter, ansicodes::Vector{Int})
    get(io, :color, false) || return
    if isempty(ansicodes)
        print(io, "\e[m")
    else
        print(io, "\e[", join(ansicodes, ';'), 'm')
    end
end


text:
using Revise
import LPDM, D3Trees, LightDarkLPDM, execute2d
# execute2d.execute(solver=:lpdm)
steps = 1
# execute2d.execute(output=2, steps = steps, reward_func = :quadratic)
# execute2d.execute(vis=Int64[1], solv_mode=:lpdm, reward_func=:quadratic, action_space_type=:adaptive, output=1, steps = steps)
execute2d.execute(s0=Vec2(3/2*π,3/2*π), solver_mode = :lpdm, action_mode = :standard, obs_mode = :continuous, steps=steps, output=3)
# execute2d.execute(vis=Int64[], solv_mode=:lpdm_bv, reward_func=:quadratic, action_space_type=:bv, output=0, steps = steps)
# execute2d.execute(vis=Int64[], solv_mode=:despot, reward_func=:quadratic, action_space_type=:small, output=0, steps = steps)
# execute2d.batch_execute(n=50, debug=0, reward_func=:quadratic)
# execute2d.batch_execute(n=50, debug=0, reward_func=:quadratic)

max_stars_repo_name: ebalaban/LightDarkLPDM

max_issues_repo_name: tomerarnon/LightDarkLPDM

max_forks_repo_name: tomerarnon/LightDarkLPDM


text:
module FASTX

export
    FASTA,
    FASTQ,
    identifier,
    description,
    sequence,
    quality

# Generic methods
function identifier end
function description end
function sequence end

include("fasta/fasta.jl")
include("fastq/fastq.jl")

import .FASTA
import .FASTQ
import .FASTQ: quality

end # module


text:
module Dispersal
# Use the README as the module docs
@doc read(joinpath(dirname(@__DIR__), "README.md"), String) Dispersal

using Dates,
      Distributions,
      DocStringExtensions,
      LinearAlgebra,
      Reexport

@reexport using DynamicGrids

using DynamicGrids.ConstructionBase
using DynamicGrids.DimensionalData
using DynamicGrids.ModelParameters
using DynamicGrids.Setfield
using DynamicGrids.StaticArrays

using DynamicGrids.ModelParameters: params

import DynamicGrids: applyrule, applyrule!, modifyrule, kernel

export KernelFormulation, ExponentialKernel, GeometricKernel, GaussianKernel, WeibullKernel

export DistanceMethod, CentroidToCentroid, AreaToArea, AreaToCentroid #, CentroidToArea,

export DispersalKernel

export InwardsDispersal, OutwardsDispersal

export AlleeExtinction, JumpDispersal

export HumanDispersal, BatchGroups, HeirarchicalGroups

export ExponentialGrowth, LogisticGrowth, ThresholdGrowth

export LoglogisticMortality, ExponentialMortality

# Documentation templates
@template TYPES =
    """
    $(TYPEDEF)
    $(DOCSTRING)
    """

const DG = DynamicGrids

include("downsampling.jl")
include("kernel/formulations.jl")
include("kernel/distancemethods.jl")
include("kernel/kernel.jl")
include("kernel/inwards.jl")
include("kernel/outwards.jl")
include("growth.jl")
include("human.jl")
include("jump.jl")
include("allee.jl")
include("mortality.jl")

end # module


text:
using Random,Distributions,Polynomials
using Statistics,QuadGK,FFTW,LinearAlgebra
using Optim,Roots
include("./BCC97_option.jl")

Random.seed!(50000)

function random_number_generator(symbol,normlization,M,I,mydim)
    if symbol==1
        rand0=rand(Normal(0,1),mydim,M+1,I)
        myrand=cat(myrand,-myrand,3)
    else
        myrand=rand(Normal(0,1),mydim,M+1,I)
    end # if

    if normlization==true
        myrand=(myrand .-mean(myrand)) ./std(myrand)
    end

    return myrand
end

function CIR_genetate_path(x0,κ,θ,σ,T,M,I,x_disc)
    dt=T/M
    x=zeros(M+1,I)
    x[1,:]=map(x->x=x0,x[1,:])
    xh=zeros(M+1,I)

    ran=rand(Normal(0,1),M+1,I)

    if isequal(x_disc,"exact")
        d=4*κ*θ/σ^2
        c=(σ^2*(1-exp(-κ*dt)))/(4*κ)
        if d>1
            for t in 2:M+1
                l=x[t-1,:]*(exp(-κ*dt))/c
                χ=rand(Chisq(d-1),I)
                x[t,:]=c*((ran[t,:] .+sqrt(l))^2 .+χ)
            end
        else
            for t in 2:M+1
                l=x[t-1,:]*(exp(-κ*dt))/c
                N=map(x->rand(Poisson(x/2)),l)
                χ=map(x->rand(Chisq(d+2*x)),N)
                x[t,:]=c*χ
            end
        end
    else
        for t in 2:M+1
            tmp1=map(x->dt*κ*(θ-max(0,x)),xh[t-1,:])
            tmp2=map(x->√(dt)*σ*sqrt(max(0,x)),xh[t-1,:])
            tmp3=ran[t,:] .*tmp2
            xh[t,:]=(xh[t-1,:] .+tmp1 .+tmp3)
            x[t,:]=map(x->max(0,x),xh[t,:])
        end
    end

    return x

end

function SRD_generate_path(x_disc,x0,κ,θ,σ,T,M,I,myrand,row,cho_matrix)
    dt=T/M
    x=zeros(M+1,I)
    x[1,:]=map(x->x=x0,x[1,:])
    xh=zeros(M+1,I)
    xh[1,:]=map(x->x=x0,xh[1,:])

    sdt=√(dt)

    @simd for t in 2:M+1
        ran=cho_matrix*myrand[:,t,:]
        if isequal(x_disc,"FULL Truncation")
            tmp1=map(x->dt*κ*(θ-max(0,x)),xh[t-1,:])
            tmp2=map(x->sdt*σ*sqrt(max(0,x)),xh[t-1,:])
            tmp3=ran[row,:] .*tmp2
            xh[t,:]=(xh[t-1,:] .+tmp1 .+tmp3)
            x[t,:]=map(x->max(0,x),xh[t,:])
        elseif isequal(x_disc,"Partial Truncation")
            tmp1=map(x->dt*κ*(θ-x),xh[t-1,:])
            tmp2=map(x->sdt*σ*sqrt(max(0,x)),xh[t-1,:])
            tmp3=ran[row,:] .*tmp2
            xh[t,:]=(xh[t-1,:] .+tmp1 .+tmp3)
            x[t,:]=map(x->max(0,x),xh[t,:])
        elseif isequal(x_disc,"Truncation")
            tmp1=map(x->dt*κ*(θ-x),x[t-1,:])
            tmp2=map(x->sdt*σ*sqrt(x),x[t-1,:])
            tmp3=ran[row,:] .*tmp2
            x[t,:]=map(x->max(0,x),(x[t-1,:] .+tmp1 .+tmp3))
        elseif isequal(x_disc,"Reflection")
            tmp1=map(x->dt*κ*(θ-abs(x)),xh[t-1,:])
            tmp2=map(x->sdt*σ*sqrt(abs(x)),xh[t-1,:])
            tmp3=ran[row,:] .*tmp2
            xh[t,:]=(xh[t-1,:] .+tmp1 .+tmp3)
            x[t,:]=map(x->abs(x),xh[t,:])
        elseif isequal(x_disc,"Higham-Mao")
            tmp1=map(x->dt*κ*(θ-x),xh[t-1,:])
            tmp2=map(x->sdt*σ*sqrt(abs(x)),xh[t-1,:])
            tmp3=ran[row,:] .*tmp2
            xh[t,:]=(xh[t-1,:] .+tmp1 .+tmp3)
            x[t,:]=map(x->abs(x),xh[t,:])
        elseif isequal(x_disc,"Simple Reflection")
            tmp1=map(x->dt*κ*(θ-x),x[t-1,:])
            tmp2=map(x->sdt*σ*sqrt(x),x[t-1,:])
            tmp3=ran[row,:] .*tmp2
            x[t,:]=map(x->abs(x),(x[t-1,:] .+tmp1 .+tmp3))
        elseif isequal(x_disc,"Absorption")
            tmp1=map(x->dt*κ*(θ-max(0,x)),xh[t-1,:])
            tmp2=map(x->sdt*σ*sqrt(max(0,x)),xh[t-1,:])
            tmp3=ran[row,:] .*tmp2
            xh[t,:]=map(x->max(0,x),xh[t-1,:] .+tmp1 .+tmp3)
            x[t,:]=map(x->max(0,x),xh[t,:])
        else
            print("wrong method!")
        end # if

    end

    return x

end

function H93_generate_path(S0,r,v,row,cho_matrix,M,I,T,myrand,s_disc)
    S=zeros(M+1,I)
    dt=T/M
    S[1,:]=map(x->x=S0,S[1,:])
    bias=0.0
    sdt=√(dt)
    @simd for t in 2:M+1
        ran=cho_matrix*myrand[:,t,:]
        # if true
        #     bias=mean(v[t,:] .*ran[row,:]*sdt)
        # end
        if isequal(s_disc,"Log")
            tmp0=(r .-0.5*v[t,:])*dt+map(x->sqrt(x),v[t,:]) .*ran[row,:]*sdt .-bias
            tmp1=map(x->exp(x),tmp0)
            S[t,:]=S[t-1,:] .*tmp1
        elseif isequal(s_disc,"Native")
            tmp2=exp(r*dt) .+map(x->sqrt(x),v[t,:]) .*ran[row,:]*sdt-bias
            S[t,:]=S[t-1,:] .*tmp2
        else
            print("wrong method1")
        end # if

    end # for
    return S
end

function ZCB_mcs(r0,κ_r,θ_r,σ_r,T,M,I,x_disc)
    dt=T/M
    r=CIR_genetate_path(r0,κ_r,θ_r,σ_r,T,M,I,x_disc)
    zcb=zeros(M+1,I)
    zcb[end,:]=map(x->x=1.0,zcb[1,:])
    for t=M+1:-1:2
        tmp1=map(x->exp(x/2*dt),-(r[t,:] .+r[t-1,:]))
        zcb[t-1,:]=zcb[t,:] .*tmp1
    end

    return sum(zcb,dims=2)/I
end

function H93_index_paths(S0,r,v,row,cho_matrix,M,I,T,myrand)
    S=zeros(M+1,I)
    dt=T/M
    S[1,:]=map(x->x=log(S0),S[1,:])
    sdt=√(dt)
    for t in 2:M+1
        ran=cho_matrix*myrand[:,t,:]
        S[t,:]+=S[t-1,:]
        S[t,:]+=((r[t,:]+r[t-1,:])/2 .-v[t,:]/2)*dt
        S[t,:]+=map(x->sqrt(x),v[t,:]) .*ran[row,:]*sdt
    end # for
    # if momath==1
    #     S[t,:]-=mean(map(x->sqrt(x),v[t,:]) .*ran[row,:]*sdt)
    # end
    S_index_path=map(x->exp(x),S)
    return S_index_path
end
#

function H93_euroption_mcs(args)
    cor_martix=[1.0 0.1;0.1 1.0]
    cho_matrix=LinearAlgebra.cholesky(cor_martix).L
    r=0.05
    x0=0.01
    κ=1.5
    θ=0.02
    σ=0.15
    T=1/12
    M=2
    dt=T/M
    S0=100.0
    I=25000
    x_disc="FULL Truncation"
    symbol=2
    normlization=false
    s_disc="Log"
    K=90
    mydim=2
    myrand=random_number_generator(symbol,normlization,M,I,mydim)
    v=SRD_generate_path(x_disc,x0,κ,θ,σ,T,M,I,myrand,2,cho_matrix)
    S=H93_generate_path(S0,r,v,1,cho_matrix,M,I,T,myrand,s_disc)
    h=map(x->max(x-K,0),S)
    H93_euroption_valution=sum(h[end,:]*exp(-r*T))/I

    return H93_euroption_valution
end

function get_condtion(A,B)
    len=length(A)
    C=zeros(sum(A))
    i=1
    for t in 1:len
        if A[t]==1
            C[i]=B[t]
            i+=1
        end
    end

    return C
end

function BCC97_SVSI_MCS(args)

    ρ=0.1
    cor_martix=[1.0 ρ 0.0;ρ 1.0 0.0;0.0 0.0 1.0]
    cho_matrix=LinearAlgebra.cholesky(cor_martix).L
    r=0.05
    x0=0.01
    κ=1.5
    θ=0.02
    σ=0.15
    T=1/12
    M=20
    dt=T/M
    S0=100.0
    I=25000
    x_disc="FULL Truncation"
    symbol=2
    normlization=false
    s_disc="Log"
    K=90
    row=1
    mydim=3
    D=10
    myrand=random_number_generator(symbol,normlization,M,I,mydim)
    r1=SRD_generate_path(x_disc,r,κ,θ,σ,T,M,I,myrand,1,cho_matrix)
    v=SRD_generate_path(x_disc,x0,κ,θ,σ,T,M,I,myrand,3,cho_matrix)
    S_path=H93_index_paths(S0,r1,v,row,cho_matrix,M,I,T,myrand)

    h=map(x->max(K-x,0),S_path)
    Va=map(x->max(K-x,0),S_path)

    for tt=M-1:-1:1
        df=map(x->exp(-x),(r1[tt,:].+r1[tt+1,:])/2*dt)
        itm=map(x->x>0 ? 1 : 0,h[tt,:])
        no_itm=sum(filter(!iszero,itm))

        println(tt)
        println(no_itm)
         rel_S=get_condtion(itm,S_path[tt,:])
        # rel_S=filter(!iszero,itm .*S_path[tt,:])
        if no_itm==0
            cv=zeros(I)
        else

            rel_v=get_condtion(itm,v[tt,:])
            rel_r=get_condtion(itm,r1[tt,:])
            rel_V0=get_condtion(itm,Va[tt,:])
            tmp000=get_condtion(itm,df)

            rel_V=rel_V0 .*tmp000
            mymatrix=zeros(D+1,no_itm)
            mymatrix[11,:]=rel_S .*rel_v .*rel_r
            mymatrix[10,:]=rel_S .*rel_v
            mymatrix[9,:]=rel_S .*rel_r
            mymatrix[8,:]=rel_v .*rel_r
            mymatrix[7,:]=rel_S .^2
            mymatrix[6,:]=rel_v .^2
            mymatrix[5,:]=rel_r .^2
            mymatrix[4,:]=rel_S
            mymatrix[3,:]=rel_v
            mymatrix[2,:]=rel_r
            mymatrix[1,:]=map(x->x=1,mymatrix[1,:])

            temp0=inv(mymatrix*mymatrix')*mymatrix
            reg=temp0*rel_V

            cv=reg'*mymatrix
        end
        erg=zeros(I)
        erg0=erg .*itm .*cv
        res=h[tt,:].>erg0
        @simd for i=1:I
            if res[i]==true
                global Va[tt,i]=h[tt,i]
            else
                global Va[tt,i]=Va[tt+1,i]*df[i]
            end
        end
    end

    df1=map(x->exp(-x),(r1[1,:]+r1[2,:])/2*dt)
    C0=H93_call_func(S0,K,T,r,κ,θ,σ,ρ,x0)
    κ_r,θ_r,σ_r,r0=0.3,0.04,0.1,0.04
    B0t=B(κ_r,θ_r,σ_r,r0,T)
    P0=C0+K*B0t-S0
    P0_MCS=sum(h[end,:]*B0t)/I

    x=B0t*h[end,:]
    y=Va[2,:] .*df1
    convar=true

    if convar
        x_mean=x .-mean(x)
        y_mean=y .-mean(y)
        b=sum(x .*y)/sum(x_mean .^2)
        y_cv=y .-1.0*(B0t*h[end,:] .-P0)
    else
        y_cv=y
    end

    SE=std(y)/√(I)

    V0_CV=max(sum(y_cv)/I,h[1,1])

    V0_LSM=max(sum(y)/I,h[1,1])

    return   V0_LSM
end

#
# res2=ZCB_mcs(r0,κ_r,θ_r,σ_r,T,M,I,x_disc)


text:
tests = ["distributions-dep",
         "bootsample-non-parametric",
         "bootsample-parametric",
         "stats",
         "utils"]

println("Running 'Bootstrap' tests:")

test_dir = dirname(@__FILE__)

for t in tests
    test_file = joinpath(test_dir, string(t, ".jl"))
    if !isfile(test_file)
        error(" ! $(test_file) missing")
    end
    include(test_file)
end


text:
# import Pkg;

# Pkg.add("JLD")
# Pkg.add("PlotlyJS")
# Pkg.add("JSON")
# Pkg.add("JuMP")
# Pkg.add("YAML")
# Pkg.add("CSV")
# Pkg.add("DataFrames")
# Pkg.add("Query")
# Pkg.add("OrderedCollections")
# Pkg.add("Missings")

import YAML

# using JLD
using OrderedCollections
using CSV
using DataFrames
using Dates
using Query
using Statistics
using JuMP
using Missings
#using Serialization

yamlFile = YAML.load_file("/mnt/861c9f85-a9ba-440b-8815-065043e41e1a/gitHubRepos/airNodesJuliaML/firmware/utdNodesJl/mintsDefinitionsV2.yaml"; dicttype=OrderedDict{String,Any})
#yamlFile = YAML.load_file("../mintsDefinitionsV2.yaml"; dicttype=OrderedDict{String,Any})      # loading yaml file and arrange in order
dirctory = yamlFile["dataFolder"]                            # taking the directory of data stored
sensorNames = yamlFile["liveStack"]                         # all the sensor names
#sensorNames = ["TSL2591"]

# only 11th node data is saved
nodeIDs_array = yamlFile["nodeIDs"]                         # node's IDs array
node11 = nodeIDs_array[11]                                  # Taking 11th node
nodeId = node11["nodeID"]                                   # taking 11th nodeID

path = dirctory*"/"*nodeId

############# anaylzing and averaging data
function ss(dd, mm, yy, sensr)
    CSV_fileName_arry = readdir(path*"/"*yy*"/"*mm*"/"*dd*"/")       # taking all the file names from the folder
    num_files = length(CSV_fileName_arry)                            # number of files

    CSV_file = "MINTS_"*nodeId*"_"*sensr*"_"*yy*"_"*mm*"_"*dd*".csv"            # CSV file name
    if (CSV_file in CSV_fileName_arry)                                          # check CSV fime exist or not
        df = CSV.read(path*"/"*yy*"/"*mm*"/"*dd*"/"*CSV_file, DataFrame)        # If the CSV file exist then take the data into a dataframe
        #df.dateTime =  SubString.(string.(df.dateTime), 1, 19)                  # Removing last three decimal numbers in dateTime column

        if sensr == "GPSGPGGA2"
            df = select!(df, Not(:timestamp))
            df = select!(df, Not(:latitudeDirection))
            df = select!(df, Not(:longitudeDirection))
            df = select!(df, Not(:altitudeUnits))
            df = select!(df, Not(:undulationUnits))
            df = select!(df, Not(:age))
            df = select!(df, Not(:stationID))
        end

        if sensr == "GPSGPRMC2"
            df = select!(df, Not(:timestamp))
            df = select!(df, Not(:status))
            df = select!(df, Not(:latitudeDirection))
            df = select!(df, Not(:longitudeDirection))
            df = select!(df, Not(:dateStamp))
            df = select!(df, Not(:magVariation))
            df = select!(df, Not(:magVariationDirection))
            df = select!(df, Not(:trueCourse))
        end

        try
            df.dateTime =  SubString.(string.(df.dateTime), 1, 19)
            df.dateTime = DateTime.(df.dateTime,"yyyy-mm-dd HH:MM:SS")

            df.dateTime = map((x) -> round(x, Dates.Second(30)), df.dateTime)       # Rounding dateTime for 30 seconds
            gdf = groupby(df, :dateTime)                                            # making groups by same dateTime
            cgdf = combine(gdf, valuecols(gdf) .=> mean)                            # Calculate the mean of each group and then combine the groups

            colFullName = names(cgdf)                                               # Take the column names of dataFrame into a array
            for x in 2:length(colFullName)                                          # Starting from 2nd column and go through all the columns
                num_let = length(colFullName[x])                                    # taking number of characters in one column name
                colName = SubString.(string.(colFullName[x]), 1, num_let-5)         # removing last five characters of each column name (that is _mean)
                rename!(cgdf,colFullName[x] => sensr*"_"*colName)                   # adding sensor name to the column name
            end

            return cgdf                             # return the dataFrame to for loop

        catch e
            println("Error on "*CSV_file)

            colFullName = names(df)                                               # Take the column names of dataFrame into a array
            for x in 2:length(colFullName)                                          # Starting from 2nd column and go through all the columns
                #num_let = length(colFullName[x])                                    # taking number of characters in one column name
                #colName = SubString.(string.(colFullName[x]), 1, num_let-5)         # removing last five characters of each column name (that is _mean)
                rename!(df,colFullName[x] => sensr*"_"*colFullName[x])                   # adding sensor name to the column name
            end

            cgdf = empty(df::AbstractDataFrame)
            return cgdf
        end
    end
end

#global sensr_exsist = false
n = 0

for sensr in sensorNames                                                # Go through all the sensor names
    k = 0
    years = readdir(path)                                               # taking all the year folder names

    for y in years                                                      #
        months = readdir(path*"/"*y)

        for m in months
            days = readdir(path*"/"*y*"/"*m)

            for d in days
                filess = readdir(path*"/"*y*"/"*m*"/"*d)
                CSV_file = "MINTS_"*nodeId*"_"*sensr*"_"*y*"_"*m*"_"*d*".csv"

                if (CSV_file in filess)
                    println("Date: "*y*"_"*m*"_"*d)
                    println(sensr)
                    averaged_df = ss(d, m, y, sensr)
                    df2 = averaged_df
                    k = k + 1

                    mapcols(col -> replace!(col, NaN=>0), df2)

                    println("done")
                    global sensr_exsist = true

                    if (k > 1)

                        #try
                        global new_df = outerjoin(new_df, df2, on = intersect(names(new_df), names(df2)))
                        #catch e
                            #println("Error of adding: "*"MINTS_"*nodeId*"_"*sensr*"_"*y*"_"*m*"_"*d*".csv")
                        #end

                    else
                        new_df = averaged_df
                    end

                else
                    println("No data of "*sensr)
                    sensr_exsist = false
                    #continue
                end
            end
        end
    end

    global n = n + 1

    if sensr_exsist

        if (n > 1)
            println("******************************************************")
            global final_df = outerjoin(final_df, new_df, on = :dateTime, makeunique=true)
        else
            final_df = new_df
        end

    end

end

final_df2 = sort!(final_df)
#CSV.write("/mnt/3fbf694d-d8e0-46c0-903d-69d994241206/mintsData/avJlData/"*nodeId*"_df.csv", final_df2)
serialize("/mnt/3fbf694d-d8e0-46c0-903d-69d994241206/mintsData/avJlData/"*nodeId*"_df2.jls", final_df2)


text:
using Pkg
using BinaryBuilder

name = "SCS_GPU"
version = v"2.1.3"

# Collection of sources required to build SCSBuilder
sources = [
    GitSource("https://github.com/cvxgrp/scs.git", "07ca69c296312c260027c755f545f05bf45156eb")
]

# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir/scs*
flags="DLONG=0 USE_OPENMP=0 BLAS64=1 BLASSUFFIX=_64_"
blasldflags="-L${libdir} -lopenblas64_"

CUDA_PATH=$prefix/cuda make BLASLDFLAGS="${blasldflags}" ${flags} out/libscsgpuindir.${dlext}

mkdir -p ${libdir}
cp out/libscs*.${dlext} ${libdir}
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line

platforms = [
    Platform("x86_64", "linux"),
]

# The products that we will ensure are always built
products = [
    LibraryProduct("libscsgpuindir", :libscsgpuindir, dont_dlopen=true)
]

# Dependencies that must be installed before this package can be built

# since https://github.com/cvxgrp/scs/pull/155 scs uses the generic
# cusparse API which was itroduced in CUDA-10.1
cuda_version = v"10.1.243"

dependencies = [
    Dependency("OpenBLAS_jll"),
    BuildDependency(PackageSpec(name="CUDA_full_jll", version=cuda_version))
]

# Build the tarballs, and possibly a `build.jl` as well.
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies)

max_stars_repo_name: waralex/Yggdrasil

max_issues_repo_name: waralex/Yggdrasil

max_forks_repo_name: waralex/Yggdrasil


text:
"""
    absorb

Function for constructing the `FunctionTerm{typeof(absorb)}` used in decompose.
"""
function absorb end
"""
    decompose(f::FormulaTerm,
              data,
              contrasts::Dict{Symbol},
              wts::Union{Nothing,Symbol},
              panel::Union{Nothing,Symbol},
              time::Union{Nothing,Symbol},
              estimator::Type{<:Union{EconometricsModel,ModelEstimator}},
              vce::VCE)

Decomposes the arguments passed to a fit(::EconometricModel) into its components.

# Returns

- data
- exogenous::FormulaTerm
- iv::FormulaTerm
- estimator::ModelEstimator
- X::Matrix{Float64}
- y::VecOrMat{<:Union{Bool,Int,Float64}}
- z::Vector{Float64}
- Z::Matrix{Float64}
- wts::FrequencyWeights
"""
function decompose(f::FormulaTerm,
                   data,
                   contrasts::Dict{Symbol},
                   wts::Union{Nothing,Symbol},
                   panel::Union{Nothing,Symbol},
                   time::Union{Nothing,Symbol},
                   estimator::Type{<:Union{EconometricsModel,ModelEstimator}},
                   vce::VCE)
    rhs = isa(f.rhs, Tuple) ? collect(f.rhs) : [f.rhs]
    absorbed = findall(t -> isa(t, FunctionTerm{typeof(absorb)}), rhs)
    # Conditions based on panel and temporal indices and absorbed features
    if isa(estimator, Type{<:BetweenEstimator}) && isnothing(panel)
        throw(ArgumentError("The between estimator requires the panel identifier."))
    elseif isa(estimator, Type{<:RandomEffectsEstimator}) && (isnothing(panel) || isnothing(time))
        throw(ArgumentError("The random effects estimator requires the panel and temporal identifiers."))
    elseif (isa(estimator, Type{<:BetweenEstimator}) ||
            isa(estimator, Type{<:RandomEffectsEstimator})) && !isempty(absorbed)
        throw(ArgumentError("Absorbing features is only implemented for least squares."))
    end
    pns = convert(Vector{Symbol}, filter!(!isnothing, union(termvars(f), [panel, time, wts])))
    data = select(data, pns...)
    if isa(wts, Symbol)
		wts = ifelse.(getproperty(data, wts) .≤ 0, missing, getproperty(data, wts))
    end
	categorical_variables = Tables.schema(data) |>
		(x -> [name for (name, type) ∈ zip(x.names, x.types) if
			isa(type, Type{<:Union{AbstractString, CategoricalValue}})])
	data_categorical =
		zip(categorical_variables,
			(levels(col), isordered(col)) for
		    col ∈ eachcolumn(select(data, categorical_variables...))) |>
		Dict
	data = materializer(data)(row for row ∈ rows(data) if
        all(pn -> !ismissing(getproperty(row, pn)), propertynames(row)))
    for cn ∈ categorical_variables
		col = getproperty(data, cn)
		levels!(col, intersect(data_categorical[cn][1],
							   unique(col)))
		ordered!(col, data_categorical[cn][2])
	end
    if isempty(absorbed)
        absorbed = Vector{Vector{Vector{Int}}}()
    elseif length(absorbed) == 1
        vce ≥ HC2 &&
            throw(ArgumentError("When absorbing features, only HC2-HC4 are unavailable."))
        absorbed = rhs[absorbed[1]]
        if isa(absorbed, AbstractVector)
            absorbed = unique(flatten(termvars(t) for t ∈ absorbed))
        else
            absorbed = termvars(absorbed)
        end
        absorbed = [ [ findall(isequal(l), getproperty(data, dim)) for l ∈ levels(getproperty(data, dim)) ] for dim ∈ absorbed ]
    else
        throw(ArgumentError("There can only be at most one absorb term"))
    end
    exo_rhs = filter(t -> !(isa(t, FormulaTerm) || isa(t, FunctionTerm{typeof(absorb)})), rhs)
    exogenous = FormulaTerm(f.lhs,
                            isempty(exo_rhs) ? Tuple([ConstantTerm(1)]) : Tuple(exo_rhs))
    @assert length(terms(exogenous.lhs)) == 1 "Response should be a single variable"
    iv = findall(t -> isa(t, FormulaTerm), rhs)
    if length(iv) == 0
        iv = @eval(@formula(0 ~ 0))
    elseif length(iv) == 1
        iv = rhs[iv[1]]
    else
        throw(ArgumentError("Formula syntax is response ~ exogenous + (endogenous ~ instruments)"))
    end
    sc = schema(data, contrasts)
    f = apply_schema(f, sc)
    exogenous = apply_schema(exogenous, sc, EconometricsModel)
    iv = apply_schema(iv, sc)
    # Conditions based on response type and instrumental variables
    if isa(f, FormulaTerm{<:CategoricalTerm})
        isa(iv.lhs, InterceptTerm{false}) ||
            throw(ArgumentError("Instrumental variables are only implemented for linear models."))
        vce == OIM ||
            throw(ArgumentError("Robust variance covariance estimators only available for continous response models."))
        if isordered(getproperty(data, f.lhs.sym))
            any(x -> isa(x, InterceptTerm{false}), f.rhs.terms) &&
                throw(ArgumentError("This estimator requires an intercept term."))
            estimator = OrdinalResponse(f.lhs.contrasts)
        else
            estimator = NominalResponse(f.lhs.contrasts)
        end
    elseif isa(estimator, Type{<:RandomEffectsEstimator}) &&
           any(x -> isa(x, InterceptTerm{false}), f.rhs.terms)
        throw(ArgumentError("The random effects estimator requires an intercept term."))
    end
    if isa(exogenous.lhs, CategoricalTerm)
        y = getproperty(data, exogenous.lhs.sym)
        X = modelcols(exogenous.rhs, data)
        if isordered(y)
            X = X[:,2:end]
        end
    else
        y, X = modelcols(exogenous, data)
    end
    if !isa(iv.lhs, InterceptTerm)
        z, Z = modelcols(iv, data)
        z = isa(z, Tuple) ? hcat(z...) : convert(Matrix{Float64}, reshape(z, length(z), 1))
    else
        z = zeros(0, 0)
        Z = zeros(0, 0)
    end
	wts = isnothing(wts) ?
		  FrequencyWeights(ones(length(y))) :
		  FrequencyWeights(collect(wts))
    if isa(estimator, Type{<:RandomEffectsEstimator})
        panel = (panel,
                 [ findall(isequal(l), getproperty(data, panel)) for l ∈ levels(getproperty(data, panel)) ])
        time = (time, [ findall(isequal(l), getproperty(data, time)) for l ∈ levels(getproperty(data, time)) ])
        estimator = RandomEffectsEstimator(panel, time, X, y, z, Z, FrequencyWeights(wts))
    elseif isa(estimator, Type{<:BetweenEstimator})
        estimator = BetweenEstimator(panel, [ findall(isequal(l), getproperty(data, panel)) for l ∈ levels(getproperty(data, panel)) ])
    elseif isa(estimator, Type{<:EconometricModel}) || isa(estimator, Type{<:ContinuousResponse})
        estimator = ContinuousResponse(absorbed)
    end
    data, exogenous, iv, estimator, X, y, z, Z, wts
end

remove_intercept(f::AbstractString) =
    occursin(" ~ 1 + ", f) ? replace(f, " ~ 1 + " => " ~ ") : f
add_intercept(f::AbstractString) =
    !occursin(r" ~ -?[0-1] ?", f) ? replace(f, r"(^.*?) ~ " => s"\1 ~ 1 + ") : f
clean_lhs(obj::AbstractTerm) = string(obj)
clean_lhs(obj::FunctionTerm) = string(obj)[3:end - 1]
clean_rhs(obj::Tuple) = mapreduce(clean_rhs, (x, y) -> "$x + $y", obj)
clean_rhs(obj::AbstractTerm) = string(obj)
clean_rhs(obj::InteractionTerm) = mapreduce(clean_rhs, (x, y) -> "$x & $y", obj.terms)
clean_rhs(obj::FunctionTerm) = string(obj)[2:end]
clean_rhs(obj::FormulaTerm) = string("(", obj.lhs, " ~ ", clean_rhs(obj.rhs), ")")
clean_rhs(obj::FunctionTerm{typeof(absorb)}) = string(obj)[3:end - 1]
clean_fm(obj::EconometricsModel) =
    obj.f |>
    (f -> string(clean_lhs(f.lhs), " ~ ", clean_rhs(f.rhs))) |>
    (f -> isa(obj, EconometricModel{<:Union{RandomEffectsEstimator,
                                            OrdinalResponse}}) ?
          remove_intercept(f) : add_intercept(f)) |>
    (f -> "Formula: $f")


text:
import Base: *, +

using FFTW

abstract type AbstractOperator end

struct PointWiseSpectralOperator{O} <: AbstractOperator
    operation::O
end

*(a::AbstractField, b::AbstractField) = a.data .* b.data
+(a::AbstractField, b::AbstractField) = a.data .+ b.data

function (operator::PointWiseSpectralOperator)(a::ScalarField)
    â = fft(a.data)
    data = operator.operation .* â
    return ifft(data)
end

function (operator::PointWiseSpectralOperator)(a::AbstractArray)
    â = fft(a)
    data = operator.operation .* â
    return ifft(data)
end

max_stars_repo_name: sandreza/FourierCore

max_issues_repo_name: sandreza/FourierCore

max_forks_repo_name: sandreza/FourierCore


text:
export DynamicalSystemIntegrator, DynSysInteg

# how the hell do you write this...???
const DynamicalSystemIntegrator{IIP, S} = Union{
    AbstractODEIntegrator{Alg, IIP, S},
    TangentDiscreteIntegrator{IIP, S},
    MinimalDiscreteIntegrator{IIP, S}
} where {Alg}

const DynSysInteg = DynamicalSystemIntegrator


text:
using DifferenceEquations, BenchmarkTools
using Test, LinearAlgebra, Random

# Check if MKL or not
julia_mkl = @static if VERSION < v"1.7"
    LinearAlgebra.BLAS.vendor() === :mkl
else
    any(contains("mkl"), getfield.(LinearAlgebra.BLAS.get_config().loaded_libs, :libname))
end

if !julia_mkl
    openblas_threads = min(4, Int64(round(Sys.CPU_THREADS / 2)))
    BLAS.set_num_threads(openblas_threads)
end

println("Running Testsuite with Threads.nthreads = $(Threads.nthreads()) MKL = $julia_mkl, and BLAS.num_threads = $(BLAS.get_num_threads()) \n")

# Benchmark groups
BenchmarkTools.DEFAULT_PARAMETERS.seconds = 15.0 # 10 seconds per benchmark by default.
BenchmarkTools.DEFAULT_PARAMETERS.evals = 3

const SUITE = BenchmarkGroup()
SUITE["linear"] = include(pkgdir(DifferenceEquations) * "/benchmark/linear.jl")
SUITE["quadratic"] = include(pkgdir(DifferenceEquations) * "/benchmark/quadratic.jl")

# results = run(SUITE; verbose = true)


text:
import DataStructures: PriorityQueue, enqueue!, peek, dequeue!

function readinstance()
    n, m, x, y = [parse(Int, x) for x in split(readline())]
    edges = Dict{Int, Set{Tuple{Int, Int, Int}}}()
    for i=1:n
        edges[i] = Set{Tuple{Int, Int, Int}}()
    end
    for i=1:m
        a, b, t, k = [parse(Int, x) for x in split(readline())]
        push!(edges[a], (b, t, k))
        push!(edges[b], (a, t, k))
    end
    n, m, x, y, edges
end

function solve()
    n, m, x, y, edges = readinstance()
    fixed = Dict{Int, Int}()
    unfixed = PriorityQueue{Int, Int}()
    for i=1:n
        enqueue!(unfixed, i, i == x ? 0 : Inf)
    end

    while length(unfixed) != 0
        v, d = peek(unfixed)
        dequeue!(unfixed)
        if d == Inf
            return -1
        end
        if v == y
            return d
        end
        fixed[v] = d
        for (b, t, k) in edges[v]
            if b ∉ keys(fixed)
                dd = ceil(Int, d / k) * k + t
                if dd < unfixed[b]
                    unfixed[b] = dd
                end
            end
        end
    end

    y ∈ keys(fixed) ? fixed[y] : -1
end

println(solve())

max_stars_repo_name: aishikawa/atcoder-julia

max_issues_repo_name: aishikawa/atcoder-julia

max_forks_repo_name: aishikawa/atcoder-julia