Skip to content

Commit

Permalink
Root simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Jul 3, 2023
1 parent 6d377e0 commit f03a2cc
Show file tree
Hide file tree
Showing 12 changed files with 361 additions and 157 deletions.
3 changes: 1 addition & 2 deletions include/fintamath/functions/IFunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class IFunction : public IMathObject {

static std::unique_ptr<IMathObject> makeExprChecked(const IFunction &function, const ArgumentsRefVector &args);

// TODO: uncomment
// static std::unique_ptr<IMathObject> makeExpr(const IFunction &function, const ArgumentsRefVector &args);
static std::unique_ptr<IMathObject> makeExpr(const IFunction &function, const ArgumentsPtrVector &args);

static bool isExpression(const ArgumentRef &arg);

Expand Down
20 changes: 20 additions & 0 deletions include/fintamath/functions/powers/Root.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "fintamath/functions/IFunction.hpp"
#include "fintamath/numbers/INumber.hpp"

namespace fintamath {

class Root : public IFunctionCRTP<INumber, Root, INumber, INumber> {
public:
Root() = default;

std::string toString() const override {
return "root";
}

protected:
std::unique_ptr<IMathObject> call(const ArgumentsRefVector &argsVect) const override;
};

}
2 changes: 2 additions & 0 deletions include/fintamath/numbers/IntegerFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Integer factorial(const Integer &rhs);

Integer factorial(const Integer &rhs, size_t order);

std::map<Integer, Integer> factors(Integer rhs, Integer limit = -1);

Integer combinations(const Integer &totalNumber, const Integer &choosedNumber);

Integer multinomialCoefficient(const Integer &totalNumber, const std::vector<Integer> &groupNumbers);
Expand Down
6 changes: 6 additions & 0 deletions src/fintamath/config/ExpressionConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "fintamath/functions/other/Rad.hpp"
#include "fintamath/functions/powers/Exp.hpp"
#include "fintamath/functions/powers/Pow.hpp"
#include "fintamath/functions/powers/Root.hpp"
#include "fintamath/functions/powers/Sqrt.hpp"
#include "fintamath/functions/trigonometry/Acos.hpp"
#include "fintamath/functions/trigonometry/Acot.hpp"
Expand Down Expand Up @@ -308,6 +309,11 @@ struct ExpressionConfig {
return makeExpr(Pow(), args.front(), std::make_shared<Rational>(1, 2));
});

// TODO! uncomment
// Expression::registerFunctionExpressionMaker<Root>([](const ArgumentsPtrVector &args) {
// return makeExpr(Pow(), args.front(), makeExpr(Div(), std::make_shared<Integer>(1), args.back()));
// });

Expression::registerFunctionExpressionMaker<Sin>([](const ArgumentsPtrVector &args) {
return std::make_shared<TrigonometryExpression>(Sin(), args.front());
});
Expand Down
7 changes: 3 additions & 4 deletions src/fintamath/config/FunctionConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ std::unique_ptr<IMathObject> IFunction::makeExprChecked(const IFunction &functio
return fintamath::makeExprChecked(function, args);
}

// TODO: uncomment
// std::unique_ptr<IMathObject> IFunction::makeExpr(const IFunction &function, const ArgumentsRefVector &args) {
// return fintamath::makeExpr(function, args);
// }
std::unique_ptr<IMathObject> IFunction::makeExpr(const IFunction &function, const ArgumentsPtrVector &args) {
return fintamath::makeExpr(function, args)->clone();
}

bool IFunction::isExpression(const ArgumentRef &arg) {
return is<IExpression>(arg);
Expand Down
2 changes: 2 additions & 0 deletions src/fintamath/config/ParserConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "fintamath/functions/other/Rad.hpp"
#include "fintamath/functions/powers/Exp.hpp"
#include "fintamath/functions/powers/Pow.hpp"
#include "fintamath/functions/powers/Root.hpp"
#include "fintamath/functions/powers/Sqrt.hpp"
#include "fintamath/functions/trigonometry/Acos.hpp"
#include "fintamath/functions/trigonometry/Acot.hpp"
Expand Down Expand Up @@ -172,6 +173,7 @@ struct ParserConfig {
IFunction::registerType<Lg>();
IFunction::registerType<Exp>();
IFunction::registerType<Sqrt>();
IFunction::registerType<Root>();
IFunction::registerType<Sin>();
IFunction::registerType<Cos>();
IFunction::registerType<Tan>();
Expand Down
Loading

0 comments on commit f03a2cc

Please sign in to comment.