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 70 71 72 73 74
|
#include "Cleanup.hh"
#include "algorithms/tab_dimension.hh"
using namespace cadabra;
tabdimension::tabdimension(const Kernel& k, Ex& ex)
: Algorithm(k, ex)
{
}
bool tabdimension::can_apply(iterator it)
{
dimension=-1;
tab=kernel.properties.get<Tableau>(it);
if(tab) {
dimension=tab->dimension;
if(dimension>0)
return true;
}
ftab=kernel.properties.get<FilledTableau>(it);
if(ftab) {
dimension=ftab->dimension;
// std::cerr << "dimension " << dimension << std::endl;
if(dimension>0)
return true;
}
return false;
}
Algorithm::result_t tabdimension::apply(iterator& it)
{
// std::cerr << "applying at " << it << std::endl;
if(ftab) {
yngtab::filled_tableau<Ex> one;
sibling_iterator sib=tr.begin(it);
unsigned int currow=0;
while(sib!=tr.end(it)) {
if(*sib->name=="\\comma") {
sibling_iterator sib2=tr.begin(sib);
while(sib2!=tr.end(sib)) {
one.add_box(currow, Ex(sib2));
++sib2;
}
}
else one.add_box(currow, Ex(sib));
++sib;
++currow;
}
auto tmp=it->multiplier;
node_one(it);
it->multiplier=tmp;
multiply(it->multiplier, one.dimension(dimension));
}
else {
yngtab::tableau one;
sibling_iterator sib=tr.begin(it);
while(sib!=tr.end(it)) {
one.add_row(to_long(*sib->multiplier));
++sib;
}
auto tmp=it->multiplier;
node_one(it);
it->multiplier=tmp;
multiply(it->multiplier, one.dimension(dimension));
}
cleanup_dispatch(kernel, tr, it);
return result_t::l_applied;
}
|