Documentation

Complexity.Computability.Circuit.Boolean.Iteration.CounterBatch

Remainder-power equivalence and batched powers of the modular counter #

Computing the T-th power of the 2 k-bit modular counter (counterStep k) is equivalent up to linear additive overhead to computing the fixed-integer remainder x ↦ T % x on k-bit moduli (counterRemainder_of_power, counterPower_of_remainder).

On a batch of r independent 2 k-bit modular counters (counterBatchPower), all r members can share a single hardwired lookup dictionary a ↦ T % a over the 2 ^ k - 1 positive k-bit moduli (residueKeys, residueValues). Each member then needs only the linear carry-safe residue addition (addResidue), giving a circuit of size at most 40000 * (k + 1) ^ 3 * (2 ^ k + r) for every r ≤ 2 ^ (k + k) (batched_counter_power). Conversely, one block of a batched circuit computes the single power with no extra gates (counterPower_of_batched), and whenever the power is not the identity every block requires its own output gate (counterBatch_size_ge_of_ne_id). Together with the counting lower bound for counterStep k, this yields matching Ω(2 ^ k / k + r) and O(k ^ 3 * (2 ^ k + r)) bounds for batched modular-counter powers (batched_hard_counter_power).

Main definitions #

Main results #

References #

Remainder-power equivalence for counterStep #

@[reducible, inline]

Fixed-integer remainder x ↦ T % x on k-bit words, returning 0 when the modulus is 0.

Instances For

    Carry-safe modular addition addResidue a b r computes ModulusCounter.advance a.toNat b.toNat T whenever r.toNat = T % a.toNat on positive moduli.

    A circuit for (counterStep k)^[T] yields a circuit for counterRemainder T with at most one extra gate.

    A circuit for counterRemainder T yields a circuit for (counterStep k)^[T] with at most 100 * (k + 1) extra gates.

    Batched modular-counter states and dictionary #

    def Cslib.Circuits.Boolean.Iteration.counterBlock {k r : ℕ} (x : BitString (r * (k + k))) (member : Fin r) :
    BitString (k + k)

    Block member of a batched r * (k + k)-bit state.

    Instances For
      def Cslib.Circuits.Boolean.Iteration.counterBatchPower {k r : ℕ} (T : ℕ) (x : BitString (r * (k + k))) :
      BitString (r * (k + k))

      The batched modular-counter power: ModulusCounter.power T applied independently to each of r blocks.

      Instances For
        @[simp]
        theorem Cslib.Circuits.Boolean.Iteration.counterBatchPower_apply {k r : ℕ} (T : ℕ) (x : BitString (r * (k + k))) (member : Fin r) (bit : Fin (k + k)) :

        The batched power is the T-th iterate of the single-step batched update.

        The left half (the modulus) of every state is preserved by ModulusCounter.power T.

        States with modulus zero are fixed by ModulusCounter.power T.

        Dictionary keys: the positive k-bit moduli 1, …, 2 ^ k - 1.

        Instances For

          Dictionary payloads: T % a for the key a = j.val + 1.

          Instances For
            theorem Cslib.Circuits.Boolean.Iteration.clog_two_pow_add_le {k r : ℕ} (hr : r ≤ 2 ^ (k + k)) :
            Nat.clog 2 (r + (2 ^ k - 1)) ≤ 2 * k + 1
            theorem Cslib.Circuits.Boolean.Iteration.batched_counter_power {k : ℕ} (T r : ℕ) (hr : r ≤ 2 ^ (k + k)) :
            ∃ (out : Circuit signature (r * (k + k)) (r * (k + k))), out.Computes interpretation (counterBatchPower T) ∧ out.size ≤ 40000 * (k + 1) ^ 3 * (2 ^ k + r)

            Batched modular-counter upper bound. Using one shared residue dictionary, r independent 2 k-bit modular counters can be advanced by T steps in size at most 40000 * (k + 1) ^ 3 * (2 ^ k + r) for every r ≤ 2 ^ (k + k).

            theorem Cslib.Circuits.Boolean.Iteration.counterPower_of_batched {k r : ℕ} (T : ℕ) (member : Fin r) (c : Circuit signature (r * (k + k)) (r * (k + k))) (hc : c.Computes interpretation (counterBatchPower T)) :

            One block of a batched circuit computes the single power with no extra gates: feed the same state to every block.

            If ModulusCounter.power T is not the identity, every block needs its own output gate.

            Both lower bounds: a batched circuit is at least as large as any circuit for the single power, and, unless the power is the identity, has size at least r.

            theorem Cslib.Circuits.Boolean.Iteration.batched_hard_counter_power (k : ℕ) (hk : 64 ≤ k) :
            ∃ T < ModulusCounter.period k, ∀ (r : ℕ), 0 < r → r ≤ 2 ^ (k + k) → (∃ (out : Circuit signature (r * (k + k)) (r * (k + k))), out.Computes interpretation (counterBatchPower T) ∧ out.size ≤ 40000 * (k + 1) ^ 3 * (2 ^ k + r)) ∧ ∀ (c : Circuit signature (r * (k + k)) (r * (k + k))), c.Computes interpretation (counterBatchPower T) → lowerBudget k < c.size ∧ r ≤ c.size

            Batched hard modular-counter powers. For k ≥ 64, there exists an exponent T < ModulusCounter.period k such that for every 0 < r ≤ 2 ^ (k + k), counterBatchPower T has a circuit of size at most 40000 * (k + 1) ^ 3 * (2 ^ k + r) and every circuit computing it has size greater than lowerBudget k and at least r.