The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V03. Sets, finite structures and big operators

Mathlib.Data.Finset.Density

40 declarations. Mathlib docs · Source

Density of a finite set

This defines the density of a Finset and provides induction principles for finsets.

Main declarations

  • Finset.dens s: Density of s : Finset α in α as a nonnegative rational number.

Implementation notes

There are many other ways to talk about the density of a finset and provide its API:

  1. Use the uniform measure
  2. Define finitely additive functions and generalise the Finset.card API to it. This could either be done with a. A structure FinitelyAdditiveFun b. A typeclass IsFinitelyAdditiveFun

Solution 1 would mean importing measure theory in simple files (not necessarily bad, but not amazing), and every single API lemma would require the user to prove that all the sets they are talking about are measurable in the trivial sigma-algebra (quite terrible user experience).

Solution 2 would mean that some API lemmas about density don't contain dens in their name because they are general results about finitely additive functions. But not all lemmas would be like that either since some really are dens-specific. Hence the user would need to think about whether the lemma they are looking for is generally true for finitely additive measure or whether it is dens-specific.

On top of this, solution 2.a would break dot notation on Finset.dens (possibly fixable by introducing notation for ⇑Finset.dens) and solution 2.b would run the risk of being bad performance-wise.

These considerations more generally apply to Finset.card and Finset.sum and demonstrate that overengineering basic definitions is likely to hinder user experience.

def Finset.dens E1 #

{α : Type u_2} → [Fintype α] → Finset α → ℚ≥0

Density of a finset.

dens s is the number of elements of s divided by the size of the ambient type α.

theorem Finset.dens_eq_card_div_card E1 #

∀ {α : Type u_2} [inst : Fintype α] (s : Finset α), s.dens = ↑s.card / ↑(Fintype.card α)

theorem Finset.dens_empty E0 #

∀ {α : Type u_2} [inst : Fintype α], ∅.dens = 0

theorem Finset.dens_singleton E0 #

∀ {α : Type u_2} [inst : Fintype α] (a : α), {a}.dens = (↑(Fintype.card α))⁻¹

theorem Finset.dens_cons E0 #

∀ {α : Type u_2} [inst : Fintype α] {s : Finset α} {a : α} (h : a ∉ s),
  (Finset.cons a s h).dens = s.dens + (↑(Fintype.card α))⁻¹

theorem Finset.dens_disjUnion E0 #

∀ {α : Type u_2} [inst : Fintype α] (s t : Finset α) (h : Disjoint s t), (s.disjUnion t h).dens = s.dens + t.dens

theorem Finset.dens_eq_zero E0 #

∀ {α : Type u_2} [inst : Fintype α] {s : Finset α}, s.dens = 0 ↔ s = ∅

theorem Finset.dens_ne_zero E1 #

∀ {α : Type u_2} [inst : Fintype α] {s : Finset α}, s.dens ≠ 0 ↔ s.Nonempty

theorem Finset.dens_pos E0 #

∀ {α : Type u_2} [inst : Fintype α] {s : Finset α}, 0 < s.dens ↔ s.Nonempty

theorem Finset.Nonempty.dens_pos E1 #

∀ {α : Type u_2} [inst : Fintype α] {s : Finset α}, s.Nonempty → 0 < s.dens

Alias of the reverse direction of Finset.dens_pos.

theorem Finset.Nonempty.dens_ne_zero E1 #

∀ {α : Type u_2} [inst : Fintype α] {s : Finset α}, s.Nonempty → s.dens ≠ 0

Alias of the reverse direction of Finset.dens_ne_zero.

theorem Finset.dens_le_dens E1 #

∀ {α : Type u_2} [inst : Fintype α] {s t : Finset α}, s ⊆ t → s.dens ≤ t.dens

theorem Finset.dens_lt_dens E1 #

∀ {α : Type u_2} [inst : Fintype α] {s t : Finset α}, s ⊂ t → s.dens < t.dens

theorem Finset.dens_mono E1 #

∀ {α : Type u_2} [inst : Fintype α], Monotone Finset.dens

theorem Finset.dens_strictMono E1 #

∀ {α : Type u_2} [inst : Fintype α], StrictMono Finset.dens

theorem Finset.dens_map_le E1 #

∀ {α : Type u_2} {β : Type u_3} [inst : Fintype α] {s : Finset α} [inst_1 : Fintype β] (f : α ↪ β),
  (Finset.map f s).dens ≤ s.dens

theorem Finset.dens_map_equiv E0 #

∀ {α : Type u_2} {β : Type u_3} [inst : Fintype α] {s : Finset α} [inst_1 : Fintype β] (e : α ≃ β),
  (Finset.map e.toEmbedding s).dens = s.dens

theorem Finset.dens_image E1 #

∀ {α : Type u_2} {β : Type u_3} [inst : Fintype α] [inst_1 : Fintype β] [inst_2 : DecidableEq β] {f : α → β},
  Function.Bijective f → ∀ (s : Finset α), (Finset.image f s).dens = s.dens

theorem Finset.card_mul_dens E0 #

∀ {α : Type u_2} [inst : Fintype α] (s : Finset α), ↑(Fintype.card α) * s.dens = ↑s.card

