Index: ginac/expairseq.cpp
===================================================================
RCS file: /home/cvs/GiNaC/ginac/expairseq.cpp,v
retrieving revision 1.77
diff -c -r1.77 expairseq.cpp
*** ginac/expairseq.cpp	1 May 2005 18:23:26 -0000	1.77
--- ginac/expairseq.cpp	3 Oct 2005 21:30:41 -0000
***************
*** 34,39 ****
--- 34,40 ----
  #include "archive.h"
  #include "operators.h"
  #include "utils.h"
+ #include "indexed.h"
  
  #if EXPAIRSEQ_USE_HASHTAB
  #include <cmath>
***************
*** 757,764 ****
  				construct_from_2_ex_via_exvector(lh,rh);
  			} else {
  #endif // EXPAIRSEQ_USE_HASHTAB
! 				construct_from_2_expairseq(ex_to<expairseq>(lh),
! 				                           ex_to<expairseq>(rh));
  #if EXPAIRSEQ_USE_HASHTAB
  			}
  #endif // EXPAIRSEQ_USE_HASHTAB
--- 758,772 ----
  				construct_from_2_ex_via_exvector(lh,rh);
  			} else {
  #endif // EXPAIRSEQ_USE_HASHTAB
! 				if(is_a<mul>(lh))
! 				{	
! 					ex newrh=rename_dummy_indices_uniquely(lh, rh);
! 					construct_from_2_expairseq(ex_to<expairseq>(lh),
! 					                           ex_to<expairseq>(newrh));
! 				}
! 				else
! 					construct_from_2_expairseq(ex_to<expairseq>(lh),
! 					                           ex_to<expairseq>(rh));
  #if EXPAIRSEQ_USE_HASHTAB
  			}
  #endif // EXPAIRSEQ_USE_HASHTAB
