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
@@ -0,0 +1,347 @@
1
+ """Compute a(n) for an OEIS ID by computing other OEIS IDs.
2
+
3
+ TODO Implement A178961 for unknown values of A001010
4
+ TODO A223094 For n >= 3: a(n) = n! - Sum_{k=3..n-1} (a(k)*n!/k!) - A000682(n+1). - _Roger Ford_, Aug 24 2024
5
+ TODO A301620 a(n) = Sum_{k=3..floor((n+3)/2)} (A259689(n+1,k)*(k-2)). - _Roger Ford_, Dec 10 2018
6
+ """
7
+ from functools import cache
8
+ from mapFolding import countFolds, dictionaryOEISMeanders
9
+ from mapFolding.basecamp import A000682, A005316
10
+
11
+ @cache
12
+ def A000136(n: int) -> int:
13
+ """
14
+ Compute A000136(n) as a function of A000682.
15
+
16
+ *The On-Line Encyclopedia of Integer Sequences* (OEIS) description of A000136 is: "Number of ways of folding a strip of n labeled stamps."
17
+
18
+ The domain of A000136 starts at 1, therefore for values of `n` < 1, a(n) is undefined. The smallest value of n for which a(n)
19
+ has not yet been computed is 46.
20
+
21
+ Parameters
22
+ ----------
23
+ n : int
24
+ Index (n-dex) for a(n) in the sequence of values. "n" (lower case) and "a(n)" are conventions in mathematics.
25
+
26
+ Returns
27
+ -------
28
+ a(n) : int
29
+ Number of ways of folding a strip of n labeled stamps.
30
+
31
+ Would You Like to Know More?
32
+ ----------------------------
33
+ OEIS : webpage
34
+ https://oeis.org/A000136
35
+ """
36
+ return n * A000682(n)
37
+
38
+ def A000560(n: int) -> int:
39
+ """
40
+ Compute A000560(n) as a function of A000682.
41
+
42
+ *The On-Line Encyclopedia of Integer Sequences* (OEIS) description of A000560 is: "Number of ways of folding a strip of n labeled stamps."
43
+
44
+ The domain of A000560 starts at 2, therefore for values of `n` < 2, a(n) is undefined. The smallest value of n for which a(n)
45
+ has not yet been computed is 45.
46
+
47
+ Parameters
48
+ ----------
49
+ n : int
50
+ Index (n-dex) for a(n) in the sequence of values. "n" (lower case) and "a(n)" are conventions in mathematics.
51
+
52
+ Returns
53
+ -------
54
+ a(n) : int
55
+ Number of ways of folding a strip of n labeled stamps.
56
+
57
+ Would You Like to Know More?
58
+ ----------------------------
59
+ OEIS : webpage
60
+ https://oeis.org/A000560
61
+ """
62
+ return A000682(n + 1) // 2
63
+
64
+ def A001010(n: int) -> int:
65
+ """
66
+ Compute A001010(n) as a function of A000682 or A007822.
67
+
68
+ *The On-Line Encyclopedia of Integer Sequences* (OEIS) description of A001010 is: "Number of symmetric foldings of a strip of n stamps."
69
+
70
+ The domain of A001010 starts at 1, therefore for values of `n` < 1, a(n) is undefined. The smallest value of n for which a(n)
71
+ has not yet been computed is 53.
72
+
73
+ Parameters
74
+ ----------
75
+ n : int
76
+ Index (n-dex) for a(n) in the sequence of values. "n" (lower case) and "a(n)" are conventions in mathematics.
77
+
78
+ Returns
79
+ -------
80
+ a(n) : int
81
+ Number of symmetric foldings of a strip of n stamps.
82
+
83
+ Would You Like to Know More?
84
+ ----------------------------
85
+ OEIS : webpage
86
+ https://oeis.org/A001010
87
+ """
88
+ if n == 1:
89
+ foldsTotal = 1
90
+ elif n & 1:
91
+ foldsTotal = 2 * countFolds(oeisID='A007822', oeis_n=(n - 1) // 2 + 1, flow='theorem2Numba')
92
+ else:
93
+ foldsTotal = 2 * A000682(n // 2 + 1)
94
+ return foldsTotal
95
+
96
+ def A001011(n: int) -> int:
97
+ """
98
+ Compute A001011(n) as a function of A000136 and A001010.
99
+
100
+ *The On-Line Encyclopedia of Integer Sequences* (OEIS) description of A001011 is: "Number of ways to fold a strip of n blank stamps."
101
+
102
+ The domain of A001011 starts at 1, therefore for values of `n` < 1, a(n) is undefined. The smallest value of n for which a(n)
103
+ has not yet been computed is 46.
104
+
105
+ Parameters
106
+ ----------
107
+ n : int
108
+ Index (n-dex) for a(n) in the sequence of values. "n" (lower case) and "a(n)" are conventions in mathematics.
109
+
110
+ Returns
111
+ -------
112
+ a(n) : int
113
+ Number of ways to fold a strip of n blank stamps.
114
+
115
+ Would You Like to Know More?
116
+ ----------------------------
117
+ OEIS : webpage
118
+ https://oeis.org/A001011
119
+ """
120
+ if n == 0:
121
+ foldsTotal = 1
122
+ else:
123
+ foldsTotal = (A001010(n) + A000136(n)) // 4
124
+ return foldsTotal
125
+
126
+ @cache
127
+ def A005315(n: int) -> int:
128
+ """
129
+ Compute A005315(n) as a function of A005316.
130
+
131
+ *The On-Line Encyclopedia of Integer Sequences* (OEIS) description of A005315 is: "Closed meandric numbers (or meanders): number of ways a loop can cross a road 2n times."
132
+
133
+ The domain of A005315 starts at 0, therefore for values of `n` < 0, a(n) is undefined. The smallest value of n for which a(n)
134
+ has not yet been computed is 29.
135
+
136
+ Parameters
137
+ ----------
138
+ n : int
139
+ Index (n-dex) for a(n) in the sequence of values. "n" (lower case) and "a(n)" are conventions in mathematics.
140
+
141
+ Returns
142
+ -------
143
+ a(n) : int
144
+ Closed meandric numbers (or meanders): number of ways a loop can cross a road 2n times.
145
+
146
+ Would You Like to Know More?
147
+ ----------------------------
148
+ OEIS : webpage
149
+ https://oeis.org/A005315
150
+ """
151
+ if n == 1:
152
+ foldsTotal = 1
153
+ else:
154
+ foldsTotal = A005316(2 * n - 1)
155
+ return foldsTotal
156
+
157
+ def A060206(n: int) -> int:
158
+ """
159
+ Compute A060206(n) as a function of A000682.
160
+
161
+ *The On-Line Encyclopedia of Integer Sequences* (OEIS) description of A060206 is: "Number of rotationally symmetric closed meanders of length 4n+2."
162
+
163
+ The domain of A060206 starts at 0, therefore for values of `n` < 0, a(n) is undefined. The smallest value of n for which a(n)
164
+ has not yet been computed is 21.
165
+
166
+ Parameters
167
+ ----------
168
+ n : int
169
+ Index (n-dex) for a(n) in the sequence of values. "n" (lower case) and "a(n)" are conventions in mathematics.
170
+
171
+ Returns
172
+ -------
173
+ a(n) : int
174
+ Number of rotationally symmetric closed meanders of length 4n+2.
175
+
176
+ Would You Like to Know More?
177
+ ----------------------------
178
+ OEIS : webpage
179
+ https://oeis.org/A060206
180
+ """
181
+ return A000682(2 * n + 1)
182
+
183
+ def A077460(n: int) -> int:
184
+ """
185
+ Compute A077460(n) as a function of A005315, A005316, and A060206.
186
+
187
+ *The On-Line Encyclopedia of Integer Sequences* (OEIS) description of A077460 is: "Number of nonisomorphic ways a loop can cross a road (running East-West) 2n times."
188
+
189
+ The domain of A077460 starts at 0, therefore for values of `n` < 0, a(n) is undefined. The smallest value of n for which a(n)
190
+ has not yet been computed is 21.
191
+
192
+ Parameters
193
+ ----------
194
+ n : int
195
+ Index (n-dex) for a(n) in the sequence of values. "n" (lower case) and "a(n)" are conventions in mathematics.
196
+
197
+ Returns
198
+ -------
199
+ a(n) : int
200
+ Number of nonisomorphic ways a loop can cross a road (running East-West) 2n times.
201
+
202
+ Would You Like to Know More?
203
+ ----------------------------
204
+ OEIS : webpage
205
+ https://oeis.org/A077460
206
+ """
207
+ if n in {0, 1}:
208
+ foldsTotal = 1
209
+ elif n & 1:
210
+ foldsTotal = (A005315(n) + A005316(n) + A060206((n - 1) // 2)) // 4
211
+ else:
212
+ foldsTotal = (A005315(n) + 2 * A005316(n)) // 4
213
+ return foldsTotal
214
+
215
+ def A078591(n: int) -> int:
216
+ """
217
+ Compute A078591(n) as a function of A005315.
218
+
219
+ *The On-Line Encyclopedia of Integer Sequences* (OEIS) description of A078591 is: "Number of nonisomorphic ways a loop can cross a road (running East-West) 2n times."
220
+
221
+ The domain of A078591 starts at 0, therefore for values of `n` < 0, a(n) is undefined. The smallest value of n for which a(n)
222
+ has not yet been computed is 29.
223
+
224
+ Parameters
225
+ ----------
226
+ n : int
227
+ Index (n-dex) for a(n) in the sequence of values. "n" (lower case) and "a(n)" are conventions in mathematics.
228
+
229
+ Returns
230
+ -------
231
+ a(n) : int
232
+ Number of nonisomorphic ways a loop can cross a road (running East-West) 2n times.
233
+
234
+ Would You Like to Know More?
235
+ ----------------------------
236
+ OEIS : webpage
237
+ https://oeis.org/A078591
238
+ """
239
+ return A005315(n) // 2
240
+
241
+ def A178961(n: int) -> int:
242
+ """
243
+ Compute A178961(n) as a function of A001010.
244
+
245
+ *The On-Line Encyclopedia of Integer Sequences* (OEIS) description of A178961 is: "Partial sums of A001010."
246
+
247
+ The domain of A178961 starts at 1, therefore for values of `n` < 1, a(n) is undefined. The smallest value of n for which a(n)
248
+ has not yet been computed is 53.
249
+
250
+ Parameters
251
+ ----------
252
+ n : int
253
+ Index (n-dex) for a(n) in the sequence of values. "n" (lower case) and "a(n)" are conventions in mathematics.
254
+
255
+ Returns
256
+ -------
257
+ a(n) : int
258
+ Partial sums of A001010.
259
+
260
+ Would You Like to Know More?
261
+ ----------------------------
262
+ OEIS : webpage
263
+ https://oeis.org/A178961
264
+ """
265
+ A001010valuesKnown: dict[int, int] = dictionaryOEISMeanders['A001010']['valuesKnown']
266
+ foldsTotal: int = 0
267
+ for n下i in range(1, n + 1):
268
+ foldsTotal += A001010valuesKnown[n下i]
269
+ return foldsTotal
270
+
271
+ def A223094(n: int) -> int:
272
+ """
273
+ Compute A223094(n) as a function of A000136 and A000682.
274
+
275
+ *The On-Line Encyclopedia of Integer Sequences* (OEIS) description of A223094 is: "Number of foldings of n labeled stamps in which leaf n is inwards."
276
+
277
+ The domain of A223094 starts at 1, therefore for values of `n` < 1, a(n) is undefined. The smallest value of n for which a(n)
278
+ has not yet been computed is 44.
279
+
280
+ Parameters
281
+ ----------
282
+ n : int
283
+ Index (n-dex) for a(n) in the sequence of values. "n" (lower case) and "a(n)" are conventions in mathematics.
284
+
285
+ Returns
286
+ -------
287
+ a(n) : int
288
+ Number of foldings of n labeled stamps in which leaf n is inwards.
289
+
290
+ Would You Like to Know More?
291
+ ----------------------------
292
+ OEIS : webpage
293
+ https://oeis.org/A223094
294
+ """
295
+ return A000136(n) - A000682(n + 1)
296
+
297
+ def A259702(n: int) -> int:
298
+ """
299
+ Compute A259702(n) as a function of A000682.
300
+
301
+ *The On-Line Encyclopedia of Integer Sequences* (OEIS) description of A259702 is: "Row sums of A259701 except first column."
302
+
303
+ The domain of A259702 starts at 2, therefore for values of `n` < 2, a(n) is undefined. The smallest value of n for which a(n)
304
+ has not yet been computed is 33.
305
+
306
+ Parameters
307
+ ----------
308
+ n : int
309
+ Index (n-dex) for a(n) in the sequence of values. "n" (lower case) and "a(n)" are conventions in mathematics.
310
+
311
+ Returns
312
+ -------
313
+ a(n) : int
314
+ Row sums of A259701 except first column.
315
+
316
+ Would You Like to Know More?
317
+ ----------------------------
318
+ OEIS : webpage
319
+ https://oeis.org/A259702
320
+ """
321
+ return A000682(n) // 2 - A000682(n - 1)
322
+
323
+ def A301620(n: int) -> int:
324
+ """
325
+ Compute A301620(n) as a function of A000682.
326
+
327
+ *The On-Line Encyclopedia of Integer Sequences* (OEIS) description of A301620 is: "a(n) is the total number of top arches with exactly one covering arch for semi-meanders with n top arches."
328
+
329
+ The domain of A301620 starts at 1, therefore for values of `n` < 1, a(n) is undefined. The smallest value of n for which a(n)
330
+ has not yet been computed is 44.
331
+
332
+ Parameters
333
+ ----------
334
+ n : int
335
+ Index (n-dex) for a(n) in the sequence of values. "n" (lower case) and "a(n)" are conventions in mathematics.
336
+
337
+ Returns
338
+ -------
339
+ a(n) : int
340
+ a(n) is the total number of top arches with exactly one covering arch for semi-meanders with n top arches.
341
+
342
+ Would You Like to Know More?
343
+ ----------------------------
344
+ OEIS : webpage
345
+ https://oeis.org/A301620
346
+ """
347
+ return A000682(n + 2) - 2 * A000682(n + 1)
@@ -0,0 +1,84 @@
1
+ """Compute a(n) for an OEIS ID by computing other OEIS IDs.
2
+
3
+ TODO Implement A178961 for unknown values of A001010
4
+ TODO A223094 For n >= 3: a(n) = n! - Sum_{k=3..n-1} (a(k)*n!/k!) - A000682(n+1). - _Roger Ford_, Aug 24 2024
5
+ TODO A301620 a(n) = Sum_{k=3..floor((n+3)/2)} (A259689(n+1,k)*(k-2)). - _Roger Ford_, Dec 10 2018
6
+ """
7
+ from functools import cache
8
+ from mapFolding import countFolds, dictionaryOEISMeanders
9
+ from mapFolding.basecamp import A000682, A005316
10
+
11
+ @cache
12
+ def A000136(n: int) -> int:
13
+ """A000682"""
14
+ return n * A000682(n)
15
+
16
+ def A000560(n: int) -> int:
17
+ """A000682"""
18
+ return A000682(n + 1) // 2
19
+
20
+ def A001010(n: int) -> int:
21
+ """A000682 or A007822"""
22
+ if n == 1:
23
+ foldsTotal = 1
24
+ elif n & 0b1:
25
+ foldsTotal = 2 * countFolds(oeisID='A007822', oeis_n=(n - 1)//2 + 1, flow='theorem2Numba')
26
+ else:
27
+ foldsTotal = 2 * A000682(n // 2 + 1)
28
+ return foldsTotal
29
+
30
+ def A001011(n: int) -> int:
31
+ """A000136 and A001010"""
32
+ if n == 0:
33
+ foldsTotal = 1
34
+ else:
35
+ foldsTotal = (A001010(n) + A000136(n)) // 4
36
+ return foldsTotal
37
+
38
+ @cache
39
+ def A005315(n: int) -> int:
40
+ """A005316"""
41
+ if n == 1:
42
+ foldsTotal = 1
43
+ else:
44
+ foldsTotal = A005316(2 * n - 1)
45
+ return foldsTotal
46
+
47
+ def A060206(n: int) -> int:
48
+ """A000682"""
49
+ return A000682(2 * n + 1)
50
+
51
+ def A077460(n: int) -> int:
52
+ """A005315, A005316, and A060206"""
53
+ if n in {0, 1}:
54
+ foldsTotal = 1
55
+ elif n & 0b1:
56
+ foldsTotal = (A005315(n) + A005316(n) + A060206((n - 1) // 2)) // 4
57
+ else:
58
+ foldsTotal = (A005315(n) + 2 * A005316(n)) // 4
59
+
60
+ return foldsTotal
61
+
62
+ def A078591(n: int) -> int:
63
+ """A005315"""
64
+ return A005315(n) // 2
65
+
66
+ def A178961(n: int) -> int:
67
+ """A001010"""
68
+ A001010valuesKnown: dict[int, int] = dictionaryOEISMeanders['A001010']['valuesKnown']
69
+ foldsTotal: int = 0
70
+ for n下i in range(1, n+1):
71
+ foldsTotal += A001010valuesKnown[n下i]
72
+ return foldsTotal
73
+
74
+ def A223094(n: int) -> int:
75
+ """A000136 and A000682"""
76
+ return A000136(n) - A000682(n + 1)
77
+
78
+ def A259702(n: int) -> int:
79
+ """A000682"""
80
+ return A000682(n) // 2 - A000682(n - 1)
81
+
82
+ def A301620(n: int) -> int:
83
+ """A000682"""
84
+ return A000682(n + 2) - 2 * A000682(n + 1)
mapFolding/basecamp.py CHANGED
@@ -1,13 +1,75 @@
1
1
  """Unified interface for map folding computation."""
2
2
 
3
3
  from collections.abc import Sequence
4
+ from functools import cache
4
5
  from mapFolding import (
5
- getPathFilenameFoldsTotal, packageSettings, saveFoldsTotal, saveFoldsTotalFAILearly, setProcessorLimit,
6
- validateListDimensions)
6
+ getPathFilenameFoldsTotal, MatrixMeandersState, packageSettings, saveFoldsTotal, saveFoldsTotalFAILearly,
7
+ setProcessorLimit, validateListDimensions)
8
+ from mapFolding.algorithms.matrixMeanders import doTheNeedful
7
9
  from os import PathLike
8
10
  from pathlib import PurePath
9
11
  import contextlib
10
12
 
13
+ """TODO new flow paradigm, incomplete
14
+
15
+ algorithms directory
16
+ manually coded algorithms or formulas
17
+ `countFolds` will be a stable interface for multidimensional map folding, including synthetic modules
18
+ This has special treatment because people may want to call mapShape not defined in OEIS
19
+ `countMeanders` will be a stable interface for meanders
20
+ This has special treatment because people may want to call meanders not defined in OEIS
21
+ an enhanced version of `oeisIDfor_n` will be a stable interface for calling by ID and n
22
+
23
+ General flow structure
24
+ doTheNeedful
25
+ specific to that version of that algorithm
26
+ abstracts the API for that algorithm, so that algorithm (such as multidimensional map folding) has a stable interface
27
+ The last place to do defensive programming
28
+
29
+ - Incomplete: how to count
30
+ - currently in parameters computationDivisions, CPUlimit, and flow
31
+
32
+ - Flow in count______
33
+ - DEFENSIVE PROGRAMMING
34
+ - FAIL EARLY
35
+ - Implement "common foundational logic".
36
+ - IDK what the correct technical term is, but I'm sure other people have researched excellent ways to do this.
37
+ - Example: in `countFolds`, every possible flow path needs `mapShape`. Therefore, `mapShape` is foundational logic that
38
+ all flow paths have in common: "common foundational logic".
39
+ - Example: in `countFolds`, some flow paths have more than one "task division" (i.e., the computation is divided into
40
+ multiple tasks), while other flow paths only have one task division. One reasonable perspective is that computing task
41
+ divisions is NOT "common foundational logic". My perspective for this example: to compute whether or not there are
42
+ task divisions and if so, how many task divisions is identical for all flow paths. Therefore, I handle computing task
43
+ divisions as "common foundational logic".
44
+ - Incomplete
45
+ - Initialize memorialization instructions, if asked
46
+ - MORE DEFENSIVE PROGRAMMING
47
+ - FAIL EARLIER THAN EARLY
48
+ - Incomplete
49
+ - DEFENSIVE PROGRAMMING ON BEHALF of downstream modules and functions
50
+ - FAIL SO EARLY IT IS BEFORE THE USER INSTALLS THE APP
51
+ - Incomplete
52
+ - REPEAT MANY OR ALL OF THE DEFENSIVE PROGRAMMING YOU HAVE ALREADY DONE
53
+
54
+ - Incomplete
55
+ - Pass control to the correct `doTheNeedful`
56
+ - I don't know how to "elegantly" pass control without putting `doTheNeedful` over `count______` in the stack, therefore,
57
+ control will come back here.
58
+ - DO NOT, for the love of puppies and cookies, DO NOT use defensive programming here. Defensive programming AFTER a
59
+ four-week-long computation is a tacit admission of incompetent programming.
60
+ - Follow memorialization instructions: which means pass control to a function will tenaciously follow the instructions.
61
+ - return "a(n)" (as OEIS calls it), such as foldsTotal
62
+
63
+ """
64
+
65
+ # Parameters
66
+ # What you want to compute
67
+ # Memorialization
68
+ # Concurrency
69
+ # How you want to compute it
70
+ # Interpretation of parameters
71
+ # Input data
72
+
11
73
  def countFolds(listDimensions: Sequence[int] | None = None
12
74
  , pathLikeWriteFoldsTotal: PathLike[str] | PurePath | None = None
13
75
  , computationDivisions: int | str | None = None
@@ -93,9 +155,9 @@ def countFolds(listDimensions: Sequence[int] | None = None
93
155
  pass
94
156
  else:
95
157
  if oeisID and oeis_n:
96
- from mapFolding.oeis import dictionaryOEIS # noqa: PLC0415
158
+ from mapFolding.oeis import dictionaryOEISMapFolding # noqa: PLC0415
97
159
  with contextlib.suppress(KeyError):
98
- mapShape = dictionaryOEIS[oeisID]['getMapShape'](oeis_n)
160
+ mapShape = dictionaryOEISMapFolding[oeisID]['getMapShape'](oeis_n)
99
161
  if not mapShape and listDimensions:
100
162
  mapShape = validateListDimensions(listDimensions)
101
163
 
@@ -146,28 +208,63 @@ def countFolds(listDimensions: Sequence[int] | None = None
146
208
 
147
209
  """
148
210
  match flow:
211
+ case 'asynchronous':
212
+ from mapFolding.dataBaskets import MapFoldingState # noqa: PLC0415
213
+ mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
214
+
215
+ from mapFolding.syntheticModules.A007822.asynchronous import doTheNeedful # noqa: PLC0415
216
+ mapFoldingState = doTheNeedful(mapFoldingState)
217
+
218
+ case 'asynchronousTheorem2':
219
+ from mapFolding.dataBaskets import MapFoldingState # noqa: PLC0415
220
+ mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
221
+
222
+ from mapFolding.syntheticModules.A007822.initializeState import transitionOnGroupsOfFolds # noqa: PLC0415
223
+ mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
224
+
225
+ from mapFolding.syntheticModules.A007822.asynchronousAnnex import initializeConcurrencyManager # noqa: PLC0415
226
+ initializeConcurrencyManager(groupsOfFolds=mapFoldingState.groupsOfFolds)
227
+ mapFoldingState.groupsOfFolds = 0
228
+
229
+ from mapFolding.syntheticModules.A007822.asynchronousTheorem2 import count # noqa: PLC0415
230
+ mapFoldingState = count(mapFoldingState)
231
+
232
+ case 'asynchronousTrimmed':
233
+ from mapFolding.dataBaskets import MapFoldingState # noqa: PLC0415
234
+ mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
235
+
236
+ from mapFolding.syntheticModules.A007822.initializeState import transitionOnGroupsOfFolds # noqa: PLC0415
237
+ mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
238
+
239
+ from mapFolding.syntheticModules.A007822.asynchronousAnnex import initializeConcurrencyManager # noqa: PLC0415
240
+ initializeConcurrencyManager(groupsOfFolds=mapFoldingState.groupsOfFolds)
241
+ mapFoldingState.groupsOfFolds = 0
242
+
243
+ from mapFolding.syntheticModules.A007822.asynchronousTrimmed import count # noqa: PLC0415
244
+ mapFoldingState = count(mapFoldingState)
245
+
149
246
  case 'numba':
150
247
  from mapFolding.dataBaskets import MapFoldingState # noqa: PLC0415
151
248
  mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
152
249
 
153
- from mapFolding.syntheticModules.algorithmA007822Numba import doTheNeedful # noqa: PLC0415
250
+ from mapFolding.syntheticModules.A007822.algorithmNumba import doTheNeedful # noqa: PLC0415
154
251
  mapFoldingState = doTheNeedful(mapFoldingState)
155
252
 
156
253
  case 'theorem2':
157
254
  from mapFolding.dataBaskets import MapFoldingState # noqa: PLC0415
158
255
  mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
159
256
 
160
- from mapFolding.syntheticModules.initializeStateA007822 import transitionOnGroupsOfFolds # noqa: PLC0415
257
+ from mapFolding.syntheticModules.A007822.initializeState import transitionOnGroupsOfFolds # noqa: PLC0415
161
258
  mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
162
259
 
163
- from mapFolding.syntheticModules.theorem2A007822 import count # noqa: PLC0415
260
+ from mapFolding.syntheticModules.A007822.theorem2 import count # noqa: PLC0415
164
261
  mapFoldingState = count(mapFoldingState)
165
262
 
166
263
  case 'theorem2Numba':
167
264
  from mapFolding.dataBaskets import MapFoldingState # noqa: PLC0415
168
265
  mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
169
266
 
170
- from mapFolding.syntheticModules.initializeStateA007822 import transitionOnGroupsOfFolds # noqa: PLC0415
267
+ from mapFolding.syntheticModules.A007822.initializeState import transitionOnGroupsOfFolds # noqa: PLC0415
171
268
  mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
172
269
 
173
270
  from mapFolding.syntheticModules.dataPackingA007822 import sequential # noqa: PLC0415
@@ -177,17 +274,17 @@ def countFolds(listDimensions: Sequence[int] | None = None
177
274
  from mapFolding.dataBaskets import MapFoldingState # noqa: PLC0415
178
275
  mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
179
276
 
180
- from mapFolding.syntheticModules.initializeStateA007822 import transitionOnGroupsOfFolds # noqa: PLC0415
277
+ from mapFolding.syntheticModules.A007822.initializeState import transitionOnGroupsOfFolds # noqa: PLC0415
181
278
  mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
182
279
 
183
- from mapFolding.syntheticModules.theorem2A007822Trimmed import count # noqa: PLC0415
280
+ from mapFolding.syntheticModules.A007822.theorem2Trimmed import count # noqa: PLC0415
184
281
  mapFoldingState = count(mapFoldingState)
185
282
 
186
283
  case _:
187
284
  from mapFolding.dataBaskets import MapFoldingState # noqa: PLC0415
188
285
  mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
189
286
 
190
- from mapFolding.syntheticModules.algorithmA007822 import doTheNeedful # noqa: PLC0415
287
+ from mapFolding.syntheticModules.A007822.algorithm import doTheNeedful # noqa: PLC0415
191
288
  mapFoldingState = doTheNeedful(mapFoldingState)
192
289
 
193
290
  foldsTotal = mapFoldingState.groupsOfFolds
@@ -196,7 +293,7 @@ def countFolds(listDimensions: Sequence[int] | None = None
196
293
  from mapFolding.dataBaskets import MapFoldingState # noqa: PLC0415
197
294
  mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
198
295
 
199
- from mapFolding.daoOfMapFolding import doTheNeedful # noqa: PLC0415
296
+ from mapFolding.algorithms.daoOfMapFolding import doTheNeedful # noqa: PLC0415
200
297
  mapFoldingState = doTheNeedful(mapFoldingState)
201
298
  foldsTotal = mapFoldingState.foldsTotal
202
299
 
@@ -250,8 +347,8 @@ def countFolds(listDimensions: Sequence[int] | None = None
250
347
 
251
348
  from mapFolding.syntheticModules.countParallelNumba import doTheNeedful # noqa: PLC0415
252
349
 
253
- # `listStatesParallel` exists in case you want to research the parallel computation.
254
- foldsTotal, listStatesParallel = doTheNeedful(parallelMapFoldingState, concurrencyLimit) # pyright: ignore[reportUnusedVariable]
350
+ # `listStatesParallel` exists so you can research the parallel computation.
351
+ foldsTotal, listStatesParallel = doTheNeedful(parallelMapFoldingState, concurrencyLimit) # pyright: ignore[reportUnusedVariable] # noqa: RUF059
255
352
 
256
353
  else:
257
354
  from mapFolding.dataBaskets import MapFoldingState # noqa: PLC0415
@@ -267,3 +364,43 @@ def countFolds(listDimensions: Sequence[int] | None = None
267
364
  saveFoldsTotal(pathFilenameFoldsTotal, foldsTotal)
268
365
 
269
366
  return foldsTotal
367
+
368
+ @cache
369
+ def A000682(n: int) -> int:
370
+ """Compute A000682(n)."""
371
+ oeisID = 'A000682'
372
+
373
+ kOfMatrix: int = n - 1
374
+
375
+ if n & 0b1:
376
+ curveLocations: int = 5
377
+ else:
378
+ curveLocations = 1
379
+ listCurveLocations: list[int] = [(curveLocations << 1) | curveLocations]
380
+
381
+ MAXIMUMcurveLocations: int = 1 << (2 * kOfMatrix + 4)
382
+ while listCurveLocations[-1] < MAXIMUMcurveLocations:
383
+ curveLocations = (curveLocations << 4) | 0b101 # == curveLocations * 2**4 + 5
384
+ listCurveLocations.append((curveLocations << 1) | curveLocations)
385
+
386
+ dictionaryCurveLocations=dict.fromkeys(listCurveLocations, 1)
387
+
388
+ state = MatrixMeandersState(n, oeisID, kOfMatrix, dictionaryCurveLocations)
389
+
390
+ return doTheNeedful(state)
391
+
392
+ @cache
393
+ def A005316(n: int) -> int:
394
+ """Compute A005316(n)."""
395
+ oeisID = 'A005316'
396
+
397
+ kOfMatrix: int = n - 1
398
+
399
+ if n & 0b1:
400
+ dictionaryCurveLocations: dict[int, int] = {15: 1}
401
+ else:
402
+ dictionaryCurveLocations = {22: 1}
403
+
404
+ state = MatrixMeandersState(n, oeisID, kOfMatrix, dictionaryCurveLocations)
405
+
406
+ return doTheNeedful(state)