Natural and logarithmic density
Densities
AbbreviationPartial density#✓fully proved
Let \(\beta\) be a preorder in which every set \(\{x \in \beta \mid x \le b\}\) is finite, let \(S, A \subseteq \beta\) and \(b \in \beta\), and write \(A_{\lt b} = \{x \in A \mid x < b\}\). The partial density of \(S\) relative to \(A\) at \(b\) is the proportion \(\lvert S \cap A_{\lt b} \rvert / \lvert A_{\lt b} \rvert\) of elements of \(A_{\lt b}\) that lie in \(S\), taken to be \(0\) when \(A_{\lt b}\) is empty. By default \(A = \beta\).
@[inline]
noncomputable abbrev partialDensity {β : Type*} [Preorder β] [LocallyFiniteOrderBot β]
(S : Set β) (A : Set β := Set.univ) (b : β) : ℝ :=
((S ∩ A) ∩ Iio b).ncard / (A ∩ Iio b).ncard
Sources
- inspired by https://github.com/b-mehta/unit-fractions
DefinitionUpper density#✓fully proved
Let \(\beta\) be a preorder in which every set \(\{x \in \beta \mid x \le b\}\) is finite, and let \(S, A \subseteq \beta\). The upper density of \(S\) relative to \(A\) is the limit superior, as \(b \to \infty\) in \(\beta\), of the partial densities of \(S\) relative to \(A\) at \(b\). By default \(A = \beta\).
noncomputable def upperDensity {β : Type*} [Preorder β] [LocallyFiniteOrderBot β]
(S : Set β) (A : Set β := Set.univ) : ℝ :=
atTop.limsup fun (b : β) ↦ S.partialDensity A b
Uses 1 · Used by 3
DefinitionLower density#✓fully proved
Let \(\beta\) be a preorder in which every set \(\{x \in \beta \mid x \le b\}\) is finite, and let \(S, A \subseteq \beta\). The lower density of \(S\) relative to \(A\) is the limit inferior, as \(b \to \infty\) in \(\beta\), of the partial densities of \(S\) relative to \(A\) at \(b\). By default \(A = \beta\).
noncomputable def lowerDensity {β : Type*} [Preorder β] [LocallyFiniteOrderBot β]
(S : Set β) (A : Set β := Set.univ) : ℝ :=
atTop.liminf fun (b : β) ↦ S.partialDensity A b
Uses 1 · Used by 3
DefinitionDensity of a set#✓fully proved
Let \(\beta\) be a preorder in which every set \(\{x \in \beta \mid x \le b\}\) is finite, let \(S, A \subseteq \beta\) and \(\alpha \in \mathbb{R}\), and write \(\beta_{\lt b} = \{x \in \beta \mid x < b\}\). The set \(S\) has density \(\alpha\) relative to \(A\) if the partial density \(\lvert S \cap A \cap \beta_{\lt b} \rvert / \lvert A \cap \beta_{\lt b} \rvert\), taken to be \(0\) when the denominator is \(0\), tends to \(\alpha\) as \(b \to \infty\) in \(\beta\).
By default \(A = \beta\); for \(\beta = \mathbb{N}\) this is the natural density of \(S\).
def HasDensity {β : Type*} [Preorder β] [LocallyFiniteOrderBot β]
(S : Set β) (α : ℝ) (A : Set β := Set.univ) : Prop :=
Tendsto (fun (b : β) => S.partialDensity A b) atTop (𝓝 α)
Uses 1 · Used by 34
DefinitionPositive density#✓fully proved
Let \(\beta\) be a preorder in which every set \(\{x \in \beta \mid x \le b\}\) is finite, and let \(S, A \subseteq \beta\). The set \(S\) has positive density relative to \(A\) if there is a real number \(\alpha > 0\) such that \(S\) has density \(\alpha\) relative to \(A\). By default \(A = \beta\).
def HasPosDensity {β : Type*} [Preorder β] [LocallyFiniteOrderBot β]
(S : Set β) (A : Set β := Set.univ) : Prop :=
∃ α > 0, S.HasDensity α A
Uses 1
DefinitionTwo-sided partial density#✓fully proved
For a set \(S\) of integers and a natural number \(N\), the two-sided partial natural density of \(S\) at \(N\) is \(\lvert S \cap [-N, N] \rvert / (2N + 1)\), where \([-N, N]\) is the set of integers \(m\) with \(-N \le m \le N\).
noncomputable def intPartialDensity (S : Set ℤ) (N : ℕ) : ℝ :=
open scoped Classical in
(((Finset.Icc (-(N : ℤ)) (N : ℤ)).filter (fun m => m ∈ S)).card : ℝ) /
(2 * (N : ℝ) + 1)
Used by 1
DefinitionTwo-sided natural density#✓fully proved
A set \(S\) of integers has two-sided natural density \(\alpha \in \mathbb{R}\) if \(\lvert S \cap [-N, N] \rvert / (2N + 1)\) tends to \(\alpha\) as the natural number \(N\) tends to infinity, where \([-N, N]\) is the set of integers \(m\) with \(-N \le m \le N\).
def HasIntDensity (S : Set ℤ) (α : ℝ) : Prop :=
Tendsto (fun N : ℕ => S.intPartialDensity N) atTop (𝓝 α)
Uses 1
Has Density
TheoremThe whole order has density one#✓fully proved
Let \(\beta\) be a partial order with a least element and at least two elements, in which every closed interval \([a, b]\) is finite. Then the set of all elements of \(\beta\) has density \(1\) (relative to all of \(\beta\)).
@[simp]
theorem univ {β : Type*} [PartialOrder β] [LocallyFiniteOrder β] [OrderBot β] [Nontrivial β] :
(@Set.univ β).HasDensity 1
Uses 2
Basic properties of natural density
TheoremNatural density of the even numbers#✓fully proved
The set of even natural numbers has natural density \(1/2\).
theorem hasDensity_even : {n : ℕ | Even n}.HasDensity (1 / 2)
Uses 2
TheoremFinite sets have natural density zero#✓fully proved
Every finite set of natural numbers has natural density \(0\).
theorem hasDensity_zero_of_finite {S : Set ℕ} (h : S.Finite) : S.HasDensity 0
Uses 2 · Used by 1
TheoremSets of nonzero natural density are infinite#✓fully proved
If a set \(S\) of natural numbers has natural density \(\alpha\) with \(\alpha \neq 0\), then \(S\) is infinite.
theorem infinite_of_hasDensity_pos {S : Set ℕ} {α : ℝ} (h : S.HasDensity α) (hα : α ≠ 0) :
S.Infinite
Uses 3
Has Density
DefinitionLogarithmic density#✓fully proved
A set \(A\) of natural numbers has logarithmic density \(d \in \mathbb{R}\) if \(\frac{1}{\log n} \sum_{k \in A,\, k \le n} \frac{1}{k}\) tends to \(d\) as \(n \to \infty\), where \(\log\) is the natural logarithm, the term \(1/k\) for \(k = 0\) is taken to be \(0\), and the whole expression is taken to be \(0\) when \(\log n = 0\).
Logarithmic density is a weaker notion than natural density: if a set has natural density \(d\), then it also has logarithmic density \(d\), but the converse is false.
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.