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.2.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.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lehmer-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 b55ab42b8718b0e0acdc25fcc1425df4bc9e764ac7357e0079a950c5522927e8
MD5 5e749a89f7d6a74c1f1f54dcf8997454
BLAKE2b-256 d02196beb8b371ac844ba85a5198e830f99e259b3aa7717270e91bdc4a8020c6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lehmer-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 04481c3b51f214bfe4676654343533a0763bdc4334f06442307d5279f9f564be
MD5 cc3ceba2555aa051792ebb73da519404
BLAKE2b-256 7bf30267510dc9cd1ce5238fcda796b3ba22fd83d026815a74aa9549458d571e

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