***************
*** 1008,1020 ****
  	seq.reserve(v.size()+noperands-nexpairseqs);
  	
  	// copy elements and split off numerical part
  	cit = v.begin();
  	while (cit!=v.end()) {
  		if (ex_to<basic>(*cit).tinfo()==this->tinfo()) {
! 			const expairseq &subseqref = ex_to<expairseq>(*cit);
! 			combine_overall_coeff(subseqref.overall_coeff);
! 			epvector::const_iterator cit_s = subseqref.seq.begin();
! 			while (cit_s!=subseqref.seq.end()) {
  				seq.push_back(*cit_s);
  				++cit_s;
  			}
--- 1016,1041 ----
  	seq.reserve(v.size()+noperands-nexpairseqs);
  	
  	// copy elements and split off numerical part
+ 	exvector dummy_indices;
  	cit = v.begin();
  	while (cit!=v.end()) {
  		if (ex_to<basic>(*cit).tinfo()==this->tinfo()) {
! 			const expairseq *subseqref;
! 			ex newfactor;
! 			if(is_a<mul>(*cit))
! 			{
! 				exvector dummies_of_factor = get_all_dummy_indices(*cit);
! 				newfactor = rename_dummy_indices_uniquely(dummy_indices, dummies_of_factor, *cit);
! 				subseqref = &(ex_to<expairseq>(newfactor));
! 				exvector new_dummy_indices;
! 				set_union(dummy_indices.begin(), dummy_indices.end(), dummies_of_factor.begin(), dummies_of_factor.end(), std::back_insert_iterator<exvector>(new_dummy_indices), ex_is_less());
! 				dummy_indices.swap(new_dummy_indices);
! 			}
! 			else
! 				subseqref = &ex_to<expairseq>(*cit);
! 			combine_overall_coeff(subseqref->overall_coeff);
! 			epvector::const_iterator cit_s = subseqref->seq.begin();
! 			while (cit_s!=subseqref->seq.end()) {
  				seq.push_back(*cit_s);
  				++cit_s;
  			}
Index: ginac/indexed.cpp
===================================================================
RCS file: /home/cvs/GiNaC/ginac/indexed.cpp,v
retrieving revision 1.96
diff -c -r1.96 indexed.cpp
*** ginac/indexed.cpp	19 May 2005 14:10:40 -0000	1.96
--- ginac/indexed.cpp	3 Oct 2005 21:30:41 -0000
***************
*** 1318,1326 ****
  	return v;
  }
  
! ex rename_dummy_indices_uniquely(const ex & a, const ex & b)
  {
! 	exvector va = get_all_dummy_indices(a), vb = get_all_dummy_indices(b), common_indices;
  	set_intersection(va.begin(), va.end(), vb.begin(), vb.end(), std::back_insert_iterator<exvector>(common_indices), ex_is_less());
  	if (common_indices.empty()) {
  		return b;
--- 1318,1326 ----
  	return v;
  }
  
! ex rename_dummy_indices_uniquely(const exvector & va, const exvector & vb, const ex & b)
  {
! 	exvector common_indices;
  	set_intersection(va.begin(), va.end(), vb.begin(), vb.end(), std::back_insert_iterator<exvector>(common_indices), ex_is_less());
  	if (common_indices.empty()) {
  		return b;
***************
*** 1330,1349 ****
  		new_indices.reserve(2*common_indices.size());
  		exvector::const_iterator ip = common_indices.begin(), ipend = common_indices.end();
  		while (ip != ipend) {
! 			if (is_a<varidx>(*ip)) {
! 				varidx mu((new symbol)->setflag(status_flags::dynallocated), ex_to<varidx>(*ip).get_dim(), ex_to<varidx>(*ip).is_covariant());
! 				old_indices.push_back(*ip);
! 				new_indices.push_back(mu);
  				old_indices.push_back(ex_to<varidx>(*ip).toggle_variance());
! 				new_indices.push_back(mu.toggle_variance());
! 			} else {
! 				old_indices.push_back(*ip);
! 				new_indices.push_back(idx((new symbol)->setflag(status_flags::dynallocated), ex_to<varidx>(*ip).get_dim()));
  			}
  			++ip;
  		}
  		return b.subs(lst(old_indices.begin(), old_indices.end()), lst(new_indices.begin(), new_indices.end()), subs_options::no_pattern);
  	}
  }
  
  ex expand_dummy_sum(const ex & e, bool subs_idx)
--- 1330,1366 ----
  		new_indices.reserve(2*common_indices.size());
  		exvector::const_iterator ip = common_indices.begin(), ipend = common_indices.end();
  		while (ip != ipend) {
! 			ex newsym=(new symbol)->setflag(status_flags::dynallocated);
! 			ex newidx;
! 			if(is_exactly_a<spinidx>(*ip))
! 				newidx = (new spinidx(newsym, ex_to<spinidx>(*ip).get_dim(),
! 						ex_to<spinidx>(*ip).is_covariant(),
! 						ex_to<spinidx>(*ip).is_dotted()))
! 					-> setflag(status_flags::dynallocated);
! 			else if (is_exactly_a<varidx>(*ip))
! 				newidx = (new varidx(newsym, ex_to<varidx>(*ip).get_dim(),
! 						ex_to<varidx>(*ip).is_covariant()))
! 					-> setflag(status_flags::dynallocated);
! 			else
! 				newidx = (new idx(newsym, ex_to<idx>(*ip).get_dim()))
! 					-> setflag(status_flags::dynallocated);
! 			old_indices.push_back(*ip);
! 			new_indices.push_back(newidx);
! 			if(is_a<varidx>(*ip)) {
  				old_indices.push_back(ex_to<varidx>(*ip).toggle_variance());
! 				new_indices.push_back(ex_to<varidx>(newidx).toggle_variance());
  			}
  			++ip;
  		}
  		return b.subs(lst(old_indices.begin(), old_indices.end()), lst(new_indices.begin(), new_indices.end()), subs_options::no_pattern);
  	}
+ }
+ 
+ ex rename_dummy_indices_uniquely(const ex & a, const ex & b)
+ {
+ 	exvector va = get_all_dummy_indices(a);
+ 	exvector vb = get_all_dummy_indices(b);
+ 	return rename_dummy_indices_uniquely(va, vb, b);
  }
  
  ex expand_dummy_sum(const ex & e, bool subs_idx)
Index: ginac/indexed.h
===================================================================
RCS file: /home/cvs/GiNaC/ginac/indexed.h,v
retrieving revision 1.52
diff -c -r1.52 indexed.h
*** ginac/indexed.h	19 May 2005 14:10:40 -0000	1.52
--- ginac/indexed.h	3 Oct 2005 21:30:41 -0000
***************
*** 256,261 ****
--- 256,264 ----
  /** Returns b with all dummy indices, which are common with a, renamed */
  ex rename_dummy_indices_uniquely(const ex & a, const ex & b);
  
+ /** Same as above, where va and vb contain the indices of a and b and are sorted */
+ ex rename_dummy_indices_uniquely(const exvector & va, const exvector & vb, const ex & b);
+ 
  /** This function returns the given expression with expanded sums
   *  for all dummy index summations, where the dimensionality of 
   *  the dummy index is numeric.
