# Integrate gives inconsistent result for gamma-like integral with complex variables

I am trying to come up with a generic formula for the below integral, which is analogous to the upper incomplete gamma function,

Clear[x, t, n]; x1 =  FullSimplify[Integrate[(1 + I t)^(-1 - I x) E^(2 \[Pi] I n t) , {t, 0, 1}, Assumptions -> x > 0 && n > 0]]


I used assumptions to increase the likelihood of getting a correct answer. It gives me the not so neat function below:

But I usually don't blindly trust Mathematica's results, so I tried to validate the formula it gave me,

Clear[t]; x = 2; n = 1; N[{x1 = Integrate[(1 + I t)^(-1 - I x) E^(2 \[Pi] I n t) , {t, 0, 1}],  x2 = I 2^((I x)/2) E^(-2 n \[Pi] - (13 \[Pi] x)/4) ((1 - I) n)^(I x) \[Pi]^(I x) ((1 - E^(2 \[Pi] x)) Gamma[-I x] - Gamma[-I x, -2 n \[Pi]] + E^(4 \[Pi] x) Gamma[-I x, (-2 - 2 I) n \[Pi]])}, 5]


but the values don't match:

This seems to be widespread in my version of Mathematica (13.0.1.0, windows 10 x64), I just found out nothing seems to work.

c = 1; b = 1; x = 1; n = 2; N[{Integrate[E^(2 \[Pi] I t n) HypergeometricU[c + I x, 1 + c + I x, 2 \[Pi] (1 + I t)] , {t, 0, 1}], E^(-2 n \[Pi]) (2 \[Pi])^(-c - I x) (-I ExpIntegralE[c + I x, -2 n \[Pi]] - 2 (1 + I)^(-1 - c - I x) ExpIntegralE[c + I x, (-2 - 2 I) n \Pi]])}, 5]


Below a quick view of the new formula:

Any ideas? I'm getting a little desperate with so many bugs that I'm not sure what's going on.

