l3lab/ntp-mathlib huggingface dataset:
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
  refine' ⟨Subtype.val '' (t' : Set s), by 

Proof state:
α : Type u_1
s✝ t s : Set α
hs : Set.Infinite s
this : Infinite ↑s
t' : Finset ↑s
⊢ Subtype.val '' ↑t' ⊆ s

Next tactic:
simp
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
  refine' ⟨Subtype.val '' (t' : Set s), by simp, Finite.image _ (by 

Proof state:
α : Type u_1
s✝ t s : Set α
hs : Set.Infinite s
this : Infinite ↑s
t' : Finset ↑s
⊢ Set.Finite ↑t'

Next tactic:
simp
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
  refine' ⟨Subtype.val '' (t' : Set s), by simp, Finite.image _ (by simp), _⟩
  

Proof state:
case intro.intro
α : Type u_1
s✝ t s : Set α
hs : Set.Infinite s
this : Infinite ↑s
t' : Finset ↑s
⊢ Set.ncard (Subtype.val '' ↑t') = Finset.card t'

Next tactic:
rw [ncard_image_of_injective _ Subtype.coe_injective]
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
  refine' ⟨Subtype.val '' (t' : Set s), by simp, Finite.image _ (by simp), _⟩
  rw [ncard_image_of_injective _ Subtype.coe_injective]
  

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

Next tactic:
simp
theorem Infinite.exists_superset_ncard_eq {s t : Set α} (ht : t.Infinite) (hst : s ⊆ t)
    (hs : s.Finite) {k : ℕ} (hsk : s.ncard ≤ k) : ∃ s', s ⊆ s' ∧ s' ⊆ t ∧ s'.ncard = k := by
  

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

Next tactic:
obtain ⟨s₁, hs₁, hs₁fin, hs₁card⟩ := (ht.diff hs).exists_subset_ncard_eq (k - s.ncard)
theorem Infinite.exists_superset_ncard_eq {s t : Set α} (ht : t.Infinite) (hst : s ⊆ t)
    (hs : s.Finite) {k : ℕ} (hsk : s.ncard ≤ k) : ∃ s', s ⊆ s' ∧ s' ⊆ t ∧ s'.ncard = k := by
  obtain ⟨s₁, hs₁, hs₁fin, hs₁card⟩ := (ht.diff hs).exists_subset_ncard_eq (k - s.ncard)
  

Proof state:
case intro.intro.intro
α : Type u_1
s✝ t✝ s t : Set α
ht : Set.Infinite t
hst : s ⊆ t
hs : Set.Finite s
k : ℕ
hsk : Set.ncard s ≤ k
s₁ : Set α
hs₁ : s₁ ⊆ t \ s
hs₁fin : Set.Finite s₁
hs₁card : Set.ncard s₁ = k - Set.ncard s
⊢ ∃ s', s ⊆ s' ∧ s' ⊆ t ∧ Set.ncard s' = k

Next tactic:
refine' ⟨s ∪ s₁, subset_union_left _ _, union_subset hst (hs₁.trans (diff_subset _ _)), _⟩
theorem Infinite.exists_superset_ncard_eq {s t : Set α} (ht : t.Infinite) (hst : s ⊆ t)
    (hs : s.Finite) {k : ℕ} (hsk : s.ncard ≤ k) : ∃ s', s ⊆ s' ∧ s' ⊆ t ∧ s'.ncard = k := by
  obtain ⟨s₁, hs₁, hs₁fin, hs₁card⟩ := (ht.diff hs).exists_subset_ncard_eq (k - s.ncard)
  refine' ⟨s ∪ s₁, subset_union_left _ _, union_subset hst (hs₁.trans (diff_subset _ _)), _⟩
  

Proof state:
case intro.intro.intro
α : Type u_1
s✝ t✝ s t : Set α
ht : Set.Infinite t
hst : s ⊆ t
hs : Set.Finite s
k : ℕ
hsk : Set.ncard s ≤ k
s₁ : Set α
hs₁ : s₁ ⊆ t \ s
hs₁fin : Set.Finite s₁
hs₁card : Set.ncard s₁ = k - Set.ncard s
⊢ Set.ncard (s ∪ s₁) = k

