* Factorization test suite. */
/*
- * GiNaC Copyright (C) 1999-2019 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2023 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
#include <iostream>
using namespace std;
-static symbol w("w"), x("x"), y("y"), z("z");
-
static unsigned check_factor(const ex& e)
{
ex ee = e.expand();
unsigned result = 0;
ex e;
symbol x("x");
- lst syms;
- syms.append(x);
-
+ lst syms = {x};
+
+ e = 1;
+ result += check_factor(e);
+
e = ex("1+x-x^3", syms);
result += check_factor(e);
return 0;
}
+static unsigned exam_factor_content()
+{
+ unsigned result = 0;
+ ex e;
+ symbol x("x"), y("y");
+
+ // Fixed 2013-07-28 by Alexei Sheplyakov in factor_univariate().
+ e = ex("174247781*x^2-1989199947807987/200000000000000", lst{x});
+ result += check_factor(e);
+
+ // Fixed 2014-05-18 by Alexei Sheplyakov in factor_multivariate().
+ e = ex("(x+y+x*y)*(3*x+2*y)", lst{x, y});
+ result += check_factor(e);
+
+ return result;
+}
+
static unsigned exam_factor_wang()
{
// these 15 polynomials are from the appendix of P.S.Wang,
// "An Improved Multivariate Polynomial Factoring Algorithm"
unsigned result = 0;
ex e;
- symbol x("x"), y("y"), z("z"), u("u");
+ symbol u("u"), w("w"), x("x"), y("y"), z("z");
e = ex("(z+x*y+10)*(x*z+y+30)*(y*z+x+20)", lst{x, y, z});
result += check_factor_expanded(e);
return result;
}
-static unsigned check_factorization(const exvector& factors)
+static unsigned exam_factor_magerya()
{
- ex e = dynallocate<mul>(factors);
- ex ef = factor(e.expand());
- if (ef.nops() != factors.size()) {
- clog << "wrong number of factors, expected " << factors.size() <<
- ", got " << ef.nops();
- return 1;
- }
- for (size_t i = 0; i < ef.nops(); ++i) {
- if (find(factors.begin(), factors.end(), ef.op(i)) == factors.end()) {
- clog << "wrong factorization: term not found: " << ef.op(i);
- return 1;
- }
- }
- return 0;
-}
+ // In 2017, Vitaly Magerya reported a class of biviariate polynomials
+ // where Hensel lifting sometimes failed to terminate.
+ // https://www.ginac.de/pipermail/ginac-list/2017-December/002162.html
+ unsigned result = 0;
+ ex e;
+ symbol x("x"), y("y");
-static unsigned factor_integer_content_bug()
-{
- parser reader;
- exvector factors;
- factors.push_back(reader("x+y+x*y"));
- factors.push_back(reader("3*x+2*y"));
- return check_factorization(factors);
+ e = (1+2*x+y)*(1+2*x-y)*(2*x-y)*(2*x+y);
+ result += check_factor_expanded(e);
+
+ e = (7+4*x+y)*(-5+2*x-y)*(-6+6*x+y)*y*(10+2*x+y);
+ result += check_factor_expanded(e);
+
+ e = (8+6*x-y)*(-5+4*x-y)*(-5+6*x+y)*(-2+2*x-y)*(2+4*x+y);
+ result += check_factor_expanded(e);
+
+ e = -(-4+4*x+5*y)*(1+4*x+5*y)*(2+3*y)*(1+2*x-y)*(4+2*x+y);
+ result += check_factor_expanded(e);
+
+ e = (-3+y-2*x)*(4+3*y-4*x)*(3+3*y+2*x)*(-2+3*y+2*x)*(-1+4*y+3*x);
+ result += check_factor_expanded(e);
+
+ e = (-9+7*x+y)*(-5+6*x+y)*(4+2*x+y)*(5+2*x-y)*(7+9*x-y)*(8+6*x-y);
+ result += check_factor_expanded(e);
+
+ e = pow(2*x-y,2)*(-1+6*x-y)*(-1+3*x-y)*(-2+4*x-y)*(1+4*x-y)*(4*x-y)*(2+4*x-y);
+ result += check_factor_expanded(e);
+
+ e = (5+2*y-3*x)*(-4+4*y+3*x)*(-3+4*y-2*x)*(4+5*y-x)*(3*y+2*x)*(-1+3*y+5*x)*(5+3*y+4*x);
+ result += check_factor_expanded(e);
+
+ return result;
}
unsigned exam_factor()
result += exam_factor1(); cout << '.' << flush;
result += exam_factor2(); cout << '.' << flush;
result += exam_factor3(); cout << '.' << flush;
+ result += exam_factor_content(); cout << '.' << flush;
result += exam_factor_wang(); cout << '.' << flush;
- result += factor_integer_content_bug();
- cout << '.' << flush;
+ result += exam_factor_magerya(); cout << '.' << flush;
return result;
}