l3lab/ntp-mathlib huggingface dataset:
/-- Compactness criterion: a closed set of compact metric spaces is compact if the spaces have
a uniformly bounded diameter, and for all `ε` the number of balls of radius `ε` required
to cover the spaces is uniformly bounded. This is an equivalence, but we only prove the
interesting direction that these conditions imply compactness. -/
theorem totallyBounded {t : Set GHSpace} {C : ℝ} {u : ℕ → ℝ} {K : ℕ → ℕ}
    (ulim : Tendsto u atTop (𝓝 0)) (hdiam : ∀ p ∈ t, diam (univ : Set (GHSpace.Rep p)) ≤ C)
    (hcov : ∀ p ∈ t, ∀ n : ℕ, ∃ s : Set (GHSpace.Rep p),
      (#s) ≤ K n ∧ univ ⊆ ⋃ x ∈ s, ball x (u n)) :
    TotallyBounded t := by
  /- Let `δ>0`, and `ε = δ/5`. For each `p`, we construct a finite subset `s p` of `p`, which
    is `ε`-dense and has cardinality at most `K n`. Encoding the mutual distances of points
    in `s p`, up to `ε`, we will get a map `F` associating to `p` finitely many data, and making
    it possible to reconstruct `p` up to `ε`. This is enough to prove total boundedness. -/
  refine' Metric.totallyBounded_of_finite_discretization fun δ δpos => _
  let ε := 1 / 5 * δ
  have εpos : 0 < ε := mul_pos (by norm_num) δpos
  -- choose `n` for which `u n < ε`
  rcases Metric.tendsto_atTop.1 ulim ε εpos with ⟨n, hn⟩
  have u_le_ε : u n ≤ ε := by
    have := hn n le_rfl
    simp only [Real.dist_eq, add_zero, sub_eq_add_neg, neg_zero] at this
    exact le_of_lt (lt_of_le_of_lt (le_abs_self _) this)
  -- construct a finite subset `s p` of `p` which is `ε`-dense and has cardinal `≤ K n`
  have :
    ∀ p : GHSpace,
      ∃ s : Set p.Rep, ∃ N ≤ K n, ∃ _ : Equiv s (Fin N), p ∈ t → univ ⊆ ⋃ x ∈ s, ball x (u n) := by
    intro p
    by_cases hp : p ∉ t
    · have : Nonempty (Equiv (∅ : Set p.Rep) (Fin 0)) := by
        rw [← Fintype.card_eq];
        simp only [empty_card', Fintype.card_fin]
      use ∅, 0, bot_le, choice this
      -- porting note: unclear why this next line wasn't needed in Lean 3
      exact fun hp' => (hp hp').elim
    · rcases hcov _ (Set.not_not_mem.1 hp) n with ⟨s, ⟨scard, scover⟩⟩
      rcases Cardinal.lt_aleph0.1 (lt_of_le_of_lt scard (Cardinal.nat_lt_aleph0 _)) with ⟨N, hN⟩
      rw [hN, Cardinal.natCast_le] at scard
      have : #s = #(Fin N) := by rw [hN, Cardinal.mk_fin]
      cases' Quotient.exact this with E
      use s, N, scard, E
      simp only [scover, imp_true_iff]
  choose s N hN E hs using this
  -- Define a function `F` taking values in a finite type and associating to `p` enough data
  -- to reconstruct it up to `ε`, namely the (discretized) distances between elements of `s p`.
  

Proof state:
case intro
t : Set GHSpace
C : ℝ
u : ℕ → ℝ
K : ℕ → ℕ
ulim : Tendsto u atTop (𝓝 0)
hdiam : ∀ p ∈ t, diam univ ≤ C
hcov : ∀ p ∈ t, ∀ (n : ℕ), ∃ s, #↑s ≤ ↑(K n) ∧ univ ⊆ ⋃ x ∈ s, ball x (u n)
δ : ℝ
δpos : δ > 0
ε : ℝ := 1 / 5 * δ
εpos : 0 < ε
n : ℕ
hn : ∀ n_1 ≥ n, dist (u n_1) 0 < ε
u_le_ε : u n ≤ ε
s : (p : GHSpace) → Set (GHSpace.Rep p)
N : GHSpace → ℕ
hN : ∀ (p : GHSpace), N p ≤ K n
E : (p : GHSpace) → ↑(s p) ≃ Fin (N p)
hs : ∀ p ∈ t, univ ⊆ ⋃ x ∈ s p, ball x (u n)
⊢ ∃ β x F, ∀ (x y : ↑t), F x = F y → dist ↑x ↑y < δ

Next tactic:
let M := ⌊ε⁻¹ * max C 0⌋₊
instance (A : Type) [MetricSpace A] : Inhabited (AuxGluingStruct A) :=
  ⟨{  Space := A
      metric := by 

Proof state:
X : ℕ → Type
inst✝³ : (n : ℕ) → MetricSpace (X n)
inst✝² : ∀ (n : ℕ), CompactSpace (X n)
inst✝¹ : ∀ (n : ℕ), Nonempty (X n)
A : Type
inst✝ : MetricSpace A
⊢ MetricSpace A

Next tactic:
infer_instance
instance (A : Type) [MetricSpace A] : Inhabited (AuxGluingStruct A) :=
  ⟨{  Space := A
      metric := by infer_instance
      embed := id
      -- porting note: without `by exact` there was an unsolved metavariable
      isom := fun x y => by 

Proof state:
X : ℕ → Type
inst✝³ : (n : ℕ) → MetricSpace (X n)
inst✝² : ∀ (n : ℕ), CompactSpace (X n)
inst✝¹ : ∀ (n : ℕ), Nonempty (X n)
A : Type
inst✝ : MetricSpace A
x y : A
⊢ edist (id x) (id y) = edist x y

Next tactic:
exact rfl
/-- Auxiliary sequence of metric spaces, containing copies of `X 0`, ..., `X n`, where each
`X i` is glued to `X (i+1)` in an optimal way. The space at step `n+1` is obtained from the space
at step `n` by adding `X (n+1)`, glued in an optimal way to the `X n` already sitting there. -/
def auxGluing (n : ℕ) : AuxGluingStruct (X n) :=
  Nat.recOn n default fun n Y =>
    { Space := GlueSpace Y.isom (isometry_optimalGHInjl (X n) (X (n + 1)))
      metric := by 

Proof state:
X : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X n)
inst✝ : ∀ (n : ℕ), Nonempty (X n)
n✝ n : ℕ
Y : AuxGluingStruct (X n)
⊢ MetricSpace (GlueSpace (_ : Isometry Y.embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))))

Next tactic:
infer_instance
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  

Proof state:
X : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X n)
inst✝ : ∀ (n : ℕ), Nonempty (X n)
⊢ CompleteSpace GHSpace

Next tactic:
set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  

Proof state:
X : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X n)
inst✝ : ∀ (n : ℕ), Nonempty (X n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
⊢ CompleteSpace GHSpace

Next tactic:
have : ∀ n : ℕ, 0 < d n := fun _ ↦ by positivity
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  have : ∀ n : ℕ, 0 < d n := fun _ ↦ by 

Proof state:
X : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X n)
inst✝ : ∀ (n : ℕ), Nonempty (X n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
x✝ : ℕ
⊢ 0 < d x✝

Next tactic:
positivity
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  have : ∀ n : ℕ, 0 < d n := fun _ ↦ by positivity
  -- start from a sequence of nonempty compact metric spaces within distance `1/2^n` of each other
  

Proof state:
X : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X n)
inst✝ : ∀ (n : ℕ), Nonempty (X n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
this : ∀ (n : ℕ), 0 < d n
⊢ CompleteSpace GHSpace

Next tactic:
refine' Metric.complete_of_convergent_controlled_sequences d this fun u hu => _
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  have : ∀ n : ℕ, 0 < d n := fun _ ↦ by positivity
  -- start from a sequence of nonempty compact metric spaces within distance `1/2^n` of each other
  refine' Metric.complete_of_convergent_controlled_sequences d this fun u hu => _
  -- `X n` is a representative of `u n`
  

Proof state:
X : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X n)
inst✝ : ∀ (n : ℕ), Nonempty (X n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
this : ∀ (n : ℕ), 0 < d n
u : ℕ → GHSpace
hu : ∀ (N n m : ℕ), N ≤ n → N ≤ m → dist (u n) (u m) < d N
⊢ ∃ x, Tendsto u atTop (𝓝 x)

Next tactic:
let X n := (u n).Rep
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  have : ∀ n : ℕ, 0 < d n := fun _ ↦ by positivity
  -- start from a sequence of nonempty compact metric spaces within distance `1/2^n` of each other
  refine' Metric.complete_of_convergent_controlled_sequences d this fun u hu => _
  -- `X n` is a representative of `u n`
  let X n := (u n).Rep
  -- glue them together successively in an optimal way, getting a sequence of metric spaces `Y n`
  

Proof state:
X✝ : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X✝ n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X✝ n)
inst✝ : ∀ (n : ℕ), Nonempty (X✝ n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
this : ∀ (n : ℕ), 0 < d n
u : ℕ → GHSpace
hu : ∀ (N n m : ℕ), N ≤ n → N ≤ m → dist (u n) (u m) < d N
X : ℕ → Type := fun n => GHSpace.Rep (u n)
⊢ ∃ x, Tendsto u atTop (𝓝 x)

Next tactic:
let Y := auxGluing X
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  have : ∀ n : ℕ, 0 < d n := fun _ ↦ by positivity
  -- start from a sequence of nonempty compact metric spaces within distance `1/2^n` of each other
  refine' Metric.complete_of_convergent_controlled_sequences d this fun u hu => _
  -- `X n` is a representative of `u n`
  let X n := (u n).Rep
  -- glue them together successively in an optimal way, getting a sequence of metric spaces `Y n`
  let Y := auxGluing X
  -- this equality is true by definition but Lean unfolds some defs in the wrong order
  

Proof state:
X✝ : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X✝ n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X✝ n)
inst✝ : ∀ (n : ℕ), Nonempty (X✝ n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
this : ∀ (n : ℕ), 0 < d n
u : ℕ → GHSpace
hu : ∀ (N n m : ℕ), N ≤ n → N ≤ m → dist (u n) (u m) < d N
X : ℕ → Type := fun n => GHSpace.Rep (u n)
Y : (n : ℕ) → AuxGluingStruct (X n) := auxGluing X
⊢ ∃ x, Tendsto u atTop (𝓝 x)

Next tactic:
have E :
    ∀ n : ℕ,
      GlueSpace (Y n).isom (isometry_optimalGHInjl (X n) (X (n + 1))) = (Y (n + 1)).Space :=
    fun n => by dsimp only [auxGluing]; rfl
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  have : ∀ n : ℕ, 0 < d n := fun _ ↦ by positivity
  -- start from a sequence of nonempty compact metric spaces within distance `1/2^n` of each other
  refine' Metric.complete_of_convergent_controlled_sequences d this fun u hu => _
  -- `X n` is a representative of `u n`
  let X n := (u n).Rep
  -- glue them together successively in an optimal way, getting a sequence of metric spaces `Y n`
  let Y := auxGluing X
  -- this equality is true by definition but Lean unfolds some defs in the wrong order
  have E :
    ∀ n : ℕ,
      GlueSpace (Y n).isom (isometry_optimalGHInjl (X n) (X (n + 1))) = (Y (n + 1)).Space :=
    fun n => by 

Proof state:
X✝ : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X✝ n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X✝ n)
inst✝ : ∀ (n : ℕ), Nonempty (X✝ n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
this : ∀ (n : ℕ), 0 < d n
u : ℕ → GHSpace
hu : ∀ (N n m : ℕ), N ≤ n → N ≤ m → dist (u n) (u m) < d N
X : ℕ → Type := fun n => GHSpace.Rep (u n)
Y : (n : ℕ) → AuxGluingStruct (X n) := auxGluing X
n : ℕ
⊢ GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) = (Y (n + 1)).Space

