Skip to content

Commit

Permalink
Sum use GCD for InCommonWith
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhmm committed Sep 29, 2024
1 parent 84140ec commit f3fbb45
Showing 1 changed file with 3 additions and 40 deletions.
43 changes: 3 additions & 40 deletions omnn/math/Sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,46 +735,7 @@ namespace

Valuable Sum::InCommonWith(const Valuable& v) const
{
if(v.IsSum())
{
auto& s = v.as<Sum>();
auto vars = Vars();
if (vars.size() == 1 && vars == s.Vars()) {
auto& v = vars.begin()->as<Variable>();
auto solutions = Solutions(v);
auto vSolutions = s.Solutions(v);

// get common solutions
decltype(solutions) commonSolutions;
std::set_intersection(solutions.begin(), solutions.end(),
vSolutions.begin(), vSolutions.end(),
std::inserter(commonSolutions, commonSolutions.begin()));

if (commonSolutions.size() > 0) {
Product p({});
for (auto& solution : commonSolutions) {
p.Add(v - solution);
}
return p;
}
else {
IMPLEMENT
}
}else{
return GCD(v);
}
}else{
auto c = v;
auto b = GetConstCont().begin();
auto e = GetConstCont().end();
if(b != e)
{
auto it = b;
while(c != constants::one && ++it != e)
c = it->InCommonWith(c);
}
return c;
}
return GCD(v);
}

max_exp_t Sum::findMaxVaExp() {
Expand Down Expand Up @@ -1303,6 +1264,8 @@ namespace
}
}

// TODO: https://math.stackexchange.com/a/1854191/118612

return PrincipalSurd(*this, 2);
}

Expand Down

0 comments on commit f3fbb45

Please sign in to comment.