l3lab/ntp-mathlib huggingface dataset:
theorem eq_σ_comp_of_not_injective {n : ℕ} {Δ' : SimplexCategory} (θ : mk (n + 1) ⟶ Δ')
    (hθ : ¬Function.Injective θ.toOrderHom) :
    ∃ (i : Fin (n + 1)) (θ' : mk n ⟶ Δ'), θ = σ i ≫ θ' := by
  simp only [Function.Injective, exists_prop, not_forall] at hθ
  -- as θ is not injective, there exists `x<y` such that `θ x = θ y`
  -- and then, `θ x = θ (x+1)`
  have hθ₂ : ∃ x y : Fin (n + 2), (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) y ∧ x < y := by
    rcases hθ with ⟨x, y, ⟨h₁, h₂⟩⟩
    by_cases h : x < y
    · exact ⟨x, y, ⟨h₁, h⟩⟩
    · refine' ⟨y, x, ⟨h₁.symm, _⟩⟩
      rcases lt_or_eq_of_le (not_lt.mp h) with h' | h'
      · exact h'
      · exfalso
        exact h₂ h'.symm
  rcases hθ₂ with ⟨x, y, ⟨h₁, h₂⟩⟩
  let z := x.castPred
  use z
  rw [← show Fin.castSucc z = x from
    Fin.castSucc_castPred (lt_of_lt_of_le h₂ (Fin.le_last y))] at h₁ h₂
  

Proof state:
case h
n : ℕ
Δ' : SimplexCategory
θ : [n + 1] ⟶ Δ'
hθ : ∃ x x_1, (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) x_1 ∧ ¬x = x_1
x y : Fin (n + 2)
z : Fin (n + 1) := Fin.castPred x
h₂ : Fin.castSucc z < y
h₁ : (Hom.toOrderHom θ) (Fin.castSucc z) = (Hom.toOrderHom θ) y
⊢ ∃ θ', θ = σ z ≫ θ'

Next tactic:
apply eq_σ_comp_of_not_injective'
theorem eq_σ_comp_of_not_injective {n : ℕ} {Δ' : SimplexCategory} (θ : mk (n + 1) ⟶ Δ')
    (hθ : ¬Function.Injective θ.toOrderHom) :
    ∃ (i : Fin (n + 1)) (θ' : mk n ⟶ Δ'), θ = σ i ≫ θ' := by
  simp only [Function.Injective, exists_prop, not_forall] at hθ
  -- as θ is not injective, there exists `x<y` such that `θ x = θ y`
  -- and then, `θ x = θ (x+1)`
  have hθ₂ : ∃ x y : Fin (n + 2), (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) y ∧ x < y := by
    rcases hθ with ⟨x, y, ⟨h₁, h₂⟩⟩
    by_cases h : x < y
    · exact ⟨x, y, ⟨h₁, h⟩⟩
    · refine' ⟨y, x, ⟨h₁.symm, _⟩⟩
      rcases lt_or_eq_of_le (not_lt.mp h) with h' | h'
      · exact h'
      · exfalso
        exact h₂ h'.symm
  rcases hθ₂ with ⟨x, y, ⟨h₁, h₂⟩⟩
  let z := x.castPred
  use z
  rw [← show Fin.castSucc z = x from
    Fin.castSucc_castPred (lt_of_lt_of_le h₂ (Fin.le_last y))] at h₁ h₂
  apply eq_σ_comp_of_not_injective'
  

Proof state:
case h.hi
n : ℕ
Δ' : SimplexCategory
θ : [n + 1] ⟶ Δ'
hθ : ∃ x x_1, (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) x_1 ∧ ¬x = x_1
x y : Fin (n + 2)
z : Fin (n + 1) := Fin.castPred x
h₂ : Fin.castSucc z < y
h₁ : (Hom.toOrderHom θ) (Fin.castSucc z) = (Hom.toOrderHom θ) y
⊢ (Hom.toOrderHom θ) (Fin.castSucc z) = (Hom.toOrderHom θ) (Fin.succ z)

