l3lab/ntp-mathlib huggingface dataset:
@[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by
  rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
    PartENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]; 

Proof state:
α : Type u_1
s t : Set α
e : α
⊢ 1 = PartENat.withTopEquiv.symm 1

Next tactic:
rfl
theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by
  

Proof state:
α : Type u_1
s t : Set α
h : Disjoint s t
⊢ encard (s ∪ t) = encard s + encard t

Next tactic:
classical
  have e := (Equiv.Set.union (by rwa [subset_empty_iff, ← disjoint_iff_inter_eq_empty])).symm
  simp [encard, ← PartENat.card_congr e, PartENat.card_sum, PartENat.withTopEquiv]
theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by
  classical
  

Proof state:
α : Type u_1
s t : Set α
h : Disjoint s t
⊢ encard (s ∪ t) = encard s + encard t

Next tactic:
have e := (Equiv.Set.union (by rwa [subset_empty_iff, ← disjoint_iff_inter_eq_empty])).symm
theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by
  classical
  have e := (Equiv.Set.union (by 

Proof state:
α : Type u_1
s t : Set α
h : Disjoint s t
⊢ ?m.5873 ∩ ?m.5874 ⊆ ∅

Next tactic:
rwa [subset_empty_iff, ← disjoint_iff_inter_eq_empty]
theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by
  classical
  have e := (Equiv.Set.union (by rwa [subset_empty_iff, ← disjoint_iff_inter_eq_empty])).symm
  

Proof state:
α : Type u_1
s t : Set α
h : Disjoint s t
e : ↑s ⊕ ↑t ≃ ↑(s ∪ t)
⊢ encard (s ∪ t) = encard s + encard t

Next tactic:
simp [encard, ← PartENat.card_congr e, PartENat.card_sum, PartENat.withTopEquiv]
theorem encard_insert_of_not_mem (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
  

Proof state:
α : Type u_1
s t : Set α
a : α
has : a ∉ s
⊢ encard (insert a s) = encard s + 1

Next tactic:
rw [← union_singleton, encard_union_eq (by simpa), encard_singleton]
theorem encard_insert_of_not_mem (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
  rw [← union_singleton, encard_union_eq (by 

Proof state:
α : Type u_1
s t : Set α
a : α
has : a ∉ s
⊢ Disjoint s {a}

Next tactic:
simpa
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
  

Proof state:
α : Type u_1
s t : Set α
h : Set.Finite s
⊢ encard s < ⊤

Next tactic:
refine' h.induction_on (by simp) _
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
  refine' h.induction_on (by 

Proof state:
α : Type u_1
s t : Set α
h : Set.Finite s
⊢ encard ∅ < ⊤

Next tactic:
simp
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
  refine' h.induction_on (by simp) _
  

Proof state:
α : Type u_1
s t : Set α
h : Set.Finite s
⊢ ∀ {a : α} {s : Set α}, a ∉ s → Set.Finite s → encard s < ⊤ → encard (insert a s) < ⊤

Next tactic:
rintro a t hat _ ht'
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
  refine' h.induction_on (by simp) _
  rintro a t hat _ ht'
  

Proof state:
α : Type u_1
s t✝ : Set α
h : Set.Finite s
a : α
t : Set α
hat : a ∉ t
a✝ : Set.Finite t
ht' : encard t < ⊤
⊢ encard (insert a t) < ⊤

Next tactic:
rw [encard_insert_of_not_mem hat]
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
  refine' h.induction_on (by simp) _
  rintro a t hat _ ht'
  rw [encard_insert_of_not_mem hat]
  

Proof state:
α : Type u_1
s t✝ : Set α
h : Set.Finite s
a : α
t : Set α
hat : a ∉ t
a✝ : Set.Finite t
ht' : encard t < ⊤
⊢ encard t + 1 < ⊤

Next tactic:
exact lt_tsub_iff_right.1 ht'
@[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by
  

Proof state:
α : Type u_1
s t : Set α
⊢ encard s = ⊤ ↔ Set.Infinite s

Next tactic:
rw [← not_iff_not, ← Ne.def, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite]
theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by
  

Proof state:
α : Type u_1
s t : Set α
⊢ encard s ≠ ⊤ ↔ Set.Finite s

Next tactic:
simp
theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by
  

Proof state:
α : Type u_1
s t : Set α
k : ℕ
h : encard s ≤ ↑k
⊢ Set.Finite s

Next tactic:
rw [← encard_lt_top_iff]
theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by
  rw [← encard_lt_top_iff]; 

Proof state:
α : Type u_1
s t : Set α
k : ℕ
h : encard s ≤ ↑k
⊢ encard s < ⊤

Next tactic:
exact h.trans_lt (WithTop.coe_lt_top _)
theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k :=
  ⟨fun h ↦ ⟨finite_of_encard_le_coe h, by 

Proof state:
α : Type u_1
s t : Set α
k : ℕ
h : encard s ≤ ↑k
⊢ ∃ n₀, encard s = ↑n₀ ∧ n₀ ≤ k

Next tactic:
rwa [ENat.le_coe_iff] at h
theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k :=
  ⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩,
    fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by 

Proof state:
α : Type u_1
s t : Set α
k : ℕ
x✝ : Set.Finite s ∧ ∃ n₀, encard s = ↑n₀ ∧ n₀ ≤ k
left✝ : Set.Finite s
n₀ : ℕ
hs : encard s = ↑n₀
hle : n₀ ≤ k
⊢ encard s ≤ ↑k

Next tactic:
rwa [hs, Nat.cast_le]
theorem encard_le_of_subset (h : s ⊆ t) : s.encard ≤ t.encard := by
  

Proof state:
α : Type u_1
s t : Set α
h : s ⊆ t
⊢ encard s ≤ encard t

Next tactic:
rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]
theorem encard_le_of_subset (h : s ⊆ t) : s.encard ≤ t.encard := by
  rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; 

Proof state:
α : Type u_1
s t : Set α
h : s ⊆ t
⊢ encard s ≤ encard s + encard (t \ s)

Next tactic:
exact le_self_add
theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
  

Proof state:
α : Type u_1
s t : Set α
h : s ⊆ t
⊢ encard (t \ s) + encard s = encard t

Next tactic:
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h]
@[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by
  

Proof state:
α : Type u_1
s t : Set α
⊢ 1 ≤ encard s ↔ Set.Nonempty s

Next tactic:
rw [nonempty_iff_ne_empty, Ne.def, ← encard_eq_zero, ENat.one_le_iff_ne_zero]
theorem encard_diff_add_encard_inter (s t : Set α) :
    (s \ t).encard + (s ∩ t).encard = s.encard := by
  

Proof state:
α : Type u_1
s✝ t✝ s t : Set α
⊢ encard (s \ t) + encard (s ∩ t) = encard s

Next tactic:
rw [← encard_union_eq (disjoint_of_subset_right (inter_subset_right _ _) disjoint_sdiff_left),
    diff_union_inter]
theorem encard_union_add_encard_inter (s t : Set α) :
    (s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard :=
by 

Proof state:
α : Type u_1
s✝ t✝ s t : Set α
⊢ encard (s ∪ t) + encard (s ∩ t) = encard s + encard t

Next tactic:
rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm,
  encard_diff_add_encard_inter]
theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) :
    s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by
  

Proof state:
α : Type u_1
s t : Set α
h : Set.Finite (s ∩ t)
⊢ encard s = encard t ↔ encard (s \ t) = encard (t \ s)

Next tactic:
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
    WithTop.add_right_cancel_iff h.encard_lt_top.ne]
theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) :
    s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by
  

Proof state:
α : Type u_1
s t : Set α
h : Set.Finite (s ∩ t)
⊢ encard s ≤ encard t ↔ encard (s \ t) ≤ encard (t \ s)

Next tactic:
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
    WithTop.add_le_add_iff_right h.encard_lt_top.ne]
theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) :
    s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by
  

Proof state:
α : Type u_1
s t : Set α
h : Set.Finite (s ∩ t)
⊢ encard s < encard t ↔ encard (s \ t) < encard (t \ s)

Next tactic:
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
    WithTop.add_lt_add_iff_right h.encard_lt_top.ne]
theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by
  

Proof state:
α : Type u_1
s✝ t✝ s t : Set α
⊢ encard (s ∪ t) ≤ encard s + encard t

Next tactic:
rw [← encard_union_add_encard_inter]
theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by
  rw [← encard_union_add_encard_inter]; 

Proof state:
α : Type u_1
s✝ t✝ s t : Set α
⊢ encard (s ∪ t) ≤ encard (s ∪ t) + encard (s ∩ t)

Next tactic:
exact le_self_add
theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by
  

Proof state:
α : Type u_1
s t : Set α
h : encard s = encard t
⊢ Set.Finite s ↔ Set.Finite t

Next tactic:
rw [← encard_lt_top_iff, ← encard_lt_top_iff, h]
theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) :
    s.Infinite ↔ t.Infinite := by 

Proof state:
α : Type u_1
s t : Set α
h : encard s = encard t
⊢ Set.Infinite s ↔ Set.Infinite t

Next tactic:
rw [← encard_eq_top_iff, h, encard_eq_top_iff]
theorem Finite.eq_of_subset_of_encard_le (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) :
    s = t := by
  

Proof state:
α : Type u_1
s t : Set α
ht : Set.Finite t
hst : s ⊆ t
hts : encard t ≤ encard s
⊢ s = t

Next tactic:
rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts
theorem Finite.eq_of_subset_of_encard_le (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) :
    s = t := by
  rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts
  

