.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/combinatorics/extremal/plot_01_ramsey_r33.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_combinatorics_extremal_plot_01_ramsey_r33.py: 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. .. GENERATED FROM PYTHON SOURCE LINES 11-18 .. code-block:: Python from itertools import combinations import matplotlib.pyplot as plt import numpy as np from mathematicskit.combinatorics import count_triangle_free_colorings, has_monochromatic_triangle .. GENERATED FROM PYTHON SOURCE LINES 19-21 Exhaustive search ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 21-26 .. code-block:: Python for n in range(3, 7): total = 2 ** (n * (n - 1) // 2) print(f"K_{n}: {count_triangle_free_colorings(n)} of {total} colorings avoid a monochromatic triangle") .. rst-class:: sphx-glr-script-out .. code-block:: none 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 .. GENERATED FROM PYTHON SOURCE LINES 27-29 The extremal coloring of K_5 ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 29-40 .. code-block:: Python 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") .. image-sg:: /api/gallery/combinatorics/extremal/images/sphx_glr_plot_01_ramsey_r33_001.png :alt: K_5 with no one-colored triangle :srcset: /api/gallery/combinatorics/extremal/images/sphx_glr_plot_01_ramsey_r33_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none pentagon/pentagram coloring has a monochromatic triangle: False Text(0.5, 1.0, 'K_5 with no one-colored triangle') .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.048 seconds) .. _sphx_glr_download_api_gallery_combinatorics_extremal_plot_01_ramsey_r33.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_ramsey_r33.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_ramsey_r33.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_ramsey_r33.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_