mapFolding 0.15.3__py3-none-any.whl → 0.16.0__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.
Files changed (92) hide show
  1. mapFolding/__init__.py +22 -20
  2. mapFolding/_theSSOT.py +56 -62
  3. mapFolding/_theTypes.py +66 -4
  4. mapFolding/algorithms/__init__.py +1 -0
  5. mapFolding/{daoOfMapFolding.py → algorithms/daoOfMapFolding.py} +1 -2
  6. mapFolding/algorithms/getBucketsTotal.py +137 -0
  7. mapFolding/algorithms/matrixMeanders.py +519 -0
  8. mapFolding/algorithms/oeisIDbyFormula.py +347 -0
  9. mapFolding/algorithms/zCuzDocStoopidoeisIDbyFormula.py +84 -0
  10. mapFolding/basecamp.py +151 -14
  11. mapFolding/dataBaskets.py +74 -0
  12. mapFolding/oeis.py +43 -56
  13. mapFolding/reference/A000682facts.py +662 -0
  14. mapFolding/reference/A005316facts.py +62 -0
  15. mapFolding/reference/matrixMeandersAnalysis/__init__.py +1 -0
  16. mapFolding/reference/matrixMeandersAnalysis/evenEven.py +144 -0
  17. mapFolding/reference/matrixMeandersAnalysis/oddEven.py +54 -0
  18. mapFolding/{_oeisFormulas/matrixMeanders64.py → reference/meandersDumpingGround/matrixMeanders64retired.py} +37 -29
  19. mapFolding/someAssemblyRequired/A007822/A007822rawMaterials.py +55 -0
  20. mapFolding/someAssemblyRequired/A007822/__init__.py +0 -0
  21. mapFolding/someAssemblyRequired/A007822/makeA007822AsynchronousModules.py +185 -0
  22. mapFolding/someAssemblyRequired/A007822/makeA007822Modules.py +71 -0
  23. mapFolding/someAssemblyRequired/RecipeJob.py +2 -2
  24. mapFolding/someAssemblyRequired/__init__.py +9 -2
  25. mapFolding/someAssemblyRequired/_toolIfThis.py +4 -3
  26. mapFolding/someAssemblyRequired/_toolkitContainers.py +8 -8
  27. mapFolding/someAssemblyRequired/infoBooth.py +27 -30
  28. mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +1 -1
  29. mapFolding/someAssemblyRequired/makeJobTheorem2codon.py +5 -2
  30. mapFolding/someAssemblyRequired/makingModules_count.py +301 -0
  31. mapFolding/someAssemblyRequired/makingModules_doTheNeedful.py +120 -0
  32. mapFolding/someAssemblyRequired/mapFolding/__init__.py +0 -0
  33. mapFolding/someAssemblyRequired/mapFolding/makeMapFoldingModules.py +220 -0
  34. mapFolding/someAssemblyRequired/toolkitMakeModules.py +152 -0
  35. mapFolding/someAssemblyRequired/toolkitNumba.py +1 -1
  36. mapFolding/someAssemblyRequired/transformationTools.py +1 -0
  37. mapFolding/syntheticModules/A007822/__init__.py +1 -0
  38. mapFolding/syntheticModules/A007822/asynchronous.py +148 -0
  39. mapFolding/syntheticModules/A007822/asynchronousAnnex.py +68 -0
  40. mapFolding/syntheticModules/A007822/asynchronousTheorem2.py +53 -0
  41. mapFolding/syntheticModules/A007822/asynchronousTrimmed.py +47 -0
  42. mapFolding/syntheticModules/dataPackingA007822.py +1 -1
  43. mapFolding/tests/conftest.py +28 -9
  44. mapFolding/tests/test_computations.py +32 -10
  45. mapFolding/tests/test_oeis.py +2 -20
  46. mapFolding/trim_memory.py +62 -0
  47. mapFolding/zCuzDocStoopid/__init__.py +1 -0
  48. mapFolding/zCuzDocStoopid/makeDocstrings.py +63 -0
  49. {mapfolding-0.15.3.dist-info → mapfolding-0.16.0.dist-info}/METADATA +9 -2
  50. mapfolding-0.16.0.dist-info/RECORD +100 -0
  51. {mapfolding-0.15.3.dist-info → mapfolding-0.16.0.dist-info}/entry_points.txt +0 -1
  52. mapFolding/_oeisFormulas/A000136.py +0 -4
  53. mapFolding/_oeisFormulas/A000560.py +0 -4
  54. mapFolding/_oeisFormulas/A000682.py +0 -85
  55. mapFolding/_oeisFormulas/A001010.py +0 -19
  56. mapFolding/_oeisFormulas/A001011.py +0 -5
  57. mapFolding/_oeisFormulas/A005315.py +0 -4
  58. mapFolding/_oeisFormulas/A005316.py +0 -10
  59. mapFolding/_oeisFormulas/A223094.py +0 -7
  60. mapFolding/_oeisFormulas/A259702.py +0 -4
  61. mapFolding/_oeisFormulas/A301620.py +0 -6
  62. mapFolding/_oeisFormulas/Z0Z_aOFn.py +0 -34
  63. mapFolding/_oeisFormulas/Z0Z_notes.py +0 -16
  64. mapFolding/_oeisFormulas/Z0Z_oeisMeanders.py +0 -74
  65. mapFolding/_oeisFormulas/Z0Z_symmetry.py +0 -131
  66. mapFolding/_oeisFormulas/__init__.py +0 -1
  67. mapFolding/_oeisFormulas/matrixMeanders.py +0 -134
  68. mapFolding/_oeisFormulas/matrixMeandersAnnex.py +0 -84
  69. mapFolding/someAssemblyRequired/A007822rawMaterials.py +0 -46
  70. mapFolding/someAssemblyRequired/makeAllModules.py +0 -764
  71. mapfolding-0.15.3.dist-info/RECORD +0 -92
  72. /mapFolding/reference/{A005316JavaPort.py → meandersDumpingGround/A005316JavaPort.py} +0 -0
  73. /mapFolding/reference/{A005316imperative.py → meandersDumpingGround/A005316imperative.py} +0 -0
  74. /mapFolding/reference/{A005316intOptimized.py → meandersDumpingGround/A005316intOptimized.py} +0 -0
  75. /mapFolding/reference/{A005316optimized128bit.py → meandersDumpingGround/A005316optimized128bit.py} +0 -0
  76. /mapFolding/reference/{A005316primitiveOptimized.py → meandersDumpingGround/A005316primitiveOptimized.py} +0 -0
  77. /mapFolding/reference/{A005316redis.py → meandersDumpingGround/A005316redis.py} +0 -0
  78. /mapFolding/reference/{A005316write2disk.py → meandersDumpingGround/A005316write2disk.py} +0 -0
  79. /mapFolding/reference/{matrixMeandersBaseline.py → meandersDumpingGround/matrixMeandersBaseline.py} +0 -0
  80. /mapFolding/reference/{matrixMeandersBaselineAnnex.py → meandersDumpingGround/matrixMeandersBaselineAnnex.py} +0 -0
  81. /mapFolding/reference/{matrixMeandersBaselineV2.py → meandersDumpingGround/matrixMeandersBaselineV2.py} +0 -0
  82. /mapFolding/reference/{matrixMeandersSimpleQueue.py → meandersDumpingGround/matrixMeandersSimpleQueue.py} +0 -0
  83. /mapFolding/reference/{matrixMeandersSlicePop.py → meandersDumpingGround/matrixMeandersSlicePop.py} +0 -0
  84. /mapFolding/syntheticModules/{algorithmA007822.py → A007822/algorithm.py} +0 -0
  85. /mapFolding/syntheticModules/{algorithmA007822Numba.py → A007822/algorithmNumba.py} +0 -0
  86. /mapFolding/syntheticModules/{initializeStateA007822.py → A007822/initializeState.py} +0 -0
  87. /mapFolding/syntheticModules/{theorem2A007822.py → A007822/theorem2.py} +0 -0
  88. /mapFolding/syntheticModules/{theorem2A007822Numba.py → A007822/theorem2Numba.py} +0 -0
  89. /mapFolding/syntheticModules/{theorem2A007822Trimmed.py → A007822/theorem2Trimmed.py} +0 -0
  90. {mapfolding-0.15.3.dist-info → mapfolding-0.16.0.dist-info}/WHEEL +0 -0
  91. {mapfolding-0.15.3.dist-info → mapfolding-0.16.0.dist-info}/licenses/LICENSE +0 -0
  92. {mapfolding-0.15.3.dist-info → mapfolding-0.16.0.dist-info}/top_level.txt +0 -0