Proof state:
α : Type u_1
s t : Set α
ht : Set.Finite t
hst : s ⊆ t
hts : encard (t \ s) + encard s ≤ 0 + encard s
⊢ s = t

Next tactic:
have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts
theorem Finite.eq_of_subset_of_encard_le (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) :
    s = t := by
  rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts
  have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts
  

Proof state:
α : Type u_1
s t : Set α
ht : Set.Finite t
hst : s ⊆ t
hts : encard (t \ s) + encard s ≤ 0 + encard s
hdiff : encard (t \ s) ≤ 0
⊢ s = t

Next tactic:
rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff
theorem Finite.eq_of_subset_of_encard_le (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) :
    s = t := by
  rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts
  have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts
  rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff
  

Proof state:
α : Type u_1
s t : Set α
ht : Set.Finite t
hst : s ⊆ t
hts : encard (t \ s) + encard s ≤ 0 + encard s
hdiff : t ⊆ s
⊢ s = t

Next tactic:
exact hst.antisymm hdiff
theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by
  

Proof state:
α : Type u_1
s✝ t✝ s t : Set α
⊢ encard (s \ t) + encard t = encard (s ∪ t)

Next tactic:
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self]
theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by
  

Proof state:
α : Type u_1
s✝ t✝ s t : Set α
⊢ encard s - encard t ≤ encard (s \ t)

Next tactic:
rw [tsub_le_iff_left, add_comm]
theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by
  rw [tsub_le_iff_left, add_comm]; 

Proof state:
α : Type u_1
s✝ t✝ s t : Set α
⊢ encard s ≤ encard (s \ t) + encard t

Next tactic:
apply encard_le_encard_diff_add_encard
theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by
  

Proof state:
α : Type u_1
s✝ t s : Set α
⊢ encard s + encard sᶜ = encard univ

Next tactic:
rw [← encard_union_eq disjoint_compl_right, union_compl_self]
theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
  

Proof state:
α : Type u_1
s✝ t s : Set α
x : α
⊢ encard (insert x s) ≤ encard s + 1

Next tactic:
rw [← union_singleton, ← encard_singleton x]
theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
  rw [← union_singleton, ← encard_singleton x]; 

Proof state:
α : Type u_1
s✝ t s : Set α
x : α
⊢ encard (s ∪ {x}) ≤ encard s + encard {x}

Next tactic:
apply encard_union_le
theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
  

Proof state:
α : Type u_1
s✝ t s : Set α
x : α
⊢ encard ({x} ∩ s) ≤ 1

Next tactic:
rw [← encard_singleton x]
theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
  rw [← encard_singleton x]; 

Proof state:
α : Type u_1
s✝ t s : Set α
x : α
⊢ encard ({x} ∩ s) ≤ encard {x}

Next tactic:
exact encard_le_of_subset (inter_subset_left _ _)
theorem encard_diff_singleton_add_one (h : a ∈ s) :
    (s \ {a}).encard + 1 = s.encard := by
  

Proof state:
α : Type u_1
s t : Set α
a : α
h : a ∈ s
⊢ encard (s \ {a}) + 1 = encard s

Next tactic:
rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h]
theorem encard_diff_singleton_of_mem (h : a ∈ s) :
    (s \ {a}).encard = s.encard - 1 := by
  

Proof state:
α : Type u_1
s t : Set α
a : α
h : a ∈ s
⊢ encard (s \ {a}) = encard s - 1

Next tactic:
rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_cancel_iff WithTop.one_ne_top,
    tsub_add_cancel_of_le (self_le_add_left _ _)]
theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) :
    s.encard - 1 ≤ (s \ {x}).encard := by
  

Proof state:
α : Type u_1
s✝ t s : Set α
x : α
⊢ encard s - 1 ≤ encard (s \ {x})

Next tactic:
rw [← encard_singleton x]
theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) :
    s.encard - 1 ≤ (s \ {x}).encard := by
  rw [← encard_singleton x]; 