Next tactic:
dsimp only [auxGluing]
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  have : ∀ n : ℕ, 0 < d n := fun _ ↦ by positivity
  -- start from a sequence of nonempty compact metric spaces within distance `1/2^n` of each other
  refine' Metric.complete_of_convergent_controlled_sequences d this fun u hu => _
  -- `X n` is a representative of `u n`
  let X n := (u n).Rep
  -- glue them together successively in an optimal way, getting a sequence of metric spaces `Y n`
  let Y := auxGluing X
  -- this equality is true by definition but Lean unfolds some defs in the wrong order
  have E :
    ∀ n : ℕ,
      GlueSpace (Y n).isom (isometry_optimalGHInjl (X n) (X (n + 1))) = (Y (n + 1)).Space :=
    fun n => by dsimp only [auxGluing]; 

Proof state:
X✝ : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X✝ n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X✝ n)
inst✝ : ∀ (n : ℕ), Nonempty (X✝ n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
this : ∀ (n : ℕ), 0 < d n
u : ℕ → GHSpace
hu : ∀ (N n m : ℕ), N ≤ n → N ≤ m → dist (u n) (u m) < d N
X : ℕ → Type := fun n => GHSpace.Rep (u n)
Y : (n : ℕ) → AuxGluingStruct (X n) := auxGluing X
n : ℕ
⊢ GlueSpace
      (_ :
        Isometry
          (Nat.rec default
              (fun n Y =>
                {
                  Space :=
                    GlueSpace (_ : Isometry Y.embed)
                      (_ : Isometry (optimalGHInjl (GHSpace.Rep (u n)) (GHSpace.Rep (u (n + 1))))),
                  metric := inferInstance,
                  embed :=
                    toGlueR (_ : Isometry Y.embed)
                        (_ : Isometry (optimalGHInjl (GHSpace.Rep (u n)) (GHSpace.Rep (u (n + 1))))) ∘
                      optimalGHInjr (GHSpace.Rep (u n)) (GHSpace.Rep (u (n + 1))),
                  isom :=
                    (_ :
                      Isometry
                        (toGlueR (_ : Isometry Y.embed)
                            (_ : Isometry (optimalGHInjl (GHSpace.Rep (u n)) (GHSpace.Rep (u (n + 1))))) ∘
                          optimalGHInjr (GHSpace.Rep (u n)) (GHSpace.Rep (u (n + 1))))) })
              n).embed)
      (_ : Isometry (optimalGHInjl (GHSpace.Rep (u n)) (GHSpace.Rep (u (n + 1))))) =
    (Nat.rec default
        (fun n Y =>
          {
            Space :=
              GlueSpace (_ : Isometry Y.embed)
                (_ : Isometry (optimalGHInjl (GHSpace.Rep (u n)) (GHSpace.Rep (u (n + 1))))),
            metric := inferInstance,
            embed :=
              toGlueR (_ : Isometry Y.embed)
                  (_ : Isometry (optimalGHInjl (GHSpace.Rep (u n)) (GHSpace.Rep (u (n + 1))))) ∘
                optimalGHInjr (GHSpace.Rep (u n)) (GHSpace.Rep (u (n + 1))),
            isom :=
              (_ :
                Isometry
                  (toGlueR (_ : Isometry Y.embed)
                      (_ : Isometry (optimalGHInjl (GHSpace.Rep (u n)) (GHSpace.Rep (u (n + 1))))) ∘
                    optimalGHInjr (GHSpace.Rep (u n)) (GHSpace.Rep (u (n + 1))))) })
        (n + 1)).Space

Next tactic:
rfl
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  have : ∀ n : ℕ, 0 < d n := fun _ ↦ by positivity
  -- start from a sequence of nonempty compact metric spaces within distance `1/2^n` of each other
  refine' Metric.complete_of_convergent_controlled_sequences d this fun u hu => _
  -- `X n` is a representative of `u n`
  let X n := (u n).Rep
  -- glue them together successively in an optimal way, getting a sequence of metric spaces `Y n`
  let Y := auxGluing X
  -- this equality is true by definition but Lean unfolds some defs in the wrong order
  have E :
    ∀ n : ℕ,
      GlueSpace (Y n).isom (isometry_optimalGHInjl (X n) (X (n + 1))) = (Y (n + 1)).Space :=
    fun n => by dsimp only [auxGluing]; rfl
  

Proof state:
X✝ : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X✝ n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X✝ n)
inst✝ : ∀ (n : ℕ), Nonempty (X✝ n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
this : ∀ (n : ℕ), 0 < d n
u : ℕ → GHSpace
hu : ∀ (N n m : ℕ), N ≤ n → N ≤ m → dist (u n) (u m) < d N
X : ℕ → Type := fun n => GHSpace.Rep (u n)
Y : (n : ℕ) → AuxGluingStruct (X n) := auxGluing X
E : ∀ (n : ℕ), GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) = (Y (n + 1)).Space
⊢ ∃ x, Tendsto u atTop (𝓝 x)

