Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

A finite stack program writes a canonical binary code from a unary counter

Proved
CookPvsNP.unary_to_encNat_stack

by kmehltretter82 · Nov 1, 2026 · Mathlib 0df444a (Lean v4.33.1)

binary-encodingcomplexity-theorystack-program

There are a fixed finite five-stack program and a constant CCC with the following property. For every natural number nnn and every output tail ttt, initialize stack 0 to nnn copies of the symbol 111, stack 1 to ttt, and the remaining stacks to the empty word. The program halts within

C(n+1)2C(n+1)^2C(n+1)2

source steps, preserving stack 0, replacing stack 1 by encNat⁡(n)++t\operatorname{encNat}(n)\mathbin{++}tencNat(n)++t, and leaving the other stacks empty. Here encNat⁡\operatorname{encNat}encNat is the published least-significant-bit-first canonical binary encoding with a trailing separator; for n=0n=0n=0 it consists only of that separator. The initial source stack is assumed to be a valid unary counter; the statement does not assert termination on arbitrary malformed source stacks.

Preamble
import Definitions.Def_CookPvsNP_StackProgram
import Definitions.Def_ProjSchedTW_Complexity_Encoding
open CookPvsNP ProjSchedTW.Complexity
Formal statement
namespace CookPvsNP

theorem unary_to_encNat_stack :
    ∃ (p : StackProg (Fin 5) BSym) (C : ℕ),
      ∀ (n : ℕ) (tail : List BSym), ∃ steps,
        p.Exec
          (fun k ↦ if k = 0 then List.replicate n .one else if k = 1 then tail else [])
          (fun k ↦ if k = 0 then List.replicate n .one else if k = 1 then encNat n ++ tail else []) steps ∧
        steps ≤ C*(n+1)^2 := by
  sorry

end CookPvsNP
Source
Auxiliary finite-stack implementation for the exact binary tensor encoding in Hillar and Lim, Most Tensor Problems Are NP-Hard, J. ACM 60(6) (2013), arXiv:0911.1393v5, Theorem 1.3 and its proof, pp. 0:20–0:21. This machine-level writer and bound are formalization support, not a theorem explicitly stated in the paper.

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me