Graph Coloring #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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 fromG
into the complete graph onα
, and colorings have a coercion toV → α
. -
G.colorable n
is the proposition thatG
isn
-colorable, which is whether there exists a coloring with at most n colors. -
G.chromatic_number
is the minimaln
such thatG
isn
-colorable, or0
if it cannot be colored with finitely many colors. -
C.color_class c
is the set of vertices colored byc : α
in the coloringC : G.coloring α
. -
C.color_classes
is 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.
Construct a term of simple_graph.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 simple_graph.hom
,
but with a syntactically better proper coloring hypothesis.)
Equations
- simple_graph.coloring.mk color valid = {to_fun := color, map_rel' := valid}
The color class of a given color.
Equations
- C.color_class c = {v : V | ⇑C v = c}
The set containing all color classes.
Equations
- C.color_classes = (setoid.ker ⇑C).classes
Equations
- simple_graph.coloring.fintype = id (fintype.of_injective coe_fn simple_graph.coloring.fintype._proof_1)
Whether a graph can be colored by at most n
colors.
The coloring of an empty graph.
Equations
The "tautological" coloring of a graph, using the vertices of the graph as colors.
Equations
The chromatic number of a graph is the minimal number of colors needed to color it.
If G
isn't colorable with finitely many colors, this will be 0.
Equations
- G.chromatic_number = has_Inf.Inf {n : ℕ | G.colorable n}
Given an embedding, there is an induced embedding of colorings.
Equations
- G.recolor_of_embedding f = {to_fun := λ (C : G.coloring α), (simple_graph.embedding.complete_graph f).to_hom.comp C, inj' := _}
Given an equivalence, there is an induced equivalence between colorings.
Equations
- G.recolor_of_equiv f = {to_fun := ⇑(G.recolor_of_embedding f.to_embedding), inv_fun := ⇑(G.recolor_of_embedding f.symm.to_embedding), left_inv := _, right_inv := _}
There is a noncomputable embedding of α
-colorings to β
-colorings if
β
has at least as large a cardinality as α
.
Equations
- G.recolor_of_card_le hn = G.recolor_of_embedding _.some
Noncomputably get a coloring from colorability.
Equations
- hc.to_coloring hn = ⇑(G.recolor_of_card_le _) (nonempty.some hc)
The bicoloring of a complete bipartite graph using whether a vertex is on the left or on the right.
Equations
- simple_graph.complete_bipartite_graph.bicoloring V W = simple_graph.coloring.mk (λ (v : V ⊕ W), v.is_right) _