Documentation

CslibFrontier.Computability.Circuit.Accumulate

Accumulating circuits #

A sequence of circuits step r : Circuit σ (K₀ + w * r) (K₀ + w * r + w) composes into Circuit.accumulate step R : Circuit σ K₀ (K₀ + w * R): round r reads every value produced so far and appends w new ones. When each round keeps its inputs and appends a block sel r y computed from the values y so far, the output keeps the input (Circuit.eval_accumulate_input), a longer accumulation extends a shorter one (Circuit.eval_accumulate_prefix), and the block of round r is sel r of the output after r rounds (Circuit.eval_accumulate_block). Size, weighted cost, weighted depth and fan-in add up or are inherited round by round.

Unlike Circuit.iterate, the width grows with every round, so later rounds can read the blocks of all earlier ones.

Main definitions #

Main results #

def Cslib.Circuits.Circuit.accumulate {σ : Signature} {K₀ w : ℕ} (step : (r : ℕ) → Circuit σ (K₀ + w * r) (K₀ + w * r + w)) (R : ℕ) :
Circuit σ K₀ (K₀ + w * R)

R rounds composed in sequence: round r maps the K₀ + w * r values produced so far to K₀ + w * r + w values. A wiring cast realigns K₀ + w * r + w with K₀ + w * (r + 1); it adds no gates.

@[simp]
theorem Cslib.Circuits.Circuit.size_accumulate {σ : Signature} {K₀ w : ℕ} (step : (r : ℕ) → Circuit σ (K₀ + w * r) (K₀ + w * r + w)) (R : ℕ) :
(accumulate step R).size = ∑ r ∈ Finset.range R, (step r).size

The size of an accumulation is the sum of the sizes of its rounds.

theorem Cslib.Circuits.Circuit.cost_program_accumulate {σ : Signature} {K₀ w : ℕ} (step : (r : ℕ) → Circuit σ (K₀ + w * r) (K₀ + w * r + w)) (cost : σ.Op → ℕ) (R : ℕ) :
(accumulate step R).program.cost cost = ∑ r ∈ Finset.range R, (step r).program.cost cost

The weighted cost of an accumulation is the sum of those of its rounds.

theorem Cslib.Circuits.Circuit.depthWith_accumulate_le {σ : Signature} {K₀ w : ℕ} (step : (r : ℕ) → Circuit σ (K₀ + w * r) (K₀ + w * r + w)) (cost : σ.Op → ℕ) {D R : ℕ} (h : ∀ r < R, depthWith cost (step r) ≤ D) :
depthWith cost (accumulate step R) ≤ R * D

Rounds of weighted depth at most D accumulate to weighted depth at most R * D.

theorem Cslib.Circuits.Circuit.fanInAtMost_accumulate {σ : Signature} {K₀ w : ℕ} (step : (r : ℕ) → Circuit σ (K₀ + w * r) (K₀ + w * r + w)) {f R : ℕ} (h : ∀ r < R, (step r).FanInAtMost f) :

Rounds of fan-in at most f accumulate to fan-in at most f.

theorem Cslib.Circuits.Circuit.eval_accumulate_prefix {σ : Signature} {K₀ w : ℕ} {step : (r : ℕ) → Circuit σ (K₀ + w * r) (K₀ + w * r + w)} {U : Type u_1} {I : Interpretation σ U} {sel : (r : ℕ) → (Fin (K₀ + w * r) → U) → Fin w → U} (hstep : ∀ (r : ℕ) (y : Fin (K₀ + w * r) → U), (step r).eval I y = Fin.append y (sel r y)) (x : Fin K₀ → U) {r R : ℕ} (hr : r ≤ R) (i : ℕ) (hi : i < K₀ + w * r) :
(accumulate step R).eval I x ⟨i, ⋯⟩ = (accumulate step r).eval I x ⟨i, hi⟩

In an accumulation of rounds that keep their inputs and append sel r, the output after R rounds extends the output after r ≤ R rounds.

theorem Cslib.Circuits.Circuit.eval_accumulate_input {σ : Signature} {K₀ w : ℕ} {step : (r : ℕ) → Circuit σ (K₀ + w * r) (K₀ + w * r + w)} {U : Type u_1} {I : Interpretation σ U} {sel : (r : ℕ) → (Fin (K₀ + w * r) → U) → Fin w → U} (hstep : ∀ (r : ℕ) (y : Fin (K₀ + w * r) → U), (step r).eval I y = Fin.append y (sel r y)) (x : Fin K₀ → U) (R : ℕ) (i : Fin K₀) :
(accumulate step R).eval I x ⟨↑i, ⋯⟩ = x i

In an accumulation of rounds that keep their inputs, the output keeps the input.

theorem Cslib.Circuits.Circuit.eval_accumulate_block {σ : Signature} {K₀ w : ℕ} {step : (r : ℕ) → Circuit σ (K₀ + w * r) (K₀ + w * r + w)} {U : Type u_1} {I : Interpretation σ U} {sel : (r : ℕ) → (Fin (K₀ + w * r) → U) → Fin w → U} (hstep : ∀ (r : ℕ) (y : Fin (K₀ + w * r) → U), (step r).eval I y = Fin.append y (sel r y)) (x : Fin K₀ → U) {r R : ℕ} (hr : r < R) (b : Fin w) :
(accumulate step R).eval I x ⟨K₀ + w * r + ↑b, ⋯⟩ = sel r ((accumulate step r).eval I x) b

In an accumulation of rounds that keep their inputs and append sel r, the block appended in round r < R is sel r of the output after r rounds.