data.set.ncardMathlib.Data.Set.Card

This file has been ported!

Changes since the initial port

The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.

Changes in mathlib3

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(last sync)

Changes in mathlib3port

mathlib3
mathlib3port
Diff
@@ -1022,7 +1022,7 @@ theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} :=
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
-/- ./././Mathport/Syntax/Translate/Basic.lean:641:2: warning: expanding binder collection (a «expr ∉ » s) -/
+/- ./././Mathport/Syntax/Translate/Basic.lean:642:2: warning: expanding binder collection (a «expr ∉ » s) -/
 #print Set.exists_eq_insert_iff_ncard /-
 theorem exists_eq_insert_iff_ncard
     (hs : s.Finite := by
Diff
@@ -383,7 +383,7 @@ theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard)
   classical
   haveI := hs.fintype
   haveI := ((to_finite s).image f).Fintype
-  simp_rw [ncard_eq_to_finset_card] at h 
+  simp_rw [ncard_eq_to_finset_card] at h
   rw [← coe_to_finset s]
   apply Finset.injOn_of_card_image_eq
   convert h
@@ -492,7 +492,7 @@ theorem eq_of_subset_of_ncard_le (h : s ⊆ t) (h' : t.ncard ≤ s.ncard)
   rw [← @to_finset_inj]
   apply Finset.eq_of_subset_of_card_le
   · simpa
-  rw [ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ (ht.subset h)] at h' 
+  rw [ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ (ht.subset h)] at h'
   convert h'
 #align set.eq_of_subset_of_ncard_le Set.eq_of_subset_of_ncard_le
 -/
@@ -618,7 +618,7 @@ theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.n
         to_finite_tac) :
     ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ f x = f y := by
   by_contra h'
-  simp only [Ne.def, exists_prop, not_exists, not_and, not_imp_not] at h' 
+  simp only [Ne.def, exists_prop, not_exists, not_and, not_imp_not] at h'
   exact (ncard_le_ncard_of_inj_on f hf h' ht).not_lt hc
 #align set.exists_ne_map_eq_of_ncard_lt_of_maps_to Set.exists_ne_map_eq_of_ncard_lt_of_maps_to
 -/
@@ -651,7 +651,7 @@ theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
     apply hinj _ _ hx hy hxy
   haveI := ht.fintype
   haveI := Fintype.ofInjective f' finj
-  simp_rw [ncard_eq_to_finset_card] at hst 
+  simp_rw [ncard_eq_to_finset_card] at hst
   set f'' : ∀ a, a ∈ s.to_finset → β := fun a h => f a (by simpa using h) with hf''
   convert
     @Finset.surj_on_of_inj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)
@@ -678,7 +678,7 @@ theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
     exact ⟨_, ha, rfl⟩
   haveI := hs.fintype
   haveI := Fintype.ofSurjective _ hsurj
-  simp_rw [ncard_eq_to_finset_card] at hst 
+  simp_rw [ncard_eq_to_finset_card] at hst
   set f'' : ∀ a, a ∈ s.to_finset → β := fun a h => f a (by simpa using h) with hf''
   exact
     @Finset.inj_on_of_surj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)
@@ -941,9 +941,9 @@ theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂
     simp_rw [ncard_eq_to_finset_card] 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₁ 
+  rw [ht.ncard] at h₁
   have h₁' := Nat.eq_zero_of_le_zero h₁
-  rw [add_eq_zero_iff] at h₁' 
+  rw [add_eq_zero_iff] at h₁'
   exact ⟨t, h₂, rfl.subset, by rw [ht.ncard, h₁'.1, h₁'.2]⟩
 #align set.exists_intermediate_set Set.exists_intermediate_Set
 -/
@@ -954,7 +954,7 @@ theorem exists_intermediate_set' {m : ℕ} (hs : s.ncard ≤ m) (ht : m ≤ t.nc
   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 
+  rw [tsub_add_cancel_of_le hs] at hc
   exact ⟨r, hsr, hrt, hc⟩
 #align set.exists_intermediate_set' Set.exists_intermediate_set'
 -/
@@ -1001,7 +1001,7 @@ theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s
   rw [ncard_eq_to_finset_card _ hu,
     finite.to_finset_union (hu.subset (subset_union_left _ _))
       (hu.subset (subset_union_right _ _))] at
-    hst 
+    hst
   obtain ⟨r', hnr', hr'⟩ := Finset.exists_subset_or_subset_of_two_mul_lt_card hst
   exact ⟨r', by simpa, by simpa using hr'⟩
 #align set.exists_subset_or_subset_of_two_mul_lt_ncard Set.exists_subset_or_subset_of_two_mul_lt_ncard
@@ -1016,8 +1016,8 @@ theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} :=
   by
   refine' ⟨fun h => _, by rintro ⟨a, rfl⟩; rw [ncard_singleton]⟩
   haveI := (finite_of_ncard_ne_zero (ne_zero_of_eq_one h)).to_subtype
-  rw [ncard_eq_to_finset_card, Finset.card_eq_one] at h 
-  exact h.imp fun a ha => by rwa [← finite.to_finset_singleton, finite.to_finset_inj] at ha 
+  rw [ncard_eq_to_finset_card, Finset.card_eq_one] at h
+  exact h.imp fun a ha => by rwa [← finite.to_finset_singleton, finite.to_finset_inj] at ha
 #align set.ncard_eq_one Set.ncard_eq_one
 -/
 
@@ -1039,11 +1039,11 @@ theorem exists_eq_insert_iff_ncard
     exact ⟨a, by rwa [finite.mem_to_finset], rfl⟩
   rintro ⟨hst, h⟩
   have ht := @finite_of_ncard_pos _ t (by rw [← h]; apply Nat.zero_lt_succ)
-  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht] at h 
+  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht] at h
   obtain ⟨a, has, ha⟩ := finset.exists_eq_insert_iff.mpr ⟨by simpa, h⟩
   have hsa := hs.insert a
-  rw [← finite.to_finset_insert] at ha 
-  exact ⟨a, by rwa [finite.mem_to_finset] at has , by rwa [← @finite.to_finset_inj _ _ _ hsa ht]⟩
+  rw [← finite.to_finset_insert] at ha
+  exact ⟨a, by rwa [finite.mem_to_finset] at has, by rwa [← @finite.to_finset_inj _ _ _ hsa ht]⟩
 #align set.exists_eq_insert_iff_ncard Set.exists_eq_insert_iff_ncard
 -/
 
@@ -1156,7 +1156,7 @@ theorem two_lt_ncard
 theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s ∧ b ≠ a :=
   by
   haveI := (finite_of_ncard_ne_zero (zero_lt_one.trans hs).Ne.symm).to_subtype
-  rw [ncard_eq_to_finset_card] at hs 
+  rw [ncard_eq_to_finset_card] at hs
   simpa only [finite.mem_to_finset] using Finset.exists_ne_of_one_lt_card hs a
 #align set.exists_ne_of_one_lt_ncard Set.exists_ne_of_one_lt_ncard
 -/
@@ -1166,7 +1166,7 @@ theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
     ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
   classical
   haveI := @Fintype.ofFinite _ (finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)).to_subtype
-  rw [ncard_eq_to_finset_card, Finset.card_eq_succ] at h 
+  rw [ncard_eq_to_finset_card, Finset.card_eq_succ] at h
   obtain ⟨a, t, hat, hts, rfl⟩ := h
   refine' ⟨a, t, hat, _, by rw [ncard_coe_finset]⟩
   rw [← to_finset_inj]
@@ -1195,7 +1195,7 @@ theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
   refine' ⟨fun h => _, _⟩
   · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
     obtain ⟨y, rfl⟩ := ncard_eq_one.mp ht
-    rw [mem_singleton_iff] at hxt 
+    rw [mem_singleton_iff] at hxt
     exact ⟨_, _, hxt, rfl⟩
   rintro ⟨x, y, hxy, rfl⟩
   rw [ncard_eq_to_finset_card, Finset.card_eq_two]
@@ -1209,7 +1209,7 @@ theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y 
   refine' ⟨fun h => _, _⟩
   · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
     obtain ⟨y, z, hyz, rfl⟩ := ncard_eq_two.mp ht
-    rw [mem_insert_iff, mem_singleton_iff, not_or] at hxt 
+    rw [mem_insert_iff, mem_singleton_iff, not_or] at hxt
     exact ⟨x, y, z, hxt.1, hxt.2, hyz, rfl⟩
   rintro ⟨x, y, z, xy, xz, yz, rfl⟩
   rw [ncard_insert_of_not_mem, ncard_insert_of_not_mem, ncard_singleton]
Diff
@@ -751,7 +751,7 @@ theorem ncard_union_eq (h : Disjoint s t)
   classical
   rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht,
     ncard_eq_to_finset_card _ (hs.union ht), finite.to_finset_union]
-  refine' Finset.card_union_eq _
+  refine' Finset.card_union_of_disjoint _
   rwa [finite.disjoint_to_finset]
 #align set.ncard_union_eq Set.ncard_union_eq
 -/
Diff
@@ -186,7 +186,12 @@ theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by simp [ncard_eq
 -/
 
 #print Set.ncard_singleton_inter /-
-theorem ncard_singleton_inter : ({a} ∩ s).ncard ≤ 1 := by classical
+theorem ncard_singleton_inter : ({a} ∩ s).ncard ≤ 1 := by
+  classical
+  rw [← inter_self {a}, inter_assoc, ncard_eq_to_finset_card, finite.to_finset_inter,
+    finite.to_finset_singleton]
+  · apply Finset.card_singleton_inter
+  all_goals apply to_finite
 #align set.ncard_singleton_inter Set.ncard_singleton_inter
 -/
 
@@ -199,7 +204,12 @@ theorem ncard_insert_of_not_mem (h : a ∉ s)
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    (insert a s).ncard = s.ncard + 1 := by classical
+    (insert a s).ncard = s.ncard + 1 := by
+  classical
+  haveI := hs.fintype
+  rw [ncard_eq_to_finset_card, ncard_eq_to_finset_card, finite.to_finset_insert,
+    Finset.card_insert_of_not_mem]
+  rwa [finite.mem_to_finset]
 #align set.ncard_insert_of_not_mem Set.ncard_insert_of_not_mem
 -/
 
@@ -209,7 +219,15 @@ theorem ncard_insert_of_mem (h : a ∈ s) : ncard (insert a s) = s.ncard := by r
 -/
 
 #print Set.ncard_insert_le /-
-theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by classical
+theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
+  classical
+  obtain hs | hs := s.finite_or_infinite
+  ·
+    exact
+      (em (a ∈ s)).elim (fun h => (ncard_insert_of_mem h).trans_le (Nat.le_succ _)) fun h => by
+        rw [ncard_insert_of_not_mem h hs]
+  rw [(hs.mono (subset_insert a s)).ncard]
+  exact Nat.zero_le _
 #align set.ncard_insert_le Set.ncard_insert_le
 -/
 
@@ -228,7 +246,14 @@ theorem ncard_insert_eq_ite [Decidable (a ∈ s)]
 -/
 
 #print Set.ncard_le_ncard_insert /-
-theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by classical
+theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
+  classical
+  refine' s.finite_or_infinite.elim (fun h => _) fun h => by rw [h.ncard]; exact Nat.zero_le _
+  rw [ncard_insert_eq_ite h]
+  split_ifs
+  · rfl
+  · simp only [le_add_iff_nonneg_right, zero_le']
+  exact Classical.dec (a ∈ s)
 #align set.ncard_le_ncard_insert Set.ncard_le_ncard_insert
 -/
 
@@ -325,7 +350,15 @@ theorem ncard_image_le
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    (f '' s).ncard ≤ s.ncard := by classical
+    (f '' s).ncard ≤ s.ncard := by
+  classical
+  rw [ncard_eq_to_finset_card s hs]
+  haveI := hs.fintype
+  convert @Finset.card_image_le _ _ s.to_finset f _
+  rw [ncard_eq_to_finset_card, finite.to_finset_image _ hs]
+  · congr; rw [← Finset.coe_inj, finite.coe_to_finset, coe_to_finset]
+  · infer_instance
+  rw [← Finset.coe_inj, finite.coe_to_finset, coe_to_finset]
 #align set.ncard_image_le Set.ncard_image_le
 -/
 
@@ -346,7 +379,16 @@ theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard)
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    Set.InjOn f s := by classical
+    Set.InjOn f s := by
+  classical
+  haveI := hs.fintype
+  haveI := ((to_finite s).image f).Fintype
+  simp_rw [ncard_eq_to_finset_card] at h 
+  rw [← coe_to_finset s]
+  apply Finset.injOn_of_card_image_eq
+  convert h
+  ext
+  simp
 #align set.inj_on_of_ncard_image_eq Set.injOn_of_ncard_image_eq
 -/
 
@@ -626,7 +668,21 @@ theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    a₁ = a₂ := by classical
+    a₁ = a₂ := by
+  classical
+  set f' : s → t := fun x => ⟨f x.1 x.2, hf _ _⟩ with hf'
+  have hsurj : f'.surjective := by
+    rintro ⟨y, hy⟩
+    obtain ⟨a, ha, rfl⟩ := hsurj y hy
+    simp only [Subtype.val_eq_coe, Subtype.coe_mk, Subtype.mk_eq_mk, SetCoe.exists]
+    exact ⟨_, ha, rfl⟩
+  haveI := hs.fintype
+  haveI := Fintype.ofSurjective _ hsurj
+  simp_rw [ncard_eq_to_finset_card] at hst 
+  set f'' : ∀ a, a ∈ s.to_finset → β := fun a h => f a (by simpa using h) with hf''
+  exact
+    @Finset.inj_on_of_surj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)
+      (by convert hst) a₁ a₂ (by simpa) (by simpa) (by simpa)
 #align set.inj_on_of_surj_on_of_ncard_le Set.inj_on_of_surj_on_of_ncard_le
 -/
 
@@ -642,7 +698,13 @@ theorem ncard_union_add_ncard_inter (s t : Set α)
     (ht : t.Finite := by
       run_tac
         to_finite_tac) :
-    (s ∪ t).ncard + (s ∩ t).ncard = s.ncard + t.ncard := by classical
+    (s ∪ t).ncard + (s ∩ t).ncard = s.ncard + t.ncard := by
+  classical
+  have hu := hs.union ht
+  have hi := hs.subset (inter_subset_left s t)
+  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ hu,
+    ncard_eq_to_finset_card _ hi, finite.to_finset_union, finite.to_finset_inter]
+  · exact Finset.card_union_add_card_inter _ _
 #align set.ncard_union_add_ncard_inter Set.ncard_union_add_ncard_inter
 -/
 
@@ -662,7 +724,16 @@ theorem ncard_inter_add_ncard_union (s t : Set α)
 -/
 
 #print Set.ncard_union_le /-
-theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by classical
+theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by
+  classical
+  cases (s ∪ t).finite_or_infinite
+  · have hs := h.subset (subset_union_left s t)
+    have ht := h.subset (subset_union_right s t)
+    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ h,
+      finite.to_finset_union]
+    exact Finset.card_union_le _ _
+  convert Nat.zero_le _
+  rw [h.ncard]
 #align set.ncard_union_le Set.ncard_union_le
 -/
 
@@ -676,7 +747,12 @@ theorem ncard_union_eq (h : Disjoint s t)
     (ht : t.Finite := by
       run_tac
         to_finite_tac) :
-    (s ∪ t).ncard = s.ncard + t.ncard := by classical
+    (s ∪ t).ncard = s.ncard + t.ncard := by
+  classical
+  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht,
+    ncard_eq_to_finset_card _ (hs.union ht), finite.to_finset_union]
+  refine' Finset.card_union_eq _
+  rwa [finite.disjoint_to_finset]
 #align set.ncard_union_eq Set.ncard_union_eq
 -/
 
@@ -686,7 +762,12 @@ theorem ncard_diff_add_ncard_of_subset (h : s ⊆ t)
     (ht : t.Finite := by
       run_tac
         to_finite_tac) :
-    (t \ s).ncard + s.ncard = t.ncard := by classical
+    (t \ s).ncard + s.ncard = t.ncard := by
+  classical
+  rw [ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ (ht.subset h),
+    ncard_eq_to_finset_card _ (ht.diff s), finite.to_finset_diff]
+  refine' Finset.card_sdiff_add_card_eq_card _
+  rwa [finite.to_finset_subset_to_finset]
 #align set.ncard_diff_add_ncard_eq_ncard Set.ncard_diff_add_ncard_of_subset
 -/
 
@@ -914,7 +995,15 @@ theorem Infinite.exists_superset_ncard_eq {s t : Set α} (ht : t.Infinite) (hst
 
 #print Set.exists_subset_or_subset_of_two_mul_lt_ncard /-
 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
+    ∃ 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_to_finset_card _ hu,
+    finite.to_finset_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'⟩
 #align set.exists_subset_or_subset_of_two_mul_lt_ncard Set.exists_subset_or_subset_of_two_mul_lt_ncard
 -/
 
@@ -939,7 +1028,22 @@ theorem exists_eq_insert_iff_ncard
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    (∃ (a : _) (_ : a ∉ s), insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by classical
+    (∃ (a : _) (_ : a ∉ s), insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
+  classical
+  constructor
+  · rintro ⟨a, ha, rfl⟩
+    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ (hs.insert a),
+      finite.to_finset_insert, ← @finite.to_finset_subset_to_finset _ _ _ hs (hs.insert a),
+      finite.to_finset_insert]
+    refine' (@Finset.exists_eq_insert_iff _ _ hs.to_finset (insert a hs.to_finset)).mp _
+    exact ⟨a, by rwa [finite.mem_to_finset], rfl⟩
+  rintro ⟨hst, h⟩
+  have ht := @finite_of_ncard_pos _ t (by rw [← h]; apply Nat.zero_lt_succ)
+  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht] at h 
+  obtain ⟨a, has, ha⟩ := finset.exists_eq_insert_iff.mpr ⟨by simpa, h⟩
+  have hsa := hs.insert a
+  rw [← finite.to_finset_insert] at ha 
+  exact ⟨a, by rwa [finite.mem_to_finset] at has , by rwa [← @finite.to_finset_inj _ _ _ hsa ht]⟩
 #align set.exists_eq_insert_iff_ncard Set.exists_eq_insert_iff_ncard
 -/
 
@@ -1059,7 +1163,15 @@ theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s 
 
 #print Set.eq_insert_of_ncard_eq_succ /-
 theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
-    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by classical
+    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
+  classical
+  haveI := @Fintype.ofFinite _ (finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)).to_subtype
+  rw [ncard_eq_to_finset_card, Finset.card_eq_succ] at h 
+  obtain ⟨a, t, hat, hts, rfl⟩ := h
+  refine' ⟨a, t, hat, _, by rw [ncard_coe_finset]⟩
+  rw [← to_finset_inj]
+  convert hts
+  simp only [to_finset_insert, Finset.toFinset_coe]
 #align set.eq_insert_of_ncard_eq_succ Set.eq_insert_of_ncard_eq_succ
 -/
 
@@ -1069,18 +1181,41 @@ theorem ncard_eq_succ {n : ℕ}
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    s.ncard = n + 1 ↔ ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by classical
+    s.ncard = n + 1 ↔ ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
+  classical
+  refine' ⟨eq_insert_of_ncard_eq_succ, _⟩
+  rintro ⟨a, t, hat, h, rfl⟩
+  rw [← h, ncard_insert_of_not_mem hat (hs.subset ((subset_insert a t).trans_eq h))]
 #align set.ncard_eq_succ Set.ncard_eq_succ
 -/
 
 #print Set.ncard_eq_two /-
-theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by classical
+theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
+  classical
+  refine' ⟨fun h => _, _⟩
+  · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
+    obtain ⟨y, rfl⟩ := ncard_eq_one.mp ht
+    rw [mem_singleton_iff] at hxt 
+    exact ⟨_, _, hxt, rfl⟩
+  rintro ⟨x, y, hxy, rfl⟩
+  rw [ncard_eq_to_finset_card, Finset.card_eq_two]
+  exact ⟨x, y, hxy, by ext; simp⟩
 #align set.ncard_eq_two Set.ncard_eq_two
 -/
 
 #print Set.ncard_eq_three /-
 theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
   classical
+  refine' ⟨fun h => _, _⟩
+  · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
+    obtain ⟨y, z, hyz, rfl⟩ := ncard_eq_two.mp ht
+    rw [mem_insert_iff, mem_singleton_iff, not_or] at hxt 
+    exact ⟨x, y, z, hxt.1, hxt.2, hyz, rfl⟩
+  rintro ⟨x, y, z, xy, xz, yz, rfl⟩
+  rw [ncard_insert_of_not_mem, ncard_insert_of_not_mem, ncard_singleton]
+  · rwa [mem_singleton_iff]
+  rw [mem_insert_iff, mem_singleton_iff]
+  tauto
 #align set.ncard_eq_three Set.ncard_eq_three
 -/
 
Diff
@@ -186,12 +186,7 @@ theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by simp [ncard_eq
 -/
 
 #print Set.ncard_singleton_inter /-
-theorem ncard_singleton_inter : ({a} ∩ s).ncard ≤ 1 := by
-  classical
-  rw [← inter_self {a}, inter_assoc, ncard_eq_to_finset_card, finite.to_finset_inter,
-    finite.to_finset_singleton]
-  · apply Finset.card_singleton_inter
-  all_goals apply to_finite
+theorem ncard_singleton_inter : ({a} ∩ s).ncard ≤ 1 := by classical
 #align set.ncard_singleton_inter Set.ncard_singleton_inter
 -/
 
@@ -204,12 +199,7 @@ theorem ncard_insert_of_not_mem (h : a ∉ s)
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    (insert a s).ncard = s.ncard + 1 := by
-  classical
-  haveI := hs.fintype
-  rw [ncard_eq_to_finset_card, ncard_eq_to_finset_card, finite.to_finset_insert,
-    Finset.card_insert_of_not_mem]
-  rwa [finite.mem_to_finset]
+    (insert a s).ncard = s.ncard + 1 := by classical
 #align set.ncard_insert_of_not_mem Set.ncard_insert_of_not_mem
 -/
 
@@ -219,15 +209,7 @@ theorem ncard_insert_of_mem (h : a ∈ s) : ncard (insert a s) = s.ncard := by r
 -/
 
 #print Set.ncard_insert_le /-
-theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
-  classical
-  obtain hs | hs := s.finite_or_infinite
-  ·
-    exact
-      (em (a ∈ s)).elim (fun h => (ncard_insert_of_mem h).trans_le (Nat.le_succ _)) fun h => by
-        rw [ncard_insert_of_not_mem h hs]
-  rw [(hs.mono (subset_insert a s)).ncard]
-  exact Nat.zero_le _
+theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by classical
 #align set.ncard_insert_le Set.ncard_insert_le
 -/
 
@@ -246,14 +228,7 @@ theorem ncard_insert_eq_ite [Decidable (a ∈ s)]
 -/
 
 #print Set.ncard_le_ncard_insert /-
-theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
-  classical
-  refine' s.finite_or_infinite.elim (fun h => _) fun h => by rw [h.ncard]; exact Nat.zero_le _
-  rw [ncard_insert_eq_ite h]
-  split_ifs
-  · rfl
-  · simp only [le_add_iff_nonneg_right, zero_le']
-  exact Classical.dec (a ∈ s)
+theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by classical
 #align set.ncard_le_ncard_insert Set.ncard_le_ncard_insert
 -/
 
@@ -350,15 +325,7 @@ theorem ncard_image_le
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    (f '' s).ncard ≤ s.ncard := by
-  classical
-  rw [ncard_eq_to_finset_card s hs]
-  haveI := hs.fintype
-  convert @Finset.card_image_le _ _ s.to_finset f _
-  rw [ncard_eq_to_finset_card, finite.to_finset_image _ hs]
-  · congr; rw [← Finset.coe_inj, finite.coe_to_finset, coe_to_finset]
-  · infer_instance
-  rw [← Finset.coe_inj, finite.coe_to_finset, coe_to_finset]
+    (f '' s).ncard ≤ s.ncard := by classical
 #align set.ncard_image_le Set.ncard_image_le
 -/
 
@@ -379,16 +346,7 @@ theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard)
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    Set.InjOn f s := by
-  classical
-  haveI := hs.fintype
-  haveI := ((to_finite s).image f).Fintype
-  simp_rw [ncard_eq_to_finset_card] at h 
-  rw [← coe_to_finset s]
-  apply Finset.injOn_of_card_image_eq
-  convert h
-  ext
-  simp
+    Set.InjOn f s := by classical
 #align set.inj_on_of_ncard_image_eq Set.injOn_of_ncard_image_eq
 -/
 
@@ -668,21 +626,7 @@ theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    a₁ = a₂ := by
-  classical
-  set f' : s → t := fun x => ⟨f x.1 x.2, hf _ _⟩ with hf'
-  have hsurj : f'.surjective := by
-    rintro ⟨y, hy⟩
-    obtain ⟨a, ha, rfl⟩ := hsurj y hy
-    simp only [Subtype.val_eq_coe, Subtype.coe_mk, Subtype.mk_eq_mk, SetCoe.exists]
-    exact ⟨_, ha, rfl⟩
-  haveI := hs.fintype
-  haveI := Fintype.ofSurjective _ hsurj
-  simp_rw [ncard_eq_to_finset_card] at hst 
-  set f'' : ∀ a, a ∈ s.to_finset → β := fun a h => f a (by simpa using h) with hf''
-  exact
-    @Finset.inj_on_of_surj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)
-      (by convert hst) a₁ a₂ (by simpa) (by simpa) (by simpa)
+    a₁ = a₂ := by classical
 #align set.inj_on_of_surj_on_of_ncard_le Set.inj_on_of_surj_on_of_ncard_le
 -/
 
@@ -698,13 +642,7 @@ theorem ncard_union_add_ncard_inter (s t : Set α)
     (ht : t.Finite := by
       run_tac
         to_finite_tac) :
-    (s ∪ t).ncard + (s ∩ t).ncard = s.ncard + t.ncard := by
-  classical
-  have hu := hs.union ht
-  have hi := hs.subset (inter_subset_left s t)
-  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ hu,
-    ncard_eq_to_finset_card _ hi, finite.to_finset_union, finite.to_finset_inter]
-  · exact Finset.card_union_add_card_inter _ _
+    (s ∪ t).ncard + (s ∩ t).ncard = s.ncard + t.ncard := by classical
 #align set.ncard_union_add_ncard_inter Set.ncard_union_add_ncard_inter
 -/
 
@@ -724,16 +662,7 @@ theorem ncard_inter_add_ncard_union (s t : Set α)
 -/
 
 #print Set.ncard_union_le /-
-theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by
-  classical
-  cases (s ∪ t).finite_or_infinite
-  · have hs := h.subset (subset_union_left s t)
-    have ht := h.subset (subset_union_right s t)
-    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ h,
-      finite.to_finset_union]
-    exact Finset.card_union_le _ _
-  convert Nat.zero_le _
-  rw [h.ncard]
+theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by classical
 #align set.ncard_union_le Set.ncard_union_le
 -/
 
@@ -747,12 +676,7 @@ theorem ncard_union_eq (h : Disjoint s t)
     (ht : t.Finite := by
       run_tac
         to_finite_tac) :
-    (s ∪ t).ncard = s.ncard + t.ncard := by
-  classical
-  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht,
-    ncard_eq_to_finset_card _ (hs.union ht), finite.to_finset_union]
-  refine' Finset.card_union_eq _
-  rwa [finite.disjoint_to_finset]
+    (s ∪ t).ncard = s.ncard + t.ncard := by classical
 #align set.ncard_union_eq Set.ncard_union_eq
 -/
 
@@ -762,12 +686,7 @@ theorem ncard_diff_add_ncard_of_subset (h : s ⊆ t)
     (ht : t.Finite := by
       run_tac
         to_finite_tac) :
-    (t \ s).ncard + s.ncard = t.ncard := by
-  classical
-  rw [ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ (ht.subset h),
-    ncard_eq_to_finset_card _ (ht.diff s), finite.to_finset_diff]
-  refine' Finset.card_sdiff_add_card_eq_card _
-  rwa [finite.to_finset_subset_to_finset]
+    (t \ s).ncard + s.ncard = t.ncard := by classical
 #align set.ncard_diff_add_ncard_eq_ncard Set.ncard_diff_add_ncard_of_subset
 -/
 
@@ -995,15 +914,7 @@ theorem Infinite.exists_superset_ncard_eq {s t : Set α} (ht : t.Infinite) (hst
 
 #print Set.exists_subset_or_subset_of_two_mul_lt_ncard /-
 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_to_finset_card _ hu,
-    finite.to_finset_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'⟩
+    ∃ r : Set α, n < r.ncard ∧ (r ⊆ s ∨ r ⊆ t) := by classical
 #align set.exists_subset_or_subset_of_two_mul_lt_ncard Set.exists_subset_or_subset_of_two_mul_lt_ncard
 -/
 
@@ -1028,22 +939,7 @@ theorem exists_eq_insert_iff_ncard
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    (∃ (a : _) (_ : a ∉ s), insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
-  classical
-  constructor
-  · rintro ⟨a, ha, rfl⟩
-    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ (hs.insert a),
-      finite.to_finset_insert, ← @finite.to_finset_subset_to_finset _ _ _ hs (hs.insert a),
-      finite.to_finset_insert]
-    refine' (@Finset.exists_eq_insert_iff _ _ hs.to_finset (insert a hs.to_finset)).mp _
-    exact ⟨a, by rwa [finite.mem_to_finset], rfl⟩
-  rintro ⟨hst, h⟩
-  have ht := @finite_of_ncard_pos _ t (by rw [← h]; apply Nat.zero_lt_succ)
-  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht] at h 
-  obtain ⟨a, has, ha⟩ := finset.exists_eq_insert_iff.mpr ⟨by simpa, h⟩
-  have hsa := hs.insert a
-  rw [← finite.to_finset_insert] at ha 
-  exact ⟨a, by rwa [finite.mem_to_finset] at has , by rwa [← @finite.to_finset_inj _ _ _ hsa ht]⟩
+    (∃ (a : _) (_ : a ∉ s), insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by classical
 #align set.exists_eq_insert_iff_ncard Set.exists_eq_insert_iff_ncard
 -/
 
@@ -1163,15 +1059,7 @@ theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s 
 
 #print Set.eq_insert_of_ncard_eq_succ /-
 theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
-    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
-  classical
-  haveI := @Fintype.ofFinite _ (finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)).to_subtype
-  rw [ncard_eq_to_finset_card, Finset.card_eq_succ] at h 
-  obtain ⟨a, t, hat, hts, rfl⟩ := h
-  refine' ⟨a, t, hat, _, by rw [ncard_coe_finset]⟩
-  rw [← to_finset_inj]
-  convert hts
-  simp only [to_finset_insert, Finset.toFinset_coe]
+    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by classical
 #align set.eq_insert_of_ncard_eq_succ Set.eq_insert_of_ncard_eq_succ
 -/
 
