Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: an equality condition for AM-GM inequality #19435

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

hehepig166
Copy link
Collaborator

@hehepig166 hehepig166 commented Nov 24, 2024

Add some theorems on the equality condition of the weighted AM-GM inequality for real-valued nonnegative functions, referring to geom_mean_arith_mean_weighted_eq_iff in Mathlib/Analysis/MeanInequalities.lean.


Open in Gitpod

Add a theorem of equality condition for weighted version of AM-GM inequality for real-valued nonnegative functions. See the theorem `geom_mean_arith_mean_weighted_eq_iff`.
@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 Nov 24, 2024
Copy link

github-actions bot commented Nov 24, 2024

PR summary 0de365a3b0

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ geom_mean_eq_arith_mean_weighted_iff
+ geom_mean_eq_arith_mean_weighted_iff_aux_of_pos
+ geom_mean_lt_arith_mean_weighted_iff_of_pos

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

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

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


No changes to technical debt.

You can run this locally as

./scripts/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-analysis Analysis (normed *, calculus) label Nov 24, 2024
@hehepig166 hehepig166 self-assigned this Nov 24, 2024
@hehepig166 hehepig166 changed the title feat: add an equality condition for AM-GM inequality feat: an equality condition for AM-GM inequality Nov 24, 2024
Copy link
Collaborator

@YaelDillies YaelDillies left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Mathlib/Analysis/MeanInequalities.lean Outdated Show resolved Hide resolved
Mathlib/Analysis/MeanInequalities.lean Outdated Show resolved Hide resolved
Mathlib/Analysis/MeanInequalities.lean Outdated Show resolved Hide resolved
@YaelDillies YaelDillies added the awaiting-author A reviewer has asked the author a question or requested changes label Nov 25, 2024
@YaelDillies
Copy link
Collaborator

The usual way to prove the equality case of an inequality is to first prove its strict inequality case. Could you please do that here? Thanks!

@hehepig166
Copy link
Collaborator Author

hehepig166 commented Nov 26, 2024

The usual way to prove the equality case of an inequality is to first prove its strict inequality case. Could you please do that here? Thanks!

Do you mean I should write a new theorem to handle the strict inequality case first, or just modify the current proof to include it as a step?

something like this?

theorem geom_mean_lt_arith_mean_weighted' (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 < w i)
    (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 < z i) (hzne : ∃ j ∈ s, ∃ k ∈ s, z j ≠ z k) :
    ∏ i ∈ s, z i ^ w i < ∑ i ∈ s, w i * z i := by
  sorry

@YaelDillies
Copy link
Collaborator

You should write a new theorem 😄

@hehepig166
Copy link
Collaborator Author

The strict inequality equivalent condition is done (maybe?).

I ended up splitting the equality case into two versions to make proving the strict inequality more convenient (yes, I used the equality condition to prove the strict inequality, which was quite easy to write).
As for the version where weights can be zero, I tried writing the strict inequality case, but the equivalent condition turned out to be too complex.

@hehepig166 hehepig166 removed the awaiting-author A reviewer has asked the author a question or requested changes label Nov 27, 2024
@acmepjz
Copy link
Collaborator

acmepjz commented Nov 29, 2024

The usual way to prove the equality case of an inequality is to first prove its strict inequality case. Could you please do that here? Thanks!

But I think eq_iff case is enough. Since we already have le, so if it's not eq it must be lt.

Copy link
Collaborator

@acmepjz acmepjz left a comment

Choose a reason for hiding this comment

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

Looks good, though I'm not familiar with elementary inequalities.

Mathlib/Analysis/MeanInequalities.lean Outdated Show resolved Hide resolved
Mathlib/Analysis/MeanInequalities.lean Outdated Show resolved Hide resolved
Mathlib/Analysis/MeanInequalities.lean Outdated Show resolved Hide resolved
@hehepig166 hehepig166 requested review from acmepjz and removed request for 0art0, hrmacbeth, dagurtomas, 77Tigers, 4hma4d and ADedecker November 30, 2024 06:14
Copy link
Collaborator

@loefflerd loefflerd left a comment

Choose a reason for hiding this comment

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

Here are a few more small tips. This is looking pretty good now, thanks for the nice contribution!

