Documentation

Complexitylib.Circuits.Encoding.Defs

Machine-facing encoding of fan-in-two AND/OR circuits #

This file defines a proof-free, on-tape representation of the library's Basis.andOr2 circuits. A raw circuit is an ordered list of gates. For an input arity N, wires 0, ..., N - 1 are primary inputs and gate i produces wire N + i. Thus topological well-formedness says that both references of gate i are strictly less than N + i. The last gate is the sole output.

The evaluator is intentionally iterative. It stores each wire value in an array exactly once, so sharing in the circuit DAG does not cause the recursive recomputation performed by the proof-oriented Circuit.wireValue definition.

The bit format is deterministic and self-delimiting. Naturals use terminated unary (n one-bits followed by a zero-bit), a gate stores three fixed bits and two unary references, and a circuit starts with its unary gate count. Exact decoding rejects truncation and trailing garbage. Unary references make the format polynomially long in the input arity and number of gates; a binary format can be added later without changing the raw circuit semantics.

A proof-free fan-in-two AND/OR gate.

input₀ and input₁ are absolute wire indices. Negation flags are applied before the AND/OR operation, matching Gate.negated in the typed circuit model.

  • op : AndOrOp

    Whether the gate computes AND or OR of its (possibly negated) inputs.

  • input₀ :

    Absolute wire index of the first input.

  • input₁ :

    Absolute wire index of the second input.

  • negated₀ : Bool

    Whether the first input value is negated before applying op.

  • negated₁ : Bool

    Whether the second input value is negated before applying op.

Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[reducible, inline]

      A raw single-output circuit. The output is the value of the last gate.

      Equations
      Instances For

        Both inputs of a gate must refer to already available wires.

        Equations
        Instances For
          @[implicit_reducible]
          Equations

          Boolean checker corresponding to WellFormedAt.

          Equations
          Instances For
            def Complexity.CircuitCode.RawGate.eval (g : RawGate) (value₀ value₁ : Bool) :

            Evaluate a gate once its two (unnegated) input values are known.

            Equations
            Instances For

              Every gate reference points to a primary input or an earlier gate.

              Equations
              Instances For

                A valid single-output raw circuit is nonempty and topologically ordered.

                Equations
                Instances For

                  Boolean checker for the explicit well-formedness predicate.

                  Equations
                  Instances For

                    Evaluate gates in order, appending each result to the memo array.

                    Failure means that a gate contains a forward or out-of-range reference.

                    Equations
                    Instances For

                      Evaluate a raw circuit on a list of primary-input values.

                      The empty gate list has no designated output and is rejected.

                      Equations
                      Instances For

                        Terminated unary fields #

                        Self-delimiting unary: n one-bits followed by a zero terminator.

                        Equations
                        Instances For

                          Gate serialization #

                          Operation bit: one is AND and zero is OR.

                          Equations
                          Instances For

                            Encode a gate as operation, negation flags, then two unary references.

                            Equations
                            Instances For

                              Parse one gate prefix, returning the unconsumed suffix.

                              Equations
                              Instances For

                                Circuit serialization #

                                Parse exactly count gate prefixes and return the remaining suffix.

                                Equations
                                Instances For

                                  Serialize a circuit as its unary gate count followed by its gates.

                                  Equations
                                  Instances For

                                    Decode one circuit prefix and return the unconsumed suffix.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For

                                      Decode exactly one circuit. Any trailing bits are rejected.

                                      Equations
                                      Instances For

                                        Translate a typed fan-in-two gate to the proof-free wire format.

                                        Equations
                                        Instances For

                                          Translate a typed single-output circuit to an ordered raw circuit.

                                          Internal gates retain their order and the typed output gate is appended as the last raw gate.

                                          Equations
                                          Instances For

                                            Serialize a typed fan-in-two circuit as machine-facing bits.

                                            Equations
                                            Instances For

                                              Decode and evaluate a circuit code against an input of exactly N bits.

                                              Equations
                                              Instances For