l3lab/ntp-mathlib huggingface dataset:
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  

Proof state:
α : Type u_1
s t : Set α
k : ℕ∞
⊢ k ≤ encard s → ∃ t ⊆ s, encard t = k

Next tactic:
refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by 

Proof state:
α : Type u_1
s t : Set α
k : ℕ∞
x✝ : 0 ≤ encard s
⊢ encard ∅ = 0

Next tactic:
simp
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
  · 

Proof state:
case refine'_1
α : Type u_1
s t : Set α
k : ℕ∞
n : ℕ
IH : ↑n ≤ encard s → ∃ t ⊆ s, encard t = ↑n
hle : ↑(Nat.succ n) ≤ encard s
⊢ ∃ t ⊆ s, encard t = ↑(Nat.succ n)

Next tactic:
obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
  · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by 

Proof state:
α : Type u_1
s t : Set α
k : ℕ∞
n : ℕ
IH : ↑n ≤ encard s → ∃ t ⊆ s, encard t = ↑n
hle : ↑(Nat.succ n) ≤ encard s
⊢ ↑n ≤ ↑(Nat.succ n)

Next tactic:
simp
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
  · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
    

Proof state:
case refine'_1.intro.intro
α : Type u_1
s t : Set α
k : ℕ∞
n : ℕ
IH : ↑n ≤ encard s → ∃ t ⊆ s, encard t = ↑n
hle : ↑(Nat.succ n) ≤ encard s
t₀ : Set α
ht₀s : t₀ ⊆ s
ht₀ : encard t₀ = ↑n
⊢ ∃ t ⊆ s, encard t = ↑(Nat.succ n)

Next tactic:
simp only [Nat.cast_succ] at *
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
  · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
    simp only [Nat.cast_succ] at *
    

Proof state:
case refine'_1.intro.intro
α : Type u_1
s t : Set α
k : ℕ∞
n : ℕ
IH : ↑n ≤ encard s → ∃ t ⊆ s, encard t = ↑n
t₀ : Set α
ht₀s : t₀ ⊆ s
ht₀ : encard t₀ = ↑n
hle : ↑n + 1 ≤ encard s
⊢ ∃ t ⊆ s, encard t = ↑n + 1

Next tactic:
have hne : t₀ ≠ s
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
  · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
    simp only [Nat.cast_succ] at *
    have hne : t₀ ≠ s
    · 

Proof state:
case hne
α : Type u_1
s t : Set α
k : ℕ∞
n : ℕ
IH : ↑n ≤ encard s → ∃ t ⊆ s, encard t = ↑n
t₀ : Set α
ht₀s : t₀ ⊆ s
ht₀ : encard t₀ = ↑n
hle : ↑n + 1 ≤ encard s
⊢ t₀ ≠ s

Next tactic:
rintro rfl
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
  · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
    simp only [Nat.cast_succ] at *
    have hne : t₀ ≠ s
    · rintro rfl; 

Proof state:
case hne
α : Type u_1
t : Set α
k : ℕ∞
n : ℕ
t₀ : Set α
ht₀ : encard t₀ = ↑n
IH : ↑n ≤ encard t₀ → ∃ t ⊆ t₀, encard t = ↑n
ht₀s : t₀ ⊆ t₀
hle : ↑n + 1 ≤ encard t₀
⊢ False

Next tactic:
rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
  · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
    simp only [Nat.cast_succ] at *
    have hne : t₀ ≠ s
    · rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; 

Proof state:
case hne
α : Type u_1
t : Set α
k : ℕ∞
n : ℕ
t₀ : Set α
ht₀ : encard t₀ = ↑n
IH : ↑n ≤ encard t₀ → ∃ t ⊆ t₀, encard t = ↑n
ht₀s : t₀ ⊆ t₀
hle : n + 1 ≤ n
⊢ False

Next tactic:
simp at hle
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
  · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
    simp only [Nat.cast_succ] at *
    have hne : t₀ ≠ s
    · rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle
    

Proof state:
case refine'_1.intro.intro
α : Type u_1
s t : Set α
k : ℕ∞
n : ℕ
IH : ↑n ≤ encard s → ∃ t ⊆ s, encard t = ↑n
t₀ : Set α
ht₀s : t₀ ⊆ s
ht₀ : encard t₀ = ↑n
hle : ↑n + 1 ≤ encard s
hne : t₀ ≠ s
⊢ ∃ t ⊆ s, encard t = ↑n + 1

Next tactic:
obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne)
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
  · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
    simp only [Nat.cast_succ] at *
    have hne : t₀ ≠ s
    · rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle
    obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne)
    

Proof state:
case refine'_1.intro.intro.intro
α : Type u_1
s t : Set α
k : ℕ∞
n : ℕ
IH : ↑n ≤ encard s → ∃ t ⊆ s, encard t = ↑n
t₀ : Set α
ht₀s : t₀ ⊆ s
ht₀ : encard t₀ = ↑n
hle : ↑n + 1 ≤ encard s
hne : t₀ ≠ s
x : α
hx : x ∈ s ∧ x ∉ t₀
⊢ ∃ t ⊆ s, encard t = ↑n + 1

Next tactic:
exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
  · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
    simp only [Nat.cast_succ] at *
    have hne : t₀ ≠ s
    · rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle
    obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne)
    exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by 

Proof state:
α : Type u_1
s t : Set α
k : ℕ∞
n : ℕ
IH : ↑n ≤ encard s → ∃ t ⊆ s, encard t = ↑n
t₀ : Set α
ht₀s : t₀ ⊆ s
ht₀ : encard t₀ = ↑n
hle : ↑n + 1 ≤ encard s
hne : t₀ ≠ s
x : α
hx : x ∈ s ∧ x ∉ t₀
⊢ encard (insert x t₀) = ↑n + 1

Next tactic:
rw [encard_insert_of_not_mem hx.2, ht₀]
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
  · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
    simp only [Nat.cast_succ] at *
    have hne : t₀ ≠ s
    · rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle
    obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne)
    exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩
  

Proof state:
case refine'_2
α : Type u_1
s t : Set α
k : ℕ∞
⊢ (∀ (n : ℕ), ↑n ≤ encard s → ∃ t ⊆ s, encard t = ↑n) → ⊤ ≤ encard s → ∃ t ⊆ s, encard t = ⊤

Next tactic:
simp only [top_le_iff, encard_eq_top_iff]
theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
  revert hk
  refine' ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ _) _
  · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
    simp only [Nat.cast_succ] at *
    have hne : t₀ ≠ s
    · rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle
    obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne)
    exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩
  simp only [top_le_iff, encard_eq_top_iff]
  

Proof state:
case refine'_2
α : Type u_1
s t : Set α
k : ℕ∞
⊢ (∀ (n : ℕ), ↑n ≤ encard s → ∃ t ⊆ s, encard t = ↑n) → Set.Infinite s → ∃ t ⊆ s, Set.Infinite t

Next tactic:
exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩
theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
    ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
  

Proof state:
α : Type u_1
s t : Set α
k : ℕ∞
hst : s ⊆ t
hsk : encard s ≤ k
hkt : k ≤ encard t
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ encard r = k

Next tactic:
obtain (hs | hs) := eq_or_ne s.encard ⊤
theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
    ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
  obtain (hs | hs) := eq_or_ne s.encard ⊤
  · 

Proof state:
case inl
α : Type u_1
s t : Set α
k : ℕ∞
hst : s ⊆ t
hsk : encard s ≤ k
hkt : k ≤ encard t
hs : encard s = ⊤
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ encard r = k

Next tactic:
rw [hs, top_le_iff] at hsk
theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
    ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
  obtain (hs | hs) := eq_or_ne s.encard ⊤
  · rw [hs, top_le_iff] at hsk; 

Proof state:
case inl
α : Type u_1
s t : Set α
k : ℕ∞
hst : s ⊆ t
hsk : k = ⊤
hkt : k ≤ encard t
hs : encard s = ⊤
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ encard r = k

