From 0f26d0449600acf6bc8b5abfdadcb7d1e9bd201a Mon Sep 17 00:00:00 2001 From: Sergii Kryvonos Date: Sun, 14 Apr 2024 11:55:07 +0200 Subject: [PATCH] Fix Product compare with Exponentiations with negative exponentiation (reciprocal) --- cmake/gitect.cmake | 1 + omnn/math/Product.cpp | 55 ++++++++++++++++++-------------- omnn/math/test/Fraction_test.cpp | 6 ++-- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/cmake/gitect.cmake b/cmake/gitect.cmake index b0945d6d1..7901fc1e3 100644 --- a/cmake/gitect.cmake +++ b/cmake/gitect.cmake @@ -22,6 +22,7 @@ if(GIT_EXECUTABLE) add_custom_target(rebase-main WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} pull --rebase --autostash origin main + COMMAND ${GIT_EXECUTABLE} fetch --all ) set_target_properties(rebase-main PROPERTIES EXCLUDE_FROM_ALL 1 diff --git a/omnn/math/Product.cpp b/omnn/math/Product.cpp index 6788b2e0f..df6d11e82 100644 --- a/omnn/math/Product.cpp +++ b/omnn/math/Product.cpp @@ -954,7 +954,7 @@ namespace math { return *this; } else if (v.IsSimple() ) { - if (v == 1_v) { + if (v == constants::one) { return *this; } else if (v.IsConstant()) { auto it = std::find(begin(), end(), v); @@ -1125,25 +1125,25 @@ namespace math { auto sameHash = (Valuable::hash & ~Hash1) == (v.Hash() & ~Hash1); // ignore multiplication by 1 auto same = v.Is() && sameHash; auto& c1 = GetConstCont(); - auto sz1 = c1.size(); + auto n1 = c1.size(); if (same) { auto& vp = v.as(); auto& c2 = vp.GetConstCont(); - auto sz2 = c2.size(); - auto sameSizes = sz1 == sz2; + auto n2 = c2.size(); + auto sameSizes = n1 == n2; if(sameSizes) { same = c1 == c2; - } else if (sz1-sz2==1 || sz2-sz1==1) { + } else if (n1-n2==1 || n2-n1==1) { auto it1 = c1.begin(), it2 = c2.begin(); auto e1 = c1.end(), e2 = c2.end(); for(same = true; same && it1 != e1 && it2 != e2; ++it1, ++it2) { - if(it1->Same(1_v)){ + if(it1->Same(constants::one)){ ++it1; } - if(it2->Same(1_v)){ + if(it2->Same(constants::one)){ ++it2; } @@ -1159,29 +1159,36 @@ namespace math { } } else if (sameHash - && (sz1 == 1 - || (sz1 == 2 && c1.begin()->Same(1_v) ))) + && (n1 == 1 + || (n1 == 2 && c1.begin()->Same(constants::one) ))) { same = c1.rbegin()->operator==(v); } else if (members.empty()) { same = v == 1; - } else if (v.IsExponentiation() && Has(v)) { - auto n = members.size(); - same = n == 1; - if (!same) { - auto& e = v.as(); - same = e.IsMultiSign() && n == 2 && Has(constants::minus_1); - if (!same && Has(constants::i)) { - auto& ee = e.getExponentiation(); - if (ee.IsFraction()) { - auto& eef = ee.as(); - auto& eefdn = eef.getDenominator(); - same = eefdn >= 4 || eefdn <= -4; - } else { - LOG_AND_IMPLEMENT("Examine new multisign form: " << *this << " == " << e); + } else if (v.IsExponentiation()) { + if (Has(v)) { + same = n1 == 1; + if (!same) { + auto& e = v.as(); + same = e.IsMultiSign() && n1 == 2 && Has(constants::minus_1); + if (!same && Has(constants::i)) { + auto& ee = e.getExponentiation(); + if (ee.IsFraction()) { + auto& eef = ee.as(); + auto& eefdn = eef.getDenominator(); + same = eefdn >= 4 || eefdn <= -4; + } else { + LOG_AND_IMPLEMENT("Examine new multisign form: " << *this << " == " << e); + } } } } + else { + auto& e = v.as(); + auto& ee = e.getExponentiation(); + same = ee.IsSimple() && ee < constants::zero + && operator==(e.getBase().Reciprocal() ^ -ee); + } } else if (v.IsProduct() && IsMultival() == YesNoMaybe::Yes && v.IsMultival() == YesNoMaybe::Yes) @@ -1230,7 +1237,7 @@ namespace math { auto it = coVa.find(va); if (it != coVa.end()) { if (it->second < 0) { - s = ((*this / (it->first ^ it->second)) / augmentation) ^ (1_v / -it->second); + s = ((*this / (it->first ^ it->second)) / augmentation) ^ (-it->second).Reciprocal(); } else { diff --git a/omnn/math/test/Fraction_test.cpp b/omnn/math/test/Fraction_test.cpp index 21632e028..2e095560c 100644 --- a/omnn/math/test/Fraction_test.cpp +++ b/omnn/math/test/Fraction_test.cpp @@ -83,14 +83,12 @@ BOOST_AUTO_TEST_CASE(FractionSimplification_tests ){ auto _1 = (25_v / 5) ^ Fraction{constants::minus_1,constants::two}; auto _2 = (1_v / 5)*(1_v^(1_v/2)); - auto c = _1 == _2; - BOOST_TEST(c); + BOOST_TEST(_1 == _2); DECL_VA(x); _1 =(-1_v)^x; _2 = (-1_v)^((1_v/2)*x + _1/4 + ((-1_v)/4)); - c = _1 != _2; - BOOST_TEST(c); + BOOST_TEST(_1 != _2); } BOOST_AUTO_TEST_CASE(Balancing_no_hang_test