Next tactic:
rwa [ncard_union_eq (disjoint_of_subset_right hs₁ disjoint_sdiff_right) hs hs₁fin, hs₁card,
    add_tsub_cancel_of_le]
theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s ∪ t).ncard) :
    ∃ r : Set α, n < r.ncard ∧ (r ⊆ s ∨ r ⊆ t) := by
  

Proof state:
α : Type u_1
s t : Set α
n : ℕ
hst : 2 * n < ncard (s ∪ t)
⊢ ∃ r, n < ncard r ∧ (r ⊆ s ∨ r ⊆ t)

Next tactic:
classical
  have hu := finite_of_ncard_ne_zero ((Nat.zero_le _).trans_lt hst).ne.symm
  rw [ncard_eq_toFinset_card _ hu,
    Finite.toFinset_union (hu.subset (subset_union_left _ _))
      (hu.subset (subset_union_right _ _))] at hst
  obtain ⟨r', hnr', hr'⟩ := Finset.exists_subset_or_subset_of_two_mul_lt_card hst
  exact ⟨r', by simpa, by simpa using hr'⟩
theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s ∪ t).ncard) :
    ∃ r : Set α, n < r.ncard ∧ (r ⊆ s ∨ r ⊆ t) := by
  classical
  

Proof state:
α : Type u_1
s t : Set α
n : ℕ
hst : 2 * n < ncard (s ∪ t)
⊢ ∃ r, n < ncard r ∧ (r ⊆ s ∨ r ⊆ t)

Next tactic:
have hu := finite_of_ncard_ne_zero ((Nat.zero_le _).trans_lt hst).ne.symm
theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s ∪ t).ncard) :
    ∃ r : Set α, n < r.ncard ∧ (r ⊆ s ∨ r ⊆ t) := by
  classical
  have hu := finite_of_ncard_ne_zero ((Nat.zero_le _).trans_lt hst).ne.symm
  

Proof state:
α : Type u_1
s t : Set α
n : ℕ
hst : 2 * n < ncard (s ∪ t)
hu : Set.Finite (s ∪ t)
⊢ ∃ r, n < ncard r ∧ (r ⊆ s ∨ r ⊆ t)

Next tactic:
rw [ncard_eq_toFinset_card _ hu,
    Finite.toFinset_union (hu.subset (subset_union_left _ _))
      (hu.subset (subset_union_right _ _))] at hst
theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s ∪ t).ncard) :
    ∃ r : Set α, n < r.ncard ∧ (r ⊆ s ∨ r ⊆ t) := by
  classical
  have hu := finite_of_ncard_ne_zero ((Nat.zero_le _).trans_lt hst).ne.symm
  rw [ncard_eq_toFinset_card _ hu,
    Finite.toFinset_union (hu.subset (subset_union_left _ _))
      (hu.subset (subset_union_right _ _))] at hst
  

Proof state:
α : Type u_1
s t : Set α
n : ℕ
hu : Set.Finite (s ∪ t)
hst : 2 * n < Finset.card (Finite.toFinset (_ : Set.Finite s) ∪ Finite.toFinset (_ : Set.Finite t))
⊢ ∃ r, n < ncard r ∧ (r ⊆ s ∨ r ⊆ t)

Next tactic:
obtain ⟨r', hnr', hr'⟩ := Finset.exists_subset_or_subset_of_two_mul_lt_card hst
theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s ∪ t).ncard) :
    ∃ r : Set α, n < r.ncard ∧ (r ⊆ s ∨ r ⊆ t) := by
  classical
  have hu := finite_of_ncard_ne_zero ((Nat.zero_le _).trans_lt hst).ne.symm
  rw [ncard_eq_toFinset_card _ hu,
    Finite.toFinset_union (hu.subset (subset_union_left _ _))
      (hu.subset (subset_union_right _ _))] at hst
  obtain ⟨r', hnr', hr'⟩ := Finset.exists_subset_or_subset_of_two_mul_lt_card hst
  