Next tactic:
let c n := cast (E n)
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  have : ∀ n : ℕ, 0 < d n := fun _ ↦ by positivity
  -- start from a sequence of nonempty compact metric spaces within distance `1/2^n` of each other
  refine' Metric.complete_of_convergent_controlled_sequences d this fun u hu => _
  -- `X n` is a representative of `u n`
  let X n := (u n).Rep
  -- glue them together successively in an optimal way, getting a sequence of metric spaces `Y n`
  let Y := auxGluing X
  -- this equality is true by definition but Lean unfolds some defs in the wrong order
  have E :
    ∀ n : ℕ,
      GlueSpace (Y n).isom (isometry_optimalGHInjl (X n) (X (n + 1))) = (Y (n + 1)).Space :=
    fun n => by dsimp only [auxGluing]; rfl
  let c n := cast (E n)
  

Proof state:
X✝ : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X✝ n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X✝ n)
inst✝ : ∀ (n : ℕ), Nonempty (X✝ n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
this : ∀ (n : ℕ), 0 < d n
u : ℕ → GHSpace
hu : ∀ (N n m : ℕ), N ≤ n → N ≤ m → dist (u n) (u m) < d N
X : ℕ → Type := fun n => GHSpace.Rep (u n)
Y : (n : ℕ) → AuxGluingStruct (X n) := auxGluing X
E : ∀ (n : ℕ), GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) = (Y (n + 1)).Space
c : (n : ℕ) →
  GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) → (Y (n + 1)).Space :=
  fun n =>
    cast (_ : GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) = (Y (n + 1)).Space)
