# test(solution, eq) for algebra and differential equation, return 0 is true;

test(sol_,eq_):= if(has(eq,y(_,x)) or has(eq,ds(y,x)) or has(eq,ints(y,x)), 
	chop(chop( n( simplify( expand(simplify( expand(simplify( expand(simplify(replace(tods(eq),y,n(replace(replace(sol,C_1,1),C_2,1))))))))))))),
	chop(n(replace(eq,x,replace(sol,n,1))))	);
test(sol_,eq2_=eq1_):= test(sol,toy(eq2)-eq1);

test(sol_,int(y(tt_),t_,a_,b_)=eqr_):=chop( expand(int(replace(sol,x,tt),t,a,b)-eqr));

test(sol_,eq_,y_):= chop(n(expand(replace(eq,y,sol))));
test(sol_,eq2_=eq1_,y_):= chop(n(expand(replace(eq2-simplify(eq1),y,sol))));

test(x=sol_,x(p_,t_)=eqr_,eqr2_):= chop(n(expand(d(sol,y,p)-replace(eqr,x,sol))));
test(y=sol_,eqr1_,y(p_,t_)=eqr_):= chop(n(expand(d(sol,x,p)-replace(eqr,y,sol))));


test(x_=sol_ and y_=sol2_,eq_,x_,y_):= chop(n(replace(replace(eq,x,replace(sol,n,1)),y,replace(sol2,n,1))));
test(x_=sol_ and y_=sol2_,eq_=eqr_,x_,y_):= chop(n(replace(replace(eq-eqr,x,replace(sol,n,1)),y,replace(sol2,n,1))));
test(x_=sol_ and y_=sol2_,x_=sol3_ and y_=sol4_,eq_,x_,y_):= chop(n(replace(replace(eq,x,replace(sol,n,1)),y,replace(sol2,n,1))));
test(x_=sol_ and y_=sol2_,x_=sol3_ and y_=sol4_,eq_=eqr_,x_,y_):= chop(n(replace(replace(eq-eqr,x,replace(sol,n,1)),y,replace(sol2,n,1))));

test(xx_=a_ and yy_=b_,eq1_,eq2_):= chop(n(expand(simplify(replace(replace(tods(eq1),xx,n(a)),yy,n(b))))))
 	and chop(n(expand(simplify(replace(replace(tods(eq2),xx,n(a)),yy,n(b))))));
test(xx_=a_ and yy_=b_, eq1_=eq1r_,eq2_=eq2r_):= chop(n(simplify(expand(simplify(replace(replace(tods(eq1-eq1r),xx,n(a)),yy,n(b))))))) 
	and chop(n(simplify(expand(simplify(replace(replace(tods(eq2-eq2r),xx,n(a)),yy,n(b)))))));

test(xx_=a_,yy_=b_,eq1_,eq2_):= chop(n(expand(simplify(replace(replace(tods(eq1),xx,n(a)),yy,n(b)))))) 	and chop(n(expand(simplify(replace(replace(tods(eq2),xx,n(a)),yy,n(b))))));
test(xx_=a_,yy_=b_,eq1_=eq1r_,eq2_=eq2r_):= chop(n(expand(simplify(replace(replace(tods(eq1-eq1r),xx,n(a)),yy,n(b)))))) and chop(n(expand(simplify(replace(replace(tods(eq2-eq2r),xx,n(a)),yy,n(b))))));
	

test(sol_ and sol2_,eq_):= test(sol,eq) and test(sol2,eq);
test(sol_ and sol2_,eq_=eqr_):= test(sol,eq-eqr) and test(sol2,eq-eqr);
test(sol_ and sol2_,mod(eq_,b_)=eqr_):= test(sol,mod(eq-eqr,b)) and test(sol2,mod(eq-eqr,b));
test(sol_ and sol2_,eq_=mod(eqr_)):= test(sol,mod(eq-1,eqr)) and test(sol2,mod(eq-1,eqr));
test(sol_ and sol2_,eq_=a_*mod(eqr_)):= test(sol,mod(eq-a,eqr)) and test(sol2,mod(eq-a,eqr));
test(sol_ and sol2_,dy/dx=eqr_):= test(sol,dy/dx=eqr) and test(sol2,dy/dx=eqr);
test(sol_ and sol2_  and sol3_,eq_):= test(sol,eq) and test(sol2,eq) and test(sol3,eq);
test(sol_ and sol2_  and sol3_ and sol4_,eq_):= test(sol,eq) and test(sol2,eq) and test(sol3,eq) and test(sol4,eq);

