Skip to main content

mapFolding

PyPI Python versions Python Tests License: CC BY-NC 4.0

Exact enumeration tools for map folding, stamp folding, semi-meanders, and meanders.

mapFolding is a typed Python research package for counting distinct foldings of one- and multidimensional maps. It provides:

  • stable dispatch functions for ordinary, rotationally symmetric, and divided computations;
  • native algorithms for map folding, semi-meanders, and meanders;
  • a unified interface to 33 implemented OEIS sequences, including exact formula relationships;
  • readable source algorithms, generated optimized implementations, and optional NumPy, Numba, Pandas, and Codon routes; and
  • cross-implementation tests against known sequence values.

Earlier versions of this project were used to compute new terms for OEIS A001415, the number of ways to fold a 2 × n strip of stamps.

This is exact combinatorial enumeration: running time and memory requirements grow quickly. Start with small inputs. The supported high-level interfaces are in mapFolding.basecamp and mapFolding.oeis; other modules include evolving research code.

Installation

mapFolding requires Python 3.13 or newer.

pip install mapFolding

Install an optional backend only when you need its corresponding implementation:

Extra Purpose
numba Numba-compiled map-folding implementations
pandas Pandas and Arrow meander implementation
codon Codon-compiled implementations on Linux
ortools Experimental constraint-propagation work
testing Test dependencies
development Broader development and analysis dependencies

For example:

pip install "mapFolding[numba,pandas]"

Quick start

Count map foldings

Each positive integer in mapShape is the length of one dimension. A (2, 3) map has six leaves.

from mapFolding.basecamp import countFolds

folds_total = countFolds((2, 3))
print(folds_total)  # 60

Calculate an OEIS term

from mapFolding.oeis import oeisIDfor_n

folds_total = oeisIDfor_n('A001415', 6)
print(folds_total)  # 10512

The installed commands expose the same sequence registry:

getOEISids
OEIS_for_n A001415 6

The second command prints:

10512 distinct folding patterns.
Time elapsed: ... seconds

Count semi-meanders and meanders

from mapFolding.basecamp import countMeanders

print(countMeanders('semi', 5))      # 10; OEIS A000682
print(countMeanders('meanders', 4))  # 3; OEIS A005316

Public interfaces

Goal Interface
Count all foldings of a map mapFolding.basecamp.countFolds(mapShape, ...)
Count rotationally symmetric foldings mapFolding.basecamp.countFoldsSymmetric(mapShape, ...)
Count semi-meanders or meanders mapFolding.basecamp.countMeanders(kind, n, ...)
Calculate any implemented OEIS term mapFolding.oeis.oeisIDfor_n(oeisID, n, ...)
Convert a map-folding OEIS index to dimensions mapFolding.oeis.makeMapShape(oeisID, n)
Retrieve cached known values mapFolding.oeis.getValuesKnown(oeisID)
List implemented sequences getOEISids

oeisIDfor_n dispatches to the appropriate folding algorithm, meander algorithm, symmetric-folding algorithm, or exact formula. Run getOEISids for the current list and descriptions of all supported sequences.

The map-folding sequence mappings are:

OEIS ID Problem mapShape for index n
A000136 Strip of n labeled stamps (1, n)
A001415 2 × n strip (2, n)
A001416 3 × n strip (3, n)
A001417 n-dimensional 2 × ⋯ × 2 map (2,) * n
A195646 n-dimensional 3 × ⋯ × 3 map (3,) * n
A001418 n × n sheet (n, n)
A007822 Symmetric foldings of 2n + 1 stamps (1, 2 * n)

For A007822, pass (1, 2 * n) to countFoldsSymmetric; the function's computational shape differs from the 2n + 1 stamps in the sequence description.

OEIS metadata and b-files are cached locally for 30 days. Missing or stale entries are refreshed from oeis.org; stale cached data remains available if a refresh fails.

Algorithm selection and long computations

Leave flow='' for the default implementation. The alternate selectors exist for research, validation, and performance comparisons:

Interface Supported flow values
countFolds '', daoOfMapFolding, numba, theorem2, theorem2Codon, theorem2Numba, theorem2Trimmed
countFoldsSymmetric '', asynchronous, theorem2, theorem2Codon, theorem2Numba, theorem2Trimmed
countMeanders '', matrixMeanders, matrixNumPy, matrixPandas

The Numba, Pandas, and Codon selectors require their corresponding extras. For OEIS sequences with multiple exact identities, the f argument to oeisIDfor_n selects a formula; leaving it empty uses the default route.

Pass pathLikeWrite to a counting function to preserve a result. An existing directory receives a generated filename such as p2x6.foldsTotal; an explicit target file is also supported. The destination is write-tested before computation, and an existing target is not overwritten.

countFolds can split work with an integer, computationDivisions='cpu', or computationDivisions='maximum'. Dividing this algorithm repeats substantial work and is usually slower, so leave computationDivisions=None unless you are deliberately studying the parallel implementation.

Repository guide

