Documentation

Complexitylib.Algebraic.LowerBound.Cutwidth.Halver

ε-halvers need (1 + κ (1 - 2ε)/2 - o(1)) n comparators #

A comparator network (ComparatorNetwork n s) on n wires applies s comparators in order; comparator c puts the smaller of the values on its two distinct wires on minWire c and the larger on maxWire c. It is an ε-halver (ComparatorNetwork.IsHalver) when on every input in {0, 1}ⁿ with k ≤ n/2 ones at most ε k ones end in the bottom half (the wires w < ⌊n/2⌋), and on every input with k ≤ n/2 zeros at most ε k zeros end in the top half.

For every 0 ≤ ε < 1/2 and δ > 0, and all large n, every ε-halver on n wires has at least (1 + κ (1 - 2ε)/2 - δ) n comparators (eventually_le_size_of_isHalver), where κ = π/(3 arccos((1 + 2√2)/4)) ≈ 3.5625 is 1/(2p) for the Gaussian edge-score pathwidth coefficient p. As ε → 0 this is about 2.78 n; at ε = 1/10 about 2.43 n. With the rational ordering coefficient 9/32 ≥ 2p it is at least (1 + 16 (1 - 2ε)/9 - δ) n, and with the Fomin–Høie coefficient 1/3 it is (1 + 3 (1 - 2ε)/2 - δ) n. Ajtai, Komlós and Szemerédi (1983) build ε-halvers of linear size from expanders, and Seiferas (Sorting networks of logarithmic depth, further simplified, Algorithmica 53, 2009) and Paterson (Improved sorting networks with O(log N) depth, Algorithmica 5, 1990) study their depth and size from above; no size lower bound for ε-halvers beyond the trivial n - 1 of connectivity (IsHalver.le_add_one) was found in the literature.

theorem Algebraic.Cutwidth.ComparatorNetwork.eval_comp {n s : ℕ} (N : ComparatorNetwork n s) {α : Type u_1} {β : Type u_2} [LinearOrder α] [LinearOrder β] {f : α → β} (hf : Monotone f) (x : Fin n → α) :
N.eval (f ∘ x) = f ∘ N.eval x

The network commutes with monotone maps. For a monotone f, evaluating on f ∘ x gives f applied to the output on x. Taking f a threshold map to Bool, this is the 0-1 principle behind the 0-1 form of the halver property.

The wire graph has 2 n + 2 s vertices: two terminals per wire and two ends per comparator.

The wire graph has n + 3 s edges: n + 2 s wire segments and s links.

The wire graph has maximum degree three.