mapFolding/__init__.py CHANGED
@@ -15,17 +15,17 @@ The computational framework integrates type safety, persistent result storage,
15
15
  and mathematical validation through OEIS sequence integration.
16
16
 
17
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
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
23
 
24
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
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
29
 
30
30
  The package handles the full spectrum of map folding analysis, from simple
31
31
  educational examples to research-grade computations requiring multi-day processing
@@ -50,11 +50,14 @@ from mapFolding._theTypes import (
50
50
  DatatypeElephino as DatatypeElephino,
51
51
  DatatypeFoldsTotal as DatatypeFoldsTotal,
52
52
  DatatypeLeavesTotal as DatatypeLeavesTotal,
53
+ MetadataOEISidMapFolding as MetadataOEISidMapFolding,
54
+ MetadataOEISidMapFoldingManuallySet as MetadataOEISidMapFoldingManuallySet,
55
+ MetadataOEISidMeanders as MetadataOEISidMeanders,
56
+ MetadataOEISidMeandersManuallySet as MetadataOEISidMeandersManuallySet,
53
57
  NumPyElephino as NumPyElephino,
54
58
  NumPyFoldsTotal as NumPyFoldsTotal,
55
59
  NumPyIntegerType as NumPyIntegerType,
56
- NumPyLeavesTotal as NumPyLeavesTotal,
57
- )
60
+ NumPyLeavesTotal as NumPyLeavesTotal)
58
61
 
