Resource-accounted circuit composition #
This module exposes serial composition of two circuits over the same basis. The construction shares every inner output and therefore has exact additive size, rather than duplicating the inner circuit once per outer use.
Main results #
Circuit.eval_compose-- exact functional composition.Circuit.size_compose-- exact additive size.Circuit.depth_compose_le-- depth is at most the sum of source depths.
theorem
Complexity.Circuit.wireValue_compose_outer
{B : Basis}
{N K M G₁ G₂ : ℕ}
[NeZero N]
[NeZero K]
[NeZero M]
(outer : Circuit B K M G₂)
(inner : Circuit B N K G₁)
(input : BitString N)
(wire : Fin (K + G₂))
:
Composition preserves outer wire semantics after feeding the inner circuit's result to the outer circuit.
theorem
Complexity.Circuit.wireDepth_compose_outer_le
{B : Basis}
{N K M G₁ G₂ : ℕ}
[NeZero N]
[NeZero K]
[NeZero M]
(outer : Circuit B K M G₂)
(inner : Circuit B N K G₁)
(wire : Fin (K + G₂))
:
Every embedded outer wire has depth at most the inner circuit depth plus its original outer-circuit wire depth.
@[simp]
theorem
Complexity.Circuit.size_compose
{B : Basis}
{N K M G₁ G₂ : ℕ}
[NeZero N]
[NeZero K]
[NeZero M]
(outer : Circuit B K M G₂)
(inner : Circuit B N K G₁)
:
Serial composition has exactly additive size under the library convention.
The K inner output gates become internal gates, so no output gate is lost or
double-counted.