theorem Algebraic.Cutwidth.ComparatorNetwork.sub_le_card_cut {n s : ℕ} (N : ComparatorNetwork n s) (x x' : Fin n → Bool) (L : Finset (WireVertex n s)) :
↑{w : Fin n | WireVertex.input w ∈ L ∧ x w = true}.card - ↑{w : Fin n | WireVertex.output w ∈ L ∧ N.eval x w = true}.card - (↑{w : Fin n | WireVertex.input w ∈ L ∧ x' w = true}.card - ↑{w : Fin n | WireVertex.output w ∈ L ∧ N.eval x' w = true}.card) ≤ ↑(N.wireGraph.cut L).card

Token conservation. For inputs x and x' in {0, 1}ⁿ and a vertex set L, the cut of L in the wire graph has at least net x - net x' edges, where net y is the number of ones of y at input terminals in L minus the number of ones of N.eval y at output terminals in L.

theorem Algebraic.Cutwidth.ComparatorNetwork.IsHalver.eq_empty_or_eq_univ_of_closed {n s : ℕ} {N : ComparatorNetwork n s} {ε : ℝ} (hN : N.IsHalver ε) (hε : ε < 1 / 2) {S : Finset (Fin n)} (hS : ∀ (c : Fin s), N.minWire c ∈ S ↔ N.maxWire c ∈ S) :

Closed sets of wires are trivial. For an ε-halver with ε < 1/2, every set of wires closed under the comparators (each comparator has both wires in it or neither) is empty or all wires.

The wire graph of an ε-halver with ε < 1/2 is connected.

theorem Algebraic.Cutwidth.ComparatorNetwork.IsHalver.le_add_one {n s : ℕ} {N : ComparatorNetwork n s} {ε : ℝ} (hN : N.IsHalver ε) (hε : ε < 1 / 2) :
n ≤ s + 1

The trivial bound. An ε-halver with ε < 1/2 on n wires has at least n - 1 comparators.

theorem Algebraic.Cutwidth.ComparatorNetwork.IsHalver.exists_le_card_cut {n s : ℕ} {N : ComparatorNetwork n s} {ε : ℝ} (hN : N.IsHalver ε) [LinearOrder (WireVertex n s)] :
∃ (L : Finset (WireVertex n s)), IsLowerSet ↑L ∧ (1 - 2 * ε) * ↑(n / 2) ≤ ↑(N.wireGraph.cut L).card

The cut lemma. Every linear order of the vertices of the wire graph of an ε-halver has a lower set whose cut has at least (1 - 2 ε) ⌊n/2⌋ edges.

theorem Algebraic.Cutwidth.ComparatorNetwork.IsHalver.le_of_orderingBound {n s : ℕ} {N : ComparatorNetwork n s} {ε A η C : ℝ} (hord : Multigraph.OrderingBound A η C) (hN : N.IsHalver ε) (hε : ε < 1 / 2) :
(1 - 2 * ε) * ↑(n / 2) ≤ (A + η) * max (↑s - ↑n) 0 + 3 * Real.logb 2 (2 * ↑n + 2 * ↑s) + C

The finite bound. Under the graph-ordering hypothesis OrderingBound A η C, an ε-halver with ε < 1/2 on n wires with s comparators satisfies (1 - 2 ε) ⌊n/2⌋ ≤ (A + η) (s - n)⁺ + 3 log₂ (2 n + 2 s) + C.

theorem Algebraic.Cutwidth.ComparatorNetwork.eventually_le_size_of_isHalver_of_orderingBound {A : ℝ} (hA : 0 < A) (hord : ∀ (η : ℝ), 0 < η → ∃ (C : ℝ), Multigraph.OrderingBound A η C) {ε δ : ℝ} (hε₀ : 0 ≤ ε) (hε : ε < 1 / 2) (hδ : 0 < δ) :
∀ᶠ (n : ℕ) in Filter.atTop, ∀ (s : ℕ) (N : ComparatorNetwork n s), N.IsHalver ε → (1 + (1 - 2 * ε) / (2 * A) - δ) * ↑n ≤ ↑s

Comparators from a general ordering coefficient. If A > 0 and every slack η > 0 admits a constant C with OrderingBound A η C, then for every 0 ≤ ε < 1/2, every δ > 0, and all large n, every ε-halver on n wires has at least (1 + (1 - 2ε)/(2A) - δ) n comparators.

theorem Algebraic.Cutwidth.ComparatorNetwork.eventually_le_size_of_isHalver {ε δ : ℝ} (hε₀ : 0 ≤ ε) (hε : ε < 1 / 2) (hδ : 0 < δ) :
∀ᶠ (n : ℕ) in Filter.atTop, ∀ (s : ℕ) (N : ComparatorNetwork n s), N.IsHalver ε → (1 + Real.pi / (3 * Real.arccos ((1 + 2 * √2) / 4)) * (1 - 2 * ε) / 2 - δ) * ↑n ≤ ↑s

ε-halvers need (1 + κ (1 - 2ε)/2 - o(1)) n comparators. For every 0 ≤ ε < 1/2, every δ > 0, and all large n, every ε-halver on n wires has at least (1 + κ (1 - 2ε)/2 - δ) n comparators, where κ = π/(3 arccos((1 + 2√2)/4)) ≈ 3.5625: about 2.78 n as ε → 0.

theorem Algebraic.Cutwidth.ComparatorNetwork.eventually_one_add_sixteen_div_nine_mul_le_size_of_isHalver {ε δ : ℝ} (hε₀ : 0 ≤ ε) (hε : ε < 1 / 2) (hδ : 0 < δ) :
∀ᶠ (n : ℕ) in Filter.atTop, ∀ (s : ℕ) (N : ComparatorNetwork n s), N.IsHalver ε → (1 + 16 * (1 - 2 * ε) / 9 - δ) * ↑n ≤ ↑s

ε-halvers need (1 + 16 (1 - 2ε)/9 - o(1)) n comparators. The rational form of eventually_le_size_of_isHalver, from the ordering coefficient 9/32 ≥ 2p: at least (25/9 - δ) n comparators as ε → 0.

theorem Algebraic.Cutwidth.ComparatorNetwork.eventually_one_add_three_div_two_mul_le_size_of_isHalver {ε δ : ℝ} (hε₀ : 0 ≤ ε) (hε : ε < 1 / 2) (hδ : 0 < δ) :
∀ᶠ (n : ℕ) in Filter.atTop, ∀ (s : ℕ) (N : ComparatorNetwork n s), N.IsHalver ε → (1 + 3 * (1 - 2 * ε) / 2 - δ) * ↑n ≤ ↑s

The cubic pathwidth coefficient. With the Fomin–Høie ordering coefficient 1/3, every ε-halver on n wires has at least (1 + 3 (1 - 2ε)/2 - δ) n comparators for all large n.