本文整理汇总了C++中SymEngine::mul方法的典型用法代码示例。如果您正苦于以下问题:C++ SymEngine::mul方法的具体用法?C++ SymEngine::mul怎么用?C++ SymEngine::mul使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymEngine
的用法示例。
在下文中一共展示了SymEngine::mul方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: expand
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)))));
}
示例2: 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;
}
示例3: 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;
}
示例4: add
RCP<const Basic> f(RCP<const Basic> z) {
return add(mul(sqrt(div(one, integer(3))), pow(z, integer(2))), div(I, integer(3)));
}
示例5: integer
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");
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)");
示例6: symbol
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);
REQUIRE(eq(*r1, *r2));
示例7: mul
using SymEngine::EulerGamma;
using SymEngine::mul;
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`
示例8: 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);
示例9: outArg
as_real_imag(neg(i2), outArg(re), outArg(im));
REQUIRE(eq(*re, *neg(i2)));
REQUIRE(eq(*im, *zero));
as_real_imag(Inf, outArg(re), outArg(im));
REQUIRE(eq(*re, *Inf));
REQUIRE(eq(*im, *zero));
as_real_imag(ComplexInf, outArg(re), outArg(im));
REQUIRE(eq(*re, *Nan));
REQUIRE(eq(*im, *Nan));
// Symbol
CHECK_THROWS_AS(
as_real_imag(mul(add(i2, I), symbol("x")), outArg(re), outArg(im)),
SymEngineException &);
}
TEST_CASE("RealImag: Mul", "[as_real_imag]")
{
RCP<const Basic> re, im;
auto i2 = integer(2), i3 = integer(3);
as_real_imag(neg(add(i2, I)), outArg(re), outArg(im));
REQUIRE(eq(*re, *neg(i2)));
REQUIRE(eq(*im, *neg(one)));
as_real_imag(mul(i2, pow(I, rational(2, 3))), outArg(re), outArg(im));
REQUIRE(eq(*re, *one));
REQUIRE(eq(*im, *sqrt(i3)));