manpagez: man pages & more
info ginac
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.7.7 Square-free decomposition

GiNaC still lacks proper factorization support. Some form of factorization is, however, easily implemented by noting that factors appearing in a polynomial with power two or more also appear in the derivative and hence can easily be found by computing the GCD of the original polynomial and its derivatives. Any decent system has an interface for this so called square-free factorization. So we provide one, too:

 
ex sqrfree(const ex & a, const lst & l = lst());

Here is an example that by the way illustrates how the exact form of the result may slightly depend on the order of differentiation, calling for some care with subsequent processing of the result:

 
    ...
    symbol x("x"), y("y");
    ex BiVarPol = expand(pow(2-2*y,3) * pow(1+x*y,2) * pow(x-2*y,2) * (x+y));

    cout << sqrfree(BiVarPol, lst(x,y)) << endl;
     // -> 8*(1-y)^3*(y*x^2-2*y+x*(1-2*y^2))^2*(y+x)

    cout << sqrfree(BiVarPol, lst(y,x)) << endl;
     // -> 8*(1-y)^3*(-y*x^2+2*y+x*(-1+2*y^2))^2*(y+x)

    cout << sqrfree(BiVarPol) << endl;
     // -> depending on luck, any of the above
    ...

Note also, how factors with the same exponents are not fully factorized with this method.


© manpagez.com 2000-2024
Individual documents may contain additional copyright information.