Documentation

CslibFrontier.Foundations.Data.Nat.IterLog

Iterated Base-2 Logarithms (Nat.iterLog, Nat.iterClog, and Nat.iterClogBeta) #

CslibFrontier/Foundations/Data/Nat/LogStar.lean defines the tower of twos Nat.twoTower and its ceiling-logarithm inverse Nat.logStar (the least k with (Nat.clog 2)^[k] n ≤ 1, equivalently n ≤ Nat.twoTower k). This module supplies:

Naming the floor stopping count Nat.floorLogStar avoids collision with the ceiling convention Nat.logStar (whose values differ at n = 3 and n = 5, …, 15), while defining it in terms of Nat.logStar avoids duplicating structural fuel recursion and provides exact floor-logarithm recurrence laws (floorLogStar_of_gt_one : 1 < n → floorLogStar n = floorLogStar (Nat.log 2 n) + 1 and lt_floorLogStar_iff : k < floorLogStar n ↔ 1 < iterLog k n).

Main definitions #

Main results #

References #

def Nat.iterLog :
ℕ → ℕ → ℕ

Iterated base-2 floor logarithm ⌊log₂^(k) n⌋: iterLog 0 n = n and iterLog (k + 1) n = Nat.log 2 (iterLog k n).

@[simp]
theorem Nat.iterLog_zero (n : ℕ) :
iterLog 0 n = n
@[simp]
theorem Nat.iterLog_succ (k n : ℕ) :
(k + 1).iterLog n = log 2 (k.iterLog n)
theorem Nat.iterLog_eq_iterate (k n : ℕ) :
k.iterLog n = (log 2)^[k] n

iterLog k agrees with k-fold function iteration of Nat.log 2.

theorem Nat.iterLog_succ_apply (k n : ℕ) :
(k + 1).iterLog n = k.iterLog (log 2 n)

Applying Nat.log 2 before k iterations is the same as k + 1 iterations.

theorem Nat.iterLog_add (j k n : ℕ) :
(j + k).iterLog n = j.iterLog (k.iterLog n)

Addition of iteration counts composes iterLog.

@[simp]
theorem Nat.iterLog_zero_right (k : ℕ) :
k.iterLog 0 = 0
theorem Nat.iterLog_one_of_pos {k : ℕ} (hk : 1 ≤ k) :
k.iterLog 1 = 0
theorem Nat.iterLog_le_self (k n : ℕ) :
k.iterLog n ≤ n

iterLog k n never exceeds n.

iterLog k is monotone in its second argument.

theorem Nat.iterLog_anti_left {j k : ℕ} (n : ℕ) (h : j ≤ k) :

iterLog k n is antitone in the iteration count k.

theorem Nat.iterLog_lt_of_gt_one {k n : ℕ} (h : 1 < k.iterLog n) :
(k + 1).iterLog n < k.iterLog n

Whenever 1 < iterLog k n, one more base-2 logarithm strictly decreases it.

iterLog k n ≤ 1 holds iff n is strictly below twoTower (k + 1).

Base-2 floor iterated logarithm: the least k : ℕ such that iterLog k n ≤ 1, expressed via logStar (n + 1) - 1 so it shares logStar's structural kernel reduction.

Threshold characterization: floorLogStar n ≤ k iff iterLog k n ≤ 1.

Strict threshold characterization: k < floorLogStar n iff 1 < iterLog k n.

After floorLogStar n iterations, iterLog reaches at most 1.

theorem Nat.floorLogStar_of_le_one {n : ℕ} (hn : n ≤ 1) :

Base equation: floorLogStar n = 0 for n ≤ 1.

theorem Nat.floorLogStar_of_gt_one {n : ℕ} (hn : 1 < n) :

Step equation: for 1 < n, floorLogStar n = floorLogStar (Nat.log 2 n) + 1.

Floor floorLogStar never exceeds ceiling logStar.

Ceiling logStar exceeds floor floorLogStar by at most 1.

floorLogStar n never exceeds n.

Clamping at 4 makes the two-step floor logarithm at least 1.

theorem Nat.max_iterLog_two_max_four (n : ℕ) :
max (iterLog 2 (max n 4)) 1 = iterLog 2 (max n 4)

Exact clamping bridge: max (iterLog 2 (max n 4)) 1 = iterLog 2 (max n 4).

theorem Nat.max_iterLog_two_eq (n : ℕ) :
max (iterLog 2 n) 1 = iterLog 2 (max n 4)

Clamping iterLog 2 n below at 1 agrees everywhere with iterLog 2 (max n 4).

theorem Nat.sub_le_iterLog_of_lt_floorLogStar {n d r : ℕ} (hd : d < n.floorLogStar) (hr : r ≤ d) :
d + 1 - r ≤ (r + 1).iterLog n

If d < floorLogStar n and r ≤ d, at least d + 1 - r remains in iterLog (r + 1) n.

theorem Nat.four_le_floorLogStar_two_pow {m : ℕ} (hm : 32 ≤ m) :

For 32 ≤ m, 2 ^ m requires at least 4 floor-logarithm steps to reach ≤ 1.

theorem Nat.six_mul_iterLog_two_two_pow_le {m : ℕ} (hm : 32 ≤ m) :
6 * iterLog 2 (2 ^ m) ≤ m

For 32 ≤ m, 6 * iterLog 2 (2 ^ m) ≤ m.

theorem Nat.iterLog_two_max_four_le_clog (n : ℕ) :
iterLog 2 (max n 4) ≤ clog 2 (clog 2 (max n 4))

Floor-to-ceiling lower bound: iterLog 2 (max n 4) ≤ ⌈log₂ ⌈log₂ (max n 4)⌉⌉.

Ceiling-to-floor upper bound: ⌈log₂ ⌈log₂ (max n 4)⌉⌉ ≤ 2 * iterLog 2 (max n 4).

Iterated base-2 ceiling logarithm and exponential tower #

def Nat.iterClog :
ℕ → ℕ → ℕ

Iterated base-2 ceiling logarithm ⌈log₂^(k) n⌉: iterClog 0 n = n and iterClog (k + 1) n = Nat.clog 2 (iterClog k n).

@[simp]
theorem Nat.iterClog_zero (n : ℕ) :
iterClog 0 n = n

Zero-iteration ceiling logarithm is the identity.

@[simp]
theorem Nat.iterClog_succ (k n : ℕ) :
(k + 1).iterClog n = clog 2 (k.iterClog n)

One more ceiling-logarithm step applies Nat.clog 2 to the outside.

theorem Nat.iterClog_eq_iterate (k n : ℕ) :
k.iterClog n = (clog 2)^[k] n

iterClog k agrees with k-fold function iteration of Nat.clog 2.

theorem Nat.iterClog_succ_apply (k n : ℕ) :
(k + 1).iterClog n = k.iterClog (clog 2 n)

Applying Nat.clog 2 before k iterations is the same as k + 1 iterations.

theorem Nat.iterClog_add (j k n : ℕ) :
(j + k).iterClog n = j.iterClog (k.iterClog n)

Addition of iteration counts composes iterClog.

@[simp]
theorem Nat.iterClog_zero_right (k : ℕ) :
k.iterClog 0 = 0

Iterated ceiling logarithm of 0 is 0.

theorem Nat.iterClog_one_of_pos {k : ℕ} (hk : 1 ≤ k) :
k.iterClog 1 = 0

Positive-iteration ceiling logarithm of 1 is 0.

theorem Nat.iterClog_le_self (k n : ℕ) :

iterClog k n never exceeds n.

iterClog k is monotone in its second argument.

theorem Nat.iterClog_anti_left {j k : ℕ} (n : ℕ) (h : j ≤ k) :

iterClog k n is antitone in the iteration count k.

theorem Nat.iterClog_lt_of_two_le {k n : ℕ} (h : 2 ≤ k.iterClog n) :
(k + 1).iterClog n < k.iterClog n

Whenever 2 ≤ iterClog k n, one more base-2 ceiling logarithm strictly decreases it.

Iterated floor logarithm never exceeds iterated ceiling logarithm.

theorem Nat.iterClog_le_iterLog_add_one {k : ℕ} (hk : 1 ≤ k) (n : ℕ) :
k.iterClog n ≤ k.iterLog n + 1

For k ≥ 1, iterClog k n ≤ iterLog k n + 1.

def Nat.iterPow2 :
ℕ → ℕ → ℕ

Iterated base-2 exponential tower (2 ^ ·)^[k] x: iterPow2 0 x = x and iterPow2 (k + 1) x = 2 ^ iterPow2 k x.

@[simp]
theorem Nat.iterPow2_zero (x : ℕ) :
iterPow2 0 x = x

Zero-iteration exponential tower is the identity.

@[simp]
theorem Nat.iterPow2_succ (k x : ℕ) :
(k + 1).iterPow2 x = 2 ^ k.iterPow2 x

One more tower step exponentiates with base 2.

theorem Nat.iterPow2_eq_iterate (k x : ℕ) :
k.iterPow2 x = (fun (x : ℕ) => 2 ^ x)^[k] x

iterPow2 k agrees with k-fold function iteration of (2 ^ ·).

theorem Nat.iterPow2_succ_apply (k x : ℕ) :
(k + 1).iterPow2 x = k.iterPow2 (2 ^ x)

Applying (2 ^ ·) before k iterations is the same as k + 1 iterations.

theorem Nat.iterPow2_add (j k x : ℕ) :
(j + k).iterPow2 x = j.iterPow2 (k.iterPow2 x)

Addition of iteration counts composes iterPow2.

@[simp]

Starting iterPow2 from 1 gives twoTower.

iterPow2 k is strictly monotone in its second argument.

iterPow2 k is monotone in its second argument.

theorem Nat.le_iterPow2 (k x : ℕ) :

iterPow2 k x is always at least x.

theorem Nat.iterPow2_pos_of_pos_left {k : ℕ} (hk : 1 ≤ k) (x : ℕ) :
0 < k.iterPow2 x

iterPow2 k x is positive whenever 1 ≤ k.

Galois correspondence: iterClog k n ≤ x iff n ≤ iterPow2 k x.

iterClog k n ≤ 1 holds iff logStar n ≤ k.

Generalized iterated-logarithm stopping index (iterClogBeta) #

def Nat.iterClogBetaAux (t n : ℕ) :
ℕ → ℕ → ℕ

Bounded upward search helper for iterClogBeta: iterClogBetaAux t n fuel k scans upward from k through k + fuel for the least m ≥ k satisfying iterClog m n ≤ max 1 t. When fuel = 0, it returns k unconditionally even if max 1 t < iterClog k n; it is guaranteed to return the least satisfying m ≥ k only under the precondition iterClog (k + fuel) n ≤ max 1 t, and otherwise returns k + fuel.

def Nat.iterClogBeta (t n : ℕ) :

Generalized iterated-logarithm stopping index β(t, n): the least k ≥ 1 such that iterClog k n ≤ max 1 t (equivalently n ≤ iterPow2 k (max 1 t)). Specializing t = 2 * m / n yields the two-parameter threshold function used in dense-graph elimination rounds.

iterClogBeta t n is always at least 1.

After iterClogBeta t n iterations, iterClog drops to at most max 1 t.

Tower characterization of iterClogBeta: n ≤ iterPow2 (iterClogBeta t n) (max 1 t).

theorem Nat.iterClogBeta_le_iff {t n k : ℕ} (hk : 1 ≤ k) :

Threshold characterization for 1 ≤ k: iterClogBeta t n ≤ k ↔ iterClog k n ≤ max 1 t.

theorem Nat.iterClogBeta_le_iff_le_iterPow2 {t n k : ℕ} (hk : 1 ≤ k) :

Tower threshold characterization for 1 ≤ k: iterClogBeta t n ≤ k ↔ n ≤ iterPow2 k (max 1 t).

theorem Nat.lt_iterClogBeta_iff {t n k : ℕ} (hk : 1 ≤ k) :
k < t.iterClogBeta n ↔ max 1 t < k.iterClog n

Strict threshold characterization for 1 ≤ k: k < iterClogBeta t n ↔ max 1 t < iterClog k n.

theorem Nat.iterClogBeta_eq_one_iff {t n : ℕ} :
t.iterClogBeta n = 1 ↔ n ≤ 2 ^ max 1 t

iterClogBeta t n = 1 iff n ≤ 2 ^ max 1 t.

theorem Nat.iterClogBeta_of_le_one {t : ℕ} (ht : t ≤ 1) (n : ℕ) :

When t ≤ 1, iterClogBeta t n equals max 1 (logStar n).

iterClogBeta t is monotone in its second argument.

theorem Nat.iterClogBeta_anti_left (n : ℕ) :
Antitone fun (t : ℕ) => t.iterClogBeta n

iterClogBeta is antitone in its threshold parameter t.

iterClogBeta t n never exceeds max 1 (logStar n).

theorem Nat.iterClogBeta_le_add_iterClog {k : ℕ} (hk : 1 ≤ k) (t n : ℕ) :

For 1 ≤ k, iterClogBeta t n ≤ k + iterClog k n.

theorem Nat.iterClogBeta_lt_of_two_pow_le {t₁ t₂ n₁ n₂ : ℕ} (hn : n₂ ≤ n₁) (hgt : 2 ^ max 1 t₁ < n₁) (hstep : 2 ^ max 1 t₁ ≤ max 1 t₂) :
t₂.iterClogBeta n₂ < t₁.iterClogBeta n₁

Strictly shrinking step: if n₂ ≤ n₁, 2 ^ max 1 t₁ < n₁, and 2 ^ max 1 t₁ ≤ max 1 t₂, then iterClogBeta t₂ n₂ < iterClogBeta t₁ n₁.

theorem Nat.iterClogBeta_div_mono_right (c : ℕ) :
Monotone fun (n : ℕ) => (c / n).iterClogBeta n

For fixed c, n ↦ iterClogBeta (c / n) n is monotone.

theorem Nat.iterClogBeta_div_lt_of_mul_le {c n₁ n₂ : ℕ} (hn₂ : 1 ≤ n₂) (hn : n₂ ≤ n₁) (hgt : 2 ^ (c / n₁) < n₁) (hmul : n₂ * (2 ^ (c / n₁) + 1) ≤ c) :
(c / n₂).iterClogBeta n₂ < (c / n₁).iterClogBeta n₁

Two-parameter rank drop: if 1 ≤ n₂ ≤ n₁, 2 ^ (c / n₁) < n₁, and n₂ * (2 ^ (c / n₁) + 1) ≤ c, then iterClogBeta (c / n₂) n₂ < iterClogBeta (c / n₁) n₁.

theorem Nat.mul_iterClogBeta_le_of_div_le (k m n t : ℕ) (ht : 2 * m / n ≤ max 1 t) :
m * t.iterClogBeta n ≤ (k + 1) * m + 2 * (k + 2) * n * max 1 (k.iterClog n)

Multiplicative phase bound parameterized by k : ℕ whenever 2 * m / n ≤ max 1 t: m * iterClogBeta t n ≤ (k + 1) * m + 2 * (k + 2) * n * max 1 (iterClog k n).

theorem Nat.mul_iterClogBeta_div_le_iterLog {k : ℕ} (hk : 1 ≤ k) (m n : ℕ) :
m * (2 * m / n).iterClogBeta n ≤ (k + 1) * m + 4 * (k + 2) * n * max 1 (k.iterLog n)

Multiplicative phase bound via iterLog k n for 1 ≤ k: m * iterClogBeta (2 * m / n) n ≤ (k + 1) * m + 4 * (k + 2) * n * max 1 (iterLog k n).