.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/abstract_algebra/groups/plot_02_dihedral_symmetries.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_abstract_algebra_groups_plot_02_dihedral_symmetries.py: Klein's Erlangen program: the symmetry group of a square ============================================================== Builds the dihedral group D_4 of the eight symmetries of a square, checks its defining relations, and draws its Cayley table. .. GENERATED FROM PYTHON SOURCE LINES 10-16 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.abstract_algebra import DihedralGroup from mathematicskit.abstract_algebra.visualizers.plots import plot_cayley_table .. GENERATED FROM PYTHON SOURCE LINES 17-19 Rotations and reflections of the square ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 19-27 .. code-block:: Python d4 = DihedralGroup(4) r, s = d4.rotation, d4.reflection print(f"|D_4| = {d4.order}, abelian: {d4.is_abelian()}") print(f"rotation r = {r}, order {d4.element_order(r)}") print(f"reflection s = {s}, order {d4.element_order(s)}") print(f"s r s = r^-1: {d4.operate(d4.operate(s, r), s) == d4.inverse(r)}") .. rst-class:: sphx-glr-script-out .. code-block:: none |D_4| = 8, abelian: False rotation r = (1, 2, 3, 0), order 4 reflection s = (0, 3, 2, 1), order 2 s r s = r^-1: True .. GENERATED FROM PYTHON SOURCE LINES 28-30 Where each symmetry sends the labelled corners ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 30-42 .. code-block:: Python corners = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]]) fig, axes = plt.subplots(2, 4, figsize=(10, 5)) for ax, g in zip(axes.flat, d4.elements): ax.fill(*corners.T, color="0.9", edgecolor="0.3") for vertex, image in enumerate(g): ax.annotate(str(vertex), corners[image] * 1.2, ha="center", va="center") ax.set_title(str(g), fontsize=9) ax.set_aspect("equal") ax.axis("off") fig.suptitle("The 8 symmetries of a square (vertex labels after each move)") .. image-sg:: /api/gallery/abstract_algebra/groups/images/sphx_glr_plot_02_dihedral_symmetries_001.png :alt: The 8 symmetries of a square (vertex labels after each move), (0, 1, 2, 3), (0, 3, 2, 1), (1, 0, 3, 2), (1, 2, 3, 0), (2, 1, 0, 3), (2, 3, 0, 1), (3, 0, 1, 2), (3, 2, 1, 0) :srcset: /api/gallery/abstract_algebra/groups/images/sphx_glr_plot_02_dihedral_symmetries_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 0.98, 'The 8 symmetries of a square (vertex labels after each move)') .. GENERATED FROM PYTHON SOURCE LINES 43-45 Cayley table ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 45-47 .. code-block:: Python plot_cayley_table(d4) .. image-sg:: /api/gallery/abstract_algebra/groups/images/sphx_glr_plot_02_dihedral_symmetries_002.png :alt: Cayley table (order 8) :srcset: /api/gallery/abstract_algebra/groups/images/sphx_glr_plot_02_dihedral_symmetries_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.076 seconds) .. _sphx_glr_download_api_gallery_abstract_algebra_groups_plot_02_dihedral_symmetries.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_dihedral_symmetries.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_dihedral_symmetries.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_dihedral_symmetries.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_