-
Notifications
You must be signed in to change notification settings - Fork 343
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
base: master
Are you sure you want to change the base?
Conversation
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`.
PR summary 0de365a3b0Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
There was a problem hiding this 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!
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?
|
You should write a new theorem 😄 |
…ty case into two versions.
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). |
But I think |
There was a problem hiding this 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.
There was a problem hiding this 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!
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😂
· apply Eq.congr <;> [apply prod_congr rfl; apply sum_congr rfl] | ||
<;> intro i hi <;> simp [exp_mul, exp_log (hz' i hi)] |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These have
s 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] |
There was a problem hiding this comment.
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]
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
inMathlib/Analysis/MeanInequalities.lean
.