integral(x*exp((k+1)*x)/(exp(x)+3),x,0,inf)?



I'm going to embarrass myself by asking how to evaluate the integral
given above.  Currently, if intanalysis is false, maxima converts
integral(x^k*log(x)/(x+3),x,0,inf) to the above integral.[1]  If k+1>0, k
< 0, and k is not an integer, maxima says the above integral is

-(log(3)^2+%pi^2)*%e^(log(3)*kk)*(%i*sin(%pi*kk)+cos(%pi*kk))/2

But imagpart(%) is

-(log(3)^2+%pi^2)*%e^(log(3)*kk)*sin(%pi*kk)/2

which is not zero.  That's silly since the integrand is always real
for real x.

Maxima evaluates this integral using a rectangular region with corners
at (-R,0) to (R,2*%i*%pi) and lets R -> inf.  The derivation is given
in Wang, p 98-100.  I've done the integration by hand, and get the
same result as maxima.  But something is wrong, and I don't know what
it is.

A quick summary of the approach is in the comments for rectzto%pi2 in
defint.lisp:

;; This is a very brief description of the algorithm.  Basically, we
;; have integrate(R(exp(x))*p(x),x,minf,inf), where R(x) is a rational
;; function and p(x) is a polynomial.
;;
;; We find a polynomial q(x) such that q(x) - q(x+2*%i*%pi) = p(x).
;; Then consider a contour integral of R(exp(z))*q(z) over a
;; rectangular contour.  Opposite corners of the rectangle are (-R,
;; 2*%i*%pi) and (R, 0).
;;
;; Wang shows that this contour integral, in the limit, is the
;; integral of R(exp(x))*q(x)-R(exp(x))*q(x+2*%i*%pi), which is
;; exactly the integral we're looking for.
;;
;; Thus, to find the value of the contour integral, we just need the
;; residues of R(exp(z))*q(z).  The only tricky part is that we want
;; the log function to have an imaginary part between 0 and 2*%pi
;; instead of -%pi to %pi.

Can someone evaluate this integral and give a correct answer?  Bonus
points if you can do it by "hand". :-)

There must be some subtle point that maxima and I are missing.

Ray



Footnotes: 
[1]  I'm going to fix it so that integral(x^k*log(x)/(x+3),x,0,inf) is
evaluated correctly according to Wang's thesis.  The answer turns out
to be 

3^k*(psi[0](k+1)-psi[0](-k)+log(3))*beta(k+1,-k)

Numerical evaluations for k=-1/2 and k=-1/3 indicates that this result
is probably correct.