Skip to content

Commit

Permalink
Merge pull request #1828 from isuruf/exp
Browse files Browse the repository at this point in the history
Fix exp(x + num)/exp(x) not evaluating
  • Loading branch information
isuruf committed Sep 3, 2021
2 parents 01fd6b4 + c50264e commit e6716b6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/test_symengine_unix.sh
Expand Up @@ -13,6 +13,9 @@ if [[ "$(uname)" == "Linux" ]]; then
fi

if [[ "$TEST_CLANG_FORMAT" == "yes" ]]; then
export conda_pkgs="clang-tools=11"
source bin/install_travis.sh
ln -sf $CONDA_PREFIX/bin/clang-format $CONDA_PREFIX/bin/clang-format-11
source bin/travis_clang_format.sh
elif [[ "$CONDA_ENV_FILE" == *"matchpycpp"* ]]; then
source bin/install_travis.sh
Expand Down
11 changes: 11 additions & 0 deletions symengine/mul.cpp
Expand Up @@ -296,6 +296,17 @@ void Mul::dict_add_term_new(const Ptr<RCP<const Number>> &coef,
d.erase(it);
m->power_num(outArg(*coef), d, exp_);
}
} else if (eq(*it->first, *E)) {
RCP<const Number> p = rcp_static_cast<const Number>(it->second);
if (not p->is_exact()) {
// Evaluate E**0.2, but not E**2
RCP<const Basic> exp_ = p->get_eval().exp(*p);
if (is_a_Number(*exp_)) {
imulnum(outArg(*coef),
rcp_static_cast<const Number>(exp_));
d.erase(it);
}
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions symengine/tests/basic/test_arit.cpp
Expand Up @@ -293,6 +293,12 @@ TEST_CASE("Mul: arit", "[arit]")
real_double(0.2)});
REQUIRE(std::abs(down_cast<const RealDouble &>(*r2).i - 0.03) < 1e-12);

r1 = real_double(0.1);
r2 = div(exp(add(x, r1)), exp(x));
REQUIRE(is_a<RealDouble>(*r2));
REQUIRE(std::abs(down_cast<const RealDouble &>(*r2).i - 1.10517091807565)
< 1e-10);

// Real * 0 = 0 * Real = 0
r1 = real_double(0.0);
r2 = integer(0);
Expand Down
6 changes: 6 additions & 0 deletions symengine/tests/basic/test_infinity.cpp
Expand Up @@ -8,9 +8,11 @@
#include <symengine/constants.h>
#include <symengine/symengine_exception.h>
#include <symengine/functions.h>
#include <symengine/add.h>
#include <symengine/pow.h>
#include <symengine/complex_double.h>

using SymEngine::add;
using SymEngine::Basic;
using SymEngine::Complex;
using SymEngine::complex_double;
Expand Down Expand Up @@ -329,6 +331,10 @@ TEST_CASE("Powers to Infinity", "[Infinity]")
CHECK_THROWS_AS(integer(10)->pow(*c), SymEngineException &);
CHECK_THROWS_AS(integer(-3)->pow(*c), SymEngineException &);
CHECK_THROWS_AS(cx->pow(*c), NotImplementedError &);

RCP<const Basic> x = symbol("x");
RCP<const Basic> r = exp(add(c, x));
CHECK_THROWS_AS(div(r, exp(x)), DomainError &);
}

TEST_CASE("Evaluate Class of Infinity", "[Infinity]")
Expand Down

0 comments on commit e6716b6

Please sign in to comment.