l3lab/ntp-mathlib huggingface dataset:
theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by
  obtain (h | h) := (s ∪ t).finite_or_infinite
  · to_encard_tac
    rw [h.cast_ncard_eq, (h.subset (subset_union_left _ _)).cast_ncard_eq,
      (h.subset (subset_union_right _ _)).cast_ncard_eq]
    apply encard_union_le
  

Proof state:
case inr
α : Type u_1
s✝ t✝ s t : Set α
h : Set.Infinite (s ∪ t)
⊢ ncard (s ∪ t) ≤ ncard s + ncard t

Next tactic:
rw [h.ncard]
theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by
  obtain (h | h) := (s ∪ t).finite_or_infinite
  · to_encard_tac
    rw [h.cast_ncard_eq, (h.subset (subset_union_left _ _)).cast_ncard_eq,
      (h.subset (subset_union_right _ _)).cast_ncard_eq]
    apply encard_union_le
  rw [h.ncard]
  

Proof state:
case inr
α : Type u_1
s✝ t✝ s t : Set α
h : Set.Infinite (s ∪ t)
⊢ 0 ≤ ncard s + ncard t

Next tactic:
apply zero_le
theorem ncard_union_eq (h : Disjoint s t) (hs : s.Finite := by toFinite_tac)
    (ht : t.Finite := by toFinite_tac) : (s ∪ t).ncard = s.ncard + t.ncard := by
  

Proof state:
α : Type u_1
s t : Set α
h : Disjoint s t
hs : autoParam (Set.Finite s) _auto✝
ht : autoParam (Set.Finite t) _auto✝
⊢ ncard (s ∪ t) = ncard s + ncard t

Next tactic:
to_encard_tac
theorem ncard_union_eq (h : Disjoint s t) (hs : s.Finite := by toFinite_tac)
    (ht : t.Finite := by toFinite_tac) : (s ∪ t).ncard = s.ncard + t.ncard := by
  to_encard_tac
  

Proof state:
α : Type u_1
s t : Set α
h : Disjoint s t
hs : autoParam (Set.Finite s) _auto✝
ht : autoParam (Set.Finite t) _auto✝
⊢ ↑(ncard (s ∪ t)) = ↑(ncard s) + ↑(ncard t)