Next tactic:
subst hsk
theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
    ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
  obtain (hs | hs) := eq_or_ne s.encard ⊤
  · rw [hs, top_le_iff] at hsk; subst hsk; 

Proof state:
case inl
α : Type u_1
s t : Set α
hst : s ⊆ t
hs : encard s = ⊤
hkt : ⊤ ≤ encard t
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ encard r = ⊤

Next tactic:
exact ⟨s, Subset.rfl, hst, hs⟩
theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
    ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
  obtain (hs | hs) := eq_or_ne s.encard ⊤
  · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
  

Proof state:
case inr
α : Type u_1
s t : Set α
k : ℕ∞
hst : s ⊆ t
hsk : encard s ≤ k
hkt : k ≤ encard t
hs : encard s ≠ ⊤
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ encard r = k

Next tactic:
obtain ⟨k, rfl⟩ := exists_add_of_le hsk
theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
    ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
  obtain (hs | hs) := eq_or_ne s.encard ⊤
  · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
  obtain ⟨k, rfl⟩ := exists_add_of_le hsk
  

Proof state:
case inr.intro
α : Type u_1
s t : Set α
hst : s ⊆ t
hs : encard s ≠ ⊤
k : ℕ∞
hsk : encard s ≤ encard s + k
hkt : encard s + k ≤ encard t
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ encard r = encard s + k

Next tactic:
obtain ⟨k', hk'⟩ := exists_add_of_le hkt
theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
    ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
  obtain (hs | hs) := eq_or_ne s.encard ⊤
  · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
  obtain ⟨k, rfl⟩ := exists_add_of_le hsk
  obtain ⟨k', hk'⟩ := exists_add_of_le hkt
  

Proof state:
case inr.intro.intro
α : Type u_1
s t : Set α
hst : s ⊆ t
hs : encard s ≠ ⊤
k : ℕ∞
hsk : encard s ≤ encard s + k
hkt : encard s + k ≤ encard t
k' : ℕ∞
hk' : encard t = encard s + k + k'
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ encard r = encard s + k

Next tactic:
have hk : k ≤ encard (t \ s)
theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
    ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
  obtain (hs | hs) := eq_or_ne s.encard ⊤
  · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
  obtain ⟨k, rfl⟩ := exists_add_of_le hsk
  obtain ⟨k', hk'⟩ := exists_add_of_le hkt
  have hk : k ≤ encard (t \ s)
  · 

Proof state:
case hk
α : Type u_1
s t : Set α
hst : s ⊆ t
hs : encard s ≠ ⊤
k : ℕ∞
hsk : encard s ≤ encard s + k
hkt : encard s + k ≤ encard t
k' : ℕ∞
hk' : encard t = encard s + k + k'
⊢ k ≤ encard (t \ s)

Next tactic:
rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt
theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
    ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
  obtain (hs | hs) := eq_or_ne s.encard ⊤
  · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
  obtain ⟨k, rfl⟩ := exists_add_of_le hsk
  obtain ⟨k', hk'⟩ := exists_add_of_le hkt
  have hk : k ≤ encard (t \ s)
  · rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt
    

Proof state:
case hk
α : Type u_1
s t : Set α
hst : s ⊆ t
hs : encard s ≠ ⊤
k : ℕ∞
hsk : encard s ≤ encard s + k
hkt : k + encard s ≤ encard (t \ s) + encard s
k' : ℕ∞
hk' : encard t = encard s + k + k'
⊢ k ≤ encard (t \ s)

Next tactic:
exact WithTop.le_of_add_le_add_right hs hkt
theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
    ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
  obtain (hs | hs) := eq_or_ne s.encard ⊤
  · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
  obtain ⟨k, rfl⟩ := exists_add_of_le hsk
  obtain ⟨k', hk'⟩ := exists_add_of_le hkt
  have hk : k ≤ encard (t \ s)
  · rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt
    exact WithTop.le_of_add_le_add_right hs hkt
  

