diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml deleted file mode 100644 index a52cd529b..000000000 --- a/.github/workflows/analysis.yml +++ /dev/null @@ -1,72 +0,0 @@ -name: analysis - -on: - push: - branches: [master] - pull_request: - branches: [master] - -defaults: - run: - shell: bash - -env: - BUILD_TYPE: Release - -jobs: - analyze: - name: Analysis - runs-on: ubuntu-latest - - env: - SONAR_SCANNER_VERSION: 5.0.1.3006 - SONAR_SERVER_URL: "https://sonarcloud.io" - BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: 'true' - fetch-depth: 0 - - - name: Install GMP and MPFR - run: | - sudo sed -i 's/azure\.//' /etc/apt/sources.list - sudo apt-get update - sudo apt-get install libgmp-dev libmpfr-dev - - - name: Install sonar-scanner - env: - SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip - run: | - mkdir -p $HOME/.sonar - curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }} - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ - echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH - - - name: Install build-wrapper - env: - BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-linux-x86.zip - run: | - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }} - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ - echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH - - - name: Configure CMake - working-directory: ${{github.workspace}} - run: cmake -Bbuild -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - env: - CC: gcc - CXX: g++ - - - name: Build with build-wrapper - working-directory: ${{github.workspace}} - run: build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build --config ${{env.BUILD_TYPE}} - - - name: Perform SonarCloud analysis - working-directory: ${{github.workspace}} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0f3642d4c..68fbce376 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,79 +18,6 @@ jobs: strategy: matrix: config: - - { - name: Ubuntu GCC Release Shared, - os: ubuntu-latest, - cc: gcc, - cxx: g++, - build-type: Release, - shared: ON, - } - - { - name: Ubuntu GCC Debug Static, - os: ubuntu-latest, - cc: gcc, - cxx: g++, - build-type: Debug, - shared: OFF, - } - - { - name: Ubuntu Clang Release Shared, - os: ubuntu-latest, - cc: clang, - cxx: clang++, - build-type: Release, - shared: ON, - } - - { - name: Ubuntu Clang Debug Static, - os: ubuntu-latest, - cc: clang, - cxx: clang++, - build-type: Debug, - shared: OFF, - } - # TODO: remove version specifiers after macos-latest upgrades to version 13 - - { - name: macOS GCC Release Shared, - os: macos-13, - cc: gcc, - cxx: g++, - build-type: Release, - shared: ON, - } - - { - name: macOS GCC Debug Static, - os: macos-13, - cc: gcc, - cxx: g++, - build-type: Debug, - shared: OFF, - } - - { - name: macOS Clang Release Shared, - os: macos-13, - cc: clang, - cxx: clang++, - build-type: Release, - shared: ON, - } - - { - name: macOS Clang Debug Static, - os: macos-13, - cc: clang, - cxx: clang++, - build-type: Debug, - shared: OFF, - } - - { - name: Windows GCC Release Shared, - os: windows-latest, - cc: gcc, - cxx: g++, - build-type: Release, - shared: ON, - } - { name: Windows GCC Debug Static, os: windows-latest, @@ -99,38 +26,6 @@ jobs: build-type: Debug, shared: OFF, } - - { - name: Windows Clang Release Shared, - os: windows-latest, - cc: clang, - cxx: clang++, - build-type: Release, - shared: ON, - } - - { - name: Windows Clang Debug Static, - os: windows-latest, - cc: clang, - cxx: clang++, - build-type: Debug, - shared: OFF, - } - - { - name: Windows MSVC Release Shared, - os: windows-latest, - cc: msvc, - cxx: msvc, - build-type: Release, - shared: ON, - } - - { - name: Windows MSVC Debug Static, - os: windows-latest, - cc: msvc, - cxx: msvc, - build-type: Debug, - shared: OFF, - } steps: - name: Checkout diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index b49b08de0..000000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: coverage - -on: - push: - branches: [master] - pull_request: - branches: [master] - -defaults: - run: - shell: bash - -env: - BUILD_TYPE: Release - -jobs: - coverage: - name: Coverage - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: 'true' - - - name: Install GMP and MPFR - run: | - sudo sed -i 's/azure\.//' /etc/apt/sources.list - sudo apt-get update - sudo apt-get install libgmp-dev libmpfr-dev - - - name: Install llvm & lcov - run: | - sudo apt-get install llvm lcov - - # TODO: remove this step after the default Clang is updated to version 16 - - name: Install LLVM and Clang - uses: KyleMayes/install-llvm-action@v2 - with: - version: "16.0" - - - name: Configure CMake - working-directory: ${{github.workspace}} - run: cmake -Bbuild -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Dfintamath_build_tests=ON -Dfintamath_enable_coverage=ON - env: - CC: clang - CXX: clang++ - - - name: Build - working-directory: ${{github.workspace}} - run: cmake --build build --config ${{env.BUILD_TYPE}} - - - name: Collect coverage report - working-directory: ${{github.workspace}} - run: cmake --build build --config ${{env.BUILD_TYPE}} --target fintamath_coverage - - - name: Upload coverage report to Coveralls - uses: coverallsapp/github-action@v2 - with: - path-to-lcov: ${{github.workspace}}/build/lcov.info diff --git a/.github/workflows/sanitizer.yml b/.github/workflows/sanitizer.yml deleted file mode 100644 index abded3ce9..000000000 --- a/.github/workflows/sanitizer.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: sanitizer - -on: - push: - branches: [master] - pull_request: - branches: [master] - -defaults: - run: - shell: bash - -env: - BUILD_TYPE: Release - -jobs: - sanitize: - name: Sanitizer - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: 'true' - - - name: Install GMP and MPFR - run: | - sudo sed -i 's/azure\.//' /etc/apt/sources.list - sudo apt-get update - sudo apt-get install libgmp-dev libmpfr-dev - - - name: Configure CMake - working-directory: ${{github.workspace}} - run: cmake -Bbuild -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Dfintamath_build_tests=ON -Dfintamath_enable_sanitizers=ON - env: - CC: gcc - CXX: g++ - - - name: Build - working-directory: ${{github.workspace}} - run: cmake --build build --config ${{env.BUILD_TYPE}} - - - name: Test - working-directory: ${{github.workspace}}/build - run: ctest -C${{env.BUILD_TYPE}} --output-on-failure diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml deleted file mode 100644 index 8d0e3e66a..000000000 --- a/.github/workflows/style.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: style - -on: - push: - branches: [master] - pull_request: - branches: [master] - -defaults: - run: - shell: bash - -env: - BUILD_TYPE: Release - -jobs: - check-style: - name: Check Style - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: 'true' - - # TODO: remove this step after the default Clang is updated to version 16 - - name: Install LLVM and Clang - uses: KyleMayes/install-llvm-action@v2 - with: - version: "16.0" - - - name: Install GMP and MPFR - run: | - sudo sed -i 's/azure\.//' /etc/apt/sources.list - sudo apt-get update - sudo apt-get install libgmp-dev libmpfr-dev - - - name: Configure CMake - working-directory: ${{github.workspace}} - run: cmake -Bbuild -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Dfintamath_enable_clangformat=ON - env: - CC: gcc - CXX: g++ - - - name: Run clang-format - working-directory: ${{github.workspace}} - run: cmake --build build --target clangformat_check diff --git a/include/fintamath/config/Config.hpp b/include/fintamath/config/Config.hpp deleted file mode 100644 index a08956ab2..000000000 --- a/include/fintamath/config/Config.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -namespace fintamath::detail { - -struct Config final { - Config(); -}; - -} diff --git a/include/fintamath/core/Cache.hpp b/include/fintamath/core/Cache.hpp deleted file mode 100644 index 0ffd380a9..000000000 --- a/include/fintamath/core/Cache.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include -#include - -namespace fintamath::detail { - -template -class Cache final { -public: - using Function = std::function; - -public: - explicit Cache(const Function &inKeyToValueFunction) : keyToValueFunction(inKeyToValueFunction) {} - - const Value &operator[](const Key &key) { - if (!keyToValueMap.contains(key)) { - keyToValueMap[key] = keyToValueFunction(key); - } - - return keyToValueMap.at(key); - } - -private: - std::unordered_map keyToValueMap; - - Function keyToValueFunction; -}; - -} diff --git a/include/fintamath/core/Converter.hpp b/include/fintamath/core/Converter.hpp deleted file mode 100644 index 370ad0778..000000000 --- a/include/fintamath/core/Converter.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "fintamath/core/MultiMethod.hpp" - -namespace fintamath { - -class IMathObject; - -namespace detail { - -class Converter final { - template To, std::derived_from From> - using ConverterFunction = std::function(const To &to, const From &from)>; - - using ConverterMultiMethod = MultiMethod(const IMathObject &, const IMathObject &)>; - -public: - static std::unique_ptr convert(const IMathObject &to, const IMathObject &from) { - return getConverter()(to, from); - } - - static bool isConvertible(const IMathObject &to, const IMathObject &from) { - return getConverter().contains(to, from); - } - - template To, std::derived_from From> - static void add(const ConverterFunction &convertFunc) { - getConverter().add(convertFunc); - } - -private: - static ConverterMultiMethod &getConverter(); -}; - -} - -template To, std::derived_from From> -std::unique_ptr convert(const To &to, const From &from) { - return cast(detail::Converter::convert(to, from)); -} - -template To, std::derived_from From> -std::unique_ptr convert(const From &from) { - static const To to; - return convert(to, from); -} - -template To, std::derived_from From> -bool isConvertible(const To &to, const From &from) { - return detail::Converter::isConvertible(to, from); -} - -template To, std::derived_from From> -bool isConvertible(const From &from) { - static const To to; - return detail::Converter::isConvertible(to, from); -} - -} diff --git a/include/fintamath/core/IArithmetic.hpp b/include/fintamath/core/IArithmetic.hpp deleted file mode 100644 index e531d13e3..000000000 --- a/include/fintamath/core/IArithmetic.hpp +++ /dev/null @@ -1,122 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/Parser.hpp" - -namespace fintamath { - -class IArithmetic : public IMathObject { - FINTAMATH_PARENT_CLASS_BODY(IArithmetic) - -public: - friend std::unique_ptr operator+(const IArithmetic &lhs, const IArithmetic &rhs) { - return lhs.addAbstract(rhs); - } - - friend std::unique_ptr operator-(const IArithmetic &lhs, const IArithmetic &rhs) { - return lhs.substractAbstract(rhs); - } - - friend std::unique_ptr operator*(const IArithmetic &lhs, const IArithmetic &rhs) { - return lhs.multiplyAbstract(rhs); - } - - friend std::unique_ptr operator/(const IArithmetic &lhs, const IArithmetic &rhs) { - return lhs.divideAbstract(rhs); - } - - friend std::unique_ptr operator+(const IArithmetic &rhs) { - return cast(rhs.clone()); - } - - friend std::unique_ptr operator-(const IArithmetic &rhs) { - return rhs.negateAbstract(); - } - -protected: - virtual std::unique_ptr addAbstract(const IArithmetic &rhs) const = 0; - - virtual std::unique_ptr substractAbstract(const IArithmetic &rhs) const = 0; - - virtual std::unique_ptr multiplyAbstract(const IArithmetic &rhs) const = 0; - - virtual std::unique_ptr divideAbstract(const IArithmetic &rhs) const = 0; - - virtual std::unique_ptr negateAbstract() const = 0; -}; - -template -class IArithmeticCRTP : public IArithmetic { -#define I_ARITHMETIC_CRTP IArithmeticCRTP -#include "fintamath/core/IArithmeticCRTP.hpp" -#undef I_ARITHMETIC_CRTP -}; - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator+=(Lhs &lhs, const Rhs &rhs) { - return lhs += Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator-=(Lhs &lhs, const Rhs &rhs) { - return lhs -= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator*=(Lhs &lhs, const Rhs &rhs) { - return lhs *= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator/=(Lhs &lhs, const Rhs &rhs) { - return lhs /= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator+(const Lhs &lhs, const Rhs &rhs) { - return lhs + Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator+(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) + rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator-(const Lhs &lhs, const Rhs &rhs) { - return lhs - Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator-(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) - rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator*(const Lhs &lhs, const Rhs &rhs) { - return lhs * Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator*(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) * rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator/(const Lhs &lhs, const Rhs &rhs) { - return lhs / Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator/(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) / rhs; -} - -} diff --git a/include/fintamath/core/IArithmeticCRTP.hpp b/include/fintamath/core/IArithmeticCRTP.hpp deleted file mode 100644 index 92331d981..000000000 --- a/include/fintamath/core/IArithmeticCRTP.hpp +++ /dev/null @@ -1,148 +0,0 @@ -#if !defined(I_ARITHMETIC_CRTP) && !defined(NDEBUG) - -#include "fintamath/core/IArithmetic.hpp" - -namespace fintamath { - -template -class IArithmeticCRTP_ : public IArithmetic { - -#endif // I_ARITHMETIC_CRTP - -#define I_MATH_OBJECT_CRTP I_ARITHMETIC_CRTP -#include "fintamath/core/IMathObjectCRTP.hpp" -#undef I_MATH_OBJECT_CRTP - -public: - Derived &operator+=(const Derived &rhs) { - return add(rhs); - } - - Derived &operator-=(const Derived &rhs) { - return substract(rhs); - } - - Derived &operator*=(const Derived &rhs) { - return multiply(rhs); - } - - Derived &operator/=(const Derived &rhs) { - return divide(rhs); - } - - Derived operator+(const Derived &rhs) const { - return Derived(cast(*this)) += rhs; - } - - Derived operator-(const Derived &rhs) const { - return Derived(cast(*this)) -= rhs; - } - - Derived operator*(const Derived &rhs) const { - return Derived(cast(*this)) *= rhs; - } - - Derived operator/(const Derived &rhs) const { - return Derived(cast(*this)) /= rhs; - } - - Derived operator+() const { - return Derived(cast(*this)); - } - - Derived operator-() const { - Derived tmp = Derived(cast(*this)); - return cast(tmp).negate(); - } - -protected: - virtual Derived &add(const Derived &rhs) = 0; - - virtual Derived &substract(const Derived &rhs) = 0; - - virtual Derived &multiply(const Derived &rhs) = 0; - - virtual Derived ÷(const Derived &rhs) = 0; - - virtual Derived &negate() = 0; - - std::unique_ptr addAbstract(const IArithmetic &inRhs) const override { - return executeAbstract( - "+", inRhs, - [](I_ARITHMETIC_CRTP &lhs, const Derived &rhs) { - return lhs.add(rhs); - }, - [](const IArithmetic &lhs, const IArithmetic &rhs) { - return lhs + rhs; - }); - } - - std::unique_ptr substractAbstract(const IArithmetic &inRhs) const override { - return executeAbstract( - "-", inRhs, - [](I_ARITHMETIC_CRTP &lhs, const Derived &rhs) { - return lhs.substract(rhs); - }, - [](const IArithmetic &lhs, const IArithmetic &rhs) { - return lhs - rhs; - }); - } - - std::unique_ptr multiplyAbstract(const IArithmetic &inRhs) const override { - return executeAbstract( - "*", inRhs, - [](I_ARITHMETIC_CRTP &lhs, const Derived &rhs) { - return lhs.multiply(rhs); - }, - [](const IArithmetic &lhs, const IArithmetic &rhs) { - return lhs * rhs; - }); - } - - std::unique_ptr divideAbstract(const IArithmetic &inRhs) const override { - return executeAbstract( - "/", inRhs, - [](I_ARITHMETIC_CRTP &lhs, const Derived &rhs) { - return lhs.divide(rhs); - }, - [](const IArithmetic &lhs, const IArithmetic &rhs) { - return lhs / rhs; - }); - } - - std::unique_ptr negateAbstract() const override { - return std::make_unique(-(*this)); - } - -private: - std::unique_ptr executeAbstract(const std::string &operStr, - const IArithmetic &rhs, - std::invocable auto callFunc, - std::invocable auto callOper) const { - - if (const auto *rhsPtr = cast(&rhs)) { - auto lhsPtr = cast(clone()); - auto res = callFunc(*lhsPtr, *rhsPtr); - return cast(res.toMinimalObject()); - } - - if (const auto rhsPtr = cast(convert(*this, rhs))) { - auto lhsPtr = cast(clone()); - auto res = callFunc(*lhsPtr, *rhsPtr); - return cast(res.toMinimalObject()); - } - - if (const auto lhsPtr = cast(convert(rhs, *this))) { - auto res = callOper(*lhsPtr, rhs); - return cast(res->toMinimalObject()); - } - - throw InvalidInputBinaryOperatorException(operStr, toString(), rhs.toString()); - } - -private: -#if !defined(I_ARITHMETIC_CRTP) && !defined(NDEBUG) -}; -} - -#endif // I_ARITHMETIC_CRTP diff --git a/include/fintamath/core/IComparable.hpp b/include/fintamath/core/IComparable.hpp deleted file mode 100644 index b8ed7be85..000000000 --- a/include/fintamath/core/IComparable.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/Parser.hpp" - -namespace fintamath { - -class IComparable : public IArithmetic { - FINTAMATH_PARENT_CLASS_BODY(IComparable) - -public: - friend std::strong_ordering operator<=>(const IComparable &lhs, const IComparable &rhs) { - return lhs.compareAbstract(rhs); - } - -protected: - virtual std::strong_ordering compareAbstract(const IComparable &rhs) const = 0; -}; - -template -class IComparableCRTP : public IComparable { -#define I_COMPARABLE_CRTP IComparableCRTP -#include "fintamath/core/IComparableCRTP.hpp" -#undef I_COMPARABLE_CRTP -}; - -template Lhs, ConvertibleToAndNotSameAs Rhs> -std::strong_ordering operator<=>(const Lhs &lhs, const Rhs &rhs) { - return lhs <=> Lhs(rhs); -} - -} diff --git a/include/fintamath/core/IComparableCRTP.hpp b/include/fintamath/core/IComparableCRTP.hpp deleted file mode 100644 index 2f04164da..000000000 --- a/include/fintamath/core/IComparableCRTP.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#if !defined(I_COMPARABLE_CRTP) && !defined(NDEBUG) - -#include "fintamath/core/IComparable.hpp" - -namespace fintamath { - -template -class IComparableCRTP_ : public IComparable { - -#endif // I_COMPARABLE_CRTP - -#define I_ARITHMETIC_CRTP I_COMPARABLE_CRTP -#include "fintamath/core/IArithmeticCRTP.hpp" -#undef I_ARITHMETIC_CRTP - -public: - std::strong_ordering operator<=>(const I_COMPARABLE_CRTP &rhs) const { - return compare(cast(rhs)); - } - -protected: - virtual std::strong_ordering compare(const Derived &rhs) const = 0; - - std::strong_ordering compareAbstract(const IComparable &rhs) const override { - if (const auto *rhsPtr = cast(&rhs)) { - return compare(*rhsPtr); - } - - if (std::unique_ptr rhsPtr = convert(*this, rhs)) { - return compare(cast(*rhsPtr)); - } - - if (isConvertible(rhs, *this)) { - return 0 <=> (rhs <=> *this); - } - - throw InvalidInputBinaryOperatorException("<=>", toString(), rhs.toString()); - } - -private: -#if !defined(I_COMPARABLE_CRTP) && !defined(NDEBUG) -}; -} - -#endif // I_COMPARABLE_CRTP diff --git a/include/fintamath/core/IMathObject.hpp b/include/fintamath/core/IMathObject.hpp deleted file mode 100644 index 1d225c889..000000000 --- a/include/fintamath/core/IMathObject.hpp +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "fintamath/core/Converter.hpp" -#include "fintamath/core/MathObjectBody.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/Parser.hpp" - -namespace fintamath { - -class IMathObject { - FINTAMATH_PARENT_CLASS_BODY(IMathObject) - -public: - virtual ~IMathObject() = default; - - virtual std::unique_ptr clone() const & = 0; - - virtual std::unique_ptr clone() && = 0; - - virtual std::string toString() const { - return std::string(getClass().getName()); - } - - virtual std::unique_ptr toMinimalObject() const { - return clone(); - } - - virtual MathObjectClass getClass() const = 0; - - friend bool operator==(const IMathObject &lhs, const IMathObject &rhs) { - return lhs.equalsAbstract(rhs); - } - -protected: - virtual bool equalsAbstract(const IMathObject &rhs) const = 0; -}; - -template -class IMathObjectCRTP : public IMathObject { -#define I_MATH_OBJECT_CRTP IMathObjectCRTP -#include "fintamath/core/IMathObjectCRTP.hpp" -#undef I_MATH_OBJECT_CRTP -}; - -template Lhs, ConvertibleToAndNotSameAs Rhs> -bool operator==(const Lhs &lhs, const Rhs &rhs) { - return lhs == Lhs(rhs); -} - -inline std::ostream &operator<<(std::ostream &out, const IMathObject &rhs) { - return out << rhs.toString(); -} - -} diff --git a/include/fintamath/core/IMathObjectCRTP.hpp b/include/fintamath/core/IMathObjectCRTP.hpp deleted file mode 100644 index e7b386f83..000000000 --- a/include/fintamath/core/IMathObjectCRTP.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#if !defined(I_MATH_OBJECT_CRTP) && !defined(NDEBUG) - -#include "fintamath/core/IMathObject.hpp" - -namespace fintamath { - -template -class IMathObjectCRTP_ : public IMathObject { - -#endif // I_MATH_OBJECT_CRTP - -public: - std::unique_ptr clone() const & final { - return std::make_unique(cast(*this)); - } - - std::unique_ptr clone() && final { - return std::make_unique(std::move(cast(*this))); - } - - bool operator==(const I_MATH_OBJECT_CRTP &rhs) const { - return equals(cast(rhs)); - } - - MathObjectClass getClass() const override { - return Derived::getClassStatic(); - } - -protected: - virtual bool equals(const Derived &rhs) const { - return toString() == rhs.toString(); - } - - bool equalsAbstract(const IMathObject &rhs) const override { - if (const auto *rhsPtr = cast(&rhs)) { - return equals(*rhsPtr); - } - - if (std::unique_ptr rhsPtr = convert(*this, rhs)) { - return equals(cast(*rhsPtr)); - } - - if (isConvertible(rhs, *this)) { - return rhs == *this; - } - - return false; - } - -private: -#if !defined(I_MATH_OBJECT_CRTP) && !defined(NDEBUG) -}; -} - -#endif // I_MATH_OBJECT_CRTP diff --git a/include/fintamath/core/MathObjectBody.hpp b/include/fintamath/core/MathObjectBody.hpp deleted file mode 100644 index 8918b4b83..000000000 --- a/include/fintamath/core/MathObjectBody.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/Parser.hpp" - -#define FINTAMATH_CLASS_BODY(Class) \ -public: \ - static constexpr MathObjectClass getClassStatic() { \ - return {#Class}; \ - } \ - \ -private: - -#define FINTAMATH_PARENT_CLASS_BODY(Class) \ - FINTAMATH_CLASS_BODY(Class) \ - \ -private: \ - using Class##Parser = detail::Parser>; \ - \ - static Class##Parser &getParser(); \ - \ -public: \ - static auto parse(std::string str) { \ - return getParser().parse(std::move(str)); \ - } \ - \ - static auto parseFirst(std::string str) { \ - return getParser().parseFirst(std::move(str)); \ - } \ - \ - template T> \ - static void registerType() { \ - MathObjectClass::bindTypes(); \ - getParser().registerType(); \ - } \ - \ -private: - -#define FINTAMATH_PARENT_CLASS_IMPLEMENTATION(Class) \ - Class::Class##Parser &Class::getParser() { \ - static Class##Parser parser; \ - return parser; \ - } diff --git a/include/fintamath/core/MathObjectClass.hpp b/include/fintamath/core/MathObjectClass.hpp deleted file mode 100644 index cbbb233c3..000000000 --- a/include/fintamath/core/MathObjectClass.hpp +++ /dev/null @@ -1,102 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include "fintamath/config/Config.hpp" - -namespace fintamath { - -class MathObjectClass; - -} - -template <> -struct std::hash { - size_t operator()(const fintamath::MathObjectClass &rhs) const noexcept; -}; - -namespace fintamath { - -class MathObjectClass final { -public: - using Name = std::string_view; - - using Id = size_t; - - using Children = std::unordered_set; - -private: - using ClassToIdMap = std::unordered_map; - - using ChildToParentMap = std::unordered_map; - - using ParentToChildrenMap = std::unordered_map; - -public: - constexpr MathObjectClass(const Name inName) : name(inName) { - } - - constexpr Name getName() const { - return name; - } - - constexpr bool operator==(const MathObjectClass rhs) const { - return name == rhs.name; - } - - std::strong_ordering operator<=>(MathObjectClass rhs) const; - - std::optional getParent() const; - - const Children &getChildren(bool recursive = false) const; - - template Child> - static void bindTypes(); - -private: - Id getId() const; - - static ClassToIdMap &getClassToIdMap(); - - static ChildToParentMap &getChildToParentMap(); - - static ParentToChildrenMap &getParentToChildrenMap(); - - static ParentToChildrenMap &getParentToRecursiveChildrenMap(); - -private: - Name name; - - inline static Id maxId = 0; - - [[maybe_unused]] inline static const detail::Config config; -}; - -template Child> -void MathObjectClass::bindTypes() { - MathObjectClass parent = Parent::getClassStatic(); - MathObjectClass child = Child::getClassStatic(); - - getClassToIdMap()[parent] = ++maxId; - getClassToIdMap()[child] = ++maxId; - - getChildToParentMap().insert_or_assign(child, parent); - getParentToChildrenMap()[parent].emplace(child); - - for (std::optional superParent = child.getParent(); superParent; superParent = superParent->getParent()) { - Children &superParentChildren = getParentToRecursiveChildrenMap()[*superParent]; - superParentChildren.emplace(child); - superParentChildren.insert(child.getChildren().begin(), child.getChildren().end()); - } -} - -} - -inline size_t std::hash::operator()(const fintamath::MathObjectClass &rhs) const noexcept { - return std::hash{}(rhs.getName()); -} diff --git a/include/fintamath/core/MathObjectUtils.hpp b/include/fintamath/core/MathObjectUtils.hpp deleted file mode 100644 index 2fcd49c96..000000000 --- a/include/fintamath/core/MathObjectUtils.hpp +++ /dev/null @@ -1,139 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" - -namespace fintamath { - -class IMathObject; - -inline bool is(const MathObjectClass to, const MathObjectClass from) { - return to == from || to.getChildren(true).contains(from); -} - -template To, std::derived_from From> -bool is(const From &from) { - if constexpr (std::is_base_of_v) { - return true; - } - else if constexpr (!std::is_base_of_v) { - return false; - } - else { - return is(To::getClassStatic(), from.getClass()); - } -} - -template To, std::derived_from From> -bool is(const From *from) { - if (!from) { - return false; - } - - return is(*from); -} - -template To, std::derived_from From> -bool is(const std::unique_ptr &from) { - return is(from.get()); -} - -template To, std::derived_from From> -bool is(const std::shared_ptr &from) { - return is(from.get()); -} - -template To, std::derived_from From> -bool is(const std::shared_ptr &from) { - return is(from.get()); -} - -template To, std::derived_from From> -bool is(const std::reference_wrapper &from) { - return is(from.get()); -} - -template To, std::derived_from From> -bool is(const std::reference_wrapper &from) { - return is(from.get()); -} - -template To, std::derived_from From> -const To &cast(const From &from) { - if constexpr (!std::is_base_of_v) { - if (!is(from)) { - throw std::bad_cast{}; - } - } - - return static_cast(from); -} - -template To, std::derived_from From> -To &cast(From &from) { - if constexpr (!std::is_base_of_v) { - if (!is(from)) { - throw std::bad_cast{}; - } - } - - return static_cast(from); -} - -template To, std::derived_from From> -const To *cast(const From *from) { - if constexpr (!std::is_base_of_v) { - if (!is(from)) { - return {}; - } - } - - return static_cast(from); -} - -template To, std::derived_from From> -To *cast(From *from) { - if constexpr (!std::is_base_of_v) { - if (!is(from)) { - return {}; - } - } - - return static_cast(from); -} - -template To, std::derived_from From> -std::unique_ptr cast(std::unique_ptr &&from) { - if constexpr (!std::is_base_of_v) { - if (!is(from)) { - from.reset(); - return {}; - } - } - - From *fromRawPtr = from.release(); - auto *toRawPtr = static_cast(fromRawPtr); - return std::unique_ptr(toRawPtr); -} - -template To, std::derived_from From> -std::shared_ptr cast(const std::shared_ptr &from) { - if constexpr (!std::is_base_of_v) { - if (!is(from)) { - return {}; - } - } - - return std::static_pointer_cast(from); -} - -template To, std::derived_from From> -std::shared_ptr cast(const std::shared_ptr &from) { - return std::const_pointer_cast(cast(std::const_pointer_cast(from))); -} - -} \ No newline at end of file diff --git a/include/fintamath/core/MultiMethod.hpp b/include/fintamath/core/MultiMethod.hpp deleted file mode 100644 index f067eaf77..000000000 --- a/include/fintamath/core/MultiMethod.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "fintamath/core/Hash.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/MathObjectUtils.hpp" - -namespace fintamath::detail { - -template -class MultiMethod; - -template -class MultiMethod final { - template - using ArgId = MathObjectClass; - - using CallbackId = std::tuple...>; - - using Callback = std::function; - - using IdToCallbackMap = std::unordered_map>; - -public: - template - requires(sizeof...(Args) == sizeof...(ArgsBase)) - void add(const auto &func) { - idToCallbackMap[CallbackId(Args::getClassStatic()...)] = [func](const ArgsBase &...args) { - return func(cast(args)...); - }; - } - - template - requires(sizeof...(Args) == sizeof...(ArgsBase)) - Res operator()(Args &&...args) const { - if (auto iter = idToCallbackMap.find(CallbackId(args.getClass()...)); iter != idToCallbackMap.end()) { - return iter->second(std::forward(args)...); - } - - return {}; - } - - template - requires(sizeof...(Args) == sizeof...(ArgsBase)) - bool contains(const Args &...args) const { - return idToCallbackMap.contains(CallbackId(args.getClass()...)); - } - -private: - IdToCallbackMap idToCallbackMap; -}; - -} diff --git a/include/fintamath/core/Parser.hpp b/include/fintamath/core/Parser.hpp deleted file mode 100644 index f1fc3d6e9..000000000 --- a/include/fintamath/core/Parser.hpp +++ /dev/null @@ -1,116 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "fintamath/core/Tokenizer.hpp" -#include "fintamath/exceptions/InvalidInputException.hpp" - -namespace fintamath::detail { - -template -concept EmptyConstructable = requires { - T().toString(); -}; - -template -concept StringConstructable = requires(std::string str) { - T(str).toString(); -}; - -template -class Parser; - -template -class Parser final { -public: - using Generator = cppcoro::generator; - -private: - using Constructor = std::function; - - using StringToConstructorsMap = std::unordered_map>; - - using GeneratorConstructor = std::function; - - using GeneratorConstructorVector = std::vector; - -public: - Generator parse(std::string str) const { - if (const auto stringToConstructors = stringToConstructorsMap.find(str); stringToConstructors != stringToConstructorsMap.end()) { - for (const auto &constructor : stringToConstructors->second) { - co_yield constructor(); - } - } - - for (const auto &generatorConstructor : generatorConstructors) { - for (auto &value : generatorConstructor(str)) { - co_yield std::move(value); - } - } - } - - std::optional parseFirst(std::string str) const { - auto gener = parse(std::move(str)); - - if (auto iter = gener.begin(); iter != gener.end()) { - return std::move(*iter); - } - - return {}; - } - - template - requires(!std::is_abstract_v && !StringConstructable && EmptyConstructable) - void registerType() { - static const std::string name = Type{}.toString(); - - stringToConstructorsMap[name].emplace_back([]() -> Return { - return std::make_unique(); - }); - - Tokenizer::registerToken(name); - } - - template - requires(!std::is_abstract_v && StringConstructable) - void registerType() { - generatorConstructors.emplace_back([](std::string str) -> Generator { - try { - co_yield std::make_unique(std::move(str)); - } - catch (const InvalidInputException &) { - // Go to the next constructor - } - }); - } - - template - requires(std::is_abstract_v) - void registerType() { - generatorConstructors.emplace_back([](std::string str) -> Generator { - for (auto &value : Type::parse(std::move(str))) { - co_yield std::move(value); - } - }); - } - - template - void registerType() const { - // No object of this type can be constructed - } - -private: - StringToConstructorsMap stringToConstructorsMap; - - GeneratorConstructorVector generatorConstructors; -}; - -} diff --git a/include/fintamath/core/Tokenizer.hpp b/include/fintamath/core/Tokenizer.hpp deleted file mode 100644 index f2f3dc44b..000000000 --- a/include/fintamath/core/Tokenizer.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include - -namespace fintamath::detail { - -using Token = std::string; -using TokenVector = std::vector; - -class Tokenizer final { -public: - static TokenVector tokenize(std::string str); - - static void registerToken(const Token &token); - -private: - static bool appendToken(TokenVector &tokens, Token &token, bool shouldSplit = false); - - static void handleSpaces(std::string &str); - - static bool isDigitOrPoint(char ch); - - static bool isSpace(char ch); - - static TokenVector &getRegisteredTokens(); -}; - -} diff --git a/include/fintamath/exceptions/Exception.hpp b/include/fintamath/exceptions/Exception.hpp deleted file mode 100644 index 9605e835e..000000000 --- a/include/fintamath/exceptions/Exception.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include - -namespace fintamath { - -class Exception : public std::exception { -public: - const char *what() const noexcept override { - return "Something went wrong..."; - } -}; - -} diff --git a/include/fintamath/exceptions/InvalidInputException.hpp b/include/fintamath/exceptions/InvalidInputException.hpp deleted file mode 100644 index de2f10aba..000000000 --- a/include/fintamath/exceptions/InvalidInputException.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "fintamath/exceptions/Exception.hpp" - -namespace fintamath { - -class InvalidInputException : public Exception { -public: - InvalidInputException() = default; - - explicit InvalidInputException(const std::string &input) { - content += ": " + input; - } - - const char *what() const noexcept override { - return content.c_str(); - } - -protected: - std::string content = "Invalid input"; -}; - -class InvalidInputFunctionException final : public InvalidInputException { -public: - explicit InvalidInputFunctionException(const std::string &func, const std::vector &argVect) { - content += ": " + func + "("; - - if (!argVect.empty()) { - for (const auto &arg : argVect) { - content += arg + ','; - } - - content.pop_back(); - } - - content += ")"; - } - - const char *what() const noexcept override { - return content.c_str(); - } -}; - -class InvalidInputBinaryOperatorException final : public InvalidInputException { -public: - explicit InvalidInputBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) { - content += ": (" + lhs + ")" + oper + "(" + rhs + ")"; - } -}; - -class InvalidInputUnaryOperatorException final : public InvalidInputException { -public: - enum class Type : uint8_t { - Prefix, - Postfix, - }; - -public: - explicit InvalidInputUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) { - switch (type) { - case Type::Prefix: - content += ": " + oper + "(" + rhs + ")"; - break; - case Type::Postfix: - content += ": (" + rhs + ")" + oper; - break; - } - } -}; - -} diff --git a/include/fintamath/exceptions/UndefinedException.hpp b/include/fintamath/exceptions/UndefinedException.hpp deleted file mode 100644 index 56ab666db..000000000 --- a/include/fintamath/exceptions/UndefinedException.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "fintamath/exceptions/Exception.hpp" - -namespace fintamath { - -class UndefinedException : public Exception { -public: - UndefinedException() = default; - - explicit UndefinedException(const std::string &input) { - content += ": " + input; - } - - const char *what() const noexcept override { - return content.c_str(); - } - -protected: - std::string content = "Undefined"; -}; - -class UndefinedFunctionException final : public UndefinedException { -public: - explicit UndefinedFunctionException(const std::string &func, const std::vector &argVect) { - content += ": " + func + "("; - - if (!argVect.empty()) { - for (const auto &arg : argVect) { - content += arg + ','; - } - - content.pop_back(); - } - - content += ")"; - } - - const char *what() const noexcept override { - return content.c_str(); - } -}; - -class UndefinedBinaryOperatorException final : public UndefinedException { -public: - explicit UndefinedBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) { - content += ": (" + lhs + ")" + oper + "(" + rhs + ")"; - } -}; - -class UndefinedUnaryOperatorException final : public UndefinedException { -public: - enum class Type : uint8_t { - Prefix, - Postfix, - }; - -public: - explicit UndefinedUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) { - switch (type) { - case Type::Prefix: - content += ": " + oper + "(" + rhs + ")"; - break; - case Type::Postfix: - content += ": (" + rhs + ")" + oper; - break; - } - } -}; - -} diff --git a/include/fintamath/expressions/Expression.hpp b/include/fintamath/expressions/Expression.hpp deleted file mode 100644 index c8e4de64f..000000000 --- a/include/fintamath/expressions/Expression.hpp +++ /dev/null @@ -1,187 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/Parser.hpp" -#include "fintamath/core/Tokenizer.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Variable.hpp" - -namespace fintamath { - -namespace detail { - -struct Term final { - Token name; - - std::unique_ptr value; - -public: - Term() = default; - - Term(std::string inName, std::unique_ptr inValue) - : name(std::move(inName)), - value(std::move(inValue)) { - } -}; - -struct FunctionTerm final { - Term term; - - std::optional priority; - -public: - FunctionTerm() = default; - - FunctionTerm(Term inTerm, const std::optional inPriority) - : term(std::move(inTerm)), - priority(inPriority) { - } -}; - -using TermVector = std::vector; - -using FunctionTermStack = std::stack; - -using OperandStack = std::stack>; - -} - -class Expression final : public IExpressionCRTP { - FINTAMATH_CLASS_BODY(Expression) - - using ExpressionConstructor = std::function(ArgumentPtrVector &&)>; - - using ExpressionMaker = std::unordered_map; - -public: - Expression(); - - explicit Expression(const std::string &str); - - explicit Expression(const ArgumentPtr &obj); - - Expression(const IMathObject &obj); - - Expression(int64_t val); - - std::string toString() const override; - - const std::shared_ptr &getFunction() const override; - - const ArgumentPtrVector &getChildren() const override; - - void setChildren(const ArgumentPtrVector &childVect) override; - - void setVariables(const std::vector> &varsToVals) override; - - void setVariable(const Variable &var, const Expression &val); - - template - static void registerExpressionConstructor(ExpressionConstructor constructor); - -protected: - ArgumentPtr simplify() const override; - -private: - void simplifyMutable() const; - - void updateStringMutable() const; - - static detail::TermVector tokensToTerms(detail::TokenVector &tokens); - - static detail::OperandStack termsToOperands(detail::TermVector &terms); - - static std::unique_ptr operandsToObject(detail::OperandStack &operands); - - static std::unique_ptr parseFunction(const std::string &str, size_t argNum); - - static std::unique_ptr parseOperator(const std::string &str, IOperator::Priority priority); - - static detail::Term parseTerm(const std::string &str); - - static void moveFunctionTermsToOperands(detail::OperandStack &operands, detail::FunctionTermStack &functions, const IOperator *nextOper); - - static void insertMultiplications(detail::TermVector &terms); - - static void fixOperatorTypes(detail::TermVector &terms); - - static void collapseFactorials(detail::TermVector &terms); - - static bool canNextTermBeBinaryOperator(const detail::Term &term); - - static bool canPrevTermBeBinaryOperator(const detail::Term &term); - - static bool isBinaryOperator(const IMathObject *val); - - static bool isPrefixOperator(const IMathObject *val); - - static bool isPostfixOperator(const IMathObject *val); - - static bool isNonOperatorFunction(const IMathObject *val); - - static void validateFunctionArgs(const IFunction &func, const ArgumentPtrVector &args); - - static bool doesArgMatch(const MathObjectClass &expectedType, const ArgumentPtr &arg); - - static ArgumentPtrVector unwrapComma(const ArgumentPtr &child); - - static ArgumentPtr compress(const ArgumentPtr &child); - - friend std::unique_ptr detail::makeExpr(const IFunction &func, ArgumentPtrVector args); - - friend std::unique_ptr parseExpr(const std::string &str); - - friend Expression approximate(const Expression &rhs, unsigned precision); - - static ExpressionMaker &getExpressionMaker(); - -private: - mutable ArgumentPtr child; - - mutable ArgumentPtrVector childrenCached = {{}}; - - mutable std::string stringCached; - - mutable bool isSimplified = false; -}; - -template -void Expression::registerExpressionConstructor(ExpressionConstructor constructor) { - getExpressionMaker()[Function::getClassStatic()] = [maker = std::move(constructor)](ArgumentPtrVector &&args) { - static const size_t funcArgSize = Function{}.getArgumentClasses().size(); - - std::unique_ptr res; - - if constexpr (Function::isVariadicStatic()) { - res = maker(std::move(args)); - } - else if constexpr (isPolynomial) { - if (funcArgSize <= args.size()) { - res = maker(std::move(args)); - } - } - else { - if (funcArgSize == args.size()) { - res = maker(std::move(args)); - } - } - - return res; - }; -} - -} diff --git a/include/fintamath/expressions/ExpressionComparator.hpp b/include/fintamath/expressions/ExpressionComparator.hpp deleted file mode 100644 index 3c503800c..000000000 --- a/include/fintamath/expressions/ExpressionComparator.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include - -#include "fintamath/functions/FunctionArguments.hpp" - -namespace fintamath::detail { - -struct ComparatorOptions final { - bool termOrderInversed = false; - bool comparableOrderInversed = false; -}; - -std::strong_ordering compare(ArgumentPtr lhs, ArgumentPtr rhs, ComparatorOptions options = {}); - -} diff --git a/include/fintamath/expressions/ExpressionFunctions.hpp b/include/fintamath/expressions/ExpressionFunctions.hpp deleted file mode 100644 index a3795556d..000000000 --- a/include/fintamath/expressions/ExpressionFunctions.hpp +++ /dev/null @@ -1,110 +0,0 @@ -#pragma once - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -Expression operator+(const Expression &lhs, const Expression &rhs); - -Expression operator+(const Expression &rhs); - -Expression operator-(const Expression &lhs, const Expression &rhs); - -Expression operator-(const Expression &rhs); - -Expression operator*(const Expression &lhs, const Expression &rhs); - -Expression operator/(const Expression &lhs, const Expression &rhs); - -Expression mod(const Expression &lhs, const Expression &rhs); - -Expression eqv(const Expression &lhs, const Expression &rhs); - -Expression neqv(const Expression &lhs, const Expression &rhs); - -Expression less(const Expression &lhs, const Expression &rhs); - -Expression more(const Expression &lhs, const Expression &rhs); - -Expression lessEqv(const Expression &lhs, const Expression &rhs); - -Expression moreEqv(const Expression &lhs, const Expression &rhs); - -Expression floor(const Expression &rhs); - -Expression ceil(const Expression &rhs); - -Expression abs(const Expression &rhs); - -Expression factorial(const Expression &rhs); - -Expression sqrt(const Expression &rhs); - -Expression pow(const Expression &lhs, const Expression &rhs); - -Expression exp(const Expression &rhs); - -Expression log(const Expression &lhs, const Expression &rhs); - -Expression ln(const Expression &rhs); - -Expression lb(const Expression &rhs); - -Expression lg(const Expression &rhs); - -Expression sin(const Expression &rhs); - -Expression cos(const Expression &rhs); - -Expression tan(const Expression &rhs); - -Expression cot(const Expression &rhs); - -Expression asin(const Expression &rhs); - -Expression acos(const Expression &rhs); - -Expression atan(const Expression &rhs); - -Expression acot(const Expression &rhs); - -Expression sinh(const Expression &rhs); - -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 derivative(const Expression &lhs, 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); - -extern Expression approximate(const Expression &rhs, unsigned precision = Real::getPrecision()); - -} diff --git a/include/fintamath/expressions/ExpressionParser.hpp b/include/fintamath/expressions/ExpressionParser.hpp deleted file mode 100644 index 2be6f27ae..000000000 --- a/include/fintamath/expressions/ExpressionParser.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" - -namespace fintamath { - -std::unique_ptr parseExpr(const std::string &str); - -} diff --git a/include/fintamath/expressions/ExpressionUtils.hpp b/include/fintamath/expressions/ExpressionUtils.hpp deleted file mode 100644 index 201571bb6..000000000 --- a/include/fintamath/expressions/ExpressionUtils.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/literals/constants/Undefined.hpp" - -namespace fintamath::detail { - -template ... Args, std::invocable SimplifyFunction> -ArgumentPtr useSimplifyFunctions(const std::vector &simplFuncs, - const IFunction &func, - const Args &...args) { - - for (const auto &simplFunc : simplFuncs) { - if (auto res = simplFunc(func, args...)) { - return res; - } - } - - return {}; -} - -ArgumentPtr simplifyUndefined(const IFunction &func, const std::same_as auto &...args) { - ArgumentPtr res; - - if ((is(args) || ...)) { - static const MathObjectClass undefinedReturnType = Undefined{}.getReturnClass(); - const MathObjectClass funcReturnType = func.getReturnClass(); - - if (is(undefinedReturnType, funcReturnType) || - is(funcReturnType, undefinedReturnType)) { - - res = Undefined{}.clone(); - } - } - - return res; -} - -bool isInfinity(const ArgumentPtr &arg); - -bool isMulInfinity(const ArgumentPtr &arg); - -bool isNegated(const ArgumentPtr &arg); - -bool isNegativeNumber(const ArgumentPtr &arg); - -bool isComplexNumber(const ArgumentPtr &arg); - -bool containsIf(const ArgumentPtr &arg, const std::function &comp); - -bool containsChild(const ArgumentPtr &arg, const ArgumentPtr &child); - -bool containsVariable(const ArgumentPtr &arg); - -bool containsVariable(const ArgumentPtr &arg, const Variable &var); - -bool containsInfinity(const ArgumentPtr &arg); - -bool containsComplex(const ArgumentPtr &arg); - -std::pair splitMulExpr(const ArgumentPtr &inChild, bool checkVariables = true); - -std::pair splitPowExpr(const ArgumentPtr &rhs); - -std::pair splitRational(const ArgumentPtr &arg); - -ArgumentPtr negate(const ArgumentPtr &arg); - -ArgumentPtr makePolynom(const IFunction &func, ArgumentPtrVector &&args); - -ArgumentPtr makePolynom(const IFunction &func, const ArgumentPtrVector &args); - -ArgumentPtrVector getPolynomChildren(const IFunction &func, const ArgumentPtr &arg); - -std::vector argumentVectorToStringVector(const ArgumentPtrVector &args); - -ArgumentPtrVector argumentRefVectorToArgumentPtrVector(const ArgumentRefVector &args); - -std::string putInBrackets(const std::string &str); - -std::string putInSpaces(const std::string &str); - -std::string functionToString(const IFunction &func, const ArgumentPtrVector &args); - -std::string operatorChildToString(const IOperator &oper, const ArgumentPtr &child); - -std::string binaryOperatorToString(const IOperator &oper, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - -std::string prefixUnaryOperatorToString(const IOperator &oper, const ArgumentPtr &rhs); - -std::string postfixUnaryOperatorToString(const IOperator &oper, const ArgumentPtr &rhs); - -} \ No newline at end of file diff --git a/include/fintamath/expressions/IExpression.hpp b/include/fintamath/expressions/IExpression.hpp deleted file mode 100644 index 21f47b3be..000000000 --- a/include/fintamath/expressions/IExpression.hpp +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/Parser.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -class IExpression : public IMathObject { - FINTAMATH_PARENT_CLASS_BODY(IExpression) - -public: - virtual const std::shared_ptr &getFunction() const = 0; - - virtual const ArgumentPtrVector &getChildren() const = 0; - - virtual void setChildren(const ArgumentPtrVector &childVect) = 0; - - std::vector getVariables() const; - - virtual void setVariables(const std::vector> &varsToVals); - - std::unique_ptr toMinimalObject() const final; - - virtual const std::shared_ptr &getOutputFunction() const; - -protected: - virtual ArgumentPtr simplify() const; - - virtual ArgumentPtr preSimplify() const; - - virtual ArgumentPtr postSimplify() const; - - virtual ArgumentPtr approximate() const; - - virtual ArgumentPtr setPrecision(unsigned precision, const Integer &maxInt) const; - - static void simplifyChild(ArgumentPtr &child); - - static void preSimplifyChild(ArgumentPtr &child); - - static void postSimplifyChild(ArgumentPtr &child); - - static void approximateChild(ArgumentPtr &child); - - static void setPrecisionChild(ArgumentPtr &child, unsigned precision, const Integer &maxInt); - - static ArgumentPtr callFunction(const IFunction &func, const ArgumentPtrVector &argPtrs); - -private: - static std::unique_ptr convertToApproximated(const INumber &num); - - static std::unique_ptr convertToApproximated(const INumber &num, unsigned precision, const Integer &maxInt); - - static ArgumentPtrVector convertToApproximatedNumbers(const ArgumentPtrVector &args); -}; - -template -class IExpressionBaseCRTP : public IExpression { -#define I_EXPRESSION_BASE_CRTP IExpressionBaseCRTP -#include "fintamath/expressions/IExpressionBaseCRTP.hpp" -#undef I_EXPRESSION_BASE_CRTP -}; - -template -class IExpressionCRTP : public IExpressionBaseCRTP { -#define I_EXPRESSION_CRTP IExpressionCRTP -#include "fintamath/expressions/IExpressionCRTP.hpp" -#undef I_EXPRESSION_CRTP -}; - -} diff --git a/include/fintamath/expressions/IExpressionBaseCRTP.hpp b/include/fintamath/expressions/IExpressionBaseCRTP.hpp deleted file mode 100644 index 886cdc4f4..000000000 --- a/include/fintamath/expressions/IExpressionBaseCRTP.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#if !defined(I_EXPRESSION_BASE_CRTP) && !defined(NDEBUG) - -#include "fintamath/expressions/IExpression.hpp" - -namespace fintamath { - -template -class IExpressionBaseCRTP_ : public IExpression { - -#endif // I_EXPRESSION_BASE_CRTP - -#define I_MATH_OBJECT_CRTP I_EXPRESSION_BASE_CRTP -#include "fintamath/core/IMathObjectCRTP.hpp" -#undef I_MATH_OBJECT_CRTP - -private: -#if !defined(I_EXPRESSION_BASE_CRTP) && !defined(NDEBUG) -}; -} - -#endif // I_EXPRESSION_CRTP diff --git a/include/fintamath/expressions/IExpressionCRTP.hpp b/include/fintamath/expressions/IExpressionCRTP.hpp deleted file mode 100644 index 68e86bd25..000000000 --- a/include/fintamath/expressions/IExpressionCRTP.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#if !defined(I_EXPRESSION_CRTP) && !defined(NDEBUG) - -#include "fintamath/expressions/IExpression.hpp" - -namespace fintamath { - -template -class IExpressionCRTP_ : public IExpressionBaseCRTP { - -#endif // I_EXPRESSION_CRTP - -public: - bool equals(const Derived &rhs) const override { - if (static_cast(this->getFunction()) != static_cast(rhs.getFunction()) || - (this->getFunction() && rhs.getFunction() && *this->getFunction() != *rhs.getFunction())) { - - return false; - } - - const ArgumentPtrVector &lhsChildren = this->getChildren(); - const ArgumentPtrVector &rhsChildren = rhs.getChildren(); - - if (lhsChildren.size() != rhsChildren.size()) { - return false; - } - - for (const auto i : stdv::iota(0U, lhsChildren.size())) { - if (lhsChildren[i] != rhsChildren[i] && *lhsChildren[i] != *rhsChildren[i]) { - return false; - } - } - - return true; - } - -private: -#if !defined(I_EXPRESSION_CRTP) && !defined(NDEBUG) -}; -} - -#endif // I_EXPRESSION_CRTP diff --git a/include/fintamath/expressions/interfaces/IBinaryExpression.hpp b/include/fintamath/expressions/interfaces/IBinaryExpression.hpp deleted file mode 100644 index 7d65d6dc6..000000000 --- a/include/fintamath/expressions/interfaces/IBinaryExpression.hpp +++ /dev/null @@ -1,79 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class IBinaryExpression : public IExpression { - FINTAMATH_PARENT_CLASS_BODY(IBinaryExpression) - -public: - explicit IBinaryExpression(const IFunction &inFunc, ArgumentPtr lhs, ArgumentPtr rhs); - - std::string toString() const override; - - const std::shared_ptr &getFunction() const final; - - const ArgumentPtrVector &getChildren() const final; - - void setChildren(const ArgumentPtrVector &childVect) final; - -protected: - using SimplifyFunction = std::function; - - using SimplifyFunctionVector = std::vector; - - virtual SimplifyFunctionVector getFunctionsForPreSimplify() const; - - virtual SimplifyFunctionVector getFunctionsForPostSimplify() const; - - ArgumentPtr preSimplify() const override; - - ArgumentPtr postSimplify() const override; - -private: - ArgumentPtr simplifyRec(bool isPostSimplify) const; - -protected: - std::shared_ptr func; - - ArgumentPtr lhsChild; - - ArgumentPtr rhsChild; - -private: - mutable ArgumentPtrVector childrenCached = {{}, {}}; -}; - -template -class IBinaryExpressionBaseCRTP : public IBinaryExpression { -#define I_EXPRESSION_BASE_CRTP IBinaryExpressionBaseCRTP -#include "fintamath/expressions/IExpressionBaseCRTP.hpp" -#undef I_EXPRESSION_BASE_CRTP - -public: - explicit IBinaryExpressionBaseCRTP(const IFunction &inFunc, ArgumentPtr lhs, ArgumentPtr rhs) - : IBinaryExpression(inFunc, std::move(lhs), std::move(rhs)) {} -}; - -template -class IBinaryExpressionCRTP : public IBinaryExpressionBaseCRTP { -#define I_EXPRESSION_CRTP IBinaryExpressionCRTP -#include "fintamath/expressions/IExpressionCRTP.hpp" -#undef I_EXPRESSION_CRTP - -public: - explicit IBinaryExpressionCRTP(const IFunction &inFunc, ArgumentPtr lhs, ArgumentPtr rhs) - : IBinaryExpressionBaseCRTP(inFunc, std::move(lhs), std::move(rhs)) {} -}; - -} diff --git a/include/fintamath/expressions/interfaces/IPolynomExpression.hpp b/include/fintamath/expressions/interfaces/IPolynomExpression.hpp deleted file mode 100644 index daaf0739f..000000000 --- a/include/fintamath/expressions/interfaces/IPolynomExpression.hpp +++ /dev/null @@ -1,91 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class IOperator; - -class IPolynomExpression : public IExpression { - FINTAMATH_PARENT_CLASS_BODY(IPolynomExpression) - -public: - explicit IPolynomExpression(const IFunction &inFunc, ArgumentPtrVector args); - - std::string toString() const override; - - const std::shared_ptr &getFunction() const final; - - const ArgumentPtrVector &getChildren() const final; - - void setChildren(const ArgumentPtrVector &childVect) final; - -protected: - using SimplifyFunction = std::function; - - using SimplifyFunctionVector = std::vector; - - virtual SimplifyFunctionVector getFunctionsForPreSimplify() const; - - virtual SimplifyFunctionVector getFunctionsForPostSimplify() const; - - virtual std::string childToString(const IOperator &oper, const ArgumentPtr &inChild, const ArgumentPtr &prevChild) const; - - virtual std::strong_ordering compare(const ArgumentPtr &lhs, const ArgumentPtr &rhs) const; - - ArgumentPtr preSimplify() const override; - - ArgumentPtr postSimplify() const override; - - virtual bool isTermOrderInversed() const; - - virtual bool isComparableOrderInversed() const; - -private: - void simplifyRec(bool isPostSimplify); - - void simplifyChildren(bool isPostSimplify); - - void compress(); - - void sort(); - -protected: - std::shared_ptr func; - - ArgumentPtrVector children; -}; - -template -class IPolynomExpressionBaseCRTP : public IPolynomExpression { -#define I_EXPRESSION_BASE_CRTP IPolynomExpressionBaseCRTP -#include "fintamath/expressions/IExpressionBaseCRTP.hpp" -#undef I_EXPRESSION_BASE_CRTP - -public: - explicit IPolynomExpressionBaseCRTP(const IFunction &inFunc, ArgumentPtrVector args) - : IPolynomExpression(inFunc, std::move(args)) {} -}; - -template -class IPolynomExpressionCRTP : public IPolynomExpressionBaseCRTP { -#define I_EXPRESSION_CRTP IPolynomExpressionCRTP -#include "fintamath/expressions/IExpressionCRTP.hpp" -#undef I_EXPRESSION_CRTP - -public: - explicit IPolynomExpressionCRTP(const IFunction &inFunc, ArgumentPtrVector args) - : IPolynomExpressionBaseCRTP(inFunc, std::move(args)) {} -}; - -} diff --git a/include/fintamath/expressions/interfaces/IUnaryExpression.hpp b/include/fintamath/expressions/interfaces/IUnaryExpression.hpp deleted file mode 100644 index fab8029a7..000000000 --- a/include/fintamath/expressions/interfaces/IUnaryExpression.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class IUnaryExpression : public IExpression { - FINTAMATH_PARENT_CLASS_BODY(IUnaryExpression) - -public: - explicit IUnaryExpression(const IFunction &inFunc, ArgumentPtr rhs); - - std::string toString() const override; - - const std::shared_ptr &getFunction() const final; - - const ArgumentPtrVector &getChildren() const override; - - void setChildren(const ArgumentPtrVector &childVect) override; - -protected: - using SimplifyFunction = std::function; - - using SimplifyFunctionVector = std::vector; - - virtual SimplifyFunctionVector getFunctionsForPreSimplify() const; - - virtual SimplifyFunctionVector getFunctionsForPostSimplify() const; - - ArgumentPtr preSimplify() const override; - - ArgumentPtr postSimplify() const override; - -protected: - std::shared_ptr func; - - ArgumentPtr child; - -private: - ArgumentPtr simplifyRec(bool isPostSimplify) const; - -private: - mutable ArgumentPtrVector childrenCached = {{}}; -}; - -template -class IUnaryExpressionBaseCRTP : public IUnaryExpression { -#define I_EXPRESSION_BASE_CRTP IUnaryExpressionBaseCRTP -#include "fintamath/expressions/IExpressionBaseCRTP.hpp" -#undef I_EXPRESSION_BASE_CRTP - -public: - explicit IUnaryExpressionBaseCRTP(const IFunction &inFunc, ArgumentPtr rhs) - : IUnaryExpression(inFunc, std::move(rhs)) {} -}; - -template -class IUnaryExpressionCRTP : public IUnaryExpressionBaseCRTP { -#define I_EXPRESSION_CRTP IUnaryExpressionCRTP -#include "fintamath/expressions/IExpressionCRTP.hpp" -#undef I_EXPRESSION_CRTP - -public: - explicit IUnaryExpressionCRTP(const IFunction &inFunc, ArgumentPtr rhs) - : IUnaryExpressionBaseCRTP(inFunc, std::move(rhs)) {} -}; - -} diff --git a/include/fintamath/functions/FunctionArguments.hpp b/include/fintamath/functions/FunctionArguments.hpp deleted file mode 100644 index 729202ac4..000000000 --- a/include/fintamath/functions/FunctionArguments.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" - -namespace fintamath { - -class IMathObject; - -using ArgumentRef = std::reference_wrapper; -using ArgumentPtr = std::shared_ptr; - -using ArgumentRefVector = std::vector; -using ArgumentPtrVector = std::vector; - -using ArgumentTypeVector = std::vector; - -} diff --git a/include/fintamath/functions/FunctionUtils.hpp b/include/fintamath/functions/FunctionUtils.hpp deleted file mode 100644 index e7325e694..000000000 --- a/include/fintamath/functions/FunctionUtils.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" - -#define FINTAMATH_FUNCTION_EXPRESSION(Function, name) \ - std::unique_ptr name(auto &&...args) { \ - static const Function f; \ - return detail::makeExpr(f, std::forward(args)...); \ - } - -namespace fintamath { -class IFunction; - -namespace detail { - -extern bool isExpression(const IMathObject &arg); - -extern std::unique_ptr makeExpr(const IFunction &func, ArgumentPtrVector args); - -extern std::unique_ptr makeExpr(const IFunction &func, const ArgumentRefVector &args); - -std::unique_ptr makeExpr(const IFunction &func, const std::derived_from auto &...args) { - return makeExpr(func, ArgumentPtrVector{args.clone()...}); -} - -std::unique_ptr makeExpr(const IFunction &func, std::convertible_to auto &&...args) { - return makeExpr(func, ArgumentPtrVector{ArgumentPtr(std::forward(args))...}); -} - -} - -} diff --git a/include/fintamath/functions/IFunction.hpp b/include/fintamath/functions/IFunction.hpp deleted file mode 100644 index 4023997be..000000000 --- a/include/fintamath/functions/IFunction.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/Parser.hpp" -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" - -namespace fintamath { - -class IFunction : public IMathObject { - FINTAMATH_PARENT_CLASS_BODY(IFunction) - - using ClassToOrderMap = std::unordered_map; - -public: - virtual const ArgumentTypeVector &getArgumentClasses() const = 0; - - virtual MathObjectClass getReturnClass() const = 0; - - virtual bool doArgsMatch(const ArgumentRefVector &argVect) const = 0; - - virtual bool isVariadic() const = 0; - - virtual bool isEvaluatable() const = 0; - - std::unique_ptr operator()(const std::derived_from auto &...args) const { - const ArgumentRefVector argVect = {args...}; - return callAbstract(argVect); - } - - std::unique_ptr operator()(const ArgumentRefVector &argVect) const { - return callAbstract(argVect); - } - -protected: - virtual std::unique_ptr callAbstract(const ArgumentRefVector &argVect) const = 0; - - virtual void validateArgsSize(const ArgumentRefVector &argVect) const; -}; - -template - requires(sizeof...(Args) > 0) -class IFunctionCRTP : public IFunction { -#define I_FUNCTION_CRTP IFunctionCRTP -#include "fintamath/functions/IFunctionCRTP.hpp" -#undef I_FUNCTION_CRTP -}; - -} diff --git a/include/fintamath/functions/IFunctionCRTP.hpp b/include/fintamath/functions/IFunctionCRTP.hpp deleted file mode 100644 index c523e6405..000000000 --- a/include/fintamath/functions/IFunctionCRTP.hpp +++ /dev/null @@ -1,114 +0,0 @@ -#if !defined(I_FUNCTION_CRTP) && !defined(NDEBUG) - -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -template -class IFunctionCRTP_ : public IFunction { - -#endif // I_FUNCTION_CRTP - -#define I_MATH_OBJECT_CRTP I_FUNCTION_CRTP -#include "fintamath/core/IMathObjectCRTP.hpp" -#undef I_MATH_OBJECT_CRTP - -public: - static constexpr auto getArgumentClassesStatic() { - return std::array{Args::getClassStatic()...}; - } - - const std::vector &getArgumentClasses() const final { - constexpr auto argClassesArr = getArgumentClassesStatic(); - static const std::vector argClassesVect(argClassesArr.begin(), argClassesArr.end()); - return argClassesVect; - } - - static constexpr MathObjectClass getReturnClassStatic() { - return Return::getClassStatic(); - } - - MathObjectClass getReturnClass() const final { - return getReturnClassStatic(); - } - - bool doArgsMatch(const ArgumentRefVector &argVect) const override { - if constexpr (Derived::isVariadicStatic()) { - return doAnyArgsMatch(argVect); - } - else { - if (argVect.size() != getArgumentClassesStatic().size()) { - return false; - } - - return doArgsMatch<0, Args...>(argVect); - } - } - - bool isVariadic() const final { - return Derived::isVariadicStatic(); - } - - static constexpr bool isVariadicStatic() { - return false; - } - - bool isEvaluatable() const final { - return Derived::isEvaluatableStatic(); - } - - static constexpr bool isEvaluatableStatic() { - return true; - } - -protected: - virtual std::unique_ptr call(const ArgumentRefVector &argVect) const = 0; - - std::unique_ptr callAbstract(const ArgumentRefVector &argVect) const override { - validateArgsSize(argVect); - - if (doArgsMatch(argVect)) { - try { - if (auto res = call(argVect)) { - return res; - } - - return detail::makeExpr(*this, argVect); - } - catch (const UndefinedException &) { - return detail::makeExpr(*this, argVect); - } - } - - return detail::makeExpr(*this, argVect)->toMinimalObject(); - } - -private: - template - bool doArgsMatch(const ArgumentRefVector &argVect) const { - if (!is(argVect[i]) || detail::isExpression(argVect[i])) { - return false; - } - - return doArgsMatch(argVect); - } - - template - bool doArgsMatch(const ArgumentRefVector & /*unused*/) const { - return true; - } - - bool doAnyArgsMatch(const ArgumentRefVector &argVect) const { - using AnyArgsType = typename std::tuple_element_t<0, std::tuple>; - - return stdr::all_of(argVect, [](const auto &arg) { - return is(arg); - }); - } - -private: -#if !defined(I_FUNCTION_CRTP) && !defined(NDEBUG) -}; -} - -#endif // I_FUNCTION_CRTP diff --git a/include/fintamath/functions/IOperator.hpp b/include/fintamath/functions/IOperator.hpp deleted file mode 100644 index 8f8e21dfe..000000000 --- a/include/fintamath/functions/IOperator.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/Parser.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class IOperator : public IFunction { - FINTAMATH_PARENT_CLASS_BODY(IOperator) - -public: - enum class Priority : uint8_t { - Exponentiation, // e.g. a ^ b - PostfixUnary, // e.g. a! - PrefixUnary, // e.g. -a - Multiplication, // e.g. a * b - Addition, // e.g. a + b - Modulo, // e.g. a mod b - Comparison, // e.g. a = b - Conjunction, // e.g. a & b - Disjunction, // e.g. a | b - Implication, // e.g. a -> b - Equivalence, // e.g. a <-> b - Comma, // e.g. a , b - }; - -public: - virtual Priority getPriority() const = 0; - - virtual bool isAssociative() const = 0; -}; - -template - requires(sizeof...(Args) > 0 && sizeof...(Args) < 3) -class IOperatorCRTP : public IOperator { -#define I_OPERATOR_CRTP IOperatorCRTP -#include "fintamath/functions/IOperatorCRTP.hpp" -#undef I_OPERATOR_CRTP -}; - -} diff --git a/include/fintamath/functions/IOperatorCRTP.hpp b/include/fintamath/functions/IOperatorCRTP.hpp deleted file mode 100644 index 7b7dc4906..000000000 --- a/include/fintamath/functions/IOperatorCRTP.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#if !defined(I_OPERATOR_CRTP) && !defined(NDEBUG) - -#include "fintamath/functions/IOperator.hpp" - -namespace fintamath { - -template -class IOperatorCRTP_ : public IOperator { - -#endif // I_OPERATOR_CRTP - -#define I_FUNCTION_CRTP I_OPERATOR_CRTP -#include "fintamath/functions/IFunctionCRTP.hpp" -#undef I_FUNCTION_CRTP - -public: - IOperator::Priority getPriority() const final { - return Derived::getPriorityStatic(); - } - - static constexpr bool isAssociativeStatic() { - return false; - } - - bool isAssociative() const final { - return Derived::isAssociativeStatic(); - } - -private: -#if !defined(I_OPERATOR_CRTP) && !defined(NDEBUG) -}; -} - -#endif // I_OPERATOR_CRTP diff --git a/include/fintamath/functions/arithmetic/Abs.hpp b/include/fintamath/functions/arithmetic/Abs.hpp deleted file mode 100644 index 2ab8df6c3..000000000 --- a/include/fintamath/functions/arithmetic/Abs.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Abs final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Abs) - -public: - std::string toString() const override { - return "abs"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - 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 deleted file mode 100644 index 310593bbd..000000000 --- a/include/fintamath/functions/arithmetic/Add.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" - -namespace fintamath { - -class Add final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Add) - -public: - std::string toString() const override { - return "+"; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Addition; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Add, addExpr); - -} diff --git a/include/fintamath/functions/arithmetic/Div.hpp b/include/fintamath/functions/arithmetic/Div.hpp deleted file mode 100644 index 7d9a47fff..000000000 --- a/include/fintamath/functions/arithmetic/Div.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" - -namespace fintamath { - -class Integer; -class INumber; - -class Div final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Div) - -public: - std::string toString() const override { - return "/"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Multiplication; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Div, divExpr); - -} diff --git a/include/fintamath/functions/arithmetic/Frac.hpp b/include/fintamath/functions/arithmetic/Frac.hpp deleted file mode 100644 index 09fb77def..000000000 --- a/include/fintamath/functions/arithmetic/Frac.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class Frac final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Frac) - -public: - std::string toString() const override { - return "frac"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -} diff --git a/include/fintamath/functions/arithmetic/FracMixed.hpp b/include/fintamath/functions/arithmetic/FracMixed.hpp deleted file mode 100644 index b828ead4a..000000000 --- a/include/fintamath/functions/arithmetic/FracMixed.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class FracMixed final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(FracMixed) - -public: - std::string toString() const override { - return "frac"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -} diff --git a/include/fintamath/functions/arithmetic/Mul.hpp b/include/fintamath/functions/arithmetic/Mul.hpp deleted file mode 100644 index 6f9103d4f..000000000 --- a/include/fintamath/functions/arithmetic/Mul.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" - -namespace fintamath { - -class Mul final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Mul) - -public: - std::string toString() const override { - return "*"; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Multiplication; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Mul, mulExpr); - -} diff --git a/include/fintamath/functions/arithmetic/Neg.hpp b/include/fintamath/functions/arithmetic/Neg.hpp deleted file mode 100644 index 52b593f34..000000000 --- a/include/fintamath/functions/arithmetic/Neg.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" - -namespace fintamath { - -class Neg final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Neg) - -public: - std::string toString() const override { - return "-"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::PrefixUnary; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Neg, negExpr); - -} diff --git a/include/fintamath/functions/arithmetic/Sign.hpp b/include/fintamath/functions/arithmetic/Sign.hpp deleted file mode 100644 index 475c8109d..000000000 --- a/include/fintamath/functions/arithmetic/Sign.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Sign final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Sign) - -public: - std::string toString() const override { - return "sign"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - 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 deleted file mode 100644 index 91239303d..000000000 --- a/include/fintamath/functions/arithmetic/Sub.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" - -namespace fintamath { - -class Sub final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Sub) - -public: - std::string toString() const override { - return "-"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Addition; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Sub, subExpr); - -} diff --git a/include/fintamath/functions/arithmetic/UnaryPlus.hpp b/include/fintamath/functions/arithmetic/UnaryPlus.hpp deleted file mode 100644 index 172f48735..000000000 --- a/include/fintamath/functions/arithmetic/UnaryPlus.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IOperator.hpp" - -namespace fintamath { - -class UnaryPlus final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(UnaryPlus) - -public: - std::string toString() const override { - return "+"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::PrefixUnary; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -} diff --git a/include/fintamath/functions/calculus/Derivative.hpp b/include/fintamath/functions/calculus/Derivative.hpp deleted file mode 100644 index a924a9646..000000000 --- a/include/fintamath/functions/calculus/Derivative.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/literals/Variable.hpp" - -namespace fintamath { - -class Derivative final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Derivative) - -public: - std::string toString() const override { - return "derivative"; - } - - static constexpr bool isEvaluatableStatic() { - return false; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Derivative, derivativeExpr); - -} diff --git a/include/fintamath/functions/calculus/Integral.hpp b/include/fintamath/functions/calculus/Integral.hpp deleted file mode 100644 index deaae948f..000000000 --- a/include/fintamath/functions/calculus/Integral.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/literals/Variable.hpp" - -namespace fintamath { - -class Integral final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Integral) - -public: - std::string toString() const override { - return "integral"; - } - - static constexpr bool isEvaluatableStatic() { - return false; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Integral, integralExpr); - -} diff --git a/include/fintamath/functions/calculus/Max.hpp b/include/fintamath/functions/calculus/Max.hpp deleted file mode 100644 index 5d491dafb..000000000 --- a/include/fintamath/functions/calculus/Max.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class Max final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Max) - -public: - std::string toString() const override { - return "max"; - } - - static constexpr bool isVariadicStatic() { - return true; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Max, maxExpr); - -} diff --git a/include/fintamath/functions/calculus/Min.hpp b/include/fintamath/functions/calculus/Min.hpp deleted file mode 100644 index d42a205b7..000000000 --- a/include/fintamath/functions/calculus/Min.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class Min final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Min) - -public: - std::string toString() const override { - return "min"; - } - - static constexpr bool isVariadicStatic() { - return true; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Min, minExpr); - -} diff --git a/include/fintamath/functions/comparison/Eqv.hpp b/include/fintamath/functions/comparison/Eqv.hpp deleted file mode 100644 index 3b115b6b3..000000000 --- a/include/fintamath/functions/comparison/Eqv.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -class Eqv final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Eqv) - -public: - std::string toString() const override { - return "="; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Comparison; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Eqv, eqvExpr); - -} diff --git a/include/fintamath/functions/comparison/Less.hpp b/include/fintamath/functions/comparison/Less.hpp deleted file mode 100644 index d720206c0..000000000 --- a/include/fintamath/functions/comparison/Less.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -class Less final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Less) - -public: - std::string toString() const override { - return "<"; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Comparison; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Less, lessExpr); - -} diff --git a/include/fintamath/functions/comparison/LessEqv.hpp b/include/fintamath/functions/comparison/LessEqv.hpp deleted file mode 100644 index 639d28a78..000000000 --- a/include/fintamath/functions/comparison/LessEqv.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -class LessEqv final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(LessEqv) - -public: - std::string toString() const override { - return "<="; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Comparison; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(LessEqv, lessEqvExpr); - -} diff --git a/include/fintamath/functions/comparison/More.hpp b/include/fintamath/functions/comparison/More.hpp deleted file mode 100644 index aab27c8ba..000000000 --- a/include/fintamath/functions/comparison/More.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -class More final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(More) - -public: - std::string toString() const override { - return ">"; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Comparison; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(More, moreExpr); - -} diff --git a/include/fintamath/functions/comparison/MoreEqv.hpp b/include/fintamath/functions/comparison/MoreEqv.hpp deleted file mode 100644 index 954edfbfb..000000000 --- a/include/fintamath/functions/comparison/MoreEqv.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -class MoreEqv final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(MoreEqv) - -public: - std::string toString() const override { - return ">="; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Comparison; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(MoreEqv, moreEqvExpr); - -} diff --git a/include/fintamath/functions/comparison/Neqv.hpp b/include/fintamath/functions/comparison/Neqv.hpp deleted file mode 100644 index 92324b196..000000000 --- a/include/fintamath/functions/comparison/Neqv.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -class Neqv final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Neqv) - -public: - std::string toString() const override { - return "!="; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Comparison; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Neqv, neqvExpr); - -} diff --git a/include/fintamath/functions/hyperbolic/Acosh.hpp b/include/fintamath/functions/hyperbolic/Acosh.hpp deleted file mode 100644 index ed67c828e..000000000 --- a/include/fintamath/functions/hyperbolic/Acosh.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Acosh final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Acosh) - -public: - std::string toString() const override { - return "acosh"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiAcoshSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Acosh, acoshExpr); - -} diff --git a/include/fintamath/functions/hyperbolic/Acoth.hpp b/include/fintamath/functions/hyperbolic/Acoth.hpp deleted file mode 100644 index 2b0aafe95..000000000 --- a/include/fintamath/functions/hyperbolic/Acoth.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Acoth final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Acoth) - -public: - std::string toString() const override { - return "acoth"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiAcothSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Acoth, acothExpr); - -} diff --git a/include/fintamath/functions/hyperbolic/Acsch.hpp b/include/fintamath/functions/hyperbolic/Acsch.hpp deleted file mode 100644 index 523e6fd4c..000000000 --- a/include/fintamath/functions/hyperbolic/Acsch.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Acsch final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Acsch) - -public: - std::string toString() const override { - return "acsch"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiAcschSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Acsch, acschExpr); - -} diff --git a/include/fintamath/functions/hyperbolic/Asech.hpp b/include/fintamath/functions/hyperbolic/Asech.hpp deleted file mode 100644 index 7e1eba0dd..000000000 --- a/include/fintamath/functions/hyperbolic/Asech.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Asech final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Asech) - -public: - std::string toString() const override { - return "asech"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiAsechSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Asech, asechExpr); - -} diff --git a/include/fintamath/functions/hyperbolic/Asinh.hpp b/include/fintamath/functions/hyperbolic/Asinh.hpp deleted file mode 100644 index 551861a8d..000000000 --- a/include/fintamath/functions/hyperbolic/Asinh.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Asinh final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Asinh) - -public: - std::string toString() const override { - return "asinh"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - 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 deleted file mode 100644 index a6cf9eb1d..000000000 --- a/include/fintamath/functions/hyperbolic/Atanh.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Atanh final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Atanh) - -public: - std::string toString() const override { - return "atanh"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiAtanhSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Atanh, atanhExpr); - -} diff --git a/include/fintamath/functions/hyperbolic/Cosh.hpp b/include/fintamath/functions/hyperbolic/Cosh.hpp deleted file mode 100644 index 56c28aea3..000000000 --- a/include/fintamath/functions/hyperbolic/Cosh.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Cosh final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Cosh) - -public: - std::string toString() const override { - return "cosh"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - 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 deleted file mode 100644 index ce9427450..000000000 --- a/include/fintamath/functions/hyperbolic/Coth.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Coth final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Coth) - -public: - std::string toString() const override { - return "coth"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiCothSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Coth, cothExpr); - -} diff --git a/include/fintamath/functions/hyperbolic/Csch.hpp b/include/fintamath/functions/hyperbolic/Csch.hpp deleted file mode 100644 index ee54f4c2b..000000000 --- a/include/fintamath/functions/hyperbolic/Csch.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Csch final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Csch) - -public: - std::string toString() const override { - return "csch"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiCschSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Csch, cschExpr); - -} diff --git a/include/fintamath/functions/hyperbolic/Sech.hpp b/include/fintamath/functions/hyperbolic/Sech.hpp deleted file mode 100644 index f6ed88872..000000000 --- a/include/fintamath/functions/hyperbolic/Sech.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Sech final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Sech) - -public: - std::string toString() const override { - return "sech"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiSechSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Sech, sechExpr); - -} diff --git a/include/fintamath/functions/hyperbolic/Sinh.hpp b/include/fintamath/functions/hyperbolic/Sinh.hpp deleted file mode 100644 index 8331e9516..000000000 --- a/include/fintamath/functions/hyperbolic/Sinh.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Sinh final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Sinh) - -public: - std::string toString() const override { - return "sinh"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - 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 deleted file mode 100644 index fb2886ed3..000000000 --- a/include/fintamath/functions/hyperbolic/Tanh.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Tanh final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Tanh) - -public: - std::string toString() const override { - return "tanh"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - 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 deleted file mode 100644 index d90568704..000000000 --- a/include/fintamath/functions/logarithms/Lb.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Lb final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Lb) - -public: - std::string toString() const override { - return "lb"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Lb, lbExpr); - -} diff --git a/include/fintamath/functions/logarithms/Lg.hpp b/include/fintamath/functions/logarithms/Lg.hpp deleted file mode 100644 index b3ff5c05f..000000000 --- a/include/fintamath/functions/logarithms/Lg.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Lg final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Lg) - -public: - std::string toString() const override { - return "lg"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Lg, lgExpr); - -} diff --git a/include/fintamath/functions/logarithms/Ln.hpp b/include/fintamath/functions/logarithms/Ln.hpp deleted file mode 100644 index fb05931e7..000000000 --- a/include/fintamath/functions/logarithms/Ln.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Ln final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Ln) - -public: - std::string toString() const override { - return "ln"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - 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 deleted file mode 100644 index 12c6fb427..000000000 --- a/include/fintamath/functions/logarithms/Log.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -class Log final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Log) - -public: - std::string toString() const override { - return "log"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - - static std::unique_ptr multiLogSimplify(const INumber &lhs, const INumber &rhs); - - static std::unique_ptr logSimplify(const Integer &lhs, const Integer &rhs); - - static std::unique_ptr logSimplify(const Rational &lhs, const Rational &rhs); - - 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 deleted file mode 100644 index 19670ded5..000000000 --- a/include/fintamath/functions/logic/And.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -class And final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(And) - -public: - std::string toString() const override { - return "&"; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Conjunction; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(And, andExpr); - -} diff --git a/include/fintamath/functions/logic/Equiv.hpp b/include/fintamath/functions/logic/Equiv.hpp deleted file mode 100644 index 2022f5e26..000000000 --- a/include/fintamath/functions/logic/Equiv.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -class Equiv final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Equiv) - -public: - std::string toString() const override { - return "<->"; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Equivalence; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Equiv, equivExpr); - -} diff --git a/include/fintamath/functions/logic/Impl.hpp b/include/fintamath/functions/logic/Impl.hpp deleted file mode 100644 index 8b8598b0a..000000000 --- a/include/fintamath/functions/logic/Impl.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -class Impl final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Impl) - -public: - std::string toString() const override { - return "->"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Implication; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Impl, implExpr); - -} diff --git a/include/fintamath/functions/logic/Nequiv.hpp b/include/fintamath/functions/logic/Nequiv.hpp deleted file mode 100644 index 41f5fa9d9..000000000 --- a/include/fintamath/functions/logic/Nequiv.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -class Nequiv final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Nequiv) - -public: - std::string toString() const override { - return "!<->"; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Equivalence; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Nequiv, nequivExpr); - -} diff --git a/include/fintamath/functions/logic/Not.hpp b/include/fintamath/functions/logic/Not.hpp deleted file mode 100644 index 768a75251..000000000 --- a/include/fintamath/functions/logic/Not.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -class Not final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Not) - -public: - std::string toString() const override { - return "~"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::PrefixUnary; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Not, notExpr); - -} diff --git a/include/fintamath/functions/logic/Or.hpp b/include/fintamath/functions/logic/Or.hpp deleted file mode 100644 index d49a3b0eb..000000000 --- a/include/fintamath/functions/logic/Or.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -class Or final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Or) - -public: - std::string toString() const override { - return "|"; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Disjunction; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Or, orExpr); - -} diff --git a/include/fintamath/functions/ntheory/Ceil.hpp b/include/fintamath/functions/ntheory/Ceil.hpp deleted file mode 100644 index cf41064f9..000000000 --- a/include/fintamath/functions/ntheory/Ceil.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Ceil final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Ceil) - -public: - std::string toString() const override { - return "ceil"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiCeilSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Ceil, ceilExpr); - -} diff --git a/include/fintamath/functions/ntheory/Floor.hpp b/include/fintamath/functions/ntheory/Floor.hpp deleted file mode 100644 index 9344450dd..000000000 --- a/include/fintamath/functions/ntheory/Floor.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Floor final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Floor) - -public: - std::string toString() const override { - return "floor"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiFloorSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Floor, floorExpr); - -} diff --git a/include/fintamath/functions/ntheory/Mod.hpp b/include/fintamath/functions/ntheory/Mod.hpp deleted file mode 100644 index a581023b1..000000000 --- a/include/fintamath/functions/ntheory/Mod.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Mod final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Mod) - -public: - std::string toString() const override { - return "mod"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Modulo; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiModSimplify(const INumber &lhs, const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Mod, modExpr); - -} diff --git a/include/fintamath/functions/other/Comma.hpp b/include/fintamath/functions/other/Comma.hpp deleted file mode 100644 index 7ac4fd0b1..000000000 --- a/include/fintamath/functions/other/Comma.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" - -namespace fintamath { - -class Comma final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Comma) - -public: - std::string toString() const override { - return ","; - } - - static constexpr bool isAssociativeStatic() { - return true; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Comma; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Comma, commaExpr); - -} diff --git a/include/fintamath/functions/other/Deg.hpp b/include/fintamath/functions/other/Deg.hpp deleted file mode 100644 index 0044c627a..000000000 --- a/include/fintamath/functions/other/Deg.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Deg final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Deg) - -public: - std::string toString() const override { - return "deg"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::PostfixUnary; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Deg, degExpr); - -} diff --git a/include/fintamath/functions/other/Factorial.hpp b/include/fintamath/functions/other/Factorial.hpp deleted file mode 100644 index 4305359b5..000000000 --- a/include/fintamath/functions/other/Factorial.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Integer; -class Rational; -class Real; - -class Factorial final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Factorial) - -public: - Factorial() = default; - - explicit Factorial(const size_t inOrder) : Factorial() { - setOrder(inOrder); - } - - std::string toString() const override { - return std::string(order, '!'); - } - - static constexpr Priority getPriorityStatic() { - return Priority::PostfixUnary; - } - - size_t getOrder() const { - return order; - } - - void setOrder(const size_t inOrder) { - assert(inOrder > 0); - order = inOrder; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiFactorialSimplify(const INumber &lhs, size_t order); - - static std::unique_ptr factorialSimplify(const Integer &rhs, size_t order); - - static std::unique_ptr factorialSimplify(const Rational &rhs, size_t order); - - static std::unique_ptr factorialSimplify(const Real &rhs, size_t order); - -private: - 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 deleted file mode 100644 index bea96eec9..000000000 --- a/include/fintamath/functions/other/Index.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -class Index final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Index) - -public: - std::string toString() const override { - return "_"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Exponentiation; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Index, indexExpr); - -} diff --git a/include/fintamath/functions/other/Percent.hpp b/include/fintamath/functions/other/Percent.hpp deleted file mode 100644 index ad55fcf73..000000000 --- a/include/fintamath/functions/other/Percent.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Percent final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Percent) - -public: - std::string toString() const override { - return "%"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::PostfixUnary; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Percent, percentExpr); - -} diff --git a/include/fintamath/functions/powers/Exp.hpp b/include/fintamath/functions/powers/Exp.hpp deleted file mode 100644 index c4e389b0b..000000000 --- a/include/fintamath/functions/powers/Exp.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Exp final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Exp) - -public: - std::string toString() const override { - return "exp"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Exp, expExpr); - -} diff --git a/include/fintamath/functions/powers/Pow.hpp b/include/fintamath/functions/powers/Pow.hpp deleted file mode 100644 index 9c34f396d..000000000 --- a/include/fintamath/functions/powers/Pow.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Integer; -class Rational; -class Real; -class Complex; - -class Pow final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(Pow) - -public: - std::string toString() const override { - return "^"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Exponentiation; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiPowSimplify(const INumber &lhs, const INumber &rhs); - - static std::unique_ptr powSimplify(const Integer &lhs, const Integer &rhs); - - static std::unique_ptr powSimplify(const Rational &lhs, const Rational &rhs); - - static std::unique_ptr powSimplify(const Real &lhs, const Real &rhs); - - static std::unique_ptr powSimplify(const Complex &lhs, const Complex &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Pow, powExpr); - -} diff --git a/include/fintamath/functions/powers/PowFunction.hpp b/include/fintamath/functions/powers/PowFunction.hpp deleted file mode 100644 index f071108e0..000000000 --- a/include/fintamath/functions/powers/PowFunction.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class PowFunction final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(PowFunction) - -public: - std::string toString() const override { - return "pow"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -} diff --git a/include/fintamath/functions/powers/Root.hpp b/include/fintamath/functions/powers/Root.hpp deleted file mode 100644 index 05b77fe01..000000000 --- a/include/fintamath/functions/powers/Root.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Integer; -class Rational; -class Real; - -class Root final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Root) - - using RootToFactorMap = std::map; - -public: - std::string toString() const override { - return "root"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiRootSimplify(const INumber &lhs, const INumber &rhs); - - static std::unique_ptr rootSimplify(const Integer &lhs, const Integer &rhs); - - static std::unique_ptr rootSimplify(const Rational &lhs, const Integer &rhs); - - static std::unique_ptr rootSimplify(const Real &lhs, const Integer &rhs); - - static RootToFactorMap roots(const Integer &lhs, const Integer &rhs); - - static std::unique_ptr perfectRoot(const Integer &lhs, const Integer &rhs); - - static Integer extractFirstFactor(RootToFactorMap &rootToFactorMap); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Root, rootExpr); - -} diff --git a/include/fintamath/functions/powers/Sqr.hpp b/include/fintamath/functions/powers/Sqr.hpp deleted file mode 100644 index a53051db4..000000000 --- a/include/fintamath/functions/powers/Sqr.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Sqr final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Sqr) - -public: - std::string toString() const override { - return "sqr"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Sqr, sqrExpr); - -} diff --git a/include/fintamath/functions/powers/Sqrt.hpp b/include/fintamath/functions/powers/Sqrt.hpp deleted file mode 100644 index 1d360cb8a..000000000 --- a/include/fintamath/functions/powers/Sqrt.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Sqrt final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Sqrt) - -public: - std::string toString() const override { - return "sqrt"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; -}; - -FINTAMATH_FUNCTION_EXPRESSION(Sqrt, sqrtExpr); - -} diff --git a/include/fintamath/functions/trigonometry/Acos.hpp b/include/fintamath/functions/trigonometry/Acos.hpp deleted file mode 100644 index 65eea4330..000000000 --- a/include/fintamath/functions/trigonometry/Acos.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Acos final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Acos) - -public: - std::string toString() const override { - return "acos"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiAcosSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Acos, acosExpr); - -} diff --git a/include/fintamath/functions/trigonometry/Acot.hpp b/include/fintamath/functions/trigonometry/Acot.hpp deleted file mode 100644 index 6729bb50e..000000000 --- a/include/fintamath/functions/trigonometry/Acot.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Acot final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Acot) - -public: - std::string toString() const override { - return "acot"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiAcotSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Acot, acotExpr); - -} diff --git a/include/fintamath/functions/trigonometry/Acsc.hpp b/include/fintamath/functions/trigonometry/Acsc.hpp deleted file mode 100644 index 816199d74..000000000 --- a/include/fintamath/functions/trigonometry/Acsc.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Acsc final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Acsc) - -public: - std::string toString() const override { - return "acsc"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiAcscSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Acsc, acscExpr); - -} diff --git a/include/fintamath/functions/trigonometry/Asec.hpp b/include/fintamath/functions/trigonometry/Asec.hpp deleted file mode 100644 index 85030f466..000000000 --- a/include/fintamath/functions/trigonometry/Asec.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Asec final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Asec) - -public: - std::string toString() const override { - return "asec"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiAsecSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Asec, asecExpr); - -} diff --git a/include/fintamath/functions/trigonometry/Asin.hpp b/include/fintamath/functions/trigonometry/Asin.hpp deleted file mode 100644 index df451eb8b..000000000 --- a/include/fintamath/functions/trigonometry/Asin.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Asin final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Asin) - -public: - std::string toString() const override { - return "asin"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiAsinSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Asin, asinExpr); - -} diff --git a/include/fintamath/functions/trigonometry/Atan.hpp b/include/fintamath/functions/trigonometry/Atan.hpp deleted file mode 100644 index 86f70c35d..000000000 --- a/include/fintamath/functions/trigonometry/Atan.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Atan final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Atan) - -public: - std::string toString() const override { - return "atan"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - 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 deleted file mode 100644 index 29f5c7193..000000000 --- a/include/fintamath/functions/trigonometry/Cos.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Cos final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Cos) - -public: - std::string toString() const override { - return "cos"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiCosSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Cos, cosExpr); - -} diff --git a/include/fintamath/functions/trigonometry/Cot.hpp b/include/fintamath/functions/trigonometry/Cot.hpp deleted file mode 100644 index dbb785145..000000000 --- a/include/fintamath/functions/trigonometry/Cot.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Cot final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Cot) - -public: - std::string toString() const override { - return "cot"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiCotSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Cot, cotExpr); - -} diff --git a/include/fintamath/functions/trigonometry/Csc.hpp b/include/fintamath/functions/trigonometry/Csc.hpp deleted file mode 100644 index b459c02d2..000000000 --- a/include/fintamath/functions/trigonometry/Csc.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Csc final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Csc) - -public: - std::string toString() const override { - return "csc"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiCscSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Csc, cscExpr); - -} diff --git a/include/fintamath/functions/trigonometry/Sec.hpp b/include/fintamath/functions/trigonometry/Sec.hpp deleted file mode 100644 index 90d31543c..000000000 --- a/include/fintamath/functions/trigonometry/Sec.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Sec final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Sec) - -public: - std::string toString() const override { - return "sec"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiSecSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Sec, secExpr); - -} diff --git a/include/fintamath/functions/trigonometry/Sin.hpp b/include/fintamath/functions/trigonometry/Sin.hpp deleted file mode 100644 index 34c761adc..000000000 --- a/include/fintamath/functions/trigonometry/Sin.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Sin final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Sin) - -public: - std::string toString() const override { - return "sin"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - 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 deleted file mode 100644 index 0ef5bde12..000000000 --- a/include/fintamath/functions/trigonometry/Tan.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Real; - -class Tan final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(Tan) - -public: - std::string toString() const override { - return "tan"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override; - -private: - static std::unique_ptr multiTanSimplify(const INumber &rhs); -}; - -FINTAMATH_FUNCTION_EXPRESSION(Tan, tanExpr); - -} diff --git a/include/fintamath/literals/Boolean.hpp b/include/fintamath/literals/Boolean.hpp deleted file mode 100644 index 7c752d389..000000000 --- a/include/fintamath/literals/Boolean.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/literals/ILiteral.hpp" - -namespace fintamath { - -class Boolean final : public ILiteralCRTP { - FINTAMATH_CLASS_BODY(Boolean) - -public: - Boolean(); - - explicit Boolean(const std::string &str); - - template Bool> - Boolean(const Bool val) : name(val ? trueStr : falseStr) { - } - - std::string toString() const override; - - explicit operator bool() const; - -private: - std::string name; - - static constexpr std::string_view trueStr = "True"; - - static constexpr std::string_view falseStr = "False"; -}; - -} diff --git a/include/fintamath/literals/ILiteral.hpp b/include/fintamath/literals/ILiteral.hpp deleted file mode 100644 index 9b9b7fc97..000000000 --- a/include/fintamath/literals/ILiteral.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/Parser.hpp" - -namespace fintamath { - -class ILiteral : public IMathObject { - FINTAMATH_PARENT_CLASS_BODY(ILiteral) -}; - -template -class ILiteralCRTP : public ILiteral { -#define I_LITERAL_CRTP ILiteralCRTP -#include "fintamath/literals/ILiteralCRTP.hpp" -#undef I_LITERAL_CRTP -}; - -} \ No newline at end of file diff --git a/include/fintamath/literals/ILiteralCRTP.hpp b/include/fintamath/literals/ILiteralCRTP.hpp deleted file mode 100644 index 459d37e81..000000000 --- a/include/fintamath/literals/ILiteralCRTP.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#if !defined(I_LITERAL_CRTP) && !defined(NDEBUG) - -#include "fintamath/literals/ILiteral.hpp" - -namespace fintamath { - -template -class ILiteralCRTP_ : public ILiteral { - -#endif // I_LITERAL_CRTP - -#define I_MATH_OBJECT_CRTP I_LITERAL_CRTP -#include "fintamath/core/IMathObjectCRTP.hpp" -#undef I_MATH_OBJECT_CRTP - -private: -#if !defined(I_LITERAL_CRTP) && !defined(NDEBUG) -}; -} - -#endif // I_LITERAL_CRTP diff --git a/include/fintamath/literals/Variable.hpp b/include/fintamath/literals/Variable.hpp deleted file mode 100644 index a879e6fb9..000000000 --- a/include/fintamath/literals/Variable.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/literals/ILiteral.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -class Variable final : public ILiteralCRTP { - FINTAMATH_CLASS_BODY(Variable) - -public: - explicit Variable(std::string inName); - - explicit Variable(std::string inName, Integer inIndex); - - std::string toString() const override; - -private: - std::string name; - - Integer index = -1; -}; - -} \ No newline at end of file diff --git a/include/fintamath/literals/constants/ComplexInf.hpp b/include/fintamath/literals/constants/ComplexInf.hpp deleted file mode 100644 index 80ae57ed1..000000000 --- a/include/fintamath/literals/constants/ComplexInf.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/literals/constants/IConstant.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class ComplexInf final : public IConstantCRTP { - FINTAMATH_CLASS_BODY(ComplexInf) - -public: - std::string toString() const override { - return "ComplexInf"; - } - -protected: - std::unique_ptr call() const override; -}; - -} diff --git a/include/fintamath/literals/constants/E.hpp b/include/fintamath/literals/constants/E.hpp deleted file mode 100644 index 50eb52f50..000000000 --- a/include/fintamath/literals/constants/E.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/literals/constants/IConstant.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -class E final : public IConstantCRTP { - FINTAMATH_CLASS_BODY(E) - -public: - std::string toString() const override { - return "E"; - } - -protected: - std::unique_ptr call() const override; -}; - -} diff --git a/include/fintamath/literals/constants/False.hpp b/include/fintamath/literals/constants/False.hpp deleted file mode 100644 index 44f565456..000000000 --- a/include/fintamath/literals/constants/False.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/constants/IConstant.hpp" - -namespace fintamath { - -class False final : public IConstantCRTP { - FINTAMATH_CLASS_BODY(False) - -public: - std::string toString() const override { - return Boolean(false).toString(); - } - -protected: - std::unique_ptr call() const override; -}; - -} diff --git a/include/fintamath/literals/constants/I.hpp b/include/fintamath/literals/constants/I.hpp deleted file mode 100644 index 23805d11d..000000000 --- a/include/fintamath/literals/constants/I.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/literals/constants/IConstant.hpp" -#include "fintamath/numbers/Complex.hpp" - -namespace fintamath { - -class I final : public IConstantCRTP { - FINTAMATH_CLASS_BODY(I) - -public: - std::string toString() const override { - return "I"; - } - -protected: - std::unique_ptr call() const override; -}; - -} diff --git a/include/fintamath/literals/constants/IConstant.hpp b/include/fintamath/literals/constants/IConstant.hpp deleted file mode 100644 index b641d5fcc..000000000 --- a/include/fintamath/literals/constants/IConstant.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/Parser.hpp" -#include "fintamath/literals/ILiteral.hpp" - -namespace fintamath { - -class IConstant : public ILiteral { - FINTAMATH_PARENT_CLASS_BODY(IConstant) - -public: - virtual MathObjectClass getReturnClass() const = 0; - - std::unique_ptr operator()() const { - return call(); - } - -protected: - virtual std::unique_ptr call() const = 0; -}; - -template -class IConstantCRTP : public IConstant { -#define I_CONSTANT_CRTP IConstantCRTP -#include "fintamath/literals/constants/IConstantCRTP.hpp" -#undef I_CONSTANT_CRTP -}; - -} diff --git a/include/fintamath/literals/constants/IConstantCRTP.hpp b/include/fintamath/literals/constants/IConstantCRTP.hpp deleted file mode 100644 index 8e1776ebb..000000000 --- a/include/fintamath/literals/constants/IConstantCRTP.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#if !defined(I_CONSTANT_CRTP) && !defined(NDEBUG) - -#include "fintamath/literals/constants/IConstant.hpp" - -namespace fintamath { - -template -class IConstantCRTP_ : public IConstant { - -#endif // I_CONSTANT_CRTP - -#define I_LITERAL_CRTP I_CONSTANT_CRTP -#include "fintamath/literals/ILiteralCRTP.hpp" -#undef I_LITERAL_CRTP - -public: - static constexpr MathObjectClass getReturnClassStatic() { - return Return::getClassStatic(); - } - - MathObjectClass getReturnClass() const final { - return getReturnClassStatic(); - } - -private: -#if !defined(I_CONSTANT_CRTP) && !defined(NDEBUG) -}; -} - -#endif // I_CONSTANT_CRTP diff --git a/include/fintamath/literals/constants/Inf.hpp b/include/fintamath/literals/constants/Inf.hpp deleted file mode 100644 index 09f0f7141..000000000 --- a/include/fintamath/literals/constants/Inf.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/literals/constants/IConstant.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class Inf final : public IConstantCRTP { - FINTAMATH_CLASS_BODY(Inf) - -public: - std::string toString() const override { - return "Inf"; - } - -protected: - std::unique_ptr call() const override; -}; - -} diff --git a/include/fintamath/literals/constants/NegInf.hpp b/include/fintamath/literals/constants/NegInf.hpp deleted file mode 100644 index aa2aea146..000000000 --- a/include/fintamath/literals/constants/NegInf.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/literals/constants/IConstant.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class NegInf final : public IConstantCRTP { - FINTAMATH_CLASS_BODY(NegInf) - -public: - std::string toString() const override { - return "-Inf"; - } - -protected: - std::unique_ptr call() const override; -}; - -} diff --git a/include/fintamath/literals/constants/Pi.hpp b/include/fintamath/literals/constants/Pi.hpp deleted file mode 100644 index b586cfc78..000000000 --- a/include/fintamath/literals/constants/Pi.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/literals/constants/IConstant.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -class Pi final : public IConstantCRTP { - FINTAMATH_CLASS_BODY(Pi) - -public: - std::string toString() const override { - return "Pi"; - } - -protected: - std::unique_ptr call() const override; -}; - -} diff --git a/include/fintamath/literals/constants/True.hpp b/include/fintamath/literals/constants/True.hpp deleted file mode 100644 index 5fc092b39..000000000 --- a/include/fintamath/literals/constants/True.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/constants/IConstant.hpp" - -namespace fintamath { - -class True final : public IConstantCRTP { - FINTAMATH_CLASS_BODY(True) - -public: - std::string toString() const override { - return Boolean(true).toString(); - } - -protected: - std::unique_ptr call() const override; -}; - -} diff --git a/include/fintamath/literals/constants/Undefined.hpp b/include/fintamath/literals/constants/Undefined.hpp deleted file mode 100644 index 116f4427d..000000000 --- a/include/fintamath/literals/constants/Undefined.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/literals/constants/IConstant.hpp" - -namespace fintamath { - -class Undefined final : public IConstantCRTP { - FINTAMATH_CLASS_BODY(Undefined) - -public: - std::string toString() const override { - return "Undefined"; - } - -protected: - std::unique_ptr call() const override; -}; - -} diff --git a/include/fintamath/numbers/Complex.hpp b/include/fintamath/numbers/Complex.hpp deleted file mode 100644 index e34bfde6a..000000000 --- a/include/fintamath/numbers/Complex.hpp +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -class Complex final : public INumberCRTP { - FINTAMATH_CLASS_BODY(Complex) - -public: - Complex() = default; - - Complex(const Complex &rhs); - - Complex(Complex &&rhs) noexcept = default; - - Complex &operator=(const Complex &rhs); - - Complex &operator=(Complex &&rhs) noexcept = default; - - explicit Complex(const std::string &str); - - explicit Complex(const INumber &inReal, const INumber &inImag); - - explicit Complex(int64_t inReal, int64_t inImag); - - Complex(const Integer &rhs); - - Complex(const Rational &rhs); - - Complex(const Real &rhs); - - Complex(int64_t rhs); - - std::string toString() const override; - - std::unique_ptr toMinimalObject() const override; - - bool isPrecise() const override; - - bool isComplex() const override; - - const INumber &real() const; - - const INumber &imag() const; - -protected: - bool equals(const Complex &rhs) const override; - - std::strong_ordering compare(const Complex &rhs) const override; - - Complex &add(const Complex &rhs) override; - - Complex &substract(const Complex &rhs) override; - - Complex &multiply(const Complex &rhs) override; - - Complex ÷(const Complex &rhs) override; - - Complex &negate() override; - -private: - static std::unique_ptr parseNonComplexNumber(const std::string &str); - -private: - std::unique_ptr re = std::make_unique(0); - - std::unique_ptr im = std::make_unique(0); -}; - -} diff --git a/include/fintamath/numbers/IInteger.hpp b/include/fintamath/numbers/IInteger.hpp deleted file mode 100644 index 93f4fe2db..000000000 --- a/include/fintamath/numbers/IInteger.hpp +++ /dev/null @@ -1,183 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/Parser.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class IInteger : public INumber { - FINTAMATH_PARENT_CLASS_BODY(IInteger) - -public: - friend std::unique_ptr operator%(const IInteger &lhs, const IInteger &rhs) { - return lhs.modAbstract(rhs); - } - - friend std::unique_ptr operator&(const IInteger &lhs, const IInteger &rhs) { - return lhs.bitAndAbstract(rhs); - } - - friend std::unique_ptr operator|(const IInteger &lhs, const IInteger &rhs) { - return lhs.bitOrAbstract(rhs); - } - - friend std::unique_ptr operator^(const IInteger &lhs, const IInteger &rhs) { - return lhs.bitXorAbstract(rhs); - } - - friend std::unique_ptr operator<<(const IInteger &lhs, const IInteger &rhs) { - return lhs.bitLeftShiftAbstract(rhs); - } - - friend std::unique_ptr operator>>(const IInteger &lhs, const IInteger &rhs) { - return lhs.bitRightShiftAbstract(rhs); - } - - friend std::unique_ptr operator~(const IInteger &rhs) { - return rhs.bitNotAbstract(); - } - - friend IInteger &operator++(IInteger &rhs) { - return rhs.increaseAbstract(); - } - - friend IInteger &operator--(IInteger &rhs) { - return rhs.decreaseAbstract(); - } - - friend std::unique_ptr operator++(IInteger &lhs, int) { - auto res = cast(lhs.clone()); - lhs.increaseAbstract(); - return res; - } - - friend std::unique_ptr operator--(IInteger &lhs, int) { - auto res = cast(lhs.clone()); - lhs.decreaseAbstract(); - return res; - } - -protected: - virtual std::unique_ptr modAbstract(const IInteger &rhs) const = 0; - - virtual std::unique_ptr bitAndAbstract(const IInteger &rhs) const = 0; - - virtual std::unique_ptr bitOrAbstract(const IInteger &rhs) const = 0; - - virtual std::unique_ptr bitXorAbstract(const IInteger &rhs) const = 0; - - virtual std::unique_ptr bitLeftShiftAbstract(const IInteger &rhs) const = 0; - - virtual std::unique_ptr bitRightShiftAbstract(const IInteger &rhs) const = 0; - - virtual std::unique_ptr bitNotAbstract() const = 0; - - virtual IInteger &increaseAbstract() = 0; - - virtual IInteger &decreaseAbstract() = 0; -}; - -template -class IIntegerCRTP : public IInteger { -#define I_INTEGER_CRTP IIntegerCRTP -#include "fintamath/numbers/IIntegerCRTP.hpp" -#undef I_INTEGER_CRTP -}; - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator%=(Lhs &lhs, const Rhs &rhs) { - return lhs %= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator&=(Lhs &lhs, const Rhs &rhs) { - return lhs &= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator|=(Lhs &lhs, const Rhs &rhs) { - return lhs |= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator^=(Lhs &lhs, const Rhs &rhs) { - return lhs ^= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator<<=(Lhs &lhs, const Rhs &rhs) { - return lhs <<= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator>>=(Lhs &lhs, const Rhs &rhs) { - return lhs >>= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator%(const Lhs &lhs, const Rhs &rhs) { - return lhs % Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator%(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) % rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator&(const Lhs &lhs, const Rhs &rhs) { - return lhs & Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator&(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) & rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator|(const Lhs &lhs, const Rhs &rhs) { - return lhs | Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator|(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) | rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator^(const Lhs &lhs, const Rhs &rhs) { - return lhs ^ Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator^(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) ^ rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator<<(const Lhs &lhs, const Rhs &rhs) { - return lhs << Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator<<(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) << rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator>>(const Lhs &lhs, const Rhs &rhs) { - return lhs >> Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator>>(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) >> rhs; -} - -} diff --git a/include/fintamath/numbers/IIntegerCRTP.hpp b/include/fintamath/numbers/IIntegerCRTP.hpp deleted file mode 100644 index 2bb9c02d7..000000000 --- a/include/fintamath/numbers/IIntegerCRTP.hpp +++ /dev/null @@ -1,220 +0,0 @@ -#if !defined(I_INTEGER_CRTP) && !defined(NDEBUG) - -#include "fintamath/numbers/IInteger.hpp" - -namespace fintamath { - -template -class IIntegerCRTP_ : public IInteger { - -#endif // I_INTEGER_CRTP - -#define I_NUMBER_CRTP I_INTEGER_CRTP -#include "fintamath/numbers/INumberCRTP.hpp" -#undef I_NUMBER_CRTP - -public: - Derived &operator%=(const Derived &rhs) { - return mod(rhs); - } - - Derived operator%(const Derived &rhs) const { - return Derived(cast(*this)) %= rhs; - } - - Derived &operator&=(const Derived &rhs) { - return bitAnd(rhs); - } - - Derived operator&(const Derived &rhs) const { - return Derived(cast(*this)) &= rhs; - } - - Derived &operator|=(const Derived &rhs) { - return bitOr(rhs); - } - - Derived operator|(const Derived &rhs) const { - return Derived(cast(*this)) |= rhs; - } - - Derived &operator^=(const Derived &rhs) { - return bitXor(rhs); - } - - Derived operator^(const Derived &rhs) const { - return Derived(cast(*this)) ^= rhs; - } - - Derived &operator<<=(const Derived &rhs) { - return bitLeftShift(rhs); - } - - Derived operator<<(const Derived &rhs) const { - return Derived(cast(*this)) <<= rhs; - } - - Derived &operator>>=(const Derived &rhs) { - return bitRightShift(rhs); - } - - Derived operator>>(const Derived &rhs) const { - return Derived(cast(*this)) >>= rhs; - } - - Derived operator~() const { - Derived tmp = Derived(cast(*this)); - return cast(tmp).bitNot(); - } - - Derived &operator++() { - return increase(); - } - - Derived &operator--() { - return decrease(); - } - - Derived operator++(int) { - auto res = Derived(cast(*this)); - increase(); - return res; - } - - Derived operator--(int) { - auto res = Derived(cast(*this)); - decrease(); - return res; - } - -protected: - virtual Derived &mod(const Derived &rhs) = 0; - - virtual Derived &bitAnd(const Derived &rhs) = 0; - - virtual Derived &bitOr(const Derived &rhs) = 0; - - virtual Derived &bitXor(const Derived &rhs) = 0; - - virtual Derived &bitLeftShift(const Derived &rhs) = 0; - - virtual Derived &bitRightShift(const Derived &rhs) = 0; - - virtual Derived &bitNot() = 0; - - virtual Derived &increase() = 0; - - virtual Derived &decrease() = 0; - - std::unique_ptr modAbstract(const IInteger &inRhs) const override { - return executeAbstract( - "%", inRhs, - [](I_INTEGER_CRTP &lhs, const Derived &rhs) { - return lhs.mod(rhs); - }, - [](const IInteger &lhs, const IInteger &rhs) { - return lhs % rhs; - }); - } - - std::unique_ptr bitAndAbstract(const IInteger &inRhs) const override { - return executeAbstract( - "&", inRhs, - [](I_INTEGER_CRTP &lhs, const Derived &rhs) { - return lhs.bitAnd(rhs); - }, - [](const IInteger &lhs, const IInteger &rhs) { - return lhs & rhs; - }); - } - - std::unique_ptr bitOrAbstract(const IInteger &inRhs) const override { - return executeAbstract( - "|", inRhs, - [](I_INTEGER_CRTP &lhs, const Derived &rhs) { - return lhs.bitOr(rhs); - }, - [](const IInteger &lhs, const IInteger &rhs) { - return lhs | rhs; - }); - } - - std::unique_ptr bitXorAbstract(const IInteger &inRhs) const override { - return executeAbstract( - "^", inRhs, - [](I_INTEGER_CRTP &lhs, const Derived &rhs) { - return lhs.bitXor(rhs); - }, - [](const IInteger &lhs, const IInteger &rhs) { - return lhs ^ rhs; - }); - } - - std::unique_ptr bitLeftShiftAbstract(const IInteger &inRhs) const override { - return executeAbstract( - "<<", inRhs, - [](I_INTEGER_CRTP &lhs, const Derived &rhs) { - return lhs.bitLeftShift(rhs); - }, - [](const IInteger &lhs, const IInteger &rhs) { - return lhs << rhs; - }); - } - - std::unique_ptr bitRightShiftAbstract(const IInteger &inRhs) const override { - return executeAbstract( - ">>", inRhs, - [](I_INTEGER_CRTP &lhs, const Derived &rhs) { - return lhs.bitRightShift(rhs); - }, - [](const IInteger &lhs, const IInteger &rhs) { - return lhs >> rhs; - }); - } - - std::unique_ptr bitNotAbstract() const override { - return std::make_unique(~(*this)); - } - - IInteger &increaseAbstract() override { - increase(); - return *this; - } - - IInteger &decreaseAbstract() override { - decrease(); - return *this; - } - -private: - std::unique_ptr executeAbstract(const std::string &operStr, - const IInteger &rhs, - std::invocable auto callFunc, - std::invocable auto callOper) const { - - if (const auto *rhsPtr = cast(&rhs)) { - auto lhsPtr = cast(clone()); - auto res = callFunc(*lhsPtr, *rhsPtr); - return cast(res.toMinimalObject()); - } - - if (const auto rhsPtr = cast(convert(*this, rhs))) { - auto lhsPtr = cast(clone()); - auto res = callFunc(*lhsPtr, *rhsPtr); - return cast(res.toMinimalObject()); - } - - if (const auto lhsPtr = cast(convert(rhs, *this))) { - auto res = callOper(*lhsPtr, rhs); - return cast(res->toMinimalObject()); - } - - throw InvalidInputBinaryOperatorException(operStr, toString(), rhs.toString()); - } - -private: -#if !defined(I_INTEGER_CRTP) && !defined(NDEBUG) -}; -} - -#endif // I_INTEGER_CRTP diff --git a/include/fintamath/numbers/INumber.hpp b/include/fintamath/numbers/INumber.hpp deleted file mode 100644 index de33d7f0e..000000000 --- a/include/fintamath/numbers/INumber.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/Parser.hpp" - -namespace fintamath { - -class INumber : public IComparable { - FINTAMATH_PARENT_CLASS_BODY(INumber) - -public: - virtual bool isPrecise() const { - return true; - } - - virtual bool isComplex() const { - return false; - } -}; - -inline std::unique_ptr operator+(const INumber &lhs, const INumber &rhs) { - auto res = lhs + cast(rhs); - return cast(std::move(res)); -} - -inline std::unique_ptr operator-(const INumber &lhs, const INumber &rhs) { - auto res = lhs - cast(rhs); - return cast(std::move(res)); -} - -inline std::unique_ptr operator*(const INumber &lhs, const INumber &rhs) { - auto res = lhs * cast(rhs); - return cast(std::move(res)); -} - -inline std::unique_ptr operator/(const INumber &lhs, const INumber &rhs) { - auto res = lhs / cast(rhs); - return cast(std::move(res)); -} - -template Rhs> -std::unique_ptr operator+(const Rhs &rhs) { - return cast(+cast(rhs)); -} - -template Rhs> -std::unique_ptr operator-(const Rhs &rhs) { - return cast(-cast(rhs)); -} - -template -class INumberCRTP : public INumber { -#define I_NUMBER_CRTP INumberCRTP -#include "fintamath/numbers/INumberCRTP.hpp" -#undef I_NUMBER_CRTP -}; - -} diff --git a/include/fintamath/numbers/INumberCRTP.hpp b/include/fintamath/numbers/INumberCRTP.hpp deleted file mode 100644 index 5e4984152..000000000 --- a/include/fintamath/numbers/INumberCRTP.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#if !defined(I_NUMBER_CRTP) && !defined(NDEBUG) - -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -template -class INumberCRTP_ : public INumber { - -#endif // I_NUMBER_CRTP - -#define I_COMPARABLE_CRTP I_NUMBER_CRTP -#include "fintamath/core/IComparableCRTP.hpp" -#undef I_COMPARABLE_CRTP - -private: -#if !defined(I_NUMBER_CRTP) && !defined(NDEBUG) -}; -} - -#endif // I_NUMBER_CRTP diff --git a/include/fintamath/numbers/Integer.hpp b/include/fintamath/numbers/Integer.hpp deleted file mode 100644 index 22690e45a..000000000 --- a/include/fintamath/numbers/Integer.hpp +++ /dev/null @@ -1,98 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/numbers/IInteger.hpp" - -namespace fintamath { - -class Integer final : public IIntegerCRTP { - FINTAMATH_CLASS_BODY(Integer) - -public: - using Backend = boost::multiprecision::mpz_int; - -public: - Integer() = default; - - Integer(Backend inBackend); - - explicit Integer(std::string str); - - explicit Integer(std::integral auto val) : backend(val) { - } - - Integer(int64_t val); - - std::string toString() const override; - - int sign() const; - - const Backend &getBackend() const; - - template - explicit operator T() const { - return backend.convert_to(); - } - -protected: - bool equals(const Integer &rhs) const override; - - std::strong_ordering compare(const Integer &rhs) const override; - - Integer &add(const Integer &rhs) override; - - Integer &substract(const Integer &rhs) override; - - Integer &multiply(const Integer &rhs) override; - - std::unique_ptr multiplyAbstract(const IArithmetic &rhs) const override; - - Integer ÷(const Integer &rhs) override; - - std::unique_ptr divideAbstract(const IArithmetic &rhs) const override; - - Integer &mod(const Integer &rhs) override; - - Integer &bitAnd(const Integer &rhs) override; - - Integer &bitOr(const Integer &rhs) override; - - Integer &bitXor(const Integer &rhs) override; - - Integer &bitLeftShift(const Integer &rhs) override; - - Integer &bitRightShift(const Integer &rhs) override; - - Integer &bitNot() override; - - Integer &negate() override; - - Integer &increase() override; - - Integer &decrease() override; - -private: - Backend backend; -}; - -} - -template <> -struct std::hash { - size_t operator()(const fintamath::Integer &rhs) const noexcept { - using fintamath::detail::Hash; - - return Hash{}(rhs.getBackend()); - } -}; diff --git a/include/fintamath/numbers/IntegerFunctions.hpp b/include/fintamath/numbers/IntegerFunctions.hpp deleted file mode 100644 index bf3dea845..000000000 --- a/include/fintamath/numbers/IntegerFunctions.hpp +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -using FactorToCountMap = std::unordered_map; - -// Use exponentiation by squaring with constant auxiliary memory (iterative version). -// https://en.wikipedia.org/wiki/Exponentiation_by_squaring#With_constant_auxiliary_memory. -template Lhs> -Lhs pow(const Lhs &lhs, Integer rhs) { - if (lhs == 0 && rhs == 0) { - throw UndefinedBinaryOperatorException("^", lhs.toString(), rhs.toString()); - } - - if (rhs < 0) { - return pow(1 / lhs, -rhs); - } - - Lhs res(1); - Lhs sqr = lhs; - - while (rhs != 0) { - if (rhs % 2 == 0) { - rhs /= 2; - sqr = sqr * sqr; - } - else { - --rhs; - res = res * sqr; - } - } - - return res; -} - -Integer abs(const Integer &rhs); - -Integer gcd(const Integer &lhs, const Integer &rhs); - -Integer lcm(const Integer &lhs, const Integer &rhs); - -Integer sqrt(const Integer &rhs); - -Integer sqrt(const Integer &rhs, Integer &remainder); - -Integer factorial(const Integer &rhs); - -Integer factorial(const Integer &rhs, size_t order); - -FactorToCountMap factors(Integer rhs, Integer limit = -1); - -Integer combinations(const Integer &totalNumber, const Integer &choosedNumber); - -Integer multinomialCoefficient(const Integer &totalNumber, const std::vector &groupNumbers); - -} diff --git a/include/fintamath/numbers/NumberUtils.hpp b/include/fintamath/numbers/NumberUtils.hpp deleted file mode 100644 index 740c5e579..000000000 --- a/include/fintamath/numbers/NumberUtils.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include - -namespace fintamath::detail { - -std::string removeLeadingZeroes(std::string str); - -} \ No newline at end of file diff --git a/include/fintamath/numbers/Rational.hpp b/include/fintamath/numbers/Rational.hpp deleted file mode 100644 index 181a8a563..000000000 --- a/include/fintamath/numbers/Rational.hpp +++ /dev/null @@ -1,82 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -class Rational final : public INumberCRTP { - FINTAMATH_CLASS_BODY(Rational) - -public: - Rational() = default; - - explicit Rational(const std::string &str); - - explicit Rational(Integer inNumer, Integer inDenom); - - Rational(Integer rhs); - - Rational(int64_t rhs); - - std::string toString() const override; - - std::unique_ptr toMinimalObject() const override; - - int sign() const; - - const Integer &numerator() const; - - const Integer &denominator() const; - -protected: - bool equals(const Rational &rhs) const override; - - std::strong_ordering compare(const Rational &rhs) const override; - - Rational &add(const Rational &rhs) override; - - Rational &substract(const Rational &rhs) override; - - Rational &multiply(const Rational &rhs) override; - - std::unique_ptr multiplyAbstract(const IArithmetic &rhs) const override; - - Rational ÷(const Rational &rhs) override; - - std::unique_ptr divideAbstract(const IArithmetic &rhs) const override; - - Rational &negate() override; - -private: - void toIrreducibleRational(); - - static void toCommonDenominators(Rational &lhs, Rational &rhs); - - Integer numer = 0; - Integer denom = 1; -}; - -} - -template <> -struct std::hash { - size_t operator()(const fintamath::Rational &rhs) const noexcept { - using fintamath::detail::Hash; - using fintamath::detail::hashCombine; - - size_t seed = 0; - hashCombine(seed, Hash{}(rhs.numerator())); - hashCombine(seed, Hash{}(rhs.denominator())); - return seed; - } -}; diff --git a/include/fintamath/numbers/RationalFunctions.hpp b/include/fintamath/numbers/RationalFunctions.hpp deleted file mode 100644 index a26457c42..000000000 --- a/include/fintamath/numbers/RationalFunctions.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -namespace fintamath { - -Integer floor(const Rational &rhs); - -Integer ceil(const Rational &rhs); - -Rational abs(const Rational &rhs); - -} diff --git a/include/fintamath/numbers/Real.hpp b/include/fintamath/numbers/Real.hpp deleted file mode 100644 index ffa942fc5..000000000 --- a/include/fintamath/numbers/Real.hpp +++ /dev/null @@ -1,128 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -namespace fintamath { - -class Real final : public INumberCRTP { - FINTAMATH_CLASS_BODY(Real) - -public: - using Backend = boost::multiprecision::mpfr_float; - - struct ScopedSetPrecision final { - unsigned currPrecision = getPrecision(); - - public: - explicit ScopedSetPrecision(unsigned precision); - - ~ScopedSetPrecision(); - - ScopedSetPrecision(const ScopedSetPrecision &rhs) = delete; - - ScopedSetPrecision &operator=(const ScopedSetPrecision &rhs) = delete; - }; - -public: - Real() = default; - - Real(Backend inBackend); - - explicit Real(std::string str); - - Real(const Rational &val); - - Real(const Integer &val); - - Real(int64_t val); - - std::string toString() const override; - - std::string toString(unsigned precision) const; - - bool isPrecise() const override; - - int sign() const; - - bool isZero() const; - - const Backend &getBackend() const; - - unsigned getOutputPrecision() const; - - void setOutputPrecision(unsigned precision); - - static unsigned getCalculationPrecision(); - - static unsigned getPrecision(); - - static void setPrecision(unsigned precision); - -protected: - bool equals(const Real &rhs) const override; - - bool equalsAbstract(const IMathObject &rhs) const override; - - std::strong_ordering compare(const Real &rhs) const override; - - std::strong_ordering compareAbstract(const IComparable &rhs) const override; - - Real &add(const Real &rhs) override; - - Real &substract(const Real &rhs) override; - - Real &multiply(const Real &rhs) override; - - std::unique_ptr multiplyAbstract(const IArithmetic &rhs) const override; - - Real ÷(const Real &rhs) override; - - Real &negate() override; - -private: - bool isFinite() const; - - void updatePrecision(const Real &rhs); - - void validateNewPrecision(unsigned precision) const; - -private: - Backend backend; - - unsigned outputPrecision = getPrecision(); - - bool isNegative = false; -}; - -} - -template <> -struct std::hash { - size_t operator()(const fintamath::Real &rhs) const noexcept { - using fintamath::detail::Hash; - using fintamath::detail::hashCombine; - - if (rhs.isZero()) { - size_t seed = 0; - hashCombine(seed, Hash{}(rhs.sign())); - return seed; - } - - return Hash{}(rhs.getBackend()); - } -}; diff --git a/include/fintamath/numbers/RealFunctions.hpp b/include/fintamath/numbers/RealFunctions.hpp deleted file mode 100644 index 97a92a6e5..000000000 --- a/include/fintamath/numbers/RealFunctions.hpp +++ /dev/null @@ -1,82 +0,0 @@ -#pragma once - -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -Integer floor(const Real &rhs); - -Integer ceil(const Real &rhs); - -Real abs(const Real &rhs); - -Real sqrt(const Real &rhs); - -Real pow(const Real &lhs, const Real &rhs); - -Real exp(const Real &rhs); - -Real log(const Real &lhs, const Real &rhs); - -Real ln(const Real &rhs); - -Real lb(const Real &rhs); - -Real lg(const Real &rhs); - -Real sin(const Real &rhs); - -Real cos(const Real &rhs); - -Real tan(const Real &rhs); - -Real cot(const Real &rhs); - -Real sec(const Real &rhs); - -Real csc(const Real &rhs); - -Real asin(const Real &rhs); - -Real acos(const Real &rhs); - -Real atan(const Real &rhs); - -Real acot(const Real &rhs); - -Real asec(const Real &rhs); - -Real acsc(const Real &rhs); - -Real sinh(const Real &rhs); - -Real cosh(const Real &rhs); - -Real tanh(const Real &rhs); - -Real coth(const Real &rhs); - -Real sech(const Real &rhs); - -Real csch(const Real &rhs); - -Real asinh(const Real &rhs); - -Real acosh(const Real &rhs); - -Real atanh(const Real &rhs); - -Real acoth(const Real &rhs); - -Real asech(const Real &rhs); - -Real acsch(const Real &rhs); - -Real tgamma(const Real &rhs); - -const Real &getE(); - -const Real &getPi(); - -} diff --git a/src/fintamath/config/Config.cpp b/src/fintamath/config/Config.cpp deleted file mode 100644 index 9dab57d4e..000000000 --- a/src/fintamath/config/Config.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "fintamath/config/Config.hpp" - -#include "fintamath/config/ConverterConfig.hpp" -#include "fintamath/config/ExpressionConfig.hpp" -#include "fintamath/config/PrecisionConfig.hpp" -#include "fintamath/config/TypeConfig.hpp" - -namespace fintamath::detail { - -Config::Config() { - [[maybe_unused]] static const TypeConfig typeConfig; - [[maybe_unused]] static const PrecisionConfig precisionConfig; - [[maybe_unused]] static const ConverterConfig converterConfig; - [[maybe_unused]] static const ExpressionConfig expressionConfig; -} - -} diff --git a/src/fintamath/config/ConverterConfig.cpp b/src/fintamath/config/ConverterConfig.cpp deleted file mode 100644 index 3e14d7fba..000000000 --- a/src/fintamath/config/ConverterConfig.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "fintamath/config/ConverterConfig.hpp" - -#include - -#include "fintamath/core/Converter.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath::detail { - -ConverterConfig::ConverterConfig() { - Converter::add([](const Integer & /*type*/, const Integer &value) { - return Integer(value).clone(); - }); - - Converter::add([](const Rational & /*type*/, const Rational &value) { - return Rational(value).clone(); - }); - Converter::add([](const Rational & /*type*/, const Integer &value) { - return Rational(value).clone(); - }); - - Converter::add([](const Real & /*type*/, const Real &value) { - return Real(value).clone(); - }); - Converter::add([](const Real & /*type*/, const Integer &value) { - return Real(value).clone(); - }); - Converter::add([](const Real & /*type*/, const Rational &value) { - return Real(value).clone(); - }); - - Converter::add([](const Complex & /*type*/, const Complex &value) { - return std::make_unique(value); - }); - Converter::add([](const Complex & /*type*/, const Integer &value) { - return std::make_unique(value); - }); - Converter::add([](const Complex & /*type*/, const Rational &value) { - return std::make_unique(value); - }); - Converter::add([](const Complex & /*type*/, const Real &value) { - return std::make_unique(value); - }); -} - -} diff --git a/src/fintamath/config/ConverterConfig.hpp b/src/fintamath/config/ConverterConfig.hpp deleted file mode 100644 index 2977f3815..000000000 --- a/src/fintamath/config/ConverterConfig.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -namespace fintamath::detail { - -struct ConverterConfig final { - ConverterConfig(); -}; - -} diff --git a/src/fintamath/config/ExpressionConfig.cpp b/src/fintamath/config/ExpressionConfig.cpp deleted file mode 100644 index bc98453b8..000000000 --- a/src/fintamath/config/ExpressionConfig.cpp +++ /dev/null @@ -1,421 +0,0 @@ -#include "fintamath/config/ExpressionConfig.hpp" - -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/binary/CompExpr.hpp" -#include "fintamath/expressions/binary/DerivativeExpr.hpp" -#include "fintamath/expressions/binary/DivExpr.hpp" -#include "fintamath/expressions/binary/IntegralExpr.hpp" -#include "fintamath/expressions/binary/LogExpr.hpp" -#include "fintamath/expressions/binary/PowExpr.hpp" -#include "fintamath/expressions/polynomial/AddExpr.hpp" -#include "fintamath/expressions/polynomial/AndExpr.hpp" -#include "fintamath/expressions/polynomial/MinMaxExpr.hpp" -#include "fintamath/expressions/polynomial/MulExpr.hpp" -#include "fintamath/expressions/polynomial/OrExpr.hpp" -#include "fintamath/expressions/unary/AbsExpr.hpp" -#include "fintamath/expressions/unary/FloorCeilExpr.hpp" -#include "fintamath/expressions/unary/HyperbExpr.hpp" -#include "fintamath/expressions/unary/InvHyperbExpr.hpp" -#include "fintamath/expressions/unary/InvTrigExpr.hpp" -#include "fintamath/expressions/unary/NotExpr.hpp" -#include "fintamath/expressions/unary/SignExpr.hpp" -#include "fintamath/expressions/unary/TrigExpr.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/arithmetic/Abs.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Frac.hpp" -#include "fintamath/functions/arithmetic/FracMixed.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/arithmetic/Sign.hpp" -#include "fintamath/functions/arithmetic/Sub.hpp" -#include "fintamath/functions/arithmetic/UnaryPlus.hpp" -#include "fintamath/functions/calculus/Derivative.hpp" -#include "fintamath/functions/calculus/Integral.hpp" -#include "fintamath/functions/calculus/Max.hpp" -#include "fintamath/functions/calculus/Min.hpp" -#include "fintamath/functions/comparison/Eqv.hpp" -#include "fintamath/functions/comparison/Less.hpp" -#include "fintamath/functions/comparison/LessEqv.hpp" -#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/Acsch.hpp" -#include "fintamath/functions/hyperbolic/Asech.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/Csch.hpp" -#include "fintamath/functions/hyperbolic/Sech.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" -#include "fintamath/functions/logarithms/Log.hpp" -#include "fintamath/functions/logic/And.hpp" -#include "fintamath/functions/logic/Equiv.hpp" -#include "fintamath/functions/logic/Impl.hpp" -#include "fintamath/functions/logic/Nequiv.hpp" -#include "fintamath/functions/logic/Not.hpp" -#include "fintamath/functions/logic/Or.hpp" -#include "fintamath/functions/ntheory/Ceil.hpp" -#include "fintamath/functions/ntheory/Floor.hpp" -#include "fintamath/functions/other/Deg.hpp" -#include "fintamath/functions/other/Index.hpp" -#include "fintamath/functions/other/Percent.hpp" -#include "fintamath/functions/powers/Exp.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/functions/powers/PowFunction.hpp" -#include "fintamath/functions/powers/Root.hpp" -#include "fintamath/functions/powers/Sqr.hpp" -#include "fintamath/functions/powers/Sqrt.hpp" -#include "fintamath/functions/trigonometry/Acos.hpp" -#include "fintamath/functions/trigonometry/Acot.hpp" -#include "fintamath/functions/trigonometry/Acsc.hpp" -#include "fintamath/functions/trigonometry/Asec.hpp" -#include "fintamath/functions/trigonometry/Asin.hpp" -#include "fintamath/functions/trigonometry/Atan.hpp" -#include "fintamath/functions/trigonometry/Cos.hpp" -#include "fintamath/functions/trigonometry/Cot.hpp" -#include "fintamath/functions/trigonometry/Csc.hpp" -#include "fintamath/functions/trigonometry/Sec.hpp" -#include "fintamath/functions/trigonometry/Sin.hpp" -#include "fintamath/functions/trigonometry/Tan.hpp" -#include "fintamath/literals/ILiteral.hpp" -#include "fintamath/literals/constants/E.hpp" - -namespace fintamath::detail { - -ExpressionConfig::ExpressionConfig() { - Expression::registerExpressionConstructor([](ArgumentPtrVector &&args) { - return AddExpr(std::move(args)).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - ArgumentPtr lhs = std::move(args.front()); - ArgumentPtr rhs = std::move(args.back()); - - ArgumentPtr negRhs = negExpr(std::move(rhs)); - - return AddExpr({std::move(lhs), std::move(negRhs)}).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector &&args) { - return MulExpr(std::move(args)).clone(); - }); - - Expression::registerExpressionConstructor
([](ArgumentPtrVector args) { - return DivExpr(std::move(args.front()), std::move(args.back())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector &&args) { - return divExpr(std::move(args)); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - ArgumentPtr integ = std::move(args[0]); - ArgumentPtr numer = std::move(args[1]); - ArgumentPtr denom = std::move(args[2]); - - return addExpr(std::move(integ), divExpr(std::move(numer), std::move(denom))); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector &&args) { - return AndExpr(std::move(args)).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector &&args) { - return OrExpr(std::move(args)).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return PowExpr(std::move(args.front()), std::move(args.back())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector &&args) { - return powExpr(std::move(args)); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return CompExpr(Eqv{}, std::move(args.front()), std::move(args.back())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return CompExpr(Neqv{}, std::move(args.front()), std::move(args.back())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return CompExpr(Less{}, std::move(args.front()), std::move(args.back())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return CompExpr(More{}, std::move(args.front()), std::move(args.back())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return CompExpr(LessEqv{}, std::move(args.front()), std::move(args.back())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return CompExpr(MoreEqv{}, std::move(args.front()), std::move(args.back())).clone(); - }); - - Expression::registerExpressionConstructor([](const ArgumentPtrVector &args) { - static const Index indexFunc; - - const ArgumentPtr &lhs = args.front(); - const ArgumentPtr &rhs = args.back(); - - if (!indexFunc.doArgsMatch({*lhs, *rhs})) { - throw InvalidInputBinaryOperatorException(indexFunc.toString(), lhs->toString(), rhs->toString()); - } - - return Expression(indexFunc(*lhs, *rhs)).clone(); // TODO: looks weird - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - ArgumentPtr lhs = std::move(args.front()); - ArgumentPtr rhs = std::move(args.back()); - - ArgumentPtr notLhs = notExpr(std::move(lhs)); - - return orExpr(std::move(notLhs), std::move(rhs)); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - ArgumentPtr lhs = std::move(args.front()); - ArgumentPtr rhs = std::move(args.back()); - - ArgumentPtr notLhs = notExpr(lhs); - ArgumentPtr notRhs = notExpr(rhs); - - ArgumentPtr lhsAndRhs = andExpr(std::move(lhs), std::move(rhs)); - ArgumentPtr notLhsAndNotRhs = andExpr(std::move(notLhs), std::move(notRhs)); - - return orExpr(std::move(lhsAndRhs), std::move(notLhsAndNotRhs)); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - ArgumentPtr lhs = std::move(args.front()); - ArgumentPtr rhs = std::move(args.back()); - - ArgumentPtr notLhs = notExpr(lhs); - ArgumentPtr notRhs = notExpr(rhs); - - ArgumentPtr notLhsAndRhs = andExpr(std::move(notLhs), std::move(rhs)); - ArgumentPtr lhsAndNotRhs = andExpr(std::move(lhs), std::move(notRhs)); - - return orExpr(std::move(notLhsAndRhs), std::move(lhsAndNotRhs)); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - static const ArgumentPtr negOne = Integer(-1).clone(); - return mulExpr(negOne, std::move(args.front())); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return std::move(args.front())->clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return NotExpr(std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return DerivativeExpr(std::move(args.front()), std::move(args.back())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return IntegralExpr(std::move(args.front()), std::move(args.back())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return LogExpr(std::move(args.front()), std::move(args.back())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - static const ArgumentPtr logBase = E{}.clone(); - return logExpr(logBase, std::move(args.front())); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - static const ArgumentPtr logBase = Integer(2).clone(); - return logExpr(logBase, std::move(args.front())); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - static const ArgumentPtr logBase = Integer(10).clone(); - return logExpr(logBase, std::move(args.front())); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - static const ArgumentPtr powBase = E{}.clone(); - return powExpr(powBase, std::move(args.front())); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - static const ArgumentPtr percentValue = Integer(100).clone(); - return divExpr(std::move(args.front()), percentValue); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector &&args) { - return MinMaxExpr(Min{}, std::move(args)).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector &&args) { - return MinMaxExpr(Max{}, std::move(args)).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - static const ArgumentPtr powRate = Integer(2).clone(); - return powExpr(std::move(args.front()), powRate); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - static const ArgumentPtr powRate = Rational(1, 2).clone(); - return powExpr(std::move(args.front()), powRate); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - ArgumentPtr lhs = std::move(args.front()); - ArgumentPtr rhs = std::move(args.back()); - - if (const auto rhsNum = cast(rhs); rhsNum && *rhsNum != Integer(0)) { - return powExpr(std::move(lhs), Rational(1) / (*rhsNum)); - } - - static const ArgumentPtr one = Integer(1).clone(); - ArgumentPtr invRhs = divExpr(one, std::move(rhs)); - - return powExpr(std::move(lhs), std::move(invRhs)); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return TrigExpr(Sin{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return TrigExpr(Cos{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return TrigExpr(Tan{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return TrigExpr(Cot{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return TrigExpr(Sec{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return TrigExpr(Csc{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return InvTrigExpr(Asin{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return InvTrigExpr(Acos{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return InvTrigExpr(Atan{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return InvTrigExpr(Acot{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return InvTrigExpr(Asec{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return InvTrigExpr(Acsc{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return HyperbExpr(Sinh{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return HyperbExpr(Cosh{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return HyperbExpr(Tanh{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return HyperbExpr(Coth{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return HyperbExpr(Sech{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return HyperbExpr(Csch{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return InvHyperbExpr(Asinh{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return InvHyperbExpr(Acosh{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return InvHyperbExpr(Atanh{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return InvHyperbExpr(Acoth{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return InvHyperbExpr(Asech{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return InvHyperbExpr(Acsch{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - static const ArgumentPtr deg1 = Deg{}(Integer(1)); - return mulExpr(std::move(args.front()), deg1); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return FloorCeilExpr(Floor{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return FloorCeilExpr(Ceil{}, std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return AbsExpr(std::move(args.front())).clone(); - }); - - Expression::registerExpressionConstructor([](ArgumentPtrVector args) { - return SignExpr(std::move(args.front())).clone(); - }); -} - -} diff --git a/src/fintamath/config/ExpressionConfig.hpp b/src/fintamath/config/ExpressionConfig.hpp deleted file mode 100644 index f188f01fd..000000000 --- a/src/fintamath/config/ExpressionConfig.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -namespace fintamath::detail { - -struct ExpressionConfig final { - ExpressionConfig(); -}; - -} diff --git a/src/fintamath/config/PrecisionConfig.cpp b/src/fintamath/config/PrecisionConfig.cpp deleted file mode 100644 index a787376da..000000000 --- a/src/fintamath/config/PrecisionConfig.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "fintamath/config/PrecisionConfig.hpp" - -#include "fintamath/numbers/Real.hpp" - -namespace fintamath::detail { - -PrecisionConfig::PrecisionConfig() { - constexpr unsigned defaultPrecision = 20; - Real::setPrecision(defaultPrecision); -} - -} diff --git a/src/fintamath/config/PrecisionConfig.hpp b/src/fintamath/config/PrecisionConfig.hpp deleted file mode 100644 index c5ef5a16b..000000000 --- a/src/fintamath/config/PrecisionConfig.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -namespace fintamath::detail { - -struct PrecisionConfig final { - PrecisionConfig(); -}; - -} diff --git a/src/fintamath/config/TypeConfig.cpp b/src/fintamath/config/TypeConfig.cpp deleted file mode 100644 index c59f312b4..000000000 --- a/src/fintamath/config/TypeConfig.cpp +++ /dev/null @@ -1,252 +0,0 @@ -#include "fintamath/config/TypeConfig.hpp" - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/FunctionExpression.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/binary/CompExpr.hpp" -#include "fintamath/expressions/binary/DerivativeExpr.hpp" -#include "fintamath/expressions/binary/DivExpr.hpp" -#include "fintamath/expressions/binary/IntegralExpr.hpp" -#include "fintamath/expressions/binary/LogExpr.hpp" -#include "fintamath/expressions/binary/PowExpr.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/expressions/polynomial/AddExpr.hpp" -#include "fintamath/expressions/polynomial/AndExpr.hpp" -#include "fintamath/expressions/polynomial/MinMaxExpr.hpp" -#include "fintamath/expressions/polynomial/MulExpr.hpp" -#include "fintamath/expressions/polynomial/OrExpr.hpp" -#include "fintamath/expressions/unary/AbsExpr.hpp" -#include "fintamath/expressions/unary/FloorCeilExpr.hpp" -#include "fintamath/expressions/unary/HyperbExpr.hpp" -#include "fintamath/expressions/unary/InvHyperbExpr.hpp" -#include "fintamath/expressions/unary/InvTrigExpr.hpp" -#include "fintamath/expressions/unary/NotExpr.hpp" -#include "fintamath/expressions/unary/SignExpr.hpp" -#include "fintamath/expressions/unary/TrigExpr.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/functions/arithmetic/Abs.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Frac.hpp" -#include "fintamath/functions/arithmetic/FracMixed.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/arithmetic/Sign.hpp" -#include "fintamath/functions/arithmetic/Sub.hpp" -#include "fintamath/functions/arithmetic/UnaryPlus.hpp" -#include "fintamath/functions/calculus/Derivative.hpp" -#include "fintamath/functions/calculus/Integral.hpp" -#include "fintamath/functions/calculus/Max.hpp" -#include "fintamath/functions/calculus/Min.hpp" -#include "fintamath/functions/comparison/Eqv.hpp" -#include "fintamath/functions/comparison/Less.hpp" -#include "fintamath/functions/comparison/LessEqv.hpp" -#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/Acsch.hpp" -#include "fintamath/functions/hyperbolic/Asech.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/Csch.hpp" -#include "fintamath/functions/hyperbolic/Sech.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" -#include "fintamath/functions/logarithms/Log.hpp" -#include "fintamath/functions/logic/And.hpp" -#include "fintamath/functions/logic/Equiv.hpp" -#include "fintamath/functions/logic/Impl.hpp" -#include "fintamath/functions/logic/Nequiv.hpp" -#include "fintamath/functions/logic/Not.hpp" -#include "fintamath/functions/logic/Or.hpp" -#include "fintamath/functions/ntheory/Ceil.hpp" -#include "fintamath/functions/ntheory/Floor.hpp" -#include "fintamath/functions/ntheory/Mod.hpp" -#include "fintamath/functions/other/Comma.hpp" -#include "fintamath/functions/other/Deg.hpp" -#include "fintamath/functions/other/Factorial.hpp" -#include "fintamath/functions/other/Index.hpp" -#include "fintamath/functions/other/Percent.hpp" -#include "fintamath/functions/powers/Exp.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/functions/powers/PowFunction.hpp" -#include "fintamath/functions/powers/Root.hpp" -#include "fintamath/functions/powers/Sqr.hpp" -#include "fintamath/functions/powers/Sqrt.hpp" -#include "fintamath/functions/trigonometry/Acos.hpp" -#include "fintamath/functions/trigonometry/Acot.hpp" -#include "fintamath/functions/trigonometry/Acsc.hpp" -#include "fintamath/functions/trigonometry/Asec.hpp" -#include "fintamath/functions/trigonometry/Asin.hpp" -#include "fintamath/functions/trigonometry/Atan.hpp" -#include "fintamath/functions/trigonometry/Cos.hpp" -#include "fintamath/functions/trigonometry/Cot.hpp" -#include "fintamath/functions/trigonometry/Csc.hpp" -#include "fintamath/functions/trigonometry/Sec.hpp" -#include "fintamath/functions/trigonometry/Sin.hpp" -#include "fintamath/functions/trigonometry/Tan.hpp" -#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/I.hpp" -#include "fintamath/literals/constants/IConstant.hpp" -#include "fintamath/literals/constants/Inf.hpp" -#include "fintamath/literals/constants/NegInf.hpp" -#include "fintamath/literals/constants/Pi.hpp" -#include "fintamath/literals/constants/True.hpp" -#include "fintamath/literals/constants/Undefined.hpp" -#include "fintamath/numbers/IInteger.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -namespace fintamath::detail { - -TypeConfig::TypeConfig() { - IMathObject::registerType(); - IMathObject::registerType(); - IMathObject::registerType(); - IMathObject::registerType(); - - IArithmetic::registerType(); - - IComparable::registerType(); - - INumber::registerType(); - INumber::registerType(); - INumber::registerType(); - INumber::registerType(); - - IInteger::registerType(); - - ILiteral::registerType(); - ILiteral::registerType(); - ILiteral::registerType(); - - IConstant::registerType(); - IConstant::registerType(); - IConstant::registerType(); - IConstant::registerType(); - IConstant::registerType(); - IConstant::registerType(); - IConstant::registerType(); - IConstant::registerType(); - IConstant::registerType(); - - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - IFunction::registerType(); - - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType
(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - - IExpression::registerType(); - IExpression::registerType(); - IExpression::registerType(); - IExpression::registerType(); - IExpression::registerType(); - - IPolynomExpression::registerType(); - IPolynomExpression::registerType(); - IPolynomExpression::registerType(); - IPolynomExpression::registerType(); - IPolynomExpression::registerType(); - - IBinaryExpression::registerType(); - IBinaryExpression::registerType(); - IBinaryExpression::registerType(); - IBinaryExpression::registerType(); - IBinaryExpression::registerType(); - IBinaryExpression::registerType(); - - IUnaryExpression::registerType(); - IUnaryExpression::registerType(); - IUnaryExpression::registerType(); - IUnaryExpression::registerType(); - IUnaryExpression::registerType(); - IUnaryExpression::registerType(); - IUnaryExpression::registerType(); - IUnaryExpression::registerType(); -} - -} diff --git a/src/fintamath/config/TypeConfig.hpp b/src/fintamath/config/TypeConfig.hpp deleted file mode 100644 index 2dbaf37b8..000000000 --- a/src/fintamath/config/TypeConfig.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -namespace fintamath::detail { - -struct TypeConfig final { - TypeConfig(); -}; - -} diff --git a/src/fintamath/core/Converter.cpp b/src/fintamath/core/Converter.cpp deleted file mode 100644 index 526d81840..000000000 --- a/src/fintamath/core/Converter.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "fintamath/core/Converter.hpp" - -#include "fintamath/core/IMathObject.hpp" - -namespace fintamath::detail { - -Converter::ConverterMultiMethod &Converter::getConverter() { - static ConverterMultiMethod converter; - return converter; -} - -} diff --git a/src/fintamath/core/IArithmetic.cpp b/src/fintamath/core/IArithmetic.cpp deleted file mode 100644 index 799969394..000000000 --- a/src/fintamath/core/IArithmetic.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "fintamath/core/IArithmetic.hpp" - -namespace fintamath { - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IArithmetic) - -} diff --git a/src/fintamath/core/IComparable.cpp b/src/fintamath/core/IComparable.cpp deleted file mode 100644 index 68843e7e4..000000000 --- a/src/fintamath/core/IComparable.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "fintamath/core/IComparable.hpp" - -namespace fintamath { - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IComparable) - -} diff --git a/src/fintamath/core/IMathObject.cpp b/src/fintamath/core/IMathObject.cpp deleted file mode 100644 index e889cae1e..000000000 --- a/src/fintamath/core/IMathObject.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "fintamath/core/IMathObject.hpp" - -namespace fintamath { - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IMathObject) - -} diff --git a/src/fintamath/core/MathObjectClass.cpp b/src/fintamath/core/MathObjectClass.cpp deleted file mode 100644 index eb073ac6f..000000000 --- a/src/fintamath/core/MathObjectClass.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "fintamath/core/MathObjectClass.hpp" - -namespace fintamath { - -std::strong_ordering MathObjectClass::operator<=>(const MathObjectClass rhs) const { - const Id lhsId = getId(); - const Id rhsId = rhs.getId(); - - return lhsId != 0 && rhsId != 0 - ? lhsId <=> rhsId - : name <=> rhs.name; -} - -std::optional MathObjectClass::getParent() const { - const auto iter = getChildToParentMap().find(name); - return iter != getChildToParentMap().end() ? iter->second : std::optional{}; -} - -const MathObjectClass::Children &MathObjectClass::getChildren(const bool recursive) const { - if (recursive) { - return getParentToRecursiveChildrenMap()[name]; - } - - return getParentToChildrenMap()[name]; -} - -MathObjectClass::Id MathObjectClass::getId() const { - const auto classToId = getClassToIdMap().find(*this); - return classToId != getClassToIdMap().end() ? classToId->second : 0; -} - -MathObjectClass::ClassToIdMap &MathObjectClass::getClassToIdMap() { - static ClassToIdMap map; - return map; -} - -MathObjectClass::ChildToParentMap &MathObjectClass::getChildToParentMap() { - static ChildToParentMap map; - return map; -} - -MathObjectClass::ParentToChildrenMap &MathObjectClass::getParentToChildrenMap() { - static ParentToChildrenMap map; - return map; -} - -MathObjectClass::ParentToChildrenMap &MathObjectClass::getParentToRecursiveChildrenMap() { - static ParentToChildrenMap map; - return map; -} - -} diff --git a/src/fintamath/core/Tokenizer.cpp b/src/fintamath/core/Tokenizer.cpp deleted file mode 100644 index b5302dd89..000000000 --- a/src/fintamath/core/Tokenizer.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include "fintamath/core/Tokenizer.hpp" - -#include -#include -#include - -#include "fintamath/core/CoreUtils.hpp" - -namespace fintamath::detail { - -TokenVector Tokenizer::tokenize(std::string str) { - handleSpaces(str); - - TokenVector tokens; - Token numberToken; - Token specialToken; - - for (const char ch : str) { - if (isDigitOrPoint(ch)) { - appendToken(tokens, specialToken, true); - numberToken.push_back(ch); - } - else if (isSpace(ch)) { - appendToken(tokens, specialToken, true); - appendToken(tokens, numberToken, false); - } - else { - appendToken(tokens, numberToken, false); - specialToken.push_back(ch); - } - } - - appendToken(tokens, numberToken, false); - appendToken(tokens, specialToken, true); - - return tokens; -} - -void Tokenizer::registerToken(const Token &token) { - auto &tokens = getRegisteredTokens(); - tokens.insert(stdr::upper_bound(tokens, token, [](const Token &lhs, const Token &rhs) { - return lhs.size() > rhs.size(); - }), - token); -} - -bool Tokenizer::appendToken(TokenVector &tokens, Token &token, const bool shouldSplit) { - if (token.empty()) { - return false; - } - - if (!shouldSplit) { - tokens.emplace_back(token); - token.clear(); - return true; - } - - while (!token.empty()) { - std::string nestedToken = token.substr(0, getRegisteredTokens().front().size()); - bool isNestedTokenFind = false; - - for (const auto ®isteredToken : getRegisteredTokens()) { - if (nestedToken.size() < registeredToken.size()) { - continue; - } - - if (nestedToken.size() > registeredToken.size()) { - nestedToken = token.substr(0, registeredToken.size()); - } - - if (nestedToken == registeredToken) { - isNestedTokenFind = true; - break; - } - } - - if (!isNestedTokenFind) { - nestedToken = token.substr(0, 1); - } - - tokens.emplace_back(nestedToken); - token = token.substr(nestedToken.size()); - } - - token.clear(); - return true; -} - -void Tokenizer::handleSpaces(std::string &str) { - str = std::regex_replace(str, std::regex(R"([\s\r\n]+)"), " "); -} - -bool Tokenizer::isDigitOrPoint(const char ch) { - return ch == '.' || (ch >= '0' && ch <= '9'); -} - -bool Tokenizer::isSpace(const char ch) { - return ch == ' '; -} - -TokenVector &Tokenizer::getRegisteredTokens() { - static TokenVector registeredTokens; - return registeredTokens; -} - -} diff --git a/src/fintamath/expressions/Expression.cpp b/src/fintamath/expressions/Expression.cpp deleted file mode 100644 index 377f927c8..000000000 --- a/src/fintamath/expressions/Expression.cpp +++ /dev/null @@ -1,526 +0,0 @@ -#include "fintamath/expressions/Expression.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/Cache.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/Tokenizer.hpp" -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/expressions/ExpressionParser.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/FunctionExpression.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/arithmetic/Sub.hpp" -#include "fintamath/functions/other/Comma.hpp" -#include "fintamath/functions/other/Factorial.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/literals/constants/IConstant.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -using namespace detail; - -Expression::Expression() : child(Integer(0).clone()) { -} - -Expression::Expression(const std::string &str) : child(parseExpr(str)) { -} - -Expression::Expression(const ArgumentPtr &obj) : child(compress(obj)) { -} - -Expression::Expression(const IMathObject &obj) : Expression(obj.clone()) { -} - -Expression::Expression(const int64_t val) : child(Integer(val).clone()) { -} - -std::string Expression::toString() const { - simplifyMutable(); - return stringCached; -} - -Expression approximate(const Expression &rhs, const unsigned precision) { - const Real::ScopedSetPrecision setPrecision(precision); - - static Cache cache([](const unsigned inPrecision) { - static const Integer powBase = 10; - return pow(powBase, inPrecision); - }); - - Expression approxExpr = rhs; - Expression::approximateChild(approxExpr.child); - Expression::setPrecisionChild(approxExpr.child, precision, cache[precision]); - approxExpr.updateStringMutable(); - - return approxExpr; -} - -const std::shared_ptr &Expression::getFunction() const { - static const std::shared_ptr func; - return func; -} - -const ArgumentPtrVector &Expression::getChildren() const { - simplifyMutable(); - childrenCached.front() = child; - return childrenCached; -} - -void Expression::setChildren(const ArgumentPtrVector &childVect) { - if (childVect.size() != 1) { - throw InvalidInputFunctionException("", argumentVectorToStringVector(childVect)); - } - - *this = Expression(childVect.front()); -} - -void Expression::setVariables(const std::vector> &varsToVals) { - simplifyMutable(); - IExpression::setVariables(varsToVals); -} - -void Expression::setVariable(const Variable &var, const Expression &val) { - setVariables({{var, val.child}}); -} - -ArgumentPtr Expression::simplify() const { - simplifyMutable(); - return child; -} - -void Expression::simplifyMutable() const { - if (isSimplified) { - return; - } - - ArgumentPtr prevChild = child; - simplifyChild(child); - - while (*child != *prevChild) { - prevChild = child; - simplifyChild(child); - } - - isSimplified = true; - updateStringMutable(); -} - -void Expression::updateStringMutable() const { - stringCached = child->toString(); -} - -std::unique_ptr parseExpr(const std::string &str) { - try { - auto tokens = Tokenizer::tokenize(str); - auto terms = Expression::tokensToTerms(tokens); - auto stack = Expression::termsToOperands(terms); - auto obj = Expression::operandsToObject(stack); - return obj; - } - catch (const InvalidInputException &) { - throw InvalidInputException(str); - } -} - -TermVector Expression::tokensToTerms(TokenVector &tokens) { - if (tokens.empty()) { - throw InvalidInputException(""); - } - - TermVector terms(tokens.size()); - - for (const auto i : stdv::iota(0U, terms.size())) { - terms[i] = parseTerm(tokens[i]); - } - - fixOperatorTypes(terms); - insertMultiplications(terms); - collapseFactorials(terms); - - return terms; -} - -// Use the shunting yard algorithm -// https://en.m.wikipedia.org/wiki/Shunting_yard_algorithm -OperandStack Expression::termsToOperands(TermVector &terms) { - OperandStack operands; - FunctionTermStack functions; - - for (auto &term : terms) { - if (!term.value) { - if (term.name == "(") { - functions.emplace(std::move(term), std::optional{}); - } - else if (term.name == ")") { - moveFunctionTermsToOperands(operands, functions, {}); - - if (functions.empty()) { - throw InvalidInputException(""); - } - - functions.pop(); - } - else { - throw InvalidInputException(""); - } - } - else if (is(term.value)) { - std::optional priority; - - if (const auto *oper = cast(term.value.get())) { - moveFunctionTermsToOperands(operands, functions, oper); - priority = oper->getPriority(); - } - - functions.emplace(std::move(term), priority); - } - else { - operands.emplace(std::move(term.value)); - } - } - - moveFunctionTermsToOperands(operands, functions, {}); - - if (!functions.empty()) { - throw InvalidInputException(""); - } - - return operands; -} - -std::unique_ptr Expression::operandsToObject(OperandStack &operands) { - if (operands.empty()) { - throw InvalidInputException(""); - } - - std::unique_ptr arg = std::move(operands.top()); - operands.pop(); - - if (is(arg)) { - auto func = cast(std::move(arg)); - const ArgumentPtr rhsChild = operandsToObject(operands); - - if (isBinaryOperator(func.get())) { - const ArgumentPtr lhsChild = operandsToObject(operands); - return makeExpr(*func, {lhsChild, rhsChild}); - } - - ArgumentPtrVector children = unwrapComma(rhsChild); - - if (!func->isVariadic() && func->getArgumentClasses().size() != children.size()) { - func = parseFunction(func->toString(), children.size()); - - if (!func) { - throw InvalidInputException(""); - } - } - - return makeExpr(*func, std::move(children)); - } - - return arg; -} - -std::unique_ptr Expression::parseFunction(const std::string &str, const size_t argNum) { - for (auto &func : IFunction::parse(str)) { - if (func->getArgumentClasses().size() == argNum) { - return std::move(func); - } - } - - return {}; -} - -auto Expression::parseOperator(const std::string &str, const IOperator::Priority priority) -> std::unique_ptr { - for (auto &oper : IOperator::parse(str)) { - if (oper->getPriority() == priority) { - return std::move(oper); - } - } - - return {}; -} - -Term Expression::parseTerm(const std::string &str) { - static auto termValueParser = [] { - Parser> parser; - parser.registerType(); - parser.registerType(); - parser.registerType(); - return parser; - }(); - - Term term = {str, {}}; - - if (auto termValue = termValueParser.parseFirst(str)) { - term.value = std::move(*termValue); - } - - return term; -} - -void Expression::moveFunctionTermsToOperands(OperandStack &operands, std::stack &functions, const IOperator *nextOper) { - if (isPrefixOperator(nextOper)) { - return; - } - - while (!functions.empty() && - functions.top().term.name != "(" && - (!nextOper || - !functions.top().priority || - *functions.top().priority <= nextOper->getPriority())) { - - operands.emplace(std::move(functions.top().term.value)); - functions.pop(); - } -} - -void Expression::insertMultiplications(TermVector &terms) { - static const ArgumentPtr mul = Mul{}.clone(); - - for (size_t i = 1; i < terms.size(); i++) { - if (canNextTermBeBinaryOperator(terms[i - 1]) && - canPrevTermBeBinaryOperator(terms[i])) { - - Term term(mul->toString(), mul->clone()); - terms.insert(terms.begin() + static_cast(i), std::move(term)); - i++; - } - } -} - -void Expression::fixOperatorTypes(TermVector &terms) { - bool isFixed = true; - - if (auto &term = terms.front(); - is(term.value) && - !isPrefixOperator(term.value.get())) { - - term.value = parseOperator(term.name, IOperator::Priority::PrefixUnary); - isFixed = static_cast(term.value); - } - - if (auto &term = terms.back(); - is(term.value) && - !isPostfixOperator(term.value.get())) { - - term.value = parseOperator(term.name, IOperator::Priority::PostfixUnary); - isFixed = isFixed && static_cast(term.value); - } - - if (!isFixed) { - throw InvalidInputException(""); - } - - if (terms.size() < 3) { - return; - } - - for (const auto i : stdv::iota(1U, terms.size() - 1)) { - auto &term = terms[i]; - const auto &termPrev = terms[i - 1]; - - if (is(term.value) && - !isPrefixOperator(term.value.get()) && - !canNextTermBeBinaryOperator(termPrev)) { - - term.value = parseOperator(term.name, IOperator::Priority::PrefixUnary); - isFixed = isFixed && term.value; - } - } - - for (const auto i : stdv::iota(1U, terms.size() - 1) | stdv::reverse) { - auto &term = terms[i]; - const auto &termNext = terms[i + 1]; - - if (is(term.value) && - !isPostfixOperator(term.value.get()) && - !canPrevTermBeBinaryOperator(termNext)) { - - term.value = parseOperator(term.name, IOperator::Priority::PostfixUnary); - isFixed = isFixed && term.value; - } - } - - if (!isFixed) { - throw InvalidInputException(""); - } -} - -void Expression::collapseFactorials(TermVector &terms) { - for (size_t i = 1; i + 1 < terms.size(); i++) { - auto &term = terms[i]; - const auto &termNext = terms[i + 1]; - - if (is(term.value) && is(termNext.value)) { - const auto &oldFactorial = cast(*term.value); - term.value = Factorial(oldFactorial.getOrder() + 1).clone(); - - terms.erase(terms.begin() + static_cast(i) + 1); - i--; - } - } -} - -bool Expression::canNextTermBeBinaryOperator(const Term &term) { - return !(isPrefixOperator(term.value.get()) || - isBinaryOperator(term.value.get()) || - isNonOperatorFunction(term.value.get()) || - term.name == "(" || - term.name == ","); -} - -bool Expression::canPrevTermBeBinaryOperator(const Term &term) { - return !(isPostfixOperator(term.value.get()) || - isBinaryOperator(term.value.get()) || - term.name == ")" || - term.name == ","); -} - -bool Expression::isBinaryOperator(const IMathObject *val) { - const auto *oper = cast(val); - return oper && oper->getArgumentClasses().size() == 2; -} - -bool Expression::isPrefixOperator(const IMathObject *val) { - const auto *oper = cast(val); - return oper && oper->getPriority() == IOperator::Priority::PrefixUnary; -} - -bool Expression::isPostfixOperator(const IMathObject *val) { - const auto *oper = cast(val); - return oper && oper->getPriority() == IOperator::Priority::PostfixUnary; -} - -bool Expression::isNonOperatorFunction(const IMathObject *val) { - return is(val) && !is(val); -} - -ArgumentPtrVector Expression::unwrapComma(const ArgumentPtr &child) { - if (const auto childExpr = cast(child); - childExpr && - is(childExpr->getFunction())) { - - const ArgumentPtr &lhs = childExpr->getChildren().front(); - const ArgumentPtr &rhs = childExpr->getChildren().back(); - - ArgumentPtrVector children = unwrapComma(lhs); - children.push_back(rhs); - return children; - } - - return {child}; -} - -ArgumentPtr Expression::compress(const ArgumentPtr &child) { - if (const auto expr = cast(child)) { - return expr->child; - } - - return child; -} - -Expression::ExpressionMaker &Expression::getExpressionMaker() { - static ExpressionMaker map; - return map; -} - -void Expression::validateFunctionArgs(const IFunction &func, const ArgumentPtrVector &args) { - const ArgumentTypeVector &expectedArgTypes = func.getArgumentClasses(); - - if (args.empty() || (!func.isVariadic() && args.size() < expectedArgTypes.size())) { - throw InvalidInputFunctionException(func.toString(), argumentVectorToStringVector(args)); - } - - const bool doesArgSizeMatch = !func.isVariadic() && args.size() == expectedArgTypes.size(); - MathObjectClass expectedType = expectedArgTypes.front(); - - for (const auto i : stdv::iota(0U, args.size())) { - if (doesArgSizeMatch) { - expectedType = expectedArgTypes[i]; - } - - if (const ArgumentPtr &arg = args[i]; !doesArgMatch(expectedType, arg)) { - throw InvalidInputFunctionException(func.toString(), argumentVectorToStringVector(args)); - } - } -} - -bool Expression::doesArgMatch(const MathObjectClass &expectedType, const ArgumentPtr &arg) { - if (const auto childExpr = cast(arg)) { - const std::shared_ptr &childFunc = childExpr->getFunction(); - const MathObjectClass childType = childFunc->getReturnClass(); - - if (childType != Variable::getClassStatic() && - !is(expectedType, childType) && - !is(childType, expectedType)) { - - return false; - } - } - else if (const auto childConst = cast(arg)) { - if (const MathObjectClass childType = childConst->getReturnClass(); - !is(expectedType, childType) && - !is(childType, expectedType)) { - - return false; - } - } - else { - if (const MathObjectClass childType = arg->getClass(); - childType != Variable::getClassStatic() && - !is(expectedType, childType)) { - - return false; - } - } - - return true; -} - -namespace detail { - -std::unique_ptr makeExpr(const IFunction &func, ArgumentPtrVector args) { - stdr::transform(args, args.begin(), &Expression::compress); - Expression::validateFunctionArgs(func, args); - - if (const auto strToConstr = Expression::getExpressionMaker().find(func.getClass()); - strToConstr != Expression::getExpressionMaker().end()) { - - if (auto expr = strToConstr->second(std::move(args))) { - return expr; - } - } - - return FunctionExpression(func, std::move(args)).clone(); -} - -std::unique_ptr makeExpr(const IFunction &func, const ArgumentRefVector &args) { - return makeExpr(func, argumentRefVectorToArgumentPtrVector(args)); -} - -} - -} diff --git a/src/fintamath/expressions/ExpressionComparator.cpp b/src/fintamath/expressions/ExpressionComparator.cpp deleted file mode 100644 index 60fb57dd6..000000000 --- a/src/fintamath/expressions/ExpressionComparator.cpp +++ /dev/null @@ -1,491 +0,0 @@ -#include "fintamath/expressions/ExpressionComparator.hpp" - -#include -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/literals/ILiteral.hpp" -#include "fintamath/literals/Variable.hpp" - -namespace fintamath::detail { - -using ExpressionTreePathStack = std::stack, size_t>>; - -using Ordering = std::strong_ordering; - -struct ChildrenComparatorResult final { - Ordering postfix = Ordering::equal; - Ordering postfixUnary = Ordering::equal; - Ordering prefixFirst = Ordering::equal; - Ordering prefixLast = Ordering::equal; - Ordering prefixVariables = Ordering::equal; - Ordering prefixLiterals = Ordering::equal; - Ordering size = Ordering::equal; -}; - -Ordering compareNonExpressions(const ArgumentPtr &lhs, - const ArgumentPtr &rhs, - const ComparatorOptions &options); - -Ordering comparePolynoms(const std::shared_ptr &lhs, - const std::shared_ptr &rhs, - const ComparatorOptions &options); - -Ordering compareExpressions(const std::shared_ptr &lhs, - const std::shared_ptr &rhs, - const ComparatorOptions &options); - -Ordering comparePolynomAndNonPolynom(const std::shared_ptr &lhs, - const ArgumentPtr &rhs, - const ComparatorOptions &options); - -Ordering compareExpressionAndNonExpression(const std::shared_ptr &lhs, - const ArgumentPtr &rhs, - const ComparatorOptions &options); - -Ordering compareFunctions(const std::shared_ptr &lhs, - const std::shared_ptr &rhs, - const ComparatorOptions &options); - -ChildrenComparatorResult compareChildren(const ArgumentPtrVector &lhsChildren, - const ArgumentPtrVector &rhsChildren, - const ComparatorOptions &options); - -bool unwrapUnaryExpression(ArgumentPtr &arg); - -bool unwrapEmptyExpression(ArgumentPtr &arg); - -Ordering reverse(Ordering ordering); - -template -size_t getPositionOfFirstChildWithTerm(const ArgumentPtrVector &children) { - for (const auto i : stdv::iota(0U, children.size())) { - if (containsIf(children[i], [](const ArgumentPtr &child) { return is(child); })) { - return i; - } - } - - return children.size(); -} - -template -std::shared_ptr popNextTerm(ExpressionTreePathStack &stack) { - while (!stack.empty()) { - const ArgumentPtrVector &children = stack.top().first->getChildren(); - - // TODO: looks weird - size_t &exprIndex = stack.top().second; - exprIndex++; - - bool hasExprChild = false; - - for (; exprIndex < children.size(); exprIndex++) { - if (const auto &exprChild = cast(children[exprIndex]); exprChild && containsVariable(exprChild)) { - stack.emplace(exprChild, -1); - hasExprChild = true; - break; - } - - if (const auto &varChild = cast(children[exprIndex])) { - return varChild; - } - } - - if (hasExprChild) { - continue; - } - - stack.pop(); - } - - return {}; -} - -template -Ordering compareTerms(const ArgumentPtr &lhs, - const ArgumentPtr &rhs, - const ComparatorOptions &options) { - - ExpressionTreePathStack lhsPath; - ExpressionTreePathStack rhsPath; - - std::shared_ptr lhsTerm; - std::shared_ptr rhsTerm; - - if (const auto &expr = cast(lhs)) { - lhsPath.emplace(expr, -1); - lhsTerm = popNextTerm(lhsPath); - } - else if (const auto &term = cast(lhs)) { - lhsTerm = term; - } - - if (const auto &expr = cast(rhs)) { - rhsPath.emplace(expr, -1); - rhsTerm = popNextTerm(rhsPath); - } - else if (const auto &term = cast(rhs)) { - rhsTerm = term; - } - - if (lhsTerm && !rhsTerm) { - return !options.termOrderInversed ? Ordering::greater : Ordering::less; - } - - if (!lhsTerm && rhsTerm) { - return options.termOrderInversed ? Ordering::greater : Ordering::less; - } - - while (lhsTerm && rhsTerm) { - if (const Ordering res = compareNonExpressions(lhsTerm, rhsTerm, options); res != Ordering::equal) { - return res; - } - - lhsTerm = popNextTerm(lhsPath); - rhsTerm = popNextTerm(rhsPath); - } - - return Ordering::equal; -} - -Ordering compare(ArgumentPtr lhs, - ArgumentPtr rhs, - const ComparatorOptions options) { - - unwrapEmptyExpression(lhs); - unwrapEmptyExpression(rhs); - - const auto lhsExpr = cast(lhs); - const auto rhsExpr = cast(rhs); - - if (!lhsExpr && !rhsExpr) { - return compareNonExpressions(lhs, rhs, options); - } - - const auto lhsPolynom = cast(lhsExpr); - const auto rhsPolynom = cast(rhsExpr); - - if (lhsPolynom && rhsPolynom) { - return comparePolynoms(lhsPolynom, rhsPolynom, options); - } - - if (lhsExpr && !rhsExpr) { - return compareExpressionAndNonExpression(lhsExpr, rhs, options); - } - - if (!lhsExpr && rhsExpr) { - return reverse(compareExpressionAndNonExpression(rhsExpr, lhs, options)); - } - - if (lhsPolynom && !rhsPolynom) { - return comparePolynomAndNonPolynom(lhsPolynom, rhs, options); - } - - if (!lhsPolynom && rhsPolynom) { - return reverse(comparePolynomAndNonPolynom(rhsPolynom, lhs, options)); - } - - return compareExpressions(lhsExpr, rhsExpr, options); -} - -Ordering compareNonExpressions(const ArgumentPtr &lhs, - const ArgumentPtr &rhs, - const ComparatorOptions &options) { - - if (is(lhs) && !is(rhs)) { - return !options.termOrderInversed ? Ordering::greater : Ordering::less; - } - if (!is(lhs) && is(rhs)) { - return options.termOrderInversed ? Ordering::greater : Ordering::less; - } - - if (is(lhs) && !is(rhs)) { - return !options.termOrderInversed ? Ordering::greater : Ordering::less; - } - if (!is(lhs) && is(rhs)) { - return options.termOrderInversed ? Ordering::greater : Ordering::less; - } - - if (*lhs == *rhs) { - return Ordering::equal; - } - - if (const auto lhsComp = cast(lhs)) { - if (const auto rhsComp = cast(rhs)) { - if (options.comparableOrderInversed) { - return *lhsComp < *rhsComp ? Ordering::greater : Ordering::less; - } - - return *lhsComp > *rhsComp ? Ordering::greater : Ordering::less; - } - } - - return lhs->toString() < rhs->toString() ? Ordering::greater : Ordering::less; -} - -Ordering comparePolynoms(const std::shared_ptr &lhs, - const std::shared_ptr &rhs, - const ComparatorOptions &options) { - - const ChildrenComparatorResult childrenComp = compareChildren(lhs->getChildren(), rhs->getChildren(), options); - - if (childrenComp.postfix != Ordering::equal) { - return childrenComp.postfix; - } - if (childrenComp.postfixUnary != Ordering::equal) { - return childrenComp.postfixUnary; - } - if (childrenComp.size != Ordering::equal) { - return childrenComp.size; - } - if (childrenComp.prefixFirst != Ordering::equal) { - return childrenComp.prefixFirst; - } - - return compareFunctions(lhs->getFunction(), rhs->getFunction(), options); -} - -Ordering compareExpressions(const std::shared_ptr &lhs, - const std::shared_ptr &rhs, - const ComparatorOptions &options) { - - const auto lhsOper = cast(lhs->getFunction()); - const auto rhsOper = cast(rhs->getFunction()); - - if ((lhsOper != nullptr) != (rhsOper != nullptr)) { - return compareFunctions(lhs->getFunction(), rhs->getFunction(), options); - } - - ComparatorOptions childCompOptions = options; - childCompOptions.termOrderInversed = false; - const ChildrenComparatorResult childrenComp = compareChildren(lhs->getChildren(), rhs->getChildren(), childCompOptions); - - if (childrenComp.prefixVariables != Ordering::equal) { - return childrenComp.prefixVariables; - } - if (childrenComp.prefixLiterals != Ordering::equal) { - return childrenComp.prefixLiterals; - } - if (childrenComp.size != Ordering::equal) { - return childrenComp.size; - } - if (childrenComp.postfix != Ordering::equal) { - return childrenComp.postfix; - } - - if (is(lhs->getFunction()) && is(rhs->getFunction())) { - if (childrenComp.prefixLast != Ordering::equal) { - return childrenComp.prefixLast; - } - } - else { - if (childrenComp.prefixFirst != Ordering::equal) { - return childrenComp.prefixFirst; - } - } - - return compareFunctions(lhs->getFunction(), rhs->getFunction(), options); -} - -Ordering comparePolynomAndNonPolynom(const std::shared_ptr &lhs, - const ArgumentPtr &rhs, - const ComparatorOptions &options) { - - const ChildrenComparatorResult childrenComp = compareChildren(lhs->getChildren(), {rhs}, options); - - if (childrenComp.postfix != Ordering::equal) { - return childrenComp.postfix; - } - - return childrenComp.prefixFirst; -} - -Ordering compareExpressionAndNonExpression(const std::shared_ptr &lhs, - const ArgumentPtr &rhs, - const ComparatorOptions &options) { - - if (!is(rhs)) { - return !options.termOrderInversed ? Ordering::greater : Ordering::less; - } - - if (const auto res = compareTerms(lhs, rhs, options); res != Ordering::equal) { - return res; - } - - if (!is(lhs->getFunction())) { - return !options.termOrderInversed ? Ordering::greater : Ordering::less; - } - - if (const auto res = compareTerms(lhs, rhs, options); res != Ordering::equal) { - return res; - } - - if (const auto lhsOper = cast(lhs->getFunction())) { - switch (lhsOper->getPriority()) { - case IOperator::Priority::PostfixUnary: - case IOperator::Priority::PrefixUnary: { - if (const Ordering res = compare(lhs->getChildren().front(), rhs); res != Ordering::equal) { - return res; - } - - return Ordering::less; - } - case IOperator::Priority::Exponentiation: - case IOperator::Priority::Multiplication: { - const ArgumentPtr rhsExpr = makeExpr(*lhsOper, rhs, Integer(1).clone()); - const Ordering res = compare(lhs, rhsExpr); - return options.termOrderInversed ? reverse(res) : res; - } - default: { - break; - } - } - } - - return !options.termOrderInversed ? Ordering::greater : Ordering::less; -} - -Ordering compareFunctions(const std::shared_ptr &lhs, - const std::shared_ptr &rhs, - const ComparatorOptions &options) { - - if (is(lhs) && !is(rhs)) { - return options.termOrderInversed ? Ordering::greater : Ordering::less; - } - if (!is(lhs) && is(rhs)) { - return !options.termOrderInversed ? Ordering::greater : Ordering::less; - } - - if (*lhs == *rhs) { - return Ordering::equal; - } - - if (lhs->getClass() != rhs->getClass()) { - return lhs->getClass() < rhs->getClass() ? Ordering::greater : Ordering::less; - } - - return lhs->toString() < rhs->toString() ? Ordering::greater : Ordering::less; -} - -ChildrenComparatorResult compareChildren(const ArgumentPtrVector &lhsChildren, - const ArgumentPtrVector &rhsChildren, - const ComparatorOptions &options) { - - ChildrenComparatorResult result = {}; - - const size_t lhsStart = getPositionOfFirstChildWithTerm(lhsChildren); - const size_t rhsStart = getPositionOfFirstChildWithTerm(rhsChildren); - - for (size_t i = lhsStart, j = rhsStart; i < lhsChildren.size() && j < rhsChildren.size(); i++, j++) { - ArgumentPtr compLhs = lhsChildren[i]; - ArgumentPtr compRhs = rhsChildren[j]; - - const bool isLhsUnary = unwrapUnaryExpression(compLhs); - const bool isRhsUnary = unwrapUnaryExpression(compRhs); - - if (isLhsUnary && isRhsUnary) { - compLhs = lhsChildren[i]; - compRhs = rhsChildren[j]; - } - - if (result.postfixUnary == Ordering::equal && isLhsUnary != isRhsUnary) { - result.postfixUnary = !isLhsUnary ? Ordering::greater : Ordering::less; - } - - if (result.postfix == Ordering::equal) { - result.postfix = compare(compLhs, compRhs, options); - } - - if (result.postfix != Ordering::equal) { - break; - } - } - - if (result.postfix == Ordering::equal) { - const size_t lhsPostfixSize = lhsChildren.size() - lhsStart; - const size_t rhsPostfixSize = rhsChildren.size() - rhsStart; - - if (lhsPostfixSize != rhsPostfixSize) { - result.postfix = lhsPostfixSize > rhsPostfixSize ? Ordering::greater : Ordering::less; - } - } - - if (lhsChildren.size() != rhsChildren.size()) { - result.postfixUnary = Ordering::equal; - } - - auto size = std::min(std::max(lhsStart, rhsStart), - std::min(lhsChildren.size(), rhsChildren.size())); - - for (const auto i : stdv::iota(0U, size)) { - const Ordering childrenComp = compare(lhsChildren[i], rhsChildren[i], options); - - if (childrenComp != Ordering::equal) { - result.prefixLast = childrenComp; - } - - if (result.prefixFirst == Ordering::equal) { - result.prefixFirst = childrenComp; - } - - if (result.prefixVariables == Ordering::equal) { - result.prefixVariables = compareTerms(lhsChildren[i], rhsChildren[i], {}); - } - - if (result.prefixLiterals == Ordering::equal) { - result.prefixLiterals = compareTerms(lhsChildren[i], rhsChildren[i], {}); - } - - if (result.prefixLiterals != Ordering::equal && result.prefixLast != Ordering::equal) { - break; - } - } - - if (lhsChildren.size() != rhsChildren.size()) { - result.size = lhsChildren.size() > rhsChildren.size() ? Ordering::greater : Ordering::less; - } - - return result; -} - -bool unwrapUnaryExpression(ArgumentPtr &arg) { - if (const auto expr = cast(arg); - expr && - expr->getFunction()->getArgumentClasses().size() == 1) { - - arg = expr->getChildren().front(); - return true; - } - - return false; -} - -bool unwrapEmptyExpression(ArgumentPtr &arg) { - if (const auto expr = cast(arg); - expr && - !expr->getFunction()) { - - arg = expr->getChildren().front(); - return true; - } - - return false; -} - -Ordering reverse(const Ordering ordering) { - return 0 <=> ordering; -} - -} diff --git a/src/fintamath/expressions/ExpressionFunctions.cpp b/src/fintamath/expressions/ExpressionFunctions.cpp deleted file mode 100644 index d0ff9aae9..000000000 --- a/src/fintamath/expressions/ExpressionFunctions.cpp +++ /dev/null @@ -1,251 +0,0 @@ -#include "fintamath/expressions/ExpressionFunctions.hpp" - -#include "fintamath/expressions/Expression.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" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/arithmetic/Sub.hpp" -#include "fintamath/functions/calculus/Derivative.hpp" -#include "fintamath/functions/comparison/Eqv.hpp" -#include "fintamath/functions/comparison/Less.hpp" -#include "fintamath/functions/comparison/LessEqv.hpp" -#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" -#include "fintamath/functions/logarithms/Log.hpp" -#include "fintamath/functions/logic/And.hpp" -#include "fintamath/functions/logic/Not.hpp" -#include "fintamath/functions/logic/Or.hpp" -#include "fintamath/functions/ntheory/Ceil.hpp" -#include "fintamath/functions/ntheory/Floor.hpp" -#include "fintamath/functions/ntheory/Mod.hpp" -#include "fintamath/functions/other/Factorial.hpp" -#include "fintamath/functions/powers/Exp.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/functions/powers/Sqrt.hpp" -#include "fintamath/functions/trigonometry/Acos.hpp" -#include "fintamath/functions/trigonometry/Acot.hpp" -#include "fintamath/functions/trigonometry/Asin.hpp" -#include "fintamath/functions/trigonometry/Atan.hpp" -#include "fintamath/functions/trigonometry/Cos.hpp" -#include "fintamath/functions/trigonometry/Cot.hpp" -#include "fintamath/functions/trigonometry/Sin.hpp" -#include "fintamath/functions/trigonometry/Tan.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 { - -Expression operator+(const Expression &lhs, const Expression &rhs) { - return Expression(addExpr(lhs, rhs)); -} - -Expression operator+(const Expression &rhs) { - return rhs; -} - -Expression operator-(const Expression &lhs, const Expression &rhs) { - return Expression(subExpr(lhs, rhs)); -} - -Expression operator-(const Expression &rhs) { - return Expression(negExpr(rhs)); -} - -Expression operator*(const Expression &lhs, const Expression &rhs) { - return Expression(mulExpr(lhs, rhs)); -} - -Expression operator/(const Expression &lhs, const Expression &rhs) { - return Expression(divExpr(lhs, rhs)); -} - -Expression mod(const Expression &lhs, const Expression &rhs) { - return Expression(modExpr(lhs, rhs)); -} - -Expression eqv(const Expression &lhs, const Expression &rhs) { - return Expression(eqvExpr(lhs, rhs)); -} - -Expression neqv(const Expression &lhs, const Expression &rhs) { - return Expression(neqvExpr(lhs, rhs)); -} - -Expression less(const Expression &lhs, const Expression &rhs) { - return Expression(lessExpr(lhs, rhs)); -} - -Expression more(const Expression &lhs, const Expression &rhs) { - return Expression(moreExpr(lhs, rhs)); -} - -Expression lessEqv(const Expression &lhs, const Expression &rhs) { - return Expression(lessEqvExpr(lhs, rhs)); -} - -Expression moreEqv(const Expression &lhs, const Expression &rhs) { - return Expression(moreEqvExpr(lhs, rhs)); -} - -Expression floor(const Expression &rhs) { - return Expression(floorExpr(rhs)); -} - -Expression ceil(const Expression &rhs) { - return Expression(ceilExpr(rhs)); -} - -Expression abs(const Expression &rhs) { - return Expression(absExpr(rhs)); -} - -Expression factorial(const Expression &rhs) { - return Expression(factorialExpr(rhs)); -} - -Expression sqrt(const Expression &rhs) { - return Expression(sqrtExpr(rhs)); -} - -Expression pow(const Expression &lhs, const Expression &rhs) { - return Expression(powExpr(lhs, rhs)); -} - -Expression exp(const Expression &rhs) { - return Expression(expExpr(rhs)); -} - -Expression log(const Expression &lhs, const Expression &rhs) { - return Expression(logExpr(lhs, rhs)); -} - -Expression ln(const Expression &rhs) { - return Expression(lnExpr(rhs)); -} - -Expression lb(const Expression &rhs) { - return Expression(lbExpr(rhs)); -} - -Expression lg(const Expression &rhs) { - return Expression(lgExpr(rhs)); -} - -Expression sin(const Expression &rhs) { - return Expression(sinExpr(rhs)); -} - -Expression cos(const Expression &rhs) { - return Expression(cosExpr(rhs)); -} - -Expression tan(const Expression &rhs) { - return Expression(tanExpr(rhs)); -} - -Expression cot(const Expression &rhs) { - return Expression(cotExpr(rhs)); -} - -Expression asin(const Expression &rhs) { - return Expression(asinExpr(rhs)); -} - -Expression acos(const Expression &rhs) { - return Expression(acosExpr(rhs)); -} - -Expression atan(const Expression &rhs) { - return Expression(atanExpr(rhs)); -} - -Expression acot(const Expression &rhs) { - return Expression(acotExpr(rhs)); -} - -Expression sinh(const Expression &rhs) { - return Expression(sinhExpr(rhs)); -} - -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 derivative(const Expression &lhs, const Expression &rhs) { - return Expression(derivativeExpr(lhs, rhs)); -} - -Expression notL(const Expression &rhs) { - return Expression(notExpr(rhs)); -} - -Expression andL(const Expression &lhs, const Expression &rhs) { - return Expression(andExpr(lhs, rhs)); -} - -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/src/fintamath/expressions/ExpressionUtils.cpp b/src/fintamath/expressions/ExpressionUtils.cpp deleted file mode 100644 index 99ad079c3..000000000 --- a/src/fintamath/expressions/ExpressionUtils.cpp +++ /dev/null @@ -1,395 +0,0 @@ -#include "fintamath/expressions/ExpressionUtils.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/powers/Pow.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/numbers/Complex.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath::detail { - -const ArgumentPtr one = Integer(1).clone(); - -bool isExpression(const IMathObject &arg) { - return is(arg); -} - -bool isInfinity(const ArgumentPtr &arg) { - return is(arg) || is(arg) || is(arg); -} - -bool isMulInfinity(const ArgumentPtr &arg) { - auto [rate, value] = splitMulExpr(arg); - return isInfinity(rate) || isInfinity(value); -} - -bool isNegated(const ArgumentPtr &arg) { - if (isNegativeNumber(arg)) { - return true; - } - - const auto expr = cast(arg); - if (!expr) { - return false; - } - - if (is(expr->getFunction()) || is
(expr->getFunction())) { - return isNegated(expr->getChildren().front()); - } - - if (is(expr->getFunction())) { - return isNegativeNumber(expr->getChildren().front()); - } - - return false; -} - -bool isNegativeNumber(const ArgumentPtr &arg) { - const auto argNum = cast(arg); - return argNum && *argNum < Integer(0); -} - -bool isComplexNumber(const ArgumentPtr &arg) { - const auto num = cast(arg); - return num && num->isComplex(); -} - -bool containsIf(const ArgumentPtr &arg, const std::function &comp) { - if (comp(arg)) { - return true; - } - - const auto expr = cast(arg); - if (!expr) { - return false; - } - - const ArgumentPtrVector &children = expr->getChildren(); - - return stdr::any_of(children, [&comp](const auto &child) { - bool res = false; - - if (containsIf(child, comp)) { - res = true; - } - - return res; - }); -} - -bool containsChild(const ArgumentPtr &arg, const ArgumentPtr &child) { - return containsIf(arg, [&child](const ArgumentPtr &compArg) { - return *compArg == *child; - }); -} - -bool containsVariable(const ArgumentPtr &arg) { - return containsIf(arg, [](const ArgumentPtr &compArg) { - return is(compArg); - }); -} - -bool containsVariable(const ArgumentPtr &arg, const Variable &var) { - return containsIf(arg, [&var](const ArgumentPtr &compArg) { - return *compArg == var; - }); -} - -bool containsInfinity(const ArgumentPtr &arg) { - return containsIf(arg, [](const ArgumentPtr &compArg) { - return isInfinity(compArg); - }); -} - -bool containsComplex(const ArgumentPtr &arg) { - return containsIf(arg, [](const ArgumentPtr &compArg) { - return isComplexNumber(compArg); - }); -} - -std::pair splitMulExpr(const ArgumentPtr &inChild, const bool checkVariables) { - const auto mulExprChild = cast(inChild); - - if (!mulExprChild || !is(mulExprChild->getFunction())) { - return {one, inChild}; - } - - const ArgumentPtrVector &mulExprChildren = mulExprChild->getChildren(); - size_t i = 0; - - if (checkVariables) { - for (; i < mulExprChildren.size(); i++) { - if (containsVariable(mulExprChildren[i])) { - break; - } - } - } - else { - for (; i < mulExprChildren.size(); i++) { - if (!is(mulExprChildren[i])) { - break; - } - } - } - - ArgumentPtr rate = makePolynom(Mul{}, - ArgumentPtrVector(mulExprChildren.begin(), - mulExprChildren.begin() + static_cast(i))); - ArgumentPtr value = makePolynom(Mul{}, - ArgumentPtrVector(mulExprChildren.begin() + static_cast(i), - mulExprChildren.end())); - - if (!rate) { - rate = one; - } - - if (!value) { - value = checkVariables ? one : inChild; - } - - return {rate, value}; -} - -std::pair splitPowExpr(const ArgumentPtr &rhs) { - if (const auto &powExpr = cast(rhs); powExpr && is(powExpr->getFunction())) { - const ArgumentPtrVector &powExprChildren = powExpr->getChildren(); - return {powExprChildren[0], powExprChildren[1]}; - } - - return {rhs, one}; -} - -std::pair splitRational(const ArgumentPtr &arg) { - if (const auto rat = cast(arg)) { - return {rat->numerator().clone(), rat->denominator().clone()}; - } - - if (const auto complex = cast(arg)) { - ArgumentPtr reNumerator; - ArgumentPtr imNumerator; - Integer denominator = 1; - - const auto *reRat = cast(&complex->real()); - const auto *imRat = cast(&complex->imag()); - - if (reRat && imRat) { - denominator = lcm(reRat->denominator(), imRat->denominator()); - reNumerator = (denominator / reRat->denominator() * reRat->numerator()).clone(); - imNumerator = (denominator / imRat->denominator() * imRat->numerator()).clone(); - } - else if (reRat) { - denominator = reRat->denominator(); - reNumerator = reRat->numerator().clone(); - imNumerator = complex->imag() * denominator; - } - else if (imRat) { - denominator = imRat->denominator(); - reNumerator = complex->real() * denominator; - imNumerator = imRat->numerator().clone(); - } - - const auto reNumeratorNum = cast(reNumerator); - const auto imNumeratorNum = cast(imNumerator); - - if (denominator != 1 && reNumeratorNum && imNumeratorNum) { - return {Complex(*reNumeratorNum, *imNumeratorNum).clone(), denominator.clone()}; - } - } - - return {arg, Integer(1).clone()}; -} - -ArgumentPtr negate(const ArgumentPtr &arg) { - if (const auto expr = cast(arg)) { - if (is(expr->getFunction())) { - auto negChildrenView = - expr->getChildren() | - stdv::transform([](const ArgumentPtr &child) { - return negate(child); - }); - return makePolynom(Add{}, ArgumentPtrVector(negChildrenView.begin(), negChildrenView.end())); // TODO: use C++23 stdv::to - } - - if (is(expr->getFunction())) { - if (const auto firstChildNum = cast(expr->getChildren().front())) { - if (*firstChildNum == Integer(-1)) { - ArgumentPtrVector negChildren(expr->getChildren().begin() + 1, expr->getChildren().end()); - return makePolynom(Mul(), std::move(negChildren)); - } - - ArgumentPtrVector negChildren = expr->getChildren(); - negChildren.front() = (*firstChildNum) * Integer(-1); - return makePolynom(Mul(), std::move(negChildren)); - } - } - } - else if (const auto arithm = cast(arg)) { - return (*arithm) * Integer(-1); - } - - return mulExpr(Integer(-1).clone(), arg); -} - -ArgumentPtr makePolynom(const IFunction &func, ArgumentPtrVector &&args) { - if (args.empty()) { - return {}; - } - - if (args.size() == 1) { - return args.front(); - } - - return makeExpr(func, std::move(args)); -} - -ArgumentPtr makePolynom(const IFunction &func, const ArgumentPtrVector &args) { - return makePolynom(func, ArgumentPtrVector(args)); -} - -ArgumentPtrVector getPolynomChildren(const IFunction &func, const ArgumentPtr &arg) { - if (const auto expr = cast(arg); expr && *expr->getFunction() == func) { - return expr->getChildren(); - } - - return {arg}; -} - -std::vector argumentVectorToStringVector(const ArgumentPtrVector &args) { - std::vector argStrings(args.size()); - - for (const auto i : stdv::iota(0U, argStrings.size())) { - argStrings[i] = args[i].get()->toString(); - } - - return argStrings; -} - -ArgumentPtrVector argumentRefVectorToArgumentPtrVector(const ArgumentRefVector &args) { - ArgumentPtrVector argsPtrVect; - - for (const auto &arg : args) { - argsPtrVect.emplace_back(arg.get().clone()); - } - - return argsPtrVect; -} - -std::string putInBrackets(const std::string &str) { - return '(' + str + ')'; -} - -std::string putInSpaces(const std::string &str) { - return ' ' + str + ' '; -} - -std::string functionToString(const IFunction &func, const ArgumentPtrVector &args) { - static const std::string delimiter = ", "; - - std::string result = func.toString() + "("; - - for (const auto &arg : args) { - result += arg->toString() + delimiter; - } - - result = result.substr(0, result.size() - delimiter.size()) + ")"; - - return result; -} - -std::string operatorChildToString(const IOperator &oper, const ArgumentPtr &child) { - std::string childStr = child->toString(); - std::shared_ptr childOper; - - if (const auto childExpr = cast(child)) { - childOper = cast(childExpr->getOutputFunction()); - } - else if (const auto childComplex = cast(child)) { - if (childComplex->real() != Integer(0)) { - childOper = std::make_shared(); - } - else if (childComplex->imag() != Integer(1)) { - if (childComplex->imag() == Integer(-1)) { - childOper = std::make_shared(); - } - else { - childOper = std::make_shared(); - } - } - } - else if (childStr.front() == Neg{}.toString().front()) { - childOper = std::make_shared(); - } - else if (is(child)) { - childOper = std::make_shared
(); - } - else if (is(child)) { - if (childStr.find(Mul{}.toString()) != std::string::npos) { - childOper = std::make_shared(); - } - } - - bool shouldPutInBrackets = false; - - if (childOper) { - if (oper.getPriority() == IOperator::Priority::PostfixUnary) { - shouldPutInBrackets = true; - } - else if (childOper->getArgumentClasses().size() == 1) { - shouldPutInBrackets = childOper->getPriority() >= oper.getPriority(); - } - else { - shouldPutInBrackets = childOper->getPriority() > oper.getPriority() || - !oper.isAssociative(); - } - } - - return shouldPutInBrackets ? putInBrackets(childStr) : childStr; -} - -std::string binaryOperatorToString(const IOperator &oper, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - std::string operStr = oper.toString(); - const IOperator::Priority operPriority = oper.getPriority(); - - if (operPriority != IOperator::Priority::Multiplication && operPriority != IOperator::Priority::Exponentiation) { - operStr = ' ' + operStr + ' '; - } - - const std::string lhsStr = operatorChildToString(oper, lhs); - const std::string rhsStr = operatorChildToString(oper, rhs); - - return lhsStr + operStr + rhsStr; -} - -std::string prefixUnaryOperatorToString(const IOperator &oper, const ArgumentPtr &rhs) { - return oper.toString() + operatorChildToString(oper, rhs); -} - -std::string postfixUnaryOperatorToString(const IOperator &oper, const ArgumentPtr &rhs) { - return operatorChildToString(oper, rhs) + oper.toString(); -} - -} diff --git a/src/fintamath/expressions/FunctionExpression.cpp b/src/fintamath/expressions/FunctionExpression.cpp deleted file mode 100644 index 82a16c578..000000000 --- a/src/fintamath/expressions/FunctionExpression.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "fintamath/expressions/FunctionExpression.hpp" - -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/IOperator.hpp" - -namespace fintamath { - -using namespace detail; - -FunctionExpression::FunctionExpression(const IFunction &inFunc, ArgumentPtrVector inChildren) - : func(cast(inFunc.clone())) { - - for (auto &&child : std::move(inChildren)) { - children.emplace_back(std::move(child)); - } -} - -std::string FunctionExpression::toString() const { - if (const auto oper = cast(func)) { - if (oper->getPriority() == IOperator::Priority::PostfixUnary) { - return postfixUnaryOperatorToString(*oper, children.front()); - } - - if (oper->getPriority() == IOperator::Priority::PrefixUnary) { - return prefixUnaryOperatorToString(*oper, children.front()); - } - - return binaryOperatorToString(*oper, children.front(), children.back()); - } - - return functionToString(*func, children); -} - -const std::shared_ptr &FunctionExpression::getFunction() const { - return func; -} - -const ArgumentPtrVector &FunctionExpression::getChildren() const { - return children; -} - -ArgumentPtr FunctionExpression::preSimplify() const { - auto simpl = cast(clone()); - - for (auto &child : simpl->children) { - preSimplifyChild(child); - } - - return simpl; -} - -ArgumentPtr FunctionExpression::postSimplify() const { - auto simpl = cast(clone()); - ArgumentRefVector args; - - for (auto &child : simpl->children) { - postSimplifyChild(child); - args.emplace_back(*child); - } - - if (!func->doArgsMatch(args)) { - return simpl; - } - - return callFunction(*simpl->func, argumentRefVectorToArgumentPtrVector(args)); -} - -void FunctionExpression::setChildren(const ArgumentPtrVector &childVect) { - if (childVect.size() != func->getArgumentClasses().size()) { - throw InvalidInputFunctionException(func->toString(), argumentVectorToStringVector(childVect)); - } - - children = childVect; -} -} diff --git a/src/fintamath/expressions/FunctionExpression.hpp b/src/fintamath/expressions/FunctionExpression.hpp deleted file mode 100644 index 2e0640e0a..000000000 --- a/src/fintamath/expressions/FunctionExpression.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class FunctionExpression final : public IExpressionCRTP { - FINTAMATH_CLASS_BODY(FunctionExpression) - -public: - explicit FunctionExpression(const IFunction &inFunc, ArgumentPtrVector inChildren); - - std::string toString() const override; - - const std::shared_ptr &getFunction() const override; - - const ArgumentPtrVector &getChildren() const override; - - void setChildren(const ArgumentPtrVector &childVect) override; - -protected: - ArgumentPtr preSimplify() const override; - - ArgumentPtr postSimplify() const override; - -private: - std::shared_ptr func; - - ArgumentPtrVector children; -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/IExpression.cpp b/src/fintamath/expressions/IExpression.cpp deleted file mode 100644 index 5a358a5d4..000000000 --- a/src/fintamath/expressions/IExpression.cpp +++ /dev/null @@ -1,364 +0,0 @@ -#include "fintamath/expressions/IExpression.hpp" - -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/Converter.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/literals/constants/IConstant.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -using namespace detail; - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IExpression) - -std::vector IExpression::getVariables() const { - std::vector vars; - - for (const auto &child : getChildren()) { - if (auto var = cast(child)) { - vars.emplace_back(*var); - } - else if (const auto childExpr = cast(child)) { - std::vector childVars = childExpr->getVariables(); - vars.insert(vars.end(), childVars.begin(), childVars.end()); - } - } - - stdr::sort(vars, std::less{}, &Variable::toString); - auto unique = stdr::unique(vars); - vars.erase(unique.begin(), unique.end()); - - return vars; -} - -void IExpression::setVariables(const std::vector> &varsToVals) { - const ArgumentPtrVector &children = getChildren(); - ArgumentPtrVector newChildren; - - for (const auto &child : children) { - if (is(child)) { - std::shared_ptr exprChild = cast(child->clone()); - exprChild->setVariables(varsToVals); - newChildren.emplace_back(std::move(exprChild)); - continue; - } - - bool isAdded = false; - - if (const auto varChild = cast(child)) { - for (const auto &[var, val] : varsToVals) { - if (*varChild == var) { - newChildren.push_back(val); - isAdded = true; - break; - } - } - } - - if (!isAdded) { - newChildren.emplace_back(child); - } - } - - setChildren(newChildren); -} - -std::unique_ptr IExpression::toMinimalObject() const { - return simplify()->clone(); -} - -const std::shared_ptr &IExpression::getOutputFunction() const { - return getFunction(); -} - -ArgumentPtr IExpression::simplify() const { - ArgumentPtr simpl = cast(clone()); - preSimplifyChild(simpl); - postSimplifyChild(simpl); - return simpl; -} - -void IExpression::simplifyChild(ArgumentPtr &child) { - if (const auto exprChild = cast(child)) { - if (const auto simplObj = exprChild->simplify()) { - child = simplObj; - } - } -} - -void IExpression::preSimplifyChild(ArgumentPtr &child) { - if (const auto exprChild = cast(child)) { - if (const auto simplObj = exprChild->preSimplify()) { - child = simplObj; - } - } - else { - if (const auto constChild = cast(child)) { - const ArgumentPtr constVal = (*constChild)(); - - if (const auto num = cast(constVal); num && !num->isPrecise()) { - child = constChild; - } - else { - child = constVal; - } - } - - child = child->toMinimalObject(); - } -} - -void IExpression::postSimplifyChild(ArgumentPtr &child) { - if (const auto exprChild = cast(child)) { - if (const auto simplObj = exprChild->postSimplify()) { - child = simplObj; - } - } -} - -void IExpression::approximateChild(ArgumentPtr &child) { - if (const auto constChild = cast(child)) { - child = (*constChild)(); - } - else if (const auto exprChild = cast(child)) { - child = exprChild->approximate(); - } -} - -void IExpression::setPrecisionChild(ArgumentPtr &child, const unsigned precision, const Integer &maxInt) { - if (const auto numChild = cast(child)) { - if (auto res = convertToApproximated(*numChild, precision, maxInt)) { - child = std::move(res); - } - } - else if (const auto exprChild = cast(child)) { - child = exprChild->setPrecision(precision, maxInt); - } -} - -std::unique_ptr IExpression::convertToApproximated(const INumber &num) { - static const auto multiApproximate = [] { - static MultiMethod(const INumber &)> outMultiApproximate; - - outMultiApproximate.add([](const Integer &inRhs) { - return Real(inRhs).clone(); - }); - - outMultiApproximate.add([](const Rational &inRhs) { - return Real(inRhs).clone(); - }); - - outMultiApproximate.add([](const Complex &inRhs) { - return Complex( - *convert(inRhs.real()), - *convert(inRhs.imag())) - .clone(); - }); - - return outMultiApproximate; - }(); - - return cast(multiApproximate(num)); -} - -std::unique_ptr IExpression::convertToApproximated(const INumber &num, - const unsigned precision, - const Integer &maxInt) { - - static const auto multiSetPrecision = [] { - static MultiMethod(const INumber &, - const Integer &, - const Integer &)> - outMultiSetPrecision; - - outMultiSetPrecision.add([](const Integer &inRhs, - const Integer & /*inPrecision*/, - const Integer &inMaxInt) { - if (inRhs >= inMaxInt) { - return Real(inRhs).clone(); - } - - return std::unique_ptr{}; - }); - - outMultiSetPrecision.add([](const Rational &inRhs, - const Integer & /*inPrecision*/, - const Integer & /*inMaxInt*/) { - return Real(inRhs).clone(); - }); - - outMultiSetPrecision.add([](const Real &inRhs, - const Integer & /*inPrecision*/, - const Integer & /*inMaxInt*/) { - auto res = cast(inRhs.clone()); - res->setOutputPrecision(Real::getPrecision()); - return res; - }); - - outMultiSetPrecision.add([](const Complex &inRhs, - const Integer &inPrecision, - const Integer &inMaxInt) { - const auto approxReal = convertToApproximated(inRhs.real(), static_cast(inPrecision), inMaxInt); - const auto approxImag = convertToApproximated(inRhs.imag(), static_cast(inPrecision), inMaxInt); - - if (!approxReal && !approxImag) { - return std::unique_ptr{}; - } - - if (!approxReal) { - return Complex(inRhs.real(), *approxImag).clone(); - } - - if (!approxImag) { - return Complex(*approxReal, inRhs.imag()).clone(); - } - - return Complex(*approxReal, *approxImag).clone(); - }); - - return outMultiSetPrecision; - }(); - - return cast(multiSetPrecision(num, Integer(precision), maxInt)); -} - -ArgumentPtrVector IExpression::convertToApproximatedNumbers(const ArgumentPtrVector &args) { - ArgumentPtrVector approxArgs = args; - - for (auto &arg : approxArgs) { - if (const auto argNum = cast(arg); argNum) { - if (auto argConv = convertToApproximated(*argNum)) { - arg = std::move(argConv); - } - } - } - - return approxArgs; -} - -ArgumentPtr IExpression::callFunction(const IFunction &func, const ArgumentPtrVector &argPtrs) { - if (!func.isEvaluatable()) { - return {}; - } - - ArgumentRefVector args; - bool areArgumentsPrecise = true; - - for (const auto &argPtr : argPtrs) { - args.emplace_back(*argPtr); - - if (const auto num = cast(argPtr); num && !num->isPrecise()) { - areArgumentsPrecise = false; - } - } - - if (!func.doArgsMatch(args)) { - return {}; - } - - ArgumentPtr res = func(args); - - if (areArgumentsPrecise) { - if (const auto num = cast(res); num && !num->isPrecise()) { - return {}; - } - } - - return res; -} - -ArgumentPtr IExpression::preSimplify() const { - return {}; -} - -ArgumentPtr IExpression::postSimplify() const { - return {}; -} - -ArgumentPtr IExpression::approximate() const { - ArgumentPtr simpl = simplify(); - - if (!is(simpl)) { - approximateChild(simpl); - return simpl; - } - - const auto simplExpr = cast(simpl); - ArgumentPtrVector approxChildren = simplExpr->getChildren(); - - bool areNumberChilrenPrecise = true; - size_t numberChildrenCount = 0; - - for (auto &child : approxChildren) { - approximateChild(child); - - if (const auto childNum = cast(child)) { - numberChildrenCount++; - - if (!childNum->isPrecise()) { - areNumberChilrenPrecise = false; - } - } - } - - auto approxExpr = cast(simplExpr->clone()); - approxExpr->setChildren(approxChildren); - - const bool containsVar = containsVariable(simplExpr); - - if (containsVar && - (numberChildrenCount < 2 || - approxChildren.size() == getFunction()->getArgumentClasses().size())) { - - return approxExpr; - } - - ArgumentPtr approxSimpl = approxExpr->simplify(); - const auto approxSimplExpr = cast(approxSimpl); - - if (!approxSimplExpr || *approxSimplExpr != *approxExpr) { - return approxSimpl; - } - - if (!containsVar && areNumberChilrenPrecise) { - if (auto res = callFunction(*approxSimplExpr->getFunction(), - convertToApproximatedNumbers(approxSimplExpr->getChildren())); - is(res)) { - - return res; - } - } - - return approxSimpl; -} - -ArgumentPtr IExpression::setPrecision(const unsigned precision, const Integer &maxInt) const { - ArgumentPtrVector newChildren = getChildren(); - - for (auto &child : newChildren) { - setPrecisionChild(child, precision, maxInt); - } - - auto newExprArg = cast(clone()); - newExprArg->setChildren(newChildren); - return newExprArg; -} - -} diff --git a/src/fintamath/expressions/binary/CompExpr.cpp b/src/fintamath/expressions/binary/CompExpr.cpp deleted file mode 100644 index e7f16fc07..000000000 --- a/src/fintamath/expressions/binary/CompExpr.cpp +++ /dev/null @@ -1,259 +0,0 @@ -#include "fintamath/expressions/binary/CompExpr.hpp" - -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/arithmetic/Sub.hpp" -#include "fintamath/functions/comparison/Eqv.hpp" -#include "fintamath/functions/comparison/Less.hpp" -#include "fintamath/functions/comparison/LessEqv.hpp" -#include "fintamath/functions/comparison/More.hpp" -#include "fintamath/functions/comparison/MoreEqv.hpp" -#include "fintamath/functions/comparison/Neqv.hpp" -#include "fintamath/literals/Boolean.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 { - -using namespace detail; - -CompExpr::CompExpr(const IOperator &inOper, ArgumentPtr inLhsChild, ArgumentPtr inRhsChild) - : IBinaryExpressionCRTP(inOper, std::move(inLhsChild), std::move(inRhsChild)) { -} - -std::string CompExpr::toString() const { - if (isSolution) { - if (const auto lhsExpr = cast(lhsChild); - lhsExpr && - *lhsExpr->getFunction() == Add{}) { - - ArgumentPtrVector sumChildren = lhsExpr->getChildren(); - ArgumentPtr solLhs = sumChildren.front(); - - if (is(solLhs)) { - sumChildren.erase(sumChildren.begin()); - ArgumentPtr solRhs = detail::negate(makePolynom(Add{}, std::move(sumChildren))); - return CompExpr(cast(*func), std::move(solLhs), std::move(solRhs)).toString(); - } - } - } - - return IBinaryExpression::toString(); -} - -ArgumentPtr CompExpr::preSimplify() const { - auto simpl = IBinaryExpression::preSimplify(); - - if (const auto simplExpr = cast(simpl)) { - if (!simplExpr->isSolution && - (!is(simplExpr->rhsChild) || *simplExpr->rhsChild != Integer(0))) { - - if (*func != Eqv{} && - *func != Neqv{} && - (containsComplex(simplExpr->lhsChild) || containsComplex(simplExpr->rhsChild))) { - - return simpl; - } - - if (!containsInfinity(simplExpr->lhsChild) && !containsInfinity(simplExpr->rhsChild)) { - ArgumentPtr resLhs = subExpr(simplExpr->lhsChild, simplExpr->rhsChild); - preSimplifyChild(resLhs); - return CompExpr(cast(*func), resLhs, Integer(0).clone()).clone(); - } - } - } - - return simpl; -} - -CompExpr::SimplifyFunctionVector CompExpr::getFunctionsForPreSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &CompExpr::constSimplify, - }; - return simplifyFunctions; -} - -CompExpr::SimplifyFunctionVector CompExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &CompExpr::constSimplify, - &CompExpr::divSimplify, - &CompExpr::negSimplify, - &CompExpr::rateSimplify, - &CompExpr::approxSimplify, - }; - return simplifyFunctions; -} - -void CompExpr::markAsSolution() { - isSolution = true; -} - -std::shared_ptr CompExpr::getOppositeFunction(const IFunction &function) { - static const std::unordered_map> nameToOppositeFuncMap = { - {Eqv{}.toString(), std::make_shared()}, - {Neqv{}.toString(), std::make_shared()}, - {More{}.toString(), std::make_shared()}, - {Less{}.toString(), std::make_shared()}, - {MoreEqv{}.toString(), std::make_shared()}, - {LessEqv{}.toString(), std::make_shared()}, - }; - return nameToOppositeFuncMap.at(function.toString()); -} - -ArgumentPtr CompExpr::constSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (is(lhs) || is(rhs)) { - // TODO: return LogicUndefined - return makeExpr(func, Undefined(), Undefined()); - } - - if ((is(lhs) && containsInfinity(rhs)) || - (is(rhs) && containsInfinity(lhs))) { - - return {}; - } - - if (*lhs == *rhs) { - Boolean res = is(func) || is(func) || is(func); - return std::move(res).clone(); - } - - if (is(lhs) && is(rhs)) { - Boolean res = is(func) || is(func) || is(func); - return std::move(res).clone(); - } - - if (is(lhs) && is(rhs)) { - Boolean res = is(func) || is(func) || is(func); - return std::move(res).clone(); - } - - if ((isInfinity(lhs) && !containsInfinity(rhs)) || - (isInfinity(rhs) && !containsInfinity(lhs))) { - - if (is(func)) { - return Boolean(false).clone(); - } - - if (is(func)) { - return Boolean(true).clone(); - } - } - - return {}; -} - -ArgumentPtr CompExpr::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); - } - - return {}; -} - -ArgumentPtr CompExpr::negSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (*rhs != Integer(0)) { - return {}; - } - - if (isNegated(lhs)) { - ArgumentPtr newLhs = negExpr(lhs); - return makeExpr(*cast(getOppositeFunction(func)), std::move(newLhs), rhs); - } - - return {}; -} - -ArgumentPtr CompExpr::rateSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (*rhs != Integer(0)) { - return {}; - } - - auto lhsExpr = cast(lhs); - if (!lhsExpr) { - return {}; - } - - if (func != Eqv{} && - func != Neqv{} && - (containsComplex(lhs) || containsComplex(rhs))) { - - return {}; - } - - ArgumentPtrVector children; - std::shared_ptr firstChildMulExpr; - - if (is(lhsExpr->getFunction())) { - children = lhsExpr->getChildren(); - firstChildMulExpr = cast(lhsExpr->getChildren().front()); - } - else { - children.emplace_back(lhsExpr); - firstChildMulExpr = lhsExpr; - } - - auto [rate, value] = splitMulExpr(firstChildMulExpr); - if (*rate == Integer(1) || containsInfinity(rate)) { - return {}; - } - - for (auto &child : stdv::drop(children, 1)) { - child = divExpr(child, rate); - } - - { - ArgumentPtrVector newChildren = firstChildMulExpr->getChildren(); - newChildren.erase(newChildren.begin()); - children.front() = makePolynom(Mul{}, std::move(newChildren)); - } - - ArgumentPtr newLhs = makePolynom(Add{}, std::move(children)); - simplifyChild(newLhs); - - approximateChild(rate); - if (isNegativeNumber(rate)) { - return makeExpr(*cast(getOppositeFunction(func)), newLhs, rhs); - } - - return makeExpr(func, newLhs, rhs); -} - -ArgumentPtr CompExpr::approxSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (*rhs != Integer(0) || containsVariable(lhs)) { - return {}; - } - - ArgumentPtr approxLhs = lhs; - approximateChild(approxLhs); - if (!is(approxLhs)) { - return {}; - } - - ArgumentPtr res = func(*approxLhs, *rhs); - if (is(res)) { - return res; - } - - return {}; -} - -} diff --git a/src/fintamath/expressions/binary/CompExpr.hpp b/src/fintamath/expressions/binary/CompExpr.hpp deleted file mode 100644 index 225bfc9d7..000000000 --- a/src/fintamath/expressions/binary/CompExpr.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class IOperator; - -class CompExpr final : public IBinaryExpressionCRTP { - FINTAMATH_CLASS_BODY(CompExpr) - -public: - CompExpr(const IOperator &inOper, ArgumentPtr inLhsChild, ArgumentPtr inRhsChild); - - std::string toString() const override; - - void markAsSolution(); - -protected: - ArgumentPtr preSimplify() const override; - - SimplifyFunctionVector getFunctionsForPreSimplify() const override; - - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - - static std::shared_ptr getOppositeFunction(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 negSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr rateSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr approxSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - bool isSolution = false; -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/binary/DerivativeExpr.cpp b/src/fintamath/expressions/binary/DerivativeExpr.cpp deleted file mode 100644 index 340e86e08..000000000 --- a/src/fintamath/expressions/binary/DerivativeExpr.cpp +++ /dev/null @@ -1,416 +0,0 @@ -#include "fintamath/expressions/binary/DerivativeExpr.hpp" - -#include -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/arithmetic/Sub.hpp" -#include "fintamath/functions/calculus/Derivative.hpp" -#include "fintamath/functions/hyperbolic/Acosh.hpp" -#include "fintamath/functions/hyperbolic/Acoth.hpp" -#include "fintamath/functions/hyperbolic/Acsch.hpp" -#include "fintamath/functions/hyperbolic/Asech.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/Csch.hpp" -#include "fintamath/functions/hyperbolic/Sech.hpp" -#include "fintamath/functions/hyperbolic/Sinh.hpp" -#include "fintamath/functions/hyperbolic/Tanh.hpp" -#include "fintamath/functions/logarithms/Ln.hpp" -#include "fintamath/functions/logarithms/Log.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/functions/powers/Sqr.hpp" -#include "fintamath/functions/powers/Sqrt.hpp" -#include "fintamath/functions/trigonometry/Acos.hpp" -#include "fintamath/functions/trigonometry/Acot.hpp" -#include "fintamath/functions/trigonometry/Acsc.hpp" -#include "fintamath/functions/trigonometry/Asec.hpp" -#include "fintamath/functions/trigonometry/Asin.hpp" -#include "fintamath/functions/trigonometry/Atan.hpp" -#include "fintamath/functions/trigonometry/Cos.hpp" -#include "fintamath/functions/trigonometry/Cot.hpp" -#include "fintamath/functions/trigonometry/Csc.hpp" -#include "fintamath/functions/trigonometry/Sec.hpp" -#include "fintamath/functions/trigonometry/Sin.hpp" -#include "fintamath/functions/trigonometry/Tan.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/literals/constants/IConstant.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -using namespace detail; - -using NameToSimplifyFunctionMap = std::unordered_map< - std::string, - std::function &var)>>; - -DerivativeExpr::DerivativeExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild) - : IBinaryExpressionCRTP(Derivative{}, std::move(inLhsChild), std::move(inRhsChild)) { -} - -DerivativeExpr::SimplifyFunctionVector DerivativeExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &DerivativeExpr::derivativeSimplify, - }; - return simplifyFunctions; -} - -ArgumentPtr DerivativeExpr::derivativeSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - const auto var = cast(rhs); - - if (const auto lhsExpr = cast(lhs)) { - return exprSimplify(lhsExpr, var); - } - - if (is(lhs)) { - return (*lhs == *var) ? Integer(1).clone() : Integer(0).clone(); - } - - if (is(lhs) || is(lhs)) { - return Integer(0).clone(); - } - - return {}; -} - -ArgumentPtr DerivativeExpr::exprSimplify(const std::shared_ptr &expr, const std::shared_ptr &var) { - static const NameToSimplifyFunctionMap nameToSimplifyFunctionMap = [] { - static const NameToSimplifyFunctionMap map = { - {Add{}.toString(), &addSimplify}, - {Mul{}.toString(), &mulSimplify}, - {Div{}.toString(), &divSimplify}, - {Pow{}.toString(), &powSimplify}, - {Log{}.toString(), &logSimplify}, - {Sin{}.toString(), &sinSimplify}, - {Cos{}.toString(), &cosSimplify}, - {Tan{}.toString(), &tanSimplify}, - {Cot{}.toString(), &cotSimplify}, - {Sec{}.toString(), &secSimplify}, - {Csc{}.toString(), &cscSimplify}, - {Asin{}.toString(), &asinSimplify}, - {Acos{}.toString(), &acosSimplify}, - {Atan{}.toString(), &atanSimplify}, - {Acot{}.toString(), &acotSimplify}, - {Asec{}.toString(), &asecSimplify}, - {Acsc{}.toString(), &acscSimplify}, - {Sinh{}.toString(), &sinhSimplify}, - {Cosh{}.toString(), &coshSimplify}, - {Tanh{}.toString(), &tanhSimplify}, - {Coth{}.toString(), &cothSimplify}, - {Sech{}.toString(), &sechSimplify}, - {Csch{}.toString(), &cschSimplify}, - {Asinh{}.toString(), &asinhSimplify}, - {Acosh{}.toString(), &acoshSimplify}, - {Atanh{}.toString(), &atanhSimplify}, - {Acoth{}.toString(), &atanhSimplify}, - {Asech{}.toString(), &asechSimplify}, - {Acsch{}.toString(), &acschSimplify}, - }; - return map; - }(); - - if (const auto iter = nameToSimplifyFunctionMap.find(expr->getFunction()->toString()); - iter != nameToSimplifyFunctionMap.end()) { - - return iter->second(expr->getChildren(), var); - } - - return {}; -} - -ArgumentPtr DerivativeExpr::addSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - ArgumentPtrVector newChildren = children; - - stdr::transform(newChildren, newChildren.begin(), [&var](const ArgumentPtr &child) { - return derivativeExpr(child, var); - }); - - return addExpr(std::move(newChildren)); -} - -ArgumentPtr DerivativeExpr::mulSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const auto childrenSizeDiv2 = static_cast(children.size() / 2); - - auto lhsChildren = ArgumentPtrVector(children.begin(), children.begin() + childrenSizeDiv2); - auto rhsChildren = ArgumentPtrVector(children.begin() + childrenSizeDiv2, children.end()); - - const ArgumentPtr lhs = makePolynom(Mul{}, std::move(lhsChildren)); - const ArgumentPtr rhs = makePolynom(Mul{}, std::move(rhsChildren)); - - return addExpr( - mulExpr(derivativeExpr(lhs, var), rhs), - mulExpr(derivativeExpr(rhs, var), lhs)); -} - -ArgumentPtr DerivativeExpr::divSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &lhs = children.front(); - const ArgumentPtr &rhs = children.back(); - - ArgumentPtr numerator = subExpr( - mulExpr(derivativeExpr(lhs, var), rhs), - mulExpr(derivativeExpr(rhs, var), lhs)); - - ArgumentPtr denominator = sqrExpr(rhs); - - return divExpr(std::move(numerator), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::powSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &lhs = children.front(); - const ArgumentPtr &rhs = children.back(); - - ArgumentPtr mulFirst = powExpr(lhs, subExpr(rhs, Integer(1).clone())); - - ArgumentPtr mulSecond = addExpr( - mulExpr(rhs, derivativeExpr(lhs, var)), - mulExpr(lhs, lnExpr(lhs), derivativeExpr(rhs, var))); - - return mulExpr(std::move(mulFirst), std::move(mulSecond)); -} - -ArgumentPtr DerivativeExpr::logSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &lhs = children.front(); - const ArgumentPtr &rhs = children.back(); - - ArgumentPtr subLhs = divExpr( - derivativeExpr(rhs, var), - mulExpr(rhs, lnExpr(lhs))); - - ArgumentPtr subRhs = divExpr( - mulExpr(derivativeExpr(lhs, var), lnExpr(rhs)), - mulExpr(lhs, sqrExpr(lnExpr(lhs)))); - - return subExpr(std::move(subLhs), std::move(subRhs)); -} - -ArgumentPtr DerivativeExpr::sinSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - return mulExpr(cosExpr(rhs), derivativeExpr(rhs, var)); -} - -ArgumentPtr DerivativeExpr::cosSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - return mulExpr(negExpr(sinExpr(rhs)), derivativeExpr(rhs, var)); -} - -ArgumentPtr DerivativeExpr::tanSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominator = sqrExpr(cosExpr(rhs)); - - return divExpr(derivativeExpr(rhs, var), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::cotSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominator = sqrExpr(sinExpr(rhs)); - - return divExpr(negExpr(derivativeExpr(rhs, var)), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::secSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - return mulExpr( - sqrExpr(secExpr(rhs)), - sinExpr(rhs), - derivativeExpr(rhs, var)); -} - -ArgumentPtr DerivativeExpr::cscSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - return negExpr(mulExpr( - sqrExpr(cscExpr(rhs)), - cosExpr(rhs), - derivativeExpr(rhs, var))); -} - -ArgumentPtr DerivativeExpr::asinSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominator = sqrtExpr(subExpr(Integer(1).clone(), sqrExpr(rhs))); - - return divExpr(derivativeExpr(rhs, var), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::acosSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominator = sqrtExpr(subExpr(Integer(1).clone(), sqrExpr(rhs))); - - return divExpr(negExpr(derivativeExpr(rhs, var)), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::atanSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominator = addExpr(sqrExpr(rhs), Integer(1).clone()); - - return divExpr(derivativeExpr(rhs, var), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::acotSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominator = addExpr(sqrExpr(rhs), Integer(1).clone()); - - return divExpr(negExpr(derivativeExpr(rhs, var)), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::asecSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominatorMulFirst = sqrtExpr( - subExpr(Integer(1).clone(), - divExpr(Integer(1).clone(), sqrExpr(rhs)))); - - ArgumentPtr denominatorMulSecond = sqrExpr(rhs); - - ArgumentPtr denominator = mulExpr(std::move(denominatorMulFirst), std::move(denominatorMulSecond)); - - return divExpr(derivativeExpr(rhs, var), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::acscSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominatorMulFirst = sqrtExpr( - subExpr(Integer(1).clone(), - divExpr(Integer(1).clone(), sqrExpr(rhs)))); - - ArgumentPtr denominatorMulRhs = sqrExpr(rhs); - - ArgumentPtr denominator = mulExpr(std::move(denominatorMulFirst), std::move(denominatorMulRhs)); - - return divExpr(negExpr(derivativeExpr(rhs, var)), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::sinhSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - return mulExpr(coshExpr(rhs), derivativeExpr(rhs, var)); -} - -ArgumentPtr DerivativeExpr::coshSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - return mulExpr(sinhExpr(rhs), derivativeExpr(rhs, var)); -} - -ArgumentPtr DerivativeExpr::tanhSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominator = powExpr(coshExpr(rhs), Integer(2).clone()); - - return divExpr(derivativeExpr(rhs, var), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::cothSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominator = powExpr(sinhExpr(rhs), Integer(2).clone()); - - return divExpr(negExpr(derivativeExpr(rhs, var)), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::sechSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - return negExpr(mulExpr( - sqrExpr(sechExpr(rhs)), - sinhExpr(rhs), - derivativeExpr(rhs, var))); -} - -ArgumentPtr DerivativeExpr::cschSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - return negExpr(mulExpr( - sqrExpr(cschExpr(rhs)), - coshExpr(rhs), - derivativeExpr(rhs, var))); -} - -ArgumentPtr DerivativeExpr::asinhSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominator = sqrtExpr(addExpr(sqrExpr(rhs), Integer(1).clone())); - - return divExpr(derivativeExpr(rhs, var), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::acoshSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominator = mulExpr( - sqrtExpr(subExpr(rhs, Integer(1).clone())), - sqrtExpr(addExpr(rhs, Integer(1).clone()))); - - return divExpr(derivativeExpr(rhs, var), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::atanhSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominator = subExpr(Integer(1).clone(), sqrExpr(rhs)); - - return divExpr(derivativeExpr(rhs, var), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::asechSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominatorMulFirst = sqrtExpr( - subExpr(divExpr(Integer(1).clone(), rhs), - Integer(1).clone())); - - ArgumentPtr denominatorMulSecond = sqrtExpr( - addExpr(divExpr(Integer(1).clone(), rhs), - Integer(1).clone())); - - ArgumentPtr denominatorMulThird = sqrExpr(rhs); - - ArgumentPtr denominator = mulExpr(std::move(denominatorMulFirst), - std::move(denominatorMulSecond), - std::move(denominatorMulThird)); - - return divExpr(negExpr(derivativeExpr(rhs, var)), std::move(denominator)); -} - -ArgumentPtr DerivativeExpr::acschSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var) { - const ArgumentPtr &rhs = children.front(); - - ArgumentPtr denominatorMulFirst = sqrtExpr( - addExpr(divExpr(Integer(1).clone(), sqrExpr(rhs)), - Integer(1).clone())); - - ArgumentPtr denominatorMulSecond = sqrExpr(rhs); - - ArgumentPtr denominator = mulExpr(std::move(denominatorMulFirst), std::move(denominatorMulSecond)); - - return divExpr(negExpr(derivativeExpr(rhs, var)), std::move(denominator)); -} - -} diff --git a/src/fintamath/expressions/binary/DerivativeExpr.hpp b/src/fintamath/expressions/binary/DerivativeExpr.hpp deleted file mode 100644 index 89c5e6568..000000000 --- a/src/fintamath/expressions/binary/DerivativeExpr.hpp +++ /dev/null @@ -1,85 +0,0 @@ -#pragma once - -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/literals/Variable.hpp" - -namespace fintamath { - -class DerivativeExpr final : public IBinaryExpressionCRTP { - FINTAMATH_CLASS_BODY(DerivativeExpr) - -public: - explicit DerivativeExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild); - -protected: - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - -private: - static ArgumentPtr derivativeSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr exprSimplify(const std::shared_ptr &expr, const std::shared_ptr &var); - - static ArgumentPtr addSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr mulSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr divSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr powSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr logSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr sinSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr cosSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr tanSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr cotSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr secSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr cscSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr asinSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr acosSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr atanSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr acotSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr asecSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr acscSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr sinhSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr coshSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr tanhSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr cothSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr sechSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr cschSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr asinhSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr acoshSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr atanhSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr asechSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); - - static ArgumentPtr acschSimplify(const ArgumentPtrVector &children, const std::shared_ptr &var); -}; - -} diff --git a/src/fintamath/expressions/binary/DivExpr.cpp b/src/fintamath/expressions/binary/DivExpr.cpp deleted file mode 100644 index 0c92896ff..000000000 --- a/src/fintamath/expressions/binary/DivExpr.cpp +++ /dev/null @@ -1,613 +0,0 @@ -#include "fintamath/expressions/binary/DivExpr.hpp" - -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionComparator.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/hyperbolic/Cosh.hpp" -#include "fintamath/functions/hyperbolic/Coth.hpp" -#include "fintamath/functions/hyperbolic/Csch.hpp" -#include "fintamath/functions/hyperbolic/Sech.hpp" -#include "fintamath/functions/hyperbolic/Sinh.hpp" -#include "fintamath/functions/hyperbolic/Tanh.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/functions/trigonometry/Cos.hpp" -#include "fintamath/functions/trigonometry/Cot.hpp" -#include "fintamath/functions/trigonometry/Csc.hpp" -#include "fintamath/functions/trigonometry/Sec.hpp" -#include "fintamath/functions/trigonometry/Sin.hpp" -#include "fintamath/functions/trigonometry/Tan.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/literals/constants/Undefined.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" -#include "fintamath/numbers/Rational.hpp" - -namespace fintamath { - -using namespace detail; - -DivExpr::DivExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild) - : IBinaryExpressionCRTP(Div{}, std::move(inLhsChild), std::move(inRhsChild)) { -} - -std::string DivExpr::toString() const { - if (isNegated(lhsChild)) { - return negExpr(divExpr(detail::negate(lhsChild), rhsChild))->toString(); - } - - return IBinaryExpression::toString(); -} - -DivExpr::SimplifyFunctionVector DivExpr::getFunctionsForPreSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &DivExpr::divSimplify, - &DivExpr::mulPreSimplify, - }; - return simplifyFunctions; -} - -DivExpr::SimplifyFunctionVector DivExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &DivExpr::constSimplify, - &DivExpr::negSimplify, - &DivExpr::numSimplify, - &DivExpr::divSimplify, - &DivExpr::mulPostSimplify, - &DivExpr::nestedRationalSimplify, - &DivExpr::gcdSimplify, - &DivExpr::sumSimplify, - &DivExpr::mulSecCscSimplify, - }; - return simplifyFunctions; -} - -ArgumentPtr DivExpr::constSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if ((*lhs == Integer(0) && *rhs == Integer(0)) || - (isMulInfinity(lhs) && isMulInfinity(rhs))) { - - return Undefined{}.clone(); - } - - if (*rhs == Integer(0)) { - return ComplexInf{}.clone(); - } - - if (isMulInfinity(rhs)) { - return Integer(0).clone(); - } - - if (*lhs == Integer(0)) { - return lhs; - } - - if (*rhs == Integer(1)) { - return lhs; - } - - return {}; -} - -ArgumentPtr DivExpr::numSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - static const Integer one = 1; - - if (*rhs != Integer(0) && Div{}.doArgsMatch({one, *rhs})) { - ArgumentPtr res = mulExpr(lhs, Div{}(one, *rhs)); - return res; - } - - return {}; -} - -ArgumentPtr DivExpr::divSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (containsDivTrigFunction(lhs) || containsDivTrigFunction(rhs)) { - return {}; - } - - ArgumentPtrVector numeratorChildren; - ArgumentPtrVector denominatorChildren; - - bool containsDivExpr = false; - - if (const auto lhsDivExpr = cast(lhs)) { - numeratorChildren.emplace_back(lhsDivExpr->getChildren().front()); - denominatorChildren.emplace_back(lhsDivExpr->getChildren().back()); - containsDivExpr = true; - } - else { - numeratorChildren.emplace_back(lhs); - } - - if (const auto rhsDivExpr = cast(rhs)) { - denominatorChildren.emplace_back(rhsDivExpr->getChildren().front()); - numeratorChildren.emplace_back(rhsDivExpr->getChildren().back()); - containsDivExpr = true; - } - else { - denominatorChildren.emplace_back(rhs); - } - - if (!containsDivExpr) { - return {}; - } - - ArgumentPtr numerator = makePolynom(Mul{}, std::move(numeratorChildren)); - ArgumentPtr denominator = makePolynom(Mul{}, std::move(denominatorChildren)); - ArgumentPtr res = divExpr(std::move(numerator), std::move(denominator)); - - return res; -} - -ArgumentPtr DivExpr::mulPreSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - static const SimplifyFunctionVector simplifyFunctions = { - &DivExpr::powSimplify, - }; - return mulSimplify(simplifyFunctions, func, lhs, rhs); -} - -ArgumentPtr DivExpr::mulPostSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - static const SimplifyFunctionVector simplifyFunctions = { - &DivExpr::constSimplify, - &DivExpr::equalSimplify, - &DivExpr::powSimplify, - &DivExpr::tanCotSimplify, - }; - return mulSimplify(simplifyFunctions, func, lhs, rhs); -} - -ArgumentPtr DivExpr::mulSecCscSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - static const SimplifyFunctionVector simplifyFunctions = { - &DivExpr::secCscSimplify, - }; - return mulSimplify(simplifyFunctions, func, lhs, rhs); -} - -ArgumentPtr DivExpr::mulSimplify(const SimplifyFunctionVector &simplFuncs, - const IFunction &func, - const ArgumentPtr &lhs, - const ArgumentPtr &rhs) { - - ArgumentPtrVector lhsChildren = getPolynomChildren(Mul{}, lhs); - ArgumentPtrVector rhsChildren = getPolynomChildren(Mul{}, rhs); - - const size_t lhsChildrenSizeInitial = lhsChildren.size(); - const size_t rhsChildrenSizeInitial = rhsChildren.size(); - - // TODO: use more efficient algorithm - for (const auto i : stdv::iota(0U, lhsChildren.size())) { - auto &lhsChild = lhsChildren[i]; - - for (const auto j : stdv::iota(0U, rhsChildren.size())) { - const auto &rhsChild = rhsChildren[j]; - - ArgumentPtr res = useSimplifyFunctions(simplFuncs, - func, - lhsChild, - rhsChild); - - if (res && !is(res) && *res != *makeExpr(func, lhsChild, rhsChild)) { - lhsChild = std::move(res); - rhsChildren.erase(rhsChildren.begin() + j); - break; - } - } - - if (rhsChildren.empty()) { - break; - } - } - - ArgumentPtr numerator = makePolynom(Mul{}, lhsChildren); - - if (rhsChildren.empty()) { - return numerator; - } - - ArgumentPtr denominator = makePolynom(Mul{}, rhsChildren); - - if (lhsChildren.size() != lhsChildrenSizeInitial || rhsChildren.size() != rhsChildrenSizeInitial) { - ArgumentPtr res = divExpr(std::move(numerator), std::move(denominator)); - return res; - } - - return {}; -} - -ArgumentPtr DivExpr::negSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (isNegated(rhs)) { - ArgumentPtr res = divExpr(negExpr(lhs), negExpr(rhs)); - return res; - } - - return {}; -} - -ArgumentPtr DivExpr::sumSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (auto [result, remainder] = mulSumSimplify(lhs, rhs); result) { - return remainder - ? addExpr(std::move(result), std::move(remainder)) - : std::move(result); - } - - if (auto [result, remainder] = sumMulSimplify(lhs, rhs); result) { - return remainder - ? addExpr(std::move(result), std::move(remainder)) - : std::move(result); - } - - if (auto [result, remainder] = sumSumSimplify(lhs, rhs); result) { - return remainder - ? addExpr(std::move(result), std::move(remainder)) - : std::move(result); - } - - if (auto [result, remainder] = sumSumSimplify(rhs, lhs); result && !is(remainder)) { - static const ArgumentPtr one = Integer(1).clone(); - ArgumentPtr denominator = remainder - ? addExpr(std::move(result), std::move(remainder)) - : std::move(result); - return divExpr(one, std::move(denominator)); - } - - return {}; -} - -std::pair DivExpr::sumSumSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - ArgumentPtrVector lhsChildren; - ArgumentPtrVector rhsChildren; - - if (const auto lhsExpr = cast(lhs); lhsExpr && is(lhsExpr->getFunction())) { - lhsChildren = lhsExpr->getChildren(); - } - - if (const auto rhsExpr = cast(rhs); rhsExpr && is(rhsExpr->getFunction())) { - rhsChildren = rhsExpr->getChildren(); - } - - if (lhsChildren.empty() || rhsChildren.empty()) { - return {}; - } - - ArgumentPtrVector resultVect; - ArgumentPtrVector remainderVect; - - for (const auto &child : lhsChildren) { - if (auto [result, remainder] = mulSumSimplify(child, rhs); result) { - resultVect.emplace_back(result); - - if (remainder) { - const auto remainderDiv = cast(remainder); - remainderVect.emplace_back(remainderDiv->getChildren().front()); - } - } - else { - remainderVect.emplace_back(child); - } - } - - if (resultVect.empty()) { - return {}; - } - - ArgumentPtr result = makePolynom(Add{}, std::move(resultVect)); - ArgumentPtr remainderAdd = addExpr(std::move(remainderVect)); - ArgumentPtr remainder = divExpr(std::move(remainderAdd), rhs); - simplifyChild(remainder); - - return {std::move(result), std::move(remainder)}; -} - -std::pair DivExpr::sumMulSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - ArgumentPtrVector lhsChildren; - - if (const auto lhsExpr = cast(lhs); lhsExpr && is(lhsExpr->getFunction())) { - lhsChildren = lhsExpr->getChildren(); - } - else { - return {}; - } - - if (const auto rhsChildExpr = cast(rhs); - rhsChildExpr && - is(rhsChildExpr->getFunction()) && - !containsChild(lhs, rhs)) { - - return {}; - } - - ArgumentPtrVector resultChildren; - ArgumentPtrVector remainderChildren; - - for (const auto &child : lhsChildren) { - ArgumentPtr divResult = divExpr(child, rhs); - simplifyChild(divResult); - - if (const auto divResultExpr = cast(divResult); - divResultExpr && - is
(divResultExpr->getFunction()) && - *divResultExpr->getChildren().back() == *rhs) { - - remainderChildren.emplace_back(child); - } - else { - resultChildren.emplace_back(divResult); - } - } - - if (remainderChildren.size() == lhsChildren.size()) { - return {}; - } - - ArgumentPtr result = makePolynom(Add{}, std::move(resultChildren)); - - ArgumentPtr remainder; - if (!remainderChildren.empty()) { - ArgumentPtr remainderAdd = makePolynom(Add{}, std::move(remainderChildren)); - remainder = divExpr(std::move(remainderAdd), rhs); - simplifyChild(remainder); - } - - return {std::move(result), std::move(remainder)}; -} - -std::pair DivExpr::mulSumSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (!containsVariable(rhs)) { - return {}; - } - - ArgumentPtrVector rhsChildren; - - if (const auto rhsExpr = cast(rhs); rhsExpr && is(rhsExpr->getFunction())) { - rhsChildren = rhsExpr->getChildren(); - } - else { - return {}; - } - - if (const auto lhsChildExpr = cast(lhs); - lhsChildExpr && - is(lhsChildExpr->getFunction())) { - - return {}; - } - - ArgumentPtr result = divExpr(lhs, rhsChildren.front()); - simplifyChild(result); - - if (containsDivTrigFunction(result) || is(result)) { - return {}; - } - - ArgumentPtrVector multiplicators; - - for (const auto &rhsChild : rhsChildren | stdv::drop(1)) { - multiplicators.emplace_back(mulExpr(rhsChild, result)); - } - - ArgumentPtr remainderAdd = negExpr(makePolynom(Add{}, std::move(multiplicators))); - simplifyChild(remainderAdd); - - if (const ArgumentPtr remainderAddFirstChild = getPolynomChildren(Add{}, remainderAdd).front(); - compare(lhs, remainderAddFirstChild) != std::strong_ordering::greater) { - - return {}; - } - - ArgumentPtr remainder = divExpr(remainderAdd, rhs); - - return {std::move(result), std::move(remainder)}; -} - -ArgumentPtr DivExpr::equalSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (*lhs == *rhs && !containsInfinity(lhs)) { - return Integer(1).clone(); - } - - return {}; -} - -ArgumentPtr DivExpr::powSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - auto [lhsChildBase, lhsChildRate] = splitPowExpr(lhs); - auto [rhsChildBase, rhsChildRate] = splitPowExpr(rhs); - - const auto lhsChildBaseNum = cast(rhsChildBase); - const auto lhsChildRateNum = cast(lhsChildRate); - const auto rhsChildBaseNum = cast(rhsChildBase); - const auto rhsChildRateNum = cast(rhsChildRate); - - if (lhsChildBaseNum && rhsChildBaseNum && - lhsChildRateNum && rhsChildRateNum && - *lhsChildRateNum < *rhsChildRateNum) { - - return {}; - } - - if (*lhsChildBase == *rhsChildBase && !containsInfinity(rhsChildBase)) { - return powExpr(rhsChildBase, addExpr(lhsChildRate, negExpr(rhsChildRate))); - } - - if (rhsChildBaseNum) { - if (const auto rhsChildRateRat = cast(rhsChildRate)) { - ArgumentPtr numeratorPow = Pow{}(*rhsChildBase, 1 - (*rhsChildRateRat)); - ArgumentPtr numerator = mulExpr(lhs, std::move(numeratorPow)); - return divExpr(std::move(numerator), std::move(rhsChildBase)); - } - } - - return {}; -} - -ArgumentPtr DivExpr::nestedRationalSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - const ArgumentPtrVector lhsChildren = getPolynomChildren(Mul{}, lhs); - - if (auto res = nestedNumeratorRationalSimplify(lhsChildren, rhs)) { - return res; - } - - return {}; -} - -ArgumentPtr DivExpr::gcdSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - const ArgumentPtrVector lhsChildren = getPolynomChildren(Add{}, lhs); - const ArgumentPtrVector rhsChildren = getPolynomChildren(Add{}, rhs); - - const Integer lhsGcdNum = getGcd(lhsChildren); - const Integer rhsGcdNum = getGcd(rhsChildren); - - if (lhsGcdNum <= 1 || rhsGcdNum <= 1) { - return {}; - } - - const Integer gcdNum = gcd(lhsGcdNum, rhsGcdNum); - - if (gcdNum <= 1) { - return {}; - } - - ArgumentPtr numerator = divExpr(lhs, gcdNum.clone()); - simplifyChild(numerator); - - ArgumentPtr denominator = divExpr(rhs, gcdNum.clone()); - simplifyChild(denominator); - - return divExpr(numerator, denominator); -} - -Integer DivExpr::getGcd(const ArgumentPtrVector &children) { - Integer gcdNum; - - for (auto child : children) { - if (const auto childExpr = cast(child); childExpr && is(childExpr->getFunction())) { - child = childExpr->getChildren().front(); - } - - if (const auto childInt = cast(child)) { - const Integer childIntAbs = abs(*childInt); - gcdNum = gcdNum != 0 ? gcd(gcdNum, childIntAbs) : childIntAbs; - } - else { - return 1; - } - } - - return gcdNum; -} - -ArgumentPtr DivExpr::nestedNumeratorRationalSimplify(const ArgumentPtrVector &lhsChildren, const ArgumentPtr &rhs) { - ArgumentPtrVector numeratorChildren; - ArgumentPtrVector denominatorChildren; - - for (const auto &child : lhsChildren) { - if (auto [childNumerator, childDenominator] = splitRational(child); - *childDenominator != Integer(1)) { - - numeratorChildren.emplace_back(childNumerator); - denominatorChildren.emplace_back(childDenominator); - } - else { - numeratorChildren.emplace_back(child); - } - } - - if (!denominatorChildren.empty()) { - denominatorChildren.emplace_back(rhs); - - ArgumentPtr numerator = makePolynom(Mul{}, std::move(numeratorChildren)); - ArgumentPtr denominator = makePolynom(Mul{}, std::move(denominatorChildren)); - - return divExpr(std::move(numerator), std::move(denominator)); - } - - return {}; -} - -ArgumentPtr DivExpr::tanCotSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - auto [lhsChildBase, lhsChildRate] = splitPowExpr(lhs); - auto [rhsChildBase, rhsChildRate] = splitPowExpr(rhs); - - if (*lhsChildRate != *rhsChildRate) { - return {}; - } - - const auto lhsChildValueExpr = cast(lhsChildBase); - const auto rhsChildValueExpr = cast(rhsChildBase); - - if (lhsChildValueExpr && rhsChildValueExpr && - *lhsChildValueExpr->getChildren().front() == *rhsChildValueExpr->getChildren().front()) { - - if (is(lhsChildValueExpr->getFunction()) && is(rhsChildValueExpr->getFunction())) { - return powExpr(tanExpr(*lhsChildValueExpr->getChildren().front()), lhsChildRate); - } - - if (is(lhsChildValueExpr->getFunction()) && is(rhsChildValueExpr->getFunction())) { - return powExpr(cotExpr(*lhsChildValueExpr->getChildren().front()), lhsChildRate); - } - - if (is(lhsChildValueExpr->getFunction()) && is(rhsChildValueExpr->getFunction())) { - return powExpr(tanhExpr(*lhsChildValueExpr->getChildren().front()), lhsChildRate); - } - - if (is(lhsChildValueExpr->getFunction()) && is(rhsChildValueExpr->getFunction())) { - return powExpr(cothExpr(*lhsChildValueExpr->getChildren().front()), lhsChildRate); - } - } - - return {}; -} - -ArgumentPtr DivExpr::secCscSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - auto [rhsChildBase, rhsChildRate] = splitPowExpr(rhs); - - if (const auto rhsChildValueExpr = cast(rhsChildBase)) { - if (is(rhsChildValueExpr->getFunction())) { - return mulExpr(lhs, powExpr(cscExpr(*rhsChildValueExpr->getChildren().front()), rhsChildRate)); - } - - if (is(rhsChildValueExpr->getFunction())) { - return mulExpr(lhs, powExpr(secExpr(*rhsChildValueExpr->getChildren().front()), rhsChildRate)); - } - - if (is(rhsChildValueExpr->getFunction())) { - return mulExpr(lhs, powExpr(cschExpr(*rhsChildValueExpr->getChildren().front()), rhsChildRate)); - } - - if (is(rhsChildValueExpr->getFunction())) { - return mulExpr(lhs, powExpr(sechExpr(*rhsChildValueExpr->getChildren().front()), rhsChildRate)); - } - } - - return {}; -} - -bool DivExpr::containsDivTrigFunction(const ArgumentPtr &arg) { - static const std::unordered_set functionStrings = { - Tan{}.toString(), - Cot{}.toString(), - Sec{}.toString(), - Csc{}.toString(), - Tanh{}.toString(), - Coth{}.toString(), - Sech{}.toString(), - Csch{}.toString(), - }; - - return containsIf(arg, [](const ArgumentPtr &inArg) { - const auto expr = cast(inArg); - return expr && functionStrings.contains(expr->getFunction()->toString()); - }); -} -} diff --git a/src/fintamath/expressions/binary/DivExpr.hpp b/src/fintamath/expressions/binary/DivExpr.hpp deleted file mode 100644 index 34ff07184..000000000 --- a/src/fintamath/expressions/binary/DivExpr.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -class DivExpr final : public IBinaryExpressionCRTP { - FINTAMATH_CLASS_BODY(DivExpr) - -public: - explicit DivExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild); - - std::string toString() const override; - -protected: - SimplifyFunctionVector getFunctionsForPreSimplify() const override; - - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - -private: - static ArgumentPtr constSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr numSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr divSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr mulPreSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr mulPostSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr mulSecCscSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr negSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr sumSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr nestedRationalSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr gcdSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr equalSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr powSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr tanCotSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr secCscSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr mulSimplify(const SimplifyFunctionVector &simplFuncs, - const IFunction &func, - const ArgumentPtr &lhs, - const ArgumentPtr &rhs); - - static std::pair sumSumSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static std::pair sumMulSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static std::pair mulSumSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr nestedNumeratorRationalSimplify(const ArgumentPtrVector &lhsChildren, const ArgumentPtr &rhs); - - static Integer getGcd(const ArgumentPtrVector &children); - - static bool containsDivTrigFunction(const ArgumentPtr &arg); -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/binary/IntegralExpr.cpp b/src/fintamath/expressions/binary/IntegralExpr.cpp deleted file mode 100644 index cdcea0afb..000000000 --- a/src/fintamath/expressions/binary/IntegralExpr.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "fintamath/expressions/binary/IntegralExpr.hpp" - -#include - -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/calculus/Integral.hpp" - -namespace fintamath { - -IntegralExpr::IntegralExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild) - : IBinaryExpressionCRTP(Integral{}, std::move(inLhsChild), std::move(inRhsChild)) { -} - -IntegralExpr::SimplifyFunctionVector IntegralExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &IntegralExpr::integralSimplify, - }; - return simplifyFunctions; -} - -ArgumentPtr IntegralExpr::integralSimplify(const IFunction & /*func*/, const ArgumentPtr & /*lhs*/, const ArgumentPtr & /*rhs*/) { - // TODO: implement integral simplify - return {}; -} - -} diff --git a/src/fintamath/expressions/binary/IntegralExpr.hpp b/src/fintamath/expressions/binary/IntegralExpr.hpp deleted file mode 100644 index 0682f4553..000000000 --- a/src/fintamath/expressions/binary/IntegralExpr.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class IntegralExpr final : public IBinaryExpressionCRTP { - FINTAMATH_CLASS_BODY(IntegralExpr) - -public: - explicit IntegralExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild); - -protected: - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - -private: - static ArgumentPtr integralSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/binary/LogExpr.cpp b/src/fintamath/expressions/binary/LogExpr.cpp deleted file mode 100644 index 236174e10..000000000 --- a/src/fintamath/expressions/binary/LogExpr.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include "fintamath/expressions/binary/LogExpr.hpp" - -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/logarithms/Ln.hpp" -#include "fintamath/functions/logarithms/Log.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/literals/constants/E.hpp" -#include "fintamath/literals/constants/Inf.hpp" -#include "fintamath/literals/constants/Undefined.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -using namespace detail; - -LogExpr::LogExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild) - : IBinaryExpressionCRTP(Log{}, std::move(inLhsChild), std::move(inRhsChild)) { -} - -std::string LogExpr::toString() const { - if (*lhsChild == E{}) { - return functionToString(Ln{}, {rhsChild}); - } - - return IBinaryExpression::toString(); -} - -const std::shared_ptr &LogExpr::getOutputFunction() const { - static const std::shared_ptr ln = std::make_shared(); - - if (*lhsChild == E{}) { - return ln; - } - - return IBinaryExpression::getFunction(); -} - -ArgumentPtr LogExpr::approximate() const { - if (*lhsChild == E{}) { - const auto approxExpr = cast(clone()); - approximateChild(approxExpr->rhsChild); - - if (is(approxExpr->rhsChild)) { - if (const auto res = cast(approxExpr->IBinaryExpression::approximate())) { - return res; - } - } - - return approxExpr->simplify(); - } - - return IBinaryExpression::approximate(); -} - -ArgumentPtr LogExpr::setPrecision(const unsigned precision, const Integer &maxInt) const { - if (*lhsChild == E{}) { - const auto approxExpr = cast(clone()); - setPrecisionChild(approxExpr->rhsChild, precision, maxInt); - return approxExpr->simplify(); - } - - return IBinaryExpression::setPrecision(precision, maxInt); -} - -LogExpr::SimplifyFunctionVector LogExpr::getFunctionsForPreSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &LogExpr::powSimplify, - }; - return simplifyFunctions; -} - -LogExpr::SimplifyFunctionVector LogExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &LogExpr::constSimplify, - &LogExpr::powSimplify, - &LogExpr::equalSimplify, - }; - return simplifyFunctions; -} - -ArgumentPtr LogExpr::constSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if ((*lhs == Integer(0) || isMulInfinity(lhs)) && - (*rhs == Integer(0) || isMulInfinity(rhs))) { - - return Undefined{}.clone(); - } - - if (*rhs == Integer(1) && !containsInfinity(lhs)) { - return Integer(0).clone(); - } - - if (*lhs == E{}) { - if (isInfinity(rhs)) { - return Inf{}.clone(); - } - - return callFunction(Ln{}, {rhs}); - } - - return {}; -} - -ArgumentPtr LogExpr::equalSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (*lhs == *rhs && !containsInfinity(lhs)) { - return Integer(1).clone(); - } - - return {}; -} - -ArgumentPtr LogExpr::powSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - ArgumentPtr res; - - if (const auto rhsExpr = cast(rhs); rhsExpr && is(rhsExpr->getFunction())) { - ArgumentPtr multiplier = rhsExpr->getChildren().back(); - ArgumentPtr logExprChild = logExpr(lhs, rhsExpr->getChildren().front()); - res = mulExpr(std::move(multiplier), std::move(logExprChild)); - } - else if (const auto lhsExpr = cast(lhs); lhsExpr && is(lhsExpr->getFunction())) { - ArgumentPtr multiplier = divExpr(Integer(1).clone(), lhsExpr->getChildren().back()); - ArgumentPtr logExprChild = logExpr(lhsExpr->getChildren().front(), rhs); - res = mulExpr(std::move(multiplier), std::move(logExprChild)); - } - - return res; -} - -} diff --git a/src/fintamath/expressions/binary/LogExpr.hpp b/src/fintamath/expressions/binary/LogExpr.hpp deleted file mode 100644 index 57bc9b178..000000000 --- a/src/fintamath/expressions/binary/LogExpr.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -class LogExpr final : public IBinaryExpressionCRTP { - FINTAMATH_CLASS_BODY(LogExpr) - -public: - explicit LogExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild); - - std::string toString() const override; - - const std::shared_ptr &getOutputFunction() const override; - -protected: - ArgumentPtr approximate() const override; - - ArgumentPtr setPrecision(unsigned precision, const Integer &maxInt) const override; - - SimplifyFunctionVector getFunctionsForPreSimplify() const override; - - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - -private: - static ArgumentPtr constSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr equalSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr powSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/binary/PowExpr.cpp b/src/fintamath/expressions/binary/PowExpr.cpp deleted file mode 100644 index 647f8bbe7..000000000 --- a/src/fintamath/expressions/binary/PowExpr.cpp +++ /dev/null @@ -1,414 +0,0 @@ -#include "fintamath/expressions/binary/PowExpr.hpp" - -#include -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.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" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/comparison/MoreEqv.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/functions/powers/Root.hpp" -#include "fintamath/functions/powers/Sqrt.hpp" -#include "fintamath/literals/Boolean.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/Complex.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" -#include "fintamath/numbers/Rational.hpp" - -namespace fintamath { - -using namespace detail; - -constexpr int64_t maxPreciseRoot = 9; - -PowExpr::PowExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild) - : IBinaryExpressionCRTP(Pow{}, std::move(inLhsChild), std::move(inRhsChild)) { -} - -std::string PowExpr::toString() const { - if (const auto rhsChildRat = cast(rhsChild)) { - const Integer &numerator = rhsChildRat->numerator(); - const Integer &denominator = rhsChildRat->denominator(); - - if (numerator == 1) { - if (denominator == 2) { - return functionToString(Sqrt{}, {lhsChild}); - } - - return functionToString(Root{}, {lhsChild, denominator.clone()}); - } - } - - if (const auto rhsChildExpr = cast(rhsChild); - rhsChildExpr && is
(rhsChildExpr->getFunction())) { - - if (*rhsChildExpr->getChildren().front() == Integer(1)) { - return functionToString(Root{}, {lhsChild, rhsChildExpr->getChildren().back()}); - } - } - - return IBinaryExpression::toString(); -} - -const std::shared_ptr &PowExpr::getOutputFunction() const { - static const std::shared_ptr sqrt = std::make_shared(); - static const std::shared_ptr root = std::make_shared(); - - if (const auto rhsChildRat = cast(rhsChild)) { - const Integer &numerator = rhsChildRat->numerator(); - const Integer &denominator = rhsChildRat->denominator(); - - if (numerator == 1) { - if (denominator == 2) { - return sqrt; - } - - return root; - } - } - - if (const auto rhsChildExpr = cast(rhsChild); - rhsChildExpr && - is
(rhsChildExpr->getFunction()) && - *rhsChildExpr->getChildren().front() == Integer(1)) { - - return root; - } - - return IBinaryExpression::getFunction(); -} - -ArgumentPtr PowExpr::approximate() const { - if (const auto ratRhsChild = cast(rhsChild); ratRhsChild && ratRhsChild->denominator() <= maxPreciseRoot) { - auto approxExpr = cast(clone()); - approximateChild(approxExpr->lhsChild); - - if (is(approxExpr->lhsChild)) { - return approxExpr->IBinaryExpression::approximate(); - } - - return approxExpr; - } - - return IBinaryExpression::approximate(); -} - -ArgumentPtr PowExpr::setPrecision(const unsigned precision, const Integer &maxInt) const { - if (const auto ratRhsChild = cast(rhsChild); ratRhsChild && ratRhsChild->denominator() <= maxPreciseRoot) { - auto approxExpr = cast(clone()); - setPrecisionChild(approxExpr->lhsChild, precision, maxInt); - return approxExpr; - } - - return IBinaryExpression::setPrecision(precision, maxInt); -} - -PowExpr::SimplifyFunctionVector PowExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &PowExpr::constSimplify, - &PowExpr::polynomSimplify, - &PowExpr::powSimplify, - }; - return simplifyFunctions; -} - -// Uses bites representation for generate all partitions of numbers, using stars and bars method. -// https://en.wikipedia.org/wiki/Stars_and_bars_(combinatorics) -// https://en.wikipedia.org/wiki/Partition_(number_theory) -// This method generate first bit number in sequence of numbers for each partition -Integer PowExpr::generateFirstNum(const Integer &countOfOne) { - Integer n = 0; - - for ([[maybe_unused]] const auto _ : stdv::iota(0U, countOfOne)) { - n <<= 1; - n |= 1; - } - - return n; -} - -// Uses algorithm for generating next number in sequence of partitions. -// https://en.wikipedia.org/wiki/Partition_(number_theory) -// https://en.wikipedia.org/wiki/Combinatorial_number_system#Applications -Integer PowExpr::generateNextNumber(const Integer &n) { - const Integer u = n & -n; - const Integer v = u + n; - return v + (((v ^ n) / u) >> 2); -} - -std::vector PowExpr::getPartition(Integer bitNumber, const Integer &variableCount) { - std::vector result; - Integer counter = 0; - - while (result.size() < variableCount) { - if (bitNumber % 2 == 1) { - ++counter; - } - - if (bitNumber % 2 == 0) { - result.emplace_back(counter); - counter = 0; - } - - bitNumber >>= 1; - } - - return result; -} - -// Uses multinomial theorem for exponentiation of sum. -// https://en.wikipedia.org/wiki/Multinomial_theorem -ArgumentPtr PowExpr::sumPolynomSimplify(const ArgumentPtr &expr, const Integer &power) { - const auto sumExpr = cast(expr); - ArgumentPtrVector polynom; - - if (sumExpr && is(sumExpr->getFunction())) { - polynom = sumExpr->getChildren(); - } - else { - return {}; - } - - const size_t variableCount = polynom.size(); - Integer bitNumber = generateFirstNum(power); - const Integer combins = combinations(power + variableCount - 1, power); - - ArgumentPtrVector newChildren; - - for ([[maybe_unused]] const auto _ : stdv::iota(0U, combins)) { - std::vector vectOfPows = getPartition(bitNumber, Integer(variableCount)); - bitNumber = generateNextNumber(bitNumber); - - ArgumentPtrVector mulExprChildren; - mulExprChildren.emplace_back(multinomialCoefficient(power, vectOfPows).clone()); - - for (const auto i : stdv::iota(0U, variableCount)) { - ArgumentPtr powExprChild = powExpr(polynom[i], vectOfPows[i].clone()); - mulExprChildren.emplace_back(std::move(powExprChild)); - } - - ArgumentPtr mulExprChild = mulExpr(std::move(mulExprChildren)); - newChildren.emplace_back(std::move(mulExprChild)); - } - - return addExpr(std::move(newChildren)); -} - -ArgumentPtr PowExpr::powSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (const auto lhsExpr = cast(lhs); lhsExpr && is(lhsExpr->getFunction())) { - const ArgumentPtr &lhsExprLhsChild = lhsExpr->getChildren().front(); - const ArgumentPtr &lhsExprRhsChild = lhsExpr->getChildren().back(); - - bool canMul = is(rhs); - - if (const auto lhsExprLhsChildNum = cast(lhsExprLhsChild)) { - canMul = canMul || - (!lhsExprLhsChildNum->isComplex() && - *MoreEqv{}(*lhsExprLhsChildNum, Integer(0)) == Boolean(true)); - } - - if (canMul) { - ArgumentPtr newLhs = lhsExprLhsChild; - ArgumentPtr newRhs = mulExpr(lhsExprRhsChild, rhs); - return powExpr(std::move(newLhs), std::move(newRhs)); - } - } - - return {}; -} - -ArgumentPtr PowExpr::constSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (is(rhs)) { - return Undefined{}.clone(); - } - - if (is(rhs)) { - return powExpr(divExpr(Integer(1).clone(), lhs), Inf{}.clone()); - } - - if (is(rhs)) { - if (isInfinity(lhs)) { - return ComplexInf{}.clone(); - } - - if (!containsVariable(lhs)) { - ArgumentPtr approxLhs = lhs; - approximateChild(approxLhs); - - if (const auto lhsNum = cast(approxLhs)) { - if (lhsNum->isComplex()) { - return Undefined{}.clone(); - } - - const auto lhsNumAbs = cast(Abs{}(*lhsNum)); - - if (*lhsNumAbs == Integer(1)) { - return Undefined{}.clone(); - } - - if (*lhsNumAbs > Integer(1)) { - return Inf{}.clone(); - } - - return Integer(0).clone(); - } - } - else { - return Undefined{}.clone(); - } - } - - if (*rhs == Integer(1)) { - return lhs; - } - - if (*rhs == Integer(-1)) { - static const ArgumentPtr one = Integer(1).clone(); - return divExpr(one, lhs); - } - - if (const auto rhsNum = cast(rhs); rhsNum && *rhsNum < Integer(0)) { - static const ArgumentPtr one = Integer(1).clone(); - ArgumentPtr divRhs = powExpr(lhs, negExpr(rhs)); - return divExpr(one, std::move(divRhs)); - } - - if (is(lhs)) { - ArgumentPtr mulLhs = powExpr(Integer(-1).clone(), rhs); - ArgumentPtr mulRhs = powExpr(Inf{}.clone(), rhs); - return mulExpr(std::move(mulLhs), std::move(mulRhs)); - } - - if (is(lhs) || is(lhs)) { - if (!containsVariable(rhs)) { - ArgumentPtr approxRhs = rhs; - approximateChild(approxRhs); - - if (const auto rhsComplex = cast(approxRhs)) { - if (rhsComplex->real() == Integer(0)) { - return Undefined{}.clone(); - } - - return ComplexInf{}.clone(); - } - - if (const auto rhsNum = cast(approxRhs)) { - if (*rhsNum == Integer(0)) { - return Undefined{}.clone(); - } - - if (*rhsNum < Integer(0)) { - return Integer(0).clone(); - } - - return lhs; - } - } - else { - return Undefined{}.clone(); - } - } - - if (*rhs == Integer(0)) { - if (isMulInfinity(lhs)) { - return Undefined{}.clone(); - } - - if (!containsInfinity(lhs)) { - return Integer(1).clone(); - } - } - - if (*lhs == Integer(0) || *lhs == Integer(1)) { - if (isMulInfinity(rhs)) { - return Undefined{}.clone(); - } - - if (!containsInfinity(rhs)) { - return lhs; - } - } - - return {}; -} - -ArgumentPtr PowExpr::polynomSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (auto res = mulSimplify(lhs, rhs)) { - return res; - } - - if (auto res = sumSimplify(lhs, rhs)) { - return res; - } - - if (auto res = divSimplify(lhs, rhs)) { - return res; - } - - return {}; -} - -ArgumentPtr PowExpr::mulSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (!is(rhs)) { - return {}; - } - - ArgumentPtr res; - - if (const auto mulExprChild = cast(lhs); mulExprChild && is(mulExprChild->getFunction())) { - ArgumentPtrVector args = mulExprChild->getChildren(); - - for (auto &arg : args) { - arg = powExpr(arg, rhs->clone()); - } - - res = mulExpr(std::move(args)); - } - - return res; -} - -ArgumentPtr PowExpr::divSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (!is(rhs)) { - return {}; - } - - ArgumentPtr res; - - if (const auto divExprChild = cast(lhs); divExprChild && is
(divExprChild->getFunction())) { - ArgumentPtr numerator = powExpr(divExprChild->getChildren().front(), rhs); - ArgumentPtr denominator = powExpr(divExprChild->getChildren().back(), rhs); - res = divExpr(std::move(numerator), std::move(denominator)); - } - - return res; -} - -ArgumentPtr PowExpr::sumSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (const auto rhsInt = cast(rhs)) { - if (auto sumExpr = sumPolynomSimplify(lhs, *rhsInt)) { - return sumExpr; - } - } - - return {}; -} -} diff --git a/src/fintamath/expressions/binary/PowExpr.hpp b/src/fintamath/expressions/binary/PowExpr.hpp deleted file mode 100644 index d271c4dad..000000000 --- a/src/fintamath/expressions/binary/PowExpr.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -class PowExpr final : public IBinaryExpressionCRTP { - FINTAMATH_CLASS_BODY(PowExpr) - -public: - explicit PowExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild); - - std::string toString() const override; - - const std::shared_ptr &getOutputFunction() const override; - -protected: - ArgumentPtr approximate() const override; - - ArgumentPtr setPrecision(unsigned precision, const Integer &maxInt) const override; - - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - -private: - static ArgumentPtr sumPolynomSimplify(const ArgumentPtr &expr, const Integer &power); - - static Integer generateNextNumber(const Integer &n); - - static Integer generateFirstNum(const Integer &countOfOne); - - static std::vector getPartition(Integer bitNumber, const Integer &variableCount); - - static ArgumentPtr powSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr constSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr polynomSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr mulSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr divSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr sumSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs); -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp b/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp deleted file mode 100644 index 361b48f94..000000000 --- a/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include "fintamath/expressions/ExpressionFunctions.hpp" - -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/binary/CompExpr.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/comparison/Eqv.hpp" -#include "fintamath/functions/logic/Or.hpp" -#include "fintamath/literals/Variable.hpp" - -namespace fintamath { - -using namespace detail; - -namespace { - -constexpr size_t maxPower = 4; - -ArgumentPtrVector getPolynomCoefficients(const ArgumentPtr &elem, const Variable &var); - -ArgumentPtrVector solveCubicEquation(const ArgumentPtrVector &coeffAtPow); - -ArgumentPtrVector solveQuadraticEquation(const ArgumentPtrVector &coeffAtPow); - -ArgumentPtrVector solveLinearEquation(const ArgumentPtrVector &coeffAtPow); - -} - -Expression solve(const Expression &rhs) { - const auto compExpr = cast(rhs.getChildren().front()->clone()); - - if (!compExpr || compExpr->getVariables().size() != 1) { - return rhs; - } - - // TODO: remove this if when inequalities will be implemented - if (!is(compExpr->getFunction())) { - const auto var = cast(compExpr->getVariables().front()); - const ArgumentPtrVector powerRate = getPolynomCoefficients(compExpr->getChildren().front(), var); - - if (powerRate.size() == 2) { - compExpr->markAsSolution(); - return *compExpr; - } - - return rhs; - } - - const auto var = cast(compExpr->getVariables().front()); - const ArgumentPtrVector powerRates = getPolynomCoefficients(compExpr->getChildren().front(), var); - ArgumentPtrVector roots; - - switch (powerRates.size()) { - case 2: - roots = solveLinearEquation(powerRates); - break; - case 3: - roots = solveQuadraticEquation(powerRates); - break; - case 4: - roots = solveCubicEquation(powerRates); - break; - default: - roots = {}; - break; - } - - if (roots.empty()) { - return *compExpr; - } - - ArgumentPtrVector answers; - - for (auto &root : roots) { - auto rootAnswer = std::make_shared(Eqv{}, var.clone(), root); - rootAnswer->markAsSolution(); - answers.emplace_back(rootAnswer); - } - - if (answers.size() == 1) { - return Expression(answers.front()); - } - - return Expression(orExpr(std::move(answers))); -} - -namespace { - -ArgumentPtrVector getPolynomCoefficients(const ArgumentPtr &elem, const Variable &var) { - ArgumentPtrVector powers; - ArgumentPtrVector polynomVect; - - if (const auto exprVal = cast(elem); exprVal && is(exprVal->getFunction())) { - polynomVect = exprVal->getChildren(); - } - else { - polynomVect.emplace_back(elem); - } - - for (const auto &polynomChild : polynomVect) { - if (!containsVariable(polynomChild, var)) { - powers[0] = polynomChild; - continue; - } - - auto [mulRate, mulValue] = splitMulExpr(polynomChild); - auto [powBase, powValue] = splitPowExpr(mulValue); - auto intPower = cast(powValue); - - if (!intPower || *intPower > maxPower || *powBase != var) { - return {}; - } - - while (powers.size() < *intPower + 1) { - powers.emplace_back(Integer(0).clone()); - } - - powers[static_cast(*intPower)] = mulRate; - } - - return powers; -} - -ArgumentPtrVector solveQuadraticEquation(const ArgumentPtrVector &coeffAtPow) { - const Expression a(coeffAtPow[2]); - const Expression b(coeffAtPow[1]); - const Expression c(coeffAtPow[0]); - - const ArgumentPtr discriminantArg = (pow(b, 2) - (4 * a * c)).toMinimalObject(); - const Expression discriminant(discriminantArg); - - const Expression firstRoot = (-b + sqrt(discriminant)) / 2 * a; - const Expression secondRoot = (-b - sqrt(discriminant)) / (2 * a); - - return {firstRoot.getChildren().front(), secondRoot.getChildren().front()}; -} - -ArgumentPtrVector solveCubicEquation(const ArgumentPtrVector & /*coeffAtPow*/) { - return {}; -} - -ArgumentPtrVector solveLinearEquation(const ArgumentPtrVector &coeffAtPow) { - return {negExpr(divExpr(coeffAtPow[0], coeffAtPow[1]))->toMinimalObject()}; -} - -} - -} diff --git a/src/fintamath/expressions/interfaces/IBinaryExpression.cpp b/src/fintamath/expressions/interfaces/IBinaryExpression.cpp deleted file mode 100644 index 650cfabd7..000000000 --- a/src/fintamath/expressions/interfaces/IBinaryExpression.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" - -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/IOperator.hpp" - -namespace fintamath { - -using namespace detail; - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IBinaryExpression) - -IBinaryExpression::IBinaryExpression(const IFunction &inFunc, ArgumentPtr lhs, ArgumentPtr rhs) - : func(cast(inFunc.clone())), - lhsChild(std::move(lhs)), - rhsChild(std::move(rhs)) { -} - -std::string IBinaryExpression::toString() const { - if (const auto oper = cast(func)) { - return binaryOperatorToString(*oper, lhsChild, rhsChild); - } - - return functionToString(*func, {lhsChild, rhsChild}); -} - -const std::shared_ptr &IBinaryExpression::getFunction() const { - return func; -} - -const ArgumentPtrVector &IBinaryExpression::getChildren() const { - childrenCached.front() = lhsChild; - childrenCached.back() = rhsChild; - return childrenCached; -} - -ArgumentPtr IBinaryExpression::preSimplify() const { - const auto simpl = cast(clone()); - preSimplifyChild(simpl->lhsChild); - preSimplifyChild(simpl->rhsChild); - return simpl->simplifyRec(false); -} - -ArgumentPtr IBinaryExpression::postSimplify() const { - const auto simpl = cast(clone()); - postSimplifyChild(simpl->lhsChild); - postSimplifyChild(simpl->rhsChild); - return simpl->simplifyRec(true); -} - -ArgumentPtr IBinaryExpression::simplifyRec(const bool isPostSimplify) const { - if (ArgumentPtr res = simplifyUndefined(*func, lhsChild, rhsChild)) { - return res; - } - - if (ArgumentPtr res = callFunction(*func, {lhsChild, rhsChild})) { - return res; - } - - ArgumentPtr res = isPostSimplify ? useSimplifyFunctions(getFunctionsForPostSimplify(), - *func, - lhsChild, - rhsChild) - : useSimplifyFunctions(getFunctionsForPreSimplify(), - *func, - lhsChild, - rhsChild); - - if (res && *res != *this) { - if (isPostSimplify) { - postSimplifyChild(res); - } - else { - preSimplifyChild(res); - } - - return res; - } - - return clone(); -} - -IBinaryExpression::SimplifyFunctionVector IBinaryExpression::getFunctionsForPreSimplify() const { - return {}; -} - -IBinaryExpression::SimplifyFunctionVector IBinaryExpression::getFunctionsForPostSimplify() const { - return {}; -} - -void IBinaryExpression::setChildren(const ArgumentPtrVector &childVect) { - if (childVect.size() != 2) { - throw InvalidInputFunctionException(toString(), argumentVectorToStringVector(childVect)); - } - - lhsChild = childVect[0]; - rhsChild = childVect[1]; -} - -} diff --git a/src/fintamath/expressions/interfaces/IPolynomExpression.cpp b/src/fintamath/expressions/interfaces/IPolynomExpression.cpp deleted file mode 100644 index 74509803d..000000000 --- a/src/fintamath/expressions/interfaces/IPolynomExpression.cpp +++ /dev/null @@ -1,233 +0,0 @@ -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionComparator.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/binary/CompExpr.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" - -namespace fintamath { - -using namespace detail; - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IPolynomExpression) - -IPolynomExpression::IPolynomExpression(const IFunction &inFunc, ArgumentPtrVector args) - : func(cast(inFunc.clone())), - children(std::move(args)) { -} - -const std::shared_ptr &IPolynomExpression::getFunction() const { - return func; -} - -const ArgumentPtrVector &IPolynomExpression::getChildren() const { - return children; -} - -std::string IPolynomExpression::toString() const { - const auto oper = cast(func); - if (!oper) { - return functionToString(*func, children); - } - - std::string result; - - result += childToString(*oper, children.front(), {}); - - for (const auto i : stdv::iota(1U, children.size())) { - const std::string childStr = childToString(*oper, children[i], children[i - 1]); - - if (childStr.size() > 2 && childStr[0] == ' ' && std::isdigit(childStr[1]) && std::isdigit(result.back())) { - result += Mul{}.toString() + childStr.substr(1); - } - else { - result += childStr; - } - } - - return result; -} - -void IPolynomExpression::compress() { - size_t i = 0; - - while (i < children.size()) { - auto &child = children[i]; - - if (const auto childPolynom = cast(child); childPolynom && *childPolynom->func == *func) { - std::swap(child, children.back()); - children.pop_back(); - - children.insert(children.end(), - childPolynom->children.begin(), - childPolynom->children.end()); - } - else { - i++; - } - } -} - -ArgumentPtr IPolynomExpression::preSimplify() const { - auto simpl = cast(clone()); - - simpl->simplifyChildren(false); - simpl->simplifyRec(false); - - if (simpl->children.size() == 1) { - return simpl->children.front(); - } - - return simpl; -} - -ArgumentPtr IPolynomExpression::postSimplify() const { - auto simpl = cast(clone()); - - simpl->simplifyChildren(true); - simpl->simplifyRec(true); - - if (simpl->children.size() == 1) { - return simpl->children.front(); - } - - return simpl; -} - -void IPolynomExpression::simplifyRec(const bool isPostSimplify) { - compress(); - sort(); - - bool isExprSimplified = true; - - // TODO: refactor this loop - for (size_t i = 1; i < children.size(); i++) { - const ArgumentPtr &lhs = children[i - 1]; - const ArgumentPtr &rhs = children[i]; - - if (auto res = simplifyUndefined(*func, lhs, rhs)) { - children = {res}; - break; - } - - ArgumentPtr res = callFunction(*func, {lhs, rhs}); - const bool isResSimplified = res != nullptr; - - if (!res) { - res = isPostSimplify ? useSimplifyFunctions(getFunctionsForPostSimplify(), - *func, - children[i - 1], - children[i]) - : useSimplifyFunctions(getFunctionsForPreSimplify(), - *func, - children[i - 1], - children[i]); - } - - if (!res) { - continue; - } - - if (!isResSimplified) { - const ArgumentPtr prevExpr = makeExpr(*getFunction(), lhs, rhs); - - if (isPostSimplify) { - postSimplifyChild(res); - } - else { - preSimplifyChild(res); - } - - if (*prevExpr == *res) { - continue; - } - } - - children.erase(children.begin() + static_cast(i) - 1); - children.erase(children.begin() + static_cast(i) - 1); - children.emplace_back(res); - - i--; - isExprSimplified = false; - } - - if (!isExprSimplified) { - simplifyRec(isPostSimplify); - } -} - -void IPolynomExpression::simplifyChildren(const bool isPostSimplify) { - ArgumentPtrVector oldChildren = children; - - children.clear(); - - for (auto &child : oldChildren) { - if (isPostSimplify) { - postSimplifyChild(child); - } - else { - preSimplifyChild(child); - } - - children.emplace_back(child); - } -} - -IPolynomExpression::SimplifyFunctionVector IPolynomExpression::getFunctionsForPreSimplify() const { - return {}; -} - -IPolynomExpression::SimplifyFunctionVector IPolynomExpression::getFunctionsForPostSimplify() const { - return {}; -} - -std::string IPolynomExpression::childToString(const IOperator &oper, const ArgumentPtr &inChild, const ArgumentPtr &prevChild) const { - const std::string childStr = operatorChildToString(oper, inChild); - return prevChild ? (putInSpaces(func->toString()) + childStr) : childStr; -} - -std::strong_ordering IPolynomExpression::compare(const ArgumentPtr &lhs, const ArgumentPtr &rhs) const { - const ComparatorOptions options = { - .termOrderInversed = isTermOrderInversed(), - .comparableOrderInversed = isComparableOrderInversed(), - }; - return fintamath::compare(lhs, rhs, options); -} - -bool IPolynomExpression::isTermOrderInversed() const { - return false; -} - -bool IPolynomExpression::isComparableOrderInversed() const { - return false; -} - -void IPolynomExpression::setChildren(const ArgumentPtrVector &childVect) { - if (childVect.empty()) { - throw InvalidInputFunctionException(toString(), {}); - } - - children = childVect; -} - -void IPolynomExpression::sort() { - stdr::stable_sort(children, [this](const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - return compare(lhs, rhs) == std::strong_ordering::greater; - }); -} - -} diff --git a/src/fintamath/expressions/interfaces/IUnaryExpression.cpp b/src/fintamath/expressions/interfaces/IUnaryExpression.cpp deleted file mode 100644 index eea6dd31f..000000000 --- a/src/fintamath/expressions/interfaces/IUnaryExpression.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" - -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/IOperator.hpp" - -namespace fintamath { - -using namespace detail; - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IUnaryExpression) - -IUnaryExpression::IUnaryExpression(const IFunction &inFunc, ArgumentPtr rhs) - : func(cast(inFunc.clone())), - child(std::move(rhs)) { -} - -std::string IUnaryExpression::toString() const { - if (const auto oper = cast(func)) { - if (oper->getPriority() == IOperator::Priority::PostfixUnary) { - return detail::postfixUnaryOperatorToString(*oper, child); - } - - return detail::prefixUnaryOperatorToString(*oper, child); - } - - return detail::functionToString(*func, {child}); -} - -const std::shared_ptr &IUnaryExpression::getFunction() const { - return func; -} - -const ArgumentPtrVector &IUnaryExpression::getChildren() const { - childrenCached.front() = child; - return childrenCached; -} - -IUnaryExpression::SimplifyFunctionVector IUnaryExpression::getFunctionsForPreSimplify() const { - return {}; -} - -IUnaryExpression::SimplifyFunctionVector IUnaryExpression::getFunctionsForPostSimplify() const { - return {}; -} - -ArgumentPtr IUnaryExpression::preSimplify() const { - const auto simpl = cast(clone()); - preSimplifyChild(simpl->child); - return simpl->simplifyRec(false); -} - -ArgumentPtr IUnaryExpression::postSimplify() const { - const auto simpl = cast(clone()); - postSimplifyChild(simpl->child); - return simpl->simplifyRec(true); -} - -ArgumentPtr IUnaryExpression::simplifyRec(const bool isPostSimplify) const { - if (ArgumentPtr res = simplifyUndefined(*func, child)) { - return res; - } - - if (ArgumentPtr res = callFunction(*func, {child})) { - return res; - } - - ArgumentPtr res = isPostSimplify ? useSimplifyFunctions(getFunctionsForPostSimplify(), - *func, - child) - : useSimplifyFunctions(getFunctionsForPreSimplify(), - *func, - child); - - if (res && *res != *this) { - if (isPostSimplify) { - postSimplifyChild(res); - } - else { - preSimplifyChild(res); - } - - return res; - } - - return clone(); -} - -void IUnaryExpression::setChildren(const ArgumentPtrVector &childVect) { - if (childVect.size() != 1) { - throw InvalidInputFunctionException(toString(), argumentVectorToStringVector(childVect)); - } - - child = childVect.front(); -} - -} \ No newline at end of file diff --git a/src/fintamath/expressions/polynomial/AddExpr.cpp b/src/fintamath/expressions/polynomial/AddExpr.cpp deleted file mode 100644 index af2354d9c..000000000 --- a/src/fintamath/expressions/polynomial/AddExpr.cpp +++ /dev/null @@ -1,409 +0,0 @@ -#include "fintamath/expressions/polynomial/AddExpr.hpp" - -#include -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/arithmetic/Sub.hpp" -#include "fintamath/functions/logarithms/Log.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/functions/powers/Sqr.hpp" -#include "fintamath/functions/trigonometry/Cos.hpp" -#include "fintamath/functions/trigonometry/Sin.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/Rational.hpp" - -namespace fintamath { - -using namespace detail; - -AddExpr::AddExpr(ArgumentPtrVector inChildren) - : IPolynomExpressionCRTP(Add{}, std::move(inChildren)) { -} - -std::string AddExpr::childToString(const IOperator &oper, const ArgumentPtr &inChild, const ArgumentPtr &prevChild) const { - std::string result = operatorChildToString(oper, inChild); - bool isChildNegated = false; - - if (result.size() > 1 && - result.front() == Neg{}.toString().front()) { - - isChildNegated = true; - result = result.substr(1, result.size() - 1); - } - - std::string funcStr; - - if (isChildNegated) { - funcStr = Sub{}.toString(); - } - else if (prevChild) { - funcStr = oper.toString(); - } - - if (!funcStr.empty()) { - if (prevChild) { - funcStr = putInSpaces(funcStr); - } - - result = funcStr + result; - } - - return result; -} - -std::strong_ordering AddExpr::compare(const ArgumentPtr &lhs, const ArgumentPtr &rhs) const { - const auto lhsExpr = cast(lhs); - const auto rhsExpr = cast(rhs); - - if (lhsExpr && - is
(lhsExpr->getFunction()) && - (!rhsExpr || !is
(rhsExpr->getFunction()))) { - - return std::strong_ordering::less; - } - - if (rhsExpr && - is
(rhsExpr->getFunction()) && - (!lhsExpr || !is
(lhsExpr->getFunction()))) { - - return std::strong_ordering::greater; - } - - return IPolynomExpression::compare(lhs, rhs); -} - -AddExpr::SimplifyFunctionVector AddExpr::getFunctionsForPreSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &AddExpr::divSimplify, - &AddExpr::constSimplify, - &AddExpr::mulSimplify, - &AddExpr::logSimplify, - &AddExpr::mulLogSimplify, - }; - return simplifyFunctions; -} - -AddExpr::SimplifyFunctionVector AddExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &AddExpr::constSimplify, - &AddExpr::mulSimplify, - &AddExpr::logSimplify, - &AddExpr::mulLogSimplify, - &AddExpr::trigSimplify, - }; - return simplifyFunctions; -} - -ArgumentPtr AddExpr::constSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (*lhs == Integer(0)) { - return rhs; - } - - if (*rhs == Integer(0)) { - return lhs; - } - - if ((is(lhs) || is(lhs)) && - (is(rhs) || is(rhs))) { - - return Undefined{}.clone(); - } - - if ((is(lhs) && is(rhs)) || - (is(lhs) && is(rhs))) { - - return lhs; - } - - if (isInfinity(lhs) && !containsInfinity(rhs)) { - return lhs; - } - - if (isInfinity(rhs) && !containsInfinity(lhs)) { - return rhs; - } - - return {}; -} - -ArgumentPtr AddExpr::logSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - const auto lhsExpr = cast(lhs); - const auto rhsExpr = cast(rhs); - - if (!lhsExpr || !rhsExpr || - !is(lhsExpr->getFunction()) || !is(rhsExpr->getFunction())) { - return {}; - } - - const ArgumentPtrVector &lhsChildren = lhsExpr->getChildren(); - const ArgumentPtrVector &rhsChildren = rhsExpr->getChildren(); - - if (*lhsChildren.front() == *rhsChildren.front()) { - ArgumentPtr logLhs = lhsChildren.front(); - ArgumentPtr logRhs = mulExpr(lhsChildren.back(), rhsChildren.back()); - ArgumentPtr res = logExpr(std::move(logLhs), std::move(logRhs)); - return res; - } - - return {}; -} - -ArgumentPtr AddExpr::mulLogSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - const auto lhsExpr = cast(lhs); - const auto rhsExpr = cast(rhs); - - if (!lhsExpr || !rhsExpr) { - return {}; - } - - if (is(lhsExpr->getFunction()) && is(rhsExpr->getFunction())) { - const ArgumentPtrVector &lhsExprChildren = lhsExpr->getChildren(); - const ArgumentPtrVector &rhsExprChildren = rhsExpr->getChildren(); - - const std::vector lhsLogChildrenIndices = findLogarithms(lhsExprChildren); - const std::vector rhsLogChildrenIndices = findLogarithms(rhsExprChildren); - - for (const size_t i : lhsLogChildrenIndices) { - auto lhsLogChild = cast(lhsExprChildren[i]); - - for (const size_t j : rhsLogChildrenIndices) { - auto rhsLogChild = cast(rhsExprChildren[j]); - - if (*lhsLogChild->getChildren().front() == *rhsLogChild->getChildren().front()) { - lhsLogChild = cast(mulToLogarithm(lhsExprChildren, i)); - rhsLogChild = cast(mulToLogarithm(rhsExprChildren, j)); - - ArgumentPtr logLhs = lhsLogChild->getChildren().front(); - ArgumentPtr logRhs = mulExpr(lhsLogChild->getChildren().back(), rhsLogChild->getChildren().back()); - return logExpr(std::move(logLhs), std::move(logRhs)); - } - } - } - } - - std::shared_ptr mulExprChild; - std::shared_ptr logExprChild; - - if (is(lhsExpr->getFunction()) && is(rhsExpr->getFunction())) { - mulExprChild = lhsExpr; - logExprChild = rhsExpr; - } - else if (is(lhsExpr->getFunction()) && is(rhsExpr->getFunction())) { - mulExprChild = rhsExpr; - logExprChild = lhsExpr; - } - else { - return {}; - } - - const ArgumentPtrVector &mulExprChildren = mulExprChild->getChildren(); - const std::vector logChildrenIndices = findLogarithms(mulExprChildren); - - for (const size_t i : logChildrenIndices) { - auto logChild = cast(mulExprChildren[i]); - - if (*logChild->getChildren().front() == *logExprChild->getChildren().front()) { - logChild = mulToLogarithm(mulExprChildren, i); - - ArgumentPtr logLhs = logExprChild->getChildren().front(); - ArgumentPtr logRhs = mulExpr(logExprChild->getChildren().back(), logChild->getChildren().back()); - return logExpr(std::move(logLhs), std::move(logRhs)); - } - } - - return {}; -} - -std::vector AddExpr::findLogarithms(const ArgumentPtrVector &children) { - std::vector indices; - - for (const auto i : stdv::iota(0U, children.size())) { - if (const auto childExpr = cast(children[i]); - childExpr && is(childExpr->getFunction())) { - - indices.emplace_back(i); - } - } - - return indices; -} - -std::shared_ptr AddExpr::mulToLogarithm(const ArgumentPtrVector &children, const size_t i) { - ArgumentPtrVector mulChildren = children; - const auto logExprChild = cast(mulChildren[i]); - - mulChildren.erase(mulChildren.begin() + static_cast(i)); - - const ArgumentPtr powRate = mulChildren.size() > 1 ? mulExpr(std::move(mulChildren)) : mulChildren.front(); - const ArgumentPtr logRhsChild = powExpr(logExprChild->getChildren().back(), powRate); - - return cast(logExpr(logExprChild->getChildren().front(), logRhsChild)); -} - -ArgumentPtr AddExpr::mulSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - { - auto [lhsChildRate, lhsChildValue] = splitMulExpr(lhs, false); - auto [rhsChildRate, rhsChildValue] = splitMulExpr(rhs, false); - - if (*lhsChildValue == *rhsChildValue) { - return mulExpr(addExpr(lhsChildRate, rhsChildRate), lhsChildValue); - } - } - - { - auto [lhsChildRate, lhsChildValue] = splitMulExpr(lhs); - auto [rhsChildRate, rhsChildValue] = splitMulExpr(rhs); - - if (*lhsChildValue == *rhsChildValue && *lhsChildValue != Integer(1)) { - return mulExpr(addExpr(lhsChildRate, rhsChildRate), lhsChildValue); - } - } - - return {}; -} - -ArgumentPtr AddExpr::divSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - const auto lhsExpr = cast(lhs); - auto rhsExpr = cast(rhs); - - if (const auto rhsRat = cast(rhs)) { - rhsExpr = cast(divExpr(rhsRat->numerator(), rhsRat->denominator())); - } - - ArgumentPtr res; - - if (rhsExpr && is
(rhsExpr->getFunction()) && containsInfinity(rhsExpr)) { - return {}; - } - - if (lhsExpr && rhsExpr && - is
(lhsExpr->getFunction()) && is
(rhsExpr->getFunction())) { - - if (*lhsExpr->getChildren().back() == *rhsExpr->getChildren().back()) { - const ArgumentPtr &lhsNumerator = lhsExpr->getChildren().front(); - const ArgumentPtr &rhsNumerator = rhsExpr->getChildren().front(); - const ArgumentPtr &rhsDenominator = rhsExpr->getChildren().back(); - - ArgumentPtr numerator = addExpr(lhsNumerator, rhsNumerator); - ArgumentPtr denominator = rhsDenominator; - res = divExpr(std::move(numerator), std::move(denominator)); - } - else { - const ArgumentPtr &lhsNumerator = lhsExpr->getChildren().front(); - const ArgumentPtr &rhsNumerator = rhsExpr->getChildren().front(); - const ArgumentPtr &lhsDenominator = lhsExpr->getChildren().back(); - const ArgumentPtr &rhsDenominator = rhsExpr->getChildren().back(); - - ArgumentPtr lhsNumeratorMulRhsDenominator = mulExpr(lhsNumerator, rhsDenominator); - ArgumentPtr rhsNumeratorMulLhsDenominator = mulExpr(rhsNumerator, lhsDenominator); - - ArgumentPtr numerator = addExpr(std::move(lhsNumeratorMulRhsDenominator), std::move(rhsNumeratorMulLhsDenominator)); - ArgumentPtr denominator = mulExpr(lhsDenominator, rhsDenominator); - res = divExpr(std::move(numerator), std::move(denominator)); - } - } - else if (rhsExpr && is
(rhsExpr->getFunction())) { - const ArgumentPtr &rhsNumerator = rhsExpr->getChildren().front(); - const ArgumentPtr &rhsDenominator = rhsExpr->getChildren().back(); - - ArgumentPtr lhsMulRhsDenominator = mulExpr(lhs, rhsDenominator); - - ArgumentPtr numerator = addExpr(std::move(lhsMulRhsDenominator), rhsNumerator); - ArgumentPtr denominator = rhsDenominator; - res = divExpr(std::move(numerator), std::move(denominator)); - } - - return res; -} - -ArgumentPtr AddExpr::trigSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - auto [lhsMulRate, lhsMulValue] = splitMulExpr(lhs, false); - auto [rhsMulRate, rhsMulValue] = splitMulExpr(rhs, false); - - auto [lhsPowBase, lhsPowRate] = splitPowExpr(lhsMulValue); - auto [rhsPowBase, rhsPowRate] = splitPowExpr(rhsMulValue); - - const auto lhsPowBaseExpr = cast(lhsPowBase); - const auto rhsPowBaseExpr = cast(rhsPowBase); - - if (!lhsPowBaseExpr || *lhsPowRate != Integer(2)) { - return {}; - } - - if (containsInfinity(lhsPowBase) || containsInfinity(rhsPowBase)) { - return {}; - } - - const auto lhsPowBaseChild = lhsPowBaseExpr->getChildren().front(); - const auto lhsMulRateNum = cast(lhsMulRate); - - if (rhsPowBaseExpr && *rhsPowRate == Integer(2)) { - if (!is(lhsPowBaseExpr->getFunction()) || !is(rhsPowBaseExpr->getFunction())) { - return {}; - } - - const auto rhsPowBaseChild = rhsPowBaseExpr->getChildren().front(); - - if (*lhsPowBaseChild != *rhsPowBaseChild) { - return {}; - } - - if (*lhsMulRate == *rhsMulRate) { - return lhsMulRate; - } - - auto rhsMulRateNum = cast(rhsMulRate); - - if (lhsMulRateNum && rhsMulRateNum && *(*lhsMulRateNum + *rhsMulRateNum) == Integer(0)) { - static const ArgumentPtr two = Integer(2).clone(); - - ArgumentPtr res = cosExpr( - mulExpr(lhsPowBaseExpr->getChildren().front(), two)); - - return mulExpr(std::move(rhsMulRateNum), std::move(res)); - } - - return {}; - } - - auto rhsNum = cast(rhs); - - if (lhsMulRateNum && rhsNum && *(*lhsMulRateNum + *rhsNum) == Integer(0)) { - ArgumentPtr res = lhsPowBaseExpr->getChildren().front(); - - if (is(lhsPowBaseExpr->getFunction())) { - res = cosExpr(res); - } - else if (is(lhsPowBaseExpr->getFunction())) { - res = sinExpr(res); - } - else { - return {}; - } - - return mulExpr(rhsNum, sqrExpr(res)); - } - - return {}; -} - -} diff --git a/src/fintamath/expressions/polynomial/AddExpr.hpp b/src/fintamath/expressions/polynomial/AddExpr.hpp deleted file mode 100644 index c9413a78f..000000000 --- a/src/fintamath/expressions/polynomial/AddExpr.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class AddExpr final : public IPolynomExpressionCRTP { - FINTAMATH_CLASS_BODY(AddExpr) - -public: - explicit AddExpr(ArgumentPtrVector inChildren); - -protected: - SimplifyFunctionVector getFunctionsForPreSimplify() const override; - - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - - std::string childToString(const IOperator &oper, const ArgumentPtr &inChild, const ArgumentPtr &prevChild) const override; - - /** - * @brief - * - * @param lhs - * @param rhs - * @return -1 if we should swap the arguments - * @return 1 if we should not swap the arguments - * @return 0 if this comparator fails - */ - std::strong_ordering compare(const ArgumentPtr &lhs, const ArgumentPtr &rhs) const override; - -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 logSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr mulLogSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr mulSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr trigSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static std::vector findLogarithms(const ArgumentPtrVector &children); - - static std::shared_ptr mulToLogarithm(const ArgumentPtrVector &children, size_t i); -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/polynomial/AndExpr.cpp b/src/fintamath/expressions/polynomial/AndExpr.cpp deleted file mode 100644 index d3e70d7c7..000000000 --- a/src/fintamath/expressions/polynomial/AndExpr.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "fintamath/expressions/polynomial/AndExpr.hpp" - -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/logic/And.hpp" -#include "fintamath/functions/logic/Not.hpp" -#include "fintamath/functions/logic/Or.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -AndExpr::AndExpr(ArgumentPtrVector inChildren) - : IPolynomExpressionCRTP(And{}, std::move(inChildren)) { -} - -AndExpr::SimplifyFunctionVector AndExpr::getFunctionsForPreSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &AndExpr::boolSimplify, - &AndExpr::equalSimplify, - &AndExpr::notSimplify, - }; - return simplifyFunctions; -} - -AndExpr::SimplifyFunctionVector AndExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &AndExpr::orSimplify, - &AndExpr::boolSimplify, - &AndExpr::equalSimplify, - &AndExpr::notSimplify, - }; - return simplifyFunctions; -} - -bool AndExpr::isComparableOrderInversed() const { - return true; -} - -ArgumentPtr AndExpr::boolSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (const auto lhsBool = cast(lhs)) { - return *lhsBool ? rhs : lhs; - } - - if (const auto rhsBool = cast(rhs)) { - return *rhsBool ? lhs : rhs; - } - - return {}; -} - -ArgumentPtr AndExpr::equalSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (*lhs == *rhs) { - return lhs; - } - - return {}; -} - -ArgumentPtr AndExpr::notSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (const auto rhsExpr = cast(rhs); - rhsExpr && - is(rhsExpr->getFunction()) && - *rhsExpr->getChildren().front() == *lhs) { - - return Boolean(false).clone(); - } - - return {}; -} - -ArgumentPtr AndExpr::orSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - const auto lhsExpr = cast(lhs); - const auto rhsExpr = cast(rhs); - - ArgumentPtrVector lhsChildren; - ArgumentPtrVector rhsChildren; - - if (lhsExpr && is(lhsExpr->getFunction())) { - lhsChildren = lhsExpr->getChildren(); - } - else { - lhsChildren.emplace_back(lhs); - } - - if (rhsExpr && is(rhsExpr->getFunction())) { - rhsChildren = rhsExpr->getChildren(); - } - else { - rhsChildren.emplace_back(rhs); - } - - if (lhsChildren.size() == 1 && rhsChildren.size() == 1) { - return {}; - } - - ArgumentPtrVector resultVect; - - for (const auto &lhsSubChild : lhsChildren) { - for (const auto &rhsSubChild : rhsChildren) { - resultVect.emplace_back(andExpr(lhsSubChild, rhsSubChild)); - } - } - - ArgumentPtr res = orExpr(std::move(resultVect)); - return res; -} - -} diff --git a/src/fintamath/expressions/polynomial/AndExpr.hpp b/src/fintamath/expressions/polynomial/AndExpr.hpp deleted file mode 100644 index fe19e63a2..000000000 --- a/src/fintamath/expressions/polynomial/AndExpr.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class AndExpr final : public IPolynomExpressionCRTP { - FINTAMATH_CLASS_BODY(AndExpr) - -public: - explicit AndExpr(ArgumentPtrVector inChildren); - -protected: - SimplifyFunctionVector getFunctionsForPreSimplify() const override; - - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - - bool isComparableOrderInversed() const override; - -private: - static ArgumentPtr boolSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr equalSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr notSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr orSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/polynomial/MinMaxExpr.cpp b/src/fintamath/expressions/polynomial/MinMaxExpr.cpp deleted file mode 100644 index db25af23e..000000000 --- a/src/fintamath/expressions/polynomial/MinMaxExpr.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "fintamath/expressions/polynomial/MinMaxExpr.hpp" - -#include - -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -MinMaxExpr::MinMaxExpr(const IFunction &inFunc, ArgumentPtrVector inChildren) - : IPolynomExpressionCRTP(inFunc, std::move(inChildren)) { -} - -} diff --git a/src/fintamath/expressions/polynomial/MinMaxExpr.hpp b/src/fintamath/expressions/polynomial/MinMaxExpr.hpp deleted file mode 100644 index 983b14a65..000000000 --- a/src/fintamath/expressions/polynomial/MinMaxExpr.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class MinMaxExpr final : public IPolynomExpressionCRTP { - FINTAMATH_CLASS_BODY(MinMaxExpr) - -public: - explicit MinMaxExpr(const IFunction &inFunc, ArgumentPtrVector inChildren); -}; - -} diff --git a/src/fintamath/expressions/polynomial/MulExpr.cpp b/src/fintamath/expressions/polynomial/MulExpr.cpp deleted file mode 100644 index 3dedd03bc..000000000 --- a/src/fintamath/expressions/polynomial/MulExpr.cpp +++ /dev/null @@ -1,323 +0,0 @@ -#include "fintamath/expressions/polynomial/MulExpr.hpp" - -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/arithmetic/Sign.hpp" -#include "fintamath/functions/logarithms/Log.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/functions/trigonometry/Cos.hpp" -#include "fintamath/functions/trigonometry/Sin.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" -#include "fintamath/numbers/Rational.hpp" - -namespace fintamath { - -using namespace detail; - -MulExpr::MulExpr(ArgumentPtrVector inChildren) - : IPolynomExpressionCRTP(Mul{}, std::move(inChildren)) { -} - -std::string MulExpr::toString() const { - auto [childNumerator, childDenominator] = splitRational(children.front()); - - if (*childDenominator != Integer(1)) { - const bool isChildNumeratorPosOne = *childNumerator == Integer(1); - const bool isChildNumeratorNegOne = *childNumerator == Integer(-1); - - ArgumentPtrVector numeratorChildren = children; - - if (isChildNumeratorPosOne || isChildNumeratorNegOne) { - numeratorChildren.erase(numeratorChildren.begin()); - } - else { - numeratorChildren.front() = childNumerator; - } - - ArgumentPtr numerator = makePolynom(Mul{}, std::move(numeratorChildren)); - ArgumentPtr denominator = childDenominator; - const ArgumentPtr res = divExpr(std::move(numerator), std::move(denominator)); - - std::string resStr = res->toString(); - - if (isChildNumeratorNegOne) { - resStr.insert(resStr.begin(), '-'); - } - - return resStr; - } - - return IPolynomExpression::toString(); -} - -std::string MulExpr::childToString(const IOperator &oper, const ArgumentPtr &inChild, const ArgumentPtr &prevChild) const { - if (!prevChild && *inChild == Integer(-1)) { - return Neg{}.toString(); - } - - std::string operStr; - if (prevChild && *prevChild != Integer(-1)) { - if (is(inChild) && is(prevChild)) { - operStr = oper.toString(); - } - else { - operStr = " "; - } - } - - return operStr + operatorChildToString(oper, inChild); -} - -MulExpr::SimplifyFunctionVector MulExpr::getFunctionsForPreSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &MulExpr::rationalSimplify, - &MulExpr::divSimplify, - &MulExpr::powSimplify, - }; - return simplifyFunctions; -} - -MulExpr::SimplifyFunctionVector MulExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &MulExpr::constSimplify, - &MulExpr::polynomSimplify, - &MulExpr::divSimplify, - &MulExpr::powSimplify, - &MulExpr::trigDoubleAngleSimplify, - }; - return simplifyFunctions; -} - -bool MulExpr::isTermOrderInversed() const { - return true; -} - -ArgumentPtr MulExpr::constSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (*lhs == Integer(0)) { - if (isMulInfinity(rhs)) { - return Undefined{}.clone(); - } - - if (!containsInfinity(rhs)) { - return lhs; - } - } - - if (is(lhs) || is(rhs)) { - return ComplexInf{}.clone(); - } - - if (is(lhs) && is(rhs)) { - return lhs; - } - - if (is(rhs) && isComplexNumber(lhs)) { - return mulExpr(negExpr(lhs), Inf{}.clone()); - } - - if (*lhs == Integer(1)) { - return rhs; - } - - { - ArgumentPtr inf; - ArgumentPtr rate; - - if (is(lhs) || is(lhs)) { - inf = lhs; - rate = rhs; - } - else if (is(rhs) || is(rhs)) { - inf = rhs; - rate = lhs; - } - - if (rate && inf) { - if (*lhs == Integer(-1)) { - return is(rhs) ? NegInf{}.clone() : Inf{}.clone(); - } - - if (!isComplexNumber(rate) && !containsVariable(rate)) { - if (const auto rateExpr = cast(rate); !rateExpr || !is(rateExpr->getFunction())) { - return mulExpr(signExpr(rate), inf); - } - } - } - } - - return {}; -} - -ArgumentPtr MulExpr::rationalSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (const auto lhsRat = cast(lhs)) { - ArgumentPtr numerator = mulExpr(lhsRat->numerator().clone(), rhs); - ArgumentPtr denominator = lhsRat->denominator().clone(); - return divExpr(std::move(numerator), std::move(denominator)); - } - - return {}; -} - -ArgumentPtr MulExpr::divSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - const std::shared_ptr lhsExpr = cast(lhs); - const std::shared_ptr rhsExpr = cast(rhs); - - bool isLhsDiv = false; - bool isRhsDiv = false; - - if (lhsExpr && is
(lhsExpr->getFunction())) { - isLhsDiv = true; - } - - if (rhsExpr && is
(rhsExpr->getFunction())) { - isRhsDiv = true; - } - - ArgumentPtr numerator; - ArgumentPtr denominator; - - if (isLhsDiv && isRhsDiv) { - numerator = mulExpr(lhsExpr->getChildren().front(), rhsExpr->getChildren().front()); - denominator = mulExpr(lhsExpr->getChildren().back(), rhsExpr->getChildren().back()); - } - else if (isLhsDiv) { - numerator = mulExpr(lhsExpr->getChildren().front(), rhs); - denominator = lhsExpr->getChildren().back(); - } - else if (isRhsDiv) { - numerator = mulExpr(lhs, rhsExpr->getChildren().front()); - denominator = rhsExpr->getChildren().back(); - } - else { - return {}; - } - - ArgumentPtr res = divExpr(numerator, denominator); - return res; -} - -ArgumentPtr MulExpr::polynomSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - const auto lhsExpr = cast(lhs); - const auto rhsExpr = cast(rhs); - - if (lhsExpr && - rhsExpr && - !is(lhsExpr->getFunction()) && - !is(rhsExpr->getFunction())) { - - return {}; - } - - if ((lhsExpr && is(lhsExpr->getFunction())) || - (rhsExpr && is(rhsExpr->getFunction()))) { - - return {}; - } - - ArgumentPtrVector lhsChildren; - ArgumentPtrVector rhsChildren; - - if (lhsExpr && is(lhsExpr->getFunction())) { - lhsChildren = lhsExpr->getChildren(); - } - else { - lhsChildren.emplace_back(lhs); - } - - if (rhsExpr && is(rhsExpr->getFunction())) { - rhsChildren = rhsExpr->getChildren(); - } - else { - if (!containsVariable(lhs) && containsVariable(rhs)) { - return {}; - } - - rhsChildren.emplace_back(rhs); - } - - if (lhsChildren.size() == 1 && rhsChildren.size() == 1) { - return {}; - } - - ArgumentPtrVector resultVect; - - for (const auto &lhsSubChild : lhsChildren) { - for (const auto &rhsSubChild : rhsChildren) { - resultVect.emplace_back(mulExpr(lhsSubChild, rhsSubChild)); - } - } - - ArgumentPtr res = addExpr(std::move(resultVect)); - return res; -} - -ArgumentPtr MulExpr::powSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - auto [lhsChildBase, lhsChildRate] = splitPowExpr(lhs); - auto [rhsChildBase, rhsChildRate] = splitPowExpr(rhs); - - if (*lhsChildBase == *rhsChildBase) { - ArgumentPtr ratesSum = addExpr(std::move(lhsChildRate), std::move(rhsChildRate)); - return powExpr(std::move(lhsChildBase), std::move(ratesSum)); - } - - const auto lhsChildValueNum = cast(lhsChildBase); - const auto rhsChildValueNum = cast(rhsChildBase); - - if (lhsChildValueNum && - rhsChildValueNum && - !lhsChildValueNum->isComplex() && - !rhsChildValueNum->isComplex() && - *lhsChildValueNum >= Integer(0) && - *rhsChildValueNum >= Integer(0) && - *lhsChildRate == *rhsChildRate && - *rhsChildRate != Integer(1)) { - - ArgumentPtr valuesMul = mulExpr(std::move(lhsChildBase), std::move(rhsChildBase)); - return powExpr(std::move(valuesMul), std::move(lhsChildRate)); - } - - return {}; -} - -ArgumentPtr MulExpr::trigDoubleAngleSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - const auto lhsExpr = cast(lhs); - const auto rhsExpr = cast(rhs); - - if (!lhsExpr || - !rhsExpr || - !is(lhsExpr->getFunction()) || - !is(rhsExpr->getFunction())) { - - return {}; - } - - auto lhsChild = lhsExpr->getChildren().front(); - const auto rhsChild = rhsExpr->getChildren().front(); - - if (*lhsChild != *rhsChild || containsInfinity(lhsChild)) { - return {}; - } - - ArgumentPtr doubleSin = sinExpr( - mulExpr(std::move(lhsChild), Integer(2).clone())); - - return divExpr(doubleSin, Integer(2).clone()); -} -} diff --git a/src/fintamath/expressions/polynomial/MulExpr.hpp b/src/fintamath/expressions/polynomial/MulExpr.hpp deleted file mode 100644 index f31aede8b..000000000 --- a/src/fintamath/expressions/polynomial/MulExpr.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { -class MulExpr final : public IPolynomExpressionCRTP { - FINTAMATH_CLASS_BODY(MulExpr) - -public: - explicit MulExpr(ArgumentPtrVector inChildren); - - std::string toString() const override; - -protected: - std::string childToString(const IOperator &oper, const ArgumentPtr &inChild, const ArgumentPtr &prevChild) const override; - - SimplifyFunctionVector getFunctionsForPreSimplify() const override; - - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - - bool isTermOrderInversed() const override; - -private: - static ArgumentPtr constSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr rationalSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr divSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr polynomSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr powSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr trigDoubleAngleSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/polynomial/OrExpr.cpp b/src/fintamath/expressions/polynomial/OrExpr.cpp deleted file mode 100644 index 3fd2bbe34..000000000 --- a/src/fintamath/expressions/polynomial/OrExpr.cpp +++ /dev/null @@ -1,255 +0,0 @@ -#include "fintamath/expressions/polynomial/OrExpr.hpp" - -#include -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/logic/And.hpp" -#include "fintamath/functions/logic/Not.hpp" -#include "fintamath/functions/logic/Or.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -using namespace detail; - -OrExpr::OrExpr(ArgumentPtrVector inChildren) - : IPolynomExpressionCRTP(Or{}, std::move(inChildren)) { -} - -std::string OrExpr::childToString(const IOperator &oper, const ArgumentPtr &inChild, const ArgumentPtr &prevChild) const { - std::string result = operatorChildToString(oper, inChild); - - if (const auto &childExpr = cast(inChild); - childExpr && is(childExpr->getFunction())) { - - result = putInBrackets(result); - } - - return prevChild ? (putInSpaces(func->toString()) + result) : result; -} - -ArgumentPtr OrExpr::postSimplify() const { - ArgumentPtr simplObj = IPolynomExpression::postSimplify(); - auto simpl = cast(simplObj); - - if (!simpl) { - return simplObj; - } - - ArgumentPtrVector simplChildren = simpl->children; - const size_t simplChildrenSizeInitial = simplChildren.size(); - - // TODO: use more efficient algorithm - for (size_t i = 0; i + 1 < simplChildren.size(); i++) { - for (size_t j = i + 1; j < simplChildren.size(); j++) { - if (auto res = absorptionSimplify(simplChildren[i], simplChildren[j])) { - simplChildren[i] = std::move(res); - simplChildren.erase(simplChildren.begin() + static_cast(j)); - j--; - } - } - } - - if (simplChildren.size() != simplChildrenSizeInitial) { - if (simplChildren.size() > 1) { - ArgumentPtr res = orExpr(std::move(simplChildren)); - postSimplifyChild(res); - return res; - } - - return simplChildren.front(); - } - - return simpl; -} - -OrExpr::SimplifyFunctionVector OrExpr::getFunctionsForPreSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &OrExpr::notSimplify, - &OrExpr::boolSimplify, - &OrExpr::equalSimplify, - }; - return simplifyFunctions; -} - -OrExpr::SimplifyFunctionVector OrExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &OrExpr::andSimplify, - &OrExpr::notSimplify, - &OrExpr::boolSimplify, - &OrExpr::equalSimplify, - }; - return simplifyFunctions; -} - -bool OrExpr::isComparableOrderInversed() const { - return true; -} - -ArgumentPtr OrExpr::boolSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - - if (const auto lhsBool = cast(lhs)) { - return *lhsBool ? lhs : rhs; - } - - if (const auto rhsBool = cast(rhs)) { - return *rhsBool ? rhs : lhs; - } - - return {}; -} - -ArgumentPtr OrExpr::equalSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (*lhs == *rhs) { - return lhs; - } - - return {}; -} - -ArgumentPtr OrExpr::notSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - if (const auto rhsExpr = cast(rhs); - rhsExpr && - is(rhsExpr->getFunction()) && - *rhsExpr->getChildren().front() == *lhs) { - - return Boolean(true).clone(); - } - - return {}; -} - -ArgumentPtr OrExpr::andSimplify(const IFunction & /*func*/, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - const auto lhsExpr = cast(lhs); - const auto rhsExpr = cast(rhs); - - if (!lhsExpr || !rhsExpr || - !is(lhsExpr->getFunction()) || !is(rhsExpr->getFunction())) { - return {}; - } - - const ArgumentPtrVector &lhsChildren = lhsExpr->getChildren(); - const ArgumentPtrVector &rhsChildren = rhsExpr->getChildren(); - - if (rhsChildren.size() != lhsChildren.size()) { - return {}; - } - - size_t resolutionIndex = lhsChildren.size(); - - for (const auto i : stdv::iota(0U, lhsChildren.size())) { - ArgumentPtr lhsSubChild = lhsChildren[i]; - ArgumentPtr rhsSubChild = rhsChildren[i]; - - bool isLhsSubChildNot = false; - - if (const auto lhsSubChildNotExpr = cast(lhsSubChild); - lhsSubChildNotExpr && - is(lhsSubChildNotExpr->getFunction())) { - - isLhsSubChildNot = true; - lhsSubChild = lhsSubChildNotExpr->getChildren().front(); - } - - bool isRhsSubChildNot = false; - - if (const auto rhsSubChildNotExpr = cast(rhsSubChild); - rhsSubChildNotExpr && - is(rhsSubChildNotExpr->getFunction())) { - - isRhsSubChildNot = true; - rhsSubChild = rhsSubChildNotExpr->getChildren().front(); - } - - if (*lhsSubChild != *rhsSubChild) { - return {}; - } - - if (isLhsSubChildNot != isRhsSubChildNot) { - if (resolutionIndex != lhsChildren.size()) { - return {}; - } - - resolutionIndex = i; - } - } - - if (resolutionIndex == lhsChildren.size()) { - return {}; - } - - ArgumentPtrVector resultChildren = lhsChildren; - resultChildren.erase(resultChildren.begin() + static_cast(resolutionIndex)); - - if (resultChildren.size() > 1) { - ArgumentPtr res = andExpr(std::move(resultChildren)); - return res; - } - - return resultChildren.front(); -} - -ArgumentPtr OrExpr::absorptionSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs) { - const auto lhsExpr = cast(lhs); - const auto rhsExpr = cast(rhs); - - ArgumentPtrVector lhsChildren; - ArgumentPtrVector rhsChildren; - - if (lhsExpr && is(lhsExpr->getFunction())) { - lhsChildren = lhsExpr->getChildren(); - } - else { - lhsChildren.emplace_back(lhs); - } - - if (rhsExpr && is(rhsExpr->getFunction())) { - rhsChildren = rhsExpr->getChildren(); - } - else { - rhsChildren.emplace_back(rhs); - } - - if (lhsChildren.size() == rhsChildren.size()) { - return {}; - } - - const ArgumentPtrVector maxChildren = lhsChildren.size() > rhsChildren.size() ? lhsChildren : rhsChildren; - ArgumentPtrVector minChildren = lhsChildren.size() < rhsChildren.size() ? lhsChildren : rhsChildren; - size_t matchCount = 0; - - { - size_t i = 0; - size_t j = 0; - - while (i < maxChildren.size() && j < minChildren.size()) { - if (*maxChildren[i] == *minChildren[j]) { - matchCount++; - j++; - } - - i++; - } - } - - if (matchCount == minChildren.size()) { - if (minChildren.size() > 1) { - ArgumentPtr res = andExpr(std::move(minChildren)); - return res; - } - - return minChildren.front(); - } - - return {}; -} - -} diff --git a/src/fintamath/expressions/polynomial/OrExpr.hpp b/src/fintamath/expressions/polynomial/OrExpr.hpp deleted file mode 100644 index 0c12762cb..000000000 --- a/src/fintamath/expressions/polynomial/OrExpr.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class OrExpr final : public IPolynomExpressionCRTP { - FINTAMATH_CLASS_BODY(OrExpr) - -public: - explicit OrExpr(ArgumentPtrVector inChildren); - -protected: - std::string childToString(const IOperator &oper, const ArgumentPtr &inChild, const ArgumentPtr &prevChild) const override; - - ArgumentPtr postSimplify() const override; - - SimplifyFunctionVector getFunctionsForPreSimplify() const override; - - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - - bool isComparableOrderInversed() const override; - -private: - static ArgumentPtr boolSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr equalSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr notSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr andSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs); - - static ArgumentPtr absorptionSimplify(const ArgumentPtr &lhs, const ArgumentPtr &rhs); -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/unary/AbsExpr.cpp b/src/fintamath/expressions/unary/AbsExpr.cpp deleted file mode 100644 index 72ff6ff08..000000000 --- a/src/fintamath/expressions/unary/AbsExpr.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "fintamath/expressions/unary/AbsExpr.hpp" - -#include - -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/arithmetic/Abs.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/literals/constants/Inf.hpp" - -namespace fintamath { - -using namespace detail; - -AbsExpr::AbsExpr(ArgumentPtr inChild) - : IUnaryExpressionCRTP(Abs{}, std::move(inChild)) { -} - -AbsExpr::SimplifyFunctionVector AbsExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &AbsExpr::constSimplify, - &AbsExpr::negSimplify, - }; - return simplifyFunctions; -} - -ArgumentPtr AbsExpr::constSimplify(const IFunction & /*func*/, const ArgumentPtr &rhs) { - if (isInfinity(rhs)) { - return Inf{}.clone(); - } - - return {}; -} - -ArgumentPtr AbsExpr::negSimplify(const IFunction & /*func*/, const ArgumentPtr &rhs) { - if (isNegated(rhs)) { - return absExpr(negExpr(rhs)); - } - - return {}; -} - -} diff --git a/src/fintamath/expressions/unary/AbsExpr.hpp b/src/fintamath/expressions/unary/AbsExpr.hpp deleted file mode 100644 index ec5cf037e..000000000 --- a/src/fintamath/expressions/unary/AbsExpr.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class AbsExpr final : public IUnaryExpressionCRTP { - FINTAMATH_CLASS_BODY(AbsExpr) - -public: - explicit AbsExpr(ArgumentPtr inChild); - -protected: - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - -private: - static ArgumentPtr constSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static ArgumentPtr negSimplify(const IFunction &func, const ArgumentPtr &rhs); -}; - -} diff --git a/src/fintamath/expressions/unary/FloorCeilExpr.cpp b/src/fintamath/expressions/unary/FloorCeilExpr.cpp deleted file mode 100644 index b8cf1d472..000000000 --- a/src/fintamath/expressions/unary/FloorCeilExpr.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "fintamath/expressions/unary/FloorCeilExpr.hpp" - -#include -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/ntheory/Ceil.hpp" -#include "fintamath/functions/ntheory/Floor.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -using namespace detail; - -FloorCeilExpr::FloorCeilExpr(const IFunction &inFunc, ArgumentPtr inChild) - : IUnaryExpressionCRTP(inFunc, std::move(inChild)) { -} - -FloorCeilExpr::SimplifyFunctionVector FloorCeilExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &FloorCeilExpr::negSimplify, - &FloorCeilExpr::intapproximate, - }; - return simplifyFunctions; -} - -ArgumentPtr FloorCeilExpr::intapproximate(const IFunction &func, const ArgumentPtr &rhs) { - if (containsVariable(rhs)) { - return {}; - } - - ArgumentPtr approx = rhs->clone(); - approximateChild(approx); - - if (auto res = cast(callFunction(func, {approx}))) { - return res; - } - - return {}; -} - -ArgumentPtr FloorCeilExpr::negSimplify(const IFunction &func, const ArgumentPtr &rhs) { - if (isNegated(rhs)) { - return negExpr(makeExpr(*getOppositeFunction(func), negExpr(rhs))); - } - - return {}; -} - -std::shared_ptr FloorCeilExpr::getOppositeFunction(const IFunction &function) { - static const std::unordered_map> nameToOppositeFuncMap = { - {Floor{}.toString(), std::make_shared()}, - {Ceil{}.toString(), std::make_shared()}, - }; - return nameToOppositeFuncMap.at(function.toString()); -} - -} diff --git a/src/fintamath/expressions/unary/FloorCeilExpr.hpp b/src/fintamath/expressions/unary/FloorCeilExpr.hpp deleted file mode 100644 index e6ae04015..000000000 --- a/src/fintamath/expressions/unary/FloorCeilExpr.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class Rational; - -class FloorCeilExpr final : public IUnaryExpressionCRTP { - FINTAMATH_CLASS_BODY(FloorCeilExpr) - -public: - explicit FloorCeilExpr(const IFunction &inFunc, ArgumentPtr inChild); - -protected: - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - -private: - static ArgumentPtr intapproximate(const IFunction &func, const ArgumentPtr &rhs); - - static ArgumentPtr negSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static std::shared_ptr getOppositeFunction(const IFunction &function); -}; - -} diff --git a/src/fintamath/expressions/unary/HyperbExpr.cpp b/src/fintamath/expressions/unary/HyperbExpr.cpp deleted file mode 100644 index 6a773e05f..000000000 --- a/src/fintamath/expressions/unary/HyperbExpr.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "fintamath/expressions/unary/HyperbExpr.hpp" - -#include -#include -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/hyperbolic/Acosh.hpp" -#include "fintamath/functions/hyperbolic/Acoth.hpp" -#include "fintamath/functions/hyperbolic/Acsch.hpp" -#include "fintamath/functions/hyperbolic/Asech.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/Csch.hpp" -#include "fintamath/functions/hyperbolic/Sech.hpp" -#include "fintamath/functions/hyperbolic/Sinh.hpp" -#include "fintamath/functions/hyperbolic/Tanh.hpp" - -namespace fintamath { - -using namespace detail; - -using NameToSimplifyFunctionMap = std::unordered_map>; - -HyperbExpr::HyperbExpr(const IFunction &inFunc, ArgumentPtr inChild) - : IUnaryExpressionCRTP(inFunc, std::move(inChild)) { -} - -HyperbExpr::SimplifyFunctionVector HyperbExpr::getFunctionsForPreSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &HyperbExpr::oppositeFunctionsSimplify, - &HyperbExpr::expandSimplify, - }; - return simplifyFunctions; -} - -HyperbExpr::SimplifyFunctionVector HyperbExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &HyperbExpr::oppositeFunctionsSimplify, - &HyperbExpr::negSimplify, - }; - return simplifyFunctions; -} - -ArgumentPtr HyperbExpr::oppositeFunctionsSimplify(const IFunction &func, const ArgumentPtr &rhs) { - if (const auto expr = cast(rhs)) { - if (const auto oppositeFunc = getOppositeFunction(func)) { - if (*expr->getFunction() == *oppositeFunc) { - return expr->getChildren().front(); - } - } - } - - return {}; -} - -ArgumentPtr HyperbExpr::expandSimplify(const IFunction &func, const ArgumentPtr &rhs) { - static const NameToSimplifyFunctionMap nameToExpandFunctionMap = { - {Tanh{}.toString(), - [](const ArgumentPtr &inRhs) { - return divExpr(sinhExpr(inRhs), coshExpr(inRhs)); - }}, - {Coth{}.toString(), - [](const ArgumentPtr &inRhs) { - return divExpr(coshExpr(inRhs), sinhExpr(inRhs)); - }}, - {Sech{}.toString(), - [](const ArgumentPtr &inRhs) { - return divExpr(Integer(1).clone(), coshExpr(inRhs)); - }}, - {Csch{}.toString(), - [](const ArgumentPtr &inRhs) { - return divExpr(Integer(1).clone(), sinhExpr(inRhs)); - }}, - }; - - if (const auto iter = nameToExpandFunctionMap.find(func.toString()); iter != nameToExpandFunctionMap.end()) { - return iter->second(rhs); - } - - return {}; -} - -ArgumentPtr HyperbExpr::negSimplify(const IFunction &func, const ArgumentPtr &rhs) { - static const NameToSimplifyFunctionMap nameToNegFunctionsMap = { - {Sinh{}.toString(), - [](const ArgumentPtr &inRhs) { - return negExpr(sinhExpr(negExpr(inRhs))); - }}, - {Cosh{}.toString(), - [](const ArgumentPtr &inRhs) { - return coshExpr(negExpr(inRhs)); - }}, - }; - - if (isNegated(rhs)) { - if (const auto iter = nameToNegFunctionsMap.find(func.toString()); iter != nameToNegFunctionsMap.end()) { - return iter->second(rhs); - } - } - - return {}; -} - -std::shared_ptr HyperbExpr::getOppositeFunction(const IFunction &function) { - static const std::unordered_map> nameToOppositeFunctionMap = { - {Sinh{}.toString(), std::make_unique()}, - {Cosh{}.toString(), std::make_unique()}, - {Tanh{}.toString(), std::make_unique()}, - {Coth{}.toString(), std::make_unique()}, - {Sech{}.toString(), std::make_shared()}, - {Csch{}.toString(), std::make_shared()}, - }; - return nameToOppositeFunctionMap.at(function.toString()); -} - -} diff --git a/src/fintamath/expressions/unary/HyperbExpr.hpp b/src/fintamath/expressions/unary/HyperbExpr.hpp deleted file mode 100644 index 3a5e5543b..000000000 --- a/src/fintamath/expressions/unary/HyperbExpr.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class HyperbExpr final : public IUnaryExpressionCRTP { - FINTAMATH_CLASS_BODY(HyperbExpr) - -public: - explicit HyperbExpr(const IFunction &inFunc, ArgumentPtr inChild); - -protected: - SimplifyFunctionVector getFunctionsForPreSimplify() const override; - - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - -private: - static ArgumentPtr oppositeFunctionsSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static ArgumentPtr expandSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static ArgumentPtr negSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static std::shared_ptr getOppositeFunction(const IFunction &function); -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/unary/InvHyperbExpr.cpp b/src/fintamath/expressions/unary/InvHyperbExpr.cpp deleted file mode 100644 index 9ff549e8c..000000000 --- a/src/fintamath/expressions/unary/InvHyperbExpr.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "fintamath/expressions/unary/InvHyperbExpr.hpp" - -#include - -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -InvHyperbExpr::InvHyperbExpr(const IFunction &inFunc, ArgumentPtr inChild) - : IUnaryExpressionCRTP(inFunc, std::move(inChild)) { -} - -} diff --git a/src/fintamath/expressions/unary/InvHyperbExpr.hpp b/src/fintamath/expressions/unary/InvHyperbExpr.hpp deleted file mode 100644 index 6b05440ce..000000000 --- a/src/fintamath/expressions/unary/InvHyperbExpr.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class InvHyperbExpr final : public IUnaryExpressionCRTP { - FINTAMATH_CLASS_BODY(InvHyperbExpr) - -public: - explicit InvHyperbExpr(const IFunction &inFunc, ArgumentPtr inChild); -}; - -} diff --git a/src/fintamath/expressions/unary/InvTrigExpr.cpp b/src/fintamath/expressions/unary/InvTrigExpr.cpp deleted file mode 100644 index 611e9307a..000000000 --- a/src/fintamath/expressions/unary/InvTrigExpr.cpp +++ /dev/null @@ -1,184 +0,0 @@ -#include "fintamath/expressions/unary/InvTrigExpr.hpp" - -#include -#include -#include -#include - -#include "fintamath/core/Converter.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/powers/Sqrt.hpp" -#include "fintamath/functions/trigonometry/Acos.hpp" -#include "fintamath/functions/trigonometry/Acot.hpp" -#include "fintamath/functions/trigonometry/Acsc.hpp" -#include "fintamath/functions/trigonometry/Asec.hpp" -#include "fintamath/functions/trigonometry/Asin.hpp" -#include "fintamath/functions/trigonometry/Atan.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/literals/constants/Pi.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" -#include "fintamath/numbers/Rational.hpp" - -namespace fintamath { - -using NameToSimplifyFunctionMap = std::unordered_map>; - -using TrigTable = std::unordered_map; - -ArgumentPtr findValue(const TrigTable &trigTable, const Rational &key); - -InvTrigExpr::InvTrigExpr(const IFunction &inFunc, ArgumentPtr inChild) - : IUnaryExpressionCRTP(inFunc, std::move(inChild)) { -} - -InvTrigExpr::SimplifyFunctionVector InvTrigExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &InvTrigExpr::constSimplify, - }; - return simplifyFunctions; -} - -ArgumentPtr InvTrigExpr::constSimplify(const IFunction &func, const ArgumentPtr &rhs) { - if (const auto rat = convert(*rhs)) { - const Rational sqr = pow(*rat, 2) * rat->sign(); - return TrigTableSimplify(func, sqr); - } - - if (const auto expr = cast(rhs)) { - if (is(expr->getOutputFunction())) { - if (const auto sqrtChildInt = cast(expr->getChildren().front())) { - const Rational sqr = (*sqrtChildInt); - return TrigTableSimplify(func, sqr); - } - } - - if (is(expr->getOutputFunction())) { - const auto childRat = convert(*expr->getChildren().front()); - const auto childExpr = cast(expr->getChildren().back()); - - if (childRat && childExpr && - is(childExpr->getOutputFunction())) { - - if (const auto sqrtChildInt = cast(childExpr->getChildren().front())) { - const Rational sqr = pow(*childRat, 2) * (*sqrtChildInt) * childRat->sign(); - return TrigTableSimplify(func, sqr); - } - } - } - } - - return {}; -} - -ArgumentPtr InvTrigExpr::TrigTableSimplify(const IFunction &func, const Rational &rhs) { - static const NameToSimplifyFunctionMap nameToSimplifyFunctionMap = { - {Asin{}.toString(), &TrigTableAsinSimplify}, - {Acos{}.toString(), &TrigTableAcosSimplify}, - {Atan{}.toString(), &TrigTableAtanSimplify}, - {Acot{}.toString(), &TrigTableAcotSimplify}, - {Asec{}.toString(), &TrigTableAsecSimplify}, - {Acsc{}.toString(), &TrigTableAcscSimplify}, - }; - return nameToSimplifyFunctionMap.at(func.toString())(rhs); -} - -ArgumentPtr InvTrigExpr::TrigTableAsinSimplify(const Rational &rhs) { - static const TrigTable trigTable = { - {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 InvTrigExpr::TrigTableAcosSimplify(const Rational &rhs) { - static const TrigTable trigTable = { - {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 InvTrigExpr::TrigTableAtanSimplify(const Rational &rhs) { - static const TrigTable trigTable = { - {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 InvTrigExpr::TrigTableAcotSimplify(const Rational &rhs) { - static const TrigTable trigTable = { - {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); -} - -ArgumentPtr InvTrigExpr::TrigTableAsecSimplify(const Rational &rhs) { - static const TrigTable trigTable = { - {Rational(-1), Pi{}.clone()}, // -1 | Ï€ - {Rational(-4, 3), mulExpr(Rational(5, 6), Pi{})}, // -2/√3 | 5Ï€/6 - {Rational(-2), mulExpr(Rational(3, 4), Pi{})}, // -2/√2 | 3Ï€/4 - {Rational(-4), mulExpr(Rational(2, 3), Pi{})}, // -2 | 2Ï€/3 - {Rational(0), ComplexInf{}.clone()}, // 0 | ComplexInf - {Rational(4), mulExpr(Rational(1, 3), Pi{})}, // 2 | Ï€/3 - {Rational(2), mulExpr(Rational(1, 4), Pi{})}, // 2/√2 | Ï€/4 - {Rational(4, 3), mulExpr(Rational(1, 6), Pi{})}, // 2/√3 | Ï€/6 - {Rational(1), Integer(0).clone()}, // 1 | 0 - }; - return findValue(trigTable, rhs); -} - -ArgumentPtr InvTrigExpr::TrigTableAcscSimplify(const Rational &rhs) { - static const TrigTable trigTable = { - {Rational(-1), mulExpr(Rational(-1, 2), Pi{})}, // -1 | -Ï€/2 - {Rational(-4, 3), mulExpr(Rational(-1, 3), Pi{})}, // -2/√3 | -Ï€/3 - {Rational(-2), mulExpr(Rational(-1, 4), Pi{})}, // -2/√2 | -Ï€/4 - {Rational(-4), mulExpr(Rational(-1, 6), Pi{})}, // -2 | -Ï€/6 - {Rational(0), ComplexInf{}.clone()}, // 0 | ComplexInf - {Rational(4), mulExpr(Rational(1, 6), Pi{})}, // 2 | Ï€/6 - {Rational(2), mulExpr(Rational(1, 4), Pi{})}, // 2/√2 | Ï€/4 - {Rational(4, 3), mulExpr(Rational(1, 3), Pi{})}, // 2/√3 | Ï€/3 - {Rational(1), mulExpr(Rational(-1, 2), Pi{})}, // 1 | -Ï€/2 - }; - return findValue(trigTable, rhs); -} - -ArgumentPtr findValue(const TrigTable &trigTable, const Rational &key) { - if (const auto res = trigTable.find(key); res != trigTable.end()) { - return res->second; - } - - return {}; -} - -} diff --git a/src/fintamath/expressions/unary/InvTrigExpr.hpp b/src/fintamath/expressions/unary/InvTrigExpr.hpp deleted file mode 100644 index df8f0f5ae..000000000 --- a/src/fintamath/expressions/unary/InvTrigExpr.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class Rational; - -class InvTrigExpr final : public IUnaryExpressionCRTP { - FINTAMATH_CLASS_BODY(InvTrigExpr) - -public: - explicit InvTrigExpr(const IFunction &inFunc, ArgumentPtr inChild); - -protected: - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - -private: - static ArgumentPtr constSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static ArgumentPtr TrigTableSimplify(const IFunction &func, const Rational &rhs); - - static ArgumentPtr TrigTableAsinSimplify(const Rational &rhs); - - static ArgumentPtr TrigTableAcosSimplify(const Rational &rhs); - - static ArgumentPtr TrigTableAtanSimplify(const Rational &rhs); - - static ArgumentPtr TrigTableAcotSimplify(const Rational &rhs); - - static ArgumentPtr TrigTableAsecSimplify(const Rational &rhs); - - static ArgumentPtr TrigTableAcscSimplify(const Rational &rhs); -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/unary/NotExpr.cpp b/src/fintamath/expressions/unary/NotExpr.cpp deleted file mode 100644 index b8ea00fe3..000000000 --- a/src/fintamath/expressions/unary/NotExpr.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include "fintamath/expressions/unary/NotExpr.hpp" - -#include -#include -#include -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/IOperator.hpp" -#include "fintamath/functions/comparison/Eqv.hpp" -#include "fintamath/functions/comparison/Less.hpp" -#include "fintamath/functions/comparison/LessEqv.hpp" -#include "fintamath/functions/comparison/More.hpp" -#include "fintamath/functions/comparison/MoreEqv.hpp" -#include "fintamath/functions/comparison/Neqv.hpp" -#include "fintamath/functions/logic/And.hpp" -#include "fintamath/functions/logic/Not.hpp" -#include "fintamath/functions/logic/Or.hpp" - -namespace fintamath { - -using namespace detail; - -NotExpr::NotExpr(ArgumentPtr inChild) - : IUnaryExpressionCRTP(Not{}, std::move(inChild)) { -} - -NotExpr::SimplifyFunctionVector NotExpr::getFunctionsForPreSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &NotExpr::nestedNotSimplify, - }; - return simplifyFunctions; -} - -NotExpr::SimplifyFunctionVector NotExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &NotExpr::logicNegatableSimplify, - &NotExpr::nestedNotSimplify, - }; - return simplifyFunctions; -} - -ArgumentPtr NotExpr::logicNegatableSimplify(const IFunction & /*func*/, const ArgumentPtr &rhs) { - const std::shared_ptr rhsExpr = cast(rhs); - - if (!rhsExpr) { - return {}; - } - - ArgumentPtr res; - - if (const auto op = cast(rhsExpr->getFunction()); - op && op->getPriority() == IOperator::Priority::Comparison) { - - res = makeExpr(*cast(getLogicOppositeFunction(*op)), rhsExpr->getChildren()); - } - else if (is(rhsExpr->getFunction())) { - ArgumentPtrVector children = rhsExpr->getChildren(); - - for (auto &child : children) { - child = notExpr(child); - } - - res = andExpr(std::move(children)); - } - else if (is(rhsExpr->getFunction())) { - ArgumentPtrVector children = rhsExpr->getChildren(); - - for (auto &child : children) { - child = notExpr(child); - } - - res = orExpr(std::move(children)); - } - - return res; -} - -ArgumentPtr NotExpr::nestedNotSimplify(const IFunction & /*func*/, const ArgumentPtr &rhs) { - if (const auto expr = cast(rhs)) { - return expr->child; - } - - return {}; -} - -std::shared_ptr NotExpr::getLogicOppositeFunction(const IFunction &function) { - static const std::unordered_map> nameToOppositeFunctionMap = { - {Eqv{}.toString(), std::make_shared()}, - {Neqv{}.toString(), std::make_shared()}, - {More{}.toString(), std::make_shared()}, - {Less{}.toString(), std::make_shared()}, - {MoreEqv{}.toString(), std::make_shared()}, - {LessEqv{}.toString(), std::make_shared()}, - }; - return nameToOppositeFunctionMap.at(function.toString()); -} - -} diff --git a/src/fintamath/expressions/unary/NotExpr.hpp b/src/fintamath/expressions/unary/NotExpr.hpp deleted file mode 100644 index 1bbf58260..000000000 --- a/src/fintamath/expressions/unary/NotExpr.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class NotExpr final : public IUnaryExpressionCRTP { - FINTAMATH_CLASS_BODY(NotExpr) - -public: - explicit NotExpr(ArgumentPtr inChild); - -protected: - SimplifyFunctionVector getFunctionsForPreSimplify() const override; - - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - -private: - static ArgumentPtr logicNegatableSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static ArgumentPtr nestedNotSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static std::shared_ptr getLogicOppositeFunction(const IFunction &function); -}; - -} \ No newline at end of file diff --git a/src/fintamath/expressions/unary/SignExpr.cpp b/src/fintamath/expressions/unary/SignExpr.cpp deleted file mode 100644 index 8f9718b02..000000000 --- a/src/fintamath/expressions/unary/SignExpr.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "fintamath/expressions/unary/SignExpr.hpp" - -#include - -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/arithmetic/Sign.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/literals/constants/Inf.hpp" -#include "fintamath/literals/constants/NegInf.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -using namespace detail; - -SignExpr::SignExpr(ArgumentPtr inChild) - : IUnaryExpressionCRTP(Sign{}, std::move(inChild)) { -} - -SignExpr::SimplifyFunctionVector SignExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &SignExpr::constSimplify, - &SignExpr::negSimplify, - &SignExpr::intapproximate, - }; - return simplifyFunctions; -} - -ArgumentPtr SignExpr::constSimplify(const IFunction & /*func*/, const ArgumentPtr &rhs) { - if (is(rhs)) { - return Integer(1).clone(); - } - - if (is(rhs)) { - return Integer(-1).clone(); - } - - if (is(rhs)) { - return Undefined{}.clone(); - } - - return {}; -} - -ArgumentPtr SignExpr::intapproximate(const IFunction &func, const ArgumentPtr &rhs) { - if (containsVariable(rhs)) { - return {}; - } - - ArgumentPtr approx = rhs->clone(); - approximateChild(approx); - - if (const auto approxNum = cast(approx); approxNum && !approxNum->isComplex()) { - return callFunction(func, {approx}); - } - - return {}; -} - -ArgumentPtr SignExpr::negSimplify(const IFunction & /*func*/, const ArgumentPtr &rhs) { - if (isNegated(rhs)) { - return negExpr(signExpr(negExpr(rhs))); - } - - return {}; -} - -} diff --git a/src/fintamath/expressions/unary/SignExpr.hpp b/src/fintamath/expressions/unary/SignExpr.hpp deleted file mode 100644 index 839f1eea1..000000000 --- a/src/fintamath/expressions/unary/SignExpr.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class SignExpr final : public IUnaryExpressionCRTP { - FINTAMATH_CLASS_BODY(SignExpr) - -public: - explicit SignExpr(ArgumentPtr inChild); - -protected: - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - -private: - static ArgumentPtr constSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static ArgumentPtr intapproximate(const IFunction &func, const ArgumentPtr &rhs); - - static ArgumentPtr negSimplify(const IFunction &func, const ArgumentPtr &rhs); -}; - -} diff --git a/src/fintamath/expressions/unary/TrigExpr.cpp b/src/fintamath/expressions/unary/TrigExpr.cpp deleted file mode 100644 index b0cf0fdd1..000000000 --- a/src/fintamath/expressions/unary/TrigExpr.cpp +++ /dev/null @@ -1,257 +0,0 @@ -#include "fintamath/expressions/unary/TrigExpr.hpp" - -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/Converter.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/powers/Sqrt.hpp" -#include "fintamath/functions/trigonometry/Acos.hpp" -#include "fintamath/functions/trigonometry/Acot.hpp" -#include "fintamath/functions/trigonometry/Acsc.hpp" -#include "fintamath/functions/trigonometry/Asec.hpp" -#include "fintamath/functions/trigonometry/Asin.hpp" -#include "fintamath/functions/trigonometry/Atan.hpp" -#include "fintamath/functions/trigonometry/Cos.hpp" -#include "fintamath/functions/trigonometry/Cot.hpp" -#include "fintamath/functions/trigonometry/Csc.hpp" -#include "fintamath/functions/trigonometry/Sec.hpp" -#include "fintamath/functions/trigonometry/Sin.hpp" -#include "fintamath/functions/trigonometry/Tan.hpp" -#include "fintamath/literals/constants/Pi.hpp" - -namespace fintamath { - -using namespace detail; - -using NameToSimplifyFunctionMap = std::unordered_map>; - -using NameToTrigFunctionMap = std::unordered_map>; - -using TrigTable = std::unordered_map; - -ArgumentPtr findValue(const TrigTable &trigTable, const Rational &key, bool isNegated); - -TrigExpr::TrigExpr(const IFunction &inFunc, ArgumentPtr inChild) - : IUnaryExpressionCRTP(inFunc, std::move(inChild)) { -} - -TrigExpr::SimplifyFunctionVector TrigExpr::getFunctionsForPreSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &TrigExpr::oppositeFunctionsSimplify, - &TrigExpr::expandSimplify, - }; - return simplifyFunctions; -} - -TrigExpr::SimplifyFunctionVector TrigExpr::getFunctionsForPostSimplify() const { - static const SimplifyFunctionVector simplifyFunctions = { - &TrigExpr::constSimplify, - &TrigExpr::oppositeFunctionsSimplify, - &TrigExpr::negSimplify, - }; - return simplifyFunctions; -} - -ArgumentPtr TrigExpr::oppositeFunctionsSimplify(const IFunction &func, const ArgumentPtr &rhs) { - if (const auto expr = cast(rhs)) { - if (const auto oppositeFunc = getOppositeFunction(func)) { - if (*expr->getFunction() == *oppositeFunc) { - return expr->getChildren().front(); - } - } - } - - return {}; -} - -ArgumentPtr TrigExpr::expandSimplify(const IFunction &func, const ArgumentPtr &rhs) { - static const NameToSimplifyFunctionMap nameToExpandFunctionMap = { - {Tan{}.toString(), - [](const ArgumentPtr &inRhs) { - return divExpr(sinExpr(inRhs), cosExpr(inRhs)); - }}, - {Cot{}.toString(), - [](const ArgumentPtr &inRhs) { - return divExpr(cosExpr(inRhs), sinExpr(inRhs)); - }}, - {Sec{}.toString(), - [](const ArgumentPtr &inRhs) { - return divExpr(Integer(1).clone(), cosExpr(inRhs)); - }}, - {Csc{}.toString(), - [](const ArgumentPtr &inRhs) { - return divExpr(Integer(1).clone(), sinExpr(inRhs)); - }}, - }; - - if (const auto iter = nameToExpandFunctionMap.find(func.toString()); iter != nameToExpandFunctionMap.end()) { - return iter->second(rhs); - } - - return {}; -} - -ArgumentPtr TrigExpr::negSimplify(const IFunction &func, const ArgumentPtr &rhs) { - static const NameToSimplifyFunctionMap nameToNegFunctionMap = { - {Sin{}.toString(), - [](const ArgumentPtr &inRhs) { - return negExpr(sinExpr(negExpr(inRhs))); - }}, - {Cos{}.toString(), - [](const ArgumentPtr &inRhs) { - return cosExpr(negExpr(inRhs)); - }}, - }; - - if (isNegated(rhs)) { - if (const auto iter = nameToNegFunctionMap.find(func.toString()); iter != nameToNegFunctionMap.end()) { - return iter->second(rhs); - } - } - - return {}; -} - -ArgumentPtr TrigExpr::constSimplify(const IFunction &func, const ArgumentPtr &rhs) { - if (*rhs == Pi{}) { - return TrigTableSimplify(func, 1); - } - - if (*rhs == *negExpr(Pi{})) { - return TrigTableSimplify(func, -1); - } - - const auto rhsExpr = cast(rhs); - if (!rhsExpr || !is(rhsExpr->getFunction())) { - return {}; - } - - const auto rhsChildren = rhsExpr->getChildren(); - if (rhsChildren.size() != 2 || !is(rhsChildren.back())) { - return {}; - } - - const auto rhsChildRat = convert(*rhsChildren.front()); - if (!rhsChildRat) { - return {}; - } - - return TrigTableSimplify(func, *rhsChildRat); -} - -ArgumentPtr TrigExpr::TrigTableSimplify(const IFunction &func, const Rational &rhs) { - static const NameToTrigFunctionMap nameToTrigFunctionMap = { - {Sin{}.toString(), &TrigTableSinSimplify}, - {Cos{}.toString(), &TrigTableCosSimplify}, - }; - - if (const auto iter = nameToTrigFunctionMap.find(func.toString()); iter != nameToTrigFunctionMap.end()) { - const Rational rhsShifted = phaseShiftPeriod(rhs); - return iter->second(rhsShifted); - } - - return {}; -} - -ArgumentPtr TrigExpr::TrigTableSinSimplify(const Rational &rhs) { - static const TrigTable trigTable = { - {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); -} - -ArgumentPtr TrigExpr::TrigTableCosSimplify(const Rational &rhs) { - static const TrigTable trigTable = { - {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); -} - -std::tuple TrigExpr::phaseShiftSin(const Rational &rhs) { - Rational rhsShifted = rhs; - bool isNegated = false; - - if (rhsShifted < 0) { - rhsShifted = -rhsShifted; - isNegated = !isNegated; - } - - if (rhsShifted.numerator() > rhsShifted.denominator()) { - rhsShifted = Rational(rhsShifted.numerator() % rhsShifted.denominator(), rhsShifted.denominator()); - isNegated = !isNegated; - } - - return {rhsShifted, isNegated}; -} - -std::tuple TrigExpr::phaseShiftCos(const Rational &rhs) { - Rational rhsShifted = rhs; - bool isNegated = false; - - if (rhsShifted < 0) { - rhsShifted = -rhsShifted; - } - - if (rhsShifted.numerator() > rhsShifted.denominator()) { - rhsShifted = Rational(rhsShifted.numerator() % rhsShifted.denominator(), rhsShifted.denominator()); - isNegated = !isNegated; - } - - return {rhsShifted, isNegated}; -} - -Rational TrigExpr::phaseShiftPeriod(const Rational &rhs) { - return Rational(rhs.numerator() % (rhs.denominator() * 2), rhs.denominator()); -} - -std::shared_ptr TrigExpr::getOppositeFunction(const IFunction &function) { - static const std::unordered_map> nameToOppositeFunctions = { - {Sin{}.toString(), std::make_shared()}, - {Cos{}.toString(), std::make_shared()}, - {Tan{}.toString(), std::make_shared()}, - {Cot{}.toString(), std::make_shared()}, - {Sec{}.toString(), std::make_shared()}, - {Csc{}.toString(), std::make_shared()}, - }; - return nameToOppositeFunctions.at(function.toString()); -} - -ArgumentPtr findValue(const TrigTable &trigTable, const Rational &key, const bool isNegated) { - if (const auto res = trigTable.find(key); res != trigTable.end()) { - return isNegated ? negExpr(res->second) : res->second; - } - - return {}; -} -} diff --git a/src/fintamath/expressions/unary/TrigExpr.hpp b/src/fintamath/expressions/unary/TrigExpr.hpp deleted file mode 100644 index 6affab39e..000000000 --- a/src/fintamath/expressions/unary/TrigExpr.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/IFunction.hpp" - -namespace fintamath { - -class Rational; - -class TrigExpr final : public IUnaryExpressionCRTP { - FINTAMATH_CLASS_BODY(TrigExpr) - -public: - explicit TrigExpr(const IFunction &inFunc, ArgumentPtr inChild); - -protected: - SimplifyFunctionVector getFunctionsForPreSimplify() const override; - - SimplifyFunctionVector getFunctionsForPostSimplify() const override; - -private: - static ArgumentPtr oppositeFunctionsSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static ArgumentPtr expandSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static ArgumentPtr negSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static ArgumentPtr constSimplify(const IFunction &func, const ArgumentPtr &rhs); - - static ArgumentPtr TrigTableSimplify(const IFunction &func, const Rational &rhs); - - static ArgumentPtr TrigTableSinSimplify(const Rational &rhs); - - static ArgumentPtr TrigTableCosSimplify(const Rational &rhs); - - static std::tuple phaseShiftSin(const Rational &rhs); - - static std::tuple phaseShiftCos(const Rational &rhs); - - static Rational phaseShiftPeriod(const Rational &rhs); - - static std::shared_ptr getOppositeFunction(const IFunction &function); -}; - -} \ No newline at end of file diff --git a/src/fintamath/functions/IFunction.cpp b/src/fintamath/functions/IFunction.cpp deleted file mode 100644 index a85518b1b..000000000 --- a/src/fintamath/functions/IFunction.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "fintamath/functions/IFunction.hpp" - -#include -#include -#include - -#include "fintamath/functions/FunctionArguments.hpp" - -namespace fintamath { - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IFunction) - -void IFunction::validateArgsSize(const ArgumentRefVector &argVect) const { - if (!argVect.empty() && (getArgumentClasses().size() == argVect.size() || isVariadic())) { - return; - } - - std::vector argNameVect(argVect.size()); - - for (const auto i : stdv::iota(0U, argNameVect.size())) { - argNameVect[i] = argVect[i].get().toString(); - } - - throw InvalidInputFunctionException(toString(), argNameVect); -} - -} diff --git a/src/fintamath/functions/IOperator.cpp b/src/fintamath/functions/IOperator.cpp deleted file mode 100644 index 089c96481..000000000 --- a/src/fintamath/functions/IOperator.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "fintamath/functions/IOperator.hpp" - -namespace fintamath { - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IOperator) - -} diff --git a/src/fintamath/functions/arithmetic/Abs.cpp b/src/fintamath/functions/arithmetic/Abs.cpp deleted file mode 100644 index 7168c53b1..000000000 --- a/src/fintamath/functions/arithmetic/Abs.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "fintamath/functions/arithmetic/Abs.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/powers/Sqrt.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RationalFunctions.hpp" -#include "fintamath/numbers/Real.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Abs::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - return multiAbsSimplify(rhs); -} - -std::unique_ptr Abs::multiAbsSimplify(const INumber &rhs) { - static const auto multiAbs = [] { - static MultiMethod(const INumber &)> outMultiAbs; - - outMultiAbs.add([](const Integer &inRhs) { - return abs(inRhs).clone(); - }); - - outMultiAbs.add([](const Rational &inRhs) { - return abs(inRhs).clone(); - }); - - outMultiAbs.add([](const Real &inRhs) { - return abs(inRhs).clone(); - }); - - outMultiAbs.add([](const Complex &inRhs) { - // https://en.wikipedia.org/wiki/Absolute_value#Complex_numbers - const auto sumOfSquares = *(inRhs.real() * inRhs.real()) + *(inRhs.imag() * inRhs.imag()); - return Sqrt{}(*sumOfSquares); - }); - - return outMultiAbs; - }(); - - return multiAbs(rhs); -} - -} diff --git a/src/fintamath/functions/arithmetic/Add.cpp b/src/fintamath/functions/arithmetic/Add.cpp deleted file mode 100644 index 3b67b7c9f..000000000 --- a/src/fintamath/functions/arithmetic/Add.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/arithmetic/Add.hpp" - -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" - -namespace fintamath { - -std::unique_ptr Add::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - return lhs + rhs; -} - -} diff --git a/src/fintamath/functions/arithmetic/Div.cpp b/src/fintamath/functions/arithmetic/Div.cpp deleted file mode 100644 index 781c78901..000000000 --- a/src/fintamath/functions/arithmetic/Div.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "fintamath/functions/arithmetic/Div.hpp" - -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/literals/constants/Undefined.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -std::unique_ptr Div::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - if (lhs == Integer(0) && rhs == Integer(0)) { - return Undefined{}.clone(); - } - - if (rhs == Integer(0)) { - return ComplexInf{}.clone(); - } - - return lhs / rhs; -} - -} diff --git a/src/fintamath/functions/arithmetic/Frac.cpp b/src/fintamath/functions/arithmetic/Frac.cpp deleted file mode 100644 index 5cdaf3512..000000000 --- a/src/fintamath/functions/arithmetic/Frac.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "fintamath/functions/arithmetic/Frac.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" - -namespace fintamath { - -std::unique_ptr Frac::call(const ArgumentRefVector &argVect) const { - return Div{}(argVect); -} - -} diff --git a/src/fintamath/functions/arithmetic/FracMixed.cpp b/src/fintamath/functions/arithmetic/FracMixed.cpp deleted file mode 100644 index cb2b96fff..000000000 --- a/src/fintamath/functions/arithmetic/FracMixed.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "fintamath/functions/arithmetic/FracMixed.hpp" - -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" - -namespace fintamath { - -std::unique_ptr FracMixed::call(const ArgumentRefVector &argVect) const { - const auto &integ = cast(argVect[0].get()); - const auto &numer = cast(argVect[1].get()); - const auto &denom = cast(argVect[2].get()); - - return Add{}(integ, *Div{}(numer, denom)); -} - -} diff --git a/src/fintamath/functions/arithmetic/Mul.cpp b/src/fintamath/functions/arithmetic/Mul.cpp deleted file mode 100644 index 5661abf75..000000000 --- a/src/fintamath/functions/arithmetic/Mul.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/arithmetic/Mul.hpp" - -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" - -namespace fintamath { - -std::unique_ptr Mul::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - return lhs * rhs; -} - -} diff --git a/src/fintamath/functions/arithmetic/Neg.cpp b/src/fintamath/functions/arithmetic/Neg.cpp deleted file mode 100644 index e0fe071f6..000000000 --- a/src/fintamath/functions/arithmetic/Neg.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "fintamath/functions/arithmetic/Neg.hpp" - -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" - -namespace fintamath { - -std::unique_ptr Neg::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - return -rhs; -} - -} diff --git a/src/fintamath/functions/arithmetic/Sign.cpp b/src/fintamath/functions/arithmetic/Sign.cpp deleted file mode 100644 index a72c57bb2..000000000 --- a/src/fintamath/functions/arithmetic/Sign.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "fintamath/functions/arithmetic/Sign.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Abs.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Sign::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - return multiSignSimplify(rhs); -} - -std::unique_ptr Sign::multiSignSimplify(const INumber &rhs) { - static const auto multiSign = [] { - static MultiMethod(const INumber &)> outMultiSign; - - outMultiSign.add([](const Integer &inRhs) { - return Integer(inRhs.sign()).clone(); - }); - - outMultiSign.add([](const Rational &inRhs) { - return Integer(inRhs.sign()).clone(); - }); - - outMultiSign.add([](const Real &inRhs) { - if (inRhs == 0) { - return Integer(1).clone(); - } - - return Integer(inRhs.sign()).clone(); - }); - - outMultiSign.add([](const Complex &inRhs) { - if (inRhs.imag() == Integer(0)) { - return multiSignSimplify(inRhs.real()); - } - - // https://en.wikipedia.org/wiki/Sign_function#Complex_signum - return Div{}(inRhs, *Abs{}(inRhs)); - }); - - return outMultiSign; - }(); - - return multiSign(rhs); -} - -} diff --git a/src/fintamath/functions/arithmetic/Sub.cpp b/src/fintamath/functions/arithmetic/Sub.cpp deleted file mode 100644 index 0130a8f8a..000000000 --- a/src/fintamath/functions/arithmetic/Sub.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/arithmetic/Sub.hpp" - -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" - -namespace fintamath { - -std::unique_ptr Sub::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - return lhs - rhs; -} - -} diff --git a/src/fintamath/functions/arithmetic/UnaryPlus.cpp b/src/fintamath/functions/arithmetic/UnaryPlus.cpp deleted file mode 100644 index 4c5b6171a..000000000 --- a/src/fintamath/functions/arithmetic/UnaryPlus.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "fintamath/functions/arithmetic/UnaryPlus.hpp" - -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" - -namespace fintamath { - -std::unique_ptr UnaryPlus::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - return +rhs; -} - -} diff --git a/src/fintamath/functions/calculus/Derivative.cpp b/src/fintamath/functions/calculus/Derivative.cpp deleted file mode 100644 index fd45423f4..000000000 --- a/src/fintamath/functions/calculus/Derivative.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "fintamath/functions/calculus/Derivative.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Derivative::call(const ArgumentRefVector &argVect) const { - return makeExpr(*this, argVect)->toMinimalObject(); -} - -} diff --git a/src/fintamath/functions/calculus/Integral.cpp b/src/fintamath/functions/calculus/Integral.cpp deleted file mode 100644 index 874a2f1ea..000000000 --- a/src/fintamath/functions/calculus/Integral.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "fintamath/functions/calculus/Integral.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/FunctionUtils.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Integral::call(const ArgumentRefVector &argVect) const { - return makeExpr(*this, argVect)->toMinimalObject(); -} - -} diff --git a/src/fintamath/functions/calculus/Max.cpp b/src/fintamath/functions/calculus/Max.cpp deleted file mode 100644 index 34c83fe7c..000000000 --- a/src/fintamath/functions/calculus/Max.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "fintamath/functions/calculus/Max.hpp" - -#include -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/Complex.hpp" - -namespace fintamath { - -std::unique_ptr Max::call(const ArgumentRefVector &argVect) const { - std::reference_wrapper res = cast(argVect.front().get()); - - for (const auto &arg : argVect | stdv::drop(1)) { - if (is(arg)) { - return {}; - } - - if (const auto &argComp = cast(arg.get()); res < argComp) { - res = argComp; - } - } - - return res.get().clone(); -} - -} diff --git a/src/fintamath/functions/calculus/Min.cpp b/src/fintamath/functions/calculus/Min.cpp deleted file mode 100644 index 6010020b4..000000000 --- a/src/fintamath/functions/calculus/Min.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "fintamath/functions/calculus/Min.hpp" - -#include -#include -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/Complex.hpp" - -namespace fintamath { - -std::unique_ptr Min::call(const ArgumentRefVector &argVect) const { - std::reference_wrapper res = cast(argVect.front().get()); - - for (const auto &arg : argVect | stdv::drop(1)) { - if (is(arg)) { - return {}; - } - - if (const auto &argComp = cast(arg.get()); res > argComp) { - res = argComp; - } - } - - return res.get().clone(); -} - -} diff --git a/src/fintamath/functions/comparison/Eqv.cpp b/src/fintamath/functions/comparison/Eqv.cpp deleted file mode 100644 index c41122318..000000000 --- a/src/fintamath/functions/comparison/Eqv.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "fintamath/functions/comparison/Eqv.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" - -namespace fintamath { - -std::unique_ptr Eqv::call(const ArgumentRefVector &argVect) const { - const auto &lhs = argVect.front().get(); - const auto &rhs = argVect.back().get(); - - return Boolean(lhs == rhs).clone(); -} - -} diff --git a/src/fintamath/functions/comparison/Less.cpp b/src/fintamath/functions/comparison/Less.cpp deleted file mode 100644 index 9c5db1334..000000000 --- a/src/fintamath/functions/comparison/Less.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "fintamath/functions/comparison/Less.hpp" - -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/Complex.hpp" - -namespace fintamath { - -std::unique_ptr Less::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - if (is(lhs) || is(rhs)) { - return {}; - } - - return Boolean(lhs < rhs).clone(); -} - -} diff --git a/src/fintamath/functions/comparison/LessEqv.cpp b/src/fintamath/functions/comparison/LessEqv.cpp deleted file mode 100644 index 70eef74ba..000000000 --- a/src/fintamath/functions/comparison/LessEqv.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "fintamath/functions/comparison/LessEqv.hpp" - -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/Complex.hpp" - -namespace fintamath { - -std::unique_ptr LessEqv::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - if (is(lhs) || is(rhs)) { - return {}; - } - - return Boolean(lhs <= rhs).clone(); -} - -} diff --git a/src/fintamath/functions/comparison/More.cpp b/src/fintamath/functions/comparison/More.cpp deleted file mode 100644 index be3171bdc..000000000 --- a/src/fintamath/functions/comparison/More.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "fintamath/functions/comparison/More.hpp" - -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/Complex.hpp" - -namespace fintamath { - -std::unique_ptr More::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - if (is(lhs) || is(rhs)) { - return {}; - } - - return Boolean(lhs > rhs).clone(); -} - -} diff --git a/src/fintamath/functions/comparison/MoreEqv.cpp b/src/fintamath/functions/comparison/MoreEqv.cpp deleted file mode 100644 index f10d24663..000000000 --- a/src/fintamath/functions/comparison/MoreEqv.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "fintamath/functions/comparison/MoreEqv.hpp" - -#include - -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/Complex.hpp" - -namespace fintamath { - -std::unique_ptr MoreEqv::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - if (is(lhs) || is(rhs)) { - return {}; - } - - return Boolean(lhs >= rhs).clone(); -} - -} diff --git a/src/fintamath/functions/comparison/Neqv.cpp b/src/fintamath/functions/comparison/Neqv.cpp deleted file mode 100644 index fe9b9b83e..000000000 --- a/src/fintamath/functions/comparison/Neqv.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "fintamath/functions/comparison/Neqv.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" - -namespace fintamath { - -std::unique_ptr Neqv::call(const ArgumentRefVector &argVect) const { - const auto &lhs = argVect.front().get(); - const auto &rhs = argVect.back().get(); - - return Boolean(lhs != rhs).clone(); -} - -} diff --git a/src/fintamath/functions/hyperbolic/Acosh.cpp b/src/fintamath/functions/hyperbolic/Acosh.cpp deleted file mode 100644 index 52d5f6df6..000000000 --- a/src/fintamath/functions/hyperbolic/Acosh.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "fintamath/functions/hyperbolic/Acosh.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/literals/constants/I.hpp" -#include "fintamath/literals/constants/Pi.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Acosh::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(-1)) { - static const auto res = mulExpr(I{}, Pi{})->toMinimalObject(); - return res->clone(); - } - - if (rhs == Integer(0)) { - static const auto res = divExpr(mulExpr(I{}, Pi{}), Integer(2).clone())->toMinimalObject(); - return res->clone(); - } - - if (rhs == Integer(1)) { - return Integer(0).clone(); - } - - return multiAcoshSimplify(rhs); -} - -std::unique_ptr Acosh::multiAcoshSimplify(const INumber &rhs) { - static const auto multiAcosh = [] { - static MultiMethod(const INumber &)> outMultiAcosh; - - outMultiAcosh.add([](const Integer &inRhs) { - return multiAcoshSimplify(Real(inRhs)); - }); - - outMultiAcosh.add([](const Rational &inRhs) { - return multiAcoshSimplify(Real(inRhs)); - }); - - outMultiAcosh.add([](const Real &inRhs) { - return acosh(inRhs).clone(); - }); - - return outMultiAcosh; - }(); - - return multiAcosh(rhs); -} - -} diff --git a/src/fintamath/functions/hyperbolic/Acoth.cpp b/src/fintamath/functions/hyperbolic/Acoth.cpp deleted file mode 100644 index a551a1ea9..000000000 --- a/src/fintamath/functions/hyperbolic/Acoth.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "fintamath/functions/hyperbolic/Acoth.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/literals/constants/I.hpp" -#include "fintamath/literals/constants/Inf.hpp" -#include "fintamath/literals/constants/NegInf.hpp" -#include "fintamath/literals/constants/Pi.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Acoth::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(-1)) { - return NegInf{}.clone(); - } - - if (rhs == Integer(0)) { - static const auto res = divExpr(mulExpr(I{}, Pi{}), Integer(2).clone())->toMinimalObject(); - return res->clone(); - } - - if (rhs == Integer(1)) { - return Inf{}.clone(); - } - - return multiAcothSimplify(rhs); -} - -std::unique_ptr Acoth::multiAcothSimplify(const INumber &rhs) { - static const auto multiAcoth = [] { - static MultiMethod(const INumber &)> outMultiAcoth; - - outMultiAcoth.add([](const Integer &inRhs) { - return multiAcothSimplify(Real(inRhs)); - }); - - outMultiAcoth.add([](const Rational &inRhs) { - return multiAcothSimplify(Real(inRhs)); - }); - - outMultiAcoth.add([](const Real &inRhs) { - return acoth(inRhs).clone(); - }); - - return outMultiAcoth; - }(); - - return multiAcoth(rhs); -} - -} diff --git a/src/fintamath/functions/hyperbolic/Acsch.cpp b/src/fintamath/functions/hyperbolic/Acsch.cpp deleted file mode 100644 index b65e43e0c..000000000 --- a/src/fintamath/functions/hyperbolic/Acsch.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "fintamath/functions/hyperbolic/Acsch.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Acsch::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return ComplexInf{}.clone(); - } - - return multiAcschSimplify(rhs); -} - -std::unique_ptr Acsch::multiAcschSimplify(const INumber &rhs) { - static const auto multiAcsch = [] { - static MultiMethod(const INumber &)> outMultiAcsch; - - outMultiAcsch.add([](const Integer &inRhs) { - return multiAcschSimplify(Real(inRhs)); - }); - - outMultiAcsch.add([](const Rational &inRhs) { - return multiAcschSimplify(Real(inRhs)); - }); - - outMultiAcsch.add([](const Real &inRhs) { - return acsch(inRhs).clone(); - }); - - return outMultiAcsch; - }(); - - return multiAcsch(rhs); -} - -} diff --git a/src/fintamath/functions/hyperbolic/Asech.cpp b/src/fintamath/functions/hyperbolic/Asech.cpp deleted file mode 100644 index 48f450a88..000000000 --- a/src/fintamath/functions/hyperbolic/Asech.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "fintamath/functions/hyperbolic/Asech.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/literals/constants/I.hpp" -#include "fintamath/literals/constants/Inf.hpp" -#include "fintamath/literals/constants/Pi.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Asech::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(-1)) { - static const auto res = mulExpr(I{}, Pi{})->toMinimalObject(); - return res->clone(); - } - - if (rhs == Integer(0)) { - return Inf{}.clone(); - } - - if (rhs == Integer(1)) { - return Integer(0).clone(); - } - - return multiAsechSimplify(rhs); -} - -std::unique_ptr Asech::multiAsechSimplify(const INumber &rhs) { - static const auto multiAsech = [] { - static MultiMethod(const INumber &)> outMultiAsech; - - outMultiAsech.add([](const Integer &inRhs) { - return multiAsechSimplify(Real(inRhs)); - }); - - outMultiAsech.add([](const Rational &inRhs) { - return multiAsechSimplify(Real(inRhs)); - }); - - outMultiAsech.add([](const Real &inRhs) { - return asech(inRhs).clone(); - }); - - return outMultiAsech; - }(); - - return multiAsech(rhs); -} - -} diff --git a/src/fintamath/functions/hyperbolic/Asinh.cpp b/src/fintamath/functions/hyperbolic/Asinh.cpp deleted file mode 100644 index f39405772..000000000 --- a/src/fintamath/functions/hyperbolic/Asinh.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "fintamath/functions/hyperbolic/Asinh.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Asinh::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return rhs.clone(); - } - - return multiAsinhSimplify(rhs); -} - -std::unique_ptr Asinh::multiAsinhSimplify(const INumber &rhs) { - static const auto multiAsinh = [] { - static MultiMethod(const INumber &)> outMultiAsinh; - - outMultiAsinh.add([](const Integer &inRhs) { - return multiAsinhSimplify(Real(inRhs)); - }); - - outMultiAsinh.add([](const Rational &inRhs) { - return multiAsinhSimplify(Real(inRhs)); - }); - - outMultiAsinh.add([](const Real &inRhs) { - return asinh(inRhs).clone(); - }); - - return outMultiAsinh; - }(); - - return multiAsinh(rhs); -} - -} diff --git a/src/fintamath/functions/hyperbolic/Atanh.cpp b/src/fintamath/functions/hyperbolic/Atanh.cpp deleted file mode 100644 index 6736b4231..000000000 --- a/src/fintamath/functions/hyperbolic/Atanh.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "fintamath/functions/hyperbolic/Atanh.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/constants/Inf.hpp" -#include "fintamath/literals/constants/NegInf.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Atanh::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(-1)) { - return NegInf{}.clone(); - } - - if (rhs == Integer(0)) { - return rhs.clone(); - } - - if (rhs == Integer(1)) { - return Inf{}.clone(); - } - - return multiAtanhSimplify(rhs); -} - -std::unique_ptr Atanh::multiAtanhSimplify(const INumber &rhs) { - static const auto multiAtanh = [] { - static MultiMethod(const INumber &)> outMultiAtanh; - - outMultiAtanh.add([](const Integer &inRhs) { - return multiAtanhSimplify(Real(inRhs)); - }); - - outMultiAtanh.add([](const Rational &inRhs) { - return multiAtanhSimplify(Real(inRhs)); - }); - - outMultiAtanh.add([](const Real &inRhs) { - return atanh(inRhs).clone(); - }); - - return outMultiAtanh; - }(); - - return multiAtanh(rhs); -} - -} diff --git a/src/fintamath/functions/hyperbolic/Cosh.cpp b/src/fintamath/functions/hyperbolic/Cosh.cpp deleted file mode 100644 index 80c7eaa49..000000000 --- a/src/fintamath/functions/hyperbolic/Cosh.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "fintamath/functions/hyperbolic/Cosh.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Cosh::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return Integer(1).clone(); - } - - return multiCoshSimplify(rhs); -} - -std::unique_ptr Cosh::multiCoshSimplify(const INumber &rhs) { - static const auto multiCosh = [] { - static MultiMethod(const INumber &)> outMultiCosh; - - outMultiCosh.add([](const Integer &inRhs) { - return multiCoshSimplify(Real(inRhs)); - }); - - outMultiCosh.add([](const Rational &inRhs) { - return multiCoshSimplify(Real(inRhs)); - }); - - outMultiCosh.add([](const Real &inRhs) { - return cosh(inRhs).clone(); - }); - - return outMultiCosh; - }(); - - return multiCosh(rhs); -} - -} diff --git a/src/fintamath/functions/hyperbolic/Coth.cpp b/src/fintamath/functions/hyperbolic/Coth.cpp deleted file mode 100644 index a8cbd13d1..000000000 --- a/src/fintamath/functions/hyperbolic/Coth.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "fintamath/functions/hyperbolic/Coth.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Coth::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return ComplexInf{}.clone(); - } - - return multiCothSimplify(rhs); -} - -std::unique_ptr Coth::multiCothSimplify(const INumber &rhs) { - static const auto multiCoth = [] { - static MultiMethod(const INumber &)> outMultiCoth; - - outMultiCoth.add([](const Integer &inRhs) { - return multiCothSimplify(Real(inRhs)); - }); - - outMultiCoth.add([](const Rational &inRhs) { - return multiCothSimplify(Real(inRhs)); - }); - - outMultiCoth.add([](const Real &inRhs) { - return coth(inRhs).clone(); - }); - - return outMultiCoth; - }(); - - return multiCoth(rhs); -} - -} diff --git a/src/fintamath/functions/hyperbolic/Csch.cpp b/src/fintamath/functions/hyperbolic/Csch.cpp deleted file mode 100644 index c79cdcff2..000000000 --- a/src/fintamath/functions/hyperbolic/Csch.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "fintamath/functions/hyperbolic/Csch.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Csch::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return ComplexInf{}.clone(); - } - - return multiCschSimplify(rhs); -} - -std::unique_ptr Csch::multiCschSimplify(const INumber &rhs) { - static const auto multiCsch = [] { - static MultiMethod(const INumber &)> outMultiCsch; - - outMultiCsch.add([](const Integer &inRhs) { - return multiCschSimplify(Real(inRhs)); - }); - - outMultiCsch.add([](const Rational &inRhs) { - return multiCschSimplify(Real(inRhs)); - }); - - outMultiCsch.add([](const Real &inRhs) { - return csch(inRhs).clone(); - }); - - return outMultiCsch; - }(); - - return multiCsch(rhs); -} - -} diff --git a/src/fintamath/functions/hyperbolic/Sech.cpp b/src/fintamath/functions/hyperbolic/Sech.cpp deleted file mode 100644 index cb28608ef..000000000 --- a/src/fintamath/functions/hyperbolic/Sech.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "fintamath/functions/hyperbolic/Sech.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Sech::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return Integer(1).clone(); - } - - return multiSechSimplify(rhs); -} - -std::unique_ptr Sech::multiSechSimplify(const INumber &rhs) { - static const auto multiSech = [] { - static MultiMethod(const INumber &)> outMultiSech; - - outMultiSech.add([](const Integer &inRhs) { - return multiSechSimplify(Real(inRhs)); - }); - - outMultiSech.add([](const Rational &inRhs) { - return multiSechSimplify(Real(inRhs)); - }); - - outMultiSech.add([](const Real &inRhs) { - return sech(inRhs).clone(); - }); - - return outMultiSech; - }(); - - return multiSech(rhs); -} - -} diff --git a/src/fintamath/functions/hyperbolic/Sinh.cpp b/src/fintamath/functions/hyperbolic/Sinh.cpp deleted file mode 100644 index e4305e38c..000000000 --- a/src/fintamath/functions/hyperbolic/Sinh.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "fintamath/functions/hyperbolic/Sinh.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Sinh::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return rhs.clone(); - } - - return multiSinhSimplify(rhs); -} - -std::unique_ptr Sinh::multiSinhSimplify(const INumber &rhs) { - static const auto multiSinh = [] { - static MultiMethod(const INumber &)> outMultiSinh; - - outMultiSinh.add([](const Integer &inRhs) { - return multiSinhSimplify(Real(inRhs)); - }); - - outMultiSinh.add([](const Rational &inRhs) { - return multiSinhSimplify(Real(inRhs)); - }); - - outMultiSinh.add([](const Real &inRhs) { - return sinh(inRhs).clone(); - }); - - return outMultiSinh; - }(); - - return multiSinh(rhs); -} - -} diff --git a/src/fintamath/functions/hyperbolic/Tanh.cpp b/src/fintamath/functions/hyperbolic/Tanh.cpp deleted file mode 100644 index 2b96695e9..000000000 --- a/src/fintamath/functions/hyperbolic/Tanh.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "fintamath/functions/hyperbolic/Tanh.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Tanh::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return rhs.clone(); - } - - return multiTanhSimplify(rhs); -} - -std::unique_ptr Tanh::multiTanhSimplify(const INumber &rhs) { - static const auto multiTanh = [] { - static MultiMethod(const INumber &)> outMultiTanh; - - outMultiTanh.add([](const Integer &inRhs) { - return multiTanhSimplify(Real(inRhs)); - }); - - outMultiTanh.add([](const Rational &inRhs) { - return multiTanhSimplify(Real(inRhs)); - }); - - outMultiTanh.add([](const Real &inRhs) { - return tanh(inRhs).clone(); - }); - - return outMultiTanh; - }(); - - return multiTanh(rhs); -} - -} diff --git a/src/fintamath/functions/logarithms/Lb.cpp b/src/fintamath/functions/logarithms/Lb.cpp deleted file mode 100644 index 41012862b..000000000 --- a/src/fintamath/functions/logarithms/Lb.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/logarithms/Lb.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/logarithms/Log.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -std::unique_ptr Lb::call(const ArgumentRefVector &argVect) const { - static const Integer lhs = 2; - const auto &rhs = argVect.front().get(); - - return Log{}(lhs, rhs); -} - -} diff --git a/src/fintamath/functions/logarithms/Lg.cpp b/src/fintamath/functions/logarithms/Lg.cpp deleted file mode 100644 index 69becfed4..000000000 --- a/src/fintamath/functions/logarithms/Lg.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/logarithms/Lg.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/logarithms/Log.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -std::unique_ptr Lg::call(const ArgumentRefVector &argVect) const { - static const Integer lhs = 10; - const auto &rhs = argVect.front().get(); - - return Log{}(lhs, rhs); -} - -} diff --git a/src/fintamath/functions/logarithms/Ln.cpp b/src/fintamath/functions/logarithms/Ln.cpp deleted file mode 100644 index fff09c50d..000000000 --- a/src/fintamath/functions/logarithms/Ln.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "fintamath/functions/logarithms/Ln.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/constants/NegInf.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Ln::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return NegInf{}.clone(); - } - - if (rhs == Integer(1)) { - return Integer(0).clone(); - } - - return multiLnSimplify(rhs); -} - -std::unique_ptr Ln::multiLnSimplify(const INumber &rhs) { - static const auto multiLn = [] { - static MultiMethod(const INumber &)> outMultiLn; - - outMultiLn.add([](const Integer &inRhs) { - return multiLnSimplify(Real(inRhs)); - }); - - outMultiLn.add([](const Rational &inRhs) { - return multiLnSimplify(Real(inRhs)); - }); - - outMultiLn.add([](const Real &inRhs) { - return ln(inRhs).clone(); - }); - - return outMultiLn; - }(); - - return multiLn(rhs); -} - -} diff --git a/src/fintamath/functions/logarithms/Log.cpp b/src/fintamath/functions/logarithms/Log.cpp deleted file mode 100644 index 70fdfcada..000000000 --- a/src/fintamath/functions/logarithms/Log.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "fintamath/functions/logarithms/Log.hpp" - -#include -#include - -#include "fintamath/core/Converter.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Neg.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/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Log::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - if (lhs == Integer(1)) { - if (rhs == Integer(1)) { - return Undefined{}.clone(); - } - - return ComplexInf{}.clone(); - } - - if (lhs == Integer(0)) { - if (rhs == Integer(0)) { - return Undefined{}.clone(); - } - - return Integer(0).clone(); - } - - if (rhs == Integer(0)) { - if (lhs > Integer(1)) { - return NegInf{}.clone(); - } - - return Inf{}.clone(); - } - - if (rhs == Integer(1)) { - return Integer(0).clone(); - } - - if (lhs == rhs && lhs.isPrecise()) { - return Integer(1).clone(); - } - - if (lhs < Integer(0) || rhs < Integer(0)) { - // TODO: complex log - return {}; - } - - if (lhs < Integer(1)) { - auto newLhs = Rational(1) / lhs; - - if (rhs < Integer(1)) { - auto newRhs = Rational(1) / rhs; - return multiLogSimplify(*newLhs, *newRhs); - } - - if (auto res = multiLogSimplify(*newLhs, rhs)) { - return negExpr(std::move(res))->toMinimalObject(); - } - } - - if (rhs < Integer(1)) { - auto newRhs = Rational(1) / rhs; - if (auto res = multiLogSimplify(lhs, *newRhs)) { - return negExpr(std::move(res))->toMinimalObject(); - } - } - - return multiLogSimplify(lhs, rhs); -} - -std::unique_ptr Log::multiLogSimplify(const INumber &lhs, const INumber &rhs) { - static const auto multiLog = [] { - static MultiMethod(const INumber &, const INumber &)> outMultiPow; - - outMultiPow.add([](const Integer &inLhs, const Integer &inRhs) { - return logSimplify(inLhs, inRhs); - }); - - outMultiPow.add([](const Rational &inLhs, const Rational &inRhs) { - return logSimplify(inLhs, inRhs); - }); - - outMultiPow.add([](const Real &inLhs, const Real &inRhs) { - return logSimplify(inLhs, inRhs); - }); - - return outMultiPow; - }(); - - if (const auto rhsConv = convert(lhs, rhs)) { - return multiLog(lhs, *rhsConv); - } - - const auto lhsConv = convert(rhs, lhs); - return multiLog(*lhsConv, rhs); -} - -std::unique_ptr Log::logSimplify(const Integer &lhs, const Integer &rhs) { - return logSimplify(Rational(lhs), Rational(rhs)); -} - -std::unique_ptr Log::logSimplify(const Rational &lhs, const Rational &rhs) { - const bool isResInverted = lhs > rhs; - const Rational divider = isResInverted ? rhs : lhs; - Rational remainder = isResInverted ? lhs : rhs; - Rational res = 0; - - while (remainder > divider) { - res += 1; - remainder /= divider; - } - - if (remainder == divider) { - res += 1; - - if (isResInverted) { - return (Rational(1) / res).toMinimalObject(); - } - - return res.toMinimalObject(); - } - - return logSimplify(Real(lhs), Real(rhs)); -} - -std::unique_ptr Log::logSimplify(const Real &lhs, const Real &rhs) { - return log(lhs, rhs).clone(); -} - -} diff --git a/src/fintamath/functions/logic/And.cpp b/src/fintamath/functions/logic/And.cpp deleted file mode 100644 index ea06c8073..000000000 --- a/src/fintamath/functions/logic/And.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/logic/And.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -std::unique_ptr And::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - return Boolean(lhs && rhs).clone(); -} - -} diff --git a/src/fintamath/functions/logic/Equiv.cpp b/src/fintamath/functions/logic/Equiv.cpp deleted file mode 100644 index b2fdda2f5..000000000 --- a/src/fintamath/functions/logic/Equiv.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/logic/Equiv.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -std::unique_ptr Equiv::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - return Boolean(lhs == rhs).clone(); -} - -} diff --git a/src/fintamath/functions/logic/Impl.cpp b/src/fintamath/functions/logic/Impl.cpp deleted file mode 100644 index b17544217..000000000 --- a/src/fintamath/functions/logic/Impl.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/logic/Impl.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -std::unique_ptr Impl::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - return Boolean(!lhs || rhs).clone(); -} - -} diff --git a/src/fintamath/functions/logic/Nequiv.cpp b/src/fintamath/functions/logic/Nequiv.cpp deleted file mode 100644 index 4fbf419a1..000000000 --- a/src/fintamath/functions/logic/Nequiv.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/logic/Nequiv.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -std::unique_ptr Nequiv::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - return Boolean(lhs != rhs).clone(); -} - -} diff --git a/src/fintamath/functions/logic/Not.cpp b/src/fintamath/functions/logic/Not.cpp deleted file mode 100644 index b60dd2aae..000000000 --- a/src/fintamath/functions/logic/Not.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "fintamath/functions/logic/Not.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -std::unique_ptr Not::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - return Boolean(!rhs).clone(); -} - -} diff --git a/src/fintamath/functions/logic/Or.cpp b/src/fintamath/functions/logic/Or.cpp deleted file mode 100644 index d460896a1..000000000 --- a/src/fintamath/functions/logic/Or.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/logic/Or.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/Boolean.hpp" - -namespace fintamath { - -std::unique_ptr Or::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - return Boolean(lhs || rhs).clone(); -} - -} diff --git a/src/fintamath/functions/ntheory/Ceil.cpp b/src/fintamath/functions/ntheory/Ceil.cpp deleted file mode 100644 index 10633dc20..000000000 --- a/src/fintamath/functions/ntheory/Ceil.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "fintamath/functions/ntheory/Ceil.hpp" - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RationalFunctions.hpp" -#include "fintamath/numbers/Real.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Ceil::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - return multiCeilSimplify(rhs); -} - -std::unique_ptr Ceil::multiCeilSimplify(const INumber &rhs) { - static const auto multiCeil = [] { - static MultiMethod(const INumber &)> outMultiCeil; - - outMultiCeil.add([](const Integer &inRhs) { - return inRhs.clone(); - }); - - outMultiCeil.add([](const Rational &inRhs) { - return ceil(inRhs).clone(); - }); - - outMultiCeil.add([](const Real &inRhs) { - Integer res = ceil(inRhs); - - if (abs(inRhs) == Real(abs(res))) { - return std::unique_ptr{}; - } - - return std::move(res).clone(); - }); - - outMultiCeil.add([](const Complex &inRhs) { - const auto re = cast(multiCeilSimplify(inRhs.real())); - const auto im = cast(multiCeilSimplify(inRhs.imag())); - - if (!re || !im) { - return std::unique_ptr{}; - } - - return Complex(*re, *im).toMinimalObject(); - }); - - return outMultiCeil; - }(); - - return multiCeil(rhs); -} - -} diff --git a/src/fintamath/functions/ntheory/Floor.cpp b/src/fintamath/functions/ntheory/Floor.cpp deleted file mode 100644 index 0262251fe..000000000 --- a/src/fintamath/functions/ntheory/Floor.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "fintamath/functions/ntheory/Floor.hpp" - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RationalFunctions.hpp" -#include "fintamath/numbers/Real.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Floor::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - return multiFloorSimplify(rhs); -} - -std::unique_ptr Floor::multiFloorSimplify(const INumber &rhs) { - static const auto multiFloor = [] { - static MultiMethod(const INumber &)> outMultiFloor; - - outMultiFloor.add([](const Integer &inRhs) { - return inRhs.clone(); - }); - - outMultiFloor.add([](const Rational &inRhs) { - return floor(inRhs).clone(); - }); - - outMultiFloor.add([](const Real &inRhs) { - Integer res = floor(inRhs); - - if (abs(inRhs) == Real(abs(res))) { - return std::unique_ptr{}; - } - - return std::move(res).clone(); - }); - - outMultiFloor.add([](const Complex &inRhs) { - const auto re = cast(multiFloorSimplify(inRhs.real())); - const auto im = cast(multiFloorSimplify(inRhs.imag())); - - if (!re || !im) { - return std::unique_ptr{}; - } - - return Complex(*re, *im).toMinimalObject(); - }); - - return outMultiFloor; - }(); - - return multiFloor(rhs); -} - -} diff --git a/src/fintamath/functions/ntheory/Mod.cpp b/src/fintamath/functions/ntheory/Mod.cpp deleted file mode 100644 index a7fe4b7fe..000000000 --- a/src/fintamath/functions/ntheory/Mod.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "fintamath/functions/ntheory/Mod.hpp" - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/constants/Undefined.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Mod::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - if (rhs == Integer(0)) { - return Undefined{}.clone(); - } - - return multiModSimplify(lhs, rhs); -} - -std::unique_ptr Mod::multiModSimplify(const INumber &lhs, const INumber &rhs) { - // TODO: implement non-integer modulo - - static const auto multiMod = [] { - static MultiMethod(const INumber &, const INumber &)> outMultiMod; - - outMultiMod.add([](const Integer &inLhs, const Integer &inRhs) { - Integer mod = inLhs % inRhs; - - if (mod != 0 && inLhs.sign() != inRhs.sign()) { - mod += inRhs; - } - - return std::move(mod).clone(); - }); - - return outMultiMod; - }(); - - return multiMod(lhs, rhs); -} - -} diff --git a/src/fintamath/functions/other/Comma.cpp b/src/fintamath/functions/other/Comma.cpp deleted file mode 100644 index e4f08173b..000000000 --- a/src/fintamath/functions/other/Comma.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "fintamath/functions/other/Comma.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" - -namespace fintamath { - -std::unique_ptr Comma::call(const ArgumentRefVector &argVect) const { - const auto &lhs = argVect.front().get(); - const auto &rhs = argVect.back().get(); - - throw InvalidInputBinaryOperatorException(toString(), lhs.toString(), rhs.toString()); -} - -} diff --git a/src/fintamath/functions/other/Deg.cpp b/src/fintamath/functions/other/Deg.cpp deleted file mode 100644 index 941ed3d29..000000000 --- a/src/fintamath/functions/other/Deg.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "fintamath/functions/other/Deg.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/literals/constants/Pi.hpp" - -namespace fintamath { - -std::unique_ptr Deg::call(const ArgumentRefVector &argVect) const { - static const ArgumentPtr degVal = divExpr(Pi{}, Integer(180)); - const auto &rhs = argVect.front().get(); - - return mulExpr(rhs, *degVal)->toMinimalObject(); -} - -} diff --git a/src/fintamath/functions/other/Factorial.cpp b/src/fintamath/functions/other/Factorial.cpp deleted file mode 100644 index dcd6e06db..000000000 --- a/src/fintamath/functions/other/Factorial.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "fintamath/functions/other/Factorial.hpp" - -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Factorial::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - return multiFactorialSimplify(rhs, order); -} - -std::unique_ptr Factorial::multiFactorialSimplify(const INumber &lhs, const size_t order) { - static const auto multiFactorial = [] { - static MultiMethod(const INumber &, const Integer &)> outMultiAbs; - - outMultiAbs.add([](const Integer &inRhs, const Integer &inOrder) { - return factorialSimplify(inRhs, static_cast(inOrder)); - }); - - outMultiAbs.add([](const Rational &inRhs, const Integer &inOrder) { - return factorialSimplify(inRhs, static_cast(inOrder)); - }); - - outMultiAbs.add([](const Real &inRhs, const Integer &inOrder) { - return factorialSimplify(inRhs, static_cast(inOrder)); - }); - - return outMultiAbs; - }(); - - return multiFactorial(lhs, Integer(order)); -} - -std::unique_ptr Factorial::factorialSimplify(const Integer &rhs, const size_t order) { - if (rhs < 0) { - if (order != 1) { - return {}; - } - - return ComplexInf{}.clone(); - } - - return factorial(rhs, order).clone(); -} - -std::unique_ptr Factorial::factorialSimplify(const Rational &rhs, const size_t order) { - if (rhs.denominator() == 1) { - return factorialSimplify(rhs.numerator(), order); - } - - if (order != 1) { - return {}; - } - - return factorialSimplify(Real(rhs), order); -} - -std::unique_ptr Factorial::factorialSimplify(const Real &rhs, const size_t order) { - if (order != 1) { - return {}; - } - - return tgamma(rhs + 1).clone(); -} - -} diff --git a/src/fintamath/functions/other/Index.cpp b/src/fintamath/functions/other/Index.cpp deleted file mode 100644 index eddb24652..000000000 --- a/src/fintamath/functions/other/Index.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "fintamath/functions/other/Index.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -std::unique_ptr Index::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - return Variable(lhs.toString(), rhs).clone(); -} - -} diff --git a/src/fintamath/functions/other/Percent.cpp b/src/fintamath/functions/other/Percent.cpp deleted file mode 100644 index c2c865b09..000000000 --- a/src/fintamath/functions/other/Percent.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "fintamath/functions/other/Percent.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Rational.hpp" - -namespace fintamath { - -std::unique_ptr Percent::call(const ArgumentRefVector &argVect) const { - static const Rational percentVal = 100; - const auto &rhs = cast(argVect.front().get()); - - return (rhs / percentVal)->toMinimalObject(); -} - -} diff --git a/src/fintamath/functions/powers/Exp.cpp b/src/fintamath/functions/powers/Exp.cpp deleted file mode 100644 index ae09ccde1..000000000 --- a/src/fintamath/functions/powers/Exp.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/powers/Exp.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/literals/constants/E.hpp" - -namespace fintamath { - -std::unique_ptr Exp::call(const ArgumentRefVector &argVect) const { - static const E lhs; - const auto &rhs = argVect.front().get(); - - return Pow{}(lhs, rhs); -} - -} diff --git a/src/fintamath/functions/powers/Pow.cpp b/src/fintamath/functions/powers/Pow.cpp deleted file mode 100644 index d037e6e92..000000000 --- a/src/fintamath/functions/powers/Pow.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include "fintamath/functions/powers/Pow.hpp" - -#include - -#include "fintamath/core/Converter.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/powers/Root.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/literals/constants/Undefined.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Pow::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - if (lhs == Integer(0) && rhs == Integer(0)) { - return Undefined{}.clone(); - } - - if (rhs == Integer(0)) { - return Integer(1).clone(); - } - - if (rhs < Integer(0)) { - if (lhs == Integer(0)) { - return ComplexInf{}.clone(); - } - - return multiPowSimplify(*(Rational(1) / lhs), *(-rhs)); - } - - if (lhs == Integer(0) || lhs == Integer(1) || rhs == Integer(1)) { - return lhs.clone(); - } - - return multiPowSimplify(lhs, rhs); -} - -std::unique_ptr Pow::multiPowSimplify(const INumber &lhs, const INumber &rhs) { - static const auto multiPow = [] { - static MultiMethod(const INumber &, const INumber &)> outMultiPow; - - outMultiPow.add([](const Integer &inLhs, const Integer &inRhs) { - return powSimplify(inLhs, inRhs); - }); - - outMultiPow.add([](const Rational &inLhs, const Rational &inRhs) { - return powSimplify(inLhs, inRhs); - }); - - outMultiPow.add([](const Real &inLhs, const Real &inRhs) { - return powSimplify(inLhs, inRhs); - }); - - outMultiPow.add([](const Complex &inLhs, const Complex &inRhs) { - return powSimplify(inLhs, inRhs); - }); - - return outMultiPow; - }(); - - if (const auto rhsConv = convert(lhs, rhs)) { - return multiPow(lhs, *rhsConv); - } - - const auto lhsConv = convert(rhs, lhs); - return multiPow(*lhsConv, rhs); -} - -std::unique_ptr Pow::powSimplify(const Integer &lhs, const Integer &rhs) { - return pow(lhs, rhs).clone(); -} - -std::unique_ptr Pow::powSimplify(const Rational &lhs, const Rational &rhs) { - const Integer &lhsNumerator = lhs.numerator(); - const Integer &lhsDenominator = lhs.denominator(); - - const Integer &rhsNumerator = rhs.numerator(); - const Integer &rhsDenominator = rhs.denominator(); - - if (rhsDenominator == 1) { - if (lhsDenominator == 1) { - return pow(lhsNumerator, rhsNumerator).toMinimalObject(); - } - - return pow(lhs, rhsNumerator).toMinimalObject(); - } - - // TODO: complex nth roots - if (lhs < Integer(0) && - (rhsNumerator != Integer(1) || rhsDenominator != Integer(2))) { - - return {}; - } - - if (lhsDenominator == 1) { - return Root{}(*multiPowSimplify(lhsNumerator, rhsNumerator), rhsDenominator); - } - - return Root{}(*multiPowSimplify(lhs, rhsNumerator), rhsDenominator); -} - -std::unique_ptr Pow::powSimplify(const Real &lhs, const Real &rhs) { - return pow(lhs, rhs).clone(); -} - -std::unique_ptr Pow::powSimplify(const Complex &lhs, const Complex &rhs) { - if (rhs.imag() == Integer(0)) { - if (const auto *rhsInt = cast(&rhs.real())) { - return pow(lhs, *rhsInt).toMinimalObject(); - } - } - - return {}; -} - -} diff --git a/src/fintamath/functions/powers/PowFunction.cpp b/src/fintamath/functions/powers/PowFunction.cpp deleted file mode 100644 index 2cb0dd7dc..000000000 --- a/src/fintamath/functions/powers/PowFunction.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "fintamath/functions/powers/PowFunction.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/powers/Pow.hpp" - -namespace fintamath { - -std::unique_ptr PowFunction::call(const ArgumentRefVector &argVect) const { - return Pow{}(argVect); -} - -} diff --git a/src/fintamath/functions/powers/Root.cpp b/src/fintamath/functions/powers/Root.cpp deleted file mode 100644 index 6469d4d8e..000000000 --- a/src/fintamath/functions/powers/Root.cpp +++ /dev/null @@ -1,234 +0,0 @@ -#include "fintamath/functions/powers/Root.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/literals/constants/I.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Root::call(const ArgumentRefVector &argVect) const { - const auto &lhs = cast(argVect.front().get()); - const auto &rhs = cast(argVect.back().get()); - - if (lhs == Integer(0) || - rhs == Integer(0) || - lhs == Integer(1) || - rhs == Integer(1)) { - - return Pow{}(lhs, *Div{}(Rational(1), rhs)); - } - - if (const auto *rhsIntPtr = cast(&rhs)) { - const auto &rhsInt = *rhsIntPtr; - - if (!lhs.isComplex() && lhs < Integer(0)) { - if (rhsInt == Integer(2)) { - return mulExpr(multiRootSimplify(*(-lhs), rhsInt), I{}())->toMinimalObject(); - } - - // TODO: complex nth roots - return {}; - } - - return multiRootSimplify(lhs, rhsInt); - } - - return Pow{}(lhs, *(Rational(1) / rhs)); -} - -std::unique_ptr Root::multiRootSimplify(const INumber &lhs, const INumber &rhs) { - static const auto multiRoot = [] { - static MultiMethod(const INumber &, const INumber &)> outMultiRoot; - - outMultiRoot.add([](const Integer &inLhs, const Integer &inRhs) { - return rootSimplify(inLhs, inRhs); - }); - - outMultiRoot.add([](const Rational &inLhs, const Integer &inRhs) { - return rootSimplify(inLhs, inRhs); - }); - - outMultiRoot.add([](const Real &inLhs, const Integer &inRhs) { - return rootSimplify(inLhs, inRhs); - }); - - return outMultiRoot; - }(); - - return multiRoot(lhs, rhs); -} - -std::unique_ptr Root::rootSimplify(const Integer &lhs, const Integer &rhs) { - if (auto res = perfectRoot(lhs, rhs)) { - return res; - } - - ArgumentPtrVector mulChildren; - - RootToFactorMap rootToFactorMap = roots(lhs, rhs); - if (const Integer firstFactor = extractFirstFactor(rootToFactorMap); firstFactor != 1) { - mulChildren.emplace_back(firstFactor.clone()); - } - - for (const auto &[root, factor] : rootToFactorMap) { - if (factor != 1) { - mulChildren.emplace_back(rootExpr(factor, root)); - } - } - - if (mulChildren.size() == 1) { - return mulChildren.front()->clone(); - } - - return mulExpr(mulChildren); -} - -Root::RootToFactorMap Root::roots(const Integer &lhs, const Integer &rhs) { - static const Integer factorLimit = pow(Integer(2), 15); - - const FactorToCountMap factorToCountMap = factors(lhs, factorLimit); - RootToFactorMap rootToFactorMap{{1, 1}}; - - for (const auto &[factor, rate] : factorToCountMap) { - const Rational power(rate, rhs); - - if (power.denominator() == 1) { - rootToFactorMap[1] *= pow(factor, power.numerator()); - continue; - } - - if (power.numerator() > power.denominator()) { - rootToFactorMap[1] *= pow(factor, power.numerator() / power.denominator()); - } - - const Integer factorMultiplier = pow(factor, power.numerator() % power.denominator()); - - if (auto rootIter = rootToFactorMap.find(power.denominator()); rootIter != rootToFactorMap.end()) { - rootIter->second *= factorMultiplier; - } - else { - rootToFactorMap.try_emplace(power.denominator(), factorMultiplier); - } - } - - return rootToFactorMap; -} - -std::unique_ptr Root::perfectRoot(const Integer &lhs, const Integer &rhs) { - if (lhs < 2) { - return lhs.clone(); - } - - if (rhs == 2) { // TODO: perfect nth-roots - Integer remainder; - const Integer lhsSqrt = sqrt(lhs, remainder); - - if (remainder == 0) { - return lhsSqrt.clone(); - } - } - - return {}; -} - -std::unique_ptr Root::rootSimplify(const Rational &lhs, const Integer &rhs) { - if (lhs.denominator() == 1) { - return Root{}(lhs.numerator(), rhs); - } - - if (ArgumentPtr numeratorRes = perfectRoot(lhs.numerator(), rhs)) { - if (const ArgumentPtr denominatorRes = perfectRoot(lhs.denominator(), rhs)) { - const auto &numer = cast(*numeratorRes); - const auto &denom = cast(*denominatorRes); - return Rational(numer, denom).toMinimalObject(); - } - - ArgumentPtr denominatorRes = Root{}(lhs.denominator(), rhs); - return divExpr(std::move(numeratorRes), std::move(denominatorRes)); - } - - if (ArgumentPtr denominatorRes = perfectRoot(lhs.denominator(), rhs)) { - return divExpr(Root{}(lhs.numerator(), rhs), std::move(denominatorRes)); - } - - ArgumentPtrVector numeratorChildren; - Rational denominator = 1; - - RootToFactorMap numeratorRootToFactorMap = roots(lhs.numerator(), rhs); - if (const Integer firstFactor = extractFirstFactor(numeratorRootToFactorMap); firstFactor != 1) { - numeratorChildren.emplace_back(firstFactor.clone()); - } - - RootToFactorMap denominatorRootToFactorMap = roots(lhs.denominator(), rhs); - if (const Integer firstFactor = extractFirstFactor(denominatorRootToFactorMap); firstFactor != 1) { - denominator *= firstFactor; - } - - for (const auto &[root, numeratorFactor] : numeratorRootToFactorMap) { - if (const auto denominatorFactorIter = denominatorRootToFactorMap.find(root); - denominatorFactorIter != denominatorRootToFactorMap.end()) { - - const Integer denominatorFactor = denominatorFactorIter->second; - - denominatorRootToFactorMap.erase(denominatorFactorIter); - - if (denominatorFactor != 1) { - denominator *= denominatorFactor; - - Integer numeratorChild = numeratorFactor * pow(denominatorFactor, root - 1); - numeratorChildren.emplace_back(rootExpr(std::move(numeratorChild), root)); - - continue; - } - } - - if (numeratorFactor != 1) { - numeratorChildren.emplace_back(rootExpr(numeratorFactor, root)); - } - } - - for (const auto &[root, denominatorFactor] : denominatorRootToFactorMap) { - if (denominatorFactor != 1) { - denominator *= denominatorFactor; - - Integer numeratorChild = pow(denominatorFactor, root - 1); - numeratorChildren.emplace_back(rootExpr(std::move(numeratorChild), root)); - } - } - - ArgumentPtr numerator; - if (numeratorChildren.size() == 1) { - numerator = numeratorChildren.front(); - } - else { - numerator = mulExpr(std::move(numeratorChildren)); - } - - return divExpr(std::move(numerator), denominator.toMinimalObject()); -} - -std::unique_ptr Root::rootSimplify(const Real &lhs, const Integer &rhs) { - return Pow{}(lhs, Rational(1, rhs)); -} - -Integer Root::extractFirstFactor(RootToFactorMap &rootToFactorMap) { - const auto iter = rootToFactorMap.find(1); - Integer res = iter->second; - rootToFactorMap.erase(iter); - return res; -} - -} diff --git a/src/fintamath/functions/powers/Sqr.cpp b/src/fintamath/functions/powers/Sqr.cpp deleted file mode 100644 index 827be61de..000000000 --- a/src/fintamath/functions/powers/Sqr.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/powers/Sqr.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -std::unique_ptr Sqr::call(const ArgumentRefVector &argVect) const { - const auto &lhs = argVect.front().get(); - static const Integer rhs = 2; - - return Pow{}(lhs, rhs); -} - -} diff --git a/src/fintamath/functions/powers/Sqrt.cpp b/src/fintamath/functions/powers/Sqrt.cpp deleted file mode 100644 index 150418af5..000000000 --- a/src/fintamath/functions/powers/Sqrt.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "fintamath/functions/powers/Sqrt.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/powers/Root.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -std::unique_ptr Sqrt::call(const ArgumentRefVector &argVect) const { - const auto &lhs = argVect.front().get(); - static const Integer rhs = 2; - - return Root{}(lhs, rhs); -} - -} diff --git a/src/fintamath/functions/trigonometry/Acos.cpp b/src/fintamath/functions/trigonometry/Acos.cpp deleted file mode 100644 index a34490002..000000000 --- a/src/fintamath/functions/trigonometry/Acos.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "fintamath/functions/trigonometry/Acos.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/literals/constants/Pi.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Acos::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(-1)) { - return Pi{}.clone(); - } - - if (rhs == Integer(0)) { - return divExpr(Pi{}, Integer(2))->toMinimalObject(); - } - - if (rhs == Integer(1)) { - return Integer(0).clone(); - } - - return multiAcosSimplify(rhs); -} - -std::unique_ptr Acos::multiAcosSimplify(const INumber &rhs) { - static const auto multiAcos = [] { - static MultiMethod(const INumber &)> outMultiAcos; - - outMultiAcos.add([](const Integer &inRhs) { - return multiAcosSimplify(Real(inRhs)); - }); - - outMultiAcos.add([](const Rational &inRhs) { - return multiAcosSimplify(Real(inRhs)); - }); - - outMultiAcos.add([](const Real &inRhs) { - return acos(inRhs).clone(); - }); - - return outMultiAcos; - }(); - - return multiAcos(rhs); -} - -} diff --git a/src/fintamath/functions/trigonometry/Acot.cpp b/src/fintamath/functions/trigonometry/Acot.cpp deleted file mode 100644 index 4e864cf8f..000000000 --- a/src/fintamath/functions/trigonometry/Acot.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "fintamath/functions/trigonometry/Acot.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/literals/constants/Pi.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Acot::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(-1)) { - return negExpr(divExpr(Pi{}, Integer(4)))->toMinimalObject(); - } - - if (rhs == Integer(0)) { - return divExpr(Pi{}, Integer(2))->toMinimalObject(); - } - - if (rhs == Integer(1)) { - return divExpr(Pi{}, Integer(4))->toMinimalObject(); - } - - return multiAcotSimplify(rhs); -} - -std::unique_ptr Acot::multiAcotSimplify(const INumber &rhs) { - static const auto multiAcot = [] { - static MultiMethod(const INumber &)> outMultiAcot; - - outMultiAcot.add([](const Integer &inRhs) { - return multiAcotSimplify(Real(inRhs)); - }); - - outMultiAcot.add([](const Rational &inRhs) { - return multiAcotSimplify(Real(inRhs)); - }); - - outMultiAcot.add([](const Real &inRhs) { - return acot(inRhs).clone(); - }); - - return outMultiAcot; - }(); - - return multiAcot(rhs); -} - -} diff --git a/src/fintamath/functions/trigonometry/Acsc.cpp b/src/fintamath/functions/trigonometry/Acsc.cpp deleted file mode 100644 index 06795f9b2..000000000 --- a/src/fintamath/functions/trigonometry/Acsc.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "fintamath/functions/trigonometry/Acsc.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/literals/constants/Pi.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Acsc::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(-1)) { - return negExpr(divExpr(Pi{}, Integer(2)))->toMinimalObject(); - } - - if (rhs == Integer(0)) { - return ComplexInf{}.clone(); - } - - if (rhs == Integer(1)) { - return divExpr(Pi{}, Integer(2))->toMinimalObject(); - } - - return multiAcscSimplify(rhs); -} - -std::unique_ptr Acsc::multiAcscSimplify(const INumber &rhs) { - static const auto multiAcsc = [] { - static MultiMethod(const INumber &)> outMultiAcsc; - - outMultiAcsc.add([](const Integer &inRhs) { - return multiAcscSimplify(Real(inRhs)); - }); - - outMultiAcsc.add([](const Rational &inRhs) { - return multiAcscSimplify(Real(inRhs)); - }); - - outMultiAcsc.add([](const Real &inRhs) { - return acsc(inRhs).clone(); - }); - - return outMultiAcsc; - }(); - - return multiAcsc(rhs); -} - -} diff --git a/src/fintamath/functions/trigonometry/Asec.cpp b/src/fintamath/functions/trigonometry/Asec.cpp deleted file mode 100644 index 06daaa365..000000000 --- a/src/fintamath/functions/trigonometry/Asec.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "fintamath/functions/trigonometry/Asec.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/literals/constants/Pi.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Asec::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(-1)) { - return Pi{}.toMinimalObject(); - } - - if (rhs == Integer(0)) { - return ComplexInf{}.clone(); - } - - if (rhs == Integer(1)) { - return Integer(0).clone(); - } - - return multiAsecSimplify(rhs); -} - -std::unique_ptr Asec::multiAsecSimplify(const INumber &rhs) { - static const auto multiAsec = [] { - static MultiMethod(const INumber &)> outMultiAsec; - - outMultiAsec.add([](const Integer &inRhs) { - return multiAsecSimplify(Real(inRhs)); - }); - - outMultiAsec.add([](const Rational &inRhs) { - return multiAsecSimplify(Real(inRhs)); - }); - - outMultiAsec.add([](const Real &inRhs) { - return asec(inRhs).clone(); - }); - - return outMultiAsec; - }(); - - return multiAsec(rhs); -} - -} diff --git a/src/fintamath/functions/trigonometry/Asin.cpp b/src/fintamath/functions/trigonometry/Asin.cpp deleted file mode 100644 index ca7819d26..000000000 --- a/src/fintamath/functions/trigonometry/Asin.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "fintamath/functions/trigonometry/Asin.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/literals/constants/Pi.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Asin::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(-1)) { - return negExpr(divExpr(Pi{}, Integer(2)))->toMinimalObject(); - } - - if (rhs == Integer(0)) { - return Integer(0).clone(); - } - - if (rhs == Integer(1)) { - return divExpr(Pi{}, Integer(2))->toMinimalObject(); - } - - return multiAsinSimplify(rhs); -} - -std::unique_ptr Asin::multiAsinSimplify(const INumber &rhs) { - static const auto multiAsin = [] { - static MultiMethod(const INumber &)> outMultiAsin; - - outMultiAsin.add([](const Integer &inRhs) { - return multiAsinSimplify(Real(inRhs)); - }); - - outMultiAsin.add([](const Rational &inRhs) { - return multiAsinSimplify(Real(inRhs)); - }); - - outMultiAsin.add([](const Real &inRhs) { - return asin(inRhs).clone(); - }); - - return outMultiAsin; - }(); - - return multiAsin(rhs); -} - -} diff --git a/src/fintamath/functions/trigonometry/Atan.cpp b/src/fintamath/functions/trigonometry/Atan.cpp deleted file mode 100644 index d998d6085..000000000 --- a/src/fintamath/functions/trigonometry/Atan.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "fintamath/functions/trigonometry/Atan.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/literals/constants/Pi.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Atan::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(-1)) { - return negExpr(divExpr(Pi{}, Integer(4)))->toMinimalObject(); - } - - if (rhs == Integer(0)) { - return Integer(0).clone(); - } - - if (rhs == Integer(1)) { - return divExpr(Pi{}, Integer(4))->toMinimalObject(); - } - - return multiAtanSimplify(rhs); -} - -std::unique_ptr Atan::multiAtanSimplify(const INumber &rhs) { - static const auto multiAtan = [] { - static MultiMethod(const INumber &)> outMultiAtan; - - outMultiAtan.add([](const Integer &inRhs) { - return multiAtanSimplify(Real(inRhs)); - }); - - outMultiAtan.add([](const Rational &inRhs) { - return multiAtanSimplify(Real(inRhs)); - }); - - outMultiAtan.add([](const Real &inRhs) { - return atan(inRhs).clone(); - }); - - return outMultiAtan; - }(); - - return multiAtan(rhs); -} - -} diff --git a/src/fintamath/functions/trigonometry/Cos.cpp b/src/fintamath/functions/trigonometry/Cos.cpp deleted file mode 100644 index 0b82f36a1..000000000 --- a/src/fintamath/functions/trigonometry/Cos.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "fintamath/functions/trigonometry/Cos.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Cos::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return Integer(1).clone(); - } - - return multiCosSimplify(rhs); -} - -std::unique_ptr Cos::multiCosSimplify(const INumber &rhs) { - static const auto multiCos = [] { - static MultiMethod(const INumber &)> outMultiCos; - - outMultiCos.add([](const Integer &inRhs) { - return multiCosSimplify(Real(inRhs)); - }); - - outMultiCos.add([](const Rational &inRhs) { - return multiCosSimplify(Real(inRhs)); - }); - - outMultiCos.add([](const Real &inRhs) { - return cos(inRhs).clone(); - }); - - return outMultiCos; - }(); - - return multiCos(rhs); -} - -} diff --git a/src/fintamath/functions/trigonometry/Cot.cpp b/src/fintamath/functions/trigonometry/Cot.cpp deleted file mode 100644 index ed27a0474..000000000 --- a/src/fintamath/functions/trigonometry/Cot.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "fintamath/functions/trigonometry/Cot.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Cot::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return ComplexInf{}.clone(); - } - - return multiCotSimplify(rhs); -} - -std::unique_ptr Cot::multiCotSimplify(const INumber &rhs) { - static const auto multiCot = [] { - static MultiMethod(const INumber &)> outMultiCot; - - outMultiCot.add([](const Integer &inRhs) { - return multiCotSimplify(Real(inRhs)); - }); - - outMultiCot.add([](const Rational &inRhs) { - return multiCotSimplify(Real(inRhs)); - }); - - outMultiCot.add([](const Real &inRhs) { - return cot(inRhs).clone(); - }); - - return outMultiCot; - }(); - - return multiCot(rhs); -} - -} diff --git a/src/fintamath/functions/trigonometry/Csc.cpp b/src/fintamath/functions/trigonometry/Csc.cpp deleted file mode 100644 index 9d8a14cca..000000000 --- a/src/fintamath/functions/trigonometry/Csc.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "fintamath/functions/trigonometry/Csc.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Csc::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return ComplexInf{}.clone(); - } - - return multiCscSimplify(rhs); -} - -std::unique_ptr Csc::multiCscSimplify(const INumber &rhs) { - static const auto multiCsc = [] { - static MultiMethod(const INumber &)> outMultiCsc; - - outMultiCsc.add([](const Integer &inRhs) { - return multiCscSimplify(Real(inRhs)); - }); - - outMultiCsc.add([](const Rational &inRhs) { - return multiCscSimplify(Real(inRhs)); - }); - - outMultiCsc.add([](const Real &inRhs) { - return csc(inRhs).clone(); - }); - - return outMultiCsc; - }(); - - return multiCsc(rhs); -} - -} diff --git a/src/fintamath/functions/trigonometry/Sec.cpp b/src/fintamath/functions/trigonometry/Sec.cpp deleted file mode 100644 index 51c25fd72..000000000 --- a/src/fintamath/functions/trigonometry/Sec.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "fintamath/functions/trigonometry/Sec.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Sec::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return Integer(1).clone(); - } - - return multiSecSimplify(rhs); -} - -std::unique_ptr Sec::multiSecSimplify(const INumber &rhs) { - static const auto multiSec = [] { - static MultiMethod(const INumber &)> outMultiSec; - - outMultiSec.add([](const Integer &inRhs) { - return multiSecSimplify(Real(inRhs)); - }); - - outMultiSec.add([](const Rational &inRhs) { - return multiSecSimplify(Real(inRhs)); - }); - - outMultiSec.add([](const Real &inRhs) { - return sec(inRhs).clone(); - }); - - return outMultiSec; - }(); - - return multiSec(rhs); -} - -} diff --git a/src/fintamath/functions/trigonometry/Sin.cpp b/src/fintamath/functions/trigonometry/Sin.cpp deleted file mode 100644 index 908c4abf2..000000000 --- a/src/fintamath/functions/trigonometry/Sin.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "fintamath/functions/trigonometry/Sin.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Sin::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return rhs.clone(); - } - - return multiSinSimplify(rhs); -} - -std::unique_ptr Sin::multiSinSimplify(const INumber &rhs) { - static const auto multiSin = [] { - static MultiMethod(const INumber &)> outMultiSin; - - outMultiSin.add([](const Integer &inRhs) { - return multiSinSimplify(Real(inRhs)); - }); - - outMultiSin.add([](const Rational &inRhs) { - return multiSinSimplify(Real(inRhs)); - }); - - outMultiSin.add([](const Real &inRhs) { - return sin(inRhs).clone(); - }); - - return outMultiSin; - }(); - - return multiSin(rhs); -} - -} diff --git a/src/fintamath/functions/trigonometry/Tan.cpp b/src/fintamath/functions/trigonometry/Tan.cpp deleted file mode 100644 index 3088a4f0a..000000000 --- a/src/fintamath/functions/trigonometry/Tan.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "fintamath/functions/trigonometry/Tan.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/MultiMethod.hpp" -#include "fintamath/functions/FunctionArguments.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -using namespace detail; - -std::unique_ptr Tan::call(const ArgumentRefVector &argVect) const { - const auto &rhs = cast(argVect.front().get()); - - if (rhs == Integer(0)) { - return rhs.clone(); - } - - return multiTanSimplify(rhs); -} - -std::unique_ptr Tan::multiTanSimplify(const INumber &rhs) { - static const auto multiTan = [] { - static MultiMethod(const INumber &)> outMultiTan; - - outMultiTan.add([](const Integer &inRhs) { - return multiTanSimplify(Real(inRhs)); - }); - - outMultiTan.add([](const Rational &inRhs) { - return multiTanSimplify(Real(inRhs)); - }); - - outMultiTan.add([](const Real &inRhs) { - return tan(inRhs).clone(); - }); - - return outMultiTan; - }(); - - return multiTan(rhs); -} - -} diff --git a/src/fintamath/literals/Boolean.cpp b/src/fintamath/literals/Boolean.cpp deleted file mode 100644 index eef68b3d7..000000000 --- a/src/fintamath/literals/Boolean.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "fintamath/literals/Boolean.hpp" - -#include "fintamath/exceptions/InvalidInputException.hpp" - -namespace fintamath { - -Boolean::Boolean() : name(falseStr) { -} - -Boolean::Boolean(const std::string &str) { - if (str != trueStr && str != falseStr) { - throw InvalidInputException(str); - } - - name = str; -} - -std::string Boolean::toString() const { - return name; -} - -Boolean::operator bool() const { - return name == trueStr; -} - -} diff --git a/src/fintamath/literals/ILiteral.cpp b/src/fintamath/literals/ILiteral.cpp deleted file mode 100644 index 695683b8b..000000000 --- a/src/fintamath/literals/ILiteral.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "fintamath/literals/ILiteral.hpp" - -namespace fintamath { - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(ILiteral) - -} diff --git a/src/fintamath/literals/Variable.cpp b/src/fintamath/literals/Variable.cpp deleted file mode 100644 index b4d46934a..000000000 --- a/src/fintamath/literals/Variable.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "fintamath/literals/Variable.hpp" - -#include -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -Variable::Variable(std::string inName) { - if (inName.size() != 1) { - throw InvalidInputException(inName); - } - - if (const char ch = inName.front(); ch < 'a' || ch > 'z') { - throw InvalidInputException(inName); - } - - name = std::move(inName); -} - -Variable::Variable(std::string inName, Integer inIndex) : Variable(std::move(inName)) { - if (inIndex < 0) { - throw InvalidInputException(name + "_" + inIndex.toString()); - } - - index = std::move(inIndex); -} - -std::string Variable::toString() const { - return name + (index != -1 ? "_" + index.toString() : ""); -} - -} diff --git a/src/fintamath/literals/constants/ComplexInf.cpp b/src/fintamath/literals/constants/ComplexInf.cpp deleted file mode 100644 index f338d1ddd..000000000 --- a/src/fintamath/literals/constants/ComplexInf.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "fintamath/literals/constants/ComplexInf.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" - -namespace fintamath { - -std::unique_ptr ComplexInf::call() const { - return clone(); -} - -} diff --git a/src/fintamath/literals/constants/E.cpp b/src/fintamath/literals/constants/E.cpp deleted file mode 100644 index 6eb30a2b5..000000000 --- a/src/fintamath/literals/constants/E.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "fintamath/literals/constants/E.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -std::unique_ptr E::call() const { - return getE().clone(); -} - -} diff --git a/src/fintamath/literals/constants/False.cpp b/src/fintamath/literals/constants/False.cpp deleted file mode 100644 index aed7b1784..000000000 --- a/src/fintamath/literals/constants/False.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "fintamath/literals/constants/False.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" - -namespace fintamath { - -std::unique_ptr False::call() const { - return Boolean(false).clone(); -} - -} diff --git a/src/fintamath/literals/constants/I.cpp b/src/fintamath/literals/constants/I.cpp deleted file mode 100644 index 5166a695b..000000000 --- a/src/fintamath/literals/constants/I.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "fintamath/literals/constants/I.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Integer.hpp" - -namespace fintamath { - -std::unique_ptr I::call() const { - return std::make_unique(Integer(0), Integer(1)); -} - -} diff --git a/src/fintamath/literals/constants/IConstant.cpp b/src/fintamath/literals/constants/IConstant.cpp deleted file mode 100644 index 036ee0cd9..000000000 --- a/src/fintamath/literals/constants/IConstant.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "fintamath/literals/constants/IConstant.hpp" - -namespace fintamath { - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IConstant) - -} diff --git a/src/fintamath/literals/constants/Inf.cpp b/src/fintamath/literals/constants/Inf.cpp deleted file mode 100644 index ac740c54f..000000000 --- a/src/fintamath/literals/constants/Inf.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "fintamath/literals/constants/Inf.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" - -namespace fintamath { - -std::unique_ptr Inf::call() const { - return clone(); -} - -} diff --git a/src/fintamath/literals/constants/NegInf.cpp b/src/fintamath/literals/constants/NegInf.cpp deleted file mode 100644 index 22f58e239..000000000 --- a/src/fintamath/literals/constants/NegInf.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "fintamath/literals/constants/NegInf.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" - -namespace fintamath { - -std::unique_ptr NegInf::call() const { - return clone(); -} - -} diff --git a/src/fintamath/literals/constants/Pi.cpp b/src/fintamath/literals/constants/Pi.cpp deleted file mode 100644 index 990acec03..000000000 --- a/src/fintamath/literals/constants/Pi.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "fintamath/literals/constants/Pi.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -namespace fintamath { - -std::unique_ptr Pi::call() const { - return getPi().clone(); -} - -} diff --git a/src/fintamath/literals/constants/True.cpp b/src/fintamath/literals/constants/True.cpp deleted file mode 100644 index 027f6d204..000000000 --- a/src/fintamath/literals/constants/True.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "fintamath/literals/constants/True.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" - -namespace fintamath { - -std::unique_ptr True::call() const { - return Boolean(true).clone(); -} - -} diff --git a/src/fintamath/literals/constants/Undefined.cpp b/src/fintamath/literals/constants/Undefined.cpp deleted file mode 100644 index 385939e6c..000000000 --- a/src/fintamath/literals/constants/Undefined.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "fintamath/literals/constants/Undefined.hpp" - -#include - -#include "fintamath/core/IMathObject.hpp" - -namespace fintamath { - -std::unique_ptr Undefined::call() const { - return clone(); -} - -} diff --git a/src/fintamath/numbers/Complex.cpp b/src/fintamath/numbers/Complex.cpp deleted file mode 100644 index 3c7829c4c..000000000 --- a/src/fintamath/numbers/Complex.cpp +++ /dev/null @@ -1,221 +0,0 @@ -#include "fintamath/numbers/Complex.hpp" - -#include -#include -#include -#include - -#include "fintamath/core/Converter.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -Complex::Complex(const Complex &rhs) : re(cast(rhs.re->clone())), im(cast(rhs.im->clone())) { -} - -Complex &Complex::operator=(const Complex &rhs) { - if (this != &rhs) { - re = cast(rhs.re->clone()); - im = cast(rhs.im->clone()); - } - - return *this; -} - -Complex::Complex(const std::string &str) { - if (!str.empty() && str.back() == 'I') { - im = parseNonComplexNumber(str.substr(0, str.size() - 1)); - } - else { - re = parseNonComplexNumber(str); - } - - if (!re || !im) { - throw InvalidInputException(str); - } -} - -Complex::Complex(const INumber &inReal, const INumber &inImag) { - if (is(inReal) || is(inImag)) { - throw InvalidInputException("Nested complex numbers are not allowed"); - } - - re = cast(inReal.toMinimalObject()); - im = cast(inImag.toMinimalObject()); -} - -Complex::Complex(int64_t inReal, int64_t inImag) : re(std::make_unique(inReal)), - im(std::make_unique(inImag)) { -} - -Complex::Complex(const Integer &rhs) : re(cast(rhs.toMinimalObject())) { -} - -Complex::Complex(const Rational &rhs) : re(cast(rhs.toMinimalObject())) { -} - -Complex::Complex(const Real &rhs) : re(cast(rhs.toMinimalObject())) { -} - -Complex::Complex(int64_t rhs) : re(std::make_unique(rhs)) { -} - -std::string Complex::toString() const { - std::string res; - - if (*re != Integer(0)) { - res += re->toString(); - } - - if (*im != Integer(0)) { - std::string imStr = im->toString(); - bool isImNeg = false; - - if (imStr.front() == '-') { - imStr = imStr.substr(1); - isImNeg = true; - } - - if (*im == Integer(1) || *im == Integer(-1)) { - imStr.clear(); - } - else { - imStr += " "; - } - - if (!res.empty()) { - res += isImNeg ? " - " : " + "; - } - else if (isImNeg) { - res += "-"; - } - - res += imStr + "I"; - } - - if (res.empty()) { - res = "0"; - } - - return res; -} - -std::unique_ptr Complex::toMinimalObject() const { - if (*im == Integer(0)) { - return re->toMinimalObject(); - } - - return clone(); -} - -bool Complex::isPrecise() const { - return !is(re) && !is(im); -} - -bool Complex::isComplex() const { - return *im != Integer(0); -} - -const INumber &Complex::real() const { - return *re; -} - -const INumber &Complex::imag() const { - return *im; -} - -bool Complex::equals(const Complex &rhs) const { - return *re == *rhs.re && *im == *rhs.im; -} - -std::strong_ordering Complex::compare(const Complex &rhs) const { - if (*re == *rhs.re) { - return *im <=> *rhs.im; - } - - return *re <=> *rhs.re; -} - -Complex &Complex::add(const Complex &rhs) { - re = *re + *rhs.re; - im = *im + *rhs.im; - - return *this; -} - -Complex &Complex::substract(const Complex &rhs) { - re = *re - *rhs.re; - im = *im - *rhs.im; - - return *this; -} - -// https://en.wikipedia.org/wiki/Complex_number#Multiplication_and_square -Complex &Complex::multiply(const Complex &rhs) { - const Complex lhs = *this; - - const auto &x = *lhs.re; - const auto &y = *lhs.im; - const auto &u = *rhs.re; - const auto &v = *rhs.im; - - re = *(x * u) - *(y * v); - im = *(x * v) + *(y * u); - - return *this; -} - -// https://en.wikipedia.org/wiki/Complex_number#Reciprocal_and_division -Complex &Complex::divide(const Complex &rhs) { - const Complex lhs = *this; - - const auto &x = *lhs.re; - const auto &y = *lhs.im; - const auto &u = *rhs.re; - const auto &v = *rhs.im; - - auto divisor = *(u * u) + *(v * v); - - if (is(divisor)) { - divisor = convert(*divisor); - } - - try { - re = *(*(x * u) + *(y * v)) / *divisor; - im = *(*(y * u) - *(x * v)) / *divisor; - } - catch (const UndefinedException &) { - throw UndefinedBinaryOperatorException("/", toString(), rhs.toString()); - } - - return *this; -} - -Complex &Complex::negate() { - re = -(*re); - im = -(*im); - return *this; -} - -std::unique_ptr Complex::parseNonComplexNumber(const std::string &str) { - static auto numberParser = [] { - detail::Parser> parser; - parser.registerType(); - parser.registerType(); - parser.registerType(); - return parser; - }(); - - return numberParser - .parseFirst(str) - .value_or(std::unique_ptr{}); -} - -} diff --git a/src/fintamath/numbers/IInteger.cpp b/src/fintamath/numbers/IInteger.cpp deleted file mode 100644 index e3f972ec4..000000000 --- a/src/fintamath/numbers/IInteger.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "fintamath/numbers/IInteger.hpp" - -namespace fintamath { - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IInteger) - -} diff --git a/src/fintamath/numbers/INumber.cpp b/src/fintamath/numbers/INumber.cpp deleted file mode 100644 index e9b27c355..000000000 --- a/src/fintamath/numbers/INumber.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(INumber) - -} diff --git a/src/fintamath/numbers/Integer.cpp b/src/fintamath/numbers/Integer.cpp deleted file mode 100644 index 52aba98eb..000000000 --- a/src/fintamath/numbers/Integer.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include "fintamath/numbers/Integer.hpp" - -#include -#include -#include -#include -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/NumberUtils.hpp" - -namespace fintamath { - -using namespace detail; - -Integer::Integer(Backend inBackend) : backend(std::move(inBackend)) { -} - -Integer::Integer(std::string str) { - if (str.empty()) { - throw InvalidInputException(str); - } - - str = removeLeadingZeroes(std::move(str)); - - try { - backend.assign(str); - } - catch (const std::runtime_error &) { - throw InvalidInputException(str); - } -} - -Integer::Integer(const int64_t val) : backend(val) { -} - -std::string Integer::toString() const { - return backend.str(); -} - -int Integer::sign() const { - return backend.sign(); -} - -const Integer::Backend &Integer::getBackend() const { - return backend; -} - -bool Integer::equals(const Integer &rhs) const { - return backend == rhs.backend; -} - -std::strong_ordering Integer::compare(const Integer &rhs) const { - return backend.compare(rhs.backend) <=> 0; -} - -Integer &Integer::add(const Integer &rhs) { - backend += rhs.backend; - return *this; -} - -Integer &Integer::substract(const Integer &rhs) { - backend -= rhs.backend; - return *this; -} - -Integer &Integer::multiply(const Integer &rhs) { - backend *= rhs.backend; - return *this; -} - -Integer &Integer::divide(const Integer &rhs) { - if (rhs == 0) { - throw UndefinedBinaryOperatorException("/", toString(), rhs.toString()); - } - - backend /= rhs.backend; - return *this; -} - -Integer &Integer::mod(const Integer &rhs) { - if (rhs == 0) { - throw UndefinedBinaryOperatorException("mod", toString(), rhs.toString()); - } - - backend %= rhs.backend; - return *this; -} - -Integer &Integer::bitAnd(const Integer &rhs) { - backend &= rhs.backend; - return *this; -} - -Integer &Integer::bitOr(const Integer &rhs) { - backend |= rhs.backend; - return *this; -} - -Integer &Integer::bitXor(const Integer &rhs) { - backend ^= rhs.backend; - return *this; -} - -Integer &Integer::bitLeftShift(const Integer &rhs) { - try { - backend <<= static_cast(rhs.backend); - return *this; - } - catch (...) { - throw UndefinedBinaryOperatorException("<<", toString(), rhs.toString()); - } -} - -Integer &Integer::bitRightShift(const Integer &rhs) { - try { - backend >>= static_cast(rhs.backend); - return *this; - } - catch (...) { - throw UndefinedBinaryOperatorException(">>", toString(), rhs.toString()); - } -} - -Integer &Integer::bitNot() { - backend = ~backend; - return *this; -} - -Integer &Integer::negate() { - backend = -backend; - return *this; -} - -Integer &Integer::increase() { - ++backend; - return *this; -} - -Integer &Integer::decrease() { - --backend; - return *this; -} - -} diff --git a/src/fintamath/numbers/IntegerFunctions.cpp b/src/fintamath/numbers/IntegerFunctions.cpp deleted file mode 100644 index b43f7492b..000000000 --- a/src/fintamath/numbers/IntegerFunctions.cpp +++ /dev/null @@ -1,160 +0,0 @@ -#include "fintamath/numbers/IntegerFunctions.hpp" - -#include -#include -#include -#include - -#include - -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/Integer.hpp" - -using namespace boost::multiprecision; - -namespace fintamath { - -Integer abs(const Integer &rhs) { - return rhs < 0 ? -rhs : rhs; -} - -Integer gcd(const Integer &lhs, const Integer &rhs) { - return {gcd(lhs.getBackend(), rhs.getBackend())}; -} - -Integer lcm(const Integer &lhs, const Integer &rhs) { - return {lcm(lhs.getBackend(), rhs.getBackend())}; -} - -Integer sqrt(const Integer &rhs) { - Integer remainder; - return sqrt(rhs, remainder); -} - -Integer sqrt(const Integer &rhs, Integer &remainder) { - if (rhs < 0) { - throw UndefinedFunctionException("sqrt", {rhs.toString()}); - } - - Integer::Backend remainderBackend; - Integer res(sqrt(rhs.getBackend(), remainderBackend)); - remainder = Integer(std::move(remainderBackend)); - return res; -} - -// Use binary splitting. -// http://numbers.computation.free.fr/Constants/Algorithms/splitting.html. -Integer factorialRec(const Integer &left, const Integer &right) { - if (left == right) { - return left; - } - - if (right - left == 1) { - return left * right; - } - - const Integer mid((left + right) / 2); - return factorialRec(left, mid) * factorialRec(mid + 1, right); -} - -Integer factorial(const Integer &rhs) { - if (rhs < 0) { - throw UndefinedUnaryOperatorException("!", rhs.toString(), UndefinedUnaryOperatorException::Type::Postfix); - } - - if (rhs < 2) { - return 1; - } - - return factorialRec(2, rhs); -} - -Integer factorial(const Integer &rhs, const size_t order) { - assert(order > 0); - - if (rhs < 0) { - throw UndefinedUnaryOperatorException(std::string(order, '!'), rhs.toString(), - UndefinedUnaryOperatorException::Type::Postfix); - } - - if (order == 1) { - return factorial(rhs); - } - - // Use generalized factorial formula. - // https://en.wikipedia.org/wiki/Double_factorial. - - Integer res = 1; - for (Integer i = rhs; i > 0; i -= order) { - res *= i; - } - - return res; -} - -FactorToCountMap factors(Integer rhs, Integer limit) { - if (rhs < 2) { - throw UndefinedFunctionException("factors", {rhs.toString()}); - } - - FactorToCountMap factorToCountMap; - - while (rhs % 2 == 0) { - ++factorToCountMap[2]; - rhs /= 2; - } - - { - const Integer rhsSqrt = sqrt(rhs); - - if (limit < 0 || limit > rhsSqrt) { - limit = rhsSqrt; - } - } - - for (Integer i = 3; i <= limit; i += 2) { - while (rhs % i == 0) { - ++factorToCountMap[i]; - rhs = rhs / i; - } - } - - if (rhs > 1) { - ++factorToCountMap[rhs]; - } - - return factorToCountMap; -} - -// Use number of combinations formula. -// https://en.wikipedia.org/wiki/Combination#Number_of_k-combinations. -Integer combinations(const Integer &totalNumber, const Integer &choosedNumber) { - if (choosedNumber > totalNumber) { - throw UndefinedFunctionException("combinations", {totalNumber.toString()}); - } - - return factorial(totalNumber) / (factorial(choosedNumber) * factorial(totalNumber - choosedNumber)); -} - -// Use multinomial coefficients formula. -// https://en.wikipedia.org/wiki/Multinomial_theorem#Multinomial_coefficients. -Integer multinomialCoefficient(const Integer &totalNumber, const std::vector &groupNumbers) { - Integer checkValue; - - for (const auto &groupNumber : groupNumbers) { - checkValue += groupNumber; - } - - if (checkValue != totalNumber) { - throw UndefinedFunctionException("split", {totalNumber.toString()}); - } - - Integer res = factorial(totalNumber); - for (const auto &groupNumber : groupNumbers) { - res /= factorial(groupNumber); - } - - return res; -} - -} diff --git a/src/fintamath/numbers/NumberAbstract.cpp b/src/fintamath/numbers/NumberAbstract.cpp deleted file mode 100644 index 9ad847284..000000000 --- a/src/fintamath/numbers/NumberAbstract.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "fintamath/numbers/INumber.hpp" - -#include -#include - -#include "fintamath/core/IArithmetic.hpp" -#include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/numbers/IInteger.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -std::unique_ptr Integer::multiplyAbstract(const IArithmetic &rhs) const { - if (*this == 0) { - return cast(Integer(0).clone()); - } - - return IIntegerCRTP::multiplyAbstract(rhs); -} - -std::unique_ptr Integer::divideAbstract(const IArithmetic &rhs) const { - if (*this == 0 && rhs != Integer(0) && rhs != Real(0)) { - return cast(Integer(0).clone()); - } - - if (const auto *intRhs = cast(&rhs)) { - if (*this % *intRhs != 0) { - return cast(Rational(*this, *intRhs).clone()); - } - } - - return IIntegerCRTP::divideAbstract(rhs); -} - -//-------------------------------------------------------------------------------------// - -std::unique_ptr Rational::multiplyAbstract(const IArithmetic &rhs) const { - if (*this == 0) { - return cast(Integer(0).clone()); - } - - return INumberCRTP::multiplyAbstract(rhs); -} - -std::unique_ptr Rational::divideAbstract(const IArithmetic &rhs) const { - if (*this == 0 && rhs != Integer(0) && rhs != Real(0)) { - return cast(Integer(0).clone()); - } - - return INumberCRTP::divideAbstract(rhs); -} - -//-------------------------------------------------------------------------------------// - -bool Real::equalsAbstract(const IMathObject &rhs) const { - if (const auto *rhsNum = cast(&rhs); rhsNum && rhsNum->isPrecise()) { - return false; - } - - return INumberCRTP::equalsAbstract(rhs); -} - -std::strong_ordering Real::compareAbstract(const IComparable &rhs) const { - const auto res = INumberCRTP::compareAbstract(rhs); - - if (res == std::strong_ordering::equal) { - if (const auto *rhsNum = cast(&rhs); rhsNum && rhsNum->isPrecise()) { - return sign() != 0 ? sign() <=> 0 : std::strong_ordering::greater; - } - } - - return res; -} - -std::unique_ptr Real::multiplyAbstract(const IArithmetic &rhs) const { - if (const auto *rhsNum = cast(&rhs); rhsNum && *rhsNum == Integer(0)) { - return cast(Integer(0).clone()); - } - - return INumberCRTP::multiplyAbstract(rhs); -} - -} diff --git a/src/fintamath/numbers/NumberUtils.cpp b/src/fintamath/numbers/NumberUtils.cpp deleted file mode 100644 index d83cc19a1..000000000 --- a/src/fintamath/numbers/NumberUtils.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "fintamath/numbers/NumberUtils.hpp" - -#include -#include - -namespace fintamath::detail { - -std::string removeLeadingZeroes(std::string str) { - size_t firstDigit = 0; - if (str.front() == '-') { - firstDigit++; - } - - const size_t firstNonZeroDigit = str.find_first_not_of('0', firstDigit); - - if (firstNonZeroDigit == std::string::npos) { - str.insert(firstDigit, "0"); - } - else if (firstNonZeroDigit > firstDigit) { - str.erase(firstDigit, firstNonZeroDigit - firstDigit); - } - - return str; -} - -} diff --git a/src/fintamath/numbers/Rational.cpp b/src/fintamath/numbers/Rational.cpp deleted file mode 100644 index f25159cfc..000000000 --- a/src/fintamath/numbers/Rational.cpp +++ /dev/null @@ -1,180 +0,0 @@ -#include "fintamath/numbers/Rational.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fintamath/core/IMathObject.hpp" -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" - -namespace fintamath { - -Rational::Rational(const std::string &str) { - if (str.empty()) { - throw InvalidInputException(str); - } - - if (str.empty() || str == ".") { - throw InvalidInputException(str); - } - - int64_t firstDigitNum = 0; - const int64_t firstDotNum = stdr::distance(str.begin(), stdr::find(str, '.')); - - bool isNegative = false; - if (str.front() == '-') { - isNegative = true; - firstDigitNum++; - } - - const std::string intPartStr = str.substr(static_cast(firstDigitNum), - static_cast(firstDotNum - firstDigitNum)); - Integer intPart; - - if (!intPartStr.empty()) { - intPart = Integer(str.substr(static_cast(firstDigitNum), - static_cast(firstDotNum - firstDigitNum))); - } - - if (firstDotNum + 1 < std::ssize(str)) { - const std::string numeratorStr = str.substr(static_cast(firstDotNum) + 1); - std::string denominatorStr(numeratorStr.size() + 1, '0'); - denominatorStr.front() = '1'; - numer = Integer(numeratorStr); - denom = Integer(denominatorStr); - } - - if (intPart < 0 || numer < 0) { - throw InvalidInputException(str); - } - - toIrreducibleRational(); - numer += intPart * denom; - - if (isNegative) { - numer *= -1; - } -} - -Rational::Rational(Integer inNumer, Integer inDenom) - : numer(std::move(inNumer)), - denom(std::move(inDenom)) { - - toIrreducibleRational(); -} - -Rational::Rational(Integer rhs) : numer(std::move(rhs)) { -} - -Rational::Rational(const int64_t rhs) : numer(rhs) { -} - -const Integer &Rational::numerator() const { - return numer; -} - -const Integer &Rational::denominator() const { - return denom; -} - -std::string Rational::toString() const { - std::string res = numer.toString(); - - if (denom != 1) { - res += "/" + denom.toString(); - } - - return res; -} - -std::unique_ptr Rational::toMinimalObject() const { - if (denom == 1) { - return numer.clone(); - } - return clone(); -} - -int Rational::sign() const { - return numer.sign(); -} - -bool Rational::equals(const Rational &rhs) const { - return numer == rhs.numer && denom == rhs.denom; -} - -std::strong_ordering Rational::compare(const Rational &rhs) const { - Rational lhs = *this; - Rational tmpRhs = rhs; - toCommonDenominators(lhs, tmpRhs); - return lhs.numer <=> tmpRhs.numer; -} - -Rational &Rational::add(const Rational &rhs) { - Rational tmpRhs = rhs; - toCommonDenominators(*this, tmpRhs); - numer += tmpRhs.numer; - toIrreducibleRational(); - return *this; -} - -Rational &Rational::substract(const Rational &rhs) { - Rational tmpRhs = rhs; - toCommonDenominators(*this, tmpRhs); - numer -= tmpRhs.numer; - toIrreducibleRational(); - return *this; -} - -Rational &Rational::multiply(const Rational &rhs) { - numer *= rhs.numer; - denom *= rhs.denom; - toIrreducibleRational(); - return *this; -} - -Rational &Rational::divide(const Rational &rhs) { - numer *= rhs.denom; - denom *= rhs.numer; - toIrreducibleRational(); - return *this; -} - -Rational &Rational::negate() { - numer = -numer; - return *this; -} - -void Rational::toIrreducibleRational() { - if (denom == 0) { - throw UndefinedBinaryOperatorException("/", numer.toString(), denom.toString()); - } - - if (denom < 0) { - numer *= -1; - denom *= -1; - } - - const Integer gcdVal = gcd(numer, denom); - numer /= gcdVal; - denom /= gcdVal; -} - -void Rational::toCommonDenominators(Rational &lhs, Rational &rhs) { - const Integer lcmVal = lcm(lhs.denom, rhs.denom); - - lhs.numer *= (lcmVal / lhs.denom); - lhs.denom = lcmVal; - - rhs.numer *= (lcmVal / rhs.denom); - rhs.denom = lcmVal; -} - -} diff --git a/src/fintamath/numbers/RationalFunctions.cpp b/src/fintamath/numbers/RationalFunctions.cpp deleted file mode 100644 index 68786dde8..000000000 --- a/src/fintamath/numbers/RationalFunctions.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "fintamath/numbers/RationalFunctions.hpp" - -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" -#include "fintamath/numbers/Rational.hpp" - -namespace fintamath { - -Integer floor(const Rational &rhs) { - Integer div = rhs.numerator() / rhs.denominator(); - - if (rhs.numerator() < 0 && abs(rhs.numerator()) % rhs.denominator() != 0) { - --div; - } - - return div; -} - -Integer ceil(const Rational &rhs) { - Integer div = rhs.numerator() / rhs.denominator(); - - if (rhs.numerator() >= 0 && abs(rhs.numerator()) % rhs.denominator() != 0) { - ++div; - } - - return div; -} - -Rational abs(const Rational &rhs) { - return rhs < 0 ? -rhs : rhs; -} - -} diff --git a/src/fintamath/numbers/Real.cpp b/src/fintamath/numbers/Real.cpp deleted file mode 100644 index 165735ed3..000000000 --- a/src/fintamath/numbers/Real.cpp +++ /dev/null @@ -1,267 +0,0 @@ -#include "fintamath/numbers/Real.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/NumberUtils.hpp" -#include "fintamath/numbers/Rational.hpp" - -namespace fintamath { - -using namespace detail; - -constexpr unsigned precisionMultiplier = 2; -constexpr unsigned precisionDelta = 10; - -Real::Real(Backend inBackend) : backend(std::move(inBackend)), - isNegative(backend < 0) { - - if (!isFinite()) { - throw UndefinedException(backend.str()); - } -} - -Real::Real(std::string str) : Real() { - if (str.empty() || str == ".") { - throw InvalidInputException(str); - } - - str = removeLeadingZeroes(std::move(str)); - - if (str.front() == '-') { - isNegative = true; - } - - { - const std::string expStr = "*10^"; - const size_t expPos = str.find(expStr); - - if (expPos != std::string::npos) { - str.replace(expPos, expStr.length(), "e"); - } - } - - try { - backend.assign(str); - } - catch (const std::runtime_error &) { - throw InvalidInputException(str); - } - - if (!isFinite()) { - throw UndefinedException(str); - } -} - -Real::Real(const Rational &val) { - *this = Real(val.numerator()) / Real(val.denominator()); -} - -Real::Real(const Integer &val) : backend(val.getBackend()), - isNegative(val < 0) { -} - -Real::Real(const int64_t val) : backend(val), - isNegative(val < 0) { -} - -std::string Real::toString() const { - std::string res = toString(outputPrecision); - - if (isNegative && res.front() != '-') { - res.insert(res.begin(), '-'); - } - - return res; -} - -std::string Real::toString(unsigned precision) const { - validateNewPrecision(precision); - - if (precision == 0) { - precision++; - } - - std::string str = backend.str(static_cast(precision)); - size_t expPos = str.find('e'); - - if (expPos != std::string::npos) { - size_t expNextPos = expPos + 1; - - if (str[expNextPos] == '+') { - str.erase(expNextPos, 1); - } - else { - expNextPos++; - } - - if (str[expNextPos] == '0') { - str.erase(expNextPos, 1); - } - - str.replace(expPos, 1, "*10^"); - } - else { - expPos = str.size(); - } - - if (str.find('.') == std::string::npos) { - str.insert(expPos, ".0"); - } - - if (str.ends_with("^1")) { - str.erase(str.size() - 2, 2); - } - - return str; -} - -bool Real::isPrecise() const { - return false; -} - -int Real::sign() const { - if (isNegative) { - return -1; - } - - return backend.sign(); -} - -bool Real::isZero() const { - return backend.is_zero(); -} - -const Real::Backend &Real::getBackend() const { - return backend; -} - -unsigned Real::getOutputPrecision() const { - return outputPrecision; -} - -void Real::setOutputPrecision(const unsigned precision) { - validateNewPrecision(precision); - outputPrecision = precision; -} - -unsigned Real::getCalculationPrecision() { - return Backend::thread_default_precision(); -} - -unsigned Real::getPrecision() { - return (getCalculationPrecision() - precisionDelta) / precisionMultiplier; -} - -void Real::setPrecision(unsigned precision) { - if (precision == 0) { - precision++; - } - - Backend::thread_default_precision(precision * precisionMultiplier + precisionDelta); -} - -bool Real::equals(const Real &rhs) const { - return backend == rhs.backend && isNegative == rhs.isNegative; -} - -std::strong_ordering Real::compare(const Real &rhs) const { - if (isNegative && !rhs.isNegative) { - return std::strong_ordering::less; - } - - if (!isNegative && rhs.isNegative) { - return std::strong_ordering::greater; - } - - return backend.compare(rhs.backend) <=> 0; -} - -Real &Real::add(const Real &rhs) { - updatePrecision(rhs); - - const bool isResNegZero = backend.is_zero() && - rhs.backend.is_zero() && - (isNegative || rhs.isNegative); - backend += rhs.backend; - isNegative = isResNegZero || backend < 0; - - return *this; -} - -Real &Real::substract(const Real &rhs) { - updatePrecision(rhs); - - const bool isResNegZero = backend.is_zero() && - rhs.backend.is_zero() && - (isNegative || !rhs.isNegative); - backend -= rhs.backend; - isNegative = isResNegZero || backend < 0; - - return *this; -} - -Real &Real::multiply(const Real &rhs) { - updatePrecision(rhs); - - isNegative = isNegative != rhs.isNegative; - backend *= rhs.backend; - - return *this; -} - -Real &Real::divide(const Real &rhs) { - updatePrecision(rhs); - - isNegative = isNegative != rhs.isNegative; - backend /= rhs.backend; - - if (!isFinite()) { - throw UndefinedBinaryOperatorException("/", toString(), rhs.toString()); - } - - return *this; -} - -Real &Real::negate() { - isNegative = !isNegative; - backend = -backend; - return *this; -} - -bool Real::isFinite() const { - return boost::math::isfinite(backend); -} - -void Real::updatePrecision(const Real &rhs) { - outputPrecision = std::min(outputPrecision, rhs.outputPrecision); -} - -void Real::validateNewPrecision(const unsigned precision) const { - if (precision > outputPrecision) { - // TODO: use std::format - throw InvalidInputException("Precision must be less than or equal to " + - std::to_string(outputPrecision)); - } -} - -Real::ScopedSetPrecision::ScopedSetPrecision(const unsigned precision) { - setPrecision(precision); -} - -Real::ScopedSetPrecision::~ScopedSetPrecision() { - setPrecision(currPrecision); -} - -} diff --git a/src/fintamath/numbers/RealFunctions.cpp b/src/fintamath/numbers/RealFunctions.cpp deleted file mode 100644 index f978b009e..000000000 --- a/src/fintamath/numbers/RealFunctions.cpp +++ /dev/null @@ -1,437 +0,0 @@ -#include "fintamath/numbers/RealFunctions.hpp" - -#include - -#include -#include -#include - -#include "fintamath/core/Cache.hpp" -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Real.hpp" - -namespace fintamath { - -using namespace detail; - -bool isOverflow(const Real &rhs) { - static Cache cache([](const unsigned precision) { - static const Real::Backend powBase = 10; - return pow(powBase, precision); - }); - - return abs(rhs) > cache[Real::getPrecision()]; -} - -bool isUnderflow(const Real &rhs) { - static Cache cache([](const unsigned precision) { - static const Real::Backend powBase = 10; - return 1 / pow(powBase, precision); - }); - - return rhs != 0 && abs(rhs) < cache[Real::getPrecision()]; -} - -bool isLogUnderflow(const Real &rhs) { - static Cache cache([](const unsigned precision) { - return 1 / pow(precision, getE().getBackend()); - }); - - return rhs != 0 && abs(rhs) < cache[Real::getPrecision()]; -} - -const Real &trigResultChecked(const Real &rhs) { - if (isUnderflow(rhs) || isOverflow(rhs)) { - throw UndefinedException(""); - } - - return rhs; -} - -const Real &hyperbResultChecked(const Real &rhs) { - if (isUnderflow(rhs)) { - throw UndefinedException(""); - } - - return rhs; -} - -const Real &tgammaResultChecked(const Real &rhs) { - if (rhs == 0) { - throw UndefinedException(""); - } - - return rhs; -} - -Integer floor(const Real &rhs) { - if (isOverflow(rhs)) { - throw UndefinedFunctionException("floor", {rhs.toString()}); - } - - const Real::Backend res = boost::multiprecision::floor(rhs.getBackend()); - return res.convert_to(); -} - -Integer ceil(const Real &rhs) { - if (isOverflow(rhs)) { - throw UndefinedFunctionException("ceil", {rhs.toString()}); - } - - const Real::Backend res = boost::multiprecision::ceil(rhs.getBackend()); - return res.convert_to(); -} - -Real abs(const Real &rhs) { - return rhs < 0 ? -rhs : rhs; -} - -Real sqrt(const Real &rhs) { - if (rhs < 0) { - throw UndefinedFunctionException("sqrt", {rhs.toString()}); - } - - return {sqrt(rhs.getBackend())}; -} - -Real pow(const Real &lhs, const Real &rhs) { - if (abs(lhs) == 0 && abs(rhs) == 0) { - throw UndefinedBinaryOperatorException("^", lhs.toString(), rhs.toString()); - } - - try { - if (lhs == Real("-0")) { - // Use (-1)^rhs to validate (-0)^rhs - Real(pow(-1, rhs.getBackend())); - } - - return {pow(lhs.getBackend(), rhs.getBackend())}; - } - catch (const UndefinedException &) { - throw UndefinedBinaryOperatorException("^", lhs.toString(), rhs.toString()); - } -} - -Real exp(const Real &rhs) { - try { - return {exp(rhs.getBackend())}; - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("exp", {rhs.toString()}); - } -} - -Real log(const Real &lhs, const Real &rhs) { - try { - return ln(rhs) / ln(lhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("log", {lhs.toString(), rhs.toString()}); - } -} - -Real ln(const Real &rhs) { - if (rhs <= 0) { - throw UndefinedFunctionException("ln", {rhs.toString()}); - } - - Real res = {log(rhs.getBackend())}; - - if (isLogUnderflow(res)) { - throw UndefinedFunctionException("ln", {rhs.toString()}); - } - - return res; -} - -Real lb(const Real &rhs) { - try { - static const Real logBase = 2; - return log(logBase, rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("lb", {rhs.toString()}); - } -} - -Real lg(const Real &rhs) { - try { - static const Real logBase = 10; - return log(logBase, rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("lg", {rhs.toString()}); - } -} - -Real sin(const Real &rhs) { - if (isOverflow(rhs)) { - throw UndefinedFunctionException("sin", {rhs.toString()}); - } - - try { - return trigResultChecked({sin(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("sin", {rhs.toString()}); - } -} - -Real cos(const Real &rhs) { - if (isOverflow(rhs)) { - throw UndefinedFunctionException("cos", {rhs.toString()}); - } - - try { - return trigResultChecked({cos(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("cos", {rhs.toString()}); - } -} - -Real tan(const Real &rhs) { - if (isOverflow(rhs)) { - throw UndefinedFunctionException("tan", {rhs.toString()}); - } - - try { - return trigResultChecked({tan(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("tan", {rhs.toString()}); - } -} - -Real cot(const Real &rhs) { - try { - return 1 / tan(rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("cot", {rhs.toString()}); - } -} - -Real sec(const Real &rhs) { - try { - return 1 / cos(rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("sec", {rhs.toString()}); - } -} - -Real csc(const Real &rhs) { - try { - return 1 / sin(rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("csc", {rhs.toString()}); - } -} - -Real asin(const Real &rhs) { - try { - return trigResultChecked({asin(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("asin", {rhs.toString()}); - } -} - -Real acos(const Real &rhs) { - try { - return trigResultChecked({acos(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("acos", {rhs.toString()}); - } -} - -Real atan(const Real &rhs) { - try { - return trigResultChecked({atan(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("atan", {rhs.toString()}); - } -} - -Real acot(const Real &rhs) { - try { - return atan(1 / rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("acot", {rhs.toString()}); - } -} - -Real asec(const Real &rhs) { - try { - return acos(1 / rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("asec", {rhs.toString()}); - } -} - -Real acsc(const Real &rhs) { - try { - return asin(1 / rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("acsc", {rhs.toString()}); - } -} - -Real sinh(const Real &rhs) { - try { - return hyperbResultChecked({sinh(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("sinh", {rhs.toString()}); - } -} - -Real cosh(const Real &rhs) { - try { - return hyperbResultChecked({cosh(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("cosh", {rhs.toString()}); - } -} - -Real tanh(const Real &rhs) { - try { - return hyperbResultChecked({tanh(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("tanh", {rhs.toString()}); - } -} - -Real coth(const Real &rhs) { - try { - return 1 / tanh(rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("coth", {rhs.toString()}); - } -} - -Real sech(const Real &rhs) { - try { - return 1 / cosh(rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("sech", {rhs.toString()}); - } -} - -Real csch(const Real &rhs) { - try { - return 1 / sinh(rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("csch", {rhs.toString()}); - } -} - -Real asinh(const Real &rhs) { - try { - return hyperbResultChecked(boost::math::asinh(rhs.getBackend())); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("asinh", {rhs.toString()}); - } -} - -Real acosh(const Real &rhs) { - try { - return boost::math::acosh(rhs.getBackend()); - } - catch (const boost::math::evaluation_error &) { - throw UndefinedFunctionException("acosh", {rhs.toString()}); - } -} - -Real atanh(const Real &rhs) { - try { - return hyperbResultChecked(boost::math::atanh(rhs.getBackend())); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("atanh", {rhs.toString()}); - } - catch (const std::overflow_error &) { - throw UndefinedFunctionException("atanh", {rhs.toString()}); - } - catch (const boost::math::evaluation_error &) { - throw UndefinedFunctionException("atanh", {rhs.toString()}); - } -} - -Real acoth(const Real &rhs) { - try { - return atanh(1 / rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("acoth", {rhs.toString()}); - } -} - -Real asech(const Real &rhs) { - try { - return acosh(1 / rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("asech", {rhs.toString()}); - } -} - -Real acsch(const Real &rhs) { - try { - return asinh(1 / rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("acsch", {rhs.toString()}); - } -} - -Real tgamma(const Real &rhs) { - try { - return tgammaResultChecked(boost::math::tgamma(rhs.getBackend())); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("tgamma", {rhs.toString()}); - } - catch (const std::overflow_error &) { - throw UndefinedFunctionException("tgamma", {rhs.toString()}); - } - catch (const boost::math::evaluation_error &) { - throw UndefinedFunctionException("tgamma", {rhs.toString()}); - } -} - -const Real &getE() { - static Cache cache([](const unsigned precision) { - Real::Backend::backend_type res; - boost::multiprecision::default_ops::calc_e(res, precision); - return Real(res); - }); - - return cache[Real::getCalculationPrecision()]; -} - -const Real &getPi() { - static Cache cache([](const unsigned precision) { - Real::Backend::backend_type res; - boost::multiprecision::default_ops::calc_pi(res, precision); - return Real(res); - }); - - return cache[Real::getCalculationPrecision()]; -} - -} diff --git a/tests/src/FintamathTests.cpp b/tests/src/FintamathTests.cpp deleted file mode 100644 index 1ced8cacf..000000000 --- a/tests/src/FintamathTests.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionFunctions.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/literals/constants/E.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -TEST(FintamathTests, fintamathTest) { - Expression expr; - Variable x("x"); - Variable y("y"); - - //-------------------------------------------------------------------------------------// - - expr = e() + pi() + Variable("a") + Variable("b"); - EXPECT_EQ(expr.toString(), "a + b + E + Pi"); - - expr = e() * pi() * Variable("a") * Variable("b"); - EXPECT_EQ(expr.toString(), "E Pi a b"); - - expr = pow(Variable("a"), Variable("b")) * Variable("c"); - EXPECT_EQ(expr.toString(), "a^b c"); - - expr = x * x * x * y + 10 * x; - EXPECT_EQ(expr.toString(), "x^3 y + 10 x"); - - expr = x + 10 * x / 10 + (sqrt(x) * 2); - EXPECT_EQ(expr.toString(), "2 x + 2 sqrt(x)"); - - expr = eqv(x * x + y * y * y, x * y); - EXPECT_EQ(expr.toString(), "x^2 - x y + y^3 = 0"); - - expr = eqv(x * x + y * y, x * y); - EXPECT_EQ(expr.toString(), "x^2 - x y + y^2 = 0"); - - expr = eqv(x / x - y / y, x / y); - EXPECT_EQ(expr.toString(), "x = 0"); - - expr = Expression("(4x^4 + 1 + 3x^3 + 2x) / (x^2 + x + 2)"); - EXPECT_EQ(expr.toString(), "4 x^2 - x - 7 + (11 x + 15)/(x^2 + x + 2)"); - - expr = log(2, 256) + ln(pow(e(), 2)); - EXPECT_EQ(expr.toString(), "10"); - - expr = sqrt(Expression(8)); - EXPECT_EQ(expr.toString(), "2 sqrt(2)"); - - expr = pow(Expression("244706656946119777797996531655819747089832578"), Rational(1, 4)); - EXPECT_EQ(expr.toString(), "sqrt(11) root(2022369065670411386760301914510907000742418, 4)"); - - expr = sin(asin(Variable(x))) + cos(acos(Integer(1))); - EXPECT_EQ(expr.toString(), "x + 1"); - - expr = pow(sin(x), 2) + pow(cos(x), 2) + tan(x) * cot(x); - EXPECT_EQ(expr.toString(), "2"); - - expr = sin(Expression("-3Pi/2")) + cos(Expression("Pi/4")); - EXPECT_EQ(expr.toString(), "sqrt(2)/2 + 1"); - - expr = approximate(sin(Expression("123"))); - EXPECT_EQ(expr.toString(), "-0.45990349068959125129"); - - expr = approximate(cos(Expression("-256"))); - EXPECT_EQ(expr.toString(), "-0.039790759931157709524"); - - expr = Expression("~a & b | ~c -> a <-> b !<-> c"); - EXPECT_EQ(expr.toString(), "(a & b & ~c) | (~a & ~b & ~c) | (~a & c) | (~b & c)"); - - //-------------------------------------------------------------------------------------// - - expr = solve(eqv(pow(x, 2) - 10, 39)); - EXPECT_EQ(expr.toString(), "x = -7 | x = 7"); - - expr = solve(Expression("-4x^2 + 28x - 49 = 0")); - EXPECT_EQ(expr.toString(), "x = 7/2"); - - expr = solve(Expression("x^2 + 4x + 5 = 0")); - EXPECT_EQ(expr.toString(), "x = -2 - I | x = -2 + I"); - - expr = solve(Expression("3x^2 + 11x + 15 = 0")); - EXPECT_EQ(expr.toString(), "x = -(I sqrt(59))/6 - 11/6 | x = (I sqrt(59))/6 - 11/6"); - - expr = approximate(solve(Expression("-3x^2 + 28x - 49 = 0")), 2); - EXPECT_EQ(expr.toString(), "x = 2.3 | x = 7"); -} diff --git a/tests/src/core/CacheTests.cpp b/tests/src/core/CacheTests.cpp deleted file mode 100644 index 8d63acfdd..000000000 --- a/tests/src/core/CacheTests.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "fintamath/core/Cache.hpp" - -#include "fintamath/literals/constants/E.hpp" -#include "fintamath/numbers/Integer.hpp" - -using namespace fintamath; - -TEST(CacheTests, atTest) { - // TODO: implement -} diff --git a/tests/src/core/ConverterTests.cpp b/tests/src/core/ConverterTests.cpp deleted file mode 100644 index 828b1fab9..000000000 --- a/tests/src/core/ConverterTests.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include - -#include "fintamath/core/Converter.hpp" - -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -TEST(ConverterTests, convertTest) { - EXPECT_TRUE(is(convert(Integer(), Integer()))); - - EXPECT_TRUE(is(convert(Rational(), Rational()))); - EXPECT_TRUE(is(convert(Rational(), Integer()))); - EXPECT_FALSE(convert(Integer(), Rational())); - - EXPECT_TRUE(is(convert(Real(), Real()))); - EXPECT_TRUE(is(convert(Real(), Integer()))); - EXPECT_FALSE(convert(Integer(), Real())); - EXPECT_TRUE(is(convert(Real(), Rational()))); - EXPECT_FALSE(convert(Rational(), Real())); - - EXPECT_TRUE(is(convert(Complex(), Complex()))); - EXPECT_TRUE(is(convert(Complex(), Integer()))); - EXPECT_FALSE(convert(Integer(), Complex())); - EXPECT_TRUE(is(convert(Complex(), Rational()))); - EXPECT_FALSE(convert(Rational(), Complex())); - EXPECT_TRUE(is(convert(Complex(), Real()))); - EXPECT_FALSE(convert(Real(), Complex())); -} - -TEST(ConverterTests, convertTemplateTest) { - EXPECT_TRUE(is(convert(Integer()))); - - EXPECT_TRUE(is(convert(Rational()))); - EXPECT_TRUE(is(convert(Integer()))); - EXPECT_FALSE(convert(Rational())); - - EXPECT_TRUE(is(convert(Real()))); - EXPECT_TRUE(is(convert(Integer()))); - EXPECT_FALSE(convert(Real())); - EXPECT_TRUE(is(convert(Rational()))); - EXPECT_FALSE(convert(Real())); - - EXPECT_TRUE(is(convert(Complex()))); - EXPECT_TRUE(is(convert(Integer()))); - EXPECT_FALSE(convert(Complex())); - EXPECT_TRUE(is(convert(Rational()))); - EXPECT_FALSE(convert(Complex())); - EXPECT_TRUE(is(convert(Real()))); - EXPECT_FALSE(convert(Complex())); -} - -TEST(ConverterTests, isConvertibleTest) { - EXPECT_TRUE(isConvertible(Rational(), Rational())); - EXPECT_TRUE(isConvertible(Rational(), Integer())); - EXPECT_FALSE(isConvertible(Integer(), Rational())); -} - -TEST(ConverterTests, isConvertibleTemplateTest) { - EXPECT_TRUE(isConvertible(Rational())); - EXPECT_TRUE(isConvertible(Integer())); - EXPECT_FALSE(isConvertible(Rational())); -} diff --git a/tests/src/core/CoreUtilsTests.cpp b/tests/src/core/CoreUtilsTests.cpp deleted file mode 100644 index 32abc5e91..000000000 --- a/tests/src/core/CoreUtilsTests.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include - -#include "fintamath/core/CoreUtils.hpp" - -// Nothing to test yet diff --git a/tests/src/core/IArithmeticTests.cpp b/tests/src/core/IArithmeticTests.cpp deleted file mode 100644 index 7f7b948ca..000000000 --- a/tests/src/core/IArithmeticTests.cpp +++ /dev/null @@ -1,211 +0,0 @@ -#include - -#include "fintamath/core/IArithmetic.hpp" - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -namespace { - -class TestArithmetic final : public IArithmeticCRTP { - FINTAMATH_CLASS_BODY(TestArithmetic) - -protected: - TestArithmetic &add(const TestArithmetic & /* rhs */) override { - return *this; - } - - TestArithmetic &substract(const TestArithmetic & /* rhs */) override { - return *this; - } - - TestArithmetic &multiply(const TestArithmetic & /* rhs */) override { - return *this; - } - - TestArithmetic ÷(const TestArithmetic & /* rhs */) override { - return *this; - } - - TestArithmetic &negate() override { - return *this; - } -}; - -[[maybe_unused]] const auto config = [] { - IArithmetic::registerType(); - return 0; -}(); - -} - -TEST(IArithmeticTests, parseTest) { - EXPECT_TRUE(is(*IArithmetic::parseFirst("TestArithmetic"))); -} - -TEST(IArithmeticTests, addTest) { - std::unique_ptr m1 = std::make_unique(1); - std::unique_ptr m2 = std::make_unique(2); - std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_EQ((*m1 + *m1)->toString(), "2"); - EXPECT_EQ((*m2 + *m2)->toString(), "4"); - EXPECT_EQ((*m1 + *m2)->toString(), "3"); - EXPECT_EQ((*m2 + *m1)->toString(), "3"); - - EXPECT_EQ((*m1 + *m3)->toString(), "3/2"); - EXPECT_EQ((*m2 + *m3)->toString(), "5/2"); - EXPECT_EQ((*m3 + *m1)->toString(), "3/2"); - EXPECT_EQ((*m3 + *m2)->toString(), "5/2"); - EXPECT_EQ((*m3 + *m3)->toString(), "1"); - - EXPECT_TRUE(is(*m1 + *m1)); - EXPECT_TRUE(is(*m2 + *m2)); - EXPECT_TRUE(is(*m1 + *m2)); - EXPECT_TRUE(is(*m2 + *m1)); - - EXPECT_TRUE(is(*m1 + *m3)); - EXPECT_TRUE(is(*m2 + *m3)); - EXPECT_TRUE(is(*m3 + *m1)); - EXPECT_TRUE(is(*m3 + *m2)); - EXPECT_TRUE(is(*m3 + *m3)); - - EXPECT_THROW(*m1 + TestArithmetic(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestArithmetic() + *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a += 3).toString(), "3"); - EXPECT_EQ((Rational() + 1).toString(), "1"); - EXPECT_EQ((-1 + Rational()).toString(), "-1"); -} - -TEST(IArithmeticTests, subTest) { - std::unique_ptr m1 = std::make_unique(1); - std::unique_ptr m2 = std::make_unique(2); - std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_EQ((*m1 - *m1)->toString(), "0"); - EXPECT_EQ((*m2 - *m2)->toString(), "0"); - EXPECT_EQ((*m1 - *m2)->toString(), "-1"); - EXPECT_EQ((*m2 - *m1)->toString(), "1"); - - EXPECT_EQ((*m1 - *m3)->toString(), "1/2"); - EXPECT_EQ((*m2 - *m3)->toString(), "3/2"); - EXPECT_EQ((*m3 - *m1)->toString(), "-1/2"); - EXPECT_EQ((*m3 - *m2)->toString(), "-3/2"); - EXPECT_EQ((*m3 - *m3)->toString(), "0"); - - EXPECT_TRUE(is(*m1 - *m1)); - EXPECT_TRUE(is(*m2 - *m2)); - EXPECT_TRUE(is(*m1 - *m2)); - EXPECT_TRUE(is(*m2 - *m1)); - - EXPECT_TRUE(is(*m1 - *m3)); - EXPECT_TRUE(is(*m2 - *m3)); - EXPECT_TRUE(is(*m3 - *m1)); - EXPECT_TRUE(is(*m3 - *m2)); - EXPECT_TRUE(is(*m3 - *m3)); - - EXPECT_THROW(*m1 - TestArithmetic(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestArithmetic() - *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a -= 3).toString(), "-3"); - EXPECT_EQ((Integer() - 1).toString(), "-1"); - EXPECT_EQ((-1 - Integer()).toString(), "-1"); -} - -TEST(IArithmeticTests, mulTest) { - std::unique_ptr m1 = std::make_unique(1); - std::unique_ptr m2 = std::make_unique(2); - std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_EQ((*m1 * *m1)->toString(), "1"); - EXPECT_EQ((*m2 * *m2)->toString(), "4"); - EXPECT_EQ((*m1 * *m2)->toString(), "2"); - EXPECT_EQ((*m2 * *m1)->toString(), "2"); - - EXPECT_EQ((*m1 * *m3)->toString(), "1/2"); - EXPECT_EQ((*m2 * *m3)->toString(), "1"); - EXPECT_EQ((*m3 * *m1)->toString(), "1/2"); - EXPECT_EQ((*m3 * *m2)->toString(), "1"); - EXPECT_EQ((*m3 * *m3)->toString(), "1/4"); - - EXPECT_TRUE(is(*m1 * *m1)); - EXPECT_TRUE(is(*m2 * *m2)); - EXPECT_TRUE(is(*m1 * *m2)); - EXPECT_TRUE(is(*m2 * *m1)); - - EXPECT_TRUE(is(*m1 * *m3)); - EXPECT_TRUE(is(*m2 * *m3)); - EXPECT_TRUE(is(*m3 * *m1)); - EXPECT_TRUE(is(*m3 * *m2)); - EXPECT_TRUE(is(*m3 * *m3)); - - EXPECT_THROW(*m1 * TestArithmetic(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestArithmetic() * *m1, InvalidInputBinaryOperatorException); - - Integer a = 2; - EXPECT_EQ((a *= 3).toString(), "6"); - EXPECT_EQ((Integer(2) * 2).toString(), "4"); - EXPECT_EQ((-2 * Integer(2)).toString(), "-4"); -} - -TEST(IArithmeticTests, divTest) { - std::unique_ptr m1 = std::make_unique(1); - std::unique_ptr m2 = std::make_unique(2); - std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_EQ((*m1 / *m1)->toString(), "1"); - EXPECT_EQ((*m2 / *m2)->toString(), "1"); - EXPECT_EQ((*m1 / *m2)->toString(), "1/2"); - EXPECT_EQ((*m2 / *m1)->toString(), "2"); - - EXPECT_EQ((*m1 / *m3)->toString(), "2"); - EXPECT_EQ((*m2 / *m3)->toString(), "4"); - EXPECT_EQ((*m3 / *m1)->toString(), "1/2"); - EXPECT_EQ((*m3 / *m2)->toString(), "1/4"); - EXPECT_EQ((*m3 / *m3)->toString(), "1"); - - EXPECT_TRUE(is(*m1 / *m1)); - EXPECT_TRUE(is(*m2 / *m2)); - EXPECT_TRUE(is(*m1 / *m2)); - EXPECT_TRUE(is(*m2 / *m1)); - - EXPECT_TRUE(is(*m1 / *m3)); - EXPECT_TRUE(is(*m2 / *m3)); - EXPECT_TRUE(is(*m3 / *m1)); - EXPECT_TRUE(is(*m3 / *m2)); - EXPECT_TRUE(is(*m3 / *m3)); - - EXPECT_THROW(*m1 / TestArithmetic(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestArithmetic() / *m1, InvalidInputBinaryOperatorException); - - Integer a = 4; - EXPECT_EQ((a /= 2).toString(), "2"); - EXPECT_EQ((Integer(4) / 2).toString(), "2"); - EXPECT_EQ((-2 / Integer(2)).toString(), "-1"); -} - -TEST(IArithmeticTests, unaryPlusTest) { - const std::unique_ptr m1 = std::make_unique(1); - EXPECT_EQ((+*m1)->toString(), "1"); - - EXPECT_EQ((+Integer(1)).toString(), "1"); -} - -TEST(IArithmeticTests, negateTest) { - const std::unique_ptr m1 = std::make_unique(1); - EXPECT_EQ((-*m1)->toString(), "-1"); - - EXPECT_EQ((-Integer(1)).toString(), "-1"); -} - -TEST(IArithmeticTests, getClassTest) { - EXPECT_EQ(IArithmetic::getClassStatic(), MathObjectClass("IArithmetic")); - EXPECT_EQ(IArithmetic::getClassStatic().getParent(), IMathObject::getClassStatic()); -} diff --git a/tests/src/core/IComparableTests.cpp b/tests/src/core/IComparableTests.cpp deleted file mode 100644 index c9290aa6f..000000000 --- a/tests/src/core/IComparableTests.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include - -#include "fintamath/core/IComparable.hpp" - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -namespace { - -class TestComparable final : public IComparableCRTP { - FINTAMATH_CLASS_BODY(TestComparable) - -protected: - std::strong_ordering compare(const TestComparable & /* rhs */) const override { - return std::strong_ordering::less; - } - - TestComparable &add(const TestComparable &rhs) override { - return *this; - } - - TestComparable &substract(const TestComparable &rhs) override { - return *this; - } - - TestComparable &multiply(const TestComparable &rhs) override { - return *this; - } - - TestComparable ÷(const TestComparable &rhs) override { - return *this; - } - - TestComparable &negate() override { - return *this; - } -}; - -[[maybe_unused]] const auto config = [] { - IComparable::registerType(); - return 0; -}(); - -} - -TEST(IComparableTests, parseTest) { - EXPECT_TRUE(is(*IComparable::parseFirst("TestComparable"))); -} - -TEST(IComparableTests, lessTest) { - std::unique_ptr m1 = std::make_unique(1); - std::unique_ptr m2 = std::make_unique(2); - std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_FALSE(*m1 < *m1); - EXPECT_FALSE(*m2 < *m2); - EXPECT_TRUE(*m1 < *m2); - EXPECT_FALSE(*m2 < *m1); - - EXPECT_FALSE(*m1 < *m3); - EXPECT_FALSE(*m2 < *m3); - EXPECT_TRUE(*m3 < *m1); - EXPECT_TRUE(*m3 < *m2); - - EXPECT_THROW((void)(*m1 < TestComparable()), InvalidInputBinaryOperatorException); - EXPECT_THROW(void(TestComparable() < *m1), InvalidInputBinaryOperatorException); - - EXPECT_TRUE(Integer() < 1); - EXPECT_TRUE(-1 < Integer()); - - EXPECT_FALSE(Integer() < 0); - EXPECT_FALSE(1 < Integer()); -} - -TEST(IComparableTests, moreTest) { - std::unique_ptr m1 = std::make_unique(1); - std::unique_ptr m2 = std::make_unique(2); - std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_FALSE(*m1 > *m1); - EXPECT_FALSE(*m2 > *m2); - EXPECT_FALSE(*m1 > *m2); - EXPECT_TRUE(*m2 > *m1); - - EXPECT_TRUE(*m1 > *m3); - EXPECT_TRUE(*m2 > *m3); - EXPECT_FALSE(*m3 > *m1); - EXPECT_FALSE(*m3 > *m2); - - EXPECT_THROW(void(*m1 > TestComparable()), InvalidInputBinaryOperatorException); - EXPECT_THROW(void(TestComparable() > *m1), InvalidInputBinaryOperatorException); - - EXPECT_FALSE(Integer() > 1); - EXPECT_FALSE(-1 > Integer()); - - EXPECT_FALSE(Integer() > 0); - EXPECT_TRUE(1 > Integer()); -} - -TEST(IComparableTests, lessEqualsTest) { - std::unique_ptr m1 = std::make_unique(1); - std::unique_ptr m2 = std::make_unique(2); - std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_TRUE(*m1 <= *m1); - EXPECT_TRUE(*m2 <= *m2); - EXPECT_TRUE(*m1 <= *m2); - EXPECT_FALSE(*m2 <= *m1); - - EXPECT_FALSE(*m1 <= *m3); - EXPECT_FALSE(*m2 <= *m3); - EXPECT_TRUE(*m3 <= *m1); - EXPECT_TRUE(*m3 <= *m2); - - EXPECT_THROW(void(*m1 <= TestComparable()), InvalidInputBinaryOperatorException); - EXPECT_THROW(void(TestComparable() <= *m1), InvalidInputBinaryOperatorException); - - EXPECT_TRUE(Integer() <= 1); - EXPECT_TRUE(-1 <= Integer()); - - EXPECT_TRUE(Integer() <= 0); - EXPECT_FALSE(1 <= Integer()); -} - -TEST(IComparableTests, moreEqualsTest) { - std::unique_ptr m1 = std::make_unique(1); - std::unique_ptr m2 = std::make_unique(2); - std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_TRUE(*m1 >= *m1); - EXPECT_TRUE(*m2 >= *m2); - EXPECT_FALSE(*m1 >= *m2); - EXPECT_TRUE(*m2 >= *m1); - - EXPECT_TRUE(*m1 >= *m3); - EXPECT_TRUE(*m2 >= *m3); - EXPECT_FALSE(*m3 >= *m1); - EXPECT_FALSE(*m3 >= *m2); - - EXPECT_THROW(void(*m1 >= TestComparable()), InvalidInputBinaryOperatorException); - EXPECT_THROW(void(TestComparable() >= *m1), InvalidInputBinaryOperatorException); - - EXPECT_FALSE(Integer() >= 1); - EXPECT_FALSE(-1 >= Integer()); - - EXPECT_TRUE(Integer() >= 0); - EXPECT_TRUE(1 >= Integer()); -} - -TEST(IComparableTests, getClassTest) { - EXPECT_EQ(IComparable::getClassStatic(), MathObjectClass("IComparable")); - EXPECT_EQ(IComparable::getClassStatic().getParent(), IArithmetic::getClassStatic()); -} diff --git a/tests/src/core/IMathObjectTests.cpp b/tests/src/core/IMathObjectTests.cpp deleted file mode 100644 index 35d24f007..000000000 --- a/tests/src/core/IMathObjectTests.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include - -#include "fintamath/core/IMathObject.hpp" - -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -namespace { - -class TestMathObject final : public IMathObjectCRTP { - FINTAMATH_CLASS_BODY(TestMathObject) -}; - -[[maybe_unused]] const auto config = [] { - IMathObject::registerType(); - return 0; -}(); - -} - -TEST(IMathObjectTests, parseTest) { - EXPECT_TRUE(is(*IMathObject::parseFirst("TestMathObject"))); -} - -TEST(IMathObjectTests, toStringTest) { - EXPECT_EQ(TestMathObject().toString(), "TestMathObject"); -} - -TEST(IMathObjectTests, cloneTest) { - const std::unique_ptr m1 = std::make_unique(); - const std::unique_ptr m2 = std::make_unique(1); - const std::unique_ptr m3 = m1->clone(); - const std::unique_ptr m4 = Integer(1).clone(); - - EXPECT_EQ(*m3, *m1); - EXPECT_EQ(*m4, *m2); - - EXPECT_NE(*m3, *m2); - EXPECT_NE(*m4, *m1); - - EXPECT_NE(m3, m1); - EXPECT_NE(m4, m2); -} - -TEST(IMathObjectTests, equalsTest) { - std::unique_ptr m1 = std::make_unique(1); - std::unique_ptr m2 = std::make_unique(1); - std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_TRUE(*m1 == *m1); - EXPECT_TRUE(*m2 == *m2); - EXPECT_TRUE(*m1 == *m2); - EXPECT_TRUE(*m2 == *m1); - - EXPECT_FALSE(*m1 == *m3); - EXPECT_FALSE(*m2 == *m3); - EXPECT_FALSE(*m3 == *m1); - EXPECT_FALSE(*m3 == *m2); - - EXPECT_FALSE(*m1 == Variable("a")); - EXPECT_FALSE(Variable("a") == *m1); - - EXPECT_TRUE(Integer() == 0); - EXPECT_TRUE(0 == Integer()); - - EXPECT_FALSE(Integer() == 1); - EXPECT_FALSE(1 == Integer()); - - Integer m4; - EXPECT_TRUE(m4 == m4); -} - -TEST(IMathObjectTests, nequalsTest) { - std::unique_ptr m1 = std::make_unique(1); - std::unique_ptr m2 = std::make_unique(1); - std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_FALSE(*m1 != *m1); - EXPECT_FALSE(*m2 != *m2); - EXPECT_FALSE(*m1 != *m2); - EXPECT_FALSE(*m2 != *m1); - - EXPECT_TRUE(*m1 != *m3); - EXPECT_TRUE(*m2 != *m3); - EXPECT_TRUE(*m3 != *m1); - EXPECT_TRUE(*m3 != *m2); - - EXPECT_TRUE(*m1 != Variable("a")); - EXPECT_TRUE(Variable("a") != *m1); - - EXPECT_FALSE(Integer() != 0); - EXPECT_FALSE(0 != Integer()); - - EXPECT_TRUE(Integer() != 1); - EXPECT_TRUE(1 != Integer()); - - Integer m4; - EXPECT_FALSE(m4 != m4); -} - -TEST(IMathObjectTests, outputTest) { - const std::unique_ptr m1 = std::make_unique(123); - std::stringstream out; - out << *m1; - EXPECT_EQ(out.str(), "123"); -} - -TEST(IMathObjectTests, getClassTest) { - EXPECT_EQ(IMathObject::getClassStatic(), MathObjectClass("IMathObject")); - EXPECT_FALSE(IMathObject::getClassStatic().getParent()); - - EXPECT_EQ(TestMathObject().getClass(), MathObjectClass("TestMathObject")); - EXPECT_EQ(TestMathObject().getClass().getParent(), IMathObject::getClassStatic()); -} diff --git a/tests/src/core/MathObjectClassTests.cpp b/tests/src/core/MathObjectClassTests.cpp deleted file mode 100644 index 0aea487f5..000000000 --- a/tests/src/core/MathObjectClassTests.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include - -#include "fintamath/core/MathObjectBody.hpp" - -using namespace fintamath; -using namespace detail; - -namespace { - -class ISuperParentTest { - FINTAMATH_PARENT_CLASS_BODY(ISuperParentTest) -}; - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(ISuperParentTest) - -class IParentTest1 : public ISuperParentTest { - FINTAMATH_PARENT_CLASS_BODY(IParentTest1) -}; - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IParentTest1) - -class IParentTest2 : public ISuperParentTest { - FINTAMATH_PARENT_CLASS_BODY(IParentTest2) -}; - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IParentTest2) - -class ChildTest1 : public IParentTest1 { - FINTAMATH_CLASS_BODY(ChildTest1) -}; - -class ChildTest2 : public IParentTest1 { - FINTAMATH_CLASS_BODY(ChildTest2) -}; - -class ChildTest3 : public IParentTest2 { - FINTAMATH_CLASS_BODY(ChildTest3) -}; - -class OtherChildTest : public IParentTest2 { - FINTAMATH_CLASS_BODY(OtherChildTest) -}; - -[[maybe_unused]] const auto config = [] { - ISuperParentTest::registerType(); - IParentTest1::registerType(); - IParentTest1::registerType(); - IParentTest2::registerType(); - ISuperParentTest::registerType(); - return 0; -}(); - -} - -TEST(MathObjectClassTests, constructorTest) { - { - constexpr MathObjectClass t("Test"); - EXPECT_EQ(t.getName(), "Test"); - } - { - MathObjectClass t("Test"); - EXPECT_EQ(t.getName(), "Test"); - } -} - -TEST(MathObjectClassTests, equalsTest) { - EXPECT_TRUE(ChildTest1::getClassStatic() == ChildTest1::getClassStatic()); - EXPECT_FALSE(ChildTest1::getClassStatic() == ChildTest2::getClassStatic()); - EXPECT_FALSE(ChildTest2::getClassStatic() == ChildTest1::getClassStatic()); -} - -TEST(MathObjectClassTests, compareTest) { - EXPECT_EQ(ChildTest1::getClassStatic() <=> ChildTest1::getClassStatic(), std::strong_ordering::equal); - EXPECT_EQ(ChildTest1::getClassStatic() <=> ChildTest2::getClassStatic(), std::strong_ordering::less); - EXPECT_EQ(ChildTest2::getClassStatic() <=> ChildTest1::getClassStatic(), std::strong_ordering::greater); -} - -TEST(MathObjectClassTests, getNameTest) { - EXPECT_EQ(ChildTest1::getClassStatic().getName(), "ChildTest1"); -} - -TEST(MathObjectClassTests, getParentTest) { - EXPECT_FALSE(MathObjectClass("Test").getParent()); - - EXPECT_FALSE(ISuperParentTest::getClassStatic().getParent()); - - EXPECT_EQ(IParentTest1::getClassStatic().getParent(), ISuperParentTest::getClassStatic()); - EXPECT_EQ(IParentTest2::getClassStatic().getParent(), ISuperParentTest::getClassStatic()); - - EXPECT_EQ(ChildTest1::getClassStatic().getParent(), IParentTest1::getClassStatic()); - EXPECT_EQ(ChildTest2::getClassStatic().getParent(), IParentTest1::getClassStatic()); - EXPECT_EQ(ChildTest3::getClassStatic().getParent(), IParentTest2::getClassStatic()); -} - -TEST(MathObjectClassTests, getChildrenTest) { - EXPECT_EQ(MathObjectClass("Test").getChildren().size(), 0); - - EXPECT_EQ(ISuperParentTest::getClassStatic().getChildren().size(), 2); - - EXPECT_EQ(IParentTest1::getClassStatic().getChildren().size(), 2); - EXPECT_EQ(IParentTest2::getClassStatic().getChildren().size(), 1); - - EXPECT_EQ(ChildTest1::getClassStatic().getChildren().size(), 0); - EXPECT_EQ(ChildTest2::getClassStatic().getChildren().size(), 0); - EXPECT_EQ(ChildTest3::getClassStatic().getChildren().size(), 0); -} - -TEST(MathObjectClassTests, getChildrenRecursiveTest) { - EXPECT_EQ(MathObjectClass("Test").getChildren(true).size(), 0); - - EXPECT_EQ(ISuperParentTest::getClassStatic().getChildren(true).size(), 5); - - EXPECT_EQ(IParentTest1::getClassStatic().getChildren(true).size(), 2); - EXPECT_EQ(IParentTest2::getClassStatic().getChildren(true).size(), 1); - - EXPECT_EQ(ChildTest1::getClassStatic().getChildren(true).size(), 0); - EXPECT_EQ(ChildTest2::getClassStatic().getChildren(true).size(), 0); - EXPECT_EQ(ChildTest3::getClassStatic().getChildren(true).size(), 0); -} - -TEST(MathObjectClassTests, bindTypesTest) { - EXPECT_FALSE(OtherChildTest::getClassStatic().getParent()); - - MathObjectClass::bindTypes(); - - EXPECT_EQ(OtherChildTest::getClassStatic().getParent(), IParentTest2::getClassStatic()); -} - -TEST(MathObjectClassTests, hashTest) { - EXPECT_EQ(std::hash{}(MathObjectClass("Test")), - std::hash{}("Test")); -} diff --git a/tests/src/core/MathObjectUtilsTests.cpp b/tests/src/core/MathObjectUtilsTests.cpp deleted file mode 100644 index bc4b6223f..000000000 --- a/tests/src/core/MathObjectUtilsTests.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include - -#include "fintamath/core/MathObjectUtils.hpp" - -#include "fintamath/literals/constants/E.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -E c; -Integer i; - -TEST(MathObjectUtilsTests, isTest) { - EXPECT_TRUE(is(i)); - EXPECT_FALSE(is(c)); - - EXPECT_TRUE(is(i.clone().get())); - EXPECT_FALSE(is(E().clone().get())); - EXPECT_FALSE(is(std::unique_ptr().get())); - - EXPECT_TRUE(is(i.clone())); - EXPECT_FALSE(is(E().clone())); - - EXPECT_TRUE(is(std::shared_ptr(i.clone()))); - EXPECT_FALSE(is(std::shared_ptr(E().clone()))); - - EXPECT_TRUE(is(std::const_pointer_cast(std::shared_ptr(i.clone())))); - EXPECT_FALSE(is(std::const_pointer_cast(std::shared_ptr(E().clone())))); - - EXPECT_TRUE(is(std::reference_wrapper(i))); - EXPECT_FALSE(is(std::reference_wrapper(c))); - - EXPECT_TRUE(is(std::reference_wrapper(i))); - EXPECT_FALSE(is(std::reference_wrapper(c))); -} - -TEST(MathObjectUtilsTests, castTest) { - EXPECT_NO_THROW(cast(i)); - EXPECT_THROW(cast(cast(c)), std::bad_cast); - - EXPECT_NO_THROW(cast(Integer(1))); - EXPECT_THROW(cast(cast(E())), std::bad_cast); - - EXPECT_TRUE(cast(i.clone().get())); - EXPECT_FALSE(cast(E().clone().get())); - - EXPECT_TRUE(cast(const_cast(i.clone().get()))); - EXPECT_FALSE(cast(const_cast(E().clone().get()))); - - EXPECT_TRUE(cast(i.clone())); - EXPECT_FALSE(cast(E().clone())); - - EXPECT_TRUE(cast(std::shared_ptr(i.clone()))); - EXPECT_FALSE(cast(std::shared_ptr(E().clone()))); - - EXPECT_TRUE(cast(std::const_pointer_cast(std::shared_ptr(i.clone())))); - EXPECT_FALSE(cast(std::const_pointer_cast(std::shared_ptr(E().clone())))); -} diff --git a/tests/src/core/MultimethodTests.cpp b/tests/src/core/MultimethodTests.cpp deleted file mode 100644 index 98af8f205..000000000 --- a/tests/src/core/MultimethodTests.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -#include "fintamath/core/MultiMethod.hpp" - -using namespace fintamath; - -TEST(MultimethodTests, multimethodTest) { - // TODO: implement -} diff --git a/tests/src/core/ParserTests.cpp b/tests/src/core/ParserTests.cpp deleted file mode 100644 index 50d5ee4e2..000000000 --- a/tests/src/core/ParserTests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include - -#include "fintamath/core/Parser.hpp" - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/functions/IFunction.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/literals/constants/E.hpp" -#include "fintamath/numbers/INumber.hpp" -#include "fintamath/numbers/Integer.hpp" - -using namespace fintamath; - -template -size_t countParseredValues(String &&str) { - size_t count = 0; - - for (const auto &_ : Class::parse(std::forward(str))) { - count++; - } - - return count; -} - -TEST(ParserTests, parseLvalueTest) { - std::string str; - - str = "123"; - EXPECT_EQ(countParseredValues(str), 4); - - str = "+"; - EXPECT_EQ(countParseredValues(str), 2); - - str = "E"; - EXPECT_EQ(countParseredValues(str), 1); - - str = "1+2"; - EXPECT_EQ(countParseredValues(str), 1); - - str = "1*)"; - EXPECT_EQ(countParseredValues(str), 0); -} - -TEST(ParserTests, parseRvalueTest) { - EXPECT_EQ(countParseredValues("123"), 4); - EXPECT_EQ(countParseredValues("+"), 2); - EXPECT_EQ(countParseredValues("E"), 1); - EXPECT_EQ(countParseredValues("1+2"), 1); - EXPECT_EQ(countParseredValues("1*)"), 0); -} - -TEST(ParserTests, parseFirstTest) { - EXPECT_EQ(IMathObject::parseFirst("123").value()->getClass(), Integer::getClassStatic()); - EXPECT_EQ(IMathObject::parseFirst("+").value()->getClass(), Add::getClassStatic()); - EXPECT_EQ(IMathObject::parseFirst("E").value()->getClass(), E::getClassStatic()); - EXPECT_EQ(IMathObject::parseFirst("1+1").value()->getClass(), Expression::getClassStatic()); - EXPECT_FALSE(IMathObject::parseFirst("1*)")); -} - -TEST(ParserTests, registerTypeTest) { - // TODO: implement -} \ No newline at end of file diff --git a/tests/src/core/TokenizerTests.cpp b/tests/src/core/TokenizerTests.cpp deleted file mode 100644 index 9c627dca8..000000000 --- a/tests/src/core/TokenizerTests.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include "fintamath/core/Tokenizer.hpp" - -using namespace fintamath; - -TEST(TokenizerTests, tokenizeTest) { - // TODO: implement -} - -TEST(TokenizerTests, registerTokenTest) { - // TODO: implement -} diff --git a/tests/src/exceptions/ExceptionTests.cpp b/tests/src/exceptions/ExceptionTests.cpp deleted file mode 100644 index 45a99b1df..000000000 --- a/tests/src/exceptions/ExceptionTests.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/Exception.hpp" - -using namespace fintamath; - -TEST(ExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw Exception(); }, - testing::ThrowsMessage( - testing::StrEq("Something went wrong..."))); -} diff --git a/tests/src/exceptions/InvalidInputBinaryOperatorExceptionTests.cpp b/tests/src/exceptions/InvalidInputBinaryOperatorExceptionTests.cpp deleted file mode 100644 index 0cc84d94f..000000000 --- a/tests/src/exceptions/InvalidInputBinaryOperatorExceptionTests.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" - -using namespace fintamath; - -TEST(InvalidInputBinaryOpearatorExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw InvalidInputBinaryOperatorException("^", "a", "0"); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: (a)^(0)"))); -} diff --git a/tests/src/exceptions/InvalidInputExceptionTests.cpp b/tests/src/exceptions/InvalidInputExceptionTests.cpp deleted file mode 100644 index aca858578..000000000 --- a/tests/src/exceptions/InvalidInputExceptionTests.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" - -using namespace fintamath; - -TEST(InvalidInputExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw InvalidInputException(); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input"))); - EXPECT_THAT( - [] { throw InvalidInputException("123"); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: 123"))); -} \ No newline at end of file diff --git a/tests/src/exceptions/InvalidInputFunctionExceptionTests.cpp b/tests/src/exceptions/InvalidInputFunctionExceptionTests.cpp deleted file mode 100644 index 65416c397..000000000 --- a/tests/src/exceptions/InvalidInputFunctionExceptionTests.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" - -using namespace fintamath; - -TEST(InvalidInputFunctionExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw InvalidInputFunctionException("f", {}); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: f()"))); - EXPECT_THAT( - [] { throw InvalidInputFunctionException("sqrt", {"-10", "a", "b"}); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: sqrt(-10,a,b)"))); -} diff --git a/tests/src/exceptions/InvalidInputUnaryOperatorExceptionTests.cpp b/tests/src/exceptions/InvalidInputUnaryOperatorExceptionTests.cpp deleted file mode 100644 index 2c1403984..000000000 --- a/tests/src/exceptions/InvalidInputUnaryOperatorExceptionTests.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" - -using namespace fintamath; - -TEST(InvalidInputUnaryOpearatorExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw InvalidInputUnaryOperatorException("!", "-10", InvalidInputUnaryOperatorException::Type::Prefix); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: !(-10)"))); - EXPECT_THAT( - [] { throw InvalidInputUnaryOperatorException("!", "-10", InvalidInputUnaryOperatorException::Type::Postfix); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: (-10)!"))); -} diff --git a/tests/src/exceptions/UndefinedBinaryOperatorExceptionTests.cpp b/tests/src/exceptions/UndefinedBinaryOperatorExceptionTests.cpp deleted file mode 100644 index bd751dc64..000000000 --- a/tests/src/exceptions/UndefinedBinaryOperatorExceptionTests.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/UndefinedException.hpp" - -using namespace fintamath; - -TEST(UndefinedBinaryOpearatorExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw UndefinedBinaryOperatorException("^", "a", "0"); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: (a)^(0)"))); -} diff --git a/tests/src/exceptions/UndefinedExceptionTests.cpp b/tests/src/exceptions/UndefinedExceptionTests.cpp deleted file mode 100644 index 59bd52967..000000000 --- a/tests/src/exceptions/UndefinedExceptionTests.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/UndefinedException.hpp" - -using namespace fintamath; - -TEST(UndefinedExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw UndefinedException(); }, - testing::ThrowsMessage( - testing::StrEq("Undefined"))); - EXPECT_THAT( - [] { throw UndefinedException("123"); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: 123"))); -} \ No newline at end of file diff --git a/tests/src/exceptions/UndefinedFunctionExceptionTests.cpp b/tests/src/exceptions/UndefinedFunctionExceptionTests.cpp deleted file mode 100644 index 101edc757..000000000 --- a/tests/src/exceptions/UndefinedFunctionExceptionTests.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/UndefinedException.hpp" - -using namespace fintamath; - -TEST(UndefinedFunctionExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw UndefinedFunctionException("f", {}); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: f()"))); - EXPECT_THAT( - [] { throw UndefinedFunctionException("sqrt", {"-10", "a", "b"}); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: sqrt(-10,a,b)"))); -} diff --git a/tests/src/exceptions/UndefinedUnaryOperatorExceptionTests.cpp b/tests/src/exceptions/UndefinedUnaryOperatorExceptionTests.cpp deleted file mode 100644 index 297f3e5e7..000000000 --- a/tests/src/exceptions/UndefinedUnaryOperatorExceptionTests.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/UndefinedException.hpp" - -using namespace fintamath; - -TEST(UndefinedUnaryOpearatorExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw UndefinedUnaryOperatorException("!", "-10", UndefinedUnaryOperatorException::Type::Prefix); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: !(-10)"))); - EXPECT_THAT( - [] { throw UndefinedUnaryOperatorException("!", "-10", UndefinedUnaryOperatorException::Type::Postfix); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: (-10)!"))); -} diff --git a/tests/src/expressions/ExpressionComparatorTests.cpp b/tests/src/expressions/ExpressionComparatorTests.cpp deleted file mode 100644 index a018920c1..000000000 --- a/tests/src/expressions/ExpressionComparatorTests.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionComparator.hpp" - -using namespace fintamath; -using namespace detail; - -TEST(ExpressionComparatorTests, comparatorTest) { - EXPECT_EQ(compare(Variable("a").clone(), Expression("a").clone()), std::strong_ordering::equal); - EXPECT_EQ(compare(Expression("a").clone(), Expression("a").clone()), std::strong_ordering::equal); - EXPECT_EQ(compare(Integer(2).clone(), Expression("2 a").clone()), std::strong_ordering::less); - EXPECT_EQ(compare(Integer(2).clone(), Expression("2 a").clone()), std::strong_ordering::less); - EXPECT_EQ(compare(Variable("a").clone(), Expression("a b").clone()), std::strong_ordering::less); - EXPECT_EQ(compare(Variable("a").clone(), Expression("a + b").clone()), std::strong_ordering::less); - EXPECT_EQ(compare(Expression("a^b").clone(), Expression("a b c").clone()), std::strong_ordering::greater); - EXPECT_EQ(compare(Expression("x^x ln(x)").clone(), Expression("x^x").clone()), std::strong_ordering::greater); - - // TODO: add more tests -} diff --git a/tests/src/expressions/ExpressionFunctionsTests.cpp b/tests/src/expressions/ExpressionFunctionsTests.cpp deleted file mode 100644 index bfd154f17..000000000 --- a/tests/src/expressions/ExpressionFunctionsTests.cpp +++ /dev/null @@ -1,341 +0,0 @@ -#include - -#include "fintamath/expressions/ExpressionFunctions.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/constants/E.hpp" - -using namespace fintamath; - -TEST(ExpressionFunctionsTests, addTest) { - EXPECT_EQ((Variable("a") + Variable("a")).toString(), "2 a"); - EXPECT_EQ((Variable("a") + Variable("b")).toString(), "a + b"); - EXPECT_EQ((Variable("a") + -1 + Expression("b^2")).toString(), "a + b^2 - 1"); - EXPECT_EQ((10 + Expression("a+2")).toString(), "a + 12"); - EXPECT_EQ((Variable("a") + Expression("a+2")).toString(), "2 a + 2"); - EXPECT_EQ((Expression("b+2") + Expression("a+2")).toString(), "a + b + 4"); - EXPECT_EQ((Expression("10+a^3") + Expression("a^2")).toString(), "a^3 + a^2 + 10"); - EXPECT_EQ((Expression("a*b") + Expression("b*a")).toString(), "2 a b"); - EXPECT_EQ((Expression("a+b") + Expression("a+b")).toString(), "2 a + 2 b"); -} - -TEST(ExpressionFunctionsTests, unaryPlusTest) { - EXPECT_EQ((+Variable("a")).toString(), "a"); - EXPECT_EQ((+Expression("a")).toString(), "a"); - EXPECT_EQ((+Expression("a+3")).toString(), "a + 3"); - EXPECT_EQ((+Expression("(a+b)^2")).toString(), "a^2 + 2 a b + b^2"); -} - -TEST(ExpressionFunctionsTests, subTest) { - EXPECT_EQ((Variable("a") - Variable("a")).toString(), "0"); - EXPECT_EQ((Variable("a") - Variable("b")).toString(), "a - b"); - EXPECT_EQ((Variable("a") - Expression("b^2")).toString(), "a - b^2"); - EXPECT_EQ((10 - Expression("a+2")).toString(), "-a + 8"); - EXPECT_EQ((Variable("a") - Expression("a+2")).toString(), "-2"); - EXPECT_EQ((Expression("b+2") - Expression("a+2")).toString(), "-a + b"); - EXPECT_EQ((Expression("10+a^3") - Expression("a^2")).toString(), "a^3 - a^2 + 10"); - EXPECT_EQ((Expression("a*b") - Expression("b*a")).toString(), "0"); - EXPECT_EQ((Expression("a+b") - Expression("a+b")).toString(), "0"); -} - -TEST(ExpressionFunctionsTests, negTest) { - EXPECT_EQ((-Variable("a")).toString(), "-a"); - EXPECT_EQ((-Expression("a")).toString(), "-a"); - EXPECT_EQ((-Expression("a+3")).toString(), "-a - 3"); - EXPECT_EQ((-Expression("(a+b)^2")).toString(), "-a^2 - 2 a b - b^2"); -} - -TEST(ExpressionFunctionsTests, mulTest) { - EXPECT_EQ((Variable("a") * Variable("a")).toString(), "a^2"); - EXPECT_EQ((Variable("a") * Variable("b")).toString(), "a b"); - EXPECT_EQ((Variable("a") * -1 * Expression("a*2")).toString(), "-2 a^2"); - EXPECT_EQ((10 * Expression("a+2")).toString(), "10 a + 20"); - EXPECT_EQ((Variable("a") * Expression("a^3+a^2")).toString(), "a^4 + a^3"); - EXPECT_EQ((5 * Expression("a+3") * Expression("a+2")).toString(), "5 a^2 + 25 a + 30"); - EXPECT_EQ((Expression("a+b") * Expression("3 b + c")).toString(), "3 a b + a c + 3 b^2 + b c"); -} - -TEST(ExpressionFunctionsTests, divTest) { - EXPECT_EQ((Variable("a") / Variable("a")).toString(), "1"); - EXPECT_EQ((Variable("a") / Variable("b")).toString(), "a/b"); - EXPECT_EQ((Variable("a") / Expression("b^2")).toString(), "a/(b^2)"); - EXPECT_EQ((10 / Expression("a+2")).toString(), "10/(a + 2)"); - EXPECT_EQ((Variable("a") / Expression("a+2")).toString(), "1 - 2/(a + 2)"); - EXPECT_EQ((Expression("b+2") / Expression("a+2")).toString(), "(b + 2)/(a + 2)"); - EXPECT_EQ((Expression("10+a^3") / Expression("a^2")).toString(), "a + 10/(a^2)"); - EXPECT_EQ((Expression("a*b") / Expression("b*a")).toString(), "1"); - EXPECT_EQ((Expression("a+b") / Expression("a+b")).toString(), "1"); -} - -TEST(ExpressionFunctionsTests, eqvTest) { - EXPECT_EQ(eqv(Expression("a+3"), Expression("3+a")).toString(), "True"); - EXPECT_EQ(eqv(Expression("a^2"), Expression("a*a+0")).toString(), "True"); - EXPECT_EQ(eqv(Expression("a^2"), Expression("a")).toString(), "a^2 - a = 0"); -} - -TEST(ExpressionFunctionsTests, neqvTest) { - EXPECT_EQ(neqv(Expression("a+3"), Expression("3+a")).toString(), "False"); - EXPECT_EQ(neqv(Expression("a^2"), Expression("a*a+0")).toString(), "False"); - EXPECT_EQ(neqv(Expression("a^2"), Expression("a")).toString(), "a^2 - a != 0"); -} - -TEST(ExpressionFunctionsTests, lessTest) { - EXPECT_EQ(less(Expression("a+3"), Expression("3+a")).toString(), "False"); - EXPECT_EQ(less(Expression("a^2"), Expression("a*a+0")).toString(), "False"); - EXPECT_EQ(less(Expression("a^2"), Expression("a")).toString(), "a^2 - a < 0"); -} - -TEST(ExpressionFunctionsTests, moreTest) { - EXPECT_EQ(more(Expression("a+3"), Expression("3+a")).toString(), "False"); - EXPECT_EQ(more(Expression("a^2"), Expression("a*a+0")).toString(), "False"); - EXPECT_EQ(more(Expression("a^2"), Expression("a")).toString(), "a^2 - a > 0"); -} - -TEST(ExpressionFunctionsTests, lessEqvTest) { - EXPECT_EQ(lessEqv(Expression("a+3"), Expression("3+a")).toString(), "True"); - EXPECT_EQ(lessEqv(Expression("a^2"), Expression("a*a+0")).toString(), "True"); - EXPECT_EQ(lessEqv(Expression("a^2"), Expression("a")).toString(), "a^2 - a <= 0"); -} - -TEST(ExpressionFunctionsTests, moreEqvTest) { - EXPECT_EQ(moreEqv(Expression("a+3"), Expression("3+a")).toString(), "True"); - EXPECT_EQ(moreEqv(Expression("a^2"), Expression("a*a+0")).toString(), "True"); - EXPECT_EQ(moreEqv(Expression("a^2"), Expression("a")).toString(), "a^2 - a >= 0"); -} - -TEST(ExpressionFunctionsTests, modTest) { - EXPECT_EQ(mod(Variable("a"), Expression("b^2")).toString(), "a mod (b^2)"); - EXPECT_EQ(mod(10, Expression("a+2")).toString(), "10 mod (a + 2)"); - EXPECT_EQ(mod(Expression("5/2"), Expression("3")).toString(), "(5/2) mod 3"); - EXPECT_EQ(mod(Expression("5"), Expression("3")).toString(), "2"); -} - -TEST(ExpressionFunctionsTests, floorTest) { - EXPECT_EQ(floor(Expression("a+3")).toString(), "floor(a + 3)"); - EXPECT_EQ(floor(Expression("a^4")).toString(), "floor(a^4)"); - EXPECT_EQ(floor(Expression("-333")).toString(), "-333"); - EXPECT_EQ(floor(Expression("2/3")).toString(), "0"); - EXPECT_EQ(floor(Expression("-2/3")).toString(), "-1"); -} - -TEST(ExpressionFunctionsTests, ceilTest) { - EXPECT_EQ(ceil(Expression("a+3")).toString(), "ceil(a + 3)"); - EXPECT_EQ(ceil(Expression("a^4")).toString(), "ceil(a^4)"); - EXPECT_EQ(ceil(Expression("-333")).toString(), "-333"); - EXPECT_EQ(ceil(Expression("2/3")).toString(), "1"); - EXPECT_EQ(ceil(Expression("-2/3")).toString(), "0"); -} - -TEST(ExpressionFunctionsTests, absTest) { - EXPECT_EQ(abs(Expression("a+3")).toString(), "abs(a + 3)"); - EXPECT_EQ(abs(Expression("a^4")).toString(), "abs(a^4)"); - EXPECT_EQ(abs(Expression("-333")).toString(), "333"); -} - -TEST(ExpressionFunctionsTests, factorialTest) { - EXPECT_EQ(factorial(Expression("a+3")).toString(), "(a + 3)!"); - EXPECT_EQ(factorial(Expression("a*3")).toString(), "(3 a)!"); - EXPECT_EQ(factorial(Expression("5")).toString(), "120"); -} - -TEST(ExpressionFunctionsTests, sqrtTest) { - EXPECT_EQ(sqrt(Expression("4")).toString(), "2"); - EXPECT_EQ(sqrt(Expression("5")).toString(), "sqrt(5)"); - EXPECT_EQ(sqrt(Expression("a^4")).toString(), "sqrt(a^4)"); - EXPECT_EQ(sqrt(Expression("a^2*b*b")).toString(), "sqrt(a^2 b^2)"); - EXPECT_EQ(sqrt(Expression("a^2+b^2+2*a*b")).toString(), "sqrt(a^2 + 2 a b + b^2)"); -} - -TEST(ExpressionFunctionsTests, powTest) { - EXPECT_EQ(pow(Expression("a+b"), Expression("0")).toString(), "1"); - EXPECT_EQ(pow(Expression("a^4"), Expression("a")).toString(), "(a^4)^a"); - EXPECT_EQ(pow(Expression("a^4"), Expression("2")).toString(), "a^8"); - EXPECT_EQ(pow(Expression("a*b"), Expression("a+3")).toString(), "(a b)^(a + 3)"); - EXPECT_EQ(pow(Expression("a+2"), Expression("2")).toString(), "a^2 + 4 a + 4"); -} - -TEST(ExpressionFunctionsTests, expTest) { - EXPECT_EQ(exp(Expression("a^4")).toString(), "E^(a^4)"); - EXPECT_EQ(exp(Expression("2")).toString(), "E^2"); - EXPECT_EQ(exp(Expression("0")).toString(), "1"); - EXPECT_EQ(exp(Expression("ln(5)")).toString(), "E^ln(5)"); -} - -TEST(ExpressionFunctionsTests, logTest) { - EXPECT_EQ(log(Expression("a+b"), Expression("1")).toString(), "0"); - EXPECT_EQ(log(Expression("2*a"), Expression("a+b")).toString(), "log(2 a, a + b)"); - EXPECT_EQ(log(Expression("a"), Expression("a^5")).toString(), "5"); -} - -TEST(ExpressionFunctionsTests, lnTest) { - EXPECT_EQ(ln(Expression("E*E")).toString(), "2"); - EXPECT_EQ(ln(Expression("10")).toString(), "ln(10)"); -} - -TEST(ExpressionFunctionsTests, lbTest) { - EXPECT_EQ(lb(Expression("1024*a")).toString(), "log(2, 1024 a)"); - EXPECT_EQ(lb(Expression("2+a")).toString(), "log(2, a + 2)"); -} - -TEST(ExpressionFunctionsTests, lgTest) { - EXPECT_EQ(lg(Expression("10")).toString(), "1"); - EXPECT_EQ(lg(Expression("E*a")).toString(), "log(10, E a)"); -} - -TEST(ExpressionFunctionsTests, sinTest) { - EXPECT_EQ(sin(Expression("5*Pi")).toString(), "0"); - EXPECT_EQ(sin(Expression("Pi/2")).toString(), "1"); - EXPECT_EQ(sin(Expression("a+b")).toString(), "sin(a + b)"); -} - -TEST(ExpressionFunctionsTests, cosTest) { - EXPECT_EQ(cos(Expression("5*Pi")).toString(), "-1"); - EXPECT_EQ(cos(Expression("3*Pi/2")).toString(), "0"); - EXPECT_EQ(cos(Expression("8*a")).toString(), "cos(8 a)"); -} - -TEST(ExpressionFunctionsTests, tanTest) { - EXPECT_EQ(tan(Expression("0")).toString(), "0"); - EXPECT_EQ(tan(Expression("3*Pi/4")).toString(), "-1"); - EXPECT_EQ(tan(Expression("a^3")).toString(), "tan(a^3)"); -} - -TEST(ExpressionFunctionsTests, cotTest) { - EXPECT_EQ(cot(Expression("Pi/4")).toString(), "1"); - EXPECT_EQ(cot(Expression("Pi/2")).toString(), "0"); - EXPECT_EQ(cot(Expression("a/5")).toString(), "cot(a/5)"); -} - -TEST(ExpressionFunctionsTests, asinTest) { - EXPECT_EQ(asin(Expression("-1")).toString(), "-Pi/2"); - EXPECT_EQ(asin(Expression("0")).toString(), "0"); - EXPECT_EQ(asin(Expression("1")).toString(), "Pi/2"); - EXPECT_EQ(asin(Expression("a+b")).toString(), "asin(a + b)"); -} - -TEST(ExpressionFunctionsTests, acosTest) { - EXPECT_EQ(acos(Expression("-1")).toString(), "Pi"); - EXPECT_EQ(acos(Expression("0")).toString(), "Pi/2"); - EXPECT_EQ(acos(Expression("1")).toString(), "0"); - EXPECT_EQ(acos(Expression("8*a")).toString(), "acos(8 a)"); -} - -TEST(ExpressionFunctionsTests, atanTest) { - EXPECT_EQ(atan(Expression("-1")).toString(), "-Pi/4"); - EXPECT_EQ(atan(Expression("0")).toString(), "0"); - EXPECT_EQ(atan(Expression("1")).toString(), "Pi/4"); - EXPECT_EQ(atan(Expression("a^3")).toString(), "atan(a^3)"); -} - -TEST(ExpressionFunctionsTests, acotTest) { - EXPECT_EQ(acot(Expression("-1")).toString(), "-Pi/4"); - EXPECT_EQ(acot(Expression("0")).toString(), "Pi/2"); - EXPECT_EQ(acot(Expression("1")).toString(), "Pi/4"); - EXPECT_EQ(acot(Expression("a/5")).toString(), "acot(a/5)"); -} - -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, 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(), "(I Pi)/2"); - 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(), "(I Pi)/2"); - EXPECT_EQ(acoth(Expression("0.5")).toString(), "acoth(1/2)"); -} - -TEST(ExpressionFunctionsTests, derivativeTest) { - EXPECT_EQ(derivative(Expression("1"), Expression("a")).toString(), "0"); - EXPECT_EQ(derivative(Expression("a"), Expression("a")).toString(), "1"); - EXPECT_EQ(derivative(Expression("(a+5)"), Expression("a")).toString(), "1"); - EXPECT_EQ(derivative(Expression("sin(a^2)"), Expression("a")).toString(), "2 a cos(a^2)"); - EXPECT_EQ(derivative(Expression("(ln(a)/tan(a))^(1/2)"), Expression("a")).toString(), "-(sqrt(cot(a) ln(a)) csc(a)^2 tan(a))/2 + sqrt(cot(a) ln(a))/(2 a ln(a))"); -} - -TEST(ExpressionFunctionsTests, notTest) { - EXPECT_EQ(notL(Expression("True")).toString(), "False"); - EXPECT_EQ(notL(Expression("False")).toString(), "True"); - EXPECT_EQ(notL(Expression("a")).toString(), "~a"); - EXPECT_EQ(notL(Expression("1=1")).toString(), "False"); -} - -TEST(ExpressionFunctionsTests, andTest) { - EXPECT_EQ(andL(Expression("True"), Expression("True")).toString(), "True"); - EXPECT_EQ(andL(Expression("False"), Expression("True")).toString(), "False"); - EXPECT_EQ(andL(Expression("a"), Expression("b")).toString(), "a & b"); - EXPECT_EQ(andL(Expression("a=a"), Expression("b=b")).toString(), "True"); -} - -TEST(ExpressionFunctionsTests, orTest) { - EXPECT_EQ(orL(Expression("True"), Expression("True")).toString(), "True"); - EXPECT_EQ(orL(Expression("False"), Expression("True")).toString(), "True"); - EXPECT_EQ(orL(Expression("a"), Expression("b")).toString(), "a | b"); - 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, negativeTest) { - EXPECT_THROW(Boolean(true) + Boolean(false), InvalidInputException); - EXPECT_THROW(Add() / Mul(), InvalidInputException); - EXPECT_THROW(sin(Boolean(true)), InvalidInputException); - EXPECT_THROW(eqv(Boolean(true), Boolean(false)), InvalidInputException); - EXPECT_THROW(orL(Integer(1), Integer(2)), InvalidInputException); -} diff --git a/tests/src/expressions/ExpressionParserTests.cpp b/tests/src/expressions/ExpressionParserTests.cpp deleted file mode 100644 index 8957645c3..000000000 --- a/tests/src/expressions/ExpressionParserTests.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include - -#include "fintamath/expressions/ExpressionParser.hpp" - -#include - -using namespace fintamath; - -TEST(ExpressionParserTests, parseExprTest) { - EXPECT_EQ(parseExpr("36/(8-6)3")->toString(), "36/(8 - 6) 3"); - EXPECT_EQ(parseExpr("2%")->toString(), "2/100"); - EXPECT_EQ(parseExpr("2.35%")->toString(), "(47/20)/100"); - EXPECT_EQ(parseExpr("1100*4.76%")->toString(), "1100 (119/25)/100"); - EXPECT_EQ(parseExpr("2.35%%%%")->toString(), "((((47/20)/100)/100)/100)/100"); - EXPECT_EQ(parseExpr("1100*4.76%1100*4.76%")->toString(), "1100 (119/25)/100*1100 (119/25)/100"); - EXPECT_EQ(parseExpr("((((((5)/(8)))/(1)))/(((((((9)/(4)))/(0)))/(5))))")->toString(), "((5/8)/1)/(((9/4)/0)/5)"); - EXPECT_EQ(parseExpr("2%a")->toString(), "2/100 a"); - EXPECT_EQ(parseExpr("2!!!!a!!!")->toString(), "2!!!! a!!!"); - EXPECT_EQ(parseExpr("sin a")->toString(), "sin(a)"); - EXPECT_EQ(parseExpr("s i n a")->toString(), "s i n a"); - EXPECT_EQ(parseExpr("a(2)")->toString(), "a 2"); - EXPECT_EQ(parseExpr("(2)a")->toString(), "2 a"); - EXPECT_EQ(parseExpr("Ea")->toString(), "E a"); - EXPECT_EQ(parseExpr("aE")->toString(), "a E"); - EXPECT_EQ(parseExpr("aEE")->toString(), "a E E"); - EXPECT_EQ(parseExpr("EEa")->toString(), "E E a"); - EXPECT_EQ(parseExpr("x123")->toString(), "x 123"); - EXPECT_EQ(parseExpr("x^y!")->toString(), "(x^y)!"); - EXPECT_EQ(parseExpr("lnE")->toString(), "ln(E)"); - EXPECT_EQ(parseExpr("lncossinE")->toString(), "ln(cos(sin(E)))"); - EXPECT_EQ(parseExpr("ln cos sin a")->toString(), "ln(cos(sin(a)))"); - EXPECT_EQ(parseExpr("log((Pi),(E)^((Pi)))")->toString(), "log(Pi, E^Pi)"); - EXPECT_EQ(parseExpr("lb100")->toString(), "log(2, 100)"); - EXPECT_EQ(parseExpr("log(4/9, 2/3)")->toString(), "log(4/9, 2/3)"); - EXPECT_EQ(parseExpr("60deg")->toString(), "60 Pi/180"); - EXPECT_EQ(parseExpr("adeg")->toString(), "a Pi/180"); -} - -TEST(ExpressionParserTests, parseExprNegativeTest) { - EXPECT_THROW(parseExpr(""), InvalidInputException); - EXPECT_THROW(parseExpr("1+"), InvalidInputException); - EXPECT_THROW(parseExpr("1-"), InvalidInputException); - EXPECT_THROW(parseExpr("1*"), InvalidInputException); - EXPECT_THROW(parseExpr("1/"), InvalidInputException); - EXPECT_THROW(parseExpr("*1"), InvalidInputException); - EXPECT_THROW(parseExpr("/1"), InvalidInputException); - EXPECT_THROW(parseExpr(" + "), InvalidInputException); - EXPECT_THROW(parseExpr("(1+2))"), InvalidInputException); - EXPECT_THROW(parseExpr("5-*3"), InvalidInputException); - EXPECT_THROW(parseExpr("5 3 +"), InvalidInputException); - EXPECT_THROW(parseExpr("2.2.2"), InvalidInputException); - EXPECT_THROW(parseExpr("--"), InvalidInputException); - EXPECT_THROW(parseExpr("."), InvalidInputException); - EXPECT_THROW(parseExpr(","), InvalidInputException); - EXPECT_THROW(parseExpr("/"), InvalidInputException); - EXPECT_THROW(parseExpr(";"), InvalidInputException); - EXPECT_THROW(parseExpr("\'"), InvalidInputException); - EXPECT_THROW(parseExpr("["), InvalidInputException); - EXPECT_THROW(parseExpr("]"), InvalidInputException); - EXPECT_THROW(parseExpr("!"), InvalidInputException); - EXPECT_THROW(parseExpr("@"), InvalidInputException); - EXPECT_THROW(parseExpr("\""), InvalidInputException); - EXPECT_THROW(parseExpr("#"), InvalidInputException); - EXPECT_THROW(parseExpr("â„–"), InvalidInputException); - EXPECT_THROW(parseExpr("%"), InvalidInputException); - EXPECT_THROW(parseExpr(":"), InvalidInputException); - EXPECT_THROW(parseExpr("?"), InvalidInputException); - EXPECT_THROW(parseExpr("*"), InvalidInputException); - EXPECT_THROW(parseExpr("("), InvalidInputException); - EXPECT_THROW(parseExpr(")"), InvalidInputException); - EXPECT_THROW(parseExpr("-"), InvalidInputException); - EXPECT_THROW(parseExpr("+"), InvalidInputException); - EXPECT_THROW(parseExpr("$"), InvalidInputException); - EXPECT_THROW(parseExpr("^"), InvalidInputException); - EXPECT_THROW(parseExpr("&"), InvalidInputException); - EXPECT_THROW(parseExpr("_"), InvalidInputException); - EXPECT_THROW(parseExpr("[1+1]"), InvalidInputException); - EXPECT_THROW(parseExpr("{1}"), InvalidInputException); - EXPECT_THROW(parseExpr(",2"), InvalidInputException); - EXPECT_THROW(parseExpr("2,"), InvalidInputException); - - EXPECT_THROW(parseExpr("(1"), InvalidInputException); - EXPECT_THROW(parseExpr("(((2)"), InvalidInputException); - EXPECT_THROW(parseExpr("(((2))"), InvalidInputException); - EXPECT_THROW(parseExpr("((2)))"), InvalidInputException); - EXPECT_THROW(parseExpr("(2)))"), InvalidInputException); - EXPECT_THROW(parseExpr("(2"), InvalidInputException); - EXPECT_THROW(parseExpr("((2)"), InvalidInputException); - EXPECT_THROW(parseExpr("((2"), InvalidInputException); - EXPECT_THROW(parseExpr("((((2)((2))))"), InvalidInputException); - EXPECT_THROW(parseExpr("(()())"), InvalidInputException); - EXPECT_THROW(parseExpr("((()()))"), InvalidInputException); - EXPECT_THROW(parseExpr("((((()))))"), InvalidInputException); - EXPECT_THROW(parseExpr("(,) + (,)"), InvalidInputException); - - EXPECT_THROW(parseExpr("!2"), InvalidInputException); - EXPECT_THROW(parseExpr("!!2"), InvalidInputException); - EXPECT_THROW(parseExpr("!2!!"), InvalidInputException); - EXPECT_THROW(parseExpr("!(2"), InvalidInputException); - EXPECT_THROW(parseExpr("!(2)"), InvalidInputException); - EXPECT_THROW(parseExpr("2)!"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(2))!"), InvalidInputException); - EXPECT_THROW(parseExpr("!!!!!!"), InvalidInputException); - - EXPECT_THROW(parseExpr("esin()"), InvalidInputException); - EXPECT_THROW(parseExpr("(a+b)*()"), InvalidInputException); - - EXPECT_THROW(parseExpr("sin(2,3)"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(2,3) + 2"), InvalidInputException); - EXPECT_THROW(parseExpr("cos(sin(2,3))"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(,)"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(,2)"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(2,)"), InvalidInputException); - EXPECT_THROW(parseExpr("sin()"), InvalidInputException); - EXPECT_THROW(parseExpr("log(1)"), InvalidInputException); - EXPECT_THROW(parseExpr("log()"), InvalidInputException); - - EXPECT_THROW(parseExpr("(1 = 1) / 2"), InvalidInputException); - EXPECT_THROW(parseExpr("2 + (1 = 2)"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(1 = 1)"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(sin(1 = 1))"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(sin(sin(1 = 1)))"), InvalidInputException); - EXPECT_THROW(parseExpr("True/True"), InvalidInputException); - EXPECT_THROW(parseExpr("((1 == 1)) + ((1 == 2))"), InvalidInputException); - EXPECT_THROW(parseExpr("((1 == 1)) - ((1 == 1))"), InvalidInputException); - EXPECT_THROW(parseExpr("((1 == 1)) / ((1 == 1))"), InvalidInputException); - EXPECT_THROW(parseExpr("(5+5)=(2=5)"), InvalidInputException); - EXPECT_THROW(parseExpr("1+(sin(x)<2)"), InvalidInputException); - EXPECT_THROW(parseExpr("1/(sin(x)<2)"), InvalidInputException); - EXPECT_THROW(parseExpr("1+False"), InvalidInputException); - EXPECT_THROW(parseExpr("False+1"), InvalidInputException); - EXPECT_THROW(parseExpr("1=False"), InvalidInputException); - EXPECT_THROW(parseExpr("False=1"), InvalidInputException); - EXPECT_THROW(parseExpr("1&2"), InvalidInputException); - EXPECT_THROW(parseExpr("x+1&x+2"), InvalidInputException); - EXPECT_THROW(parseExpr("x+1&x"), InvalidInputException); - EXPECT_THROW(parseExpr("x&x+2"), InvalidInputException); - EXPECT_THROW(parseExpr("(x&y)=(y&z)"), InvalidInputException); - EXPECT_THROW(parseExpr("derivative(x=y, x)"), InvalidInputException); - EXPECT_THROW(parseExpr("derivative(x&y,x)"), InvalidInputException); - EXPECT_THROW(parseExpr("derivative(True,a)"), InvalidInputException); - EXPECT_THROW(parseExpr("(a+1)_(a>2)"), InvalidInputException); - EXPECT_THROW(parseExpr("(x+1)_1"), InvalidInputException); - EXPECT_THROW(parseExpr("(x*2)_1"), InvalidInputException); - EXPECT_THROW(parseExpr("(x*2)_((x+2)_x)"), InvalidInputException); - EXPECT_THROW(parseExpr("x^x_1"), InvalidInputException); - EXPECT_THROW(parseExpr("E&a"), InvalidInputException); - EXPECT_THROW(parseExpr("~Inf"), InvalidInputException); - EXPECT_THROW(parseExpr("~Undefined"), InvalidInputException); - EXPECT_THROW(parseExpr("a | Undefined"), InvalidInputException); - - EXPECT_THROW(parseExpr("min()"), InvalidInputException); - EXPECT_THROW(parseExpr("min(True, False)"), InvalidInputException); - EXPECT_THROW(parseExpr("max()"), InvalidInputException); - EXPECT_THROW(parseExpr("max(True, False)"), InvalidInputException); -} diff --git a/tests/src/expressions/ExpressionTests.cpp b/tests/src/expressions/ExpressionTests.cpp deleted file mode 100644 index 0fba33d51..000000000 --- a/tests/src/expressions/ExpressionTests.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -#include - -using namespace fintamath; - -TEST(ExpressionTests, constructorTest) { - EXPECT_EQ(Expression().toString(), "0"); -} - -TEST(ExpressionTests, moveTest) { - auto a = Expression("1+2"); - EXPECT_EQ(a.toString(), "3"); - - auto b = std::move(a); - EXPECT_TRUE(b.toString() == "3" && &a != &b); - - a = std::move(b); - EXPECT_TRUE(a.toString() == "3" && &a != &b); -} - -TEST(ExpressionTests, copyTest) { - const auto a = Expression("1+2"); - const auto b = a; - EXPECT_TRUE(a == b && &a != &b); -} - -TEST(ExpressionTests, stringConstructorTest) { - EXPECT_EQ(Expression("2").toString(), "2"); - EXPECT_EQ(Expression("2 + 2").toString(), "4"); - EXPECT_EQ(Expression(" 2 + 2 ").toString(), "4"); - EXPECT_EQ(Expression("-2 + 3").toString(), "1"); - EXPECT_EQ(Expression("sqrt144").toString(), "12"); -} - -TEST(ExpressionTests, stringConstructorNegativeTest) { - EXPECT_THROW(Expression(""), InvalidInputException); - EXPECT_THROW(Expression("1+"), InvalidInputException); -} - -TEST(ExpressionTests, setChildrenTest) { - Expression expr; - - expr.setChildren({Variable("a").clone()}); - EXPECT_EQ(expr.toString(), "a"); - - expr.setChildren({Expression("a-a").clone()}); - EXPECT_EQ(expr.toString(), "0"); - - EXPECT_THROW(expr.setChildren({Variable("a").clone(), Variable("b").clone()}), InvalidInputException); -} - -TEST(ExpressionTests, getFunctionTest) { - EXPECT_EQ(Expression().getFunction(), nullptr); -} - -TEST(ExpressionTests, getChildrenTest) { - // TODO: implement -} - -TEST(ExpressionTests, setVariablesTest) { - // TODO: implement -} - -TEST(ExpressionTests, setVariableTest) { - Expression a("a+b+c"); - Expression b = a; - Expression c = a; - - a.setVariable(Variable("a"), 1); - a.setVariable(Variable("b"), 2); - a.setVariable(Variable("c"), 3); - EXPECT_EQ(a.toString(), "6"); - - b.setVariable(Variable("d"), 1); - EXPECT_EQ(b.toString(), "a + b + c"); - - c.setVariable(Variable("a"), Expression("ln(b)")); - c.setVariable(Variable("b"), Expression("E")); - c.setVariable(Variable("c"), Expression("(a+b)^2")); - EXPECT_EQ(c.toString(), "a^2 + 2 a b + b^2 + E + 1"); -} - -TEST(ExpressionTests, equalsTest) { - const Expression a; - - EXPECT_EQ(a, a); - EXPECT_EQ(a, Expression()); - EXPECT_EQ(Expression(), a); - EXPECT_EQ(a, cast(Expression())); - EXPECT_EQ(cast(Expression()), a); - EXPECT_NE(a, Variable("a")); - EXPECT_NE(Variable("a"), a); - - // TODO: implement more tests -} - -TEST(ExpressionTests, getClassTest) { - EXPECT_EQ(Expression().getClass(), MathObjectClass("Expression")); - EXPECT_EQ(Expression().getClassStatic().getParent(), IExpression::getClassStatic()); -} diff --git a/tests/src/expressions/ExpressionUtilsTests.cpp b/tests/src/expressions/ExpressionUtilsTests.cpp deleted file mode 100644 index ed30240ee..000000000 --- a/tests/src/expressions/ExpressionUtilsTests.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include - -#include "fintamath/expressions/ExpressionUtils.hpp" - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; -using namespace detail; - -TEST(ExpressionUtilsTests, putInBracketsTest) { - EXPECT_EQ(putInBrackets(""), "()"); - EXPECT_EQ(putInBrackets("a"), "(a)"); - EXPECT_EQ(putInBrackets("ab"), "(ab)"); -} - -TEST(ExpressionUtilsTests, putInSpacesTest) { - EXPECT_EQ(putInSpaces(""), " "); - EXPECT_EQ(putInSpaces("a"), " a "); - EXPECT_EQ(putInSpaces("ab"), " ab "); -} - -TEST(ExpressionUtilsTests, functionToStringTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, binaryOperatorToStringTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, prefixOperatorToStringTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, postfixUnaryOperatorToStringTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, argumentVectorToStringVectorTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, argumentRefVectorToArgumentPtrVector) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, containsIfTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, containsChildTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, containsVariableTest) { - EXPECT_TRUE(containsVariable(Variable("a").clone(), Variable("a"))); - - EXPECT_FALSE(containsVariable(Variable("b").clone(), Variable("a"))); - - EXPECT_FALSE(containsVariable(Integer(1).clone(), Variable("a"))); - - auto expr = std::make_shared("cos(sin(a))"); - EXPECT_TRUE(containsVariable(expr, Variable("a"))); - - expr = std::make_shared("cos(sin(b))"); - EXPECT_FALSE(containsVariable(expr, Variable("a"))); - - expr = std::make_shared("cos(a)"); - EXPECT_TRUE(containsVariable(expr, Variable("a"))); - - expr = std::make_shared("cos(b) + a"); - EXPECT_TRUE(containsVariable(expr, Variable("a"))); - - expr = std::make_shared("cos(b)"); - EXPECT_FALSE(containsVariable(expr, Variable("a"))); - - expr = std::make_shared("10"); - EXPECT_FALSE(containsVariable(expr, Variable("a"))); -} - -TEST(ExpressionUtilsTests, containsVariablesTest) { - EXPECT_TRUE(containsVariable(Variable("a").clone())); - - EXPECT_FALSE(containsVariable(Integer(1).clone())); - - auto expr = std::make_shared("cos(sin(a))"); - EXPECT_TRUE(containsVariable(expr)); - - expr = std::make_shared("cos(sin(b))"); - EXPECT_TRUE(containsVariable(expr)); - - expr = std::make_shared("cos(a)"); - EXPECT_TRUE(containsVariable(expr)); - - expr = std::make_shared("cos(b)"); - EXPECT_TRUE(containsVariable(expr)); - - expr = std::make_shared("cos(2) + a"); - EXPECT_TRUE(containsVariable(expr)); - - expr = std::make_shared("10"); - EXPECT_FALSE(containsVariable(expr)); -} - -TEST(ExpressionUtilsTests, constainsInfinityTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, containsComplexTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, isInfinityTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, isNegatedExpressionTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, isNegativeNumberTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, makePolynomTest) { - // TODO: implement -} - -TEST(ExpressionUtilsTests, negateTest) { - // TODO: implement -} diff --git a/tests/src/expressions/FunctionExpressionTests.cpp b/tests/src/expressions/FunctionExpressionTests.cpp deleted file mode 100644 index b64ced571..000000000 --- a/tests/src/expressions/FunctionExpressionTests.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/functions/arithmetic/Abs.hpp" - -using namespace fintamath; -using namespace detail; - -namespace { - -class TestUnaryFunction final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(TestUnaryFunction) - -public: - std::string toString() const override { - return "testfunction"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override { - return std::make_unique(1); - } -}; - -class TestBinaryFunction final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(TestBinaryFunction) - -public: - std::string toString() const override { - return "testfunction"; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override { - return std::make_unique(1); - } -}; - -class TestBinaryOperator final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(TestBinaryOperator) - -public: - std::string toString() const override { - return "$"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::Exponentiation; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override { - return std::make_unique(1); - } -}; - -class TestUnaryPrefixOperator final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(TestUnaryPrefixOperator) - -public: - std::string toString() const override { - return "$"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::PrefixUnary; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override { - return std::make_unique(1); - } -}; - -class TestUnaryPostfixOperator final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(TestUnaryPostfixOperator) - -public: - std::string toString() const override { - return "$"; - } - - static constexpr Priority getPriorityStatic() { - return Priority::PostfixUnary; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override { - return std::make_unique(1); - } -}; - -[[maybe_unused]] const auto config = [] { - IFunction::registerType(); - IFunction::registerType(); - - IOperator::registerType(); - IOperator::registerType(); - IOperator::registerType(); - - return 0; -}(); - -} - -TEST(FunctionExpressionTests, stringConstructorTest) { - EXPECT_EQ(Expression("a$a").toString(), "a$a"); - EXPECT_EQ(Expression("(a+1)$(b+1)").toString(), "(a + 1)$(b + 1)"); - - EXPECT_EQ(Expression("$a").toString(), "$a"); - EXPECT_EQ(Expression("$(a+1)").toString(), "$(a + 1)"); - EXPECT_EQ(Expression("($a)").toString(), "$a"); - EXPECT_EQ(Expression("($(a+1))").toString(), "$(a + 1)"); - - EXPECT_EQ(Expression("a$").toString(), "a$"); - EXPECT_EQ(Expression("(a+1)$").toString(), "(a + 1)$"); - EXPECT_EQ(Expression("(a$)").toString(), "a$"); - EXPECT_EQ(Expression("((a+1)$)").toString(), "(a + 1)$"); - - EXPECT_EQ(Expression("testfunction(a)").toString(), "testfunction(a)"); - EXPECT_EQ(Expression("testfunction(a+1)").toString(), "testfunction(a + 1)"); - - EXPECT_EQ(Expression("testfunction(a,b)").toString(), "testfunction(a, b)"); - EXPECT_EQ(Expression("testfunction(a+1,b+1)").toString(), "testfunction(a + 1, b + 1)"); -} - -TEST(FunctionExpressionTests, getClassTest) { - auto expr = makeExpr(TestBinaryOperator(), Integer(0), Integer(0)); - EXPECT_EQ(expr->getClass(), MathObjectClass("FunctionExpression")); - EXPECT_EQ(expr->getClass().getParent(), IExpression::getClassStatic()); -} diff --git a/tests/src/expressions/IExpressionTests.cpp b/tests/src/expressions/IExpressionTests.cpp deleted file mode 100644 index 66651c2cf..000000000 --- a/tests/src/expressions/IExpressionTests.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include - -#include "fintamath/expressions/IExpression.hpp" - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/other/Factorial.hpp" -#include "fintamath/functions/trigonometry/Sin.hpp" - -using namespace fintamath; - -namespace { - -class TestExpression final : public IExpressionCRTP { - FINTAMATH_CLASS_BODY(TestExpression) - -public: - const std::shared_ptr &getFunction() const override { - static const std::shared_ptr func = cast(Add().clone()); - return func; - } - - const ArgumentPtrVector &getChildren() const override { - static const ArgumentPtrVector children; - return children; - } - - void setChildren(const ArgumentPtrVector &childVect) override { - } - -protected: - ArgumentPtr simplify() const override { - if (auto res = preSimplify()) { - return res; - } - - if (auto res = postSimplify()) { - return res; - } - - return clone(); - } - - ArgumentPtr approximate() const override { - return clone(); - } -}; - -[[maybe_unused]] const auto config = [] { - IExpression::registerType(); - return 0; -}(); - -} - -TEST(IExpressionTests, parseTest) { - EXPECT_TRUE(is(*IExpression::parseFirst("TestExpression"))); -} - -TEST(IExpressionTests, getFunctionTest) { - // TODO: implement -} - -TEST(IExpressionTests, getFunctionToStringNotationTest) { - // TODO: implement -} - -TEST(IExpressionTests, getChildrenTest) { - // TODO: implement -} - -TEST(IExpressionTests, setChildrenTest) { - const auto expr = cast(factorialExpr(Variable("a"))->clone()); - - expr->setChildren({Variable("b").clone()}); - EXPECT_EQ(expr->toString(), "b!"); - - EXPECT_THROW(expr->setChildren({Variable("b").clone(), Variable("c").clone()}), InvalidInputException); - - // TODO: implement more tests -} - -TEST(IExpressionTests, getVariablesTest) { - const auto expr = cast(Expression("x^2+y^2+a").clone()); - const auto vars = expr->getVariables(); - EXPECT_EQ(vars[0].toString(), "a"); - EXPECT_EQ(vars[1].toString(), "x"); - EXPECT_EQ(vars[2].toString(), "y"); - - // TODO: implement more tests -} - -TEST(IExpressionTests, setVariablesTest) { - // TODO: implement -} - -TEST(IExpressionTests, toMinimalObjectTest) { - const TestExpression a; - EXPECT_EQ(*a.toMinimalObject(), a); - - // TODO: implement more tests -} - -TEST(IExpressionTests, getClassTest) { - EXPECT_EQ(IExpression::getClassStatic(), MathObjectClass("IExpression")); - EXPECT_EQ(IExpression::getClassStatic().getParent(), IMathObject::getClassStatic()); -} diff --git a/tests/src/expressions/binary/CompExprTests.cpp b/tests/src/expressions/binary/CompExprTests.cpp deleted file mode 100644 index 0ef05a2e7..000000000 --- a/tests/src/expressions/binary/CompExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/comparison/Eqv.hpp" - -using namespace fintamath; - -TEST(CompExprTests, getClassTest) { - const auto expr = eqvExpr(Integer(0), Integer(0)); - - EXPECT_EQ(expr->getClass(), MathObjectClass("CompExpr")); - EXPECT_EQ(expr->getClass().getParent(), IBinaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/binary/DerivativeExprTests.cpp b/tests/src/expressions/binary/DerivativeExprTests.cpp deleted file mode 100644 index d5594f7dc..000000000 --- a/tests/src/expressions/binary/DerivativeExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/calculus/Derivative.hpp" - -using namespace fintamath; - -TEST(DerivativeExprTests, getClassTest) { - const auto expr = derivativeExpr(Integer(0), Variable("x")); - - EXPECT_EQ(expr->getClass(), MathObjectClass("DerivativeExpr")); - EXPECT_EQ(expr->getClass().getParent(), IBinaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/binary/DivExprTests.cpp b/tests/src/expressions/binary/DivExprTests.cpp deleted file mode 100644 index 17dd94dba..000000000 --- a/tests/src/expressions/binary/DivExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/arithmetic/Div.hpp" - -using namespace fintamath; - -TEST(DivExprTests, getClassTest) { - const auto expr = divExpr(Integer(0), Integer(0)); - - EXPECT_EQ(expr->getClass(), MathObjectClass("DivExpr")); - EXPECT_EQ(expr->getClass().getParent(), IBinaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/binary/IntegralExprTests.cpp b/tests/src/expressions/binary/IntegralExprTests.cpp deleted file mode 100644 index e2828cd87..000000000 --- a/tests/src/expressions/binary/IntegralExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/calculus/Integral.hpp" - -using namespace fintamath; - -TEST(IntegralExprTests, getClassTest) { - const auto expr = integralExpr(Integer(0), Variable("x")); - - EXPECT_EQ(expr->getClass(), MathObjectClass("IntegralExpr")); - EXPECT_EQ(expr->getClass().getParent(), IBinaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/binary/LogExprTests.cpp b/tests/src/expressions/binary/LogExprTests.cpp deleted file mode 100644 index fb641475a..000000000 --- a/tests/src/expressions/binary/LogExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/logarithms/Log.hpp" - -using namespace fintamath; - -TEST(LogExprTests, getClassTest) { - const auto expr = logExpr(Integer(0), Integer(0)); - - EXPECT_EQ(expr->getClass(), MathObjectClass("LogExpr")); - EXPECT_EQ(expr->getClass().getParent(), IBinaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/binary/PowExprTests.cpp b/tests/src/expressions/binary/PowExprTests.cpp deleted file mode 100644 index 59b1ed296..000000000 --- a/tests/src/expressions/binary/PowExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" -#include "fintamath/functions/powers/Pow.hpp" - -using namespace fintamath; - -TEST(PowExprTests, getClassTest) { - const auto expr = powExpr(Integer(0), Integer(0)); - - EXPECT_EQ(expr->getClass(), MathObjectClass("PowExpr")); - EXPECT_EQ(expr->getClass().getParent(), IBinaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/interfaces/IBinaryExpressionTests.cpp b/tests/src/expressions/interfaces/IBinaryExpressionTests.cpp deleted file mode 100644 index 581d1dc8d..000000000 --- a/tests/src/expressions/interfaces/IBinaryExpressionTests.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include - -#include "fintamath/expressions/interfaces/IBinaryExpression.hpp" - -#include "fintamath/functions/arithmetic/Add.hpp" - -using namespace fintamath; - -const Add f; - -namespace { - -class TestBinaryExpression final : public IBinaryExpressionCRTP { - FINTAMATH_CLASS_BODY(TestBinaryExpression) - -public: - explicit TestBinaryExpression(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild) - : IBinaryExpressionCRTP(f, std::move(inLhsChild), std::move(inRhsChild)) { - } -}; - -[[maybe_unused]] const auto config = [] { - IBinaryExpression::registerType(); - return 0; -}(); - -} - -TEST(IBinaryExpressionTests, parseTest) { - EXPECT_FALSE(IBinaryExpression::parseFirst("1*)")); -} - -TEST(IBinaryExpressionTests, toStringTest) { - const TestBinaryExpression expr(std::make_shared(1), std::make_shared(2)); - EXPECT_EQ(expr.toString(), "1 + 2"); -} - -TEST(IBinaryExpressionTests, getFunctionTest) { - const TestBinaryExpression expr(std::make_shared(1), std::make_shared(2)); - EXPECT_EQ(*expr.getFunction(), f); -} - -TEST(IBinaryExpressionTests, getChildren) { - const TestBinaryExpression expr(std::make_shared(1), std::make_shared(2)); - EXPECT_EQ(expr.getChildren().size(), 2); - EXPECT_EQ(*expr.getChildren().front(), Integer(1)); - EXPECT_EQ(*expr.getChildren().back(), Integer(2)); -} - -TEST(IBinaryExpressionTests, setChildren) { - TestBinaryExpression expr(std::make_shared(1), std::make_shared(2)); - - expr.setChildren({std::make_shared(0), std::make_shared(0)}); - EXPECT_EQ(expr.getChildren().size(), 2); - EXPECT_EQ(*expr.getChildren().front(), Integer(0)); - EXPECT_EQ(*expr.getChildren().back(), Integer(0)); - - EXPECT_THROW(expr.setChildren({}), InvalidInputFunctionException); - EXPECT_THROW(expr.setChildren({std::make_shared(1)}), InvalidInputFunctionException); - EXPECT_THROW( - expr.setChildren({std::make_shared(1), std::make_shared(1), std::make_shared(1)}), - InvalidInputFunctionException); -} - -TEST(IBinaryExpressionTests, toMinimalObjectTest) { - const TestBinaryExpression expr1(std::make_shared(1), std::make_shared(2)); - EXPECT_EQ(expr1.toMinimalObject()->toString(), "3"); - - const TestBinaryExpression expr2(std::make_shared(1), Variable("a").clone()); - EXPECT_EQ(expr2.toMinimalObject()->toString(), "1 + a"); -} - -TEST(IBinaryExpressionTests, getClassTest) { - EXPECT_EQ(IBinaryExpression::getClassStatic(), MathObjectClass("IBinaryExpression")); - EXPECT_EQ(IBinaryExpression::getClassStatic().getParent(), IExpression::getClassStatic()); -} diff --git a/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp b/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp deleted file mode 100644 index 8478c8000..000000000 --- a/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include - -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" - -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" - -using namespace fintamath; - -const Mul f; - -namespace { - -class TestPolynomExpression final : public IPolynomExpressionCRTP { - FINTAMATH_CLASS_BODY(TestPolynomExpression) - -public: - explicit TestPolynomExpression(ArgumentPtrVector args) : IPolynomExpressionCRTP(f, std::move(args)) { - } -}; - -[[maybe_unused]] const auto config = [] { - IPolynomExpression::registerType(); - return 0; -}(); - -} - -TEST(IPolynomExpressionTests, parseTest) { - EXPECT_FALSE(IPolynomExpression::parseFirst("1*)")); -} - -TEST(IPolynomExpressionTests, toStringTest) { - TestPolynomExpression expr({Integer(1).clone(), Integer(2).clone(), Integer(3).clone()}); - EXPECT_EQ(expr.toString(), "1 * 2 * 3"); - - expr = TestPolynomExpression({addExpr(Variable("x"), Variable("y")), Variable("a").clone()}); - EXPECT_EQ(expr.toString(), "(x + y) * a"); -} - -TEST(IPolynomExpressionTests, getFunctionTest) { - const TestPolynomExpression expr({Integer(1).clone(), Integer(2).clone(), Integer(3).clone()}); - EXPECT_EQ(*expr.getFunction(), f); -} - -TEST(IPolynomExpressionTests, getChildren) { - const TestPolynomExpression expr({Integer(1).clone(), Integer(2).clone(), Integer(3).clone()}); - EXPECT_EQ(expr.getChildren().size(), 3); - EXPECT_EQ(*expr.getChildren()[0], Integer(1)); - EXPECT_EQ(*expr.getChildren()[1], Integer(2)); - EXPECT_EQ(*expr.getChildren()[2], Integer(3)); -} - -TEST(IPolynomExpressionTests, setChildren) { - TestPolynomExpression expr({Integer(1).clone(), Integer(2).clone(), Integer(3).clone()}); - - expr.setChildren({Integer(0).clone()}); - EXPECT_EQ(expr.getChildren().size(), 1); - EXPECT_EQ(*expr.getChildren().back(), Integer(0)); - - expr.setChildren({Integer(0).clone(), Integer(0).clone()}); - EXPECT_EQ(expr.getChildren().size(), 2); - EXPECT_EQ(*expr.getChildren().front(), Integer(0)); - EXPECT_EQ(*expr.getChildren().back(), Integer(0)); - - expr.setChildren({Integer(0).clone(), Integer(0).clone(), Integer(0).clone()}); - EXPECT_EQ(expr.getChildren().size(), 3); - EXPECT_EQ(*expr.getChildren()[0], Integer(0)); - EXPECT_EQ(*expr.getChildren()[1], Integer(0)); - EXPECT_EQ(*expr.getChildren()[2], Integer(0)); - - EXPECT_THROW(expr.setChildren({}), InvalidInputFunctionException); -} - -TEST(IPolynomExpressionTests, toMinimalObjectTest) { - const TestPolynomExpression expr({Integer(1).clone(), Integer(2).clone(), Variable("a").clone()}); - EXPECT_EQ(expr.toMinimalObject()->toString(), "a * 2"); -} - -TEST(IPolynomExpressionTests, getClassTest) { - EXPECT_EQ(IPolynomExpression::getClassStatic(), MathObjectClass("IPolynomExpression")); - EXPECT_EQ(IPolynomExpression::getClassStatic().getParent(), IExpression::getClassStatic()); -} diff --git a/tests/src/expressions/interfaces/IUnaryExpressionTests.cpp b/tests/src/expressions/interfaces/IUnaryExpressionTests.cpp deleted file mode 100644 index cafa0c6b3..000000000 --- a/tests/src/expressions/interfaces/IUnaryExpressionTests.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include - -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" - -#include "fintamath/functions/other/Factorial.hpp" - -using namespace fintamath; - -const Factorial f; - -namespace { - -class TestUnaryExpression final : public IUnaryExpressionCRTP { - FINTAMATH_CLASS_BODY(TestUnaryExpression) - -public: - explicit TestUnaryExpression(ArgumentPtr inRhsChild) - : IUnaryExpressionCRTP(f, std::move(inRhsChild)) { - } -}; - -[[maybe_unused]] const auto config = [] { - IUnaryExpression::registerType(); - return 0; -}(); - -} - -TEST(IUnaryExpressionTests, parseTest) { - EXPECT_FALSE(IUnaryExpression::parseFirst("1*)")); -} - -TEST(IUnaryExpressionTests, toStringTest) { - const TestUnaryExpression expr(std::make_shared(1)); - EXPECT_EQ(expr.toString(), "1!"); -} - -TEST(IUnaryExpressionTests, getFunctionTest) { - const TestUnaryExpression expr(std::make_shared(1)); - EXPECT_EQ(*expr.getFunction(), f); -} - -TEST(IUnaryExpressionTests, getChildren) { - const TestUnaryExpression expr(std::make_shared(1)); - EXPECT_EQ(expr.getChildren().size(), 1); - EXPECT_EQ(*expr.getChildren().front(), Integer(1)); -} - -TEST(IUnaryExpressionTests, setChildren) { - TestUnaryExpression expr(std::make_shared(1)); - - expr.setChildren({std::make_shared(0)}); - EXPECT_EQ(expr.getChildren().size(), 1); - EXPECT_EQ(*expr.getChildren().front(), Integer(0)); - - EXPECT_THROW(expr.setChildren({}), InvalidInputFunctionException); - EXPECT_THROW(expr.setChildren({std::make_shared(1), std::make_shared(1)}), - InvalidInputFunctionException); -} - -TEST(IUnaryExpressionTests, toMinimalObjectTest) { - const TestUnaryExpression expr1(Integer(4).clone()); - EXPECT_EQ(expr1.toMinimalObject()->toString(), "24"); - - const TestUnaryExpression expr2(Variable("a").clone()); - EXPECT_EQ(expr2.toMinimalObject()->toString(), "a!"); - - const TestUnaryExpression expr3(TestUnaryExpression(Variable("a").clone()).clone()); - EXPECT_EQ(expr3.toMinimalObject()->toString(), "(a!)!"); -} - -TEST(IUnaryExpressionTests, getClassTest) { - EXPECT_EQ(IUnaryExpression::getClassStatic(), MathObjectClass("IUnaryExpression")); - EXPECT_EQ(IUnaryExpression::getClassStatic().getParent(), IExpression::getClassStatic()); -} diff --git a/tests/src/expressions/polynomial/AddExprTests.cpp b/tests/src/expressions/polynomial/AddExprTests.cpp deleted file mode 100644 index 5d30d03a0..000000000 --- a/tests/src/expressions/polynomial/AddExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" - -using namespace fintamath; - -TEST(AddExprTests, getClassTest) { - const auto expr = addExpr(Integer(0), Integer(0)); - - EXPECT_EQ(expr->getClass(), MathObjectClass("AddExpr")); - EXPECT_EQ(expr->getClass().getParent(), IPolynomExpression::getClassStatic()); -} diff --git a/tests/src/expressions/polynomial/AndExprTests.cpp b/tests/src/expressions/polynomial/AndExprTests.cpp deleted file mode 100644 index a41b50205..000000000 --- a/tests/src/expressions/polynomial/AndExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/logic/And.hpp" - -using namespace fintamath; - -TEST(AndExprTests, getClassTest) { - const auto expr = andExpr(Boolean(), Boolean()); - - EXPECT_EQ(expr->getClass(), MathObjectClass("AndExpr")); - EXPECT_EQ(expr->getClass().getParent(), IPolynomExpression::getClassStatic()); -} diff --git a/tests/src/expressions/polynomial/MinMaxExprTests.cpp b/tests/src/expressions/polynomial/MinMaxExprTests.cpp deleted file mode 100644 index 033722309..000000000 --- a/tests/src/expressions/polynomial/MinMaxExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/calculus/Min.hpp" - -using namespace fintamath; - -TEST(MinMaxExprTests, getClassTest) { - const auto expr = minExpr(Integer(0), Integer(0)); - - EXPECT_EQ(expr->getClass(), MathObjectClass("MinMaxExpr")); - EXPECT_EQ(expr->getClass().getParent(), IPolynomExpression::getClassStatic()); -} diff --git a/tests/src/expressions/polynomial/MulExprTests.cpp b/tests/src/expressions/polynomial/MulExprTests.cpp deleted file mode 100644 index 6f97e33d1..000000000 --- a/tests/src/expressions/polynomial/MulExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" - -using namespace fintamath; - -TEST(MulExprTests, getClassTest) { - const auto expr = mulExpr(Integer(0), Integer(0)); - - EXPECT_EQ(expr->getClass(), MathObjectClass("MulExpr")); - EXPECT_EQ(expr->getClass().getParent(), IPolynomExpression::getClassStatic()); -} diff --git a/tests/src/expressions/polynomial/OrExprTests.cpp b/tests/src/expressions/polynomial/OrExprTests.cpp deleted file mode 100644 index 57fba1558..000000000 --- a/tests/src/expressions/polynomial/OrExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IPolynomExpression.hpp" -#include "fintamath/functions/logic/Or.hpp" - -using namespace fintamath; - -TEST(OrExprTests, getClassTest) { - const auto expr = orExpr(Boolean(), Boolean()); - - EXPECT_EQ(expr->getClass(), MathObjectClass("OrExpr")); - EXPECT_EQ(expr->getClass().getParent(), IPolynomExpression::getClassStatic()); -} diff --git a/tests/src/expressions/unary/AbsExprTests.cpp b/tests/src/expressions/unary/AbsExprTests.cpp deleted file mode 100644 index dd46d577c..000000000 --- a/tests/src/expressions/unary/AbsExprTests.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/arithmetic/Abs.hpp" -#include "fintamath/numbers/Integer.hpp" - -using namespace fintamath; - -TEST(AbsExprTests, getClassTest) { - const auto expr = absExpr(Integer(0).clone()); - - EXPECT_EQ(expr->getClass(), MathObjectClass("AbsExpr")); - EXPECT_EQ(expr->getClass().getParent(), IUnaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/unary/FloorCeilExprTests.cpp b/tests/src/expressions/unary/FloorCeilExprTests.cpp deleted file mode 100644 index 39753ca30..000000000 --- a/tests/src/expressions/unary/FloorCeilExprTests.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/ntheory/Floor.hpp" -#include "fintamath/numbers/Integer.hpp" - -using namespace fintamath; - -TEST(FloorCeilExprTests, getClassTest) { - const auto expr = floorExpr(Integer(0).clone()); - - EXPECT_EQ(expr->getClass(), MathObjectClass("FloorCeilExpr")); - EXPECT_EQ(expr->getClass().getParent(), IUnaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/unary/HyperbExprTests.cpp b/tests/src/expressions/unary/HyperbExprTests.cpp deleted file mode 100644 index f0c19a10f..000000000 --- a/tests/src/expressions/unary/HyperbExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/hyperbolic/Sinh.hpp" - -using namespace fintamath; - -TEST(HyperbExprTests, getClassTest) { - const auto expr = sinhExpr(Integer(0).clone()); - - EXPECT_EQ(expr->getClass(), MathObjectClass("HyperbExpr")); - EXPECT_EQ(expr->getClass().getParent(), IUnaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/unary/InvHyperbExprTests.cpp b/tests/src/expressions/unary/InvHyperbExprTests.cpp deleted file mode 100644 index 668a50b62..000000000 --- a/tests/src/expressions/unary/InvHyperbExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/hyperbolic/Asinh.hpp" - -using namespace fintamath; - -TEST(InvHyperbExprTests, getClassTest) { - const auto expr = asinhExpr(Integer(0).clone()); - - EXPECT_EQ(expr->getClass(), MathObjectClass("InvHyperbExpr")); - EXPECT_EQ(expr->getClass().getParent(), IUnaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/unary/InvTrigExprTests.cpp b/tests/src/expressions/unary/InvTrigExprTests.cpp deleted file mode 100644 index b5513c262..000000000 --- a/tests/src/expressions/unary/InvTrigExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/trigonometry/Asin.hpp" - -using namespace fintamath; - -TEST(InvTrigExprTests, getClassTest) { - const auto expr = asinExpr(Integer(0).clone()); - - EXPECT_EQ(expr->getClass(), MathObjectClass("InvTrigExpr")); - EXPECT_EQ(expr->getClass().getParent(), IUnaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/unary/NotExprTests.cpp b/tests/src/expressions/unary/NotExprTests.cpp deleted file mode 100644 index f4ed5cdf9..000000000 --- a/tests/src/expressions/unary/NotExprTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionUtils.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/logic/Not.hpp" - -using namespace fintamath; - -TEST(NotExprTests, getClassTest) { - const auto expr = notExpr(Boolean()); - - EXPECT_EQ(expr->getClass(), MathObjectClass("NotExpr")); - EXPECT_EQ(expr->getClass().getParent(), IUnaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/unary/SignExprTests.cpp b/tests/src/expressions/unary/SignExprTests.cpp deleted file mode 100644 index 68754079e..000000000 --- a/tests/src/expressions/unary/SignExprTests.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/arithmetic/Sign.hpp" -#include "fintamath/numbers/Integer.hpp" - -using namespace fintamath; - -TEST(SignExprTests, getClassTest) { - const auto expr = signExpr(Integer(0).clone()); - - EXPECT_EQ(expr->getClass(), MathObjectClass("SignExpr")); - EXPECT_EQ(expr->getClass().getParent(), IUnaryExpression::getClassStatic()); -} diff --git a/tests/src/expressions/unary/TrigExprTests.cpp b/tests/src/expressions/unary/TrigExprTests.cpp deleted file mode 100644 index 09bb2734f..000000000 --- a/tests/src/expressions/unary/TrigExprTests.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/interfaces/IUnaryExpression.hpp" -#include "fintamath/functions/trigonometry/Sin.hpp" - -using namespace fintamath; - -TEST(TrigExprTests, getClassTest) { - const auto expr = sinExpr(Integer(0).clone()); - - EXPECT_EQ(expr->getClass(), MathObjectClass("TrigExpr")); - EXPECT_EQ(expr->getClass().getParent(), IUnaryExpression::getClassStatic()); -} diff --git a/tests/src/functions/FunctionUtilsTests.cpp b/tests/src/functions/FunctionUtilsTests.cpp deleted file mode 100644 index 092b761cb..000000000 --- a/tests/src/functions/FunctionUtilsTests.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/functions/IFunction.hpp" - -#include "fintamath/expressions/IExpression.hpp" -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Mul.hpp" -#include "fintamath/functions/powers/Pow.hpp" -#include "fintamath/functions/trigonometry/Cos.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; -using namespace detail; - -TEST(FunctionUtilsTests, makeExpressionPtrsTest) { - ArgumentPtr one = std::make_unique(1); - ArgumentPtr two = std::make_unique(2); - auto expr1 = makeExpr(Add(), {one, two}); - EXPECT_EQ(expr1->toString(), "1 + 2"); - EXPECT_FALSE(is(expr1)); - - ArgumentPtr var = std::make_unique("a"); - ArgumentPtr expr2 = makeExpr(Cos(), {var}); - EXPECT_EQ(expr2->toString(), "cos(a)"); - EXPECT_TRUE(is(expr2)); - - EXPECT_THROW(makeExpr(Mul(), ArgumentPtrVector{var})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(Mul(), ArgumentPtrVector{})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(Pow(), ArgumentPtrVector{var})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(Pow(), ArgumentPtrVector{})->toString(), InvalidInputException); -} - -TEST(FunctionUtilsTests, makeExpressionRefsTest) { - Integer one = 1; - Integer two = 2; - auto expr1 = makeExpr(Add(), {one, two}); - EXPECT_EQ(expr1->toString(), "1 + 2"); - EXPECT_FALSE(is(expr1)); - - Variable var("a"); - auto expr2 = makeExpr(Cos(), {var}); - EXPECT_EQ(expr2->toString(), "cos(a)"); - EXPECT_TRUE(is(expr2)); - - EXPECT_THROW(makeExpr(Mul(), ArgumentRefVector{var})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(Mul(), ArgumentRefVector{})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(Pow(), ArgumentRefVector{var})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(Pow(), ArgumentRefVector{})->toString(), InvalidInputException); -} - -TEST(FunctionUtilsTests, makeExpressionAnyArgsRefTest) { - const auto expr1 = makeExpr(Add(), Integer(1), Integer(2)); - EXPECT_EQ(expr1->toString(), "1 + 2"); - EXPECT_TRUE(is(expr1)); - EXPECT_FALSE(is(expr1)); - - const auto var = Variable("a"); - const auto expr2 = makeExpr(Cos(), var); - EXPECT_EQ(expr2->toString(), "cos(a)"); - EXPECT_TRUE(is(expr2)); - EXPECT_FALSE(is(expr2)); -} - -TEST(FunctionUtilsTests, makeExpressionAnyArgsPtrTest) { - const auto expr1 = makeExpr(Add(), std::make_shared(1), std::make_shared(2)); - EXPECT_EQ(expr1->toString(), "1 + 2"); - EXPECT_TRUE(is(expr1)); - EXPECT_FALSE(is(expr1)); - - auto var = std::make_shared("a"); - const auto expr2 = makeExpr(Cos(), var); - EXPECT_EQ(expr2->toString(), "cos(a)"); - EXPECT_TRUE(is(expr2)); - EXPECT_FALSE(is(expr2)); -} diff --git a/tests/src/functions/IFunctionTests.cpp b/tests/src/functions/IFunctionTests.cpp deleted file mode 100644 index b8bf41ba7..000000000 --- a/tests/src/functions/IFunctionTests.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include -#include - -#include "fintamath/functions/IFunction.hpp" - -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/arithmetic/Sub.hpp" -#include "fintamath/functions/arithmetic/UnaryPlus.hpp" -#include "fintamath/functions/trigonometry/Sin.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -namespace { - -class TestFunction final : public IFunctionCRTP { - FINTAMATH_CLASS_BODY(TestFunction) - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override { - return {}; - } -}; - -[[maybe_unused]] const auto config = [] { - IFunction::registerType(); - return 0; -}(); - -} - -TEST(IFunctionTests, parseTest) { - EXPECT_TRUE(is(*IFunction::parseFirst("TestFunction"))); -} - -TEST(IFunctionTests, callTest) { - std::unique_ptr f = std::make_unique(); - Integer a = 3; - Rational b(1, 2); - Variable c("c"); - - EXPECT_EQ((*f)(a, a)->toString(), "6"); - EXPECT_EQ((*f)(b, b)->toString(), "1"); - EXPECT_EQ((*f)(a, b)->toString(), "7/2"); - EXPECT_EQ((*f)(b, a)->toString(), "7/2"); - - EXPECT_EQ((*f)(a, c)->toString(), "c + 3"); - - EXPECT_THROW((*f)(), InvalidInputFunctionException); - EXPECT_THROW((*f)(a), InvalidInputFunctionException); - EXPECT_THROW((*f)(a, a, a), InvalidInputFunctionException); - EXPECT_THROW((*f)(a, a, a, a, a, a, a), InvalidInputFunctionException); -} - -TEST(IFunctionTests, callVectTest) { - std::unique_ptr f = std::make_unique(); - Integer a = 3; - Rational b(1, 2); - Variable c("c"); - - EXPECT_EQ((*f)({a, a})->toString(), "6"); - EXPECT_EQ((*f)({b, b})->toString(), "1"); - EXPECT_EQ((*f)({a, b})->toString(), "7/2"); - EXPECT_EQ((*f)({b, a})->toString(), "7/2"); - - EXPECT_EQ((*f)({a, c})->toString(), "c + 3"); - - EXPECT_THROW((*f)({}), InvalidInputFunctionException); - EXPECT_THROW((*f)({a}), InvalidInputFunctionException); - EXPECT_THROW((*f)({a, a, a}), InvalidInputFunctionException); - EXPECT_THROW((*f)({a, a, a, a, a, a, a}), InvalidInputFunctionException); -} - -TEST(IFunctionTests, equalsTest) { - EXPECT_EQ(Add(), Add()); - EXPECT_NE(Add(), Sub()); - EXPECT_NE(Sub(), Add()); - EXPECT_NE(Add(), UnaryPlus()); - EXPECT_NE(UnaryPlus(), Add()); - EXPECT_NE(Add(), Sin()); - EXPECT_NE(Sin(), Add()); -} - -TEST(IFunctionTests, getArgumentClassesTest) { - EXPECT_THAT(Add().getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic(), IArithmetic::getClassStatic())); - EXPECT_THAT(Neg().getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic())); - EXPECT_THAT(Sin().getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(IFunctionTests, getReturnClassTest) { - EXPECT_EQ(Add().getReturnClass(), IArithmetic::getClassStatic()); - EXPECT_EQ(Neg().getReturnClass(), IArithmetic::getClassStatic()); - EXPECT_EQ(Sin().getReturnClass(), INumber::getClassStatic()); -} - -TEST(IFunctionTests, doArgsMatchTest) { - Integer a = 3; - Rational b(1, 2); - Variable c("c"); - - EXPECT_TRUE(Add().doArgsMatch({a, b})); - EXPECT_FALSE(Add().doArgsMatch({c, c})); - EXPECT_FALSE(Add().doArgsMatch({a, c})); - EXPECT_FALSE(Add().doArgsMatch({c, a})); - EXPECT_FALSE(Add().doArgsMatch({})); - EXPECT_FALSE(Add().doArgsMatch({a})); - EXPECT_FALSE(Add().doArgsMatch({a, a, a})); - EXPECT_FALSE(Add().doArgsMatch({a, b, a, b})); -} - -TEST(IFunctionTests, getClassTest) { - EXPECT_EQ(IFunction::getClassStatic(), MathObjectClass("IFunction")); - EXPECT_EQ(IFunction::getClassStatic().getParent(), IMathObject::getClassStatic()); -} diff --git a/tests/src/functions/IOperatorTests.cpp b/tests/src/functions/IOperatorTests.cpp deleted file mode 100644 index 3fcba96da..000000000 --- a/tests/src/functions/IOperatorTests.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include - -#include "fintamath/functions/IOperator.hpp" - -#include "fintamath/functions/arithmetic/Add.hpp" -#include "fintamath/functions/arithmetic/Neg.hpp" -#include "fintamath/functions/logic/Or.hpp" -#include "fintamath/functions/other/Factorial.hpp" -#include "fintamath/functions/powers/Pow.hpp" - -using namespace fintamath; - -namespace { - -class TestOperator final : public IOperatorCRTP { - FINTAMATH_CLASS_BODY(TestOperator) - -public: - static constexpr Priority getPriorityStatic() { - return Priority::Addition; - } - -protected: - std::unique_ptr call(const ArgumentRefVector &argVect) const override { - return {}; - } -}; - -[[maybe_unused]] const auto config = [] { - IOperator::registerType(); - return 0; -}(); - -} - -TEST(IOperatorTests, parseTest) { - EXPECT_TRUE(is(*IOperator::parseFirst("TestOperator"))); -} - -TEST(IOperatorTests, getPriorityTest) { - EXPECT_EQ(Add().getPriority(), IOperator::Priority::Addition); - EXPECT_EQ(Neg().getPriority(), IOperator::Priority::PrefixUnary); - EXPECT_EQ(Factorial().getPriority(), IOperator::Priority::PostfixUnary); - EXPECT_EQ(Or().getPriority(), IOperator::Priority::Disjunction); -} - -TEST(IOperatorTests, isAssociativeTest) { - EXPECT_TRUE(Add().isAssociative()); - EXPECT_FALSE(Neg().isAssociative()); - EXPECT_TRUE(Or().isAssociative()); - EXPECT_FALSE(Pow().isAssociative()); -} - -TEST(IOperatorTests, getClassTest) { - EXPECT_EQ(IOperator::getClassStatic(), MathObjectClass("IOperator")); - EXPECT_EQ(IOperator::getClassStatic().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/arithmetic/AbsTests.cpp b/tests/src/functions/arithmetic/AbsTests.cpp deleted file mode 100644 index 989209f6c..000000000 --- a/tests/src/functions/arithmetic/AbsTests.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include - -#include "fintamath/functions/arithmetic/Abs.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Abs f; - -TEST(AbsTests, toStringTest) { - EXPECT_EQ(f.toString(), "abs"); -} - -TEST(AbsTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AbsTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AbsTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AbsTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AbsTests, callTest) { - EXPECT_EQ(f(Integer(10))->toString(), "10"); - EXPECT_EQ(f(Integer(-10))->toString(), "10"); - EXPECT_EQ(f(Integer("-210"))->toString(), "210"); - EXPECT_EQ(f(Integer("4545628562"))->toString(), "4545628562"); - - EXPECT_EQ(f(Rational(-5, 2))->toString(), "5/2"); - EXPECT_EQ(f(Rational(-1, 100))->toString(), "1/100"); - EXPECT_EQ(f(Rational(1, -100))->toString(), "1/100"); - EXPECT_EQ(f(Rational(10, 1000))->toString(), "1/100"); - - EXPECT_EQ(f(Real("8465132.321651651"))->toString(), "8465132.321651651"); - EXPECT_EQ(f(Real("-98465136846516354684651.351"))->toString(), "9.8465136846516354685*10^22"); - - EXPECT_EQ(f(Complex(2, 0))->toString(), "2"); - EXPECT_EQ(f(Complex(0, 2))->toString(), "2"); - EXPECT_EQ(f(Complex(2, 2))->toString(), "2 sqrt(2)"); - EXPECT_EQ(f(Complex(3, 2))->toString(), "sqrt(13)"); - EXPECT_EQ(f(Complex(2, 3))->toString(), "sqrt(13)"); - EXPECT_EQ(f(Complex(-2, 0))->toString(), "2"); - EXPECT_EQ(f(Complex(0, -2))->toString(), "2"); - EXPECT_EQ(f(Complex(2, -2))->toString(), "2 sqrt(2)"); - EXPECT_EQ(f(Complex(-3, 2))->toString(), "sqrt(13)"); - EXPECT_EQ(f(Complex(2, -3))->toString(), "sqrt(13)"); - EXPECT_EQ(f(Complex(-2, -3))->toString(), "sqrt(13)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "abs(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AbsTests, exprTest) { - EXPECT_EQ(absExpr(Integer(10))->toString(), "abs(10)"); -} - -TEST(AbsTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Abs")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/arithmetic/AddTests.cpp b/tests/src/functions/arithmetic/AddTests.cpp deleted file mode 100644 index c2e92eb43..000000000 --- a/tests/src/functions/arithmetic/AddTests.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include - -#include "fintamath/functions/arithmetic/Add.hpp" - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Add f; - -TEST(AddTests, toStringTest) { - EXPECT_EQ(f.toString(), "+"); -} - -TEST(AddTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic(), IArithmetic::getClassStatic())); -} - -TEST(AddTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IArithmetic::getClassStatic()); -} - -TEST(AddTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AddTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AddTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Addition); -} - -TEST(AddTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(AddTests, callTest) { - EXPECT_EQ(f(Integer(3), Integer(5))->toString(), "8"); - EXPECT_EQ(f(Integer(3), Rational(5, 2))->toString(), "11/2"); - EXPECT_EQ(f(Rational(5, 2), Integer(3))->toString(), "11/2"); - EXPECT_EQ(f(Rational(5, 2), Rational(5, 2))->toString(), "5"); - EXPECT_EQ(f(Rational(5, 2), Rational(5, 3))->toString(), "25/6"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a + 3"); - - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Add")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/arithmetic/DivTests.cpp b/tests/src/functions/arithmetic/DivTests.cpp deleted file mode 100644 index c3ba19656..000000000 --- a/tests/src/functions/arithmetic/DivTests.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include - -#include "fintamath/functions/arithmetic/Div.hpp" - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Div f; - -TEST(DivTests, toStringTest) { - EXPECT_EQ(f.toString(), "/"); -} - -TEST(DivTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic(), IArithmetic::getClassStatic())); -} - -TEST(DivTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IArithmetic::getClassStatic()); -} - -TEST(DivTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(DivTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(DivTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Multiplication); -} - -TEST(DivTests, isAssociativeTest) { - EXPECT_FALSE(f.isAssociative()); -} - -TEST(DivTests, callTest) { - EXPECT_EQ(f(Integer(3), Integer(5))->toString(), "3/5"); - EXPECT_EQ(f(Integer(3), Rational(5, 2))->toString(), "6/5"); - EXPECT_EQ(f(Rational(5, 2), Integer(3))->toString(), "5/6"); - EXPECT_EQ(f(Rational(5, 2), Rational(5, 3))->toString(), "3/2"); - - 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); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Div")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/arithmetic/FracMixedTests.cpp b/tests/src/functions/arithmetic/FracMixedTests.cpp deleted file mode 100644 index b97969f3e..000000000 --- a/tests/src/functions/arithmetic/FracMixedTests.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include - -#include "fintamath/functions/arithmetic/FracMixed.hpp" - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const FracMixed f; - -TEST(FracMixedTests, toStringTest) { - EXPECT_EQ(f.toString(), "frac"); -} - -TEST(FracMixedTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic(), IArithmetic::getClassStatic(), IArithmetic::getClassStatic())); -} - -TEST(FracMixedTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IArithmetic::getClassStatic()); -} - -TEST(FracMixedTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(FracMixedTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(FracMixedTests, callTest) { - EXPECT_EQ(f(Integer(0), Integer(3), Integer(5))->toString(), "3/5"); - EXPECT_EQ(f(Integer(0), Integer(3), Rational(5, 2))->toString(), "6/5"); - EXPECT_EQ(f(Integer(0), Rational(5, 2), Integer(3))->toString(), "5/6"); - EXPECT_EQ(f(Integer(0), Rational(-5, 2), Rational(5, 3))->toString(), "-3/2"); - EXPECT_EQ(f(Integer(2), Integer(3), Integer(5))->toString(), "13/5"); - EXPECT_EQ(f(Integer(2), Integer(3), Integer(-5))->toString(), "7/5"); - EXPECT_EQ(f(Integer(2), Integer(-3), Integer(5))->toString(), "7/5"); - EXPECT_EQ(f(Integer(-2), Integer(3), Integer(5))->toString(), "-7/5"); - EXPECT_EQ(f(Integer(-5), Integer(3), Rational(5, 2))->toString(), "-19/5"); - EXPECT_EQ(f(Integer(14), Rational(-5, 2), Integer(-3))->toString(), "89/6"); - EXPECT_EQ(f(Integer(-12), Rational(15, 5), Rational(5, -3))->toString(), "-69/5"); - - EXPECT_EQ(f(Integer(0), Integer(3), Variable("a"))->toString(), "3/a"); - - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(FracMixedTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("FracMixed")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/arithmetic/FracTests.cpp b/tests/src/functions/arithmetic/FracTests.cpp deleted file mode 100644 index c0d99be83..000000000 --- a/tests/src/functions/arithmetic/FracTests.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include - -#include "fintamath/functions/arithmetic/Frac.hpp" - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Frac f; - -TEST(FracTests, toStringTest) { - EXPECT_EQ(f.toString(), "frac"); -} - -TEST(FracTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic(), IArithmetic::getClassStatic())); -} - -TEST(FracTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IArithmetic::getClassStatic()); -} - -TEST(FracTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(FracTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(FracTests, callTest) { - EXPECT_EQ(f(Integer(3), Integer(5))->toString(), "3/5"); - EXPECT_EQ(f(Integer(3), Rational(5, 2))->toString(), "6/5"); - EXPECT_EQ(f(Rational(5, 2), Integer(3))->toString(), "5/6"); - EXPECT_EQ(f(Rational(5, 2), Rational(5, 3))->toString(), "3/2"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "3/a"); - - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(FracTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Frac")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/arithmetic/MulTests.cpp b/tests/src/functions/arithmetic/MulTests.cpp deleted file mode 100644 index 330e18c33..000000000 --- a/tests/src/functions/arithmetic/MulTests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include "fintamath/functions/arithmetic/Mul.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Mul f; - -TEST(MulTests, toStringTest) { - EXPECT_EQ(f.toString(), "*"); -} - -TEST(MulTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic(), IArithmetic::getClassStatic())); -} - -TEST(MulTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IArithmetic::getClassStatic()); -} - -TEST(MulTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(MulTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(MulTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Multiplication); -} - -TEST(MulTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(MulTests, callTest) { - EXPECT_EQ(f(Integer(3), Integer(5))->toString(), "15"); - EXPECT_EQ(f(Integer(3), Rational(5, 2))->toString(), "15/2"); - EXPECT_EQ(f(Rational(5, 2), Integer(3))->toString(), "15/2"); - EXPECT_EQ(f(Rational(5, 2), Rational(5, 3))->toString(), "25/6"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "3 a"); - - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Mul")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/arithmetic/NegTests.cpp b/tests/src/functions/arithmetic/NegTests.cpp deleted file mode 100644 index 4e9626656..000000000 --- a/tests/src/functions/arithmetic/NegTests.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include - -#include "fintamath/functions/arithmetic/Neg.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Neg f; - -TEST(NegTests, toStringTest) { - EXPECT_EQ(f.toString(), "-"); -} - -TEST(NegTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic())); -} - -TEST(NegTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IArithmetic::getClassStatic()); -} - -TEST(NegTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(NegTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(NegTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::PrefixUnary); -} - -TEST(NegTests, isAssociativeTest) { - EXPECT_FALSE(f.isAssociative()); -} - -TEST(NegTests, callTest) { - EXPECT_EQ(f(Integer(3))->toString(), "-3"); - EXPECT_EQ(f(Rational(5, 2))->toString(), "-5/2"); - EXPECT_EQ(f(Rational(-5, 2))->toString(), "5/2"); - - EXPECT_EQ(f(Variable("a"))->toString(), "-a"); - - EXPECT_THROW(f(Integer(1), Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(NegTests, exprTest) { - EXPECT_EQ(negExpr(Integer(10))->toString(), "-10"); -} - -TEST(NegTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Neg")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/arithmetic/SignTests.cpp b/tests/src/functions/arithmetic/SignTests.cpp deleted file mode 100644 index 488f81fa9..000000000 --- a/tests/src/functions/arithmetic/SignTests.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include - -#include "fintamath/functions/arithmetic/Sign.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Sign f; - -TEST(SignTests, toStringTest) { - EXPECT_EQ(f.toString(), "sign"); -} - -TEST(SignTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(SignTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(SignTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(SignTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(SignTests, callTest) { - EXPECT_EQ(f(Integer(-10))->toString(), "-1"); - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(10))->toString(), "1"); - - EXPECT_EQ(f(Rational(-10, 3))->toString(), "-1"); - EXPECT_EQ(f(Rational(10, 3))->toString(), "1"); - - EXPECT_EQ(f(Real("-1.23"))->toString(), "-1"); - EXPECT_EQ(f(Real(0))->toString(), "1"); - EXPECT_EQ(f(Real("1.23"))->toString(), "1"); - - EXPECT_EQ(f(Complex(2, 0))->toString(), "1"); - EXPECT_EQ(f(Complex(0, 2))->toString(), "I"); - EXPECT_EQ(f(Complex(2, 2))->toString(), "((1 + I) sqrt(2))/2"); - EXPECT_EQ(f(Complex(3, 2))->toString(), "((3 + 2 I) sqrt(13))/13"); - EXPECT_EQ(f(Complex(2, 3))->toString(), "((2 + 3 I) sqrt(13))/13"); - EXPECT_EQ(f(Complex(-2, 0))->toString(), "-1"); - EXPECT_EQ(f(Complex(0, -2))->toString(), "-I"); - EXPECT_EQ(f(Complex(2, -2))->toString(), "((1 - I) sqrt(2))/2"); - EXPECT_EQ(f(Complex(-3, 2))->toString(), "-((3 - 2 I) sqrt(13))/13"); - EXPECT_EQ(f(Complex(2, -3))->toString(), "((2 - 3 I) sqrt(13))/13"); - EXPECT_EQ(f(Complex(-2, -3))->toString(), "-((2 + 3 I) sqrt(13))/13"); - - EXPECT_EQ(f(Variable("a"))->toString(), "sign(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(SignTests, exprTest) { - EXPECT_EQ(signExpr(Integer(10))->toString(), "sign(10)"); -} - -TEST(SignTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Sign")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/arithmetic/SubTests.cpp b/tests/src/functions/arithmetic/SubTests.cpp deleted file mode 100644 index 98b923f28..000000000 --- a/tests/src/functions/arithmetic/SubTests.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include - -#include "fintamath/functions/arithmetic/Sub.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Sub f; - -TEST(SubTests, toStringTest) { - EXPECT_EQ(f.toString(), "-"); -} - -TEST(SubTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic(), IArithmetic::getClassStatic())); -} - -TEST(SubTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IArithmetic::getClassStatic()); -} - -TEST(SubTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(SubTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(SubTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Addition); -} - -TEST(SubTests, isAssociativeTest) { - EXPECT_FALSE(f.isAssociative()); -} - -TEST(SubTests, callTest) { - EXPECT_EQ(f(Integer(3), Integer(5))->toString(), "-2"); - EXPECT_EQ(f(Integer(3), Rational(5, 2))->toString(), "1/2"); - EXPECT_EQ(f(Rational(5, 2), Integer(3))->toString(), "-1/2"); - EXPECT_EQ(f(Rational(5, 2), Rational(5, 2))->toString(), "0"); - EXPECT_EQ(f(Rational(5, 2), Rational(5, 3))->toString(), "5/6"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "-a + 3"); - - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Sub")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/arithmetic/UnaryPlusTests.cpp b/tests/src/functions/arithmetic/UnaryPlusTests.cpp deleted file mode 100644 index d7c70bbb5..000000000 --- a/tests/src/functions/arithmetic/UnaryPlusTests.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include - -#include "fintamath/functions/arithmetic/UnaryPlus.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const UnaryPlus f; - -TEST(UnaryPlusTests, toStringTest) { - EXPECT_EQ(f.toString(), "+"); -} - -TEST(UnaryPlusTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic())); -} - -TEST(UnaryPlusTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IArithmetic::getClassStatic()); -} - -TEST(UnaryPlusTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(UnaryPlusTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(UnaryPlusTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::PrefixUnary); -} - -TEST(UnaryPlusTests, isAssociativeTest) { - EXPECT_FALSE(f.isAssociative()); -} - -TEST(UnaryPlusTests, callTest) { - EXPECT_EQ(f(Integer(3))->toString(), "3"); - EXPECT_EQ(f(Rational(5, 2))->toString(), "5/2"); - EXPECT_EQ(f(Rational(-5, 2))->toString(), "-5/2"); - - EXPECT_EQ(f(Variable("a"))->toString(), "a"); - - EXPECT_THROW(f(Integer(1), Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(UnaryPlusTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("UnaryPlus")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/calculus/DerivativeTests.cpp b/tests/src/functions/calculus/DerivativeTests.cpp deleted file mode 100644 index eb50a9f4b..000000000 --- a/tests/src/functions/calculus/DerivativeTests.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include -#include - -#include "fintamath/functions/calculus/Derivative.hpp" - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Derivative f; - -namespace { - -class TestComparable final : public IComparableCRTP { - FINTAMATH_CLASS_BODY(TestComparable) - -public: - std::string toString() const override { - return "testderivative"; - } - -protected: - std::strong_ordering compare(const TestComparable & /* rhs */) const override { - return std::strong_ordering::less; - } - - TestComparable &add(const TestComparable & /* rhs */) override { - return *this; - } - - TestComparable &substract(const TestComparable & /* rhs */) override { - return *this; - } - - TestComparable &multiply(const TestComparable & /* rhs */) override { - return *this; - } - - TestComparable ÷(const TestComparable & /* rhs */) override { - return *this; - } - - TestComparable &negate() override { - return *this; - } -}; - -[[maybe_unused]] const auto config = [] { - IComparable::registerType(); - return 0; -}(); - -} - -TEST(DerivativeTests, toStringTest) { - EXPECT_EQ(f.toString(), "derivative"); -} - -TEST(DerivativeTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IComparable::getClassStatic(), Variable::getClassStatic())); -} - -TEST(DerivativeTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IComparable::getClassStatic()); -} - -TEST(DerivativeTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(DerivativeTests, isEvaluatableTest) { - EXPECT_FALSE(f.isEvaluatable()); -} - -TEST(DerivativeTests, callTest) { - EXPECT_EQ(f(Integer(5), Variable("a"))->toString(), "0"); - EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "1"); - EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "0"); - EXPECT_EQ(f(Expression("a+a"), Variable("a"))->toString(), "2"); - - EXPECT_EQ(f(TestComparable(), Variable("a"))->toString(), "derivative(testderivative, a)"); - - EXPECT_THROW(f(Integer(5), Integer(1)), InvalidInputException); - EXPECT_THROW(f(Variable("a"), Integer(1)), InvalidInputException); - EXPECT_THROW(f(Variable("a"), Expression("a+a")), InvalidInputException); - - EXPECT_THROW(f(), InvalidInputException); - EXPECT_THROW(f(Integer(1)), InvalidInputException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Derivative")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/calculus/IntegralTests.cpp b/tests/src/functions/calculus/IntegralTests.cpp deleted file mode 100644 index faf41044a..000000000 --- a/tests/src/functions/calculus/IntegralTests.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include - -#include "fintamath/functions/calculus/Integral.hpp" - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Integral f; - -TEST(IntegralTests, toStringTest) { - EXPECT_EQ(f.toString(), "integral"); -} - -TEST(IntegralTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IComparable::getClassStatic(), Variable::getClassStatic())); -} - -TEST(IntegralTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IComparable::getClassStatic()); -} - -TEST(IntegralTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(IntegralTests, isEvaluatableTest) { - EXPECT_FALSE(f.isEvaluatable()); -} - -TEST(IntegralTests, callTest) { - // TODO: integral - EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "integral(a, a)"); - EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "integral(a, b)"); - EXPECT_EQ(f(Expression("a+a"), Variable("a"))->toString(), "integral(2 a, a)"); - EXPECT_EQ(f(Integer(5), Variable("a"))->toString(), "integral(5, a)"); - - EXPECT_THROW(f(Integer(5), Integer(1)), InvalidInputException); - EXPECT_THROW(f(Variable("a"), Integer(1)), InvalidInputException); - EXPECT_THROW(f(Variable("a"), Expression("a+a")), InvalidInputException); - - EXPECT_THROW(f(), InvalidInputException); - EXPECT_THROW(f(Integer(1)), InvalidInputException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Integral")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/calculus/MaxTests.cpp b/tests/src/functions/calculus/MaxTests.cpp deleted file mode 100644 index 29021aad4..000000000 --- a/tests/src/functions/calculus/MaxTests.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include - -#include "fintamath/functions/calculus/Max.hpp" - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Max f; - -TEST(MaxTests, toStringTest) { - EXPECT_EQ(f.toString(), "max"); -} - -TEST(MaxTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IComparable::getClassStatic())); -} - -TEST(MaxTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IComparable::getClassStatic()); -} - -TEST(MaxTests, isVariadicTest) { - EXPECT_TRUE(f.isVariadic()); -} - -TEST(MaxTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(MaxTests, callTest) { - EXPECT_EQ(f(Integer(1))->toString(), "1"); - EXPECT_EQ(f(Integer(1), Integer(-1))->toString(), "1"); - EXPECT_EQ(f(Integer(1), Integer(-1), Rational(-5, 2))->toString(), "1"); - EXPECT_EQ(f(Integer(1), Rational(5, 2), Rational(-5, 2), Integer(-1))->toString(), "5/2"); - - EXPECT_EQ(f(Integer(1), Rational(5, 2), Complex(1, 1))->toString(), "max(1, 5/2, 1 + I)"); - EXPECT_EQ(f(Integer(1), Complex(1, 1), Rational(5, 2))->toString(), "max(1, 1 + I, 5/2)"); - - EXPECT_EQ(f(Rational(-1), Variable("x"), Variable("y"), Integer(1))->toString(), "max(x, y, 1)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean()), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(), Boolean()), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(), Integer()), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(), Integer(), Boolean()), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(), Boolean(), Integer()), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(), Integer(), Integer()), InvalidInputFunctionException); -} - -TEST(MaxTests, exprTest) { - EXPECT_EQ(maxExpr(Variable("a"), Variable("a"))->toString(), "max(a, a)"); -} - -TEST(MaxTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Max")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/calculus/MinTests.cpp b/tests/src/functions/calculus/MinTests.cpp deleted file mode 100644 index ece74398b..000000000 --- a/tests/src/functions/calculus/MinTests.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include - -#include "fintamath/functions/calculus/Min.hpp" - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Min f; - -TEST(MinTests, toStringTest) { - EXPECT_EQ(f.toString(), "min"); -} - -TEST(MinTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IComparable::getClassStatic())); -} - -TEST(MinTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IComparable::getClassStatic()); -} - -TEST(MinTests, isVariadicTest) { - EXPECT_TRUE(f.isVariadic()); -} - -TEST(MinTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(MinTests, callTest) { - EXPECT_EQ(f(Integer(1))->toString(), "1"); - EXPECT_EQ(f(Integer(1), Integer(-1))->toString(), "-1"); - EXPECT_EQ(f(Integer(1), Integer(-1), Rational(-5, 2))->toString(), "-5/2"); - EXPECT_EQ(f(Integer(1), Rational(5, 2), Rational(-5, 2), Integer(-1))->toString(), "-5/2"); - - EXPECT_EQ(f(Integer(1), Rational(5, 2), Complex(1, 1))->toString(), "min(1, 5/2, 1 + I)"); - EXPECT_EQ(f(Integer(1), Complex(1, 1), Rational(5, 2))->toString(), "min(1, 1 + I, 5/2)"); - - EXPECT_EQ(f(Rational(-1), Variable("x"), Variable("y"), Integer(1))->toString(), "min(x, y, -1)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean()), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(), Boolean()), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(), Integer()), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(), Integer(), Boolean()), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(), Boolean(), Integer()), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(), Integer(), Integer()), InvalidInputFunctionException); -} - -TEST(MinTests, exprTest) { - EXPECT_EQ(minExpr(Variable("a"), Variable("a"))->toString(), "min(a, a)"); -} - -TEST(MinTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Min")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/comparison/EqvTests.cpp b/tests/src/functions/comparison/EqvTests.cpp deleted file mode 100644 index e395c5689..000000000 --- a/tests/src/functions/comparison/EqvTests.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include - -#include "fintamath/functions/comparison/Eqv.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Eqv f; - -TEST(EqvTests, toStringTest) { - EXPECT_EQ(f.toString(), "="); -} - -TEST(EqvTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IComparable::getClassStatic(), IComparable::getClassStatic())); -} - -TEST(EqvTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Boolean::getClassStatic()); -} - -TEST(EqvTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(EqvTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(EqvTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Comparison); -} - -TEST(EqvTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(EqvTests, callTest) { - EXPECT_EQ(f(Integer(5), Integer(3))->toString(), "False"); - EXPECT_EQ(f(Integer(3), Integer(5))->toString(), "False"); - EXPECT_EQ(f(Integer(3), Integer(3))->toString(), "True"); - EXPECT_EQ(f(Integer(3), Rational(3, 1))->toString(), "True"); - EXPECT_EQ(f(Rational(5, 2), Integer(2))->toString(), "False"); - - EXPECT_EQ(f(Complex(1, 1), Complex(1, 1))->toString(), "True"); - EXPECT_EQ(f(Complex(1, 1), Complex(1, 2))->toString(), "False"); - EXPECT_EQ(f(Complex(1, 1), Complex(2, 1))->toString(), "False"); - EXPECT_EQ(f(Complex(1, 1), Complex(2, 2))->toString(), "False"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a - 3 = 0"); - EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "True"); - - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Eqv")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/comparison/LessEqvTests.cpp b/tests/src/functions/comparison/LessEqvTests.cpp deleted file mode 100644 index 167da7eba..000000000 --- a/tests/src/functions/comparison/LessEqvTests.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include - -#include "fintamath/functions/comparison/LessEqv.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const LessEqv f; - -TEST(LessEqvTests, toStringTest) { - EXPECT_EQ(f.toString(), "<="); -} - -TEST(LessEqvTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IComparable::getClassStatic(), IComparable::getClassStatic())); -} - -TEST(LessEqvTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Boolean::getClassStatic()); -} - -TEST(LessEqvTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(LessEqvTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(LessEqvTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Comparison); -} - -TEST(LessEqvTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(LessEqvTests, callTest) { - EXPECT_EQ(f(Integer(5), Integer(3))->toString(), "False"); - EXPECT_EQ(f(Integer(3), Integer(5))->toString(), "True"); - EXPECT_EQ(f(Integer(3), Integer(3))->toString(), "True"); - EXPECT_EQ(f(Integer(3), Rational(3, 1))->toString(), "True"); - EXPECT_EQ(f(Rational(5, 2), Integer(2))->toString(), "False"); - - EXPECT_EQ(f(Complex(1, 1), Complex(1, 1))->toString(), "1 + I <= 1 + I"); - EXPECT_EQ(f(Complex(1, 1), Complex(1, 2))->toString(), "1 + I <= 1 + 2 I"); - EXPECT_EQ(f(Complex(1, 1), Complex(2, 1))->toString(), "1 + I <= 2 + I"); - EXPECT_EQ(f(Complex(1, 1), Complex(2, 2))->toString(), "1 + I <= 2 + 2 I"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a - 3 >= 0"); - EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "True"); - - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("LessEqv")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/comparison/LessTests.cpp b/tests/src/functions/comparison/LessTests.cpp deleted file mode 100644 index 284453ee9..000000000 --- a/tests/src/functions/comparison/LessTests.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include - -#include "fintamath/functions/comparison/Less.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Less f; - -TEST(LessTests, toStringTest) { - EXPECT_EQ(f.toString(), "<"); -} - -TEST(LessTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IComparable::getClassStatic(), IComparable::getClassStatic())); -} - -TEST(LessTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Boolean::getClassStatic()); -} - -TEST(LessTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(LessTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(LessTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Comparison); -} - -TEST(LessTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(LessTests, callTest) { - EXPECT_EQ(f(Integer(5), Integer(3))->toString(), "False"); - EXPECT_EQ(f(Integer(3), Integer(5))->toString(), "True"); - EXPECT_EQ(f(Integer(3), Integer(3))->toString(), "False"); - EXPECT_EQ(f(Integer(3), Rational(3, 1))->toString(), "False"); - EXPECT_EQ(f(Rational(5, 2), Integer(2))->toString(), "False"); - - EXPECT_EQ(f(Complex(1, 1), Complex(1, 1))->toString(), "1 + I < 1 + I"); - EXPECT_EQ(f(Complex(1, 1), Complex(1, 2))->toString(), "1 + I < 1 + 2 I"); - EXPECT_EQ(f(Complex(1, 1), Complex(2, 1))->toString(), "1 + I < 2 + I"); - EXPECT_EQ(f(Complex(1, 1), Complex(2, 2))->toString(), "1 + I < 2 + 2 I"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a - 3 > 0"); - EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "False"); - - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Less")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/comparison/MoreEqvTests.cpp b/tests/src/functions/comparison/MoreEqvTests.cpp deleted file mode 100644 index eed084eaf..000000000 --- a/tests/src/functions/comparison/MoreEqvTests.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include - -#include "fintamath/functions/comparison/MoreEqv.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const MoreEqv f; - -TEST(MoreEqvTests, toStringTest) { - EXPECT_EQ(f.toString(), ">="); -} - -TEST(MoreEqvTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IComparable::getClassStatic(), IComparable::getClassStatic())); -} - -TEST(MoreEqvTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Boolean::getClassStatic()); -} - -TEST(MoreEqvTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(MoreEqvTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(MoreEqvTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Comparison); -} - -TEST(MoreEqvTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(MoreEqvTests, callTest) { - EXPECT_EQ(f(Integer(5), Integer(3))->toString(), "True"); - EXPECT_EQ(f(Integer(3), Integer(5))->toString(), "False"); - EXPECT_EQ(f(Integer(3), Integer(3))->toString(), "True"); - EXPECT_EQ(f(Integer(3), Rational(3, 1))->toString(), "True"); - EXPECT_EQ(f(Rational(5, 2), Integer(2))->toString(), "True"); - - EXPECT_EQ(f(Complex(1, 1), Complex(1, 1))->toString(), "1 + I >= 1 + I"); - EXPECT_EQ(f(Complex(1, 1), Complex(1, 2))->toString(), "1 + I >= 1 + 2 I"); - EXPECT_EQ(f(Complex(1, 1), Complex(2, 1))->toString(), "1 + I >= 2 + I"); - EXPECT_EQ(f(Complex(1, 1), Complex(2, 2))->toString(), "1 + I >= 2 + 2 I"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a - 3 <= 0"); - EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "True"); - - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("MoreEqv")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/comparison/MoreTests.cpp b/tests/src/functions/comparison/MoreTests.cpp deleted file mode 100644 index 8db533f21..000000000 --- a/tests/src/functions/comparison/MoreTests.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include - -#include "fintamath/functions/comparison/More.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const More f; - -TEST(MoreTests, toStringTest) { - EXPECT_EQ(f.toString(), ">"); -} - -TEST(MoreTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IComparable::getClassStatic(), IComparable::getClassStatic())); -} - -TEST(MoreTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Boolean::getClassStatic()); -} - -TEST(MoreTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(MoreTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(MoreTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Comparison); -} - -TEST(MoreTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(MoreTests, callTest) { - EXPECT_EQ(f(Integer(5), Integer(3))->toString(), "True"); - EXPECT_EQ(f(Integer(3), Integer(5))->toString(), "False"); - EXPECT_EQ(f(Integer(3), Integer(3))->toString(), "False"); - EXPECT_EQ(f(Integer(3), Rational(3, 1))->toString(), "False"); - EXPECT_EQ(f(Rational(5, 2), Integer(2))->toString(), "True"); - - EXPECT_EQ(f(Complex(1, 1), Complex(1, 1))->toString(), "1 + I > 1 + I"); - EXPECT_EQ(f(Complex(1, 1), Complex(1, 2))->toString(), "1 + I > 1 + 2 I"); - EXPECT_EQ(f(Complex(1, 1), Complex(2, 1))->toString(), "1 + I > 2 + I"); - EXPECT_EQ(f(Complex(1, 1), Complex(2, 2))->toString(), "1 + I > 2 + 2 I"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a - 3 < 0"); - EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "False"); - - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("More")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/comparison/NeqvTests.cpp b/tests/src/functions/comparison/NeqvTests.cpp deleted file mode 100644 index 8658f175b..000000000 --- a/tests/src/functions/comparison/NeqvTests.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include - -#include "fintamath/functions/comparison/Neqv.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Neqv f; - -TEST(NeqvTests, toStringTest) { - EXPECT_EQ(f.toString(), "!="); -} - -TEST(NeqvTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IComparable::getClassStatic(), IComparable::getClassStatic())); -} - -TEST(NeqvTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Boolean::getClassStatic()); -} - -TEST(NeqvTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(NeqvTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(NeqvTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Comparison); -} - -TEST(NeqvTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(NeqvTests, callTest) { - EXPECT_EQ(f(Integer(5), Integer(3))->toString(), "True"); - EXPECT_EQ(f(Integer(3), Integer(5))->toString(), "True"); - EXPECT_EQ(f(Integer(3), Integer(3))->toString(), "False"); - EXPECT_EQ(f(Integer(3), Rational(3, 1))->toString(), "False"); - EXPECT_EQ(f(Rational(5, 2), Integer(2))->toString(), "True"); - - EXPECT_EQ(f(Complex(1, 1), Complex(1, 1))->toString(), "False"); - EXPECT_EQ(f(Complex(1, 1), Complex(1, 2))->toString(), "True"); - EXPECT_EQ(f(Complex(1, 1), Complex(2, 1))->toString(), "True"); - EXPECT_EQ(f(Complex(1, 1), Complex(2, 2))->toString(), "True"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a - 3 != 0"); - EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "False"); - - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Neqv")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/hyperbolic/AcoshTests.cpp b/tests/src/functions/hyperbolic/AcoshTests.cpp deleted file mode 100644 index edd446c64..000000000 --- a/tests/src/functions/hyperbolic/AcoshTests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include "fintamath/functions/hyperbolic/Acosh.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Acosh f; - -TEST(AcoshTests, toStringTest) { - EXPECT_EQ(f.toString(), "acosh"); -} - -TEST(AcoshTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AcoshTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AcoshTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AcoshTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AcoshTests, callTest) { - EXPECT_EQ(f(Integer(-1))->toString(), "I Pi"); - EXPECT_EQ(f(Integer(0))->toString(), "(I Pi)/2"); - EXPECT_EQ(f(Integer(1))->toString(), "0"); - EXPECT_EQ(f(Integer(2))->toString(), "1.3169578969248167086"); - EXPECT_EQ(f(Integer(-2))->toString(), "acosh(-2)"); - - EXPECT_EQ(f(Rational(11, 10))->toString(), "0.44356825438511518913"); - EXPECT_EQ(f(Rational(23, 13))->toString(), "1.1720930632462197633"); - - EXPECT_EQ(f(Real("1.5"))->toString(), "0.962423650119206895"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "acosh(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "acosh(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AcoshTests, exprTest) { - EXPECT_EQ(acoshExpr(Integer(10))->toString(), "acosh(10)"); -} - -TEST(AcoshTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Acosh")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/hyperbolic/AcothTests.cpp b/tests/src/functions/hyperbolic/AcothTests.cpp deleted file mode 100644 index 61670637b..000000000 --- a/tests/src/functions/hyperbolic/AcothTests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include "fintamath/functions/hyperbolic/Acoth.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Acoth f; - -TEST(AcothTests, toStringTest) { - EXPECT_EQ(f.toString(), "acoth"); -} - -TEST(AcothTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AcothTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AcothTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AcothTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AcothTests, callTest) { - EXPECT_EQ(f(Integer(-1))->toString(), "-Inf"); - EXPECT_EQ(f(Integer(0))->toString(), "(I Pi)/2"); - EXPECT_EQ(f(Integer(1))->toString(), "Inf"); - EXPECT_EQ(f(Integer(2))->toString(), "0.5493061443340548457"); - - EXPECT_EQ(f(Rational(27, 10))->toString(), "0.38885228429400418206"); - EXPECT_EQ(f(Rational(23, 13))->toString(), "0.6404669227310321588"); - - EXPECT_EQ(f(Real("1.5"))->toString(), "0.8047189562170501873"); - EXPECT_EQ(f(Real("0.5"))->toString(), "acoth(0.5)"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "acoth(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "acoth(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AcothTests, exprTest) { - EXPECT_EQ(acothExpr(Integer(10))->toString(), "acoth(10)"); -} - -TEST(AcothTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Acoth")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/hyperbolic/AcschTests.cpp b/tests/src/functions/hyperbolic/AcschTests.cpp deleted file mode 100644 index e7c42eedc..000000000 --- a/tests/src/functions/hyperbolic/AcschTests.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include - -#include "fintamath/functions/hyperbolic/Acsch.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Acsch f; - -TEST(AcschTests, toStringTest) { - EXPECT_EQ(f.toString(), "acsch"); -} - -TEST(AcschTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AcschTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AcschTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AcschTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AcschTests, callTest) { - EXPECT_EQ(f(Integer(-1))->toString(), "-0.88137358701954302523"); - EXPECT_EQ(f(Integer(0))->toString(), "ComplexInf"); - EXPECT_EQ(f(Integer(1))->toString(), "0.88137358701954302523"); - EXPECT_EQ(f(Integer(2))->toString(), "0.4812118250596034475"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "2.9982229502979697388"); - EXPECT_EQ(f(Rational(-1, 5))->toString(), "-2.3124383412727526203"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "1.4436354751788103425"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "acsch(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "acsch(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AcschTests, exprTest) { - EXPECT_EQ(acschExpr(Integer(10))->toString(), "acsch(10)"); -} - -TEST(AcschTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Acsch")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/hyperbolic/AsechTests.cpp b/tests/src/functions/hyperbolic/AsechTests.cpp deleted file mode 100644 index 86572daac..000000000 --- a/tests/src/functions/hyperbolic/AsechTests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include "fintamath/functions/hyperbolic/Asech.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Asech f; - -TEST(AsechTests, toStringTest) { - EXPECT_EQ(f.toString(), "asech"); -} - -TEST(AsechTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AsechTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AsechTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AsechTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AsechTests, callTest) { - EXPECT_EQ(f(Integer(-1))->toString(), "I Pi"); - EXPECT_EQ(f(Integer(0))->toString(), "Inf"); - EXPECT_EQ(f(Integer(1))->toString(), "0"); - EXPECT_EQ(f(Integer(2))->toString(), "asech(2)"); - EXPECT_EQ(f(Integer(-2))->toString(), "asech(-2)"); - - EXPECT_EQ(f(Rational(11, 10))->toString(), "asech(11/10)"); - EXPECT_EQ(f(Rational(23, 13))->toString(), "asech(23/13)"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "1.3169578969248167086"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "asech(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "asech(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AsechTests, exprTest) { - EXPECT_EQ(asechExpr(Integer(10))->toString(), "asech(10)"); -} - -TEST(AsechTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Asech")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/hyperbolic/AsinhTests.cpp b/tests/src/functions/hyperbolic/AsinhTests.cpp deleted file mode 100644 index d98130ea5..000000000 --- a/tests/src/functions/hyperbolic/AsinhTests.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include - -#include "fintamath/functions/hyperbolic/Asinh.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Asinh f; - -TEST(AsinhTests, toStringTest) { - EXPECT_EQ(f.toString(), "asinh"); -} - -TEST(AsinhTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AsinhTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AsinhTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AsinhTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AsinhTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(1))->toString(), "0.88137358701954302523"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "0.099834078899207563327"); - EXPECT_EQ(f(Rational(-1, 5))->toString(), "-0.19869011034924140647"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "0.4812118250596034475"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "asinh(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "asinh(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AsinhTests, exprTest) { - EXPECT_EQ(asinhExpr(Integer(10))->toString(), "asinh(10)"); -} - -TEST(AsinhTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Asinh")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/hyperbolic/AtanhTests.cpp b/tests/src/functions/hyperbolic/AtanhTests.cpp deleted file mode 100644 index 5e03e874e..000000000 --- a/tests/src/functions/hyperbolic/AtanhTests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include "fintamath/functions/hyperbolic/Atanh.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Atanh f; - -TEST(AtanhTests, toStringTest) { - EXPECT_EQ(f.toString(), "atanh"); -} - -TEST(AtanhTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AtanhTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AtanhTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AtanhTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AtanhTests, callTest) { - EXPECT_EQ(f(Integer(-1))->toString(), "-Inf"); - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(1))->toString(), "Inf"); - EXPECT_EQ(f(Integer(2))->toString(), "atanh(2)"); - - EXPECT_EQ(f(Rational(10, 11))->toString(), "1.5222612188617114983"); - EXPECT_EQ(f(Rational(-10, 11))->toString(), "-1.5222612188617114983"); - EXPECT_EQ(f(Rational(1, 10))->toString(), "0.10033534773107558064"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "0.5493061443340548457"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "atanh(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "atanh(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AtanhTests, exprTest) { - EXPECT_EQ(atanhExpr(Integer(10))->toString(), "atanh(10)"); -} - -TEST(AtanhTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Atanh")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/hyperbolic/CoshTests.cpp b/tests/src/functions/hyperbolic/CoshTests.cpp deleted file mode 100644 index 0e20c1fe1..000000000 --- a/tests/src/functions/hyperbolic/CoshTests.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include - -#include "fintamath/functions/hyperbolic/Cosh.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Cosh f; - -TEST(CoshTests, toStringTest) { - EXPECT_EQ(f.toString(), "cosh"); -} - -TEST(CoshTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(CoshTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(CoshTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(CoshTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(CoshTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "1"); - EXPECT_EQ(f(Integer(5))->toString(), "74.209948524787844444"); - EXPECT_EQ(f(Integer(-5))->toString(), "74.209948524787844444"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "1.005004168055803599"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "1.1276259652063807852"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "cosh(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "cosh(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(CoshTests, exprTest) { - EXPECT_EQ(coshExpr(Integer(10))->toString(), "cosh(10)"); -} - -TEST(CoshTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Cosh")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/hyperbolic/CothTests.cpp b/tests/src/functions/hyperbolic/CothTests.cpp deleted file mode 100644 index 8cab1c1ce..000000000 --- a/tests/src/functions/hyperbolic/CothTests.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include - -#include "fintamath/functions/hyperbolic/Coth.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Coth f; - -TEST(CothTests, toStringTest) { - EXPECT_EQ(f.toString(), "coth"); -} - -TEST(CothTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(CothTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(CothTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(CothTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(CothTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "ComplexInf"); - EXPECT_EQ(f(Integer(5))->toString(), "1.0000908039820193755"); - EXPECT_EQ(f(Integer(-5))->toString(), "-1.0000908039820193755"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "10.03331113225398961"); - EXPECT_EQ(f(Rational(11, 10))->toString(), "1.2492207645683124166"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "2.1639534137386528488"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "coth(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "coth(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(CothTests, exprTest) { - EXPECT_EQ(cothExpr(Integer(10))->toString(), "coth(10)"); -} - -TEST(CothTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Coth")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/hyperbolic/CschTests.cpp b/tests/src/functions/hyperbolic/CschTests.cpp deleted file mode 100644 index 869ba2604..000000000 --- a/tests/src/functions/hyperbolic/CschTests.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include - -#include "fintamath/functions/hyperbolic/Csch.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Csch f; - -TEST(CschTests, toStringTest) { - EXPECT_EQ(f.toString(), "csch"); -} - -TEST(CschTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(CschTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(CschTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(CschTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(CschTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "ComplexInf"); - EXPECT_EQ(f(Integer(5))->toString(), "0.013476505830589086655"); - EXPECT_EQ(f(Integer(-5))->toString(), "-0.013476505830589086655"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "9.9833527572961096379"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "1.9190347513349437195"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "csch(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "csch(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(CschTests, exprTest) { - EXPECT_EQ(cschExpr(Integer(10))->toString(), "csch(10)"); -} - -TEST(CschTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Csch")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/hyperbolic/SechTests.cpp b/tests/src/functions/hyperbolic/SechTests.cpp deleted file mode 100644 index 994a3af29..000000000 --- a/tests/src/functions/hyperbolic/SechTests.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include - -#include "fintamath/functions/hyperbolic/Sech.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Sech f; - -TEST(SechTests, toStringTest) { - EXPECT_EQ(f.toString(), "sech"); -} - -TEST(SechTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(SechTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(SechTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(SechTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(SechTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "1"); - EXPECT_EQ(f(Integer(5))->toString(), "0.013475282221304557306"); - EXPECT_EQ(f(Integer(-5))->toString(), "0.013475282221304557306"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "0.99502074895322649163"); - EXPECT_EQ(f(Rational(11, 10))->toString(), "0.59933406057079292981"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "0.88681888397007390866"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "sech(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "sech(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(SechTests, exprTest) { - EXPECT_EQ(sechExpr(Integer(10))->toString(), "sech(10)"); -} - -TEST(SechTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Sech")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/hyperbolic/SinhTests.cpp b/tests/src/functions/hyperbolic/SinhTests.cpp deleted file mode 100644 index be95b8943..000000000 --- a/tests/src/functions/hyperbolic/SinhTests.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include - -#include "fintamath/functions/hyperbolic/Sinh.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Sinh f; - -TEST(SinhTests, toStringTest) { - EXPECT_EQ(f.toString(), "sinh"); -} - -TEST(SinhTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(SinhTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(SinhTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(SinhTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(SinhTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(5))->toString(), "74.203210577788758977"); - EXPECT_EQ(f(Integer(-5))->toString(), "-74.203210577788758977"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "0.10016675001984402582"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "0.52109530549374736162"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "sinh(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "sinh(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(SinhTests, exprTest) { - EXPECT_EQ(sinhExpr(Integer(10))->toString(), "sinh(10)"); -} - -TEST(SinhTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Sinh")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/hyperbolic/TanhTests.cpp b/tests/src/functions/hyperbolic/TanhTests.cpp deleted file mode 100644 index 893a162c1..000000000 --- a/tests/src/functions/hyperbolic/TanhTests.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include - -#include "fintamath/functions/hyperbolic/Tanh.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Tanh f; - -TEST(TanhTests, toStringTest) { - EXPECT_EQ(f.toString(), "tanh"); -} - -TEST(TanhTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(TanhTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(TanhTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(TanhTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(TanhTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(5))->toString(), "0.99990920426259513121"); - EXPECT_EQ(f(Integer(-5))->toString(), "-0.99990920426259513121"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "0.099667994624955817118"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "0.4621171572600097585"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "tanh(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "tanh(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(TanhTests, exprTest) { - EXPECT_EQ(tanhExpr(Integer(10))->toString(), "tanh(10)"); -} - -TEST(TanhTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Tanh")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/logarithms/LbTests.cpp b/tests/src/functions/logarithms/LbTests.cpp deleted file mode 100644 index 40b7c50df..000000000 --- a/tests/src/functions/logarithms/LbTests.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include - -#include "fintamath/functions/logarithms/Lb.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Lb f; - -TEST(LbTests, toStringTest) { - EXPECT_EQ(f.toString(), "lb"); -} - -TEST(LbTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(LbTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(LbTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(LbTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(LbTests, callTest) { - EXPECT_EQ(f(Integer(2))->toString(), "1"); - EXPECT_EQ(f(Integer(10))->toString(), "3.3219280948873623479"); - EXPECT_EQ(f(Integer(3))->toString(), "1.5849625007211561815"); - - EXPECT_EQ(f(Rational(1, 16))->toString(), "-4"); - - EXPECT_EQ(f(Integer(-10))->toString(), "log(2, -10)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "log(2, a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(10), Integer(10), Integer(10)), InvalidInputFunctionException); -} - -TEST(LbTests, exprTest) { - EXPECT_EQ(lbExpr(Integer(10))->toString(), "log(2, 10)"); -} - -TEST(LbTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Lb")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/logarithms/LgTests.cpp b/tests/src/functions/logarithms/LgTests.cpp deleted file mode 100644 index 4b2aa8ef7..000000000 --- a/tests/src/functions/logarithms/LgTests.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include - -#include "fintamath/functions/logarithms/Lg.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Lg f; - -TEST(LgTests, toStringTest) { - EXPECT_EQ(f.toString(), "lg"); -} - -TEST(LgTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(LgTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(LgTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(LgTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(LgTests, callTest) { - EXPECT_EQ(f(Integer(10))->toString(), "1"); - EXPECT_EQ(f(Integer(20))->toString(), "1.3010299956639811952"); - EXPECT_EQ(f(Integer(2))->toString(), "0.30102999566398119521"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "-1"); - - EXPECT_EQ(f(Integer(-10))->toString(), "log(10, -10)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "log(10, a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(10), Integer(10), Integer(10)), InvalidInputFunctionException); -} - -TEST(LgTests, exprTest) { - EXPECT_EQ(lgExpr(Integer(10))->toString(), "log(10, 10)"); -} - -TEST(LgTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Lg")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/logarithms/LnTests.cpp b/tests/src/functions/logarithms/LnTests.cpp deleted file mode 100644 index 507007b09..000000000 --- a/tests/src/functions/logarithms/LnTests.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include - -#include "fintamath/functions/logarithms/Ln.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Ln f; - -TEST(LnTests, toStringTest) { - EXPECT_EQ(f.toString(), "ln"); -} - -TEST(LnTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(LnTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(LnTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(LnTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(LnTests, callTest) { - EXPECT_EQ(f(Integer(1))->toString(), "0"); - EXPECT_EQ(f(Integer(10))->toString(), "2.302585092994045684"); - EXPECT_EQ(f(Integer(5))->toString(), "1.6094379124341003746"); - EXPECT_EQ(f(Rational(1, 10))->toString(), "-2.302585092994045684"); - EXPECT_EQ(f(Real("2.71828"))->toString(), "0.99999932734728200316"); - - EXPECT_EQ(f(Integer(-10))->toString(), "ln(-10)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "ln(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(LnTests, exprTest) { - EXPECT_EQ(lnExpr(Integer(10))->toString(), "ln(10)"); -} - -TEST(LnTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Ln")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/logarithms/LogTests.cpp b/tests/src/functions/logarithms/LogTests.cpp deleted file mode 100644 index d3e402ebf..000000000 --- a/tests/src/functions/logarithms/LogTests.cpp +++ /dev/null @@ -1,137 +0,0 @@ -#include -#include - -#include "fintamath/functions/logarithms/Log.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Log f; - -TEST(LogTests, toStringTest) { - EXPECT_EQ(f.toString(), "log"); -} - -TEST(LogTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic(), INumber::getClassStatic())); -} - -TEST(LogTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(LogTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(LogTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(LogTests, callTest) { - EXPECT_EQ(f(Integer(10), Integer(1))->toString(), - "0"); - EXPECT_EQ(f(Integer(0), Integer(10))->toString(), - "0"); - - EXPECT_EQ(f(Integer(10), Integer(10))->toString(), - "1"); - EXPECT_EQ(f(Integer(10), Rational(1, 10))->toString(), - "-1"); - EXPECT_EQ(f(Rational(1, 10), Integer(10))->toString(), - "-1"); - EXPECT_EQ(f(Rational(1, 10), Rational(1, 10))->toString(), - "1"); - - EXPECT_EQ(f(Integer(11), Integer(11))->toString(), - "1"); - EXPECT_EQ(f(Integer(11), Rational(1, 11))->toString(), - "-1"); - EXPECT_EQ(f(Rational(1, 11), Integer(11))->toString(), - "-1"); - EXPECT_EQ(f(Rational(1, 11), Rational(1, 11))->toString(), - "1"); - - EXPECT_EQ(f(Integer(10), Integer("10000000000000000000000000000000000000000000000000000000000"))->toString(), - "58"); - EXPECT_EQ(f(Integer("10000000000000000000000000000000000000000000000000000000000"), Integer(10))->toString(), - "1/58"); - - EXPECT_EQ(f(Integer(121), Integer(11))->toString(), - "1/2"); - EXPECT_EQ(f(Rational(1, 11), Integer(121))->toString(), - "-2"); - EXPECT_EQ(f(Rational(1, 121), Integer(11))->toString(), - "-1/2"); - EXPECT_EQ(f(Integer(121), Rational(1, 11))->toString(), - "-1/2"); - EXPECT_EQ(f(Integer(11), Rational(1, 121))->toString(), - "-2"); - - EXPECT_EQ(f(Rational(7, 9), Rational(40353607, 387420489))->toString(), - "9"); - EXPECT_EQ(f(Rational(40353607, 387420489), Rational(7, 9))->toString(), - "1/9"); - EXPECT_EQ(f(Rational(387420489, 40353607), Rational(7, 9))->toString(), - "-1/9"); - - EXPECT_EQ(f(Integer(2), Integer(10))->toString(), - "3.3219280948873623479"); - EXPECT_EQ(f(Integer(2), Integer(3))->toString(), - "1.5849625007211561815"); - EXPECT_EQ(f(Integer(10), Real(121))->toString(), - "2.0827853703164500815"); - EXPECT_EQ(f(Real(121), Integer(10))->toString(), - "0.4801262838945637487"); - EXPECT_EQ(f(1 / Real(121), Integer(10))->toString(), - "-0.4801262838945637487"); - EXPECT_EQ(f(Integer(10), 1 / Real(121))->toString(), - "-2.0827853703164500815"); - - EXPECT_EQ(f(Complex(1, 1), Complex(1, 1))->toString(), - "1"); - EXPECT_EQ(f(Complex(1, 1), Complex(1, 2))->toString(), - "log(1 + I, 1 + 2 I)"); - EXPECT_EQ(f(Complex(1, 1), Integer(1))->toString(), - "0"); - - EXPECT_EQ(f(Integer(10), Integer(0))->toString(), - "-Inf"); - EXPECT_EQ(f(Rational(1, 10), Integer(0))->toString(), - "Inf"); - EXPECT_EQ(f(Integer(1), Integer(10))->toString(), - "ComplexInf"); - EXPECT_EQ(f(Integer(1), Complex(1, 1))->toString(), - "ComplexInf"); - EXPECT_EQ(f(Integer(1), Integer(1))->toString(), - "Undefined"); - EXPECT_EQ(f(Integer(0), Integer(0))->toString(), - "Undefined"); - - EXPECT_EQ(f(Integer(-10), Integer(10))->toString(), - "log(-10, 10)"); - EXPECT_EQ(f(Integer(10), Integer(-10))->toString(), - "log(10, -10)"); - EXPECT_EQ(f(Real("-10.2"), Integer(-10))->toString(), - "log(-10.2, -10)"); - - EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), - "log(a, b)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(10)), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Log")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/logic/AndTests.cpp b/tests/src/functions/logic/AndTests.cpp deleted file mode 100644 index b8655b9cc..000000000 --- a/tests/src/functions/logic/AndTests.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include - -#include "fintamath/functions/logic/And.hpp" - -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/Variable.hpp" - -using namespace fintamath; - -const And f; - -TEST(AndTests, toStringTest) { - EXPECT_EQ(f.toString(), "&"); -} - -TEST(AndTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(Boolean::getClassStatic(), Boolean::getClassStatic())); -} - -TEST(AndTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Boolean::getClassStatic()); -} - -TEST(AndTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AndTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AndTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Conjunction); -} - -TEST(AndTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(AndTests, callTest) { - EXPECT_EQ(f(Boolean(false), Boolean(false))->toString(), "False"); - EXPECT_EQ(f(Boolean(false), Boolean(true))->toString(), "False"); - EXPECT_EQ(f(Boolean(true), Boolean(false))->toString(), "False"); - EXPECT_EQ(f(Boolean(true), Boolean(true))->toString(), "True"); - - EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "a & b"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true)), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("And")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/logic/EquivTests.cpp b/tests/src/functions/logic/EquivTests.cpp deleted file mode 100644 index 547663e0f..000000000 --- a/tests/src/functions/logic/EquivTests.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include - -#include "fintamath/functions/logic/Equiv.hpp" - -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/Variable.hpp" - -using namespace fintamath; - -const Equiv f; - -TEST(EquivTests, toStringTest) { - EXPECT_EQ(f.toString(), "<->"); -} - -TEST(EquivTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(Boolean::getClassStatic(), Boolean::getClassStatic())); -} - -TEST(EquivTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Boolean::getClassStatic()); -} - -TEST(EquivTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(EquivTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(EquivTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Equivalence); -} - -TEST(EquivTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(EquivTests, callTest) { - EXPECT_EQ(f(Boolean(false), Boolean(false))->toString(), "True"); - EXPECT_EQ(f(Boolean(false), Boolean(true))->toString(), "False"); - EXPECT_EQ(f(Boolean(true), Boolean(false))->toString(), "False"); - EXPECT_EQ(f(Boolean(true), Boolean(true))->toString(), "True"); - - EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "(a & b) | (~a & ~b)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true)), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Equiv")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/logic/ImplTests.cpp b/tests/src/functions/logic/ImplTests.cpp deleted file mode 100644 index 2db8b0533..000000000 --- a/tests/src/functions/logic/ImplTests.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include - -#include "fintamath/functions/logic/Impl.hpp" - -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/Variable.hpp" - -using namespace fintamath; - -const Impl f; - -TEST(ImplTests, toStringTest) { - EXPECT_EQ(f.toString(), "->"); -} - -TEST(ImplTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(Boolean::getClassStatic(), Boolean::getClassStatic())); -} - -TEST(ImplTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Boolean::getClassStatic()); -} - -TEST(ImplTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(ImplTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(ImplTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Implication); -} - -TEST(ImplTests, isAssociativeTest) { - EXPECT_FALSE(f.isAssociative()); -} - -TEST(ImplTests, callTest) { - EXPECT_EQ(f(Boolean(false), Boolean(false))->toString(), "True"); - EXPECT_EQ(f(Boolean(false), Boolean(true))->toString(), "True"); - EXPECT_EQ(f(Boolean(true), Boolean(false))->toString(), "False"); - EXPECT_EQ(f(Boolean(true), Boolean(true))->toString(), "True"); - - EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "~a | b"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true)), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Impl")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/logic/NequivTests.cpp b/tests/src/functions/logic/NequivTests.cpp deleted file mode 100644 index 3c04227c1..000000000 --- a/tests/src/functions/logic/NequivTests.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include - -#include "fintamath/functions/logic/Nequiv.hpp" - -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/Variable.hpp" - -using namespace fintamath; - -const Nequiv f; - -TEST(NequivTests, toStringTest) { - EXPECT_EQ(f.toString(), "!<->"); -} - -TEST(NequivTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(Boolean::getClassStatic(), Boolean::getClassStatic())); -} - -TEST(NequivTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Boolean::getClassStatic()); -} - -TEST(NequivTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(NequivTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(NequivTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Equivalence); -} - -TEST(NequivTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(NequivTests, callTest) { - EXPECT_EQ(f(Boolean(false), Boolean(false))->toString(), "False"); - EXPECT_EQ(f(Boolean(false), Boolean(true))->toString(), "True"); - EXPECT_EQ(f(Boolean(true), Boolean(false))->toString(), "True"); - EXPECT_EQ(f(Boolean(true), Boolean(true))->toString(), "False"); - - EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "(a & ~b) | (~a & b)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true)), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Nequiv")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/logic/NotTests.cpp b/tests/src/functions/logic/NotTests.cpp deleted file mode 100644 index 45f46368e..000000000 --- a/tests/src/functions/logic/NotTests.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include - -#include "fintamath/functions/logic/Not.hpp" - -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/Variable.hpp" - -using namespace fintamath; - -const Not f; - -TEST(NotTests, toStringTest) { - EXPECT_EQ(f.toString(), "~"); -} - -TEST(NotTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(Boolean::getClassStatic())); -} - -TEST(NotTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Boolean::getClassStatic()); -} - -TEST(NotTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(NotTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(NotTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::PrefixUnary); -} - -TEST(NotTests, isAssociativeTest) { - EXPECT_FALSE(f.isAssociative()); -} - -TEST(NotTests, callTest) { - EXPECT_EQ(f(Boolean(true))->toString(), "False"); - EXPECT_EQ(f(Boolean(false))->toString(), "True"); - - EXPECT_EQ(f(Variable("a"))->toString(), "~a"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true), Boolean(true)), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); -} - -TEST(NotTests, exprTest) { - EXPECT_EQ(notExpr(Boolean(true))->toString(), "~True"); -} - -TEST(NotTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Not")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/logic/OrTests.cpp b/tests/src/functions/logic/OrTests.cpp deleted file mode 100644 index b469d5d70..000000000 --- a/tests/src/functions/logic/OrTests.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include - -#include "fintamath/functions/logic/Or.hpp" - -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/Variable.hpp" - -using namespace fintamath; - -const Or f; - -TEST(OrTests, toStringTest) { - EXPECT_EQ(f.toString(), "|"); -} - -TEST(OrTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(Boolean::getClassStatic(), Boolean::getClassStatic())); -} - -TEST(OrTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Boolean::getClassStatic()); -} - -TEST(OrTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(OrTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(OrTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Disjunction); -} - -TEST(OrTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(OrTests, callTest) { - EXPECT_EQ(f(Boolean(false), Boolean(false))->toString(), "False"); - EXPECT_EQ(f(Boolean(false), Boolean(true))->toString(), "True"); - EXPECT_EQ(f(Boolean(true), Boolean(false))->toString(), "True"); - EXPECT_EQ(f(Boolean(true), Boolean(true))->toString(), "True"); - - EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "a | b"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true)), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Or")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/ntheory/CeilTests.cpp b/tests/src/functions/ntheory/CeilTests.cpp deleted file mode 100644 index 4b2c7ef16..000000000 --- a/tests/src/functions/ntheory/CeilTests.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include - -#include "fintamath/functions/ntheory/Ceil.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Ceil f; - -TEST(CeilTests, toStringTest) { - EXPECT_EQ(f.toString(), "ceil"); -} - -TEST(CeilTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(CeilTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(CeilTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(CeilTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(CeilTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(10))->toString(), "10"); - EXPECT_EQ(f(Integer(-10))->toString(), "-10"); - - EXPECT_EQ(f(Rational("-2.9"))->toString(), "-2"); - EXPECT_EQ(f(Rational("-2.2"))->toString(), "-2"); - EXPECT_EQ(f(Rational("-2"))->toString(), "-2"); - EXPECT_EQ(f(Rational("0"))->toString(), "0"); - EXPECT_EQ(f(Rational("2"))->toString(), "2"); - EXPECT_EQ(f(Rational("2.2"))->toString(), "3"); - EXPECT_EQ(f(Rational("2.9"))->toString(), "3"); - - EXPECT_EQ(f(Real("-2.9"))->toString(), "-2"); - EXPECT_EQ(f(Real("-2.2"))->toString(), "-2"); - EXPECT_EQ(f(Real("-2"))->toString(), "ceil(-2.0)"); - EXPECT_EQ(f(Real("0"))->toString(), "ceil(0.0)"); - EXPECT_EQ(f(Real("2"))->toString(), "ceil(2.0)"); - EXPECT_EQ(f(Real("2.2"))->toString(), "3"); - EXPECT_EQ(f(Real("2.9"))->toString(), "3"); - - EXPECT_EQ(f(Complex(0, 0))->toString(), "0"); - EXPECT_EQ(f(Complex(2, 0))->toString(), "2"); - EXPECT_EQ(f(Complex(0, 2))->toString(), "2 I"); - EXPECT_EQ(f(Complex(2, 2))->toString(), "2 + 2 I"); - EXPECT_EQ(f(Complex(Rational("1.1"), Rational("2.2")))->toString(), "2 + 3 I"); - EXPECT_EQ(f(Complex(Rational("1.1"), Rational("-2.2")))->toString(), "2 - 2 I"); - EXPECT_EQ(f(Complex(Rational("-1.1"), Rational("2.2")))->toString(), "-1 + 3 I"); - EXPECT_EQ(f(Complex(Rational("-1.1"), Rational("-2.2")))->toString(), "-1 - 2 I"); - EXPECT_EQ(f(Complex(Real("1.1"), Real("2.2")))->toString(), "2 + 3 I"); - EXPECT_EQ(f(Complex(Real("1.1"), Real("-2.2")))->toString(), "2 - 2 I"); - EXPECT_EQ(f(Complex(Real("-1.1"), Real("2.2")))->toString(), "-1 + 3 I"); - EXPECT_EQ(f(Complex(Real("-1.1"), Real("-2.2")))->toString(), "-1 - 2 I"); - EXPECT_EQ(f(Complex(Real("0"), Real("0")))->toString(), "ceil(0.0 + 0.0 I)"); - EXPECT_EQ(f(Complex(Real("0"), Real("0.5")))->toString(), "ceil(0.0 + 0.5 I)"); - EXPECT_EQ(f(Complex(Real("0.5"), Real("0")))->toString(), "ceil(0.5 + 0.0 I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "ceil(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(CeilTests, exprTest) { - EXPECT_EQ(ceilExpr(Integer(10))->toString(), "ceil(10)"); -} - -TEST(CeilTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Ceil")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/ntheory/FloorTests.cpp b/tests/src/functions/ntheory/FloorTests.cpp deleted file mode 100644 index bb2f678c6..000000000 --- a/tests/src/functions/ntheory/FloorTests.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include - -#include "fintamath/functions/ntheory/Floor.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Floor f; - -TEST(FloorTests, toStringTest) { - EXPECT_EQ(f.toString(), "floor"); -} - -TEST(FloorTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(FloorTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(FloorTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(FloorTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(FloorTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(10))->toString(), "10"); - EXPECT_EQ(f(Integer(-10))->toString(), "-10"); - - EXPECT_EQ(f(Rational("-2.9"))->toString(), "-3"); - EXPECT_EQ(f(Rational("-2.2"))->toString(), "-3"); - EXPECT_EQ(f(Rational("-2"))->toString(), "-2"); - EXPECT_EQ(f(Rational("0"))->toString(), "0"); - EXPECT_EQ(f(Rational("2"))->toString(), "2"); - EXPECT_EQ(f(Rational("2.2"))->toString(), "2"); - EXPECT_EQ(f(Rational("2.9"))->toString(), "2"); - - EXPECT_EQ(f(Real("-2.9"))->toString(), "-3"); - EXPECT_EQ(f(Real("-2.2"))->toString(), "-3"); - EXPECT_EQ(f(Real("-2"))->toString(), "floor(-2.0)"); - EXPECT_EQ(f(Real("0"))->toString(), "floor(0.0)"); - EXPECT_EQ(f(Real("2"))->toString(), "floor(2.0)"); - EXPECT_EQ(f(Real("2.2"))->toString(), "2"); - EXPECT_EQ(f(Real("2.9"))->toString(), "2"); - - EXPECT_EQ(f(Complex(0, 0))->toString(), "0"); - EXPECT_EQ(f(Complex(2, 0))->toString(), "2"); - EXPECT_EQ(f(Complex(0, 2))->toString(), "2 I"); - EXPECT_EQ(f(Complex(2, 2))->toString(), "2 + 2 I"); - EXPECT_EQ(f(Complex(Rational("1.1"), Rational("2.2")))->toString(), "1 + 2 I"); - EXPECT_EQ(f(Complex(Rational("1.1"), Rational("-2.2")))->toString(), "1 - 3 I"); - EXPECT_EQ(f(Complex(Rational("-1.1"), Rational("2.2")))->toString(), "-2 + 2 I"); - EXPECT_EQ(f(Complex(Rational("-1.1"), Rational("-2.2")))->toString(), "-2 - 3 I"); - EXPECT_EQ(f(Complex(Real("1.1"), Real("2.2")))->toString(), "1 + 2 I"); - EXPECT_EQ(f(Complex(Real("1.1"), Real("-2.2")))->toString(), "1 - 3 I"); - EXPECT_EQ(f(Complex(Real("-1.1"), Real("2.2")))->toString(), "-2 + 2 I"); - EXPECT_EQ(f(Complex(Real("-1.1"), Real("-2.2")))->toString(), "-2 - 3 I"); - EXPECT_EQ(f(Complex(Real("0"), Real("0")))->toString(), "floor(0.0 + 0.0 I)"); - EXPECT_EQ(f(Complex(Real("0"), Real("0.5")))->toString(), "floor(0.0 + 0.5 I)"); - EXPECT_EQ(f(Complex(Real("0.5"), Real("0")))->toString(), "floor(0.5 + 0.0 I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "floor(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(FloorTests, exprTest) { - EXPECT_EQ(floorExpr(Integer(10))->toString(), "floor(10)"); -} - -TEST(FloorTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Floor")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/ntheory/ModTests.cpp b/tests/src/functions/ntheory/ModTests.cpp deleted file mode 100644 index 60beb28cb..000000000 --- a/tests/src/functions/ntheory/ModTests.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include -#include - -#include "fintamath/functions/ntheory/Mod.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Mod f; - -TEST(ModTests, toStringTest) { - EXPECT_EQ(f.toString(), "mod"); -} - -TEST(ModTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic(), INumber::getClassStatic())); -} - -TEST(ModTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(ModTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(ModTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(ModTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Modulo); -} - -TEST(ModTests, isAssociativeTest) { - EXPECT_FALSE(f.isAssociative()); -} - -TEST(ModTests, callTest) { - EXPECT_EQ(f(Integer(0), Integer(2))->toString(), "0"); - EXPECT_EQ(f(Integer(0), Integer(-2))->toString(), "0"); - EXPECT_EQ(f(Integer(10), Integer(1))->toString(), "0"); - EXPECT_EQ(f(Integer(10), Integer(-1))->toString(), "0"); - EXPECT_EQ(f(Integer(-10), Integer(1))->toString(), "0"); - EXPECT_EQ(f(Integer(-10), Integer(-1))->toString(), "0"); - EXPECT_EQ(f(Integer(2), Integer(2))->toString(), "0"); - EXPECT_EQ(f(Integer(2), Integer(-2))->toString(), "0"); - EXPECT_EQ(f(Integer(-2), Integer(2))->toString(), "0"); - EXPECT_EQ(f(Integer(-2), Integer(-2))->toString(), "0"); - EXPECT_EQ(f(Integer(4), Integer(2))->toString(), "0"); - EXPECT_EQ(f(Integer(4), Integer(-2))->toString(), "0"); - EXPECT_EQ(f(Integer(4), Integer(2))->toString(), "0"); - EXPECT_EQ(f(Integer(4), Integer(-2))->toString(), "0"); - EXPECT_EQ(f(Integer(2), Integer(3))->toString(), "2"); - EXPECT_EQ(f(Integer(2), Integer(-3))->toString(), "-1"); - EXPECT_EQ(f(Integer(-2), Integer(3))->toString(), "1"); - EXPECT_EQ(f(Integer(-2), Integer(-3))->toString(), "-2"); - EXPECT_EQ(f(Integer(19), Integer(11))->toString(), "8"); - EXPECT_EQ(f(Integer(19), Integer(-11))->toString(), "-3"); - EXPECT_EQ(f(Integer(-19), Integer(11))->toString(), "3"); - EXPECT_EQ(f(Integer(-19), Integer(-11))->toString(), "-8"); - EXPECT_EQ(f(Integer(25), Integer(368273929))->toString(), "25"); - EXPECT_EQ(f(Integer(25), Integer(-368273929))->toString(), "-368273904"); - EXPECT_EQ(f(Integer(-25), Integer(368273929))->toString(), "368273904"); - EXPECT_EQ(f(Integer(-25), Integer(-368273929))->toString(), "-25"); - EXPECT_EQ(f(Integer(25), Integer(3))->toString(), "1"); - EXPECT_EQ(f(Integer(25), Integer(-3))->toString(), "-2"); - EXPECT_EQ(f(Integer(-25), Integer(3))->toString(), "2"); - EXPECT_EQ(f(Integer(-25), Integer(-3))->toString(), "-1"); - EXPECT_EQ(f(Integer(2000), Integer(36))->toString(), "20"); - EXPECT_EQ(f(Integer(2000), Integer(-36))->toString(), "-16"); - EXPECT_EQ(f(Integer(-2000), Integer(36))->toString(), "16"); - EXPECT_EQ(f(Integer(-2000), Integer(-36))->toString(), "-20"); - - EXPECT_EQ(f(Rational(5, 2), Rational(2, 3))->toString(), "(5/2) mod (2/3)"); - - EXPECT_EQ(f(Real("12.2"), Real("-12.2"))->toString(), "12.2 mod -12.2"); - - EXPECT_EQ(f(Complex(1, 1), Complex(2, 2))->toString(), "(1 + I) mod (2 + 2 I)"); - - EXPECT_EQ(f(Integer(1), Integer(0))->toString(), "Undefined"); - EXPECT_EQ(f(Rational(-1, 2), Integer(0))->toString(), "Undefined"); - EXPECT_EQ(f(Real("1.6"), Integer(0))->toString(), "Undefined"); - EXPECT_EQ(f(Complex(2, 2), Integer(0))->toString(), "Undefined"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "3 mod a"); - - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(ModTests, exprTest) { - EXPECT_EQ(modExpr(Integer(10), Integer(10))->toString(), "10 mod 10"); -} - -TEST(ModTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Mod")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/other/CommaTests.cpp b/tests/src/functions/other/CommaTests.cpp deleted file mode 100644 index d0a770d3e..000000000 --- a/tests/src/functions/other/CommaTests.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include - -#include "fintamath/functions/other/Comma.hpp" - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Integer.hpp" - -using namespace fintamath; - -const Comma f; - -TEST(CommaTests, toStringTest) { - EXPECT_EQ(f.toString(), ","); -} - -TEST(CommaTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IMathObject::getClassStatic(), IMathObject::getClassStatic())); -} - -TEST(CommaTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IMathObject::getClassStatic()); -} - -TEST(CommaTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(CommaTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(CommaTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Comma); -} - -TEST(CommaTests, isAssociativeTest) { - EXPECT_TRUE(f.isAssociative()); -} - -TEST(CommaTests, callTest) { - EXPECT_THROW(f(Variable("a"), Variable("a"))->toString(), InvalidInputException); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(CommaTests, exprTest) { - EXPECT_EQ(commaExpr(Variable("a"), Integer(1))->toString(), "a , 1"); -} - -TEST(CommaTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Comma")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/other/DegTests.cpp b/tests/src/functions/other/DegTests.cpp deleted file mode 100644 index b61eb4f2a..000000000 --- a/tests/src/functions/other/DegTests.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include - -#include "fintamath/functions/other/Deg.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Deg f; - -TEST(DegTests, toStringTest) { - EXPECT_EQ(f.toString(), "deg"); -} - -TEST(DegTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(DegTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(DegTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(DegTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(DegTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::PostfixUnary); -} - -TEST(DegTests, isAssociativeTest) { - EXPECT_FALSE(f.isAssociative()); -} - -TEST(DegTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(1))->toString(), "Pi/180"); - EXPECT_EQ(f(Integer(10))->toString(), "Pi/18"); - EXPECT_EQ(f(Integer(-10))->toString(), "-Pi/18"); - EXPECT_EQ(f(Rational(1, 10))->toString(), "Pi/1800"); - - EXPECT_EQ(f(Variable("a"))->toString(), "(Pi a)/180"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(DegTests, degTest) { - EXPECT_EQ(degExpr(Integer(10))->toString(), "10 Pi/180"); -} - -TEST(DegTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Deg")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/other/FactorialTests.cpp b/tests/src/functions/other/FactorialTests.cpp deleted file mode 100644 index 83cc4f5fd..000000000 --- a/tests/src/functions/other/FactorialTests.cpp +++ /dev/null @@ -1,143 +0,0 @@ -#include -#include - -#include "fintamath/functions/other/Factorial.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Factorial f; -const Factorial f2(2); -const Factorial f3(3); - -TEST(FactorialTests, toStringTest) { - EXPECT_EQ(f.toString(), "!"); -} - -TEST(FactorialTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(FactorialTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(FactorialTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(FactorialTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(FactorialTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::PostfixUnary); -} - -TEST(FactorialTests, isAssociativeTest) { - EXPECT_FALSE(f.isAssociative()); -} - -TEST(FactorialTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "1"); - EXPECT_EQ(f(Integer(1))->toString(), "1"); - EXPECT_EQ(f(Integer(2))->toString(), "2"); - EXPECT_EQ(f(Integer(3))->toString(), "6"); - EXPECT_EQ(f(Integer(4))->toString(), "24"); - EXPECT_EQ(f(Integer(5))->toString(), "120"); - EXPECT_EQ(f(Integer(10))->toString(), "3628800"); - EXPECT_EQ(f(Integer(500))->toString(), "1220136825991110068701238785423046926253574342803192842192413588385845373153881997605496447502203281863013616477148203584163378722078177200480785205159329285477907571939330603772960859086270429174547882424912726344305670173270769461062802310452644218878789465754777149863494367781037644274033827365397471386477878495438489595537537990423241061271326984327745715546309977202781014561081188373709531016356324432987029563896628911658974769572087926928871281780070265174507768410719624390394322536422605234945850129918571501248706961568141625359056693423813008856249246891564126775654481886506593847951775360894005745238940335798476363944905313062323749066445048824665075946735862074637925184200459369692981022263971952597190945217823331756934581508552332820762820023402626907898342451712006207714640979456116127629145951237229913340169552363850942885592018727433795173014586357570828355780158735432768888680120399882384702151467605445407663535984174430480128938313896881639487469658817504506926365338175055478128640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); - - EXPECT_EQ(f(Rational(10, 1))->toString(), "3628800"); - EXPECT_EQ(f(Rational(1, 10))->toString(), "0.95135076986687318363"); - EXPECT_EQ(f(Rational(-1, 10))->toString(), "1.0686287021193193549"); - - EXPECT_EQ(f(Real("0.1"))->toString(), "0.95135076986687318363"); - EXPECT_EQ(f(Real("10"))->toString(), "3628800.0"); - EXPECT_EQ(f(Real(-10))->toString(), "(-10.0)!"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "(1 + I)!"); - - EXPECT_EQ(f(Integer(-10))->toString(), "ComplexInf"); - EXPECT_EQ(f(Rational(-10))->toString(), "ComplexInf"); - - EXPECT_EQ(f(Variable("a"))->toString(), "a!"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(FactorialTests, callDoubleFactorialTest) { - EXPECT_EQ(f2(Integer(0))->toString(), "1"); - EXPECT_EQ(f2(Integer(1))->toString(), "1"); - EXPECT_EQ(f2(Integer(2))->toString(), "2"); - EXPECT_EQ(f2(Integer(3))->toString(), "3"); - EXPECT_EQ(f2(Integer(4))->toString(), "8"); - EXPECT_EQ(f2(Integer(5))->toString(), "15"); - EXPECT_EQ(f2(Integer(10))->toString(), "3840"); - EXPECT_EQ(f2(Integer(500))->toString(), "5849049697728183931901573966636399185893290101863305204136019757220414567257738129869679070426230366367652451980197858002263561449805551771020901113739313626336705563563705788360503630094403488675854668161534760788195420015279377621729517620792668944963981391489926671539372938481001173031117052763221491420281727661731208544954134335107331812412321791962113178938189516786683915122565052376248782141535507632768973188905459515532298174562947984906490257552942386774824261588679054048717674760963003462451200000000000000000000000000000000000000000000000000000000000000"); - - EXPECT_EQ(f2(Rational(10, 1))->toString(), "3840"); - EXPECT_EQ(f2(Rational(1, 10))->toString(), "(1/10)!!"); - EXPECT_EQ(f2(Rational(-1, 10))->toString(), "(-1/10)!!"); - - EXPECT_EQ(f2(Real("0.1"))->toString(), "0.1!!"); - EXPECT_EQ(f2(Real("10"))->toString(), "10.0!!"); - - EXPECT_EQ(f2(Integer(-10))->toString(), "(-10)!!"); - EXPECT_EQ(f2(Rational(-10))->toString(), "(-10)!!"); - EXPECT_EQ(f2(Real(-10))->toString(), "(-10.0)!!"); - - EXPECT_EQ(f2(Variable("a"))->toString(), "a!!"); - - EXPECT_THROW(f2(), InvalidInputFunctionException); - EXPECT_THROW(f2(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(FactorialTests, callTripleFactorialTest) { - EXPECT_EQ(f3(Integer(0))->toString(), "1"); - EXPECT_EQ(f3(Integer(1))->toString(), "1"); - EXPECT_EQ(f3(Integer(2))->toString(), "2"); - EXPECT_EQ(f3(Integer(3))->toString(), "3"); - EXPECT_EQ(f3(Integer(4))->toString(), "4"); - EXPECT_EQ(f3(Integer(5))->toString(), "10"); - EXPECT_EQ(f3(Integer(10))->toString(), "280"); - EXPECT_EQ(f3(Integer(500))->toString(), "9627993490692047015610121660806242061041980962334724315971467112857597905672427525550231392342889276669093474644610206756436530180330598715821337538360891907159788735830800163548948683344114125087443630285937857466976705253184237531544976736667589459068339188161451991788646385980337996874494685894881079941170348443108099519138035138560000000000000000000000000000000000000000000"); - - EXPECT_EQ(f3(Rational(10, 1))->toString(), "280"); - EXPECT_EQ(f3(Rational(1, 10))->toString(), "(1/10)!!!"); - EXPECT_EQ(f3(Rational(-1, 10))->toString(), "(-1/10)!!!"); - - EXPECT_EQ(f3(Real("0.1"))->toString(), "0.1!!!"); - EXPECT_EQ(f3(Real("10"))->toString(), "10.0!!!"); - - EXPECT_EQ(f3(Integer(-10))->toString(), "(-10)!!!"); - EXPECT_EQ(f3(Rational(-10))->toString(), "(-10)!!!"); - EXPECT_EQ(f3(Real(-10))->toString(), "(-10.0)!!!"); - - EXPECT_EQ(f3(Variable("a"))->toString(), "a!!!"); - - EXPECT_THROW(f3(), InvalidInputFunctionException); - EXPECT_THROW(f3(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(FactorialTests, getSetOrderTest) { - Factorial fnth; - EXPECT_EQ(fnth.getOrder(), 1); - - fnth.setOrder(123); - EXPECT_EQ(fnth.getOrder(), 123); -} - -TEST(FactorialTests, exprTest) { - EXPECT_EQ(factorialExpr(Integer(10))->toString(), "10!"); -} - -TEST(FactorialTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Factorial")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/other/IndexTests.cpp b/tests/src/functions/other/IndexTests.cpp deleted file mode 100644 index 3f147c0cd..000000000 --- a/tests/src/functions/other/IndexTests.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include - -#include "fintamath/functions/other/Index.hpp" - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Integer.hpp" - -using namespace fintamath; - -const Index f; - -TEST(IndexTests, toStringTest) { - EXPECT_EQ(f.toString(), "_"); -} - -TEST(IndexTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(Variable::getClassStatic(), Integer::getClassStatic())); -} - -TEST(IndexTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), Variable::getClassStatic()); -} - -TEST(IndexTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(IndexTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(IndexTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Exponentiation); -} - -TEST(IndexTests, isAssociativeTest) { - EXPECT_FALSE(f.isAssociative()); -} - -TEST(IndexTests, callTest) { - EXPECT_EQ(f(Expression("a"), Integer(0))->toString(), "a_0"); - EXPECT_EQ(f(Variable("a"), Integer(1))->toString(), "a_1"); - EXPECT_EQ(f(Variable("a"), Integer(2))->toString(), "a_2"); - EXPECT_EQ(f(Variable("a"), Integer("100000000000000000000000000000000"))->toString(), - "a_100000000000000000000000000000000"); - - EXPECT_THROW(f(Variable("a"), Variable("a"))->toString(), InvalidInputException); - EXPECT_THROW(f(Variable("a"), Expression("a+1"))->toString(), InvalidInputException); - EXPECT_THROW(f(Expression("a"), Integer(-1))->toString(), InvalidInputException); - EXPECT_THROW(f(Expression("1"), Integer(2))->toString(), InvalidInputException); - EXPECT_THROW(f(Expression("a+1"), Integer(2))->toString(), InvalidInputException); - EXPECT_THROW(f(Expression("a+1"), Expression("a+1"))->toString(), InvalidInputException); - EXPECT_THROW(f(Expression("a"), Expression("a>1"))->toString(), InvalidInputException); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(IndexTests, exprTest) { - EXPECT_EQ(indexExpr(Variable("a"), Integer(1))->toString(), "a_1"); -} - -TEST(IndexTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Index")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/other/PercentTests.cpp b/tests/src/functions/other/PercentTests.cpp deleted file mode 100644 index c59b87b0f..000000000 --- a/tests/src/functions/other/PercentTests.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include - -#include "fintamath/functions/other/Percent.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Percent f; - -TEST(PercentTests, toStringTest) { - EXPECT_EQ(f.toString(), "%"); -} - -TEST(PercentTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(PercentTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(PercentTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(PercentTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(PercentTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::PostfixUnary); -} - -TEST(PercentTests, isAssociativeTest) { - EXPECT_FALSE(f.isAssociative()); -} - -TEST(PercentTests, callTest) { - EXPECT_EQ(f(Integer(1))->toString(), "1/100"); - EXPECT_EQ(f(Integer(1000))->toString(), "10"); - EXPECT_EQ(f(Integer(-10))->toString(), "-1/10"); - EXPECT_EQ(f(Rational(1, 10))->toString(), "1/1000"); - - EXPECT_EQ(f(Variable("a"))->toString(), "a/100"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(PercentTests, degTest) { - EXPECT_EQ(percentExpr(Integer(10))->toString(), "10/100"); -} - -TEST(PercentTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Percent")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/powers/ExpTests.cpp b/tests/src/functions/powers/ExpTests.cpp deleted file mode 100644 index 536fcf0df..000000000 --- a/tests/src/functions/powers/ExpTests.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include - -#include "fintamath/functions/powers/Exp.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -const Exp f; - -TEST(ExpTests, toStringTest) { - EXPECT_EQ(f.toString(), "exp"); -} - -TEST(ExpTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(ExpTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(ExpTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(ExpTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(ExpTests, callTest) { - EXPECT_EQ(f(Integer(3))->toString(), "E^3"); - EXPECT_EQ(f(Integer(-3))->toString(), "1/(E^3)"); - EXPECT_EQ(f(Rational(1, 3))->toString(), "root(E, 3)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "E^a"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(ExpTests, exprTest) { - EXPECT_EQ(expExpr(Integer(10))->toString(), "E^10"); -} - -TEST(ExpTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Exp")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/powers/PowFunctionTests.cpp b/tests/src/functions/powers/PowFunctionTests.cpp deleted file mode 100644 index e6f552b12..000000000 --- a/tests/src/functions/powers/PowFunctionTests.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include - -#include "fintamath/functions/powers/PowFunction.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const PowFunction f; - -TEST(PowFunctionTests, toStringTest) { - EXPECT_EQ(f.toString(), "pow"); -} - -TEST(PowFunctionTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic(), IArithmetic::getClassStatic())); -} - -TEST(PowFunctionTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), IArithmetic::getClassStatic()); -} - -TEST(PowFunctionTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(PowFunctionTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(PowFunctionTests, callTest) { - EXPECT_EQ(f(Integer(3), Integer(2))->toString(), "9"); - EXPECT_EQ(f(Rational(-10), Rational(-3))->toString(), "-1/1000"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "3^a"); - EXPECT_EQ(f(Variable("a"), Rational(1, 2))->toString(), "sqrt(a)"); - EXPECT_EQ(f(Variable("a"), Rational(3, 2))->toString(), "a^(3/2)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(PowFunctionTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("PowFunction")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/powers/PowTests.cpp b/tests/src/functions/powers/PowTests.cpp deleted file mode 100644 index fb4d409e5..000000000 --- a/tests/src/functions/powers/PowTests.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include -#include - -#include "fintamath/functions/powers/Pow.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Pow f; - -TEST(PowTests, toStringTest) { - EXPECT_EQ(f.toString(), "^"); -} - -TEST(PowTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic(), INumber::getClassStatic())); -} - -TEST(PowTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(PowTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(PowTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(PowTests, getPriorityTest) { - EXPECT_EQ(f.getPriority(), IOperator::Priority::Exponentiation); -} - -TEST(PowTests, isAssociativeTest) { - EXPECT_FALSE(f.isAssociative()); -} - -TEST(PowTests, callTest) { - EXPECT_EQ(f(Integer(3), Integer(0))->toString(), - "1"); - EXPECT_EQ(f(Integer(3), Integer(2))->toString(), - "9"); - EXPECT_EQ(f(Integer(-3), Integer(2))->toString(), - "9"); - EXPECT_EQ(f(Integer(3), Integer(-2))->toString(), - "1/9"); - EXPECT_EQ(f(Rational(5, 2), Integer(2))->toString(), - "25/4"); - EXPECT_EQ(f(Integer(11), Integer(200))->toString(), - "18990527646046182421218204639541163405858322400098778481272514561037626461679891407506620665933284558135881805238401044949435868367905913020005911442340062387227375955664576836341689587626164144676307968892001"); - - EXPECT_EQ(f(Integer(0), Rational(1, 2))->toString(), - "0"); - EXPECT_EQ(f(Integer(4), Rational(1, 2))->toString(), - "2"); - EXPECT_EQ(f(Integer(4), Rational(1, 3))->toString(), - "root(4, 3)"); - EXPECT_EQ(f(Integer(4), Rational(1, 4))->toString(), - "sqrt(2)"); - EXPECT_EQ(f(Integer(8), Rational(1, 3))->toString(), - "2"); - EXPECT_EQ(f(Integer(16), Rational(1, 4))->toString(), - "2"); - EXPECT_EQ(f(Integer(7), Rational(1, 1000))->toString(), - "root(7, 1000)"); - EXPECT_EQ(f(Integer(4), Rational(5, 2))->toString(), - "32"); - EXPECT_EQ(f(Integer(4), Rational(5, 3))->toString(), - "8 root(2, 3)"); - EXPECT_EQ(f(Integer(4), Rational(5, 4))->toString(), - "4 sqrt(2)"); - EXPECT_EQ(f(Integer(8), Rational(5, 3))->toString(), - "32"); - EXPECT_EQ(f(Integer(16), Rational(5, 4))->toString(), - "32"); - EXPECT_EQ(f(Integer(7), Rational(3, 1000))->toString(), - "root(343, 1000)"); - EXPECT_EQ(f(Integer(1), Rational(1, 1234))->toString(), - "1"); - EXPECT_EQ(f(Integer(10000000000), Rational(1, 100))->toString(), - "root(10, 10)"); - EXPECT_EQ(f(Integer(-4), Rational(1))->toString(), - "-4"); - - EXPECT_EQ(f(*f(Integer(10), Integer(100)), Rational(1, 100))->toString(), - "10"); - EXPECT_EQ(f(*f(Integer(10), Integer(300)), Rational(1, 100))->toString(), - "1000"); - - EXPECT_EQ(f(Integer(4), Rational(-1, 2))->toString(), - "1/2"); - EXPECT_EQ(f(Integer(4), Rational(-1, 3))->toString(), - "1/root(4, 3)"); - EXPECT_EQ(f(Integer(4), Rational(-1, 4))->toString(), - "1/sqrt(2)"); - EXPECT_EQ(f(Integer(8), Rational(-1, 3))->toString(), - "1/2"); - EXPECT_EQ(f(Integer(16), Rational(-1, 4))->toString(), - "1/2"); - EXPECT_EQ(f(Integer(4), Rational(-5, 2))->toString(), - "1/32"); - EXPECT_EQ(f(Integer(4), Rational(-5, 3))->toString(), - "1/(8 root(2, 3))"); - EXPECT_EQ(f(Integer(4), Rational(-5, 4))->toString(), - "1/(4 sqrt(2))"); - EXPECT_EQ(f(Integer(8), Rational(-5, 3))->toString(), - "1/32"); - EXPECT_EQ(f(Integer(16), Rational(-5, 4))->toString(), - "1/32"); - EXPECT_EQ(f(Integer(7), Rational(-3, 1000))->toString(), - "1/root(343, 1000)"); - - EXPECT_EQ(f(Rational(-10), Rational(-3))->toString(), - "-1/1000"); - EXPECT_EQ(f(Rational(-1), Rational(-25))->toString(), - "-1"); - EXPECT_EQ(f(Rational("-2.2"), Rational(-5))->toString(), - "-3125/161051"); - EXPECT_EQ(f(Rational("2.2"), Rational(-5, 2))->toString(), - "(25 sqrt(55))/1331"); - - EXPECT_EQ(f(Real("2.2"), Real("2"))->toString(), - "4.84"); - EXPECT_EQ(f(Real("2.2"), Real("0.5"))->toString(), - "1.4832396974191325897"); - - EXPECT_EQ(f(Integer(-10), Rational(1, 2))->toString(), - "I sqrt(10)"); - EXPECT_EQ(f(Rational(-10), Real("-1.5"))->toString(), - "(-10)^(-1.5)"); // TODO: solve this - - EXPECT_EQ(f(Complex(1, 1), Integer(1))->toString(), - "1 + I"); - EXPECT_EQ(f(Complex(1, 1), Rational(1, 2))->toString(), - "sqrt(1 + I)"); - EXPECT_EQ(f(Complex(1, 1), Real("1.2"))->toString(), - "(1 + I)^1.2"); - EXPECT_EQ(f(Complex(1, 1), Complex(1, 1))->toString(), - "(1 + I)^(1 + I)"); - - EXPECT_EQ(f(Integer(0), Integer(-1))->toString(), - "ComplexInf"); - EXPECT_EQ(f(Integer(0), Integer(-10))->toString(), - "ComplexInf"); - EXPECT_EQ(f(Integer(0), Integer(0))->toString(), - "Undefined"); - - EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), - "3^a"); - EXPECT_EQ(f(Variable("a"), Rational(1, 2))->toString(), - "sqrt(a)"); - EXPECT_EQ(f(Variable("a"), Rational(3, 2))->toString(), - "a^(3/2)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Pow")); - EXPECT_EQ(f.getClass().getParent(), IOperator::getClassStatic()); -} diff --git a/tests/src/functions/powers/RootTests.cpp b/tests/src/functions/powers/RootTests.cpp deleted file mode 100644 index 2682dcfe8..000000000 --- a/tests/src/functions/powers/RootTests.cpp +++ /dev/null @@ -1,187 +0,0 @@ -#include -#include - -#include "fintamath/functions/powers/Root.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Root f; - -TEST(RootTests, toStringTest) { - EXPECT_EQ(f.toString(), "root"); -} - -TEST(RootTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic(), INumber::getClassStatic())); -} - -TEST(RootTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(RootTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(RootTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(RootTests, callTest) { - EXPECT_EQ(f(Integer(0), Integer(3))->toString(), - "0"); - EXPECT_EQ(f(Integer(10), Integer(1))->toString(), - "10"); - EXPECT_EQ(f(Integer(-10), Integer(1))->toString(), - "-10"); - EXPECT_EQ(f(Integer(100), Integer(2))->toString(), - "10"); - EXPECT_EQ(f(Integer(25), Integer(2))->toString(), - "5"); - EXPECT_EQ(f(Integer(144), Integer(2))->toString(), - "12"); - EXPECT_EQ(f(Integer("10000000000000000000000000000000000000000000000000000"), Integer(2))->toString(), - "100000000000000000000000000"); - EXPECT_EQ(f(Integer(10), Integer(2))->toString(), - "sqrt(10)"); - EXPECT_EQ(f(Integer(35), Integer(2))->toString(), - "sqrt(35)"); - EXPECT_EQ(f(Integer(4212), Integer(2))->toString(), - "18 sqrt(13)"); - EXPECT_EQ(f(Integer("992188888888"), Integer(2))->toString(), - "2 sqrt(248047222222)"); - EXPECT_EQ(f(Integer("68732648273642987365932706179432649827364"), Integer(2))->toString(), - "2 sqrt(17183162068410746841483176544858162456841)"); - EXPECT_EQ(f(Integer(100), Integer(3))->toString(), - "root(100, 3)"); - EXPECT_EQ(f(Integer(25), Integer(3))->toString(), - "root(25, 3)"); - EXPECT_EQ(f(Integer(144), Integer(3))->toString(), - "2 root(18, 3)"); - EXPECT_EQ(f(Integer("10000000000000000000000000000000000000000000000000000"), Integer(3))->toString(), - "100000000000000000 root(10, 3)"); - EXPECT_EQ(f(Integer(10), Integer(3))->toString(), - "root(10, 3)"); - EXPECT_EQ(f(Integer(35), Integer(3))->toString(), - "root(35, 3)"); - EXPECT_EQ(f(Integer(4212), Integer(3))->toString(), - "3 root(156, 3)"); - EXPECT_EQ(f(Integer("992188888888"), Integer(3))->toString(), - "2 root(124023611111, 3)"); - EXPECT_EQ(f(Integer("68732648273642987365932706179432649827364"), Integer(3))->toString(), - "root(68732648273642987365932706179432649827364, 3)"); - EXPECT_EQ(f(Integer(1024), Integer(3))->toString(), - "8 root(2, 3)"); - EXPECT_EQ(f(Integer(1024), Integer(5))->toString(), - "4"); - EXPECT_EQ(f(Integer(1024), Integer(10))->toString(), - "2"); - EXPECT_EQ(f(Integer(-1000), Integer(3))->toString(), - "root(-1000, 3)"); - EXPECT_EQ(f(Integer(-10), Integer(3))->toString(), - "root(-10, 3)"); - EXPECT_EQ(f(Integer(-100000), Integer(5))->toString(), - "root(-100000, 5)"); - EXPECT_EQ(f(Integer(-10), Integer(5))->toString(), - "root(-10, 5)"); - - EXPECT_EQ(f(Rational(25), Integer(4))->toString(), - "sqrt(5)"); - EXPECT_EQ(f(Rational(25, 169), Integer(4))->toString(), - "sqrt(65)/13"); - EXPECT_EQ(f(Rational(144, 49), Integer(4))->toString(), - "(2 sqrt(21))/7"); - EXPECT_EQ(f(Rational("1.44"), Integer(4))->toString(), - "sqrt(30)/5"); - EXPECT_EQ(f(Rational(1, 10), Integer(4))->toString(), - "1/root(10, 4)"); - EXPECT_EQ(f(Rational(25, 48), Integer(4))->toString(), - "(sqrt(5) root(27, 4))/6"); - EXPECT_EQ(f(Rational(26, 49), Integer(4))->toString(), - "(root(26, 4) sqrt(7))/7"); - EXPECT_EQ(f(Rational(45, 67), Integer(4))->toString(), - "(sqrt(3) root(1503815, 4))/67"); - EXPECT_EQ(f(Rational("68732648273642987365932706179432649827364.144"), Integer(4))->toString(), - "root(16780431707432369962385914594588049274258824218750, 4)/125"); - - EXPECT_EQ(f(Rational(25), Rational(4, 3))->toString(), - "5 sqrt(5)"); - EXPECT_EQ(f(Rational(25, 169), Rational(4, 3))->toString(), - "(5 sqrt(65))/169"); - EXPECT_EQ(f(Rational(144, 49), Rational(4, 3))->toString(), - "(24 sqrt(21))/49"); - EXPECT_EQ(f(Rational("1.44"), Rational(4, 3))->toString(), - "(6 sqrt(30))/25"); - EXPECT_EQ(f(Rational(1, 10), Rational(4, 3))->toString(), - "1/root(1000, 4)"); - EXPECT_EQ(f(Rational(25, 48), Rational(4, 3))->toString(), - "(5 sqrt(5) root(19683, 4))/216"); - EXPECT_EQ(f(Rational(26, 49), Rational(4, 3))->toString(), - "(root(17576, 4) sqrt(7))/49"); - EXPECT_EQ(f(Rational(45, 67), Rational(4, 3))->toString(), - "(3 sqrt(3) root(3400816799536868375, 4))/300763"); - EXPECT_EQ(f(Rational("68732648273642987365932706179432649827364.144"), Rational(4, 3))->toString(), - "root(79273728493821852759219484162954910061238025079805909288285023460357068666345126055475627257403374507144013103294156851180403979000, 4)/125"); - - EXPECT_EQ(f(Real(144), Integer(2))->toString(), - "12.0"); - EXPECT_EQ(f(Real(144), Integer(4))->toString(), - "3.4641016151377545871"); - EXPECT_EQ(f(Real(2), Integer(3))->toString(), - "1.2599210498948731648"); - - EXPECT_EQ(f(Real(144), Rational(2, 3))->toString(), - "1728.0"); - EXPECT_EQ(f(Real(144), Rational(4, 3))->toString(), - "41.569219381653055045"); - EXPECT_EQ(f(Real(2), Rational(3, 5))->toString(), - "3.1748021039363989495"); - - EXPECT_EQ(f(Real(2), Real("2.33"))->toString(), - "1.3464722988167144947"); - - EXPECT_EQ(f(Integer(-10), Integer(2))->toString(), - "I sqrt(10)"); - EXPECT_EQ(f(Integer(-10), Integer(4))->toString(), - "root(-10, 4)"); - EXPECT_EQ(f(Integer(-10), Integer(6))->toString(), - "root(-10, 6)"); - EXPECT_EQ(f(Rational(-9289, 10), Rational(2, 3))->toString(), - "(-9289/10)^(3/2)"); - EXPECT_EQ(f(Real(-9289), Rational(2, 3))->toString(), - "(-9289.0)^(3/2)"); // TODO: solve this - - EXPECT_EQ(f(Integer(0), Integer(-1))->toString(), - "ComplexInf"); - EXPECT_EQ(f(Integer(0), Integer(-10))->toString(), - "ComplexInf"); - EXPECT_EQ(f(Integer(0), Integer(0))->toString(), - "Undefined"); - EXPECT_EQ(f(Integer(2), Integer(0))->toString(), - "Undefined"); - - EXPECT_EQ(f(Variable("a"), Integer(2))->toString(), - "sqrt(a)"); - EXPECT_EQ(f(Variable("a"), Integer(3))->toString(), - "root(a, 3)"); - EXPECT_EQ(f(Variable("a"), Integer(123))->toString(), - "root(a, 123)"); - EXPECT_EQ(f(Integer(2), Variable("a"))->toString(), - "root(2, a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - 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, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Root")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/powers/SqrTests.cpp b/tests/src/functions/powers/SqrTests.cpp deleted file mode 100644 index 1989ccbd0..000000000 --- a/tests/src/functions/powers/SqrTests.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include - -#include "fintamath/functions/powers/Sqr.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Sqr f; - -TEST(SqrTests, toStringTest) { - EXPECT_EQ(f.toString(), "sqr"); -} - -TEST(SqrTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(SqrTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(SqrTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(SqrTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(SqrTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(100))->toString(), "10000"); - EXPECT_EQ(f(Integer(-100))->toString(), "10000"); - - EXPECT_EQ(f(Rational(3, 5))->toString(), "9/25"); - - EXPECT_EQ(f(Real("144.23"))->toString(), "20802.2929"); - - EXPECT_EQ(f(Variable("a"))->toString(), "a^2"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(SqrTests, exprTest) { - EXPECT_EQ(sqrExpr(Integer(10))->toString(), "10^2"); -} - -TEST(SqrTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Sqr")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/powers/SqrtTests.cpp b/tests/src/functions/powers/SqrtTests.cpp deleted file mode 100644 index 834bfd96a..000000000 --- a/tests/src/functions/powers/SqrtTests.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include - -#include "fintamath/functions/powers/Sqrt.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Sqrt f; - -TEST(SqrtTests, toStringTest) { - EXPECT_EQ(f.toString(), "sqrt"); -} - -TEST(SqrtTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(SqrtTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(SqrtTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(SqrtTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(SqrtTests, callTest) { - EXPECT_EQ(f(Integer(100))->toString(), "10"); - EXPECT_EQ(f(Integer(25))->toString(), "5"); - EXPECT_EQ(f(Integer(144))->toString(), "12"); - EXPECT_EQ(f(Integer("10000000000000000000000000000000000000000000000000000"))->toString(), "100000000000000000000000000"); - EXPECT_EQ(f(Integer(10))->toString(), "sqrt(10)"); - EXPECT_EQ(f(Integer(35))->toString(), "sqrt(35)"); - EXPECT_EQ(f(Integer(4212))->toString(), "18 sqrt(13)"); - EXPECT_EQ(f(Integer("992188888888"))->toString(), "2 sqrt(248047222222)"); - EXPECT_EQ(f(Integer("68732648273642987365932706179432649827364"))->toString(), "2 sqrt(17183162068410746841483176544858162456841)"); - - EXPECT_EQ(f(Rational(25))->toString(), "5"); - EXPECT_EQ(f(Rational(25, 169))->toString(), "5/13"); - EXPECT_EQ(f(Rational(144, 49))->toString(), "12/7"); - EXPECT_EQ(f(Rational("1.44"))->toString(), "6/5"); - EXPECT_EQ(f(Rational(1, 10))->toString(), "1/sqrt(10)"); - EXPECT_EQ(f(Rational(25, 48))->toString(), "5/(4 sqrt(3))"); - EXPECT_EQ(f(Rational(26, 49))->toString(), "sqrt(26)/7"); - EXPECT_EQ(f(Rational(45, 67))->toString(), "(3 sqrt(335))/67"); - EXPECT_EQ(f(Rational("68732648273642987365932706179432649827364.144"))->toString(), "sqrt(42957905171026867103707941362145406142102590)/25"); - - EXPECT_EQ(f(Real(144))->toString(), "12.0"); - EXPECT_EQ(f(Real(2))->toString(), "1.4142135623730950488"); - - EXPECT_EQ(f(Integer(-10))->toString(), "I sqrt(10)"); - EXPECT_EQ(f(Rational(-9289, 10))->toString(), "(I sqrt(92890))/10"); - EXPECT_EQ(f(Real(-9289))->toString(), "96.379458392335863966 I"); - - EXPECT_EQ(f(Variable("a"))->toString(), "sqrt(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(SqrtTests, exprTest) { - EXPECT_EQ(sqrtExpr(Integer(10))->toString(), "sqrt(10)"); -} - -TEST(SqrtTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Sqrt")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/trigonometry/AcosTests.cpp b/tests/src/functions/trigonometry/AcosTests.cpp deleted file mode 100644 index d20784e40..000000000 --- a/tests/src/functions/trigonometry/AcosTests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include "fintamath/functions/trigonometry/Acos.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Acos f; - -TEST(AcosTests, toStringTest) { - EXPECT_EQ(f.toString(), "acos"); -} - -TEST(AcosTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AcosTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AcosTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AcosTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AcosTests, callTest) { - EXPECT_EQ(f(Integer(-1))->toString(), "Pi"); - EXPECT_EQ(f(Integer(0))->toString(), "Pi/2"); - EXPECT_EQ(f(Integer(1))->toString(), "0"); - EXPECT_EQ(f(Integer(-2))->toString(), "acos(-2)"); - EXPECT_EQ(f(Integer(2))->toString(), "acos(2)"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "1.4706289056333368229"); - EXPECT_EQ(f(Rational(-1, 5))->toString(), "1.7721542475852274107"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "1.0471975511965977462"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "acos(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "acos(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AcosTests, exprTest) { - EXPECT_EQ(acosExpr(Integer(10))->toString(), "acos(10)"); -} - -TEST(AcosTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Acos")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/trigonometry/AcotTests.cpp b/tests/src/functions/trigonometry/AcotTests.cpp deleted file mode 100644 index 9fb5dea39..000000000 --- a/tests/src/functions/trigonometry/AcotTests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include "fintamath/functions/trigonometry/Acot.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Acot f; - -TEST(AcotTests, toStringTest) { - EXPECT_EQ(f.toString(), "acot"); -} - -TEST(AcotTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AcotTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AcotTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AcotTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AcotTests, callTest) { - EXPECT_EQ(f(Integer(-1))->toString(), "-Pi/4"); - EXPECT_EQ(f(Integer(0))->toString(), "Pi/2"); - EXPECT_EQ(f(Integer(1))->toString(), "Pi/4"); - EXPECT_EQ(f(Integer(-2))->toString(), "-0.46364760900080611621"); - EXPECT_EQ(f(Integer(2))->toString(), "0.46364760900080611621"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "1.4711276743037345919"); - EXPECT_EQ(f(Rational(-1, 5))->toString(), "-1.3734007669450158609"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "1.107148717794090503"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "acot(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "acot(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AcotTests, exprTest) { - EXPECT_EQ(acotExpr(Integer(10))->toString(), "acot(10)"); -} - -TEST(AcotTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Acot")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/trigonometry/AcscTests.cpp b/tests/src/functions/trigonometry/AcscTests.cpp deleted file mode 100644 index c07382cf3..000000000 --- a/tests/src/functions/trigonometry/AcscTests.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include - -#include "fintamath/functions/trigonometry/Acsc.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Acsc f; - -TEST(AcscTests, toStringTest) { - EXPECT_EQ(f.toString(), "acsc"); -} - -TEST(AcscTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AcscTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AcscTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AcscTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AcscTests, callTest) { - EXPECT_EQ(f(Integer(-1))->toString(), "-Pi/2"); - EXPECT_EQ(f(Integer(0))->toString(), "ComplexInf"); - EXPECT_EQ(f(Integer(1))->toString(), "Pi/2"); - EXPECT_EQ(f(Integer(-2))->toString(), "-0.52359877559829887308"); - EXPECT_EQ(f(Integer(2))->toString(), "0.52359877559829887308"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "acsc(1/10)"); - EXPECT_EQ(f(Rational(-1, 5))->toString(), "acsc(-1/5)"); - - EXPECT_EQ(f(Real("0.5"))->toString(), - "acsc(0.5)"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "acsc(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "acsc(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AcscTests, exprTest) { - EXPECT_EQ(acscExpr(Integer(10))->toString(), "acsc(10)"); -} - -TEST(AcscTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Acsc")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/trigonometry/AsecTests.cpp b/tests/src/functions/trigonometry/AsecTests.cpp deleted file mode 100644 index 761bf6f0e..000000000 --- a/tests/src/functions/trigonometry/AsecTests.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include - -#include "fintamath/functions/trigonometry/Asec.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Asec f; - -TEST(AsecTests, toStringTest) { - EXPECT_EQ(f.toString(), "asec"); -} - -TEST(AsecTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AsecTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AsecTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AsecTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AsecTests, callTest) { - EXPECT_EQ(f(Integer(-1))->toString(), "Pi"); - EXPECT_EQ(f(Integer(0))->toString(), "ComplexInf"); - EXPECT_EQ(f(Integer(1))->toString(), "0"); - EXPECT_EQ(f(Integer(-2))->toString(), "2.0943951023931954923"); - EXPECT_EQ(f(Integer(2))->toString(), "1.0471975511965977462"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "asec(1/10)"); - EXPECT_EQ(f(Rational(-1, 5))->toString(), "asec(-1/5)"); - - EXPECT_EQ(f(Real("0.5"))->toString(), - "asec(0.5)"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "asec(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "asec(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AsecTests, exprTest) { - EXPECT_EQ(asecExpr(Integer(10))->toString(), "asec(10)"); -} - -TEST(AsecTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Asec")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/trigonometry/AsinTests.cpp b/tests/src/functions/trigonometry/AsinTests.cpp deleted file mode 100644 index 70ee6b802..000000000 --- a/tests/src/functions/trigonometry/AsinTests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include "fintamath/functions/trigonometry/Asin.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Asin f; - -TEST(AsinTests, toStringTest) { - EXPECT_EQ(f.toString(), "asin"); -} - -TEST(AsinTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AsinTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AsinTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AsinTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AsinTests, callTest) { - EXPECT_EQ(f(Integer(-1))->toString(), "-Pi/2"); - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(1))->toString(), "Pi/2"); - EXPECT_EQ(f(Integer(-2))->toString(), "asin(-2)"); - EXPECT_EQ(f(Integer(2))->toString(), "asin(2)"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "0.10016742116155979635"); - EXPECT_EQ(f(Rational(-1, 5))->toString(), "-0.20135792079033079146"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "0.52359877559829887308"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "asin(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "asin(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AsinTests, exprTest) { - EXPECT_EQ(asinExpr(Integer(10))->toString(), "asin(10)"); -} - -TEST(AsinTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Asin")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/trigonometry/AtanTests.cpp b/tests/src/functions/trigonometry/AtanTests.cpp deleted file mode 100644 index daecb8475..000000000 --- a/tests/src/functions/trigonometry/AtanTests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include "fintamath/functions/trigonometry/Atan.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Atan f; - -TEST(AtanTests, toStringTest) { - EXPECT_EQ(f.toString(), "atan"); -} - -TEST(AtanTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(AtanTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(AtanTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(AtanTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(AtanTests, callTest) { - EXPECT_EQ(f(Integer(-1))->toString(), "-Pi/4"); - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(1))->toString(), "Pi/4"); - EXPECT_EQ(f(Integer(-2))->toString(), "-1.107148717794090503"); - EXPECT_EQ(f(Integer(2))->toString(), "1.107148717794090503"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "0.099668652491162027378"); - EXPECT_EQ(f(Rational(-1, 5))->toString(), "-0.19739555984988075837"); - - EXPECT_EQ(f(Real("0.5"))->toString(), "0.46364760900080611621"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "atan(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "atan(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(AtanTests, exprTest) { - EXPECT_EQ(atanExpr(Integer(10))->toString(), "atan(10)"); -} - -TEST(AtanTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Atan")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/trigonometry/CosTests.cpp b/tests/src/functions/trigonometry/CosTests.cpp deleted file mode 100644 index 00390d60b..000000000 --- a/tests/src/functions/trigonometry/CosTests.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include - -#include "fintamath/functions/trigonometry/Cos.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Cos f; - -TEST(CosTests, toStringTest) { - EXPECT_EQ(f.toString(), "cos"); -} - -TEST(CosTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(CosTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(CosTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(CosTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(CosTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "1"); - EXPECT_EQ(f(Integer(10))->toString(), "-0.83907152907645245226"); - EXPECT_EQ(f(Integer(5))->toString(), "0.28366218546322626447"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "0.9950041652780257661"); - - EXPECT_EQ(f(Real("1.123"))->toString(), "0.43298018843109500232"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "cos(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "cos(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(CosTests, exprTest) { - EXPECT_EQ(cosExpr(Integer(10))->toString(), "cos(10)"); -} - -TEST(CosTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Cos")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/trigonometry/CotTests.cpp b/tests/src/functions/trigonometry/CotTests.cpp deleted file mode 100644 index 1b59d95bb..000000000 --- a/tests/src/functions/trigonometry/CotTests.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include - -#include "fintamath/functions/trigonometry/Cot.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Cot f; - -TEST(CotTests, toStringTest) { - EXPECT_EQ(f.toString(), "cot"); -} - -TEST(CotTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(CotTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(CotTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(CotTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(CotTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "ComplexInf"); - EXPECT_EQ(f(Integer(10))->toString(), "1.5423510453569200483"); - EXPECT_EQ(f(Integer(-10))->toString(), "-1.5423510453569200483"); - EXPECT_EQ(f(Integer(5))->toString(), "-0.29581291553274554043"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "9.9666444232592378598"); - - EXPECT_EQ(f(Real("1.123"))->toString(), "0.48034006817334639693"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "cot(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "cot(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(CotTests, exprTest) { - EXPECT_EQ(cotExpr(Integer(10))->toString(), "cot(10)"); -} - -TEST(CotTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Cot")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/trigonometry/CscTests.cpp b/tests/src/functions/trigonometry/CscTests.cpp deleted file mode 100644 index 448ae0d1a..000000000 --- a/tests/src/functions/trigonometry/CscTests.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include - -#include "fintamath/functions/trigonometry/Csc.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Csc f; - -TEST(CscTests, toStringTest) { - EXPECT_EQ(f.toString(), "csc"); -} - -TEST(CscTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(CscTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(CscTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(CscTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(CscTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "ComplexInf"); - EXPECT_EQ(f(Integer(10))->toString(), "-1.8381639608896655887"); - EXPECT_EQ(f(Integer(5))->toString(), "-1.0428352127714058198"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "10.016686131634776649"); - - EXPECT_EQ(f(Real("1.123"))->toString(), "1.1093811703345135938"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "csc(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "csc(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(CscTests, exprTest) { - EXPECT_EQ(cscExpr(Integer(10))->toString(), "csc(10)"); -} - -TEST(CscTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Csc")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/trigonometry/SecTests.cpp b/tests/src/functions/trigonometry/SecTests.cpp deleted file mode 100644 index 7c829d22e..000000000 --- a/tests/src/functions/trigonometry/SecTests.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include - -#include "fintamath/functions/trigonometry/Sec.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Sec f; - -TEST(SecTests, toStringTest) { - EXPECT_EQ(f.toString(), "sec"); -} - -TEST(SecTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(SecTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(SecTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(SecTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(SecTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "1"); - EXPECT_EQ(f(Integer(10))->toString(), "-1.1917935066878958109"); - EXPECT_EQ(f(Integer(5))->toString(), "3.5253200858160884067"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "1.0050209184004554285"); - - EXPECT_EQ(f(Real("1.123"))->toString(), "2.3095744949058823397"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "sec(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "sec(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(SecTests, exprTest) { - EXPECT_EQ(secExpr(Integer(10))->toString(), "sec(10)"); -} - -TEST(SecTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Sec")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/trigonometry/SinTests.cpp b/tests/src/functions/trigonometry/SinTests.cpp deleted file mode 100644 index 3f12fb12e..000000000 --- a/tests/src/functions/trigonometry/SinTests.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include - -#include "fintamath/functions/trigonometry/Sin.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Sin f; - -TEST(SinTests, toStringTest) { - EXPECT_EQ(f.toString(), "sin"); -} - -TEST(SinTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(SinTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(SinTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(SinTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(SinTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(10))->toString(), "-0.5440211108893698134"); - EXPECT_EQ(f(Integer(5))->toString(), "-0.95892427466313846889"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "0.099833416646828152307"); - - EXPECT_EQ(f(Real("1.123"))->toString(), "0.90140343710581305144"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "sin(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "sin(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(SinTests, exprTest) { - EXPECT_EQ(sinExpr(Integer(10))->toString(), "sin(10)"); -} - -TEST(SinTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Sin")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/functions/trigonometry/TanTests.cpp b/tests/src/functions/trigonometry/TanTests.cpp deleted file mode 100644 index 4436c13df..000000000 --- a/tests/src/functions/trigonometry/TanTests.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include - -#include "fintamath/functions/trigonometry/Tan.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -const Tan f; - -TEST(TanTests, toStringTest) { - EXPECT_EQ(f.toString(), "tan"); -} - -TEST(TanTests, getArgumentClassesTest) { - EXPECT_THAT(f.getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); -} - -TEST(TanTests, getReturnClassTest) { - EXPECT_EQ(f.getReturnClass(), INumber::getClassStatic()); -} - -TEST(TanTests, isVariadicTest) { - EXPECT_FALSE(f.isVariadic()); -} - -TEST(TanTests, isEvaluatableTest) { - EXPECT_TRUE(f.isEvaluatable()); -} - -TEST(TanTests, callTest) { - EXPECT_EQ(f(Integer(0))->toString(), "0"); - EXPECT_EQ(f(Integer(10))->toString(), "0.64836082745908667126"); - EXPECT_EQ(f(Integer(-10))->toString(), "-0.64836082745908667126"); - EXPECT_EQ(f(Integer(5))->toString(), "-3.380515006246585637"); - - EXPECT_EQ(f(Rational(1, 10))->toString(), "0.10033467208545054506"); - - EXPECT_EQ(f(Real("1.123"))->toString(), "2.0818583879600844574"); - - EXPECT_EQ(f(Complex(1, 1))->toString(), "tan(1 + I)"); - - EXPECT_EQ(f(Variable("a"))->toString(), "tan(a)"); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); -} - -TEST(TanTests, exprTest) { - EXPECT_EQ(tanExpr(Integer(10))->toString(), "tan(10)"); -} - -TEST(TanTests, getClassTest) { - EXPECT_EQ(f.getClass(), MathObjectClass("Tan")); - EXPECT_EQ(f.getClass().getParent(), IFunction::getClassStatic()); -} diff --git a/tests/src/literals/BooleanTests.cpp b/tests/src/literals/BooleanTests.cpp deleted file mode 100644 index a4151328a..000000000 --- a/tests/src/literals/BooleanTests.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/constants/E.hpp" - -using namespace fintamath; - -TEST(BooleanTests, constructorTest) { - EXPECT_EQ(Boolean(std::string("False")), false); -} - -TEST(BooleanTests, stringConstructorTest) { - EXPECT_EQ(Boolean("True"), true); - EXPECT_EQ(Boolean("False"), false); - - EXPECT_THROW(Boolean("true"), InvalidInputException); - EXPECT_THROW(Boolean("false"), InvalidInputException); - EXPECT_THROW(Boolean("10"), InvalidInputException); - EXPECT_THROW(Boolean("i"), InvalidInputException); - EXPECT_THROW(Boolean(""), InvalidInputException); - EXPECT_THROW(Boolean(""), InvalidInputException); -} - -TEST(BooleanTests, boolConstructorTest) { - EXPECT_EQ(Boolean(true), true); - EXPECT_EQ(Boolean(false), false); -} - -TEST(BooleanTests, toStringTest) { - EXPECT_EQ(Boolean(true).toString(), "True"); - EXPECT_EQ(Boolean(false).toString(), "False"); -} - -TEST(BooleanTests, opearatorsTest) { - EXPECT_EQ(Boolean(false) && Boolean(false), false); - EXPECT_EQ(Boolean(true) && Boolean(false), false); - EXPECT_EQ(Boolean(false) && Boolean(true), false); - EXPECT_EQ(Boolean(true) && Boolean(true), true); - - EXPECT_EQ(Boolean(false) || Boolean(false), false); - EXPECT_EQ(Boolean(true) || Boolean(false), true); - EXPECT_EQ(Boolean(false) || Boolean(true), true); - EXPECT_EQ(Boolean(true) || Boolean(true), true); -} - -TEST(BooleanTest, getClassTest) { - EXPECT_EQ(Boolean().getClass(), MathObjectClass("Boolean")); - EXPECT_EQ(Boolean().getClass().getParent(), ILiteral::getClassStatic()); -} diff --git a/tests/src/literals/ILiteralTests.cpp b/tests/src/literals/ILiteralTests.cpp deleted file mode 100644 index e3b0ea6f2..000000000 --- a/tests/src/literals/ILiteralTests.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include - -#include "fintamath/literals/ILiteral.hpp" - -#include "fintamath/literals/Variable.hpp" -#include "fintamath/literals/constants/E.hpp" -#include "fintamath/literals/constants/Pi.hpp" - -using namespace fintamath; - -namespace { - -class TestLiteral final : public ILiteralCRTP { - FINTAMATH_CLASS_BODY(TestLiteral) -}; - -[[maybe_unused]] const auto config = [] { - ILiteral::registerType(); - return 0; -}(); - -} - -TEST(ILiteralTests, parseTest) { - EXPECT_TRUE(is(*ILiteral::parseFirst("TestLiteral"))); -} - -TEST(ILiteralTests, equalsTest) { - const std::unique_ptr c1 = std::make_unique(); - const std::unique_ptr c2 = std::make_unique(); - const std::unique_ptr v1 = std::make_unique("a"); - const std::unique_ptr v2 = std::make_unique("b"); - - EXPECT_EQ(*c1, *c1); - EXPECT_EQ(*c2, *c2); - EXPECT_NE(*c1, *c2); - EXPECT_NE(*c2, *c1); - - EXPECT_EQ(*v1, *v1); - EXPECT_EQ(*v2, *v2); - EXPECT_NE(*v1, *v2); - EXPECT_NE(*v2, *v1); - - EXPECT_NE(*c1, *v1); - EXPECT_NE(*c1, *v1); -} - -TEST(ILiteralTests, getClassTest) { - EXPECT_EQ(ILiteral::getClassStatic(), MathObjectClass("ILiteral")); - EXPECT_EQ(ILiteral::getClassStatic().getParent(), IMathObject::getClassStatic()); -} diff --git a/tests/src/literals/VariableTests.cpp b/tests/src/literals/VariableTests.cpp deleted file mode 100644 index 3e21e0440..000000000 --- a/tests/src/literals/VariableTests.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/literals/Variable.hpp" -#include "fintamath/literals/constants/E.hpp" - -using namespace fintamath; - -TEST(VariableTest, stringIntegerConstructorTest) { - EXPECT_EQ(Variable("a").toString(), "a"); - EXPECT_EQ(Variable("b").toString(), "b"); - EXPECT_EQ(Variable("e").toString(), "e"); - - EXPECT_EQ(Variable("a", 0).toString(), "a_0"); - EXPECT_EQ(Variable("a", 1).toString(), "a_1"); - EXPECT_EQ(Variable("a", 2).toString(), "a_2"); - EXPECT_EQ(Variable("a", Integer("100000000000000000000000000000000000000")).toString(), "a_100000000000000000000000000000000000000"); - - EXPECT_THROW(Variable(""), InvalidInputException); - EXPECT_THROW(Variable("A"), InvalidInputException); - EXPECT_THROW(Variable("B"), InvalidInputException); - EXPECT_THROW(Variable("C"), InvalidInputException); - EXPECT_THROW(Variable("1"), InvalidInputException); - EXPECT_THROW(Variable("+"), InvalidInputException); - EXPECT_THROW(Variable("!"), InvalidInputException); - EXPECT_THROW(Variable("["), InvalidInputException); - EXPECT_THROW(Variable("|"), InvalidInputException); - EXPECT_THROW(Variable("10"), InvalidInputException); - EXPECT_THROW(Variable("a1"), InvalidInputException); - EXPECT_THROW(Variable("ba"), InvalidInputException); - EXPECT_THROW(Variable("1e"), InvalidInputException); - EXPECT_THROW(Variable("A1"), InvalidInputException); - EXPECT_THROW(Variable("Bb"), InvalidInputException); - EXPECT_THROW(Variable("1C"), InvalidInputException); - - EXPECT_THROW(Variable("a", -1), InvalidInputException); - EXPECT_THROW(Variable("a", -2), InvalidInputException); - EXPECT_THROW(Variable("a", Integer("-100000000000000000000000000000000000000")), InvalidInputException); -} - -TEST(VariableTest, getClassTest) { - EXPECT_EQ(Variable("a").getClass(), MathObjectClass("Variable")); - EXPECT_EQ(Variable("a").getClass().getParent(), ILiteral::getClassStatic()); -} diff --git a/tests/src/literals/constants/ComplexInfTests.cpp b/tests/src/literals/constants/ComplexInfTests.cpp deleted file mode 100644 index 2016ba46a..000000000 --- a/tests/src/literals/constants/ComplexInfTests.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include - -#include "fintamath/literals/constants/ComplexInf.hpp" -#include "fintamath/literals/constants/Pi.hpp" - -using namespace fintamath; - -const ComplexInf c; - -TEST(ComplexInfTests, toStringTest) { - EXPECT_EQ(c.toString(), "ComplexInf"); -} - -TEST(ComplexInfTests, callTest) { - EXPECT_EQ(c()->toString(), "ComplexInf"); -} - -TEST(ComplexInfTests, getClassTest) { - EXPECT_EQ(c.getClass(), MathObjectClass("ComplexInf")); - EXPECT_EQ(c.getClass().getParent(), IConstant::getClassStatic()); -} diff --git a/tests/src/literals/constants/ETests.cpp b/tests/src/literals/constants/ETests.cpp deleted file mode 100644 index c6426cb87..000000000 --- a/tests/src/literals/constants/ETests.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include - -#include "fintamath/literals/constants/E.hpp" -#include "fintamath/literals/constants/Pi.hpp" - -using namespace fintamath; - -const E c; - -TEST(ETests, toStringTest) { - EXPECT_EQ(c.toString(), "E"); -} - -TEST(ETests, callTest) { - EXPECT_EQ(c()->toString(), "2.7182818284590452354"); -} - -TEST(ETests, getClassTest) { - EXPECT_EQ(c.getClass(), MathObjectClass("E")); - EXPECT_EQ(c.getClass().getParent(), IConstant::getClassStatic()); -} diff --git a/tests/src/literals/constants/FalseTests.cpp b/tests/src/literals/constants/FalseTests.cpp deleted file mode 100644 index 4e15beeb4..000000000 --- a/tests/src/literals/constants/FalseTests.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/constants/False.hpp" -#include "fintamath/literals/constants/Pi.hpp" - -using namespace fintamath; - -const False c; - -TEST(FalseTests, toStringTest) { - EXPECT_EQ(c.toString(), "False"); -} - -TEST(FalseTests, callTest) { - EXPECT_EQ(c()->toString(), "False"); - EXPECT_TRUE(is(c())); -} - -TEST(FalseTests, getClassTest) { - EXPECT_EQ(c.getClass(), MathObjectClass("False")); - EXPECT_EQ(c.getClass().getParent(), IConstant::getClassStatic()); -} diff --git a/tests/src/literals/constants/IConstantTests.cpp b/tests/src/literals/constants/IConstantTests.cpp deleted file mode 100644 index ca95f4b01..000000000 --- a/tests/src/literals/constants/IConstantTests.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include - -#include "fintamath/literals/constants/IConstant.hpp" - -#include "fintamath/literals/constants/E.hpp" -#include "fintamath/literals/constants/Pi.hpp" - -using namespace fintamath; - -namespace { - -class TestConstant final : public IConstantCRTP { - FINTAMATH_CLASS_BODY(TestConstant) - -protected: - std::unique_ptr call() const override { - return {}; - } -}; - -[[maybe_unused]] const auto config = [] { - IConstant::registerType(); - return 0; -}(); - -} - -TEST(IConstantTests, parseTest) { - EXPECT_TRUE(is(*IConstant::parseFirst("TestConstant"))); -} - -TEST(IConstantTests, callTest) { - const std::unique_ptr c1 = std::make_unique(); - const std::unique_ptr c2 = std::make_unique(); - - EXPECT_EQ((*c1)()->toString(), "2.7182818284590452354"); - EXPECT_EQ((*c2)()->toString(), "3.1415926535897932385"); -} - -TEST(IConstantTests, getClassTest) { - EXPECT_EQ(IConstant::getClassStatic(), MathObjectClass("IConstant")); - EXPECT_EQ(IConstant::getClassStatic().getParent(), ILiteral::getClassStatic()); -} diff --git a/tests/src/literals/constants/ITests.cpp b/tests/src/literals/constants/ITests.cpp deleted file mode 100644 index 546782604..000000000 --- a/tests/src/literals/constants/ITests.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include - -#include "fintamath/literals/constants/I.hpp" -#include "fintamath/literals/constants/Pi.hpp" - -using namespace fintamath; - -const I c; - -TEST(ITests, toStringTest) { - EXPECT_EQ(c.toString(), "I"); -} - -TEST(ITests, callTest) { - EXPECT_EQ(c()->toString(), "I"); -} - -TEST(ITests, getClassTest) { - EXPECT_EQ(c.getClass(), MathObjectClass("I")); - EXPECT_EQ(c.getClass().getParent(), IConstant::getClassStatic()); -} diff --git a/tests/src/literals/constants/InfTests.cpp b/tests/src/literals/constants/InfTests.cpp deleted file mode 100644 index 701c6604b..000000000 --- a/tests/src/literals/constants/InfTests.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include - -#include "fintamath/literals/constants/Inf.hpp" -#include "fintamath/literals/constants/Pi.hpp" - -using namespace fintamath; - -const Inf c; - -TEST(InfTests, toStringTest) { - EXPECT_EQ(c.toString(), "Inf"); -} - -TEST(InfTests, callTest) { - EXPECT_EQ(c()->toString(), "Inf"); -} - -TEST(InfTests, getClassTest) { - EXPECT_EQ(c.getClass(), MathObjectClass("Inf")); - EXPECT_EQ(c.getClass().getParent(), IConstant::getClassStatic()); -} diff --git a/tests/src/literals/constants/NegInfTests.cpp b/tests/src/literals/constants/NegInfTests.cpp deleted file mode 100644 index 7da6d8cd3..000000000 --- a/tests/src/literals/constants/NegInfTests.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include - -#include "fintamath/literals/constants/NegInf.hpp" -#include "fintamath/literals/constants/Pi.hpp" - -using namespace fintamath; - -const NegInf c; - -TEST(NegInfTests, toStringTest) { - EXPECT_EQ(c.toString(), "-Inf"); -} - -TEST(NegInfTests, callTest) { - EXPECT_EQ(c()->toString(), "-Inf"); -} - -TEST(NegInfTests, getClassTest) { - EXPECT_EQ(c.getClass(), MathObjectClass("NegInf")); - EXPECT_EQ(c.getClass().getParent(), IConstant::getClassStatic()); -} diff --git a/tests/src/literals/constants/PiTests.cpp b/tests/src/literals/constants/PiTests.cpp deleted file mode 100644 index d5eede41c..000000000 --- a/tests/src/literals/constants/PiTests.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include - -#include "fintamath/literals/constants/E.hpp" -#include "fintamath/literals/constants/Pi.hpp" - -using namespace fintamath; - -const Pi c; - -TEST(PiTests, toStringTest) { - EXPECT_EQ(c.toString(), "Pi"); -} - -TEST(PiTests, callTest) { - EXPECT_EQ(c()->toString(), "3.1415926535897932385"); -} - -TEST(PiTests, getClassTest) { - EXPECT_EQ(c.getClass(), MathObjectClass("Pi")); - EXPECT_EQ(c.getClass().getParent(), IConstant::getClassStatic()); -} diff --git a/tests/src/literals/constants/TrueTests.cpp b/tests/src/literals/constants/TrueTests.cpp deleted file mode 100644 index 8312b0c14..000000000 --- a/tests/src/literals/constants/TrueTests.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - -#include "fintamath/literals/Boolean.hpp" -#include "fintamath/literals/constants/E.hpp" -#include "fintamath/literals/constants/True.hpp" - -using namespace fintamath; - -const True c; - -TEST(TrueTests, toStringTest) { - EXPECT_EQ(c.toString(), "True"); -} - -TEST(TrueTests, callTest) { - EXPECT_EQ(c()->toString(), "True"); - EXPECT_TRUE(is(c())); -} - -TEST(TrueTests, getClassTest) { - EXPECT_EQ(c.getClass(), MathObjectClass("True")); - EXPECT_EQ(c.getClass().getParent(), IConstant::getClassStatic()); -} diff --git a/tests/src/literals/constants/UndefinedTests.cpp b/tests/src/literals/constants/UndefinedTests.cpp deleted file mode 100644 index 3a1254754..000000000 --- a/tests/src/literals/constants/UndefinedTests.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include - -#include "fintamath/literals/constants/Pi.hpp" -#include "fintamath/literals/constants/Undefined.hpp" - -using namespace fintamath; - -const Undefined c; - -TEST(UndefinedTests, toStringTest) { - EXPECT_EQ(c.toString(), "Undefined"); -} - -TEST(UndefinedTests, callTest) { - EXPECT_EQ(c()->toString(), "Undefined"); -} - -TEST(UndefinedTests, getClassTest) { - EXPECT_EQ(c.getClass(), MathObjectClass("Undefined")); - EXPECT_EQ(c.getClass().getParent(), IConstant::getClassStatic()); -} diff --git a/tests/src/numbers/ComplexTests.cpp b/tests/src/numbers/ComplexTests.cpp deleted file mode 100644 index 18c66a891..000000000 --- a/tests/src/numbers/ComplexTests.cpp +++ /dev/null @@ -1,911 +0,0 @@ -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/Complex.hpp" - -using namespace fintamath; - -TEST(ComplexTests, constructorTest) { - EXPECT_EQ(Complex(), 0); -} - -TEST(ComplexTests, moveTest) { - auto a = Complex(3); - EXPECT_EQ(a.toString(), "3"); - - auto b = std::move(a); - EXPECT_TRUE(b.toString() == "3" && &a != &b); - - a = std::move(b); - EXPECT_TRUE(a.toString() == "3" && &a != &b); - - a = std::move(a); - EXPECT_TRUE(a.toString() == "3" && &a == &a); -} - -TEST(ComplexTests, copyTest) { - auto a = Complex("3"); - EXPECT_EQ(a.toString(), "3"); - - const auto b = a; - EXPECT_TRUE(a == b && &a != &b); - - a = b; - EXPECT_TRUE(a == b && &a != &b); -} - -TEST(ComplexTests, stringConstructorTest) { - EXPECT_EQ(Complex("0"), 0); - EXPECT_EQ(Complex("1"), 1); - EXPECT_EQ(Complex("2"), 2); - EXPECT_EQ(Complex("-93"), -93); - EXPECT_EQ(Complex("-9.3").toString(), "-93/10"); - EXPECT_EQ(Complex("0989929039237832000.9302930929333").toString(), "9899290392378320009302930929333/10000000000000"); - EXPECT_EQ(Complex(".1").toString(), "1/10"); - EXPECT_EQ(Complex("1.").toString(), "1"); - - EXPECT_EQ(Complex("0I"), 0); - EXPECT_EQ(Complex("1I").toString(), "I"); - EXPECT_EQ(Complex("2I").toString(), "2 I"); - EXPECT_EQ(Complex("-93I").toString(), "-93 I"); - EXPECT_EQ(Complex("-9.3I").toString(), "-93/10 I"); - EXPECT_EQ(Complex("0989929039237832000.9302930929333I").toString(), "9899290392378320009302930929333/10000000000000 I"); - EXPECT_EQ(Complex(".1I").toString(), "1/10 I"); - EXPECT_EQ(Complex("1.I").toString(), "I"); - - EXPECT_THROW(Complex("--10"), InvalidInputException); - EXPECT_THROW(Complex("test"), InvalidInputException); - EXPECT_THROW(Complex(""), InvalidInputException); - EXPECT_THROW(Complex("+"), InvalidInputException); - EXPECT_THROW(Complex("939849.0-0023"), InvalidInputException); - EXPECT_THROW(Complex("a"), InvalidInputException); - EXPECT_THROW(Complex("a.1"), InvalidInputException); - EXPECT_THROW(Complex("1.a"), InvalidInputException); - EXPECT_THROW(Complex("1a.1"), InvalidInputException); - EXPECT_THROW(Complex("1.1a"), InvalidInputException); - EXPECT_THROW(Complex(".1."), InvalidInputException); - EXPECT_THROW(Complex("."), InvalidInputException); - EXPECT_THROW(Complex("--10.-1"), InvalidInputException); - EXPECT_THROW(Complex("10.-1"), InvalidInputException); - EXPECT_THROW(Complex("1-0.1"), InvalidInputException); - EXPECT_THROW(Complex("10-.1"), InvalidInputException); - EXPECT_THROW(Complex("10.--1"), InvalidInputException); - EXPECT_THROW(Complex("1.10.1"), InvalidInputException); - EXPECT_THROW(Complex("0II"), InvalidInputException); -} - -TEST(ComplexTests, intIntConstructorTest) { - EXPECT_EQ(Complex(2, 1).toString(), "2 + I"); - EXPECT_EQ(Complex(2, -1).toString(), "2 - I"); - EXPECT_EQ(Complex(-2, 1).toString(), "-2 + I"); - EXPECT_EQ(Complex(-2, -1).toString(), "-2 - I"); -} - -TEST(ComplexTests, numberNumberConstructorTest) { - EXPECT_EQ(Complex(Integer(2), Integer(1)).toString(), "2 + I"); - EXPECT_EQ(Complex(Integer(2), Integer(-1)).toString(), "2 - I"); - EXPECT_EQ(Complex(Integer(-2), Integer(1)).toString(), "-2 + I"); - EXPECT_EQ(Complex(Integer(-2), Integer(-1)).toString(), "-2 - I"); - - EXPECT_EQ(Complex(Rational(2, 3), Rational(1, 2)).toString(), "2/3 + 1/2 I"); - EXPECT_EQ(Complex(Rational(2, 3), Rational(-1, 2)).toString(), "2/3 - 1/2 I"); - EXPECT_EQ(Complex(Rational(-2, 3), Rational(1, 2)).toString(), "-2/3 + 1/2 I"); - EXPECT_EQ(Complex(Rational(-2, 3), Rational(-1, 2)).toString(), "-2/3 - 1/2 I"); - - EXPECT_EQ(Complex(Real("2.2"), Real("2.3545")).toString(), "2.2 + 2.3545 I"); - EXPECT_EQ(Complex(Real("-2.2"), Real("2.3545")).toString(), "-2.2 + 2.3545 I"); - EXPECT_EQ(Complex(Real("2.2"), Real("-2.3545")).toString(), "2.2 - 2.3545 I"); - EXPECT_EQ(Complex(Real("-2.2"), Real("-2.3545")).toString(), "-2.2 - 2.3545 I"); - - EXPECT_EQ(Complex(Rational(2, 3), Integer(2)).toString(), "2/3 + 2 I"); - EXPECT_EQ(Complex(Integer(3), Rational(2, 3)).toString(), "3 + 2/3 I"); - EXPECT_EQ(Complex(Real("2.2"), Integer(2)).toString(), "2.2 + 2 I"); - EXPECT_EQ(Complex(Integer(3), Real("2.2")).toString(), "3 + 2.2 I"); - EXPECT_EQ(Complex(Real("2.2"), Rational(2, 3)).toString(), "2.2 + 2/3 I"); - EXPECT_EQ(Complex(Rational(3, 2), Real("2.2")).toString(), "3/2 + 2.2 I"); - - EXPECT_THROW(Complex(Complex(), Complex()), InvalidInputException); - EXPECT_THROW(Complex(Complex(), Integer()), InvalidInputException); - EXPECT_THROW(Complex(Integer(), Complex()), InvalidInputException); - EXPECT_THROW(Complex(Complex(), Rational()), InvalidInputException); - EXPECT_THROW(Complex(Rational(), Complex()), InvalidInputException); - EXPECT_THROW(Complex(Complex(), Real()), InvalidInputException); - EXPECT_THROW(Complex(Real(), Complex()), InvalidInputException); -} - -TEST(ComplexTests, integerConstructorTest) { - EXPECT_EQ(Complex(Integer("122432964238764283746823")), Integer("122432964238764283746823")); -} - -TEST(ComplexTests, integerAssignmentOperatorTest) { - Complex b; - EXPECT_EQ(b = Integer("39743491820370928039"), Complex("39743491820370928039")); -} - -TEST(ComplexTests, rationalConstructorTest) { - EXPECT_EQ(Complex(Rational("122432964.238764283746823")), Rational(Integer("122432964238764283746823"), Integer("1000000000000000"))); -} - -TEST(ComplexTests, rationalAssignmentOperatorTest) { - Complex b; - EXPECT_EQ(b = Rational("3974349182.0370928039"), Rational(Integer("39743491820370928039"), Integer("10000000000"))); -} - -TEST(ComplexTests, realConstructorTest) { - EXPECT_EQ(Complex(Real("12243296423876.4283746823")), Real("12243296423876.4283746823")); -} - -TEST(ComplexTests, realAssignmentOperatorTest) { - Complex b; - EXPECT_EQ(b = Real("3974349182.0370928039"), Real("3974349182.0370928039")); -} - -TEST(ComplexTests, intConstructorTest) { - EXPECT_EQ(Complex(2), 2); -} - -TEST(ComplexTests, intAssignmentOperatorTest) { - Complex a; - EXPECT_EQ(a = 2, 2); -} - -TEST(ComplexTests, plusAssignmentOperatorTest) { - EXPECT_EQ(Complex(2, 3) += Complex(5, 2), Complex(7, 5)); - EXPECT_EQ(Complex(-738, 10) += Complex(5, 2), Complex(-733, 12)); - EXPECT_EQ(Complex(738, 10) += Complex(5, 2), Complex(743, 12)); - EXPECT_EQ(Complex(-738, 10) += Complex(-5, 2), Complex(-743, 12)); -} - -TEST(ComplexTests, integerPlusAssignmentOperatorTest) { - EXPECT_EQ(Complex(-10) += Integer(5), Integer(-5)); - EXPECT_EQ(Complex(2, 3) += Integer(-5), Complex(-3, 3)); -} - -TEST(ComplexTests, rationalPlusAssignmentOperatorTest) { - EXPECT_EQ(Complex(-10) += Rational(5, 2), Rational(-15, 2)); - EXPECT_EQ(Complex(2, 3) += Rational(-5, 2), Complex(Rational(-1, 2), Integer(3))); -} - -TEST(ComplexTests, realPlusAssignmentOperatorTest) { - EXPECT_EQ((Complex(-10) += Real("2.2")).toString(), "-7.8"); - EXPECT_EQ((Complex(2, 3) += Real("-2.2")).toString(), "-0.2 + 3 I"); -} - -TEST(ComplexTests, intPlusAssignmentOperatorTest) { - EXPECT_EQ(Complex(-10) += 5, -5); - EXPECT_EQ(Complex(2, 3) += -5, Complex(-3, 3)); -} - -TEST(ComplexTests, plusOperatorTest) { - EXPECT_EQ(Complex(170, 15) + Complex(-5, 2), Complex(165, 17)); - EXPECT_EQ(Complex(17, 19) + Complex(53, 5), Complex(70, 24)); - EXPECT_EQ(Complex(170, 12) + Complex(2, 5), Complex(172, 17)); -} - -TEST(ComplexTests, integerPlusOperatorTest) { - EXPECT_EQ(Complex(170) + Integer(-5), 165); - EXPECT_EQ(Complex(170, 12) + Integer(2), Complex(172, 12)); -} - -TEST(ComplexTests, rationalPlusOperatorTest) { - EXPECT_EQ(Complex(170) + Rational(-5, 2), Rational(335, 2)); - EXPECT_EQ(Complex(170, 12) + Rational(2, 5), Complex(Rational(852, 5), Integer(12))); -} - -TEST(ComplexTests, realPlusOperatorTest) { - EXPECT_EQ((Complex(170) + Real("2.4")).toString(), "172.4"); - EXPECT_EQ((Complex(170, 12) + Real("2.5")).toString(), "172.5 + 12 I"); -} - -TEST(ComplexTests, intPlusOperatorTest) { - EXPECT_EQ(Complex(170) + -5, 165); - EXPECT_EQ(Complex(170, 12) + 2, Complex(172, 12)); -} - -TEST(ComplexTests, integerFriendPlusOperatorTest) { - EXPECT_EQ(Integer(-5) + Complex(170), 165); - EXPECT_EQ(Integer(2) + Complex(170, 12), Complex(172, 12)); -} - -TEST(ComplexTests, rationalFriendPlusOperatorTest) { - EXPECT_EQ(Rational(-5, 2) + Complex(170), Rational(335, 2)); - EXPECT_EQ(Rational(2, 5) + Complex(170, 12), Complex(Rational(852, 5), Integer(12))); -} - -TEST(ComplexTests, realFriendPlusOperatorTest) { - EXPECT_EQ((Real("2.4") + Complex(170)).toString(), "172.4"); - EXPECT_EQ((Real("2.5") + Complex(170, 12)).toString(), "172.5 + 12 I"); -} - -TEST(ComplexTests, intFriendPlusOperatorTest) { - EXPECT_EQ(-5 + Complex(170), 165); - EXPECT_EQ(2 + Complex(170, 12), Complex(172, 12)); -} - -TEST(ComplexTests, minusAssignmentOperatorTest) { - EXPECT_EQ(Complex(2, 3) -= Complex(5, 2), Complex(-3, 1)); - EXPECT_EQ(Complex(-738, 10) -= Complex(5, 2), Complex(-743, 8)); - EXPECT_EQ(Complex(738, 10) -= Complex(5, 2), Complex(733, 8)); - EXPECT_EQ(Complex(-738, 10) -= Complex(-5, 2), Complex(-733, 8)); -} - -TEST(ComplexTests, integerMinusAssignmentOperatorTest) { - EXPECT_EQ(Complex(-10) -= Integer(5), Integer(-15)); - EXPECT_EQ(Complex(2, 3) -= Integer(-5), Complex(7, 3)); -} - -TEST(ComplexTests, rationalMinusAssignmentOperatorTest) { - EXPECT_EQ(Complex(-10) -= Rational(5, 2), Rational(-25, 2)); - EXPECT_EQ(Complex(2, 3) -= Rational(-5, 2), Complex(Rational(9, 2), Integer(3))); -} - -TEST(ComplexTests, realMinusAssignmentOperatorTest) { - EXPECT_EQ((Complex(-10) -= Real("2.2")).toString(), "-12.2"); - EXPECT_EQ((Complex(2, 3) -= Real("-2.2")).toString(), "4.2 + 3 I"); -} - -TEST(ComplexTests, intMinusAssignmentOperatorTest) { - EXPECT_EQ(Complex(-10) -= 5, -15); - EXPECT_EQ(Complex(2, 3) -= -5, Complex(7, 3)); -} - -TEST(ComplexTests, minusOperatorTest) { - EXPECT_EQ(Complex(170, 15) - Complex(-5, 2), Complex(175, 13)); - EXPECT_EQ(Complex(17, 19) - Complex(53, 5), Complex(-36, 14)); - EXPECT_EQ(Complex(170, 12) - Complex(2, 5), Complex(168, 7)); -} - -TEST(ComplexTests, integerMinusOperatorTest) { - EXPECT_EQ(Complex(170) - Integer(-5), 175); - EXPECT_EQ(Complex(170, 12) - Integer(2), Complex(168, 12)); -} - -TEST(ComplexTests, rationalMinusOperatorTest) { - EXPECT_EQ(Complex(170) - Rational(-5, 2), Rational(345, 2)); - EXPECT_EQ(Complex(170, 12) - Rational(2, 5), Complex(Rational(848, 5), Integer(12))); -} - -TEST(ComplexTests, realMinusOperatorTest) { - EXPECT_EQ((Complex(170) - Real("2.4")).toString(), "167.6"); - EXPECT_EQ((Complex(170, 12) - Real("2.5")).toString(), "167.5 + 12 I"); -} - -TEST(ComplexTests, intMinusOperatorTest) { - EXPECT_EQ(Complex(170) - -5, 175); - EXPECT_EQ(Complex(170, 12) - 2, Complex(168, 12)); -} - -TEST(ComplexTests, integerFriendMinusOperatorTest) { - EXPECT_EQ(Integer(-5) - Complex(170), -175); - EXPECT_EQ(Integer(2) - Complex(170, 12), Complex(-168, -12)); -} - -TEST(ComplexTests, rationalFriendMinusOperatorTest) { - EXPECT_EQ(Rational(-5, 2) - Complex(170), Rational(-345, 2)); - EXPECT_EQ(Rational(2, 5) - Complex(170, 12), Complex(Rational(-848, 5), Integer(-12))); -} - -TEST(ComplexTests, realFriendMinusOperatorTest) { - EXPECT_EQ((Real("2.4") - Complex(170)).toString(), "-167.6"); - EXPECT_EQ((Real("2.5") - Complex(170, 12)).toString(), "-167.5 - 12 I"); -} - -TEST(ComplexTests, intFriendMinusOperatorTest) { - EXPECT_EQ(-5 - Complex(170), -175); - EXPECT_EQ(2 - Complex(170, 12), Complex(-168, -12)); -} - -TEST(ComplexTests, multiplyAssignmentOperatorTest) { - EXPECT_EQ(Complex(0, 0) *= Complex(0, 0), Complex(0)); - EXPECT_EQ(Complex(0, 0) *= Complex(0, 2), Complex(0)); - EXPECT_EQ(Complex(0, 0) *= Complex(2, 0), Complex(0)); - EXPECT_EQ(Complex(0, 0) *= Complex(2, 2), Complex(0)); - EXPECT_EQ(Complex(0, 2) *= Complex(0, 0), Complex(0)); - EXPECT_EQ(Complex(0, 2) *= Complex(0, 2), Complex(-4)); - EXPECT_EQ(Complex(0, 2) *= Complex(2, 0), Complex(0, 4)); - EXPECT_EQ(Complex(0, 2) *= Complex(2, 2), Complex(-4, 4)); - EXPECT_EQ(Complex(2, 0) *= Complex(0, 0), Complex(0)); - EXPECT_EQ(Complex(2, 0) *= Complex(0, 2), Complex(0, 4)); - EXPECT_EQ(Complex(2, 0) *= Complex(2, 0), Complex(4)); - EXPECT_EQ(Complex(2, 0) *= Complex(2, 2), Complex(4, 4)); - EXPECT_EQ(Complex(2, 2) *= Complex(0, 0), Complex(0)); - EXPECT_EQ(Complex(2, 2) *= Complex(0, 2), Complex(-4, 4)); - EXPECT_EQ(Complex(2, 2) *= Complex(2, 0), Complex(4, 4)); - EXPECT_EQ(Complex(2, 2) *= Complex(2, 2), Complex(0, 8)); - - EXPECT_EQ(Complex(0, 0) *= Complex(0, 0), Complex(0)); - EXPECT_EQ(Complex(0, 0) *= Complex(0, -2), Complex(0)); - EXPECT_EQ(Complex(0, 0) *= Complex(-2, 0), Complex(0)); - EXPECT_EQ(Complex(0, 0) *= Complex(-2, -2), Complex(0)); - EXPECT_EQ(Complex(0, 2) *= Complex(0, 0), Complex(0)); - EXPECT_EQ(Complex(0, 2) *= Complex(0, -2), Complex(4)); - EXPECT_EQ(Complex(0, 2) *= Complex(-2, 0), Complex(0, -4)); - EXPECT_EQ(Complex(0, 2) *= Complex(-2, -2), Complex(4, -4)); - EXPECT_EQ(Complex(2, 0) *= Complex(0, 0), Complex(0)); - EXPECT_EQ(Complex(2, 0) *= Complex(0, -2), Complex(0, -4)); - EXPECT_EQ(Complex(2, 0) *= Complex(-2, 0), Complex(-4)); - EXPECT_EQ(Complex(2, 0) *= Complex(-2, -2), Complex(-4, -4)); - EXPECT_EQ(Complex(2, 2) *= Complex(0, 0), Complex(0)); - EXPECT_EQ(Complex(2, 2) *= Complex(0, -2), Complex(4, -4)); - EXPECT_EQ(Complex(2, 2) *= Complex(-2, 0), Complex(-4, -4)); - EXPECT_EQ(Complex(2, 2) *= Complex(-2, -2), Complex(0, -8)); - - EXPECT_EQ(Complex(2, 3) *= Complex(1, 0), Complex(2, 3)); - EXPECT_EQ(Complex(2, 3) *= Complex(0, 1), Complex(-3, 2)); - EXPECT_EQ(Complex(2, 3) *= Complex(1, 1), Complex(-1, 5)); - - EXPECT_EQ(Complex(738, 10) *= Complex(5, 2), Complex(3670, 1526)); - EXPECT_EQ(Complex(-738, 10) *= Complex(5, 2), Complex(-3710, -1426)); - EXPECT_EQ(Complex(-738, 10) *= Complex(-5, 2), Complex(3670, -1526)); -} - -TEST(ComplexTests, integerMultiplyAssignmentOperatorTest) { - EXPECT_EQ(Complex(-10) *= Integer(5), Integer(-50)); - EXPECT_EQ(Complex(2, 3) *= Integer(-5), Complex(-10, -15)); -} - -TEST(ComplexTests, rationalMultiplyAssignmentOperatorTest) { - EXPECT_EQ(Complex(-10) *= Rational(5, 2), Integer(-25)); - EXPECT_EQ(Complex(2, 3) *= Rational(-5, 2), Complex(Integer(-5), Rational(-15, 2))); -} - -TEST(ComplexTests, realMultiplyAssignmentOperatorTest) { - EXPECT_EQ((Complex(-10) *= Real("2.2")).toString(), "-22.0"); - EXPECT_EQ((Complex(2, 3) *= Real("-2.2")).toString(), "-4.4 - 6.6 I"); -} - -TEST(ComplexTests, intMultiplyAssignmentOperatorTest) { - EXPECT_EQ(Complex(-10) *= 5, -50); - EXPECT_EQ(Complex(2, 3) *= -5, Complex(-10, -15)); -} - -TEST(ComplexTests, multiplyOperatorTest) { - EXPECT_EQ(Complex(170, 15) * Complex(-5, 2), Complex(-880, 265)); - EXPECT_EQ(Complex(17, 19) * Complex(53, 5), Complex(806, 1092)); - EXPECT_EQ(Complex(170, 12) * Complex(2, 5), Complex(280, 874)); -} - -TEST(ComplexTests, integerMultiplyOperatorTest) { - EXPECT_EQ(Complex(170) * Integer(-5), -850); - EXPECT_EQ(Complex(170, 12) * Integer(2), Complex(340, 24)); -} - -TEST(ComplexTests, rationalMultiplyOperatorTest) { - EXPECT_EQ(Complex(170) * Rational(-5, 2), Integer(-425)); - EXPECT_EQ(Complex(170, 12) * Rational(2, 5), Complex(Integer(68), Rational(24, 5))); -} - -TEST(ComplexTests, realMultiplyOperatorTest) { - EXPECT_EQ((Complex(170) * Real("2.4")).toString(), "408.0"); - EXPECT_EQ((Complex(170, 12) * Real("2.5")).toString(), "425.0 + 30.0 I"); -} - -TEST(ComplexTests, intMultiplyOperatorTest) { - EXPECT_EQ(Complex(170) * -5, -850); - EXPECT_EQ(Complex(170, 12) * 2, Complex(340, 24)); -} - -TEST(ComplexTests, integerFriendMultiplyOperatorTest) { - EXPECT_EQ(Integer(-5) * Complex(170), -850); - EXPECT_EQ(Integer(2) * Complex(170, 12), Complex(340, 24)); -} - -TEST(ComplexTests, rationalFriendMultiplyOperatorTest) { - EXPECT_EQ(Rational(-5, 2) * Complex(170), Rational(-425)); - EXPECT_EQ(Rational(2, 5) * Complex(170, 12), Complex(Integer(68), Rational(24, 5))); -} - -TEST(ComplexTests, realFriendMultiplyOperatorTest) { - EXPECT_EQ((Real("2.4") * Complex(170)).toString(), "408.0"); - EXPECT_EQ((Real("2.5") * Complex(170, 12)).toString(), "425.0 + 30.0 I"); -} - -TEST(ComplexTests, intFriendMultiplyOperatorTest) { - EXPECT_EQ(-5 * Complex(170), -850); - EXPECT_EQ(2 * Complex(170, 12), Complex(340, 24)); -} - -TEST(ComplexTests, divideAssignmentOperatorTest) { - EXPECT_EQ(Complex(0, 0) /= Complex(0, 2), Complex(0)); - EXPECT_EQ(Complex(0, 0) /= Complex(2, 0), Complex(0)); - EXPECT_EQ(Complex(0, 0) /= Complex(2, 2), Complex(0)); - EXPECT_EQ(Complex(0, 2) /= Complex(0, 2), Complex(1)); - EXPECT_EQ(Complex(0, 2) /= Complex(2, 0), Complex(0, 1)); - EXPECT_EQ(Complex(0, 2) /= Complex(2, 2), Complex(Rational(1, 2), Rational(1, 2))); - EXPECT_EQ(Complex(2, 0) /= Complex(0, 2), Complex(0, -1)); - EXPECT_EQ(Complex(2, 0) /= Complex(2, 0), Complex(1)); - EXPECT_EQ(Complex(2, 0) /= Complex(2, 2), Complex(Rational(1, 2), Rational(-1, 2))); - EXPECT_EQ(Complex(2, 2) /= Complex(0, 2), Complex(1, -1)); - EXPECT_EQ(Complex(2, 2) /= Complex(2, 0), Complex(1, 1)); - EXPECT_EQ(Complex(2, 2) /= Complex(2, 2), Complex(1)); - - EXPECT_EQ(Complex(0, 0) /= Complex(0, -2), Complex(0)); - EXPECT_EQ(Complex(0, 0) /= Complex(-2, 0), Complex(0)); - EXPECT_EQ(Complex(0, 0) /= Complex(-2, -2), Complex(0)); - EXPECT_EQ(Complex(0, 2) /= Complex(0, -2), Complex(-1)); - EXPECT_EQ(Complex(0, 2) /= Complex(-2, 0), Complex(0, -1)); - EXPECT_EQ(Complex(0, 2) /= Complex(-2, -2), Complex(Rational(-1, 2), Rational(-1, 2))); - EXPECT_EQ(Complex(2, 0) /= Complex(0, -2), Complex(0, 1)); - EXPECT_EQ(Complex(2, 0) /= Complex(-2, 0), Complex(-1)); - EXPECT_EQ(Complex(2, 0) /= Complex(-2, -2), Complex(Rational(-1, 2), Rational(1, 2))); - EXPECT_EQ(Complex(2, 2) /= Complex(0, -2), Complex(-1, 1)); - EXPECT_EQ(Complex(2, 2) /= Complex(-2, 0), Complex(-1, -1)); - EXPECT_EQ(Complex(2, 2) /= Complex(-2, -2), Complex(-1)); - - EXPECT_EQ(Complex(2, 3) /= Complex(1, 0), Complex(2, 3)); - EXPECT_EQ(Complex(2, 3) /= Complex(0, 1), Complex(3, -2)); - EXPECT_EQ(Complex(2, 3) /= Complex(1, 1), Complex(Rational(5, 2), Rational(1, 2))); - - EXPECT_EQ(Complex(738, 10) /= Complex(5, 2), Complex(Rational(3710, 29), Rational(-1426, 29))); - EXPECT_EQ(Complex(-738, 10) /= Complex(5, 2), Complex(Rational(-3670, 29), Rational(1526, 29))); - EXPECT_EQ(Complex(-738, 10) /= Complex(-5, 2), Complex(Rational(3710, 29), Rational(1426, 29))); - - EXPECT_THROW(Complex(0, 0) /= Complex(0, 0), UndefinedException); - EXPECT_THROW(Complex(2, 3) /= Complex(0, 0), UndefinedException); -} - -TEST(ComplexTests, integerDivideAssignmentOperatorTest) { - EXPECT_EQ(Complex(-10) /= Integer(5), Integer(-2)); - EXPECT_EQ(Complex(2, 3) /= Integer(-5), Complex(Rational(-2, 5), Rational(-3, 5))); -} - -TEST(ComplexTests, rationalDivideAssignmentOperatorTest) { - EXPECT_EQ(Complex(-10) /= Rational(5, 2), Integer(-4)); - EXPECT_EQ(Complex(2, 3) /= Rational(-5, 2), Complex(Rational(-4, 5), Rational(-6, 5))); -} - -TEST(ComplexTests, realDivideAssignmentOperatorTest) { - EXPECT_EQ((Complex(-10) /= Real("2.2")).toString(), "-4.5454545454545454545"); - EXPECT_EQ((Complex(2, 3) /= Real("-2.2")).toString(), "-0.90909090909090909091 - 1.3636363636363636364 I"); -} - -TEST(ComplexTests, intDivideAssignmentOperatorTest) { - EXPECT_EQ(Complex(-10) /= 5, -2); - EXPECT_EQ(Complex(2, 3) /= -5, Complex(Rational(-2, 5), Rational(-3, 5))); -} - -TEST(ComplexTests, divideOperatorTest) { - EXPECT_EQ(Complex(170, 15) / Complex(-5, 2), Complex(Rational(-820, 29), Rational(-415, 29))); - EXPECT_EQ(Complex(17, 19) / Complex(53, 5), Complex(Rational(498, 1417), Rational(461, 1417))); - EXPECT_EQ(Complex(170, 12) / Complex(2, 5), Complex(Rational(400, 29), Rational(-826, 29))); -} - -TEST(ComplexTests, integerDivideOperatorTest) { - EXPECT_EQ(Complex(170) / Integer(-5), -34); - EXPECT_EQ(Complex(170, 12) / Integer(2), Complex(85, 6)); -} - -TEST(ComplexTests, rationalDivideOperatorTest) { - EXPECT_EQ(Complex(170) / Rational(-5, 2), Integer(-68)); - EXPECT_EQ(Complex(170, 12) / Rational(2, 5), Complex(425, 30)); -} - -TEST(ComplexTests, realDivideOperatorTest) { - EXPECT_EQ((Complex(170) / Real("2.4")).toString(), "70.833333333333333333"); - EXPECT_EQ((Complex(170, 12) / Real("2.5")).toString(), "68.0 + 4.8 I"); -} - -TEST(ComplexTests, intDivideOperatorTest) { - EXPECT_EQ(Complex(170) / -5, -34); - EXPECT_EQ(Complex(170, 12) / 2, Complex(85, 6)); -} - -TEST(ComplexTests, integerFriendDivideOperatorTest) { - EXPECT_EQ(Integer(-5) / Complex(170), Rational(-1, 34)); - EXPECT_EQ(Integer(2) / Complex(170, 12), Complex(Rational(85, 7261), Rational(-6, 7261))); -} - -TEST(ComplexTests, rationalFriendDivideOperatorTest) { - EXPECT_EQ(Rational(-5, 2) / Complex(170), Rational(-1, 68)); - EXPECT_EQ(Rational(2, 5) / Complex(170, 12), Complex(Rational(17, 7261), Rational(-6, 36305))); -} - -TEST(ComplexTests, realFriendDivideOperatorTest) { - EXPECT_EQ((Real("2.4") / Complex(170)).toString(), "0.014117647058823529412"); - EXPECT_EQ((Real("2.5") / Complex(170, 12)).toString(), "0.01463297066519763118 - 0.0010329155763668916127 I"); -} - -TEST(ComplexTests, intFriendDivideOperatorTest) { - EXPECT_EQ(-5 / Complex(170), Rational(-1, 34)); - EXPECT_EQ(2 / Complex(170, 12), Complex(Rational(85, 7261), Rational(-6, 7261))); -} - -TEST(ComplexTests, unaryPlusOperatorTest) { - EXPECT_EQ(+Complex(-5), -5); - EXPECT_EQ(+Complex(-5, 2), Complex(-5, 2)); -} - -TEST(ComplexTests, unaryMinusOperatorTest) { - EXPECT_EQ(-Complex(5), -5); - EXPECT_EQ(-Complex(-5, 2), Complex(5, -2)); -} - -TEST(ComplexTests, equalOperatorTest) { - EXPECT_TRUE(Complex(1, 2) == Complex(1, 2)); - EXPECT_TRUE(Complex(2, 0) == Complex(2, 0)); - EXPECT_TRUE(Complex(0, 2) == Complex(0, 2)); - - EXPECT_FALSE(Complex(1, 2) == Complex(1, 3)); - EXPECT_FALSE(Complex(1, 2) == Complex(2, 2)); - EXPECT_FALSE(Complex(3, 2) == Complex(2, 3)); -} - -TEST(ComplexTests, integerEqualOperatorTest) { - EXPECT_TRUE(Complex(500) == Integer(500)); -} - -TEST(ComplexTests, rationalEqualOperatorTest) { - EXPECT_TRUE(Complex(Rational(1, 2)) == Rational(1, 2)); -} - -TEST(ComplexTests, realEqualOperatorTest) { - EXPECT_TRUE(Complex(Real("2.2")) == Real("2.2")); -} - -TEST(ComplexTests, intEqualOperatorTest) { - EXPECT_TRUE(Complex(500) == 500); -} - -TEST(ComplexTests, integerFriendEqualOperatorTest) { - EXPECT_TRUE(Integer(500) == Complex(500)); -} - -TEST(ComplexTests, rationalFriendEqualOperatorTest) { - EXPECT_TRUE(Rational(1, 2) == Complex(Rational(1, 2))); -} - -TEST(ComplexTests, realFriendEqualOperatorTest) { - EXPECT_TRUE(Real("2.2") == Complex(Real("2.2"))); -} - -TEST(ComplexTests, intFriendEqualOperatorTest) { - EXPECT_TRUE(500 == Complex(500)); -} - -TEST(ComplexTests, notEqualOperatorTest) { - EXPECT_FALSE(Complex(1, 2) != Complex(1, 2)); - EXPECT_FALSE(Complex(2, 0) != Complex(2, 0)); - EXPECT_FALSE(Complex(0, 2) != Complex(0, 2)); - - EXPECT_TRUE(Complex(1, 2) != Complex(1, 3)); - EXPECT_TRUE(Complex(1, 2) != Complex(2, 2)); - EXPECT_TRUE(Complex(3, 2) != Complex(2, 3)); -} - -TEST(ComplexTests, integerNotEqualOperatorTest) { - EXPECT_FALSE(Complex(500) != Integer(500)); -} - -TEST(ComplexTests, rationalNotEqualOperatorTest) { - EXPECT_FALSE(Complex(Rational(1, 2)) != Rational(1, 2)); -} - -TEST(ComplexTests, realNotEqualOperatorTest) { - EXPECT_FALSE(Complex(Real("2.2")) != Real("2.2")); -} - -TEST(ComplexTests, intNotEqualOperatorTest) { - EXPECT_FALSE(Complex(500) != 500); -} - -TEST(ComplexTests, integerFriendNotEqualOperatorTest) { - EXPECT_FALSE(Integer(500) != Complex(500)); -} - -TEST(ComplexTests, rationalFriendNotEqualOperatorTest) { - EXPECT_FALSE(Rational(1, 2) != Complex(Rational(1, 2))); -} - -TEST(ComplexTests, realFriendNotEqualOperatorTest) { - EXPECT_FALSE(Real("2.2") != Complex(Real("2.2"))); -} - -TEST(ComplexTests, intFriendNotEqualOperatorTest) { - EXPECT_FALSE(500 != Complex(500)); -} - -TEST(ComplexTests, lessOperatorTest) { - EXPECT_FALSE(Complex(0, 0) < Complex(0, 0)); - EXPECT_TRUE(Complex(0, 0) < Complex(0, 1)); - EXPECT_TRUE(Complex(0, 0) < Complex(1, 0)); - EXPECT_TRUE(Complex(0, 0) < Complex(1, 1)); - - EXPECT_FALSE(Complex(1, 1) < Complex(1, 1)); - EXPECT_TRUE(Complex(1, 1) < Complex(1, 2)); - EXPECT_TRUE(Complex(1, 1) < Complex(2, 1)); - EXPECT_TRUE(Complex(1, 1) < Complex(2, 2)); - - EXPECT_TRUE(Complex(1, 2) < Complex(2, 1)); - EXPECT_FALSE(Complex(2, 1) < Complex(1, 2)); - - EXPECT_FALSE(Complex(0, 0) < Complex(0, -1)); - EXPECT_FALSE(Complex(0, 0) < Complex(-1, 0)); - EXPECT_FALSE(Complex(0, 0) < Complex(-1, -1)); - - EXPECT_FALSE(Complex(-1, -1) < Complex(-1, -1)); - EXPECT_FALSE(Complex(-1, -1) < Complex(-1, -2)); - EXPECT_FALSE(Complex(-1, -1) < Complex(-2, -1)); - EXPECT_FALSE(Complex(-1, -1) < Complex(-2, -2)); - - EXPECT_FALSE(Complex(-1, -2) < Complex(-2, -1)); - EXPECT_TRUE(Complex(-2, -1) < Complex(-1, -2)); -} - -TEST(ComplexTests, integerLessOperatorTest) { - EXPECT_TRUE(Complex(500, 1) < Integer(501)); -} - -TEST(ComplexTests, rationalLessOperatorTest) { - EXPECT_FALSE(Complex(Rational(1, 2), Integer(1)) < Rational(1, 3)); -} - -TEST(ComplexTests, realLessOperatorTest) { - EXPECT_TRUE(Complex(Real("2.2"), Integer(1)) < Real("2.3")); -} - -TEST(ComplexTests, intLessOperatorTest) { - EXPECT_TRUE(Complex(500, 1) < 501); -} - -TEST(ComplexTests, integerFriendLessOperatorTest) { - EXPECT_TRUE(Integer(500) < Complex(501, 1)); -} - -TEST(ComplexTests, rationalFriendLessOperatorTest) { - EXPECT_FALSE(Rational(1, 2) < Complex(Rational(1, 3), Integer(1))); -} - -TEST(ComplexTests, realFriendLessOperatorTest) { - EXPECT_TRUE(Real("2.2") < Complex(Real("2.3"), Integer(1))); -} - -TEST(ComplexTests, intFriendLessOperatorTest) { - EXPECT_TRUE(500 < Complex(501, 1)); -} - -TEST(ComplexTests, moreOperatorTest) { - EXPECT_FALSE(Complex(0, 0) > Complex(0, 0)); - EXPECT_FALSE(Complex(0, 0) > Complex(0, 1)); - EXPECT_FALSE(Complex(0, 0) > Complex(1, 0)); - EXPECT_FALSE(Complex(0, 0) > Complex(1, 1)); - - EXPECT_FALSE(Complex(1, 1) > Complex(1, 1)); - EXPECT_FALSE(Complex(1, 1) > Complex(1, 2)); - EXPECT_FALSE(Complex(1, 1) > Complex(2, 1)); - EXPECT_FALSE(Complex(1, 1) > Complex(2, 2)); - - EXPECT_FALSE(Complex(1, 2) > Complex(2, 1)); - EXPECT_TRUE(Complex(2, 1) > Complex(1, 2)); - - EXPECT_TRUE(Complex(0, 0) > Complex(0, -1)); - EXPECT_TRUE(Complex(0, 0) > Complex(-1, 0)); - EXPECT_TRUE(Complex(0, 0) > Complex(-1, -1)); - - EXPECT_FALSE(Complex(-1, -1) > Complex(-1, -1)); - EXPECT_TRUE(Complex(-1, -1) > Complex(-1, -2)); - EXPECT_TRUE(Complex(-1, -1) > Complex(-2, -1)); - EXPECT_TRUE(Complex(-1, -1) > Complex(-2, -2)); - - EXPECT_TRUE(Complex(-1, -2) > Complex(-2, -1)); - EXPECT_FALSE(Complex(-2, -1) > Complex(-1, -2)); -} - -TEST(ComplexTests, integerMoreOperatorTest) { - EXPECT_FALSE(Complex(500, 1) > Integer(501)); -} - -TEST(ComplexTests, rationalMoreOperatorTest) { - EXPECT_TRUE(Complex(Rational(1, 2), Integer(1)) > Rational(1, 3)); -} - -TEST(ComplexTests, realMoreOperatorTest) { - EXPECT_FALSE(Complex(Real("2.2"), Integer(1)) > Real("2.3")); -} - -TEST(ComplexTests, intMoreOperatorTest) { - EXPECT_FALSE(Complex(500, 1) > 501); -} - -TEST(ComplexTests, integerFriendMoreOperatorTest) { - EXPECT_FALSE(Integer(500) > Complex(501, 1)); -} - -TEST(ComplexTests, rationalFriendMoreOperatorTest) { - EXPECT_TRUE(Rational(1, 2) > Complex(Rational(1, 3), Integer(1))); -} - -TEST(ComplexTests, realFriendMoreOperatorTest) { - EXPECT_FALSE(Real("2.2") > Complex(Real("2.3"), Integer(1))); -} - -TEST(ComplexTests, intFriendMoreOperatorTest) { - EXPECT_FALSE(500 > Complex(501, 1)); -} - -TEST(ComplexTests, lessEqvOperatorTest) { - EXPECT_TRUE(Complex(0, 0) <= Complex(0, 0)); - EXPECT_TRUE(Complex(0, 0) <= Complex(0, 1)); - EXPECT_TRUE(Complex(0, 0) <= Complex(1, 0)); - EXPECT_TRUE(Complex(0, 0) <= Complex(1, 1)); - - EXPECT_TRUE(Complex(1, 1) <= Complex(1, 1)); - EXPECT_TRUE(Complex(1, 1) <= Complex(1, 2)); - EXPECT_TRUE(Complex(1, 1) <= Complex(2, 1)); - EXPECT_TRUE(Complex(1, 1) <= Complex(2, 2)); - - EXPECT_TRUE(Complex(1, 2) <= Complex(2, 1)); - EXPECT_FALSE(Complex(2, 1) <= Complex(1, 2)); - - EXPECT_FALSE(Complex(0, 0) <= Complex(0, -1)); - EXPECT_FALSE(Complex(0, 0) <= Complex(-1, 0)); - EXPECT_FALSE(Complex(0, 0) <= Complex(-1, -1)); - - EXPECT_TRUE(Complex(-1, -1) <= Complex(-1, -1)); - EXPECT_FALSE(Complex(-1, -1) <= Complex(-1, -2)); - EXPECT_FALSE(Complex(-1, -1) <= Complex(-2, -1)); - EXPECT_FALSE(Complex(-1, -1) <= Complex(-2, -2)); - - EXPECT_FALSE(Complex(-1, -2) <= Complex(-2, -1)); - EXPECT_TRUE(Complex(-2, -1) <= Complex(-1, -2)); -} - -TEST(ComplexTests, integerLessEqvOperatorTest) { - EXPECT_TRUE(Complex(500, 1) <= Integer(501)); -} - -TEST(ComplexTests, rationalLessEqvOperatorTest) { - EXPECT_FALSE(Complex(Rational(1, 2), Integer(1)) <= Rational(1, 3)); -} - -TEST(ComplexTests, realLessEqvOperatorTest) { - EXPECT_TRUE(Complex(Real("2.2"), Integer(1)) <= Real("2.3")); -} - -TEST(ComplexTests, intLessEqvOperatorTest) { - EXPECT_TRUE(Complex(500, 1) <= 501); -} - -TEST(ComplexTests, integerFriendLessEqvOperatorTest) { - EXPECT_TRUE(Integer(500) <= Complex(501, 1)); -} - -TEST(ComplexTests, rationalFriendLessEqvOperatorTest) { - EXPECT_FALSE(Rational(1, 2) <= Complex(Rational(1, 3), Integer(1))); -} - -TEST(ComplexTests, realFriendLessEqvOperatorTest) { - EXPECT_TRUE(Real("2.2") <= Complex(Real("2.3"), Integer(1))); -} - -TEST(ComplexTests, intFriendLessEqvOperatorTest) { - EXPECT_TRUE(500 <= Complex(501, 1)); -} - -TEST(ComplexTests, moreEqvOperatorTest) { - EXPECT_TRUE(Complex(0, 0) >= Complex(0, 0)); - EXPECT_FALSE(Complex(0, 0) >= Complex(0, 1)); - EXPECT_FALSE(Complex(0, 0) >= Complex(1, 0)); - EXPECT_FALSE(Complex(0, 0) >= Complex(1, 1)); - - EXPECT_TRUE(Complex(1, 1) >= Complex(1, 1)); - EXPECT_FALSE(Complex(1, 1) >= Complex(1, 2)); - EXPECT_FALSE(Complex(1, 1) >= Complex(2, 1)); - EXPECT_FALSE(Complex(1, 1) >= Complex(2, 2)); - - EXPECT_FALSE(Complex(1, 2) >= Complex(2, 1)); - EXPECT_TRUE(Complex(2, 1) >= Complex(1, 2)); - - EXPECT_TRUE(Complex(0, 0) >= Complex(0, -1)); - EXPECT_TRUE(Complex(0, 0) >= Complex(-1, 0)); - EXPECT_TRUE(Complex(0, 0) >= Complex(-1, -1)); - - EXPECT_TRUE(Complex(-1, -1) >= Complex(-1, -1)); - EXPECT_TRUE(Complex(-1, -1) >= Complex(-1, -2)); - EXPECT_TRUE(Complex(-1, -1) >= Complex(-2, -1)); - EXPECT_TRUE(Complex(-1, -1) >= Complex(-2, -2)); - - EXPECT_TRUE(Complex(-1, -2) >= Complex(-2, -1)); - EXPECT_FALSE(Complex(-2, -1) >= Complex(-1, -2)); -} - -TEST(ComplexTests, integerEqvMoreOperatorTest) { - EXPECT_FALSE(Complex(500, 1) >= Integer(501)); -} - -TEST(ComplexTests, rationalMoreEqvOperatorTest) { - EXPECT_TRUE(Complex(Rational(1, 2), Integer(1)) >= Rational(1, 3)); -} - -TEST(ComplexTests, realMoreEqvOperatorTest) { - EXPECT_FALSE(Complex(Real("2.2"), Integer(1)) >= Real("2.3")); -} - -TEST(ComplexTests, intMoreEqvOperatorTest) { - EXPECT_FALSE(Complex(500, 1) >= 501); -} - -TEST(ComplexTests, integerFriendMoreEqvOperatorTest) { - EXPECT_FALSE(Integer(500) >= Complex(501, 1)); -} - -TEST(ComplexTests, rationalFriendMoreEqvOperatorTest) { - EXPECT_TRUE(Rational(1, 2) >= Complex(Rational(1, 3), Integer(1))); -} - -TEST(ComplexTests, realFriendMoreEqvOperatorTest) { - EXPECT_FALSE(Real("2.2") >= Complex(Real("2.3"), Integer(1))); -} - -TEST(ComplexTests, intFriendMoreEqvOperatorTest) { - EXPECT_FALSE(500 >= Complex(501, 1)); -} - -TEST(ComplexTests, realTest) { - EXPECT_EQ(Complex(5, 2).real(), Integer(5)); - EXPECT_EQ(Complex(55).real(), Integer(55)); - EXPECT_EQ(Complex(-10, 100).real(), Integer(-10)); - EXPECT_EQ(Complex(0, 100).real(), Integer(0)); - - EXPECT_TRUE(is(Complex(Rational(2, 2), Integer(1)).real())); -} - -TEST(ComplexTests, imagTest) { - EXPECT_EQ(Complex(5, 2).imag(), Integer(2)); - EXPECT_EQ(Complex(55).imag(), Integer(0)); - EXPECT_EQ(Complex(-10, 100).imag(), Integer(100)); - - EXPECT_TRUE(is(Complex(Integer(1), Rational(2, 2)).imag())); -} - -TEST(ComplexTests, toStringTest) { - EXPECT_EQ(Complex(0, 0).toString(), "0"); - EXPECT_EQ(Complex(1, 0).toString(), "1"); - EXPECT_EQ(Complex(0, 1).toString(), "I"); - EXPECT_EQ(Complex(0, 2).toString(), "2 I"); - EXPECT_EQ(Complex(1, 1).toString(), "1 + I"); - EXPECT_EQ(Complex(1, 2).toString(), "1 + 2 I"); - EXPECT_EQ(Complex(2, 1).toString(), "2 + I"); - EXPECT_EQ(Complex(2, 2).toString(), "2 + 2 I"); - EXPECT_EQ(Complex(-1, 0).toString(), "-1"); - EXPECT_EQ(Complex(0, -1).toString(), "-I"); - EXPECT_EQ(Complex(0, -2).toString(), "-2 I"); - EXPECT_EQ(Complex(-1, -1).toString(), "-1 - I"); - EXPECT_EQ(Complex(-1, -2).toString(), "-1 - 2 I"); - EXPECT_EQ(Complex(-2, -1).toString(), "-2 - I"); - EXPECT_EQ(Complex(-2, -2).toString(), "-2 - 2 I"); -} - -TEST(ComplexTests, simplifyTest) { - EXPECT_TRUE(is(Complex(5, 2).toMinimalObject())); - EXPECT_TRUE(is(Complex(55, 0).toMinimalObject())); - EXPECT_TRUE(is(Complex(Rational(5, 5), Integer(0)).toMinimalObject())); - EXPECT_TRUE(is(Complex(Rational(5, 2), Integer(0)).toMinimalObject())); - EXPECT_TRUE(is(Complex(Real("5.2"), Integer(0)).toMinimalObject())); - - EXPECT_EQ(Complex(5, 2).toMinimalObject()->toString(), "5 + 2 I"); - EXPECT_EQ(Complex(55, 0).toMinimalObject()->toString(), "55"); - EXPECT_EQ(Complex(Rational(5, 5), Integer(0)).toMinimalObject()->toString(), "1"); - EXPECT_EQ(Complex(Rational(5, 2), Integer(0)).toMinimalObject()->toString(), "5/2"); - EXPECT_EQ(Complex(Real("5.2"), Integer(0)).toMinimalObject()->toString(), "5.2"); -} - -TEST(ComplexTests, isPreciseTest) { - EXPECT_TRUE(Complex(1, 2).isPrecise()); - EXPECT_TRUE(Complex(Rational(1, 2), Rational(1, 2)).isPrecise()); - - EXPECT_FALSE(Complex(Real(1), Real(1)).isPrecise()); - EXPECT_FALSE(Complex(Real(1), Integer(1)).isPrecise()); - EXPECT_FALSE(Complex(Integer(1), Real(1)).isPrecise()); -} - -TEST(ComplexTests, isComplexTest) { - EXPECT_TRUE(Complex(1, 1).isComplex()); - - EXPECT_FALSE(Complex(1, 0).isComplex()); -} - -TEST(ComplexTests, getClassTest) { - EXPECT_EQ(Complex().getClass(), MathObjectClass("Complex")); - EXPECT_EQ(Complex().getClass().getParent(), INumber::getClassStatic()); -} diff --git a/tests/src/numbers/IIntegerTests.cpp b/tests/src/numbers/IIntegerTests.cpp deleted file mode 100644 index e3ebacfcf..000000000 --- a/tests/src/numbers/IIntegerTests.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#include - -#include "fintamath/numbers/IInteger.hpp" - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/numbers/Integer.hpp" - -using namespace fintamath; -using namespace detail; - -namespace { - -class TestInteger : public IIntegerCRTP { - FINTAMATH_PARENT_CLASS_BODY(TestInteger) - -protected: - TestInteger &mod(const TestInteger & /* rhs */) override { - return *this; - } - - TestInteger &bitAnd(const TestInteger &rhs) override { - return *this; - } - - TestInteger &bitOr(const TestInteger &rhs) override { - return *this; - } - - TestInteger &bitXor(const TestInteger &rhs) override { - return *this; - } - - TestInteger &bitLeftShift(const TestInteger &rhs) override { - return *this; - } - - TestInteger &bitRightShift(const TestInteger &rhs) override { - return *this; - } - - TestInteger &bitNot() override { - return *this; - } - - TestInteger &add(const TestInteger &rhs) override { - return *this; - } - - TestInteger &substract(const TestInteger &rhs) override { - return *this; - } - - TestInteger &multiply(const TestInteger &rhs) override { - return *this; - } - - TestInteger ÷(const TestInteger &rhs) override { - return *this; - } - - TestInteger &negate() override { - return *this; - } - - std::strong_ordering compare(const TestInteger &rhs) const override { - return std::strong_ordering::less; - } - - TestInteger &increase() override { - return *this; - } - - TestInteger &decrease() override { - return *this; - } -}; - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(TestInteger) - -class TestIntegerConvertible final : public TestInteger { - FINTAMATH_CLASS_BODY(TestIntegerConvertible) - -public: - TestIntegerConvertible() : TestInteger() { - } - - TestIntegerConvertible(const Integer &) : TestIntegerConvertible() { - } - - MathObjectClass getClass() const override { - return getClassStatic(); - } -}; - -[[maybe_unused]] const auto config = [] { - IInteger::registerType(); - TestInteger::registerType(); - - Converter::add( - [](const TestIntegerConvertible & /*type*/, const TestIntegerConvertible &value) { - return std::make_unique(value); - }); - Converter::add( - [](const TestIntegerConvertible & /*type*/, const Integer &value) { - return std::make_unique(value); - }); - - return 0; -}(); - -} - -TEST(IIntegerTests, parseTest) { - EXPECT_TRUE(is(*IInteger::parseFirst("TestInteger"))); -} - -TEST(IIntegerTests, modTest) { - std::unique_ptr m1 = std::make_unique(10); - std::unique_ptr m2 = std::make_unique(3); - - EXPECT_EQ((*m1 % *m1)->toString(), "0"); - EXPECT_EQ((*m2 % *m2)->toString(), "0"); - EXPECT_EQ((*m1 % *m2)->toString(), "1"); - EXPECT_EQ((*m2 % *m1)->toString(), "3"); - - EXPECT_TRUE(is(*m1 % *m1)); - EXPECT_TRUE(is(*m2 % *m2)); - EXPECT_TRUE(is(*m1 % *m2)); - EXPECT_TRUE(is(*m2 % *m1)); - - EXPECT_TRUE(is(*m1 % TestIntegerConvertible())); - EXPECT_TRUE(is(TestIntegerConvertible() % *m1)); - - EXPECT_THROW(*m1 % TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() % *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a %= 3).toString(), "0"); -} - -TEST(IIntegerTests, bitAndTest) { - std::unique_ptr m1 = std::make_unique(10); - std::unique_ptr m2 = std::make_unique(3); - - EXPECT_EQ((*m1 & *m1)->toString(), "10"); - EXPECT_EQ((*m2 & *m2)->toString(), "3"); - EXPECT_EQ((*m1 & *m2)->toString(), "2"); - EXPECT_EQ((*m2 & *m1)->toString(), "2"); - - EXPECT_TRUE(is(*m1 & *m1)); - EXPECT_TRUE(is(*m2 & *m2)); - EXPECT_TRUE(is(*m1 & *m2)); - EXPECT_TRUE(is(*m2 & *m1)); - - EXPECT_TRUE(is(*m1 & TestIntegerConvertible())); - EXPECT_TRUE(is(TestIntegerConvertible() & *m1)); - - EXPECT_THROW(*m1 & TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() & *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a &= 3).toString(), "0"); -} - -TEST(IIntegerTests, bitOrTest) { - std::unique_ptr m1 = std::make_unique(10); - std::unique_ptr m2 = std::make_unique(3); - - EXPECT_EQ((*m1 | *m1)->toString(), "10"); - EXPECT_EQ((*m2 | *m2)->toString(), "3"); - EXPECT_EQ((*m1 | *m2)->toString(), "11"); - EXPECT_EQ((*m2 | *m1)->toString(), "11"); - - EXPECT_TRUE(is(*m1 | *m1)); - EXPECT_TRUE(is(*m2 | *m2)); - EXPECT_TRUE(is(*m1 | *m2)); - EXPECT_TRUE(is(*m2 | *m1)); - - EXPECT_TRUE(is(*m1 | TestIntegerConvertible())); - EXPECT_TRUE(is(TestIntegerConvertible() | *m1)); - - EXPECT_THROW(*m1 | TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() | *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a |= 3).toString(), "3"); -} - -TEST(IIntegerTests, bitXorTest) { - std::unique_ptr m1 = std::make_unique(10); - std::unique_ptr m2 = std::make_unique(3); - - EXPECT_EQ((*m1 ^ *m1)->toString(), "0"); - EXPECT_EQ((*m2 ^ *m2)->toString(), "0"); - EXPECT_EQ((*m1 ^ *m2)->toString(), "9"); - EXPECT_EQ((*m2 ^ *m1)->toString(), "9"); - - EXPECT_TRUE(is(*m1 ^ *m1)); - EXPECT_TRUE(is(*m2 ^ *m2)); - EXPECT_TRUE(is(*m1 ^ *m2)); - EXPECT_TRUE(is(*m2 ^ *m1)); - - EXPECT_TRUE(is(*m1 ^ TestIntegerConvertible())); - EXPECT_TRUE(is(TestIntegerConvertible() ^ *m1)); - - EXPECT_THROW(*m1 ^ TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() ^ *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a ^= 3).toString(), "3"); -} - -TEST(IIntegerTests, bitLeftShiftTest) { - std::unique_ptr m1 = std::make_unique(10); - std::unique_ptr m2 = std::make_unique(3); - - EXPECT_EQ((*m1 << *m1)->toString(), "10240"); - EXPECT_EQ((*m2 << *m2)->toString(), "24"); - EXPECT_EQ((*m1 << *m2)->toString(), "80"); - EXPECT_EQ((*m2 << *m1)->toString(), "3072"); - - EXPECT_TRUE(is(*m1 << *m1)); - EXPECT_TRUE(is(*m2 << *m2)); - EXPECT_TRUE(is(*m1 << *m2)); - EXPECT_TRUE(is(*m2 << *m1)); - - EXPECT_TRUE(is(*m1 << TestIntegerConvertible())); - EXPECT_TRUE(is(TestIntegerConvertible() << *m1)); - - EXPECT_THROW(*m1 << TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() << *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a <<= 3).toString(), "0"); -} - -TEST(IIntegerTests, bitRightShiftTest) { - std::unique_ptr m1 = std::make_unique(10); - std::unique_ptr m2 = std::make_unique(3); - - EXPECT_EQ((*m1 >> *m1)->toString(), "0"); - EXPECT_EQ((*m2 >> *m2)->toString(), "0"); - EXPECT_EQ((*m1 >> *m2)->toString(), "1"); - EXPECT_EQ((*m2 >> *m1)->toString(), "0"); - - EXPECT_TRUE(is(*m1 >> *m1)); - EXPECT_TRUE(is(*m2 >> *m2)); - EXPECT_TRUE(is(*m1 >> *m2)); - EXPECT_TRUE(is(*m2 >> *m1)); - - EXPECT_TRUE(is(*m1 >> TestIntegerConvertible())); - EXPECT_TRUE(is(TestIntegerConvertible() >> *m1)); - - EXPECT_THROW(*m1 >> TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() >> *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a >>= 3).toString(), "0"); -} - -TEST(IIntegerTests, bitNotTest) { - const std::unique_ptr m1 = std::make_unique(44); - EXPECT_EQ((~*m1)->toString(), "-45"); - - EXPECT_EQ((~Integer(1)).toString(), "-2"); -} - -TEST(IIntegerTests, incTest) { - const std::unique_ptr m1 = std::make_unique(1); - EXPECT_EQ((++*m1).toString(), "2"); - EXPECT_EQ(((*m1)++)->toString(), "2"); - EXPECT_EQ(m1->toString(), "3"); - - EXPECT_EQ((++Integer(1)).toString(), "2"); - EXPECT_EQ((Integer(1)++).toString(), "1"); -} - -TEST(IIntegerTests, decTest) { - const std::unique_ptr m1 = std::make_unique(1); - EXPECT_EQ((--*m1).toString(), "0"); - EXPECT_EQ(((*m1)--)->toString(), "0"); - EXPECT_EQ(m1->toString(), "-1"); - - EXPECT_EQ((--Integer(1)).toString(), "0"); - EXPECT_EQ((Integer(1)--).toString(), "1"); -} - -TEST(IIntegerTests, getClassTest) { - EXPECT_EQ(IInteger::getClassStatic(), MathObjectClass("IInteger")); - EXPECT_EQ(IInteger::getClassStatic().getParent(), INumber::getClassStatic()); -} diff --git a/tests/src/numbers/INumberTests.cpp b/tests/src/numbers/INumberTests.cpp deleted file mode 100644 index 72bb21d86..000000000 --- a/tests/src/numbers/INumberTests.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include - -#include "fintamath/numbers/INumber.hpp" - -#include "fintamath/numbers/Integer.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -namespace { - -class TestNumber final : public INumberCRTP { - FINTAMATH_CLASS_BODY(TestNumber) - -protected: - TestNumber &add(const TestNumber &rhs) override { - return *this; - } - - TestNumber &substract(const TestNumber &rhs) override { - return *this; - } - - TestNumber &multiply(const TestNumber &rhs) override { - return *this; - } - - TestNumber ÷(const TestNumber &rhs) override { - return *this; - } - - TestNumber &negate() override { - return *this; - } - - std::strong_ordering compare(const TestNumber &rhs) const override { - return std::strong_ordering::less; - } -}; - -[[maybe_unused]] const auto config = [] { - INumber::registerType(); - return 0; -}(); - -} - -TEST(INumberTests, parseTest) { - EXPECT_TRUE(is(*INumber::parseFirst("TestNumber"))); -} - -TEST(INumberTests, addTest) { - const std::unique_ptr m1 = std::make_unique(1); - const std::unique_ptr m2 = std::make_unique(2); - const std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_EQ((*m1 + *m1)->toString(), "2"); - EXPECT_EQ((*m2 + *m2)->toString(), "4"); - EXPECT_EQ((*m1 + *m2)->toString(), "3"); - EXPECT_EQ((*m2 + *m1)->toString(), "3"); - - EXPECT_EQ((*m1 + *m3)->toString(), "3/2"); - EXPECT_EQ((*m2 + *m3)->toString(), "5/2"); - EXPECT_EQ((*m3 + *m1)->toString(), "3/2"); - EXPECT_EQ((*m3 + *m2)->toString(), "5/2"); -} - -TEST(INumberTests, subTest) { - const std::unique_ptr m1 = std::make_unique(1); - const std::unique_ptr m2 = std::make_unique(2); - const std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_EQ((*m1 - *m1)->toString(), "0"); - EXPECT_EQ((*m2 - *m2)->toString(), "0"); - EXPECT_EQ((*m1 - *m2)->toString(), "-1"); - EXPECT_EQ((*m2 - *m1)->toString(), "1"); - - EXPECT_EQ((*m1 - *m3)->toString(), "1/2"); - EXPECT_EQ((*m2 - *m3)->toString(), "3/2"); - EXPECT_EQ((*m3 - *m1)->toString(), "-1/2"); - EXPECT_EQ((*m3 - *m2)->toString(), "-3/2"); -} - -TEST(INumberTests, mulTest) { - const std::unique_ptr m1 = std::make_unique(1); - const std::unique_ptr m2 = std::make_unique(2); - const std::unique_ptr m3 = std::make_unique(1, 2); - - EXPECT_EQ((*m1 * *m1)->toString(), "1"); - EXPECT_EQ((*m2 * *m2)->toString(), "4"); - EXPECT_EQ((*m1 * *m2)->toString(), "2"); - EXPECT_EQ((*m2 * *m1)->toString(), "2"); - - EXPECT_EQ((*m1 * *m3)->toString(), "1/2"); - EXPECT_EQ((*m2 * *m3)->toString(), "1"); - EXPECT_EQ((*m3 * *m1)->toString(), "1/2"); - EXPECT_EQ((*m3 * *m2)->toString(), "1"); -} - -TEST(INumberTests, divTest) { - const std::unique_ptr m1 = std::make_unique(1); - const std::unique_ptr m2 = std::make_unique(5); - const std::unique_ptr m3 = std::make_unique(2); - const std::unique_ptr m4 = std::make_unique(1, 2); - - EXPECT_EQ((*m1 / *m2)->toString(), "1/5"); - - EXPECT_EQ((*m1 / *m1)->toString(), "1"); - EXPECT_EQ((*m3 / *m3)->toString(), "1"); - EXPECT_EQ((*m1 / *m3)->toString(), "1/2"); - EXPECT_EQ((*m3 / *m1)->toString(), "2"); - - EXPECT_EQ((*m1 / *m4)->toString(), "2"); - EXPECT_EQ((*m3 / *m4)->toString(), "4"); - EXPECT_EQ((*m4 / *m1)->toString(), "1/2"); - EXPECT_EQ((*m4 / *m3)->toString(), "1/4"); -} - -TEST(INumberTests, convertTest) { - const std::unique_ptr m1 = std::make_unique(1); - EXPECT_EQ((+*m1)->toString(), "1"); - EXPECT_TRUE(is(+*m1)); -} - -TEST(INumberTests, negateTest) { - const std::unique_ptr m1 = std::make_unique(1); - EXPECT_EQ((-*m1)->toString(), "-1"); - EXPECT_TRUE(is(+*m1)); -} - -TEST(INumberTests, getClassTest) { - EXPECT_EQ(INumber::getClassStatic(), MathObjectClass("INumber")); - EXPECT_EQ(INumber::getClassStatic().getParent(), IComparable::getClassStatic()); -} diff --git a/tests/src/numbers/IntegerFunctionsTests.cpp b/tests/src/numbers/IntegerFunctionsTests.cpp deleted file mode 100644 index 8767d4a0e..000000000 --- a/tests/src/numbers/IntegerFunctionsTests.cpp +++ /dev/null @@ -1,298 +0,0 @@ -#include - -#include "fintamath/numbers/Complex.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" - -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/Rational.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -TEST(IntegerFunctionsTests, absTest) { - EXPECT_EQ(abs(Integer("-210")).toString(), "210"); - EXPECT_EQ(abs(Integer("4545628562")).toString(), "4545628562"); - EXPECT_EQ(abs(Integer("0")).toString(), "0"); -} - -TEST(IntegerFunctionsTests, gcdTest) { - EXPECT_EQ(gcd(Integer(12), Integer(18)), - Integer(6)); - EXPECT_EQ(gcd(Integer(30), Integer(45)), - Integer(15)); - EXPECT_EQ(gcd(Integer(25), Integer(35)), - Integer(5)); - - EXPECT_EQ(gcd(Integer(-12), Integer(-18)), - Integer(6)); - EXPECT_EQ(gcd(Integer(-30), Integer(-45)), - Integer(15)); - EXPECT_EQ(gcd(Integer(-25), Integer(-35)), - Integer(5)); - - EXPECT_EQ(gcd(Integer(0), Integer(10)), - Integer(10)); - EXPECT_EQ(gcd(Integer(0), Integer(-15)), - Integer(15)); - - EXPECT_EQ(gcd(Integer(0), Integer(0)), - Integer(0)); - - EXPECT_EQ(gcd(Integer("1234567890123456789012345678901234567890123456789012345678901234567890"), Integer("9876543210987654321098765432109876543210987654321098765432109876543210")).toString(), - "90000000009000000000900000000090000000009000000000900000000090"); -} - -TEST(IntegerFunctionsTests, lcmTest) { - EXPECT_EQ(lcm(Integer(12), Integer(18)), - Integer(36)); - EXPECT_EQ(lcm(Integer(5), Integer(7)), - Integer(35)); - EXPECT_EQ(lcm(Integer(8), Integer(12)), - Integer(24)); - EXPECT_EQ(lcm(Integer(15), Integer(25)), - Integer(75)); - EXPECT_EQ(lcm(Integer(4), Integer(9)), - Integer(36)); - - EXPECT_EQ(lcm(Integer(0), Integer(5)), - Integer(0)); - EXPECT_EQ(lcm(Integer(5), Integer(0)), - Integer(0)); - EXPECT_EQ(lcm(Integer(0), Integer(0)), - Integer(0)); - - EXPECT_GE(lcm(Integer(-4), Integer(7)), - Integer(0)); - EXPECT_GE(lcm(Integer(3), Integer(-6)), - Integer(0)); - EXPECT_EQ(lcm(Integer(-2), Integer(0)), - Integer(0)); - - EXPECT_EQ(lcm(Integer("1234567890123456789012345678901234567890123456789012345678901234567890"), Integer("9876543210987654321098765432109876543210987654321098765432109876543210")).toString(), - "135480701249809480124980948012498094801249809480124980948012498094801236261410"); -} - -TEST(IntegerFunctionsTests, sqrtTest) { - EXPECT_EQ(sqrt(Integer(25)), 5); - EXPECT_EQ(sqrt(Integer(100)), 10); - EXPECT_EQ(sqrt(Integer(144)), 12); - EXPECT_EQ(sqrt(Integer("10000000000000000000000000000000000000000000000000000")), Integer("100000000000000000000000000")); - - EXPECT_EQ(sqrt(Integer(35)), 5); - EXPECT_EQ(sqrt(Integer(4212)), Integer(64)); - EXPECT_EQ(sqrt(Integer("992188888888")), Integer(996086)); - EXPECT_EQ(sqrt(Integer("68732648273642987365932706179432649827364")), Integer("262169121510606178721")); - - EXPECT_THROW(sqrt(Integer(-9289)), UndefinedFunctionException); -} - -TEST(IntegerFunctionsTests, sqrtWithRemainderTest) { - Integer remainder; - - EXPECT_EQ(sqrt(Integer(25), remainder), 5); - EXPECT_EQ(remainder, 0); - - EXPECT_EQ(sqrt(Integer(100), remainder), 10); - EXPECT_EQ(remainder, 0); - - EXPECT_EQ(sqrt(Integer(144), remainder), 12); - EXPECT_EQ(remainder, 0); - - EXPECT_EQ(sqrt(Integer("10000000000000000000000000000000000000000000000000000"), remainder), Integer("100000000000000000000000000")); - EXPECT_EQ(remainder, 0); - - EXPECT_EQ(sqrt(Integer(35), remainder), 5); - EXPECT_EQ(remainder, 10); - - EXPECT_EQ(sqrt(Integer(4212), remainder), Integer(64)); - EXPECT_EQ(remainder, 116); - - EXPECT_EQ(sqrt(Integer("992188888888"), remainder), Integer(996086)); - EXPECT_EQ(remainder, 1569492); - - EXPECT_EQ(sqrt(Integer("68732648273642987365932706179432649827364"), remainder), Integer("262169121510606178721")); - EXPECT_EQ(remainder.toString(), "307087949370856631523"); - - EXPECT_THROW(sqrt(Integer(-9289), remainder), UndefinedFunctionException); -} - -TEST(IntegerFunctionsTests, powTest) { - EXPECT_EQ(pow(Integer(5), Integer(2)), - 25); - EXPECT_EQ(pow(Integer(-5), Integer(5)), - -3125); - EXPECT_EQ(pow(Integer(6789), Integer(4)).toString(), - "2124336126051441"); - EXPECT_EQ(pow(Integer(1), Integer("429837493286275623874628734628734")), - 1); - EXPECT_EQ(pow(Integer("135253468973498327423987498324729384"), Integer(3)).toString(), - "2474259452251333810348988009462181048257185161014872437371075550103119323428971486869861741659206806895104"); - EXPECT_EQ(pow(Integer(6789), Integer(-4)), - 0); - - EXPECT_EQ(pow(Rational(5, 2), Integer(2)).toString(), - "25/4"); - EXPECT_EQ(pow(Rational(-5, 2), Integer(5)).toString(), - "-3125/32"); - EXPECT_EQ(pow(Rational(6789), Integer(4)).toString(), - "2124336126051441"); - EXPECT_EQ(pow(Rational("135253468973498327423987498324729384.12987349823749832"), Integer(3)).toString(), - "4832537992678386348337867205980822373798257851094432575433371642956047093945525418683507600681355491343220122262032882136893556623485326120689398001084489/1953125000000000000000000000000000000000000000000"); - EXPECT_EQ(pow(Rational(6789), Integer(-4)).toString(), - "1/2124336126051441"); - - EXPECT_EQ(pow(Real(5), Integer(2)).toString(), - "25.0"); - EXPECT_EQ(pow(Real(-5), Integer(5)).toString(), - "-3125.0"); - EXPECT_EQ(pow(Real(6789), Integer(4)).toString(), - "2124336126051441.0"); - EXPECT_EQ(pow(Real("135253468973498327423987498324729384.12987349823749832"), Integer(3)).toString(), - "2.4742594522513338103*10^105"); - EXPECT_EQ(pow(Real(6789), Integer(-4)).toString(), - "4.7073529830645308412*10^-16"); - - EXPECT_EQ(pow(Complex(5, 2), Integer(2)).toString(), - "21 + 20 I"); - EXPECT_EQ(pow(Complex(Rational(1, 2), Rational(2, 3)), Integer(5)).toString(), - "-79/2592 - 779/1944 I"); - EXPECT_EQ(pow(Complex(6789, 2345), Integer(4)).toString(), - "633857838549916 + 2584899750306720 I"); - EXPECT_EQ(pow(Complex("135253468973498327423987498324729384.12987349823749832"), Integer(3)).toString(), - "4832537992678386348337867205980822373798257851094432575433371642956047093945525418683507600681355491343220122262032882136893556623485326120689398001084489/1953125000000000000000000000000000000000000000000"); - EXPECT_EQ(pow(Complex(6789, 11), Integer(-4)).toString(), - "531075666086959/1128212841481282934557153710724 - 860496245400/282053210370320733639288427681 I"); - - EXPECT_THROW(pow(Integer(0), Integer(0)), UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Rational(0), Integer(0)), UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real(0), Integer(0)), UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Complex(0), Integer(0)), UndefinedBinaryOperatorException); -} - -TEST(IntegerFunctionsTests, factorialTest) { - EXPECT_EQ(factorial(Integer(0)), 1); - EXPECT_EQ(factorial(Integer(1)), 1); - EXPECT_EQ(factorial(Integer(2)), 2); - EXPECT_EQ(factorial(Integer(3)), 6); - EXPECT_EQ(factorial(Integer(4)), 24); - EXPECT_EQ(factorial(Integer(5)), 120); - EXPECT_EQ(factorial(Integer(10)), 3628800); - EXPECT_EQ(factorial(Integer(25)).toString(), "15511210043330985984000000"); - - EXPECT_THROW(factorial(Integer(-1)), UndefinedUnaryOperatorException); - EXPECT_THROW(factorial(Integer(-2)), UndefinedUnaryOperatorException); -} - -TEST(IntegerFunctionsTests, nthFactorialTest) { - EXPECT_EQ(factorial(Integer(0), 1), 1); - EXPECT_EQ(factorial(Integer(1), 1), 1); - EXPECT_EQ(factorial(Integer(2), 1), 2); - EXPECT_EQ(factorial(Integer(3), 1), 6); - EXPECT_EQ(factorial(Integer(4), 1), 24); - EXPECT_EQ(factorial(Integer(5), 1), 120); - EXPECT_EQ(factorial(Integer(10), 1), 3628800); - EXPECT_EQ(factorial(Integer(25), 1).toString(), "15511210043330985984000000"); - - EXPECT_EQ(factorial(Integer(0), 2), 1); - EXPECT_EQ(factorial(Integer(1), 2), 1); - EXPECT_EQ(factorial(Integer(2), 2), 2); - EXPECT_EQ(factorial(Integer(3), 2), 3); - EXPECT_EQ(factorial(Integer(4), 2), 8); - EXPECT_EQ(factorial(Integer(5), 2), 15); - EXPECT_EQ(factorial(Integer(10), 2), 3840); - EXPECT_EQ(factorial(Integer(25), 2).toString(), "7905853580625"); - - EXPECT_EQ(factorial(Integer(0), 3), 1); - EXPECT_EQ(factorial(Integer(1), 3), 1); - EXPECT_EQ(factorial(Integer(2), 3), 2); - EXPECT_EQ(factorial(Integer(3), 3), 3); - EXPECT_EQ(factorial(Integer(4), 3), 4); - EXPECT_EQ(factorial(Integer(5), 3), 10); - EXPECT_EQ(factorial(Integer(10), 3), 280); - EXPECT_EQ(factorial(Integer(25), 3).toString(), "608608000"); - - EXPECT_EQ(factorial(Integer(0), 10), 1); - EXPECT_EQ(factorial(Integer(1), 10), 1); - EXPECT_EQ(factorial(Integer(2), 10), 2); - EXPECT_EQ(factorial(Integer(3), 10), 3); - EXPECT_EQ(factorial(Integer(4), 10), 4); - EXPECT_EQ(factorial(Integer(5), 10), 5); - EXPECT_EQ(factorial(Integer(10), 10), 10); - EXPECT_EQ(factorial(Integer(25), 10).toString(), "1875"); - - EXPECT_THROW(factorial(Integer(-1), 1), UndefinedUnaryOperatorException); - EXPECT_THROW(factorial(Integer(-1), 20), UndefinedUnaryOperatorException); - EXPECT_THROW(factorial(Integer(-2), 1), UndefinedUnaryOperatorException); - EXPECT_THROW(factorial(Integer(-2), 20), UndefinedUnaryOperatorException); -} - -TEST(IntegerFunctionsTests, factorsTest) { - FactorToCountMap factorToCountMap; - - factorToCountMap = factors(2); - EXPECT_EQ(factorToCountMap.size(), 1); - EXPECT_EQ(factorToCountMap[2], 1); - - factorToCountMap = factors(32); - EXPECT_EQ(factorToCountMap.size(), 1); - EXPECT_EQ(factorToCountMap[2], 5); - - factorToCountMap = factors(144); - EXPECT_EQ(factorToCountMap.size(), 2); - EXPECT_EQ(factorToCountMap[2], 4); - EXPECT_EQ(factorToCountMap[3], 2); - - factorToCountMap = factors(123); - EXPECT_EQ(factorToCountMap.size(), 2); - EXPECT_EQ(factorToCountMap[3], 1); - EXPECT_EQ(factorToCountMap[41], 1); - - factorToCountMap = factors(Integer("139826427468275632"), 1000); - EXPECT_EQ(factorToCountMap.size(), 5); - EXPECT_EQ(factorToCountMap[2], 4); - EXPECT_EQ(factorToCountMap[7], 1); - EXPECT_EQ(factorToCountMap[17], 1); - EXPECT_EQ(factorToCountMap[31], 1); - EXPECT_EQ(factorToCountMap[Integer("2368975797443")], 1); - - factorToCountMap = factors(Integer("139826427468275632"), 10000); - EXPECT_EQ(factorToCountMap[2], 4); - EXPECT_EQ(factorToCountMap[7], 1); - EXPECT_EQ(factorToCountMap[17], 1); - EXPECT_EQ(factorToCountMap[31], 1); - EXPECT_EQ(factorToCountMap[1093], 1); - EXPECT_EQ(factorToCountMap[Integer("2167406951")], 1); - - factorToCountMap = factors(Integer("13982642746827562949728"), 1000); - EXPECT_EQ(factorToCountMap.size(), 3); - EXPECT_EQ(factorToCountMap[2], 5); - EXPECT_EQ(factorToCountMap[59], 1); - EXPECT_EQ(factorToCountMap[Integer("7406060776921378681")], 1); - - EXPECT_THROW(factors(-1), UndefinedFunctionException); - EXPECT_THROW(factors(0), UndefinedFunctionException); - EXPECT_THROW(factors(1), UndefinedFunctionException); -} - -TEST(IntegerFunctionsTests, combinationsTest) { - EXPECT_EQ(combinations(Integer(6), Integer(2)), 15); - EXPECT_EQ(combinations(Integer(10), Integer(7)), 120); - EXPECT_EQ(combinations(Integer(15), Integer(2)), 105); - - EXPECT_THROW(combinations(Integer(20), Integer(40)), UndefinedFunctionException); - EXPECT_THROW(combinations(Integer(-3), Integer(-8)), UndefinedUnaryOperatorException); - EXPECT_THROW(combinations(Integer(5), Integer(-3)), UndefinedUnaryOperatorException); -} - -TEST(IntegerFunctionsTests, multinomialCoefficientTest) { - EXPECT_EQ(multinomialCoefficient(Integer(6), {Integer(2), Integer(3), Integer(1)}), 60); - EXPECT_EQ(multinomialCoefficient(Integer(8), {Integer(8)}), 1); - EXPECT_EQ(multinomialCoefficient(Integer(5), {Integer(3), Integer(2)}), 10); - EXPECT_EQ(multinomialCoefficient(Integer(12), {Integer(3), Integer(9), Integer(0)}), 220); - - EXPECT_THROW(multinomialCoefficient(Integer(12), {Integer(3)}), UndefinedFunctionException); - EXPECT_THROW(multinomialCoefficient(Integer(12), {Integer(3), Integer(19), Integer(0)}), UndefinedFunctionException); - EXPECT_THROW(multinomialCoefficient(Integer(12), {Integer(0)}), UndefinedFunctionException); - EXPECT_THROW(multinomialCoefficient(Integer(-12), {Integer(3), Integer(9), Integer(0)}), UndefinedFunctionException); - EXPECT_THROW(multinomialCoefficient(Integer(12), {Integer(-3), Integer(9), Integer(0)}), UndefinedFunctionException); -} diff --git a/tests/src/numbers/IntegerTests.cpp b/tests/src/numbers/IntegerTests.cpp deleted file mode 100644 index 6bbf95218..000000000 --- a/tests/src/numbers/IntegerTests.cpp +++ /dev/null @@ -1,630 +0,0 @@ -#include - -#include "fintamath/numbers/Integer.hpp" - -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -TEST(IntegerTests, constructorTest) { - EXPECT_EQ(Integer(), 0); -} - -TEST(IntegerTests, stringConstructorTest) { - EXPECT_EQ(Integer("10").toString(), "10"); - EXPECT_EQ(Integer("2432432423432432454745").toString(), "2432432423432432454745"); - EXPECT_EQ(Integer("-10"), -10); - EXPECT_EQ(Integer("01"), 1); - EXPECT_EQ(Integer("-01"), -1); - EXPECT_EQ(Integer("00"), 0); - EXPECT_EQ(Integer("-00"), 0); - - EXPECT_THROW(Integer("--10"), InvalidInputException); - EXPECT_THROW(Integer("test"), InvalidInputException); - EXPECT_THROW(Integer(""), InvalidInputException); - EXPECT_THROW(Integer("+"), InvalidInputException); -} - -TEST(IntegerTests, templateConstructorTest) { - EXPECT_EQ(Integer(std::numeric_limits::max()).toString(), "18446744073709551615"); - EXPECT_EQ(Integer(std::numeric_limits::min()).toString(), "-9223372036854775808"); - EXPECT_EQ(Integer(std::numeric_limits::max()).toString(), "255"); - EXPECT_EQ(Integer(std::numeric_limits::min()).toString(), "-128"); -} - -TEST(IntegerTests, intConstructorTest) { - EXPECT_EQ(Integer(10), 10); - - const Integer a = 10; - EXPECT_EQ(a, 10); -} - -TEST(IntegerTests, intAssignmentOperatorTest) { - Integer a; - EXPECT_EQ(a = 10, 10); -} - -TEST(IntegerTests, plusAssignmentOperatorTest) { - EXPECT_EQ(Integer(5) += Integer(10), 15); - EXPECT_EQ(Integer(-5) += Integer(10), 5); - EXPECT_EQ(Integer(-10) += Integer(10), 0); - EXPECT_EQ(Integer("-72838928574893245678976545678765457483992") += Integer("-387827392020390239201210"), Integer("-72838928574893246066803937699155696685202")); -} - -TEST(IntegerTests, intPlusAssignmentOperatorTest) { - EXPECT_EQ(Integer(5) += 10, 15); -} - -TEST(IntegerTests, plusOperatorTest) { - EXPECT_EQ(Integer(-100) + Integer("10"), -90); - EXPECT_EQ(Integer("65784932384756574839238475674839") + Integer("-387827392020390239201210"), Integer("65784931996929182818848236473629")); -} - -TEST(IntegerTests, intPlusOperatorTest) { - EXPECT_EQ(Integer(5) + 10, 15); -} - -TEST(IntegerTests, intFriendPlusOperatorTest) { - EXPECT_EQ(5 + Integer(10), 15); -} - -TEST(IntegerTests, minusAssignmentOperatorTest) { - EXPECT_EQ(Integer(5) -= Integer(10), -5); - EXPECT_EQ(Integer(-5) -= Integer(-10105), 10100); - EXPECT_EQ(Integer("520039026478395743890") -= Integer("-1930275483923745483957483983"), Integer("1930276003962771962353227873")); -} - -TEST(IntegerTests, intMinusAssignmentOperatorTest) { - EXPECT_EQ(Integer(5) -= 10, -5); -} - -TEST(IntegerTests, minusOperatorTest) { - EXPECT_EQ(Integer(-100) - Integer("-748"), 648); - EXPECT_EQ(Integer("65784932384756574839238475674839") - Integer("-387827392020390239201210"), Integer("65784932772583966859628714876049")); -} - -TEST(IntegerTests, intMinusOperatorTest) { - EXPECT_EQ(Integer(5) - 10, -5); -} - -TEST(IntegerTests, intFriendMinusOperatorTest) { - EXPECT_EQ(5 - Integer(10), -5); -} - -TEST(IntegerTests, multiplyAssignmentOperatorTest) { - EXPECT_EQ(Integer(5) *= Integer("-12"), -60); - EXPECT_EQ(Integer(190) *= Integer(100), 19000); - - EXPECT_EQ(Integer(2) *= Integer(2), 4); - EXPECT_EQ(Integer(2) *= Integer(-2), -4); - EXPECT_EQ(Integer(-2) *= Integer(2), -4); - EXPECT_EQ(Integer(-2) *= Integer(-2), 4); - - EXPECT_EQ(Integer("10000000000000000000000000000000000000000000") *= Integer("10000000000000000000000000000000000000000000"), Integer("100000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); - EXPECT_EQ(Integer("100000000000000000000000000000000000000000000000000000000000000000000000000000000000000") *= Integer("100000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), Integer("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); - EXPECT_EQ(Integer("1000000000000000000000000000000000000000000000000000000000000000000000") *= Integer("100000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000"), Integer("100000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); - EXPECT_EQ(Integer("100000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000") *= Integer("1000000000000000000000000000000000000000000000000000000000000000000000"), Integer("100000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); - EXPECT_EQ(Integer("123") *= Integer("29837492356328746293432095803247329462387463287462347628437"), Integer("3670011559828435794092147783799421523873657984357868758297751")); - EXPECT_EQ(Integer("123") *= Integer("3507630615696849555869044818661735064986392883263011691538871248141434862220387449579227548346015035603501276296494442204769872208628882685816583149015034150490829747567986311156822048603845157334656209386816063095043939468216080230001796494390400252142375053346581510773088042280290835395905258970276127578670424725237113115641881479792031434427596080908227551489188776476145554883257759405245297150541759841671819727944845899493678892840111830112509529920517471699237861267263602427655073892668208557712684031475765670957010740054698088570050264362373595571625821629034477445434265168041405756975664327860057312868835959178663661834688407715795207372052181069795781487373087361"), - Integer("431438565730712495371892512695393412993326324641350438059281163521396488053107656298244988446559849379230656984468816391186694281661352570355439727328849200510372058950862316272289111978272954352162713754578375760690404554590577868290220968810019231013512131561629525825089829200475772753696346853343963692176462241204164913223951422014419866434594317951711988833170219506565903250640704406845171549516636460525633826537216045637722503819333755103838672180223649019006256935873423098601574088798189652598660135871519177527712321026727864894116182516571952255309976060371240725788414615669092908108006712326787049482866822978975630405666674149042810506762418271584881122946889745403")); - - Integer bigNum("3507630615696849555869044818661735064986392883263011691538871248141434862220387449579227548346015035603501276296494442204769872208628882685816583149015034150490829747567986311156822048603845157334656209386816063095043939468216080230001796494390400252142375053346581510773088042280290835395905258970276127578670424725237113115641881479792031434427596080908227551489188776476145554883257759405245297150541759841671819727944845899493678892840111830112509529920517471699237861267263602427655073892668208557712684031475765670957010740054698088570050264362373595571625821629034477445434265168041405756975664327860057312868835959178663661834688407715795207372052181069795781487373087361"); - EXPECT_EQ( - bigNum *= bigNum, - Integer("12303472536173859897916428377004935502004782919473057718871885043121781030098281780962637499969740130034456796500497509967452384582718074569004226484838279539257840095803149479101902072107837585131338230734054484921735569952391937234268928563893630777142850988345024717543088307452801811210636637774003502445558735145874342882934545079027970481216212551657139612736189944411920584073797480578668308872637837001226353933695298258623052077243146320976152890046183936959909708081150863318073036043586093209911389700226049811866608298458025084632141823154889542312490211657796070035617193651170851414935349019757621741341581542453267210040771001589520120490625177984198075544187001077934984041073965661299629440392924639719149765304535578896851351796566857314406226110515876882013067166666081619090773839736739801138095581269455420639319475624952362734849224487015130500274462036985670028437301153570145786839237097878094701275317259422555992691652743629535317375185705474463303523391875678091608659985127231205021506089419933399015580274121092988281352642975490569169565260763230292445030602585146983427386833017379443652221654863709315583493223508686729510859720119953570044368557853119295109670212239442035426004278725022502115464382587460494853075114778931717857481993662419358424270675936018796608915343974203803928220416770794160300461016974165792937944321")); - EXPECT_EQ( - bigNum *= bigNum, - Integer("151375436448384432254283307583486066667042190660677620373123854553192330171309426231376077199633148394587309320500780366596644977921667705846188987094209368940524153866159642542317461838630631239213601469094819727267931442110409869192021916471495566770793968771356423244153613116589891384095154889897447129616495361921128483415008013000809960124014824730978336773349172340512505436233122012217784681438531620807943478571185612552450478078388300936606517852653888025048589518914846487741067060341531436357187268537672362009339521911619031150310962055950155717666529133873841751541637455255626595846380131842901830415858642992816729709654251950863750665357762009085810629217917751342352313325984460629046549764303679784381441423865043453230665790947214415711707134874389436507764444241582593434407423309392527966674580478029178887423061253968562091672677599167671594875604798350156550372883311207885282088863879202461885968408041715086679139981263812558960095695476485505356891618587969820162186732250377710432275819830606562398013148854467177307257792538812521105073250276853587043874285676126878294501204134744955080973659170543493289121184558611797400317932087143639362969152630394559727560144885191109167802199267405992294077943816747815152047986153974462696242579776353456270439825236419290517542215340162294579962815285992414141725975115146703976251490225724031898802682695139379699275083967566953749280275248401215696451748644475142038613799290222798072247498886364828935253690749237820783821104282786528804685820847939317976725694662661166127380194678954930597817803996943971279795062385881705273889663480715671471466170947086809281202777180196503031441640466417520512377184927727082258708265839007600152745143501419320905768663557824966355252526518492368909694102745402184718285534458364891811419700240301070527639998721161225798676121766517224180501332030635179372072827350327920970532916699374836128894515290852189101489989500779928531013587309296296610484631205391906273047197136471856730859350878848416701953443562929378684861312928240015961371220036087605180304967215500558598031593601273862799041607646012945892188848304803064939675273843852174253591780671275868647310004309203524619697995493946647868123514739427870390608088912784755244273289213735492487806711200286298562110855389881142350728943050786535546037005625779944656488759175679073720657521788460803169399098915443582503593087698432551216543011752197660404175871840418634933566440380132475375830576077689889610555877165396071750587143416063996020201199751972410003093042374458757966810782966064384827015516919398703986180788431985196032764700920816810628506882704347513628278314226925268661535156504738466810090463408594081517474013296151041")); - EXPECT_EQ( - bigNum *= bigNum, - Integer("22914522759938874057257796193940596423762542563739879819187393716228927674967102320259140971970039681191953521845107003819722577675852648130582896523848489300401618605144122178714963775315121813016233845422666622391967070941222799991295148831604972014921548669988136910550583429196439564836192324208536390075346725270307881101136126066955930813005977004295048633367661493212947906274000463120197390631976069467888760302480674278463114891148564244560291804425558419637288491400563181216459405331910010819918137114169562642686365913909445366408221600536326850870319872641796188460477912754130475845019221244350802397125804616753941677689892186254852238819879711077466594270233275970184207089241959307606452888121946069973473187178429621850923035803698584605004760057193907991428349516173654483188034735443370608424952437287574373625961683858180545459455731113036740803540346295478191137401742626599685108689305122688033625091500192149433471606758187111336623695836324149798109957530488929446237876611701578903632656988704601991170700318699090994443569737006886000456073286856832541755147032007023848544143868344286688174920490227019670357331744186240639434820124532892352495837628204444865768628315003727667059064601350476306019344185835610136999805072162972396533444018543234945705785801821194544795893910083914065380374581906040367797923269828097444359083214426924695826759222422401187030525848439285325590904532357622684759168083883723952528353770651292912353239288710618208932679714147759798496233936162152171905976411257991446004244531243126651514169775566408412416511444811109103899344293964379515901127515320476282176914209630350256334388105277492245601971083748259439326882633122390095262959180743540407733675527295279499991631717528076028720677403681769874412993756416028695509846567879736829425609338122366782343942650249332310100547917756764208734431846361875150022547195730876860679811370074262572557427240358446300607238583697760935031783739309862948733945730295672533557727771537494882239568329563576770570606329684880497260939187425470873867143488273389096394243998495619633686867346743769228160190083712400123848953650078424071169480737580861136715479714127746230384382865950765497480109352661480555006731263945743183034301238410236979626291311032814899739382004792340528714915330712266376650002122663569232455538119647024917892734601362157376909353726319281790738177948929145333250777783978176541297394727906730299383146616448180733889068268599261810017781838919180138662094081385192258174261545871952875801308190538317356227339188486353746330923973530201740072804014657847444988089284144170453189654603578954204626924643099816144886147459088949092784033892978787575062623503061889652707999392292347473952957532795235401047800864405435853399880388715911468503525171819281118283726059420706666552865328266533470636056519420573479139923915043133111864940316152682413241917666115171401791140032628091019109335553629107070620749415293936339348629747315656963987875872250499927462252367512342970015455071101112416923988458694971674401354945910476837308082758970341531436126768614092284352396793570217362532358491921745166515235152898497406958486162902354227108786831372351765343347904984158770895141952588592652299981928710073552216436189302069313410225821322433564703182574388010762810684722915809782551097189131942038189563611436852004587748807950758655280277391196850285491455416185798115505237175677506901602668904618826165911951495633018090606511774557689333941216768544315914736643372744828367204001912510197427409448831552751042000422039004149802611430340871495790858997852479826193964390248251280477764007698046982394341468012728793697828122999388706064260426692774210328226339341379438411206398931797051585521526807317101524009057371016132112545199764943549943326444646235669506956042908664599458497547456749876794859537886281768596029303723720332705455665634858099642014423205143739524386758549220521234830839208965722364098657699818192394699943364222343941223479060118452399061520722297962510624978048981715339309875274789665446635366589494597138864901393177319919152360393110944458711815529566970440379045660106657941905985215623021370512088133019589637861683593525102496937340784575014892786755977183192764911904351528899931278143796813833172083355705686681659522250862553325448682854099048230487915252166521639972564771433268262796140330985771226586402923404606257921403131362992358393518563773523925487734949536127043741829152981325876012232440805450076516225451540372122407892137482317363205677671074187015524609263873584616317672015801549437543267647452011544121490920840199642082230695556813095518035464095432997410772453597587386072115154148107567203457891346737590794597292704435998478167499557259458457163119774832200481730716782158250823789304648687511787714897784958091435912146321482406579658845079719272836892750418667427354580814233072015777425586167263754843785617094707143927179461892972294357012992365104447070705874208671348211245412452116578149929826222475181307607501961730938328115766177264457813780894607079802908527780472438061400951946974872719185935072427958936902748097045969906062446607202359056893700205826243288062391760906322233464801517244406643473041960333113251024605272472620391940968519334443603057579347215930939098326014060418702027599415372606679852539380605614835673895284870410708896194577628004973269175667606960064970207771488716919268551306001746368500505085383681")); - EXPECT_EQ( - bigNum *= bigNum, - Integer("525075353315756673987618364527862464858716372017412885232571478560168577552209070511173433565235955940364560952860656397837830394604637877201606477680271846821784909835242978112259166132208524924371648278765953812076911502580473519197862690332109930354425292582838847304211721368377024071571024407564655862023623582785542891295169805475740236707532369847647160352595561399174226161372051119367964038413514796750032120455727324186149712584011077192245186945541229988604036892860284188482193277127170215420012582011112036715313180465998072023464100003713416938236616004168899320316839467590116601389187047878469071367161056823939650210465397815615597446976774529260839387016814553478936129356930887953193690505163691453503861735210235948342724886085807456292589191359800580376022351805601942695143564683078028295583869318805512467023663787323317724850556307061760008730844382571845690381429431428069844374228399683130459382924309222707554640404717393785442614523565363121404370242009703671940044418512035745065429309883708579915497932725860094821724795303758838910625487782173119919216349329132068166657584939969081037646017819721196787342928377382488352866314556440200216960855423459540535978088959749396077685648336789277868136546135389801645652736482147965516245998418297439365831698615078556680015084742463574896059538336809285860015649813246655901546424402916873513079542350464414355328507053386377289360562135812157949213621273789622610851546572940940266442838367314772058531652940537902779247352033821267988111366161726953439264776175337211674025972709622461859859669381264026406916182825306650874382453789863499797648559340902745209243319387265607551166691648364483889028843962175563092239789826528062149461078094499127106117771100473287337155018275978015580024920678769041767385184723781015538143092147637625197771971723604938366108165768288391374919944812915666066799654179578072062195349281603083993828127738839238238659251366674702054074262900682547657200000859878461992913998240124974252120816160534031574133749686183834162937299307302725926433190615071123808547577208494330171188656297049145976208286879876129406757662106973024660216895455977147734405953610178246891263282261594031233674085339574304981172317700845321606952993609424793587876309390345099382379035188708348138679973336159244663563744793331049992530061088629871008386844749932669008013727216327350161061389033606939706275004632122401251122740736099510637739594430929719490265918643152921412072495781217406540469185138825548184989058911183569847303792839920513469663788124531433355682992291463444807316721390064812904712941785290633523647084996791706557448701382325960475660048561675767919364598651758367276616933631674225370132050716810773636418447517799431986508269948832893618550253900094016562859802441412434562565766030741277482133930968353549550315582616706002737317541556722471866931277674872751050406685192150104668791849178350013296372518506450153161649770857168801536454075240511220431245474533706817622903745335817600547636690696256452875281358536643727688483097449339123033027260140628052526172530234626680697704913073492025678344122142772514923761791200093419079356280283648119280857202306189979538818598329663265822394044482653084672658606183662599235626397648062587254925013618451314703520753086840309352274432406492485686029137036085326501117284165451719931597019319684593970034477606801750176622212236473166420105977544570073434738997380085658275644171346821845532738847215699501809642064493592669480898207041305631717657969732074872468803536005458671257609610852633409668856553509125697513192231447443131746616953384410706678631268949624865474289113819418373999407633292855662737878765993029417087207959889515315452933504030428664798256259414653908774703682809006926497009584012082724453910245356601156916366083495783068922940641472466048641578463464892844501460667299570052794177880506351138130523817247338403035678745336098371836315418775428020124793558500934001772214752333961310267621362252617684894960119016690569699123655471513974952925508694750492080810823344275851513387794990204687695673011847169848995219282391362362339131013291775654057383785423640585148195121914498275218438302525126573227100575001740983727707669096625707914588059911504831480638139061560295121679804521657768055614015091437485681689086419261599223472443886584652448808235095285534066651138993954965313295519655208338300767897261119303484943657111771172192833933307752290935398300876853849454482620894161226863560809415132749665404913265676690102022997597966256646351582215099452782525505135029945775939193620154493271081788802951835908247250628078673663308143962473139129591507074619771199406429104620297725152587440996233578277369149321213655413829719984245773745267853037287695097583967966905763984375463306983952548195606590815490671153229773602186393940874255149044744976942492699395393325071974619197602821558044196278697884718114465622126251745855059203612647573705891131313316421774138495800552379635170509097566160259791415259830835226608489176959856445436969045023501348219310838768240408165382826275009942861253719719531832747070084673476271624183685963639612061391886072913996863237764630580879370239551187240132494944685531582811784143827837105534017958825465791108732628186088484006690731597117089266033508597841418714345819569016442937499563423997698578393270432352885335924095484562284154359045466224797484593823207543788244541185662201875304057485292030507417454010592001520129739124185997180661397699345717097539662749330639502216007335018498564555378227937603279949983925641000940152397036713073444333366931349050064744300330033058918403228693399623811113254566920933807536518355228543913382981841497691561916952265920231330756270658147873743172886300568831197683112643325886246567922048333391808812200219558307281308888496836417464630527152193185179154836730104679322521490923834208200642101851260187883405377916781905355733533082703245059144726524120545922163654204970506770854094822827087288192990555593749164296444198196112515796115036170886553001191091014711477592966832412412395131786254019901961511973943480164362208147683400378344665066549209892098054542481454731127264027359336344574718430440262580260412005882564900597051874843228978824506422646767162694551369756470030387773591193311635253168823679898907885852046674494676851673345178876824583520181875809284046172493900582861874455577160944122690597719972546261194473607000285296133281163483054968200617383169665728265448969708194181807219307771722715379969913714215109895806854117505396588426465845511706883667938673904517415181299036854841913818170413576571482702051034475497124137650803665704304818071824059979473144898706484278261322319954181748083155910248365779976924454460562447046465257509770510397673977739157371881574104652306714007208095619978502621690781249771964340449663183430484570494456781672407437199438567416737768819329579632497745690074591949654084298416319789264471419531839499576655712436221533893769277247292025837494520816793046055730955263931617024711147033181287029822052440119691229346224448633529892161743767554557111529031937873427853540712225973420368466692812400378892098219817693929605399543992607241922351591775221893754698738365973580538040105891490353934003827740354602307899409923517743764081462495439306859332473483662123846334053725067114506414490855645232670464725616633016909127428704523494874088285841696376035865234837005623814190056761810644063797460425676898204366569273562337457382750078343095731459612952417145995042869758205308314159344928884188506745133124880941046263278283565853783610230805500193523082332247572532394281976697288988764646763673337672281862087937684322466856005950361098646512865199381542942670006951849511892508341594164830143201451859620892460990612613377187456280324124110545347047853923268370125737507075498790507164704797846753656435887128026945764750182084756718845692706340151314175123289294628378396365876381378173109675695264889221708824920571769882141470739824827749221268338203742767505294406618135611657174547075581233072466023066124038338435412635230983394554384953778300407259687648443515470204723825916171594517902342586149143655042361903300375456931499997522159779991577547292813073697009088735089061023530906373974105270684428174109860820199028456312448574213702168482555659668995130163990647511426431888970109123765942300839055779598067338542073051246311570678598527616314449766851282142845070073361103187662858802053013654734458206767897552976640822559598818245455394779247516263574648226664346236551508702679083410016278869995994060435331540325672022513021479422312979712385317000169053048071561851447695143844851283249830456895626179072165200509905225261746909288726299887356441471923143953484462493176001670411860274102892740447720037821993967439540002177852007379653726200397180606830200464336727913726057000435818060038141627719459438535148533180556382971831138530184113148751201274456906148407002112965308464200869659663800924510271118270253547817692214329226444698373644992831169365954282311459343787760019842742268228114575225014765326691171155942106032930738538485214275197826606171007274432422147327734928642478655312652124817665119261080347747454026341242124337631046995193881546946579378917993093301616893051090016635865578611748575115441432557247810134804756157628006413600655027201493261157165070135491076039905304502614717823693292626326609571626638080809687246864700316951722810325833194726229292587054056791885294417734789272804200827758259781528645238700414063833093095281483089913730990690638307371919875661563050717963498646198893571318794098759955001140362148262519261037837015035243359364476296102715468614047737336450771691747186870301981790380912839918048286023064226484733749405982026685682893902900705711207899504387905988214693522369292360746014624164732048241406798782632934661157099415619954855413917237889477351899485852638485624349706454648835190464996690342216094734288703900942777884244520854062658764228247343256443286202882064035552413867580110446571711031696206295404899192522768540407161137320732919347841392014962878706097079470555912173163437138767759383691371529737677448521710703438560293409811559466136416706663738455954156557979888543673781192761780623419404598391260144581043707596545482362298237262689094674452239002072487348812153201280571935376691292142097136332249842271008619134945668397449003661477459397828280249836195177557873354496650101252149620963022402320837724722221521355457738829403774528586763001984673142693533057996208909790775600257616624887416254259829992772490203085569404796254996239858440041433274200690837181845702296096899881452319022399743878664475279581420130632815890324906120799587196239625285537049703745880213074847992463253073407426073938512212379965366695424855366627524513096871821462780954251198329876879475643655179996936141808182981109761")); -} - -TEST(IntegerTests, intMultiplyAssignmentOperatorTest) { - EXPECT_EQ(Integer(5) *= 10, 50); -} - -TEST(IntegerTests, multiplyOperatorTest) { - EXPECT_EQ(Integer(100) * Integer(-748), -74800); - EXPECT_EQ(Integer(63275) * Integer(4), 253100); - EXPECT_EQ(Integer("-46387457368576823782") * Integer("-4837274673279875647746473847384738478378327647387463746372"), - Integer("224388872686866615413795053083509315281416419176500823292877913926466185818904")); -} - -TEST(IntegerTests, intMultiplyOperatorTest) { - EXPECT_EQ(Integer(5) * 10, 50); -} - -TEST(IntegerTests, intFriendMultiplyOperatorTest) { - EXPECT_EQ(5 * Integer(10), 50); -} - -TEST(IntegerTests, divideAssignmentOperatorTest) { - EXPECT_EQ(Integer(-25) /= Integer(368273929), 0); - EXPECT_EQ(Integer(2000) /= Integer(-368273929), 0); - EXPECT_EQ(Integer(-20) /= Integer(-20), 1); - EXPECT_EQ(Integer(-29829920) /= Integer(1), -29829920); - EXPECT_EQ(Integer(150067278) /= Integer(100000), 1500); - - EXPECT_EQ(Integer(2) /= Integer(2), 1); - EXPECT_EQ(Integer(2) /= Integer(-2), -1); - EXPECT_EQ(Integer(-2) /= Integer(2), -1); - EXPECT_EQ(Integer(-2) /= Integer(-2), 1); - - EXPECT_EQ(Integer(0) /= Integer("368273929654738476473823743829388329882"), 0); - EXPECT_EQ(Integer("10000000000000000000000000000000000000000000") /= - Integer("10000000000000000000000000000000000000000"), - Integer("1000")); - EXPECT_EQ(Integer("-4837274673279875647746473847384738478378327647387463746372") /= Integer("-463874573"), - Integer("10427979792028556925767245809751978965181020274175")); - EXPECT_EQ(Integer("100000000000000000000000000000000000000000000000000000000000000000000000000000000") /= - Integer("7182818284590452353602874713526624977572470936999595749669676277240766335354759"), - 13); - - EXPECT_EQ( - Integer("100000000000000000000000000000000000000000000000000000000000000000000000000000000000000") /= - Integer("10000000000000000000000000000000000000000000"), - Integer("10000000000000000000000000000000000000000000")); - EXPECT_EQ( - Integer("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") /= - Integer("100000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), - Integer("100000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); - EXPECT_EQ( - Integer("100000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") /= - Integer("100000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000"), - Integer("1000000000000000000000000000000000000000000000000000000000000000000000")); - EXPECT_EQ( - Integer("100000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") /= - Integer("1000000000000000000000000000000000000000000000000000000000000000000000"), - Integer("100000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000")); - - Integer bigA("12303472536173859897916428377004935502004782919473057718871885043121781030098281780962637499969740130034456796500497509967452384582718074569004226484838279539257840095803149479101902072107837585131338230734054484921735569952391937234268928563893630777142850988345024717543088307452801811210636637774003502445558735145874342882934545079027970481216212551657139612736189944411920584073797480578668308872637837001226353933695298258623052077243146320976152890046183936959909708081150863318073036043586093209911389700226049811866608298458025084632141823154889542312490211657796070035617193651170851414935349019757621741341581542453267210040771001589520120490625177984198075544187001077934984041073965661299629440392924639719149765304535578896851351796566857314406226110515876882013067166666081619090773839736739801138095581269455420639319475624952362734849224487015130500274462036985670028437301153570145786839237097878094701275317259422555992691652743629535317375185705474463303523391875678091608659985127231205021506089419933399015580274121092988281352642975490569169565260763230292445030602585146983427386833017379443652221654863709315583493223508686729510859720119953570044368557853119295109670212239442035426004278725022502115464382587460494853075114778931717857481993662419358424270675936018796608915343974203803928220416770794160300461016974165792937944321"); - EXPECT_EQ(bigA /= - Integer("3507630615696849555869044818661735064986392883263011691538871248141434862220387449579227548346015035603501276296494442204769872208628882685816583149015034150490829747567986311156822048603845157334656209386816063095043939468216080230001796494390400252142375053346581510773088042280290835395905258970276127578670424725237113115641881479792031434427596080908227551489188776476145554883257759405245297150541759841671819727944845899493678892840111830112509529920517471699237861267263602427655073892668208557712684031475765670957010740054698088570050264362373595571625821629034477445434265168041405756975664327860057312868835959178663661834688407715795207372052181069795781487373087361"), - Integer("3507630615696849555869044818661735064986392883263011691538871248141434862220387449579227548346015035603501276296494442204769872208628882685816583149015034150490829747567986311156822048603845157334656209386816063095043939468216080230001796494390400252142375053346581510773088042280290835395905258970276127578670424725237113115641881479792031434427596080908227551489188776476145554883257759405245297150541759841671819727944845899493678892840111830112509529920517471699237861267263602427655073892668208557712684031475765670957010740054698088570050264362373595571625821629034477445434265168041405756975664327860057312868835959178663661834688407715795207372052181069795781487373087361")); - - EXPECT_THROW(Integer(-25) /= Integer(0), UndefinedBinaryOperatorException); -} - -TEST(IntegerTests, intDivideAssignmentOperatorTest) { - EXPECT_EQ(Integer(10) /= 5, 2); -} - -TEST(IntegerTests, divideOperatorTest) { - EXPECT_EQ(Integer(-25) / Integer(368273929), 0); - EXPECT_EQ(Integer("-4837274673279875647746473847384738478378327647387463746372") / Integer("-463874573"), - Integer("10427979792028556925767245809751978965181020274175")); -} - -TEST(IntegerTests, intDivideOperatorTest) { - EXPECT_EQ(Integer(10) / 5, 2); -} - -TEST(IntegerTests, intFriendDivideOperatorTest) { - EXPECT_EQ(10 / Integer(5), 2); -} - -TEST(IntegerTests, moduloAssignmentOperatorTest) { - EXPECT_EQ(Integer(0) %= Integer(2), Integer(0)); - EXPECT_EQ(Integer(0) %= Integer(-2), Integer(0)); - - EXPECT_EQ(Integer(10) %= Integer(1), Integer(0)); - EXPECT_EQ(Integer(10) %= Integer(-1), Integer(0)); - EXPECT_EQ(Integer(-10) %= Integer(1), Integer(0)); - EXPECT_EQ(Integer(-10) %= Integer(-1), Integer(0)); - - EXPECT_EQ(Integer(2) %= Integer(3), Integer(2)); - EXPECT_EQ(Integer(2) %= Integer(-3), Integer(2)); - EXPECT_EQ(Integer(-2) %= Integer(3), Integer(-2)); - EXPECT_EQ(Integer(-2) %= Integer(-3), Integer(-2)); - - EXPECT_EQ(Integer(19) %= Integer(11), Integer(8)); - EXPECT_EQ(Integer(19) %= Integer(-11), Integer(8)); - EXPECT_EQ(Integer(-19) %= Integer(11), Integer(-8)); - EXPECT_EQ(Integer(-19) %= Integer(-11), Integer(-8)); - - EXPECT_EQ(Integer(25) %= Integer(368273929), 25); - EXPECT_EQ(Integer(25) %= Integer(-368273929), 25); - EXPECT_EQ(Integer(-25) %= Integer(368273929), -25); - EXPECT_EQ(Integer(-25) %= Integer(-368273929), -25); - - EXPECT_EQ(Integer(25) %= Integer(3), 1); - EXPECT_EQ(Integer(25) %= Integer(-3), 1); - EXPECT_EQ(Integer(-25) %= Integer(3), -1); - EXPECT_EQ(Integer(-25) %= Integer(-3), -1); - - EXPECT_EQ(Integer(2000) %= Integer(36), Integer(20)); - EXPECT_EQ(Integer(2000) %= Integer(-36), Integer(20)); - EXPECT_EQ(Integer(-2000) %= Integer(36), Integer(-20)); - EXPECT_EQ(Integer(-2000) %= Integer(-36), Integer(-20)); - - EXPECT_EQ(Integer(0) %= Integer("368273929654738476473823743829388329882"), - 0); - EXPECT_EQ(Integer("54732897657873247528747287294738765738746547387476327946763287467387267328724673874") %= Integer("47632837528673287446238746237943"), - Integer("25193809905191080888100466723580")); - EXPECT_EQ(Integer("5473289765787324752874728729473876573874654738747632794676328746738849389483948938493848394839849383893847267328724673874") %= Integer("1738383928837528673287446238746237943"), - Integer("1186817955126284001426922341829394317")); - - EXPECT_THROW(Integer(-25) %= Integer(0), UndefinedBinaryOperatorException); -} - -TEST(IntegerTests, intModuloAssignmentOperatorTest) { - EXPECT_EQ(Integer(10) %= 4, 2); -} - -TEST(IntegerTests, moduloOperatorTest) { - EXPECT_EQ(Integer(-25) % Integer(3), -1); - EXPECT_EQ(Integer("54732897657873247528747287294738765738746547387476327946763287467387267328724673874") % - Integer("47632837528673287446238746237943"), - Integer("25193809905191080888100466723580")); -} - -TEST(IntegerTests, intModuloOperatorTest) { - EXPECT_EQ(Integer(10) % 4, 2); -} - -TEST(IntegerTests, intFriendModuloOperatorTest) { - EXPECT_EQ(10 % Integer(4), 2); -} - -TEST(IntegerTests, bitAndAssignmentOperatorTest) { - EXPECT_EQ(Integer(192) &= Integer(361), 64); - EXPECT_EQ(Integer(192) &= Integer(-361), 128); - EXPECT_EQ(Integer(-192) &= Integer(361), 320); - EXPECT_EQ(Integer(-192) &= Integer(-361), -512); - - EXPECT_EQ(Integer("12091392839827399999999999999999999992983729837928392800000711") &= - Integer("239821736218376218710101004349800036128736128451262548126372110293"), - Integer("1646269354501586035462268928227889963640732025882107625773765")); -} - -TEST(IntegerTests, intBitAndAssignmentOperatorTest) { - EXPECT_EQ(Integer(5) &= 3, 1); -} - -TEST(IntegerTests, bitAndOperatorTest) { - EXPECT_EQ(Integer(5) & Integer(3), 1); -} - -TEST(IntegerTests, intBitAndOperatorTest) { - EXPECT_EQ(Integer(5) & 3, 1); -} - -TEST(IntegerTests, intFriendBitAndOperatorTest) { - EXPECT_EQ(5 & Integer(3), 1); -} - -TEST(IntegerTests, bitOrAssignmentOperatorTest) { - EXPECT_EQ(Integer(192) |= Integer(361), 489); - EXPECT_EQ(Integer(192) |= Integer(-361), -297); - EXPECT_EQ(Integer(-192) |= Integer(361), -151); - EXPECT_EQ(Integer(-192) |= Integer(-361), -41); - - EXPECT_EQ(Integer("12091392839827399999999999999999999992983729837928392800000711") |= - Integer("239821736218376218710101004349800036128736128451262548126372110293"), - Integer("239832181341861544524065542080871808238765471449074594411546337239")); -} - -TEST(IntegerTests, intBitOrAssignmentOperatorTest) { - EXPECT_EQ(Integer(5) |= 3, 7); -} - -TEST(IntegerTests, bitOrOperatorTest) { - EXPECT_EQ(Integer(5) | Integer(3), 7); -} - -TEST(IntegerTests, intBitOrOperatorTest) { - EXPECT_EQ(Integer(5) | 3, 7); -} - -TEST(IntegerTests, intFriendBitOrOperatorTest) { - EXPECT_EQ(5 | Integer(3), 7); -} - -TEST(IntegerTests, bitXorAssignmentOperatorTest) { - EXPECT_EQ(Integer(192) ^= Integer(361), 425); - EXPECT_EQ(Integer(192) ^= Integer(-361), -425); - EXPECT_EQ(Integer(-192) ^= Integer(361), -471); - EXPECT_EQ(Integer(-192) ^= Integer(-361), 471); - - EXPECT_EQ(Integer("12091392839827399999999999999999999992983729837928392800000711") ^= - Integer("239821736218376218710101004349800036128736128451262548126372110293"), - Integer("239830535072507042938030079811943580348801830717048712303920563474")); -} - -TEST(IntegerTests, intBitXorAssignmentOperatorTest) { - EXPECT_EQ(Integer(5) ^= 3, 6); -} - -TEST(IntegerTests, bitXorOperatorTest) { - EXPECT_EQ(Integer(5) ^ Integer(3), 6); -} - -TEST(IntegerTests, intBitXorOperatorTest) { - EXPECT_EQ(Integer(5) ^ 3, 6); -} - -TEST(IntegerTests, intFriendBitXorOperatorTest) { - EXPECT_EQ(5 ^ Integer(3), 6); -} - -TEST(IntegerTests, bitLeftShiftAssignmentOperatorTest) { - EXPECT_EQ(Integer(192) <<= Integer(5), 6144); - EXPECT_EQ(Integer(-192) <<= Integer(5), -6144); - - EXPECT_EQ(Integer("12091392839827399999999999999999999992983729837928392800000711") <<= 5, - Integer("386924570874476799999999999999999999775479354813708569600022752")); - - EXPECT_THROW(Integer(192) <<= Integer(-5), UndefinedBinaryOperatorException); - EXPECT_THROW(Integer(-192) <<= Integer(-5), UndefinedBinaryOperatorException); -} - -TEST(IntegerTests, intBitLeftShiftAssignmentOperatorTest) { - EXPECT_EQ(Integer(5) <<= 3, 40); -} - -TEST(IntegerTests, bitLeftShiftOperatorTest) { - EXPECT_EQ(Integer(5) << Integer(3), 40); -} - -TEST(IntegerTests, intBitLeftShiftOperatorTest) { - EXPECT_EQ(Integer(5) << 3, 40); -} - -TEST(IntegerTests, intFriendBitLeftShiftOperatorTest) { - EXPECT_EQ(5 << Integer(3), 40); -} - -TEST(IntegerTests, bitRightShiftAssignmentOperatorTest) { - EXPECT_EQ(Integer(192) >>= Integer(5), 6); - EXPECT_EQ(Integer(-192) >>= Integer(5), -6); - - EXPECT_EQ(Integer("12091392839827399999999999999999999992983729837928392800000711") >>= 5, - Integer("377856026244606249999999999999999999780741557435262275000022")); - - EXPECT_THROW(Integer(192) >>= Integer(-5), UndefinedBinaryOperatorException); - EXPECT_THROW(Integer(-192) >>= Integer(-5), UndefinedBinaryOperatorException); -} - -TEST(IntegerTests, intBitRightShiftAssignmentOperatorTest) { - EXPECT_EQ(Integer(5) >>= 3, 0); -} - -TEST(IntegerTests, bitRightShiftOperatorTest) { - EXPECT_EQ(Integer(5) >> Integer(3), 0); -} - -TEST(IntegerTests, intBitRightShiftOperatorTest) { - EXPECT_EQ(Integer(5) >> 3, 0); -} - -TEST(IntegerTests, intFriendBitRightShiftOperatorTest) { - EXPECT_EQ(5 >> Integer(3), 0); -} - -TEST(IntegerTests, bitNotOperatorTest) { - EXPECT_EQ(~Integer(5), -6); - EXPECT_EQ(~Integer("-6748346738212618723653728362813238128121823281328381262673676266"), - Integer("6748346738212618723653728362813238128121823281328381262673676265")); -} - -TEST(IntegerTests, preIncrementOperatorTest) { - Integer a = 5; - EXPECT_EQ(++a, 6); - - Integer b("4632819374289745632874563287263891364238928"); - EXPECT_EQ(++b, Integer("4632819374289745632874563287263891364238929")); -} - -TEST(IntegerTests, postIncrementOperatorTest) { - Integer a = 5; - EXPECT_EQ(a++, 5); - EXPECT_EQ(a, 6); - - Integer b("4632819374289745632874563287263891364238928"); - EXPECT_EQ(b++, Integer("4632819374289745632874563287263891364238928")); - EXPECT_EQ(b, Integer("4632819374289745632874563287263891364238929")); -} - -TEST(IntegerTests, preDecrementOperatorTest) { - EXPECT_EQ(--Integer(5), 4); - EXPECT_EQ(--Integer("4632819374289745632874563287263891364238928"), - Integer("4632819374289745632874563287263891364238927")); -} - -TEST(IntegerTests, postDecrementOperatorTest) { - Integer a = 5; - EXPECT_EQ(a--, 5); - EXPECT_EQ(a, 4); - - Integer b("4632819374289745632874563287263891364238928"); - EXPECT_EQ(b--, Integer("4632819374289745632874563287263891364238928")); - EXPECT_EQ(b, Integer("4632819374289745632874563287263891364238927")); -} - -TEST(IntegerTests, unaryPlusOperatorTest) { - EXPECT_EQ(+Integer(5), 5); - EXPECT_EQ(+Integer("-6748346738212618723653728362813238128121823281328381262673676266"), - Integer("-6748346738212618723653728362813238128121823281328381262673676266")); -} - -TEST(IntegerTests, unaryMinusOperatorTest) { - EXPECT_EQ(-Integer(5), -5); - EXPECT_EQ(-Integer(0), 0); - EXPECT_EQ(-Integer("-6748346738212618723653728362813238128121823281328381262673676266"), - Integer("6748346738212618723653728362813238128121823281328381262673676266")); -} - -TEST(IntegerTests, equalOperatorTest) { - EXPECT_TRUE(Integer(13663) == Integer(13663)); - - EXPECT_FALSE(Integer("5643879274839203876783492873448927") == Integer("-5643879274839203876783492873448927")); - EXPECT_FALSE(Integer(13663) == Integer(298392)); -} - -TEST(IntegerTests, intEqualOperatorTest) { - EXPECT_TRUE(Integer(283746) == 283746); -} - -TEST(IntegerTests, intFriendEqualOperatorTest) { - EXPECT_TRUE(283746 == Integer(283746)); -} - -TEST(IntegerTests, notEqualOperatorTest) { - EXPECT_TRUE(Integer(13663) != 298392); - EXPECT_TRUE(Integer("5643879274839203876783492873448927") != Integer("-5643879274839203876783492873448927")); - - EXPECT_FALSE(Integer(13663) != 13663); -} - -TEST(IntegerTests, intNotEqualOperatorTest) { - EXPECT_TRUE(Integer(283746) != 12121); -} - -TEST(IntegerTests, intFriendNotEqualOperatorTest) { - EXPECT_TRUE(283746 != Integer(12121)); -} - -TEST(IntegerTests, lessOperatorTest) { - EXPECT_TRUE(Integer("-724627382732") < Integer("643864837483437378342")); - EXPECT_TRUE(Integer("7236") < Integer("748274299")); - EXPECT_TRUE(Integer("1") < Integer("10000000000000000000000000000000000")); - - EXPECT_FALSE(Integer("-7236726372") < Integer("-64283827387283728")); - EXPECT_FALSE(Integer("7236726372") < Integer("-62736")); -} - -TEST(IntegerTests, intLessOperatorTest) { - EXPECT_TRUE(Integer(283746) < 2379264); -} - -TEST(IntegerTests, intFriendLessOperatorTest) { - EXPECT_TRUE(283746 < Integer(2379264)); -} - -TEST(IntegerTests, moreOperatorTest) { - EXPECT_TRUE(Integer("-7236726372") > Integer("-64283827387283728")); - EXPECT_TRUE(Integer("7236726372") > Integer("-727")); - EXPECT_TRUE(Integer("7236") > Integer("483")); - - EXPECT_FALSE(Integer("-724627382732") > Integer("643864837483437378342")); - EXPECT_FALSE(Integer("1") > Integer("10000000000000000000000000000000000")); -} - -TEST(IntegerTests, intMoreOperatorTest) { - EXPECT_TRUE(Integer(283746) > 12121); -} - -TEST(IntegerTests, intFriendMoreOperatorTest) { - EXPECT_TRUE(283746 > Integer(12121)); -} - -TEST(IntegerTests, lessEqualOperatorTest) { - EXPECT_TRUE(Integer("-724627382732") <= Integer("643864837483437378342")); - EXPECT_TRUE(Integer("-7246") <= Integer("-7246")); - EXPECT_TRUE(Integer("1") <= Integer("10000000000000000000000000000000000")); - - EXPECT_FALSE(Integer("-7236726372") <= Integer("-64283827387283728")); - EXPECT_FALSE(Integer("7236726372") <= Integer("0")); - EXPECT_FALSE(Integer("7236") <= Integer("-74827")); -} - -TEST(IntegerTests, intLessEqualOperatorTest) { - EXPECT_TRUE(Integer(12121) <= 283746); -} - -TEST(IntegerTests, intFriendLessEqualOperatorTest) { - EXPECT_TRUE(12121 <= Integer(283746)); -} - -TEST(IntegerTests, moreEqualOperatorTest) { - EXPECT_TRUE(Integer("-7246") >= Integer("-7246")); - EXPECT_TRUE(Integer("-7236726372") >= Integer("-64283827387283728")); - EXPECT_TRUE(Integer("7236726372") >= Integer("0")); - EXPECT_TRUE(Integer("7236") >= Integer("-748274299")); - - EXPECT_FALSE(Integer("-724627382732") >= Integer("643864837483437378342")); - EXPECT_FALSE(Integer("1") >= Integer("10000000000000000000000000000000000")); -} - -TEST(IntegerTests, intMoreEqualOperatorTest) { - EXPECT_TRUE(Integer(283746) >= 12121); -} - -TEST(IntegerTests, intFriendMoreEqualOperatorTest) { - EXPECT_TRUE(283746 >= Integer(12121)); -} - -TEST(IntegerTests, toStringTest) { - EXPECT_EQ(Integer("618288").toString(), "618288"); - EXPECT_EQ(Integer("0").toString(), "0"); - EXPECT_EQ(Integer("-738").toString(), "-738"); -} - -TEST(IntegerTests, signTest) { - EXPECT_EQ(Integer(-2).sign(), -1); - EXPECT_EQ(Integer(-1).sign(), -1); - EXPECT_EQ(Integer(0).sign(), 0); - EXPECT_EQ(Integer(1).sign(), 1); - EXPECT_EQ(Integer(2).sign(), 1); -} - -TEST(IntegerTests, intOperatorTest) { - EXPECT_EQ(static_cast(Integer(-2)), -2); - EXPECT_EQ(static_cast(Integer(10)), 10); - EXPECT_EQ(static_cast(Integer(0)), 0); - EXPECT_EQ(static_cast(Integer("100000000000000000000000000000000000000000000000000")), 9223372036854775807); - EXPECT_EQ(static_cast(Integer("-100000000000000000000000000000000000000000000000000")) + 1, -9223372036854775807); -} - -TEST(IntegerTests, isPreciseTest) { - EXPECT_TRUE(Integer(1).isPrecise()); -} - -TEST(IntegerTests, isComplexTest) { - EXPECT_FALSE(Integer(1).isComplex()); -} - -TEST(IntegerTests, equalsTest) { - const Integer a; - const Rational b; - const Rational c(1); - - EXPECT_EQ(a, a); - EXPECT_EQ(a, Integer()); - EXPECT_EQ(Integer(), a); - EXPECT_EQ(a, cast(Integer())); - EXPECT_EQ(cast(Integer()), a); - EXPECT_EQ(a, b); - EXPECT_EQ(b, a); - EXPECT_NE(a, c); - EXPECT_NE(c, a); -} - -TEST(IntegerTests, getClassTest) { - EXPECT_EQ(Integer().getClass(), MathObjectClass("Integer")); - EXPECT_EQ(Integer().getClass().getParent(), IInteger::getClassStatic()); -} - -TEST(IntegerTests, hashTest) { - constexpr std::hash hasher; - - EXPECT_EQ(hasher(Integer(0)), hasher(Integer(0))); - EXPECT_EQ(hasher(Integer(12)), hasher(Integer(12))); - EXPECT_EQ(hasher(Integer(-12)), hasher(Integer(-12))); - EXPECT_EQ(hasher(Integer("452734865298734659873246238756987435")), hasher(Integer("452734865298734659873246238756987435"))); - EXPECT_EQ(hasher(Integer("-452734865298734659873246238756987435")), hasher(Integer("-452734865298734659873246238756987435"))); - - EXPECT_NE(hasher(Integer(0)), hasher(Integer(1))); - EXPECT_NE(hasher(Integer(12)), hasher(Integer(13))); - EXPECT_NE(hasher(Integer(-12)), hasher(Integer(-13))); - EXPECT_NE(hasher(Integer("452734865298734659873246238756987435")), hasher(Integer("452734865298734659873246238756987436"))); - EXPECT_NE(hasher(Integer("-452734865298734659873246238756987435")), hasher(Integer("-452734865298734659873246238756987436"))); -} diff --git a/tests/src/numbers/NumberAbstractTests.cpp b/tests/src/numbers/NumberAbstractTests.cpp deleted file mode 100644 index c3fa499e0..000000000 --- a/tests/src/numbers/NumberAbstractTests.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include - -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -TEST(NumberAbstractIntegerTests, multiplyTest) { - EXPECT_EQ((Integer(0) * cast(Real(2)))->toString(), "0"); - EXPECT_EQ((Integer(1) * cast(Real(2)))->toString(), "2.0"); -} - -TEST(NumberAbstractIntegerTests, divideTest) { - EXPECT_EQ((Integer(4) / cast(Integer(2)))->toString(), "2"); - EXPECT_EQ((Integer(1) / cast(Integer(2)))->toString(), "1/2"); - - EXPECT_EQ((Integer(0) / cast(Real(2)))->toString(), "0"); - EXPECT_EQ((Integer(1) / cast(Real(2)))->toString(), "0.5"); - - EXPECT_THROW((Integer(0) / cast(Integer(0)))->toString(), UndefinedException); - EXPECT_THROW((Integer(0) / cast(Real(0)))->toString(), UndefinedException); -} - -//-------------------------------------------------------------------------------------// - -TEST(NumberAbstractRationalTests, multiplyTest) { - EXPECT_EQ((Rational(0) * cast(Real(2)))->toString(), "0"); - EXPECT_EQ((Rational(1) * cast(Real(2)))->toString(), "2.0"); -} - -TEST(NumberAbstractRationalTests, divideTest) { - EXPECT_EQ((Rational(0) / cast(Real(2)))->toString(), "0"); - EXPECT_EQ((Rational(1) / cast(Real(2)))->toString(), "0.5"); - - EXPECT_THROW((Rational(0) / cast(Integer(0)))->toString(), UndefinedException); - EXPECT_THROW((Rational(0) / cast(Real(0)))->toString(), UndefinedException); -} - -//-------------------------------------------------------------------------------------// - -TEST(NumberAbstractRealTests, equalsTest) { - const Real a; - const Integer b; - const Rational c; - - EXPECT_NE(a, cast(b)); - EXPECT_NE(cast(b), a); - EXPECT_NE(a, cast(c)); - EXPECT_NE(cast(c), a); -} - -TEST(NumberAbstractRealTests, compareTest) { - Real a; - Integer b; - Rational c; - - EXPECT_GT(a, cast(b)); - EXPECT_LT(cast(b), a); - EXPECT_GE(a, cast(b)); - EXPECT_LE(cast(b), a); - - EXPECT_GT(a, cast(c)); - EXPECT_LT(cast(c), a); - EXPECT_GE(a, cast(c)); - EXPECT_LE(cast(c), a); - - a = 10; - b = 10; - c = 10; - - EXPECT_GT(a, cast(b)); - EXPECT_LT(cast(b), a); - EXPECT_GE(a, cast(b)); - EXPECT_LE(cast(b), a); - - EXPECT_GT(a, cast(c)); - EXPECT_LT(cast(c), a); - EXPECT_GE(a, cast(c)); - EXPECT_LE(cast(c), a); - - a = -10; - b = -10; - c = -10; - - EXPECT_LT(a, cast(b)); - EXPECT_GT(cast(b), a); - EXPECT_LE(a, cast(b)); - EXPECT_GE(cast(b), a); - - EXPECT_LT(a, cast(c)); - EXPECT_GT(cast(c), a); - EXPECT_LE(a, cast(c)); - EXPECT_GE(cast(c), a); -} - -TEST(NumberAbstractRealTests, multiplyTest) { - EXPECT_EQ((Real(2) * cast(Integer(0)))->toString(), "0"); - EXPECT_EQ((Real(2) * cast(Integer(2)))->toString(), "4.0"); -} diff --git a/tests/src/numbers/NumberUtilsTests.cpp b/tests/src/numbers/NumberUtilsTests.cpp deleted file mode 100644 index 3487ff2aa..000000000 --- a/tests/src/numbers/NumberUtilsTests.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/Real.hpp" - -using namespace fintamath; - -TEST(NumberUtilsTests, removeLeadingZeroesTest) { - // TODO: implement -} diff --git a/tests/src/numbers/RationalFunctionsTests.cpp b/tests/src/numbers/RationalFunctionsTests.cpp deleted file mode 100644 index c7eda7cce..000000000 --- a/tests/src/numbers/RationalFunctionsTests.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include - -#include "fintamath/numbers/RationalFunctions.hpp" - -using namespace fintamath; - -TEST(RationalFunctionsTests, floorTest) { - EXPECT_EQ(floor(Rational("-1000.8")).toString(), "-1001"); - EXPECT_EQ(floor(Rational("-1000.1")).toString(), "-1001"); - EXPECT_EQ(floor(Rational("-1000")).toString(), "-1000"); - EXPECT_EQ(floor(Rational("-1.9")).toString(), "-2"); - EXPECT_EQ(floor(Rational("-1.5")).toString(), "-2"); - EXPECT_EQ(floor(Rational("-1.3")).toString(), "-2"); - EXPECT_EQ(floor(Rational("-1")).toString(), "-1"); - EXPECT_EQ(floor(Rational("-0.9")).toString(), "-1"); - EXPECT_EQ(floor(Rational("-0.3")).toString(), "-1"); - EXPECT_EQ(floor(Rational("0")).toString(), "0"); - EXPECT_EQ(floor(Rational("0.3")).toString(), "0"); - EXPECT_EQ(floor(Rational("0.9")).toString(), "0"); - EXPECT_EQ(floor(Rational("1")).toString(), "1"); - EXPECT_EQ(floor(Rational("1.9")).toString(), "1"); - EXPECT_EQ(floor(Rational("1.5")).toString(), "1"); - EXPECT_EQ(floor(Rational("1.3")).toString(), "1"); - EXPECT_EQ(floor(Rational("1000")).toString(), "1000"); - EXPECT_EQ(floor(Rational("1000.1")).toString(), "1000"); - EXPECT_EQ(floor(Rational("1000.8")).toString(), "1000"); -} - -TEST(RationalFunctionsTests, ceilTest) { - EXPECT_EQ(ceil(Rational("-1000.8")).toString(), "-1000"); - EXPECT_EQ(ceil(Rational("-1000.1")).toString(), "-1000"); - EXPECT_EQ(ceil(Rational("-1000")).toString(), "-1000"); - EXPECT_EQ(ceil(Rational("-1.9")).toString(), "-1"); - EXPECT_EQ(ceil(Rational("-1.5")).toString(), "-1"); - EXPECT_EQ(ceil(Rational("-1.3")).toString(), "-1"); - EXPECT_EQ(ceil(Rational("-1")).toString(), "-1"); - EXPECT_EQ(ceil(Rational("-0.9")).toString(), "0"); - EXPECT_EQ(ceil(Rational("-0.3")).toString(), "0"); - EXPECT_EQ(ceil(Rational("0")).toString(), "0"); - EXPECT_EQ(ceil(Rational("0.3")).toString(), "1"); - EXPECT_EQ(ceil(Rational("0.9")).toString(), "1"); - EXPECT_EQ(ceil(Rational("1")).toString(), "1"); - EXPECT_EQ(ceil(Rational("1.9")).toString(), "2"); - EXPECT_EQ(ceil(Rational("1.5")).toString(), "2"); - EXPECT_EQ(ceil(Rational("1.3")).toString(), "2"); - EXPECT_EQ(ceil(Rational("1000")).toString(), "1000"); - EXPECT_EQ(ceil(Rational("1000.1")).toString(), "1001"); - EXPECT_EQ(ceil(Rational("1000.8")).toString(), "1001"); -} - -TEST(RationalFunctionsTests, absTest) { - EXPECT_EQ(abs(Rational(-1, 100)).toString(), "1/100"); - EXPECT_EQ(abs(Rational(1, -100)).toString(), "1/100"); - EXPECT_EQ(abs(Rational(10, 1000)).toString(), "1/100"); - EXPECT_EQ(abs(Rational(0)).toString(), "0"); -} diff --git a/tests/src/numbers/RationalTests.cpp b/tests/src/numbers/RationalTests.cpp deleted file mode 100644 index ee5ded2f4..000000000 --- a/tests/src/numbers/RationalTests.cpp +++ /dev/null @@ -1,529 +0,0 @@ -#include - -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/Rational.hpp" - -using namespace fintamath; - -TEST(RationalTests, constructorTest) { - EXPECT_EQ(Rational(), 0); -} - -TEST(RationalTests, stringConstructorTest) { - EXPECT_EQ(Rational("0"), 0); - EXPECT_EQ(Rational("2"), 2); - EXPECT_EQ(Rational("-93"), -93); - EXPECT_EQ(Rational("-9.3").toString(), "-93/10"); - EXPECT_EQ(Rational("0989929039237832000.9302930929333").toString(), "9899290392378320009302930929333/10000000000000"); - EXPECT_EQ(Rational(".1").toString(), "1/10"); - EXPECT_EQ(Rational("1.").toString(), "1"); - - EXPECT_THROW(Rational("--10"), InvalidInputException); - EXPECT_THROW(Rational("test"), InvalidInputException); - EXPECT_THROW(Rational(""), InvalidInputException); - EXPECT_THROW(Rational("+"), InvalidInputException); - EXPECT_THROW(Rational("939849.0-0023"), InvalidInputException); - EXPECT_THROW(Rational("a"), InvalidInputException); - EXPECT_THROW(Rational("a.1"), InvalidInputException); - EXPECT_THROW(Rational("1.a"), InvalidInputException); - EXPECT_THROW(Rational("1a.1"), InvalidInputException); - EXPECT_THROW(Rational("1.1a"), InvalidInputException); - EXPECT_THROW(Rational(".1."), InvalidInputException); - EXPECT_THROW(Rational("."), InvalidInputException); - EXPECT_THROW(Rational("--10.-1"), InvalidInputException); - EXPECT_THROW(Rational("10.-1"), InvalidInputException); - EXPECT_THROW(Rational("1-0.1"), InvalidInputException); - EXPECT_THROW(Rational("10-.1"), InvalidInputException); - EXPECT_THROW(Rational("10.--1"), InvalidInputException); - EXPECT_THROW(Rational("1.10.1"), InvalidInputException); -} - -TEST(RationalTests, integerIntegerConstructorTest) { - EXPECT_EQ(Rational(-380, -608).toString(), "5/8"); - EXPECT_EQ(Rational(2849300, 18493).toString(), "2849300/18493"); - EXPECT_EQ(Rational(2849300, -1893).toString(), "-2849300/1893"); - - EXPECT_THROW(Rational(23070, 0), UndefinedBinaryOperatorException); -} - -TEST(RationalTests, integerConstructorTest) { - EXPECT_EQ(Rational(Integer("122432964238764283746823")), Integer("122432964238764283746823")); -} - -TEST(RationalTests, integerAssignmentOperatorTest) { - Rational b; - EXPECT_EQ(b = Integer("39743491820370928039"), Rational("39743491820370928039")); -} - -TEST(RationalTests, intConstructorTest) { - EXPECT_EQ(Rational(2), 2); -} - -TEST(RationalTests, intAssignmentOperatorTest) { - Rational a; - EXPECT_EQ(a = 2, 2); -} - -TEST(RationalTests, plusAssignmentOperatorTest) { - EXPECT_EQ(Rational(2, 3) += Rational(5, 2), Rational(19, 6)); - EXPECT_EQ(Rational(-738, 10) += Rational(5, 2), Rational(-713, 10)); - EXPECT_EQ(Rational(738, 10) += Rational(5, 2), Rational(763, 10)); - EXPECT_EQ(Rational(-738, 10) += Rational(-5, 2), Rational(-763, 10)); -} - -TEST(RationalTests, integerPlusAssignmentOperatorTest) { - EXPECT_EQ(Rational(-10) += Integer(5), -5); - EXPECT_EQ(Rational(2, 3) += Integer(-5), Rational(-13, 3)); -} - -TEST(RationalTests, intPlusAssignmentOperatorTest) { - EXPECT_EQ(Rational(-10) += 5, -5); - EXPECT_EQ(Rational(2, 3) += -5, Rational(-13, 3)); -} - -TEST(RationalTests, plusOperatorTest) { - EXPECT_EQ(Rational(170, 15) + Rational(-5, 2), Rational(53, 6)); - EXPECT_EQ(Rational(17, 19) + Rational(53, 5), Rational(1092, 95)); - EXPECT_EQ(Rational(170, 12) + Rational(2, 5), Rational(437, 30)); -} - -TEST(RationalTests, integerPlusOperatorTest) { - EXPECT_EQ(Rational(170) + Integer(-5), 165); - EXPECT_EQ(Rational(17) + Integer(53), 70); - EXPECT_EQ(Rational(170, 12) + Integer(2), Rational(194, 12)); -} - -TEST(RationalTests, intPlusOperatorTest) { - EXPECT_EQ(Rational(170) + -5, 165); - EXPECT_EQ(Rational(17) + 53, 70); - EXPECT_EQ(Rational(170, 12) + 2, Rational(194, 12)); -} - -TEST(RationalTests, integerFriendPlusOperatorTest) { - EXPECT_EQ(Integer(2) + Rational(-18), -16); - EXPECT_EQ(Integer(4938493849) + Rational(1009), 4938494858); -} - -TEST(RationalTests, intFriendPlusOperatorTest) { - EXPECT_EQ(2 + Rational(-18), -16); - EXPECT_EQ(4938493849 + Rational(1009), 4938494858); -} - -TEST(RationalTests, minusAssignmentOperatorTest) { - EXPECT_EQ(Rational(2, 3) -= Rational(5, 2), Rational(-11, 6)); - EXPECT_EQ(Rational(-738, 10) -= Rational(5, 2), Rational(-763, 10)); - EXPECT_EQ(Rational(738, 10) -= Rational(5, 2), Rational(713, 10)); - EXPECT_EQ(Rational(-738, 10) -= Rational(-5, 2), Rational(-713, 10)); -} - -TEST(RationalTests, integerMinusAssignmentOperatorTest) { - EXPECT_EQ(Rational(-738, -10) -= Integer(-5), Rational(394, 5)); - EXPECT_EQ(Rational(-738, 10) -= Integer(5), Rational(-394, 5)); -} - -TEST(RationalTests, intMinusAssignmentOperatorTest) { - EXPECT_EQ(Rational(-738, -10) -= -5, Rational(394, 5)); - EXPECT_EQ(Rational(-738, 10) -= 5, Rational(-394, 5)); -} - -TEST(RationalTests, minusOperatorTest) { - EXPECT_EQ(Rational(170, 15) - Rational(-5, 2), Rational(83, 6)); - EXPECT_EQ(Rational(17, 19) - Rational(53, 5), Rational(-922, 95)); - EXPECT_EQ(Rational(170, 12) - Rational(2, 5), Rational(413, 30)); -} - -TEST(RationalTests, integerMinusOperatorTest) { - EXPECT_EQ(Rational(170) - Integer(5), 165); - EXPECT_EQ(Rational(17) - Integer(53), -36); - EXPECT_EQ(Rational(170, 12) - Integer(-2), Rational(194, 12)); -} - -TEST(RationalTests, intMinusOperatorTest) { - EXPECT_EQ(Rational(170) - 5, 165); - EXPECT_EQ(Rational(17) - 53, -36); - EXPECT_EQ(Rational(170, 12) - -2, Rational(194, 12)); -} - -TEST(RationalTests, integerFriendMinusOperatorTest) { - EXPECT_EQ(Integer(2) - Rational(-18), 20); - EXPECT_EQ(Integer(4938493849) - Rational(1009), 4938492840); -} - -TEST(RationalTests, intFriendMinusOperatorTest) { - EXPECT_EQ(2 - Rational(-18), 20); - EXPECT_EQ(4938493849 - Rational(1009), 4938492840); -} - -TEST(RationalTests, multiplyAssignmentOperatorTest) { - EXPECT_EQ(Rational(2, 3) *= Rational(5, 2), Rational(5, 3)); - EXPECT_EQ(Rational(-738, 10) *= Rational(5, 2), Rational(-369, 2)); - EXPECT_EQ(Rational(738, 10) *= Rational(5, 2), Rational(369, 2)); - EXPECT_EQ(Rational(-738, 10) *= Rational(-5, 2), Rational(369, 2)); -} - -TEST(RationalTests, integerMultiplyAssignmentOperatorTest) { - EXPECT_EQ(Rational(2, 3) *= Integer(-5), Rational(-10, 3)); - EXPECT_EQ(Rational(738, -10) *= Integer(5894), Rational(-4349772, 10)); - EXPECT_EQ(Rational(-738, -10) *= Integer(10), 738); -} - -TEST(RationalTests, intMultiplyAssignmentOperatorTest) { - EXPECT_EQ(Rational(2, 3) *= -5, Rational(-10, 3)); - EXPECT_EQ(Rational(738, -10) *= 5894, Rational(-4349772, 10)); - EXPECT_EQ(Rational(-738, -10) *= 10, 738); -} - -TEST(RationalTests, multiplyOperatorTest) { - EXPECT_EQ(Rational(170, 15) * Rational(-5, 2), Rational(-85, 3)); - EXPECT_EQ(Rational(17, 19) * Rational(53, 5), Rational(901, 95)); - EXPECT_EQ(Rational(170, 12) * Rational(2, 5), Rational(17, 3)); -} - -TEST(RationalTests, integerMultiplyOperatorTest) { - EXPECT_EQ(Rational(2, 3) * Integer(-5), Rational(-10, 3)); - EXPECT_EQ(Rational(738, -10) * Integer(5894), Rational(-4349772, 10)); - EXPECT_EQ(Rational(-738, -10) * Integer(10), 738); -} - -TEST(RationalTests, intMultiplyOperatorTest) { - EXPECT_EQ(Rational(2, 3) * -5, Rational(-10, 3)); - EXPECT_EQ(Rational(738, -10) * 5894, Rational(-4349772, 10)); - EXPECT_EQ(Rational(-738, -10) * 10, 738); -} - -TEST(RationalTests, integerFriendMultiplyOperatorTest) { - EXPECT_EQ(Integer(-5) * Rational(2, 3), Rational(-10, 3)); - EXPECT_EQ(Integer(589398724) * Rational(1, 8372738), Rational(589398724, 8372738)); - EXPECT_EQ(Integer(10) * Rational(-738, -10), 738); -} - -TEST(RationalTests, intFriendMultiplyOperatorTest) { - EXPECT_EQ(-5 * Rational(2, 3), Rational(-10, 3)); - EXPECT_EQ(589398724 * Rational(1, 8372738), Rational(589398724, 8372738)); - EXPECT_EQ(10 * Rational(-738, -10), 738); -} - -TEST(RationalTests, divideAssignmentOperatorTest) { - EXPECT_EQ(Rational(2, 3) /= Rational(5, 2), Rational(4, 15)); - EXPECT_EQ(Rational(-738, 10) /= Rational(5, 2), Rational(-738, 25)); - EXPECT_EQ(Rational(738, 10) /= Rational(5, 2), Rational(738, 25)); - EXPECT_EQ(Rational(-738, 10) /= Rational(-5, 2), Rational(738, 25)); - - EXPECT_THROW(Rational(-738, -10) /= Rational("0"), UndefinedBinaryOperatorException); -} - -TEST(RationalTests, integerDivideAssignmentOperatorTest) { - EXPECT_EQ(Rational(2, 3) /= Integer(-2), Rational(1, -3)); - EXPECT_EQ(Rational(738, -10) /= Integer(5894), Rational(-738, 58940)); - EXPECT_EQ(Rational(-738, -10) /= Integer(10), Rational(369, 50)); -} - -TEST(RationalTests, intDivideAssignmentOperatorTest) { - EXPECT_EQ(Rational(2, 3) /= -2, Rational(1, -3)); - EXPECT_EQ(Rational(738, -10) /= 5894, Rational(-738, 58940)); - EXPECT_EQ(Rational(-738, -10) /= 10, Rational(369, 50)); -} - -TEST(RationalTests, divideOperatorTest) { - EXPECT_EQ(Rational(170, 15) / Rational(-5, 2), Rational(-68, 15)); - EXPECT_EQ(Rational(17, 19) / Rational(53, 5), Rational(85, 1007)); - EXPECT_EQ(Rational(170, 12) / Rational(2, 5), Rational(425, 12)); -} - -TEST(RationalTests, integerDivideOperatorTest) { - EXPECT_EQ(Rational(2, 3) / Integer(-5), Rational(-2, 15)); - EXPECT_EQ(Rational(738, -10) / Integer(5894), Rational(738, -58940)); -} - -TEST(RationalTests, intDivideOperatorTest) { - EXPECT_EQ(Rational(2, 3) / -5, Rational(-2, 15)); - EXPECT_EQ(Rational(738, -10) / 5894, Rational(738, -58940)); -} - -TEST(RationalTests, integerFriendDivideOperatorTest) { - EXPECT_EQ(Integer(-5) / Rational(2, 3), Rational(-15, 2)); - EXPECT_EQ(Integer(589398724) / Rational(8372738), Rational(589398724, 8372738)); - EXPECT_EQ(Integer(10) / Rational(-10, -738), 738); -} - -TEST(RationalTests, intFriendDivideOperatorTest) { - EXPECT_EQ(-5 / Rational(2, 3), Rational(-15, 2)); - EXPECT_EQ(589398724 / Rational(8372738), Rational(589398724, 8372738)); - EXPECT_EQ(10 / Rational(-10, -738), 738); -} - -TEST(RationalTests, unaryPlusOperatorTest) { - EXPECT_EQ(+Rational(-5), -5); -} - -TEST(RationalTests, unaryMinusOperatorTest) { - EXPECT_EQ(-Rational(5), -5); -} - -TEST(RationalTests, equalOperatorTest) { - EXPECT_TRUE(Rational(1, 2) == Rational(1, 2)); - EXPECT_TRUE(Rational(5, 10) == Rational(1, 2)); - EXPECT_TRUE(Rational(5, -10) == Rational(-5, 10)); - - EXPECT_FALSE(Rational(1, 2) == Rational(1, 3)); - EXPECT_FALSE(Rational(3, 2) == Rational(1, 3)); - EXPECT_FALSE(Rational(55, 10) == Rational(-1, 10)); -} - -TEST(RationalTests, integerEqualOperatorTest) { - EXPECT_TRUE(Rational(500) == Integer(500)); - EXPECT_TRUE(Rational(50, -10) == Integer(-5)); -} - -TEST(RationalTests, intEqualOperatorTest) { - EXPECT_TRUE(Rational(500) == 500); - EXPECT_TRUE(Rational(50, -10) == -5); -} - -TEST(RationalTests, integerFriendEqualOperatorTest) { - EXPECT_TRUE(Integer(500) == Rational(500)); - EXPECT_TRUE(Integer(-5) == Rational(50, -10)); -} - -TEST(RationalTests, intFriendEqualOperatorTest) { - EXPECT_TRUE(500 == Rational(500)); - EXPECT_TRUE(-5 == Rational(50, -10)); -} - -TEST(RationalTests, notEqualOperatorTest) { - EXPECT_TRUE(Rational(55, 10) != Rational(-1, 10)); - - EXPECT_FALSE(Rational(5, 10) != Rational(1, 2)); - EXPECT_FALSE(Rational(5, -10) != Rational(-5, 10)); -} - -TEST(RationalTests, integerNotEqualOperatorTest) { - EXPECT_TRUE(Rational(50, 10) != Integer(-5)); - - EXPECT_FALSE(Rational(500) != Integer(500)); -} - -TEST(RationalTests, intNotEqualOperatorTest) { - EXPECT_TRUE(Rational(50, 10) != -5); - - EXPECT_FALSE(Rational(500) != 500); -} - -TEST(RationalTests, integerFriendNotEqualOperatorTest) { - EXPECT_TRUE(Integer(50) != Rational(3920)); - - EXPECT_FALSE(Integer(500) != Rational(500)); - EXPECT_FALSE(Integer(-5) != Rational(50, -10)); -} - -TEST(RationalTests, intFriendNotEqualOperatorTest) { - EXPECT_TRUE(50 != Rational(3920)); - - EXPECT_FALSE(500 != Rational(500)); - EXPECT_FALSE(-5 != Rational(50, -10)); -} - -TEST(RationalTests, lessOperatorTest) { - EXPECT_TRUE(Rational(5, -10) < Rational(50, 10)); - - EXPECT_FALSE(Rational(5, 10) < Rational(1, 2)); - EXPECT_FALSE(Rational(5, -10) < Rational(-50, 10)); - EXPECT_FALSE(Rational(55, 10) < Rational(1, 10)); -} - -TEST(RationalTests, integerLessOperatorTest) { - EXPECT_TRUE(Rational(500) < Integer(3283)); - - EXPECT_FALSE(Rational(50, -10) < Integer(-5)); -} - -TEST(RationalTests, intLessOperatorTest) { - EXPECT_TRUE(Rational(500) < 3283); - - EXPECT_FALSE(Rational(50, -10) < -5); -} - -TEST(RationalTests, integerFriendLessOperatorTest) { - EXPECT_TRUE(Integer(-5) < Rational(50, 10)); - EXPECT_TRUE(Integer(7387) < Rational(3983920)); - - EXPECT_FALSE(Integer(500) < Rational(500)); -} - -TEST(RationalTests, intFriendLessOperatorTest) { - EXPECT_TRUE(-5 < Rational(50, 10)); - EXPECT_TRUE(7387 < Rational(3983920)); - - EXPECT_FALSE(500 < Rational(500)); -} - -TEST(RationalTests, moreOperatorTest) { - EXPECT_TRUE(Rational(5, -10) > Rational(-50, 10)); - EXPECT_TRUE(Rational(55, 10) > Rational(1, 10)); - - EXPECT_FALSE(Rational(5, 10) > Rational(1, 2)); - EXPECT_FALSE(Rational(5, -10) > Rational(50, 10)); -} - -TEST(RationalTests, integerMoreOperatorTest) { - EXPECT_FALSE(Rational(500) > Integer(3283)); - EXPECT_FALSE(Rational(50, -10) > Integer(-5)); -} - -TEST(RationalTests, intMoreOperatorTest) { - EXPECT_FALSE(Rational(500) > 3283); - EXPECT_FALSE(Rational(50, -10) > -5); -} - -TEST(RationalTests, integerFriendMoreOperatorTest) { - EXPECT_TRUE(Integer(738657) > Rational(320)); - - EXPECT_FALSE(Integer(500) > Rational(500)); - EXPECT_FALSE(Integer(-5) > Rational(50, 10)); -} - -TEST(RationalTests, intFriendMoreOperatorTest) { - EXPECT_TRUE(738657 > Rational(320)); - - EXPECT_FALSE(500 > Rational(500)); - EXPECT_FALSE(-5 > Rational(50, 10)); -} - -TEST(RationalTests, lessEqualOperatorTest) { - EXPECT_TRUE(Rational(5, 10) <= Rational(1, 2)); - EXPECT_TRUE(Rational(5, -10) <= Rational(50, 10)); - - EXPECT_FALSE(Rational(5, -10) <= Rational(-50, 10)); - EXPECT_FALSE(Rational(55, 10) <= Rational(1, 10)); -} - -TEST(RationalTests, integerLessEqualOperatorTest) { - EXPECT_TRUE(Rational(500) <= Integer(3283)); - EXPECT_TRUE(Rational(50, -10) <= Integer(-5)); -} - -TEST(RationalTests, intLessEqualOperatorTest) { - EXPECT_TRUE(Rational(500) <= 3283); - EXPECT_TRUE(Rational(50, -10) <= -5); -} - -TEST(RationalTests, integerFriendLessEqualOperatorTest) { - EXPECT_TRUE(Integer(500) <= Rational(500)); - EXPECT_TRUE(Integer(-5) <= Rational(50, 10)); - - EXPECT_FALSE(Integer(73687) <= Rational(30)); -} - -TEST(RationalTests, intFriendLessEqualOperatorTest) { - EXPECT_TRUE(500 <= Rational(500)); - EXPECT_TRUE(-5 <= Rational(50, 10)); - - EXPECT_FALSE(73687 <= Rational(30)); -} - -TEST(RationalTests, moreEqualOperatorTest) { - EXPECT_TRUE(Rational(5, 10) >= Rational(1, 2)); - EXPECT_TRUE(Rational(5, -10) >= Rational(-50, 10)); - EXPECT_TRUE(Rational(55, 10) >= Rational(1, 10)); - - EXPECT_FALSE(Rational(5, -10) >= Rational(50, 10)); -} - -TEST(RationalTests, integerMoreEqualOperatorTest) { - EXPECT_TRUE(Rational(50, -10) >= Integer(-5)); - - EXPECT_FALSE(Rational(500) >= Integer(3283)); -} - -TEST(RationalTests, intMoreEqualOperatorTest) { - EXPECT_TRUE(Rational(50, -10) >= -5); - - EXPECT_FALSE(Rational(500) >= 3283); -} - -TEST(RationalTests, integerFriendMoreEqualOperatorTest) { - EXPECT_TRUE(Integer(500) >= Rational(500)); - EXPECT_TRUE(Integer(738657) >= Rational(320)); - - EXPECT_FALSE(Integer(-5) >= Rational(50, 10)); -} - -TEST(RationalTests, intFriendMoreEqualOperatorTest) { - EXPECT_TRUE(500 >= Rational(500)); - EXPECT_TRUE(738657 >= Rational(320)); - - EXPECT_FALSE(-5 >= Rational(50, 10)); -} - -TEST(RationalTests, numeratorTest) { - EXPECT_EQ(Rational(5, 2).numerator(), 5); - EXPECT_EQ(Rational(55).numerator(), 55); - EXPECT_EQ(Rational(-10, 100).numerator(), -1); -} - -TEST(RationalTests, denominatorTest) { - EXPECT_EQ(Rational(5, 2).denominator(), 2); - EXPECT_EQ(Rational(55).denominator(), 1); - EXPECT_EQ(Rational(-10, 100).denominator(), 10); -} - -TEST(RationalTests, toStringTest) { - EXPECT_EQ(Rational(5, 2).toString(), "5/2"); - EXPECT_EQ(Rational(55, -10).toString(), "-11/2"); -} - -TEST(RationalTests, simplifyTest) { - EXPECT_TRUE(is(Rational(5, 2).toMinimalObject())); - EXPECT_TRUE(is(Rational(55, 5).toMinimalObject())); - EXPECT_TRUE(is(Rational(-5, 2).toMinimalObject())); - EXPECT_TRUE(is(Rational(-55, 5).toMinimalObject())); - - EXPECT_EQ(Rational(5, 2).toMinimalObject()->toString(), "5/2"); - EXPECT_EQ(Rational(55, 5).toMinimalObject()->toString(), "11"); - EXPECT_EQ(Rational(-5, 2).toMinimalObject()->toString(), "-5/2"); - EXPECT_EQ(Rational(-55, 5).toMinimalObject()->toString(), "-11"); -} - -TEST(RationalTests, signTest) { - EXPECT_EQ(Rational(-2).sign(), -1); - EXPECT_EQ(Rational(-1).sign(), -1); - EXPECT_EQ(Rational(0).sign(), 0); - EXPECT_EQ(Rational(1).sign(), 1); - EXPECT_EQ(Rational(2).sign(), 1); -} - -TEST(RationalTests, isPreciseTest) { - EXPECT_TRUE(Rational(1, 2).isPrecise()); -} - -TEST(RationalTests, isComplexTest) { - EXPECT_FALSE(Rational(1, 2).isComplex()); -} - -TEST(RationalTests, getClassTest) { - EXPECT_EQ(Rational().getClass(), MathObjectClass("Rational")); - EXPECT_EQ(Rational().getClass().getParent(), INumber::getClassStatic()); -} - -TEST(RationalTests, hashTest) { - constexpr std::hash hasher; - - EXPECT_EQ(hasher(Rational(0)), hasher(Rational(0))); - EXPECT_EQ(hasher(Rational(12)), hasher(Rational(12))); - EXPECT_EQ(hasher(Rational(-12)), hasher(Rational(-12))); - EXPECT_EQ(hasher(Rational(3, 2)), hasher(Rational(3, 2))); - EXPECT_EQ(hasher(Rational(-3, 2)), hasher(Rational(-3, 2))); - EXPECT_EQ(hasher(Rational(Integer("452734865298734659873246238756987435"), Integer("39842732658275642342352642634234234"))), hasher(Rational(Integer("452734865298734659873246238756987435"), Integer("39842732658275642342352642634234234")))); - EXPECT_EQ(hasher(Rational(-Integer("452734865298734659873246238756987435"), Integer("39842732658275642342352642634234234"))), hasher(Rational(-Integer("452734865298734659873246238756987435"), Integer("39842732658275642342352642634234234")))); - - EXPECT_NE(hasher(Rational(0)), hasher(Rational(1))); - EXPECT_NE(hasher(Rational(12)), hasher(Rational(13))); - EXPECT_NE(hasher(Rational(-12)), hasher(Rational(-13))); - EXPECT_NE(hasher(Rational(3, 2)), hasher(Rational(2, 3))); - EXPECT_NE(hasher(Rational(-3, 2)), hasher(Rational(-2, 3))); - EXPECT_NE(hasher(Rational(Integer("39842732658275642342352642634234234"), Integer("452734865298734659873246238756987435"))), Rational(Integer("452734865298734659873246238756987435"), Integer("39842732658275642342352642634234234"))); - EXPECT_NE(hasher(Rational(-Integer("39842732658275642342352642634234234"), Integer("452734865298734659873246238756987435"))), Rational(-Integer("452734865298734659873246238756987435"), Integer("39842732658275642342352642634234234"))); -} diff --git a/tests/src/numbers/RealFunctionsTests.cpp b/tests/src/numbers/RealFunctionsTests.cpp deleted file mode 100644 index cdc4be8d0..000000000 --- a/tests/src/numbers/RealFunctionsTests.cpp +++ /dev/null @@ -1,2132 +0,0 @@ -#include - -#include "fintamath/core/Cache.hpp" -#include "fintamath/numbers/RealFunctions.hpp" - -#include "fintamath/exceptions/UndefinedException.hpp" -#include "fintamath/numbers/IntegerFunctions.hpp" - -using namespace fintamath; - -namespace { - -unsigned precision = 500; - -const Real &getBottom() { - static const Real res = pow(Rational("9.99"), precision); - return res; -} - -const Real &getTop() { - static const Real res = pow(Rational("10.01"), precision); - return res; -} - -const Real &getLogBottom() { - static const Real res = pow(precision - 1, getE()); - return res; -} - -const Real &getLogTop() { - static const Real res = pow(precision + 1, getE()); - return res; -} - -} - -TEST(RealFunctionsTests, floorTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(floor(Real("-1000.8")).toString(), - "-1001"); - EXPECT_EQ(floor(Real("-1000.1")).toString(), - "-1001"); - EXPECT_EQ(floor(Real("-1000")).toString(), - "-1000"); - EXPECT_EQ(floor(Real("-1.9")).toString(), - "-2"); - EXPECT_EQ(floor(Real("-1.5")).toString(), - "-2"); - EXPECT_EQ(floor(Real("-1.3")).toString(), - "-2"); - EXPECT_EQ(floor(Real("-1")).toString(), - "-1"); - EXPECT_EQ(floor(Real("-0.9")).toString(), - "-1"); - EXPECT_EQ(floor(Real("-0.3")).toString(), - "-1"); - EXPECT_EQ(floor(Real("0")).toString(), - "0"); - EXPECT_EQ(floor(Real("0.3")).toString(), - "0"); - EXPECT_EQ(floor(Real("0.9")).toString(), - "0"); - EXPECT_EQ(floor(Real("1")).toString(), - "1"); - EXPECT_EQ(floor(Real("1.9")).toString(), - "1"); - EXPECT_EQ(floor(Real("1.5")).toString(), - "1"); - EXPECT_EQ(floor(Real("1.3")).toString(), - "1"); - EXPECT_EQ(floor(Real("1000")).toString(), - "1000"); - EXPECT_EQ(floor(Real("1000.1")).toString(), - "1000"); - EXPECT_EQ(floor(Real("1000.8")).toString(), - "1000"); - - EXPECT_EQ(floor(getBottom()).toString(), - "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633532"); - EXPECT_EQ(floor(-getBottom()).toString(), - "-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533"); - EXPECT_EQ(floor(1 / getBottom()).toString(), - "0"); - EXPECT_EQ(floor(-1 / getBottom()).toString(), - "-1"); - EXPECT_EQ(floor(1 + 1 / getBottom()).toString(), - "1"); - EXPECT_EQ(floor(1 - 1 / getBottom()).toString(), - "0"); - EXPECT_EQ(floor(-1 + 1 / getBottom()).toString(), - "-1"); - EXPECT_EQ(floor(-1 - 1 / getBottom()).toString(), - "-2"); - - EXPECT_THROW(floor(getTop()), - UndefinedFunctionException); - EXPECT_THROW(floor(-getTop()), - UndefinedFunctionException); - EXPECT_EQ(floor(1 / getTop()).toString(), - "0"); - EXPECT_EQ(floor(-1 / getTop()).toString(), - "-1"); - EXPECT_EQ(floor(1 + 1 / getTop()).toString(), - "1"); - EXPECT_EQ(floor(1 - 1 / getTop()).toString(), - "0"); - EXPECT_EQ(floor(-1 + 1 / getTop()).toString(), - "-1"); - EXPECT_EQ(floor(-1 - 1 / getTop()).toString(), - "-2"); -} - -TEST(RealFunctionsTests, ceilTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(ceil(Real("-1000.8")).toString(), - "-1000"); - EXPECT_EQ(ceil(Real("-1000.1")).toString(), - "-1000"); - EXPECT_EQ(ceil(Real("-1000")).toString(), - "-1000"); - EXPECT_EQ(ceil(Real("-1.9")).toString(), - "-1"); - EXPECT_EQ(ceil(Real("-1.5")).toString(), - "-1"); - EXPECT_EQ(ceil(Real("-1.3")).toString(), - "-1"); - EXPECT_EQ(ceil(Real("-1")).toString(), - "-1"); - EXPECT_EQ(ceil(Real("-0.9")).toString(), - "0"); - EXPECT_EQ(ceil(Real("-0.3")).toString(), - "0"); - EXPECT_EQ(ceil(Real("0")).toString(), - "0"); - EXPECT_EQ(ceil(Real("0.3")).toString(), - "1"); - EXPECT_EQ(ceil(Real("0.9")).toString(), - "1"); - EXPECT_EQ(ceil(Real("1")).toString(), - "1"); - EXPECT_EQ(ceil(Real("1.9")).toString(), - "2"); - EXPECT_EQ(ceil(Real("1.5")).toString(), - "2"); - EXPECT_EQ(ceil(Real("1.3")).toString(), - "2"); - EXPECT_EQ(ceil(Real("1000")).toString(), - "1000"); - EXPECT_EQ(ceil(Real("1000.1")).toString(), - "1001"); - EXPECT_EQ(ceil(Real("1000.8")).toString(), - "1001"); - - EXPECT_EQ(ceil(getBottom()).toString(), - "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533"); - EXPECT_EQ(ceil(-getBottom()).toString(), - "-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633532"); - EXPECT_EQ(ceil(1 / getBottom()).toString(), - "1"); - EXPECT_EQ(ceil(-1 / getBottom()).toString(), - "0"); - EXPECT_EQ(ceil(1 + 1 / getBottom()).toString(), - "2"); - EXPECT_EQ(ceil(1 - 1 / getBottom()).toString(), - "1"); - EXPECT_EQ(ceil(-1 + 1 / getBottom()).toString(), - "0"); - EXPECT_EQ(ceil(-1 - 1 / getBottom()).toString(), - "-1"); - - EXPECT_THROW(ceil(getTop()), - UndefinedFunctionException); - EXPECT_THROW(ceil(-getTop()), - UndefinedFunctionException); - EXPECT_EQ(ceil(1 / getTop()).toString(), - "1"); - EXPECT_EQ(ceil(-1 / getTop()).toString(), - "0"); - EXPECT_EQ(ceil(1 + 1 / getTop()).toString(), - "2"); - EXPECT_EQ(ceil(1 - 1 / getTop()).toString(), - "1"); - EXPECT_EQ(ceil(-1 + 1 / getTop()).toString(), - "0"); - EXPECT_EQ(ceil(-1 - 1 / getTop()).toString(), - "-1"); -} - -TEST(RealFunctionsTests, absTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(abs(Real("0")).toString(), - "0.0"); - EXPECT_EQ(abs(Real("1")).toString(), - "1.0"); - EXPECT_EQ(abs(Real("-1")).toString(), - "1.0"); - EXPECT_EQ(abs(Real("8465132.321651651")).toString(), - "8465132.321651651"); - EXPECT_EQ(abs(Real("-98465136846516354684651.351")).toString(), - "98465136846516354684651.351"); - - EXPECT_EQ(abs(getBottom()).toString(), - "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); - EXPECT_EQ(abs(-getBottom()).toString(), - "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); - EXPECT_EQ(abs(1 / getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(abs(-1 / getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(abs(1 + 1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(abs(1 - 1 / getBottom()).toString(), - "0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998"); - EXPECT_EQ(abs(-1 + 1 / getBottom()).toString(), - "0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998"); - EXPECT_EQ(abs(-1 - 1 / getBottom()).toString(), - "1.0"); - - EXPECT_EQ(abs(getTop()).toString(), - "1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500"); - EXPECT_EQ(abs(-getTop()).toString(), - "1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500"); - EXPECT_EQ(abs(1 / getTop()).toString(), - "6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501"); - EXPECT_EQ(abs(-1 / getTop()).toString(), - "6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501"); - EXPECT_EQ(abs(1 + 1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(abs(1 - 1 / getTop()).toString(), - "0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); - EXPECT_EQ(abs(-1 + 1 / getTop()).toString(), - "0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); - EXPECT_EQ(abs(-1 - 1 / getTop()).toString(), - "1.0"); -} - -TEST(RealFunctionsTests, sqrtTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(sqrt(Real(0)).toString(), - "0.0"); - EXPECT_EQ(sqrt(Real(1)).toString(), - "1.0"); - EXPECT_EQ(sqrt(Real(2)).toString(), - "1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372"); - EXPECT_EQ(sqrt(Real(3)).toString(), - "1.7320508075688772935274463415058723669428052538103806280558069794519330169088000370811461867572485756756261414154067030299699450949989524788116555120943736485280932319023055820679748201010846749232650153123432669033228866506722546689218379712270471316603678615880190499865373798593894676503475065760507566183481296061009476021871903250831458295239598329977898245082887144638329173472241639845878553976679580638183536661108431737808943783161020883055249016700235207111442886959909563657970871684980729"); - EXPECT_EQ(sqrt(Real(4)).toString(), - "2.0"); - EXPECT_EQ(sqrt(Real(144)).toString(), - "12.0"); - EXPECT_EQ(sqrt(Real(13274)).toString(), - "115.21284650593439790572652382777691656117309945220258699979613263506905239760151704907444527831691562590160722956868739995810831106018229199767066691880297989649444558827475898610288233585194686396936463566845788538210419045585889382699974121670227377612938399307044834938222554290753004264359544978929244759855334569257960433493015078664603877200766988106619062028004375821258844691477035970273539205497260395698511065593781421896623229723378998585892590250139253387664052892480355774660010289906899"); - EXPECT_EQ(sqrt(Real("1000000000000000000")).toString(), - "1000000000.0"); - EXPECT_EQ(sqrt(Real("1.44")).toString(), - "1.2"); - EXPECT_EQ(sqrt(Real("44.3556")).toString(), - "6.66"); - EXPECT_EQ(sqrt(Real("23525.32323")).toString(), - "153.3796701978459725492204121512750781434647796772676747984731910025774620380353585873562153282468402449005481841073883419559395475898767906139439557306692737624706612235430876655932097400345746485358772717813443198131631030112210968228863289213224144876095410020617778466774885899344482470787465483347525492641579485905056875560330297592329863862879918845030254813451236241418098342383111584169389597987963419936486843277917396618643781613363643398613256282148482430926660270155657970283248756900848"); - - EXPECT_THROW(sqrt(Real("-0")), - UndefinedFunctionException); - EXPECT_THROW(sqrt(Real(-1)), - UndefinedFunctionException); - EXPECT_THROW(sqrt(Real(-10)), - UndefinedFunctionException); - - EXPECT_EQ(sqrt(getBottom()).toString(), - "7787033741169900729251715815485773693572833921585377451230548885066769607873479007659071982456633322947892066185977166857642583972097125178340595060116728563374256202600009698063524254105227036090331595060371028923930614245952174706617222746879926470.8510897821851530612877059206724864583284715928797081352754008253316368153779308877986149769954082553680155667453706957387521573664658902203158531980680861391512633677953799840216307772389412518628573193107066033055571314455053475570689817047532784603"); - EXPECT_THROW(sqrt(-getBottom()), - UndefinedFunctionException); - EXPECT_EQ(sqrt(1 / getBottom()).toString(), - "1.2841860369925185169195865952383508057123821807667332113965732899333735192964417864608252585218328774917153021280599859509786581786949635487347411625376722695975048418146219841266294120347267333021747448367685684705244150436777244265866727495790653942061720429576784243367046100069815963928689537008542761364333764862880204579607209976819485622074126185896863972614464760124406252414731669354556859013861276802795992857774887556800764918992498834454139271858853705219677109320158415550275924857185617*10^-250"); - EXPECT_THROW(sqrt(-1 / getBottom()), - UndefinedFunctionException); - EXPECT_EQ(sqrt(1 + 1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(sqrt(1 - 1 / getBottom()).toString(), - "0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); - EXPECT_THROW(sqrt(-1 + 1 / getBottom()), - UndefinedFunctionException); - EXPECT_THROW(sqrt(-1 - 1 / getBottom()), - UndefinedFunctionException); - - EXPECT_EQ(sqrt(getTop()).toString(), - "12838650304502567820342847439865633074310503792406078718470723550586214728557638663815746712937333587127496004640597516330302267248830820742443565086264610567153748278274474007832355643130116977702031439768479199109529814956630304548763269465384389756.52053975223085046502607341722170036312711000508017122016275623179708765814713563176019216943962531158532833134883846404994409109602478985370587448336374563571387052781900218402134345188878655222048458591611141484862841724667172384676656109304785616"); - EXPECT_THROW(sqrt(-getTop()), - UndefinedFunctionException); - EXPECT_EQ(sqrt(1 / getTop()).toString(), - "7.7889807439439008591929713981619621881971392435573811385088347637072345211810942977255979201531668508482901835644432798800170069487225436142800834442509986034840508694607108858414951348906886898011055367223021346068786307215243194670694502011075788038186003443520210828144735797247891719537311773034898064286211749687166104322818682124309519595250930225768952588266953614018071794569009012215771558628143915625887558527587041384073595362951663610913990606444790659372759934196101320638736883335585609*10^-251"); - EXPECT_THROW(sqrt(-1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(sqrt(1 + 1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(sqrt(1 - 1 / getTop()).toString(), - "1.0"); - EXPECT_THROW(sqrt(-1 + 1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(sqrt(-1 - 1 / getTop()), - UndefinedFunctionException); -} - -TEST(RealFunctionsTests, powTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(pow(Real("0"), Real("1")).toString(), - "0.0"); - EXPECT_EQ(pow(Real("1"), Real("0")).toString(), - "1.0"); - EXPECT_EQ(pow(Real("1"), Real("1")).toString(), - "1.0"); - EXPECT_EQ(pow(Real("-1"), Real("0")).toString(), - "1.0"); - EXPECT_EQ(pow(Real("-1"), Real("-1")).toString(), - "-1.0"); - EXPECT_EQ(pow(Real("10"), Real("0")).toString(), - "1.0"); - EXPECT_EQ(pow(Real("-10"), Real("3")).toString(), - "-1000.0"); - EXPECT_EQ(pow(Real("1"), Real("25")).toString(), - "1.0"); - EXPECT_EQ(pow(Real("2.2"), Real("5")).toString(), - "51.53632"); - EXPECT_EQ(pow(Real("10"), Real("10000")).toString(), - "1.0*10^10000"); - EXPECT_EQ(pow(Real("20"), Real("10000")).toString(), - "1.9950631168807583848837421626835850838234968318861924548520089498529438830221946631919961684036194597899331129423209124271556491349413781117593785932096323957855730046793794526765246551266059895520550086918193311542508608460618104685509074866089624888090489894838009253941633257850621568309473902556912388065225096643874441046759871626985453222868538161694315775629640762836880760732228535091641476183956381458969463899410840960536267821064621427333394036525565649530603142680234969400335934316651459*10^13010"); - EXPECT_EQ(pow(Real("10"), Real("-10000")).toString(), - "1.0*10^-10000"); - EXPECT_EQ(pow(Real("-10"), Real("-3")).toString(), - "-0.001"); - EXPECT_EQ(pow(Real("-1"), Real("-25")).toString(), - "-1.0"); - EXPECT_EQ(pow(Real("-2.2"), Real("-5")).toString(), - "-0.019403791345598599201495178545926445660070412478034908196782385703907457886011263512800293074864483921242339383176757673035249703510068239253404201153671818243910314124097335626602753165146444294043501747893524411521816070685683417054225059142756021384530366157304207983806371894617233050400183792711625509931636562331187015293292186946991946650439922757387411441096298687993244376005116391702007438637450248678989885191647366362208244593327579462406318495383449963055181277980267120353180048556047463"); - EXPECT_EQ(pow(Real("-10"), Real("-10000")).toString(), - "1.0*10^-10000"); - EXPECT_EQ(pow(Real("-20"), Real("-10000")).toString(), - "5.0123727492064520092975559337429777493215677813384258394214290422792395309507840401891106962484224133615218492862058372081327443176891273016482168954795781185874209111160612289384877840210668133773552608102495789572162971239408991402272898479042193487906171309477254859220910820260373325729016674503082447394244693204052866594230899522151692248580978679514873159608242138078045415083878886701652303992237313103864199817534633842287720605482756450323537116934243653732537194326201888943493999035280474*10^-13011"); - - EXPECT_EQ(pow(Real("10"), 1 / Real("3")).toString(), - "2.1544346900318837217592935665193504952593449421921085824892355063464111066483408001854415035432432761012612204917809204465575051000832749571206753778093319327305836534892638281254969314038783827968633151615752725693778372934970683568763101881668266147059903345049436171293525496169098347413979669736925921971249146750614140234563308859377534574613645942142167294898249398279542094759454708927976303942406819672696899552050824405187389377726818687403613497196972899233926818975913959138450835966645393"); - EXPECT_EQ(pow(Real("1"), 2 / Real("25")).toString(), - "1.0"); - EXPECT_EQ(pow(Real("2.2"), 3 / Real("5")).toString(), - "1.6049208106703467949297944976671869862588600862104906533562863998657540927533321624904764579547362230505387098441046854305877722316266370346896459910074651102193672501375747398518448711167896745429713628564578245699292015721075742499801869083145396809801350266283491791266667942193540839834301508230912488598653668927471360968700369852654261857303896750633092662814608593818224480784698226206380714896093466853924800849562171364280480604383370430342725648335480486646741093642331808843875651011680266"); - EXPECT_EQ(pow(Real("1.61051"), Real("0.2")).toString(), - "1.1"); - EXPECT_EQ(pow(Real("10"), Real("12527") / Real("10000")).toString(), - "17.893693744453038568478697708497956474073628495270698073113162233836287079137705360230072413246614308524145362637351363955006625872119162760602692969734753424142055610408967601060899898572824230558075304078857524854558638123610917041671546495972827640077385810008474194104978036019740502339099007731549045368579937074573859406347658325799189041094332354043976275489363375372191776492600853619273404590371361870976855336367405592931186423576460346681858145852904563107541788720985949166759003737504923"); - EXPECT_EQ(pow(Real("3208912742835798256297875237432984"), Real("2873872") / Real("32864198276498721360325792813562983746832458643")).toString(), - "1.0000000000000000000000000000000000000067466361790784533917899279259257770642939000988278729038268266049673088117026115809762408403688986636865522629582349229597508643227256257231850374836217686719315025745758053622255582922189977830918548005234207224907736735025354706598258554727480106991557453527822132281506686575542683708158238228060057796811236095102568230822757267340795278272226617796718933682252377631231447285112542037382374229043327586830097275116124395396833879278205860383633617016360025"); - EXPECT_EQ(pow(Real("20"), Real("123.123")).toString(), - "15371496698710127538049660207002996251046701240373832293320415676548540249323541328683199199947267490554116434553064075939129183501326770706172585764242164485464.382515100297609740421028072198093722181254540828236428826926831536068839199271795753450337852736384882680205506109908810878550824071221279469619651916696019345196584525823429494097076982849497142377625248218568977811684777567647327971777533839116116665290885441998570014176213283558962536330908764178072262409449011453242722257699813917631"); - EXPECT_EQ(pow(Real("10"), 1 / Real("-10000")).toString(), - "0.99976976799815658635141604638981297541396466984477711459083930684685186989697929041213306336963649014516445226715342205456445791603567419530668529333352385821493766355725683790126843515237328825664519963335505490416683633603244426616970444670188624455993900745976147392132159517393443913064196380170053772066058092785778167974295533857824628460101843381416143605938274800210123785374166454561558791202253353388499943904479146244325732868900825077422806602517570895866818404904976261773431671253269019"); - - EXPECT_THROW(pow(Real("0"), Real("0")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("0"), Real("-0")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("-0"), Real("0")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("-0"), Real("-0")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("0"), Real("-10")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("-10"), Real("1.5")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("-0"), Real("1.5")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("10"), Real("100000000000000000000")), - UndefinedBinaryOperatorException); - - EXPECT_THROW(pow(2, getBottom()), - UndefinedBinaryOperatorException); - EXPECT_EQ(pow(2, -getBottom()).toString(), - "0.0"); - EXPECT_EQ(pow(2, 1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(pow(2, -1 / getBottom()).toString(), - "0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); - EXPECT_EQ(pow(2, 1 + 1 / getBottom()).toString(), - "2.0"); - EXPECT_EQ(pow(2, 1 - 1 / getBottom()).toString(), - "2.0"); - EXPECT_EQ(pow(2, -1 + 1 / getBottom()).toString(), - "0.50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"); - EXPECT_EQ(pow(2, -1 - 1 / getBottom()).toString(), - "0.49999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); - - EXPECT_THROW(pow(2, getTop()), - UndefinedBinaryOperatorException); - EXPECT_EQ(pow(2, -getTop()).toString(), - "0.0"); - EXPECT_EQ(pow(2, 1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(pow(2, -1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(pow(2, 1 + 1 / getTop()).toString(), - "2.0"); - EXPECT_EQ(pow(2, 1 - 1 / getTop()).toString(), - "2.0"); - EXPECT_EQ(pow(2, -1 + 1 / getTop()).toString(), - "0.5"); - EXPECT_EQ(pow(2, -1 - 1 / getTop()).toString(), - "0.5"); -} - -TEST(RealFunctionsTests, expTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(exp(Real("0")).toString(), - "1.0"); - EXPECT_EQ(exp(Real("1")).toString(), - "2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987931"); - EXPECT_EQ(exp(Real("-1")).toString(), - "0.36787944117144232159552377016146086744581113103176783450783680169746149574489980335714727434591964374662732527684399520824697579279012900862665358949409878309219436737733811504863899112514561634498771997868447595793974730254989249545323936620796481051464752061229422308916492656660036507457728370553285373838810680478761195682989345449735073931859921661743300356993720820710227751802158499423378169071566767176233660823037612291562375720947000704050973342567757625252803037688616515709365379954274064"); - EXPECT_EQ(exp(Real("0.5")).toString(), - "1.6487212707001281468486507878141635716537761007101480115750793116406610211942156086327765200563666430028666377563077970046711669752196091598409714524900597969294226590984039147199484646594892448968689053364184657208410666568598000889249812117122873752149721955119716090340911156197998698399606426550917545746263044830751947582587826254399319557126900765453228814761009577397884861814432652082034241701047183385915106301256614755338082520260614009728919590840501489150294406956331137767638009584808933"); - EXPECT_EQ(exp(Real("10")).toString(), - "22026.465794806716516957900645284244366353512618556781074235426355225202818570792575199120968164525895451555501092457836652423291606522895166222480137728972873485577837847275195480610095881417055888657927317236168401192698035170264925041101757502556764762696107543817931960834044404934236682455357614946828619042431465132389556031319229262768101604495197503774167204806526056321203478848798442802530300736913501270054483832852034221081438619616965319660145104983081899378508779549154525301991890605635"); - EXPECT_EQ(exp(Real("-0.5")).toString(), - "0.6065306597126334236037995349911804534419181354871869556828921587350565194137484239986476115079894560264237897940395251765378080855629465333411798229476774247075812465168479412725158988479005552443885718507531384868441993187156845315753208901075976526891171627344906525598579744052145098224995153853317132728425381311889784012562413987629395987670629281648622926075508458525481494580844614877927321357050562862180016899819853574321791741172013015245321858502440442587753042160269949404650924021711362"); - EXPECT_EQ(exp(Real("-10")).toString(), - "4.5399929762484851535591515560550610237918088866564969259071305650999421614302281652525004545947782321708055089686028492945199117244520388837183347709414567560990909217007363970181059501783900762968517787030908824365171548448722293652332416020501168264360305604941570107729975354408079403994232932138270780520042710498960354486166066837009201707573208836344679390514026888603880832944976776162030390901503245487645114316303309520493125377657667740067564548767381252875056905722753776283821712841436637*10^-5"); - - EXPECT_THROW(exp(getBottom()), - UndefinedFunctionException); - EXPECT_EQ(exp(-getBottom()).toString(), - "0.0"); - EXPECT_EQ(exp(1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(exp(-1 / getBottom()).toString(), - "0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998"); - EXPECT_EQ(exp(1 + 1 / getBottom()).toString(), - "2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987932"); - EXPECT_EQ(exp(1 - 1 / getBottom()).toString(), - "2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987931"); - EXPECT_EQ(exp(-1 + 1 / getBottom()).toString(), - "0.36787944117144232159552377016146086744581113103176783450783680169746149574489980335714727434591964374662732527684399520824697579279012900862665358949409878309219436737733811504863899112514561634498771997868447595793974730254989249545323936620796481051464752061229422308916492656660036507457728370553285373838810680478761195682989345449735073931859921661743300356993720820710227751802158499423378169071566767176233660823037612291562375720947000704050973342567757625252803037688616515709365379954274064"); - EXPECT_EQ(exp(-1 - 1 / getBottom()).toString(), - "0.36787944117144232159552377016146086744581113103176783450783680169746149574489980335714727434591964374662732527684399520824697579279012900862665358949409878309219436737733811504863899112514561634498771997868447595793974730254989249545323936620796481051464752061229422308916492656660036507457728370553285373838810680478761195682989345449735073931859921661743300356993720820710227751802158499423378169071566767176233660823037612291562375720947000704050973342567757625252803037688616515709365379954274063"); - - EXPECT_THROW(exp(getTop()), - UndefinedFunctionException); - EXPECT_EQ(exp(-getTop()).toString(), - "0.0"); - EXPECT_EQ(exp(1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(exp(-1 / getTop()).toString(), - "0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); - EXPECT_EQ(exp(1 + 1 / getTop()).toString(), - "2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987931"); - EXPECT_EQ(exp(1 - 1 / getTop()).toString(), - "2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987931"); - EXPECT_EQ(exp(-1 + 1 / getTop()).toString(), - "0.36787944117144232159552377016146086744581113103176783450783680169746149574489980335714727434591964374662732527684399520824697579279012900862665358949409878309219436737733811504863899112514561634498771997868447595793974730254989249545323936620796481051464752061229422308916492656660036507457728370553285373838810680478761195682989345449735073931859921661743300356993720820710227751802158499423378169071566767176233660823037612291562375720947000704050973342567757625252803037688616515709365379954274064"); - EXPECT_EQ(exp(-1 - 1 / getTop()).toString(), - "0.36787944117144232159552377016146086744581113103176783450783680169746149574489980335714727434591964374662732527684399520824697579279012900862665358949409878309219436737733811504863899112514561634498771997868447595793974730254989249545323936620796481051464752061229422308916492656660036507457728370553285373838810680478761195682989345449735073931859921661743300356993720820710227751802158499423378169071566767176233660823037612291562375720947000704050973342567757625252803037688616515709365379954274063"); -} - -TEST(RealFunctionsTests, logTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(log(Real("2"), Real("2")).toString(), - "1.0"); - EXPECT_EQ(log(Real("2"), Real("1")).toString(), - "0.0"); - EXPECT_EQ(log(Real("2"), Real("32")).toString(), - "5.0"); - EXPECT_EQ(log(Real("32"), Real("2")).toString(), - "0.2"); - EXPECT_EQ(log(Real("2"), Real("0.25")).toString(), - "-2.0"); - EXPECT_EQ(log(Real("0.25"), Real("2")).toString(), - "-0.5"); - EXPECT_EQ(log(Real("6.6"), Real("1897.4736")).toString(), - "4.0"); - EXPECT_EQ(log(Real("25625423589"), Real("1")).toString(), - "0.0"); - EXPECT_EQ(log(Real("234"), Real("456")).toString(), - "1.1222974193541929914091049820966032951869292388423209325537371341751861248725024294684039810737754191127025139990642530554677237392120213955638850860455713858838987038771896556260193792802570202807764685294937127092370332053395439112921888063631815226555045250111525592217887826436890820769352432015778884182694477709693745627040317414295717765434267492587111295054311044734933231300297230475501668009960166527523370142599693595381986766847446850611323401985907606701536577492557408647073586015029771"); - EXPECT_EQ(log(Real("123"), Real("3")).toString(), - "0.22829804669507253420091742121566627185908792299090405968939796763433454285159041676588419998482757839371689346209379517730339372034840376022238927088693047570332903372921561266443571597810069961390797964879364638498081426258029876122767504975758494814081188814340960403206499543320426822963504013066560962927311557433263064930185243997692687207514006816563297664993832759900838947365031162508017932846183275954763828289733740568447254640580419264754070732897967792535760921586753187990583142842967943"); - EXPECT_EQ(log(Real("75247"), Real("0.68435")).toString(), - "-0.033778753934460266831123720169941041787759355941411136734454955533886146484127898493184980237813739244448454243420392936502045016674569962209814275727352836919949049415559421679410308159709256959797454498420094107815528460322967551865627348653354984850194104469047553556465014670960743737140450043288149004099600827249690082455702273163639153216810229377163903235783240133675673398267510771264572190077916049497194915157768086200964726532820721368267150719459928030950998912391748956424034001304734526"); - EXPECT_EQ(log(Real("11"), Real("0.00000684")).toString(), - "-4.9596506408100445306058667311608947616694473401420987552975540951574705545668156244555578347027261930172804465709772764580440664073234543077966933164288342955868125420174089966348870945823695705564221333938415208587768655712571156624527831275002399039875389541512605180425872940404498139900307297532732851584897387439882234374306241935267297499115355828711046374777413582523954386270708493063557040368385641048408015177476717560251797888258558661298144676992768810920939335155666218508897241314595805"); - EXPECT_EQ(log(Real("0.2435"), Real("0.00000684")).toString(), - "8.4188022648009447163225799145503253101352002864631415297742615181622921460652203893252135022820887001341319601850770875520110928757753272796499436866770185110234096367992828394100601687613288221555097697261899842957945949684413331136056597578143523418528905203613881861131482071992287714071407638448773005224414092163126495683427152060080881159486144871539822246244096502129174394529727345020839956353246490469480019902233480738616934001479599668640841126968042303450589052841035577354726797101205172"); - - EXPECT_THROW(log(Real("0"), Real("0")), - UndefinedFunctionException); - EXPECT_THROW(log(Real("1"), Real("66")), - UndefinedFunctionException); - EXPECT_THROW(log(Real("-1"), Real("66")), - UndefinedFunctionException); - EXPECT_THROW(log(Real("10"), Real("-10")), - UndefinedFunctionException); - EXPECT_THROW(log(Real("-10"), Real("10")), - UndefinedFunctionException); - - EXPECT_EQ(log(getBottom(), 2).toString(), - "0.00060232170720148787335668247421703824233401793451907250732522916773385188954022906541837983996988431059094169862536414811557500495692329813203780906742857930168615297869764675322448206577626017712119000549151745205989997178535528834383829035005402069701450414530378257833776070969021526094444364816945235600935174058268565904524492686376745284448718663559682349198279109942125716899713858375086069625495195599080433207462875895090264590143184205942381892712807641877394970943778378340993960349468596485"); - EXPECT_THROW(log(-getBottom(), 2), - UndefinedFunctionException); - EXPECT_EQ(log(1 / getBottom(), 2).toString(), - "-0.00060232170720148787335668247421703824233401793451907250732522916773385188954022906541837983996988431059094169862536414811557500495692329813203780906742857930168615297869764675322448206577626017712119000549151745205989997178535528834383829035005402069701450414530378257833776070969021526094444364816945235600935174058268565904524492686376745284448718663559682349198279109942125716899713858375086069625495195599080433207462875895090264590143184205942381892712807641877394970943778378340993960349468596485"); - EXPECT_THROW(log(-1 / getLogBottom(), 2), - UndefinedFunctionException); - EXPECT_EQ(log(1 + 1 / getLogBottom(), 2).toString(), - "14963154.342193243093712422680699151218039448432193587925035209260728038442025299193161011575994641480733267603410795076728690433584657628985768067584936488667559367158689971672050622879383900097405635209428211341951760557078825755420138867544380597591843358031587606341538450740374340818539759287918718630178509911678830554597975722879609294487135551363296720303098811247554495036254205298081533919450324265477298924474830320510074612511552543256262421158570339037070105389548400264147722652605567058"); - EXPECT_EQ(log(1 - 1 / getLogBottom(), 2).toString(), - "-14963153.649046062533766989312806358204380132571285775672422334025760220766251209439677029312401130838446029433818113410281395034922507978017975984060675629138377197348662974614554022611743937520407130897559671111307912059737145360364966233212630661876029704672607678956857740095364811145206406331320973952493609990097452764896860389596820154454690636445526725151914481416015887811174583083122205222815129307965002439358242471444513582333540499948851074193241291292412608104867497408832830908537979595"); - EXPECT_THROW(log(-1 + 1 / getLogBottom(), 2), - UndefinedFunctionException); - EXPECT_THROW(log(-1 - 1 / getLogBottom(), 2), - UndefinedFunctionException); - - EXPECT_EQ(log(getTop(), 2).toString(), - "0.00060179876403741195722267317028855276394958413863600696746297947633334990788320974726870323010323169588434938957603948500307384601018276229818373404501474310740195421987299739513709619111109837324557071587494251284044564219729803312816295558386812381034330050678075348580043519249230961108398858937009744461829681015882625617053962800932198087109777009790513513968156196421213763732007888196867038077809114726287574264983420066015703482789580169600344172129477299815596840195855948016245613690226508255"); - EXPECT_THROW(log(-getTop(), 2), - UndefinedFunctionException); - EXPECT_EQ(log(1 / getTop(), 2).toString(), - "-0.00060179876403741195722267317028855276394958413863600696746297947633334990788320974726870323010323169588434938957603948500307384601018276229818373404501474310740195421987299739513709619111109837324557071587494251284044564219729803312816295558386812381034330050678075348580043519249230961108398858937009744461829681015882625617053962800932198087109777009790513513968156196421213763732007888196867038077809114726287574264983420066015703482789580169600344172129477299815596840195855948016245613690226508255"); - EXPECT_THROW(log(-1 / getLogTop(), 2), - UndefinedFunctionException); - EXPECT_THROW(log(1 + 1 / getLogTop(), 2), - UndefinedFunctionException); - EXPECT_THROW(log(1 - 1 / getLogTop(), 2), - UndefinedFunctionException); - EXPECT_THROW(log(-1 + 1 / getLogTop(), 2), - UndefinedFunctionException); - EXPECT_THROW(log(-1 - 1 / getLogTop(), 2), - UndefinedFunctionException); -} - -TEST(RealFunctionsTests, lnTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(ln(Real("1")).toString(), - "0.0"); - EXPECT_EQ(ln(Real("66")).toString(), - "4.1896547420264255448744209363458315725446975461204218810739420522614615391015403955545337898127855677446872359746665499983090936202844377734407750132034614375855322466924278989591414054061908800439205842378476964717818785535562556221481423253679976493420852339317987961870493593040854711141491246445359358373722644761959819863963576390829124879365541233265787258798046029241557202934580563944417723930344537189078848697331335312087479189786893021895715688916117667659732380841091142872749455090483267"); - - EXPECT_THROW(ln(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(ln(Real("-1")), - UndefinedFunctionException); - - EXPECT_EQ(ln(getBottom()).toString(), - "1150.7922963302310752589242362151479313201731416891692833911699400851637036457415027739371939670841652308917357020983836730332705230349503481680214714976474839209077565316325602764151150216708300128886161589992601482604232651461734619835153032025914096909878125883457082637067939111344489500238615160009909178260268499686021249686533307312007952386375303998821252181168668959796267869490105263893896521620725067223980718367681264027500730584855433248242010154290038201336903273791780223593743126300917"); - EXPECT_THROW(ln(-getBottom()), - UndefinedFunctionException); - EXPECT_EQ(ln(1 / getBottom()).toString(), - "-1150.7922963302310752589242362151479313201731416891692833911699400851637036457415027739371939670841652308917357020983836730332705230349503481680214714976474839209077565316325602764151150216708300128886161589992601482604232651461734619835153032025914096909878125883457082637067939111344489500238615160009909178260268499686021249686533307312007952386375303998821252181168668959796267869490105263893896521620725067223980718367681264027500730584855433248242010154290038201336903273791780223593743126300917"); - EXPECT_THROW(ln(-1 / getBottom()), - UndefinedFunctionException); - EXPECT_EQ(ln(1 + 1 / getLogBottom()).toString(), - "4.6323600272263608359211448156691072758876883168532246396075018549197775864381748298765365178030226248931374034769820083630251670816629519619538771280826564142288757639085979249471768209927217584931411470222413930228246265766896137048119643681987110433036930098119342190809014298077854480927710521960607704530573579776137719257059197071981057875303104096646125993974912722187860475512221757680333935876388355834671077676526614466116968774936860874832197537416426668522106100035121945103848322706376739*10^-8"); - EXPECT_EQ(ln(1 - 1 / getLogBottom()).toString(), - "-4.6323602418139649948376866797514572995752197210491058307576641336724719216383352361062914663674587656808848656687346701431219655465277394329551348639843630422542096702434001605272127288895929327215751563898813796074182163877372714057313772012933040704156169358608742070625510148804860304660664175014151072551726215293399858991624334681638597053383486705746061983545762472894857379243882709348125599832720555810145898279618567784920213785469969120637225339355267781491799812225999918525565812072662816*10^-8"); - EXPECT_THROW(ln(-1 + 1 / getLogBottom()), - UndefinedFunctionException); - EXPECT_THROW(ln(-1 - 1 / getLogBottom()), - UndefinedFunctionException); - - EXPECT_EQ(ln(getTop()).toString(), - "1151.7922966635646085924004268024496095309282755109697640151737838982364673175055998951467299258996052465500220510896818993462124890472738694984769323698716068886745193057012811943430642366646091837561108162687936796823299767705815255181578427768061307290354919840683949388317852313255500361482131430137488582877970196536516803839211139492790968508269095773231100312182466822895779683752382008537434837173083611909767545379191434734806361489542919224380933936036537329432840742844554171617404889632642"); - EXPECT_THROW(ln(-getTop()), - UndefinedFunctionException); - EXPECT_EQ(ln(1 / getTop()).toString(), - "-1151.7922966635646085924004268024496095309282755109697640151737838982364673175055998951467299258996052465500220510896818993462124890472738694984769323698716068886745193057012811943430642366646091837561108162687936796823299767705815255181578427768061307290354919840683949388317852313255500361482131430137488582877970196536516803839211139492790968508269095773231100312182466822895779683752382008537434837173083611909767545379191434734806361489542919224380933936036537329432840742844554171617404889632642"); - EXPECT_THROW(ln(-1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(ln(1 + 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(ln(1 - 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(ln(-1 + 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(ln(-1 - 1 / getLogTop()), - UndefinedFunctionException); -} - -TEST(RealFunctionsTests, lbTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(lb(Real("2")).toString(), - "1.0"); - EXPECT_EQ(lb(Real("3")).toString(), - "1.5849625007211561814537389439478165087598144076924810604557526545410982277943585625222804749180882420909806624750591673437175524410609248221420839506216982994936575922385852344415825363027476853069780516875995544737266834624612364248850047581810676961316404807130823233281262445248670633898014837234235783662478390118977006466312634223363341821270106098049177472541357330110499026268818251703576994712157113638912494135752192998699040767081539505404488360050368231275419147491001732578668989256977448"); - EXPECT_EQ(lb(Real("1024")).toString(), - "10.0"); - - EXPECT_THROW(lb(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(lb(Real("-1")), - UndefinedFunctionException); - - EXPECT_EQ(lb(getBottom()).toString(), - "1660.2423390088468152391910752389223371556027033502350030047043970665552604033557193348632239845183566271017417710501538215097901794377254202764363841871643747071564808438403849686328703846578940097114426960217287346753381210056644885659785581770910105170063280253795447247762538890216319599066790175392754544932873241866224231658503043157397318916028330680138739335892411716116576564640798839083902475693032164084479471776090955137972737315592315237578699070714960186770111882960267580469773996621113"); - EXPECT_THROW(lb(-getBottom()), - UndefinedFunctionException); - EXPECT_EQ(lb(1 / getBottom()).toString(), - "-1660.2423390088468152391910752389223371556027033502350030047043970665552604033557193348632239845183566271017417710501538215097901794377254202764363841871643747071564808438403849686328703846578940097114426960217287346753381210056644885659785581770910105170063280253795447247762538890216319599066790175392754544932873241866224231658503043157397318916028330680138739335892411716116576564640798839083902475693032164084479471776090955137972737315592315237578699070714960186770111882960267580469773996621113"); - EXPECT_THROW(lb(-1 / getBottom()), - UndefinedFunctionException); - EXPECT_EQ(lb(1 + 1 / getLogBottom()).toString(), - "6.6830828388917342891547486506847285272697011778553511348949644332867998614145798830938470048136194213017431224868715797761885633680790132044146091615119170196741798630401321276786841802843498968365743316373147452925462901218524916301183034992001817086023359871860301036108309491023873401867078175761078204601368178509939844185624097243114009597752846308861275905256459124059713686286528167411921428262024218955687308981115116829854695701605260995123094905260651631487252496425326512975747703200977325*10^-8"); - EXPECT_EQ(lb(1 - 1 / getLogBottom()).toString(), - "-6.6830831484762066454675431422618825159987009233331409228534171430721783908516912969136729509928481419301908889301013133376453055787330828035242245174918370788506914927006846997402561569218574136561328101264573366071228147749489667517185452979226874060919022014009523263275164170543945098746986850351969607585674398333075312204333527471490256380337562966263984228239648580231885737336077106126682033590185973637834381756120060255959619721822463124707428302867531505814243457204894530719616210924893046*10^-8"); - EXPECT_THROW(lb(-1 + 1 / getLogBottom()), - UndefinedFunctionException); - EXPECT_THROW(lb(-1 - 1 / getLogBottom()), - UndefinedFunctionException); - - EXPECT_EQ(lb(getTop()).toString(), - "1661.6850345306344141487530796177690746215158836948925002095220520038185509989931038272246710097629299710429990443367317181033697520479130844014839956432996829364738082384471341579821245656450941161111418270425586144696676643091196292534437222731085099151401430686452988712060138169216117489101036905404477911088920929597538663365923888861719817611791774685691023049143284296171501716483628778816866896852353629726107200682703242297950283551340834724294269534579127490555479536375902006763171420106197"); - EXPECT_THROW(lb(-getTop()), - UndefinedFunctionException); - EXPECT_EQ(lb(1 / getTop()).toString(), - "-1661.6850345306344141487530796177690746215158836948925002095220520038185509989931038272246710097629299710429990443367317181033697520479130844014839956432996829364738082384471341579821245656450941161111418270425586144696676643091196292534437222731085099151401430686452988712060138169216117489101036905404477911088920929597538663365923888861719817611791774685691023049143284296171501716483628778816866896852353629726107200682703242297950283551340834724294269534579127490555479536375902006763171420106197"); - EXPECT_THROW(lb(-1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(lb(1 + 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(lb(1 - 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(lb(-1 + 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(lb(-1 - 1 / getLogTop()), - UndefinedFunctionException); -} - -TEST(RealFunctionsTests, lgTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(lg(Real("0.001")).toString(), - "-3.0"); - EXPECT_EQ(lg(Real("1000")).toString(), - "3.0"); - EXPECT_EQ(lg(Real("25")).toString(), - "1.3979400086720376095725222105510139464636202370757829173791450777457836214511509810261454957636276559186310456171380092418104642377329529880006153325906088498709940714916131946763605313767941129976321942036428347656911209362761419072922306009595213783007750749191994733748107570423083053634346546320353476069144129847373649032981457220701061644284621638984199848009038243690805708299360702447477550154183417636180970020056567602790446469998643589641748853427426633159991941589803258308555502090114049"); - - EXPECT_THROW(lg(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(lg(Real("-1")), - UndefinedFunctionException); - - EXPECT_EQ(lg(getBottom()).toString(), - "499.78274411299115434676719965223768779167964136920007055363841585463644188622791943555370510164980964264750094313258593253768816086436746615232975204548281091270192678941451207329501545599209700116287734424296607709230395802024565114215533908757411944516763884090982261616328224420567778290181253387292750617933539643330552558518205798043923795251523923586037612283521406459121448490318126006960906308176149951008770475545170983614291254760922234519816329245038107624609046278865956610110296462324552"); - EXPECT_THROW(lg(-getBottom()), - UndefinedFunctionException); - EXPECT_EQ(lg(1 / getBottom()).toString(), - "-499.78274411299115434676719965223768779167964136920007055363841585463644188622791943555370510164980964264750094313258593253768816086436746615232975204548281091270192678941451207329501545599209700116287734424296607709230395802024565114215533908757411944516763884090982261616328224420567778290181253387292750617933539643330552558518205798043923795251523923586037612283521406459121448490318126006960906308176149951008770475545170983614291254760922234519816329245038107624609046278865956610110296462324552"); - EXPECT_THROW(lg(-1 / getBottom()), - UndefinedFunctionException); - EXPECT_EQ(lg(1 + 1 / getLogBottom()).toString(), - "2.0118083980136059096853434888142725109436709718011389861452655487998101335198937186475792783475983528667713471278999353571427318335463536665832676784887325437368177755415090648923706314921768803261907182208662223893200401867605259641745584319375168426834845475247780539274153193313255028313714813446321763442399999146370680777253992458317214084017722141404310604446853968438354712208344696034596216350581382476247785306793448540127788042183387871859234405690320319579913363050300456144355260913054575*10^-8"); - EXPECT_EQ(lg(1 - 1 / getLogBottom()).toString(), - "-2.0118084912078182807420902078090487438954699922096761156253211468848051193024573881935808149245464415884943909535208439584744424064895057343999409001554072702232573612470198517753848891829489035460711247341029104077303724685445729129086771709504291590342477175777030466488750254387650200689200176200847160261425426622753483111550954791817472467095433096890416721603648181690701011424585813302233944898337824051565095996050613509755257069316927468635539620462707852017840963058700239856708772770957763*10^-8"); - EXPECT_THROW(lg(-1 + 1 / getLogBottom()), - UndefinedFunctionException); - EXPECT_THROW(lg(-1 - 1 / getLogBottom()), - UndefinedFunctionException); - - EXPECT_EQ(lg(getTop()).toString(), - "500.21703873965932033446069388899443301000188758874338645068247369777978188276137722252688424605970600893853927714983535582557236730510225838524295217100484539293318342301289243646059775923458762067839867333175852316509178327044942829214965210822082429417197201185525689704910240757839537066890081621757756380437386048194814809511491445030505791198598921869543591521133770911428148229663487063107650428872664624111572569774068160311266584524855638648630118535214458717640520183965265359385275880778024"); - EXPECT_THROW(lg(-getTop()), - UndefinedFunctionException); - EXPECT_EQ(lg(1 / getTop()).toString(), - "-500.21703873965932033446069388899443301000188758874338645068247369777978188276137722252688424605970600893853927714983535582557236730510225838524295217100484539293318342301289243646059775923458762067839867333175852316509178327044942829214965210822082429417197201185525689704910240757839537066890081621757756380437386048194814809511491445030505791198598921869543591521133770911428148229663487063107650428872664624111572569774068160311266584524855638648630118535214458717640520183965265359385275880778024"); - EXPECT_THROW(lg(-1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(lg(1 + 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(lg(1 - 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(lg(-1 + 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(lg(-1 - 1 / getLogTop()), - UndefinedFunctionException); -} - -TEST(RealFunctionsTests, sinTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(sin(Real("0")).toString(), - "0.0"); - EXPECT_EQ(sin(Real("1")).toString(), - "0.8414709848078965066525023216302989996225630607983710656727517099919104043912396689486397435430526958543490379079206742932591189209918988811934103277292124094807919558267666069999077640119784087827325663474848028702986561570179624553948935729246701270864862810533820305613772182038684496677616742662390133827533979567642555654779639897648243286902756964291206300583036515230312782552898532648513981934521359709559620621721148144417810576010756741366480550089167266058041400780623930703718779562612888"); - EXPECT_EQ(sin(Real("-1")).toString(), - "-0.8414709848078965066525023216302989996225630607983710656727517099919104043912396689486397435430526958543490379079206742932591189209918988811934103277292124094807919558267666069999077640119784087827325663474848028702986561570179624553948935729246701270864862810533820305613772182038684496677616742662390133827533979567642555654779639897648243286902756964291206300583036515230312782552898532648513981934521359709559620621721148144417810576010756741366480550089167266058041400780623930703718779562612888"); - EXPECT_EQ(sin(Real("360")).toString(), - "0.95891572341430650775887594775378440067396475320176419597230510239310187233155216762469333666238341968877803078186966928960032096690227561941454486085366726260909801244212617791982769634387261903781883823531474415994524980397676039997066747095237475703837143800063095336626267981859128776133587943412648564335693073303454697354580361100438284186802625914881351877222107015824075695678302538013095447706197595852901261436701189763894410700471281462208671109751813776339466816838916499612073892989487919"); - - EXPECT_THROW(sin(Real(2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(sin(Real(-2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(sin(Real(getPi())), - UndefinedFunctionException); - EXPECT_THROW(sin(Real(-getPi())), - UndefinedFunctionException); - EXPECT_EQ(sin(Real(getPi() / 2)).toString(), - "1.0"); - EXPECT_EQ(sin(Real(-getPi() / 2)).toString(), - "-1.0"); - EXPECT_EQ(sin(Real(getPi() / 4)).toString(), - "0.70710678118654752440084436210484903928483593768847403658833986899536623923105351942519376716382078636750692311545614851246241802792536860632206074854996791570661133296375279637789997525057639103028573505477998580298513726729843100736425870932044459930477616461524215435716072541988130181399762570399484362669827316590441482031030762917619752737287514387998086491778761016876592850567718730170424942358019344998534950240751527201389515822712391153424646845931079028923155579833435650650780928449361862"); - EXPECT_EQ(sin(Real(-getPi() / 4)).toString(), - "-0.70710678118654752440084436210484903928483593768847403658833986899536623923105351942519376716382078636750692311545614851246241802792536860632206074854996791570661133296375279637789997525057639103028573505477998580298513726729843100736425870932044459930477616461524215435716072541988130181399762570399484362669827316590441482031030762917619752737287514387998086491778761016876592850567718730170424942358019344998534950240751527201389515822712391153424646845931079028923155579833435650650780928449361862"); - - EXPECT_EQ(sin(getBottom()).toString(), - "-0.98346869560902914062693555980250127530853789035666630941964154169814082834152103822955847548032315657788740242220954264252496013611890184217090501217407550546904780398084505101868282009740661708389019834794267475631391890239343293076379703900493697517424359285300058751616840343372688452565598267734289774019091766399087307968730200813762096382013163248558803477576627229107768823780068201793913943622856047279936459202691553762712831927884350588972037520019653237432848995971513618960476402769444879"); - EXPECT_EQ(sin(-getBottom()).toString(), - "0.98346869560902914062693555980250127530853789035666630941964154169814082834152103822955847548032315657788740242220954264252496013611890184217090501217407550546904780398084505101868282009740661708389019834794267475631391890239343293076379703900493697517424359285300058751616840343372688452565598267734289774019091766399087307968730200813762096382013163248558803477576627229107768823780068201793913943622856047279936459202691553762712831927884350588972037520019653237432848995971513618960476402769444879"); - EXPECT_EQ(sin(1 / getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(sin(-1 / getBottom()).toString(), - "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(sin(1 + 1 / getBottom()).toString(), - "0.84147098480789650665250232163029899962256306079837106567275170999191040439123966894863974354305269585434903790792067429325911892099189888119341032772921240948079195582676660699990776401197840878273256634748480287029865615701796245539489357292467012708648628105338203056137721820386844966776167426623901338275339795676425556547796398976482432869027569642912063005830365152303127825528985326485139819345213597095596206217211481444178105760107567413664805500891672660580414007806239307037187795626128881"); - EXPECT_EQ(sin(1 - 1 / getBottom()).toString(), - "0.8414709848078965066525023216302989996225630607983710656727517099919104043912396689486397435430526958543490379079206742932591189209918988811934103277292124094807919558267666069999077640119784087827325663474848028702986561570179624553948935729246701270864862810533820305613772182038684496677616742662390133827533979567642555654779639897648243286902756964291206300583036515230312782552898532648513981934521359709559620621721148144417810576010756741366480550089167266058041400780623930703718779562612888"); - EXPECT_EQ(sin(-1 + 1 / getBottom()).toString(), - "-0.8414709848078965066525023216302989996225630607983710656727517099919104043912396689486397435430526958543490379079206742932591189209918988811934103277292124094807919558267666069999077640119784087827325663474848028702986561570179624553948935729246701270864862810533820305613772182038684496677616742662390133827533979567642555654779639897648243286902756964291206300583036515230312782552898532648513981934521359709559620621721148144417810576010756741366480550089167266058041400780623930703718779562612888"); - EXPECT_EQ(sin(-1 - 1 / getBottom()).toString(), - "-0.84147098480789650665250232163029899962256306079837106567275170999191040439123966894863974354305269585434903790792067429325911892099189888119341032772921240948079195582676660699990776401197840878273256634748480287029865615701796245539489357292467012708648628105338203056137721820386844966776167426623901338275339795676425556547796398976482432869027569642912063005830365152303127825528985326485139819345213597095596206217211481444178105760107567413664805500891672660580414007806239307037187795626128881"); - - EXPECT_THROW(sin(getTop()), - UndefinedFunctionException); - EXPECT_THROW(sin(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(sin(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(sin(-1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(sin(1 + 1 / getTop()).toString(), - "0.84147098480789650665250232163029899962256306079837106567275170999191040439123966894863974354305269585434903790792067429325911892099189888119341032772921240948079195582676660699990776401197840878273256634748480287029865615701796245539489357292467012708648628105338203056137721820386844966776167426623901338275339795676425556547796398976482432869027569642912063005830365152303127825528985326485139819345213597095596206217211481444178105760107567413664805500891672660580414007806239307037187795626128881"); - EXPECT_EQ(sin(1 - 1 / getTop()).toString(), - "0.8414709848078965066525023216302989996225630607983710656727517099919104043912396689486397435430526958543490379079206742932591189209918988811934103277292124094807919558267666069999077640119784087827325663474848028702986561570179624553948935729246701270864862810533820305613772182038684496677616742662390133827533979567642555654779639897648243286902756964291206300583036515230312782552898532648513981934521359709559620621721148144417810576010756741366480550089167266058041400780623930703718779562612888"); - EXPECT_EQ(sin(-1 + 1 / getTop()).toString(), - "-0.8414709848078965066525023216302989996225630607983710656727517099919104043912396689486397435430526958543490379079206742932591189209918988811934103277292124094807919558267666069999077640119784087827325663474848028702986561570179624553948935729246701270864862810533820305613772182038684496677616742662390133827533979567642555654779639897648243286902756964291206300583036515230312782552898532648513981934521359709559620621721148144417810576010756741366480550089167266058041400780623930703718779562612888"); - EXPECT_EQ(sin(-1 - 1 / getTop()).toString(), - "-0.84147098480789650665250232163029899962256306079837106567275170999191040439123966894863974354305269585434903790792067429325911892099189888119341032772921240948079195582676660699990776401197840878273256634748480287029865615701796245539489357292467012708648628105338203056137721820386844966776167426623901338275339795676425556547796398976482432869027569642912063005830365152303127825528985326485139819345213597095596206217211481444178105760107567413664805500891672660580414007806239307037187795626128881"); -} - -TEST(RealFunctionsTests, cosTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(cos(Real("0")).toString(), - "1.0"); - EXPECT_EQ(cos(Real("1")).toString(), - "0.54030230586813971740093660744297660373231042061792222767009725538110039477447176451795185608718308934357173116003008909786063376002166345640651226541731858471797116447447949423311792455139325433594351775670289259637573615432754964175449177511513122273010063135707823223677140151746899593667873067422762024507763744067587498161784272021645585111563296889057108124272933169868524714568949043423754330944230240935962395831824547281736640780712434336217481003220271297578822917644683598726994264913443918"); - EXPECT_EQ(cos(Real("-1")).toString(), - "0.54030230586813971740093660744297660373231042061792222767009725538110039477447176451795185608718308934357173116003008909786063376002166345640651226541731858471797116447447949423311792455139325433594351775670289259637573615432754964175449177511513122273010063135707823223677140151746899593667873067422762024507763744067587498161784272021645585111563296889057108124272933169868524714568949043423754330944230240935962395831824547281736640780712434336217481003220271297578822917644683598726994264913443918"); - EXPECT_EQ(cos(Real("125")).toString(), - "0.78771451214423447462921467726566085443902399155278651945734350565151508650071466796046012998819530537913247408233058596748835815699856225018573130396740121910887953345238483506835226621728100197018195398650422386215489495273443848383144677431506778903258135280929055290871533015644884795860443216997870894673253673690210503795035903512795400064635918314237317783029884809120156764010545892718073460405049089393892131493855667255271056591535964817972992611733247628171649165107208037643806386267753876"); - - EXPECT_EQ(cos(Real(2 * getPi())).toString(), - "1.0"); - EXPECT_EQ(cos(Real(-2 * getPi())).toString(), - "1.0"); - EXPECT_EQ(cos(Real(getPi())).toString(), - "-1.0"); - EXPECT_EQ(cos(Real(-getPi())).toString(), - "-1.0"); - EXPECT_THROW(cos(Real(getPi() / 2)), - UndefinedFunctionException); - EXPECT_THROW(cos(Real(-getPi() / 2)), - UndefinedFunctionException); - EXPECT_EQ(cos(Real(getPi() / 4)).toString(), - "0.70710678118654752440084436210484903928483593768847403658833986899536623923105351942519376716382078636750692311545614851246241802792536860632206074854996791570661133296375279637789997525057639103028573505477998580298513726729843100736425870932044459930477616461524215435716072541988130181399762570399484362669827316590441482031030762917619752737287514387998086491778761016876592850567718730170424942358019344998534950240751527201389515822712391153424646845931079028923155579833435650650780928449361862"); - EXPECT_EQ(cos(Real(-getPi() / 4)).toString(), - "0.70710678118654752440084436210484903928483593768847403658833986899536623923105351942519376716382078636750692311545614851246241802792536860632206074854996791570661133296375279637789997525057639103028573505477998580298513726729843100736425870932044459930477616461524215435716072541988130181399762570399484362669827316590441482031030762917619752737287514387998086491778761016876592850567718730170424942358019344998534950240751527201389515822712391153424646845931079028923155579833435650650780928449361862"); - - EXPECT_EQ(cos(getBottom()).toString(), - "0.18107822828014080812607973994963809668022018011968409833373163784753628059485292302847692733882493201565592860971009452054722366667927461002984132146537414144521794805683267153319975296740790546732173708859161845231695829716519164490461156032970448655817132188042531338873192841891372222861405636027113743113787211291499008269618071877503842072971904820757006606986576614584311546515292403514735305130971875653866745656152313117710000358536699317727992252311639534399177421169797056773901970315909101"); - EXPECT_EQ(cos(-getBottom()).toString(), - "0.18107822828014080812607973994963809668022018011968409833373163784753628059485292302847692733882493201565592860971009452054722366667927461002984132146537414144521794805683267153319975296740790546732173708859161845231695829716519164490461156032970448655817132188042531338873192841891372222861405636027113743113787211291499008269618071877503842072971904820757006606986576614584311546515292403514735305130971875653866745656152313117710000358536699317727992252311639534399177421169797056773901970315909101"); - EXPECT_EQ(cos(1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(cos(-1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(cos(1 + 1 / getBottom()).toString(), - "0.54030230586813971740093660744297660373231042061792222767009725538110039477447176451795185608718308934357173116003008909786063376002166345640651226541731858471797116447447949423311792455139325433594351775670289259637573615432754964175449177511513122273010063135707823223677140151746899593667873067422762024507763744067587498161784272021645585111563296889057108124272933169868524714568949043423754330944230240935962395831824547281736640780712434336217481003220271297578822917644683598726994264913443917"); - EXPECT_EQ(cos(1 - 1 / getBottom()).toString(), - "0.5403023058681397174009366074429766037323104206179222276700972553811003947744717645179518560871830893435717311600300890978606337600216634564065122654173185847179711644744794942331179245513932543359435177567028925963757361543275496417544917751151312227301006313570782322367714015174689959366787306742276202450776374406758749816178427202164558511156329688905710812427293316986852471456894904342375433094423024093596239583182454728173664078071243433621748100322027129757882291764468359872699426491344392"); - EXPECT_EQ(cos(-1 + 1 / getBottom()).toString(), - "0.5403023058681397174009366074429766037323104206179222276700972553811003947744717645179518560871830893435717311600300890978606337600216634564065122654173185847179711644744794942331179245513932543359435177567028925963757361543275496417544917751151312227301006313570782322367714015174689959366787306742276202450776374406758749816178427202164558511156329688905710812427293316986852471456894904342375433094423024093596239583182454728173664078071243433621748100322027129757882291764468359872699426491344392"); - EXPECT_EQ(cos(-1 - 1 / getBottom()).toString(), - "0.54030230586813971740093660744297660373231042061792222767009725538110039477447176451795185608718308934357173116003008909786063376002166345640651226541731858471797116447447949423311792455139325433594351775670289259637573615432754964175449177511513122273010063135707823223677140151746899593667873067422762024507763744067587498161784272021645585111563296889057108124272933169868524714568949043423754330944230240935962395831824547281736640780712434336217481003220271297578822917644683598726994264913443917"); - - EXPECT_THROW(cos(getTop()), - UndefinedFunctionException); - EXPECT_THROW(cos(-getTop()), - UndefinedFunctionException); - EXPECT_EQ(cos(1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(cos(-1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(cos(1 + 1 / getTop()).toString(), - "0.54030230586813971740093660744297660373231042061792222767009725538110039477447176451795185608718308934357173116003008909786063376002166345640651226541731858471797116447447949423311792455139325433594351775670289259637573615432754964175449177511513122273010063135707823223677140151746899593667873067422762024507763744067587498161784272021645585111563296889057108124272933169868524714568949043423754330944230240935962395831824547281736640780712434336217481003220271297578822917644683598726994264913443918"); - EXPECT_EQ(cos(1 - 1 / getTop()).toString(), - "0.54030230586813971740093660744297660373231042061792222767009725538110039477447176451795185608718308934357173116003008909786063376002166345640651226541731858471797116447447949423311792455139325433594351775670289259637573615432754964175449177511513122273010063135707823223677140151746899593667873067422762024507763744067587498161784272021645585111563296889057108124272933169868524714568949043423754330944230240935962395831824547281736640780712434336217481003220271297578822917644683598726994264913443919"); - EXPECT_EQ(cos(-1 + 1 / getTop()).toString(), - "0.54030230586813971740093660744297660373231042061792222767009725538110039477447176451795185608718308934357173116003008909786063376002166345640651226541731858471797116447447949423311792455139325433594351775670289259637573615432754964175449177511513122273010063135707823223677140151746899593667873067422762024507763744067587498161784272021645585111563296889057108124272933169868524714568949043423754330944230240935962395831824547281736640780712434336217481003220271297578822917644683598726994264913443919"); - EXPECT_EQ(cos(-1 - 1 / getTop()).toString(), - "0.54030230586813971740093660744297660373231042061792222767009725538110039477447176451795185608718308934357173116003008909786063376002166345640651226541731858471797116447447949423311792455139325433594351775670289259637573615432754964175449177511513122273010063135707823223677140151746899593667873067422762024507763744067587498161784272021645585111563296889057108124272933169868524714568949043423754330944230240935962395831824547281736640780712434336217481003220271297578822917644683598726994264913443918"); -} - -TEST(RealFunctionsTests, tanTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(tan(Real("0")).toString(), - "0.0"); - EXPECT_EQ(tan(Real("1")).toString(), - "1.5574077246549022305069748074583601730872507723815200383839466056988613971517272895550999652022429838046338214117481666133235546181245589376060716845489044392935860431671479080368246132747069555973416406107755352473025067968505070413523851449176214816275700278860224507720140161857721306739416643223690166756717950962610882330224852131148350591629692587616111732650100459456348215643353850532597808631549824289061892210758848878924221385209053656104434472362861925446578778273514850773908880700372159"); - EXPECT_EQ(tan(Real("-1")).toString(), - "-1.5574077246549022305069748074583601730872507723815200383839466056988613971517272895550999652022429838046338214117481666133235546181245589376060716845489044392935860431671479080368246132747069555973416406107755352473025067968505070413523851449176214816275700278860224507720140161857721306739416643223690166756717950962610882330224852131148350591629692587616111732650100459456348215643353850532597808631549824289061892210758848878924221385209053656104434472362861925446578778273514850773908880700372159"); - EXPECT_EQ(tan(Real("-10")).toString(), - "-0.6483608274590866712591249330098086768168743429837249756336279673958556003746239008717172062971522861549649082745628323881247057768331995554482067466781684083012928476313833274987342947597860101498990855080324569905070116199321918608717812524808937688710576705226811315614415204550320168972347982491031856202182645398325093913761463643961876140274925792594521384137730587973600612277350961593186576249726202766060828898554007609573802669631814961066246743477343275986185253199041641032488778055939355"); - EXPECT_EQ(tan(Real("1.5")).toString(), - "14.101419947171719387646083651987756445659543577235861866123267586089696270414155268648702926309442287045867838594565919691699004491669865025264248980039061351918594865941647830085172090316199132420462962006307262522713747887816074895835112885636990533301440984006371447953191752413056040636010883158885875789200937415934573118249197536454626507188777255849020779992691101711887207194991636234000277717211545383470167900668346883508414041371529451749917009685422130690021955751283209276658434501266213"); - - EXPECT_THROW(tan(Real(2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(tan(Real(-2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(tan(Real(getPi())), - UndefinedFunctionException); - EXPECT_THROW(tan(Real(-getPi())), - UndefinedFunctionException); - EXPECT_THROW(tan(Real(getPi() / 2)), - UndefinedFunctionException); - EXPECT_THROW(tan(Real(-getPi() / 2)), - UndefinedFunctionException); - EXPECT_EQ(tan(Real(getPi() / 4)).toString(), - "1.0"); - EXPECT_EQ(tan(Real(-getPi() / 4)).toString(), - "-1.0"); - - EXPECT_EQ(tan(getBottom()).toString(), - "-5.4311813460397547587447626770341529596318481084609222513383566349634405846754861155341663030985082767329410852819272956220065758125013239154998142654888199376669218829383175606254107298040562405258471241951475616978001604758520322879113716208185098017287396820886853793727895613451789889314372167107893444667693830431676291482786421428868633758769942810198298654383034764282104423943865423031730216183810899862386979444690387492101492614503609057506161758460060673155113790113421825914100376792659807"); - EXPECT_EQ(tan(-getBottom()).toString(), - "5.4311813460397547587447626770341529596318481084609222513383566349634405846754861155341663030985082767329410852819272956220065758125013239154998142654888199376669218829383175606254107298040562405258471241951475616978001604758520322879113716208185098017287396820886853793727895613451789889314372167107893444667693830431676291482786421428868633758769942810198298654383034764282104423943865423031730216183810899862386979444690387492101492614503609057506161758460060673155113790113421825914100376792659807"); - EXPECT_EQ(tan(1 / getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(tan(-1 / getBottom()).toString(), - "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(tan(1 + 1 / getBottom()).toString(), - "1.557407724654902230506974807458360173087250772381520038383946605698861397151727289555099965202242983804633821411748166613323554618124558937606071684548904439293586043167147908036824613274706955597341640610775535247302506796850507041352385144917621481627570027886022450772014016185772130673941664322369016675671795096261088233022485213114835059162969258761611173265010045945634821564335385053259780863154982428906189221075884887892422138520905365610443447236286192544657877827351485077390888070037216"); - EXPECT_EQ(tan(1 - 1 / getBottom()).toString(), - "1.5574077246549022305069748074583601730872507723815200383839466056988613971517272895550999652022429838046338214117481666133235546181245589376060716845489044392935860431671479080368246132747069555973416406107755352473025067968505070413523851449176214816275700278860224507720140161857721306739416643223690166756717950962610882330224852131148350591629692587616111732650100459456348215643353850532597808631549824289061892210758848878924221385209053656104434472362861925446578778273514850773908880700372159"); - EXPECT_EQ(tan(-1 + 1 / getBottom()).toString(), - "-1.5574077246549022305069748074583601730872507723815200383839466056988613971517272895550999652022429838046338214117481666133235546181245589376060716845489044392935860431671479080368246132747069555973416406107755352473025067968505070413523851449176214816275700278860224507720140161857721306739416643223690166756717950962610882330224852131148350591629692587616111732650100459456348215643353850532597808631549824289061892210758848878924221385209053656104434472362861925446578778273514850773908880700372159"); - EXPECT_EQ(tan(-1 - 1 / getBottom()).toString(), - "-1.557407724654902230506974807458360173087250772381520038383946605698861397151727289555099965202242983804633821411748166613323554618124558937606071684548904439293586043167147908036824613274706955597341640610775535247302506796850507041352385144917621481627570027886022450772014016185772130673941664322369016675671795096261088233022485213114835059162969258761611173265010045945634821564335385053259780863154982428906189221075884887892422138520905365610443447236286192544657877827351485077390888070037216"); - - EXPECT_THROW(tan(getTop()), - UndefinedFunctionException); - EXPECT_THROW(tan(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(tan(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(tan(-1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(tan(1 + 1 / getTop()).toString(), - "1.5574077246549022305069748074583601730872507723815200383839466056988613971517272895550999652022429838046338214117481666133235546181245589376060716845489044392935860431671479080368246132747069555973416406107755352473025067968505070413523851449176214816275700278860224507720140161857721306739416643223690166756717950962610882330224852131148350591629692587616111732650100459456348215643353850532597808631549824289061892210758848878924221385209053656104434472362861925446578778273514850773908880700372159"); - EXPECT_EQ(tan(1 - 1 / getTop()).toString(), - "1.5574077246549022305069748074583601730872507723815200383839466056988613971517272895550999652022429838046338214117481666133235546181245589376060716845489044392935860431671479080368246132747069555973416406107755352473025067968505070413523851449176214816275700278860224507720140161857721306739416643223690166756717950962610882330224852131148350591629692587616111732650100459456348215643353850532597808631549824289061892210758848878924221385209053656104434472362861925446578778273514850773908880700372159"); - EXPECT_EQ(tan(-1 + 1 / getTop()).toString(), - "-1.5574077246549022305069748074583601730872507723815200383839466056988613971517272895550999652022429838046338214117481666133235546181245589376060716845489044392935860431671479080368246132747069555973416406107755352473025067968505070413523851449176214816275700278860224507720140161857721306739416643223690166756717950962610882330224852131148350591629692587616111732650100459456348215643353850532597808631549824289061892210758848878924221385209053656104434472362861925446578778273514850773908880700372159"); - EXPECT_EQ(tan(-1 - 1 / getTop()).toString(), - "-1.5574077246549022305069748074583601730872507723815200383839466056988613971517272895550999652022429838046338214117481666133235546181245589376060716845489044392935860431671479080368246132747069555973416406107755352473025067968505070413523851449176214816275700278860224507720140161857721306739416643223690166756717950962610882330224852131148350591629692587616111732650100459456348215643353850532597808631549824289061892210758848878924221385209053656104434472362861925446578778273514850773908880700372159"); -} - -TEST(RealFunctionsTests, cotTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(cot(Real("1")).toString(), - "0.64209261593433070300641998659426562023027811391817137910116228042627685683916467219848291976019680465814306596047141573918356963493705933122378784310056202796590177952583993144431226921022120997092394574813060354777658685526661570956826754318872654659780710610492629489626709295081160952483427016354137699541561458952860701107858227259376088670827067970590687137491185081969260425814554198558997437568690607879275252280812126851999661677146531833095334863246223721746553979982097961711441872912451219"); - EXPECT_EQ(cot(Real("-1")).toString(), - "-0.64209261593433070300641998659426562023027811391817137910116228042627685683916467219848291976019680465814306596047141573918356963493705933122378784310056202796590177952583993144431226921022120997092394574813060354777658685526661570956826754318872654659780710610492629489626709295081160952483427016354137699541561458952860701107858227259376088670827067970590687137491185081969260425814554198558997437568690607879275252280812126851999661677146531833095334863246223721746553979982097961711441872912451219"); - EXPECT_EQ(cot(Real("200")).toString(), - "-0.55787150213477006971046091195634798429557648836442892718891989460860978240822024024667631450915451073774660263791236163592328009778534581106986084480350539383783137442829604976008950393385033137664222291196435800801798666975792079027585757253905954498091388828903280740148427025875009780214237562977529275111353591152602195933083396628582325080994878394128853394424914997962035967037148064659763141601517052421951131036455074413807404136589615370376036685512143765315739842723268204732900903332822869"); - EXPECT_EQ(cot(Real("0.001")).toString(), - "999.99966666664444444232804211640209502431508213496869579304205077674381954644639520634408395164810974790187059748663056319413799052324462182627171056687766083031520368701013112433153015271276878401509116019338890857459742077956424095491422840422498363560795969002271508729354091645914312319141941002918853623649271992390238327218620139099559359347286220707598821816371457779702994485393706092219607511288539620817165843202653888983899420142454517047661478883062764207608764656613887179725266038933487"); - - EXPECT_THROW(cot(Real("0")), - UndefinedFunctionException); - - EXPECT_THROW(cot(Real(2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(cot(Real(-2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(cot(Real(getPi())), - UndefinedFunctionException); - EXPECT_THROW(cot(Real(-getPi())), - UndefinedFunctionException); - EXPECT_THROW(cot(Real(getPi() / 2)), - UndefinedFunctionException); - EXPECT_THROW(cot(Real(-getPi() / 2)), - UndefinedFunctionException); - EXPECT_EQ(cot(Real(getPi() / 4)).toString(), - "1.0"); - EXPECT_EQ(cot(Real(-getPi() / 4)).toString(), - "-1.0"); - - EXPECT_EQ(cot(getBottom()).toString(), - "-0.18412200519306325407016667669326355916639152669105496672481910174237578167454000191529188464337708129186521629316512830967379465496878179090856555761165685637252528026613210487863729027780010442269847000568542919990903149267916072258207027621895628215541812447287541118888490877686060026532959493627918857475027913676595229078710637701585879757478815591944506850808282759560215986868950156570451221542112525396565833442169756353657878534922198274092733651818614758864926560243915837935991441192773878"); - EXPECT_EQ(cot(-getBottom()).toString(), - "0.18412200519306325407016667669326355916639152669105496672481910174237578167454000191529188464337708129186521629316512830967379465496878179090856555761165685637252528026613210487863729027780010442269847000568542919990903149267916072258207027621895628215541812447287541118888490877686060026532959493627918857475027913676595229078710637701585879757478815591944506850808282759560215986868950156570451221542112525396565833442169756353657878534922198274092733651818614758864926560243915837935991441192773878"); - EXPECT_EQ(cot(1 / getBottom()).toString(), - "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); - EXPECT_EQ(cot(-1 / getBottom()).toString(), - "-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); - EXPECT_EQ(cot(1 + 1 / getBottom()).toString(), - "0.64209261593433070300641998659426562023027811391817137910116228042627685683916467219848291976019680465814306596047141573918356963493705933122378784310056202796590177952583993144431226921022120997092394574813060354777658685526661570956826754318872654659780710610492629489626709295081160952483427016354137699541561458952860701107858227259376088670827067970590687137491185081969260425814554198558997437568690607879275252280812126851999661677146531833095334863246223721746553979982097961711441872912451217"); - EXPECT_EQ(cot(1 - 1 / getBottom()).toString(), - "0.64209261593433070300641998659426562023027811391817137910116228042627685683916467219848291976019680465814306596047141573918356963493705933122378784310056202796590177952583993144431226921022120997092394574813060354777658685526661570956826754318872654659780710610492629489626709295081160952483427016354137699541561458952860701107858227259376088670827067970590687137491185081969260425814554198558997437568690607879275252280812126851999661677146531833095334863246223721746553979982097961711441872912451222"); - EXPECT_EQ(cot(-1 + 1 / getBottom()).toString(), - "-0.64209261593433070300641998659426562023027811391817137910116228042627685683916467219848291976019680465814306596047141573918356963493705933122378784310056202796590177952583993144431226921022120997092394574813060354777658685526661570956826754318872654659780710610492629489626709295081160952483427016354137699541561458952860701107858227259376088670827067970590687137491185081969260425814554198558997437568690607879275252280812126851999661677146531833095334863246223721746553979982097961711441872912451222"); - EXPECT_EQ(cot(-1 - 1 / getBottom()).toString(), - "-0.64209261593433070300641998659426562023027811391817137910116228042627685683916467219848291976019680465814306596047141573918356963493705933122378784310056202796590177952583993144431226921022120997092394574813060354777658685526661570956826754318872654659780710610492629489626709295081160952483427016354137699541561458952860701107858227259376088670827067970590687137491185081969260425814554198558997437568690607879275252280812126851999661677146531833095334863246223721746553979982097961711441872912451217"); - - EXPECT_THROW(cot(getTop()), - UndefinedFunctionException); - EXPECT_THROW(cot(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(cot(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(cot(-1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(cot(1 + 1 / getTop()).toString(), - "0.64209261593433070300641998659426562023027811391817137910116228042627685683916467219848291976019680465814306596047141573918356963493705933122378784310056202796590177952583993144431226921022120997092394574813060354777658685526661570956826754318872654659780710610492629489626709295081160952483427016354137699541561458952860701107858227259376088670827067970590687137491185081969260425814554198558997437568690607879275252280812126851999661677146531833095334863246223721746553979982097961711441872912451218"); - EXPECT_EQ(cot(1 - 1 / getTop()).toString(), - "0.6420926159343307030064199865942656202302781139181713791011622804262768568391646721984829197601968046581430659604714157391835696349370593312237878431005620279659017795258399314443122692102212099709239457481306035477765868552666157095682675431887265465978071061049262948962670929508116095248342701635413769954156145895286070110785822725937608867082706797059068713749118508196926042581455419855899743756869060787927525228081212685199966167714653183309533486324622372174655397998209796171144187291245122"); - EXPECT_EQ(cot(-1 + 1 / getTop()).toString(), - "-0.6420926159343307030064199865942656202302781139181713791011622804262768568391646721984829197601968046581430659604714157391835696349370593312237878431005620279659017795258399314443122692102212099709239457481306035477765868552666157095682675431887265465978071061049262948962670929508116095248342701635413769954156145895286070110785822725937608867082706797059068713749118508196926042581455419855899743756869060787927525228081212685199966167714653183309533486324622372174655397998209796171144187291245122"); - EXPECT_EQ(cot(-1 - 1 / getTop()).toString(), - "-0.64209261593433070300641998659426562023027811391817137910116228042627685683916467219848291976019680465814306596047141573918356963493705933122378784310056202796590177952583993144431226921022120997092394574813060354777658685526661570956826754318872654659780710610492629489626709295081160952483427016354137699541561458952860701107858227259376088670827067970590687137491185081969260425814554198558997437568690607879275252280812126851999661677146531833095334863246223721746553979982097961711441872912451218"); -} - -TEST(RealFunctionsTests, secTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(sec(Real("0")).toString(), - "1.0"); - EXPECT_EQ(sec(Real("1")).toString(), - "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967059218414132873066711491035115807339528416408998731176774131560787241383862147409231241515235786388237571054049733204438514990354855937330333279994572038442605499267955577813651494388974489708121098698689024822929458998871134135427663188500839953123828815800381513006621410411846961570477808388478499442707545318664792285082946656651090325360041775536641555012184458039002171415610374409790953100073117119984608557958766"); - EXPECT_EQ(sec(Real("-1")).toString(), - "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967059218414132873066711491035115807339528416408998731176774131560787241383862147409231241515235786388237571054049733204438514990354855937330333279994572038442605499267955577813651494388974489708121098698689024822929458998871134135427663188500839953123828815800381513006621410411846961570477808388478499442707545318664792285082946656651090325360041775536641555012184458039002171415610374409790953100073117119984608557958766"); - EXPECT_EQ(sec(Real("1.6")).toString(), - "-34.247135610018689205295461483291306219436082882081545055042205706353264742234616759766841076191473839409664538611734617925195701220366610832263260617917260666538563185430899075936508430636255904019861473560275218809871596204265030719512813134685457060746391560781480085081537225093306444179331910946860689431289023477284569340963085841852135429061810527466364052287322154566699315157860608492031102930268932110820811414857180989285521966142672614977651216298392520847891294180247230071394631737507323"); - EXPECT_EQ(sec(Real("125")).toString(), - "1.2694954638805676703376706923632363680417203139865889801435769773818587224340106180842561778627398594296328675156647915025175388802644283560611677887547991438323525363695731878072183300046296268565249875778407154113058071105022718291605450833897545964022288687132708562009303297085706313043356191448387819176502699366292607471598837815123627568762349266196564992265112706988801993419761704140701407040679260548618434002889725490991259085916154432876282144381225020401674602917107148114699610840240977"); - - EXPECT_EQ(sec(Real(2 * getPi())).toString(), - "1.0"); - EXPECT_EQ(sec(Real(-2 * getPi())).toString(), - "1.0"); - EXPECT_EQ(sec(Real(getPi())).toString(), - "-1.0"); - EXPECT_EQ(sec(Real(-getPi())).toString(), - "-1.0"); - EXPECT_THROW(sec(Real(getPi() / 2)), - UndefinedFunctionException); - EXPECT_THROW(sec(Real(-getPi() / 2)), - UndefinedFunctionException); - EXPECT_EQ(sec(Real(getPi() / 4)).toString(), - "1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372"); - EXPECT_EQ(sec(Real(-getPi() / 4)).toString(), - "1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372"); - - EXPECT_EQ(sec(getBottom()).toString(), - "5.5224750622859495465964662921146893135433520038993227250524960754335636816850909427543118213846078297629438197508143277558281878898204929639582661981607948956934846217838693173987993735096951003095464182896479996883696138243219483926647052470306989426491643011782181267644463988552115383650445030020964010481643621860143724117293706875692478335707778003337790738930966248644458916757094723063555531952328900856966235191908206293164456530597523283812670000850370381280570127286697753503335814392062378"); - EXPECT_EQ(sec(-getBottom()).toString(), - "5.5224750622859495465964662921146893135433520038993227250524960754335636816850909427543118213846078297629438197508143277558281878898204929639582661981607948956934846217838693173987993735096951003095464182896479996883696138243219483926647052470306989426491643011782181267644463988552115383650445030020964010481643621860143724117293706875692478335707778003337790738930966248644458916757094723063555531952328900856966235191908206293164456530597523283812670000850370381280570127286697753503335814392062378"); - EXPECT_EQ(sec(1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(sec(-1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(sec(1 + 1 / getBottom()).toString(), - "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967059218414132873066711491035115807339528416408998731176774131560787241383862147409231241515235786388237571054049733204438514990354855937330333279994572038442605499267955577813651494388974489708121098698689024822929458998871134135427663188500839953123828815800381513006621410411846961570477808388478499442707545318664792285082946656651090325360041775536641555012184458039002171415610374409790953100073117119984608557958767"); - EXPECT_EQ(sec(1 - 1 / getBottom()).toString(), - "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967059218414132873066711491035115807339528416408998731176774131560787241383862147409231241515235786388237571054049733204438514990354855937330333279994572038442605499267955577813651494388974489708121098698689024822929458998871134135427663188500839953123828815800381513006621410411846961570477808388478499442707545318664792285082946656651090325360041775536641555012184458039002171415610374409790953100073117119984608557958766"); - EXPECT_EQ(sec(-1 + 1 / getBottom()).toString(), - "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967059218414132873066711491035115807339528416408998731176774131560787241383862147409231241515235786388237571054049733204438514990354855937330333279994572038442605499267955577813651494388974489708121098698689024822929458998871134135427663188500839953123828815800381513006621410411846961570477808388478499442707545318664792285082946656651090325360041775536641555012184458039002171415610374409790953100073117119984608557958766"); - EXPECT_EQ(sec(-1 - 1 / getBottom()).toString(), - "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967059218414132873066711491035115807339528416408998731176774131560787241383862147409231241515235786388237571054049733204438514990354855937330333279994572038442605499267955577813651494388974489708121098698689024822929458998871134135427663188500839953123828815800381513006621410411846961570477808388478499442707545318664792285082946656651090325360041775536641555012184458039002171415610374409790953100073117119984608557958767"); - - EXPECT_THROW(sec(getTop()), - UndefinedFunctionException); - EXPECT_THROW(sec(-getTop()), - UndefinedFunctionException); - EXPECT_EQ(sec(1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(sec(-1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(sec(1 + 1 / getTop()).toString(), - "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967059218414132873066711491035115807339528416408998731176774131560787241383862147409231241515235786388237571054049733204438514990354855937330333279994572038442605499267955577813651494388974489708121098698689024822929458998871134135427663188500839953123828815800381513006621410411846961570477808388478499442707545318664792285082946656651090325360041775536641555012184458039002171415610374409790953100073117119984608557958766"); - EXPECT_EQ(sec(1 - 1 / getTop()).toString(), - "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967059218414132873066711491035115807339528416408998731176774131560787241383862147409231241515235786388237571054049733204438514990354855937330333279994572038442605499267955577813651494388974489708121098698689024822929458998871134135427663188500839953123828815800381513006621410411846961570477808388478499442707545318664792285082946656651090325360041775536641555012184458039002171415610374409790953100073117119984608557958766"); - EXPECT_EQ(sec(-1 + 1 / getTop()).toString(), - "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967059218414132873066711491035115807339528416408998731176774131560787241383862147409231241515235786388237571054049733204438514990354855937330333279994572038442605499267955577813651494388974489708121098698689024822929458998871134135427663188500839953123828815800381513006621410411846961570477808388478499442707545318664792285082946656651090325360041775536641555012184458039002171415610374409790953100073117119984608557958766"); - EXPECT_EQ(sec(-1 - 1 / getTop()).toString(), - "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967059218414132873066711491035115807339528416408998731176774131560787241383862147409231241515235786388237571054049733204438514990354855937330333279994572038442605499267955577813651494388974489708121098698689024822929458998871134135427663188500839953123828815800381513006621410411846961570477808388478499442707545318664792285082946656651090325360041775536641555012184458039002171415610374409790953100073117119984608557958766"); -} - -TEST(RealFunctionsTests, cscTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(csc(Real("1")).toString(), - "1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101737"); - EXPECT_EQ(csc(Real("-1")).toString(), - "-1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101737"); - EXPECT_EQ(csc(Real("3.2")).toString(), - "-17.130872356878680929063816308707772644748981698069414677586948372772984323565408423483640507766628666148265681237511920086970258511680236062318076707749313521817695876380123831909508282966596093285835686395831410297351280914374490328653498778387071527682687131275496025461594734785879102960537054992570954747112214307178536824675515213310334523318434172386047053111498611835029969273057774864899638121645170459166882594313731446347965365139623182955223448213487647268143906769534762185923830892787334"); - EXPECT_EQ(csc(Real("360")).toString(), - "1.0428445123825993746264366840754767090833603173462451344005105419339646525772188525630433129769205288221271874687459480283950885566962033314936632943542886378755570603246796014735776586481664170715810139367954138715715911811558417791760191438999416933570705650066613051160621833296545829520831260246352219360937624349461381007386246664520190341892795778721077472722878343691805161587106133391138153350352638091687284934165572172843784932994015464381320697611705861039314671188244542292789065000592844"); - EXPECT_EQ(csc(Real("-1")).toString(), - "-1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101737"); - - EXPECT_THROW(csc(Real("0")), - UndefinedFunctionException); - - EXPECT_THROW(csc(Real(2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(csc(Real(-2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(csc(Real(getPi())), - UndefinedFunctionException); - EXPECT_THROW(csc(Real(-getPi())), - UndefinedFunctionException); - EXPECT_EQ(csc(Real(getPi() / 2)).toString(), - "1.0"); - EXPECT_EQ(csc(Real(-getPi() / 2)).toString(), - "-1.0"); - EXPECT_EQ(csc(Real(getPi() / 4)).toString(), - "1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372"); - EXPECT_EQ(csc(Real(-getPi() / 4)).toString(), - "-1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372"); - - EXPECT_EQ(csc(getBottom()).toString(), - "-1.0168091820967759198944541198068394518950303536090902584418294758503608753456234988205651359665264123356739099356815935009084045098417114495501327359159176023372334374711086172695375589987360879117045055773051219478877680325646502640804858037502160335387035365989364135681834916084319232797202913202067377290588902193529234645997864148858978549775752319148779332193797461579373322968960363717661928066574046233039921433563022497177618261627922912652319553547089161758887141387706086744056070416794161"); - EXPECT_EQ(csc(-getBottom()).toString(), - "1.0168091820967759198944541198068394518950303536090902584418294758503608753456234988205651359665264123356739099356815935009084045098417114495501327359159176023372334374711086172695375589987360879117045055773051219478877680325646502640804858037502160335387035365989364135681834916084319232797202913202067377290588902193529234645997864148858978549775752319148779332193797461579373322968960363717661928066574046233039921433563022497177618261627922912652319553547089161758887141387706086744056070416794161"); - EXPECT_EQ(csc(1 / getBottom()).toString(), - "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); - EXPECT_EQ(csc(-1 / getBottom()).toString(), - "-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); - EXPECT_EQ(csc(1 + 1 / getBottom()).toString(), - "1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101736"); - EXPECT_EQ(csc(1 - 1 / getBottom()).toString(), - "1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101737"); - EXPECT_EQ(csc(-1 + 1 / getBottom()).toString(), - "-1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101737"); - EXPECT_EQ(csc(-1 - 1 / getBottom()).toString(), - "-1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101736"); - - EXPECT_THROW(csc(getTop()), - UndefinedFunctionException); - EXPECT_THROW(csc(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(csc(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(csc(-1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(csc(1 + 1 / getTop()).toString(), - "1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101736"); - EXPECT_EQ(csc(1 - 1 / getTop()).toString(), - "1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101737"); - EXPECT_EQ(csc(-1 + 1 / getTop()).toString(), - "-1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101737"); - EXPECT_EQ(csc(-1 - 1 / getTop()).toString(), - "-1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101736"); -} - -TEST(RealFunctionsTests, asinTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(asin(Real("0")).toString(), - "0.0"); - EXPECT_EQ(asin(Real("1")).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_EQ(asin(Real("-1")).toString(), - "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_EQ(asin(Real("0.84")).toString(), - "0.99728322237179986604941509532521395934714998516818417157450478882243040040739064902926893714026459287035064571130233073211754382793258492775437715855004671674889185623000769840763429304713098716629852727968827073908276636401276048204827877385901902774150173708596546031159844406856310972438478179578175951803710882156311730333179191202945257138910105504820794989813222587723991409775037600465013785958465561810434613925198365489052649647827967461192622015741352528579453326828887043801608108051477269"); - EXPECT_EQ(asin(Real("-0.84")).toString(), - "-0.99728322237179986604941509532521395934714998516818417157450478882243040040739064902926893714026459287035064571130233073211754382793258492775437715855004671674889185623000769840763429304713098716629852727968827073908276636401276048204827877385901902774150173708596546031159844406856310972438478179578175951803710882156311730333179191202945257138910105504820794989813222587723991409775037600465013785958465561810434613925198365489052649647827967461192622015741352528579453326828887043801608108051477269"); - - EXPECT_THROW(asin(Real("10")), - UndefinedFunctionException); - EXPECT_THROW(asin(Real("-10")), - UndefinedFunctionException); - - EXPECT_THROW(asin(getBottom()), - UndefinedFunctionException); - EXPECT_THROW(asin(-getBottom()), - UndefinedFunctionException); - EXPECT_EQ(asin(1 / getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(asin(-1 / getBottom()).toString(), - "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_THROW(asin(1 + 1 / getBottom()), - UndefinedFunctionException); - EXPECT_EQ(asin(1 - 1 / getBottom()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009543912129524492324911746294869466144351334645739492814493392173080120000958159852068569162071237110901347121303126022389964745087204086224350396918759598758653434173964159689735465688654414318032072936064099095247650063335973521689401338531070936559496"); - EXPECT_EQ(asin(-1 + 1 / getBottom()).toString(), - "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009543912129524492324911746294869466144351334645739492814493392173080120000958159852068569162071237110901347121303126022389964745087204086224350396918759598758653434173964159689735465688654414318032072936064099095247650063335973521689401338531070936559496"); - EXPECT_THROW(asin(-1 - 1 / getBottom()), - UndefinedFunctionException); - - EXPECT_THROW(asin(getTop()), - UndefinedFunctionException); - EXPECT_THROW(asin(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(asin(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(asin(-1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(asin(1 + 1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(asin(1 - 1 / getTop()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009544626714614102467331749140037017778707281343108720908767252437637606686704112448519217753623331070673065952614115246421127884387262543844228820964934513815710803478219109453922658176229218505271474546070789591352895215538283417829914082233990617199866"); - EXPECT_EQ(asin(-1 + 1 / getTop()).toString(), - "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009544626714614102467331749140037017778707281343108720908767252437637606686704112448519217753623331070673065952614115246421127884387262543844228820964934513815710803478219109453922658176229218505271474546070789591352895215538283417829914082233990617199866"); - EXPECT_THROW(asin(-1 - 1 / getTop()), - UndefinedFunctionException); -} - -TEST(RealFunctionsTests, acosTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(acos(Real("0")).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_EQ(acos(Real("1")).toString(), - "0.0"); - EXPECT_EQ(acos(Real("-1")).toString(), - "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491"); - EXPECT_EQ(acos(Real("0.54")).toString(), - "1.0003592173949747118791376298435469512885913377969497906049204887187423921567895177976022221907050335650845132822965716649845600735516029413986139650461173550128803998067400065310353542792427835105916184592623138459755250330281624455815464611629996440114260012860252020183567009333702645210375334263809552895280288326212717942179665352569519572762060481581698696284766538229040683728130641302999291849537143100925393941523072142724992850232516181797925495768215872066743637596358371283895797058420554"); - - EXPECT_THROW(acos(Real("10")), - UndefinedFunctionException); - EXPECT_THROW(acos(Real("-10")), - UndefinedFunctionException); - - EXPECT_THROW(acos(getBottom()), - UndefinedFunctionException); - EXPECT_THROW(acos(-getBottom()), - UndefinedFunctionException); - EXPECT_EQ(acos(1 / getBottom()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059745"); - EXPECT_EQ(acos(-1 / getBottom()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_THROW(acos(1 + 1 / getBottom()), - UndefinedFunctionException); - EXPECT_EQ(acos(1 - 1 / getBottom()).toString(), - "1.8161133101249768313059767637749226167016555062135541295428599514579399162477525362449841992214659204923416486740342626879990151285206963843627887984484066329176548338000757254648982552487409334526566762732166521636845007859070742231176086199785002494824233671741808993871471604475449814991979005026904466371335432200684754360612792364909810664574323876073450385968843689808751624105899580384533574694605556028984635741348186918197680661361994642285426418712562403143105149802614347742290494321962424*10^-250"); - EXPECT_EQ(acos(-1 + 1 / getBottom()).toString(), - "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019089640372359109626654798566502707211319370946985199183116327206111697941832567456673383308341695687723186584254926079042617489189536693145085156626317645923939786002762119455196396275564077376997598528804471407147463811172732950453025794670761851619242"); - EXPECT_THROW(acos(-1 - 1 / getBottom()), - UndefinedFunctionException); - - EXPECT_THROW(acos(getTop()), - UndefinedFunctionException); - EXPECT_THROW(acos(-getTop()), - UndefinedFunctionException); - EXPECT_EQ(acos(1 / getTop()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_EQ(acos(-1 / getTop()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_THROW(acos(1 + 1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(acos(1 - 1 / getTop()).toString(), - "1.1015282205148344113031315962232882607549581369854598556825953939712541702951560855963926471275061487735103376848102315248597150700630765059387426235333495755483505788503115382724106804445536940510466695827205469185322984760109337103739057002978598795971390260446685983828095271655143299592980169999703367652156688155730814358165398832394569722569002490431507814481217842691057439436763109599092031344149400752025936592695703741466909450253591955614422574626565454002410396637850800605126854091903233*10^-250"); - EXPECT_EQ(acos(-1 + 1 / getTop()).toString(), - "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019090354957448719769074801411670258845675317644354427277390187470669184627578520053124031899893789647494905415565915303073780628489595150764963580672492560980997155307017069219383588763138881564237000138811161903252708963375042846593538538373681532259612"); - EXPECT_THROW(acos(-1 - 1 / getTop()), - UndefinedFunctionException); -} - -TEST(RealFunctionsTests, atanTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(atan(Real("0")).toString(), - "0.0"); - EXPECT_EQ(atan(Real("1")).toString(), - "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298728"); - EXPECT_EQ(atan(Real("-1")).toString(), - "-0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298728"); - EXPECT_EQ(atan(Real("14.101419947171719387646083651987756445659543577235861866123267586089696270414155")).toString(), - "1.4999999999999999999999999999999999999999999999999999999999999999999999999999999986557485960895199125387043907542032801136829232958046907115124578097639341530485021618692919413868147394671838598734881735885773972918552984731919752053253231253315465725537708536001345140870093737528215974550433984916148591853059984658651385865500161526429293734649866629271250527621483972031469401349267647155678663320895436053043953039159231443788199005744104871304685292815911594688201423702826364719784004235324669"); - - EXPECT_EQ(atan(getBottom()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059745"); - EXPECT_EQ(atan(-getBottom()).toString(), - "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059745"); - EXPECT_EQ(atan(1 / getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(atan(-1 / getBottom()).toString(), - "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(atan(1 + 1 / getBottom()).toString(), - "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298729"); - EXPECT_EQ(atan(1 - 1 / getBottom()).toString(), - "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298727"); - EXPECT_EQ(atan(-1 + 1 / getBottom()).toString(), - "-0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298727"); - EXPECT_EQ(atan(-1 - 1 / getBottom()).toString(), - "-0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298729"); - - EXPECT_EQ(atan(getTop()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_EQ(atan(-getTop()).toString(), - "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_THROW(atan(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(atan(-1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(atan(1 + 1 / getTop()).toString(), - "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298729"); - EXPECT_EQ(atan(1 - 1 / getTop()).toString(), - "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298728"); - EXPECT_EQ(atan(-1 + 1 / getTop()).toString(), - "-0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298728"); - EXPECT_EQ(atan(-1 - 1 / getTop()).toString(), - "-0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298729"); -} - -TEST(RealFunctionsTests, acotTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(acot(Real("1")).toString(), - "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298728"); - EXPECT_EQ(acot(Real("-1")).toString(), - "-0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298728"); - EXPECT_EQ(acot(Real("999.9996666666444444423280421164020950243150821349686957930420507767438195464464")).toString(), - "0.00099999999999999999999999999999999999999999999999999999999999999999999999999999999520634568183674040783970331582554073275320346626391287599441844855329139555995768197166058821093605951741769596479352976180441333074229850093543964493443860640600490586849713950251489092715413226533897754456153271726325985194450173733913611757889318251097033681593161211552378778014959359303764665491769639631227095346657170959640829846817771528191249797072531699834783539726035526166348364413613552480681028846378824925"); - - EXPECT_THROW(acot(Real("0")), - UndefinedFunctionException); - - EXPECT_EQ(acot(getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(acot(-getBottom()).toString(), - "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(acot(1 / getBottom()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059745"); - EXPECT_EQ(acot(-1 / getBottom()).toString(), - "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059745"); - EXPECT_EQ(acot(1 + 1 / getBottom()).toString(), - "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298727"); - EXPECT_EQ(acot(1 - 1 / getBottom()).toString(), - "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298729"); - EXPECT_EQ(acot(-1 + 1 / getBottom()).toString(), - "-0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298729"); - EXPECT_EQ(acot(-1 - 1 / getBottom()).toString(), - "-0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298727"); - - EXPECT_THROW(acot(getTop()), - UndefinedFunctionException); - EXPECT_THROW(acot(-getTop()), - UndefinedFunctionException); - EXPECT_EQ(acot(1 / getTop()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_EQ(acot(-1 / getTop()).toString(), - "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_EQ(acot(1 + 1 / getTop()).toString(), - "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298728"); - EXPECT_EQ(acot(1 - 1 / getTop()).toString(), - "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298729"); - EXPECT_EQ(acot(-1 + 1 / getTop()).toString(), - "-0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298729"); - EXPECT_EQ(acot(-1 - 1 / getTop()).toString(), - "-0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298728"); -} - -TEST(RealFunctionsTests, asecTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(asec(Real("1")).toString(), - "0.0"); - EXPECT_EQ(asec(Real("-1")).toString(), - "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491"); - EXPECT_EQ(asec(Real("10")).toString(), - "1.4706289056333368228857985121870581235299087274579233690964484411175055294922419476600795483115540790354139523365445673552638537317168230955847715295934245933913273961251744327831394252885495329911892499587550164005381463914995532449150831130595422903562451075432852164075675492409300957134191398921963555860131780733948338794456781847945590245320828639079428623293050680318781426214169668104934082060094067210621573745719103079204399886370944891456272623132457064796150016835215040991855108847914131"); - EXPECT_EQ(asec(Real("-10")).toString(), - "1.670963747956456415576844871092444760667260671917182451878496151190310876793967050967955277030562988946734134176737739291829990877833759136140587878535056524058956706576764088322420219334399421939192714470055959265395299736976094988871700052211659618789403459380175132202886777407283297893841109249077369000993428242193341002075242778034695067183281503984647497682025462516942323899967180141448103403423650549303602217381181878196941943974698615972920812149134256269952350202231220792042427298220536"); - - EXPECT_THROW(asec(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(asec(Real("0.54")), - UndefinedFunctionException); - EXPECT_THROW(asec(Real("-0.54")), - UndefinedFunctionException); - - EXPECT_EQ(asec(getBottom()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059745"); - EXPECT_EQ(asec(-getBottom()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_THROW(asec(1 / getBottom()), - UndefinedFunctionException); - EXPECT_THROW(asec(-1 / getBottom()), - UndefinedFunctionException); - EXPECT_EQ(asec(1 + 1 / getBottom()).toString(), - "1.8161133101249768313059767637749226167016555062135541295428599514579399162477525362449841992214659204923416486740342626879990151285206963843627887984484066329176548338000757254648982552487409334526566762732166521636845007859070742231176086199785002494824233671741808993871471604475449814991979005026904466371335432200684754360612792364909810664574323876073450385968843689808751624105899580384533574694605556028984635741348186918197680661361994642285426418712562403143105149802614347742290494321962424*10^-250"); - EXPECT_THROW(asec(1 - 1 / getBottom()), - UndefinedFunctionException); - EXPECT_THROW(asec(-1 + 1 / getBottom()), - UndefinedFunctionException); - EXPECT_EQ(asec(-1 - 1 / getBottom()).toString(), - "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019089640372359109626654798566502707211319370946985199183116327206111697941832567456673383308341695687723186584254926079042617489189536693145085156626317645923939786002762119455196396275564077376997598528804471407147463811172732950453025794670761851619242"); - - EXPECT_EQ(asec(getTop()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_EQ(asec(-getTop()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_THROW(asec(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(asec(-1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(asec(1 + 1 / getTop()).toString(), - "1.1015282205148344113031315962232882607549581369854598556825953939712541702951560855963926471275061487735103376848102315248597150700630765059387426235333495755483505788503115382724106804445536940510466695827205469185322984760109337103739057002978598795971390260446685983828095271655143299592980169999703367652156688155730814358165398832394569722569002490431507814481217842691057439436763109599092031344149400752025936592695703741466909450253591955614422574626565454002410396637850800605126854091903233*10^-250"); - EXPECT_THROW(asec(1 - 1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(asec(-1 + 1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(asec(-1 - 1 / getTop()).toString(), - "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019090354957448719769074801411670258845675317644354427277390187470669184627578520053124031899893789647494905415565915303073780628489595150764963580672492560980997155307017069219383588763138881564237000138811161903252708963375042846593538538373681532259612"); -} - -TEST(RealFunctionsTests, acscTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(acsc(Real("1")).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_EQ(acsc(Real("-1")).toString(), - "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_EQ(acsc(Real("2")).toString(), - "0.52359877559829887307710723054658381403286156656251763682915743205130273438103483310467247089035284466369134775221371777451564076825843037195422656802141351957504735045032308685092660743715815915506366073813516261098890768807927470563113052754520031819094142782057672476840905444136889893454337485687895409783443438593136248025348682713820901528589406131543172666855508842480341108689735782532358526823884287839429326532551536435289698876863218418642467907706332712492789198095878748187132303050199152"); - EXPECT_EQ(acsc(Real("10")).toString(), - "0.10016742116155979634552317945269331856867597222962954139102385503640267365086255165393786435950445495566009092009658596828306857305846802027790817447081596533381465522579482776964039702292494447400173225565047143242857667273827087197830846957605866421657917591844495789765961408317660109021098467844050670749012508439925356131478229662006802132559932003835231767636019724253209063927510666547734759870712191412072242140463578513825097766880206341364677491794427489516867425935485834642845820671456144"); - EXPECT_EQ(acsc(Real("-10")).toString(), - "-0.10016742116155979634552317945269331856867597222962954139102385503640267365086255165393786435950445495566009092009658596828306857305846802027790817447081596533381465522579482776964039702292494447400173225565047143242857667273827087197830846957605866421657917591844495789765961408317660109021098467844050670749012508439925356131478229662006802132559932003835231767636019724253209063927510666547734759870712191412072242140463578513825097766880206341364677491794427489516867425935485834642845820671456144"); - - EXPECT_THROW(acsc(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(acsc(Real("0.54")), - UndefinedFunctionException); - EXPECT_THROW(acsc(Real("-0.54")), - UndefinedFunctionException); - - EXPECT_EQ(acsc(getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(acsc(-getBottom()).toString(), - "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_THROW(acsc(1 / getBottom()), - UndefinedFunctionException); - EXPECT_THROW(acsc(-1 / getBottom()), - UndefinedFunctionException); - EXPECT_EQ(acsc(1 + 1 / getBottom()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009543912129524492324911746294869466144351334645739492814493392173080120000958159852068569162071237110901347121303126022389964745087204086224350396918759598758653434173964159689735465688654414318032072936064099095247650063335973521689401338531070936559496"); - EXPECT_THROW(acsc(1 - 1 / getBottom()), - UndefinedFunctionException); - EXPECT_THROW(acsc(-1 + 1 / getBottom()), - UndefinedFunctionException); - EXPECT_EQ(acsc(-1 - 1 / getBottom()).toString(), - "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009543912129524492324911746294869466144351334645739492814493392173080120000958159852068569162071237110901347121303126022389964745087204086224350396918759598758653434173964159689735465688654414318032072936064099095247650063335973521689401338531070936559496"); - - EXPECT_THROW(acsc(getTop()), - UndefinedFunctionException); - EXPECT_THROW(acsc(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(acsc(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(acsc(-1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(acsc(1 + 1 / getTop()).toString(), - "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009544626714614102467331749140037017778707281343108720908767252437637606686704112448519217753623331070673065952614115246421127884387262543844228820964934513815710803478219109453922658176229218505271474546070789591352895215538283417829914082233990617199866"); - EXPECT_THROW(acsc(1 - 1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(acsc(-1 + 1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(acsc(-1 - 1 / getTop()).toString(), - "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009544626714614102467331749140037017778707281343108720908767252437637606686704112448519217753623331070673065952614115246421127884387262543844228820964934513815710803478219109453922658176229218505271474546070789591352895215538283417829914082233990617199866"); -} - -TEST(RealFunctionsTests, sinhTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(sinh(Real("0")).toString(), - "0.0"); - EXPECT_EQ(sinh(Real("1")).toString(), - "1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780262"); - EXPECT_EQ(sinh(Real("-1")).toString(), - "-1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780262"); - EXPECT_EQ(sinh(Real("360")).toString(), - "1109132648769277699994832951779334959572708277708353570726045868205344177119690594588131746049580652728185317433434728299662326745010242929866979740785668334.9369930931945296295585489677849719995780307375177864620603810216778944498417730244884075816447558390018965037731947414439832396164138967666157382569681877669037975855593072277274753560410593052652613283568803324928535988392249507967662940803864786943951899720538017858364240981304455315325988152122269310390141654913689036232994901821575183366"); - EXPECT_EQ(sinh(Real("1000000")).toString(), - "1.5166076984010437725432010707090571635419868974067387048030974998931132315932118262378896014238733712231453572791977727160648924261330240557869860774850358098312131563768360829761690407034195827198088986937033466934046726913218958947601036565089018349581925436647068674894225777805207965238477572592464354499304442433954381395399968367300979907629021482576602691540020197706252822827022193134154228496566284261501675246544829778210486724753160797320622498901320808395701922250790368495099757883193218*10^434294"); - EXPECT_EQ(sinh(Real("-1000000")).toString(), - "-1.5166076984010437725432010707090571635419868974067387048030974998931132315932118262378896014238733712231453572791977727160648924261330240557869860774850358098312131563768360829761690407034195827198088986937033466934046726913218958947601036565089018349581925436647068674894225777805207965238477572592464354499304442433954381395399968367300979907629021482576602691540020197706252822827022193134154228496566284261501675246544829778210486724753160797320622498901320808395701922250790368495099757883193218*10^434294"); - - EXPECT_THROW(sinh(getBottom()), - UndefinedFunctionException); - EXPECT_THROW(sinh(-getBottom()), - UndefinedFunctionException); - EXPECT_EQ(sinh(1 / getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(sinh(-1 / getBottom()).toString(), - "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(sinh(1 + 1 / getBottom()).toString(), - "1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780263"); - EXPECT_EQ(sinh(1 - 1 / getBottom()).toString(), - "1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780262"); - EXPECT_EQ(sinh(-1 + 1 / getBottom()).toString(), - "-1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780262"); - EXPECT_EQ(sinh(-1 - 1 / getBottom()).toString(), - "-1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780263"); - - EXPECT_THROW(sinh(getTop()), - UndefinedFunctionException); - EXPECT_THROW(sinh(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(sinh(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(sinh(-1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(sinh(1 + 1 / getTop()).toString(), - "1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780263"); - EXPECT_EQ(sinh(1 - 1 / getTop()).toString(), - "1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780262"); - EXPECT_EQ(sinh(-1 + 1 / getTop()).toString(), - "-1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780262"); - EXPECT_EQ(sinh(-1 - 1 / getTop()).toString(), - "-1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780263"); -} - -TEST(RealFunctionsTests, coshTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(cosh(Real("0")).toString(), - "1.0"); - EXPECT_EQ(cosh(Real("1")).toString(), - "1.5430806348152437784779056207570616826015291123658637047374022147107690630492236989642647264355430355870468586044235275650321946947095862907634939423773472069151633480026408029059364105029494057980033657762593319443209506958499136898103743054847127392984561603903858174714536360045187363068275143488012027205749727055244716707064471032711422829394484116772731021396329586672730122826261409857215459162042522453939258584439199475134380734969475319971032521055637731102374474158960765443652715148207669"); - EXPECT_EQ(cosh(Real("-1")).toString(), - "1.5430806348152437784779056207570616826015291123658637047374022147107690630492236989642647264355430355870468586044235275650321946947095862907634939423773472069151633480026408029059364105029494057980033657762593319443209506958499136898103743054847127392984561603903858174714536360045187363068275143488012027205749727055244716707064471032711422829394484116772731021396329586672730122826261409857215459162042522453939258584439199475134380734969475319971032521055637731102374474158960765443652715148207669"); - EXPECT_EQ(cosh(Real("125")).toString(), - "967788021017861284360312245263743609428141503861911628.64033144120749560890919682980085560050488085395212512026558310267449706617759172826635347506504267878288393972548683072688439459866997986011447684535615219301778692196684742834562718938301353094423455793969187886409230354763153693439885288025503613794244881555555702720690834846404138079225231434323388617953772771564781077546600594506118915603773124658746748177543832367820875787516380230311817562929218294096243813165231014238938523739493229521"); - EXPECT_EQ(cosh(Real("1000000")).toString(), - "1.5166076984010437725432010707090571635419868974067387048030974998931132315932118262378896014238733712231453572791977727160648924261330240557869860774850358098312131563768360829761690407034195827198088986937033466934046726913218958947601036565089018349581925436647068674894225777805207965238477572592464354499304442433954381395399968367300979907629021482576602691540020197706252822827022193134154228496566284261501675246544829778210486724753160797320622498901320808395701922250790368495099757883193218*10^434294"); - EXPECT_EQ(cosh(Real("-1000000")).toString(), - "1.5166076984010437725432010707090571635419868974067387048030974998931132315932118262378896014238733712231453572791977727160648924261330240557869860774850358098312131563768360829761690407034195827198088986937033466934046726913218958947601036565089018349581925436647068674894225777805207965238477572592464354499304442433954381395399968367300979907629021482576602691540020197706252822827022193134154228496566284261501675246544829778210486724753160797320622498901320808395701922250790368495099757883193218*10^434294"); - - EXPECT_THROW(cosh(getBottom()), - UndefinedFunctionException); - EXPECT_THROW(cosh(-getBottom()), - UndefinedFunctionException); - EXPECT_EQ(cosh(1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(cosh(-1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(cosh(1 + 1 / getBottom()).toString(), - "1.5430806348152437784779056207570616826015291123658637047374022147107690630492236989642647264355430355870468586044235275650321946947095862907634939423773472069151633480026408029059364105029494057980033657762593319443209506958499136898103743054847127392984561603903858174714536360045187363068275143488012027205749727055244716707064471032711422829394484116772731021396329586672730122826261409857215459162042522453939258584439199475134380734969475319971032521055637731102374474158960765443652715148207669"); - EXPECT_EQ(cosh(1 - 1 / getBottom()).toString(), - "1.5430806348152437784779056207570616826015291123658637047374022147107690630492236989642647264355430355870468586044235275650321946947095862907634939423773472069151633480026408029059364105029494057980033657762593319443209506958499136898103743054847127392984561603903858174714536360045187363068275143488012027205749727055244716707064471032711422829394484116772731021396329586672730122826261409857215459162042522453939258584439199475134380734969475319971032521055637731102374474158960765443652715148207669"); - EXPECT_EQ(cosh(-1 + 1 / getBottom()).toString(), - "1.5430806348152437784779056207570616826015291123658637047374022147107690630492236989642647264355430355870468586044235275650321946947095862907634939423773472069151633480026408029059364105029494057980033657762593319443209506958499136898103743054847127392984561603903858174714536360045187363068275143488012027205749727055244716707064471032711422829394484116772731021396329586672730122826261409857215459162042522453939258584439199475134380734969475319971032521055637731102374474158960765443652715148207669"); - EXPECT_EQ(cosh(-1 - 1 / getBottom()).toString(), - "1.5430806348152437784779056207570616826015291123658637047374022147107690630492236989642647264355430355870468586044235275650321946947095862907634939423773472069151633480026408029059364105029494057980033657762593319443209506958499136898103743054847127392984561603903858174714536360045187363068275143488012027205749727055244716707064471032711422829394484116772731021396329586672730122826261409857215459162042522453939258584439199475134380734969475319971032521055637731102374474158960765443652715148207669"); - - EXPECT_THROW(cosh(getTop()), - UndefinedFunctionException); - EXPECT_THROW(cosh(-getTop()), - UndefinedFunctionException); - EXPECT_EQ(cosh(1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(cosh(-1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(cosh(1 + 1 / getTop()).toString(), - "1.5430806348152437784779056207570616826015291123658637047374022147107690630492236989642647264355430355870468586044235275650321946947095862907634939423773472069151633480026408029059364105029494057980033657762593319443209506958499136898103743054847127392984561603903858174714536360045187363068275143488012027205749727055244716707064471032711422829394484116772731021396329586672730122826261409857215459162042522453939258584439199475134380734969475319971032521055637731102374474158960765443652715148207669"); - EXPECT_EQ(cosh(1 - 1 / getTop()).toString(), - "1.5430806348152437784779056207570616826015291123658637047374022147107690630492236989642647264355430355870468586044235275650321946947095862907634939423773472069151633480026408029059364105029494057980033657762593319443209506958499136898103743054847127392984561603903858174714536360045187363068275143488012027205749727055244716707064471032711422829394484116772731021396329586672730122826261409857215459162042522453939258584439199475134380734969475319971032521055637731102374474158960765443652715148207669"); - EXPECT_EQ(cosh(-1 + 1 / getTop()).toString(), - "1.5430806348152437784779056207570616826015291123658637047374022147107690630492236989642647264355430355870468586044235275650321946947095862907634939423773472069151633480026408029059364105029494057980033657762593319443209506958499136898103743054847127392984561603903858174714536360045187363068275143488012027205749727055244716707064471032711422829394484116772731021396329586672730122826261409857215459162042522453939258584439199475134380734969475319971032521055637731102374474158960765443652715148207669"); - EXPECT_EQ(cosh(-1 - 1 / getTop()).toString(), - "1.5430806348152437784779056207570616826015291123658637047374022147107690630492236989642647264355430355870468586044235275650321946947095862907634939423773472069151633480026408029059364105029494057980033657762593319443209506958499136898103743054847127392984561603903858174714536360045187363068275143488012027205749727055244716707064471032711422829394484116772731021396329586672730122826261409857215459162042522453939258584439199475134380734969475319971032521055637731102374474158960765443652715148207669"); -} - -TEST(RealFunctionsTests, tanhTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(tanh(Real("0")).toString(), - "0.0"); - EXPECT_EQ(tanh(Real("1")).toString(), - "0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804484"); - EXPECT_EQ(tanh(Real("-1")).toString(), - "-0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804484"); - EXPECT_EQ(tanh(Real("-10")).toString(), - "-0.99999999587769276361959283713827574105081461849501996226140069543680188089876682610651332495069023186972594195440363277723624598935122112440069080032115324852030221370176075706784328596681042097167304971561185014681914071046105155116929711575041632291885682046344687578127127378663128356531074774188950457761545651571845725123775892342065718865628066593586139144590877440112159808017122001606191995699617317633908518383704737642531119106680691544131671862104511838933336178182094978245610587892680611"); - EXPECT_EQ(tanh(Real("1.5")).toString(), - "0.90514825364486643824230369645649559722764113515878179856422398245110257699457953222843269101787992198816384606649913310622603564592634684340525624846730061861687883119099234115393484765923872777837195630862043546376347603797951539605486739277429280113414587707105343910689582734795135162623708843908897111414918276778575826105640243378448095138635623465280403620875453278721442624467678545763846839133816738080129681138567975955106015534793342340598634645685414817360153396968748805911380462289187205"); - EXPECT_EQ(tanh(Real("1000000")).toString(), - "1.0"); - EXPECT_EQ(tanh(Real("-1000000")).toString(), - "-1.0"); - - EXPECT_EQ(tanh(getBottom()).toString(), - "1.0"); - EXPECT_EQ(tanh(-getBottom()).toString(), - "-1.0"); - EXPECT_EQ(tanh(1 / getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(tanh(-1 / getBottom()).toString(), - "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(tanh(1 + 1 / getBottom()).toString(), - "0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804485"); - EXPECT_EQ(tanh(1 - 1 / getBottom()).toString(), - "0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804483"); - EXPECT_EQ(tanh(-1 + 1 / getBottom()).toString(), - "-0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804483"); - EXPECT_EQ(tanh(-1 - 1 / getBottom()).toString(), - "-0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804485"); - - EXPECT_EQ(tanh(getTop()).toString(), - "1.0"); - EXPECT_EQ(tanh(-getTop()).toString(), - "-1.0"); - EXPECT_THROW(tanh(1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(tanh(-1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_EQ(tanh(1 + 1 / getTop()).toString(), - "0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804484"); - EXPECT_EQ(tanh(1 - 1 / getTop()).toString(), - "0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804484"); - EXPECT_EQ(tanh(-1 + 1 / getTop()).toString(), - "-0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804484"); - EXPECT_EQ(tanh(-1 - 1 / getTop()).toString(), - "-0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804484"); -} - -TEST(RealFunctionsTests, cothTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(coth(Real("1")).toString(), - "1.3130352854993313036361612469308478329120139412404526555431529675670842704618743826746792414808563029467947050738448204197703961861267108989696017535496187432786603952677415430193164214901222207116902698721736279449551078863534426431459421512705491545530284902291249287850149672463612993918572556026640725698026338831716611079696232602874932353108307435238960892539297808523447222896268792900584895961848078828348145997881467167886864925710322604873807663078752942123708924231550111748471298599194883"); - EXPECT_EQ(coth(Real("-1")).toString(), - "-1.3130352854993313036361612469308478329120139412404526555431529675670842704618743826746792414808563029467947050738448204197703961861267108989696017535496187432786603952677415430193164214901222207116902698721736279449551078863534426431459421512705491545530284902291249287850149672463612993918572556026640725698026338831716611079696232602874932353108307435238960892539297808523447222896268792900584895961848078828348145997881467167886864925710322604873807663078752942123708924231550111748471298599194883"); - EXPECT_EQ(coth(Real("200")).toString(), - "1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000038303391934280113900396795573085287014841855524448953631021607422417646473573760059507801414331691466209937002832713535194020115091227231599793300253123583380378786696229319672772120386416997445670439552281318152281668340867503976012400453575958901885856116905302318946467013430357677968237169269573544570155512584968141826895"); - EXPECT_EQ(coth(Real("0.001")).toString(), - "1000.0003333333111111132275130158730372508128641887448236432439795543114729807153254114482587616590903727706298998985853351209233276211395607849063256242229428450694565780626672470531710727943388092505107386416560257427382464277011318403943334868282617859483860836013434754673344838329233034140082802259546514283321520764948797860429100584080842871729723162311625968708950842631100447087303126022291471917210087667595609631298555089952496586378122482454668445694499448905241095228274357354349242116424"); - EXPECT_EQ(coth(Real("1000000")).toString(), - "1.0"); - EXPECT_EQ(coth(Real("-1000000")).toString(), - "-1.0"); - - EXPECT_THROW(coth(Real("0")), - UndefinedFunctionException); - - EXPECT_EQ(coth(getBottom()).toString(), - "1.0"); - EXPECT_EQ(coth(-getBottom()).toString(), - "-1.0"); - EXPECT_EQ(coth(1 / getBottom()).toString(), - "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); - EXPECT_EQ(coth(-1 / getBottom()).toString(), - "-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); - EXPECT_EQ(coth(1 + 1 / getBottom()).toString(), - "1.3130352854993313036361612469308478329120139412404526555431529675670842704618743826746792414808563029467947050738448204197703961861267108989696017535496187432786603952677415430193164214901222207116902698721736279449551078863534426431459421512705491545530284902291249287850149672463612993918572556026640725698026338831716611079696232602874932353108307435238960892539297808523447222896268792900584895961848078828348145997881467167886864925710322604873807663078752942123708924231550111748471298599194883"); - EXPECT_EQ(coth(1 - 1 / getBottom()).toString(), - "1.3130352854993313036361612469308478329120139412404526555431529675670842704618743826746792414808563029467947050738448204197703961861267108989696017535496187432786603952677415430193164214901222207116902698721736279449551078863534426431459421512705491545530284902291249287850149672463612993918572556026640725698026338831716611079696232602874932353108307435238960892539297808523447222896268792900584895961848078828348145997881467167886864925710322604873807663078752942123708924231550111748471298599194883"); - EXPECT_EQ(coth(-1 + 1 / getBottom()).toString(), - "-1.3130352854993313036361612469308478329120139412404526555431529675670842704618743826746792414808563029467947050738448204197703961861267108989696017535496187432786603952677415430193164214901222207116902698721736279449551078863534426431459421512705491545530284902291249287850149672463612993918572556026640725698026338831716611079696232602874932353108307435238960892539297808523447222896268792900584895961848078828348145997881467167886864925710322604873807663078752942123708924231550111748471298599194883"); - EXPECT_EQ(coth(-1 - 1 / getBottom()).toString(), - "-1.3130352854993313036361612469308478329120139412404526555431529675670842704618743826746792414808563029467947050738448204197703961861267108989696017535496187432786603952677415430193164214901222207116902698721736279449551078863534426431459421512705491545530284902291249287850149672463612993918572556026640725698026338831716611079696232602874932353108307435238960892539297808523447222896268792900584895961848078828348145997881467167886864925710322604873807663078752942123708924231550111748471298599194883"); - - EXPECT_EQ(coth(getTop()).toString(), - "1.0"); - EXPECT_EQ(coth(-getTop()).toString(), - "-1.0"); - EXPECT_THROW(coth(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(coth(-1 / getTop()), - UndefinedFunctionException); - EXPECT_EQ(coth(1 + 1 / getTop()).toString(), - "1.3130352854993313036361612469308478329120139412404526555431529675670842704618743826746792414808563029467947050738448204197703961861267108989696017535496187432786603952677415430193164214901222207116902698721736279449551078863534426431459421512705491545530284902291249287850149672463612993918572556026640725698026338831716611079696232602874932353108307435238960892539297808523447222896268792900584895961848078828348145997881467167886864925710322604873807663078752942123708924231550111748471298599194883"); - EXPECT_EQ(coth(1 - 1 / getTop()).toString(), - "1.3130352854993313036361612469308478329120139412404526555431529675670842704618743826746792414808563029467947050738448204197703961861267108989696017535496187432786603952677415430193164214901222207116902698721736279449551078863534426431459421512705491545530284902291249287850149672463612993918572556026640725698026338831716611079696232602874932353108307435238960892539297808523447222896268792900584895961848078828348145997881467167886864925710322604873807663078752942123708924231550111748471298599194883"); - EXPECT_EQ(coth(-1 + 1 / getTop()).toString(), - "-1.3130352854993313036361612469308478329120139412404526555431529675670842704618743826746792414808563029467947050738448204197703961861267108989696017535496187432786603952677415430193164214901222207116902698721736279449551078863534426431459421512705491545530284902291249287850149672463612993918572556026640725698026338831716611079696232602874932353108307435238960892539297808523447222896268792900584895961848078828348145997881467167886864925710322604873807663078752942123708924231550111748471298599194883"); - EXPECT_EQ(coth(-1 - 1 / getTop()).toString(), - "-1.3130352854993313036361612469308478329120139412404526555431529675670842704618743826746792414808563029467947050738448204197703961861267108989696017535496187432786603952677415430193164214901222207116902698721736279449551078863534426431459421512705491545530284902291249287850149672463612993918572556026640725698026338831716611079696232602874932353108307435238960892539297808523447222896268792900584895961848078828348145997881467167886864925710322604873807663078752942123708924231550111748471298599194883"); -} - -TEST(RealFunctionsTests, sechTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(sech(Real("0")).toString(), - "1.0"); - EXPECT_EQ(sech(Real("1")).toString(), - "0.64805427366388539957497735322615032310848931207194202303786533731871759564671283028085478530789289238484741080920067693803371342199608047328527095053204320637710138926219751549816225165048045954767037456642342841785116074316762362109780982148957951547955724736187053107831495505487985321572485483727544183904287647250786507031934414748522969445640178730087299069355083406660792094751146726395612000124233338654264471442651311028781015766133420886738838930728215565261724863512460842165916753490629436"); - EXPECT_EQ(sech(Real("-1")).toString(), - "0.64805427366388539957497735322615032310848931207194202303786533731871759564671283028085478530789289238484741080920067693803371342199608047328527095053204320637710138926219751549816225165048045954767037456642342841785116074316762362109780982148957951547955724736187053107831495505487985321572485483727544183904287647250786507031934414748522969445640178730087299069355083406660792094751146726395612000124233338654264471442651311028781015766133420886738838930728215565261724863512460842165916753490629436"); - EXPECT_EQ(sech(Real("360")).toString(), - "9.0160541312134836868594093056048781135886063264031045543166320171424640100585882750111676606707679687798370808229846475098013788288893479045365187439243562588172707510472221597293237365990886510719036721249726917243026017147558624482756185584536093876579417138589896111836329466097327949593815608999431443286434895483252097658897022968306978939693485674151172251112364819206851109443108256063175917164862533282035464946491027808962419554350193283228593523189612433017700351671212631029111311660331076*10^-157"); - EXPECT_EQ(sech(Real("1000000")).toString(), - "6.5936629561771171579378159382154484171228030133167403192941769797906985007591094541101544505266576590003136623166279624437072289948914410518596660796372850144818311771718689218961756235736614332305572015788134843142823987619684063908579723392812450600316769828831818379538015455924132128248931752957164658625567427893359723762484980284103878781196254875345414062804199987764098081657081303453035863381229295149281777943984386777373544544747833870835791847918279021119342276015780078343555344003180895*10^-434295"); - EXPECT_EQ(sech(Real("-1000000")).toString(), - "6.5936629561771171579378159382154484171228030133167403192941769797906985007591094541101544505266576590003136623166279624437072289948914410518596660796372850144818311771718689218961756235736614332305572015788134843142823987619684063908579723392812450600316769828831818379538015455924132128248931752957164658625567427893359723762484980284103878781196254875345414062804199987764098081657081303453035863381229295149281777943984386777373544544747833870835791847918279021119342276015780078343555344003180895*10^-434295"); - - EXPECT_THROW(sech(getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(sech(-getBottom()).toString(), - UndefinedFunctionException); - EXPECT_EQ(sech(1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(sech(-1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(sech(1 + 1 / getBottom()).toString(), - "0.64805427366388539957497735322615032310848931207194202303786533731871759564671283028085478530789289238484741080920067693803371342199608047328527095053204320637710138926219751549816225165048045954767037456642342841785116074316762362109780982148957951547955724736187053107831495505487985321572485483727544183904287647250786507031934414748522969445640178730087299069355083406660792094751146726395612000124233338654264471442651311028781015766133420886738838930728215565261724863512460842165916753490629435"); - EXPECT_EQ(sech(1 - 1 / getBottom()).toString(), - "0.64805427366388539957497735322615032310848931207194202303786533731871759564671283028085478530789289238484741080920067693803371342199608047328527095053204320637710138926219751549816225165048045954767037456642342841785116074316762362109780982148957951547955724736187053107831495505487985321572485483727544183904287647250786507031934414748522969445640178730087299069355083406660792094751146726395612000124233338654264471442651311028781015766133420886738838930728215565261724863512460842165916753490629437"); - EXPECT_EQ(sech(-1 + 1 / getBottom()).toString(), - "0.64805427366388539957497735322615032310848931207194202303786533731871759564671283028085478530789289238484741080920067693803371342199608047328527095053204320637710138926219751549816225165048045954767037456642342841785116074316762362109780982148957951547955724736187053107831495505487985321572485483727544183904287647250786507031934414748522969445640178730087299069355083406660792094751146726395612000124233338654264471442651311028781015766133420886738838930728215565261724863512460842165916753490629437"); - EXPECT_EQ(sech(-1 - 1 / getBottom()).toString(), - "0.64805427366388539957497735322615032310848931207194202303786533731871759564671283028085478530789289238484741080920067693803371342199608047328527095053204320637710138926219751549816225165048045954767037456642342841785116074316762362109780982148957951547955724736187053107831495505487985321572485483727544183904287647250786507031934414748522969445640178730087299069355083406660792094751146726395612000124233338654264471442651311028781015766133420886738838930728215565261724863512460842165916753490629435"); - - EXPECT_THROW(sech(getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(sech(-getTop()).toString(), - UndefinedFunctionException); - EXPECT_EQ(sech(1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(sech(-1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(sech(1 + 1 / getTop()).toString(), - "0.64805427366388539957497735322615032310848931207194202303786533731871759564671283028085478530789289238484741080920067693803371342199608047328527095053204320637710138926219751549816225165048045954767037456642342841785116074316762362109780982148957951547955724736187053107831495505487985321572485483727544183904287647250786507031934414748522969445640178730087299069355083406660792094751146726395612000124233338654264471442651311028781015766133420886738838930728215565261724863512460842165916753490629435"); - EXPECT_EQ(sech(1 - 1 / getTop()).toString(), - "0.64805427366388539957497735322615032310848931207194202303786533731871759564671283028085478530789289238484741080920067693803371342199608047328527095053204320637710138926219751549816225165048045954767037456642342841785116074316762362109780982148957951547955724736187053107831495505487985321572485483727544183904287647250786507031934414748522969445640178730087299069355083406660792094751146726395612000124233338654264471442651311028781015766133420886738838930728215565261724863512460842165916753490629436"); - EXPECT_EQ(sech(-1 + 1 / getTop()).toString(), - "0.64805427366388539957497735322615032310848931207194202303786533731871759564671283028085478530789289238484741080920067693803371342199608047328527095053204320637710138926219751549816225165048045954767037456642342841785116074316762362109780982148957951547955724736187053107831495505487985321572485483727544183904287647250786507031934414748522969445640178730087299069355083406660792094751146726395612000124233338654264471442651311028781015766133420886738838930728215565261724863512460842165916753490629436"); - EXPECT_EQ(sech(-1 - 1 / getTop()).toString(), - "0.64805427366388539957497735322615032310848931207194202303786533731871759564671283028085478530789289238484741080920067693803371342199608047328527095053204320637710138926219751549816225165048045954767037456642342841785116074316762362109780982148957951547955724736187053107831495505487985321572485483727544183904287647250786507031934414748522969445640178730087299069355083406660792094751146726395612000124233338654264471442651311028781015766133420886738838930728215565261724863512460842165916753490629435"); -} - -TEST(RealFunctionsTests, cschTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(csch(Real("1")).toString(), - "0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161075"); - EXPECT_EQ(csch(Real("-1")).toString(), - "-0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161075"); - EXPECT_EQ(csch(Real("125")).toString(), - "1.0332841265675721960505437214715115728551601889626861910405726604708228332416092881854306944989230030460236167836137359397081822921002801470512203174228780621055856609786688437579101831007292377825499274878287336648478287736672235107826213641009163027328639052382154566248395104535246559872642789556752337532973174231774610727790703071181803845915514461183667677762535606054101393902850089254396725865399242781044473195976260786636003301855557383763585055800394487043155974556701151211812188176233042*10^-54"); - EXPECT_EQ(csch(Real("1000000")).toString(), - "6.5936629561771171579378159382154484171228030133167403192941769797906985007591094541101544505266576590003136623166279624437072289948914410518596660796372850144818311771718689218961756235736614332305572015788134843142823987619684063908579723392812450600316769828831818379538015455924132128248931752957164658625567427893359723762484980284103878781196254875345414062804199987764098081657081303453035863381229295149281777943984386777373544544747833870835791847918279021119342276015780078343555344003180895*10^-434295"); - EXPECT_EQ(csch(Real("-1000000")).toString(), - "-6.5936629561771171579378159382154484171228030133167403192941769797906985007591094541101544505266576590003136623166279624437072289948914410518596660796372850144818311771718689218961756235736614332305572015788134843142823987619684063908579723392812450600316769828831818379538015455924132128248931752957164658625567427893359723762484980284103878781196254875345414062804199987764098081657081303453035863381229295149281777943984386777373544544747833870835791847918279021119342276015780078343555344003180895*10^-434295"); - - EXPECT_THROW(csch(Real("0")), - UndefinedFunctionException); - - EXPECT_THROW(csch(getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(csch(-getBottom()).toString(), - UndefinedFunctionException); - EXPECT_EQ(csch(1 / getBottom()).toString(), - "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); - EXPECT_EQ(csch(-1 / getBottom()).toString(), - "-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); - EXPECT_EQ(csch(1 + 1 / getBottom()).toString(), - "0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161073"); - EXPECT_EQ(csch(1 - 1 / getBottom()).toString(), - "0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161077"); - EXPECT_EQ(csch(-1 + 1 / getBottom()).toString(), - "-0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161077"); - EXPECT_EQ(csch(-1 - 1 / getBottom()).toString(), - "-0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161073"); - - EXPECT_THROW(csch(getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(csch(-getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(csch(1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(csch(-1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_EQ(csch(1 + 1 / getTop()).toString(), - "0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161074"); - EXPECT_EQ(csch(1 - 1 / getTop()).toString(), - "0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161075"); - EXPECT_EQ(csch(-1 + 1 / getTop()).toString(), - "-0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161075"); - EXPECT_EQ(csch(-1 - 1 / getTop()).toString(), - "-0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161074"); -} - -TEST(RealFunctionsTests, asinhTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(asinh(Real("0")).toString(), - "0.0"); - EXPECT_EQ(asinh(Real("1")).toString(), - "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957213"); - EXPECT_EQ(asinh(Real("-1")).toString(), - "-0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957213"); - EXPECT_EQ(asinh(Real("10")).toString(), - "2.9982229502979697388465955375964534766070580548773036557344592627530896573521660892245927552391289301685117204184544564003090787358329069604562491320816046506888907288930668063296761113122383771954824827065559549640163465985690170583729712790695028450456699468948151999289646051193291789113485811264166666053093984787849861532060758619536759668386184899755910040265307557384499220067058993213963242831577379376488161983397507367322474941945745330687632550535052193222795026609536297093497594878553644"); - EXPECT_EQ(asinh(Real("-10")).toString(), - "-2.9982229502979697388465955375964534766070580548773036557344592627530896573521660892245927552391289301685117204184544564003090787358329069604562491320816046506888907288930668063296761113122383771954824827065559549640163465985690170583729712790695028450456699468948151999289646051193291789113485811264166666053093984787849861532060758619536759668386184899755910040265307557384499220067058993213963242831577379376488161983397507367322474941945745330687632550535052193222795026609536297093497594878553644"); - - EXPECT_EQ(asinh(getBottom()).toString(), - "1151.4854435107910205683414683366061078882486418235295386452906200946570972677111974895430572940805839184337371831189543587669560432707084787250541422492825598828384841024609317116054220602947216863597395091146246462156623856213461435584473683581161438305136955387987153590331605537885531891816764680447313482115276519127727666401719754440407634104220773569083968491814130462368341894306482997790282028573331750635353457104910553592436200842481954236838942173940623748983936341728324549070070575813421"); - EXPECT_EQ(asinh(-getBottom()).toString(), - "-1151.4854435107910205683414683366061078882486418235295386452906200946570972677111974895430572940805839184337371831189543587669560432707084787250541422492825598828384841024609317116054220602947216863597395091146246462156623856213461435584473683581161438305136955387987153590331605537885531891816764680447313482115276519127727666401719754440407634104220773569083968491814130462368341894306482997790282028573331750635353457104910553592436200842481954236838942173940623748983936341728324549070070575813421"); - EXPECT_EQ(asinh(1 / getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(asinh(-1 / getBottom()).toString(), - "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(asinh(1 + 1 / getBottom()).toString(), - "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957214"); - EXPECT_EQ(asinh(1 - 1 / getBottom()).toString(), - "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957212"); - EXPECT_EQ(asinh(-1 + 1 / getBottom()).toString(), - "-0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957212"); - EXPECT_EQ(asinh(-1 - 1 / getBottom()).toString(), - "-0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957214"); - - EXPECT_EQ(asinh(getTop()).toString(), - "1152.4854438441245539018176589239077860990037756453300192692944639077298609394752946107525932528960239340920235321102525850798980092830320000555096031215066828506052468765296526295333712752885008572272341663841581776375690972457542070930899079323308648685613749345214020341581518739796542753060280950574892886732978215978223220554397586621190650226114565343493816622827928325467853708568759742433820344125690295321140284116420724299741831747169440212977865955687122877079873810781098497093732339145146"); - EXPECT_EQ(asinh(-getTop()).toString(), - "-1152.4854438441245539018176589239077860990037756453300192692944639077298609394752946107525932528960239340920235321102525850798980092830320000555096031215066828506052468765296526295333712752885008572272341663841581776375690972457542070930899079323308648685613749345214020341581518739796542753060280950574892886732978215978223220554397586621190650226114565343493816622827928325467853708568759742433820344125690295321140284116420724299741831747169440212977865955687122877079873810781098497093732339145146"); - EXPECT_THROW(asinh(1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asinh(-1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_EQ(asinh(1 + 1 / getTop()).toString(), - "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957213"); - EXPECT_EQ(asinh(1 - 1 / getTop()).toString(), - "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957212"); - EXPECT_EQ(asinh(-1 + 1 / getTop()).toString(), - "-0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957212"); - EXPECT_EQ(asinh(-1 - 1 / getTop()).toString(), - "-0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957213"); -} - -TEST(RealFunctionsTests, acoshTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(acosh(Real("1")).toString(), - "0.0"); - EXPECT_EQ(acosh(Real("1.5")).toString(), - "0.9624236501192068949955178268487368462703686687713210393220363376803277352164435488240188582454469499944636799165873128225451366474534752455061184837288195083648340144236743004476478749383745504865583860375941580071234535938890915046106908683775305710651298041479938699323751126020424799273586164127199559770199603136515957052986573333022324834276165451855769580521930662264944550298628129970177864352732005133323906421359363515323694614703197207969691509082411264682714009560127897444863052357936009"); - EXPECT_EQ(acosh(Real("2")).toString(), - "1.3169578969248167086250463473079684440269819714675164797684722569204601854164439760742190134501017835564654365656049793198098168621063715327267633457099206769058311287762569581704704373368637119409556504467967320008259374753779128904267720926333444215608442411897668706630346965128936149937499537698028627808731599409811428097663442379476682307349961925278153630369708948389904496288710224816511828830572848189519734408731840366524342889795548865144199047686542941645741789506721185816445558831470023"); - EXPECT_EQ(acosh(Real("10")).toString(), - "2.9932228461263808979126677137741829130836604511809806426851456009774992267097398782806309627071306286046865176881901887028554896814935413690847474111985922493471912906011650028941172974869633641092903806482028247303316780128983728332606064702198928422287172145728944626745052216234707627773357746661996601495403999428221091494818161863753089238550874102387216275936737844716325739316027641823891247889708324367169731889324984924290373939321197822760725086953493673905982459240183481006562811521855309"); - EXPECT_EQ(acosh(Real("10000")).toString(), - "9.9034875500361280361141978881122997233496952946044950260923836567032304913473953953515725690020423830616528288365523258767489061828343586434808328114258581397841702325146629897292350467756349150430346767665607862477177574083345392634284879969502968285783359747240559839678639708801405512480837902804708295990543604809597201948371269987208380244777001464587545463324020220343935621295486955507859950839246805950189125008128131560856033583621613460499389134966397916170999800412590099260076143420325062"); - - EXPECT_THROW(acosh(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(acosh(Real("-1")), - UndefinedFunctionException); - EXPECT_THROW(acosh(Real("0.5")), - UndefinedFunctionException); - EXPECT_THROW(acosh(Real("-0.5")), - UndefinedFunctionException); - - EXPECT_EQ(acosh(getBottom()).toString(), - "1151.4854435107910205683414683366061078882486418235295386452906200946570972677111974895430572940805839184337371831189543587669560432707084787250541422492825598828384841024609317116054220602947216863597395091146246462156623856213461435584473683581161438305136955387987153590331605537885531891816764680447313482115276519127727666401719754440407634104220773569083968491814130462368341894306482997790282028573331750635353457104910553592436200842481954236838942173940623748983936341728324549070070575813421"); - EXPECT_THROW(acosh(-getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(-1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_EQ(acosh(1 + 1 / getBottom()).toString(), - "1.8161133101249768313059767637749226167016555062135541295428599514579399162477525362449841992214659204923416486740342626879990151285206963843627887984484066329176548338000757254648982552487409334526566762732166521636845007859070742231176086199785002494824233671741808993871471604475449814991979005026904466371335432200684754360612792364909810664574323876073450385968843689808751624105899580384533574694605556028984635741348186918197680661361994642285426418712562403143105149802614347742290494321962424*10^-250"); - EXPECT_THROW(acosh(1 - 1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(-1 + 1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(-1 - 1 / getBottom()).toString(), - UndefinedFunctionException); - - EXPECT_EQ(acosh(getTop()).toString(), - "1152.4854438441245539018176589239077860990037756453300192692944639077298609394752946107525932528960239340920235321102525850798980092830320000555096031215066828506052468765296526295333712752885008572272341663841581776375690972457542070930899079323308648685613749345214020341581518739796542753060280950574892886732978215978223220554397586621190650226114565343493816622827928325467853708568759742433820344125690295321140284116420724299741831747169440212977865955687122877079873810781098497093732339145146"); - EXPECT_THROW(acosh(-getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(-1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_EQ(acosh(1 + 1 / getTop()).toString(), - "1.1015282205148344113031315962232882607549581369854598556825953939712541702951560855963926471275061487735103376848102315248597150700630765059387426235333495755483505788503115382724106804445536940510466695827205469185322984760109337103739057002978598795971390260446685983828095271655143299592980169999703367652156688155730814358165398832394569722569002490431507814481217842691057439436763109599092031344149400752025936592695703741466909450253591955614422574626565454002410396637850800605126854091903233*10^-250"); - EXPECT_THROW(acosh(1 - 1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(-1 + 1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(-1 - 1 / getTop()).toString(), - UndefinedFunctionException); -} - -TEST(RealFunctionsTests, atanhTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(atanh(Real("0")).toString(), - "0.0"); - EXPECT_EQ(atanh(Real("0.333")).toString(), - "0.34619863713154247570599098685804826103609094329948378301404880413603328167394351962984431122461634023514290948031983237010653082502383710411969497037700185034288291947812555415915624018289058114167215829473448898016693296117239767068765288453353874546879688588509527472127797230451642236773965637268386840777259731872792797439722710677660848463210316000632738984571681501515219339944295988966181227125287741569589464016162821348393994703181239553059740942030273093670294694522971556318809608720244053"); - EXPECT_EQ(atanh(Real("0.333")).toString(), - "0.34619863713154247570599098685804826103609094329948378301404880413603328167394351962984431122461634023514290948031983237010653082502383710411969497037700185034288291947812555415915624018289058114167215829473448898016693296117239767068765288453353874546879688588509527472127797230451642236773965637268386840777259731872792797439722710677660848463210316000632738984571681501515219339944295988966181227125287741569589464016162821348393994703181239553059740942030273093670294694522971556318809608720244053"); - EXPECT_EQ(atanh(Real("0.5")).toString(), - "0.54930614433405484569762261846126285232374527891137472586734716681874714660930448343680787740686604439398501453297893287118400211296525991052640093538363870530158138459169068358968684942218047995187128515839795576057279595887533567352747008338779011110158512647344878034505326075282143406901815868664928889118349582739606590907451001505191181506112432637409911299554872624544822902673350442298254287422205950942854382374743353980654291470580108306059200070491275719597438444683992471511278657676648427"); - EXPECT_EQ(atanh(Real("-0.5")).toString(), - "-0.54930614433405484569762261846126285232374527891137472586734716681874714660930448343680787740686604439398501453297893287118400211296525991052640093538363870530158138459169068358968684942218047995187128515839795576057279595887533567352747008338779011110158512647344878034505326075282143406901815868664928889118349582739606590907451001505191181506112432637409911299554872624544822902673350442298254287422205950942854382374743353980654291470580108306059200070491275719597438444683992471511278657676648427"); - - EXPECT_THROW(atanh(Real("-1")), - UndefinedFunctionException); - EXPECT_THROW(atanh(Real("1")), - UndefinedFunctionException); - - EXPECT_THROW(atanh(getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(atanh(-getBottom()).toString(), - UndefinedFunctionException); - EXPECT_EQ(atanh(1 / getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(atanh(-1 / getBottom()).toString(), - "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_THROW(atanh(1 + 1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_EQ(atanh(1 - 1 / getBottom()).toString(), - "575.74272175539551028417073416830305394412432091176476932264531004732854863385559874477152864704029195921686859155947717938347802163535423936252707112464127994141924205123046585580271103014736084317986975455731232310783119281067307177922368417905807191525684776939935767951658027689427659459083823402236567410576382595638638332008598772202038170521103867845419842459070652311841709471532414988951410142866658753176767285524552767962181004212409771184194710869703118744919681708641622745350352879067105"); - EXPECT_EQ(atanh(-1 + 1 / getBottom()).toString(), - "-575.74272175539551028417073416830305394412432091176476932264531004732854863385559874477152864704029195921686859155947717938347802163535423936252707112464127994141924205123046585580271103014736084317986975455731232310783119281067307177922368417905807191525684776939935767951658027689427659459083823402236567410576382595638638332008598772202038170521103867845419842459070652311841709471532414988951410142866658753176767285524552767962181004212409771184194710869703118744919681708641622745350352879067105"); - EXPECT_THROW(atanh(-1 - 1 / getBottom()).toString(), - UndefinedFunctionException); - - EXPECT_THROW(atanh(getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(atanh(-getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(atanh(1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(atanh(-1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(atanh(1 + 1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_EQ(atanh(1 - 1 / getTop()).toString(), - "576.24272192206227695090882946195389304950188782266500963464723195386493046973764730537629662644801196704601176605512629253994900464151600002775480156075334142530262343826482631476668563764425042861361708319207908881878454862287710354654495396616543243428068746726070101707907593698982713765301404752874464433664891079891116102771987933105953251130572826717469083114139641627339268542843798712169101720628451476605701420582103621498709158735847201064889329778435614385399369053905492485468661695725731"); - EXPECT_EQ(atanh(-1 + 1 / getTop()).toString(), - "-576.24272192206227695090882946195389304950188782266500963464723195386493046973764730537629662644801196704601176605512629253994900464151600002775480156075334142530262343826482631476668563764425042861361708319207908881878454862287710354654495396616543243428068746726070101707907593698982713765301404752874464433664891079891116102771987933105953251130572826717469083114139641627339268542843798712169101720628451476605701420582103621498709158735847201064889329778435614385399369053905492485468661695725731"); - EXPECT_THROW(atanh(-1 - 1 / getTop()).toString(), - UndefinedFunctionException); -} - -TEST(RealFunctionsTests, acothTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(acoth(Real("1.5")).toString(), - "0.80471895621705018730037966661309381976280067713425886095632394573708949385382888231506693904658980539998315151085778144986200261466233809981680830873185286377608981874859162282674642810117076252863507759680043988869486284409677035638307736561090476397426064641067902986128383614264362023079472408918233566433699921231887979659471192196717672552548752722709737025068299354393369160656528648602032974269191936183137693827278135908075582996545762160368245583893195033793629288938319579191841197521274398"); - EXPECT_EQ(acoth(Real("10")).toString(), - "0.10033534773107558063572655206003894526336286914595913587458952092779251873800938966391159918758530691938783387811113351875978035336737387662484932463327662192265818415695618111535663512460816343078476158604773197655299116256578000302562833475826142160334576231904950939518157606652631377111261024044988605238524378382447243021532641796573671289263060402785620842098304759712947182570962823345398222622071416059967402676280166793797170249061535248316318134853833441271181230470756672448274054859950749"); - EXPECT_EQ(acoth(Real("-10")).toString(), - "-0.10033534773107558063572655206003894526336286914595913587458952092779251873800938966391159918758530691938783387811113351875978035336737387662484932463327662192265818415695618111535663512460816343078476158604773197655299116256578000302562833475826142160334576231904950939518157606652631377111261024044988605238524378382447243021532641796573671289263060402785620842098304759712947182570962823345398222622071416059967402676280166793797170249061535248316318134853833441271181230470756672448274054859950749"); - EXPECT_EQ(acoth(Real("1000000")).toString(), - "1.0000000000003333333333335333333333334761904761905873015873016782106782107551337551338218004218004806239512122391378831007790169926393271392163571860919690829874095283975828022345212989041356330600528686215480517790976833658290967943214330423945771447901567838740949898923463959982926831592832320699731200327474460887158676102648452426732872099468392344630693121604911565633353193154827823840273775285323654539196982943585718028584123194242214521410447558728089475965531459210710507581093455074511807*10^-6"); - EXPECT_EQ(acoth(Real("-1000000")).toString(), - "-1.0000000000003333333333335333333333334761904761905873015873016782106782107551337551338218004218004806239512122391378831007790169926393271392163571860919690829874095283975828022345212989041356330600528686215480517790976833658290967943214330423945771447901567838740949898923463959982926831592832320699731200327474460887158676102648452426732872099468392344630693121604911565633353193154827823840273775285323654539196982943585718028584123194242214521410447558728089475965531459210710507581093455074511807*10^-6"); - - EXPECT_THROW(acoth(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(acoth(Real("1")), - UndefinedFunctionException); - EXPECT_THROW(acoth(Real("-1")), - UndefinedFunctionException); - - EXPECT_EQ(acoth(getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(acoth(-getBottom()).toString(), - "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_THROW(acoth(1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acoth(-1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_EQ(acoth(1 + 1 / getBottom()).toString(), - "575.74272175539551028417073416830305394412432091176476932264531004732854863385559874477152864704029195921686859155947717938347802163535423936252707112464127994141924205123046585580271103014736084317986975455731232310783119281067307177922368417905807191525684776939935767951658027689427659459083823402236567410576382595638638332008598772202038170521103867845419842459070652311841709471532414988951410142866658753176767285524552767962181004212409771184194710869703118744919681708641622745350352879067105"); - EXPECT_THROW(acoth(1 - 1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acoth(-1 + 1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_EQ(acoth(-1 - 1 / getBottom()).toString(), - "-575.74272175539551028417073416830305394412432091176476932264531004732854863385559874477152864704029195921686859155947717938347802163535423936252707112464127994141924205123046585580271103014736084317986975455731232310783119281067307177922368417905807191525684776939935767951658027689427659459083823402236567410576382595638638332008598772202038170521103867845419842459070652311841709471532414988951410142866658753176767285524552767962181004212409771184194710869703118744919681708641622745350352879067105"); - - EXPECT_THROW(acoth(getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acoth(-getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acoth(1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acoth(-1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_EQ(acoth(1 + 1 / getTop()).toString(), - "576.24272192206227695090882946195389304950188782266500963464723195386493046973764730537629662644801196704601176605512629253994900464151600002775480156075334142530262343826482631476668563764425042861361708319207908881878454862287710354654495396616543243428068746726070101707907593698982713765301404752874464433664891079891116102771987933105953251130572826717469083114139641627339268542843798712169101720628451476605701420582103621498709158735847201064889329778435614385399369053905492485468661695725731"); - EXPECT_THROW(acoth(1 - 1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acoth(-1 + 1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_EQ(acoth(-1 - 1 / getTop()).toString(), - "-576.24272192206227695090882946195389304950188782266500963464723195386493046973764730537629662644801196704601176605512629253994900464151600002775480156075334142530262343826482631476668563764425042861361708319207908881878454862287710354654495396616543243428068746726070101707907593698982713765301404752874464433664891079891116102771987933105953251130572826717469083114139641627339268542843798712169101720628451476605701420582103621498709158735847201064889329778435614385399369053905492485468661695725731"); -} - -TEST(RealFunctionsTests, asechTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(asech(Real("1")).toString(), - "0.0"); - EXPECT_EQ(asech(Real("0.3")).toString(), - "1.8738202425274144249769979852084091960595966794746295241858217517040005820158278851534411168211145658177843656484413350930215517691180087245903618033257617151356779496656583081325881056102755332268893719527517388687674565532297951023140595434050640501119683029827193523962603090554562844290616786755042820870552306427318016979538853991240878757931048535120391087062472168992069238168546806195419284235553712458438064751489527450865586998030775688278528233955918991340307831663886599765953189366294701"); - EXPECT_EQ(asech(Real("0.5")).toString(), - "1.3169578969248167086250463473079684440269819714675164797684722569204601854164439760742190134501017835564654365656049793198098168621063715327267633457099206769058311287762569581704704373368637119409556504467967320008259374753779128904267720926333444215608442411897668706630346965128936149937499537698028627808731599409811428097663442379476682307349961925278153630369708948389904496288710224816511828830572848189519734408731840366524342889795548865144199047686542941645741789506721185816445558831470023"); - EXPECT_EQ(asech(Real("0.8")).toString(), - "0.69314718055994530941723212145817656807550013436025525412068000949339362196969471560586332699641868754200148102057068573368552023575813055703267075163507596193072757082837143519030703862389167347112335011536449795523912047517268157493206515552473413952588295045300709532636664265410423915781495204374043038550080194417064167151864471283996817178454695702627163106454615025720740248163777338963855069526066834113727387372292895649354702576265209885969320196505855476470330679365443254763274495125040607"); - - EXPECT_THROW(asech(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(asech(Real("-1")), - UndefinedFunctionException); - - EXPECT_THROW(asech(getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asech(-getBottom()).toString(), - UndefinedFunctionException); - EXPECT_EQ(asech(1 / getBottom()).toString(), - "1151.4854435107910205683414683366061078882486418235295386452906200946570972677111974895430572940805839184337371831189543587669560432707084787250541422492825598828384841024609317116054220602947216863597395091146246462156623856213461435584473683581161438305136955387987153590331605537885531891816764680447313482115276519127727666401719754440407634104220773569083968491814130462368341894306482997790282028573331750635353457104910553592436200842481954236838942173940623748983936341728324549070070575813421"); - EXPECT_THROW(asech(-1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asech(1 + 1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_EQ(asech(1 - 1 / getBottom()).toString(), - "1.8161133101249768313059767637749226167016555062135541295428599514579399162477525362449841992214659204923416486740342626879990151285206963843627887984484066329176548338000757254648982552487409334526566762732166521636845007859070742231176086199785002494824233671741808993871471604475449814991979005026904466371335432200684754360612792364909810664574323876073450385968843689808751624105899580384533574694605556028984635741348186918197680661361994642285426418712562403143105149802614347742290494321962424*10^-250"); - EXPECT_THROW(asech(-1 + 1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asech(-1 - 1 / getBottom()).toString(), - UndefinedFunctionException); - - EXPECT_THROW(asech(getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asech(-getTop()).toString(), - UndefinedFunctionException); - EXPECT_EQ(asech(1 / getTop()).toString(), - "1152.4854438441245539018176589239077860990037756453300192692944639077298609394752946107525932528960239340920235321102525850798980092830320000555096031215066828506052468765296526295333712752885008572272341663841581776375690972457542070930899079323308648685613749345214020341581518739796542753060280950574892886732978215978223220554397586621190650226114565343493816622827928325467853708568759742433820344125690295321140284116420724299741831747169440212977865955687122877079873810781098497093732339145146"); - EXPECT_THROW(asech(-1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asech(1 + 1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_EQ(asech(1 - 1 / getTop()).toString(), - "1.1015282205148344113031315962232882607549581369854598556825953939712541702951560855963926471275061487735103376848102315248597150700630765059387426235333495755483505788503115382724106804445536940510466695827205469185322984760109337103739057002978598795971390260446685983828095271655143299592980169999703367652156688155730814358165398832394569722569002490431507814481217842691057439436763109599092031344149400752025936592695703741466909450253591955614422574626565454002410396637850800605126854091903233*10^-250"); - EXPECT_THROW(asech(-1 + 1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asech(-1 - 1 / getTop()).toString(), - UndefinedFunctionException); -} - -TEST(RealFunctionsTests, acschTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(acsch(Real("1")).toString(), - "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957213"); - EXPECT_EQ(acsch(Real("-1")).toString(), - "-0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957213"); - EXPECT_EQ(acsch(Real("0.1")).toString(), - "2.9982229502979697388465955375964534766070580548773036557344592627530896573521660892245927552391289301685117204184544564003090787358329069604562491320816046506888907288930668063296761113122383771954824827065559549640163465985690170583729712790695028450456699468948151999289646051193291789113485811264166666053093984787849861532060758619536759668386184899755910040265307557384499220067058993213963242831577379376488161983397507367322474941945745330687632550535052193222795026609536297093497594878553644"); - EXPECT_EQ(acsch(Real("-0.1")).toString(), - "-2.9982229502979697388465955375964534766070580548773036557344592627530896573521660892245927552391289301685117204184544564003090787358329069604562491320816046506888907288930668063296761113122383771954824827065559549640163465985690170583729712790695028450456699468948151999289646051193291789113485811264166666053093984787849861532060758619536759668386184899755910040265307557384499220067058993213963242831577379376488161983397507367322474941945745330687632550535052193222795026609536297093497594878553644"); - EXPECT_EQ(acsch(Real("10")).toString(), - "0.099834078899207563327303124704769443267712911708825010742382695651591768393613465106348449276903206188498406124677873226665835008446207400450999534936293675240929453784224661129186765218330354629955675698152652769815825877645487030185349956435110130012981123752137217672920058387798058093768737175840538375257997368850237548539261911564149546535903638541338513727379764043253416619589358627380617415202311544469434044730284747059064635906989915828599615256664129116822263249491427784753934869133607176"); - EXPECT_EQ(acsch(Real("-10")).toString(), - "-0.099834078899207563327303124704769443267712911708825010742382695651591768393613465106348449276903206188498406124677873226665835008446207400450999534936293675240929453784224661129186765218330354629955675698152652769815825877645487030185349956435110130012981123752137217672920058387798058093768737175840538375257997368850237548539261911564149546535903638541338513727379764043253416619589358627380617415202311544469434044730284747059064635906989915828599615256664129116822263249491427784753934869133607176"); - - EXPECT_THROW(acsch(Real("0")), - UndefinedFunctionException); - - EXPECT_EQ(acsch(getBottom()).toString(), - "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(acsch(-getBottom()).toString(), - "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_EQ(acsch(1 / getBottom()).toString(), - "1151.4854435107910205683414683366061078882486418235295386452906200946570972677111974895430572940805839184337371831189543587669560432707084787250541422492825598828384841024609317116054220602947216863597395091146246462156623856213461435584473683581161438305136955387987153590331605537885531891816764680447313482115276519127727666401719754440407634104220773569083968491814130462368341894306482997790282028573331750635353457104910553592436200842481954236838942173940623748983936341728324549070070575813421"); - EXPECT_EQ(acsch(-1 / getBottom()).toString(), - "-1151.4854435107910205683414683366061078882486418235295386452906200946570972677111974895430572940805839184337371831189543587669560432707084787250541422492825598828384841024609317116054220602947216863597395091146246462156623856213461435584473683581161438305136955387987153590331605537885531891816764680447313482115276519127727666401719754440407634104220773569083968491814130462368341894306482997790282028573331750635353457104910553592436200842481954236838942173940623748983936341728324549070070575813421"); - EXPECT_EQ(acsch(1 + 1 / getBottom()).toString(), - "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957212"); - EXPECT_EQ(acsch(1 - 1 / getBottom()).toString(), - "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957214"); - EXPECT_EQ(acsch(-1 + 1 / getBottom()).toString(), - "-0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957214"); - EXPECT_EQ(acsch(-1 - 1 / getBottom()).toString(), - "-0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957212"); - - EXPECT_THROW(acsch(getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acsch(-getTop()).toString(), - UndefinedFunctionException); - EXPECT_EQ(acsch(1 / getTop()).toString(), - "1152.4854438441245539018176589239077860990037756453300192692944639077298609394752946107525932528960239340920235321102525850798980092830320000555096031215066828506052468765296526295333712752885008572272341663841581776375690972457542070930899079323308648685613749345214020341581518739796542753060280950574892886732978215978223220554397586621190650226114565343493816622827928325467853708568759742433820344125690295321140284116420724299741831747169440212977865955687122877079873810781098497093732339145146"); - EXPECT_EQ(acsch(-1 / getTop()).toString(), - "-1152.4854438441245539018176589239077860990037756453300192692944639077298609394752946107525932528960239340920235321102525850798980092830320000555096031215066828506052468765296526295333712752885008572272341663841581776375690972457542070930899079323308648685613749345214020341581518739796542753060280950574892886732978215978223220554397586621190650226114565343493816622827928325467853708568759742433820344125690295321140284116420724299741831747169440212977865955687122877079873810781098497093732339145146"); - EXPECT_EQ(acsch(1 + 1 / getTop()).toString(), - "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957212"); - EXPECT_EQ(acsch(1 - 1 / getTop()).toString(), - "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957213"); - EXPECT_EQ(acsch(-1 + 1 / getTop()).toString(), - "-0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957213"); - EXPECT_EQ(acsch(-1 - 1 / getTop()).toString(), - "-0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957212"); -} - -TEST(RealFunctionsTests, tgammaTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(tgamma(Real("1")).toString(), - "1.0"); - EXPECT_EQ(tgamma(Real("2")).toString(), - "1.0"); - EXPECT_EQ(tgamma(Real("3")).toString(), - "2.0"); - EXPECT_EQ(tgamma(Real("4")).toString(), - "6.0"); - EXPECT_EQ(tgamma(Real("5")).toString(), - "24.0"); - EXPECT_EQ(tgamma(Real("10")).toString(), - "362880.0"); - EXPECT_EQ(tgamma(Real("1000000")).toString(), - "8.2639316883312400623766461031726662911353479789638730451677758855633796110356450844465305113114639733516068042108785885414647469506478361823012109754232995901156417462491737988838926919341417654578323931987280247219893964365444552161533920583519938798941774206240841593987701818807223169252057737128436859815222389311521255279546829742282164292748493887784712443572285950934362117645254493052265841197629905619012120241419002534128319433065076207004051595915117186613844750900755834037427137686877042*10^5565702"); - - EXPECT_EQ(tgamma(Real("0.5")).toString(), - "1.7724538509055160272981674833411451827975494561223871282138077898529112845910321813749506567385446654162268236242825706662361528657244226025250937096027870684620376986531051228499251730289508262289320953792679628001746390153514797205167001901852340185854469744949126403139217755259062164054193325009063984076137334774751534336679897893658518364087954511651617387600590673934317913328098548462481849020546548521956132515616474675150427387610561079961271072100603720444836723652966137080943234988316684"); - EXPECT_EQ(tgamma(Real("1.5")).toString(), - "0.88622692545275801364908374167057259139877472806119356410690389492645564229551609068747532836927233270811341181214128533311807643286221130126254685480139353423101884932655256142496258651447541311446604768963398140008731950767573986025835009509261700929272348724745632015696088776295310820270966625045319920380686673873757671683399489468292591820439772558258086938002953369671589566640492742312409245102732742609780662578082373375752136938052805399806355360503018602224183618264830685404716174941583421"); - EXPECT_EQ(tgamma(Real("1.23345")).toString(), - "0.90997105032312305741807535506003700168381988861711231924267338164564458593112273125696987256899621132303818098137283116421520223319720347086948665785172868831211838452701034020713638268002799809552102939595408319742471656798452664127285521748016037411776449726761460118893057519106421069436424704545012336856748903629746230563710905187654407336803466611082474903581743763894898782277751840392159614983699384269698816070941866389062892918430656836692667152309173180265182848885641358691827669594084204"); - EXPECT_EQ(tgamma(Real("10.888")).toString(), - "2790176.174447460354671258080163376360120906017912181133856325386017527337920813441646902459962249753739973127551260150123098945829193226725763790106059834119482308232269368419601296416661166502225116620576358235256445497552002757230157460108522208731732927654599193624763066064505671846738599497816614189411925902232920735160323231051826704397665105182360454257988924354879880878409127512837530661841849644186879142901369497218377746568415712684711567198117424940558645257842106266774290371839534482"); - EXPECT_EQ(tgamma(Real("-0.5")).toString(), - "-3.5449077018110320545963349666822903655950989122447742564276155797058225691820643627499013134770893308324536472485651413324723057314488452050501874192055741369240753973062102456998503460579016524578641907585359256003492780307029594410334003803704680371708939489898252806278435510518124328108386650018127968152274669549503068673359795787317036728175909023303234775201181347868635826656197096924963698041093097043912265031232949350300854775221122159922542144201207440889673447305932274161886469976633368"); - EXPECT_EQ(tgamma(Real("-1.5")).toString(), - "2.3632718012073547030642233111215269103967326081631828376184103864705483794547095751666008756513928872216357648323767608883148704876325634700334582794703827579493835982041401637999002307052677683052427938390239504002328520204686396273556002535803120247805959659932168537518957007012082885405591100012085312101516446366335379115573197191544691152117272682202156516800787565245757217770798064616642465360728731362608176687488632900200569850147414773281694762800804960593115631537288182774590979984422246"); - EXPECT_EQ(tgamma(Real("-1.23345")).toString(), - "4.1813173753338157686838484929306398465161945343856820450249490692138002199035392838734396409338251323026983705566970911924417832860723529581102283391559584847217302210440220504331321929372879804054828756399944297387879287343693136960164420167639066179690489140150100981131828453782058083685070893198152539225428420854912521832597931104574704313662292981686944758759661685704101299550098921387735170683299236505100398281382536288445474025809803119260386126881570866360966281549865406783345514283330934"); - EXPECT_EQ(tgamma(Real("-10.888")).toString(), - "-3.0005493180448293721869822512345553711440749496581172835311328514510130843563454159410327449904102534962687933580402601136163144286923729599616329109973278889155036400167226010992532533509025591412102006858233580038908845631422707177405401193989133451023586269917939276976357523808049579203927948328610335908936407429428225823028618009800997924455338572712470543931305206282199854307120672911338853112757794177468305728016425719152016898292004791645737323685134147712344090181049164725937814247506367*10^-7"); - - EXPECT_THROW(tgamma(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(tgamma(Real("-1")), - UndefinedFunctionException); - EXPECT_THROW(tgamma(Real("-2")), - UndefinedFunctionException); - EXPECT_THROW(tgamma(Real("-3")), - UndefinedFunctionException); - EXPECT_THROW(tgamma(Real("-32352")), - UndefinedFunctionException); - - EXPECT_THROW(tgamma(Real("1000000000")), - UndefinedFunctionException); - EXPECT_THROW(tgamma(Real("-1000000000")), - UndefinedFunctionException); - - EXPECT_THROW(tgamma(getBottom()), - UndefinedFunctionException); - EXPECT_THROW(tgamma(-getBottom()), - UndefinedFunctionException); - EXPECT_EQ(tgamma(1 / getBottom()).toString(), - "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633532.0"); - EXPECT_EQ(tgamma(-1 / getBottom()).toString(), - "-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); - EXPECT_EQ(tgamma(1 + 1 / getBottom()).toString(), - "0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); - EXPECT_EQ(tgamma(1 - 1 / getBottom()).toString(), - "1.0"); - EXPECT_EQ(tgamma(-1 + 1 / getBottom()).toString(), - "-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); - EXPECT_EQ(tgamma(-1 - 1 / getBottom()).toString(), - "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633532.0"); - - EXPECT_THROW(tgamma(getTop()), - UndefinedFunctionException); - EXPECT_THROW(tgamma(-getTop()).toString(), - UndefinedFunctionException); - EXPECT_EQ(tgamma(1 / getTop()).toString(), - "1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500"); - EXPECT_EQ(tgamma(-1 / getTop()).toString(), - "-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500"); - EXPECT_EQ(tgamma(1 + 1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(tgamma(1 - 1 / getTop()).toString(), - "1.0"); - EXPECT_EQ(tgamma(-1 + 1 / getTop()).toString(), - "-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500"); - EXPECT_EQ(tgamma(-1 - 1 / getTop()).toString(), - "1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500"); -} - -TEST(RealFunctionsTests, getETest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(getE().toString(), - "2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987931"); -} - -TEST(RealFunctionsTests, getPiTest) { - Real::ScopedSetPrecision setPrecision(precision); - - EXPECT_EQ(getPi().toString(), - "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491"); -} diff --git a/tests/src/numbers/RealTests.cpp b/tests/src/numbers/RealTests.cpp deleted file mode 100644 index c9acd2b07..000000000 --- a/tests/src/numbers/RealTests.cpp +++ /dev/null @@ -1,1083 +0,0 @@ -#include - -#include "fintamath/numbers/Real.hpp" - -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/exceptions/UndefinedException.hpp" - -using namespace fintamath; - -TEST(RealTests, constructorTest) { - EXPECT_EQ(Real(), 0); -} - -TEST(RealTests, stringConstructorTest) { - EXPECT_EQ(Real("0").toString(), "0.0"); - EXPECT_EQ(Real("-0").toString(), "-0.0"); - EXPECT_EQ(Real("-93").toString(), "-93.0"); - EXPECT_EQ(Real("-9.3").toString(), "-9.3"); - EXPECT_EQ(Real("0989929039237832000.9302930929333").toString(), "989929039237832000.93"); - EXPECT_EQ(Real(".1").toString(), "0.1"); - EXPECT_EQ(Real("1.").toString(), "1.0"); - EXPECT_EQ(Real("10000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000").toString(), "1.00000000002*10^94"); - EXPECT_EQ(Real("2*10^2").toString(), "200.0"); - EXPECT_EQ(Real("-2*10^2").toString(), "-200.0"); - EXPECT_EQ(Real("2*10^-2").toString(), "0.02"); - EXPECT_EQ(Real("-2*10^-2").toString(), "-0.02"); - EXPECT_EQ(Real("123.456*10^1000").toString(), "1.23456*10^1002"); - EXPECT_EQ(Real("-123.456*10^1000").toString(), "-1.23456*10^1002"); - EXPECT_EQ(Real("123.456*10^-1000").toString(), "1.23456*10^-998"); - EXPECT_EQ(Real("-123.456*10^-1000").toString(), "-1.23456*10^-998"); - EXPECT_EQ(Real("0.123456*10^1000").toString(), "1.23456*10^999"); - EXPECT_EQ(Real("-0.123456*10^1000").toString(), "-1.23456*10^999"); - EXPECT_EQ(Real("0.123456*10^-1000").toString(), "1.23456*10^-1001"); - EXPECT_EQ(Real("-0.123456*10^-1000").toString(), "-1.23456*10^-1001"); - - EXPECT_THROW(Real("--10"), InvalidInputException); - EXPECT_THROW(Real("test"), InvalidInputException); - EXPECT_THROW(Real(""), InvalidInputException); - EXPECT_THROW(Real("+"), InvalidInputException); - EXPECT_THROW(Real("939849.0-0023"), InvalidInputException); - EXPECT_THROW(Real("a"), InvalidInputException); - EXPECT_THROW(Real("a.1"), InvalidInputException); - EXPECT_THROW(Real("1.a"), InvalidInputException); - EXPECT_THROW(Real("1a.1"), InvalidInputException); - EXPECT_THROW(Real("1.1a"), InvalidInputException); - EXPECT_THROW(Real("--10.-1"), InvalidInputException); - EXPECT_THROW(Real("10.-1"), InvalidInputException); - EXPECT_THROW(Real("1-0.1"), InvalidInputException); - EXPECT_THROW(Real("10-.1"), InvalidInputException); - EXPECT_THROW(Real("10.--1"), InvalidInputException); - EXPECT_THROW(Real("."), InvalidInputException); - EXPECT_THROW(Real("1.2.1"), InvalidInputException); - EXPECT_THROW(Real("2*10^2.2"), InvalidInputException); - EXPECT_THROW(Real("0*10^0"), InvalidInputException); - - EXPECT_THROW(Real("10*10^100000000000000000000"), UndefinedException); -} - -TEST(RealTests, rationalConstructorTest) { - EXPECT_EQ(Real(Rational(2, 5)).toString(), "0.4"); - EXPECT_EQ(Real(Rational(-2, 5)).toString(), "-0.4"); - EXPECT_EQ(Real(Rational(30, 10)).toString(), "3.0"); -} - -TEST(RealTests, rationalAssignmentOperatorConstructorTest) { - Real a; - EXPECT_EQ((a = Rational(2, 4)).toString(), "0.5"); - - Real b; - EXPECT_EQ((b = Rational(1, 3)).toString(5), "0.33333"); -} - -TEST(RealTests, integerConstructorTest) { - EXPECT_EQ(Real(Integer(2)).toString(), "2.0"); - EXPECT_EQ(Real(Integer(10)).toString(), "10.0"); -} - -TEST(RealTests, integerAssignmentOperatorTest) { - Real a; - EXPECT_EQ((a = Integer(2)).toString(), "2.0"); - - Real b; - EXPECT_EQ((b = Integer("9182037092803932425434")).toString(), "9.1820370928039324254*10^21"); -} - -TEST(RealTests, intConstructorTest) { - EXPECT_EQ(Real(2).toString(), "2.0"); - EXPECT_EQ(Real(-2).toString(), "-2.0"); -} - -TEST(RealTests, intAssignmentOperatorTest) { - Real a; - EXPECT_EQ((a = 2).toString(), "2.0"); -} - -TEST(RealTests, plusAssignmentOperatorTest) { - EXPECT_EQ((Real("0.66") += Real("0.33")).toString(), "0.99"); - EXPECT_EQ((Real("-73.85") += Real("2.55")).toString(), "-71.3"); - EXPECT_EQ((Real("73.8") += Real("2.5")).toString(), "76.3"); - EXPECT_EQ((Real("-73.8") += Real("-2.5")).toString(), "-76.3"); - - EXPECT_EQ((Real("0") += Real("-0")).toString(), "-0.0"); - EXPECT_EQ((Real("-0") += Real("0")).toString(), "-0.0"); - EXPECT_EQ((Real("-0") += -Real("-0")).toString(), "-0.0"); -} - -TEST(RealTests, rationalPlusAssignmentOperatorTest) { - EXPECT_EQ((Real("0.66") += Rational(33, 100)).toString(), "0.99"); - EXPECT_EQ((Real("-73.85") += Rational(51, 20)).toString(), "-71.3"); - EXPECT_EQ((Real("73.8") += Rational(5, 2)).toString(), "76.3"); - EXPECT_EQ((Real("-73.8") += Rational(-5, 2)).toString(), "-76.3"); -} - -TEST(RealTests, integerPlusAssignmentOperatorTest) { - EXPECT_EQ((Real(-18) += Integer(2)).toString(), "-16.0"); - EXPECT_EQ((Real(1009) += Integer(4938493849)).toString(), "4938494858.0"); - EXPECT_EQ((Real(6) += Integer(660)).toString(), "666.0"); - - EXPECT_EQ((Real("0.66") += Integer(6)).toString(), "6.66"); - EXPECT_EQ((Real("-73.85") += Integer(5)).toString(), "-68.85"); - EXPECT_EQ((Real("73.8") += Integer(5)).toString(), "78.8"); - EXPECT_EQ((Real("-73.8") += Integer(-5)).toString(), "-78.8"); -} - -TEST(RealTests, intPlusAssignmentOperatorTest) { - EXPECT_EQ((Real("0.66") += 1).toString(), "1.66"); - EXPECT_EQ((Real("-73.85") += 2).toString(), "-71.85"); - EXPECT_EQ((Real("73.8") += -2).toString(), "71.8"); - EXPECT_EQ((Real("-73.8") += -2).toString(), "-75.8"); -} - -TEST(RealTests, plusOperatorTest) { - EXPECT_EQ((Real("0.66") + Real("0.33")).toString(), "0.99"); - EXPECT_EQ((Real("-73.85") + Real("2.55")).toString(), "-71.3"); - EXPECT_EQ((Real("73.8") + Real("2.5")).toString(), "76.3"); - EXPECT_EQ((Real("-73.8") + Real("-2.5")).toString(), "-76.3"); -} - -TEST(RealTests, rationalPlusOperatorTest) { - EXPECT_EQ((Real("0.66") + Rational(33, 100)).toString(), "0.99"); - EXPECT_EQ((Real("-73.85") + Rational(51, 20)).toString(), "-71.3"); - EXPECT_EQ((Real("73.8") + Rational(5, 2)).toString(), "76.3"); - EXPECT_EQ((Real("-73.8") + Rational(-5, 2)).toString(), "-76.3"); -} - -TEST(RealTests, integerPlusOperatorTest) { - EXPECT_EQ((Real(-18) + Integer(2)).toString(), "-16.0"); - EXPECT_EQ((Real(1009) + Integer(4938493849)).toString(), "4938494858.0"); - EXPECT_EQ((Real(6) + Integer(660)).toString(), "666.0"); - - EXPECT_EQ((Real("0.66") + Integer(6)).toString(), "6.66"); - EXPECT_EQ((Real("-73.85") + Integer(5)).toString(), "-68.85"); - EXPECT_EQ((Real("73.8") + Integer(5)).toString(), "78.8"); - EXPECT_EQ((Real("-73.8") + Integer(-5)).toString(), "-78.8"); -} - -TEST(RealTests, intPlusOperatorTest) { - EXPECT_EQ((Real("0.66") + 1).toString(), "1.66"); - EXPECT_EQ((Real("-73.85") + 2).toString(), "-71.85"); - EXPECT_EQ((Real("73.8") + -2).toString(), "71.8"); - EXPECT_EQ((Real("-73.8") + -2).toString(), "-75.8"); -} - -TEST(RealTests, rationalFriendPlusOperatorTest) { - EXPECT_EQ((Rational(33, 100) + Real("0.66")).toString(), "0.99"); - EXPECT_EQ((Rational(51, 20) + Real("-73.85")).toString(), "-71.3"); - EXPECT_EQ((Rational(5, 2) + Real("73.8")).toString(), "76.3"); - EXPECT_EQ((Rational(-5, 2) + Real("-73.8")).toString(), "-76.3"); -} - -TEST(RealTests, integerFriendPlusOperatorTest) { - EXPECT_EQ((Integer(2) + Real(-18)).toString(), "-16.0"); - EXPECT_EQ((Integer(4938493849) + Real(1009)).toString(), "4938494858.0"); - EXPECT_EQ((Integer(660) + Real(6)).toString(), "666.0"); - - EXPECT_EQ((Integer(6) + Real("0.66")).toString(), "6.66"); - EXPECT_EQ((Integer(5) + Real("-73.85")).toString(), "-68.85"); - EXPECT_EQ((Integer(5) + Real("73.8")).toString(), "78.8"); - EXPECT_EQ((Integer(-5) + Real("-73.8")).toString(), "-78.8"); -} - -TEST(RealTests, intFriendPlusOperatorTest) { - EXPECT_EQ((1 + Real("0.66")).toString(), "1.66"); - EXPECT_EQ((2 + Real("-73.85")).toString(), "-71.85"); - EXPECT_EQ((-2 + Real("73.8")).toString(), "71.8"); - EXPECT_EQ((-2 + Real("-73.8")).toString(), "-75.8"); -} - -TEST(RealTests, minusAssignmentOperatorTest) { - EXPECT_EQ((Real("0.66") -= Real("0.22")).toString(), "0.44"); - EXPECT_EQ((Real("-73.85") -= Real("2.55")).toString(), "-76.4"); - EXPECT_EQ((Real("73.8") -= Real("2.5")).toString(), "71.3"); - EXPECT_EQ((Real("-73.8") -= Real("-2.5")).toString(), "-71.3"); - - EXPECT_EQ((Real("0") -= Real("0")).toString(), "-0.0"); - EXPECT_EQ((Real("-0") -= Real("-0")).toString(), "-0.0"); - EXPECT_EQ((Real("-0") -= -Real("0")).toString(), "-0.0"); -} - -TEST(RealTests, rationalMinusAssignmentOperatorTest) { - EXPECT_EQ((Real("0.66") -= Rational(22, 100)).toString(), "0.44"); - EXPECT_EQ((Real("-73.85") -= Rational(51, 20)).toString(), "-76.4"); - EXPECT_EQ((Real("73.8") -= Rational(5, 2)).toString(), "71.3"); - EXPECT_EQ((Real("-73.8") -= Rational(-5, 2)).toString(), "-71.3"); -} - -TEST(RealTests, integerMinusAssignmentOperatorTest) { - EXPECT_EQ((Real(-20) -= Integer(2)).toString(), "-22.0"); - EXPECT_EQ((Real(4938493849) -= Integer(1009)).toString(), "4938492840.0"); - EXPECT_EQ((Real(6) -= Integer(666)).toString(), "-660.0"); - - EXPECT_EQ((Real("6.66") -= Integer(6)).toString(), "0.66"); - EXPECT_EQ((Real("-73.85") -= Integer(5)).toString(), "-78.85"); - EXPECT_EQ((Real("73.8") -= Integer(5)).toString(), "68.8"); - EXPECT_EQ((Real("-73.8") -= Integer(-5)).toString(), "-68.8"); -} - -TEST(RealTests, intMinusAssignmentOperatorTest) { - EXPECT_EQ((Real("0.66") -= 1).toString(), "-0.34"); - EXPECT_EQ((Real("-73.85") -= 2).toString(), "-75.85"); - EXPECT_EQ((Real("73.8") -= -2).toString(), "75.8"); - EXPECT_EQ((Real("-73.8") -= -2).toString(), "-71.8"); -} - -TEST(RealTests, minusOperatorTest) { - EXPECT_EQ((Real("0.66") - Real("0.22")).toString(), "0.44"); - EXPECT_EQ((Real("-73.85") - Real("2.55")).toString(), "-76.4"); - EXPECT_EQ((Real("73.8") - Real("2.5")).toString(), "71.3"); - EXPECT_EQ((Real("-73.8") - Real("-2.5")).toString(), "-71.3"); -} - -TEST(RealTests, rationalMinusOperatorTest) { - EXPECT_EQ((Real("0.66") - Rational(22, 100)).toString(), "0.44"); - EXPECT_EQ((Real("-73.85") - Rational(51, 20)).toString(), "-76.4"); - EXPECT_EQ((Real("73.8") - Rational(5, 2)).toString(), "71.3"); - EXPECT_EQ((Real("-73.8") - Rational(-5, 2)).toString(), "-71.3"); -} - -TEST(RealTests, integerMinusOperatorTest) { - EXPECT_EQ((Real(-20) - Integer(2)).toString(), "-22.0"); - EXPECT_EQ((Real(4938493849) - Integer(1009)).toString(), "4938492840.0"); - EXPECT_EQ((Real(6) - Integer(666)).toString(), "-660.0"); - - EXPECT_EQ((Real("6.66") - Integer(6)).toString(), "0.66"); - EXPECT_EQ((Real("-73.85") - Integer(5)).toString(), "-78.85"); - EXPECT_EQ((Real("73.8") - Integer(5)).toString(), "68.8"); - EXPECT_EQ((Real("-73.8") - Integer(-5)).toString(), "-68.8"); -} - -TEST(RealTests, intMinusOperatorTest) { - EXPECT_EQ((Real("0.66") - 1).toString(), "-0.34"); - EXPECT_EQ((Real("-73.85") - 2).toString(), "-75.85"); - EXPECT_EQ((Real("73.8") - -2).toString(), "75.8"); - EXPECT_EQ((Real("-73.8") - -2).toString(), "-71.8"); -} - -TEST(RealTests, rationalFriendMinusOperatorTest) { - EXPECT_EQ((Rational(22, 100) - Real("0.66")).toString(), "-0.44"); - EXPECT_EQ((Rational(51, 20) - Real("-73.85")).toString(), "76.4"); - EXPECT_EQ((Rational(5, 2) - Real("73.8")).toString(), "-71.3"); - EXPECT_EQ((Rational(-5, 2) - Real("-73.8")).toString(), "71.3"); -} - -TEST(RealTests, integerFriendMinusOperatorTest) { - EXPECT_EQ((Integer(2) - Real(-20)).toString(), "22.0"); - EXPECT_EQ((Integer(1009) - Real(4938493849)).toString(), "-4938492840.0"); - EXPECT_EQ((Integer(666) - Real(6)).toString(), "660.0"); - - EXPECT_EQ((Integer(6) - Real("6.66")).toString(), "-0.66"); - EXPECT_EQ((Integer(5) - Real("-73.85")).toString(), "78.85"); - EXPECT_EQ((Integer(5) - Real("73.8")).toString(), "-68.8"); - EXPECT_EQ((Integer(-5) - Real("-73.8")).toString(), "68.8"); -} - -TEST(RealTests, intFriendMinusOperatorTest) { - EXPECT_EQ((1 - Real("0.66")).toString(), "0.34"); - EXPECT_EQ((2 - Real("-73.85")).toString(), "75.85"); - EXPECT_EQ((-2 - Real("73.8")).toString(), "-75.8"); - EXPECT_EQ((-2 - Real("-73.8")).toString(), "71.8"); -} - -TEST(RealTests, multiplyAssignmentOperatorTest) { - EXPECT_EQ((Real(5) *= Real(2)).toString(), "10.0"); - EXPECT_EQ((Real("2.5") *= Real("-1.1")).toString(), "-2.75"); - EXPECT_EQ((Real("-2.5") *= Real("1.1")).toString(), "-2.75"); - EXPECT_EQ((Real("-2.05") *= Real("-1.1")).toString(), "2.255"); - - EXPECT_EQ((Real("0") *= Real("-2")).toString(), "-0.0"); - EXPECT_EQ((Real("-0") *= Real("2")).toString(), "-0.0"); - EXPECT_EQ((Real("-0") *= Real("-2")).toString(), "0.0"); - EXPECT_EQ((Real("-2") *= Real("0")).toString(), "-0.0"); - EXPECT_EQ((Real("2") *= Real("-0")).toString(), "-0.0"); - EXPECT_EQ((Real("-2") *= Real("-0")).toString(), "0.0"); - EXPECT_EQ((Real("0") *= Real("-0")).toString(), "-0.0"); - EXPECT_EQ((Real("-0") *= Real("0")).toString(), "-0.0"); - EXPECT_EQ((Real("-0") *= Real("-0")).toString(), "0.0"); -} - -TEST(RealTests, rationalMultiplyAssignmentOperatorTest) { - EXPECT_EQ((Real(5) *= Rational(5, 2)).toString(), "12.5"); - EXPECT_EQ((Real("-2.05") *= Rational(-11, 10)).toString(), "2.255"); - EXPECT_EQ((Real("2.5") *= Rational(-11, 10)).toString(), "-2.75"); -} - -TEST(RealTests, integerMultiplyAssignmentOperatorTest) { - EXPECT_EQ((Real(5) *= Integer(2)).toString(), "10.0"); - EXPECT_EQ((Real(5) *= Integer(-2)).toString(), "-10.0"); - EXPECT_EQ((Real("-2.05") *= Integer(-11)).toString(), "22.55"); - EXPECT_EQ((Real("2.5") *= Integer(-11)).toString(), "-27.5"); -} - -TEST(RealTests, intMultiplyAssignmentOperatorTest) { - EXPECT_EQ((Real("0.66") *= 3).toString(), "1.98"); - EXPECT_EQ((Real("-73.85") *= 3).toString(), "-221.55"); - EXPECT_EQ((Real("73.8") *= -71).toString(), "-5239.8"); - EXPECT_EQ((Real("-73.8") *= -71).toString(), "5239.8"); -} - -TEST(RealTests, multiplyOperatorTest) { - EXPECT_EQ((Real(5) * Real(2)).toString(), "10.0"); - EXPECT_EQ((Real("-2.05") * Real("-1.1")).toString(), "2.255"); - EXPECT_EQ((Real("2.5") * Real("-1.1")).toString(), "-2.75"); -} - -TEST(RealTests, rationalMultiplyOperatorTest) { - EXPECT_EQ((Real(5) * Rational(5, 2)).toString(), "12.5"); - EXPECT_EQ((Real("-2.05") * Rational(-11, 10)).toString(), "2.255"); - EXPECT_EQ((Real("2.5") * Rational(-11, 10)).toString(), "-2.75"); -} - -TEST(RealTests, integerMultiplyOperatorTest) { - EXPECT_EQ((Real(5) * Integer(2)).toString(), "10.0"); - EXPECT_EQ((Real(5) * Integer(-2)).toString(), "-10.0"); - EXPECT_EQ((Real("-2.05") * Integer(-11)).toString(), "22.55"); - EXPECT_EQ((Real("2.5") * Integer(-11)).toString(), "-27.5"); -} - -TEST(RealTests, intMultiplyOperatorTest) { - EXPECT_EQ((Real("0.66") * 3).toString(), "1.98"); - EXPECT_EQ((Real("-73.85") * 3).toString(), "-221.55"); - EXPECT_EQ((Real("73.8") * -71).toString(), "-5239.8"); - EXPECT_EQ((Real("-73.8") * -71).toString(), "5239.8"); -} - -TEST(RealTests, rationalFriendMultiplyOperatorTest) { - EXPECT_EQ((Rational(5, 2) * Real(5)).toString(), "12.5"); - EXPECT_EQ((Rational(-11, 10) * Real("-2.05")).toString(), "2.255"); - EXPECT_EQ((Rational(-11, 10) * Real("2.5")).toString(), "-2.75"); -} - -TEST(RealTests, integerFriendMultiplyOperatorTest) { - EXPECT_EQ((Integer(2) * Real(5)).toString(), "10.0"); - EXPECT_EQ((Integer(-2) * Real(5)).toString(), "-10.0"); - EXPECT_EQ((Integer(-11) * Real("-2.05")).toString(), "22.55"); - EXPECT_EQ((Integer(-11) * Real("2.5")).toString(), "-27.5"); -} - -TEST(RealTests, intFriendMultiplyOperatorTest) { - EXPECT_EQ((3 * Real("0.66")).toString(), "1.98"); - EXPECT_EQ((3 * Real("-73.85")).toString(), "-221.55"); - EXPECT_EQ((-71 * Real("73.8")).toString(), "-5239.8"); - EXPECT_EQ((-71 * Real("-73.8")).toString(), "5239.8"); -} - -TEST(RealTests, divideAssignmentOperatorTest) { - EXPECT_EQ((Real(10) /= Real(2)).toString(), "5.0"); - EXPECT_EQ((Real("2.255") /= Real("-1.1")).toString(), "-2.05"); - EXPECT_EQ((Real("-12.1") /= Real("1.1")).toString(), "-11.0"); - EXPECT_EQ((Real("-11") /= Real("-3")).toString(5), "3.6667"); - - EXPECT_EQ(Real("0") /= Real("-2"), Real("-0.0")); - EXPECT_EQ(Real("-0") /= Real("2"), Real("-0.0")); - EXPECT_EQ(Real("-0") /= Real("-2"), Real("0.0")); -} - -TEST(RealTests, rationalDivideAssignmentOperatorTest) { - EXPECT_EQ((Real(5) /= Rational(2, 5)).toString(), "12.5"); - EXPECT_EQ((Real("-2.255") /= Rational(-11, 10)).toString(), "2.05"); - EXPECT_EQ((Real("12.1") /= Rational(-11, 10)).toString(), "-11.0"); -} - -TEST(RealTests, integerDivideAssignmentOperatorTest) { - EXPECT_EQ((Real(10) /= Integer(2)).toString(), "5.0"); - EXPECT_EQ((Real(10) /= Integer(-2)).toString(), "-5.0"); - EXPECT_EQ((Real("22.5") /= Integer(-11)).toString(5), "-2.0455"); - EXPECT_EQ((Real("-27.5") /= Integer(-11)).toString(), "2.5"); -} - -TEST(RealTests, intDivideAssignmentOperatorTest) { - EXPECT_EQ((Real("0.66") /= 3).toString(), "0.22"); - EXPECT_EQ((Real("-73.85") /= 3).toString(5), "-24.617"); - EXPECT_EQ((Real("73.8") /= -71).toString(5), "-1.0394"); - EXPECT_EQ((Real("-73.8") /= -71).toString(5), "1.0394"); -} - -TEST(RealTests, divideOperatorTest) { - EXPECT_EQ((Real(10) / Real(2)).toString(), "5.0"); - EXPECT_EQ((Real("-2.255") / Real("-1.1")).toString(), "2.05"); - EXPECT_EQ((Real("12.1") / Real("-1.1")).toString(), "-11.0"); -} - -TEST(RealTests, rationalDivideOperatorTest) { - EXPECT_EQ((Real(5) / Rational(2, 5)).toString(), "12.5"); - EXPECT_EQ((Real("-2.255") / Rational(-11, 10)).toString(), "2.05"); - EXPECT_EQ((Real("12.1") / Rational(-11, 10)).toString(), "-11.0"); -} - -TEST(RealTests, integerDivideOperatorTest) { - EXPECT_EQ((Real(10) / Integer(2)).toString(), "5.0"); - EXPECT_EQ((Real(10) / Integer(-2)).toString(), "-5.0"); - EXPECT_EQ((Real("22.5") / Integer(-11)).toString(5), "-2.0455"); - EXPECT_EQ((Real("-27.5") / Integer(-11)).toString(), "2.5"); -} - -TEST(RealTests, intDivideOperatorTest) { - EXPECT_EQ((Real("0.66") / 3).toString(), "0.22"); - EXPECT_EQ((Real("-73.85") / 3).toString(5), "-24.617"); - EXPECT_EQ((Real("73.8") / -71).toString(5), "-1.0394"); - EXPECT_EQ((Real("-73.8") / -71).toString(5), "1.0394"); -} - -TEST(RealTests, rationalFriendDivideOperatorTest) { - EXPECT_EQ((Rational(5, 2) / Real(5)).toString(), "0.5"); - EXPECT_EQ((Rational(-11, 10) / Real("-2.5")).toString(), "0.44"); - EXPECT_EQ((Rational(-11, 10) / Real("0.1")).toString(), "-11.0"); -} - -TEST(RealTests, integerFriendDivideOperatorTest) { - EXPECT_EQ((Integer(10) / Real(2)).toString(), "5.0"); - EXPECT_EQ((Integer(10) / Real(-2)).toString(), "-5.0"); - EXPECT_EQ((Integer(-6) / Real("1.6")).toString(), "-3.75"); - EXPECT_EQ((Integer(-6) / Real("-1.6")).toString(), "3.75"); -} - -TEST(RealTests, intFriendDivideOperatorTest) { - EXPECT_EQ((3 / Real("0.66")).toString(5), "4.5455"); - EXPECT_EQ((3 / Real("-73.85")).toString(5), "-0.040623"); - EXPECT_EQ((-71 / Real("73.8")).toString(5), "-0.96206"); - EXPECT_EQ((-71 / Real("-73.8")).toString(5), "0.96206"); -} - -TEST(RealTests, unaryPlusOperatorTest) { - EXPECT_EQ((+Real(-5)).toString(), "-5.0"); - EXPECT_EQ((+Real(5)).toString(), "5.0"); - - EXPECT_EQ((+Real("0")).toString(), "0.0"); - EXPECT_EQ((+Real("-0")).toString(), "-0.0"); -} - -TEST(RealTests, unaryMinusOperatorTest) { - EXPECT_EQ((-Real(5)).toString(), "-5.0"); - EXPECT_EQ((-Real(-5)).toString(), "5.0"); - - EXPECT_EQ((-Real("0")).toString(), "-0.0"); - EXPECT_EQ((-Real("-0")).toString(), "0.0"); -} - -TEST(RealTests, equalOperatorTest) { - EXPECT_TRUE(Real("0.5") == Real("0.5")); - EXPECT_TRUE(Real(-5) == Real(-5)); - EXPECT_TRUE(Real("5.0") == Real(5)); - - EXPECT_FALSE(Real("0.5") == Real("1.5")); - EXPECT_FALSE(Real("-0.5") == Real("0.5")); - - EXPECT_TRUE(Real("-0") == Real("-0")); - EXPECT_FALSE(Real("-0") == Real("0")); - EXPECT_FALSE(Real("0") == Real("-0")); -} - -TEST(RealTests, rationalEqualOperatorTest) { - EXPECT_TRUE(Real("0.5") == Rational(1, 2)); - EXPECT_TRUE(Real(-5) == Rational(10, -2)); - - EXPECT_FALSE(Real("0.5") == Rational(2, 1)); - EXPECT_FALSE(Real("-0.5") == Rational(1, 2)); -} - -TEST(RealTests, integerEqualOperatorTest) { - EXPECT_TRUE(Real(500) == Integer(500)); - EXPECT_TRUE(Real("5.0") == Integer(5)); - EXPECT_TRUE(Real("-5.0") == Integer(-5)); - - EXPECT_FALSE(Real("0.5") == Integer(5)); - EXPECT_FALSE(Real("-5") == Integer(5)); -} - -TEST(RealTests, intEqualOperatorTest) { - EXPECT_TRUE(Real("2") == 2); - EXPECT_TRUE(Real("-2") == -2); - - EXPECT_FALSE(Real("2.1") == 2); - EXPECT_FALSE(Real("-2") == 2); -} - -TEST(RealTests, rationalFriendEqualOperatorTest) { - EXPECT_TRUE(Rational(1, 2) == Real("0.5")); - EXPECT_TRUE(Rational(10, -2) == Real(-5)); - - EXPECT_FALSE(Rational(2, 1) == Real("0.5")); - EXPECT_FALSE(Rational(1, 2) == Real("-0.5")); -} - -TEST(RealTests, integerFriendEqualOperatorTest) { - EXPECT_TRUE(Integer(500) == Real(500)); - EXPECT_TRUE(Integer(5) == Real("5.0")); - EXPECT_TRUE(Integer(-5) == Real("-5")); - - EXPECT_FALSE(Integer(5) == Real("0.5")); - EXPECT_FALSE(Integer(5) == Real("-5")); -} - -TEST(RealTests, intFriendEqualOperatorTest) { - EXPECT_TRUE(2 == Real("2")); - EXPECT_TRUE(-2 == Real("-2")); - - EXPECT_FALSE(2 == Real("2.1")); - EXPECT_FALSE(2 == Real("-2")); -} - -TEST(RealTests, notEqualOperatorTest) { - EXPECT_TRUE(Real("0.5") != Real("1.5")); - EXPECT_TRUE(Real("-0.5") != Real("0.5")); - - EXPECT_FALSE(Real("0.5") != Real("0.5")); - EXPECT_FALSE(Real(-5) != Real(-5)); - EXPECT_FALSE(Real("5.0") != Real(5)); - - EXPECT_FALSE(Real("-0") != Real("-0")); - EXPECT_TRUE(Real("-0") != Real("0")); - EXPECT_TRUE(Real("0") != Real("-0")); -} - -TEST(RealTests, rationalNotEqualOperatorTest) { - EXPECT_TRUE(Real("0.5") != Rational(2, 1)); - EXPECT_TRUE(Real("-0.5") != Rational(1, 2)); - - EXPECT_FALSE(Real("0.5") != Rational(1, 2)); - EXPECT_FALSE(Real(-5) != Rational(10, -2)); -} - -TEST(RealTests, integerNotEqualOperatorTest) { - EXPECT_TRUE(Real("0.5") != Integer(5)); - EXPECT_TRUE(Real("-5") != Integer(5)); - - EXPECT_FALSE(Real(500) != Integer(500)); - EXPECT_FALSE(Real("5.0") != Integer(5)); - EXPECT_FALSE(Real("-5.0") != Integer(-5)); -} - -TEST(RealTests, intNotEqualOperatorTest) { - EXPECT_TRUE(Real("2.1") != 2); - EXPECT_TRUE(Real("-2") != 2); - - EXPECT_FALSE(Real("2") != 2); - EXPECT_FALSE(Real("-2") != -2); -} - -TEST(RealTests, rationalFriendNotEqualOperatorTest) { - EXPECT_TRUE(Rational(2, 1) != Real("0.5")); - EXPECT_TRUE(Rational(1, 2) != Real("-0.5")); - - EXPECT_FALSE(Rational(1, 2) != Real("0.5")); - EXPECT_FALSE(Rational(10, -2) != Real(-5)); -} - -TEST(RealTests, integerFriendNotEqualOperatorTest) { - EXPECT_TRUE(Integer(5) != Real("0.5")); - EXPECT_TRUE(Integer(5) != Real("-5")); - - EXPECT_FALSE(Integer(500) != Real(500)); - EXPECT_FALSE(Integer(5) != Real("5.0")); - EXPECT_FALSE(Integer(-5) != Real("-5")); -} - -TEST(RealTests, intFriendNotEqualOperatorTest) { - EXPECT_TRUE(2 != Real("2.1")); - EXPECT_TRUE(2 != Real("-2")); - - EXPECT_FALSE(2 != Real("2")); - EXPECT_FALSE(-2 != Real("-2")); -} - -TEST(RealTests, lessOperatorTest) { - EXPECT_TRUE(Real(5) < Real(10)); - - EXPECT_FALSE(Real("5.1") < Real("5.1")); - EXPECT_FALSE(Real(5) < Real(-5)); - - EXPECT_FALSE(Real("-0") < Real("-0")); - EXPECT_TRUE(Real("-0") < Real("0")); - EXPECT_FALSE(Real("0") < Real("-0")); -} - -TEST(RealTests, rationalLessOperatorTest) { - EXPECT_TRUE(Real(5) < Rational(51, 10)); - - EXPECT_FALSE(Real("5.1") < Rational(51, 10)); - EXPECT_FALSE(Real(5) < Rational(50, -10)); -} - -TEST(RealTests, integerLessOperatorTest) { - EXPECT_TRUE(Real(5) < Integer(10)); - EXPECT_TRUE(Real(-5) < Integer(5)); - - EXPECT_FALSE(Real("5.1") < Integer(5)); - EXPECT_FALSE(Real(5) < Integer(-5)); -} - -TEST(RealTests, intLessOperatorTest) { - EXPECT_TRUE(Real("-2") < 2); - - EXPECT_FALSE(Real("2") < 2); - EXPECT_FALSE(Real("-2") < -2); - EXPECT_FALSE(Real("2.1") < 2); -} - -TEST(RealTests, rationalFriendLessOperatorTest) { - EXPECT_TRUE(Rational(49, 10) < Real(5)); - - EXPECT_FALSE(Rational(51, 10) < Real("5.1")); - EXPECT_FALSE(Rational(50, 10) < Real(-5)); -} - -TEST(RealTests, integerFriendLessOperatorTest) { - EXPECT_TRUE(Integer(4) < Real(5)); - EXPECT_TRUE(Integer(-5) < Real(5)); - - EXPECT_FALSE(Integer(6) < Real("6.0")); - EXPECT_FALSE(Integer(5) < Real(-5)); -} - -TEST(RealTests, intFriendLessOperatorTest) { - EXPECT_TRUE(2 < Real("2.1")); - - EXPECT_FALSE(2 < Real("2")); - EXPECT_FALSE(-2 < Real("-2")); - EXPECT_FALSE(2 < Real("-2")); -} - -TEST(RealTests, moreOperatorTest) { - EXPECT_TRUE(Real(50) > Real(10)); - - EXPECT_FALSE(Real("5.1") > Real("5.1")); - EXPECT_FALSE(Real(-5) > Real(5)); - - EXPECT_FALSE(Real("-0") > Real("-0")); - EXPECT_FALSE(Real("-0") > Real("0")); - EXPECT_TRUE(Real("0") > Real("-0")); -} - -TEST(RealTests, rationalMoreOperatorTest) { - EXPECT_TRUE(Real(50) > Rational(50, 10)); - - EXPECT_FALSE(Real("5.1") > Rational(51, 10)); - EXPECT_FALSE(Real("-5.1") > Rational(51, 10)); -} - -TEST(RealTests, integerMoreOperatorTest) { - EXPECT_TRUE(Real(50) > Integer(10)); - EXPECT_TRUE(Real(50) > Integer(-50)); - - EXPECT_FALSE(Real("5.0") > Integer(5)); - EXPECT_FALSE(Real(-5) > Integer(5)); -} - -TEST(RealTests, intMoreOperatorTest) { - EXPECT_TRUE(Real("2.1") > 2); - - EXPECT_FALSE(Real("2") > 2); - EXPECT_FALSE(Real("-2") > -2); - EXPECT_FALSE(Real("-2") > 2); -} - -TEST(RealTests, rationalFriendMoreOperatorTest) { - EXPECT_TRUE(Rational(50, 10) > Real(4)); - - EXPECT_FALSE(Rational(50, 10) > Real(5)); - EXPECT_FALSE(Rational(50, -10) > Real("5.0")); -} - -TEST(RealTests, integerFriendMoreOperatorTest) { - EXPECT_TRUE(Integer(5) > Real("4.9")); - EXPECT_TRUE(Integer(5) > Real(-5)); - - EXPECT_FALSE(Integer(5) > Real(5)); - EXPECT_FALSE(Integer(-5) > Real("5.0")); -} - -TEST(RealTests, intFriendMoreOperatorTest) { - EXPECT_TRUE(2 > Real("-2")); - - EXPECT_FALSE(2 > Real("2")); - EXPECT_FALSE(-2 > Real("-2")); - EXPECT_FALSE(2 > Real("2.1")); -} - -TEST(RealTests, lessEqualOperatorTest) { - EXPECT_TRUE(Real(5) <= Real(10)); - EXPECT_TRUE(Real("5.1") <= Real("5.1")); - - EXPECT_FALSE(Real("5.5") <= Real("5.1")); - EXPECT_FALSE(Real(5) <= Real(-5)); - - EXPECT_TRUE(Real("-0") <= Real("-0")); - EXPECT_TRUE(Real("-0") <= Real("0")); - EXPECT_FALSE(Real("0") <= Real("-0")); -} - -TEST(RealTests, rationalLessEqualOperatorTest) { - EXPECT_TRUE(Real(5) <= Rational(51, 10)); - EXPECT_TRUE(Real("5.1") <= Rational(51, 10)); - - EXPECT_FALSE(Real("5.2") <= Rational(51, 10)); - EXPECT_FALSE(Real(5) <= Rational(50, -10)); -} - -TEST(RealTests, integerLessEqualOperatorTest) { - EXPECT_TRUE(Real(5) <= Integer(10)); - EXPECT_TRUE(Real(-5) <= Integer(5)); - EXPECT_TRUE(Real("5") <= Integer(5)); - - EXPECT_FALSE(Real("5.1") <= Integer(5)); - EXPECT_FALSE(Real(5) <= Integer(-5)); -} - -TEST(RealTests, intLessEqualOperatorTest) { - EXPECT_TRUE(Real("2") <= 2); - EXPECT_TRUE(Real("-2") <= -2); - EXPECT_TRUE(Real("-2") <= 2); - - EXPECT_FALSE(Real("2.1") <= 2); -} - -TEST(RealTests, rationalFriendLessEqualOperatorTest) { - EXPECT_TRUE(Rational(49, 10) <= Real(5)); - EXPECT_TRUE(Rational(51, 10) <= Real("5.1")); - - EXPECT_FALSE(Rational(52, 10) <= Real("5.1")); - EXPECT_FALSE(Rational(50, 10) <= Real(-5)); -} - -TEST(RealTests, integerFriendLessEqualOperatorTest) { - EXPECT_TRUE(Integer(4) <= Real(5)); - EXPECT_TRUE(Integer(-5) <= Real(5)); - EXPECT_TRUE(Integer(6) <= Real("6.0")); - - EXPECT_FALSE(Integer(6) <= Real("5.9")); - EXPECT_FALSE(Integer(5) <= Real(-5)); -} - -TEST(RealTests, intFriendLessEqualOperatorTest) { - EXPECT_TRUE(2 <= Real("2.1")); - EXPECT_TRUE(2 <= Real("2")); - EXPECT_TRUE(-2 <= Real("-2")); - - EXPECT_FALSE(2 <= Real("-2")); -} - -TEST(RealTests, moreEqualOperatorTest) { - EXPECT_TRUE(Real(50) >= Real(10)); - EXPECT_TRUE(Real("5.1") >= Real("5.1")); - - EXPECT_FALSE(Real("5.1") >= Real("5.2")); - EXPECT_FALSE(Real(-5) >= Real(5)); - - EXPECT_TRUE(Real("-0") >= Real("-0")); - EXPECT_FALSE(Real("-0") >= Real("0")); - EXPECT_TRUE(Real("0") >= Real("-0")); -} - -TEST(RealTests, rationalMoreEqualOperatorTest) { - EXPECT_TRUE(Real(50) >= Rational(50, 10)); - EXPECT_TRUE(Real("5.1") >= Rational(51, 10)); - - EXPECT_FALSE(Real("5.1") >= Rational(52, 10)); - EXPECT_FALSE(Real("-5.1") >= Rational(51, 10)); -} - -TEST(RealTests, integerMoreEqualOperatorTest) { - EXPECT_TRUE(Real(50) >= Integer(10)); - EXPECT_TRUE(Real(50) >= Integer(-50)); - EXPECT_TRUE(Real("5.0") >= Integer(5)); - - EXPECT_FALSE(Real("4.9") >= Integer(5)); - EXPECT_FALSE(Real(-5) >= Integer(5)); -} - -TEST(RealTests, intMoreEqualOperatorTest) { - EXPECT_TRUE(Real("2") >= 2); - EXPECT_TRUE(Real("-2") >= -2); - EXPECT_TRUE(Real("2.1") >= 2); - - EXPECT_FALSE(Real("-2") >= 2); -} - -TEST(RealTests, rationalFriendMoreEqualOperatorTest) { - EXPECT_TRUE(Rational(50, 10) >= Real(4)); - EXPECT_TRUE(Rational(50, 10) >= Real(5)); - - EXPECT_FALSE(Rational(49, 10) >= Real(5)); - EXPECT_FALSE(Rational(50, -10) >= Real("5.0")); -} - -TEST(RealTests, integerFriendMoreEqualOperatorTest) { - EXPECT_TRUE(Integer(5) >= Real("4.9")); - EXPECT_TRUE(Integer(5) >= Real(-5)); - EXPECT_TRUE(Integer(5) >= Real(5)); - - EXPECT_FALSE(Integer(5) >= Real("5.1")); - EXPECT_FALSE(Integer(-5) >= Real("5.0")); -} - -TEST(RealTests, intFriendMoreEqualOperatorTest) { - EXPECT_TRUE(2 >= Real("-2")); - EXPECT_TRUE(2 >= Real("2")); - EXPECT_TRUE(-2 >= Real("-2")); - - EXPECT_FALSE(2 >= Real("2.1")); -} - -TEST(RealTests, toStringTest) { - EXPECT_EQ(Real(0).toString(), "0.0"); - EXPECT_EQ((-Real(0)).toString(), "-0.0"); - EXPECT_EQ(Real(11).toString(), "11.0"); - EXPECT_EQ(Real(-11).toString(), "-11.0"); - EXPECT_EQ(Real("2.334455").toString(), "2.334455"); - EXPECT_EQ(Real("11821937432984732987").toString(), "11821937432984732987.0"); - EXPECT_EQ(Real("-1182193743298473298").toString(), "-1182193743298473298.0"); - EXPECT_EQ(Real("1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").toString(), "1.0*10^90"); - EXPECT_EQ(Real("-1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").toString(), "-1.0*10^90"); -} - -TEST(RealTests, toStringPrecisionPrecisionTest) { - Real val = Rational(1, 3); - EXPECT_EQ(val.toString(1), "0.3"); - EXPECT_EQ(val.toString(2), "0.33"); - EXPECT_EQ(val.toString(3), "0.333"); - EXPECT_EQ(val.toString(10), "0.3333333333"); - - val = -val; - EXPECT_EQ(val.toString(1), "-0.3"); - EXPECT_EQ(val.toString(2), "-0.33"); - EXPECT_EQ(val.toString(3), "-0.333"); - EXPECT_EQ(val.toString(10), "-0.3333333333"); - - val = Real("100000000000000.37841620837012"); - EXPECT_EQ(val.toString(18), "100000000000000.378"); - - val = Real("100000000000000.3775"); - EXPECT_EQ(val.toString(18), "100000000000000.378"); - - val = Real("0.000000001"); - EXPECT_EQ(val.toString(1), "1.0*10^-9"); - - val = Real("1000000000.1"); - EXPECT_EQ(val.toString(1), "1.0*10^9"); - - val = Real("10.1"); - EXPECT_EQ(val.toString(1), "1.0*10"); - - val = Real("10.1"); - EXPECT_EQ(val.toString(0), "1.0*10"); - - Real::ScopedSetPrecision setPrecision(10); - val = Real("1.3"); - EXPECT_THROW(val.toString(20), InvalidInputException); -} - -TEST(RealTests, getOutputPrecisionTest) { - EXPECT_EQ(Real().getOutputPrecision(), Real::getPrecision()); -} - -TEST(RealTests, setOutputPrecisionTest) { - Real a; - EXPECT_EQ(a.getOutputPrecision(), Real::getPrecision()); - - a.setOutputPrecision(10); - EXPECT_EQ(a.getOutputPrecision(), 10); - - a.setOutputPrecision(5); - EXPECT_EQ(a.getOutputPrecision(), 5); - - a.setOutputPrecision(5); - EXPECT_EQ(a.getOutputPrecision(), 5); - - EXPECT_THROW(a.setOutputPrecision(6), InvalidInputException); - EXPECT_THROW(a.setOutputPrecision(10), InvalidInputException); -} - -TEST(RealTests, updatePrecisionTest) { - { - Real a = 1; - a.setOutputPrecision(10); - - Real b = 1; - b.setOutputPrecision(5); - - a += b; - - EXPECT_EQ(a.getOutputPrecision(), 5); - EXPECT_EQ(b.getOutputPrecision(), 5); - } - { - Real a = 1; - a.setOutputPrecision(10); - - Real b = 1; - b.setOutputPrecision(5); - - b += a; - - EXPECT_EQ(a.getOutputPrecision(), 10); - EXPECT_EQ(b.getOutputPrecision(), 5); - } - { - Real a = 1; - a.setOutputPrecision(10); - - Real b = 1; - b.setOutputPrecision(5); - - a -= b; - - EXPECT_EQ(a.getOutputPrecision(), 5); - EXPECT_EQ(b.getOutputPrecision(), 5); - } - { - Real a = 1; - a.setOutputPrecision(10); - - Real b = 1; - b.setOutputPrecision(5); - - b -= a; - - EXPECT_EQ(a.getOutputPrecision(), 10); - EXPECT_EQ(b.getOutputPrecision(), 5); - } - { - Real a = 1; - a.setOutputPrecision(10); - - Real b = 1; - b.setOutputPrecision(5); - - a *= b; - - EXPECT_EQ(a.getOutputPrecision(), 5); - EXPECT_EQ(b.getOutputPrecision(), 5); - } - { - Real a = 1; - a.setOutputPrecision(10); - - Real b = 1; - b.setOutputPrecision(5); - - b *= a; - - EXPECT_EQ(a.getOutputPrecision(), 10); - EXPECT_EQ(b.getOutputPrecision(), 5); - } - { - Real a = 1; - a.setOutputPrecision(10); - - Real b = 1; - b.setOutputPrecision(5); - - a /= b; - - EXPECT_EQ(a.getOutputPrecision(), 5); - EXPECT_EQ(b.getOutputPrecision(), 5); - } - { - Real a = 1; - a.setOutputPrecision(10); - - Real b = 1; - b.setOutputPrecision(5); - - b /= a; - - EXPECT_EQ(a.getOutputPrecision(), 10); - EXPECT_EQ(b.getOutputPrecision(), 5); - } -} - -TEST(RealTests, getPrecisionTest) { - EXPECT_EQ(Real::getPrecision(), 20); -} - -TEST(RealTests, getCalculationPrecisionTest) { - EXPECT_EQ(Real::getCalculationPrecision(), 50); -} - -TEST(RealTests, setPrecisionTest) { - const unsigned currPrecision = Real::getPrecision(); - - Real::setPrecision(10); - EXPECT_EQ(Real::getPrecision(), 10); - - Real::setPrecision(currPrecision); - EXPECT_EQ(Real::getPrecision(), 20); -} - -TEST(RealTests, scopedSetPrecisionTest) { - const unsigned currPrecision = Real::getPrecision(); - - { - Real::ScopedSetPrecision setPrecision(123); - EXPECT_EQ(Real::getPrecision(), 123); - } - - EXPECT_EQ(Real::getPrecision(), currPrecision); -} - -TEST(RealTests, signTest) { - EXPECT_EQ(Real(-2).sign(), -1); - EXPECT_EQ(Real(-1).sign(), -1); - EXPECT_EQ(Real("-0").sign(), -1); - EXPECT_EQ(Real("0").sign(), 0); - EXPECT_EQ(Real(1).sign(), 1); - EXPECT_EQ(Real(2).sign(), 1); -} - -TEST(RealTests, isZeroTest) { - EXPECT_TRUE(Real("0").isZero()); - EXPECT_TRUE(Real("-0").isZero()); - - EXPECT_FALSE(Real("1").isZero()); - EXPECT_FALSE(Real("-1").isZero()); -} - -TEST(RealTests, isPreciseTest) { - EXPECT_FALSE(Real(2).isPrecise()); -} - -TEST(RealTests, isComplexTest) { - EXPECT_FALSE(Real(2).isComplex()); -} - -TEST(RealTests, getClassTest) { - EXPECT_EQ(Real().getClass(), MathObjectClass("Real")); - EXPECT_EQ(Real().getClass().getParent(), INumber::getClassStatic()); -} - -TEST(RealTests, hashTest) { - constexpr std::hash hasher; - - EXPECT_EQ(hasher(Real("0")), hasher(Real("0"))); - EXPECT_EQ(hasher(Real("-0")), hasher(Real("-0"))); - EXPECT_EQ(hasher(Real("12")), hasher(Real("12"))); - EXPECT_EQ(hasher(Real("-12")), hasher(Real("-12"))); - EXPECT_EQ(hasher(Real("452734865298734659873246238756987435")), hasher(Real("452734865298734659873246238756987435"))); - EXPECT_EQ(hasher(Real("-452734865298734659873246238756987435")), hasher(Real("-452734865298734659873246238756987435"))); - EXPECT_EQ(hasher(Real("1.4357")), hasher(Real("1.4357"))); - EXPECT_EQ(hasher(Real("-1.4357")), hasher(Real("-1.4357"))); - EXPECT_EQ(hasher(Real("3.3333")), hasher(Real("3.3333"))); - EXPECT_EQ(hasher(Real("-3.3333")), hasher(Real("-3.3333"))); - EXPECT_EQ(hasher(Real("123.00001")), hasher(Real("123.00001"))); - EXPECT_EQ(hasher(Real("-123.00001")), hasher(Real("-123.00001"))); - EXPECT_EQ(hasher(Real("897259832648723648327648273463287.48732648273652873")), hasher(Real("897259832648723648327648273463287.48732648273652873"))); - EXPECT_EQ(hasher(Real("-897259832648723648327648273463287.48732648273652873")), hasher(Real("-897259832648723648327648273463287.48732648273652873"))); - - EXPECT_NE(hasher(Real("0")), hasher(Real("-0"))); - EXPECT_NE(hasher(Real("0")), hasher(Real("1"))); - EXPECT_NE(hasher(Real("12")), hasher(Real("13"))); - EXPECT_NE(hasher(Real("-12")), hasher(Real("-13"))); - EXPECT_NE(hasher(Real("452734865298734659873246238756987435")), hasher(Real("452734865298734659873246238756987436"))); - EXPECT_NE(hasher(Real("-452734865298734659873246238756987435")), hasher(Real("-452734865298734659873246238756987436"))); - EXPECT_NE(hasher(Real("1.4357")), hasher(Real("1.4358"))); - EXPECT_NE(hasher(Real("-1.4357")), hasher(Real("-1.4358"))); - EXPECT_NE(hasher(Real("3.3333")), hasher(Real("3.33333"))); - EXPECT_NE(hasher(Real("-3.3333")), hasher(Real("-3.33333"))); - EXPECT_NE(hasher(Real("123.00001")), hasher(Real("123.000001"))); - EXPECT_NE(hasher(Real("-123.00001")), hasher(Real("-123.000001"))); - EXPECT_NE(hasher(Real("897259832648723648327648273463287.48732648273652873")), hasher(Real("897259832648723648327648273463287.48732648273652874"))); - EXPECT_NE(hasher(Real("-897259832648723648327648273463287.48732648273652873")), hasher(Real("-897259832648723648327648273463287.48732648273652874"))); -} diff --git a/tests/src/overall/approximate/ApproximateTests.cpp b/tests/src/overall/approximate/ApproximateTests.cpp deleted file mode 100644 index 84667b46d..000000000 --- a/tests/src/overall/approximate/ApproximateTests.cpp +++ /dev/null @@ -1,564 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionFunctions.hpp" - -using namespace fintamath; - -TEST(ApproximateTests, approximateTest) { - EXPECT_EQ(approximate(Expression("150!")).toString(), - "5.7133839564458545905*10^262"); - EXPECT_EQ(approximate(Expression("E")).toString(), - "2.7182818284590452354"); - EXPECT_EQ(approximate(Expression("Pi")).toString(), - "3.1415926535897932385"); - EXPECT_EQ(approximate(Expression("exp100")).toString(), - "2.6881171418161354484*10^43"); - EXPECT_EQ(approximate(Expression("E^101")).toString(), - "7.3070599793680672726*10^43"); - EXPECT_EQ(approximate(Expression("E^(-101)")).toString(), - "1.3685394711738530002*10^-44"); - EXPECT_EQ(approximate(Expression("ln3")).toString(), - "1.0986122886681096914"); - EXPECT_EQ(approximate(Expression("ln2")).toString(), - "0.69314718055994530942"); - EXPECT_EQ(approximate(Expression("ln100")).toString(), - "4.605170185988091368"); - EXPECT_EQ(approximate(Expression("lg99")).toString(), - "1.9956351945975499153"); - EXPECT_EQ(approximate(Expression("lg100")).toString(), - "2"); - EXPECT_EQ(approximate(Expression("lb100")).toString(), - "6.6438561897747246957"); - EXPECT_EQ(approximate(Expression("lb4")).toString(), - "2"); - EXPECT_EQ(approximate(Expression("sin10")).toString(), - "-0.5440211108893698134"); - EXPECT_EQ(approximate(Expression("cos10")).toString(), - "-0.83907152907645245226"); - EXPECT_EQ(approximate(Expression("tan10")).toString(), - "0.64836082745908667126"); - EXPECT_EQ(approximate(Expression("cot10")).toString(), - "1.5423510453569200483"); - EXPECT_EQ(approximate(Expression("sec10")).toString(), - "-1.1917935066878958109"); - EXPECT_EQ(approximate(Expression("csc10")).toString(), - "-1.8381639608896655887"); - EXPECT_EQ(approximate(Expression("asin0.9")).toString(), - "1.1197695149986341867"); - EXPECT_EQ(approximate(Expression("acos0.9")).toString(), - "0.45102681179626243254"); - EXPECT_EQ(approximate(Expression("atan10")).toString(), - "1.4711276743037345919"); - EXPECT_EQ(approximate(Expression("acot10")).toString(), - "0.099668652491162027378"); - EXPECT_EQ(approximate(Expression("asec10")).toString(), - "1.4706289056333368229"); - EXPECT_EQ(approximate(Expression("acsc10")).toString(), - "0.10016742116155979635"); - EXPECT_EQ(approximate(Expression("sinh10")).toString(), - "11013.232874703393377"); - EXPECT_EQ(approximate(Expression("cosh10")).toString(), - "11013.23292010332314"); - EXPECT_EQ(approximate(Expression("tanh10")).toString(), - "0.99999999587769276362"); - EXPECT_EQ(approximate(Expression("coth10")).toString(), - "1.0000000041223072534"); - EXPECT_EQ(approximate(Expression("sech10")).toString(), - "9.079985933781724408*10^-5"); - EXPECT_EQ(approximate(Expression("csch10")).toString(), - "9.0799859712122162834*10^-5"); - EXPECT_EQ(approximate(Expression("asinh0.9")).toString(), - "0.80886693565278246251"); - EXPECT_EQ(approximate(Expression("acosh1.9")).toString(), - "1.2571958266003804345"); - EXPECT_EQ(approximate(Expression("atanh0.9")).toString(), - "1.47221948958322023"); - EXPECT_EQ(approximate(Expression("acoth1.9")).toString(), - "0.5850356263251273222"); - EXPECT_EQ(approximate(Expression("asech0.9")).toString(), - "0.46714530810326201813"); - EXPECT_EQ(approximate(Expression("acsch1.9")).toString(), - "0.50462466551048371742"); - EXPECT_EQ(approximate(Expression("((2))*sqrt2")).toString(), - "2.8284271247461900976"); - EXPECT_EQ(approximate(Expression("sqrt2*((2))")).toString(), - "2.8284271247461900976"); - EXPECT_EQ(approximate(Expression("sin(1)^2")).toString(), - "0.7080734182735711935"); - EXPECT_EQ(approximate(Expression("sin(-1)^2")).toString(), - "0.7080734182735711935"); - EXPECT_EQ(approximate(Expression("sin1^2")).toString(), - "0.7080734182735711935"); - EXPECT_EQ(approximate(Expression("sin(10^10)")).toString(), - "-0.48750602508751069153"); - EXPECT_EQ(approximate(Expression("sin(Pi/3)")).toString(), - "0.86602540378443864676"); - EXPECT_EQ(approximate(Expression("cos(Pi/3)")).toString(), - "0.5"); - EXPECT_EQ(approximate(Expression("2!*E")).toString(), - "5.4365636569180904707"); - EXPECT_EQ(approximate(Expression("E*2!")).toString(), - "5.4365636569180904707"); - EXPECT_EQ(approximate(Expression("sqrt((1-cos(2*(Pi/3)))/2)")).toString(), - "0.86602540378443864676"); - EXPECT_EQ(approximate(Expression("2*sqrt((1-cos(2*(Pi/3)))/2)*cos(Pi/3)")).toString(), - "0.86602540378443864676"); - EXPECT_EQ(approximate(Expression("1/(sin(5))")).toString(), - "-1.0428352127714058198"); - EXPECT_EQ(approximate(Expression("sin(60deg)")).toString(), - "0.86602540378443864676"); - EXPECT_EQ(approximate(Expression("log(500!, 500! + 1)")).toString(), - "1.0"); - - EXPECT_EQ(approximate(Expression("E^(E^(E^(E^(E^E))))")).toString(), - "2.7182818284590452354^(2.7182818284590452354^(2.3315043990071954623*10^1656520))"); - - EXPECT_EQ(approximate(Expression("sin(floor(E^10))")).toString(), - "-0.28969263040207500615"); - EXPECT_EQ(approximate(Expression("sin(ceil(E^10))")).toString(), - "-0.96191007900804641384"); - EXPECT_EQ(approximate(Expression("cos(floor(11^10))")).toString(), - "-0.43983244324764898786"); - EXPECT_EQ(approximate(Expression("cos(ceil(11^10))")).toString(), - "-0.43983244324764898786"); - EXPECT_EQ(approximate(Expression("ln(floor(E^10))")).toString(), - "9.9999788527248892938"); - EXPECT_EQ(approximate(Expression("root(ceil(E^10), 3)")).toString(), - "28.031851508556071101"); - EXPECT_EQ(approximate(Expression("ln(floor(11^10))")).toString(), - "23.978952727983705441"); - EXPECT_EQ(approximate(Expression("root(ceil(11^10), 3)")).toString(), - "2960.1175005477589587"); - - EXPECT_EQ(approximate(Expression("(2/3)!")).toString(), - "0.9027452929509336113"); - EXPECT_EQ(approximate(Expression("E!")).toString(), - "4.2608204763570033817"); - EXPECT_EQ(approximate(Expression("(2/3)!!")).toString(), - "0.66666666666666666667!!"); - EXPECT_EQ(approximate(Expression("(1/1000000000000000000000000000000000000000)!!")).toString(), - "(1.0*10^-39)!!"); - EXPECT_EQ(approximate(Expression("(-1)!!")).toString(), - "(-1)!!"); - - EXPECT_EQ(approximate(Expression("I")).toString(), - "I"); - EXPECT_EQ(approximate(Expression("5 + I")).toString(), - "5 + I"); - EXPECT_EQ(approximate(Expression("5 I")).toString(), - "5 I"); - EXPECT_EQ(approximate(Expression("5 + 5 I")).toString(), - "5 + 5 I"); - EXPECT_EQ(approximate(Expression("5/2 + 1/2 I")).toString(), - "2.5 + 0.5 I"); - EXPECT_EQ(approximate(Expression("5 + 1/2 I")).toString(), - "5 + 0.5 I"); - EXPECT_EQ(approximate(Expression("5/2 + 2 I")).toString(), - "2.5 + 2 I"); - EXPECT_EQ(approximate(Expression("5/I")).toString(), - "-5 I"); - EXPECT_EQ(approximate(Expression("E/I")).toString(), - "-2.7182818284590452354 I"); - EXPECT_EQ(approximate(Expression("-I")).toString(), - "-I"); - EXPECT_EQ(approximate(Expression("5 - I")).toString(), - "5 - I"); - EXPECT_EQ(approximate(Expression("5 - I")).toString(), - "5 - I"); - EXPECT_EQ(approximate(Expression("5 - 5 I")).toString(), - "5 - 5 I"); - EXPECT_EQ(approximate(Expression("5/2 - 1/2 I")).toString(), - "2.5 - 0.5 I"); - EXPECT_EQ(approximate(Expression("5 - 1/2 I")).toString(), - "5 - 0.5 I"); - EXPECT_EQ(approximate(Expression("5/2 - 2 I")).toString(), - "2.5 - 2 I"); - EXPECT_EQ(approximate(Expression("5/-I")).toString(), - "5 I"); - EXPECT_EQ(approximate(Expression("E/-I")).toString(), - "2.7182818284590452354 I"); - EXPECT_EQ(approximate(Expression("sin(I)")).toString(), - "sin(I)"); - EXPECT_EQ(approximate(Expression("sin(5 + I)")).toString(), - "sin(5 + I)"); - EXPECT_EQ(approximate(Expression("sin(5/2 + 1/2 I)")).toString(), - "sin(2.5 + 0.5 I)"); - EXPECT_EQ(approximate(Expression("ln(I + 1)")).toString(), - "ln(1 + I)"); - - EXPECT_EQ(approximate(Expression("ln(x)")).toString(), - "ln(x)"); - EXPECT_EQ(approximate(Expression("lb(x)")).toString(), - "log(2, x)"); - EXPECT_EQ(approximate(Expression("sqrt(x)")).toString(), - "sqrt(x)"); - EXPECT_EQ(approximate(Expression("root(x, 3)")).toString(), - "root(x, 3)"); - EXPECT_EQ(approximate(Expression("root(x, 10)")).toString(), - "x^0.1"); - EXPECT_EQ(approximate(Expression("root(x, 33)")).toString(), - "x^0.03030303030303030303"); - - EXPECT_EQ(approximate(Expression("ln(9/40) a + 1 > 0")).toString(), - "a - 0.67039636015551187563 < 0"); - EXPECT_EQ(approximate(Expression("-a + Pi^4 sqrt(2) a < 0")).toString(), - "a < 0"); - EXPECT_EQ(approximate(Expression("-a + Pi^4 sqrt(2) a - sqrt(3) a < 0")).toString(), - "a < 0"); - EXPECT_EQ(approximate(Expression("-a + Pi^4 sqrt(2) a - sqrt(3) a + 1 < 0")).toString(), - "a + 0.0074060245747335632557 < 0"); -} - -TEST(ApproximateTests, approxamateExtremumsTest) { - EXPECT_EQ(approximate(Expression("sqr(ln(2)^10000000000000)")).toString(), - "0.0"); - EXPECT_EQ(approximate(Expression("root(ln(2)^10000000000000, 3)")).toString(), - "0.0"); - EXPECT_EQ(approximate(Expression("sin(ln(2)^10000000000000)")).toString(), - "0.0"); - EXPECT_EQ(approximate(Expression("cos(ln(2)^10000000000000)")).toString(), - "1.0"); - EXPECT_EQ(approximate(Expression("tan(ln(2)^10000000000000)")).toString(), - "0.0"); - EXPECT_EQ(approximate(Expression("cot(ln(2)^10000000000000)")).toString(), - "cot(0.0)"); - EXPECT_EQ(approximate(Expression("sec(ln(2)^10000000000000)")).toString(), - "1.0"); - EXPECT_EQ(approximate(Expression("csc(ln(2)^10000000000000)")).toString(), - "csc(0.0)"); - EXPECT_EQ(approximate(Expression("asin(ln(2)^10000000000000)")).toString(), - "0.0"); - EXPECT_EQ(approximate(Expression("acos(ln(2)^10000000000000)")).toString(), - "1.5707963267948966192"); - EXPECT_EQ(approximate(Expression("atan(ln(2)^10000000000000)")).toString(), - "0.0"); - EXPECT_EQ(approximate(Expression("acot(ln(2)^10000000000000)")).toString(), - "acot(0.0)"); - EXPECT_EQ(approximate(Expression("asec(ln(2)^10000000000000)")).toString(), - "asec(0.0)"); - EXPECT_EQ(approximate(Expression("acsc(ln(2)^10000000000000)")).toString(), - "acsc(0.0)"); - EXPECT_EQ(approximate(Expression("sinh(ln(2)^10000000000000)")).toString(), - "0.0"); - EXPECT_EQ(approximate(Expression("cosh(ln(2)^10000000000000)")).toString(), - "1.0"); - EXPECT_EQ(approximate(Expression("tanh(ln(2)^10000000000000)")).toString(), - "0.0"); - EXPECT_EQ(approximate(Expression("coth(ln(2)^10000000000000)")).toString(), - "coth(0.0)"); - EXPECT_EQ(approximate(Expression("sech(ln(2)^10000000000000)")).toString(), - "1.0"); - EXPECT_EQ(approximate(Expression("csch(ln(2)^10000000000000)")).toString(), - "csch(0.0)"); - EXPECT_EQ(approximate(Expression("asinh(ln(2)^10000000000000)")).toString(), - "0.0"); - EXPECT_EQ(approximate(Expression("acosh(ln(2)^10000000000000)")).toString(), - "acosh(0.0)"); - EXPECT_EQ(approximate(Expression("atanh(ln(2)^10000000000000)")).toString(), - "0.0"); - EXPECT_EQ(approximate(Expression("acoth(ln(2)^10000000000000)")).toString(), - "acoth(0.0)"); - EXPECT_EQ(approximate(Expression("asech(ln(2)^10000000000000)")).toString(), - "asech(0.0)"); - EXPECT_EQ(approximate(Expression("acsch(ln(2)^10000000000000)")).toString(), - "acsch(0.0)"); - - EXPECT_EQ(approximate(Expression("sqrt(-ln(2)^10000000000000)")).toString(), - "sqrt(-0.0)"); - EXPECT_EQ(approximate(Expression("root(-ln(2)^10000000000000, 3)")).toString(), - "root(-0.0, 3)"); - EXPECT_EQ(approximate(Expression("sin(-ln(2)^10000000000000)")).toString(), - "-0.0"); - EXPECT_EQ(approximate(Expression("cos(-ln(2)^10000000000000)")).toString(), - "1.0"); - EXPECT_EQ(approximate(Expression("tan(-ln(2)^10000000000000)")).toString(), - "-0.0"); - EXPECT_EQ(approximate(Expression("cot(-ln(2)^10000000000000)")).toString(), - "-cot(0.0)"); - EXPECT_EQ(approximate(Expression("sec(-ln(2)^10000000000000)")).toString(), - "1.0"); - EXPECT_EQ(approximate(Expression("csc(-ln(2)^10000000000000)")).toString(), - "-csc(0.0)"); - EXPECT_EQ(approximate(Expression("asin(-ln(2)^10000000000000)")).toString(), - "-0.0"); - EXPECT_EQ(approximate(Expression("acos(-ln(2)^10000000000000)")).toString(), - "1.5707963267948966192"); - EXPECT_EQ(approximate(Expression("atan(-ln(2)^10000000000000)")).toString(), - "-0.0"); - EXPECT_EQ(approximate(Expression("acot(-ln(2)^10000000000000)")).toString(), - "acot(-0.0)"); - EXPECT_EQ(approximate(Expression("asec(-ln(2)^10000000000000)")).toString(), - "asec(-0.0)"); - EXPECT_EQ(approximate(Expression("acsc(-ln(2)^10000000000000)")).toString(), - "acsc(-0.0)"); - EXPECT_EQ(approximate(Expression("sinh(-ln(2)^10000000000000)")).toString(), - "-0.0"); - EXPECT_EQ(approximate(Expression("cosh(-ln(2)^10000000000000)")).toString(), - "1.0"); - EXPECT_EQ(approximate(Expression("tanh(-ln(2)^10000000000000)")).toString(), - "-0.0"); - EXPECT_EQ(approximate(Expression("coth(-ln(2)^10000000000000)")).toString(), - "-coth(0.0)"); - EXPECT_EQ(approximate(Expression("sech(-ln(2)^10000000000000)")).toString(), - "1.0"); - EXPECT_EQ(approximate(Expression("csch(-ln(2)^10000000000000)")).toString(), - "-csch(0.0)"); - EXPECT_EQ(approximate(Expression("asinh(-ln(2)^10000000000000)")).toString(), - "-0.0"); - EXPECT_EQ(approximate(Expression("acosh(-ln(2)^10000000000000)")).toString(), - "acosh(-0.0)"); - EXPECT_EQ(approximate(Expression("atanh(-ln(2)^10000000000000)")).toString(), - "-0.0"); - EXPECT_EQ(approximate(Expression("acoth(-ln(2)^10000000000000)")).toString(), - "acoth(-0.0)"); - EXPECT_EQ(approximate(Expression("asech(-ln(2)^10000000000000)")).toString(), - "asech(-0.0)"); - EXPECT_EQ(approximate(Expression("acsch(-ln(2)^10000000000000)")).toString(), - "acsch(-0.0)"); - - EXPECT_EQ(approximate(Expression("floor(ln(2)^10000000000000)")).toString(), - "floor(0.0)"); - EXPECT_EQ(approximate(Expression("ceil(ln(2)^10000000000000)")).toString(), - "ceil(0.0)"); - EXPECT_EQ(approximate(Expression("sign(ln(2)^10000000000000)")).toString(), - "1"); - EXPECT_EQ(approximate(Expression("floor(1 - ln(2)^10000000000000)")).toString(), - "-ceil(-1.0)"); - EXPECT_EQ(approximate(Expression("ceil(1 - ln(2)^10000000000000)")).toString(), - "-floor(-1.0)"); - EXPECT_EQ(approximate(Expression("sign(1 - ln(2)^10000000000000)")).toString(), - "1"); - - EXPECT_EQ(approximate(Expression("floor(ln(2)^10000000000000 * sin(4))")).toString(), - "floor(-0.0)"); - EXPECT_EQ(approximate(Expression("ceil(ln(2)^10000000000000 * sin(4))")).toString(), - "ceil(-0.0)"); - EXPECT_EQ(approximate(Expression("sign(ln(2)^10000000000000 * sin(4))")).toString(), - "-1"); - EXPECT_EQ(approximate(Expression("floor(1 - ln(2)^10000000000000 * sin(4))")).toString(), - "-ceil(-1.0)"); - EXPECT_EQ(approximate(Expression("ceil(1 - ln(2)^10000000000000 * sin(4))")).toString(), - "-floor(-1.0)"); - EXPECT_EQ(approximate(Expression("sign(1 - ln(2)^10000000000000 * sin(4))")).toString(), - "1"); - - EXPECT_EQ(approximate(Expression("floor(ln(2)^10000000000000 * (sin(4) + 1 - 1))")).toString(), - "floor(-0.0)"); - EXPECT_EQ(approximate(Expression("ceil(ln(2)^10000000000000 * (sin(4) + 1 - 1))")).toString(), - "ceil(-0.0)"); - EXPECT_EQ(approximate(Expression("sign(ln(2)^10000000000000 * (sin(4) + 1 - 1))")).toString(), - "-1"); - EXPECT_EQ(approximate(Expression("floor(1 - ln(2)^10000000000000 * (sin(4) + 1 - 1))")).toString(), - "-ceil(-1.0)"); - EXPECT_EQ(approximate(Expression("ceil(1 - ln(2)^10000000000000 * (sin(4) + 1 - 1))")).toString(), - "-floor(-1.0)"); - EXPECT_EQ(approximate(Expression("sign(1 - ln(2)^10000000000000 * (sin(4) + 1 - 1))")).toString(), - "1"); - - EXPECT_EQ(approximate(Expression("floor(ln(2)^10000000000000 * (2sin(4) - sin(4)))")).toString(), - "floor(-0.0)"); - EXPECT_EQ(approximate(Expression("ceil(ln(2)^10000000000000 * (2sin(4) - sin(4)))")).toString(), - "ceil(-0.0)"); - EXPECT_EQ(approximate(Expression("sign(ln(2)^10000000000000 * (2sin(4) - sin(4)))")).toString(), - "-1"); - EXPECT_EQ(approximate(Expression("floor(1 - ln(2)^10000000000000 * (2sin(4) - sin(4)))")).toString(), - "-ceil(-1.0)"); - EXPECT_EQ(approximate(Expression("ceil(1 - ln(2)^10000000000000 * (2sin(4) - sin(4)))")).toString(), - "-floor(-1.0)"); - EXPECT_EQ(approximate(Expression("sign(1 - ln(2)^10000000000000 * (2sin(4) - sin(4)))")).toString(), - "1"); - - EXPECT_EQ(approximate(Expression("floor(ln(2)^10000000000000 / sin(4))")).toString(), - "floor(-0.0)"); - EXPECT_EQ(approximate(Expression("ceil(ln(2)^10000000000000 / sin(4))")).toString(), - "ceil(-0.0)"); - EXPECT_EQ(approximate(Expression("sign(ln(2)^10000000000000 / sin(4))")).toString(), - "-1"); - EXPECT_EQ(approximate(Expression("floor(1 - ln(2)^10000000000000 / sin(4))")).toString(), - "-ceil(-1.0)"); - EXPECT_EQ(approximate(Expression("ceil(1 - ln(2)^10000000000000 / sin(4))")).toString(), - "-floor(-1.0)"); - EXPECT_EQ(approximate(Expression("sign(1 - ln(2)^10000000000000 / sin(4))")).toString(), - "1"); - - EXPECT_EQ(approximate(Expression("floor(ln(2)^10000000000000 / (sin(4) + 1 - 1))")).toString(), - "floor(-0.0)"); - EXPECT_EQ(approximate(Expression("ceil(ln(2)^10000000000000 / (sin(4) + 1 - 1))")).toString(), - "ceil(-0.0)"); - EXPECT_EQ(approximate(Expression("sign(ln(2)^10000000000000 / (sin(4) + 1 - 1))")).toString(), - "-1"); - EXPECT_EQ(approximate(Expression("floor(1 - ln(2)^10000000000000 / (sin(4) + 1 - 1))")).toString(), - "-ceil(-1.0)"); - EXPECT_EQ(approximate(Expression("ceil(1 - ln(2)^10000000000000 / (sin(4) + 1 - 1))")).toString(), - "-floor(-1.0)"); - EXPECT_EQ(approximate(Expression("sign(1 - ln(2)^10000000000000 / (sin(4) + 1 - 1))")).toString(), - "1"); - - EXPECT_EQ(approximate(Expression("floor(ln(2)^10000000000000 / (2sin(4) - sin(4)))")).toString(), - "floor(-0.0)"); - EXPECT_EQ(approximate(Expression("ceil(ln(2)^10000000000000 / (2sin(4) - sin(4)))")).toString(), - "ceil(-0.0)"); - EXPECT_EQ(approximate(Expression("sign(ln(2)^10000000000000 / (2sin(4) - sin(4)))")).toString(), - "-1"); - EXPECT_EQ(approximate(Expression("floor(1 - ln(2)^10000000000000 / (2sin(4) - sin(4)))")).toString(), - "-ceil(-1.0)"); - EXPECT_EQ(approximate(Expression("ceil(1 - ln(2)^10000000000000 / (2sin(4) - sin(4)))")).toString(), - "-floor(-1.0)"); - EXPECT_EQ(approximate(Expression("sign(1 - ln(2)^10000000000000 / (2sin(4) - sin(4)))")).toString(), - "1"); - - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 = 0")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 != 0")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 < 0")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 > 0")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 <= 0")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 >= 0")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 = 0")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 != 0")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 < 0")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 > 0")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 <= 0")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 >= 0")).toString(), - "False"); - - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 = ln(2)^100000000")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 != ln(2)^100000000")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 < ln(2)^100000000")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 > ln(2)^100000000")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 <= ln(2)^100000000")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 >= ln(2)^100000000")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 = ln(2)^100000000")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 != ln(2)^100000000")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 < ln(2)^100000000")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 > ln(2)^100000000")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 <= ln(2)^100000000")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 >= ln(2)^100000000")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 = -ln(2)^100000000")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 != -ln(2)^100000000")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 < -ln(2)^100000000")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 > -ln(2)^100000000")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 <= -ln(2)^100000000")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("ln(2)^10000000000000 >= -ln(2)^100000000")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 = -ln(2)^100000000")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 != -ln(2)^100000000")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 < -ln(2)^100000000")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 > -ln(2)^100000000")).toString(), - "True"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 <= -ln(2)^100000000")).toString(), - "False"); - EXPECT_EQ(approximate(Expression("-ln(2)^10000000000000 >= -ln(2)^100000000")).toString(), - "True"); - - EXPECT_EQ(approximate(Expression("1 / (1 - tanh(11^10))")).toString(), - "cosh(25937424601)/(cosh(25937424601) - sinh(25937424601))"); - EXPECT_EQ(approximate(Expression("1 / (1 - coth(11^10))")).toString(), - "sinh(25937424601)/(sinh(25937424601) - cosh(25937424601))"); - EXPECT_EQ(approximate(Expression("1 / (ln(2)^10000000000000)")).toString(), - "1/0.0"); -} - -TEST(ApproximateTests, approximateWithPrecisionTest) { - EXPECT_EQ(approximate(Expression("123"), 2).toString(), - "1.2*10^2"); - EXPECT_EQ(approximate(Expression("123"), 3).toString(), - "123"); - EXPECT_EQ(approximate(Expression("999"), 2).toString(), - "1.0*10^3"); - EXPECT_EQ(approximate(Expression("999"), 3).toString(), - "999"); - EXPECT_EQ(approximate(Expression("1000"), 3).toString(), - "1.0*10^3"); - EXPECT_EQ(approximate(Expression("1000"), 4).toString(), - "1000"); - EXPECT_EQ(approximate(Expression("2/3"), 0).toString(), - "0.7"); - EXPECT_EQ(approximate(Expression("2/3"), 1).toString(), - "0.7"); - EXPECT_EQ(approximate(Expression("2/3"), 2).toString(), - "0.67"); - EXPECT_EQ(approximate(Expression("10^10000"), 8).toString(), - "1.0*10^10000"); - EXPECT_EQ(approximate(Expression("9^10000"), 8).toString(), - "2.6613034*10^9542"); - EXPECT_EQ(approximate(Expression("sin(E)"), 16).toString(), - "0.4107812905029087"); - EXPECT_EQ(approximate(Expression("sin(E)"), 100).toString(), - "0.4107812905029086954760094920183605918883069703934153453045716588061351824376549958759786190454355935"); - EXPECT_EQ(approximate(Expression("sin(E)"), 500).toString(), - "0.41078129050290869547600949201836059188830697039341534530457165880613518243765499587597861904543559353998291725993302611025612058214980807451386832166444404531330197030068700843779775501870429268806003976547248700619445558784780526262698913892212813629990839737608068439105974107056580477820375774780424366945910698422961638162689359340566062721679765484253127451162965356964229969288617282831139369276388867344864990496109344825533823527519982767717612020764891885643060371919941565596238925522726933"); - EXPECT_EQ(approximate(Expression("sin(E)"), 1000).toString(), - "0.410781290502908695476009492018360591888306970393415345304571658806135182437654995875978619045435593539982917259933026110256120582149808074513868321664444045313301970300687008437797755018704292688060039765472487006194455587847805262626989138922128136299908397376080684391059741070565804778203757747804243669459106984229616381626893593405660627216797654842531274511629653569642299692886172828311393692763888673448649904961093448255338235275199827677176120207648918856430603719199415655962389255227269329528247477565374084254456845493070521764653289529029121531798267980455224152201783074312455247443118659121061166824975283442729765920066115702948819794373441039363621507249342167892877264237554995364981898784098244975928739908684886687169561527095433756282781475277781538970397993742686571201323888405828052948752757923286033258285782682064914566808696556377856800938584299870591049139758903145979548061988835578438108419199725833087967291498589345414792089183496072498118579415411402320500775908443"); - EXPECT_EQ(approximate(Expression("sin(sin(E))"), 30).toString(), - "0.39932574404189139297067052142"); - EXPECT_EQ(approximate(Expression("(sqrt(2) + 1)^2"), 5).toString(), - "5.8284"); - EXPECT_EQ(approximate(Expression("E/I"), 5).toString(), - "-2.7183 I"); - EXPECT_EQ(approximate(Expression("E/-I"), 5).toString(), - "2.7183 I"); - EXPECT_EQ(approximate(Expression("x+E"), 8).toString(), - "x + 2.7182818"); - EXPECT_EQ(approximate(Expression("x^(100!)"), 8).toString(), - "x^(9.3326215*10^157)"); - EXPECT_EQ(approximate(Expression("2^200/x"), 10).toString(), - "(1.606938044*10^60)/x"); - EXPECT_EQ(approximate(Expression("x/2^200"), 10).toString(), - "6.223015278*10^-61 x"); - EXPECT_EQ(approximate(Expression("(sqrt(2) - a - 1)^2"), 5).toString(), - "a^2 - 0.82843 a + 0.17157"); - EXPECT_EQ(approximate(Expression("2 sqrt2 sin3 a + 3 ln5 root(2, 3) b"), 5).toString(), - "0.39915 a + 6.0833 b"); - - EXPECT_EQ(approximate(approximate(Expression("sin(5)"), 100), 5).toString(), - "-0.95892"); - EXPECT_EQ(approximate(approximate(Expression("sin(5) I"), 100), 5).toString(), - "-0.95892 I"); - EXPECT_EQ(approximate(approximate(Expression("I + sin(4)"), 100), 5).toString(), - "-0.7568 + I"); - EXPECT_EQ(approximate(approximate(Expression("sin(5) I + sin(4)"), 100), 5).toString(), - "-0.7568 - 0.95892 I"); - - { - Expression expr = approximate(Expression("cos(5)"), 56); - EXPECT_EQ(expr.toString(), "0.28366218546322626446663917151355730833442259225221594493"); - - expr = approximate(expr, 55); - EXPECT_EQ(expr.toString(), "0.2836621854632262644666391715135573083344225922522159449"); - - expr = approximate(expr, 1); - EXPECT_EQ(expr.toString(), "0.3"); - } -} diff --git a/tests/src/overall/simplify/SimplifyComparisonTests.cpp b/tests/src/overall/simplify/SimplifyComparisonTests.cpp deleted file mode 100644 index ff12b0262..000000000 --- a/tests/src/overall/simplify/SimplifyComparisonTests.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyComparisonTests, simplifyTest) { - EXPECT_EQ(Expression("a=a").toString(), - "True"); - EXPECT_EQ(Expression("a+a=2*a").toString(), - "True"); - EXPECT_EQ(Expression("a=b").toString(), - "a - b = 0"); - EXPECT_EQ(Expression("a!=a").toString(), - "False"); - EXPECT_EQ(Expression("a+a!=2*a").toString(), - "False"); - EXPECT_EQ(Expression("a!=b").toString(), - "a - b != 0"); - EXPECT_EQ(Expression("x<6").toString(), - "x - 6 < 0"); - EXPECT_EQ(Expression("x<=6").toString(), - "x - 6 <= 0"); - EXPECT_EQ(Expression("x>6").toString(), - "x - 6 > 0"); - EXPECT_EQ(Expression("x>=6").toString(), - "x - 6 >= 0"); - EXPECT_EQ(Expression("(5+5)=(2*5)").toString(), - "True"); - EXPECT_EQ(Expression("((((5+5)=(2*5))))").toString(), - "True"); - EXPECT_EQ(Expression("((1*1))(5+5)=((2*5)/(1/1))").toString(), - "True"); - EXPECT_EQ(Expression("-x - 10 = 0").toString(), - "x + 10 = 0"); - EXPECT_EQ(Expression("2x = 0").toString(), - "x = 0"); - EXPECT_EQ(Expression("2x - 10 = 0").toString(), - "x - 5 = 0"); - EXPECT_EQ(Expression("-a > 0").toString(), - "a < 0"); - EXPECT_EQ(Expression("-2a + 5 > 6").toString(), - "a + 1/2 < 0"); - EXPECT_EQ(Expression("-2a+5>6").toString(), - "a + 1/2 < 0"); - EXPECT_EQ(Expression("-6x^2 + 4x - 20 = 15x - 9").toString(), - "x^2 + (11 x)/6 + 11/6 = 0"); - EXPECT_EQ(Expression("2 a^5 b - 4 a b^5 = 0").toString(), - "a^5 b - 2 a b^5 = 0"); - EXPECT_EQ(Expression("-2 a^5 b + 4 a b^5 = 0").toString(), - "a^5 b - 2 a b^5 = 0"); - - EXPECT_EQ(Expression("sin(E)=sin(E)").toString(), - "True"); - EXPECT_EQ(Expression("sin(E)>sin(E)").toString(), - "False"); - EXPECT_EQ(Expression("sin(E)>=sin(E)").toString(), - "True"); - EXPECT_EQ(Expression("sin(E)ln(5)").toString(), - "False"); - EXPECT_EQ(Expression("log(E,5)<=ln(5)").toString(), - "True"); - EXPECT_EQ(Expression("log(E,5)>=ln(5)").toString(), - "True"); - EXPECT_EQ(Expression("log(1deg, (1deg)^(1deg)) = 1deg").toString(), - "True"); - EXPECT_EQ(Expression("E^Pi > Pi^E").toString(), - "True"); - EXPECT_EQ(Expression("Pi^E < E^Pi").toString(), - "True"); - EXPECT_EQ(Expression("log(floor(E), E) = lb(E)").toString(), - "True"); - - EXPECT_EQ(Expression("I! > 0").toString(), - "I! > 0"); - EXPECT_EQ(Expression("Inf mod 2 > 0").toString(), - "Inf mod 2 > 0"); - EXPECT_EQ(Expression("Inf! - 1 = 0").toString(), - "Inf! - 1 = 0"); - EXPECT_EQ(Expression("Inf - 1 > 0").toString(), - "Inf > 0"); - EXPECT_EQ(Expression("Pi!! - Pi > 0").toString(), - "Pi!! - Pi > 0"); -} diff --git a/tests/src/overall/simplify/SimplifyComplexNumberTests.cpp b/tests/src/overall/simplify/SimplifyComplexNumberTests.cpp deleted file mode 100644 index 7ec9d398e..000000000 --- a/tests/src/overall/simplify/SimplifyComplexNumberTests.cpp +++ /dev/null @@ -1,271 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyComplexNumberTests, simplifyTest) { - EXPECT_EQ(Expression("(1 + 2I) + (2 + 3I)").toString(), - "3 + 5 I"); - EXPECT_EQ(Expression("(1 + 2I) - (2 + 3I)").toString(), - "-1 - I"); - EXPECT_EQ(Expression("(1 + 2I) * (2 + 3I)").toString(), - "-4 + 7 I"); - EXPECT_EQ(Expression("(1 + 2I) / (2 + 3I)").toString(), - "8/13 + 1/13 I"); - EXPECT_EQ(Expression("-(2 + 3I)").toString(), - "-2 - 3 I"); - EXPECT_EQ(Expression("+(2 + 3I)").toString(), - "2 + 3 I"); - - EXPECT_EQ(Expression("(-5 + 2I)^0").toString(), - "1"); - EXPECT_EQ(Expression("(-5 + 2I)^1").toString(), - "-5 + 2 I"); - EXPECT_EQ(Expression("(-5 + 2I)^2").toString(), - "21 - 20 I"); - EXPECT_EQ(Expression("(-5 + 2I)^3").toString(), - "-65 + 142 I"); - EXPECT_EQ(Expression("(-5 + 2I)^4").toString(), - "41 - 840 I"); - EXPECT_EQ(Expression("(-5 + 2I)^5").toString(), - "1475 + 4282 I"); - EXPECT_EQ(Expression("(-5 + 2I)^6").toString(), - "-15939 - 18460 I"); - EXPECT_EQ(Expression("(-5 + 2I)^7").toString(), - "116615 + 60422 I"); - EXPECT_EQ(Expression("(-5 + 2I)^8").toString(), - "-703919 - 68880 I"); - EXPECT_EQ(Expression("(-5 + 2I)^32").toString(), - "231439382100320515840321 + 95179357018581597343680 I"); - EXPECT_EQ(Expression("(-5 + 2I)^-1").toString(), - "-5/29 - 2/29 I"); - EXPECT_EQ(Expression("(-5 + 2I)^-5").toString(), - "1475/20511149 - 4282/20511149 I"); - EXPECT_EQ(Expression("(-5 + 2I)^-6").toString(), - "-15939/594823321 + 18460/594823321 I"); - EXPECT_EQ(Expression("(-5 + 2I)^-32").toString(), - "231439382100320515840321/62623297589448778360828428329074752308805325441 - 95179357018581597343680/62623297589448778360828428329074752308805325441 I"); - - EXPECT_EQ(Expression("sqrt(-1)").toString(), - "I"); - EXPECT_EQ(Expression("sqrt(-4) - 5").toString(), - "-5 + 2 I"); - // TODO: implement - EXPECT_EQ(Expression("root(-1, 3)").toString(), - "root(-1, 3)"); - EXPECT_EQ(Expression("root(-1, 4)").toString(), - "root(-1, 4)"); - EXPECT_EQ(Expression("root(-1, 5)").toString(), - "root(-1, 5)"); - EXPECT_EQ(Expression("root(-1, 6)").toString(), - "root(-1, 6)"); - EXPECT_EQ(Expression("root(-1, 7)").toString(), - "root(-1, 7)"); - EXPECT_EQ(Expression("(-1)^(3/2)").toString(), - "(-1)^(3/2)"); - EXPECT_EQ(Expression("(-1)^(2/3)").toString(), - "(-1)^(2/3)"); - EXPECT_EQ(Expression("(-1)^(3/4)").toString(), - "(-1)^(3/4)"); - EXPECT_EQ(Expression("(-1)^(4/5)").toString(), - "(-1)^(4/5)"); - EXPECT_EQ(Expression("(-1)^(5/6)").toString(), - "(-1)^(5/6)"); - EXPECT_EQ(Expression("(-1)^(6/7)").toString(), - "(-1)^(6/7)"); - EXPECT_EQ(Expression("sqrt(-3) sqrt(-3)").toString(), - "-3"); - EXPECT_EQ(Expression("sqrt(-3) sqrt(-2)").toString(), - "-sqrt(6)"); - EXPECT_EQ(Expression("sqrt(I+1) sqrt(I+1)").toString(), - "1 + I"); - EXPECT_EQ(Expression("sqrt(I+1) sqrt(I)").toString(), - "sqrt(1 + I) sqrt(I)"); - EXPECT_EQ(Expression("root(-3, 3) root(-3, 3)").toString(), - "(-3)^(2/3)"); - EXPECT_EQ(Expression("root(-3, 3) root(-2, 3)").toString(), - "root(-2, 3) root(-3, 3)"); - EXPECT_EQ(Expression("root(I+1, 3) root(I+1, 3)").toString(), - "(1 + I)^(2/3)"); - EXPECT_EQ(Expression("root(I+1, 3) root(I, 3)").toString(), - "root(1 + I, 3) root(I, 3)"); - - // TODO: implement - EXPECT_EQ(Expression("ln(-1)").toString(), - "ln(-1)"); - EXPECT_EQ(Expression("lb(-1)").toString(), - "log(2, -1)"); - EXPECT_EQ(Expression("lg(-1)").toString(), - "log(10, -1)"); - - // TODO: implement - EXPECT_EQ(Expression("asin(2)").toString(), - "asin(2)"); - EXPECT_EQ(Expression("acos(2)").toString(), - "acos(2)"); - - EXPECT_EQ(Expression("abs(I)").toString(), - "1"); - EXPECT_EQ(Expression("abs(I + 1)").toString(), - "sqrt(2)"); - EXPECT_EQ(Expression("abs(3I + 2)").toString(), - "sqrt(13)"); - - EXPECT_EQ(Expression("sign(I)").toString(), - "I"); - EXPECT_EQ(Expression("sign(I + 1)").toString(), - "((1 + I) sqrt(2))/2"); - EXPECT_EQ(Expression("sign(3I + 2)").toString(), - "((2 + 3 I) sqrt(13))/13"); - - // TODO: implement - EXPECT_EQ(Expression("sin(I + 1)").toString(), - "sin(1 + I)"); - EXPECT_EQ(Expression("cos(I + 1)").toString(), - "cos(1 + I)"); - EXPECT_EQ(Expression("tan(I + 1)").toString(), - "tan(1 + I)"); - EXPECT_EQ(Expression("cot(I + 1)").toString(), - "cot(1 + I)"); - EXPECT_EQ(Expression("sec(I + 1)").toString(), - "sec(1 + I)"); - EXPECT_EQ(Expression("csc(I + 1)").toString(), - "csc(1 + I)"); - EXPECT_EQ(Expression("asin(I + 1)").toString(), - "asin(1 + I)"); - EXPECT_EQ(Expression("acos(I + 1)").toString(), - "acos(1 + I)"); - EXPECT_EQ(Expression("atan(I + 1)").toString(), - "atan(1 + I)"); - EXPECT_EQ(Expression("acot(I + 1)").toString(), - "acot(1 + I)"); - EXPECT_EQ(Expression("asec(I + 1)").toString(), - "asec(1 + I)"); - EXPECT_EQ(Expression("acsc(I + 1)").toString(), - "acsc(1 + I)"); - EXPECT_EQ(Expression("sinh(I + 1)").toString(), - "sinh(1 + I)"); - EXPECT_EQ(Expression("cosh(I + 1)").toString(), - "cosh(1 + I)"); - EXPECT_EQ(Expression("tanh(I + 1)").toString(), - "tanh(1 + I)"); - EXPECT_EQ(Expression("coth(I + 1)").toString(), - "coth(1 + I)"); - EXPECT_EQ(Expression("sech(I + 1)").toString(), - "sech(1 + I)"); - EXPECT_EQ(Expression("csch(I + 1)").toString(), - "csch(1 + I)"); - EXPECT_EQ(Expression("asinh(I + 1)").toString(), - "asinh(1 + I)"); - EXPECT_EQ(Expression("acosh(I + 1)").toString(), - "acosh(1 + I)"); - EXPECT_EQ(Expression("atanh(I + 1)").toString(), - "atanh(1 + I)"); - EXPECT_EQ(Expression("acoth(I + 1)").toString(), - "acoth(1 + I)"); - EXPECT_EQ(Expression("asech(I + 1)").toString(), - "asech(1 + I)"); - EXPECT_EQ(Expression("acsch(I + 1)").toString(), - "acsch(1 + I)"); - - EXPECT_EQ(Expression("sqrt(3) (2/3 + 1/2 I)").toString(), - "((4 + 3 I) sqrt(3))/6"); - EXPECT_EQ(Expression("I / x").toString(), - "I/x"); - EXPECT_EQ(Expression("-I / x").toString(), - "-I/x"); - EXPECT_EQ(Expression("2I / x").toString(), - "(2 I)/x"); - EXPECT_EQ(Expression("-2I / x").toString(), - "-(2 I)/x"); - EXPECT_EQ(Expression("(5/6 I) x").toString(), - "(5 I x)/6"); - EXPECT_EQ(Expression("(5/6 I + 2/7) x").toString(), - "((12 + 35 I) x)/42"); - EXPECT_EQ(Expression("(5/6 I + 2) x").toString(), - "((12 + 5 I) x)/6"); - EXPECT_EQ(Expression("(5 I + 2/7) x").toString(), - "((2 + 35 I) x)/7"); - EXPECT_EQ(Expression("(5/6 I) / x").toString(), - "(5 I)/(6 x)"); - EXPECT_EQ(Expression("(5/6 I + 2/7) / x").toString(), - "(12 + 35 I)/(42 x)"); - EXPECT_EQ(Expression("(5/6 I + 2) / x").toString(), - "(12 + 5 I)/(6 x)"); - EXPECT_EQ(Expression("(5 I + 2/7) / x").toString(), - "(2 + 35 I)/(7 x)"); - EXPECT_EQ(Expression("x / (5/6 I)").toString(), - "-(6 I x)/5"); - EXPECT_EQ(Expression("x / (5/6 I + 2/7)").toString(), - "((504 - 1470 I) x)/1369"); - EXPECT_EQ(Expression("x / (5/6 I + 2)").toString(), - "((72 - 30 I) x)/169"); - EXPECT_EQ(Expression("x / (5 I + 2/7)").toString(), - "((14 - 245 I) x)/1229"); - - EXPECT_EQ(Expression("I = I").toString(), - "True"); - EXPECT_EQ(Expression("I = 2 I").toString(), - "False"); - EXPECT_EQ(Expression("I = I x").toString(), - "x - 1 = 0"); - EXPECT_EQ(Expression("I x = I").toString(), - "x - 1 = 0"); - - EXPECT_EQ(Expression("I != I").toString(), - "False"); - EXPECT_EQ(Expression("I != 2 I").toString(), - "True"); - EXPECT_EQ(Expression("I != I x").toString(), - "x - 1 != 0"); - EXPECT_EQ(Expression("I x != I").toString(), - "x - 1 != 0"); - - EXPECT_EQ(Expression("I < I").toString(), - "I < I"); - EXPECT_EQ(Expression("I < 2 I").toString(), - "I < 2 I"); - EXPECT_EQ(Expression("I < I x").toString(), - "I < I x"); - EXPECT_EQ(Expression("I x < I").toString(), - "I x < I"); - - EXPECT_EQ(Expression("I > I").toString(), - "I > I"); - EXPECT_EQ(Expression("I > 2 I").toString(), - "I > 2 I"); - EXPECT_EQ(Expression("I x > I").toString(), - "I x > I"); - - EXPECT_EQ(Expression("I <= I").toString(), - "I <= I"); - EXPECT_EQ(Expression("I <= 2 I").toString(), - "I <= 2 I"); - EXPECT_EQ(Expression("I <= I x").toString(), - "I <= I x"); - EXPECT_EQ(Expression("I x <= I").toString(), - "I x <= I"); - - EXPECT_EQ(Expression("I >= I").toString(), - "I >= I"); - EXPECT_EQ(Expression("I >= 2 I").toString(), - "I >= 2 I"); - EXPECT_EQ(Expression("I >= I x").toString(), - "I >= I x"); - EXPECT_EQ(Expression("I x >= I").toString(), - "I x >= I"); - - EXPECT_EQ(Expression("2 I = E").toString(), - "False"); - EXPECT_EQ(Expression("2 I > E").toString(), - "2 I > E"); - EXPECT_EQ(Expression("E = 2 I").toString(), - "False"); - EXPECT_EQ(Expression("E > 2 I").toString(), - "E > 2 I"); - EXPECT_EQ(Expression("2 I + 3 = 0").toString(), - "False"); - EXPECT_EQ(Expression("2 I + E > 0").toString(), - "E + 2 I > 0"); -} diff --git a/tests/src/overall/simplify/SimplifyDerivativeTests.cpp b/tests/src/overall/simplify/SimplifyDerivativeTests.cpp deleted file mode 100644 index 4e5617fe7..000000000 --- a/tests/src/overall/simplify/SimplifyDerivativeTests.cpp +++ /dev/null @@ -1,312 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyDerivativeTests, simplifyTest) { - EXPECT_EQ(Expression("derivative(2, x)").toString(), - "0"); - EXPECT_EQ(Expression("derivative(2 + I, x)").toString(), - "0"); - EXPECT_EQ(Expression("derivative(E, x)").toString(), - "0"); - EXPECT_EQ(Expression("derivative(x, x)").toString(), - "1"); - EXPECT_EQ(Expression("derivative(x, y)").toString(), - "0"); - EXPECT_EQ(Expression("derivative(x_1, x_1)").toString(), - "1"); - EXPECT_EQ(Expression("derivative(x_1, x_2)").toString(), - "0"); - EXPECT_EQ(Expression("derivative(-x, x)").toString(), - "-1"); - EXPECT_EQ(Expression("derivative(x + y, x)").toString(), - "1"); - EXPECT_EQ(Expression("derivative(x + 2, x)").toString(), - "1"); - EXPECT_EQ(Expression("derivative(x + (2+I), x)").toString(), - "1"); - EXPECT_EQ(Expression("derivative(x - y, x)").toString(), - "1"); - EXPECT_EQ(Expression("derivative(x - 2, x)").toString(), - "1"); - EXPECT_EQ(Expression("derivative(x - (2+I), x)").toString(), - "1"); - EXPECT_EQ(Expression("derivative(x * y, x)").toString(), - "y"); - EXPECT_EQ(Expression("derivative(x * 2, x)").toString(), - "2"); - EXPECT_EQ(Expression("derivative(x * (2+I), x)").toString(), - "2 + I"); - EXPECT_EQ(Expression("derivative(x / y, x)").toString(), - "1/y"); - EXPECT_EQ(Expression("derivative(y / x, x)").toString(), - "-y/(x^2)"); - EXPECT_EQ(Expression("derivative(x / 2, x)").toString(), - "1/2"); - EXPECT_EQ(Expression("derivative(2 / x, x)").toString(), - "-2/(x^2)"); - EXPECT_EQ(Expression("derivative(x / (2+I), x)").toString(), - "2/5 - 1/5 I"); - EXPECT_EQ(Expression("derivative((2+I) / x, x)").toString(), - "-(2 + I)/(x^2)"); - EXPECT_EQ(Expression("derivative(x mod y, x)").toString(), - "derivative(x mod y, x)"); - EXPECT_EQ(Expression("derivative(y mod x, x)").toString(), - "derivative(y mod x, x)"); - EXPECT_EQ(Expression("derivative(x mod 2, x)").toString(), - "derivative(x mod 2, x)"); - EXPECT_EQ(Expression("derivative(2 mod x, x)").toString(), - "derivative(2 mod x, x)"); - EXPECT_EQ(Expression("derivative(x ^ x, x)").toString(), - "x^x ln(x) + x^x"); - EXPECT_EQ(Expression("derivative(x ^ y, x)").toString(), - "x^(y - 1) y"); - EXPECT_EQ(Expression("derivative(y ^ x, x)").toString(), - "y^x ln(y)"); - EXPECT_EQ(Expression("derivative(x ^ 2, x)").toString(), - "2 x"); - EXPECT_EQ(Expression("derivative(2 ^ x, x)").toString(), - "2^x ln(2)"); - EXPECT_EQ(Expression("derivative(x ^ (3/5), x)").toString(), - "3/(5 x^(2/5))"); - EXPECT_EQ(Expression("derivative((3/5) ^ x, x)").toString(), - "(3/5)^x ln(3/5)"); - EXPECT_EQ(Expression("derivative(x ^ (-3/5), x)").toString(), - "-3/(5 x^(8/5))"); - EXPECT_EQ(Expression("derivative((-3/5) ^ x, x)").toString(), - "(-3/5)^x ln(-3/5)"); - EXPECT_EQ(Expression("derivative(x ^ (2+I), x)").toString(), - "(2 + I) x^(1 + I)"); - EXPECT_EQ(Expression("derivative((2+I) ^ x, x)").toString(), - "(2 + I)^x ln(2 + I)"); - EXPECT_EQ(Expression("derivative(x deg, x)").toString(), - "Pi/180"); - EXPECT_EQ(Expression("derivative(x%, x)").toString(), - "1/100"); - EXPECT_EQ(Expression("derivative(x!, x)").toString(), - "derivative(x!, x)"); - EXPECT_EQ(Expression("derivative(sqrt(x), x)").toString(), - "1/(2 sqrt(x))"); - EXPECT_EQ(Expression("derivative(root(x, 3), x)").toString(), - "1/(3 x^(2/3))"); - EXPECT_EQ(Expression("derivative(root(x, 10), x)").toString(), - "1/(10 x^(9/10))"); - EXPECT_EQ(Expression("derivative(exp(x), x)").toString(), - "E^x"); - EXPECT_EQ(Expression("derivative(ln(x), x)").toString(), - "1/x"); - EXPECT_EQ(Expression("derivative(lb(x), x)").toString(), - "1/(ln(2) x)"); - EXPECT_EQ(Expression("derivative(lg(x), x)").toString(), - "1/(ln(10) x)"); - EXPECT_EQ(Expression("derivative(log(x, y), x)").toString(), - "-ln(y)/(ln(x)^2 x)"); - EXPECT_EQ(Expression("derivative(log(y, x), x)").toString(), - "1/(x ln(y))"); - EXPECT_EQ(Expression("derivative(log(x, 2), x)").toString(), - "-ln(2)/(ln(x)^2 x)"); - EXPECT_EQ(Expression("derivative(log(2, x), x)").toString(), - "1/(ln(2) x)"); - EXPECT_EQ(Expression("derivative(log(x, (3/5)), x)").toString(), - "-ln(3/5)/(ln(x)^2 x)"); - EXPECT_EQ(Expression("derivative(log((3/5), x), x)").toString(), - "1/(ln(3/5) x)"); - EXPECT_EQ(Expression("derivative(log(x, (-3/5)), x)").toString(), - "-ln(-3/5)/(ln(x)^2 x)"); - EXPECT_EQ(Expression("derivative(log((-3/5), x), x)").toString(), - "1/(ln(-3/5) x)"); - EXPECT_EQ(Expression("derivative(log(x, (2+I)), x)").toString(), - "-ln(2 + I)/(ln(x)^2 x)"); - EXPECT_EQ(Expression("derivative(log((2+I), x), x)").toString(), - "1/(ln(2 + I) x)"); - EXPECT_EQ(Expression("derivative(sin(x), x)").toString(), - "cos(x)"); - EXPECT_EQ(Expression("derivative(sin(x^2), x)").toString(), - "2 x cos(x^2)"); - EXPECT_EQ(Expression("derivative(cos(x), x)").toString(), - "-sin(x)"); - EXPECT_EQ(Expression("derivative(cos(x^2), x)").toString(), - "-2 x sin(x^2)"); - EXPECT_EQ(Expression("derivative(tan(x), x)").toString(), - "sec(x)^2"); - EXPECT_EQ(Expression("derivative(tan(x^2), x)").toString(), - "2 x sec(x^2)^2"); - EXPECT_EQ(Expression("derivative(cot(x), x)").toString(), - "-csc(x)^2"); - EXPECT_EQ(Expression("derivative(cot(x^2), x)").toString(), - "-2 x csc(x^2)^2"); - EXPECT_EQ(Expression("derivative(sec(x), x)").toString(), - "sec(x)^2 sin(x)"); - EXPECT_EQ(Expression("derivative(sec(x^2), x)").toString(), - "2 x sec(x^2)^2 sin(x^2)"); - EXPECT_EQ(Expression("derivative(csc(x), x)").toString(), - "-csc(x)^2 cos(x)"); - EXPECT_EQ(Expression("derivative(csc(x^2), x)").toString(), - "-2 x csc(x^2)^2 cos(x^2)"); - EXPECT_EQ(Expression("derivative(asin(x), x)").toString(), - "1/sqrt(-x^2 + 1)"); - EXPECT_EQ(Expression("derivative(asin(x^2), x)").toString(), - "(2 x)/sqrt(-x^4 + 1)"); - EXPECT_EQ(Expression("derivative(acos(x), x)").toString(), - "-1/sqrt(-x^2 + 1)"); - EXPECT_EQ(Expression("derivative(acos(x^2), x)").toString(), - "-(2 x)/sqrt(-x^4 + 1)"); - EXPECT_EQ(Expression("derivative(atan(x), x)").toString(), - "1/(x^2 + 1)"); - EXPECT_EQ(Expression("derivative(atan(x^2), x)").toString(), - "(2 x)/(x^4 + 1)"); - EXPECT_EQ(Expression("derivative(acot(x), x)").toString(), - "-1/(x^2 + 1)"); - EXPECT_EQ(Expression("derivative(acot(x^2), x)").toString(), - "-(2 x)/(x^4 + 1)"); - EXPECT_EQ(Expression("derivative(asec(x), x)").toString(), - "1/(sqrt(1 - 1/(x^2)) x^2)"); - EXPECT_EQ(Expression("derivative(asec(x^2), x)").toString(), - "2/(sqrt(1 - 1/(x^4)) x^3)"); - EXPECT_EQ(Expression("derivative(acsc(x), x)").toString(), - "-1/(sqrt(1 - 1/(x^2)) x^2)"); - EXPECT_EQ(Expression("derivative(acsc(x^2), x)").toString(), - "-2/(sqrt(1 - 1/(x^4)) x^3)"); - EXPECT_EQ(Expression("derivative(sinh(x), x)").toString(), - "cosh(x)"); - EXPECT_EQ(Expression("derivative(sinh(x^2), x)").toString(), - "2 x cosh(x^2)"); - EXPECT_EQ(Expression("derivative(cosh(x), x)").toString(), - "sinh(x)"); - EXPECT_EQ(Expression("derivative(cosh(x^2), x)").toString(), - "2 x sinh(x^2)"); - EXPECT_EQ(Expression("derivative(tanh(x), x)").toString(), - "sech(x)^2"); - EXPECT_EQ(Expression("derivative(tanh(x^2), x)").toString(), - "2 x sech(x^2)^2"); - EXPECT_EQ(Expression("derivative(coth(x), x)").toString(), - "-csch(x)^2"); - EXPECT_EQ(Expression("derivative(coth(x^2), x)").toString(), - "-2 x csch(x^2)^2"); - EXPECT_EQ(Expression("derivative(sech(x), x)").toString(), - "-sech(x)^2 sinh(x)"); - EXPECT_EQ(Expression("derivative(sech(x^2), x)").toString(), - "-2 x sech(x^2)^2 sinh(x^2)"); - EXPECT_EQ(Expression("derivative(csch(x), x)").toString(), - "-csch(x)^2 cosh(x)"); - EXPECT_EQ(Expression("derivative(csch(x^2), x)").toString(), - "-2 x csch(x^2)^2 cosh(x^2)"); - EXPECT_EQ(Expression("derivative(asinh(x), x)").toString(), - "1/sqrt(x^2 + 1)"); - EXPECT_EQ(Expression("derivative(asinh(x^2), x)").toString(), - "(2 x)/sqrt(x^4 + 1)"); - EXPECT_EQ(Expression("derivative(acosh(x), x)").toString(), - "1/(sqrt(x + 1) sqrt(x - 1))"); - EXPECT_EQ(Expression("derivative(acosh(x^2), x)").toString(), - "(2 x)/(sqrt(x^2 + 1) sqrt(x^2 - 1))"); - EXPECT_EQ(Expression("derivative(atanh(x), x)").toString(), - "-1/(x^2 - 1)"); - EXPECT_EQ(Expression("derivative(atanh(x^2), x)").toString(), - "-(2 x)/(x^4 - 1)"); - EXPECT_EQ(Expression("derivative(acoth(x), x)").toString(), - "-1/(x^2 - 1)"); - EXPECT_EQ(Expression("derivative(acoth(x^2), x)").toString(), - "-(2 x)/(x^4 - 1)"); - EXPECT_EQ(Expression("derivative(asech(x), x)").toString(), - "-1/(sqrt(1 + 1/x) sqrt(-1 + 1/x) x^2)"); - EXPECT_EQ(Expression("derivative(asech(x^2), x)").toString(), - "-2/(sqrt(1 + 1/(x^2)) sqrt(-1 + 1/(x^2)) x^3)"); - EXPECT_EQ(Expression("derivative(acsch(x), x)").toString(), - "-1/(sqrt(1 + 1/(x^2)) x^2)"); - EXPECT_EQ(Expression("derivative(acsch(x^2), x)").toString(), - "-2/(sqrt(1 + 1/(x^4)) x^3)"); - EXPECT_EQ(Expression("derivative(abs(x), x)").toString(), - "derivative(abs(x), x)"); - EXPECT_EQ(Expression("derivative(sign(x), x)").toString(), - "derivative(sign(x), x)"); - EXPECT_EQ(Expression("derivative(floor(x), x)").toString(), - "derivative(floor(x), x)"); - EXPECT_EQ(Expression("derivative(ceil(x), x)").toString(), - "derivative(ceil(x), x)"); - EXPECT_EQ(Expression("derivative(min(x, y), x)").toString(), - "derivative(min(x, y), x)"); - EXPECT_EQ(Expression("derivative(max(x, y), x)").toString(), - "derivative(max(x, y), x)"); - EXPECT_EQ(Expression("derivative(integral(x!, x), x)").toString(), - "derivative(integral(x!, x), x)"); - EXPECT_EQ(Expression("derivative(a b x, x)").toString(), - "a b"); - EXPECT_EQ(Expression("derivative(a b c x, x)").toString(), - "a b c"); - EXPECT_EQ(Expression("derivative(a x y, x)").toString(), - "a y"); - EXPECT_EQ(Expression("derivative(x y z, x)").toString(), - "y z"); - EXPECT_EQ(Expression("derivative(x y z z_1, x)").toString(), - "y z z_1"); - EXPECT_EQ(Expression("derivative(3x^2 - 2x, x)").toString(), - "6 x - 2"); - EXPECT_EQ(Expression("derivative(x^4 - 3x^3 + 2x - 1, x)").toString(), - "4 x^3 - 9 x^2 + 2"); - EXPECT_EQ(Expression("derivative(x^2 cos(x), x)").toString(), - "-x^2 sin(x) + 2 x cos(x)"); - EXPECT_EQ(Expression("derivative(E^(x^2 + 2x), x)").toString(), - "2 E^(x^2 + 2 x) x + 2 E^(x^2 + 2 x)"); // TODO: 2 E^(x^2 + 2 x) (x + 1) - EXPECT_EQ(Expression("derivative(E^sin(x), x)").toString(), - "E^sin(x) cos(x)"); - EXPECT_EQ(Expression("derivative(5E^(-x^3), x)").toString(), - "-15 E x^2 E^(-x^3 - 1)"); // TODO: -15 E^(-x^3) x^2 - EXPECT_EQ(Expression("derivative(8^(x^2 - 5x), x)").toString(), - "(16*8^(x^2 - 5 x - 1) x - 40*8^(x^2 - 5 x - 1)) ln(8)"); // TODO: simplify this - EXPECT_EQ(Expression("derivative((1 + 5x)^3, x)").toString(), - "375 x^2 + 150 x + 15"); - EXPECT_EQ(Expression("derivative(x^5 (2 - x/3 + 3x^2), x)").toString(), - "21 x^6 - 2 x^5 + 10 x^4"); - EXPECT_EQ(Expression("derivative(x^3 3^x, x)").toString(), - "x^3*3^x ln(3) + 3 x^2*3^x"); - EXPECT_EQ(Expression("derivative(ln(3x + 5), x)").toString(), - "3/(3 x + 5)"); - EXPECT_EQ(Expression("derivative(ln(x^5 - 2x^2 + 5), x)").toString(), - "(5 x^4 - 4 x)/(x^5 - 2 x^2 + 5)"); - EXPECT_EQ(Expression("derivative(lb(sin(x)^2), x)").toString(), - "(2 cot(x))/ln(2)"); - EXPECT_EQ(Expression("derivative(root(2 + x^4, 3), x)").toString(), - "(4 x^3)/(3 (x^4 + 2)^(2/3))"); - EXPECT_EQ(Expression("derivative(sqrt(x) + 5/root(x, 5) - 1/x^9 + 7/(9x^5), x)").toString(), - "9/(x^10) - 35/(9 x^6) - 1/(x^(6/5)) + 1/(2 sqrt(x))"); - EXPECT_EQ(Expression("derivative(cos(5x), x)").toString(), - "-5 sin(5 x)"); - EXPECT_EQ(Expression("derivative(asin(5x), x)").toString(), - "5/sqrt(-25 x^2 + 1)"); - EXPECT_EQ(Expression("derivative(sin(x)^2, x)").toString(), - "sin(2 x)"); - EXPECT_EQ(Expression("derivative(cos(x)^2, x)").toString(), - "-sin(2 x)"); - EXPECT_EQ(Expression("derivative(ln(cos(3x)), x)").toString(), - "-3 tan(3 x)"); - EXPECT_EQ(Expression("derivative(log(sin(x^5), tan(x^3)), x)").toString(), - "(3 sec(x^3)^2 x^2 cos(x^3) csc(x^3))/ln(sin(x^5)) - (5 x^4 cos(x^5) csc(x^5) ln(tan(x^3)))/(ln(sin(x^5))^2)"); - EXPECT_EQ(Expression("derivative(acos(4x + 5)^5, x)").toString(), - "-(20 acos(4 x + 5)^4)/sqrt(-16 x^2 - 40 x - 24)"); - EXPECT_EQ(Expression("derivative(sin(sin(sin(x))), x)").toString(), - "cos(sin(sin(x))) cos(sin(x)) cos(x)"); - EXPECT_EQ(Expression("derivative(cos(tan(cot(x))), x)").toString(), - "sec(cot(x))^2 csc(x)^2 sin(tan(cot(x)))"); - EXPECT_EQ(Expression("derivative(a b cos(x), x)").toString(), - "-a b sin(x)"); - EXPECT_EQ(Expression("derivative(a x cos(x) ln(x) sign(x), x)").toString(), - "(a x derivative(sign(x), x) cos(x) - a x sin(x) sign(x) + a cos(x) sign(x)) ln(x) + a cos(x) sign(x)"); - EXPECT_EQ(Expression("derivative(a * c * cos(x)/(x^2 + 1), x)").toString(), - "-(a c x^2 sin(x) + 2 a c x cos(x) + a c sin(x))/(x^4 + 2 x^2 + 1)"); - EXPECT_EQ(Expression("derivative((2x^3)/tan(x), x)").toString(), - "-2 x^3 csc(x)^2 + 6 x^2 cot(x)"); - EXPECT_EQ(Expression("derivative(acos(x)/(x^2 + 1), x)").toString(), - "-(x^2 + 2 x sqrt(-x^2 + 1) acos(x) + 1)/(sqrt(-x^2 + 1) x^4 + 2 sqrt(-x^2 + 1) x^2 + sqrt(-x^2 + 1))"); - EXPECT_EQ(Expression("derivative(sin(x)/sinh(x), x)").toString(), - "-csch(x)^2 sin(x) cosh(x) + cos(x) csch(x)"); - EXPECT_EQ(Expression("derivative(tan(x)/tanh(x), x)").toString(), - "sec(x)^2 coth(x) - csch(x)^2 tan(x)"); - EXPECT_EQ(Expression("derivative(derivative(derivative(sin(x^3), x), x), x)").toString(), - "-27 x^6 cos(x^3) - 54 x^3 sin(x^3) + 6 cos(x^3)"); - EXPECT_EQ(Expression("derivative(x^2, x) + derivative(y^2, y)").toString(), - "2 x + 2 y"); - EXPECT_EQ(Expression("derivative(sin(x^3), x) + derivative(cos(y^3), y) / derivative(tan(ln(y)), y)").toString(), - "3 x^2 cos(x^3) - (3 y^3 sin(y^3))/(sec(ln(y))^2)"); -} diff --git a/tests/src/overall/simplify/SimplifyDivisionTests.cpp b/tests/src/overall/simplify/SimplifyDivisionTests.cpp deleted file mode 100644 index 8dbfb989c..000000000 --- a/tests/src/overall/simplify/SimplifyDivisionTests.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyDivisionTests, simplifyTest) { - EXPECT_EQ(Expression("-9 / (3x+3)").toString(), - "-3/(x + 1)"); - EXPECT_EQ(Expression("(4x^2 - 5x - 21) / (x - 3)").toString(), - "4 x + 7"); - EXPECT_EQ(Expression("(3x^3 - 5x^2 + 10x - 3) / (3x + 1)").toString(), - "x^2 - 2 x + 4 - 7/(3 x + 1)"); - EXPECT_EQ(Expression("(2x^3 - 9x^2 + 15) / (2x - 5)").toString(), - "x^2 - 2 x - 5 - 10/(2 x - 5)"); - EXPECT_EQ(Expression("(4x^4 + 1 + 3x^3 + 2x) / (x^2 + x + 2)").toString(), - "4 x^2 - x - 7 + (11 x + 15)/(x^2 + x + 2)"); - EXPECT_EQ(Expression("(2x^4 - 3x^3 + 4x^2 - 5x + 6) / (x^2 + 2x - 3)").toString(), - "2 x^2 - 7 x + 24 - (74 x - 78)/(x^2 + 2 x - 3)"); - EXPECT_EQ(Expression("(4x^5 + 2x^4 - 6x^3 + 3x^2 + x - 2) / (2x^3 + x^2 - 3x + 2)").toString(), - "2 x^2 - (x^2 - x + 2)/(2 x^3 + x^2 - 3 x + 2)"); - EXPECT_EQ(Expression("(3x^6 + 5x^5 - 2x^4 + 4x^3 + x^2 + 3x - 5) / (x^4 + 3x^2 - 2)").toString(), - "3 x^2 + 5 x - 11 - (11 x^3 - 40 x^2 - 13 x + 27)/(x^4 + 3 x^2 - 2)"); - EXPECT_EQ(Expression("(6x^8 - 7x^6 + 9x^4 - 4x^2 + 8) / (2x^3 - x^2 + 3x - 1)").toString(), - "3 x^5 + (3 x^4)/2 - (29 x^3)/4 - (35 x^2)/8 + (223 x)/16 + 317/32 - (1289 x^2 + 505 x - 573)/(64 x^3 - 32 x^2 + 96 x - 32)"); - EXPECT_EQ(Expression("(2 a^3 + 5 a^2 b + 4 a b^2 + b^3)/(25 a^2 + 40 a b + 15 b^2)").toString(), - "(2 a)/25 + (9 b)/125 - (2 a b^2 + 2 b^3)/(625 a^2 + 1000 a b + 375 b^2)"); - EXPECT_EQ(Expression("(25 a^2 + 40 a b + 15 b^2)/(2 a^3 + 5 a^2 b + 4 a b^2 + b^3)").toString(), - "(25 a^2 + 40 a b + 15 b^2)/(2 a^3 + 5 a^2 b + 4 a b^2 + b^3)"); - EXPECT_EQ(Expression("(x^2 + 2x + 1)/(x^3 + 3x^2 + 3x + 1)").toString(), - "1/(x + 1)"); - EXPECT_EQ(Expression("5/(a+b) + 5/(2a+b) + 5/(a+b)").toString(), - "(25 a^2 + 40 a b + 15 b^2)/(2 a^3 + 5 a^2 b + 4 a b^2 + b^3)"); - EXPECT_EQ(Expression("(x+y)/(a+b) + 5/(2a+b) + (x+2y)/(a+b)").toString(), - "(4 a^2 x + 6 a^2 y + 5 a^2 + 6 a b x + 9 a b y + 10 a b + 2 b^2 x + 3 b^2 y + 5 b^2)/(2 a^3 + 5 a^2 b + 4 a b^2 + b^3)"); // TODO: "(4 a x + 6 a y + 5 a + 2 b x + 3 b y + 5 b)/(2 a^2 + 3 a b + b^2)" - EXPECT_EQ(Expression("(a/b)(c/d)").toString(), - "(a c)/(b d)"); - EXPECT_EQ(Expression("(ab/2)(ad/3)").toString(), - "(a^2 b d)/6"); - EXPECT_EQ(Expression("(-a)(-b)").toString(), - "a b"); - EXPECT_EQ(Expression("(a)(-b)").toString(), - "-a b"); - EXPECT_EQ(Expression("(-a)(b)").toString(), - "-a b"); - EXPECT_EQ(Expression("(5/3 b)/a").toString(), - "(5 b)/(3 a)"); - EXPECT_EQ(Expression("(5/3 + b)/(2/5 + a)").toString(), - "(15 b + 25)/(15 a + 6)"); - EXPECT_EQ(Expression("(a b)/(a b)").toString(), - "1"); - EXPECT_EQ(Expression("(a b)/1").toString(), - "a b"); - EXPECT_EQ(Expression("(a b)/-1").toString(), - "-a b"); - EXPECT_EQ(Expression("(a b)/-2").toString(), - "-(a b)/2"); - EXPECT_EQ(Expression("(a b)/(-a - b)").toString(), - "-b + (b^2)/(a + b)"); - EXPECT_EQ(Expression("(x^5)/(x - y)").toString(), - "x^4 + x^3 y + x^2 y^2 + x y^3 + y^4 + (y^5)/(x - y)"); - EXPECT_EQ(Expression("(3 x + 5/9)/(2y - 9/x + 3/2 x + 1/2 + 2 y / x)").toString(), - "2 - (72 x^2 y + 8 x^2 + 72 x y - 324 x)/(27 x^3 + 36 x^2 y + 9 x^2 + 36 x y - 162 x)"); // TODO: "2 - (72 x y + 8 x + 72 y - 324)/(27 x^2 + 36 x y + 9 x + 36 y - 162)" - EXPECT_EQ(Expression("(a/x + b/(y+3/r)/4)/(3+t/5)").toString(), - "(20 a r y + 60 a + 5 b r x)/(4 r t x y + 60 r x y + 12 t x + 180 x)"); - EXPECT_EQ(Expression("(x/a - (b+5)/(y-8/(12 y))/4)/(8-a/5)").toString(), - "(15 a b y + 75 a y - 60 x y^2 + 40 x)/(12 a^2 y^2 - 8 a^2 - 480 a y^2 + 320 a)"); - EXPECT_EQ(Expression("(a + b + c^2) / ((a + b + c^3) / (5/2 * (a + b) / (3/b + c/2)))").toString(), - "5 c + (5 a^2 b + 10 a b^2 - 30 a c + 5 b^3 - 5 b c^5 - 30 b c - 30 c^4)/(a b c + 6 a + b^2 c + b c^4 + 6 " - "b + 6 c^3)"); - EXPECT_EQ(Expression("((2xy)/(x^2 - y^2) + (x - y)/(2x + 2y)) * (2x)/(x + y) + y/(y - x)").toString(), - "1"); - EXPECT_EQ(Expression("y/(x - y) - (x ^3 - xy ^2)/(x ^2 + y ^2) * (x/((x - y) ^2) - y/(x ^2 - y ^2))").toString(), - "-1"); - EXPECT_EQ(Expression("(a+3)/(b+2)").toString(), - "(a + 3)/(b + 2)"); - EXPECT_EQ(Expression("b/a*(a+3)/(b+2)").toString(), - "1 - (2 a - 3 b)/(a b + 2 a)"); - EXPECT_EQ(Expression("(5+b)/a*(a+3)/(b+2)").toString(), - "1 + (3 a + 3 b + 15)/(a b + 2 a)"); - EXPECT_EQ(Expression("(a+b)*(a+b)/(a+b)").toString(), - "a + b"); - EXPECT_EQ(Expression("(a+b)*(a+b)*(1/(a+b))").toString(), - "a + b"); - EXPECT_EQ(Expression("(x^2+2x+1)/(x+1)").toString(), - "x + 1"); - EXPECT_EQ(Expression("(1/2 + sqrt(3)) / (x^(1/4) + 6)").toString(), - "(2 sqrt(3) + 1)/(2 root(x, 4) + 12)"); - EXPECT_EQ(Expression("(x^2 + sqrt(y) - 45) / (sqrt(3) + 3)").toString(), - "(x^2 + sqrt(y) - 45)/(sqrt(3) + 3)"); - EXPECT_EQ(Expression("(x^2 + sqrt(y) - 45x) / (root(3, 4) + 3)").toString(), - "(x^2 - 45 x + sqrt(y))/(root(3, 4) + 3)"); - EXPECT_EQ(Expression("(x^2 + sqrt(y) - 45x) / (root(3, 4) x + 3)").toString(), - "(root(27, 4) x)/3 - sqrt(3) - 15 root(27, 4) + (sqrt(y) + 45 root(27, 4) + 3 sqrt(3))/(root(3, 4) x + 3)"); - EXPECT_EQ(Expression("(sqrt(-4 a c + b^2) - b) / (2 a)").toString(), - "(sqrt(-4 a c + b^2) - b)/(2 a)"); -} diff --git a/tests/src/overall/simplify/SimplifyFactorialTests.cpp b/tests/src/overall/simplify/SimplifyFactorialTests.cpp deleted file mode 100644 index 14bf311ff..000000000 --- a/tests/src/overall/simplify/SimplifyFactorialTests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyFactorialTests, simplifyTest) { - EXPECT_EQ(Expression("9!").toString(), - "362880"); - EXPECT_EQ(Expression("-1!").toString(), - "-1"); - EXPECT_EQ(Expression("-100!").toString(), - "-933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536" - "97920827223758251185210916864000000000000000000000000"); - EXPECT_EQ(Expression("(5!)!").toString(), - "6689502913449127057588118054090372586752746333138029810295671352301633557244962989366874165271984981308157" - "637893214090552534408589408121859898481114389650005964960521256960000000000000000000000000000"); - EXPECT_EQ(Expression("(2)!").toString(), - "2"); - - EXPECT_EQ(Expression("5!").toString(), - "120"); - EXPECT_EQ(Expression("5!!").toString(), - "15"); - EXPECT_EQ(Expression("5!!!").toString(), - "10"); - EXPECT_EQ(Expression("5!!!!").toString(), - "5"); - EXPECT_EQ(Expression("5!!!!!").toString(), - "5"); - EXPECT_EQ(Expression("5!!!!!!").toString(), - "5"); - EXPECT_EQ(Expression("6!").toString(), - "720"); - EXPECT_EQ(Expression("6!!").toString(), - "48"); - EXPECT_EQ(Expression("6!!!").toString(), - "18"); - EXPECT_EQ(Expression("6!!!!").toString(), - "12"); - EXPECT_EQ(Expression("6!!!!!").toString(), - "6"); - EXPECT_EQ(Expression("6!!!!!!").toString(), - "6"); - EXPECT_EQ(Expression("15!!!!!!").toString(), - "405"); - EXPECT_EQ(Expression("15!!!!!!!").toString(), - "120"); - EXPECT_EQ(Expression("30!!!!!!").toString(), - "933120"); - EXPECT_EQ(Expression("30!!!!!!!").toString(), - "198720"); - - EXPECT_EQ(Expression("(2/3)!").toString(), - "(2/3)!"); - EXPECT_EQ(Expression("E!").toString(), - "E!"); - EXPECT_EQ(Expression("(2/3)!!").toString(), - "(2/3)!!"); - EXPECT_EQ(Expression("(-1)!!").toString(), - "(-1)!!"); -} diff --git a/tests/src/overall/simplify/SimplifyHyperbolicTests.cpp b/tests/src/overall/simplify/SimplifyHyperbolicTests.cpp deleted file mode 100644 index aa67a0005..000000000 --- a/tests/src/overall/simplify/SimplifyHyperbolicTests.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyHyperbolicTests, simplifyTest) { - EXPECT_EQ(Expression("sinh(-x)").toString(), - "-sinh(x)"); - EXPECT_EQ(Expression("cosh(-x)").toString(), - "cosh(x)"); - EXPECT_EQ(Expression("tanh(-x)").toString(), - "-tanh(x)"); - EXPECT_EQ(Expression("coth(-x)").toString(), - "-coth(x)"); - EXPECT_EQ(Expression("sech(-x)").toString(), - "sech(x)"); - EXPECT_EQ(Expression("csch(-x)").toString(), - "-csch(x)"); - - EXPECT_EQ(Expression("sinh(asinh(x))").toString(), - "x"); - EXPECT_EQ(Expression("cosh(acosh(x))").toString(), - "x"); - EXPECT_EQ(Expression("tanh(atanh(x))").toString(), - "x"); - EXPECT_EQ(Expression("coth(acoth(x))").toString(), - "x"); - EXPECT_EQ(Expression("sech(asech(x))").toString(), - "x"); - EXPECT_EQ(Expression("csch(acsch(x))").toString(), - "x"); - EXPECT_EQ(Expression("asinh(sinh(x))").toString(), - "asinh(sinh(x))"); - EXPECT_EQ(Expression("acosh(cosh(x))").toString(), - "acosh(cosh(x))"); - EXPECT_EQ(Expression("atanh(tanh(x))").toString(), - "atanh(tanh(x))"); - EXPECT_EQ(Expression("acoth(coth(x))").toString(), - "acoth(coth(x))"); - EXPECT_EQ(Expression("asech(sech(x))").toString(), - "asech(sech(x))"); - EXPECT_EQ(Expression("acsch(csch(x))").toString(), - "acsch(csch(x))"); - - EXPECT_EQ(Expression("sinh(x)/cosh(x)").toString(), - "tanh(x)"); - EXPECT_EQ(Expression("(-2sinh(x))/cosh(x)").toString(), - "-2 tanh(x)"); - EXPECT_EQ(Expression("(2sinh(x))/(3cosh(x))").toString(), - "(2 tanh(x))/3"); - EXPECT_EQ(Expression("sinh(x)^2/cosh(x)").toString(), - "sinh(x)^2 sech(x)"); - EXPECT_EQ(Expression("sinh(x)/cosh(x)^2").toString(), - "sech(x)^2 sinh(x)"); - EXPECT_EQ(Expression("sinh(x)^2/cosh(x)^2").toString(), - "tanh(x)^2"); - EXPECT_EQ(Expression("(2sinh(x))^2/cosh(x)^2").toString(), - "4 tanh(x)^2"); - EXPECT_EQ(Expression("(2sinh(x))^2/(3cosh(x))^2").toString(), - "(4 tanh(x)^2)/9"); - - EXPECT_EQ(Expression("cosh(x)/sinh(x)").toString(), - "coth(x)"); - EXPECT_EQ(Expression("(-2cosh(x))/sinh(x)").toString(), - "-2 coth(x)"); - EXPECT_EQ(Expression("(2cosh(x))/(3sinh(x))").toString(), - "(2 coth(x))/3"); - EXPECT_EQ(Expression("cosh(x)^2/sinh(x)").toString(), - "cosh(x)^2 csch(x)"); - EXPECT_EQ(Expression("cosh(x)/sinh(x)^2").toString(), - "csch(x)^2 cosh(x)"); - EXPECT_EQ(Expression("cosh(x)^2/sinh(x)^2").toString(), - "coth(x)^2"); - EXPECT_EQ(Expression("(2cosh(x))^2/sinh(x)^2").toString(), - "4 coth(x)^2"); - EXPECT_EQ(Expression("(2cosh(x))^2/(3sinh(x))^2").toString(), - "(4 coth(x)^2)/9"); - - EXPECT_EQ(Expression("sech(x)/csch(x)").toString(), - "tanh(x)"); - EXPECT_EQ(Expression("csch(x)/sech(x)").toString(), - "coth(x)"); - EXPECT_EQ(Expression("sech(x)*coth(x)").toString(), - "csch(x)"); - EXPECT_EQ(Expression("csch(x)*tanh(x)").toString(), - "sech(x)"); - - EXPECT_EQ(Expression("tanh(x) * coth(x)").toString(), - "1"); - EXPECT_EQ(Expression("coth(x) * tanh(x)").toString(), - "1"); - // TODO: implement - // EXPECT_EQ(Expression("cosh(x)^2 - sinh(x)^2").toString(), - // "1"); -} diff --git a/tests/src/overall/simplify/SimplifyInfinityTests.cpp b/tests/src/overall/simplify/SimplifyInfinityTests.cpp deleted file mode 100644 index 139f7b26c..000000000 --- a/tests/src/overall/simplify/SimplifyInfinityTests.cpp +++ /dev/null @@ -1,710 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyInfinityTests, simplifyTest) { - EXPECT_EQ(Expression("Inf").toString(), - "Inf"); - EXPECT_EQ(Expression("-Inf").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("0/Inf").toString(), - "0"); - EXPECT_EQ(Expression("Inf/0").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("0/-Inf").toString(), - "0"); - EXPECT_EQ(Expression("-Inf/0").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("0/ComplexInf").toString(), - "0"); - EXPECT_EQ(Expression("ComplexInf/0").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("0 / (Inf x)").toString(), - "0"); - EXPECT_EQ(Expression("(Inf/x) / 0").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("1/Inf - 1").toString(), - "-1"); - EXPECT_EQ(Expression("Inf/2 - 1").toString(), - "Inf"); - 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("I + Inf").toString(), - "Inf"); - EXPECT_EQ(Expression("I - Inf").toString(), - "-Inf"); - EXPECT_EQ(Expression("I + ComplexInf").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("a + Inf").toString(), - "Inf"); - EXPECT_EQ(Expression("-a - Inf").toString(), - "-Inf"); - EXPECT_EQ(Expression("a + ComplexInf").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("a - ComplexInf").toString(), - "ComplexInf"); - 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("(I+2) * Inf").toString(), - "(2 + I) Inf"); - EXPECT_EQ(Expression("(I+2) * -Inf").toString(), - "(-2 - I) Inf"); - EXPECT_EQ(Expression("(I+2) * ComplexInf").toString(), - "ComplexInf"); - 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("a * Inf").toString(), - "Inf a"); - EXPECT_EQ(Expression("Inf * (Inf x)").toString(), - "Inf x"); - EXPECT_EQ(Expression("Inf * (Inf/x)").toString(), - "Inf/x"); - EXPECT_EQ(Expression("Inf / a").toString(), - "Inf/a"); - EXPECT_EQ(Expression("Inf / 2").toString(), - "Inf"); - EXPECT_EQ(Expression("Inf / -2").toString(), - "-Inf"); - EXPECT_EQ(Expression("Inf / I").toString(), - "-I Inf"); - EXPECT_EQ(Expression("Inf / (-I - 3)").toString(), - "-((3 - I) Inf)/10"); - EXPECT_EQ(Expression("Inf^2").toString(), - "Inf"); - EXPECT_EQ(Expression("Inf^(2/3)").toString(), - "Inf"); - EXPECT_EQ(Expression("Inf^-2").toString(), - "0"); - EXPECT_EQ(Expression("Inf^(-2/3)").toString(), - "0"); - EXPECT_EQ(Expression("(-Inf)^2").toString(), - "Inf"); - EXPECT_EQ(Expression("(-Inf)^3").toString(), - "-Inf"); - EXPECT_EQ(Expression("(-Inf)^(2/3)").toString(), - "Inf sign((-1)^(2/3))"); - EXPECT_EQ(Expression("ComplexInf^2").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("ComplexInf^(2/3)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("ComplexInf^-2").toString(), - "0"); - EXPECT_EQ(Expression("ComplexInf^(-2/3)").toString(), - "0"); - EXPECT_EQ(Expression("Inf^(I+2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("Inf^(I-2)").toString(), - "0"); - EXPECT_EQ(Expression("Inf^(-I+2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("Inf^(-I-2)").toString(), - "0"); - EXPECT_EQ(Expression("(-Inf)^(I+2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("(-Inf)^(I-2)").toString(), - "0"); - EXPECT_EQ(Expression("(-Inf)^(-I+2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("(-Inf)^(-I-2)").toString(), - "0"); - EXPECT_EQ(Expression("ComplexInf^(I+2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("ComplexInf^(I-2)").toString(), - "0"); - EXPECT_EQ(Expression("ComplexInf^(-I+2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("ComplexInf^(-I-2)").toString(), - "0"); - EXPECT_EQ(Expression("0^Inf").toString(), - "0"); - EXPECT_EQ(Expression("0^-Inf").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("0^-1").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("2^Inf").toString(), - "Inf"); - EXPECT_EQ(Expression("2^-Inf").toString(), - "0"); - EXPECT_EQ(Expression("0.2^Inf").toString(), - "0"); - EXPECT_EQ(Expression("0.2^-Inf").toString(), - "Inf"); - EXPECT_EQ(Expression("Inf^Inf").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("(-Inf)^Inf").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("ComplexInf^Inf").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("0^(Inf/x)").toString(), - "0^(Inf/x)"); - EXPECT_EQ(Expression("1^(Inf/x)").toString(), - "1^(Inf/x)"); - EXPECT_EQ(Expression("sqrt(2) * Inf").toString(), - "Inf"); - EXPECT_EQ(Expression("-sqrt(2) * Inf").toString(), - "-Inf"); - EXPECT_EQ(Expression("sqrt(2) ^ Inf").toString(), - "Inf"); - EXPECT_EQ(Expression("sqrt(0.5) ^ Inf").toString(), - "0"); - EXPECT_EQ(Expression("sqrt(2) ^ (-Inf)").toString(), - "0"); - EXPECT_EQ(Expression("sqrt(0.5) ^ (-Inf)").toString(), - "Inf"); - EXPECT_EQ(Expression("Inf ^ sqrt(5)").toString(), - "Inf"); - EXPECT_EQ(Expression("Inf ^ -sqrt(5)").toString(), - "0"); - EXPECT_EQ(Expression("(-Inf) ^ sqrt(5)").toString(), - "Inf sign((-1)^sqrt(5))"); - EXPECT_EQ(Expression("(-Inf) ^ -sqrt(5)").toString(), - "0"); - EXPECT_EQ(Expression("ComplexInf ^ sqrt(5)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("ComplexInf ^ -sqrt(5)").toString(), - "0"); - EXPECT_EQ(Expression("sin(Inf)").toString(), - "sin(Inf)"); // TODO: [-1, 1] - EXPECT_EQ(Expression("log(1, 0)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("log(1, 10)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("log(10, 0)").toString(), - "-Inf"); - EXPECT_EQ(Expression("log(1/10, 0)").toString(), - "Inf"); - EXPECT_EQ(Expression("ln(0)").toString(), - "-Inf"); - EXPECT_EQ(Expression("ln(Inf)").toString(), - "Inf"); - EXPECT_EQ(Expression("ln(-Inf)").toString(), - "Inf"); - EXPECT_EQ(Expression("ln(ComplexInf)").toString(), - "Inf"); - EXPECT_EQ(Expression("(-1)!").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("tan(Pi/2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("tan(3/2*Pi)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("cot(0)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("cot(2*Pi)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("sin(Inf)^2 + cos(Inf)^2").toString(), - "sin(Inf)^2 + cos(Inf)^2"); - EXPECT_EQ(Expression("sin(Inf) cos(Inf)").toString(), - "sin(Inf) cos(Inf)"); - EXPECT_EQ(Expression("tan(Inf)").toString(), - "tan(Inf)"); - EXPECT_EQ(Expression("tan(Inf) * cot(Inf)").toString(), - "tan(Inf) cot(Inf)"); - EXPECT_EQ(Expression("sign(Inf)").toString(), - "1"); - EXPECT_EQ(Expression("sign(-Inf)").toString(), - "-1"); - EXPECT_EQ(Expression("abs(Inf)").toString(), - "Inf"); - EXPECT_EQ(Expression("abs(-Inf)").toString(), - "Inf"); - EXPECT_EQ(Expression("abs(ComplexInf)").toString(), - "Inf"); - EXPECT_EQ(Expression("0/sign(Inf)").toString(), - "0"); - EXPECT_EQ(Expression("sign(Inf)/0").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("0^sign(Inf)").toString(), - "0"); - EXPECT_EQ(Expression("sign(Inf)^0").toString(), - "1"); - EXPECT_EQ(Expression("0 (Inf!)").toString(), - "0 Inf!"); - EXPECT_EQ(Expression("0/(Inf!)").toString(), - "0"); - EXPECT_EQ(Expression("(Inf!)/0").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("0^(Inf!)").toString(), - "0^(Inf!)"); - EXPECT_EQ(Expression("(Inf!)^0").toString(), - "(Inf!)^0"); - EXPECT_EQ(Expression("log((Inf!), (Inf!))").toString(), - "log(Inf!, Inf!)"); - EXPECT_EQ(Expression("log((Inf!), Inf)").toString(), - "log(Inf!, Inf)"); - EXPECT_EQ(Expression("log(Inf, (Inf!))").toString(), - "log(Inf, Inf!)"); - EXPECT_EQ(Expression("log((Inf!), 1)").toString(), - "log(Inf!, 1)"); - EXPECT_EQ(Expression("log(1, (Inf!))").toString(), - "log(1, Inf!)"); - - EXPECT_EQ(Expression("Inf = Inf").toString(), - "True"); - EXPECT_EQ(Expression("Inf = -Inf").toString(), - "False"); - EXPECT_EQ(Expression("-Inf = Inf").toString(), - "False"); - EXPECT_EQ(Expression("-Inf = -Inf").toString(), - "True"); - EXPECT_EQ(Expression("x = Inf").toString(), - "False"); - EXPECT_EQ(Expression("x = -Inf").toString(), - "False"); - EXPECT_EQ(Expression("Inf = x").toString(), - "False"); - EXPECT_EQ(Expression("-Inf = x").toString(), - "False"); - EXPECT_EQ(Expression("x != Inf").toString(), - "True"); - EXPECT_EQ(Expression("x != -Inf").toString(), - "True"); - EXPECT_EQ(Expression("Inf != x").toString(), - "True"); - EXPECT_EQ(Expression("-Inf != x").toString(), - "True"); - EXPECT_EQ(Expression("x > Inf").toString(), - "x > Inf"); - EXPECT_EQ(Expression("x < Inf").toString(), - "x < Inf"); - EXPECT_EQ(Expression("x <= Inf").toString(), - "x <= Inf"); - EXPECT_EQ(Expression("x >= Inf").toString(), - "x >= Inf"); - EXPECT_EQ(Expression("x > -Inf").toString(), - "x > -Inf"); - EXPECT_EQ(Expression("x < -Inf").toString(), - "x < -Inf"); - EXPECT_EQ(Expression("x <= -Inf").toString(), - "x <= -Inf"); - EXPECT_EQ(Expression("x >= -Inf").toString(), - "x >= -Inf"); - EXPECT_EQ(Expression("Inf > x").toString(), - "Inf > x"); - EXPECT_EQ(Expression("Inf < x").toString(), - "Inf < x"); - EXPECT_EQ(Expression("Inf <= x").toString(), - "Inf <= x"); - EXPECT_EQ(Expression("Inf >= x").toString(), - "Inf >= x"); - EXPECT_EQ(Expression("-Inf > x").toString(), - "-Inf > x"); - EXPECT_EQ(Expression("-Inf < x").toString(), - "-Inf < x"); - EXPECT_EQ(Expression("-Inf <= x").toString(), - "-Inf <= x"); - EXPECT_EQ(Expression("-Inf >= x").toString(), - "-Inf >= x"); - EXPECT_EQ(Expression("x Inf = Inf").toString(), - "Inf x = Inf"); - EXPECT_EQ(Expression("Inf = x Inf").toString(), - "Inf = Inf x"); - EXPECT_EQ(Expression("x Inf < Inf").toString(), - "Inf x < Inf"); - EXPECT_EQ(Expression("Inf < x Inf").toString(), - "Inf < Inf x"); - EXPECT_EQ(Expression("x Inf = 0").toString(), - "Inf x = 0"); - EXPECT_EQ(Expression("0 = x Inf").toString(), - "0 = Inf x"); - EXPECT_EQ(Expression("x Inf < 0").toString(), - "Inf x < 0"); - EXPECT_EQ(Expression("0 < x Inf").toString(), - "0 < Inf x"); - EXPECT_EQ(Expression("x = ComplexInf").toString(), - "False"); - EXPECT_EQ(Expression("x != ComplexInf").toString(), - "True"); - EXPECT_EQ(Expression("x < ComplexInf").toString(), - "x < ComplexInf"); - EXPECT_EQ(Expression("x > ComplexInf").toString(), - "x > ComplexInf"); - EXPECT_EQ(Expression("x <= ComplexInf").toString(), - "x <= ComplexInf"); - EXPECT_EQ(Expression("x >= ComplexInf").toString(), - "x >= ComplexInf"); - EXPECT_EQ(Expression("ComplexInf = x").toString(), - "False"); - EXPECT_EQ(Expression("ComplexInf != x").toString(), - "True"); - EXPECT_EQ(Expression("ComplexInf < x").toString(), - "ComplexInf < x"); - EXPECT_EQ(Expression("ComplexInf > x").toString(), - "ComplexInf > x"); - EXPECT_EQ(Expression("ComplexInf <= x").toString(), - "ComplexInf <= x"); - EXPECT_EQ(Expression("ComplexInf >= x").toString(), - "ComplexInf >= x"); - EXPECT_EQ(Expression("ComplexInf = ComplexInf").toString(), - "ComplexInf = ComplexInf"); - EXPECT_EQ(Expression("Inf = Inf").toString(), - "True"); - EXPECT_EQ(Expression("Inf != Inf").toString(), - "False"); - EXPECT_EQ(Expression("Inf > Inf").toString(), - "False"); - EXPECT_EQ(Expression("Inf < Inf").toString(), - "False"); - EXPECT_EQ(Expression("Inf <= Inf").toString(), - "True"); - EXPECT_EQ(Expression("-Inf >= Inf").toString(), - "False"); - EXPECT_EQ(Expression("-Inf = Inf").toString(), - "False"); - EXPECT_EQ(Expression("-Inf != Inf").toString(), - "True"); - EXPECT_EQ(Expression("-Inf > Inf").toString(), - "False"); - EXPECT_EQ(Expression("-Inf < Inf").toString(), - "True"); - EXPECT_EQ(Expression("-Inf <= Inf").toString(), - "True"); - EXPECT_EQ(Expression("-Inf >= Inf").toString(), - "False"); - EXPECT_EQ(Expression("Inf = -Inf").toString(), - "False"); - EXPECT_EQ(Expression("Inf != -Inf").toString(), - "True"); - EXPECT_EQ(Expression("Inf > -Inf").toString(), - "True"); - EXPECT_EQ(Expression("Inf < -Inf").toString(), - "False"); - EXPECT_EQ(Expression("Inf <= -Inf").toString(), - "False"); - EXPECT_EQ(Expression("Inf >= -Inf").toString(), - "True"); - EXPECT_EQ(Expression("ComplexInf = Inf").toString(), - "ComplexInf = Inf"); - EXPECT_EQ(Expression("ComplexInf != Inf").toString(), - "ComplexInf != Inf"); - EXPECT_EQ(Expression("ComplexInf > Inf").toString(), - "ComplexInf > Inf"); - EXPECT_EQ(Expression("ComplexInf < Inf").toString(), - "ComplexInf < Inf"); - EXPECT_EQ(Expression("ComplexInf >= Inf").toString(), - "ComplexInf >= Inf"); - EXPECT_EQ(Expression("ComplexInf <= Inf").toString(), - "ComplexInf <= Inf"); - EXPECT_EQ(Expression("ComplexInf = -Inf").toString(), - "ComplexInf = -Inf"); - EXPECT_EQ(Expression("ComplexInf != -Inf").toString(), - "ComplexInf != -Inf"); - EXPECT_EQ(Expression("ComplexInf > -Inf").toString(), - "ComplexInf > -Inf"); - EXPECT_EQ(Expression("ComplexInf < -Inf").toString(), - "ComplexInf < -Inf"); - EXPECT_EQ(Expression("ComplexInf >= -Inf").toString(), - "ComplexInf >= -Inf"); - EXPECT_EQ(Expression("ComplexInf <= -Inf").toString(), - "ComplexInf <= -Inf"); - EXPECT_EQ(Expression("Inf = ComplexInf").toString(), - "Inf = ComplexInf"); - EXPECT_EQ(Expression("Inf != ComplexInf").toString(), - "Inf != ComplexInf"); - EXPECT_EQ(Expression("Inf > ComplexInf").toString(), - "Inf > ComplexInf"); - EXPECT_EQ(Expression("Inf < ComplexInf").toString(), - "Inf < ComplexInf"); - EXPECT_EQ(Expression("Inf >= ComplexInf").toString(), - "Inf >= ComplexInf"); - EXPECT_EQ(Expression("Inf <= ComplexInf").toString(), - "Inf <= ComplexInf"); - EXPECT_EQ(Expression("-Inf = ComplexInf").toString(), - "-Inf = ComplexInf"); - EXPECT_EQ(Expression("-Inf != ComplexInf").toString(), - "-Inf != ComplexInf"); - EXPECT_EQ(Expression("-Inf > ComplexInf").toString(), - "-Inf > ComplexInf"); - EXPECT_EQ(Expression("-Inf < ComplexInf").toString(), - "-Inf < ComplexInf"); - EXPECT_EQ(Expression("-Inf >= ComplexInf").toString(), - "-Inf >= ComplexInf"); - EXPECT_EQ(Expression("-Inf <= ComplexInf").toString(), - "-Inf <= ComplexInf"); - EXPECT_EQ(Expression("Inf * Inf + Inf - Inf * -1% = Inf").toString(), - "True"); - EXPECT_EQ(Expression("Inf * Inf + Inf - Inf * -1% != Inf").toString(), - "False"); - EXPECT_EQ(Expression("Inf * Inf + Inf - Inf * -1% < Inf").toString(), - "False"); - EXPECT_EQ(Expression("Inf * Inf + Inf - Inf * -1% > Inf").toString(), - "False"); - EXPECT_EQ(Expression("Inf * Inf + Inf - Inf * -1% <= Inf").toString(), - "True"); - EXPECT_EQ(Expression("Inf * Inf + Inf - Inf * -1% >= Inf").toString(), - "True"); - - 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("Inf + ComplexInf").toString(), - "Undefined"); - EXPECT_EQ(Expression("-Inf + ComplexInf").toString(), - "Undefined"); - EXPECT_EQ(Expression("0/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("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("x 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("(-Inf)^0").toString(), - "Undefined"); - EXPECT_EQ(Expression("ComplexInf^0").toString(), - "Undefined"); - EXPECT_EQ(Expression("Inf^I").toString(), - "Undefined"); - EXPECT_EQ(Expression("(-Inf)^I").toString(), - "Undefined"); - EXPECT_EQ(Expression("(ComplexInf)^I").toString(), - "Undefined"); - EXPECT_EQ(Expression("1^Inf").toString(), - "Undefined"); - EXPECT_EQ(Expression("1^-Inf").toString(), - "Undefined"); - EXPECT_EQ(Expression("1^ComplexInf").toString(), - "Undefined"); - EXPECT_EQ(Expression("x^ComplexInf").toString(), - "Undefined"); - EXPECT_EQ(Expression("I^Inf").toString(), - "Undefined"); - EXPECT_EQ(Expression("I^-Inf").toString(), - "Undefined"); - EXPECT_EQ(Expression("I^ComplexInf").toString(), - "Undefined"); - EXPECT_EQ(Expression("2^ComplexInf").toString(), - "Undefined"); - EXPECT_EQ(Expression("0.2^ComplexInf").toString(), - "Undefined"); - EXPECT_EQ(Expression("(x Inf)^0").toString(), - "Undefined"); - EXPECT_EQ(Expression("0^(x Inf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("1^(x Inf)").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("sin(-((2^2 - 4)^0))").toString(), - "Undefined"); - EXPECT_EQ(Expression("0^0 - 0^0").toString(), - "Undefined"); - EXPECT_EQ(Expression("0^0 * 0").toString(), - "Undefined"); - EXPECT_EQ(Expression("0^0 / 0").toString(), - "Undefined"); - EXPECT_EQ(Expression("0 / 0^0").toString(), - "Undefined"); - EXPECT_EQ(Expression("0^0 / 0^0").toString(), - "Undefined"); - EXPECT_EQ(Expression("(x/x - 1)^0 / 0^0").toString(), - "Undefined"); - EXPECT_EQ(Expression("0/0 - 0/0").toString(), - "Undefined"); - EXPECT_EQ(Expression("0/0 * 0").toString(), - "Undefined"); - EXPECT_EQ(Expression("0/0 / 0").toString(), - "Undefined"); - EXPECT_EQ(Expression("Inf / (Inf x)").toString(), - "Undefined"); - EXPECT_EQ(Expression("(Inf x) / Inf").toString(), - "Undefined"); - EXPECT_EQ(Expression("0 * (Inf x)").toString(), - "Undefined"); - EXPECT_EQ(Expression("Inf^x").toString(), - "Undefined"); - EXPECT_EQ(Expression("Inf^-x").toString(), - "Undefined"); - EXPECT_EQ(Expression("x^Inf").toString(), - "Undefined"); - EXPECT_EQ(Expression("(-x)^Inf").toString(), - "Undefined"); - EXPECT_EQ(Expression("(Inf x) ^ 0").toString(), - "Undefined"); - EXPECT_EQ(Expression("(Inf x) ^ Inf").toString(), - "Undefined"); - EXPECT_EQ(Expression("0 ^ (Inf x)").toString(), - "Undefined"); - EXPECT_EQ(Expression("Inf ^ (Inf x)").toString(), - "Undefined"); - EXPECT_EQ(Expression("(Inf/x)^0").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(1, 1)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(0, 0)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(Inf, Inf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(0, Inf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(Inf, 0)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(-Inf, -Inf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(0, -Inf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(-Inf, 0)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(Inf, -Inf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(-Inf, Inf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(ComplexInf, ComplexInf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(0, ComplexInf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(ComplexInf, 0)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(ComplexInf, Inf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(ComplexInf, -Inf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(Inf, ComplexInf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(-Inf, ComplexInf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(x Inf, Inf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(Inf, x Inf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(0^0, 0^0)").toString(), - "Undefined"); - EXPECT_EQ(Expression("log(sign(Inf), -sign(-Inf))").toString(), - "Undefined"); - EXPECT_EQ(Expression("tan(Pi) * cot(Pi)").toString(), - "Undefined"); - EXPECT_EQ(Expression("sign(ComplexInf)").toString(), - "Undefined"); - EXPECT_EQ(Expression("root(2, 0)").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("Undefined^1").toString(), - "Undefined"); - EXPECT_EQ(Expression("Undefined^0").toString(), - "Undefined"); - EXPECT_EQ(Expression("sin(Undefined)").toString(), - "Undefined"); - - EXPECT_EQ(Expression("Undefined = Undefined").toString(), - "Undefined = Undefined"); - EXPECT_EQ(Expression("0/0 = 0/0").toString(), - "Undefined = Undefined"); - EXPECT_EQ(Expression("(sin(x)^2 + cos(x)^2 - 1)/0 = 0/(sin(x)^2 + cos(x)^2 - 1)").toString(), - "Undefined = Undefined"); - EXPECT_EQ(Expression("Inf - Inf = 0").toString(), - "Undefined = Undefined"); - EXPECT_EQ(Expression("Inf - Inf = 0 | a").toString(), - "a | Undefined = Undefined"); - EXPECT_EQ(Expression("Undefined < Undefined").toString(), - "Undefined < Undefined"); - EXPECT_EQ(Expression("0/0 < 0/0").toString(), - "Undefined < Undefined"); - EXPECT_EQ(Expression("(sin(x)^2 + cos(x)^2 - 1)/0 < 0/(sin(x)^2 + cos(x)^2 - 1)").toString(), - "Undefined < Undefined"); - EXPECT_EQ(Expression("Inf - Inf < 0").toString(), - "Undefined < Undefined"); - EXPECT_EQ(Expression("Inf - Inf < 0 | a").toString(), - "a | Undefined < Undefined"); -} diff --git a/tests/src/overall/simplify/SimplifyIntegralTests.cpp b/tests/src/overall/simplify/SimplifyIntegralTests.cpp deleted file mode 100644 index a0c09beaf..000000000 --- a/tests/src/overall/simplify/SimplifyIntegralTests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyIntegralTests, simplifyTest) { - // TODO: integral - EXPECT_EQ(Expression("integral(x, x)").toString(), - "integral(x, x)"); - EXPECT_EQ(Expression("integral(x+x, x)").toString(), - "integral(2 x, x)"); - EXPECT_EQ(Expression("integral(x, x) + integral(b, b)").toString(), - "integral(b, b) + integral(x, x)"); -} diff --git a/tests/src/overall/simplify/SimplifyLogarithmTests.cpp b/tests/src/overall/simplify/SimplifyLogarithmTests.cpp deleted file mode 100644 index b2fd9edb8..000000000 --- a/tests/src/overall/simplify/SimplifyLogarithmTests.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyLogarithmTests, simplifyTest) { - EXPECT_EQ(Expression("log(2, 2)").toString(), - "1"); - EXPECT_EQ(Expression("log(2, 256)").toString(), - "8"); - EXPECT_EQ(Expression("log(3, 515377520732011331036461129765621272702107522001)").toString(), - "100"); - EXPECT_EQ(Expression("log(515377520732011331036461129765621272702107522001, 3)").toString(), - "1/100"); - EXPECT_EQ(Expression("log(2/3, 4/9)").toString(), - "2"); - EXPECT_EQ(Expression("log(9/4, 3/2)").toString(), - "1/2"); - EXPECT_EQ(Expression("log(4/9, 2/3)").toString(), - "1/2"); - EXPECT_EQ(Expression("log(4/11, 2/3)").toString(), - "log(4/11, 2/3)"); - EXPECT_EQ(Expression("ln1").toString(), - "0"); - EXPECT_EQ(Expression("ln3").toString(), - "ln(3)"); - EXPECT_EQ(Expression("ln2").toString(), - "ln(2)"); - EXPECT_EQ(Expression("ln100").toString(), - "ln(100)"); - EXPECT_EQ(Expression("ln(E)").toString(), - "1"); - EXPECT_EQ(Expression("lg99").toString(), - "log(10, 99)"); - EXPECT_EQ(Expression("lg100").toString(), - "2"); - EXPECT_EQ(Expression("lb100").toString(), - "log(2, 100)"); - EXPECT_EQ(Expression("lb4").toString(), - "2"); - EXPECT_EQ(Expression("ln(ln(E))").toString(), - "0"); - EXPECT_EQ(Expression("ln(E)!").toString(), - "1"); - EXPECT_EQ(Expression("log(0, 1)").toString(), - "0"); - EXPECT_EQ(Expression("log(-1, 1)").toString(), - "0"); - EXPECT_EQ(Expression("log(E,E)").toString(), - "1"); - EXPECT_EQ(Expression("log(Pi, Pi^10)").toString(), - "10"); - EXPECT_EQ(Expression("log(E,E^3)").toString(), - "3"); - EXPECT_EQ(Expression("log((Pi),(E)^((Pi)))").toString(), - "Pi log(Pi, E)"); - EXPECT_EQ(Expression("log(E^3, E)").toString(), - "1/3"); - EXPECT_EQ(Expression("log(E^Pi, E)").toString(), - "1/Pi"); - - EXPECT_EQ(Expression("ln(x) + ln(y)").toString(), - "ln(x y)"); - EXPECT_EQ(Expression("ln(x) - ln(y)").toString(), - "ln(x/y)"); - EXPECT_EQ(Expression("-ln(x) + ln(y)").toString(), - "ln(y/x)"); - EXPECT_EQ(Expression("-ln(x) - ln(y)").toString(), - "ln(1/(x y))"); - EXPECT_EQ(Expression("lb(x)/y").toString(), - "log(2, x)/y"); - EXPECT_EQ(Expression("ln((E)/(20000.1EE)) + ln(20000.1E)").toString(), - "0"); - EXPECT_EQ(Expression("ln((10 E)^2) - ln(10 E 10 E)").toString(), - "0"); - EXPECT_EQ(Expression("ln((10 E)^2) - 2 ln(10 E)").toString(), - "0"); - EXPECT_EQ(Expression("3 ln((10 E)^2) - 2 ln(10 E)").toString(), - "4 ln(10 E)"); - EXPECT_EQ(Expression("ln((10 E)^(2ab)) - 2 a ln(10 E) b").toString(), - "0"); - EXPECT_EQ(Expression("ln((10 E)^(2 ln(2))) - 2 ln(2) ln(10 E)").toString(), - "0"); - EXPECT_EQ(Expression("log(2.3, (E)/(20000.1*E*E)) + log(2.3, 20000.1*E)").toString(), - "0"); - EXPECT_EQ(Expression("log(2.3, (E)/(20000.1*E*E)) - log(2.3, 20000.1*E)").toString(), - "log(23/10, 100/(40000400001 E^2))"); - EXPECT_EQ(Expression("log(2, 3) + log(3, 4)").toString(), - "log(3, 4) + log(2, 3)"); - EXPECT_EQ(Expression("x log(2, 3) + log(2, 5)").toString(), - "log(2, 5*3^x)"); - EXPECT_EQ(Expression("x log(2, 3) + log(2, 5a)").toString(), - "log(2, 5 a 3^x)"); - EXPECT_EQ(Expression("log(2, 3) + 3log(3, 4)").toString(), - "log(2, 3) + 3 log(3, 4)"); - EXPECT_EQ(Expression("3log(2x, 3) + log(3, 4)").toString(), - "3 log(2 x, 3) + log(3, 4)"); - EXPECT_EQ(Expression("3log(2x, 3) + 4log(3, 4)").toString(), - "3 log(2 x, 3) + 4 log(3, 4)"); - EXPECT_EQ(Expression("3log(2x, 3) + 5log(2x, 4)").toString(), - "log(2 x, 27648)"); -} diff --git a/tests/src/overall/simplify/SimplifyLogicTests.cpp b/tests/src/overall/simplify/SimplifyLogicTests.cpp deleted file mode 100644 index 506dd5881..000000000 --- a/tests/src/overall/simplify/SimplifyLogicTests.cpp +++ /dev/null @@ -1,271 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyLogicTests, simplifyTest) { - EXPECT_EQ(Expression("~True").toString(), - "False"); - EXPECT_EQ(Expression("~False").toString(), - "True"); - EXPECT_EQ(Expression("True&False").toString(), - "False"); - EXPECT_EQ(Expression("~~~True&~~~~False|~~~~~~False|False").toString(), - "False"); - EXPECT_EQ(Expression("True|False").toString(), - "True"); - EXPECT_EQ(Expression("True&False|True&False").toString(), - "False"); - EXPECT_EQ(Expression("False&True|True&False").toString(), - "False"); - EXPECT_EQ(Expression("False&True|True&True|False").toString(), - "True"); - EXPECT_EQ(Expression("False|~False&True").toString(), - "True"); - EXPECT_EQ(Expression("(False|False&~True)|(True&~(False|True))").toString(), - "False"); - EXPECT_EQ(Expression("True !<-> True").toString(), - "False"); - EXPECT_EQ(Expression("(False -> False & ~True) !<-> (True <-> ~(False|True))").toString(), - "True"); - EXPECT_EQ(Expression("False <-> ~False & True").toString(), - "False"); - EXPECT_EQ(Expression("False <-> True -> False").toString(), - "True"); - - EXPECT_EQ(Expression("~(1=1)").toString(), - "False"); - EXPECT_EQ(Expression("~(1=2)").toString(), - "True"); - EXPECT_EQ(Expression("(1=1)&(1=2)").toString(), - "False"); - EXPECT_EQ(Expression("(1=1)|(1=2)").toString(), - "True"); - EXPECT_EQ(Expression("(1=2)|~(1=2)&(1=1)").toString(), - "True"); - EXPECT_EQ(Expression("((1=2)|(1=2)&~(1=1))|((1=1)&~((1=2)|(1=1)))").toString(), - "False"); - EXPECT_EQ(Expression("((1=2) -> (1=2) & ~(1=1)) !<-> ((1=1) <-> ~((1=2) | (1=1)))").toString(), - "True"); - EXPECT_EQ(Expression("False|1=1").toString(), - "True"); - EXPECT_EQ(Expression("1=1|False").toString(), - "True"); - EXPECT_EQ(Expression("a>b|a").toString(), - "a - b > 0 | a"); - EXPECT_EQ(Expression("x = -7 | x = 7 | x = -7 | x = 7").toString(), - "x - 7 = 0 | x + 7 = 0"); - EXPECT_EQ(Expression("x = -7 & x = 7 & x = -7 & x = 7").toString(), - "x - 7 = 0 & x + 7 = 0"); - - EXPECT_EQ(Expression("~(x = 1)").toString(), - "x - 1 != 0"); - EXPECT_EQ(Expression("~(x != 1)").toString(), - "x - 1 = 0"); - EXPECT_EQ(Expression("~(x > 1)").toString(), - "x - 1 <= 0"); - EXPECT_EQ(Expression("~(x < 1)").toString(), - "x - 1 >= 0"); - EXPECT_EQ(Expression("~(x >= 1)").toString(), - "x - 1 < 0"); - EXPECT_EQ(Expression("~(x <= 1)").toString(), - "x - 1 > 0"); - EXPECT_EQ(Expression("~(x <= 1 | y >= 1)").toString(), - "x - 1 > 0 & y - 1 < 0"); - - EXPECT_EQ(Expression("~a").toString(), - "~a"); - EXPECT_EQ(Expression("~~a").toString(), - "a"); - EXPECT_EQ(Expression("~~~a").toString(), - "~a"); - EXPECT_EQ(Expression("~~~~~~~~~~a").toString(), - "a"); - EXPECT_EQ(Expression("~~~~~~~~~~~a").toString(), - "~a"); - - EXPECT_EQ(Expression("a & b").toString(), - "a & b"); - EXPECT_EQ(Expression("a | b").toString(), - "a | b"); - EXPECT_EQ(Expression("a -> b").toString(), - "~a | b"); - EXPECT_EQ(Expression("a <-> b").toString(), - "(a & b) | (~a & ~b)"); - EXPECT_EQ(Expression("a !<-> b").toString(), - "(a & ~b) | (~a & b)"); - - EXPECT_EQ(Expression("a & a").toString(), - "a"); - EXPECT_EQ(Expression("a | a").toString(), - "a"); - EXPECT_EQ(Expression("a -> a").toString(), - "True"); - EXPECT_EQ(Expression("a <-> a").toString(), - "True"); - EXPECT_EQ(Expression("a !<-> a").toString(), - "False"); - - EXPECT_EQ(Expression("a & ~a").toString(), - "False"); - EXPECT_EQ(Expression("a | ~a").toString(), - "True"); - EXPECT_EQ(Expression("a -> ~a").toString(), - "~a"); - EXPECT_EQ(Expression("a <-> ~a").toString(), - "False"); - EXPECT_EQ(Expression("a !<-> ~a").toString(), - "True"); - - EXPECT_EQ(Expression("~a & a").toString(), - "False"); - EXPECT_EQ(Expression("~a | a").toString(), - "True"); - EXPECT_EQ(Expression("~a -> a").toString(), - "a"); - EXPECT_EQ(Expression("~a <-> a").toString(), - "False"); - EXPECT_EQ(Expression("~a !<-> a").toString(), - "True"); - - EXPECT_EQ(Expression("~a & ~a").toString(), - "~a"); - EXPECT_EQ(Expression("~a | ~a").toString(), - "~a"); - EXPECT_EQ(Expression("~a -> ~a").toString(), - "True"); - EXPECT_EQ(Expression("~a <-> ~a").toString(), - "True"); - EXPECT_EQ(Expression("~a !<-> ~a").toString(), - "False"); - - EXPECT_EQ(Expression("a & False").toString(), - "False"); - EXPECT_EQ(Expression("a | False").toString(), - "a"); - EXPECT_EQ(Expression("a -> False").toString(), - "~a"); - EXPECT_EQ(Expression("a <-> False").toString(), - "~a"); - EXPECT_EQ(Expression("a !<-> False").toString(), - "a"); - - EXPECT_EQ(Expression("a & True").toString(), - "a"); - EXPECT_EQ(Expression("a | True").toString(), - "True"); - EXPECT_EQ(Expression("a -> True").toString(), - "True"); - EXPECT_EQ(Expression("a <-> True").toString(), - "a"); - EXPECT_EQ(Expression("a !<-> True").toString(), - "~a"); - - EXPECT_EQ(Expression("a<->(True)<->(False)").toString(), - "~a"); - EXPECT_EQ(Expression("a<->(True)!<->(False)").toString(), - "a"); - EXPECT_EQ(Expression("True & b & False & c").toString(), - "False"); - EXPECT_EQ(Expression("True | b | False | c").toString(), - "True"); - EXPECT_EQ(Expression("True | a | b | False").toString(), - "True"); - EXPECT_EQ(Expression("a<->a<->a<->a<->a<->a").toString(), - "True"); - EXPECT_EQ(Expression("a<->a<->a<->a<->a<->a<->a").toString(), - "a"); - EXPECT_EQ(Expression("a&b->b&c").toString(), - "~a | (b & c) | ~b"); - EXPECT_EQ(Expression("a&b&c").toString(), - "a & b & c"); - EXPECT_EQ(Expression("a&(b&c)").toString(), - "a & b & c"); - EXPECT_EQ(Expression("a & ~b & c").toString(), - "a & ~b & c"); - EXPECT_EQ(Expression("a | (~b & c)").toString(), - "a | (~b & c)"); - EXPECT_EQ(Expression("(a | ~b) & c").toString(), - "(a & c) | (~b & c)"); - EXPECT_EQ(Expression("~(a & b)").toString(), - "~a | ~b"); - EXPECT_EQ(Expression("~(a | b)").toString(), - "~a & ~b"); - EXPECT_EQ(Expression("~(a & b & c)").toString(), - "~a | ~b | ~c"); - EXPECT_EQ(Expression("~(a | b | c)").toString(), - "~a & ~b & ~c"); - EXPECT_EQ(Expression("~(~a & ~a)").toString(), - "a"); - EXPECT_EQ(Expression("b&c&d | a&c&d | a&b&c").toString(), - "(a & b & c) | (a & c & d) | (b & c & d)"); - EXPECT_EQ(Expression("a | (a & b)").toString(), - "a"); - EXPECT_EQ(Expression("(a & b & c) | (a & b)").toString(), - "a & b"); - EXPECT_EQ(Expression("a & (a | b)").toString(), - "a"); - EXPECT_EQ(Expression("(a | b | c) & (a | b)").toString(), - "a | b"); - EXPECT_EQ(Expression("(a & b & c) | (a & c)").toString(), - "a & c"); - EXPECT_EQ(Expression("(a & ~b) | (a & b)").toString(), - "a"); - EXPECT_EQ(Expression("(a | b | c) & (a | b)").toString(), - "a | b"); - EXPECT_EQ(Expression("~(a & b) | ~(~a & c)").toString(), - "True"); - EXPECT_EQ(Expression("~(a | b) & ~(~a | c)").toString(), - "False"); - EXPECT_EQ(Expression("(x & ~y & z) | (y & z)").toString(), - "(x & ~y & z) | (y & z)"); - EXPECT_EQ(Expression("(x | ~y | (x | ~y | z) & (y | z)) & (y | (x & ~y & z) | (y & z))").toString(), - "(x & ~y & z) | (x & y) | (y & z)"); - EXPECT_EQ(Expression("~a & b | ~c -> a <-> b !<-> c").toString(), - "(a & b & ~c) | (~a & ~b & ~c) | (~a & c) | (~b & c)"); - EXPECT_EQ(Expression("~~~a & ~~b | ~~~c -> ~~a <-> ~~b !<-> ~~c").toString(), - "(a & b & ~c) | (~a & ~b & ~c) | (~a & c) | (~b & c)"); - EXPECT_EQ(Expression("((a | b) & (a -> c)) <-> (~a -> b)").toString(), - "(a & c) | ~a | (b & c)"); - - EXPECT_EQ(Expression("x=1&a").toString(), - "a & x - 1 = 0"); - EXPECT_EQ(Expression("True & a = b").toString(), - "a - b = 0"); -} - -TEST(SimplifyLogicTests, simplifyLargeTest) { - EXPECT_EQ(Expression("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~a").toString(), - "a"); - - EXPECT_EQ(Expression("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~a").toString(), - "~a"); - - // TODO: for benchmark - // EXPECT_EQ(Expression("a<->b<->c<->d<->e<->f").toString(), - - EXPECT_EQ(Expression("a<->b<->c<->d<->e").toString(), - "(a & b & c & d & e) | " - "(a & b & c & ~d & ~e) | " - "(a & b & ~c & d & ~e) | " - "(a & b & ~c & ~d & e) | " - "(a & ~b & c & d & ~e) | " - "(a & ~b & c & ~d & e) | " - "(a & ~b & ~c & d & e) | " - "(a & ~b & ~c & ~d & ~e) | " - "(~a & b & c & d & ~e) | " - "(~a & b & c & ~d & e) | " - "(~a & b & ~c & d & e) | " - "(~a & b & ~c & ~d & ~e) | " - "(~a & ~b & c & d & e) | " - "(~a & ~b & c & ~d & ~e) | " - "(~a & ~b & ~c & d & ~e) | " - "(~a & ~b & ~c & ~d & e)"); - - EXPECT_EQ(Expression("a & b & c & d & e & f & g & h & i & j & k & l & m & n & o & p & q & r & s & t & u & v & w & x & y & z & x_1 & x_2 & x_3 | x_4").toString(), - "(a & b & c & d & e & f & g & h & i & j & k & l & m & n & o & p & q & r & s & t & u & v & w & x & x_1 & x_2 & x_3 & y & z) | x_4"); - - EXPECT_EQ(Expression("a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | x_1 | x_2 | x_3 & x_4").toString(), - "a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | x_1 | x_2 | (x_3 & x_4) | y | z"); -} diff --git a/tests/src/overall/simplify/SimplifyMinMaxTests.cpp b/tests/src/overall/simplify/SimplifyMinMaxTests.cpp deleted file mode 100644 index 29eae8cf8..000000000 --- a/tests/src/overall/simplify/SimplifyMinMaxTests.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyMinMaxTests, simplifyTest) { - EXPECT_EQ(Expression("min(1)").toString(), "1"); - EXPECT_EQ(Expression("min(1,2)").toString(), "1"); - EXPECT_EQ(Expression("min(1,2,3)").toString(), "1"); - EXPECT_EQ(Expression("min(1, 2, 3, 4)").toString(), "1"); - EXPECT_EQ(Expression("min(-1, -2, -3, -4)").toString(), "-4"); - EXPECT_EQ(Expression("min(x)").toString(), "x"); - EXPECT_EQ(Expression("min(1,x)").toString(), "min(x, 1)"); - EXPECT_EQ(Expression("min(1,2,x)").toString(), "min(x, 1)"); - EXPECT_EQ(Expression("min(1, 2, x, 4)").toString(), "min(x, 1)"); - EXPECT_EQ(Expression("min(-1, x, y, -4)").toString(), "min(x, y, -4)"); - EXPECT_EQ(Expression("min(E, x, y, z)").toString(), "min(x, y, z, E)"); - - EXPECT_EQ(Expression("max(1)").toString(), "1"); - EXPECT_EQ(Expression("max(1,2)").toString(), "2"); - EXPECT_EQ(Expression("max(1,2,3)").toString(), "3"); - EXPECT_EQ(Expression("max(1, 2, 3, 4)").toString(), "4"); - EXPECT_EQ(Expression("max(-1, -2, -3, -4)").toString(), "-1"); - EXPECT_EQ(Expression("max(x)").toString(), "x"); - EXPECT_EQ(Expression("max(1,x)").toString(), "max(x, 1)"); - EXPECT_EQ(Expression("max(1,2,x)").toString(), "max(x, 2)"); - EXPECT_EQ(Expression("max(1, 2, x, 4)").toString(), "max(x, 4)"); - EXPECT_EQ(Expression("max(-1, x, y, -4)").toString(), "max(x, y, -1)"); - EXPECT_EQ(Expression("max(E, x, y, z)").toString(), "max(x, y, z, E)"); -} diff --git a/tests/src/overall/simplify/SimplifyPowerTests.cpp b/tests/src/overall/simplify/SimplifyPowerTests.cpp deleted file mode 100644 index 0a4a323a2..000000000 --- a/tests/src/overall/simplify/SimplifyPowerTests.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyPowerTests, simplifyTest) { - EXPECT_EQ(Expression("sqrt0").toString(), - "0"); - EXPECT_EQ(Expression("sqrt(25)").toString(), - "5"); - EXPECT_EQ(Expression("sqrt(144/25)").toString(), - "12/5"); - EXPECT_EQ(Expression("sqrt(50)").toString(), - "5 sqrt(2)"); - EXPECT_EQ(Expression("sqrt(26)").toString(), - "sqrt(26)"); - EXPECT_EQ(Expression("sqrt(145/26)").toString(), - "sqrt(3770)/26"); - EXPECT_EQ(Expression("sqrt(169/3)").toString(), - "(13 sqrt(3))/3"); - EXPECT_EQ(Expression("sqrt(168/25)").toString(), - "(2 sqrt(42))/5"); - EXPECT_EQ(Expression("root(4, 2)").toString(), - "2"); - EXPECT_EQ(Expression("root(8, 3)").toString(), - "2"); - EXPECT_EQ(Expression("root(16, 4)").toString(), - "2"); - EXPECT_EQ(Expression("root(27, 3)").toString(), - "3"); - EXPECT_EQ(Expression("root(0, 3)").toString(), - "0"); - - EXPECT_EQ(Expression("4^(1/2)").toString(), - "2"); - EXPECT_EQ(Expression("8^(1/3)").toString(), - "2"); - EXPECT_EQ(Expression("8^(4/3)").toString(), - "16"); - EXPECT_EQ(Expression("7 2^(2/3)").toString(), - "7 root(4, 3)"); - EXPECT_EQ(Expression("2^(2/3) 3^(2/3)").toString(), - "root(36, 3)"); - EXPECT_EQ(Expression("2^(2/3) 7^(2/3) 3^(3/4)").toString(), - "root(196, 3) root(27, 4)"); - EXPECT_EQ(Expression("2^(2/3) 1/7^(2/3) 3^(3/4)").toString(), - "(root(28, 3) root(27, 4))/7"); - - EXPECT_EQ(Expression("1/sqrt(3)").toString(), - "sqrt(3)/3"); - EXPECT_EQ(Expression("1/root(3, 3)").toString(), - "root(9, 3)/3"); - EXPECT_EQ(Expression("1/root(3, 4)").toString(), - "root(27, 4)/3"); - EXPECT_EQ(Expression("sqrt(2) / (sqrt(2/3) sqrt(8))").toString(), - "sqrt(6)/4"); - EXPECT_EQ(Expression("(sqrt(8) sqrt(2/3)) / sqrt(2)").toString(), - "(2 sqrt(6))/3"); - - EXPECT_EQ(Expression("(x/y)^2").toString(), - "(x^2)/(y^2)"); - EXPECT_EQ(Expression("(x/y)^(1/2)").toString(), - "sqrt(x/y)"); - EXPECT_EQ(Expression("(x/y)^(1/3)").toString(), - "root(x/y, 3)"); - EXPECT_EQ(Expression("(x/y)^(-1/2)").toString(), - "1/sqrt(x/y)"); - EXPECT_EQ(Expression("(x/y)^(-1/3)").toString(), - "1/root(x/y, 3)"); - EXPECT_EQ(Expression("(x/y)^x").toString(), - "(x/y)^x"); - EXPECT_EQ(Expression("(x/y)^(1/x)").toString(), - "root(x/y, x)"); - - EXPECT_EQ(Expression("sqrt(x^2)").toString(), - "sqrt(x^2)"); - EXPECT_EQ(Expression("sqrt(x)^2").toString(), - "x"); - EXPECT_EQ(Expression("(x^10)^(1/10)").toString(), - "root(x^10, 10)"); - EXPECT_EQ(Expression("(x^(1/10))^10").toString(), - "x"); - EXPECT_EQ(Expression("(x^3)^(1/3)").toString(), - "root(x^3, 3)"); - EXPECT_EQ(Expression("(x^(1/3))^3").toString(), - "x"); - EXPECT_EQ(Expression("root(x^(-2), -2)").toString(), - "1/sqrt(1/(x^2))"); - EXPECT_EQ(Expression("root(0, x)").toString(), - "0"); -} diff --git a/tests/src/overall/simplify/SimplifyTests.cpp b/tests/src/overall/simplify/SimplifyTests.cpp deleted file mode 100644 index e8e4be571..000000000 --- a/tests/src/overall/simplify/SimplifyTests.cpp +++ /dev/null @@ -1,719 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyTests, simplifyTest) { - EXPECT_EQ(Expression("3 + 5").toString(), - "8"); - EXPECT_EQ(Expression("3 + -5").toString(), - "-2"); - EXPECT_EQ(Expression("-3 + 5").toString(), - "2"); - EXPECT_EQ(Expression("2 * 2").toString(), - "4"); - EXPECT_EQ(Expression("-2 * 2").toString(), - "-4"); - EXPECT_EQ(Expression("2 * -2").toString(), - "-4"); - EXPECT_EQ(Expression("2 * 3!").toString(), - "12"); - EXPECT_EQ(Expression("1 / 3").toString(), - "1/3"); - EXPECT_EQ(Expression("0 / 3").toString(), - "0"); - EXPECT_EQ(Expression("2 ^ 2").toString(), - "4"); - EXPECT_EQ(Expression("-2 ^ 2").toString(), - "-4"); - EXPECT_EQ(Expression("2 ^ -2").toString(), - "1/4"); - EXPECT_EQ(Expression("2 ^ 3!").toString(), - "40320"); - EXPECT_EQ(Expression("0^1").toString(), - "0"); - EXPECT_EQ(Expression("2^0").toString(), - "1"); - EXPECT_EQ(Expression("(-7)^10").toString(), - "282475249"); - EXPECT_EQ(Expression("2^0").toString(), - "1"); - EXPECT_EQ(Expression("0.001-0.002").toString(), - "-1/1000"); - EXPECT_EQ(Expression("(0.004)/(0.002+0.002)").toString(), - "1"); - EXPECT_EQ(Expression("2 + 2 * 2").toString(), - "6"); - EXPECT_EQ(Expression("2^2^2^2").toString(), - "256"); - EXPECT_EQ(Expression("(2 + 2) * 2").toString(), - "8"); - EXPECT_EQ(Expression("(2-2)").toString(), - "0"); - EXPECT_EQ(Expression("(2 + 2) / (2 ^ 2 - 2) * 2").toString(), - "4"); - EXPECT_EQ(Expression("((((2))))").toString(), - "2"); - EXPECT_EQ(Expression("(((((2 + 2) + 2) + 2) + 2) + 2)").toString(), - "12"); - EXPECT_EQ(Expression("(((2 ^ 2)^2))").toString(), - "16"); - EXPECT_EQ(Expression("-5").toString(), - "-5"); - EXPECT_EQ(Expression("--5").toString(), - "5"); - EXPECT_EQ(Expression("---5").toString(), - "-5"); - EXPECT_EQ(Expression("+5").toString(), - "5"); - EXPECT_EQ(Expression("5*-3").toString(), - "-15"); - EXPECT_EQ(Expression("----5+++5").toString(), - "10"); - EXPECT_EQ(Expression("5----4").toString(), - "9"); - EXPECT_EQ(Expression("5+-+-4").toString(), - "9"); - EXPECT_EQ(Expression("5*+++---4").toString(), - "-20"); - EXPECT_EQ(Expression("1^-1").toString(), - "1"); - EXPECT_EQ(Expression("1.").toString(), - "1"); - EXPECT_EQ(Expression(".1").toString(), - "1/10"); - EXPECT_EQ(Expression("2+.1+.1+1.+1.").toString(), - "21/5"); - EXPECT_EQ(Expression("1/10^-20").toString(), - "100000000000000000000"); - EXPECT_EQ(Expression("1/10^--20").toString(), - "1/100000000000000000000"); - EXPECT_EQ(Expression("1/10^---20").toString(), - "100000000000000000000"); - EXPECT_EQ(Expression("36/3(8-6)").toString(), - "24"); - EXPECT_EQ(Expression("36/(8-6)3").toString(), - "54"); - EXPECT_EQ(Expression("((((((5)/(8)))/(1)))/(((((((9)/(4)))/(0)))/(5))))").toString(), - "0"); - EXPECT_EQ(Expression("2 mod 2").toString(), - "0"); - EXPECT_EQ(Expression("5 mod -3").toString(), - "-1"); - EXPECT_EQ(Expression("-10 mod 4").toString(), - "2"); - EXPECT_EQ(Expression("-51 mod -11").toString(), - "-7"); - EXPECT_EQ(Expression("2 mod 3 * 4 / 2").toString(), - "2"); - EXPECT_EQ(Expression("2 + 3 * 4 mod 5").toString(), - "4"); - EXPECT_EQ(Expression("2^3 mod 3^2").toString(), - "8"); - EXPECT_EQ(Expression("2 + 3 * 4 mod 5 / 6").toString(), - "14 mod (5/6)"); - EXPECT_EQ(Expression("2%").toString(), - "1/50"); - EXPECT_EQ(Expression("2.35%").toString(), - "47/2000"); - EXPECT_EQ(Expression("1100*4.76%").toString(), - "1309/25"); - EXPECT_EQ(Expression("2.35%%%%").toString(), - "47/2000000000"); - EXPECT_EQ(Expression("1100*4.76%1100*4.76%").toString(), - "1713481/625"); - - EXPECT_EQ(Expression("E").toString(), - "E"); - EXPECT_EQ(Expression("Pi").toString(), - "Pi"); - EXPECT_EQ(Expression("E^101-E^101").toString(), - "0"); - EXPECT_EQ(Expression("E E Pi E").toString(), - "E^3 Pi"); - EXPECT_EQ(Expression("E Pi E^2 Pi").toString(), - "E^3 Pi^2"); - EXPECT_EQ(Expression("Pi^5 E^2 Pi").toString(), - "E^2 Pi^6"); - EXPECT_EQ(Expression("E Pi E^2 Pi^3 E^2 Pi^3 E^5 Pi^5").toString(), - "E^10 Pi^12"); - EXPECT_EQ(Expression("ln(E^E) / ln(E^E) - 1").toString(), - "0"); - EXPECT_EQ(Expression("8E").toString(), - "8 E"); - EXPECT_EQ(Expression("8Pi").toString(), - "8 Pi"); - EXPECT_EQ(Expression("E8").toString(), - "8 E"); - EXPECT_EQ(Expression("Pi8").toString(), - "8 Pi"); - EXPECT_EQ(Expression("exp100").toString(), - "E^100"); - EXPECT_EQ(Expression("E^101").toString(), - "E^101"); - EXPECT_EQ(Expression("E^(-101)").toString(), - "1/(E^101)"); - EXPECT_EQ(Expression("sin10").toString(), - "sin(10)"); - EXPECT_EQ(Expression("cos10").toString(), - "cos(10)"); - EXPECT_EQ(Expression("tan10").toString(), - "tan(10)"); - EXPECT_EQ(Expression("cot10").toString(), - "cot(10)"); - EXPECT_EQ(Expression("sec10").toString(), - "sec(10)"); - EXPECT_EQ(Expression("csc10").toString(), - "csc(10)"); - EXPECT_EQ(Expression("asin0.9").toString(), - "asin(9/10)"); - EXPECT_EQ(Expression("acos0.9").toString(), - "acos(9/10)"); - EXPECT_EQ(Expression("atan10").toString(), - "atan(10)"); - EXPECT_EQ(Expression("acot10").toString(), - "acot(10)"); - EXPECT_EQ(Expression("asec10").toString(), - "asec(10)"); - EXPECT_EQ(Expression("acsc10").toString(), - "acsc(10)"); - EXPECT_EQ(Expression("sinh10").toString(), - "sinh(10)"); - EXPECT_EQ(Expression("cosh10").toString(), - "cosh(10)"); - EXPECT_EQ(Expression("tanh10").toString(), - "tanh(10)"); - EXPECT_EQ(Expression("coth10").toString(), - "coth(10)"); - EXPECT_EQ(Expression("sech10").toString(), - "sech(10)"); - EXPECT_EQ(Expression("csch10").toString(), - "csch(10)"); - EXPECT_EQ(Expression("asinh0.9").toString(), - "asinh(9/10)"); - EXPECT_EQ(Expression("acosh1.9").toString(), - "acosh(19/10)"); - EXPECT_EQ(Expression("atanh0.9").toString(), - "atanh(9/10)"); - EXPECT_EQ(Expression("acoth1.9").toString(), - "acoth(19/10)"); - EXPECT_EQ(Expression("asech0.9").toString(), - "asech(9/10)"); - EXPECT_EQ(Expression("acsch1.9").toString(), - "acsch(19/10)"); - EXPECT_EQ(Expression("((2))*sqrt2").toString(), - "2 sqrt(2)"); - EXPECT_EQ(Expression("sqrt2*((2))").toString(), - "2 sqrt(2)"); - EXPECT_EQ(Expression("sin(1)^2").toString(), - "sin(1)^2"); - EXPECT_EQ(Expression("sin(-1)^2").toString(), - "sin(1)^2"); - EXPECT_EQ(Expression("sin1^2").toString(), - "sin(1)^2"); - EXPECT_EQ(Expression("sin(10^30)").toString(), - "sin(1000000000000000000000000000000)"); - EXPECT_EQ(Expression("sin(1)^2 + cos(1)^2").toString(), - "1"); - EXPECT_EQ(Expression("3sin(1)^2 + 3cos(1)^2").toString(), - "3"); - EXPECT_EQ(Expression("2!*E").toString(), - "2 E"); - EXPECT_EQ(Expression("E*2!").toString(), - "2 E"); - EXPECT_EQ(Expression("sqrt((1-cos(2*(Pi/3)))/2)").toString(), - "sqrt(3)/2"); - EXPECT_EQ(Expression("2*sqrt((1-cos(2*(Pi/3)))/2)*cos(Pi/3)").toString(), - "sqrt(3)/2"); - EXPECT_EQ(Expression("-sin(2)").toString(), - "-sin(2)"); - EXPECT_EQ(Expression("2^(3/2)").toString(), - "2 sqrt(2)"); - EXPECT_EQ(Expression("sqrt((-1)^2)").toString(), - "1"); - EXPECT_EQ(Expression("sqrt(sqrt5)").toString(), - "root(5, 4)"); - EXPECT_EQ(Expression("sqrt(sqrt(-5))").toString(), - "sqrt(I sqrt(5))"); - EXPECT_EQ(Expression("sqrt4!").toString(), - "2"); - EXPECT_EQ(Expression("(sqrt4)!").toString(), - "2"); - EXPECT_EQ(Expression("sqrt4*2!").toString(), - "4"); - EXPECT_EQ(Expression("abs(-5)").toString(), - "5"); - EXPECT_EQ(Expression("abs((-5))").toString(), - "5"); - EXPECT_EQ(Expression("sign(10)").toString(), - "1"); - EXPECT_EQ(Expression("sign(0)").toString(), - "0"); - EXPECT_EQ(Expression("sign(-5)").toString(), - "-1"); - EXPECT_EQ(Expression("frac(2,4)").toString(), - "1/2"); - EXPECT_EQ(Expression("frac(2,2,4)").toString(), - "5/2"); - EXPECT_EQ(Expression("sqr(3)").toString(), - "9"); - EXPECT_EQ(Expression("pow(2,4)").toString(), - "16"); - EXPECT_EQ(Expression("1deg").toString(), - "Pi/180"); - EXPECT_EQ(Expression("60deg").toString(), - "Pi/3"); - EXPECT_EQ(Expression("adeg").toString(), - "(Pi a)/180"); - EXPECT_EQ(Expression("floor(2/3)").toString(), - "0"); - EXPECT_EQ(Expression("floor(-2/3)").toString(), - "-1"); - EXPECT_EQ(Expression("ceil(2/3)").toString(), - "1"); - EXPECT_EQ(Expression("ceil(-2/3)").toString(), - "0"); - EXPECT_EQ(Expression("cos(5) - cos(-5)").toString(), - "0"); - - EXPECT_EQ(Expression("x_1").toString(), - "x_1"); - EXPECT_EQ(Expression("x+x_1").toString(), - "x + x_1"); - EXPECT_EQ(Expression("x*x_1").toString(), - "x x_1"); - EXPECT_EQ(Expression("x_2^2").toString(), - "x_2^2"); - EXPECT_EQ(Expression("sin(x_1)").toString(), - "sin(x_1)"); - - EXPECT_EQ(Expression("a*0").toString(), - "0"); - EXPECT_EQ(Expression("0*a").toString(), - "0"); - EXPECT_EQ(Expression("1*a").toString(), - "a"); - EXPECT_EQ(Expression("a*1").toString(), - "a"); - EXPECT_EQ(Expression("0^a").toString(), - "0"); - EXPECT_EQ(Expression("1^a").toString(), - "1"); - EXPECT_EQ(Expression("(a b)^0").toString(), - "1"); - EXPECT_EQ(Expression("(a + b)^-1").toString(), - "1/(a + b)"); - EXPECT_EQ(Expression("(a + b)^-2").toString(), - "1/(a^2 + 2 a b + b^2)"); - EXPECT_EQ(Expression("(a b)^-1").toString(), - "1/(a b)"); - EXPECT_EQ(Expression("(a b)^-2").toString(), - "1/(a^2 b^2)"); - - EXPECT_EQ(Expression("2.a").toString(), - "2 a"); - EXPECT_EQ(Expression("a.2").toString(), - "a/5"); - EXPECT_EQ(Expression("a+a").toString(), - "2 a"); - EXPECT_EQ(Expression("a-a").toString(), - "0"); - EXPECT_EQ(Expression("-a").toString(), - "-a"); - EXPECT_EQ(Expression("+a").toString(), - "a"); - EXPECT_EQ(Expression("--a").toString(), - "a"); - EXPECT_EQ(Expression("---a").toString(), - "-a"); - EXPECT_EQ(Expression("b--a").toString(), - "a + b"); - EXPECT_EQ(Expression("b---a").toString(), - "-a + b"); - EXPECT_EQ(Expression("-(-(-(-(-(-(-(-a)))))))").toString(), - "a"); - EXPECT_EQ(Expression("-(-(-(-(-(-(-(-(-a))))))))").toString(), - "-a"); - EXPECT_EQ(Expression("--------a").toString(), - "a"); - EXPECT_EQ(Expression("---------a").toString(), - "-a"); - EXPECT_EQ(Expression("abcdefg").toString(), - "a b c d e f g"); - EXPECT_EQ(Expression("a+b+c+d+e+f+g").toString(), - "a + b + c + d + e + f + g"); - EXPECT_EQ(Expression("(a+b)-b").toString(), - "a"); - EXPECT_EQ(Expression("a-b-c").toString(), - "a - b - c"); - EXPECT_EQ(Expression("a-(b-c)").toString(), - "a - b + c"); - EXPECT_EQ(Expression("(a-b)-c").toString(), - "a - b - c"); - EXPECT_EQ(Expression("(a+b)*(a+b)+a*b*c-c*a*b+b*a").toString(), - "a^2 + 3 a b + b^2"); - EXPECT_EQ(Expression("x/y/z").toString(), - "x/(y z)"); - EXPECT_EQ(Expression("x/(y/z)").toString(), - "(x z)/y"); - EXPECT_EQ(Expression("(x/y)/z").toString(), - "x/(y z)"); - EXPECT_EQ(Expression("x^y^z").toString(), - "(x^y)^z"); - EXPECT_EQ(Expression("x^(y^z)").toString(), - "x^(y^z)"); - EXPECT_EQ(Expression("(x^y)^z").toString(), - "(x^y)^z"); - EXPECT_EQ(Expression("(a+b)^2").toString(), - "a^2 + 2 a b + b^2"); - EXPECT_EQ(Expression("(a+b)^3").toString(), - "a^3 + 3 a^2 b + 3 a b^2 + b^3"); - EXPECT_EQ(Expression("1*(a+b)^3").toString(), - "a^3 + 3 a^2 b + 3 a b^2 + b^3"); - EXPECT_EQ(Expression("(a+b)^4").toString(), - "a^4 + 4 a^3 b + 6 a^2 b^2 + 4 a b^3 + b^4"); - EXPECT_EQ(Expression("5^x 9").toString(), - "9*5^x"); - EXPECT_EQ(Expression("9 5^x").toString(), - "9*5^x"); - EXPECT_EQ(Expression("9 5^x 9").toString(), - "81*5^x"); - EXPECT_EQ(Expression("5^x 99").toString(), - "99*5^x"); - EXPECT_EQ(Expression("99 5^x").toString(), - "99*5^x"); - EXPECT_EQ(Expression("99 5^x 99").toString(), - "9801*5^x"); - EXPECT_EQ(Expression("5^x a").toString(), - "a 5^x"); - EXPECT_EQ(Expression("a 5^x").toString(), - "a 5^x"); - EXPECT_EQ(Expression("a 5^x a").toString(), - "a^2*5^x"); - EXPECT_EQ(Expression("2 5^x 6^y 7^z x^2 y^3").toString(), - "2 x^2 y^3*5^x 6^y 7^z"); - EXPECT_EQ(Expression("1*(a+b)*1").toString(), - "a + b"); - EXPECT_EQ(Expression("-1*(a+b)*1").toString(), - "-a - b"); - EXPECT_EQ(Expression("1*(a+b)*-1").toString(), - "-a - b"); - EXPECT_EQ(Expression("-1*(a+b)*-1").toString(), - "a + b"); - EXPECT_EQ(Expression("1+(a+b)+1").toString(), - "a + b + 2"); - EXPECT_EQ(Expression("-1+(a+b)+1").toString(), - "a + b"); - EXPECT_EQ(Expression("1+(a+b)-1").toString(), - "a + b"); - EXPECT_EQ(Expression("-1+(a+b)-1").toString(), - "a + b - 2"); - EXPECT_EQ(Expression("2*(a+b)*2").toString(), - "4 a + 4 b"); - EXPECT_EQ(Expression("-2*(a+b)*2").toString(), - "-4 a - 4 b"); - EXPECT_EQ(Expression("2*(a+b)*-2").toString(), - "-4 a - 4 b"); - EXPECT_EQ(Expression("-2*(a+b)*-2").toString(), - "4 a + 4 b"); - EXPECT_EQ(Expression("2+(a+b)+2").toString(), - "a + b + 4"); - EXPECT_EQ(Expression("-2+(a+b)+2").toString(), - "a + b"); - EXPECT_EQ(Expression("2+(a+b)-2").toString(), - "a + b"); - EXPECT_EQ(Expression("-2+(a+b)-2").toString(), - "a + b - 4"); - EXPECT_EQ(Expression("(a+b)+(a+b)-(a+b)").toString(), - "a + b"); - EXPECT_EQ(Expression("(a+b)+(a+b)+(-(a+b))").toString(), - "a + b"); - EXPECT_EQ(Expression("(a+b)+(a+b)+(-(-(a+b)))").toString(), - "3 a + 3 b"); - EXPECT_EQ(Expression("-a^2 + b").toString(), - "-a^2 + b"); - EXPECT_EQ(Expression("-a^2 c + b").toString(), - "-a^2 c + b"); - EXPECT_EQ(Expression("-a^2 d - a^2 c + b").toString(), - "-a^2 c - a^2 d + b"); - EXPECT_EQ(Expression("abc").toString(), - "a b c"); - EXPECT_EQ(Expression("d^abc").toString(), - "b c d^a"); - EXPECT_EQ(Expression("abc^d").toString(), - "a b c^d"); - EXPECT_EQ(Expression("(a+b(a+b(a+b(a+b))))").toString(), - "a b^3 + a b^2 + a b + a + b^4"); - EXPECT_EQ(Expression("(ab+(ab+(ab+(ab))))").toString(), - "4 a b"); - EXPECT_EQ(Expression("((a+b+(a+c)+(1+v))+((a+c(abc(aaa))+v)c+d))((c)((d+d+d)b)a)").toString(), - "3 a^5 b^2 c^4 d + 3 a^2 b c^2 d + 6 a^2 b c d + 3 a b^2 c d + 3 a b c^2 d v + 3 a b c^2 d + 3 a b c d^2 + " - "3 a b c d v + 3 a b c d"); - EXPECT_EQ(Expression("2/(a + 2) + b/(a + 2)").toString(), - "(b + 2)/(a + 2)"); - EXPECT_EQ(Expression("c * 2^(a + 2) + b^(a + 2)").toString(), - "b^(a + 2) + 2^(a + 2) c"); - EXPECT_EQ(Expression("2^(a + 2) * b^(a + 2)").toString(), - "b^(a + 2) 2^(a + 2)"); - EXPECT_EQ(Expression("2 a b c + a b + a b c").toString(), - "3 a b c + a b"); - - EXPECT_EQ(Expression("2%a").toString(), - "a/50"); - EXPECT_EQ(Expression("2!!!!a!!!").toString(), - "2 a!!!"); - EXPECT_EQ(Expression("sin a").toString(), - "sin(a)"); - EXPECT_EQ(Expression("s i n a").toString(), - "a i n s"); - EXPECT_EQ(Expression("a(2)").toString(), - "2 a"); - EXPECT_EQ(Expression("(2)a").toString(), - "2 a"); - EXPECT_EQ(Expression("Ea").toString(), - "E a"); - EXPECT_EQ(Expression("aE").toString(), - "E a"); - EXPECT_EQ(Expression("aEE").toString(), - "E^2 a"); - EXPECT_EQ(Expression("EEa").toString(), - "E^2 a"); - EXPECT_EQ(Expression("x123").toString(), - "123 x"); - EXPECT_EQ(Expression("x^y!").toString(), - "(x^y)!"); - EXPECT_EQ(Expression("lnE").toString(), - "1"); - EXPECT_EQ(Expression("lncossinE").toString(), - "ln(cos(sin(E)))"); - EXPECT_EQ(Expression("ln cos sin a").toString(), - "ln(cos(sin(a)))"); - EXPECT_EQ(Expression("frac(x,y)").toString(), - "x/y"); - EXPECT_EQ(Expression("pow(x,y)").toString(), - "x^y"); - EXPECT_EQ(Expression("frac(x,y,z)").toString(), - "x + y/z"); - - EXPECT_EQ(Expression("sqrt(x) + x").toString(), - "x + sqrt(x)"); - EXPECT_EQ(Expression("sqrt(x) - x").toString(), - "-x + sqrt(x)"); - EXPECT_EQ(Expression("sqrt(x) * sqrt(x)").toString(), - "x"); - EXPECT_EQ(Expression("x/(sqrt(x) - x)").toString(), - "-1 - sqrt(x)/(x - sqrt(x))"); - EXPECT_EQ(Expression("x/(2 sqrt(x) - x)").toString(), - "-1 - (2 sqrt(x))/(x - 2 sqrt(x))"); - EXPECT_EQ(Expression("(x-1)/(sqrt(x) - x)").toString(), - "-1 - 1/sqrt(x)"); - EXPECT_EQ(Expression("(x-1)/(2 sqrt(x) - x)").toString(), - "-1 - (2 sqrt(x) - 1)/(x - 2 sqrt(x))"); - EXPECT_EQ(Expression("(x-1)/(sqrt(x)/2 - x)").toString(), - "-1 - (sqrt(x) - 2)/(2 x - sqrt(x))"); - EXPECT_EQ(Expression("(x-1)/(root(x, 3) - x)").toString(), - "-1 - (root(x, 3) - 1)/(x - root(x, 3))"); - EXPECT_EQ(Expression("(x-1)/(2 root(x, 3) - x)").toString(), - "-1 - (2 root(x, 3) - 1)/(x - 2 root(x, 3))"); - EXPECT_EQ(Expression("(x-1)/(root(x, 3)/2 - x)").toString(), - "-1 - (root(x, 3) - 2)/(2 x - root(x, 3))"); - EXPECT_EQ(Expression("(x-1)/(x^(4/3) - x)").toString(), - "(x - 1)/(x^(4/3) - x)"); - EXPECT_EQ(Expression("(x-1)/(2 x^(4/3) - x)").toString(), - "(x - 1)/(2 x^(4/3) - x)"); - EXPECT_EQ(Expression("x (sqrt(2) + sqrt(3))").toString(), - "(sqrt(3) + sqrt(2)) x"); - EXPECT_EQ(Expression("x (sqrt(2) + sqrt(3)) y sqrt(2)").toString(), - "(sqrt(6) + 2) x y"); - EXPECT_EQ(Expression("a + sqrt(2) x + sqrt(3) x + Pi^4 x + 1").toString(), - "a + (Pi^4 + sqrt(3) + sqrt(2)) x + 1"); - EXPECT_EQ(Expression("a - sqrt(2) x - sqrt(3) x - Pi^4 x + 1").toString(), - "a + (-Pi^4 - sqrt(3) - sqrt(2)) x + 1"); - EXPECT_EQ(Expression("x Pi^4 ln(5) + x E^2 sin(1) sinh(2)").toString(), - "(E^2 sinh(2) sin(1) + Pi^4 ln(5)) x"); - EXPECT_EQ(Expression("(a+b) (-sqrt2 + sqrt3 - sqrt5)").toString(), - "(sqrt(3) - sqrt(5) - sqrt(2)) a + (sqrt(3) - sqrt(5) - sqrt(2)) b"); - EXPECT_EQ(Expression("(sqrt(2) x + sqrt(3) x + Pi^4 x + 1) / (sqrt(2) + sqrt(3) + Pi^4)").toString(), - "x + 1/(Pi^4 + sqrt(3) + sqrt(2))"); - EXPECT_EQ(Expression("sqrt(1/(7 + x^2)) + sqrt(x)/(sqrt(x) + 1)").toString(), - "sqrt(1/(x^2 + 7)) + 1 - 1/(sqrt(x) + 1)"); - EXPECT_EQ(Expression("root(1/(7 + x^2), 3) + sqrt(x)/(sqrt(x) + 1)").toString(), - "root(1/(x^2 + 7), 3) + 1 - 1/(sqrt(x) + 1)"); - EXPECT_EQ(Expression("ln(a) (2x + 2)").toString(), - "ln(a) (2 x + 2)"); - EXPECT_EQ(Expression("log(a, 2) (2x + 2)").toString(), - "log(a, 2) (2 x + 2)"); - EXPECT_EQ(Expression("x / (t sin(x))").toString(), - "(x csc(x))/t"); - EXPECT_EQ(Expression("root(x, x) mod 1").toString(), - "root(x, x) mod 1"); - EXPECT_EQ(Expression("root(x, y/x) mod 1").toString(), - "(x^(x/y)) mod 1"); - - EXPECT_EQ(Expression("(a+b+1-1)^1000/(a+b+1-1)^998").toString(), - "a^2 + 2 a b + b^2"); - EXPECT_EQ(Expression("(a+b)^1000/(a+b)^998").toString(), - "a^2 + 2 a b + b^2"); - EXPECT_EQ(Expression("sin(asin(a+b+1-1))^1000/(a+b+1-1)^998").toString(), - "a^2 + 2 a b + b^2"); - EXPECT_EQ(Expression("a(10^100)/10^99").toString(), - "10 a"); - - EXPECT_EQ(Expression("-sin(x)").toString(), - "-sin(x)"); - EXPECT_EQ(Expression("-sin(x) + sin(2)").toString(), - "-sin(x) + sin(2)"); - EXPECT_EQ(Expression("-3sin(E)").toString(), - "-3 sin(E)"); - EXPECT_EQ(Expression("1-(sin(x)+1)").toString(), - "-sin(x)"); - EXPECT_EQ(Expression("1/(sin(x)+1)").toString(), - "1/(sin(x) + 1)"); - EXPECT_EQ(Expression("(x+1)^3").toString(), - "x^3 + 3 x^2 + 3 x + 1"); - EXPECT_EQ(Expression("(x+1)^(-3)").toString(), - "1/(x^3 + 3 x^2 + 3 x + 1)"); - EXPECT_EQ(Expression("(sin(x)+1)^3").toString(), - "sin(x)^3 + 3 sin(x)^2 + 3 sin(x) + 1"); - EXPECT_EQ(Expression("(sin(x)+1)^(-3)").toString(), - "1/(sin(x)^3 + 3 sin(x)^2 + 3 sin(x) + 1)"); - EXPECT_EQ(Expression("(sin(x)+1)^(-4)").toString(), - "1/(sin(x)^4 + 4 sin(x)^3 + 6 sin(x)^2 + 4 sin(x) + 1)"); - EXPECT_EQ(Expression("(x)sin(a)").toString(), - "sin(a) x"); - EXPECT_EQ(Expression("tan(4 a^3 b) + cot(4 a b^3) + b^4 + sin(a^4) + cos(6 a^2 b^2)").toString(), - "sin(a^4) + tan(4 a^3 b) + cos(6 a^2 b^2) + cot(4 a b^3) + b^4"); - EXPECT_EQ(Expression("tan(4 a^3 b) + cot(sin(4 a b^3)) + b^4 + asin(sin(a^4)) + cos(6 a^2 b^2)").toString(), - "asin(sin(a^4)) + tan(4 a^3 b) + cos(6 a^2 b^2) + cot(sin(4 a b^3)) + b^4"); - EXPECT_EQ(Expression("tan(4 a_1^3 b) + cot(sin(4 a_1 b^3)) + b^4 + asin(sin(a_1^4)) + cos(6 a_1^2 b^2)").toString(), - "asin(sin(a_1^4)) + tan(4 a_1^3 b) + cos(6 a_1^2 b^2) + cot(sin(4 a_1 b^3)) + b^4"); - EXPECT_EQ(Expression("a!!!!!!!!!!").toString(), - "a!!!!!!!!!!"); - EXPECT_EQ(Expression("a% * a!!! * a! * a!!").toString(), - "(a a! a!! a!!!)/100"); - EXPECT_EQ(Expression("a! sin(a)").toString(), - "a! sin(a)"); - EXPECT_EQ(Expression("sin(a) a!").toString(), - "a! sin(a)"); - EXPECT_EQ(Expression("sin(a) a").toString(), - "a sin(a)"); - EXPECT_EQ(Expression("a sin(a)").toString(), - "a sin(a)"); - EXPECT_EQ(Expression("cos(b) sin(a)").toString(), - "sin(a) cos(b)"); - EXPECT_EQ(Expression("cos(b) log(b, a)").toString(), - "log(b, a) cos(b)"); - EXPECT_EQ(Expression("cos(a) log(b, c)").toString(), - "log(b, c) cos(a)"); - EXPECT_EQ(Expression("cos(b^2) log(b, c)").toString(), - "log(b, c) cos(b^2)"); - EXPECT_EQ(Expression("(x + y^3)^2 * sin(x)/ln(2)/x^2 - (2 sin(x) y^3)/(x ln(2))").toString(), - "sin(x)/ln(2) + (y^6 sin(x))/(x^2 ln(2))"); - - EXPECT_EQ(Expression("1 / (1 - tan(2))").toString(), - "cos(2)/(cos(2) - sin(2))"); - EXPECT_EQ(Expression("1 / (1 - cot(2))").toString(), - "sin(2)/(sin(2) - cos(2))"); - EXPECT_EQ(Expression("1 / (1 - tanh(2))").toString(), - "cosh(2)/(cosh(2) - sinh(2))"); - EXPECT_EQ(Expression("1 / (1 - coth(2))").toString(), - "sinh(2)/(sinh(2) - cosh(2))"); - EXPECT_EQ(Expression("1 / (1 - sec(2))").toString(), - "cos(2)/(cos(2) - 1)"); - EXPECT_EQ(Expression("1 / (1 - csc(2))").toString(), - "sin(2)/(sin(2) - 1)"); - EXPECT_EQ(Expression("1 / (1 - sech(2))").toString(), - "cosh(2)/(cosh(2) - 1)"); - EXPECT_EQ(Expression("1 / (1 - csch(2))").toString(), - "sinh(2)/(sinh(2) - 1)"); - - EXPECT_EQ(Expression("floor(E)").toString(), - "2"); - EXPECT_EQ(Expression("ceil(E)").toString(), - "3"); - EXPECT_EQ(Expression("floor(E^10)").toString(), - "22026"); - EXPECT_EQ(Expression("ceil(E^10)").toString(), - "22027"); - EXPECT_EQ(Expression("floor(11^10)").toString(), - "25937424601"); - EXPECT_EQ(Expression("ceil(11^10)").toString(), - "25937424601"); - EXPECT_EQ(Expression("tan(floor(E/3))").toString(), - "0"); - EXPECT_EQ(Expression("tan(ceil(-E/3))").toString(), - "0"); - EXPECT_EQ(Expression("ln(floor(E/3))").toString(), - "-Inf"); - EXPECT_EQ(Expression("root(ceil(-E/3), 3)").toString(), - "0"); - EXPECT_EQ(Expression("floor(E + I)").toString(), - "2 + I"); - EXPECT_EQ(Expression("floor(E + x)").toString(), - "floor(x + E)"); - - EXPECT_EQ(Expression("abs(E)").toString(), - "abs(E)"); - EXPECT_EQ(Expression("sign(E)").toString(), - "1"); - EXPECT_EQ(Expression("abs(-E)").toString(), - "abs(E)"); - EXPECT_EQ(Expression("sign(-E)").toString(), - "-1"); - EXPECT_EQ(Expression("abs(E + I)").toString(), - "abs(E + I)"); - EXPECT_EQ(Expression("sign(E + I)").toString(), - "sign(E + I)"); - - EXPECT_EQ(Expression("floor(-x)").toString(), - "-ceil(x)"); - EXPECT_EQ(Expression("ceil(-x)").toString(), - "-floor(x)"); - EXPECT_EQ(Expression("abs(-x)").toString(), - "abs(x)"); - EXPECT_EQ(Expression("sign(-x)").toString(), - "-sign(x)"); - - EXPECT_EQ(Expression("floor(E^(E^(E^2)))").toString(), - "floor(E^(E^(E^2)))"); - EXPECT_EQ(Expression("ceil(E^(E^(E^2)))").toString(), - "ceil(E^(E^(E^2)))"); - EXPECT_EQ(Expression("sign(E^(E^(E^2)))").toString(), - "1"); -} - -TEST(SimplifyTests, simplifyLargeTest) { - EXPECT_EQ(Expression("10^-500").toString(), - "1/100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); - - EXPECT_EQ(Expression("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------a").toString(), - "a"); - - EXPECT_EQ(Expression("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------a").toString(), - "-a"); - - EXPECT_EQ(Expression("a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a").toString(), - "266 a"); - - EXPECT_EQ(Expression("(x+y)^20").toString(), - "x^20 + 20 x^19 y + 190 x^18 y^2 + 1140 x^17 y^3 + 4845 x^16 y^4 + 15504 x^15 y^5 + 38760 x^14 y^6 + 77520 x^13 y^7 + 125970 x^12 y^8 + 167960 x^11 y^9 + 184756 x^10 y^10 + 167960 x^9 y^11 + 125970 x^8 y^12 + 77520 x^7 y^13 + 38760 x^6 y^14 + 15504 x^5 y^15 + 4845 x^4 y^16 + 1140 x^3 y^17 + 190 x^2 y^18 + 20 x y^19 + y^20"); - - EXPECT_EQ(Expression("(x+y+z)^4").toString(), - "x^4 + 4 x^3 y + 4 x^3 z + 6 x^2 y^2 + 12 x^2 y z + 6 x^2 z^2 + 4 x y^3 + 12 x y^2 z + 12 x y z^2 + 4 x z^3 + y^4 + 4 y^3 z + 6 y^2 z^2 + 4 y z^3 + z^4"); - - EXPECT_EQ(Expression("(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)(x+y)").toString(), - "x^30 + 30 x^29 y + 435 x^28 y^2 + 4060 x^27 y^3 + 27405 x^26 y^4 + 142506 x^25 y^5 + 593775 x^24 y^6 + 2035800 x^23 y^7 + 5852925 x^22 y^8 + 14307150 x^21 y^9 + 30045015 x^20 y^10 + 54627300 x^19 y^11 + 86493225 x^18 y^12 + 119759850 x^17 y^13 + 145422675 x^16 y^14 + 155117520 x^15 y^15 + 145422675 x^14 y^16 + 119759850 x^13 y^17 + 86493225 x^12 y^18 + 54627300 x^11 y^19 + 30045015 x^10 y^20 + 14307150 x^9 y^21 + 5852925 x^8 y^22 + 2035800 x^7 y^23 + 593775 x^6 y^24 + 142506 x^5 y^25 + 27405 x^4 y^26 + 4060 x^3 y^27 + 435 x^2 y^28 + 30 x y^29 + y^30"); - - EXPECT_EQ(Expression("(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)(x-y)").toString(), - "x^30 - 30 x^29 y + 435 x^28 y^2 - 4060 x^27 y^3 + 27405 x^26 y^4 - 142506 x^25 y^5 + 593775 x^24 y^6 - 2035800 x^23 y^7 + 5852925 x^22 y^8 - 14307150 x^21 y^9 + 30045015 x^20 y^10 - 54627300 x^19 y^11 + 86493225 x^18 y^12 - 119759850 x^17 y^13 + 145422675 x^16 y^14 - 155117520 x^15 y^15 + 145422675 x^14 y^16 - 119759850 x^13 y^17 + 86493225 x^12 y^18 - 54627300 x^11 y^19 + 30045015 x^10 y^20 - 14307150 x^9 y^21 + 5852925 x^8 y^22 - 2035800 x^7 y^23 + 593775 x^6 y^24 - 142506 x^5 y^25 + 27405 x^4 y^26 - 4060 x^3 y^27 + 435 x^2 y^28 - 30 x y^29 + y^30"); - - EXPECT_EQ(Expression("sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(x)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))").toString(), - "sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(sin(x)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))"); - - // TODO: for benchmarks - // EXPECT_EQ(Expression("(2 + 3 * x + 4 * x * y)^60").toString(), - // ""); - // EXPECT_EQ(Expression("(a+b+c+d)^60").toString(), - // ""); -} diff --git a/tests/src/overall/simplify/SimplifyTrigonometryTests.cpp b/tests/src/overall/simplify/SimplifyTrigonometryTests.cpp deleted file mode 100644 index c358b1e1f..000000000 --- a/tests/src/overall/simplify/SimplifyTrigonometryTests.cpp +++ /dev/null @@ -1,803 +0,0 @@ -#include - -#include "fintamath/expressions/Expression.hpp" - -using namespace fintamath; - -TEST(SimplifyTrigonometryTests, simplifyTest) { - EXPECT_EQ(Expression("sin(asin(x))").toString(), - "x"); - EXPECT_EQ(Expression("cos(acos(x))").toString(), - "x"); - EXPECT_EQ(Expression("tan(atan(x))").toString(), - "x"); - EXPECT_EQ(Expression("cot(acot(x))").toString(), - "x"); - EXPECT_EQ(Expression("sec(asec(x))").toString(), - "x"); - EXPECT_EQ(Expression("csc(acsc(x))").toString(), - "x"); - EXPECT_EQ(Expression("asin(sin(x))").toString(), - "asin(sin(x))"); - EXPECT_EQ(Expression("acos(cos(x))").toString(), - "acos(cos(x))"); - EXPECT_EQ(Expression("atan(tan(x))").toString(), - "atan(tan(x))"); - EXPECT_EQ(Expression("acot(cot(x))").toString(), - "acot(cot(x))"); - EXPECT_EQ(Expression("asec(sec(x))").toString(), - "asec(sec(x))"); - EXPECT_EQ(Expression("acsc(csc(x))").toString(), - "acsc(csc(x))"); - - EXPECT_EQ(Expression("sin(-x)").toString(), - "-sin(x)"); - EXPECT_EQ(Expression("cos(-x)").toString(), - "cos(x)"); - EXPECT_EQ(Expression("tan(-x)").toString(), - "-tan(x)"); - EXPECT_EQ(Expression("cot(-x)").toString(), - "-cot(x)"); - EXPECT_EQ(Expression("sec(-x)").toString(), - "sec(x)"); - EXPECT_EQ(Expression("csc(-x)").toString(), - "-csc(x)"); - - EXPECT_EQ(Expression("sin(x)/cos(x)").toString(), - "tan(x)"); - EXPECT_EQ(Expression("(-2sin(x))/cos(x)").toString(), - "-2 tan(x)"); - EXPECT_EQ(Expression("(2sin(x))/(3cos(x))").toString(), - "(2 tan(x))/3"); - EXPECT_EQ(Expression("sin(x)^2/cos(x)").toString(), - "sin(x)^2 sec(x)"); - EXPECT_EQ(Expression("sin(x)/cos(x)^2").toString(), - "sec(x)^2 sin(x)"); - EXPECT_EQ(Expression("sin(x)^2/cos(x)^2").toString(), - "tan(x)^2"); - EXPECT_EQ(Expression("(2sin(x))^2/cos(x)^2").toString(), - "4 tan(x)^2"); - EXPECT_EQ(Expression("(2sin(x))^2/(3cos(x))^2").toString(), - "(4 tan(x)^2)/9"); - - EXPECT_EQ(Expression("cos(x)/sin(x)").toString(), - "cot(x)"); - EXPECT_EQ(Expression("(-2cos(x))/sin(x)").toString(), - "-2 cot(x)"); - EXPECT_EQ(Expression("(2cos(x))/(3sin(x))").toString(), - "(2 cot(x))/3"); - EXPECT_EQ(Expression("cos(x)^2/sin(x)").toString(), - "cos(x)^2 csc(x)"); - EXPECT_EQ(Expression("cos(x)/sin(x)^2").toString(), - "csc(x)^2 cos(x)"); - EXPECT_EQ(Expression("cos(x)^2/sin(x)^2").toString(), - "cot(x)^2"); - EXPECT_EQ(Expression("(2cos(x))^2/sin(x)^2").toString(), - "4 cot(x)^2"); - EXPECT_EQ(Expression("(2cos(x))^2/(3sin(x))^2").toString(), - "(4 cot(x)^2)/9"); - - EXPECT_EQ(Expression("sec(x)/csc(x)").toString(), - "tan(x)"); - EXPECT_EQ(Expression("csc(x)/sec(x)").toString(), - "cot(x)"); - EXPECT_EQ(Expression("sec(x)*cot(x)").toString(), - "csc(x)"); - EXPECT_EQ(Expression("csc(x)*tan(x)").toString(), - "sec(x)"); - - EXPECT_EQ(Expression("sin(x)cos(x)").toString(), - "sin(2 x)/2"); - EXPECT_EQ(Expression("sin(x)cos(x)sign(x)").toString(), - "(sign(x) sin(2 x))/2"); - - EXPECT_EQ(Expression("sin(x)^2").toString(), - "sin(x)^2"); - EXPECT_EQ(Expression("cos(x)^2").toString(), - "cos(x)^2"); - EXPECT_EQ(Expression("1 - sin(x)^2").toString(), - "cos(x)^2"); - EXPECT_EQ(Expression("-1 + sin(x)^2").toString(), - "-cos(x)^2"); - EXPECT_EQ(Expression("2 - 2sin(x)^2").toString(), - "2 cos(x)^2"); - EXPECT_EQ(Expression("-2 + 2sin(x)^2").toString(), - "-2 cos(x)^2"); - EXPECT_EQ(Expression("1 - cos(x)^2").toString(), - "sin(x)^2"); - EXPECT_EQ(Expression("-1 + cos(x)^2").toString(), - "-sin(x)^2"); - EXPECT_EQ(Expression("2 - 2cos(x)^2").toString(), - "2 sin(x)^2"); - EXPECT_EQ(Expression("-2 + 2cos(x)^2").toString(), - "-2 sin(x)^2"); - EXPECT_EQ(Expression("1 - 2sin(x)^2").toString(), - "-2 sin(x)^2 + 1"); // TODO: cos of double angle - EXPECT_EQ(Expression("1 - 2cos(x)^2").toString(), - "-2 cos(x)^2 + 1"); // TODO: cos of double angle - - EXPECT_EQ(Expression("sin(x)^2 + cos(x)^2").toString(), - "1"); - EXPECT_EQ(Expression("sin(x)^2 - cos(x)^2").toString(), - "-cos(2 x)"); - EXPECT_EQ(Expression("-sin(x)^2 + cos(x)^2").toString(), - "cos(2 x)"); - EXPECT_EQ(Expression("-sin(x)^2 - cos(x)^2").toString(), - "-1"); - EXPECT_EQ(Expression("2sin(x)^2 + 2cos(x)^2").toString(), - "2"); - EXPECT_EQ(Expression("sin(x)^2 + 2cos(x)^2").toString(), - "sin(x)^2 + 2 cos(x)^2"); - EXPECT_EQ(Expression("2sin(x)^2 + cos(x)^2").toString(), - "2 sin(x)^2 + cos(x)^2"); - EXPECT_EQ(Expression("2sin(x)^2 - 3cos(x)^2").toString(), - "2 sin(x)^2 - 3 cos(x)^2"); - EXPECT_EQ(Expression("-5sin(x)^2 + 10cos(x)^2").toString(), - "-5 sin(x)^2 + 10 cos(x)^2"); - EXPECT_EQ(Expression("-4sin(x)^2 - 6cos(x)^2").toString(), - "-4 sin(x)^2 - 6 cos(x)^2"); - EXPECT_EQ(Expression("(2I + 2) sin(x)^2 + (2I + 2) cos(x)^2").toString(), - "2 + 2 I"); - EXPECT_EQ(Expression("(2I + 2) sin(x)^2 + (2I - 2) cos(x)^2").toString(), - "(2 + 2 I) sin(x)^2 + (-2 + 2 I) cos(x)^2"); - EXPECT_EQ(Expression("(2I + 2) sin(x)^2 + (-2I + 2) cos(x)^2").toString(), - "(2 + 2 I) sin(x)^2 + (2 - 2 I) cos(x)^2"); - EXPECT_EQ(Expression("(2I + 2) sin(x)^2 + (-2I - 2) cos(x)^2").toString(), - "(-2 - 2 I) cos(2 x)"); - EXPECT_EQ(Expression("(2I - 2) sin(x)^2 + (2I + 2) cos(x)^2").toString(), - "(-2 + 2 I) sin(x)^2 + (2 + 2 I) cos(x)^2"); - EXPECT_EQ(Expression("(2I - 2) sin(x)^2 + (2I - 2) cos(x)^2").toString(), - "-2 + 2 I"); - EXPECT_EQ(Expression("(2I - 2) sin(x)^2 + (-2I + 2) cos(x)^2").toString(), - "(2 - 2 I) cos(2 x)"); - EXPECT_EQ(Expression("(2I - 2) sin(x)^2 + (-2I - 2) cos(x)^2").toString(), - "(-2 + 2 I) sin(x)^2 + (-2 - 2 I) cos(x)^2"); - EXPECT_EQ(Expression("(-2I + 2) sin(x)^2 + (2I + 2) cos(x)^2").toString(), - "(2 - 2 I) sin(x)^2 + (2 + 2 I) cos(x)^2"); - EXPECT_EQ(Expression("(-2I + 2) sin(x)^2 + (2I - 2) cos(x)^2").toString(), - "(-2 + 2 I) cos(2 x)"); - EXPECT_EQ(Expression("(-2I + 2) sin(x)^2 + (-2I + 2) cos(x)^2").toString(), - "2 - 2 I"); - EXPECT_EQ(Expression("(-2I + 2) sin(x)^2 + (-2I - 2) cos(x)^2").toString(), - "(2 - 2 I) sin(x)^2 + (-2 - 2 I) cos(x)^2"); - EXPECT_EQ(Expression("(-2I - 2) sin(x)^2 + (2I + 2) cos(x)^2").toString(), - "(2 + 2 I) cos(2 x)"); - EXPECT_EQ(Expression("(-2I - 2) sin(x)^2 + (2I - 2) cos(x)^2").toString(), - "(-2 - 2 I) sin(x)^2 + (-2 + 2 I) cos(x)^2"); - EXPECT_EQ(Expression("(-2I - 2) sin(x)^2 + (-2I + 2) cos(x)^2").toString(), - "(-2 - 2 I) sin(x)^2 + (2 - 2 I) cos(x)^2"); - EXPECT_EQ(Expression("(-2I - 2) sin(x)^2 + (-2I - 2) cos(x)^2").toString(), - "-2 - 2 I"); - // TODO: simplify - EXPECT_EQ(Expression("E sin(x)^2 + E cos(x)^2").toString(), - "E sin(x)^2 + E cos(x)^2"); - EXPECT_EQ(Expression("E sin(x)^2 - E cos(x)^2").toString(), - "E sin(x)^2 - E cos(x)^2"); - EXPECT_EQ(Expression("-E sin(x)^2 + E cos(x)^2").toString(), - "-E sin(x)^2 + E cos(x)^2"); - EXPECT_EQ(Expression("-E sin(x)^2 - E cos(x)^2").toString(), - "-E sin(x)^2 - E cos(x)^2"); - EXPECT_EQ(Expression("E^2 sin(x)^2 + E cos(x)^2").toString(), - "sin(x)^2 E^2 + E cos(x)^2"); - EXPECT_EQ(Expression("E^2 sin(x)^2 - E cos(x)^2").toString(), - "sin(x)^2 E^2 - E cos(x)^2"); - EXPECT_EQ(Expression("-E^2 sin(x)^2 + E cos(x)^2").toString(), - "-sin(x)^2 E^2 + E cos(x)^2"); - EXPECT_EQ(Expression("-E^2 sin(x)^2 - E cos(x)^2").toString(), - "-sin(x)^2 E^2 - E cos(x)^2"); - EXPECT_EQ(Expression("sin(x) * sin(x) + cos(x) * cos(x)").toString(), - "1"); - EXPECT_EQ(Expression("(sin(x) + cos(x))^2").toString(), - "sin(2 x) + 1"); - EXPECT_EQ(Expression("(sin(x) - cos(x))^2").toString(), - "-sin(2 x) + 1"); - EXPECT_EQ(Expression("sin(x)^2 + cos(y)^2").toString(), - "sin(x)^2 + cos(y)^2"); - - EXPECT_EQ(Expression("sin(x)^2 + sign(x)^2").toString(), - "sin(x)^2 + sign(x)^2"); - EXPECT_EQ(Expression("sin(x)^2 - sign(x)^2").toString(), - "sin(x)^2 - sign(x)^2"); - EXPECT_EQ(Expression("cos(x)^2 + sign(x)^2").toString(), - "cos(x)^2 + sign(x)^2"); - EXPECT_EQ(Expression("cos(x)^2 - sign(x)^2").toString(), - "cos(x)^2 - sign(x)^2"); - EXPECT_EQ(Expression("sign(x)^2 + 1").toString(), - "sign(x)^2 + 1"); - EXPECT_EQ(Expression("sign(x)^2 - 1").toString(), - "sign(x)^2 - 1"); - - EXPECT_EQ(Expression("tan(x) * cot(x)").toString(), - "1"); - EXPECT_EQ(Expression("cot(x) * tan(x)").toString(), - "1"); - EXPECT_EQ(Expression("sec(x) * cos(x)").toString(), - "1"); - EXPECT_EQ(Expression("cos(x) * sec(x)").toString(), - "1"); - EXPECT_EQ(Expression("csc(x) * sin(x)").toString(), - "1"); - EXPECT_EQ(Expression("sin(x) * csc(x)").toString(), - "1"); - // TODO: implement - // EXPECT_EQ(Expression("tan(x)^5 * cot(x)^5").toString(), - // "1"); - // EXPECT_EQ(Expression("tan(x)^4 * (sin(x)/cos(x)) * cot(x)^5").toString(), - // "1"); - - EXPECT_EQ(Expression("sin(-13Pi/6)").toString(), - "-1/2"); - EXPECT_EQ(Expression("sin(-2Pi)").toString(), - "0"); - EXPECT_EQ(Expression("sin(-11Pi/6)").toString(), - "1/2"); - EXPECT_EQ(Expression("sin(-7Pi/4)").toString(), - "sqrt(2)/2"); - EXPECT_EQ(Expression("sin(-5Pi/3)").toString(), - "sqrt(3)/2"); - EXPECT_EQ(Expression("sin(-3Pi/2)").toString(), - "1"); - EXPECT_EQ(Expression("sin(-4Pi/3)").toString(), - "sqrt(3)/2"); - EXPECT_EQ(Expression("sin(-5Pi/4)").toString(), - "sqrt(2)/2"); - EXPECT_EQ(Expression("sin(-7Pi/6)").toString(), - "1/2"); - EXPECT_EQ(Expression("sin(-Pi)").toString(), - "0"); - EXPECT_EQ(Expression("sin(-5Pi/6)").toString(), - "-1/2"); - EXPECT_EQ(Expression("sin(-3Pi/4)").toString(), - "-sqrt(2)/2"); - EXPECT_EQ(Expression("sin(-2Pi/3)").toString(), - "-sqrt(3)/2"); - EXPECT_EQ(Expression("sin(-Pi/2)").toString(), - "-1"); - EXPECT_EQ(Expression("sin(-Pi/3)").toString(), - "-sqrt(3)/2"); - EXPECT_EQ(Expression("sin(-Pi/4)").toString(), - "-sqrt(2)/2"); - EXPECT_EQ(Expression("sin(-Pi/6)").toString(), - "-1/2"); - EXPECT_EQ(Expression("sin(0)").toString(), - "0"); - EXPECT_EQ(Expression("sin(Pi/6)").toString(), - "1/2"); - EXPECT_EQ(Expression("sin(Pi/4)").toString(), - "sqrt(2)/2"); - EXPECT_EQ(Expression("sin(Pi/3)").toString(), - "sqrt(3)/2"); - EXPECT_EQ(Expression("sin(Pi/2)").toString(), - "1"); - EXPECT_EQ(Expression("sin(2Pi/3)").toString(), - "sqrt(3)/2"); - EXPECT_EQ(Expression("sin(3Pi/4)").toString(), - "sqrt(2)/2"); - EXPECT_EQ(Expression("sin(5Pi/6)").toString(), - "1/2"); - EXPECT_EQ(Expression("sin(Pi)").toString(), - "0"); - EXPECT_EQ(Expression("sin(7Pi/6)").toString(), - "-1/2"); - EXPECT_EQ(Expression("sin(5Pi/4)").toString(), - "-sqrt(2)/2"); - EXPECT_EQ(Expression("sin(4Pi/3)").toString(), - "-sqrt(3)/2"); - EXPECT_EQ(Expression("sin(3Pi/2)").toString(), - "-1"); - EXPECT_EQ(Expression("sin(5Pi/3)").toString(), - "-sqrt(3)/2"); - EXPECT_EQ(Expression("sin(7Pi/4)").toString(), - "-sqrt(2)/2"); - EXPECT_EQ(Expression("sin(11Pi/6)").toString(), - "-1/2"); - EXPECT_EQ(Expression("sin(2Pi)").toString(), - "0"); - EXPECT_EQ(Expression("sin(13Pi/6)").toString(), - "1/2"); - - EXPECT_EQ(Expression("cos(-13Pi/6)").toString(), - "sqrt(3)/2"); - EXPECT_EQ(Expression("cos(-2Pi)").toString(), - "1"); - EXPECT_EQ(Expression("cos(-11Pi/6)").toString(), - "sqrt(3)/2"); - EXPECT_EQ(Expression("cos(-7Pi/4)").toString(), - "sqrt(2)/2"); - EXPECT_EQ(Expression("cos(-5Pi/3)").toString(), - "1/2"); - EXPECT_EQ(Expression("cos(-3Pi/2)").toString(), - "0"); - EXPECT_EQ(Expression("cos(-4Pi/3)").toString(), - "-1/2"); - EXPECT_EQ(Expression("cos(-5Pi/4)").toString(), - "-sqrt(2)/2"); - EXPECT_EQ(Expression("cos(-7Pi/6)").toString(), - "-sqrt(3)/2"); - EXPECT_EQ(Expression("cos(-Pi)").toString(), - "-1"); - EXPECT_EQ(Expression("cos(-5Pi/6)").toString(), - "-sqrt(3)/2"); - EXPECT_EQ(Expression("cos(-3Pi/4)").toString(), - "-sqrt(2)/2"); - EXPECT_EQ(Expression("cos(-2Pi/3)").toString(), - "-1/2"); - EXPECT_EQ(Expression("cos(-Pi/2)").toString(), - "0"); - EXPECT_EQ(Expression("cos(-Pi/3)").toString(), - "1/2"); - EXPECT_EQ(Expression("cos(-Pi/4)").toString(), - "sqrt(2)/2"); - EXPECT_EQ(Expression("cos(-Pi/6)").toString(), - "sqrt(3)/2"); - EXPECT_EQ(Expression("cos(0)").toString(), - "1"); - EXPECT_EQ(Expression("cos(Pi/6)").toString(), - "sqrt(3)/2"); - EXPECT_EQ(Expression("cos(Pi/4)").toString(), - "sqrt(2)/2"); - EXPECT_EQ(Expression("cos(Pi/3)").toString(), - "1/2"); - EXPECT_EQ(Expression("cos(Pi/2)").toString(), - "0"); - EXPECT_EQ(Expression("cos(2Pi/3)").toString(), - "-1/2"); - EXPECT_EQ(Expression("cos(3Pi/4)").toString(), - "-sqrt(2)/2"); - EXPECT_EQ(Expression("cos(5Pi/6)").toString(), - "-sqrt(3)/2"); - EXPECT_EQ(Expression("cos(Pi)").toString(), - "-1"); - EXPECT_EQ(Expression("cos(7Pi/6)").toString(), - "-sqrt(3)/2"); - EXPECT_EQ(Expression("cos(5Pi/4)").toString(), - "-sqrt(2)/2"); - EXPECT_EQ(Expression("cos(4Pi/3)").toString(), - "-1/2"); - EXPECT_EQ(Expression("cos(3Pi/2)").toString(), - "0"); - EXPECT_EQ(Expression("cos(5Pi/3)").toString(), - "1/2"); - EXPECT_EQ(Expression("cos(7Pi/4)").toString(), - "sqrt(2)/2"); - EXPECT_EQ(Expression("cos(11Pi/6)").toString(), - "sqrt(3)/2"); - EXPECT_EQ(Expression("cos(2Pi)").toString(), - "1"); - EXPECT_EQ(Expression("cos(13Pi/6)").toString(), - "sqrt(3)/2"); - - EXPECT_EQ(Expression("tan(-13Pi/6)").toString(), - "-sqrt(3)/3"); - EXPECT_EQ(Expression("tan(-2Pi)").toString(), - "0"); - EXPECT_EQ(Expression("tan(-11Pi/6)").toString(), - "sqrt(3)/3"); - EXPECT_EQ(Expression("tan(-7Pi/4)").toString(), - "1"); - EXPECT_EQ(Expression("tan(-5Pi/3)").toString(), - "sqrt(3)"); - EXPECT_EQ(Expression("tan(-3Pi/2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("tan(-4Pi/3)").toString(), - "-sqrt(3)"); - EXPECT_EQ(Expression("tan(-5Pi/4)").toString(), - "-1"); - EXPECT_EQ(Expression("tan(-7Pi/6)").toString(), - "-sqrt(3)/3"); - EXPECT_EQ(Expression("tan(-Pi)").toString(), - "0"); - EXPECT_EQ(Expression("tan(-5Pi/6)").toString(), - "sqrt(3)/3"); - EXPECT_EQ(Expression("tan(-3Pi/4)").toString(), - "1"); - EXPECT_EQ(Expression("tan(-2Pi/3)").toString(), - "sqrt(3)"); - EXPECT_EQ(Expression("tan(-Pi/2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("tan(-Pi/3)").toString(), - "-sqrt(3)"); - EXPECT_EQ(Expression("tan(-Pi/4)").toString(), - "-1"); - EXPECT_EQ(Expression("tan(-Pi/6)").toString(), - "-sqrt(3)/3"); - EXPECT_EQ(Expression("tan(0)").toString(), - "0"); - EXPECT_EQ(Expression("tan(Pi/6)").toString(), - "sqrt(3)/3"); - EXPECT_EQ(Expression("tan(Pi/4)").toString(), - "1"); - EXPECT_EQ(Expression("tan(Pi/3)").toString(), - "sqrt(3)"); - EXPECT_EQ(Expression("tan(Pi/2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("tan(2Pi/3)").toString(), - "-sqrt(3)"); - EXPECT_EQ(Expression("tan(3Pi/4)").toString(), - "-1"); - EXPECT_EQ(Expression("tan(5Pi/6)").toString(), - "-sqrt(3)/3"); - EXPECT_EQ(Expression("tan(Pi)").toString(), - "0"); - EXPECT_EQ(Expression("tan(7Pi/6)").toString(), - "sqrt(3)/3"); - EXPECT_EQ(Expression("tan(5Pi/4)").toString(), - "1"); - EXPECT_EQ(Expression("tan(4Pi/3)").toString(), - "sqrt(3)"); - EXPECT_EQ(Expression("tan(3Pi/2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("tan(5Pi/3)").toString(), - "-sqrt(3)"); - EXPECT_EQ(Expression("tan(7Pi/4)").toString(), - "-1"); - EXPECT_EQ(Expression("tan(11Pi/6)").toString(), - "-sqrt(3)/3"); - EXPECT_EQ(Expression("tan(2Pi)").toString(), - "0"); - EXPECT_EQ(Expression("tan(13Pi/6)").toString(), - "sqrt(3)/3"); - - EXPECT_EQ(Expression("sec(-13Pi/6)").toString(), - "(2 sqrt(3))/3"); - EXPECT_EQ(Expression("sec(-2Pi)").toString(), - "1"); - EXPECT_EQ(Expression("sec(-11Pi/6)").toString(), - "(2 sqrt(3))/3"); - EXPECT_EQ(Expression("sec(-7Pi/4)").toString(), - "sqrt(2)"); - EXPECT_EQ(Expression("sec(-5Pi/3)").toString(), - "2"); - EXPECT_EQ(Expression("sec(-3Pi/2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("sec(-4Pi/3)").toString(), - "-2"); - EXPECT_EQ(Expression("sec(-5Pi/4)").toString(), - "-sqrt(2)"); - EXPECT_EQ(Expression("sec(-7Pi/6)").toString(), - "-(2 sqrt(3))/3"); - EXPECT_EQ(Expression("sec(-Pi)").toString(), - "-1"); - EXPECT_EQ(Expression("sec(-5Pi/6)").toString(), - "-(2 sqrt(3))/3"); - EXPECT_EQ(Expression("sec(-3Pi/4)").toString(), - "-sqrt(2)"); - EXPECT_EQ(Expression("sec(-2Pi/3)").toString(), - "-2"); - EXPECT_EQ(Expression("sec(-Pi/2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("sec(-Pi/3)").toString(), - "2"); - EXPECT_EQ(Expression("sec(-Pi/4)").toString(), - "sqrt(2)"); - EXPECT_EQ(Expression("sec(-Pi/6)").toString(), - "(2 sqrt(3))/3"); - EXPECT_EQ(Expression("sec(0)").toString(), - "1"); - EXPECT_EQ(Expression("sec(Pi/6)").toString(), - "(2 sqrt(3))/3"); - EXPECT_EQ(Expression("sec(Pi/4)").toString(), - "sqrt(2)"); - EXPECT_EQ(Expression("sec(Pi/3)").toString(), - "2"); - EXPECT_EQ(Expression("sec(Pi/2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("sec(2Pi/3)").toString(), - "-2"); - EXPECT_EQ(Expression("sec(3Pi/4)").toString(), - "-sqrt(2)"); - EXPECT_EQ(Expression("sec(5Pi/6)").toString(), - "-(2 sqrt(3))/3"); - EXPECT_EQ(Expression("sec(Pi)").toString(), - "-1"); - EXPECT_EQ(Expression("sec(7Pi/6)").toString(), - "-(2 sqrt(3))/3"); - EXPECT_EQ(Expression("sec(5Pi/4)").toString(), - "-sqrt(2)"); - EXPECT_EQ(Expression("sec(4Pi/3)").toString(), - "-2"); - EXPECT_EQ(Expression("sec(3Pi/2)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("sec(5Pi/3)").toString(), - "2"); - EXPECT_EQ(Expression("sec(7Pi/4)").toString(), - "sqrt(2)"); - EXPECT_EQ(Expression("sec(11Pi/6)").toString(), - "(2 sqrt(3))/3"); - EXPECT_EQ(Expression("sec(2Pi)").toString(), - "1"); - EXPECT_EQ(Expression("sec(13Pi/6)").toString(), - "(2 sqrt(3))/3"); - - EXPECT_EQ(Expression("csc(-13Pi/6)").toString(), - "-2"); - EXPECT_EQ(Expression("csc(-2Pi)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("csc(-11Pi/6)").toString(), - "2"); - EXPECT_EQ(Expression("csc(-7Pi/4)").toString(), - "sqrt(2)"); - EXPECT_EQ(Expression("csc(-5Pi/3)").toString(), - "(2 sqrt(3))/3"); - EXPECT_EQ(Expression("csc(-3Pi/2)").toString(), - "1"); - EXPECT_EQ(Expression("csc(-4Pi/3)").toString(), - "(2 sqrt(3))/3"); - EXPECT_EQ(Expression("csc(-5Pi/4)").toString(), - "sqrt(2)"); - EXPECT_EQ(Expression("csc(-7Pi/6)").toString(), - "2"); - EXPECT_EQ(Expression("csc(-Pi)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("csc(-5Pi/6)").toString(), - "-2"); - EXPECT_EQ(Expression("csc(-3Pi/4)").toString(), - "-sqrt(2)"); - EXPECT_EQ(Expression("csc(-2Pi/3)").toString(), - "-(2 sqrt(3))/3"); - EXPECT_EQ(Expression("csc(-Pi/2)").toString(), - "-1"); - EXPECT_EQ(Expression("csc(-Pi/3)").toString(), - "-(2 sqrt(3))/3"); - EXPECT_EQ(Expression("csc(-Pi/4)").toString(), - "-sqrt(2)"); - EXPECT_EQ(Expression("csc(-Pi/6)").toString(), - "-2"); - EXPECT_EQ(Expression("csc(0)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("csc(Pi/6)").toString(), - "2"); - EXPECT_EQ(Expression("csc(Pi/4)").toString(), - "sqrt(2)"); - EXPECT_EQ(Expression("csc(Pi/3)").toString(), - "(2 sqrt(3))/3"); - EXPECT_EQ(Expression("csc(Pi/2)").toString(), - "1"); - EXPECT_EQ(Expression("csc(2Pi/3)").toString(), - "(2 sqrt(3))/3"); - EXPECT_EQ(Expression("csc(3Pi/4)").toString(), - "sqrt(2)"); - EXPECT_EQ(Expression("csc(5Pi/6)").toString(), - "2"); - EXPECT_EQ(Expression("csc(Pi)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("csc(7Pi/6)").toString(), - "-2"); - EXPECT_EQ(Expression("csc(5Pi/4)").toString(), - "-sqrt(2)"); - EXPECT_EQ(Expression("csc(4Pi/3)").toString(), - "-(2 sqrt(3))/3"); - EXPECT_EQ(Expression("csc(3Pi/2)").toString(), - "-1"); - EXPECT_EQ(Expression("csc(5Pi/3)").toString(), - "-(2 sqrt(3))/3"); - EXPECT_EQ(Expression("csc(7Pi/4)").toString(), - "-sqrt(2)"); - EXPECT_EQ(Expression("csc(11Pi/6)").toString(), - "-2"); - EXPECT_EQ(Expression("csc(2Pi)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("csc(13Pi/6)").toString(), - "2"); - - EXPECT_EQ(Expression("sin(Pi/7)").toString(), - "sin(Pi/7)"); - EXPECT_EQ(Expression("cos(Pi/7)").toString(), - "cos(Pi/7)"); - EXPECT_EQ(Expression("tan(Pi/7)").toString(), - "tan(Pi/7)"); - EXPECT_EQ(Expression("cot(Pi/7)").toString(), - "cot(Pi/7)"); - EXPECT_EQ(Expression("sec(Pi/7)").toString(), - "sec(Pi/7)"); - EXPECT_EQ(Expression("csc(Pi/7)").toString(), - "csc(Pi/7)"); - - EXPECT_EQ(Expression("sin(E Pi)").toString(), - "sin(E Pi)"); - EXPECT_EQ(Expression("cos(E Pi)").toString(), - "cos(E Pi)"); - EXPECT_EQ(Expression("tan(E Pi)").toString(), - "tan(E Pi)"); - EXPECT_EQ(Expression("cot(E Pi)").toString(), - "cot(E Pi)"); - EXPECT_EQ(Expression("sec(E Pi)").toString(), - "sec(E Pi)"); - EXPECT_EQ(Expression("csc(E Pi)").toString(), - "csc(E Pi)"); - - EXPECT_EQ(Expression("asin(-1)").toString(), - "-Pi/2"); - EXPECT_EQ(Expression("asin(-sqrt(3)/2)").toString(), - "-Pi/3"); - EXPECT_EQ(Expression("asin(-sqrt(2)/2)").toString(), - "-Pi/4"); - EXPECT_EQ(Expression("asin(-1/2)").toString(), - "-Pi/6"); - EXPECT_EQ(Expression("asin(0)").toString(), - "0"); - EXPECT_EQ(Expression("asin(1/2)").toString(), - "Pi/6"); - EXPECT_EQ(Expression("asin(sqrt(2)/2)").toString(), - "Pi/4"); - EXPECT_EQ(Expression("asin(sqrt(3)/2)").toString(), - "Pi/3"); - EXPECT_EQ(Expression("asin(1)").toString(), - "Pi/2"); - - EXPECT_EQ(Expression("acos(-1)").toString(), - "Pi"); - EXPECT_EQ(Expression("acos(-sqrt(3)/2)").toString(), - "(5 Pi)/6"); - EXPECT_EQ(Expression("acos(-sqrt(2)/2)").toString(), - "(3 Pi)/4"); - EXPECT_EQ(Expression("acos(-1/2)").toString(), - "(2 Pi)/3"); - EXPECT_EQ(Expression("acos(0)").toString(), - "Pi/2"); - EXPECT_EQ(Expression("acos(1/2)").toString(), - "Pi/3"); - EXPECT_EQ(Expression("acos(sqrt(2)/2)").toString(), - "Pi/4"); - EXPECT_EQ(Expression("acos(sqrt(3)/2)").toString(), - "Pi/6"); - EXPECT_EQ(Expression("acos(1)").toString(), - "0"); - - EXPECT_EQ(Expression("atan(-sqrt(3))").toString(), - "-Pi/3"); - EXPECT_EQ(Expression("atan(-1)").toString(), - "-Pi/4"); - EXPECT_EQ(Expression("atan(-sqrt(3)/3)").toString(), - "-Pi/6"); - EXPECT_EQ(Expression("atan(0)").toString(), - "0"); - EXPECT_EQ(Expression("atan(sqrt(3)/3)").toString(), - "Pi/6"); - EXPECT_EQ(Expression("atan(1)").toString(), - "Pi/4"); - EXPECT_EQ(Expression("atan(sqrt(3))").toString(), - "Pi/3"); - - EXPECT_EQ(Expression("acot(-sqrt(3))").toString(), - "-Pi/6"); - EXPECT_EQ(Expression("acot(-1)").toString(), - "-Pi/4"); - EXPECT_EQ(Expression("acot(-sqrt(3)/3)").toString(), - "-Pi/3"); - EXPECT_EQ(Expression("acot(0)").toString(), - "Pi/2"); - EXPECT_EQ(Expression("acot(sqrt(3)/3)").toString(), - "Pi/3"); - EXPECT_EQ(Expression("acot(1)").toString(), - "Pi/4"); - EXPECT_EQ(Expression("acot(sqrt(3))").toString(), - "Pi/6"); - - EXPECT_EQ(Expression("asec(-1)").toString(), - "Pi"); - EXPECT_EQ(Expression("asec(-2/sqrt(3))").toString(), - "(5 Pi)/6"); - EXPECT_EQ(Expression("asec(-2/sqrt(2))").toString(), - "(3 Pi)/4"); - EXPECT_EQ(Expression("asec(-2)").toString(), - "(2 Pi)/3"); - EXPECT_EQ(Expression("asec(0)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("asec(2)").toString(), - "Pi/3"); - EXPECT_EQ(Expression("asec(2/sqrt(2))").toString(), - "Pi/4"); - EXPECT_EQ(Expression("asec(2/sqrt(3))").toString(), - "Pi/6"); - EXPECT_EQ(Expression("asec(1)").toString(), - "0"); - - EXPECT_EQ(Expression("acsc(-1)").toString(), - "-Pi/2"); - EXPECT_EQ(Expression("acsc(-2/sqrt(3))").toString(), - "-Pi/3"); - EXPECT_EQ(Expression("acsc(-2/sqrt(2))").toString(), - "-Pi/4"); - EXPECT_EQ(Expression("acsc(-2)").toString(), - "-Pi/6"); - EXPECT_EQ(Expression("acsc(0)").toString(), - "ComplexInf"); - EXPECT_EQ(Expression("acsc(2)").toString(), - "Pi/6"); - EXPECT_EQ(Expression("acsc(2/sqrt(2))").toString(), - "Pi/4"); - EXPECT_EQ(Expression("acsc(2/sqrt(3))").toString(), - "Pi/3"); - EXPECT_EQ(Expression("acsc(1)").toString(), - "Pi/2"); - - EXPECT_EQ(Expression("asin(sqrt(5)/10)").toString(), - "asin(sqrt(5)/10)"); - EXPECT_EQ(Expression("acos(sqrt(5)/10)").toString(), - "acos(sqrt(5)/10)"); - EXPECT_EQ(Expression("atan(sqrt(5)/10)").toString(), - "atan(sqrt(5)/10)"); - EXPECT_EQ(Expression("acot(sqrt(5)/10)").toString(), - "acot(sqrt(5)/10)"); - EXPECT_EQ(Expression("asec(sqrt(5)/10)").toString(), - "asec(sqrt(5)/10)"); - EXPECT_EQ(Expression("acsc(sqrt(5)/10)").toString(), - "acsc(sqrt(5)/10)"); - - EXPECT_EQ(Expression("asin(x)").toString(), - "asin(x)"); - EXPECT_EQ(Expression("acos(x)").toString(), - "acos(x)"); - EXPECT_EQ(Expression("atan(x)").toString(), - "atan(x)"); - EXPECT_EQ(Expression("acot(x)").toString(), - "acot(x)"); - EXPECT_EQ(Expression("asec(x)").toString(), - "asec(x)"); - EXPECT_EQ(Expression("acsc(x)").toString(), - "acsc(x)"); - - EXPECT_EQ(Expression("asin(sqrt(x))").toString(), - "asin(sqrt(x))"); - EXPECT_EQ(Expression("acos(sqrt(x))").toString(), - "acos(sqrt(x))"); - EXPECT_EQ(Expression("atan(sqrt(x))").toString(), - "atan(sqrt(x))"); - EXPECT_EQ(Expression("acot(sqrt(x))").toString(), - "acot(sqrt(x))"); - EXPECT_EQ(Expression("asec(sqrt(x))").toString(), - "asec(sqrt(x))"); - EXPECT_EQ(Expression("acsc(sqrt(x))").toString(), - "acsc(sqrt(x))"); - - EXPECT_EQ(Expression("asin(sqrt(x)/2)").toString(), - "asin(sqrt(x)/2)"); - EXPECT_EQ(Expression("acos(sqrt(x)/2)").toString(), - "acos(sqrt(x)/2)"); - EXPECT_EQ(Expression("atan(sqrt(x)/2)").toString(), - "atan(sqrt(x)/2)"); - EXPECT_EQ(Expression("asec(sqrt(x)/2)").toString(), - "asec(sqrt(x)/2)"); - EXPECT_EQ(Expression("acsc(sqrt(x)/2)").toString(), - "acsc(sqrt(x)/2)"); - - EXPECT_EQ(Expression("asin(-x)").toString(), - "asin(-x)"); - EXPECT_EQ(Expression("acos(-x)").toString(), - "acos(-x)"); - EXPECT_EQ(Expression("atan(-x)").toString(), - "atan(-x)"); - EXPECT_EQ(Expression("acot(-x)").toString(), - "acot(-x)"); - EXPECT_EQ(Expression("asec(-x)").toString(), - "asec(-x)"); - EXPECT_EQ(Expression("acsc(-x)").toString(), - "acsc(-x)"); - - EXPECT_EQ(Expression("asin(-sqrt(x))").toString(), - "asin(-sqrt(x))"); - EXPECT_EQ(Expression("acos(-sqrt(x))").toString(), - "acos(-sqrt(x))"); - EXPECT_EQ(Expression("atan(-sqrt(x))").toString(), - "atan(-sqrt(x))"); - EXPECT_EQ(Expression("acot(-sqrt(x))").toString(), - "acot(-sqrt(x))"); - EXPECT_EQ(Expression("asec(-sqrt(x))").toString(), - "asec(-sqrt(x))"); - EXPECT_EQ(Expression("acsc(-sqrt(x))").toString(), - "acsc(-sqrt(x))"); - - EXPECT_EQ(Expression("asin(-sqrt(x)/2)").toString(), - "asin(-sqrt(x)/2)"); - EXPECT_EQ(Expression("acos(-sqrt(x)/2)").toString(), - "acos(-sqrt(x)/2)"); - EXPECT_EQ(Expression("atan(-sqrt(x)/2)").toString(), - "atan(-sqrt(x)/2)"); - EXPECT_EQ(Expression("acot(-sqrt(x)/2)").toString(), - "acot(-sqrt(x)/2)"); - EXPECT_EQ(Expression("asec(-sqrt(x)/2)").toString(), - "asec(-sqrt(x)/2)"); - EXPECT_EQ(Expression("acsc(-sqrt(x)/2)").toString(), - "acsc(-sqrt(x)/2)"); -} diff --git a/tests/src/overall/solve/SolveTests.cpp b/tests/src/overall/solve/SolveTests.cpp deleted file mode 100644 index e7a04abd2..000000000 --- a/tests/src/overall/solve/SolveTests.cpp +++ /dev/null @@ -1,148 +0,0 @@ -#include - -#include "fintamath/expressions/ExpressionFunctions.hpp" - -using namespace fintamath; - -TEST(SolveTests, solveTest) { - EXPECT_EQ(solve(Expression("x - 10 = 0")).toString(), - "x = 10"); - EXPECT_EQ(solve(Expression("-10 - x = 0")).toString(), - "x = -10"); - - EXPECT_EQ(solve(Expression("z - 10 - I = 0")).toString(), - "z = 10 + I"); - EXPECT_EQ(solve(Expression("(6 + 3I)^2 = 4I - 30z")).toString(), - "z = -9/10 - 16/15 I"); - - EXPECT_EQ(solve(Expression("x^2 - 10 = 39")).toString(), - "x = -7 | x = 7"); - EXPECT_EQ(solve(Expression("x^2 = 0")).toString(), - "x = 0"); - EXPECT_EQ(solve(Expression("x^2 = 1")).toString(), - "x = -1 | x = 1"); - EXPECT_EQ(solve(Expression("x^2 - 2x - 3 = 0")).toString(), - "x = -1 | x = 3"); - EXPECT_EQ(solve(Expression("15 - 2x - x^2 = 0")).toString(), - "x = -5 | x = 3"); - EXPECT_EQ(solve(Expression("x^2 + 12x + 36 = 0")).toString(), - "x = -6"); - EXPECT_EQ(solve(Expression("x^2 + 12x = 0")).toString(), - "x = -12 | x = 0"); - EXPECT_EQ(solve(Expression("x^2 - 23x - 3 = 0")).toString(), - "x = -sqrt(541)/2 + 23/2 | x = sqrt(541)/2 + 23/2"); - EXPECT_EQ(solve(Expression("-12x^2 - 23x + 30 = 0")).toString(), - "x = -sqrt(1969)/24 - 23/24 | x = sqrt(1969)/24 - 23/24"); - EXPECT_EQ(solve(Expression("-33x^2 - x + 34 = 0")).toString(), - "x = -34/33 | x = 1"); - EXPECT_EQ(solve(Expression("2x^2 + 2sqrt(2)x + 1 = 0")).toString(), - "x = -sqrt(2)/2"); - - EXPECT_EQ(solve(Expression("x^2 = -1")).toString(), - "x = -I | x = I"); - EXPECT_EQ(solve(Expression("x^2 + 4x + 5 = 0")).toString(), - "x = -2 - I | x = -2 + I"); - EXPECT_EQ(solve(Expression("2x^2 + x + 1 = 0")).toString(), - "x = -(I sqrt(7))/4 - 1/4 | x = (I sqrt(7))/4 - 1/4"); - EXPECT_EQ(solve(Expression("x^2 + 3x + 5 = 0")).toString(), - "x = -(I sqrt(11))/2 - 3/2 | x = (I sqrt(11))/2 - 3/2"); - - // TODO: implement cubic equations - EXPECT_EQ(solve(Expression("x^3 - 3x^2 + 3x - 1 = 0")).toString(), - "x^3 - 3 x^2 + 3 x - 1 = 0"); // TODO: x = 1 - // EXPECT_EQ(solve(Expression("x^3 - 6x^2 + 11x - 6 = 0")).toString(), - // "x = 1 | x = 2 | x = 3"); - // EXPECT_EQ(solve(Expression("x^3 + 2x^2 - 5x - 6 = 0")).toString(), - // "x = -3 | x = -1 | x = 2"); - // EXPECT_EQ(solve(Expression("x^3 = 0")).toString(), - // "x = 0"); - // EXPECT_EQ(solve(Expression("x^3 + 1 = 0")).toString(), - // "x = -1"); - // EXPECT_EQ(solve(Expression("x^3 - 1 = 0")).toString(), - // "x = 1"); - // EXPECT_EQ(solve(Expression("x^3 + 2x^2 + x = 0")).toString(), - // "x = -1 | x = 0"); - // EXPECT_EQ(solve(Expression("-x^3 + 5x^2 - 8x + 4 = 0")).toString(), - // "x = 1 | x = 2"); - // EXPECT_EQ(solve(Expression("-2x^3 + 4x^2 + 4x - 8 = 0")).toString(), - // "x = -1 | x = 1 | x = 2"); - // EXPECT_EQ(solve(Expression("2x^3 - 3x^2 - 11x + 6 = 0")).toString(), - // "x = -2 | x = 1/2 | x = 3"); - // EXPECT_EQ(solve(Expression("3x^3 - 3x^2 - 12x - 8 = 0")).toString(), - // "1/9 (3 + (1485 - 162 sqrt(23))^(1/3) + 3 (55 + 6 sqrt(23))^(1/3))"); - - EXPECT_EQ(solve(Expression("x < 1")).toString(), - "x < 1"); - EXPECT_EQ(solve(Expression("x < -10")).toString(), - "x < -10"); - EXPECT_EQ(solve(Expression("x! = 0")).toString(), - "x! = 0"); - - // TODO: implement quadric inequalities - EXPECT_EQ(solve(Expression("x^2 + 2 x - 1 < 0")).toString(), - "x^2 + 2 x - 1 < 0"); - - EXPECT_EQ(solve(Expression("15x^2 + sin(25)x - 10% = Ey")).toString(), - "x^2 + (sin(25) x)/15 - (E y)/15 - 1/150 = 0"); - EXPECT_EQ(solve(Expression("x + x_1 + x_2 + y + y_1 = 0")).toString(), - "x + x_1 + x_2 + y + y_1 = 0"); - EXPECT_EQ(solve(Expression("-x^a = 0")).toString(), - "x^a = 0"); - EXPECT_EQ(solve(Expression("sin(x) = 0")).toString(), - "sin(x) = 0"); - EXPECT_EQ(solve(Expression("x^2 + y = 0")).toString(), - "x^2 + y = 0"); - EXPECT_EQ(solve(Expression("x y = 0")).toString(), - "x y = 0"); - EXPECT_EQ(solve(Expression("2 x^a = 0")).toString(), - "x^a = 0"); - EXPECT_EQ(solve(Expression("x^b a = 0")).toString(), - "a x^b = 0"); - EXPECT_EQ(solve(Expression("x/y = 0")).toString(), - "x = 0"); - EXPECT_EQ(solve(Expression("x^2 - 2*sin(2) = 0")).toString(), - "x = -sqrt(8 sin(2))/2 | x = sqrt(8 sin(2))/2"); - EXPECT_EQ(solve(Expression("x = x sqrt(x)")).toString(), - "x^(3/2) - x = 0"); - EXPECT_EQ(solve(Expression("x = 3^x")).toString(), - "x - 3^x = 0"); - - EXPECT_EQ(solve(Expression("E = Ey")).toString(), - "y = 1"); - EXPECT_EQ(solve(Expression("sin(4) = sin(4) y")).toString(), - "y = 1"); - EXPECT_EQ(solve(Expression("E >= Ey")).toString(), - "y <= 1"); - EXPECT_EQ(solve(Expression("sin(4) >= sin(4) y")).toString(), - "y >= 1"); - EXPECT_EQ(solve(Expression("x >= x sqrt(x)")).toString(), - "x^(3/2) - x <= 0"); - EXPECT_EQ(solve(Expression("x >= x^(1/100)")).toString(), - "x - root(x, 100) >= 0"); -} - -TEST(SolveTests, solveApproximateTest) { - const Variable x("x"); - - { - Expression expr = pow(x + 1, 6); - EXPECT_EQ(expr.toString(), "x^6 + 6 x^5 + 15 x^4 + 20 x^3 + 15 x^2 + 6 x + 1"); - - expr = solve(expr); - EXPECT_EQ(expr.toString(), "x^6 + 6 x^5 + 15 x^4 + 20 x^3 + 15 x^2 + 6 x + 1"); - - expr = approximate(expr, 2); - EXPECT_EQ(expr.toString(), "x^6 + 6 x^5 + 15 x^4 + 20 x^3 + 15 x^2 + 6 x + 1"); - } - - { - Expression expr = pow(x + 1, 7); - EXPECT_EQ(expr.toString(), "x^7 + 7 x^6 + 21 x^5 + 35 x^4 + 35 x^3 + 21 x^2 + 7 x + 1"); - - expr = solve(expr); - EXPECT_EQ(expr.toString(), "x^7 + 7 x^6 + 21 x^5 + 35 x^4 + 35 x^3 + 21 x^2 + 7 x + 1"); - - expr = approximate(expr, 2); - EXPECT_EQ(expr.toString(), "x^7 + 7 x^6 + 21 x^5 + 35 x^4 + 35 x^3 + 21 x^2 + 7 x + 1"); - } -}