Skip to main content

Compute homology of finite semigroups and monoids

Project description

Fast Semigroup Homology

This is a Python package for computing the integral homology of finite semigroups. It is very fast in most cases:

$ python -m fast_semigroup_homology -i "010100;010100;232322;232322;010100;010100" -d 12
H_0: Z
H_1: trivial
H_2: Z
H_3: Z^2
H_4: Z^4
H_5: Z^8
H_6: Z^16
H_7: Z^32
H_8: Z^64
H_9: Z^128
H_10: Z^256
H_11: Z^512
H_12: Z^1024
Elapsed (wall) time: 0:00:00.001716

The above even quickly finishes if you pass -d 10_000 to compute the homology group in dimensions up to 10,000!

Installation:

Install with pip: pip install fast_semigroup_homology

Usage

Homology of one semigroup from the command line:

To compute the homology of an individual semigroup with the command line, run python -m fast_semigroup_homology -i "01;10" -d 10 as above, replacing the string that follows -i with the multiplication table for some semigroup. Such a multiplication table must be entered as strings of digits separated by semicolons, all wrapped in quotes. Letters (as in hexadecimal) are also supported to allow semigroups of size at most 10+26=36 to be passed in quotes after -i. The integer following -d indicates the maximum dimension to compute to.

As a Python Function

With this package installed, you can use the fast_integral_semigroup_homology function from python code:

>>> from fast_semigroup_homology import fast_integral_semigroup_homology as h
>>> h([[0,1],[1,0]], 10) # Homology of C2
[{0: 1}, {2: 1}, {}, {2: 1}, {}, {2: 1}, {}, {2: 1}, {}, {2: 1}, {}]

The result of fast_integral_semigroup_homology(table, maxdim) is a list of length maxdim+1 of dictionaries representing the multisets of invariant factors of the homology groups in dimensions 0 up through maxdim, inclusive. For example {0: 1} represents one copy of the infinite cyclic group Z, while {2: 1} represents one copy of the cyclic group Z/2Z.

Homology of HDF5 files of semigroup tables:

If you have a folder of HDF5 files like those produced by Semisearch, you can run:

python -m fast_semigroup_homology -f /PATH/TO/FOLDER -o MAXORDER -d MAXDIM -c NUM_CORES

This will make a folder called results in the current working directory with .hdf5 files containing the homology groups [H_0, ... H_MAXDIM] of the semigroups from the files order1.hdf5 through orderMAXORDER.hdf5 in the folder passed after -f. If NUM_CORES is specified, that many processes will compute in parallel.

My results folder is also stored in the git repository for this package, which you can browse and download. This is not included when pip installs this package.

Refining an existing HDF5 calculation

If you've already computed homology from a folder of HDF5 files as above, you can attempt to extend these computations with the -r flag:

python -m fast_semigroup_homology -f /PATH/TO/FOLDER -r ./results/EXISTING.hdf5 -d MAXDIM -c NUM_CORES -k KERNEL_BOUND

This creates a new file "refined_EXISTING.hdf5" in which calculations from "EXISTING.hdf5" are re-attempted, organized into bins of semigroups whose homology computed so far has been identical. If the calculations are found to be distinct, then the semigroups are separated into bins accordingly and the homology of these bins is extended in the same way recursively.

If any calculation within a bin attempts to compute the kernel of some integer matrix larger than KERNEL_BOUND, then the calculation fails and the bin is not refined any further. Therefore no list of homology groups produced by this refinement process is a prefix of any other.

The final format of refined_EXISTING.hdf5 is identical to the input EXISTING.hdf5, and a similar refined_EXISTING.md is generated to summarize the calculation. Question mark emojis ("❓") in the markdown files indicate computations that were abandoned for exceeding KERNEL_BOUND.

How It Works

We compute semigroup homology by first reducing to monoid homology, adjoining a unit as necessary. Then, according to Theorem 2 of (Adams, W. and Rieffel, M. Adjoint functors and derived functors with an application to the cohomology of semigroups. J. Algebra, 7 (1967), 25-34), we can get the same homology groups by reducing from a monoid S to the monoid eSe for some idempotent e of S, so long as eSe is a left ideal or right ideal of S.

