-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Merged by Bors] - feat: restore positivity extensions for EReal
#24539
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -801,49 +801,35 @@ def neTopBotEquivReal : ({⊥, ⊤}ᶜ : Set EReal) ≃ ℝ where | |
|
|
||
| end EReal | ||
|
|
||
| -- Porting note(https://github.com/leanprover-community/mathlib4/issues/6038): restore | ||
| /- | ||
| namespace Tactic | ||
|
|
||
| open Positivity | ||
|
|
||
| private theorem ereal_coe_ne_zero {r : ℝ} : r ≠ 0 → (r : EReal) ≠ 0 := | ||
| EReal.coe_ne_zero.2 | ||
| namespace Mathlib.Meta.Positivity | ||
|
|
||
| private theorem ereal_coe_nonneg {r : ℝ} : 0 ≤ r → 0 ≤ (r : EReal) := | ||
| EReal.coe_nonneg.2 | ||
|
|
||
| private theorem ereal_coe_pos {r : ℝ} : 0 < r → 0 < (r : EReal) := | ||
| EReal.coe_pos.2 | ||
|
|
||
| private theorem ereal_coe_ennreal_pos {r : ℝ≥0∞} : 0 < r → 0 < (r : EReal) := | ||
| EReal.coe_ennreal_pos.2 | ||
| open Lean Meta Qq Function | ||
|
|
||
| /-- Extension for the `positivity` tactic: cast from `ℝ` to `EReal`. -/ | ||
| @[positivity] | ||
| unsafe def positivity_coe_real_ereal : expr → tactic strictness | ||
| | q(@coe _ _ $(inst) $(a)) => do | ||
| unify inst q(@coeToLift _ _ <| @coeBase _ _ EReal.hasCoe) | ||
| let strictness_a ← core a | ||
| match strictness_a with | ||
| | positive p => positive <$> mk_app `` ereal_coe_pos [p] | ||
| | nonnegative p => nonnegative <$> mk_mapp `` ereal_coe_nonneg [a, p] | ||
| | nonzero p => nonzero <$> mk_mapp `` ereal_coe_ne_zero [a, p] | ||
| | e => | ||
| pp e >>= fail ∘ format.bracket "The expression " " is not of the form `(r : ereal)` for `r : ℝ`" | ||
| @[positivity Real.toEReal _] | ||
| def evalRealtoEReal : PositivityExt where eval {u α} _zα _pα e := do | ||
| match u, α, e with | ||
| | 0, ~q(EReal), ~q(Real.toEReal $a) => | ||
| let ra ← core q(inferInstance) q(inferInstance) a | ||
| assertInstancesCommute | ||
| match ra with | ||
| | .positive pa => pure (.positive q(EReal.coe_pos.2 $pa)) | ||
| | .nonnegative pa => pure (.nonnegative q(EReal.coe_nonneg.2 $pa)) | ||
| | .nonzero pa => pure (.nonzero q(EReal.coe_ne_zero.2 $pa)) | ||
| | _ => pure .none | ||
| | _, _, _ => throwError "not Real.toEReal" | ||
|
|
||
| /-- Extension for the `positivity` tactic: cast from `ℝ≥0∞` to `EReal`. -/ | ||
| @[positivity] | ||
| unsafe def positivity_coe_ennreal_ereal : expr → tactic strictness | ||
| | q(@coe _ _ $(inst) $(a)) => do | ||
| unify inst q(@coeToLift _ _ <| @coeBase _ _ EReal.hasCoeENNReal) | ||
| let strictness_a ← core a | ||
| match strictness_a with | ||
| | positive p => positive <$> mk_app `` ereal_coe_ennreal_pos [p] | ||
| | _ => nonnegative <$> mk_mapp `ereal.coe_ennreal_nonneg [a] | ||
| | e => | ||
| pp e >>= | ||
| fail ∘ format.bracket "The expression " " is not of the form `(r : ereal)` for `r : ℝ≥0∞`" | ||
|
|
||
| end Tactic | ||
| -/ | ||
| @[positivity ENNReal.toEReal _] | ||
| def evalENNRealtoEReal : PositivityExt where eval {u α} _zα _pα e := do | ||
| match u, α, e with | ||
| | 0, ~q(EReal), ~q(ENNReal.toEReal $a) => | ||
| let ra ← core q(inferInstance) q(inferInstance) a | ||
| assertInstancesCommute | ||
| match ra with | ||
| | .positive pa => pure (.positive q(EReal.coe_ennreal_pos.2 $pa)) | ||
| | .nonzero pa => pure (.nonzero q(EReal.coe_ennreal_ne_zero.2 $pa)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we know here that it's |
||
| | _ => pure (.nonnegative q(EReal.coe_ennreal_nonneg $a)) | ||
| | _, _, _ => throwError "not ENNReal.toEReal" | ||
|
|
||
| end Mathlib.Meta.Positivity | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.