Comment on lines +195 to +197
theorem geom_mean_eq_arith_mean_weighted_iff_aux_of_pos (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 < w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) :
∏ i ∈ s, z i ^ w i = ∑ i ∈ s, w i * z i ↔ ∀ j ∈ s, z j = ∑ i ∈ s, w i * z i := by
Copy link
Collaborator

Choose a reason for hiding this comment

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

In this theorem, w and z can be inferred from the other arguments – you can't prove that ∀ i ∈ s, 0 < w i without knowing what w is – so the usual library convention would be to make them implicit. That is, replace the round brackets with curly ones, {w z : ι → ℝ}. (Same applies to the other theorems here too.)

On another matter: is this first theorem only useful as a stepping-stone to the theorems later on in the file (as the aux in the name suggests)? If it is no longer useful once those theorems are proved (i.e. if the later theorems trivially imply it) then you can mark it as private, so it doesn't appear in the reference manual and can't be used outside this file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the review.
I found two simililar theorem in Jasen.lean, StrictConvexOn.map_sum_eq_iff and StrictConvexOn.map_sum_eq_iff' (here), and I followed the same style to write the two theorems here. I'm not sure if I should make the 'aux' one private or rename it properly. (I also tried to name it something like geom_mean_eq_arith_mean_weighted_iff' , but the linter didn't accept the apostrophe)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Aha! The linter shouldn't complain about the apostrophe as long as there is a doc-string. In your case you clearly meant to make a doc-string (the text preceding the theorem); but doc-strings need to start with /-- (two dashes), not /- (one dash) which is just an ordinary comment. So this needs to be fixed anyway; and it will have the side-effect of stopping the linter complaining.

I had overlooked this until now, so it's lucky that you made the remark about linters.

· rcases A with ⟨i, his, hzi, hwi⟩
rw [prod_eq_zero his]
· constructor
· intro h; rw [← h]; intro j hj
Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally we discourage chaining together multiple tactics on one line.

· simp only [not_exists, not_and] at A
have hz' := fun i h => lt_of_le_of_ne (hz i h) (fun a => (A i h a.symm) (ne_of_gt (hw i h)))
have := strictConvexOn_exp.map_sum_eq_iff hw hw' fun i _ => Set.mem_univ <| log (z i)
simp only [exp_sum, (· ∘ ·), smul_eq_mul, mul_comm (w _) (log _)] at this
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does simp only [(· ∘ ·)] do? I've never seen this syntax before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

While reading the geom_mean_le_arith_mean_weighted theorem earlier in the same file, I noticed this. Deleting it doesn't affect local compilation, but I kept it in case it was a historical issue. Perhaps the code is a bit outdated due to Lean version differences?

I'll delete it in my theorem. What about the original geom_mean_le_arith_mean_weighted theorem?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's a hangover from an old version. If it's not needed please delete it (here and in the earlier proof). Always use as few simp lemmas as you can.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What does simp only [(· ∘ ·)] do? I've never seen this syntax before.

I think it's equivalent to Function.comp or Function.comp_def. (· ∘ ·) is for cuteness 😂

Comment on lines +216 to +217
· apply Eq.congr <;> [apply prod_congr rfl; apply sum_congr rfl]
<;> intro i hi <;> simp [exp_mul, exp_log (hz' i hi)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

More line breaks, and putting the <;> at the end of lines rather than the beginning, would be easier to read.

Comment on lines +233 to +234
have h (i) (_ : i ∈ s) : w i * z i ≠ 0 → w i ≠ 0 := by aesop
have h' (i) (_ : i ∈ s) : z i ^ w i ≠ 1 → w i ≠ 0 := by aesop
Copy link
Collaborator

Choose a reason for hiding this comment

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

These haves seem to be duplicating existing lemmas in the library, eg the first is just left_ne_zero_of_mul.

have h' (i) (_ : i ∈ s) : z i ^ w i ≠ 1 → w i ≠ 0 := by aesop
rw [← sum_filter_of_ne h, ← prod_filter_of_ne h', geom_mean_eq_arith_mean_weighted_iff_aux_of_pos]
· simp
· simp (config := { contextual := true }) [(hw _ _).gt_iff_ne]
Copy link
Collaborator

Choose a reason for hiding this comment

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

There was a Zulip thread recently about a new cleaner syntax for this, something like simp +contextual [foo]

@loefflerd loefflerd added the awaiting-author A reviewer has asked the author a question or requested changes label Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-author A reviewer has asked the author a question or requested changes new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-analysis Analysis (normed *, calculus)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants