theorem exists_min_bad_of_exists_bad (r : α → α → Prop) (rk : α → ℕ) (s : Set α) :
    (∃ f, IsBadSeq r s f) → ∃ f, IsBadSeq r s f ∧ ∀ n, IsMinBadSeq r rk s n f := by
  rintro ⟨f0, hf0 : IsBadSeq r s f0⟩
  let fs : ∀ n : ℕ, { f : ℕ → α // IsBadSeq r s f ∧ IsMinBadSeq r rk s n f } := by
    refine' Nat.rec _ fun n fn => _
    · exact ⟨(minBadSeqOfBadSeq r rk s 0 f0 hf0).1, (minBadSeqOfBadSeq r rk s 0 f0 hf0).2.2⟩
    · exact ⟨(minBadSeqOfBadSeq r rk s (n + 1) fn.1 fn.2.1).1,
        (minBadSeqOfBadSeq r rk s (n + 1) fn.1 fn.2.1).2.2⟩
  have h : ∀ m n, m ≤ n → (fs m).1 m = (fs n).1 m := fun m n mn => by
    obtain ⟨k, rfl⟩ := exists_add_of_le mn; clear mn
    induction' k with k ih
    · rfl
    · rw [ih, (minBadSeqOfBadSeq r rk s (m + k + 1) (fs (m + k)).1 (fs (m + k)).2.1).2.1 m
        (Nat.lt_succ_iff.2 (Nat.add_le_add_left k.zero_le m))]
      rfl
  refine ⟨fun n => (fs n).1 n, ⟨fun n => (fs n).2.1.1 n, fun m n mn => ?_⟩, fun n g hg1 hg2 => ?_⟩
  · dsimp
    

Proof state:
case intro.refine_1
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r✝ r : α → α → Prop
rk : α → ℕ
s : Set α
f0 : ℕ → α
hf0 : IsBadSeq r s f0
fs : (n : ℕ) → { f // IsBadSeq r s f ∧ IsMinBadSeq r rk s n f } :=
  fun t =>
    Nat.rec
      { val := ↑(minBadSeqOfBadSeq r rk s 0 f0 hf0),
        property :=
          (_ :
            IsBadSeq r s ↑(minBadSeqOfBadSeq r rk s 0 f0 hf0) ∧
              IsMinBadSeq r rk s 0 ↑(minBadSeqOfBadSeq r rk s 0 f0 hf0)) }
      (fun n fn =>
        { val := ↑(minBadSeqOfBadSeq r rk s (n + 1) ↑fn (_ : IsBadSeq r s ↑fn)),
          property :=
            (_ :
              IsBadSeq r s ↑(minBadSeqOfBadSeq r rk s (n + 1) ↑fn (_ : IsBadSeq r s ↑fn)) ∧
                IsMinBadSeq r rk s (n + 1) ↑(minBadSeqOfBadSeq r rk s (n + 1) ↑fn (_ : IsBadSeq r s ↑fn))) })
      t
h : ∀ (m n : ℕ), m ≤ n → ↑(fs m) m = ↑(fs n) m
m n : ℕ
mn : m < n
⊢ ¬r
      (↑(Nat.rec
            { val := ↑(minBadSeqOfBadSeq r rk s 0 f0 hf0),
              property :=
                (_ :
                  IsBadSeq r s ↑(minBadSeqOfBadSeq r rk s 0 f0 hf0) ∧
                    IsMinBadSeq r rk s 0 ↑(minBadSeqOfBadSeq r rk s 0 f0 hf0)) }
            (fun n fn =>
              { val := ↑(minBadSeqOfBadSeq r rk s (n + 1) ↑fn (_ : IsBadSeq r s ↑fn)),
                property :=
                  (_ :
                    IsBadSeq r s ↑(minBadSeqOfBadSeq r rk s (n + 1) ↑fn (_ : IsBadSeq r s ↑fn)) ∧
                      IsMinBadSeq r rk s (n + 1) ↑(minBadSeqOfBadSeq r rk s (n + 1) ↑fn (_ : IsBadSeq r s ↑fn))) })
            m)
        m)
      (↑(Nat.rec
            { val := ↑(minBadSeqOfBadSeq r rk s 0 f0 hf0),
              property :=
                (_ :
                  IsBadSeq r s ↑(minBadSeqOfBadSeq r rk s 0 f0 hf0) ∧
                    IsMinBadSeq r rk s 0 ↑(minBadSeqOfBadSeq r rk s 0 f0 hf0)) }
            (fun n fn =>
              { val := ↑(minBadSeqOfBadSeq r rk s (n + 1) ↑fn (_ : IsBadSeq r s ↑fn)),
                property :=
                  (_ :
                    IsBadSeq r s ↑(minBadSeqOfBadSeq r rk s (n + 1) ↑fn (_ : IsBadSeq r s ↑fn)) ∧
                      IsMinBadSeq r rk s (n + 1) ↑(minBadSeqOfBadSeq r rk s (n + 1) ↑fn (_ : IsBadSeq r s ↑fn))) })
            n)
        n)

Next tactic:
rw [h m n mn.le]