l3lab/ntp-mathlib huggingface dataset:
theorem exists_locallyConstant_finite_aux {α : Type*} [Finite α] (hC : IsLimit C)
    (f : LocallyConstant C.pt α) : ∃ (j : J) (g : LocallyConstant (F.obj j) (α → Fin 2)),
      (f.map fun a b => if a = b then (0 : Fin 2) else 1) = g.comap (C.π.app _) := by
  cases nonempty_fintype α
  let ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
  let ff := (f.map ι).flip
  have hff := fun a : α => exists_locallyConstant_fin_two _ hC (ff a)
  choose j g h using hff
  let G : Finset J := Finset.univ.image j
  obtain ⟨j0, hj0⟩ := IsCofiltered.inf_objs_exists G
  have hj : ∀ a, j a ∈ (Finset.univ.image j : Finset J) := by
    intro a
    simp only [Finset.mem_image, Finset.mem_univ, true_and, exists_apply_eq_apply]
  let fs : ∀ a : α, j0 ⟶ j a := fun a => (hj0 (hj a)).some
  let gg : α → LocallyConstant (F.obj j0) (Fin 2) := fun a => (g a).comap (F.map (fs _))
  let ggg := LocallyConstant.unflip gg
  refine' ⟨j0, ggg, _⟩
  have : f.map ι = LocallyConstant.unflip (f.map ι).flip := by simp
  rw [this]; clear this
  have :
    LocallyConstant.comap (C.π.app j0) ggg =
      LocallyConstant.unflip (LocallyConstant.comap (C.π.app j0) ggg).flip :=
    by simp
  rw [this]; clear this
  congr 1
  ext1 a
  

Proof state:
case intro.intro.e_f.h
J : Type v
inst✝² : SmallCategory J
inst✝¹ : IsCofiltered J
F : J ⥤ ProfiniteMax
C : Cone F
α : Type u_1
inst✝ : Finite α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toCompHaus.toTop) α
val✝ : Fintype α
ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
ff : α → LocallyConstant (↑C.pt.toCompHaus.toTop) (Fin 2) := LocallyConstant.flip (LocallyConstant.map ι f)
j : α → J
g : (a : α) → LocallyConstant (↑(F.obj (j a)).toCompHaus.toTop) (Fin 2)
h : ∀ (a : α), ff a = LocallyConstant.comap (⇑(C.π.app (j a))) (g a)
G : Finset J := Finset.image j Finset.univ
j0 : J
hj0 : ∀ {X : J}, X ∈ G → Nonempty (j0 ⟶ X)
hj : ∀ (a : α), j a ∈ Finset.image j Finset.univ
fs : (a : α) → j0 ⟶ j a := fun a => Nonempty.some (_ : Nonempty (j0 ⟶ j a))
gg : α → LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (Fin 2) :=
  fun a => LocallyConstant.comap (⇑(F.map (fs a))) (g a)
ggg : LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (α → Fin 2) := LocallyConstant.unflip gg
a : α
⊢ LocallyConstant.flip (LocallyConstant.map ι f) a = LocallyConstant.flip (LocallyConstant.comap (⇑(C.π.app j0)) ggg) a

Next tactic:
change ff a = _
theorem exists_locallyConstant_finite_aux {α : Type*} [Finite α] (hC : IsLimit C)
    (f : LocallyConstant C.pt α) : ∃ (j : J) (g : LocallyConstant (F.obj j) (α → Fin 2)),
      (f.map fun a b => if a = b then (0 : Fin 2) else 1) = g.comap (C.π.app _) := by
  cases nonempty_fintype α
  let ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
  let ff := (f.map ι).flip
  have hff := fun a : α => exists_locallyConstant_fin_two _ hC (ff a)
  choose j g h using hff
  let G : Finset J := Finset.univ.image j
  obtain ⟨j0, hj0⟩ := IsCofiltered.inf_objs_exists G
  have hj : ∀ a, j a ∈ (Finset.univ.image j : Finset J) := by
    intro a
    simp only [Finset.mem_image, Finset.mem_univ, true_and, exists_apply_eq_apply]
  let fs : ∀ a : α, j0 ⟶ j a := fun a => (hj0 (hj a)).some
  let gg : α → LocallyConstant (F.obj j0) (Fin 2) := fun a => (g a).comap (F.map (fs _))
  let ggg := LocallyConstant.unflip gg
  refine' ⟨j0, ggg, _⟩
  have : f.map ι = LocallyConstant.unflip (f.map ι).flip := by simp
  rw [this]; clear this
  have :
    LocallyConstant.comap (C.π.app j0) ggg =
      LocallyConstant.unflip (LocallyConstant.comap (C.π.app j0) ggg).flip :=
    by simp
  rw [this]; clear this
  congr 1
  ext1 a
  change ff a = _
  

Proof state:
case intro.intro.e_f.h
J : Type v
inst✝² : SmallCategory J
inst✝¹ : IsCofiltered J
F : J ⥤ ProfiniteMax
C : Cone F
α : Type u_1
inst✝ : Finite α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toCompHaus.toTop) α
val✝ : Fintype α
ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
ff : α → LocallyConstant (↑C.pt.toCompHaus.toTop) (Fin 2) := LocallyConstant.flip (LocallyConstant.map ι f)
j : α → J
g : (a : α) → LocallyConstant (↑(F.obj (j a)).toCompHaus.toTop) (Fin 2)
h : ∀ (a : α), ff a = LocallyConstant.comap (⇑(C.π.app (j a))) (g a)
G : Finset J := Finset.image j Finset.univ
j0 : J
hj0 : ∀ {X : J}, X ∈ G → Nonempty (j0 ⟶ X)
hj : ∀ (a : α), j a ∈ Finset.image j Finset.univ
fs : (a : α) → j0 ⟶ j a := fun a => Nonempty.some (_ : Nonempty (j0 ⟶ j a))
gg : α → LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (Fin 2) :=
  fun a => LocallyConstant.comap (⇑(F.map (fs a))) (g a)
ggg : LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (α → Fin 2) := LocallyConstant.unflip gg
a : α
⊢ ff a = LocallyConstant.flip (LocallyConstant.comap (⇑(C.π.app j0)) ggg) a

Next tactic:
rw [h]
theorem exists_locallyConstant_finite_aux {α : Type*} [Finite α] (hC : IsLimit C)
    (f : LocallyConstant C.pt α) : ∃ (j : J) (g : LocallyConstant (F.obj j) (α → Fin 2)),
      (f.map fun a b => if a = b then (0 : Fin 2) else 1) = g.comap (C.π.app _) := by
  cases nonempty_fintype α
  let ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
  let ff := (f.map ι).flip
  have hff := fun a : α => exists_locallyConstant_fin_two _ hC (ff a)
  choose j g h using hff
  let G : Finset J := Finset.univ.image j
  obtain ⟨j0, hj0⟩ := IsCofiltered.inf_objs_exists G
  have hj : ∀ a, j a ∈ (Finset.univ.image j : Finset J) := by
    intro a
    simp only [Finset.mem_image, Finset.mem_univ, true_and, exists_apply_eq_apply]
  let fs : ∀ a : α, j0 ⟶ j a := fun a => (hj0 (hj a)).some
  let gg : α → LocallyConstant (F.obj j0) (Fin 2) := fun a => (g a).comap (F.map (fs _))
  let ggg := LocallyConstant.unflip gg
  refine' ⟨j0, ggg, _⟩
  have : f.map ι = LocallyConstant.unflip (f.map ι).flip := by simp
  rw [this]; clear this
  have :
    LocallyConstant.comap (C.π.app j0) ggg =
      LocallyConstant.unflip (LocallyConstant.comap (C.π.app j0) ggg).flip :=
    by simp
  rw [this]; clear this
  congr 1
  ext1 a
  change ff a = _
  rw [h]
  

