[GiNaC-devel] [PATCH 1/5, GiNaC 1.3] Improve info(info_flags::has_indices), introduce flags to cache the result.

Alexei Sheplyakov varg at theor.jinr.ru
Mon Sep 17 17:02:29 CEST 2007


This is the similar set of patches for GiNaC 1.3

---
 ginac/expairseq.cpp |   23 +++++++++++++++++++++--
 ginac/flags.h       |    4 +++-
 ginac/idx.cpp       |    7 +++++--
 ginac/power.cpp     |   15 +++++++++++++++
 ginac/symbol.cpp    |   30 ++++++++++++++++--------------
 5 files changed, 60 insertions(+), 19 deletions(-)

diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp
index be8790f..97cf961 100644
--- a/ginac/expairseq.cpp
+++ b/ginac/expairseq.cpp
@@ -24,6 +24,7 @@
 #include <algorithm>
 #include <string>
 #include <stdexcept>
+#include <iterator>
 
 #include "expairseq.h"
 #include "lst.h"
@@ -261,8 +262,26 @@ void expairseq::do_print_tree(const print_tree & c, unsigned level) const
 
 bool expairseq::info(unsigned inf) const
 {
-	if (inf == info_flags::expanded)
-		return (flags & status_flags::expanded);
+	switch(inf) {
+		case info_flags::expanded:
+			return (flags & status_flags::expanded);
+		case info_flags::has_indices: {
+			if (flags & status_flags::has_indices)
+				return true;
+			else if (flags & status_flags::has_no_indices)
+				return false;
+			for (epvector::const_iterator i = seq.begin(); i != seq.end(); ++i) {
+				if (i->rest.info(info_flags::has_indices)) {
+					this->setflag(status_flags::has_indices);
+					this->clearflag(status_flags::has_no_indices);
+					return true;
+				}
+			}
+			this->clearflag(status_flags::has_indices);
+			this->setflag(status_flags::has_no_indices);
+			return false;
+		}
+	}
 	return inherited::info(inf);
 }
 
diff --git a/ginac/flags.h b/ginac/flags.h
index a42f869..33622f9 100644
--- a/ginac/flags.h
+++ b/ginac/flags.h
@@ -179,7 +179,9 @@ public:
 		evaluated       = 0x0002, ///< .eval() has already done its job
 		expanded        = 0x0004, ///< .expand(0) has already done its job (other expand() options ignore this flag)
 		hash_calculated = 0x0008, ///< .calchash() has already done its job
-		not_shareable   = 0x0010  ///< don't share instances of this object between different expressions unless explicitly asked to (used by ex::compare())
+		not_shareable   = 0x0010, ///< don't share instances of this object between different expressions unless explicitly asked to (used by ex::compare())
+		has_indices	= 0x0020,
+		has_no_indices	= 0x0040  // ! (has_indices || has_no_indices) means "don't know"
 	};
 };
 
diff --git a/ginac/idx.cpp b/ginac/idx.cpp
index 3d363e0..601a77c 100644
--- a/ginac/idx.cpp
+++ b/ginac/idx.cpp
@@ -232,8 +232,11 @@ void spinidx::do_print_tree(const print_tree & c, unsigned level) const
 
 bool idx::info(unsigned inf) const
 {
-	if (inf == info_flags::idx)
-		return true;
+	switch(inf) {
+		case info_flags::idx:
+		case info_flags::has_indices:
+			return true;
+	}
 	return inherited::info(inf);
 }
 
diff --git a/ginac/power.cpp b/ginac/power.cpp
index f243147..676b862 100644
--- a/ginac/power.cpp
+++ b/ginac/power.cpp
@@ -240,6 +240,21 @@ bool power::info(unsigned inf) const
 			       basis.info(inf);
 		case info_flags::expanded:
 			return (flags & status_flags::expanded);
+		case info_flags::has_indices: {
+			if (flags & status_flags::has_indices)
+				return true;
+			else if (flags & status_flags::has_no_indices)
+				return false;
+			else if (basis.info(info_flags::has_indices)) {
+				setflag(status_flags::has_indices);
+				clearflag(status_flags::has_no_indices);
+				return true;
+			} else {
+				clearflag(status_flags::has_indices);
+				setflag(status_flags::has_no_indices);
+				return false;
+			}
+		}
 	}
 	return inherited::info(inf);
 }
diff --git a/ginac/symbol.cpp b/ginac/symbol.cpp
index 2edd714..0e51f0e 100644
--- a/ginac/symbol.cpp
+++ b/ginac/symbol.cpp
@@ -190,20 +190,22 @@ void symbol::do_print_python_repr(const print_python_repr & c, unsigned level) c
 
 bool symbol::info(unsigned inf) const
 {
-	if (inf == info_flags::symbol)
-		return true;
-	if (inf == info_flags::polynomial ||
-	    inf == info_flags::integer_polynomial ||
-	    inf == info_flags::cinteger_polynomial ||
-	    inf == info_flags::rational_polynomial ||
-	    inf == info_flags::crational_polynomial ||
-	    inf == info_flags::rational_function ||
-			inf == info_flags::expanded)
-		return true;
-	if (inf == info_flags::real)
-		return domain == domain::real;
-	else
-		return inherited::info(inf);
+	switch (inf) {
+		case info_flags::symbol:
+		case info_flags::polynomial:
+		case info_flags::integer_polynomial: 
+		case info_flags::cinteger_polynomial: 
+		case info_flags::rational_polynomial: 
+		case info_flags::crational_polynomial: 
+		case info_flags::rational_function: 
+		case info_flags::expanded:
+			return true;
+		case info_flags::has_indices:
+			return false;
+		case info_flags::real:
+			return domain == domain::real;
+	}
+	return inherited::info(inf);
 }
 
 ex symbol::eval(int level) const
-- 
1.5.2.4

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/20070917/0baa33ca/attachment.pgp


More information about the GiNaC-devel mailing list