Proof state:
α : Type u_1
s✝ t s : Set α
x : α
⊢ encard s - encard {x} ≤ encard (s \ {x})

Next tactic:
apply tsub_encard_le_encard_diff
theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by
  

Proof state:
α : Type u_1
s t : Set α
a b : α
ha : a ∉ s
hb : b ∈ s
⊢ encard (insert a (s \ {b})) = encard s

Next tactic:
rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb]
theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by
  rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb]
  

Proof state:
α : Type u_1
s t : Set α
a b : α
ha : a ∉ s
hb : b ∈ s
⊢ a ∉ s \ {b}

Next tactic:
simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true]
theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by
  

Proof state:
α : Type u_1
s t : Set α
a b : α
ha : a ∉ s
hb : b ∈ s
⊢ encard (insert a s \ {b}) = encard s

Next tactic:
rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb]
theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by
  rw [← insert_diff_singleton_comm (by 

Proof state:
α : Type u_1
s t : Set α
a b : α
ha : a ∉ s
hb : b ∈ s
⊢ a ≠ b

Next tactic:
rintro rfl
theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by
  rw [← insert_diff_singleton_comm (by rintro rfl; 

Proof state:
α : Type u_1
s t : Set α
a : α
ha : a ∉ s
hb : a ∈ s
⊢ False

Next tactic:
exact ha hb
theorem encard_eq_add_one_iff {k : ℕ∞} :
    s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
  

Proof state:
α : Type u_1
s t : Set α
k : ℕ∞
⊢ encard s = k + 1 ↔ ∃ a t, a ∉ t ∧ insert a t = s ∧ encard t = k

Next tactic:
refine' ⟨fun h ↦ _, _⟩
theorem encard_eq_add_one_iff {k : ℕ∞} :
    s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
  refine' ⟨fun h ↦ _, _⟩
  · 

Proof state:
case refine'_1
α : Type u_1
s t : Set α
k : ℕ∞
h : encard s = k + 1
⊢ ∃ a t, a ∉ t ∧ insert a t = s ∧ encard t = k

Next tactic:
obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
theorem encard_eq_add_one_iff {k : ℕ∞} :
    s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
  refine' ⟨fun h ↦ _, _⟩
  · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by 

Proof state:
α : Type u_1
s t : Set α
k : ℕ∞
h : encard s = k + 1
⊢ encard s ≠ 0

Next tactic:
simp [h]
theorem encard_eq_add_one_iff {k : ℕ∞} :
    s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
  refine' ⟨fun h ↦ _, _⟩
  · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
    

Proof state:
case refine'_1.intro
α : Type u_1
s t : Set α
k : ℕ∞
h : encard s = k + 1
a : α
ha : a ∈ s
⊢ ∃ a t, a ∉ t ∧ insert a t = s ∧ encard t = k

Next tactic:
refine' ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], _⟩
theorem encard_eq_add_one_iff {k : ℕ∞} :
    s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
  refine' ⟨fun h ↦ _, _⟩
  · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
    refine' ⟨a, s \ {a}, fun h ↦ h.2 rfl, by 

Proof state:
α : Type u_1
s t : Set α
k : ℕ∞
h : encard s = k + 1
a : α
ha : a ∈ s
⊢ insert a (s \ {a}) = s

Next tactic:
rwa [insert_diff_singleton, insert_eq_of_mem]
theorem encard_eq_add_one_iff {k : ℕ∞} :
    s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
  refine' ⟨fun h ↦ _, _⟩
  · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
    refine' ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], _⟩
    

Proof state:
case refine'_1.intro
α : Type u_1
s t : Set α
k : ℕ∞
h : encard s = k + 1
a : α
ha : a ∈ s
⊢ encard (s \ {a}) = k

Next tactic:
rw [← WithTop.add_right_cancel_iff WithTop.one_ne_top, ← h,
      encard_diff_singleton_add_one ha]
theorem encard_eq_add_one_iff {k : ℕ∞} :
    s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
  refine' ⟨fun h ↦ _, _⟩
  · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
    refine' ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], _⟩
    rw [← WithTop.add_right_cancel_iff WithTop.one_ne_top, ← h,
      encard_diff_singleton_add_one ha]
  

Proof state:
case refine'_2
α : Type u_1
s t : Set α
k : ℕ∞
⊢ (∃ a t, a ∉ t ∧ insert a t = s ∧ encard t = k) → encard s = k + 1

Next tactic:
rintro ⟨a, t, h, rfl, rfl⟩
theorem encard_eq_add_one_iff {k : ℕ∞} :
    s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
  refine' ⟨fun h ↦ _, _⟩
  · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
    refine' ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], _⟩
    rw [← WithTop.add_right_cancel_iff WithTop.one_ne_top, ← h,
      encard_diff_singleton_add_one ha]
  rintro ⟨a, t, h, rfl, rfl⟩
  

Proof state:
case refine'_2.intro.intro.intro.intro
α : Type u_1
t✝ : Set α
a : α
t : Set α
h : a ∉ t
⊢ encard (insert a t) = encard t + 1

Next tactic:
rw [encard_insert_of_not_mem h]
/-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended
  for well-founded induction on the value of `encard`. -/
theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) :
    s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by
  

Proof state:
α : Type u_1
s✝ t s : Set α
⊢ s = ∅ ∨ encard s = ⊤ ∨ ∃ a ∈ s, encard (s \ {a}) < encard s

Next tactic:
refine' s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦
    (s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, _⟩) (Or.inl ∘ Infinite.encard_eq)))
/-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended
  for well-founded induction on the value of `encard`. -/
theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) :
    s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by
  refine' s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦
    (s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, _⟩) (Or.inl ∘ Infinite.encard_eq)))
  

