@@ -801,49 +801,35 @@ def neTopBotEquivReal : ({⊥, ⊤}ᶜ : Set EReal) ≃ ℝ where
801801
802802end EReal
803803
804- -- Porting note(https://github.com/leanprover-community/mathlib4/issues/6038): restore
805- /-
806- namespace Tactic
807-
808- open Positivity
809-
810- private theorem ereal_coe_ne_zero {r : ℝ} : r ≠ 0 → (r : EReal) ≠ 0 :=
811- EReal.coe_ne_zero.2
804+ namespace Mathlib.Meta.Positivity
812805
813- private theorem ereal_coe_nonneg {r : ℝ} : 0 ≤ r → 0 ≤ (r : EReal) :=
814- EReal.coe_nonneg.2
815-
816- private theorem ereal_coe_pos {r : ℝ} : 0 < r → 0 < (r : EReal) :=
817- EReal.coe_pos.2
818-
819- private theorem ereal_coe_ennreal_pos {r : ℝ≥0∞} : 0 < r → 0 < (r : EReal) :=
820- EReal.coe_ennreal_pos.2
806+ open Lean Meta Qq Function
821807
822808/-- Extension for the `positivity` tactic: cast from `ℝ` to `EReal`. -/
823- @[ positivity ]
824- unsafe def positivity_coe_real_ereal : expr → tactic strictness
825- | q(@coe _ _ $(inst) $(a)) => do
826- unify inst q(@coeToLift _ _ <| @coeBase _ _ EReal.hasCoe)
827- let strictness_a ← core a
828- match strictness_a with
829- | positive p => positive <$> mk_app `` ereal_coe_pos [ p ]
830- | nonnegative p => nonnegative <$> mk_mapp `` ereal_coe_nonneg [a, p]
831- | nonzero p => nonzero <$> mk_mapp `` ereal_coe_ne_zero [a, p]
832- | e =>
833- pp e >>= fail ∘ format.bracket "The expression " " is not of the form `(r : ereal)` for `r : ℝ`"
809+ @[positivity Real.toEReal _]
810+ def evalRealtoEReal : PositivityExt where eval {u α} _zα _pα e := do
811+ match u, α, e with
812+ | 0 , ~q(EReal), ~q(Real.toEReal $a) =>
813+ let ra ← core q(inferInstance) q(inferInstance) a
814+ assertInstancesCommute
815+ match ra with
816+ | .positive pa => pure (.positive q(EReal.coe_pos.2 $pa))
817+ | .nonnegative pa => pure (.nonnegative q(EReal.coe_nonneg.2 $pa))
818+ | .nonzero pa => pure (.nonzero q(EReal.coe_ne_zero.2 $pa))
819+ | _ => pure .none
820+ | _, _, _ => throwError "not Real.toEReal"
834821
835822/-- Extension for the `positivity` tactic: cast from `ℝ≥0∞` to `EReal`. -/
836- @[ positivity ]
837- unsafe def positivity_coe_ennreal_ereal : expr → tactic strictness
838- | q(@coe _ _ $(inst) $(a)) => do
839- unify inst q(@coeToLift _ _ <| @coeBase _ _ EReal.hasCoeENNReal)
840- let strictness_a ← core a
841- match strictness_a with
842- | positive p => positive <$> mk_app `` ereal_coe_ennreal_pos [ p ]
843- | _ => nonnegative <$> mk_mapp `ereal.coe_ennreal_nonneg [ a ]
844- | e =>
845- pp e >>=
846- fail ∘ format.bracket "The expression " " is not of the form `(r : ereal)` for `r : ℝ≥0∞`"
847-
848- end Tactic
849- -/
823+ @[positivity ENNReal.toEReal _]
824+ def evalENNRealtoEReal : PositivityExt where eval {u α} _zα _pα e := do
825+ match u, α, e with
826+ | 0 , ~q(EReal), ~q(ENNReal.toEReal $a) =>
827+ let ra ← core q(inferInstance) q(inferInstance) a
828+ assertInstancesCommute
829+ match ra with
830+ | .positive pa => pure (.positive q(EReal.coe_ennreal_pos.2 $pa))
831+ | .nonzero pa => pure (.nonzero q(EReal.coe_ennreal_ne_zero.2 $pa))
832+ | _ => pure (.nonnegative q(EReal.coe_ennreal_nonneg $a))
833+ | _, _, _ => throwError "not ENNReal.toEReal"
834+
835+ end Mathlib.Meta.Positivity
0 commit comments