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⟩
    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 intro b; 

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:
cases 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
      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 intro b; cases b; 

Proof state:
case mk
α : 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
val✝ : α
property✝ : val✝ ∈ S
⊢ { val := ↑{ val := val✝, property := property✝ }, property := (_ : ↑{ val := val✝, property := property✝ } ∈ S) } =
    { val := val✝, property := property✝ }

Next tactic:
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 intro b; cases b; rfl]
    

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 b

Next tactic:
exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba)
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  

Proof state:
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
⊢ cof o = sInf {a | ∃ ι f, lsub f = o ∧ #ι = a}

Next tactic:
refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · 

Proof state:
case refine'_1
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
⊢ ∀ b ∈ {a | ∃ ι f, lsub f = o ∧ #ι = a}, cof o ≤ b

Next tactic:
rintro a ⟨ι, f, hf, rfl⟩
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    

Proof state:
case refine'_1.intro.intro.intro
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
⊢ cof o ≤ #ι

Next tactic:
rw [← type_lt o]
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    

Proof state:
case refine'_1.intro.intro.intro
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
⊢ cof (type fun x x_1 => x < x_1) ≤ #ι

Next tactic:
refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          

Proof state:
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
s t : ↑((typein fun x x_1 => x < x_1) ⁻¹' range f)
hst :
  (fun s => choose (_ : ↑s ∈ (typein fun x x_1 => x < x_1) ⁻¹' range f)) s =
    (fun s => choose (_ : ↑s ∈ (typein fun x x_1 => x < x_1) ⁻¹' range f)) t
⊢ s = t

Next tactic:
let H := congr_arg f hst
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          

Proof state:
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
s t : ↑((typein fun x x_1 => x < x_1) ⁻¹' range f)
hst :
  (fun s => choose (_ : ↑s ∈ (typein fun x x_1 => x < x_1) ⁻¹' range f)) s =
    (fun s => choose (_ : ↑s ∈ (typein fun x x_1 => x < x_1) ⁻¹' range f)) t
H : f ((fun s => choose (_ : ↑s ∈ (typein fun x x_1 => x < x_1) ⁻¹' range f)) s) =
  f ((fun s => choose (_ : ↑s ∈ (typein fun x x_1 => x < x_1) ⁻¹' range f)) t) :=
  congr_arg f hst
⊢ s = t

Next tactic:
rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
    

Proof state:
case refine'_1.intro.intro.intro
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
a : (Quotient.out o).α
⊢ ∃ b ∈ (typein fun x x_1 => x < x_1) ⁻¹' range f, ¬b < a

Next tactic:
have := typein_lt_self a
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
    have := typein_lt_self a
    

Proof state:
case refine'_1.intro.intro.intro
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
a : (Quotient.out o).α
this : typein (fun x x_1 => x < x_1) a < o
⊢ ∃ b ∈ (typein fun x x_1 => x < x_1) ⁻¹' range f, ¬b < a

Next tactic:
simp_rw [← hf, lt_lsub_iff] at this
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
    have := typein_lt_self a
    simp_rw [← hf, lt_lsub_iff] at this
    

Proof state:
case refine'_1.intro.intro.intro
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
a : (Quotient.out o).α
this : ∃ i, typein (fun x x_1 => x < x_1) a ≤ f i
⊢ ∃ b ∈ (typein fun x x_1 => x < x_1) ⁻¹' range f, ¬b < a

Next tactic:
cases' this with i hi
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
    have := typein_lt_self a
    simp_rw [← hf, lt_lsub_iff] at this
    cases' this with i hi
    

Proof state:
case refine'_1.intro.intro.intro.intro
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
a : (Quotient.out o).α
i : ι
hi : typein (fun x x_1 => x < x_1) a ≤ f i
⊢ ∃ b ∈ (typein fun x x_1 => x < x_1) ⁻¹' range f, ¬b < a

Next tactic:
refine' ⟨enum (· < ·) (f i) _, _, _⟩
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
    have := typein_lt_self a
    simp_rw [← hf, lt_lsub_iff] at this
    cases' this with i hi
    refine' ⟨enum (· < ·) (f i) _, _, _⟩
    · 

Proof state:
case refine'_1.intro.intro.intro.intro.refine'_1
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
a : (Quotient.out o).α
i : ι
hi : typein (fun x x_1 => x < x_1) a ≤ f i
⊢ f i < type fun x x_1 => x < x_1

Next tactic:
rw [type_lt, ← hf]
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
    have := typein_lt_self a
    simp_rw [← hf, lt_lsub_iff] at this
    cases' this with i hi
    refine' ⟨enum (· < ·) (f i) _, _, _⟩
    · rw [type_lt, ← hf]
      

Proof state:
case refine'_1.intro.intro.intro.intro.refine'_1
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
a : (Quotient.out o).α
i : ι
hi : typein (fun x x_1 => x < x_1) a ≤ f i
⊢ f i < lsub f

Next tactic:
apply lt_lsub
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
    have := typein_lt_self a
    simp_rw [← hf, lt_lsub_iff] at this
    cases' this with i hi
    refine' ⟨enum (· < ·) (f i) _, _, _⟩
    · rw [type_lt, ← hf]
      apply lt_lsub
    · 

Proof state:
case refine'_1.intro.intro.intro.intro.refine'_2
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
a : (Quotient.out o).α
i : ι
hi : typein (fun x x_1 => x < x_1) a ≤ f i
⊢ enum (fun x x_1 => x < x_1) (f i) (_ : f i < type fun x x_1 => x < x_1) ∈ (typein fun x x_1 => x < x_1) ⁻¹' range f

Next tactic:
rw [mem_preimage, typein_enum]
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
    have := typein_lt_self a
    simp_rw [← hf, lt_lsub_iff] at this
    cases' this with i hi
    refine' ⟨enum (· < ·) (f i) _, _, _⟩
    · rw [type_lt, ← hf]
      apply lt_lsub
    · rw [mem_preimage, typein_enum]
      

Proof state:
case refine'_1.intro.intro.intro.intro.refine'_2
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
a : (Quotient.out o).α
i : ι
hi : typein (fun x x_1 => x < x_1) a ≤ f i
⊢ f i ∈ range f

Next tactic:
exact mem_range_self i
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
    have := typein_lt_self a
    simp_rw [← hf, lt_lsub_iff] at this
    cases' this with i hi
    refine' ⟨enum (· < ·) (f i) _, _, _⟩
    · rw [type_lt, ← hf]
      apply lt_lsub
    · rw [mem_preimage, typein_enum]
      exact mem_range_self i
    · 

Proof state:
case refine'_1.intro.intro.intro.intro.refine'_3
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
ι : Type u
f : ι → Ordinal.{u}
hf : lsub f = o
a : (Quotient.out o).α
i : ι
hi : typein (fun x x_1 => x < x_1) a ≤ f i
⊢ ¬enum (fun x x_1 => x < x_1) (f i) (_ : f i < type fun x x_1 => x < x_1) < a

Next tactic:
rwa [← typein_le_typein, typein_enum]
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
    have := typein_lt_self a
    simp_rw [← hf, lt_lsub_iff] at this
    cases' this with i hi
    refine' ⟨enum (· < ·) (f i) _, _, _⟩
    · rw [type_lt, ← hf]
      apply lt_lsub
    · rw [mem_preimage, typein_enum]
      exact mem_range_self i
    · rwa [← typein_le_typein, typein_enum]
  · 

Proof state:
case refine'_2
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
⊢ cof o ∈ {a | ∃ ι f, lsub f = o ∧ #ι = a}

Next tactic:
rcases cof_eq (· < · : (Quotient.out o).α → (Quotient.out o).α → Prop) with ⟨S, hS, hS'⟩
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
    have := typein_lt_self a
    simp_rw [← hf, lt_lsub_iff] at this
    cases' this with i hi
    refine' ⟨enum (· < ·) (f i) _, _, _⟩
    · rw [type_lt, ← hf]
      apply lt_lsub
    · rw [mem_preimage, typein_enum]
      exact mem_range_self i
    · rwa [← typein_le_typein, typein_enum]
  · rcases cof_eq (· < · : (Quotient.out o).α → (Quotient.out o).α → Prop) with ⟨S, hS, hS'⟩
    

Proof state:
case refine'_2.intro.intro
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
S : Set (Quotient.out o).α
hS : Unbounded (fun x x_1 => x < x_1) S
hS' : #↑S = cof (type fun x x_1 => x < x_1)
⊢ cof o ∈ {a | ∃ ι f, lsub f = o ∧ #ι = a}

Next tactic:
let f : S → Ordinal := fun s => typein LT.lt s.val
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
    sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
  refine' le_antisymm (le_csInf (cof_lsub_def_nonempty o) _) (csInf_le' _)
  · rintro a ⟨ι, f, hf, rfl⟩
    rw [← type_lt o]
    refine'
      (cof_type_le fun a => _).trans
        (@mk_le_of_injective _ _
          (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
            Classical.choose s.prop)
          fun s t hst => by
          let H := congr_arg f hst
          rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
            Subtype.coe_inj] at H)
    have := typein_lt_self a
    simp_rw [← hf, lt_lsub_iff] at this
    cases' this with i hi
    refine' ⟨enum (· < ·) (f i) _, _, _⟩
    · rw [type_lt, ← hf]
      apply lt_lsub
    · rw [mem_preimage, typein_enum]
      exact mem_range_self i
    · rwa [← typein_le_typein, typein_enum]
  · rcases cof_eq (· < · : (Quotient.out o).α → (Quotient.out o).α → Prop) with ⟨S, hS, hS'⟩
    let f : S → Ordinal := fun s => typein LT.lt s.val
    

Proof state:
case refine'_2.intro.intro
α : Type u_1
r : α → α → Prop
o : Ordinal.{u}
S : Set (Quotient.out o).α
hS : Unbounded (fun x x_1 => x < x_1) S
hS' : #↑S = cof (type fun x x_1 => x < x_1)
f : ↑S → Ordinal.{u} := fun s => typein LT.lt ↑s
⊢ cof o ∈ {a | ∃ ι f, lsub f = o ∧ #ι = a}

Next tactic:
refine'
      ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self i) (le_of_forall_lt fun a ha => _), by
        rwa [type_lt o] at hS'⟩