Comparator networks, ε-halvers, and their wire graphs #
A comparator network on n wires with s comparators (ComparatorNetwork n s) applies its
comparators in the order 0, 1, …, s - 1. Comparator c acts on two distinct wires
minWire c and maxWire c: it puts the smaller of their two values on minWire c and the larger
on maxWire c. The wires need not satisfy minWire c < maxWire c. The network acts on wire
values in any linear order (ComparatorNetwork.eval); on {0, 1}, encoded as Bool with
false < true, the minimum is and and the maximum is or.
The bottom half consists of the wires w < ⌊n/2⌋ and the top half of the others. The network
is an ε-halver (ComparatorNetwork.IsHalver) when on every input x ∈ {0, 1}ⁿ with k ≤ n/2
ones, at most ε k ones end in the bottom half, and on every input with k ≤ n/2 zeros, at most
ε k zeros end in the top half. For even n this is the 0-1 form of the ε-halvers of Ajtai,
Komlós and Szemerédi: among the k ≤ n/2 largest inputs at most ε k end in the bottom half, and
among the k smallest at most ε k end in the top half.
The wire graph (ComparatorNetwork.wireGraph) is a directed multigraph. Its vertices
(WireVertex) are an input and an output terminal for every wire and, for every comparator c,
two vertices gate c false and gate c true, the ends of c on minWire c and on maxWire c.
Its edges (WireEdge) are the wire segments, which follow each wire from its input terminal
through the ends of the comparators acting on it, in order, to its output terminal, and for every
comparator a link from gate c false to gate c true. A wire segment is named after the vertex
it enters: into c b enters gate c b and last w enters the output terminal of w. It leaves
lastStop w t, the end on wire w of the last comparator before time t acting on w, or the
input terminal of w if there is none.
A comparator network on n wires with s comparators, applied in the order
0, 1, …, s - 1. Comparator c acts on the distinct wires minWire c and maxWire c.
The wire that receives the smaller value at comparator
c.The wire that receives the larger value at comparator
c.The two wires of a comparator are distinct.
Instances For
A vertex of the wire graph of a comparator network on n wires with s comparators.
- input
{n s : ℕ}
(w : Fin n)
: WireVertex n s
The input terminal of a wire.
- output
{n s : ℕ}
(w : Fin n)
: WireVertex n s
The output terminal of a wire.
- gate {n s : ℕ} (c : Fin s) (b : Bool) : WireVertex n s
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Algebraic.Cutwidth.instDecidableEqWireVertex.decEq (Algebraic.Cutwidth.WireVertex.input a) (Algebraic.Cutwidth.WireVertex.input b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireVertex.decEq (Algebraic.Cutwidth.WireVertex.input w) (Algebraic.Cutwidth.WireVertex.output w_1) = isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireVertex.decEq (Algebraic.Cutwidth.WireVertex.input w) (Algebraic.Cutwidth.WireVertex.gate c b) = isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireVertex.decEq (Algebraic.Cutwidth.WireVertex.output w) (Algebraic.Cutwidth.WireVertex.input w_1) = isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireVertex.decEq (Algebraic.Cutwidth.WireVertex.output a) (Algebraic.Cutwidth.WireVertex.output b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireVertex.decEq (Algebraic.Cutwidth.WireVertex.output w) (Algebraic.Cutwidth.WireVertex.gate c b) = isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireVertex.decEq (Algebraic.Cutwidth.WireVertex.gate c b) (Algebraic.Cutwidth.WireVertex.input w) = isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireVertex.decEq (Algebraic.Cutwidth.WireVertex.gate c b) (Algebraic.Cutwidth.WireVertex.output w) = isFalse ⋯
Instances For
Equations
- Algebraic.Cutwidth.instFintypeWireVertex = Fintype.ofEquiv (Fin n✝ ⊕ Fin n✝ ⊕ (_ : Fin s✝) × Bool) (Algebraic.Cutwidth.WireVertex.proxyTypeEquiv n✝ s✝)
An edge of the wire graph of a comparator network on n wires with s comparators.
- last
{n s : ℕ}
(w : Fin n)
: WireEdge n s
The last segment of wire
w, which enters its output terminal. - into
{n s : ℕ}
(c : Fin s)
(b : Bool)
: WireEdge n s
The wire segment entering the end
gate c bof comparatorc. - link {n s : ℕ} (c : Fin s) : WireEdge n s
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Algebraic.Cutwidth.instDecidableEqWireEdge.decEq (Algebraic.Cutwidth.WireEdge.last a) (Algebraic.Cutwidth.WireEdge.last b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireEdge.decEq (Algebraic.Cutwidth.WireEdge.last w) (Algebraic.Cutwidth.WireEdge.into c b) = isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireEdge.decEq (Algebraic.Cutwidth.WireEdge.last w) (Algebraic.Cutwidth.WireEdge.link c) = isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireEdge.decEq (Algebraic.Cutwidth.WireEdge.into c b) (Algebraic.Cutwidth.WireEdge.last w) = isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireEdge.decEq (Algebraic.Cutwidth.WireEdge.into c b) (Algebraic.Cutwidth.WireEdge.link c_1) = isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireEdge.decEq (Algebraic.Cutwidth.WireEdge.link c) (Algebraic.Cutwidth.WireEdge.last w) = isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireEdge.decEq (Algebraic.Cutwidth.WireEdge.link c) (Algebraic.Cutwidth.WireEdge.into c_1 b) = isFalse ⋯
- Algebraic.Cutwidth.instDecidableEqWireEdge.decEq (Algebraic.Cutwidth.WireEdge.link a) (Algebraic.Cutwidth.WireEdge.link b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
Instances For
Equations
- Algebraic.Cutwidth.instFintypeWireEdge = Fintype.ofEquiv (Fin n✝ ⊕ (_ : Fin s✝) × Bool ⊕ Fin s✝) (Algebraic.Cutwidth.WireEdge.proxyTypeEquiv n✝ s✝)
Apply comparator c to the wire values x: the smaller of the values on minWire c and
maxWire c goes to minWire c, the larger to maxWire c, and the other wires keep their
values.
Equations
Instances For
The wire values after the first t comparators, on input x.
Equations
Instances For
The output of the network on input x: the wire values after all s comparators.
Instances For
N is an ε-halver. The bottom half is the wires w < ⌊n/2⌋ and the top half the others.
On every input x ∈ {0, 1}ⁿ with k ≤ n/2 ones (true), at most ε k ones end in the bottom
half; on every input with k ≤ n/2 zeros (false), at most ε k zeros end in the top half.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The vertex of wire w last visited before time t: the end on w of the last comparator
c < t acting on w, or the input terminal of w if no comparator before time t acts on
it.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The wire graph of N. The segment last w runs from the last vertex of wire w to its
output terminal, the segment into c b from the previous vertex of wire sideWire c b to the
end gate c b, and the link of comparator c from gate c false to gate c true.
Equations
- One or more equations did not get rendered due to their size.