mapFolding 0.12.0__tar.gz → 0.12.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mapfolding-0.12.2/PKG-INFO +167 -0
- mapfolding-0.12.2/README.md +115 -0
- mapfolding-0.12.2/mapFolding/__init__.py +86 -0
- mapfolding-0.12.2/mapFolding/_theSSOT.py +137 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/basecamp.py +28 -18
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/beDRY.py +21 -19
- mapfolding-0.12.2/mapFolding/dataBaskets.py +235 -0
- mapfolding-0.12.2/mapFolding/datatypes.py +126 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/filesystemToolkit.py +38 -33
- mapfolding-0.12.2/mapFolding/oeis.py +557 -0
- mapfolding-0.12.2/mapFolding/someAssemblyRequired/RecipeJob.py +200 -0
- mapfolding-0.12.2/mapFolding/someAssemblyRequired/__init__.py +60 -0
- mapfolding-0.12.2/mapFolding/someAssemblyRequired/_toolIfThis.py +120 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/someAssemblyRequired/_toolkitContainers.py +123 -45
- mapfolding-0.12.2/mapFolding/someAssemblyRequired/infoBooth.py +52 -0
- mapfolding-0.12.2/mapFolding/someAssemblyRequired/makeAllModules.py +712 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +111 -48
- mapfolding-0.12.2/mapFolding/someAssemblyRequired/toolkitNumba.py +284 -0
- mapfolding-0.12.2/mapFolding/someAssemblyRequired/transformationTools.py +171 -0
- mapfolding-0.12.2/mapFolding.egg-info/PKG-INFO +167 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding.egg-info/SOURCES.txt +2 -2
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding.egg-info/requires.txt +4 -3
- mapfolding-0.12.2/pyproject.toml +108 -0
- mapfolding-0.12.2/tests/__init__.py +28 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/tests/conftest.py +66 -61
- mapfolding-0.12.2/tests/test_computations.py +99 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/tests/test_filesystem.py +25 -1
- {mapfolding-0.12.0 → mapfolding-0.12.2}/tests/test_oeis.py +30 -1
- {mapfolding-0.12.0 → mapfolding-0.12.2}/tests/test_other.py +27 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/tests/test_tasks.py +31 -1
- mapfolding-0.12.0/PKG-INFO +0 -184
- mapfolding-0.12.0/README.md +0 -133
- mapfolding-0.12.0/mapFolding/__init__.py +0 -62
- mapfolding-0.12.0/mapFolding/dataBaskets.py +0 -83
- mapfolding-0.12.0/mapFolding/datatypes.py +0 -18
- mapfolding-0.12.0/mapFolding/oeis.py +0 -441
- mapfolding-0.12.0/mapFolding/someAssemblyRequired/RecipeJob.py +0 -89
- mapfolding-0.12.0/mapFolding/someAssemblyRequired/Z0Z_makeAllModules.py +0 -433
- mapfolding-0.12.0/mapFolding/someAssemblyRequired/__init__.py +0 -63
- mapfolding-0.12.0/mapFolding/someAssemblyRequired/_toolIfThis.py +0 -58
- mapfolding-0.12.0/mapFolding/someAssemblyRequired/infoBooth.py +0 -17
- mapfolding-0.12.0/mapFolding/someAssemblyRequired/toolkitNumba.py +0 -132
- mapfolding-0.12.0/mapFolding/someAssemblyRequired/transformationTools.py +0 -127
- mapfolding-0.12.0/mapFolding/theSSOT.py +0 -34
- mapfolding-0.12.0/mapFolding.egg-info/PKG-INFO +0 -184
- mapfolding-0.12.0/pyproject.toml +0 -107
- mapfolding-0.12.0/tests/__init__.py +0 -44
- mapfolding-0.12.0/tests/test_computations.py +0 -142
- {mapfolding-0.12.0 → mapfolding-0.12.2}/LICENSE +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/daoOfMapFolding.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/py.typed +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/reference/__init__.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/reference/flattened.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/reference/hunterNumba.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/reference/irvineJavaPort.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/reference/jaxCount.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/reference/jobsCompleted/[2x19]/p2x19.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/reference/jobsCompleted/__init__.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/reference/jobsCompleted/p2x19/p2x19.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/reference/lunnonNumpy.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/reference/lunnonWhile.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/reference/rotatedEntryPoint.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/reference/total_countPlus1vsPlusN.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/someAssemblyRequired/getLLVMforNoReason.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/syntheticModules/__init__.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/syntheticModules/countParallel.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/syntheticModules/daoOfMapFolding.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/syntheticModules/dataPacking.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/syntheticModules/initializeCount.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/syntheticModules/theorem2.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/syntheticModules/theorem2Numba.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding/syntheticModules/theorem2Trimmed.py +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding.egg-info/dependency_links.txt +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding.egg-info/entry_points.txt +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/mapFolding.egg-info/top_level.txt +0 -0
- {mapfolding-0.12.0 → mapfolding-0.12.2}/setup.cfg +0 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mapFolding
|
|
3
|
+
Version: 0.12.2
|
|
4
|
+
Summary: Map folding algorithm with code transformation framework for optimizing numerical computations
|
|
5
|
+
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
6
|
+
License: CC-BY-NC-4.0
|
|
7
|
+
Project-URL: Donate, https://www.patreon.com/integrated
|
|
8
|
+
Project-URL: Homepage, https://github.com/hunterhogan/mapFolding
|
|
9
|
+
Project-URL: Issues, https://github.com/hunterhogan/mapFolding/issues
|
|
10
|
+
Project-URL: Repository, https://github.com/hunterhogan/mapFolding.git
|
|
11
|
+
Keywords: A000136,A001415,A001416,A001417,A001418,A195646,AST manipulation,Numba optimization,OEIS,algorithmic optimization,code generation,code transformation,combinatorics,computational geometry,dataclass transformation,folding pattern enumeration,just-in-time compilation,map folding,performance optimization,source code analysis,stamp folding
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Education
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Natural Language :: English
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
25
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
26
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Requires-Python: >=3.12
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: Z0Z_tools
|
|
33
|
+
Requires-Dist: astToolkit>=0.5.0
|
|
34
|
+
Requires-Dist: autoflake
|
|
35
|
+
Requires-Dist: numba
|
|
36
|
+
Requires-Dist: numba_progress
|
|
37
|
+
Requires-Dist: numpy
|
|
38
|
+
Requires-Dist: platformdirs
|
|
39
|
+
Requires-Dist: python_minifier
|
|
40
|
+
Requires-Dist: sympy
|
|
41
|
+
Requires-Dist: tomli
|
|
42
|
+
Provides-Extra: testing
|
|
43
|
+
Requires-Dist: mypy; extra == "testing"
|
|
44
|
+
Requires-Dist: pytest; extra == "testing"
|
|
45
|
+
Requires-Dist: pytest-cov; extra == "testing"
|
|
46
|
+
Requires-Dist: pytest-env; extra == "testing"
|
|
47
|
+
Requires-Dist: pytest-xdist; extra == "testing"
|
|
48
|
+
Requires-Dist: pyupgrade; extra == "testing"
|
|
49
|
+
Requires-Dist: ruff; extra == "testing"
|
|
50
|
+
Requires-Dist: setuptools-scm; extra == "testing"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# mapFolding
|
|
54
|
+
|
|
55
|
+
[](https://pypi.org/project/mapFolding/)
|
|
56
|
+
[](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml)
|
|
57
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
58
|
+
|
|
59
|
+
A computational framework that starts with Lunnon's 1971 algorithm for counting distinct ways to fold maps and improves it. Plus there is a comprehensive AST transformation system for transforming algorithms for optimization and research.
|
|
60
|
+
|
|
61
|
+
(Yo, the rest is AI generated and I don't have the energy to proofread it. This package helped me compute two previously unknown values: I'm sure others can improve it.)
|
|
62
|
+
|
|
63
|
+
## The Mathematical Problem
|
|
64
|
+
|
|
65
|
+
Map folding is a combinatorial problem: given a rectangular grid of unit squares, how many distinct ways can you fold it? "Distinct" means that foldings producing identical final shapes are counted as one. This problem connects to combinatorial geometry, integer sequences, and computational complexity theory.
|
|
66
|
+
|
|
67
|
+
The calculations extend the Online Encyclopedia of Integer Sequences (OEIS):
|
|
68
|
+
|
|
69
|
+
- **A001415**: 2×n strips (computed through n=20 for the first time)
|
|
70
|
+
- **A001418**: n×n squares
|
|
71
|
+
- **A001416**: 3×n strips
|
|
72
|
+
- **A001417**: n-dimensional hypercubes
|
|
73
|
+
- **A195646**: 3×3×...×3 hypercubes
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from mapFolding import oeisIDfor_n
|
|
77
|
+
|
|
78
|
+
# How many ways can you fold a 2×4 strip?
|
|
79
|
+
foldsTotal = oeisIDfor_n('A001415', 4)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## The Computational Challenge
|
|
83
|
+
|
|
84
|
+
For larger maps, these calculations require hours or days to complete. A 2×20 strip requires processing leaves through billions of recursive operations. The package addresses this through systematic algorithm transformation: converting readable Python implementations into specialized, Numba-optimized modules that achieve order-of-magnitude performance improvements.
|
|
85
|
+
|
|
86
|
+
## What This Package Provides
|
|
87
|
+
|
|
88
|
+
### Core Functionality
|
|
89
|
+
|
|
90
|
+
- **Complete implementation** of Lunnon's recursive algorithm
|
|
91
|
+
- **Mathematical validation** through OEIS integration and caching
|
|
92
|
+
- **Type-safe computational state** management with automatic initialization
|
|
93
|
+
- **Result persistence** for long-running calculations
|
|
94
|
+
|
|
95
|
+
### Algorithm Transformation System
|
|
96
|
+
|
|
97
|
+
- **AST manipulation framework** for converting dataclass-based algorithms to optimized implementations
|
|
98
|
+
- **Automatic code generation** that produces standalone, highly optimized computation modules
|
|
99
|
+
- **Dataclass decomposition** to enable Numba compatibility while preserving readable source code
|
|
100
|
+
- **Comprehensive optimization** including dead code elimination, static value embedding, and aggressive compilation settings
|
|
101
|
+
|
|
102
|
+
### Educational Resources
|
|
103
|
+
|
|
104
|
+
- **Historical implementations** showing algorithm evolution from 1971 to present
|
|
105
|
+
- **Performance comparison** studies demonstrating optimization techniques
|
|
106
|
+
- **Complete test suite** with patterns for validating custom implementations
|
|
107
|
+
- **Reference documentation** for extending the transformation framework
|
|
108
|
+
|
|
109
|
+
## Use Cases
|
|
110
|
+
|
|
111
|
+
**Mathematical Research**: Explore folding pattern properties, extend known sequences, or validate theoretical results against computed values.
|
|
112
|
+
|
|
113
|
+
**Algorithm Optimization Learning**: Study a complete transformation pipeline that converts high-level algorithms into production-ready optimized code.
|
|
114
|
+
|
|
115
|
+
**Performance Computing Education**: Examine techniques for achieving maximum Python performance through Numba integration, AST manipulation, and specialized code generation.
|
|
116
|
+
|
|
117
|
+
**Combinatorial Problem Solving**: Use the framework as a template for optimizing other recursive combinatorial algorithms.
|
|
118
|
+
|
|
119
|
+
## Example Usage
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from mapFolding import countFolds
|
|
123
|
+
|
|
124
|
+
# Count folding patterns for a 3×3 square
|
|
125
|
+
result = countFolds([3, 3])
|
|
126
|
+
|
|
127
|
+
# Access OEIS sequences directly
|
|
128
|
+
from mapFolding import oeisIDfor_n
|
|
129
|
+
strip_foldings = oeisIDfor_n('A001415', 6) # 2×6 strip
|
|
130
|
+
|
|
131
|
+
# Generate optimized code for specific dimensions
|
|
132
|
+
from mapFolding.someAssemblyRequired import makeJobTheorem2Numba
|
|
133
|
+
# Creates specialized modules for maximum performance
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Repository Structure
|
|
137
|
+
|
|
138
|
+
- `mapFolding/`: Core implementation with modular architecture
|
|
139
|
+
- `reference/`: Historical algorithm implementations and performance studies
|
|
140
|
+
- `someAssemblyRequired/`: AST transformation framework
|
|
141
|
+
- `tests/`: Comprehensive validation suite
|
|
142
|
+
- `jobs/`: Generated optimized modules for specific calculations
|
|
143
|
+
|
|
144
|
+
## Performance Characteristics
|
|
145
|
+
|
|
146
|
+
- **Pure Python baseline**: Educational implementations for understanding
|
|
147
|
+
- **NumPy optimization**: ~10× improvement through vectorized operations
|
|
148
|
+
- **Numba compilation**: ~100× improvement through native code generation
|
|
149
|
+
- **Specialized modules**: ~1000× improvement through static optimization and embedded constants
|
|
150
|
+
|
|
151
|
+
Actual performance varies by map dimensions and available hardware.
|
|
152
|
+
|
|
153
|
+
## My recovery
|
|
154
|
+
|
|
155
|
+
[](https://HunterThinks.com/support)
|
|
156
|
+
[](https://www.youtube.com/@HunterHogan)
|
|
157
|
+
|
|
158
|
+
## How to code
|
|
159
|
+
|
|
160
|
+
Coding One Step at a Time:
|
|
161
|
+
|
|
162
|
+
0. WRITE CODE.
|
|
163
|
+
1. Don't write stupid code that's hard to revise.
|
|
164
|
+
2. Write good code.
|
|
165
|
+
3. When revising, write better code.
|
|
166
|
+
|
|
167
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# mapFolding
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/mapFolding/)
|
|
4
|
+
[](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml)
|
|
5
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
6
|
+
|
|
7
|
+
A computational framework that starts with Lunnon's 1971 algorithm for counting distinct ways to fold maps and improves it. Plus there is a comprehensive AST transformation system for transforming algorithms for optimization and research.
|
|
8
|
+
|
|
9
|
+
(Yo, the rest is AI generated and I don't have the energy to proofread it. This package helped me compute two previously unknown values: I'm sure others can improve it.)
|
|
10
|
+
|
|
11
|
+
## The Mathematical Problem
|
|
12
|
+
|
|
13
|
+
Map folding is a combinatorial problem: given a rectangular grid of unit squares, how many distinct ways can you fold it? "Distinct" means that foldings producing identical final shapes are counted as one. This problem connects to combinatorial geometry, integer sequences, and computational complexity theory.
|
|
14
|
+
|
|
15
|
+
The calculations extend the Online Encyclopedia of Integer Sequences (OEIS):
|
|
16
|
+
|
|
17
|
+
- **A001415**: 2×n strips (computed through n=20 for the first time)
|
|
18
|
+
- **A001418**: n×n squares
|
|
19
|
+
- **A001416**: 3×n strips
|
|
20
|
+
- **A001417**: n-dimensional hypercubes
|
|
21
|
+
- **A195646**: 3×3×...×3 hypercubes
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from mapFolding import oeisIDfor_n
|
|
25
|
+
|
|
26
|
+
# How many ways can you fold a 2×4 strip?
|
|
27
|
+
foldsTotal = oeisIDfor_n('A001415', 4)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## The Computational Challenge
|
|
31
|
+
|
|
32
|
+
For larger maps, these calculations require hours or days to complete. A 2×20 strip requires processing leaves through billions of recursive operations. The package addresses this through systematic algorithm transformation: converting readable Python implementations into specialized, Numba-optimized modules that achieve order-of-magnitude performance improvements.
|
|
33
|
+
|
|
34
|
+
## What This Package Provides
|
|
35
|
+
|
|
36
|
+
### Core Functionality
|
|
37
|
+
|
|
38
|
+
- **Complete implementation** of Lunnon's recursive algorithm
|
|
39
|
+
- **Mathematical validation** through OEIS integration and caching
|
|
40
|
+
- **Type-safe computational state** management with automatic initialization
|
|
41
|
+
- **Result persistence** for long-running calculations
|
|
42
|
+
|
|
43
|
+
### Algorithm Transformation System
|
|
44
|
+
|
|
45
|
+
- **AST manipulation framework** for converting dataclass-based algorithms to optimized implementations
|
|
46
|
+
- **Automatic code generation** that produces standalone, highly optimized computation modules
|
|
47
|
+
- **Dataclass decomposition** to enable Numba compatibility while preserving readable source code
|
|
48
|
+
- **Comprehensive optimization** including dead code elimination, static value embedding, and aggressive compilation settings
|
|
49
|
+
|
|
50
|
+
### Educational Resources
|
|
51
|
+
|
|
52
|
+
- **Historical implementations** showing algorithm evolution from 1971 to present
|
|
53
|
+
- **Performance comparison** studies demonstrating optimization techniques
|
|
54
|
+
- **Complete test suite** with patterns for validating custom implementations
|
|
55
|
+
- **Reference documentation** for extending the transformation framework
|
|
56
|
+
|
|
57
|
+
## Use Cases
|
|
58
|
+
|
|
59
|
+
**Mathematical Research**: Explore folding pattern properties, extend known sequences, or validate theoretical results against computed values.
|
|
60
|
+
|
|
61
|
+
**Algorithm Optimization Learning**: Study a complete transformation pipeline that converts high-level algorithms into production-ready optimized code.
|
|
62
|
+
|
|
63
|
+
**Performance Computing Education**: Examine techniques for achieving maximum Python performance through Numba integration, AST manipulation, and specialized code generation.
|
|
64
|
+
|
|
65
|
+
**Combinatorial Problem Solving**: Use the framework as a template for optimizing other recursive combinatorial algorithms.
|
|
66
|
+
|
|
67
|
+
## Example Usage
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from mapFolding import countFolds
|
|
71
|
+
|
|
72
|
+
# Count folding patterns for a 3×3 square
|
|
73
|
+
result = countFolds([3, 3])
|
|
74
|
+
|
|
75
|
+
# Access OEIS sequences directly
|
|
76
|
+
from mapFolding import oeisIDfor_n
|
|
77
|
+
strip_foldings = oeisIDfor_n('A001415', 6) # 2×6 strip
|
|
78
|
+
|
|
79
|
+
# Generate optimized code for specific dimensions
|
|
80
|
+
from mapFolding.someAssemblyRequired import makeJobTheorem2Numba
|
|
81
|
+
# Creates specialized modules for maximum performance
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Repository Structure
|
|
85
|
+
|
|
86
|
+
- `mapFolding/`: Core implementation with modular architecture
|
|
87
|
+
- `reference/`: Historical algorithm implementations and performance studies
|
|
88
|
+
- `someAssemblyRequired/`: AST transformation framework
|
|
89
|
+
- `tests/`: Comprehensive validation suite
|
|
90
|
+
- `jobs/`: Generated optimized modules for specific calculations
|
|
91
|
+
|
|
92
|
+
## Performance Characteristics
|
|
93
|
+
|
|
94
|
+
- **Pure Python baseline**: Educational implementations for understanding
|
|
95
|
+
- **NumPy optimization**: ~10× improvement through vectorized operations
|
|
96
|
+
- **Numba compilation**: ~100× improvement through native code generation
|
|
97
|
+
- **Specialized modules**: ~1000× improvement through static optimization and embedded constants
|
|
98
|
+
|
|
99
|
+
Actual performance varies by map dimensions and available hardware.
|
|
100
|
+
|
|
101
|
+
## My recovery
|
|
102
|
+
|
|
103
|
+
[](https://HunterThinks.com/support)
|
|
104
|
+
[](https://www.youtube.com/@HunterHogan)
|
|
105
|
+
|
|
106
|
+
## How to code
|
|
107
|
+
|
|
108
|
+
Coding One Step at a Time:
|
|
109
|
+
|
|
110
|
+
0. WRITE CODE.
|
|
111
|
+
1. Don't write stupid code that's hard to revise.
|
|
112
|
+
2. Write good code.
|
|
113
|
+
3. When revising, write better code.
|
|
114
|
+
|
|
115
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Computational toolkit for analyzing multi-dimensional map folding patterns.
|
|
2
|
+
|
|
3
|
+
The mapFolding package provides a complete implementation of Lunnon's 1971 algorithm
|
|
4
|
+
for counting distinct folding patterns in multi-dimensional maps. This toolkit
|
|
5
|
+
transforms the complex combinatorial mathematics of map folding into accessible
|
|
6
|
+
computational tools, enabling researchers and practitioners to analyze folding
|
|
7
|
+
patterns across dimensions from simple 2D strips to complex multi-dimensional
|
|
8
|
+
hypercubes.
|
|
9
|
+
|
|
10
|
+
The package architecture follows Domain-Driven Design principles, organizing
|
|
11
|
+
functionality around mathematical concepts rather than implementation details.
|
|
12
|
+
The computational framework integrates type safety, persistent result storage,
|
|
13
|
+
and mathematical validation through OEIS sequence integration.
|
|
14
|
+
|
|
15
|
+
Core Transformation Tools:
|
|
16
|
+
countFolds: Primary interface for computing folding pattern counts
|
|
17
|
+
MapFoldingState: Computational state management for recursive analysis
|
|
18
|
+
Connection graph generation: Mathematical foundation for folding relationships
|
|
19
|
+
Task division utilities: Experimental parallel computation options
|
|
20
|
+
OEIS integration: Mathematical validation and sequence discovery
|
|
21
|
+
|
|
22
|
+
Primary Use Cases:
|
|
23
|
+
Mathematical research into folding pattern properties and relationships
|
|
24
|
+
Educational exploration of combinatorial mathematics concepts
|
|
25
|
+
Computational validation of theoretical results
|
|
26
|
+
Extension of known mathematical sequences through new discoveries
|
|
27
|
+
|
|
28
|
+
The package handles the full spectrum of map folding analysis, from simple
|
|
29
|
+
educational examples to research-grade computations requiring multi-day processing
|
|
30
|
+
time. Results integrate seamlessly with the mathematical community through
|
|
31
|
+
comprehensive OEIS connectivity and standardized result persistence.
|
|
32
|
+
|
|
33
|
+
For researchers: The computational foundation supports both replication of
|
|
34
|
+
established results and discovery of new mathematical relationships.
|
|
35
|
+
|
|
36
|
+
For educators: The clear interfaces and type safety enable confident exploration
|
|
37
|
+
of combinatorial concepts without computational complexity barriers.
|
|
38
|
+
|
|
39
|
+
For practitioners: The robust result persistence and type safety ensure
|
|
40
|
+
reliable completion of complex analytical tasks.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
from mapFolding.datatypes import (
|
|
44
|
+
Array1DElephino as Array1DElephino,
|
|
45
|
+
Array1DFoldsTotal as Array1DFoldsTotal,
|
|
46
|
+
Array1DLeavesTotal as Array1DLeavesTotal,
|
|
47
|
+
Array3D as Array3D,
|
|
48
|
+
DatatypeElephino as DatatypeElephino,
|
|
49
|
+
DatatypeFoldsTotal as DatatypeFoldsTotal,
|
|
50
|
+
DatatypeLeavesTotal as DatatypeLeavesTotal,
|
|
51
|
+
NumPyElephino as NumPyElephino,
|
|
52
|
+
NumPyFoldsTotal as NumPyFoldsTotal,
|
|
53
|
+
NumPyIntegerType as NumPyIntegerType,
|
|
54
|
+
NumPyLeavesTotal as NumPyLeavesTotal,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
from mapFolding._theSSOT import PackageSettings as PackageSettings, packageSettings as packageSettings
|
|
58
|
+
|
|
59
|
+
from mapFolding.beDRY import (
|
|
60
|
+
getConnectionGraph as getConnectionGraph,
|
|
61
|
+
getLeavesTotal as getLeavesTotal,
|
|
62
|
+
getTaskDivisions as getTaskDivisions,
|
|
63
|
+
makeDataContainer as makeDataContainer,
|
|
64
|
+
setProcessorLimit as setProcessorLimit,
|
|
65
|
+
validateListDimensions as validateListDimensions,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
from mapFolding.dataBaskets import MapFoldingState as MapFoldingState
|
|
69
|
+
|
|
70
|
+
from mapFolding.filesystemToolkit import (
|
|
71
|
+
getFilenameFoldsTotal as getFilenameFoldsTotal,
|
|
72
|
+
getPathFilenameFoldsTotal as getPathFilenameFoldsTotal,
|
|
73
|
+
getPathRootJobDEFAULT as getPathRootJobDEFAULT,
|
|
74
|
+
saveFoldsTotal as saveFoldsTotal,
|
|
75
|
+
saveFoldsTotalFAILearly as saveFoldsTotalFAILearly,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
from mapFolding.basecamp import countFolds as countFolds
|
|
79
|
+
|
|
80
|
+
from mapFolding.oeis import (
|
|
81
|
+
clearOEIScache as clearOEIScache,
|
|
82
|
+
getFoldsTotalKnown as getFoldsTotalKnown,
|
|
83
|
+
getOEISids as getOEISids,
|
|
84
|
+
OEIS_for_n as OEIS_for_n,
|
|
85
|
+
oeisIDfor_n as oeisIDfor_n,
|
|
86
|
+
)
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Foundation layer for the map folding computational ecosystem.
|
|
3
|
+
|
|
4
|
+
This module establishes the fundamental configuration infrastructure that underpins
|
|
5
|
+
all map folding operations. Map folding, as defined by Lunnon's 1971 algorithm,
|
|
6
|
+
requires precise coordination of computational resources, type systems, and data
|
|
7
|
+
flow management to solve the complex combinatorial problem of counting distinct
|
|
8
|
+
folding patterns across multi-dimensional maps.
|
|
9
|
+
|
|
10
|
+
The Single Source Of Truth (SSOT) principle governs this foundation, ensuring that
|
|
11
|
+
package identity, filesystem locations, and concurrency configuration remain
|
|
12
|
+
consistent across all computational phases. During packaging, static metadata is
|
|
13
|
+
resolved from pyproject.toml. During installation, filesystem-dependent paths are
|
|
14
|
+
dynamically discovered. During runtime, the `packageSettings` instance provides
|
|
15
|
+
unified access to all configuration values, enabling the sophisticated computational
|
|
16
|
+
framework that follows.
|
|
17
|
+
|
|
18
|
+
This configuration foundation supports the type system definition, core utility
|
|
19
|
+
functions, computational state management, result persistence, and ultimately the
|
|
20
|
+
main computational interface that users interact with to solve map folding problems.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from importlib import import_module as importlib_import_module
|
|
24
|
+
from inspect import getfile as inspect_getfile
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
from tomli import load as tomli_load
|
|
27
|
+
import dataclasses
|
|
28
|
+
|
|
29
|
+
packageNamePACKAGING_HARDCODED = "mapFolding"
|
|
30
|
+
"""
|
|
31
|
+
Hardcoded package name used as fallback when dynamic resolution fails.
|
|
32
|
+
|
|
33
|
+
This constant serves as the ultimate fallback for package name resolution,
|
|
34
|
+
ensuring the package can function even when pyproject.toml is not accessible
|
|
35
|
+
during packaging or when module introspection fails during installation.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
concurrencyPackageHARDCODED = 'multiprocessing'
|
|
39
|
+
"""
|
|
40
|
+
Default package identifier for concurrent execution operations.
|
|
41
|
+
|
|
42
|
+
Specifies which Python concurrency package should be used as the default
|
|
43
|
+
for parallel computations. This can be overridden through PackageSettings
|
|
44
|
+
to use alternative packages like 'numba' for specialized performance scenarios.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
# Evaluate When Packaging
|
|
48
|
+
# https://github.com/hunterhogan/mapFolding/issues/18
|
|
49
|
+
try:
|
|
50
|
+
packageNamePACKAGING: str = tomli_load(Path("../pyproject.toml").open('rb'))["project"]["name"]
|
|
51
|
+
"""
|
|
52
|
+
Package name dynamically resolved from pyproject.toml during packaging.
|
|
53
|
+
|
|
54
|
+
This value is determined by reading the project configuration file during
|
|
55
|
+
the packaging process, ensuring consistency between the package metadata
|
|
56
|
+
and runtime identification. Falls back to hardcoded value if resolution fails.
|
|
57
|
+
"""
|
|
58
|
+
except Exception:
|
|
59
|
+
packageNamePACKAGING = packageNamePACKAGING_HARDCODED
|
|
60
|
+
|
|
61
|
+
# Evaluate When Installing
|
|
62
|
+
# https://github.com/hunterhogan/mapFolding/issues/18
|
|
63
|
+
def getPathPackageINSTALLING() -> Path:
|
|
64
|
+
"""
|
|
65
|
+
Resolve the absolute filesystem path to the installed package directory.
|
|
66
|
+
|
|
67
|
+
This function determines the package location at runtime by introspecting
|
|
68
|
+
the imported module's file location. It handles both regular Python files
|
|
69
|
+
and package directories, ensuring reliable path resolution across different
|
|
70
|
+
installation methods and environments.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
pathPackage: Absolute path to the package directory containing the module files.
|
|
74
|
+
|
|
75
|
+
Notes:
|
|
76
|
+
The function automatically handles the case where module introspection
|
|
77
|
+
returns a file path by extracting the parent directory, ensuring the
|
|
78
|
+
returned path always points to the package directory itself.
|
|
79
|
+
"""
|
|
80
|
+
pathPackage: Path = Path(inspect_getfile(importlib_import_module(packageNamePACKAGING)))
|
|
81
|
+
if pathPackage.is_file():
|
|
82
|
+
pathPackage = pathPackage.parent
|
|
83
|
+
return pathPackage
|
|
84
|
+
|
|
85
|
+
@dataclasses.dataclass
|
|
86
|
+
class PackageSettings:
|
|
87
|
+
"""
|
|
88
|
+
Centralized configuration container for all package-wide settings.
|
|
89
|
+
|
|
90
|
+
This dataclass serves as the single source of truth for package configuration,
|
|
91
|
+
providing both static and dynamically-resolved values needed throughout the
|
|
92
|
+
package lifecycle. The metadata on each field indicates when that value is
|
|
93
|
+
determined - either during packaging or at installation/runtime.
|
|
94
|
+
|
|
95
|
+
The design supports different evaluation phases to optimize performance and
|
|
96
|
+
reliability:
|
|
97
|
+
- Packaging-time: Values that can be determined during package creation
|
|
98
|
+
- Installing-time: Values that require filesystem access or module introspection
|
|
99
|
+
|
|
100
|
+
Attributes:
|
|
101
|
+
fileExtension: Standard file extension for Python modules in this package.
|
|
102
|
+
packageName: Canonical name of the package as defined in project configuration.
|
|
103
|
+
pathPackage: Absolute filesystem path to the installed package directory.
|
|
104
|
+
concurrencyPackage: Package to use for concurrent execution operations.
|
|
105
|
+
"""
|
|
106
|
+
fileExtension: str = dataclasses.field(default='.py', metadata={'evaluateWhen': 'installing'})
|
|
107
|
+
packageName: str = dataclasses.field(default = packageNamePACKAGING, metadata={'evaluateWhen': 'packaging'})
|
|
108
|
+
pathPackage: Path = dataclasses.field(default_factory=getPathPackageINSTALLING, metadata={'evaluateWhen': 'installing'})
|
|
109
|
+
concurrencyPackage: str | None = None
|
|
110
|
+
"""
|
|
111
|
+
Package identifier for concurrent execution operations.
|
|
112
|
+
|
|
113
|
+
Specifies which Python package should be used for parallel processing
|
|
114
|
+
in computationally intensive operations. When None, the default concurrency
|
|
115
|
+
package specified in the module constants is used. Accepted values include
|
|
116
|
+
'multiprocessing' for standard parallel processing and 'numba' for
|
|
117
|
+
specialized numerical computations.
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
concurrencyPackage = concurrencyPackageHARDCODED
|
|
121
|
+
"""
|
|
122
|
+
Active concurrency package configuration for the current session.
|
|
123
|
+
|
|
124
|
+
This module-level variable holds the currently selected concurrency package
|
|
125
|
+
identifier, initialized from the hardcoded default but available for runtime
|
|
126
|
+
modification through the package settings system.
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
packageSettings = PackageSettings(concurrencyPackage=concurrencyPackage)
|
|
130
|
+
"""
|
|
131
|
+
Global package settings instance providing access to all configuration values.
|
|
132
|
+
|
|
133
|
+
This singleton instance serves as the primary interface for accessing package
|
|
134
|
+
configuration throughout the codebase. It combines statically-defined defaults
|
|
135
|
+
with dynamically-resolved values to provide a complete configuration profile
|
|
136
|
+
for the current package installation and runtime environment.
|
|
137
|
+
"""
|
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
"""
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
This module
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
Unified interface for map folding computation orchestration.
|
|
3
|
+
|
|
4
|
+
This module represents the culmination of the computational ecosystem, providing
|
|
5
|
+
the primary entry point where users interact with the complete map folding analysis
|
|
6
|
+
system. It orchestrates all preceding layers: the configuration foundation,
|
|
7
|
+
type system, core utilities, state management, and persistent storage to deliver
|
|
8
|
+
a seamless computational experience.
|
|
9
|
+
|
|
10
|
+
The interface handles multiple computation flows including sequential algorithms,
|
|
11
|
+
experimental task division strategies, and various mathematical theorem implementations.
|
|
12
|
+
It provides flexible parameter validation, computation method selection, task
|
|
13
|
+
division management, processor utilization control, and automatic result persistence.
|
|
14
|
+
Integration with OEIS sequences enables research validation and mathematical
|
|
15
|
+
verification of computed results.
|
|
16
|
+
|
|
17
|
+
Through this unified interface, researchers and practitioners can access the full
|
|
18
|
+
power of Lunnon's algorithm implementation while the underlying computational
|
|
19
|
+
complexity remains elegantly abstracted. The interface ensures that whether
|
|
20
|
+
solving simple 2D problems or complex multi-dimensional challenges, users receive
|
|
21
|
+
consistent, reliable, and efficiently computed folding pattern counts.
|
|
10
22
|
"""
|
|
11
23
|
|
|
12
24
|
from collections.abc import Sequence
|
|
13
25
|
from mapFolding import (
|
|
14
|
-
getPathFilenameFoldsTotal,
|
|
15
|
-
|
|
16
|
-
saveFoldsTotal,
|
|
17
|
-
saveFoldsTotalFAILearly,
|
|
18
|
-
setProcessorLimit,
|
|
19
|
-
validateListDimensions,
|
|
26
|
+
getPathFilenameFoldsTotal, packageSettings, saveFoldsTotal, saveFoldsTotalFAILearly,
|
|
27
|
+
setProcessorLimit, validateListDimensions,
|
|
20
28
|
)
|
|
21
29
|
from os import PathLike
|
|
22
30
|
from pathlib import PurePath
|
|
@@ -129,7 +137,7 @@ def countFolds(listDimensions: Sequence[int] | None = None
|
|
|
129
137
|
mapFoldingState = doTheNeedful(mapFoldingState)
|
|
130
138
|
foldsTotal = mapFoldingState.foldsTotal
|
|
131
139
|
|
|
132
|
-
elif flow == 'theorem2' and any(
|
|
140
|
+
elif flow == 'theorem2' and any(dimension > 2 for dimension in mapShape):
|
|
133
141
|
from mapFolding.dataBaskets import MapFoldingState
|
|
134
142
|
mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
|
|
135
143
|
|
|
@@ -141,7 +149,7 @@ def countFolds(listDimensions: Sequence[int] | None = None
|
|
|
141
149
|
|
|
142
150
|
foldsTotal = mapFoldingState.foldsTotal
|
|
143
151
|
|
|
144
|
-
elif flow == 'theorem2Trimmed' and any(
|
|
152
|
+
elif flow == 'theorem2Trimmed' and any(dimension > 2 for dimension in mapShape):
|
|
145
153
|
from mapFolding.dataBaskets import MapFoldingState
|
|
146
154
|
mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
|
|
147
155
|
|
|
@@ -153,7 +161,7 @@ def countFolds(listDimensions: Sequence[int] | None = None
|
|
|
153
161
|
|
|
154
162
|
foldsTotal = mapFoldingState.foldsTotal
|
|
155
163
|
|
|
156
|
-
elif (flow == 'theorem2Numba' or taskDivisions == 0) and any(
|
|
164
|
+
elif (flow == 'theorem2Numba' or taskDivisions == 0) and any(dimension > 2 for dimension in mapShape):
|
|
157
165
|
from mapFolding.dataBaskets import MapFoldingState
|
|
158
166
|
mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
|
|
159
167
|
|
|
@@ -170,7 +178,9 @@ def countFolds(listDimensions: Sequence[int] | None = None
|
|
|
170
178
|
parallelMapFoldingState: ParallelMapFoldingState = ParallelMapFoldingState(mapShape, taskDivisions=taskDivisions)
|
|
171
179
|
|
|
172
180
|
from mapFolding.syntheticModules.countParallel import doTheNeedful
|
|
173
|
-
|
|
181
|
+
|
|
182
|
+
# `listStatesParallel` exists in case you want to research the parallel computation.
|
|
183
|
+
foldsTotal, listStatesParallel = doTheNeedful(parallelMapFoldingState, concurrencyLimit) # pyright: ignore[reportUnusedVariable]
|
|
174
184
|
|
|
175
185
|
else:
|
|
176
186
|
from mapFolding.dataBaskets import MapFoldingState
|
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Core
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
These utilities
|
|
18
|
-
|
|
2
|
+
Core computational utilities implementing Lunnon's map folding algorithm.
|
|
3
|
+
|
|
4
|
+
With the configuration foundation established and the type system defined, this
|
|
5
|
+
module provides the essential building blocks that transform mathematical theory
|
|
6
|
+
into executable computation. These utilities implement the fundamental operations
|
|
7
|
+
required by Lunnon's 1971 algorithm, handling dimension validation, connection
|
|
8
|
+
graph generation, and computational resource management.
|
|
9
|
+
|
|
10
|
+
The connection graph generation represents the mathematical heart of the algorithm,
|
|
11
|
+
calculating how leaves connect across dimensions using coordinate systems, parity
|
|
12
|
+
rules, and boundary conditions. This graph becomes the foundation upon which the
|
|
13
|
+
recursive folding analysis operates. Validation functions ensure computational
|
|
14
|
+
of large-scale problems. Validation functions ensure computational
|
|
15
|
+
integrity, while task division management enables experimental task division strategies.
|
|
16
|
+
|
|
17
|
+
These utilities follow DRY and SSOT principles, providing reusable functions that
|
|
18
|
+
serve as the computational assembly-line components. They prepare the essential
|
|
19
|
+
data structures and computational parameters that the state management system
|
|
20
|
+
requires to orchestrate the complex recursive algorithms.
|
|
19
21
|
"""
|
|
22
|
+
|
|
20
23
|
from collections.abc import Sequence
|
|
21
|
-
from mapFolding import
|
|
24
|
+
from mapFolding import NumPyIntegerType
|
|
22
25
|
from numpy import dtype as numpy_dtype, int64 as numpy_int64, ndarray
|
|
23
26
|
from sys import maxsize as sysMaxsize
|
|
24
27
|
from typing import Any
|
|
25
28
|
from Z0Z_tools import defineConcurrencyLimit, intInnit, oopsieKwargsie
|
|
26
29
|
import numpy
|
|
27
|
-
import dataclasses
|
|
28
30
|
|
|
29
31
|
def getLeavesTotal(mapShape: tuple[int, ...]) -> int:
|
|
30
32
|
"""
|