Theorem: Ordinal.ord_cof_eq
File: Mathlib/SetTheory/Cardinal/Cofinality.lean

tactic: let ⟨S, hS, e⟩ := cof_eq r
state_before: α : Type u_1
r✝ r : α → α → Prop
inst✝ : IsWellOrder α r
⊢ ∃ S, Unbounded r S ∧ type (Subrel r S) = ord (cof (type r))

tactic: let ⟨s, _, e'⟩ := Cardinal.ord_eq S
state_before: α : Type u_1
r✝ r : α → α → Prop
inst✝ : IsWellOrder α r
S : Set α
hS : Unbounded r S
e : (#↑S) = cof (type r)
⊢ ∃ S, Unbounded r S ∧ type (Subrel r S) = ord (cof (type r))

tactic: let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
state_before: α : 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
⊢ ∃ S, Unbounded r S ∧ type (Subrel r S) = ord (cof (type r))

tactic: suffices : Unbounded r T
state_before: α : 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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
⊢ ∃ S, Unbounded r S ∧ type (Subrel r S) = ord (cof (type r))

tactic: refine' ⟨T, this, le_antisymm _ (Cardinal.ord_le.2 <| cof_type_le this)⟩
state_before: α : 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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
this : Unbounded r T
⊢ ∃ S, Unbounded r S ∧ type (Subrel r S) = ord (cof (type r))

tactic: rw [← e, e']
state_before: α : 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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
this : Unbounded r T
⊢ type (Subrel r T) ≤ ord (cof (type r))

tactic: refine'
  (RelEmbedding.ofMonotone
      (fun a : T =>
        (⟨a,
            let ⟨aS, _⟩ := a.2
            aS⟩ :
          S))
      fun a b h => _).ordinal_type_le
state_before: α : 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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
this : Unbounded r T
⊢ type (Subrel r T) ≤ type s

tactic: rcases a with ⟨a, aS, ha⟩
state_before: α : 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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
this : Unbounded r T
a b : ↑T
h : Subrel r T a b
⊢ s ((fun a => { val := ↑a, property := (_ : ↑a ∈ S) }) a) ((fun a => { val := ↑a, property := (_ : ↑a ∈ S) }) b)

tactic: rcases b with ⟨b, bS, hb⟩
state_before: case 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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
this : Unbounded r T
b : ↑T
a : α
aS : a ∈ S
ha : ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a
h : Subrel r T { val := a, property := (_ : ∃ aS, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) } b
⊢ s
    ((fun a => { val := ↑a, property := (_ : ↑a ∈ S) })
      { val := a, property := (_ : ∃ aS, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) })
    ((fun a => { val := ↑a, property := (_ : ↑a ∈ S) }) b)

tactic: change s ⟨a, _⟩ ⟨b, _⟩
state_before: 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, ∀ (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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := b, property := (_ : ∃ aS, ∀ (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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) })
    ((fun a => { val := ↑a, property := (_ : ↑a ∈ S) })
      { val := b, property := (_ : ∃ aS, ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) })

tactic: refine' ((trichotomous_of s _ _).resolve_left fun hn => _).resolve_left _
state_before: 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, ∀ (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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := b, property := (_ : ∃ aS, ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) }
⊢ s
    { val := a,
      property :=
        (_ : ↑{ val := a, property := (_ : ∃ aS, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) } ∈ S) }
    { val := b,
      property :=
        (_ : ↑{ val := b, property := (_ : ∃ aS, ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) } ∈ S) }

tactic: exact asymm h (ha _ hn)
state_before: 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, ∀ (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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := b, property := (_ : ∃ aS, ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) }
hn :
  s
    { val := b,
      property :=
        (_ : ↑{ val := b, property := (_ : ∃ aS, ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) } ∈ S) }
    { val := a,
      property :=
        (_ : ↑{ val := a, property := (_ : ∃ aS, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) } ∈ S) }
⊢ False

tactic: intro e
state_before: 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, ∀ (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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := b, property := (_ : ∃ aS, ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) }
⊢ ¬{ val := b,
        property :=
          (_ :
            ↑{ val := b, property := (_ : ∃ aS, ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) } ∈
              S) } =
      { val := a,
        property :=
          (_ : ↑{ val := a, property := (_ : ∃ aS, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) } ∈ S) }

tactic: injection e with e
state_before: 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, ∀ (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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := b, property := (_ : ∃ aS, ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) }
e :
  { val := b,
      property :=
        (_ :
          ↑{ val := b, property := (_ : ∃ aS, ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) } ∈ S) } =
    { val := a,
      property :=
        (_ : ↑{ val := a, property := (_ : ∃ aS, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) } ∈ S) }
⊢ False

tactic: subst b
state_before: 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, ∀ (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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := b, property := (_ : ∃ aS, ∀ (b_1 : ↑S), s b_1 { val := b, property := aS } → r (↑b_1) b) }
e : b = a
⊢ False

tactic: exact irrefl _ h
state_before: 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, ∀ (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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
    { val := a, property := (_ : ∃ aS, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a) }
⊢ False

tactic: intro a
state_before: 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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
⊢ Unbounded r T

tactic: have : { b : S | ¬r b a }.Nonempty :=
  let ⟨b, bS, ba⟩ := hS a
  ⟨⟨b, bS⟩, ba⟩
state_before: 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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
a : α
⊢ ∃ b, b ∈ T ∧ ¬r b a

tactic: let b := (IsWellFounded.wf : WellFounded s).min _ this
state_before: 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, ∀ (b : ↑S), s b { val := a, property := aS } → r (↑b) a}
a : α
this : Set.Nonempty {b | ¬r (↑b) a}
⊢ ∃ b, b ∈ T ∧ ¬r b a

tactic: have ba : ¬r b a := IsWellFounded.wf.min_mem _ this
state_before: 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, ∀ (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, b ∈ T ∧ ¬r b a

tactic: refine' ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => _⟩, ba⟩
state_before: 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, ∀ (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, b ∈ T ∧ ¬r b a

tactic: rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl]
state_before: 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, ∀ (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) }

tactic: exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba)
state_before: 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, ∀ (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

tactic: intro b
state_before: α : 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, ∀ (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

tactic: cases b
state_before: α : 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, ∀ (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

tactic: rfl
state_before: 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, ∀ (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✝ }