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

[Merged by Bors] - refactor: Let positivity handle ENNReal-valued ofNat #17212

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions Mathlib/Data/ENNReal/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -685,33 +685,6 @@ end OrdConnected

end Set

namespace Mathlib.Meta.Positivity

open Lean Meta Qq

/-- Extension for the `positivity` tactic: `ENNReal.toReal`. -/
@[positivity ENNReal.toReal _]
def evalENNRealtoReal : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(ENNReal.toReal $a) =>
assertInstancesCommute
pure (.nonnegative q(ENNReal.toReal_nonneg))
| _, _, _ => throwError "not ENNReal.toReal"

/-- Extension for the `positivity` tactic: `ENNReal.ofNNReal`. -/
@[positivity ENNReal.ofNNReal _]
def evalENNRealOfNNReal : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ≥0∞), ~q(ENNReal.ofNNReal $a) =>
let ra ← core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa => pure <| .positive q(ENNReal.coe_pos.mpr $pa)
| _ => pure .none
| _, _, _ => throwError "not ENNReal.ofNNReal"

end Mathlib.Meta.Positivity

YaelDillies marked this conversation as resolved.
Show resolved Hide resolved
@[deprecated (since := "2023-12-23")] protected alias
ENNReal.le_inv_smul_iff_of_pos := le_inv_smul_iff_of_pos
@[deprecated (since := "2023-12-23")] protected alias
Expand Down
7 changes: 4 additions & 3 deletions Mathlib/Tactic/Positivity/Core.lean
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ variable {A : Type*} {e : A}
lemma lt_of_le_of_ne' {a b : A} [PartialOrder A] :
(a : A) ≤ b → b ≠ a → a < b := fun h₁ h₂ => lt_of_le_of_ne h₁ h₂.symm

lemma pos_of_isNat {n : ℕ} [StrictOrderedSemiring A]
lemma pos_of_isNat {n : ℕ} [OrderedSemiring A] [Nontrivial A]
(h : NormNum.IsNat e n) (w : Nat.ble 1 n = true) : 0 < (e : A) := by
rw [NormNum.IsNat.to_eq h rfl]
apply Nat.cast_pos.2
Expand Down Expand Up @@ -184,11 +184,12 @@ def normNumPositivity (e : Q($α)) : MetaM (Strictness zα pα e) := catchNone d
| .isBool .. => failure
| .isNat _ lit p =>
if 0 < lit.natLit! then
let _a ← synthInstanceQ q(StrictOrderedSemiring $α)
let _a ← synthInstanceQ q(OrderedSemiring $α)
let _a ← synthInstanceQ q(Nontrivial $α)
assumeInstancesCommute
have p : Q(NormNum.IsNat $e $lit) := p
haveI' p' : Nat.ble 1 $lit =Q true := ⟨⟩
pure (.positive q(@pos_of_isNat $α _ _ _ $p $p'))
pure (.positive q(@pos_of_isNat $α _ _ _ _ $p $p'))
else
let _a ← synthInstanceQ q(OrderedSemiring $α)
assumeInstancesCommute
Expand Down
3 changes: 3 additions & 0 deletions test/positivity.lean
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ example : 0 ≤ 3 := by positivity

example : 0 < 3 := by positivity

example : (0 : ℝ≥0∞) < 1 := by positivity
example : (0 : ℝ≥0∞) < 2 := by positivity
Copy link
Member

@hrmacbeth hrmacbeth Oct 3, 2024

Choose a reason for hiding this comment

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

Could you please add a test like this?

example : (0 : ℝ≥0∞) < 3 - 2 := by positivity

(since the norm_num positivity extension should handle that too.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't work. I suspect it's because norm_num doesn't know about truncated subtraction.

Is your "should" meant as in "it should work" or as in "you should make it work"? I think it's pretty out of scope for this PR regardless of your answer.

In fact, my motivation here is to have positivity prove that the L2 norm of a nonzero function is positive, and there I really don't have any truncated subtraction

Copy link
Member

Choose a reason for hiding this comment

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

I was operating under the mistaken assumption that norm_num reduces (2:ENNReal) - 1 to 1. (It does for Nat but apparently not here.). No action required!


/- ## Goals working directly from a hypothesis -/
-- set_option trace.Meta.debug true
-- sudo set_option trace.Tactic.positivity true
Expand Down
Loading