Skip to content

Commit

Permalink
Implement Logarithm class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-ai-integration[bot] authored and ohhmm committed Oct 7, 2024
1 parent 09f14f3 commit e1c47db
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 80 deletions.
60 changes: 29 additions & 31 deletions omnn/math/Exponentiation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace omnn::math {
{
return getMaxVaExp(getBase(), getExponentiation());
}

Valuable Exponentiation::varless() const
{
if (FindVa())
Expand Down Expand Up @@ -91,7 +91,7 @@ namespace omnn::math {
Become(std::move(ebase()));
return;
}

if (eexp().IsSum())
{
auto& s = eexp().as<Sum>();
Expand Down Expand Up @@ -203,7 +203,7 @@ namespace omnn::math {
// }
// }
// }

if (ebase().IsFraction() && eexp().IsMultival()==YesNoMaybe::No) {
auto& f = ebase().as<Fraction>();
auto _ = (f.getNumerator() ^ eexp()) / (f.getDenominator() ^ eexp());
Expand Down Expand Up @@ -232,7 +232,7 @@ namespace omnn::math {
if (p.Has(constants::pi) &&
p.Has(constants::i)) { // TODO : sequence does matter :
// e^(i*pi) =?= e^(pi*i)
// https://en.wikipedia.org/wiki/Commutative_property#Division,_subtraction,_and_exponentiation
// https://en.wikipedia.org/wiki/Commutative_property#Division,_subtraction,_and_exponentiation
// what about Commutativity on irrationals product?
// lets assume yes for this particular expression, but there are some doubts, need a prove

Expand Down Expand Up @@ -496,7 +496,7 @@ namespace omnn::math {
InitVars();
}
}

Valuable& Exponentiation::operator +=(const Valuable& v)
{
return Become(Sum {*this, v});
Expand Down Expand Up @@ -660,7 +660,7 @@ namespace omnn::math {
// copy.updateBase(std::move(is.second));
// is.second = copy;
// }
//} else
//} else
if (ee == constants::minus_1)
{
auto gcd = ebase().GCD(v);
Expand Down Expand Up @@ -760,14 +760,14 @@ namespace omnn::math {
thisValues.insert(thisVal);
return true;
});

v.Values([&](auto& vVal) {
for (auto& tv : thisValues) {
vals.insert(tv / vVal);
}
return true;
});

return Become(Valuable(std::move(vals)));
}
else if (v.IsExponentiation())
Expand Down Expand Up @@ -810,7 +810,7 @@ namespace omnn::math {
optimize();
return *this;
}

bool Exponentiation::operator ==(const Valuable& v) const
{
auto eq = v.IsExponentiation() && Hash()==v.Hash();
Expand All @@ -829,7 +829,7 @@ namespace omnn::math {
}
return eq;
}

Exponentiation::operator double() const
{
return std::pow(static_cast<double>(ebase()), static_cast<double>(eexp()));
Expand All @@ -842,9 +842,9 @@ namespace omnn::math {
if(ehx) {
IMPLEMENT
if(bhx){

}else{

}
} else if (bhx) {
if(ebase() == x)
Expand All @@ -856,7 +856,7 @@ namespace omnn::math {
optimize();
return *this;
}

Valuable& Exponentiation::integral(const Variable& x, const Variable& C)
{
if (ebase()==x) {
Expand All @@ -875,7 +875,7 @@ namespace omnn::math {
} else {
IMPLEMENT
}

return *this;
}

Expand All @@ -889,7 +889,7 @@ namespace omnn::math {
if (e.getExponentiation() == getExponentiation())
return getBase() < e.getBase();
}

return base::operator <(v);
}

Expand All @@ -909,27 +909,27 @@ namespace omnn::math {
is = _2.as<Fraction>().getDenominator().IsEven() || is;
return is;
}

void Exponentiation::Values(const std::function<bool(const Valuable&)>& fun) const
{
if (fun) {
auto cache = optimized; // TODO: multival caching (inspect all optimized and optimization transisions) auto isCached =

solutions_t vals;
{
std::deque<Valuable> d1;
_1.Values([&](auto& v){
d1.push_back(v);
return true;
});

_2.Values([&](auto& v){
auto vIsFrac = v.IsFraction();
const Fraction* f;
if(vIsFrac)
f = &v.template as<Fraction>();
auto vMakesMultival = vIsFrac && f->getDenominator().IsEven()==YesNoMaybe::Yes;

for(auto& item1:d1){
if(vMakesMultival){
static const Variable x;
Expand All @@ -949,7 +949,7 @@ namespace omnn::math {
return true;
});
}

for(auto& v:vals)
fun(v);
}
Expand All @@ -968,7 +968,7 @@ namespace omnn::math {
out << "pow(";
getBase().code(out) << ',';
getExponentiation().code(out) << ')';
}
}
return out;
}

Expand Down Expand Up @@ -1001,7 +1001,7 @@ namespace omnn::math {
if (c != ec)
is = c > ec;
else {
is = getBase().IsComesBefore(e.getBase()) ||
is = getBase().IsComesBefore(e.getBase()) ||
(!e.ebase().IsComesBefore(ebase()) && getExponentiation().IsComesBefore(e.getExponentiation())); // || str().length() > e->str().length();
// auto expComesBefore = eexp().IsComesBefore(e->eexp());
// auto ebase()ComesBefore = ebase().IsComesBefore(e->ebase());
Expand All @@ -1026,7 +1026,7 @@ namespace omnn::math {

return is;
}

Valuable Exponentiation::calcFreeMember() const
{
Valuable c;
Expand Down Expand Up @@ -1061,16 +1061,15 @@ namespace omnn::math {
}

Valuable& Exponentiation::sqrt() {
hash ^= _2.Hash();
hash ^= _2.Hash();
_2 /= 2;
hash ^= _2.Hash();
optimized = {};
optimize();
return *this;
}

const Valuable::vars_cont_t& Exponentiation::getCommonVars() const
{
const Valuable::vars_cont_t& Exponentiation::getCommonVars() const {
#ifndef NDEBUG
auto& b = ebase();
if (b.IsVa()) { // TODO: FindVa too
Expand All @@ -1082,14 +1081,13 @@ namespace omnn::math {
}

//<< (v.begin()->first == b)
LOG_AND_IMPLEMENT(*this << " Exponentiation::getCommonVars not ready, no " << b << " in v "
);
LOG_AND_IMPLEMENT(*this << " Exponentiation::getCommonVars not ready, no " << b << " in v ");
}
}
#endif
return v;
}

Valuable::vars_cont_t Exponentiation::GetVaExps() const
{
auto vaExps = getBase().GetVaExps();
Expand All @@ -1099,7 +1097,7 @@ namespace omnn::math {
}
return vaExps;
}

Valuable Exponentiation::InCommonWith(const Valuable& v) const
{
auto c = 1_v;
Expand Down Expand Up @@ -1161,7 +1159,7 @@ namespace omnn::math {
}
return c;
}

Valuable Exponentiation::operator()(const Variable& va) const
{
return operator()(va, constants::zero);
Expand Down
34 changes: 19 additions & 15 deletions omnn/math/Exponentiation.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,50 @@
//
#pragma once
#include <omnn/math/Variable.h>
#include <omnn/math/DuoValDescendant.h>
#include <omnn/math/Logarithm.h>

namespace omnn::math {

class Exponentiation
: public DuoValDescendant<Exponentiation>
: public DuoValDescendant<Exponentiation>
{
using base = DuoValDescendant<Exponentiation>;
using base = DuoValDescendant<Exponentiation>;
vars_cont_t v;
void InitVars();

protected:
Valuable& ebase() { return base::_1; }
Valuable& eexp() { return base::_2; }
friend Logarithm;
constexpr Valuable& ebase() { return base::_1; }
constexpr Valuable& eexp() { return base::_2; }
std::ostream& print_sign(std::ostream& out) const override;
public:
std::ostream& code(std::ostream& out) const override;

// DONT: overrides behaviour (calls InitVars)
// using base::base;
// using base::base;

template <class BaseT, class ExponentiationT>
template <class BaseT, class ExponentiationT>
Exponentiation(BaseT&& b, ExponentiationT&& e)
: base(std::forward<BaseT>(b), std::forward<ExponentiationT>(e))
{
{
InitVars();
}

static constexpr auto GetBinaryOperationLambdaTemplate() {
return [](const auto& base, const auto& exp) { return ::std::pow(base, exp); };
}

[[nodiscard]]
bool IsExponentiation() const override { return true; }
[[nodiscard]]
bool IsVaExp() const override { return ebase().IsVa(); }
[[nodiscard]]
bool IsSimple() const override {
return !FindVa() && eexp().IsInt();
}
return !FindVa() && eexp().IsInt();
}
[[nodiscard]]
bool IsZero() const override { return _1.IsZero() && !_2.IsZero(); }


Valuable Sign() const override;
bool IsMultiSign() const;
YesNoMaybe IsMultival() const override;
Expand All @@ -52,14 +56,14 @@ class Exponentiation
template<class T>
void setBase(T&& b)
{
set1(::std::forward<T>(b));
set1(::std::forward<T>(b));
InitVars();
optimized = {};
}
template<class T>
void updateBase(T&& b)
{
update1(std::forward<T>(b));
update1(std::forward<T>(b));
InitVars();
optimized = {};
}
Expand All @@ -69,14 +73,14 @@ class Exponentiation
template<class T>
void setExponentiation(T&& exponentiation)
{
set2(std::forward<T>(exponentiation));
set2(std::forward<T>(exponentiation));
InitVars();
optimized = {};
}
template<class T>
void updateExponentiation(T&& exponentiation)
{
update2(std::forward<T>(exponentiation));
update2(std::forward<T>(exponentiation));
InitVars();
optimized = {};
}
Expand Down
Loading

0 comments on commit e1c47db

Please sign in to comment.