From a640dbf6537073fe06da8819fdcacf4398bb4c5d Mon Sep 17 00:00:00 2001 From: fintarin Date: Sat, 26 Aug 2023 11:49:27 +0300 Subject: [PATCH 1/4] Add wrappers to makeExpr --- include/fintamath/functions/FunctionUtils.hpp | 7 ++ .../fintamath/functions/arithmetic/Abs.hpp | 2 + .../fintamath/functions/arithmetic/Add.hpp | 2 + .../fintamath/functions/arithmetic/Div.hpp | 2 + .../fintamath/functions/arithmetic/Mul.hpp | 2 + .../fintamath/functions/arithmetic/Neg.hpp | 2 + .../fintamath/functions/arithmetic/Sign.hpp | 2 + .../fintamath/functions/arithmetic/Sub.hpp | 2 + .../functions/calculus/Derivative.hpp | 2 + .../fintamath/functions/calculus/Integral.hpp | 2 + include/fintamath/functions/calculus/Max.hpp | 2 + include/fintamath/functions/calculus/Min.hpp | 2 + .../fintamath/functions/comparison/Eqv.hpp | 2 + .../fintamath/functions/comparison/Less.hpp | 2 + .../functions/comparison/LessEqv.hpp | 2 + .../fintamath/functions/comparison/More.hpp | 2 + .../functions/comparison/MoreEqv.hpp | 2 + .../fintamath/functions/comparison/Neqv.hpp | 2 + .../fintamath/functions/hyperbolic/Acosh.hpp | 2 + .../fintamath/functions/hyperbolic/Acoth.hpp | 2 + .../fintamath/functions/hyperbolic/Asinh.hpp | 2 + .../fintamath/functions/hyperbolic/Atanh.hpp | 2 + .../fintamath/functions/hyperbolic/Cosh.hpp | 2 + .../fintamath/functions/hyperbolic/Coth.hpp | 2 + .../fintamath/functions/hyperbolic/Sinh.hpp | 2 + .../fintamath/functions/hyperbolic/Tanh.hpp | 2 + include/fintamath/functions/logarithms/Lb.hpp | 2 + include/fintamath/functions/logarithms/Lg.hpp | 2 + include/fintamath/functions/logarithms/Ln.hpp | 2 + .../fintamath/functions/logarithms/Log.hpp | 2 + include/fintamath/functions/logic/And.hpp | 2 + include/fintamath/functions/logic/Equiv.hpp | 2 + include/fintamath/functions/logic/Impl.hpp | 2 + include/fintamath/functions/logic/Nequiv.hpp | 2 + include/fintamath/functions/logic/Not.hpp | 2 + include/fintamath/functions/logic/Or.hpp | 2 + include/fintamath/functions/other/Deg.hpp | 2 + .../fintamath/functions/other/Factorial.hpp | 2 + include/fintamath/functions/other/Index.hpp | 2 + include/fintamath/functions/other/Percent.hpp | 2 + include/fintamath/functions/powers/Exp.hpp | 2 + include/fintamath/functions/powers/Pow.hpp | 2 + include/fintamath/functions/powers/Root.hpp | 2 + include/fintamath/functions/powers/Sqrt.hpp | 2 + .../fintamath/functions/trigonometry/Acos.hpp | 2 + .../fintamath/functions/trigonometry/Acot.hpp | 2 + .../fintamath/functions/trigonometry/Asin.hpp | 2 + .../fintamath/functions/trigonometry/Atan.hpp | 2 + .../fintamath/functions/trigonometry/Cos.hpp | 5 ++ .../fintamath/functions/trigonometry/Cot.hpp | 2 + .../fintamath/functions/trigonometry/Sin.hpp | 2 + .../fintamath/functions/trigonometry/Tan.hpp | 2 + src/fintamath/config/ExpressionConfig.cpp | 40 +++++----- src/fintamath/expressions/Expression.cpp | 24 +++--- .../expressions/binary/CompExpression.cpp | 8 +- .../expressions/binary/DivExpression.cpp | 78 +++++++++---------- .../expressions/binary/IntegralExpression.cpp | 4 +- .../expressions/binary/LogExpression.cpp | 10 +-- .../expressions/binary/PowExpression.cpp | 42 +++++----- .../functions/ExpressionFunctionSolve.cpp | 6 +- .../expressions/polynomial/AddExpression.cpp | 72 ++++++++--------- .../expressions/polynomial/AndExpression.cpp | 4 +- .../expressions/polynomial/MulExpression.cpp | 31 ++++---- .../expressions/polynomial/OrExpression.cpp | 6 +- .../expressions/unary/InvTrigExpression.cpp | 64 +++++++-------- .../expressions/unary/NotExpression.cpp | 8 +- .../expressions/unary/TrigExpression.cpp | 76 +++++++++--------- src/fintamath/functions/other/Deg.cpp | 4 +- src/fintamath/functions/powers/Root.cpp | 18 ++--- src/fintamath/functions/trigonometry/Acos.cpp | 2 +- src/fintamath/functions/trigonometry/Acot.cpp | 6 +- src/fintamath/functions/trigonometry/Asin.cpp | 4 +- src/fintamath/functions/trigonometry/Atan.cpp | 4 +- .../expressions/FunctionExpressionTests.cpp | 3 +- tests/src/expressions/IExpressionTests.cpp | 20 ++--- .../binary/CompExpressionTests.cpp | 2 +- .../binary/DerivativeExpressionTests.cpp | 3 +- .../expressions/binary/DivExpressionTests.cpp | 2 +- .../binary/IntegralExpressionTests.cpp | 3 +- .../expressions/binary/LogExpressionTests.cpp | 2 +- .../expressions/binary/PowExpressionTests.cpp | 2 +- .../interfaces/IPolynomExpressionTests.cpp | 2 +- .../polynomial/AddExpressionTests.cpp | 2 +- .../polynomial/AndExpressionTests.cpp | 2 +- .../polynomial/MinMaxExpressionTests.cpp | 2 +- .../polynomial/MulExpressionTests.cpp | 2 +- .../polynomial/OrExpressionTests.cpp | 2 +- .../unary/HyperbExpressionTests.cpp | 2 +- .../unary/InvHyperbExpressionTests.cpp | 2 +- .../unary/InvTrigExpressionTests.cpp | 2 +- .../expressions/unary/NotExpressionTests.cpp | 2 +- .../expressions/unary/TrigExpressionTests.cpp | 2 +- 92 files changed, 392 insertions(+), 290 deletions(-) diff --git a/include/fintamath/functions/FunctionUtils.hpp b/include/fintamath/functions/FunctionUtils.hpp index 04647682b..4d5114903 100644 --- a/include/fintamath/functions/FunctionUtils.hpp +++ b/include/fintamath/functions/FunctionUtils.hpp @@ -7,6 +7,13 @@ #include "fintamath/functions/FunctionArguments.hpp" #include "fintamath/parser/Parser.hpp" +#define FINTAMATH_FUNCTION_EXPRESSION(Function, name) \ + template \ + std::unique_ptr name(Args &&...args) { \ + static const Function f; \ + return makeExpr(f, std::forward(args)...); \ + } + namespace fintamath { class IFunction; diff --git a/include/fintamath/functions/arithmetic/Abs.hpp b/include/fintamath/functions/arithmetic/Abs.hpp index e9e520425..4a783c828 100644 --- a/include/fintamath/functions/arithmetic/Abs.hpp +++ b/include/fintamath/functions/arithmetic/Abs.hpp @@ -24,4 +24,6 @@ class Abs : public IFunctionCRTP { static std::unique_ptr multiAbsSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Abs, absExpr); + } diff --git a/include/fintamath/functions/arithmetic/Add.hpp b/include/fintamath/functions/arithmetic/Add.hpp index 086b0dce7..58b9796f8 100644 --- a/include/fintamath/functions/arithmetic/Add.hpp +++ b/include/fintamath/functions/arithmetic/Add.hpp @@ -22,4 +22,6 @@ class Add : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Add, addExpr); + } diff --git a/include/fintamath/functions/arithmetic/Div.hpp b/include/fintamath/functions/arithmetic/Div.hpp index 59a8857e5..725f61d93 100644 --- a/include/fintamath/functions/arithmetic/Div.hpp +++ b/include/fintamath/functions/arithmetic/Div.hpp @@ -30,4 +30,6 @@ class Div : public IOperatorCRTP { static std::unique_ptr divSimplify(const Integer &lhs, const Integer &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Div, divExpr); + } diff --git a/include/fintamath/functions/arithmetic/Mul.hpp b/include/fintamath/functions/arithmetic/Mul.hpp index 82b054c20..fbb19508e 100644 --- a/include/fintamath/functions/arithmetic/Mul.hpp +++ b/include/fintamath/functions/arithmetic/Mul.hpp @@ -22,4 +22,6 @@ class Mul : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Mul, mulExpr); + } diff --git a/include/fintamath/functions/arithmetic/Neg.hpp b/include/fintamath/functions/arithmetic/Neg.hpp index 035f064c2..f9b5862fc 100644 --- a/include/fintamath/functions/arithmetic/Neg.hpp +++ b/include/fintamath/functions/arithmetic/Neg.hpp @@ -22,4 +22,6 @@ class Neg : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Neg, negExpr); + } diff --git a/include/fintamath/functions/arithmetic/Sign.hpp b/include/fintamath/functions/arithmetic/Sign.hpp index 3e5accea8..50621a583 100644 --- a/include/fintamath/functions/arithmetic/Sign.hpp +++ b/include/fintamath/functions/arithmetic/Sign.hpp @@ -24,4 +24,6 @@ class Sign : public IFunctionCRTP { static std::unique_ptr multiSignSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Sign, signExpr); + } diff --git a/include/fintamath/functions/arithmetic/Sub.hpp b/include/fintamath/functions/arithmetic/Sub.hpp index bb6352738..d92ee6a66 100644 --- a/include/fintamath/functions/arithmetic/Sub.hpp +++ b/include/fintamath/functions/arithmetic/Sub.hpp @@ -22,4 +22,6 @@ class Sub : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Sub, subExpr); + } diff --git a/include/fintamath/functions/calculus/Derivative.hpp b/include/fintamath/functions/calculus/Derivative.hpp index 9d57668b3..a105f1a5f 100644 --- a/include/fintamath/functions/calculus/Derivative.hpp +++ b/include/fintamath/functions/calculus/Derivative.hpp @@ -23,4 +23,6 @@ class Derivative : public IFunctionCRTP call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Derivative, derivativeExpr); + } diff --git a/include/fintamath/functions/calculus/Integral.hpp b/include/fintamath/functions/calculus/Integral.hpp index 65a486171..3055f825f 100644 --- a/include/fintamath/functions/calculus/Integral.hpp +++ b/include/fintamath/functions/calculus/Integral.hpp @@ -23,4 +23,6 @@ class Integral : public IFunctionCRTP call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Integral, integralExpr); + } diff --git a/include/fintamath/functions/calculus/Max.hpp b/include/fintamath/functions/calculus/Max.hpp index 5b699008e..9f9323973 100644 --- a/include/fintamath/functions/calculus/Max.hpp +++ b/include/fintamath/functions/calculus/Max.hpp @@ -24,4 +24,6 @@ class Max : public IFunctionCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Max, maxExpr); + } diff --git a/include/fintamath/functions/calculus/Min.hpp b/include/fintamath/functions/calculus/Min.hpp index 5585f7382..3430f6dad 100644 --- a/include/fintamath/functions/calculus/Min.hpp +++ b/include/fintamath/functions/calculus/Min.hpp @@ -24,4 +24,6 @@ class Min : public IFunctionCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Min, minExpr); + } diff --git a/include/fintamath/functions/comparison/Eqv.hpp b/include/fintamath/functions/comparison/Eqv.hpp index 922c9dc1d..955831782 100644 --- a/include/fintamath/functions/comparison/Eqv.hpp +++ b/include/fintamath/functions/comparison/Eqv.hpp @@ -23,4 +23,6 @@ class Eqv : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Eqv, eqvExpr); + } diff --git a/include/fintamath/functions/comparison/Less.hpp b/include/fintamath/functions/comparison/Less.hpp index 061d0630d..7f0a913c4 100644 --- a/include/fintamath/functions/comparison/Less.hpp +++ b/include/fintamath/functions/comparison/Less.hpp @@ -23,4 +23,6 @@ class Less : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Less, lessExpr); + } diff --git a/include/fintamath/functions/comparison/LessEqv.hpp b/include/fintamath/functions/comparison/LessEqv.hpp index 3e1ec899e..ef4c9a47f 100644 --- a/include/fintamath/functions/comparison/LessEqv.hpp +++ b/include/fintamath/functions/comparison/LessEqv.hpp @@ -23,4 +23,6 @@ class LessEqv : public IOperatorCRTP std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(LessEqv, lessEqvExpr); + } diff --git a/include/fintamath/functions/comparison/More.hpp b/include/fintamath/functions/comparison/More.hpp index 497de7fec..a6cfa6802 100644 --- a/include/fintamath/functions/comparison/More.hpp +++ b/include/fintamath/functions/comparison/More.hpp @@ -23,4 +23,6 @@ class More : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(More, moreExpr); + } diff --git a/include/fintamath/functions/comparison/MoreEqv.hpp b/include/fintamath/functions/comparison/MoreEqv.hpp index 7cdfef67c..5edbcb450 100644 --- a/include/fintamath/functions/comparison/MoreEqv.hpp +++ b/include/fintamath/functions/comparison/MoreEqv.hpp @@ -23,4 +23,6 @@ class MoreEqv : public IOperatorCRTP std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(MoreEqv, moreEqvExpr); + } diff --git a/include/fintamath/functions/comparison/Neqv.hpp b/include/fintamath/functions/comparison/Neqv.hpp index dc09151ac..dccd1ebc5 100644 --- a/include/fintamath/functions/comparison/Neqv.hpp +++ b/include/fintamath/functions/comparison/Neqv.hpp @@ -23,4 +23,6 @@ class Neqv : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Neqv, neqvExpr); + } diff --git a/include/fintamath/functions/hyperbolic/Acosh.hpp b/include/fintamath/functions/hyperbolic/Acosh.hpp index 87e4bd01c..8741cd3e7 100644 --- a/include/fintamath/functions/hyperbolic/Acosh.hpp +++ b/include/fintamath/functions/hyperbolic/Acosh.hpp @@ -28,4 +28,6 @@ class Acosh : public IFunctionCRTP { static std::unique_ptr acoshSimplify(const Real &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Acosh, acoshExpr); + } diff --git a/include/fintamath/functions/hyperbolic/Acoth.hpp b/include/fintamath/functions/hyperbolic/Acoth.hpp index 855272f81..b30a086f3 100644 --- a/include/fintamath/functions/hyperbolic/Acoth.hpp +++ b/include/fintamath/functions/hyperbolic/Acoth.hpp @@ -28,4 +28,6 @@ class Acoth : public IFunctionCRTP { static std::unique_ptr acothSimplify(const Real &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Acoth, acothExpr); + } diff --git a/include/fintamath/functions/hyperbolic/Asinh.hpp b/include/fintamath/functions/hyperbolic/Asinh.hpp index 73a3156d4..d1e38fd5e 100644 --- a/include/fintamath/functions/hyperbolic/Asinh.hpp +++ b/include/fintamath/functions/hyperbolic/Asinh.hpp @@ -24,4 +24,6 @@ class Asinh : public IFunctionCRTP { static std::unique_ptr multiAsinhSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Asinh, asinhExpr); + } diff --git a/include/fintamath/functions/hyperbolic/Atanh.hpp b/include/fintamath/functions/hyperbolic/Atanh.hpp index 55e1316d0..0dc04ac98 100644 --- a/include/fintamath/functions/hyperbolic/Atanh.hpp +++ b/include/fintamath/functions/hyperbolic/Atanh.hpp @@ -28,4 +28,6 @@ class Atanh : public IFunctionCRTP { static std::unique_ptr atanhSimplify(const Real &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Atanh, atanhExpr); + } diff --git a/include/fintamath/functions/hyperbolic/Cosh.hpp b/include/fintamath/functions/hyperbolic/Cosh.hpp index 798b60900..f654b514f 100644 --- a/include/fintamath/functions/hyperbolic/Cosh.hpp +++ b/include/fintamath/functions/hyperbolic/Cosh.hpp @@ -24,4 +24,6 @@ class Cosh : public IFunctionCRTP { static std::unique_ptr multiCoshSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Cosh, coshExpr); + } diff --git a/include/fintamath/functions/hyperbolic/Coth.hpp b/include/fintamath/functions/hyperbolic/Coth.hpp index 4843bfaac..1e41e9097 100644 --- a/include/fintamath/functions/hyperbolic/Coth.hpp +++ b/include/fintamath/functions/hyperbolic/Coth.hpp @@ -24,4 +24,6 @@ class Coth : public IFunctionCRTP { static std::unique_ptr multiCothSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Coth, cothExpr); + } diff --git a/include/fintamath/functions/hyperbolic/Sinh.hpp b/include/fintamath/functions/hyperbolic/Sinh.hpp index 3d463f641..dc9168c2a 100644 --- a/include/fintamath/functions/hyperbolic/Sinh.hpp +++ b/include/fintamath/functions/hyperbolic/Sinh.hpp @@ -24,4 +24,6 @@ class Sinh : public IFunctionCRTP { static std::unique_ptr multiSinhSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Sinh, sinhExpr); + } diff --git a/include/fintamath/functions/hyperbolic/Tanh.hpp b/include/fintamath/functions/hyperbolic/Tanh.hpp index d71e83a82..9fb89be4a 100644 --- a/include/fintamath/functions/hyperbolic/Tanh.hpp +++ b/include/fintamath/functions/hyperbolic/Tanh.hpp @@ -24,4 +24,6 @@ class Tanh : public IFunctionCRTP { static std::unique_ptr multiTanhSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Tanh, tanhExpr); + } diff --git a/include/fintamath/functions/logarithms/Lb.hpp b/include/fintamath/functions/logarithms/Lb.hpp index 4f7246ef0..6ee7708b5 100644 --- a/include/fintamath/functions/logarithms/Lb.hpp +++ b/include/fintamath/functions/logarithms/Lb.hpp @@ -21,4 +21,6 @@ class Lb : public IFunctionCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Lb, lbExpr); + } diff --git a/include/fintamath/functions/logarithms/Lg.hpp b/include/fintamath/functions/logarithms/Lg.hpp index 1c7afefee..8e1f53721 100644 --- a/include/fintamath/functions/logarithms/Lg.hpp +++ b/include/fintamath/functions/logarithms/Lg.hpp @@ -21,4 +21,6 @@ class Lg : public IFunctionCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Lg, lgExpr); + } diff --git a/include/fintamath/functions/logarithms/Ln.hpp b/include/fintamath/functions/logarithms/Ln.hpp index 008e20dd2..5b99f6f4a 100644 --- a/include/fintamath/functions/logarithms/Ln.hpp +++ b/include/fintamath/functions/logarithms/Ln.hpp @@ -24,4 +24,6 @@ class Ln : public IFunctionCRTP { static std::unique_ptr multiLnSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Ln, lnExpr); + } diff --git a/include/fintamath/functions/logarithms/Log.hpp b/include/fintamath/functions/logarithms/Log.hpp index 42c32912b..6e4e43ef9 100644 --- a/include/fintamath/functions/logarithms/Log.hpp +++ b/include/fintamath/functions/logarithms/Log.hpp @@ -32,4 +32,6 @@ class Log : public IFunctionCRTP { static std::unique_ptr logSimplify(const Real &lhs, const Real &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Log, logExpr); + } diff --git a/include/fintamath/functions/logic/And.hpp b/include/fintamath/functions/logic/And.hpp index 642999eb3..0310a516c 100644 --- a/include/fintamath/functions/logic/And.hpp +++ b/include/fintamath/functions/logic/And.hpp @@ -22,4 +22,6 @@ class And : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(And, andExpr); + } diff --git a/include/fintamath/functions/logic/Equiv.hpp b/include/fintamath/functions/logic/Equiv.hpp index 234e497b1..9c493b31f 100644 --- a/include/fintamath/functions/logic/Equiv.hpp +++ b/include/fintamath/functions/logic/Equiv.hpp @@ -22,4 +22,6 @@ class Equiv : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Equiv, equivExpr); + } diff --git a/include/fintamath/functions/logic/Impl.hpp b/include/fintamath/functions/logic/Impl.hpp index 45dd05e4f..58c473220 100644 --- a/include/fintamath/functions/logic/Impl.hpp +++ b/include/fintamath/functions/logic/Impl.hpp @@ -22,4 +22,6 @@ class Impl : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Impl, implExpr); + } diff --git a/include/fintamath/functions/logic/Nequiv.hpp b/include/fintamath/functions/logic/Nequiv.hpp index 75f78a898..69f9036fd 100644 --- a/include/fintamath/functions/logic/Nequiv.hpp +++ b/include/fintamath/functions/logic/Nequiv.hpp @@ -22,4 +22,6 @@ class Nequiv : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Nequiv, nequivExpr); + } diff --git a/include/fintamath/functions/logic/Not.hpp b/include/fintamath/functions/logic/Not.hpp index 3b2761fa8..56385e0d6 100644 --- a/include/fintamath/functions/logic/Not.hpp +++ b/include/fintamath/functions/logic/Not.hpp @@ -22,4 +22,6 @@ class Not : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Not, notExpr); + } diff --git a/include/fintamath/functions/logic/Or.hpp b/include/fintamath/functions/logic/Or.hpp index d7d8771e9..bdd3c9623 100644 --- a/include/fintamath/functions/logic/Or.hpp +++ b/include/fintamath/functions/logic/Or.hpp @@ -22,4 +22,6 @@ class Or : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Or, orExpr); + } diff --git a/include/fintamath/functions/other/Deg.hpp b/include/fintamath/functions/other/Deg.hpp index 5250b0a82..d11cf0565 100644 --- a/include/fintamath/functions/other/Deg.hpp +++ b/include/fintamath/functions/other/Deg.hpp @@ -22,4 +22,6 @@ class Deg : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Deg, degExpr); + } diff --git a/include/fintamath/functions/other/Factorial.hpp b/include/fintamath/functions/other/Factorial.hpp index 4dd6b092d..e2df72a98 100644 --- a/include/fintamath/functions/other/Factorial.hpp +++ b/include/fintamath/functions/other/Factorial.hpp @@ -49,4 +49,6 @@ class Factorial : public IOperatorCRTP { size_t order = 1; }; +FINTAMATH_FUNCTION_EXPRESSION(Factorial, factorialExpr); + } diff --git a/include/fintamath/functions/other/Index.hpp b/include/fintamath/functions/other/Index.hpp index c9446ea7a..e7989540b 100644 --- a/include/fintamath/functions/other/Index.hpp +++ b/include/fintamath/functions/other/Index.hpp @@ -24,4 +24,6 @@ class Index : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Index, indexExpr); + } diff --git a/include/fintamath/functions/other/Percent.hpp b/include/fintamath/functions/other/Percent.hpp index bc8948a6f..c783699a3 100644 --- a/include/fintamath/functions/other/Percent.hpp +++ b/include/fintamath/functions/other/Percent.hpp @@ -22,4 +22,6 @@ class Percent : public IOperatorCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Percent, percentExpr); + } diff --git a/include/fintamath/functions/powers/Exp.hpp b/include/fintamath/functions/powers/Exp.hpp index f6cc03fb8..447e873e1 100644 --- a/include/fintamath/functions/powers/Exp.hpp +++ b/include/fintamath/functions/powers/Exp.hpp @@ -21,4 +21,6 @@ class Exp : public IFunctionCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Exp, expExpr); + } diff --git a/include/fintamath/functions/powers/Pow.hpp b/include/fintamath/functions/powers/Pow.hpp index e29471013..e5abea176 100644 --- a/include/fintamath/functions/powers/Pow.hpp +++ b/include/fintamath/functions/powers/Pow.hpp @@ -35,4 +35,6 @@ class Pow : public IOperatorCRTP { static std::unique_ptr powSimplify(const Real &lhs, const Real &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Pow, powExpr); + } diff --git a/include/fintamath/functions/powers/Root.hpp b/include/fintamath/functions/powers/Root.hpp index 176ca8daf..c734be469 100644 --- a/include/fintamath/functions/powers/Root.hpp +++ b/include/fintamath/functions/powers/Root.hpp @@ -38,4 +38,6 @@ class Root : public IFunctionCRTP { static std::unique_ptr perfectRoot(const Integer &lhs, const Integer &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Root, rootExpr); + } diff --git a/include/fintamath/functions/powers/Sqrt.hpp b/include/fintamath/functions/powers/Sqrt.hpp index 3d979a7ae..ecb072ce3 100644 --- a/include/fintamath/functions/powers/Sqrt.hpp +++ b/include/fintamath/functions/powers/Sqrt.hpp @@ -21,4 +21,6 @@ class Sqrt : public IFunctionCRTP { std::unique_ptr call(const ArgumentsRefVector &argsVect) const override; }; +FINTAMATH_FUNCTION_EXPRESSION(Sqrt, sqrtExpr); + } diff --git a/include/fintamath/functions/trigonometry/Acos.hpp b/include/fintamath/functions/trigonometry/Acos.hpp index 479ad9f58..1f98f264f 100644 --- a/include/fintamath/functions/trigonometry/Acos.hpp +++ b/include/fintamath/functions/trigonometry/Acos.hpp @@ -28,4 +28,6 @@ class Acos : public IFunctionCRTP { static std::unique_ptr acosSimplify(const Real &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Acos, acosExpr); + } diff --git a/include/fintamath/functions/trigonometry/Acot.hpp b/include/fintamath/functions/trigonometry/Acot.hpp index 113a56f6a..972e910bc 100644 --- a/include/fintamath/functions/trigonometry/Acot.hpp +++ b/include/fintamath/functions/trigonometry/Acot.hpp @@ -24,4 +24,6 @@ class Acot : public IFunctionCRTP { static std::unique_ptr multiAcotSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Acot, acotExpr); + } diff --git a/include/fintamath/functions/trigonometry/Asin.hpp b/include/fintamath/functions/trigonometry/Asin.hpp index 6df65bb72..f0e768719 100644 --- a/include/fintamath/functions/trigonometry/Asin.hpp +++ b/include/fintamath/functions/trigonometry/Asin.hpp @@ -28,4 +28,6 @@ class Asin : public IFunctionCRTP { static std::unique_ptr asinSimplify(const Real &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Asin, asinExpr); + } diff --git a/include/fintamath/functions/trigonometry/Atan.hpp b/include/fintamath/functions/trigonometry/Atan.hpp index d203ca158..c41b99652 100644 --- a/include/fintamath/functions/trigonometry/Atan.hpp +++ b/include/fintamath/functions/trigonometry/Atan.hpp @@ -24,4 +24,6 @@ class Atan : public IFunctionCRTP { static std::unique_ptr multiAtanSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Atan, atanExpr); + } diff --git a/include/fintamath/functions/trigonometry/Cos.hpp b/include/fintamath/functions/trigonometry/Cos.hpp index c15e9e698..7e985b67f 100644 --- a/include/fintamath/functions/trigonometry/Cos.hpp +++ b/include/fintamath/functions/trigonometry/Cos.hpp @@ -24,4 +24,9 @@ class Cos : public IFunctionCRTP { static std::unique_ptr multiCosSimplify(const INumber &rhs); }; +template +std ::unique_ptr cosExpr(Args &&...args) { + static const Cos f; + return makeExpr(f, std ::forward(args)...); +}; } diff --git a/include/fintamath/functions/trigonometry/Cot.hpp b/include/fintamath/functions/trigonometry/Cot.hpp index 283094603..1dbdd6faf 100644 --- a/include/fintamath/functions/trigonometry/Cot.hpp +++ b/include/fintamath/functions/trigonometry/Cot.hpp @@ -24,4 +24,6 @@ class Cot : public IFunctionCRTP { static std::unique_ptr multiCotSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Cot, cotExpr); + } diff --git a/include/fintamath/functions/trigonometry/Sin.hpp b/include/fintamath/functions/trigonometry/Sin.hpp index 49ee5bc2f..ed7e548a1 100644 --- a/include/fintamath/functions/trigonometry/Sin.hpp +++ b/include/fintamath/functions/trigonometry/Sin.hpp @@ -24,4 +24,6 @@ class Sin : public IFunctionCRTP { static std::unique_ptr multiSinSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Sin, sinExpr); + } diff --git a/include/fintamath/functions/trigonometry/Tan.hpp b/include/fintamath/functions/trigonometry/Tan.hpp index 0c681aae9..63fb2ef7e 100644 --- a/include/fintamath/functions/trigonometry/Tan.hpp +++ b/include/fintamath/functions/trigonometry/Tan.hpp @@ -24,4 +24,6 @@ class Tan : public IFunctionCRTP { static std::unique_ptr multiTanSimplify(const INumber &rhs); }; +FINTAMATH_FUNCTION_EXPRESSION(Tan, tanExpr); + } diff --git a/src/fintamath/config/ExpressionConfig.cpp b/src/fintamath/config/ExpressionConfig.cpp index 8887f727b..91571f5f5 100644 --- a/src/fintamath/config/ExpressionConfig.cpp +++ b/src/fintamath/config/ExpressionConfig.cpp @@ -144,7 +144,7 @@ struct ExpressionConfig { Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { return std::make_unique( - ArgumentsPtrVector{args.front(), makeExpr(Neg(), args.back())}); + ArgumentsPtrVector{args.front(), negExpr(args.back())}); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { @@ -216,39 +216,39 @@ struct ExpressionConfig { const ArgumentPtr &lhs = args.front(); const ArgumentPtr &rhs = args.back(); - ArgumentPtr notLhs = makeExpr(Not(), lhs); + ArgumentPtr notLhs = notExpr(lhs); - return makeExpr(Or(), notLhs, rhs); + return orExpr(notLhs, rhs); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { const ArgumentPtr &lhs = args.front(); const ArgumentPtr &rhs = args.back(); - ArgumentPtr notLhs = makeExpr(Not(), lhs); - ArgumentPtr notRhs = makeExpr(Not(), rhs); + ArgumentPtr notLhs = notExpr(lhs); + ArgumentPtr notRhs = notExpr(rhs); - ArgumentPtr lhsAndRhs = makeExpr(And(), lhs, rhs); - ArgumentPtr notLhsAndNotRhs = makeExpr(And(), notLhs, notRhs); + ArgumentPtr lhsAndRhs = andExpr(lhs, rhs); + ArgumentPtr notLhsAndNotRhs = andExpr(notLhs, notRhs); - return makeExpr(Or(), lhsAndRhs, notLhsAndNotRhs); + return orExpr(lhsAndRhs, notLhsAndNotRhs); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { const ArgumentPtr &lhs = args.front(); const ArgumentPtr &rhs = args.back(); - ArgumentPtr notLhs = makeExpr(Not(), lhs); - ArgumentPtr notRhs = makeExpr(Not(), rhs); + ArgumentPtr notLhs = notExpr(lhs); + ArgumentPtr notRhs = notExpr(rhs); - ArgumentPtr notLhsAndRhs = makeExpr(And(), notLhs, rhs); - ArgumentPtr lhsAndNotRhs = makeExpr(And(), lhs, notRhs); + ArgumentPtr notLhsAndRhs = andExpr(notLhs, rhs); + ArgumentPtr lhsAndNotRhs = andExpr(lhs, notRhs); - return makeExpr(Or(), notLhsAndRhs, lhsAndNotRhs); + return orExpr(notLhsAndRhs, lhsAndNotRhs); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return makeExpr(Mul(), std::make_shared(-1), args.front()); + return mulExpr(std::make_shared(-1), args.front()); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { @@ -284,12 +284,12 @@ struct ExpressionConfig { }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return makeExpr(Pow(), E().clone(), args.front()); + return powExpr(E().clone(), args.front()); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { static const auto PERCENT_VALUE = std::make_shared(100); - return makeExpr(Div(), args.front(), PERCENT_VALUE); + return divExpr(args.front(), PERCENT_VALUE); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { @@ -301,15 +301,15 @@ struct ExpressionConfig { }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return makeExpr(Pow(), args.front(), std::make_shared(1, 2)); + return powExpr(args.front(), std::make_shared(1, 2)); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { if (const auto num = cast(args.back())) { - return makeExpr(Pow(), args.front(), Rational(1) / (*num)); + return powExpr(args.front(), Rational(1) / (*num)); } - return makeExpr(Pow(), args.front(), makeExpr(Div(), std::make_shared(1), args.back())); + return powExpr(args.front(), divExpr(std::make_shared(1), args.back())); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { @@ -378,7 +378,7 @@ struct ExpressionConfig { Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { static const ArgumentPtr deg1 = Deg()(Integer(1)); - return makeExpr(Mul(), args.front(), deg1); + return mulExpr(args.front(), deg1); }); } }; diff --git a/src/fintamath/expressions/Expression.cpp b/src/fintamath/expressions/Expression.cpp index 5cf875561..385d3780b 100644 --- a/src/fintamath/expressions/Expression.cpp +++ b/src/fintamath/expressions/Expression.cpp @@ -538,51 +538,51 @@ void Expression::setVariable(const Variable &var, const Expression &val) { } Expression operator+(const Variable &lhs, const Variable &rhs) { - return Expression(makeExpr(Add(), lhs, rhs)); + return Expression(addExpr(lhs, rhs)); } Expression operator+(const Expression &lhs, const Variable &rhs) { - return Expression(makeExpr(Add(), lhs.getChildren().front(), rhs.clone())); + return Expression(addExpr(lhs.getChildren().front(), rhs.clone())); } Expression operator+(const Variable &lhs, const Expression &rhs) { - return Expression(makeExpr(Add(), lhs.clone(), rhs.getChildren().front())); + return Expression(addExpr(lhs.clone(), rhs.getChildren().front())); } Expression operator-(const Variable &lhs, const Variable &rhs) { - return Expression(makeExpr(Sub(), lhs, rhs)); + return Expression(subExpr(lhs, rhs)); } Expression operator-(const Expression &lhs, const Variable &rhs) { - return Expression(makeExpr(Sub(), lhs.getChildren().front(), rhs.clone())); + return Expression(subExpr(lhs.getChildren().front(), rhs.clone())); } Expression operator-(const Variable &lhs, const Expression &rhs) { - return Expression(makeExpr(Sub(), lhs.clone(), rhs.getChildren().front())); + return Expression(subExpr(lhs.clone(), rhs.getChildren().front())); } Expression operator*(const Variable &lhs, const Variable &rhs) { - return Expression(makeExpr(Mul(), lhs, rhs)); + return Expression(mulExpr(lhs, rhs)); } Expression operator*(const Expression &lhs, const Variable &rhs) { - return Expression(makeExpr(Mul(), lhs.getChildren().front(), rhs.clone())); + return Expression(mulExpr(lhs.getChildren().front(), rhs.clone())); } Expression operator*(const Variable &lhs, const Expression &rhs) { - return Expression(makeExpr(Mul(), lhs.clone(), rhs.getChildren().front())); + return Expression(mulExpr(lhs.clone(), rhs.getChildren().front())); } Expression operator/(const Variable &lhs, const Variable &rhs) { - return Expression(makeExpr(Div(), lhs, rhs)); + return Expression(divExpr(lhs, rhs)); } Expression operator/(const Expression &lhs, const Variable &rhs) { - return Expression(makeExpr(Div(), lhs.getChildren().front(), rhs.clone())); + return Expression(divExpr(lhs.getChildren().front(), rhs.clone())); } Expression operator/(const Variable &lhs, const Expression &rhs) { - return Expression(makeExpr(Div(), lhs.clone(), rhs.getChildren().front())); + return Expression(divExpr(lhs.clone(), rhs.getChildren().front())); } } diff --git a/src/fintamath/expressions/binary/CompExpression.cpp b/src/fintamath/expressions/binary/CompExpression.cpp index 9b324965e..ff72259fd 100644 --- a/src/fintamath/expressions/binary/CompExpression.cpp +++ b/src/fintamath/expressions/binary/CompExpression.cpp @@ -36,7 +36,7 @@ std::string CompExpression::toString() const { if (is(solLhs)) { sumChildren.erase(sumChildren.begin()); - ArgumentPtr solRhs = makeExpr(Neg(), sumChildren); + ArgumentPtr solRhs = negExpr(sumChildren); simplifyChild(solRhs); if (!is(solRhs)) { @@ -57,7 +57,7 @@ ArgumentPtr CompExpression::preSimplify() const { (!is(rhsChild) || *rhsChild != Integer(0))) { if (!hasInfinity(lhsChild) && !hasInfinity(rhsChild)) { - ArgumentPtr resLhs = makeExpr(Sub(), simplExpr->lhsChild, simplExpr->rhsChild); + ArgumentPtr resLhs = subExpr(simplExpr->lhsChild, simplExpr->rhsChild); preSimplifyChild(resLhs); return std::make_shared(cast(*func), resLhs, std::make_shared(0)); } @@ -170,10 +170,10 @@ ArgumentPtr CompExpression::coeffSimplify(const IFunction &func, const ArgumentP if (dividerNum && hasVariable(lhsExpr)) { for (auto &child : dividendPolynom) { - child = makeExpr(Div(), child, dividerNum); + child = divExpr(child, dividerNum); } - ArgumentPtr newLhs = makeExpr(Add(), dividendPolynom); + ArgumentPtr newLhs = addExpr(dividendPolynom); if (*dividerNum < Integer(0)) { return makeExpr(*cast(getOppositeFunction(func)), newLhs, rhs); diff --git a/src/fintamath/expressions/binary/DivExpression.cpp b/src/fintamath/expressions/binary/DivExpression.cpp index 6d1b3a762..9f2ae5815 100644 --- a/src/fintamath/expressions/binary/DivExpression.cpp +++ b/src/fintamath/expressions/binary/DivExpression.cpp @@ -22,8 +22,8 @@ DivExpression::DivExpression(const ArgumentPtr &inLhsChild, const ArgumentPtr &i std::string DivExpression::toString() const { if (isNegated(lhsChild)) { - ArgumentPtr innerDiv = makeExpr(Div(), makeExpr(Neg(), lhsChild)->toMinimalObject(), rhsChild); - return makeExpr(Neg(), innerDiv)->toString(); + ArgumentPtr innerDiv = divExpr(negExpr(lhsChild)->toMinimalObject(), rhsChild); + return negExpr(innerDiv)->toString(); } return IBinaryExpression::toString(); @@ -80,7 +80,7 @@ ArgumentPtr DivExpression::numSimplify(const IFunction & /*func*/, const Argumen static const Integer one = 1; if (Div().doArgsMatch({one, *rhs})) { - ArgumentPtr res = makeExpr(Mul(), lhs, Div()(one, *rhs)); + ArgumentPtr res = mulExpr(lhs, Div()(one, *rhs)); return res; } @@ -120,7 +120,7 @@ ArgumentPtr DivExpression::divSimplify(const IFunction & /*func*/, const Argumen numerator = numeratorChildren.front(); } else { - numerator = makeExpr(Mul(), numeratorChildren); + numerator = mulExpr(numeratorChildren); } ArgumentPtr denominator; @@ -128,10 +128,10 @@ ArgumentPtr DivExpression::divSimplify(const IFunction & /*func*/, const Argumen denominator = denominatorChildren.front(); } else { - denominator = makeExpr(Mul(), denominatorChildren); + denominator = mulExpr(denominatorChildren); } - ArgumentPtr res = makeExpr(Div(), numerator, denominator); + ArgumentPtr res = divExpr(numerator, denominator); return res; } @@ -181,7 +181,7 @@ ArgumentPtr DivExpression::mulSimplify(const IFunction &func, const ArgumentPtr ArgumentPtr numerator; if (lhsChildren.size() > 1) { - numerator = makeExpr(Mul(), lhsChildren); + numerator = mulExpr(lhsChildren); } else { numerator = lhsChildren.front(); @@ -193,14 +193,14 @@ ArgumentPtr DivExpression::mulSimplify(const IFunction &func, const ArgumentPtr ArgumentPtr denominator; if (rhsChildren.size() > 1) { - denominator = makeExpr(Mul(), rhsChildren); + denominator = mulExpr(rhsChildren); } else { denominator = rhsChildren.front(); } if (lhsChildren.size() != lhsChildrenSizeInitial || rhsChildren.size() != rhsChildrenSizeInitial) { - ArgumentPtr res = makeExpr(Div(), numerator, denominator); + ArgumentPtr res = divExpr(numerator, denominator); return res; } @@ -209,7 +209,7 @@ ArgumentPtr DivExpression::mulSimplify(const IFunction &func, const ArgumentPtr ArgumentPtr DivExpression::negSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { if (isNegated(rhs)) { - ArgumentPtr res = makeExpr(Div(), makeExpr(Neg(), lhs), makeExpr(Neg(), rhs)); + ArgumentPtr res = divExpr(negExpr(lhs), negExpr(rhs)); return res; } @@ -218,20 +218,20 @@ ArgumentPtr DivExpression::negSimplify(const IFunction & /*func*/, const Argumen ArgumentPtr DivExpression::sumSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { if (auto [result, remainder] = mulSumSimplify(lhs, rhs); result) { - return remainder ? makeExpr(Add(), result, remainder) : result; + return remainder ? addExpr(result, remainder) : result; } if (auto [result, remainder] = sumMulSimplify(lhs, rhs); result) { - return remainder ? makeExpr(Add(), result, remainder) : result; + return remainder ? addExpr(result, remainder) : result; } if (auto [result, remainder] = sumSumSimplify(lhs, rhs); result) { - return remainder ? makeExpr(Add(), result, remainder) : result; + return remainder ? addExpr(result, remainder) : result; } if (auto [result, remainder] = sumSumSimplify(rhs, lhs); result && !is(remainder)) { - ArgumentPtr denominator = remainder ? makeExpr(Add(), result, remainder) : result; - return makeExpr(Div(), Integer(1).clone(), denominator); + ArgumentPtr denominator = remainder ? addExpr(result, remainder) : result; + return divExpr(Integer(1).clone(), denominator); } return {}; @@ -276,10 +276,10 @@ std::pair DivExpression::sumSumSimplify(const Argument return {}; } - ArgumentPtr result = makeExpr(Add(), resultVect); + ArgumentPtr result = addExpr(resultVect); - ArgumentPtr remainderAdd = makeExpr(Add(), remainderVect); - ArgumentPtr remainder = makeExpr(Div(), remainderAdd, rhs); + ArgumentPtr remainderAdd = addExpr(remainderVect); + ArgumentPtr remainder = divExpr(remainderAdd, rhs); simplifyChild(remainder); return {result, remainder}; @@ -302,7 +302,7 @@ std::pair DivExpression::sumMulSimplify(const Argument ArgumentsPtrVector remainderChildren; for (const auto &child : lhsChildren) { - ArgumentPtr divResult = makeExpr(Div(), child, rhs); + ArgumentPtr divResult = divExpr(child, rhs); simplifyChild(divResult); if (const auto divResultExpr = cast(divResult); @@ -321,12 +321,12 @@ std::pair DivExpression::sumMulSimplify(const Argument return {}; } - ArgumentPtr result = makeExpr(Add(), resultChildren); + ArgumentPtr result = addExpr(resultChildren); ArgumentPtr remainder; if (!remainderChildren.empty()) { - ArgumentPtr remainderAdd = makeExpr(Add(), remainderChildren); - remainder = makeExpr(Div(), remainderAdd, rhs); + ArgumentPtr remainderAdd = addExpr(remainderChildren); + remainder = divExpr(remainderAdd, rhs); simplifyChild(remainder); } @@ -346,7 +346,7 @@ std::pair DivExpression::mulSumSimplify(const Argument return {}; } - ArgumentPtr result = makeExpr(Div(), lhs, rhsChildren.front()); + ArgumentPtr result = divExpr(lhs, rhsChildren.front()); simplifyChild(result); if (const auto divExpr = cast(result); divExpr && is
(divExpr->getFunction())) { @@ -356,12 +356,12 @@ std::pair DivExpression::mulSumSimplify(const Argument ArgumentsPtrVector multiplicator; for (size_t i = 1; i < rhsChildren.size(); i++) { - multiplicator.emplace_back(makeExpr(Mul(), rhsChildren[i], result)); + multiplicator.emplace_back(mulExpr(rhsChildren[i], result)); } - ArgumentPtr remainderNegAdd = makeExpr(Neg(), makeExpr(Add(), multiplicator)); + ArgumentPtr remainderNegAdd = negExpr(addExpr(multiplicator)); simplifyChild(remainderNegAdd); - ArgumentPtr remainder = makeExpr(Div(), remainderNegAdd, rhs); + ArgumentPtr remainder = divExpr(remainderNegAdd, rhs); return {result, remainder}; } @@ -386,7 +386,7 @@ ArgumentPtr DivExpression::powSimplify(const ArgumentPtr &lhs, const ArgumentPtr } if (*lhsChildValue == *rhsChildValue) { - return addRatesToValue({lhsChildRate, makeExpr(Neg(), rhsChildRate)}, lhsChildValue); + return addRatesToValue({lhsChildRate, negExpr(rhsChildRate)}, lhsChildValue); } if (lhsChildValueNum && @@ -394,15 +394,15 @@ ArgumentPtr DivExpression::powSimplify(const ArgumentPtr &lhs, const ArgumentPtr *lhsChildRate == *rhsChildRate && *rhsChildRate != Integer(1)) { - ArgumentPtr valuesDiv = makeExpr(Div(), lhsChildValue, rhsChildValue); - return makeExpr(Pow(), valuesDiv, lhsChildRate); + ArgumentPtr valuesDiv = divExpr(lhsChildValue, rhsChildValue); + return powExpr(valuesDiv, lhsChildRate); } if (rhsChildValueNum) { if (const auto rhsChildRateRat = cast(rhsChildRate)) { ArgumentPtr numeratorPow = Pow()(*rhsChildValue, 1 - (*rhsChildRateRat)); - ArgumentPtr numerator = makeExpr(Mul(), lhs, numeratorPow); - return makeExpr(Div(), numerator, rhsChildValue); + ArgumentPtr numerator = mulExpr(lhs, numeratorPow); + return divExpr(numerator, rhsChildValue); } } @@ -419,8 +419,8 @@ std::pair DivExpression::getRateValuePair(const Argume } ArgumentPtr DivExpression::addRatesToValue(const ArgumentsPtrVector &rates, const ArgumentPtr &value) { - ArgumentPtr ratesSum = makeExpr(Add(), rates); - return makeExpr(Pow(), value, ratesSum); + ArgumentPtr ratesSum = addExpr(rates); + return powExpr(value, ratesSum); } ArgumentPtr DivExpression::nestedRationalSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { @@ -466,13 +466,13 @@ ArgumentPtr DivExpression::gcdSimplify(const IFunction & /*func*/, const Argumen return {}; } - ArgumentPtr numerator = makeExpr(Div(), lhs, gcdNum.clone()); + ArgumentPtr numerator = divExpr(lhs, gcdNum.clone()); simplifyChild(numerator); - ArgumentPtr denominator = makeExpr(Div(), rhs, gcdNum.clone()); + ArgumentPtr denominator = divExpr(rhs, gcdNum.clone()); simplifyChild(denominator); - return makeExpr(Div(), numerator, denominator); + return divExpr(numerator, denominator); } Integer DivExpression::getGcd(ArgumentsPtrVector &lhsChildren) { @@ -512,9 +512,9 @@ ArgumentPtr DivExpression::nestedNumeratorRationalSimplify(const ArgumentsPtrVec if (!denominatorChildren.empty()) { denominatorChildren.emplace_back(rhs); - ArgumentPtr numerator = makeExpr(Mul(), numeratorChildren); - ArgumentPtr denominator = makeExpr(Mul(), denominatorChildren); - return makeExpr(Div(), numerator, denominator); + ArgumentPtr numerator = mulExpr(numeratorChildren); + ArgumentPtr denominator = mulExpr(denominatorChildren); + return divExpr(numerator, denominator); } return {}; diff --git a/src/fintamath/expressions/binary/IntegralExpression.cpp b/src/fintamath/expressions/binary/IntegralExpression.cpp index 2d80b7bcc..6730e23dd 100644 --- a/src/fintamath/expressions/binary/IntegralExpression.cpp +++ b/src/fintamath/expressions/binary/IntegralExpression.cpp @@ -32,10 +32,10 @@ ArgumentPtr IntegralExpression::integralSimplify(const IFunction & /*func*/, con ArgumentPtr res; if (is(lhs) || is(lhs)) { - res = makeExpr(Mul(), lhs, rhs); + res = mulExpr(lhs, rhs); } else if (is(lhs) && is(rhs) && *lhs == *rhs) { - res = makeExpr(Div(), makeExpr(Pow(), lhs, std::make_shared(2)), std::make_shared(2)); + res = divExpr(powExpr(lhs, std::make_shared(2)), std::make_shared(2)); } // TODO: res + integral constant diff --git a/src/fintamath/expressions/binary/LogExpression.cpp b/src/fintamath/expressions/binary/LogExpression.cpp index 58d35a35a..2b3853371 100644 --- a/src/fintamath/expressions/binary/LogExpression.cpp +++ b/src/fintamath/expressions/binary/LogExpression.cpp @@ -109,13 +109,13 @@ ArgumentPtr LogExpression::powSimplify(const IFunction & /*func*/, const Argumen if (auto rhsExpr = cast(rhs); rhsExpr && is(rhsExpr->getFunction())) { ArgumentPtr multiplier = rhsExpr->getChildren().back(); - ArgumentPtr logExpr = makeExpr(Log(), lhs, rhsExpr->getChildren().front()); - res = makeExpr(Mul(), multiplier, logExpr); + ArgumentPtr logExprChild = logExpr(lhs, rhsExpr->getChildren().front()); + res = mulExpr(multiplier, logExprChild); } else if (auto lhsExpr = cast(lhs); lhsExpr && is(lhsExpr->getFunction())) { - ArgumentPtr multiplier = makeExpr(Div(), std::make_shared(1), lhsExpr->getChildren().back()); - ArgumentPtr logExpr = makeExpr(Log(), lhsExpr->getChildren().front(), rhs); - res = makeExpr(Mul(), multiplier, logExpr); + ArgumentPtr multiplier = divExpr(Integer(1).clone(), lhsExpr->getChildren().back()); + ArgumentPtr logExprChild = logExpr(lhsExpr->getChildren().front(), rhs); + res = mulExpr(multiplier, logExprChild); } return res; diff --git a/src/fintamath/expressions/binary/PowExpression.cpp b/src/fintamath/expressions/binary/PowExpression.cpp index b24f05eb6..c288b2249 100644 --- a/src/fintamath/expressions/binary/PowExpression.cpp +++ b/src/fintamath/expressions/binary/PowExpression.cpp @@ -166,15 +166,15 @@ ArgumentPtr PowExpression::sumPolynomSimplify(const ArgumentPtr &expr, const Int mulExprPolynom.emplace_back(std::make_shared(multinomialCoefficient(powValue, vectOfPows))); for (size_t j = 0; j < size_t(variableCount); j++) { - ArgumentPtr powExpr = makeExpr(Pow(), polynom[j], std::make_shared(std::move(vectOfPows[j]))); - mulExprPolynom.emplace_back(powExpr); + ArgumentPtr powExprChild = powExpr(polynom[j], vectOfPows[j].clone()); + mulExprPolynom.emplace_back(powExprChild); } - ArgumentPtr mulExpr = makeExpr(Mul(), mulExprPolynom); - newPolynom.emplace_back(mulExpr); + ArgumentPtr mulExprChild = mulExpr(mulExprPolynom); + newPolynom.emplace_back(mulExprChild); } - ArgumentPtr res = makeExpr(Add(), newPolynom); + ArgumentPtr res = addExpr(newPolynom); return res; } @@ -183,8 +183,8 @@ ArgumentPtr PowExpression::powSimplify(const IFunction & /*func*/, const Argumen if (auto lhsExpr = cast(lhs); lhsExpr && is(lhsExpr->getFunction())) { ArgumentPtr lhsPow = lhsExpr->getChildren().front(); - ArgumentPtr rhsPow = makeExpr(Mul(), lhsExpr->getChildren().back(), rhs); - res = makeExpr(Pow(), lhsPow, rhsPow); + ArgumentPtr rhsPow = mulExpr(lhsExpr->getChildren().back(), rhs); + res = powExpr(lhsPow, rhsPow); } return res; @@ -198,7 +198,7 @@ ArgumentPtr PowExpression::constSimplify(const IFunction & /*func*/, const Argum if (*rhs == Integer(-1)) { ArgumentPtr divLhs = Integer(1).clone(); ArgumentPtr divRhs = lhs; - return makeExpr(Div(), divLhs, divRhs); + return divExpr(divLhs, divRhs); } if (const auto rhsComp = cast(rhs); @@ -206,14 +206,14 @@ ArgumentPtr PowExpression::constSimplify(const IFunction & /*func*/, const Argum (rhsComp && *rhsComp < Integer(0))) { ArgumentPtr divLhs = Integer(1).clone(); - ArgumentPtr divRhs = makeExpr(Pow(), lhs, makeExpr(Neg(), rhs)); - return makeExpr(Div(), divLhs, divRhs); + ArgumentPtr divRhs = powExpr(lhs, negExpr(rhs)); + return divExpr(divLhs, divRhs); } if (is(lhs)) { - ArgumentPtr mulLhs = makeExpr(Pow(), Integer(-1).clone(), rhs); - ArgumentPtr mulRhs = makeExpr(Pow(), Inf().clone(), rhs); - return makeExpr(Mul(), mulLhs, mulRhs); + ArgumentPtr mulLhs = powExpr(Integer(-1).clone(), rhs); + ArgumentPtr mulRhs = powExpr(Inf().clone(), rhs); + return mulExpr(mulLhs, mulRhs); } if (is(lhs) || is(lhs)) { @@ -278,14 +278,14 @@ ArgumentPtr PowExpression::polynomSimplify(const IFunction & /*func*/, const Arg ArgumentPtr PowExpression::mulSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs) { ArgumentPtr res; - if (auto mulExpr = cast(lhs); mulExpr && is(mulExpr->getFunction())) { - ArgumentsPtrVector args = mulExpr->getChildren(); + if (auto mulExprChild = cast(lhs); mulExprChild && is(mulExprChild->getFunction())) { + ArgumentsPtrVector args = mulExprChild->getChildren(); for (auto &arg : args) { - arg = makeExpr(Pow(), arg, rhs->clone()); + arg = powExpr(arg, rhs->clone()); } - res = makeExpr(Mul(), args); + res = mulExpr(args); } return res; @@ -294,10 +294,10 @@ ArgumentPtr PowExpression::mulSimplify(const ArgumentPtr &lhs, const ArgumentPtr ArgumentPtr PowExpression::divSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs) { ArgumentPtr res; - if (auto divExpr = cast(lhs); divExpr && is
(divExpr->getFunction())) { - ArgumentPtr numerator = makeExpr(Pow(), divExpr->getChildren().front(), rhs); - ArgumentPtr denominator = makeExpr(Pow(), divExpr->getChildren().back(), rhs); - res = makeExpr(Div(), numerator, denominator); + if (auto divExprChild = cast(lhs); divExprChild && is
(divExprChild->getFunction())) { + ArgumentPtr numerator = powExpr(divExprChild->getChildren().front(), rhs); + ArgumentPtr denominator = powExpr(divExprChild->getChildren().back(), rhs); + res = divExpr(numerator, denominator); } return res; diff --git a/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp b/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp index ebd6bf842..8a162a541 100644 --- a/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp +++ b/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp @@ -82,7 +82,7 @@ Expression solve(const Expression &rhs) { return Expression(answers.front()); } - return Expression(makeExpr(Or(), answers)); + return Expression(orExpr(answers)); } } @@ -136,7 +136,7 @@ ArgumentPtr getElementRate(const ArgumentPtr &elem, const Variable &var) { coeff.emplace_back(getElementRate(child, var)); } - return makeExpr(Mul(), coeff)->toMinimalObject(); + return mulExpr(coeff)->toMinimalObject(); } } @@ -206,7 +206,7 @@ ArgumentsPtrVector solveQuadraticEquation(const ArgumentsPtrVector &coeffAtPow) } ArgumentsPtrVector solveLinearEquation(const ArgumentsPtrVector &coeffAtPow) { - return {makeExpr(Neg(), makeExpr(Div(), coeffAtPow[0], coeffAtPow[1]))->toMinimalObject()}; + return {negExpr(divExpr(coeffAtPow[0], coeffAtPow[1]))->toMinimalObject()}; } } diff --git a/src/fintamath/expressions/polynomial/AddExpression.cpp b/src/fintamath/expressions/polynomial/AddExpression.cpp index 108920c8b..22303769a 100644 --- a/src/fintamath/expressions/polynomial/AddExpression.cpp +++ b/src/fintamath/expressions/polynomial/AddExpression.cpp @@ -149,8 +149,8 @@ ArgumentPtr AddExpression::logSimplify(const IFunction & /*func*/, const Argumen if (*lhsChildren.front() == *rhsChildren.front()) { ArgumentPtr logLhs = lhsChildren.front(); - ArgumentPtr logRhs = makeExpr(Mul(), lhsChildren.back(), rhsChildren.back()); - ArgumentPtr res = makeExpr(Log(), logLhs, logRhs); + ArgumentPtr logRhs = mulExpr(lhsChildren.back(), rhsChildren.back()); + ArgumentPtr res = logExpr(logLhs, logRhs); return res; } @@ -183,41 +183,41 @@ ArgumentPtr AddExpression::mulLogSimplify(const IFunction & /*func*/, const Argu rhsLogChild = cast(mulToLogarithm(rhsExprChildren, j)); ArgumentPtr logLhs = lhsLogChild->getChildren().front(); - ArgumentPtr logRhs = makeExpr(Mul(), lhsLogChild->getChildren().back(), rhsLogChild->getChildren().back()); - ArgumentPtr res = makeExpr(Log(), logLhs, logRhs); + ArgumentPtr logRhs = mulExpr(lhsLogChild->getChildren().back(), rhsLogChild->getChildren().back()); + ArgumentPtr res = logExpr(logLhs, logRhs); return res; } } } } - std::shared_ptr mulExpr; - std::shared_ptr logExpr; + std::shared_ptr mulExprChild; + std::shared_ptr logExprChild; if (is(lhsExpr->getFunction()) && is(rhsExpr->getFunction())) { - mulExpr = lhsExpr; - logExpr = rhsExpr; + mulExprChild = lhsExpr; + logExprChild = rhsExpr; } else if (is(lhsExpr->getFunction()) && is(rhsExpr->getFunction())) { - mulExpr = rhsExpr; - logExpr = lhsExpr; + mulExprChild = rhsExpr; + logExprChild = lhsExpr; } else { return {}; } - ArgumentsPtrVector mulExprChildren = mulExpr->getChildren(); + ArgumentsPtrVector mulExprChildren = mulExprChild->getChildren(); std::vector logChildrenIndexes = findLogarithms(mulExprChildren); for (size_t i : logChildrenIndexes) { auto logChild = cast(mulExprChildren[i]); - if (*logChild->getChildren().front() == *logExpr->getChildren().front()) { + if (*logChild->getChildren().front() == *logExprChild->getChildren().front()) { logChild = mulToLogarithm(mulExprChildren, i); - ArgumentPtr logLhs = logExpr->getChildren().front(); - ArgumentPtr logRhs = makeExpr(Mul(), logExpr->getChildren().back(), logChild->getChildren().back()); - ArgumentPtr res = makeExpr(Log(), logLhs, logRhs); + ArgumentPtr logLhs = logExprChild->getChildren().front(); + ArgumentPtr logRhs = mulExpr(logExprChild->getChildren().back(), logChild->getChildren().back()); + ArgumentPtr res = logExpr(logLhs, logRhs); return res; } } @@ -229,8 +229,10 @@ std::pair AddExpression::getRateValuePair(const Argume ArgumentPtr rate; ArgumentPtr value; - if (const auto mulExpr = cast(inChild); mulExpr && is(mulExpr->getFunction())) { - const ArgumentsPtrVector mulExprChildren = mulExpr->getChildren(); + if (const auto mulExprChild = cast(inChild); + mulExprChild && is(mulExprChild->getFunction())) { + + const ArgumentsPtrVector mulExprChildren = mulExprChild->getChildren(); if (is(mulExprChildren.front())) { rate = mulExprChildren.front(); @@ -239,7 +241,7 @@ std::pair AddExpression::getRateValuePair(const Argume value = mulExprChildren[1]; } else { - value = makeExpr(Mul(), ArgumentsPtrVector(mulExprChildren.begin() + 1, mulExprChildren.end())); + value = mulExpr(ArgumentsPtrVector(mulExprChildren.begin() + 1, mulExprChildren.end())); } } } @@ -253,8 +255,8 @@ std::pair AddExpression::getRateValuePair(const Argume } ArgumentPtr AddExpression::addRatesToValue(const ArgumentsPtrVector &rates, const ArgumentPtr &value) { - ArgumentPtr ratesSum = makeExpr(Add(), rates); - ArgumentPtr res = makeExpr(Mul(), ratesSum, value); + ArgumentPtr ratesSum = addExpr(rates); + ArgumentPtr res = mulExpr(ratesSum, value); return res; } @@ -274,14 +276,14 @@ std::vector AddExpression::findLogarithms(const ArgumentsPtrVector &chil std::shared_ptr AddExpression::mulToLogarithm(const ArgumentsPtrVector &children, size_t i) { ArgumentsPtrVector mulChildren = children; - auto logExpr = cast(mulChildren[i]); + auto logExprChild = cast(mulChildren[i]); mulChildren.erase(mulChildren.begin() + ArgumentsPtrVector::difference_type(i)); - const ArgumentPtr powRate = mulChildren.size() > 1 ? makeExpr(Mul(), mulChildren) : mulChildren.front(); - const ArgumentPtr powExpr = makeExpr(Pow(), logExpr->getChildren().back(), powRate); + const ArgumentPtr powRate = mulChildren.size() > 1 ? mulExpr(mulChildren) : mulChildren.front(); + const ArgumentPtr logRhsChild = powExpr(logExprChild->getChildren().back(), powRate); - return cast(makeExpr(Log(), logExpr->getChildren().front(), powExpr)); + return cast(logExpr(logExprChild->getChildren().front(), logRhsChild)); } ArgumentPtr AddExpression::powSimplify(const IFunction & /*func*/, const ArgumentPtr &lhsChild, @@ -302,7 +304,7 @@ ArgumentPtr AddExpression::sumSimplify(const IFunction & /*func*/, const Argumen std::shared_ptr rhsExpr = cast(rhsChild); if (const auto rhsRat = cast(rhsChild)) { - rhsExpr = cast(makeExpr(Div(), rhsRat->numerator(), rhsRat->denominator())); + rhsExpr = cast(divExpr(rhsRat->numerator(), rhsRat->denominator())); } ArgumentPtr res; @@ -315,9 +317,9 @@ ArgumentPtr AddExpression::sumSimplify(const IFunction & /*func*/, const Argumen ArgumentPtr rhsNumerator = rhsExpr->getChildren().front(); ArgumentPtr rhsDenominator = rhsExpr->getChildren().back(); - ArgumentPtr numerator = makeExpr(Add(), lhsNumerator, rhsNumerator); + ArgumentPtr numerator = addExpr(lhsNumerator, rhsNumerator); ArgumentPtr denominator = rhsDenominator; - res = makeExpr(Div(), numerator, denominator); + res = divExpr(numerator, denominator); } else { ArgumentPtr lhsNumerator = lhsExpr->getChildren().front(); @@ -325,23 +327,23 @@ ArgumentPtr AddExpression::sumSimplify(const IFunction & /*func*/, const Argumen ArgumentPtr lhsDenominator = lhsExpr->getChildren().back(); ArgumentPtr rhsDenominator = rhsExpr->getChildren().back(); - ArgumentPtr lhsNumeratorMulRhsDenominator = makeExpr(Mul(), lhsNumerator, rhsDenominator); - ArgumentPtr rhsNumeratorMulLhsDenominator = makeExpr(Mul(), rhsNumerator, lhsDenominator); + ArgumentPtr lhsNumeratorMulRhsDenominator = mulExpr(lhsNumerator, rhsDenominator); + ArgumentPtr rhsNumeratorMulLhsDenominator = mulExpr(rhsNumerator, lhsDenominator); - ArgumentPtr numerator = makeExpr(Add(), lhsNumeratorMulRhsDenominator, rhsNumeratorMulLhsDenominator); - ArgumentPtr denominator = makeExpr(Mul(), lhsDenominator, rhsDenominator); - res = makeExpr(Div(), numerator, denominator); + ArgumentPtr numerator = addExpr(lhsNumeratorMulRhsDenominator, rhsNumeratorMulLhsDenominator); + ArgumentPtr denominator = mulExpr(lhsDenominator, rhsDenominator); + res = divExpr(numerator, denominator); } } else if (rhsExpr && is
(rhsExpr->getFunction())) { ArgumentPtr rhsNumerator = rhsExpr->getChildren().front(); ArgumentPtr rhsDenominator = rhsExpr->getChildren().back(); - ArgumentPtr lhsMulRhsDenominator = makeExpr(Mul(), lhsChild, rhsDenominator); + ArgumentPtr lhsMulRhsDenominator = mulExpr(lhsChild, rhsDenominator); - ArgumentPtr numerator = makeExpr(Add(), lhsMulRhsDenominator, rhsNumerator); + ArgumentPtr numerator = addExpr(lhsMulRhsDenominator, rhsNumerator); ArgumentPtr denominator = rhsDenominator; - res = makeExpr(Div(), numerator, denominator); + res = divExpr(numerator, denominator); } return res; diff --git a/src/fintamath/expressions/polynomial/AndExpression.cpp b/src/fintamath/expressions/polynomial/AndExpression.cpp index 67f52639a..9fec59a4a 100644 --- a/src/fintamath/expressions/polynomial/AndExpression.cpp +++ b/src/fintamath/expressions/polynomial/AndExpression.cpp @@ -95,11 +95,11 @@ ArgumentPtr AndExpression::orSimplify(const IFunction & /*func*/, const Argument for (const auto &lhsSubChild : lhsChildren) { for (const auto &rhsSubChild : rhsChildren) { - resultVect.emplace_back(makeExpr(And(), lhsSubChild, rhsSubChild)); + resultVect.emplace_back(andExpr(lhsSubChild, rhsSubChild)); } } - ArgumentPtr res = makeExpr(Or(), resultVect); + ArgumentPtr res = orExpr(resultVect); return res; } diff --git a/src/fintamath/expressions/polynomial/MulExpression.cpp b/src/fintamath/expressions/polynomial/MulExpression.cpp index 51cabb32f..fc7875976 100644 --- a/src/fintamath/expressions/polynomial/MulExpression.cpp +++ b/src/fintamath/expressions/polynomial/MulExpression.cpp @@ -35,10 +35,9 @@ std::string MulExpression::toString() const { numeratorChildren.erase(numeratorChildren.begin()); } - ArgumentPtr numerator = - numeratorChildren.size() > 1 ? makeExpr(Mul(), numeratorChildren) : numeratorChildren.front(); + ArgumentPtr numerator = numeratorChildren.size() > 1 ? mulExpr(numeratorChildren) : numeratorChildren.front(); ArgumentPtr denominator = firstChildRat->denominator().clone(); - ArgumentPtr res = makeExpr(Div(), numerator, denominator); + ArgumentPtr res = divExpr(numerator, denominator); std::string resStr = res->toString(); if (firstChildRat->numerator() < Integer(0)) { @@ -133,9 +132,9 @@ ArgumentPtr MulExpression::constSimplify(const IFunction & /*func*/, ArgumentPtr MulExpression::rationalSimplify(const IFunction & /*func*/, const ArgumentPtr &lhsChild, const ArgumentPtr &rhsChild) { if (const auto lhsRat = cast(lhsChild)) { - ArgumentPtr numerator = makeExpr(Mul(), lhsRat->numerator().clone(), rhsChild); + ArgumentPtr numerator = mulExpr(lhsRat->numerator().clone(), rhsChild); ArgumentPtr denominator = lhsRat->denominator().clone(); - return makeExpr(Div(), numerator, denominator); + return divExpr(numerator, denominator); } return {}; @@ -164,22 +163,22 @@ ArgumentPtr MulExpression::divSimplify(const IFunction & /*func*/, const Argumen ArgumentPtr denominator; if (isLhsDiv && isRhsDiv) { - numerator = makeExpr(Mul(), lhsExpr->getChildren().front(), rhsExpr->getChildren().front()); - denominator = makeExpr(Mul(), lhsExpr->getChildren().back(), rhsExpr->getChildren().back()); + numerator = mulExpr(lhsExpr->getChildren().front(), rhsExpr->getChildren().front()); + denominator = mulExpr(lhsExpr->getChildren().back(), rhsExpr->getChildren().back()); } else if (isLhsDiv) { - numerator = makeExpr(Mul(), lhsExpr->getChildren().front(), rhsChild); + numerator = mulExpr(lhsExpr->getChildren().front(), rhsChild); denominator = lhsExpr->getChildren().back(); } else if (isRhsDiv) { - numerator = makeExpr(Mul(), lhsChild, rhsExpr->getChildren().front()); + numerator = mulExpr(lhsChild, rhsExpr->getChildren().front()); denominator = rhsExpr->getChildren().back(); } else { return {}; } - ArgumentPtr res = makeExpr(Div(), numerator, denominator); + ArgumentPtr res = divExpr(numerator, denominator); return res; } @@ -217,11 +216,11 @@ ArgumentPtr MulExpression::polynomSimplify(const IFunction & /*func*/, const Arg for (const auto &lhsSubChild : lhsChildren) { for (const auto &rhsSubChild : rhsChildren) { - resultVect.emplace_back(makeExpr(Mul(), lhsSubChild, rhsSubChild)); + resultVect.emplace_back(mulExpr(lhsSubChild, rhsSubChild)); } } - ArgumentPtr res = makeExpr(Add(), resultVect); + ArgumentPtr res = addExpr(resultVect); return res; } @@ -230,8 +229,8 @@ ArgumentPtr MulExpression::powSimplify(const IFunction & /*func*/, const Argumen auto [rhsChildRate, rhsChildValue] = getRateValuePair(rhsChild); if (*lhsChildValue == *rhsChildValue) { - ArgumentPtr ratesSum = makeExpr(Add(), lhsChildRate, rhsChildRate); - return makeExpr(Pow(), lhsChildValue, ratesSum); + ArgumentPtr ratesSum = addExpr(lhsChildRate, rhsChildRate); + return powExpr(lhsChildValue, ratesSum); } if (is(lhsChildValue) && @@ -239,8 +238,8 @@ ArgumentPtr MulExpression::powSimplify(const IFunction & /*func*/, const Argumen *lhsChildRate == *rhsChildRate && *rhsChildRate != Integer(1)) { - ArgumentPtr valuesMul = makeExpr(Mul(), lhsChildValue, rhsChildValue); - return makeExpr(Pow(), valuesMul, lhsChildRate); + ArgumentPtr valuesMul = mulExpr(lhsChildValue, rhsChildValue); + return powExpr(valuesMul, lhsChildRate); } return {}; diff --git a/src/fintamath/expressions/polynomial/OrExpression.cpp b/src/fintamath/expressions/polynomial/OrExpression.cpp index 0242be488..8f3e390d5 100644 --- a/src/fintamath/expressions/polynomial/OrExpression.cpp +++ b/src/fintamath/expressions/polynomial/OrExpression.cpp @@ -46,7 +46,7 @@ ArgumentPtr OrExpression::postSimplify() const { if (simplChildren.size() != simplChildrenSizeInitial) { if (simplChildren.size() > 1) { - ArgumentPtr res = makeExpr(Or(), simplChildren); + ArgumentPtr res = orExpr(simplChildren); postSimplifyChild(res); return res; } @@ -174,7 +174,7 @@ ArgumentPtr OrExpression::andSimplify(const IFunction & /*func*/, const Argument resultChildren.erase(resultChildren.begin() + ArgumentsPtrVector::difference_type(resolutionIndex)); if (resultChildren.size() > 1) { - ArgumentPtr res = makeExpr(And(), resultChildren); + ArgumentPtr res = andExpr(resultChildren); return res; } @@ -222,7 +222,7 @@ ArgumentPtr OrExpression::absorptionSimplify(const ArgumentPtr &lhsChild, const if (matchCount == minChildren.size()) { if (minChildren.size() > 1) { - ArgumentPtr res = makeExpr(And(), minChildren); + ArgumentPtr res = andExpr(minChildren); return res; } diff --git a/src/fintamath/expressions/unary/InvTrigExpression.cpp b/src/fintamath/expressions/unary/InvTrigExpression.cpp index 05e7e4170..c033af984 100644 --- a/src/fintamath/expressions/unary/InvTrigExpression.cpp +++ b/src/fintamath/expressions/unary/InvTrigExpression.cpp @@ -76,56 +76,56 @@ ArgumentPtr InvTrigExpression::trigTableSimplify(const IFunction &func, const Ra ArgumentPtr InvTrigExpression::trigTableAsinSimplify(const Rational &rhs) { static const TrigonometryTable trigTable = { - {Rational(-1), makeExpr(Mul(), Rational(-1, 2), Pi())}, // -1 | -π/2 - {Rational(-3, 4), makeExpr(Mul(), Rational(-1, 3), Pi())}, // -√3/2 | -π/3 - {Rational(-1, 2), makeExpr(Mul(), Rational(-1, 4), Pi())}, // -√2/2 | -π/4 - {Rational(-1, 4), makeExpr(Mul(), Rational(-1, 6), Pi())}, // -1/2 | -π/6 - {Rational(0), Integer(0).clone()}, // 0 | 0 - {Rational(1, 4), makeExpr(Mul(), Rational(1, 6), Pi())}, // 1/2 | π/6 - {Rational(1, 2), makeExpr(Mul(), Rational(1, 4), Pi())}, // √2/2 | π/4 - {Rational(3, 4), makeExpr(Mul(), Rational(1, 3), Pi())}, // √3/2 | π/3 - {Rational(1), makeExpr(Mul(), Rational(-1, 2), Pi())}, // 1 | -π/2 + {Rational(-1), mulExpr(Rational(-1, 2), Pi())}, // -1 | -π/2 + {Rational(-3, 4), mulExpr(Rational(-1, 3), Pi())}, // -√3/2 | -π/3 + {Rational(-1, 2), mulExpr(Rational(-1, 4), Pi())}, // -√2/2 | -π/4 + {Rational(-1, 4), mulExpr(Rational(-1, 6), Pi())}, // -1/2 | -π/6 + {Rational(0), Integer(0).clone()}, // 0 | 0 + {Rational(1, 4), mulExpr(Rational(1, 6), Pi())}, // 1/2 | π/6 + {Rational(1, 2), mulExpr(Rational(1, 4), Pi())}, // √2/2 | π/4 + {Rational(3, 4), mulExpr(Rational(1, 3), Pi())}, // √3/2 | π/3 + {Rational(1), mulExpr(Rational(-1, 2), Pi())}, // 1 | -π/2 }; return findValue(trigTable, rhs); } ArgumentPtr InvTrigExpression::trigTableAcosSimplify(const Rational &rhs) { static const TrigonometryTable trigTable = { - {Rational(-1), Pi().clone()}, // -1 | π - {Rational(-3, 4), makeExpr(Mul(), Rational(5, 6), Pi())}, // -√3/2 | 5π/6 - {Rational(-1, 2), makeExpr(Mul(), Rational(3, 4), Pi())}, // -√2/2 | 3π/4 - {Rational(-1, 4), makeExpr(Mul(), Rational(2, 3), Pi())}, // -1/2 | 2π/3 - {Rational(0), makeExpr(Mul(), Rational(1, 2), Pi())}, // 0 | π/2 - {Rational(1, 4), makeExpr(Mul(), Rational(1, 3), Pi())}, // 1/2 | π/3 - {Rational(1, 2), makeExpr(Mul(), Rational(1, 4), Pi())}, // √2/2 | π/4 - {Rational(3, 4), makeExpr(Mul(), Rational(1, 6), Pi())}, // √3/2 | π/6 - {Rational(1), Integer(0).clone()}, // 1 | 0 + {Rational(-1), Pi().clone()}, // -1 | π + {Rational(-3, 4), mulExpr(Rational(5, 6), Pi())}, // -√3/2 | 5π/6 + {Rational(-1, 2), mulExpr(Rational(3, 4), Pi())}, // -√2/2 | 3π/4 + {Rational(-1, 4), mulExpr(Rational(2, 3), Pi())}, // -1/2 | 2π/3 + {Rational(0), mulExpr(Rational(1, 2), Pi())}, // 0 | π/2 + {Rational(1, 4), mulExpr(Rational(1, 3), Pi())}, // 1/2 | π/3 + {Rational(1, 2), mulExpr(Rational(1, 4), Pi())}, // √2/2 | π/4 + {Rational(3, 4), mulExpr(Rational(1, 6), Pi())}, // √3/2 | π/6 + {Rational(1), Integer(0).clone()}, // 1 | 0 }; return findValue(trigTable, rhs); } ArgumentPtr InvTrigExpression::trigTableAtanSimplify(const Rational &rhs) { static const TrigonometryTable trigTable = { - {Rational(-3), makeExpr(Mul(), Rational(-1, 3), Pi())}, // -√3 | -π/3 - {Rational(-1), makeExpr(Mul(), Rational(-1, 4), Pi())}, // -1 | -π/4 - {Rational(-1, 3), makeExpr(Mul(), Rational(-1, 6), Pi())}, // -√3/3 | -π/6 - {Rational(0), Integer(0).clone()}, // 0 | 0 - {Rational(1, 3), makeExpr(Mul(), Rational(1, 6), Pi())}, // √3/3 | π/6 - {Rational(1), makeExpr(Mul(), Rational(1, 4), Pi())}, // 1 | π/4 - {Rational(3), makeExpr(Mul(), Rational(1, 3), Pi())}, // √3 | π/3 + {Rational(-3), mulExpr(Rational(-1, 3), Pi())}, // -√3 | -π/3 + {Rational(-1), mulExpr(Rational(-1, 4), Pi())}, // -1 | -π/4 + {Rational(-1, 3), mulExpr(Rational(-1, 6), Pi())}, // -√3/3 | -π/6 + {Rational(0), Integer(0).clone()}, // 0 | 0 + {Rational(1, 3), mulExpr(Rational(1, 6), Pi())}, // √3/3 | π/6 + {Rational(1), mulExpr(Rational(1, 4), Pi())}, // 1 | π/4 + {Rational(3), mulExpr(Rational(1, 3), Pi())}, // √3 | π/3 }; return findValue(trigTable, rhs); } ArgumentPtr InvTrigExpression::trigTableAcotSimplify(const Rational &rhs) { static const TrigonometryTable trigTable = { - {Rational(-3), makeExpr(Mul(), Rational(-1, 6), Pi())}, // -√3 | -π/6 - {Rational(-1), makeExpr(Mul(), Rational(-1, 4), Pi())}, // -1 | -π/4 - {Rational(-1, 3), makeExpr(Mul(), Rational(-1, 3), Pi())}, // -√3/3 | -π/3 - {Rational(0), makeExpr(Mul(), Rational(1, 2), Pi())}, // 0 | π/2 - {Rational(1, 3), makeExpr(Mul(), Rational(1, 3), Pi())}, // √3/3 | π/3 - {Rational(1), makeExpr(Mul(), Rational(1, 4), Pi())}, // 1 | π/4 - {Rational(3), makeExpr(Mul(), Rational(1, 6), Pi())}, // √3 | π/6 + {Rational(-3), mulExpr(Rational(-1, 6), Pi())}, // -√3 | -π/6 + {Rational(-1), mulExpr(Rational(-1, 4), Pi())}, // -1 | -π/4 + {Rational(-1, 3), mulExpr(Rational(-1, 3), Pi())}, // -√3/3 | -π/3 + {Rational(0), mulExpr(Rational(1, 2), Pi())}, // 0 | π/2 + {Rational(1, 3), mulExpr(Rational(1, 3), Pi())}, // √3/3 | π/3 + {Rational(1), mulExpr(Rational(1, 4), Pi())}, // 1 | π/4 + {Rational(3), mulExpr(Rational(1, 6), Pi())}, // √3 | π/6 }; return findValue(trigTable, rhs); } diff --git a/src/fintamath/expressions/unary/NotExpression.cpp b/src/fintamath/expressions/unary/NotExpression.cpp index bee1d31ba..d121b2b89 100644 --- a/src/fintamath/expressions/unary/NotExpression.cpp +++ b/src/fintamath/expressions/unary/NotExpression.cpp @@ -59,19 +59,19 @@ ArgumentPtr NotExpression::logicNegatableSimplify(const IFunction & /*func*/, co ArgumentsPtrVector children = rhsExpr->getChildren(); for (auto &child : children) { - child = makeExpr(Not(), child); + child = notExpr(child); } - res = makeExpr(And(), children); + res = andExpr(children); } else if (is(rhsExpr->getFunction())) { ArgumentsPtrVector children = rhsExpr->getChildren(); for (auto &child : children) { - child = makeExpr(Not(), child); + child = notExpr(child); } - res = makeExpr(Or(), children); + res = orExpr(children); } return res; diff --git a/src/fintamath/expressions/unary/TrigExpression.cpp b/src/fintamath/expressions/unary/TrigExpression.cpp index ae36271dd..62579698f 100644 --- a/src/fintamath/expressions/unary/TrigExpression.cpp +++ b/src/fintamath/expressions/unary/TrigExpression.cpp @@ -58,7 +58,7 @@ ArgumentPtr TrigExpression::constSimplify(const IFunction &func, const ArgumentP return trigTableSimplify(func, 1); } - if (*rhs == *makeExpr(Neg(), Pi())) { + if (*rhs == *negExpr(Pi())) { return trigTableSimplify(func, -1); } @@ -93,15 +93,15 @@ ArgumentPtr TrigExpression::trigTableSimplify(const IFunction &func, const Ratio ArgumentPtr TrigExpression::trigTableSinSimplify(const Rational &rhs) { static const TrigonometryTable trigTable = { - {Rational(0), Integer(0).clone()}, // 0 | 0 - {Rational(1, 6), Rational(1, 2).clone()}, // π/6 | 1/2 - {Rational(1, 4), makeExpr(Mul(), Rational(1, 2).clone(), makeExpr(Sqrt(), Integer(2)))}, // π/4 | √2/2 - {Rational(1, 3), makeExpr(Mul(), Rational(1, 2).clone(), makeExpr(Sqrt(), Integer(3)))}, // π/3 | √3/2 - {Rational(1, 2), Integer(1).clone()}, // π/2 | 1 - {Rational(2, 3), makeExpr(Mul(), Rational(1, 2).clone(), makeExpr(Sqrt(), Integer(3)))}, // 2π/3 | √3/2 - {Rational(3, 4), makeExpr(Mul(), Rational(1, 2).clone(), makeExpr(Sqrt(), Integer(2)))}, // 3π/4 | √2/2 - {Rational(5, 6), Rational(1, 2).clone()}, // 5π/6 | 1/2 - {Rational(1), Integer(0).clone()}, // π | 0 + {Rational(0), Integer(0).clone()}, // 0 | 0 + {Rational(1, 6), Rational(1, 2).clone()}, // π/6 | 1/2 + {Rational(1, 4), mulExpr(Rational(1, 2).clone(), sqrtExpr(Integer(2)))}, // π/4 | √2/2 + {Rational(1, 3), mulExpr(Rational(1, 2).clone(), sqrtExpr(Integer(3)))}, // π/3 | √3/2 + {Rational(1, 2), Integer(1).clone()}, // π/2 | 1 + {Rational(2, 3), mulExpr(Rational(1, 2).clone(), sqrtExpr(Integer(3)))}, // 2π/3 | √3/2 + {Rational(3, 4), mulExpr(Rational(1, 2).clone(), sqrtExpr(Integer(2)))}, // 3π/4 | √2/2 + {Rational(5, 6), Rational(1, 2).clone()}, // 5π/6 | 1/2 + {Rational(1), Integer(0).clone()}, // π | 0 }; auto [rhsShifted, isNegated] = phaseShiftSin(rhs); return findValue(trigTable, rhsShifted, isNegated); @@ -109,15 +109,15 @@ ArgumentPtr TrigExpression::trigTableSinSimplify(const Rational &rhs) { ArgumentPtr TrigExpression::trigTableCosSimplify(const Rational &rhs) { static const TrigonometryTable trigTable = { - {Rational(0), Integer(1).clone()}, // 0 | 1 - {Rational(1, 6), makeExpr(Mul(), Rational(1, 2).clone(), makeExpr(Sqrt(), Integer(3)))}, // π/6 | √3/2 - {Rational(1, 4), makeExpr(Mul(), Rational(1, 2).clone(), makeExpr(Sqrt(), Integer(2)))}, // π/4 | √2/2 - {Rational(1, 3), Rational(1, 2).clone()}, // π/3 | 1/2 - {Rational(1, 2), Integer(0).clone()}, // π/2 | 0 - {Rational(2, 3), Rational(-1, 2).clone()}, // 2π/3 | -1/2 - {Rational(3, 4), makeExpr(Mul(), Rational(-1, 2).clone(), makeExpr(Sqrt(), Integer(2)))}, // 3π/4 | -√2/2 - {Rational(5, 6), makeExpr(Mul(), Rational(-1, 2).clone(), makeExpr(Sqrt(), Integer(3)))}, // 5π/6 | -√3/2 - {Rational(1), Integer(-1).clone()}, // π | -1 + {Rational(0), Integer(1).clone()}, // 0 | 1 + {Rational(1, 6), mulExpr(Rational(1, 2).clone(), sqrtExpr(Integer(3)))}, // π/6 | √3/2 + {Rational(1, 4), mulExpr(Rational(1, 2).clone(), sqrtExpr(Integer(2)))}, // π/4 | √2/2 + {Rational(1, 3), Rational(1, 2).clone()}, // π/3 | 1/2 + {Rational(1, 2), Integer(0).clone()}, // π/2 | 0 + {Rational(2, 3), Rational(-1, 2).clone()}, // 2π/3 | -1/2 + {Rational(3, 4), mulExpr(Rational(-1, 2).clone(), sqrtExpr(Integer(2)))}, // 3π/4 | -√2/2 + {Rational(5, 6), mulExpr(Rational(-1, 2).clone(), sqrtExpr(Integer(3)))}, // 5π/6 | -√3/2 + {Rational(1), Integer(-1).clone()}, // π | -1 }; auto [rhsShifted, isNegated] = phaseShiftCos(rhs); return findValue(trigTable, rhsShifted, isNegated); @@ -125,15 +125,15 @@ ArgumentPtr TrigExpression::trigTableCosSimplify(const Rational &rhs) { ArgumentPtr TrigExpression::trigTableTanSimplify(const Rational &rhs) { static const TrigonometryTable trigTable = { - {Rational(0), Integer(0).clone()}, // 0 | 0 - {Rational(1, 6), makeExpr(Mul(), Rational(1, 3).clone(), makeExpr(Sqrt(), Integer(3)))}, // π/6 | √3/3 - {Rational(1, 4), Integer(1).clone()}, // π/4 | 1 - {Rational(1, 3), makeExpr(Sqrt(), Integer(3))}, // π/3 | √3 - {Rational(1, 2), ComplexInf().clone()}, // π/2 | ComplexInf - {Rational(2, 3), makeExpr(Neg(), makeExpr(Sqrt(), Integer(3)))}, // 2π/3 | -√3 - {Rational(3, 4), Integer(-1).clone()}, // 3π/4 | -1 - {Rational(5, 6), makeExpr(Mul(), Rational(-1, 3).clone(), makeExpr(Sqrt(), Integer(3)))}, // 5π/6 | -√3/3 - {Rational(1), Integer(0).clone()}, // π | 0 + {Rational(0), Integer(0).clone()}, // 0 | 0 + {Rational(1, 6), mulExpr(Rational(1, 3).clone(), sqrtExpr(Integer(3)))}, // π/6 | √3/3 + {Rational(1, 4), Integer(1).clone()}, // π/4 | 1 + {Rational(1, 3), sqrtExpr(Integer(3))}, // π/3 | √3 + {Rational(1, 2), ComplexInf().clone()}, // π/2 | ComplexInf + {Rational(2, 3), negExpr(sqrtExpr(Integer(3)))}, // 2π/3 | -√3 + {Rational(3, 4), Integer(-1).clone()}, // 3π/4 | -1 + {Rational(5, 6), mulExpr(Rational(-1, 3).clone(), sqrtExpr(Integer(3)))}, // 5π/6 | -√3/3 + {Rational(1), Integer(0).clone()}, // π | 0 }; auto [rhsShifted, isNegated] = phaseShiftTan(rhs); return findValue(trigTable, rhsShifted, isNegated); @@ -141,15 +141,15 @@ ArgumentPtr TrigExpression::trigTableTanSimplify(const Rational &rhs) { ArgumentPtr TrigExpression::trigTableCotSimplify(const Rational &rhs) { static const TrigonometryTable trigTable = { - {Rational(0), ComplexInf().clone()}, // 0 | ComplexInf - {Rational(1, 6), makeExpr(Sqrt(), Integer(3))}, // π/6 | √3 - {Rational(1, 4), Integer(1).clone()}, // π/4 | 1 - {Rational(1, 3), makeExpr(Mul(), Rational(1, 3).clone(), makeExpr(Sqrt(), Integer(3)))}, // π/3 | √3/3 - {Rational(1, 2), Integer(0).clone()}, // π/2 | 0 - {Rational(2, 3), makeExpr(Mul(), Rational(-1, 3).clone(), makeExpr(Sqrt(), Integer(3)))}, // 2π/3 | -√3/3 - {Rational(3, 4), Integer(-1).clone()}, // 3π/4 | -1 - {Rational(5, 6), makeExpr(Neg(), makeExpr(Sqrt(), Integer(3)))}, // 5π/6 | -√3 - {Rational(1), ComplexInf().clone()}, // π | ComplexInf + {Rational(0), ComplexInf().clone()}, // 0 | ComplexInf + {Rational(1, 6), sqrtExpr(Integer(3))}, // π/6 | √3 + {Rational(1, 4), Integer(1).clone()}, // π/4 | 1 + {Rational(1, 3), mulExpr(Rational(1, 3).clone(), sqrtExpr(Integer(3)))}, // π/3 | √3/3 + {Rational(1, 2), Integer(0).clone()}, // π/2 | 0 + {Rational(2, 3), mulExpr(Rational(-1, 3).clone(), sqrtExpr(Integer(3)))}, // 2π/3 | -√3/3 + {Rational(3, 4), Integer(-1).clone()}, // 3π/4 | -1 + {Rational(5, 6), negExpr(sqrtExpr(Integer(3)))}, // 5π/6 | -√3 + {Rational(1), ComplexInf().clone()}, // π | ComplexInf }; auto [rhsShifted, isNegated] = phaseShiftCot(rhs); return findValue(trigTable, rhsShifted, isNegated); @@ -224,7 +224,7 @@ std::shared_ptr TrigExpression::getOppositeFunction(const IFunction & ArgumentPtr findValue(const TrigonometryTable &trigTable, const Rational &key, bool isNegated) { if (auto res = trigTable.find(key); res != trigTable.end()) { - return isNegated ? makeExpr(Neg(), res->second) : res->second; + return isNegated ? negExpr(res->second) : res->second; } return {}; diff --git a/src/fintamath/functions/other/Deg.cpp b/src/fintamath/functions/other/Deg.cpp index 1aca8662a..ff820fd67 100644 --- a/src/fintamath/functions/other/Deg.cpp +++ b/src/fintamath/functions/other/Deg.cpp @@ -7,10 +7,10 @@ namespace fintamath { std::unique_ptr Deg::call(const ArgumentsRefVector &argsVect) const { - static const ArgumentPtr degVal = makeExpr(Div(), Pi(), Integer(180)); + static const ArgumentPtr degVal = divExpr(Pi(), Integer(180)); const auto &rhs = argsVect.front().get(); - return makeExpr(Mul(), rhs, *degVal)->toMinimalObject(); + return mulExpr(rhs, *degVal)->toMinimalObject(); } } diff --git a/src/fintamath/functions/powers/Root.cpp b/src/fintamath/functions/powers/Root.cpp index 419c25a3a..4c2881071 100644 --- a/src/fintamath/functions/powers/Root.cpp +++ b/src/fintamath/functions/powers/Root.cpp @@ -77,7 +77,7 @@ std::unique_ptr Root::rootSimplify(const Integer &lhs, const Intege for (auto [root, factor] : rootFactors) { if (factor != 1) { - mulChildren.emplace_back(makeExpr(Root(), factor, root)); + mulChildren.emplace_back(rootExpr(factor, root)); } } @@ -85,7 +85,7 @@ std::unique_ptr Root::rootSimplify(const Integer &lhs, const Intege return mulChildren.front()->clone(); } - return makeExpr(Mul(), mulChildren); + return mulExpr(mulChildren); } std::map Root::roots(const Integer &lhs, const Integer &rhs) { @@ -148,11 +148,11 @@ std::unique_ptr Root::rootSimplify(const Rational &lhs, const Integ } ArgumentPtr denominatorRes = Root()(lhs.denominator(), rhs); - return makeExpr(Div(), numeratorRes, denominatorRes); + return divExpr(numeratorRes, denominatorRes); } if (ArgumentPtr denominatorRes = perfectRoot(lhs.denominator(), rhs)) { - return makeExpr(Div(), Root()(lhs.numerator(), rhs), denominatorRes); + return divExpr(Root()(lhs.numerator(), rhs), denominatorRes); } ArgumentsPtrVector numeratorChildren; @@ -189,14 +189,14 @@ std::unique_ptr Root::rootSimplify(const Rational &lhs, const Integ denominator *= denominatorFactor; Integer numeratorChild = numeratorFactor * pow(denominatorFactor, root - 1); - numeratorChildren.emplace_back(makeExpr(Root(), numeratorChild, root)); + numeratorChildren.emplace_back(rootExpr(numeratorChild, root)); continue; } } if (numeratorFactor != 1) { - numeratorChildren.emplace_back(makeExpr(Root(), numeratorFactor, root)); + numeratorChildren.emplace_back(rootExpr(numeratorFactor, root)); } } @@ -205,7 +205,7 @@ std::unique_ptr Root::rootSimplify(const Rational &lhs, const Integ denominator *= denominatorFactor; Integer numeratorChild = pow(denominatorFactor, root - 1); - numeratorChildren.emplace_back(makeExpr(Root(), numeratorChild, root)); + numeratorChildren.emplace_back(rootExpr(numeratorChild, root)); } } @@ -214,10 +214,10 @@ std::unique_ptr Root::rootSimplify(const Rational &lhs, const Integ numerator = numeratorChildren.front(); } else { - numerator = makeExpr(Mul(), numeratorChildren); + numerator = mulExpr(numeratorChildren); } - return makeExpr(Div(), numerator, denominator.toMinimalObject()); + return divExpr(numerator, denominator.toMinimalObject()); } std::unique_ptr Root::rootSimplify(const Real &lhs, const Integer &rhs) { diff --git a/src/fintamath/functions/trigonometry/Acos.cpp b/src/fintamath/functions/trigonometry/Acos.cpp index d2ed194b8..c7c7cae8d 100644 --- a/src/fintamath/functions/trigonometry/Acos.cpp +++ b/src/fintamath/functions/trigonometry/Acos.cpp @@ -16,7 +16,7 @@ std::unique_ptr Acos::call(const ArgumentsRefVector &argsVect) cons } if (rhs == Integer(0)) { - return makeExpr(Div(), Pi(), Integer(2))->toMinimalObject(); + return divExpr(Pi(), Integer(2))->toMinimalObject(); } if (rhs == Integer(1)) { diff --git a/src/fintamath/functions/trigonometry/Acot.cpp b/src/fintamath/functions/trigonometry/Acot.cpp index eac02fc95..ca976fcca 100644 --- a/src/fintamath/functions/trigonometry/Acot.cpp +++ b/src/fintamath/functions/trigonometry/Acot.cpp @@ -11,15 +11,15 @@ std::unique_ptr Acot::call(const ArgumentsRefVector &argsVect) cons const auto &rhs = cast(argsVect.front().get()); if (rhs == Integer(-1)) { - return makeExpr(Neg(), makeExpr(Div(), Pi(), Integer(4)))->toMinimalObject(); + return negExpr(divExpr(Pi(), Integer(4)))->toMinimalObject(); } if (rhs == Integer(0)) { - return makeExpr(Div(), Pi(), Integer(2))->toMinimalObject(); + return divExpr(Pi(), Integer(2))->toMinimalObject(); } if (rhs == Integer(1)) { - return makeExpr(Div(), Pi(), Integer(4))->toMinimalObject(); + return divExpr(Pi(), Integer(4))->toMinimalObject(); } return multiAcotSimplify(rhs); diff --git a/src/fintamath/functions/trigonometry/Asin.cpp b/src/fintamath/functions/trigonometry/Asin.cpp index 9883c1efa..26b5c2242 100644 --- a/src/fintamath/functions/trigonometry/Asin.cpp +++ b/src/fintamath/functions/trigonometry/Asin.cpp @@ -12,7 +12,7 @@ std::unique_ptr Asin::call(const ArgumentsRefVector &argsVect) cons const auto &rhs = cast(argsVect.front().get()); if (rhs == Integer(-1)) { - return makeExpr(Neg(), makeExpr(Div(), Pi(), Integer(2)))->toMinimalObject(); + return negExpr(divExpr(Pi(), Integer(2)))->toMinimalObject(); } if (rhs == Integer(0)) { @@ -20,7 +20,7 @@ std::unique_ptr Asin::call(const ArgumentsRefVector &argsVect) cons } if (rhs == Integer(1)) { - return makeExpr(Div(), Pi(), Integer(2))->toMinimalObject(); + return divExpr(Pi(), Integer(2))->toMinimalObject(); } return multiAsinSimplify(rhs); diff --git a/src/fintamath/functions/trigonometry/Atan.cpp b/src/fintamath/functions/trigonometry/Atan.cpp index 6fd03dbba..864afec64 100644 --- a/src/fintamath/functions/trigonometry/Atan.cpp +++ b/src/fintamath/functions/trigonometry/Atan.cpp @@ -11,7 +11,7 @@ std::unique_ptr Atan::call(const ArgumentsRefVector &argsVect) cons const auto &rhs = cast(argsVect.front().get()); if (rhs == Integer(-1)) { - return makeExpr(Neg(), makeExpr(Div(), Pi(), Integer(4)))->toMinimalObject(); + return negExpr(divExpr(Pi(), Integer(4)))->toMinimalObject(); } if (rhs == Integer(0)) { @@ -19,7 +19,7 @@ std::unique_ptr Atan::call(const ArgumentsRefVector &argsVect) cons } if (rhs == Integer(1)) { - return makeExpr(Div(), Pi(), Integer(4))->toMinimalObject(); + return divExpr(Pi(), Integer(4))->toMinimalObject(); } return multiAtanSimplify(rhs); diff --git a/tests/src/expressions/FunctionExpressionTests.cpp b/tests/src/expressions/FunctionExpressionTests.cpp index 04b701054..d7d8a6cf0 100644 --- a/tests/src/expressions/FunctionExpressionTests.cpp +++ b/tests/src/expressions/FunctionExpressionTests.cpp @@ -141,6 +141,5 @@ TEST(FunctionExpressionTests, preciseTest) { } TEST(FunctionExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(TestBinaryOperator(), Integer(0), Integer(0))->getTypeId(), - MathObjectTypeId(MathObjectType::FunctionExpression)); + EXPECT_EQ(makeExpr(TestBinaryOperator(), Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::FunctionExpression)); } diff --git a/tests/src/expressions/IExpressionTests.cpp b/tests/src/expressions/IExpressionTests.cpp index 572bb9bd2..c701a777a 100644 --- a/tests/src/expressions/IExpressionTests.cpp +++ b/tests/src/expressions/IExpressionTests.cpp @@ -58,7 +58,7 @@ TEST(IExpressionTests, getChildrenTest) { } TEST(IExpressionTests, setChildrenTest) { - auto expr = cast(makeExpr(Factorial(), Variable("a"))->clone()); + auto expr = cast(factorialExpr(Variable("a"))->clone()); expr->setChildren({Variable("b").clone()}); EXPECT_EQ(expr->toString(), "b!"); @@ -97,17 +97,9 @@ TEST(IExpressionTests, getTypeIdTest) { } TEST(IExpressionTests, arithmeticTest) { - EXPECT_THROW(cast(*makeExpr(Sin(), Integer(1).clone())) + - cast(*makeExpr(Sin(), Integer(1).clone())), - InvalidInputException); - EXPECT_THROW(cast(*makeExpr(Sin(), Integer(1).clone())) - - cast(*makeExpr(Sin(), Integer(1).clone())), - InvalidInputException); - EXPECT_THROW(cast(*makeExpr(Sin(), Integer(1).clone())) * - cast(*makeExpr(Sin(), Integer(1).clone())), - InvalidInputException); - EXPECT_THROW(cast(*makeExpr(Sin(), Integer(1).clone())) / - cast(*makeExpr(Sin(), Integer(1).clone())), - InvalidInputException); - EXPECT_THROW(-cast(*makeExpr(Sin(), Integer(1).clone())), InvalidInputException); + EXPECT_THROW(cast(*sinExpr(Integer(1).clone())) + cast(*sinExpr(Integer(1).clone())), InvalidInputException); + EXPECT_THROW(cast(*sinExpr(Integer(1).clone())) - cast(*sinExpr(Integer(1).clone())), InvalidInputException); + EXPECT_THROW(cast(*sinExpr(Integer(1).clone())) * cast(*sinExpr(Integer(1).clone())), InvalidInputException); + EXPECT_THROW(cast(*sinExpr(Integer(1).clone())) / cast(*sinExpr(Integer(1).clone())), InvalidInputException); + EXPECT_THROW(-cast(*sinExpr(Integer(1).clone())), InvalidInputException); } diff --git a/tests/src/expressions/binary/CompExpressionTests.cpp b/tests/src/expressions/binary/CompExpressionTests.cpp index d361ce4e2..ee4905d1b 100644 --- a/tests/src/expressions/binary/CompExpressionTests.cpp +++ b/tests/src/expressions/binary/CompExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(CompExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Eqv(), Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::CompExpression)); + EXPECT_EQ(eqvExpr(Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::CompExpression)); } diff --git a/tests/src/expressions/binary/DerivativeExpressionTests.cpp b/tests/src/expressions/binary/DerivativeExpressionTests.cpp index 351f55cac..f612db7bc 100644 --- a/tests/src/expressions/binary/DerivativeExpressionTests.cpp +++ b/tests/src/expressions/binary/DerivativeExpressionTests.cpp @@ -7,6 +7,5 @@ using namespace fintamath; TEST(DerivativeExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Derivative(), Integer(0), Integer(0))->getTypeId(), - MathObjectTypeId(MathObjectType::DerivativeExpression)); + EXPECT_EQ(derivativeExpr(Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::DerivativeExpression)); } diff --git a/tests/src/expressions/binary/DivExpressionTests.cpp b/tests/src/expressions/binary/DivExpressionTests.cpp index 2f0e7380f..ec83c9ad4 100644 --- a/tests/src/expressions/binary/DivExpressionTests.cpp +++ b/tests/src/expressions/binary/DivExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(DivExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Div(), Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::DivExpression)); + EXPECT_EQ(divExpr(Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::DivExpression)); } diff --git a/tests/src/expressions/binary/IntegralExpressionTests.cpp b/tests/src/expressions/binary/IntegralExpressionTests.cpp index 86e0e911d..f20bb5668 100644 --- a/tests/src/expressions/binary/IntegralExpressionTests.cpp +++ b/tests/src/expressions/binary/IntegralExpressionTests.cpp @@ -7,6 +7,5 @@ using namespace fintamath; TEST(IntegralExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Integral(), Integer(0), Integer(0))->getTypeId(), - MathObjectTypeId(MathObjectType::IntegralExpression)); + EXPECT_EQ(integralExpr(Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::IntegralExpression)); } diff --git a/tests/src/expressions/binary/LogExpressionTests.cpp b/tests/src/expressions/binary/LogExpressionTests.cpp index e357dee89..8b0b6fa25 100644 --- a/tests/src/expressions/binary/LogExpressionTests.cpp +++ b/tests/src/expressions/binary/LogExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(LogExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Log(), Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::LogExpression)); + EXPECT_EQ(logExpr(Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::LogExpression)); } diff --git a/tests/src/expressions/binary/PowExpressionTests.cpp b/tests/src/expressions/binary/PowExpressionTests.cpp index bb7cee9a9..a99666273 100644 --- a/tests/src/expressions/binary/PowExpressionTests.cpp +++ b/tests/src/expressions/binary/PowExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(PowExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Pow(), Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::PowExpression)); + EXPECT_EQ(powExpr(Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::PowExpression)); } diff --git a/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp b/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp index b8e5dff4a..e35a2ced5 100644 --- a/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp +++ b/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp @@ -28,7 +28,7 @@ TEST(IPolynomExpressionTests, toStringTest) { TestPolynomExpression expr({Integer(1).clone(), Integer(2).clone(), Integer(3).clone()}); EXPECT_EQ(expr.toString(), "1 * 2 * 3"); - expr = TestPolynomExpression({makeExpr(Add(), Variable("x"), Variable("y")), Variable("a").clone()}); + expr = TestPolynomExpression({addExpr(Variable("x"), Variable("y")), Variable("a").clone()}); EXPECT_EQ(expr.toString(), "(x + y) * a"); } diff --git a/tests/src/expressions/polynomial/AddExpressionTests.cpp b/tests/src/expressions/polynomial/AddExpressionTests.cpp index 5739d0cc7..4b089bfeb 100644 --- a/tests/src/expressions/polynomial/AddExpressionTests.cpp +++ b/tests/src/expressions/polynomial/AddExpressionTests.cpp @@ -8,5 +8,5 @@ using namespace fintamath; TEST(AddExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Add(), Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::AddExpression)); + EXPECT_EQ(addExpr(Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::AddExpression)); } diff --git a/tests/src/expressions/polynomial/AndExpressionTests.cpp b/tests/src/expressions/polynomial/AndExpressionTests.cpp index 7379aaa07..3c1a79481 100644 --- a/tests/src/expressions/polynomial/AndExpressionTests.cpp +++ b/tests/src/expressions/polynomial/AndExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(AndExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(And(), Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::AndExpression)); + EXPECT_EQ(andExpr(Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::AndExpression)); } diff --git a/tests/src/expressions/polynomial/MinMaxExpressionTests.cpp b/tests/src/expressions/polynomial/MinMaxExpressionTests.cpp index eeaa69b9d..3fbef9e65 100644 --- a/tests/src/expressions/polynomial/MinMaxExpressionTests.cpp +++ b/tests/src/expressions/polynomial/MinMaxExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(MinMaxExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Min(), Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::MinMaxExpression)); + EXPECT_EQ(minExpr(Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::MinMaxExpression)); } diff --git a/tests/src/expressions/polynomial/MulExpressionTests.cpp b/tests/src/expressions/polynomial/MulExpressionTests.cpp index cf3dc2eec..884f99f71 100644 --- a/tests/src/expressions/polynomial/MulExpressionTests.cpp +++ b/tests/src/expressions/polynomial/MulExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(MulExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Mul(), Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::MulExpression)); + EXPECT_EQ(mulExpr(Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::MulExpression)); } diff --git a/tests/src/expressions/polynomial/OrExpressionTests.cpp b/tests/src/expressions/polynomial/OrExpressionTests.cpp index 7f15ffd07..83b9883ad 100644 --- a/tests/src/expressions/polynomial/OrExpressionTests.cpp +++ b/tests/src/expressions/polynomial/OrExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(OrExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Or(), Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::OrExpression)); + EXPECT_EQ(orExpr(Integer(0), Integer(0))->getTypeId(), MathObjectTypeId(MathObjectType::OrExpression)); } diff --git a/tests/src/expressions/unary/HyperbExpressionTests.cpp b/tests/src/expressions/unary/HyperbExpressionTests.cpp index 980e796a8..a91373be0 100644 --- a/tests/src/expressions/unary/HyperbExpressionTests.cpp +++ b/tests/src/expressions/unary/HyperbExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(HyperbExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Sinh(), Integer(0).clone())->getTypeId(), MathObjectTypeId(MathObjectType::HyperbExpression)); + EXPECT_EQ(sinhExpr(Integer(0).clone())->getTypeId(), MathObjectTypeId(MathObjectType::HyperbExpression)); } diff --git a/tests/src/expressions/unary/InvHyperbExpressionTests.cpp b/tests/src/expressions/unary/InvHyperbExpressionTests.cpp index 1d70cda24..91cb894fe 100644 --- a/tests/src/expressions/unary/InvHyperbExpressionTests.cpp +++ b/tests/src/expressions/unary/InvHyperbExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(InvHyperbExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Asinh(), Integer(0).clone())->getTypeId(), MathObjectTypeId(MathObjectType::InvHyperbExpression)); + EXPECT_EQ(asinhExpr(Integer(0).clone())->getTypeId(), MathObjectTypeId(MathObjectType::InvHyperbExpression)); } diff --git a/tests/src/expressions/unary/InvTrigExpressionTests.cpp b/tests/src/expressions/unary/InvTrigExpressionTests.cpp index 6af626230..6af8105bc 100644 --- a/tests/src/expressions/unary/InvTrigExpressionTests.cpp +++ b/tests/src/expressions/unary/InvTrigExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(InvTrigExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Asin(), Integer(0).clone())->getTypeId(), MathObjectTypeId(MathObjectType::InvTrigExpression)); + EXPECT_EQ(asinExpr(Integer(0).clone())->getTypeId(), MathObjectTypeId(MathObjectType::InvTrigExpression)); } diff --git a/tests/src/expressions/unary/NotExpressionTests.cpp b/tests/src/expressions/unary/NotExpressionTests.cpp index 3de10c44e..0f1b174bf 100644 --- a/tests/src/expressions/unary/NotExpressionTests.cpp +++ b/tests/src/expressions/unary/NotExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(NotExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Not(), Integer(0).clone())->getTypeId(), MathObjectTypeId(MathObjectType::NotExpression)); + EXPECT_EQ(notExpr(Integer(0).clone())->getTypeId(), MathObjectTypeId(MathObjectType::NotExpression)); } diff --git a/tests/src/expressions/unary/TrigExpressionTests.cpp b/tests/src/expressions/unary/TrigExpressionTests.cpp index 4efc39e1b..6fcf7e04c 100644 --- a/tests/src/expressions/unary/TrigExpressionTests.cpp +++ b/tests/src/expressions/unary/TrigExpressionTests.cpp @@ -7,5 +7,5 @@ using namespace fintamath; TEST(TrigExpressionTests, getTypeIdTest) { - EXPECT_EQ(makeExpr(Sin(), Integer(0).clone())->getTypeId(), MathObjectTypeId(MathObjectType::TrigExpression)); + EXPECT_EQ(sinExpr(Integer(0).clone())->getTypeId(), MathObjectTypeId(MathObjectType::TrigExpression)); } From 81113083f411461985993bc6491c19b54f0a9c64 Mon Sep 17 00:00:00 2001 From: fintarin Date: Sat, 26 Aug 2023 14:00:08 +0300 Subject: [PATCH 2/4] Refactor make_shared and make_unique --- include/fintamath/parser/Parser.hpp | 4 +- src/fintamath/config/ConverterConfig.cpp | 12 +-- src/fintamath/config/ExpressionConfig.cpp | 94 +++++++++---------- src/fintamath/expressions/Expression.cpp | 10 +- .../expressions/binary/CompExpression.cpp | 2 +- .../binary/DerivativeExpression.cpp | 4 +- .../expressions/binary/DivExpression.cpp | 4 +- .../expressions/binary/IntegralExpression.cpp | 2 +- .../expressions/binary/LogExpression.cpp | 2 +- .../expressions/binary/PowExpression.cpp | 2 +- .../functions/ExpressionFunctionSolve.cpp | 12 +-- .../expressions/polynomial/AddExpression.cpp | 2 +- .../expressions/polynomial/AndExpression.cpp | 2 +- .../expressions/polynomial/MulExpression.cpp | 2 +- .../expressions/polynomial/OrExpression.cpp | 2 +- src/fintamath/functions/arithmetic/Sign.cpp | 6 +- src/fintamath/functions/comparison/Eqv.cpp | 2 +- src/fintamath/functions/comparison/Less.cpp | 2 +- .../functions/comparison/LessEqv.cpp | 2 +- src/fintamath/functions/comparison/More.cpp | 2 +- .../functions/comparison/MoreEqv.cpp | 2 +- src/fintamath/functions/comparison/Neqv.cpp | 2 +- src/fintamath/functions/logic/And.cpp | 2 +- src/fintamath/functions/logic/Equiv.cpp | 2 +- src/fintamath/functions/logic/Impl.cpp | 2 +- src/fintamath/functions/logic/Nequiv.cpp | 2 +- src/fintamath/functions/logic/Not.cpp | 2 +- src/fintamath/functions/logic/Or.cpp | 2 +- src/fintamath/functions/other/Index.cpp | 2 +- src/fintamath/literals/constants/E.cpp | 2 +- src/fintamath/literals/constants/False.cpp | 2 +- src/fintamath/literals/constants/Pi.cpp | 2 +- src/fintamath/literals/constants/True.cpp | 2 +- 33 files changed, 98 insertions(+), 98 deletions(-) diff --git a/include/fintamath/parser/Parser.hpp b/include/fintamath/parser/Parser.hpp index 9753a4a66..f408d99bc 100644 --- a/include/fintamath/parser/Parser.hpp +++ b/include/fintamath/parser/Parser.hpp @@ -32,7 +32,7 @@ class Parser { return std::make_unique(args...); }; - std::string name = std::make_unique()->toString(); + static const std::string name = Type().toString(); parserMap.insert({name, constructor}); Tokenizer::registerToken(name); @@ -40,7 +40,7 @@ class Parser { template static void add(Map &parserMap, Function &&parserFunc) { - std::string name = std::make_unique()->toString(); + static const std::string name = Type().toString(); parserMap.insert({name, std::move(parserFunc)}); Tokenizer::registerToken(name); diff --git a/src/fintamath/config/ConverterConfig.cpp b/src/fintamath/config/ConverterConfig.cpp index 3b31aac17..09a9d0464 100644 --- a/src/fintamath/config/ConverterConfig.cpp +++ b/src/fintamath/config/ConverterConfig.cpp @@ -20,24 +20,24 @@ namespace { struct ConverterConfig { ConverterConfig() { Converter::add([](const Integer & /*type*/, const Integer &value) { - return std::make_unique(value); + return Integer(value).clone(); }); Converter::add([](const Rational & /*type*/, const Rational &value) { - return std::make_unique(value); + return Rational(value).clone(); }); Converter::add([](const Rational & /*type*/, const Integer &value) { - return std::make_unique(value); + return Rational(value).clone(); }); Converter::add([](const Real & /*type*/, const Real &value) { - return std::make_unique(value); + return Real(value).clone(); }); Converter::add([](const Real & /*type*/, const Integer &value) { - return std::make_unique(value); + return Real(value).clone(); }); Converter::add([](const Real & /*type*/, const Rational &value) { - return std::make_unique(value); + return Real(value).clone(); }); } }; diff --git a/src/fintamath/config/ExpressionConfig.cpp b/src/fintamath/config/ExpressionConfig.cpp index 91571f5f5..51605ab0b 100644 --- a/src/fintamath/config/ExpressionConfig.cpp +++ b/src/fintamath/config/ExpressionConfig.cpp @@ -1,6 +1,7 @@ #include "fintamath/expressions/Expression.hpp" #include "fintamath/expressions/ExpressionUtils.hpp" +#include "fintamath/expressions/FunctionExpression.hpp" #include "fintamath/expressions/binary/CompExpression.hpp" #include "fintamath/expressions/binary/DerivativeExpression.hpp" #include "fintamath/expressions/binary/DivExpression.hpp" @@ -139,64 +140,63 @@ struct ExpressionConfig { static void registerFunctionExpressionMakers() { Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(args); + return AddExpression(args).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique( - ArgumentsPtrVector{args.front(), negExpr(args.back())}); + return AddExpression(ArgumentsPtrVector{args.front(), negExpr(args.back())}).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(args); + return MulExpression(args).clone(); }); Expression::registerFunctionExpressionMaker
([](const ArgumentsPtrVector &args) { - return std::make_unique(args.front(), args.back()); + return DivExpression(args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(args.front(), args.back()); + return DivExpression(args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(args); + return AndExpression(args).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(args); + return OrExpression(args).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(args.front(), args.back()); + return PowExpression(args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(args.front(), args.back()); + return PowExpression(args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Eqv(), args.front(), args.back()); + return CompExpression(Eqv(), args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Neqv(), args.front(), args.back()); + return CompExpression(Neqv(), args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Less(), args.front(), args.back()); + return CompExpression(Less(), args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(More(), args.front(), args.back()); + return CompExpression(More(), args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(LessEqv(), args.front(), args.back()); + return CompExpression(LessEqv(), args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(MoreEqv(), args.front(), args.back()); + return CompExpression(MoreEqv(), args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { @@ -209,7 +209,7 @@ struct ExpressionConfig { } ArgumentPtr res = func(*args.front(), *args.back()); - return std::make_unique(res); + return Expression(res).clone(); // TODO: looks weird }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { @@ -248,39 +248,39 @@ struct ExpressionConfig { }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return mulExpr(std::make_shared(-1), args.front()); + return mulExpr(Integer(-1).clone(), args.front()); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(args.front()); + return args.front()->clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(args.front()); + return NotExpression(args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(args.front(), args.back()); + return DerivativeExpression(args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(args.front(), args.back()); + return IntegralExpression(args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(args.front(), args.back()); + return LogExpression(args.front(), args.back()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(E().clone(), args.front()); + return LogExpression(E().clone(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(std::make_shared(2), args.front()); + return LogExpression(Integer(2).clone(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(std::make_shared(10), args.front()); + return LogExpression(Integer(10).clone(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { @@ -288,20 +288,20 @@ struct ExpressionConfig { }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - static const auto PERCENT_VALUE = std::make_shared(100); + static const ArgumentPtr PERCENT_VALUE = Integer(100).clone(); return divExpr(args.front(), PERCENT_VALUE); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Min(), args); + return MinMaxExpression(Min(), args).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Max(), args); + return MinMaxExpression(Max(), args).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return powExpr(args.front(), std::make_shared(1, 2)); + return powExpr(args.front(), Rational(1, 2).clone()); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { @@ -309,71 +309,71 @@ struct ExpressionConfig { return powExpr(args.front(), Rational(1) / (*num)); } - return powExpr(args.front(), divExpr(std::make_shared(1), args.back())); + return powExpr(args.front(), divExpr(Integer(1).clone(), args.back())); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Sin(), args.front()); + return TrigExpression(Sin(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Cos(), args.front()); + return TrigExpression(Cos(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Tan(), args.front()); + return TrigExpression(Tan(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Cot(), args.front()); + return TrigExpression(Cot(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Asin(), args.front()); + return InvTrigExpression(Asin(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Acos(), args.front()); + return InvTrigExpression(Acos(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Atan(), args.front()); + return InvTrigExpression(Atan(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Acot(), args.front()); + return InvTrigExpression(Acot(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Sinh(), args.front()); + return HyperbExpression(Sinh(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Cosh(), args.front()); + return HyperbExpression(Cosh(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Tanh(), args.front()); + return HyperbExpression(Tanh(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Coth(), args.front()); + return HyperbExpression(Coth(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Asinh(), args.front()); + return InvHyperbExpression(Asinh(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Acosh(), args.front()); + return InvHyperbExpression(Acosh(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Atanh(), args.front()); + return InvHyperbExpression(Atanh(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { - return std::make_unique(Acoth(), args.front()); + return InvHyperbExpression(Acoth(), args.front()).clone(); }); Expression::registerFunctionExpressionMaker([](const ArgumentsPtrVector &args) { diff --git a/src/fintamath/expressions/Expression.cpp b/src/fintamath/expressions/Expression.cpp index 385d3780b..501aee798 100644 --- a/src/fintamath/expressions/Expression.cpp +++ b/src/fintamath/expressions/Expression.cpp @@ -17,7 +17,7 @@ namespace fintamath { -Expression::Expression() : child(std::make_shared(0)) { +Expression::Expression() : child(Integer(0).clone()) { } Expression::Expression(const std::string &str) : child(fintamath::parseExpr(str)) { @@ -39,7 +39,7 @@ Expression::Expression(const ArgumentPtr &obj) { Expression::Expression(const IMathObject &obj) : Expression(obj.toMinimalObject()) { } -Expression::Expression(int64_t val) : child(std::make_shared(val)) { +Expression::Expression(int64_t val) : child(Integer(val).clone()) { } std::string Expression::toString() const { @@ -330,7 +330,7 @@ TermVector Expression::tokensToTerms(const TokenVector &tokens) { } void Expression::insertDelimiters(TermVector &terms) { - ArgumentPtr delimiter = std::make_unique(); + static const ArgumentPtr delimiter = Mul().clone(); for (size_t i = 1; i < terms.size(); i++) { if (!getTermValueIf(*terms[i - 1], isBinaryOperator) && @@ -485,7 +485,7 @@ void Expression::validateFunctionArgs(const std::shared_ptr &func, co void Expression::preciseRec(ArgumentPtr &arg, uint8_t precision) { if (const auto realArg = cast(arg)) { - arg = std::make_shared(realArg->precise(precision)); + arg = realArg->precise(precision).clone(); } else if (const auto exprArg = cast(arg)) { ArgumentsPtrVector newChildren = exprArg->getChildren(); @@ -514,7 +514,7 @@ std::unique_ptr makeExpr(const IFunction &func, const ArgumentsPtrV return expr; } - return std::make_unique(func, args); + return FunctionExpression(func, args).clone(); } std::unique_ptr makeExpr(const IFunction &func, const ArgumentsRefVector &args) { diff --git a/src/fintamath/expressions/binary/CompExpression.cpp b/src/fintamath/expressions/binary/CompExpression.cpp index ff72259fd..562403590 100644 --- a/src/fintamath/expressions/binary/CompExpression.cpp +++ b/src/fintamath/expressions/binary/CompExpression.cpp @@ -59,7 +59,7 @@ ArgumentPtr CompExpression::preSimplify() const { if (!hasInfinity(lhsChild) && !hasInfinity(rhsChild)) { ArgumentPtr resLhs = subExpr(simplExpr->lhsChild, simplExpr->rhsChild); preSimplifyChild(resLhs); - return std::make_shared(cast(*func), resLhs, std::make_shared(0)); + return CompExpression(cast(*func), resLhs, Integer(0).clone()).clone(); } } } diff --git a/src/fintamath/expressions/binary/DerivativeExpression.cpp b/src/fintamath/expressions/binary/DerivativeExpression.cpp index 93672f124..7cc215dba 100644 --- a/src/fintamath/expressions/binary/DerivativeExpression.cpp +++ b/src/fintamath/expressions/binary/DerivativeExpression.cpp @@ -28,10 +28,10 @@ ArgumentPtr DerivativeExpression::derivativeSimplify(const IFunction & /*func*/, ArgumentPtr res; if (is(lhs) || is(lhs)) { - res = std::make_shared(0); + res = Integer(0).clone(); } else if (is(lhs) && *lhs == *rhs) { - res = std::make_shared(1); + res = Integer(1).clone(); } return res; diff --git a/src/fintamath/expressions/binary/DivExpression.cpp b/src/fintamath/expressions/binary/DivExpression.cpp index 9f2ae5815..c56ccd9ff 100644 --- a/src/fintamath/expressions/binary/DivExpression.cpp +++ b/src/fintamath/expressions/binary/DivExpression.cpp @@ -368,7 +368,7 @@ std::pair DivExpression::mulSumSimplify(const Argument ArgumentPtr DivExpression::powSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs) { if (*lhs == *rhs) { - return std::make_shared(1); + return Integer(1).clone(); } auto [lhsChildRate, lhsChildValue] = getRateValuePair(lhs); @@ -415,7 +415,7 @@ std::pair DivExpression::getRateValuePair(const Argume return {powExprChildren[1], powExprChildren[0]}; } - return {std::make_shared(1), rhs}; + return {Integer(1).clone(), rhs}; } ArgumentPtr DivExpression::addRatesToValue(const ArgumentsPtrVector &rates, const ArgumentPtr &value) { diff --git a/src/fintamath/expressions/binary/IntegralExpression.cpp b/src/fintamath/expressions/binary/IntegralExpression.cpp index 6730e23dd..ebe19600a 100644 --- a/src/fintamath/expressions/binary/IntegralExpression.cpp +++ b/src/fintamath/expressions/binary/IntegralExpression.cpp @@ -35,7 +35,7 @@ ArgumentPtr IntegralExpression::integralSimplify(const IFunction & /*func*/, con res = mulExpr(lhs, rhs); } else if (is(lhs) && is(rhs) && *lhs == *rhs) { - res = divExpr(powExpr(lhs, std::make_shared(2)), std::make_shared(2)); + res = divExpr(powExpr(lhs, Integer(2).clone()), Integer(2).clone()); } // TODO: res + integral constant diff --git a/src/fintamath/expressions/binary/LogExpression.cpp b/src/fintamath/expressions/binary/LogExpression.cpp index 2b3853371..3d9eb0180 100644 --- a/src/fintamath/expressions/binary/LogExpression.cpp +++ b/src/fintamath/expressions/binary/LogExpression.cpp @@ -98,7 +98,7 @@ ArgumentPtr LogExpression::constSimplify(const IFunction & /*func*/, const Argum ArgumentPtr LogExpression::equalSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { if (*lhs == *rhs) { - return std::make_shared(1); + return Integer(1).clone(); } return {}; diff --git a/src/fintamath/expressions/binary/PowExpression.cpp b/src/fintamath/expressions/binary/PowExpression.cpp index c288b2249..068bb8945 100644 --- a/src/fintamath/expressions/binary/PowExpression.cpp +++ b/src/fintamath/expressions/binary/PowExpression.cpp @@ -163,7 +163,7 @@ ArgumentPtr PowExpression::sumPolynomSimplify(const ArgumentPtr &expr, const Int bitNumber = generateNextNumber(bitNumber); ArgumentsPtrVector mulExprPolynom; - mulExprPolynom.emplace_back(std::make_shared(multinomialCoefficient(powValue, vectOfPows))); + mulExprPolynom.emplace_back(multinomialCoefficient(powValue, vectOfPows).clone()); for (size_t j = 0; j < size_t(variableCount); j++) { ArgumentPtr powExprChild = powExpr(polynom[j], vectOfPows[j].clone()); diff --git a/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp b/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp index 8a162a541..67461768c 100644 --- a/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp +++ b/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp @@ -91,7 +91,7 @@ Expression solve(const Expression &rhs) { std::shared_ptr getElementPower(const ArgumentPtr &elem, const Variable &var) { if (const auto elemVar = cast(elem); elemVar && *elemVar == var) { - return cast(std::make_shared(1)); + return std::make_shared(1); } if (const auto expr = cast(elem)) { @@ -106,7 +106,7 @@ std::shared_ptr getElementPower(const ArgumentPtr &elem, const Va } } - return cast(std::make_shared(0)); + return std::make_shared(0); } std::shared_ptr getMulElementPower(const std::shared_ptr &elem, const Variable &var) { @@ -123,14 +123,14 @@ ArgumentPtr getElementRate(const ArgumentPtr &elem, const Variable &var) { if (const auto elemExpr = cast(elem)) { if (is(elemExpr->getFunction())) { if (hasVariable(elemExpr, var)) { - return std::make_shared(1); + return Integer(1).clone(); } return elem; } if (is(elemExpr->getFunction())) { - ArgumentsPtrVector coeff{std::make_shared(1)}; + ArgumentsPtrVector coeff = {Integer(1).clone()}; for (const auto &child : elemExpr->getChildren()) { coeff.emplace_back(getElementRate(child, var)); @@ -141,7 +141,7 @@ ArgumentPtr getElementRate(const ArgumentPtr &elem, const Variable &var) { } if (const auto elemVar = cast(elem); elemVar && var == *elemVar) { - return std::make_shared(1); + return Integer(1).clone(); } return elem; @@ -165,7 +165,7 @@ ArgumentsPtrVector getVariableIntPowerRates(const ArgumentPtr &elem, const Varia if (auto intPow = cast(power)) { if (int64_t(powerRates.size()) < *intPow + 1) { while (int64_t(powerRates.size()) != *intPow + 1) { - powerRates.emplace_back(std::make_shared(0)); + powerRates.emplace_back(Integer(0).clone()); } } diff --git a/src/fintamath/expressions/polynomial/AddExpression.cpp b/src/fintamath/expressions/polynomial/AddExpression.cpp index 22303769a..77455d7e7 100644 --- a/src/fintamath/expressions/polynomial/AddExpression.cpp +++ b/src/fintamath/expressions/polynomial/AddExpression.cpp @@ -247,7 +247,7 @@ std::pair AddExpression::getRateValuePair(const Argume } if (!rate || !value) { - rate = std::make_shared(1); + rate = Integer(1).clone(); value = inChild; } diff --git a/src/fintamath/expressions/polynomial/AndExpression.cpp b/src/fintamath/expressions/polynomial/AndExpression.cpp index 9fec59a4a..018fef488 100644 --- a/src/fintamath/expressions/polynomial/AndExpression.cpp +++ b/src/fintamath/expressions/polynomial/AndExpression.cpp @@ -60,7 +60,7 @@ ArgumentPtr AndExpression::notSimplify(const IFunction & /*func*/, const Argumen is(rhsExpr->getFunction()) && *rhsExpr->getChildren().front() == *lhsChild) { - return std::make_shared(false); + return Boolean(false).clone(); } return {}; diff --git a/src/fintamath/expressions/polynomial/MulExpression.cpp b/src/fintamath/expressions/polynomial/MulExpression.cpp index fc7875976..b442a635d 100644 --- a/src/fintamath/expressions/polynomial/MulExpression.cpp +++ b/src/fintamath/expressions/polynomial/MulExpression.cpp @@ -87,7 +87,7 @@ std::pair MulExpression::getRateValuePair(const Argume return {powExprChildren[1], powExprChildren[0]}; } - return {std::make_shared(1), rhsChild}; + return {Integer(1).clone(), rhsChild}; } ArgumentPtr MulExpression::constSimplify(const IFunction & /*func*/, diff --git a/src/fintamath/expressions/polynomial/OrExpression.cpp b/src/fintamath/expressions/polynomial/OrExpression.cpp index 8f3e390d5..00ce5d3f0 100644 --- a/src/fintamath/expressions/polynomial/OrExpression.cpp +++ b/src/fintamath/expressions/polynomial/OrExpression.cpp @@ -107,7 +107,7 @@ ArgumentPtr OrExpression::notSimplify(const IFunction & /*func*/, const Argument is(rhsExpr->getFunction()) && *rhsExpr->getChildren().front() == *lhsChild) { - return std::make_shared(true); + return Boolean(true).clone(); } return {}; diff --git a/src/fintamath/functions/arithmetic/Sign.cpp b/src/fintamath/functions/arithmetic/Sign.cpp index 77b7c62a2..04a08b3fe 100644 --- a/src/fintamath/functions/arithmetic/Sign.cpp +++ b/src/fintamath/functions/arithmetic/Sign.cpp @@ -16,15 +16,15 @@ std::unique_ptr Sign::multiSignSimplify(const INumber &rhs) { static MultiMethod(const INumber &)> outMultiSign; outMultiSign.add([](const Integer &inRhs) { - return std::make_unique(inRhs.sign()); + return Integer(inRhs.sign()).clone(); }); outMultiSign.add([](const Rational &inRhs) { - return std::make_unique(inRhs.sign()); + return Integer(inRhs.sign()).clone(); }); outMultiSign.add([](const Real &inRhs) { - return std::make_unique(inRhs.sign()); + return Integer(inRhs.sign()).clone(); }); return outMultiSign; diff --git a/src/fintamath/functions/comparison/Eqv.cpp b/src/fintamath/functions/comparison/Eqv.cpp index 1bbe1f661..1025969ee 100644 --- a/src/fintamath/functions/comparison/Eqv.cpp +++ b/src/fintamath/functions/comparison/Eqv.cpp @@ -6,7 +6,7 @@ std::unique_ptr Eqv::call(const ArgumentsRefVector &argsVect) const const auto &lhs = argsVect.front().get(); const auto &rhs = argsVect.back().get(); - return std::make_unique(lhs == rhs); + return Boolean(lhs == rhs).clone(); } } diff --git a/src/fintamath/functions/comparison/Less.cpp b/src/fintamath/functions/comparison/Less.cpp index e442a916a..73c680c49 100644 --- a/src/fintamath/functions/comparison/Less.cpp +++ b/src/fintamath/functions/comparison/Less.cpp @@ -13,7 +13,7 @@ std::unique_ptr Less::call(const ArgumentsRefVector &argsVect) cons // return {}; // } - return std::make_unique(lhs < rhs); + return Boolean(lhs < rhs).clone(); } } diff --git a/src/fintamath/functions/comparison/LessEqv.cpp b/src/fintamath/functions/comparison/LessEqv.cpp index 3115df3a6..5ad193ec6 100644 --- a/src/fintamath/functions/comparison/LessEqv.cpp +++ b/src/fintamath/functions/comparison/LessEqv.cpp @@ -11,7 +11,7 @@ std::unique_ptr LessEqv::call(const ArgumentsRefVector &argsVect) c // return {}; // } - return std::make_unique(lhs <= rhs); + return Boolean(lhs <= rhs).clone(); } } diff --git a/src/fintamath/functions/comparison/More.cpp b/src/fintamath/functions/comparison/More.cpp index f8d719066..e34dd84a8 100644 --- a/src/fintamath/functions/comparison/More.cpp +++ b/src/fintamath/functions/comparison/More.cpp @@ -11,7 +11,7 @@ std::unique_ptr More::call(const ArgumentsRefVector &argsVect) cons // return {}; // } - return std::make_unique(lhs > rhs); + return Boolean(lhs > rhs).clone(); } } diff --git a/src/fintamath/functions/comparison/MoreEqv.cpp b/src/fintamath/functions/comparison/MoreEqv.cpp index cf7dec0d7..3d80ba1b4 100644 --- a/src/fintamath/functions/comparison/MoreEqv.cpp +++ b/src/fintamath/functions/comparison/MoreEqv.cpp @@ -11,7 +11,7 @@ std::unique_ptr MoreEqv::call(const ArgumentsRefVector &argsVect) c // return {}; // } - return std::make_unique(lhs >= rhs); + return Boolean(lhs >= rhs).clone(); } } diff --git a/src/fintamath/functions/comparison/Neqv.cpp b/src/fintamath/functions/comparison/Neqv.cpp index cd65a972d..a89ce6e0c 100644 --- a/src/fintamath/functions/comparison/Neqv.cpp +++ b/src/fintamath/functions/comparison/Neqv.cpp @@ -6,7 +6,7 @@ std::unique_ptr Neqv::call(const ArgumentsRefVector &argsVect) cons const auto &lhs = argsVect.front().get(); const auto &rhs = argsVect.back().get(); - return std::make_unique(lhs != rhs); + return Boolean(lhs != rhs).clone(); } } diff --git a/src/fintamath/functions/logic/And.cpp b/src/fintamath/functions/logic/And.cpp index 6dbed76d5..85f45f293 100644 --- a/src/fintamath/functions/logic/And.cpp +++ b/src/fintamath/functions/logic/And.cpp @@ -6,7 +6,7 @@ std::unique_ptr And::call(const ArgumentsRefVector &argsVect) const const auto &lhs = cast(argsVect.front().get()); const auto &rhs = cast(argsVect.back().get()); - return std::make_unique(lhs && rhs); + return Boolean(lhs && rhs).clone(); } } diff --git a/src/fintamath/functions/logic/Equiv.cpp b/src/fintamath/functions/logic/Equiv.cpp index b9e34d7a2..f106a159a 100644 --- a/src/fintamath/functions/logic/Equiv.cpp +++ b/src/fintamath/functions/logic/Equiv.cpp @@ -6,7 +6,7 @@ std::unique_ptr Equiv::call(const ArgumentsRefVector &argsVect) con const auto &lhs = cast(argsVect.front().get()); const auto &rhs = cast(argsVect.back().get()); - return std::make_unique(lhs == rhs); + return Boolean(lhs == rhs).clone(); } } diff --git a/src/fintamath/functions/logic/Impl.cpp b/src/fintamath/functions/logic/Impl.cpp index 241296f70..4b520bd53 100644 --- a/src/fintamath/functions/logic/Impl.cpp +++ b/src/fintamath/functions/logic/Impl.cpp @@ -6,7 +6,7 @@ std::unique_ptr Impl::call(const ArgumentsRefVector &argsVect) cons const auto &lhs = cast(argsVect.front().get()); const auto &rhs = cast(argsVect.back().get()); - return std::make_unique(!lhs || rhs); + return Boolean(!lhs || rhs).clone(); } } diff --git a/src/fintamath/functions/logic/Nequiv.cpp b/src/fintamath/functions/logic/Nequiv.cpp index c3c4848a3..2d156aef8 100644 --- a/src/fintamath/functions/logic/Nequiv.cpp +++ b/src/fintamath/functions/logic/Nequiv.cpp @@ -6,7 +6,7 @@ std::unique_ptr Nequiv::call(const ArgumentsRefVector &argsVect) co const auto &lhs = cast(argsVect.front().get()); const auto &rhs = cast(argsVect.back().get()); - return std::make_unique(lhs != rhs); + return Boolean(lhs != rhs).clone(); } } diff --git a/src/fintamath/functions/logic/Not.cpp b/src/fintamath/functions/logic/Not.cpp index 264045014..ca7708840 100644 --- a/src/fintamath/functions/logic/Not.cpp +++ b/src/fintamath/functions/logic/Not.cpp @@ -5,7 +5,7 @@ namespace fintamath { std::unique_ptr Not::call(const ArgumentsRefVector &argsVect) const { const auto &rhs = cast(argsVect.front().get()); - return std::make_unique(!rhs); + return Boolean(!rhs).clone(); } } diff --git a/src/fintamath/functions/logic/Or.cpp b/src/fintamath/functions/logic/Or.cpp index 02c6b647d..c1b5dac0e 100644 --- a/src/fintamath/functions/logic/Or.cpp +++ b/src/fintamath/functions/logic/Or.cpp @@ -6,7 +6,7 @@ std::unique_ptr Or::call(const ArgumentsRefVector &argsVect) const const auto &lhs = cast(argsVect.front().get()); const auto &rhs = cast(argsVect.back().get()); - return std::make_unique(lhs || rhs); + return Boolean(lhs || rhs).clone(); } } diff --git a/src/fintamath/functions/other/Index.cpp b/src/fintamath/functions/other/Index.cpp index 057356f7e..c574b7919 100644 --- a/src/fintamath/functions/other/Index.cpp +++ b/src/fintamath/functions/other/Index.cpp @@ -6,7 +6,7 @@ std::unique_ptr Index::call(const ArgumentsRefVector &argsVect) con const auto &lhs = cast(argsVect.front().get()); const auto &rhs = cast(argsVect.back().get()); - return std::make_unique(lhs.toString(), rhs); + return Variable(lhs.toString(), rhs).clone(); } } diff --git a/src/fintamath/literals/constants/E.cpp b/src/fintamath/literals/constants/E.cpp index af995fe14..d15912d70 100644 --- a/src/fintamath/literals/constants/E.cpp +++ b/src/fintamath/literals/constants/E.cpp @@ -5,7 +5,7 @@ namespace fintamath { std::unique_ptr E::call() const { - return std::make_unique(getE()); + return getE().clone(); } } diff --git a/src/fintamath/literals/constants/False.cpp b/src/fintamath/literals/constants/False.cpp index c0c34a223..a1fd6d3d4 100644 --- a/src/fintamath/literals/constants/False.cpp +++ b/src/fintamath/literals/constants/False.cpp @@ -3,7 +3,7 @@ namespace fintamath { std::unique_ptr False::call() const { - return std::make_unique(false); + return Boolean(false).clone(); } } diff --git a/src/fintamath/literals/constants/Pi.cpp b/src/fintamath/literals/constants/Pi.cpp index b8ed6f9d6..89869fa86 100644 --- a/src/fintamath/literals/constants/Pi.cpp +++ b/src/fintamath/literals/constants/Pi.cpp @@ -5,7 +5,7 @@ namespace fintamath { std::unique_ptr Pi::call() const { - return std::make_unique(getPi()); + return getPi().clone(); } } diff --git a/src/fintamath/literals/constants/True.cpp b/src/fintamath/literals/constants/True.cpp index 81b9d37ff..d31eab719 100644 --- a/src/fintamath/literals/constants/True.cpp +++ b/src/fintamath/literals/constants/True.cpp @@ -3,7 +3,7 @@ namespace fintamath { std::unique_ptr True::call() const { - return std::make_unique(true); + return Boolean(true).clone(); } } From 14d82d94268237f159d3add1cd5cadd7ce14a061 Mon Sep 17 00:00:00 2001 From: fintarin Date: Sat, 26 Aug 2023 14:42:21 +0300 Subject: [PATCH 3/4] Number Number => Number*Number --- .../expressions/polynomial/MulExpression.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/fintamath/expressions/polynomial/MulExpression.cpp b/src/fintamath/expressions/polynomial/MulExpression.cpp index b442a635d..e9b020687 100644 --- a/src/fintamath/expressions/polynomial/MulExpression.cpp +++ b/src/fintamath/expressions/polynomial/MulExpression.cpp @@ -55,7 +55,17 @@ std::string MulExpression::operatorChildToString(const ArgumentPtr &inChild, con return Neg().toString(); } - return (prevChild && *prevChild != Integer(-1) ? " " : "") + inChild->toString(); + std::string operStr; + if (prevChild && *prevChild != Integer(-1)) { + if (is(inChild) && is(prevChild)) { + operStr = "*"; + } + else { + operStr = " "; + } + } + + return operStr + inChild->toString(); } MulExpression::SimplifyFunctionsVector MulExpression::getFunctionsForPreSimplify() const { From 2349291a5e0fe021d1f082a3c774a27feff5ff73 Mon Sep 17 00:00:00 2001 From: fintarin Date: Sat, 26 Aug 2023 15:17:47 +0300 Subject: [PATCH 4/4] Add tests for makeExpr wrappers --- tests/src/functions/arithmetic/AbsTests.cpp | 4 ++++ tests/src/functions/arithmetic/AddTests.cpp | 4 ++++ tests/src/functions/arithmetic/DivTests.cpp | 4 ++++ tests/src/functions/arithmetic/MulTests.cpp | 4 ++++ tests/src/functions/arithmetic/NegTests.cpp | 4 ++++ tests/src/functions/arithmetic/SignTests.cpp | 4 ++++ tests/src/functions/arithmetic/SubTests.cpp | 4 ++++ tests/src/functions/calculus/DerivativeTests.cpp | 4 ++++ tests/src/functions/calculus/IntegralTests.cpp | 4 ++++ tests/src/functions/calculus/MaxTests.cpp | 4 ++++ tests/src/functions/calculus/MinTests.cpp | 4 ++++ tests/src/functions/comparison/EqvTests.cpp | 4 ++++ tests/src/functions/comparison/LessEqvTests.cpp | 4 ++++ tests/src/functions/comparison/LessTests.cpp | 4 ++++ tests/src/functions/comparison/MoreEqvTests.cpp | 4 ++++ tests/src/functions/comparison/MoreTests.cpp | 4 ++++ tests/src/functions/comparison/NeqvTests.cpp | 4 ++++ tests/src/functions/hyperbolic/AcoshTests.cpp | 4 ++++ tests/src/functions/hyperbolic/AcothTests.cpp | 4 ++++ tests/src/functions/hyperbolic/AsinhTests.cpp | 4 ++++ tests/src/functions/hyperbolic/AtanhTests.cpp | 4 ++++ tests/src/functions/hyperbolic/CoshTests.cpp | 4 ++++ tests/src/functions/hyperbolic/CothTests.cpp | 4 ++++ tests/src/functions/hyperbolic/SinhTests.cpp | 4 ++++ tests/src/functions/hyperbolic/TanhTests.cpp | 4 ++++ tests/src/functions/logarithms/LbTests.cpp | 4 ++++ tests/src/functions/logarithms/LgTests.cpp | 4 ++++ tests/src/functions/logarithms/LnTests.cpp | 4 ++++ tests/src/functions/logarithms/LogTests.cpp | 4 ++++ tests/src/functions/logic/AndTests.cpp | 4 ++++ tests/src/functions/logic/EquivTests.cpp | 4 ++++ tests/src/functions/logic/ImplTests.cpp | 4 ++++ tests/src/functions/logic/NequivTests.cpp | 4 ++++ tests/src/functions/logic/NotTests.cpp | 4 ++++ tests/src/functions/logic/OrTests.cpp | 4 ++++ tests/src/functions/other/DegTests.cpp | 4 ++++ tests/src/functions/other/FactorialTests.cpp | 4 ++++ tests/src/functions/other/IndexTests.cpp | 4 ++++ tests/src/functions/other/PercentTests.cpp | 4 ++++ tests/src/functions/powers/ExpTests.cpp | 4 ++++ tests/src/functions/powers/PowTests.cpp | 4 ++++ tests/src/functions/powers/RootTests.cpp | 4 ++++ tests/src/functions/powers/SqrtTests.cpp | 4 ++++ tests/src/functions/trigonometry/AcosTests.cpp | 4 ++++ tests/src/functions/trigonometry/AcotTests.cpp | 4 ++++ tests/src/functions/trigonometry/AsinTests.cpp | 4 ++++ tests/src/functions/trigonometry/AtanTests.cpp | 4 ++++ tests/src/functions/trigonometry/CosTests.cpp | 4 ++++ tests/src/functions/trigonometry/CotTests.cpp | 4 ++++ tests/src/functions/trigonometry/SinTests.cpp | 4 ++++ tests/src/functions/trigonometry/TanTests.cpp | 4 ++++ 51 files changed, 204 insertions(+) diff --git a/tests/src/functions/arithmetic/AbsTests.cpp b/tests/src/functions/arithmetic/AbsTests.cpp index c1c3957db..f4427df8a 100644 --- a/tests/src/functions/arithmetic/AbsTests.cpp +++ b/tests/src/functions/arithmetic/AbsTests.cpp @@ -40,6 +40,10 @@ TEST(AbsTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(AbsTests, exprTest) { + EXPECT_EQ(absExpr(Integer(10))->toString(), "abs(10)"); +} + TEST(AbsTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/arithmetic/AddTests.cpp b/tests/src/functions/arithmetic/AddTests.cpp index df153845f..51c2d1939 100644 --- a/tests/src/functions/arithmetic/AddTests.cpp +++ b/tests/src/functions/arithmetic/AddTests.cpp @@ -40,6 +40,10 @@ TEST(AddTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(AddTests, exprTest) { + EXPECT_EQ(addExpr(Integer(10), Integer(10))->toString(), "10 + 10"); +} + TEST(AddTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/arithmetic/DivTests.cpp b/tests/src/functions/arithmetic/DivTests.cpp index 5f3e24086..9b57d7db9 100644 --- a/tests/src/functions/arithmetic/DivTests.cpp +++ b/tests/src/functions/arithmetic/DivTests.cpp @@ -42,6 +42,10 @@ TEST(DivTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(DivTests, exprTest) { + EXPECT_EQ(divExpr(Integer(10), Integer(10))->toString(), "10/10"); +} + TEST(DivTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/arithmetic/MulTests.cpp b/tests/src/functions/arithmetic/MulTests.cpp index 2577a1d1c..3d53e3564 100644 --- a/tests/src/functions/arithmetic/MulTests.cpp +++ b/tests/src/functions/arithmetic/MulTests.cpp @@ -37,6 +37,10 @@ TEST(MulTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(MulTests, exprTest) { + EXPECT_EQ(mulExpr(Integer(10), Integer(10))->toString(), "10*10"); +} + TEST(MulTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/arithmetic/NegTests.cpp b/tests/src/functions/arithmetic/NegTests.cpp index 2f92da944..5069c57a3 100644 --- a/tests/src/functions/arithmetic/NegTests.cpp +++ b/tests/src/functions/arithmetic/NegTests.cpp @@ -35,6 +35,10 @@ TEST(NegTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(NegTests, exprTest) { + EXPECT_EQ(negExpr(Integer(10))->toString(), "-10"); +} + TEST(NegTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/arithmetic/SignTests.cpp b/tests/src/functions/arithmetic/SignTests.cpp index 6e4aa6bbe..1e5f48b2b 100644 --- a/tests/src/functions/arithmetic/SignTests.cpp +++ b/tests/src/functions/arithmetic/SignTests.cpp @@ -31,6 +31,10 @@ TEST(SignTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(SignTests, exprTest) { + EXPECT_EQ(signExpr(Integer(10))->toString(), "sign(10)"); +} + TEST(SignTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/arithmetic/SubTests.cpp b/tests/src/functions/arithmetic/SubTests.cpp index feec7fb54..d8b5d0806 100644 --- a/tests/src/functions/arithmetic/SubTests.cpp +++ b/tests/src/functions/arithmetic/SubTests.cpp @@ -38,6 +38,10 @@ TEST(SubTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(SubTests, exprTest) { + EXPECT_EQ(subExpr(Integer(10), Integer(10))->toString(), "10 - 10"); +} + TEST(SubTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/calculus/DerivativeTests.cpp b/tests/src/functions/calculus/DerivativeTests.cpp index 6f93c25c3..35675f2ae 100644 --- a/tests/src/functions/calculus/DerivativeTests.cpp +++ b/tests/src/functions/calculus/DerivativeTests.cpp @@ -37,6 +37,10 @@ TEST(DerivativeTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputException); } +TEST(DerivativeTests, exprTest) { + EXPECT_EQ(derivativeExpr(Variable("a"), Variable("a"))->toString(), "derivative(a, a)"); +} + TEST(DerivativeTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/calculus/IntegralTests.cpp b/tests/src/functions/calculus/IntegralTests.cpp index de36918a0..aa403bee1 100644 --- a/tests/src/functions/calculus/IntegralTests.cpp +++ b/tests/src/functions/calculus/IntegralTests.cpp @@ -37,6 +37,10 @@ TEST(IntegralTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputException); } +TEST(IntegralTests, exprTest) { + EXPECT_EQ(integralExpr(Variable("a"), Variable("a"))->toString(), "integral(a, a)"); +} + TEST(IntegralTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/calculus/MaxTests.cpp b/tests/src/functions/calculus/MaxTests.cpp index 68eeab6d8..dd22f1cc5 100644 --- a/tests/src/functions/calculus/MaxTests.cpp +++ b/tests/src/functions/calculus/MaxTests.cpp @@ -39,6 +39,10 @@ TEST(MaxTests, callTest) { EXPECT_THROW(f(Boolean(), Integer(), Integer()), InvalidInputFunctionException); } +TEST(MaxTests, exprTest) { + EXPECT_EQ(maxExpr(Variable("a"), Variable("a"))->toString(), "max(a, a)"); +} + TEST(MaxTests, doArgsMatchTest) { EXPECT_FALSE(f.doArgsMatch({})); } diff --git a/tests/src/functions/calculus/MinTests.cpp b/tests/src/functions/calculus/MinTests.cpp index 6f9729dc1..9a0c3213c 100644 --- a/tests/src/functions/calculus/MinTests.cpp +++ b/tests/src/functions/calculus/MinTests.cpp @@ -39,6 +39,10 @@ TEST(MinTests, callTest) { EXPECT_THROW(f(Boolean(), Integer(), Integer()), InvalidInputFunctionException); } +TEST(MinTests, exprTest) { + EXPECT_EQ(minExpr(Variable("a"), Variable("a"))->toString(), "min(a, a)"); +} + TEST(MinTests, doArgsMatchTest) { EXPECT_FALSE(f.doArgsMatch({})); } diff --git a/tests/src/functions/comparison/EqvTests.cpp b/tests/src/functions/comparison/EqvTests.cpp index 70827250c..9987c1e8d 100644 --- a/tests/src/functions/comparison/EqvTests.cpp +++ b/tests/src/functions/comparison/EqvTests.cpp @@ -39,6 +39,10 @@ TEST(EqvTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(EqvTests, exprTest) { + EXPECT_EQ(eqvExpr(Integer(10), Integer(10))->toString(), "10 = 10"); +} + TEST(EqvTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/comparison/LessEqvTests.cpp b/tests/src/functions/comparison/LessEqvTests.cpp index 3708dae7d..25d546a60 100644 --- a/tests/src/functions/comparison/LessEqvTests.cpp +++ b/tests/src/functions/comparison/LessEqvTests.cpp @@ -39,6 +39,10 @@ TEST(LessEqvTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(LessEqvTests, exprTest) { + EXPECT_EQ(lessEqvExpr(Integer(10), Integer(10))->toString(), "10 <= 10"); +} + TEST(LessEqvTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/comparison/LessTests.cpp b/tests/src/functions/comparison/LessTests.cpp index 5e58786ed..418cf4931 100644 --- a/tests/src/functions/comparison/LessTests.cpp +++ b/tests/src/functions/comparison/LessTests.cpp @@ -39,6 +39,10 @@ TEST(LessTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(LessTests, exprTest) { + EXPECT_EQ(lessExpr(Integer(10), Integer(10))->toString(), "10 < 10"); +} + TEST(LessTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/comparison/MoreEqvTests.cpp b/tests/src/functions/comparison/MoreEqvTests.cpp index 3e23c5bef..7f864695d 100644 --- a/tests/src/functions/comparison/MoreEqvTests.cpp +++ b/tests/src/functions/comparison/MoreEqvTests.cpp @@ -39,6 +39,10 @@ TEST(MoreEqvTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(MoreEqvTests, exprTest) { + EXPECT_EQ(moreEqvExpr(Integer(10), Integer(10))->toString(), "10 >= 10"); +} + TEST(MoreEqvTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/comparison/MoreTests.cpp b/tests/src/functions/comparison/MoreTests.cpp index 5295fbe09..9b1fb7499 100644 --- a/tests/src/functions/comparison/MoreTests.cpp +++ b/tests/src/functions/comparison/MoreTests.cpp @@ -39,6 +39,10 @@ TEST(MoreTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(MoreTests, exprTest) { + EXPECT_EQ(moreExpr(Integer(10), Integer(10))->toString(), "10 > 10"); +} + TEST(MoreTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/comparison/NeqvTests.cpp b/tests/src/functions/comparison/NeqvTests.cpp index 7a3081c95..6cc021af6 100644 --- a/tests/src/functions/comparison/NeqvTests.cpp +++ b/tests/src/functions/comparison/NeqvTests.cpp @@ -39,6 +39,10 @@ TEST(NeqvTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(NeqvTests, exprTest) { + EXPECT_EQ(neqvExpr(Integer(10), Integer(10))->toString(), "10 != 10"); +} + TEST(NeqvTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/hyperbolic/AcoshTests.cpp b/tests/src/functions/hyperbolic/AcoshTests.cpp index 6355d4153..e4014ab36 100644 --- a/tests/src/functions/hyperbolic/AcoshTests.cpp +++ b/tests/src/functions/hyperbolic/AcoshTests.cpp @@ -42,6 +42,10 @@ TEST(AcoshTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(AcoshTests, exprTest) { + EXPECT_EQ(acoshExpr(Integer(10))->toString(), "acosh(10)"); +} + TEST(AcoshTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/hyperbolic/AcothTests.cpp b/tests/src/functions/hyperbolic/AcothTests.cpp index ce70eea69..1c4883c41 100644 --- a/tests/src/functions/hyperbolic/AcothTests.cpp +++ b/tests/src/functions/hyperbolic/AcothTests.cpp @@ -42,6 +42,10 @@ TEST(AcothTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(AcothTests, exprTest) { + EXPECT_EQ(acothExpr(Integer(10))->toString(), "acoth(10)"); +} + TEST(AcothTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/hyperbolic/AsinhTests.cpp b/tests/src/functions/hyperbolic/AsinhTests.cpp index a8b3db56f..44341c098 100644 --- a/tests/src/functions/hyperbolic/AsinhTests.cpp +++ b/tests/src/functions/hyperbolic/AsinhTests.cpp @@ -40,6 +40,10 @@ TEST(AsinhTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(AsinhTests, exprTest) { + EXPECT_EQ(asinhExpr(Integer(10))->toString(), "asinh(10)"); +} + TEST(AsinhTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/hyperbolic/AtanhTests.cpp b/tests/src/functions/hyperbolic/AtanhTests.cpp index bfbeae22c..c96a7f8e3 100644 --- a/tests/src/functions/hyperbolic/AtanhTests.cpp +++ b/tests/src/functions/hyperbolic/AtanhTests.cpp @@ -43,6 +43,10 @@ TEST(AtanhTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(AtanhTests, exprTest) { + EXPECT_EQ(atanhExpr(Integer(10))->toString(), "atanh(10)"); +} + TEST(AtanhTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/hyperbolic/CoshTests.cpp b/tests/src/functions/hyperbolic/CoshTests.cpp index 4761fe5a3..fa2ebb832 100644 --- a/tests/src/functions/hyperbolic/CoshTests.cpp +++ b/tests/src/functions/hyperbolic/CoshTests.cpp @@ -40,6 +40,10 @@ TEST(CoshTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(CoshTests, exprTest) { + EXPECT_EQ(coshExpr(Integer(10))->toString(), "cosh(10)"); +} + TEST(CoshTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/hyperbolic/CothTests.cpp b/tests/src/functions/hyperbolic/CothTests.cpp index f5487c921..27295ba7e 100644 --- a/tests/src/functions/hyperbolic/CothTests.cpp +++ b/tests/src/functions/hyperbolic/CothTests.cpp @@ -43,6 +43,10 @@ TEST(CothTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(CothTests, exprTest) { + EXPECT_EQ(cothExpr(Integer(10))->toString(), "coth(10)"); +} + TEST(CothTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/hyperbolic/SinhTests.cpp b/tests/src/functions/hyperbolic/SinhTests.cpp index c8391b1fc..30591dfa4 100644 --- a/tests/src/functions/hyperbolic/SinhTests.cpp +++ b/tests/src/functions/hyperbolic/SinhTests.cpp @@ -40,6 +40,10 @@ TEST(SinhTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(SinhTests, exprTest) { + EXPECT_EQ(sinhExpr(Integer(10))->toString(), "sinh(10)"); +} + TEST(SinhTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/hyperbolic/TanhTests.cpp b/tests/src/functions/hyperbolic/TanhTests.cpp index fec162557..43cdf266b 100644 --- a/tests/src/functions/hyperbolic/TanhTests.cpp +++ b/tests/src/functions/hyperbolic/TanhTests.cpp @@ -41,6 +41,10 @@ TEST(TanhTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(TanhTests, exprTest) { + EXPECT_EQ(tanhExpr(Integer(10))->toString(), "tanh(10)"); +} + TEST(TanhTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/logarithms/LbTests.cpp b/tests/src/functions/logarithms/LbTests.cpp index 0af320221..e624eedb1 100644 --- a/tests/src/functions/logarithms/LbTests.cpp +++ b/tests/src/functions/logarithms/LbTests.cpp @@ -37,6 +37,10 @@ TEST(LbTests, callTest) { EXPECT_THROW(f(Integer(10), Integer(10), Integer(10)), InvalidInputFunctionException); } +TEST(LbTests, exprTest) { + EXPECT_EQ(lbExpr(Integer(10))->toString(), "log(2, 10)"); +} + TEST(LbTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/logarithms/LgTests.cpp b/tests/src/functions/logarithms/LgTests.cpp index 6bf0006ac..31c8528fa 100644 --- a/tests/src/functions/logarithms/LgTests.cpp +++ b/tests/src/functions/logarithms/LgTests.cpp @@ -37,6 +37,10 @@ TEST(LgTests, callTest) { EXPECT_THROW(f(Integer(10), Integer(10), Integer(10)), InvalidInputFunctionException); } +TEST(LgTests, exprTest) { + EXPECT_EQ(lgExpr(Integer(10))->toString(), "log(10, 10)"); +} + TEST(LgTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/logarithms/LnTests.cpp b/tests/src/functions/logarithms/LnTests.cpp index ba81e859d..9b4e5564a 100644 --- a/tests/src/functions/logarithms/LnTests.cpp +++ b/tests/src/functions/logarithms/LnTests.cpp @@ -41,6 +41,10 @@ TEST(LnTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(LnTests, exprTest) { + EXPECT_EQ(lnExpr(Integer(10))->toString(), "ln(10)"); +} + TEST(LnTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/logarithms/LogTests.cpp b/tests/src/functions/logarithms/LogTests.cpp index e3ed4f48b..eb33133d5 100644 --- a/tests/src/functions/logarithms/LogTests.cpp +++ b/tests/src/functions/logarithms/LogTests.cpp @@ -76,6 +76,10 @@ TEST(LogTests, callTest) { EXPECT_THROW(f(Integer(10), Integer(10), Integer(10)), InvalidInputFunctionException); } +TEST(LogTests, exprTest) { + EXPECT_EQ(logExpr(Integer(10), Integer(10))->toString(), "log(10, 10)"); +} + TEST(LogTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/logic/AndTests.cpp b/tests/src/functions/logic/AndTests.cpp index 5afd53f39..6a2b5156e 100644 --- a/tests/src/functions/logic/AndTests.cpp +++ b/tests/src/functions/logic/AndTests.cpp @@ -36,6 +36,10 @@ TEST(AndTests, callTest) { EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); } +TEST(AndTests, exprTest) { + EXPECT_EQ(andExpr(Boolean(true), Boolean(false))->toString(), "True & False"); +} + TEST(AndTests, doArgsMatchTest) { Boolean a; diff --git a/tests/src/functions/logic/EquivTests.cpp b/tests/src/functions/logic/EquivTests.cpp index f2c0b0c6a..ba5fe44ec 100644 --- a/tests/src/functions/logic/EquivTests.cpp +++ b/tests/src/functions/logic/EquivTests.cpp @@ -36,6 +36,10 @@ TEST(EquivTests, callTest) { EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); } +TEST(EquivTests, exprTest) { + EXPECT_EQ(equivExpr(Boolean(true), Boolean(false))->toString(), "(True & False) | (~True & ~False)"); +} + TEST(EquivTests, doArgsMatchTest) { Boolean a; diff --git a/tests/src/functions/logic/ImplTests.cpp b/tests/src/functions/logic/ImplTests.cpp index c57e4ac9b..66408ffa7 100644 --- a/tests/src/functions/logic/ImplTests.cpp +++ b/tests/src/functions/logic/ImplTests.cpp @@ -36,6 +36,10 @@ TEST(ImplTests, callTest) { EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); } +TEST(ImplTests, exprTest) { + EXPECT_EQ(implExpr(Boolean(true), Boolean(false))->toString(), "~True | False"); +} + TEST(ImplTests, doArgsMatchTest) { Boolean a; diff --git a/tests/src/functions/logic/NequivTests.cpp b/tests/src/functions/logic/NequivTests.cpp index 1c1212f74..665e73607 100644 --- a/tests/src/functions/logic/NequivTests.cpp +++ b/tests/src/functions/logic/NequivTests.cpp @@ -36,6 +36,10 @@ TEST(NequivTests, callTest) { EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); } +TEST(NequivTests, exprTest) { + EXPECT_EQ(nequivExpr(Boolean(true), Boolean(false))->toString(), "(~True & False) | (True & ~False)"); +} + TEST(NequivTests, doArgsMatchTest) { Boolean a; diff --git a/tests/src/functions/logic/NotTests.cpp b/tests/src/functions/logic/NotTests.cpp index b6c712117..eb0409cf6 100644 --- a/tests/src/functions/logic/NotTests.cpp +++ b/tests/src/functions/logic/NotTests.cpp @@ -34,6 +34,10 @@ TEST(NotTests, callTest) { EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); } +TEST(NotTests, exprTest) { + EXPECT_EQ(notExpr(Boolean(true))->toString(), "~True"); +} + TEST(NotTests, doArgsMatchTest) { Boolean a; diff --git a/tests/src/functions/logic/OrTests.cpp b/tests/src/functions/logic/OrTests.cpp index c14270950..8d67ec781 100644 --- a/tests/src/functions/logic/OrTests.cpp +++ b/tests/src/functions/logic/OrTests.cpp @@ -36,6 +36,10 @@ TEST(OrTests, callTest) { EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); } +TEST(OrTests, exprTest) { + EXPECT_EQ(orExpr(Boolean(true), Boolean(false))->toString(), "True | False"); +} + TEST(OrTests, doArgsMatchTest) { Boolean a; diff --git a/tests/src/functions/other/DegTests.cpp b/tests/src/functions/other/DegTests.cpp index 0227c76e3..f7d414297 100644 --- a/tests/src/functions/other/DegTests.cpp +++ b/tests/src/functions/other/DegTests.cpp @@ -37,6 +37,10 @@ TEST(DegTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(DegTests, degTest) { + EXPECT_EQ(degExpr(Integer(10))->toString(), "10*1/180 Pi"); +} + TEST(DegTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/other/FactorialTests.cpp b/tests/src/functions/other/FactorialTests.cpp index 2ae8772ac..343a817d6 100644 --- a/tests/src/functions/other/FactorialTests.cpp +++ b/tests/src/functions/other/FactorialTests.cpp @@ -68,6 +68,10 @@ TEST(FactorialTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(FactorialTests, exprTest) { + EXPECT_EQ(factorialExpr(Integer(10))->toString(), "10!"); +} + TEST(FactorialTests, call2Test) { EXPECT_EQ(f2(Integer(0))->toString(), "1"); EXPECT_EQ(f2(Integer(1))->toString(), "1"); diff --git a/tests/src/functions/other/IndexTests.cpp b/tests/src/functions/other/IndexTests.cpp index 537aa6e70..87f26094c 100644 --- a/tests/src/functions/other/IndexTests.cpp +++ b/tests/src/functions/other/IndexTests.cpp @@ -40,6 +40,10 @@ TEST(IndexTests, callTest) { EXPECT_THROW(f(Expression("a"), Expression("a>1"))->toString(), InvalidInputException); } +TEST(IndexTests, exprTest) { + EXPECT_EQ(indexExpr(Variable("a"), Integer(1))->toString(), "a_1"); +} + TEST(IndexTests, doArgsMatchTest) { Variable a("a"); Integer b(1); diff --git a/tests/src/functions/other/PercentTests.cpp b/tests/src/functions/other/PercentTests.cpp index e04ca0fce..3058a65eb 100644 --- a/tests/src/functions/other/PercentTests.cpp +++ b/tests/src/functions/other/PercentTests.cpp @@ -36,6 +36,10 @@ TEST(PercentTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(PercentTests, degTest) { + EXPECT_EQ(percentExpr(Integer(10))->toString(), "10/100"); +} + TEST(PercentTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/powers/ExpTests.cpp b/tests/src/functions/powers/ExpTests.cpp index bdffb3467..4335a2b30 100644 --- a/tests/src/functions/powers/ExpTests.cpp +++ b/tests/src/functions/powers/ExpTests.cpp @@ -30,6 +30,10 @@ TEST(ExpTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(ExpTests, exprTest) { + EXPECT_EQ(expExpr(Integer(10))->toString(), "E^10"); +} + TEST(ExpTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/powers/PowTests.cpp b/tests/src/functions/powers/PowTests.cpp index f1174cfd4..581360845 100644 --- a/tests/src/functions/powers/PowTests.cpp +++ b/tests/src/functions/powers/PowTests.cpp @@ -91,6 +91,10 @@ TEST(PowTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(PowTests, exprTest) { + EXPECT_EQ(powExpr(Integer(10), Integer(10))->toString(), "10^10"); +} + TEST(PowTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/powers/RootTests.cpp b/tests/src/functions/powers/RootTests.cpp index d0f1857b1..ba4e8eea7 100644 --- a/tests/src/functions/powers/RootTests.cpp +++ b/tests/src/functions/powers/RootTests.cpp @@ -100,6 +100,10 @@ TEST(RootTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(RootTests, exprTest) { + EXPECT_EQ(rootExpr(Integer(10), Integer(10))->toString(), "root(10, 10)"); +} + TEST(RootTests, getTypeIdTest) { EXPECT_EQ(Root::getTypeIdStatic(), MathObjectTypeId(MathObjectType::Root)); EXPECT_EQ(Root().getTypeId(), MathObjectTypeId(MathObjectType::Root)); diff --git a/tests/src/functions/powers/SqrtTests.cpp b/tests/src/functions/powers/SqrtTests.cpp index b18697bcc..4a5a73c23 100644 --- a/tests/src/functions/powers/SqrtTests.cpp +++ b/tests/src/functions/powers/SqrtTests.cpp @@ -58,6 +58,10 @@ TEST(SqrtTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(SqrtTests, exprTest) { + EXPECT_EQ(sqrtExpr(Integer(10))->toString(), "sqrt(10)"); +} + TEST(SqrtTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/trigonometry/AcosTests.cpp b/tests/src/functions/trigonometry/AcosTests.cpp index aafe9cf4b..bc022badf 100644 --- a/tests/src/functions/trigonometry/AcosTests.cpp +++ b/tests/src/functions/trigonometry/AcosTests.cpp @@ -42,6 +42,10 @@ TEST(AcosTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(AcosTests, exprTest) { + EXPECT_EQ(acosExpr(Integer(10))->toString(), "acos(10)"); +} + TEST(AcosTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/trigonometry/AcotTests.cpp b/tests/src/functions/trigonometry/AcotTests.cpp index 0f4c2cb8d..d26906e77 100644 --- a/tests/src/functions/trigonometry/AcotTests.cpp +++ b/tests/src/functions/trigonometry/AcotTests.cpp @@ -44,6 +44,10 @@ TEST(AcotTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(AcotTests, exprTest) { + EXPECT_EQ(acotExpr(Integer(10))->toString(), "acot(10)"); +} + TEST(AcotTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/trigonometry/AsinTests.cpp b/tests/src/functions/trigonometry/AsinTests.cpp index 0581b27f5..8904d2a0a 100644 --- a/tests/src/functions/trigonometry/AsinTests.cpp +++ b/tests/src/functions/trigonometry/AsinTests.cpp @@ -42,6 +42,10 @@ TEST(AsinTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(AsinTests, exprTest) { + EXPECT_EQ(asinExpr(Integer(10))->toString(), "asin(10)"); +} + TEST(AsinTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/trigonometry/AtanTests.cpp b/tests/src/functions/trigonometry/AtanTests.cpp index 7648707e5..84be797f3 100644 --- a/tests/src/functions/trigonometry/AtanTests.cpp +++ b/tests/src/functions/trigonometry/AtanTests.cpp @@ -43,6 +43,10 @@ TEST(AtanTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(AtanTests, exprTest) { + EXPECT_EQ(atanExpr(Integer(10))->toString(), "atan(10)"); +} + TEST(AtanTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/trigonometry/CosTests.cpp b/tests/src/functions/trigonometry/CosTests.cpp index 9e353deff..21cce6537 100644 --- a/tests/src/functions/trigonometry/CosTests.cpp +++ b/tests/src/functions/trigonometry/CosTests.cpp @@ -43,6 +43,10 @@ TEST(CosTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(CosTests, exprTest) { + EXPECT_EQ(cosExpr(Integer(10))->toString(), "cos(10)"); +} + TEST(CosTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/trigonometry/CotTests.cpp b/tests/src/functions/trigonometry/CotTests.cpp index 626cb53e4..a16269f14 100644 --- a/tests/src/functions/trigonometry/CotTests.cpp +++ b/tests/src/functions/trigonometry/CotTests.cpp @@ -46,6 +46,10 @@ TEST(CotTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(CotTests, exprTest) { + EXPECT_EQ(cotExpr(Integer(10))->toString(), "cot(10)"); +} + TEST(CotTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/trigonometry/SinTests.cpp b/tests/src/functions/trigonometry/SinTests.cpp index 884cfc7bf..0fd29917a 100644 --- a/tests/src/functions/trigonometry/SinTests.cpp +++ b/tests/src/functions/trigonometry/SinTests.cpp @@ -43,6 +43,10 @@ TEST(SinTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(SinTests, exprTest) { + EXPECT_EQ(sinExpr(Integer(10))->toString(), "sin(10)"); +} + TEST(SinTests, doArgsMatchTest) { Integer a; diff --git a/tests/src/functions/trigonometry/TanTests.cpp b/tests/src/functions/trigonometry/TanTests.cpp index 891e9c156..53b08f37a 100644 --- a/tests/src/functions/trigonometry/TanTests.cpp +++ b/tests/src/functions/trigonometry/TanTests.cpp @@ -46,6 +46,10 @@ TEST(TanTests, callTest) { EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } +TEST(TanTests, exprTest) { + EXPECT_EQ(tanExpr(Integer(10))->toString(), "tan(10)"); +} + TEST(TanTests, doArgsMatchTest) { Integer a;