Proof state:
case intro.intro.e_f.h
J : Type v
inst✝² : SmallCategory J
inst✝¹ : IsCofiltered J
F : J ⥤ ProfiniteMax
C : Cone F
α : Type u_1
inst✝ : Finite α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toCompHaus.toTop) α
val✝ : Fintype α
ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
ff : α → LocallyConstant (↑C.pt.toCompHaus.toTop) (Fin 2) := LocallyConstant.flip (LocallyConstant.map ι f)
j : α → J
g : (a : α) → LocallyConstant (↑(F.obj (j a)).toCompHaus.toTop) (Fin 2)
h : ∀ (a : α), ff a = LocallyConstant.comap (⇑(C.π.app (j a))) (g a)
G : Finset J := Finset.image j Finset.univ
j0 : J
hj0 : ∀ {X : J}, X ∈ G → Nonempty (j0 ⟶ X)
hj : ∀ (a : α), j a ∈ Finset.image j Finset.univ
fs : (a : α) → j0 ⟶ j a := fun a => Nonempty.some (_ : Nonempty (j0 ⟶ j a))
gg : α → LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (Fin 2) :=
  fun a => LocallyConstant.comap (⇑(F.map (fs a))) (g a)
ggg : LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (α → Fin 2) := LocallyConstant.unflip gg
a : α
⊢ LocallyConstant.comap (⇑(C.π.app (j a))) (g a) = LocallyConstant.flip (LocallyConstant.comap (⇑(C.π.app j0)) ggg) a

Next tactic:
dsimp
theorem exists_locallyConstant_finite_aux {α : Type*} [Finite α] (hC : IsLimit C)
    (f : LocallyConstant C.pt α) : ∃ (j : J) (g : LocallyConstant (F.obj j) (α → Fin 2)),
      (f.map fun a b => if a = b then (0 : Fin 2) else 1) = g.comap (C.π.app _) := by
  cases nonempty_fintype α
  let ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
  let ff := (f.map ι).flip
  have hff := fun a : α => exists_locallyConstant_fin_two _ hC (ff a)
  choose j g h using hff
  let G : Finset J := Finset.univ.image j
  obtain ⟨j0, hj0⟩ := IsCofiltered.inf_objs_exists G
  have hj : ∀ a, j a ∈ (Finset.univ.image j : Finset J) := by
    intro a
    simp only [Finset.mem_image, Finset.mem_univ, true_and, exists_apply_eq_apply]
  let fs : ∀ a : α, j0 ⟶ j a := fun a => (hj0 (hj a)).some
  let gg : α → LocallyConstant (F.obj j0) (Fin 2) := fun a => (g a).comap (F.map (fs _))
  let ggg := LocallyConstant.unflip gg
  refine' ⟨j0, ggg, _⟩
  have : f.map ι = LocallyConstant.unflip (f.map ι).flip := by simp
  rw [this]; clear this
  have :
    LocallyConstant.comap (C.π.app j0) ggg =
      LocallyConstant.unflip (LocallyConstant.comap (C.π.app j0) ggg).flip :=
    by simp
  rw [this]; clear this
  congr 1
  ext1 a
  change ff a = _
  rw [h]
  dsimp
  

Proof state:
case intro.intro.e_f.h
J : Type v
inst✝² : SmallCategory J
inst✝¹ : IsCofiltered J
F : J ⥤ ProfiniteMax
C : Cone F
α : Type u_1
inst✝ : Finite α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toCompHaus.toTop) α
val✝ : Fintype α
ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
ff : α → LocallyConstant (↑C.pt.toCompHaus.toTop) (Fin 2) := LocallyConstant.flip (LocallyConstant.map ι f)
j : α → J
g : (a : α) → LocallyConstant (↑(F.obj (j a)).toCompHaus.toTop) (Fin 2)
h : ∀ (a : α), ff a = LocallyConstant.comap (⇑(C.π.app (j a))) (g a)
G : Finset J := Finset.image j Finset.univ
j0 : J
hj0 : ∀ {X : J}, X ∈ G → Nonempty (j0 ⟶ X)
hj : ∀ (a : α), j a ∈ Finset.image j Finset.univ
fs : (a : α) → j0 ⟶ j a := fun a => Nonempty.some (_ : Nonempty (j0 ⟶ j a))
gg : α → LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (Fin 2) :=
  fun a => LocallyConstant.comap (⇑(F.map (fs a))) (g a)
