本文整理汇总了C++中SymEngine类的典型用法代码示例。如果您正苦于以下问题:C++ SymEngine类的具体用法?C++ SymEngine怎么用?C++ SymEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SymEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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;
}
示例2: main
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()
/ 500.
<< "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;
}
示例3: main
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;
}
示例4: main
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;
}
示例5: real_mpfr_set_d
CWRAPPER_OUTPUT_TYPE real_mpfr_set_d(basic s, double d, int prec)
{
CWRAPPER_BEGIN
mpfr_class mc = mpfr_class(prec);
mpfr_set_d(mc.get_mpfr_t(), d, MPFR_RNDN);
s->m = SymEngine::real_mpfr(std::move(mc));
CWRAPPER_END
}
示例6: main
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;
}
示例7: R8
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;
}
示例8: R1
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;
}
示例9: R2
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;
}
示例10: A
double A()
{
auto t1 = std::chrono::high_resolution_clock::now();
for (int i = 1; i <= 100; i++) {
div(factorial(1000 + i), factorial(900 + i));
}
auto t2 = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
示例11: B
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;
}
示例12: mulnum
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);
}
示例13: 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;
}
示例14: function_symbol_set
CWRAPPER_OUTPUT_TYPE function_symbol_set(basic s, const char *c,
const CVecBasic *arg)
{
CWRAPPER_BEGIN
s->m = function_symbol(c, arg->m);
CWRAPPER_END
}
示例15: rational_get_mpq
CWRAPPER_OUTPUT_TYPE rational_get_mpq(mpq_t a, const basic s)
{
CWRAPPER_BEGIN
SYMENGINE_ASSERT(is_a<Rational>(*(s->m)));
mpq_set(a, get_mpq_t((rcp_static_cast<const Rational>(s->m))
->as_rational_class()));
CWRAPPER_END
}