l3lab/ntp-mathlib huggingface dataset:
/-- For any candidate `f`, `HD(f)` is larger than or equal to the Hausdorff distance in the
optimal coupling. This follows from the fact that `HD` of the optimal candidate is exactly
the Hausdorff distance in the optimal coupling, although we only prove here the inequality
we need. -/
theorem hausdorffDist_optimal_le_HD {f} (h : f ∈ candidatesB X Y) :
    hausdorffDist (range (optimalGHInjl X Y)) (range (optimalGHInjr X Y)) ≤ HD f := by
  refine' le_trans (le_of_forall_le_of_dense fun r hr => _) (HD_optimalGHDist_le X Y f h)
  have A : ∀ x ∈ range (optimalGHInjl X Y), ∃ y ∈ range (optimalGHInjr X Y), dist x y ≤ r := by
    rintro _ ⟨z, rfl⟩
    have I1 : (⨆ x, ⨅ y, optimalGHDist X Y (inl x, inr y)) < r :=
      lt_of_le_of_lt (le_max_left _ _) hr
    have I2 :
        ⨅ y, optimalGHDist X Y (inl z, inr y) ≤ ⨆ x, ⨅ y, optimalGHDist X Y (inl x, inr y) :=
      le_csSup (by simpa using HD_bound_aux1 _ 0) (mem_range_self _)
    have I : ⨅ y, optimalGHDist X Y (inl z, inr y) < r := lt_of_le_of_lt I2 I1
    rcases exists_lt_of_csInf_lt (range_nonempty _) I with ⟨r', ⟨z', rfl⟩, hr'⟩
    exact ⟨optimalGHInjr X Y z', mem_range_self _, le_of_lt hr'⟩
  refine' hausdorffDist_le_of_mem_dist _ A _
  · inhabit X
    rcases A _ (mem_range_self default) with ⟨y, -, hy⟩
    exact le_trans dist_nonneg hy
  · rintro _ ⟨z, rfl⟩
    have I1 : (⨆ y, ⨅ x, optimalGHDist X Y (inl x, inr y)) < r :=
      lt_of_le_of_lt (le_max_right _ _) hr
    have I2 :
        ⨅ x, optimalGHDist X Y (inl x, inr z) ≤ ⨆ y, ⨅ x, optimalGHDist X Y (inl x, inr y) :=
      le_csSup (by simpa using HD_bound_aux2 _ 0) (mem_range_self _)
    have I : ⨅ x, optimalGHDist X Y (inl x, inr z) < r := lt_of_le_of_lt I2 I1
    rcases exists_lt_of_csInf_lt (range_nonempty _) I with ⟨r', ⟨z', rfl⟩, hr'⟩
    refine' ⟨optimalGHInjl X Y z', mem_range_self _, le_of_lt _⟩
    

Proof state:
case refine'_2.intro.intro.intro.intro
X : Type u
Y : Type v
inst✝⁵ : MetricSpace X
inst✝⁴ : CompactSpace X
inst✝³ : Nonempty X
inst✝² : MetricSpace Y
inst✝¹ : CompactSpace Y
inst✝ : Nonempty Y
f : GromovHausdorff.Cb X Y
h : f ∈ GromovHausdorff.candidatesB X Y
r : ℝ
hr : HD (GromovHausdorff.optimalGHDist X Y) < r
A : ∀ x ∈ range (optimalGHInjl X Y), ∃ y ∈ range (optimalGHInjr X Y), dist x y ≤ r
z : Y
I1 : ⨆ y, ⨅ x, (GromovHausdorff.optimalGHDist X Y) (inl x, inr y) < r
I2 :
  ⨅ x, (GromovHausdorff.optimalGHDist X Y) (inl x, inr z) ≤ ⨆ y, ⨅ x, (GromovHausdorff.optimalGHDist X Y) (inl x, inr y)
