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 p (list.range n)
@[instance]
A fintype instance for the set relevant to nat.count
. Locally an instance in locale count
Equations
- nat.count_set.fintype p n = fintype.of_finset (finset.filter p (finset.range n)) _
theorem
nat.count_eq_card_filter_range
(p : ℕ → Prop)
[decidable_pred p]
(n : ℕ) :
nat.count p n = (finset.filter p (finset.range n)).card
theorem
nat.count_eq_card_fintype
(p : ℕ → Prop)
[decidable_pred p]
(n : ℕ) :
nat.count p n = fintype.card {k // k < n ∧ p k}
count p n
can be expressed as the cardinality of {k // k < n ∧ p k}
.
@[simp]
Alias of count_succ_eq_succ_count_iff
.
Alias of count_succ_eq_count_iff
.
theorem
nat.lt_of_count_lt_count
{p : ℕ → Prop}
[decidable_pred p]
{a b : ℕ}
(h : nat.count p a < nat.count p b) :
a < b
theorem
nat.count_strict_mono
{p : ℕ → Prop}
[decidable_pred p]
{m n : ℕ}
(hm : p m)
(hmn : m < n) :
theorem
nat.count_injective
{p : ℕ → Prop}
[decidable_pred p]
{m n : ℕ}
(hm : p m)
(hn : p n)
(heq : nat.count p m = nat.count p n) :
m = n
theorem
nat.count_mono_left
{p : ℕ → Prop}
[decidable_pred p]
{q : ℕ → Prop}
[decidable_pred q]
{n : ℕ}
(hpq : ∀ (k : ℕ), p k → q k) :