Добавили белый список для построения полного вывода
This commit is contained in:
@@ -36,14 +36,22 @@ def function_values_to_number(values):
|
||||
return res
|
||||
|
||||
|
||||
def count_lens(args_count):
|
||||
def count_lens(args_count, white_map_path):
|
||||
bit_counts = bytes(bin(x).count("1") for x in range(256))
|
||||
len_to_count = {}
|
||||
white_map = None
|
||||
if white_map_path:
|
||||
white_map = open(white_map_path, "rb").read()
|
||||
print(f"Total whitelisted functions: {sum(map(lambda x: bit_counts[x], white_map))}")
|
||||
for rank_ind in range(1, 10):
|
||||
file_object = get_rank_file_object(args_count, rank_ind)
|
||||
if not file_object:
|
||||
break
|
||||
len_to_count[rank_ind] = sum(map(lambda x: bit_counts[x], file_object.read()))
|
||||
src_data = file_object.read()
|
||||
if white_map:
|
||||
assert len(src_data) == len(white_map)
|
||||
src_data = bytes(x & y for x,y in zip(src_data, white_map))
|
||||
len_to_count[rank_ind] = sum(map(lambda x: bit_counts[x], src_data))
|
||||
total = sum(len_to_count.values())
|
||||
for rank_ind, count in len_to_count.items():
|
||||
print("len {} count {} share {}".format(rank_ind, count, 1.0 * count / total))
|
||||
@@ -62,7 +70,7 @@ def get_function_len(args_count, function_number):
|
||||
|
||||
|
||||
def count_symmetricals(args_count):
|
||||
func_strings = list(open("./build/functions_strings.txt").read().split("\n")[:-1])
|
||||
func_strings = list(open(f"./build/functions_strings_{args_count}.txt").read().split("\n")[:-1])
|
||||
print(f"Total {len(func_strings)} representations")
|
||||
functions_to_check = set()
|
||||
for layer_values in itertools.product([0, 1], repeat=args_count + 1):
|
||||
@@ -81,21 +89,11 @@ def count_symmetricals(args_count):
|
||||
if rank not in function_ranks:
|
||||
function_ranks[rank] = []
|
||||
function_ranks[rank].append(fn)
|
||||
"""
|
||||
for rank_ind in range(1, 10):
|
||||
if not functions_to_check:
|
||||
break
|
||||
file_object = get_rank_file_object(args_count, rank_ind)
|
||||
if not file_object:
|
||||
break
|
||||
function_ranks[rank_ind] = []
|
||||
for fn in list(functions_to_check):
|
||||
if is_function_exists(fn, file_object):
|
||||
function_ranks[rank_ind].append(fn)
|
||||
functions_to_check.remove(fn)
|
||||
"""
|
||||
zhegalkin_functions = {key: list(filter(lambda x: is_good_zhegalkin(x, args_count), value)) for key,value in function_ranks.items()}
|
||||
for processed_function_ranks in [function_ranks, zhegalkin_functions]:
|
||||
if processed_function_ranks is zhegalkin_functions:
|
||||
print("Со степенью <= 3:")
|
||||
|
||||
len_to_count = {key: len(value) for key, value in processed_function_ranks.items()}
|
||||
total = sum(len_to_count.values())
|
||||
for rank_ind, count in sorted(len_to_count.items(), key=lambda x: x[0]):
|
||||
@@ -107,25 +105,43 @@ def count_symmetricals(args_count):
|
||||
)
|
||||
|
||||
|
||||
if args_count <= 3:
|
||||
print(r"\begin{center}")
|
||||
print(r"\begin{tabular}{| l| r | l|}")
|
||||
print(r"\begin{longtable}{| l| r | p{11cm}|}")
|
||||
print(r"\hline")
|
||||
if args_count <= 4:
|
||||
print(r"Длина функции & Номер & ПСПФ\\")
|
||||
else:
|
||||
print(r"Длина функции & Номер & Полином Жегалкина\\")
|
||||
|
||||
print(r"\hline")
|
||||
print(r"\endhead")
|
||||
print(r"\hline \multicolumn{3}{r}{\textit{Продолжение на следующей странице}} \\")
|
||||
print(r"\endfoot")
|
||||
print(r"\hline")
|
||||
print(r"\endlastfoot")
|
||||
for rank in sorted(function_ranks.keys()):
|
||||
for function_number in sorted(function_ranks[rank]):
|
||||
print(f"{rank} & {function_number} & ${func_strings[function_number]}$\\\\")
|
||||
|
||||
if args_count <= 4:
|
||||
function_representation = func_strings[function_number]
|
||||
else:
|
||||
function_representation = generate_function(function_number, args_count).tex_str().strip()
|
||||
|
||||
print(f"{rank} & {function_number} & ${function_representation}$\\\\")
|
||||
if rank != max(function_ranks.keys()):
|
||||
print(r"\hline")
|
||||
print(r"\hline")
|
||||
print(r"\end{tabular}")
|
||||
print(r"\end{longtable}")
|
||||
print(r"\addtocounter{table}{-1}")
|
||||
print(r"\end{center}")
|
||||
|
||||
|
||||
def main():
|
||||
if sys.argv[1] == "count_lens":
|
||||
count_lens(sys.argv[2])
|
||||
white_map_path = None
|
||||
if len(sys.argv) > 3:
|
||||
white_map_path = sys.argv[3]
|
||||
count_lens(sys.argv[2], white_map_path)
|
||||
return
|
||||
elif sys.argv[1] == "count_symmetricals":
|
||||
count_symmetricals(int(sys.argv[2]))
|
||||
|
||||
Reference in New Issue
Block a user