Documentation

CslibFrontier.Computability.Circuit.Boolean.Iteration.Record

Records for detecting checkpoint hits and repeats #

The fixed-power circuit sorts one array of records. Stored records carry a checkpoint state and a payload, queries carry a state of the orbit prefix and its time, and padding fills the array. Records are sorted by a padding flag followed by their state, so that padding comes last. Both a checkpoint hit and a repeated state appear as two different records with equal keys, and sorting makes such a pair adjacent; a linear scan finds one (detect). The detected pair certifies one of the two situations exactly (detect_sorted_witness), even when complete records repeat. Sorting uses the native Batcher circuit bitonicSortCircuit.

Main definitions #

Main results #

References #

A complete record carried through the sorting network.

  • padding : Bool

    Padding records sort after all others and never collide.

  • state : BitString n

    The state compared by the sort.

  • checkpoint : Bool

    Whether this is a stored checkpoint rather than a query.

  • index : BitVec w

    The time of a query in the orbit prefix.

  • payload : BitString n

    The shifted state stored with a checkpoint.

theorem Cslib.Circuits.Boolean.Iteration.Record.ext {n w : ℕ} {x y : Record n w} (padding : x.padding = y.padding) (state : x.state = y.state) (checkpoint : x.checkpoint = y.checkpoint) (index : x.index = y.index) (payload : x.payload = y.payload) :
x = y
def Cslib.Circuits.Boolean.Iteration.instDecidableEqRecord.decEq {n✝ w✝ : ℕ} (x✝ x✝¹ : Record n✝ w✝) :
Decidable (x✝ = x✝¹)
@[instance_reducible]

The number of bits of a record: its key, then its remaining fields.

The sort key: the padding flag, then the state.

The key coordinates of an encoded record.

The bits of a record: padding flag and state, then checkpoint flag, index and payload.

The record with the given bits; inverse to encode.

@[simp]

Decoding the bit encoding of a record recovers the record.

@[simp]

Encoding the decoded record of a bit string recovers the bit string.

Two records have equal sort keys iff they have the same padding flag and state.

A query for the state at time index of the orbit prefix.

A stored checkpoint with its payload.

Two records collide when neither is padding, their states agree, and they differ.

collision a b holds iff neither record is padding, their states are equal, and the records are distinct.

def Cslib.Circuits.Boolean.Iteration.Record.initial {n w M R : ℕ} (f : BitString n → BitString n) (T K : ℕ) (checkpoints : Fin M → BitString n) (x : BitString n) (j : Fin R) :
Record n w

The initial array: stored checkpoints, then the orbit prefix up to time K, then padding. Checkpoint h stores the state T - K steps later.

def Cslib.Circuits.Boolean.Iteration.Record.Valid {n w M : ℕ} (f : BitString n → BitString n) (T K : ℕ) (checkpoints : Fin M → BitString n) (x : BitString n) (r : Record n w) :

A record that is padding, a stored checkpoint, or a query of the orbit prefix.

inductive Cslib.Circuits.Boolean.Iteration.Record.Witness {n w M : ℕ} (f : BitString n → BitString n) (T K : ℕ) (checkpoints : Fin M → BitString n) (x : BitString n) :
Record n w → Record n w → Prop

What a collision certifies: the prefix reaches a checkpoint, or it repeats.

Sorting and detection #

def Cslib.Circuits.Boolean.Iteration.Record.pack {n w R : ℕ} (records : Fin R → Record n w) :
BitString (R * width n w)

Records stored in consecutive blocks of bits: the encodings joined by BitString.blocksEquiv.symm.

@[simp]
theorem Cslib.Circuits.Boolean.Iteration.Record.block_pack {n w R : ℕ} (records : Fin R → Record n w) (j : Fin R) :
BitString.block (pack records) j = (records j).encode

Extracting the j-th block of pack records gives encode (records j).

Sort records by padding flag and state with the native Batcher circuit.

def Cslib.Circuits.Boolean.Iteration.Record.adjacentPair {n w R : ℕ} (records : Fin R → Record n w) (j : Fin (R - 1)) :
Record n w × Record n w

Two adjacent records of an array.

def Cslib.Circuits.Boolean.Iteration.Record.detect {n w R : ℕ} (records : Fin R → Record n w) :
Record n w × Record n w

The last colliding adjacent pair, or two padding records if there is none.

theorem Cslib.Circuits.Boolean.Iteration.Record.detect_sorted_witness {n w M : ℕ} (f : BitString n → BitString n) (T K d : ℕ) (checkpoints : Fin M → BitString n) (x : BitString n) (hR : M + (K + 1) ≤ BitonicSort.arity d) (hK : K < 2 ^ w) (hcover : (∃ t ≤ K, ∃ (h : Fin M), f^[t] x = checkpoints h) ∨ ∃ (i : ℕ) (j : ℕ), i < j ∧ j ≤ K ∧ f^[i] x = f^[j] x) :
have pair := detect (sorted d (initial f T K checkpoints x)); Witness f T K checkpoints x pair.1 pair.2

If the prefix up to time K reaches a checkpoint or repeats, the detected pair of the sorted initial array is a witness.