Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Mathlib/Algebra/Polynomial/EraseLead.lean
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ theorem self_sub_C_mul_X_pow {R : Type*} [Ring R] (f : R[X]) :
theorem eraseLead_ne_zero (f0 : 2 ≤ #f.support) : eraseLead f ≠ 0 := by
rw [Ne, ← card_support_eq_zero, eraseLead_support]
exact
(zero_lt_one.trans_le <| (tsub_le_tsub_right f0 1).trans Finset.pred_card_le_card_erase).ne.symm
(zero_lt_one.trans_le <|
(tsub_le_tsub_right f0 1).trans Finset.card_sub_one_le_card_erase).ne.symm

theorem lt_natDegree_of_mem_eraseLead_support {a : ℕ} (h : a ∈ (eraseLead f).support) :
a < f.natDegree := by
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Combinatorics/Additive/SubsetSum.lean
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ theorem card_succ_choose_two_lt_card_subsetSum_of_pos (A_pos : ∀ x ∈ A, 0 <
theorem card_choose_two_lt_card_subsetSum_of_nonneg (A_pos : ∀ x ∈ A, 0 ≤ x) :
(#A).choose 2 < #A.subsetSum := by
calc (#A).choose 2
_ ≤ (#(A.erase 0) + 1).choose 2 := by grw [tsub_le_iff_right.1 <| pred_card_le_card_erase]
_ ≤ (#(A.erase 0) + 1).choose 2 := by grw [tsub_le_iff_right.1 <| card_sub_one_le_card_erase]
_ < #(A.erase 0).subsetSum :=
card_succ_choose_two_lt_card_subsetSum_of_pos fun x hx =>
(A_pos x (mem_of_mem_erase hx)).lt_of_ne (ne_of_mem_erase hx).symm
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Combinatorics/SetFamily/AhlswedeZhang.lean
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ lemma supSum_of_univ_notMem (h𝒜₁ : 𝒜.Nonempty) (h𝒜₂ : univ ∉ 𝒜
simpa [eq_comm] using h𝒜₂
cases m
· cases h𝒜₁.card_pos.ne hm
obtain ⟨s, 𝒜, hs, rfl, rfl⟩ := card_eq_succ.1 hm.symm
obtain ⟨s, 𝒜, hs, rfl, rfl⟩ := card_eq_add_one.1 hm.symm
have h𝒜 : 𝒜.Nonempty := by by_contra! rfl; simp at h𝒜₃
rw [insert_eq, eq_sub_of_add_eq (supSum_union_add_supSum_infs _ _), singleton_infs,
supSum_singleton (ne_of_mem_of_not_mem (mem_insert_self _ _) h𝒜₂), ih, ih, add_sub_cancel_right]
Expand Down
4 changes: 2 additions & 2 deletions Mathlib/Combinatorics/SetFamily/Shadow.lean
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ lemma mem_shadow_iterate_iff_exists_card :
induction k generalizing t with
| zero => simp
| succ k ih =>
simp only [mem_shadow_iff_insert_mem, ih, Function.iterate_succ_apply', card_eq_succ]
simp only [mem_shadow_iff_insert_mem, ih, Function.iterate_succ_apply', card_eq_add_one]
aesop

/-- `t ∈ ∂^k 𝒜` iff `t` is exactly `k` elements less than something from `𝒜`.
Expand Down Expand Up @@ -234,7 +234,7 @@ lemma mem_upShadow_iterate_iff_exists_card :
induction k generalizing t with
| zero => simp
| succ k ih =>
simp only [mem_upShadow_iff_erase_mem, ih, Function.iterate_succ_apply', card_eq_succ,
simp only [mem_upShadow_iff_erase_mem, ih, Function.iterate_succ_apply', card_eq_add_one,
subset_erase, erase_sdiff_comm, ← sdiff_insert]
constructor
· rintro ⟨a, hat, u, rfl, ⟨hut, hau⟩, htu⟩
Expand Down
18 changes: 12 additions & 6 deletions Mathlib/Data/Finset/Card.lean
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ theorem card_erase_lt_of_mem : a ∈ s → #(s.erase a) < #s :=
theorem card_erase_le : #(s.erase a) ≤ #s :=
Multiset.card_erase_le

theorem pred_card_le_card_erase : #s - 1 ≤ #(s.erase a) := by grind
theorem card_sub_one_le_card_erase : #s - 1 ≤ #(s.erase a) := by grind

@[deprecated (since := "2026-04-01")] alias pred_card_le_card_erase := card_sub_one_le_card_erase
@[deprecated (since := "2026-04-01")] alias sub_one_card_le_card_erase := card_sub_one_le_card_erase
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@[deprecated (since := "2026-04-01")] alias sub_one_card_le_card_erase := card_sub_one_le_card_erase

Also, please update the PR title


/-- If `a ∈ s` is known, see also `Finset.card_erase_of_mem` and `Finset.erase_eq_of_notMem`. -/
theorem card_erase_eq_ite : #(s.erase a) = if a ∈ s then #s - 1 else #s :=
Expand Down Expand Up @@ -738,37 +741,40 @@ lemma exists_of_one_lt_card_pi {ι : Type*} {α : ι → Type*} [∀ i, Decidabl
obtain rfl | hne := eq_or_ne (a2 i) ai
exacts [⟨a1, h1, hne⟩, ⟨a2, h2, hne⟩]

theorem card_eq_succ_iff_cons :
theorem card_eq_add_one_iff_cons :
#s = n + 1 ↔ ∃ a t, ∃ (h : a ∉ t), cons a t h = s ∧ #t = n :=
⟨cons_induction_on s (by simp) fun a s _ _ _ => ⟨a, s, by simp_all⟩,
fun ⟨a, t, _, hs, _⟩ => by simpa [← hs]⟩

section DecidableEq
variable [DecidableEq α]

theorem card_eq_succ : #s = n + 1 ↔ ∃ a t, a ∉ t ∧ insert a t = s ∧ #t = n :=
theorem card_eq_add_one : #s = n + 1 ↔ ∃ a t, a ∉ t ∧ insert a t = s ∧ #t = n :=
⟨fun h =>
let ⟨a, has⟩ := card_pos.mp (h.symm ▸ Nat.zero_lt_succ _ : 0 < #s)
⟨a, s.erase a, s.notMem_erase a, insert_erase has, by
simp only [h, card_erase_of_mem has, Nat.add_sub_cancel_right]⟩,
fun ⟨_, _, hat, s_eq, n_eq⟩ => s_eq ▸ n_eq ▸ card_insert_of_notMem hat⟩

@[deprecated (since := "2026-04-01")] alias card_eq_succ_iff_cons := card_eq_add_one_iff_cons
@[deprecated (since := "2026-04-01")] alias card_eq_succ := card_eq_add_one

theorem card_eq_two : #s = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
constructor
· rw [card_eq_succ]
· rw [card_eq_add_one]
grind [card_eq_one]
· grind

theorem card_eq_three : #s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
constructor
· rw [card_eq_succ]
· rw [card_eq_add_one]
grind [card_eq_two]
· grind

theorem card_eq_four : #s = 4 ↔
∃ x y z w, x ≠ y ∧ x ≠ z ∧ x ≠ w ∧ y ≠ z ∧ y ≠ w ∧ z ≠ w ∧ s = {x, y, z, w} := by
constructor
· rw [card_eq_succ]
· rw [card_eq_add_one]
grind [card_eq_three]
· grind

Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Data/Finset/Powerset.lean
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ theorem powersetCard_sup [DecidableEq α] (u : Finset α) (n : ℕ) (hn : n < u.
intro x hx
simp only [mem_biUnion, id]
obtain ⟨t, ht⟩ : ∃ t, t ∈ powersetCard n (u.erase x) := powersetCard_nonempty.2
(le_trans (Nat.le_sub_one_of_lt hn) pred_card_le_card_erase)
(le_trans (Nat.le_sub_one_of_lt hn) card_sub_one_le_card_erase)
refine ⟨insert x t, ?_, mem_insert_self _ _⟩
rw [← insert_erase hx, powersetCard_succ_insert (notMem_erase _ _)]
exact mem_union_right _ (mem_image_of_mem _ ht)
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Data/Set/Card.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,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
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
rw [ncard_eq_toFinset_card _ hsf, Finset.card_eq_add_one] 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, ?_, ?_⟩
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/GroupTheory/Perm/Support.lean
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ theorem card_support_swap {x y : α} (hxy : x ≠ y) : #(swap x y).support = 2 :
@[simp]
theorem card_support_eq_two {f : Perm α} : #f.support = 2 ↔ IsSwap f := by
constructor <;> intro h
· obtain ⟨x, t, hmem, hins, ht⟩ := card_eq_succ.1 h
· obtain ⟨x, t, hmem, hins, ht⟩ := card_eq_add_one.1 h
obtain ⟨y, rfl⟩ := card_eq_one.1 ht
rw [mem_singleton] at hmem
refine ⟨x, y, hmem, ?_⟩
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/RingTheory/Ideal/Operations.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ theorem subset_union_prime' {R : Type u} [CommRing R] {s : Finset ι} {f : ι
| succ n ih =>
classical
replace hn : ∃ (i : ι) (t : Finset ι), i ∉ t ∧ insert i t = s ∧ t.card = n :=
Finset.card_eq_succ.1 hn
Finset.card_eq_add_one.1 hn
rcases hn with ⟨i, t, hit, rfl, hn⟩
replace hp : IsPrime (f i) ∧ ∀ x ∈ t, IsPrime (f x) := (t.forall_mem_insert _ _).1 hp
by_cases Ht : ∃ j ∈ t, f j ≤ f i
Expand Down
Loading