Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

PricingWithTips 3DM dependency: CLRSLean.Chapter_34.Section_34_4_NP_Completeness_Proofs.PolyBuilder.UnaryFrameLengthPrefixedFourWaySplitCore

Definition
PricingWithTips3DM_5e69ea7ca26d3fead719bc26

by qmaai2907271020 · Oct 22, 2026 · Mathlib 0df444a (Lean v4.33.1)

complexity-theorypricing-with-tipsthree-dimensional-matching

A private, kernel-checked dependency module used by the formal NP-hardness proof for three-dimensional matching and Theorems 4.1 and 4.2 of arXiv:2507.10872.

Definition code
import Definitions.Def_PricingWithTips3DM_dea1a793ff7c6a92846a13d9

import Definitions.Def_PricingWithTips3DM_b4f76447a6d2b46e80bcfdbb
import Mathlib.Tactic
set_option autoImplicit true
set_option backward.isDefEq.respectTransparency.types false

set_option backward.isDefEq.respectTransparency.types false

/-!
# Streaming split of length-prefixed four-channel unary packets

One input packet has the layout

`width / selector / 3*width coordinate fields / width true fields /
 width false fields / frameEnd`.

The fixed controller copies the payload while inserting ordinary row markers
after selector, coordinates, true, and false.  The three runtime counters are
loaded from the unary width; no packet width enters finite control.
-/

noncomputable section

open StateTransition

namespace CLRS.Chapter34.Turing.PolyBuilder

/-- The three variable-width sections of a four-channel packet. -/
inductive UnaryFrameLengthPrefixedFourWaySplitSection
  | coordinates | trueArm | falseArm
deriving DecidableEq, Fintype

/-- Finite control of the dynamic four-way splitter. -/
inductive UnaryFrameLengthPrefixedFourWaySplitLabel
  | loadWidth
  | incCoordinate₁ | incCoordinate₂ | incCoordinate₃
  | incTrue | incFalse
  | selectorScan | selectorTick | selectorSeparator | selectorBoundary
  | sectionCheck (channel : UnaryFrameLengthPrefixedFourWaySplitSection)
  | sectionScan (channel : UnaryFrameLengthPrefixedFourWaySplitSection)
  | sectionTick (channel : UnaryFrameLengthPrefixedFourWaySplitSection)
  | sectionSeparator (channel : UnaryFrameLengthPrefixedFourWaySplitSection)
  | sectionBoundary (channel : UnaryFrameLengthPrefixedFourWaySplitSection)
  | consumeBoundary
  | finish | invalid
deriving DecidableEq, Fintype

abbrev UnaryFrameLengthPrefixedFourWaySplitProgram :=
  Program UnaryFrameSym UnaryFrameSym

/-- The next section after one completed channel. -/
def unaryFrameLengthPrefixedFourWaySplitNext
    (channel : UnaryFrameLengthPrefixedFourWaySplitSection) :
    UnaryFrameLengthPrefixedFourWaySplitLabel :=
  match channel with
  | .coordinates => .sectionCheck .trueArm
  | .trueArm => .sectionCheck .falseArm
  | .falseArm => .consumeBoundary

/-- Decrement the runtime field counter belonging to one section. -/
def unaryFrameLengthPrefixedFourWaySplitCheckOp
    (channel : UnaryFrameLengthPrefixedFourWaySplitSection) :
    Op UnaryFrameSym UnaryFrameSym
      UnaryFrameLengthPrefixedFourWaySplitLabel :=
  match channel with
  | .coordinates => .dec₁ (.sectionBoundary channel) (.sectionScan channel)
  | .trueArm => .dec₂ (.sectionBoundary channel) (.sectionScan channel)
  | .falseArm => .dec₃ (.sectionBoundary channel) (.sectionScan channel)

