Skip to content

Commit

Permalink
Add hyperbolic functions & some constants to ExpressionFunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Sep 27, 2023
1 parent edcbc05 commit 98df4f0
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 10 deletions.
26 changes: 24 additions & 2 deletions include/fintamath/expressions/ExpressionFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,38 @@ Expression atan(const Expression &rhs);

Expression acot(const Expression &rhs);

Expression e();
Expression sinh(const Expression &rhs);

Expression pi();
Expression cosh(const Expression &rhs);

Expression tanh(const Expression &rhs);

Expression coth(const Expression &rhs);

Expression asinh(const Expression &rhs);

Expression acosh(const Expression &rhs);

Expression atanh(const Expression &rhs);

Expression acoth(const Expression &rhs);

Expression notL(const Expression &rhs);

Expression andL(const Expression &lhs, const Expression &rhs);

Expression orL(const Expression &lhs, const Expression &rhs);

Expression e();

Expression pi();

Expression inf();

Expression negInf();

Expression complexInf();

Expression solve(const Expression &rhs);

}
63 changes: 59 additions & 4 deletions src/fintamath/expressions/ExpressionFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
#include "fintamath/functions/comparison/More.hpp"
#include "fintamath/functions/comparison/MoreEqv.hpp"
#include "fintamath/functions/comparison/Neqv.hpp"
#include "fintamath/functions/hyperbolic/Acosh.hpp"
#include "fintamath/functions/hyperbolic/Acoth.hpp"
#include "fintamath/functions/hyperbolic/Asinh.hpp"
#include "fintamath/functions/hyperbolic/Atanh.hpp"
#include "fintamath/functions/hyperbolic/Cosh.hpp"
#include "fintamath/functions/hyperbolic/Coth.hpp"
#include "fintamath/functions/hyperbolic/Sinh.hpp"
#include "fintamath/functions/hyperbolic/Tanh.hpp"
#include "fintamath/functions/logarithms/Lb.hpp"
#include "fintamath/functions/logarithms/Lg.hpp"
#include "fintamath/functions/logarithms/Ln.hpp"
Expand All @@ -29,7 +37,10 @@
#include "fintamath/functions/trigonometry/Sin.hpp"
#include "fintamath/functions/trigonometry/Tan.hpp"
#include "fintamath/literals/Boolean.hpp"
#include "fintamath/literals/constants/ComplexInf.hpp"
#include "fintamath/literals/constants/E.hpp"
#include "fintamath/literals/constants/Inf.hpp"
#include "fintamath/literals/constants/NegInf.hpp"
#include "fintamath/literals/constants/Pi.hpp"