test(sol_=sol2_,eq_):= test(solve(replace(replace(sol=sol2,C_1,1),C_2,1),y),toy(eq));
test(sol_=sol2_,eql_=eqr_):= test(solve(replace(replace(sol=sol2,C_1,1),C_2,1),y),eql-eqr);


test(x=sol_,ds(y_,x_)*f_+qr_):= chop(n(expand(d(sol,y)+replace(f/qr,x,sol))));
test(x=sol_,ds(y_,x_)+eqr_):= chop(n(expand(d(sol,y)+replace(1/eqr,x,sol))));
test(x=sol_,ds(y_,x_,p_)+eqr_):= chop(n(expand(d(sol,y,p)+replace(1/eqr,x,sol))));
test(x=sol_,b_*y(p_,x_)+eqr_):= chop(n(simplify(expand(d(sol,y,p)+replace(b/eqr,x,sol)))));
test(x=sol_,y(p_,x_)+eqr_):= chop(n(simplify(expand(d(sol,y,p)+replace(1/eqr,x,sol)))));
test(x=sol_,eql_=eqr_):= test(x=sol,toy(eql-eqr));
test(x=sol_,y(p_,x_)=eqr_):= chop(n(simplify(expand(d(sol,y,p)-replace(1/eqr,x,sol)))));
test(x=sol_,ds(y_,x_)=eqr_):= chop(n(expand(replace(d(sol,y)-1/eqr,x,sol))));
test(x=sol_,dy/dx=eqr_):= chop(n(expand(replace(d(sol,y)-1/eqr,x,sol))));

test(sol_=x,ds(y_,x_)*f_+qr_):= chop(n(expand(d(sol,y)+replace(f/qr,x,sol))));
test(sol_=x,ds(y_,x_)+eqr_):= chop(n(expand(d(sol,y)+replace(1/eqr,x,sol))));
test(sol_=x,ds(y_,x_,p_)+eqr_):= chop(n(expand(d(sol,y,p)+replace(1/eqr,x,sol))));
test(sol_=x,b_*y(p_,x_)+eqr_):= chop(n(simplify(expand(d(sol,y,p)+replace(b/eqr,x,sol)))));
test(sol_=x,y(p_,x_)+eqr_):= chop(n(simplify(expand(d(sol,y,p)+replace(1/eqr,x,sol)))));
test(sol_=x,eql_=eqr_):= test(sol=x,toy(eql-eqr));
test(sol_=x,y(p_,x_)=eqr_):= chop(n(simplify(expand(d(sol,y,p)-replace(1/eqr,x,sol)))));
test(sol_=x,dy/dx=eqr_):= chop(n(expand(replace(d(sol,y)-1/eqr,x,sol))));

test(sol_=C_1,eq2_):= test(sol=C_1,toy(eq2));
test(sol_=C_1,eq2_=eq1_):= test(sol=C_1,toy(eq2)-eq1);
test(sol_=C_1,n_*y(1,x_)+m_):= chop(n(expand(d(sol,x)+d(sol,y)-m-n)));
test(sol_=C_1,n_*y(1,x_)=m_):= chop(n(expand(d(sol,x)+d(sol,y)+m-n)));
#test(sol_=C_1,y(1,x_)=m_/n_):= chop(n(expand(d(sol,x)+d(sol,y)+m-n)));
#test(sol_=C_1,y(1,x_)=n_/m_):= chop(n(expand(d(sol,x)+d(sol,y)-m+n)));
test(sol_=C_1,y(1,x_)+m_/n_):= chop(n(expand(d(sol,x)+d(sol,y)-m-n)));
test(sol_=C_1,y(1,x_)+n_/m_):= chop(n(expand(d(sol,x)+d(sol,y)-n-m)));
test(sol_=C_1,ds(y,x)+m_/n_):= chop(n(expand(d(sol,x)+d(sol,y)-m-n)));
test(sol_=C_1,ds(y,x)+n_/m_):= chop(n(expand(d(sol,x)+d(sol,y)-m-n)));
test(sol_=C_1,dy/dx=m_/n_):= 	chop(n(expand(d(sol,x)+d(sol,y)+m-n)));

test(sol_=C_1,x(p_,t_)=n_,y(p_,t_)=m_):= chop(n(expand(d(sol,x,p)+d(sol,y,p)+m-n)));
test(sol_=C_1,ds(x_,t_)=n_,ds(y_,t_)=m_):= chop(n(expand(d(sol,x)+d(sol,y)+m-n)));