Next tactic:
rw [Fin.castSucc_lt_iff_succ_le] at h₂
theorem eq_σ_comp_of_not_injective {n : ℕ} {Δ' : SimplexCategory} (θ : mk (n + 1) ⟶ Δ')
    (hθ : ¬Function.Injective θ.toOrderHom) :
    ∃ (i : Fin (n + 1)) (θ' : mk n ⟶ Δ'), θ = σ i ≫ θ' := by
  simp only [Function.Injective, exists_prop, not_forall] at hθ
  -- as θ is not injective, there exists `x<y` such that `θ x = θ y`
  -- and then, `θ x = θ (x+1)`
  have hθ₂ : ∃ x y : Fin (n + 2), (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) y ∧ x < y := by
    rcases hθ with ⟨x, y, ⟨h₁, h₂⟩⟩
    by_cases h : x < y
    · exact ⟨x, y, ⟨h₁, h⟩⟩
    · refine' ⟨y, x, ⟨h₁.symm, _⟩⟩
      rcases lt_or_eq_of_le (not_lt.mp h) with h' | h'
      · exact h'
      · exfalso
        exact h₂ h'.symm
  rcases hθ₂ with ⟨x, y, ⟨h₁, h₂⟩⟩
  let z := x.castPred
  use z
  rw [← show Fin.castSucc z = x from
    Fin.castSucc_castPred (lt_of_lt_of_le h₂ (Fin.le_last y))] at h₁ h₂
  apply eq_σ_comp_of_not_injective'
  rw [Fin.castSucc_lt_iff_succ_le] at h₂
  

Proof state:
case h.hi
n : ℕ
Δ' : SimplexCategory
θ : [n + 1] ⟶ Δ'
hθ : ∃ x x_1, (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) x_1 ∧ ¬x = x_1
x y : Fin (n + 2)
z : Fin (n + 1) := Fin.castPred x
h₂ : Fin.succ z ≤ y
h₁ : (Hom.toOrderHom θ) (Fin.castSucc z) = (Hom.toOrderHom θ) y
⊢ (Hom.toOrderHom θ) (Fin.castSucc z) = (Hom.toOrderHom θ) (Fin.succ z)

Next tactic:
apply le_antisymm
theorem eq_σ_comp_of_not_injective {n : ℕ} {Δ' : SimplexCategory} (θ : mk (n + 1) ⟶ Δ')
    (hθ : ¬Function.Injective θ.toOrderHom) :
    ∃ (i : Fin (n + 1)) (θ' : mk n ⟶ Δ'), θ = σ i ≫ θ' := by
  simp only [Function.Injective, exists_prop, not_forall] at hθ
  -- as θ is not injective, there exists `x<y` such that `θ x = θ y`
  -- and then, `θ x = θ (x+1)`
  have hθ₂ : ∃ x y : Fin (n + 2), (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) y ∧ x < y := by
    rcases hθ with ⟨x, y, ⟨h₁, h₂⟩⟩
    by_cases h : x < y
    · exact ⟨x, y, ⟨h₁, h⟩⟩
    · refine' ⟨y, x, ⟨h₁.symm, _⟩⟩
      rcases lt_or_eq_of_le (not_lt.mp h) with h' | h'
      · exact h'
      · exfalso
        exact h₂ h'.symm
  rcases hθ₂ with ⟨x, y, ⟨h₁, h₂⟩⟩
  let z := x.castPred
  use z
  rw [← show Fin.castSucc z = x from
    Fin.castSucc_castPred (lt_of_lt_of_le h₂ (Fin.le_last y))] at h₁ h₂
  apply eq_σ_comp_of_not_injective'
  rw [Fin.castSucc_lt_iff_succ_le] at h₂
  apply le_antisymm
  · 

Proof state:
case h.hi.a
n : ℕ
Δ' : SimplexCategory
θ : [n + 1] ⟶ Δ'
hθ : ∃ x x_1, (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) x_1 ∧ ¬x = x_1
x y : Fin (n + 2)
z : Fin (n + 1) := Fin.castPred x
h₂ : Fin.succ z ≤ y
h₁ : (Hom.toOrderHom θ) (Fin.castSucc z) = (Hom.toOrderHom θ) y
⊢ (Hom.toOrderHom θ) (Fin.castSucc z) ≤ (Hom.toOrderHom θ) (Fin.succ z)