$Version (* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *) Clear["Global*"] x1[n_, x_] = Assuming[x > 0 && n > 0, Integrate[ (1 + I t)^(-1 - I x) E^(2 π I n t), {t, 0, 1}] // Simplify] (* -I E^(-π (2 n + x)) n^(I x) (2 π)^( I x) ((-1 + E^(2 π x)) Gamma[-I x] + Gamma[-I x, -2 n π] - E^(2 π x) Gamma[-I x, (-2 - 2 I) n π]) *) x2[n_?Positive, x_?Positive] := Integrate[ (1 + I t)^(-1 - I x) E^(2 π I n t), {t, 0, 1}] // FullSimplify x3[n_?Positive, x_?Positive] := NIntegrate[ (1 + I t)^(-1 - I x) E^(2 π I n t), {t, 0, 1}, WorkingPrecision -> 20, MinRecursion -> 5, MaxRecursion -> 20] {x1[1, 2], x2[1, 2], x3[1, 2]} // N (* {-0.872307 + 0.00711754 I, -0.662633 + 0.0372631 I, -0.872307 + 0.00711754 I} *)  x1 is consistent with numerical integration, i.e., x3 And @@ Flatten[ Outer[x1[#1, #2] == x3[#1, #2] &, Range[1/4, 5, 1/4], Range[1/4, 5, 1/4]]] (* True *)  EDIT: As requested in a comment, replacing(1 + I t)^(-1 - I x) with (1 + I t)^(-c - I x) and c > 0 x4[n_, x_, c_] = Assuming[x > 0 && n > 0 && c > 0, Integrate[ (1 + I t)^(-c - I x) E^(2 π I n t), {t, 0, 1}] // FullSimplify] (* -I E^(π (-I c - 2 n - x)) n^(-1 + c + I x) (2 π)^(-1 + c + I x) ((E^(2 I c π) - E^(2 π x)) Gamma[1 - c - I x] - E^(2 I c π) Gamma[1 - c - I x, -2 n π] + E^(2 π x) Gamma[1 - c - I x, (-2 - 2 I) n π]) *)  x4 reduces to x1 for c == 1 x1[n, x] == x4[n, x, 1] // Simplify (* True *)  EDIT 2: For the revised question, x5[n_, x_, c_] = Assuming[c > 0 && n > 0 && x > 0, Integrate[ E^(2 π I t n) HypergeometricU[c + I x, 1 + c + I x, 2 π (1 + I t)], {t, 0, 1}] // Simplify] (* -(1/(2 π)) I E^(π (-I c - 2 n - x)) n^(-1 + c + I x) ((E^(2 I c π) - E^(2 π x)) Gamma[1 - c - I x] - E^(2 I c π) Gamma[1 - c - I x, -2 n π] + E^(2 π x) Gamma[1 - c - I x, (-2 - 2 I) n π]) *) x6[n_?Positive, x_?Positive, c_?Positive] := NIntegrate[ E^(2 π I t n) HypergeometricU[c + I x, 1 + c + I x, 2 π (1 + I t)], {t, 0, 1}, WorkingPrecision -> 20, MinRecursion -> 5, MaxRecursion -> 20] {x5[n, x, c], x6[n, x, c]} /. {c -> 1.025, x -> 1.025, n -> 2.025} // N (* {0.0100435 + 0.0187961 I, 0.0100435 + 0.0187961 I} *)  • Thanks a lot, let me try it. Btw Are you able to come up with a generic closed formula as a function of any known functions? Commented May 16 at 23:28 • Oh, looks like it's the expression in the brackets. Awesome. Commented May 16 at 23:35 With your version but on a Mac $Version

(* "13.0.1 for Mac OS X x86 (64-bit) (January 28, 2022)" *)

Clear["Global*"]

x5[n_, x_, c_] = Assuming[c > 0 && n > 0 && x > 0,
Integrate[
E^(2 π I t n) HypergeometricU[c + I x, 1 + c + I x,
2 π (1 + I t)], {t, 0, 1}] // Simplify]

(* -(1/(2 π))
I E^(π (-I c - 2 n - x))
n^(-1 + c +
I x) ((E^(2 I c π) - E^(2 π x)) Gamma[1 - c - I x] -
E^(2 I c π) Gamma[1 - c - I x, -2 n π] +
E^(2 π x) Gamma[1 - c - I x, (-2 - 2 I) n π]) *)

x6[n_?Positive, x_?Positive, c_?Positive] :=
NIntegrate[
E^(2 π I t n) HypergeometricU[c + I x, 1 + c + I x,
2 π (1 + I t)], {t, 0, 1},
WorkingPrecision -> 20,
MinRecursion -> 5,
MaxRecursion -> 20]

{x5[n, x, c], x6[n, x, c]} /.
{c -> 1.025, x -> 1.025, n -> 2.025} // N

(* {0.0100435 + 0.0187961 I, 0.0100435 + 0.0187961 I} *)


Also, note that your integrand simplifies

Assuming[c > 0 && n > 0 && x > 0,
integrand =
E^(2 π I t n) HypergeometricU[c + I x, 1 + c + I x, 2 π (1 + I t)] //
Simplify]

(* E^(2 I n π t) (2 π)^(-c - I x) (1 + I t)^(-c - I x) *)

• I hadn't noticed that that function could be simplified to the first form. In that case it doesn't matter, the 2nd form won't be any different. Commented May 18 at 6:21
• The purpose of this forum is not to remotely execute code for others. To do that, use the Wolfram Cloud. Commented May 18 at 17:57
• Ok, thanks for what you've done so far anyway. I need to find out what's wrong with my installation. Commented May 18 at 19:17
• I've tried your tip and was amazed to see my Windows answer is different from the cloud. Great tip, thanks. I didn't know that I could use that and for free. The validation now works. Commented May 18 at 19:55