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 Oct 5, 2024
1 parent 9af1b53 commit d240211
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
54 changes: 35 additions & 19 deletions omnn/math/Product.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,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 @@ -1148,19 +1148,21 @@ namespace math {
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;
}

if(it1 == e1 || it2 == e2)
continue;

same = same && it1->Same(*it2);

++it1, ++it2;
}

same = same && it1 == e1 && it2 == e2;
Expand Down Expand Up @@ -1195,23 +1197,37 @@ namespace math {
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)) {
auto sz1 = c1.size();
same = sz1 == 1;
if (!same) {
auto& e = v.as<Exponentiation>();
same = e.IsMultiSign() && sz1 == 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::minus_1
&& operator==(e.getBase().Reciprocal() ^ -ee);
}
} else if (v.IsProduct()
&& IsMultival() == YesNoMaybe::Yes
&& v.IsMultival() == YesNoMaybe::Yes)
{
// TODO: Check if it has same multival exponentiation and different sign or i in coefficient
//LOG_AND_IMPLEMENT("Check if it has same multival exponentiation and different sign or i in coefficient: " << *this << " == " << v);
}
return same;
}
Expand Down Expand Up @@ -1254,7 +1270,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(Fraction_optimization_no_hang_test
Expand Down

0 comments on commit d240211

Please sign in to comment.