@@ -301,7 +301,7 @@ BooleanFunction BooleanFunction::operator()(const std::vector<BooleanFunction>&
301301}
302302/**/
303303
304- // ВАРИАНТ 2. Функция от векторов значений
304+ /* / ВАРИАНТ 2. Функция от векторов значений
305305BooleanFunction BooleanFunction::operator()(const std::vector<BooleanFunction>& fs) const
306306{
307307 if (fs.size() != dimension()) {
@@ -334,6 +334,37 @@ BooleanFunction BooleanFunction::operator()(const std::vector<BooleanFunction>&
334334}
335335/**/
336336
337+ BooleanFunction BooleanFunction::operator ()(const std::vector<BooleanFunction>& fs) const
338+ {
339+ if (fs.size () != dimension ()) {
340+ throw IncorrectLengthException ();
341+ }
342+ if (fs.size () == 0 ) {
343+ return BooleanFunction ();
344+ }
345+
346+ size_type d = 0 ;
347+ for (BooleanFunction const & f : fs) {
348+ if (f.dimension () > d) {
349+ d = f.dimension ();
350+ }
351+ }
352+
353+ BooleanFunction result (d);
354+
355+ for (size_type i = 0 ; i < result.func_ .size (); ++i) {
356+ std::vector<bool > vars;
357+ for (BooleanFunction const & f : fs) {
358+ vars.push_back (f.func_ [i % f.size ()]);
359+ }
360+ result.func_ [i] = (*this )(vars);
361+ }
362+
363+ // result.func_ = ReduceFunc_(result.func_);
364+
365+ return result;
366+ }
367+
337368BooleanFunction BooleanFunction::operator ()(const std::initializer_list<BooleanFunction> fs) const
338369{
339370 if (fs.size () != dimension ()) {
@@ -360,7 +391,7 @@ BooleanFunction BooleanFunction::operator()(const std::initializer_list<BooleanF
360391 result.func_ [i] = (*this )(vars);
361392 }
362393
363- result.func_ = ReduceFunc_ (result.func_ );
394+ // result.func_ = ReduceFunc_(result.func_);
364395
365396 return result;
366397}
@@ -469,22 +500,22 @@ std::vector<BooleanFunction::value_type> BooleanFunction::anf() const
469500 return result;
470501}
471502
472- std::vector<BooleanFunction::value_type> BooleanFunction::ReduceFunc_ (std::vector<value_type> const & func )
503+ void BooleanFunction::ReduceFunc ( )
473504{
474- size_type dim = static_cast <size_type>(log2 (func .size ()));
505+ size_type dim = static_cast <size_type>(log2 (func_ .size ()));
475506
476507 std::vector<bool > isEssential (dim, false );
477508
478509 for (size_type j = 0 ; j < dim; ++j) {
479510 size_type s = static_cast <size_type>(pow (2 , j)); // Размер половины участка
480- size_type c = static_cast <size_type>(func .size () / (s * 2 )); // Количество пар
511+ size_type c = static_cast <size_type>(func_ .size () / (s * 2 )); // Количество пар
481512
482513 for (size_type k = 0 ; k < c; ++k) {
483514 if (isEssential[j]) {
484515 break ;
485516 }
486517 for (size_type i = 2 * s * k; i < 2 * s * k + s; ++i) {
487- if (func [i] != func [i + s]) {
518+ if (func_ [i] != func_ [i + s]) {
488519 isEssential[j] = true ;
489520 break ;
490521 }
@@ -500,12 +531,12 @@ std::vector<BooleanFunction::value_type> BooleanFunction::ReduceFunc_(std::vecto
500531 }
501532
502533 if (dim != newDim) {
503- std::vector<bool > isResValue (func .size (), true );
534+ std::vector<bool > isResValue (func_ .size (), true );
504535
505536 for (size_type j = 0 ; j < dim; ++j) {
506537 if (!isEssential[j]) {
507538 size_type s = static_cast <size_type>(pow (2 , j)); // Размер половины участка
508- size_type c = static_cast <size_type>(func .size () / (s * 2 )); // Количество пар
539+ size_type c = static_cast <size_type>(func_ .size () / (s * 2 )); // Количество пар
509540
510541 for (size_type k = 0 ; k < c; ++k) {
511542 for (size_type i = 2 * s * k + s; i < 2 * s * k + 2 * s; ++i) {
@@ -517,18 +548,14 @@ std::vector<BooleanFunction::value_type> BooleanFunction::ReduceFunc_(std::vecto
517548
518549 std::vector<value_type> result;
519550
520- for (size_type i = 0 ; i < func .size (); ++i) {
551+ for (size_type i = 0 ; i < func_ .size (); ++i) {
521552 if (isResValue[i]) {
522- result.push_back (func [i]);
553+ result.push_back (func_ [i]);
523554 }
524555 }
525556
526- return result;
527- }
528- else {
529- return func;
557+ func_ = result;
530558 }
531-
532559}
533560
534561std::string get_polynom (const BooleanFunction& rhs)
0 commit comments