@@ -1181,41 +1069,18 @@ theorem ncard_eq_succ {n : ℕ}
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    s.ncard = n + 1 ↔ ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
-  classical
-  refine' ⟨eq_insert_of_ncard_eq_succ, _⟩
-  rintro ⟨a, t, hat, h, rfl⟩
-  rw [← h, ncard_insert_of_not_mem hat (hs.subset ((subset_insert a t).trans_eq h))]
+    s.ncard = n + 1 ↔ ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by classical
 #align set.ncard_eq_succ Set.ncard_eq_succ
 -/
 
 #print Set.ncard_eq_two /-
-theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
-  classical
-  refine' ⟨fun h => _, _⟩
-  · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
-    obtain ⟨y, rfl⟩ := ncard_eq_one.mp ht
-    rw [mem_singleton_iff] at hxt 
-    exact ⟨_, _, hxt, rfl⟩
-  rintro ⟨x, y, hxy, rfl⟩
-  rw [ncard_eq_to_finset_card, Finset.card_eq_two]
-  exact ⟨x, y, hxy, by ext; simp⟩
+theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by classical
 #align set.ncard_eq_two Set.ncard_eq_two
 -/
 
 #print Set.ncard_eq_three /-
 theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
   classical
-  refine' ⟨fun h => _, _⟩
-  · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
-    obtain ⟨y, z, hyz, rfl⟩ := ncard_eq_two.mp ht
-    rw [mem_insert_iff, mem_singleton_iff, not_or] at hxt 
-    exact ⟨x, y, z, hxt.1, hxt.2, hyz, rfl⟩
-  rintro ⟨x, y, z, xy, xz, yz, rfl⟩
-  rw [ncard_insert_of_not_mem, ncard_insert_of_not_mem, ncard_singleton]
-  · rwa [mem_singleton_iff]
-  rw [mem_insert_iff, mem_singleton_iff]
-  tauto
 #align set.ncard_eq_three Set.ncard_eq_three
 -/
 
Diff
@@ -84,18 +84,18 @@ theorem ncard_eq_toFinset_card (s : Set α)
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
-#print Set.ncard_le_of_subset /-
-theorem ncard_le_of_subset (hst : s ⊆ t)
+#print Set.ncard_le_ncard /-
+theorem ncard_le_ncard (hst : s ⊆ t)
     (ht : t.Finite := by
       run_tac
         to_finite_tac) :
     s.ncard ≤ t.ncard :=
   @Finite.card_le_of_embedding _ _ (finite_coe_iff.mpr ht) (Set.embeddingOfSubset _ _ hst)
-#align set.ncard_le_of_subset Set.ncard_le_of_subset
+#align set.ncard_le_of_subset Set.ncard_le_ncard
 -/
 
 #print Set.ncard_mono /-
-theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ => ncard_le_of_subset
+theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ => ncard_le_ncard
 #align set.ncard_mono Set.ncard_mono
 -/
 
@@ -465,7 +465,7 @@ theorem ncard_inter_le_ncard_left (s t : Set α)
       run_tac
         to_finite_tac) :
     (s ∩ t).ncard ≤ s.ncard :=
-  ncard_le_of_subset (inter_subset_left _ _) hs
+  ncard_le_ncard (inter_subset_left _ _) hs
 #align set.ncard_inter_le_ncard_left Set.ncard_inter_le_ncard_left
 -/
 
@@ -476,7 +476,7 @@ theorem ncard_inter_le_ncard_right (s t : Set α)
       run_tac
         to_finite_tac) :
     (s ∩ t).ncard ≤ t.ncard :=
-  ncard_le_of_subset (inter_subset_right _ _) ht
+  ncard_le_ncard (inter_subset_right _ _) ht
 #align set.ncard_inter_le_ncard_right Set.ncard_inter_le_ncard_right
 -/
 
Diff
@@ -3,8 +3,8 @@ Copyright (c) 2023 Peter Nelson. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Peter Nelson
 -/
-import Mathbin.Data.Finite.Card
-import Mathbin.Algebra.BigOperators.Finprod
+import Data.Finite.Card
+import Algebra.BigOperators.Finprod
 
 #align_import data.set.ncard from "leanprover-community/mathlib"@"c20927220ef87bb4962ba08bf6da2ce3cf50a6dd"
 
@@ -59,7 +59,7 @@ noncomputable def ncard (s : Set α) :=
 #align set.ncard Set.ncard
 -/
 
-/- ./././Mathport/Syntax/Translate/Expr.lean:336:4: warning: unsupported (TODO): `[tacs] -/
+/- ./././Mathport/Syntax/Translate/Expr.lean:337:4: warning: unsupported (TODO): `[tacs] -/
 /-- A tactic, for use in `auto_param`s, that finds a `t.finite` term for a set `t`
   whose finiteness can be deduced from typeclasses (eg. in a `finite` type). -/
 unsafe def to_finite_tac : tactic Unit :=
@@ -1022,7 +1022,7 @@ theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} :=
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
-/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (a «expr ∉ » s) -/
+/- ./././Mathport/Syntax/Translate/Basic.lean:641:2: warning: expanding binder collection (a «expr ∉ » s) -/
 #print Set.exists_eq_insert_iff_ncard /-
 theorem exists_eq_insert_iff_ncard
     (hs : s.Finite := by
Diff
@@ -982,15 +982,15 @@ theorem Infinite.exists_subset_ncard_eq {s : Set α} (hs : s.Infinite) (k : ℕ)
 #align set.infinite.exists_subset_ncard_eq Set.Infinite.exists_subset_ncard_eq
 -/
 
-#print Set.Infinite.exists_supset_ncard_eq /-
-theorem Infinite.exists_supset_ncard_eq {s t : Set α} (ht : t.Infinite) (hst : s ⊆ t)
+#print Set.Infinite.exists_superset_ncard_eq /-
+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 _ _)), _⟩
   rwa [ncard_union_eq (disjoint_of_subset_right hs₁ disjoint_sdiff_right) hs hs₁fin, hs₁card,
     add_tsub_cancel_of_le]
-#align set.infinite.exists_supset_ncard_eq Set.Infinite.exists_supset_ncard_eq
+#align set.infinite.exists_supset_ncard_eq Set.Infinite.exists_superset_ncard_eq
 -/
 
 #print Set.exists_subset_or_subset_of_two_mul_lt_ncard /-
Diff
@@ -757,8 +757,8 @@ theorem ncard_union_eq (h : Disjoint s t)
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
-#print Set.ncard_diff_add_ncard_eq_ncard /-
-theorem ncard_diff_add_ncard_eq_ncard (h : s ⊆ t)
+#print Set.ncard_diff_add_ncard_of_subset /-
+theorem ncard_diff_add_ncard_of_subset (h : s ⊆ t)
     (ht : t.Finite := by
       run_tac
         to_finite_tac) :
@@ -768,7 +768,7 @@ theorem ncard_diff_add_ncard_eq_ncard (h : s ⊆ t)
     ncard_eq_to_finset_card _ (ht.diff s), finite.to_finset_diff]
   refine' Finset.card_sdiff_add_card_eq_card _
   rwa [finite.to_finset_subset_to_finset]
-#align set.ncard_diff_add_ncard_eq_ncard Set.ncard_diff_add_ncard_eq_ncard
+#align set.ncard_diff_add_ncard_eq_ncard Set.ncard_diff_add_ncard_of_subset
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
Diff
@@ -2,15 +2,12 @@
 Copyright (c) 2023 Peter Nelson. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Peter Nelson
-
-! This file was ported from Lean 3 source module data.set.ncard
-! leanprover-community/mathlib commit c20927220ef87bb4962ba08bf6da2ce3cf50a6dd
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathbin.Data.Finite.Card
 import Mathbin.Algebra.BigOperators.Finprod
 
+#align_import data.set.ncard from "leanprover-community/mathlib"@"c20927220ef87bb4962ba08bf6da2ce3cf50a6dd"
+
 /-!
 # Noncomputable Set Cardinality
 
