Maximal runs of 1s in a ternary digit list
DefinitionErdos406RunsFor a natural number , let be its ternary digit list, written least significant digit first. This definition counts the number of maximal blocks of consecutive digits equal to in such a list. A block is a maximal interval of positions on which the digit is ; for example, the ternary expansion has digit list and two maximal blocks of s, while has one.
The count is defined by the recursion , if and otherwise, and
Thus counts the positions at which a block of s ends, which is the number of maximal blocks of s.
The statistic is used to split the exceptional powers of two in Erdős Problem 406 by the number of alternating blocks in their ternary expansion; a uniform bound on it is the structural input of the reduction to S-unit equations.
Formalization Note The definition is Erdos406.oneRunCount : List ℕ → ℕ; it acts on Nat.digits 3 n, whose entries are the ternary digits of from least to most significant.
import Mathlib namespace Erdos406 /-- The number of maximal blocks of consecutive `1`s in a list of ternary digits, listed least significant digit first. This is the number of maximal runs of the digit `1` in the ternary expansion of a natural number. -/ def oneRunCount : List ℕ → ℕ | [] => 0 | [a] => if a = 1 then 1 else 0 | a :: b :: l => (if a = 1 ∧ b ≠ 1 then 1 else 0) + oneRunCount (b :: l) end Erdos406