feat: Фильтр по степени полинома Ж. в постпроцессинге
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
from __future__ import print_function, unicode_literals
|
|
||||||
|
|
||||||
import lzma
|
import lzma
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import itertools
|
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):
|
def get_rank_file_object(args_count, rank_ind):
|
||||||
base_name = "base_{}_rank_{}.txt".format(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))
|
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):
|
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()
|
functions_to_check = set()
|
||||||
for layer_values in itertools.product([0, 1], repeat=args_count + 1):
|
for layer_values in itertools.product([0, 1], repeat=args_count + 1):
|
||||||
func_values = []
|
func_values = []
|
||||||
@@ -58,9 +74,14 @@ def count_symmetricals(args_count):
|
|||||||
func_values.append("0")
|
func_values.append("0")
|
||||||
function_number = function_values_to_number("".join(func_values))
|
function_number = function_values_to_number("".join(func_values))
|
||||||
functions_to_check.add(function_number)
|
functions_to_check.add(function_number)
|
||||||
print("".join(func_values), function_number)
|
|
||||||
|
|
||||||
function_ranks = {}
|
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):
|
for rank_ind in range(1, 10):
|
||||||
if not functions_to_check:
|
if not functions_to_check:
|
||||||
break
|
break
|
||||||
@@ -72,10 +93,12 @@ def count_symmetricals(args_count):
|
|||||||
if is_function_exists(fn, file_object):
|
if is_function_exists(fn, file_object):
|
||||||
function_ranks[rank_ind].append(fn)
|
function_ranks[rank_ind].append(fn)
|
||||||
functions_to_check.remove(fn)
|
functions_to_check.remove(fn)
|
||||||
print(function_ranks)
|
"""
|
||||||
len_to_count = {key: len(value) for key, value in function_ranks.items()}
|
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())
|
total = sum(len_to_count.values())
|
||||||
for rank_ind, count in len_to_count.items():
|
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("len {} count {} share {}".format(rank_ind, count, 1.0 * count / total))
|
||||||
print(
|
print(
|
||||||
"average: {}".format(
|
"average: {}".format(
|
||||||
@@ -84,6 +107,22 @@ def count_symmetricals(args_count):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
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():
|
def main():
|
||||||
if sys.argv[1] == "count_lens":
|
if sys.argv[1] == "count_lens":
|
||||||
count_lens(sys.argv[2])
|
count_lens(sys.argv[2])
|
||||||
|
|||||||
Reference in New Issue
Block a user