theorem Finset.dens_mul_card E0 #

∀ {α : Type u_2} [inst : Fintype α] (s : Finset α), s.dens * ↑(Fintype.card α) = ↑s.card

theorem Finset.natCast_card_mul_nnratCast_dens E0 #

∀ {𝕜 : Type u_1} {α : Type u_2} [inst : Fintype α] [inst_1 : Semifield 𝕜] [CharZero 𝕜] (s : Finset α),
  ↑(Fintype.card α) * ↑s.dens = ↑s.card

theorem Finset.nnratCast_dens_mul_natCast_card E0 #

∀ {𝕜 : Type u_1} {α : Type u_2} [inst : Fintype α] [inst_1 : Semifield 𝕜] [CharZero 𝕜] (s : Finset α),
  ↑s.dens * ↑(Fintype.card α) = ↑s.card

theorem Finset.nnratCast_dens E1 #

∀ {𝕜 : Type u_1} {α : Type u_2} [inst : Fintype α] [inst_1 : Semifield 𝕜] [CharZero 𝕜] (s : Finset α),
  ↑s.dens = ↑s.card / ↑(Fintype.card α)

theorem Finset.dens_univ E0 #

∀ {α : Type u_2} [inst : Fintype α] [Nonempty α], Finset.univ.dens = 1

theorem Finset.dens_eq_one E0 #

∀ {α : Type u_2} [inst : Fintype α] {s : Finset α} [Nonempty α], s.dens = 1 ↔ s = Finset.univ

theorem Finset.dens_ne_one E1 #

∀ {α : Type u_2} [inst : Fintype α] {s : Finset α} [Nonempty α], s.dens ≠ 1 ↔ s ≠ Finset.univ

theorem Finset.dens_le_one E0 #

∀ {α : Type u_2} [inst : Fintype α] {s : Finset α}, s.dens ≤ 1

theorem Finset.dens_union_add_dens_inter E1 #

∀ {α : Type u_2} [inst : Fintype α] [inst_1 : DecidableEq α] (s t : Finset α),
  (s ∪ t).dens + (s ∩ t).dens = s.dens + t.dens

theorem Finset.dens_inter_add_dens_union E1 #

∀ {α : Type u_2} [inst : Fintype α] [inst_1 : DecidableEq α] (s t : Finset α),
  (s ∩ t).dens + (s ∪ t).dens = s.dens + t.dens

theorem Finset.dens_union_of_disjoint E0 #

∀ {α : Type u_2} [inst : Fintype α] {s t : Finset α} [inst_1 : DecidableEq α],
  Disjoint s t → (s ∪ t).dens = s.dens + t.dens

theorem Finset.dens_sdiff_add_dens_eq_dens E1 #

∀ {α : Type u_2} [inst : Fintype α] {s t : Finset α} [inst_1 : DecidableEq α], s ⊆ t → (t \ s).dens + s.dens = t.dens

theorem Finset.dens_sdiff_add_dens E1 #

∀ {α : Type u_2} [inst : Fintype α] [inst_1 : DecidableEq α] (s t : Finset α), (s \ t).dens + t.dens = (s ∪ t).dens

theorem Finset.dens_sdiff_comm E1 #

∀ {α : Type u_2} [inst : Fintype α] {s t : Finset α} [inst_1 : DecidableEq α],
  s.card = t.card → (s \ t).dens = (t \ s).dens

theorem Finset.dens_sdiff_add_dens_inter E0 #

∀ {α : Type u_2} [inst : Fintype α] [inst_1 : DecidableEq α] (s t : Finset α), (s \ t).dens + (s ∩ t).dens = s.dens

theorem Finset.dens_inter_add_dens_sdiff E0 #

∀ {α : Type u_2} [inst : Fintype α] [inst_1 : DecidableEq α] (s t : Finset α), (s ∩ t).dens + (s \ t).dens = s.dens

theorem Finset.dens_filter_add_dens_filter_not_eq_dens E1 #

∀ {α : Type u_4} [inst : Fintype α] {s : Finset α} (p : α → Prop) [inst_1 : DecidablePred p]
  [inst_2 : (x : α) → Decidable ¬p x], {a ∈ s | p a}.dens + {a ∈ s | ¬p a}.dens = s.dens

theorem Finset.dens_union_le E1 #

∀ {α : Type u_2} [inst : Fintype α] [inst_1 : DecidableEq α] (s t : Finset α), (s ∪ t).dens ≤ s.dens + t.dens

theorem Finset.dens_le_dens_sdiff_add_dens E1 #

∀ {α : Type u_2} [inst : Fintype α] {s t : Finset α} [inst_1 : DecidableEq α], s.dens ≤ (s \ t).dens + t.dens

theorem Finset.dens_sdiff E1 #

∀ {α : Type u_2} [inst : Fintype α] {s t : Finset α} [inst_1 : DecidableEq α], s ⊆ t → (t \ s).dens = t.dens - s.dens

theorem Finset.le_dens_sdiff E1 #

∀ {α : Type u_2} [inst : Fintype α] [inst_1 : DecidableEq α] (s t : Finset α), t.dens - s.dens ≤ (t \ s).dens