GiNaC tries to avoid expanding expressions while computing GCDs and applies
a number of heuristics. Usually this improves performance, but in some cases
it doesn't. Allow user to switch off heuristics.
Part 4:
refactor gcd() a little bit, so subsequent patch(es) won't be so big and ugly.
// Try heuristic algorithm first, fall back to PRS if that failed
ex g;
bool found = heur_gcd(g, aex, bex, ca, cb, var);
// Try heuristic algorithm first, fall back to PRS if that failed
ex g;
bool found = heur_gcd(g, aex, bex, ca, cb, var);
- if (!found) {
-#if STATISTICS
- heur_gcd_failed++;
-#endif
- g = sr_gcd(aex, bex, var);
- if (g.is_equal(_ex1)) {
- // Keep cofactors factored if possible
- if (ca)
- *ca = a;
- if (cb)
- *cb = b;
- } else {
- if (ca)
- divide(aex, g, *ca, false);
- if (cb)
- divide(bex, g, *cb, false);
- }
- } else {
+ if (found) {
+ // heur_gcd have already computed cofactors...
- // Keep cofactors factored if possible
+ // ... but we want to keep them factored if possible.
if (ca)
*ca = a;
if (cb)
*cb = b;
}
if (ca)
*ca = a;
if (cb)
*cb = b;
}
+#if STATISTICS
+ else {
+ heur_gcd_failed++;
+ }
+#endif
+ g = sr_gcd(aex, bex, var);
+ if (g.is_equal(_ex1)) {
+ // Keep cofactors factored if possible
+ if (ca)
+ *ca = a;
+ if (cb)
+ *cb = b;
+ } else {
+ if (ca)
+ divide(aex, g, *ca, false);
+ if (cb)
+ divide(bex, g, *cb, false);
+ }