Skip to content

Commit

Permalink
Rename Indeterminate to Undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Jul 27, 2023
1 parent ab54acd commit 9799ae5
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion include/fintamath/core/MathObjectTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ enum class MathObjectType : MathObjectTypeId {
False,
Inf,
NegInf,
Indeterminate,
Undefined,

IFunction = 11000,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace fintamath {

class Indeterminate : public IConstantCRTP<IMathObject, Indeterminate> {
class Undefined : public IConstantCRTP<IMathObject, Undefined> {
public:
std::string toString() const override {
return "Indeterminate";
return "Undefined";
}

static MathObjectTypeId getTypeIdStatic() {
return MathObjectTypeId(MathObjectType::Indeterminate);
return MathObjectTypeId(MathObjectType::Undefined);
}

protected:
Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/config/ParserConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#include "fintamath/literals/constants/E.hpp"
#include "fintamath/literals/constants/False.hpp"
#include "fintamath/literals/constants/IConstant.hpp"
#include "fintamath/literals/constants/Indeterminate.hpp"
#include "fintamath/literals/constants/Undefined.hpp"
#include "fintamath/literals/constants/Inf.hpp"
#include "fintamath/literals/constants/NegInf.hpp"
#include "fintamath/literals/constants/Pi.hpp"
Expand Down Expand Up @@ -170,7 +170,7 @@ struct ParserConfig {
IConstant::registerType<False>();
IConstant::registerType<Inf>();
IConstant::registerType<NegInf>();
IConstant::registerType<Indeterminate>();
IConstant::registerType<Undefined>();

IFunction::registerType<Abs>();
IFunction::registerType<Log>();
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/expressions/IExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "fintamath/functions/other/Index.hpp"
#include "fintamath/literals/Variable.hpp"
#include "fintamath/literals/constants/IConstant.hpp"
#include "fintamath/literals/constants/Indeterminate.hpp"
#include "fintamath/literals/constants/Undefined.hpp"
#include "fintamath/numbers/INumber.hpp"
#include "fintamath/numbers/Real.hpp"

Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/expressions/binary/DivExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "fintamath/functions/arithmetic/Neg.hpp"
#include "fintamath/functions/arithmetic/Sub.hpp"
#include "fintamath/functions/powers/Pow.hpp"
#include "fintamath/literals/constants/Indeterminate.hpp"
#include "fintamath/literals/constants/Undefined.hpp"
#include "fintamath/literals/constants/Inf.hpp"
#include "fintamath/literals/constants/NegInf.hpp"
#include "fintamath/numbers/IntegerFunctions.hpp"
Expand Down Expand Up @@ -56,7 +56,7 @@ ArgumentPtr DivExpression::constSimplify(const IFunction & /*func*/, const Argum
if ((*lhs == Integer(0) || is<Inf>(lhs) || is<NegInf>(lhs)) &&
(*rhs == Integer(0) || is<Inf>(rhs) || is<NegInf>(rhs))) {

return Indeterminate().clone();
return Undefined().clone();
}

if (*lhs == Integer(0)) {
Expand Down
6 changes: 3 additions & 3 deletions src/fintamath/expressions/binary/PowExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "fintamath/functions/powers/Pow.hpp"
#include "fintamath/functions/powers/Root.hpp"
#include "fintamath/functions/powers/Sqrt.hpp"
#include "fintamath/literals/constants/Indeterminate.hpp"
#include "fintamath/literals/constants/Undefined.hpp"
#include "fintamath/literals/constants/Inf.hpp"
#include "fintamath/literals/constants/NegInf.hpp"
#include "fintamath/numbers/Integer.hpp"
Expand Down Expand Up @@ -228,7 +228,7 @@ ArgumentPtr PowExpression::constSimplify(const IFunction & /*func*/, const Argum

if (is<Inf>(lhs)) {
if (*rhs == Integer(0)) {
return Indeterminate().clone();
return Undefined().clone();
}

return lhs;
Expand All @@ -240,7 +240,7 @@ ArgumentPtr PowExpression::constSimplify(const IFunction & /*func*/, const Argum

if (*lhs == Integer(1)) {
if (is<Inf>(rhs)) {
return Indeterminate().clone();
return Undefined().clone();
}

return lhs;
Expand Down
10 changes: 5 additions & 5 deletions src/fintamath/expressions/interfaces/IBinaryExpression.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "fintamath/expressions/interfaces/IBinaryExpression.hpp"

#include "fintamath/expressions/ExpressionUtils.hpp"
#include "fintamath/literals/constants/Indeterminate.hpp"
#include "fintamath/literals/constants/Undefined.hpp"

namespace fintamath {

Expand All @@ -26,8 +26,8 @@ ArgumentPtr IBinaryExpression::preSimplify() const {
preSimplifyChild(simpl->lhsChild);
preSimplifyChild(simpl->rhsChild);

if (is<Indeterminate>(simpl->lhsChild) || is<Indeterminate>(simpl->rhsChild)) {
return Indeterminate().clone();
if (is<Undefined>(simpl->lhsChild) || is<Undefined>(simpl->rhsChild)) {
return Undefined().clone();
}

ArgumentPtr res = simpl->useSimplifyFunctions(getFunctionsForPreSimplify());
Expand All @@ -45,8 +45,8 @@ ArgumentPtr IBinaryExpression::postSimplify() const {
postSimplifyChild(simpl->lhsChild);
postSimplifyChild(simpl->rhsChild);

if (is<Indeterminate>(simpl->lhsChild) || is<Indeterminate>(simpl->rhsChild)) {
return Indeterminate().clone();
if (is<Undefined>(simpl->lhsChild) || is<Undefined>(simpl->rhsChild)) {
return Undefined().clone();
}

if (ArgumentPtr res = callFunction(*simpl->func, {simpl->lhsChild, simpl->rhsChild})) {
Expand Down
6 changes: 3 additions & 3 deletions src/fintamath/expressions/interfaces/IPolynomExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "fintamath/functions/IOperator.hpp"
#include "fintamath/literals/Variable.hpp"
#include "fintamath/literals/constants/IConstant.hpp"
#include "fintamath/literals/constants/Indeterminate.hpp"
#include "fintamath/literals/constants/Undefined.hpp"

namespace fintamath {

Expand Down Expand Up @@ -93,8 +93,8 @@ void IPolynomExpression::simplifyRec(bool isPostSimplify) {
const ArgumentPtr &lhs = children[i - 1];
const ArgumentPtr &rhs = children[i];

if (is<Indeterminate>(lhs) || is<Indeterminate>(rhs)) {
children = {Indeterminate().clone()};
if (is<Undefined>(lhs) || is<Undefined>(rhs)) {
children = {Undefined().clone()};
break;
}

Expand Down
10 changes: 5 additions & 5 deletions src/fintamath/expressions/interfaces/IUnaryExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "fintamath/core/IComparable.hpp"
#include "fintamath/expressions/ExpressionUtils.hpp"
#include "fintamath/literals/constants/Indeterminate.hpp"
#include "fintamath/literals/constants/Undefined.hpp"

namespace fintamath {

Expand Down Expand Up @@ -45,8 +45,8 @@ ArgumentPtr IUnaryExpression::preSimplify() const {
auto simpl = cast<IUnaryExpression>(clone());
preSimplifyChild(simpl->child);

if (is<Indeterminate>(simpl->child)) {
return Indeterminate().clone();
if (is<Undefined>(simpl->child)) {
return Undefined().clone();
}

ArgumentPtr res = simpl->useSimplifyFunctions(getFunctionsForPreSimplify());
Expand All @@ -63,8 +63,8 @@ ArgumentPtr IUnaryExpression::postSimplify() const {
auto simpl = cast<IUnaryExpression>(clone());
postSimplifyChild(simpl->child);

if (is<Indeterminate>(simpl->child)) {
return Indeterminate().clone();
if (is<Undefined>(simpl->child)) {
return Undefined().clone();
}

if (ArgumentPtr res = callFunction(*simpl->func, {simpl->child})) {
Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/expressions/polynomial/AddExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "fintamath/functions/powers/Pow.hpp"
#include "fintamath/literals/Variable.hpp"
#include "fintamath/literals/constants/IConstant.hpp"
#include "fintamath/literals/constants/Indeterminate.hpp"
#include "fintamath/literals/constants/Undefined.hpp"
#include "fintamath/literals/constants/Inf.hpp"
#include "fintamath/literals/constants/NegInf.hpp"
#include "fintamath/numbers/Rational.hpp"
Expand Down Expand Up @@ -105,7 +105,7 @@ ArgumentPtr AddExpression::simplifyConst(const IFunction & /*func*/, const Argum
}

if (is<NegInf>(lhsChild) && is<Inf>(rhsChild)) {
return Indeterminate().clone();
return Undefined().clone();
}

if (is<Inf>(lhsChild) || is<NegInf>(lhsChild)) {
Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/expressions/polynomial/MulExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "fintamath/functions/arithmetic/Neg.hpp"
#include "fintamath/functions/powers/Pow.hpp"
#include "fintamath/literals/constants/IConstant.hpp"
#include "fintamath/literals/constants/Indeterminate.hpp"
#include "fintamath/literals/constants/Undefined.hpp"
#include "fintamath/literals/constants/Inf.hpp"
#include "fintamath/literals/constants/NegInf.hpp"
#include "fintamath/numbers/Integer.hpp"
Expand Down Expand Up @@ -93,7 +93,7 @@ ArgumentPtr MulExpression::simplifyConst(const IFunction & /*func*/, const Argum
const ArgumentPtr &rhsChild) {

if (*lhsChild == Integer(0) && (is<Inf>(rhsChild) || is<NegInf>(rhsChild))) {
return Indeterminate().clone();
return Undefined().clone();
}

if (is<NegInf>(lhsChild) && is<Inf>(rhsChild)) {
Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/functions/arithmetic/Div.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "fintamath/numbers/INumber.hpp"

#include "fintamath/functions/arithmetic/Div.hpp"
#include "fintamath/literals/constants/Indeterminate.hpp"
#include "fintamath/literals/constants/Undefined.hpp"
#include "fintamath/numbers/Integer.hpp"
#include "fintamath/numbers/Rational.hpp"

Expand All @@ -23,7 +23,7 @@ std::unique_ptr<IMathObject> Div::call(const ArgumentsRefVector &argsVect) const
const auto &rhs = cast<IArithmetic>(argsVect.back().get());

if (lhs == Integer(0) && rhs == Integer(0)) {
return Indeterminate().clone();
return Undefined().clone();
}

if (rhs == Integer(0)) {
Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/functions/powers/Pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "fintamath/functions/powers/Root.hpp"
#include "fintamath/functions/powers/Sqrt.hpp"
#include "fintamath/literals/constants/Indeterminate.hpp"
#include "fintamath/literals/constants/Undefined.hpp"
#include "fintamath/numbers/Integer.hpp"
#include "fintamath/numbers/IntegerFunctions.hpp"
#include "fintamath/numbers/Rational.hpp"
Expand Down Expand Up @@ -34,7 +34,7 @@ std::unique_ptr<IMathObject> Pow::call(const ArgumentsRefVector &argsVect) const
const auto &rhs = cast<INumber>(argsVect.back().get());

if (lhs == Integer(0) && rhs == Integer(0)) {
return Indeterminate().clone();
return Undefined().clone();
}

if (rhs < Integer(0)) {
Expand Down
11 changes: 0 additions & 11 deletions src/fintamath/literals/constants/Indeterminate.cpp

This file was deleted.

11 changes: 11 additions & 0 deletions src/fintamath/literals/constants/Undefined.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "fintamath/literals/constants/Undefined.hpp"

#include "fintamath/numbers/RealFunctions.hpp"

namespace fintamath {

std::unique_ptr<IMathObject> Undefined::call() const {
return clone();
}

}
76 changes: 38 additions & 38 deletions tests/src/expressions/ExpressionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,44 +703,44 @@ TEST(ExpressionTests, stringConstructorTest) {
EXPECT_EQ(Expression("x = Inf").toString(), "x - Inf = 0");
EXPECT_EQ(Expression("x = -Inf").toString(), "x + Inf = 0");

EXPECT_EQ(Expression("0*Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("0*-Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("Inf - Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("0/0").toString(), "Indeterminate");
EXPECT_EQ(Expression("Inf/Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("0/Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("Inf/0").toString(), "Indeterminate");
EXPECT_EQ(Expression("-Inf/-Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("0/-Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("-Inf/0").toString(), "Indeterminate");
EXPECT_EQ(Expression("Inf/-Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("-Inf/Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("-Inf + Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("Inf - Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("0^0").toString(), "Indeterminate");
EXPECT_EQ(Expression("Inf^0").toString(), "Indeterminate");
EXPECT_EQ(Expression("1^Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("1^-Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("Inf = Inf").toString(), "Indeterminate");
EXPECT_EQ(Expression("Inf - Inf = 0").toString(), "Indeterminate");
EXPECT_EQ(Expression("Inf - Inf = 0 | a").toString(), "Indeterminate");
EXPECT_EQ(Expression("~Indeterminate").toString(), "Indeterminate");

EXPECT_EQ(Expression("Indeterminate").toString(), "Indeterminate");
EXPECT_EQ(Expression("-Indeterminate").toString(), "Indeterminate");
EXPECT_EQ(Expression("Indeterminate + 10").toString(), "Indeterminate");
EXPECT_EQ(Expression("Indeterminate - 10").toString(), "Indeterminate");
EXPECT_EQ(Expression("0/Indeterminate").toString(), "Indeterminate");
EXPECT_EQ(Expression("1/Indeterminate").toString(), "Indeterminate");
EXPECT_EQ(Expression("sin(Indeterminate)").toString(), "Indeterminate");
EXPECT_EQ(Expression("sin(0/0)").toString(), "Indeterminate");
EXPECT_EQ(Expression("1 + 0^0").toString(), "Indeterminate");
EXPECT_EQ(Expression("1 + sin(asin(0^0)) + x").toString(), "Indeterminate");
EXPECT_EQ(Expression("1 + (2^2 - 4)^0").toString(), "Indeterminate");
EXPECT_EQ(Expression("0^((2^2 - 4)^0)").toString(), "Indeterminate");
EXPECT_EQ(Expression("-((2^2 - 4)^0)").toString(), "Indeterminate");
EXPECT_EQ(Expression("Indeterminate = Indeterminate").toString(), "Indeterminate");
EXPECT_EQ(Expression("0/0 = 0/0").toString(), "Indeterminate");
EXPECT_EQ(Expression("0*Inf").toString(), "Undefined");
EXPECT_EQ(Expression("0*-Inf").toString(), "Undefined");
EXPECT_EQ(Expression("Inf - Inf").toString(), "Undefined");
EXPECT_EQ(Expression("0/0").toString(), "Undefined");
EXPECT_EQ(Expression("Inf/Inf").toString(), "Undefined");
EXPECT_EQ(Expression("0/Inf").toString(), "Undefined");
EXPECT_EQ(Expression("Inf/0").toString(), "Undefined");
EXPECT_EQ(Expression("-Inf/-Inf").toString(), "Undefined");
EXPECT_EQ(Expression("0/-Inf").toString(), "Undefined");
EXPECT_EQ(Expression("-Inf/0").toString(), "Undefined");
EXPECT_EQ(Expression("Inf/-Inf").toString(), "Undefined");
EXPECT_EQ(Expression("-Inf/Inf").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("Inf - Inf = 0").toString(), "Undefined");
EXPECT_EQ(Expression("Inf - Inf = 0 | a").toString(), "Undefined");
EXPECT_EQ(Expression("~Undefined").toString(), "Undefined");

EXPECT_EQ(Expression("Undefined").toString(), "Undefined");
EXPECT_EQ(Expression("-Undefined").toString(), "Undefined");
EXPECT_EQ(Expression("Undefined + 10").toString(), "Undefined");
EXPECT_EQ(Expression("Undefined - 10").toString(), "Undefined");
EXPECT_EQ(Expression("0/Undefined").toString(), "Undefined");
EXPECT_EQ(Expression("1/Undefined").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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/functions/arithmetic/DivTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST(DivTests, callTest) {

EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "3/a");

EXPECT_EQ(f(Integer(0), Integer(0))->toString(), "Indeterminate");
EXPECT_EQ(f(Integer(0), Integer(0))->toString(), "Undefined");

EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException);
EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/functions/powers/PowFTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TEST(PowFTests, callTest) {
EXPECT_EQ(f(Variable("a"), Rational(1, 2))->toString(), "sqrt(a)");
EXPECT_EQ(f(Variable("a"), Rational(3, 2))->toString(), "a^(3/2)");

EXPECT_EQ(f(Integer(0), Integer(0))->toString(), "Indeterminate");
EXPECT_EQ(f(Integer(0), Integer(0))->toString(), "Undefined");

EXPECT_THROW(f(Rational("0"), Rational("-10")), UndefinedException);
EXPECT_THROW(f(Rational("-10"), Rational("-1.5")), UndefinedException);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/functions/powers/PowTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ TEST(PowTests, callTest) {
EXPECT_EQ(f(Variable("a"), Rational(1, 2))->toString(), "sqrt(a)");
EXPECT_EQ(f(Variable("a"), Rational(3, 2))->toString(), "a^(3/2)");

EXPECT_EQ(f(Integer(0), Integer(0))->toString(), "Indeterminate");
EXPECT_EQ(f(Integer(0), Integer(0))->toString(), "Undefined");

EXPECT_THROW(f(Rational("0"), Rational("-10")), UndefinedException);
EXPECT_THROW(f(Rational("-10"), Rational("-1.5")), UndefinedException);
Expand Down
Loading

0 comments on commit 9799ae5

Please sign in to comment.