[GiNaC-devel] [PATCH] Apparently mul ctors do index renaming too. Fix them also.

Alexei Sheplyakov varg at theor.jinr.ru
Mon Sep 17 15:50:22 CEST 2007


Do not bother to rename indices if object has no indices at all.
---
 ginac/expairseq.cpp |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp
index 79c741a..788f783 100644
--- a/ginac/expairseq.cpp
+++ b/ginac/expairseq.cpp
@@ -812,8 +812,8 @@ void expairseq::construct_from_2_ex(const ex &lh, const ex &rh)
 				construct_from_2_ex_via_exvector(lh,rh);
 			} else {
 #endif // EXPAIRSEQ_USE_HASHTAB
-				if(is_a<mul>(lh))
-				{
+				if (is_a<mul>(lh) && lh.info(info_flags::has_indices) && 
+					rh.info(info_flags::has_indices)) {
 					ex newrh=rename_dummy_indices_uniquely(lh, rh);
 					construct_from_2_expairseq(ex_to<expairseq>(lh),
 					                           ex_to<expairseq>(newrh));
@@ -1057,6 +1057,7 @@ void expairseq::make_flat(const exvector &v)
 	// and their cumulative number of operands
 	int nexpairseqs = 0;
 	int noperands = 0;
+	bool do_idx_rename = false;
 	
 	cit = v.begin();
 	while (cit!=v.end()) {
@@ -1064,6 +1065,9 @@ void expairseq::make_flat(const exvector &v)
 			++nexpairseqs;
 			noperands += ex_to<expairseq>(*cit).seq.size();
 		}
+		if (is_a<mul>(*this) && (!do_idx_rename) &&
+				cit->info(info_flags::has_indices))
+			do_idx_rename = true;
 		++cit;
 	}
 	
@@ -1071,7 +1075,7 @@ void expairseq::make_flat(const exvector &v)
 	seq.reserve(v.size()+noperands-nexpairseqs);
 	
 	// copy elements and split off numerical part
-	make_flat_inserter mf(v, this->tinfo() == &mul::tinfo_static);
+	make_flat_inserter mf(v, do_idx_rename);
 	cit = v.begin();
 	while (cit!=v.end()) {
 		if (ex_to<basic>(*cit).tinfo()==this->tinfo()) {
@@ -1105,6 +1109,7 @@ void expairseq::make_flat(const epvector &v, bool do_index_renaming)
 	// and their cumulative number of operands
 	int nexpairseqs = 0;
 	int noperands = 0;
+	bool really_need_rename_inds = false;
 	
 	cit = v.begin();
 	while (cit!=v.end()) {
@@ -1112,8 +1117,12 @@ void expairseq::make_flat(const epvector &v, bool do_index_renaming)
 			++nexpairseqs;
 			noperands += ex_to<expairseq>(cit->rest).seq.size();
 		}
+		if ((!really_need_rename_inds) && is_a<mul>(*this) &&
+				cit->rest.info(info_flags::has_indices))
+			really_need_rename_inds = true;
 		++cit;
 	}
+	do_index_renaming = do_index_renaming && really_need_rename_inds;
 	
 	// reserve seq and coeffseq which will hold all operands
 	seq.reserve(v.size()+noperands-nexpairseqs);
-- 
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/081d561b/attachment-0001.pgp


More information about the GiNaC-devel mailing list