Skip to content

Commit 444b9f3

Browse files
apnelson1j-loreaux
andcommitted
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 existing`ncard` 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>
1 parent 292d54d commit 444b9f3

4 files changed

Lines changed: 555 additions & 163 deletions

File tree

Mathlib/Data/ENat/Basic.lean

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ instance canLift : CanLift ℕ∞ ℕ (↑) fun n => n ≠ ⊤ :=
9292
WithTop.canLift
9393
#align enat.can_lift ENat.canLift
9494

95+
instance : WellFoundedRelation ℕ∞ where
96+
rel := (· < ·)
97+
wf := IsWellFounded.wf
98+
9599
/-- Conversion of `ℕ∞` to `ℕ` sending `∞` to `0`. -/
96100
def toNat : MonoidWithZeroHom ℕ∞ ℕ
97101
where
@@ -202,6 +206,9 @@ theorem le_of_lt_add_one (h : m < n + 1) : m ≤ n :=
202206
Order.le_of_lt_succ <| n.succ_def.symm ▸ h
203207
#align enat.le_of_lt_add_one ENat.le_of_lt_add_one
204208

209+
theorem le_coe_iff {n : ℕ∞} {k : ℕ} : n ≤ ↑k ↔ ∃ (n₀ : ℕ), n = n₀ ∧ n₀ ≤ k :=
210+
WithTop.le_coe_iff
211+
205212
@[elab_as_elim]
206213
theorem nat_induction {P : ℕ∞ → Prop} (a : ℕ∞) (h0 : P 0) (hsuc : ∀ n : ℕ, P n → P n.succ)
207214
(htop : (∀ n : ℕ, P n) → P ⊤) : P a := by

Mathlib/Data/Set/Function.lean

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,26 @@ theorem InjOn.invFunOn_image [Nonempty α] (h : InjOn f s₂) (ht : s₁ ⊆ s
12591259
h.leftInvOn_invFunOn.image_image' ht
12601260
#align set.inj_on.inv_fun_on_image Set.InjOn.invFunOn_image
12611261

1262+
theorem _root_.Function.LeftInvOn_invFunOn_of_subset_image_image [Nonempty α]
1263+
(h : s ⊆ (invFunOn f s) '' (f '' s)) : LeftInvOn (invFunOn f s) f s :=
1264+
fun x hx ↦ by
1265+
obtain ⟨-, ⟨x, hx', rfl⟩, rfl⟩ := h hx
1266+
rw [invFunOn_apply_eq (f := f) hx']
1267+
1268+
theorem injOn_iff_invFunOn_image_image_eq_self [Nonempty α] :
1269+
InjOn f s ↔ (invFunOn f s) '' (f '' s) = s :=
1270+
fun h ↦ h.invFunOn_image Subset.rfl, fun h ↦
1271+
(Function.LeftInvOn_invFunOn_of_subset_image_image h.symm.subset).injOn⟩
1272+
1273+
theorem _root_.Function.invFunOn_injOn_image [Nonempty α] (f : α → β) (s : Set α) :
1274+
Set.InjOn (invFunOn f s) (f '' s) := by
1275+
rintro _ ⟨x, hx, rfl⟩ _ ⟨x', hx', rfl⟩ he
1276+
rw [←invFunOn_apply_eq (f := f) hx, he, invFunOn_apply_eq (f := f) hx']
1277+
1278+
theorem _root_.Function.invFunOn_image_image_subset [Nonempty α] (f : α → β) (s : Set α) :
1279+
(invFunOn f s) '' (f '' s) ⊆ s := by
1280+
rintro _ ⟨_, ⟨x,hx,rfl⟩, rfl⟩; exact invFunOn_apply_mem hx
1281+
12621282
theorem SurjOn.rightInvOn_invFunOn [Nonempty α] (h : SurjOn f s t) :
12631283
RightInvOn (invFunOn f s) f t := fun _y hy => invFunOn_eq <| h hy
12641284
#align set.surj_on.right_inv_on_inv_fun_on Set.SurjOn.rightInvOn_invFunOn

0 commit comments

Comments
 (0)