Skip to content

feat(Probability/HypothesisTesting): add Neyman-Pearson lemma#39791

Open
zixiaowang17 wants to merge 3 commits into
leanprover-community:masterfrom
zixiaowang17:NPlemma
Open

feat(Probability/HypothesisTesting): add Neyman-Pearson lemma#39791
zixiaowang17 wants to merge 3 commits into
leanprover-community:masterfrom
zixiaowang17:NPlemma

Conversation

@zixiaowang17

@zixiaowang17 zixiaowang17 commented May 24, 2026

Copy link
Copy Markdown

This PR adds Probability/HypothesisTesting/NeymanPearson.lean, formalizing the classical Neyman-Pearson lemma with reference

Ingster, Y. and Suslina, I.A., 2012. Nonparametric goodness-of-fit testing under Gaussian models (Vol. 169). Springer Science & Business Media.
-/

The main definitions are:

  • ProbabilityTheory.NeymanPearson.npLikelihoodRatio
  • ProbabilityTheory.NeymanPearson.npTest
  • ProbabilityTheory.NeymanPearson.npSumError

The main theorem is:

  • ProbabilityTheory.NeymanPearson.neyman_pearson

We state the theorem in the weighted form ∫ T dP + t * ∫ (1 - T) dQ, over measurable tests T : Ω → ℝ with values in [0, 1], using P + Q as the canonical dominating measure; rather than starting with the constrained formulation that fixes the Type I error and minimizes the Type II error. The reasons are two fold.

First, it can be thought as the Lagrangian form of the classical constrained Neyman-Pearson problem.

Second, this weighted form is often arises in applications, such as, in minimax lower-bound arguments for functional estimation, where one typically reduces estimation lower bounds to testing inequalities involving weighted sums of error probabilities.

Worflow with AI: we first manually wrote a blueprint in latex with every definition and lemma we need NL_Blueprint_NP_Lemma.pdf. then we checked the Mathlib API with claude code, chatgpt and LeanSearch, We manually wrote the outline, in the outline version we deleted the discussion on gamma in the blueprint - since we have used the version of the NP lemma that uses the likelihood ratio to construct the test, rather than writing in terms of comparisons of Radon-Nikodym derivatives with a common dominating measure, and hence have used gamma to arbitrarily define likelihood-ratio sets of measure zero under the null hypothesis. This choice is motivated by the downstream derivation of errors of NP tests. since we are unfamiliar with mathlib naming style, we used claude code skill for proof golfing and some syntax correction, eg whether should use unfold or simp only [];

Co-authored-by: Rajarshi Mukherjee ram521@mail.harvard.edu


@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 May 24, 2026
@github-actions

Copy link
Copy Markdown

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 t-measure-probability Measure theory / Probability theory label May 24, 2026
@github-actions

Copy link
Copy Markdown

PR summary f95e015368

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Probability.Decision.HypothesisTesting.NeymanPearson (new file) 2317

Declarations diff

+ measurable_npLikelihoodRatio
+ measurable_npTest
+ neyman_pearson
+ npLikelihoodRatio
+ npSumError
+ npTest
+ npTest_le_one
+ npTest_nonneg

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

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

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.


No changes to strong technical debt.
No changes to weak technical debt.

@grunweg

grunweg commented May 24, 2026

Copy link
Copy Markdown
Contributor

Per zulip, the code in this PR is LLM-generated.
I've labelled the PR accordingly. Note that the PR description should be updated to match the zulip comment.

@grunweg grunweg added the LLM-generated PRs with substantial input from LLMs - review accordingly label May 24, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LLM-generated PRs with substantial input from LLMs - review accordingly merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) 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.

2 participants