@@ -124,6 +124,10 @@ theorem sqrt_div (x y : ℝ≥0) : sqrt (x / y) = sqrt x / sqrt y :=
124
124
theorem continuous_sqrt : Continuous sqrt := sqrt.continuous
125
125
#align nnreal.continuous_sqrt NNReal.continuous_sqrt
126
126
127
+ @[simp] theorem sqrt_pos : 0 < sqrt x ↔ 0 < x := by simp [pos_iff_ne_zero]
128
+
129
+ alias sqrt_pos ↔ _ sqrt_pos_of_pos
130
+
127
131
end NNReal
128
132
129
133
namespace Real
@@ -350,29 +354,41 @@ theorem sqrt_pos : 0 < sqrt x ↔ 0 < x :=
350
354
alias sqrt_pos ↔ _ sqrt_pos_of_pos
351
355
#align real.sqrt_pos_of_pos Real.sqrt_pos_of_pos
352
356
353
- /-
354
- section
357
+ end Real
355
358
356
- Porting note: todo: restore positivity plugin
357
- open Tactic Tactic.Positivity
359
+ namespace Mathlib.Meta.Positivity
360
+
361
+ open Lean Meta Qq Function
362
+
363
+ /-- Extension for the `positivity` tactic: a square root of a strictly positive nonnegative real is
364
+ positive. -/
365
+ @[positivity NNReal.sqrt _]
366
+ def evalNNRealSqrt : PositivityExt where eval {_ _} _zα _pα e := do
367
+ let (.app _ (a : Q(NNReal))) ← whnfR e | throwError "not NNReal.sqrt"
368
+ let zα' ← synthInstanceQ (q(Zero NNReal) : Q(Type ))
369
+ let pα' ← synthInstanceQ (q(PartialOrder NNReal) : Q(Type ))
370
+ let ra ← core zα' pα' a
371
+ assertInstancesCommute
372
+ match ra with
373
+ | .positive pa => pure (.positive (q(NNReal.sqrt_pos_of_pos $pa) : Expr))
374
+ | _ => failure -- this case is dealt with by generic nonnegativity of nnreals
358
375
359
376
/-- Extension for the `positivity` tactic: a square root is nonnegative, and is strictly positive if
360
377
its input is. -/
361
- @[ positivity ]
362
- unsafe def _root_ .tactic.positivity_sqrt : expr → tactic strictness
363
- | q(Real.sqrt $(a)) => do
364
- (-- if can prove `0 < a`, report positivity
365
- do
366
- let positive pa ← core a
367
- positive <$> mk_app `` sqrt_pos_of_pos [ pa ] ) <|>
368
- nonnegative <$> mk_app `` sqrt_nonneg [ a ]
369
- |-- else report nonnegativity
370
- _ =>
371
- failed
372
- #align tactic.positivity_sqrt tactic.positivity_sqrt
373
-
374
- end
375
- -/
378
+ @[positivity Real.sqrt _]
379
+ def evalSqrt : PositivityExt where eval {_ _} _zα _pα e := do
380
+ let (.app _ (a : Q(Real))) ← whnfR e | throwError "not Real.sqrt"
381
+ let zα' ← synthInstanceQ (q(Zero Real) : Q(Type ))
382
+ let pα' ← synthInstanceQ (q(PartialOrder Real) : Q(Type ))
383
+ let ra ← core zα' pα' a
384
+ assertInstancesCommute
385
+ match ra with
386
+ | .positive pa => pure (.positive (q(Real.sqrt_pos_of_pos $pa) : Expr))
387
+ | _ => pure (.nonnegative (q(Real.sqrt_nonneg $a) : Expr))
388
+
389
+ end Mathlib.Meta.Positivity
390
+
391
+ namespace Real
376
392
377
393
@[simp]
378
394
theorem sqrt_mul (hx : 0 ≤ x) (y : ℝ) : sqrt (x * y) = sqrt x * sqrt y := by
0 commit comments