Proof state:
case intro.intro
α : Type u_1
s t : Set α
n : ℕ
hu : Set.Finite (s ∪ t)
hst : 2 * n < Finset.card (Finite.toFinset (_ : Set.Finite s) ∪ Finite.toFinset (_ : Set.Finite t))
r' : Finset α
hnr' : n < Finset.card r'
hr' : r' ⊆ Finite.toFinset (_ : Set.Finite s) ∨ r' ⊆ Finite.toFinset (_ : Set.Finite t)
⊢ ∃ r, n < ncard r ∧ (r ⊆ s ∨ r ⊆ t)

Next tactic:
exact ⟨r', by simpa, by simpa using hr'⟩
theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s ∪ t).ncard) :
    ∃ r : Set α, n < r.ncard ∧ (r ⊆ s ∨ r ⊆ t) := by
  classical
  have hu := finite_of_ncard_ne_zero ((Nat.zero_le _).trans_lt hst).ne.symm
  rw [ncard_eq_toFinset_card _ hu,
    Finite.toFinset_union (hu.subset (subset_union_left _ _))
      (hu.subset (subset_union_right _ _))] at hst
  obtain ⟨r', hnr', hr'⟩ := Finset.exists_subset_or_subset_of_two_mul_lt_card hst
  exact ⟨r', by 

Proof state:
α : Type u_1
s t : Set α
n : ℕ
hu : Set.Finite (s ∪ t)
hst : 2 * n < Finset.card (Finite.toFinset (_ : Set.Finite s) ∪ Finite.toFinset (_ : Set.Finite t))
r' : Finset α
hnr' : n < Finset.card r'
hr' : r' ⊆ Finite.toFinset (_ : Set.Finite s) ∨ r' ⊆ Finite.toFinset (_ : Set.Finite t)
⊢ n < ncard ↑r'

Next tactic:
simpa
theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s ∪ t).ncard) :
    ∃ r : Set α, n < r.ncard ∧ (r ⊆ s ∨ r ⊆ t) := by
  classical
  have hu := finite_of_ncard_ne_zero ((Nat.zero_le _).trans_lt hst).ne.symm
  rw [ncard_eq_toFinset_card _ hu,
    Finite.toFinset_union (hu.subset (subset_union_left _ _))
      (hu.subset (subset_union_right _ _))] at hst
  obtain ⟨r', hnr', hr'⟩ := Finset.exists_subset_or_subset_of_two_mul_lt_card hst
  exact ⟨r', by simpa, by 

Proof state:
α : Type u_1
s t : Set α
n : ℕ
hu : Set.Finite (s ∪ t)
hst : 2 * n < Finset.card (Finite.toFinset (_ : Set.Finite s) ∪ Finite.toFinset (_ : Set.Finite t))
r' : Finset α
hnr' : n < Finset.card r'
hr' : r' ⊆ Finite.toFinset (_ : Set.Finite s) ∨ r' ⊆ Finite.toFinset (_ : Set.Finite t)
⊢ ↑r' ⊆ s ∨ ↑r' ⊆ t

Next tactic:
simpa using hr'
@[simp] theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} := by
  

Proof state:
α : Type u_1
s t : Set α
⊢ ncard s = 1 ↔ ∃ a, s = {a}

Next tactic:
refine' ⟨fun h ↦ _, by rintro ⟨a, rfl⟩; rw [ncard_singleton]⟩
@[simp] theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} := by
  refine' ⟨fun h ↦ _, by 

Proof state:
α : Type u_1
s t : Set α
⊢ (∃ a, s = {a}) → ncard s = 1

Next tactic:
rintro ⟨a, rfl⟩
@[simp] theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} := by
  refine' ⟨fun h ↦ _, by rintro ⟨a, rfl⟩; 

Proof state:
case intro
α : Type u_1
t : Set α
a : α
⊢ ncard {a} = 1