ggg : LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (α → Fin 2) := LocallyConstant.unflip gg
a : α
⊢ LocallyConstant.comap (⇑(C.π.app (j a))) (g a) =
    LocallyConstant.flip
      (LocallyConstant.comap (⇑(C.π.app j0))
        (LocallyConstant.unflip fun a =>
          LocallyConstant.comap (⇑(F.map (Nonempty.some (_ : Nonempty (j0 ⟶ j a))))) (g a)))
      a

Next tactic:
ext1 x
theorem exists_locallyConstant_finite_aux {α : Type*} [Finite α] (hC : IsLimit C)
    (f : LocallyConstant C.pt α) : ∃ (j : J) (g : LocallyConstant (F.obj j) (α → Fin 2)),
      (f.map fun a b => if a = b then (0 : Fin 2) else 1) = g.comap (C.π.app _) := by
  cases nonempty_fintype α
  let ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
  let ff := (f.map ι).flip
  have hff := fun a : α => exists_locallyConstant_fin_two _ hC (ff a)
  choose j g h using hff
  let G : Finset J := Finset.univ.image j
  obtain ⟨j0, hj0⟩ := IsCofiltered.inf_objs_exists G
  have hj : ∀ a, j a ∈ (Finset.univ.image j : Finset J) := by
    intro a
    simp only [Finset.mem_image, Finset.mem_univ, true_and, exists_apply_eq_apply]
  let fs : ∀ a : α, j0 ⟶ j a := fun a => (hj0 (hj a)).some
  let gg : α → LocallyConstant (F.obj j0) (Fin 2) := fun a => (g a).comap (F.map (fs _))
  let ggg := LocallyConstant.unflip gg
  refine' ⟨j0, ggg, _⟩
  have : f.map ι = LocallyConstant.unflip (f.map ι).flip := by simp
  rw [this]; clear this
  have :
    LocallyConstant.comap (C.π.app j0) ggg =
      LocallyConstant.unflip (LocallyConstant.comap (C.π.app j0) ggg).flip :=
    by simp
  rw [this]; clear this
  congr 1
  ext1 a
  change ff a = _
  rw [h]
  dsimp
  ext1 x
  -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
  

Proof state:
case intro.intro.e_f.h.h
J : Type v
inst✝² : SmallCategory J
inst✝¹ : IsCofiltered J
F : J ⥤ ProfiniteMax
C : Cone F
α : Type u_1
inst✝ : Finite α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toCompHaus.toTop) α
val✝ : Fintype α
ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
ff : α → LocallyConstant (↑C.pt.toCompHaus.toTop) (Fin 2) := LocallyConstant.flip (LocallyConstant.map ι f)
j : α → J
g : (a : α) → LocallyConstant (↑(F.obj (j a)).toCompHaus.toTop) (Fin 2)
h : ∀ (a : α), ff a = LocallyConstant.comap (⇑(C.π.app (j a))) (g a)
G : Finset J := Finset.image j Finset.univ
j0 : J
hj0 : ∀ {X : J}, X ∈ G → Nonempty (j0 ⟶ X)
hj : ∀ (a : α), j a ∈ Finset.image j Finset.univ
fs : (a : α) → j0 ⟶ j a := fun a => Nonempty.some (_ : Nonempty (j0 ⟶ j a))
gg : α → LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (Fin 2) :=
  fun a => LocallyConstant.comap (⇑(F.map (fs a))) (g a)
