[GiNaC-devel] [PATCH 4/5, GiNaC 1.3] {mul, power}::expand: expand monomials faster.

Alexei Sheplyakov varg at theor.jinr.ru
Mon Sep 17 17:04:01 CEST 2007


---
 ginac/mul.cpp   |   12 ++++++++++++
 ginac/power.cpp |    3 +++
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/ginac/mul.cpp b/ginac/mul.cpp
index 5176218..d6ff7cb 100644
--- a/ginac/mul.cpp
+++ b/ginac/mul.cpp
@@ -34,6 +34,7 @@
 #include "lst.h"
 #include "archive.h"
 #include "utils.h"
+#include "symbol.h"
 #include "compiler.h"
 
 namespace GiNaC {
@@ -940,7 +941,18 @@ bool mul::can_be_further_expanded(const ex & e)
 
 ex mul::expand(unsigned options) const
 {
+	{
+  	// trivial case: expanding the monomial (~ 30% of all calls)
+		epvector::const_iterator i = seq.begin(), seq_end = seq.end();
+		while ((i != seq.end()) &&  is_a<symbol>(i->rest) && i->coeff.info(info_flags::integer))
+			++i;
+		if (i == seq_end)
+			return (new mul(*this))->setflag(status_flags::dynallocated | status_flags::expanded);
+	}
+
 	const bool skip_idx_rename = ! info(info_flags::has_indices);
+	if (skip_idx_rename)
+		++(mul_expand_stats::n_indexless);
 	// First, expand the children
 	std::auto_ptr<epvector> expanded_seqp = expandchildren(options);
 	const epvector & expanded_seq = (expanded_seqp.get() ? *expanded_seqp : seq);
diff --git a/ginac/power.cpp b/ginac/power.cpp
index bbcb453..010af6c 100644
--- a/ginac/power.cpp
+++ b/ginac/power.cpp
@@ -680,6 +680,9 @@ unsigned power::return_type_tinfo() const
 
 ex power::expand(unsigned options) const
 {
+	if (is_a<symbol>(basis) && exponent.info(info_flags::integer))
+		return (new power(*this))->setflag(status_flags::dynallocated | status_flags::expanded);
+
 	if (options == 0 && (flags & status_flags::expanded))
 		return *this;
 	
-- 
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/2d3eda5a/attachment.pgp


More information about the GiNaC-devel mailing list