[BUGFIX] factor_multivariate(): respect unit...
authorRichard Kreckel <kreckel@ginac.de>
Wed, 29 Jul 2020 22:20:22 +0000 (00:20 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Thu, 30 Jul 2020 07:07:28 +0000 (09:07 +0200)
...if the content of polynomial isn't a number and needs to be factored.
And while at it, reduce the scope of a local variable.

ginac/factor.cpp

index 2878a2c13eb593cc57123d08f7452cdafae23312..bb20589b4b9cf890945107cbf7143b497aa4e920 100644 (file)
@@ -2229,14 +2229,13 @@ static ex factor_sqrfree(const ex& poly);
  */
 static ex factor_multivariate(const ex& poly, const exset& syms)
 {
  */
 static ex factor_multivariate(const ex& poly, const exset& syms)
 {
-       exset::const_iterator s;
        const ex& x = *syms.begin();
 
        // make polynomial primitive
        ex unit, cont, pp;
        poly.unitcontprim(x, unit, cont, pp);
        if ( !is_a<numeric>(cont) ) {
        const ex& x = *syms.begin();
 
        // make polynomial primitive
        ex unit, cont, pp;
        poly.unitcontprim(x, unit, cont, pp);
        if ( !is_a<numeric>(cont) ) {
-               return factor_sqrfree(cont) * factor_sqrfree(pp);
+               return unit * factor_sqrfree(cont) * factor_sqrfree(pp);
        }
 
        // factor leading coefficient
        }
 
        // factor leading coefficient
@@ -2309,7 +2308,7 @@ static ex factor_multivariate(const ex& poly, const exset& syms)
                        vector<numeric> ftilde(vnlst.nops()-1);
                        for ( size_t i=0; i<ftilde.size(); ++i ) {
                                ex ft = vnlst.op(i+1);
                        vector<numeric> ftilde(vnlst.nops()-1);
                        for ( size_t i=0; i<ftilde.size(); ++i ) {
                                ex ft = vnlst.op(i+1);
-                               s = syms.begin();
+                               auto s = syms.begin();
                                ++s;
                                for ( size_t j=0; j<a.size(); ++j ) {
                                        ft = ft.subs(*s == a[j]);
                                ++s;
                                for ( size_t j=0; j<a.size(); ++j ) {
                                        ft = ft.subs(*s == a[j]);
@@ -2383,7 +2382,7 @@ static ex factor_multivariate(const ex& poly, const exset& syms)
                // set up evaluation points
                EvalPoint ep;
                vector<EvalPoint> epv;
                // set up evaluation points
                EvalPoint ep;
                vector<EvalPoint> epv;
-               s = syms.begin();
+               auto s = syms.begin();
                ++s;
                for ( size_t i=0; i<a.size(); ++i ) {
                        ep.x = *s++;
                ++s;
                for ( size_t i=0; i<a.size(); ++i ) {
                        ep.x = *s++;