Integer logarithms in a field with respect to a natural base #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
This file defines two ℤ
-valued analogs of the logarithm of r : R
with base b : ℕ
:
int.log b r
: Lower logarithm, or floor log. Greatestk
such that↑b^k ≤ r
.int.clog b r
: Upper logarithm, or ceil log. Leastk
such thatr ≤ ↑b^k
.
Note that int.log
gives the position of the left-most non-zero digit:
#eval (int.log 10 (0.09 : ℚ), int.log 10 (0.10 : ℚ), int.log 10 (0.11 : ℚ))
-- (-2, -1, -1)
#eval (int.log 10 (9 : ℚ), int.log 10 (10 : ℚ), int.log 10 (11 : ℚ))
-- (0, 1, 1)
which means it can be used for computing digit expansions
import data.fin.vec_notation
def digits (b : ℕ) (q : ℚ) (n : ℕ) : ℕ :=
⌊q*b^(↑n - int.log b q)⌋₊ % b
#eval digits 10 (1/7) ∘ (coe : fin 8 → ℕ)
-- ![1, 4, 2, 8, 5, 7, 1, 4]
Main results #
- For
int.log
:int.zpow_log_le_self
,int.lt_zpow_succ_log_self
: the bounds formed byint.log
,(b : R) ^ log b r ≤ r < (b : R) ^ (log b r + 1)
.int.zpow_log_gi
: the galois coinsertion betweenzpow
andint.log
.
- For
int.clog
:int.zpow_pred_clog_lt_self
,int.self_le_zpow_clog
: the bounds formed byint.clog
,(b : R) ^ (clog b r - 1) < r ≤ (b : R) ^ clog b r
.int.clog_zpow_gi
: the galois insertion betweenint.clog
andzpow
.
int.neg_log_inv_eq_clog
,int.neg_clog_inv_eq_log
: the link between the two definitions.
theorem
int.log_of_one_le_right
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
(b : ℕ)
{r : R}
(hr : 1 ≤ r) :
theorem
int.log_of_right_le_one
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
(b : ℕ)
{r : R}
(hr : r ≤ 1) :
@[simp, norm_cast]
theorem
int.log_of_left_le_one
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
{b : ℕ}
(hb : b ≤ 1)
(r : R) :
theorem
int.log_of_right_le_zero
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
(b : ℕ)
{r : R}
(hr : r ≤ 0) :
theorem
int.zpow_log_le_self
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
{b : ℕ}
{r : R}
(hb : 1 < b)
(hr : 0 < r) :
theorem
int.lt_zpow_succ_log_self
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
{b : ℕ}
(hb : 1 < b)
(r : R) :
@[simp]
@[simp]
theorem
int.log_zpow
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
{b : ℕ}
(hb : 1 < b)
(z : ℤ) :
theorem
int.log_mono_right
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
{b : ℕ}
{r₁ r₂ : R}
(h₀ : 0 < r₁)
(h : r₁ ≤ r₂) :
def
int.zpow_log_gi
(R : Type u_1)
[linear_ordered_semifield R]
[floor_semiring R]
{b : ℕ}
(hb : 1 < b) :
Over suitable subtypes, zpow
and int.log
form a galois coinsertion
Equations
- int.zpow_log_gi R hb = galois_coinsertion.monotone_intro _ _ _ _
theorem
int.clog_of_one_le_right
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
(b : ℕ)
{r : R}
(hr : 1 ≤ r) :
theorem
int.clog_of_right_le_one
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
(b : ℕ)
{r : R}
(hr : r ≤ 1) :
theorem
int.clog_of_right_le_zero
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
(b : ℕ)
{r : R}
(hr : r ≤ 0) :
@[simp]
theorem
int.clog_inv
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
(b : ℕ)
(r : R) :
@[simp]
theorem
int.log_inv
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
(b : ℕ)
(r : R) :
theorem
int.neg_log_inv_eq_clog
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
(b : ℕ)
(r : R) :
theorem
int.neg_clog_inv_eq_log
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
(b : ℕ)
(r : R) :
@[simp, norm_cast]
theorem
int.clog_nat_cast
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
(b n : ℕ) :
theorem
int.clog_of_left_le_one
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
{b : ℕ}
(hb : b ≤ 1)
(r : R) :
theorem
int.self_le_zpow_clog
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
{b : ℕ}
(hb : 1 < b)
(r : R) :
theorem
int.zpow_pred_clog_lt_self
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
{b : ℕ}
{r : R}
(hb : 1 < b)
(hr : 0 < r) :
@[simp]
theorem
int.clog_zero_right
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
(b : ℕ) :
@[simp]
theorem
int.clog_zpow
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
{b : ℕ}
(hb : 1 < b)
(z : ℤ) :
theorem
int.clog_mono_right
{R : Type u_1}
[linear_ordered_semifield R]
[floor_semiring R]
{b : ℕ}
{r₁ r₂ : R}
(h₀ : 0 < r₁)
(h : r₁ ≤ r₂) :
def
int.clog_zpow_gi
(R : Type u_1)
[linear_ordered_semifield R]
[floor_semiring R]
{b : ℕ}
(hb : 1 < b) :
Over suitable subtypes, int.clog
and zpow
form a galois insertion
Equations
- int.clog_zpow_gi R hb = galois_insertion.monotone_intro _ _ _ _