Files
math-research/lib/tait_coloring.py
T
2026-04-15 20:23:44 -04:00

19 lines
835 B
Python

"""Utilities for computing Tait colorings from vertex colorings of the dual graph."""
from typing import Any, cast
from sage.all import Graph
from lib.edge_for_dual_edge import get_edge_for_dual_edge
def get_tait_coloring(planar_dual: Graph, coloring: dict[Any, int]) -> dict[Any, int]:
"""Return a Tait (edge 3-coloring) from a vertex 4-coloring of the dual graph."""
tait_coloring: dict[Any, int] = {}
for dual_edge in cast(list[Any], planar_dual.edges()): # type: ignore
edge = get_edge_for_dual_edge(dual_edge)
colors = {coloring[edge[0]], coloring[edge[1]]}
if colors in ({0, 1}, {2, 3}):
tait_coloring[dual_edge] = 0
elif colors in ({1, 2}, {0, 3}):
tait_coloring[dual_edge] = 1
else:
tait_coloring[dual_edge] = 2
return tait_coloring