Path Role
mapFolding/basecamp.py Stable high-level dispatch for folding and meander computations
mapFolding/oeis/ OEIS dispatch, formulas, metadata, and cached values
mapFolding/algorithms/ Handwritten source algorithms
mapFolding/syntheticModules/ Generated implementations; regenerate these instead of editing them directly
mapFolding/someAssemblyRequired/ Project-specific AST transformations and module generators
mapFolding/_e/ Experimental elimination-based algorithms and analysis
mapFolding/tests/ Main correctness, dispatch, filesystem, and parameter tests
mapFolding/reference/ Historical implementations, completed jobs, notes, and research artifacts
easyRun/ Benchmark and exploration harnesses

General-purpose transformation primitives developed alongside this project now live in astToolkit and astToolFactory. The transformation pipeline retained here is specific to generating and validating mapFolding implementations.

Development

Create and activate a virtual environment, then install both development extras:

git clone https://github.com/hunterhogan/mapFolding.git
cd mapFolding
python -m venv .venv

PowerShell:

.venv\Scripts\Activate.ps1

POSIX shells:

source .venv/bin/activate

Install and test:

pip install -e ".[development,testing]"
pytest

The test suite compares independent implementations with known OEIS values and stored data samples. When adding an algorithm variant, begin with mapFolding/tests/test_computations.py and register the new flow beside the existing implementations.

Citation

To cite this software, use the metadata in CITATION.cff. BibTeX files for the mathematical literature are collected in citations/.

Research references

A map-folding problem

Folding a strip of stamps

Multi-dimensional map-folding

A transfer matrix approach to the enumeration of plane meanders

A new transfer-matrix algorithm for exact enumerations: self-avoiding polygons on the square lattice

Stamp Foldings, Semi-Meanders, and Open Meanders: Fast Generation Algorithms

Foldings and meanders

Valid Orderings of Layers When Simple-Folding a Map

jOEIS: Java Online Encyclopedia of Integer Sequences

The Online Encyclopedia of Integer Sequences

License

mapFolding is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License.

My recovery

2011 August: Homeless since YouTube channel subscribers

Download files

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

Source Distribution

mapfolding-0.29.0.tar.gz (311.8 kB view details)

Uploaded Source

Built Distribution

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

mapfolding-0.29.0-py3-none-any.whl (393.4 kB view details)

Uploaded Python 3

File details

Details for the file mapfolding-0.29.0.tar.gz.

File metadata

  • Download URL: mapfolding-0.29.0.tar.gz
  • Upload date:
  • Size: 311.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mapfolding-0.29.0.tar.gz
Algorithm Hash digest
SHA256 f77fdb5f362c9e27a840b36b728c0b56dee7fdedf99358120a8614e5a4c1bcce
MD5 a5717757a586e91c68aa7d1b226c653c
BLAKE2b-256 11bfd8dca09c243d8ed53822855e04c4b10ed9f5a42446fb31e7866b170a1608

See more details on using hashes here.

File details

Details for the file mapfolding-0.29.0-py3-none-any.whl.

File metadata

  • Download URL: mapfolding-0.29.0-py3-none-any.whl
  • Upload date:
  • Size: 393.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mapfolding-0.29.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88d1edacf7509e224566261c958ce7d2666088fa65ee047e93f61556f1ccaaaa
MD5 a12236d01fe0bc44fdb01835562742e6
BLAKE2b-256 0d10ac3d050693d92a8fdc132060c2a8ff22da936470f3203a05c4e840d3262a

See more details on using hashes here.

Release history Release notifications | RSS feed

0.33.0

2 files

0.32.0

2 files

0.31.0

2 files

0.30.0

2 files

This release

0.29.0 This release

2 files

0.28.0

2 files

0.27.0

2 files

0.26.0

2 files

0.25.0

2 files

0.24.1

2 files

0.24.0

2 files

0.23.1

2 files

0.23.0

2 files

0.22.0

2 files

0.21.0

2 files

0.20.0

2 files

0.19.0

2 files

0.18.4

1 file

0.18.3

2 files

0.18.2

2 files

0.18.1

2 files

0.18.0

2 files

0.17.1

2 files

0.17.0

2 files

0.16.4

2 files

0.16.2

2 files

0.16.1

2 files

0.16.0

2 files

0.15.4

2 files

0.15.3

2 files

0.15.2

2 files

0.15.1

2 files

0.15.0

2 files

0.14.1

2 files

0.14.0

2 files

0.13.1

2 files

0.13.0

2 files

0.12.3

2 files

0.12.2

2 files

0.12.1

2 files

0.12.0

2 files

0.11.4

2 files

0.11.3

2 files

0.11.2

2 files

0.11.1

2 files

0.11.0

2 files

0.10.0

2 files

0.9.5

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.6

2 files

0.8.5

2 files

0.8.4

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.1

2 files

0.7.0

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.12

2 files

0.3.11

2 files

0.3.10

2 files

0.3.9

2 files

0.3.8

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

Supported by

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