@@ -46,6 +46,8 @@ namespace cadabra {
4646 changed = changed || res;
4747 if (*it->name ==" \\ sum" ) res = cleanup_sumlike (kernel, tr, it);
4848 changed = changed || res;
49+ if (*it->name ==" \\ comma" ) res = cleanup_comma (kernel, tr, it);
50+ changed = changed || res;
4951 if (*it->name ==" \\ components" ) res = cleanup_components (kernel, tr, it);
5052 changed = changed || res;
5153
@@ -124,7 +126,7 @@ namespace cadabra {
124126 tr.append_child (rhsfrac, div);
125127
126128 it=tr.flatten_and_erase (it);
127-
129+
128130 return true ;
129131 }
130132
@@ -413,7 +415,7 @@ namespace cadabra {
413415 while (sib!=tr.end (it)) {
414416 if (*sib->name ==" \\ equals" ) ++equalities;
415417 else ++nonequalities;
416- if (equalities!=0 && nonequalities!=0 )
418+ if (equalities!=0 && nonequalities!=0 )
417419 throw ConsistencyException (" Encountered an equality and a normal term in the same sum; not allowed." );
418420 ++sib;
419421 }
@@ -448,9 +450,9 @@ namespace cadabra {
448450#endif
449451 Ex::iterator tmp1=lhs, tmp2=rhs;
450452 cleanup_sumlike (k, tr, tmp1);
451- cleanup_sumlike (k, tr, tmp2);
453+ cleanup_sumlike (k, tr, tmp2);
452454 }
453-
455+
454456 // Flatten sums which are supposed to be flat.
455457 long num=tr.number_of_children (it);
456458 if (num==0 ) {
@@ -855,6 +857,19 @@ namespace cadabra {
855857 return false ;
856858 }
857859
860+ bool cleanup_comma (const Kernel& k, Ex& tr, Ex::iterator& it)
861+ {
862+ if (*it->multiplier !=1 ) {
863+ Ex::sibling_iterator sib = tr.begin (it);
864+ while (sib!=tr.end (it)) {
865+ multiply (sib->multiplier , *it->multiplier );
866+ ++sib;
867+ }
868+ one (it->multiplier );
869+ return true ;
870+ }
871+ else return false ;
872+ }
858873
859874 void cleanup_dispatch_deep (const Kernel& k, Ex& tr, dispatcher_t dispatch)
860875 {
0 commit comments