# Fix for conversion of Gamma function in Mathematica interface

Reported by: Owned by: gh-mwageringel major sage-8.7 interfaces Mathematica dimpase, etn40ff Markus Wageringel Dima Pasechnik, Salvatore Stella N/A 4d8f85a (Commits) 4d8f85aada8a67432827f8079250e6fabb3010f9

### Description

Converting expressions involving Gamma functions from Mathematica to Sage currently fails:

```sage: mathematica('Gamma[4/3]').sage()
...
NotImplementedError: Unable to parse Mathematica                 output: Gamma(4/3)

sage: mathematica('Gamma[4/3, 1]').sage()  # This should be the upper incomplete Gamma function `gamma(4/3, 1)` in Sage.
gamma_inc_lower(4/3, 1)

sage: mathematica('Gamma[4/3, 0, 1]').sage()
...
NotImplementedError: Unable to parse Mathematica                 output: Gamma(4/3, 0, 1)
```

Moreover, this should convert to `Gamma[4/3, 0, 1]` in Mathematica:

```sage: gamma_inc_lower(4/3, 1)._mathematica_()
Gamma[4/3, 1]
```

The reason for this is that all three kinds of Gamma functions (the (complete) Gamma, the upper incomplete Gamma `gamma_inc` and the lower incomplete `gamma_inc_lower`) all convert to `Gamma` in Mathematica, but the conversion does not properly take into account that the arguments to those functions are different. Conversely, `Gamma` is currently registered to convert to `gamma_inc_lower`, which is always wrong and fails as shown above.

More precisely, there are the following correspondences:

• `gamma(x)` and `Gamma[x]`,
• `gamma(x, y)` and `Gamma[x, y]`,
• `gamma_inc_lower(x, z)` and `Gamma[x, 0, z]`,
• `gamma(x, y) - gamma(x, z)` and `Gamma[x, y, z]`.

The Mathematica documentation for this can be found here: https://reference.wolfram.com/language/ref/Gamma.html.

This was tested with Sage 8.6 and Mathematica 11.3.

### comment:1 Changed 13 months ago by gh-mwageringel

• Authors set to Markus Wageringel
• Branch set to u/gh-mwageringel/mathematica_gamma
• Status changed from new to needs_review

New commits:

 ​4d8f85a `fix Mathematica conversions of Gamma function`

### comment:2 Changed 13 months ago by tscrim

Dima, Salvatore, could one of you test this? Otherwise I can test it when I get back to Australia next month.

### comment:3 Changed 13 months ago by etn40ff

It works as advertised and all the tests pass on my machine. My knowledge of the Gamma function is too limited to spot any mathematical issue.

Feel free to set this to positive review if you are confident on the math side.

### comment:4 Changed 13 months ago by dimpase

It'd help to know what Mathematica version you tested it with, thanks.

### comment:5 Changed 13 months ago by etn40ff

Mathematica 11.3.0 Kernel for Linux x86 (64-bit)

### comment:6 Changed 13 months ago by dimpase

• Reviewers set to Dima Pasechnik, Salvatore Stella
• Status changed from needs_review to positive_review

Looks good to me. Tested with Mathematica 11.2 on Linux

Thank you.

### comment:8 Changed 13 months ago by vbraun

• Branch changed from u/gh-mwageringel/mathematica_gamma to 4d8f85aada8a67432827f8079250e6fabb3010f9
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.