Skip to content

Commit 76f3ac1

Browse files
committed
Make rearrange_lp_sol.py check all conditions by itself without simple_check.py .
1 parent 52fcded commit 76f3ac1

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/rearrange/README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,22 @@ sys 0m0.074s
108108

109109
* `rearrange_lp_sol.py` helps verify the lower bound produced by the
110110
`lp_solve` output of a program produced by the previous program. It
111-
checks some of the smoothness conditions, but otherwise outputs a
112-
file that can be checked by `simple_check.py`. For example:
111+
checks all of the rearrangement conditions, so if it succeeds, the
112+
input is verified. Optionally, it is also possible to output a file
113+
that can be checked by `simple_check.py`. For example:
113114

114115
```
115-
erdos-guy-selfridge$ time python3 src/rearrange/rearrange_lp.py --ilp 7 50000 14530 | lp_solve | python3 src/rearrange/rearrange_lp_sol.py 7 50000 14530 | python3 src/python/verification/simple_check.py
116+
erdos-guy-selfridge$ time python3 src/rearrange/rearrange_lp.py --ilp 7 50000 14530 | lp_solve | python3 src/rearrange/rearrange_lp_sol.py 7 50000 14530
117+
7 50000 14530
118+
119+
real 0m2.736s
120+
user 0m2.001s
121+
sys 0m0.099s
122+
123+
erdos-guy-selfridge$ time python3 src/rearrange/rearrange_lp.py --ilp 7 50000 14530 | lp_solve | python3 src/rearrange/rearrange_lp_sol.py --simple_check 7 50000 14530 | python3 src/python/verification/simple_check.py
116124
50000 50000 14530
117125
118-
real 0m8.050s
119-
user 0m5.187s
120-
sys 0m0.125s
126+
real 0m6.608s
127+
user 0m5.149s
128+
sys 0m0.117s
121129
```

src/rearrange/rearrange_lp_sol.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from sympy import primerange
33
import sys
44

5-
def main(P: int, N: int, T: int):
5+
def main(P: int, N: int, T: int, simple_check: bool = False):
66
primes = list(primerange(2, P+1))
7+
budget = {p: 0 for p in primes}
78

89
divided_factors = []
910
for i in range(1, N+1):
@@ -12,6 +13,7 @@ def main(P: int, N: int, T: int):
1213
for p in primes:
1314
while (t % p) == 0:
1415
t //= p
16+
budget[p] += 1
1517
divided_factors.append(t)
1618

1719
divided_factors.sort()
@@ -30,22 +32,32 @@ def main(P: int, N: int, T: int):
3032
multiply_factors = []
3133
for line in sys.stdin:
3234
variable, value = line.split()
33-
value = int(value)
3435
assert variable.startswith("a")
3536
n = int(variable[1:])
37+
value = int(value)
3638
t = n
3739
for p in primes:
3840
while (t % p) == 0:
3941
t //= p
42+
budget[p] -= value
4043
assert t == 1, f"Variable {variable} which corresponds to n={n} was not {P}-smooth!"
4144
for i in range(value):
4245
multiply_factors.append(n)
4346

47+
# Check prime budgets
48+
for p in primes:
49+
assert budget[p] >= 0, "Prime budget exhausted for prime {p}."
50+
4451
assert len(divided_factors) == len(multiply_factors), f"Unexpected number of factors."
4552
factors = [divided_factor * multiply_factor for divided_factor, multiply_factor in zip(divided_factors, multiply_factors)]
46-
print(N, N, T)
4753
for factor in factors:
48-
print(factor)
54+
assert factor >= T, f"The resulting factor {factor} should have been at least {T}."
55+
if simple_check:
56+
print(N, N, T)
57+
for factor in factors:
58+
print(factor)
59+
else:
60+
print(P, N, T)
4961

5062
if __name__ == '__main__':
5163
import argparse
@@ -56,11 +68,12 @@ def main(P: int, N: int, T: int):
5668
parser.add_argument('P', type=int)
5769
parser.add_argument('N', type=int)
5870
parser.add_argument('T', type=int, nargs='?', default=0)
71+
parser.add_argument('--simple_check', action='store_true', help='Output file for simple_check.py to check.')
5972

6073
args = parser.parse_args()
6174

6275
P = args.P
6376
N = args.N
6477
T = args.T or math.ceil(N/4)
6578

66-
main(P, N, T)
79+
main(P, N, T, args.simple_check)

0 commit comments

Comments
 (0)