Documentation

CslibFrontier.Algorithms.WordRAM.XORSATDense

Word-RAM dense Gaussian elimination over 𝔽₂ with one row per word #

A checked standard-basis Word-RAM implementation of the dense elimination decider Cslib.Complexity.XORSAT.Dense.decide, with a word-parallel instruction bound.

Representation and width condition. A well-formed m Γ— n instance (Instance: every row has the declared width n) is laid out in input memory as [n, m] followed by one word per row, rowWord e, with coefficient j at bit j and the right-hand side at bit n. Admitted widths (FitsWidth) satisfy w β‰₯ n + 1, so that one row fits in one word, and fit the row addresses 3, …, m + 2. Each ^^^ instruction therefore processes a whole row of n + 1 coefficient bits: the bound 30 (m + 1) (n + 1) counts word instructions under this one-row-per-word convention, and is not the Θ(m nΒ²) bit-operation cost. The packed input is an uncharged representation convention (the Word-RAM input placement convention); it differs from the multi-tape encoding encInput of XORSAT.Dense, and this module makes no claim about running time on that bit encoding.

Domain. The packed words cannot record row lengths, so the domain is restricted to well-formed instances. On that domain the row-width conjunct of XORSAT.Dense.decide is constantly true, and the program computes exactly the elimination part; mem_satisfiable_iff relates the decided set to {q : Input | Width q.width q.rows ∧ Satisfiable q.width q.rows}.

Algorithm. For each column c < n, the program scans the rows for the first word with bit c set (the pivot of XORSAT.Dense.step), then XORs the pivot into every row with bit c set (the pivot row itself becomes zero in its live bits, matching clear p p). It finally checks that no row has bit n set. Every address calculation, load, store, shift, mask, XOR, comparison, loop test and the final halt is charged by the Word-RAM semantics.

Calling convention. The elimination itself is the callable routine elimCode, which takes n, m and the base address b of the packed rows in registers 0, 1 and 2, and returns the answer in register 12. exec_elimCode holds at any base b and any width w β‰₯ n + 1 at which b + m fits, with arbitrary memory outside the window [b, b + m) and arbitrary values in the other registers: the routine returns the same answer within the same 30 (m + 1) (n + 1) bound, and preserves every cell outside the window and registers 0, 1 and 2. program reads the header [n, m] and runs elimCode at b = 3.

Main definitions #

Main results #

References #

Packed rows #

The packed word of a dense row: coefficients at bits 0, …, n - 1, right-hand side at bit n, where n is the number of coefficients (least significant bit first, lsbValue).

Packed rows representing a partially eliminated row #

After c elimination columns of an n-column system, the word x represents the row e (which has n - c remaining coefficients): bit c + j is coefficient j, bit n is the right-hand side, and x has at most n + 1 bits. Bits below c are unconstrained.

The packed word of a row with n coefficients represents it before elimination.

One elimination column on packed rows #

The pivot word for column c: the first row with bit c set, or 0 if there is none.

Eliminate column c from one packed row using the pivot word pv.

One elimination column on packed rows.

Packed rows after the first c elimination columns.

After c ≀ n packed columns, the packed rows represent step^[c] of the system.

On a well-formed instance, the dense decider is the right-hand-side check on the packed rows after width packed columns.

The Word-RAM program #

Pure facts used by the loop invariants #

The elimination pass, a callable routine: every row word x of the window becomes elimWord c pv x. It reads the number of rows m, the base address b, the constant 1, the column c and the word pv from registers 1, 2, 3, 5 and 10 (exec_elimPass).

theorem Cslib.Algorithms.WordRAM.XORSATDense.exec_elimPass {w n b : β„•} (W : List β„•) (y : WordRAM.Data 14) (hm : y.regs 1 = W.length) (hbase : y.regs 2 = b) (hone : y.regs 3 = 1) (hmfit : WordRAM.Fits w (b + W.length)) (hn : WordRAM.Fits w (2 ^ (n + 1) - 1)) (hmem : βˆ€ j < W.length, y.mem (b + j) = W.getD j 0) (hWlt : βˆ€ x ∈ W, x < 2 ^ (n + 1)) (hpv : y.regs 10 < 2 ^ (n + 1)) :
βˆƒ (z : WordRAM.Data 14), WordRAM.ExecWithin w elimPass y z (14 * W.length + 3) ∧ (βˆ€ (i : Fin 14), ↑i < 6 β†’ z.regs i = y.regs i) ∧ (βˆ€ j < W.length, z.mem (b + j) = elimWord (y.regs 5) (y.regs 10) (W.getD j 0)) ∧ βˆ€ (a : β„•), a < b ∨ b + W.length ≀ a β†’ z.mem a = y.mem a

One elimination pass in a caller-given memory window. Let the caller's state y hold m in register 1, a base address b in register 2, 1 in register 3, a column c in register 5 and a word pv < 2 ^ (n + 1) in register 10, with the word W[j] < 2 ^ (n + 1) at address b + j for j < m. Memory outside this window and the other registers are arbitrary. At every width w at which b + m and 2 ^ (n + 1) - 1 fit, elimPass replaces cell b + j by elimWord c pv W[j] within 14 m + 3 instructions, preserves registers 0 to 5, and preserves every memory cell outside [b, b + m).

