Exemplo n.º 1
1
RCP<const Basic> hermite(RCP<const Integer> n, RCP<const Basic> y)
{
    if (eq(*n, *one)) return mul(y, integer(2));
    if (eq(*n, *zero)) return one;
    return expand(sub(mul(mul(integer(2), y), hermite(n->subint(*one), y)),
        mul(integer(2), mul(n->subint(*one), hermite(n->subint(*integer(2)), y)))));
}
Exemplo n.º 2
0
using SymEngine::erf;
using SymEngine::sub;
using SymEngine::eval_mpfr;
using SymEngine::integer_class;
using SymEngine::print_stack_on_segfault;
using SymEngine::max;
using SymEngine::min;
using SymEngine::loggamma;

TEST_CASE("precision: eval_mpfr", "[eval_mpfr]")
{
    mpfr_t a;
    mpfr_init2(a, 53);
    RCP<const Basic> s = mul(pi, integer(1963319607));
    RCP<const Basic> t = integer(integer_class("6167950454"));
    RCP<const Basic> r = sub(s, t);
    // value of `r` is approximately 0.000000000149734291

    eval_mpfr(a, *r, MPFR_RNDN);
    // `eval_mpfr` was done with a precision of 53 bits (precision of `a`) and
    // rounding mode `MPFR_RNDN`
    // With 53 bit precision, `s` and `t` have the same value.
    // Hence value of `r` was  rounded down to `0.000000000000000`
    REQUIRE(mpfr_cmp_si(a, 0) == 0);

    mpfr_set_prec(a, 100);
    eval_mpfr(a, *r, MPFR_RNDN);
    // `eval_mpfr` was done with a precision of 100 bits (precision of `a`) and
    // rounding mode `MPFR_RNDN`
    // With 100 bit precision, `s` and `t` are not equal in value.
    // Value of `r` is a positive quantity with value 0.000000000149734291.....