Next tactic:
exact θ.toOrderHom.monotone (le_of_lt (Fin.castSucc_lt_succ z))
theorem eq_σ_comp_of_not_injective {n : ℕ} {Δ' : SimplexCategory} (θ : mk (n + 1) ⟶ Δ')
    (hθ : ¬Function.Injective θ.toOrderHom) :
    ∃ (i : Fin (n + 1)) (θ' : mk n ⟶ Δ'), θ = σ i ≫ θ' := by
  simp only [Function.Injective, exists_prop, not_forall] at hθ
  -- as θ is not injective, there exists `x<y` such that `θ x = θ y`
  -- and then, `θ x = θ (x+1)`
  have hθ₂ : ∃ x y : Fin (n + 2), (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) y ∧ x < y := by
    rcases hθ with ⟨x, y, ⟨h₁, h₂⟩⟩
    by_cases h : x < y
    · exact ⟨x, y, ⟨h₁, h⟩⟩
    · refine' ⟨y, x, ⟨h₁.symm, _⟩⟩
      rcases lt_or_eq_of_le (not_lt.mp h) with h' | h'
      · exact h'
      · exfalso
        exact h₂ h'.symm
  rcases hθ₂ with ⟨x, y, ⟨h₁, h₂⟩⟩
  let z := x.castPred
  use z
  rw [← show Fin.castSucc z = x from
    Fin.castSucc_castPred (lt_of_lt_of_le h₂ (Fin.le_last y))] at h₁ h₂
  apply eq_σ_comp_of_not_injective'
  rw [Fin.castSucc_lt_iff_succ_le] at h₂
  apply le_antisymm
  · exact θ.toOrderHom.monotone (le_of_lt (Fin.castSucc_lt_succ z))
  · 

Proof state:
case h.hi.a
n : ℕ
Δ' : SimplexCategory
θ : [n + 1] ⟶ Δ'
hθ : ∃ x x_1, (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) x_1 ∧ ¬x = x_1
x y : Fin (n + 2)
z : Fin (n + 1) := Fin.castPred x
h₂ : Fin.succ z ≤ y
h₁ : (Hom.toOrderHom θ) (Fin.castSucc z) = (Hom.toOrderHom θ) y
⊢ (Hom.toOrderHom θ) (Fin.succ z) ≤ (Hom.toOrderHom θ) (Fin.castSucc z)

Next tactic:
rw [h₁]
theorem eq_σ_comp_of_not_injective {n : ℕ} {Δ' : SimplexCategory} (θ : mk (n + 1) ⟶ Δ')
    (hθ : ¬Function.Injective θ.toOrderHom) :
    ∃ (i : Fin (n + 1)) (θ' : mk n ⟶ Δ'), θ = σ i ≫ θ' := by
  simp only [Function.Injective, exists_prop, not_forall] at hθ
  -- as θ is not injective, there exists `x<y` such that `θ x = θ y`
  -- and then, `θ x = θ (x+1)`
  have hθ₂ : ∃ x y : Fin (n + 2), (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) y ∧ x < y := by
    rcases hθ with ⟨x, y, ⟨h₁, h₂⟩⟩
    by_cases h : x < y
    · exact ⟨x, y, ⟨h₁, h⟩⟩
    · refine' ⟨y, x, ⟨h₁.symm, _⟩⟩
      rcases lt_or_eq_of_le (not_lt.mp h) with h' | h'
      · exact h'
      · exfalso
        exact h₂ h'.symm
  rcases hθ₂ with ⟨x, y, ⟨h₁, h₂⟩⟩
  let z := x.castPred
  use z
  rw [← show Fin.castSucc z = x from
    Fin.castSucc_castPred (lt_of_lt_of_le h₂ (Fin.le_last y))] at h₁ h₂
  apply eq_σ_comp_of_not_injective'
  rw [Fin.castSucc_lt_iff_succ_le] at h₂
  apply le_antisymm
  · exact θ.toOrderHom.monotone (le_of_lt (Fin.castSucc_lt_succ z))
  · rw [h₁]
    

Proof state:
case h.hi.a
n : ℕ
Δ' : SimplexCategory
θ : [n + 1] ⟶ Δ'
hθ : ∃ x x_1, (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) x_1 ∧ ¬x = x_1
x y : Fin (n + 2)
z : Fin (n + 1) := Fin.castPred x
h₂ : Fin.succ z ≤ y
h₁ : (Hom.toOrderHom θ) (Fin.castSucc z) = (Hom.toOrderHom θ) y
⊢ (Hom.toOrderHom θ) (Fin.succ z) ≤ (Hom.toOrderHom θ) y

Next tactic:
exact θ.toOrderHom.monotone h₂
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  

Proof state:
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
⊢ ∃ θ', θ = θ' ≫ δ i

Next tactic:
by_cases h : i < Fin.last (n + 1)
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · 

Proof state:
case pos
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
⊢ ∃ θ', θ = θ' ≫ δ i

Next tactic:
use θ ≫ σ (Fin.castPred i)
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    

Proof state:
case h
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
⊢ θ = (θ ≫ σ (Fin.castPred i)) ≫ δ i

Next tactic:
ext1
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    

Proof state:
case h.a
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
⊢ Hom.toOrderHom θ = Hom.toOrderHom ((θ ≫ σ (Fin.castPred i)) ≫ δ i)

Next tactic:
ext1
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    

