Documentation

CslibFrontier.Algorithms.WordRAM.Refuter4n.InputLayout

Word layout of the input circuit of the 4n - 9d refuter, and its charged decoding #

The input layout of the Word-RAM refuter of issue #4322 (Milestone 4), and a fixed standard-basis program initCode that decodes it and builds the packed initial state initialPacked C of Cslib.Algorithms.WordRAM.Refuter4n.PackedState in memory, with an ExecWithin certificate and an explicit instruction bound in the library's Word-RAM cost model. No running time is claimed here for the refuter as a whole.

Input layout (encode). A circuit C : Circuit (fullSignature 2 Bool) n 1 with s = C.size program lines is the word list [n, s], then the three words LineWords (tag, left, right) of each line in program order, then the number of the output wire. The line words are read off the existing circuit code Circuit.code (codeWords), so wires are their numbers Wire.toNat (input i ↦ i, gate k ↦ n + k). A line .fn op has the 4-bit truth table ttOf of op as tag (below 16) and the numbers of its two wires; a constant line .con c has tag 16 + c and operand words 0. This is a word list for Cslib.WordRAM.Data.init, one field per word, so the program reads each field with one load. It is separate from the bit-string code Cslib.Circuits.Circuit.encCircuit, whose decoding on the Word-RAM would need bit parsing. The words determine the circuit (encode_injective). LineWords has the shape of the gate row GateRow of the packed state but other contents (wire numbers and the constant tags 16 + c, not argument codes), so it is a separate record. At an admitted width every input word fits (inputFits_encode).

Decoding. initCode decodes the lines in one pass in program order, as the one-pass gate-table builder of SemiCircuit.ofCircuitBinary: line j reads the literal codes (litCode) of the earlier lines, absorbs the negations of its operands into its truth table, and is either a function of one operand (unaryLit) or the binary gate n + j with gate row ⟨tt, left, right⟩. The arithmetic decoder that the program computes is private and is proved equal to the builder line by line (literal codes and gate rows) through the public prefix and last-line interface of SemiCircuit.OfCircuit, so the public statement is about initialPacked C itself.

Memory image (Layout, Stored). From a base address, the parameter mask, auxiliary mask, gate mask, output literal and number of pairs, then N gate rows of three words, E equation words, n rows of the parameter map and room for N two-word pair records. layout C places it just past the input (base 4 + 3 s) with N = nameBound C and E = eqnBound C; the program keeps one scratch word per line after it, in [(layout C).top, workEnd C), and states nothing about their final values. Stored L P does not relate the sizes in L to the table lengths of P; a client uses it with layout C and the length facts of Rep. Its tables are fixed-stride record arrays Cslib.WordRAM.Realization.HoldsRecords (gate rows of three words, equation and parameter words of one, pair records of two), so the framing and slicing lemmas of that predicate apply; Stored.of_words builds it from the words of the state, row by row.

Width condition (FitsWidth). w ≥ n + C.size + 2 (the basis of Rep.fits) and w ≥ 7 (the tags 16, 17, and the workspace when n + C.size < 5). At these widths the input words fit (inputFits_encode) and every address of the workspace fits (fits_workEnd). Memory past the input starts at zero, so the zero words of the state (unused gate rows, the equation table, the auxiliary mask, the empty pair list) need no stores.

Bound. exec_initCode: from encode C, at every admitted width, initCode stores initialPacked C at layout C in at most initTime C = 6 n + 73 s + 50 instructions in the library's Word-RAM cost model, counting every load, store, arithmetic and bitwise operation, comparison, branch and loop test, and every cell outside [base, workEnd C) ends as it started. The workspace bound (workEnd C, linear in n + s) and the instruction bound are separate statements.

Main definitions #

Main results #

The input layout #

The three input words of a program line, stored in this order.

  • tag : ℕ

    The truth table ttOf (below 16) of a .fn line, or 16 + c for a constant .con c.

  • left : ℕ

    The wire number of the first operand (0 for a constant line).

  • right : ℕ

    The wire number of the second operand (0 for a constant line).

