mapFolding 0.14.1__py3-none-any.whl → 0.15.1__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.
- mapFolding/__init__.py +2 -1
- mapFolding/_oeisFormulas/A000682.py +2 -2
- mapFolding/_oeisFormulas/A001010.py +18 -0
- mapFolding/_oeisFormulas/Z0Z_aOFn.py +7 -4
- mapFolding/_oeisFormulas/Z0Z_oeisMeanders.py +7 -0
- mapFolding/_oeisFormulas/matrixMeanders.py +122 -75
- mapFolding/_oeisFormulas/matrixMeandersAnnex.py +66 -66
- mapFolding/_theSSOT.py +9 -3
- mapFolding/_theTypes.py +34 -130
- mapFolding/basecamp.py +90 -10
- mapFolding/beDRY.py +5 -21
- mapFolding/daoOfMapFolding.py +2 -1
- mapFolding/dataBaskets.py +8 -3
- mapFolding/oeis.py +10 -16
- mapFolding/reference/A005316optimized128bit.py +19 -19
- mapFolding/reference/A005316primitiveOptimized.py +25 -25
- mapFolding/reference/A005316redis.py +19 -19
- mapFolding/reference/A005316write2disk.py +19 -19
- mapFolding/reference/jaxCount.py +1 -1
- mapFolding/reference/matrixMeandersBaseline.py +20 -20
- mapFolding/reference/matrixMeandersBaselineAnnex.py +4 -4
- mapFolding/reference/matrixMeandersSimpleQueue.py +90 -0
- mapFolding/reference/matrixMeandersSlicePop.py +104 -0
- mapFolding/reference/rotatedEntryPoint.py +1 -1
- mapFolding/someAssemblyRequired/A007822rawMaterials.py +46 -0
- mapFolding/someAssemblyRequired/_toolkitContainers.py +1 -1
- mapFolding/someAssemblyRequired/makeAllModules.py +192 -199
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +3 -3
- mapFolding/someAssemblyRequired/makeJobTheorem2codon.py +3 -3
- mapFolding/syntheticModules/algorithmA007822.py +166 -0
- mapFolding/syntheticModules/algorithmA007822Numba.py +95 -0
- mapFolding/syntheticModules/{countParallel.py → countParallelNumba.py} +5 -4
- mapFolding/syntheticModules/{daoOfMapFolding.py → daoOfMapFoldingNumba.py} +5 -4
- mapFolding/syntheticModules/dataPacking.py +4 -3
- mapFolding/syntheticModules/{initializeCount.py → initializeState.py} +1 -1
- mapFolding/syntheticModules/initializeStateA007822.py +69 -0
- mapFolding/syntheticModules/theorem2.py +2 -1
- mapFolding/syntheticModules/theorem2A007822.py +70 -0
- mapFolding/syntheticModules/theorem2A007822Numba.py +67 -0
- mapFolding/syntheticModules/theorem2A007822Trimmed.py +64 -0
- mapFolding/syntheticModules/theorem2Numba.py +6 -4
- mapFolding/syntheticModules/theorem2Trimmed.py +2 -1
- mapFolding/tests/test_computations.py +29 -4
- {mapfolding-0.14.1.dist-info → mapfolding-0.15.1.dist-info}/METADATA +2 -2
- mapfolding-0.15.1.dist-info/RECORD +86 -0
- mapfolding-0.14.1.dist-info/RECORD +0 -76
- {mapfolding-0.14.1.dist-info → mapfolding-0.15.1.dist-info}/WHEEL +0 -0
- {mapfolding-0.14.1.dist-info → mapfolding-0.15.1.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.14.1.dist-info → mapfolding-0.15.1.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.14.1.dist-info → mapfolding-0.15.1.dist-info}/top_level.txt +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
bitWidth = 1 << (
|
|
1
|
+
bifurcationAlphaLocator = 0x55555555555555555555555555555555
|
|
2
|
+
bitWidth = 1 << (bifurcationAlphaLocator.bit_length() - 1).bit_length()
|
|
3
3
|
|
|
4
4
|
def count(bridges: int, dictionaryCurveLocationsKnown: dict[int, int]) -> int:
|
|
5
5
|
while bridges > 0:
|
|
@@ -9,53 +9,53 @@ def count(bridges: int, dictionaryCurveLocationsKnown: dict[int, int]) -> int:
|
|
|
9
9
|
dictionaryCurveLocationsDiscovered: dict[int, int] = {}
|
|
10
10
|
|
|
11
11
|
for curveLocations, distinctCrossings in dictionaryCurveLocationsKnown.items():
|
|
12
|
-
global
|
|
12
|
+
global bifurcationAlphaLocator, bitWidth # noqa: PLW0603
|
|
13
13
|
|
|
14
|
-
if curveLocations >
|
|
15
|
-
while curveLocations >
|
|
16
|
-
|
|
14
|
+
if curveLocations > bifurcationAlphaLocator:
|
|
15
|
+
while curveLocations > bifurcationAlphaLocator:
|
|
16
|
+
bifurcationAlphaLocator |= bifurcationAlphaLocator << bitWidth
|
|
17
17
|
bitWidth <<= 1
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
bifurcationAlpha = curveLocations & bifurcationAlphaLocator
|
|
20
|
+
bifurcationZulu = (curveLocations ^ bifurcationAlpha) >> 1
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
bifurcationAlphaHasCurves = bifurcationAlpha != 1
|
|
23
|
+
bifurcationZuluHasCurves = bifurcationZulu != 1
|
|
24
|
+
bifurcationAlphaFinalZero = (bifurcationAlpha & 1) == 0
|
|
25
|
+
bifurcationZuluFinalZero = (bifurcationZulu & 1) == 0
|
|
26
26
|
|
|
27
|
-
if
|
|
28
|
-
curveLocationAnalysis = (
|
|
27
|
+
if bifurcationAlphaHasCurves:
|
|
28
|
+
curveLocationAnalysis = (bifurcationAlpha >> 2) | (bifurcationZulu << 3) | (bifurcationAlphaFinalZero << 1)
|
|
29
29
|
if curveLocationAnalysis < curveLocationsMAXIMUM:
|
|
30
30
|
dictionaryCurveLocationsDiscovered[curveLocationAnalysis] = dictionaryCurveLocationsDiscovered.get(curveLocationAnalysis, 0) + distinctCrossings
|
|
31
31
|
|
|
32
|
-
if
|
|
33
|
-
curveLocationAnalysis = (
|
|
32
|
+
if bifurcationZuluHasCurves:
|
|
33
|
+
curveLocationAnalysis = (bifurcationZulu >> 1) | ((bifurcationAlpha << 2) | bifurcationZuluFinalZero)
|
|
34
34
|
if curveLocationAnalysis < curveLocationsMAXIMUM:
|
|
35
35
|
dictionaryCurveLocationsDiscovered[curveLocationAnalysis] = dictionaryCurveLocationsDiscovered.get(curveLocationAnalysis, 0) + distinctCrossings
|
|
36
36
|
|
|
37
|
-
curveLocationAnalysis = ((
|
|
37
|
+
curveLocationAnalysis = ((bifurcationAlpha | (bifurcationZulu << 1)) << 2) | 3
|
|
38
38
|
if curveLocationAnalysis < curveLocationsMAXIMUM:
|
|
39
39
|
dictionaryCurveLocationsDiscovered[curveLocationAnalysis] = dictionaryCurveLocationsDiscovered.get(curveLocationAnalysis, 0) + distinctCrossings
|
|
40
40
|
|
|
41
|
-
if
|
|
42
|
-
if
|
|
41
|
+
if bifurcationAlphaHasCurves and bifurcationZuluHasCurves and (bifurcationAlphaFinalZero or bifurcationZuluFinalZero):
|
|
42
|
+
if bifurcationAlphaFinalZero and not bifurcationZuluFinalZero:
|
|
43
43
|
Z0Z_idk = 0
|
|
44
44
|
Z0Z_indexIDK = 1
|
|
45
45
|
while Z0Z_idk >= 0:
|
|
46
46
|
Z0Z_indexIDK <<= 2
|
|
47
|
-
Z0Z_idk += 1 if (
|
|
48
|
-
|
|
47
|
+
Z0Z_idk += 1 if (bifurcationAlpha & Z0Z_indexIDK) == 0 else -1
|
|
48
|
+
bifurcationAlpha ^= Z0Z_indexIDK
|
|
49
49
|
|
|
50
|
-
if
|
|
50
|
+
if bifurcationZuluFinalZero and not bifurcationAlphaFinalZero:
|
|
51
51
|
Z0Z_idk = 0
|
|
52
52
|
Z0Z_indexIDK = 1
|
|
53
53
|
while Z0Z_idk >= 0:
|
|
54
54
|
Z0Z_indexIDK <<= 2
|
|
55
|
-
Z0Z_idk += 1 if (
|
|
56
|
-
|
|
55
|
+
Z0Z_idk += 1 if (bifurcationZulu & Z0Z_indexIDK) == 0 else -1
|
|
56
|
+
bifurcationZulu ^= Z0Z_indexIDK
|
|
57
57
|
|
|
58
|
-
curveLocationAnalysis = (
|
|
58
|
+
curveLocationAnalysis = (bifurcationAlpha >> 2) | ((bifurcationZulu >> 2) << 1)
|
|
59
59
|
if curveLocationAnalysis < curveLocationsMAXIMUM:
|
|
60
60
|
dictionaryCurveLocationsDiscovered[curveLocationAnalysis] = dictionaryCurveLocationsDiscovered.get(curveLocationAnalysis, 0) + distinctCrossings
|
|
61
61
|
|
|
@@ -34,41 +34,41 @@ def count(bridges: int, curveLocationsKnown: dict[int, int]) -> int:
|
|
|
34
34
|
curveLocations = int(str(keyName).split(":")[1])
|
|
35
35
|
distinctCrossings = int(str(redisClient.get(keyName)))
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
bifurcationAlpha = curveLocations & 0x5555555555555555555555555555555555555555555555555555555555555555
|
|
38
|
+
bifurcationZulu = (curveLocations ^ bifurcationAlpha) >> 1
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
bifurcationAlphaHasCurves = bifurcationAlpha != 1
|
|
41
|
+
bifurcationZuluHasCurves = bifurcationZulu != 1
|
|
42
|
+
bifurcationAlphaFinalZero = not bifurcationAlpha & 1
|
|
43
|
+
bifurcationZuluFinalZero = not bifurcationZulu & 1
|
|
44
44
|
|
|
45
|
-
if
|
|
46
|
-
curveLocationAnalysis = (
|
|
45
|
+
if bifurcationAlphaHasCurves:
|
|
46
|
+
curveLocationAnalysis = (bifurcationAlpha >> 2) | (bifurcationZulu << 3) | (bifurcationAlphaFinalZero << 1)
|
|
47
47
|
storeCurveLocations(curveLocationAnalysis, distinctCrossings)
|
|
48
48
|
|
|
49
|
-
if
|
|
50
|
-
curveLocationAnalysis = (
|
|
49
|
+
if bifurcationZuluHasCurves:
|
|
50
|
+
curveLocationAnalysis = (bifurcationZulu >> 1) | (bifurcationAlpha << 2) | bifurcationZuluFinalZero
|
|
51
51
|
storeCurveLocations(curveLocationAnalysis, distinctCrossings)
|
|
52
52
|
|
|
53
|
-
curveLocationAnalysis = ((
|
|
53
|
+
curveLocationAnalysis = ((bifurcationAlpha | (bifurcationZulu << 1)) << 2) | 3
|
|
54
54
|
storeCurveLocations(curveLocationAnalysis, distinctCrossings)
|
|
55
55
|
|
|
56
|
-
if
|
|
56
|
+
if bifurcationAlphaHasCurves and bifurcationZuluHasCurves and (bifurcationAlphaFinalZero or bifurcationZuluFinalZero):
|
|
57
57
|
XOrHere2makePair = 0b1
|
|
58
58
|
findUnpairedBinary1 = 0
|
|
59
|
-
if
|
|
59
|
+
if bifurcationAlphaFinalZero and not bifurcationZuluFinalZero:
|
|
60
60
|
while findUnpairedBinary1 >= 0:
|
|
61
61
|
XOrHere2makePair <<= 2
|
|
62
|
-
findUnpairedBinary1 += 1 if (
|
|
63
|
-
|
|
62
|
+
findUnpairedBinary1 += 1 if (bifurcationAlpha & XOrHere2makePair) == 0 else -1
|
|
63
|
+
bifurcationAlpha ^= XOrHere2makePair
|
|
64
64
|
|
|
65
|
-
elif
|
|
65
|
+
elif bifurcationZuluFinalZero and not bifurcationAlphaFinalZero:
|
|
66
66
|
while findUnpairedBinary1 >= 0:
|
|
67
67
|
XOrHere2makePair <<= 2
|
|
68
|
-
findUnpairedBinary1 += 1 if (
|
|
69
|
-
|
|
68
|
+
findUnpairedBinary1 += 1 if (bifurcationZulu & XOrHere2makePair) == 0 else -1
|
|
69
|
+
bifurcationZulu ^= XOrHere2makePair
|
|
70
70
|
|
|
71
|
-
curveLocationAnalysis = (
|
|
71
|
+
curveLocationAnalysis = (bifurcationAlpha >> 2) | ((bifurcationZulu >> 2) << 1)
|
|
72
72
|
storeCurveLocations(curveLocationAnalysis, distinctCrossings)
|
|
73
73
|
|
|
74
74
|
# Move discovered data to known for next iteration
|
|
@@ -86,41 +86,41 @@ def recordAnalysis(bridges: int, curveLocationAnalysis: int, distinctCrossings:
|
|
|
86
86
|
bookkeeper.start()
|
|
87
87
|
|
|
88
88
|
def analyzeCurves(bridges: int, curveLocations: int, distinctCrossings: int) -> None:
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
bifurcationAlpha = curveLocations & 0x5555555555555555555555555555555555555555555555555555555555555555
|
|
90
|
+
bifurcationZulu = (curveLocations ^ bifurcationAlpha) >> 1
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
bifurcationAlphaHasCurves = bifurcationAlpha != 1
|
|
93
|
+
bifurcationZuluHasCurves = bifurcationZulu != 1
|
|
94
|
+
bifurcationAlphaFinalZero = not bifurcationAlpha & 1
|
|
95
|
+
bifurcationZuluFinalZero = not bifurcationZulu & 1
|
|
96
96
|
|
|
97
|
-
if
|
|
98
|
-
curveLocationAnalysis = (
|
|
97
|
+
if bifurcationAlphaHasCurves:
|
|
98
|
+
curveLocationAnalysis = (bifurcationAlpha >> 2) | (bifurcationZulu << 3) | (bifurcationAlphaFinalZero << 1)
|
|
99
99
|
recordAnalysis(bridges, curveLocationAnalysis, distinctCrossings)
|
|
100
100
|
|
|
101
|
-
if
|
|
102
|
-
curveLocationAnalysis = (
|
|
101
|
+
if bifurcationZuluHasCurves:
|
|
102
|
+
curveLocationAnalysis = (bifurcationZulu >> 1) | (bifurcationAlpha << 2) | bifurcationZuluFinalZero
|
|
103
103
|
recordAnalysis(bridges, curveLocationAnalysis, distinctCrossings)
|
|
104
104
|
|
|
105
|
-
curveLocationAnalysis = ((
|
|
105
|
+
curveLocationAnalysis = ((bifurcationAlpha | (bifurcationZulu << 1)) << 2) | 3
|
|
106
106
|
recordAnalysis(bridges, curveLocationAnalysis, distinctCrossings)
|
|
107
107
|
|
|
108
|
-
if
|
|
108
|
+
if bifurcationAlphaHasCurves and bifurcationZuluHasCurves and (bifurcationAlphaFinalZero or bifurcationZuluFinalZero):
|
|
109
109
|
XOrHere2makePair = 0b1
|
|
110
110
|
findUnpairedBinary1 = 0
|
|
111
|
-
if
|
|
111
|
+
if bifurcationAlphaFinalZero and not bifurcationZuluFinalZero:
|
|
112
112
|
while findUnpairedBinary1 >= 0:
|
|
113
113
|
XOrHere2makePair <<= 2
|
|
114
|
-
findUnpairedBinary1 += 1 if (
|
|
115
|
-
|
|
114
|
+
findUnpairedBinary1 += 1 if (bifurcationAlpha & XOrHere2makePair) == 0 else -1
|
|
115
|
+
bifurcationAlpha ^= XOrHere2makePair
|
|
116
116
|
|
|
117
|
-
elif
|
|
117
|
+
elif bifurcationZuluFinalZero and not bifurcationAlphaFinalZero:
|
|
118
118
|
while findUnpairedBinary1 >= 0:
|
|
119
119
|
XOrHere2makePair <<= 2
|
|
120
|
-
findUnpairedBinary1 += 1 if (
|
|
121
|
-
|
|
120
|
+
findUnpairedBinary1 += 1 if (bifurcationZulu & XOrHere2makePair) == 0 else -1
|
|
121
|
+
bifurcationZulu ^= XOrHere2makePair
|
|
122
122
|
|
|
123
|
-
curveLocationAnalysis = (
|
|
123
|
+
curveLocationAnalysis = (bifurcationAlpha >> 2) | ((bifurcationZulu >> 2) << 1)
|
|
124
124
|
recordAnalysis(bridges, curveLocationAnalysis, distinctCrossings)
|
|
125
125
|
|
|
126
126
|
def count(bridges: int, dictionaryCurveLocations: dict[int, int]) -> int:
|
mapFolding/reference/jaxCount.py
CHANGED
|
@@ -18,7 +18,7 @@ over other approaches and presented additional complexity. It serves as a valuab
|
|
|
18
18
|
for exploring alternative acceleration strategies and understanding the limitations of
|
|
19
19
|
different computational frameworks for this specific algorithm.
|
|
20
20
|
"""
|
|
21
|
-
from flattened import
|
|
21
|
+
from flattened import getLeavesTotal, makeConnectionGraph, validateListDimensions
|
|
22
22
|
from numpy.typing import NDArray
|
|
23
23
|
from typing import Any
|
|
24
24
|
import jax
|
|
@@ -21,45 +21,45 @@ def count(bridges: int, startingCurveLocations: dict[int, int]) -> int:
|
|
|
21
21
|
|
|
22
22
|
while bridges > 0:
|
|
23
23
|
bridges -= 1
|
|
24
|
-
curveLocationsMAXIMUM,
|
|
24
|
+
curveLocationsMAXIMUM, bifurcationZuluLocator, bifurcationAlphaLocator = curveMaximum[bridges]
|
|
25
25
|
|
|
26
26
|
for curveLocations, distinctCrossings in getCurveLocations().items():
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
bifurcationZulu = (curveLocations & bifurcationZuluLocator) >> 1
|
|
28
|
+
bifurcationAlpha = curveLocations & bifurcationAlphaLocator
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
bifurcationZuluFinalZero = (bifurcationZulu & 0b1) == 0
|
|
31
|
+
bifurcationZuluHasCurves = bifurcationZulu != 1
|
|
32
|
+
bifurcationAlphaFinalZero = (bifurcationAlpha & 0b1) == 0
|
|
33
|
+
bifurcationAlphaHasCurves = bifurcationAlpha != 1
|
|
34
34
|
|
|
35
|
-
if
|
|
36
|
-
curveLocationAnalysis = (
|
|
35
|
+
if bifurcationZuluHasCurves:
|
|
36
|
+
curveLocationAnalysis = (bifurcationZulu >> 1) | (bifurcationAlpha << 2) | bifurcationZuluFinalZero
|
|
37
37
|
recordAnalysis(curveLocationAnalysis, curveLocationsMAXIMUM, distinctCrossings)
|
|
38
38
|
|
|
39
|
-
if
|
|
40
|
-
curveLocationAnalysis = (
|
|
39
|
+
if bifurcationAlphaHasCurves:
|
|
40
|
+
curveLocationAnalysis = (bifurcationAlpha >> 2) | (bifurcationZulu << 3) | (bifurcationAlphaFinalZero << 1)
|
|
41
41
|
recordAnalysis(curveLocationAnalysis, curveLocationsMAXIMUM, distinctCrossings)
|
|
42
42
|
|
|
43
|
-
curveLocationAnalysis = ((
|
|
43
|
+
curveLocationAnalysis = ((bifurcationAlpha | (bifurcationZulu << 1)) << 2) | 3
|
|
44
44
|
recordAnalysis(curveLocationAnalysis, curveLocationsMAXIMUM, distinctCrossings)
|
|
45
45
|
|
|
46
|
-
if
|
|
46
|
+
if bifurcationZuluHasCurves and bifurcationAlphaHasCurves and (bifurcationZuluFinalZero or bifurcationAlphaFinalZero):
|
|
47
47
|
XOrHere2makePair = 0b1
|
|
48
48
|
findUnpairedBinary1 = 0
|
|
49
49
|
|
|
50
|
-
if
|
|
50
|
+
if bifurcationZuluFinalZero and not bifurcationAlphaFinalZero:
|
|
51
51
|
while findUnpairedBinary1 >= 0:
|
|
52
52
|
XOrHere2makePair <<= 2
|
|
53
|
-
findUnpairedBinary1 += 1 if (
|
|
54
|
-
|
|
53
|
+
findUnpairedBinary1 += 1 if (bifurcationZulu & XOrHere2makePair) == 0 else -1
|
|
54
|
+
bifurcationZulu ^= XOrHere2makePair
|
|
55
55
|
|
|
56
|
-
elif
|
|
56
|
+
elif bifurcationAlphaFinalZero and not bifurcationZuluFinalZero:
|
|
57
57
|
while findUnpairedBinary1 >= 0:
|
|
58
58
|
XOrHere2makePair <<= 2
|
|
59
|
-
findUnpairedBinary1 += 1 if (
|
|
60
|
-
|
|
59
|
+
findUnpairedBinary1 += 1 if (bifurcationAlpha & XOrHere2makePair) == 0 else -1
|
|
60
|
+
bifurcationAlpha ^= XOrHere2makePair
|
|
61
61
|
|
|
62
|
-
curveLocationAnalysis = ((
|
|
62
|
+
curveLocationAnalysis = ((bifurcationZulu >> 2) << 1) | (bifurcationAlpha >> 2)
|
|
63
63
|
recordAnalysis(curveLocationAnalysis, curveLocationsMAXIMUM, distinctCrossings)
|
|
64
64
|
|
|
65
65
|
return sum(getCurveLocations().values())
|
|
@@ -3,8 +3,8 @@ import sys
|
|
|
3
3
|
|
|
4
4
|
class limitLocators(NamedTuple):
|
|
5
5
|
curveLocationsMAXIMUM: int
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
bifurcationZuluLocator: int
|
|
7
|
+
bifurcationAlphaLocator: int
|
|
8
8
|
|
|
9
9
|
curveMaximum: dict[int, limitLocators] = {
|
|
10
10
|
0: limitLocators(16, 0x2a, 0x15),
|
|
@@ -75,8 +75,8 @@ def makeCurveMaximum() -> None:
|
|
|
75
75
|
sys.stdout.write("curveMaximum: dict[int, limitLocators] = {\n")
|
|
76
76
|
for n in range(62):
|
|
77
77
|
curveLocationsMAXIMUM = 1 << (2 * n + 4)
|
|
78
|
-
|
|
79
|
-
sys.stdout.write(f"{n}: limitLocators({curveLocationsMAXIMUM}, {hex(
|
|
78
|
+
bifurcationAlphaLocator = int('01' * ((curveLocationsMAXIMUM.bit_length() + 1) // 2), 2)
|
|
79
|
+
sys.stdout.write(f"{n}: limitLocators({curveLocationsMAXIMUM}, {hex(bifurcationAlphaLocator << 1)}, {hex(bifurcationAlphaLocator)}),\n")
|
|
80
80
|
sys.stdout.write("}\n")
|
|
81
81
|
|
|
82
82
|
if __name__ == '__main__':
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from mapFolding._oeisFormulas.matrixMeandersAnnex import curveMaximum as curveMaximum
|
|
2
|
+
from queue import Empty, SimpleQueue
|
|
3
|
+
from typing import NamedTuple
|
|
4
|
+
import contextlib
|
|
5
|
+
|
|
6
|
+
class BifurcatedCurves(NamedTuple):
|
|
7
|
+
bifurcationZulu: int
|
|
8
|
+
bifurcationAlpha: int
|
|
9
|
+
distinctCrossings: int
|
|
10
|
+
curveLocationsMAXIMUM: int
|
|
11
|
+
|
|
12
|
+
dictionaryCurveLocations: dict[int, int] = {}
|
|
13
|
+
simpleQueueCurveLocations: SimpleQueue[tuple[int, int]] = SimpleQueue()
|
|
14
|
+
|
|
15
|
+
def unpackQueue() -> dict[int, int]:
|
|
16
|
+
with contextlib.suppress(Empty):
|
|
17
|
+
while True:
|
|
18
|
+
curveLocations, distinctCrossings = simpleQueueCurveLocations.get_nowait()
|
|
19
|
+
dictionaryCurveLocations[curveLocations] = dictionaryCurveLocations.get(curveLocations, 0) + distinctCrossings
|
|
20
|
+
|
|
21
|
+
return dictionaryCurveLocations
|
|
22
|
+
|
|
23
|
+
def getCurveLocations(bridges: int) -> list[BifurcatedCurves]:
|
|
24
|
+
global dictionaryCurveLocations # noqa: PLW0603
|
|
25
|
+
dictionaryCurveLocations = unpackQueue()
|
|
26
|
+
curveLocationsMAXIMUM, bifurcationZuluLocator, bifurcationAlphaLocator = curveMaximum[bridges]
|
|
27
|
+
listBifurcatedCurves: list[BifurcatedCurves] = []
|
|
28
|
+
# TODO This is ready for concurrency and/or vectorization.
|
|
29
|
+
for curveLocations, distinctCrossings in dictionaryCurveLocations.items():
|
|
30
|
+
bifurcationZulu = (curveLocations & bifurcationZuluLocator) >> 1
|
|
31
|
+
bifurcationAlpha = (curveLocations & bifurcationAlphaLocator)
|
|
32
|
+
listBifurcatedCurves.append(BifurcatedCurves(bifurcationZulu, bifurcationAlpha, distinctCrossings, curveLocationsMAXIMUM))
|
|
33
|
+
dictionaryCurveLocations = {}
|
|
34
|
+
return listBifurcatedCurves
|
|
35
|
+
|
|
36
|
+
def recordAnalysis(curveLocationAnalysis: int, curveLocationsMAXIMUM: int, distinctCrossings: int) -> None:
|
|
37
|
+
if curveLocationAnalysis < curveLocationsMAXIMUM:
|
|
38
|
+
simpleQueueCurveLocations.put((curveLocationAnalysis, distinctCrossings))
|
|
39
|
+
|
|
40
|
+
def analyzeCurve(bifurcationZulu: int, bifurcationAlpha: int, distinctCrossings: int, curveLocationsMAXIMUM: int) -> None:
|
|
41
|
+
bifurcationZuluFinalZero = (bifurcationZulu & 0b1) == 0
|
|
42
|
+
bifurcationZuluHasCurves = bifurcationZulu != 1
|
|
43
|
+
bifurcationAlphaFinalZero = (bifurcationAlpha & 0b1) == 0
|
|
44
|
+
bifurcationAlphaHasCurves = bifurcationAlpha != 1
|
|
45
|
+
|
|
46
|
+
if bifurcationZuluHasCurves:
|
|
47
|
+
curveLocationAnalysis = (bifurcationZulu >> 1) | (bifurcationAlpha << 2) | bifurcationZuluFinalZero
|
|
48
|
+
recordAnalysis(curveLocationAnalysis, curveLocationsMAXIMUM, distinctCrossings)
|
|
49
|
+
|
|
50
|
+
if bifurcationAlphaHasCurves:
|
|
51
|
+
curveLocationAnalysis = (bifurcationAlpha >> 2) | (bifurcationZulu << 3) | (bifurcationAlphaFinalZero << 1)
|
|
52
|
+
recordAnalysis(curveLocationAnalysis, curveLocationsMAXIMUM, distinctCrossings)
|
|
53
|
+
|
|
54
|
+
curveLocationAnalysis = ((bifurcationAlpha | (bifurcationZulu << 1)) << 2) | 3
|
|
55
|
+
recordAnalysis(curveLocationAnalysis, curveLocationsMAXIMUM, distinctCrossings)
|
|
56
|
+
|
|
57
|
+
if bifurcationZuluHasCurves and bifurcationAlphaHasCurves and (bifurcationZuluFinalZero or bifurcationAlphaFinalZero):
|
|
58
|
+
XOrHere2makePair = 0b1
|
|
59
|
+
findUnpairedBinary1 = 0
|
|
60
|
+
|
|
61
|
+
if bifurcationZuluFinalZero and not bifurcationAlphaFinalZero:
|
|
62
|
+
while findUnpairedBinary1 >= 0:
|
|
63
|
+
XOrHere2makePair <<= 2
|
|
64
|
+
findUnpairedBinary1 += 1 if (bifurcationZulu & XOrHere2makePair) == 0 else -1
|
|
65
|
+
bifurcationZulu ^= XOrHere2makePair
|
|
66
|
+
|
|
67
|
+
elif bifurcationAlphaFinalZero and not bifurcationZuluFinalZero:
|
|
68
|
+
while findUnpairedBinary1 >= 0:
|
|
69
|
+
XOrHere2makePair <<= 2
|
|
70
|
+
findUnpairedBinary1 += 1 if (bifurcationAlpha & XOrHere2makePair) == 0 else -1
|
|
71
|
+
bifurcationAlpha ^= XOrHere2makePair
|
|
72
|
+
|
|
73
|
+
curveLocationAnalysis = ((bifurcationZulu >> 2) << 1) | (bifurcationAlpha >> 2)
|
|
74
|
+
recordAnalysis(curveLocationAnalysis, curveLocationsMAXIMUM, distinctCrossings)
|
|
75
|
+
|
|
76
|
+
def initializeCurveLocations(startingCurveLocations: dict[int, int]) -> None:
|
|
77
|
+
global dictionaryCurveLocations # noqa: PLW0603
|
|
78
|
+
dictionaryCurveLocations = startingCurveLocations.copy()
|
|
79
|
+
|
|
80
|
+
def count(bridges: int, startingCurveLocations: dict[int, int]) -> int:
|
|
81
|
+
initializeCurveLocations(startingCurveLocations)
|
|
82
|
+
|
|
83
|
+
while bridges > 0:
|
|
84
|
+
bridges -= 1
|
|
85
|
+
|
|
86
|
+
# TODO This could be parallelized when `recordAnalysis` is thread-safe
|
|
87
|
+
for bifurcatedCurve in getCurveLocations(bridges):
|
|
88
|
+
analyzeCurve(*bifurcatedCurve)
|
|
89
|
+
|
|
90
|
+
return getCurveLocations(bridges)[0].distinctCrossings
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
def count(bridges: int, startingCurveLocations: dict[int, int]) -> int:
|
|
2
|
+
listCurveMaximums: list[tuple[int, int, int]] = [
|
|
3
|
+
(16, 0x2a, 0x15),
|
|
4
|
+
(64, 0xaa, 0x55),
|
|
5
|
+
(256, 0x2aa, 0x155),
|
|
6
|
+
(1024, 0xaaa, 0x555),
|
|
7
|
+
(4096, 0x2aaa, 0x1555),
|
|
8
|
+
(16384, 0xaaaa, 0x5555),
|
|
9
|
+
(65536, 0x2aaaa, 0x15555),
|
|
10
|
+
(262144, 0xaaaaa, 0x55555),
|
|
11
|
+
(1048576, 0x2aaaaa, 0x155555),
|
|
12
|
+
(4194304, 0xaaaaaa, 0x555555),
|
|
13
|
+
(16777216, 0x2aaaaaa, 0x1555555),
|
|
14
|
+
(67108864, 0xaaaaaaa, 0x5555555),
|
|
15
|
+
(268435456, 0x2aaaaaaa, 0x15555555),
|
|
16
|
+
(1073741824, 0xaaaaaaaa, 0x55555555),
|
|
17
|
+
(4294967296, 0x2aaaaaaaa, 0x155555555),
|
|
18
|
+
(17179869184, 0xaaaaaaaaa, 0x555555555),
|
|
19
|
+
(68719476736, 0x2aaaaaaaaa, 0x1555555555),
|
|
20
|
+
(274877906944, 0xaaaaaaaaaa, 0x5555555555),
|
|
21
|
+
(1099511627776, 0x2aaaaaaaaaa, 0x15555555555),
|
|
22
|
+
(4398046511104, 0xaaaaaaaaaaa, 0x55555555555),
|
|
23
|
+
(17592186044416, 0x2aaaaaaaaaaa, 0x155555555555),
|
|
24
|
+
(70368744177664, 0xaaaaaaaaaaaa, 0x555555555555),
|
|
25
|
+
(281474976710656, 0x2aaaaaaaaaaaa, 0x1555555555555),
|
|
26
|
+
(1125899906842624, 0xaaaaaaaaaaaaa, 0x5555555555555),
|
|
27
|
+
(4503599627370496, 0x2aaaaaaaaaaaaa, 0x15555555555555),
|
|
28
|
+
(18014398509481984, 0xaaaaaaaaaaaaaa, 0x55555555555555),
|
|
29
|
+
(72057594037927936, 0x2aaaaaaaaaaaaaa, 0x155555555555555),
|
|
30
|
+
(288230376151711744, 0xaaaaaaaaaaaaaaa, 0x555555555555555),
|
|
31
|
+
(1152921504606846976, 0x2aaaaaaaaaaaaaaa, 0x1555555555555555), # 0x2aaaaaaaaaaaaaaa.bit_length() = 62
|
|
32
|
+
(4611686018427387904, 0xaaaaaaaaaaaaaaaa, 0x5555555555555555),
|
|
33
|
+
(18446744073709551616, 0x2aaaaaaaaaaaaaaaa, 0x15555555555555555),
|
|
34
|
+
(73786976294838206464, 0xaaaaaaaaaaaaaaaaa, 0x55555555555555555),
|
|
35
|
+
(295147905179352825856, 0x2aaaaaaaaaaaaaaaaa, 0x155555555555555555),
|
|
36
|
+
(1180591620717411303424, 0xaaaaaaaaaaaaaaaaaa, 0x555555555555555555),
|
|
37
|
+
(4722366482869645213696, 0x2aaaaaaaaaaaaaaaaaa, 0x1555555555555555555),
|
|
38
|
+
(18889465931478580854784, 0xaaaaaaaaaaaaaaaaaaa, 0x5555555555555555555),
|
|
39
|
+
(75557863725914323419136, 0x2aaaaaaaaaaaaaaaaaaa, 0x15555555555555555555),
|
|
40
|
+
(302231454903657293676544, 0xaaaaaaaaaaaaaaaaaaaa, 0x55555555555555555555),
|
|
41
|
+
(1208925819614629174706176, 0x2aaaaaaaaaaaaaaaaaaaa, 0x155555555555555555555),
|
|
42
|
+
(4835703278458516698824704, 0xaaaaaaaaaaaaaaaaaaaaa, 0x555555555555555555555),
|
|
43
|
+
(19342813113834066795298816, 0x2aaaaaaaaaaaaaaaaaaaaa, 0x1555555555555555555555),
|
|
44
|
+
(77371252455336267181195264, 0xaaaaaaaaaaaaaaaaaaaaaa, 0x5555555555555555555555),
|
|
45
|
+
(309485009821345068724781056, 0x2aaaaaaaaaaaaaaaaaaaaaa, 0x15555555555555555555555),
|
|
46
|
+
(1237940039285380274899124224, 0xaaaaaaaaaaaaaaaaaaaaaaa, 0x55555555555555555555555),
|
|
47
|
+
(4951760157141521099596496896, 0x2aaaaaaaaaaaaaaaaaaaaaaa, 0x155555555555555555555555),
|
|
48
|
+
(19807040628566084398385987584, 0xaaaaaaaaaaaaaaaaaaaaaaaa, 0x555555555555555555555555),
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
listCurveMaximums = listCurveMaximums[0:bridges]
|
|
52
|
+
dictionaryCurveLocations: dict[int, int] = {}
|
|
53
|
+
|
|
54
|
+
while bridges > 0:
|
|
55
|
+
bridges -= 1
|
|
56
|
+
|
|
57
|
+
curveLocationsMAXIMUM, bifurcationZuluLocator, bifurcationAlphaLocator = listCurveMaximums.pop()
|
|
58
|
+
|
|
59
|
+
for curveLocations, distinctCrossings in startingCurveLocations.items():
|
|
60
|
+
bifurcationZulu = (curveLocations & bifurcationZuluLocator) >> 1
|
|
61
|
+
bifurcationAlpha = (curveLocations & bifurcationAlphaLocator)
|
|
62
|
+
bifurcationZuluFinalZero = (bifurcationZulu & 0b1) == 0
|
|
63
|
+
bifurcationZuluHasCurves = bifurcationZulu != 1
|
|
64
|
+
bifurcationAlphaFinalZero = (bifurcationAlpha & 0b1) == 0
|
|
65
|
+
bifurcationAlphaHasCurves = bifurcationAlpha != 1
|
|
66
|
+
|
|
67
|
+
if bifurcationZuluHasCurves:
|
|
68
|
+
curveLocationAnalysis = (bifurcationZulu >> 1) | (bifurcationAlpha << 2) | bifurcationZuluFinalZero
|
|
69
|
+
if curveLocationAnalysis < curveLocationsMAXIMUM:
|
|
70
|
+
dictionaryCurveLocations[curveLocationAnalysis] = dictionaryCurveLocations.get(curveLocationAnalysis, 0) + distinctCrossings
|
|
71
|
+
|
|
72
|
+
if bifurcationAlphaHasCurves:
|
|
73
|
+
curveLocationAnalysis = (bifurcationAlpha >> 2) | (bifurcationZulu << 3) | (bifurcationAlphaFinalZero << 1)
|
|
74
|
+
if curveLocationAnalysis < curveLocationsMAXIMUM:
|
|
75
|
+
dictionaryCurveLocations[curveLocationAnalysis] = dictionaryCurveLocations.get(curveLocationAnalysis, 0) + distinctCrossings
|
|
76
|
+
|
|
77
|
+
curveLocationAnalysis = ((bifurcationAlpha | (bifurcationZulu << 1)) << 2) | 3
|
|
78
|
+
if curveLocationAnalysis < curveLocationsMAXIMUM:
|
|
79
|
+
dictionaryCurveLocations[curveLocationAnalysis] = dictionaryCurveLocations.get(curveLocationAnalysis, 0) + distinctCrossings
|
|
80
|
+
|
|
81
|
+
if bifurcationZuluHasCurves and bifurcationAlphaHasCurves and (bifurcationZuluFinalZero or bifurcationAlphaFinalZero):
|
|
82
|
+
XOrHere2makePair = 0b1
|
|
83
|
+
findUnpairedBinary1 = 0
|
|
84
|
+
|
|
85
|
+
if bifurcationZuluFinalZero and not bifurcationAlphaFinalZero:
|
|
86
|
+
while findUnpairedBinary1 >= 0:
|
|
87
|
+
XOrHere2makePair <<= 2
|
|
88
|
+
findUnpairedBinary1 += 1 if (bifurcationZulu & XOrHere2makePair) == 0 else -1
|
|
89
|
+
bifurcationZulu ^= XOrHere2makePair
|
|
90
|
+
|
|
91
|
+
elif bifurcationAlphaFinalZero and not bifurcationZuluFinalZero:
|
|
92
|
+
while findUnpairedBinary1 >= 0:
|
|
93
|
+
XOrHere2makePair <<= 2
|
|
94
|
+
findUnpairedBinary1 += 1 if (bifurcationAlpha & XOrHere2makePair) == 0 else -1
|
|
95
|
+
bifurcationAlpha ^= XOrHere2makePair
|
|
96
|
+
|
|
97
|
+
curveLocationAnalysis = ((bifurcationZulu >> 2) << 1) | (bifurcationAlpha >> 2)
|
|
98
|
+
if curveLocationAnalysis < curveLocationsMAXIMUM:
|
|
99
|
+
dictionaryCurveLocations[curveLocationAnalysis] = dictionaryCurveLocations.get(curveLocationAnalysis, 0) + distinctCrossings
|
|
100
|
+
|
|
101
|
+
startingCurveLocations = dictionaryCurveLocations.copy()
|
|
102
|
+
dictionaryCurveLocations = {}
|
|
103
|
+
|
|
104
|
+
return sum(startingCurveLocations.values())
|
|
@@ -18,8 +18,8 @@ structure can be creatively redesigned while maintaining the core computational
|
|
|
18
18
|
|
|
19
19
|
from mapFolding import outfitFoldings
|
|
20
20
|
from numba import njit
|
|
21
|
-
import numpy
|
|
22
21
|
from numpy.typing import NDArray
|
|
22
|
+
import numpy
|
|
23
23
|
|
|
24
24
|
"""
|
|
25
25
|
It is possible to enter the main `while` loop from an arbitrary point. This version is "rotated" to effectively enter at the modulo operator.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from astToolkit import extractFunctionDef # noqa: D100
|
|
2
|
+
from hunterMakesPy import raiseIfNone
|
|
3
|
+
from mapFolding.someAssemblyRequired.infoBooth import (
|
|
4
|
+
dataclassInstanceIdentifierDEFAULT, sourceCallableIdentifierDEFAULT, theCountingIdentifierDEFAULT)
|
|
5
|
+
import ast
|
|
6
|
+
|
|
7
|
+
Z0Z_identifier = 'filterAsymmetricFolds'
|
|
8
|
+
ImaString = f"""
|
|
9
|
+
def {Z0Z_identifier}(state: MapFoldingState) -> MapFoldingState:
|
|
10
|
+
state.indexLeaf = 0
|
|
11
|
+
leafConnectee = 0
|
|
12
|
+
while leafConnectee < state.leavesTotal + 1:
|
|
13
|
+
leafNumber = int(state.leafBelow[state.indexLeaf])
|
|
14
|
+
state.leafComparison[leafConnectee] = (leafNumber - state.indexLeaf + state.leavesTotal) % state.leavesTotal
|
|
15
|
+
state.indexLeaf = leafNumber
|
|
16
|
+
leafConnectee += 1
|
|
17
|
+
|
|
18
|
+
indexInMiddle = state.leavesTotal // 2
|
|
19
|
+
state.indexMiniGap = 0
|
|
20
|
+
while state.indexMiniGap < state.leavesTotal + 1:
|
|
21
|
+
ImaSymmetricFold = True
|
|
22
|
+
leafConnectee = 0
|
|
23
|
+
while leafConnectee < indexInMiddle:
|
|
24
|
+
if state.leafComparison[(state.indexMiniGap + leafConnectee) % (state.leavesTotal + 1)] != state.leafComparison[(state.indexMiniGap + state.leavesTotal + 1 - 2 - leafConnectee) % (state.leavesTotal + 1)]:
|
|
25
|
+
ImaSymmetricFold = False
|
|
26
|
+
break
|
|
27
|
+
leafConnectee += 1
|
|
28
|
+
if ImaSymmetricFold:
|
|
29
|
+
state.groupsOfFolds += 1
|
|
30
|
+
state.indexMiniGap += 1
|
|
31
|
+
|
|
32
|
+
return state
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
FunctionDef_filterAsymmetricFolds: ast.FunctionDef = raiseIfNone(extractFunctionDef(ast.parse(ImaString), Z0Z_identifier))
|
|
36
|
+
del ImaString
|
|
37
|
+
|
|
38
|
+
ImaString = f"{dataclassInstanceIdentifierDEFAULT} = {Z0Z_identifier}({dataclassInstanceIdentifierDEFAULT})"
|
|
39
|
+
Z0Z_incrementCount = ast.parse(ImaString).body[0]
|
|
40
|
+
del ImaString
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
ImaString = 'state.groupsOfFolds = (state.groupsOfFolds + 1) // 2'
|
|
44
|
+
Z0Z_adjustFoldsTotal = ast.parse(ImaString).body[0]
|
|
45
|
+
del ImaString
|
|
46
|
+
|
|
@@ -232,7 +232,7 @@ class DeReConstructField2ast:
|
|
|
232
232
|
self.ledger.addImportFrom_asStr(moduleWithLogicalPath, 'dtype')
|
|
233
233
|
axesSubscript = Make.Subscript(Make.Name('tuple'), Make.Name('uint8'))
|
|
234
234
|
dtype_asnameName: ast.Name = self.astAnnotation
|
|
235
|
-
if dtype_asnameName.id == '
|
|
235
|
+
if dtype_asnameName.id == 'Array3DLeavesTotal':
|
|
236
236
|
axesSubscript = Make.Subscript(Make.Name('tuple'), Make.Tuple([Make.Name('uint8'), Make.Name('uint8'), Make.Name('uint8')]))
|
|
237
237
|
ast_expr = Make.Subscript(Make.Name(annotationType), Make.Tuple([axesSubscript, Make.Subscript(Make.Name('dtype'), dtype_asnameName)]))
|
|
238
238
|
constructor = 'array'
|