[GiNaC-devel] [PATCH 01/10] gcd: allow user to override (some of) heuristics.

Alexei Sheplyakov varg at theor.jinr.ru
Mon Aug 25 14:52:45 CEST 2008


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 e756a67..9ec7574 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 5f44427..5a735e3 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);
-- 
1.5.6

Best regards,
	Alexei

-- 
All science is either physics or stamp collecting.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-devel/attachments/20080825/a110660d/attachment.sig 


More information about the GiNaC-devel mailing list