Next tactic:
rw [ncard_singleton]
@[simp] theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} := by
  refine' ⟨fun h ↦ _, by rintro ⟨a, rfl⟩; rw [ncard_singleton]⟩
  

Proof state:
α : Type u_1
s t : Set α
h : ncard s = 1
⊢ ∃ a, s = {a}

Next tactic:
have hft := (finite_of_ncard_ne_zero (ne_zero_of_eq_one h)).fintype
@[simp] theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} := by
  refine' ⟨fun h ↦ _, by rintro ⟨a, rfl⟩; rw [ncard_singleton]⟩
  have hft := (finite_of_ncard_ne_zero (ne_zero_of_eq_one h)).fintype
  

Proof state:
α : Type u_1
s t : Set α
h : ncard s = 1
hft : Fintype ↑s
⊢ ∃ a, s = {a}

Next tactic:
simp_rw [ncard_eq_toFinset_card', @Finset.card_eq_one _ (toFinset s)] at h
@[simp] theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} := by
  refine' ⟨fun h ↦ _, by rintro ⟨a, rfl⟩; rw [ncard_singleton]⟩
  have hft := (finite_of_ncard_ne_zero (ne_zero_of_eq_one h)).fintype
  simp_rw [ncard_eq_toFinset_card', @Finset.card_eq_one _ (toFinset s)] at h
  

Proof state:
α : Type u_1
s t : Set α
hft : Fintype ↑s
h : ∃ a, toFinset s = {a}
⊢ ∃ a, s = {a}

Next tactic:
refine' h.imp fun a ha ↦ _
@[simp] theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} := by
  refine' ⟨fun h ↦ _, by rintro ⟨a, rfl⟩; rw [ncard_singleton]⟩
  have hft := (finite_of_ncard_ne_zero (ne_zero_of_eq_one h)).fintype
  simp_rw [ncard_eq_toFinset_card', @Finset.card_eq_one _ (toFinset s)] at h
  refine' h.imp fun a ha ↦ _
  

Proof state:
α : Type u_1
s t : Set α
hft : Fintype ↑s
h : ∃ a, toFinset s = {a}
a : α
ha : toFinset s = {a}
⊢ s = {a}

Next tactic:
simp_rw [Set.ext_iff, mem_singleton_iff]
@[simp] theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} := by
  refine' ⟨fun h ↦ _, by rintro ⟨a, rfl⟩; rw [ncard_singleton]⟩
  have hft := (finite_of_ncard_ne_zero (ne_zero_of_eq_one h)).fintype
  simp_rw [ncard_eq_toFinset_card', @Finset.card_eq_one _ (toFinset s)] at h
  refine' h.imp fun a ha ↦ _
  simp_rw [Set.ext_iff, mem_singleton_iff]
  

Proof state:
α : Type u_1
s t : Set α
hft : Fintype ↑s
h : ∃ a, toFinset s = {a}
a : α
ha : toFinset s = {a}
⊢ ∀ (x : α), x ∈ s ↔ x = a

Next tactic:
simp only [Finset.ext_iff, mem_toFinset, Finset.mem_singleton] at ha
@[simp] theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} := by
  refine' ⟨fun h ↦ _, by rintro ⟨a, rfl⟩; rw [ncard_singleton]⟩
  have hft := (finite_of_ncard_ne_zero (ne_zero_of_eq_one h)).fintype
  simp_rw [ncard_eq_toFinset_card', @Finset.card_eq_one _ (toFinset s)] at h
  refine' h.imp fun a ha ↦ _
  simp_rw [Set.ext_iff, mem_singleton_iff]
  simp only [Finset.ext_iff, mem_toFinset, Finset.mem_singleton] at ha
  

Proof state:
α : Type u_1
s t : Set α
hft : Fintype ↑s
h : ∃ a, toFinset s = {a}
a : α
ha : ∀ (a_1 : α), a_1 ∈ s ↔ a_1 = a
⊢ ∀ (x : α), x ∈ s ↔ x = a

Next tactic:
exact ha
theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
    (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ ncard s + 1 = ncard t

Next tactic:
classical
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht,
      ← @Finite.toFinset_subset_toFinset _ _ _ hs ht, ← Finset.exists_eq_insert_iff]
    convert Iff.rfl using 2; simp
    ext x
    simp [Finset.ext_iff, Set.ext_iff]
  simp only [ht.ncard, exists_prop, add_eq_zero, and_false, iff_false, not_exists, not_and]
  rintro x - rfl
  exact ht (hs.insert x)
theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
    (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
  classical
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ ncard s + 1 = ncard t

Next tactic:
cases' t.finite_or_infinite with ht ht
theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
    (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
  classical
  cases' t.finite_or_infinite with ht ht
  · 

Proof state:
case inl
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
ht : Set.Finite t
⊢ (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ ncard s + 1 = ncard t

Next tactic:
rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht,
      ← @Finite.toFinset_subset_toFinset _ _ _ hs ht, ← Finset.exists_eq_insert_iff]
theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
    (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
  classical
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht,
      ← @Finite.toFinset_subset_toFinset _ _ _ hs ht, ← Finset.exists_eq_insert_iff]
    

Proof state:
case inl
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
ht : Set.Finite t
⊢ (∃ a ∉ s, insert a s = t) ↔ ∃ a ∉ Finite.toFinset hs, insert a (Finite.toFinset hs) = Finite.toFinset ht

Next tactic:
convert Iff.rfl using 2
theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
    (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
  classical
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht,
      ← @Finite.toFinset_subset_toFinset _ _ _ hs ht, ← Finset.exists_eq_insert_iff]
    convert Iff.rfl using 2; 

Proof state:
case h.e'_2.h.e'_2
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
ht : Set.Finite t
⊢ (fun a => a ∉ Finite.toFinset hs ∧ insert a (Finite.toFinset hs) = Finite.toFinset ht) = fun a =>
    a ∉ s ∧ insert a s = t

Next tactic:
simp
theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
    (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
  classical
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht,
      ← @Finite.toFinset_subset_toFinset _ _ _ hs ht, ← Finset.exists_eq_insert_iff]
    convert Iff.rfl using 2; simp
    

Proof state:
case h.e'_2.h.e'_2
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
ht : Set.Finite t
⊢ (fun a => a ∉ s ∧ insert a (Finite.toFinset hs) = Finite.toFinset ht) = fun a => a ∉ s ∧ insert a s = t

Next tactic:
ext x
theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
    (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
  classical
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht,
      ← @Finite.toFinset_subset_toFinset _ _ _ hs ht, ← Finset.exists_eq_insert_iff]
    convert Iff.rfl using 2; simp
    ext x
    

Proof state:
case h.e'_2.h.e'_2.h.a
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
ht : Set.Finite t
x : α
⊢ x ∉ s ∧ insert x (Finite.toFinset hs) = Finite.toFinset ht ↔ x ∉ s ∧ insert x s = t

Next tactic:
simp [Finset.ext_iff, Set.ext_iff]
theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
    (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
  classical
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht,
      ← @Finite.toFinset_subset_toFinset _ _ _ hs ht, ← Finset.exists_eq_insert_iff]
    convert Iff.rfl using 2; simp
    ext x
    simp [Finset.ext_iff, Set.ext_iff]
  

Proof state:
case inr
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
ht : Set.Infinite t
⊢ (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ ncard s + 1 = ncard t

Next tactic:
simp only [ht.ncard, exists_prop, add_eq_zero, and_false, iff_false, not_exists, not_and]
theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
    (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
  classical
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht,
      ← @Finite.toFinset_subset_toFinset _ _ _ hs ht, ← Finset.exists_eq_insert_iff]
    convert Iff.rfl using 2; simp
    ext x
    simp [Finset.ext_iff, Set.ext_iff]
  simp only [ht.ncard, exists_prop, add_eq_zero, and_false, iff_false, not_exists, not_and]
  

Proof state:
case inr
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
ht : Set.Infinite t
⊢ ∀ x ∉ s, ¬insert x s = t

Next tactic:
rintro x - rfl
theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
    (∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
  classical
  cases' t.finite_or_infinite with ht ht
  · rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht,
      ← @Finite.toFinset_subset_toFinset _ _ _ hs ht, ← Finset.exists_eq_insert_iff]
    convert Iff.rfl using 2; simp
    ext x
    simp [Finset.ext_iff, Set.ext_iff]
  simp only [ht.ncard, exists_prop, add_eq_zero, and_false, iff_false, not_exists, not_and]
  rintro x - rfl
  

Proof state:
case inr
α : Type u_1
s : Set α
hs : autoParam (Set.Finite s) _auto✝
x : α
ht : Set.Infinite (insert x s)
⊢ False

Next tactic:
exact ht (hs.insert x)
theorem ncard_le_one (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ ∀ a ∈ s, ∀ b ∈ s, a = b := by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard s ≤ 1 ↔ ∀ a ∈ s, ∀ b ∈ s, a = b

Next tactic:
simp_rw [ncard_eq_toFinset_card _ hs, Finset.card_le_one, Finite.mem_toFinset]
theorem ncard_le_one_iff (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ ∀ {a b}, a ∈ s → b ∈ s → a = b := by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard s ≤ 1 ↔ ∀ {a b : α}, a ∈ s → b ∈ s → a = b

Next tactic:
rw [ncard_le_one hs]
theorem ncard_le_one_iff (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ ∀ {a b}, a ∈ s → b ∈ s → a = b := by
  rw [ncard_le_one hs]
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ (∀ a ∈ s, ∀ b ∈ s, a = b) ↔ ∀ {a b : α}, a ∈ s → b ∈ s → a = b

Next tactic:
tauto
theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a} := by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard s ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a}

Next tactic:
obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty
theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a} := by
  obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty
  · 

Proof state:
case inl
α : Type u_1
t : Set α
hs : autoParam (Set.Finite ∅) _auto✝
⊢ ncard ∅ ≤ 1 ↔ ∅ = ∅ ∨ ∃ a, ∅ = {a}

Next tactic:
exact iff_of_true (by simp) (Or.inl rfl)
theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a} := by
  obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty
  · exact iff_of_true (by 

Proof state:
α : Type u_1
t : Set α
hs : autoParam (Set.Finite ∅) _auto✝
⊢ ncard ∅ ≤ 1

Next tactic:
simp
theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a} := by
  obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty
  · exact iff_of_true (by simp) (Or.inl rfl)
  

Proof state:
case inr.intro
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
x : α
hx : x ∈ s
⊢ ncard s ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a}

Next tactic:
rw [ncard_le_one_iff hs]
theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a} := by
  obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty
  · exact iff_of_true (by simp) (Or.inl rfl)
  rw [ncard_le_one_iff hs]
  

Proof state:
case inr.intro
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
x : α
hx : x ∈ s
⊢ (∀ {a b : α}, a ∈ s → b ∈ s → a = b) ↔ s = ∅ ∨ ∃ a, s = {a}

Next tactic:
refine' ⟨fun h ↦ Or.inr ⟨x, (singleton_subset_iff.mpr hx).antisymm' fun y hy ↦ h hy hx⟩, _⟩
theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a} := by
  obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty
  · exact iff_of_true (by simp) (Or.inl rfl)
  rw [ncard_le_one_iff hs]
  refine' ⟨fun h ↦ Or.inr ⟨x, (singleton_subset_iff.mpr hx).antisymm' fun y hy ↦ h hy hx⟩, _⟩
  

