The basic semidefinite relaxation of MAX NAE-3SAT with one vector per literal occurrence
DefinitionPNPMission_BHPZRelaxationThe basic semidefinite relaxation of MAX NAE-3SAT with one vector per literal occurrence, with rational entries.
Let be an instance with clauses, each on three literals. Its literal occurrences are numbered in clause order: clause holds occurrences , , (occLits, occVars).
A rational matrix indexed by is feasible for (Feasible) when
- is positive semidefinite and for every ;
- whenever occurrences and carry the same variable, so they get the same vector;
- for every clause, the three literal correlations (
corrA,corrB,corrD, obtained from the entries of with a sign change for each negated literal) satisfy
that is, they are the pairwise correlations of a probability distribution on the eight assignments of the clause (ClauseLocal).
The relaxed value of a clause is , and the relaxed value of (sdpVal) is the sum over its clauses.
A rational number is written as the sign of its numerator, the absolute value of the numerator and the denominator, each natural number in the encoding natBits of PNPMission_Instances (ratBits). A square matrix is written row by row (matBits).
/-
Definitions for the parts of `PNPMission.bhpz_verdicts`: the basic semidefinite relaxation of
MAX NAE-3SAT with one vector per literal occurrence, with rational entries, and the bit encoding
of a rational matrix.
The `3m` literal occurrences of an instance `Ψ` with `m` clauses are numbered in clause order:
clause `i` holds the occurrences `3i, 3i + 1, 3i + 2` (`occLits`, `occVars`). A rational matrix `X`
indexed by `Fin (3m)` is feasible for `Ψ` when it is positive semidefinite, has unit diagonal,
has entry `1` between two occurrences of the same variable (so that they carry the same vector),
and, for every clause, the three literal correlations `a, b, d` satisfy the four inequalities
`a + b + d ≥ -1`, `a - b - d ≥ -1`, `-a + b - d ≥ -1`, `-a - b + d ≥ -1`, that is, they are the
pairwise correlations of a distribution on the eight `±1` assignments of the clause. The relaxed
value of a clause is `(3 - a - b - d)/4`.
-/
import Mathlib
import Definitions.Def_PNP_ThmMain_Defs
import Definitions.Def_PNPMission_Instances
open PNP.Gadget PNP.Semantics
open PNPMission
namespace PNPMission.BHPZLink
/-- The three literals of a clause. -/
def clauseLits (c : Clause ℕ) : List (ℕ × Bool) := [c.1, c.2.1, c.2.2]
/-- The literal occurrences of an instance, in clause order. -/
def occLits {m : ℕ} (Ψ : Fin m → Clause ℕ) : List (ℕ × Bool) := (List.ofFn Ψ).flatMap clauseLits
/-- The variables of the literal occurrences of an instance, in clause order. -/
def occVars {m : ℕ} (Ψ : Fin m → Clause ℕ) : List ℕ := (occLits Ψ).map Prod.fst
/-- A rational number written as the sign of its numerator, the absolute value of the numerator
and the denominator. -/
def ratBits (q : ℚ) : List Bool :=
[decide (0 ≤ q.num)] ++ natBits q.num.natAbs ++ natBits q.den
/-- A square rational matrix written row by row. -/
def matBits {n : ℕ} (X : Matrix (Fin n) (Fin n) ℚ) : List Bool :=
(List.finRange n).flatMap fun i => (List.finRange n).flatMap fun j => ratBits (X i j)
/-- The entry of `X` at natural-number indices, `0` outside the matrix. -/
def ext {n : ℕ} (X : Matrix (Fin n) (Fin n) ℚ) (a b : ℕ) : ℚ :=
if h : a < n ∧ b < n then X ⟨a, h.1⟩ ⟨b, h.2⟩ else 0
/-- Correlation of the literal of sign `s` at occurrence `p` with the literal of sign `t` at
occurrence `q`: negating one literal negates the correlation. -/
def occCorr {n : ℕ} (X : Matrix (Fin n) (Fin n) ℚ) (p : ℕ) (s : Bool) (q : ℕ) (t : Bool) : ℚ :=
(if s = t then 1 else -1) * ext X p q
/-- Correlation of the first and second literal of clause `i`. -/
def corrA {n : ℕ} (X : Matrix (Fin n) (Fin n) ℚ) (i : ℕ) (c : Clause ℕ) : ℚ :=
occCorr X (3 * i) c.1.2 (3 * i + 1) c.2.1.2
/-- Correlation of the second and third literal of clause `i`. -/
def corrB {n : ℕ} (X : Matrix (Fin n) (Fin n) ℚ) (i : ℕ) (c : Clause ℕ) : ℚ :=
occCorr X (3 * i + 1) c.2.1.2 (3 * i + 2) c.2.2.2
/-- Correlation of the third and first literal of clause `i`. -/
def corrD {n : ℕ} (X : Matrix (Fin n) (Fin n) ℚ) (i : ℕ) (c : Clause ℕ) : ℚ :=
occCorr X (3 * i + 2) c.2.2.2 (3 * i) c.1.2
/-- Relaxed value of clause `i`. -/
def clauseSdp {n : ℕ} (X : Matrix (Fin n) (Fin n) ℚ) (i : ℕ) (c : Clause ℕ) : ℚ :=
(3 - corrA X i c - corrB X i c - corrD X i c) / 4
/-- Relaxed value of an instance. -/
def sdpVal {m n : ℕ} (X : Matrix (Fin n) (Fin n) ℚ) (Ψ : Fin m → Clause ℕ) : ℚ :=
∑ i : Fin m, clauseSdp X i.val (Ψ i)
/-- The four local-distribution inequalities of clause `i`. -/
def ClauseLocal {n : ℕ} (X : Matrix (Fin n) (Fin n) ℚ) (i : ℕ) (c : Clause ℕ) : Prop :=
-1 ≤ corrA X i c + corrB X i c + corrD X i c ∧
-1 ≤ corrA X i c - corrB X i c - corrD X i c ∧
-1 ≤ -corrA X i c + corrB X i c - corrD X i c ∧
-1 ≤ -corrA X i c - corrB X i c + corrD X i c
/-- Feasible solutions of the basic semidefinite relaxation. -/
def Feasible {m : ℕ} (X : Matrix (Fin (3 * m)) (Fin (3 * m)) ℚ) (Ψ : Fin m → Clause ℕ) : Prop :=
(X.map (fun q : ℚ => (q : ℝ))).PosSemidef ∧ (∀ p, X p p = 1) ∧
(∀ i : Fin m, ClauseLocal X i.val (Ψ i)) ∧
∀ p q : Fin (3 * m), (occVars Ψ).getD p.val 0 = (occVars Ψ).getD q.val 0 → X p q = 1
end PNPMission.BHPZLink