mapFolding 0.16.2__py3-none-any.whl → 0.16.4__py3-none-any.whl
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.
- easyRun/NOTcountingFolds.py +6 -5
- easyRun/countFolds.py +1 -1
- easyRun/generateAllModules.py +14 -0
- easyRun/meanders.py +1 -1
- mapFolding/__init__.py +1 -0
- mapFolding/_theSSOT.py +3 -2
- mapFolding/_theTypes.py +3 -0
- mapFolding/algorithms/A086345.py +75 -0
- mapFolding/algorithms/oeisIDbyFormula.py +2 -2
- mapFolding/algorithms/symmetricFolds.py +36 -0
- mapFolding/basecamp.py +80 -149
- mapFolding/dataBaskets.py +123 -5
- mapFolding/filesystemToolkit.py +4 -32
- mapFolding/oeis.py +5 -12
- mapFolding/reference/A086345Wu.py +25 -0
- mapFolding/reference/matrixMeandersAnalysis/signatures.py +3 -0
- mapFolding/someAssemblyRequired/A007822/A007822rawMaterials.py +10 -45
- mapFolding/someAssemblyRequired/A007822/_asynchronousAnnex.py +51 -0
- mapFolding/someAssemblyRequired/A007822/makeA007822AsynchronousModules.py +36 -195
- mapFolding/someAssemblyRequired/A007822/makeA007822Modules.py +42 -44
- mapFolding/someAssemblyRequired/RecipeJob.py +78 -18
- mapFolding/someAssemblyRequired/__init__.py +3 -8
- mapFolding/someAssemblyRequired/_toolkitContainers.py +32 -3
- mapFolding/someAssemblyRequired/infoBooth.py +40 -23
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +74 -153
- mapFolding/someAssemblyRequired/makeJobTheorem2codon.py +56 -88
- mapFolding/someAssemblyRequired/makingModules_count.py +10 -12
- mapFolding/someAssemblyRequired/makingModules_doTheNeedful.py +6 -68
- mapFolding/someAssemblyRequired/{mapFolding → mapFoldingModules}/makeMapFoldingModules.py +24 -30
- mapFolding/someAssemblyRequired/meanders/makeMeandersModules.py +8 -6
- mapFolding/someAssemblyRequired/toolkitMakeModules.py +2 -2
- mapFolding/someAssemblyRequired/toolkitNumba.py +1 -1
- mapFolding/someAssemblyRequired/transformationTools.py +10 -12
- mapFolding/syntheticModules/A007822/algorithm.py +45 -50
- mapFolding/syntheticModules/A007822/asynchronous.py +91 -34
- mapFolding/syntheticModules/A007822/initializeState.py +15 -21
- mapFolding/syntheticModules/A007822/theorem2.py +16 -22
- mapFolding/syntheticModules/A007822/theorem2Numba.py +20 -26
- mapFolding/syntheticModules/A007822/theorem2Trimmed.py +17 -23
- mapFolding/syntheticModules/countParallelNumba.py +3 -7
- mapFolding/syntheticModules/daoOfMapFoldingNumba.py +1 -2
- mapFolding/syntheticModules/meanders/bigInt.py +9 -9
- mapFolding/syntheticModules/theorem2Numba.py +28 -9
- mapFolding/syntheticModules/theorem2Trimmed.py +1 -1
- mapFolding/tests/test_computations.py +1 -1
- {mapfolding-0.16.2.dist-info → mapfolding-0.16.4.dist-info}/METADATA +4 -1
- {mapfolding-0.16.2.dist-info → mapfolding-0.16.4.dist-info}/RECORD +52 -61
- mapFolding/_dataPacking.py +0 -68
- mapFolding/reference/meandersDumpingGround/A005316intOptimized.py +0 -122
- mapFolding/reference/meandersDumpingGround/A005316optimized128bit.py +0 -79
- mapFolding/reference/meandersDumpingGround/matrixMeandersBaseline.py +0 -65
- mapFolding/reference/meandersDumpingGround/matrixMeandersBaselineAnnex.py +0 -84
- mapFolding/reference/meandersDumpingGround/matrixMeandersSimpleQueue.py +0 -90
- mapFolding/syntheticModules/A007822/algorithmNumba.py +0 -94
- mapFolding/syntheticModules/A007822/asynchronousAnnex.py +0 -66
- mapFolding/syntheticModules/A007822/asynchronousAnnexNumba.py +0 -70
- mapFolding/syntheticModules/A007822/asynchronousNumba.py +0 -79
- mapFolding/syntheticModules/A007822/asynchronousTheorem2.py +0 -65
- mapFolding/syntheticModules/A007822/asynchronousTrimmed.py +0 -56
- mapFolding/syntheticModules/dataPacking.py +0 -26
- mapFolding/syntheticModules/dataPackingA007822.py +0 -92
- /mapFolding/someAssemblyRequired/{mapFolding → mapFoldingModules}/__init__.py +0 -0
- {mapfolding-0.16.2.dist-info → mapfolding-0.16.4.dist-info}/WHEEL +0 -0
- {mapfolding-0.16.2.dist-info → mapfolding-0.16.4.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.16.2.dist-info → mapfolding-0.16.4.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.16.2.dist-info → mapfolding-0.16.4.dist-info}/top_level.txt +0 -0
mapFolding/dataBaskets.py
CHANGED
|
@@ -21,8 +21,8 @@ integrity throughout the recursive analysis while providing the structured data
|
|
|
21
21
|
access patterns that enable efficient result persistence and retrieval.
|
|
22
22
|
"""
|
|
23
23
|
from mapFolding import (
|
|
24
|
-
Array1DElephino, Array1DLeavesTotal, Array3DLeavesTotal, DatatypeElephino, DatatypeFoldsTotal,
|
|
25
|
-
getConnectionGraph, getLeavesTotal, makeDataContainer)
|
|
24
|
+
Array1DElephino, Array1DLeavesTotal, Array2DLeavesTotal, Array3DLeavesTotal, DatatypeElephino, DatatypeFoldsTotal,
|
|
25
|
+
DatatypeLeavesTotal, getConnectionGraph, getLeavesTotal, makeDataContainer)
|
|
26
26
|
from numpy.typing import NDArray
|
|
27
27
|
from typing import TypeAlias
|
|
28
28
|
import dataclasses
|
|
@@ -111,8 +111,6 @@ class MapFoldingState:
|
|
|
111
111
|
"""Array tracking the leaves above to the current leaf, `leaf1ndex`, during computation."""
|
|
112
112
|
leafBelow: Array1DLeavesTotal = dataclasses.field(default=None, init=True, metadata={'dtype': Array1DLeavesTotal.__args__[1].__args__[0]}) # pyright: ignore[reportAssignmentType, reportAttributeAccessIssue, reportUnknownMemberType]
|
|
113
113
|
"""Array tracking the leaves below to the current leaf, `leaf1ndex`, during computation."""
|
|
114
|
-
leafComparison: Array1DLeavesTotal = dataclasses.field(default=None, init=True, metadata={'dtype': Array1DLeavesTotal.__args__[1].__args__[0]}) # pyright: ignore[reportAssignmentType, reportAttributeAccessIssue, reportUnknownMemberType]
|
|
115
|
-
"""Array for finding symmetric folds."""
|
|
116
114
|
|
|
117
115
|
connectionGraph: Array3DLeavesTotal = dataclasses.field(init=False, metadata={'dtype': Array3DLeavesTotal.__args__[1].__args__[0]}) # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue]
|
|
118
116
|
"""Unchanging array representing connections between all leaves."""
|
|
@@ -126,7 +124,7 @@ class MapFoldingState:
|
|
|
126
124
|
|
|
127
125
|
Returns
|
|
128
126
|
-------
|
|
129
|
-
|
|
127
|
+
foldsTotal : DatatypeFoldsTotal
|
|
130
128
|
The complete count of distinct folding patterns achievable with the current map configuration.
|
|
131
129
|
|
|
132
130
|
"""
|
|
@@ -154,6 +152,126 @@ class MapFoldingState:
|
|
|
154
152
|
if self.gapRangeStart is None: self.gapRangeStart = makeDataContainer(leavesTotalAsInt + 1, self.__dataclass_fields__['gapRangeStart'].metadata['dtype']) # pyright: ignore[reportUnnecessaryComparison] # noqa: E701
|
|
155
153
|
if self.leafAbove is None: self.leafAbove = makeDataContainer(leavesTotalAsInt + 1, self.__dataclass_fields__['leafAbove'].metadata['dtype']) # pyright: ignore[reportUnnecessaryComparison] # noqa: E701
|
|
156
154
|
if self.leafBelow is None: self.leafBelow = makeDataContainer(leavesTotalAsInt + 1, self.__dataclass_fields__['leafBelow'].metadata['dtype']) # pyright: ignore[reportUnnecessaryComparison] # noqa: E701
|
|
155
|
+
|
|
156
|
+
@dataclasses.dataclass(slots=True)
|
|
157
|
+
class SymmetricFoldsState:
|
|
158
|
+
"""Core computational state for symmetric map folding algorithms.
|
|
159
|
+
|
|
160
|
+
Attributes
|
|
161
|
+
----------
|
|
162
|
+
mapShape : tuple[DatatypeLeavesTotal, ...]
|
|
163
|
+
Dimensions of the map being analyzed for folding patterns.
|
|
164
|
+
groupsOfFolds : DatatypeFoldsTotal = DatatypeFoldsTotal(0)
|
|
165
|
+
Current count of distinct folding pattern groups: each group has `leavesTotal`-many foldings.
|
|
166
|
+
gap1ndex : DatatypeElephino = DatatypeElephino(0)
|
|
167
|
+
The current 1-indexed position of the 'gap' during computation: 1-indexed as opposed to 0-indexed.
|
|
168
|
+
gap1ndexCeiling : DatatypeElephino = DatatypeElephino(0)
|
|
169
|
+
The upper bound of `gap1ndex`.
|
|
170
|
+
indexDimension : DatatypeLeavesTotal = DatatypeLeavesTotal(0)
|
|
171
|
+
The current 0-indexed position of the dimension during computation.
|
|
172
|
+
indexLeaf : DatatypeLeavesTotal = DatatypeLeavesTotal(0)
|
|
173
|
+
The current 0-indexed position of a leaf in a loop during computation: not to be confused with `leaf1ndex`.
|
|
174
|
+
indexMiniGap : DatatypeElephino = DatatypeElephino(0)
|
|
175
|
+
The current 0-indexed position of a 'gap' in a loop during computation.
|
|
176
|
+
leaf1ndex : DatatypeLeavesTotal = DatatypeLeavesTotal(1)
|
|
177
|
+
The current 1-indexed position of the leaf during computation: 1-indexed as opposed to 0-indexed.
|
|
178
|
+
leafConnectee : DatatypeLeavesTotal = DatatypeLeavesTotal(0)
|
|
179
|
+
Target leaf for connection operations.
|
|
180
|
+
dimensionsUnconstrained : DatatypeLeavesTotal = None
|
|
181
|
+
Count of dimensions not subject to folding constraints.
|
|
182
|
+
countDimensionsGapped : Array1DLeavesTotal = None
|
|
183
|
+
Array tracking computed number of dimensions with gaps.
|
|
184
|
+
gapRangeStart : Array1DElephino = None
|
|
185
|
+
Array tracking computed starting positions of gap ranges.
|
|
186
|
+
gapsWhere : Array1DLeavesTotal = None
|
|
187
|
+
Array indicating locations of gaps in the folding pattern.
|
|
188
|
+
leafAbove : Array1DLeavesTotal = None
|
|
189
|
+
Array tracking the leaves above to the current leaf, `leaf1ndex`, during computation.
|
|
190
|
+
leafBelow : Array1DLeavesTotal = None
|
|
191
|
+
Array tracking the leaves below to the current leaf, `leaf1ndex`, during computation.
|
|
192
|
+
leafComparison : Array1DLeavesTotal = None
|
|
193
|
+
Array for finding symmetric folds.
|
|
194
|
+
connectionGraph : Array3DLeavesTotal
|
|
195
|
+
Unchanging array representing connections between all leaves.
|
|
196
|
+
dimensionsTotal : DatatypeLeavesTotal
|
|
197
|
+
Unchanging total number of dimensions in the map.
|
|
198
|
+
leavesTotal : DatatypeLeavesTotal
|
|
199
|
+
Unchanging total number of leaves in the map.
|
|
200
|
+
|
|
201
|
+
"""
|
|
202
|
+
|
|
203
|
+
mapShape: tuple[DatatypeLeavesTotal, ...] = dataclasses.field(init=True, metadata={'elementConstructor': 'DatatypeLeavesTotal'})
|
|
204
|
+
"""Dimensions of the map being analyzed for folding patterns."""
|
|
205
|
+
|
|
206
|
+
groupsOfFolds: DatatypeFoldsTotal = dataclasses.field(default=DatatypeFoldsTotal(0), metadata={'theCountingIdentifier': True})
|
|
207
|
+
"""Current count of symmetric folds."""
|
|
208
|
+
|
|
209
|
+
gap1ndex: DatatypeElephino = DatatypeElephino(0) # noqa: RUF009
|
|
210
|
+
"""The current 1-indexed position of the 'gap' during computation: 1-indexed as opposed to 0-indexed."""
|
|
211
|
+
gap1ndexCeiling: DatatypeElephino = DatatypeElephino(0) # noqa: RUF009
|
|
212
|
+
"""The upper bound of `gap1ndex`."""
|
|
213
|
+
indexDimension: DatatypeLeavesTotal = DatatypeLeavesTotal(0) # noqa: RUF009
|
|
214
|
+
"""The current 0-indexed position of the dimension during computation."""
|
|
215
|
+
indexLeaf: DatatypeLeavesTotal = DatatypeLeavesTotal(0) # noqa: RUF009
|
|
216
|
+
"""The current 0-indexed position of a leaf in a loop during computation: not to be confused with `leaf1ndex`."""
|
|
217
|
+
indexMiniGap: DatatypeElephino = DatatypeElephino(0) # noqa: RUF009
|
|
218
|
+
"""The current 0-indexed position of a 'gap' in a loop during computation."""
|
|
219
|
+
leaf1ndex: DatatypeLeavesTotal = DatatypeLeavesTotal(1) # noqa: RUF009
|
|
220
|
+
"""The current 1-indexed position of the leaf during computation: 1-indexed as opposed to 0-indexed."""
|
|
221
|
+
leafConnectee: DatatypeLeavesTotal = DatatypeLeavesTotal(0) # noqa: RUF009
|
|
222
|
+
"""Target leaf for connection operations."""
|
|
223
|
+
|
|
224
|
+
dimensionsUnconstrained: DatatypeLeavesTotal = dataclasses.field(default=None, init=True) # pyright: ignore[reportAssignmentType, reportAttributeAccessIssue, reportUnknownMemberType]
|
|
225
|
+
"""Count of dimensions not subject to folding constraints."""
|
|
226
|
+
|
|
227
|
+
countDimensionsGapped: Array1DLeavesTotal = dataclasses.field(default=None, init=True, metadata={'dtype': Array1DLeavesTotal.__args__[1].__args__[0]}) # pyright: ignore[reportAssignmentType, reportAttributeAccessIssue, reportUnknownMemberType]
|
|
228
|
+
"""Array tracking computed number of dimensions with gaps."""
|
|
229
|
+
gapRangeStart: Array1DElephino = dataclasses.field(default=None, init=True, metadata={'dtype': Array1DElephino.__args__[1].__args__[0]}) # pyright: ignore[reportAssignmentType, reportAttributeAccessIssue, reportUnknownMemberType]
|
|
230
|
+
"""Array tracking computed starting positions of gap ranges."""
|
|
231
|
+
gapsWhere: Array1DLeavesTotal = dataclasses.field(default=None, init=True, metadata={'dtype': Array1DLeavesTotal.__args__[1].__args__[0]}) # pyright: ignore[reportAssignmentType, reportAttributeAccessIssue, reportUnknownMemberType]
|
|
232
|
+
"""Array indicating locations of gaps in the folding pattern."""
|
|
233
|
+
leafAbove: Array1DLeavesTotal = dataclasses.field(default=None, init=True, metadata={'dtype': Array1DLeavesTotal.__args__[1].__args__[0]}) # pyright: ignore[reportAssignmentType, reportAttributeAccessIssue, reportUnknownMemberType]
|
|
234
|
+
"""Array tracking the leaves above to the current leaf, `leaf1ndex`, during computation."""
|
|
235
|
+
leafBelow: Array1DLeavesTotal = dataclasses.field(default=None, init=True, metadata={'dtype': Array1DLeavesTotal.__args__[1].__args__[0]}) # pyright: ignore[reportAssignmentType, reportAttributeAccessIssue, reportUnknownMemberType]
|
|
236
|
+
"""Array tracking the leaves below to the current leaf, `leaf1ndex`, during computation."""
|
|
237
|
+
leafComparison: Array1DLeavesTotal = dataclasses.field(default=None, init=True, metadata={'dtype': Array1DLeavesTotal.__args__[1].__args__[0]}) # pyright: ignore[reportAssignmentType, reportAttributeAccessIssue, reportUnknownMemberType]
|
|
238
|
+
"""Array for finding symmetric folds."""
|
|
239
|
+
|
|
240
|
+
arrayGroupOfFolds: Array2DLeavesTotal = dataclasses.field(init=False, metadata={'dtype': Array2DLeavesTotal.__args__[1].__args__[0]}) # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue]
|
|
241
|
+
connectionGraph: Array3DLeavesTotal = dataclasses.field(init=False, metadata={'dtype': Array3DLeavesTotal.__args__[1].__args__[0]}) # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue]
|
|
242
|
+
"""Unchanging array representing connections between all leaves."""
|
|
243
|
+
dimensionsTotal: DatatypeLeavesTotal = dataclasses.field(init=False)
|
|
244
|
+
"""Unchanging total number of dimensions in the map."""
|
|
245
|
+
indicesArrayGroupOfFolds: Array2DLeavesTotal = dataclasses.field(init=False, metadata={'dtype': Array2DLeavesTotal.__args__[1].__args__[0]}) # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue]
|
|
246
|
+
leavesTotal: DatatypeLeavesTotal = dataclasses.field(init=False)
|
|
247
|
+
"""Unchanging total number of leaves in the map."""
|
|
248
|
+
|
|
249
|
+
def __post_init__(self) -> None:
|
|
250
|
+
"""Ensure all fields have a value.
|
|
251
|
+
|
|
252
|
+
Notes
|
|
253
|
+
-----
|
|
254
|
+
Arrays that are not explicitly provided (None) are automatically allocated with appropriate sizes based on the map
|
|
255
|
+
dimensions. `dimensionsTotal`, `leavesTotal`, and `connectionGraph` cannot be set: they are calculated.
|
|
256
|
+
|
|
257
|
+
"""
|
|
258
|
+
self.dimensionsTotal = DatatypeLeavesTotal(len(self.mapShape))
|
|
259
|
+
self.leavesTotal = DatatypeLeavesTotal(getLeavesTotal(self.mapShape))
|
|
260
|
+
|
|
261
|
+
leavesTotalAsInt = int(self.leavesTotal)
|
|
262
|
+
|
|
263
|
+
self.connectionGraph = getConnectionGraph(self.mapShape, leavesTotalAsInt, self.__dataclass_fields__['connectionGraph'].metadata['dtype'])
|
|
264
|
+
|
|
265
|
+
self.indicesArrayGroupOfFolds = (numpy.arange(leavesTotalAsInt + 1)[:, None] + numpy.arange(leavesTotalAsInt)[None, :]) % (leavesTotalAsInt + 1)
|
|
266
|
+
self.indicesArrayGroupOfFolds[..., leavesTotalAsInt // 2:None] = self.indicesArrayGroupOfFolds[..., leavesTotalAsInt - 1: leavesTotalAsInt - leavesTotalAsInt // 2 - 1: -1]
|
|
267
|
+
self.arrayGroupOfFolds = numpy.zeros_like(self.indicesArrayGroupOfFolds)
|
|
268
|
+
|
|
269
|
+
if self.dimensionsUnconstrained is None: self.dimensionsUnconstrained = DatatypeLeavesTotal(int(self.dimensionsTotal)) # pyright: ignore[reportUnnecessaryComparison] # noqa: E701
|
|
270
|
+
if self.gapsWhere is None: self.gapsWhere = makeDataContainer(leavesTotalAsInt * leavesTotalAsInt + 1, self.__dataclass_fields__['gapsWhere'].metadata['dtype']) # pyright: ignore[reportUnnecessaryComparison] # noqa: E701
|
|
271
|
+
if self.countDimensionsGapped is None: self.countDimensionsGapped = makeDataContainer(leavesTotalAsInt + 1, self.__dataclass_fields__['countDimensionsGapped'].metadata['dtype']) # pyright: ignore[reportUnnecessaryComparison] # noqa: E701
|
|
272
|
+
if self.gapRangeStart is None: self.gapRangeStart = makeDataContainer(leavesTotalAsInt + 1, self.__dataclass_fields__['gapRangeStart'].metadata['dtype']) # pyright: ignore[reportUnnecessaryComparison] # noqa: E701
|
|
273
|
+
if self.leafAbove is None: self.leafAbove = makeDataContainer(leavesTotalAsInt + 1, self.__dataclass_fields__['leafAbove'].metadata['dtype']) # pyright: ignore[reportUnnecessaryComparison] # noqa: E701
|
|
274
|
+
if self.leafBelow is None: self.leafBelow = makeDataContainer(leavesTotalAsInt + 1, self.__dataclass_fields__['leafBelow'].metadata['dtype']) # pyright: ignore[reportUnnecessaryComparison] # noqa: E701
|
|
157
275
|
if self.leafComparison is None: self.leafComparison = makeDataContainer(leavesTotalAsInt + 1, self.__dataclass_fields__['leafComparison'].metadata['dtype']) # pyright: ignore[reportUnnecessaryComparison] # noqa: E701
|
|
158
276
|
|
|
159
277
|
@dataclasses.dataclass
|
mapFolding/filesystemToolkit.py
CHANGED
|
@@ -56,12 +56,10 @@ def getFilenameFoldsTotal(mapShape: tuple[int, ...]) -> str:
|
|
|
56
56
|
return 'p' + 'x'.join(str(dimension) for dimension in sorted(mapShape)) + '.foldsTotal'
|
|
57
57
|
|
|
58
58
|
def getPathFilenameFoldsTotal(mapShape: tuple[int, ...], pathLikeWriteFoldsTotal: PathLike[str] | PurePath | None = None) -> Path:
|
|
59
|
-
"""Get a standardized
|
|
59
|
+
"""Get a standardized filename and create a configurable path to store the computed `foldsTotal` value.
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
This function resolves paths for storing computation results, handling different input types including directories,
|
|
64
|
-
absolute paths, or relative paths. It ensures that all parent directories exist in the resulting path.
|
|
61
|
+
To help reduce duplicate code and to increase predictability, this function creates a standardized filename, has a default but
|
|
62
|
+
configurable path, and creates the path.
|
|
65
63
|
|
|
66
64
|
Parameters
|
|
67
65
|
----------
|
|
@@ -78,10 +76,9 @@ def getPathFilenameFoldsTotal(mapShape: tuple[int, ...], pathLikeWriteFoldsTotal
|
|
|
78
76
|
Notes
|
|
79
77
|
-----
|
|
80
78
|
The function creates any necessary directories in the path if they don't exist.
|
|
81
|
-
|
|
82
79
|
"""
|
|
83
80
|
if pathLikeWriteFoldsTotal is None:
|
|
84
|
-
pathFilenameFoldsTotal = getPathRootJobDEFAULT() / getFilenameFoldsTotal(mapShape)
|
|
81
|
+
pathFilenameFoldsTotal: Path = getPathRootJobDEFAULT() / getFilenameFoldsTotal(mapShape)
|
|
85
82
|
else:
|
|
86
83
|
pathLikeSherpa = Path(pathLikeWriteFoldsTotal)
|
|
87
84
|
if pathLikeSherpa.is_dir():
|
|
@@ -237,28 +234,3 @@ def saveFoldsTotalFAILearly(pathFilename: PathLike[str] | PurePath) -> None:
|
|
|
237
234
|
if foldsTotalRead != foldsTotal:
|
|
238
235
|
message = f"I wrote a test file to `{pathFilename = }` with contents of `{str(foldsTotal) = }`, but I read `{foldsTotalRead = }` from the file. Python says the values are not equal. Fix that now, so your computation doesn't get corrupted later. And be pro-social."
|
|
239
236
|
raise FileNotFoundError(message)
|
|
240
|
-
|
|
241
|
-
def writeStringToHere(this: str, pathFilename: PathLike[str] | PurePath) -> None:
|
|
242
|
-
"""Write a string to a file, creating parent directories if needed.
|
|
243
|
-
|
|
244
|
-
(AI generated docstring)
|
|
245
|
-
|
|
246
|
-
This utility function provides a consistent interface for writing string content to files across the package. It
|
|
247
|
-
handles path creation and ensures proper string conversion.
|
|
248
|
-
|
|
249
|
-
Parameters
|
|
250
|
-
----------
|
|
251
|
-
this : str
|
|
252
|
-
The string content to write to the file.
|
|
253
|
-
pathFilename : PathLike[str] | PurePath
|
|
254
|
-
The target file path where the string should be written.
|
|
255
|
-
|
|
256
|
-
Notes
|
|
257
|
-
-----
|
|
258
|
-
This function creates all parent directories in the path if they don't exist, making it safe to use with newly
|
|
259
|
-
created directory structures.
|
|
260
|
-
|
|
261
|
-
"""
|
|
262
|
-
pathFilename = Path(pathFilename)
|
|
263
|
-
pathFilename.parent.mkdir(parents=True, exist_ok=True)
|
|
264
|
-
pathFilename.write_text(str(this))
|
mapFolding/oeis.py
CHANGED
|
@@ -306,12 +306,6 @@ def makeDictionaryFoldsTotalKnown() -> dict[tuple[int, ...], int]:
|
|
|
306
306
|
def getFoldsTotalKnown(mapShape: tuple[int, ...]) -> int:
|
|
307
307
|
"""Retrieve the known total number of distinct folding patterns for a given map shape.
|
|
308
308
|
|
|
309
|
-
(AI generated docstring)
|
|
310
|
-
|
|
311
|
-
This function provides rapid access to precalculated folding totals from OEIS sequences without
|
|
312
|
-
requiring computation. It serves as a validation reference for algorithm results and enables
|
|
313
|
-
quick lookup of known values across all implemented sequences.
|
|
314
|
-
|
|
315
309
|
Parameters
|
|
316
310
|
----------
|
|
317
311
|
mapShape : tuple[int, ...]
|
|
@@ -320,17 +314,16 @@ def getFoldsTotalKnown(mapShape: tuple[int, ...]) -> int:
|
|
|
320
314
|
Returns
|
|
321
315
|
-------
|
|
322
316
|
foldingsTotal : int
|
|
323
|
-
The known total number of distinct folding patterns for the given map shape,
|
|
324
|
-
|
|
317
|
+
The known total number of distinct folding patterns for the given map shape, or 0 if the map shape does not match any
|
|
318
|
+
known values in the OEIS sequences.
|
|
325
319
|
|
|
326
320
|
Notes
|
|
327
321
|
-----
|
|
328
|
-
|
|
329
|
-
OEIS data. Map shapes are matched exactly as provided without internal sorting or normalization.
|
|
322
|
+
Map shapes are matched exactly as provided without internal sorting or normalization.
|
|
330
323
|
|
|
331
324
|
"""
|
|
332
|
-
lookupFoldsTotal = makeDictionaryFoldsTotalKnown()
|
|
333
|
-
return lookupFoldsTotal.get(tuple(mapShape),
|
|
325
|
+
lookupFoldsTotal: dict[tuple[int, ...], int] = makeDictionaryFoldsTotalKnown()
|
|
326
|
+
return lookupFoldsTotal.get(tuple(mapShape), 0)
|
|
334
327
|
|
|
335
328
|
def _formatHelpText() -> str:
|
|
336
329
|
"""Format comprehensive help text for both command-line and interactive use.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# ruff: noqa: ANN001, T201, D103, D100, ANN201, ANN202
|
|
2
|
+
# pyright: standard
|
|
3
|
+
from fractions import Fraction
|
|
4
|
+
from functools import cache
|
|
5
|
+
from itertools import combinations
|
|
6
|
+
from math import factorial, gcd, prod
|
|
7
|
+
from sympy import divisors
|
|
8
|
+
from sympy.functions.combinatorial.numbers import mobius
|
|
9
|
+
from sympy.utilities.iterables import partitions
|
|
10
|
+
import time
|
|
11
|
+
|
|
12
|
+
# NOTE Because `b` and `c` are inside `A086345` instead of peers, the run time is increased by a factor of 6.
|
|
13
|
+
|
|
14
|
+
def A086345(n):
|
|
15
|
+
@cache
|
|
16
|
+
def b(n): return int(sum(Fraction(3**(sum(p[r]*p[s]*gcd(r, s) for r, s in combinations(p.keys(), 2))+sum((q-1>>1)*r+(q*r*(r-1)>>1) for q, r in p.items())), prod(q**r*factorial(r) for q, r in p.items())) for p in partitions(n))) # pyright: ignore[reportAttributeAccessIssue, reportOperatorIssue]
|
|
17
|
+
@cache
|
|
18
|
+
def c(n): return n*b(n)-sum(c(k)*b(n-k) for k in range(1, n))
|
|
19
|
+
return sum(mobius(d)*c(n//d) for d in divisors(n, generator=True))//n if n else 1 # Chai Wah Wu, Jul 15 2024
|
|
20
|
+
|
|
21
|
+
if __name__ == "__main__":
|
|
22
|
+
timeStart = time.perf_counter()
|
|
23
|
+
for n in range(51):
|
|
24
|
+
print(n, A086345(n))
|
|
25
|
+
print(time.perf_counter() - timeStart)
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"""buckets and signatures."""
|
|
2
|
+
bucketsTotalMaximumBy_boundary: dict[int, int] = {1:3, 2:12, 3:40, 4:125, 5:392, 6:1254, 7:4087, 8:13623, 9:46181, 10:159137, 11:555469, 12:1961369, 13:6991893, 14:25134208}
|
|
3
|
+
|
|
1
4
|
signatures: dict[str, dict[int, dict[int, int]]] = {'A000682': {2: {1: 1, 2: 3},
|
|
2
5
|
3: {1: 1, 2: 3, 3: 3},
|
|
3
6
|
4: {1: 1, 2: 3, 3: 4, 4: 4},
|
|
@@ -1,54 +1,19 @@
|
|
|
1
|
-
from astToolkit import extractFunctionDef,
|
|
1
|
+
from astToolkit import extractFunctionDef, Make # noqa: D100
|
|
2
2
|
from hunterMakesPy import raiseIfNone
|
|
3
|
-
from mapFolding.someAssemblyRequired import
|
|
4
|
-
|
|
5
|
-
identifierDataclassInstanceDEFAULT, logicalPathInfixDEFAULT)
|
|
3
|
+
from mapFolding.someAssemblyRequired import defaultA007822
|
|
4
|
+
from mapFolding.someAssemblyRequired.toolkitMakeModules import getModule
|
|
6
5
|
import ast
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
identifierCounting: str = identifierCountingDEFAULT
|
|
10
|
-
logicalPathInfixA007822: identifierDotAttribute = logicalPathInfixDEFAULT + '.A007822'
|
|
11
|
-
sourceCallableDispatcherA007822: str = identifierCallableSourceDispatcherDEFAULT
|
|
12
|
-
sourceCallableIdentifierA007822: str = identifierCallableSourceDEFAULT
|
|
7
|
+
FunctionDef_filterAsymmetricFolds: ast.FunctionDef = raiseIfNone(extractFunctionDef(getModule(logicalPathInfix='algorithms', identifierModule='symmetricFolds'), defaultA007822['function']['filterAsymmetricFolds']))
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ImaString = f"""
|
|
17
|
-
def {identifier_filterAsymmetricFolds}({identifierDataclass}: MapFoldingState) -> MapFoldingState:
|
|
18
|
-
{identifierDataclass}.indexLeaf = 0
|
|
19
|
-
leafConnectee = 0
|
|
20
|
-
while leafConnectee < {identifierDataclass}.leavesTotal + 1:
|
|
21
|
-
leafNumber = int({identifierDataclass}.leafBelow[{identifierDataclass}.indexLeaf])
|
|
22
|
-
{identifierDataclass}.leafComparison[leafConnectee] = (leafNumber - {identifierDataclass}.indexLeaf + {identifierDataclass}.leavesTotal) % {identifierDataclass}.leavesTotal
|
|
23
|
-
{identifierDataclass}.indexLeaf = leafNumber
|
|
24
|
-
leafConnectee += 1
|
|
25
|
-
|
|
26
|
-
indexInMiddle = {identifierDataclass}.leavesTotal // 2
|
|
27
|
-
{identifierDataclass}.indexMiniGap = 0
|
|
28
|
-
while {identifierDataclass}.indexMiniGap < {identifierDataclass}.leavesTotal + 1:
|
|
29
|
-
ImaSymmetricFold = True
|
|
30
|
-
leafConnectee = 0
|
|
31
|
-
while leafConnectee < indexInMiddle:
|
|
32
|
-
if {identifierDataclass}.leafComparison[({identifierDataclass}.indexMiniGap + leafConnectee) % ({identifierDataclass}.leavesTotal + 1)] != {identifierDataclass}.leafComparison[({identifierDataclass}.indexMiniGap + {identifierDataclass}.leavesTotal - 1 - leafConnectee) % ({identifierDataclass}.leavesTotal + 1)]:
|
|
33
|
-
ImaSymmetricFold = False
|
|
34
|
-
break
|
|
35
|
-
leafConnectee += 1
|
|
36
|
-
{identifierDataclass}.{identifierCounting} += ImaSymmetricFold
|
|
37
|
-
{identifierDataclass}.indexMiniGap += 1
|
|
38
|
-
|
|
39
|
-
return {identifierDataclass}
|
|
40
|
-
""" # noqa: E501
|
|
41
|
-
|
|
42
|
-
FunctionDef_filterAsymmetricFolds: ast.FunctionDef = raiseIfNone(extractFunctionDef(ast.parse(ImaString), identifier_filterAsymmetricFolds))
|
|
43
|
-
del ImaString
|
|
44
|
-
|
|
45
|
-
ImaString = f"{identifierDataclass} = {identifier_filterAsymmetricFolds}({identifierDataclass})"
|
|
9
|
+
ImaString: str = f"{defaultA007822['variable']['stateInstance']} = {defaultA007822['function']['filterAsymmetricFolds']}({defaultA007822['variable']['stateInstance']})"
|
|
46
10
|
A007822incrementCount = ast.parse(ImaString).body[0]
|
|
47
11
|
del ImaString
|
|
48
12
|
|
|
49
|
-
ImaString = f'{
|
|
50
|
-
A007822adjustFoldsTotal = ast.parse(ImaString).body[0]
|
|
13
|
+
ImaString = f'{defaultA007822['variable']['stateInstance']}.{defaultA007822['variable']['counting']} = ({defaultA007822['variable']['stateInstance']}.{defaultA007822['variable']['counting']} + 1) // 2'
|
|
14
|
+
A007822adjustFoldsTotal: ast.stmt = ast.parse(ImaString).body[0]
|
|
51
15
|
del ImaString
|
|
52
16
|
|
|
53
|
-
|
|
54
|
-
|
|
17
|
+
ExprCallFilterAsymmetricFolds_leafBelow: ast.Expr = Make.Expr(Make.Call(Make.Name(defaultA007822['function']['filterAsymmetricFolds']), listParameters=[Make.Name('leafBelow')]))
|
|
18
|
+
ExprCallFilterAsymmetricFoldsState: ast.Expr = Make.Expr(Make.Call(Make.Name(defaultA007822['function']['filterAsymmetricFolds']), listParameters=[Make.Name(defaultA007822['variable']['stateInstance'])]))
|
|
19
|
+
ExprCallFilterAsymmetricFoldsStateDot_leafBelow: ast.Expr = Make.Expr(Make.Call(Make.Name(defaultA007822['function']['filterAsymmetricFolds']), listParameters=[Make.Attribute(Make.Name(defaultA007822['variable']['stateInstance']), 'leafBelow')]))
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# NOTE The real module is generated from this incomplete module. Comments are not preserved.
|
|
2
|
+
# ruff: noqa: PLW0603
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
from mapFolding import DatatypeFoldsTotal
|
|
5
|
+
from mapFolding.dataBaskets import SymmetricFoldsState
|
|
6
|
+
from queue import Queue
|
|
7
|
+
from threading import Lock, Thread
|
|
8
|
+
|
|
9
|
+
listThreads: list[Thread] = []
|
|
10
|
+
queueFutures: Queue[SymmetricFoldsState] = Queue()
|
|
11
|
+
symmetricFoldsTotal: int = 0
|
|
12
|
+
LOCKsymmetricFoldsTotal = Lock()
|
|
13
|
+
# TODO There isn't a better way to do this?
|
|
14
|
+
STOPsignal = object()
|
|
15
|
+
|
|
16
|
+
def initializeConcurrencyManager(maxWorkers: int, symmetricFolds: int=0) -> None:
|
|
17
|
+
global listThreads, symmetricFoldsTotal, queueFutures
|
|
18
|
+
listThreads = []
|
|
19
|
+
queueFutures = Queue()
|
|
20
|
+
symmetricFoldsTotal = symmetricFolds
|
|
21
|
+
|
|
22
|
+
indexThread = 0
|
|
23
|
+
while indexThread < maxWorkers:
|
|
24
|
+
thread = Thread(target=_threadDoesSomething, name=f"thread{indexThread}", daemon=True)
|
|
25
|
+
thread.start()
|
|
26
|
+
listThreads.append(thread)
|
|
27
|
+
indexThread += 1
|
|
28
|
+
|
|
29
|
+
def _threadDoesSomething() -> None:
|
|
30
|
+
global symmetricFoldsTotal
|
|
31
|
+
while True:
|
|
32
|
+
state = queueFutures.get()
|
|
33
|
+
if state is STOPsignal:
|
|
34
|
+
break
|
|
35
|
+
state = _filterAsymmetricFolds(state)
|
|
36
|
+
with LOCKsymmetricFoldsTotal:
|
|
37
|
+
symmetricFoldsTotal += state.groupsOfFolds
|
|
38
|
+
|
|
39
|
+
def _filterAsymmetricFolds(state: SymmetricFoldsState) -> SymmetricFoldsState:
|
|
40
|
+
"""Add real function during generation; the signature is here to preview its interactions with the module."""
|
|
41
|
+
return state
|
|
42
|
+
|
|
43
|
+
def filterAsymmetricFolds(state: SymmetricFoldsState) -> None:
|
|
44
|
+
queueFutures.put_nowait(deepcopy(state))
|
|
45
|
+
|
|
46
|
+
def getSymmetricFoldsTotal() -> DatatypeFoldsTotal:
|
|
47
|
+
for _thread in listThreads:
|
|
48
|
+
queueFutures.put(STOPsignal) # pyright: ignore[reportArgumentType]
|
|
49
|
+
for thread in listThreads:
|
|
50
|
+
thread.join()
|
|
51
|
+
return symmetricFoldsTotal
|