Documentation

Complexitylib.Algebraic.LowerBound.Cutwidth.Halver.Internal

Proofs for ε-halvers #

Let N be a comparator network on n wires with s comparators.

Evaluation #

theorem Algebraic.Cutwidth.Halver.Internal.state_succ {n s : ℕ} (N : ComparatorNetwork n s) {α : Type u_1} [LinearOrder α] (x : Fin n → α) (c : Fin s) :
N.state x (↑c + 1) = N.apply c (N.state x ↑c)
theorem Algebraic.Cutwidth.Halver.Internal.apply_minWire {n s : ℕ} (N : ComparatorNetwork n s) {α : Type u_1} [LinearOrder α] (c : Fin s) (x : Fin n → α) :
N.apply c x (N.minWire c) = min (x (N.minWire c)) (x (N.maxWire c))
theorem Algebraic.Cutwidth.Halver.Internal.apply_maxWire {n s : ℕ} (N : ComparatorNetwork n s) {α : Type u_1} [LinearOrder α] (c : Fin s) (x : Fin n → α) :
N.apply c x (N.maxWire c) = max (x (N.minWire c)) (x (N.maxWire c))
theorem Algebraic.Cutwidth.Halver.Internal.apply_of_ne {n s : ℕ} (N : ComparatorNetwork n s) {α : Type u_1} [LinearOrder α] (c : Fin s) (x : Fin n → α) {w : Fin n} (h₁ : N.minWire c ≠ w) (h₂ : N.maxWire c ≠ w) :
N.apply c x w = x w
theorem Algebraic.Cutwidth.Halver.Internal.apply_eq_self {n s : ℕ} (N : ComparatorNetwork n s) {α : Type u_1} [LinearOrder α] (c : Fin s) (x : Fin n → α) (h : x (N.minWire c) = x (N.maxWire c)) :
N.apply c x = x

A comparator whose two wires carry the same value changes nothing.

theorem Algebraic.Cutwidth.Halver.Internal.eval_eq_self {n s : ℕ} (N : ComparatorNetwork n s) {α : Type u_1} [LinearOrder α] (x : Fin n → α) (h : ∀ (c : Fin s), x (N.minWire c) = x (N.maxWire c)) :
N.eval x = x

An input on which every comparator sees two equal values is fixed by the network.

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

Comparators commute with monotone maps.

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

The network commutes with monotone maps.

Stops along a wire #

The comparators before time t acting on wire w.

