mapFolding 0.17.0__py3-none-any.whl → 0.17.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.
- easyRun/NOTcountingFolds.py +16 -6
- easyRun/__init__.py +1 -0
- easyRun/countFolds.py +12 -5
- easyRun/eliminateFolds.py +60 -0
- mapFolding/__init__.py +2 -1
- mapFolding/_theTypes.py +0 -1
- mapFolding/algorithms/A086345.py +8 -3
- mapFolding/algorithms/__init__.py +1 -1
- mapFolding/algorithms/constraintPropagation.py +184 -0
- mapFolding/algorithms/elimination.py +131 -0
- mapFolding/algorithms/eliminationCount.py +26 -0
- mapFolding/algorithms/eliminationPinned.py +35 -0
- mapFolding/algorithms/iff.py +206 -0
- mapFolding/algorithms/patternFinder.py +280 -0
- mapFolding/algorithms/pinning2Dn.py +345 -0
- mapFolding/algorithms/pinning2DnAnnex.py +43 -0
- mapFolding/basecamp.py +72 -18
- mapFolding/beDRY.py +14 -1
- mapFolding/dataBaskets.py +56 -0
- mapFolding/someAssemblyRequired/transformationTools.py +1 -1
- mapFolding/tests/conftest.py +1 -1
- mapFolding/tests/test_computations.py +17 -26
- mapFolding/tests/verify.py +323 -0
- {mapfolding-0.17.0.dist-info → mapfolding-0.17.1.dist-info}/METADATA +6 -3
- {mapfolding-0.17.0.dist-info → mapfolding-0.17.1.dist-info}/RECORD +29 -24
- easyRun/A000682.py +0 -25
- easyRun/A005316.py +0 -20
- mapFolding/algorithms/A000136constraintPropagation.py +0 -95
- mapFolding/algorithms/A000136elimination.py +0 -163
- mapFolding/algorithms/A000136eliminationParallel.py +0 -77
- {mapfolding-0.17.0.dist-info → mapfolding-0.17.1.dist-info}/WHEEL +0 -0
- {mapfolding-0.17.0.dist-info → mapfolding-0.17.1.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.17.0.dist-info → mapfolding-0.17.1.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.17.0.dist-info → mapfolding-0.17.1.dist-info}/top_level.txt +0 -0
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
from itertools import permutations, starmap
|
|
2
|
-
from typing import Final
|
|
3
|
-
|
|
4
|
-
def isThisValid(folding: tuple[int, ...]) -> bool:
|
|
5
|
-
"""Verify that a folding sequence is possible.
|
|
6
|
-
|
|
7
|
-
Parameters
|
|
8
|
-
----------
|
|
9
|
-
folding : list[int]
|
|
10
|
-
List of integers representing the folding sequence.
|
|
11
|
-
|
|
12
|
-
Returns
|
|
13
|
-
-------
|
|
14
|
-
valid : bool
|
|
15
|
-
True if the folding sequence is valid, False otherwise.
|
|
16
|
-
|
|
17
|
-
Notes
|
|
18
|
-
-----
|
|
19
|
-
All 8 forbidden forms
|
|
20
|
-
[k, r, k+1, r+1] [r, k+1, r+1, k] [k+1, r+1, k, r] [r+1, k, r, k+1]
|
|
21
|
-
[r, k, r+1, k+1] [k, r+1, k+1, r] [r+1, k+1, r, k] [k+1, r, k, r+1]
|
|
22
|
-
|
|
23
|
-
I selected the four forms in which k precedes r. Because of the flow, I _think_ that is why these four are sufficient.
|
|
24
|
-
|
|
25
|
-
Citation
|
|
26
|
-
--------
|
|
27
|
-
John E. Koehler, Folding a strip of stamps, Journal of Combinatorial Theory, Volume 5, Issue 2, 1968, Pages 135-152, ISSN
|
|
28
|
-
0021-9800, https://doi.org/10.1016/S0021-9800(68)80048-1.
|
|
29
|
-
(https://www.sciencedirect.com/science/article/pii/S0021980068800481)
|
|
30
|
-
|
|
31
|
-
See Also
|
|
32
|
-
--------
|
|
33
|
-
- "[Annotated, corrected, scanned copy]" at https://oeis.org/A001011.
|
|
34
|
-
- Citation in BibTeX format "citations/KOEHLER1968135.bib".
|
|
35
|
-
"""
|
|
36
|
-
leavesTotal: int = len(folding)
|
|
37
|
-
for index, leaf in enumerate(folding[0:-1]): # `[0:-1]` No room to interpose
|
|
38
|
-
if leaf == leavesTotal:
|
|
39
|
-
continue
|
|
40
|
-
indexLeafRightSide: int = folding.index(leaf+1)
|
|
41
|
-
leafIsOdd: int = leaf & 1
|
|
42
|
-
|
|
43
|
-
for indexInterposer, interposer in enumerate(folding[index + 1:None], start=index + 1): # [k != r]
|
|
44
|
-
if leafIsOdd != (interposer & 1): # [k%2 == r%2]
|
|
45
|
-
continue
|
|
46
|
-
if interposer == leavesTotal:
|
|
47
|
-
continue
|
|
48
|
-
|
|
49
|
-
indexInterposerRightSide: int = folding.index(interposer + 1)
|
|
50
|
-
|
|
51
|
-
if (index < indexInterposer < indexLeafRightSide < indexInterposerRightSide # [k, r, k+1, r+1]
|
|
52
|
-
or index < indexInterposerRightSide < indexLeafRightSide < indexInterposer # [k, r+1, k+1, r]
|
|
53
|
-
or indexLeafRightSide < indexInterposerRightSide < index < indexInterposer # [k+1, r+1, k, r]
|
|
54
|
-
or indexInterposerRightSide < index < indexInterposer < indexLeafRightSide # [r+1, k, r, k+1]
|
|
55
|
-
):
|
|
56
|
-
return False
|
|
57
|
-
return True
|
|
58
|
-
|
|
59
|
-
def count(prefix: list[int], permutands: list[int], postfix: list[int]) -> int:
|
|
60
|
-
"""Count the number of valid foldings for a given fixed start and remaining leaves.
|
|
61
|
-
|
|
62
|
-
Parameters
|
|
63
|
-
----------
|
|
64
|
-
prefix : list[int]
|
|
65
|
-
List of integers representing the fixed start of the folding sequence.
|
|
66
|
-
permutands : list[int]
|
|
67
|
-
List of elements to permute into permutations.
|
|
68
|
-
postfix : list[int]
|
|
69
|
-
List of integers representing the fixed end of the folding sequence.
|
|
70
|
-
|
|
71
|
-
Returns
|
|
72
|
-
-------
|
|
73
|
-
groupsOfFolds : int
|
|
74
|
-
Number of valid foldings, which each represent a group of folds, for the given configuration.
|
|
75
|
-
"""
|
|
76
|
-
groupsOfFolds: int = 0
|
|
77
|
-
for aPermutation in permutations(permutands):
|
|
78
|
-
groupsOfFolds += isThisValid((*prefix, *aPermutation, *postfix))
|
|
79
|
-
return groupsOfFolds
|
|
80
|
-
|
|
81
|
-
def staging(prefix: list[int], permutands: list[int]) -> int:
|
|
82
|
-
"""Segregate sequences with a final `2`: necessary as part of excluding leading `1,2`.
|
|
83
|
-
|
|
84
|
-
Parameters
|
|
85
|
-
----------
|
|
86
|
-
prefix : list[int]
|
|
87
|
-
List of integers representing the fixed start of the folding sequence.
|
|
88
|
-
permutands : list[int]
|
|
89
|
-
List of elements to permute into permutations.
|
|
90
|
-
|
|
91
|
-
Notes
|
|
92
|
-
-----
|
|
93
|
-
Transformation indices:
|
|
94
|
-
|
|
95
|
-
1,3,4,5,6,2,
|
|
96
|
-
1,2,6,5,4,3,
|
|
97
|
-
|
|
98
|
-
All valid sequences that end with '2' are in the first half.
|
|
99
|
-
All valid sequences that start with '1,2' are in the second half.
|
|
100
|
-
The remaining valid sequences are evenly split between the two halves.
|
|
101
|
-
Therefore:
|
|
102
|
-
1. Filter out all '1,2' before checking validity.
|
|
103
|
-
2. If a valid sequence ends in '2', add 2 to the total count.
|
|
104
|
-
3. If a valid sequence does not end in '2', add 1 to the total count.
|
|
105
|
-
|
|
106
|
-
`leaf = leavesTotal` is evenly distributed in each half like this: (ex. from A007822(7))
|
|
107
|
-
^1,14, ,14,$ 612
|
|
108
|
-
,14,$ ^1,14, 1486
|
|
109
|
-
"""
|
|
110
|
-
groupsOfFolds: int = 0
|
|
111
|
-
postfix: list[int] = []
|
|
112
|
-
if 2 in permutands:
|
|
113
|
-
postfix.append(2)
|
|
114
|
-
postfixComplement: list[int] = permutands.copy()
|
|
115
|
-
postfixComplement.remove(2)
|
|
116
|
-
groupsOfFolds += count(prefix, postfixComplement, postfix) * 2
|
|
117
|
-
for leafPostfix in postfixComplement:
|
|
118
|
-
groupsOfFolds += count(prefix, [leaf for leaf in permutands if leaf != leafPostfix], [leafPostfix])
|
|
119
|
-
else:
|
|
120
|
-
groupsOfFolds += count(prefix, permutands, postfix)
|
|
121
|
-
return groupsOfFolds
|
|
122
|
-
|
|
123
|
-
def doTheNeedful(n: int) -> int:
|
|
124
|
-
"""Count the number of valid foldings for a given number of leaves."""
|
|
125
|
-
leavesTotal: Final[int] = n
|
|
126
|
-
listToPermute: list[tuple[list[int], list[int]]] = []
|
|
127
|
-
|
|
128
|
-
prefix: list[int] = [1]
|
|
129
|
-
listLeaves: Final[list[int]] = list(range(leavesTotal, 1, -1))
|
|
130
|
-
|
|
131
|
-
permutands: list[int] = listLeaves.copy()
|
|
132
|
-
|
|
133
|
-
# ------- Exclude leading 2 -------------------------------
|
|
134
|
-
# NOTE 1,{3..n},{2..n}...
|
|
135
|
-
excludeLeading2: list[int] = permutands.copy()
|
|
136
|
-
excludeLeading2.remove(2)
|
|
137
|
-
listToPermute.extend([([*prefix, leafPrefix], [leaf for leaf in permutands if leaf != leafPrefix]) for leafPrefix in excludeLeading2])
|
|
138
|
-
del excludeLeading2
|
|
139
|
-
|
|
140
|
-
# ------- Exclude interposed 2 ----------------------------
|
|
141
|
-
# NOTE 1,{3..n},{3..n},{2..n}...
|
|
142
|
-
# NOTE 1,{n,if n&1},{2..n-1}...
|
|
143
|
-
for aTuple in listToPermute.copy():
|
|
144
|
-
if len(aTuple[0]) != 2 or leavesTotal < 4:
|
|
145
|
-
continue
|
|
146
|
-
interposer: int = aTuple[0][1]
|
|
147
|
-
excludeInterposed2: list[int] = permutands.copy()
|
|
148
|
-
excludeInterposed2.remove(2)
|
|
149
|
-
excludeInterposed2.remove(interposer)
|
|
150
|
-
if interposer == leavesTotal and interposer & 1:
|
|
151
|
-
listToPermute.append(([*aTuple[0], 2], excludeInterposed2))
|
|
152
|
-
listToPermute.extend([([*aTuple[0], leafPrefix], [leaf for leaf in permutands if leaf not in (leafPrefix, interposer)]) for leafPrefix in excludeInterposed2])
|
|
153
|
-
listToPermute.remove(aTuple)
|
|
154
|
-
del aTuple, excludeInterposed2, interposer
|
|
155
|
-
|
|
156
|
-
return sum(starmap(staging, listToPermute)) * leavesTotal
|
|
157
|
-
|
|
158
|
-
# ------- Exclude interposed 3 ----------------------------
|
|
159
|
-
# NOTE 1,{3..n},{3..n},{2..n}...,{3..n}
|
|
160
|
-
# NOTE 1,{3..n},{3..n},{3..n}...,{4..n},{3..n},{2}
|
|
161
|
-
# NOTE 1,{3..n-1},...,{n,if ~n&1},{2}
|
|
162
|
-
# NOTE 1,{n,if n&1},{2..n-1}...
|
|
163
|
-
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
from concurrent.futures import Future, ProcessPoolExecutor
|
|
2
|
-
from itertools import permutations
|
|
3
|
-
|
|
4
|
-
def isThisValid(folding: list[int]) -> bool:
|
|
5
|
-
"""Verify that a folding sequence is possible.
|
|
6
|
-
|
|
7
|
-
Parameters
|
|
8
|
-
----------
|
|
9
|
-
folding : list[int]
|
|
10
|
-
List of integers representing the folding sequence.
|
|
11
|
-
|
|
12
|
-
Returns
|
|
13
|
-
-------
|
|
14
|
-
valid : bool
|
|
15
|
-
True if the folding sequence is valid, False otherwise.
|
|
16
|
-
"""
|
|
17
|
-
leavesTotal: int = len(folding)
|
|
18
|
-
for index, leaf in enumerate(folding[0:-1]): # Last leaf cannot interpose
|
|
19
|
-
if leaf == leavesTotal:
|
|
20
|
-
continue
|
|
21
|
-
indexLeafRightSide: int = folding.index(leaf+1)
|
|
22
|
-
leafIsOdd: int = leaf & 1
|
|
23
|
-
|
|
24
|
-
for indexInterposer, interposer in enumerate(folding[index + 1:None], start=index + 1): # [k != r]
|
|
25
|
-
if leafIsOdd != (interposer & 1): # [k%2 == r%2]
|
|
26
|
-
continue
|
|
27
|
-
if interposer == leavesTotal:
|
|
28
|
-
continue
|
|
29
|
-
|
|
30
|
-
indexInterposerRightSide: int = folding.index(interposer + 1)
|
|
31
|
-
|
|
32
|
-
if (index < indexInterposer < indexLeafRightSide < indexInterposerRightSide # [k, r, k+1, r+1]
|
|
33
|
-
or index < indexInterposerRightSide < indexLeafRightSide < indexInterposer # [k, r+1, k+1, r]
|
|
34
|
-
or indexLeafRightSide < indexInterposerRightSide < index < indexInterposer # [k+1, r+1, k, r]
|
|
35
|
-
or indexInterposerRightSide < index < indexInterposer < indexLeafRightSide # [r+1, k, r, k+1]
|
|
36
|
-
):
|
|
37
|
-
return False
|
|
38
|
-
return True
|
|
39
|
-
|
|
40
|
-
def count(fixed: list[int], permutands: list[int]) -> int:
|
|
41
|
-
"""Count the number of valid foldings for a given fixed start and remaining leaves.
|
|
42
|
-
|
|
43
|
-
Parameters
|
|
44
|
-
----------
|
|
45
|
-
fixed : list[int]
|
|
46
|
-
List of integers representing the fixed start of the folding sequence.
|
|
47
|
-
permutands : list[int]
|
|
48
|
-
List of elements to permute into permutations.
|
|
49
|
-
"""
|
|
50
|
-
validTotal: int = 0
|
|
51
|
-
for aPermutation in permutations(permutands):
|
|
52
|
-
validTotal += isThisValid([*fixed, *aPermutation])
|
|
53
|
-
return validTotal
|
|
54
|
-
|
|
55
|
-
def doTheNeedful(n: int, processesMaximum: int) -> int:
|
|
56
|
-
"""Count the number of valid foldings for a given number of leaves."""
|
|
57
|
-
validTotal: int = 0
|
|
58
|
-
listLeavesTruncated: list[int] = list(range(2, n + 1))
|
|
59
|
-
# NOTE Design goals:
|
|
60
|
-
# Minimize creation/destruction of processes.
|
|
61
|
-
# Use all processes until the end.
|
|
62
|
-
# A valid sequence takes many times more cycles to process than a sequence that is proved invalid in the first few elements.
|
|
63
|
-
# So, dividing purely on the number of sequences is not optimal.
|
|
64
|
-
# Prefer generators of lists over lists of lists.
|
|
65
|
-
|
|
66
|
-
# In the current system, each `Future` leads to a returned value, which is then summed. But, I don't care about any specific
|
|
67
|
-
# `Future`. I would rather have the processes "consume" work from a common well and return their results when the work is done.
|
|
68
|
-
workers: int = min(processesMaximum, n - 1)
|
|
69
|
-
with ProcessPoolExecutor(max_workers=workers) as processPool:
|
|
70
|
-
listFutures: list[Future[int]] = []
|
|
71
|
-
for index in range(len(listLeavesTruncated)):
|
|
72
|
-
permutands: list[int] = listLeavesTruncated.copy()
|
|
73
|
-
fixedLeaves: list[int] = [1, permutands.pop(index)]
|
|
74
|
-
listFutures.append(processPool.submit(count, fixedLeaves, permutands))
|
|
75
|
-
for futureCount in listFutures:
|
|
76
|
-
validTotal += futureCount.result()
|
|
77
|
-
return validTotal * n
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|