Documentation

Complexitylib.Algebraic.LowerBound.Cutwidth.Wiring

The wiring graph of a binary circuit #

Fix a program over the full binary basis and an output gate. The reachable wires are the output gate and, recursively, the argument wires of reachable gates. The wiring graph has a vertex for every reachable wire and, for a signal feeding f ≥ 2 gate slots, f - 1 copy vertices of degree three through which the signal is routed. Its edges are the slots of reachable gates and the incoming edge of every copy vertex.

Each edge carries one bit. A gate vertex checks that its outgoing edge carries the gate's function of its two slot bits, the output gate checks that this value is 1, and a copy vertex checks that all its incident edges agree. An input vertex has no check; its outgoing edge is the port of the variable.

The main results are

theorem Algebraic.Cutwidth.lines_wires_lt {n s : ℕ} (p : Program Binary.signature n s) (g : Fin s) (a : Fin 2) :
↑((p.lines g).wires a).index < n + ↑g

The argument wires of a widened binary line refer to earlier wires.

inductive Algebraic.Cutwidth.Wiring.Reach {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) :
Wire n s → Prop

A wire is reachable when it is the output gate or an argument of a reachable gate.

Instances For
    @[reducible, inline]

    The reachable wires: the signals of the wiring graph.

    Equations
    Instances For
      @[reducible, inline]

      The argument slots of reachable gates.

      Equations
      Instances For
        @[instance_reducible]
        noncomputable instance Algebraic.Cutwidth.Wiring.instFintypeSignal {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) :
        Fintype (Signal p out)

        Reachability is decided classically; the graph is a proof object.

        Equations
        @[instance_reducible]
        noncomputable instance Algebraic.Cutwidth.Wiring.instFintypeSlot {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) :
        Fintype (Slot p out)
        Equations
        def Algebraic.Cutwidth.Wiring.slotSignal {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (t : Slot p out) :
        Signal p out

        The signal read by a slot.

        Equations
        Instances For
          def Algebraic.Cutwidth.Wiring.slotGate {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (t : Slot p out) :
          Signal p out

          The gate owning a slot.

          Equations
          Instances For
            noncomputable def Algebraic.Cutwidth.Wiring.slots {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Signal p out) :
            Finset (Slot p out)

            The slots fed by a signal.

            Equations
            Instances For
              theorem Algebraic.Cutwidth.Wiring.mem_slots {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {w : Signal p out} {t : Slot p out} :
              t ∈ slots p out w ↔ slotSignal p out t = w
              noncomputable def Algebraic.Cutwidth.Wiring.fanout {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Signal p out) :

              The number of slots fed by a signal.

              Equations
              Instances For
                theorem Algebraic.Cutwidth.Wiring.fanout_pos_of_slot {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (t : Slot p out) :
                0 < fanout p out (slotSignal p out t)
                @[reducible, inline]

                A signal feeding f ≥ 2 slots is routed through f - 1 copy vertices.

                Equations
                Instances For
                  @[reducible, inline]

                  Vertices: reachable wires and copy vertices.

                  Equations
                  Instances For
                    @[reducible, inline]

                    Edges: slots of reachable gates and the incoming edges of copy vertices.

                    Equations
                    Instances For
                      noncomputable def Algebraic.Cutwidth.Wiring.slotIndex {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (t : Slot p out) :

                      The position of a slot among the slots of its signal.

                      Equations
                      Instances For
                        theorem Algebraic.Cutwidth.Wiring.slotIndex_lt {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (t : Slot p out) :
                        slotIndex p out t < fanout p out (slotSignal p out t)
                        theorem Algebraic.Cutwidth.Wiring.slotIndex_injective {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {t t' : Slot p out} (hsignal : slotSignal p out t = slotSignal p out t') (hindex : slotIndex p out t = slotIndex p out t') :
                        t = t'

                        Slots of one signal are determined by their positions.

                        noncomputable def Algebraic.Cutwidth.Wiring.copyIndex {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (t : Slot p out) :

                        The copy vertex at which a slot is attached, when its signal has fan-out at least two: slots in order, with the last two slots sharing the last copy.

                        Equations
                        Instances For
                          theorem Algebraic.Cutwidth.Wiring.copyIndex_lt {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (t : Slot p out) (h : 2 ≤ fanout p out (slotSignal p out t)) :
                          copyIndex p out t < fanout p out (slotSignal p out t) - 1
                          noncomputable def Algebraic.Cutwidth.Wiring.fst {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) :
                          Edge p out → Vertex p out

                          The first endpoint of an edge: the signal vertex or copy vertex supplying it.

                          Equations
                          Instances For
                            def Algebraic.Cutwidth.Wiring.snd {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) :
                            Edge p out → Vertex p out

                            The second endpoint of an edge: the gate reading a slot, or the copy vertex.

                            Equations
                            Instances For
                              def Algebraic.Cutwidth.Wiring.signal {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) :
                              Edge p out → Signal p out

                              The signal carried by an edge.

                              Equations
                              Instances For
                                noncomputable def Algebraic.Cutwidth.Wiring.firstOut {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Signal p out) :
                                Edge p out

                                The first outgoing edge of a signal with positive fan-out: the incoming edge of its first copy vertex, or its unique slot.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  theorem Algebraic.Cutwidth.Wiring.fst_inl_of_two_le {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (t : Slot p out) (h : 2 ≤ fanout p out (slotSignal p out t)) :
                                  fst p out (Sum.inl t) = Sum.inr ⟨slotSignal p out t, ⟨copyIndex p out t, ⋯⟩⟩
                                  theorem Algebraic.Cutwidth.Wiring.fst_inl_of_fanout_eq_one {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (t : Slot p out) (h : fanout p out (slotSignal p out t) = 1) :
                                  fst p out (Sum.inl t) = Sum.inl (slotSignal p out t)
                                  theorem Algebraic.Cutwidth.Wiring.fst_inr_zero {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Signal p out) (h : 0 < fanout p out w - 1) :
                                  fst p out (Sum.inr ⟨w, ⟨0, h⟩⟩) = Sum.inl w
                                  theorem Algebraic.Cutwidth.Wiring.fst_inr_succ {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Signal p out) (k : ℕ) (h : k + 1 < fanout p out w - 1) :
                                  fst p out (Sum.inr ⟨w, ⟨k + 1, h⟩⟩) = Sum.inr ⟨w, ⟨k, ⋯⟩⟩
                                  theorem Algebraic.Cutwidth.Wiring.snd_inl {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (t : Slot p out) :
                                  snd p out (Sum.inl t) = Sum.inl (slotGate p out t)
                                  theorem Algebraic.Cutwidth.Wiring.snd_inr {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (c : Copy p out) :
                                  snd p out (Sum.inr c) = Sum.inr c
                                  theorem Algebraic.Cutwidth.Wiring.fanout_eq_one_of_not_two_le {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (t : Slot p out) (h : ¬2 ≤ fanout p out (slotSignal p out t)) :
                                  fanout p out (slotSignal p out t) = 1
                                  theorem Algebraic.Cutwidth.Wiring.signal_eq_of_fst_eq_inl {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {e : Edge p out} {w : Signal p out} (h : fst p out e = Sum.inl w) :
                                  signal p out e = w

                                  The first endpoint of an edge belongs to the tree of its signal.

                                  theorem Algebraic.Cutwidth.Wiring.signal_eq_of_fst_eq_inr {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {e : Edge p out} {w : Signal p out} {k : Fin (fanout p out w - 1)} (h : fst p out e = Sum.inr ⟨w, k⟩) :
                                  signal p out e = w
                                  theorem Algebraic.Cutwidth.Wiring.signal_firstOut {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Signal p out) (h : 0 < fanout p out w) :
                                  signal p out (firstOut p out w) = w
                                  theorem Algebraic.Cutwidth.Wiring.fst_firstOut {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Signal p out) (h : 0 < fanout p out w) :
                                  fst p out (firstOut p out w) = Sum.inl w
                                  theorem Algebraic.Cutwidth.Wiring.eq_firstOut_of_fst_eq_inl {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {e : Edge p out} {w : Signal p out} (h : fst p out e = Sum.inl w) :
                                  e = firstOut p out w

                                  The only edge leaving a signal vertex is its first outgoing edge.

                                  theorem Algebraic.Cutwidth.Wiring.fanout_pos {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Signal p out) (hne : ↑w ≠ Wire.gate out) :
                                  0 < fanout p out w

                                  Every reachable wire other than the output gate feeds a slot.

                                  def Algebraic.Cutwidth.Wiring.opValue {n s : ℕ} (p : Program Binary.signature n s) (out g : Fin s) (h : Reach p out (Wire.gate g)) (α : Edge p out → Bool) :

                                  The value a gate's operation takes on the bits of its two slots.

                                  Equations
                                  Instances For
                                    def Algebraic.Cutwidth.Wiring.Check {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) :
                                    Vertex p out → (Edge p out → Bool) → Prop

                                    The local check of a vertex. A reachable gate requires its outgoing edge, if any, to carry its operation applied to its slot bits, the output gate requires that value to be 1, and a copy vertex requires all its outgoing edges to carry the bit of its incoming edge. Input vertices have no check.

                                    Equations
                                    Instances For
                                      noncomputable def Algebraic.Cutwidth.Wiring.read {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) :

                                      The variables read by the circuit: the reachable input wires.

                                      Equations
                                      Instances For
                                        theorem Algebraic.Cutwidth.Wiring.mem_read {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {j : Fin n} :
                                        j ∈ read p out ↔ Reach p out (Wire.input j)
                                        noncomputable def Algebraic.Cutwidth.Wiring.portVertex {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (j : Fin n) :
                                        Vertex p out

                                        The vertex of an input variable.

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For
                                          noncomputable def Algebraic.Cutwidth.Wiring.portEdge {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (j : Fin n) :
                                          Edge p out

                                          The edge carrying an input variable.

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For
                                            theorem Algebraic.Cutwidth.Wiring.portEdge_of_reach {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {j : Fin n} (h : Reach p out (Wire.input j)) :
                                            portEdge p out j = firstOut p out ⟨Wire.input j, h⟩
                                            noncomputable def Algebraic.Cutwidth.Wiring.network {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) :
                                            Network n (Vertex p out) (Edge p out)

                                            The wiring graph as a constraint network.

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

                                              Semantics #

                                              The value of a gate is its operation applied to the values of its argument wires.

                                              noncomputable def Algebraic.Cutwidth.Wiring.traceAssignment {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (x : Fin n → Bool) :
                                              Edge p out → Bool

                                              The bits carried by the edges under the circuit's own evaluation.

                                              Equations
                                              Instances For
                                                theorem Algebraic.Cutwidth.Wiring.opValue_traceAssignment {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (x : Fin n → Bool) (g : Fin s) (h : Reach p out (Wire.gate g)) :

                                                The evaluation of an accepted input satisfies every check and every port.

                                                theorem Algebraic.Cutwidth.Wiring.copy_eq_firstOut_of_satisfies {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {x : Fin n → Bool} {α : Edge p out → Bool} (hα : (network p out).Satisfies x α) (w : Signal p out) (m : ℕ) (hm : m < fanout p out w - 1) :
                                                α (Sum.inr ⟨w, ⟨m, hm⟩⟩) = α (firstOut p out w)

                                                Under a satisfying assignment, the incoming edge of every copy vertex of a signal carries the bit of the signal's first outgoing edge.

                                                theorem Algebraic.Cutwidth.Wiring.eq_firstOut_of_satisfies {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {x : Fin n → Bool} {α : Edge p out → Bool} (hα : (network p out).Satisfies x α) (w : Signal p out) (e : Edge p out) (he : signal p out e = w) :
                                                α e = α (firstOut p out w)

                                                Under a satisfying assignment, every edge carrying a signal with positive fan-out carries the bit of the signal's first outgoing edge.

                                                theorem Algebraic.Cutwidth.Wiring.eq_trace_of_satisfies {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {x : Fin n → Bool} {α : Edge p out → Bool} (hα : (network p out).Satisfies x α) (w : Signal p out) (e : Edge p out) :
                                                signal p out e = w → α e = p.trace Binary.interpretation x ↑w

                                                Under a satisfying assignment, every edge carries the circuit's value of its signal.

                                                theorem Algebraic.Cutwidth.Wiring.eval_out_eq_true_of_satisfies {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {x : Fin n → Bool} {α : Edge p out → Bool} (hα : (network p out).Satisfies x α) :

                                                A satisfying assignment exists only for accepted inputs.

                                                The wiring network accepts exactly the inputs accepted by the circuit.

                                                Graph properties #

                                                No edge joins a vertex to itself.

                                                noncomputable def Algebraic.Cutwidth.Wiring.outEdges {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (v : Vertex p out) :
                                                Finset (Edge p out)

                                                The edges leaving a vertex.

                                                Equations
                                                Instances For
                                                  noncomputable def Algebraic.Cutwidth.Wiring.inEdges {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (v : Vertex p out) :
                                                  Finset (Edge p out)

                                                  The edges entering a vertex.

                                                  Equations
                                                  Instances For
                                                    theorem Algebraic.Cutwidth.Wiring.mem_outEdges {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {v : Vertex p out} {e : Edge p out} :
                                                    e ∈ outEdges p out v ↔ fst p out e = v
                                                    theorem Algebraic.Cutwidth.Wiring.mem_inEdges {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) {v : Vertex p out} {e : Edge p out} :
                                                    e ∈ inEdges p out v ↔ snd p out e = v
                                                    theorem Algebraic.Cutwidth.Wiring.edgesAt_subset {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (v : Vertex p out) :
                                                    (network p out).edgesAt v ⊆ outEdges p out v ∪ inEdges p out v
                                                    theorem Algebraic.Cutwidth.Wiring.gate_injective {n s : ℕ} {g g' : Fin s} (h : Wire.gate g = Wire.gate g') :
                                                    g = g'
                                                    theorem Algebraic.Cutwidth.Wiring.card_inEdges_inl_le {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Signal p out) :
                                                    (inEdges p out (Sum.inl w)).card ≤ 2

                                                    A signal vertex receives at most two edges: the slots of its gate.

                                                    theorem Algebraic.Cutwidth.Wiring.card_outEdges_inl_le {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Signal p out) :
                                                    (outEdges p out (Sum.inl w)).card ≤ 1

                                                    At most one edge leaves a signal vertex: its first outgoing edge.

                                                    theorem Algebraic.Cutwidth.Wiring.card_inEdges_inr_le {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (c : Copy p out) :
                                                    (inEdges p out (Sum.inr c)).card ≤ 1

                                                    Exactly one edge enters a copy vertex.

                                                    theorem Algebraic.Cutwidth.Wiring.copyIndex_le_slotIndex {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (t : Slot p out) :
                                                    copyIndex p out t ≤ slotIndex p out t

                                                    A slot attached to a copy vertex has its position at least the copy's.

                                                    theorem Algebraic.Cutwidth.Wiring.card_outEdges_inr_le {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Signal p out) (k : Fin (fanout p out w - 1)) :
                                                    (outEdges p out (Sum.inr ⟨w, k⟩)).card ≤ 2

                                                    At most two edges leave a copy vertex: the next copy edge and its slots.

                                                    Every vertex has at most three incident edges.

                                                    def Algebraic.Cutwidth.Wiring.root {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) :
                                                    Vertex p out

                                                    The output gate's vertex.

                                                    Equations
                                                    Instances For
                                                      theorem Algebraic.Cutwidth.Wiring.adj_of_edge {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (e : Edge p out) :
                                                      (network p out).Adj (fst p out e) (snd p out e)
                                                      theorem Algebraic.Cutwidth.Wiring.copy_reaches_signal {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Signal p out) (m : ℕ) (hm : m < fanout p out w - 1) :

                                                      Every copy vertex is joined to its signal vertex along the copy chain.

                                                      theorem Algebraic.Cutwidth.Wiring.signal_reaches_root {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) (w : Wire n s) (h : Reach p out w) :

                                                      Every reachable wire is joined to the output gate.

                                                      The wiring graph is connected.

                                                      Counting vertices and edges #

                                                      @[reducible, inline]

                                                      The reachable gates.

                                                      Equations
                                                      Instances For

                                                        Edges plus signals equal vertices plus slots: both sides count every copy once.

                                                        Every reachable gate has two slots.

                                                        The signals are the reachable inputs and the reachable gates.

                                                        There are fewer copy vertices than slots.

                                                        The vertex count is at most n + 3 s.

                                                        theorem Algebraic.Cutwidth.Wiring.card_edge_sub_card_vertex {n s : ℕ} (p : Program Binary.signature n s) (out : Fin s) :
                                                        ↑(Fintype.card (Edge p out)) - ↑(Fintype.card (Vertex p out)) = ↑(Fintype.card (ReachableGate p out)) - ↑(read p out).card

                                                        Edges minus vertices is reachable gates minus reachable inputs, as reals.