To consolidate effort, we now write a procedure that automatically separates out the trig and

polynomial parts of the integrand and performs integration by parts with the polynomial term

chosen as the one that is differentiated. Comments in the procedure body explain what's

happening. This procedure is highly optimized for this particular form of integral.

ugh := proc( expr )

local p, q, H, K, locI, locp, T, remdr;

global parts, _k_;

# update the parts index

if not assigned(_k_) then

_k_ := 0;

else

_k_ := _k_ + 1;

fi;

# grab the integral

if type( expr, function ) and op(0,expr)=Int then

H := expr;

else

H := select( has, expr, Int );

fi;

# get the integrand

K := op(1,H);

# grab the polynomial part and store in p

q := remove( has, %, {sin,cos} );

if type(q,`+`) then #already have it

p := q;

else

for p in q do

if type(p,`+`) then

break;

fi;

od:

fi;

if not has(p,{s,g}) then

locp := location( K, p );

debug_print(procname,`polynomial factor p:`,1,p);

debug_print(procname,`location of p in integrand: `,2,locp);

else

locp := [];

debug_print(procname,`no polynomial factor!`,1);

fi;

# now integrate by parts

debug_print(procname,`integrating by parts...`,0);

if nops(locp) > 0 then

q := intparts( expr, p );

debug_print(procname,`entire integrated mess:`,4,q);

else

debug_print(procname,`entire integrated mess:`,4);

RETURN( value( expr ) );

fi;

# store the evaluated part

parts[_k_] := remove( has, q, Int );

debug_print( procname,

Page 7