59
62
  from mapFolding._theSSOT import packageSettings as packageSettings
60
63
 
@@ -64,26 +67,25 @@ from mapFolding.beDRY import (
64
67
  getTaskDivisions as getTaskDivisions,
65
68
  makeDataContainer as makeDataContainer,
66
69
  setProcessorLimit as setProcessorLimit,
67
- validateListDimensions as validateListDimensions,
68
- )
70
+ validateListDimensions as validateListDimensions)
69
71
 
70
- from mapFolding.dataBaskets import MapFoldingState as MapFoldingState
72
+ from mapFolding.dataBaskets import (
73
+ MapFoldingState as MapFoldingState,
74
+ MatrixMeandersState as MatrixMeandersState)
71
75
 
72
76
  from mapFolding.filesystemToolkit import (
73
77
  getFilenameFoldsTotal as getFilenameFoldsTotal,
74
78
  getPathFilenameFoldsTotal as getPathFilenameFoldsTotal,
75
79
  getPathRootJobDEFAULT as getPathRootJobDEFAULT,
76
80
  saveFoldsTotal as saveFoldsTotal,
77
- saveFoldsTotalFAILearly as saveFoldsTotalFAILearly,
78
- )
81
+ saveFoldsTotalFAILearly as saveFoldsTotalFAILearly)
79
82
 
80
83
  from mapFolding.basecamp import countFolds as countFolds
81
84
 
82
85
  from mapFolding.oeis import (
83
- clearOEIScache as clearOEIScache,
86
+ dictionaryOEISMapFolding as dictionaryOEISMapFolding,
87
+ dictionaryOEISMeanders as dictionaryOEISMeanders,
84
88
  getFoldsTotalKnown as getFoldsTotalKnown,
85
89
  getOEISids as getOEISids,
86
90
  OEIS_for_n as OEIS_for_n,
87
- oeisIDfor_n as oeisIDfor_n,
88
- dictionaryOEIS as dictionaryOEIS,
89
- )
91
+ oeisIDfor_n as oeisIDfor_n)
mapFolding/_theSSOT.py CHANGED
@@ -1,80 +1,50 @@
1
- """Primary goal: access and configure package settings and metadata.
1
+ """Access and configure package settings and metadata."""
2
2
 
3
- Secondary goal: store hardcoded values until I implement a dynamic solution.
4
- """
5
-
6
- from collections.abc import Callable
7
3
  from hunterMakesPy import PackageSettings
4
+ from mapFolding._theTypes import MetadataOEISidMapFoldingManuallySet, MetadataOEISidMeandersManuallySet
8
5
  from pathlib import Path
9
- from typing import TypedDict
10
6
  import dataclasses
11
7
  import random
12
8
 
