Bit-length arithmetic for size accounts #
Bounding how much room a computation needs comes down, over and over, to two facts about
Nat.size that Mathlib does not state: what pairing costs in bits, and how a bit-length compares
with the value it measures. Mathlib bounds Nat.pair monotonically, but says nothing about its
bit-length.
size_pair_le_max— pairing costs at most twice the wider component.Nat.pair x yis Cantor's square pairing, so it lands strictly below(2 ^ M) ^ 2whereMis the larger of the two bit-lengths. The constant2is attained:Nat.pair 1 0 = 2, of size2 = 2 · 1.size_pair_le— pairing costs at most twice each component, plus two. Themax-free shape, which is what an additive account of a polynomial bound composes with.size_le_self— a bit-length never exceeds the value it measures. Available at zero, where themax-form bounds are not.size_le_size_pair_left,size_le_size_pair_right— pairing never shortens a component: each ofaandbhas bit-length at most that ofNat.pair a b.size_four_mul_add_four_le,size_four_mul_add_six_le,size_succ_le_size,size_two_mul_succ_le— the small-increment facts: quadrupling and adding a constant costs at most three bits, and incrementing or doubling-and-adding-one costs at most one.
The module stays deliberately light: it is arithmetic on bit-lengths, and knows nothing about the programs whose sizes are being counted.
Square pairing costs at most twice the wider component. Nat.pair x y is Cantor's square
pairing (y² + x or x² + x + y), so it lands strictly below (2^M)² where M is the larger of
the two bit-lengths: Nat.size (Nat.pair x y) ≤ 2M. The constant 2 is attained (x = 1, y = 0
gives Nat.pair 1 0 = 2, of size 2 = 2·1). Mathlib bounds Nat.pair monotonically but does not
state its bit-length.
Widths never exceed the value. Safe at zero, unlike the max-form bounds.
Nat.size (4 * p + 4) ≤ Nat.size p + 3: quadrupling and adding a small constant costs at most
three more bits. From p < 2 ^ size p (Nat.lt_size_self), 4 * p + 4 ≤ 4 * 2 ^ size p < 8 * 2 ^ size p = 2 ^ (size p + 3), uniformly — no case on p = 0 is needed here, unlike the + 6 sibling
below.