From 98df4f0bf54028a8145d412770ce5267b2b3f1aa Mon Sep 17 00:00:00 2001 From: fintarin Date: Wed, 27 Sep 2023 09:43:39 +0300 Subject: [PATCH] Add hyperbolic functions & some constants to ExpressionFunctions --- .../expressions/ExpressionFunctions.hpp | 26 ++++++- .../expressions/ExpressionFunctions.cpp | 63 +++++++++++++++-- .../expressions/ExpressionFunctionsTests.cpp | 68 +++++++++++++++++-- 3 files changed, 147 insertions(+), 10 deletions(-) diff --git a/include/fintamath/expressions/ExpressionFunctions.hpp b/include/fintamath/expressions/ExpressionFunctions.hpp index 122860ef9..f65a6ab54 100644 --- a/include/fintamath/expressions/ExpressionFunctions.hpp +++ b/include/fintamath/expressions/ExpressionFunctions.hpp @@ -64,9 +64,21 @@ 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); @@ -74,6 +86,16 @@ 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); } diff --git a/src/fintamath/expressions/ExpressionFunctions.cpp b/src/fintamath/expressions/ExpressionFunctions.cpp index 49451d720..e0851f139 100644 --- a/src/fintamath/expressions/ExpressionFunctions.cpp +++ b/src/fintamath/expressions/ExpressionFunctions.cpp @@ -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" @@ -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 { @@ -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) { @@ -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(); +} + } diff --git a/tests/src/expressions/ExpressionFunctionsTests.cpp b/tests/src/expressions/ExpressionFunctionsTests.cpp index f0087da86..db36e7e8f 100644 --- a/tests/src/expressions/ExpressionFunctionsTests.cpp +++ b/tests/src/expressions/ExpressionFunctionsTests.cpp @@ -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 @@ -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");