Skip to main content

This is a minimal, vectorised and batchable library for computing Lehmer codes.

Project description

Lehmer

A minimal, vectorized, and batchable implementation of Lehmer codes.

Rubik's Cube

Lehmer codes, named after D.H. Lehmer, offer a method for enumerating the permutations of a set. The Lehmer code counts the number of inversions in a permutation. Together with the factoradic base, it provides a way to uniquely encode permutations as integers. This encoding therefore provides a bijection between integers and permutations. In other words, it is a perfect, memory-efficient hashing function for permutations.

Installation

Installing from PyPI:

[uv] pip install lehmer

Installing from source:

git clone ...
cd lehmer
uv venv
uv sync

Description

The class Lehmer provides two pairs of methods (depicted below in blue). Additionally, there are two convenience functions encode and decode (depicted below in orange) that combine the pairs for encoding and decoding permutations to and from integer indices.

$$ \underbrace{\text{permutation} \xrightarrow{\text{\color{blue}{perm2code}}} \text{code} \xrightarrow{\text{\color{blue}{code2index}}} \text{index} \in \mathbb{Z}}_{\text{\color{orange}{encode}}} $$

$$ \underbrace{\text{permutation} \xleftarrow{\text{\color{blue}{code2perm}}} \text{code} \xleftarrow{\text{\color{blue}{index2code}}} \text{index} \in \mathbb{Z}}_{\text{\color{orange}{decode}}} $$

Examples

Coming soon

Contributing

Please read the contributing guidelines if you wish to contribute to this project.

Credits

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

lehmer-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

lehmer-0.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file lehmer-0.1.1.tar.gz.

File metadata

  • Download URL: lehmer-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for lehmer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6bcf9264bd83a723f274064f86fe23f8538a0a191bd4063da964bbb01769117e
MD5 8d1c0af651736187a68d52515a1de15a
BLAKE2b-256 7c6f36a56f141ad8bd3def03af4ff4b79ead3d519085fe1a264c5d5dfd9878aa

See more details on using hashes here.

File details

Details for the file lehmer-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: lehmer-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for lehmer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1907fe7e872e1c404f0b78d639665e9d5f79000de9bf1ad7054b4c7fecfe0c8d
MD5 678b1f07c59067e035cdb45bf8547656
BLAKE2b-256 31a1549ec29bf9710fd75b9407c4ba63e4d667c609870e7dcf017dcae82b1013

See more details on using hashes here.

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