Note
Go to the end to download the full example code.
Ramsey’s theorem: R(3,3) = 6#
Searches every red/blue coloring of the edges of K_5 and K_6. K_5 has colorings with no single-colored triangle, such as the pentagon and pentagram, but every one of the 32768 colorings of K_6 contains one.
from itertools import combinations
import matplotlib.pyplot as plt
import numpy as np
from mathematicskit.combinatorics import count_triangle_free_colorings, has_monochromatic_triangle
Exhaustive search#
K_3: 6 of 8 colorings avoid a monochromatic triangle
K_4: 18 of 64 colorings avoid a monochromatic triangle
K_5: 12 of 1024 colorings avoid a monochromatic triangle
K_6: 0 of 32768 colorings avoid a monochromatic triangle
The extremal coloring of K_5#
coloring = {(i, j): int((j - i) % 5 in (1, 4)) for i, j in combinations(range(5), 2)}
print(f"pentagon/pentagram coloring has a monochromatic triangle: {has_monochromatic_triangle(5, coloring)}")
points = np.array([(np.sin(2 * np.pi * k / 5), np.cos(2 * np.pi * k / 5)) for k in range(5)])
fig, ax = plt.subplots()
for (i, j), color in coloring.items():
ax.plot(*points[[i, j]].T, color=("tab:red" if color else "tab:blue"), lw=2)
ax.plot(*points.T, "ko")
ax.set_aspect("equal")
ax.axis("off")
ax.set_title("K_5 with no one-colored triangle")

pentagon/pentagram coloring has a monochromatic triangle: False
Text(0.5, 1.0, 'K_5 with no one-colored triangle')
Total running time of the script: (0 minutes 0.048 seconds)