Documentation

Complexity.Computability.Circuit.Boolean.Layered

Boolean circuits scheduled in layers #

Each node reads only the preceding layer. Constants allow evaluation with no input wires; copies carry values across layers; NAND nodes may read a wire twice. The last layer supplies all outputs, and the empty program preserves all inputs. Wire indices have binary encodings.

The number of scheduled layers counts copies and empty layers too. It is not identified here with the depth of a De Morgan circuit. Layered.Compile converts ordinary shared circuits into exactly two layers per designated-output depth, with output selection as separate wiring.

Main definitions #

References #

The consecutive-layer presentation, including inserted copy gates, is used in C. Gentry, Fully homomorphic encryption using ideal lattices, Section 2.

A node whose inputs are positions in the preceding layer.

Instances For
    Instances For

      The two tag bits distinguish the four operations; unused wire positions are zero.

      Instances For

        Encode nodes with two operation bits and binary wire indices, including invalid indices.

        Instances For

          A node is valid when each of its references exists in the preceding layer.

          Instances For

            Evaluate one node. Invalid references read false; correctness of a client interpreter may require Node.Valid rather than preserving this fallback.

            Instances For

              Evaluate a layer, preserving its order and repeated references.

              Instances For
                @[simp]
                theorem Cslib.Circuits.Boolean.Layered.length_evalLayer (inputs : List Bool) (layer : List Node) :
                (evalLayer inputs layer).length = layer.length

                Execute the layers in order. No layers means identity, including on an empty input.

                Instances For
                  @[simp]
                  theorem Cslib.Circuits.Boolean.Layered.eval_nil (inputs : List Bool) :
                  eval inputs [] = inputs
                  @[simp]
                  theorem Cslib.Circuits.Boolean.Layered.eval_cons (inputs : List Bool) (layer : List Node) (layers : List (List Node)) :
                  eval inputs (layer :: layers) = eval (evalLayer inputs layer) layers
                  theorem Cslib.Circuits.Boolean.Layered.eval_append (inputs : List Bool) (first second : List (List Node)) :
                  eval inputs (first ++ second) = eval (eval inputs first) second

                  The number of wires after the schedule, retaining the input width for an empty schedule.

                  Instances For
                    @[simp]
                    theorem Cslib.Circuits.Boolean.Layered.outputWidth_nil (inputCount : ℕ) :
                    outputWidth inputCount [] = inputCount
                    @[simp]
                    theorem Cslib.Circuits.Boolean.Layered.outputWidth_cons (inputCount : ℕ) (layer : List Node) (layers : List (List Node)) :
                    outputWidth inputCount (layer :: layers) = outputWidth layer.length layers
                    theorem Cslib.Circuits.Boolean.Layered.outputWidth_append (inputCount : ℕ) (first second : List (List Node)) :
                    outputWidth inputCount (first ++ second) = outputWidth (outputWidth inputCount first) second
                    @[simp]
                    theorem Cslib.Circuits.Boolean.Layered.length_eval (inputs : List Bool) (layers : List (List Node)) :
                    (eval inputs layers).length = outputWidth inputs.length layers

                    Evaluation has the width determined by the syntax, regardless of reference validity.

                    Select output wires in order, allowing repetitions. Selection adds no circuit layer.

                    Instances For
                      @[simp]
                      theorem Cslib.Circuits.Boolean.Layered.length_select (inputs : List Bool) (outputs : List ℕ) :
                      (select inputs outputs).length = outputs.length
                      theorem Cslib.Circuits.Boolean.Layered.eval_take_succ (inputs : List Bool) (layers : List (List Node)) {i : ℕ} (hi : i < layers.length) :
                      eval inputs (List.take (i + 1) layers) = evalLayer (eval inputs (List.take i layers)) (layers.getD i [])

                      Extending a prefix executes precisely its next scheduled layer.

                      All references are in range in the immediately preceding layer.

                      Instances For
                        @[simp]
                        @[simp]
                        theorem Cslib.Circuits.Boolean.Layered.wellFormed_cons (inputCount : ℕ) (layer : List Node) (layers : List (List Node)) :
                        WellFormed inputCount (layer :: layers) ↔ (∀ node ∈ layer, Node.Valid inputCount node) ∧ WellFormed layer.length layers
                        theorem Cslib.Circuits.Boolean.Layered.wellFormed_append (inputCount : ℕ) (first second : List (List Node)) :
                        WellFormed inputCount (first ++ second) ↔ WellFormed inputCount first ∧ WellFormed (outputWidth inputCount first) second
                        theorem Cslib.Circuits.Boolean.Layered.WellFormed.valid_getD {inputs : List Bool} {layers : List (List Node)} (h : WellFormed inputs.length layers) {i : ℕ} (hi : i < layers.length) (node : Node) :
                        node ∈ layers.getD i [] → Node.Valid (eval inputs (List.take i layers)).length node

                        Each scheduled layer reads valid wires of the evaluated prefix.