Documentation

CslibFrontier.Foundations.Combinatorics.Sperner

Sperner's lemma on the triangulated square grid #

Cutting each unit cell of the W × H integer grid along its main diagonal triangulates it by the GridTriangles of triangles W H. A colouring c : ℕ × ℕ → Fin 3 of the grid points of the N × N grid is a Sperner colouring (IsSpernerColoring) when it agrees on the boundary with the boundary colouring boundaryColor of Chen, Deng and Teng [CDT09] (Section 4.1, the valid colourings of Theorem 4.1 and Definition 4.4 with d = 2, colour 3 written 0): colour 2 on the bottom edge, colour 1 on the rest of the left edge and colour 0 on the rest of the boundary. Sperner's lemma says that such a colouring has a trichromatic triangle; here it is proved in its parity form, by the path-following argument that underlies PPAD [Pap94b]. (Mathlib's IsAntichain.sperner is Sperner's theorem on antichains, an unrelated result.)

An edge of a triangle whose endpoints are coloured 1 and 2 is a door; traversing the corners counterclockwise, it is an exit (2 then 1, IsExit) or an entry (1 then 2, IsEntry). A triangle has at most one exit and at most one entry, it is trichromatic exactly when it has exactly one door (trichromatic_iff_isSink_or_isSource), and crossing an interior door turns an exit into an entry (gluing, isEntry_across). Crossing interior exits (next) and interior entries (prev) therefore defines a directed graph of in- and out-degree at most one, and counting doors gives, for every colouring of every W × H grid, the index theorem #sinks + #boundary exits = #sources + #boundary entries (card_isSink_add_card_hasBoundaryExit). A Sperner colouring has no boundary exit and exactly one boundary entry, the left edge of start, so it has one more sink than sources and an odd number of trichromatic triangles.

The last section identifies the door graph of a Sperner colouring as an end-of-line graph whose distinguished source is start and whose other unbalanced vertices are exactly the trichromatic triangles (IsSpernerColoring.door_out_iff, IsSpernerColoring.door_in_iff, IsSpernerColoring.trichromatic_iff). The circuit-presented search problem built on it is Cslib.Complexity.Sperner2D.

Main definitions #

Main results #

References #

A triangle of the standard triangulation of the integer grid.

  • lower : Bool

    true for the lower triangle (x, y), (x + 1, y), (x + 1, y + 1) of the cell, false for the upper triangle (x, y), (x + 1, y + 1), (x, y + 1).

  • x : ℕ

    The x-coordinate of the lower-left corner of the cell.

  • y : ℕ

    The y-coordinate of the lower-left corner of the cell.

The corners of a grid triangle, in counterclockwise order.

The triangle on the other side of edge k, from corner t k to corner t (k + 1).

Edge k of t is an interior edge of the W × H grid.

The index of the shared edge in the neighbouring triangle.

t lies in the W × H grid.

