Skip to content

Commit 6187636

Browse files
perf(Data.Real.Sqrt): make Real.sqrt irreducible (#25856)
We try to see what happens if we make Real.sqrt irreducible. There are cases where this makes unification very significantly faster, compare [#mathlib4 > Coercion triggers timeout @ πŸ’¬](https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Coercion.20triggers.20timeout/near/517177117). (Migrated manually from #24752)
1 parent 17991a0 commit 6187636

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

β€ŽMathlib/Data/Real/Sqrt.leanβ€Ž

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ lemma sqrt_le_iff_le_sq : sqrt x ≀ y ↔ x ≀ y ^ 2 := sqrt.to_galoisConnecti
6464

6565
lemma le_sqrt_iff_sq_le : x ≀ sqrt y ↔ x ^ 2 ≀ y := (sqrt.symm.to_galoisConnection _ _).symm
6666

67-
6867
@[simp] lemma sqrt_eq_zero : sqrt x = 0 ↔ x = 0 := by simp [sqrt_eq_iff_eq_sq]
6968

7069
@[simp] lemma sqrt_eq_one : sqrt x = 1 ↔ x = 1 := by simp [sqrt_eq_iff_eq_sq]
@@ -107,7 +106,7 @@ namespace Real
107106
/-- The square root of a real number. This returns 0 for negative inputs.
108107
109108
This has notation `√x`. Note that `√x⁻¹` is parsed as `√(x⁻¹)`. -/
110-
noncomputable def sqrt (x : ℝ) : ℝ :=
109+
@[irreducible] noncomputable def sqrt (x : ℝ) : ℝ :=
111110
NNReal.sqrt (Real.toNNReal x)
112111

113112
-- TODO: replace this with a typeclass
@@ -121,12 +120,15 @@ theorem coe_sqrt {x : ℝβ‰₯0} : (NNReal.sqrt x : ℝ) = √(x : ℝ) := by
121120
rw [Real.sqrt, Real.toNNReal_coe]
122121

123122
@[continuity]
124-
theorem continuous_sqrt : Continuous (√· : ℝ β†’ ℝ) :=
125-
NNReal.continuous_coe.comp <| NNReal.continuous_sqrt.comp continuous_real_toNNReal
123+
theorem continuous_sqrt : Continuous (√· : ℝ β†’ ℝ) := by
124+
unfold sqrt
125+
exact NNReal.continuous_coe.comp <| NNReal.continuous_sqrt.comp continuous_real_toNNReal
126126

127127
theorem sqrt_eq_zero_of_nonpos (h : x ≀ 0) : sqrt x = 0 := by simp [sqrt, Real.toNNReal_eq_zero.2 h]
128128

129-
@[simp] theorem sqrt_nonneg (x : ℝ) : 0 ≀ √x := NNReal.coe_nonneg _
129+
@[simp] theorem sqrt_nonneg (x : ℝ) : 0 ≀ √x := by
130+
unfold sqrt
131+
exact NNReal.coe_nonneg _
130132

131133
@[simp]
132134
theorem mul_self_sqrt (h : 0 ≀ x) : √x * √x = x := by

0 commit comments

Comments
Β (0)