13
- # TODO eliminate hardcoding
14
- concurrencyPackageHARDCODED = 'multiprocessing'
15
- """Default package identifier for concurrent execution operations."""
16
-
17
- class MetadataOEISidManuallySet(TypedDict):
18
- """Settings that are best selected by a human instead of algorithmically."""
19
-
20
- getMapShape: Callable[[int], tuple[int, ...]]
21
- """Function to convert the OEIS sequence index, 'n', to its `mapShape` tuple."""
22
- valuesBenchmark: list[int]
23
- """List of index values, 'n', to use when benchmarking the algorithm performance."""
24
- valuesTestParallelization: list[int]
25
- """List of index values, 'n', to use when testing parallelization performance."""
26
- valuesTestValidation: list[int]
27
- """List of index values, 'n', to use when testing validation performance."""
28
-
29
9
  @dataclasses.dataclass
30
10
  class mapFoldingPackageSettings(PackageSettings):
31
- """Centralized configuration container for all package-wide settings.
32
-
33
- (AI generated docstring)
34
-
35
- This dataclass serves as the single source of truth for package configuration,
36
- providing both static and dynamically-resolved values needed throughout the
37
- package lifecycle. The metadata on each field indicates when that value is
38
- determined - either during packaging or at installation/runtime.
39
-
40
- The design supports different evaluation phases to optimize performance and
41
- reliability. Packaging-time values can be determined during package creation,
42
- while installing-time values require filesystem access or module introspection.
11
+ """Widely used settings that are especially useful for map folding algorithms.
43
12
 
44
13
  Attributes
45
14
  ----------
15
+ identifierPackageFALLBACK : str = ''
16
+ Fallback package identifier used only during initialization when automatic discovery fails.
17
+ pathPackage : Path = Path()
18
+ Absolute path to the installed package directory. Automatically resolved from `identifierPackage` if not provided.
19
+ identifierPackage : str = ''
20
+ Canonical name of the package. Automatically extracted from `pyproject.toml`.
46
21
  fileExtension : str = '.py'
47
- Standard file extension for Python modules in this package.
48
- packageName : str
49
- Canonical name of the package as defined in project configuration.
50
- pathPackage : Path
51
- Absolute filesystem path to the installed package directory.
52
- concurrencyPackage : str | None = None
53
- Package identifier for concurrent execution operations.
22
+ Default file extension.
54
23
 
24
+ cacheDays : int = 30
25
+ Number of days to retain cached OEIS data before refreshing from the online source.
26
+ concurrencyPackage : str = 'multiprocessing'
27
+ Package identifier for concurrent execution operations.
28
+ OEISidMapFoldingManuallySet : dict[str, MetadataOEISidMapFoldingManuallySet]
29
+ Settings that are best selected by a human instead of algorithmically.
30
+ OEISidMeandersManuallySet : dict[str, MetadataOEISidMeandersManuallySet]
31
+ Settings that are best selected by a human instead of algorithmically for meander sequences.
55
32
  """
56
33
 
57
- concurrencyPackage: str | None = None
58
- """
59
- Package identifier for concurrent execution operations.
60
-
61
- (AI generated docstring)
34
+ OEISidMapFoldingManuallySet: dict[str, MetadataOEISidMapFoldingManuallySet] = dataclasses.field(default_factory=dict[str, MetadataOEISidMapFoldingManuallySet])
35
+ """Settings that are best selected by a human instead of algorithmically."""
62
36
 