⊢ ∃ x, Tendsto u atTop (𝓝 x)

Next tactic:
have ic : ∀ n, Isometry (c n) := fun n x y => by dsimp only [auxGluing]; exact rfl
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  have : ∀ n : ℕ, 0 < d n := fun _ ↦ by positivity
  -- start from a sequence of nonempty compact metric spaces within distance `1/2^n` of each other
  refine' Metric.complete_of_convergent_controlled_sequences d this fun u hu => _
  -- `X n` is a representative of `u n`
  let X n := (u n).Rep
  -- glue them together successively in an optimal way, getting a sequence of metric spaces `Y n`
  let Y := auxGluing X
  -- this equality is true by definition but Lean unfolds some defs in the wrong order
  have E :
    ∀ n : ℕ,
      GlueSpace (Y n).isom (isometry_optimalGHInjl (X n) (X (n + 1))) = (Y (n + 1)).Space :=
    fun n => by dsimp only [auxGluing]; rfl
  let c n := cast (E n)
  have ic : ∀ n, Isometry (c n) := fun n x y => by 

Proof state:
X✝ : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X✝ n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X✝ n)
inst✝ : ∀ (n : ℕ), Nonempty (X✝ n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
this : ∀ (n : ℕ), 0 < d n
u : ℕ → GHSpace
hu : ∀ (N n m : ℕ), N ≤ n → N ≤ m → dist (u n) (u m) < d N
X : ℕ → Type := fun n => GHSpace.Rep (u n)
Y : (n : ℕ) → AuxGluingStruct (X n) := auxGluing X
E : ∀ (n : ℕ), GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) = (Y (n + 1)).Space
c : (n : ℕ) →
  GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) → (Y (n + 1)).Space :=
  fun n =>
    cast (_ : GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) = (Y (n + 1)).Space)
