本文整理汇总了C++中SymEngine::symbol方法的典型用法代码示例。如果您正苦于以下问题:C++ SymEngine::symbol方法的具体用法?C++ SymEngine::symbol怎么用?C++ SymEngine::symbol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymEngine
的用法示例。
在下文中一共展示了SymEngine::symbol方法的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: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: main
int main(int argc, char* argv[])
{
Teuchos::print_stack_on_segfault();
int N;
if (argc == 2) {
N = std::atoi(argv[1]);
} else {
N = 100;
}
auto t1 = std::chrono::high_resolution_clock::now();
RCP<const Basic> e, f, s, a0, a1;
a0 = symbol("a0");
a1 = symbol("a1");
e = add(a0, a1);
f = zero;
for (int i = 2; i < N; i++) {
s = symbol("a" + std::to_string(i));
e = add(e, s);
f = sub(f, s);
}
e = expand(mul(e, e));
map_basic_basic dict;
insert(dict, a0, f);
e = e->subs(dict);
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;
}