-- 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:
α : 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
⊢ ∃ S, Unbounded r S ∧ type (Subrel r fun x => x ∈ S) = (type r).cof.ord

Tactic:
let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }

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}
⊢ ∃ S, Unbounded r S ∧ type (Subrel r fun x => x ∈ S) = (type r).cof.ord

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
c : ↑S
h : ¬r ↑c ↑b
⊢ ¬s c b

Tactic:
exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba)

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}
this : Unbounded r T
a b : ↑T
h : Subrel r (fun x => x ∈ T) a b
⊢ s ((fun a => ⟨↑a, ⋯⟩) a) ((fun a => ⟨↑a, ⋯⟩) b)

Tactic:
rcases a with ⟨a, aS, ha⟩

Result:
case mk.intro
α : 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
b : ↑T
a : α
aS : a ∈ S
ha : ∀ (b : ↑S), s b ⟨a, aS⟩ → r (↑b) a
h : Subrel r (fun x => x ∈ T) ⟨a, ⋯⟩ b
⊢ s ((fun a => ⟨↑a, ⋯⟩) ⟨a, ⋯⟩) ((fun a => ⟨↑a, ⋯⟩) b)

Proof state:
case mk.intro.mk.intro
α : 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, ⋯⟩
⊢ s ⟨a, ⋯⟩ ⟨b, ⋯⟩

Tactic:
refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_

Result:
case mk.intro.mk.intro.refine_1
α : 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, ⋯⟩
hn : s ⟨b, ⋯⟩ ⟨a, ⋯⟩
⊢ False

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, ⋯⟩
⊢ ¬⟨b, ⋯⟩ = ⟨a, ⋯⟩

Proof state:
α : Type u
r : α → α → Prop
inst✝ : IsWellOrder α r
⊢ ∃ S, Unbounded r S ∧ type (Subrel r fun x => x ∈ S) = (type r).cof.ord

Tactic:
let ⟨S, hS, e⟩ := cof_eq r

Result:
α : Type u
r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = (type r).cof
⊢ ∃ S, Unbounded r S ∧ type (Subrel r fun x => x ∈ S) = (type r).cof.ord

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:
subst b

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
bS : a ∈ S
hb : ∀ (b : ↑S), s b ⟨a, bS⟩ → r (↑b) a
h : Subrel r (fun x => x ∈ T) ⟨a, ⋯⟩ ⟨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}
this : Unbounded r T
⊢ type (Subrel r fun x => x ∈ T) ≤ type s

Tactic:
refine
  (RelEmbedding.ofMonotone
      (fun a : T =>
        (⟨a,
            let ⟨aS, _⟩ := a.2
            aS⟩ :
          S))
      fun a b h => ?_).ordinal_type_le

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}
this : Unbounded r T
a b : ↑T
h : Subrel r (fun x => x ∈ T) a b
⊢ s ((fun a => ⟨↑a, ⋯⟩) a) ((fun a => ⟨↑a, ⋯⟩) 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 : ↑S := ⋯.min {b | ¬r (↑b) a} this
ba : ¬r (↑b) a
c : ↑S
h : ¬r ↑c ↑b
⊢ ¬s c ⟨↑b, ⋯⟩

Tactic:
rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl]

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:
case mk.intro.mk.intro.refine_1
α : 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, ⋯⟩
hn : s ⟨b, ⋯⟩ ⟨a, ⋯⟩
⊢ False

Tactic:
exact asymm h (ha _ hn)

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}
⊢ Unbounded r T

Tactic:
intro a

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 : α
⊢ ∃ b ∈ T, ¬r b a