Exemplo n.º 1
1
int main(int argc, char *argv[])
{
    SymEngine::print_stack_on_segfault();
    int N;
    if (argc == 2) {
        N = std::atoi(argv[1]);
    } else {
        N = 20;
    }

    RCP<const Basic> x = symbol("x"), y = symbol("y"), e, f;
    e = pow(add(one, add(mul(sqrt(integer(3)), x), mul(sqrt(integer(5)), y))),
            integer(N));
    f = mul(e, add(e, sqrt(integer(7))));
    auto t1 = std::chrono::high_resolution_clock::now();
    f = expand(f);
    auto t2 = std::chrono::high_resolution_clock::now();

    std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1)
                     .count()
              << "ms" << std::endl;
    // std::cout << f->__str__() << std::endl;

    return 0;
}
Exemplo n.º 2
1
int main(int argc, char* argv[])
{
    Teuchos::print_stack_on_segfault();

    RCP<const Basic> x = symbol("x");
    RCP<const Basic> y = symbol("y");
    RCP<const Basic> z = symbol("z");
    RCP<const Basic> w = symbol("w");
    RCP<const Basic> i100 = integer(100);

    RCP<const Basic> e, r;

    e = pow(add(add(pow(x, y), pow(y, x)), pow(z, x)), i100);

    std::cout << "Expanding: " << *e << std::endl;

    auto t1 = std::chrono::high_resolution_clock::now();
    r = expand(e);
    auto t2 = std::chrono::high_resolution_clock::now();
    //std::cout << *r << std::endl;
    std::cout
        << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
        << "ms" << std::endl;
    std::cout << "number of terms: "
        << rcp_dynamic_cast<const Add>(r)->dict_.size() << std::endl;

    return 0;
}
Exemplo n.º 3
1
int main(int argc, char* argv[])
{
    SymEngine::print_stack_on_segfault();

    RCP<const Basic> x = symbol("x");
    RCP<const Basic> y = symbol("y");
    RCP<const Basic> z = symbol("z");
    RCP<const Basic> w = symbol("w");
    RCP<const Basic> i15 = integer(15);

    RCP<const Basic> e, f, r;

    e = pow(add(add(add(x, y), z), w), i15);
    f = mul(e, add(e, w));

    std::cout << "Expanding: " << *f << std::endl;

    auto t1 = std::chrono::high_resolution_clock::now();
    r = expand(f);
    auto t2 = std::chrono::high_resolution_clock::now();
    //std::cout << *r << std::endl;
    std::cout
        << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
        << "ms" << std::endl;
    std::cout << "number of terms: "
        << rcp_dynamic_cast<const Add>(r)->dict_.size() << std::endl;

    return 0;
}
Exemplo n.º 4
1
double R3()
{
    RCP<const Basic> x = symbol("x");
    RCP<const Basic> y = symbol("y");
    RCP<const Basic> z = symbol("z");
    RCP<const Basic> f = add(x, add(y, z));
    std::vector<bool> vec(10);
    auto t1 = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < 10; i++) {
        vec.push_back(eq(*f, *f));
    }
    auto t2 = std::chrono::high_resolution_clock::now();
    return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
