NP checker for BundleMVL-2: integer-list codes, certificates, and the shape / canonicity / revenue conditions
DefinitionMultiPurchase_Hardness_CheckerAuxiliary 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 products is the binary code encInts c of the integer list
where are the rationals of the instance in the order , , the pair weights (, row by row), and . There are of them, and the pair () sits at position
of the pair block. chkNum c t, chkDen c t and chkRat c t chkNum c t / chkDen c t read the -th rational.
Checker input. A certificate is the indicator vector of a recommendation set ; the checker reads the word chkWord c d encInts c over the alphabet Option (BSym ⊕ Bool) (none is the separator ).
Conditions.
ShapeOK c d: , has exactly entries, , every revenue numerator is positive, every weight numerator (, ) is nonnegative and the numerator of 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 ,
which (for a well-formed instance, whose denominator is positive) is exactly of eq. (4).
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