Skip to content

Commit 456ecaa

Browse files
committed
feat: positivity extension for the coercion ℝ → ℂ (#9528)
From LeanAPAP
1 parent 86b7828 commit 456ecaa

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

Mathlib/Analysis/NormedSpace/Star/ContinuousFunctionalCalculus.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ theorem spectrum_star_mul_self_of_isStarNormal :
9292
rintro - ⟨φ, rfl⟩
9393
rw [gelfandTransform_apply_apply ℂ _ (star a' * a') φ, map_mul φ, map_star φ]
9494
rw [Complex.eq_coe_norm_of_nonneg (star_mul_self_nonneg _), ← map_star, ← map_mul]
95-
exact
96-
⟨Complex.zero_le_real.2 (norm_nonneg _),
97-
Complex.real_le_real.2 (AlgHom.norm_apply_le_self φ (star a' * a'))⟩
95+
exact ⟨by positivity, Complex.real_le_real.2 (AlgHom.norm_apply_le_self φ (star a' * a'))⟩
9896
#align spectrum_star_mul_self_of_is_star_normal spectrum_star_mul_self_of_isStarNormal
9997

10098
variable {a}

Mathlib/Data/Complex/Order.lean

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,39 @@ lemma monotone_ofReal : Monotone ofReal' := by
125125
simp only [ofReal_eq_coe, real_le_real, hxy]
126126

127127
end Complex
128+
129+
namespace Mathlib.Meta.Positivity
130+
open Lean Meta Qq Complex
131+
open scoped ComplexOrder
132+
133+
private alias ⟨_, ofReal_pos⟩ := zero_lt_real
134+
private alias ⟨_, ofReal_nonneg⟩ := zero_le_real
135+
private alias ⟨_, ofReal_ne_zero_of_ne_zero⟩ := ofReal_ne_zero
136+
137+
/-- Extension for the `positivity` tactic: `Complex.ofReal` is positive/nonnegative/nonzero if its
138+
input is. -/
139+
@[positivity Complex.ofReal' _, Complex.ofReal _]
140+
def evalComplexOfReal : PositivityExt where eval {u α} _ _ e := do
141+
-- TODO: Can we avoid duplicating the code?
142+
match u, α, e with
143+
| 0, ~q(ℂ), ~q(Complex.ofReal' $a) =>
144+
assumeInstancesCommute
145+
match ← core q(inferInstance) q(inferInstance) a with
146+
| .positive pa => return .positive q(ofReal_pos $pa)
147+
| .nonnegative pa => return .nonnegative q(ofReal_nonneg $pa)
148+
| .nonzero pa => return .nonzero q(ofReal_ne_zero_of_ne_zero $pa)
149+
| _ => return .none
150+
| 0, ~q(ℂ), ~q(Complex.ofReal $a) =>
151+
assumeInstancesCommute
152+
match ← core q(inferInstance) q(inferInstance) a with
153+
| .positive pa => return .positive q(ofReal_pos $pa)
154+
| .nonnegative pa => return .nonnegative q(ofReal_nonneg $pa)
155+
| .nonzero pa => return .nonzero q(ofReal_ne_zero_of_ne_zero $pa)
156+
| _ => return .none
157+
| _, _ => throwError "not Complex.ofReal'"
158+
159+
example (x : ℝ) (hx : 0 < x) : 0 < (x : ℂ) := by positivity
160+
example (x : ℝ) (hx : 0 ≤ x) : 0 ≤ (x : ℂ) := by positivity
161+
example (x : ℝ) (hx : x ≠ 0) : (x : ℂ) ≠ 0 := by positivity
162+
163+
end Mathlib.Meta.Positivity

0 commit comments

Comments
 (0)