Proof state:
case inr.intro
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
x : α
hx : x ∈ s
⊢ (s = ∅ ∨ ∃ a, s = {a}) → ∀ {a b : α}, a ∈ s → b ∈ s → a = b

Next tactic:
rintro (rfl | ⟨a, rfl⟩)
theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a} := by
  obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty
  · exact iff_of_true (by simp) (Or.inl rfl)
  rw [ncard_le_one_iff hs]
  refine' ⟨fun h ↦ Or.inr ⟨x, (singleton_subset_iff.mpr hx).antisymm' fun y hy ↦ h hy hx⟩, _⟩
  rintro (rfl | ⟨a, rfl⟩)
  · 

Proof state:
case inr.intro.inl
α : Type u_1
t : Set α
x : α
hs : autoParam (Set.Finite ∅) _auto✝
hx : x ∈ ∅
⊢ ∀ {a b : α}, a ∈ ∅ → b ∈ ∅ → a = b

Next tactic:
exact (not_mem_empty _ hx).elim
theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a} := by
  obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty
  · exact iff_of_true (by simp) (Or.inl rfl)
  rw [ncard_le_one_iff hs]
  refine' ⟨fun h ↦ Or.inr ⟨x, (singleton_subset_iff.mpr hx).antisymm' fun y hy ↦ h hy hx⟩, _⟩
  rintro (rfl | ⟨a, rfl⟩)
  · exact (not_mem_empty _ hx).elim
  