The words of a line code (Line.code: the operation and the numbers Wire.toNat of the wires it reads): .fn op has the truth table ttOf of op as tag (below 16) and the numbers of its two wires; .con c has tag 16 + c and operand words 0.

The Word-RAM input of a circuit, read off its code Circuit.code (line codes and output wire numbers): [n, s], the three words codeWords of each line, the number of the output wire.

The decoder #

Literal codes #

Validity of the encoding #

Decoding prefixes #

The decoded circuit #

Faithfulness of the input layout #

Faithful layout. The input words determine the circuit.

The memory image of a packed state #

Addresses of a packed state in memory, from the base address base, with N gate rows, E equation words and n rows of the parameter map.

  • base : ℕ

    Address of the parameter mask; then the auxiliary mask, gate mask, output literal and number of pairs.

  • N : ℕ

    Number of gate rows.

  • E : ℕ

    Number of equation words.

  • n : ℕ

    Number of rows of the parameter map.

Word c < 3 of gate row J.

Row i of the parameter map.

Word c < 2 of pair record k (room for N records, Rep.length_pairs_le).

The first address past the packed state.

The memory mem holds the words of the packed state P at the addresses of L. It does not relate the sizes L.N, L.E, L.n to the table lengths of P, so the regions are disjoint only when those lengths are at most the sizes (as for layout C and a state represented by Rep).

theorem Cslib.Algorithms.WordRAM.Refuter4n.Stored.of_words {L : Layout} {P : PackedState} {mem : ℕ → ℕ} (h₀ : mem L.base = P.params) (h₁ : mem (L.base + 1) = P.aux) (h₂ : mem (L.base + 2) = P.gates) (h₃ : mem (L.base + 3) = P.out) (h₄ : mem (L.base + 4) = P.pairs.length) (hg : ∀ J < P.gateRows.length, mem (L.rowAddr J 0) = (P.gateRows.getD J { tt := 0, left := 0, right := 0 }).tt ∧ mem (L.rowAddr J 1) = (P.gateRows.getD J { tt := 0, left := 0, right := 0 }).left ∧ mem (L.rowAddr J 2) = (P.gateRows.getD J { tt := 0, left := 0, right := 0 }).right) (he : ∀ e < P.eqnRows.length, mem (L.eqnAddr e) = P.eqnRows.getD e 0) (hp : ∀ i < P.phiRows.length, mem (L.phiAddr i) = P.phiRows.getD i 0) (hq : ∀ k < P.pairs.length, mem (L.pairAddr k 0) = (P.pairs.getD k (0, 0)).1 ∧ mem (L.pairAddr k 1) = (P.pairs.getD k (0, 0)).2) :
Stored L P mem

Stored from its words, row by row.

The layout of the initial state of C, just past the input: base 4 + 3 C.size, nameBound C gate rows, eqnBound C equation words and n rows of the parameter map. The program keeps one scratch word per line at top + j.

The end of the workspace of the program: the packed state and one scratch word per line.

Admitted word widths: w ≥ n + C.size + 2 (the width basis of Rep.fits) and w ≥ 7 (the tags 16, 17 of constant lines, and the workspace of small circuits).

Fit of the workspace. At an admitted width every address of the program, up to workEnd C = 9 + 16 C.size + 11 n, fits in a word.

Fit of the input. At an admitted width, the input length and every input word (n, the line count, tags below 18, wire words below n + C.size) fit in a word.

The Word-RAM program #

The fixed standard-basis program that decodes the input circuit and builds the packed initial state initialPacked C at the addresses of layout C.

The instruction bound of initCode: 6 n + 73 s + 50 for s = C.size lines.

Charged decoding and initial state. At every admitted width, initCode runs from the input encode C in at most initTime C = 6 n + 73 C.size + 50 instructions (in the library's Word-RAM cost model, every load, store, arithmetic and bitwise operation, branch and loop test counted) and leaves the packed initial state initialPacked C at the addresses of layout C. Every cell outside the workspace [(layout C).base, workEnd C), the input included, ends with its initial value.