[GiNaC-devel] [PATCH 2/5, GiNaC 1.3] Tell mul::expand() to not rename indices if the product has no indices at all.

Alexei Sheplyakov varg at theor.jinr.ru
Mon Sep 17 17:03:00 CEST 2007


---
 ginac/mul.cpp |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/ginac/mul.cpp b/ginac/mul.cpp
index 3c87d5a..5176218 100644
--- a/ginac/mul.cpp
+++ b/ginac/mul.cpp
@@ -940,6 +940,7 @@ bool mul::can_be_further_expanded(const ex & e)
 
 ex mul::expand(unsigned options) const
 {
+	const bool skip_idx_rename = ! info(info_flags::has_indices);
 	// First, expand the children
 	std::auto_ptr<epvector> expanded_seqp = expandchildren(options);
 	const epvector & expanded_seq = (expanded_seqp.get() ? *expanded_seqp : seq);
@@ -1003,7 +1004,7 @@ ex mul::expand(unsigned options) const
 					for (epvector::const_iterator i2=add2begin; i2!=add2end; ++i2) {
 						// Don't push_back expairs which might have a rest that evaluates to a numeric,
 						// since that would violate an invariant of expairseq:
-						const ex rest = (new mul(i1->rest, rename_dummy_indices_uniquely(i1->rest, i2->rest)))->setflag(status_flags::dynallocated);
+						const ex rest = (new mul(i1->rest, skip_idx_rename ? i2->rest : rename_dummy_indices_uniquely(i1->rest, i2->rest)))->setflag(status_flags::dynallocated);
 						if (is_exactly_a<numeric>(rest)) {
 							oc += ex_to<numeric>(rest).mul(ex_to<numeric>(i1->coeff).mul(ex_to<numeric>(i2->coeff)));
 						} else {
@@ -1034,7 +1035,10 @@ ex mul::expand(unsigned options) const
 
 		for (size_t i=0; i<n; ++i) {
 			epvector factors = non_adds;
-			factors.push_back(split_ex_to_pair(rename_dummy_indices_uniquely(mul(non_adds), last_expanded.op(i))));
+			if (skip_idx_rename)
+				factors.push_back(split_ex_to_pair(last_expanded.op(i)));
+			else
+				factors.push_back(split_ex_to_pair(rename_dummy_indices_uniquely(mul(non_adds), last_expanded.op(i))));
 			ex term = (new mul(factors, overall_coeff))->setflag(status_flags::dynallocated);
 			if (can_be_further_expanded(term)) {
 				distrseq.push_back(term.expand());
-- 
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/72deb61d/attachment.pgp


More information about the GiNaC-devel mailing list