本文整理汇总了C++中SymEngine::add方法的典型用法代码示例。如果您正苦于以下问题:C++ SymEngine::add方法的具体用法?C++ SymEngine::add怎么用?C++ SymEngine::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymEngine
的用法示例。
在下文中一共展示了SymEngine::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: R3
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;
}
示例2: S2
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;
}
示例3: E
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;
}
示例4: S1
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;
}
示例5: S3a
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;
}
示例6: R7
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;
}
示例7: R5
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;
}
示例8: Expression
{{{1, 1}, a}, {{1, 2}, negB}, {{2, 1}, num1}, {{0, 1}, negNum}});
RCP<const MExprPoly> p2 = MExprPoly::from_dict(
{x, y},
{{{1, 0}, comp1}, {{0, 0}, comp2}, {{2, 2}, comp3}, {{3, 4}, comp4}});
RCP<const MExprPoly> p3
= MExprPoly::from_dict({x, y}, {{{0, 0}, Expression(integer(0))}});
RCP<const MExprPoly> p4 = MExprPoly::from_dict(s, {{v, Expression(0)}});
RCP<const MExprPoly> p5 = MExprPoly::from_dict(s, {{v, comp1}});
RCP<const MExprPoly> p6 = MExprPoly::from_dict({x, y}, {{{0, 0}, comp1},
{{0, -1}, comp2},
{{-2, 2}, comp3},
{{-3, -3}, comp4}});
REQUIRE(eq(*p1->as_symbolic(),
*add({mul(integer(2), mul(pow(x, integer(2)), y)),
mul(negB.get_basic(), mul(x, pow(y, integer(2)))),
mul(symbol("a"), mul(x, y)), mul(integer(-3), y)})));
REQUIRE(eq(*pprime->as_symbolic(),
*add({mul(negB.get_basic(), mul(pow(x, integer(2)), y)),
mul(integer(2), mul(x, pow(y, integer(2)))),
mul(symbol("a"), mul(x, y)), mul(integer(-3), x)})));
REQUIRE(eq(*p2->as_symbolic(),
*add({mul(comp4.get_basic(),
mul(pow(x, integer(3)), pow(y, integer(4)))),
mul(comp3.get_basic(),
mul(pow(x, integer(2)), pow(y, integer(2)))),
mul(comp1.get_basic(), x), comp2.get_basic()})));
REQUIRE(eq(*p3->as_symbolic(), *zero));
REQUIRE(eq(*p4->as_symbolic(), *zero));
REQUIRE(eq(*p5->as_symbolic(), *comp1.get_basic()));
REQUIRE(eq(*p6->as_symbolic(),
示例9: symbol
using SymEngine::real_double;
using SymEngine::complex_double;
using SymEngine::rational_class;
using SymEngine::is_a;
using SymEngine::set_basic;
TEST_CASE("Add: arit", "[arit]")
{
RCP<const Basic> x = symbol("x");
RCP<const Basic> y = symbol("y");
RCP<const Basic> z = symbol("z");
RCP<const Basic> i2 = integer(2);
RCP<const Basic> i3 = integer(3);
RCP<const Basic> i4 = integer(4);
RCP<const Basic> r1 = add(x, x);
RCP<const Basic> r2 = mul(i2, x);
RCP<const Basic> r3 = mul(i3, x);
REQUIRE(eq(*r1, *r2));
REQUIRE(neq(*r1, *r3));
r3 = mul(i2, y);
REQUIRE(neq(*r1, *r3));
REQUIRE(neq(*r2, *r3));
r1 = add(mul(y, x), mul(mul(i2, x), y));
r2 = mul(mul(i3, x), y);
REQUIRE(eq(*r1, *r2));
r1 = add({mul(y, x), mul({i2, x, y})});
r2 = mul({i3, x, y});
示例10: mul
r = mul(integer(2), pow(symbol("x"), integer(2)));
REQUIRE(r->__str__() == "2*x**2");
r = mul(integer(23), mul(pow(div(integer(5), integer(2)), div(integer(1), integer(2))),
pow(div(integer(7), integer(3)), div(integer(1), integer(2)))));
REQUIRE(r->__str__() == "23*(7/3)**(1/2)*(5/2)**(1/2)");
r = pow(div(symbol("x"), integer(2)), div(integer(1), integer(2)));
REQUIRE(r->__str__() == "((1/2)*x)**(1/2)");
r = pow(div(integer(3), integer(2)),div(integer(1), integer(2)));
REQUIRE(r->__str__() == "(3/2)**(1/2)");
r1 = mul(integer(12), pow(integer(196), div(integer(-1), integer(2))));
r2 = mul(integer(294), pow(integer(196), div(integer(-1), integer(2))));
r = add(integer(-51), mul(r1, r2));
REQUIRE(r->__str__() == "-33");
r1 = mul(x, i);
r2 = mul(r1, y);
REQUIRE(r1->__str__() == "-x");
REQUIRE(r1->__str__() != "-1x");
REQUIRE(r2->__str__() == "-x*y");
REQUIRE(r2->__str__() != "-1x*y");
r = mul(integer(-1), pow(integer(196), div(integer(1), integer(2))));
REQUIRE(r->__str__() == "-196**(1/2)");
r = pow(integer(-6), div(integer(1), integer(2)));
REQUIRE(r->__str__() == "(-6)**(1/2)");
RCP<const Number> rn1, rn2, rn3, c1, c2;
示例11: symbol
using SymEngine::RealDouble;
using SymEngine::ComplexDouble;
using SymEngine::real_double;
using SymEngine::complex_double;
using SymEngine::is_a;
TEST_CASE("Add: arit", "[arit]")
{
RCP<const Basic> x = symbol("x");
RCP<const Basic> y = symbol("y");
RCP<const Basic> z = symbol("z");
RCP<const Basic> i2 = integer(2);
RCP<const Basic> i3 = integer(3);
RCP<const Basic> i4 = integer(4);
RCP<const Basic> r1 = add(x, x);
RCP<const Basic> r2 = mul(i2, x);
RCP<const Basic> r3 = mul(i3, x);
REQUIRE(eq(*r1, *r2));
REQUIRE(neq(*r1, *r3));
r3 = mul(i2, y);
REQUIRE(neq(*r1, *r3));
REQUIRE(neq(*r2, *r3));
r1 = add(mul(y, x), mul(mul(i2, x), y));
r2 = mul(mul(i3, x), y);
REQUIRE(eq(*r1, *r2));
r1 = add(add(x, x), x);
r2 = mul(i3, x);
示例12: integer
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}};
REQUIRE(unified_eq(gens, rgens));
// x/2 + 1/2 -> (x)
basic = add(xb2, hf);
gens = _find_gens_poly(basic);
rgens = {{x, one}};
REQUIRE(unified_eq(gens, rgens));
示例13: REQUIRE
REQUIRE(r->__str__() == "2*x**2");
r = mul(integer(23),
mul(pow(div(integer(5), integer(2)), div(integer(1), integer(2))),
pow(div(integer(7), integer(3)), div(integer(1), integer(2)))));
REQUIRE(r->__str__() == "(23/6)*sqrt(2)*sqrt(3)*sqrt(5)*sqrt(7)");
r = pow(div(symbol("x"), integer(2)), div(integer(1), integer(2)));
REQUIRE(r->__str__() == "(1/2)*sqrt(2)*sqrt(x)");
r = pow(div(integer(3), integer(2)), div(integer(1), integer(2)));
REQUIRE(r->__str__() == "(1/2)*sqrt(2)*sqrt(3)");
r1 = mul(integer(12), pow(integer(196), div(integer(-1), integer(2))));
r2 = mul(integer(294), pow(integer(196), div(integer(-1), integer(2))));
r = add(integer(-51), mul(r1, r2));
REQUIRE(r->__str__() == "-33");
r1 = mul(x, i);
r2 = mul(r1, y);
REQUIRE(r1->__str__() == "-x");
REQUIRE(r1->__str__() != "-1x");
REQUIRE(r2->__str__() == "-x*y");
REQUIRE(r2->__str__() != "-1x*y");
r = mul(integer(-1), pow(integer(195), div(integer(1), integer(3))));
REQUIRE(r->__str__() == "-195**(1/3)");
r = pow(integer(-6), div(integer(1), integer(2)));
REQUIRE(r->__str__() == "I*sqrt(6)");
RCP<const Number> rn1, rn2, rn3, c1, c2;
示例14: symbol
using SymEngine::LambdaComplexDoubleVisitor;
using SymEngine::max;
using SymEngine::E;
using SymEngine::gamma;
using SymEngine::loggamma;
using SymEngine::min;
TEST_CASE("Evaluate to double", "[lambda_double]")
{
RCP<const Basic> x, y, z, r;
double d;
x = symbol("x");
y = symbol("y");
z = symbol("z");
r = add(x, add(mul(y, z), pow(x, integer(2))));
LambdaRealDoubleVisitor v;
v.init({x, y, z}, *r);
d = v.call({1.5, 2.0, 3.0});
REQUIRE(::fabs(d - 9.75) < 1e-12);
d = v.call({1.5, -1.0, 2.0});
REQUIRE(::fabs(d - 1.75) < 1e-12);
r = max({x, add(mul(y, z), integer(3))});
v.init({x, y, z}, *r);
d = v.call({4.0, 1.0, 2.5});
REQUIRE(::fabs(d - 5.5) < 1e-12);
示例15: symbol
{
auto ser = SymEngine::UPSeriesPiranha::series(ex, x->get_name(), prec);
for (auto it : pairs) {
// std::cerr << it.first << ", " << *(it.second) << "::" <<
// *(v1.at(it.first)) << std::endl;
if (not it.second->__eq__(
*(ser->get_poly().find_cf({it.first}).get_basic())))
return false;
}
return true;
}
TEST_CASE("Expression series expansion: Add ", "[Expansion of Add]")
{
RCP<const Symbol> x = symbol("x"), y = symbol("y");
auto z = add(integer(1), x);
z = sub(z, pow(x, integer(2)));
z = add(z, pow(x, integer(4)));
auto vb = umap_short_basic{
{0, integer(1)}, {1, integer(1)}, {2, integer(-1)}, {4, integer(1)}};
REQUIRE(expand_check_pairs(z, x, 5, vb));
auto vb1
= umap_short_basic{{0, integer(1)}, {1, integer(1)}, {2, integer(-1)}};
REQUIRE(expand_check_pairs(z, x, 3, vb1));
}
TEST_CASE("Expression series expansion: sin, cos", "[Expansion of sin, cos]")
{
RCP<const Symbol> x = symbol("x");
RCP<const Integer> one = integer(1);