Skip to content

Commit

Permalink
Add new functions and rework operators
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Feb 24, 2024
1 parent df8c9d6 commit 3c7dc43
Show file tree
Hide file tree
Showing 49 changed files with 545 additions and 325 deletions.
70 changes: 44 additions & 26 deletions include/fintamath/core/MathObjectType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,22 @@ struct MathObjectType final {

IFunction = 11000,

Abs,
Log,
Ln,
Lb,
Lg,
Add,
Sub,
Mul,
Div,
Frac,
FracMixed,
Neg,
Pow,
Exp,
Sqr,
Sqrt,
Root,
Log,
Ln,
Lb,
Lg,
Sin,
Cos,
Tan,
Expand All @@ -113,27 +120,14 @@ struct MathObjectType final {
Acoth,
Asech,
Acsch,
Abs,
Factorial,
Floor,
Ceil,
Min,
Max,
Derivative,
Integral,
Frac,
FracMixed,
PowFunction,
Floor,
Ceil,

IOperator = 12000,

Add,
Sub,
Mul,
Div,
Neg,
UnaryPlus,
Factorial,
Percent,
Pow,
Eqv,
Neqv,
Less,
Expand All @@ -146,10 +140,34 @@ struct MathObjectType final {
Impl,
Equiv,
Nequiv,
Index,
Deg,
Comma,
Mod,

IOperator = 12000,

AddOper,
SubOper,
MulOper,
DivOper,
NegOper,
PlusOper,
PowOper,
FactorialOper,
PercentOper,
DegOper,
ModOper,
EqvOper,
NeqvOper,
LessOper,
MoreOper,
LessEqvOper,
MoreEqvOper,
NotOper,
AndOper,
OrOper,
ImplOper,
EquivOper,
NequivOper,
IndexOper,
CommaOper,

None = std::numeric_limits<size_t>::max(),
};
Expand Down
2 changes: 2 additions & 0 deletions include/fintamath/expressions/ExpressionUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ std::pair<ArgumentPtr, ArgumentPtr> splitRational(const ArgumentPtr &arg);

ArgumentPtr negate(const ArgumentPtr &arg);

ArgumentPtr invert(const ArgumentPtr &arg);

ArgumentPtr makePolynom(const IFunction &func, ArgumentPtrVector &&args);

ArgumentPtr makePolynom(const IFunction &func, const ArgumentPtrVector &args);
Expand Down
31 changes: 26 additions & 5 deletions include/fintamath/functions/arithmetic/Add.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,32 @@
#include "fintamath/core/MathObjectType.hpp"
#include "fintamath/functions/FunctionArguments.hpp"
#include "fintamath/functions/FunctionUtils.hpp"
#include "fintamath/functions/IFunction.hpp"
#include "fintamath/functions/IOperator.hpp"

namespace fintamath {

class Add final : public IOperatorCRTP<IArithmetic, Add, IArithmetic, IArithmetic> {
class Add final : public IFunctionCRTP<IArithmetic, Add, IArithmetic> {
public:
std::string toString() const override {
return "add";
}

static constexpr bool isVariadicStatic() {
return true;
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Add, "Add"};
}

protected:
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override;
};

FINTAMATH_FUNCTION_EXPRESSION(Add, addExpr);

class AddOper final : public IOperatorCRTP<IArithmetic, AddOper, IArithmetic, IArithmetic> {
public:
std::string toString() const override {
return "+";
Expand All @@ -27,13 +48,13 @@ class Add final : public IOperatorCRTP<IArithmetic, Add, IArithmetic, IArithmeti
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Add, "Add"};
return {MathObjectType::AddOper, "AddOper"};
}

protected:
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override;
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override{
return Add{}(argVect);
}
};

FINTAMATH_FUNCTION_EXPRESSION(Add, addExpr);

}
27 changes: 22 additions & 5 deletions include/fintamath/functions/arithmetic/Div.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,31 @@
#include "fintamath/core/MathObjectType.hpp"
#include "fintamath/functions/FunctionArguments.hpp"
#include "fintamath/functions/FunctionUtils.hpp"
#include "fintamath/functions/IFunction.hpp"
#include "fintamath/functions/IOperator.hpp"

namespace fintamath {

class Integer;
class INumber;

class Div final : public IOperatorCRTP<IArithmetic, Div, IArithmetic, IArithmetic> {
class Div final : public IFunctionCRTP<IArithmetic, Div, IArithmetic, IArithmetic> {
public:
std::string toString() const override {
return "div";
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Div, "Div"};
}

protected:
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override;
};

FINTAMATH_FUNCTION_EXPRESSION(Div, divExpr);

class DivOper final : public IOperatorCRTP<IArithmetic, DivOper, IArithmetic, IArithmetic> {
public:
std::string toString() const override {
return "/";
Expand All @@ -26,13 +43,13 @@ class Div final : public IOperatorCRTP<IArithmetic, Div, IArithmetic, IArithmeti
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Div, "Div"};
return {MathObjectType::DivOper, "DivOper"};
}

protected:
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override;
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override {
return Div{}(argVect);
}
};

FINTAMATH_FUNCTION_EXPRESSION(Div, divExpr);

}
31 changes: 26 additions & 5 deletions include/fintamath/functions/arithmetic/Mul.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,32 @@
#include "fintamath/core/MathObjectType.hpp"
#include "fintamath/functions/FunctionArguments.hpp"
#include "fintamath/functions/FunctionUtils.hpp"
#include "fintamath/functions/IFunction.hpp"
#include "fintamath/functions/IOperator.hpp"

namespace fintamath {

class Mul final : public IOperatorCRTP<IArithmetic, Mul, IArithmetic, IArithmetic> {
class Mul final : public IFunctionCRTP<IArithmetic, Mul, IArithmetic> {
public:
std::string toString() const override {
return "mul";
}

static constexpr bool isVariadicStatic() {
return true;
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Mul, "Mul"};
}

protected:
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override;
};

FINTAMATH_FUNCTION_EXPRESSION(Mul, mulExpr);

class MulOper final : public IOperatorCRTP<IArithmetic, MulOper, IArithmetic, IArithmetic> {
public:
std::string toString() const override {
return "*";
Expand All @@ -27,13 +48,13 @@ class Mul final : public IOperatorCRTP<IArithmetic, Mul, IArithmetic, IArithmeti
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Mul, "Mul"};
return {MathObjectType::MulOper, "MulOper"};
}

protected:
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override;
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override {
return Mul{}(argVect);
}
};

FINTAMATH_FUNCTION_EXPRESSION(Mul, mulExpr);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace fintamath {

class UnaryPlus final : public IOperatorCRTP<IArithmetic, UnaryPlus, IArithmetic> {
class PlusOper final : public IOperatorCRTP<IArithmetic, PlusOper, IArithmetic> {
public:
std::string toString() const override {
return "+";
Expand All @@ -22,7 +22,7 @@ class UnaryPlus final : public IOperatorCRTP<IArithmetic, UnaryPlus, IArithmetic
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::UnaryPlus, "UnaryPlus"};
return {MathObjectType::PlusOper, "PlusOper"};
}

protected:
Expand Down
2 changes: 1 addition & 1 deletion include/fintamath/functions/ntheory/Mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Mod final : public IOperatorCRTP<INumber, Mod, INumber, INumber> {
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Mod, "Mod"};
return {MathObjectType::ModOper, "ModOper"};
}

protected:
Expand Down
4 changes: 1 addition & 3 deletions include/fintamath/functions/other/Comma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ class Comma final : public IOperatorCRTP<IMathObject, Comma, IMathObject, IMathO
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Comma, "Comma"};
return {MathObjectType::CommaOper, "CommaOper"};
}

protected:
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override;
};

FINTAMATH_FUNCTION_EXPRESSION(Comma, commaExpr);

}
4 changes: 1 addition & 3 deletions include/fintamath/functions/other/Deg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ class Deg final : public IOperatorCRTP<INumber, Deg, INumber> {
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Deg, "Deg"};
return {MathObjectType::DegOper, "DegOper"};
}

protected:
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override;
};

FINTAMATH_FUNCTION_EXPRESSION(Deg, degExpr);

}
4 changes: 1 addition & 3 deletions include/fintamath/functions/other/Index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ class Index final : public IOperatorCRTP<Variable, Index, Variable, Integer> {
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Index, "Index"};
return {MathObjectType::IndexOper, "IndexOper"};
}

protected:
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override;
};

FINTAMATH_FUNCTION_EXPRESSION(Index, indexExpr);

}
4 changes: 1 addition & 3 deletions include/fintamath/functions/other/Percent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ class Percent final : public IOperatorCRTP<INumber, Percent, INumber> {
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Percent, "Percent"};
return {MathObjectType::PercentOper, "PercentOper"};
}

protected:
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override;
};

FINTAMATH_FUNCTION_EXPRESSION(Percent, percentExpr);

}
28 changes: 22 additions & 6 deletions include/fintamath/functions/powers/Pow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ class Rational;
class Real;
class Complex;

class Pow final : public IOperatorCRTP<INumber, Pow, INumber, INumber> {
class Pow final : public IFunctionCRTP<INumber, Pow, INumber, INumber> {
public:
std::string toString() const override {
return "^";
}

static constexpr Priority getPriorityStatic() {
return Priority::Exponentiation;
return "pow";
}

static constexpr MathObjectType getTypeStatic() {
Expand All @@ -48,4 +44,24 @@ class Pow final : public IOperatorCRTP<INumber, Pow, INumber, INumber> {

FINTAMATH_FUNCTION_EXPRESSION(Pow, powExpr);

class PowOper final : public IOperatorCRTP<IArithmetic, PowOper, IArithmetic, IArithmetic> {
public:
std::string toString() const override {
return "^";
}

static constexpr Priority getPriorityStatic() {
return Priority::Exponentiation;
}

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::PowOper, "PowOper"};
}

protected:
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argVect) const override {
return Pow{}(argVect);
}
};

}
Loading

0 comments on commit 3c7dc43

Please sign in to comment.