diff --git a/main.cpp b/main.cpp index 2aadace..bb419d2 100644 --- a/main.cpp +++ b/main.cpp @@ -35,9 +35,37 @@ void test_function() { // no changed in this objects assert(("a = 00001100", a.string() == "00001100")); assert(("b = 00000101", b.string() == "00000101")); + + Function negation(107); + assert(("f(x_1 + 1 + 1, x_2, x_3) == f", negation == negation.var_negation(1).var_negation(1))); + assert(("f(x_1, x_2 + 1 + 1, x_3) == f", negation == negation.var_negation(2).var_negation(2))); + assert(("f(x_1, x_2, x_3 + 1 + 1) == f", negation == negation.var_negation(3).var_negation(3))); + /* + cout << "f(x_1, x_2, x_3) = " << negation.string() << endl; + cout << "f(x_1 + 1, x_2, x_3) = " << negation.var_negation(1).string() << endl; + cout << "f(x_1 + 1 + 1, x_2, x_3) = " << negation.var_negation(1).var_negation(1).string() << endl; + cout << "f(x_1, x_2 + 1, x_3) = " << negation.var_negation(2).string() << endl; + cout << "f(x_1, x_2 + 1 + 1, x_3) = " << negation.var_negation(2).var_negation(2).string() << endl; + cout << "f(x_1, x_2, x_3 + 1) = " << negation.var_negation(3).string() << endl; + */ + cout << "self-test passed" << endl; } + +vector get_function_class(MyFunction f) { + set cur_res; + for (Storage i = 0; i < FUNCTION_LEN; ++i) { + MyFunction cur_f = f; + for (Storage arg_ind = 0; arg_ind < ARGS_COUNT; ++arg_ind) + if ( (i >> arg_ind) % 2 == 1 ) + cur_f = cur_f.var_negation(arg_ind + 1); + cur_res.insert(cur_f); + } + return vector(cur_res.begin(), cur_res.end()); +} + + vector get_linear_components() { vector res; if ( ARGS_COUNT == 3 ) { @@ -97,37 +125,58 @@ void fill_ranks(vector monomials) { size_t functions_remains = FUNCTIONS_COUNT; ofstream f_out("out.txt"); - vector< vector > ranks; ranks.push_back(vector()); // empty set ranks.push_back(monomials); // empty set cout << "rank index = " << 1 << endl; - f_out << "rank index = " << 1 << endl; for (auto el: monomials) { --functions_remains; used_map.at(el.value()) = 1; - f_out << el.string() << endl; } - for (size_t rank_ind = 2; functions_remains; ++rank_ind) { + size_t total_ranks = 1; + for (total_ranks = 1; functions_remains; ++total_ranks) { ranks.push_back(vector()); - cout << "rank index = " << rank_ind << " remains: " << functions_remains << endl; - f_out << "rank index = " << rank_ind << endl; - for (auto el_first: ranks.at(rank_ind - 1)) { + cout << "rank index = " << total_ranks << " remains: " << functions_remains << endl; + for (auto el_first: ranks.at(total_ranks - 1)) { for (auto el_second: ranks.at(1)) { MyFunction res_el = el_first xor el_second; if ( used_map[res_el.value()] == 0 ) { --functions_remains; - used_map[res_el.value()] = 1; - ranks.at(rank_ind).push_back(res_el); - f_out << res_el.string() << " = " - << el_first.string() << " + " << el_second.string() << "\n"; + used_map[res_el.value()] = total_ranks; + ranks.at(total_ranks).push_back(res_el); } } } - if ( rank_ind - 1 > 1 ) - ranks.at(rank_ind - 1).clear(); // больше не нужен - cout << "size for rank " << rank_ind << " is " << ranks.at(rank_ind).size() << endl; + if ( total_ranks - 1 > 1 ) + ranks.at(total_ranks - 1).clear(); // больше не нужен + cout << "size for rank " << total_ranks << " is " << ranks.at(total_ranks).size() << endl; + } + + ranks.clear(); + for (auto i = total_ranks - 1; i != 0; --i) + ranks.push_back(vector()); // empty set + size_t total_functions = 0; + for (size_t fn_value = 0; fn_value < used_map.size(); ++fn_value) { + auto cur_rank = used_map[fn_value]; + if ( not cur_rank ) + continue; + ++total_functions; + MyFunction current_fn(fn_value); + vector function_class = get_function_class(current_fn); + f_out << "Function class for " << current_fn.string() << ": "; + for (auto marked_function: function_class) { + used_map[marked_function.value()] = 0; + f_out << marked_function.string() << " "; + } + f_out << endl; + ranks.at(cur_rank - 1).push_back(current_fn); + } + cout << "total unique functions: " << total_functions << endl; + for (size_t rank_ind = 0; rank_ind < ranks.size(); ++rank_ind) { + f_out << "rank index = " << rank_ind + 1 << endl; + for (auto f: ranks.at(rank_ind)) + f_out << f.string() << endl; } f_out.close(); }