ggg : LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (α → Fin 2) := LocallyConstant.unflip gg
a : α
x : (forget ProfiniteMax).obj C.pt
⊢ (LocallyConstant.comap (⇑(C.π.app (j a))) (g a)) x =
    (LocallyConstant.flip
        (LocallyConstant.comap (⇑(C.π.app j0))
          (LocallyConstant.unflip fun a =>
            LocallyConstant.comap (⇑(F.map (Nonempty.some (_ : Nonempty (j0 ⟶ j a))))) (g a)))
        a)
      x

Next tactic:
erw [LocallyConstant.coe_comap _ _ (C.π.app (j a)).continuous]
theorem exists_locallyConstant_finite_aux {α : Type*} [Finite α] (hC : IsLimit C)
    (f : LocallyConstant C.pt α) : ∃ (j : J) (g : LocallyConstant (F.obj j) (α → Fin 2)),
      (f.map fun a b => if a = b then (0 : Fin 2) else 1) = g.comap (C.π.app _) := by
  cases nonempty_fintype α
  let ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
  let ff := (f.map ι).flip
  have hff := fun a : α => exists_locallyConstant_fin_two _ hC (ff a)
  choose j g h using hff
  let G : Finset J := Finset.univ.image j
  obtain ⟨j0, hj0⟩ := IsCofiltered.inf_objs_exists G
  have hj : ∀ a, j a ∈ (Finset.univ.image j : Finset J) := by
    intro a
    simp only [Finset.mem_image, Finset.mem_univ, true_and, exists_apply_eq_apply]
  let fs : ∀ a : α, j0 ⟶ j a := fun a => (hj0 (hj a)).some
  let gg : α → LocallyConstant (F.obj j0) (Fin 2) := fun a => (g a).comap (F.map (fs _))
  let ggg := LocallyConstant.unflip gg
  refine' ⟨j0, ggg, _⟩
  have : f.map ι = LocallyConstant.unflip (f.map ι).flip := by simp
  rw [this]; clear this
  have :
    LocallyConstant.comap (C.π.app j0) ggg =
      LocallyConstant.unflip (LocallyConstant.comap (C.π.app j0) ggg).flip :=
    by simp
  rw [this]; clear this
  congr 1
  ext1 a
  change ff a = _
  rw [h]
  dsimp
  ext1 x
  -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
  erw [LocallyConstant.coe_comap _ _ (C.π.app (j a)).continuous]
  

Proof state:
case intro.intro.e_f.h.h
J : Type v
inst✝² : SmallCategory J
inst✝¹ : IsCofiltered J
F : J ⥤ ProfiniteMax
C : Cone F
α : Type u_1
inst✝ : Finite α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toCompHaus.toTop) α
val✝ : Fintype α
ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
ff : α → LocallyConstant (↑C.pt.toCompHaus.toTop) (Fin 2) := LocallyConstant.flip (LocallyConstant.map ι f)
j : α → J
g : (a : α) → LocallyConstant (↑(F.obj (j a)).toCompHaus.toTop) (Fin 2)
h : ∀ (a : α), ff a = LocallyConstant.comap (⇑(C.π.app (j a))) (g a)
G : Finset J := Finset.image j Finset.univ
j0 : J
hj0 : ∀ {X : J}, X ∈ G → Nonempty (j0 ⟶ X)
hj : ∀ (a : α), j a ∈ Finset.image j Finset.univ
fs : (a : α) → j0 ⟶ j a := fun a => Nonempty.some (_ : Nonempty (j0 ⟶ j a))
gg : α → LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (Fin 2) :=
  fun a => LocallyConstant.comap (⇑(F.map (fs a))) (g a)
ggg : LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (α → Fin 2) := LocallyConstant.unflip gg
a : α
x : (forget ProfiniteMax).obj C.pt
⊢ (⇑(g a) ∘ ⇑(C.π.app (j a))) x =
    (LocallyConstant.flip
        (LocallyConstant.comap (⇑(C.π.app j0))
          (LocallyConstant.unflip fun a =>
            LocallyConstant.comap (⇑(F.map (Nonempty.some (_ : Nonempty (j0 ⟶ j a))))) (g a)))
        a)
      x

