* Implementation of sequences of expression pairs. */
/*
- * GiNaC Copyright (C) 1999-2006 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <algorithm>
#include <string>
#include <stdexcept>
+#include <iterator>
#include "expairseq.h"
#include "lst.h"
bool expairseq::info(unsigned inf) const
{
+ switch(inf) {
+ case info_flags::expanded:
+ return (flags & status_flags::expanded);
+ case info_flags::has_indices: {
+ if (flags & status_flags::has_indices)
+ return true;
+ else if (flags & status_flags::has_no_indices)
+ return false;
+ for (epvector::const_iterator i = seq.begin(); i != seq.end(); ++i) {
+ if (i->rest.info(info_flags::has_indices)) {
+ this->setflag(status_flags::has_indices);
+ this->clearflag(status_flags::has_no_indices);
+ return true;
+ }
+ }
+ this->clearflag(status_flags::has_indices);
+ this->setflag(status_flags::has_no_indices);
+ return false;
+ }
+ }
return inherited::info(inf);
}
construct_from_2_ex_via_exvector(lh,rh);
} else {
#endif // EXPAIRSEQ_USE_HASHTAB
- if(is_a<mul>(lh))
- {
+ if (is_a<mul>(lh) && lh.info(info_flags::has_indices) &&
+ rh.info(info_flags::has_indices)) {
ex newrh=rename_dummy_indices_uniquely(lh, rh);
construct_from_2_expairseq(ex_to<expairseq>(lh),
ex_to<expairseq>(newrh));
// and their cumulative number of operands
int nexpairseqs = 0;
int noperands = 0;
+ bool do_idx_rename = false;
cit = v.begin();
while (cit!=v.end()) {
++nexpairseqs;
noperands += ex_to<expairseq>(*cit).seq.size();
}
+ if (is_a<mul>(*this) && (!do_idx_rename) &&
+ cit->info(info_flags::has_indices))
+ do_idx_rename = true;
++cit;
}
seq.reserve(v.size()+noperands-nexpairseqs);
// copy elements and split off numerical part
- make_flat_inserter mf(v, this->tinfo() == &mul::tinfo_static);
+ make_flat_inserter mf(v, do_idx_rename);
cit = v.begin();
while (cit!=v.end()) {
if (ex_to<basic>(*cit).tinfo()==this->tinfo()) {
// and their cumulative number of operands
int nexpairseqs = 0;
int noperands = 0;
+ bool really_need_rename_inds = false;
cit = v.begin();
while (cit!=v.end()) {
++nexpairseqs;
noperands += ex_to<expairseq>(cit->rest).seq.size();
}
+ if ((!really_need_rename_inds) && is_a<mul>(*this) &&
+ cit->rest.info(info_flags::has_indices))
+ really_need_rename_inds = true;
++cit;
}
+ do_index_renaming = do_index_renaming && really_need_rename_inds;
// reserve seq and coeffseq which will hold all operands
seq.reserve(v.size()+noperands-nexpairseqs);