# Gamma function: Mathematica disagrees with Wolfram Alpha

When I enter

N[Gamma[2, -40]]


into my Mathematica notebook, I get

-9.18003*10^18 + 1124.23 i


However, Wolfram Alpha will give me a real expression. Why do these two numbers disagree - and which one is correct?

• It is a precision issue. Use arbitrary precision rather than machine precision: N[Gamma[2, -40], 20] – Bob Hanlon Jun 26 '17 at 13:41
• @BobHanlon Apparently I also have to wrap N[x, 20] around Gamma whenever I use Gamma in longer equations, if I want to kill those imaginary terms in the result? Sounds somewhat suspicious to me. – FooBar Jun 26 '17 at 13:48
• Using arbitrary precision causes Mma to track and control the precision. Look at N[Gamma[2, -40], 6]. You could also force the Gamma function to evaluate before asking for the numerical approximation: Evaluate[Gamma[2, -40]] // N – Bob Hanlon Jun 26 '17 at 14:00
• @BobHanlon the Evaluate, // chain also yields an imaginary component – FooBar Jun 26 '17 at 14:02
• Must be a version difference. There is no imaginary component with version 11.1.1 for Mac OS X x86 (64-bit) (April 18, 2017) – Bob Hanlon Jun 26 '17 at 14:04

This is a precision issue. If you use arbitrary precision rather than machine precision, Mathematica will track and control the precision.

$Version (* "10.4.1 for Mac OS X x86 (64-bit) (April 11, 2016)" *) N[Gamma[2, -40]] (* -9.18003*10^18 + 1124.23 I *) N[Gamma[2, -40], 30] // Chop (* -9.18002540664377943090809651921*10^18 *)  This Gamma function can be evaluated exactly using FunctionExpand Gamma[2, -40] // FunctionExpand (* -39 E^40 *) Gamma[2, -40] // FunctionExpand // N (* -9.18003*10^18 *)  A later version does not have these problems $Version

(*  "11.1.1 for Mac OS X x86 (64-bit) (April 18, 2017)"  *)

Gamma[2, -40]

(*  -39 E^40  *)

Gamma[2, -40] // N

(*  -9.18003*10^18  *)