Instances For
    @[instance_reducible]
    theorem Cslib.Sperner.GridTriangle.gluing {W H : ℕ} {t : GridTriangle} {k : Fin 3} (ht : InGrid W H t) (hk : interior W H t k = true) :
    InGrid W H (t.across k) ∧ interior W H (t.across k) (t.mate k) = true ∧ (t.across k).across (t.mate k) = t ∧ (t.across k).corner (t.mate k) = t.corner (k + 1) ∧ (t.across k).corner (t.mate k + 1) = t.corner k

    Crossing an interior edge k of a triangle t of the grid leads to a triangle of the grid that shares the edge, traversed in the opposite direction, as its edge mate t k; crossing back returns to t.

    Grid triangles are triples (lower, x, y).

    The triangles of the W × H grid.

    def Cslib.Sperner.IsExit (c : ℕ × ℕ → Fin 3) (t : GridTriangle) (k : Fin 3) :

    Edge k of t is an exit door: its endpoints are coloured 2 then 1.

    Instances For
      def Cslib.Sperner.IsEntry (c : ℕ × ℕ → Fin 3) (t : GridTriangle) (k : Fin 3) :

      Edge k of t is an entry door: its endpoints are coloured 1 then 2.

      Instances For
        @[instance_reducible]
        instance Cslib.Sperner.instDecidableIsExit (c : ℕ × ℕ → Fin 3) (t : GridTriangle) (k : Fin 3) :
        @[instance_reducible]
        instance Cslib.Sperner.instDecidableIsEntry (c : ℕ × ℕ → Fin 3) (t : GridTriangle) (k : Fin 3) :

        The corners of t carry three distinct colours.

        Instances For
          @[instance_reducible]
          theorem Cslib.Sperner.isExit_unique (c : ℕ × ℕ → Fin 3) {t : GridTriangle} {k l : Fin 3} (hk : IsExit c t k) (hl : IsExit c t l) :
          k = l
          theorem Cslib.Sperner.isEntry_unique (c : ℕ × ℕ → Fin 3) {t : GridTriangle} {k l : Fin 3} (hk : IsEntry c t k) (hl : IsEntry c t l) :
          k = l
          theorem Cslib.Sperner.isEntry_across (c : ℕ × ℕ → Fin 3) {W H : ℕ} {t : GridTriangle} {k : Fin 3} (ht : GridTriangle.InGrid W H t) (hk : GridTriangle.interior W H t k = true) (h : IsExit c t k) :
          IsEntry c (t.across k) (t.mate k)

          An exit door of t is an entry door of the neighbouring triangle.

          theorem Cslib.Sperner.isExit_across (c : ℕ × ℕ → Fin 3) {W H : ℕ} {t : GridTriangle} {k : Fin 3} (ht : GridTriangle.InGrid W H t) (hk : GridTriangle.interior W H t k = true) (h : IsEntry c t k) :
          IsExit c (t.across k) (t.mate k)

          An entry door of t is an exit door of the neighbouring triangle.

          def Cslib.Sperner.next (c : ℕ × ℕ → Fin 3) (W H : ℕ) (t : GridTriangle) :

          Follow the interior exit door of t, if any; otherwise stay at t.

          def Cslib.Sperner.prev (c : ℕ × ℕ → Fin 3) (W H : ℕ) (t : GridTriangle) :

          Follow the interior entry door of t backwards, if any; otherwise stay at t.

          theorem Cslib.Sperner.next_eq_across {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} {k : Fin 3} (h : IsExit c t k) (hk : GridTriangle.interior W H t k = true) :
          next c W H t = t.across k
          theorem Cslib.Sperner.next_eq_self {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} (h : ∀ (k : Fin 3), IsExit c t k → GridTriangle.interior W H t k = false) :
          next c W H t = t
          theorem Cslib.Sperner.prev_eq_across {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} {k : Fin 3} (h : IsEntry c t k) (hk : GridTriangle.interior W H t k = true) :
          prev c W H t = t.across k
          theorem Cslib.Sperner.prev_eq_self {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} (h : ∀ (k : Fin 3), IsEntry c t k → GridTriangle.interior W H t k = false) :
          prev c W H t = t
          theorem Cslib.Sperner.prev_next {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} {k : Fin 3} (ht : GridTriangle.InGrid W H t) (h : IsExit c t k) (hk : GridTriangle.interior W H t k = true) :
          prev c W H (next c W H t) = t
          theorem Cslib.Sperner.next_prev {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} {k : Fin 3} (ht : GridTriangle.InGrid W H t) (h : IsEntry c t k) (hk : GridTriangle.interior W H t k = true) :
          next c W H (prev c W H t) = t

          Doors and the index theorem #

          t has an exit door.

          Instances For

            t has an entry door.

            Instances For

              t has an exit door that is an interior edge of the W × H grid.

              Instances For

                t has an exit door on the boundary of the W × H grid.

                Instances For

                  t has an entry door that is an interior edge of the W × H grid.

                  Instances For

                    t has an entry door on the boundary of the W × H grid.

                    Instances For

                      A sink of the door graph: an entry door but no exit door.

                      Instances For

                        A source of the door graph: an exit door but no entry door.

                        Instances For
                          @[instance_reducible]
                          @[instance_reducible]
                          @[instance_reducible]
                          @[instance_reducible]
                          @[instance_reducible]
                          @[instance_reducible]
                          @[instance_reducible]
                          @[instance_reducible]

                          A triangle is trichromatic exactly when it is a sink or a source of the door graph.

                          Interior exit doors and interior entry doors are matched by crossing the door.

                          Index theorem for the door graph. In every colouring of the W × H grid, the number of sinks plus the number of boundary exit doors equals the number of sources plus the number of boundary entry doors.

                          Sperner colourings of the square grid #

                          The boundary colouring of the N × N grid (Chen, Deng and Teng, Definition 4.4, d = 2, with their colour 3 written 0): the bottom edge y = 0 has colour 2, the rest of the left edge x = 0 has colour 1, and the rest of the boundary has colour 0.

                          A colouring of the N × N grid is a Sperner colouring if it agrees with boundaryColor on the boundary.

                          The triangle whose left edge is the unique boundary door of a Sperner colouring.

                          In a Sperner colouring of the N × N grid (0 < N), the door graph has exactly one more sink than it has sources.

                          Sperner's lemma, parity form. A Sperner colouring of the N × N grid (0 < N) has an odd number of trichromatic triangles.

                          Sperner's lemma. A Sperner colouring of the N × N grid (0 < N) has a trichromatic triangle.

                          The door graph as an end-of-line graph #

                          theorem Cslib.Sperner.next_eq_self_of_not {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} (h : ¬HasInteriorExit c W H t) :
                          next c W H t = t
                          theorem Cslib.Sperner.prev_eq_self_of_not {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} (h : ¬HasInteriorEntry c W H t) :
                          prev c W H t = t
                          theorem Cslib.Sperner.inGrid_next {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} (ht : GridTriangle.InGrid W H t) :
                          theorem Cslib.Sperner.inGrid_prev {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} (ht : GridTriangle.InGrid W H t) :
                          theorem Cslib.Sperner.next_ne_self_iff {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} :
                          next c W H t ≠ t ↔ HasInteriorExit c W H t
                          theorem Cslib.Sperner.prev_ne_self_iff {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} :
                          prev c W H t ≠ t ↔ HasInteriorEntry c W H t
                          theorem Cslib.Sperner.prev_next_of_hasInteriorExit {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} (ht : GridTriangle.InGrid W H t) (h : HasInteriorExit c W H t) :
                          prev c W H (next c W H t) = t
                          theorem Cslib.Sperner.next_prev_of_hasInteriorEntry {c : ℕ × ℕ → Fin 3} {W H : ℕ} {t : GridTriangle} (ht : GridTriangle.InGrid W H t) (h : HasInteriorEntry c W H t) :
                          next c W H (prev c W H t) = t
                          theorem Cslib.Sperner.IsSpernerColoring.next_ne_start {c : ℕ × ℕ → Fin 3} {N : ℕ} (hc : IsSpernerColoring N c) {t : GridTriangle} (ht : GridTriangle.InGrid N N t) (h : HasInteriorExit c N N t) :
                          next c N N t ≠ start

                          Following an interior exit door never leads back to start: the entry door of start lies on the boundary.

                          theorem Cslib.Sperner.IsSpernerColoring.door_out_iff {c : ℕ × ℕ → Fin 3} {N : ℕ} (hc : IsSpernerColoring N c) {t : GridTriangle} (ht : GridTriangle.InGrid N N t) :
                          prev c N N (next c N N t) = t ∧ next c N N t ≠ t ∧ next c N N t ≠ start ↔ HasExit c t

                          The door graph of a Sperner colouring has an outgoing edge at t exactly when t has an exit door.

                          theorem Cslib.Sperner.IsSpernerColoring.door_in_iff {c : ℕ × ℕ → Fin 3} {N : ℕ} (hc : IsSpernerColoring N c) {t : GridTriangle} (ht : GridTriangle.InGrid N N t) :
                          next c N N (prev c N N t) = t ∧ prev c N N t ≠ t ∧ t ≠ start ↔ HasEntry c t ∧ t ≠ start

                          The door graph of a Sperner colouring has an incoming edge at t exactly when t has an entry door and is not start.

                          Trichromatic triangles are the unbalanced vertices of the door graph. For a Sperner colouring, a triangle t ≠ start is trichromatic exactly when it has exactly one of an entry and an exit door, and start (which always has an entry door) is trichromatic exactly when it has no exit door.