@@ -1025,7 +1022,7 @@ theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} :=
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
-/- ./././Mathport/Syntax/Translate/Basic.lean:638:2: warning: expanding binder collection (a «expr ∉ » s) -/
+/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (a «expr ∉ » s) -/
 #print Set.exists_eq_insert_iff_ncard /-
 theorem exists_eq_insert_iff_ncard
     (hs : s.Finite := by
Diff
@@ -164,16 +164,16 @@ theorem ncard_ne_zero_of_mem (h : a ∈ s)
 #align set.ncard_ne_zero_of_mem Set.ncard_ne_zero_of_mem
 -/
 
-#print Set.Finite_of_ncard_ne_zero /-
-theorem Finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite :=
+#print Set.finite_of_ncard_ne_zero /-
+theorem finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite :=
   s.finite_or_infinite.elim id fun h => (hs h.ncard).elim
-#align set.finite_of_ncard_ne_zero Set.Finite_of_ncard_ne_zero
+#align set.finite_of_ncard_ne_zero Set.finite_of_ncard_ne_zero
 -/
 
-#print Set.Finite_of_ncard_pos /-
-theorem Finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite :=
-  Finite_of_ncard_ne_zero hs.Ne.symm
-#align set.finite_of_ncard_pos Set.Finite_of_ncard_pos
+#print Set.finite_of_ncard_pos /-
+theorem finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite :=
+  finite_of_ncard_ne_zero hs.Ne.symm
+#align set.finite_of_ncard_pos Set.finite_of_ncard_pos
 -/
 
 #print Set.nonempty_of_ncard_ne_zero /-
@@ -406,17 +406,17 @@ theorem ncard_image_iff
 #align set.ncard_image_iff Set.ncard_image_iff
 -/
 
-#print Set.ncard_image_ofInjective /-
-theorem ncard_image_ofInjective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard :=
+#print Set.ncard_image_of_injective /-
+theorem ncard_image_of_injective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard :=
   ncard_image_of_injOn fun x _ y _ h => H h
-#align set.ncard_image_of_injective Set.ncard_image_ofInjective
+#align set.ncard_image_of_injective Set.ncard_image_of_injective
 -/
 
-#print Set.ncard_preimage_ofInjective_subset_range /-
-theorem ncard_preimage_ofInjective_subset_range {s : Set β} (H : f.Injective)
+#print Set.ncard_preimage_of_injective_subset_range /-
+theorem ncard_preimage_of_injective_subset_range {s : Set β} (H : f.Injective)
     (hs : s ⊆ Set.range f) : (f ⁻¹' s).ncard = s.ncard := by
   rw [← ncard_image_of_injective _ H, image_preimage_eq_iff.mpr hs]
-#align set.ncard_preimage_of_injective_subset_range Set.ncard_preimage_ofInjective_subset_range
+#align set.ncard_preimage_of_injective_subset_range Set.ncard_preimage_of_injective_subset_range
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
@@ -437,7 +437,7 @@ theorem fiber_ncard_ne_zero_iff_mem_image {y : β}
 #print Set.ncard_map /-
 @[simp]
 theorem ncard_map (f : α ↪ β) : (f '' s).ncard = s.ncard :=
-  ncard_image_ofInjective _ f.Injective
+  ncard_image_of_injective _ f.Injective
 #align set.ncard_map Set.ncard_map
 -/
 
@@ -554,8 +554,8 @@ theorem ncard_strictMono [Finite α] : @StrictMono (Set α) _ _ _ ncard := fun _
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
-#print Set.ncard_eq_ofBijective /-
-theorem ncard_eq_ofBijective {n : ℕ} (f : ∀ i, i < n → α)
+#print Set.ncard_eq_of_bijective /-
+theorem ncard_eq_of_bijective {n : ℕ} (f : ∀ i, i < n → α)
     (hf : ∀ a ∈ s, ∃ i, ∃ h : i < n, f i h = a) (hf' : ∀ (i) (h : i < n), f i h ∈ s)
     (f_inj : ∀ (i j) (hi : i < n) (hj : j < n), f i hi = f j hj → i = j)
     (hs : s.Finite := by
@@ -565,7 +565,7 @@ theorem ncard_eq_ofBijective {n : ℕ} (f : ∀ i, i < n → α)
   rw [ncard_eq_to_finset_card _ hs]
   apply Finset.card_eq_of_bijective
   all_goals simpa
-#align set.ncard_eq_of_bijective Set.ncard_eq_ofBijective
+#align set.ncard_eq_of_bijective Set.ncard_eq_of_bijective
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
@@ -951,24 +951,24 @@ theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂
 #align set.exists_intermediate_set Set.exists_intermediate_Set
 -/
 
-#print Set.exists_intermediate_Set' /-
-theorem exists_intermediate_Set' {m : ℕ} (hs : s.ncard ≤ m) (ht : m ≤ t.ncard) (h : s ⊆ t) :
+#print Set.exists_intermediate_set' /-
+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 
   exact ⟨r, hsr, hrt, hc⟩
-#align set.exists_intermediate_set' Set.exists_intermediate_Set'
+#align set.exists_intermediate_set' Set.exists_intermediate_set'
 -/
 
-#print Set.exists_smaller_Set /-
+#print Set.exists_smaller_set /-
 /-- We can shrink `s` to any smaller size. -/
-theorem exists_smaller_Set (s : Set α) (i : ℕ) (h₁ : i ≤ s.ncard) :
+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 simpa using ht.2.2⟩
-#align set.exists_smaller_set Set.exists_smaller_Set
+#align set.exists_smaller_set Set.exists_smaller_set
 -/
 
 /- warning: set.infinite.exists_subset_ncard_eq clashes with set.Infinite.exists_subset_ncard_eq -> Set.Infinite.exists_subset_ncard_eq
Diff
@@ -97,8 +97,10 @@ theorem ncard_le_of_subset (hst : s ⊆ t)
 #align set.ncard_le_of_subset Set.ncard_le_of_subset
 -/
 
+#print Set.ncard_mono /-
 theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ => ncard_le_of_subset
 #align set.ncard_mono Set.ncard_mono
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 #print Set.ncard_eq_zero /-
@@ -186,6 +188,7 @@ theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by simp [ncard_eq
 #align set.ncard_singleton Set.ncard_singleton
 -/
 
+#print Set.ncard_singleton_inter /-
 theorem ncard_singleton_inter : ({a} ∩ s).ncard ≤ 1 := by
   classical
   rw [← inter_self {a}, inter_assoc, ncard_eq_to_finset_card, finite.to_finset_inter,
@@ -193,6 +196,7 @@ theorem ncard_singleton_inter : ({a} ∩ s).ncard ≤ 1 := by
   · apply Finset.card_singleton_inter
   all_goals apply to_finite
 #align set.ncard_singleton_inter Set.ncard_singleton_inter
+-/
 
 section InsertErase
 
@@ -265,6 +269,7 @@ theorem ncard_pair (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_diff_singleton_add_one /-
 theorem ncard_diff_singleton_add_one (h : a ∈ s)
     (hs : s.Finite := by
       run_tac
@@ -276,8 +281,10 @@ theorem ncard_diff_singleton_add_one (h : a ∈ s)
   congr
   simpa
 #align set.ncard_diff_singleton_add_one Set.ncard_diff_singleton_add_one
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_diff_singleton_of_mem /-
 theorem ncard_diff_singleton_of_mem (h : a ∈ s)
     (hs : s.Finite := by
       run_tac
@@ -285,15 +292,19 @@ theorem ncard_diff_singleton_of_mem (h : a ∈ s)
     (s \ {a}).ncard = s.ncard - 1 :=
   eq_tsub_of_add_eq (ncard_diff_singleton_add_one h hs)
 #align set.ncard_diff_singleton_of_mem Set.ncard_diff_singleton_of_mem
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_diff_singleton_lt_of_mem /-
 theorem ncard_diff_singleton_lt_of_mem (h : a ∈ s)
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
     (s \ {a}).ncard < s.ncard := by rw [← ncard_diff_singleton_add_one h hs]; apply lt_add_one
 #align set.ncard_diff_singleton_lt_of_mem Set.ncard_diff_singleton_lt_of_mem
+-/
 
+#print Set.ncard_diff_singleton_le /-
 theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard :=
   by
   obtain hs | hs := s.finite_or_infinite
@@ -301,7 +312,9 @@ theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.nc
   convert zero_le _
   exact (hs.diff (by simp : Set.Finite {a})).ncard
 #align set.ncard_diff_singleton_le Set.ncard_diff_singleton_le
+-/
 
+#print Set.pred_ncard_le_ncard_diff_singleton /-
 theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard :=
   by
   cases' s.finite_or_infinite with hs hs
@@ -312,7 +325,9 @@ theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 
   convert Nat.zero_le _
   rw [hs.ncard]
 #align set.pred_ncard_le_ncard_diff_singleton Set.pred_ncard_le_ncard_diff_singleton
+-/
 
+#print Set.ncard_exchange /-
 theorem ncard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncard = s.ncard :=
   by
   cases' s.finite_or_infinite with h h
@@ -321,15 +336,19 @@ theorem ncard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncar
     simpa only [mem_diff, not_and] using ha
   rw [((h.diff (Set.toFinite {b})).mono (subset_insert _ _)).ncard, h.ncard]
 #align set.ncard_exchange Set.ncard_exchange
+-/
 
+#print Set.ncard_exchange' /-
 theorem ncard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).ncard = s.ncard := by
   rw [← ncard_exchange ha hb, ← singleton_union, ← singleton_union, union_diff_distrib,
     @diff_singleton_eq_self _ b {a} fun h => ha (by rwa [← mem_singleton_iff.mp h])]
 #align set.ncard_exchange' Set.ncard_exchange'
+-/
 
 end InsertErase
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_image_le /-
 theorem ncard_image_le
     (hs : s.Finite := by
       run_tac
@@ -344,7 +363,9 @@ theorem ncard_image_le
   · infer_instance
   rw [← Finset.coe_inj, finite.coe_to_finset, coe_to_finset]
 #align set.ncard_image_le Set.ncard_image_le
+-/
 
+#print Set.ncard_image_of_injOn /-
 theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard :=
   by
   cases s.finite_or_infinite
@@ -353,6 +374,7 @@ theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard :=
     convert card_image_of_inj_on H <;> simp [ncard_def]
   rw [h.ncard, ((infinite_image_iff H).mpr h).ncard]
 #align set.ncard_image_of_inj_on Set.ncard_image_of_injOn
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 #print Set.injOn_of_ncard_image_eq /-
@@ -374,6 +396,7 @@ theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard)
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_image_iff /-
 theorem ncard_image_iff
     (hs : s.Finite := by
       run_tac
@@ -381,10 +404,13 @@ theorem ncard_image_iff
     (f '' s).ncard = s.ncard ↔ Set.InjOn f s :=
   ⟨fun h => injOn_of_ncard_image_eq h hs, ncard_image_of_injOn⟩
 #align set.ncard_image_iff Set.ncard_image_iff
+-/
 
+#print Set.ncard_image_ofInjective /-
 theorem ncard_image_ofInjective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard :=
   ncard_image_of_injOn fun x _ y _ h => H h
 #align set.ncard_image_of_injective Set.ncard_image_ofInjective
+-/
 
 #print Set.ncard_preimage_ofInjective_subset_range /-
 theorem ncard_preimage_ofInjective_subset_range {s : Set β} (H : f.Injective)
@@ -394,6 +420,7 @@ theorem ncard_preimage_ofInjective_subset_range {s : Set β} (H : f.Injective)
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.fiber_ncard_ne_zero_iff_mem_image /-
 theorem fiber_ncard_ne_zero_iff_mem_image {y : β}
     (hs : s.Finite := by
       run_tac
@@ -405,12 +432,16 @@ theorem fiber_ncard_ne_zero_iff_mem_image {y : β}
   exact
     @ncard_ne_zero_of_mem _ ({x ∈ s | f x = f z}) z (mem_sep hz rfl) (hs.subset (sep_subset _ _))
 #align set.fiber_ncard_ne_zero_iff_mem_image Set.fiber_ncard_ne_zero_iff_mem_image
+-/
 
+#print Set.ncard_map /-
 @[simp]
 theorem ncard_map (f : α ↪ β) : (f '' s).ncard = s.ncard :=
   ncard_image_ofInjective _ f.Injective
 #align set.ncard_map Set.ncard_map
+-/
 
+#print Set.ncard_subtype /-
 @[simp]
 theorem ncard_subtype (P : α → Prop) (s : Set α) :
     {x : Subtype P | (x : α) ∈ s}.ncard = (s ∩ setOf P).ncard :=
@@ -418,6 +449,7 @@ theorem ncard_subtype (P : α → Prop) (s : Set α) :
   convert (ncard_image_of_injective _ (@Subtype.coe_injective _ P)).symm
   ext; rw [inter_comm]; simp
 #align set.ncard_subtype Set.ncard_subtype
+-/
 
 #print Set.Nat.card_coe_set_eq /-
 @[simp]
@@ -430,6 +462,7 @@ theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard :=
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_inter_le_ncard_left /-
 theorem ncard_inter_le_ncard_left (s t : Set α)
     (hs : s.Finite := by
       run_tac
@@ -437,8 +470,10 @@ theorem ncard_inter_le_ncard_left (s t : Set α)
     (s ∩ t).ncard ≤ s.ncard :=
   ncard_le_of_subset (inter_subset_left _ _) hs
 #align set.ncard_inter_le_ncard_left Set.ncard_inter_le_ncard_left
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_inter_le_ncard_right /-
 theorem ncard_inter_le_ncard_right (s t : Set α)
     (ht : t.Finite := by
       run_tac
@@ -446,6 +481,7 @@ theorem ncard_inter_le_ncard_right (s t : Set α)
     (s ∩ t).ncard ≤ t.ncard :=
   ncard_le_of_subset (inter_subset_right _ _) ht
 #align set.ncard_inter_le_ncard_right Set.ncard_inter_le_ncard_right
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 #print Set.eq_of_subset_of_ncard_le /-
@@ -498,6 +534,7 @@ theorem sep_of_ncard_eq {P : α → Prop} (h : {x ∈ s | P x}.ncard = s.ncard)
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_lt_ncard /-
 theorem ncard_lt_ncard (h : s ⊂ t)
     (ht : t.Finite := by
       run_tac
@@ -508,10 +545,13 @@ theorem ncard_lt_ncard (h : s ⊂ t)
   refine' Finset.card_lt_card _
   rwa [finite.to_finset_ssubset_to_finset]
 #align set.ncard_lt_ncard Set.ncard_lt_ncard
+-/
 
+#print Set.ncard_strictMono /-
 theorem ncard_strictMono [Finite α] : @StrictMono (Set α) _ _ _ ncard := fun _ _ h =>
   ncard_lt_ncard h
 #align set.ncard_strict_mono Set.ncard_strictMono
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 #print Set.ncard_eq_ofBijective /-
@@ -573,6 +613,7 @@ theorem ncard_le_ncard_of_injOn {t : Set β} (f : α → β) (hf : ∀ a ∈ s,
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.exists_ne_map_eq_of_ncard_lt_of_maps_to /-
 theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.ncard) {f : α → β}
     (hf : ∀ a ∈ s, f a ∈ t)
     (ht : t.Finite := by
@@ -583,6 +624,7 @@ theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.n
   simp only [Ne.def, exists_prop, not_exists, not_and, not_imp_not] at h' 
   exact (ncard_le_ncard_of_inj_on f hf h' ht).not_lt hc
 #align set.exists_ne_map_eq_of_ncard_lt_of_maps_to Set.exists_ne_map_eq_of_ncard_lt_of_maps_to
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 #print Set.le_ncard_of_inj_on_range /-
@@ -651,6 +693,7 @@ section Lattice
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_union_add_ncard_inter /-
 theorem ncard_union_add_ncard_inter (s t : Set α)
     (hs : s.Finite := by
       run_tac
@@ -666,9 +709,11 @@ theorem ncard_union_add_ncard_inter (s t : Set α)
     ncard_eq_to_finset_card _ hi, finite.to_finset_union, finite.to_finset_inter]
   · exact Finset.card_union_add_card_inter _ _
 #align set.ncard_union_add_ncard_inter Set.ncard_union_add_ncard_inter
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_inter_add_ncard_union /-
 theorem ncard_inter_add_ncard_union (s t : Set α)
     (hs : s.Finite := by
       run_tac
@@ -679,7 +724,9 @@ theorem ncard_inter_add_ncard_union (s t : Set α)
     (s ∩ t).ncard + (s ∪ t).ncard = s.ncard + t.ncard := by
   rw [add_comm, ncard_union_add_ncard_inter _ _ hs ht]
 #align set.ncard_inter_add_ncard_union Set.ncard_inter_add_ncard_union
+-/
 
+#print Set.ncard_union_le /-
 theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by
   classical
   cases (s ∪ t).finite_or_infinite
@@ -691,9 +738,11 @@ theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard :=
   convert Nat.zero_le _
   rw [h.ncard]
 #align set.ncard_union_le Set.ncard_union_le
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_union_eq /-
 theorem ncard_union_eq (h : Disjoint s t)
     (hs : s.Finite := by
       run_tac
@@ -708,8 +757,10 @@ theorem ncard_union_eq (h : Disjoint s t)
   refine' Finset.card_union_eq _
   rwa [finite.disjoint_to_finset]
 #align set.ncard_union_eq Set.ncard_union_eq
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_diff_add_ncard_eq_ncard /-
 theorem ncard_diff_add_ncard_eq_ncard (h : s ⊆ t)
     (ht : t.Finite := by
       run_tac
@@ -721,8 +772,10 @@ theorem ncard_diff_add_ncard_eq_ncard (h : s ⊆ t)
   refine' Finset.card_sdiff_add_card_eq_card _
   rwa [finite.to_finset_subset_to_finset]
 #align set.ncard_diff_add_ncard_eq_ncard Set.ncard_diff_add_ncard_eq_ncard
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_diff /-
 theorem ncard_diff (h : s ⊆ t)
     (ht : t.Finite := by
       run_tac
@@ -730,8 +783,10 @@ theorem ncard_diff (h : s ⊆ t)
     (t \ s).ncard = t.ncard - s.ncard := by
   rw [← ncard_diff_add_ncard_eq_ncard h ht, add_tsub_cancel_right]
 #align set.ncard_diff Set.ncard_diff
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_le_ncard_diff_add_ncard /-
 theorem ncard_le_ncard_diff_add_ncard (s t : Set α)
     (ht : t.Finite := by
       run_tac
@@ -745,8 +800,10 @@ theorem ncard_le_ncard_diff_add_ncard (s t : Set α)
   convert Nat.zero_le _
   rw [h.ncard]
 #align set.ncard_le_ncard_diff_add_ncard Set.ncard_le_ncard_diff_add_ncard
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.le_ncard_diff /-
 theorem le_ncard_diff (s t : Set α)
     (hs : s.Finite := by
       run_tac
@@ -757,9 +814,11 @@ theorem le_ncard_diff (s t : Set α)
   rw [add_comm]
   apply ncard_le_ncard_diff_add_ncard _ _ hs
 #align set.le_ncard_diff Set.le_ncard_diff
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_diff_add_ncard /-
 theorem ncard_diff_add_ncard (s t : Set α)
     (hs : s.Finite := by
       run_tac
@@ -770,8 +829,10 @@ theorem ncard_diff_add_ncard (s t : Set α)
     (s \ t).ncard + t.ncard = (s ∪ t).ncard := by
   rw [← union_diff_right, ncard_diff_add_ncard_eq_ncard (subset_union_right s t) (hs.union ht)]
 #align set.ncard_diff_add_ncard Set.ncard_diff_add_ncard
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.diff_nonempty_of_ncard_lt_ncard /-
 theorem diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard)
     (hs : s.Finite := by
       run_tac
@@ -781,6 +842,7 @@ theorem diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard)
   rw [Set.nonempty_iff_ne_empty, Ne.def, diff_eq_empty]
   exact fun h' => h.not_le (ncard_le_of_subset h' hs)
 #align set.diff_nonempty_of_ncard_lt_ncard Set.diff_nonempty_of_ncard_lt_ncard
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 #print Set.exists_mem_not_mem_of_ncard_lt_ncard /-
@@ -794,6 +856,7 @@ theorem exists_mem_not_mem_of_ncard_lt_ncard (h : s.ncard < t.ncard)
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_inter_add_ncard_diff_eq_ncard /-
 @[simp]
 theorem ncard_inter_add_ncard_diff_eq_ncard (s t : Set α)
     (hs : s.Finite := by
@@ -802,9 +865,11 @@ theorem ncard_inter_add_ncard_diff_eq_ncard (s t : Set α)
     (s ∩ t).ncard + (s \ t).ncard = s.ncard := by
   rw [← ncard_diff_add_ncard_eq_ncard (diff_subset s t) hs, sdiff_sdiff_right_self, inf_eq_inter]
 #align set.ncard_inter_add_ncard_diff_eq_ncard Set.ncard_inter_add_ncard_diff_eq_ncard
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff /-
 theorem ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff
     (hs : s.Finite := by
       run_tac
@@ -816,9 +881,11 @@ theorem ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff
   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]
 #align set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff Set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_le_ncard_iff_ncard_diff_le_ncard_diff /-
 theorem ncard_le_ncard_iff_ncard_diff_le_ncard_diff
     (hs : s.Finite := by
       run_tac
@@ -830,9 +897,11 @@ theorem ncard_le_ncard_iff_ncard_diff_le_ncard_diff
   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]
 #align set.ncard_le_ncard_iff_ncard_diff_le_ncard_diff Set.ncard_le_ncard_iff_ncard_diff_le_ncard_diff
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff /-
 theorem ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
     (hs : s.Finite := by
       run_tac
@@ -844,9 +913,11 @@ theorem ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
   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]
 #align set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff Set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_add_ncard_compl /-
 theorem ncard_add_ncard_compl (s : Set α)
     (hs : s.Finite := by
       run_tac
@@ -857,6 +928,7 @@ theorem ncard_add_ncard_compl (s : Set α)
     s.ncard + sᶜ.ncard = Nat.card α := by
   rw [← ncard_univ, ← ncard_union_eq (@disjoint_compl_right _ _ s) hs hsc, union_compl_self]
 #align set.ncard_add_ncard_compl Set.ncard_add_ncard_compl
+-/
 
 end Lattice
 
@@ -924,6 +996,7 @@ theorem Infinite.exists_supset_ncard_eq {s t : Set α} (ht : t.Infinite) (hst :
 #align set.infinite.exists_supset_ncard_eq Set.Infinite.exists_supset_ncard_eq
 -/
 
+#print Set.exists_subset_or_subset_of_two_mul_lt_ncard /-
 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
@@ -935,6 +1008,7 @@ theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s
   obtain ⟨r', hnr', hr'⟩ := Finset.exists_subset_or_subset_of_two_mul_lt_card hst
   exact ⟨r', by simpa, by simpa using hr'⟩
 #align set.exists_subset_or_subset_of_two_mul_lt_ncard Set.exists_subset_or_subset_of_two_mul_lt_ncard
+-/
 
 /-! ### Explicit description of a set from its cardinality -/
 
@@ -1038,6 +1112,7 @@ theorem ncard_le_one_of_subsingleton [Subsingleton α] (s : Set α) : s.ncard 
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.one_lt_ncard /-
 theorem one_lt_ncard
     (hs : s.Finite := by
       run_tac
@@ -1045,6 +1120,7 @@ theorem one_lt_ncard
     1 < s.ncard ↔ ∃ a ∈ s, ∃ b ∈ s, a ≠ b := by
   simp_rw [ncard_eq_to_finset_card _ hs, Finset.one_lt_card, finite.mem_to_finset]
 #align set.one_lt_ncard Set.one_lt_ncard
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 #print Set.one_lt_ncard_iff /-
@@ -1069,6 +1145,7 @@ theorem two_lt_ncard_iff
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.two_lt_ncard /-
 theorem two_lt_ncard
     (hs : s.Finite := by
       run_tac
@@ -1076,6 +1153,7 @@ theorem two_lt_ncard
     2 < s.ncard ↔ ∃ a ∈ s, ∃ b ∈ s, ∃ c ∈ s, a ≠ b ∧ a ≠ c ∧ b ≠ c := by
   simp only [two_lt_ncard_iff hs, exists_and_left, exists_prop]
 #align set.two_lt_card Set.two_lt_ncard
+-/
 
 #print Set.exists_ne_of_one_lt_ncard /-
 theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s ∧ b ≠ a :=
Diff
@@ -62,7 +62,7 @@ noncomputable def ncard (s : Set α) :=
 #align set.ncard Set.ncard
 -/
 
-/- ./././Mathport/Syntax/Translate/Expr.lean:330:4: warning: unsupported (TODO): `[tacs] -/
+/- ./././Mathport/Syntax/Translate/Expr.lean:336:4: warning: unsupported (TODO): `[tacs] -/
 /-- A tactic, for use in `auto_param`s, that finds a `t.finite` term for a set `t`
   whose finiteness can be deduced from typeclasses (eg. in a `finite` type). -/
 unsafe def to_finite_tac : tactic Unit :=
Diff
@@ -951,7 +951,7 @@ theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} :=
 -/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
-/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (a «expr ∉ » s) -/
+/- ./././Mathport/Syntax/Translate/Basic.lean:638:2: warning: expanding binder collection (a «expr ∉ » s) -/
 #print Set.exists_eq_insert_iff_ncard /-
 theorem exists_eq_insert_iff_ncard
     (hs : s.Finite := by
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Peter Nelson
 
 ! This file was ported from Lean 3 source module data.set.ncard
-! leanprover-community/mathlib commit 74c2af38a828107941029b03839882c5c6f87a04
+! leanprover-community/mathlib commit c20927220ef87bb4962ba08bf6da2ce3cf50a6dd
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -14,6 +14,9 @@ import Mathbin.Algebra.BigOperators.Finprod
 /-!
 # Noncomputable Set Cardinality
 
+> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
+> Any changes to this file require a corresponding PR to mathlib4.
+
 We define the cardinality `set.ncard s` of a set `s` as a natural number. This function is
 noncomputable (being defined in terms of `nat.card`) and takes the value `0` if `s` is infinite.
 
Diff
@@ -52,10 +52,12 @@ variable {α β : Type _} {s t : Set α} {a b x y : α} {f : α → β}
 
 namespace Set
 
+#print Set.ncard /-
 /-- The cardinality of `s : set α`. Has the junk value `0` if `s` is infinite -/
 noncomputable def ncard (s : Set α) :=
   Nat.card s
 #align set.ncard Set.ncard
+-/
 
 /- ./././Mathport/Syntax/Translate/Expr.lean:330:4: warning: unsupported (TODO): `[tacs] -/
 /-- A tactic, for use in `auto_param`s, that finds a `t.finite` term for a set `t`
@@ -64,11 +66,14 @@ unsafe def to_finite_tac : tactic Unit :=
   sorry
 #align set.to_finite_tac set.to_finite_tac
 
+#print Set.ncard_def /-
 theorem ncard_def (s : Set α) : s.ncard = Nat.card s :=
   rfl
 #align set.ncard_def Set.ncard_def
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_eq_toFinset_card /-
 theorem ncard_eq_toFinset_card (s : Set α)
     (hs : s.Finite := by
       run_tac
@@ -76,8 +81,10 @@ theorem ncard_eq_toFinset_card (s : Set α)
     s.ncard = hs.toFinset.card := by
   rw [ncard_def, @Nat.card_eq_fintype_card _ hs.fintype, @finite.card_to_finset _ _ hs.fintype hs]
 #align set.ncard_eq_to_finset_card Set.ncard_eq_toFinset_card
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_le_of_subset /-
 theorem ncard_le_of_subset (hst : s ⊆ t)
     (ht : t.Finite := by
       run_tac
@@ -85,11 +92,13 @@ theorem ncard_le_of_subset (hst : s ⊆ t)
     s.ncard ≤ t.ncard :=
   @Finite.card_le_of_embedding _ _ (finite_coe_iff.mpr ht) (Set.embeddingOfSubset _ _ hst)
 #align set.ncard_le_of_subset Set.ncard_le_of_subset
+-/
 
 theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ => ncard_le_of_subset
 #align set.ncard_mono Set.ncard_mono
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_eq_zero /-
 @[simp]
 theorem ncard_eq_zero
     (hs : s.Finite := by
@@ -97,16 +106,22 @@ theorem ncard_eq_zero
         to_finite_tac) :
     s.ncard = 0 ↔ s = ∅ := by simp [ncard_def, @Finite.card_eq_zero_iff _ hs.to_subtype]
 #align set.ncard_eq_zero Set.ncard_eq_zero
+-/
 
+#print Set.ncard_coe_Finset /-
 @[simp]
-theorem ncard_coe_finset (s : Finset α) : (s : Set α).ncard = s.card := by
+theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by
   rw [ncard_eq_to_finset_card, Finset.finite_toSet_toFinset]
-#align set.ncard_coe_finset Set.ncard_coe_finset
+#align set.ncard_coe_finset Set.ncard_coe_Finset
+-/
 
+#print Set.Infinite.ncard /-
 theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 :=
   @Nat.card_eq_zero_of_infinite _ hs.to_subtype
 #align set.infinite.ncard Set.Infinite.ncard
+-/
 
+#print Set.ncard_univ /-
 theorem ncard_univ (α : Type _) : (univ : Set α).ncard = Nat.card α :=
   by
   cases' finite_or_infinite α with h h
@@ -114,12 +129,16 @@ theorem ncard_univ (α : Type _) : (univ : Set α).ncard = Nat.card α :=
     rw [ncard_eq_to_finset_card, finite.to_finset_univ, Finset.card_univ, Nat.card_eq_fintype_card]
   rw [(@infinite_univ _ h).ncard, @Nat.card_eq_zero_of_infinite _ h]
 #align set.ncard_univ Set.ncard_univ
+-/
 
+#print Set.ncard_empty /-
 @[simp]
 theorem ncard_empty (α : Type _) : (∅ : Set α).ncard = 0 := by simp only [ncard_eq_zero]
 #align set.ncard_empty Set.ncard_empty
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_pos /-
 theorem ncard_pos
     (hs : s.Finite := by
       run_tac
@@ -127,8 +146,10 @@ theorem ncard_pos
     0 < s.ncard ↔ s.Nonempty := by
   rw [pos_iff_ne_zero, Ne.def, ncard_eq_zero hs, nonempty_iff_ne_empty]
 #align set.ncard_pos Set.ncard_pos
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_ne_zero_of_mem /-
 theorem ncard_ne_zero_of_mem (h : a ∈ s)
     (hs : s.Finite := by
       run_tac
@@ -136,22 +157,31 @@ theorem ncard_ne_zero_of_mem (h : a ∈ s)
     s.ncard ≠ 0 :=
   ((ncard_pos hs).mpr ⟨a, h⟩).Ne.symm
 #align set.ncard_ne_zero_of_mem Set.ncard_ne_zero_of_mem
+-/
 
-theorem finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite :=
+#print Set.Finite_of_ncard_ne_zero /-
+theorem Finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite :=
   s.finite_or_infinite.elim id fun h => (hs h.ncard).elim
-#align set.finite_of_ncard_ne_zero Set.finite_of_ncard_ne_zero
+#align set.finite_of_ncard_ne_zero Set.Finite_of_ncard_ne_zero
+-/
 
-theorem finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite :=
-  finite_of_ncard_ne_zero hs.Ne.symm
-#align set.finite_of_ncard_pos Set.finite_of_ncard_pos
+#print Set.Finite_of_ncard_pos /-
+theorem Finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite :=
+  Finite_of_ncard_ne_zero hs.Ne.symm
+#align set.finite_of_ncard_pos Set.Finite_of_ncard_pos
+-/
 
+#print Set.nonempty_of_ncard_ne_zero /-
 theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by rw [nonempty_iff_ne_empty];
   rintro rfl; simpa using hs
 #align set.nonempty_of_ncard_ne_zero Set.nonempty_of_ncard_ne_zero
+-/
 
+#print Set.ncard_singleton /-
 @[simp]
 theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by simp [ncard_eq_to_finset_card]
 #align set.ncard_singleton Set.ncard_singleton
+-/
 
 theorem ncard_singleton_inter : ({a} ∩ s).ncard ≤ 1 := by
   classical
@@ -164,6 +194,7 @@ theorem ncard_singleton_inter : ({a} ∩ s).ncard ≤ 1 := by
 section InsertErase
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_insert_of_not_mem /-
 @[simp]
 theorem ncard_insert_of_not_mem (h : a ∉ s)
     (hs : s.Finite := by
@@ -176,10 +207,14 @@ theorem ncard_insert_of_not_mem (h : a ∉ s)
     Finset.card_insert_of_not_mem]
   rwa [finite.mem_to_finset]
 #align set.ncard_insert_of_not_mem Set.ncard_insert_of_not_mem
+-/
 
+#print Set.ncard_insert_of_mem /-
 theorem ncard_insert_of_mem (h : a ∈ s) : ncard (insert a s) = s.ncard := by rw [insert_eq_of_mem h]
 #align set.ncard_insert_of_mem Set.ncard_insert_of_mem
+-/
 
+#print Set.ncard_insert_le /-
 theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
   classical
   obtain hs | hs := s.finite_or_infinite
@@ -190,8 +225,10 @@ theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard +
   rw [(hs.mono (subset_insert a s)).ncard]
   exact Nat.zero_le _
 #align set.ncard_insert_le Set.ncard_insert_le
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_insert_eq_ite /-
 theorem ncard_insert_eq_ite [Decidable (a ∈ s)]
     (hs : s.Finite := by
       run_tac
@@ -202,7 +239,9 @@ theorem ncard_insert_eq_ite [Decidable (a ∈ s)]
   · rw [ncard_insert_of_mem h, if_pos h]
   · rw [ncard_insert_of_not_mem h hs, if_neg h]
 #align set.ncard_insert_eq_ite Set.ncard_insert_eq_ite
+-/
 
+#print Set.ncard_le_ncard_insert /-
 theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
   classical
   refine' s.finite_or_infinite.elim (fun h => _) fun h => by rw [h.ncard]; exact Nat.zero_le _
@@ -212,10 +251,15 @@ theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).n
   · simp only [le_add_iff_nonneg_right, zero_le']
   exact Classical.dec (a ∈ s)
 #align set.ncard_le_ncard_insert Set.ncard_le_ncard_insert
+-/
 
+/- warning: set.ncard_pair clashes with set.card_doubleton -> Set.ncard_pair
+Case conversion may be inaccurate. Consider using '#align set.ncard_pair Set.ncard_pairₓ'. -/
+#print Set.ncard_pair /-
 theorem ncard_pair (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by
   rw [ncard_insert_of_not_mem, ncard_singleton]; simpa
 #align set.ncard_pair Set.ncard_pair
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 theorem ncard_diff_singleton_add_one (h : a ∈ s)
@@ -308,6 +352,7 @@ theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard :=
 #align set.ncard_image_of_inj_on Set.ncard_image_of_injOn
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.injOn_of_ncard_image_eq /-
 theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard)
     (hs : s.Finite := by
       run_tac
@@ -323,6 +368,7 @@ theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard)
   ext
   simp
 #align set.inj_on_of_ncard_image_eq Set.injOn_of_ncard_image_eq
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 theorem ncard_image_iff
@@ -333,14 +379,16 @@ theorem ncard_image_iff
   ⟨fun h => injOn_of_ncard_image_eq h hs, ncard_image_of_injOn⟩
 #align set.ncard_image_iff Set.ncard_image_iff
 
-theorem ncard_image_of_injective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard :=
+theorem ncard_image_ofInjective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard :=
   ncard_image_of_injOn fun x _ y _ h => H h
-#align set.ncard_image_of_injective Set.ncard_image_of_injective
+#align set.ncard_image_of_injective Set.ncard_image_ofInjective
 
-theorem ncard_preimage_of_injective_subset_range {s : Set β} (H : f.Injective)
+#print Set.ncard_preimage_ofInjective_subset_range /-
+theorem ncard_preimage_ofInjective_subset_range {s : Set β} (H : f.Injective)
     (hs : s ⊆ Set.range f) : (f ⁻¹' s).ncard = s.ncard := by
   rw [← ncard_image_of_injective _ H, image_preimage_eq_iff.mpr hs]
-#align set.ncard_preimage_of_injective_subset_range Set.ncard_preimage_of_injective_subset_range
+#align set.ncard_preimage_of_injective_subset_range Set.ncard_preimage_ofInjective_subset_range
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 theorem fiber_ncard_ne_zero_iff_mem_image {y : β}
@@ -357,7 +405,7 @@ theorem fiber_ncard_ne_zero_iff_mem_image {y : β}
 
 @[simp]
 theorem ncard_map (f : α ↪ β) : (f '' s).ncard = s.ncard :=
-  ncard_image_of_injective _ f.Injective
+  ncard_image_ofInjective _ f.Injective
 #align set.ncard_map Set.ncard_map
 
 @[simp]
@@ -368,6 +416,7 @@ theorem ncard_subtype (P : α → Prop) (s : Set α) :
   ext; rw [inter_comm]; simp
 #align set.ncard_subtype Set.ncard_subtype
 
+#print Set.Nat.card_coe_set_eq /-
 @[simp]
 theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard :=
   by
@@ -375,6 +424,7 @@ theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard :=
   · rw [ncard_univ]; rfl
   simp
 #align set.nat.card_coe_set_eq Set.Nat.card_coe_set_eq
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 theorem ncard_inter_le_ncard_left (s t : Set α)
@@ -395,6 +445,7 @@ theorem ncard_inter_le_ncard_right (s t : Set α)
 #align set.ncard_inter_le_ncard_right Set.ncard_inter_le_ncard_right
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.eq_of_subset_of_ncard_le /-
 theorem eq_of_subset_of_ncard_le (h : s ⊆ t) (h' : t.ncard ≤ s.ncard)
     (ht : t.Finite := by
       run_tac
@@ -408,8 +459,10 @@ theorem eq_of_subset_of_ncard_le (h : s ⊆ t) (h' : t.ncard ≤ s.ncard)
   rw [ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ (ht.subset h)] at h' 
   convert h'
 #align set.eq_of_subset_of_ncard_le Set.eq_of_subset_of_ncard_le
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.subset_iff_eq_of_ncard_le /-
 theorem subset_iff_eq_of_ncard_le (h : t.ncard ≤ s.ncard)
     (ht : t.Finite := by
       run_tac
@@ -417,8 +470,10 @@ theorem subset_iff_eq_of_ncard_le (h : t.ncard ≤ s.ncard)
     s ⊆ t ↔ s = t :=
   ⟨fun hst => eq_of_subset_of_ncard_le hst h ht, Eq.subset'⟩
 #align set.subset_iff_eq_of_ncard_le Set.subset_iff_eq_of_ncard_le
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.map_eq_of_subset /-
 theorem map_eq_of_subset {f : α ↪ α} (h : f '' s ⊆ s)
     (hs : s.Finite := by
       run_tac
@@ -426,8 +481,10 @@ theorem map_eq_of_subset {f : α ↪ α} (h : f '' s ⊆ s)
     f '' s = s :=
   eq_of_subset_of_ncard_le h (ncard_map _).ge hs
 #align set.map_eq_of_subset Set.map_eq_of_subset
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.sep_of_ncard_eq /-
 theorem sep_of_ncard_eq {P : α → Prop} (h : {x ∈ s | P x}.ncard = s.ncard) (ha : a ∈ s)
     (hs : s.Finite := by
       run_tac
@@ -435,6 +492,7 @@ theorem sep_of_ncard_eq {P : α → Prop} (h : {x ∈ s | P x}.ncard = s.ncard)
     P a :=
   sep_eq_self_iff_mem_true.mp (eq_of_subset_of_ncard_le (by simp) h.symm.le hs) _ ha
 #align set.sep_of_ncard_eq Set.sep_of_ncard_eq
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 theorem ncard_lt_ncard (h : s ⊂ t)
@@ -453,7 +511,8 @@ theorem ncard_strictMono [Finite α] : @StrictMono (Set α) _ _ _ ncard := fun _
 #align set.ncard_strict_mono Set.ncard_strictMono
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
-theorem ncard_eq_of_bijective {n : ℕ} (f : ∀ i, i < n → α)
+#print Set.ncard_eq_ofBijective /-
+theorem ncard_eq_ofBijective {n : ℕ} (f : ∀ i, i < n → α)
     (hf : ∀ a ∈ s, ∃ i, ∃ h : i < n, f i h = a) (hf' : ∀ (i) (h : i < n), f i h ∈ s)
     (f_inj : ∀ (i j) (hi : i < n) (hj : j < n), f i hi = f j hj → i = j)
     (hs : s.Finite := by
@@ -463,9 +522,11 @@ theorem ncard_eq_of_bijective {n : ℕ} (f : ∀ i, i < n → α)
   rw [ncard_eq_to_finset_card _ hs]
   apply Finset.card_eq_of_bijective
   all_goals simpa
-#align set.ncard_eq_of_bijective Set.ncard_eq_of_bijective
+#align set.ncard_eq_of_bijective Set.ncard_eq_ofBijective
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_congr /-
 theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha ∈ t)
     (h₂ : ∀ a b ha hb, f a ha = f b hb → a = b) (h₃ : ∀ b ∈ t, ∃ a ha, f a ha = b)
     (hs : s.Finite := by
@@ -490,8 +551,10 @@ theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha
   rw [ncard_def, Nat.card_eq_fintype_card]
   rw [ncard_def, Nat.card_eq_fintype_card]
 #align set.ncard_congr Set.ncard_congr
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_le_ncard_of_injOn /-
 theorem ncard_le_ncard_of_injOn {t : Set β} (f : α → β) (hf : ∀ a ∈ s, f a ∈ t) (f_inj : InjOn f s)
     (ht : t.Finite := by
       run_tac
@@ -504,6 +567,7 @@ theorem ncard_le_ncard_of_injOn {t : Set β} (f : α → β) (hf : ∀ a ∈ s,
   convert Nat.zero_le _
   rw [h.ncard]
 #align set.ncard_le_ncard_of_inj_on Set.ncard_le_ncard_of_injOn
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.ncard) {f : α → β}
@@ -518,6 +582,7 @@ theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.n
 #align set.exists_ne_map_eq_of_ncard_lt_of_maps_to Set.exists_ne_map_eq_of_ncard_lt_of_maps_to
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.le_ncard_of_inj_on_range /-
 theorem le_ncard_of_inj_on_range {n : ℕ} (f : ℕ → α) (hf : ∀ i < n, f i ∈ s)
     (f_inj : ∀ i < n, ∀ j < n, f i = f j → i = j)
     (hs : s.Finite := by
@@ -526,8 +591,10 @@ theorem le_ncard_of_inj_on_range {n : ℕ} (f : ℕ → α) (hf : ∀ i < n, f i
     n ≤ s.ncard := by rw [ncard_eq_to_finset_card _ hs];
   apply Finset.le_card_of_inj_on_range <;> simpa
 #align set.le_ncard_of_inj_on_range Set.le_ncard_of_inj_on_range
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.surj_on_of_inj_on_of_ncard_le /-
 theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
     (hinj : ∀ a₁ a₂ ha₁ ha₂, f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂) (hst : t.ncard ≤ s.ncard)
     (ht : t.Finite := by
@@ -549,8 +616,10 @@ theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
       (by convert hst) b (by simpa)
   simp
 #align set.surj_on_of_inj_on_of_ncard_le Set.surj_on_of_inj_on_of_ncard_le
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.inj_on_of_surj_on_of_ncard_le /-
 theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
     (hsurj : ∀ b ∈ t, ∃ a ha, b = f a ha) (hst : s.ncard ≤ t.ncard) ⦃a₁ a₂⦄ (ha₁ : a₁ ∈ s)
     (ha₂ : a₂ ∈ s) (ha₁a₂ : f a₁ ha₁ = f a₂ ha₂)
@@ -573,6 +642,7 @@ theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
     @Finset.inj_on_of_surj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)
       (by convert hst) a₁ a₂ (by simpa) (by simpa) (by simpa)
 #align set.inj_on_of_surj_on_of_ncard_le Set.inj_on_of_surj_on_of_ncard_le
+-/
 
 section Lattice
 
@@ -710,6 +780,7 @@ theorem diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard)
 #align set.diff_nonempty_of_ncard_lt_ncard Set.diff_nonempty_of_ncard_lt_ncard
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.exists_mem_not_mem_of_ncard_lt_ncard /-
 theorem exists_mem_not_mem_of_ncard_lt_ncard (h : s.ncard < t.ncard)
     (hs : s.Finite := by
       run_tac
@@ -717,6 +788,7 @@ theorem exists_mem_not_mem_of_ncard_lt_ncard (h : s.ncard < t.ncard)
     ∃ e, e ∈ t ∧ e ∉ s :=
   diff_nonempty_of_ncard_lt_ncard h hs
 #align set.exists_mem_not_mem_of_ncard_lt_ncard Set.exists_mem_not_mem_of_ncard_lt_ncard
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 @[simp]
@@ -785,9 +857,10 @@ theorem ncard_add_ncard_compl (s : Set α)
 
 end Lattice
 
+#print Set.exists_intermediate_Set /-
 /-- 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) :
+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
@@ -800,24 +873,32 @@ theorem exists_intermediate_set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂
   have h₁' := Nat.eq_zero_of_le_zero h₁
   rw [add_eq_zero_iff] at h₁' 
   exact ⟨t, h₂, rfl.subset, by rw [ht.ncard, h₁'.1, h₁'.2]⟩
-#align set.exists_intermediate_set Set.exists_intermediate_set
+#align set.exists_intermediate_set Set.exists_intermediate_Set
+-/
 
-theorem exists_intermediate_set' {m : ℕ} (hs : s.ncard ≤ m) (ht : m ≤ t.ncard) (h : s ⊆ t) :
+#print Set.exists_intermediate_Set' /-
+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 
   exact ⟨r, hsr, hrt, hc⟩
-#align set.exists_intermediate_set' Set.exists_intermediate_set'
+#align set.exists_intermediate_set' Set.exists_intermediate_Set'
+-/
 
+#print Set.exists_smaller_Set /-
 /-- We can shrink `s` to any smaller size. -/
-theorem exists_smaller_set (s : Set α) (i : ℕ) (h₁ : i ≤ s.ncard) :
+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 =>
+  (exists_intermediate_Set i (by simpa) (empty_subset s)).imp fun t ht =>
     ⟨ht.2.1, by simpa using ht.2.2⟩
-#align set.exists_smaller_set Set.exists_smaller_set
+#align set.exists_smaller_set Set.exists_smaller_Set
+-/
 
+/- warning: set.infinite.exists_subset_ncard_eq clashes with set.Infinite.exists_subset_ncard_eq -> Set.Infinite.exists_subset_ncard_eq
+Case conversion may be inaccurate. Consider using '#align set.infinite.exists_subset_ncard_eq Set.Infinite.exists_subset_ncard_eqₓ'. -/
+#print Set.Infinite.exists_subset_ncard_eq /-
 theorem Infinite.exists_subset_ncard_eq {s : Set α} (hs : s.Infinite) (k : ℕ) :
     ∃ t, t ⊆ s ∧ t.Finite ∧ t.ncard = k :=
   by
@@ -827,7 +908,9 @@ theorem Infinite.exists_subset_ncard_eq {s : Set α} (hs : s.Infinite) (k : ℕ)
   rw [ncard_image_of_injective _ Subtype.coe_injective]
   simp
 #align set.infinite.exists_subset_ncard_eq Set.Infinite.exists_subset_ncard_eq
+-/
 
+#print Set.Infinite.exists_supset_ncard_eq /-
 theorem Infinite.exists_supset_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
@@ -836,6 +919,7 @@ theorem Infinite.exists_supset_ncard_eq {s t : Set α} (ht : t.Infinite) (hst :
   rwa [ncard_union_eq (disjoint_of_subset_right hs₁ disjoint_sdiff_right) hs hs₁fin, hs₁card,
     add_tsub_cancel_of_le]
 #align set.infinite.exists_supset_ncard_eq Set.Infinite.exists_supset_ncard_eq
+-/
 
 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
@@ -852,6 +936,7 @@ theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s
 /-! ### Explicit description of a set from its cardinality -/
 
 
+#print Set.ncard_eq_one /-
 @[simp]
 theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} :=
   by
@@ -860,9 +945,11 @@ theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} :=
   rw [ncard_eq_to_finset_card, Finset.card_eq_one] at h 
   exact h.imp fun a ha => by rwa [← finite.to_finset_singleton, finite.to_finset_inj] at ha 
 #align set.ncard_eq_one Set.ncard_eq_one
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 /- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (a «expr ∉ » s) -/
+#print Set.exists_eq_insert_iff_ncard /-
 theorem exists_eq_insert_iff_ncard
     (hs : s.Finite := by
       run_tac
@@ -884,8 +971,10 @@ theorem exists_eq_insert_iff_ncard
   rw [← finite.to_finset_insert] at ha 
   exact ⟨a, by rwa [finite.mem_to_finset] at has , by rwa [← @finite.to_finset_inj _ _ _ hsa ht]⟩
 #align set.exists_eq_insert_iff_ncard Set.exists_eq_insert_iff_ncard
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_le_one /-
 theorem ncard_le_one
     (hs : s.Finite := by
       run_tac
@@ -893,16 +982,20 @@ theorem ncard_le_one
     s.ncard ≤ 1 ↔ ∀ a ∈ s, ∀ b ∈ s, a = b := by
   simp_rw [ncard_eq_to_finset_card _ hs, Finset.card_le_one, finite.mem_to_finset]
 #align set.ncard_le_one Set.ncard_le_one
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_le_one_iff /-
 theorem ncard_le_one_iff
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
     s.ncard ≤ 1 ↔ ∀ {a b}, a ∈ s → b ∈ s → a = b := by rw [ncard_le_one hs]; tauto
 #align set.ncard_le_one_iff Set.ncard_le_one_iff
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_le_one_iff_eq /-
 theorem ncard_le_one_iff_eq
     (hs : s.Finite := by
       run_tac
@@ -918,8 +1011,10 @@ theorem ncard_le_one_iff_eq
   simp_rw [mem_singleton_iff] at hx ⊢; subst hx
   exact fun a b h h' => h.trans h'.symm
 #align set.ncard_le_one_iff_eq Set.ncard_le_one_iff_eq
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_le_one_iff_subset_singleton /-
 theorem ncard_le_one_iff_subset_singleton [Nonempty α]
     (hs : s.Finite := by
       run_tac
@@ -928,11 +1023,16 @@ theorem ncard_le_one_iff_subset_singleton [Nonempty α]
   simp_rw [ncard_eq_to_finset_card _ hs, Finset.card_le_one_iff_subset_singleton,
     finite.to_finset_subset, Finset.coe_singleton]
 #align set.ncard_le_one_iff_subset_singleton Set.ncard_le_one_iff_subset_singleton
+-/
 
+/- warning: set.ncard_le_one_of_subsingleton clashes with ncard_le_one_of_subsingleton -> Set.ncard_le_one_of_subsingleton
+Case conversion may be inaccurate. Consider using '#align set.ncard_le_one_of_subsingleton Set.ncard_le_one_of_subsingletonₓ'. -/
+#print Set.ncard_le_one_of_subsingleton /-
 /-- A `set` of a subsingleton type has cardinality at most one. -/
 theorem ncard_le_one_of_subsingleton [Subsingleton α] (s : Set α) : s.ncard ≤ 1 := by
   rw [ncard_eq_to_finset_card]; exact Finset.card_le_one_of_subsingleton _
 #align set.ncard_le_one_of_subsingleton Set.ncard_le_one_of_subsingleton
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
 theorem one_lt_ncard
@@ -944,6 +1044,7 @@ theorem one_lt_ncard
 #align set.one_lt_ncard Set.one_lt_ncard
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.one_lt_ncard_iff /-
 theorem one_lt_ncard_iff
     (hs : s.Finite := by
       run_tac
@@ -951,8 +1052,10 @@ theorem one_lt_ncard_iff
     1 < s.ncard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by rw [one_lt_ncard hs];
   simp only [exists_prop, exists_and_left]
 #align set.one_lt_ncard_iff Set.one_lt_ncard_iff
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.two_lt_ncard_iff /-
 theorem two_lt_ncard_iff
     (hs : s.Finite := by
       run_tac
@@ -960,23 +1063,27 @@ theorem two_lt_ncard_iff
     2 < s.ncard ↔ ∃ a b c, a ∈ s ∧ b ∈ s ∧ c ∈ s ∧ a ≠ b ∧ a ≠ c ∧ b ≠ c := by
   simp_rw [ncard_eq_to_finset_card _ hs, Finset.two_lt_card_iff, finite.mem_to_finset]
 #align set.two_lt_ncard_iff Set.two_lt_ncard_iff
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
-theorem two_lt_card
+theorem two_lt_ncard
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
     2 < s.ncard ↔ ∃ a ∈ s, ∃ b ∈ s, ∃ c ∈ s, a ≠ b ∧ a ≠ c ∧ b ≠ c := by
   simp only [two_lt_ncard_iff hs, exists_and_left, exists_prop]
-#align set.two_lt_card Set.two_lt_card
+#align set.two_lt_card Set.two_lt_ncard
 
+#print Set.exists_ne_of_one_lt_ncard /-
 theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s ∧ b ≠ a :=
   by
   haveI := (finite_of_ncard_ne_zero (zero_lt_one.trans hs).Ne.symm).to_subtype
   rw [ncard_eq_to_finset_card] at hs 
   simpa only [finite.mem_to_finset] using Finset.exists_ne_of_one_lt_card hs a
 #align set.exists_ne_of_one_lt_ncard Set.exists_ne_of_one_lt_ncard
+-/
 
+#print Set.eq_insert_of_ncard_eq_succ /-
 theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
     ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
   classical
@@ -988,8 +1095,10 @@ theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
   convert hts
   simp only [to_finset_insert, Finset.toFinset_coe]
 #align set.eq_insert_of_ncard_eq_succ Set.eq_insert_of_ncard_eq_succ
+-/
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
+#print Set.ncard_eq_succ /-
 theorem ncard_eq_succ {n : ℕ}
     (hs : s.Finite := by
       run_tac
@@ -1000,7 +1109,9 @@ theorem ncard_eq_succ {n : ℕ}
   rintro ⟨a, t, hat, h, rfl⟩
   rw [← h, ncard_insert_of_not_mem hat (hs.subset ((subset_insert a t).trans_eq h))]
 #align set.ncard_eq_succ Set.ncard_eq_succ
+-/
 
+#print Set.ncard_eq_two /-
 theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
   classical
   refine' ⟨fun h => _, _⟩
@@ -1012,7 +1123,9 @@ theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
   rw [ncard_eq_to_finset_card, Finset.card_eq_two]
   exact ⟨x, y, hxy, by ext; simp⟩
 #align set.ncard_eq_two Set.ncard_eq_two
+-/
 
+#print Set.ncard_eq_three /-
 theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
   classical
   refine' ⟨fun h => _, _⟩
@@ -1026,6 +1139,7 @@ theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y 
   rw [mem_insert_iff, mem_singleton_iff]
   tauto
 #align set.ncard_eq_three Set.ncard_eq_three
+-/
 
 end Set
 
Diff
@@ -155,10 +155,10 @@ theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by simp [ncard_eq
 
 theorem ncard_singleton_inter : ({a} ∩ s).ncard ≤ 1 := by
   classical
-    rw [← inter_self {a}, inter_assoc, ncard_eq_to_finset_card, finite.to_finset_inter,
-      finite.to_finset_singleton]
-    · apply Finset.card_singleton_inter
-    all_goals apply to_finite
+  rw [← inter_self {a}, inter_assoc, ncard_eq_to_finset_card, finite.to_finset_inter,
+    finite.to_finset_singleton]
+  · apply Finset.card_singleton_inter
+  all_goals apply to_finite
 #align set.ncard_singleton_inter Set.ncard_singleton_inter
 
 section InsertErase
@@ -171,10 +171,10 @@ theorem ncard_insert_of_not_mem (h : a ∉ s)
         to_finite_tac) :
     (insert a s).ncard = s.ncard + 1 := by
   classical
-    haveI := hs.fintype
-    rw [ncard_eq_to_finset_card, ncard_eq_to_finset_card, finite.to_finset_insert,
-      Finset.card_insert_of_not_mem]
-    rwa [finite.mem_to_finset]
+  haveI := hs.fintype
+  rw [ncard_eq_to_finset_card, ncard_eq_to_finset_card, finite.to_finset_insert,
+    Finset.card_insert_of_not_mem]
+  rwa [finite.mem_to_finset]
 #align set.ncard_insert_of_not_mem Set.ncard_insert_of_not_mem
 
 theorem ncard_insert_of_mem (h : a ∈ s) : ncard (insert a s) = s.ncard := by rw [insert_eq_of_mem h]
@@ -182,13 +182,13 @@ theorem ncard_insert_of_mem (h : a ∈ s) : ncard (insert a s) = s.ncard := by r
 
 theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
   classical
-    obtain hs | hs := s.finite_or_infinite
-    ·
-      exact
-        (em (a ∈ s)).elim (fun h => (ncard_insert_of_mem h).trans_le (Nat.le_succ _)) fun h => by
-          rw [ncard_insert_of_not_mem h hs]
-    rw [(hs.mono (subset_insert a s)).ncard]
-    exact Nat.zero_le _
+  obtain hs | hs := s.finite_or_infinite
+  ·
+    exact
+      (em (a ∈ s)).elim (fun h => (ncard_insert_of_mem h).trans_le (Nat.le_succ _)) fun h => by
+        rw [ncard_insert_of_not_mem h hs]
+  rw [(hs.mono (subset_insert a s)).ncard]
+  exact Nat.zero_le _
 #align set.ncard_insert_le Set.ncard_insert_le
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
@@ -205,12 +205,12 @@ theorem ncard_insert_eq_ite [Decidable (a ∈ s)]
 
 theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
   classical
-    refine' s.finite_or_infinite.elim (fun h => _) fun h => by rw [h.ncard]; exact Nat.zero_le _
-    rw [ncard_insert_eq_ite h]
-    split_ifs
-    · rfl
-    · simp only [le_add_iff_nonneg_right, zero_le']
-    exact Classical.dec (a ∈ s)
+  refine' s.finite_or_infinite.elim (fun h => _) fun h => by rw [h.ncard]; exact Nat.zero_le _
+  rw [ncard_insert_eq_ite h]
+  split_ifs
+  · rfl
+  · simp only [le_add_iff_nonneg_right, zero_le']
+  exact Classical.dec (a ∈ s)
 #align set.ncard_le_ncard_insert Set.ncard_le_ncard_insert
 
 theorem ncard_pair (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by
@@ -289,13 +289,13 @@ theorem ncard_image_le
         to_finite_tac) :
     (f '' s).ncard ≤ s.ncard := by
   classical
-    rw [ncard_eq_to_finset_card s hs]
-    haveI := hs.fintype
-    convert@Finset.card_image_le _ _ s.to_finset f _
-    rw [ncard_eq_to_finset_card, finite.to_finset_image _ hs]
-    · congr; rw [← Finset.coe_inj, finite.coe_to_finset, coe_to_finset]
-    · infer_instance
-    rw [← Finset.coe_inj, finite.coe_to_finset, coe_to_finset]
+  rw [ncard_eq_to_finset_card s hs]
+  haveI := hs.fintype
+  convert @Finset.card_image_le _ _ s.to_finset f _
+  rw [ncard_eq_to_finset_card, finite.to_finset_image _ hs]
+  · congr; rw [← Finset.coe_inj, finite.coe_to_finset, coe_to_finset]
+  · infer_instance
+  rw [← Finset.coe_inj, finite.coe_to_finset, coe_to_finset]
 #align set.ncard_image_le Set.ncard_image_le
 
 theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard :=
@@ -314,14 +314,14 @@ theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard)
         to_finite_tac) :
     Set.InjOn f s := by
   classical
-    haveI := hs.fintype
-    haveI := ((to_finite s).image f).Fintype
-    simp_rw [ncard_eq_to_finset_card] at h 
-    rw [← coe_to_finset s]
-    apply Finset.injOn_of_card_image_eq
-    convert h
-    ext
-    simp
+  haveI := hs.fintype
+  haveI := ((to_finite s).image f).Fintype
+  simp_rw [ncard_eq_to_finset_card] at h 
+  rw [← coe_to_finset s]
+  apply Finset.injOn_of_card_image_eq
+  convert h
+  ext
+  simp
 #align set.inj_on_of_ncard_image_eq Set.injOn_of_ncard_image_eq
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
@@ -347,12 +347,12 @@ theorem fiber_ncard_ne_zero_iff_mem_image {y : β}
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    { x ∈ s | f x = y }.ncard ≠ 0 ↔ y ∈ f '' s :=
+    {x ∈ s | f x = y}.ncard ≠ 0 ↔ y ∈ f '' s :=
   by
   refine' ⟨nonempty_of_ncard_ne_zero, _⟩
   rintro ⟨z, hz, rfl⟩
   exact
-    @ncard_ne_zero_of_mem _ ({ x ∈ s | f x = f z }) z (mem_sep hz rfl) (hs.subset (sep_subset _ _))
+    @ncard_ne_zero_of_mem _ ({x ∈ s | f x = f z}) z (mem_sep hz rfl) (hs.subset (sep_subset _ _))
 #align set.fiber_ncard_ne_zero_iff_mem_image Set.fiber_ncard_ne_zero_iff_mem_image
 
 @[simp]
@@ -362,16 +362,16 @@ theorem ncard_map (f : α ↪ β) : (f '' s).ncard = s.ncard :=
 
 @[simp]
 theorem ncard_subtype (P : α → Prop) (s : Set α) :
-    { x : Subtype P | (x : α) ∈ s }.ncard = (s ∩ setOf P).ncard :=
+    {x : Subtype P | (x : α) ∈ s}.ncard = (s ∩ setOf P).ncard :=
   by
-  convert(ncard_image_of_injective _ (@Subtype.coe_injective _ P)).symm
+  convert (ncard_image_of_injective _ (@Subtype.coe_injective _ P)).symm
   ext; rw [inter_comm]; simp
 #align set.ncard_subtype Set.ncard_subtype
 
 @[simp]
 theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard :=
   by
-  convert(ncard_image_of_injective univ Subtype.coe_injective).symm using 1
+  convert (ncard_image_of_injective univ Subtype.coe_injective).symm using 1
   · rw [ncard_univ]; rfl
   simp
 #align set.nat.card_coe_set_eq Set.Nat.card_coe_set_eq
@@ -428,7 +428,7 @@ theorem map_eq_of_subset {f : α ↪ α} (h : f '' s ⊆ s)
 #align set.map_eq_of_subset Set.map_eq_of_subset
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
-theorem sep_of_ncard_eq {P : α → Prop} (h : { x ∈ s | P x }.ncard = s.ncard) (ha : a ∈ s)
+theorem sep_of_ncard_eq {P : α → Prop} (h : {x ∈ s | P x}.ncard = s.ncard) (ha : a ∈ s)
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
@@ -544,7 +544,8 @@ theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
   haveI := Fintype.ofInjective f' finj
   simp_rw [ncard_eq_to_finset_card] at hst 
   set f'' : ∀ a, a ∈ s.to_finset → β := fun a h => f a (by simpa using h) with hf''
-  convert@Finset.surj_on_of_inj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)
+  convert
+    @Finset.surj_on_of_inj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)
       (by convert hst) b (by simpa)
   simp
 #align set.surj_on_of_inj_on_of_ncard_le Set.surj_on_of_inj_on_of_ncard_le
@@ -558,19 +559,19 @@ theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
         to_finite_tac) :
     a₁ = a₂ := by
   classical
-    set f' : s → t := fun x => ⟨f x.1 x.2, hf _ _⟩ with hf'
-    have hsurj : f'.surjective := by
-      rintro ⟨y, hy⟩
-      obtain ⟨a, ha, rfl⟩ := hsurj y hy
-      simp only [Subtype.val_eq_coe, Subtype.coe_mk, Subtype.mk_eq_mk, SetCoe.exists]
-      exact ⟨_, ha, rfl⟩
-    haveI := hs.fintype
-    haveI := Fintype.ofSurjective _ hsurj
-    simp_rw [ncard_eq_to_finset_card] at hst 
-    set f'' : ∀ a, a ∈ s.to_finset → β := fun a h => f a (by simpa using h) with hf''
-    exact
-      @Finset.inj_on_of_surj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)
-        (by convert hst) a₁ a₂ (by simpa) (by simpa) (by simpa)
+  set f' : s → t := fun x => ⟨f x.1 x.2, hf _ _⟩ with hf'
+  have hsurj : f'.surjective := by
+    rintro ⟨y, hy⟩
+    obtain ⟨a, ha, rfl⟩ := hsurj y hy
+    simp only [Subtype.val_eq_coe, Subtype.coe_mk, Subtype.mk_eq_mk, SetCoe.exists]
+    exact ⟨_, ha, rfl⟩
+  haveI := hs.fintype
+  haveI := Fintype.ofSurjective _ hsurj
+  simp_rw [ncard_eq_to_finset_card] at hst 
+  set f'' : ∀ a, a ∈ s.to_finset → β := fun a h => f a (by simpa using h) with hf''
+  exact
+    @Finset.inj_on_of_surj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)
+      (by convert hst) a₁ a₂ (by simpa) (by simpa) (by simpa)
 #align set.inj_on_of_surj_on_of_ncard_le Set.inj_on_of_surj_on_of_ncard_le
 
 section Lattice
@@ -586,11 +587,11 @@ theorem ncard_union_add_ncard_inter (s t : Set α)
         to_finite_tac) :
     (s ∪ t).ncard + (s ∩ t).ncard = s.ncard + t.ncard := by
   classical
-    have hu := hs.union ht
-    have hi := hs.subset (inter_subset_left s t)
-    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ hu,
-      ncard_eq_to_finset_card _ hi, finite.to_finset_union, finite.to_finset_inter]
-    · exact Finset.card_union_add_card_inter _ _
+  have hu := hs.union ht
+  have hi := hs.subset (inter_subset_left s t)
+  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ hu,
+    ncard_eq_to_finset_card _ hi, finite.to_finset_union, finite.to_finset_inter]
+  · exact Finset.card_union_add_card_inter _ _
 #align set.ncard_union_add_ncard_inter Set.ncard_union_add_ncard_inter
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
@@ -608,14 +609,14 @@ theorem ncard_inter_add_ncard_union (s t : Set α)
 
 theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by
   classical
-    cases (s ∪ t).finite_or_infinite
-    · have hs := h.subset (subset_union_left s t)
-      have ht := h.subset (subset_union_right s t)
-      rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ h,
-        finite.to_finset_union]
-      exact Finset.card_union_le _ _
-    convert Nat.zero_le _
-    rw [h.ncard]
+  cases (s ∪ t).finite_or_infinite
+  · have hs := h.subset (subset_union_left s t)
+    have ht := h.subset (subset_union_right s t)
+    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ h,
+      finite.to_finset_union]
+    exact Finset.card_union_le _ _
+  convert Nat.zero_le _
+  rw [h.ncard]
 #align set.ncard_union_le Set.ncard_union_le
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
@@ -629,10 +630,10 @@ theorem ncard_union_eq (h : Disjoint s t)
         to_finite_tac) :
     (s ∪ t).ncard = s.ncard + t.ncard := by
   classical
-    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht,
-      ncard_eq_to_finset_card _ (hs.union ht), finite.to_finset_union]
-    refine' Finset.card_union_eq _
-    rwa [finite.disjoint_to_finset]
+  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht,
+    ncard_eq_to_finset_card _ (hs.union ht), finite.to_finset_union]
+  refine' Finset.card_union_eq _
+  rwa [finite.disjoint_to_finset]
 #align set.ncard_union_eq Set.ncard_union_eq
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
@@ -642,10 +643,10 @@ theorem ncard_diff_add_ncard_eq_ncard (h : s ⊆ t)
         to_finite_tac) :
     (t \ s).ncard + s.ncard = t.ncard := by
   classical
-    rw [ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ (ht.subset h),
-      ncard_eq_to_finset_card _ (ht.diff s), finite.to_finset_diff]
-    refine' Finset.card_sdiff_add_card_eq_card _
-    rwa [finite.to_finset_subset_to_finset]
+  rw [ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ (ht.subset h),
+    ncard_eq_to_finset_card _ (ht.diff s), finite.to_finset_diff]
+  refine' Finset.card_sdiff_add_card_eq_card _
+  rwa [finite.to_finset_subset_to_finset]
 #align set.ncard_diff_add_ncard_eq_ncard Set.ncard_diff_add_ncard_eq_ncard
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
@@ -839,13 +840,13 @@ theorem Infinite.exists_supset_ncard_eq {s t : Set α} (ht : t.Infinite) (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_to_finset_card _ hu,
-      finite.to_finset_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'⟩
+  have hu := finite_of_ncard_ne_zero ((Nat.zero_le _).trans_lt hst).Ne.symm
+  rw [ncard_eq_to_finset_card _ hu,
+    finite.to_finset_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'⟩
 #align set.exists_subset_or_subset_of_two_mul_lt_ncard Set.exists_subset_or_subset_of_two_mul_lt_ncard
 
 /-! ### Explicit description of a set from its cardinality -/
@@ -868,20 +869,20 @@ theorem exists_eq_insert_iff_ncard
         to_finite_tac) :
     (∃ (a : _) (_ : a ∉ s), insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
   classical
-    constructor
-    · rintro ⟨a, ha, rfl⟩
-      rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ (hs.insert a),
-        finite.to_finset_insert, ← @finite.to_finset_subset_to_finset _ _ _ hs (hs.insert a),
-        finite.to_finset_insert]
-      refine' (@Finset.exists_eq_insert_iff _ _ hs.to_finset (insert a hs.to_finset)).mp _
-      exact ⟨a, by rwa [finite.mem_to_finset], rfl⟩
-    rintro ⟨hst, h⟩
-    have ht := @finite_of_ncard_pos _ t (by rw [← h]; apply Nat.zero_lt_succ)
-    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht] at h 
-    obtain ⟨a, has, ha⟩ := finset.exists_eq_insert_iff.mpr ⟨by simpa, h⟩
-    have hsa := hs.insert a
-    rw [← finite.to_finset_insert] at ha 
-    exact ⟨a, by rwa [finite.mem_to_finset] at has , by rwa [← @finite.to_finset_inj _ _ _ hsa ht]⟩
+  constructor
+  · rintro ⟨a, ha, rfl⟩
+    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ (hs.insert a),
+      finite.to_finset_insert, ← @finite.to_finset_subset_to_finset _ _ _ hs (hs.insert a),
+      finite.to_finset_insert]
+    refine' (@Finset.exists_eq_insert_iff _ _ hs.to_finset (insert a hs.to_finset)).mp _
+    exact ⟨a, by rwa [finite.mem_to_finset], rfl⟩
+  rintro ⟨hst, h⟩
+  have ht := @finite_of_ncard_pos _ t (by rw [← h]; apply Nat.zero_lt_succ)
+  rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht] at h 
+  obtain ⟨a, has, ha⟩ := finset.exists_eq_insert_iff.mpr ⟨by simpa, h⟩
+  have hsa := hs.insert a
+  rw [← finite.to_finset_insert] at ha 
+  exact ⟨a, by rwa [finite.mem_to_finset] at has , by rwa [← @finite.to_finset_inj _ _ _ hsa ht]⟩
 #align set.exists_eq_insert_iff_ncard Set.exists_eq_insert_iff_ncard
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
@@ -979,13 +980,13 @@ theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s 
 theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
     ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
   classical
-    haveI := @Fintype.ofFinite _ (finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)).to_subtype
-    rw [ncard_eq_to_finset_card, Finset.card_eq_succ] at h 
-    obtain ⟨a, t, hat, hts, rfl⟩ := h
-    refine' ⟨a, t, hat, _, by rw [ncard_coe_finset]⟩
-    rw [← to_finset_inj]
-    convert hts
-    simp only [to_finset_insert, Finset.toFinset_coe]
+  haveI := @Fintype.ofFinite _ (finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)).to_subtype
+  rw [ncard_eq_to_finset_card, Finset.card_eq_succ] at h 
+  obtain ⟨a, t, hat, hts, rfl⟩ := h
+  refine' ⟨a, t, hat, _, by rw [ncard_coe_finset]⟩
+  rw [← to_finset_inj]
+  convert hts
+  simp only [to_finset_insert, Finset.toFinset_coe]
 #align set.eq_insert_of_ncard_eq_succ Set.eq_insert_of_ncard_eq_succ
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
@@ -995,35 +996,35 @@ theorem ncard_eq_succ {n : ℕ}
         to_finite_tac) :
     s.ncard = n + 1 ↔ ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
   classical
-    refine' ⟨eq_insert_of_ncard_eq_succ, _⟩
-    rintro ⟨a, t, hat, h, rfl⟩
-    rw [← h, ncard_insert_of_not_mem hat (hs.subset ((subset_insert a t).trans_eq h))]
+  refine' ⟨eq_insert_of_ncard_eq_succ, _⟩
+  rintro ⟨a, t, hat, h, rfl⟩
+  rw [← h, ncard_insert_of_not_mem hat (hs.subset ((subset_insert a t).trans_eq h))]
 #align set.ncard_eq_succ Set.ncard_eq_succ
 
 theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
   classical
-    refine' ⟨fun h => _, _⟩
-    · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
-      obtain ⟨y, rfl⟩ := ncard_eq_one.mp ht
-      rw [mem_singleton_iff] at hxt 
-      exact ⟨_, _, hxt, rfl⟩
-    rintro ⟨x, y, hxy, rfl⟩
-    rw [ncard_eq_to_finset_card, Finset.card_eq_two]
-    exact ⟨x, y, hxy, by ext; simp⟩
+  refine' ⟨fun h => _, _⟩
+  · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
+    obtain ⟨y, rfl⟩ := ncard_eq_one.mp ht
+    rw [mem_singleton_iff] at hxt 
+    exact ⟨_, _, hxt, rfl⟩
+  rintro ⟨x, y, hxy, rfl⟩
+  rw [ncard_eq_to_finset_card, Finset.card_eq_two]
+  exact ⟨x, y, hxy, by ext; simp⟩
 #align set.ncard_eq_two Set.ncard_eq_two
 
 theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
   classical
-    refine' ⟨fun h => _, _⟩
-    · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
-      obtain ⟨y, z, hyz, rfl⟩ := ncard_eq_two.mp ht
-      rw [mem_insert_iff, mem_singleton_iff, not_or] at hxt 
-      exact ⟨x, y, z, hxt.1, hxt.2, hyz, rfl⟩
-    rintro ⟨x, y, z, xy, xz, yz, rfl⟩
-    rw [ncard_insert_of_not_mem, ncard_insert_of_not_mem, ncard_singleton]
-    · rwa [mem_singleton_iff]
-    rw [mem_insert_iff, mem_singleton_iff]
-    tauto
+  refine' ⟨fun h => _, _⟩
+  · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
+    obtain ⟨y, z, hyz, rfl⟩ := ncard_eq_two.mp ht
+    rw [mem_insert_iff, mem_singleton_iff, not_or] at hxt 
+    exact ⟨x, y, z, hxt.1, hxt.2, hyz, rfl⟩
+  rintro ⟨x, y, z, xy, xz, yz, rfl⟩
+  rw [ncard_insert_of_not_mem, ncard_insert_of_not_mem, ncard_singleton]
+  · rwa [mem_singleton_iff]
+  rw [mem_insert_iff, mem_singleton_iff]
+  tauto
 #align set.ncard_eq_three Set.ncard_eq_three
 
 end Set
Diff
@@ -293,7 +293,7 @@ theorem ncard_image_le
     haveI := hs.fintype
     convert@Finset.card_image_le _ _ s.to_finset f _
     rw [ncard_eq_to_finset_card, finite.to_finset_image _ hs]
-    · congr ; rw [← Finset.coe_inj, finite.coe_to_finset, coe_to_finset]
+    · congr; rw [← Finset.coe_inj, finite.coe_to_finset, coe_to_finset]
     · infer_instance
     rw [← Finset.coe_inj, finite.coe_to_finset, coe_to_finset]
 #align set.ncard_image_le Set.ncard_image_le
@@ -316,7 +316,7 @@ theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard)
   classical
     haveI := hs.fintype
     haveI := ((to_finite s).image f).Fintype
-    simp_rw [ncard_eq_to_finset_card] at h
+    simp_rw [ncard_eq_to_finset_card] at h 
     rw [← coe_to_finset s]
     apply Finset.injOn_of_card_image_eq
     convert h
@@ -405,7 +405,7 @@ theorem eq_of_subset_of_ncard_le (h : s ⊆ t) (h' : t.ncard ≤ s.ncard)
   rw [← @to_finset_inj]
   apply Finset.eq_of_subset_of_card_le
   · simpa
-  rw [ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ (ht.subset h)] at h'
+  rw [ncard_eq_to_finset_card _ ht, ncard_eq_to_finset_card _ (ht.subset h)] at h' 
   convert h'
 #align set.eq_of_subset_of_ncard_le Set.eq_of_subset_of_ncard_le
 
@@ -477,7 +477,7 @@ theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha
   have hbij : f'.bijective := by
     constructor
     · rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy
-      simp only [hf', Subtype.val_eq_coe, Subtype.coe_mk, Subtype.mk_eq_mk] at hxy⊢
+      simp only [hf', Subtype.val_eq_coe, Subtype.coe_mk, Subtype.mk_eq_mk] at hxy ⊢
       apply h₂ _ _ hx hy hxy
     rintro ⟨y, hy⟩
     obtain ⟨a, ha, rfl⟩ := h₃ y hy
@@ -513,7 +513,7 @@ theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.n
         to_finite_tac) :
     ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ f x = f y := by
   by_contra h'
-  simp only [Ne.def, exists_prop, not_exists, not_and, not_imp_not] at h'
+  simp only [Ne.def, exists_prop, not_exists, not_and, not_imp_not] at h' 
   exact (ncard_le_ncard_of_inj_on f hf h' ht).not_lt hc
 #align set.exists_ne_map_eq_of_ncard_lt_of_maps_to Set.exists_ne_map_eq_of_ncard_lt_of_maps_to
 
@@ -538,11 +538,11 @@ theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
   set f' : s → t := fun x => ⟨f x.1 x.2, hf _ _⟩ with hf'
   have finj : f'.injective := by
     rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy
-    simp only [hf', Subtype.val_eq_coe, Subtype.coe_mk, Subtype.mk_eq_mk] at hxy⊢
+    simp only [hf', Subtype.val_eq_coe, Subtype.coe_mk, Subtype.mk_eq_mk] at hxy ⊢
     apply hinj _ _ hx hy hxy
   haveI := ht.fintype
   haveI := Fintype.ofInjective f' finj
-  simp_rw [ncard_eq_to_finset_card] at hst
+  simp_rw [ncard_eq_to_finset_card] at hst 
   set f'' : ∀ a, a ∈ s.to_finset → β := fun a h => f a (by simpa using h) with hf''
   convert@Finset.surj_on_of_inj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)
       (by convert hst) b (by simpa)
@@ -566,7 +566,7 @@ theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
       exact ⟨_, ha, rfl⟩
     haveI := hs.fintype
     haveI := Fintype.ofSurjective _ hsurj
-    simp_rw [ncard_eq_to_finset_card] at hst
+    simp_rw [ncard_eq_to_finset_card] at hst 
     set f'' : ∀ a, a ∈ s.to_finset → β := fun a h => f a (by simpa using h) with hf''
     exact
       @Finset.inj_on_of_surj_on_of_card_le _ _ _ t.to_finset f'' (by simpa) (by simpa)
@@ -792,12 +792,12 @@ theorem exists_intermediate_set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂
   cases' t.finite_or_infinite with ht ht
   · haveI := ht.to_subtype
     haveI := (ht.subset h₂).to_subtype
-    simp_rw [ncard_eq_to_finset_card] at h₁⊢
+    simp_rw [ncard_eq_to_finset_card] 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₁
+  rw [ht.ncard] at h₁ 
   have h₁' := Nat.eq_zero_of_le_zero h₁
-  rw [add_eq_zero_iff] at h₁'
+  rw [add_eq_zero_iff] at h₁' 
   exact ⟨t, h₂, rfl.subset, by rw [ht.ncard, h₁'.1, h₁'.2]⟩
 #align set.exists_intermediate_set Set.exists_intermediate_set
 
@@ -806,7 +806,7 @@ theorem exists_intermediate_set' {m : ℕ} (hs : s.ncard ≤ m) (ht : m ≤ t.nc
   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
+  rw [tsub_add_cancel_of_le hs] at hc 
   exact ⟨r, hsr, hrt, hc⟩
 #align set.exists_intermediate_set' Set.exists_intermediate_set'
 
@@ -843,7 +843,7 @@ theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s
     rw [ncard_eq_to_finset_card _ hu,
       finite.to_finset_union (hu.subset (subset_union_left _ _))
         (hu.subset (subset_union_right _ _))] at
-      hst
+      hst 
     obtain ⟨r', hnr', hr'⟩ := Finset.exists_subset_or_subset_of_two_mul_lt_card hst
     exact ⟨r', by simpa, by simpa using hr'⟩
 #align set.exists_subset_or_subset_of_two_mul_lt_ncard Set.exists_subset_or_subset_of_two_mul_lt_ncard
@@ -856,8 +856,8 @@ theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} :=
   by
   refine' ⟨fun h => _, by rintro ⟨a, rfl⟩; rw [ncard_singleton]⟩
   haveI := (finite_of_ncard_ne_zero (ne_zero_of_eq_one h)).to_subtype
-  rw [ncard_eq_to_finset_card, Finset.card_eq_one] at h
-  exact h.imp fun a ha => by rwa [← finite.to_finset_singleton, finite.to_finset_inj] at ha
+  rw [ncard_eq_to_finset_card, Finset.card_eq_one] at h 
+  exact h.imp fun a ha => by rwa [← finite.to_finset_singleton, finite.to_finset_inj] at ha 
 #align set.ncard_eq_one Set.ncard_eq_one
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
@@ -866,7 +866,7 @@ theorem exists_eq_insert_iff_ncard
     (hs : s.Finite := by
       run_tac
         to_finite_tac) :
-    (∃ (a : _)(_ : a ∉ s), insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
+    (∃ (a : _) (_ : a ∉ s), insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
   classical
     constructor
     · rintro ⟨a, ha, rfl⟩
@@ -877,11 +877,11 @@ theorem exists_eq_insert_iff_ncard
       exact ⟨a, by rwa [finite.mem_to_finset], rfl⟩
     rintro ⟨hst, h⟩
     have ht := @finite_of_ncard_pos _ t (by rw [← h]; apply Nat.zero_lt_succ)
-    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht] at h
+    rw [ncard_eq_to_finset_card _ hs, ncard_eq_to_finset_card _ ht] at h 
     obtain ⟨a, has, ha⟩ := finset.exists_eq_insert_iff.mpr ⟨by simpa, h⟩
     have hsa := hs.insert a
-    rw [← finite.to_finset_insert] at ha
-    exact ⟨a, by rwa [finite.mem_to_finset] at has, by rwa [← @finite.to_finset_inj _ _ _ hsa ht]⟩
+    rw [← finite.to_finset_insert] at ha 
+    exact ⟨a, by rwa [finite.mem_to_finset] at has , by rwa [← @finite.to_finset_inj _ _ _ hsa ht]⟩
 #align set.exists_eq_insert_iff_ncard Set.exists_eq_insert_iff_ncard
 
 /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic to_finite_tac -/
@@ -914,7 +914,7 @@ theorem ncard_le_one_iff_eq
   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
+  simp_rw [mem_singleton_iff] at hx ⊢; subst hx
   exact fun a b h h' => h.trans h'.symm
 #align set.ncard_le_one_iff_eq Set.ncard_le_one_iff_eq
 
@@ -972,7 +972,7 @@ theorem two_lt_card
 theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s ∧ b ≠ a :=
   by
   haveI := (finite_of_ncard_ne_zero (zero_lt_one.trans hs).Ne.symm).to_subtype
-  rw [ncard_eq_to_finset_card] at hs
+  rw [ncard_eq_to_finset_card] at hs 
   simpa only [finite.mem_to_finset] using Finset.exists_ne_of_one_lt_card hs a
 #align set.exists_ne_of_one_lt_ncard Set.exists_ne_of_one_lt_ncard
 
@@ -980,7 +980,7 @@ theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
     ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
   classical
     haveI := @Fintype.ofFinite _ (finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)).to_subtype
-    rw [ncard_eq_to_finset_card, Finset.card_eq_succ] at h
+    rw [ncard_eq_to_finset_card, Finset.card_eq_succ] at h 
     obtain ⟨a, t, hat, hts, rfl⟩ := h
     refine' ⟨a, t, hat, _, by rw [ncard_coe_finset]⟩
     rw [← to_finset_inj]
@@ -1005,7 +1005,7 @@ theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
     refine' ⟨fun h => _, _⟩
     · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
       obtain ⟨y, rfl⟩ := ncard_eq_one.mp ht
-      rw [mem_singleton_iff] at hxt
+      rw [mem_singleton_iff] at hxt 
       exact ⟨_, _, hxt, rfl⟩
     rintro ⟨x, y, hxy, rfl⟩
     rw [ncard_eq_to_finset_card, Finset.card_eq_two]
@@ -1017,7 +1017,7 @@ theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y 
     refine' ⟨fun h => _, _⟩
     · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
       obtain ⟨y, z, hyz, rfl⟩ := ncard_eq_two.mp ht
-      rw [mem_insert_iff, mem_singleton_iff, not_or] at hxt
+      rw [mem_insert_iff, mem_singleton_iff, not_or] at hxt 
       exact ⟨x, y, z, hxt.1, hxt.2, hyz, rfl⟩
     rintro ⟨x, y, z, xy, xz, yz, rfl⟩
     rw [ncard_insert_of_not_mem, ncard_insert_of_not_mem, ncard_singleton]

Changes in mathlib4

mathlib3
mathlib4
chore: reformat deprecation warnings on one line, if possible (#12335)

Occasionally, remove a "deprecated by" or "deprecated since", to fit the line length.

This is desirable (to me) because

  • it's more compact: I don't see a good reason for these declarations taking up more space than needed; as I understand it, deprecated lemmas are not supposed to be used in mathlib anyway
  • putting the date on the same line as the attribute makes it easier to discover un-dated deprecations; they also ease writing a tool to replace these by a machine-readable version using leanprover/lean4#3968
Diff
@@ -1120,10 +1120,4 @@ theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y 
 
 end ncard
 
-/-!
-### Deprecated lemmas
-
-Those lemmas have been deprecated on 2023-12-27.
--/
-
-@[deprecated] alias ncard_le_of_subset := ncard_le_ncard
+@[deprecated] alias ncard_le_of_subset := ncard_le_ncard -- 2023-12-27
chore: backports from #11997, adaptations for nightly-2024-04-07 (#12176)

These are changes from #11997, the latest adaptation PR for nightly-2024-04-07, which can be made directly on master.

Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Ruben Van de Velde <65514131+Ruben-VandeVelde@users.noreply.github.com>

Diff
@@ -132,7 +132,7 @@ theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n
   ⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩
 
 @[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by
-  rw [← not_iff_not, ← Ne.def, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite]
+  rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite]
 
 theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by
   simp
@@ -297,7 +297,7 @@ theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} :=
     encard_eq_one]
 
 theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by
-  rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne.def, ← nonempty_iff_ne_empty]
+  rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty]
   refine' ⟨fun h a b has hbs ↦ _,
     fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩
   obtain ⟨x, rfl⟩ := h ⟨_, has⟩
Chore(Data/Set/Card): Remove unnecessary assumption for ncard eq of bijective (#12108)

Drop redundant hypothesis s.Finite from Set.ncard_eq_of_bijective.

Diff
@@ -738,12 +738,16 @@ theorem ncard_strictMono [Finite α] : @StrictMono (Set α) _ _ _ ncard :=
 
 theorem ncard_eq_of_bijective {n : ℕ} (f : ∀ i, i < n → α)
     (hf : ∀ a ∈ s, ∃ i, ∃ h : i < n, f i h = a) (hf' : ∀ (i) (h : i < n), f i h ∈ s)
-    (f_inj : ∀ (i j) (hi : i < n) (hj : j < n), f i hi = f j hj → i = j)
-    (hs : s.Finite := by toFinite_tac) :
-    s.ncard = n := by
-  rw [ncard_eq_toFinset_card _ hs]
-  apply Finset.card_eq_of_bijective
-  all_goals simpa
+    (f_inj : ∀ (i j) (hi : i < n) (hj : j < n), f i hi = f j hj → i = j) : s.ncard = n := by
+  let f' : Fin n → α := fun i ↦ f i.val i.is_lt
+  suffices himage : s = f' '' Set.univ by
+    rw [← Fintype.card_fin n, ← Nat.card_eq_fintype_card, ← Set.ncard_univ, himage]
+    exact ncard_image_of_injOn <| fun i _hi j _hj h ↦ Fin.ext <| f_inj i.val j.val i.is_lt j.is_lt h
+  ext x
+  simp only [image_univ, mem_range]
+  refine ⟨fun hx ↦ ?_, fun ⟨⟨i, hi⟩, hx⟩ ↦ hx ▸ hf' i hi⟩
+  obtain ⟨i, hi, rfl⟩ := hf x hx
+  use ⟨i, hi⟩
 #align set.ncard_eq_of_bijective Set.ncard_eq_of_bijective
 
 theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha ∈ t)
chore: superfluous parentheses part 2 (#12131)

Co-authored-by: Moritz Firsching <firsching@google.com>

Diff
@@ -1075,7 +1075,7 @@ theorem two_lt_ncard (hs : s.Finite := by toFinite_tac) :
 #align set.two_lt_card Set.two_lt_ncard
 
 theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s ∧ b ≠ a := by
-  have hsf := (finite_of_ncard_ne_zero (zero_lt_one.trans hs).ne.symm)
+  have hsf := finite_of_ncard_ne_zero (zero_lt_one.trans hs).ne.symm
   rw [ncard_eq_toFinset_card _ hsf] at hs
   simpa only [Finite.mem_toFinset] using Finset.exists_ne_of_one_lt_card hs a
 #align set.exists_ne_of_one_lt_ncard Set.exists_ne_of_one_lt_ncard
chore: remove autoImplicit from more files (#11798)

and reduce its scope in a few other instances. Mostly in CategoryTheory and Data this time; some Combinatorics also.

Co-authored-by: Richard Osborn <richardosborn@mac.com>

Diff
@@ -56,11 +56,9 @@ the other inside the proof. A few of the theorems, such as `ncard_union_le` do n
 finiteness arguments; they are true by coincidence due to junk values.
 -/
 
-set_option autoImplicit true
-
 namespace Set
 
-variable {s t : Set α}
+variable {α β : Type*} {s t : Set α}
 
 /-- The cardinality of a set as a term in `ℕ∞` -/
 noncomputable def encard (s : Set α) : ℕ∞ := PartENat.withTopEquiv (PartENat.card s)
@@ -115,7 +113,7 @@ theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.enc
   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_insert_of_not_mem (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
+theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
   rw [← union_singleton, encard_union_eq (by simpa), encard_singleton]
 
 theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
@@ -234,6 +232,8 @@ end Lattice
 
 section InsertErase
 
+variable {a b : α}
+
 theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
   rw [← union_singleton, ← encard_singleton x]; apply encard_union_le
 
@@ -283,7 +283,7 @@ end InsertErase
 
 section SmallSets
 
-theorem encard_pair (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
+theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
   rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two,
     WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_singleton]
 
@@ -348,7 +348,7 @@ theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆
     WithTop.add_left_cancel_iff hs.encard_lt_top.ne, encard_eq_one] at hst
   obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union]
 
-theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
+theorem exists_subset_encard_eq {k : ℕ∞} (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)
@@ -360,7 +360,8 @@ theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.enc
   simp only [top_le_iff, encard_eq_top_iff]
   exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩
 
-theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
+theorem exists_superset_subset_encard_eq {k : ℕ∞}
+    (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⟩
@@ -538,7 +539,7 @@ theorem ncard_pos (hs : s.Finite := by toFinite_tac) : 0 < s.ncard ↔ s.Nonempt
   rw [pos_iff_ne_zero, Ne, ncard_eq_zero hs, nonempty_iff_ne_empty]
 #align set.ncard_pos Set.ncard_pos
 
-theorem ncard_ne_zero_of_mem (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : s.ncard ≠ 0 :=
+theorem ncard_ne_zero_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : s.ncard ≠ 0 :=
   ((ncard_pos hs).mpr ⟨a, h⟩).ne.symm
 #align set.ncard_ne_zero_of_mem Set.ncard_ne_zero_of_mem
 
@@ -564,13 +565,13 @@ theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 :=
 #align set.ncard_singleton_inter Set.ncard_singleton_inter
 section InsertErase
 
-@[simp] theorem ncard_insert_of_not_mem (h : a ∉ s) (hs : s.Finite := by toFinite_tac) :
+@[simp] theorem ncard_insert_of_not_mem {a : α} (h : a ∉ s) (hs : s.Finite := by toFinite_tac) :
     (insert a s).ncard = s.ncard + 1 := by
   rw [← Nat.cast_inj (R := ℕ∞), (hs.insert a).cast_ncard_eq, Nat.cast_add, Nat.cast_one,
     hs.cast_ncard_eq, encard_insert_of_not_mem h]
 #align set.ncard_insert_of_not_mem Set.ncard_insert_of_not_mem
 
-theorem ncard_insert_of_mem (h : a ∈ s) : ncard (insert a s) = s.ncard := by
+theorem ncard_insert_of_mem {a : α} (h : a ∈ s) : ncard (insert a s) = s.ncard := by
     rw [insert_eq_of_mem h]
 #align set.ncard_insert_of_mem Set.ncard_insert_of_mem
 
@@ -581,7 +582,7 @@ theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard +
   exact Nat.zero_le _
 #align set.ncard_insert_le Set.ncard_insert_le
 
-theorem ncard_insert_eq_ite [Decidable (a ∈ s)] (hs : s.Finite := by toFinite_tac) :
+theorem ncard_insert_eq_ite {a : α} [Decidable (a ∈ s)] (hs : s.Finite := by toFinite_tac) :
     ncard (insert a s) = if a ∈ s then s.ncard else s.ncard + 1 := by
   by_cases h : a ∈ s
   · rw [ncard_insert_of_mem h, if_pos h]
@@ -595,22 +596,22 @@ theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).n
   rw [ncard_insert_eq_ite h]; split_ifs <;> simp
 #align set.ncard_le_ncard_insert Set.ncard_le_ncard_insert
 
-@[simp] theorem ncard_pair (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by
+@[simp] theorem ncard_pair {a b : α} (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by
   rw [ncard_insert_of_not_mem, ncard_singleton]; simpa
 #align set.card_doubleton Set.ncard_pair
 
-@[simp] theorem ncard_diff_singleton_add_one (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
-    (s \ {a}).ncard + 1 = s.ncard := by
+@[simp] theorem ncard_diff_singleton_add_one {a : α} (h : a ∈ s)
+    (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard + 1 = s.ncard := by
   to_encard_tac; rw [hs.cast_ncard_eq, (hs.diff _).cast_ncard_eq,
     encard_diff_singleton_add_one h]
 #align set.ncard_diff_singleton_add_one Set.ncard_diff_singleton_add_one
 
-@[simp] theorem ncard_diff_singleton_of_mem (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
+@[simp] theorem ncard_diff_singleton_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
     (s \ {a}).ncard = s.ncard - 1 :=
   eq_tsub_of_add_eq (ncard_diff_singleton_add_one h hs)
 #align set.ncard_diff_singleton_of_mem Set.ncard_diff_singleton_of_mem
 
-theorem ncard_diff_singleton_lt_of_mem (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
+theorem ncard_diff_singleton_lt_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
     (s \ {a}).ncard < s.ncard := by
   rw [← ncard_diff_singleton_add_one h hs]; apply lt_add_one
 #align set.ncard_diff_singleton_lt_of_mem Set.ncard_diff_singleton_lt_of_mem
@@ -632,17 +633,20 @@ theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 
   rw [hs.ncard]
 #align set.pred_ncard_le_ncard_diff_singleton Set.pred_ncard_le_ncard_diff_singleton
 
-theorem ncard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncard = s.ncard :=
+theorem ncard_exchange {a b : α} (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncard = s.ncard :=
   congr_arg ENat.toNat <| encard_exchange ha hb
 #align set.ncard_exchange Set.ncard_exchange
 
-theorem ncard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).ncard = s.ncard := by
+theorem ncard_exchange' {a b : α} (ha : a ∉ s) (hb : b ∈ s) :
+    (insert a s \ {b}).ncard = s.ncard := by
   rw [← ncard_exchange ha hb, ← singleton_union, ← singleton_union, union_diff_distrib,
     @diff_singleton_eq_self _ b {a} fun h ↦ ha (by rwa [← mem_singleton_iff.mp h])]
 #align set.ncard_exchange' Set.ncard_exchange'
 
 end InsertErase
 
+variable {f : α → β}
+
 theorem ncard_image_le (hs : s.Finite := by toFinite_tac) : (f '' s).ncard ≤ s.ncard := by
   to_encard_tac; rw [hs.cast_ncard_eq, (hs.image _).cast_ncard_eq]; apply encard_image_le
 #align set.ncard_image_le Set.ncard_image_le
@@ -717,7 +721,7 @@ theorem map_eq_of_subset {f : α ↪ α} (h : f '' s ⊆ s) (hs : s.Finite := by
   eq_of_subset_of_ncard_le h (ncard_map _).ge hs
 #align set.map_eq_of_subset Set.map_eq_of_subset
 
-theorem sep_of_ncard_eq {P : α → Prop} (h : { x ∈ s | P x }.ncard = s.ncard) (ha : a ∈ s)
+theorem sep_of_ncard_eq {a : α} {P : α → Prop} (h : { x ∈ s | P x }.ncard = s.ncard) (ha : a ∈ s)
     (hs : s.Finite := by toFinite_tac) : P a :=
   sep_eq_self_iff_mem_true.mp (eq_of_subset_of_ncard_le (by simp) h.symm.le hs) _ ha
 #align set.sep_of_ncard_eq Set.sep_of_ncard_eq
chore: avoid Ne.def (adaptation for nightly-2024-03-27) (#11801)
Diff
@@ -98,7 +98,7 @@ theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by
   rw [encard_eq_zero]
 
 theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by
-  rwa [nonempty_iff_ne_empty, Ne.def, ← encard_eq_zero]
+  rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero]
 
 theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by
   rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty]
@@ -161,7 +161,7 @@ theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.enca
   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
-  rw [nonempty_iff_ne_empty, Ne.def, ← encard_eq_zero, ENat.one_le_iff_ne_zero]
+  rw [nonempty_iff_ne_empty, Ne, ← 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
@@ -535,7 +535,7 @@ theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by
 #align set.ncard_empty Set.ncard_empty
 
 theorem ncard_pos (hs : s.Finite := by toFinite_tac) : 0 < s.ncard ↔ s.Nonempty := by
-  rw [pos_iff_ne_zero, Ne.def, ncard_eq_zero hs, nonempty_iff_ne_empty]
+  rw [pos_iff_ne_zero, Ne, ncard_eq_zero hs, nonempty_iff_ne_empty]
 #align set.ncard_pos Set.ncard_pos
 
 theorem ncard_ne_zero_of_mem (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : s.ncard ≠ 0 :=
@@ -770,7 +770,7 @@ theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.n
     (hf : ∀ a ∈ s, f a ∈ t) (ht : t.Finite := by toFinite_tac) :
     ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ f x = f y := by
   by_contra h'
-  simp only [Ne.def, exists_prop, not_exists, not_and, not_imp_not] at h'
+  simp only [Ne, exists_prop, not_exists, not_and, not_imp_not] at h'
   exact (ncard_le_ncard_of_injOn f hf h' ht).not_lt hc
 #align set.exists_ne_map_eq_of_ncard_lt_of_maps_to Set.exists_ne_map_eq_of_ncard_lt_of_maps_to
 
@@ -888,7 +888,7 @@ theorem ncard_diff_add_ncard (s t : Set α) (hs : s.Finite := by toFinite_tac)
 
 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]
+  rw [Set.nonempty_iff_ne_empty, Ne, diff_eq_empty]
   exact fun h' ↦ h.not_le (ncard_le_ncard h' hs)
 #align set.diff_nonempty_of_ncard_lt_ncard Set.diff_nonempty_of_ncard_lt_ncard
 
chore: prepare Lean version bump with explicit simp (#10999)

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -749,7 +749,7 @@ theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha
   have hbij : f'.Bijective := by
     constructor
     · rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy
-      simp only [Subtype.mk.injEq] at hxy ⊢
+      simp only [f', Subtype.mk.injEq] at hxy ⊢
       exact h₂ _ _ hx hy hxy
     rintro ⟨y, hy⟩
     obtain ⟨a, ha, rfl⟩ := h₃ y hy
@@ -789,7 +789,7 @@ theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
   set f' : s → t := fun x ↦ ⟨f x.1 x.2, hf _ _⟩
   have finj : f'.Injective := by
     rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy
-    simp only [Subtype.mk.injEq] at hxy ⊢
+    simp only [f', Subtype.mk.injEq] at hxy ⊢
     apply hinj _ _ hx hy hxy
   have hft := ht.fintype
   have hft' := Fintype.ofInjective f' finj
chore: Remove unnecessary "rw"s (#10704)

Remove unnecessary "rw"s.

Diff
@@ -79,7 +79,7 @@ theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinse
 
 theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by
   have h := toFinite s
-  rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset, toFinset_card]
+  rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset]
 
 theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by
   rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp
chore: remove stream-of-consciousness uses of have, replace and suffices (#10640)

No changes to tactic file, it's just boring fixes throughout the library.

This follows on from #6964.

Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr> Co-authored-by: Eric Wieser <wieser.eric@gmail.com>

Diff
@@ -353,8 +353,8 @@ theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.enc
   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
+    have hne : t₀ ≠ s := by
+      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]
@@ -366,8 +366,8 @@ theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k)
   · 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
+  have hk : k ≤ encard (t \ s) := by
+    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 _ _)), _⟩
@@ -421,8 +421,8 @@ theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β}
   · simp
   · exact (encard_ne_top_iff.mpr hs h).elim
   obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle)
-  have hle' : (s \ {a}).encard ≤ (t \ {b}).encard
-  · rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top,
+  have hle' : (s \ {a}).encard ≤ (t \ {b}).encard := by
+    rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top,
     encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt]
 
   obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le (hs.diff {a}) hle'
chore: move to v4.6.0-rc1, merging adaptations from bump/v4.6.0 (#10176)

Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Joachim Breitner <mail@joachim-breitner.de>

Diff
@@ -437,7 +437,7 @@ theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β}
   refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩
   · rintro x hx; split_ifs with h; assumption; exact (hf₀s x hx h).1
   exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_noteq])
-termination_by _ => encard s
+termination_by encard s
 
 theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) :
     ∃ (f : α → β), BijOn f s t := by
chore: reduce imports (#9830)

This uses the improved shake script from #9772 to reduce imports across mathlib. The corresponding noshake.json file has been added to #9772.

Co-authored-by: Mario Carneiro <di.gama@gmail.com>

Diff
@@ -3,7 +3,7 @@ Copyright (c) 2023 Peter Nelson. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Peter Nelson
 -/
-import Mathlib.Data.Finite.Card
+import Mathlib.SetTheory.Cardinal.Finite
 
 #align_import data.set.ncard from "leanprover-community/mathlib"@"74c2af38a828107941029b03839882c5c6f87a04"
 
chore: cleanup spaces (#9745)
Diff
@@ -1055,7 +1055,7 @@ theorem one_lt_ncard (hs : s.Finite := by toFinite_tac) :
 #align set.one_lt_ncard Set.one_lt_ncard
 
 theorem one_lt_ncard_iff (hs : s.Finite := by toFinite_tac) :
-    1 < s.ncard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b :=   by
+    1 < s.ncard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by
   rw [one_lt_ncard hs]
   simp only [exists_prop, exists_and_left]
 #align set.one_lt_ncard_iff Set.one_lt_ncard_iff
feat: Better lemmas for transferring finite sums along equivalences (#9237)

Lemmas around this were a mess, throth in terms of names, statement and location. This PR standardises everything to be in Algebra.BigOperators.Basic and changes the lemmas to take in InjOn and SurjOn assumptions where possible (and where impossible make sure the hypotheses are taken in the correct order) and moves the equality of functions hypothesis last.

Also add a few lemmas that help fix downstream uses by golfing.

From LeanAPAP and LeanCamCombi

Diff
@@ -804,7 +804,7 @@ theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
 #align set.surj_on_of_inj_on_of_ncard_le Set.surj_on_of_inj_on_of_ncard_le
 
 theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
-    (hsurj : ∀ b ∈ t, ∃ a ha, b = f a ha) (hst : s.ncard ≤ t.ncard) ⦃a₁ a₂⦄ (ha₁ : a₁ ∈ s)
+    (hsurj : ∀ b ∈ t, ∃ a ha, f a ha = b) (hst : s.ncard ≤ t.ncard) ⦃a₁⦄ (ha₁ : a₁ ∈ s) ⦃a₂⦄
     (ha₂ : a₂ ∈ s) (ha₁a₂ : f a₁ ha₁ = f a₂ ha₂) (hs : s.Finite := by toFinite_tac) :
     a₁ = a₂ := by
   classical
@@ -820,8 +820,8 @@ theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
   exact
     @Finset.inj_on_of_surj_on_of_card_le _ _ _ t.toFinset f''
       (fun a ha ↦ by { rw [mem_toFinset] at ha ⊢; exact hf a ha }) (by simpa)
-      (by { rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card'] }) a₁ a₂
-      (by simpa) (by simpa) (by simpa)
+      (by { rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card'] }) a₁
+      (by simpa) a₂ (by simpa) (by simpa)
 #align set.inj_on_of_surj_on_of_ncard_le Set.inj_on_of_surj_on_of_ncard_le
 
 section Lattice
chore: Improve Finset lemma names (#8894)

Change a few lemma names that have historically bothered me.

  • Finset.card_le_of_subsetFinset.card_le_card
  • Multiset.card_le_of_leMultiset.card_le_card
  • Multiset.card_lt_of_ltMultiset.card_lt_card
  • Set.ncard_le_of_subsetSet.ncard_le_ncard
  • Finset.image_filterFinset.filter_image
  • CompleteLattice.finset_sup_compact_of_compactCompleteLattice.isCompactElement_finset_sup
Diff
@@ -151,11 +151,11 @@ theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀
 
 section Lattice
 
-theorem encard_le_of_subset (h : s ⊆ t) : s.encard ≤ t.encard := by
+theorem encard_le_card (h : s ⊆ t) : s.encard ≤ t.encard := by
   rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
 
 theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) :=
-  fun _ _ ↦ encard_le_of_subset
+  fun _ _ ↦ encard_le_card
 
 theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
   rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h]
@@ -238,7 +238,7 @@ theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encar
   rw [← union_singleton, ← encard_singleton x]; apply encard_union_le
 
 theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
-  rw [← encard_singleton x]; exact encard_le_of_subset (inter_subset_left _ _)
+  rw [← encard_singleton x]; exact encard_le_card (inter_subset_left _ _)
 
 theorem encard_diff_singleton_add_one (h : a ∈ s) :
     (s \ {a}).encard + 1 = s.encard := by
@@ -395,7 +395,7 @@ theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.enc
   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
+  apply encard_le_card
   exact f.invFunOn_image_image_subset s
 
 theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) :
@@ -412,7 +412,7 @@ theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t ⊆
 
 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⟩; exact hf hx
+  rw [← f_inj.encard_image]; apply encard_le_card; rintro _ ⟨x, hx, rfl⟩; exact hf hx
 
 theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite)
     (hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by
@@ -504,13 +504,13 @@ theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by
   rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype]
 #align set.infinite.ncard Set.Infinite.ncard
 
-theorem ncard_le_of_subset (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
+theorem ncard_le_ncard (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
     s.ncard ≤ t.ncard := by
   rw [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq]
   exact encard_mono hst
-#align set.ncard_le_of_subset Set.ncard_le_of_subset
+#align set.ncard_le_of_subset Set.ncard_le_ncard
 
-theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ ncard_le_of_subset
+theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ ncard_le_ncard
 #align set.ncard_mono Set.ncard_mono
 
 @[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) :
@@ -617,7 +617,7 @@ theorem ncard_diff_singleton_lt_of_mem (h : a ∈ s) (hs : s.Finite := by toFini
 
 theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by
   obtain hs | hs := s.finite_or_infinite
-  · apply ncard_le_of_subset (diff_subset _ _) hs
+  · apply ncard_le_ncard (diff_subset _ _) hs
   convert @zero_le ℕ _ _
   exact (hs.diff (by simp : Set.Finite {a})).ncard
 #align set.ncard_diff_singleton_le Set.ncard_diff_singleton_le
@@ -693,12 +693,12 @@ theorem fiber_ncard_ne_zero_iff_mem_image {y : β} (hs : s.Finite := by toFinite
 
 theorem ncard_inter_le_ncard_left (s t : Set α) (hs : s.Finite := by toFinite_tac) :
     (s ∩ t).ncard ≤ s.ncard :=
-  ncard_le_of_subset (inter_subset_left _ _) hs
+  ncard_le_ncard (inter_subset_left _ _) hs
 #align set.ncard_inter_le_ncard_left Set.ncard_inter_le_ncard_left
 
 theorem ncard_inter_le_ncard_right (s t : Set α) (ht : t.Finite := by toFinite_tac) :
     (s ∩ t).ncard ≤ t.ncard :=
-  ncard_le_of_subset (inter_subset_right _ _) ht
+  ncard_le_ncard (inter_subset_right _ _) ht
 #align set.ncard_inter_le_ncard_right Set.ncard_inter_le_ncard_right
 
 theorem eq_of_subset_of_ncard_le (h : s ⊆ t) (h' : t.ncard ≤ s.ncard)
@@ -889,7 +889,7 @@ theorem ncard_diff_add_ncard (s t : Set α) (hs : s.Finite := by toFinite_tac)
 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]
-  exact fun h' ↦ h.not_le (ncard_le_of_subset h' hs)
+  exact fun h' ↦ h.not_le (ncard_le_ncard h' hs)
 #align set.diff_nonempty_of_ncard_lt_ncard Set.diff_nonempty_of_ncard_lt_ncard
 
 theorem exists_mem_not_mem_of_ncard_lt_ncard (h : s.ncard < t.ncard)
@@ -1111,3 +1111,11 @@ theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y 
 #align set.ncard_eq_three Set.ncard_eq_three
 
 end ncard
+
+/-!
+### Deprecated lemmas
+
+Those lemmas have been deprecated on 2023-12-27.
+-/
+
+@[deprecated] alias ncard_le_of_subset := ncard_le_ncard
chore(*): use ∃ x ∈ s, _ instead of ∃ (x) (_ : x ∈ s), _ (#9184)

Search for [∀∃].*(_ and manually replace some occurrences with more readable versions. In case of , the new expressions are defeq to the old ones. In case of , they differ by exists_prop.

In some rare cases, golf proofs that needed fixing.

Diff
@@ -1000,7 +1000,7 @@ theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s
 #align set.ncard_eq_one Set.ncard_eq_one
 
 theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
-    (∃ (a : α) (_ : a ∉ s), insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
+    (∃ 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,
feat: Ruzsa covering for sets (#8916)

Add a version covering for Set α and Nat.card.

From PFR

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>

Diff
@@ -476,7 +476,7 @@ theorem ncard_def (s : Set α) : s.ncard = ENat.toNat s.encard := rfl
 theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by
   rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not]
 
-@[simp] theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
+theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
   obtain (h | h) := s.finite_or_infinite
   · have := h.fintype
     rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card,
chore: rename by_contra' to by_contra! (#8797)

To fit with the "please try harder" convention of ! tactics.

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -307,7 +307,7 @@ theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a
   rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop
 
 theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by
-  by_contra' h'
+  by_contra! h'
   obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h
   apply hne
   rw [h' b hb, h' b' hb']
chore: space after (#8178)

Co-authored-by: Moritz Firsching <firsching@google.com>

Diff
@@ -86,11 +86,11 @@ theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.c
 
 theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by
   have := h.to_subtype
-  rw [encard, ←PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
+  rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
     PartENat.withTopEquiv_symm_top, PartENat.card_eq_top_of_infinite]
 
 @[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by
-  rw [encard, ←PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
+  rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
     PartENat.withTopEquiv_symm_zero, PartENat.card_eq_zero_iff_empty, isEmpty_subtype,
     eq_empty_iff_forall_not_mem]
 
@@ -98,7 +98,7 @@ theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by
   rw [encard_eq_zero]
 
 theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by
-  rwa [nonempty_iff_ne_empty, Ne.def, ←encard_eq_zero]
+  rwa [nonempty_iff_ne_empty, Ne.def, ← encard_eq_zero]
 
 theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by
   rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty]
@@ -107,16 +107,16 @@ theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by
   rw [pos_iff_ne_zero, encard_ne_zero]
 
 @[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by
-  rw [encard, ←PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
+  rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
     PartENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]; rfl
 
 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
-  simp [encard, ←PartENat.card_congr e, PartENat.card_sum, PartENat.withTopEquiv]
+  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_insert_of_not_mem (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
-  rw [←union_singleton, encard_union_eq (by simpa), encard_singleton]
+  rw [← union_singleton, encard_union_eq (by simpa), encard_singleton]
 
 theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
   refine' h.induction_on (by simp) _
@@ -134,13 +134,13 @@ theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n
   ⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩
 
 @[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by
-  rw [←not_iff_not, ←Ne.def, ←lt_top_iff_ne_top, encard_lt_top_iff, not_infinite]
+  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
   simp
 
 theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by
-  rw [←encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _)
+  rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _)
 
 theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite :=
   finite_of_encard_le_coe h.le
@@ -152,25 +152,25 @@ theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀
 section Lattice
 
 theorem encard_le_of_subset (h : s ⊆ t) : s.encard ≤ t.encard := by
-  rw [←union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
+  rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
 
 theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) :=
   fun _ _ ↦ encard_le_of_subset
 
 theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
-  rw [←encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h]
+  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
-  rw [nonempty_iff_ne_empty, Ne.def, ←encard_eq_zero, ENat.one_le_iff_ne_zero]
+  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
-  rw [←encard_union_eq (disjoint_of_subset_right (inter_subset_right _ _) disjoint_sdiff_left),
+  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 rw [←diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm,
+by 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) :
@@ -189,13 +189,13 @@ theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) :
     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
-  rw [←encard_union_add_encard_inter]; exact le_self_add
+  rw [← encard_union_add_encard_inter]; exact le_self_add
 
 theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by
-  rw [←encard_lt_top_iff, ←encard_lt_top_iff, h]
+  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 rw [←encard_eq_top_iff, h, encard_eq_top_iff]
+    s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff]
 
 theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite)
     (h : t.encard ≤ s.encard) : t.Finite :=
@@ -203,7 +203,7 @@ theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite)
 
 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
+  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
   exact hst.antisymm hdiff
@@ -219,7 +219,7 @@ theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞)
   fun _ _ h ↦ (toFinite _).encard_lt_encard h
 
 theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by
-  rw [←encard_union_eq disjoint_sdiff_left, diff_union_self]
+  rw [← encard_union_eq disjoint_sdiff_left, diff_union_self]
 
 theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard :=
   (encard_mono (subset_union_left s t)).trans_eq (encard_diff_add_encard _ _).symm
@@ -228,44 +228,44 @@ theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \
   rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard
 
 theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by
-  rw [←encard_union_eq disjoint_compl_right, union_compl_self]
+  rw [← encard_union_eq disjoint_compl_right, union_compl_self]
 
 end Lattice
 
 section InsertErase
 
 theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
-  rw [←union_singleton, ←encard_singleton x]; apply encard_union_le
+  rw [← union_singleton, ← encard_singleton x]; apply encard_union_le
 
 theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
-  rw [←encard_singleton x]; exact encard_le_of_subset (inter_subset_left _ _)
+  rw [← encard_singleton x]; exact encard_le_of_subset (inter_subset_left _ _)
 
 theorem encard_diff_singleton_add_one (h : a ∈ s) :
     (s \ {a}).encard + 1 = s.encard := by
-  rw [←encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h]
+  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
-  rw [←encard_diff_singleton_add_one h, ←WithTop.add_right_cancel_iff WithTop.one_ne_top,
+  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
-  rw [←encard_singleton x]; apply tsub_encard_le_encard_diff
+  rw [← encard_singleton x]; apply tsub_encard_le_encard_diff
 
 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]
   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
-  rw [←insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb]
+  rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange 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
   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,
+    rw [← WithTop.add_right_cancel_iff WithTop.one_ne_top, ← h,
       encard_diff_singleton_add_one ha]
   rintro ⟨a, t, h, rfl, rfl⟩
   rw [encard_insert_of_not_mem h]
@@ -276,7 +276,7 @@ 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 _)]
+  rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)]
   exact WithTop.add_lt_add_left (hfin.diff _).encard_lt_top.ne zero_lt_one
 
 end InsertErase
@@ -284,7 +284,7 @@ end InsertErase
 section SmallSets
 
 theorem encard_pair (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
-  rw [encard_insert_of_not_mem (by simpa), ←one_add_one_eq_two,
+  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_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
@@ -297,14 +297,14 @@ theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} :=
     encard_eq_one]
 
 theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by
-  rw [encard_le_one_iff_eq, or_iff_not_imp_left, ←Ne.def, ←nonempty_iff_ne_empty]
+  rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne.def, ← nonempty_iff_ne_empty]
   refine' ⟨fun h a b has hbs ↦ _,
     fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩
   obtain ⟨x, rfl⟩ := h ⟨_, has⟩
   rw [(has : a = x), (hbs : b = x)]
 
 theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by
-  rw [←not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop
+  rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop
 
 theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by
   by_contra' h'
@@ -315,24 +315,24 @@ theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b
 theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
   refine' ⟨fun h ↦ _, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩
   obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
-  rw [←insert_eq_of_mem hx, ←insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl),
-    ←one_add_one_eq_two, WithTop.add_right_cancel_iff (WithTop.one_ne_top), encard_eq_one] at h
+  rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl),
+    ← one_add_one_eq_two, WithTop.add_right_cancel_iff (WithTop.one_ne_top), encard_eq_one] at h
   obtain ⟨y, h⟩ := h
   refine' ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, _⟩
-  rw [←h, insert_diff_singleton, insert_eq_of_mem hx]
+  rw [← h, insert_diff_singleton, insert_eq_of_mem hx]
 
 theorem encard_eq_three {α : Type u_1} {s : Set α} :
     encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
   refine' ⟨fun h ↦ _, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ _⟩
   · obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
-    rw [←insert_eq_of_mem hx, ←insert_diff_singleton,
+    rw [← insert_eq_of_mem hx, ← insert_diff_singleton,
       encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1),
       WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_eq_two] at h
     obtain ⟨y, z, hne, hs⟩ := h
     refine' ⟨x, y, z, _, _, hne, _⟩
     · rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl
     · rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl
-    rw [←hs, insert_diff_singleton, insert_eq_of_mem hx]
+    rw [← hs, insert_diff_singleton, insert_eq_of_mem hx]
   rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop
 
 theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by
@@ -344,9 +344,9 @@ end SmallSets
 
 theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t)
     (hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by
-  rw [←encard_diff_add_encard_of_subset h, add_comm,
+  rw [← encard_diff_add_encard_of_subset h, add_comm,
     WithTop.add_left_cancel_iff hs.encard_lt_top.ne, encard_eq_one] at hst
-  obtain ⟨x, hx⟩ := hst; use x; rw [←diff_union_of_subset h, hx, singleton_union]
+  obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union]
 
 theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
   revert hk
@@ -354,7 +354,7 @@ theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.enc
   · 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
+    · 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]
@@ -367,7 +367,7 @@ theorem exists_superset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k)
   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
+  · 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 _ _)), _⟩
@@ -381,20 +381,20 @@ theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by
   rw [encard, PartENat.card_image_of_injOn h, encard]
 
 theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by
-  rw [←encard_univ_coe, ←encard_univ_coe t, encard_univ, encard_univ, PartENat.card_congr e]
+  rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, PartENat.card_congr e]
 
 theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) :
     (f '' s).encard = s.encard :=
   (hf.injOn s).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]
+  rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image]
   exact encard_mono (by 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
-  rw [←(f.invFunOn_injOn_image s).encard_image]
+  rw [← (f.invFunOn_injOn_image s).encard_image]
   apply encard_le_of_subset
   exact f.invFunOn_image_image_subset s
 
@@ -402,17 +402,17 @@ theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s
     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 [← (f.invFunOn_injOn_image s).encard_image] at h
   rw [injOn_iff_invFunOn_image_image_eq_self]
   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
-  rw [←hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht]
+  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
-  rw [←f_inj.encard_image]; apply encard_le_of_subset; rintro _ ⟨x, hx, rfl⟩; exact hf hx
+  rw [← f_inj.encard_image]; apply encard_le_of_subset; rintro _ ⟨x, hx, rfl⟩; exact hf hx
 
 theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite)
     (hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by
@@ -422,14 +422,14 @@ theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β}
   · exact (encard_ne_top_iff.mpr hs h).elim
   obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle)
   have hle' : (s \ {a}).encard ≤ (t \ {b}).encard
-  · rwa [←WithTop.add_le_add_iff_right WithTop.one_ne_top,
+  · rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top,
     encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt]
 
   obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le (hs.diff {a}) hle'
   simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hf₀s
 
   use Function.update f₀ a b
-  rw [←insert_eq_of_mem has, ←insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)]
+  rw [← insert_eq_of_mem has, ← insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)]
   simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def,
     mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp,
     mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt]
@@ -464,7 +464,7 @@ syntax "to_encard_tac" : tactic
 
 macro_rules
   | `(tactic| to_encard_tac) => `(tactic|
-      simp only [←Nat.cast_le (α := ℕ∞), ←Nat.cast_inj (R := ℕ∞), Nat.cast_add, Nat.cast_one])
+      simp only [← Nat.cast_le (α := ℕ∞), ← Nat.cast_inj (R := ℕ∞), Nat.cast_add, Nat.cast_one])
 
 
 /-- The cardinality of `s : Set α` . Has the junk value `0` if `s` is infinite -/
@@ -487,13 +487,13 @@ theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by
 
 theorem ncard_eq_toFinset_card (s : Set α) (hs : s.Finite := by toFinite_tac) :
     s.ncard = hs.toFinset.card := by
-  rw [←Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype,
+  rw [← Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype,
     @Finite.card_toFinset _ _ hs.fintype hs]
 #align set.ncard_eq_to_finset_card Set.ncard_eq_toFinset_card
 
 theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] :
     s.ncard = s.toFinset.card := by
-  simp [←Nat.card_coe_set_eq, Nat.card_eq_fintype_card]
+  simp [← Nat.card_coe_set_eq, Nat.card_eq_fintype_card]
 
 theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by
   rw [encard_le_coe_iff, and_congr_right_iff]
@@ -501,12 +501,12 @@ theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finit
     fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩
 
 theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by
-  rw [←Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype]
+  rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype]
 #align set.infinite.ncard Set.Infinite.ncard
 
 theorem ncard_le_of_subset (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
     s.ncard ≤ t.ncard := by
-  rw [←Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq]
+  rw [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq]
   exact encard_mono hst
 #align set.ncard_le_of_subset Set.ncard_le_of_subset
 
@@ -515,7 +515,7 @@ theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ n
 
 @[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) :
     s.ncard = 0 ↔ s = ∅ := by
-  rw [←Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero]
+  rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero]
 #align set.ncard_eq_zero Set.ncard_eq_zero
 
 @[simp] theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by
@@ -559,14 +559,14 @@ theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by
 #align set.ncard_singleton Set.ncard_singleton
 
 theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 := by
-  rw [←Nat.cast_le (α := ℕ∞), (toFinite _).cast_ncard_eq, Nat.cast_one]
+  rw [← Nat.cast_le (α := ℕ∞), (toFinite _).cast_ncard_eq, Nat.cast_one]
   apply encard_singleton_inter
 #align set.ncard_singleton_inter Set.ncard_singleton_inter
 section InsertErase
 
 @[simp] theorem ncard_insert_of_not_mem (h : a ∉ s) (hs : s.Finite := by toFinite_tac) :
     (insert a s).ncard = s.ncard + 1 := by
-  rw [←Nat.cast_inj (R := ℕ∞), (hs.insert a).cast_ncard_eq, Nat.cast_add, Nat.cast_one,
+  rw [← Nat.cast_inj (R := ℕ∞), (hs.insert a).cast_ncard_eq, Nat.cast_add, Nat.cast_one,
     hs.cast_ncard_eq, encard_insert_of_not_mem h]
 #align set.ncard_insert_of_not_mem Set.ncard_insert_of_not_mem
 
@@ -653,7 +653,7 @@ theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard :=
 
 theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard) (hs : s.Finite := by toFinite_tac) :
     Set.InjOn f s := by
-  rw [←Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, (hs.image _).cast_ncard_eq] at h
+  rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, (hs.image _).cast_ncard_eq] at h
   exact hs.injOn_of_encard_image_eq h
 #align set.inj_on_of_ncard_image_eq Set.injOn_of_ncard_image_eq
 
@@ -688,7 +688,7 @@ theorem fiber_ncard_ne_zero_iff_mem_image {y : β} (hs : s.Finite := by toFinite
     { x : Subtype P | (x : α) ∈ s }.ncard = (s ∩ setOf P).ncard := by
   convert (ncard_image_of_injective _ (@Subtype.coe_injective _ P)).symm
   ext x
-  simp [←and_assoc, exists_eq_right]
+  simp [← and_assoc, exists_eq_right]
 #align set.ncard_subtype Set.ncard_subtype
 
 theorem ncard_inter_le_ncard_left (s t : Set α) (hs : s.Finite := by toFinite_tac) :
@@ -704,7 +704,7 @@ theorem ncard_inter_le_ncard_right (s t : Set α) (ht : t.Finite := by toFinite_
 theorem eq_of_subset_of_ncard_le (h : s ⊆ t) (h' : t.ncard ≤ s.ncard)
     (ht : t.Finite := by toFinite_tac) : s = t :=
   ht.eq_of_subset_of_encard_le h
-    (by rwa [←Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq] at h')
+    (by rwa [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq] at h')
 #align set.eq_of_subset_of_ncard_le Set.eq_of_subset_of_ncard_le
 
 theorem subset_iff_eq_of_ncard_le (h : t.ncard ≤ s.ncard) (ht : t.Finite := by toFinite_tac) :
@@ -724,7 +724,7 @@ theorem sep_of_ncard_eq {P : α → Prop} (h : { x ∈ s | P x }.ncard = s.ncard
 
 theorem ncard_lt_ncard (h : s ⊂ t) (ht : t.Finite := by toFinite_tac) :
     s.ncard < t.ncard := by
-  rw [←Nat.cast_lt (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h.subset).cast_ncard_eq]
+  rw [← Nat.cast_lt (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h.subset).cast_ncard_eq]
   exact ht.encard_lt_encard h
 #align set.ncard_lt_ncard Set.ncard_lt_ncard
 
@@ -755,7 +755,7 @@ theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha
     obtain ⟨a, ha, rfl⟩ := h₃ y hy
     simp only [Subtype.mk.injEq, Subtype.exists]
     exact ⟨_, ha, rfl⟩
-  simp_rw [←Nat.card_coe_set_eq]
+  simp_rw [← Nat.card_coe_set_eq]
   exact Nat.card_congr (Equiv.ofBijective f' hbij)
 #align set.ncard_congr Set.ncard_congr
 
@@ -800,7 +800,7 @@ theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
   · intros a₁ a₂ ha₁ ha₂ h
     rw [mem_toFinset] at ha₁ ha₂
     exact hinj _ _ ha₁ ha₂ h
-  rwa [←ncard_eq_toFinset_card', ←ncard_eq_toFinset_card']
+  rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card']
 #align set.surj_on_of_inj_on_of_ncard_le Set.surj_on_of_inj_on_of_ncard_le
 
 theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
@@ -820,7 +820,7 @@ theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
   exact
     @Finset.inj_on_of_surj_on_of_card_le _ _ _ t.toFinset f''
       (fun a ha ↦ by { rw [mem_toFinset] at ha ⊢; exact hf a ha }) (by simpa)
-      (by { rwa [←ncard_eq_toFinset_card', ←ncard_eq_toFinset_card'] }) a₁ a₂
+      (by { rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card'] }) a₁ a₂
       (by simpa) (by simpa) (by simpa)
 #align set.inj_on_of_surj_on_of_ncard_le Set.inj_on_of_surj_on_of_ncard_le
 
@@ -883,7 +883,7 @@ theorem le_ncard_diff (s t : Set α) (hs : s.Finite := by toFinite_tac) :
 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
-  rw [←ncard_union_eq disjoint_sdiff_left (hs.diff _) ht, diff_union_self]
+  rw [← ncard_union_eq disjoint_sdiff_left (hs.diff _) ht, diff_union_self]
 #align set.ncard_diff_add_ncard Set.ncard_diff_add_ncard
 
 theorem diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.Finite := by toFinite_tac) :
@@ -899,7 +899,7 @@ theorem exists_mem_not_mem_of_ncard_lt_ncard (h : s.ncard < t.ncard)
 
 @[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
-  rw [←ncard_union_eq (disjoint_of_subset_left (inter_subset_right _ _) disjoint_sdiff_right)
+  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]
 #align set.ncard_inter_add_ncard_diff_eq_ncard Set.ncard_inter_add_ncard_diff_eq_ncard
 
@@ -1004,7 +1004,7 @@ theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
   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]
+      ← @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]
@@ -1097,14 +1097,14 @@ theorem ncard_eq_succ {n : ℕ} (hs : s.Finite := by toFinite_tac) :
 #align set.ncard_eq_succ Set.ncard_eq_succ
 
 theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
-  rw [←encard_eq_two, ncard_def, ←Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
+  rw [← encard_eq_two, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
   refine' ⟨fun h ↦ _, fun h ↦ _⟩
   · rwa [ENat.coe_toNat] at h; rintro h'; simp [h'] at h
   rw [h]; rfl
 #align set.ncard_eq_two Set.ncard_eq_two
 
 theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
-  rw [←encard_eq_three, ncard_def, ←Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
+  rw [← encard_eq_three, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
   refine' ⟨fun h ↦ _, fun h ↦ _⟩
   · rwa [ENat.coe_toNat] at h; rintro h'; simp [h'] at h
   rw [h]; rfl
chore: bump to v4.3.0-rc2 (#8366)

PR contents

This is the supremum of

along with some minor fixes from failures on nightly-testing as Mathlib master is merged into it.

Note that some PRs for changes that are already compatible with the current toolchain and will be necessary have already been split out: #8380.

I am hopeful that in future we will be able to progressively merge adaptation PRs into a bump/v4.X.0 branch, so we never end up with a "big merge" like this. However one of these adaptation PRs (#8056) predates my new scheme for combined CI, and it wasn't possible to keep that PR viable in the meantime.

Lean PRs involved in this bump

In particular this includes adjustments for the Lean PRs

leanprover/lean4#2778

We can get rid of all the

local macro_rules | `($x ^ $y) => `(HPow.hPow $x $y) -- Porting note: See issue [lean4#2220](https://github.com/leanprover/lean4/pull/2220)

macros across Mathlib (and in any projects that want to write natural number powers of reals).

leanprover/lean4#2722

Changes the default behaviour of simp to (config := {decide := false}). This makes simp (and consequentially norm_num) less powerful, but also more consistent, and less likely to blow up in long failures. This requires a variety of changes: changing some previously by simp or norm_num to decide or rfl, or adding (config := {decide := true}).

leanprover/lean4#2783

This changed the behaviour of simp so that simp [f] will only unfold "fully applied" occurrences of f. The old behaviour can be recovered with simp (config := { unfoldPartialApp := true }). We may in future add a syntax for this, e.g. simp [!f]; please provide feedback! In the meantime, we have made the following changes:

  • switching to using explicit lemmas that have the intended level of application
  • (config := { unfoldPartialApp := true }) in some places, to recover the old behaviour
  • Using @[eqns] to manually adjust the equation lemmas for a particular definition, recovering the old behaviour just for that definition. See #8371, where we do this for Function.comp and Function.flip.

This change in Lean may require further changes down the line (e.g. adding the !f syntax, and/or upstreaming the special treatment for Function.comp and Function.flip, and/or removing this special treatment). Please keep an open and skeptical mind about these changes!

Co-authored-by: leanprover-community-mathlib4-bot <leanprover-community-mathlib4-bot@users.noreply.github.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Mauricio Collares <mauricio@collares.org>

Diff
@@ -555,7 +555,7 @@ theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by
 #align set.nonempty_of_ncard_ne_zero Set.nonempty_of_ncard_ne_zero
 
 @[simp] theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by
-  simp [ncard_eq_toFinset_card]
+  simp [ncard, ncard_eq_toFinset_card]
 #align set.ncard_singleton Set.ncard_singleton
 
 theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 := by
chore: make sure all #align's are on a single line (#8215)

We'll need to do this step anyway when it is time to remove them all.

(See #8214 where I'm benchmarking the removal.)

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -985,8 +985,7 @@ theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s
       (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'⟩
-#align set.exists_subset_or_subset_of_two_mul_lt_ncard
-  Set.exists_subset_or_subset_of_two_mul_lt_ncard
+#align set.exists_subset_or_subset_of_two_mul_lt_ncard Set.exists_subset_or_subset_of_two_mul_lt_ncard
 
 /-! ### Explicit description of a set from its cardinality -/
 
fix: make sure types of Set.encard and Set.ncard are beta reduced (#8044)
Diff
@@ -63,7 +63,7 @@ namespace Set
 variable {s t : Set α}
 
 /-- The cardinality of a set as a term in `ℕ∞` -/
-noncomputable def encard (s : Set α) := PartENat.withTopEquiv (PartENat.card s)
+noncomputable def encard (s : Set α) : ℕ∞ := PartENat.withTopEquiv (PartENat.card s)
 
 @[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by
   rw [encard, encard, PartENat.card_congr (Equiv.Set.univ ↑s)]
@@ -119,7 +119,7 @@ theorem encard_insert_of_not_mem (has : a ∉ s) : (insert a s).encard = s.encar
   rw [←union_singleton, encard_union_eq (by simpa), encard_singleton]
 
 theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
-  refine' h.induction_on (by simpa using WithTop.zero_lt_top) _
+  refine' h.induction_on (by simp) _
   rintro a t hat _ ht'
   rw [encard_insert_of_not_mem hat]
   exact lt_tsub_iff_right.1 ht'
@@ -468,8 +468,7 @@ macro_rules
 
 
 /-- The cardinality of `s : Set α` . Has the junk value `0` if `s` is infinite -/
-noncomputable def ncard (s : Set α) :=
-  ENat.toNat s.encard
+noncomputable def ncard (s : Set α) : ℕ := ENat.toNat s.encard
 #align set.ncard Set.ncard
 
 theorem ncard_def (s : Set α) : s.ncard = ENat.toNat s.encard := rfl
chore: swap primes on forall_apply_eq_imp_iff (#7705)

Two pairs of the form foo and foo', where foo' is the simp lemma (and hence used in many simp onlys) and foo is not used at all.

Swap the primes, so that when it is time (now!) to upstream the lemma we actually use, it doesn't need to have a prime...

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -1035,7 +1035,7 @@ theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
   rintro (rfl | ⟨a, rfl⟩)
   · exact (not_mem_empty _ hx).elim
   simp_rw [mem_singleton_iff] at hx ⊢; subst hx
-  simp only [forall_eq_apply_imp_iff', imp_self, implies_true]
+  simp only [forall_eq_apply_imp_iff, imp_self, implies_true]
 #align set.ncard_le_one_iff_eq Set.ncard_le_one_iff_eq
 
 theorem ncard_le_one_iff_subset_singleton [Nonempty α]
chore: exactly 4 spaces in theorems (#7328)

Co-authored-by: Moritz Firsching <firsching@google.com>

Diff
@@ -668,7 +668,7 @@ theorem ncard_image_of_injective (s : Set α) (H : f.Injective) : (f '' s).ncard
 #align set.ncard_image_of_injective Set.ncard_image_of_injective
 
 theorem ncard_preimage_of_injective_subset_range {s : Set β} (H : f.Injective)
-  (hs : s ⊆ Set.range f) :
+    (hs : s ⊆ Set.range f) :
     (f ⁻¹' s).ncard = s.ncard := by
   rw [← ncard_image_of_injective _ H, image_preimage_eq_iff.mpr hs]
 #align set.ncard_preimage_of_injective_subset_range Set.ncard_preimage_of_injective_subset_range
@@ -768,7 +768,7 @@ theorem ncard_le_ncard_of_injOn {t : Set β} (f : α → β) (hf : ∀ a ∈ s,
 #align set.ncard_le_ncard_of_inj_on Set.ncard_le_ncard_of_injOn
 
 theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.ncard) {f : α → β}
-  (hf : ∀ a ∈ s, f a ∈ t) (ht : t.Finite := by toFinite_tac) :
+    (hf : ∀ a ∈ s, f a ∈ t) (ht : t.Finite := by toFinite_tac) :
     ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ f x = f y := by
   by_contra h'
   simp only [Ne.def, exists_prop, not_exists, not_and, not_imp_not] at h'
@@ -776,15 +776,15 @@ theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.n
 #align set.exists_ne_map_eq_of_ncard_lt_of_maps_to Set.exists_ne_map_eq_of_ncard_lt_of_maps_to
 
 theorem le_ncard_of_inj_on_range {n : ℕ} (f : ℕ → α) (hf : ∀ i < n, f i ∈ s)
-  (f_inj : ∀ i < n, ∀ j < n, f i = f j → i = j) (hs : s.Finite := by toFinite_tac) :
+    (f_inj : ∀ i < n, ∀ j < n, f i = f j → i = j) (hs : s.Finite := by toFinite_tac) :
     n ≤ s.ncard := by
   rw [ncard_eq_toFinset_card _ hs]
   apply Finset.le_card_of_inj_on_range <;> simpa
 #align set.le_ncard_of_inj_on_range Set.le_ncard_of_inj_on_range
 
 theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
-  (hinj : ∀ a₁ a₂ ha₁ ha₂, f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂) (hst : t.ncard ≤ s.ncard)
-  (ht : t.Finite := by toFinite_tac) :
+    (hinj : ∀ a₁ a₂ ha₁ ha₂, f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂) (hst : t.ncard ≤ s.ncard)
+    (ht : t.Finite := by toFinite_tac) :
     ∀ b ∈ t, ∃ a ha, b = f a ha := by
   intro b hb
   set f' : s → t := fun x ↦ ⟨f x.1 x.2, hf _ _⟩
@@ -894,7 +894,7 @@ theorem diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.Finite :
 #align set.diff_nonempty_of_ncard_lt_ncard Set.diff_nonempty_of_ncard_lt_ncard
 
 theorem exists_mem_not_mem_of_ncard_lt_ncard (h : s.ncard < t.ncard)
-  (hs : s.Finite := by toFinite_tac) : ∃ e, e ∈ t ∧ e ∉ s :=
+    (hs : s.Finite := by toFinite_tac) : ∃ e, e ∈ t ∧ e ∉ s :=
   diff_nonempty_of_ncard_lt_ncard h hs
 #align set.exists_mem_not_mem_of_ncard_lt_ncard Set.exists_mem_not_mem_of_ncard_lt_ncard
 
@@ -1039,7 +1039,7 @@ theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
 #align set.ncard_le_one_iff_eq Set.ncard_le_one_iff_eq
 
 theorem ncard_le_one_iff_subset_singleton [Nonempty α]
-  (hs : s.Finite := by toFinite_tac) :
+    (hs : s.Finite := by toFinite_tac) :
     s.ncard ≤ 1 ↔ ∃ x : α, s ⊆ {x} := by
   simp_rw [ncard_eq_toFinset_card _ hs, Finset.card_le_one_iff_subset_singleton,
     Finite.toFinset_subset, Finset.coe_singleton]
chore: tidy various files (#7132)
Diff
@@ -283,7 +283,7 @@ end InsertErase
 
 section SmallSets
 
-theorem encard_pair (hne : x ≠ y) : ({x,y} : Set α).encard = 2 := by
+theorem encard_pair (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
   rw [encard_insert_of_not_mem (by simpa), ←one_add_one_eq_two,
     WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_singleton]
 
@@ -308,11 +308,11 @@ theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a
 
 theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by
   by_contra' h'
-  obtain ⟨b,b',hb,hb',hne⟩ := one_lt_encard_iff.1 h
+  obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h
   apply hne
   rw [h' b hb, h' b' hb']
 
-theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x,y} := by
+theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
   refine' ⟨fun h ↦ _, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩
   obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
   rw [←insert_eq_of_mem hx, ←insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl),
@@ -328,8 +328,8 @@ theorem encard_eq_three {α : Type u_1} {s : Set α} :
     rw [←insert_eq_of_mem hx, ←insert_diff_singleton,
       encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1),
       WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_eq_two] at h
-    obtain ⟨y,z,hne, hs⟩ := h
-    refine' ⟨x,y,z, _, _, hne, _⟩
+    obtain ⟨y, z, hne, hs⟩ := h
+    refine' ⟨x, y, z, _, _, hne, _⟩
     · rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl
     · rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl
     rw [←hs, insert_diff_singleton, insert_eq_of_mem hx]
@@ -360,7 +360,7 @@ theorem exists_subset_encard_eq (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.enc
   simp only [top_le_iff, encard_eq_top_iff]
   exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩
 
-theorem exists_supset_subset_encard_eq (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.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 ⊤
   · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
@@ -434,7 +434,7 @@ theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β}
     mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp,
     mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt]
 
-  refine ⟨?_,?_,fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩
+  refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩
   · rintro x hx; split_ifs with h; assumption; exact (hf₀s x hx h).1
   exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_noteq])
 termination_by _ => encard s
@@ -908,22 +908,19 @@ theorem ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff (hs : s.Finite := by toFinit
     (ht : t.Finite := by toFinite_tac) : s.ncard = t.ncard ↔ (s \ t).ncard = (t \ s).ncard := by
   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]
-#align set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff
-  Set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff
+#align set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff Set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff
 
 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
   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]
-#align set.ncard_le_ncard_iff_ncard_diff_le_ncard_diff
-  Set.ncard_le_ncard_iff_ncard_diff_le_ncard_diff
+#align set.ncard_le_ncard_iff_ncard_diff_le_ncard_diff Set.ncard_le_ncard_iff_ncard_diff_le_ncard_diff
 
 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
   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]
-#align set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
-  Set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
+#align set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff Set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
 
 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
@@ -972,13 +969,13 @@ theorem Infinite.exists_subset_ncard_eq {s : Set α} (hs : s.Infinite) (k : ℕ)
   simp
 #align set.Infinite.exists_subset_ncard_eq Set.Infinite.exists_subset_ncard_eq
 
-theorem Infinite.exists_supset_ncard_eq {s t : Set α} (ht : t.Infinite) (hst : s ⊆ t)
+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 _ _)), _⟩
   rwa [ncard_union_eq (disjoint_of_subset_right hs₁ disjoint_sdiff_right) hs hs₁fin, hs₁card,
     add_tsub_cancel_of_le]
-#align set.infinite.exists_supset_ncard_eq Set.Infinite.exists_supset_ncard_eq
+#align set.infinite.exists_supset_ncard_eq Set.Infinite.exists_superset_ncard_eq
 
 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
@@ -1105,14 +1102,14 @@ theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
   rw [←encard_eq_two, ncard_def, ←Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
   refine' ⟨fun h ↦ _, fun h ↦ _⟩
   · rwa [ENat.coe_toNat] at h; rintro h'; simp [h'] at h
-  simp [h]; exact Iff.mp ENat.coe_toNat_eq_self rfl
+  rw [h]; rfl
 #align set.ncard_eq_two Set.ncard_eq_two
 
 theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
   rw [←encard_eq_three, ncard_def, ←Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
   refine' ⟨fun h ↦ _, fun h ↦ _⟩
   · rwa [ENat.coe_toNat] at h; rintro h'; simp [h'] at h
-  simp [h]; exact Iff.mp ENat.coe_toNat_eq_self rfl
+  rw [h]; rfl
 #align set.ncard_eq_three Set.ncard_eq_three
 
 end ncard
chore: remove unused simps (#6632)

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>

Diff
@@ -794,7 +794,6 @@ theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
     apply hinj _ _ hx hy hxy
   have hft := ht.fintype
   have hft' := Fintype.ofInjective f' finj
-  simp_rw [ncard_eq_toFinset_card] at hst
   set f'' : ∀ a, a ∈ s.toFinset → β := fun a h ↦ f a (by simpa using h)
   convert @Finset.surj_on_of_inj_on_of_card_le _ _ _ t.toFinset f'' _ _ _ _ (by simpa)
   · simp
@@ -818,7 +817,6 @@ theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
     exact ⟨_, ha, rfl⟩
   haveI := hs.fintype
   haveI := Fintype.ofSurjective _ hsurj
-  simp_rw [ncard_eq_toFinset_card] at hst
   set f'' : ∀ a, a ∈ s.toFinset → β := fun a h ↦ f a (by simpa using h)
   exact
     @Finset.inj_on_of_surj_on_of_card_le _ _ _ t.toFinset f''
fix: disable autoImplicit globally (#6528)

Autoimplicits are highly controversial and also defeat the performance-improving work in #6474.

The intent of this PR is to make autoImplicit opt-in on a per-file basis, by disabling it in the lakefile and enabling it again with set_option autoImplicit true in the few files that rely on it.

That also keeps this PR small, as opposed to attempting to "fix" files to not need it any more.

I claim that many of the uses of autoImplicit in these files are accidental; situations such as:

  • Assuming variables are in scope, but pasting the lemma in the wrong section
  • Pasting in a lemma from a scratch file without checking to see if the variable names are consistent with the rest of the file
  • Making a copy-paste error between lemmas and forgetting to add an explicit arguments.

Having set_option autoImplicit false as the default prevents these types of mistake being made in the 90% of files where autoImplicits are not used at all, and causes them to be caught by CI during review.

I think there were various points during the port where we encouraged porters to delete the universes u v lines; I think having autoparams for universe variables only would cover a lot of the cases we actually use them, while avoiding any real shortcomings.

A Zulip poll (after combining overlapping votes accordingly) was in favor of this change with 5:5:18 as the no:dontcare:yes vote ratio.

While this PR was being reviewed, a handful of files gained some more likely-accidental autoImplicits. In these places, set_option autoImplicit true has been placed locally within a section, rather than at the top of the file.

Diff
@@ -56,6 +56,8 @@ the other inside the proof. A few of the theorems, such as `ncard_union_le` do n
 finiteness arguments; they are true by coincidence due to junk values.
 -/
 
+set_option autoImplicit true
+
 namespace Set
 
 variable {s t : Set α}
chore: banish Type _ and Sort _ (#6499)

We remove all possible occurences of Type _ and Sort _ in favor of Type* and Sort*.

This has nice performance benefits.

Diff
@@ -66,7 +66,7 @@ noncomputable def encard (s : Set α) := PartENat.withTopEquiv (PartENat.card s)
 @[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by
   rw [encard, encard, PartENat.card_congr (Equiv.Set.univ ↑s)]
 
-theorem encard_univ (α : Type _) :
+theorem encard_univ (α : Type*) :
     encard (univ : Set α) = PartENat.withTopEquiv (PartENat.card α) := by
   rw [encard, PartENat.card_congr (Equiv.Set.univ α)]
 
@@ -152,7 +152,7 @@ section Lattice
 theorem encard_le_of_subset (h : s ⊆ t) : s.encard ≤ t.encard := by
   rw [←union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
 
-theorem encard_mono {α : Type _} : Monotone (encard : Set α → ℕ∞) :=
+theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) :=
   fun _ _ ↦ encard_le_of_subset
 
 theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
@@ -521,7 +521,7 @@ theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ n
   rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset]
 #align set.ncard_coe_finset Set.ncard_coe_Finset
 
-theorem ncard_univ (α : Type _) : (univ : Set α).ncard = Nat.card α := by
+theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by
   cases' finite_or_infinite α with h h
   · have hft := Fintype.ofFinite α
     rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card]
@@ -529,7 +529,7 @@ theorem ncard_univ (α : Type _) : (univ : Set α).ncard = Nat.card α := by
   exact infinite_univ
 #align set.ncard_univ Set.ncard_univ
 
-@[simp] theorem ncard_empty (α : Type _) : (∅ : Set α).ncard = 0 := by
+@[simp] theorem ncard_empty (α : Type*) : (∅ : Set α).ncard = 0 := by
   rw [ncard_eq_zero]
 #align set.ncard_empty Set.ncard_empty
 
feat(Data.Set.Ncard): enat set cardinality (#5908)

This PR is a second attempt at defining the cardinality of a set as extended natural number, with a function encard. The implementation involves a refactor, where the existingncard function is redefined in terms of encard. This shortens a lot of proofs, reduces reliance on the Finset API, and allows for a potential future refactor where ncard is removed if it is decided to be redundant.

Co-authored-by: Jireh Loreaux <loreaujy@gmail.com>

Diff
@@ -4,25 +4,34 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Peter Nelson
 -/
 import Mathlib.Data.Finite.Card
-import Mathlib.Algebra.BigOperators.Finprod
 
 #align_import data.set.ncard from "leanprover-community/mathlib"@"74c2af38a828107941029b03839882c5c6f87a04"
 
 /-!
 # Noncomputable Set Cardinality
 
-We define the cardinality `Set.ncard s` of a set `s` as a natural number. This function is
-noncomputable (being defined in terms of `Nat.card`) and takes the value `0` if `s` is Infinite.
+We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`.
+The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and
+are defined in terms of `PartENat.card` (which takes a type as its argument); this file can be seen
+as an API for the same function in the special case where the type is a coercion of a `Set`,
+allowing for smoother interactions with the `Set` API.
 
-This can be seen as an API for `Nat.card α` in the special case where `α` is a subtype arising from
-a set. It is intended as an alternative to `Finset.card` and `Fintype.card`,  both of which contain
-data in their definition that can cause awkwardness when using `Set.toFinset`.  Using `Set.ncard`
-allows cardinality computations to avoid `Finset`/`Fintype` completely, staying in `Set` and letting
-Finiteness be handled explicitly, or (where a `Finite α` instance is present and the sets are
-in `Set α`) via default arguments.
+`Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even
+though it takes values in a less convenient type. It is probably the right choice in settings where
+one is concerned with the cardinalities of sets that may or may not be infinite.
+
+`Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to
+make sure its values are meaningful.  More generally, `Set.ncard` is intended to be used over the
+obvious alternative `Finset.card` when finiteness is 'propositional' rather than  'structural'.
+When working with sets that are finite by virtue of their definition, then `Finset.card` probably
+makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`,
+where every set is automatically finite. In this setting, we use default arguments and a simple
+tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems.
 
 ## Main Definitions
 
+* `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if
+    `s` is infinite.
 * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite.
   If `s` is Infinite, then `Set.ncard s = 0`.
 * `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with
@@ -31,50 +40,473 @@ in `Set α`) via default arguments.
 ## Implementation Notes
 
 The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations
-instead of `Finset`; most of the proofs invoke their `Finset` analogues. Nearly all the theorems
-require finiteness of one or more of their arguments. We provide this assumption with a
-default argument of the form `(hs : s.Finite := by toFinite_tac)`, where `toFinite_tac` will find
-a `Finite s` term in the cases where `s` is a set in a `Finite` type.
+instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the
+`Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API
+for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard`
+in the future.
+
+Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We
+provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`,
+where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite`
+type.
 
-Often, where there are two set arguments `s` and `t`, the Finiteness of one follows from the other
+Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other
 in the context of the theorem, in which case we only include the ones that are needed, and derive
 the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require
 finiteness arguments; they are true by coincidence due to junk values.
 -/
 
-open BigOperators
+namespace Set
+
+variable {s t : Set α}
+
+/-- The cardinality of a set as a term in `ℕ∞` -/
+noncomputable def encard (s : Set α) := PartENat.withTopEquiv (PartENat.card s)
+
+@[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by
+  rw [encard, encard, PartENat.card_congr (Equiv.Set.univ ↑s)]
+
+theorem encard_univ (α : Type _) :
+    encard (univ : Set α) = PartENat.withTopEquiv (PartENat.card α) := by
+  rw [encard, PartENat.card_congr (Equiv.Set.univ α)]
+
+theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by
+  have := h.fintype
+  rw [encard, PartENat.card_eq_coe_fintype_card,
+    PartENat.withTopEquiv_natCast, toFinite_toFinset, toFinset_card]
+
+theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by
+  have h := toFinite s
+  rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset, toFinset_card]
+
+theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by
+  rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp
+
+theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by
+  have := h.to_subtype
+  rw [encard, ←PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
+    PartENat.withTopEquiv_symm_top, PartENat.card_eq_top_of_infinite]
+
+@[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by
+  rw [encard, ←PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
+    PartENat.withTopEquiv_symm_zero, PartENat.card_eq_zero_iff_empty, isEmpty_subtype,
+    eq_empty_iff_forall_not_mem]
+
+@[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by
+  rw [encard_eq_zero]
+
+theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by
+  rwa [nonempty_iff_ne_empty, Ne.def, ←encard_eq_zero]
+
+theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by
+  rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty]
+
+@[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by
+  rw [pos_iff_ne_zero, encard_ne_zero]
+
+@[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]; rfl
+
+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
+  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
+  rw [←union_singleton, encard_union_eq (by simpa), encard_singleton]
+
+theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
+  refine' h.induction_on (by simpa using WithTop.zero_lt_top) _
+  rintro a t hat _ ht'
+  rw [encard_insert_of_not_mem hat]
+  exact lt_tsub_iff_right.1 ht'
+
+theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard :=
+  (ENat.coe_toNat h.encard_lt_top.ne).symm
+
+theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n :=
+  ⟨_, h.encard_eq_coe⟩
+
+@[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite :=
+  ⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩
+
+@[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by
+  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
+  simp
+
+theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by
+  rw [←encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _)
+
+theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite :=
+  finite_of_encard_le_coe h.le
+
+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 rwa [hs, Nat.cast_le]⟩
+
+section Lattice
+
+theorem encard_le_of_subset (h : s ⊆ t) : s.encard ≤ t.encard := by
+  rw [←union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
+
+theorem encard_mono {α : Type _} : Monotone (encard : Set α → ℕ∞) :=
+  fun _ _ ↦ encard_le_of_subset
+
+theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
+  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
+  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
+  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 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
+  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
+  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
+  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
+  rw [←encard_union_add_encard_inter]; exact le_self_add
+
+theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by
+  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 rw [←encard_eq_top_iff, h, encard_eq_top_iff]
+
+theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite)
+    (h : t.encard ≤ s.encard) : t.Finite :=
+  encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top)
+
+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
+  exact hst.antisymm hdiff
+
+theorem Finite.eq_of_subset_of_encard_le' (hs : s.Finite) (hst : s ⊆ t)
+    (hts : t.encard ≤ s.encard) : s = t :=
+  (hs.finite_of_encard_le hts).eq_of_subset_of_encard_le hst hts
+
+theorem Finite.encard_lt_encard (ht : t.Finite) (h : s ⊂ t) : s.encard < t.encard :=
+  (encard_mono h.subset).lt_of_ne (fun he ↦ h.ne (ht.eq_of_subset_of_encard_le h.subset he.symm.le))
+
+theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) :=
+  fun _ _ h ↦ (toFinite _).encard_lt_encard h
+
+theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by
+  rw [←encard_union_eq disjoint_sdiff_left, diff_union_self]
+
+theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard :=
+  (encard_mono (subset_union_left s t)).trans_eq (encard_diff_add_encard _ _).symm
+
+theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by
+  rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard
+
+theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by
+  rw [←encard_union_eq disjoint_compl_right, union_compl_self]
+
+end Lattice
+
+section InsertErase
+
+theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
+  rw [←union_singleton, ←encard_singleton x]; apply encard_union_le
 
-variable {α β : Type _} {s t : Set α} {a b x y : α} {f : α → β}
+theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
+  rw [←encard_singleton x]; exact encard_le_of_subset (inter_subset_left _ _)
 
-/-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a
-  `Set.Finite` term. -/
+theorem encard_diff_singleton_add_one (h : a ∈ s) :
+    (s \ {a}).encard + 1 = s.encard := by
+  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
+  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
+  rw [←encard_singleton x]; apply tsub_encard_le_encard_diff
+
+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]
+  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
+  rw [←insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange 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
+  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⟩
+  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
+  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 _)]
+  exact WithTop.add_lt_add_left (hfin.diff _).encard_lt_top.ne zero_lt_one
+
+end InsertErase
+
+section SmallSets
+
+theorem encard_pair (hne : x ≠ y) : ({x,y} : Set α).encard = 2 := by
+  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_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 simpa) (by simp [h])).symm⟩
+
+theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by
+  rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero,
+    encard_eq_one]
+
+theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by
+  rw [encard_le_one_iff_eq, or_iff_not_imp_left, ←Ne.def, ←nonempty_iff_ne_empty]
+  refine' ⟨fun h a b has hbs ↦ _,
+    fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩
+  obtain ⟨x, rfl⟩ := h ⟨_, has⟩
+  rw [(has : a = x), (hbs : b = x)]
+
+theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by
+  rw [←not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop
+
+theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by
+  by_contra' h'
+  obtain ⟨b,b',hb,hb',hne⟩ := one_lt_encard_iff.1 h
+  apply hne
+  rw [h' b hb, h' b' hb']
+
+theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x,y} := by
+  refine' ⟨fun h ↦ _, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩
+  obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
+  rw [←insert_eq_of_mem hx, ←insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl),
+    ←one_add_one_eq_two, WithTop.add_right_cancel_iff (WithTop.one_ne_top), encard_eq_one] at h
+  obtain ⟨y, h⟩ := h
+  refine' ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, _⟩
+  rw [←h, insert_diff_singleton, insert_eq_of_mem hx]
+
+theorem encard_eq_three {α : Type u_1} {s : Set α} :
+    encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
+  refine' ⟨fun h ↦ _, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ _⟩
+  · obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
+    rw [←insert_eq_of_mem hx, ←insert_diff_singleton,
+      encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1),
+      WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_eq_two] at h
+    obtain ⟨y,z,hne, hs⟩ := h
+    refine' ⟨x,y,z, _, _, hne, _⟩
+    · rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl
+    · rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl
+    rw [←hs, insert_diff_singleton, insert_eq_of_mem hx]
+  rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop
+
+theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by
+  convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1
+  · rw [Finset.coe_range, Iio_def]
+  rw [Finset.card_range]
+
+end SmallSets
+
+theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t)
+    (hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by
+  rw [←encard_diff_add_encard_of_subset h, add_comm,
+    WithTop.add_left_cancel_iff hs.encard_lt_top.ne, encard_eq_one] at hst
+  obtain ⟨x, hx⟩ := hst; use x; rw [←diff_union_of_subset h, hx, singleton_union]
+
+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]
+  exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩
+
+theorem exists_supset_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 _ _)), _⟩
+  rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)]
+
+section Function
+
+variable {s : Set α} {t : Set β} {f : α → β}
+
+theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by
+  rw [encard, PartENat.card_image_of_injOn h, encard]
+
+theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by
+  rw [←encard_univ_coe, ←encard_univ_coe t, encard_univ, encard_univ, PartENat.card_congr e]
+
+theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) :
+    (f '' s).encard = s.encard :=
+  (hf.injOn s).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]
+  exact encard_mono (by 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
+  rw [←(f.invFunOn_injOn_image s).encard_image]
+  apply encard_le_of_subset
+  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
+  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]
+  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
+  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
+  rw [←f_inj.encard_image]; apply encard_le_of_subset; rintro _ ⟨x, hx, rfl⟩; exact hf hx
+
+theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite)
+    (hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by
+  classical
+  obtain (rfl | h | ⟨a, has, -⟩) := s.eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt
+  · simp
+  · exact (encard_ne_top_iff.mpr hs h).elim
+  obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle)
+  have hle' : (s \ {a}).encard ≤ (t \ {b}).encard
+  · rwa [←WithTop.add_le_add_iff_right WithTop.one_ne_top,
+    encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt]
+
+  obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le (hs.diff {a}) hle'
+  simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hf₀s
+
+  use Function.update f₀ a b
+  rw [←insert_eq_of_mem has, ←insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)]
+  simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def,
+    mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp,
+    mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt]
+
+  refine ⟨?_,?_,fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩
+  · rintro x hx; split_ifs with h; assumption; exact (hf₀s x hx h).1
+  exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_noteq])
+termination_by _ => encard s
+
+theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) :
+    ∃ (f : α → β), BijOn f s t := by
+  obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f
+  convert hinj.bijOn_image
+  rw [(hs.image f).eq_of_subset_of_encard_le' (image_subset_iff.mpr hf)
+    (h.symm.trans hinj.encard_image.symm).le]
+
+end Function
+
+section ncard
+
+open Nat
+
+/-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a `Set.Finite`
+  term. -/
 syntax "toFinite_tac" : tactic
 
 macro_rules
   | `(tactic| toFinite_tac) => `(tactic| apply Set.toFinite)
 
-namespace Set
+/-- A tactic useful for transferring proofs for `encard` to their corresponding `card` statements -/
+syntax "to_encard_tac" : tactic
+
+macro_rules
+  | `(tactic| to_encard_tac) => `(tactic|
+      simp only [←Nat.cast_le (α := ℕ∞), ←Nat.cast_inj (R := ℕ∞), Nat.cast_add, Nat.cast_one])
+
 
 /-- The cardinality of `s : Set α` . Has the junk value `0` if `s` is infinite -/
 noncomputable def ncard (s : Set α) :=
-  Nat.card s
+  ENat.toNat s.encard
 #align set.ncard Set.ncard
 
-theorem ncard_def (s : Set α) : s.ncard = Nat.card s := rfl
-#align set.ncard_def Set.ncard_def
+theorem ncard_def (s : Set α) : s.ncard = ENat.toNat s.encard := rfl
+
+theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by
+  rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not]
+
+@[simp] theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
+  obtain (h | h) := s.finite_or_infinite
+  · have := h.fintype
+    rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card,
+      toFinite_toFinset, toFinset_card, ENat.toNat_coe]
+  have := infinite_coe_iff.2 h
+  rw [ncard, h.encard_eq, Nat.card_eq_zero_of_infinite, ENat.toNat_top]
+#align set.nat.card_coe_set_eq Set.Nat.card_coe_set_eq
 
 theorem ncard_eq_toFinset_card (s : Set α) (hs : s.Finite := by toFinite_tac) :
     s.ncard = hs.toFinset.card := by
-  rw [ncard_def, @Nat.card_eq_fintype_card _ hs.fintype, @Finite.card_toFinset _ _ hs.fintype hs]
+  rw [←Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype,
+    @Finite.card_toFinset _ _ hs.fintype hs]
 #align set.ncard_eq_to_finset_card Set.ncard_eq_toFinset_card
 
 theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] :
     s.ncard = s.toFinset.card := by
-  simp [ncard_def, Nat.card_eq_fintype_card]
+  simp [←Nat.card_coe_set_eq, Nat.card_eq_fintype_card]
+
+theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by
+  rw [encard_le_coe_iff, and_congr_right_iff]
+  exact fun hfin ↦ ⟨fun ⟨n₀, hn₀, hle⟩ ↦ by rwa [ncard_def, hn₀, ENat.toNat_coe],
+    fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩
+
+theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by
+  rw [←Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype]
+#align set.infinite.ncard Set.Infinite.ncard
 
 theorem ncard_le_of_subset (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
-    s.ncard ≤ t.ncard :=
-  @Finite.card_le_of_embedding _ _ (finite_coe_iff.mpr ht) (Set.embeddingOfSubset _ _ hst)
+    s.ncard ≤ t.ncard := by
+  rw [←Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq]
+  exact encard_mono hst
 #align set.ncard_le_of_subset Set.ncard_le_of_subset
 
 theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ ncard_le_of_subset
@@ -82,18 +514,13 @@ theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ n
 
 @[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) :
     s.ncard = 0 ↔ s = ∅ := by
-  rw [ncard_def, @Finite.card_eq_zero_iff _ hs.to_subtype, isEmpty_subtype,
-    eq_empty_iff_forall_not_mem]
+  rw [←Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero]
 #align set.ncard_eq_zero Set.ncard_eq_zero
 
 @[simp] theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by
   rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset]
 #align set.ncard_coe_finset Set.ncard_coe_Finset
 
-theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 :=
-  @Nat.card_eq_zero_of_infinite _ hs.to_subtype
-#align set.infinite.ncard Set.Infinite.ncard
-
 theorem ncard_univ (α : Type _) : (univ : Set α).ncard = Nat.card α := by
   cases' finite_or_infinite α with h h
   · have hft := Fintype.ofFinite α
@@ -130,32 +557,25 @@ theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by
   simp [ncard_eq_toFinset_card]
 #align set.ncard_singleton Set.ncard_singleton
 
-theorem ncard_singleton_inter : ({a} ∩ s).ncard ≤ 1 := by
-  classical
-  rw [← inter_self {a}, inter_assoc, ncard_eq_toFinset_card _, Finite.toFinset_inter,
-    Finite.toFinset_singleton]
-  · apply Finset.card_singleton_inter
-  all_goals toFinite_tac
+theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 := by
+  rw [←Nat.cast_le (α := ℕ∞), (toFinite _).cast_ncard_eq, Nat.cast_one]
+  apply encard_singleton_inter
 #align set.ncard_singleton_inter Set.ncard_singleton_inter
-
 section InsertErase
 
 @[simp] theorem ncard_insert_of_not_mem (h : a ∉ s) (hs : s.Finite := by toFinite_tac) :
     (insert a s).ncard = s.ncard + 1 := by
-  classical
-  have hft := hs.fintype
-  rw [ncard_eq_toFinset_card _, ncard_eq_toFinset_card _, Finite.toFinset_insert,
-    Finset.card_insert_of_not_mem]
-  rwa [Finite.mem_toFinset]
+  rw [←Nat.cast_inj (R := ℕ∞), (hs.insert a).cast_ncard_eq, Nat.cast_add, Nat.cast_one,
+    hs.cast_ncard_eq, encard_insert_of_not_mem h]
 #align set.ncard_insert_of_not_mem Set.ncard_insert_of_not_mem
 
-theorem ncard_insert_of_mem (h : a ∈ s) : ncard (insert a s) = s.ncard := by rw [insert_eq_of_mem h]
+theorem ncard_insert_of_mem (h : a ∈ s) : ncard (insert a s) = s.ncard := by
+    rw [insert_eq_of_mem h]
 #align set.ncard_insert_of_mem Set.ncard_insert_of_mem
 
 theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
   obtain hs | hs := s.finite_or_infinite
-  · exact (em (a ∈ s)).elim (fun h ↦ (ncard_insert_of_mem h).trans_le (Nat.le_succ _))
-      (fun h ↦ by rw [ncard_insert_of_not_mem h hs])
+  · to_encard_tac; rw [hs.cast_ncard_eq, (hs.insert _).cast_ncard_eq]; apply encard_insert_le
   rw [(hs.mono (subset_insert a s)).ncard]
   exact Nat.zero_le _
 #align set.ncard_insert_le Set.ncard_insert_le
@@ -180,10 +600,8 @@ theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).n
 
 @[simp] theorem ncard_diff_singleton_add_one (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
     (s \ {a}).ncard + 1 = s.ncard := by
-  have h' : a ∉ s \ {a} := by rw [mem_diff_singleton]; tauto
-  rw [← ncard_insert_of_not_mem h' (hs.diff {a})]
-  congr
-  simpa
+  to_encard_tac; rw [hs.cast_ncard_eq, (hs.diff _).cast_ncard_eq,
+    encard_diff_singleton_add_one h]
 #align set.ncard_diff_singleton_add_one Set.ncard_diff_singleton_add_one
 
 @[simp] theorem ncard_diff_singleton_of_mem (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
@@ -193,8 +611,7 @@ theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).n
 
 theorem ncard_diff_singleton_lt_of_mem (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
     (s \ {a}).ncard < s.ncard := by
-  rw [← ncard_diff_singleton_add_one h hs]
-  apply lt_add_one
+  rw [← ncard_diff_singleton_add_one h hs]; apply lt_add_one
 #align set.ncard_diff_singleton_lt_of_mem Set.ncard_diff_singleton_lt_of_mem
 
 theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by
@@ -214,12 +631,8 @@ theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 
   rw [hs.ncard]
 #align set.pred_ncard_le_ncard_diff_singleton Set.pred_ncard_le_ncard_diff_singleton
 
-theorem ncard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncard = s.ncard := by
-  cases' s.finite_or_infinite with h h
-  · haveI := h.to_subtype
-    rw [ncard_insert_of_not_mem, ncard_diff_singleton_add_one hb]
-    simp [mem_diff, not_and, not_not, ha];
-  rw [((h.diff (Set.toFinite {b})).mono (subset_insert _ _)).ncard, h.ncard]
+theorem ncard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncard = s.ncard :=
+  congr_arg ENat.toNat <| encard_exchange ha hb
 #align set.ncard_exchange Set.ncard_exchange
 
 theorem ncard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).ncard = s.ncard := by
@@ -230,32 +643,17 @@ theorem ncard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).ncard
 end InsertErase
 
 theorem ncard_image_le (hs : s.Finite := by toFinite_tac) : (f '' s).ncard ≤ s.ncard := by
-  classical
-  rw [ncard_eq_toFinset_card s hs]
-  convert @Finset.card_image_le _ _ hs.toFinset f _
-  simp only
-  rw [@ncard_eq_toFinset_card _ _ (hs.image f), Finite.toFinset_image]
+  to_encard_tac; rw [hs.cast_ncard_eq, (hs.image _).cast_ncard_eq]; apply encard_image_le
 #align set.ncard_image_le Set.ncard_image_le
 
-theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard := by
-  classical
-  cases' s.finite_or_infinite with h h
-  · haveI := @Fintype.ofFinite s h.to_subtype
-    haveI := @Fintype.ofFinite _ (h.image f).to_subtype
-    convert card_image_of_inj_on H <;> simp [ncard_def]
-  rw [h.ncard, ((infinite_image_iff H).mpr h).ncard]
+theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard :=
+  congr_arg ENat.toNat <| H.encard_image
 #align set.ncard_image_of_inj_on Set.ncard_image_of_injOn
 
 theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard) (hs : s.Finite := by toFinite_tac) :
     Set.InjOn f s := by
-  classical
-  have hft := hs.fintype
-  rw [@ncard_eq_toFinset_card _ _ (hs.image f), @ncard_eq_toFinset_card _ _ hs] at h
-  rw [←coe_toFinset s]
-  apply Finset.injOn_of_card_image_eq
-  convert h
-  · ext; simp
-  ext; simp
+  rw [←Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, (hs.image _).cast_ncard_eq] at h
+  exact hs.injOn_of_encard_image_eq h
 #align set.inj_on_of_ncard_image_eq Set.injOn_of_ncard_image_eq
 
 theorem ncard_image_iff (hs : s.Finite := by toFinite_tac) :
@@ -292,12 +690,6 @@ theorem fiber_ncard_ne_zero_iff_mem_image {y : β} (hs : s.Finite := by toFinite
   simp [←and_assoc, exists_eq_right]
 #align set.ncard_subtype Set.ncard_subtype
 
-@[simp] theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
-  convert (ncard_image_of_injective univ Subtype.coe_injective).symm using 1
-  · rw [ncard_univ]
-  simp
-#align set.nat.card_coe_set_eq Set.Nat.card_coe_set_eq
-
 theorem ncard_inter_le_ncard_left (s t : Set α) (hs : s.Finite := by toFinite_tac) :
     (s ∩ t).ncard ≤ s.ncard :=
   ncard_le_of_subset (inter_subset_left _ _) hs
@@ -309,16 +701,9 @@ theorem ncard_inter_le_ncard_right (s t : Set α) (ht : t.Finite := by toFinite_
 #align set.ncard_inter_le_ncard_right Set.ncard_inter_le_ncard_right
 
 theorem eq_of_subset_of_ncard_le (h : s ⊆ t) (h' : t.ncard ≤ s.ncard)
-    (ht : t.Finite := by toFinite_tac) : s = t := by
-  have htfin := ht.fintype
-  have hft := (ht.subset h).fintype
-  rw [← @toFinset_inj]
-  apply Finset.eq_of_subset_of_card_le
-  · simpa
-  rw [ncard_eq_toFinset_card _ ht, ncard_eq_toFinset_card _ (ht.subset h)] at h'
-  convert h'
-  · ext; simp
-  ext; simp
+    (ht : t.Finite := by toFinite_tac) : s = t :=
+  ht.eq_of_subset_of_encard_le h
+    (by rwa [←Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq] at h')
 #align set.eq_of_subset_of_ncard_le Set.eq_of_subset_of_ncard_le
 
 theorem subset_iff_eq_of_ncard_le (h : t.ncard ≤ s.ncard) (ht : t.Finite := by toFinite_tac) :
@@ -338,9 +723,8 @@ theorem sep_of_ncard_eq {P : α → Prop} (h : { x ∈ s | P x }.ncard = s.ncard
 
 theorem ncard_lt_ncard (h : s ⊂ t) (ht : t.Finite := by toFinite_tac) :
     s.ncard < t.ncard := by
-  rw [ncard_eq_toFinset_card _ (ht.subset h.subset), ncard_eq_toFinset_card t ht]
-  refine' Finset.card_lt_card _
-  rwa [Finite.toFinset_ssubset_toFinset]
+  rw [←Nat.cast_lt (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h.subset).cast_ncard_eq]
+  exact ht.encard_lt_encard h
 #align set.ncard_lt_ncard Set.ncard_lt_ncard
 
 theorem ncard_strictMono [Finite α] : @StrictMono (Set α) _ _ _ ncard :=
@@ -370,18 +754,15 @@ theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha
     obtain ⟨a, ha, rfl⟩ := h₃ y hy
     simp only [Subtype.mk.injEq, Subtype.exists]
     exact ⟨_, ha, rfl⟩
+  simp_rw [←Nat.card_coe_set_eq]
   exact Nat.card_congr (Equiv.ofBijective f' hbij)
 #align set.ncard_congr Set.ncard_congr
 
 theorem ncard_le_ncard_of_injOn {t : Set β} (f : α → β) (hf : ∀ a ∈ s, f a ∈ t) (f_inj : InjOn f s)
     (ht : t.Finite := by toFinite_tac) :
     s.ncard ≤ t.ncard := by
-  cases' s.finite_or_infinite with h h
-  · haveI := h.to_subtype
-    rw [ncard_eq_toFinset_card _ ht, ncard_eq_toFinset_card _ (toFinite s)]
-    exact Finset.card_le_card_of_inj_on f (by simpa) (by simpa)
-  convert Nat.zero_le _
-  rw [h.ncard]
+  have hle := encard_le_encard_of_injOn hf f_inj
+  to_encard_tac; rwa [ht.cast_ncard_eq, (ht.finite_of_encard_le hle).cast_ncard_eq]
 #align set.ncard_le_ncard_of_inj_on Set.ncard_le_ncard_of_injOn
 
 theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.ncard) {f : α → β}
@@ -448,12 +829,8 @@ section Lattice
 
 theorem ncard_union_add_ncard_inter (s t : Set α) (hs : s.Finite := by toFinite_tac)
     (ht : t.Finite := by toFinite_tac) : (s ∪ t).ncard + (s ∩ t).ncard = s.ncard + t.ncard := by
-  have hu := hs.union ht
-  have hi := hs.subset (inter_subset_left s t)
-  classical
-  rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht, ncard_eq_toFinset_card _ hu,
-    ncard_eq_toFinset_card _ hi, Finite.toFinset_union, Finite.toFinset_inter]
-  · exact Finset.card_union_add_card_inter _ _
+  to_encard_tac; rw [hs.cast_ncard_eq, ht.cast_ncard_eq, (hs.union ht).cast_ncard_eq,
+    (hs.subset (inter_subset_left _ _)).cast_ncard_eq, encard_union_add_encard_inter]
 #align set.ncard_union_add_ncard_inter Set.ncard_union_add_ncard_inter
 
 theorem ncard_inter_add_ncard_union (s t : Set α) (hs : s.Finite := by toFinite_tac)
@@ -462,48 +839,41 @@ theorem ncard_inter_add_ncard_union (s t : Set α) (hs : s.Finite := by toFinite
 #align set.ncard_inter_add_ncard_union Set.ncard_inter_add_ncard_union
 
 theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by
-  classical
-  cases' (s ∪ t).finite_or_infinite with h h
-  · have hs := h.subset (subset_union_left s t)
-    have ht := h.subset (subset_union_right s t)
-    rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht, ncard_eq_toFinset_card _ h,
-      Finite.toFinset_union]
-    exact Finset.card_union_le _ _
-  convert Nat.zero_le _
+  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]
+  apply zero_le
 #align set.ncard_union_le Set.ncard_union_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
-  classical
-  rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht,
-    ncard_eq_toFinset_card _ (hs.union ht), Finite.toFinset_union]
-  refine' Finset.card_union_eq _
-  rwa [Finite.disjoint_toFinset]
+  to_encard_tac
+  rw [hs.cast_ncard_eq, ht.cast_ncard_eq, (hs.union ht).cast_ncard_eq, encard_union_eq h]
 #align set.ncard_union_eq Set.ncard_union_eq
 
-theorem ncard_diff_add_ncard_eq_ncard (h : s ⊆ t) (ht : t.Finite := by toFinite_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
-  classical
-  rw [ncard_eq_toFinset_card _ ht, ncard_eq_toFinset_card _ (ht.subset h),
-    ncard_eq_toFinset_card _ (ht.diff s), Finite.toFinset_diff]
-  refine' Finset.card_sdiff_add_card_eq_card _
-  rwa [Finite.toFinset_subset_toFinset]
-#align set.ncard_diff_add_ncard_eq_ncard Set.ncard_diff_add_ncard_eq_ncard
+  to_encard_tac
+  rw [ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq, (ht.diff _).cast_ncard_eq,
+    encard_diff_add_encard_of_subset h]
+#align set.ncard_diff_add_ncard_eq_ncard Set.ncard_diff_add_ncard_of_subset
 
 theorem ncard_diff (h : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
     (t \ s).ncard = t.ncard - s.ncard := by
-  rw [← ncard_diff_add_ncard_eq_ncard h ht, add_tsub_cancel_right]
+  rw [← ncard_diff_add_ncard_of_subset h ht, add_tsub_cancel_right]
 #align set.ncard_diff Set.ncard_diff
 
 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 h h
-  · rw [← diff_inter_self_eq_diff, ← ncard_diff_add_ncard_eq_ncard (inter_subset_right t s) h,
-      add_le_add_iff_left]
-    apply ncard_inter_le_ncard_left _ _ ht
+  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 _
-  rw [h.ncard]
+  rw [hs.ncard]
 #align set.ncard_le_ncard_diff_add_ncard Set.ncard_le_ncard_diff_add_ncard
 
 theorem le_ncard_diff (s t : Set α) (hs : s.Finite := by toFinite_tac) :
@@ -514,7 +884,7 @@ theorem le_ncard_diff (s t : Set α) (hs : s.Finite := by toFinite_tac) :
 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
-  rw [← union_diff_right, ncard_diff_add_ncard_eq_ncard (subset_union_right s t) (hs.union ht)]
+  rw [←ncard_union_eq disjoint_sdiff_left (hs.diff _) ht, diff_union_self]
 #align set.ncard_diff_add_ncard Set.ncard_diff_add_ncard
 
 theorem diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.Finite := by toFinite_tac) :
@@ -529,17 +899,17 @@ theorem exists_mem_not_mem_of_ncard_lt_ncard (h : s.ncard < t.ncard)
 #align set.exists_mem_not_mem_of_ncard_lt_ncard Set.exists_mem_not_mem_of_ncard_lt_ncard
 
 @[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
-  simp_rw [← ncard_diff_add_ncard_eq_ncard (diff_subset s t) hs, sdiff_sdiff_right_self,
-    inf_eq_inter]
+    (hs : s.Finite := by toFinite_tac) : (s ∩ t).ncard + (s \ t).ncard = s.ncard := by
+  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]
 #align set.ncard_inter_add_ncard_diff_eq_ncard Set.ncard_inter_add_ncard_diff_eq_ncard
 
 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
   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]
-#align set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff Set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff
+#align set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff
+  Set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff
 
 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
@@ -552,7 +922,8 @@ theorem ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff (hs : s.Finite := by toFinit
     (ht : t.Finite := by toFinite_tac) : s.ncard < t.ncard ↔ (s \ t).ncard < (t \ s).ncard := by
   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]
-#align set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff Set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
+#align set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
+  Set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
 
 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
@@ -731,28 +1102,17 @@ theorem ncard_eq_succ {n : ℕ} (hs : s.Finite := by toFinite_tac) :
 #align set.ncard_eq_succ Set.ncard_eq_succ
 
 theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
-  classical
-  refine' ⟨fun h ↦ _, _⟩
-  · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
-    obtain ⟨y, rfl⟩ := ncard_eq_one.mp ht
-    rw [mem_singleton_iff] at hxt
-    exact ⟨_, _, hxt, rfl⟩
-  rintro ⟨x, y, hxy, rfl⟩
-  rw [ncard_eq_toFinset_card _, Finset.card_eq_two]
-  exact ⟨x, y, hxy, by ext; simp⟩
+  rw [←encard_eq_two, ncard_def, ←Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
+  refine' ⟨fun h ↦ _, fun h ↦ _⟩
+  · rwa [ENat.coe_toNat] at h; rintro h'; simp [h'] at h
+  simp [h]; exact Iff.mp ENat.coe_toNat_eq_self rfl
 #align set.ncard_eq_two Set.ncard_eq_two
 
 theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
-  refine' ⟨fun h ↦ _, _⟩
-  · obtain ⟨x, t, hxt, rfl, ht⟩ := eq_insert_of_ncard_eq_succ h
-    obtain ⟨y, z, hyz, rfl⟩ := ncard_eq_two.mp ht
-    rw [mem_insert_iff, mem_singleton_iff, not_or] at hxt
-    exact ⟨x, y, z, hxt.1, hxt.2, hyz, rfl⟩
-  rintro ⟨x, y, z, xy, xz, yz, rfl⟩
-  rw [ncard_insert_of_not_mem, ncard_insert_of_not_mem, ncard_singleton]
-  · rwa [mem_singleton_iff]
-  rw [mem_insert_iff, mem_singleton_iff]
-  tauto
+  rw [←encard_eq_three, ncard_def, ←Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
+  refine' ⟨fun h ↦ _, fun h ↦ _⟩
+  · rwa [ENat.coe_toNat] at h; rintro h'; simp [h'] at h
+  simp [h]; exact Iff.mp ENat.coe_toNat_eq_self rfl
 #align set.ncard_eq_three Set.ncard_eq_three
 
-end Set
+end ncard
feat: let convert infer instances from goal and allow tc failure (#6041)

Changes the way the term is elaborated so that typeclass inference is tolerated and so that instances are allowed to come from the goal without re-inferring them.

Diff
@@ -413,7 +413,7 @@ theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : 
   have hft' := Fintype.ofInjective f' finj
   simp_rw [ncard_eq_toFinset_card] at hst
   set f'' : ∀ a, a ∈ s.toFinset → β := fun a h ↦ f a (by simpa using h)
-  convert @Finset.surj_on_of_inj_on_of_card_le _ _ _ t.toFinset f'' _ _ _ (by simpa) (by simpa)
+  convert @Finset.surj_on_of_inj_on_of_card_le _ _ _ t.toFinset f'' _ _ _ _ (by simpa)
   · simp
   · simp [hf]
   · intros a₁ a₂ ha₁ ha₂ h
chore: fix grammar mistakes (#6121)
Diff
@@ -39,7 +39,7 @@ a `Finite s` term in the cases where `s` is a set in a `Finite` type.
 Often, where there are two set arguments `s` and `t`, the Finiteness of one follows from the other
 in the context of the theorem, in which case we only include the ones that are needed, and derive
 the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require
-finiteness arguments; they are are true by coincidence due to junk values.
+finiteness arguments; they are true by coincidence due to junk values.
 -/
 
 open BigOperators
chore: script to replace headers with #align_import statements (#5979)

Open in Gitpod

Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -2,15 +2,12 @@
 Copyright (c) 2023 Peter Nelson. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Peter Nelson
-
-! This file was ported from Lean 3 source module data.set.ncard
-! leanprover-community/mathlib commit 74c2af38a828107941029b03839882c5c6f87a04
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathlib.Data.Finite.Card
 import Mathlib.Algebra.BigOperators.Finprod
 
+#align_import data.set.ncard from "leanprover-community/mathlib"@"74c2af38a828107941029b03839882c5c6f87a04"
+
 /-!
 # Noncomputable Set Cardinality
 
chore: remove occurrences of semicolon after space (#5713)

This is the second half of the changes originally in #5699, removing all occurrences of ; after a space and implementing a linter rule to enforce it.

In most cases this 2-character substring has a space after it, so the following command was run first:

find . -type f -name "*.lean" -exec sed -i -E 's/ ; /; /g' {} \;

The remaining cases were few enough in number that they were done manually.

Diff
@@ -642,7 +642,7 @@ theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
   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
+    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]
chore: fix align linebreaks (#5683)

The result of running

find . -type f -name "*.lean" -exec sed -i -E 'N;s/^#align ([^[:space:]]+)\n *([^[:space:]]+)$/#align \1 \2/' {} \;

Hopefully for the last time...

Co-authored-by: Moritz Firsching <firsching@google.com>

Diff
@@ -542,8 +542,7 @@ theorem ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff (hs : s.Finite := by toFinit
     (ht : t.Finite := by toFinite_tac) : s.ncard = t.ncard ↔ (s \ t).ncard = (t \ s).ncard := by
   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]
-#align set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff
-  Set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff
+#align set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff Set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff
 
 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
@@ -556,8 +555,7 @@ theorem ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff (hs : s.Finite := by toFinit
     (ht : t.Finite := by toFinite_tac) : s.ncard < t.ncard ↔ (s \ t).ncard < (t \ s).ncard := by
   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]
-#align set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
-  Set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
+#align set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff Set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
 
 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
refactor: Golf and generalize Set.ncard_congr (#5327)

This PR golfs and generalizes Set.ncard_congr.

Diff
@@ -361,10 +361,8 @@ theorem ncard_eq_of_bijective {n : ℕ} (f : ∀ i, i < n → α)
 #align set.ncard_eq_of_bijective Set.ncard_eq_of_bijective
 
 theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha ∈ t)
-    (h₂ : ∀ a b ha hb, f a ha = f b hb → a = b) (h₃ : ∀ b ∈ t, ∃ a ha, f a ha = b)
-    (hs : s.Finite := by toFinite_tac) :
+    (h₂ : ∀ a b ha hb, f a ha = f b hb → a = b) (h₃ : ∀ b ∈ t, ∃ a ha, f a ha = b) :
     s.ncard = t.ncard := by
-  classical
   set f' : s → t := fun x ↦ ⟨f x.1 x.2, h₁ _ _⟩
   have hbij : f'.Bijective := by
     constructor
@@ -375,11 +373,7 @@ theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha
     obtain ⟨a, ha, rfl⟩ := h₃ y hy
     simp only [Subtype.mk.injEq, Subtype.exists]
     exact ⟨_, ha, rfl⟩
-  haveI := hs.to_subtype
-  haveI := @Fintype.ofFinite _ (Finite.ofBijective hbij)
-  haveI := Fintype.ofFinite s
-  convert Fintype.card_of_bijective hbij
-  <;> rw [ncard_def, Nat.card_eq_fintype_card]
+  exact Nat.card_congr (Equiv.ofBijective f' hbij)
 #align set.ncard_congr Set.ncard_congr
 
 theorem ncard_le_ncard_of_injOn {t : Set β} (f : α → β) (hf : ∀ a ∈ s, f a ∈ t) (f_inj : InjOn f s)
chore: tidy various files (#5469)

Co-authored-by: Scott Morrison <scott@tqft.net>

Diff
@@ -22,14 +22,14 @@ a set. It is intended as an alternative to `Finset.card` and `Fintype.card`,  bo
 data in their definition that can cause awkwardness when using `Set.toFinset`.  Using `Set.ncard`
 allows cardinality computations to avoid `Finset`/`Fintype` completely, staying in `Set` and letting
 Finiteness be handled explicitly, or (where a `Finite α` instance is present and the sets are
-in `set α`) via default arguments.
+in `Set α`) via default arguments.
 
 ## Main Definitions
 
 * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite.
   If `s` is Infinite, then `Set.ncard s = 0`.
 * `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with
-  `Set.toFinite`. This will work for `s : set α` where there is a `Finite α` instance.
+  `Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance.
 
 ## Implementation Notes
 
@@ -117,13 +117,13 @@ theorem ncard_ne_zero_of_mem (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
   ((ncard_pos hs).mpr ⟨a, h⟩).ne.symm
 #align set.ncard_ne_zero_of_mem Set.ncard_ne_zero_of_mem
 
-theorem Finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite :=
+theorem finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite :=
   s.finite_or_infinite.elim id fun h ↦ (hs h.ncard).elim
-#align set.finite_of_ncard_ne_zero Set.Finite_of_ncard_ne_zero
+#align set.finite_of_ncard_ne_zero Set.finite_of_ncard_ne_zero
 
-theorem Finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite :=
-  Finite_of_ncard_ne_zero hs.ne.symm
-#align set.finite_of_ncard_pos Set.Finite_of_ncard_pos
+theorem finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite :=
+  finite_of_ncard_ne_zero hs.ne.symm
+#align set.finite_of_ncard_pos Set.finite_of_ncard_pos
 
 theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by
   rw [nonempty_iff_ne_empty]; rintro rfl; simp at hs
@@ -266,15 +266,15 @@ theorem ncard_image_iff (hs : s.Finite := by toFinite_tac) :
   ⟨fun h ↦ injOn_of_ncard_image_eq h hs, ncard_image_of_injOn⟩
 #align set.ncard_image_iff Set.ncard_image_iff
 
-theorem ncard_image_ofInjective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard :=
+theorem ncard_image_of_injective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard :=
   ncard_image_of_injOn fun _ _ _ _ h ↦ H h
-#align set.ncard_image_of_injective Set.ncard_image_ofInjective
+#align set.ncard_image_of_injective Set.ncard_image_of_injective
 
-theorem ncard_preimage_ofInjective_subset_range {s : Set β} (H : f.Injective)
+theorem ncard_preimage_of_injective_subset_range {s : Set β} (H : f.Injective)
   (hs : s ⊆ Set.range f) :
     (f ⁻¹' s).ncard = s.ncard := by
-  rw [← ncard_image_ofInjective _ H, image_preimage_eq_iff.mpr hs]
-#align set.ncard_preimage_of_injective_subset_range Set.ncard_preimage_ofInjective_subset_range
+  rw [← ncard_image_of_injective _ H, image_preimage_eq_iff.mpr hs]
+#align set.ncard_preimage_of_injective_subset_range Set.ncard_preimage_of_injective_subset_range
 
 theorem fiber_ncard_ne_zero_iff_mem_image {y : β} (hs : s.Finite := by toFinite_tac) :
     { x ∈ s | f x = y }.ncard ≠ 0 ↔ y ∈ f '' s := by
@@ -285,18 +285,18 @@ theorem fiber_ncard_ne_zero_iff_mem_image {y : β} (hs : s.Finite := by toFinite
 #align set.fiber_ncard_ne_zero_iff_mem_image Set.fiber_ncard_ne_zero_iff_mem_image
 
 @[simp] theorem ncard_map (f : α ↪ β) : (f '' s).ncard = s.ncard :=
-  ncard_image_ofInjective _ f.inj'
+  ncard_image_of_injective _ f.inj'
 #align set.ncard_map Set.ncard_map
 
 @[simp] theorem ncard_subtype (P : α → Prop) (s : Set α) :
     { x : Subtype P | (x : α) ∈ s }.ncard = (s ∩ setOf P).ncard := by
-  convert (ncard_image_ofInjective _ (@Subtype.coe_injective _ P)).symm
+  convert (ncard_image_of_injective _ (@Subtype.coe_injective _ P)).symm
   ext x
   simp [←and_assoc, exists_eq_right]
 #align set.ncard_subtype Set.ncard_subtype
 
 @[simp] theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
-  convert (ncard_image_ofInjective univ Subtype.coe_injective).symm using 1
+  convert (ncard_image_of_injective univ Subtype.coe_injective).symm using 1
   · rw [ncard_univ]
   simp
 #align set.nat.card_coe_set_eq Set.Nat.card_coe_set_eq
@@ -350,7 +350,7 @@ theorem ncard_strictMono [Finite α] : @StrictMono (Set α) _ _ _ ncard :=
   fun _ _ h ↦ ncard_lt_ncard h
 #align set.ncard_strict_mono Set.ncard_strictMono
 
-theorem ncard_eq_ofBijective {n : ℕ} (f : ∀ i, i < n → α)
+theorem ncard_eq_of_bijective {n : ℕ} (f : ∀ i, i < n → α)
     (hf : ∀ a ∈ s, ∃ i, ∃ h : i < n, f i h = a) (hf' : ∀ (i) (h : i < n), f i h ∈ s)
     (f_inj : ∀ (i j) (hi : i < n) (hj : j < n), f i hi = f j hj → i = j)
     (hs : s.Finite := by toFinite_tac) :
@@ -358,7 +358,7 @@ theorem ncard_eq_ofBijective {n : ℕ} (f : ∀ i, i < n → α)
   rw [ncard_eq_toFinset_card _ hs]
   apply Finset.card_eq_of_bijective
   all_goals simpa
-#align set.ncard_eq_of_bijective Set.ncard_eq_ofBijective
+#align set.ncard_eq_of_bijective Set.ncard_eq_of_bijective
 
 theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha ∈ t)
     (h₂ : ∀ a b ha hb, f a ha = f b hb → a = b) (h₃ : ∀ b ∈ t, ∃ a ha, f a ha = b)
@@ -588,27 +588,27 @@ theorem exists_intermediate_Set (i : ℕ) (h₁ : i + s.ncard ≤ t.ncard) (h₂
   rw [h₁'.2, h₁'.1, ht.ncard, add_zero]
 #align set.exists_intermediate_set Set.exists_intermediate_Set
 
-theorem exists_intermediate_Set' {m : ℕ} (hs : s.ncard ≤ m) (ht : m ≤ t.ncard) (h : s ⊆ t) :
+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
   exact ⟨r, hsr, hrt, hc⟩
-#align set.exists_intermediate_set' Set.exists_intermediate_Set'
+#align set.exists_intermediate_set' Set.exists_intermediate_set'
 
 /-- We can shrink `s` to any smaller size. -/
-theorem exists_smaller_Set (s : Set α) (i : ℕ) (h₁ : i ≤ s.ncard) :
+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 simpa using ht.2.2⟩
-#align set.exists_smaller_set Set.exists_smaller_Set
+#align set.exists_smaller_set Set.exists_smaller_set
 
 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_ofInjective _ Subtype.coe_injective]
+  rw [ncard_image_of_injective _ Subtype.coe_injective]
   simp
 #align set.Infinite.exists_subset_ncard_eq Set.Infinite.exists_subset_ncard_eq
 
@@ -623,7 +623,7 @@ theorem Infinite.exists_supset_ncard_eq {s t : Set α} (ht : t.Infinite) (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
+  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
@@ -636,7 +636,7 @@ theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s
 
 @[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
+  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]
@@ -688,7 +688,7 @@ theorem ncard_le_one_iff_subset_singleton [Nonempty α]
     Finite.toFinset_subset, Finset.coe_singleton]
 #align set.ncard_le_one_iff_subset_singleton Set.ncard_le_one_iff_subset_singleton
 
-/-- A `set` of a subsingleton type has cardinality at most one. -/
+/-- A `Set` of a subsingleton type has cardinality at most one. -/
 theorem ncard_le_one_of_subsingleton [Subsingleton α] (s : Set α) : s.ncard ≤ 1 := by
   rw [ncard_eq_toFinset_card]
   exact Finset.card_le_one_of_subsingleton _
@@ -716,7 +716,7 @@ theorem two_lt_ncard (hs : s.Finite := by toFinite_tac) :
 #align set.two_lt_card Set.two_lt_ncard
 
 theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s ∧ b ≠ a := by
-  have hsf := (Finite_of_ncard_ne_zero (zero_lt_one.trans hs).ne.symm)
+  have hsf := (finite_of_ncard_ne_zero (zero_lt_one.trans hs).ne.symm)
   rw [ncard_eq_toFinset_card _ hsf] at hs
   simpa only [Finite.mem_toFinset] using Finset.exists_ne_of_one_lt_card hs a
 #align set.exists_ne_of_one_lt_ncard Set.exists_ne_of_one_lt_ncard
@@ -724,10 +724,9 @@ theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s 
 theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
     ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
   classical
-  have hsf := Finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)
+  have hsf := finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)
   rw [ncard_eq_toFinset_card _ hsf, Finset.card_eq_succ] at h
   obtain ⟨a, t, hat, hts, rfl⟩ := h
-
   simp only [Finset.ext_iff, Finset.mem_insert, Finite.mem_toFinset] at hts
   refine' ⟨a, t, hat, _, _⟩
   · simp only [Finset.mem_coe, ext_iff, mem_insert_iff]
chore: clean up spacing around at and goals (#5387)

Changes are of the form

  • some_tactic at h⊢ -> some_tactic at h ⊢
  • some_tactic at h -> some_tactic at h
Diff
@@ -677,7 +677,7 @@ theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
   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
+  simp_rw [mem_singleton_iff] at hx ⊢; subst hx
   simp only [forall_eq_apply_imp_iff', imp_self, implies_true]
 #align set.ncard_le_one_iff_eq Set.ncard_le_one_iff_eq
 
chore: fix grammar 2/3 (#5002)

Part 2 of #5001

Diff
@@ -28,7 +28,7 @@ in `set α`) via default arguments.
 
 * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite.
   If `s` is Infinite, then `Set.ncard s = 0`.
-* `toFinite_tac` is a tactic that tries to synthesize an `Set.Finite s` argument with
+* `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with
   `Set.toFinite`. This will work for `s : set α` where there is a `Finite α` instance.
 
 ## Implementation Notes
feat: port Data.Set.Ncard (#4591)

A port of the newly added ncard file.

Co-authored-by: Johan Commelin <johan@commelin.net> Co-authored-by: Jeremy Tan Jie Rui <reddeloostw@gmail.com>

Dependencies 7 + 313

314 files ported (97.8%)
128360 lines ported (97.7%)
Show graph

The unported dependencies are