Documentation

Complexity.Computability.Circuit.Boolean.Iteration.ModulusCounter.Basic

The modular-counter permutation: state, period, and linear-size step circuit #

On 2 k bits split into a k-bit modulus a (leftWord) and a k-bit state b (rightWord), ModulusCounter.power T advances b to (b + T) % a whenever 0 < a and b < a, and fixes all other states (advance). For T = 1, this defines a permutation counterStep k = ModulusCounter.power 1 computed by a native De Morgan circuit of linear size at most 50 * k + 20 (counterStep_circuit, ModulusCounter.exists_linear_circuit).

Every active modulus 1 ≤ a ≤ 2 ^ k - 1 divides ModulusCounter.period k = lcm(1, …, 2 ^ k - 1), and distinct exponents below ModulusCounter.period k give distinct Boolean functions (ModulusCounter.powers_injective, counter_power_ne).

Main definitions #

Main results #

References #

Modular counter semantics and period #

Advance b by T modulo a when 0 < a and b < a; inactive pairs are fixed.

Instances For
    theorem Cslib.Circuits.Boolean.Iteration.ModulusCounter.advance_lt {a b U T : ℕ} (ha : a < U) (hb : b < U) :
    advance a b T < U

    The k-bit modulus word in the first k coordinates.

    Instances For

      The k-bit counter state word in the last k coordinates.

      Instances For

        Pack a k-bit modulus word and a k-bit counter state word into BitString (k + k).

        Instances For

          The T-step modular counter map on BitString (k + k).

          Instances For

            The order lcm(1, …, 2 ^ k - 1) common to every active k-bit modular counter.

            Instances For

              Different residues modulo period k give different Boolean functions.

              Linear-size step circuit #

              Next counter word after one step: increment b modulo a when b < a.

              Instances For
                theorem Cslib.Circuits.Boolean.Iteration.ModulusCounter.synthesis_word_eq {k n : ℕ} (s : Set (BooleanFunction n)) (a b : BitString n → BitVec k) (ha : ∀ (i : Fin k), (fun (x : BitString n) => (a x).getLsbD ↑i) ∈ s) (hb : ∀ (i : Fin k), (fun (x : BitString n) => (b x).getLsbD ↑i) ∈ s) :
                Synthesis interpretation s {fun (x : BitString n) => decide (a x = b x)} (6 * k + 1)

                Equality of two available k-bit words costs at most 6 * k + 1 gates.

                theorem Cslib.Circuits.Boolean.Iteration.ModulusCounter.synthesis_stepValue {k n : ℕ} (src : Set (BooleanFunction n)) (a b : BitString n → BitVec k) (ha : ∀ (i : Fin k), (fun (x : BitString n) => (a x).getLsbD ↑i) ∈ src) (hb : ∀ (i : Fin k), (fun (x : BitString n) => (b x).getLsbD ↑i) ∈ src) (hc : ∀ (v : Bool), (fun (x : BitString n) => v) ∈ src) :
                Synthesis interpretation src (wordWires fun (x : BitString n) => stepValue (a x) (b x)) (50 * k + 18)

                Synthesizing stepValue (a x) (b x) from available words and constants costs at most 50 * k + 18 gates.

                The single-step modular counter power 1 has a De Morgan circuit of size at most 50 * k + 20.

                Top-level counter definitions #

                The modulus as a natural number.

                Instances For

                  Single-step modular counter transition on natural numbers.

                  Instances For

                    Single-step modular counter permutation on BitString (k + k).

                    Instances For

                      Coordinate bits of ModulusCounter.stepValue (ModulusCounter.leftWord x) (ModulusCounter.rightWord x).

                      Instances For
                        theorem Cslib.Circuits.Boolean.Iteration.counterModulus_eq_of_eq {k : ℕ} {x y : BitString (k + k)} (h : (fun (i : Fin k) => x (Fin.castAdd k i)) = fun (i : Fin k) => y (Fin.castAdd k i)) :

                        Distinct exponents below ModulusCounter.period k produce distinct counter powers.

                        The single-step modular counter counterStep k has a De Morgan circuit of size at most 50 * k + 20.