/-- Reversed-output streaming program.  Each width tick loads three
coordinate-field tokens and one token for each arm. -/
def unaryFrameLengthPrefixedFourWaySplitRevProgram :
    UnaryFrameLengthPrefixedFourWaySplitProgram where
  Label := UnaryFrameLengthPrefixedFourWaySplitLabel
  main := .loadWidth
  op
    | .loadWidth => .popInput .finish fun
        | .tick => .incCoordinate₁
        | .separator => .selectorScan
        | .frameEnd => .invalid
    | .incCoordinate₁ => .inc₁ .incCoordinate₂
    | .incCoordinate₂ => .inc₁ .incCoordinate₃
    | .incCoordinate₃ => .inc₁ .incTrue
    | .incTrue => .inc₂ .incFalse
    | .incFalse => .inc₃ .loadWidth
    | .selectorScan => .popInput .invalid fun
        | .tick => .selectorTick
        | .separator => .selectorSeparator
        | .frameEnd => .invalid
    | .selectorTick => .pushOutput .tick .selectorScan
    | .selectorSeparator => .pushOutput .separator .selectorBoundary
    | .selectorBoundary =>
        .pushOutput .frameEnd (.sectionCheck .coordinates)
    | .sectionCheck channel =>
        unaryFrameLengthPrefixedFourWaySplitCheckOp channel
    | .sectionScan channel => .popInput .invalid fun
        | .tick => .sectionTick channel
        | .separator => .sectionSeparator channel
        | .frameEnd => .invalid
    | .sectionTick channel => .pushOutput .tick (.sectionScan channel)
    | .sectionSeparator channel =>
        .pushOutput .separator (.sectionCheck channel)
    | .sectionBoundary channel =>
        .pushOutput .frameEnd
          (unaryFrameLengthPrefixedFourWaySplitNext channel)
    | .consumeBoundary => .popInput .invalid fun
        | .frameEnd => .loadWidth
        | _ => .invalid
    | .finish => .halt
    | .invalid => .halt

/-- Uniform explicit configuration surface used by the simulation proof. -/
def unaryFrameLengthPrefixedFourWaySplitCfg
    (label : UnaryFrameLengthPrefixedFourWaySplitLabel)
    (buffer₁ buffer₂ : Option UnaryFrameSym) (test : Bool)
    (input output : List UnaryFrameSym)
    (coordinateFields trueFields falseFields : Nat) :
    BuilderCfg unaryFrameLengthPrefixedFourWaySplitRevProgram :=
  { label := some label
    buffer₁ := buffer₁
    buffer₂ := buffer₂
    test := test
    input := input
    output := output
    work₁ := []
    work₂ := []
    counter₁ := List.replicate coordinateFields ()
    counter₂ := List.replicate trueFields ()
    counter₃ := List.replicate falseFields () }

/-- Clean packet-loop boundary. -/
def unaryFrameLengthPrefixedFourWaySplitLoopCfg
    (input output : List UnaryFrameSym) :
    BuilderCfg unaryFrameLengthPrefixedFourWaySplitRevProgram :=
  unaryFrameLengthPrefixedFourWaySplitCfg .loadWidth none none false input
    output 0 0 0

/-- Exact marked four-row output for one numeric packet. -/
def encodeUnaryFrameLengthPrefixedFourWaySplitOutput
    (selector : Nat) (coordinates whenTrue whenFalse : List Nat) :
    List UnaryFrameSym :=
  encodeUnaryFrame [selector] ++ [.frameEnd] ++
    encodeUnaryFrame coordinates ++ [.frameEnd] ++
    encodeUnaryFrame whenTrue ++ [.frameEnd] ++
    encodeUnaryFrame whenFalse ++ [.frameEnd]

/-- Exact length-prefixed input for one numeric packet. -/
def encodeUnaryFrameLengthPrefixedFourWaySplitInput
    (width selector : Nat)
    (coordinates whenTrue whenFalse : List Nat) : List UnaryFrameSym :=
  encodeUnaryFrame [width, selector] ++ encodeUnaryFrame coordinates ++
    encodeUnaryFrame whenTrue ++ encodeUnaryFrame whenFalse ++ [.frameEnd]

end CLRS.Chapter34.Turing.PolyBuilder
Source
https://github.com/tanktechnology/CLRS-Lean

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