Next tactic:
rw [hs.cast_ncard_eq, ht.cast_ncard_eq, (hs.union ht).cast_ncard_eq, encard_union_eq h]
theorem ncard_diff_add_ncard_of_subset (h : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
    (t \ s).ncard + s.ncard = t.ncard := by
  

Proof state:
α : Type u_1
s t : Set α
h : s ⊆ t
ht : autoParam (Set.Finite t) _auto✝
⊢ ncard (t \ s) + ncard s = ncard t

Next tactic:
to_encard_tac
theorem ncard_diff_add_ncard_of_subset (h : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
    (t \ s).ncard + s.ncard = t.ncard := by
  to_encard_tac
  

Proof state:
α : Type u_1
s t : Set α
h : s ⊆ t
ht : autoParam (Set.Finite t) _auto✝
⊢ ↑(ncard (t \ s)) + ↑(ncard s) = ↑(ncard t)

Next tactic:
rw [ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq, (ht.diff _).cast_ncard_eq,
    encard_diff_add_encard_of_subset h]
theorem ncard_diff (h : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
    (t \ s).ncard = t.ncard - s.ncard := by
  

Proof state:
α : Type u_1
s t : Set α
h : s ⊆ t
ht : autoParam (Set.Finite t) _auto✝
⊢ ncard (t \ s) = ncard t - ncard s

Next tactic:
rw [← ncard_diff_add_ncard_of_subset h ht, add_tsub_cancel_right]
theorem ncard_le_ncard_diff_add_ncard (s t : Set α) (ht : t.Finite := by toFinite_tac) :
    s.ncard ≤ (s \ t).ncard + t.ncard := by
  

Proof state:
α : Type u_1
s✝ t✝ s t : Set α
ht : autoParam (Set.Finite t) _auto✝
⊢ ncard s ≤ ncard (s \ t) + ncard t

Next tactic:
cases' s.finite_or_infinite with hs hs
theorem ncard_le_ncard_diff_add_ncard (s t : Set α) (ht : t.Finite := by toFinite_tac) :
    s.ncard ≤ (s \ t).ncard + t.ncard := by
  cases' s.finite_or_infinite with hs hs
  · 

Proof state:
case inl
α : Type u_1
s✝ t✝ s t : Set α
ht : autoParam (Set.Finite t) _auto✝
hs : Set.Finite s
⊢ ncard s ≤ ncard (s \ t) + ncard t

Next tactic:
to_encard_tac
theorem ncard_le_ncard_diff_add_ncard (s t : Set α) (ht : t.Finite := by toFinite_tac) :
    s.ncard ≤ (s \ t).ncard + t.ncard := by
  cases' s.finite_or_infinite with hs hs
  · to_encard_tac
    

Proof state:
case inl
α : Type u_1
s✝ t✝ s t : Set α
ht : autoParam (Set.Finite t) _auto✝
hs : Set.Finite s
⊢ ↑(ncard s) ≤ ↑(ncard (s \ t)) + ↑(ncard t)

Next tactic:
rw [ht.cast_ncard_eq, hs.cast_ncard_eq, (hs.diff _).cast_ncard_eq]
theorem ncard_le_ncard_diff_add_ncard (s t : Set α) (ht : t.Finite := by toFinite_tac) :
    s.ncard ≤ (s \ t).ncard + t.ncard := by
  cases' s.finite_or_infinite with hs hs
  · to_encard_tac
    rw [ht.cast_ncard_eq, hs.cast_ncard_eq, (hs.diff _).cast_ncard_eq]
    

Proof state:
case inl
α : Type u_1
s✝ t✝ s t : Set α
ht : autoParam (Set.Finite t) _auto✝
hs : Set.Finite s
⊢ encard s ≤ encard (s \ t) + encard t

Next tactic:
apply encard_le_encard_diff_add_encard
theorem ncard_le_ncard_diff_add_ncard (s t : Set α) (ht : t.Finite := by toFinite_tac) :
    s.ncard ≤ (s \ t).ncard + t.ncard := by
  cases' s.finite_or_infinite with hs hs
  · to_encard_tac
    rw [ht.cast_ncard_eq, hs.cast_ncard_eq, (hs.diff _).cast_ncard_eq]
    apply encard_le_encard_diff_add_encard
  

Proof state:
case inr
α : Type u_1
s✝ t✝ s t : Set α
ht : autoParam (Set.Finite t) _auto✝
hs : Set.Infinite s
⊢ ncard s ≤ ncard (s \ t) + ncard t

Next tactic:
convert Nat.zero_le _
theorem ncard_le_ncard_diff_add_ncard (s t : Set α) (ht : t.Finite := by toFinite_tac) :
    s.ncard ≤ (s \ t).ncard + t.ncard := by
  cases' s.finite_or_infinite with hs hs
  · to_encard_tac
    rw [ht.cast_ncard_eq, hs.cast_ncard_eq, (hs.diff _).cast_ncard_eq]
    apply encard_le_encard_diff_add_encard
  convert Nat.zero_le _
  

Proof state:
case h.e'_3
α : Type u_1
s✝ t✝ s t : Set α
ht : autoParam (Set.Finite t) _auto✝
hs : Set.Infinite s
⊢ ncard s = 0

Next tactic:
rw [hs.ncard]
theorem le_ncard_diff (s t : Set α) (hs : s.Finite := by toFinite_tac) :
    t.ncard - s.ncard ≤ (t \ s).ncard :=
  tsub_le_iff_left.mpr (by 

Proof state:
α : Type u_1
s✝ t✝ s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard t ≤ ncard s + ncard (t \ s)

Next tactic:
rw [add_comm]
theorem le_ncard_diff (s t : Set α) (hs : s.Finite := by toFinite_tac) :
    t.ncard - s.ncard ≤ (t \ s).ncard :=
  tsub_le_iff_left.mpr (by rw [add_comm]; 

Proof state:
α : Type u_1
s✝ t✝ s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard t ≤ ncard (t \ s) + ncard s

Next tactic:
apply ncard_le_ncard_diff_add_ncard _ _ hs
theorem ncard_diff_add_ncard (s t : Set α) (hs : s.Finite := by toFinite_tac)
  (ht : t.Finite := by toFinite_tac) :
    (s \ t).ncard + t.ncard = (s ∪ t).ncard := by
  

Proof state:
α : Type u_1
s✝ t✝ s t : Set α
hs : autoParam (Set.Finite s) _auto✝
ht : autoParam (Set.Finite t) _auto✝
⊢ ncard (s \ t) + ncard t = ncard (s ∪ t)

Next tactic:
rw [← ncard_union_eq disjoint_sdiff_left (hs.diff _) ht, diff_union_self]
theorem diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.Finite := by toFinite_tac) :
    (t \ s).Nonempty := by
  

Proof state:
α : Type u_1
s t : Set α
h : ncard s < ncard t
hs : autoParam (Set.Finite s) _auto✝
⊢ Set.Nonempty (t \ s)

Next tactic:
rw [Set.nonempty_iff_ne_empty, Ne.def, diff_eq_empty]
theorem diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.Finite := by toFinite_tac) :
    (t \ s).Nonempty := by
  rw [Set.nonempty_iff_ne_empty, Ne.def, diff_eq_empty]
  

Proof state:
α : Type u_1
s t : Set α
h : ncard s < ncard t
hs : autoParam (Set.Finite s) _auto✝
⊢ ¬t ⊆ s

Next tactic:
exact fun h' ↦ h.not_le (ncard_le_of_subset h' hs)
@[simp] theorem ncard_inter_add_ncard_diff_eq_ncard (s t : Set α)
    (hs : s.Finite := by toFinite_tac) : (s ∩ t).ncard + (s \ t).ncard = s.ncard := by
  

Proof state:
α : Type u_1
s✝ t✝ s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard (s ∩ t) + ncard (s \ t) = ncard s

Next tactic:
rw [← ncard_union_eq (disjoint_of_subset_left (inter_subset_right _ _) disjoint_sdiff_right)
    (hs.inter_of_left _) (hs.diff _), union_comm, diff_union_inter]
theorem ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff (hs : s.Finite := by toFinite_tac)
    (ht : t.Finite := by toFinite_tac) : s.ncard = t.ncard ↔ (s \ t).ncard = (t \ s).ncard := by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
ht : autoParam (Set.Finite t) _auto✝
⊢ ncard s = ncard t ↔ ncard (s \ t) = ncard (t \ s)

Next tactic:
rw [← ncard_inter_add_ncard_diff_eq_ncard s t hs, ← ncard_inter_add_ncard_diff_eq_ncard t s ht,
    inter_comm, add_right_inj]
theorem ncard_le_ncard_iff_ncard_diff_le_ncard_diff (hs : s.Finite := by toFinite_tac)
    (ht : t.Finite := by toFinite_tac) : s.ncard ≤ t.ncard ↔ (s \ t).ncard ≤ (t \ s).ncard := by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
ht : autoParam (Set.Finite t) _auto✝
⊢ ncard s ≤ ncard t ↔ ncard (s \ t) ≤ ncard (t \ s)

Next tactic:
rw [← ncard_inter_add_ncard_diff_eq_ncard s t hs, ← ncard_inter_add_ncard_diff_eq_ncard t s ht,
    inter_comm, add_le_add_iff_left]
theorem ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff (hs : s.Finite := by toFinite_tac)
    (ht : t.Finite := by toFinite_tac) : s.ncard < t.ncard ↔ (s \ t).ncard < (t \ s).ncard := by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
ht : autoParam (Set.Finite t) _auto✝
⊢ ncard s < ncard t ↔ ncard (s \ t) < ncard (t \ s)

Next tactic:
rw [← ncard_inter_add_ncard_diff_eq_ncard s t hs, ← ncard_inter_add_ncard_diff_eq_ncard t s ht,
    inter_comm, add_lt_add_iff_left]
theorem ncard_add_ncard_compl (s : Set α) (hs : s.Finite := by toFinite_tac)
    (hsc : sᶜ.Finite := by toFinite_tac) : s.ncard + sᶜ.ncard = Nat.card α := by
  

Proof state:
α : Type u_1
s✝ t s : Set α
hs : autoParam (Set.Finite s) _auto✝
hsc : autoParam (Set.Finite sᶜ) _auto✝
⊢ ncard s + ncard sᶜ = Nat.card α

Next tactic:
rw [← ncard_univ, ← ncard_union_eq (@disjoint_compl_right _ _ s) hs hsc, union_compl_self]
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  

Proof state:
α : Type u_1
s t : Set α
i : ℕ
h₁ : i + ncard s ≤ ncard t
h₂ : s ⊆ t
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ ncard r = i + ncard s

Next tactic:
cases' t.finite_or_infinite with ht ht
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · 

Proof state:
case inl
α : Type u_1
s t : Set α
i : ℕ
h₁ : i + ncard s ≤ ncard t
h₂ : s ⊆ t
ht : Set.Finite t
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ ncard r = i + ncard s

Next tactic:
rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
    

Proof state:
case inl
α : Type u_1
s t : Set α
i : ℕ
h₂ : s ⊆ t
ht : Set.Finite t
h₁ : i + Finset.card (Finite.toFinset (_ : Set.Finite s)) ≤ ncard t
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ ncard r = i + Finset.card (Finite.toFinset (_ : Set.Finite s))

Next tactic:
rw [ncard_eq_toFinset_card t ht] at h₁
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
    rw [ncard_eq_toFinset_card t ht] at h₁
    

Proof state:
case inl
α : Type u_1
s t : Set α
i : ℕ
h₂ : s ⊆ t
ht : Set.Finite t
h₁ : i + Finset.card (Finite.toFinset (_ : Set.Finite s)) ≤ Finset.card (Finite.toFinset ht)
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ ncard r = i + Finset.card (Finite.toFinset (_ : Set.Finite s))

Next tactic:
obtain ⟨r', hsr', hr't, hr'⟩ := Finset.exists_intermediate_set _ h₁ (by simpa)
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
    rw [ncard_eq_toFinset_card t ht] at h₁
    obtain ⟨r', hsr', hr't, hr'⟩ := Finset.exists_intermediate_set _ h₁ (by 

Proof state:
α : Type u_1
s t : Set α
i : ℕ
h₂ : s ⊆ t
ht : Set.Finite t
h₁ : i + Finset.card (Finite.toFinset (_ : Set.Finite s)) ≤ Finset.card (Finite.toFinset ht)
⊢ Finite.toFinset (_ : Set.Finite s) ⊆ Finite.toFinset ht

Next tactic:
simpa
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
    rw [ncard_eq_toFinset_card t ht] at h₁
    obtain ⟨r', hsr', hr't, hr'⟩ := Finset.exists_intermediate_set _ h₁ (by simpa)
    

Proof state:
case inl.intro.intro.intro
α : Type u_1
s t : Set α
i : ℕ
h₂ : s ⊆ t
ht : Set.Finite t
h₁ : i + Finset.card (Finite.toFinset (_ : Set.Finite s)) ≤ Finset.card (Finite.toFinset ht)
r' : Finset α
hsr' : Finite.toFinset (_ : Set.Finite s) ⊆ r'
hr't : r' ⊆ Finite.toFinset ht
hr' : Finset.card r' = i + Finset.card (Finite.toFinset (_ : Set.Finite s))
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ ncard r = i + Finset.card (Finite.toFinset (_ : Set.Finite s))

Next tactic:
exact ⟨r', by simpa using hsr', by simpa using hr't, by rw [← hr', ncard_coe_Finset]⟩
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
    rw [ncard_eq_toFinset_card t ht] at h₁
    obtain ⟨r', hsr', hr't, hr'⟩ := Finset.exists_intermediate_set _ h₁ (by simpa)
    exact ⟨r', by 

Proof state:
α : Type u_1
s t : Set α
i : ℕ
h₂ : s ⊆ t
ht : Set.Finite t
h₁ : i + Finset.card (Finite.toFinset (_ : Set.Finite s)) ≤ Finset.card (Finite.toFinset ht)
r' : Finset α
hsr' : Finite.toFinset (_ : Set.Finite s) ⊆ r'
hr't : r' ⊆ Finite.toFinset ht
hr' : Finset.card r' = i + Finset.card (Finite.toFinset (_ : Set.Finite s))
⊢ s ⊆ ↑r'

Next tactic:
simpa using hsr'
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
    rw [ncard_eq_toFinset_card t ht] at h₁
    obtain ⟨r', hsr', hr't, hr'⟩ := Finset.exists_intermediate_set _ h₁ (by simpa)
    exact ⟨r', by simpa using hsr', by 

Proof state:
α : Type u_1
s t : Set α
i : ℕ
h₂ : s ⊆ t
ht : Set.Finite t
h₁ : i + Finset.card (Finite.toFinset (_ : Set.Finite s)) ≤ Finset.card (Finite.toFinset ht)
r' : Finset α
hsr' : Finite.toFinset (_ : Set.Finite s) ⊆ r'
hr't : r' ⊆ Finite.toFinset ht
hr' : Finset.card r' = i + Finset.card (Finite.toFinset (_ : Set.Finite s))
⊢ ↑r' ⊆ t

Next tactic:
simpa using hr't
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
    rw [ncard_eq_toFinset_card t ht] at h₁
    obtain ⟨r', hsr', hr't, hr'⟩ := Finset.exists_intermediate_set _ h₁ (by simpa)
    exact ⟨r', by simpa using hsr', by simpa using hr't, by 

Proof state:
α : Type u_1
s t : Set α
i : ℕ
h₂ : s ⊆ t
ht : Set.Finite t
h₁ : i + Finset.card (Finite.toFinset (_ : Set.Finite s)) ≤ Finset.card (Finite.toFinset ht)
r' : Finset α
hsr' : Finite.toFinset (_ : Set.Finite s) ⊆ r'
hr't : r' ⊆ Finite.toFinset ht
hr' : Finset.card r' = i + Finset.card (Finite.toFinset (_ : Set.Finite s))
⊢ ncard ↑r' = i + Finset.card (Finite.toFinset (_ : Set.Finite s))

Next tactic:
rw [← hr', ncard_coe_Finset]
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
    rw [ncard_eq_toFinset_card t ht] at h₁
    obtain ⟨r', hsr', hr't, hr'⟩ := Finset.exists_intermediate_set _ h₁ (by simpa)
    exact ⟨r', by simpa using hsr', by simpa using hr't, by rw [← hr', ncard_coe_Finset]⟩
  

Proof state:
case inr
α : Type u_1
s t : Set α
i : ℕ
h₁ : i + ncard s ≤ ncard t
h₂ : s ⊆ t
ht : Set.Infinite t
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ ncard r = i + ncard s

Next tactic:
rw [ht.ncard] at h₁
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
    rw [ncard_eq_toFinset_card t ht] at h₁
    obtain ⟨r', hsr', hr't, hr'⟩ := Finset.exists_intermediate_set _ h₁ (by simpa)
    exact ⟨r', by simpa using hsr', by simpa using hr't, by rw [← hr', ncard_coe_Finset]⟩
  rw [ht.ncard] at h₁
  

Proof state:
case inr
α : Type u_1
s t : Set α
i : ℕ
h₁ : i + ncard s ≤ 0
h₂ : s ⊆ t
ht : Set.Infinite t
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ ncard r = i + ncard s

Next tactic:
have h₁' := Nat.eq_zero_of_le_zero h₁
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
    rw [ncard_eq_toFinset_card t ht] at h₁
    obtain ⟨r', hsr', hr't, hr'⟩ := Finset.exists_intermediate_set _ h₁ (by simpa)
    exact ⟨r', by simpa using hsr', by simpa using hr't, by rw [← hr', ncard_coe_Finset]⟩
  rw [ht.ncard] at h₁
  have h₁' := Nat.eq_zero_of_le_zero h₁
  