Next tactic:
dsimp [LocallyConstant.flip, LocallyConstant.unflip]
theorem exists_locallyConstant_finite_aux {α : Type*} [Finite α] (hC : IsLimit C)
    (f : LocallyConstant C.pt α) : ∃ (j : J) (g : LocallyConstant (F.obj j) (α → Fin 2)),
      (f.map fun a b => if a = b then (0 : Fin 2) else 1) = g.comap (C.π.app _) := by
  cases nonempty_fintype α
  let ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
  let ff := (f.map ι).flip
  have hff := fun a : α => exists_locallyConstant_fin_two _ hC (ff a)
  choose j g h using hff
  let G : Finset J := Finset.univ.image j
  obtain ⟨j0, hj0⟩ := IsCofiltered.inf_objs_exists G
  have hj : ∀ a, j a ∈ (Finset.univ.image j : Finset J) := by
    intro a
    simp only [Finset.mem_image, Finset.mem_univ, true_and, exists_apply_eq_apply]
  let fs : ∀ a : α, j0 ⟶ j a := fun a => (hj0 (hj a)).some
  let gg : α → LocallyConstant (F.obj j0) (Fin 2) := fun a => (g a).comap (F.map (fs _))
  let ggg := LocallyConstant.unflip gg
  refine' ⟨j0, ggg, _⟩
  have : f.map ι = LocallyConstant.unflip (f.map ι).flip := by simp
  rw [this]; clear this
  have :
    LocallyConstant.comap (C.π.app j0) ggg =
      LocallyConstant.unflip (LocallyConstant.comap (C.π.app j0) ggg).flip :=
    by simp
  rw [this]; clear this
  congr 1
  ext1 a
  change ff a = _
  rw [h]
  dsimp
  ext1 x
  -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
  erw [LocallyConstant.coe_comap _ _ (C.π.app (j a)).continuous]
  dsimp [LocallyConstant.flip, LocallyConstant.unflip]
  -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
  

Proof state:
case intro.intro.e_f.h.h
J : Type v
inst✝² : SmallCategory J
inst✝¹ : IsCofiltered J
F : J ⥤ ProfiniteMax
C : Cone F
α : Type u_1
inst✝ : Finite α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toCompHaus.toTop) α
val✝ : Fintype α
ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
ff : α → LocallyConstant (↑C.pt.toCompHaus.toTop) (Fin 2) := LocallyConstant.flip (LocallyConstant.map ι f)
j : α → J
g : (a : α) → LocallyConstant (↑(F.obj (j a)).toCompHaus.toTop) (Fin 2)
h : ∀ (a : α), ff a = LocallyConstant.comap (⇑(C.π.app (j a))) (g a)
G : Finset J := Finset.image j Finset.univ
j0 : J
hj0 : ∀ {X : J}, X ∈ G → Nonempty (j0 ⟶ X)
hj : ∀ (a : α), j a ∈ Finset.image j Finset.univ
fs : (a : α) → j0 ⟶ j a := fun a => Nonempty.some (_ : Nonempty (j0 ⟶ j a))
gg : α → LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (Fin 2) :=
  fun a => LocallyConstant.comap (⇑(F.map (fs a))) (g a)
ggg : LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (α → Fin 2) := LocallyConstant.unflip gg
a : α
x : (forget ProfiniteMax).obj C.pt
⊢ (g a) ((C.π.app (j a)) x) =
    (LocallyConstant.comap ⇑(C.π.app j0)
        { toFun := fun x a => (LocallyConstant.comap (⇑(F.map (Nonempty.some (_ : Nonempty (j0 ⟶ j a))))) (g a)) x,
          isLocallyConstant :=
            (_ :
              IsLocallyConstant fun x a =>
                (LocallyConstant.comap (⇑(F.map (Nonempty.some (_ : Nonempty (j0 ⟶ j a))))) (g a)) x) })
      x a

