Natural number logarithms #
This file defines two ℕ
-valued analogs of the logarithm of n
with base b
:
log b n
: Lower logarithm, or floor log. Greatestk
such thatb^k ≤ n
.clog b n
: Upper logarithm, or ceil log. Leastk
such thatn ≤ b^k
.
These are interesting because, for 1 < b
, Nat.log b
and Nat.clog b
are respectively right and
left adjoints of Nat.pow b
. See pow_le_iff_le_log
and le_pow_iff_clog_le
.
Floor logarithm #
pow b
and log b
(almost) form a Galois connection. See also Nat.pow_le_of_le_log
and
Nat.le_log_of_pow_le
for individual implications under weaker assumptions.
Ceil logarithm #
@[irreducible]
clog b n
, is the upper logarithm of natural number n
in base b
. It returns the smallest
k : ℕ
such that n ≤ b^k
, so if b^k = n
, it returns exactly k
.