After reducing to smaller monoids as applicable, the computation computes the homology H_i(S) as a Tor group Tor^Z[S]_i(Z, Z), where Z[S] is the monoid ring for S, and Z is a Z[S]-module with trivial S-action. To do this, we need a projective resolution for Z as a Z[S]-module.

Forming such a projective resolution is an alternating process of taking kernels and covering those kernels with maps from a new projective Z[S]-module. The projective modules we use are direct sums of modules of the form Z[S]e, where e is some idempotent of S. Kernels of integer matrices are computed using the implementation in ./fast_semigroup_homology/kernels.py, and those kernels are then covered by maps from a new module using the implementation in ./fast_semigroup_homology/find_generating_subset.py.

We apply two major additional optimizations in ./fast_semigroup_homology/projective_resolution.py:

  1. We use the mutable_lattice.Lattice.decompose() method to identify when a kernel splits along the Z[S]e summands, so we can cover the two summands of the kernel independently, thus "forking" the projective resolution into multiple branches of a tree.

  2. We cache and re-use parts of the resolution already computed, so that infinite resolutions can be represented as finite graphs with cycles. This is what allows large calculations like the 1000th homology group of the semigroup from the top of this README.

Performance Notes

  • Computing homology is extremely fast for many semigroups, but much slower for others. The time spent calculating homology for a big list of semigroups might be dominated by a tiny handful of the most difficult examples. In these most difficult cases, the complexity of the computation is exponential in MAXDIM.

  • The fast_integral_semigroup_homology function aims to provide shortcuts and sensible default thresholds to minimize the computation time expended finding small projective resolutions. You can get more fine-grained control by using the ProjectiveResolution class directly.

  • It appears that the majority of calculation time occurs in computing the kernels of integer matrices. The mutable_lattice.relations_among function proved to be the fastest for the data provided by actual semigroups, which appear to usually small integer entries including many zeros. However, ProjectiveResolution allows dependency-injecting your own kernel function. See ./fast_semigroup_homology/kernels.py for some commented-out examples of alternate implementations. This dependency-injection also allows bounding the size of kernel computation that is allowed, as is done in ./fast_semigroup_homology/refine_hdf5.py.

  • The most intensive calculations tend to take lots of memory, and this is especially relevant if you are running multiple processes in parallel with the -c flag. Adding swap space can help offload some of the required memory onto your hard drive and extend the computations your computer can complete without crashing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_semigroup_homology-0.1.0.tar.gz (40.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fast_semigroup_homology-0.1.0-py3-none-any.whl (36.8 kB view details)

Uploaded Python 3

File details

Details for the file fast_semigroup_homology-0.1.0.tar.gz.

File metadata

  • Download URL: fast_semigroup_homology-0.1.0.tar.gz
  • Upload date:
  • Size: 40.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fast_semigroup_homology-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c5fc0a654c31ad775a04a71e4fddd5bb046301aeac6ae04fd94074e5a977af9c
MD5 e48aa86b5438c3ebdca69fc533e6bb42
BLAKE2b-256 a5de991ad762774887031c001e359b364bfe149ba784504f158a3f59f0c22119

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_semigroup_homology-0.1.0.tar.gz:

Publisher: test_build_publish.yml on sweeneyde/fast_semigroup_homology

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fast_semigroup_homology-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fast_semigroup_homology-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a002a8ffe84c06230e0ade075ad775930cc96774c69472c702e0e64da3c78a8b
MD5 fbffb1701641ec2e2a7870b320be6f64
BLAKE2b-256 2fb83600be9b84aa60d4e0dddc60da3a06ca0bdd9239debdbd3c9e3f6523340c

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_semigroup_homology-0.1.0-py3-none-any.whl:

Publisher: test_build_publish.yml on sweeneyde/fast_semigroup_homology

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page