-- Mathlib/Topology/Category/Profinite/CofilteredLimit.lean
theorem exists_locallyConstant_finite_nonempty {α : Type*} [Finite α] [Nonempty α]
    (hC : IsLimit C) (f : LocallyConstant C.pt α) :
    ∃ (j : J) (g : LocallyConstant (F.obj j) α), f = g.comap (C.π.app _).hom

Proof state:
case intro.intro.h
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
inhabited_h : Inhabited α
j : J
gg : LocallyConstant (↑(F.obj j).toTop) (α → Fin 2)
h : LocallyConstant.map (fun a b => if a = b then 0 else 1) f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) gg
ι : α → α → Fin 2 := fun a b => if a = b then 0 else 1
σ : (α → Fin 2) → α := fun f => if h : ∃ a, ι a = f then h.choose else default
x : ↑C.pt.toTop
h1 : ι (f x) = gg ((ConcreteCategory.hom (C.π.app j)) x)
⊢ f x = if h : ∃ a, ι a = gg ((TopCat.Hom.hom (C.π.app j)) x) then h.choose else default

Tactic:
have h2 : ∃ a : α, ι a = gg (C.π.app j x) := ⟨f x, h1⟩

Result:
case intro.intro.h
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
inhabited_h : Inhabited α
j : J
gg : LocallyConstant (↑(F.obj j).toTop) (α → Fin 2)
h : LocallyConstant.map (fun a b => if a = b then 0 else 1) f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) gg
ι : α → α → Fin 2 := fun a b => if a = b then 0 else 1
σ : (α → Fin 2) → α := fun f => if h : ∃ a, ι a = f then h.choose else default
x : ↑C.pt.toTop
h1 : ι (f x) = gg ((ConcreteCategory.hom (C.π.app j)) x)
h2 : ∃ a, ι a = gg ((ConcreteCategory.hom (C.π.app j)) x)
⊢ f x = if h : ∃ a, ι a = gg ((TopCat.Hom.hom (C.π.app j)) x) then h.choose else default

Proof state:
case intro.intro.h
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
inhabited_h : Inhabited α
j : J
gg : LocallyConstant (↑(F.obj j).toTop) (α → Fin 2)
h : LocallyConstant.map (fun a b => if a = b then 0 else 1) f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) gg
ι : α → α → Fin 2 := fun a b => if a = b then 0 else 1
σ : (α → Fin 2) → α := fun f => if h : ∃ a, ι a = f then h.choose else default
x : ↑C.pt.toTop
⊢ f x = (LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) (LocallyConstant.map σ gg)) x

Tactic:
simp only [Functor.const_obj_obj, LocallyConstant.coe_comap, LocallyConstant.map_apply,
  Function.comp_apply]

Result:
case intro.intro.h
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
inhabited_h : Inhabited α
j : J
gg : LocallyConstant (↑(F.obj j).toTop) (α → Fin 2)
h : LocallyConstant.map (fun a b => if a = b then 0 else 1) f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) gg
ι : α → α → Fin 2 := fun a b => if a = b then 0 else 1
σ : (α → Fin 2) → α := fun f => if h : ∃ a, ι a = f then h.choose else default
x : ↑C.pt.toTop
⊢ f x = σ (gg ((TopCat.Hom.hom (C.π.app j)) x))

Proof state:
case intro.intro
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
inhabited_h : Inhabited α
j : J
gg : LocallyConstant (↑(F.obj j).toTop) (α → Fin 2)
h : LocallyConstant.map (fun a b => if a = b then 0 else 1) f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) gg
ι : α → α → Fin 2 := fun a b => if a = b then 0 else 1
σ : (α → Fin 2) → α := fun f => if h : ∃ a, ι a = f then h.choose else default
⊢ ∃ j g, f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) g

Tactic:
refine ⟨j, gg.map σ, ?_⟩

Result:
case intro.intro
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
inhabited_h : Inhabited α
j : J
gg : LocallyConstant (↑(F.obj j).toTop) (α → Fin 2)
h : LocallyConstant.map (fun a b => if a = b then 0 else 1) f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) gg
ι : α → α → Fin 2 := fun a b => if a = b then 0 else 1
σ : (α → Fin 2) → α := fun f => if h : ∃ a, ι a = f then h.choose else default
⊢ f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) (LocallyConstant.map σ gg)

Proof state:
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
inhabited_h : Inhabited α
⊢ ∃ j g, f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) g

Tactic:
obtain ⟨j, gg, h⟩ := exists_locallyConstant_finite_aux _ hC f

Result:
case intro.intro
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
inhabited_h : Inhabited α
j : J
gg : LocallyConstant (↑(F.obj j).toTop) (α → Fin 2)
h : LocallyConstant.map (fun a b => if a = b then 0 else 1) f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) gg
⊢ ∃ j g, f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) g

Proof state:
case intro.intro
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
inhabited_h : Inhabited α
j : J
gg : LocallyConstant (↑(F.obj j).toTop) (α → Fin 2)
h : LocallyConstant.map (fun a b => if a = b then 0 else 1) f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) gg
⊢ ∃ j g, f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) g

Tactic:
let ι : α → α → Fin 2 := fun a b => if a = b then 0 else 1

Result:
case intro.intro
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
inhabited_h : Inhabited α
j : J
gg : LocallyConstant (↑(F.obj j).toTop) (α → Fin 2)
h : LocallyConstant.map (fun a b => if a = b then 0 else 1) f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) gg
ι : α → α → Fin 2 := fun a b => if a = b then 0 else 1
⊢ ∃ j g, f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) g

Proof state:
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
⊢ ∃ j g, f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) g

Tactic:
inhabit α

Result:
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
inhabited_h : Inhabited α
⊢ ∃ j g, f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) g

Proof state:
case neg
J : Type v
inst✝³ : SmallCategory J
inst✝² : IsCofiltered J
F : J ⥤ Profinite
C : Cone F
α : Type u_1
inst✝¹ : Finite α
inst✝ : Nonempty α
hC : IsLimit C
f : LocallyConstant (↑C.pt.toTop) α
inhabited_h : Inhabited α
j : J
gg : LocallyConstant (↑(F.obj j).toTop) (α → Fin 2)
h : LocallyConstant.map (fun a b => if a = b then 0 else 1) f = LocallyConstant.comap (TopCat.Hom.hom (C.π.app j)) gg
ι : α → α → Fin 2 := fun a b => if a = b then 0 else 1
σ : (α → Fin 2) → α := fun f => if h : ∃ a, ι a = f then h.choose else default
x : ↑C.pt.toTop
h1 : ι (f x) = gg ((ConcreteCategory.hom (C.π.app j)) x)
h2 : ∃ a, ι a = gg ((ConcreteCategory.hom (C.π.app j)) x)
a b : α
hh : ι a = ι b
hh1 : ¬b = a
hhh : 0 = 1
⊢ a = b

Tactic:
exact False.elim (bot_ne_top hhh)

Result:
no goals