Proof state:
case inr.intro.intro
α : Type u_1
s t : Set α
hst : s ⊆ t
hs : encard s ≠ ⊤
k : ℕ∞
hsk : encard s ≤ encard s + k
hkt : encard s + k ≤ encard t
k' : ℕ∞
hk' : encard t = encard s + k + k'
hk : k ≤ encard (t \ s)
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ encard r = encard s + k

Next tactic:
obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk
theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
    ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
  obtain (hs | hs) := eq_or_ne s.encard ⊤
  · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
  obtain ⟨k, rfl⟩ := exists_add_of_le hsk
  obtain ⟨k', hk'⟩ := exists_add_of_le hkt
  have hk : k ≤ encard (t \ s)
  · rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt
    exact WithTop.le_of_add_le_add_right hs hkt
  obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk
  

Proof state:
case inr.intro.intro.intro.intro
α : Type u_1
s t : Set α
hst : s ⊆ t
hs : encard s ≠ ⊤
k' : ℕ∞
r' : Set α
hr' : r' ⊆ t \ s
hsk : encard s ≤ encard s + encard r'
hkt : encard s + encard r' ≤ encard t
hk' : encard t = encard s + encard r' + k'
hk : encard r' ≤ encard (t \ s)
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ encard r = encard s + encard r'

Next tactic:
refine' ⟨s ∪ r', subset_union_left _ _, union_subset hst (hr'.trans (diff_subset _ _)), _⟩
theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
    ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
  obtain (hs | hs) := eq_or_ne s.encard ⊤
  · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
  obtain ⟨k, rfl⟩ := exists_add_of_le hsk
  obtain ⟨k', hk'⟩ := exists_add_of_le hkt
  have hk : k ≤ encard (t \ s)
  · rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt
    exact WithTop.le_of_add_le_add_right hs hkt
  obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk
  refine' ⟨s ∪ r', subset_union_left _ _, union_subset hst (hr'.trans (diff_subset _ _)), _⟩
  

Proof state:
case inr.intro.intro.intro.intro
α : Type u_1
s t : Set α
hst : s ⊆ t
hs : encard s ≠ ⊤
k' : ℕ∞
r' : Set α
hr' : r' ⊆ t \ s
hsk : encard s ≤ encard s + encard r'
hkt : encard s + encard r' ≤ encard t
hk' : encard t = encard s + encard r' + k'
hk : encard r' ≤ encard (t \ s)
⊢ encard (s ∪ r') = encard s + encard r'

Next tactic:
rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)]
theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by
  

Proof state:
α : Type u_2
β : Type u_1
s✝ t✝ s : Set α
t : Set β
f : α → β
h : InjOn f s
⊢ encard (f '' s) = encard s

Next tactic:
rw [encard, PartENat.card_image_of_injOn h, encard]
theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by
  

Proof state:
α : Type u_1
β : Type u_2
s✝ t✝ s : Set α
t : Set β
f : α → β
e : ↑s ≃ ↑t
⊢ encard s = encard t

Next tactic:
rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, PartENat.card_congr e]
theorem _root_.Function.Embedding.enccard_le (e : s ↪ t) : s.encard ≤ t.encard := by
  

Proof state:
α : Type u_2
β : Type u_1
s✝ t✝ s : Set α
t : Set β
f : α → β
e : ↑s ↪ ↑t
⊢ encard s ≤ encard t

Next tactic:
rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image]
theorem _root_.Function.Embedding.enccard_le (e : s ↪ t) : s.encard ≤ t.encard := by
  rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image]
  

Proof state:
α : Type u_2
β : Type u_1
s✝ t✝ s : Set α
t : Set β
f : α → β
e : ↑s ↪ ↑t
⊢ encard ((fun a => ↑a) '' (⇑e '' univ)) ≤ encard t

