[GiNaC-list] Polynomial Factoring
Richard B. Kreckel
kreckel at in.terlu.de
Fri May 5 21:02:41 CEST 2023
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/>
More information about the GiNaC-list
mailing list