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 Sep 29, 2024
1 parent 4090bc5 commit eec1704
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
1 change: 1 addition & 0 deletions cmake/gitect.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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
50 changes: 32 additions & 18 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 @@ -1145,10 +1145,10 @@ namespace math {
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 Down Expand Up @@ -1190,23 +1190,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::zero
&& 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 @@ -1249,7 +1263,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 eec1704

Please sign in to comment.