Counting on ℕ #
This file defines the count function, which gives, for any predicate on the natural numbers,
"how many numbers under k satisfy this predicate?".
We then prove several expected lemmas about count, relating it to the cardinality of other
objects, and helping to evaluate it for specific k.
Count the number of naturals k < n satisfying p k.
Equations
- Nat.count p n = List.countP (fun (b : ℕ) => decide (p b)) (List.range n)
Instances For
A fintype instance for the set relevant to Nat.count. Locally an instance in scope count
Equations
- Nat.CountSet.fintype p n = Fintype.ofFinset ({x ∈ Finset.range n | p x}) ⋯
Instances For
Alias of the reverse direction of Nat.count_succ_eq_succ_count_iff.
Alias of the reverse direction of Nat.count_succ_eq_count_iff.
theorem
Nat.lt_of_count_lt_count
{p : ℕ → Prop}
[DecidablePred p]
{a b : ℕ}
(h : count p a < count p b)
:
theorem
Nat.count_injective
{p : ℕ → Prop}
[DecidablePred p]
{m n : ℕ}
(hm : p m)
(hn : p n)
(heq : count p m = count p n)
:
Alias of the reverse direction of Nat.count_iff_forall.
Alias of the reverse direction of Nat.count_iff_forall_not.
theorem
Nat.exists_of_count_lt_count
{p : ℕ → Prop}
[DecidablePred p]
{a b : ℕ}
(h : count p a < count p b)
:
∃ x ∈ Set.Ico a b, p x
theorem
Nat.count_mono_left
{p : ℕ → Prop}
[DecidablePred p]
{q : ℕ → Prop}
[DecidablePred q]
{n : ℕ}
(hpq : ∀ (k : ℕ), p k → q k)
: