Skip to content

Commit f1001e4

Browse files
committed
chore(Data/Set/Card): adjust naming and simp set (#26791)
Renames: - `Set.ncard_coe_Finset` -> `Set.ncard_coe_finset` - `Set.Nat.card_coe_set_eq` -> `Nat.card_coe_set_eq` Additionally, make the latter simp, so that `Nat.card` of a coerced set to type is no longer simp-normal, and make `ncard_univ` simp so that `Set.ncard univ` is no longer simp-normal. The other simp changes in this PR are all for the simpNF linter, since a good chunk of simp lemmas are now provable.
1 parent 129a2bf commit f1001e4

File tree

15 files changed

+42
-55
lines changed

15 files changed

+42
-55
lines changed

Mathlib/Algebra/Group/Pointwise/Set/Card.lean

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,16 @@ variable [InvolutiveInv G]
4444
lemma _root_.Cardinal.mk_inv (s : Set G) : #↥(s⁻¹) = #s := by
4545
rw [← image_inv_eq_inv, Cardinal.mk_image_eq_of_injOn _ _ inv_injective.injOn]
4646

47-
@[to_additive (attr := simp)]
48-
lemma natCard_inv (s : Set G) : Nat.card ↥(s⁻¹) = Nat.card s := by
49-
rw [← image_inv_eq_inv, Nat.card_image_of_injective inv_injective]
50-
5147
@[to_additive (attr := simp)]
5248
lemma encard_inv (s : Set G) : s⁻¹.encard = s.encard := by
5349
simp [← toENat_cardinalMk]
5450

5551
@[to_additive (attr := simp)]
5652
lemma ncard_inv (s : Set G) : s⁻¹.ncard = s.ncard := by simp [ncard]
5753

54+
@[to_additive]
55+
lemma natCard_inv (s : Set G) : Nat.card ↥(s⁻¹) = Nat.card s := by simp
56+
5857
end InvolutiveInv
5958

6059
section DivInvMonoid
@@ -79,16 +78,16 @@ variable [MulAction G α]
7978
lemma _root_.Cardinal.mk_smul_set (a : G) (s : Set α) : #↥(a • s) = #s :=
8079
Cardinal.mk_image_eq_of_injOn _ _ (MulAction.injective a).injOn
8180

82-
@[to_additive (attr := simp)]
83-
lemma natCard_smul_set (a : G) (s : Set α) : Nat.card ↥(a • s) = Nat.card s :=
84-
Nat.card_image_of_injective (MulAction.injective a) _
85-
8681
@[to_additive (attr := simp)]
8782
lemma encard_smul_set (a : G) (s : Set α) : (a • s).encard = s.encard := by
8883
simp [← toENat_cardinalMk]
8984

9085
@[to_additive (attr := simp)]
9186
lemma ncard_smul_set (a : G) (s : Set α) : (a • s).ncard = s.ncard := by simp [ncard]
9287

88+
@[to_additive]
89+
lemma natCard_smul_set (a : G) (s : Set α) : Nat.card ↥(a • s) = Nat.card s := by
90+
simp
91+
9392
end Group
9493
end Set

Mathlib/Combinatorics/SimpleGraph/Connectivity/WalkCounting.lean

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,15 @@ abbrev oddComponents : Set G.ConnectedComponent := {c : G.ConnectedComponent | O
240240
lemma ConnectedComponent.odd_oddComponents_ncard_subset_supp [Finite V] {G'}
241241
(h : G ≤ G') (c' : ConnectedComponent G') :
242242
Odd {c ∈ G.oddComponents | c.supp ⊆ c'.supp}.ncard ↔ Odd c'.supp.ncard := by
243-
simp_rw [← Set.Nat.card_coe_set_eq]
243+
simp_rw [← Nat.card_coe_set_eq]
244244
classical
245245
cases nonempty_fintype V
246246
rw [Nat.card_eq_card_toFinset c'.supp, ← disjiUnion_supp_toFinset_eq_supp_toFinset h]
247247
simp only [Finset.card_disjiUnion, Set.toFinset_card, Fintype.card_ofFinset]
248248
rw [Finset.odd_sum_iff_odd_card_odd, Nat.card_eq_fintype_card, Fintype.card_ofFinset]
249249
congr! 2
250250
ext c
251-
simp_rw [Set.toFinset_setOf, mem_filter, ← Set.ncard_coe_Finset, coe_filter,
251+
simp_rw [Set.toFinset_setOf, mem_filter, ← Set.ncard_coe_finset, coe_filter,
252252
mem_supp_iff, mem_univ, true_and, supp, and_comm]
253253

254254
lemma odd_ncard_oddComponents [Finite V] : Odd G.oddComponents.ncard ↔ Odd (Nat.card V) := by
@@ -259,8 +259,7 @@ lemma odd_ncard_oddComponents [Finite V] : Odd G.oddComponents.ncard ↔ Odd (Na
259259
← Set.toFinset_card, Set.toFinset_iUnion ConnectedComponent.supp]
260260
rw [Finset.card_biUnion
261261
(fun x _ y _ hxy ↦ Set.disjoint_toFinset.mpr (pairwise_disjoint_supp_connectedComponent _ hxy))]
262-
simp_rw [Set.toFinset_card, ← Nat.card_eq_fintype_card, ← Finset.coe_filter_univ,
263-
Set.ncard_coe_Finset, Set.Nat.card_coe_set_eq]
262+
simp_rw [← Set.ncard_eq_toFinset_card', ← Finset.coe_filter_univ, Set.ncard_coe_finset]
264263
exact (Finset.odd_sum_iff_odd_card_odd (fun x : G.ConnectedComponent ↦ x.supp.ncard)).symm
265264

266265
lemma ncard_oddComponents_mono [Finite V] {G' : SimpleGraph V} (h : G ≤ G') :

Mathlib/Combinatorics/SimpleGraph/Matching.lean

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,8 @@ lemma odd_matches_node_outside [Finite V] {u : Set V}
311311
haveI : Fintype ↑(Subgraph.induce M (Subtype.val '' supp c.val)).verts := Fintype.ofFinite _
312312
classical
313313
haveI : Fintype (c.val.supp) := Fintype.ofFinite _
314-
simpa [Subgraph.induce_verts, Subgraph.verts_top, Set.toFinset_image, Nat.card_eq_fintype_card,
315-
Set.toFinset_image,Finset.card_image_of_injective _ (Subtype.val_injective), Set.toFinset_card,
316-
← Set.Nat.card_coe_set_eq] using hMmatch.even_card
314+
simpa [Subgraph.induce_verts, Subgraph.verts_top, Nat.card_eq_fintype_card, Set.toFinset_card,
315+
Finset.card_image_of_injective, ← Nat.card_coe_set_eq] using hMmatch.even_card
317316

318317
end Finite
319318
end ConnectedComponent

Mathlib/Combinatorics/SimpleGraph/Tutte.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ lemma exists_isTutteViolator (h : ∀ (M : G.Subgraph), ¬M.IsPerfectMatching)
280280
Gmax.deleteUniversalVerts.coe.IsClique K.supp
281281
· -- Deleting universal vertices splits the graph into cliques
282282
rw [Fintype.card_eq_nat_card] at hc
283-
simp_rw [Fintype.card_eq_nat_card, Set.Nat.card_coe_set_eq] at hc
283+
simp_rw [Fintype.card_eq_nat_card, Nat.card_coe_set_eq] at hc
284284
push_neg at hc
285285
obtain ⟨M, hM⟩ := Subgraph.IsPerfectMatching.exists_of_isClique_supp hvEven
286286
(by simpa [IsTutteViolator] using hc) h'

Mathlib/Data/Set/Card.lean

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -503,22 +503,18 @@ theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by
503503

504504
lemma ncard_le_encard (s : Set α) : s.ncard ≤ s.encard := ENat.coe_toNat_le_self _
505505

506-
theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
507-
obtain (h | h) := s.finite_or_infinite
508-
· have := h.fintype
509-
rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card,
510-
toFinite_toFinset, toFinset_card, ENat.toNat_coe]
511-
have := infinite_coe_iff.2 h
512-
rw [ncard, h.encard_eq, Nat.card_eq_zero_of_infinite, ENat.toNat_top]
506+
@[simp] theorem _root_.Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := rfl
507+
508+
@[deprecated (since := "2025-07-05")] alias Nat.card_coe_set_eq := _root_.Nat.card_coe_set_eq
513509

514510
theorem ncard_eq_toFinset_card (s : Set α) (hs : s.Finite := by toFinite_tac) :
515511
s.ncard = hs.toFinset.card := by
516-
rw [← Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype,
512+
rw [← _root_.Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype,
517513
@Finite.card_toFinset _ _ hs.fintype hs]
518514

519515
theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] :
520516
s.ncard = s.toFinset.card := by
521-
simp [← Nat.card_coe_set_eq, Nat.card_eq_fintype_card]
517+
simp [← _root_.Nat.card_coe_set_eq, Nat.card_eq_fintype_card]
522518

523519
lemma cast_ncard {s : Set α} (hs : s.Finite) :
524520
(s.ncard : Cardinal) = Cardinal.mk s := @Nat.cast_card _ hs
@@ -529,7 +525,7 @@ theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finit
529525
fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩
530526

531527
theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by
532-
rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype]
528+
rw [← _root_.Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype]
533529

534530
@[gcongr]
535531
theorem ncard_le_ncard (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
@@ -543,15 +539,12 @@ theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ n
543539
s.ncard = 0 ↔ s = ∅ := by
544540
rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero]
545541

546-
@[simp, norm_cast] theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by
542+
@[simp, norm_cast] theorem ncard_coe_finset (s : Finset α) : (s : Set α).ncard = s.card := by
547543
rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset]
548544

549-
theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by
550-
rcases finite_or_infinite α with h | h
551-
· have hft := Fintype.ofFinite α
552-
rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card]
553-
rw [Nat.card_eq_zero_of_infinite, Infinite.ncard]
554-
exact infinite_univ
545+
@[deprecated (since := "2025-07-05")] alias ncard_coe_Finset := ncard_coe_finset
546+
547+
@[simp] theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := Nat.card_univ
555548

556549
@[simp] theorem ncard_empty (α : Type*) : (∅ : Set α).ncard = 0 := by
557550
rw [ncard_eq_zero]
@@ -771,7 +764,7 @@ theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha
771764
obtain ⟨a, ha, rfl⟩ := h₃ y hy
772765
simp only [Subtype.exists]
773766
exact ⟨_, ha, rfl⟩
774-
simp_rw [← Nat.card_coe_set_eq]
767+
simp_rw [← _root_.Nat.card_coe_set_eq]
775768
exact Nat.card_congr (Equiv.ofBijective f' hbij)
776769

777770
theorem ncard_le_ncard_of_injOn {t : Set β} (f : α → β) (hf : ∀ a ∈ s, f a ∈ t) (f_inj : InjOn f s)
@@ -834,9 +827,8 @@ theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf :
834827
(by { rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card'] }) a₁
835828
(by simpa) a₂ (by simpa) (by simpa)
836829

837-
@[simp] theorem ncard_coe {α : Type*} (s : Set α) :
838-
Set.ncard (Set.univ : Set (Set.Elem s)) = s.ncard :=
839-
Set.ncard_congr (fun a ha ↦ ↑a) (fun a ha ↦ a.prop) (by simp) (by simp)
830+
theorem ncard_coe {α : Type*} (s : Set α) :
831+
Set.ncard (Set.univ : Set (Set.Elem s)) = s.ncard := by simp
840832

841833
@[simp] lemma ncard_graphOn (s : Set α) (f : α → β) : (s.graphOn f).ncard = s.ncard := by
842834
rw [← ncard_image_of_injOn fst_injOn_graph, image_fst_graphOn]
@@ -942,9 +934,7 @@ theorem eq_univ_iff_ncard [Finite α] (s : Set α) :
942934

943935
lemma even_ncard_compl_iff [Finite α] (heven : Even (Nat.card α)) (s : Set α) :
944936
Even sᶜ.ncard ↔ Even s.ncard := by
945-
simp [compl_eq_univ_diff, ncard_diff (subset_univ _ : s ⊆ Set.univ),
946-
Nat.even_sub (ncard_le_ncard (subset_univ _ : s ⊆ Set.univ)),
947-
(ncard_univ _).symm ▸ heven]
937+
rwa [iff_comm, ← Nat.even_add, ncard_add_ncard_compl]
948938

949939
lemma odd_ncard_compl_iff [Finite α] (heven : Even (Nat.card α)) (s : Set α) :
950940
Odd sᶜ.ncard ↔ Odd s.ncard := by

Mathlib/Data/Setoid/Partition/Card.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ theorem Setoid.IsPartition.ncard_eq_finsum {α : Type*} {P : Set (Set α)}
3030
Nat.card_eq_card_finite_toFinset (hst t)
3131
suffices hs' : _ by
3232
rw [finsum_def, dif_pos hs']
33-
simp only [← Set.Nat.card_coe_set_eq, Nat.card_eq_card_finite_toFinset hs]
33+
simp only [← Nat.card_coe_set_eq, Nat.card_eq_card_finite_toFinset hs]
3434
rw [Finset.sum_congr rfl (fun t ht ↦ by exact hst' ↑t)]
3535
rw [← Finset.card_sigma, eq_comm]
3636
apply Finset.card_nbij' (fun ⟨t, x⟩ ↦ x)

Mathlib/FieldTheory/Finite/GaloisField.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ theorem unitsMap_norm_surjective : Function.Surjective (Units.map <| Algebra.nor
250250
convert IsCyclic.card_pow_eq_one_le (α := K'ˣ) <| Nat.div_pos
251251
(Nat.sub_le_sub_right (Nat.card_le_card_of_injective _ (algebraMap K K').injective) _) <|
252252
Nat.sub_pos_of_lt Finite.one_lt_card
253-
rw [← Set.ncard_coe_Finset, ← SetLike.coe_sort_coe, Set.Nat.card_coe_set_eq]; congr; ext
253+
rw [← Set.ncard_coe_finset, ← SetLike.coe_sort_coe, Nat.card_coe_set_eq]; congr; ext
254254
simp [Units.ext_iff, ← (algebraMap K K').injective.eq_iff, algebraMap_norm_eq_pow]
255255

256256
theorem norm_surjective : Function.Surjective (Algebra.norm K (S := K')) := fun k ↦ by

Mathlib/GroupTheory/GroupAction/MultipleTransitivity.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ theorem isMultiplyPretransitive {m n : ℕ} [Hn : IsMultiplyPretransitive G α n
511511
exists_smul_eq x y := by
512512
have : IsMultiplyPretransitive G α (s.ncard + m) := by rw [hmn]; infer_instance
513513
have Hs : Nonempty (Fin (s.ncard) ≃ s) :=
514-
Finite.card_eq.mp (by simp [Set.Nat.card_coe_set_eq])
514+
Finite.card_eq.mp (by simp [Nat.card_coe_set_eq])
515515
set x' := ofFixingSubgroup.append x with hx
516516
set y' := ofFixingSubgroup.append y with hy
517517
obtain ⟨g, hg⟩ := exists_smul_eq G x' y'

Mathlib/GroupTheory/GroupAction/SubMulAction/OfFixingSubgroup.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ noncomputable def ofFixingSubgroup.append
444444
{n : ℕ} [Finite s] (x : Fin n ↪ ofFixingSubgroup M s) :
445445
Fin (s.ncard + n) ↪ α := by
446446
have : Nonempty (Fin (s.ncard) ≃ s) :=
447-
Finite.card_eq.mp (by simp [Set.Nat.card_coe_set_eq])
447+
Finite.card_eq.mp (by simp [Nat.card_coe_set_eq])
448448
let y := (Classical.choice this).toEmbedding
449449
apply Fin.Embedding.append (x := y.trans (subtype _)) (y := x.trans (subtype _))
450450
rw [Set.disjoint_iff_forall_ne]
@@ -457,7 +457,7 @@ noncomputable def ofFixingSubgroup.append
457457
theorem ofFixingSubgroup.append_left {n : ℕ} [Finite s]
458458
(x : Fin n ↪ ofFixingSubgroup M s) (i : Fin s.ncard) :
459459
let Hs : Nonempty (Fin (s.ncard) ≃ s) :=
460-
Finite.card_eq.mp (by simp [Set.Nat.card_coe_set_eq])
460+
Finite.card_eq.mp (by simp [Nat.card_coe_set_eq])
461461
ofFixingSubgroup.append x (Fin.castAdd n i) = (Classical.choice Hs) i := by
462462
simp [ofFixingSubgroup.append]
463463

Mathlib/GroupTheory/Index.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ variable (G : Type*) {X : Type*} [Group G] [MulAction G X] (x : X)
699699
@[to_additive] theorem index_stabilizer :
700700
(stabilizer G x).index = (orbit G x).ncard :=
701701
(Nat.card_congr (MulAction.orbitEquivQuotientStabilizer G x)).symm.trans
702-
(Set.Nat.card_coe_set_eq (orbit G x))
702+
(Nat.card_coe_set_eq (orbit G x))
703703

704704
@[to_additive] theorem index_stabilizer_of_transitive [IsPretransitive G X] :
705705
(stabilizer G x).index = Nat.card X := by
@@ -713,7 +713,7 @@ namespace MonoidHom
713713
lemma surjective_of_card_ker_le_div {G M : Type*} [Group G] [Group M] [Finite G] [Finite M]
714714
(f : G →* M) (h : Nat.card f.ker ≤ Nat.card G / Nat.card M) : Function.Surjective f := by
715715
refine range_eq_top.1 <| SetLike.ext' <| Set.eq_of_subset_of_ncard_le (Set.subset_univ _) ?_
716-
rw [Subgroup.coe_top, Set.ncard_univ, ← Set.Nat.card_coe_set_eq, SetLike.coe_sort_coe,
716+
rw [Subgroup.coe_top, Set.ncard_univ, ← Nat.card_coe_set_eq, SetLike.coe_sort_coe,
717717
← Nat.card_congr (QuotientGroup.quotientKerEquivRange f).toEquiv]
718718
exact Nat.le_of_mul_le_mul_left (f.ker.card_mul_index ▸ Nat.mul_le_of_le_div _ _ _ h) Nat.card_pos
719719

0 commit comments

Comments
 (0)