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
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.º 3
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.º 4
1
RCP<const Basic> right(const RCP<const Basic> &f, const RCP<const Number> &a,
                       const RCP<const Number> &b, const RCP<const Basic> &x, int n)
{
    RCP<const Number> Deltax = b->sub(*a)->div(*integer(n));
    RCP<const Number> c = a;
    RCP<const Number> est = integer(0);
    for (int i = 0; i < n; i++) {
        iaddnum(outArg(c), Deltax);
        iaddnum(outArg(est), rcp_static_cast<const Number>(f->subs({{x, c}})));
    }
    return mulnum(est, Deltax);
}
Exemplo n.º 5
1
double B()
{
    RCP<const Number> s = integer(0);

    auto t1 = std::chrono::high_resolution_clock::now();
    for (int i = 1; i <= 1000; i++) {
        s = s->add(*one->div(*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.º 6
1
double C()
{
    RCP<const Integer> x = integer(13*17*31);
    RCP<const Integer> y = integer(13*19*29);

    auto t1 = std::chrono::high_resolution_clock::now();
    for (int i = 1; i <= 200; i++) {
        gcd(*rcp_static_cast<const Integer>(pow(x, integer(300 + i%181))),
            *rcp_static_cast<const Integer>(pow(y, integer(200 + i%183))));
    }
    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
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.º 8
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.º 9
1
double R1()
{
    RCP<const Basic> g;
    RCP<const Basic> h = div(I, integer(2));
    auto t1 = std::chrono::high_resolution_clock::now();
    g = expand(f(f(f(f(f(f(f(f(f(f(h)))))))))));
    auto t2 = std::chrono::high_resolution_clock::now();
    return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
Exemplo n.º 10
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.º 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
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.º 13
1
RCP<const Basic> f(RCP<const Basic> z) {
    return add(mul(sqrt(div(one, integer(3))), pow(z, integer(2))), div(I, integer(3)));
}
Exemplo n.º 14
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.º 15
0
int main(int argc, char* argv[])
{
    SymEngine::print_stack_on_segfault();

    RCP<const Basic> e = sin(integer(1));
    double r, r_exact;

    for(int i = 0; i < 10000; i++)
        e = pow(add(mul(add(e, pow(integer(2), integer(-3))), integer(3)), integer(1)), div(integer(2), integer(3)));

//  Too long:
//  std::cout << "Evaluating: " << *e << std::endl;

    auto t1 = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < 500; i++)
        r = eval_double(*e);
    auto t2 = std::chrono::high_resolution_clock::now();
    std::cout
        << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
        << "ms" << std::endl;
/*
In SymPy for few iterations:
In [7]: sympify("(1 + 3*(1/8 + (1 + 3*(1/8 + (1 + 3*(1/8 + (1 + 3*(1/8 + (1 + 3*(1/8 + sin(1)))^(2/3)))^(2/3)))^(2/3)))^(2/3)))^(2/3)").n(20)
Out[7]: 8.0152751504518535013

//    r_exact = 8.0152751504518535013;

Here is code to use SymPy for more iterations:

In [5]: e = sin(1)

In [6]: for i in range(10):
   ...:     e = ((e+2**(-S(3)))*3 + 1)**(S(2)/3)
   ...:

In [7]: e.n(20)
Out[7]: 9.6473976427977306146

But unfortunately SymPy can't do more than perhaps 10 or 20 iterations, while
we need to test ~10000. However, the numbers seem to converge to 9.85647...

*/
    r_exact = 9.8564741713701043569;
    std::cout << "r (double) = " << r << std::endl;
    std::cout << "r (exact)  = " << r_exact << std::endl;
    std::cout << "error      = " << std::abs(r-r_exact) << std::endl;

    return 0;
}
Exemplo n.º 16
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.º 17
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.º 18
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.º 19
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.º 20
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.º 21
0
using SymEngine::asec;
using SymEngine::acot;
using SymEngine::E;
using SymEngine::EulerGamma;
using SymEngine::eval_arb;
using SymEngine::print_stack_on_segfault;
using SymEngine::min;
using SymEngine::max;

TEST_CASE("Integer: eval_arb", "[eval_arb]")
{
    arb_t a, b;
    arb_init(a);
    arb_init(b);

    eval_arb(a, *integer(3));
    arb_set_ui(b, 3);

    REQUIRE(arb_equal(a, b));

    eval_arb(a, *integer(-45));
    arb_set_si(b, -45);

    REQUIRE(arb_equal(a, b));

    srand(time(nullptr));
    unsigned int ui = rand();

    RCP<const Basic> i = integer(ui);
    eval_arb(a, *i);
    arb_set_ui(b, ui);
Exemplo n.º 22
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.º 23
0
using SymEngine::Number;
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)));
Exemplo n.º 24
0
            return false;
    }
    // If all elements were found, then a == b
    return true;
}

TEST_CASE("test_homogeneous_lde()", "[diophantine]")
{
    std::vector<DenseMatrix> basis, true_basis;

    // First two tests are taken from the following paper:
    // Evelyne Contejean, Herve Devie. An Efficient Incremental Algorithm
    // for Solving Systems of Linear Diophantine Equations. Information and
    // computation, 113(1):143-172, August 1994.

    DenseMatrix A = DenseMatrix(2, 4, {integer(-1), integer(1), integer(2),
                                       integer(-3), integer(-1), integer(3),
                                       integer(-2), integer(-1)});
    homogeneous_lde(basis, A);
    true_basis = std::vector<DenseMatrix>{
        DenseMatrix(1, 4, {integer(0), integer(1), integer(1), integer(1)}),
        DenseMatrix(1, 4, {integer(4), integer(2), integer(1), integer(0)})};

    REQUIRE(vec_dense_matrix_eq_perm(basis, true_basis));

    basis.clear();
    A = DenseMatrix(1, 4, {integer(-1), integer(1), integer(2), integer(-3)});
    homogeneous_lde(basis, A);
    true_basis = std::vector<DenseMatrix>{
        DenseMatrix(1, 4, {integer(0), integer(0), integer(3), integer(2)}),
        DenseMatrix(1, 4, {integer(0), integer(1), integer(1), integer(1)}),
Exemplo n.º 25
0
using SymEngine::RealDouble;
using SymEngine::E;
using SymEngine::parse;
using SymEngine::max;
using SymEngine::min;
using SymEngine::loggamma;
using SymEngine::gamma;

TEST_CASE("Parsing: integers, basic operations", "[parser]")
{
    std::string s;
    RCP<const Basic> res;

    s = "-3-5";
    res = parse(s);
    REQUIRE(eq(*res, *integer(-8)));

    s = "((3)+(1*0))";
    res = parse(s);
    REQUIRE(eq(*res, *integer(3)));

    s = "((2))*(1+(2*3))";
    res = parse(s);
    REQUIRE(eq(*res, *integer(14)));

    s = "(1+1)*((1+1)+(1+1))";
    res = parse(s);
    REQUIRE(eq(*res, *integer(8)));

    s = "(1*3)*(2+4)*(2)";
    res = parse(s);
Exemplo n.º 26
0
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}});
    RCP<const MExprPoly> pprime = MExprPoly::from_dict(
        {y, x},
        {{{1, 1}, a}, {{1, 2}, negB}, {{2, 1}, num1}, {{0, 1}, negNum}});
    RCP<const MExprPoly> p2 = MExprPoly::from_dict(
Exemplo n.º 27
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");
}
Exemplo n.º 28
0
#include "catch.hpp"

#include <symengine/rational.h>

using SymEngine::print_stack_on_segfault;
using SymEngine::RCP;
using SymEngine::Integer;
using SymEngine::integer;
using SymEngine::Rational;
using SymEngine::rational;
using SymEngine::Number;
using SymEngine::is_a;

TEST_CASE("Rational", "[rational]")
{
    RCP<const Integer> i2 = integer(2);
    RCP<const Integer> i5 = integer(5);
    RCP<const Integer> i10 = integer(10);
    RCP<const Integer> i25 = integer(25);

    RCP<const Number> q10_25 = Rational::from_two_ints(*i10, *i25);
    RCP<const Number> q2_5 = Rational::from_two_ints(*i2, *i5);
    RCP<const Number> q = rational(2, 5);

    REQUIRE(q10_25->__eq__(*q2_5));
    REQUIRE(q10_25->__eq__(*q));

    RCP<const Number> r1 = rational(2, 1);
    CHECK(is_a<Integer>(*r1));
    CHECK(r1->__eq__(*integer(2)));
Exemplo n.º 29
0
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));
}

TEST_CASE("Add: subs", "[subs]")
{
    RCP<const Basic> x = symbol("x");
    RCP<const Basic> y = symbol("y");
Exemplo n.º 30
0
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]")
{
    Expression e0 = symbol("x");
    std::stringstream s;
    s << e0;
    REQUIRE(s.str() == "x");