Skip to content

Commit

Permalink
Fix Product compare with Exponentiations with negative exponentiation…
Browse files Browse the repository at this point in the history
… (reciprocal)
  • Loading branch information
ohhmm committed Apr 18, 2024
1 parent 3d59ec8 commit 0f26d04
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
1 change: 1 addition & 0 deletions cmake/gitect.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 31 additions & 24 deletions omnn/math/Product.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1125,25 +1125,25 @@ namespace math {
auto sameHash = (Valuable::hash & ~Hash1) == (v.Hash() & ~Hash1); // ignore multiplication by 1
auto same = v.Is<Product>() && sameHash;
auto& c1 = GetConstCont();
auto sz1 = c1.size();
auto n1 = c1.size();
if (same) {
auto& vp = v.as<Product>();
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;
}

Expand All @@ -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<Exponentiation>();
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<Fraction>();
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<Exponentiation>();
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<Fraction>();
auto& eefdn = eef.getDenominator();
same = eefdn >= 4 || eefdn <= -4;
} else {
LOG_AND_IMPLEMENT("Examine new multisign form: " << *this << " == " << e);
}
}
}
}
else {
auto& e = v.as<Exponentiation>();
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)
Expand Down Expand Up @@ -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
{
Expand Down
6 changes: 2 additions & 4 deletions omnn/math/test/Fraction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0f26d04

Please sign in to comment.