63
- Specifies which Python package should be used for parallel processing
64
- in computationally intensive operations. When None, the default concurrency
65
- package specified in the module constants is used. Accepted values include
66
- 'multiprocessing' for standard parallel processing and 'numba' for
67
- specialized numerical computations.
68
- """
37
+ OEISidMeandersManuallySet: dict[str, MetadataOEISidMeandersManuallySet] = dataclasses.field(default_factory=dict[str, MetadataOEISidMeandersManuallySet])
38
+ """Settings that are best selected by a human instead of algorithmically for meander sequences."""
69
39
 
70
- identifierPackageFALLBACK = "mapFolding"
71
- """Hardcoded package name used as fallback when dynamic resolution fails."""
40
+ cacheDays: int = 30
41
+ """Number of days to retain cached OEIS data before refreshing from the online source."""
72
42
 
73
- concurrencyPackage = concurrencyPackageHARDCODED
74
- """Active concurrency package configuration for the current session."""
43
+ concurrencyPackage: str = 'multiprocessing'
44
+ """Package identifier for concurrent execution operations."""
75
45
 
76
46
  # TODO I made a `TypedDict` before I knew how to make dataclasses and classes. Think about other data structures.
77
- settingsOEISManuallySelected: dict[str, MetadataOEISidManuallySet] = {
47
+ OEISidMapFoldingManuallySet: dict[str, MetadataOEISidMapFoldingManuallySet] = {
78
48
  'A000136': {
79
49
  'getMapShape': lambda n: (1, n),
80
50
  'valuesBenchmark': [14],
@@ -119,11 +89,35 @@ settingsOEISManuallySelected: dict[str, MetadataOEISidManuallySet] = {
119
89
  },
120
90
  }
121
91
 
122
- packageSettings = mapFoldingPackageSettings(
123
- identifierPackageFALLBACK=identifierPackageFALLBACK
124
- , concurrencyPackage=concurrencyPackage)
92
+ identifierPackageFALLBACK = "mapFolding"
93
+ """Manually entered package name used as fallback when dynamic resolution fails."""
94
+
95
+ packageSettings = mapFoldingPackageSettings(identifierPackageFALLBACK=identifierPackageFALLBACK, OEISidMapFoldingManuallySet=OEISidMapFoldingManuallySet)
125
96
  """Global package settings."""
126
- cacheDays = 30
127
- """Number of days to retain cached OEIS data before refreshing from the online source."""
97
+
98
+ # TODO integrate into packageSettings
128
99
  pathCache: Path = packageSettings.pathPackage / ".cache"
129
100
  """Local directory path for storing cached OEIS sequence data and metadata."""
101
+ OEISidMeandersManuallySet: dict[str, MetadataOEISidMeandersManuallySet] = {
102
+ 'A000560': {'valuesTestValidation': [*range(3, 12)]},
103
+ 'A000682': {'valuesTestValidation': [*range(3, 12)]},
104
+ 'A001010': {'valuesTestValidation': [*range(3, 11)]},
105
+ 'A001011': {'valuesTestValidation': [*range(3, 7)]},
106
+ 'A005315': {'valuesTestValidation': [*range(3, 9)]},
107
+ 'A005316': {'valuesTestValidation': [*range(3, 13)]},
108
+ 'A060206': {'valuesTestValidation': [*range(3, 9)]},
109
+ 'A077460': {'valuesTestValidation': [*range(3, 8)]},
110
+ 'A078591': {'valuesTestValidation': [*range(3, 10)]},
111
+ 'A178961': {'valuesTestValidation': [*range(3, 11)]},
112
+ 'A223094': {'valuesTestValidation': [*range(3, 11)]},
113
+ 'A259702': {'valuesTestValidation': [*range(3, 13)]},
114
+ 'A301620': {'valuesTestValidation': [*range(3, 11)]},
115
+ }
116
+
117
+ # Recreate packageSettings with meanders settings included
118
+ packageSettings = mapFoldingPackageSettings(
119
+ identifierPackageFALLBACK=identifierPackageFALLBACK,
120
+ OEISidMapFoldingManuallySet=OEISidMapFoldingManuallySet,
121
+ OEISidMeandersManuallySet=OEISidMeandersManuallySet,
122
+ )
123
+ """Global package settings."""
mapFolding/_theTypes.py CHANGED
@@ -1,7 +1,8 @@
1
1
  """Types for defensive coding and for computation optimization."""
2
2
 
3
+ from collections.abc import Callable
3
4
  from numpy import dtype, int_ as numpy_int, integer, ndarray, uint64 as numpy_uint64
4
- from typing import Any, TypeAlias, TypeVar
5
+ from typing import Any, TypeAlias, TypedDict, TypeVar
5
6
 
6
7
  NumPyIntegerType = TypeVar('NumPyIntegerType', bound=integer[Any], covariant=True)
7
8
  """Any NumPy integer type, which is usually between 8-bit signed and 64-bit unsigned."""
@@ -19,9 +20,9 @@ Note well
19
20
  ---------
20
21
  Colossal values are found with the cross humpy inequality:
21
22
 
22
- ⎡ el ⎤ ⎡ ⎤
23
- ⎢ eph ⎥ X ⎢ rhi ⎥ <= elephino
24
- ⎣ ant ⎦ ⎣ no ⎦
23
+ ⎡ el ⎤ ⎡ ⎤
24
+ ⎢ eph ⎥ X ⎢ rhi ⎥ <= elephino
25
+ ⎣ ant ⎦ ⎣ no ⎦
25
26
 
26
27
  """
27
28
 
