Upper incomplete Gamma function numerical differences

I have the following issue. Using Mathematica 11.2 (with Rubi loaded) I find that e.g.

In[504]:= Gamma[-1/3, 2] // N

Out[504]= 0.0353296 + 5.01821*10^-16 I

The imaginary part is absurd, and the correct approximation is the real part of the output. Indeed, if I look for the result using the Wolfram query, it is the correct one. I am pretty sure that this is a numerical issue since I am getting things like

In[507]:= Gamma[-10/3, 2] // N

Out[507]= 0.00234763 + 0. I

What can I do to resolve this? Is it something known?

• MMA version 12.1 gives: 0.0353296 Feb 23 '21 at 16:07
• I don't see this with v12.2, try Gamma[-1/3, 2] // N[#, 20] & // N Feb 23 '21 at 16:31
• Again, I get 0.0353296 + 0. I :( Feb 23 '21 at 17:08
• Feb 23 '21 at 17:20
• I know I could also use Re[] but that is not the point. The question is about the origin of this issue. Would some extra info help perhaps? Feb 23 '21 at 17:24

I ran these on the WolframCloud and seemingly the issue is fixed now on v12.2.0.

$Version Gamma[-1/3,2] N@% Gamma[-120/320, 220]  12.2.0 for Linux x86 (64-bit) (November 16, 2020) Gamma[-1/3,2] 0.0353296 0.035329560217661993 If none of these methods work, I would either do these calculations on the cloud or upgrade your license to the newest version. The issue is one of numerical precision & underlying algorithms. I will say that the relative magnitude of the complex term is small enough in comparison to the real term to trust in the use of Chop as recommended by others. • Thanks, actually it was resolved already from 12.1 Feb 24 '21 at 12:45 $Version

(* "12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019)" *)

Gamma[-10/3, 2] // N

(* 0.00234763 + 0. I *)


A transformation for Gamma[a, z] is

repl = Gamma[a_, z_] -> (-z^a + E^z*Gamma[1 + a, z])/(E^z*a);


Verifying,

Gamma[a, z] == (Gamma[a, z] /. repl) // FullSimplify

(* True *)

Gamma[-10/3, 2] //.
Gamma[a_?Negative, z_] -> (-z^a + E^z*Gamma[1 + a, z])/(E^z*a) //
Simplify // N

(* 0.00234763 *)
`