@@ -908,6 +908,9 @@ theorem cast_natAbs_eq_nnabs_cast (n : ℤ) : (n.natAbs : ℝ≥0) = nnabs n :=
908908 ext
909909 rw [NNReal.coe_natCast, Nat.cast_natAbs, Real.coe_nnabs, Int.cast_abs]
910910
911+ @[simp]
912+ theorem nnabs_pos {x : ℝ} : 0 < x.nnabs ↔ x ≠ 0 := by simp [← NNReal.coe_pos]
913+
911914/-- Every real number nonnegative or nonpositive, phrased using `ℝ≥0`. -/
912915lemma nnreal_dichotomy (r : ℝ) : ∃ x : ℝ≥0 , r = x ∨ r = -x := by
913916 obtain (hr | hr) : 0 ≤ r ∨ 0 ≤ -r := by simpa using le_total ..
@@ -995,4 +998,28 @@ meta def evalNNRealtoReal : PositivityExt where eval {u α} _zα _pα e := do
995998 | _ => pure (.nonnegative q(NNReal.coe_nonneg $a))
996999 | _, _, _ => throwError "not NNReal.toReal"
9971000
1001+ /-- Extension for the `positivity` tactic: `Real.toNNReal. -/
1002+ @[positivity Real.toNNReal _]
1003+ meta def evalRealToNNReal : PositivityExt where eval {u α} _zα _pα e := do
1004+ match u, α, e with
1005+ | 0 , ~q(ℝ≥0 ), ~q(Real.toNNReal $a) =>
1006+ assertInstancesCommute
1007+ match (← core q(inferInstance) q(inferInstance) a) with
1008+ | .positive pa => pure (.positive q(toNNReal_pos.mpr $pa))
1009+ | _ => failure
1010+ | _, _, _ => throwError "not Real.toNNReal"
1011+
1012+ private alias ⟨_, nnabs_pos_of_pos⟩ := Real.nnabs_pos
1013+
1014+ /-- Extension for the `positivity` tactic: `Real.nnabs. -/
1015+ @[positivity Real.nnabs _]
1016+ meta def evalRealNNAbs : PositivityExt where eval {u α} _zα _pα e := do
1017+ match u, α, e with
1018+ | 0 , ~q(ℝ≥0 ), ~q(Real.nnabs $a) =>
1019+ assertInstancesCommute
1020+ match (← core q(inferInstance) q(inferInstance) a).toNonzero with
1021+ | some pa => pure (.positive q(nnabs_pos_of_pos $pa))
1022+ | _ => failure
1023+ | _, _, _ => throwError "not Real.nnabs"
1024+
9981025end Mathlib.Meta.Positivity
0 commit comments