I : ⨅ x, (GromovHausdorff.optimalGHDist X Y) (inl x, inr z) < r
z' : X
hr' : (fun x => (GromovHausdorff.optimalGHDist X Y) (inl x, inr z)) z' < r
⊢ dist (optimalGHInjr X Y z) (optimalGHInjl X Y z') < r

Next tactic:
rwa [dist_comm]
theorem hasStrictDerivAt : HasStrictDerivAt f (f.linear 1) x := by
  

Proof state:
𝕜 : Type u_1
inst✝² : NontriviallyNormedField 𝕜
E : Type u_2
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 →ᵃ[𝕜] E
a b : E
L : Filter 𝕜
s : Set 𝕜
x : 𝕜
⊢ HasStrictDerivAt (⇑f) (f.linear 1) x

Next tactic:
rw [f.decomp]
theorem hasStrictDerivAt : HasStrictDerivAt f (f.linear 1) x := by
  rw [f.decomp]
  

Proof state:
𝕜 : Type u_1
inst✝² : NontriviallyNormedField 𝕜
E : Type u_2
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 →ᵃ[𝕜] E
a b : E
L : Filter 𝕜
s : Set 𝕜
x : 𝕜
⊢ HasStrictDerivAt (⇑f.linear + fun x => f 0) (f.linear 1) x

Next tactic:
exact f.linear.hasStrictDerivAt.add_const (f 0)
theorem hasDerivAtFilter : HasDerivAtFilter f (f.linear 1) x L := by
  

Proof state:
𝕜 : Type u_1
inst✝² : NontriviallyNormedField 𝕜
E : Type u_2
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 →ᵃ[𝕜] E
a b : E
L : Filter 𝕜
s : Set 𝕜
x : 𝕜
⊢ HasDerivAtFilter (⇑f) (f.linear 1) x L

Next tactic:
rw [f.decomp]
theorem hasDerivAtFilter : HasDerivAtFilter f (f.linear 1) x L := by
  rw [f.decomp]
  

Proof state:
𝕜 : Type u_1
inst✝² : NontriviallyNormedField 𝕜
E : Type u_2
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 →ᵃ[𝕜] E
a b : E
L : Filter 𝕜
s : Set 𝕜
x : 𝕜
⊢ HasDerivAtFilter (⇑f.linear + fun x => f 0) (f.linear 1) x L

Next tactic:
exact f.linear.hasDerivAtFilter.add_const (f 0)
theorem hasStrictDerivAt_lineMap : HasStrictDerivAt (lineMap a b) (b - a) x := by
  

Proof state:
𝕜 : Type u_1
inst✝² : NontriviallyNormedField 𝕜
E : Type u_2
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 →ᵃ[𝕜] E
a b : E
L : Filter 𝕜
s : Set 𝕜
x : 𝕜
⊢ HasStrictDerivAt (⇑(lineMap a b)) (b - a) x

Next tactic:
simpa using (lineMap a b : 𝕜 →ᵃ[𝕜] E).hasStrictDerivAt
@[simp]
theorem map_valEmbedding_Icc : (Icc a b).map Fin.valEmbedding = Icc ↑a ↑b := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ map valEmbedding (Icc a b) = Icc ↑a ↑b

Next tactic:
simp [Icc_eq_finset_subtype, Finset.fin, Finset.map_map, Icc_filter_lt_of_lt_right]
@[simp]
theorem map_valEmbedding_Ico : (Ico a b).map Fin.valEmbedding = Ico ↑a ↑b := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ map valEmbedding (Ico a b) = Ico ↑a ↑b

Next tactic:
simp [Ico_eq_finset_subtype, Finset.fin, Finset.map_map]
@[simp]
theorem map_valEmbedding_Ioc : (Ioc a b).map Fin.valEmbedding = Ioc ↑a ↑b := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ map valEmbedding (Ioc a b) = Ioc ↑a ↑b

Next tactic:
simp [Ioc_eq_finset_subtype, Finset.fin, Finset.map_map, Ioc_filter_lt_of_lt_right]
@[simp]
theorem map_valEmbedding_Ioo : (Ioo a b).map Fin.valEmbedding = Ioo ↑a ↑b := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ map valEmbedding (Ioo a b) = Ioo ↑a ↑b

Next tactic:
simp [Ioo_eq_finset_subtype, Finset.fin, Finset.map_map]
@[simp]
theorem card_Icc : (Icc a b).card = b + 1 - a := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ card (Icc a b) = ↑b + 1 - ↑a

Next tactic:
rw [← Nat.card_Icc, ← map_valEmbedding_Icc, card_map]
@[simp]
theorem card_Ico : (Ico a b).card = b - a := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ card (Ico a b) = ↑b - ↑a

Next tactic:
rw [← Nat.card_Ico, ← map_valEmbedding_Ico, card_map]
@[simp]
theorem card_Ioc : (Ioc a b).card = b - a := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ card (Ioc a b) = ↑b - ↑a

Next tactic:
rw [← Nat.card_Ioc, ← map_valEmbedding_Ioc, card_map]
@[simp]
theorem card_Ioo : (Ioo a b).card = b - a - 1 := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ card (Ioo a b) = ↑b - ↑a - 1

Next tactic:
rw [← Nat.card_Ioo, ← map_valEmbedding_Ioo, card_map]
@[simp]
theorem card_uIcc : (uIcc a b).card = (b - a : ℤ).natAbs + 1 := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ card (uIcc a b) = Int.natAbs (↑↑b - ↑↑a) + 1

Next tactic:
rw [← Nat.card_uIcc, ← map_subtype_embedding_uIcc, card_map]
theorem card_fintypeIcc : Fintype.card (Set.Icc a b) = b + 1 - a := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ Fintype.card ↑(Set.Icc a b) = ↑b + 1 - ↑a

Next tactic:
rw [← card_Icc, Fintype.card_ofFinset]
theorem card_fintypeIco : Fintype.card (Set.Ico a b) = b - a := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ Fintype.card ↑(Set.Ico a b) = ↑b - ↑a

Next tactic:
rw [← card_Ico, Fintype.card_ofFinset]
theorem card_fintypeIoc : Fintype.card (Set.Ioc a b) = b - a := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ Fintype.card ↑(Set.Ioc a b) = ↑b - ↑a

Next tactic:
rw [← card_Ioc, Fintype.card_ofFinset]
theorem card_fintypeIoo : Fintype.card (Set.Ioo a b) = b - a - 1 := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ Fintype.card ↑(Set.Ioo a b) = ↑b - ↑a - 1

Next tactic:
rw [← card_Ioo, Fintype.card_ofFinset]
theorem card_fintype_uIcc : Fintype.card (Set.uIcc a b) = (b - a : ℤ).natAbs + 1 := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ Fintype.card ↑(Set.uIcc a b) = Int.natAbs (↑↑b - ↑↑a) + 1

Next tactic:
rw [← card_uIcc, Fintype.card_ofFinset]
theorem Ici_eq_finset_subtype : Ici a = (Icc (a : ℕ) n).fin n := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ Ici a = Finset.fin n (Icc (↑a) n)

Next tactic:
ext
theorem Ici_eq_finset_subtype : Ici a = (Icc (a : ℕ) n).fin n := by
  ext
  

Proof state:
case a
n : ℕ
a b a✝ : Fin n
⊢ a✝ ∈ Ici a ↔ a✝ ∈ Finset.fin n (Icc (↑a) n)

Next tactic:
simp
theorem Ioi_eq_finset_subtype : Ioi a = (Ioc (a : ℕ) n).fin n := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ Ioi a = Finset.fin n (Ioc (↑a) n)

Next tactic:
ext
theorem Ioi_eq_finset_subtype : Ioi a = (Ioc (a : ℕ) n).fin n := by
  ext
  

Proof state:
case a
n : ℕ
a b a✝ : Fin n
⊢ a✝ ∈ Ioi a ↔ a✝ ∈ Finset.fin n (Ioc (↑a) n)

Next tactic:
simp
@[simp]
theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Icc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  

Proof state:
n : ℕ
a b : Fin n
⊢ map valEmbedding (Ici a) = Icc (↑a) (n - 1)

Next tactic:
clear b
@[simp]
theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Icc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  

Proof state:
n : ℕ
a : Fin n
⊢ map valEmbedding (Ici a) = Icc (↑a) (n - 1)

Next tactic:
ext x
@[simp]
theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Icc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  

Proof state:
case a
n : ℕ
a : Fin n
x : ℕ
⊢ x ∈ map valEmbedding (Ici a) ↔ x ∈ Icc (↑a) (n - 1)

Next tactic:
simp only [exists_prop, Embedding.coe_subtype, mem_Ici, mem_map, mem_Icc]
@[simp]
theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Icc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  simp only [exists_prop, Embedding.coe_subtype, mem_Ici, mem_map, mem_Icc]
  

Proof state:
case a
n : ℕ
a : Fin n
x : ℕ
⊢ (∃ a_1, a ≤ a_1 ∧ valEmbedding a_1 = x) ↔ ↑a ≤ x ∧ x ≤ n - 1

Next tactic:
constructor
@[simp]
theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Icc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  simp only [exists_prop, Embedding.coe_subtype, mem_Ici, mem_map, mem_Icc]
  constructor
  · 

Proof state:
case a.mp
n : ℕ
a : Fin n
x : ℕ
⊢ (∃ a_1, a ≤ a_1 ∧ valEmbedding a_1 = x) → ↑a ≤ x ∧ x ≤ n - 1

Next tactic:
rintro ⟨x, hx, rfl⟩
@[simp]
theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Icc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  simp only [exists_prop, Embedding.coe_subtype, mem_Ici, mem_map, mem_Icc]
  constructor
  · rintro ⟨x, hx, rfl⟩
    

Proof state:
case a.mp.intro.intro
n : ℕ
a x : Fin n
hx : a ≤ x
⊢ ↑a ≤ valEmbedding x ∧ valEmbedding x ≤ n - 1

Next tactic:
exact ⟨hx, le_tsub_of_add_le_right <| x.2⟩
@[simp]
theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Icc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  simp only [exists_prop, Embedding.coe_subtype, mem_Ici, mem_map, mem_Icc]
  constructor
  · rintro ⟨x, hx, rfl⟩
    exact ⟨hx, le_tsub_of_add_le_right <| x.2⟩
  

Proof state:
case a.mpr
n : ℕ
a : Fin n
x : ℕ
⊢ ↑a ≤ x ∧ x ≤ n - 1 → ∃ a_2, a ≤ a_2 ∧ valEmbedding a_2 = x

Next tactic:
cases n
@[simp]
theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Icc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  simp only [exists_prop, Embedding.coe_subtype, mem_Ici, mem_map, mem_Icc]
  constructor
  · rintro ⟨x, hx, rfl⟩
    exact ⟨hx, le_tsub_of_add_le_right <| x.2⟩
  cases n
  · 

Proof state:
case a.mpr.zero
x : ℕ
a : Fin Nat.zero
⊢ ↑a ≤ x ∧ x ≤ Nat.zero - 1 → ∃ a_2, a ≤ a_2 ∧ valEmbedding a_2 = x

Next tactic:
exact Fin.elim0 a
@[simp]
theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Icc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  simp only [exists_prop, Embedding.coe_subtype, mem_Ici, mem_map, mem_Icc]
  constructor
  · rintro ⟨x, hx, rfl⟩
    exact ⟨hx, le_tsub_of_add_le_right <| x.2⟩
  cases n
  · exact Fin.elim0 a
  · 

Proof state:
case a.mpr.succ
x n✝ : ℕ
a : Fin (Nat.succ n✝)
⊢ ↑a ≤ x ∧ x ≤ Nat.succ n✝ - 1 → ∃ a_2, a ≤ a_2 ∧ valEmbedding a_2 = x

Next tactic:
exact fun hx => ⟨⟨x, Nat.lt_succ_iff.2 hx.2⟩, hx.1, rfl⟩
@[simp]
theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  

Proof state:
n : ℕ
a b : Fin n
⊢ map valEmbedding (Ioi a) = Ioc (↑a) (n - 1)

Next tactic:
clear b
@[simp]
theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  

Proof state:
n : ℕ
a : Fin n
⊢ map valEmbedding (Ioi a) = Ioc (↑a) (n - 1)

Next tactic:
ext x
@[simp]
theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  

Proof state:
case a
n : ℕ
a : Fin n
x : ℕ
⊢ x ∈ map valEmbedding (Ioi a) ↔ x ∈ Ioc (↑a) (n - 1)

Next tactic:
simp only [exists_prop, Embedding.coe_subtype, mem_Ioi, mem_map, mem_Ioc]
@[simp]
theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  simp only [exists_prop, Embedding.coe_subtype, mem_Ioi, mem_map, mem_Ioc]
  

Proof state:
case a
n : ℕ
a : Fin n
x : ℕ
⊢ (∃ a_1, a < a_1 ∧ valEmbedding a_1 = x) ↔ ↑a < x ∧ x ≤ n - 1

Next tactic:
constructor
@[simp]
theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  simp only [exists_prop, Embedding.coe_subtype, mem_Ioi, mem_map, mem_Ioc]
  constructor
  · 

Proof state:
case a.mp
n : ℕ
a : Fin n
x : ℕ
⊢ (∃ a_1, a < a_1 ∧ valEmbedding a_1 = x) → ↑a < x ∧ x ≤ n - 1

Next tactic:
rintro ⟨x, hx, rfl⟩
@[simp]
theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  simp only [exists_prop, Embedding.coe_subtype, mem_Ioi, mem_map, mem_Ioc]
  constructor
  · rintro ⟨x, hx, rfl⟩
    

Proof state:
case a.mp.intro.intro
n : ℕ
a x : Fin n
hx : a < x
⊢ ↑a < valEmbedding x ∧ valEmbedding x ≤ n - 1

Next tactic:
exact ⟨hx, le_tsub_of_add_le_right <| x.2⟩
@[simp]
theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  simp only [exists_prop, Embedding.coe_subtype, mem_Ioi, mem_map, mem_Ioc]
  constructor
  · rintro ⟨x, hx, rfl⟩
    exact ⟨hx, le_tsub_of_add_le_right <| x.2⟩
  

Proof state:
case a.mpr
n : ℕ
a : Fin n
x : ℕ
⊢ ↑a < x ∧ x ≤ n - 1 → ∃ a_2, a < a_2 ∧ valEmbedding a_2 = x

Next tactic:
cases n
@[simp]
theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  simp only [exists_prop, Embedding.coe_subtype, mem_Ioi, mem_map, mem_Ioc]
  constructor
  · rintro ⟨x, hx, rfl⟩
    exact ⟨hx, le_tsub_of_add_le_right <| x.2⟩
  cases n
  · 

Proof state:
case a.mpr.zero
x : ℕ
a : Fin Nat.zero
⊢ ↑a < x ∧ x ≤ Nat.zero - 1 → ∃ a_2, a < a_2 ∧ valEmbedding a_2 = x

Next tactic:
exact Fin.elim0 a
@[simp]
theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
  clear b
  ext x
  simp only [exists_prop, Embedding.coe_subtype, mem_Ioi, mem_map, mem_Ioc]
  constructor
  · rintro ⟨x, hx, rfl⟩
    exact ⟨hx, le_tsub_of_add_le_right <| x.2⟩
  cases n
  · exact Fin.elim0 a
  · 

Proof state:
case a.mpr.succ
x n✝ : ℕ
a : Fin (Nat.succ n✝)
⊢ ↑a < x ∧ x ≤ Nat.succ n✝ - 1 → ∃ a_2, a < a_2 ∧ valEmbedding a_2 = x

Next tactic:
exact fun hx => ⟨⟨x, Nat.lt_succ_iff.2 hx.2⟩, hx.1, rfl⟩
@[simp]
theorem map_valEmbedding_Iic : (Iic b).map Fin.valEmbedding = Iic ↑b := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ map valEmbedding (Iic b) = Iic ↑b

Next tactic:
simp [Iic_eq_finset_subtype, Finset.fin, Finset.map_map, Iic_filter_lt_of_lt_right]
@[simp]
theorem map_valEmbedding_Iio : (Iio b).map Fin.valEmbedding = Iio ↑b := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ map valEmbedding (Iio b) = Iio ↑b

Next tactic:
simp [Iio_eq_finset_subtype, Finset.fin, Finset.map_map]
@[simp]
theorem card_Ici : (Ici a).card = n - a := by
-- Porting note: without `clear b` Lean includes `b` in the statement.
  

Proof state:
n : ℕ
a b : Fin n
⊢ card (Ici a) = n - ↑a

Next tactic:
clear b
@[simp]
theorem card_Ici : (Ici a).card = n - a := by
-- Porting note: without `clear b` Lean includes `b` in the statement.
  clear b
  

Proof state:
n : ℕ
a : Fin n
⊢ card (Ici a) = n - ↑a

Next tactic:
cases n with
  | zero => exact Fin.elim0 a
  | succ =>
    rw [← card_map, map_valEmbedding_Ici, Nat.card_Icc, Nat.add_one_sub_one]
@[simp]
theorem card_Ici : (Ici a).card = n - a := by
-- Porting note: without `clear b` Lean includes `b` in the statement.
  clear b
  cases n with
  

Proof state:
case zero
a : Fin Nat.zero
⊢ card (Ici a) = Nat.zero - ↑a

Next tactic:
| zero => exact Fin.elim0 a
@[simp]
theorem card_Ici : (Ici a).card = n - a := by
-- Porting note: without `clear b` Lean includes `b` in the statement.
  clear b
  cases n with
  | zero => 

Proof state:
case zero
a : Fin Nat.zero
⊢ card (Ici a) = Nat.zero - ↑a

Next tactic:
exact Fin.elim0 a
@[simp]
theorem card_Ici : (Ici a).card = n - a := by
-- Porting note: without `clear b` Lean includes `b` in the statement.
  clear b
  cases n with
  | zero => exact Fin.elim0 a
  

Proof state:
case succ
n✝ : ℕ
a : Fin (Nat.succ n✝)
⊢ card (Ici a) = Nat.succ n✝ - ↑a

Next tactic:
| succ =>
    rw [← card_map, map_valEmbedding_Ici, Nat.card_Icc, Nat.add_one_sub_one]
@[simp]
theorem card_Ici : (Ici a).card = n - a := by
-- Porting note: without `clear b` Lean includes `b` in the statement.
  clear b
  cases n with
  | zero => exact Fin.elim0 a
  | succ =>
    

Proof state:
case succ
n✝ : ℕ
a : Fin (Nat.succ n✝)
⊢ card (Ici a) = Nat.succ n✝ - ↑a

Next tactic:
rw [← card_map, map_valEmbedding_Ici, Nat.card_Icc, Nat.add_one_sub_one]
@[simp]
theorem card_Ioi : (Ioi a).card = n - 1 - a := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ card (Ioi a) = n - 1 - ↑a

Next tactic:
rw [← card_map, map_valEmbedding_Ioi, Nat.card_Ioc]
@[simp]
theorem card_Iic : (Iic b).card = b + 1 := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ card (Iic b) = ↑b + 1

Next tactic:
rw [← Nat.card_Iic b, ← map_valEmbedding_Iic, card_map]
@[simp]
theorem card_Iio : (Iio b).card = b := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ card (Iio b) = ↑b

Next tactic:
rw [← Nat.card_Iio b, ← map_valEmbedding_Iio, card_map]
theorem card_fintypeIci : Fintype.card (Set.Ici a) = n - a := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ Fintype.card ↑(Set.Ici a) = n - ↑a

Next tactic:
rw [Fintype.card_ofFinset, card_Ici]
theorem card_fintypeIoi : Fintype.card (Set.Ioi a) = n - 1 - a := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ Fintype.card ↑(Set.Ioi a) = n - 1 - ↑a

Next tactic:
rw [Fintype.card_ofFinset, card_Ioi]
theorem card_fintypeIic : Fintype.card (Set.Iic b) = b + 1 := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ Fintype.card ↑(Set.Iic b) = ↑b + 1

Next tactic:
rw [Fintype.card_ofFinset, card_Iic]
theorem card_fintypeIio : Fintype.card (Set.Iio b) = b := by
  

Proof state:
n : ℕ
a b : Fin n
⊢ Fintype.card ↑(Set.Iio b) = ↑b

Next tactic:
rw [Fintype.card_ofFinset, card_Iio]
/-- If `x` and `y` are on the same ray, then the triangle inequality becomes the equality: the norm
of `x + y` is the sum of the norms of `x` and `y`. The converse is true for a strictly convex
space. -/
theorem norm_add (h : SameRay ℝ x y) : ‖x + y‖ = ‖x‖ + ‖y‖ := by
  

Proof state:
E : Type u_1
inst✝³ : SeminormedAddCommGroup E
inst✝² : NormedSpace ℝ E
F : Type u_2
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace ℝ F
x y : E
h : SameRay ℝ x y
⊢ ‖x + y‖ = ‖x‖ + ‖y‖

Next tactic:
rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩
/-- If `x` and `y` are on the same ray, then the triangle inequality becomes the equality: the norm
of `x + y` is the sum of the norms of `x` and `y`. The converse is true for a strictly convex
space. -/
theorem norm_add (h : SameRay ℝ x y) : ‖x + y‖ = ‖x‖ + ‖y‖ := by
  rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩
  

Proof state:
case intro.intro.intro.intro.intro.intro.intro
E : Type u_1
inst✝³ : SeminormedAddCommGroup E
inst✝² : NormedSpace ℝ E
F : Type u_2
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace ℝ F
u : E
a b : ℝ
ha : 0 ≤ a
hb : 0 ≤ b
h : SameRay ℝ (a • u) (b • u)
⊢ ‖a • u + b • u‖ = ‖a • u‖ + ‖b • u‖

Next tactic:
rw [← add_smul, norm_smul_of_nonneg (add_nonneg ha hb), norm_smul_of_nonneg ha,
    norm_smul_of_nonneg hb, add_mul]
theorem norm_sub (h : SameRay ℝ x y) : ‖x - y‖ = |‖x‖ - ‖y‖| := by
  

Proof state:
E : Type u_1
inst✝³ : SeminormedAddCommGroup E
inst✝² : NormedSpace ℝ E
F : Type u_2
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace ℝ F
x y : E
h : SameRay ℝ x y
⊢ ‖x - y‖ = |‖x‖ - ‖y‖|

Next tactic:
rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩
theorem norm_sub (h : SameRay ℝ x y) : ‖x - y‖ = |‖x‖ - ‖y‖| := by
  rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩
  

Proof state:
case intro.intro.intro.intro.intro.intro.intro
E : Type u_1
inst✝³ : SeminormedAddCommGroup E
inst✝² : NormedSpace ℝ E
F : Type u_2
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace ℝ F
u : E
a b : ℝ
ha : 0 ≤ a
hb : 0 ≤ b
h : SameRay ℝ (a • u) (b • u)
⊢ ‖a • u - b • u‖ = |‖a • u‖ - ‖b • u‖|

Next tactic:
wlog hab : b ≤ a generalizing a b with H
theorem norm_sub (h : SameRay ℝ x y) : ‖x - y‖ = |‖x‖ - ‖y‖| := by
  rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩
  wlog hab : b ≤ a generalizing a b with H
  · 

Proof state:
case intro.intro.intro.intro.intro.intro.intro.inr
E : Type u_1
inst✝³ : SeminormedAddCommGroup E
inst✝² : NormedSpace ℝ E
F : Type u_2
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace ℝ F
u : E
a b : ℝ
ha : 0 ≤ a
hb : 0 ≤ b
h : SameRay ℝ (a • u) (b • u)
H : ∀ (a b : ℝ), 0 ≤ a → 0 ≤ b → SameRay ℝ (a • u) (b • u) → b ≤ a → ‖a • u - b • u‖ = |‖a • u‖ - ‖b • u‖|
hab : ¬b ≤ a
⊢ ‖a • u - b • u‖ = |‖a • u‖ - ‖b • u‖|

Next tactic:
rw [SameRay.sameRay_comm] at h
theorem norm_sub (h : SameRay ℝ x y) : ‖x - y‖ = |‖x‖ - ‖y‖| := by
  rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩
  wlog hab : b ≤ a generalizing a b with H
  · rw [SameRay.sameRay_comm] at h
    

Proof state:
case intro.intro.intro.intro.intro.intro.intro.inr
E : Type u_1
inst✝³ : SeminormedAddCommGroup E
inst✝² : NormedSpace ℝ E
F : Type u_2
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace ℝ F
u : E
a b : ℝ
ha : 0 ≤ a
hb : 0 ≤ b
h : SameRay ℝ (b • u) (a • u)
H : ∀ (a b : ℝ), 0 ≤ a → 0 ≤ b → SameRay ℝ (a • u) (b • u) → b ≤ a → ‖a • u - b • u‖ = |‖a • u‖ - ‖b • u‖|
hab : ¬b ≤ a
⊢ ‖a • u - b • u‖ = |‖a • u‖ - ‖b • u‖|

Next tactic:
rw [norm_sub_rev, abs_sub_comm]