Proof state:
α : Type u_1
s✝ t s : Set α
x✝ : Set.Nonempty s
a : α
ha : a ∈ s
hfin : Set.Finite s
⊢ encard (s \ {a}) < encard s

Next tactic:
rw [← encard_diff_singleton_add_one ha]
/-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended
  for well-founded induction on the value of `encard`. -/
theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) :
    s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by
  refine' s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦
    (s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, _⟩) (Or.inl ∘ Infinite.encard_eq)))
  rw [← encard_diff_singleton_add_one ha]; 

Proof state:
α : Type u_1
s✝ t s : Set α
x✝ : Set.Nonempty s
a : α
ha : a ∈ s
hfin : Set.Finite s
⊢ encard (s \ {a}) < encard (s \ {a}) + 1

Next tactic:
nth_rw 1 [← add_zero (encard _)]
/-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended
  for well-founded induction on the value of `encard`. -/
theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) :
    s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by
  refine' s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦
    (s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, _⟩) (Or.inl ∘ Infinite.encard_eq)))
  rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)]
  

Proof state:
α : Type u_1
s✝ t s : Set α
x✝ : Set.Nonempty s
a : α
ha : a ∈ s
hfin : Set.Finite s
⊢ encard (s \ {a}) + 0 < encard (s \ {a}) + 1

Next tactic:
exact WithTop.add_lt_add_left (hfin.diff _).encard_lt_top.ne zero_lt_one
theorem encard_pair (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
  

Proof state:
α : Type u_1
s t : Set α
x y : α
hne : x ≠ y
⊢ encard {x, y} = 2

Next tactic:
rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two,
    WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_singleton]
theorem encard_pair (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
  rw [encard_insert_of_not_mem (by 

Proof state:
α : Type u_1
s t : Set α
x y : α
hne : x ≠ y
⊢ x ∉ {y}

Next tactic:
simpa
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
  

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

Next tactic:
refine' ⟨fun h ↦ _, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
  refine' ⟨fun h ↦ _, fun ⟨x, hx⟩ ↦ by 

Proof state:
α : Type u_1
s t : Set α
x✝ : ∃ x, s = {x}
x : α
hx : s = {x}
⊢ encard s = 1

Next tactic:
rw [hx, encard_singleton]
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
  refine' ⟨fun h ↦ _, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
  

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

Next tactic:
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
  refine' ⟨fun h ↦ _, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
  obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by 

Proof state:
α : Type u_1
s t : Set α
h : encard s = 1
⊢ encard s ≠ 0

Next tactic:
rw [h]
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
  refine' ⟨fun h ↦ _, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
  obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; 

Proof state:
α : Type u_1
s t : Set α
h : encard s = 1
⊢ 1 ≠ 0

Next tactic:
simp
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
  refine' ⟨fun h ↦ _, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
  obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
  

Proof state:
case intro
α : Type u_1
s t : Set α
h : encard s = 1
x : α
hx : x ∈ s
⊢ ∃ x, s = {x}

Next tactic:
exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le' (by simpa) (by simp [h])).symm⟩
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
  refine' ⟨fun h ↦ _, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
  obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
  exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le' (by 

Proof state:
α : Type u_1
s t : Set α
h : encard s = 1
x : α
hx : x ∈ s
⊢ {x} ⊆ s

Next tactic:
simpa