@@ -50,3 +51,64 @@ Array1DElephino: TypeAlias = ndarray[tuple[int], dtype[NumPyElephino]] # noqa:
50
51
 
51
52
  Array1DFoldsTotal: TypeAlias = ndarray[tuple[int], dtype[NumPyFoldsTotal]] # noqa: UP040 The TypeAlias may be used to construct ("cast") a value to the type. And the identifier may be changed to a different type.
52
53
  """A `numpy.ndarray` with one axis and elements of type `NumPyFoldsTotal`."""
54
+
55
+ class MetadataOEISidMapFoldingManuallySet(TypedDict):
56
+ """Settings that are best selected by a human instead of algorithmically."""
57
+
58
+ getMapShape: Callable[[int], tuple[int, ...]]
59
+ """Function to convert the OEIS sequence index, 'n', to its `mapShape` tuple."""
60
+ valuesBenchmark: list[int]
61
+ """List of index values, 'n', to use when benchmarking the algorithm performance."""
62
+ valuesTestParallelization: list[int]
63
+ """List of index values, 'n', to use when testing parallelization performance."""
64
+ valuesTestValidation: list[int]
65
+ """List of index values, 'n', to use when testing validation performance."""
66
+
67
+ class MetadataOEISidMapFolding(TypedDict):
68
+ """Settings for an implemented OEIS sequence."""
69
+
70
+ description: str
71
+ """The OEIS.org description of the integer sequence."""
72
+ getMapShape: Callable[[int], tuple[int, ...]]
73
+ """Function to convert the OEIS sequence index, 'n', to its `mapShape` tuple."""
74
+ offset: int
75
+ """The starting index, 'n', of the sequence, typically 0 or 1."""
76
+ valuesBenchmark: list[int]
77
+ """List of index values, 'n', to use when benchmarking the algorithm performance."""
78
+ valuesKnown: dict[int, int]
79
+ """Dictionary of sequence indices, 'n', to their known values, `foldsTotal`."""
80
+ valuesTestParallelization: list[int]
81
+ """List of index values, 'n', to use when testing parallelization performance."""
82
+ valuesTestValidation: list[int]
83
+ """List of index values, 'n', to use when testing validation performance."""
84
+ valueUnknown: int
85
+ """The smallest value of 'n' for for which `foldsTotal` is unknown."""
86
+
87
+ # ruff: noqa: ERA001
88
+ class MetadataOEISidMeandersManuallySet(TypedDict):
89
+ """Settings that are best selected by a human instead of algorithmically."""
90
+
91
+ # valuesBenchmark: list[int]
92
+ """List of index values, 'n', to use when benchmarking the algorithm performance."""
93
+ # valuesTestParallelization: list[int]
94
+ """List of index values, 'n', to use when testing parallelization performance."""
95
+ valuesTestValidation: list[int]
96
+ """List of index values, 'n', to use when testing validation performance."""
97
+
98
+ class MetadataOEISidMeanders(TypedDict):
99
+ """Settings for an implemented OEIS sequence."""
100
+
101
+ description: str
102
+ """The OEIS.org description of the integer sequence."""
103
+ offset: int
104
+ """The starting index, 'n', of the sequence, typically 0 or 1."""
105
+ # valuesBenchmark: list[int]
106
+ """List of index values, 'n', to use when benchmarking the algorithm performance."""
107
+ valuesKnown: dict[int, int]
108
+ """Dictionary of sequence indices, 'n', to their known values, `foldsTotal`."""
109
+ # valuesTestParallelization: list[int]
110
+ """List of index values, 'n', to use when testing parallelization performance."""
111
+ valuesTestValidation: list[int]
112
+ """List of index values, 'n', to use when testing validation performance."""
113
+ valueUnknown: int
114
+ """The smallest value of 'n' for for which `foldsTotal` is unknown."""
@@ -0,0 +1 @@
1
+ """Hand-made algorithms."""
@@ -1,4 +1,3 @@
1
- # ruff: noqa: D100 D103
2
1
  from mapFolding.dataBaskets import MapFoldingState
3
2
 
4
3
  def activeLeafGreaterThan0(state: MapFoldingState) -> bool:
@@ -140,4 +139,4 @@ def count(state: MapFoldingState) -> MapFoldingState:
140
139
 
141
140
  def doTheNeedful(state: MapFoldingState) -> MapFoldingState:
142
141
  state = count(state)
