Graph Coloring #
This module defines colorings of simple graphs (also known as proper colorings in the literature). A graph coloring is the attribution of "colors" to all of its vertices such that adjacent vertices have different colors. A coloring can be represented as a homomorphism into a complete graph, whose vertices represent the colors.
Main definitions #
G.Coloring αis the type ofα-colorings of a simple graphG, withαbeing the set of available colors. The type is defined to be homomorphisms fromGinto the complete graph onα, and colorings have a coercion toV → α.G.Colorable nis the proposition thatGisn-colorable, which is whether there exists a coloring with at most n colors.G.chromaticNumberis the minimalnsuch thatGisn-colorable, or⊤if it cannot be colored with finitely many colors. (Cardinal-valued chromatic numbers are more niche, so we stick toℕ∞.) We writeG.chromaticNumber ≠ ⊤to mean a graph is colorable with finitely many colors.C.colorClass cis the set of vertices colored byc : αin the coloringC : G.Coloring α.C.colorClassesis the set containing all color classes.
TODO #
Gather material from:
Trees
Planar graphs
Chromatic polynomials
develop API for partial colorings, likely as colorings of subgraphs (
H.coe.Coloring α)
An α-coloring of a simple graph G is a homomorphism of G into the complete graph on α.
This is also known as a proper coloring.
Equations
- G.Coloring α = (G →g SimpleGraph.completeGraph α)
Instances For
Construct a term of SimpleGraph.Coloring using a function that
assigns vertices to colors and a proof that it is as proper coloring.
(Note: this is a definitionally the constructor for SimpleGraph.Hom,
but with a syntactically better proper coloring hypothesis.)
Equations
- SimpleGraph.Coloring.mk color valid = { toFun := color, map_rel' := valid }
Instances For
The color class of a given color.
Instances For
The set containing all color classes.
Equations
- C.colorClasses = (Setoid.ker ⇑C).classes
Instances For
Equations
- SimpleGraph.instFintypeColoring = id (Fintype.ofInjective (fun (f : G.Adj →r (SimpleGraph.completeGraph α).Adj) => ⇑f) ⋯)
Equations
- SimpleGraph.instDecidablePredMemSetColorClassOfDecidableEq C = inferInstanceAs (DecidablePred fun (x : V) => x ∈ {v : V | C v = c})
The coloring of an empty graph.
Equations
- G.coloringOfIsEmpty = SimpleGraph.Coloring.mk (fun (a : V) => isEmptyElim a) ⋯
Instances For
If G is n-colorable, then mapping the vertices of G produces an n-colorable simple
graph.
The "tautological" coloring of a graph, using the vertices of the graph as colors.
Equations
Instances For
The chromatic number of a graph is the minimal number of colors needed to color it.
This is ⊤ (infinity) iff G isn't colorable with finitely many colors.
If G is colorable, then ENat.toNat G.chromaticNumber is the ℕ-valued chromatic number.
Equations
- G.chromaticNumber = ⨅ n ∈ setOf G.Colorable, ↑n
Instances For
Given an embedding, there is an induced embedding of colorings.
Equations
- G.recolorOfEmbedding f = { toFun := fun (C : G.Coloring α) => (SimpleGraph.Embedding.completeGraph f).toHom.comp C, inj' := ⋯ }
Instances For
Given an equivalence, there is an induced equivalence between colorings.
Equations
- G.recolorOfEquiv f = { toFun := ⇑(G.recolorOfEmbedding f.toEmbedding), invFun := ⇑(G.recolorOfEmbedding f.symm.toEmbedding), left_inv := ⋯, right_inv := ⋯ }
Instances For
There is a noncomputable embedding of α-colorings to β-colorings if
β has at least as large a cardinality as α.
Equations
- G.recolorOfCardLE hn = G.recolorOfEmbedding ⋯.some
Instances For
Noncomputably get a coloring from colorability.
Equations
- hc.toColoring hn = (G.recolorOfCardLE ⋯) (Nonempty.some hc)
Instances For
If the chromatic number of G is n + 1, then G is colorable in no fewer than n + 1
colors.
The bicoloring of a complete bipartite graph using whether a vertex is on the left or on the right.
Equations
- SimpleGraph.CompleteBipartiteGraph.bicoloring V W = SimpleGraph.Coloring.mk (fun (v : V ⊕ W) => v.isRight) ⋯
Instances For
Cliques #
Given a colouring α of G, and a clique of size at least the number of colours, the clique
contains a vertex of each colour.
The canonical ι-coloring of a completeMultipartiteGraph with parts indexed by ι
Equations
- SimpleGraph.completeMultipartiteGraph.coloring V = SimpleGraph.Coloring.mk (fun (v : (i : ι) × V i) => v.fst) ⋯
Instances For
If H is not n-colorable and G is n-colorable, then G is H.Free.