Next tactic:
exact encard_mono (by simp)
theorem _root_.Function.Embedding.enccard_le (e : s ↪ t) : s.encard ≤ t.encard := by
  rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image]
  exact encard_mono (by 

Proof state:
α : Type u_2
β : Type u_1
s✝ t✝ s : Set α
t : Set β
f : α → β
e : ↑s ↪ ↑t
⊢ (fun a => ↑a) '' (⇑e '' univ) ≤ t

Next tactic:
simp
theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by
  

Proof state:
α : Type u_1
β : Type u_2
s✝¹ t✝ s✝ : Set α
t : Set β
f✝ f : α → β
s : Set α
⊢ encard (f '' s) ≤ encard s

Next tactic:
obtain (h | h) := isEmpty_or_nonempty α
theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by
  obtain (h | h) := isEmpty_or_nonempty α
  · 

Proof state:
case inl
α : Type u_1
β : Type u_2
s✝¹ t✝ s✝ : Set α
t : Set β
f✝ f : α → β
s : Set α
h : IsEmpty α
⊢ encard (f '' s) ≤ encard s

Next tactic:
rw [s.eq_empty_of_isEmpty]
theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by
  obtain (h | h) := isEmpty_or_nonempty α
  · rw [s.eq_empty_of_isEmpty]; 

Proof state:
case inl
α : Type u_1
β : Type u_2
s✝¹ t✝ s✝ : Set α
t : Set β
f✝ f : α → β
s : Set α
h : IsEmpty α
⊢ encard (f '' ∅) ≤ encard ∅

Next tactic:
simp
theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by
  obtain (h | h) := isEmpty_or_nonempty α
  · rw [s.eq_empty_of_isEmpty]; simp
  

Proof state:
case inr
α : Type u_1
β : Type u_2
s✝¹ t✝ s✝ : Set α
t : Set β
f✝ f : α → β
s : Set α
h : Nonempty α
⊢ encard (f '' s) ≤ encard s

Next tactic:
rw [← (f.invFunOn_injOn_image s).encard_image]
theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by
  obtain (h | h) := isEmpty_or_nonempty α
  · rw [s.eq_empty_of_isEmpty]; simp
  rw [← (f.invFunOn_injOn_image s).encard_image]
  

Proof state:
case inr
α : Type u_1
β : Type u_2
s✝¹ t✝ s✝ : Set α
t : Set β
f✝ f : α → β
s : Set α
h : Nonempty α
⊢ encard (Function.invFunOn f s '' (f '' s)) ≤ encard s

Next tactic:
apply encard_le_of_subset
theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by
  obtain (h | h) := isEmpty_or_nonempty α
  · rw [s.eq_empty_of_isEmpty]; simp
  rw [← (f.invFunOn_injOn_image s).encard_image]
  apply encard_le_of_subset
  

Proof state:
case inr.h
α : Type u_1
β : Type u_2
s✝¹ t✝ s✝ : Set α
t : Set β
f✝ f : α → β
s : Set α
h : Nonempty α
⊢ Function.invFunOn f s '' (f '' s) ⊆ s

Next tactic:
exact f.invFunOn_image_image_subset s
theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) :
    InjOn f s := by
  

Proof state:
α : Type u_1
β : Type u_2
s✝ t✝ s : Set α
t : Set β
f : α → β
hs : Set.Finite s
h : encard (f '' s) = encard s
⊢ InjOn f s

