@@ -159,21 +159,21 @@ namespace cadabra {
159159 return factor;
160160 }
161161
162- void ProjectedForm::combine (const ProjectedForm& other, mpq_class factor )
162+ void ProjectedForm::combine (const ProjectedForm& other)
163163 {
164- if (factor == 1 ) {
165- for (const auto & kv : other.data ) {
166- data[kv.first ] += kv.second ;
167- if (data[kv.first ] == 0 )
168- data.erase (kv.first );
169- }
164+ for (const auto & kv : other.data ) {
165+ data[kv.first ] += kv.second ;
166+ if (data[kv.first ] == 0 )
167+ data.erase (kv.first );
170168 }
171- else {
172- for (const auto & kv : other.data ) {
173- data[kv.first ] += kv.second * factor;
174- if (data[kv.first ] == 0 )
175- data.erase (kv.first );
176- }
169+ }
170+
171+ void ProjectedForm::combine (const ProjectedForm& other, mpq_class factor)
172+ {
173+ for (const auto & kv : other.data ) {
174+ data[kv.first ] += kv.second * factor;
175+ if (data[kv.first ] == 0 )
176+ data.erase (kv.first );
177177 }
178178 }
179179
@@ -190,7 +190,8 @@ namespace cadabra {
190190
191191 void ProjectedForm::insert (adjform_t adjform, mpq_class value)
192192 {
193- data[adjform] = value;
193+ if (value != 0 )
194+ data[adjform] = value;
194195 }
195196
196197 void ProjectedForm::apply_young_symmetry (const adjform_t & indices, bool antisymmetric)
@@ -221,6 +222,8 @@ namespace cadabra {
221222 }
222223 cdebug << " \t Made term " << adjform_to_string (ret) << " * " << (parity * kv.second ) << ' \n ' ;
223224 data[ret] += parity * kv.second ;
225+ if (data[ret] == 0 )
226+ data.erase (ret);
224227 } while (swaps = next_perm (perm));
225228 }
226229 }
@@ -258,8 +261,6 @@ namespace cadabra {
258261 Ex::iterator l1 = lhs.begin (), l2 = lhs.end ();
259262 Ex::iterator r1 = rhs.begin (), r2 = rhs.end ();
260263
261- std::vector<Ex::iterator> l_indices, r_indices;
262-
263264 // Loop over all tree nodes using a depth first iterator. If the
264265 // entry is an index ensure that it has the same parent_rel, if it
265266 // is any other type of node check that the names match.
@@ -270,8 +271,6 @@ namespace cadabra {
270271 if (l1->fl .parent_rel != r1->fl .parent_rel ) {
271272 return false ;
272273 }
273- l_indices.push_back (l1);
274- r_indices.push_back (r1);
275274 }
276275 else {
277276 if (l1->name != r1->name || l1->multiplier != r1->multiplier ) {
@@ -284,6 +283,18 @@ namespace cadabra {
284283 return l1 == l2 && r1 == r2;
285284 }
286285
286+ bool has_TableauBase (Ex::iterator it, const cadabra::Kernel& kernel)
287+ {
288+ if (*it->name == " \\ prod" || *it->name == " \\ sum" ) {
289+ for (Ex::sibling_iterator beg = it.begin (), end = it.end (); beg != end; ++beg)
290+ if (has_TableauBase (beg, kernel))
291+ return true ;
292+ }
293+ else {
294+ return (kernel.properties .get_composite <cadabra::TableauBase>(it) != nullptr );
295+ }
296+ }
297+
287298 std::vector<Ex::iterator> split_ex (Ex::iterator it, const std::string& delim)
288299 {
289300 if (*it->name == delim) {
@@ -368,7 +379,12 @@ young_reduce::~young_reduce()
368379
369380bool young_reduce::can_apply (iterator it)
370381{
371- return true ;
382+ if (pat == Ex::iterator ()) {
383+ // check for TableauBase
384+ return has_TableauBase (it, kernel);
385+ }
386+ else
387+ return true ;
372388}
373389
374390young_reduce::result_t young_reduce::apply (iterator& it)
@@ -513,17 +529,13 @@ bool young_reduce::set_pattern(Ex::iterator new_pat)
513529 throw std::runtime_error (" pat is empty" );
514530
515531 cdebug << " Checking for TableauBase property..." ;
516- bool has_tableau_symmetry = false ;
517- for (const auto & term: collect) {
518- if (kernel.properties .get_composite <TableauBase>(term) != nullptr ) {
519- has_tableau_symmetry = true ;
520- break ;
521- }
522- }
523- cdebug << (has_tableau_symmetry ? " true!" : " false - exiting..." ) << ' \n ' ;
524-
525- if (!has_tableau_symmetry)
532+ if (!has_TableauBase (new_pat, kernel)) {
533+ cdebug << " false, returning...\n " ;
526534 return false ;
535+ }
536+ else {
537+ cdebug << " true!\n " ;
538+ }
527539
528540 pat = new_pat;
529541 pat_sym = symmetrize (new_pat);
0 commit comments