From 494e69773855419fc42bb6f4917d734ea6d26829 Mon Sep 17 00:00:00 2001 From: Aleksey Lobanov Date: Sat, 28 Apr 2018 01:04:44 +0300 Subject: [PATCH] Added good functions and extended conditions for k=4 --- main.cpp | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 142 insertions(+), 10 deletions(-) diff --git a/main.cpp b/main.cpp index e5b19a3..979dda6 100644 --- a/main.cpp +++ b/main.cpp @@ -22,7 +22,7 @@ using namespace std; -const CellType CUR_BASE = 3; +const CellType CUR_BASE = 4; const int ARGS_COUNT = 2; const string CLASSES_FILENAME = "classes.txt"; @@ -130,9 +130,10 @@ bool is_one_arg_func(const TripleArgsFiniteFunction &h) { for (CellType x = 0; x < CUR_BASE; ++x) for (CellType y = 0; y < CUR_BASE; ++y) { for (CellType z = 0; z < CUR_BASE; ++z) { - is_equaled_x = is_equaled_x && (h(x,y,z) == x); - is_equaled_y = is_equaled_y && (h(x,y,z) == y); - is_equaled_z = is_equaled_z && (h(x,y,z) == z); + auto h_res = h(x,y,z); + is_equaled_x = is_equaled_x && (h_res == x); + is_equaled_y = is_equaled_y && (h_res == y); + is_equaled_z = is_equaled_z && (h_res == z); } if ( !is_equaled_x && !is_equaled_y && !is_equaled_z ) return false; @@ -140,6 +141,29 @@ bool is_one_arg_func(const TripleArgsFiniteFunction &h) { return true; } +template +bool is_one_arg_func_fourth(const FourthArgsFiniteFunction &h) { + bool is_equaled_x = true; + bool is_equaled_y = true; + bool is_equaled_z = true; + bool is_equaled_w = true; + for (CellType x = 0; x < CUR_BASE; ++x) + for (CellType y = 0; y < CUR_BASE; ++y) { + for (CellType z = 0; z < CUR_BASE; ++z) { + for (CellType w = 0; w < CUR_BASE; ++w) { + auto h_res = h(x,y,z,w); + is_equaled_x = is_equaled_x && (h_res == x); + is_equaled_y = is_equaled_y && (h_res == y); + is_equaled_z = is_equaled_z && (h_res == z); + is_equaled_w = is_equaled_w && (h_res == w); + } + } + if ( !is_equaled_x && !is_equaled_y && !is_equaled_z && !is_equaled_w) + return false; + } + return true; +} + template bool is_projection(const TripleArgsFiniteFunction &h) { bool is_projection = true; @@ -153,6 +177,20 @@ bool is_projection(const TripleArgsFiniteFunction &h) { return is_projection; } +template +bool is_projection_fourth(const FourthArgsFiniteFunction &h) { + bool is_projection = true; + for (CellType x = 0; x < CUR_BASE; ++x) + for (CellType y = 0; y < CUR_BASE; ++y) { + is_projection = (is_projection + && h(x,x,x,y) == h(x,x,y,x) + && h(x,x,y,x) == h(x,y,x,x) + && h(x,y,x,x) == h(y,x,x,x) + && h(y,x,x,x) == x); + } + return is_projection; +} + template bool is_semiprojection(const TripleArgsFiniteFunction &h) { bool is_equaled_x = true; @@ -164,13 +202,57 @@ bool is_semiprojection(const TripleArgsFiniteFunction &h) { // если все различны, то не рассматриваем if ( x != y && x != z && y != z ) continue; - is_equaled_x = is_equaled_x && (h(x,y,z) == x); - is_equaled_y = is_equaled_y && (h(x,y,z) == y); - is_equaled_z = is_equaled_z && (h(x,y,z) == z); + + auto h_res = h(x,y,z); + is_equaled_x = is_equaled_x && (h_res == x); + is_equaled_y = is_equaled_y && (h_res == y); + is_equaled_z = is_equaled_z && (h_res == z); + if ( + !is_equaled_x + && !is_equaled_y + && !is_equaled_z + ) + return false; } return is_equaled_x || is_equaled_y || is_equaled_z; } +template +bool is_semiprojection_fourth(const FourthArgsFiniteFunction &h) { + bool is_equaled_x = true; + bool is_equaled_y = true; + bool is_equaled_z = true; + bool is_equaled_w = true; + for (CellType x = 0; x < CUR_BASE; ++x) + for (CellType y = 0; y < CUR_BASE; ++y) + for (CellType z = 0; z < CUR_BASE; ++z) { + for (CellType w = 0; w < CUR_BASE; ++w) { + set s; + s.insert(x); + s.insert(y); + s.insert(z); + s.insert(w); + if ( s.size() == 4 ) + // если все различны, то не рассматриваем + continue; + + auto h_res = h(x,y,z,w); + is_equaled_x = is_equaled_x && (h_res == x); + is_equaled_y = is_equaled_y && (h_res == y); + is_equaled_z = is_equaled_z && (h_res == z); + is_equaled_w = is_equaled_w && (h_res == w); + if ( + !is_equaled_x + && !is_equaled_y + && !is_equaled_z + && !is_equaled_w + ) + return false; + } + } + return is_equaled_x || is_equaled_y || is_equaled_z || is_equaled_w; +} + bool is_passed_rosenberg(const FiniteFunction &f) { auto h_1 = [f](const CellType x, const CellType y, CellType z) -> CellType { return f( f(x,y), f(x,z) ); @@ -203,6 +285,49 @@ bool is_passed_rosenberg(const FiniteFunction &f) { if ( is_projection(h_4) || is_semiprojection(h_4) ) return false; } + + if ( CUR_BASE == 4 ) { + auto g_1 = [f, h_1](const CellType x, const CellType y, CellType z, CellType u) -> CellType { + return f( h_1(x,y,z), u ); + }; + if ( !is_one_arg_func_fourth(g_1) ) { + if ( is_projection_fourth(g_1) || is_semiprojection_fourth(g_1) ) + return false; + } + + auto g_2 = [f, h_2](const CellType x, const CellType y, CellType z, CellType u) -> CellType { + return f( h_2(x,y,z), u ); + }; + if ( !is_one_arg_func_fourth(g_2) ) { + if ( is_projection_fourth(g_2) || is_semiprojection_fourth(g_2) ) + return false; + } + + auto g_3 = [f, h_3](const CellType x, const CellType y, CellType z, CellType u) -> CellType { + return f( h_3(x,y,z), u ); + }; + if ( !is_one_arg_func_fourth(g_3) ) { + if ( is_projection_fourth(g_3) || is_semiprojection_fourth(g_3) ) + return false; + } + + auto g_4 = [f, h_4](const CellType x, const CellType y, CellType z, CellType u) -> CellType { + return f( h_4(x,y,z), u ); + }; + if ( !is_one_arg_func_fourth(g_4) ) { + if ( is_projection_fourth(g_4) || is_semiprojection_fourth(g_4) ) + return false; + } + + auto g_both = [f](const CellType x, const CellType y, CellType z, CellType u) -> CellType { + return f( f(x,y), f(z,u) ); + }; + if ( !is_one_arg_func_fourth(g_both) ) { + if ( is_projection_fourth(g_both) || is_semiprojection_fourth(g_both) ) + return false; + } + } + return true; } @@ -381,6 +506,7 @@ vector processed_task_list; mutex processed_task_mutex; set> bad_functions; +set> good_functions; atomic current_max_coeff; void do_work() { @@ -499,6 +625,14 @@ void process_task_lists() { vector functions_to_remove; is_need_append = !is_bad_class(task.current, bad_functions); + + for (auto&& f: task.current) + if ( good_functions.find(f) == good_functions.end() ) { + is_need_append = false; + break; + } + + /*for (auto it = shared_function_classes.begin(); it != shared_function_classes.end(); ++it) { if ( func_class.size() < it->size() ) { if (includes( @@ -592,15 +726,13 @@ int main() { decltype(FiniteFunctionHasher) > allowed_functions(funcs.begin(), funcs.end(), 128, FiniteFunctionHasher); - - cout << identical_x.get_hash() << endl; - cout << identical_y.get_hash() << endl; allowed_functions.erase(identical_x); allowed_functions.erase(identical_y); completed_tasks = 0; current_max_coeff = 1; for (auto&& func: allowed_functions) { + good_functions.insert(func); FunctionTask task; task.current = {func}; task.is_finished = false;