Proof state:
case h.a.h
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
⊢ ⇑(Hom.toOrderHom θ) = ⇑(Hom.toOrderHom ((θ ≫ σ (Fin.castPred i)) ≫ δ i))

Next tactic:
ext1 x
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    

Proof state:
case h.a.h.h
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
⊢ (Hom.toOrderHom θ) x = (Hom.toOrderHom ((θ ≫ σ (Fin.castPred i)) ≫ δ i)) x

Next tactic:
simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
    

Proof state:
case h.a.h.h
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
⊢ (Hom.toOrderHom θ) x = (Hom.toOrderHom (δ i)) ((Hom.toOrderHom (σ (Fin.castPred i))) ((Hom.toOrderHom θ) x))

Next tactic:
by_cases h' : θ.toOrderHom x ≤ i
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
    by_cases h' : θ.toOrderHom x ≤ i
    · 

Proof state:
case pos
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
h' : (Hom.toOrderHom θ) x ≤ i
⊢ (Hom.toOrderHom θ) x = (Hom.toOrderHom (δ i)) ((Hom.toOrderHom (σ (Fin.castPred i))) ((Hom.toOrderHom θ) x))

Next tactic:
simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk]
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
    by_cases h' : θ.toOrderHom x ≤ i
    · simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk]
      -- This was not needed before leanprover/lean4#2644
      

Proof state:
case pos
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
h' : (Hom.toOrderHom θ) x ≤ i
⊢ (Hom.toOrderHom θ) x =
    (Hom.toOrderHom (δ i))
      ({ toFun := Fin.predAbove (Fin.castPred i), monotone' := (_ : Monotone (Fin.predAbove (Fin.castPred i))) }
        ((Hom.toOrderHom θ) x))

Next tactic:
dsimp
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
    by_cases h' : θ.toOrderHom x ≤ i
    · simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk]
      -- This was not needed before leanprover/lean4#2644
      dsimp
      -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
      

Proof state:
case pos
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
h' : (Hom.toOrderHom θ) x ≤ i
⊢ (Hom.toOrderHom θ) x = (Hom.toOrderHom (δ i)) (Fin.predAbove (Fin.castPred i) ((Hom.toOrderHom θ) x))

