l3lab/ntp-mathlib huggingface dataset:
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    

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

Next tactic:
change s ⟨a, _⟩ ⟨b, _⟩
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    

Proof state:
case mk.intro.mk.intro
α : Type u_1
r✝ r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = cof (type r)
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : ord #↑S = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
this : Unbounded r T
a : α
aS : a ∈ S
ha : ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a
b : α
bS : b ∈ S
hb : ∀ (b_1 : ↑S), s b_1 { val := b, property := bS } → r (↑b_1) b
h :
  Subrel r T { val := a, property := (_ : ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := b, property := (_ : ∃ (aS : b ∈ S), ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) }
⊢ s
    { val := a,
      property :=
        (_ :
          ↑{ val := a, property := (_ : ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) } ∈
            S) }
    { val := b,
      property :=
        (_ :
          ↑{ val := b,
                property := (_ : ∃ (aS : b ∈ S), ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) } ∈
            S) }

Next tactic:
refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
    · 

Proof state:
case mk.intro.mk.intro.refine'_1
α : Type u_1
r✝ r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = cof (type r)
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : ord #↑S = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
this : Unbounded r T
a : α
aS : a ∈ S
ha : ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a
b : α
bS : b ∈ S
hb : ∀ (b_1 : ↑S), s b_1 { val := b, property := bS } → r (↑b_1) b
h :
  Subrel r T { val := a, property := (_ : ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := b, property := (_ : ∃ (aS : b ∈ S), ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) }
hn :
  s
    { val := b,
      property :=
        (_ :
          ↑{ val := b,
                property := (_ : ∃ (aS : b ∈ S), ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) } ∈
            S) }
    { val := a,
      property :=
        (_ :
          ↑{ val := a, property := (_ : ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) } ∈
            S) }
⊢ False

Next tactic:
exact asymm h (ha _ hn)
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
    · exact asymm h (ha _ hn)
    · 

Proof state:
case mk.intro.mk.intro.refine'_2
α : Type u_1
r✝ r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = cof (type r)
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : ord #↑S = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
this : Unbounded r T
a : α
aS : a ∈ S
ha : ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a
b : α
bS : b ∈ S
hb : ∀ (b_1 : ↑S), s b_1 { val := b, property := bS } → r (↑b_1) b
h :
  Subrel r T { val := a, property := (_ : ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := b, property := (_ : ∃ (aS : b ∈ S), ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) }
⊢ ¬{ val := b,
        property :=
          (_ :
            ↑{ val := b,
                  property := (_ : ∃ (aS : b ∈ S), ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) } ∈
              S) } =
      { val := a,
        property :=
          (_ :
            ↑{ val := a, property := (_ : ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) } ∈
              S) }

Next tactic:
intro e
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
    · exact asymm h (ha _ hn)
    · intro e
      

Proof state:
case mk.intro.mk.intro.refine'_2
α : Type u_1
r✝ r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e✝ : #↑S = cof (type r)
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : ord #↑S = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
this : Unbounded r T
a : α
aS : a ∈ S
ha : ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a
b : α
bS : b ∈ S
hb : ∀ (b_1 : ↑S), s b_1 { val := b, property := bS } → r (↑b_1) b
h :
  Subrel r T { val := a, property := (_ : ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := b, property := (_ : ∃ (aS : b ∈ S), ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) }
e :
  { val := b,
      property :=
        (_ :
          ↑{ val := b,
                property := (_ : ∃ (aS : b ∈ S), ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) } ∈
            S) } =
    { val := a,
      property :=
        (_ :
          ↑{ val := a, property := (_ : ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) } ∈
            S) }
⊢ False

Next tactic:
injection e with e
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
    · exact asymm h (ha _ hn)
    · intro e
      injection e with e
      

Proof state:
case mk.intro.mk.intro.refine'_2
α : Type u_1
r✝ r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e✝ : #↑S = cof (type r)
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : ord #↑S = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
this : Unbounded r T
a : α
aS : a ∈ S
ha : ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a
b : α
bS : b ∈ S
hb : ∀ (b_1 : ↑S), s b_1 { val := b, property := bS } → r (↑b_1) b
h :
  Subrel r T { val := a, property := (_ : ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := b, property := (_ : ∃ (aS : b ∈ S), ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) }
e : b = a
⊢ False

Next tactic:
subst b
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
    · exact asymm h (ha _ hn)
    · intro e
      injection e with e
      subst b
      

Proof state:
case mk.intro.mk.intro.refine'_2
α : Type u_1
r✝ r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : #↑S = cof (type r)
s : ↑S → ↑S → Prop
w✝ : IsWellOrder (↑S) s
e' : ord #↑S = type s
T : Set α := {a | ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
this : Unbounded r T
a : α
aS : a ∈ S
ha : ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a
bS : a ∈ S
hb : ∀ (b : ↑S), s b { val := a, property := bS } → r (↑b) a
h :
  Subrel r T { val := a, property := (_ : ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := a, property := (_ : ∃ (aS : a ∈ S), ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
⊢ False

Next tactic:
exact irrefl _ h
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
    · exact asymm h (ha _ hn)
    · intro e
      injection e with e
      subst b
      exact irrefl _ h
  · 

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

Next tactic:
intro a
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
    · exact asymm h (ha _ hn)
    · intro e
      injection e with e
      subst b
      exact irrefl _ h
  · intro a
    

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

Next tactic:
have : { b : S | ¬r b a }.Nonempty :=
      let ⟨b, bS, ba⟩ := hS a
      ⟨⟨b, bS⟩, ba⟩
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
    · exact asymm h (ha _ hn)
    · intro e
      injection e with e
      subst b
      exact irrefl _ h
  · intro a
    have : { b : S | ¬r b a }.Nonempty :=
      let ⟨b, bS, ba⟩ := hS a
      ⟨⟨b, bS⟩, ba⟩
    

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

Next tactic:
let b := (IsWellFounded.wf : WellFounded s).min _ this
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
    · exact asymm h (ha _ hn)
    · intro e
      injection e with e
      subst b
      exact irrefl _ h
  · intro a
    have : { b : S | ¬r b a }.Nonempty :=
      let ⟨b, bS, ba⟩ := hS a
      ⟨⟨b, bS⟩, ba⟩
    let b := (IsWellFounded.wf : WellFounded s).min _ this
    

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

Next tactic:
have ba : ¬r b a := IsWellFounded.wf.min_mem _ this
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
    · exact asymm h (ha _ hn)
    · intro e
      injection e with e
      subst b
      exact irrefl _ h
  · intro a
    have : { b : S | ¬r b a }.Nonempty :=
      let ⟨b, bS, ba⟩ := hS a
      ⟨⟨b, bS⟩, ba⟩
    let b := (IsWellFounded.wf : WellFounded s).min _ this
    have ba : ¬r b a := IsWellFounded.wf.min_mem _ this
    

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

Next tactic:
refine' ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => _⟩, ba⟩
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
    · exact asymm h (ha _ hn)
    · intro e
      injection e with e
      subst b
      exact irrefl _ h
  · intro a
    have : { b : S | ¬r b a }.Nonempty :=
      let ⟨b, bS, ba⟩ := hS a
      ⟨⟨b, bS⟩, ba⟩
    let b := (IsWellFounded.wf : WellFounded s).min _ this
    have ba : ¬r b a := IsWellFounded.wf.min_mem _ this
    refine' ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => _⟩, ba⟩
    

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

Next tactic:
rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl]
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
    ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
  let ⟨S, hS, e⟩ := cof_eq r
  let ⟨s, _, e'⟩ := Cardinal.ord_eq S
  let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
  suffices : Unbounded r T
  · refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
    rw [← e, e']
    refine'
      (RelEmbedding.ofMonotone
          (fun a : T =>
            (⟨a,
                let ⟨aS, _⟩ := a.2
                aS⟩ :
              S))
          fun a b h => _).ordinal_type_le
    rcases a with ⟨a, aS, ha⟩
    rcases b with ⟨b, bS, hb⟩
    change s ⟨a, _⟩ ⟨b, _⟩
    refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
    · exact asymm h (ha _ hn)
    · intro e
      injection e with e
      subst b
      exact irrefl _ h
  · intro a
    have : { b : S | ¬r b a }.Nonempty :=
      let ⟨b, bS, ba⟩ := hS a
      ⟨⟨b, bS⟩, ba⟩
    let b := (IsWellFounded.wf : WellFounded s).min _ this
    have ba : ¬r b a := IsWellFounded.wf.min_mem _ this
    refine' ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => _⟩, ba⟩
    rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by 

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

Next tactic:
intro b