mapFolding 0.12.1__tar.gz → 0.12.3__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.3/PKG-INFO +163 -0
- mapfolding-0.12.3/README.md +115 -0
- mapfolding-0.12.3/mapFolding/__init__.py +88 -0
- mapfolding-0.12.3/mapFolding/_theSSOT.py +81 -0
- mapfolding-0.12.3/mapFolding/_theTypes.py +148 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/basecamp.py +62 -47
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/beDRY.py +100 -73
- mapfolding-0.12.3/mapFolding/dataBaskets.py +278 -0
- mapfolding-0.12.3/mapFolding/filesystemToolkit.py +264 -0
- mapfolding-0.12.3/mapFolding/oeis.py +655 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/reference/flattened.py +1 -1
- mapfolding-0.12.3/mapFolding/someAssemblyRequired/RecipeJob.py +215 -0
- mapfolding-0.12.3/mapFolding/someAssemblyRequired/__init__.py +85 -0
- mapfolding-0.12.3/mapFolding/someAssemblyRequired/_toolIfThis.py +148 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/someAssemblyRequired/_toolkitContainers.py +125 -44
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/someAssemblyRequired/getLLVMforNoReason.py +35 -26
- mapfolding-0.12.3/mapFolding/someAssemblyRequired/infoBooth.py +52 -0
- mapfolding-0.12.3/mapFolding/someAssemblyRequired/makeAllModules.py +785 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +161 -74
- mapfolding-0.12.3/mapFolding/someAssemblyRequired/toolkitNumba.py +314 -0
- mapfolding-0.12.3/mapFolding/someAssemblyRequired/transformationTools.py +194 -0
- mapfolding-0.12.3/mapFolding.egg-info/PKG-INFO +163 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding.egg-info/SOURCES.txt +3 -3
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding.egg-info/requires.txt +8 -10
- mapfolding-0.12.3/pyproject.toml +109 -0
- mapfolding-0.12.3/tests/__init__.py +28 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/tests/conftest.py +66 -61
- mapfolding-0.12.3/tests/test_computations.py +117 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/tests/test_filesystem.py +25 -1
- {mapfolding-0.12.1 → mapfolding-0.12.3}/tests/test_oeis.py +37 -7
- {mapfolding-0.12.1 → mapfolding-0.12.3}/tests/test_other.py +29 -2
- {mapfolding-0.12.1 → mapfolding-0.12.3}/tests/test_tasks.py +30 -2
- mapfolding-0.12.1/PKG-INFO +0 -184
- mapfolding-0.12.1/README.md +0 -133
- mapfolding-0.12.1/mapFolding/__init__.py +0 -62
- mapfolding-0.12.1/mapFolding/dataBaskets.py +0 -83
- mapfolding-0.12.1/mapFolding/datatypes.py +0 -18
- mapfolding-0.12.1/mapFolding/filesystemToolkit.py +0 -210
- mapfolding-0.12.1/mapFolding/oeis.py +0 -441
- mapfolding-0.12.1/mapFolding/someAssemblyRequired/RecipeJob.py +0 -89
- mapfolding-0.12.1/mapFolding/someAssemblyRequired/Z0Z_makeAllModules.py +0 -433
- mapfolding-0.12.1/mapFolding/someAssemblyRequired/__init__.py +0 -63
- mapfolding-0.12.1/mapFolding/someAssemblyRequired/_toolIfThis.py +0 -58
- mapfolding-0.12.1/mapFolding/someAssemblyRequired/infoBooth.py +0 -17
- mapfolding-0.12.1/mapFolding/someAssemblyRequired/toolkitNumba.py +0 -132
- mapfolding-0.12.1/mapFolding/someAssemblyRequired/transformationTools.py +0 -127
- mapfolding-0.12.1/mapFolding/theSSOT.py +0 -34
- mapfolding-0.12.1/mapFolding.egg-info/PKG-INFO +0 -184
- mapfolding-0.12.1/pyproject.toml +0 -107
- mapfolding-0.12.1/tests/__init__.py +0 -44
- mapfolding-0.12.1/tests/test_computations.py +0 -142
- {mapfolding-0.12.1 → mapfolding-0.12.3}/LICENSE +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/daoOfMapFolding.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/py.typed +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/reference/__init__.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/reference/hunterNumba.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/reference/irvineJavaPort.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/reference/jaxCount.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/reference/jobsCompleted/[2x19]/p2x19.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/reference/jobsCompleted/__init__.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/reference/jobsCompleted/p2x19/p2x19.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/reference/lunnonNumpy.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/reference/lunnonWhile.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/reference/rotatedEntryPoint.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/reference/total_countPlus1vsPlusN.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/syntheticModules/__init__.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/syntheticModules/countParallel.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/syntheticModules/daoOfMapFolding.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/syntheticModules/dataPacking.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/syntheticModules/initializeCount.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/syntheticModules/theorem2.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/syntheticModules/theorem2Numba.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding/syntheticModules/theorem2Trimmed.py +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding.egg-info/dependency_links.txt +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding.egg-info/entry_points.txt +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/mapFolding.egg-info/top_level.txt +0 -0
- {mapfolding-0.12.1 → mapfolding-0.12.3}/setup.cfg +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mapFolding
|
|
3
|
+
Version: 0.12.3
|
|
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: astToolkit>=0.5.0
|
|
33
|
+
Requires-Dist: hunterMakesPy
|
|
34
|
+
Requires-Dist: numba
|
|
35
|
+
Requires-Dist: numba_progress
|
|
36
|
+
Requires-Dist: numpy
|
|
37
|
+
Requires-Dist: platformdirs
|
|
38
|
+
Provides-Extra: development
|
|
39
|
+
Requires-Dist: mypy; extra == "development"
|
|
40
|
+
Requires-Dist: pyupgrade; extra == "development"
|
|
41
|
+
Requires-Dist: setuptools-scm; extra == "development"
|
|
42
|
+
Provides-Extra: testing
|
|
43
|
+
Requires-Dist: pytest; extra == "testing"
|
|
44
|
+
Requires-Dist: pytest-cov; extra == "testing"
|
|
45
|
+
Requires-Dist: pytest-env; extra == "testing"
|
|
46
|
+
Requires-Dist: pytest-xdist; extra == "testing"
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+
# mapFolding
|
|
50
|
+
|
|
51
|
+
[](https://pypi.org/project/mapFolding/)
|
|
52
|
+
[](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml)
|
|
53
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
54
|
+
|
|
55
|
+
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.
|
|
56
|
+
|
|
57
|
+
(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.)
|
|
58
|
+
|
|
59
|
+
## The Mathematical Problem
|
|
60
|
+
|
|
61
|
+
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.
|
|
62
|
+
|
|
63
|
+
The calculations extend the Online Encyclopedia of Integer Sequences (OEIS):
|
|
64
|
+
|
|
65
|
+
- **A001415**: 2×n strips (computed through n=20 for the first time)
|
|
66
|
+
- **A001418**: n×n squares
|
|
67
|
+
- **A001416**: 3×n strips
|
|
68
|
+
- **A001417**: n-dimensional hypercubes
|
|
69
|
+
- **A195646**: 3×3×...×3 hypercubes
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from mapFolding import oeisIDfor_n
|
|
73
|
+
|
|
74
|
+
# How many ways can you fold a 2×4 strip?
|
|
75
|
+
foldsTotal = oeisIDfor_n('A001415', 4)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## The Computational Challenge
|
|
79
|
+
|
|
80
|
+
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.
|
|
81
|
+
|
|
82
|
+
## What This Package Provides
|
|
83
|
+
|
|
84
|
+
### Core Functionality
|
|
85
|
+
|
|
86
|
+
- **Complete implementation** of Lunnon's recursive algorithm
|
|
87
|
+
- **Mathematical validation** through OEIS integration and caching
|
|
88
|
+
- **Type-safe computational state** management with automatic initialization
|
|
89
|
+
- **Result persistence** for long-running calculations
|
|
90
|
+
|
|
91
|
+
### Algorithm Transformation System
|
|
92
|
+
|
|
93
|
+
- **AST manipulation framework** for converting dataclass-based algorithms to optimized implementations
|
|
94
|
+
- **Automatic code generation** that produces standalone, highly optimized computation modules
|
|
95
|
+
- **Dataclass decomposition** to enable Numba compatibility while preserving readable source code
|
|
96
|
+
- **Comprehensive optimization** including dead code elimination, static value embedding, and aggressive compilation settings
|
|
97
|
+
|
|
98
|
+
### Educational Resources
|
|
99
|
+
|
|
100
|
+
- **Historical implementations** showing algorithm evolution from 1971 to present
|
|
101
|
+
- **Performance comparison** studies demonstrating optimization techniques
|
|
102
|
+
- **Complete test suite** with patterns for validating custom implementations
|
|
103
|
+
- **Reference documentation** for extending the transformation framework
|
|
104
|
+
|
|
105
|
+
## Use Cases
|
|
106
|
+
|
|
107
|
+
**Mathematical Research**: Explore folding pattern properties, extend known sequences, or validate theoretical results against computed values.
|
|
108
|
+
|
|
109
|
+
**Algorithm Optimization Learning**: Study a complete transformation pipeline that converts high-level algorithms into production-ready optimized code.
|
|
110
|
+
|
|
111
|
+
**Performance Computing Education**: Examine techniques for achieving maximum Python performance through Numba integration, AST manipulation, and specialized code generation.
|
|
112
|
+
|
|
113
|
+
**Combinatorial Problem Solving**: Use the framework as a template for optimizing other recursive combinatorial algorithms.
|
|
114
|
+
|
|
115
|
+
## Example Usage
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from mapFolding import countFolds
|
|
119
|
+
|
|
120
|
+
# Count folding patterns for a 3×3 square
|
|
121
|
+
result = countFolds([3, 3])
|
|
122
|
+
|
|
123
|
+
# Access OEIS sequences directly
|
|
124
|
+
from mapFolding import oeisIDfor_n
|
|
125
|
+
strip_foldings = oeisIDfor_n('A001415', 6) # 2×6 strip
|
|
126
|
+
|
|
127
|
+
# Generate optimized code for specific dimensions
|
|
128
|
+
from mapFolding.someAssemblyRequired import makeJobTheorem2Numba
|
|
129
|
+
# Creates specialized modules for maximum performance
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Repository Structure
|
|
133
|
+
|
|
134
|
+
- `mapFolding/`: Core implementation with modular architecture
|
|
135
|
+
- `reference/`: Historical algorithm implementations and performance studies
|
|
136
|
+
- `someAssemblyRequired/`: AST transformation framework
|
|
137
|
+
- `tests/`: Comprehensive validation suite
|
|
138
|
+
- `jobs/`: Generated optimized modules for specific calculations
|
|
139
|
+
|
|
140
|
+
## Performance Characteristics
|
|
141
|
+
|
|
142
|
+
- **Pure Python baseline**: Educational implementations for understanding
|
|
143
|
+
- **NumPy optimization**: ~10× improvement through vectorized operations
|
|
144
|
+
- **Numba compilation**: ~100× improvement through native code generation
|
|
145
|
+
- **Specialized modules**: ~1000× improvement through static optimization and embedded constants
|
|
146
|
+
|
|
147
|
+
Actual performance varies by map dimensions and available hardware.
|
|
148
|
+
|
|
149
|
+
## My recovery
|
|
150
|
+
|
|
151
|
+
[](https://HunterThinks.com/support)
|
|
152
|
+
[](https://www.youtube.com/@HunterHogan)
|
|
153
|
+
|
|
154
|
+
## How to code
|
|
155
|
+
|
|
156
|
+
Coding One Step at a Time:
|
|
157
|
+
|
|
158
|
+
0. WRITE CODE.
|
|
159
|
+
1. Don't write stupid code that's hard to revise.
|
|
160
|
+
2. Write good code.
|
|
161
|
+
3. When revising, write better code.
|
|
162
|
+
|
|
163
|
+
[](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,88 @@
|
|
|
1
|
+
"""Computational toolkit for analyzing multi-dimensional map folding patterns.
|
|
2
|
+
|
|
3
|
+
(AI generated docstring)
|
|
4
|
+
|
|
5
|
+
The mapFolding package provides a complete implementation of Lunnon's 1971 algorithm
|
|
6
|
+
for counting distinct folding patterns in multi-dimensional maps. This toolkit
|
|
7
|
+
transforms the complex combinatorial mathematics of map folding into accessible
|
|
8
|
+
computational tools, enabling researchers and practitioners to analyze folding
|
|
9
|
+
patterns across dimensions from simple 2D strips to complex multi-dimensional
|
|
10
|
+
hypercubes.
|
|
11
|
+
|
|
12
|
+
The package architecture follows Domain-Driven Design principles, organizing
|
|
13
|
+
functionality around mathematical concepts rather than implementation details.
|
|
14
|
+
The computational framework integrates type safety, persistent result storage,
|
|
15
|
+
and mathematical validation through OEIS sequence integration.
|
|
16
|
+
|
|
17
|
+
Core Transformation Tools:
|
|
18
|
+
countFolds: Primary interface for computing folding pattern counts
|
|
19
|
+
MapFoldingState: Computational state management for recursive analysis
|
|
20
|
+
Connection graph generation: Mathematical foundation for folding relationships
|
|
21
|
+
Task division utilities: Experimental parallel computation options
|
|
22
|
+
OEIS integration: Mathematical validation and sequence discovery
|
|
23
|
+
|
|
24
|
+
Primary Use Cases:
|
|
25
|
+
Mathematical research into folding pattern properties and relationships
|
|
26
|
+
Educational exploration of combinatorial mathematics concepts
|
|
27
|
+
Computational validation of theoretical results
|
|
28
|
+
Extension of known mathematical sequences through new discoveries
|
|
29
|
+
|
|
30
|
+
The package handles the full spectrum of map folding analysis, from simple
|
|
31
|
+
educational examples to research-grade computations requiring multi-day processing
|
|
32
|
+
time. Results integrate seamlessly with the mathematical community through
|
|
33
|
+
comprehensive OEIS connectivity and standardized result persistence.
|
|
34
|
+
|
|
35
|
+
For researchers: The computational foundation supports both replication of
|
|
36
|
+
established results and discovery of new mathematical relationships.
|
|
37
|
+
|
|
38
|
+
For educators: The clear interfaces and type safety enable confident exploration
|
|
39
|
+
of combinatorial concepts without computational complexity barriers.
|
|
40
|
+
|
|
41
|
+
For practitioners: The robust result persistence and type safety ensure
|
|
42
|
+
reliable completion of complex analytical tasks.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
from mapFolding._theTypes import (
|
|
46
|
+
Array1DElephino as Array1DElephino,
|
|
47
|
+
Array1DFoldsTotal as Array1DFoldsTotal,
|
|
48
|
+
Array1DLeavesTotal as Array1DLeavesTotal,
|
|
49
|
+
Array3D as Array3D,
|
|
50
|
+
DatatypeElephino as DatatypeElephino,
|
|
51
|
+
DatatypeFoldsTotal as DatatypeFoldsTotal,
|
|
52
|
+
DatatypeLeavesTotal as DatatypeLeavesTotal,
|
|
53
|
+
NumPyElephino as NumPyElephino,
|
|
54
|
+
NumPyFoldsTotal as NumPyFoldsTotal,
|
|
55
|
+
NumPyIntegerType as NumPyIntegerType,
|
|
56
|
+
NumPyLeavesTotal as NumPyLeavesTotal,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
from mapFolding._theSSOT import packageSettings as packageSettings
|
|
60
|
+
|
|
61
|
+
from mapFolding.beDRY import (
|
|
62
|
+
getConnectionGraph as getConnectionGraph,
|
|
63
|
+
getLeavesTotal as getLeavesTotal,
|
|
64
|
+
getTaskDivisions as getTaskDivisions,
|
|
65
|
+
makeDataContainer as makeDataContainer,
|
|
66
|
+
setProcessorLimit as setProcessorLimit,
|
|
67
|
+
validateListDimensions as validateListDimensions,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
from mapFolding.dataBaskets import MapFoldingState as MapFoldingState
|
|
71
|
+
|
|
72
|
+
from mapFolding.filesystemToolkit import (
|
|
73
|
+
getFilenameFoldsTotal as getFilenameFoldsTotal,
|
|
74
|
+
getPathFilenameFoldsTotal as getPathFilenameFoldsTotal,
|
|
75
|
+
getPathRootJobDEFAULT as getPathRootJobDEFAULT,
|
|
76
|
+
saveFoldsTotal as saveFoldsTotal,
|
|
77
|
+
saveFoldsTotalFAILearly as saveFoldsTotalFAILearly,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
from mapFolding.basecamp import countFolds as countFolds
|
|
81
|
+
|
|
82
|
+
from mapFolding.oeis import (
|
|
83
|
+
clearOEIScache as clearOEIScache,
|
|
84
|
+
getFoldsTotalKnown as getFoldsTotalKnown,
|
|
85
|
+
getOEISids as getOEISids,
|
|
86
|
+
OEIS_for_n as OEIS_for_n,
|
|
87
|
+
oeisIDfor_n as oeisIDfor_n,
|
|
88
|
+
)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Foundation layer for the map folding computational ecosystem.
|
|
3
|
+
|
|
4
|
+
(AI generated docstring)
|
|
5
|
+
|
|
6
|
+
This module establishes the fundamental configuration infrastructure that underpins
|
|
7
|
+
all map folding operations. Map folding, as defined by Lunnon's 1971 algorithm,
|
|
8
|
+
requires precise coordination of computational resources, type systems, and data
|
|
9
|
+
flow management to solve the complex combinatorial problem of counting distinct
|
|
10
|
+
folding patterns across multi-dimensional maps.
|
|
11
|
+
|
|
12
|
+
The Single Source Of Truth (SSOT) principle governs this foundation, ensuring that
|
|
13
|
+
package identity, filesystem locations, and concurrency configuration remain
|
|
14
|
+
consistent across all computational phases. During packaging, static metadata is
|
|
15
|
+
resolved from pyproject.toml. During installation, filesystem-dependent paths are
|
|
16
|
+
dynamically discovered. During runtime, the `packageSettings` instance provides
|
|
17
|
+
unified access to all configuration values, enabling the sophisticated computational
|
|
18
|
+
framework that follows.
|
|
19
|
+
|
|
20
|
+
This configuration foundation supports the type system definition, core utility
|
|
21
|
+
functions, computational state management, result persistence, and ultimately the
|
|
22
|
+
main computational interface that users interact with to solve map folding problems.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from hunterMakesPy import PackageSettings
|
|
26
|
+
import dataclasses
|
|
27
|
+
|
|
28
|
+
packageNameHARDCODED = "mapFolding"
|
|
29
|
+
"""Hardcoded package name used as fallback when dynamic resolution fails."""
|
|
30
|
+
|
|
31
|
+
concurrencyPackageHARDCODED = 'multiprocessing'
|
|
32
|
+
"""Default package identifier for concurrent execution operations."""
|
|
33
|
+
|
|
34
|
+
@dataclasses.dataclass
|
|
35
|
+
class mapFoldingPackageSettings(PackageSettings):
|
|
36
|
+
"""Centralized configuration container for all package-wide settings.
|
|
37
|
+
|
|
38
|
+
(AI generated docstring)
|
|
39
|
+
|
|
40
|
+
This dataclass serves as the single source of truth for package configuration,
|
|
41
|
+
providing both static and dynamically-resolved values needed throughout the
|
|
42
|
+
package lifecycle. The metadata on each field indicates when that value is
|
|
43
|
+
determined - either during packaging or at installation/runtime.
|
|
44
|
+
|
|
45
|
+
The design supports different evaluation phases to optimize performance and
|
|
46
|
+
reliability. Packaging-time values can be determined during package creation,
|
|
47
|
+
while installing-time values require filesystem access or module introspection.
|
|
48
|
+
|
|
49
|
+
Attributes
|
|
50
|
+
----------
|
|
51
|
+
fileExtension : str = '.py'
|
|
52
|
+
Standard file extension for Python modules in this package.
|
|
53
|
+
packageName : str
|
|
54
|
+
Canonical name of the package as defined in project configuration.
|
|
55
|
+
pathPackage : Path
|
|
56
|
+
Absolute filesystem path to the installed package directory.
|
|
57
|
+
concurrencyPackage : str | None = None
|
|
58
|
+
Package identifier for concurrent execution operations.
|
|
59
|
+
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
concurrencyPackage: str | None = None
|
|
63
|
+
"""
|
|
64
|
+
Package identifier for concurrent execution operations.
|
|
65
|
+
|
|
66
|
+
(AI generated docstring)
|
|
67
|
+
|
|
68
|
+
Specifies which Python package should be used for parallel processing
|
|
69
|
+
in computationally intensive operations. When None, the default concurrency
|
|
70
|
+
package specified in the module constants is used. Accepted values include
|
|
71
|
+
'multiprocessing' for standard parallel processing and 'numba' for
|
|
72
|
+
specialized numerical computations.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
concurrencyPackage = concurrencyPackageHARDCODED
|
|
76
|
+
"""Active concurrency package configuration for the current session."""
|
|
77
|
+
|
|
78
|
+
packageSettings = mapFoldingPackageSettings(
|
|
79
|
+
identifierPackageFALLBACK=packageNameHARDCODED
|
|
80
|
+
, concurrencyPackage=concurrencyPackage)
|
|
81
|
+
"""Global package settings."""
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Type system architecture for map folding computational domains.
|
|
3
|
+
|
|
4
|
+
(AI generated docstring)
|
|
5
|
+
|
|
6
|
+
Building upon the configuration foundation, this module defines the complete type
|
|
7
|
+
hierarchy that ensures type safety and semantic clarity throughout the map folding
|
|
8
|
+
computational framework. The type system recognizes three distinct computational
|
|
9
|
+
domains, each with specific data characteristics and performance requirements
|
|
10
|
+
that emerge from Lunnon's algorithm implementation.
|
|
11
|
+
|
|
12
|
+
The Leaves domain handles map sections, their indices, and dimensional parameters.
|
|
13
|
+
The Elephino domain manages internal computational state, gap calculations, and
|
|
14
|
+
temporary indices used during the recursive folding analysis. The Folds domain
|
|
15
|
+
represents final pattern counts and computation results. Each domain employs both
|
|
16
|
+
Python types for general computation and NumPy types for performance-critical
|
|
17
|
+
array operations.
|
|
18
|
+
|
|
19
|
+
This dual-type strategy enables the core utility functions to operate with type
|
|
20
|
+
safety while maintaining the computational efficiency required for analyzing
|
|
21
|
+
complex multi-dimensional folding patterns. The array types built from these
|
|
22
|
+
base types provide the structured data containers that computational state
|
|
23
|
+
management depends upon.
|
|
24
|
+
"""
|
|
25
|
+
from numpy import dtype, integer, ndarray, uint8 as numpy_uint8, uint16 as numpy_uint16, uint64 as numpy_uint64
|
|
26
|
+
from typing import Any, TypeAlias, TypeVar
|
|
27
|
+
|
|
28
|
+
NumPyIntegerType = TypeVar('NumPyIntegerType', bound=integer[Any], covariant=True)
|
|
29
|
+
"""
|
|
30
|
+
Generic type variable for NumPy integer types used in computational operations.
|
|
31
|
+
|
|
32
|
+
(AI generated docstring)
|
|
33
|
+
|
|
34
|
+
This type variable enables generic programming with NumPy integer types while
|
|
35
|
+
maintaining type safety. It supports covariant relationships between different
|
|
36
|
+
NumPy integer types and their array containers.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
DatatypeLeavesTotal: TypeAlias = int
|
|
40
|
+
"""
|
|
41
|
+
Python type for leaf-related counts and indices in map folding computations.
|
|
42
|
+
|
|
43
|
+
(AI generated docstring)
|
|
44
|
+
|
|
45
|
+
Represents quantities related to individual map sections (leaves), including
|
|
46
|
+
total leaf counts, leaf indices, and dimensional parameters. Uses standard
|
|
47
|
+
Python integers for compatibility with general computations while enabling
|
|
48
|
+
conversion to NumPy types when performance optimization is needed.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
NumPyLeavesTotal: TypeAlias = numpy_uint8
|
|
52
|
+
"""
|
|
53
|
+
NumPy type for efficient leaf-related computations and array operations.
|
|
54
|
+
|
|
55
|
+
(AI generated docstring)
|
|
56
|
+
|
|
57
|
+
Corresponds to `DatatypeLeavesTotal` but optimized for NumPy operations.
|
|
58
|
+
Uses 8-bit unsigned integers since leaf counts in practical map folding
|
|
59
|
+
scenarios typically remain small (under 256).
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
DatatypeElephino: TypeAlias = int
|
|
63
|
+
"""
|
|
64
|
+
Python type for internal computational indices and intermediate values.
|
|
65
|
+
|
|
66
|
+
(AI generated docstring)
|
|
67
|
+
|
|
68
|
+
Used for temporary variables, gap indices, and other internal computational
|
|
69
|
+
state that doesn't directly correspond to leaves or final fold counts. The
|
|
70
|
+
name follows the package convention for internal computational domains.
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
NumPyElephino: TypeAlias = numpy_uint16
|
|
74
|
+
"""
|
|
75
|
+
NumPy type for internal computational operations requiring moderate value ranges.
|
|
76
|
+
|
|
77
|
+
(AI generated docstring)
|
|
78
|
+
|
|
79
|
+
Corresponds to `DatatypeElephino` with 16-bit unsigned integer storage,
|
|
80
|
+
providing sufficient range for internal computations while maintaining
|
|
81
|
+
memory efficiency in array operations.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
DatatypeFoldsTotal: TypeAlias = int
|
|
85
|
+
"""
|
|
86
|
+
Python type for final fold counts and pattern totals.
|
|
87
|
+
|
|
88
|
+
(AI generated docstring)
|
|
89
|
+
|
|
90
|
+
Represents the ultimate results of map folding computations - the total number
|
|
91
|
+
of distinct folding patterns possible for a given map configuration. These
|
|
92
|
+
values can grow exponentially with map size, requiring flexible integer types.
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
NumPyFoldsTotal: TypeAlias = numpy_uint64
|
|
96
|
+
"""
|
|
97
|
+
NumPy type for large fold count computations and high-precision results.
|
|
98
|
+
|
|
99
|
+
(AI generated docstring)
|
|
100
|
+
|
|
101
|
+
Corresponds to `DatatypeFoldsTotal` using 64-bit unsigned integers to
|
|
102
|
+
accommodate the exponentially large values that can result from map folding
|
|
103
|
+
computations on even moderately-sized maps.
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
Array3D: TypeAlias = ndarray[tuple[int, int, int], dtype[NumPyLeavesTotal]]
|
|
107
|
+
"""
|
|
108
|
+
Three-dimensional NumPy array type for connection graph representations.
|
|
109
|
+
|
|
110
|
+
(AI generated docstring)
|
|
111
|
+
|
|
112
|
+
Used to store the connectivity relationships between map leaves in a
|
|
113
|
+
3D array structure. The array uses `NumPyLeavesTotal` element type since
|
|
114
|
+
the stored values represent leaf indices and connection states.
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
Array1DLeavesTotal: TypeAlias = ndarray[tuple[int], dtype[NumPyLeavesTotal]]
|
|
118
|
+
"""
|
|
119
|
+
One-dimensional NumPy array type for leaf-related data sequences.
|
|
120
|
+
|
|
121
|
+
(AI generated docstring)
|
|
122
|
+
|
|
123
|
+
Stores sequences of leaf counts, indices, or related values in efficient
|
|
124
|
+
array format. Common uses include leaf sequences, gap locations, and
|
|
125
|
+
dimensional data where each element relates to the leaves domain.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
Array1DElephino: TypeAlias = ndarray[tuple[int], dtype[NumPyElephino]]
|
|
129
|
+
"""
|
|
130
|
+
One-dimensional NumPy array type for internal computational sequences.
|
|
131
|
+
|
|
132
|
+
(AI generated docstring)
|
|
133
|
+
|
|
134
|
+
Used for storing sequences of internal computational values such as
|
|
135
|
+
gap range starts, temporary indices, and other intermediate results
|
|
136
|
+
that require the elephino computational domain's value range.
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
Array1DFoldsTotal: TypeAlias = ndarray[tuple[int], dtype[NumPyFoldsTotal]]
|
|
140
|
+
"""
|
|
141
|
+
One-dimensional NumPy array type for sequences of fold count results.
|
|
142
|
+
|
|
143
|
+
(AI generated docstring)
|
|
144
|
+
|
|
145
|
+
Stores sequences of fold totals and pattern counts, using the large
|
|
146
|
+
integer type to accommodate the potentially enormous values that
|
|
147
|
+
result from complex map folding computations.
|
|
148
|
+
"""
|