Next tactic:
erw [Fin.predAbove_below (Fin.castPred i) (θ.toOrderHom x)
          (by simpa [Fin.castSucc_castPred h] using h')]
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
    by_cases h' : θ.toOrderHom x ≤ i
    · simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk]
      -- This was not needed before leanprover/lean4#2644
      dsimp
      -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
      erw [Fin.predAbove_below (Fin.castPred i) (θ.toOrderHom x)
          (by 

Proof state:
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
h' : (Hom.toOrderHom θ) x ≤ i
⊢ (Hom.toOrderHom θ) x ≤ Fin.castSucc (Fin.castPred i)

Next tactic:
simpa [Fin.castSucc_castPred h] using h'
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
    by_cases h' : θ.toOrderHom x ≤ i
    · simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk]
      -- This was not needed before leanprover/lean4#2644
      dsimp
      -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
      erw [Fin.predAbove_below (Fin.castPred i) (θ.toOrderHom x)
          (by simpa [Fin.castSucc_castPred h] using h')]
      

Proof state:
case pos
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
h' : (Hom.toOrderHom θ) x ≤ i
⊢ (Hom.toOrderHom θ) x = (Hom.toOrderHom (δ i)) (Fin.castPred ((Hom.toOrderHom θ) x))

Next tactic:
dsimp [δ]
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
    by_cases h' : θ.toOrderHom x ≤ i
    · simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk]
      -- This was not needed before leanprover/lean4#2644
      dsimp
      -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
      erw [Fin.predAbove_below (Fin.castPred i) (θ.toOrderHom x)
          (by simpa [Fin.castSucc_castPred h] using h')]
      dsimp [δ]
      

Proof state:
case pos
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
h' : (Hom.toOrderHom θ) x ≤ i
⊢ (Hom.toOrderHom θ) x = Fin.succAbove i (Fin.castPred ((Hom.toOrderHom θ) x))

Next tactic:
erw [Fin.succAbove_below i]
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
    by_cases h' : θ.toOrderHom x ≤ i
    · simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk]
      -- This was not needed before leanprover/lean4#2644
      dsimp
      -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
      erw [Fin.predAbove_below (Fin.castPred i) (θ.toOrderHom x)
          (by simpa [Fin.castSucc_castPred h] using h')]
      dsimp [δ]
      erw [Fin.succAbove_below i]
      

Proof state:
case pos
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
h' : (Hom.toOrderHom θ) x ≤ i
⊢ (Hom.toOrderHom θ) x = Fin.castSucc (Fin.castPred ((Hom.toOrderHom θ) x))
case pos.h
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
h' : (Hom.toOrderHom θ) x ≤ i
⊢ Fin.castSucc (Fin.castPred ((Hom.toOrderHom θ) x)) < i

Next tactic:
swap
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
    by_cases h' : θ.toOrderHom x ≤ i
    · simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk]
      -- This was not needed before leanprover/lean4#2644
      dsimp
      -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
      erw [Fin.predAbove_below (Fin.castPred i) (θ.toOrderHom x)
          (by simpa [Fin.castSucc_castPred h] using h')]
      dsimp [δ]
      erw [Fin.succAbove_below i]
      swap
      · 

Proof state:
case pos.h
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
h' : (Hom.toOrderHom θ) x ≤ i
⊢ Fin.castSucc (Fin.castPred ((Hom.toOrderHom θ) x)) < i

Next tactic:
simp only [Fin.lt_iff_val_lt_val, Fin.coe_castSucc]
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
    by_cases h' : θ.toOrderHom x ≤ i
    · simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk]
      -- This was not needed before leanprover/lean4#2644
      dsimp
      -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
      erw [Fin.predAbove_below (Fin.castPred i) (θ.toOrderHom x)
          (by simpa [Fin.castSucc_castPred h] using h')]
      dsimp [δ]
      erw [Fin.succAbove_below i]
      swap
      · simp only [Fin.lt_iff_val_lt_val, Fin.coe_castSucc]
        

Proof state:
case pos.h
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
h' : (Hom.toOrderHom θ) x ≤ i
⊢ ↑(Fin.castPred ((Hom.toOrderHom θ) x)) < ↑i

Next tactic:
exact
          lt_of_le_of_lt (Fin.coe_castPred_le_self _)
            (Fin.lt_iff_val_lt_val.mp ((Ne.le_iff_lt (hi x)).mp h'))
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
    by_cases h' : θ.toOrderHom x ≤ i
    · simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk]
      -- This was not needed before leanprover/lean4#2644
      dsimp
      -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
      erw [Fin.predAbove_below (Fin.castPred i) (θ.toOrderHom x)
          (by simpa [Fin.castSucc_castPred h] using h')]
      dsimp [δ]
      erw [Fin.succAbove_below i]
      swap
      · simp only [Fin.lt_iff_val_lt_val, Fin.coe_castSucc]
        exact
          lt_of_le_of_lt (Fin.coe_castPred_le_self _)
            (Fin.lt_iff_val_lt_val.mp ((Ne.le_iff_lt (hi x)).mp h'))
      

Proof state:
case pos
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
h' : (Hom.toOrderHom θ) x ≤ i
⊢ (Hom.toOrderHom θ) x = Fin.castSucc (Fin.castPred ((Hom.toOrderHom θ) x))

Next tactic:
rw [Fin.castSucc_castPred]
theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1))
    (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by
  by_cases h : i < Fin.last (n + 1)
  · use θ ≫ σ (Fin.castPred i)
    ext1
    ext1
    ext1 x
    simp only [Hom.toOrderHom_mk, Function.comp_apply, OrderHom.comp_coe, Hom.comp,
      smallCategory_comp]
    by_cases h' : θ.toOrderHom x ≤ i
    · simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk]
      -- This was not needed before leanprover/lean4#2644
      dsimp
      -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
      erw [Fin.predAbove_below (Fin.castPred i) (θ.toOrderHom x)
          (by simpa [Fin.castSucc_castPred h] using h')]
      dsimp [δ]
      erw [Fin.succAbove_below i]
      swap
      · simp only [Fin.lt_iff_val_lt_val, Fin.coe_castSucc]
        exact
          lt_of_le_of_lt (Fin.coe_castPred_le_self _)
            (Fin.lt_iff_val_lt_val.mp ((Ne.le_iff_lt (hi x)).mp h'))
      rw [Fin.castSucc_castPred]
      

Proof state:
case pos
n : ℕ
Δ : SimplexCategory
θ : Δ ⟶ [n + 1]
i : Fin (n + 2)
hi : ∀ (x : Fin (len Δ + 1)), (Hom.toOrderHom θ) x ≠ i
h : i < Fin.last (n + 1)
x : Fin (len Δ + 1)
h' : (Hom.toOrderHom θ) x ≤ i
⊢ (Hom.toOrderHom θ) x < Fin.last (n + 1)

Next tactic:
apply lt_of_le_of_lt h' h