本文整理汇总了C++中ginac::ex::coeff方法的典型用法代码示例。如果您正苦于以下问题:C++ ex::coeff方法的具体用法?C++ ex::coeff怎么用?C++ ex::coeff使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ginac::ex
的用法示例。
在下文中一共展示了ex::coeff方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetCoeffs
// GetCoeffs
vector<GiNaC::ex> GetCoeffs(GiNaC::ex Ex, GiNaC::symbol Sym) {
assert(Ex.is_polynomial(Sym));
vector<GiNaC::ex> Coeffs;
unsigned Degree = Ex.degree(Sym);
for (unsigned Idx = 0; Idx <= Degree; ++Idx)
Coeffs.push_back(Ex.coeff(Sym, Idx));
return Coeffs;
}
示例2: runOnModule
bool TestExpr::runOnModule(Module&) {
Expr A("a");
Expr B("b");
assert(A + B == B + A);
assert(A * B == B * A);
assert(A - B != B - A);
assert(A / B != B / A);
//map<GiNaC::symbol, int> GetMaxExps(GiNaC::ex Ex);
GiNaC::symbol GA("a");
GiNaC::symbol GB("b");
GiNaC::ex EZ = 5 * GA * GA * GA + 4 * GB + 1;
assert(EZ.is_polynomial(GA));
assert(EZ.degree(GA) == 3);
assert(EZ.coeff(GA, 3) == GiNaC::numeric(5));
assert(EZ.coeff(GA, 2) == GiNaC::numeric(0));
assert(EZ.coeff(GA, 1) == GiNaC::numeric(0));
assert(EZ.coeff(GA, 0) == 4 * GB + 1);
assert(EZ.is_polynomial(GB));
assert(EZ.degree(GB) == 1);
assert(EZ.coeff(GB, 1) == GiNaC::numeric(4));
assert(EZ.coeff(GB, 0) == 5 * GA * GA * GA + 1);
auto SEZ = GetSymbols(EZ);
assert(SEZ.size() == 2);
assert(SEZ.count(GA) && SEZ.count(GB));
auto CEZGA = GetCoeffs(EZ, GA);
assert(CEZGA.size() == 4);
assert(CEZGA[3] == GiNaC::numeric(5));
assert(CEZGA[2] == GiNaC::numeric(0));
assert(CEZGA[1] == GiNaC::numeric(0));
assert(CEZGA[0] == 4 * GB + 1);
auto CEZGB = GetCoeffs(EZ, GB);
assert(CEZGB.size() == 2);
assert(CEZGB[1] == GiNaC::numeric(4));
assert(CEZGB[0] == 5 * GA * GA * GA + 1);
auto EF = GA * GA - 1;
auto EFSolve = Solve(EF, GA);
assert(EFSolve.size() == 2);
assert(Round(EFSolve[0]) == -1 || Round(EFSolve[1]) == -1);
assert(Round(EFSolve[0]) == 1 || Round(EFSolve[1]) == 1);
auto EFNegs = NegativeOrdinate(EFSolve, GA, EF);
assert(EFNegs.empty());
EF = GA * GA - 2 * GA + 1;
EFSolve = Solve(EF, GA);
assert(EFSolve.size() == 2);
assert(Round(EFSolve[0]) == 1 && Round(EFSolve[1]) == 1);
EFNegs = NegativeOrdinate(EFSolve, GA, EF);
assert(EFNegs.empty());
EF = (-1) * GA * GA + GA - 1;
EFSolve = Solve(EF, GA);
assert(EFSolve.size() == 0);
EFNegs = NegativeOrdinate(EFSolve, GA, EF);
assert(EFNegs.size() == 1);
assert(EFNegs[0].first.is_equal(GiNaC::inf(-1)));
assert(EFNegs[0].second.is_equal(GiNaC::inf(1)));
return false;
}