-- Mathlib/SetTheory/Cardinal/Cofinality.lean
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r (· ∈ S)) = (cof (type r)).ord

Proof state:
case mk
α : Type u
r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = (type r).cof
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : (#↑S).ord = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a}
a : α
this : {b | ¬r (↑b) a}.Nonempty
b : ↑S := ⋯.min {b | ¬r (↑b) a} this
ba : ¬r (↑b) a
c : ↑S
h : ¬r ↑c ↑b
val✝ : α
property✝ : val✝ ∈ S
⊢ ⟨↑⟨val✝, property✝⟩, ⋯⟩ = ⟨val✝, property✝⟩

Tactic:
rfl

Result:
no goals

Proof state:
case mk.intro.mk.intro.refine_2
α : Type u
r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e✝ : #↑S = (type r).cof
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : (#↑S).ord = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a}
this : Unbounded r T
a : α
aS : a ∈ S
ha : ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a
b : α
bS : b ∈ S
hb : ∀ (b_1 : ↑S), s b_1 ⟨b, bS⟩ → r (↑b_1) b
h : Subrel r (fun x => x ∈ T) ⟨a, ⋯⟩ ⟨b, ⋯⟩
e : ⟨b, ⋯⟩ = ⟨a, ⋯⟩
⊢ False

Tactic:
injection e with e

Result:
case mk.intro.mk.intro.refine_2
α : Type u
r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e✝ : #↑S = (type r).cof
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : (#↑S).ord = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a}
this : Unbounded r T
a : α
aS : a ∈ S
ha : ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a
b : α
bS : b ∈ S
hb : ∀ (b_1 : ↑S), s b_1 ⟨b, bS⟩ → r (↑b_1) b
h : Subrel r (fun x => x ∈ T) ⟨a, ⋯⟩ ⟨b, ⋯⟩
e : b = a
⊢ False

Proof state:
α : Type u
r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = (type r).cof
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : (#↑S).ord = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a}
a : α
⊢ ∃ b ∈ T, ¬r b a

Tactic:
have : { b : S | ¬r b a }.Nonempty :=
  let ⟨b, bS, ba⟩ := hS a
  ⟨⟨b, bS⟩, ba⟩

Result:
α : Type u
r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = (type r).cof
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : (#↑S).ord = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a}
a : α
this : {b | ¬r (↑b) a}.Nonempty
⊢ ∃ b ∈ T, ¬r b a

Proof state:
case mk.intro.mk.intro.refine_2
α : Type u
r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = (type r).cof
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : (#↑S).ord = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a}
this : Unbounded r T
a : α
aS : a ∈ S
ha : ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a
bS : a ∈ S
hb : ∀ (b : ↑S), s b ⟨a, bS⟩ → r (↑b) a
h : Subrel r (fun x => x ∈ T) ⟨a, ⋯⟩ ⟨a, ⋯⟩
⊢ False

Tactic:
exact irrefl _ h

Result:
no goals

Proof state:
α : Type u
r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = (type r).cof
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : (#↑S).ord = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a}
a : α
this : {b | ¬r (↑b) a}.Nonempty
b : ↑S := ⋯.min {b | ¬r (↑b) a} this
ba : ¬r (↑b) a
⊢ ∃ b ∈ T, ¬r b a

Tactic:
refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩

Result:
α : Type u
r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = (type r).cof
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : (#↑S).ord = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a}
a : α
this : {b | ¬r (↑b) a}.Nonempty
b : ↑S := ⋯.min {b | ¬r (↑b) a} this
ba : ¬r (↑b) a
c : ↑S
h : ¬r ↑c ↑b
⊢ ¬s c ⟨↑b, ⋯⟩

Proof state:
α : Type u
r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = (type r).cof
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : (#↑S).ord = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a}
a : α
this : {b | ¬r (↑b) a}.Nonempty
⊢ ∃ b ∈ T, ¬r b a

Tactic:
let b := (IsWellFounded.wf : WellFounded s).min _ this

Result:
α : Type u
r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = (type r).cof
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : (#↑S).ord = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a}
a : α
this : {b | ¬r (↑b) a}.Nonempty
b : ↑S := ⋯.min {b | ¬r (↑b) a} this
⊢ ∃ b ∈ T, ¬r b a