Skip to content

Commit

Permalink
Fixing SKRYPT ohhmm/skrypt#10
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhmm committed Dec 28, 2023
1 parent 6f6f64c commit a834dff
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 44 deletions.
91 changes: 48 additions & 43 deletions omnn/math/PrincipalSurd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,49 +122,49 @@ PrincipalSurd::operator long double() const {
return _2 == 2 ? std::sqrt(d) : std::pow(d, 1./static_cast<long double>(_2));
}

Valuable::vars_cont_t PrincipalSurd::GetVaExps() const {
auto vaExps = _1.GetVaExps();
if(_2.IsInt() && _2 > constants::one) {
for(auto& ve : vaExps)
ve.second /= _2;
} else {
IMPLEMENT
}
return vaExps;
}

Valuable::vars_cont_t PrincipalSurd::GetVaExps() const {
auto vaExps = _1.GetVaExps();
if(_2.IsInt() && _2 > constants::one) {
for(auto& ve : vaExps)
ve.second /= _2;
} else {
IMPLEMENT
}
return vaExps;
}

max_exp_t PrincipalSurd::getMaxVaExp(const Valuable& _1, const Valuable& _2) {
return _1.getMaxVaExp() / _2.ca();
}

bool PrincipalSurd::operator <(const Valuable& other) const {

Valuable power;
if(other.IsPrincipalSurd()) {
auto& ps = other.as<PrincipalSurd>();
if(_2 == ps._2) {
return _1 < ps._1;
} else if (_1 == ps._1) {
return ps._2 < _2;
} else if (_2.IsInt() && ps._2.IsInt()) {
power = std::max(_2, ps._2);
} else {
power = _2 * ps._2;
}
} else {
power = _2;
}

return (*this ^ power) < (other ^ power);
}

Valuable& PrincipalSurd::operator^=(const Valuable& e) {
if (_2 == e)
return _1;
else
return base::operator^=(e);
}


bool PrincipalSurd::operator <(const Valuable& other) const {

Valuable power;
if(other.IsPrincipalSurd()) {
auto& ps = other.as<PrincipalSurd>();
if(_2 == ps._2) {
return _1 < ps._1;
} else if (_1 == ps._1) {
return ps._2 < _2;
} else if (_2.IsInt() && ps._2.IsInt()) {
power = std::max(_2, ps._2);
} else {
power = _2 * ps._2;
}
} else {
power = _2;
}

return (*this ^ power) < (other ^ power);
}

Valuable& PrincipalSurd::operator^=(const Valuable& e) {
if (_2 == e)
return _1;
else
return base::operator^=(e);
}

bool PrincipalSurd::IsComesBefore(const Valuable& v) const {
if(v.IsPrincipalSurd()) {
auto& ps = v.as<PrincipalSurd>();
Expand Down Expand Up @@ -198,9 +198,14 @@ Valuable PrincipalSurd::InCommonWith(const Valuable& v) const {
return _2.IsEven() == YesNoMaybe::Yes && _1.Sign() != constants::one
? v
: constants::one;
} else if (v.IsProduct()) {
return v.InCommonWith(*this);
} else if (v.IsVa() && !HasVa(v.as<Variable>())){
return constants::one;
} else {
return base::InCommonWith(v);
auto commonUnderRoot = _1.InCommonWith(v ^ _2);
if(commonUnderRoot == constants::one) {
return commonUnderRoot;
} else {
return PrincipalSurd{commonUnderRoot, _2};
}
}
}
2 changes: 1 addition & 1 deletion omnn/math/Product.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ namespace math {
}
} else if (v.IsSimple()) {
} else if (v.IsModulo()) {
} else if (v.IsSum()) {
} else if (v.IsSum() || v.IsPrincipalSurd()) {
is = v.IsSummationSimplifiable(*this);
} else if (v.IsProduct()
|| v.IsVa()
Expand Down

0 comments on commit a834dff

Please sign in to comment.