Next tactic:
erw [LocallyConstant.coe_comap _ _ (C.π.app j0).continuous]
theorem exists_locallyConstant_finite_aux {α : Type*} [Finite α] (hC : IsLimit C)
    (f : LocallyConstant C.pt α) : ∃ (j : J) (g : LocallyConstant (F.obj j) (α → Fin 2)),
      (f.map fun a b => if a = b then (0 : Fin 2) else 1) = g.comap (C.π.app _) := by
  cases nonempty_fintype α
  let ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
  let ff := (f.map ι).flip
  have hff := fun a : α => exists_locallyConstant_fin_two _ hC (ff a)
  choose j g h using hff
  let G : Finset J := Finset.univ.image j
  obtain ⟨j0, hj0⟩ := IsCofiltered.inf_objs_exists G
  have hj : ∀ a, j a ∈ (Finset.univ.image j : Finset J) := by
    intro a
    simp only [Finset.mem_image, Finset.mem_univ, true_and, exists_apply_eq_apply]
  let fs : ∀ a : α, j0 ⟶ j a := fun a => (hj0 (hj a)).some
  let gg : α → LocallyConstant (F.obj j0) (Fin 2) := fun a => (g a).comap (F.map (fs _))
  let ggg := LocallyConstant.unflip gg
  refine' ⟨j0, ggg, _⟩
  have : f.map ι = LocallyConstant.unflip (f.map ι).flip := by simp
  rw [this]; clear this
  have :
    LocallyConstant.comap (C.π.app j0) ggg =
      LocallyConstant.unflip (LocallyConstant.comap (C.π.app j0) ggg).flip :=
    by simp
  rw [this]; clear this
  congr 1
  ext1 a
  change ff a = _
  rw [h]
  dsimp
  ext1 x
  -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
  erw [LocallyConstant.coe_comap _ _ (C.π.app (j a)).continuous]
  dsimp [LocallyConstant.flip, LocallyConstant.unflip]
  -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
  erw [LocallyConstant.coe_comap _ _ (C.π.app j0).continuous]
  

Proof state:
case intro.intro.e_f.h.h
J : Type v
inst✝² : SmallCategory J
inst✝¹ : IsCofiltered J
F : J ⥤ ProfiniteMax
C : Cone F
α : Type u_1
inst✝ : Finite α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toCompHaus.toTop) α
val✝ : Fintype α
ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
ff : α → LocallyConstant (↑C.pt.toCompHaus.toTop) (Fin 2) := LocallyConstant.flip (LocallyConstant.map ι f)
j : α → J
g : (a : α) → LocallyConstant (↑(F.obj (j a)).toCompHaus.toTop) (Fin 2)
h : ∀ (a : α), ff a = LocallyConstant.comap (⇑(C.π.app (j a))) (g a)
G : Finset J := Finset.image j Finset.univ
j0 : J
hj0 : ∀ {X : J}, X ∈ G → Nonempty (j0 ⟶ X)
hj : ∀ (a : α), j a ∈ Finset.image j Finset.univ
fs : (a : α) → j0 ⟶ j a := fun a => Nonempty.some (_ : Nonempty (j0 ⟶ j a))
gg : α → LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (Fin 2) :=
  fun a => LocallyConstant.comap (⇑(F.map (fs a))) (g a)
ggg : LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (α → Fin 2) := LocallyConstant.unflip gg
a : α
x : (forget ProfiniteMax).obj C.pt
⊢ (g a) ((C.π.app (j a)) x) =
    (⇑{ toFun := fun x a => (LocallyConstant.comap (⇑(F.map (Nonempty.some (_ : Nonempty (j0 ⟶ j a))))) (g a)) x,
            isLocallyConstant :=
              (_ :
                IsLocallyConstant fun x a =>
                  (LocallyConstant.comap (⇑(F.map (Nonempty.some (_ : Nonempty (j0 ⟶ j a))))) (g a)) x) } ∘
        ⇑(C.π.app j0))
      x a

