Skip to content

Implement the Gamma function with very low relative error - #47

Merged
Axect merged 36 commits into
Axect:masterfrom
JSorngard:fukushima_gamma
Feb 6, 2026
Merged

Implement the Gamma function with very low relative error#47
Axect merged 36 commits into
Axect:masterfrom
JSorngard:fukushima_gamma

Conversation

@JSorngard

@JSorngard JSorngard commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

Hello!

I found this interesting implementation of the Gamma function by T. Fukushima (same person that published the algorithm I use in the lambert_w crate) in Fortran. It has a lower relative error than the current implementation (often within a single ulp), so I thought I could try implementing it in Rust.

This PR implements this new Gamma function and makes the tests more stringent to show the reduced error.

@JSorngard

JSorngard commented Oct 31, 2025

Copy link
Copy Markdown
Contributor Author

It seems the tests fail because pyo3 expects an older version of python (3.13) than is available on the CI image (3.14).

The tests compile and run fine on my local machine.

I don't know how to fix the problem though.

@JSorngard

JSorngard commented Oct 31, 2025

Copy link
Copy Markdown
Contributor Author

It may be that updating the pyo3 dependency of peroxide will make it able to compile on the latest CI images. I opened that PR in Axect/Peroxide#89.

@JSorngard

Copy link
Copy Markdown
Contributor Author

If this PR is interesting then this code might also be interesting as it contains functions for computing the incomplete and complementary incomplete Gamma functions.

@JSorngard

Copy link
Copy Markdown
Contributor Author

Should the polynomial function also be exported outside the crate?

@Axect Axect left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement! Thank you for great contributions!

@Axect

Axect commented Feb 6, 2026

Copy link
Copy Markdown
Owner

Should the polynomial function also be exported outside the crate?

I think current implementation pub(crate) is okay enough 👍

@Axect
Axect merged commit e7a0802 into Axect:master Feb 6, 2026
6 of 12 checks passed
Axect added a commit that referenced this pull request Feb 6, 2026
- Improve Gamma function (#47)
@JSorngard
JSorngard deleted the fukushima_gamma branch February 6, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants