Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Counting nonzero binary blocks: correctness and total time bound

Proved
TwoAgentSched.TotalTotal.CountPositive.correct_and_total

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

binary-encodingcomplexity-theorystack-programtwo-agent-scheduling

The positive-block counter has two properties.

  1. On the canonical encoding of a finite list of natural weights, with an initial success marker, it consumes all blocks and adds one unary count marker for each nonzero weight. It records two success markers per parsed block and halts in at most 14∣w∣+114|w|+114∣w∣+1 source steps, where www is the encoded input.
  2. For every symbol input and every initial status and count stack, including malformed or truncated input, it terminates within 10(∣w∣+1)210(|w|+1)^210(∣w∣+1)2 source steps.

The counter supplies the number of positive weights used by the no-sort ordered PARTITION gadget. The second clause establishes termination only; the complete reduction still must reject malformed words and actually remove zero weights.

Preamble
import Mathlib
import Definitions.Def_TwoAgentSched_TotalTotal_CountPositive
Formal statement
namespace TwoAgentSched.TotalTotal.CountPositive

open CookPvsNP ProjSchedTW.Complexity

theorem correct_and_total :
    (∀ (xs : List ℕ) (status count : List BSym), status.head? = some .one →
      ∃ steps : ℕ,
        countPositive.Exec (store4 (encNats xs) [] status count)
          (store4 [] [] (List.replicate (2 * xs.length) .one ++ status)
            (List.replicate (xs.filter (fun m => m ≠ 0)).length .one ++ count)) steps ∧
        steps ≤ 14 * (encNats xs).length + 1) ∧
    (∀ input status count : List BSym, ∃ (out : Fin 4 → List BSym) (steps : ℕ),
      countPositive.Exec (store4 input [] status count) out steps ∧
        steps ≤ 10 * (input.length + 1) ^ 2) := by sorry

end TwoAgentSched.TotalTotal.CountPositive
Source
Supporting implementation for Agnetis, Mirchandani, Pacciarelli and Pacifici, Scheduling Problems with Two Competing Agents, Operations Research 52(2), 2004, Theorem 9.2, pp. 237–238. This counter and its bounds are additional formalization results, not claims of 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