5 May
2023
5 May
'23
9:02 p.m.
Hi! On 5/5/23 09:32, Vladimir V. Kisil wrote:
More automated C++ code to get factors (note the scalar as well) is:
#include <fstream> #include <ginac/ginac.h>
using namespace GiNaC; using namespace std;
int main () {
symbol x("x"); ex rat = 2*(pow(x,6)+1); ex fac = factor(rat); for (int i =0; i < fac.nops(); ++i) cout << fac.op(i) << endl;
return 0; }
The output is: -1+x^2-x^4 1+x^2 -2
In C++, you could also just leverage the iterators and... for (auto f : fac) { cout << f << endl; } Best wishes, -richy. -- Richard B. Kreckel <https://in.terlu.de/~kreckel/>