Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

NP checker for BundleMVL-2: integer-list codes, certificates, and the shape / canonicity / revenue conditions

Definition
MultiPurchase_Hardness_Checker

by tianyipeng · Nov 3, 2026 · Mathlib 0df444a (Lean v4.33.1)

choice-modelsmulti-purchasenp-completeness

Auxiliary objects for the NP-membership half of Theorem 1 (the BundleMVL-2 decision language bundleLang is in NP in Cook's sense).

Integer-list form of a code. The code code I κ of an instance with nnn products is the binary code encInts c of the integer list

c=(n, num(q0),den(q0), num(q1),den(q1),… ),c = (n,\ \mathrm{num}(q_0), \mathrm{den}(q_0),\ \mathrm{num}(q_1), \mathrm{den}(q_1), \dots),c=(n, num(q0​),den(q0​), num(q1​),den(q1​),…),

where q0,q1,…q_0, q_1, \dotsq0​,q1​,… are the rationals of the instance in the order r0,…,rn−1r_0,\dots,r_{n-1}r0​,…,rn−1​, V{0},…,V{n−1}V_{\{0\}},\dots,V_{\{n-1\}}V{0}​,…,V{n−1}​, the pair weights V{i,j}V_{\{i,j\}}V{i,j}​ (i<ji<ji<j, row by row), v0v_0v0​ and κ\kappaκ. There are numRats(n)=2n+n(n−1)/2+2\mathrm{numRats}(n) = 2n + n(n-1)/2 + 2numRats(n)=2n+n(n−1)/2+2 of them, and the pair {i,j}\{i,j\}{i,j} (i<ji<ji<j) sits at position

pairIdx(n,i,j)=i n−i(i+1)2+(j−i−1)\mathrm{pairIdx}(n,i,j) = i\,n - \tfrac{i(i+1)}{2} + (j-i-1)pairIdx(n,i,j)=in−2i(i+1)​+(j−i−1)

of the pair block. chkNum c t, chkDen c t and chkRat c t === chkNum c t / chkDen c t read the ttt-th rational.

Checker input. A certificate is the indicator vector d∈{0,1}nd \in \{0,1\}^nd∈{0,1}n of a recommendation set CCC; the checker reads the word chkWord c d === encInts c #\## ddd over the alphabet Option (BSym ⊕ Bool) (none is the separator #\##).

Conditions.

  • ShapeOK c d: n=c0≥0n = c_0 \ge 0n=c0​≥0, ccc has exactly 2 numRats(n)+12\,\mathrm{numRats}(n)+12numRats(n)+1 entries, ∣d∣=n|d| = n∣d∣=n, every revenue numerator is positive, every weight numerator (V{i}V_{\{i\}}V{i}​, V{i,j}V_{\{i,j\}}V{i,j}​) is nonnegative and the numerator of v0v_0v0​ is positive.
  • CanonOK c: every denominator entry is positive and coprime to its numerator (so each pair is the normalized form of its rational).
  • RevOK c d: with xi=dix_i = d_ixi​=di​,
κ(v0+∑ixiV{i}+∑i<jxixjV{i,j})≤∑ixiriV{i}+∑i<jxixj(ri+rj)V{i,j},\kappa\Big(v_0 + \sum_{i} x_i V_{\{i\}} + \sum_{i<j} x_i x_j V_{\{i,j\}}\Big) \le \sum_i x_i r_i V_{\{i\}} + \sum_{i<j} x_i x_j (r_i + r_j) V_{\{i,j\}},κ(v0​+i∑​xi​V{i}​+i<j∑​xi​xj​V{i,j}​)≤i∑​xi​ri​V{i}​+i<j∑​xi​xj​(ri​+rj​)V{i,j}​,

which (for a well-formed instance, whose denominator is positive) is exactly R2(C)≥κR_2(C) \ge \kappaR2​(C)≥κ of eq. (4).

Definition code
import Mathlib
import Definitions.Def_CookPvsNP_defs
import Definitions.Def_ProjSchedTW_Complexity_Encoding
import Definitions.Def_MultiPurchase_Hardness_Model

namespace MultiPurchase.Hardness

open CookPvsNP ProjSchedTW.Complexity

/-! # The NP checker for the BundleMVL-2 decision language

The code `code I κ` of a BundleMVL-2 instance is the binary code `encInts c` of the integer list
`c = n, num(q₀), den(q₀), num(q₁), den(q₁), …` where `q₀, q₁, …` are the instance's rationals in
the order `r₀,…,r_{n-1}, V{0},…,V{n-1}, V{i,j} (i<j, row by row), v0, κ`. A certificate is the
indicator vector `d` of a recommendation set `C`. The checker reads the word
`encInts c # d` (over `Option (BSym ⊕ Bool)`, `none` being `#`). -/

/-- The checker input `encInts c # d`. -/
def chkWord (c : List ℤ) (d : List Bool) : List (Option (BSym ⊕ Bool)) :=
  (encInts c).map (some ∘ Sum.inl) ++ none :: d.map (some ∘ Sum.inr)

/-- The number of rationals in the code of an instance with `n` products:
`n` revenues, `n` singleton weights, `n(n-1)/2` pair weights, `v0` and `κ`. -/
def numRats (n : ℕ) : ℕ := 2 * n + n * (n - 1) / 2 + 2

/-- The position of the pair `{i, j}` (`i < j`) in the row-by-row list of pairs:
`Σ_{i' < i} (n - 1 - i') + (j - i - 1)`. -/
def pairIdx (n i j : ℕ) : ℕ := i * n - i * (i + 1) / 2 + (j - i - 1)

/-- The numerator entry of the `t`-th rational of the integer list `c`. -/
def chkNum (c : List ℤ) (t : ℕ) : ℤ := c.getD (2 * t + 1) 0

/-- The denominator entry of the `t`-th rational of the integer list `c`. -/
def chkDen (c : List ℤ) (t : ℕ) : ℤ := c.getD (2 * t + 2) 0

/-- The `t`-th rational `num / den` of the integer list `c`. -/
def chkRat (c : List ℤ) (t : ℕ) : ℚ := (chkNum c t : ℚ) / (chkDen c t : ℚ)

/-- Shape and sign conditions: `n = c₀ ≥ 0`, `c` holds exactly `numRats n` rationals, the
certificate has `n` bits, the revenue numerators are positive, the weight numerators are
nonnegative and the numerator of `v0` is positive. -/
def ShapeOK (c : List ℤ) (d : List Bool) : Prop :=
  0 ≤ c.getD 0 0 ∧
    c.length = 2 * numRats (c.getD 0 0).toNat + 1 ∧
    d.length = (c.getD 0 0).toNat ∧
    (∀ i, i < (c.getD 0 0).toNat → 0 < chkNum c i) ∧
    (∀ t, (c.getD 0 0).toNat ≤ t → t < numRats (c.getD 0 0).toNat - 2 → 0 ≤ chkNum c t) ∧
    0 < chkNum c (numRats (c.getD 0 0).toNat - 2)

/-- Canonical rationals: every denominator entry is positive and coprime to its numerator. -/
def CanonOK (c : List ℤ) : Prop :=
  ∀ t, t < numRats (c.getD 0 0).toNat →
    0 < chkDen c t ∧ Int.gcd (chkNum c t) (chkDen c t) = 1

/-- The revenue condition `κ · (v0 + Σ V{i} + Σ V{i,j}) ≤ Σ rᵢ V{i} + Σ (rᵢ + rⱼ) V{i,j}`, the sums
running over the products `i` (and pairs `i < j`) selected by the certificate `d`. -/
def RevOK (c : List ℤ) (d : List Bool) : Prop :=
  chkRat c (numRats (c.getD 0 0).toNat - 1) *
      (chkRat c (numRats (c.getD 0 0).toNat - 2) +
        ∑ i ∈ Finset.range (c.getD 0 0).toNat,
          (if d.getD i false then chkRat c ((c.getD 0 0).toNat + i) else 0) +
        ∑ i ∈ Finset.range (c.getD 0 0).toNat, ∑ j ∈ Finset.range (c.getD 0 0).toNat,
          (if i < j ∧ d.getD i false = true ∧ d.getD j false = true then
            chkRat c (2 * (c.getD 0 0).toNat + pairIdx (c.getD 0 0).toNat i j) else 0)) ≤
    ∑ i ∈ Finset.range (c.getD 0 0).toNat,
        (if d.getD i false then chkRat c i * chkRat c ((c.getD 0 0).toNat + i) else 0) +
      ∑ i ∈ Finset.range (c.getD 0 0).toNat, ∑ j ∈ Finset.range (c.getD 0 0).toNat,
        (if i < j ∧ d.getD i false = true ∧ d.getD j false = true then
          (chkRat c i + chkRat c j) *
            chkRat c (2 * (c.getD 0 0).toNat + pairIdx (c.getD 0 0).toNat i j) else 0)

end MultiPurchase.Hardness
Source
Tulabandhula, Sinha, Karra & Patidar, Multi-Purchase Behavior: Modeling, Estimation and Optimization, arXiv:2006.08055v2, p. 17, Theorem 1 (membership half), eq. (4); class NP and checking relations as in S. Cook, The P versus NP problem (Clay Mathematics Institute), §1

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