n : ℕ
x y : GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1))))
⊢ edist (c n x) (c n y) = edist x y

Next tactic:
dsimp only [auxGluing]
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  have : ∀ n : ℕ, 0 < d n := fun _ ↦ by positivity
  -- start from a sequence of nonempty compact metric spaces within distance `1/2^n` of each other
  refine' Metric.complete_of_convergent_controlled_sequences d this fun u hu => _
  -- `X n` is a representative of `u n`
  let X n := (u n).Rep
  -- glue them together successively in an optimal way, getting a sequence of metric spaces `Y n`
  let Y := auxGluing X
  -- this equality is true by definition but Lean unfolds some defs in the wrong order
  have E :
    ∀ n : ℕ,
      GlueSpace (Y n).isom (isometry_optimalGHInjl (X n) (X (n + 1))) = (Y (n + 1)).Space :=
    fun n => by dsimp only [auxGluing]; rfl
  let c n := cast (E n)
  have ic : ∀ n, Isometry (c n) := fun n x y => by dsimp only [auxGluing]; 

Proof state:
X✝ : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X✝ n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X✝ n)
inst✝ : ∀ (n : ℕ), Nonempty (X✝ n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
this : ∀ (n : ℕ), 0 < d n
u : ℕ → GHSpace
hu : ∀ (N n m : ℕ), N ≤ n → N ≤ m → dist (u n) (u m) < d N
X : ℕ → Type := fun n => GHSpace.Rep (u n)
Y : (n : ℕ) → AuxGluingStruct (X n) := auxGluing X
E : ∀ (n : ℕ), GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) = (Y (n + 1)).Space
c : (n : ℕ) →
  GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) → (Y (n + 1)).Space :=
  fun n =>
    cast (_ : GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) = (Y (n + 1)).Space)
