analysis.special_functions.bernsteinMathlib.Analysis.SpecialFunctions.Bernstein

This file has been ported!

Changes since the initial port

The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.

Changes in mathlib3

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(last sync)

Changes in mathlib3port

mathlib3
mathlib3port
Diff
@@ -133,7 +133,7 @@ theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
   conv_rhs => rw [div_mul_cancel₀ _ h']
   have := bernsteinPolynomial.variance ℝ n
   apply_fun fun p => Polynomial.aeval (x : ℝ) p at this
-  simp [AlgHom.map_sum, Finset.sum_range, ← Polynomial.nat_cast_mul] at this
+  simp [AlgHom.map_sum, Finset.sum_range, ← Polynomial.natCast_mul] at this
   convert this using 1
   · congr 1; funext k
     rw [mul_comm _ (n : ℝ), mul_comm _ (n : ℝ), ← mul_assoc, ← mul_assoc]
Diff
@@ -130,7 +130,7 @@ theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
   apply_fun fun x : ℝ => x * n using GroupWithZero.mul_right_injective h'
   dsimp
   conv_lhs => simp only [Finset.sum_mul, z]
-  conv_rhs => rw [div_mul_cancel _ h']
+  conv_rhs => rw [div_mul_cancel₀ _ h']
   have := bernsteinPolynomial.variance ℝ n
   apply_fun fun p => Polynomial.aeval (x : ℝ) p at this
   simp [AlgHom.map_sum, Finset.sum_range, ← Polynomial.nat_cast_mul] at this
Diff
@@ -115,8 +115,8 @@ local postfix:90 "/ₙ" => z
 theorem probability (n : ℕ) (x : I) : ∑ k : Fin (n + 1), bernstein n k x = 1 :=
   by
   have := bernsteinPolynomial.sum ℝ n
-  apply_fun fun p => Polynomial.aeval (x : ℝ) p at this 
-  simp [AlgHom.map_sum, Finset.sum_range] at this 
+  apply_fun fun p => Polynomial.aeval (x : ℝ) p at this
+  simp [AlgHom.map_sum, Finset.sum_range] at this
   exact this
 #align bernstein.probability bernstein.probability
 -/
@@ -132,8 +132,8 @@ theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
   conv_lhs => simp only [Finset.sum_mul, z]
   conv_rhs => rw [div_mul_cancel _ h']
   have := bernsteinPolynomial.variance ℝ n
-  apply_fun fun p => Polynomial.aeval (x : ℝ) p at this 
-  simp [AlgHom.map_sum, Finset.sum_range, ← Polynomial.nat_cast_mul] at this 
+  apply_fun fun p => Polynomial.aeval (x : ℝ) p at this
+  simp [AlgHom.map_sum, Finset.sum_range, ← Polynomial.nat_cast_mul] at this
   convert this using 1
   · congr 1; funext k
     rw [mul_comm _ (n : ℝ), mul_comm _ (n : ℝ), ← mul_assoc, ← mul_assoc]
@@ -224,10 +224,10 @@ This particular formulation will be helpful later.
 theorem le_of_mem_S_compl {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : Fin (n + 1)}
     (m : k ∈ S f ε h n xᶜ) : (1 : ℝ) ≤ δ f ε h ^ (-2 : ℤ) * (x - k/ₙ) ^ 2 :=
   by
-  simp only [Finset.mem_compl, not_lt, Set.mem_toFinset, Set.mem_setOf_eq, S] at m 
+  simp only [Finset.mem_compl, not_lt, Set.mem_toFinset, Set.mem_setOf_eq, S] at m
   rw [zpow_neg, ← div_eq_inv_mul, zpow_two, ← pow_two, one_le_div (pow_pos δ_pos 2), sq_le_sq,
     abs_of_pos δ_pos]
-  rwa [dist_comm] at m 
+  rwa [dist_comm] at m
 #align bernstein_approximation.le_of_mem_S_compl bernsteinApproximation.le_of_mem_S_compl
 -/
 
Diff
@@ -257,7 +257,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
   simp only [metric.nhds_basis_ball.tendsto_right_iff, Metric.mem_ball, dist_eq_norm]
   intro ε h
   let δ := δ f ε h
-  have nhds_zero := tendsto_const_div_atTop_nhds_0_nat (2 * ‖f‖ * δ ^ (-2 : ℤ))
+  have nhds_zero := tendsto_const_div_atTop_nhds_zero_nat (2 * ‖f‖ * δ ^ (-2 : ℤ))
   filter_upwards [nhds_zero.eventually (gt_mem_nhds (half_pos h)), eventually_gt_at_top 0] with n nh
     npos'
   have npos : 0 < (n : ℝ) := by exact_mod_cast npos'
Diff
@@ -3,10 +3,10 @@ Copyright (c) 2021 Scott Morrison. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Scott Morrison
 -/
-import Mathbin.Analysis.SpecificLimits.Basic
-import Mathbin.RingTheory.Polynomial.Bernstein
-import Mathbin.Topology.ContinuousFunction.Polynomial
-import Mathbin.Topology.ContinuousFunction.Compact
+import Analysis.SpecificLimits.Basic
+import RingTheory.Polynomial.Bernstein
+import Topology.ContinuousFunction.Polynomial
+import Topology.ContinuousFunction.Compact
 
 #align_import analysis.special_functions.bernstein from "leanprover-community/mathlib"@"36938f775671ff28bea1c0310f1608e4afbb22e0"
 
Diff
@@ -2,17 +2,14 @@
 Copyright (c) 2021 Scott Morrison. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Scott Morrison
-
-! This file was ported from Lean 3 source module analysis.special_functions.bernstein
-! leanprover-community/mathlib commit 36938f775671ff28bea1c0310f1608e4afbb22e0
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathbin.Analysis.SpecificLimits.Basic
 import Mathbin.RingTheory.Polynomial.Bernstein
 import Mathbin.Topology.ContinuousFunction.Polynomial
 import Mathbin.Topology.ContinuousFunction.Compact
 
+#align_import analysis.special_functions.bernstein from "leanprover-community/mathlib"@"36938f775671ff28bea1c0310f1608e4afbb22e0"
+
 /-!
 # Bernstein approximations and Weierstrass' theorem
 
Diff
@@ -70,6 +70,7 @@ def bernstein (n ν : ℕ) : C(I, ℝ) :=
 #align bernstein bernstein
 -/
 
+#print bernstein_apply /-
 @[simp]
 theorem bernstein_apply (n ν : ℕ) (x : I) :
     bernstein n ν x = n.choose ν * x ^ ν * (1 - x) ^ (n - ν) :=
@@ -77,7 +78,9 @@ theorem bernstein_apply (n ν : ℕ) (x : I) :
   dsimp [bernstein, Polynomial.toContinuousMapOn, Polynomial.toContinuousMap, bernsteinPolynomial]
   simp
 #align bernstein_apply bernstein_apply
+-/
 
+#print bernstein_nonneg /-
 theorem bernstein_nonneg {n ν : ℕ} {x : I} : 0 ≤ bernstein n ν x :=
   by
   simp only [bernstein_apply]
@@ -85,6 +88,7 @@ theorem bernstein_nonneg {n ν : ℕ} {x : I} : 0 ≤ bernstein n ν x :=
     mul_nonneg (mul_nonneg (Nat.cast_nonneg _) (pow_nonneg (by unit_interval) _))
       (pow_nonneg (by unit_interval) _)
 #align bernstein_nonneg bernstein_nonneg
+-/
 
 /-!
 We now give a slight reformulation of `bernstein_polynomial.variance`.
@@ -108,9 +112,9 @@ def z {n : ℕ} (k : Fin (n + 1)) : I :=
 #align bernstein.z bernstein.z
 -/
 
--- mathport name: «expr /ₙ»
 local postfix:90 "/ₙ" => z
 
+#print bernstein.probability /-
 theorem probability (n : ℕ) (x : I) : ∑ k : Fin (n + 1), bernstein n k x = 1 :=
   by
   have := bernsteinPolynomial.sum ℝ n
@@ -118,7 +122,9 @@ theorem probability (n : ℕ) (x : I) : ∑ k : Fin (n + 1), bernstein n k x = 1
   simp [AlgHom.map_sum, Finset.sum_range] at this 
   exact this
 #align bernstein.probability bernstein.probability
+-/
 
+#print bernstein.variance /-
 theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
     ∑ k : Fin (n + 1), (x - k/ₙ : ℝ) ^ 2 * bernstein n k x = x * (1 - x) / n :=
   by
@@ -139,12 +145,12 @@ theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
     ring
   · ring
 #align bernstein.variance bernstein.variance
+-/
 
 end bernstein
 
 open bernstein
 
--- mathport name: «expr /ₙ»
 local postfix:1024 "/ₙ" => z
 
 #print bernsteinApproximation /-
@@ -173,28 +179,37 @@ We show that if `k ∉ S`, then `1 ≤ δ^-2 * (x - k/n)^2`.
 
 namespace bernsteinApproximation
 
+#print bernsteinApproximation.apply /-
 @[simp]
 theorem apply (n : ℕ) (f : C(I, ℝ)) (x : I) :
     bernsteinApproximation n f x = ∑ k : Fin (n + 1), f k/ₙ * bernstein n k x := by
   simp [bernsteinApproximation]
 #align bernstein_approximation.apply bernsteinApproximation.apply
+-/
 
+#print bernsteinApproximation.δ /-
 /-- The modulus of (uniform) continuity for `f`, chosen so `|f x - f y| < ε/2` when `|x - y| < δ`.
 -/
 def δ (f : C(I, ℝ)) (ε : ℝ) (h : 0 < ε) : ℝ :=
   f.modulus (ε / 2) (half_pos h)
 #align bernstein_approximation.δ bernsteinApproximation.δ
+-/
 
+#print bernsteinApproximation.δ_pos /-
 theorem δ_pos {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} : 0 < δ f ε h :=
   f.modulus_pos
 #align bernstein_approximation.δ_pos bernsteinApproximation.δ_pos
+-/
 
+#print bernsteinApproximation.S /-
 /-- The set of points `k` so `k/n` is within `δ` of `x`.
 -/
 def S (f : C(I, ℝ)) (ε : ℝ) (h : 0 < ε) (n : ℕ) (x : I) : Finset (Fin (n + 1)) :=
   {k : Fin (n + 1) | dist k/ₙ x < δ f ε h}.toFinset
 #align bernstein_approximation.S bernsteinApproximation.S
+-/
 
+#print bernsteinApproximation.lt_of_mem_S /-
 /-- If `k ∈ S`, then `f(k/n)` is close to `f x`.
 -/
 theorem lt_of_mem_S {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : Fin (n + 1)}
@@ -203,7 +218,9 @@ theorem lt_of_mem_S {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k
   apply f.dist_lt_of_dist_lt_modulus (ε / 2) (half_pos h)
   simpa [S] using m
 #align bernstein_approximation.lt_of_mem_S bernsteinApproximation.lt_of_mem_S
+-/
 
+#print bernsteinApproximation.le_of_mem_S_compl /-
 /-- If `k ∉ S`, then as `δ ≤ |x - k/n|`, we have the inequality `1 ≤ δ^-2 * (x - k/n)^2`.
 This particular formulation will be helpful later.
 -/
@@ -215,6 +232,7 @@ theorem le_of_mem_S_compl {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x :
     abs_of_pos δ_pos]
   rwa [dist_comm] at m 
 #align bernstein_approximation.le_of_mem_S_compl bernsteinApproximation.le_of_mem_S_compl
+-/
 
 end bernsteinApproximation
 
Diff
@@ -111,7 +111,7 @@ def z {n : ℕ} (k : Fin (n + 1)) : I :=
 -- mathport name: «expr /ₙ»
 local postfix:90 "/ₙ" => z
 
-theorem probability (n : ℕ) (x : I) : (∑ k : Fin (n + 1), bernstein n k x) = 1 :=
+theorem probability (n : ℕ) (x : I) : ∑ k : Fin (n + 1), bernstein n k x = 1 :=
   by
   have := bernsteinPolynomial.sum ℝ n
   apply_fun fun p => Polynomial.aeval (x : ℝ) p at this 
@@ -120,7 +120,7 @@ theorem probability (n : ℕ) (x : I) : (∑ k : Fin (n + 1), bernstein n k x) =
 #align bernstein.probability bernstein.probability
 
 theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
-    (∑ k : Fin (n + 1), (x - k/ₙ : ℝ) ^ 2 * bernstein n k x) = x * (1 - x) / n :=
+    ∑ k : Fin (n + 1), (x - k/ₙ : ℝ) ^ 2 * bernstein n k x = x * (1 - x) / n :=
   by
   have h' : (n : ℝ) ≠ 0 := ne_of_gt h
   apply_fun fun x : ℝ => x * n using GroupWithZero.mul_right_injective h'
@@ -265,7 +265,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
     _ ≤ ∑ k : Fin (n + 1), |(f k/ₙ - f x) * bernstein n k x| := (Finset.abs_sum_le_sum_abs _ _)
     _ = ∑ k : Fin (n + 1), |f k/ₙ - f x| * bernstein n k x := by
       simp_rw [abs_mul, abs_eq_self.mpr bernstein_nonneg]
-    _ = (∑ k in S, |f k/ₙ - f x| * bernstein n k x) + ∑ k in Sᶜ, |f k/ₙ - f x| * bernstein n k x :=
+    _ = ∑ k in S, |f k/ₙ - f x| * bernstein n k x + ∑ k in Sᶜ, |f k/ₙ - f x| * bernstein n k x :=
       (S.sum_add_sum_compl _).symm
     -- We'll now deal with the terms in `S` and the terms in `Sᶜ` in separate calc blocks.
         _ <
@@ -275,7 +275,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
   ·-- We now work on the terms in `S`: uniform continuity and `bernstein.probability`
     -- quickly give us a bound.
     calc
-      (∑ k in S, |f k/ₙ - f x| * bernstein n k x) ≤ ∑ k in S, ε / 2 * bernstein n k x :=
+      ∑ k in S, |f k/ₙ - f x| * bernstein n k x ≤ ∑ k in S, ε / 2 * bernstein n k x :=
         Finset.sum_le_sum fun k m =>
           mul_le_mul_of_nonneg_right (le_of_lt (lt_of_mem_S m)) bernstein_nonneg
       _ = ε / 2 * ∑ k in S, bernstein n k x := by rw [Finset.mul_sum]
@@ -290,7 +290,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
     -- and then insert a `δ^(-2) * (x - k/n)^2` factor
     -- (which is at least one because we are not in `S`).
     calc
-      (∑ k in Sᶜ, |f k/ₙ - f x| * bernstein n k x) ≤ ∑ k in Sᶜ, 2 * ‖f‖ * bernstein n k x :=
+      ∑ k in Sᶜ, |f k/ₙ - f x| * bernstein n k x ≤ ∑ k in Sᶜ, 2 * ‖f‖ * bernstein n k x :=
         Finset.sum_le_sum fun k m =>
           mul_le_mul_of_nonneg_right (f.dist_le_two_norm _ _) bernstein_nonneg
       _ = 2 * ‖f‖ * ∑ k in Sᶜ, bernstein n k x := by rw [Finset.mul_sum]
Diff
@@ -272,7 +272,6 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
         ε / 2 + ε / 2 :=
       (add_lt_add_of_le_of_lt _ _)
     _ = ε := add_halves ε
-    
   ·-- We now work on the terms in `S`: uniform continuity and `bernstein.probability`
     -- quickly give us a bound.
     calc
@@ -287,7 +286,6 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
         (mul_le_mul_of_nonneg_left (Finset.sum_le_univ_sum_of_nonneg fun k => bernstein_nonneg)
           (le_of_lt (half_pos h)))
       _ = ε / 2 := by rw [bernstein.probability, mul_one]
-      
   ·-- We now turn to working on `Sᶜ`: we control the difference term just using `‖f‖`,
     -- and then insert a `δ^(-2) * (x - k/n)^2` factor
     -- (which is at least one because we are not in `S`).
@@ -322,7 +320,6 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
         ((div_le_div_right npos).mpr <| by
           refine' mul_le_of_le_of_le_one' (mul_le_of_le_one_right w₂ _) _ _ w₂ <;> unit_interval)
       _ < ε / 2 := nh
-      
 #align bernstein_approximation_uniform bernsteinApproximation_uniform
 -/
 
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Scott Morrison
 
 ! This file was ported from Lean 3 source module analysis.special_functions.bernstein
-! leanprover-community/mathlib commit 2c1d8ca2812b64f88992a5294ea3dba144755cd1
+! leanprover-community/mathlib commit 36938f775671ff28bea1c0310f1608e4afbb22e0
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -16,6 +16,9 @@ import Mathbin.Topology.ContinuousFunction.Compact
 /-!
 # Bernstein approximations and Weierstrass' theorem
 
+> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
+> Any changes to this file require a corresponding PR to mathlib4.
+
 We prove that the Bernstein approximations
 ```
 ∑ k : fin (n+1), f (k/n : ℝ) * n.choose k * x^k * (1-x)^(n-k)
Diff
@@ -59,11 +59,13 @@ open scoped BoundedContinuousFunction
 
 open scoped unitInterval
 
+#print bernstein /-
 /-- The Bernstein polynomials, as continuous functions on `[0,1]`.
 -/
 def bernstein (n ν : ℕ) : C(I, ℝ) :=
   (bernsteinPolynomial ℝ n ν).toContinuousMapOn I
 #align bernstein bernstein
+-/
 
 @[simp]
 theorem bernstein_apply (n ν : ℕ) (x : I) :
@@ -88,6 +90,7 @@ We now give a slight reformulation of `bernstein_polynomial.variance`.
 
 namespace bernstein
 
+#print bernstein.z /-
 /-- Send `k : fin (n+1)` to the equally spaced points `k/n` in the unit interval.
 -/
 def z {n : ℕ} (k : Fin (n + 1)) : I :=
@@ -100,6 +103,7 @@ def z {n : ℕ} (k : Fin (n + 1)) : I :=
       norm_cast
       simp [h₂]⟩
 #align bernstein.z bernstein.z
+-/
 
 -- mathport name: «expr /ₙ»
 local postfix:90 "/ₙ" => z
@@ -140,12 +144,14 @@ open bernstein
 -- mathport name: «expr /ₙ»
 local postfix:1024 "/ₙ" => z
 
+#print bernsteinApproximation /-
 /-- The `n`-th approximation of a continuous function on `[0,1]` by Bernstein polynomials,
 given by `∑ k, f (k/n) * bernstein n k x`.
 -/
 def bernsteinApproximation (n : ℕ) (f : C(I, ℝ)) : C(I, ℝ) :=
   ∑ k : Fin (n + 1), f k/ₙ • bernstein n k
 #align bernstein_approximation bernsteinApproximation
+-/
 
 /-!
 We now set up some of the basic machinery of the proof that the Bernstein approximations
@@ -182,30 +188,30 @@ theorem δ_pos {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} : 0 < δ f ε h :=
 
 /-- The set of points `k` so `k/n` is within `δ` of `x`.
 -/
-def s (f : C(I, ℝ)) (ε : ℝ) (h : 0 < ε) (n : ℕ) (x : I) : Finset (Fin (n + 1)) :=
+def S (f : C(I, ℝ)) (ε : ℝ) (h : 0 < ε) (n : ℕ) (x : I) : Finset (Fin (n + 1)) :=
   {k : Fin (n + 1) | dist k/ₙ x < δ f ε h}.toFinset
-#align bernstein_approximation.S bernsteinApproximation.s
+#align bernstein_approximation.S bernsteinApproximation.S
 
 /-- If `k ∈ S`, then `f(k/n)` is close to `f x`.
 -/
-theorem lt_of_mem_s {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : Fin (n + 1)}
-    (m : k ∈ s f ε h n x) : |f k/ₙ - f x| < ε / 2 :=
+theorem lt_of_mem_S {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : Fin (n + 1)}
+    (m : k ∈ S f ε h n x) : |f k/ₙ - f x| < ε / 2 :=
   by
   apply f.dist_lt_of_dist_lt_modulus (ε / 2) (half_pos h)
   simpa [S] using m
-#align bernstein_approximation.lt_of_mem_S bernsteinApproximation.lt_of_mem_s
+#align bernstein_approximation.lt_of_mem_S bernsteinApproximation.lt_of_mem_S
 
 /-- If `k ∉ S`, then as `δ ≤ |x - k/n|`, we have the inequality `1 ≤ δ^-2 * (x - k/n)^2`.
 This particular formulation will be helpful later.
 -/
-theorem le_of_mem_s_compl {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : Fin (n + 1)}
-    (m : k ∈ s f ε h n xᶜ) : (1 : ℝ) ≤ δ f ε h ^ (-2 : ℤ) * (x - k/ₙ) ^ 2 :=
+theorem le_of_mem_S_compl {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : Fin (n + 1)}
+    (m : k ∈ S f ε h n xᶜ) : (1 : ℝ) ≤ δ f ε h ^ (-2 : ℤ) * (x - k/ₙ) ^ 2 :=
   by
   simp only [Finset.mem_compl, not_lt, Set.mem_toFinset, Set.mem_setOf_eq, S] at m 
   rw [zpow_neg, ← div_eq_inv_mul, zpow_two, ← pow_two, one_le_div (pow_pos δ_pos 2), sq_le_sq,
     abs_of_pos δ_pos]
   rwa [dist_comm] at m 
-#align bernstein_approximation.le_of_mem_S_compl bernsteinApproximation.le_of_mem_s_compl
+#align bernstein_approximation.le_of_mem_S_compl bernsteinApproximation.le_of_mem_S_compl
 
 end bernsteinApproximation
 
@@ -217,6 +223,7 @@ open Filter
 
 open scoped Topology
 
+#print bernsteinApproximation_uniform /-
 /-- The Bernstein approximations
 ```
 ∑ k : fin (n+1), f (k/n : ℝ) * n.choose k * x^k * (1-x)^(n-k)
@@ -314,4 +321,5 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
       _ < ε / 2 := nh
       
 #align bernstein_approximation_uniform bernsteinApproximation_uniform
+-/
 
Diff
@@ -107,7 +107,7 @@ local postfix:90 "/ₙ" => z
 theorem probability (n : ℕ) (x : I) : (∑ k : Fin (n + 1), bernstein n k x) = 1 :=
   by
   have := bernsteinPolynomial.sum ℝ n
-  apply_fun fun p => Polynomial.aeval (x : ℝ) p  at this 
+  apply_fun fun p => Polynomial.aeval (x : ℝ) p at this 
   simp [AlgHom.map_sum, Finset.sum_range] at this 
   exact this
 #align bernstein.probability bernstein.probability
@@ -122,7 +122,7 @@ theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
   conv_lhs => simp only [Finset.sum_mul, z]
   conv_rhs => rw [div_mul_cancel _ h']
   have := bernsteinPolynomial.variance ℝ n
-  apply_fun fun p => Polynomial.aeval (x : ℝ) p  at this 
+  apply_fun fun p => Polynomial.aeval (x : ℝ) p at this 
   simp [AlgHom.map_sum, Finset.sum_range, ← Polynomial.nat_cast_mul] at this 
   convert this using 1
   · congr 1; funext k
@@ -183,7 +183,7 @@ theorem δ_pos {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} : 0 < δ f ε h :=
 /-- The set of points `k` so `k/n` is within `δ` of `x`.
 -/
 def s (f : C(I, ℝ)) (ε : ℝ) (h : 0 < ε) (n : ℕ) (x : I) : Finset (Fin (n + 1)) :=
-  { k : Fin (n + 1) | dist k/ₙ x < δ f ε h }.toFinset
+  {k : Fin (n + 1) | dist k/ₙ x < δ f ε h}.toFinset
 #align bernstein_approximation.S bernsteinApproximation.s
 
 /-- If `k ∈ S`, then `f(k/n)` is close to `f x`.
@@ -233,8 +233,8 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
   intro ε h
   let δ := δ f ε h
   have nhds_zero := tendsto_const_div_atTop_nhds_0_nat (2 * ‖f‖ * δ ^ (-2 : ℤ))
-  filter_upwards [nhds_zero.eventually (gt_mem_nhds (half_pos h)),
-    eventually_gt_at_top 0]with n nh npos'
+  filter_upwards [nhds_zero.eventually (gt_mem_nhds (half_pos h)), eventually_gt_at_top 0] with n nh
+    npos'
   have npos : 0 < (n : ℝ) := by exact_mod_cast npos'
   -- Two easy inequalities we'll need later:
   have w₁ : 0 ≤ 2 * ‖f‖ := mul_nonneg (by norm_num) (norm_nonneg f)
Diff
@@ -107,8 +107,8 @@ local postfix:90 "/ₙ" => z
 theorem probability (n : ℕ) (x : I) : (∑ k : Fin (n + 1), bernstein n k x) = 1 :=
   by
   have := bernsteinPolynomial.sum ℝ n
-  apply_fun fun p => Polynomial.aeval (x : ℝ) p  at this
-  simp [AlgHom.map_sum, Finset.sum_range] at this
+  apply_fun fun p => Polynomial.aeval (x : ℝ) p  at this 
+  simp [AlgHom.map_sum, Finset.sum_range] at this 
   exact this
 #align bernstein.probability bernstein.probability
 
@@ -122,8 +122,8 @@ theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
   conv_lhs => simp only [Finset.sum_mul, z]
   conv_rhs => rw [div_mul_cancel _ h']
   have := bernsteinPolynomial.variance ℝ n
-  apply_fun fun p => Polynomial.aeval (x : ℝ) p  at this
-  simp [AlgHom.map_sum, Finset.sum_range, ← Polynomial.nat_cast_mul] at this
+  apply_fun fun p => Polynomial.aeval (x : ℝ) p  at this 
+  simp [AlgHom.map_sum, Finset.sum_range, ← Polynomial.nat_cast_mul] at this 
   convert this using 1
   · congr 1; funext k
     rw [mul_comm _ (n : ℝ), mul_comm _ (n : ℝ), ← mul_assoc, ← mul_assoc]
@@ -201,10 +201,10 @@ This particular formulation will be helpful later.
 theorem le_of_mem_s_compl {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : Fin (n + 1)}
     (m : k ∈ s f ε h n xᶜ) : (1 : ℝ) ≤ δ f ε h ^ (-2 : ℤ) * (x - k/ₙ) ^ 2 :=
   by
-  simp only [Finset.mem_compl, not_lt, Set.mem_toFinset, Set.mem_setOf_eq, S] at m
+  simp only [Finset.mem_compl, not_lt, Set.mem_toFinset, Set.mem_setOf_eq, S] at m 
   rw [zpow_neg, ← div_eq_inv_mul, zpow_two, ← pow_two, one_le_div (pow_pos δ_pos 2), sq_le_sq,
     abs_of_pos δ_pos]
-  rwa [dist_comm] at m
+  rwa [dist_comm] at m 
 #align bernstein_approximation.le_of_mem_S_compl bernsteinApproximation.le_of_mem_s_compl
 
 end bernsteinApproximation
Diff
@@ -51,13 +51,13 @@ although we defer an abstract statement of this until later.
 
 noncomputable section
 
-open Classical
+open scoped Classical
 
-open BigOperators
+open scoped BigOperators
 
-open BoundedContinuousFunction
+open scoped BoundedContinuousFunction
 
-open unitInterval
+open scoped unitInterval
 
 /-- The Bernstein polynomials, as continuous functions on `[0,1]`.
 -/
@@ -215,7 +215,7 @@ open BoundedContinuousFunction
 
 open Filter
 
-open Topology
+open scoped Topology
 
 /-- The Bernstein approximations
 ```
Diff
@@ -125,8 +125,7 @@ theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
   apply_fun fun p => Polynomial.aeval (x : ℝ) p  at this
   simp [AlgHom.map_sum, Finset.sum_range, ← Polynomial.nat_cast_mul] at this
   convert this using 1
-  · congr 1
-    funext k
+  · congr 1; funext k
     rw [mul_comm _ (n : ℝ), mul_comm _ (n : ℝ), ← mul_assoc, ← mul_assoc]
     congr 1
     field_simp [h]
@@ -308,9 +307,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
       -- `bernstein.variance` and `x ∈ [0,1]` gives the uniform bound
           _ =
           2 * ‖f‖ * δ ^ (-2 : ℤ) * x * (1 - x) / n :=
-        by
-        rw [variance npos]
-        ring
+        by rw [variance npos]; ring
       _ ≤ 2 * ‖f‖ * δ ^ (-2 : ℤ) / n :=
         ((div_le_div_right npos).mpr <| by
           refine' mul_le_of_le_of_le_one' (mul_le_of_le_one_right w₂ _) _ _ w₂ <;> unit_interval)
Diff
@@ -4,11 +4,10 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Scott Morrison
 
 ! This file was ported from Lean 3 source module analysis.special_functions.bernstein
-! leanprover-community/mathlib commit acb3d204d4ee883eb686f45d486a2a6811a01329
+! leanprover-community/mathlib commit 2c1d8ca2812b64f88992a5294ea3dba144755cd1
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
-import Mathbin.Algebra.Order.Field.Basic
 import Mathbin.Analysis.SpecificLimits.Basic
 import Mathbin.RingTheory.Polynomial.Bernstein
 import Mathbin.Topology.ContinuousFunction.Polynomial
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Scott Morrison
 
 ! This file was ported from Lean 3 source module analysis.special_functions.bernstein
-! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982
+! leanprover-community/mathlib commit acb3d204d4ee883eb686f45d486a2a6811a01329
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -240,7 +240,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
   have npos : 0 < (n : ℝ) := by exact_mod_cast npos'
   -- Two easy inequalities we'll need later:
   have w₁ : 0 ≤ 2 * ‖f‖ := mul_nonneg (by norm_num) (norm_nonneg f)
-  have w₂ : 0 ≤ 2 * ‖f‖ * δ ^ (-2 : ℤ) := mul_nonneg w₁ pow_minus_two_nonneg
+  have w₂ : 0 ≤ 2 * ‖f‖ * δ ^ (-2 : ℤ) := mul_nonneg w₁ (zpow_neg_two_nonneg _)
   -- As `[0,1]` is compact, it suffices to check the inequality pointwise.
   rw [ContinuousMap.norm_lt_iff _ h]
   intro x
@@ -300,7 +300,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
           2 * ‖f‖ * ∑ k : Fin (n + 1), δ ^ (-2 : ℤ) * (x - k/ₙ) ^ 2 * bernstein n k x :=
         (mul_le_mul_of_nonneg_left
           (Finset.sum_le_univ_sum_of_nonneg fun k =>
-            mul_nonneg (mul_nonneg pow_minus_two_nonneg (sq_nonneg _)) bernstein_nonneg)
+            mul_nonneg (mul_nonneg (zpow_neg_two_nonneg _) (sq_nonneg _)) bernstein_nonneg)
           w₁)
       _ = 2 * ‖f‖ * δ ^ (-2 : ℤ) * ∑ k : Fin (n + 1), (x - k/ₙ) ^ 2 * bernstein n k x := by
         conv_rhs =>
Diff
@@ -254,7 +254,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
       rw [bernstein.probability]
     _ = |∑ k : Fin (n + 1), (f k/ₙ - f x) * bernstein n k x| := by
       simp [bernsteinApproximation, Finset.mul_sum, sub_mul]
-    _ ≤ ∑ k : Fin (n + 1), |(f k/ₙ - f x) * bernstein n k x| := Finset.abs_sum_le_sum_abs _ _
+    _ ≤ ∑ k : Fin (n + 1), |(f k/ₙ - f x) * bernstein n k x| := (Finset.abs_sum_le_sum_abs _ _)
     _ = ∑ k : Fin (n + 1), |f k/ₙ - f x| * bernstein n k x := by
       simp_rw [abs_mul, abs_eq_self.mpr bernstein_nonneg]
     _ = (∑ k in S, |f k/ₙ - f x| * bernstein n k x) + ∑ k in Sᶜ, |f k/ₙ - f x| * bernstein n k x :=
@@ -262,7 +262,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
     -- We'll now deal with the terms in `S` and the terms in `Sᶜ` in separate calc blocks.
         _ <
         ε / 2 + ε / 2 :=
-      add_lt_add_of_le_of_lt _ _
+      (add_lt_add_of_le_of_lt _ _)
     _ = ε := add_halves ε
     
   ·-- We now work on the terms in `S`: uniform continuity and `bernstein.probability`
@@ -276,8 +276,8 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
           -- so that we can use `bernstein.probability`.
           _ ≤
           ε / 2 * ∑ k : Fin (n + 1), bernstein n k x :=
-        mul_le_mul_of_nonneg_left (Finset.sum_le_univ_sum_of_nonneg fun k => bernstein_nonneg)
-          (le_of_lt (half_pos h))
+        (mul_le_mul_of_nonneg_left (Finset.sum_le_univ_sum_of_nonneg fun k => bernstein_nonneg)
+          (le_of_lt (half_pos h)))
       _ = ε / 2 := by rw [bernstein.probability, mul_one]
       
   ·-- We now turn to working on `Sᶜ`: we control the difference term just using `‖f‖`,
@@ -289,19 +289,19 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
           mul_le_mul_of_nonneg_right (f.dist_le_two_norm _ _) bernstein_nonneg
       _ = 2 * ‖f‖ * ∑ k in Sᶜ, bernstein n k x := by rw [Finset.mul_sum]
       _ ≤ 2 * ‖f‖ * ∑ k in Sᶜ, δ ^ (-2 : ℤ) * (x - k/ₙ) ^ 2 * bernstein n k x :=
-        mul_le_mul_of_nonneg_left
+        (mul_le_mul_of_nonneg_left
           (Finset.sum_le_sum fun k m =>
             by
             conv_lhs => rw [← one_mul (bernstein _ _ _)]
             exact mul_le_mul_of_nonneg_right (le_of_mem_S_compl m) bernstein_nonneg)
-          w₁
+          w₁)
       -- Again enlarging the sum from `Sᶜ` to all of `fin (n+1)`
           _ ≤
           2 * ‖f‖ * ∑ k : Fin (n + 1), δ ^ (-2 : ℤ) * (x - k/ₙ) ^ 2 * bernstein n k x :=
-        mul_le_mul_of_nonneg_left
+        (mul_le_mul_of_nonneg_left
           (Finset.sum_le_univ_sum_of_nonneg fun k =>
             mul_nonneg (mul_nonneg pow_minus_two_nonneg (sq_nonneg _)) bernstein_nonneg)
-          w₁
+          w₁)
       _ = 2 * ‖f‖ * δ ^ (-2 : ℤ) * ∑ k : Fin (n + 1), (x - k/ₙ) ^ 2 * bernstein n k x := by
         conv_rhs =>
           rw [mul_assoc, Finset.mul_sum]
@@ -313,8 +313,8 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
         rw [variance npos]
         ring
       _ ≤ 2 * ‖f‖ * δ ^ (-2 : ℤ) / n :=
-        (div_le_div_right npos).mpr <| by
-          refine' mul_le_of_le_of_le_one' (mul_le_of_le_one_right w₂ _) _ _ w₂ <;> unit_interval
+        ((div_le_div_right npos).mpr <| by
+          refine' mul_le_of_le_of_le_one' (mul_le_of_le_one_right w₂ _) _ _ w₂ <;> unit_interval)
       _ < ε / 2 := nh
       
 #align bernstein_approximation_uniform bernsteinApproximation_uniform

Changes in mathlib4

mathlib3
mathlib4
doc: three positivity extensions (#12483)
Diff
@@ -75,6 +75,7 @@ namespace Mathlib.Meta.Positivity
 
 open Lean Meta Qq Function
 
+/-- Extension of the `positivity` tactic for Bernstein polynomials: they are always non-negative. -/
 @[positivity DFunLike.coe _ _]
 def evalBernstein : PositivityExt where eval {_ _} _zα _pα e := do
   let .app (.app _coe (.app (.app _ n) ν)) x ← whnfR e | throwError "not bernstein polynomial"
chore: Rename nat_cast/int_cast/rat_cast to natCast/intCast/ratCast (#11486)

Now that I am defining NNRat.cast, I want a definitive answer to this naming issue. Plenty of lemmas in mathlib already use natCast/intCast/ratCast over nat_cast/int_cast/rat_cast, and this matches with the general expectation that underscore-separated name parts correspond to a single declaration.

Diff
@@ -123,7 +123,7 @@ theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
   conv_rhs => rw [div_mul_cancel₀ _ h']
   have := bernsteinPolynomial.variance ℝ n
   apply_fun fun p => Polynomial.aeval (x : ℝ) p at this
-  simp? [AlgHom.map_sum, Finset.sum_range, ← Polynomial.nat_cast_mul] at this says
+  simp? [AlgHom.map_sum, Finset.sum_range, ← Polynomial.natCast_mul] at this says
     simp only [nsmul_eq_mul, Finset.sum_range, map_sum, map_mul, map_pow, map_sub, map_natCast,
       Polynomial.aeval_X, Polynomial.coe_aeval_eq_eval, map_one] at this
   convert this using 1
chore: superfluous parentheses part 2 (#12131)

Co-authored-by: Moritz Firsching <firsching@google.com>

Diff
@@ -202,7 +202,7 @@ This particular formulation will be helpful later.
 theorem le_of_mem_S_compl {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : Fin (n + 1)}
     (m : k ∈ (S f ε h n x)ᶜ) : (1 : ℝ) ≤ δ f ε h ^ (-2 : ℤ) * ((x : ℝ) - k/ₙ) ^ 2 := by
   -- Porting note: added parentheses to help `simp`
-  simp only [Finset.mem_compl, not_lt, (Set.mem_toFinset), Set.mem_setOf_eq, S] at m
+  simp only [Finset.mem_compl, not_lt, Set.mem_toFinset, Set.mem_setOf_eq, S] at m
   rw [zpow_neg, ← div_eq_inv_mul, zpow_two, ← pow_two, one_le_div (pow_pos δ_pos 2), sq_le_sq,
     abs_of_pos δ_pos]
   rwa [dist_comm] at m
@@ -249,7 +249,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
       rw [bernstein.probability]
     _ = |∑ k : Fin (n + 1), (f k/ₙ - f x) * bernstein n k x| := by
       simp [bernsteinApproximation, Finset.mul_sum, sub_mul]
-    _ ≤ ∑ k : Fin (n + 1), |(f k/ₙ - f x) * bernstein n k x| := (Finset.abs_sum_le_sum_abs _ _)
+    _ ≤ ∑ k : Fin (n + 1), |(f k/ₙ - f x) * bernstein n k x| := Finset.abs_sum_le_sum_abs _ _
     _ = ∑ k : Fin (n + 1), |f k/ₙ - f x| * bernstein n k x := by
       simp_rw [abs_mul, abs_eq_self.mpr bernstein_nonneg]
     _ = (∑ k in S, |f k/ₙ - f x| * bernstein n k x) + ∑ k in Sᶜ, |f k/ₙ - f x| * bernstein n k x :=
chore: Rename mul-div cancellation lemmas (#11530)

Lemma names around cancellation of multiplication and division are a mess.

This PR renames a handful of them according to the following table (each big row contains the multiplicative statement, then the three rows contain the GroupWithZero lemma name, the Group lemma, the AddGroup lemma name).

| Statement | New name | Old name | |

Diff
@@ -120,7 +120,7 @@ theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
   apply_fun fun x : ℝ => x * n using GroupWithZero.mul_right_injective h'
   dsimp
   conv_lhs => simp only [Finset.sum_mul, z]
-  conv_rhs => rw [div_mul_cancel _ h']
+  conv_rhs => rw [div_mul_cancel₀ _ h']
   have := bernsteinPolynomial.variance ℝ n
   apply_fun fun p => Polynomial.aeval (x : ℝ) p at this
   simp? [AlgHom.map_sum, Finset.sum_range, ← Polynomial.nat_cast_mul] at this says
chore(Analysis/SpecificLimits/* and others): rename _0 -> _zero, _1 -> _one (#10077)

See here on Zulip.

This PR changes a bunch of names containing nhds_0 or/and lt_1 to nhds_zero or/and lt_one.

Diff
@@ -232,7 +232,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
   simp only [Metric.nhds_basis_ball.tendsto_right_iff, Metric.mem_ball, dist_eq_norm]
   intro ε h
   let δ := δ f ε h
-  have nhds_zero := tendsto_const_div_atTop_nhds_0_nat (2 * ‖f‖ * δ ^ (-2 : ℤ))
+  have nhds_zero := tendsto_const_div_atTop_nhds_zero_nat (2 * ‖f‖ * δ ^ (-2 : ℤ))
   filter_upwards [nhds_zero.eventually (gt_mem_nhds (half_pos h)), eventually_gt_atTop 0] with n nh
     npos'
   have npos : 0 < (n : ℝ) := by positivity
chore(*): rename FunLike to DFunLike (#9785)

This prepares for the introduction of a non-dependent synonym of FunLike, which helps a lot with keeping #8386 readable.

This is entirely search-and-replace in 680197f combined with manual fixes in 4145626, e900597 and b8428f8. The commands that generated this change:

sed -i 's/\bFunLike\b/DFunLike/g' {Archive,Counterexamples,Mathlib,test}/**/*.lean
sed -i 's/\btoFunLike\b/toDFunLike/g' {Archive,Counterexamples,Mathlib,test}/**/*.lean
sed -i 's/import Mathlib.Data.DFunLike/import Mathlib.Data.FunLike/g' {Archive,Counterexamples,Mathlib,test}/**/*.lean
sed -i 's/\bHom_FunLike\b/Hom_DFunLike/g' {Archive,Counterexamples,Mathlib,test}/**/*.lean     
sed -i 's/\binstFunLike\b/instDFunLike/g' {Archive,Counterexamples,Mathlib,test}/**/*.lean
sed -i 's/\bfunLike\b/instDFunLike/g' {Archive,Counterexamples,Mathlib,test}/**/*.lean
sed -i 's/\btoo many metavariables to apply `fun_like.has_coe_to_fun`/too many metavariables to apply `DFunLike.hasCoeToFun`/g' {Archive,Counterexamples,Mathlib,test}/**/*.lean

Co-authored-by: Anne Baanen <Vierkantor@users.noreply.github.com>

Diff
@@ -75,7 +75,7 @@ namespace Mathlib.Meta.Positivity
 
 open Lean Meta Qq Function
 
-@[positivity FunLike.coe _ _]
+@[positivity DFunLike.coe _ _]
 def evalBernstein : PositivityExt where eval {_ _} _zα _pα e := do
   let .app (.app _coe (.app (.app _ n) ν)) x ← whnfR e | throwError "not bernstein polynomial"
   let p ← mkAppOptM ``bernstein_nonneg #[n, ν, x]
chore(*): drop $/<| before fun (#9361)

Subset of #9319

Diff
@@ -287,7 +287,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
       -- Again enlarging the sum from `Sᶜ` to all of `Fin (n+1)`
       _ ≤ 2 * ‖f‖ * ∑ k : Fin (n + 1), δ ^ (-2 : ℤ) * ((x : ℝ) - k/ₙ) ^ 2 * bernstein n k x := by
         gcongr
-        refine Finset.sum_le_univ_sum_of_nonneg <| fun k => ?_
+        refine Finset.sum_le_univ_sum_of_nonneg fun k => ?_
         positivity
       _ = 2 * ‖f‖ * δ ^ (-2 : ℤ) * ∑ k : Fin (n + 1), ((x : ℝ) - k/ₙ) ^ 2 * bernstein n k x := by
         conv_rhs =>
feat: positivity extension for zpow (#8003)

This PR adds a positivity extension for integer powers, i.e. a ^ (r : ℤ). It's basically copy-pasted from the natural power extension. Note that this makes the imports of Mathlib.Tactic.Positivity.Basic slightly heavier since the required lemmas were not there (and the relevant file doesn't import positivity so I couldn't put it there either). It's probably not too bad, but I can put it in a new file if people think this would be better.

Co-authored-by: David Renshaw <dwrenshaw@gmail.com>

Diff
@@ -236,7 +236,6 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
   filter_upwards [nhds_zero.eventually (gt_mem_nhds (half_pos h)), eventually_gt_atTop 0] with n nh
     npos'
   have npos : 0 < (n : ℝ) := by positivity
-  have w₂ : 0 ≤ δ ^ (-2:ℤ) := zpow_neg_two_nonneg _ -- TODO: need a positivity extension for `zpow`
   -- As `[0,1]` is compact, it suffices to check the inequality pointwise.
   rw [ContinuousMap.norm_lt_iff _ h]
   intro x
chore: Remove nonterminal simp at (#7795)

Removes nonterminal uses of simp at. Replaces most of these with instances of simp? ... says.

Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Mario Carneiro <di.gama@gmail.com>

Diff
@@ -108,7 +108,8 @@ local postfix:90 "/ₙ" => z
 theorem probability (n : ℕ) (x : I) : (∑ k : Fin (n + 1), bernstein n k x) = 1 := by
   have := bernsteinPolynomial.sum ℝ n
   apply_fun fun p => Polynomial.aeval (x : ℝ) p at this
-  simp [AlgHom.map_sum, Finset.sum_range] at this
+  simp? [AlgHom.map_sum, Finset.sum_range] at this says
+    simp only [Finset.sum_range, map_sum, Polynomial.coe_aeval_eq_eval, map_one] at this
   exact this
 #align bernstein.probability bernstein.probability
 
@@ -122,7 +123,9 @@ theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
   conv_rhs => rw [div_mul_cancel _ h']
   have := bernsteinPolynomial.variance ℝ n
   apply_fun fun p => Polynomial.aeval (x : ℝ) p at this
-  simp [AlgHom.map_sum, Finset.sum_range, ← Polynomial.nat_cast_mul] at this
+  simp? [AlgHom.map_sum, Finset.sum_range, ← Polynomial.nat_cast_mul] at this says
+    simp only [nsmul_eq_mul, Finset.sum_range, map_sum, map_mul, map_pow, map_sub, map_natCast,
+      Polynomial.aeval_X, Polynomial.coe_aeval_eq_eval, map_one] at this
   convert this using 1
   · congr 1; funext k
     rw [mul_comm _ (n : ℝ), mul_comm _ (n : ℝ), ← mul_assoc, ← mul_assoc]
chore: replace exact_mod_cast tactic with mod_cast elaborator where possible (#8404)

We still have the exact_mod_cast tactic, used in a few places, which somehow (?) works a little bit harder to prevent the expected type influencing the elaboration of the term. I would like to get to the bottom of this, and it will be easier once the only usages of exact_mod_cast are the ones that don't work using the term elaborator by itself.

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -96,8 +96,8 @@ def z {n : ℕ} (k : Fin (n + 1)) : I :=
   ⟨(k : ℝ) / n, by
     cases' n with n
     · norm_num
-    · have h₁ : 0 < (n.succ : ℝ) := by exact_mod_cast Nat.succ_pos _
-      have h₂ : ↑k ≤ n.succ := by exact_mod_cast Fin.le_last k
+    · have h₁ : 0 < (n.succ : ℝ) := mod_cast Nat.succ_pos _
+      have h₂ : ↑k ≤ n.succ := mod_cast Fin.le_last k
       rw [Set.mem_Icc, le_div_iff h₁, div_le_iff h₁]
       norm_cast
       simp [h₂]⟩
feat: some improvements to apply_fun (#6732)
  • Re-enabling applying an order equiv to the target
  • using withMainContext so that locals are treated properly
  • enabling some commented out tests
Diff
@@ -115,12 +115,8 @@ theorem probability (n : ℕ) (x : I) : (∑ k : Fin (n + 1), bernstein n k x) =
 theorem variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :
     (∑ k : Fin (n + 1), (x - k/ₙ : ℝ) ^ 2 * bernstein n k x) = (x : ℝ) * (1 - x) / n := by
   have h' : (n : ℝ) ≠ 0 := ne_of_gt h
-  -- Porting note: fails with `unknown identifier 'h''`
-  -- apply_fun fun x : ℝ => x * n using GroupWithZero.mul_right_injective h'
-  -- apply_fun fun x : ℝ => x * n using GroupWithZero.mul_right_injective h'
-  have h'' := GroupWithZero.mul_right_injective h'
-  apply h''
-  apply h''
+  apply_fun fun x : ℝ => x * n using GroupWithZero.mul_right_injective h'
+  apply_fun fun x : ℝ => x * n using GroupWithZero.mul_right_injective h'
   dsimp
   conv_lhs => simp only [Finset.sum_mul, z]
   conv_rhs => rw [div_mul_cancel _ h']
chore: script to replace headers with #align_import statements (#5979)

Open in Gitpod

Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -2,17 +2,14 @@
 Copyright (c) 2021 Scott Morrison. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Scott Morrison
-
-! This file was ported from Lean 3 source module analysis.special_functions.bernstein
-! leanprover-community/mathlib commit 2c1d8ca2812b64f88992a5294ea3dba144755cd1
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathlib.Analysis.SpecificLimits.Basic
 import Mathlib.RingTheory.Polynomial.Bernstein
 import Mathlib.Topology.ContinuousFunction.Polynomial
 import Mathlib.Topology.ContinuousFunction.Compact
 
+#align_import analysis.special_functions.bernstein from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1"
+
 /-!
 # Bernstein approximations and Weierstrass' theorem
 
fix: ∑' precedence (#5615)
  • Also remove most superfluous parentheses around big operators (, and variants).
  • roughly the used regex: ([^a-zA-Zα-ωΑ-Ω'𝓝ℳ₀𝕂ₛ)]) \(([∑∏][^()∑∏]*,[^()∑∏:]*)\) ([⊂⊆=<≤]) replaced by $1 $2 $3
Diff
@@ -266,7 +266,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
   · -- We now work on the terms in `S`: uniform continuity and `bernstein.probability`
     -- quickly give us a bound.
     calc
-      (∑ k in S, |f k/ₙ - f x| * bernstein n k x) ≤ ∑ k in S, ε / 2 * bernstein n k x := by
+      ∑ k in S, |f k/ₙ - f x| * bernstein n k x ≤ ∑ k in S, ε / 2 * bernstein n k x := by
         gcongr with _ m
         exact le_of_lt (lt_of_mem_S m)
       _ = ε / 2 * ∑ k in S, bernstein n k x := by rw [Finset.mul_sum]
@@ -280,7 +280,7 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
     -- and then insert a `δ^(-2) * (x - k/n)^2` factor
     -- (which is at least one because we are not in `S`).
     calc
-      (∑ k in Sᶜ, |f k/ₙ - f x| * bernstein n k x) ≤ ∑ k in Sᶜ, 2 * ‖f‖ * bernstein n k x := by
+      ∑ k in Sᶜ, |f k/ₙ - f x| * bernstein n k x ≤ ∑ k in Sᶜ, 2 * ‖f‖ * bernstein n k x := by
         gcongr
         apply f.dist_le_two_norm
       _ = 2 * ‖f‖ * ∑ k in Sᶜ, bernstein n k x := by rw [Finset.mul_sum]
fix precedence of Nat.iterate (#5589)
Diff
@@ -204,7 +204,7 @@ theorem lt_of_mem_S {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k
 This particular formulation will be helpful later.
 -/
 theorem le_of_mem_S_compl {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : Fin (n + 1)}
-    (m : k ∈ S f ε h n xᶜ) : (1 : ℝ) ≤ δ f ε h ^ (-2 : ℤ) * ((x : ℝ) - k/ₙ) ^ 2 := by
+    (m : k ∈ (S f ε h n x)ᶜ) : (1 : ℝ) ≤ δ f ε h ^ (-2 : ℤ) * ((x : ℝ) - k/ₙ) ^ 2 := by
   -- Porting note: added parentheses to help `simp`
   simp only [Finset.mem_compl, not_lt, (Set.mem_toFinset), Set.mem_setOf_eq, S] at m
   rw [zpow_neg, ← div_eq_inv_mul, zpow_two, ← pow_two, one_le_div (pow_pos δ_pos 2), sq_le_sq,
feat: golf using gcongr throughout the library (#4784)

Following on from #4702, another hundred sample uses of the gcongr tactic.

Diff
@@ -69,11 +69,23 @@ theorem bernstein_apply (n ν : ℕ) (x : I) :
 
 theorem bernstein_nonneg {n ν : ℕ} {x : I} : 0 ≤ bernstein n ν x := by
   simp only [bernstein_apply]
-  exact
-    mul_nonneg (mul_nonneg (Nat.cast_nonneg _) (pow_nonneg (by unit_interval) _))
-      (pow_nonneg (by unit_interval) _)
+  have h₁ : (0:ℝ) ≤ x := by unit_interval
+  have h₂ : (0:ℝ) ≤ 1 - x := by unit_interval
+  positivity
 #align bernstein_nonneg bernstein_nonneg
 
+namespace Mathlib.Meta.Positivity
+
+open Lean Meta Qq Function
+
+@[positivity FunLike.coe _ _]
+def evalBernstein : PositivityExt where eval {_ _} _zα _pα e := do
+  let .app (.app _coe (.app (.app _ n) ν)) x ← whnfR e | throwError "not bernstein polynomial"
+  let p ← mkAppOptM ``bernstein_nonneg #[n, ν, x]
+  pure (.nonnegative p)
+
+end Mathlib.Meta.Positivity
+
 /-!
 We now give a slight reformulation of `bernsteinPolynomial.variance`.
 -/
@@ -227,10 +239,8 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
   have nhds_zero := tendsto_const_div_atTop_nhds_0_nat (2 * ‖f‖ * δ ^ (-2 : ℤ))
   filter_upwards [nhds_zero.eventually (gt_mem_nhds (half_pos h)), eventually_gt_atTop 0] with n nh
     npos'
-  have npos : 0 < (n : ℝ) := by exact_mod_cast npos'
-  -- Two easy inequalities we'll need later:
-  have w₁ : 0 ≤ 2 * ‖f‖ := mul_nonneg (by norm_num) (norm_nonneg f)
-  have w₂ : 0 ≤ 2 * ‖f‖ * δ ^ (-2 : ℤ) := mul_nonneg w₁ (zpow_neg_two_nonneg _)
+  have npos : 0 < (n : ℝ) := by positivity
+  have w₂ : 0 ≤ δ ^ (-2:ℤ) := zpow_neg_two_nonneg _ -- TODO: need a positivity extension for `zpow`
   -- As `[0,1]` is compact, it suffices to check the inequality pointwise.
   rw [ContinuousMap.norm_lt_iff _ h]
   intro x
@@ -256,48 +266,40 @@ theorem bernsteinApproximation_uniform (f : C(I, ℝ)) :
   · -- We now work on the terms in `S`: uniform continuity and `bernstein.probability`
     -- quickly give us a bound.
     calc
-      (∑ k in S, |f k/ₙ - f x| * bernstein n k x) ≤ ∑ k in S, ε / 2 * bernstein n k x :=
-        Finset.sum_le_sum fun k m =>
-          mul_le_mul_of_nonneg_right (le_of_lt (lt_of_mem_S m)) bernstein_nonneg
+      (∑ k in S, |f k/ₙ - f x| * bernstein n k x) ≤ ∑ k in S, ε / 2 * bernstein n k x := by
+        gcongr with _ m
+        exact le_of_lt (lt_of_mem_S m)
       _ = ε / 2 * ∑ k in S, bernstein n k x := by rw [Finset.mul_sum]
       -- In this step we increase the sum over `S` back to a sum over all of `Fin (n+1)`,
       -- so that we can use `bernstein.probability`.
-      _ ≤
-          ε / 2 * ∑ k : Fin (n + 1), bernstein n k x :=
-        (mul_le_mul_of_nonneg_left (Finset.sum_le_univ_sum_of_nonneg fun k => bernstein_nonneg)
-          (le_of_lt (half_pos h)))
+      _ ≤ ε / 2 * ∑ k : Fin (n + 1), bernstein n k x := by
+        gcongr
+        exact Finset.sum_le_univ_sum_of_nonneg fun k => bernstein_nonneg
       _ = ε / 2 := by rw [bernstein.probability, mul_one]
   · -- We now turn to working on `Sᶜ`: we control the difference term just using `‖f‖`,
     -- and then insert a `δ^(-2) * (x - k/n)^2` factor
     -- (which is at least one because we are not in `S`).
     calc
-      (∑ k in Sᶜ, |f k/ₙ - f x| * bernstein n k x) ≤ ∑ k in Sᶜ, 2 * ‖f‖ * bernstein n k x :=
-        Finset.sum_le_sum fun k _ =>
-          mul_le_mul_of_nonneg_right (f.dist_le_two_norm _ _) bernstein_nonneg
+      (∑ k in Sᶜ, |f k/ₙ - f x| * bernstein n k x) ≤ ∑ k in Sᶜ, 2 * ‖f‖ * bernstein n k x := by
+        gcongr
+        apply f.dist_le_two_norm
       _ = 2 * ‖f‖ * ∑ k in Sᶜ, bernstein n k x := by rw [Finset.mul_sum]
-      _ ≤ 2 * ‖f‖ * ∑ k in Sᶜ, δ ^ (-2 : ℤ) * ((x : ℝ) - k/ₙ) ^ 2 * bernstein n k x :=
-        (mul_le_mul_of_nonneg_left
-          (Finset.sum_le_sum fun k m => by
-            conv_lhs => rw [← one_mul (bernstein _ _ _)]
-            exact mul_le_mul_of_nonneg_right (le_of_mem_S_compl m) bernstein_nonneg)
-          w₁)
+      _ ≤ 2 * ‖f‖ * ∑ k in Sᶜ, δ ^ (-2 : ℤ) * ((x : ℝ) - k/ₙ) ^ 2 * bernstein n k x := by
+        gcongr with _ m
+        conv_lhs => rw [← one_mul (bernstein _ _ _)]
+        gcongr
+        exact le_of_mem_S_compl m
       -- Again enlarging the sum from `Sᶜ` to all of `Fin (n+1)`
-      _ ≤
-          2 * ‖f‖ * ∑ k : Fin (n + 1), δ ^ (-2 : ℤ) * ((x : ℝ) - k/ₙ) ^ 2 * bernstein n k x :=
-        (mul_le_mul_of_nonneg_left
-          (Finset.sum_le_univ_sum_of_nonneg fun k =>
-            mul_nonneg (mul_nonneg (zpow_neg_two_nonneg _) (sq_nonneg _)) bernstein_nonneg)
-          w₁)
+      _ ≤ 2 * ‖f‖ * ∑ k : Fin (n + 1), δ ^ (-2 : ℤ) * ((x : ℝ) - k/ₙ) ^ 2 * bernstein n k x := by
+        gcongr
+        refine Finset.sum_le_univ_sum_of_nonneg <| fun k => ?_
+        positivity
       _ = 2 * ‖f‖ * δ ^ (-2 : ℤ) * ∑ k : Fin (n + 1), ((x : ℝ) - k/ₙ) ^ 2 * bernstein n k x := by
         conv_rhs =>
           rw [mul_assoc, Finset.mul_sum]
           simp only [← mul_assoc]
       -- `bernstein.variance` and `x ∈ [0,1]` gives the uniform bound
-      _ =
-          2 * ‖f‖ * δ ^ (-2 : ℤ) * x * (1 - x) / n :=
-        by rw [variance npos]; ring
-      _ ≤ 2 * ‖f‖ * δ ^ (-2 : ℤ) / n :=
-        ((div_le_div_right npos).mpr <| by
-          refine' mul_le_of_le_of_le_one' (mul_le_of_le_one_right w₂ _) _ _ w₂ <;> unit_interval)
-      _ < ε / 2 := nh
+      _ = 2 * ‖f‖ * δ ^ (-2 : ℤ) * x * (1 - x) / n := by rw [variance npos]; ring
+      _ ≤ 2 * ‖f‖ * δ ^ (-2 : ℤ) * 1 * 1 / n := by gcongr <;> unit_interval
+      _ < ε / 2 := by simp only [mul_one]; exact nh
 #align bernstein_approximation_uniform bernsteinApproximation_uniform
feat: port Analysis.SpecialFunctions.Bernstein (#4697)

Dependencies 10 + 733

734 files ported (98.7%)
323227 lines ported (98.4%)
Show graph

The unported dependencies are

The following 1 dependencies have changed in mathlib3 since they were ported, which may complicate porting this file