Encoding indexed exact covers as positive exact-one triples
DefinitionNQueensComp_NPC_X3CTriplesThe two pin variables have fixed false and true values. Each indexed row has a selection bit and its complement. For each universe element, the formula constrains running prefix sums of the incident selection bits to start at zero and finish at one. The unary bit-string encoding is applied after checking the input incidence matrix.
Definition code
import Definitions.Def_NQueensComp_NPC_MonotoneOccurrenceSplit
import Definitions.Def_CountOrderings_NFree_OracleReduction
import Mathlib.Data.Nat.Pairing
namespace NQueensComp.NPC
open CountOrderings.NFree
/-- A zero wire appears twice in the pin clause, forcing it false. The other wire is true. -/
def x3cTriplePin : List ℕ := [0,0,1]
def x3cRowWire (i : ℕ) := 6*i+2
def x3cNegRowWire (i : ℕ) := 6*i+3
def x3cPrefixWire (j i : ℕ) := 6*Nat.pair j i + 4
def x3cNegPrefixWire (j i : ℕ) := 6*Nat.pair j i + 5
/-- Each column starts with a false prefix and ends with a true prefix. At each step
the prefix can switch from false to true precisely when the selected row covers this column.
Every auxiliary wire is uniquely determined. -/
def x3cTripleCode (I : X3CInstance) : Code6 :=
let rows := List.ofFn fun i : Fin I.n => [x3cRowWire i, x3cNegRowWire i, 0]
let cols := (List.ofFn fun j : Fin (3*I.h) =>
let startStop := [[x3cPrefixWire j 0,x3cPrefixWire j 0,1],
[x3cPrefixWire j I.n,0,0]]
let balance := List.ofFn fun i : Fin (I.n+1) =>
[x3cPrefixWire j i, x3cNegPrefixWire j i,0]
let transitions := List.ofFn fun i : Fin I.n =>
[x3cPrefixWire j i, if j ∈ I.S i then x3cRowWire i else 0,
x3cNegPrefixWire j (i.val+1)]
startStop ++ balance ++ transitions).flatten
x3cTriplePin :: (rows ++ cols)
def x3cTripleBits (x : List Bool) : List Bool :=
match decodeX3C x with
| none => []
| some I => enc6 (x3cTripleCode I)
end NQueensComp.NPC
Source
Construction for the incidence reduction specified in Prove2Me theorem NQueensComp.NPC.x3c_to_monotoneTriples (e04dd6c2-b264-4688-88cc-9364f8a82e43). For the role of positive 1-in-3 SAT see Gent, Jefferson and Nightingale, Complexity of n-Queens Completion (2017), Theorem 4, pp. 820–821, https://doi.org/10.1613/jair.5512.