Proof state:
case inr.intro.inr.intro
α : Type u_1
t : Set α
x a : α
hs : autoParam (Set.Finite {a}) _auto✝
hx : x ∈ {a}
⊢ ∀ {a_1 b : α}, a_1 ∈ {a} → b ∈ {a} → a_1 = b

Next tactic:
simp_rw [mem_singleton_iff] at hx ⊢
theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a} := by
  obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty
  · exact iff_of_true (by simp) (Or.inl rfl)
  rw [ncard_le_one_iff hs]
  refine' ⟨fun h ↦ Or.inr ⟨x, (singleton_subset_iff.mpr hx).antisymm' fun y hy ↦ h hy hx⟩, _⟩
  rintro (rfl | ⟨a, rfl⟩)
  · exact (not_mem_empty _ hx).elim
  simp_rw [mem_singleton_iff] at hx ⊢; 

Proof state:
case inr.intro.inr.intro
α : Type u_1
t : Set α
x a : α
hs : autoParam (Set.Finite {a}) _auto✝
hx : x = a
⊢ ∀ {a_1 b : α}, a_1 = a → b = a → a_1 = b

Next tactic:
subst hx
theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a} := by
  obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty
  · exact iff_of_true (by simp) (Or.inl rfl)
  rw [ncard_le_one_iff hs]
  refine' ⟨fun h ↦ Or.inr ⟨x, (singleton_subset_iff.mpr hx).antisymm' fun y hy ↦ h hy hx⟩, _⟩
  rintro (rfl | ⟨a, rfl⟩)
  · exact (not_mem_empty _ hx).elim
  simp_rw [mem_singleton_iff] at hx ⊢; subst hx
  

