Last active
May 9, 2017 23:02
-
-
Save psqq/8fd909602438a112bac6b12e90113105 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, subprocess | |
from tqdm import tqdm | |
N_semigroups = [1, 1, 4, 18, 126, 1160, 15973, 836021, 1843120128] | |
N_semilattices = [1, 1, 1, 2, 5, 15, 53, 222, 1078] | |
template = """ | |
LoadPackage("smallsemi");; | |
n := {n};; | |
for k in [{a}..{b}] do | |
m := RecoverMultiplicationTable(n, k);; | |
l := List(m, row -> JoinStringsWithSeparator(row, ""));; | |
Print(JoinStringsWithSeparator(l, "")); | |
Print("\\n"); | |
od; | |
quit;; | |
""" | |
def is_semilattice(n, line): | |
for x in range(n): | |
if int(line[n*x + x]) != (x + 1): | |
return False | |
for x in range(n): | |
for y in range(n): | |
if line[n*x + y] != line[n*y + x]: | |
return False | |
return True | |
def make_iter_of_semigroups(n, a, b): | |
print("-"*50) | |
script_fn = "script_of_main_py.txt" | |
gap_code = template.format(n=n, a=a, b=b) | |
with open(script_fn, "w") as f: | |
f.write(gap_code) | |
print(script_fn + ":") | |
print(gap_code) | |
cmd = "cat {script_fn} | ./gap.sh -q".format(script_fn=script_fn) | |
print("cmd:", cmd) | |
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) | |
print("-"*50) | |
return iter(process.stdout.readline, b'') | |
def go(n, only_semilattices=False, start_a=None, progbar=True, islog=False): | |
print("-"*50) | |
only_semilattices = bool(only_semilattices) | |
print("only_semilattices:", only_semilattices) | |
l = N_semigroups[n] | |
a, b = 1, l | |
if start_a is not None: | |
a = start_a | |
print("a, b, l:", a, b, l) | |
i, j = a-1, 0 # i -- количество найденых полугрупп, j -- количество найденых полурешеток | |
t = "" | |
if only_semilattices: | |
t = "_semilattices" | |
output_fn = "{}_{:010}_{:010}{}.txt".format(n, a, b, t) | |
output_file = open(output_fn, "w") | |
print("output_fn:", output_fn) | |
print("-"*50) | |
if progbar: | |
pbar = tqdm(total=l) | |
pbar.update(i) | |
while True: | |
a = i+1 | |
for line in make_iter_of_semigroups(n, a, b): | |
line = line.strip().decode() | |
if not line.isdigit(): | |
continue | |
if progbar: | |
pbar.update(1) | |
i += 1 | |
if only_semilattices: | |
flag = is_semilattice(n, line) | |
if islog: | |
print(line, flag) | |
if not flag: | |
continue | |
j += 1 | |
output_file.write(line) | |
if i == l: | |
break | |
if progbar: | |
pbar.close() | |
output_file.close() | |
print("-"*50) | |
print("The End:", (n, a, b), (l, i, j)) | |
print("-"*50) | |
args = sys.argv[1:] | |
go(*map(int, args)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment