The nth Number Satisfying a Predicate #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
This file defines a function for "what is the nth number that satisifies a given predicate p",
and provides lemmas that deal with this function and its connection to nat.count.
Main definitions #
nat.nth p n: Then-th naturalk(zero-indexed) such thatp k. If there is no such natural (that is,pis true for at mostnnaturals), thennat.nth p n = 0.
Main results #
nat.nth_set_card: For a fintely-often truep, gives the cardinality of the set of numbers satisfyingpabove particular values ofnth pnat.count_nth_gc: Establishes a Galois connection betweennat.nth pandnat.count p.nat.nth_eq_order_iso_of_nat: For an infinitely-ofter true predicate,nthagrees with the order-isomorphism of the subtype to the natural numbers.
There has been some discussion on the subject of whether both of nth and
nat.subtype.order_iso_of_nat should exist. See discussion
here.
Future work should address how lemmas that use these should be written.
Find the n-th natural number satisfying p (indexed from 0, so nth p 0 is the first
natural number satisfying p), or 0 if there is no such number. See also
subtype.order_iso_of_nat for the order isomorphism with ℕ when p is infinitely often true.
When s is an infinite set, nth agrees with nat.subtype.order_iso_of_nat.
When s is an infinite set, nth agrees with nat.subtype.order_iso_of_nat.
Lemmas that work for finite and infinite sets #
An alternative recursive definition of nat.nth: nat.nth s n is the infimum of x ∈ s such
that nat.nth s k < x for all k < n, if this set is nonempty. We do not assume that the set is
nonempty because we use the same "garbage value" 0 both for Inf on ℕ and for nat.nth s n for
n ≥ card s.
If a predicate p : ℕ → Prop is true for infinitely many numbers, then nat.count p and
nat.nth p form a Galois insertion.
Equations
- nat.gi_count_nth hp = galois_insertion.monotone_intro _ nat.gi_count_nth._proof_1 _ _