143
- return state # noqa: RET504
142
+ return state
@@ -0,0 +1,137 @@
1
+ """Buckets."""
2
+ from mapFolding import MatrixMeandersState
3
+ from mapFolding.reference.A005316facts import bucketsIf_k_EVEN_by_nLess_k, bucketsIf_k_ODD_by_nLess_k
4
+ from math import exp, log
5
+ from typing import NamedTuple
6
+ import math
7
+
8
+ class ImaKey(NamedTuple):
9
+ """keys for dictionaries."""
10
+
11
+ oeisID: str
12
+ kIsOdd: bool
13
+ nLess_kIsOdd: bool
14
+
15
+ def getBucketsTotal(state: MatrixMeandersState, safetyMultiplicand: float = 1.2) -> int:
16
+ """Estimate the total number of non-unique curveLocations that will be computed from the existing curveLocations.
17
+
18
+ Notes
19
+ -----
20
+ Subexponential bucketsTotal unified estimator parameters (derived in reference notebook).
21
+
22
+ The model is: log(buckets) = intercept + bN*log(n) + bK*log(k) + bD*log(n-k) + g_r*(k/n) + g_r2*(k/n)^2 + g_s*((n-k)/n) + offset(subseries)
23
+ Subseries key: f"{oeisID}_kOdd={int(kIsOdd)}_dOdd={int(nLess_kIsOdd)}" with a reference subseries offset of zero.
24
+ These coefficients intentionally remain in-source (SSOT) to avoid runtime JSON parsing overhead and to support reproducibility.
25
+ """
26
+ dictionaryExponentialCoefficients: dict[ImaKey, float] = {
27
+ (ImaKey(oeisID='', kIsOdd=False, nLess_kIsOdd=True)): 0.834,
28
+ (ImaKey(oeisID='', kIsOdd=False, nLess_kIsOdd=False)): 1.5803,
29
+ (ImaKey(oeisID='', kIsOdd=True, nLess_kIsOdd=True)): 1.556,
30
+ (ImaKey(oeisID='', kIsOdd=True, nLess_kIsOdd=False)): 1.8047,
31
+ }
32
+
33
+ logarithmicOffsets: dict[ImaKey, float] ={
34
+ (ImaKey('A000682', kIsOdd=False, nLess_kIsOdd=False)): 0.0,
35
+ (ImaKey('A000682', kIsOdd=False, nLess_kIsOdd=True)): -0.07302547148212568,
36
+ (ImaKey('A000682', kIsOdd=True, nLess_kIsOdd=False)): -0.00595307513938792,
37
+ (ImaKey('A000682', kIsOdd=True, nLess_kIsOdd=True)): -0.012201222865243722,
38
+ (ImaKey('A005316', kIsOdd=False, nLess_kIsOdd=False)): -0.6392728422078733,
39
+ (ImaKey('A005316', kIsOdd=False, nLess_kIsOdd=True)): -0.6904925299923548,
40
+ (ImaKey('A005316', kIsOdd=True, nLess_kIsOdd=False)): 0.0,
41
+ (ImaKey('A005316', kIsOdd=True, nLess_kIsOdd=True)): 0.0,
42
+ }
43
+
44
+ logarithmicParameters: dict[str, float] = {
45
+ 'intercept': -166.1750299793178,
46
+ 'log(n)': 1259.0051001675547,
47
+ 'log(k)': -396.4306071056408,
48
+ 'log(nLess_k)': -854.3309503739766,
49
+ 'k/n': 716.530410654819,
50
+ '(k/n)^2': -2527.035113444166,
51
+ 'normalized k': -882.7054406339189,
52
+ }
53
+
54
+ bucketsTotalMaximumBy_kOfMatrix: 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}
55
+
56
+ xCommon = 1.57
57
+
58
+ nLess_k: int = state.n - state.kOfMatrix
59
+ kIsOdd: bool = bool(state.kOfMatrix & 1)
60
+ nLess_kIsOdd: bool = bool(nLess_k & 1)
61
+ kIsEven: bool = not kIsOdd
62
+ bucketsTotal: int = -8
63
+
64
+ """NOTE temporary notes
65
+ I have a fault in my thinking. bucketsTotal increases as k decreases until ~0.4k, then bucketsTotal decreases rapidly to 1. I
66
+ have ignored the decreasing side. In the formulas for estimation, I didn't differentiate between increasing and decreasing.
67
+ So, I probably need to refine the formulas. I guess I need to add checks to the if/else monster, too.
68
+
69
+ While buckets is increasing:
70
+ 3 types of estimates:
71
+ 1. Exponential growth.
72
+ 2. Logarithmic growth.
73
+ 3. Hard ceiling.
74
+ While buckets is decreasing:
75
+ 1. Hard ceiling, same as increasing side.
76
+ 2. ???
77
+ 3. buckets = 1.
78
+
79
+ The formula for exponential growth _never_ underestimates. I haven't measured by how much it overestimates.
80
+
81
+ """
82
+
83
+ bucketsTotalAtMaximum: bool = state.kOfMatrix <= ((state.n - 1 - (state.kOfMatrix % 2)) // 3)
84
+ bucketsTotalGrowsExponentially: bool = state.kOfMatrix > nLess_k
85
+ bucketsTotalGrowsLogarithmically: bool = state.kOfMatrix > ((state.n - (state.n % 3)) // 3)
86
+
87
+ if bucketsTotalAtMaximum:
88
+ if state.kOfMatrix in bucketsTotalMaximumBy_kOfMatrix:
89
+ bucketsTotal = bucketsTotalMaximumBy_kOfMatrix[state.kOfMatrix]
90
+ else:
91
+ c = 0.95037
92
+ r = 3.3591258254
93
+ if kIsOdd:
94
+ c = 0.92444
95
+ r = 3.35776
96
+ bucketsTotal = int(c * r**state.kOfMatrix * safetyMultiplicand)
97
+
98
+ elif bucketsTotalGrowsExponentially:
99
+ if (state.oeisID == 'A005316') and kIsOdd and (nLess_k in bucketsIf_k_ODD_by_nLess_k):
100
+ # If I already know bucketsTotal.
101
+ bucketsTotal = bucketsIf_k_ODD_by_nLess_k[nLess_k]
102
+ elif (state.oeisID == 'A005316') and kIsEven and (nLess_k in bucketsIf_k_EVEN_by_nLess_k):
103
+ # If I already know bucketsTotal.
104
+ bucketsTotal = bucketsIf_k_EVEN_by_nLess_k[nLess_k]
105
+ else: # I estimate bucketsTotal during exponential growth.
106
+ xInstant: int = math.ceil(nLess_k / 2)
107
+ A000682adjustStartingCurveLocations: float = 0.25
108
+ startingConditionsCoefficient: float = dictionaryExponentialCoefficients[ImaKey('', kIsOdd, nLess_kIsOdd)]
109
+ if kIsOdd and nLess_kIsOdd:
110
+ A000682adjustStartingCurveLocations = 0.0
111
+ if state.oeisID == 'A000682': # NOTE Net effect is between `*= n` and `*= n * 2.2` if n=46.
112
+ startingConditionsCoefficient *= state.n * (((state.n // 2) + 2) ** A000682adjustStartingCurveLocations)
113
+ bucketsTotal = int(startingConditionsCoefficient * math.exp(xCommon * xInstant))
114
+
115
+ elif state.kOfMatrix <= max(bucketsTotalMaximumBy_kOfMatrix.keys()):
116
+ # If `kOfMatrix` is low, use maximum bucketsTotal. 1. Can't underestimate. 2. Skip computation that can underestimate.
117
+ # 3. The potential difference in memory use is relatively small.
118
+ bucketsTotal = bucketsTotalMaximumBy_kOfMatrix[state.kOfMatrix]
119
+
120
+ elif bucketsTotalGrowsLogarithmically:
121
+ xPower: float = (0
122
+ + logarithmicParameters['intercept']
123
+ + logarithmicParameters['log(n)'] * log(state.n)
124
+ + logarithmicParameters['log(k)'] * log(state.kOfMatrix)
125
+ + logarithmicParameters['log(nLess_k)'] * log(nLess_k)
126
+ + logarithmicParameters['k/n'] * (state.kOfMatrix / state.n)
127
+ + logarithmicParameters['(k/n)^2'] * (state.kOfMatrix / state.n)**2
128
+ + logarithmicParameters['normalized k'] * nLess_k / state.n
129
+ + logarithmicOffsets[ImaKey(state.oeisID, kIsOdd, nLess_kIsOdd)]
130
+ )
131
+
132
+ bucketsTotal = int(exp(xPower * safetyMultiplicand))
133
+
134
+ else:
135
+ message = "I shouldn't be here."
136
+ raise SystemError(message)
137
+ return bucketsTotal