本文整理汇总了C++中SymEngine::integer方法的典型用法代码示例。如果您正苦于以下问题:C++ SymEngine::integer方法的具体用法?C++ SymEngine::integer怎么用?C++ SymEngine::integer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymEngine
的用法示例。
在下文中一共展示了SymEngine::integer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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)))));
}
示例3: 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;
}
示例4: 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);
}
示例5: 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;
}
示例6: main
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;
}
示例7: C
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;
}
示例8: 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()
<< "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;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: test_expand
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;
}
示例14: 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;
}
示例15: 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;
}