guaranteed_rollercoaster_length
The maximum guaranteed length f_k(n) of a k-rollercoaster subsequence in any permutation of length n: 0 for n ≤ (k-1)², 2(k-1) - ⌊√(2(k-1)² - n)⌋ for (k-1)² < n < 2(k-1)², and ⌈n/(k-1)⌉ for n ≥ 2(k-1)².
Statement
def guaranteed_rollercoaster_length (k n : ℕ) : ℕ- Defined in
- arXiv:2611.26297, Thm. 1
- Verified
- 22 Nov 2026
- Axioms
- none listed
- Used by 1
- is_valid_guaranteed_rollercoasterA strictly increasing list of indices ans is a valid guaranteed-length k-rollercoaster for a sequence v of length n if its length is at…
Read back from the Lean
A function guaranteed_rollercoaster_length mapping natural numbers k and n to a natural number, defined as follows:
Let q = k - 1 (where subtraction is truncated on ℕ, so q = 0 if k = 0).
- If n ≤ q ^ 2, the value is 0.
- Otherwise, if n < 2 * q ^ 2, the value is 2 * q - Nat.sqrt (2 * q ^ 2 - n) (where Nat.sqrt is the integer square root $\lfloor \sqrt{\cdot} \rfloor$).
- Otherwise (n ≥ 2 * q ^ 2), the value is (n + q - 1) / q using integer division on ℕ (which returns 0 if q = 0).
Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.
Lean source view module on GitHub
/-- The maximum guaranteed length f_k(n) of a k-rollercoaster in an n-element permutation. -/ def guaranteed_rollercoaster_length (k n : ℕ) : ℕ := let q := k - 1 if n ≤ q ^ 2 then 0 else if n < 2 * q ^ 2 then 2 * q - Nat.sqrt (2 * q ^ 2 - n) else (n + q - 1) / q