feat: Фильтр по степени полинома Ж. в постпроцессинге

This commit is contained in:
2021-05-02 14:16:59 +03:00
parent c2ccb5e60f
commit 1e4a37756f

View File

@@ -1,11 +1,14 @@
from __future__ import print_function, unicode_literals
import lzma
import sys
import os
import itertools
from booleantools import generate_function
def is_good_zhegalkin(function_number, args_count):
return all(map(lambda x: len(x) <= 3, generate_function(function_number, args_count).listform))
def get_rank_file_object(args_count, rank_ind):
base_name = "base_{}_rank_{}.txt".format(args_count, rank_ind)
@@ -47,7 +50,20 @@ def count_lens(args_count):
print("average: {}".format(sum([key * value for key, value in len_to_count.items()]) / total))
def get_function_len(args_count, function_number):
for rank_ind in range(1, 10):
file_object = get_rank_file_object(args_count, rank_ind)
if not file_object:
assert False
if is_function_exists(function_number, file_object):
return rank_ind
assert False
def count_symmetricals(args_count):
func_strings = list(open("./build/functions_strings.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):
func_values = []
@@ -58,9 +74,14 @@ def count_symmetricals(args_count):
func_values.append("0")
function_number = function_values_to_number("".join(func_values))
functions_to_check.add(function_number)
print("".join(func_values), function_number)
function_ranks = {}
for fn in functions_to_check:
rank = get_function_len(args_count, fn)
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
@@ -72,16 +93,34 @@ def count_symmetricals(args_count):
if is_function_exists(fn, file_object):
function_ranks[rank_ind].append(fn)
functions_to_check.remove(fn)
print(function_ranks)
len_to_count = {key: len(value) for key, value in function_ranks.items()}
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))
print(
"average: {}".format(
sum([1.0 * key * value for key, value in len_to_count.items()]) / total
"""
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]:
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]):
print("len {} count {} share {}".format(rank_ind, count, 1.0 * count / total))
print(
"average: {}".format(
sum([1.0 * key * value for key, value in len_to_count.items()]) / total
)
)
)
if args_count <= 3:
print(r"\begin{center}")
print(r"\begin{tabular}{| l| r | l|}")
print(r"\hline")
print(r"Длина функции & Номер & ПСПФ\\")
print(r"\hline")
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 rank != max(function_ranks.keys()):
print(r"\hline")
print(r"\hline")
print(r"\end{tabular}")
print(r"\end{center}")
def main():