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 Mar 3, 2024
1 parent df8c9d6 commit 0459241
Show file tree
Hide file tree
Showing 44 changed files with 706 additions and 217 deletions.
29 changes: 16 additions & 13 deletions include/fintamath/core/MathObjectType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ struct MathObjectType final {

IFunction = 11000,

Add,
Mul,
Pow,
Abs,
Log,
Ln,
Expand Down Expand Up @@ -119,37 +122,37 @@ struct MathObjectType final {
Integral,
Frac,
FracMixed,
PowFunction,
Floor,
Ceil,
And,
Or,

IOperator = 12000,

Add,
AddOper,
UnaryPlus,
Sub,
Mul,
Div,
Neg,
UnaryPlus,
MulOper,
Div,
Mod,
PowOper,
Factorial,
Percent,
Pow,
Deg,
Index,
Comma,
Eqv,
Neqv,
Less,
More,
LessEqv,
MoreEqv,
Not,
And,
Or,
AndOper,
OrOper,
Impl,
Equiv,
Nequiv,
Index,
Deg,
Comma,
Mod,

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
12 changes: 4 additions & 8 deletions include/fintamath/functions/arithmetic/Add.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@
#include "fintamath/core/MathObjectType.hpp"
#include "fintamath/functions/FunctionArguments.hpp"
#include "fintamath/functions/FunctionUtils.hpp"
#include "fintamath/functions/IOperator.hpp"
#include "fintamath/functions/IFunction.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 "+";
return "add";
}

static constexpr bool isAssociativeStatic() {
static constexpr bool isVariadicStatic() {
return true;
}

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

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Add, "Add"};
}
Expand Down
36 changes: 36 additions & 0 deletions include/fintamath/functions/arithmetic/AddOper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <memory>
#include <string>

#include "fintamath/core/IArithmetic.hpp"
#include "fintamath/core/IMathObject.hpp"
#include "fintamath/core/MathObjectType.hpp"
#include "fintamath/functions/FunctionArguments.hpp"
#include "fintamath/functions/IOperator.hpp"

namespace fintamath {

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

static constexpr bool isAssociativeStatic() {
return true;
}

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

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

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

}
12 changes: 4 additions & 8 deletions include/fintamath/functions/arithmetic/Mul.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@
#include "fintamath/core/MathObjectType.hpp"
#include "fintamath/functions/FunctionArguments.hpp"
#include "fintamath/functions/FunctionUtils.hpp"
#include "fintamath/functions/IOperator.hpp"
#include "fintamath/functions/IFunction.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 "*";
return "mul";
}

static constexpr bool isAssociativeStatic() {
static constexpr bool isVariadicStatic() {
return true;
}

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

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Mul, "Mul"};
}
Expand Down
36 changes: 36 additions & 0 deletions include/fintamath/functions/arithmetic/MulOper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <memory>
#include <string>

#include "fintamath/core/IArithmetic.hpp"
#include "fintamath/core/IMathObject.hpp"
#include "fintamath/core/MathObjectType.hpp"
#include "fintamath/functions/FunctionArguments.hpp"
#include "fintamath/functions/IOperator.hpp"

namespace fintamath {

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

static constexpr bool isAssociativeStatic() {
return true;
}

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

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

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

}
11 changes: 4 additions & 7 deletions include/fintamath/functions/logic/And.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@
#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"
#include "fintamath/literals/Boolean.hpp"

namespace fintamath {

class And final : public IOperatorCRTP<Boolean, And, Boolean, Boolean> {
class And final : public IFunctionCRTP<Boolean, And, Boolean> {
public:
std::string toString() const override {
return "&";
return "and";
}

static constexpr bool isAssociativeStatic() {
static constexpr bool isVariadicStatic() {
return true;
}

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

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::And, "And"};
}
Expand Down
36 changes: 36 additions & 0 deletions include/fintamath/functions/logic/AndOper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <memory>
#include <string>

#include "fintamath/core/IMathObject.hpp"
#include "fintamath/core/MathObjectType.hpp"
#include "fintamath/functions/FunctionArguments.hpp"
#include "fintamath/functions/IOperator.hpp"
#include "fintamath/literals/Boolean.hpp"

namespace fintamath {

class AndOper final : public IOperatorCRTP<Boolean, AndOper, Boolean, Boolean> {
public:
std::string toString() const override {
return "&";
}

static constexpr bool isAssociativeStatic() {
return true;
}

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

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

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

}
12 changes: 4 additions & 8 deletions include/fintamath/functions/logic/Or.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@
#include "fintamath/core/MathObjectType.hpp"
#include "fintamath/functions/FunctionArguments.hpp"
#include "fintamath/functions/FunctionUtils.hpp"
#include "fintamath/functions/IOperator.hpp"
#include "fintamath/functions/IFunction.hpp"
#include "fintamath/literals/Boolean.hpp"

namespace fintamath {

class Or final : public IOperatorCRTP<Boolean, Or, Boolean, Boolean> {
class Or final : public IFunctionCRTP<Boolean, Or, Boolean, Boolean> {
public:
std::string toString() const override {
return "|";
return "or";
}

static constexpr bool isAssociativeStatic() {
static constexpr bool isVariadicStatic() {
return true;
}

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

static constexpr MathObjectType getTypeStatic() {
return {MathObjectType::Or, "Or"};
}
Expand Down
38 changes: 38 additions & 0 deletions include/fintamath/functions/logic/OrOper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include <memory>
#include <string>

#include "fintamath/core/IMathObject.hpp"
#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"
#include "fintamath/literals/Boolean.hpp"

namespace fintamath {

class OrOper final : public IOperatorCRTP<Boolean, OrOper, Boolean, Boolean> {
public:
std::string toString() const override {
return "|";
}

static constexpr bool isAssociativeStatic() {
return true;
}

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

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

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

}
8 changes: 2 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
#include "fintamath/core/IMathObject.hpp"
#include "fintamath/core/MathObjectType.hpp"
#include "fintamath/functions/FunctionArguments.hpp"
#include "fintamath/functions/IFunction.hpp"
#include "fintamath/functions/IOperator.hpp"

namespace fintamath {

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

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

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

protected:
Expand Down
Loading

0 comments on commit 0459241

Please sign in to comment.