1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include "IndexIterator.hh"
#include "properties/TableauSymmetry.hh"
#include "algorithms/indexsort.hh"
using namespace cadabra;
indexsort::indexsort(const Kernel& k, Ex& tr)
: Algorithm(k, tr), tb(0)
{
}
bool indexsort::can_apply(iterator st)
{
if(number_of_indices(kernel.properties, st)<2) return false;
tb=kernel.properties.get<TableauBase>(st);
if(tb) return true;
return false;
}
indexsort::less_indexed_treenode::less_indexed_treenode(const Kernel& k, Ex&, iterator i)
: kernel(k), it(i)
{
}
bool indexsort::less_indexed_treenode::operator()(unsigned int i1, unsigned int i2) const
{
return subtree_exact_less(&kernel.properties,
index_iterator::begin(kernel.properties, it, i1),
index_iterator::begin(kernel.properties, it,i2) );
}
Algorithm::result_t indexsort::apply(iterator& st)
{
// txtout << "indexsort acting on " << *st->name << std::endl;
// txtout << properties::get<TableauBase>(st) << std::endl;
result_t res=result_t::l_no_action;
Ex backup(st);
for(unsigned int i=0; i<tb->size(kernel.properties, tr, st); ++i) {
TableauSymmetry::tab_t tmptab(tb->get_tab(kernel.properties, tr, st, i));
TableauSymmetry::tab_t origtab(tmptab);
less_indexed_treenode comp(kernel,tr,st);
tmptab.canonicalise(comp, false); // KP: why is this here? tb->only_column_exchange());
TableauSymmetry::tab_t::iterator it1=origtab.begin();
TableauSymmetry::tab_t::iterator it2=tmptab.begin();
while(it2!=tmptab.end()) {
if(*it1!=*it2) {
tr.replace_index(index_iterator::begin(kernel.properties,st,*it1),
index_iterator::begin(kernel.properties,backup.begin(),*it2) );
// tr.tensor_index(st,*it1)->multiplier=backup.tensor_index(backup.begin(),*it2)->multiplier;
res = result_t::l_applied;
}
++it1;
++it2;
}
if(*(tr.parent(st)->name)=="\\prod") {
multiply(tr.parent(st)->multiplier, tmptab.multiplicity*origtab.multiplicity);
pushup_multiplier(tr.parent(st));
}
else {
multiply(st->multiplier, tmptab.multiplicity*origtab.multiplicity);
pushup_multiplier(st);
}
}
return res;
}
|