Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Knapsack Method, paragraph after Step (7), p. 868 — the invariant on entry to Step (3)

Proved
CuttingStock63.Knapsack.tested_vector_invariant

by mikedeng1 · Oct 6, 2026 · Mathlib 0df444a (Lean v4.33.1)

algorithm-correctnessinvariantknapsackp2o-batch-pfp2ap2o-gran-per-chapterp2o-plan-paperp2o-v1

Consider the Knapsack Method with lengths l1,…,lm>0l_1,\dots,l_m>0l1​,…,lm​>0, prices b1,…,bm≥0b_1,\dots,b_m\ge0b1​,…,bm​≥0 ordered by density (b1/l1≥⋯≥bm/lmb_1/l_1\ge\dots\ge b_m/l_mb1​/l1​≥⋯≥bm​/lm​), stock lengths L1>⋯>LkL_1>\dots>L_kL1​>⋯>Lk​ and costs c1,…,ckc_1,\dots,c_kc1​,…,ck​. Let σ\sigmaσ be a reachable state at which Step (3) is about to test the vector (α)m(\alpha)_m(α)m​, with current values M1,…,MkM_1,\dots,M_kM1​,…,Mk​. Then:

  1. for every jjj, cj≤Mjc_j\le M_jcj​≤Mj​, and either Mj=cjM_j=c_jMj​=cj​ or Mj=β⋅(α′)mM_j=\beta\cdot(\alpha')_mMj​=β⋅(α′)m​ for some vector with Lj≥λ⋅(α′)mL_j\ge\lambda\cdot(\alpha')_mLj​≥λ⋅(α′)m​;
  2. every vector (α′)m(\alpha')_m(α′)m​ with L1≥λ⋅(α′)mL_1\ge\lambda\cdot(\alpha')_mL1​≥λ⋅(α′)m​ that is lexicographically larger than (α)m(\alpha)_m(α)m​ satisfies
β⋅(α′)m≤M1.\beta\cdot(\alpha')_m\le M_1 .β⋅(α′)m​≤M1​.

Clause 2 says that, for the longest stock length, every vector above the one being tested has already been accounted for; it is the invariant behind the paper's justification "each succeeding vector tested in (3) is the lexicographically next largest mmm-vector that can satisfy Lt≥λ⋅(α)mL_t\ge\lambda\cdot(\alpha)_mLt​≥λ⋅(α)m​ and β⋅(α)m>Mj\beta\cdot(\alpha)_m>M_jβ⋅(α)m​>Mj​".

Formalization Note Clause 2 is stated for L1L_1L1​ only, because for the shorter stock lengths it is false: with m=1m=1m=1, l1=b1=1l_1=b_1=1l1​=b1​=1, L=(5,2)L=(5,2)L=(5,2), c=(0,0)c=(0,0)c=(0,0), the method tests (5)(5)(5), then the test of Step (5) at (4)(4)(4) fails for j=2j=2j=2 only because 4>L24>L_24>L2​, Step (6) stops, and the vectors (2),(1)(2),(1)(2),(1), which fit L2L_2L2​, are never examined. With a single stock length (k=1k=1k=1) the statement is the paper's claim in full. Nonnegative prices are a disclosed hypothesis (see the goal theorem).

Preamble
import Mathlib
import Definitions.Def_CuttingStock63_Knapsack_Problem
import Definitions.Def_CuttingStock63_Knapsack_Method
Formal statement
namespace CuttingStock63.Knapsack

/-- Knapsack Method, paragraph after Step (7), p. 868, in corrected form: on every entry to
Step (3) of every run, (i) for every j, c_j ≤ M_j and M_j is c_j or the objective of a vector
satisfying L_j ≥ λ·(α)_m; and (ii) for the longest stock length L_1, every vector satisfying
L_1 ≥ λ·(α)_m that is lexicographically larger than the vector about to be tested has objective
at most M_1. (Clause (ii) fails for the shorter stock lengths: see the Formalization Note.) -/
theorem tested_vector_invariant {m k : ℕ} (hk : 0 < k) (l b : Fin m → ℝ) (L c : Fin k → ℝ)
    (hl : ∀ i, 0 < l i) (hb : ∀ i, 0 ≤ b i)
    (hdens : ∀ i i' : Fin m, i ≤ i' → b i' / l i' ≤ b i / l i) (hL : StrictAnti L)
    (σ : State m k) (hσ : Reachable l b L c hk σ) (hu : σ.phase = .update) :
    (∀ j : Fin k, c j ≤ σ.M j ∧
        (σ.M j = c j ∨ ∃ a : Fin m → ℕ, Fits l (L j) a ∧ bet b a m = σ.M j)) ∧
      ∀ a' : Fin m → ℕ, toLex σ.a < toLex a' → Fits l (L ⟨0, hk⟩) a' →
        bet b a' m ≤ σ.M ⟨0, hk⟩ := by sorry

end CuttingStock63.Knapsack
Source
Gilmore & Gomory, A linear programming approach to the cutting stock problem—Part II, Opns. Res. 11 (1963), p. 868, Knapsack Method, paragraph after Step (7)
Human review
  • Endorsed by Shuze Chen · Oct 6, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Oct 6, 2026

    Confirmed by the mission captain (proposal self-audit).

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