Next tactic:
dsimp
theorem exists_locallyConstant_finite_aux {α : Type*} [Finite α] (hC : IsLimit C)
    (f : LocallyConstant C.pt α) : ∃ (j : J) (g : LocallyConstant (F.obj j) (α → Fin 2)),
      (f.map fun a b => if a = b then (0 : Fin 2) else 1) = g.comap (C.π.app _) := by
  cases nonempty_fintype α
  let ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
  let ff := (f.map ι).flip
  have hff := fun a : α => exists_locallyConstant_fin_two _ hC (ff a)
  choose j g h using hff
  let G : Finset J := Finset.univ.image j
  obtain ⟨j0, hj0⟩ := IsCofiltered.inf_objs_exists G
  have hj : ∀ a, j a ∈ (Finset.univ.image j : Finset J) := by
    intro a
    simp only [Finset.mem_image, Finset.mem_univ, true_and, exists_apply_eq_apply]
  let fs : ∀ a : α, j0 ⟶ j a := fun a => (hj0 (hj a)).some
  let gg : α → LocallyConstant (F.obj j0) (Fin 2) := fun a => (g a).comap (F.map (fs _))
  let ggg := LocallyConstant.unflip gg
  refine' ⟨j0, ggg, _⟩
  have : f.map ι = LocallyConstant.unflip (f.map ι).flip := by simp
  rw [this]; clear this
  have :
    LocallyConstant.comap (C.π.app j0) ggg =
      LocallyConstant.unflip (LocallyConstant.comap (C.π.app j0) ggg).flip :=
    by simp
  rw [this]; clear this
  congr 1
  ext1 a
  change ff a = _
  rw [h]
  dsimp
  ext1 x
  -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
  erw [LocallyConstant.coe_comap _ _ (C.π.app (j a)).continuous]
  dsimp [LocallyConstant.flip, LocallyConstant.unflip]
  -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
  erw [LocallyConstant.coe_comap _ _ (C.π.app j0).continuous]
  dsimp
  

Proof state:
case intro.intro.e_f.h.h
J : Type v
inst✝² : SmallCategory J
inst✝¹ : IsCofiltered J
F : J ⥤ ProfiniteMax
C : Cone F
α : Type u_1
inst✝ : Finite α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toCompHaus.toTop) α
val✝ : Fintype α
ι : α → α → Fin 2 := fun x y => if x = y then 0 else 1
ff : α → LocallyConstant (↑C.pt.toCompHaus.toTop) (Fin 2) := LocallyConstant.flip (LocallyConstant.map ι f)
j : α → J
g : (a : α) → LocallyConstant (↑(F.obj (j a)).toCompHaus.toTop) (Fin 2)
h : ∀ (a : α), ff a = LocallyConstant.comap (⇑(C.π.app (j a))) (g a)
G : Finset J := Finset.image j Finset.univ
j0 : J
hj0 : ∀ {X : J}, X ∈ G → Nonempty (j0 ⟶ X)
hj : ∀ (a : α), j a ∈ Finset.image j Finset.univ
fs : (a : α) → j0 ⟶ j a := fun a => Nonempty.some (_ : Nonempty (j0 ⟶ j a))
gg : α → LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (Fin 2) :=
  fun a => LocallyConstant.comap (⇑(F.map (fs a))) (g a)
ggg : LocallyConstant (↑(F.obj j0).toCompHaus.toTop) (α → Fin 2) := LocallyConstant.unflip gg
a : α
x : (forget ProfiniteMax).obj C.pt
⊢ (g a) ((C.π.app (j a)) x) =
    (LocallyConstant.comap (⇑(F.map (Nonempty.some (_ : Nonempty (j0 ⟶ j a))))) (g a)) ((C.π.app j0) x)

Next tactic:
rw [LocallyConstant.coe_comap _ _ _]