Compiling shared Boolean circuits into consecutive layers #
Each original depth uses a preparation layer and a finishing layer. Original input and gate values retain their wire numbers. Two further slots per gate hold NAND intermediates, including the two negated operands of OR. Copies carry earlier values between levels. The first layer creates the working slots directly from the original inputs; it requires no padding layer.
Output selection is separate wiring, so an empty schedule preserves depth-zero circuits.
Main definitions #
Cslib.Circuits.Boolean.Layered.prepareLayer: prepare one depth's NAND intermediates.Cslib.Circuits.Boolean.Layered.finishLayer: finish gates at that depth and carry older wires.Cslib.Circuits.Boolean.Layered.schedule: two consecutive layers per original depth.Cslib.Circuits.Boolean.Layered.compile: compute depths, schedule layers, and retain outputs.Cslib.Circuits.Boolean.Layered.encCompiled: encode the layers and binary output indices.
Main results #
Cslib.Circuits.Boolean.Layered.length_compile: exactly twice the designated-output depth.
Compile.Correctness proves well-formedness and semantic preservation. Compile.Size bounds
the complete encoded result; Compile.PolyTime certifies the actual compiler on all raw codes.
References #
Finish a gate using the two scratch positions allocated after all main wires.
Instances For
Compile raw De Morgan code, retaining its designated outputs as free final wiring. Depths are computed from the code, not supplied as extra input. Malformed codes have total fallback behavior; semantic agreement is specified for well-formed circuits.
Instances For
Every scheduled layer has the same working width. The empty schedule still has input width.
The first scratch block stores the first intermediate for an active gate.
The second scratch block stores OR's second negated operand.
The two microlevels compute one De Morgan operation from its original wire values.