From 8474043d373a19e04008f476fa9b77e45734b604 Mon Sep 17 00:00:00 2001 From: Alexei Sheplyakov Date: Mon, 25 Aug 2008 16:52:45 +0400 Subject: [PATCH] gcd: allow user to override (some of) heuristics. 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 1: * add new (optional) argument to gcd() to control its behaviour. * introduce gcd_options structure. N.B. No actual code changes so far, the actual handling of newly introduced options is the subject of further patches. --- ginac/normal.cpp | 2 +- ginac/normal.h | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ginac/normal.cpp b/ginac/normal.cpp index e756a677..9ec7574a 100644 --- a/ginac/normal.cpp +++ b/ginac/normal.cpp @@ -1426,7 +1426,7 @@ static bool heur_gcd(ex& res, const ex& a, const ex& b, ex *ca, ex *cb, * @param check_args check whether a and b are polynomials with rational * coefficients (defaults to "true") * @return the GCD as a new expression */ -ex gcd(const ex &a, const ex &b, ex *ca, ex *cb, bool check_args) +ex gcd(const ex &a, const ex &b, ex *ca, ex *cb, bool check_args, unsigned options) { #if STATISTICS gcd_called++; diff --git a/ginac/normal.h b/ginac/normal.h index 5f444278..5a735e34 100644 --- a/ginac/normal.h +++ b/ginac/normal.h @@ -30,6 +30,28 @@ namespace GiNaC { +/** + * Flags to control the behaviour of gcd() and friends + */ +struct gcd_options +{ + enum { + /** + * Usually GiNaC tries heuristic GCD algorithm before PRS. + * Some people don't like this, so here's a flag to disable it. + */ + no_heur_gcd = 2, + /** + * GiNaC tries to avoid expanding expressions when computing + * GCDs. This is a good idea, but some people dislike it. + * Hence the flag to disable special handling of partially + * factored polynomials. DON'T SET THIS unless you *really* + * know what are you doing! + */ + no_part_factored = 4 + }; +}; + class ex; class symbol; @@ -52,7 +74,8 @@ extern ex sprem(const ex &a, const ex &b, const ex &x, bool check_args = true); extern bool divide(const ex &a, const ex &b, ex &q, bool check_args = true); // Polynomial GCD in Z[X], cofactors are returned in ca and cb, if desired -extern ex gcd(const ex &a, const ex &b, ex *ca = NULL, ex *cb = NULL, bool check_args = true); +extern ex gcd(const ex &a, const ex &b, ex *ca = NULL, ex *cb = NULL, + bool check_args = true, unsigned options = 0); // Polynomial LCM in Z[X] extern ex lcm(const ex &a, const ex &b, bool check_args = true); -- 2.49.0