Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

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

Definition
PricingWithTips3DM_3785bc176ea811d599d16198

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_c64b728cccfb325d8721b92b
set_option autoImplicit true
set_option backward.isDefEq.respectTransparency.types false

/-!
# Counter-delimited payload channels of the four-way splitter

This file lifts the one-block scanner to a complete dynamically sized channel.
The same theorem covers coordinates, true-arm fields, and false-arm fields by
placing the active unary counter in the appropriate counter stack.
-/

noncomputable section

open StateTransition

namespace CLRS.Chapter34.Turing.PolyBuilder

private abbrev splitStep :=
  step unaryFrameLengthPrefixedFourWaySplitRevProgram

/-- Put the active field count in the counter selected by `channel`. -/
def unaryFrameLengthPrefixedFourWaySplitSectionCfg
    (channel : UnaryFrameLengthPrefixedFourWaySplitSection)
    (label : UnaryFrameLengthPrefixedFourWaySplitLabel)
    (buffer₁ buffer₂ : Option UnaryFrameSym) (test : Bool)
    (input output : List UnaryFrameSym)
    (active other₁ other₂ : Nat) :
    BuilderCfg unaryFrameLengthPrefixedFourWaySplitRevProgram :=
  match channel with
  | .coordinates => unaryFrameLengthPrefixedFourWaySplitCfg label buffer₁ buffer₂
      test input output active other₁ other₂
  | .trueArm => unaryFrameLengthPrefixedFourWaySplitCfg label buffer₁ buffer₂
      test input output other₁ active other₂
  | .falseArm => unaryFrameLengthPrefixedFourWaySplitCfg label buffer₁ buffer₂
      test input output other₁ other₂ active

/-- The scanner's final buffer is unchanged for an empty channel and contains
the last separator otherwise. -/
def unaryFrameLengthPrefixedFourWaySplitFinalBuffer
    (initial : Option UnaryFrameSym) : List Nat → Option UnaryFrameSym
  | [] => initial
  | _ :: _ => some .separator

@[simp] theorem unaryFrameLengthPrefixedFourWaySplitFinalBuffer_separator
    (values : List Nat) :
    unaryFrameLengthPrefixedFourWaySplitFinalBuffer
      (some UnaryFrameSym.separator) values = some UnaryFrameSym.separator := by
  cases values <;> rfl

/-- Exact builder-step count for one complete payload channel. -/
def unaryFrameLengthPrefixedFourWaySplitSectionSteps
    (values : List Nat) : Nat :=
  values.length + 2 * (encodeUnaryFrame values).length + 2

/-- A counter-delimited channel copies exactly its declared number of fields,
emits one row boundary, and transfers control to the next channel. -/
def unaryFrameLengthPrefixedFourWaySplit_section
    (channel : UnaryFrameLengthPrefixedFourWaySplitSection)
    (values : List Nat) (other₁ other₂ : Nat)
    (buffer₁ buffer₂ : Option UnaryFrameSym) (test : Bool)
    (tail output : List UnaryFrameSym) :
    EvalsToInTime splitStep
      (unaryFrameLengthPrefixedFourWaySplitSectionCfg channel
        (.sectionCheck channel) buffer₁ buffer₂ test
        (encodeUnaryFrame values ++ tail) output values.length other₁ other₂)
      (some (unaryFrameLengthPrefixedFourWaySplitSectionCfg channel
        (unaryFrameLengthPrefixedFourWaySplitNext channel)
        (unaryFrameLengthPrefixedFourWaySplitFinalBuffer buffer₁ values)
        buffer₂ false tail
        ((encodeUnaryFrame values ++ [UnaryFrameSym.frameEnd]).reverse ++ output)
        0 other₁ other₂))
      (unaryFrameLengthPrefixedFourWaySplitSectionSteps values) := by
  induction values generalizing buffer₁ test output with
  | nil =>
      cases channel <;> exact ⟨⟨2, rfl⟩, le_rfl⟩
  | cons value values ih =>
      let afterCheck := unaryFrameLengthPrefixedFourWaySplitSectionCfg channel
        (.sectionScan channel) buffer₁ buffer₂ true
        (encodeUnaryFrameBlock value ++ encodeUnaryFrame values ++ tail) output
        values.length other₁ other₂
      have hcheck : EvalsToInTime splitStep
          (unaryFrameLengthPrefixedFourWaySplitSectionCfg channel
            (.sectionCheck channel) buffer₁ buffer₂ test
            (encodeUnaryFrame (value :: values) ++ tail) output
            (value :: values).length other₁ other₂)
          (some afterCheck) 1 := by
        cases channel <;> exact ⟨⟨1, rfl⟩, le_rfl⟩
      have hblock : EvalsToInTime splitStep afterCheck
          (some (unaryFrameLengthPrefixedFourWaySplitSectionCfg channel
            (.sectionCheck channel) (some .separator) buffer₂ true
            (encodeUnaryFrame values ++ tail)
            ((encodeUnaryFrameBlock value).reverse ++ output)
            values.length other₁ other₂))
          (2 * (value + 1)) := by
        cases channel <;>
          simpa [afterCheck, unaryFrameLengthPrefixedFourWaySplitSectionCfg,
            List.append_assoc] using
            (unaryFrameLengthPrefixedFourWaySplit_sectionBlock
              _ value _ _ _ buffer₁ buffer₂ true
              (encodeUnaryFrame values ++ tail) output)
      have hfirst := EvalsToInTime.trans splitStep 1 (2 * (value + 1))
        _ afterCheck _ hcheck hblock
      have hrest := ih (buffer₁ := some UnaryFrameSym.separator)
        (test := true)
        (output := (encodeUnaryFrameBlock value).reverse ++ output)
      let full := EvalsToInTime.trans splitStep (2 * (value + 1) + 1)
        (unaryFrameLengthPrefixedFourWaySplitSectionSteps values)
        _ _ _ hfirst hrest
      convert full using 1
      · cases values <;>
          simp [unaryFrameLengthPrefixedFourWaySplitFinalBuffer,
          encodeUnaryFrame, List.reverse_append, List.append_assoc]
      · simp [unaryFrameLengthPrefixedFourWaySplitSectionSteps,
          encodeUnaryFrame, encodeUnaryFrameBlock]
        omega

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