Signature-generic circuit code combinators and typed fun_prop bridges #
Wire-relocating transformations on raw circuit codes (List (Op × List ℕ) × List ℕ) depend only
on wire numbers, never on the operation type Op:
Circuit.appendCode,Circuit.appendCodes,Circuit.bundleCode: combine raw circuit codes on shared inputs, matchingCircuit.appendandCircuit.pi.Circuit.compCode: sequential composition feeding the outputs of one raw code into the inputs of another, matchingCircuit.comp.Circuit.replicateCode: disjoint-input copies of a raw code, matchingCircuit.replicate.Circuit.formulaCode: instantiate a fixedFormula σ mat raw wire numbers, matchingFormula.renamefollowed byFormula.toCircuit.Circuit.balancedCode: combine raw leaf codes along the exact half-split tree ofCircuit.balancedwithout arity-sized loops.
Each raw combinator is polynomial-time under Circuit.encCode encOp for any explicit operation
encoding encOp : Op ↪ List Bool (with no finiteness assumption on Op), and each has a typed
Circuit.code_* bridge equation. Layering of_enc_eq on those bridges gives direct @[fun_prop]
rules for (fun a => (C a).code) across Circuit.wiring, Circuit.oneGate, Circuit.append,
Circuit.pi, Circuit.comp, Circuit.replicate, Circuit.balanced, and Formula.toCircuit, so
uniform circuit-family proofs compose directly over typed Circuit definitions.
Main definitions #
Cslib.Circuits.Program.appendWireCode: wire-number map under program continuation.Cslib.Circuits.Circuit.shiftCodeWire,Cslib.Circuits.Circuit.shiftCode,Cslib.Circuits.Circuit.appendCode,Cslib.Circuits.Circuit.appendCodes,Cslib.Circuits.Circuit.bundleCode: shared-input raw code combinators.Cslib.Circuits.Circuit.compCodeWire,Cslib.Circuits.Circuit.compCode: sequential raw code composition.Cslib.Circuits.Circuit.replicateWire,Cslib.Circuits.Circuit.replicateCode: disjoint-input raw code replication.Cslib.Circuits.Circuit.formulaCode: raw wire instantiation of a fixedFormula.Cslib.Circuits.Circuit.balancedCode: half-split balanced raw code fold.Cslib.Circuits.Circuit.encWithFinUnary: explicit encoding of(Σ a : α, Fin (k a))pairing an encoded input with a unaryFinindex.Cslib.Circuits.Circuit.ComputableCircuitCode:@[fun_prop]predicate indexing uniform polynomial-time(·.code)generation by the outerCircuitconstructor rather than colliding onCircuit.code.
Main results #
Cslib.Circuits.Program.code_append: code of program continuation.Cslib.Circuits.Circuit.code_oneGate,Cslib.Circuits.Circuit.code_append,Cslib.Circuits.Circuit.code_pi,Cslib.Circuits.Circuit.code_pi_bundle,Cslib.Circuits.Circuit.code_comp,Cslib.Circuits.Circuit.code_replicate,Cslib.Circuits.Circuit.code_balanced,Cslib.Circuits.Circuit.formulaCode_eq_code: typedCircuit.codebridge equations over an arbitrarySignature.Cslib.Circuits.Circuit.computableInPolyTime_appendCode,Cslib.Circuits.Circuit.computableInPolyTime_appendCodes,Cslib.Circuits.Circuit.computableInPolyTime_bundleCode,Cslib.Circuits.Circuit.computableInPolyTime_compCode,Cslib.Circuits.Circuit.computableInPolyTime_replicateCode,Cslib.Circuits.Circuit.computableInPolyTime_formulaCode,Cslib.Circuits.Circuit.computableInPolyTime_balancedCode: polynomial-time raw code combinators.Cslib.Circuits.Circuit.computableInPolyTime_code,Cslib.Circuits.Circuit.computableCircuitCode_id,Cslib.Circuits.Circuit.computableCircuitCode_wiring,Cslib.Circuits.Circuit.computableCircuitCode_append,Cslib.Circuits.Circuit.computableCircuitCode_pi,Cslib.Circuits.Circuit.computableCircuitCode_comp,Cslib.Circuits.Circuit.computableCircuitCode_replicate,Cslib.Circuits.Circuit.computableCircuitCode_balanced,Cslib.Circuits.Circuit.computableCircuitCode_ite: constructor-indexed@[fun_prop]rules for(fun a => (c a).code).Cslib.Circuits.Circuit.computableInPolyTime_code_id,Cslib.Circuits.Circuit.computableInPolyTime_code_wiring,Cslib.Circuits.Circuit.computableInPolyTime_code_oneGate,Cslib.Circuits.Circuit.computableInPolyTime_code_append,Cslib.Circuits.Circuit.computableInPolyTime_code_pi,Cslib.Circuits.Circuit.computableInPolyTime_code_comp,Cslib.Circuits.Circuit.computableInPolyTime_code_replicate,Cslib.Circuits.Circuit.computableInPolyTime_code_balanced,Cslib.Circuits.Formula.computableInPolyTime_code_gate_toCircuit: direct typedComputableInPolyTimecode-generation theorems.
References #
Numbering a continued wire agrees with the raw wire-number map.
Shared-input append and bundling #
Retain an input wire, or shift a gate wire past offset preceding gates.
The serialized code of c.append d is appendCode n c.code d.code.
The serialized code of Circuit.pi cs is appendCodes n of the component codes.
A parallel layer of single-gate circuits lists their gate rows in output order. Since each component returns its gate, its output is relocated past the preceding gates.
Sequential composition #
Disjoint-input replication #
The number of wire i of a circuit with n inputs and s gates in copy t of k
disjoint copies: input i < n is input t * n + i of the replicated circuit, and gate wire
n + g is gate t * s + g of the replicated circuit.
The serialized code of c.replicate k is replicateCode n k c.code.
Single-gate and formula-template serialization #
Polynomial-time certificates for raw combinators #
Shifting wire numbers is polynomial-time with all quantities encoded in binary.
Relocating a circuit-code block is polynomial-time with binary offsets.
Combining circuit codes is polynomial-time, including binary input and wire counts.
Combining arbitrary raw blocks is polynomial-time in their complete encodings. Input and wire numbers are binary; no uniform block-size or well-formedness premise is needed.
Bundling raw blocks is polynomial-time in their encodings and binary layout parameters.
Resolve a composed wire in polynomial time, including binary output lookup and offsets.
Construct sequential circuit codes in polynomial time. All wire indices and input counts are binary; list lengths, input lookup, gate relocation and the whole output code are charged.
Numbering a replicated wire is polynomial-time with all quantities in binary.
Replicating a raw code is polynomial-time, with a binary input count and a unary number of copies.
A fixed formula's instantiated code is polynomial-time in the target input count and
selected binary wire numbers, over any signature σ.
Balanced raw code tree #
Generate the exact half-split code on shared inputs. The supplied fallback is returned only for an empty leaf list. Malformed codes are transformed as data, without arity-sized loops.
The serialized code of Circuit.balanced op unit leaves is balancedCode of their codes,
including empty fallback programs, unused operators, dead gates and intermediate gate order.
Uniform native generation from the binary shared-input count and the complete operator,
fallback and leaf codes, over any operation encoding encOp : Op ↪ List Bool.
Typed @[fun_prop] (·.code) rules #
encWithFinUnary encodes ⟨a, i⟩ as the framed pair (a, i.val) with i.val in unary.
Project the outer input from an encWithFinUnary-encoded dependent pair.
Project the Fin index as a unary natural from an encWithFinUnary-encoded dependent pair.
Project the Fin index as a binary natural from an encWithFinUnary-encoded dependent pair.
Tabulate a runtime-indexed Fin (k a) → β family in polynomial time when k is computed in
unary and the indexed body is polynomial-time on encWithFinUnary enc k.
Emit the code of a typed Circuit.wiring from unary output arity and binary wire indices.
Emit the code of a typed identity circuit Circuit.id σ (n a) from unary arity.
Emit the code of a typed Circuit.oneGate from binary input arity and binary wire indices.
Emit the code of a typed Circuit.append from binary input arity and the two subcircuit
codes.
Emit the code of a typed Circuit.pi family from binary input arity, unary output count, and
uniformly generated component codes.
Emit the code of a typed sequential composition d.comp c from binary input arity and the two
subcircuit codes.
Emit the code of a typed Circuit.replicate from binary input arity, unary copy count, and
the base circuit code.
Emit the code of a typed Circuit.balanced tree from binary input arity and the operator,
fallback, and leaf circuit codes.
Emit the code of a conditional choice of typed circuits.
Uniform polynomial-time generation of the serialized code (c a).code of a typed circuit
family c : (a : α) → Circuit σ (n a) (m a) under explicit input encoding enc and operation
encoding encOp. Indexing @[fun_prop] rules on ComputableCircuitCode keys each rule by its
outer Circuit constructor (comp, append, replicate, wiring, pi, balanced, ite)
instead of colliding on Circuit.code.
Bridge ComputableInPolyTime (fun a => (c a).code) to constructor-indexed
ComputableCircuitCode.
Bridge a plain ComputableInPolyTime (fun a => (c a).code) hypothesis (such as a free
circuit-family parameter) into ComputableCircuitCode.
Extract the underlying ComputableInPolyTime certificate from ComputableCircuitCode.
@[fun_prop] rule for Circuit.id.
@[fun_prop] rule for Circuit.wiring.
@[fun_prop] rule for Circuit.append.
@[fun_prop] rule for Circuit.pi.
@[fun_prop] rule for Circuit.comp.
@[fun_prop] rule for Circuit.replicate.
@[fun_prop] rule for Circuit.balanced.
@[fun_prop] rule for conditional choice of typed circuits.
Emit the circuit code of an input formula (Formula.input (w a)).toCircuit.
Emit the circuit code of a fixed-operation formula node (Formula.gate op (args a)).toCircuit
from binary input arity and the subformula circuit codes.
Emit the circuit code of a conditional choice of formulas
(if p a then t a else e a).toCircuit.