Implementation of Si(x), Ci(x) integrals



While dealing with special functions, I don't know if I just duplicated 
someone else's work, but I needed to compute integrals of forms like 
sin(x)/x^n  for integer n>=1.  I ended up writing some maxima code, 
which looks pretty neat and might help others with similar thoughts.  
Also, because of the way the integration program modifies the problem 
and tries again, it turns out to be surprisingly powerful.  Though it is 
far from perfect.  Here's the code.

/* Integration of some forms including cos(x)/x^n and sin(x)/x^n in
terms of Ci(x)=integrate(cos(x)/x,x) and Si(x)=integrate(sin(x)/x,x)*/

(matchdeclare(w,true,nn, nonnegintegerp),
tellsimp('integrate(cos(w)/w^nn,w), cosint[nn](w)),
tellsimp('integrate(sin(w)/w^nn,w), sinint[nn](w)),
/*cosint[n](w) is integral of cos(w)/w^n */
cosint[n](w):= block([k:1-n], cos(w)*w^k/k +integrate(sin(w)*w^k,w)/k),
sinint[n](w):= block([k:1-n], sin(w)*w^k/k -integrate(cos(w)*w^k,w)/k),
cosint[0](w):= sin(w),
sinint[0](w):= -cos(w),
cosint[1](w):= Ci(w),
sinint[1](w):= Si(w),
gradef(Ci(w), cos(w)/w),
gradef(Si(w), sin(w)/w))

/* you may be surprised [I was] that this will find closed forms for

integrate (a*cos(x)*x^4+b*sin(x))/x^2,x);
integrate(cos(sqrt(x))/x^2,x);
integrate(cos(x+1)/(x+1)^2,x);
integrate(cos(x^4)/x,x);
integrate(x*cos(sqrt(x^2+2))/(x^2+2), x);
integrate(cos(x)*cos(sin(x))/sin(x), x);
integrate(-sin(x)*cos(cos(x))*cos(sin(cos(x)))/sin(cos(x)),x);

I didn't need the exponential integral Ei(x), but that could also
be added.

*/