topology.metric_space.metrizable_uniformityMathlib.Topology.Metrizable.Uniformity

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)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(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
@@ -3,7 +3,7 @@ Copyright (c) 2022 Yury Kudryashov. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yury Kudryashov
 -/
-import Topology.MetricSpace.Metrizable
+import Topology.Metrizable.Basic
 
 #align_import topology.metric_space.metrizable_uniformity from "leanprover-community/mathlib"@"f60c6087a7275b72d5db3c5a1d0e19e35a429c0a"
 
@@ -255,7 +255,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
     refine' PseudoMetricSpace.le_two_mul_dist_ofPreNNDist _ _ _ fun x₁ x₂ x₃ x₄ => _
     by_cases H : ∃ n, (x₁, x₄) ∉ U n
     · refine' (dif_pos H).trans_le _
-      rw [← NNReal.div_le_iff' two_ne_zero, ← mul_one_div (_ ^ _), ← pow_succ']
+      rw [← NNReal.div_le_iff' two_ne_zero, ← mul_one_div (_ ^ _), ← pow_succ]
       simp only [le_max_iff, hle_d, ← not_and_or]
       rintro ⟨h₁₂, h₂₃, h₃₄⟩
       refine' Nat.find_spec H (hU_comp (lt_add_one <| Nat.find H) _)
@@ -268,8 +268,8 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
     rw [mem_set_of_eq] at hx
     contrapose! hx
     refine' le_trans _ ((div_le_iff' (zero_lt_two' ℝ)).2 (hd_le x.1 x.2))
-    rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ',
-      mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel _ (two_ne_zero' ℝ≥0), hle_d,
+    rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ,
+      mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel₀ _ (two_ne_zero' ℝ≥0), hle_d,
       Prod.mk.eta]
 #align uniform_space.metrizable_uniformity UniformSpace.metrizable_uniformity
 -/
Diff
@@ -146,7 +146,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
     simpa only [*, max_eq_right, MulZeroClass.mul_zero] using hd a b c c
   haveI : IsTrans X fun x y => d x y = 0 := ⟨hd₀_trans⟩
   induction' hn : length l using Nat.strong_induction_on with n ihn generalizing x y l
-  simp only at ihn ; subst n
+  simp only at ihn; subst n
   set L := zip_with d (x::l) (l ++ [y])
   have hL_len : length L = length l + 1 := by simp
   cases' eq_or_ne (d x y) 0 with hd₀ hd₀; · simp only [hd₀, zero_le]
@@ -163,7 +163,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
       intro hLm
       rw [mem_set_of_eq, take_all_of_le hLm, two_mul, add_le_iff_nonpos_left, nonpos_iff_eq_zero,
           sum_eq_zero_iff, ← all₂_iff_forall, all₂_zip_with, ←
-          chain_append_singleton_iff_forall₂] at hm  <;>
+          chain_append_singleton_iff_forall₂] at hm <;>
         [skip; · simp]
       exact hd₀ (hm.rel (mem_append.2 <| Or.inr <| mem_singleton_self _))
     have hs_bdd : BddAbove s := ⟨length l, hs_ub⟩
@@ -173,7 +173,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
   have hM_lty : M < length (l ++ [y]) := lt_length_right_of_zip_with hM_lt
   refine' ⟨(x::l).nthLe M hM_ltx, (l ++ [y]).nthLe M hM_lty, _, _, _⟩
   · cases M; · simp [dist_self]
-    rw [Nat.succ_le_iff] at hMl 
+    rw [Nat.succ_le_iff] at hMl
     have hMl' : length (take M l) = M := (length_take _ _).trans (min_eq_left hMl.le)
     simp only [nth_le]
     refine' (ihn _ hMl _ _ _ hMl').trans _
@@ -193,7 +193,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
     have hMs' : L.sum ≤ 2 * (L.take (M + 1)).Sum :=
       not_lt.1 fun h => (hMs.2 h.le).not_lt M.lt_succ_self
     rw [← sum_take_add_sum_drop L (M + 1), two_mul, add_le_add_iff_left, ← add_le_add_iff_right,
-      sum_take_add_sum_drop, ← two_mul] at hMs' 
+      sum_take_add_sum_drop, ← two_mul] at hMs'
     convert hMs'
     rwa [zip_with_distrib_drop, drop, drop_append_of_le_length]
 #align pseudo_metric_space.le_two_mul_dist_of_prenndist PseudoMetricSpace.le_two_mul_dist_ofPreNNDist
@@ -227,14 +227,14 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
           (eventually_uniformity_iterate_comp_subset (hB.mem m) 2) with
       ⟨φ, hφ_mono, hφ_comp, hφB⟩
     exact ⟨V ∘ φ, fun n => hV_symm _, hφ_comp, hφB⟩
-  letI := UniformSpace.separationSetoid X
+  letI := inseparableSetoid X
   set d : X → X → ℝ≥0 := fun x y => if h : ∃ n, (x, y) ∉ U n then (1 / 2) ^ Nat.find h else 0
   have hd₀ : ∀ {x y}, d x y = 0 ↔ x ≈ y := by
     intro x y; dsimp only [d]
     refine' Iff.trans _ hB.to_has_basis.mem_separation_rel.symm
     simp only [true_imp_iff]
     split_ifs with h
-    · rw [← Classical.not_forall] at h ; simp [h, pow_eq_zero_iff']
+    · rw [← Classical.not_forall] at h; simp [h, pow_eq_zero_iff']
     · simpa only [not_exists, Classical.not_not, eq_self_iff_true, true_iff_iff] using h
   have hd_symm : ∀ x y, d x y = d y x := by
     intro x y; dsimp only [d]
@@ -248,7 +248,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
     simp only [d]; split_ifs with h
     · rw [(pow_right_strictAnti hr.1 hr.2).le_iff_le, Nat.find_le_iff]
       exact ⟨fun ⟨m, hmn, hm⟩ hn => hm (hB.antitone hmn hn), fun h => ⟨n, le_rfl, h⟩⟩
-    · push_neg at h 
+    · push_neg at h
       simp only [h, not_true, (pow_pos hr.1 _).not_le]
   have hd_le : ∀ x y, ↑(d x y) ≤ 2 * dist x y :=
     by
@@ -265,7 +265,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
   · refine' fun n hn => ⟨n, hn, fun x hx => (hdist_le _ _).trans_lt _⟩
     rwa [← NNReal.coe_pow, NNReal.coe_lt_coe, ← not_le, hle_d, Classical.not_not, Prod.mk.eta]
   · refine' fun n hn => ⟨n + 1, trivial, fun x hx => _⟩
-    rw [mem_set_of_eq] at hx 
+    rw [mem_set_of_eq] at hx
     contrapose! hx
     refine' le_trans _ ((div_le_iff' (zero_lt_two' ℝ)).2 (hd_le x.1 x.2))
     rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ',
Diff
@@ -73,7 +73,7 @@ noncomputable def ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x
     (NNReal.coe_eq_zero _).2 <|
       nonpos_iff_eq_zero.1 <| (ciInf_le (OrderBot.bddBelow _) []).trans_eq <| by simp [dist_self]
   dist_comm x y :=
-    NNReal.coe_eq.2 <| by
+    NNReal.coe_inj.2 <| by
       refine' reverse_surjective.infi_congr _ fun l => _
       rw [← sum_reverse, zip_with_distrib_reverse, reverse_append, reverse_reverse,
         reverse_singleton, singleton_append, reverse_cons, reverse_reverse,
Diff
@@ -206,19 +206,75 @@ end PseudoMetricSpace
 `pseudo_metric_space` structure compatible with the `uniform_space` structure. Use
 `uniform_space.pseudo_metric_space` or `uniform_space.metric_space` instead. -/
 protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace X]
-    [IsCountablyGenerated (𝓤 X)] : ∃ I : PseudoMetricSpace X, I.toUniformSpace = ‹_› := by classical
+    [IsCountablyGenerated (𝓤 X)] : ∃ I : PseudoMetricSpace X, I.toUniformSpace = ‹_› := by
+  classical
+  /- Choose a fast decreasing antitone basis `U : ℕ → set (X × X)` of the uniformity filter `𝓤 X`.
+    Define `d x y : ℝ≥0` to be `(1 / 2) ^ n`, where `n` is the minimal index of `U n` that separates
+    `x` and `y`: `(x, y) ∉ U n`, or `0` if `x` is not separated from `y`. This function satisfies the
+    assumptions of `pseudo_metric_space.of_prenndist` and
+    `pseudo_metric_space.le_two_mul_dist_of_prenndist`, hence the distance given by the former pseudo
+    metric space structure is Lipschitz equivalent to the `d`. Thus the uniformities generated by
+    `d` and `dist` are equal. Since the former uniformity is equal to `𝓤 X`, the latter is equal to
+    `𝓤 X` as well. -/
+  obtain ⟨U, hU_symm, hU_comp, hB⟩ :
+    ∃ U : ℕ → Set (X × X),
+      (∀ n, SymmetricRel (U n)) ∧
+        (∀ ⦃m n⦄, m < n → U n ○ (U n ○ U n) ⊆ U m) ∧ (𝓤 X).HasAntitoneBasis U :=
+    by
+    rcases UniformSpace.has_seq_basis X with ⟨V, hB, hV_symm⟩
+    rcases hB.subbasis_with_rel fun m =>
+        hB.tendsto_small_sets.eventually
+          (eventually_uniformity_iterate_comp_subset (hB.mem m) 2) with
+      ⟨φ, hφ_mono, hφ_comp, hφB⟩
+    exact ⟨V ∘ φ, fun n => hV_symm _, hφ_comp, hφB⟩
+  letI := UniformSpace.separationSetoid X
+  set d : X → X → ℝ≥0 := fun x y => if h : ∃ n, (x, y) ∉ U n then (1 / 2) ^ Nat.find h else 0
+  have hd₀ : ∀ {x y}, d x y = 0 ↔ x ≈ y := by
+    intro x y; dsimp only [d]
+    refine' Iff.trans _ hB.to_has_basis.mem_separation_rel.symm
+    simp only [true_imp_iff]
+    split_ifs with h
+    · rw [← Classical.not_forall] at h ; simp [h, pow_eq_zero_iff']
+    · simpa only [not_exists, Classical.not_not, eq_self_iff_true, true_iff_iff] using h
+  have hd_symm : ∀ x y, d x y = d y x := by
+    intro x y; dsimp only [d]
+    simp only [@SymmetricRel.mk_mem_comm _ _ (hU_symm _) x y]
+  have hr : (1 / 2 : ℝ≥0) ∈ Ioo (0 : ℝ≥0) 1 := ⟨half_pos one_pos, NNReal.half_lt_self one_ne_zero⟩
+  letI I := PseudoMetricSpace.ofPreNNDist d (fun x => hd₀.2 (Setoid.refl _)) hd_symm
+  have hdist_le : ∀ x y, dist x y ≤ d x y := PseudoMetricSpace.dist_ofPreNNDist_le _ _ _
+  have hle_d : ∀ {x y : X} {n : ℕ}, (1 / 2) ^ n ≤ d x y ↔ (x, y) ∉ U n :=
+    by
+    intro x y n
+    simp only [d]; split_ifs with h
+    · rw [(pow_right_strictAnti hr.1 hr.2).le_iff_le, Nat.find_le_iff]
+      exact ⟨fun ⟨m, hmn, hm⟩ hn => hm (hB.antitone hmn hn), fun h => ⟨n, le_rfl, h⟩⟩
+    · push_neg at h 
+      simp only [h, not_true, (pow_pos hr.1 _).not_le]
+  have hd_le : ∀ x y, ↑(d x y) ≤ 2 * dist x y :=
+    by
+    refine' PseudoMetricSpace.le_two_mul_dist_ofPreNNDist _ _ _ fun x₁ x₂ x₃ x₄ => _
+    by_cases H : ∃ n, (x₁, x₄) ∉ U n
+    · refine' (dif_pos H).trans_le _
+      rw [← NNReal.div_le_iff' two_ne_zero, ← mul_one_div (_ ^ _), ← pow_succ']
+      simp only [le_max_iff, hle_d, ← not_and_or]
+      rintro ⟨h₁₂, h₂₃, h₃₄⟩
+      refine' Nat.find_spec H (hU_comp (lt_add_one <| Nat.find H) _)
+      exact ⟨x₂, h₁₂, x₃, h₂₃, h₃₄⟩
+    · exact (dif_neg H).trans_le (zero_le _)
+  refine' ⟨I, UniformSpace.ext <| (uniformity_basis_dist_pow hr.1 hr.2).ext hB.to_has_basis _ _⟩
+  · refine' fun n hn => ⟨n, hn, fun x hx => (hdist_le _ _).trans_lt _⟩
+    rwa [← NNReal.coe_pow, NNReal.coe_lt_coe, ← not_le, hle_d, Classical.not_not, Prod.mk.eta]
+  · refine' fun n hn => ⟨n + 1, trivial, fun x hx => _⟩
+    rw [mem_set_of_eq] at hx 
+    contrapose! hx
+    refine' le_trans _ ((div_le_iff' (zero_lt_two' ℝ)).2 (hd_le x.1 x.2))
+    rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ',
+      mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel _ (two_ne_zero' ℝ≥0), hle_d,
+      Prod.mk.eta]
 #align uniform_space.metrizable_uniformity UniformSpace.metrizable_uniformity
 -/
 
 #print UniformSpace.pseudoMetricSpace /-
-/- Choose a fast decreasing antitone basis `U : ℕ → set (X × X)` of the uniformity filter `𝓤 X`.
-  Define `d x y : ℝ≥0` to be `(1 / 2) ^ n`, where `n` is the minimal index of `U n` that separates
-  `x` and `y`: `(x, y) ∉ U n`, or `0` if `x` is not separated from `y`. This function satisfies the
-  assumptions of `pseudo_metric_space.of_prenndist` and
-  `pseudo_metric_space.le_two_mul_dist_of_prenndist`, hence the distance given by the former pseudo
-  metric space structure is Lipschitz equivalent to the `d`. Thus the uniformities generated by
-  `d` and `dist` are equal. Since the former uniformity is equal to `𝓤 X`, the latter is equal to
-  `𝓤 X` as well. -/
 /-- A `pseudo_metric_space` instance compatible with a given `uniform_space` structure. -/
 protected noncomputable def UniformSpace.pseudoMetricSpace (X : Type _) [UniformSpace X]
     [IsCountablyGenerated (𝓤 X)] : PseudoMetricSpace X :=
Diff
@@ -206,75 +206,19 @@ end PseudoMetricSpace
 `pseudo_metric_space` structure compatible with the `uniform_space` structure. Use
 `uniform_space.pseudo_metric_space` or `uniform_space.metric_space` instead. -/
 protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace X]
-    [IsCountablyGenerated (𝓤 X)] : ∃ I : PseudoMetricSpace X, I.toUniformSpace = ‹_› := by
-  classical
-  /- Choose a fast decreasing antitone basis `U : ℕ → set (X × X)` of the uniformity filter `𝓤 X`.
-    Define `d x y : ℝ≥0` to be `(1 / 2) ^ n`, where `n` is the minimal index of `U n` that separates
-    `x` and `y`: `(x, y) ∉ U n`, or `0` if `x` is not separated from `y`. This function satisfies the
-    assumptions of `pseudo_metric_space.of_prenndist` and
-    `pseudo_metric_space.le_two_mul_dist_of_prenndist`, hence the distance given by the former pseudo
-    metric space structure is Lipschitz equivalent to the `d`. Thus the uniformities generated by
-    `d` and `dist` are equal. Since the former uniformity is equal to `𝓤 X`, the latter is equal to
-    `𝓤 X` as well. -/
-  obtain ⟨U, hU_symm, hU_comp, hB⟩ :
-    ∃ U : ℕ → Set (X × X),
-      (∀ n, SymmetricRel (U n)) ∧
-        (∀ ⦃m n⦄, m < n → U n ○ (U n ○ U n) ⊆ U m) ∧ (𝓤 X).HasAntitoneBasis U :=
-    by
-    rcases UniformSpace.has_seq_basis X with ⟨V, hB, hV_symm⟩
-    rcases hB.subbasis_with_rel fun m =>
-        hB.tendsto_small_sets.eventually
-          (eventually_uniformity_iterate_comp_subset (hB.mem m) 2) with
-      ⟨φ, hφ_mono, hφ_comp, hφB⟩
-    exact ⟨V ∘ φ, fun n => hV_symm _, hφ_comp, hφB⟩
-  letI := UniformSpace.separationSetoid X
-  set d : X → X → ℝ≥0 := fun x y => if h : ∃ n, (x, y) ∉ U n then (1 / 2) ^ Nat.find h else 0
-  have hd₀ : ∀ {x y}, d x y = 0 ↔ x ≈ y := by
-    intro x y; dsimp only [d]
-    refine' Iff.trans _ hB.to_has_basis.mem_separation_rel.symm
-    simp only [true_imp_iff]
-    split_ifs with h
-    · rw [← Classical.not_forall] at h ; simp [h, pow_eq_zero_iff']
-    · simpa only [not_exists, Classical.not_not, eq_self_iff_true, true_iff_iff] using h
-  have hd_symm : ∀ x y, d x y = d y x := by
-    intro x y; dsimp only [d]
-    simp only [@SymmetricRel.mk_mem_comm _ _ (hU_symm _) x y]
-  have hr : (1 / 2 : ℝ≥0) ∈ Ioo (0 : ℝ≥0) 1 := ⟨half_pos one_pos, NNReal.half_lt_self one_ne_zero⟩
-  letI I := PseudoMetricSpace.ofPreNNDist d (fun x => hd₀.2 (Setoid.refl _)) hd_symm
-  have hdist_le : ∀ x y, dist x y ≤ d x y := PseudoMetricSpace.dist_ofPreNNDist_le _ _ _
-  have hle_d : ∀ {x y : X} {n : ℕ}, (1 / 2) ^ n ≤ d x y ↔ (x, y) ∉ U n :=
-    by
-    intro x y n
-    simp only [d]; split_ifs with h
-    · rw [(pow_right_strictAnti hr.1 hr.2).le_iff_le, Nat.find_le_iff]
-      exact ⟨fun ⟨m, hmn, hm⟩ hn => hm (hB.antitone hmn hn), fun h => ⟨n, le_rfl, h⟩⟩
-    · push_neg at h 
-      simp only [h, not_true, (pow_pos hr.1 _).not_le]
-  have hd_le : ∀ x y, ↑(d x y) ≤ 2 * dist x y :=
-    by
-    refine' PseudoMetricSpace.le_two_mul_dist_ofPreNNDist _ _ _ fun x₁ x₂ x₃ x₄ => _
-    by_cases H : ∃ n, (x₁, x₄) ∉ U n
-    · refine' (dif_pos H).trans_le _
-      rw [← NNReal.div_le_iff' two_ne_zero, ← mul_one_div (_ ^ _), ← pow_succ']
-      simp only [le_max_iff, hle_d, ← not_and_or]
-      rintro ⟨h₁₂, h₂₃, h₃₄⟩
-      refine' Nat.find_spec H (hU_comp (lt_add_one <| Nat.find H) _)
-      exact ⟨x₂, h₁₂, x₃, h₂₃, h₃₄⟩
-    · exact (dif_neg H).trans_le (zero_le _)
-  refine' ⟨I, UniformSpace.ext <| (uniformity_basis_dist_pow hr.1 hr.2).ext hB.to_has_basis _ _⟩
-  · refine' fun n hn => ⟨n, hn, fun x hx => (hdist_le _ _).trans_lt _⟩
-    rwa [← NNReal.coe_pow, NNReal.coe_lt_coe, ← not_le, hle_d, Classical.not_not, Prod.mk.eta]
-  · refine' fun n hn => ⟨n + 1, trivial, fun x hx => _⟩
-    rw [mem_set_of_eq] at hx 
-    contrapose! hx
-    refine' le_trans _ ((div_le_iff' (zero_lt_two' ℝ)).2 (hd_le x.1 x.2))
-    rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ',
-      mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel _ (two_ne_zero' ℝ≥0), hle_d,
-      Prod.mk.eta]
+    [IsCountablyGenerated (𝓤 X)] : ∃ I : PseudoMetricSpace X, I.toUniformSpace = ‹_› := by classical
 #align uniform_space.metrizable_uniformity UniformSpace.metrizable_uniformity
 -/
 
 #print UniformSpace.pseudoMetricSpace /-
+/- Choose a fast decreasing antitone basis `U : ℕ → set (X × X)` of the uniformity filter `𝓤 X`.
+  Define `d x y : ℝ≥0` to be `(1 / 2) ^ n`, where `n` is the minimal index of `U n` that separates
+  `x` and `y`: `(x, y) ∉ U n`, or `0` if `x` is not separated from `y`. This function satisfies the
+  assumptions of `pseudo_metric_space.of_prenndist` and
+  `pseudo_metric_space.le_two_mul_dist_of_prenndist`, hence the distance given by the former pseudo
+  metric space structure is Lipschitz equivalent to the `d`. Thus the uniformities generated by
+  `d` and `dist` are equal. Since the former uniformity is equal to `𝓤 X`, the latter is equal to
+  `𝓤 X` as well. -/
 /-- A `pseudo_metric_space` instance compatible with a given `uniform_space` structure. -/
 protected noncomputable def UniformSpace.pseudoMetricSpace (X : Type _) [UniformSpace X]
     [IsCountablyGenerated (𝓤 X)] : PseudoMetricSpace X :=
Diff
@@ -246,7 +246,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
     by
     intro x y n
     simp only [d]; split_ifs with h
-    · rw [(strictAnti_pow hr.1 hr.2).le_iff_le, Nat.find_le_iff]
+    · rw [(pow_right_strictAnti hr.1 hr.2).le_iff_le, Nat.find_le_iff]
       exact ⟨fun ⟨m, hmn, hm⟩ hn => hm (hB.antitone hmn hn), fun h => ⟨n, le_rfl, h⟩⟩
     · push_neg at h 
       simp only [h, not_true, (pow_pos hr.1 _).not_le]
Diff
@@ -234,7 +234,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
     refine' Iff.trans _ hB.to_has_basis.mem_separation_rel.symm
     simp only [true_imp_iff]
     split_ifs with h
-    · rw [← not_forall] at h ; simp [h, pow_eq_zero_iff']
+    · rw [← Classical.not_forall] at h ; simp [h, pow_eq_zero_iff']
     · simpa only [not_exists, Classical.not_not, eq_self_iff_true, true_iff_iff] using h
   have hd_symm : ∀ x y, d x y = d y x := by
     intro x y; dsimp only [d]
Diff
@@ -3,7 +3,7 @@ Copyright (c) 2022 Yury Kudryashov. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yury Kudryashov
 -/
-import Mathbin.Topology.MetricSpace.Metrizable
+import Topology.MetricSpace.Metrizable
 
 #align_import topology.metric_space.metrizable_uniformity from "leanprover-community/mathlib"@"f60c6087a7275b72d5db3c5a1d0e19e35a429c0a"
 
Diff
@@ -261,7 +261,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
       refine' Nat.find_spec H (hU_comp (lt_add_one <| Nat.find H) _)
       exact ⟨x₂, h₁₂, x₃, h₂₃, h₃₄⟩
     · exact (dif_neg H).trans_le (zero_le _)
-  refine' ⟨I, uniformSpace_eq <| (uniformity_basis_dist_pow hr.1 hr.2).ext hB.to_has_basis _ _⟩
+  refine' ⟨I, UniformSpace.ext <| (uniformity_basis_dist_pow hr.1 hr.2).ext hB.to_has_basis _ _⟩
   · refine' fun n hn => ⟨n, hn, fun x hx => (hdist_le _ _).trans_lt _⟩
     rwa [← NNReal.coe_pow, NNReal.coe_lt_coe, ← not_le, hle_d, Classical.not_not, Prod.mk.eta]
   · refine' fun n hn => ⟨n + 1, trivial, fun x hx => _⟩
Diff
@@ -2,14 +2,11 @@
 Copyright (c) 2022 Yury Kudryashov. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yury Kudryashov
-
-! This file was ported from Lean 3 source module topology.metric_space.metrizable_uniformity
-! leanprover-community/mathlib commit f60c6087a7275b72d5db3c5a1d0e19e35a429c0a
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathbin.Topology.MetricSpace.Metrizable
 
+#align_import topology.metric_space.metrizable_uniformity from "leanprover-community/mathlib"@"f60c6087a7275b72d5db3c5a1d0e19e35a429c0a"
+
 /-!
 # Metrizable uniform spaces
 
Diff
@@ -65,6 +65,7 @@ namespace PseudoMetricSpace
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
+#print PseudoMetricSpace.ofPreNNDist /-
 /-- The maximal pseudo metric space structure on `X` such that `dist x y ≤ d x y` for all `x y`,
 where `d : X → X → ℝ≥0` is a function such that `d x x = 0` and `d x y = d y x` for all `x`, `y`. -/
 noncomputable def ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0)
@@ -93,8 +94,10 @@ noncomputable def ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x
       append_assoc, append_assoc]
     rw [length_cons, length_append, length_singleton]
 #align pseudo_metric_space.of_prenndist PseudoMetricSpace.ofPreNNDist
+-/
 
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
+#print PseudoMetricSpace.dist_ofPreNNDist /-
 theorem dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0)
     (dist_comm : ∀ x y, d x y = d y x) (x y : X) :
     @dist X (@PseudoMetricSpace.toHasDist X (PseudoMetricSpace.ofPreNNDist d dist_self dist_comm)) x
@@ -102,7 +105,9 @@ theorem dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0
       ↑(⨅ l : List X, ((x::l).zipWith d (l ++ [y])).Sum : ℝ≥0) :=
   rfl
 #align pseudo_metric_space.dist_of_prenndist PseudoMetricSpace.dist_ofPreNNDist
+-/
 
+#print PseudoMetricSpace.dist_ofPreNNDist_le /-
 theorem dist_ofPreNNDist_le (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0)
     (dist_comm : ∀ x y, d x y = d y x) (x y : X) :
     @dist X (@PseudoMetricSpace.toHasDist X (PseudoMetricSpace.ofPreNNDist d dist_self dist_comm)) x
@@ -110,10 +115,12 @@ theorem dist_ofPreNNDist_le (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x
       d x y :=
   NNReal.coe_le_coe.2 <| (ciInf_le (OrderBot.bddBelow _) []).trans_eq <| by simp
 #align pseudo_metric_space.dist_of_prenndist_le PseudoMetricSpace.dist_ofPreNNDist_le
+-/
 
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
+#print PseudoMetricSpace.le_two_mul_dist_ofPreNNDist /-
 /-- Consider a function `d : X → X → ℝ≥0` such that `d x x = 0` and `d x y = d y x` for all `x`,
 `y`. Let `dist` be the largest pseudometric distance such that `dist x y ≤ d x y`, see
 `pseudo_metric_space.of_prenndist`. Suppose that `d` satisfies the following triangle-like
@@ -193,6 +200,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
     convert hMs'
     rwa [zip_with_distrib_drop, drop, drop_append_of_le_length]
 #align pseudo_metric_space.le_two_mul_dist_of_prenndist PseudoMetricSpace.le_two_mul_dist_ofPreNNDist
+-/
 
 end PseudoMetricSpace
 
Diff
@@ -89,7 +89,6 @@ noncomputable def ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x
           (zip_with d (x::lxy ++ y::lyz) ((lxy ++ y::lyz) ++ [z])).Sum :=
         ciInf_le (OrderBot.bddBelow _) (lxy ++ y::lyz)
       _ = (zip_with d (x::lxy) (lxy ++ [y])).Sum + (zip_with d (y::lyz) (lyz ++ [z])).Sum := _
-      
     rw [← sum_append, ← zip_with_append, cons_append, ← @singleton_append _ y, append_assoc,
       append_assoc, append_assoc]
     rw [length_cons, length_append, length_singleton]
Diff
@@ -149,7 +149,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
   cases' eq_or_ne (d x y) 0 with hd₀ hd₀; · simp only [hd₀, zero_le]
   rsuffices ⟨z, z', hxz, hzz', hz'y⟩ : ∃ z z' : X, d x z ≤ L.sum ∧ d z z' ≤ L.sum ∧ d z' y ≤ L.sum
   · exact (hd x z z' y).trans (mul_le_mul_left' (max_le hxz (max_le hzz' hz'y)) _)
-  set s : Set ℕ := { m : ℕ | 2 * (take m L).Sum ≤ L.sum }
+  set s : Set ℕ := {m : ℕ | 2 * (take m L).Sum ≤ L.sum}
   have hs₀ : 0 ∈ s := by simp [s]
   have hsne : s.nonempty := ⟨0, hs₀⟩
   obtain ⟨M, hMl, hMs⟩ : ∃ M ≤ length l, IsGreatest s M :=
@@ -204,69 +204,69 @@ end PseudoMetricSpace
 protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace X]
     [IsCountablyGenerated (𝓤 X)] : ∃ I : PseudoMetricSpace X, I.toUniformSpace = ‹_› := by
   classical
-    /- Choose a fast decreasing antitone basis `U : ℕ → set (X × X)` of the uniformity filter `𝓤 X`.
-      Define `d x y : ℝ≥0` to be `(1 / 2) ^ n`, where `n` is the minimal index of `U n` that separates
-      `x` and `y`: `(x, y) ∉ U n`, or `0` if `x` is not separated from `y`. This function satisfies the
-      assumptions of `pseudo_metric_space.of_prenndist` and
-      `pseudo_metric_space.le_two_mul_dist_of_prenndist`, hence the distance given by the former pseudo
-      metric space structure is Lipschitz equivalent to the `d`. Thus the uniformities generated by
-      `d` and `dist` are equal. Since the former uniformity is equal to `𝓤 X`, the latter is equal to
-      `𝓤 X` as well. -/
-    obtain ⟨U, hU_symm, hU_comp, hB⟩ :
-      ∃ U : ℕ → Set (X × X),
-        (∀ n, SymmetricRel (U n)) ∧
-          (∀ ⦃m n⦄, m < n → U n ○ (U n ○ U n) ⊆ U m) ∧ (𝓤 X).HasAntitoneBasis U :=
-      by
-      rcases UniformSpace.has_seq_basis X with ⟨V, hB, hV_symm⟩
-      rcases hB.subbasis_with_rel fun m =>
-          hB.tendsto_small_sets.eventually
-            (eventually_uniformity_iterate_comp_subset (hB.mem m) 2) with
-        ⟨φ, hφ_mono, hφ_comp, hφB⟩
-      exact ⟨V ∘ φ, fun n => hV_symm _, hφ_comp, hφB⟩
-    letI := UniformSpace.separationSetoid X
-    set d : X → X → ℝ≥0 := fun x y => if h : ∃ n, (x, y) ∉ U n then (1 / 2) ^ Nat.find h else 0
-    have hd₀ : ∀ {x y}, d x y = 0 ↔ x ≈ y := by
-      intro x y; dsimp only [d]
-      refine' Iff.trans _ hB.to_has_basis.mem_separation_rel.symm
-      simp only [true_imp_iff]
-      split_ifs with h
-      · rw [← not_forall] at h ; simp [h, pow_eq_zero_iff']
-      · simpa only [not_exists, Classical.not_not, eq_self_iff_true, true_iff_iff] using h
-    have hd_symm : ∀ x y, d x y = d y x := by
-      intro x y; dsimp only [d]
-      simp only [@SymmetricRel.mk_mem_comm _ _ (hU_symm _) x y]
-    have hr : (1 / 2 : ℝ≥0) ∈ Ioo (0 : ℝ≥0) 1 := ⟨half_pos one_pos, NNReal.half_lt_self one_ne_zero⟩
-    letI I := PseudoMetricSpace.ofPreNNDist d (fun x => hd₀.2 (Setoid.refl _)) hd_symm
-    have hdist_le : ∀ x y, dist x y ≤ d x y := PseudoMetricSpace.dist_ofPreNNDist_le _ _ _
-    have hle_d : ∀ {x y : X} {n : ℕ}, (1 / 2) ^ n ≤ d x y ↔ (x, y) ∉ U n :=
-      by
-      intro x y n
-      simp only [d]; split_ifs with h
-      · rw [(strictAnti_pow hr.1 hr.2).le_iff_le, Nat.find_le_iff]
-        exact ⟨fun ⟨m, hmn, hm⟩ hn => hm (hB.antitone hmn hn), fun h => ⟨n, le_rfl, h⟩⟩
-      · push_neg  at h 
-        simp only [h, not_true, (pow_pos hr.1 _).not_le]
-    have hd_le : ∀ x y, ↑(d x y) ≤ 2 * dist x y :=
-      by
-      refine' PseudoMetricSpace.le_two_mul_dist_ofPreNNDist _ _ _ fun x₁ x₂ x₃ x₄ => _
-      by_cases H : ∃ n, (x₁, x₄) ∉ U n
-      · refine' (dif_pos H).trans_le _
-        rw [← NNReal.div_le_iff' two_ne_zero, ← mul_one_div (_ ^ _), ← pow_succ']
-        simp only [le_max_iff, hle_d, ← not_and_or]
-        rintro ⟨h₁₂, h₂₃, h₃₄⟩
-        refine' Nat.find_spec H (hU_comp (lt_add_one <| Nat.find H) _)
-        exact ⟨x₂, h₁₂, x₃, h₂₃, h₃₄⟩
-      · exact (dif_neg H).trans_le (zero_le _)
-    refine' ⟨I, uniformSpace_eq <| (uniformity_basis_dist_pow hr.1 hr.2).ext hB.to_has_basis _ _⟩
-    · refine' fun n hn => ⟨n, hn, fun x hx => (hdist_le _ _).trans_lt _⟩
-      rwa [← NNReal.coe_pow, NNReal.coe_lt_coe, ← not_le, hle_d, Classical.not_not, Prod.mk.eta]
-    · refine' fun n hn => ⟨n + 1, trivial, fun x hx => _⟩
-      rw [mem_set_of_eq] at hx 
-      contrapose! hx
-      refine' le_trans _ ((div_le_iff' (zero_lt_two' ℝ)).2 (hd_le x.1 x.2))
-      rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ',
-        mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel _ (two_ne_zero' ℝ≥0), hle_d,
-        Prod.mk.eta]
+  /- Choose a fast decreasing antitone basis `U : ℕ → set (X × X)` of the uniformity filter `𝓤 X`.
+    Define `d x y : ℝ≥0` to be `(1 / 2) ^ n`, where `n` is the minimal index of `U n` that separates
+    `x` and `y`: `(x, y) ∉ U n`, or `0` if `x` is not separated from `y`. This function satisfies the
+    assumptions of `pseudo_metric_space.of_prenndist` and
+    `pseudo_metric_space.le_two_mul_dist_of_prenndist`, hence the distance given by the former pseudo
+    metric space structure is Lipschitz equivalent to the `d`. Thus the uniformities generated by
+    `d` and `dist` are equal. Since the former uniformity is equal to `𝓤 X`, the latter is equal to
+    `𝓤 X` as well. -/
+  obtain ⟨U, hU_symm, hU_comp, hB⟩ :
+    ∃ U : ℕ → Set (X × X),
+      (∀ n, SymmetricRel (U n)) ∧
+        (∀ ⦃m n⦄, m < n → U n ○ (U n ○ U n) ⊆ U m) ∧ (𝓤 X).HasAntitoneBasis U :=
+    by
+    rcases UniformSpace.has_seq_basis X with ⟨V, hB, hV_symm⟩
+    rcases hB.subbasis_with_rel fun m =>
+        hB.tendsto_small_sets.eventually
+          (eventually_uniformity_iterate_comp_subset (hB.mem m) 2) with
+      ⟨φ, hφ_mono, hφ_comp, hφB⟩
+    exact ⟨V ∘ φ, fun n => hV_symm _, hφ_comp, hφB⟩
+  letI := UniformSpace.separationSetoid X
+  set d : X → X → ℝ≥0 := fun x y => if h : ∃ n, (x, y) ∉ U n then (1 / 2) ^ Nat.find h else 0
+  have hd₀ : ∀ {x y}, d x y = 0 ↔ x ≈ y := by
+    intro x y; dsimp only [d]
+    refine' Iff.trans _ hB.to_has_basis.mem_separation_rel.symm
+    simp only [true_imp_iff]
+    split_ifs with h
+    · rw [← not_forall] at h ; simp [h, pow_eq_zero_iff']
+    · simpa only [not_exists, Classical.not_not, eq_self_iff_true, true_iff_iff] using h
+  have hd_symm : ∀ x y, d x y = d y x := by
+    intro x y; dsimp only [d]
+    simp only [@SymmetricRel.mk_mem_comm _ _ (hU_symm _) x y]
+  have hr : (1 / 2 : ℝ≥0) ∈ Ioo (0 : ℝ≥0) 1 := ⟨half_pos one_pos, NNReal.half_lt_self one_ne_zero⟩
+  letI I := PseudoMetricSpace.ofPreNNDist d (fun x => hd₀.2 (Setoid.refl _)) hd_symm
+  have hdist_le : ∀ x y, dist x y ≤ d x y := PseudoMetricSpace.dist_ofPreNNDist_le _ _ _
+  have hle_d : ∀ {x y : X} {n : ℕ}, (1 / 2) ^ n ≤ d x y ↔ (x, y) ∉ U n :=
+    by
+    intro x y n
+    simp only [d]; split_ifs with h
+    · rw [(strictAnti_pow hr.1 hr.2).le_iff_le, Nat.find_le_iff]
+      exact ⟨fun ⟨m, hmn, hm⟩ hn => hm (hB.antitone hmn hn), fun h => ⟨n, le_rfl, h⟩⟩
+    · push_neg at h 
+      simp only [h, not_true, (pow_pos hr.1 _).not_le]
+  have hd_le : ∀ x y, ↑(d x y) ≤ 2 * dist x y :=
+    by
+    refine' PseudoMetricSpace.le_two_mul_dist_ofPreNNDist _ _ _ fun x₁ x₂ x₃ x₄ => _
+    by_cases H : ∃ n, (x₁, x₄) ∉ U n
+    · refine' (dif_pos H).trans_le _
+      rw [← NNReal.div_le_iff' two_ne_zero, ← mul_one_div (_ ^ _), ← pow_succ']
+      simp only [le_max_iff, hle_d, ← not_and_or]
+      rintro ⟨h₁₂, h₂₃, h₃₄⟩
+      refine' Nat.find_spec H (hU_comp (lt_add_one <| Nat.find H) _)
+      exact ⟨x₂, h₁₂, x₃, h₂₃, h₃₄⟩
+    · exact (dif_neg H).trans_le (zero_le _)
+  refine' ⟨I, uniformSpace_eq <| (uniformity_basis_dist_pow hr.1 hr.2).ext hB.to_has_basis _ _⟩
+  · refine' fun n hn => ⟨n, hn, fun x hx => (hdist_le _ _).trans_lt _⟩
+    rwa [← NNReal.coe_pow, NNReal.coe_lt_coe, ← not_le, hle_d, Classical.not_not, Prod.mk.eta]
+  · refine' fun n hn => ⟨n + 1, trivial, fun x hx => _⟩
+    rw [mem_set_of_eq] at hx 
+    contrapose! hx
+    refine' le_trans _ ((div_le_iff' (zero_lt_two' ℝ)).2 (hd_le x.1 x.2))
+    rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ',
+      mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel _ (two_ne_zero' ℝ≥0), hle_d,
+      Prod.mk.eta]
 #align uniform_space.metrizable_uniformity UniformSpace.metrizable_uniformity
 -/
 
Diff
@@ -143,7 +143,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
     simpa only [*, max_eq_right, MulZeroClass.mul_zero] using hd a b c c
   haveI : IsTrans X fun x y => d x y = 0 := ⟨hd₀_trans⟩
   induction' hn : length l using Nat.strong_induction_on with n ihn generalizing x y l
-  simp only at ihn; subst n
+  simp only at ihn ; subst n
   set L := zip_with d (x::l) (l ++ [y])
   have hL_len : length L = length l + 1 := by simp
   cases' eq_or_ne (d x y) 0 with hd₀ hd₀; · simp only [hd₀, zero_le]
@@ -160,8 +160,8 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
       intro hLm
       rw [mem_set_of_eq, take_all_of_le hLm, two_mul, add_le_iff_nonpos_left, nonpos_iff_eq_zero,
           sum_eq_zero_iff, ← all₂_iff_forall, all₂_zip_with, ←
-          chain_append_singleton_iff_forall₂] at hm <;>
-        [skip;· simp]
+          chain_append_singleton_iff_forall₂] at hm  <;>
+        [skip; · simp]
       exact hd₀ (hm.rel (mem_append.2 <| Or.inr <| mem_singleton_self _))
     have hs_bdd : BddAbove s := ⟨length l, hs_ub⟩
     exact ⟨Sup s, csSup_le hsne hs_ub, ⟨Nat.sSup_mem hsne hs_bdd, fun k => le_csSup hs_bdd⟩⟩
@@ -170,7 +170,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
   have hM_lty : M < length (l ++ [y]) := lt_length_right_of_zip_with hM_lt
   refine' ⟨(x::l).nthLe M hM_ltx, (l ++ [y]).nthLe M hM_lty, _, _, _⟩
   · cases M; · simp [dist_self]
-    rw [Nat.succ_le_iff] at hMl
+    rw [Nat.succ_le_iff] at hMl 
     have hMl' : length (take M l) = M := (length_take _ _).trans (min_eq_left hMl.le)
     simp only [nth_le]
     refine' (ihn _ hMl _ _ _ hMl').trans _
@@ -190,7 +190,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
     have hMs' : L.sum ≤ 2 * (L.take (M + 1)).Sum :=
       not_lt.1 fun h => (hMs.2 h.le).not_lt M.lt_succ_self
     rw [← sum_take_add_sum_drop L (M + 1), two_mul, add_le_add_iff_left, ← add_le_add_iff_right,
-      sum_take_add_sum_drop, ← two_mul] at hMs'
+      sum_take_add_sum_drop, ← two_mul] at hMs' 
     convert hMs'
     rwa [zip_with_distrib_drop, drop, drop_append_of_le_length]
 #align pseudo_metric_space.le_two_mul_dist_of_prenndist PseudoMetricSpace.le_two_mul_dist_ofPreNNDist
@@ -230,7 +230,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
       refine' Iff.trans _ hB.to_has_basis.mem_separation_rel.symm
       simp only [true_imp_iff]
       split_ifs with h
-      · rw [← not_forall] at h; simp [h, pow_eq_zero_iff']
+      · rw [← not_forall] at h ; simp [h, pow_eq_zero_iff']
       · simpa only [not_exists, Classical.not_not, eq_self_iff_true, true_iff_iff] using h
     have hd_symm : ∀ x y, d x y = d y x := by
       intro x y; dsimp only [d]
@@ -244,7 +244,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
       simp only [d]; split_ifs with h
       · rw [(strictAnti_pow hr.1 hr.2).le_iff_le, Nat.find_le_iff]
         exact ⟨fun ⟨m, hmn, hm⟩ hn => hm (hB.antitone hmn hn), fun h => ⟨n, le_rfl, h⟩⟩
-      · push_neg  at h
+      · push_neg  at h 
         simp only [h, not_true, (pow_pos hr.1 _).not_le]
     have hd_le : ∀ x y, ↑(d x y) ≤ 2 * dist x y :=
       by
@@ -261,7 +261,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
     · refine' fun n hn => ⟨n, hn, fun x hx => (hdist_le _ _).trans_lt _⟩
       rwa [← NNReal.coe_pow, NNReal.coe_lt_coe, ← not_le, hle_d, Classical.not_not, Prod.mk.eta]
     · refine' fun n hn => ⟨n + 1, trivial, fun x hx => _⟩
-      rw [mem_set_of_eq] at hx
+      rw [mem_set_of_eq] at hx 
       contrapose! hx
       refine' le_trans _ ((div_le_iff' (zero_lt_two' ℝ)).2 (hd_le x.1 x.2))
       rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ',
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yury Kudryashov
 
 ! This file was ported from Lean 3 source module topology.metric_space.metrizable_uniformity
-! leanprover-community/mathlib commit 195fcd60ff2bfe392543bceb0ec2adcdb472db4c
+! leanprover-community/mathlib commit f60c6087a7275b72d5db3c5a1d0e19e35a429c0a
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -13,6 +13,9 @@ import Mathbin.Topology.MetricSpace.Metrizable
 /-!
 # Metrizable uniform spaces
 
+> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
+> Any changes to this file require a corresponding PR to mathlib4.
+
 In this file we prove that a uniform space with countably generated uniformity filter is
 pseudometrizable: there exists a `pseudo_metric_space` structure that generates the same uniformity.
 The proof follows [Sergey Melikhov, Metrizable uniform spaces][melikhov2011].
@@ -64,7 +67,7 @@ namespace PseudoMetricSpace
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
 /-- The maximal pseudo metric space structure on `X` such that `dist x y ≤ d x y` for all `x y`,
 where `d : X → X → ℝ≥0` is a function such that `d x x = 0` and `d x y = d y x` for all `x`, `y`. -/
-noncomputable def ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0)
+noncomputable def ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0)
     (dist_comm : ∀ x y, d x y = d y x) : PseudoMetricSpace X
     where
   dist x y := ↑(⨅ l : List X, ((x::l).zipWith d (l ++ [y])).Sum : ℝ≥0)
@@ -90,24 +93,24 @@ noncomputable def ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x
     rw [← sum_append, ← zip_with_append, cons_append, ← @singleton_append _ y, append_assoc,
       append_assoc, append_assoc]
     rw [length_cons, length_append, length_singleton]
-#align pseudo_metric_space.of_prenndist PseudoMetricSpace.ofPrenndist
+#align pseudo_metric_space.of_prenndist PseudoMetricSpace.ofPreNNDist
 
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
-theorem dist_ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0)
+theorem dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0)
     (dist_comm : ∀ x y, d x y = d y x) (x y : X) :
-    @dist X (@PseudoMetricSpace.toHasDist X (PseudoMetricSpace.ofPrenndist d dist_self dist_comm)) x
+    @dist X (@PseudoMetricSpace.toHasDist X (PseudoMetricSpace.ofPreNNDist d dist_self dist_comm)) x
         y =
       ↑(⨅ l : List X, ((x::l).zipWith d (l ++ [y])).Sum : ℝ≥0) :=
   rfl
-#align pseudo_metric_space.dist_of_prenndist PseudoMetricSpace.dist_ofPrenndist
+#align pseudo_metric_space.dist_of_prenndist PseudoMetricSpace.dist_ofPreNNDist
 
-theorem dist_ofPrenndist_le (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0)
+theorem dist_ofPreNNDist_le (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0)
     (dist_comm : ∀ x y, d x y = d y x) (x y : X) :
-    @dist X (@PseudoMetricSpace.toHasDist X (PseudoMetricSpace.ofPrenndist d dist_self dist_comm)) x
+    @dist X (@PseudoMetricSpace.toHasDist X (PseudoMetricSpace.ofPreNNDist d dist_self dist_comm)) x
         y ≤
       d x y :=
   NNReal.coe_le_coe.2 <| (ciInf_le (OrderBot.bddBelow _) []).trans_eq <| by simp
-#align pseudo_metric_space.dist_of_prenndist_le PseudoMetricSpace.dist_ofPrenndist_le
+#align pseudo_metric_space.dist_of_prenndist_le PseudoMetricSpace.dist_ofPreNNDist_le
 
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
@@ -117,13 +120,13 @@ theorem dist_ofPrenndist_le (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x
 `pseudo_metric_space.of_prenndist`. Suppose that `d` satisfies the following triangle-like
 inequality: `d x₁ x₄ ≤ 2 * max (d x₁ x₂, d x₂ x₃, d x₃ x₄)`. Then `d x y ≤ 2 * dist x y` for all
 `x`, `y`. -/
-theorem le_two_mul_dist_ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0)
+theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0)
     (dist_comm : ∀ x y, d x y = d y x)
     (hd : ∀ x₁ x₂ x₃ x₄, d x₁ x₄ ≤ 2 * max (d x₁ x₂) (max (d x₂ x₃) (d x₃ x₄))) (x y : X) :
     ↑(d x y) ≤
       2 *
         @dist X
-          (@PseudoMetricSpace.toHasDist X (PseudoMetricSpace.ofPrenndist d dist_self dist_comm)) x
+          (@PseudoMetricSpace.toHasDist X (PseudoMetricSpace.ofPreNNDist d dist_self dist_comm)) x
           y :=
   by
   /- We need to show that `d x y` is at most twice the sum `L` of `d xᵢ xᵢ₊₁` over a path
@@ -190,10 +193,11 @@ theorem le_two_mul_dist_ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x
       sum_take_add_sum_drop, ← two_mul] at hMs'
     convert hMs'
     rwa [zip_with_distrib_drop, drop, drop_append_of_le_length]
-#align pseudo_metric_space.le_two_mul_dist_of_prenndist PseudoMetricSpace.le_two_mul_dist_ofPrenndist
+#align pseudo_metric_space.le_two_mul_dist_of_prenndist PseudoMetricSpace.le_two_mul_dist_ofPreNNDist
 
 end PseudoMetricSpace
 
+#print UniformSpace.metrizable_uniformity /-
 /-- If `X` is a uniform space with countably generated uniformity filter, there exists a
 `pseudo_metric_space` structure compatible with the `uniform_space` structure. Use
 `uniform_space.pseudo_metric_space` or `uniform_space.metric_space` instead. -/
@@ -232,8 +236,8 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
       intro x y; dsimp only [d]
       simp only [@SymmetricRel.mk_mem_comm _ _ (hU_symm _) x y]
     have hr : (1 / 2 : ℝ≥0) ∈ Ioo (0 : ℝ≥0) 1 := ⟨half_pos one_pos, NNReal.half_lt_self one_ne_zero⟩
-    letI I := PseudoMetricSpace.ofPrenndist d (fun x => hd₀.2 (Setoid.refl _)) hd_symm
-    have hdist_le : ∀ x y, dist x y ≤ d x y := PseudoMetricSpace.dist_ofPrenndist_le _ _ _
+    letI I := PseudoMetricSpace.ofPreNNDist d (fun x => hd₀.2 (Setoid.refl _)) hd_symm
+    have hdist_le : ∀ x y, dist x y ≤ d x y := PseudoMetricSpace.dist_ofPreNNDist_le _ _ _
     have hle_d : ∀ {x y : X} {n : ℕ}, (1 / 2) ^ n ≤ d x y ↔ (x, y) ∉ U n :=
       by
       intro x y n
@@ -244,7 +248,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
         simp only [h, not_true, (pow_pos hr.1 _).not_le]
     have hd_le : ∀ x y, ↑(d x y) ≤ 2 * dist x y :=
       by
-      refine' PseudoMetricSpace.le_two_mul_dist_ofPrenndist _ _ _ fun x₁ x₂ x₃ x₄ => _
+      refine' PseudoMetricSpace.le_two_mul_dist_ofPreNNDist _ _ _ fun x₁ x₂ x₃ x₄ => _
       by_cases H : ∃ n, (x₁, x₄) ∉ U n
       · refine' (dif_pos H).trans_le _
         rw [← NNReal.div_le_iff' two_ne_zero, ← mul_one_div (_ ^ _), ← pow_succ']
@@ -264,29 +268,38 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
         mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel _ (two_ne_zero' ℝ≥0), hle_d,
         Prod.mk.eta]
 #align uniform_space.metrizable_uniformity UniformSpace.metrizable_uniformity
+-/
 
+#print UniformSpace.pseudoMetricSpace /-
 /-- A `pseudo_metric_space` instance compatible with a given `uniform_space` structure. -/
 protected noncomputable def UniformSpace.pseudoMetricSpace (X : Type _) [UniformSpace X]
     [IsCountablyGenerated (𝓤 X)] : PseudoMetricSpace X :=
   (UniformSpace.metrizable_uniformity X).some.replaceUniformity <|
     congr_arg _ (UniformSpace.metrizable_uniformity X).choose_spec.symm
 #align uniform_space.pseudo_metric_space UniformSpace.pseudoMetricSpace
+-/
 
+#print UniformSpace.metricSpace /-
 /-- A `metric_space` instance compatible with a given `uniform_space` structure. -/
 protected noncomputable def UniformSpace.metricSpace (X : Type _) [UniformSpace X]
     [IsCountablyGenerated (𝓤 X)] [T0Space X] : MetricSpace X :=
   @MetricSpace.ofT0PseudoMetricSpace X (UniformSpace.pseudoMetricSpace X) _
 #align uniform_space.metric_space UniformSpace.metricSpace
+-/
 
+#print UniformSpace.pseudoMetrizableSpace /-
 /-- A uniform space with countably generated `𝓤 X` is pseudo metrizable. -/
 instance (priority := 100) UniformSpace.pseudoMetrizableSpace [UniformSpace X]
     [IsCountablyGenerated (𝓤 X)] : TopologicalSpace.PseudoMetrizableSpace X := by
   letI := UniformSpace.pseudoMetricSpace X; infer_instance
 #align uniform_space.pseudo_metrizable_space UniformSpace.pseudoMetrizableSpace
+-/
 
+#print UniformSpace.metrizableSpace /-
 /-- A T₀ uniform space with countably generated `𝓤 X` is metrizable. This is not an instance to
 avoid loops. -/
 theorem UniformSpace.metrizableSpace [UniformSpace X] [IsCountablyGenerated (𝓤 X)] [T0Space X] :
     TopologicalSpace.MetrizableSpace X := by letI := UniformSpace.metricSpace X; infer_instance
 #align uniform_space.metrizable_space UniformSpace.metrizableSpace
+-/
 
Diff
@@ -48,7 +48,7 @@ metrizable space, uniform space
 
 open Set Function Metric List Filter
 
-open NNReal Filter uniformity
+open scoped NNReal Filter uniformity
 
 variable {X : Type _}
 
Diff
@@ -140,12 +140,10 @@ theorem le_two_mul_dist_ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x
     simpa only [*, max_eq_right, MulZeroClass.mul_zero] using hd a b c c
   haveI : IsTrans X fun x y => d x y = 0 := ⟨hd₀_trans⟩
   induction' hn : length l using Nat.strong_induction_on with n ihn generalizing x y l
-  simp only at ihn
-  subst n
+  simp only at ihn; subst n
   set L := zip_with d (x::l) (l ++ [y])
   have hL_len : length L = length l + 1 := by simp
-  cases' eq_or_ne (d x y) 0 with hd₀ hd₀
-  · simp only [hd₀, zero_le]
+  cases' eq_or_ne (d x y) 0 with hd₀ hd₀; · simp only [hd₀, zero_le]
   rsuffices ⟨z, z', hxz, hzz', hz'y⟩ : ∃ z z' : X, d x z ≤ L.sum ∧ d z z' ≤ L.sum ∧ d z' y ≤ L.sum
   · exact (hd x z z' y).trans (mul_le_mul_left' (max_le hxz (max_le hzz' hz'y)) _)
   set s : Set ℕ := { m : ℕ | 2 * (take m L).Sum ≤ L.sum }
@@ -168,8 +166,7 @@ theorem le_two_mul_dist_ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x
   have hM_ltx : M < length (x::l) := lt_length_left_of_zip_with hM_lt
   have hM_lty : M < length (l ++ [y]) := lt_length_right_of_zip_with hM_lt
   refine' ⟨(x::l).nthLe M hM_ltx, (l ++ [y]).nthLe M hM_lty, _, _, _⟩
-  · cases M
-    · simp [dist_self]
+  · cases M; · simp [dist_self]
     rw [Nat.succ_le_iff] at hMl
     have hMl' : length (take M l) = M := (length_take _ _).trans (min_eq_left hMl.le)
     simp only [nth_le]
@@ -225,17 +222,14 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
     letI := UniformSpace.separationSetoid X
     set d : X → X → ℝ≥0 := fun x y => if h : ∃ n, (x, y) ∉ U n then (1 / 2) ^ Nat.find h else 0
     have hd₀ : ∀ {x y}, d x y = 0 ↔ x ≈ y := by
-      intro x y
-      dsimp only [d]
+      intro x y; dsimp only [d]
       refine' Iff.trans _ hB.to_has_basis.mem_separation_rel.symm
       simp only [true_imp_iff]
       split_ifs with h
-      · rw [← not_forall] at h
-        simp [h, pow_eq_zero_iff']
+      · rw [← not_forall] at h; simp [h, pow_eq_zero_iff']
       · simpa only [not_exists, Classical.not_not, eq_self_iff_true, true_iff_iff] using h
     have hd_symm : ∀ x y, d x y = d y x := by
-      intro x y
-      dsimp only [d]
+      intro x y; dsimp only [d]
       simp only [@SymmetricRel.mk_mem_comm _ _ (hU_symm _) x y]
     have hr : (1 / 2 : ℝ≥0) ∈ Ioo (0 : ℝ≥0) 1 := ⟨half_pos one_pos, NNReal.half_lt_self one_ne_zero⟩
     letI I := PseudoMetricSpace.ofPrenndist d (fun x => hd₀.2 (Setoid.refl _)) hd_symm
@@ -243,8 +237,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
     have hle_d : ∀ {x y : X} {n : ℕ}, (1 / 2) ^ n ≤ d x y ↔ (x, y) ∉ U n :=
       by
       intro x y n
-      simp only [d]
-      split_ifs with h
+      simp only [d]; split_ifs with h
       · rw [(strictAnti_pow hr.1 hr.2).le_iff_le, Nat.find_le_iff]
         exact ⟨fun ⟨m, hmn, hm⟩ hn => hm (hB.antitone hmn hn), fun h => ⟨n, le_rfl, h⟩⟩
       · push_neg  at h
@@ -287,18 +280,13 @@ protected noncomputable def UniformSpace.metricSpace (X : Type _) [UniformSpace
 
 /-- A uniform space with countably generated `𝓤 X` is pseudo metrizable. -/
 instance (priority := 100) UniformSpace.pseudoMetrizableSpace [UniformSpace X]
-    [IsCountablyGenerated (𝓤 X)] : TopologicalSpace.PseudoMetrizableSpace X :=
-  by
-  letI := UniformSpace.pseudoMetricSpace X
-  infer_instance
+    [IsCountablyGenerated (𝓤 X)] : TopologicalSpace.PseudoMetrizableSpace X := by
+  letI := UniformSpace.pseudoMetricSpace X; infer_instance
 #align uniform_space.pseudo_metrizable_space UniformSpace.pseudoMetrizableSpace
 
 /-- A T₀ uniform space with countably generated `𝓤 X` is metrizable. This is not an instance to
 avoid loops. -/
 theorem UniformSpace.metrizableSpace [UniformSpace X] [IsCountablyGenerated (𝓤 X)] [T0Space X] :
-    TopologicalSpace.MetrizableSpace X :=
-  by
-  letI := UniformSpace.metricSpace X
-  infer_instance
+    TopologicalSpace.MetrizableSpace X := by letI := UniformSpace.metricSpace X; infer_instance
 #align uniform_space.metrizable_space UniformSpace.metrizableSpace
 
Diff
@@ -160,7 +160,7 @@ theorem le_two_mul_dist_ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x
       rw [mem_set_of_eq, take_all_of_le hLm, two_mul, add_le_iff_nonpos_left, nonpos_iff_eq_zero,
           sum_eq_zero_iff, ← all₂_iff_forall, all₂_zip_with, ←
           chain_append_singleton_iff_forall₂] at hm <;>
-        [skip, · simp]
+        [skip;· simp]
       exact hd₀ (hm.rel (mem_append.2 <| Or.inr <| mem_singleton_self _))
     have hs_bdd : BddAbove s := ⟨length l, hs_ub⟩
     exact ⟨Sup s, csSup_le hsne hs_ub, ⟨Nat.sSup_mem hsne hs_bdd, fun k => le_csSup hs_bdd⟩⟩
Diff
@@ -70,7 +70,7 @@ noncomputable def ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x
   dist x y := ↑(⨅ l : List X, ((x::l).zipWith d (l ++ [y])).Sum : ℝ≥0)
   dist_self x :=
     (NNReal.coe_eq_zero _).2 <|
-      nonpos_iff_eq_zero.1 <| (cinfᵢ_le (OrderBot.bddBelow _) []).trans_eq <| by simp [dist_self]
+      nonpos_iff_eq_zero.1 <| (ciInf_le (OrderBot.bddBelow _) []).trans_eq <| by simp [dist_self]
   dist_comm x y :=
     NNReal.coe_eq.2 <| by
       refine' reverse_surjective.infi_congr _ fun l => _
@@ -80,11 +80,11 @@ noncomputable def ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x
       simp only [length, length_append]
   dist_triangle x y z := by
     rw [← NNReal.coe_add, NNReal.coe_le_coe]
-    refine' NNReal.le_infᵢ_add_infᵢ fun lxy lyz => _
+    refine' NNReal.le_iInf_add_iInf fun lxy lyz => _
     calc
       (⨅ l, (zip_with d (x::l) (l ++ [z])).Sum) ≤
           (zip_with d (x::lxy ++ y::lyz) ((lxy ++ y::lyz) ++ [z])).Sum :=
-        cinfᵢ_le (OrderBot.bddBelow _) (lxy ++ y::lyz)
+        ciInf_le (OrderBot.bddBelow _) (lxy ++ y::lyz)
       _ = (zip_with d (x::lxy) (lxy ++ [y])).Sum + (zip_with d (y::lyz) (lyz ++ [z])).Sum := _
       
     rw [← sum_append, ← zip_with_append, cons_append, ← @singleton_append _ y, append_assoc,
@@ -106,7 +106,7 @@ theorem dist_ofPrenndist_le (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x
     @dist X (@PseudoMetricSpace.toHasDist X (PseudoMetricSpace.ofPrenndist d dist_self dist_comm)) x
         y ≤
       d x y :=
-  NNReal.coe_le_coe.2 <| (cinfᵢ_le (OrderBot.bddBelow _) []).trans_eq <| by simp
+  NNReal.coe_le_coe.2 <| (ciInf_le (OrderBot.bddBelow _) []).trans_eq <| by simp
 #align pseudo_metric_space.dist_of_prenndist_le PseudoMetricSpace.dist_ofPrenndist_le
 
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
@@ -131,8 +131,8 @@ theorem le_two_mul_dist_ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x
     splits the path into two parts of almost equal length: both `d x₀ x₁ + ... + d xₖ₋₁ xₖ` and
     `d xₖ₊₁ xₖ₊₂ + ... + d xₙ₋₁ xₙ` are less than or equal to `L / 2`.
     Then `d x₀ xₖ ≤ L`, `d xₖ xₖ₊₁ ≤ L`, and `d xₖ₊₁ xₙ ≤ L`, thus `d x₀ xₙ ≤ 2 * L`. -/
-  rw [dist_of_prenndist, ← NNReal.coe_two, ← NNReal.coe_mul, NNReal.mul_infᵢ, NNReal.coe_le_coe]
-  refine' le_cinfᵢ fun l => _
+  rw [dist_of_prenndist, ← NNReal.coe_two, ← NNReal.coe_mul, NNReal.mul_iInf, NNReal.coe_le_coe]
+  refine' le_ciInf fun l => _
   have hd₀_trans : Transitive fun x y => d x y = 0 :=
     by
     intro a b c hab hbc
@@ -163,7 +163,7 @@ theorem le_two_mul_dist_ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x
         [skip, · simp]
       exact hd₀ (hm.rel (mem_append.2 <| Or.inr <| mem_singleton_self _))
     have hs_bdd : BddAbove s := ⟨length l, hs_ub⟩
-    exact ⟨Sup s, csupₛ_le hsne hs_ub, ⟨Nat.supₛ_mem hsne hs_bdd, fun k => le_csupₛ hs_bdd⟩⟩
+    exact ⟨Sup s, csSup_le hsne hs_ub, ⟨Nat.sSup_mem hsne hs_bdd, fun k => le_csSup hs_bdd⟩⟩
   have hM_lt : M < length L := by rwa [hL_len, Nat.lt_succ_iff]
   have hM_ltx : M < length (x::l) := lt_length_left_of_zip_with hM_lt
   have hM_lty : M < length (l ++ [y]) := lt_length_right_of_zip_with hM_lt
Diff
@@ -137,7 +137,7 @@ theorem le_two_mul_dist_ofPrenndist (d : X → X → ℝ≥0) (dist_self : ∀ x
     by
     intro a b c hab hbc
     rw [← nonpos_iff_eq_zero]
-    simpa only [*, max_eq_right, mul_zero] using hd a b c c
+    simpa only [*, max_eq_right, MulZeroClass.mul_zero] using hd a b c c
   haveI : IsTrans X fun x y => d x y = 0 := ⟨hd₀_trans⟩
   induction' hn : length l using Nat.strong_induction_on with n ihn generalizing x y l
   simp only at ihn
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yury Kudryashov
 
 ! This file was ported from Lean 3 source module topology.metric_space.metrizable_uniformity
-! leanprover-community/mathlib commit b2ff9a3d7a15fd5b0f060b135421d6a89a999c2f
+! leanprover-community/mathlib commit 195fcd60ff2bfe392543bceb0ec2adcdb472db4c
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -282,7 +282,7 @@ protected noncomputable def UniformSpace.pseudoMetricSpace (X : Type _) [Uniform
 /-- A `metric_space` instance compatible with a given `uniform_space` structure. -/
 protected noncomputable def UniformSpace.metricSpace (X : Type _) [UniformSpace X]
     [IsCountablyGenerated (𝓤 X)] [T0Space X] : MetricSpace X :=
-  @ofT0PseudoMetricSpace X (UniformSpace.pseudoMetricSpace X) _
+  @MetricSpace.ofT0PseudoMetricSpace X (UniformSpace.pseudoMetricSpace X) _
 #align uniform_space.metric_space UniformSpace.metricSpace
 
 /-- A uniform space with countably generated `𝓤 X` is pseudo metrizable. -/
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yury Kudryashov
 
 ! This file was ported from Lean 3 source module topology.metric_space.metrizable_uniformity
-! leanprover-community/mathlib commit 9b2660e1b25419042c8da10bf411aa3c67f14383
+! leanprover-community/mathlib commit b2ff9a3d7a15fd5b0f060b135421d6a89a999c2f
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -237,8 +237,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
       intro x y
       dsimp only [d]
       simp only [@SymmetricRel.mk_mem_comm _ _ (hU_symm _) x y]
-    have hr : (1 / 2 : ℝ≥0) ∈ Ioo (0 : ℝ≥0) 1 :=
-      ⟨NNReal.half_pos one_pos, NNReal.half_lt_self one_ne_zero⟩
+    have hr : (1 / 2 : ℝ≥0) ∈ Ioo (0 : ℝ≥0) 1 := ⟨half_pos one_pos, NNReal.half_lt_self one_ne_zero⟩
     letI I := PseudoMetricSpace.ofPrenndist d (fun x => hd₀.2 (Setoid.refl _)) hd_symm
     have hdist_le : ∀ x y, dist x y ≤ d x y := PseudoMetricSpace.dist_ofPrenndist_le _ _ _
     have hle_d : ∀ {x y : X} {n : ℕ}, (1 / 2) ^ n ≤ d x y ↔ (x, y) ∉ U n :=

Changes in mathlib4

mathlib3
mathlib4
feat(UniformSpace) : TotallyBounded + countably generated -> Separable (#12404)

Just a small result, that TotallyBounded sets are Separable sets in Uniform spaces with countably generated uniformities.

Diff
@@ -279,3 +279,18 @@ theorem UniformSpace.metrizableSpace [UniformSpace X] [IsCountablyGenerated (
   letI := UniformSpace.metricSpace X
   infer_instance
 #align uniform_space.metrizable_space UniformSpace.metrizableSpace
+
+/-- A totally bounded set is separable in countably generated uniform spaces. This can be obtained
+from the more general `EMetric.subset_countable_closure_of_almost_dense_set`.-/
+lemma TotallyBounded.isSeparable [UniformSpace X] [i : IsCountablyGenerated (𝓤 X)]
+    {s : Set X} (h : TotallyBounded s) : TopologicalSpace.IsSeparable s:= by
+  letI := (UniformSpace.pseudoMetricSpace (X := X)).toPseudoEMetricSpace
+  rw [EMetric.totallyBounded_iff] at h
+  have h' : ∀ ε > 0, ∃ t, Set.Countable t ∧ s ⊆ ⋃ y ∈ t, EMetric.closedBall y ε := by
+    intro ε hε
+    obtain ⟨t, ht⟩ := h ε hε
+    refine ⟨t, ht.1.countable, subset_trans ht.2 ?_⟩
+    gcongr
+    exact EMetric.ball_subset_closedBall
+  obtain ⟨t, _, htc, hts⟩ := EMetric.subset_countable_closure_of_almost_dense_set s h'
+  exact ⟨t, htc, hts⟩
change the order of operation in zsmulRec and nsmulRec (#11451)

We change the following field in the definition of an additive commutative monoid:

 nsmul_succ : ∀ (n : ℕ) (x : G),
-  AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
+  AddMonoid.nsmul (n + 1) x = AddMonoid.nsmul n x + x

where the latter is more natural

We adjust the definitions of ^ in monoids, groups, etc. Originally there was a warning comment about why this natural order was preferred

use x * npowRec n x and not npowRec n x * x in the definition to make sure that definitional unfolding of npowRec is blocked, to avoid deep recursion issues.

but it seems to no longer apply.

Remarks on the PR :

  • pow_succ and pow_succ' have switched their meanings.
  • Most of the time, the proofs were adjusted by priming/unpriming one lemma, or exchanging left and right; a few proofs were more complicated to adjust.
  • In particular, [Mathlib/NumberTheory/RamificationInertia.lean] used Ideal.IsPrime.mul_mem_pow which is defined in [Mathlib/RingTheory/DedekindDomain/Ideal.lean]. Changing the order of operation forced me to add the symmetric lemma Ideal.IsPrime.mem_pow_mul.
  • the docstring for Cauchy condensation test in [Mathlib/Analysis/PSeries.lean] was mathematically incorrect, I added the mention that the function is antitone.
Diff
@@ -232,7 +232,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type*) [UniformSpace X
     refine' PseudoMetricSpace.le_two_mul_dist_ofPreNNDist _ _ _ fun x₁ x₂ x₃ x₄ => _
     by_cases H : ∃ n, (x₁, x₄) ∉ U n
     · refine' (dif_pos H).trans_le _
-      rw [← NNReal.div_le_iff' two_ne_zero, ← mul_one_div (_ ^ _), ← pow_succ']
+      rw [← NNReal.div_le_iff' two_ne_zero, ← mul_one_div (_ ^ _), ← pow_succ]
       simp only [le_max_iff, hle_d, ← not_and_or]
       rintro ⟨h₁₂, h₂₃, h₃₄⟩
       refine' Nat.find_spec H (hU_comp (lt_add_one <| Nat.find H) _)
@@ -248,7 +248,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type*) [UniformSpace X
     rw [mem_setOf_eq] at hx
     contrapose! hx
     refine' le_trans _ ((div_le_iff' (zero_lt_two' ℝ)).2 (hd_le x.1 x.2))
-    rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ',
+    rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ,
       mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel₀ _ (two_ne_zero' ℝ≥0), hle_d]
 #align uniform_space.metrizable_uniformity UniformSpace.metrizable_uniformity
 
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
@@ -249,7 +249,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type*) [UniformSpace X
     contrapose! hx
     refine' le_trans _ ((div_le_iff' (zero_lt_two' ℝ)).2 (hd_le x.1 x.2))
     rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ',
-      mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel _ (two_ne_zero' ℝ≥0), hle_d]
+      mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel₀ _ (two_ne_zero' ℝ≥0), hle_d]
 #align uniform_space.metrizable_uniformity UniformSpace.metrizable_uniformity
 
 /-- A `PseudoMetricSpace` instance compatible with a given `UniformSpace` structure. -/
refactor(UniformSpace): drop separationRel (#10644)

We had duplicated API between topological spaces and uniform spaces. In this PR I mostly deduplicate it with some exceptions:

  • SeparationQuotient.lift' and SeparationQuotient.map are leftovers from the old version that are designed to work with uniform spaces;
  • probably, some theorems/instances still assume UniformSpace when TopologicalSpace would work.

Outside of UniformSpace/Separation, I mostly changed SeparatedSpace to T0Space and separationRel to Inseparable. I also rewrote a few proofs that were broken by the API change.

Fixes #2031

Diff
@@ -205,11 +205,10 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type*) [UniformSpace X
           (eventually_uniformity_iterate_comp_subset (hB.mem m) 2) with
       ⟨φ, -, hφ_comp, hφB⟩
     exact ⟨V ∘ φ, fun n => hV_symm _, hφ_comp, hφB⟩
-  letI := UniformSpace.separationSetoid X
   set d : X → X → ℝ≥0 := fun x y => if h : ∃ n, (x, y) ∉ U n then (1 / 2) ^ Nat.find h else 0
-  have hd₀ : ∀ {x y}, d x y = 0 ↔ x ≈ y := by
+  have hd₀ : ∀ {x y}, d x y = 0 ↔ Inseparable x y := by
     intro x y
-    refine' Iff.trans _ hB.mem_separationRel.symm
+    refine' Iff.trans _ hB.inseparable_iff_uniformity.symm
     simp only [d, true_imp_iff]
     split_ifs with h
     · rw [← not_forall] at h
@@ -219,7 +218,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type*) [UniformSpace X
     intro x y
     simp only [d, @SymmetricRel.mk_mem_comm _ _ (hU_symm _) x y]
   have hr : (1 / 2 : ℝ≥0) ∈ Ioo (0 : ℝ≥0) 1 := ⟨half_pos one_pos, NNReal.half_lt_self one_ne_zero⟩
-  letI I := PseudoMetricSpace.ofPreNNDist d (fun x => hd₀.2 (Setoid.refl _)) hd_symm
+  letI I := PseudoMetricSpace.ofPreNNDist d (fun x => hd₀.2 rfl) hd_symm
   have hdist_le : ∀ x y, dist x y ≤ d x y := PseudoMetricSpace.dist_ofPreNNDist_le _ _ _
   have hle_d : ∀ {x y : X} {n : ℕ}, (1 / 2) ^ n ≤ d x y ↔ (x, y) ∉ U n := by
     intro x y n
chore: move Mathlib to v4.7.0-rc1 (#11162)

This is a very large PR, but it has been reviewed piecemeal already in PRs to the bump/v4.7.0 branch as we update to intermediate nightlies.

Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Kyle Miller <kmill31415@gmail.com> Co-authored-by: damiano <adomani@gmail.com>

Diff
@@ -126,13 +126,13 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
   simp only at ihn
   subst n
   set L := zipWith d (x::l) (l ++ [y])
-  have hL_len : length L = length l + 1 := by simp
+  have hL_len : length L = length l + 1 := by simp [L]
   rcases eq_or_ne (d x y) 0 with hd₀ | hd₀
   · simp only [hd₀, zero_le]
   rsuffices ⟨z, z', hxz, hzz', hz'y⟩ : ∃ z z' : X, d x z ≤ L.sum ∧ d z z' ≤ L.sum ∧ d z' y ≤ L.sum
   · exact (hd x z z' y).trans (mul_le_mul_left' (max_le hxz (max_le hzz' hz'y)) _)
   set s : Set ℕ := { m : ℕ | 2 * (take m L).sum ≤ L.sum }
-  have hs₀ : 0 ∈ s := by simp
+  have hs₀ : 0 ∈ s := by simp [s]
   have hsne : s.Nonempty := ⟨0, hs₀⟩
   obtain ⟨M, hMl, hMs⟩ : ∃ M ≤ length l, IsGreatest s M := by
     have hs_ub : length l ∈ upperBounds s := by
@@ -161,7 +161,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
       refine' (ihn _ hMl _ _ _ hMl').trans _
       convert hMs.1.out
       rw [zipWith_distrib_take, take, take_succ, get?_append hMl, get?_eq_get hMl, ← Option.coe_def,
-        Option.to_list_some, take_append_of_le_length hMl.le]
+        Option.toList_some, take_append_of_le_length hMl.le]
   · exact single_le_sum (fun x _ => zero_le x) _ (mem_iff_get.2 ⟨⟨M, hM_lt⟩, get_zipWith⟩)
   · rcases hMl.eq_or_lt with (rfl | hMl)
     · simp only [get_append_right' le_rfl, sub_self, get_singleton, dist_self, zero_le]
@@ -210,20 +210,20 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type*) [UniformSpace X
   have hd₀ : ∀ {x y}, d x y = 0 ↔ x ≈ y := by
     intro x y
     refine' Iff.trans _ hB.mem_separationRel.symm
-    simp only [true_imp_iff]
+    simp only [d, true_imp_iff]
     split_ifs with h
     · rw [← not_forall] at h
       simp [h, pow_eq_zero_iff']
     · simpa only [not_exists, Classical.not_not, eq_self_iff_true, true_iff_iff] using h
   have hd_symm : ∀ x y, d x y = d y x := by
     intro x y
-    simp only [@SymmetricRel.mk_mem_comm _ _ (hU_symm _) x y]
+    simp only [d, @SymmetricRel.mk_mem_comm _ _ (hU_symm _) x y]
   have hr : (1 / 2 : ℝ≥0) ∈ Ioo (0 : ℝ≥0) 1 := ⟨half_pos one_pos, NNReal.half_lt_self one_ne_zero⟩
   letI I := PseudoMetricSpace.ofPreNNDist d (fun x => hd₀.2 (Setoid.refl _)) hd_symm
   have hdist_le : ∀ x y, dist x y ≤ d x y := PseudoMetricSpace.dist_ofPreNNDist_le _ _ _
   have hle_d : ∀ {x y : X} {n : ℕ}, (1 / 2) ^ n ≤ d x y ↔ (x, y) ∉ U n := by
     intro x y n
-    dsimp only []
+    dsimp only [d]
     split_ifs with h
     · rw [(pow_right_strictAnti hr.1 hr.2).le_iff_le, Nat.find_le_iff]
       exact ⟨fun ⟨m, hmn, hm⟩ hn => hm (hB.antitone hmn hn), fun h => ⟨n, le_rfl, h⟩⟩
chore: classify slow / slower porting notes (#11084)

Classifies by adding issue number #11083 to porting notes claiming anything semantically equivalent to:

  • "very slow; improve performance?"
  • "quite slow; improve performance?"
  • "`tactic" was slow"
  • "removed attribute because it caused extremely slow tactic"
  • "proof was rewritten, because it was too slow"
  • "doing this make things very slow"
  • "slower implementation"
Diff
@@ -180,7 +180,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
 
 end PseudoMetricSpace
 
--- Porting note: this is slower than in Lean3 for some reason...
+-- Porting note (#11083): this is slower than in Lean3 for some reason...
 /-- If `X` is a uniform space with countably generated uniformity filter, there exists a
 `PseudoMetricSpace` structure compatible with the `UniformSpace` structure. Use
 `UniformSpace.pseudoMetricSpace` or `UniformSpace.metricSpace` instead. -/
feat: Complete NNReal coercion lemmas (#10214)

Add a few missing lemmas about the coercion NNReal → Real. Remove a bunch of protected on the existing coercion lemmas (so that it matches the convention for other coercions). Rename NNReal.coe_eq to NNReal.coe_inj

From LeanAPAP

Diff
@@ -58,11 +58,10 @@ where `d : X → X → ℝ≥0` is a function such that `d x x = 0` and `d x y =
 noncomputable def ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0)
     (dist_comm : ∀ x y, d x y = d y x) : PseudoMetricSpace X where
   dist x y := ↑(⨅ l : List X, ((x::l).zipWith d (l ++ [y])).sum : ℝ≥0)
-  dist_self x :=
-    (NNReal.coe_eq_zero _).2 <|
+  dist_self x := NNReal.coe_eq_zero.2 <|
       nonpos_iff_eq_zero.1 <| (ciInf_le (OrderBot.bddBelow _) []).trans_eq <| by simp [dist_self]
   dist_comm x y :=
-    NNReal.coe_eq.2 <| by
+    NNReal.coe_inj.2 <| by
       refine' reverse_surjective.iInf_congr _ fun l => _
       rw [← sum_reverse, zipWith_distrib_reverse, reverse_append, reverse_reverse,
         reverse_singleton, singleton_append, reverse_cons, reverse_reverse,
chore: remove uses of cases' (#9171)

I literally went through and regex'd some uses of cases', replacing them with rcases; this is meant to be a low effort PR as I hope that tools can do this in the future.

rcases is an easier replacement than cases, though with better tools we could in future do a second pass converting simple rcases added here (and existing ones) to cases.

Diff
@@ -128,7 +128,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
   subst n
   set L := zipWith d (x::l) (l ++ [y])
   have hL_len : length L = length l + 1 := by simp
-  cases' eq_or_ne (d x y) 0 with hd₀ hd₀
+  rcases eq_or_ne (d x y) 0 with hd₀ | hd₀
   · simp only [hd₀, zero_le]
   rsuffices ⟨z, z', hxz, hzz', hz'y⟩ : ∃ z z' : X, d x z ≤ L.sum ∧ d z z' ≤ L.sum ∧ d z' y ≤ L.sum
   · exact (hd x z z' y).trans (mul_le_mul_left' (max_le hxz (max_le hzz' hz'y)) _)
chore: Rename pow monotonicity lemmas (#9095)

The names for lemmas about monotonicity of (a ^ ·) and (· ^ n) were a mess. This PR tidies up everything related by following the naming convention for (a * ·) and (· * b). Namely, (a ^ ·) is pow_right and (· ^ n) is pow_left in lemma names. All lemma renames follow the corresponding multiplication lemma names closely.

Renames

Algebra.GroupPower.Order

  • pow_monopow_right_mono
  • pow_le_powpow_le_pow_right
  • pow_le_pow_of_le_leftpow_le_pow_left
  • pow_lt_pow_of_lt_leftpow_lt_pow_left
  • strictMonoOn_powpow_left_strictMonoOn
  • pow_strictMono_rightpow_right_strictMono
  • pow_lt_powpow_lt_pow_right
  • pow_lt_pow_iffpow_lt_pow_iff_right
  • pow_le_pow_iffpow_le_pow_iff_right
  • self_lt_powlt_self_pow
  • strictAnti_powpow_right_strictAnti
  • pow_lt_pow_iff_of_lt_onepow_lt_pow_iff_right_of_lt_one
  • pow_lt_pow_of_lt_onepow_lt_pow_right_of_lt_one
  • lt_of_pow_lt_powlt_of_pow_lt_pow_left
  • le_of_pow_le_powle_of_pow_le_pow_left
  • pow_lt_pow₀pow_lt_pow_right₀

Algebra.GroupPower.CovariantClass

  • pow_le_pow_of_le_left'pow_le_pow_left'
  • nsmul_le_nsmul_of_le_rightnsmul_le_nsmul_right
  • pow_lt_pow'pow_lt_pow_right'
  • nsmul_lt_nsmulnsmul_lt_nsmul_left
  • pow_strictMono_leftpow_right_strictMono'
  • nsmul_strictMono_rightnsmul_left_strictMono
  • StrictMono.pow_right'StrictMono.pow_const
  • StrictMono.nsmul_leftStrictMono.const_nsmul
  • pow_strictMono_right'pow_left_strictMono
  • nsmul_strictMono_leftnsmul_right_strictMono
  • Monotone.pow_rightMonotone.pow_const
  • Monotone.nsmul_leftMonotone.const_nsmul
  • lt_of_pow_lt_pow'lt_of_pow_lt_pow_left'
  • lt_of_nsmul_lt_nsmullt_of_nsmul_lt_nsmul_right
  • pow_le_pow'pow_le_pow_right'
  • nsmul_le_nsmulnsmul_le_nsmul_left
  • pow_le_pow_of_le_one'pow_le_pow_right_of_le_one'
  • nsmul_le_nsmul_of_nonposnsmul_le_nsmul_left_of_nonpos
  • le_of_pow_le_pow'le_of_pow_le_pow_left'
  • le_of_nsmul_le_nsmul'le_of_nsmul_le_nsmul_right'
  • pow_le_pow_iff'pow_le_pow_iff_right'
  • nsmul_le_nsmul_iffnsmul_le_nsmul_iff_left
  • pow_lt_pow_iff'pow_lt_pow_iff_right'
  • nsmul_lt_nsmul_iffnsmul_lt_nsmul_iff_left

Data.Nat.Pow

  • Nat.pow_lt_pow_of_lt_leftNat.pow_lt_pow_left
  • Nat.pow_le_iff_le_leftNat.pow_le_pow_iff_left
  • Nat.pow_lt_iff_lt_leftNat.pow_lt_pow_iff_left

Lemmas added

  • pow_le_pow_iff_left
  • pow_lt_pow_iff_left
  • pow_right_injective
  • pow_right_inj
  • Nat.pow_le_pow_left to have the correct name since Nat.pow_le_pow_of_le_left is in Std.
  • Nat.pow_le_pow_right to have the correct name since Nat.pow_le_pow_of_le_right is in Std.

Lemmas removed

  • self_le_pow was a duplicate of le_self_pow.
  • Nat.pow_lt_pow_of_lt_right is defeq to pow_lt_pow_right.
  • Nat.pow_right_strictMono is defeq to pow_right_strictMono.
  • Nat.pow_le_iff_le_right is defeq to pow_le_pow_iff_right.
  • Nat.pow_lt_iff_lt_right is defeq to pow_lt_pow_iff_right.

Other changes

  • A bunch of proofs have been golfed.
  • Some lemma assumptions have been turned from 0 < n or 1 ≤ n to n ≠ 0.
  • A few Nat lemmas have been protected.
  • One docstring has been fixed.
Diff
@@ -226,7 +226,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type*) [UniformSpace X
     intro x y n
     dsimp only []
     split_ifs with h
-    · rw [(strictAnti_pow hr.1 hr.2).le_iff_le, Nat.find_le_iff]
+    · rw [(pow_right_strictAnti hr.1 hr.2).le_iff_le, Nat.find_le_iff]
       exact ⟨fun ⟨m, hmn, hm⟩ hn => hm (hB.antitone hmn hn), fun h => ⟨n, le_rfl, h⟩⟩
     · push_neg at h
       simp only [h, not_true, (pow_pos hr.1 _).not_le]
chore: split Topology.MetricSpace.Metrizable* (#7912)

Move

  • basic definitions to Topology.Metrizable.Basic,
  • Urysohn's metrization theorem to `Topology.Metrizable.Urysohns', and
  • metrizability of a uniform space with countably generated uniformity to Topology.Metrizable.Uniform.

The next step is to redefine Metrizable as "uniformizable with countably generated uniformity" and make this definition available much earlier.

Diff
@@ -3,7 +3,8 @@ Copyright (c) 2022 Yury Kudryashov. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yury Kudryashov
 -/
-import Mathlib.Topology.MetricSpace.Metrizable
+import Mathlib.Topology.Metrizable.Basic
+import Mathlib.Data.Nat.Lattice
 
 #align_import topology.metric_space.metrizable_uniformity from "leanprover-community/mathlib"@"195fcd60ff2bfe392543bceb0ec2adcdb472db4c"
 
refactor: List.All₂ to List.Forall (#7797)

This renames List.All₂ to List.Forall, because the is highly confusing when it usually means “two lists”, and we had users on Zulip not find List.Forall because of that (https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/Is.20there.20List.2EForall.E2.82.82.2C.20but.20for.20one.20list.3F.20.28In.20library.20Std.29/near/397551365)

Co-authored-by: Mario Carneiro <di.gama@gmail.com>

Diff
@@ -140,7 +140,8 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
       rw [← not_lt, Nat.lt_iff_add_one_le, ← hL_len]
       intro hLm
       rw [mem_setOf_eq, take_all_of_le hLm, two_mul, add_le_iff_nonpos_left, nonpos_iff_eq_zero,
-          sum_eq_zero_iff, ← all₂_iff_forall, all₂_zipWith, ← chain_append_singleton_iff_forall₂]
+          sum_eq_zero_iff, ← forall_iff_forall_mem, forall_zipWith,
+          ← chain_append_singleton_iff_forall₂]
           at hm <;>
         [skip; simp]
       exact hd₀ (hm.rel (mem_append.2 <| Or.inr <| mem_singleton_self _))
chore: cleanup Mathlib.Init.Data.Prod (#6972)

Removing from Mathlib.Init.Data.Prod from the early parts of the import hierarchy.

While at it, remove unnecessary uses of Prod.mk.eta across the library.

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

Diff
@@ -243,14 +243,13 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type*) [UniformSpace X
   rw [mem_Ioo, ← NNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at hr
   refine' ⟨I, UniformSpace.ext <| (uniformity_basis_dist_pow hr.1 hr.2).ext hB.toHasBasis _ _⟩
   · refine' fun n hn => ⟨n, hn, fun x hx => (hdist_le _ _).trans_lt _⟩
-    rwa [← NNReal.coe_pow, NNReal.coe_lt_coe, ← not_le, hle_d, Classical.not_not, Prod.mk.eta]
+    rwa [← NNReal.coe_pow, NNReal.coe_lt_coe, ← not_le, hle_d, Classical.not_not]
   · refine' fun n _ => ⟨n + 1, trivial, fun x hx => _⟩
     rw [mem_setOf_eq] at hx
     contrapose! hx
     refine' le_trans _ ((div_le_iff' (zero_lt_two' ℝ)).2 (hd_le x.1 x.2))
     rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ',
-      mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel _ (two_ne_zero' ℝ≥0), hle_d,
-      Prod.mk.eta]
+      mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel _ (two_ne_zero' ℝ≥0), hle_d]
 #align uniform_space.metrizable_uniformity UniformSpace.metrizable_uniformity
 
 /-- A `PseudoMetricSpace` instance compatible with a given `UniformSpace` structure. -/
chore: more predictable ext lemmas for TopologicalSpace and UniformSpace (#6705)
Diff
@@ -241,7 +241,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type*) [UniformSpace X
   -- Porting note: without the next line, `uniformity_basis_dist_pow` ends up introducing some
   -- `Subtype.val` applications instead of `NNReal.toReal`.
   rw [mem_Ioo, ← NNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at hr
-  refine' ⟨I, uniformSpace_eq <| (uniformity_basis_dist_pow hr.1 hr.2).ext hB.toHasBasis _ _⟩
+  refine' ⟨I, UniformSpace.ext <| (uniformity_basis_dist_pow hr.1 hr.2).ext hB.toHasBasis _ _⟩
   · refine' fun n hn => ⟨n, hn, fun x hx => (hdist_le _ _).trans_lt _⟩
     rwa [← NNReal.coe_pow, NNReal.coe_lt_coe, ← not_le, hle_d, Classical.not_not, Prod.mk.eta]
   · refine' fun n _ => ⟨n + 1, trivial, fun x hx => _⟩
chore: banish Type _ and Sort _ (#6499)

We remove all possible occurences of Type _ and Sort _ in favor of Type* and Sort*.

This has nice performance benefits.

Diff
@@ -48,7 +48,7 @@ open Set Function Metric List Filter
 
 open NNReal Filter Uniformity
 
-variable {X : Type _}
+variable {X : Type*}
 
 namespace PseudoMetricSpace
 
@@ -183,7 +183,7 @@ end PseudoMetricSpace
 /-- If `X` is a uniform space with countably generated uniformity filter, there exists a
 `PseudoMetricSpace` structure compatible with the `UniformSpace` structure. Use
 `UniformSpace.pseudoMetricSpace` or `UniformSpace.metricSpace` instead. -/
-protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace X]
+protected theorem UniformSpace.metrizable_uniformity (X : Type*) [UniformSpace X]
     [IsCountablyGenerated (𝓤 X)] : ∃ I : PseudoMetricSpace X, I.toUniformSpace = ‹_› := by
   classical
   /- Choose a fast decreasing antitone basis `U : ℕ → set (X × X)` of the uniformity filter `𝓤 X`.
@@ -254,14 +254,14 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
 #align uniform_space.metrizable_uniformity UniformSpace.metrizable_uniformity
 
 /-- A `PseudoMetricSpace` instance compatible with a given `UniformSpace` structure. -/
-protected noncomputable def UniformSpace.pseudoMetricSpace (X : Type _) [UniformSpace X]
+protected noncomputable def UniformSpace.pseudoMetricSpace (X : Type*) [UniformSpace X]
     [IsCountablyGenerated (𝓤 X)] : PseudoMetricSpace X :=
   (UniformSpace.metrizable_uniformity X).choose.replaceUniformity <|
     congr_arg _ (UniformSpace.metrizable_uniformity X).choose_spec.symm
 #align uniform_space.pseudo_metric_space UniformSpace.pseudoMetricSpace
 
 /-- A `MetricSpace` instance compatible with a given `UniformSpace` structure. -/
-protected noncomputable def UniformSpace.metricSpace (X : Type _) [UniformSpace X]
+protected noncomputable def UniformSpace.metricSpace (X : Type*) [UniformSpace X]
     [IsCountablyGenerated (𝓤 X)] [T0Space X] : MetricSpace X :=
   @MetricSpace.ofT0PseudoMetricSpace X (UniformSpace.pseudoMetricSpace X) _
 #align uniform_space.metric_space UniformSpace.metricSpace
chore: bump to nightly-2023-07-15 (#5992)

Various adaptations to changes when Fin API was moved to Std. One notable change is that many lemmas are now stated in terms of i ≠ 0 (for i : Fin n) rather then i.1 ≠ 0, and as a consequence many Fin.vne_of_ne applications have been added or removed, mostly removed.

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

Diff
@@ -166,7 +166,7 @@ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x
     · simp only [get_append_right' le_rfl, sub_self, get_singleton, dist_self, zero_le]
     rw [get_append _ hMl]
     have hlen : length (drop (M + 1) l) = length l - (M + 1) := length_drop _ _
-    have hlen_lt : length l - (M + 1) < length l := Nat.sub_lt_of_pos_le _ _ M.succ_pos hMl
+    have hlen_lt : length l - (M + 1) < length l := Nat.sub_lt_of_pos_le M.succ_pos hMl
     refine' (ihn _ hlen_lt _ y _ hlen).trans _
     rw [cons_get_drop_succ]
     have hMs' : L.sum ≤ 2 * (L.take (M + 1)).sum :=
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,14 +2,11 @@
 Copyright (c) 2022 Yury Kudryashov. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yury Kudryashov
-
-! This file was ported from Lean 3 source module topology.metric_space.metrizable_uniformity
-! leanprover-community/mathlib commit 195fcd60ff2bfe392543bceb0ec2adcdb472db4c
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathlib.Topology.MetricSpace.Metrizable
 
+#align_import topology.metric_space.metrizable_uniformity from "leanprover-community/mathlib"@"195fcd60ff2bfe392543bceb0ec2adcdb472db4c"
+
 /-!
 # Metrizable uniform spaces
 
fix: precedences of ⨆⋃⋂⨅ (#5614)
Diff
@@ -76,7 +76,7 @@ noncomputable def ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x
     rw [← NNReal.coe_add, NNReal.coe_le_coe]
     refine' NNReal.le_iInf_add_iInf fun lxy lyz => _
     calc
-      (⨅ l, (zipWith d (x::l) (l ++ [z])).sum) ≤
+      ⨅ l, (zipWith d (x::l) (l ++ [z])).sum ≤
           (zipWith d (x::lxy ++ y::lyz) ((lxy ++ y::lyz) ++ [z])).sum :=
         ciInf_le (OrderBot.bddBelow _) (lxy ++ y::lyz)
       _ = (zipWith d (x::lxy) (lxy ++ [y])).sum + (zipWith d (y::lyz) (lyz ++ [z])).sum := by
chore: tidy various files (#5449)
Diff
@@ -241,19 +241,16 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
       refine' Nat.find_spec H (hU_comp (lt_add_one <| Nat.find H) _)
       exact ⟨x₂, h₁₂, x₃, h₂₃, h₃₄⟩
     · exact (dif_neg H).trans_le (zero_le _)
+  -- Porting note: without the next line, `uniformity_basis_dist_pow` ends up introducing some
+  -- `Subtype.val` applications instead of `NNReal.toReal`.
+  rw [mem_Ioo, ← NNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at hr
   refine' ⟨I, uniformSpace_eq <| (uniformity_basis_dist_pow hr.1 hr.2).ext hB.toHasBasis _ _⟩
   · refine' fun n hn => ⟨n, hn, fun x hx => (hdist_le _ _).trans_lt _⟩
-    -- Porting note: for some reason, some coercions are `Subtype.val` instead of
-    -- `NNReal.toReal`, which messes up the rewrites. So we have to `change` them in the goal
-    change _ < (toReal _) ^ _
     rwa [← NNReal.coe_pow, NNReal.coe_lt_coe, ← not_le, hle_d, Classical.not_not, Prod.mk.eta]
   · refine' fun n _ => ⟨n + 1, trivial, fun x hx => _⟩
     rw [mem_setOf_eq] at hx
     contrapose! hx
     refine' le_trans _ ((div_le_iff' (zero_lt_two' ℝ)).2 (hd_le x.1 x.2))
-    -- Porting note: for some reason, some coercions are `Subtype.val` instead of
-    -- `NNReal.toReal`, which messes up the rewrites. So we have to `change` them in the goal
-    change (toReal _) ^ _ ≤ _
     rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ',
       mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel _ (two_ne_zero' ℝ≥0), hle_d,
       Prod.mk.eta]
chore: clean up spacing around at and goals (#5387)

Changes are of the form

  • some_tactic at h⊢ -> some_tactic at h ⊢
  • some_tactic at h -> some_tactic at h
Diff
@@ -229,7 +229,7 @@ protected theorem UniformSpace.metrizable_uniformity (X : Type _) [UniformSpace
     split_ifs with h
     · rw [(strictAnti_pow hr.1 hr.2).le_iff_le, Nat.find_le_iff]
       exact ⟨fun ⟨m, hmn, hm⟩ hn => hm (hB.antitone hmn hn), fun h => ⟨n, le_rfl, h⟩⟩
-    · push_neg  at h
+    · push_neg at h
       simp only [h, not_true, (pow_pos hr.1 _).not_le]
   have hd_le : ∀ x y, ↑(d x y) ≤ 2 * dist x y := by
     refine' PseudoMetricSpace.le_two_mul_dist_ofPreNNDist _ _ _ fun x₁ x₂ x₃ x₄ => _
feat: port Topology.MetricSpace.MetrizableUniformity (#4229)

Co-authored-by: int-y1 <jason_yuen2007@hotmail.com>

Dependencies 10 + 689

690 files ported (98.6%)
301407 lines ported (98.3%)
Show graph

The unported dependencies are

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