n : ℕ
x y : GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1))))
⊢ edist
      (cast
        (_ : GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) = (Y (n + 1)).Space)
        x)
      (cast
        (_ : GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) = (Y (n + 1)).Space)
        y) =
    edist x y

Next tactic:
exact rfl
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
  set d := fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n
  have : ∀ n : ℕ, 0 < d n := fun _ ↦ by positivity
  -- start from a sequence of nonempty compact metric spaces within distance `1/2^n` of each other
  refine' Metric.complete_of_convergent_controlled_sequences d this fun u hu => _
  -- `X n` is a representative of `u n`
  let X n := (u n).Rep
  -- glue them together successively in an optimal way, getting a sequence of metric spaces `Y n`
  let Y := auxGluing X
  -- this equality is true by definition but Lean unfolds some defs in the wrong order
  have E :
    ∀ n : ℕ,
      GlueSpace (Y n).isom (isometry_optimalGHInjl (X n) (X (n + 1))) = (Y (n + 1)).Space :=
    fun n => by dsimp only [auxGluing]; rfl
  let c n := cast (E n)
  have ic : ∀ n, Isometry (c n) := fun n x y => by dsimp only [auxGluing]; exact rfl
  -- there is a canonical embedding of `Y n` in `Y (n+1)`, by construction
  

Proof state:
X✝ : ℕ → Type
inst✝² : (n : ℕ) → MetricSpace (X✝ n)
inst✝¹ : ∀ (n : ℕ), CompactSpace (X✝ n)
inst✝ : ∀ (n : ℕ), Nonempty (X✝ n)
d : ℕ → ℝ := fun n => (1 / 2) ^ n
this : ∀ (n : ℕ), 0 < d n
u : ℕ → GHSpace
hu : ∀ (N n m : ℕ), N ≤ n → N ≤ m → dist (u n) (u m) < d N
X : ℕ → Type := fun n => GHSpace.Rep (u n)
Y : (n : ℕ) → AuxGluingStruct (X n) := auxGluing X
E : ∀ (n : ℕ), GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) = (Y (n + 1)).Space
c : (n : ℕ) →
  GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) → (Y (n + 1)).Space :=
  fun n =>
    cast (_ : GlueSpace (_ : Isometry (Y n).embed) (_ : Isometry (optimalGHInjl (X n) (X (n + 1)))) = (Y (n + 1)).Space)
ic : ∀ (n : ℕ), Isometry (c n)
⊢ ∃ x, Tendsto u atTop (𝓝 x)

Next tactic:
let f : ∀ n, (Y n).Space → (Y (n + 1)).Space := fun n =>
    c n ∘ toGlueL (Y n).isom (isometry_optimalGHInjl (X n) (X n.succ))