Proof state:
case inr.intro.inr.intro
α : Type u_1
t : Set α
x : α
hs : autoParam (Set.Finite {x}) _auto✝
⊢ ∀ {a b : α}, a = x → b = x → a = b

Next tactic:
simp only [forall_eq_apply_imp_iff, imp_self, implies_true]
theorem ncard_le_one_iff_subset_singleton [Nonempty α]
    (hs : s.Finite := by toFinite_tac) :
    s.ncard ≤ 1 ↔ ∃ x : α, s ⊆ {x} := by
  

Proof state:
α : Type u_1
s t : Set α
inst✝ : Nonempty α
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard s ≤ 1 ↔ ∃ x, s ⊆ {x}

Next tactic:
simp_rw [ncard_eq_toFinset_card _ hs, Finset.card_le_one_iff_subset_singleton,
    Finite.toFinset_subset, Finset.coe_singleton]
/-- A `Set` of a subsingleton type has cardinality at most one. -/
theorem ncard_le_one_of_subsingleton [Subsingleton α] (s : Set α) : s.ncard ≤ 1 := by
  

Proof state:
α : Type u_1
s✝ t : Set α
inst✝ : Subsingleton α
s : Set α
⊢ ncard s ≤ 1

Next tactic:
rw [ncard_eq_toFinset_card]