Documentation

CslibFrontier.Foundations.Data.Nat.InverseAckermann

Ackermann function and inverse-Ackermann bounds #

This module defines the diagonal Ackermann hierarchy Nat.ackermann k j from [CLRS09] Section 21.4 (pp. 573–581) together with rank-shifted inverses Nat.inverseAckermannAt d n, Nat.inverseAckermann n, and Nat.inverseAckermannTwo m n used in amortized disjoint-set step analyses (toward #3558 and #5441).

Every definition is structurally recursive, so small values evaluate by decide. For k = 0, ackermann 0 j = j + 1; for k + 1, ackermann (k + 1) j = (ackermann k)^[j + 1] j, matching [CLRS09] Section 21.4 (so ackermann 1 j = 2 * j + 1, ackermann 2 1 = 7, and ackermann 3 1 = 2047). This differs from Mathlib.Computability.Ackermann (ack, the Péter–Robinson recurrence with ack 1 n = n + 2 and ack 3 n = 2 ^ (n + 3) - 3) and from CslibFrontier.Foundations.Data.Nat.LogStar (Nat.twoTower / Nat.logStar, the single-level tower of twos and iterated logarithm). Because ackermann k 0 = 1 for every k, strict monotonicity in k and unbounded growth require 1 ≤ j. Shifting the diagonal offset by d' := max 1 d ≥ 1, inverseAckermannAt d n returns the least k ≥ 1 with Nat.log 2 n + d' < ackermann k d'. Taking d = 1 yields the single-parameter inverse inverseAckermann n, and taking d = m / n + 1 yields a two-parameter analogue inverseAckermannTwo m n (using shift d = m / n + 1 in the [CLRS09] recurrence, differing by small constants from [Tar75]'s 4 * ⌈m / n⌉ threshold convention).

Main definitions #

Main results #

References #

def Nat.ackermann :
ℕ → ℕ → ℕ

Two-argument Ackermann hierarchy by structural recursion: ackermann 0 j = j + 1 and ackermann (k + 1) j = (ackermann k)^[j + 1] j.

def Nat.inverseAckermannAux (d target : ℕ) :
ℕ → ℕ → ℕ

Bounded upward search helper for inverseAckermannAt: returns the first m ≥ k in at most fuel steps satisfying target < ackermann m d.

Shifted inverse Ackermann function: least k ≥ 1 with Nat.log 2 n + max 1 d < ackermann k (max 1 d).

Single-parameter inverse Ackermann function α(n) = inverseAckermannAt 1 n.

Shifted two-parameter inverse Ackermann function α(m, n) = inverseAckermannAt (m / n + 1) n, a constant-shift analogue of Tarjan's α(m, n).

@[simp]
theorem Nat.ackermann_zero (j : ℕ) :
ackermann 0 j = j + 1
theorem Nat.ackermann_succ (k j : ℕ) :
(k + 1).ackermann j = k.ackermann^[j + 1] j
theorem Nat.ackermann_one (j : ℕ) :
ackermann 1 j = 2 * j + 1

Closed form at level 1: ackermann 1 j = 2 * j + 1.

theorem Nat.ackermann_two (j : ℕ) :
ackermann 2 j = 2 ^ (j + 1) * (j + 1) - 1

Closed form at level 2: ackermann 2 j = 2 ^ (j + 1) * (j + 1) - 1.

Concrete value ackermann 3 1 = 2047.

theorem Nat.lt_ackermann (k j : ℕ) :
j < k.ackermann j

Every diagonal value strictly exceeds its second argument.

For fixed level k, ackermann k is strictly increasing.

For fixed level k, ackermann k is monotone.

theorem Nat.ackermann_le_succ_left (k j : ℕ) :
k.ackermann j ≤ (k + 1).ackermann j

ackermann is nondecreasing in the level k.

theorem Nat.ackermann_monotone_left (j : ℕ) :
Monotone fun (k : ℕ) => k.ackermann j

For fixed j, k ↦ ackermann k j is monotone.

theorem Nat.ackermann_lt_succ_left (k : ℕ) {j : ℕ} (hj : 1 ≤ j) :
k.ackermann j < (k + 1).ackermann j

For 1 ≤ j, advancing the level strictly increases ackermann k j.

theorem Nat.ackermann_strictMono_left {j : ℕ} (hj : 1 ≤ j) :
StrictMono fun (k : ℕ) => k.ackermann j

For 1 ≤ j, k ↦ ackermann k j is strictly increasing.

theorem Nat.add_lt_ackermann (k : ℕ) {j : ℕ} :
1 ≤ j → j + k < k.ackermann j

For 1 ≤ j, j + k < ackermann k j.

Defining inequality for inverseAckermannAt d n.

theorem Nat.inverseAckermannAt_le_iff {d n k : ℕ} (hk : 1 ≤ k) :
d.inverseAckermannAt n ≤ k ↔ log 2 n + max 1 d < k.ackermann (max 1 d)

Equivalence characterization for inverseAckermannAt d n ≤ k when 1 ≤ k.

For fixed n, d ↦ inverseAckermannAt d n is antitone.

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

Equivalence characterization for inverseAckermann n ≤ k when 1 ≤ k.

theorem Nat.inverseAckermann_le_three_of_lt {n : ℕ} (hn : n < 2 ^ 2046) :

For all n < 2 ^ 2046, inverseAckermann n ≤ 3.

Defining inequality for inverseAckermannTwo m n.

For fixed n, m ↦ inverseAckermannTwo m n is antitone.

When Nat.log 2 n ≤ m / n + 1, inverseAckermannTwo m n = 1.

Once n * Nat.log 2 n ≤ m, Tarjan's two-parameter inverse Ackermann collapses to 1.