Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Four-stack binary-adder output normalizer

Definition
TwoAgentSched_TotalTotal_BinaryAdderNormalizer

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

complexity-theorycomputation

A fixed four-stack normalizer removes leading zeros from a most-significant-bit-first output, transfers the remaining bits in reverse to the input stack, clears the carry history, and resets the carry stack to zero. It is a component for repeated binary addition.

Definition code
import Definitions.Def_TwoAgentSched_TotalTotal_BinaryAdder
import Definitions.Def_CookPvsNP_StackMacros

set_option autoImplicit false
open CookPvsNP ProjSchedTW.Complexity

namespace TwoAgentSched.TotalTotal.BinaryAdder.Normalizer

/-- Continue while the MSB-first output begins with a redundant zero. -/
def zeroOnOutput (h : Fin 4 → Option BSym) : Bool := h 2 == some BSym.zero

def dropOutputAct (_h : Fin 4 → Option BSym) (k : Fin 4) : StackAct BSym :=
  if k = 2 then .pop else .keep

/-- Discard leading zero symbols from the output stack. -/
def trimOutput : StackProg (Fin 4) BSym := .loop zeroOnOutput (.act dropOutputAct)

/-- Trim the high-zero prefix, reverse the remaining output onto input stack
    zero, clear the carry history, and reset carry to zero. -/
def normalizeOutput : StackProg (Fin 4) BSym :=
  .seq trimOutput
    (.seq (transferProg 2 (fun k => decide (k = 0)))
      (.seq (clearProg 3) (pushProg 3 .zero)))

end TwoAgentSched.TotalTotal.BinaryAdder.Normalizer

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