The callable elimination routine: constants, all elimination columns, the final check. It reads n, m and the base address of the packed rows from registers 0, 1 and 2, and leaves the answer in register 12 (exec_elimCode).

The fixed standard-basis program; its answer is register rOk.

Instances, encoding and the running-time theorem #

@[reducible, inline]

A dense XOR-SAT instance whose rows all have the declared width.

Word-RAM input layout [n, m] ++ packed rows.

Admitted widths: a packed row (n + 1 bits) fits in one word, and so do the row addresses 3, …, m + 2. This is the word-width condition of the bit-packed representation.

theorem Cslib.Algorithms.WordRAM.XORSATDense.exec_elimCode {w b : β„•} (q : Instance) (x : WordRAM.Data 14) (hn : x.regs 0 = (↑q).width) (hm : x.regs 1 = List.length (↑q).rows) (hb : x.regs 2 = b) (hrows : βˆ€ (j : β„•) (hj : j < List.length (↑q).rows), x.mem (b + j) = rowWord (↑q).rows[j]) (hw : (↑q).width + 1 ≀ w) (hfit : WordRAM.Fits w (b + List.length (↑q).rows)) :
βˆƒ (y : WordRAM.Data 14), WordRAM.ExecWithin w elimCode x y (30 * (List.length (↑q).rows + 1) * ((↑q).width + 1)) ∧ y.regs 12 = (Complexity.XORSAT.Dense.decide ↑q).toNat ∧ (βˆ€ (i : Fin 14), ↑i < 3 β†’ y.regs i = x.regs i) ∧ βˆ€ (a : β„•), a < b ∨ b + List.length (↑q).rows ≀ a β†’ y.mem a = x.mem a

Callable dense elimination in a caller-given memory window. Let the caller's state x hold n (the width of q) in register 0, m (the number of rows) in register 1 and a base address b in register 2, with the packed row rowWord of row j at address b + j for j < m. Memory outside this window and the other eleven registers are arbitrary. At every width w β‰₯ n + 1 at which b + m fits, elimCode leaves (XORSAT.Dense.decide q).toNat in register 12 within 30 (m + 1) (n + 1) instructions (no final halt is charged), preserves registers 0, 1 and 2, and preserves every memory cell outside [b, b + m). Window cells and the other registers are left unspecified. A caller with a larger register bank can run elimCode in a renamed bank with ExecWithin.call, which also keeps every register outside that bank.

theorem Cslib.Algorithms.WordRAM.XORSATDense.exec_elimCode_words {w b n : β„•} (W : List β„•) (x : WordRAM.Data 14) (hn : x.regs 0 = n) (hm : x.regs 1 = W.length) (hb : x.regs 2 = b) (hrows : βˆ€ j < W.length, x.mem (b + j) = W.getD j 0) (hWlt : βˆ€ v ∈ W, v < 2 ^ (n + 1)) (hw : n + 1 ≀ w) (hfit : WordRAM.Fits w (b + W.length)) :
βˆƒ (y : WordRAM.Data 14), WordRAM.ExecWithin w elimCode x y (30 * (W.length + 1) * (n + 1)) ∧ y.regs 12 = ((cols W n).all fun (v : β„•) => !v.testBit n).toNat ∧ (βˆ€ (i : Fin 14), ↑i < 3 β†’ y.regs i = x.regs i) ∧ βˆ€ (a : β„•), a < b ∨ b + W.length ≀ a β†’ y.mem a = x.mem a

Callable dense elimination on packed words in a caller-given memory window. Let the caller's state x hold n in register 0, m = W.length in register 1 and a base address b in register 2, with the word W[j] < 2 ^ (n + 1) at address b + j for j < m. Memory outside this window and the other eleven registers are arbitrary. At every width w β‰₯ n + 1 at which b + m fits, elimCode leaves ((cols W n).all fun v => !v.testBit n).toNat in register 12 within 30 (m + 1) (n + 1) instructions, preserves registers 0, 1 and 2, and preserves every memory cell outside [b, b + m).

Word-RAM running time of dense Gaussian elimination over 𝔽₂ (one row per word). The fixed standard-basis program program computes (XORSAT.Dense.decide q).toNat on every well-formed m Γ— n instance, laid out as [n, m] and one packed word per row, in at most 30 (m + 1) (n + 1) word instructions, at every word width w β‰₯ n + 1 at which the row addresses fit (FitsWidth). On this domain the row-width check of decide is constantly true.

Word-RAM decision of dense XOR-SAT. program decides satisfiability of every well-formed m Γ— n dense system in at most 30 (m + 1) (n + 1) word instructions at admitted widths, which have w β‰₯ n + 1 (one packed row per word).

Every well-formed instance has an admitted width at which its encoding fits.

Uniform Word-RAM decidability of dense XOR-SAT by Gaussian elimination with one packed row per word, in at most 30 (m + 1) (n + 1) standard-basis word instructions at word widths w β‰₯ n + 1, bundling width admissibility (inputAdmissible).