Skip to content

feat(Probability): add gamma distribution MGF, mean and variance#37802

Closed
huaizhangchu wants to merge 3 commits intoleanprover-community:masterfrom
huaizhangchu:gamma-mgf-moments
Closed

feat(Probability): add gamma distribution MGF, mean and variance#37802
huaizhangchu wants to merge 3 commits intoleanprover-community:masterfrom
huaizhangchu:gamma-mgf-moments

Conversation

@huaizhangchu
Copy link
Copy Markdown
Contributor

@huaizhangchu huaizhangchu commented Apr 8, 2026

This PR adds the moment generating function, mean, and variance for the gamma distribution.

gammaMeasure_mgf: the MGF of the gamma distribution with shape a and rate r at t < r is (r / (r - t)) ^ a.
gammaMeasure_mean: the mean of the gamma distribution is a / r.
gammaMeasure_variance: the variance of the gamma distribution is a / r ^ 2.

The auxiliary lemmas in section RPowDivSub (e.g., hasDerivAt_rpow_div_sub, iteratedDeriv_two_rpow_div_sub) are currently placed in this file. Happy to move them elsewhere if reviewers think they belong in a more general location.

AI Disclosure: This PR was primarily authored with the assistance of Claude. The workflow involved providing mathematical requirements and iteratively resolving compilation errors based on Lean's compiler feedback. I have manually reviewed the final output for mathematical correctness and logical consistency.

@github-actions github-actions bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Apr 8, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

Welcome new contributor!

Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the awaiting-author tag, or another reason described in the Lifecycle of a PR. The review dashboard has a dedicated webpage which shows whether your PR is on the review queue, and (if not), why.

If you haven't already done so, please come to https://leanprover.zulipchat.com/, introduce yourself, and mention your new PR.

Thank you again for joining our community.

@github-actions github-actions bot added the large-import Automatically added label for PRs with a significant increase in transitive imports label Apr 8, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

PR summary 2d105a290d

Import changes exceeding 2%

% File
+6.00% Mathlib.Probability.Distributions.Gamma

Import changes for modified files

Dependency changes

File Base Count Head Count Change
Mathlib.Probability.Distributions.Gamma 2516 2667 +151 (+6.00%)
Import changes for all files
Files Import difference
Mathlib.Probability.Distributions.Exponential Mathlib.Probability.Distributions.Gamma 151

Declarations diff

+ deriv_rpow_div_sub_zero
+ gammaMeasure_integrable_exp_mul
+ gammaMeasure_mean
+ gammaMeasure_mgf
+ gammaMeasure_variance
+ gammaMeasure_zero_mem_interior_integrableExpSet
+ hasDerivAt_rpow_div_sub
+ hasDerivAt_rpow_div_sub'
+ iteratedDeriv_two_rpow_div_sub
+ mgf_id_gammaMeasure_eventually

You can run this locally as follows
## summary with just the declaration names:
./scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions bot added the t-measure-probability Measure theory / Probability theory label Apr 8, 2026
@grunweg
Copy link
Copy Markdown
Contributor

grunweg commented Apr 9, 2026

Hello from the triage team! Can I ask if you used AI to prepare your PR? (Your code shares some features of AI-generated code.) If so, please indicate so in the PR description; this is useful information for reviewing your PR.)

@grunweg grunweg added the awaiting-author A reviewer has asked the author a question or requested changes. label Apr 9, 2026
@huaizhangchu
Copy link
Copy Markdown
Contributor Author

Hello from the triage team! Can I ask if you used AI to prepare your PR? (Your code shares some features of AI-generated code.) If so, please indicate so in the PR description; this is useful information for reviewing your PR.)

Hi! Yes, I used Claude to help prepare this PR. My process was to provide the mathematical goals to the AI and then iteratively refine the code by feeding Lean's compiler errors back into it until it bypassed the checks.

I have added a note to the PR description as requested. Since the code was largely AI-generated, I’d particularly appreciate feedback on whether the proof style and lemma naming align with Mathlib’s idiomatic standards. Thanks for the heads-up!

@huaizhangchu
Copy link
Copy Markdown
Contributor Author

-awaiting-author

@github-actions github-actions bot removed the awaiting-author A reviewer has asked the author a question or requested changes. label Apr 9, 2026
@grunweg grunweg added the LLM-generated PRs with substantial input from LLMs - review accordingly label Apr 9, 2026
@EtienneC30
Copy link
Copy Markdown
Member

We appreciate your desire to contribute to mathlib, but unfortunately we will have to close this PR. The LLM-generated code in this PR fails to meet our standards, and while reviewers and maintainers are willing to help new contributors to improve the quality of their code through the review process, this can only be done if the code is indeed written by somebody who learns in the process, otherwise the quality will not improve in future PRs and the effort required will be larger than the benefit.

@EtienneC30 EtienneC30 closed this Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

large-import Automatically added label for PRs with a significant increase in transitive imports LLM-generated PRs with substantial input from LLMs - review accordingly new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-measure-probability Measure theory / Probability theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants