From 5fca39f4b6586848d08672d9149d601327b7bc92 Mon Sep 17 00:00:00 2001 From: fintarin Date: Fri, 28 Jul 2023 22:40:04 +0300 Subject: [PATCH] Implement ComplexInf --- include/fintamath/core/MathObjectTypes.hpp | 1 + .../literals/constants/ComplexInf.hpp | 22 +++++++ src/fintamath/config/ParserConfig.cpp | 2 + .../expressions/binary/CompExpression.cpp | 34 ++++++++++ .../expressions/binary/CompExpression.hpp | 4 ++ .../expressions/binary/DivExpression.cpp | 9 +-- .../expressions/binary/PowExpression.cpp | 22 +++++-- .../expressions/polynomial/AddExpression.cpp | 7 ++- .../expressions/polynomial/MulExpression.cpp | 9 ++- .../expressions/unary/NegExpression.cpp | 5 ++ src/fintamath/functions/arithmetic/Div.cpp | 8 +-- .../literals/constants/ComplexInf.cpp | 11 ++++ tests/src/expressions/ExpressionTests.cpp | 63 +++++++++++++++---- tests/src/functions/arithmetic/DivTests.cpp | 1 + tests/src/parser/ParserTests.cpp | 2 + 15 files changed, 172 insertions(+), 28 deletions(-) create mode 100644 include/fintamath/literals/constants/ComplexInf.hpp create mode 100644 src/fintamath/literals/constants/ComplexInf.cpp diff --git a/include/fintamath/core/MathObjectTypes.hpp b/include/fintamath/core/MathObjectTypes.hpp index c5766e35e..947445a37 100644 --- a/include/fintamath/core/MathObjectTypes.hpp +++ b/include/fintamath/core/MathObjectTypes.hpp @@ -66,6 +66,7 @@ enum class MathObjectType : MathObjectTypeId { False, Inf, NegInf, + ComplexInf, Undefined, IFunction = 11000, diff --git a/include/fintamath/literals/constants/ComplexInf.hpp b/include/fintamath/literals/constants/ComplexInf.hpp new file mode 100644 index 000000000..74d6b82c5 --- /dev/null +++ b/include/fintamath/literals/constants/ComplexInf.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "fintamath/literals/constants/IConstant.hpp" +#include "fintamath/numbers/INumber.hpp" + +namespace fintamath { + +class ComplexInf : public IConstantCRTP { +public: + std::string toString() const override { + return "ComplexInf"; + } + + static MathObjectTypeId getTypeIdStatic() { + return MathObjectTypeId(MathObjectType::ComplexInf); + } + +protected: + std::unique_ptr call() const override; +}; + +} diff --git a/src/fintamath/config/ParserConfig.cpp b/src/fintamath/config/ParserConfig.cpp index a56dec734..927b76a12 100644 --- a/src/fintamath/config/ParserConfig.cpp +++ b/src/fintamath/config/ParserConfig.cpp @@ -62,6 +62,7 @@ #include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/ILiteral.hpp" #include "fintamath/literals/Variable.hpp" +#include "fintamath/literals/constants/ComplexInf.hpp" #include "fintamath/literals/constants/E.hpp" #include "fintamath/literals/constants/False.hpp" #include "fintamath/literals/constants/IConstant.hpp" @@ -170,6 +171,7 @@ struct ParserConfig { IConstant::registerType(); IConstant::registerType(); IConstant::registerType(); + IConstant::registerType(); IConstant::registerType(); IFunction::registerType(); diff --git a/src/fintamath/expressions/binary/CompExpression.cpp b/src/fintamath/expressions/binary/CompExpression.cpp index 575f4ca8b..06778c81e 100644 --- a/src/fintamath/expressions/binary/CompExpression.cpp +++ b/src/fintamath/expressions/binary/CompExpression.cpp @@ -13,6 +13,10 @@ #include "fintamath/functions/comparison/MoreEqv.hpp" #include "fintamath/functions/comparison/Neqv.hpp" #include "fintamath/literals/Variable.hpp" +#include "fintamath/literals/constants/ComplexInf.hpp" +#include "fintamath/literals/constants/Inf.hpp" +#include "fintamath/literals/constants/NegInf.hpp" +#include "fintamath/literals/constants/Undefined.hpp" #include "fintamath/numbers/Integer.hpp" namespace fintamath { @@ -58,8 +62,16 @@ ArgumentPtr CompExpression::preSimplify() const { return simpl; } +CompExpression::SimplifyFunctionsVector CompExpression::getFunctionsForPreSimplify() const { + static const CompExpression::SimplifyFunctionsVector simplifyFunctions = { + &CompExpression::constSimplify, // + }; + return simplifyFunctions; +} + CompExpression::SimplifyFunctionsVector CompExpression::getFunctionsForPostSimplify() const { static const CompExpression::SimplifyFunctionsVector simplifyFunctions = { + &CompExpression::constSimplify, // &CompExpression::divSimplify, // &CompExpression::coeffSimplify, // }; @@ -82,6 +94,28 @@ std::shared_ptr CompExpression::getOppositeFunction(const IFunction & return oppositeFunctions.at(function.toString()); } +ArgumentPtr CompExpression::constSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { + if (is(lhs) && (is(rhs) || is(rhs) || is(rhs))) { + return Undefined().clone(); + } + + if ((is(lhs) || is(lhs) || is(lhs)) && is(rhs)) { + return Undefined().clone(); + } + + if ((is(lhs) && is(rhs)) || (is(lhs) && is(rhs))) { + return Boolean(true).clone(); + } + + if (is(lhs) || is(lhs) || is(lhs) || // + is(rhs) || is(rhs) || is(rhs)) { + + return Boolean(false).clone(); + } + + return {}; +} + ArgumentPtr CompExpression::divSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { if (const auto lhsExpr = cast(lhs); lhsExpr && is
(lhsExpr->getFunction())) { return makeExpr(func, lhsExpr->getChildren().front(), rhs); diff --git a/src/fintamath/expressions/binary/CompExpression.hpp b/src/fintamath/expressions/binary/CompExpression.hpp index c9a069f18..df2cce21b 100644 --- a/src/fintamath/expressions/binary/CompExpression.hpp +++ b/src/fintamath/expressions/binary/CompExpression.hpp @@ -19,6 +19,8 @@ class CompExpression : public IBinaryExpressionCRTP { protected: ArgumentPtr preSimplify() const override; + SimplifyFunctionsVector getFunctionsForPreSimplify() const override; + SimplifyFunctionsVector getFunctionsForPostSimplify() const override; static std::map, std::less<>> &getOppositeFunctionsMap(); @@ -30,6 +32,8 @@ class CompExpression : public IBinaryExpressionCRTP { static std::shared_ptr getLogicOppositeFunction(const IFunction &function); private: + static ArgumentPtr constSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); + static ArgumentPtr divSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); static ArgumentPtr coeffSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); diff --git a/src/fintamath/expressions/binary/DivExpression.cpp b/src/fintamath/expressions/binary/DivExpression.cpp index 39bdab49f..e5d115ab6 100644 --- a/src/fintamath/expressions/binary/DivExpression.cpp +++ b/src/fintamath/expressions/binary/DivExpression.cpp @@ -8,6 +8,7 @@ #include "fintamath/functions/arithmetic/Neg.hpp" #include "fintamath/functions/arithmetic/Sub.hpp" #include "fintamath/functions/powers/Pow.hpp" +#include "fintamath/literals/constants/ComplexInf.hpp" #include "fintamath/literals/constants/Inf.hpp" #include "fintamath/literals/constants/NegInf.hpp" #include "fintamath/literals/constants/Undefined.hpp" @@ -53,8 +54,8 @@ DivExpression::SimplifyFunctionsVector DivExpression::getFunctionsForPostSimplif } ArgumentPtr DivExpression::constSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if ((*lhs == Integer(0) || is(lhs) || is(lhs)) && - (*rhs == Integer(0) || is(rhs) || is(rhs))) { + if ((*lhs == Integer(0) || is(lhs) || is(lhs) || is(lhs)) && + (*rhs == Integer(0) || is(rhs) || is(rhs) || is(rhs))) { return Undefined().clone(); } @@ -64,10 +65,10 @@ ArgumentPtr DivExpression::constSimplify(const IFunction & /*func*/, const Argum } if (*rhs == Integer(0)) { - return Inf().clone(); + return ComplexInf().clone(); } - if (is(rhs) || is(rhs)) { + if (is(rhs) || is(rhs) || is(rhs)) { return Integer(0).clone(); } diff --git a/src/fintamath/expressions/binary/PowExpression.cpp b/src/fintamath/expressions/binary/PowExpression.cpp index 06d080f87..dbaf54c25 100644 --- a/src/fintamath/expressions/binary/PowExpression.cpp +++ b/src/fintamath/expressions/binary/PowExpression.cpp @@ -2,6 +2,7 @@ #include "fintamath/exceptions/UndefinedException.hpp" #include "fintamath/expressions/ExpressionUtils.hpp" +#include "fintamath/functions/arithmetic/Abs.hpp" #include "fintamath/functions/arithmetic/Add.hpp" #include "fintamath/functions/arithmetic/Div.hpp" #include "fintamath/functions/arithmetic/Mul.hpp" @@ -9,6 +10,7 @@ #include "fintamath/functions/powers/Pow.hpp" #include "fintamath/functions/powers/Root.hpp" #include "fintamath/functions/powers/Sqrt.hpp" +#include "fintamath/literals/constants/ComplexInf.hpp" #include "fintamath/literals/constants/Inf.hpp" #include "fintamath/literals/constants/NegInf.hpp" #include "fintamath/literals/constants/Undefined.hpp" @@ -226,7 +228,7 @@ ArgumentPtr PowExpression::constSimplify(const IFunction & /*func*/, const Argum return makeExpr(Mul(), mulLhs, mulRhs); } - if (is(lhs)) { + if (is(lhs) || is(lhs)) { if (*rhs == Integer(0)) { return Undefined().clone(); } @@ -238,11 +240,23 @@ ArgumentPtr PowExpression::constSimplify(const IFunction & /*func*/, const Argum return lhs; } - if (*lhs == Integer(1)) { - if (is(rhs)) { - return Undefined().clone(); + if (is(rhs) || is(rhs)) { + if (const auto lhsNum = cast(lhs)) { + auto lhsNumAbs = cast(Abs()(*lhsNum)); + + if (*lhsNumAbs == Integer(1)) { + return Undefined().clone(); + } + + if (*lhsNumAbs > Integer(1)) { + return ComplexInf().clone(); + } + + return Integer(0).clone(); } + } + if (*lhs == Integer(1)) { return lhs; } diff --git a/src/fintamath/expressions/polynomial/AddExpression.cpp b/src/fintamath/expressions/polynomial/AddExpression.cpp index 154ece391..5b259f09c 100644 --- a/src/fintamath/expressions/polynomial/AddExpression.cpp +++ b/src/fintamath/expressions/polynomial/AddExpression.cpp @@ -9,6 +9,7 @@ #include "fintamath/functions/logarithms/Log.hpp" #include "fintamath/functions/powers/Pow.hpp" #include "fintamath/literals/Variable.hpp" +#include "fintamath/literals/constants/ComplexInf.hpp" #include "fintamath/literals/constants/IConstant.hpp" #include "fintamath/literals/constants/Inf.hpp" #include "fintamath/literals/constants/NegInf.hpp" @@ -104,7 +105,7 @@ ArgumentPtr AddExpression::simplifyConst(const IFunction & /*func*/, const Argum return lhsChild; } - if (is(lhsChild) && is(rhsChild)) { + if ((is(lhsChild) || is(lhsChild)) && (is(rhsChild) || is(rhsChild))) { return Undefined().clone(); } @@ -112,6 +113,10 @@ ArgumentPtr AddExpression::simplifyConst(const IFunction & /*func*/, const Argum return lhsChild; } + if (is(rhsChild) || is(rhsChild)) { + return rhsChild; + } + return {}; } diff --git a/src/fintamath/expressions/polynomial/MulExpression.cpp b/src/fintamath/expressions/polynomial/MulExpression.cpp index 971384119..f2e5693e8 100644 --- a/src/fintamath/expressions/polynomial/MulExpression.cpp +++ b/src/fintamath/expressions/polynomial/MulExpression.cpp @@ -9,6 +9,7 @@ #include "fintamath/functions/arithmetic/Mul.hpp" #include "fintamath/functions/arithmetic/Neg.hpp" #include "fintamath/functions/powers/Pow.hpp" +#include "fintamath/literals/constants/ComplexInf.hpp" #include "fintamath/literals/constants/IConstant.hpp" #include "fintamath/literals/constants/Inf.hpp" #include "fintamath/literals/constants/NegInf.hpp" @@ -92,15 +93,19 @@ std::pair MulExpression::getRateValuePair(const Argume ArgumentPtr MulExpression::simplifyConst(const IFunction & /*func*/, const ArgumentPtr &lhsChild, const ArgumentPtr &rhsChild) { - if (*lhsChild == Integer(0) && (is(rhsChild) || is(rhsChild))) { + if (*lhsChild == Integer(0) && (is(rhsChild) || is(rhsChild) || is(rhsChild))) { return Undefined().clone(); } + if (is(lhsChild) || is(rhsChild)) { + return ComplexInf().clone(); + } + if (is(lhsChild) && is(rhsChild)) { return lhsChild; } - if (is(rhsChild) || is(rhsChild)) { + if (is(rhsChild) || is(rhsChild) || is(rhsChild)) { if (const auto lhsNum = cast(lhsChild)) { return *lhsNum < Integer(0) ? makeExpr(Neg(), rhsChild) : rhsChild; } diff --git a/src/fintamath/expressions/unary/NegExpression.cpp b/src/fintamath/expressions/unary/NegExpression.cpp index 3e7fe712f..448c6e5e9 100644 --- a/src/fintamath/expressions/unary/NegExpression.cpp +++ b/src/fintamath/expressions/unary/NegExpression.cpp @@ -6,6 +6,7 @@ #include "fintamath/functions/arithmetic/Mul.hpp" #include "fintamath/functions/arithmetic/Neg.hpp" #include "fintamath/functions/logarithms/Log.hpp" +#include "fintamath/literals/constants/ComplexInf.hpp" #include "fintamath/literals/constants/Inf.hpp" #include "fintamath/literals/constants/NegInf.hpp" @@ -92,6 +93,10 @@ ArgumentPtr NegExpression::simplifyConst(const IFunction & /*func*/, const Argum return Inf().clone(); } + if (is(rhs)) { + return rhs; + } + return {}; } diff --git a/src/fintamath/functions/arithmetic/Div.cpp b/src/fintamath/functions/arithmetic/Div.cpp index d91457692..61494b050 100644 --- a/src/fintamath/functions/arithmetic/Div.cpp +++ b/src/fintamath/functions/arithmetic/Div.cpp @@ -1,8 +1,8 @@ -#include "fintamath/literals/constants/Inf.hpp" -#include "fintamath/numbers/INumber.hpp" - #include "fintamath/functions/arithmetic/Div.hpp" + +#include "fintamath/literals/constants/ComplexInf.hpp" #include "fintamath/literals/constants/Undefined.hpp" +#include "fintamath/numbers/INumber.hpp" #include "fintamath/numbers/Integer.hpp" #include "fintamath/numbers/Rational.hpp" @@ -27,7 +27,7 @@ std::unique_ptr Div::call(const ArgumentsRefVector &argsVect) const } if (rhs == Integer(0)) { - return Inf().clone(); + return ComplexInf().clone(); } if (auto res = multiPow(lhs, rhs)) { diff --git a/src/fintamath/literals/constants/ComplexInf.cpp b/src/fintamath/literals/constants/ComplexInf.cpp new file mode 100644 index 000000000..6ccc28469 --- /dev/null +++ b/src/fintamath/literals/constants/ComplexInf.cpp @@ -0,0 +1,11 @@ +#include "fintamath/literals/constants/ComplexInf.hpp" + +#include "fintamath/numbers/RealFunctions.hpp" + +namespace fintamath { + +std::unique_ptr ComplexInf::call() const { + return clone(); +} + +} diff --git a/tests/src/expressions/ExpressionTests.cpp b/tests/src/expressions/ExpressionTests.cpp index f6b1bb301..430045d3e 100644 --- a/tests/src/expressions/ExpressionTests.cpp +++ b/tests/src/expressions/ExpressionTests.cpp @@ -672,40 +672,63 @@ TEST(ExpressionTests, stringConstructorTest) { EXPECT_EQ(Expression("Inf").toString(), "Inf"); EXPECT_EQ(Expression("-Inf").toString(), "-Inf"); - EXPECT_EQ(Expression("1/0").toString(), "Inf"); - EXPECT_EQ(Expression("a/0").toString(), "Inf"); + EXPECT_EQ(Expression("ComplexInf").toString(), "ComplexInf"); + EXPECT_EQ(Expression("-ComplexInf").toString(), "ComplexInf"); + EXPECT_EQ(Expression("1/0").toString(), "ComplexInf"); + EXPECT_EQ(Expression("a/0").toString(), "ComplexInf"); EXPECT_EQ(Expression("1/Inf").toString(), "0"); EXPECT_EQ(Expression("1/-Inf").toString(), "0"); EXPECT_EQ(Expression("a/Inf").toString(), "0"); EXPECT_EQ(Expression("a/-Inf").toString(), "0"); + EXPECT_EQ(Expression("1/ComplexInf").toString(), "0"); + EXPECT_EQ(Expression("a/ComplexInf").toString(), "0"); EXPECT_EQ(Expression("Inf + Inf").toString(), "Inf"); EXPECT_EQ(Expression("-Inf - Inf").toString(), "-Inf"); EXPECT_EQ(Expression("10 + Inf").toString(), "Inf"); EXPECT_EQ(Expression("-10 + Inf").toString(), "Inf"); EXPECT_EQ(Expression("10 - Inf").toString(), "-Inf"); EXPECT_EQ(Expression("-10 - Inf").toString(), "-Inf"); + EXPECT_EQ(Expression("a + Inf").toString(), "Inf"); + EXPECT_EQ(Expression("-a - Inf").toString(), "-Inf"); EXPECT_EQ(Expression("10 * Inf").toString(), "Inf"); EXPECT_EQ(Expression("-10 * Inf").toString(), "-Inf"); EXPECT_EQ(Expression("-2/3 * Inf").toString(), "-Inf"); + EXPECT_EQ(Expression("a * Inf").toString(), "Inf a"); EXPECT_EQ(Expression("Inf * Inf").toString(), "Inf"); EXPECT_EQ(Expression("Inf * -Inf").toString(), "-Inf"); EXPECT_EQ(Expression("-Inf * -Inf").toString(), "Inf"); + EXPECT_EQ(Expression("ComplexInf*ComplexInf").toString(), "ComplexInf"); + EXPECT_EQ(Expression("ComplexInf*Inf").toString(), "ComplexInf"); + EXPECT_EQ(Expression("ComplexInf*-Inf").toString(), "ComplexInf"); EXPECT_EQ(Expression("Inf^2").toString(), "Inf"); EXPECT_EQ(Expression("Inf^(2/3)").toString(), "Inf"); EXPECT_EQ(Expression("(-Inf)^2").toString(), "Inf"); EXPECT_EQ(Expression("(-Inf)^3").toString(), "-Inf"); // EXPECT_EQ(Expression("(-Inf)^(2/3)").toString(), "-Inf"); // TODO! complex numbers EXPECT_EQ(Expression("0^Inf").toString(), "0"); - EXPECT_EQ(Expression("0^-Inf").toString(), "Inf"); + EXPECT_EQ(Expression("0^-Inf").toString(), "ComplexInf"); + EXPECT_EQ(Expression("2^Inf").toString(), "ComplexInf"); + EXPECT_EQ(Expression("2^-Inf").toString(), "0"); + EXPECT_EQ(Expression("2^ComplexInf").toString(), "ComplexInf"); + EXPECT_EQ(Expression("0.2^Inf").toString(), "0"); + EXPECT_EQ(Expression("0.2^-Inf").toString(), "ComplexInf"); + EXPECT_EQ(Expression("0.2^ComplexInf").toString(), "0"); EXPECT_EQ(Expression("sqrt(2) * Inf").toString(), "Inf sqrt(2)"); // TODO! Inf EXPECT_EQ(Expression("-sqrt(2) * Inf").toString(), "-Inf sqrt(2)"); // TODO! -Inf EXPECT_EQ(Expression("sin(Inf)").toString(), "sin(Inf)"); // TODO: [-1, 1] - EXPECT_EQ(Expression("x = Inf").toString(), "x - Inf = 0"); - EXPECT_EQ(Expression("x = -Inf").toString(), "x + Inf = 0"); + EXPECT_EQ(Expression("x = Inf").toString(), "False"); + EXPECT_EQ(Expression("x = -Inf").toString(), "False"); + EXPECT_EQ(Expression("Inf = Inf").toString(), "True"); + EXPECT_EQ(Expression("Inf = -Inf").toString(), "False"); EXPECT_EQ(Expression("0*Inf").toString(), "Undefined"); EXPECT_EQ(Expression("0*-Inf").toString(), "Undefined"); + EXPECT_EQ(Expression("0*ComplexInf").toString(), "Undefined"); EXPECT_EQ(Expression("Inf - Inf").toString(), "Undefined"); + EXPECT_EQ(Expression("ComplexInf - ComplexInf").toString(), "Undefined"); + EXPECT_EQ(Expression("ComplexInf + ComplexInf").toString(), "Undefined"); + EXPECT_EQ(Expression("ComplexInf + Inf").toString(), "Undefined"); + EXPECT_EQ(Expression("ComplexInf - Inf").toString(), "Undefined"); EXPECT_EQ(Expression("0/0").toString(), "Undefined"); EXPECT_EQ(Expression("Inf/Inf").toString(), "Undefined"); EXPECT_EQ(Expression("0/Inf").toString(), "Undefined"); @@ -715,15 +738,34 @@ TEST(ExpressionTests, stringConstructorTest) { EXPECT_EQ(Expression("-Inf/0").toString(), "Undefined"); EXPECT_EQ(Expression("Inf/-Inf").toString(), "Undefined"); EXPECT_EQ(Expression("-Inf/Inf").toString(), "Undefined"); + EXPECT_EQ(Expression("ComplexInf/ComplexInf").toString(), "Undefined"); + EXPECT_EQ(Expression("0/ComplexInf").toString(), "Undefined"); + EXPECT_EQ(Expression("ComplexInf/0").toString(), "Undefined"); + EXPECT_EQ(Expression("ComplexInf/Inf").toString(), "Undefined"); + EXPECT_EQ(Expression("ComplexInf/-Inf").toString(), "Undefined"); + EXPECT_EQ(Expression("Inf/ComplexInf").toString(), "Undefined"); + EXPECT_EQ(Expression("-Inf/ComplexInf").toString(), "Undefined"); EXPECT_EQ(Expression("-Inf + Inf").toString(), "Undefined"); EXPECT_EQ(Expression("Inf - Inf").toString(), "Undefined"); EXPECT_EQ(Expression("0^0").toString(), "Undefined"); EXPECT_EQ(Expression("Inf^0").toString(), "Undefined"); EXPECT_EQ(Expression("1^Inf").toString(), "Undefined"); EXPECT_EQ(Expression("1^-Inf").toString(), "Undefined"); - EXPECT_EQ(Expression("Inf = Inf").toString(), "Undefined"); + EXPECT_EQ(Expression("1^ComplexInf").toString(), "Undefined"); EXPECT_EQ(Expression("Inf - Inf = 0").toString(), "Undefined"); EXPECT_EQ(Expression("Inf - Inf = 0 | a").toString(), "Undefined"); + EXPECT_EQ(Expression("0/0 = 0/0").toString(), "Undefined"); + EXPECT_EQ(Expression("sin(0/0)").toString(), "Undefined"); + EXPECT_EQ(Expression("1 + 0^0").toString(), "Undefined"); + EXPECT_EQ(Expression("1 + sin(asin(0^0)) + x").toString(), "Undefined"); + EXPECT_EQ(Expression("1 + (2^2 - 4)^0").toString(), "Undefined"); + EXPECT_EQ(Expression("0^((2^2 - 4)^0)").toString(), "Undefined"); + EXPECT_EQ(Expression("-((2^2 - 4)^0)").toString(), "Undefined"); + EXPECT_EQ(Expression("ComplexInf = ComplexInf").toString(), "Undefined"); + EXPECT_EQ(Expression("ComplexInf = Inf").toString(), "Undefined"); + EXPECT_EQ(Expression("ComplexInf = -Inf").toString(), "Undefined"); + EXPECT_EQ(Expression("Inf = ComplexInf").toString(), "Undefined"); + EXPECT_EQ(Expression("-Inf = ComplexInf").toString(), "Undefined"); EXPECT_EQ(Expression("Undefined").toString(), "Undefined"); EXPECT_EQ(Expression("-Undefined").toString(), "Undefined"); @@ -731,15 +773,10 @@ TEST(ExpressionTests, stringConstructorTest) { EXPECT_EQ(Expression("Undefined - 10").toString(), "Undefined"); EXPECT_EQ(Expression("0/Undefined").toString(), "Undefined"); EXPECT_EQ(Expression("1/Undefined").toString(), "Undefined"); + EXPECT_EQ(Expression("Undefined^1").toString(), "Undefined"); + EXPECT_EQ(Expression("Undefined^0").toString(), "Undefined"); EXPECT_EQ(Expression("sin(Undefined)").toString(), "Undefined"); - EXPECT_EQ(Expression("sin(0/0)").toString(), "Undefined"); - EXPECT_EQ(Expression("1 + 0^0").toString(), "Undefined"); - EXPECT_EQ(Expression("1 + sin(asin(0^0)) + x").toString(), "Undefined"); - EXPECT_EQ(Expression("1 + (2^2 - 4)^0").toString(), "Undefined"); - EXPECT_EQ(Expression("0^((2^2 - 4)^0)").toString(), "Undefined"); - EXPECT_EQ(Expression("-((2^2 - 4)^0)").toString(), "Undefined"); EXPECT_EQ(Expression("Undefined = Undefined").toString(), "Undefined"); - EXPECT_EQ(Expression("0/0 = 0/0").toString(), "Undefined"); } TEST(ExpressionTests, stringConstructorLargeTest) { diff --git a/tests/src/functions/arithmetic/DivTests.cpp b/tests/src/functions/arithmetic/DivTests.cpp index 435682c86..5f3e24086 100644 --- a/tests/src/functions/arithmetic/DivTests.cpp +++ b/tests/src/functions/arithmetic/DivTests.cpp @@ -33,6 +33,7 @@ TEST(DivTests, callTest) { EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "3/a"); + EXPECT_EQ(f(Integer(1), Integer(0))->toString(), "ComplexInf"); EXPECT_EQ(f(Integer(0), Integer(0))->toString(), "Undefined"); EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); diff --git a/tests/src/parser/ParserTests.cpp b/tests/src/parser/ParserTests.cpp index 4493e41db..2c342b121 100644 --- a/tests/src/parser/ParserTests.cpp +++ b/tests/src/parser/ParserTests.cpp @@ -59,6 +59,7 @@ #include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/ILiteral.hpp" #include "fintamath/literals/Variable.hpp" +#include "fintamath/literals/constants/ComplexInf.hpp" #include "fintamath/literals/constants/E.hpp" #include "fintamath/literals/constants/False.hpp" #include "fintamath/literals/constants/IConstant.hpp" @@ -183,6 +184,7 @@ TEST(ParseTests, parseConstantTest) { EXPECT_TRUE(is(IConstant::parse("False"))); EXPECT_TRUE(is(IConstant::parse("Inf"))); EXPECT_TRUE(is(IConstant::parse("-Inf"))); + EXPECT_TRUE(is(IConstant::parse("ComplexInf"))); EXPECT_TRUE(is(IConstant::parse("Undefined"))); EXPECT_EQ(IConstant::parse("a"), nullptr);