Exemplo n.º 5
1
int main(int argc, char *argv[])
{
    SymEngine::print_stack_on_segfault();

    RCP<const Symbol> x = symbol("x");
    std::vector<Expression> v;
    int N;

    N = 1000;
    for (int i = 0; i < N; ++i) {
        Expression coef(i);
        v.push_back(coef);
    }

    UExprDict c, p(UExprPoly::from_vec(x, v)->get_dict());
    auto t1 = std::chrono::high_resolution_clock::now();
    c = UnivariateSeries::mul(p, p, 1000);
    auto t2 = std::chrono::high_resolution_clock::now();
    // std::cout << *a << std::endl;
    std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1)
                     .count()
              << "ms" << std::endl;

    return 0;
}
Exemplo n.º 6
1
double R8()
{
    RCP<const Basic> x = symbol("x");
    auto t1 = std::chrono::high_resolution_clock::now();
    x = right(pow(x, integer(2)), integer(0), integer(5), x, 10000);
    auto t2 = std::chrono::high_resolution_clock::now();
    return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
Exemplo n.º 7
1
double R2()
{
    RCP<const Basic> g;
    RCP<const Integer> n = integer(15);
    RCP<const Basic> y = symbol("y");
    auto t1 = std::chrono::high_resolution_clock::now();
    g = hermite(n, y);
    auto t2 = std::chrono::high_resolution_clock::now();
    return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
Exemplo n.º 8
1
double R5()
{
    RCP<const Basic> x = symbol("x");
    RCP<const Basic> y = symbol("y");
    RCP<const Basic> z = symbol("z");
    RCP<const Basic> f = add(x, add(y, z));
    vec_basic v;

    v.push_back(x);
    v.push_back(y);
    v.push_back(z);
    for (int i = 0; i < 8; i++) {
        v.push_back(add(v[i], add(v[i + 1], v[i + 2])));
    }

    auto t1 = std::chrono::high_resolution_clock::now();
    std::set<RCP<const Basic>, RCPBasicKeyLess> s(v.begin(), v.end());
    auto t2 = std::chrono::high_resolution_clock::now();
    return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
Exemplo n.º 9
1
int main(int argc, char* argv[])
{
    Teuchos::print_stack_on_segfault();
    int N;
    if (argc == 2) {
        N = std::atoi(argv[1]);
    } else {
        N = 100;
    }

    auto t1 = std::chrono::high_resolution_clock::now();
    RCP<const Basic> e, f, s, a0, a1;
    a0 = symbol("a0");
    a1 = symbol("a1");
    e = add(a0, a1);
    f = zero;
    for (int i = 2; i < N; i++) {
        s = symbol("a" + std::to_string(i));
        e = add(e, s);
        f = sub(f, s);
    }
    e = expand(mul(e, e));
    map_basic_basic dict;
    insert(dict, a0, f);
    e = e->subs(dict);

    e = expand(e);

    auto t2 = std::chrono::high_resolution_clock::now();

    std::cout
        << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
        << "ms" << std::endl;
    std::cout << e->__str__() << std::endl;

    return 0;
}
Exemplo n.º 10
1
int main(int argc, char *argv[])
{
    SymEngine::print_stack_on_segfault();
    int N;
    if (argc == 2) {
        N = std::atoi(argv[1]);
    } else {
        N = 100;
    }

    RCP<const Basic> e, f, s, a0, a1;
    a0 = symbol("a0");
    a1 = symbol("a1");
    e = add(a0, a1);
    f = zero;
    for (long long i = 2; i < N; i++) {
        std::ostringstream o;
        o << "a" << i;
        s = symbol(o.str());
        e = add(e, s);
        f = add(f, s);
    }
    f = neg(f);
    auto t1 = std::chrono::high_resolution_clock::now();
    e = expand(pow(e, integer(2)));
    e = e->subs({{a0, f}});
    e = expand(e);
    auto t2 = std::chrono::high_resolution_clock::now();

    std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1)
                     .count()
              << "ms" << std::endl;
    std::cout << e->__str__() << std::endl;

    return 0;
}
Exemplo n.º 11
1
int main(int argc, char* argv[])
{
    Teuchos::print_stack_on_segfault();

    RCP<const Basic> x = symbol("x");
    RCP<const Basic> a, c;
    int N;

    N = 3000; a = x; c = integer(1);
    auto t1 = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < N; i++) {
        a = add(a, mul(c, pow(x, integer(i))));
        c = mul(c, integer(-1));
    }
    auto t2 = std::chrono::high_resolution_clock::now();
    //std::cout << *a << std::endl;
    std::cout
        << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
        << "ms" << std::endl;
    std::cout << "number of terms: "
        << rcp_dynamic_cast<const Add>(a)->dict_.size() << std::endl;

    return 0;
}
Exemplo n.º 12
1
using SymEngine::zero;
using SymEngine::sin;
using SymEngine::erf;
using SymEngine::RCP;
using SymEngine::rcp_dynamic_cast;
using SymEngine::map_basic_basic;
using SymEngine::print_stack_on_segfault;
using SymEngine::real_double;
using SymEngine::kronecker_delta;
using SymEngine::levi_civita;
using SymEngine::msubs;
using SymEngine::function_symbol;

TEST_CASE("Symbol: subs", "[subs]")
{
    RCP<const Basic> x = symbol("x");
    RCP<const Basic> y = symbol("y");
    RCP<const Basic> z = symbol("z");
    RCP<const Basic> w = symbol("w");
    RCP<const Basic> i2 = integer(2);
    RCP<const Basic> i3 = integer(3);
    RCP<const Basic> i4 = integer(4);

    RCP<const Basic> r1 = x;
    RCP<const Basic> r2 = y;
    map_basic_basic d;
    d[x] = y;
    REQUIRE(eq(*r1->subs(d), *r2));
    REQUIRE(neq(*r1->subs(d), *r1));
}
Exemplo n.º 13
0
int main(int argc, char* argv[])
{
    print_stack_on_segfault();
    RCP<const Basic> x = symbol("x");
    RCP<const Basic> y = symbol("y");
    RCP<const Basic> z = symbol("z");
    RCP<const Basic> w = symbol("w");
    RCP<const Basic> i15 = integer(15);

    RCP<const Basic> e, f1, f2, r;

    e = pow(add(add(add(x, y), z), w), i15);
    f1 = expand(e);
    f2 = expand(add(e, w));

    umap_basic_num syms;
    insert(syms, x, integer(0));
    insert(syms, y, integer(1));
    insert(syms, z, integer(2));
    insert(syms, w, integer(3));

    umap_vec_mpz P1, P2, C;

    expr2poly(f1, syms, P1);
    expr2poly(f2, syms, P2);
    std::cout << "poly_mul start" << std::endl;
    auto t1 = std::chrono::high_resolution_clock::now();
    poly_mul(P1, P2, C);
    auto t2 = std::chrono::high_resolution_clock::now();
    std::cout << "poly_mul stop" << std::endl;


    /*
    std::cout << *e << std::endl;
    std::cout << *f1 << std::endl;
    std::cout << P1 << std::endl;
    std::cout << *f2 << std::endl;
    std::cout << P2 << std::endl;
    std::cout << "RESULT:" << std::endl;
    std::cout << C << std::endl;
    */
    std::cout
        << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
        << "ms" << std::endl;
    std::cout << "number of terms: "
        << C.size() << std::endl;



    return 0;
}
Exemplo n.º 14
0
double S2()
{
    RCP<const Basic> x = symbol("x");
    RCP<const Basic> y = symbol("y");
    RCP<const Basic> z = symbol("z");
    RCP<const Basic> e;
    RCP<const Basic> f;

    e = pow(add(pow(x, sin(x)), add(pow(y, cos(y)), pow(z, add(x, y)))), integer(100));

    auto t1 = std::chrono::high_resolution_clock::now();
    f = expand(e);
    auto t2 = std::chrono::high_resolution_clock::now();
    return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
Exemplo n.º 15
0
double E()
{
    RCP<const Basic> s = integer(0);
    RCP<const Basic> y = symbol("y");
    RCP<const Basic> t = symbol("t");

    auto t1 = std::chrono::high_resolution_clock::now();
    for (int i = 1; i <= 10; i++) {
        s = add(s, div(mul(integer(i), mul(y, pow(t, integer(i)))),
                    pow(add(y, mul(integer(abs(5 - i)), t)), integer(i))));
    }
    auto t2 = std::chrono::high_resolution_clock::now();

    return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
Exemplo n.º 16
0
double S3a()
{
    RCP<const Basic> x = symbol("x");
    RCP<const Basic> y = symbol("y");
    RCP<const Basic> z = symbol("z");
    RCP<const Basic> e;
    RCP<const Basic> f;

    e = pow(add(pow(x, y), add(pow(y, z), pow(z, x))), integer(500));
    e = expand(e);

    auto t1 = std::chrono::high_resolution_clock::now();
    f = e->diff(rcp_static_cast<const Symbol>(x));
    auto t2 = std::chrono::high_resolution_clock::now();
    return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
Exemplo n.º 17
0
double S1()
{
    RCP<const Basic> x = symbol("x");
    RCP<const Basic> y = symbol("y");
    RCP<const Basic> z = symbol("z");
    RCP<const Basic> e;
    RCP<const Basic> f;

    e = pow(add(x, add(y, add(z, one))), integer(7));
    f = mul(e, add(e, one));

    auto t1 = std::chrono::high_resolution_clock::now();
    f = expand(f);
    auto t2 = std::chrono::high_resolution_clock::now();
    return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
Exemplo n.º 18
0
void test_expand()
{
    RCP<const Basic> x = symbol("x");
    RCP<const Basic> y = symbol("y");
    RCP<const Basic> z = symbol("z");
    RCP<const Basic> w = symbol("w");
    RCP<const Basic> i4 = integer(2);

    RCP<const Basic> e, f1, f2, r;

    e = pow(add(add(add(x, y), z), w), i4);
    f1 = expand(e);
    f2 = expand(add(e, w));

    umap_basic_num syms;
    insert(syms, x, integer(0));
    insert(syms, y, integer(1));
    insert(syms, z, integer(2));
    insert(syms, w, integer(3));

    umap_vec_mpz P1, P2, C;

    expr2poly(f1, syms, P1);
    expr2poly(f2, syms, P2);
    std::cout << "poly_mul start" << std::endl;
    auto t1 = std::chrono::high_resolution_clock::now();
    poly_mul(P1, P2, C);
    auto t2 = std::chrono::high_resolution_clock::now();
    std::cout << "poly_mul stop" << std::endl;


    /*
    std::cout << *e << std::endl;
    std::cout << *f1 << std::endl;
    std::cout << P1 << std::endl;
    std::cout << *f2 << std::endl;
    std::cout << P2 << std::endl;
    std::cout << "RESULT:" << std::endl;
    std::cout << C << std::endl;
    */
    std::cout
        << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
        << "ms" << std::endl;
}
Exemplo n.º 19
0
double R7()
{
    RCP<const Basic> x = symbol("x");
    RCP<const Basic> f = add(pow(x, integer(24)),
                             add(mul(integer(34), pow(x, integer(12))),
                                 add(mul(integer(45), pow(x, integer(3))),
                                     add(mul(integer(9), pow(x, integer(18))),
                                         add(mul(integer(34), pow(x, integer(10))),
                                             mul(integer(32), pow(x, integer(21))))))));
    vec_basic v;
    auto t1 = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < 10000; ++i) {
        v.push_back(f->subs({{x, real_double(0.5)}}));
    }
    auto t2 = std::chrono::high_resolution_clock::now();
    return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
Exemplo n.º 20
0
using SymEngine::umap_short_basic;
using SymEngine::EulerGamma;
using SymEngine::Number;
using SymEngine::umap_int_basic;
using SymEngine::pi;
using SymEngine::I;
using SymEngine::DomainError;
using SymEngine::NotImplementedError;
using SymEngine::SymEngineException;
using SymEngine::gamma;

using namespace SymEngine::literals;

TEST_CASE("Create UnivariateSeries", "[UnivariateSeries]")
{
    RCP<const Symbol> x = symbol("x");
    map_int_Expr adict_ = {{0, 1}, {1, 2}, {2, 1}};
    UExprDict apoly_(adict_);
    RCP<const UnivariateSeries> P = univariate_series(x, 2, apoly_);
    REQUIRE(P->__str__() == "x**2 + 2*x + 1 + O(x**2)");

    map_int_Expr bdict_ = {{0, 1}, {1, 0}, {2, 2}, {3, 1}};
    UExprDict bpoly_(bdict_);
    RCP<const UnivariateSeries> Q = UnivariateSeries::create(x, 5, bpoly_);
    REQUIRE(Q->__str__() == "x**3 + 2*x**2 + 1 + O(x**5)");

    map_int_Expr cdict_
        = {{0, symbol("c")}, {1, symbol("b")}, {2, symbol("a")}};
    UExprDict cpoly_(cdict_);
    RCP<const UnivariateSeries> R = UnivariateSeries::create(x, 3, cpoly_);
    REQUIRE(R->__str__() == "a*x**2 + b*x + c + O(x**3)");
using SymEngine::MIntPoly;
using SymEngine::MExprPoly;

using namespace SymEngine::literals;

TEST_CASE("find_gen_poly", "[b2poly]")
{
    umap_basic_num gens, rgens;
    RCP<const Basic> basic;
    RCP<const Integer> one = integer(1);
    RCP<const Integer> minus_one = integer(-1);
    RCP<const Number> i2 = rcp_static_cast<const Number>(integer(2));
    RCP<const Number> i3 = rcp_static_cast<const Number>(integer(3));
    RCP<const Number> i6 = rcp_static_cast<const Number>(integer(6));
    RCP<const Number> hf = rcp_static_cast<const Number>(div(one, integer(2)));
    RCP<const Symbol> x = symbol("x");
    RCP<const Symbol> y = symbol("y");
    RCP<const Symbol> z = symbol("z");
    RCP<const Basic> xb2 = div(x, i2);
    RCP<const Basic> twopx = pow(i2, x);

    // x**2 + x**(1/2) -> (x**(1/2))
    basic = add(pow(x, hf), pow(x, i2));
    gens = _find_gens_poly(basic);
    rgens = {{x, hf}};
    REQUIRE(unified_eq(gens, rgens));

    // x**(-1/2) + x**2 + x**(-1) -> (x, x**(-1/2))
    basic = add(add(pow(x, neg(hf)), pow(x, i2)), pow(x, minus_one));
    gens = _find_gens_poly(basic);
    rgens = {{x, one}, {pow(x, minus_one), hf}};
Exemplo n.º 22
0
int main(int argc, char* argv[])
{
    SymEngine::print_stack_on_segfault();

    DenseMatrix A = DenseMatrix(3, 3, {symbol("a"), symbol("b"), symbol("c"),
        symbol("d"), symbol("e"), symbol("f"), symbol("g"), symbol("h"), symbol("i")});


    DenseMatrix B = DenseMatrix(3, 3, {symbol("x"), symbol("y"), symbol("z"), symbol("p"),
        symbol("q"), symbol("r"), symbol("u"), symbol("v"), symbol("w")});

    DenseMatrix C(3, 3);

    std::cout << "Multiplying Two Matrices; matrix dimensions: 3 x 3" << std::endl;

    unsigned N = 10000;
    auto t1 = std::chrono::high_resolution_clock::now();
    for (unsigned i = 0; i < N; i++)
        mul_dense_dense(A, B, C);
    auto t2 = std::chrono::high_resolution_clock::now();

    std::cout
        << std::chrono::duration_cast<std::chrono::microseconds>(t2-t1).count()/N
        << " microseconds" << std::endl;

    return 0;
}
Exemplo n.º 23
0
int main(int argc, char* argv[])
{
    SymEngine::print_stack_on_segfault();

    DenseMatrix A = DenseMatrix(3, 3, {symbol("a"), symbol("b"), symbol("c"), symbol("d"),
        symbol("e"), symbol("f"), symbol("g"), symbol("h"), symbol("i")});

    DenseMatrix B = DenseMatrix(3, 3, {symbol("x"), symbol("y"), symbol("z"), symbol("p"),
        symbol("q"), symbol("r"), symbol("u"), symbol("v"), symbol("w")});

    DenseMatrix C(3, 3);

    std::cout << "Adding Two Matrices; matrix dimensions: 3 x 3" << std::endl;

    // We are taking an average time since time for a single addition varied in
    // a range of 40-50 microseconds
    unsigned N = 10000;
    auto t1 = std::chrono::high_resolution_clock::now();
    for (unsigned i = 0; i < N; i++)
        add_dense_dense(A, B, C);
    auto t2 = std::chrono::high_resolution_clock::now();

    std::cout
        << std::chrono::duration_cast<std::chrono::microseconds>(t2-t1).count()/N
        << " microseconds" << std::endl;

    return 0;
}
Exemplo n.º 24
0
using SymEngine::Precedence;
using SymEngine::PrecedenceEnum;
using SymEngine::vec_uint;
using SymEngine::vec_int;
using SymEngine::vec_basic;
using SymEngine::vec_uint;
using SymEngine::RCPBasicKeyLess;
using SymEngine::MExprPoly;
using SymEngine::UExprPoly;
using SymEngine::SymEngineException;

using namespace SymEngine::literals;

TEST_CASE("Constructing MExprPoly", "[MExprPoly]")
{
    RCP<const Symbol> x = symbol("x");
    RCP<const Symbol> y = symbol("y");
    Expression a(symbol("a"));                               // a
    Expression negB(-Expression(symbol("b")));               //-b
    Expression num1(integer(2));                             // 2
    Expression negNum(integer(-3));                          //-3
    Expression comp1(integer(1) + Expression(symbol("c")));  //(1+c)
    Expression comp2(integer(2) - Expression(symbol("d")));  //(2 - d)
    Expression comp3(integer(-3) + Expression(symbol("e"))); //(-3 + e)
    Expression comp4(integer(-4) - Expression(symbol("f"))); //(-4 - f)
    vec_basic s;
    vec_int v;

    RCP<const MExprPoly> p1 = MExprPoly::from_dict(
        {x, y},
        {{{1, 1}, a}, {{1, 2}, negB}, {{2, 1}, num1}, {{0, 1}, negNum}});
Exemplo n.º 25
0
using SymEngine::map_uint_mpz;
using SymEngine::Basic;
using SymEngine::one;
using SymEngine::zero;
using SymEngine::integer;
using SymEngine::vec_basic_eq_perm;
using SymEngine::integer_class;
using SymEngine::UIntDict;
using SymEngine::add;
using SymEngine::vec_integer_class;

using namespace SymEngine::literals;

TEST_CASE("Constructor of UIntPoly", "[UIntPoly]")
{
    RCP<const Symbol> x = symbol("x");
    RCP<const UIntPoly> P
        = UIntPoly::from_dict(x, {{0, 1_z}, {1, 2_z}, {2, 1_z}});
    REQUIRE(P->__str__() == "x**2 + 2*x + 1");

    RCP<const UIntPoly> Q = UIntPoly::from_vec(x, {1_z, 0_z, 2_z, 1_z});
    REQUIRE(Q->__str__() == "x**3 + 2*x**2 + 1");

    RCP<const UIntPoly> R = UIntPoly::from_vec(x, {1_z, 0_z, 2_z, 1_z});
    REQUIRE(R->__str__() == "x**3 + 2*x**2 + 1");

    RCP<const UIntPoly> S = UIntPoly::from_dict(x, {{0, 2_z}});
    REQUIRE(S->__str__() == "2");

    RCP<const UIntPoly> T = UIntPoly::from_dict(x, map_uint_mpz{});
    REQUIRE(T->__str__() == "0");
Exemplo n.º 26
0
#include "catch.hpp"
#include <iostream>
#include <chrono>

#include <symengine/expression.h>

using SymEngine::Expression;
using SymEngine::symbol;

TEST_CASE("Constructors of Expression", "[Expression]")
{
    Expression e0 = symbol("x");
}

TEST_CASE("Printing of Expression", "[Expression]")
{
    Expression e0 = symbol("x");
    std::cout << e0 << std::endl;
}

TEST_CASE("Arithmetic of Expression", "[Expression]")
{
    Expression x = symbol("x"), y = symbol("y");
    auto z = x + y;
    std::cout << z << std::endl;
    z += y;
    std::cout << z << std::endl;
    REQUIRE(z == x + y + y);
    REQUIRE(z == x + 2 * y);
    std::cout << pow_ex(z, z) << std::endl;
    std::cout << pow_ex(z, 45) << std::endl;
Exemplo n.º 27
0
#include <chrono>

#include <symengine/expression.h>

using SymEngine::Expression;
using SymEngine::symbol;
using SymEngine::eq;
using SymEngine::integer;
using SymEngine::real_double;
using SymEngine::complex_double;
using SymEngine::sin;
using SymEngine::pi;

TEST_CASE("Constructors of Expression", "[Expression]")
{
    Expression e0 = symbol("x");
    REQUIRE(eq(*e0.get_basic(), *symbol("x")));

    Expression e1 = 20;
    REQUIRE(eq(*e1.get_basic(), *integer(20)));

    Expression e2 = 10.0;
    REQUIRE(eq(*e2.get_basic(), *real_double(10.0)));

    Expression e3 = std::complex<double>(1.0, 2.0);
    REQUIRE(
        eq(*e3.get_basic(), *complex_double(std::complex<double>(1.0, 2.0))));
}

TEST_CASE("Printing of Expression", "[Expression]")
{
Exemplo n.º 28
0
using SymEngine::add;
using SymEngine::Symbol;
using SymEngine::Integer;
using SymEngine::DenseMatrix;
using SymEngine::Subs;
using SymEngine::Derivative;
using SymEngine::function_symbol;
using SymEngine::I;
using SymEngine::real_double;
using SymEngine::complex_double;

TEST_CASE("test_printing(): printing", "[printing]")
{
    RCP<const Basic> r, r1, r2;
    RCP<const Integer> i = integer(-1);
    RCP<const Symbol> x  = symbol("x");
    RCP<const Symbol> y  = symbol("y");
    RCP<const Symbol> z  = symbol("z");

    r = div(integer(12), pow(integer(196), div(integer(1), integer(2))));
    REQUIRE(r->__str__() == "(3/49)*196**(1/2)");

    r = mul(integer(12), pow(integer(196), div(integer(1), integer(2))));
    REQUIRE(r->__str__() == "12*196**(1/2)");

    r = mul(integer(23), mul(pow(integer(5), div(integer(1), integer(2))),
        pow(integer(7), div(integer(1), integer(2)))));
    REQUIRE(r->__str__() == "23*5**(1/2)*7**(1/2)");

    r = mul(integer(2), pow(symbol("x"), integer(2)));
    REQUIRE(r->__str__() == "2*x**2");
Exemplo n.º 29
0
using SymEngine::pow;
using SymEngine::RCP;
using SymEngine::make_rcp;
using SymEngine::print_stack_on_segfault;
using SymEngine::Complex;
using SymEngine::has_symbol;
using SymEngine::is_a;
using SymEngine::rcp_static_cast;
using SymEngine::set_basic;
using SymEngine::free_symbols;
using SymEngine::function_symbol;
using SymEngine::rational_class;

TEST_CASE("Symbol hash: Basic", "[basic]")
{
    RCP<const Symbol> x  = symbol("x");
    RCP<const Symbol> x2 = symbol("x");
    RCP<const Symbol> y  = symbol("y");

    REQUIRE(x->__eq__(*x));
    REQUIRE(x->__eq__(*x2));
    REQUIRE(not (x->__eq__(*y)));
    REQUIRE(x->__neq__(*y));

    std::hash<Basic> hash_fn;
    // Hashes of x and x2 must be the same:
    REQUIRE(hash_fn(*x) == hash_fn(*x2));
    // Hashes of x and y can but don't have to be different:
    if (hash_fn(*x) != hash_fn(*y)) REQUIRE(x->__neq__(*y));

Exemplo n.º 30
0
#include <symengine/pow.h>
#include <symengine/series.h>

using SymEngine::Basic;
using SymEngine::Integer;
using SymEngine::integer;
using SymEngine::rational;
using SymEngine::Symbol;
using SymEngine::Number;
using SymEngine::symbol;
using SymEngine::Add;
using SymEngine::rcp_static_cast;
using SymEngine::RCP;
using SymEngine::add;
using SymEngine::sin;
using SymEngine::cos;
using SymEngine::series;

TEST_CASE("Expression series expansion interface", "[Expansion interface]")
{
    RCP<const Symbol> x = symbol("x"), y = symbol("y");
    auto ex = div(integer(1), add(integer(1), x));

    auto ser = series(ex, x, 10);

    REQUIRE(rcp_static_cast<const Number>(ser->get_coeff(7))->is_minus_one());
    REQUIRE(rcp_static_cast<const Number>(ser->as_dict()[8])->is_one());
    REQUIRE(ser->as_basic()->__str__()
            == "1 - x + x**2 - x**3 + x**4 - x**5 + x**6 - x**7 + x**8 - x**9");
}