Equations
Instances For
    theorem Algebraic.Cutwidth.Halver.Internal.mem_touchSet {n s : ℕ} (N : ComparatorNetwork n s) {w : Fin n} {t : ℕ} {c : Fin s} :
    c ∈ touchSet N w t ↔ ↑c < t ∧ (N.minWire c = w ∨ N.maxWire c = w)
    theorem Algebraic.Cutwidth.Halver.Internal.lastStop_eq {n s : ℕ} (N : ComparatorNetwork n s) (w : Fin n) (t : ℕ) :
    N.lastStop w t = if h : (touchSet N w t).Nonempty then WireVertex.gate ((touchSet N w t).max' h) (decide (N.maxWire ((touchSet N w t).max' h) = w)) else WireVertex.input w

    The time of a vertex: 0 for input terminals, c + 1 for the ends of comparator c, and s + 1 for output terminals.

    Equations
    Instances For
      theorem Algebraic.Cutwidth.Halver.Internal.sideWire_decide {n s : ℕ} (N : ComparatorNetwork n s) {c : Fin s} {w : Fin n} (h : N.minWire c = w ∨ N.maxWire c = w) :
      N.sideWire c (decide (N.maxWire c = w)) = w

      The wire on side decide (maxWire c = w) of a comparator acting on w is w.

      The two sides of a comparator lie on distinct wires.

      theorem Algebraic.Cutwidth.Halver.Internal.le_rank_lastStop {n s : ℕ} (N : ComparatorNetwork n s) {w : Fin n} {t : ℕ} {c : Fin s} (hc : ↑c < t) (hw : N.minWire c = w ∨ N.maxWire c = w) :
      ↑c + 1 ≤ rank (N.lastStop w t)
      theorem Algebraic.Cutwidth.Halver.Internal.lastStop_succ_of_touch {n s : ℕ} (N : ComparatorNetwork n s) {w : Fin n} (c : Fin s) (hw : N.minWire c = w ∨ N.maxWire c = w) :
      N.lastStop w (↑c + 1) = WireVertex.gate c (decide (N.maxWire c = w))
      theorem Algebraic.Cutwidth.Halver.Internal.lastStop_succ_of_not_touch {n s : ℕ} (N : ComparatorNetwork n s) {w : Fin n} (c : Fin s) (h₁ : N.minWire c ≠ w) (h₂ : N.maxWire c ≠ w) :
      N.lastStop w (↑c + 1) = N.lastStop w ↑c

      The wire graph #

      theorem Algebraic.Cutwidth.Halver.Internal.exists_touch_of_segTime_lt {n s : ℕ} (N : ComparatorNetwork n s) {e : WireEdge n s} (he : IsSegment e) (ht : segTime e < s) :
      ∃ (c : Fin s), ↑c = segTime e ∧ (N.minWire c = segWire N e ∨ N.maxWire c = segWire N e)

      A wire segment ending at time t < s enters a comparator acting on its wire.

      theorem Algebraic.Cutwidth.Halver.Internal.eq_of_segWire_eq_of_segTime_eq {n s : ℕ} (N : ComparatorNetwork n s) {e e' : WireEdge n s} (he : IsSegment e) (he' : IsSegment e') (hw : segWire N e = segWire N e') (ht : segTime e = segTime e') :
      e = e'

      Two wire segments ending at the same time on the same wire are equal.

      theorem Algebraic.Cutwidth.Halver.Internal.eq_of_fst_eq {n s : ℕ} (N : ComparatorNetwork n s) {e e' : WireEdge n s} (he : IsSegment e) (he' : IsSegment e') (h : N.wireGraph.fst e = N.wireGraph.fst e') :
      e = e'

      At most one wire segment leaves a vertex.

      theorem Algebraic.Cutwidth.Halver.Internal.eq_of_snd_eq {n s : ℕ} (N : ComparatorNetwork n s) {e e' : WireEdge n s} (he : IsSegment e) (he' : IsSegment e') (h : N.wireGraph.snd e = N.wireGraph.snd e') :
      e = e'

      At most one wire segment enters a vertex.

      The wire graph has maximum degree three.

      Counting vertices and edges #

      The vertices as a sum type.

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

        The edges as a sum type.

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

          Token conservation #

          1 on vertices in L and 0 elsewhere.

          Equations
          Instances For

            The tokens carried by an edge on input x: the value of its wire for a wire segment, and for the link of a comparator 1 exactly when its minWire input is 1 and its maxWire input 0.

            Equations
            Instances For
              theorem Algebraic.Cutwidth.Halver.Internal.flow_nonneg {n s : ℕ} (N : ComparatorNetwork n s) (x : Fin n → Bool) (e : WireEdge n s) :
              0 ≤ flow N x e
              theorem Algebraic.Cutwidth.Halver.Internal.flow_le_one {n s : ℕ} (N : ComparatorNetwork n s) (x : Fin n → Bool) (e : WireEdge n s) :
              flow N x e ≤ 1
              def Algebraic.Cutwidth.Halver.Internal.crossing {n s : ℕ} (N : ComparatorNetwork n s) (x : Fin n → Bool) (L : Finset (WireVertex n s)) (e : WireEdge n s) :

              The net flow out of L along the edge e.

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

                The number of wires carrying 1 at time t whose last vertex before time t lies in L.

                Equations
                Instances For
                  theorem Algebraic.Cutwidth.Halver.Internal.potential_sub_potential_succ {n s : ℕ} (N : ComparatorNetwork n s) (x : Fin n → Bool) (L : Finset (WireVertex n s)) (c : Fin s) :
                  potential N x L ↑c - potential N x L (↑c + 1) = crossing N x L (WireEdge.into c false) + crossing N x L (WireEdge.into c true) + crossing N x L (WireEdge.link c)

                  Conservation at a comparator. Comparator c lowers the potential by the net flow out of L along its two incoming segments and its link.

                  theorem Algebraic.Cutwidth.Halver.Internal.sum_crossing {n s : ℕ} (N : ComparatorNetwork n s) (x : Fin n → Bool) (L : Finset (WireVertex n s)) :
                  ∑ e : WireEdge n s, crossing N x L e = ∑ w : Fin n, ind L (WireVertex.input w) * ↑(x w).toNat - ∑ w : Fin n, ind L (WireVertex.output w) * ↑(N.eval x w).toNat

                  Token conservation. The net flow out of L is the number of ones at input terminals in L minus the number at output terminals in L.

                  theorem Algebraic.Cutwidth.Halver.Internal.sum_ind_mul_toNat {n s : ℕ} (L : Finset (WireVertex n s)) (P : Fin n → WireVertex n s) (y : Fin n → Bool) :
                  ∑ w : Fin n, ind L (P w) * ↑(y w).toNat = ↑{w : Fin n | P w ∈ L ∧ y w = true}.card

                  Counting the wires with a one whose terminal lies in L.

                  theorem Algebraic.Cutwidth.Halver.Internal.crossing_sub_crossing_le {n s : ℕ} (N : ComparatorNetwork n s) (x x' : Fin n → Bool) (L : Finset (WireVertex n s)) (e : WireEdge n s) :
                  crossing N x L e - crossing N x' L e ≤ if N.wireGraph.fst e ∈ L ↔ N.wireGraph.snd e ∈ L then 0 else 1

                  One edge carries a net flow of at most one token across L, in either direction.

                  theorem Algebraic.Cutwidth.Halver.Internal.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

                  The cut bound of token conservation. For any two inputs x and x' and any vertex set L, the cut of L 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.

                  Connectivity #

                  Every vertex is joined to the input terminal of its wire.

                  theorem Algebraic.Cutwidth.Halver.Internal.eq_empty_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) (hk : S.card ≤ n / 2) :
                  S = ∅

                  Small closed sets of wires are empty. If N is an ε-halver with ε < 1/2 and a set S of at most n/2 wires is closed under the comparators, it is empty: the indicator input of S and that of its complement are fixed by the network, and they would put at most ε |S| of the wires of S in each half.

                  theorem Algebraic.Cutwidth.Halver.Internal.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) :

                  Lemma 8: closed sets of wires are trivial. If N is an ε-halver with ε < 1/2, every set of wires closed under the comparators is empty or all wires.

                  theorem Algebraic.Cutwidth.Halver.Internal.wireGraph_connected {n s : ℕ} (N : ComparatorNetwork n s) {ε : ℝ} (hN : N.IsHalver ε) (hε : ε < 1 / 2) :

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

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

                  The edge baseline. An ε-halver with ε < 1/2 on n wires has at least n - 1 comparators: its wire graph is connected.

                  The cut lemma and the bounds #

                  theorem Algebraic.Cutwidth.Halver.Internal.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 for halvers. 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.Halver.Internal.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.Halver.Internal.eventually_le_size_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

                  The asymptotic bound for a general ordering coefficient.