Next tactic:
obtain (h' | hne) := isEmpty_or_nonempty α
theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) :
    InjOn f s := by
  obtain (h' | hne) := isEmpty_or_nonempty α
  · 

Proof state:
case inl
α : Type u_1
β : Type u_2
s✝ t✝ s : Set α
t : Set β
f : α → β
hs : Set.Finite s
h : encard (f '' s) = encard s
h' : IsEmpty α
⊢ InjOn f s

Next tactic:
rw [s.eq_empty_of_isEmpty]
theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) :
    InjOn f s := by
  obtain (h' | hne) := isEmpty_or_nonempty α
  · rw [s.eq_empty_of_isEmpty]; 

Proof state:
case inl
α : Type u_1
β : Type u_2
s✝ t✝ s : Set α
t : Set β
f : α → β
hs : Set.Finite s
h : encard (f '' s) = encard s
h' : IsEmpty α
⊢ InjOn f ∅

Next tactic:
simp
theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) :
    InjOn f s := by
  obtain (h' | hne) := isEmpty_or_nonempty α
  · rw [s.eq_empty_of_isEmpty]; simp
  

Proof state:
case inr
α : Type u_1
β : Type u_2
s✝ t✝ s : Set α
t : Set β
f : α → β
hs : Set.Finite s
h : encard (f '' s) = encard s
hne : Nonempty α
⊢ InjOn f s

Next tactic:
rw [← (f.invFunOn_injOn_image s).encard_image] at h
theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) :
    InjOn f s := by
  obtain (h' | hne) := isEmpty_or_nonempty α
  · rw [s.eq_empty_of_isEmpty]; simp
  rw [← (f.invFunOn_injOn_image s).encard_image] at h
  

Proof state:
case inr
α : Type u_1
β : Type u_2
s✝ t✝ s : Set α
t : Set β
f : α → β
hs : Set.Finite s
hne : Nonempty α
h : encard (Function.invFunOn f s '' (f '' s)) = encard s
⊢ InjOn f s

Next tactic:
rw [injOn_iff_invFunOn_image_image_eq_self]
theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) :
    InjOn f s := by
  obtain (h' | hne) := isEmpty_or_nonempty α
  · rw [s.eq_empty_of_isEmpty]; simp
  rw [← (f.invFunOn_injOn_image s).encard_image] at h
  rw [injOn_iff_invFunOn_image_image_eq_self]
  

Proof state:
case inr
α : Type u_1
β : Type u_2
s✝ t✝ s : Set α
t : Set β
f : α → β
hs : Set.Finite s
hne : Nonempty α
h : encard (Function.invFunOn f s '' (f '' s)) = encard s
⊢ Function.invFunOn f s '' (f '' s) = s

Next tactic:
exact hs.eq_of_subset_of_encard_le (f.invFunOn_image_image_subset s) h.symm.le
theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t ⊆ range f) :
    (f ⁻¹' t).encard = t.encard := by
  

Proof state:
α : Type u_1
β : Type u_2
s✝ t✝ s : Set α
t : Set β
f : α → β
hf : Function.Injective f
ht : t ⊆ range f
⊢ encard (f ⁻¹' t) = encard t

Next tactic:
rw [← hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht]
theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) :
    s.encard ≤ t.encard := by
  

Proof state:
α : Type u_2
β : Type u_1
s✝ t✝ s : Set α
t : Set β
f : α → β
hf : MapsTo f s t
f_inj : InjOn f s
⊢ encard s ≤ encard t

Next tactic:
rw [← f_inj.encard_image]
theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) :
    s.encard ≤ t.encard := by
  rw [← f_inj.encard_image]; 

Proof state:
α : Type u_2
β : Type u_1
s✝ t✝ s : Set α
t : Set β
f : α → β
hf : MapsTo f s t
f_inj : InjOn f s
⊢ encard (f '' s) ≤ encard t

Next tactic:
apply encard_le_of_subset
theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) :
    s.encard ≤ t.encard := by
  rw [← f_inj.encard_image]; apply encard_le_of_subset; 

Proof state:
case h
α : Type u_2
β : Type u_1
s✝ t✝ s : Set α
t : Set β
f : α → β
hf : MapsTo f s t
f_inj : InjOn f s
⊢ f '' s ⊆ t

Next tactic:
rintro _ ⟨x, hx, rfl⟩
theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) :
    s.encard ≤ t.encard := by
  rw [← f_inj.encard_image]; apply encard_le_of_subset; rintro _ ⟨x, hx, rfl⟩; 

Proof state:
case h.intro.intro
α : Type u_2
β : Type u_1
s✝ t✝ s : Set α
t : Set β
f : α → β
hf : MapsTo f s t
f_inj : InjOn f s
x : α
hx : x ∈ s
⊢ f x ∈ t

Next tactic:
exact hf hx