.. 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_03_quaternions.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_03_quaternions.py: Hamilton's quaternions: the group Q_8 =========================================== Verifies Hamilton's relations i^2 = j^2 = k^2 = ijk = -1 in the quaternion group, shows that it is non-abelian, and prints its multiplication table. .. GENERATED FROM PYTHON SOURCE LINES 11-14 .. code-block:: Python from mathematicskit.abstract_algebra import QuaternionGroup, all_subgroups, is_normal_subgroup from mathematicskit.abstract_algebra.visualizers.plots import plot_cayley_table .. GENERATED FROM PYTHON SOURCE LINES 15-17 Hamilton's relations ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 17-24 .. code-block:: Python q = QuaternionGroup() for unit in ("i", "j", "k"): print(f"{unit}^2 = {q.operate(unit, unit)}") print(f"ijk = {q.operate(q.operate('i', 'j'), 'k')}") print(f"ij = {q.operate('i', 'j')}, but ji = {q.operate('j', 'i')}") .. rst-class:: sphx-glr-script-out .. code-block:: none i^2 = -1 j^2 = -1 k^2 = -1 ijk = -1 ij = k, but ji = -k .. GENERATED FROM PYTHON SOURCE LINES 25-27 Multiplication table ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: Python print("\n " + "".join(f"{b:>4}" for b in q.elements)) for a in q.elements: print(f"{a:>4} " + "".join(f"{q.operate(a, b):>4}" for b in q.elements)) .. rst-class:: sphx-glr-script-out .. code-block:: none 1 -1 i -i j -j k -k 1 1 -1 i -i j -j k -k -1 -1 1 -i i -j j -k k i i -i -1 1 k -k -j j -i -i i 1 -1 -k k j -j j j -j -k k -1 1 i -i -j -j j k -k 1 -1 -i i k k -k j -j -i i -1 1 -k -k k -j j i -i 1 -1 .. GENERATED FROM PYTHON SOURCE LINES 33-35 Non-abelian, yet every subgroup is normal ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-39 .. code-block:: Python subgroups = all_subgroups(q) print(f"\n{len(subgroups)} subgroups, all normal: {all(is_normal_subgroup(q, h) for h in subgroups)}") plot_cayley_table(q) .. image-sg:: /api/gallery/abstract_algebra/groups/images/sphx_glr_plot_03_quaternions_001.png :alt: Cayley table (order 8) :srcset: /api/gallery/abstract_algebra/groups/images/sphx_glr_plot_03_quaternions_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 6 subgroups, all normal: True .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.023 seconds) .. _sphx_glr_download_api_gallery_abstract_algebra_groups_plot_03_quaternions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_quaternions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_quaternions.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_quaternions.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_