.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/topology/homology/plot_03_poincare_homology_euler_formula.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 or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_topology_homology_plot_03_poincare_homology_euler_formula.py: Poincaré's Analysis Situs: homology and the Euler-Poincaré formula (1895-1900) ============================================================================== Poincaré made Betti's numbers a theory. Chains of simplices, their boundaries, and the homology groups :math:`H_k = \ker\partial_k / \operatorname{im}\partial_{k+1}`, together with torsion coefficients. One consequence generalizes Euler: the alternating count of simplices equals the alternating sum of Betti numbers, .. math:: \sum_k (-1)^k f_k = \sum_k (-1)^k \beta_k , so :math:`\chi` depends only on the space, not on the triangulation. Below, many triangulations of five spaces with wildly different simplex counts land on the same :math:`\chi`. .. GENERATED FROM PYTHON SOURCE LINES 19-44 .. image-sg:: /api/gallery/topology/homology/images/sphx_glr_plot_03_poincare_homology_euler_formula_001.png :alt: The Euler characteristic is a topological invariant :srcset: /api/gallery/topology/homology/images/sphx_glr_plot_03_poincare_homology_euler_formula_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none sphere: H_0 = Z, H_1 = 0, H_2 = Z (chi = 2) circle: H_0 = Z, H_1 = Z (chi = 0) torus: H_0 = Z, H_1 = Z^2, H_2 = Z (chi = 0) Klein bottle: H_0 = Z, H_1 = Z + Z/2, H_2 = 0 (chi = 0) projective plane: H_0 = Z, H_1 = Z/2, H_2 = 0 (chi = 1) Text(0.5, 1.0, 'The Euler characteristic is a topological invariant') | .. code-block:: Python import matplotlib.pyplot as plt from mathematicskit.topology import circle, homology, klein_bottle, projective_plane, sphere, torus families = { "sphere": [sphere(2), sphere(2, "cross_polytope")], "circle": [circle(n) for n in (3, 5, 9, 17)], "torus": [torus(n, m) for n, m in ((3, 3), (5, 4), (8, 6), (12, 9))], "Klein bottle": [klein_bottle(n, m) for n, m in ((3, 3), (6, 4), (10, 7))], "projective plane": [projective_plane()], } fig, ax = plt.subplots(figsize=(9, 5)) for i, (name, complexes) in enumerate(families.items()): for K in complexes: H = homology(K) assert H.euler_characteristic == K.euler_characteristic ax.scatter(len(K), K.euler_characteristic, s=50, color=f"C{i}", label=name if K is complexes[0] else None) print(f"{name:>16}: {H} (chi = {H.euler_characteristic})") ax.set_xscale("log") ax.set_xlabel("number of simplices in the triangulation") ax.set_ylabel(r"$\chi = \sum (-1)^k f_k = \sum (-1)^k \beta_k$") ax.set_yticks([0, 1, 2]) ax.legend() ax.set_title("The Euler characteristic is a topological invariant") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.539 seconds) .. _sphx_glr_download_api_gallery_topology_homology_plot_03_poincare_homology_euler_formula.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/topology/homology/plot_03_poincare_homology_euler_formula.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_poincare_homology_euler_formula.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_poincare_homology_euler_formula.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_poincare_homology_euler_formula.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_