namespace fintamath {
Expand Down Expand Up @@ -138,12 +149,36 @@ Expression acot(const Expression &rhs) {
return Expression(acotExpr(rhs));
}

Expression e() {
return E();
Expression sinh(const Expression &rhs) {
return Expression(sinhExpr(rhs));
}

Expression pi() {
return Pi();
Expression cosh(const Expression &rhs) {
return Expression(coshExpr(rhs));
}

Expression tanh(const Expression &rhs) {
return Expression(tanhExpr(rhs));
}

Expression coth(const Expression &rhs) {
return Expression(cothExpr(rhs));
}

Expression asinh(const Expression &rhs) {
return Expression(asinhExpr(rhs));
}

Expression acosh(const Expression &rhs) {
return Expression(acoshExpr(rhs));
}

Expression atanh(const Expression &rhs) {
return Expression(atanhExpr(rhs));
}

Expression acoth(const Expression &rhs) {
return Expression(acothExpr(rhs));
}

Expression notL(const Expression &rhs) {
Expand All @@ -158,4 +193,24 @@ Expression orL(const Expression &lhs, const Expression &rhs) {
return Expression(orExpr(lhs, rhs));
}

Expression e() {
return E();
}

Expression pi() {
return Pi();
}

Expression inf() {
return Inf();
}

Expression negInf() {
return NegInf();
}

Expression complexInf() {
return ComplexInf();
}

}
68 changes: 64 additions & 4 deletions tests/src/expressions/ExpressionFunctionsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,52 @@ TEST(ExpressionFunctionsTests, acotTest) {
EXPECT_EQ(acot(Expression("a/5")).toString(), "acot(a/5)");
}

TEST(ExpressionFunctionsTests, eTest) {
EXPECT_EQ(e().toString(), "E");
TEST(ExpressionFunctionsTests, sinhTest) {
EXPECT_EQ(sinh(Expression("-0.5")).toString(), "sinh(-1/2)");
EXPECT_EQ(sinh(Expression("0")).toString(), "0");
EXPECT_EQ(sinh(Expression("0.5")).toString(), "sinh(1/2)");
}

TEST(ExpressionFunctionsTests, piTest) {
EXPECT_EQ(pi().toString(), "Pi");
TEST(ExpressionFunctionsTests, coshTest) {
EXPECT_EQ(cosh(Expression("-0.5")).toString(), "cosh(-1/2)");
EXPECT_EQ(cosh(Expression("0")).toString(), "1");
EXPECT_EQ(cosh(Expression("0.5")).toString(), "cosh(1/2)");
}

TEST(ExpressionFunctionsTests, tanhTest) {
EXPECT_EQ(tanh(Expression("-0.5")).toString(), "tanh(-1/2)");
EXPECT_EQ(tanh(Expression("0")).toString(), "0");
EXPECT_EQ(tanh(Expression("0.5")).toString(), "tanh(1/2)");
}

TEST(ExpressionFunctionsTests, cothTest) {
EXPECT_EQ(coth(Expression("-0.5")).toString(), "coth(-1/2)");
EXPECT_EQ(coth(Expression("0")).toString(), "ComplexInf");
EXPECT_EQ(coth(Expression("0.5")).toString(), "coth(1/2)");
}

TEST(ExpressionFunctionsTests, asinhTest) {
EXPECT_EQ(asinh(Expression("-0.5")).toString(), "asinh(-1/2)");
EXPECT_EQ(asinh(Expression("0")).toString(), "0");
EXPECT_EQ(asinh(Expression("0.5")).toString(), "asinh(1/2)");
}

TEST(ExpressionFunctionsTests, acoshTest) {
EXPECT_EQ(acosh(Expression("-0.5")).toString(), "acosh(-1/2)");
EXPECT_EQ(acosh(Expression("0")).toString(), "1/2 I Pi");
EXPECT_EQ(acosh(Expression("0.5")).toString(), "acosh(1/2)");
}

TEST(ExpressionFunctionsTests, atanhTest) {
EXPECT_EQ(atanh(Expression("-0.5")).toString(), "atanh(-1/2)");
EXPECT_EQ(atanh(Expression("0")).toString(), "0");
EXPECT_EQ(atanh(Expression("0.5")).toString(), "atanh(1/2)");
}

TEST(ExpressionFunctionsTests, acothTest) {
EXPECT_EQ(acoth(Expression("-0.5")).toString(), "acoth(-1/2)");
EXPECT_EQ(acoth(Expression("0")).toString(), "1/2 I Pi");
EXPECT_EQ(acoth(Expression("0.5")).toString(), "acoth(1/2)");
}

// TODO! implement derivative
Expand Down Expand Up @@ -232,6 +272,26 @@ TEST(ExpressionFunctionsTests, orTest) {
EXPECT_EQ(orL(Expression("a!=a"), Expression("b!=b")).toString(), "False");
}

TEST(ExpressionFunctionsTests, eTest) {
EXPECT_EQ(e().toString(), "E");
}

TEST(ExpressionFunctionsTests, piTest) {
EXPECT_EQ(pi().toString(), "Pi");
}

TEST(ExpressionFunctionsTests, infTest) {
EXPECT_EQ(inf().toString(), "Inf");
}

TEST(ExpressionFunctionsTests, negInfTest) {
EXPECT_EQ(negInf().toString(), "-Inf");
}

TEST(ExpressionFunctionsTests, complexInfTest) {
EXPECT_EQ(complexInf().toString(), "ComplexInf");
}

TEST(ExpressionFunctionsTests, solveTest) {
EXPECT_EQ(solve(Expression("x - 10 = 0")).toString(), "x = 10");
EXPECT_EQ(solve(Expression("-10 - x = 0")).toString(), "x = -10");
Expand Down

0 comments on commit 98df4f0

Please sign in to comment.