Proof state:
case inr
α : Type u_1
s t : Set α
i : ℕ
h₁ : i + ncard s ≤ 0
h₂ : s ⊆ t
ht : Set.Infinite t
h₁' : i + ncard s = 0
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ ncard r = i + ncard s

Next tactic:
rw [add_eq_zero_iff] at h₁'
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
    rw [ncard_eq_toFinset_card t ht] at h₁
    obtain ⟨r', hsr', hr't, hr'⟩ := Finset.exists_intermediate_set _ h₁ (by simpa)
    exact ⟨r', by simpa using hsr', by simpa using hr't, by rw [← hr', ncard_coe_Finset]⟩
  rw [ht.ncard] at h₁
  have h₁' := Nat.eq_zero_of_le_zero h₁
  rw [add_eq_zero_iff] at h₁'
  

Proof state:
case inr
α : Type u_1
s t : Set α
i : ℕ
h₁ : i + ncard s ≤ 0
h₂ : s ⊆ t
ht : Set.Infinite t
h₁' : i = 0 ∧ ncard s = 0
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ ncard r = i + ncard s

Next tactic:
refine' ⟨t, h₂, rfl.subset, _⟩
/-- Given a set `t` and a set `s` inside it, we can shrink `t` to any appropriate size, and keep `s`
    inside it. -/
theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂ : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = i + s.ncard := by
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ (ht.subset h₂)] at h₁ ⊢
    rw [ncard_eq_toFinset_card t ht] at h₁
    obtain ⟨r', hsr', hr't, hr'⟩ := Finset.exists_intermediate_set _ h₁ (by simpa)
    exact ⟨r', by simpa using hsr', by simpa using hr't, by rw [← hr', ncard_coe_Finset]⟩
  rw [ht.ncard] at h₁
  have h₁' := Nat.eq_zero_of_le_zero h₁
  rw [add_eq_zero_iff] at h₁'
  refine' ⟨t, h₂, rfl.subset, _⟩
  

Proof state:
case inr
α : Type u_1
s t : Set α
i : ℕ
h₁ : i + ncard s ≤ 0
h₂ : s ⊆ t
ht : Set.Infinite t
h₁' : i = 0 ∧ ncard s = 0
⊢ ncard t = i + ncard s

Next tactic:
rw [h₁'.2, h₁'.1, ht.ncard, add_zero]
theorem exists_intermediate_set' {m : ℕ} (hs : s.ncard ≤ m) (ht : m ≤ t.ncard) (h : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = m := by
  

Proof state:
α : Type u_1
s t : Set α
m : ℕ
hs : ncard s ≤ m
ht : m ≤ ncard t
h : s ⊆ t
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ ncard r = m

