]> www.ginac.de Git - ginac.git/blobdiff - ginac/factor.cpp
[BUGFIX] factor_multivariate(): respect unit...
[ginac.git] / ginac / factor.cpp
index cfb9e29d9000b81410b4dba4858cdd62325ba1ac..bb20589b4b9cf890945107cbf7143b497aa4e920 100644 (file)
@@ -33,7 +33,7 @@
  */
 
 /*
- *  GiNaC Copyright (C) 1999-2017 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2020 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -1953,7 +1953,7 @@ static vector<ex> multivar_diophant(const vector<ex>& a_, const ex& x, const ex&
                                delta_s[j] = delta_s[j] * modcm;
                                sigma[j] = sigma[j] + umodpoly_to_ex(delta_s[j], x);
                        }
-                       if ( nterms > 1 ) {
+                       if ( nterms > 1 && i+1 != nterms ) {
                                z = c.op(i+1);
                        }
                }
@@ -2229,14 +2229,13 @@ static ex factor_sqrfree(const ex& poly);
  */
 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) ) {
-               return factor_sqrfree(cont) * factor_sqrfree(pp);
+               return unit * factor_sqrfree(cont) * factor_sqrfree(pp);
        }
 
        // 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);
-                               s = syms.begin();
+                               auto s = syms.begin();
                                ++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;
-               s = syms.begin();
+               auto s = syms.begin();
                ++s;
                for ( size_t i=0; i<a.size(); ++i ) {
                        ep.x = *s++;