Documentation

Complexitylib.Circuits.Encoding

Encoded fan-in-two circuits #

This module exposes the machine-facing representation of Basis.andOr2 circuits and its correctness theorems.

Main definitions #

Main results #

theorem Complexity.CircuitCode.RawCircuit.decode?_eq_some_iff (bits : List Bool) (circuit : RawCircuit) :
decode? bits = some circuit bits = circuit.encode

Exact decoding succeeds precisely on canonical raw-circuit encodings.

theorem Complexity.CircuitCode.RawCircuit.eval?_isSome_iff (circuit : RawCircuit) (input : List Bool) :
(circuit.eval? input).isSome = true WellFormed input.length circuit

Raw evaluation succeeds precisely for nonempty topologically ordered circuits at the supplied input arity.

theorem Complexity.CircuitCode.evalCode_encodeCircuit {N G : } [NeZero N] (c : Circuit Basis.andOr2 N 1 G) (input : BitString N) :
evalCode N (encodeCircuit c) input.toList = some (c.eval input 0)

Decoding and iteratively evaluating the canonical encoding of a typed fan-in-two circuit returns its typed output.

theorem Complexity.CircuitCode.evalCode_encodeCircuit_of_length {N G : } [NeZero N] (c : Circuit Basis.andOr2 N 1 G) (input : List Bool) (hinput : input.length = N) :
evalCode N (encodeCircuit c) input = some (c.eval (BitString.ofList input hinput) 0)

List-native semantic correctness for an input of the declared arity.

In the library's size convention, which counts internal and output gates but not primary inputs or free negations, unary circuit codes have quadratic length in the input arity and circuit size.