Next tactic:
obtain ⟨r, hsr, hrt, hc⟩ :=
    exists_intermediate_Set (m - s.ncard) (by rwa [tsub_add_cancel_of_le hs]) h
theorem exists_intermediate_set' {m : ℕ} (hs : s.ncard ≤ m) (ht : m ≤ t.ncard) (h : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = m := by
  obtain ⟨r, hsr, hrt, hc⟩ :=
    exists_intermediate_Set (m - s.ncard) (by 

Proof state:
α : Type u_1
s t : Set α
m : ℕ
hs : ncard s ≤ m
ht : m ≤ ncard t
h : s ⊆ t
⊢ m - ncard s + ncard s ≤ ncard t

Next tactic:
rwa [tsub_add_cancel_of_le hs]
theorem exists_intermediate_set' {m : ℕ} (hs : s.ncard ≤ m) (ht : m ≤ t.ncard) (h : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = m := by
  obtain ⟨r, hsr, hrt, hc⟩ :=
    exists_intermediate_Set (m - s.ncard) (by rwa [tsub_add_cancel_of_le hs]) h
  

Proof state:
case intro.intro.intro
α : Type u_1
s t : Set α
m : ℕ
hs : ncard s ≤ m
ht : m ≤ ncard t
h : s ⊆ t
r : Set α
hsr : s ⊆ r
hrt : r ⊆ t
hc : ncard r = m - ncard s + ncard s
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ ncard r = m

Next tactic:
rw [tsub_add_cancel_of_le hs] at hc
theorem exists_intermediate_set' {m : ℕ} (hs : s.ncard ≤ m) (ht : m ≤ t.ncard) (h : s ⊆ t) :
    ∃ r : Set α, s ⊆ r ∧ r ⊆ t ∧ r.ncard = m := by
  obtain ⟨r, hsr, hrt, hc⟩ :=
    exists_intermediate_Set (m - s.ncard) (by rwa [tsub_add_cancel_of_le hs]) h
  rw [tsub_add_cancel_of_le hs] at hc
  

Proof state:
case intro.intro.intro
α : Type u_1
s t : Set α
m : ℕ
hs : ncard s ≤ m
ht : m ≤ ncard t
h : s ⊆ t
r : Set α
hsr : s ⊆ r
hrt : r ⊆ t
hc : ncard r = m
⊢ ∃ r, s ⊆ r ∧ r ⊆ t ∧ ncard r = m

Next tactic:
exact ⟨r, hsr, hrt, hc⟩
/-- We can shrink `s` to any smaller size. -/
theorem exists_smaller_set (s : Set α) (i : ℕ) (h₁ : i ≤ s.ncard) :
    ∃ t : Set α, t ⊆ s ∧ t.ncard = i :=
  (exists_intermediate_Set i (by 

Proof state:
α : Type u_1
s✝ t s : Set α
i : ℕ
h₁ : i ≤ ncard s
⊢ i + ncard ∅ ≤ ncard s

Next tactic:
simpa
/-- We can shrink `s` to any smaller size. -/
theorem exists_smaller_set (s : Set α) (i : ℕ) (h₁ : i ≤ s.ncard) :
    ∃ t : Set α, t ⊆ s ∧ t.ncard = i :=
  (exists_intermediate_Set i (by simpa) (empty_subset s)).imp fun t ht ↦
    ⟨ht.2.1, by 

Proof state:
α : Type u_1
s✝ t✝ s : Set α
i : ℕ
h₁ : i ≤ ncard s
t : Set α
ht : ∅ ⊆ t ∧ t ⊆ s ∧ ncard t = i + ncard ∅
⊢ ncard t = i

Next tactic:
simpa using ht.2.2
theorem Infinite.exists_subset_ncard_eq {s : Set α} (hs : s.Infinite) (k : ℕ) :
    ∃ t, t ⊆ s ∧ t.Finite ∧ t.ncard = k := by
  

Proof state:
α : Type u_1
s✝ t s : Set α
hs : Set.Infinite s
k : ℕ
⊢ ∃ t ⊆ s, Set.Finite t ∧ Set.ncard t = k

Next tactic:
have := hs.to_subtype
theorem Infinite.exists_subset_ncard_eq {s : Set α} (hs : s.Infinite) (k : ℕ) :
    ∃ t, t ⊆ s ∧ t.Finite ∧ t.ncard = k := by
  have := hs.to_subtype
  

Proof state:
α : Type u_1
s✝ t s : Set α
hs : Set.Infinite s
k : ℕ
this : Infinite ↑s
⊢ ∃ t ⊆ s, Set.Finite t ∧ Set.ncard t = k

Next tactic:
obtain ⟨t', -, rfl⟩ := @Infinite.exists_subset_card_eq s univ infinite_univ k
theorem Infinite.exists_subset_ncard_eq {s : Set α} (hs : s.Infinite) (k : ℕ) :
    ∃ t, t ⊆ s ∧ t.Finite ∧ t.ncard = k := by
  have := hs.to_subtype
  obtain ⟨t', -, rfl⟩ := @Infinite.exists_subset_card_eq s univ infinite_univ k
  

Proof state:
case intro.intro
α : Type u_1
s✝ t s : Set α
hs : Set.Infinite s
this : Infinite ↑s
t' : Finset ↑s
⊢ ∃ t ⊆ s, Set.Finite t ∧ Set.ncard t = Finset.card t'

Next tactic:
refine' ⟨Subtype.val '' (t' : Set s), by simp, Finite.image _ (by simp), _⟩