Skip to content

feat(Algebra/Order/BigOperators/Expect): add lemmas and strict variants#33662

Open
Pjotr5 wants to merge 8 commits intoleanprover-community:masterfrom
Pjotr5:expect-lemmas
Open

feat(Algebra/Order/BigOperators/Expect): add lemmas and strict variants#33662
Pjotr5 wants to merge 8 commits intoleanprover-community:masterfrom
Pjotr5:expect-lemmas

Conversation

@Pjotr5
Copy link
Copy Markdown
Contributor

@Pjotr5 Pjotr5 commented Jan 6, 2026

Summary

  • Combine le_expect_nonempty_of_subadditive and le_expect_of_subadditive into a single lemma le_expect_of_subadditive.
    The extra assumptions (hs : s.Nonempty) and (h_zero : m 0 = 0) are unnecessary (since m 0 = 0 follows from h_div).
    This requires a small downstream update to Mathlib/Analysis/RCLike/Basic.lean (norm_expect_le).

  • Add strict-inequality variants:
    expect_lt_expect, expect_lt, lt_expect.

  • Add existence lemmas:
    exists_le_of_expect_le_expect, exists_le_of_le_expect, exists_le_of_expect_le,
    and exists_lt_of_expect_lt_expect.


Open in Gitpod

@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 Jan 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 6, 2026

PR summary 68e18bf8ed

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ exists_le_of_expect_le
+ exists_le_of_expect_le_expect
+ exists_le_of_le_expect
+ exists_lt_of_expect_lt_expect
+ expect_lt
+ expect_lt_expect
+ lt_expect
- le_expect_nonempty_of_subadditive

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).

@mathlib-triage mathlib-triage bot assigned kim-em and unassigned thorimur Mar 15, 2026
Copy link
Copy Markdown
Contributor

@b-mehta b-mehta left a comment

Choose a reason for hiding this comment

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

I've left a few preliminary comments, will come back for a more detailed review once those are addressed

Comment on lines 92 to +98
-- TODO: Contribute back better docstring to `le_prod_of_submultiplicative`
/-- If `m` is a subadditive function (`m (x + y) ≤ m x + m y`, `m 0 = 0`) preserved under division
/-- If `m` is a subadditive function (`m (x + y) ≤ m x + m y`) preserved under division
by a natural, then `m (𝔼 i ∈ s, f i) ≤ 𝔼 i ∈ s, m (f i)`. -/
lemma le_expect_of_subadditive (h_zero : m 0 = 0) (h_add : ∀ a b, m (a + b) ≤ m a + m b)
lemma le_expect_of_subadditive (h_add : ∀ a b, m (a + b) ≤ m a + m b)
(h_div : ∀ (n : ℕ) a, m (a /ℚ n) = m a /ℚ n) : m (𝔼 i ∈ s, f i) ≤ 𝔼 i ∈ s, m (f i) :=
le_expect_of_subadditive_on_pred (p := fun _ ↦ True) h_zero (by simpa) (by simp) (by simpa)
(by simp)
le_expect_of_subadditive_on_pred (p := fun _ ↦ True) (by convert h_div 0 0 <;> simp)
(by simpa) (by simp) (by simpa) (by simp)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice catch, although I wonder if this actually means h_div should be stated for n != 0 in le_expect_nonempty_of_subadditive. @YaelDillies I guess you wrote these?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Implemented the style updates. Regarding h_div: I agree it feels a bit artificial to derive m 0 = 0 from h_div 0 0.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Pjotr5 note you can also click on "apply suggestion" on github. This is much easier and automatically resolves the comment.

Comment on lines +109 to +110
lemma expect_lt_expect (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i)
: 𝔼 i ∈ s, f i < 𝔼 i ∈ s, g i := by
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
lemma expect_lt_expect (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i)
: 𝔼 i ∈ s, f i < 𝔼 i ∈ s, g i := by
lemma expect_lt_expect (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :
𝔼 i ∈ s, f i < 𝔼 i ∈ s, g i := by

This is what mathlib's style guidelines say, and be sure to make this change below too.


lemma expect_lt (hle : ∀ x ∈ s, f x ≤ a) (hlt : ∃ x ∈ s, f x < a)
: 𝔼 i ∈ s, f i < a := by
rw [←expect_const (hlt.imp (fun _ => And.left)) a]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
rw [←expect_const (hlt.imp (fun _ => And.left)) a]
rw [← expect_const (hlt.imp (fun _ => And.left)) a]

@b-mehta
Copy link
Copy Markdown
Contributor

b-mehta commented Mar 22, 2026

Oh, and sorry for the delay on this one, I think you got an unlucky sequence of assignments! Thanks for your contribution though!

@b-mehta b-mehta assigned b-mehta and unassigned kim-em Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-algebra Algebra (groups, rings, fields, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants