Towers of twos and the iterated logarithm #
The tower Nat.twoTower k = 2 ^ 2 ^ ⋯ ^ 2 (k twos, twoTower 0 = 1) and its inverse, the
iterated logarithm Nat.logStar n = log* n: the number of times ⌈log₂ ·⌉ must be applied to n
to reach a value at most 1. Both are computable by structural recursion, so small values follow
by decide. Mathlib already has the tower as hyperoperation 4 2 (and no iterated logarithm);
Nat.twoTower_eq_hyperoperation identifies the two. The structural copy is kept because
hyperoperation is defined by well-founded recursion, on which decide and kernel reduction get
stuck. The characterization log* n ≤ k ↔ n ≤ twoTower k (Nat.logStar_le_iff) is the main
interface; the recursion log* n = log* ⌈log₂ n⌉ + 1 for n ≥ 2 is Nat.logStar_of_two_le.
Main definitions #
Nat.twoTower: the tower of twos2 ↑↑ k, a structurally recursive copy ofhyperoperation 4 2.Nat.logStar: the iterated ceiling logarithmlog* n.
Main results #
Nat.twoTower_eq_hyperoperation:twoTower k = hyperoperation 4 2 k.Nat.logStar_le_iff:log* n ≤ k ↔ n ≤ 2 ↑↑ k.Nat.logStar_of_two_le:log* n = log* ⌈log₂ n⌉ + 1forn ≥ 2.Nat.logStar_twoTower,Nat.logStar_twoTower_add_one:log* (2 ↑↑ k) = kandlog* (2 ↑↑ k + 1) = k + 1.Nat.logStar_mono:log*is monotone.Nat.iterate_two_pow_le_twoTower: iteratingc ↦ 2 ^ cktimes fromcstays below2 ↑↑ (k + log* c).
The tower of twos 2 ↑↑ k: twoTower 0 = 1 and twoTower (k + 1) = 2 ^ twoTower k.
This equals Mathlib's hyperoperation 4 2 (Nat.twoTower_eq_hyperoperation). It is redefined by
structural recursion so that decide and kernel reduction can evaluate it; hyperoperation uses
well-founded recursion and does not reduce.
The iterated logarithm log* n: the number of times ⌈log₂ ·⌉ must be applied to n to reach
a value at most 1. Equivalently (Nat.logStar_le_iff), the least k with n ≤ 2 ↑↑ k.
The tower is Mathlib's fourth hyperoperation with base 2.