[GiNaC-devel] Patch for products of dummy summations

Vladimir Kisil kisilv at maths.leeds.ac.uk
Wed Nov 16 19:44:19 CET 2005


>>>>> "RK" == Richard B Kreckel <kreckel at ginac.de> writes:
     RK> deteriorated recently.  Indeed, times like Lewis-Wester O1 have
     RK> dropped by about 50%.  I'm pretty sure this happend with your
     RK> patch.

     RK> Is there a way to speed this up again?

 	I propose a patch which restore much of the previous speed and 
still passing through all standard checks. I also correct some errors in 
exam_clifford.cpp.

 	Best wishes,
 	Vladimir
--
Vladimir Kisil            email: kisilv at amsta.leeds.ac.uk
                             www: http://amsta.leeds.ac.uk/~kisilv
-------------- next part --------------
Index: ginac/mul.cpp
===================================================================
RCS file: /home/cvs/GiNaC/ginac/mul.cpp,v
retrieving revision 1.90
diff -r1.90 mul.cpp
897a898,912
> 				exvector add1_dummy_indices, add2_dummy_indices, add_indices;
> 
> 				for (epvector::const_iterator i=add1begin; i!=add1end; ++i) {
> 					add_indices = get_all_dummy_indices(i->rest);
> 					add1_dummy_indices.insert(add1_dummy_indices.end(), add_indices.begin(), add_indices.end());
> 				}
> 				for (epvector::const_iterator i=add2begin; i!=add2end; ++i) {
> 					add_indices = get_all_dummy_indices(i->rest);
> 					add2_dummy_indices.insert(add2_dummy_indices.end(), add_indices.begin(), add_indices.end());
> 				}
> 
> 				sort(add1_dummy_indices.begin(), add1_dummy_indices.end(), ex_is_less());
> 				sort(add2_dummy_indices.begin(), add2_dummy_indices.end(), ex_is_less());
> 				lst dummy_subs = rename_dummy_indices_uniquely(add1_dummy_indices, add2_dummy_indices);
> 
899c914
< 				for (epvector::const_iterator i1=add1begin; i1!=add1end; ++i1) {
---
> 				for (epvector::const_iterator i2=add2begin; i2!=add2end; ++i2) {
904c919,921
< 					for (epvector::const_iterator i2=add2begin; i2!=add2end; ++i2) {
---
> 					ex i2_new = (dummy_subs.op(0).nops()>0? 
> 								 i2->rest.subs((lst)dummy_subs.op(0), (lst)dummy_subs.op(1), subs_options::no_pattern) : i2->rest);
> 					for (epvector::const_iterator i1=add1begin; i1!=add1end; ++i1) {
907c924
< 						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, i2_new))->setflag(status_flags::dynallocated);
934a952,953
> 		exvector va = get_all_dummy_indices(mul(non_adds));
> 		sort(va.begin(), va.end(), ex_is_less());
938c957
< 			factors.push_back(split_ex_to_pair(rename_dummy_indices_uniquely(mul(non_adds), last_expanded.op(i))));
---
> 			factors.push_back(split_ex_to_pair(rename_dummy_indices_uniquely(va, last_expanded.op(i))));
Index: ginac/ncmul.cpp
===================================================================
RCS file: /home/cvs/GiNaC/ginac/ncmul.cpp,v
retrieving revision 1.57
diff -r1.57 ncmul.cpp
173,174c173,175
< 	size_t j = 0;
< 	size_t i;
---
> 	size_t j = 0, i;
> 	exvector va;
> 
180c181
< 			expanded_seq_mod.push_back(rename_dummy_indices_uniquely(ncmul(expanded_seq_mod), expanded_seq[i]));
---
> 			expanded_seq_mod.push_back(rename_dummy_indices_uniquely(va, expanded_seq[i], true));
187c188
< 			term[positions_of_adds[i]] = rename_dummy_indices_uniquely(ncmul(term), expanded_seq[positions_of_adds[i]].op(k[i]));
---
> 			term[positions_of_adds[i]] = rename_dummy_indices_uniquely(va, expanded_seq[positions_of_adds[i]].op(k[i]), true);
Index: ginac/power.cpp
===================================================================
RCS file: /home/cvs/GiNaC/ginac/power.cpp,v
retrieving revision 1.102
diff -r1.102 power.cpp
866a867,869
> 		exvector va = get_all_dummy_indices(m);
> 		sort(va.begin(), va.end(), ex_is_less());
> 
868c871
< 			result *= rename_dummy_indices_uniquely(m,m);
---
> 			result *= rename_dummy_indices_uniquely(va, m);
Index: ginac/indexed.h
===================================================================
RCS file: /home/cvs/GiNaC/ginac/indexed.h,v
retrieving revision 1.53
diff -r1.53 indexed.h
256a257,260
> /** Returns b with all dummy indices, which are listed in va, renamed 
>  *  if modify_va is set to TRUE all dummy indices of b will be appended to va */
> ex rename_dummy_indices_uniquely(exvector & va, const ex & b, bool modify_va = false);
> 
262a267,270
> /** Similar to above, where va and vb are the same and the return value is a list of two lists 
>  *  for substitution in b */
> lst rename_dummy_indices_uniquely(const exvector & va, const exvector & vb);
> 
Index: ginac/indexed.cpp
===================================================================
RCS file: /home/cvs/GiNaC/ginac/indexed.cpp,v
retrieving revision 1.97
diff -r1.97 indexed.cpp
1377c1377
< ex rename_dummy_indices_uniquely(const exvector & va, const exvector & vb, const ex & b)
---
> lst rename_dummy_indices_uniquely(const exvector & va, const exvector & vb)
1382c1382
< 		return b;
---
> 		return lst(lst(), lst());
1411c1411
< 		return b.subs(lst(old_indices.begin(), old_indices.end()), lst(new_indices.begin(), new_indices.end()), subs_options::no_pattern);
---
> 		return lst(lst(old_indices.begin(), old_indices.end()), lst(new_indices.begin(), new_indices.end()));
1414a1415,1420
> ex rename_dummy_indices_uniquely(const exvector & va, const exvector & vb, const ex & b)
> {
> 	lst indices_subs = rename_dummy_indices_uniquely(va, vb);
> 	return (indices_subs.op(0).nops()>0 ? b.subs((lst)indices_subs.op(0), (lst)indices_subs.op(1), subs_options::no_pattern) : b);
> }
> 
1418,1421c1424,1461
< 	exvector vb = get_all_dummy_indices(b);
< 	sort(va.begin(), va.end(), ex_is_less());
< 	sort(vb.begin(), vb.end(), ex_is_less());
< 	return rename_dummy_indices_uniquely(va, vb, b);
---
> 	if (va.size() > 0) {
> 		exvector vb = get_all_dummy_indices(b);
> 		if (vb.size() > 0) {
> 			sort(va.begin(), va.end(), ex_is_less());
> 			sort(vb.begin(), vb.end(), ex_is_less());
> 			lst indices_subs = rename_dummy_indices_uniquely(va, vb);
> 			if (indices_subs.op(0).nops() > 0)
> 				return b.subs((lst)indices_subs.op(0), (lst)indices_subs.op(1), subs_options::no_pattern);
> 		}
> 	}
> 	return b;
> }
> 
> ex rename_dummy_indices_uniquely(exvector & va, const ex & b, bool modify_va)
> {
> 	if (va.size() > 0) {
> 		exvector vb = get_all_dummy_indices(b);
> 		if (vb.size() > 0) {
> 			sort(vb.begin(), vb.end(), ex_is_less());
> 			lst indices_subs = rename_dummy_indices_uniquely(va, vb);
> 			if (indices_subs.op(0).nops() > 0) {
> 				if (modify_va) {
> 					for (lst::const_iterator i = ex_to<lst>(indices_subs.op(1)).begin(); i != ex_to<lst>(indices_subs.op(1)).end(); ++i)
> 						va.push_back(*i);
> 					exvector uncommon_indices;
> 					set_difference(vb.begin(), vb.end(), indices_subs.op(0).begin(), indices_subs.op(0).end(), std::back_insert_iterator<exvector>(uncommon_indices), ex_is_less());
> 					exvector::const_iterator ip = uncommon_indices.begin(), ipend = uncommon_indices.end();
> 					while (ip != ipend) {
> 						va.push_back(*ip);
> 						++ip;
> 					}
> 					sort(va.begin(), va.end(), ex_is_less());
> 				}
> 				return b.subs((lst)indices_subs.op(0), (lst)indices_subs.op(1), subs_options::no_pattern);
> 			}
> 		}
> 	}
> 	return b;
Index: check/exam_clifford.cpp
===================================================================
RCS file: /home/cvs/GiNaC/check/exam_clifford.cpp,v
retrieving revision 1.27
diff -r1.27 exam_clifford.cpp
51c51
< 	for(int i = 0; i++; i < e1.nops()) {
---
> 	for (unsigned int i = 0; i < e1.nops(); i++) {
53c53
< 		if (!e.is_zero()) {
---
> 		if (!e.normal().is_zero()) {
317c317
< 
---
> 	
415c415
< 	result += check_equal_lst((e*e1).simplify_indexed(), dirac_ONE(1));
---
> 	result += check_equal((e*e1).simplify_indexed(), dirac_ONE(1));


More information about the GiNaC-devel mailing list