mapFolding 0.16.0__py3-none-any.whl → 0.16.2__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/A000682.py +25 -0
- easyRun/A005316.py +20 -0
- easyRun/NOTcountingFolds.py +36 -0
- easyRun/__init__.py +0 -0
- easyRun/countFolds.py +41 -0
- easyRun/meanders.py +69 -0
- mapFolding/__init__.py +8 -51
- mapFolding/_dataPacking.py +68 -0
- mapFolding/_theSSOT.py +33 -37
- mapFolding/_theTypes.py +21 -4
- mapFolding/algorithms/matrixMeanders.py +86 -517
- mapFolding/algorithms/matrixMeandersBeDry.py +182 -0
- mapFolding/algorithms/matrixMeandersNumPy.py +333 -0
- mapFolding/algorithms/matrixMeandersPandas.py +334 -0
- mapFolding/algorithms/oeisIDbyFormula.py +50 -29
- mapFolding/algorithms/zCuzDocStoopidoeisIDbyFormula.py +51 -29
- mapFolding/basecamp.py +167 -206
- mapFolding/beDRY.py +2 -30
- mapFolding/dataBaskets.py +75 -49
- mapFolding/oeis.py +11 -32
- mapFolding/reference/A000682facts.py +787 -652
- mapFolding/reference/A005316facts.py +961 -3
- mapFolding/reference/matrixMeandersAnalysis/prefixNotationNotes.py +15 -0
- mapFolding/reference/matrixMeandersAnalysis/signatures.py +2030 -0
- mapFolding/reference/meandersDumpingGround/A005316JavaPort.py +1 -1
- mapFolding/reference/meandersDumpingGround/A005316imperative.py +1 -1
- mapFolding/reference/meandersDumpingGround/matrixMeandersNumPyV1finalForm.py +424 -0
- mapFolding/someAssemblyRequired/A007822/A007822rawMaterials.py +3 -4
- mapFolding/someAssemblyRequired/A007822/makeA007822AsynchronousModules.py +103 -29
- mapFolding/someAssemblyRequired/A007822/makeA007822Modules.py +18 -14
- mapFolding/someAssemblyRequired/RecipeJob.py +2 -2
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +7 -6
- mapFolding/someAssemblyRequired/makeJobTheorem2codon.py +3 -4
- mapFolding/someAssemblyRequired/makingModules_count.py +88 -87
- mapFolding/someAssemblyRequired/makingModules_doTheNeedful.py +10 -9
- mapFolding/someAssemblyRequired/mapFolding/makeMapFoldingModules.py +3 -3
- mapFolding/someAssemblyRequired/meanders/__init__.py +0 -0
- mapFolding/someAssemblyRequired/meanders/makeMeandersModules.py +63 -0
- mapFolding/someAssemblyRequired/toolkitMakeModules.py +37 -37
- mapFolding/someAssemblyRequired/transformationTools.py +8 -8
- mapFolding/syntheticModules/A007822/algorithm.py +3 -3
- mapFolding/syntheticModules/A007822/algorithmNumba.py +1 -2
- mapFolding/syntheticModules/A007822/asynchronous.py +6 -4
- mapFolding/syntheticModules/A007822/asynchronousAnnex.py +5 -7
- mapFolding/syntheticModules/A007822/asynchronousAnnexNumba.py +70 -0
- mapFolding/syntheticModules/A007822/asynchronousNumba.py +79 -0
- mapFolding/syntheticModules/A007822/asynchronousTheorem2.py +15 -3
- mapFolding/syntheticModules/A007822/asynchronousTrimmed.py +12 -3
- mapFolding/syntheticModules/A007822/initializeState.py +1 -2
- mapFolding/syntheticModules/A007822/theorem2.py +7 -2
- mapFolding/syntheticModules/A007822/theorem2Numba.py +31 -4
- mapFolding/syntheticModules/A007822/theorem2Trimmed.py +8 -3
- mapFolding/syntheticModules/countParallelNumba.py +5 -2
- mapFolding/syntheticModules/dataPacking.py +1 -1
- mapFolding/syntheticModules/dataPackingA007822.py +92 -26
- mapFolding/syntheticModules/meanders/__init__.py +1 -0
- mapFolding/syntheticModules/meanders/bigInt.py +52 -0
- mapFolding/syntheticModules/theorem2.py +6 -0
- mapFolding/syntheticModules/theorem2Numba.py +8 -2
- mapFolding/syntheticModules/theorem2Trimmed.py +6 -0
- mapFolding/tests/conftest.py +28 -13
- mapFolding/tests/test_computations.py +68 -61
- mapFolding/tests/test_oeis.py +6 -6
- mapFolding/zCuzDocStoopid/__init__.py +4 -1
- mapFolding/zCuzDocStoopid/makeDocstrings.py +35 -28
- mapfolding-0.16.2.dist-info/METADATA +99 -0
- mapfolding-0.16.2.dist-info/RECORD +115 -0
- {mapfolding-0.16.0.dist-info → mapfolding-0.16.2.dist-info}/top_level.txt +1 -0
- mapFolding/algorithms/getBucketsTotal.py +0 -137
- mapFolding/reference/matrixMeandersAnalysis/evenEven.py +0 -144
- mapFolding/reference/matrixMeandersAnalysis/oddEven.py +0 -54
- mapFolding/trim_memory.py +0 -62
- mapfolding-0.16.0.dist-info/METADATA +0 -85
- mapfolding-0.16.0.dist-info/RECORD +0 -100
- {mapfolding-0.16.0.dist-info → mapfolding-0.16.2.dist-info}/WHEEL +0 -0
- {mapfolding-0.16.0.dist-info → mapfolding-0.16.2.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.16.0.dist-info → mapfolding-0.16.2.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
from gc import collect as goByeBye
|
|
2
|
+
from mapFolding.algorithms.matrixMeandersBeDry import areIntegersWide, flipTheExtra_0b1AsUfunc, getBucketsTotal
|
|
3
|
+
from mapFolding.dataBaskets import MatrixMeandersNumPyState
|
|
4
|
+
from mapFolding.syntheticModules.meanders.bigInt import countBigInt
|
|
5
|
+
from warnings import warn
|
|
6
|
+
import pandas
|
|
7
|
+
|
|
8
|
+
def countPandas(state: MatrixMeandersNumPyState) -> MatrixMeandersNumPyState:
|
|
9
|
+
"""Count meanders with matrix transfer algorithm using pandas DataFrame.
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
state : MatrixMeandersState
|
|
14
|
+
The algorithm state containing current `boundary`, `dictionaryMeanders`, and thresholds.
|
|
15
|
+
|
|
16
|
+
Returns
|
|
17
|
+
-------
|
|
18
|
+
state : MatrixMeandersState
|
|
19
|
+
Updated state with new `boundary` and `dictionaryMeanders`.
|
|
20
|
+
"""
|
|
21
|
+
dataframeAnalyzed = pandas.DataFrame({
|
|
22
|
+
'analyzed': pandas.Series(name='analyzed', data=state.dictionaryMeanders.keys(), copy=False, dtype=state.datatypeArcCode)
|
|
23
|
+
, 'crossings': pandas.Series(name='crossings', data=state.dictionaryMeanders.values(), copy=False, dtype=state.datatypeCrossings)
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
state.dictionaryMeanders.clear()
|
|
27
|
+
|
|
28
|
+
while (state.boundary > 0 and not areIntegersWide(state, dataframe=dataframeAnalyzed)):
|
|
29
|
+
|
|
30
|
+
def aggregateArcCodes() -> None:
|
|
31
|
+
nonlocal dataframeAnalyzed
|
|
32
|
+
dataframeAnalyzed = dataframeAnalyzed.iloc[0:state.indexTarget].groupby('analyzed', sort=False)['crossings'].aggregate('sum').reset_index()
|
|
33
|
+
|
|
34
|
+
def analyzeArcCodesAligned(dataframeMeanders: pandas.DataFrame) -> pandas.DataFrame:
|
|
35
|
+
"""Compute `arcCode` from `bitsAlpha` and `bitsZulu` if at least one is an even number.
|
|
36
|
+
|
|
37
|
+
Before computing `arcCode`, some values of `bitsAlpha` and `bitsZulu` are modified.
|
|
38
|
+
|
|
39
|
+
Warning
|
|
40
|
+
-------
|
|
41
|
+
This function deletes rows from `dataframeMeanders`. Always run this analysis last.
|
|
42
|
+
|
|
43
|
+
Formula
|
|
44
|
+
-------
|
|
45
|
+
```python
|
|
46
|
+
if bitsAlpha > 1 and bitsZulu > 1 and (bitsAlphaIsEven or bitsZuluIsEven):
|
|
47
|
+
arcCode = (bitsAlpha >> 2) | ((bitsZulu >> 2) << 1)
|
|
48
|
+
```
|
|
49
|
+
"""
|
|
50
|
+
# NOTE Step 1 drop unqualified rows
|
|
51
|
+
# ======= > * > bitsAlpha 1 bitsZulu 1 ====================
|
|
52
|
+
dataframeMeanders['analyzed'] = dataframeMeanders['arcCode'].copy() # `bitsAlpha`
|
|
53
|
+
dataframeMeanders['analyzed'] &= state.locatorBits # `bitsAlpha`
|
|
54
|
+
|
|
55
|
+
dataframeMeanders['analyzed'] = dataframeMeanders['analyzed'].gt(1) # if bitsAlphaHasArcs
|
|
56
|
+
|
|
57
|
+
bitsTarget: pandas.Series = dataframeMeanders['arcCode'].copy() # `bitsZulu`
|
|
58
|
+
bitsTarget //= 2**1 # `bitsZulu` (bitsZulu >> 1)
|
|
59
|
+
bitsTarget &= state.locatorBits # `bitsZulu`
|
|
60
|
+
|
|
61
|
+
dataframeMeanders['analyzed'] *= bitsTarget
|
|
62
|
+
del bitsTarget
|
|
63
|
+
dataframeMeanders = dataframeMeanders.loc[(dataframeMeanders['analyzed'] > 1)] # if (bitsAlphaHasArcs and bitsZuluHasArcs)
|
|
64
|
+
|
|
65
|
+
# ======= ^ & & bitsAlpha 1 bitsZulu 1 ====================
|
|
66
|
+
dataframeMeanders.loc[:, 'analyzed'] = dataframeMeanders['arcCode'].copy() # `bitsAlpha`
|
|
67
|
+
dataframeMeanders.loc[:, 'analyzed'] &= state.locatorBits # `bitsAlpha`
|
|
68
|
+
|
|
69
|
+
dataframeMeanders.loc[:, 'analyzed'] &= 1 # `bitsAlpha`
|
|
70
|
+
|
|
71
|
+
bitsTarget: pandas.Series = dataframeMeanders['arcCode'].copy() # `bitsZulu`
|
|
72
|
+
bitsTarget //= 2**1 # `bitsZulu` (bitsZulu >> 1)
|
|
73
|
+
bitsTarget &= state.locatorBits # `bitsZulu`
|
|
74
|
+
|
|
75
|
+
dataframeMeanders.loc[:, 'analyzed'] &= bitsTarget
|
|
76
|
+
del bitsTarget
|
|
77
|
+
dataframeMeanders.loc[:, 'analyzed'] ^= 1
|
|
78
|
+
|
|
79
|
+
dataframeMeanders = dataframeMeanders.loc[(dataframeMeanders['analyzed'] > 0)] # if (bitsAlphaIsEven or bitsZuluIsEven)
|
|
80
|
+
|
|
81
|
+
# NOTE Step 2 modify rows
|
|
82
|
+
# Make a selector for bitsZuluAtOdd, so you can modify bitsAlpha
|
|
83
|
+
dataframeMeanders.loc[:, 'analyzed'] = dataframeMeanders['arcCode'].copy() # `bitsZulu`
|
|
84
|
+
dataframeMeanders.loc[:, 'analyzed'] //= 2**1 # `bitsZulu` (bitsZulu >> 1)
|
|
85
|
+
dataframeMeanders.loc[:, 'analyzed'] &= 1 # selectorBitsZuluAtOdd
|
|
86
|
+
|
|
87
|
+
bitsTarget = dataframeMeanders['arcCode'].copy() # `bitsAlpha`
|
|
88
|
+
bitsTarget &= state.locatorBits # `bitsAlpha`
|
|
89
|
+
|
|
90
|
+
# if bitsAlphaAtEven and not bitsZuluAtEven, modify bitsAlphaPairedToOdd
|
|
91
|
+
bitsTarget.loc[(dataframeMeanders['analyzed'] > 0)] = state.datatypeArcCode(
|
|
92
|
+
flipTheExtra_0b1AsUfunc(bitsTarget.loc[(dataframeMeanders['analyzed'] > 0)]))
|
|
93
|
+
|
|
94
|
+
dataframeMeanders.loc[:, 'analyzed'] = dataframeMeanders['arcCode'].copy() # `bitsZulu`
|
|
95
|
+
dataframeMeanders.loc[:, 'analyzed'] //= 2**1 # `bitsZulu` (bitsZulu >> 1)
|
|
96
|
+
dataframeMeanders.loc[:, 'analyzed'] &= state.locatorBits # `bitsZulu`
|
|
97
|
+
|
|
98
|
+
# if bitsZuluAtEven and not bitsAlphaAtEven, modify bitsZuluPairedToOdd
|
|
99
|
+
dataframeMeanders.loc[((dataframeMeanders.loc[:, 'arcCode'] & 1) > 0), 'analyzed'] = state.datatypeArcCode(
|
|
100
|
+
flipTheExtra_0b1AsUfunc(dataframeMeanders.loc[((dataframeMeanders.loc[:, 'arcCode'] & 1) > 0), 'analyzed']))
|
|
101
|
+
|
|
102
|
+
# NOTE Step 3 compute arcCode
|
|
103
|
+
# ======= >> | << >> bitsZulu 2 3 bitsAlpha 2 =============
|
|
104
|
+
dataframeMeanders.loc[:, 'analyzed'] //= 2**2 # (bitsZulu >> 2)
|
|
105
|
+
dataframeMeanders.loc[:, 'analyzed'] *= 2**3 # (bitsZulu << 3)
|
|
106
|
+
dataframeMeanders.loc[:, 'analyzed'] |= bitsTarget
|
|
107
|
+
del bitsTarget
|
|
108
|
+
dataframeMeanders.loc[:, 'analyzed'] //= 2**2 # (... >> 2)
|
|
109
|
+
|
|
110
|
+
dataframeMeanders.loc[dataframeMeanders['analyzed'] >= state.MAXIMUMarcCode, 'analyzed'] = 0
|
|
111
|
+
|
|
112
|
+
return dataframeMeanders
|
|
113
|
+
|
|
114
|
+
def analyzeArcCodesSimple(dataframeMeanders: pandas.DataFrame) -> pandas.DataFrame:
|
|
115
|
+
"""Compute arcCode with the 'simple' formula.
|
|
116
|
+
|
|
117
|
+
Formula
|
|
118
|
+
-------
|
|
119
|
+
```python
|
|
120
|
+
arcCode = ((bitsAlpha | (bitsZulu << 1)) << 2) | 3
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Notes
|
|
124
|
+
-----
|
|
125
|
+
Using `+= 3` instead of `|= 3` is valid in this specific case. Left shift by two means the last bits are '0b00'. '0 + 3'
|
|
126
|
+
is '0b11', and '0b00 | 0b11' is also '0b11'.
|
|
127
|
+
|
|
128
|
+
"""
|
|
129
|
+
dataframeMeanders['analyzed'] = dataframeMeanders['arcCode']
|
|
130
|
+
dataframeMeanders.loc[:, 'analyzed'] &= state.locatorBits
|
|
131
|
+
|
|
132
|
+
bitsZulu: pandas.Series = dataframeMeanders['arcCode'].copy()
|
|
133
|
+
bitsZulu //= 2**1 # (bitsZulu >> 1)
|
|
134
|
+
bitsZulu &= state.locatorBits # `bitsZulu`
|
|
135
|
+
|
|
136
|
+
bitsZulu *= 2**1 # (bitsZulu << 1)
|
|
137
|
+
|
|
138
|
+
dataframeMeanders.loc[:, 'analyzed'] |= bitsZulu # ((bitsAlpha | (bitsZulu ...))
|
|
139
|
+
|
|
140
|
+
del bitsZulu
|
|
141
|
+
|
|
142
|
+
dataframeMeanders.loc[:, 'analyzed'] *= 2**2 # (... << 2)
|
|
143
|
+
dataframeMeanders.loc[:, 'analyzed'] += 3 # (...) | 3
|
|
144
|
+
dataframeMeanders.loc[dataframeMeanders['analyzed'] >= state.MAXIMUMarcCode, 'analyzed'] = 0
|
|
145
|
+
|
|
146
|
+
return dataframeMeanders
|
|
147
|
+
|
|
148
|
+
def analyzeBitsAlpha(dataframeMeanders: pandas.DataFrame) -> pandas.DataFrame:
|
|
149
|
+
"""Compute `arcCode` from `bitsAlpha`.
|
|
150
|
+
|
|
151
|
+
Formula
|
|
152
|
+
-------
|
|
153
|
+
```python
|
|
154
|
+
if bitsAlpha > 1:
|
|
155
|
+
arcCode = ((1 - (bitsAlpha & 1)) << 1) | (bitsZulu << 3) | (bitsAlpha >> 2)
|
|
156
|
+
# `(1 - (bitsAlpha & 1)` is an evenness test.
|
|
157
|
+
```
|
|
158
|
+
"""
|
|
159
|
+
dataframeMeanders['analyzed'] = dataframeMeanders['arcCode']
|
|
160
|
+
dataframeMeanders.loc[:, 'analyzed'] &= 1 # (bitsAlpha & 1)
|
|
161
|
+
dataframeMeanders.loc[:, 'analyzed'] ^= 1 # (1 - (bitsAlpha ...))
|
|
162
|
+
|
|
163
|
+
dataframeMeanders.loc[:, 'analyzed'] *= 2**1 # ((bitsAlpha ...) << 1)
|
|
164
|
+
|
|
165
|
+
bitsTarget: pandas.Series = dataframeMeanders['arcCode'].copy() # `bitsZulu`
|
|
166
|
+
bitsTarget //= 2**1 # `bitsZulu` (bitsZulu >> 1)
|
|
167
|
+
bitsTarget &= state.locatorBits # `bitsZulu`
|
|
168
|
+
|
|
169
|
+
bitsTarget *= 2**3 # (bitsZulu << 3)
|
|
170
|
+
dataframeMeanders.loc[:, 'analyzed'] |= bitsTarget # ... | (bitsZulu ...)
|
|
171
|
+
|
|
172
|
+
del bitsTarget
|
|
173
|
+
|
|
174
|
+
"""NOTE In this code block, I rearranged the "formula" to use `bitsTarget` for two goals. 1. `(bitsAlpha >> 2)`.
|
|
175
|
+
2. `if bitsAlpha > 1`. The trick is in the equivalence of v1 and v2.
|
|
176
|
+
v1: BITScow | (BITSwalk >> 2)
|
|
177
|
+
v2: ((BITScow << 2) | BITSwalk) >> 2
|
|
178
|
+
|
|
179
|
+
The "formula" calls for v1, but by using v2, `bitsTarget` is not changed. Therefore, because `bitsTarget` is
|
|
180
|
+
`bitsAlpha`, I can use `bitsTarget` for goal 2, `if bitsAlpha > 1`.
|
|
181
|
+
"""
|
|
182
|
+
dataframeMeanders.loc[:, 'analyzed'] *= 2**2 # ... | (bitsAlpha >> 2)
|
|
183
|
+
|
|
184
|
+
bitsTarget = dataframeMeanders['arcCode'].copy() # `bitsAlpha`
|
|
185
|
+
bitsTarget &= state.locatorBits # `bitsAlpha`
|
|
186
|
+
|
|
187
|
+
dataframeMeanders.loc[:, 'analyzed'] |= bitsTarget # ... | (bitsAlpha)
|
|
188
|
+
dataframeMeanders.loc[:, 'analyzed'] //= 2**2 # (... >> 2)
|
|
189
|
+
|
|
190
|
+
dataframeMeanders.loc[(bitsTarget <= 1), 'analyzed'] = 0 # if bitsAlpha > 1
|
|
191
|
+
|
|
192
|
+
del bitsTarget
|
|
193
|
+
|
|
194
|
+
dataframeMeanders.loc[dataframeMeanders['analyzed'] >= state.MAXIMUMarcCode, 'analyzed'] = 0
|
|
195
|
+
|
|
196
|
+
return dataframeMeanders
|
|
197
|
+
|
|
198
|
+
def analyzeBitsZulu(dataframeMeanders: pandas.DataFrame) -> pandas.DataFrame:
|
|
199
|
+
"""Compute `arcCode` from `bitsZulu`.
|
|
200
|
+
|
|
201
|
+
Formula
|
|
202
|
+
-------
|
|
203
|
+
```python
|
|
204
|
+
if bitsZulu > 1:
|
|
205
|
+
arcCode = (1 - (bitsZulu & 1)) | (bitsAlpha << 2) | (bitsZulu >> 1)
|
|
206
|
+
```
|
|
207
|
+
"""
|
|
208
|
+
# NOTE `(1 - (bitsZulu & 1))` is an evenness test: we want a single bit as the answer.
|
|
209
|
+
dataframeMeanders.loc[:, 'analyzed'] = dataframeMeanders['arcCode'] # `bitsZulu`
|
|
210
|
+
dataframeMeanders.loc[:, 'analyzed'] //= 2**1 # `bitsZulu` (bitsZulu >> 1)
|
|
211
|
+
dataframeMeanders.loc[:, 'analyzed'] &= 1 # `bitsZulu`
|
|
212
|
+
dataframeMeanders.loc[:, 'analyzed'] &= 1 # (bitsZulu & 1)
|
|
213
|
+
dataframeMeanders.loc[:, 'analyzed'] ^= 1 # (1 - (bitsZulu ...))
|
|
214
|
+
|
|
215
|
+
bitsTarget: pandas.Series = dataframeMeanders['arcCode'].copy() # `bitsAlpha`
|
|
216
|
+
bitsTarget &= state.locatorBits # `bitsAlpha`
|
|
217
|
+
|
|
218
|
+
bitsTarget *= 2**2 # (bitsAlpha << 2)
|
|
219
|
+
dataframeMeanders.loc[:, 'analyzed'] |= bitsTarget # ... | (bitsAlpha ...)
|
|
220
|
+
del bitsTarget
|
|
221
|
+
|
|
222
|
+
# NOTE Same trick as in `analyzeBitsAlpha`.
|
|
223
|
+
dataframeMeanders.loc[:, 'analyzed'] *= 2**1 # (... << 1)
|
|
224
|
+
|
|
225
|
+
bitsTarget = dataframeMeanders['arcCode'].copy() # `bitsZulu`
|
|
226
|
+
bitsTarget //= 2**1 # `bitsZulu` (bitsZulu >> 1)
|
|
227
|
+
bitsTarget &= state.locatorBits # `bitsZulu`
|
|
228
|
+
|
|
229
|
+
dataframeMeanders.loc[:, 'analyzed'] |= bitsTarget # ... | (bitsZulu)
|
|
230
|
+
dataframeMeanders.loc[:, 'analyzed'] //= 2**1 # (... >> 1)
|
|
231
|
+
|
|
232
|
+
dataframeMeanders.loc[bitsTarget <= 1, 'analyzed'] = 0 # if bitsZulu > 1
|
|
233
|
+
del bitsTarget
|
|
234
|
+
|
|
235
|
+
dataframeMeanders.loc[dataframeMeanders['analyzed'] >= state.MAXIMUMarcCode, 'analyzed'] = 0
|
|
236
|
+
|
|
237
|
+
return dataframeMeanders
|
|
238
|
+
|
|
239
|
+
def recordArcCodes(dataframeMeanders: pandas.DataFrame) -> pandas.DataFrame:
|
|
240
|
+
nonlocal dataframeAnalyzed
|
|
241
|
+
|
|
242
|
+
indexStopAnalyzed: int = state.indexTarget + int((dataframeMeanders['analyzed'] > 0).sum())
|
|
243
|
+
|
|
244
|
+
if indexStopAnalyzed > state.indexTarget:
|
|
245
|
+
if len(dataframeAnalyzed.index) < indexStopAnalyzed:
|
|
246
|
+
warn(f"Lengthened `dataframeAnalyzed` from {len(dataframeAnalyzed.index)} to {indexStopAnalyzed=}; n={state.n}, {state.boundary=}.", stacklevel=2)
|
|
247
|
+
dataframeAnalyzed = dataframeAnalyzed.reindex(index=pandas.RangeIndex(indexStopAnalyzed), fill_value=0)
|
|
248
|
+
|
|
249
|
+
dataframeAnalyzed.loc[state.indexTarget:indexStopAnalyzed - 1, ['analyzed']] = (
|
|
250
|
+
dataframeMeanders.loc[(dataframeMeanders['analyzed'] > 0), ['analyzed']
|
|
251
|
+
].to_numpy(dtype=state.datatypeArcCode, copy=False)
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
dataframeAnalyzed.loc[state.indexTarget:indexStopAnalyzed - 1, ['crossings']] = (
|
|
255
|
+
dataframeMeanders.loc[(dataframeMeanders['analyzed'] > 0), ['crossings']
|
|
256
|
+
].to_numpy(dtype=state.datatypeCrossings, copy=False)
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
state.indexTarget = indexStopAnalyzed
|
|
260
|
+
|
|
261
|
+
del indexStopAnalyzed
|
|
262
|
+
|
|
263
|
+
return dataframeMeanders
|
|
264
|
+
|
|
265
|
+
dataframeMeanders = pandas.DataFrame({
|
|
266
|
+
'arcCode': pandas.Series(name='arcCode', data=dataframeAnalyzed['analyzed'], copy=False, dtype=state.datatypeArcCode)
|
|
267
|
+
, 'analyzed': pandas.Series(name='analyzed', data=0, dtype=state.datatypeArcCode)
|
|
268
|
+
, 'crossings': pandas.Series(name='crossings', data=dataframeAnalyzed['crossings'], copy=False, dtype=state.datatypeCrossings)
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
del dataframeAnalyzed
|
|
273
|
+
goByeBye()
|
|
274
|
+
|
|
275
|
+
state.bitWidth = int(dataframeMeanders['arcCode'].max()).bit_length()
|
|
276
|
+
length: int = getBucketsTotal(state)
|
|
277
|
+
dataframeAnalyzed = pandas.DataFrame({
|
|
278
|
+
'analyzed': pandas.Series(name='analyzed', data=0, index=pandas.RangeIndex(length), dtype=state.datatypeArcCode)
|
|
279
|
+
, 'crossings': pandas.Series(name='crossings', data=0, index=pandas.RangeIndex(length), dtype=state.datatypeCrossings)
|
|
280
|
+
}, index=pandas.RangeIndex(length)
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
state.boundary -= 1
|
|
284
|
+
|
|
285
|
+
state.indexTarget = 0
|
|
286
|
+
|
|
287
|
+
dataframeMeanders: pandas.DataFrame = analyzeArcCodesSimple(dataframeMeanders)
|
|
288
|
+
dataframeMeanders = recordArcCodes(dataframeMeanders)
|
|
289
|
+
|
|
290
|
+
dataframeMeanders = analyzeBitsAlpha(dataframeMeanders)
|
|
291
|
+
dataframeMeanders = recordArcCodes(dataframeMeanders)
|
|
292
|
+
|
|
293
|
+
dataframeMeanders = analyzeBitsZulu(dataframeMeanders)
|
|
294
|
+
dataframeMeanders = recordArcCodes(dataframeMeanders)
|
|
295
|
+
|
|
296
|
+
dataframeMeanders = analyzeArcCodesAligned(dataframeMeanders)
|
|
297
|
+
dataframeMeanders = recordArcCodes(dataframeMeanders)
|
|
298
|
+
del dataframeMeanders
|
|
299
|
+
goByeBye()
|
|
300
|
+
|
|
301
|
+
aggregateArcCodes()
|
|
302
|
+
|
|
303
|
+
state.dictionaryMeanders = dataframeAnalyzed.set_index('analyzed')['crossings'].to_dict()
|
|
304
|
+
del dataframeAnalyzed
|
|
305
|
+
return state
|
|
306
|
+
|
|
307
|
+
def doTheNeedful(state: MatrixMeandersNumPyState) -> int:
|
|
308
|
+
"""Compute `crossings` with a transfer matrix algorithm implemented in pandas.
|
|
309
|
+
|
|
310
|
+
Parameters
|
|
311
|
+
----------
|
|
312
|
+
state : MatrixMeandersState
|
|
313
|
+
The algorithm state.
|
|
314
|
+
|
|
315
|
+
Returns
|
|
316
|
+
-------
|
|
317
|
+
crossings : int
|
|
318
|
+
The computed value of `crossings`.
|
|
319
|
+
|
|
320
|
+
Notes
|
|
321
|
+
-----
|
|
322
|
+
Citation: https://github.com/hunterhogan/mapFolding/blob/main/citations/Jensen.bibtex
|
|
323
|
+
|
|
324
|
+
See Also
|
|
325
|
+
--------
|
|
326
|
+
https://oeis.org/A000682
|
|
327
|
+
https://oeis.org/A005316
|
|
328
|
+
"""
|
|
329
|
+
while state.boundary > 0:
|
|
330
|
+
if areIntegersWide(state):
|
|
331
|
+
state = countBigInt(state)
|
|
332
|
+
else:
|
|
333
|
+
state = countPandas(state)
|
|
334
|
+
return sum(state.dictionaryMeanders.values())
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
TODO Implement A178961 for unknown values of A001010
|
|
4
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
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
|
+
NOTE: This is a generated file; edit the source file.
|
|
6
8
|
"""
|
|
7
9
|
from functools import cache
|
|
8
|
-
from mapFolding import
|
|
9
|
-
from mapFolding.basecamp import
|
|
10
|
+
from mapFolding import dictionaryOEIS
|
|
11
|
+
from mapFolding.basecamp import NOTcountingFolds
|
|
10
12
|
|
|
11
13
|
@cache
|
|
12
14
|
def A000136(n: int) -> int:
|
|
@@ -33,7 +35,7 @@ def A000136(n: int) -> int:
|
|
|
33
35
|
OEIS : webpage
|
|
34
36
|
https://oeis.org/A000136
|
|
35
37
|
"""
|
|
36
|
-
return n *
|
|
38
|
+
return n * _A000682(n)
|
|
37
39
|
|
|
38
40
|
def A000560(n: int) -> int:
|
|
39
41
|
"""
|
|
@@ -59,7 +61,7 @@ def A000560(n: int) -> int:
|
|
|
59
61
|
OEIS : webpage
|
|
60
62
|
https://oeis.org/A000560
|
|
61
63
|
"""
|
|
62
|
-
return
|
|
64
|
+
return _A000682(n + 1) // 2
|
|
63
65
|
|
|
64
66
|
def A001010(n: int) -> int:
|
|
65
67
|
"""
|
|
@@ -86,12 +88,12 @@ def A001010(n: int) -> int:
|
|
|
86
88
|
https://oeis.org/A001010
|
|
87
89
|
"""
|
|
88
90
|
if n == 1:
|
|
89
|
-
|
|
91
|
+
countTotal = 1
|
|
90
92
|
elif n & 1:
|
|
91
|
-
|
|
93
|
+
countTotal = 2 * _A007822((n - 1) // 2 + 1)
|
|
92
94
|
else:
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
+
countTotal = 2 * _A000682(n // 2 + 1)
|
|
96
|
+
return countTotal
|
|
95
97
|
|
|
96
98
|
def A001011(n: int) -> int:
|
|
97
99
|
"""
|
|
@@ -117,11 +119,11 @@ def A001011(n: int) -> int:
|
|
|
117
119
|
OEIS : webpage
|
|
118
120
|
https://oeis.org/A001011
|
|
119
121
|
"""
|
|
120
|
-
if n ==
|
|
121
|
-
|
|
122
|
+
if n == 1:
|
|
123
|
+
countTotal = 1
|
|
122
124
|
else:
|
|
123
|
-
|
|
124
|
-
return
|
|
125
|
+
countTotal = (A001010(n) + A000136(n)) // 4
|
|
126
|
+
return countTotal
|
|
125
127
|
|
|
126
128
|
@cache
|
|
127
129
|
def A005315(n: int) -> int:
|
|
@@ -148,11 +150,11 @@ def A005315(n: int) -> int:
|
|
|
148
150
|
OEIS : webpage
|
|
149
151
|
https://oeis.org/A005315
|
|
150
152
|
"""
|
|
151
|
-
if n
|
|
152
|
-
|
|
153
|
+
if n in {0, 1}:
|
|
154
|
+
countTotal = 1
|
|
153
155
|
else:
|
|
154
|
-
|
|
155
|
-
return
|
|
156
|
+
countTotal = _A005316(2 * n - 1)
|
|
157
|
+
return countTotal
|
|
156
158
|
|
|
157
159
|
def A060206(n: int) -> int:
|
|
158
160
|
"""
|
|
@@ -178,7 +180,7 @@ def A060206(n: int) -> int:
|
|
|
178
180
|
OEIS : webpage
|
|
179
181
|
https://oeis.org/A060206
|
|
180
182
|
"""
|
|
181
|
-
return
|
|
183
|
+
return _A000682(2 * n + 1)
|
|
182
184
|
|
|
183
185
|
def A077460(n: int) -> int:
|
|
184
186
|
"""
|
|
@@ -205,12 +207,12 @@ def A077460(n: int) -> int:
|
|
|
205
207
|
https://oeis.org/A077460
|
|
206
208
|
"""
|
|
207
209
|
if n in {0, 1}:
|
|
208
|
-
|
|
210
|
+
countTotal = 1
|
|
209
211
|
elif n & 1:
|
|
210
|
-
|
|
212
|
+
countTotal = (A005315(n) + _A005316(n) + A060206((n - 1) // 2)) // 4
|
|
211
213
|
else:
|
|
212
|
-
|
|
213
|
-
return
|
|
214
|
+
countTotal = (A005315(n) + 2 * _A005316(n)) // 4
|
|
215
|
+
return countTotal
|
|
214
216
|
|
|
215
217
|
def A078591(n: int) -> int:
|
|
216
218
|
"""
|
|
@@ -236,7 +238,11 @@ def A078591(n: int) -> int:
|
|
|
236
238
|
OEIS : webpage
|
|
237
239
|
https://oeis.org/A078591
|
|
238
240
|
"""
|
|
239
|
-
|
|
241
|
+
if n in {0, 1}:
|
|
242
|
+
countTotal = 1
|
|
243
|
+
else:
|
|
244
|
+
countTotal = A005315(n) // 2
|
|
245
|
+
return countTotal
|
|
240
246
|
|
|
241
247
|
def A178961(n: int) -> int:
|
|
242
248
|
"""
|
|
@@ -262,11 +268,11 @@ def A178961(n: int) -> int:
|
|
|
262
268
|
OEIS : webpage
|
|
263
269
|
https://oeis.org/A178961
|
|
264
270
|
"""
|
|
265
|
-
A001010valuesKnown: dict[int, int] =
|
|
266
|
-
|
|
271
|
+
A001010valuesKnown: dict[int, int] = dictionaryOEIS['A001010']['valuesKnown']
|
|
272
|
+
countTotal: int = 0
|
|
267
273
|
for n下i in range(1, n + 1):
|
|
268
|
-
|
|
269
|
-
return
|
|
274
|
+
countTotal += A001010valuesKnown[n下i]
|
|
275
|
+
return countTotal
|
|
270
276
|
|
|
271
277
|
def A223094(n: int) -> int:
|
|
272
278
|
"""
|
|
@@ -292,7 +298,7 @@ def A223094(n: int) -> int:
|
|
|
292
298
|
OEIS : webpage
|
|
293
299
|
https://oeis.org/A223094
|
|
294
300
|
"""
|
|
295
|
-
return A000136(n) -
|
|
301
|
+
return A000136(n) - _A000682(n + 1)
|
|
296
302
|
|
|
297
303
|
def A259702(n: int) -> int:
|
|
298
304
|
"""
|
|
@@ -318,7 +324,11 @@ def A259702(n: int) -> int:
|
|
|
318
324
|
OEIS : webpage
|
|
319
325
|
https://oeis.org/A259702
|
|
320
326
|
"""
|
|
321
|
-
|
|
327
|
+
if n == 2:
|
|
328
|
+
countTotal = 0
|
|
329
|
+
else:
|
|
330
|
+
countTotal = _A000682(n) // 2 - _A000682(n - 1)
|
|
331
|
+
return countTotal
|
|
322
332
|
|
|
323
333
|
def A301620(n: int) -> int:
|
|
324
334
|
"""
|
|
@@ -344,4 +354,15 @@ def A301620(n: int) -> int:
|
|
|
344
354
|
OEIS : webpage
|
|
345
355
|
https://oeis.org/A301620
|
|
346
356
|
"""
|
|
347
|
-
return
|
|
357
|
+
return _A000682(n + 2) - 2 * _A000682(n + 1)
|
|
358
|
+
|
|
359
|
+
@cache
|
|
360
|
+
def _A000682(n: int) -> int:
|
|
361
|
+
return NOTcountingFolds('A000682', n)
|
|
362
|
+
|
|
363
|
+
def _A007822(n: int) -> int:
|
|
364
|
+
return NOTcountingFolds('A007822', n)
|
|
365
|
+
|
|
366
|
+
@cache
|
|
367
|
+
def _A005316(n: int) -> int:
|
|
368
|
+
return NOTcountingFolds('A005316', n)
|
|
@@ -5,80 +5,102 @@ TODO A223094 For n >= 3: a(n) = n! - Sum_{k=3..n-1} (a(k)*n!/k!) - A000682(n+1).
|
|
|
5
5
|
TODO A301620 a(n) = Sum_{k=3..floor((n+3)/2)} (A259689(n+1,k)*(k-2)). - _Roger Ford_, Dec 10 2018
|
|
6
6
|
"""
|
|
7
7
|
from functools import cache
|
|
8
|
-
from mapFolding import
|
|
9
|
-
from mapFolding.basecamp import
|
|
8
|
+
from mapFolding import dictionaryOEIS
|
|
9
|
+
from mapFolding.basecamp import NOTcountingFolds
|
|
10
10
|
|
|
11
|
+
# ruff: noqa: D400
|
|
11
12
|
@cache
|
|
12
13
|
def A000136(n: int) -> int:
|
|
13
14
|
"""A000682"""
|
|
14
|
-
return n *
|
|
15
|
+
return n * _A000682(n)
|
|
15
16
|
|
|
16
17
|
def A000560(n: int) -> int:
|
|
17
18
|
"""A000682"""
|
|
18
|
-
return
|
|
19
|
+
return _A000682(n + 1) // 2
|
|
19
20
|
|
|
20
21
|
def A001010(n: int) -> int:
|
|
21
22
|
"""A000682 or A007822"""
|
|
22
23
|
if n == 1:
|
|
23
|
-
|
|
24
|
+
countTotal = 1
|
|
24
25
|
elif n & 0b1:
|
|
25
|
-
|
|
26
|
+
countTotal = 2 * _A007822((n - 1)//2 + 1)
|
|
26
27
|
else:
|
|
27
|
-
|
|
28
|
-
return
|
|
28
|
+
countTotal = 2 * _A000682(n // 2 + 1)
|
|
29
|
+
return countTotal
|
|
29
30
|
|
|
30
31
|
def A001011(n: int) -> int:
|
|
31
32
|
"""A000136 and A001010"""
|
|
32
|
-
if n ==
|
|
33
|
-
|
|
33
|
+
if n == 1:
|
|
34
|
+
countTotal = 1
|
|
34
35
|
else:
|
|
35
|
-
|
|
36
|
-
return
|
|
36
|
+
countTotal = (A001010(n) + A000136(n)) // 4
|
|
37
|
+
return countTotal
|
|
37
38
|
|
|
38
39
|
@cache
|
|
39
40
|
def A005315(n: int) -> int:
|
|
40
41
|
"""A005316"""
|
|
41
|
-
if n
|
|
42
|
-
|
|
42
|
+
if n in {0, 1}:
|
|
43
|
+
countTotal = 1
|
|
43
44
|
else:
|
|
44
|
-
|
|
45
|
-
return
|
|
45
|
+
countTotal = _A005316(2 * n - 1)
|
|
46
|
+
return countTotal
|
|
46
47
|
|
|
47
48
|
def A060206(n: int) -> int:
|
|
48
49
|
"""A000682"""
|
|
49
|
-
return
|
|
50
|
+
return _A000682(2 * n + 1)
|
|
50
51
|
|
|
51
52
|
def A077460(n: int) -> int:
|
|
52
53
|
"""A005315, A005316, and A060206"""
|
|
53
54
|
if n in {0, 1}:
|
|
54
|
-
|
|
55
|
+
countTotal = 1
|
|
55
56
|
elif n & 0b1:
|
|
56
|
-
|
|
57
|
+
countTotal = (A005315(n) + _A005316(n) + A060206((n - 1) // 2)) // 4
|
|
57
58
|
else:
|
|
58
|
-
|
|
59
|
+
countTotal = (A005315(n) + 2 * _A005316(n)) // 4
|
|
59
60
|
|
|
60
|
-
return
|
|
61
|
+
return countTotal
|
|
61
62
|
|
|
62
63
|
def A078591(n: int) -> int:
|
|
63
64
|
"""A005315"""
|
|
64
|
-
|
|
65
|
+
if n in {0, 1}:
|
|
66
|
+
countTotal = 1
|
|
67
|
+
else:
|
|
68
|
+
countTotal = A005315(n) // 2
|
|
69
|
+
return countTotal
|
|
65
70
|
|
|
66
71
|
def A178961(n: int) -> int:
|
|
67
72
|
"""A001010"""
|
|
68
|
-
A001010valuesKnown: dict[int, int] =
|
|
69
|
-
|
|
73
|
+
A001010valuesKnown: dict[int, int] = dictionaryOEIS['A001010']['valuesKnown']
|
|
74
|
+
countTotal: int = 0
|
|
70
75
|
for n下i in range(1, n+1):
|
|
71
|
-
|
|
72
|
-
return
|
|
76
|
+
countTotal += A001010valuesKnown[n下i]
|
|
77
|
+
return countTotal
|
|
73
78
|
|
|
74
79
|
def A223094(n: int) -> int:
|
|
75
80
|
"""A000136 and A000682"""
|
|
76
|
-
return A000136(n) -
|
|
81
|
+
return A000136(n) - _A000682(n + 1)
|
|
77
82
|
|
|
78
83
|
def A259702(n: int) -> int:
|
|
79
84
|
"""A000682"""
|
|
80
|
-
|
|
85
|
+
if n == 2:
|
|
86
|
+
countTotal = 0
|
|
87
|
+
else:
|
|
88
|
+
countTotal = _A000682(n) // 2 - _A000682(n - 1)
|
|
89
|
+
return countTotal
|
|
81
90
|
|
|
82
91
|
def A301620(n: int) -> int:
|
|
83
92
|
"""A000682"""
|
|
84
|
-
return
|
|
93
|
+
return _A000682(n + 2) - 2 * _A000682(n + 1)
|
|
94
|
+
|
|
95
|
+
# ================= Not formulas ==========================
|
|
96
|
+
|
|
97
|
+
@cache
|
|
98
|
+
def _A000682(n: int) -> int:
|
|
99
|
+
return NOTcountingFolds('A000682', n)
|
|
100
|
+
|
|
101
|
+
def _A007822(n: int) -> int:
|
|
102
|
+
return NOTcountingFolds('A007822', n)
|
|
103
|
+
|
|
104
|
+
@cache
|
|
105
|
+
def _A005316(n: int) -> int:
|
|
106
|
+
return NOTcountingFolds('A005316', n)
|