}
// Then proceed with the remaining factors
- epvector::const_iterator it = seq.begin(), itend = seq.end();
- while (it != itend) {
- coeff = ex_to<numeric>(it->coeff);
+ for (auto & it : seq) {
+ coeff = ex_to<numeric>(it.coeff);
if (!first) {
if (coeff.csgn() == -1) c.s << '-'; else c.s << '+';
} else {
}
c.s << mul_sym;
}
- it->rest.print(c, precedence());
- ++it;
+ it.rest.print(c, precedence());
}
if (precedence() <= level)
c.s << "(";
// Print arguments, separated by "+" or "-"
- epvector::const_iterator it = seq.begin(), itend = seq.end();
char separator = ' ';
- while (it != itend) {
+ for (auto & it : seq) {
// If the coefficient is negative, separator is "-"
- if (it->coeff.is_equal(_ex_1) ||
- ex_to<numeric>(it->coeff).numer().is_equal(*_num_1_p))
+ if (it.coeff.is_equal(_ex_1) ||
+ ex_to<numeric>(it.coeff).numer().is_equal(*_num_1_p))
separator = '-';
c.s << separator;
- if (it->coeff.is_equal(_ex1) || it->coeff.is_equal(_ex_1)) {
- it->rest.print(c, precedence());
- } else if (ex_to<numeric>(it->coeff).numer().is_equal(*_num1_p) ||
- ex_to<numeric>(it->coeff).numer().is_equal(*_num_1_p))
+ if (it.coeff.is_equal(_ex1) || it.coeff.is_equal(_ex_1)) {
+ it.rest.print(c, precedence());
+ } else if (ex_to<numeric>(it.coeff).numer().is_equal(*_num1_p) ||
+ ex_to<numeric>(it.coeff).numer().is_equal(*_num_1_p))
{
- it->rest.print(c, precedence());
+ it.rest.print(c, precedence());
c.s << '/';
- ex_to<numeric>(it->coeff).denom().print(c, precedence());
+ ex_to<numeric>(it.coeff).denom().print(c, precedence());
} else {
- it->coeff.print(c, precedence());
+ it.coeff.print(c, precedence());
c.s << '*';
- it->rest.print(c, precedence());
+ it.rest.print(c, precedence());
}
- ++it;
separator = '+';
}
case info_flags::even:
case info_flags::crational_polynomial:
case info_flags::rational_function: {
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- if (!(recombine_pair_to_ex(*i).info(inf)))
+ for (auto & i : seq) {
+ if (!(recombine_pair_to_ex(i).info(inf)))
return false;
- ++i;
}
if (overall_coeff.is_zero() && (inf == info_flags::positive || inf == info_flags::posint))
return true;
bool add::is_polynomial(const ex & var) const
{
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
- if (!(i->rest).is_polynomial(var)) {
+ for (auto & i : seq) {
+ if (!i.rest.is_polynomial(var)) {
return false;
}
}
deg = 0;
// Find maximum of degrees of individual terms
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- int cur_deg = i->rest.degree(s);
+ for (auto & i : seq) {
+ int cur_deg = i.rest.degree(s);
if (cur_deg > deg)
deg = cur_deg;
- ++i;
}
return deg;
}
deg = 0;
// Find minimum of degrees of individual terms
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- int cur_deg = i->rest.ldegree(s);
+ for (auto & i : seq) {
+ int cur_deg = i.rest.ldegree(s);
if (cur_deg < deg)
deg = cur_deg;
- ++i;
}
return deg;
}
bool nonscalar = false;
// Calculate sum of coefficients in each term
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- ex restcoeff = i->rest.coeff(s, n);
+ for (auto & i : seq) {
+ ex restcoeff = i.rest.coeff(s, n);
if (!restcoeff.is_zero()) {
if (do_clifford) {
if (clifford_max_label(restcoeff) == -1) {
- coeffseq_cliff.push_back(combine_ex_with_coeff_to_pair(ncmul(restcoeff, dirac_ONE(rl)), i->coeff));
+ coeffseq_cliff.push_back(combine_ex_with_coeff_to_pair(ncmul(restcoeff, dirac_ONE(rl)), i.coeff));
} else {
- coeffseq_cliff.push_back(combine_ex_with_coeff_to_pair(restcoeff, i->coeff));
+ coeffseq_cliff.push_back(combine_ex_with_coeff_to_pair(restcoeff, i.coeff));
nonscalar = true;
}
}
- coeffseq.push_back(combine_ex_with_coeff_to_pair(restcoeff, i->coeff));
+ coeffseq.push_back(combine_ex_with_coeff_to_pair(restcoeff, i.coeff));
}
- ++i;
}
return (new add(nonscalar ? std::move(coeffseq_cliff) : std::move(coeffseq),
}
#ifdef DO_GINAC_ASSERT
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- GINAC_ASSERT(!is_exactly_a<add>(i->rest));
- ++i;
+ for (auto & i : seq) {
+ GINAC_ASSERT(!is_exactly_a<add>(i.rest));
}
#endif // def DO_GINAC_ASSERT
// if any terms in the sum still are purely numeric, then they are more
// appropriately collected into the overall coefficient
- epvector::const_iterator last = seq.end();
- epvector::const_iterator j = seq.begin();
int terms_to_collect = 0;
- while (j != last) {
- if (unlikely(is_a<numeric>(j->rest)))
+ for (auto & it : seq) {
+ if (unlikely(is_a<numeric>(it.rest)))
++terms_to_collect;
- ++j;
}
if (terms_to_collect) {
epvector s;
s.reserve(seq_size - terms_to_collect);
numeric oc = *_num1_p;
- j = seq.begin();
- while (j != last) {
- if (unlikely(is_a<numeric>(j->rest)))
- oc = oc.mul(ex_to<numeric>(j->rest)).mul(ex_to<numeric>(j->coeff));
+ for (auto & it : seq) {
+ if (unlikely(is_a<numeric>(it.rest)))
+ oc = oc.mul(ex_to<numeric>(it.rest)).mul(ex_to<numeric>(it.coeff));
else
- s.push_back(*j);
- ++j;
+ s.push_back(it);
}
return (new add(std::move(s), ex_to<numeric>(overall_coeff).add_dyn(oc)))
->setflag(status_flags::dynallocated);
bool first_term = true;
matrix sum;
- epvector::const_iterator it = seq.begin(), itend = seq.end();
- while (it != itend) {
- const ex &m = recombine_pair_to_ex(*it).evalm();
+ for (auto & it : seq) {
+ const ex &m = recombine_pair_to_ex(it).evalm();
s.push_back(split_ex_to_pair(m));
if (is_a<matrix>(m)) {
if (first_term) {
sum = sum.add(ex_to<matrix>(m));
} else
all_matrices = false;
- ++it;
}
if (all_matrices)
ex add::conjugate() const
{
- exvector *v = 0;
+ std::unique_ptr<exvector> v(nullptr);
for (size_t i=0; i<nops(); ++i) {
if (v) {
v->push_back(op(i).conjugate());
ex ccterm = term.conjugate();
if (are_ex_trivially_equal(term, ccterm))
continue;
- v = new exvector;
+ v.reset(new exvector);
v->reserve(nops());
for (size_t j=0; j<i; ++j)
v->push_back(op(j));
v->push_back(ccterm);
}
if (v) {
- ex result = add(*v);
- delete v;
- return result;
+ return add(std::move(*v));
}
return *this;
}
{
epvector v;
v.reserve(seq.size());
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
- if ((i->coeff).info(info_flags::real)) {
- ex rp = (i->rest).real_part();
+ for (auto & it : seq)
+ if (it.coeff.info(info_flags::real)) {
+ ex rp = it.rest.real_part();
if (!rp.is_zero())
- v.push_back(expair(rp, i->coeff));
+ v.push_back(expair(rp, it.coeff));
} else {
- ex rp=recombine_pair_to_ex(*i).real_part();
+ ex rp = recombine_pair_to_ex(it).real_part();
if (!rp.is_zero())
v.push_back(split_ex_to_pair(rp));
}
- return (new add(v, overall_coeff.real_part()))
+ return (new add(std::move(v), overall_coeff.real_part()))
-> setflag(status_flags::dynallocated);
}
{
epvector v;
v.reserve(seq.size());
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
- if ((i->coeff).info(info_flags::real)) {
- ex ip = (i->rest).imag_part();
+ for (auto & it : seq)
+ if (it.coeff.info(info_flags::real)) {
+ ex ip = it.rest.imag_part();
if (!ip.is_zero())
- v.push_back(expair(ip, i->coeff));
+ v.push_back(expair(ip, it.coeff));
} else {
- ex ip=recombine_pair_to_ex(*i).imag_part();
+ ex ip = recombine_pair_to_ex(it).imag_part();
if (!ip.is_zero())
v.push_back(split_ex_to_pair(ip));
}
- return (new add(v, overall_coeff.imag_part()))
+ return (new add(std::move(v), overall_coeff.imag_part()))
-> setflag(status_flags::dynallocated);
}
// Only differentiate the "rest" parts of the expairs. This is faster
// than the default implementation in basic::derivative() although
// if performs the same function (differentiate each term).
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- s.push_back(combine_ex_with_coeff_to_pair(i->rest.diff(y), i->coeff));
- ++i;
- }
+ for (auto & it : seq)
+ s.push_back(combine_ex_with_coeff_to_pair(it.rest.diff(y), it.coeff));
+
return (new add(std::move(s), _ex0))->setflag(status_flags::dynallocated);
}
exmap cmap;
cmap[_ex1] = _ex0;
- for (const_iterator xi=x.begin(); xi!=x.end(); ++xi) {
+ for (const auto & xi : x) {
ex key = _ex1;
- ex pre_coeff = *xi;
- for (lst::const_iterator li=l.begin(); li!=l.end(); ++li) {
- int cexp = pre_coeff.degree(*li);
- pre_coeff = pre_coeff.coeff(*li, cexp);
- key *= pow(*li, cexp);
+ ex pre_coeff = xi;
+ for (auto & li : l) {
+ int cexp = pre_coeff.degree(li);
+ pre_coeff = pre_coeff.coeff(li, cexp);
+ key *= pow(li, cexp);
}
exmap::iterator ci = cmap.find(key);
if (ci != cmap.end())
}
exvector resv;
- for (exmap::const_iterator mi=cmap.begin(); mi != cmap.end(); ++mi)
- resv.push_back((mi->first)*(mi->second));
+ for (auto & mi : cmap)
+ resv.push_back((mi.first)*(mi.second));
return (new add(resv))->setflag(status_flags::dynallocated);
} else {
// Wildcard matches anything, but check whether we already have found
// a match for that wildcard first (if so, the earlier match must be
// the same expression)
- for (exmap::const_iterator it = repl_lst.begin(); it != repl_lst.end(); ++it) {
- if (it->first.is_equal(pattern))
- return is_equal(ex_to<basic>(it->second));
+ for (auto & it : repl_lst) {
+ if (it.first.is_equal(pattern))
+ return is_equal(ex_to<basic>(it.second));
}
repl_lst[pattern] = *this;
return true;
/** Helper function for subs(). Does not recurse into subexpressions. */
ex basic::subs_one_level(const exmap & m, unsigned options) const
{
- exmap::const_iterator it;
-
if (options & subs_options::no_pattern) {
- ex thisex = *this;
- it = m.find(thisex);
+ auto it = m.find(*this);
if (it != m.end())
return it->second;
- return thisex;
+ return *this;
} else {
- for (it = m.begin(); it != m.end(); ++it) {
+ for (auto & it : m) {
exmap repl_lst;
- if (match(ex_to<basic>(it->first), repl_lst))
- return it->second.subs(repl_lst, options | subs_options::no_pattern);
+ if (match(ex_to<basic>(it.first), repl_lst))
+ return it.second.subs(repl_lst, options | subs_options::no_pattern);
// avoid infinite recursion when re-substituting the wildcards
}
}
s.reserve(v.size());
// Remove superfluous ONEs
- exvector::const_iterator cit = v.begin(), citend = v.end();
- while (cit != citend) {
- if (!is_a<clifford>(*cit) || !is_a<diracone>(cit->op(0)))
- s.push_back(*cit);
- cit++;
+ for (auto & it : v) {
+ if (!is_a<clifford>(it) || !is_a<diracone>(it.op(0)))
+ s.push_back(it);
}
bool something_changed = false;
if (ind_vec.size() > 0) {
found_dummy = true;
- exvector::const_iterator it = ind_vec.begin(), itend = ind_vec.end();
- while (it != itend) {
- ex curridx = *it;
+ for (auto & it : ind_vec) {
+ ex curridx = it;
ex curridx_toggle = is_a<varidx>(curridx)
? ex_to<varidx>(curridx).toggle_variance()
: curridx;
S = S * e.op(j).subs(lst(curridx == ival,
curridx_toggle == ival), subs_options::no_pattern);
- ++it;
}
} else
S = S * e.op(j);
s.reserve(v.size());
// Remove superfluous ONEs
- exvector::const_iterator it = v.begin(), itend = v.end();
- while (it != itend) {
- if (!is_a<su3one>(it->op(0)))
- s.push_back(*it);
- it++;
+ for (auto & it : v) {
+ if (!is_a<su3one>(it.op(0)))
+ s.push_back(it);
}
if (s.empty())
{
// Convert list to set
std::set<unsigned char> rls;
- for (lst::const_iterator i = rll.begin(); i != rll.end(); ++i) {
- if (i->info(info_flags::nonnegint))
- rls.insert(ex_to<numeric>(*i).to_int());
+ for (auto & it : rll) {
+ if (it.info(info_flags::nonnegint))
+ rls.insert(ex_to<numeric>(it).to_int());
}
return color_trace(e, rls);
void archive(archive_node &n) const
{
inherited::archive(n);
- const_iterator i = this->seq.begin(), end = this->seq.end();
- while (i != end) {
- n.add_ex("seq", *i);
- ++i;
+ for (auto & i : this->seq) {
+ n.add_ex("seq", i);
}
}
// Argument is a list: convert it to a map
exmap m;
GINAC_ASSERT(is_a<lst>(e));
- for (lst::const_iterator it = ex_to<lst>(e).begin(); it != ex_to<lst>(e).end(); ++it) {
- ex r = *it;
+ for (auto & r : ex_to<lst>(e)) {
if (!r.info(info_flags::relation_equal))
throw(std::invalid_argument("basic::subs(ex): argument must be a list of equations"));
const ex & s = r.op(0);
{
if (is_a<lst>(vars)) {
const lst & varlst = ex_to<lst>(vars);
- for (lst::const_iterator i=varlst.begin(); i!=varlst.end(); ++i)
- if (!bp->is_polynomial(*i))
+ for (auto & it : varlst)
+ if (!bp->is_polynomial(it))
return false;
return true;
}
*/
~excompiler()
{
- for (std::vector<filedesc>::const_iterator it = filelist.begin(); it != filelist.end(); ++it) {
+ for (auto it = filelist.begin(); it != filelist.end(); ++it) {
clean_up(it);
}
}
*/
void unlink(const std::string filename)
{
- for (std::vector<filedesc>::iterator it = filelist.begin(); it != filelist.end();) {
+ for (auto it = filelist.begin(); it != filelist.end();) {
if (it->name == filename) {
clean_up(it);
it = filelist.erase(it);
void expairseq::read_archive(const archive_node &n, lst &sym_lst)
{
inherited::read_archive(n, sym_lst);
- archive_node::archive_node_cit first = n.find_first("rest");
- archive_node::archive_node_cit last = n.find_last("coeff");
+ auto first = n.find_first("rest");
+ auto last = n.find_last("coeff");
++last;
seq.reserve((last-first)/2);
- for (archive_node::archive_node_cit loc = first; loc < last;) {
+ for (auto loc = first; loc < last;) {
ex rest;
ex coeff;
n.find_ex_by_loc(loc++, rest, sym_lst);
void expairseq::archive(archive_node &n) const
{
inherited::archive(n);
- epvector::const_iterator i = seq.begin(), iend = seq.end();
- while (i != iend) {
- n.add_ex("rest", i->rest);
- n.add_ex("coeff", i->coeff);
- ++i;
+ for (auto & i : seq) {
+ n.add_ex("rest", i.rest);
+ n.add_ex("coeff", i.coeff);
}
n.add_ex("overall_coeff", overall_coeff);
}
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)) {
+ for (auto & i : seq) {
+ if (i.rest.info(info_flags::has_indices)) {
this->setflag(status_flags::has_indices);
this->clearflag(status_flags::has_no_indices);
return true;
epvector v;
v.reserve(seq.size()+1);
- epvector::const_iterator cit = seq.begin(), last = seq.end();
- while (cit != last) {
- v.push_back(split_ex_to_pair(f(recombine_pair_to_ex(*cit))));
- ++cit;
- }
+ for (auto & it : seq)
+ v.push_back(split_ex_to_pair(f(recombine_pair_to_ex(it))));
if (overall_coeff.is_equal(default_overall_coeff()))
return thisexpairseq(std::move(v), default_overall_coeff(), true);
epvector* conjugateepvector(const epvector&epv)
{
- epvector *newepv = 0;
- for (epvector::const_iterator i=epv.begin(); i!=epv.end(); ++i) {
- if(newepv) {
+ epvector *newepv = nullptr;
+ for (auto i=epv.begin(); i!=epv.end(); ++i) {
+ if (newepv) {
newepv->push_back(i->conjugate());
continue;
}
ex expairseq::conjugate() const
{
- epvector* newepv = conjugateepvector(seq);
+ std::unique_ptr<epvector> newepv(conjugateepvector(seq));
ex x = overall_coeff.conjugate();
if (newepv) {
- ex result = thisexpairseq(std::move(*newepv), x);
- delete newepv;
- return result;
+ return thisexpairseq(std::move(*newepv), x);
}
if (are_ex_trivially_equal(x, overall_coeff)) {
return *this;
ex p = pattern.op(i);
if (has_global_wildcard && p.is_equal(global_wildcard))
continue;
- exvector::iterator it = ops.begin(), itend = ops.end();
+ auto it = ops.begin(), itend = ops.end();
while (it != itend) {
if (it->match(p, tmp_repl)) {
ops.erase(it);
for (size_t i=0; i<num; i++)
vp.push_back(split_ex_to_pair(ops[i]));
ex rest = thisexpairseq(std::move(vp), default_overall_coeff());
- for (exmap::const_iterator it = tmp_repl.begin(); it != tmp_repl.end(); ++it) {
- if (it->first.is_equal(global_wildcard)) {
- if (rest.is_equal(it->second)) {
+ for (auto & it : tmp_repl) {
+ if (it.first.is_equal(global_wildcard)) {
+ if (rest.is_equal(it.second)) {
repl_lst = tmp_repl;
return true;
}
if (cmpval!=0)
return cmpval;
- epvector::const_iterator cit1 = seq.begin();
- epvector::const_iterator cit2 = o.seq.begin();
- epvector::const_iterator last1 = seq.end();
- epvector::const_iterator last2 = o.seq.end();
-
- for (; (cit1!=last1)&&(cit2!=last2); ++cit1, ++cit2) {
+ auto cit1 = seq.begin(), last1 = seq.end();
+ auto cit2 = o.seq.begin(), last2 = o.seq.end();
+ for (; (cit1!=last1) && (cit2!=last2); ++cit1, ++cit2) {
cmpval = (*cit1).compare(*cit2);
if (cmpval!=0) return cmpval;
}
if (!overall_coeff.is_equal(o.overall_coeff))
return false;
- epvector::const_iterator cit1 = seq.begin();
- epvector::const_iterator cit2 = o.seq.begin();
- epvector::const_iterator last1 = seq.end();
-
- while (cit1!=last1) {
- if (!(*cit1).is_equal(*cit2)) return false;
- ++cit1;
+ auto cit2 = o.seq.begin();
+ for (auto & cit1 : seq) {
+ if (!cit1.is_equal(*cit2))
+ return false;
++cit2;
}
unsigned expairseq::calchash() const
{
unsigned v = make_hash_seed(typeid(*this));
- epvector::const_iterator i = seq.begin();
- const epvector::const_iterator end = seq.end();
- while (i != end) {
- v ^= i->rest.gethash();
+ for (auto & i : seq) {
+ v ^= i.rest.gethash();
v = rotate_left(v);
- v ^= i->coeff.gethash();
- ++i;
+ v ^= i.coeff.gethash();
}
v ^= overall_coeff.gethash();
{
if (this_precedence <= upper_precedence)
c.s << "(";
- epvector::const_iterator it, it_last = seq.end() - 1;
- for (it=seq.begin(); it!=it_last; ++it) {
+ auto it = seq.begin(), it_last = seq.end() - 1;
+ for (; it!=it_last; ++it) {
printpair(c, *it, this_precedence);
c.s << delim;
}
combine_overall_coeff(s1.overall_coeff);
combine_overall_coeff(s2.overall_coeff);
- epvector::const_iterator first1 = s1.seq.begin();
- epvector::const_iterator last1 = s1.seq.end();
- epvector::const_iterator first2 = s2.seq.begin();
- epvector::const_iterator last2 = s2.seq.end();
+ auto first1 = s1.seq.begin(), last1 = s1.seq.end();
+ auto first2 = s2.seq.begin(), last2 = s2.seq.end();
seq.reserve(s1.seq.size()+s2.seq.size());
return;
}
- epvector::const_iterator first = s.seq.begin();
- epvector::const_iterator last = s.seq.end();
+ auto first = s.seq.begin(), last = s.seq.end();
expair p = split_ex_to_pair(e);
seq.reserve(s.seq.size()+1);
* It cares for associativity as well as for special handling of numerics. */
void expairseq::make_flat(const exvector &v)
{
- exvector::const_iterator cit;
-
// count number of operands which are of same expairseq derived type
// and their cumulative number of operands
int nexpairseqs = 0;
int noperands = 0;
bool do_idx_rename = false;
- cit = v.begin();
- while (cit!=v.end()) {
- if (typeid(ex_to<basic>(*cit)) == typeid(*this)) {
+ for (auto & cit : v) {
+ if (typeid(ex_to<basic>(cit)) == typeid(*this)) {
++nexpairseqs;
- noperands += ex_to<expairseq>(*cit).seq.size();
+ noperands += ex_to<expairseq>(cit).seq.size();
}
if (is_a<mul>(*this) && (!do_idx_rename) &&
- cit->info(info_flags::has_indices))
+ cit.info(info_flags::has_indices))
do_idx_rename = true;
- ++cit;
}
// reserve seq and coeffseq which will hold all operands
// copy elements and split off numerical part
make_flat_inserter mf(v, do_idx_rename);
- cit = v.begin();
- while (cit!=v.end()) {
- if (typeid(ex_to<basic>(*cit)) == typeid(*this)) {
- ex newfactor = mf.handle_factor(*cit, _ex1);
+ for (auto & cit : v) {
+ if (typeid(ex_to<basic>(cit)) == typeid(*this)) {
+ ex newfactor = mf.handle_factor(cit, _ex1);
const expairseq &subseqref = ex_to<expairseq>(newfactor);
combine_overall_coeff(subseqref.overall_coeff);
- epvector::const_iterator cit_s = subseqref.seq.begin();
- while (cit_s!=subseqref.seq.end()) {
- seq.push_back(*cit_s);
- ++cit_s;
+ for (auto & cit_s : subseqref.seq) {
+ seq.push_back(cit_s);
}
} else {
- if (is_exactly_a<numeric>(*cit))
- combine_overall_coeff(*cit);
+ if (is_exactly_a<numeric>(cit))
+ combine_overall_coeff(cit);
else {
- ex newfactor = mf.handle_factor(*cit, _ex1);
+ ex newfactor = mf.handle_factor(cit, _ex1);
seq.push_back(split_ex_to_pair(newfactor));
}
}
- ++cit;
}
}
* It cares for associativity as well as for special handling of numerics. */
void expairseq::make_flat(const epvector &v, bool do_index_renaming)
{
- epvector::const_iterator cit;
-
// count number of operands which are of same expairseq derived type
// 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()) {
- if (typeid(ex_to<basic>(cit->rest)) == typeid(*this)) {
+ for (auto & cit : v) {
+ if (typeid(ex_to<basic>(cit.rest)) == typeid(*this)) {
++nexpairseqs;
- noperands += ex_to<expairseq>(cit->rest).seq.size();
+ noperands += ex_to<expairseq>(cit.rest).seq.size();
}
if ((!really_need_rename_inds) && is_a<mul>(*this) &&
- cit->rest.info(info_flags::has_indices))
+ cit.rest.info(info_flags::has_indices))
really_need_rename_inds = true;
- ++cit;
}
do_index_renaming = do_index_renaming && really_need_rename_inds;
make_flat_inserter mf(v, do_index_renaming);
// copy elements and split off numerical part
- cit = v.begin();
- while (cit!=v.end()) {
- if ((typeid(ex_to<basic>(cit->rest)) == typeid(*this)) &&
- this->can_make_flat(*cit)) {
- ex newrest = mf.handle_factor(cit->rest, cit->coeff);
+ for (auto & cit : v) {
+ if (typeid(ex_to<basic>(cit.rest)) == typeid(*this) &&
+ this->can_make_flat(cit)) {
+ ex newrest = mf.handle_factor(cit.rest, cit.coeff);
const expairseq &subseqref = ex_to<expairseq>(newrest);
combine_overall_coeff(ex_to<numeric>(subseqref.overall_coeff),
- ex_to<numeric>(cit->coeff));
- epvector::const_iterator cit_s = subseqref.seq.begin();
- while (cit_s!=subseqref.seq.end()) {
- seq.push_back(expair(cit_s->rest,
- ex_to<numeric>(cit_s->coeff).mul_dyn(ex_to<numeric>(cit->coeff))));
- ++cit_s;
+ ex_to<numeric>(cit.coeff));
+ for (auto & cit_s : subseqref.seq) {
+ seq.push_back(expair(cit_s.rest,
+ ex_to<numeric>(cit_s.coeff).mul_dyn(ex_to<numeric>(cit.coeff))));
}
} else {
- if (cit->is_canonical_numeric())
- combine_overall_coeff(mf.handle_factor(cit->rest, _ex1));
+ if (cit.is_canonical_numeric())
+ combine_overall_coeff(mf.handle_factor(cit.rest, _ex1));
else {
- ex rest = cit->rest;
- ex newrest = mf.handle_factor(rest, cit->coeff);
+ ex rest = cit.rest;
+ ex newrest = mf.handle_factor(rest, cit.coeff);
if (are_ex_trivially_equal(newrest, rest))
- seq.push_back(*cit);
+ seq.push_back(cit);
else
- seq.push_back(expair(newrest, cit->coeff));
+ seq.push_back(expair(newrest, cit.coeff));
}
}
- ++cit;
}
}
bool needs_further_processing = false;
- epvector::iterator itin1 = seq.begin();
- epvector::iterator itin2 = itin1+1;
- epvector::iterator itout = itin1;
- epvector::iterator last = seq.end();
+ auto itin1 = seq.begin();
+ auto itin2 = itin1 + 1;
+ auto itout = itin1;
+ auto last = seq.end();
// must_copy will be set to true the first time some combination is
// possible from then on the sequence has changed and must be compacted
bool must_copy = false;
if (seq.size() <= 1)
return 1;
- epvector::const_iterator it = seq.begin(), itend = seq.end();
- epvector::const_iterator it_last = it;
+ auto it = seq.begin(), itend = seq.end();
+ auto it_last = it;
for (++it; it!=itend; it_last=it, ++it) {
if (!(it_last->is_less(*it) || it_last->is_equal(*it))) {
if (!is_exactly_a<numeric>(it_last->rest) ||
* had to be changed. */
epvector expairseq::expandchildren(unsigned options) const
{
- const epvector::const_iterator last = seq.end();
- epvector::const_iterator cit = seq.begin();
+ auto cit = seq.begin(), last = seq.end();
while (cit!=last) {
const ex &expanded_ex = cit->rest.expand(options);
if (!are_ex_trivially_equal(cit->rest,expanded_ex)) {
s.reserve(seq.size());
// copy parts of seq which are known not to have changed
- epvector::const_iterator cit2 = seq.begin();
+ auto cit2 = seq.begin();
while (cit2!=cit) {
s.push_back(*cit2);
++cit2;
throw(std::runtime_error("max recursion level reached"));
--level;
- epvector::const_iterator last = seq.end();
- epvector::const_iterator cit = seq.begin();
+ auto cit = seq.begin(), last = seq.end();
while (cit!=last) {
const ex evaled_ex = cit->rest.eval(level);
if (!are_ex_trivially_equal(cit->rest,evaled_ex)) {
s.reserve(seq.size());
// copy parts of seq which are known not to have changed
- epvector::const_iterator cit2=seq.begin();
+ auto cit2 = seq.begin();
while (cit2!=cit) {
s.push_back(*cit2);
++cit2;
if (!(options & (subs_options::pattern_is_product | subs_options::pattern_is_not_product))) {
// Search the list of substitutions and cache our findings
- for (exmap::const_iterator it = m.begin(); it != m.end(); ++it) {
- if (is_exactly_a<mul>(it->first) || is_exactly_a<power>(it->first)) {
+ for (auto & it : m) {
+ if (is_exactly_a<mul>(it.first) || is_exactly_a<power>(it.first)) {
options |= subs_options::pattern_is_product;
break;
}
if (options & subs_options::pattern_is_product) {
// Substitute in the recombined pairs
- epvector::const_iterator cit = seq.begin(), last = seq.end();
+ auto cit = seq.begin(), last = seq.end();
while (cit != last) {
const ex &orig_ex = recombine_pair_to_ex(*cit);
} else {
// Substitute only in the "rest" part of the pairs
- epvector::const_iterator cit = seq.begin(), last = seq.end();
+ auto cit = seq.begin(), last = seq.end();
while (cit != last) {
const ex &subsed_ex = cit->rest.subs(m, options);
#define DCOUT2(str,var) cout << #str << ": " << var << endl
ostream& operator<<(ostream& o, const vector<int>& v)
{
- vector<int>::const_iterator i = v.begin(), end = v.end();
+ auto i = v.begin(), end = v.end();
while ( i != end ) {
- o << *i++ << " ";
+ o << *i << " ";
+ ++i;
}
return o;
}
static ostream& operator<<(ostream& o, const vector<cl_I>& v)
{
- vector<cl_I>::const_iterator i = v.begin(), end = v.end();
+ auto i = v.begin(), end = v.end();
while ( i != end ) {
o << *i << "[" << i-v.begin() << "]" << " ";
++i;
}
static ostream& operator<<(ostream& o, const vector<cl_MI>& v)
{
- vector<cl_MI>::const_iterator i = v.begin(), end = v.end();
+ auto i = v.begin(), end = v.end();
while ( i != end ) {
o << *i << "[" << i-v.begin() << "]" << " ";
++i;
}
ostream& operator<<(ostream& o, const vector< vector<cl_MI> >& v)
{
- vector< vector<cl_MI> >::const_iterator i = v.begin(), end = v.end();
+ auto i = v.begin(), end = v.end();
while ( i != end ) {
o << i-v.begin() << ": " << *i << endl;
++i;
if ( a.empty() ) return;
cl_modint_ring R = a[0].ring();
- umodpoly::iterator i = a.begin(), end = a.end();
- for ( ; i!=end; ++i ) {
+ for (auto & i : a) {
// cln cannot perform this division in the modular field
- cl_I c = R->retract(*i);
- *i = cl_MI(R, the<cl_I>(c / x));
+ cl_I c = R->retract(i);
+ i = cl_MI(R, the<cl_I>(c / x));
}
}
}
factors.push_back(g);
size = 0;
- list<umodpoly>::const_iterator i = factors.begin(), end = factors.end();
- while ( i != end ) {
- if ( degree(*i) ) ++size;
- ++i;
+ for (auto & i : factors) {
+ if (degree(i))
+ ++size;
}
if ( size == k ) {
- list<umodpoly>::const_iterator i = factors.begin(), end = factors.end();
- while ( i != end ) {
- upv.push_back(*i++);
+ for (auto & i : factors) {
+ upv.push_back(i);
}
return;
}
d2 = r2;
}
cl_MI fac = recip(lcoeff(a) * lcoeff(c));
- umodpoly::iterator i = s.begin(), end = s.end();
- for ( ; i!=end; ++i ) {
- *i = *i * fac;
+ for (auto & i : s) {
+ i = i * fac;
}
canonicalize(s);
fac = recip(lcoeff(b) * lcoeff(c));
- i = t.begin(), end = t.end();
- for ( ; i!=end; ++i ) {
- *i = *i * fac;
+ for (auto & i : t) {
+ i = i * fac;
}
canonicalize(t);
}
if ( primes.size() == 0 ) {
primes.push_back(3); primes.push_back(5); primes.push_back(7);
}
- vector<unsigned int>::const_iterator it = primes.begin();
if ( p >= primes.back() ) {
unsigned int candidate = primes.back() + 2;
while ( true ) {
}
return candidate;
}
- vector<unsigned int>::const_iterator end = primes.end();
- for ( ; it!=end; ++it ) {
- if ( *it > p ) {
- return *it;
+ for (auto & it : primes) {
+ if ( it > p ) {
+ return it;
}
}
throw logic_error("next_prime: should not reach this point!");
}
else {
upvec newfactors1(part.size_left()), newfactors2(part.size_right());
- upvec::iterator i1 = newfactors1.begin(), i2 = newfactors2.begin();
+ auto i1 = newfactors1.begin(), i2 = newfactors2.begin();
for ( size_t i=0; i<n; ++i ) {
if ( part[i] ) {
*i2++ = tocheck.top().factors[i];
{
if ( a.empty() ) return;
cl_modint_ring oldR = a[0].ring();
- umodpoly::iterator i = a.begin(), end = a.end();
- for ( ; i!=end; ++i ) {
- *i = R->canonhom(oldR->retract(*i));
+ for (auto & i : a) {
+ i = R->canonhom(oldR->retract(i));
}
canonicalize(a);
}
return poly;
}
lst syms;
- exset::const_iterator i=findsymbols.syms.begin(), end=findsymbols.syms.end();
- for ( ; i!=end; ++i ) {
- syms.append(*i);
+ for (auto & i : findsymbols.syms ) {
+ syms.append(i);
}
// make poly square free
std::string s;
if (n.find_string("name", s)) {
unsigned int ser = 0;
- std::vector<function_options>::const_iterator i = registered_functions().begin(), iend = registered_functions().end();
- while (i != iend) {
- if (s == i->name) {
+ for (auto & it : registered_functions()) {
+ if (s == it.name) {
serial = ser;
return;
}
- ++i; ++ser;
+ ++ser;
}
throw (std::runtime_error("unknown function '" + s + "' in archive"));
} else
else {
eseq.reserve(seq.size());
--level;
- exvector::const_iterator it = seq.begin(), itend = seq.end();
- while (it != itend) {
- eseq.push_back(it->evalf(level));
- ++it;
+ for (auto & it : seq) {
+ eseq.push_back(it.evalf(level));
}
}
* Throws exception if function was not found. */
unsigned function::find_function(const std::string &name, unsigned nparams)
{
- std::vector<function_options>::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end();
unsigned serial = 0;
- while (i != end) {
- if (i->get_name() == name && i->get_nparams() == nparams)
+ for (auto & it : function::registered_functions()) {
+ if (it.get_name() == name && it.get_nparams() == nparams)
return serial;
- ++i;
++serial;
}
throw (std::runtime_error("no function '" + name + "' with " + ToString(nparams) + " parameters defined"));
{
if (seq.size() > 1) {
- exvector::const_iterator it=seq.begin() + 1, itend = seq.end();
+ auto it = seq.begin() + 1, itend = seq.end();
if (is_a<print_latex>(c)) {
void indexed::validate() const
{
GINAC_ASSERT(seq.size() > 0);
- exvector::const_iterator it = seq.begin() + 1, itend = seq.end();
+ auto it = seq.begin() + 1, itend = seq.end();
while (it != itend) {
if (!is_a<idx>(*it))
throw(std::invalid_argument("indices of indexed object must be of type idx"));
bool indexed::has_dummy_index_for(const ex & i) const
{
- exvector::const_iterator it = seq.begin() + 1, itend = seq.end();
+ auto it = seq.begin() + 1, itend = seq.end();
while (it != itend) {
if (is_dummy_pair(*it, i))
return true;
template<class T> size_t number_of_type(const exvector&v)
{
size_t number = 0;
- for(exvector::const_iterator i=v.begin(); i!=v.end(); ++i)
- if(is_exactly_a<T>(*i))
+ for (auto & it : v)
+ if (is_exactly_a<T>(it))
++number;
return number;
}
// to the global set
size_t old_global_size = global_size;
int remaining = local_size - global_size;
- exvector::const_iterator it = local_dummy_indices.begin(), itend = local_dummy_indices.end();
+ auto it = local_dummy_indices.begin(), itend = local_dummy_indices.end();
while (it != itend && remaining > 0) {
if (is_exactly_a<T>(*it) && find_if(global_dummy_indices.begin(), global_dummy_indices.end(), bind2nd(idx_is_equal_ignore_dim(), *it)) == global_dummy_indices.end()) {
global_dummy_indices.push_back(*it);
for (size_t j=i+1; j<e.nops(); ++j) {
if (is_dummy_pair(e.op(i), e.op(j))) {
local_var_dummies.push_back(e.op(i));
- for (exvector::iterator k = variant_dummy_indices.begin();
- k!=variant_dummy_indices.end(); ++k) {
+ for (auto k = variant_dummy_indices.begin(); k!=variant_dummy_indices.end(); ++k) {
if (e.op(i).op(0) == k->op(0)) {
variant_dummy_indices.erase(k);
break;
// If a dummy index is encountered for the first time in the
// product, pull it up, otherwise, pull it down
- for (exvector::iterator it2 = seq.begin()+1, it2end = seq.end();
- it2 != it2end; ++it2) {
+ for (auto it2 = seq.begin()+1, it2end = seq.end(); it2 != it2end; ++it2) {
if (!is_exactly_a<varidx>(*it2))
continue;
template<class T> ex idx_symmetrization(const ex& r,const exvector& local_dummy_indices)
{ exvector dummy_syms;
dummy_syms.reserve(r.nops());
- for (exvector::const_iterator it = local_dummy_indices.begin(); it != local_dummy_indices.end(); ++it)
- if(is_exactly_a<T>(*it))
- dummy_syms.push_back(it->op(0));
+ for (auto & it : local_dummy_indices)
+ if(is_exactly_a<T>(it))
+ dummy_syms.push_back(it.op(0));
if(dummy_syms.size() < 2)
return r;
ex q=symmetrize(r, dummy_syms);
const ex & term = sum.op(i);
exvector dummy_indices_of_term;
dummy_indices_of_term.reserve(dummy_indices.size());
- for(exvector::iterator i=dummy_indices.begin(); i!=dummy_indices.end(); ++i)
- if(hasindex(term,i->op(0)))
- dummy_indices_of_term.push_back(*i);
+ for (auto & i : dummy_indices)
+ if (hasindex(term,i.op(0)))
+ dummy_indices_of_term.push_back(i);
ex term_symm = idx_symmetrization<idx>(term, dummy_indices_of_term);
term_symm = idx_symmetrization<varidx>(term_symm, dummy_indices_of_term);
term_symm = idx_symmetrization<spinidx>(term_symm, dummy_indices_of_term);
std::vector<terminfo> terms_pass2;
for (std::vector<terminfo>::const_iterator i=terms.begin(); i!=terms.end(); ) {
size_t num = 1;
- std::vector<terminfo>::const_iterator j = i + 1;
+ auto j = i + 1;
while (j != terms.end() && j->symm == i->symm) {
num++;
j++;
// Chop the symmetrized terms into subterms
std::vector<symminfo> sy;
- for (std::vector<terminfo>::const_iterator i=terms_pass2.begin(); i!=terms_pass2.end(); ++i) {
- if (is_exactly_a<add>(i->symm)) {
- size_t num = i->symm.nops();
+ for (auto & i : terms_pass2) {
+ if (is_exactly_a<add>(i.symm)) {
+ size_t num = i.symm.nops();
for (size_t j=0; j<num; j++)
- sy.push_back(symminfo(i->symm.op(j), i->orig, num));
+ sy.push_back(symminfo(i.symm.op(j), i.orig, num));
} else
- sy.push_back(symminfo(i->symm, i->orig, 1));
+ sy.push_back(symminfo(i.symm, i.orig, 1));
}
// Sort by symmetrized subterms
// Combine equal symmetrized subterms
std::vector<symminfo> sy_pass2;
exvector result;
- for (std::vector<symminfo>::const_iterator i=sy.begin(); i!=sy.end(); ) {
+ for (auto i=sy.begin(); i!=sy.end(); ) {
// Combine equal terms
- std::vector<symminfo>::const_iterator j = i + 1;
+ auto j = i + 1;
if (j != sy.end() && j->symmterm == i->symmterm) {
// More than one term, collect the coefficients
// How many symmetrized terms of this original term are left?
size_t num = 1;
- std::vector<symminfo>::const_iterator j = i + 1;
+ auto j = i + 1;
while (j != sy_pass2.end() && j->orig == i->orig) {
num++;
j++;
void scalar_products::add_vectors(const lst & l, const ex & dim)
{
// Add all possible pairs of products
- for (lst::const_iterator it1 = l.begin(); it1 != l.end(); ++it1)
- for (lst::const_iterator it2 = l.begin(); it2 != l.end(); ++it2)
- add(*it1, *it2, *it1 * *it2);
+ for (auto & it1 : l)
+ for (auto & it2 : l)
+ add(it1, it2, it1 * it2);
}
void scalar_products::clear()
void scalar_products::debugprint() const
{
std::cerr << "map size=" << spm.size() << std::endl;
- spmap::const_iterator i = spm.begin(), end = spm.end();
- while (i != end) {
- const spmapkey & k = i->first;
+ for (auto & it : spm) {
+ const spmapkey & k = it.first;
std::cerr << "item key=";
k.debugprint();
- std::cerr << ", value=" << i->second << std::endl;
- ++i;
+ std::cerr << ", value=" << it.second << std::endl;
}
}
exvector p;
bool nc;
product_to_exvector(e, p, nc);
- exvector::const_iterator ip = p.begin(), ipend = p.end();
+ auto ip = p.begin(), ipend = p.end();
exvector v, v1;
while (ip != ipend) {
if (is_a<indexed>(*ip)) {
v1 = ex_to<indexed>(*ip).get_dummy_indices();
v.insert(v.end(), v1.begin(), v1.end());
- exvector::const_iterator ip1 = ip+1;
+ auto ip1 = ip + 1;
while (ip1 != ipend) {
if (is_a<indexed>(*ip1)) {
v1 = ex_to<indexed>(*ip).get_dummy_indices(ex_to<indexed>(*ip1));
lst indices_subs = rename_dummy_indices_uniquely(va, vb);
if (indices_subs.op(0).nops() > 0) {
if (modify_va) {
- for (lst::const_iterator i = ex_to<lst>(indices_subs.op(1)).begin(); i != ex_to<lst>(indices_subs.op(1)).end(); ++i)
- va.push_back(*i);
+ for (auto & i : ex_to<lst>(indices_subs.op(1)))
+ va.push_back(i);
exvector uncommon_indices;
set_difference(vb.begin(), vb.end(), indices_subs.op(0).begin(), indices_subs.op(0).end(), std::back_insert_iterator<exvector>(uncommon_indices), ex_is_less());
- exvector::const_iterator ip = uncommon_indices.begin(), ipend = uncommon_indices.end();
- while (ip != ipend) {
- va.push_back(*ip);
- ++ip;
- }
+ for (auto & ip : uncommon_indices)
+ va.push_back(ip);
sort(va.begin(), va.end(), ex_is_less());
}
return b.subs(ex_to<lst>(indices_subs.op(0)), ex_to<lst>(indices_subs.op(1)), subs_options::no_pattern|subs_options::no_index_renaming);
else
v = get_all_dummy_indices(e_expanded);
ex result = e_expanded;
- for(exvector::const_iterator it=v.begin(); it!=v.end(); ++it) {
- ex nu = *it;
+ for (const auto & nu : v) {
if (ex_to<idx>(nu).get_dim().info(info_flags::nonnegint)) {
int idim = ex_to<numeric>(ex_to<idx>(nu).get_dim()).to_int();
ex en = 0;
setflag(status_flags::not_shareable);
size_t i = 0;
- for (lst::const_iterator it = l.begin(); it != l.end(); ++it, ++i) {
+ for (auto & it : l) {
size_t x = i % c;
size_t y = i / c;
if (y >= r)
break; // matrix smaller than list: throw away excessive elements
- m[y*c+x] = *it;
+ m[y*c+x] = it;
+ ++i;
}
}
m.reserve(row * col);
// XXX: default ctor inserts a zero element, we need to erase it here.
m.pop_back();
- archive_node::archive_node_cit first = n.find_first("m");
- archive_node::archive_node_cit last = n.find_last("m");
+ auto first = n.find_first("m");
+ auto last = n.find_last("m");
++last;
- for (archive_node::archive_node_cit i=first; i != last; ++i) {
+ for (auto i=first; i != last; ++i) {
ex e;
n.find_ex_by_loc(i, e, sym_lst);
m.push_back(e);
inherited::archive(n);
n.add_unsigned("row", row);
n.add_unsigned("col", col);
- exvector::const_iterator i = m.begin(), iend = m.end();
- while (i != iend) {
- n.add_ex("m", *i);
- ++i;
+ for (auto & i : m) {
+ n.add_ex("m", i);
}
}
for (unsigned c=0; c<col; ++c)
m2[r*col+c] = m[r*col+c].eval(level);
- return (new matrix(row, col, m2))->setflag(status_flags::dynallocated |
- status_flags::evaluated);
+ return (new matrix(row, col, std::move(m2)))->setflag(status_flags::dynallocated |
+ status_flags::evaluated);
}
ex matrix::subs(const exmap & mp, unsigned options) const
for (unsigned c=0; c<col; ++c)
m2[r*col+c] = m[r*col+c].subs(mp, options);
- return matrix(row, col, m2).subs_one_level(mp, options);
+ return matrix(row, col, std::move(m2)).subs_one_level(mp, options);
}
/** Complex conjugate every matrix entry. */
ex matrix::conjugate() const
{
- exvector * ev = 0;
- for (exvector::const_iterator i=m.begin(); i!=m.end(); ++i) {
+ std::unique_ptr<exvector> ev(nullptr);
+ for (auto i=m.begin(); i!=m.end(); ++i) {
ex x = i->conjugate();
if (ev) {
ev->push_back(x);
if (are_ex_trivially_equal(x, *i)) {
continue;
}
- ev = new exvector;
+ ev.reset(new exvector);
ev->reserve(m.size());
- for (exvector::const_iterator j=m.begin(); j!=i; ++j) {
+ for (auto j=m.begin(); j!=i; ++j) {
ev->push_back(*j);
}
ev->push_back(x);
}
if (ev) {
- ex result = matrix(row, col, *ev);
- delete ev;
- return result;
+ return matrix(row, col, std::move(*ev));
}
return *this;
}
{
exvector v;
v.reserve(m.size());
- for (exvector::const_iterator i=m.begin(); i!=m.end(); ++i)
- v.push_back(i->real_part());
- return matrix(row, col, v);
+ for (auto & i : m)
+ v.push_back(i.real_part());
+ return matrix(row, col, std::move(v));
}
ex matrix::imag_part() const
{
exvector v;
v.reserve(m.size());
- for (exvector::const_iterator i=m.begin(); i!=m.end(); ++i)
- v.push_back(i->imag_part());
- return matrix(row, col, v);
+ for (auto & i : m)
+ v.push_back(i.imag_part());
+ return matrix(row, col, std::move(v));
}
// protected
throw std::logic_error("matrix::add(): incompatible matrices");
exvector sum(this->m);
- exvector::iterator i = sum.begin(), end = sum.end();
- exvector::const_iterator ci = other.m.begin();
- while (i != end)
- *i++ += *ci++;
+ auto ci = other.m.begin();
+ for (auto & i : sum)
+ i += *ci++;
- return matrix(row,col,sum);
+ return matrix(row, col, std::move(sum));
}
throw std::logic_error("matrix::sub(): incompatible matrices");
exvector dif(this->m);
- exvector::iterator i = dif.begin(), end = dif.end();
- exvector::const_iterator ci = other.m.begin();
- while (i != end)
- *i++ -= *ci++;
+ auto ci = other.m.begin();
+ for (auto & i : dif)
+ i -= *ci++;
- return matrix(row,col,dif);
+ return matrix(row, col, std::move(dif));
}
prod[r1*other.col+r2] += (m[r1*col+c] * other.m[c*other.col+r2]);
}
}
- return matrix(row, other.col, prod);
+ return matrix(row, other.col, std::move(prod));
}
for (unsigned c=0; c<col; ++c)
prod[r*col+c] = m[r*col+c] * other;
- return matrix(row, col, prod);
+ return matrix(row, col, std::move(prod));
}
for (unsigned c=0; c<col; ++c)
prod[r*col+c] = m[r*col+c] * other;
- return matrix(row, col, prod);
+ return matrix(row, col, std::move(prod));
}
for (unsigned c=0; c<this->rows(); ++c)
trans[r*this->rows()+c] = m[c*this->cols()+r];
- return matrix(this->cols(),this->rows(),trans);
+ return matrix(this->cols(), this->rows(), std::move(trans));
}
/** Determinant of square matrix. This routine doesn't actually calculate the
bool numeric_flag = true;
bool normal_flag = false;
unsigned sparse_count = 0; // counts non-zero elements
- exvector::const_iterator r = m.begin(), rend = m.end();
- while (r != rend) {
- if (!r->info(info_flags::numeric))
+ for (auto r : m) {
+ if (!r.info(info_flags::numeric))
numeric_flag = false;
exmap srl; // symbol replacement list
- ex rtest = r->to_rational(srl);
+ ex rtest = r.to_rational(srl);
if (!rtest.is_zero())
++sparse_count;
if (!rtest.info(info_flags::crational_polynomial) &&
- rtest.info(info_flags::rational_function))
+ rtest.info(info_flags::rational_function))
normal_flag = true;
- ++r;
}
// Here is the heuristics in case this routine has to decide:
}
std::sort(c_zeros.begin(),c_zeros.end());
std::vector<unsigned> pre_sort;
- for (std::vector<uintpair>::const_iterator i=c_zeros.begin(); i!=c_zeros.end(); ++i)
- pre_sort.push_back(i->second);
+ for (auto & i : c_zeros)
+ pre_sort.push_back(i.second);
std::vector<unsigned> pre_sort_test(pre_sort); // permutation_sign() modifies the vector so we make a copy here
int sign = permutation_sign(pre_sort_test.begin(), pre_sort_test.end());
exvector result(row*col); // represents sorted matrix
unsigned c = 0;
- for (std::vector<unsigned>::const_iterator i=pre_sort.begin();
- i!=pre_sort.end();
- ++i,++c) {
+ for (auto & it : pre_sort) {
for (unsigned r=0; r<row; ++r)
- result[r*col+c] = m[r*col+(*i)];
+ result[r*col+c] = m[r*col+it];
+ ++c;
}
if (normal_flag)
- return (sign*matrix(row,col,result).determinant_minor()).normal();
+ return (sign*matrix(row, col, std::move(result)).determinant_minor()).normal();
else
- return sign*matrix(row,col,result).determinant_minor();
+ return sign*matrix(row, col, std::move(result)).determinant_minor();
}
}
}
throw (std::logic_error("matrix::charpoly(): matrix not square"));
bool numeric_flag = true;
- exvector::const_iterator r = m.begin(), rend = m.end();
- while (r!=rend && numeric_flag==true) {
- if (!r->info(info_flags::numeric))
+ for (auto & r : m) {
+ if (!r.info(info_flags::numeric)) {
numeric_flag = false;
- ++r;
+ break;
+ }
}
// The pure numeric case is traditionally rather common. Hence, it is
// Gather some statistical information about the augmented matrix:
bool numeric_flag = true;
- exvector::const_iterator r = aug.m.begin(), rend = aug.m.end();
- while (r!=rend && numeric_flag==true) {
- if (!r->info(info_flags::numeric))
+ for (auto & r : aug.m) {
+ if (!r.info(info_flags::numeric)) {
numeric_flag = false;
- ++r;
+ break;
+ }
}
// Here is the heuristics in case this routine has to decide:
matrix tmp_n(*this);
matrix tmp_d(m,n); // for denominators, if needed
exmap srl; // symbol replacement list
- exvector::const_iterator cit = this->m.begin(), citend = this->m.end();
- exvector::iterator tmp_n_it = tmp_n.m.begin(), tmp_d_it = tmp_d.m.begin();
- while (cit != citend) {
- ex nd = cit->normal().to_rational(srl).numer_denom();
- ++cit;
+ auto tmp_n_it = tmp_n.m.begin(), tmp_d_it = tmp_d.m.begin();
+ for (auto & it : this->m) {
+ ex nd = it.normal().to_rational(srl).numer_denom();
*tmp_n_it++ = nd.op(0);
*tmp_d_it++ = nd.op(1);
}
}
// repopulate *this matrix:
- exvector::iterator it = this->m.begin(), itend = this->m.end();
tmp_n_it = tmp_n.m.begin();
tmp_d_it = tmp_d.m.begin();
- while (it != itend)
- *it++ = ((*tmp_n_it++)/(*tmp_d_it++)).subs(srl, subs_options::no_pattern);
+ for (auto & it : this->m)
+ it = ((*tmp_n_it++)/(*tmp_d_it++)).subs(srl, subs_options::no_pattern);
return sign;
}
*/
bool matrix::is_zero_matrix() const
{
- for (exvector::const_iterator i=m.begin(); i!=m.end(); ++i)
- if(!(i->is_zero()))
+ for (auto & i : m)
+ if (!i.is_zero())
return false;
return true;
}
ex lst_to_matrix(const lst & l)
{
- lst::const_iterator itr, itc;
-
// Find number of rows and columns
size_t rows = l.nops(), cols = 0;
- for (itr = l.begin(); itr != l.end(); ++itr) {
- if (!is_a<lst>(*itr))
+ for (auto & itr : l) {
+ if (!is_a<lst>(itr))
throw (std::invalid_argument("lst_to_matrix: argument must be a list of lists"));
- if (itr->nops() > cols)
- cols = itr->nops();
+ if (itr.nops() > cols)
+ cols = itr.nops();
}
// Allocate and fill matrix
matrix &M = *new matrix(rows, cols);
M.setflag(status_flags::dynallocated);
- unsigned i;
- for (itr = l.begin(), i = 0; itr != l.end(); ++itr, ++i) {
- unsigned j;
- for (itc = ex_to<lst>(*itr).begin(), j = 0; itc != ex_to<lst>(*itr).end(); ++itc, ++j)
- M(i, j) = *itc;
+ unsigned i = 0;
+ for (auto & itr : l) {
+ unsigned j = 0;
+ for (auto & itc : ex_to<lst>(itr)) {
+ M(i, j) = itc;
+ ++j;
+ }
+ ++i;
}
return M;
ex diag_matrix(const lst & l)
{
- lst::const_iterator it;
size_t dim = l.nops();
// Allocate and fill matrix
matrix &M = *new matrix(dim, dim);
M.setflag(status_flags::dynallocated);
- unsigned i;
- for (it = l.begin(), i = 0; it != l.end(); ++it, ++i)
- M(i, i) = *it;
+ unsigned i = 0;
+ for (auto & it : l) {
+ M(i, i) = it;
+ ++i;
+ }
return M;
}
print_overall_coeff(c, "*");
- epvector::const_iterator it = seq.begin(), itend = seq.end();
bool first = true;
- while (it != itend) {
+ for (auto & it : seq) {
if (!first)
c.s << '*';
else
first = false;
- recombine_pair_to_ex(*it).print(c, precedence());
- ++it;
+ recombine_pair_to_ex(it).print(c, precedence());
}
if (precedence() <= level)
// Separate factors into those with negative numeric exponent
// and all others
- epvector::const_iterator it = seq.begin(), itend = seq.end();
exvector neg_powers, others;
- while (it != itend) {
- GINAC_ASSERT(is_exactly_a<numeric>(it->coeff));
- if (ex_to<numeric>(it->coeff).is_negative())
- neg_powers.push_back(recombine_pair_to_ex(expair(it->rest, -(it->coeff))));
+ for (auto & it : seq) {
+ GINAC_ASSERT(is_exactly_a<numeric>(it.coeff));
+ if (ex_to<numeric>(it.coeff).is_negative())
+ neg_powers.push_back(recombine_pair_to_ex(expair(it.rest, -it.coeff)));
else
- others.push_back(recombine_pair_to_ex(*it));
- ++it;
+ others.push_back(recombine_pair_to_ex(it));
}
if (!neg_powers.empty()) {
} else {
// All other factors are printed in the ordinary way
- exvector::const_iterator vit = others.begin(), vitend = others.end();
- while (vit != vitend) {
+ for (auto & vit : others) {
c.s << ' ';
- vit->print(c, precedence());
- ++vit;
+ vit.print(c, precedence());
}
}
}
// Print arguments, separated by "*" or "/"
- epvector::const_iterator it = seq.begin(), itend = seq.end();
+ auto it = seq.begin(), itend = seq.end();
while (it != itend) {
// If the first argument is a negative integer power, it gets printed as "1.0/<expr>"
if (it->coeff.is_equal(_ex1) || it->coeff.is_equal(_ex_1))
it->rest.print(c, precedence());
else if (it->coeff.info(info_flags::negint))
- // Outer parens around ex needed for broken GCC parser:
- (ex(power(it->rest, -ex_to<numeric>(it->coeff)))).print(c, level);
+ ex(power(it->rest, -ex_to<numeric>(it->coeff))).print(c, level);
else
- // Outer parens around ex needed for broken GCC parser:
- (ex(power(it->rest, ex_to<numeric>(it->coeff)))).print(c, level);
+ ex(power(it->rest, ex_to<numeric>(it->coeff))).print(c, level);
if (needclosingparenthesis)
c.s << ")";
case info_flags::even:
case info_flags::crational_polynomial:
case info_flags::rational_function: {
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- if (!(recombine_pair_to_ex(*i).info(inf)))
+ for (auto & it : seq) {
+ if (!recombine_pair_to_ex(it).info(inf))
return false;
- ++i;
}
if (overall_coeff.is_equal(*_num1_p) && inf == info_flags::even)
return true;
return overall_coeff.info(inf);
}
case info_flags::algebraic: {
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- if ((recombine_pair_to_ex(*i).info(inf)))
+ for (auto & it : seq) {
+ if (recombine_pair_to_ex(it).info(inf))
return true;
- ++i;
}
return false;
}
return false;
bool pos = true;
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- const ex& factor = recombine_pair_to_ex(*i++);
+ for (auto & it : seq) {
+ const ex& factor = recombine_pair_to_ex(it);
if (factor.info(info_flags::positive))
continue;
else if (factor.info(info_flags::negative))
if (flags & status_flags::is_positive)
return true;
bool pos = true;
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- const ex& factor = recombine_pair_to_ex(*i++);
+ for (auto & it : seq) {
+ const ex& factor = recombine_pair_to_ex(it);
if (factor.info(info_flags::nonnegative) || factor.info(info_flags::positive))
continue;
else if (factor.info(info_flags::negative))
case info_flags::posint:
case info_flags::negint: {
bool pos = true;
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- const ex& factor = recombine_pair_to_ex(*i++);
+ for (auto & it : seq) {
+ const ex& factor = recombine_pair_to_ex(it);
if (factor.info(info_flags::posint))
continue;
else if (factor.info(info_flags::negint))
}
case info_flags::nonnegint: {
bool pos = true;
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- const ex& factor = recombine_pair_to_ex(*i++);
+ for (auto & it : seq) {
+ const ex& factor = recombine_pair_to_ex(it);
if (factor.info(info_flags::nonnegint) || factor.info(info_flags::posint))
continue;
else if (factor.info(info_flags::negint))
return true;
if (flags & (status_flags::is_positive | status_flags::is_negative))
return false;
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- const ex& term = recombine_pair_to_ex(*i);
+ for (auto & it : seq) {
+ const ex& term = recombine_pair_to_ex(it);
if (term.info(info_flags::positive) || term.info(info_flags::negative))
return false;
- ++i;
}
setflag(status_flags::purely_indefinite);
return true;
bool mul::is_polynomial(const ex & var) const
{
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
- if (!i->rest.is_polynomial(var) ||
- (i->rest.has(var) && !i->coeff.info(info_flags::nonnegint))) {
+ for (auto & it : seq) {
+ if (!it.rest.is_polynomial(var) ||
+ (it.rest.has(var) && !it.coeff.info(info_flags::nonnegint))) {
return false;
}
}
{
// Sum up degrees of factors
int deg_sum = 0;
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- if (ex_to<numeric>(i->coeff).is_integer())
- deg_sum += recombine_pair_to_ex(*i).degree(s);
+ for (auto & it : seq) {
+ if (ex_to<numeric>(it.coeff).is_integer())
+ deg_sum += recombine_pair_to_ex(it).degree(s);
else {
- if (i->rest.has(s))
+ if (it.rest.has(s))
throw std::runtime_error("mul::degree() undefined degree because of non-integer exponent");
}
- ++i;
}
return deg_sum;
}
{
// Sum up degrees of factors
int deg_sum = 0;
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- if (ex_to<numeric>(i->coeff).is_integer())
- deg_sum += recombine_pair_to_ex(*i).ldegree(s);
+ for (auto & it : seq) {
+ if (ex_to<numeric>(it.coeff).is_integer())
+ deg_sum += recombine_pair_to_ex(it).ldegree(s);
else {
- if (i->rest.has(s))
+ if (it.rest.has(s))
throw std::runtime_error("mul::ldegree() undefined degree because of non-integer exponent");
}
- ++i;
}
return deg_sum;
}
if (n==0) {
// product of individual coeffs
// if a non-zero power of s is found, the resulting product will be 0
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- coeffseq.push_back(recombine_pair_to_ex(*i).coeff(s,n));
- ++i;
- }
+ for (auto & it : seq)
+ coeffseq.push_back(recombine_pair_to_ex(it).coeff(s,n));
coeffseq.push_back(overall_coeff);
return (new mul(coeffseq))->setflag(status_flags::dynallocated);
}
- epvector::const_iterator i = seq.begin(), end = seq.end();
bool coeff_found = false;
- while (i != end) {
- ex t = recombine_pair_to_ex(*i);
+ for (auto & it : seq) {
+ ex t = recombine_pair_to_ex(it);
ex c = t.coeff(s, n);
if (!c.is_zero()) {
coeffseq.push_back(c);
} else {
coeffseq.push_back(t);
}
- ++i;
}
if (coeff_found) {
coeffseq.push_back(overall_coeff);
const add & addref = ex_to<add>((*seq.begin()).rest);
epvector distrseq;
distrseq.reserve(addref.seq.size());
- epvector::const_iterator i = addref.seq.begin(), end = addref.seq.end();
- while (i != end) {
- distrseq.push_back(addref.combine_pair_with_coeff_to_pair(*i, overall_coeff));
- ++i;
+ for (auto & it : addref.seq) {
+ distrseq.push_back(addref.combine_pair_with_coeff_to_pair(it, overall_coeff));
}
return (new add(std::move(distrseq),
ex_to<numeric>(addref.overall_coeff).
// Strip the content and the unit part from each term. Thus
// things like (-x+a)*(3*x-3*a) automagically turn into - 3*(x-a)^2
- epvector::const_iterator last = seq.end();
- epvector::const_iterator i = seq.begin();
- epvector::const_iterator j = seq.begin();
+ auto i = seq.begin(), last = seq.end();
+ auto j = seq.begin();
epvector s;
numeric oc = *_num1_p;
bool something_changed = false;
s.reserve(seq.size());
--level;
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- s.push_back(combine_ex_with_coeff_to_pair(i->rest.evalf(level),
- i->coeff));
- ++i;
+ for (auto & it : seq) {
+ s.push_back(combine_ex_with_coeff_to_pair(it.rest.evalf(level),
+ it.coeff));
}
return mul(std::move(s), overall_coeff.evalf(level));
}
{
rp = overall_coeff.real_part();
ip = overall_coeff.imag_part();
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
- ex factor = recombine_pair_to_ex(*i);
+ for (auto & it : seq) {
+ ex factor = recombine_pair_to_ex(it);
ex new_rp = factor.real_part();
ex new_ip = factor.imag_part();
- if(new_ip.is_zero()) {
+ if (new_ip.is_zero()) {
rp *= new_rp;
ip *= new_rp;
} else {
bool have_matrix = false;
epvector::iterator the_matrix;
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- const ex &m = recombine_pair_to_ex(*i).evalm();
+ for (auto & it : seq) {
+ const ex &m = recombine_pair_to_ex(it).evalm();
s.push_back(split_ex_to_pair(m));
if (is_a<matrix>(m)) {
have_matrix = true;
the_matrix = s.end() - 1;
}
- ++i;
}
if (have_matrix) {
return inherited::eval_ncmul(v);
// Find first noncommutative element and call its eval_ncmul()
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- if (i->rest.return_type() == return_types::noncommutative)
- return i->rest.eval_ncmul(v);
- ++i;
- }
+ for (auto & it : seq)
+ if (it.rest.return_type() == return_types::noncommutative)
+ return it.rest.eval_ncmul(v);
return inherited::eval_ncmul(v);
}
ex divide_by = 1;
ex multiply_by = 1;
- for (exmap::const_iterator it = m.begin(); it != m.end(); ++it) {
+ for (auto & it : m) {
- if (is_exactly_a<mul>(it->first)) {
+ if (is_exactly_a<mul>(it.first)) {
retry1:
int nummatches = std::numeric_limits<int>::max();
std::vector<bool> currsubsed(nops(), false);
exmap repls;
- if(!algebraic_match_mul_with_mul(*this, it->first, repls, 0, nummatches, subsed, currsubsed))
+ if (!algebraic_match_mul_with_mul(*this, it.first, repls, 0, nummatches, subsed, currsubsed))
continue;
for (size_t j=0; j<subsed.size(); j++)
if (currsubsed[j])
subsed[j] = true;
ex subsed_pattern
- = it->first.subs(repls, subs_options::no_pattern);
+ = it.first.subs(repls, subs_options::no_pattern);
divide_by *= power(subsed_pattern, nummatches);
ex subsed_result
- = it->second.subs(repls, subs_options::no_pattern);
+ = it.second.subs(repls, subs_options::no_pattern);
multiply_by *= power(subsed_result, nummatches);
goto retry1;
for (size_t j=0; j<this->nops(); j++) {
int nummatches = std::numeric_limits<int>::max();
exmap repls;
- if (!subsed[j] && tryfactsubs(op(j), it->first, nummatches, repls)){
+ if (!subsed[j] && tryfactsubs(op(j), it.first, nummatches, repls)){
subsed[j] = true;
ex subsed_pattern
- = it->first.subs(repls, subs_options::no_pattern);
+ = it.first.subs(repls, subs_options::no_pattern);
divide_by *= power(subsed_pattern, nummatches);
ex subsed_result
- = it->second.subs(repls, subs_options::no_pattern);
+ = it.second.subs(repls, subs_options::no_pattern);
multiply_by *= power(subsed_result, nummatches);
}
}
{
// The base class' method is wrong here because we have to be careful at
// branch cuts. power::conjugate takes care of that already, so use it.
- epvector *newepv = 0;
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+ std::unique_ptr<epvector> newepv(nullptr);
+ for (auto i=seq.begin(); i!=seq.end(); ++i) {
if (newepv) {
newepv->push_back(split_ex_to_pair(recombine_pair_to_ex(*i).conjugate()));
continue;
if (c.is_equal(x)) {
continue;
}
- newepv = new epvector;
+ newepv.reset(new epvector);
newepv->reserve(seq.size());
- for (epvector::const_iterator j=seq.begin(); j!=i; ++j) {
+ for (auto j=seq.begin(); j!=i; ++j) {
newepv->push_back(*j);
}
newepv->push_back(split_ex_to_pair(c));
if (!newepv && are_ex_trivially_equal(x, overall_coeff)) {
return *this;
}
- ex result = thisexpairseq(newepv ? *newepv : seq, x);
- delete newepv;
- return result;
+ return thisexpairseq(newepv ? std::move(*newepv) : seq, x);
}
// D(a*b*c) = D(a)*b*c + a*D(b)*c + a*b*D(c)
epvector mulseq = seq;
- epvector::const_iterator i = seq.begin(), end = seq.end();
- epvector::iterator i2 = mulseq.begin();
+ auto i = seq.begin(), end = seq.end();
+ auto i2 = mulseq.begin();
while (i != end) {
expair ep = split_ex_to_pair(power(i->rest, i->coeff - _ex1) *
i->rest.diff(s));
return make_return_type_t<mul>(); // mul without factors: should not happen
// return type_info of first noncommutative element
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- if (i->rest.return_type() == return_types::noncommutative)
- return i->rest.return_type_tinfo();
- ++i;
- }
+ for (auto & it : seq)
+ if (it.rest.return_type() == return_types::noncommutative)
+ return it.rest.return_type_tinfo();
+
// no noncommutative element found, should not happen
return make_return_type_t<mul>();
}
bool mul::can_be_further_expanded(const ex & e)
{
if (is_exactly_a<mul>(e)) {
- for (epvector::const_iterator cit = ex_to<mul>(e).seq.begin(); cit != ex_to<mul>(e).seq.end(); ++cit) {
- if (is_exactly_a<add>(cit->rest) && cit->coeff.info(info_flags::posint))
+ for (auto & it : ex_to<mul>(e).seq) {
+ if (is_exactly_a<add>(it.rest) && it.coeff.info(info_flags::posint))
return true;
}
} else if (is_exactly_a<power>(e)) {
epvector non_adds;
non_adds.reserve(expanded_seq.size());
- for (epvector::const_iterator cit = expanded_seq.begin(); cit != expanded_seq.end(); ++cit) {
- if (is_exactly_a<add>(cit->rest) &&
- (cit->coeff.is_equal(_ex1))) {
+ for (const auto & cit : expanded_seq) {
+ if (is_exactly_a<add>(cit.rest) &&
+ (cit.coeff.is_equal(_ex1))) {
if (is_exactly_a<add>(last_expanded)) {
// Expand a product of two sums, aggressive version.
// Caring for the overall coefficients in separate loops can
// sometimes give a performance gain of up to 15%!
- const int sizedifference = ex_to<add>(last_expanded).seq.size()-ex_to<add>(cit->rest).seq.size();
+ const int sizedifference = ex_to<add>(last_expanded).seq.size()-ex_to<add>(cit.rest).seq.size();
// add2 is for the inner loop and should be the bigger of the two sums
// in the presence of asymptotically good sorting:
- const add& add1 = (sizedifference<0 ? ex_to<add>(last_expanded) : ex_to<add>(cit->rest));
- const add& add2 = (sizedifference<0 ? ex_to<add>(cit->rest) : ex_to<add>(last_expanded));
- const epvector::const_iterator add1begin = add1.seq.begin();
- const epvector::const_iterator add1end = add1.seq.end();
- const epvector::const_iterator add2begin = add2.seq.begin();
- const epvector::const_iterator add2end = add2.seq.end();
+ const add& add1 = (sizedifference<0 ? ex_to<add>(last_expanded) : ex_to<add>(cit.rest));
+ const add& add2 = (sizedifference<0 ? ex_to<add>(cit.rest) : ex_to<add>(last_expanded));
epvector distrseq;
distrseq.reserve(add1.seq.size()+add2.seq.size());
// Multiply add2 with the overall coefficient of add1 and append it to distrseq:
if (!add1.overall_coeff.is_zero()) {
if (add1.overall_coeff.is_equal(_ex1))
- distrseq.insert(distrseq.end(),add2begin,add2end);
+ distrseq.insert(distrseq.end(), add2.seq.begin(), add2.seq.end());
else
- for (epvector::const_iterator i=add2begin; i!=add2end; ++i)
- distrseq.push_back(expair(i->rest, ex_to<numeric>(i->coeff).mul_dyn(ex_to<numeric>(add1.overall_coeff))));
+ for (const auto & i : add2.seq)
+ distrseq.push_back(expair(i.rest, ex_to<numeric>(i.coeff).mul_dyn(ex_to<numeric>(add1.overall_coeff))));
}
// Multiply add1 with the overall coefficient of add2 and append it to distrseq:
if (!add2.overall_coeff.is_zero()) {
if (add2.overall_coeff.is_equal(_ex1))
- distrseq.insert(distrseq.end(),add1begin,add1end);
+ distrseq.insert(distrseq.end(), add1.seq.begin(), add1.seq.end());
else
- for (epvector::const_iterator i=add1begin; i!=add1end; ++i)
- distrseq.push_back(expair(i->rest, ex_to<numeric>(i->coeff).mul_dyn(ex_to<numeric>(add2.overall_coeff))));
+ for (const auto & i : add1.seq)
+ distrseq.push_back(expair(i.rest, ex_to<numeric>(i.coeff).mul_dyn(ex_to<numeric>(add2.overall_coeff))));
}
// Compute the new overall coefficient and put it together:
lst dummy_subs;
if (!skip_idx_rename) {
- for (epvector::const_iterator i=add1begin; i!=add1end; ++i) {
- add_indices = get_all_dummy_indices_safely(i->rest);
+ for (const auto & i : add1.seq) {
+ add_indices = get_all_dummy_indices_safely(i.rest);
add1_dummy_indices.insert(add1_dummy_indices.end(), add_indices.begin(), add_indices.end());
}
- for (epvector::const_iterator i=add2begin; i!=add2end; ++i) {
- add_indices = get_all_dummy_indices_safely(i->rest);
+ for (const auto & i : add2.seq) {
+ add_indices = get_all_dummy_indices_safely(i.rest);
add2_dummy_indices.insert(add2_dummy_indices.end(), add_indices.begin(), add_indices.end());
}
}
// Multiply explicitly all non-numeric terms of add1 and add2:
- for (epvector::const_iterator i2=add2begin; i2!=add2end; ++i2) {
+ for (const auto & i2 : add2.seq) {
// We really have to combine terms here in order to compactify
// the result. Otherwise it would become waayy tooo bigg.
numeric oc(*_num0_p);
epvector distrseq2;
distrseq2.reserve(add1.seq.size());
const ex i2_new = (skip_idx_rename || (dummy_subs.op(0).nops() == 0) ?
- i2->rest :
- i2->rest.subs(ex_to<lst>(dummy_subs.op(0)),
- ex_to<lst>(dummy_subs.op(1)), subs_options::no_pattern));
- for (epvector::const_iterator i1=add1begin; i1!=add1end; ++i1) {
+ i2.rest :
+ i2.rest.subs(ex_to<lst>(dummy_subs.op(0)),
+ ex_to<lst>(dummy_subs.op(1)), subs_options::no_pattern));
+ for (const auto & i1 : add1.seq) {
// Don't push_back expairs which might have a rest that evaluates to a numeric,
// since that would violate an invariant of expairseq:
- const ex rest = (new mul(i1->rest, i2_new))->setflag(status_flags::dynallocated);
+ const ex rest = (new mul(i1.rest, i2_new))->setflag(status_flags::dynallocated);
if (is_exactly_a<numeric>(rest)) {
- oc += ex_to<numeric>(rest).mul(ex_to<numeric>(i1->coeff).mul(ex_to<numeric>(i2->coeff)));
+ oc += ex_to<numeric>(rest).mul(ex_to<numeric>(i1.coeff).mul(ex_to<numeric>(i2.coeff)));
} else {
- distrseq2.push_back(expair(rest, ex_to<numeric>(i1->coeff).mul_dyn(ex_to<numeric>(i2->coeff))));
+ distrseq2.push_back(expair(rest, ex_to<numeric>(i1.coeff).mul_dyn(ex_to<numeric>(i2.coeff))));
}
}
tmp_accu += (new add(distrseq2, oc))->setflag(status_flags::dynallocated);
- }
+ }
last_expanded = tmp_accu;
} else {
if (!last_expanded.is_equal(_ex1))
non_adds.push_back(split_ex_to_pair(last_expanded));
- last_expanded = cit->rest;
+ last_expanded = cit.rest;
}
} else {
- non_adds.push_back(*cit);
+ non_adds.push_back(cit);
}
}
* had to be changed. */
epvector mul::expandchildren(unsigned options) const
{
- const epvector::const_iterator last = seq.end();
- epvector::const_iterator cit = seq.begin();
+ auto cit = seq.begin(), last = seq.end();
while (cit!=last) {
const ex & factor = recombine_pair_to_ex(*cit);
const ex & expanded_factor = factor.expand(options);
s.reserve(seq.size());
// copy parts of seq which are known not to have changed
- epvector::const_iterator cit2 = seq.begin();
+ auto cit2 = seq.begin();
while (cit2!=cit) {
s.push_back(*cit2);
++cit2;
size_t number_of_expanded_terms = 1;
size_t current_position = 0;
- exvector::const_iterator last = expanded_seq.end();
- for (exvector::const_iterator cit=expanded_seq.begin(); cit!=last; ++cit) {
- if (is_exactly_a<add>(*cit)) {
+ for (auto & it : expanded_seq) {
+ if (is_exactly_a<add>(it)) {
positions_of_adds[number_of_adds] = current_position;
- size_t num_ops = cit->nops();
+ size_t num_ops = it.nops();
number_of_add_operands[number_of_adds] = num_ops;
number_of_expanded_terms *= num_ops;
number_of_adds++;
// Sum up degrees of factors
int deg_sum = 0;
- exvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- deg_sum += i->degree(s);
- ++i;
- }
+ for (auto & i : seq)
+ deg_sum += i.degree(s);
return deg_sum;
}
// Sum up degrees of factors
int deg_sum = 0;
- exvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- deg_sum += i->degree(s);
- ++i;
- }
+ for (auto & i : seq)
+ deg_sum += i.degree(s);
return deg_sum;
}
if (n == 0) {
// product of individual coeffs
// if a non-zero power of s is found, the resulting product will be 0
- exvector::const_iterator it=seq.begin();
- while (it!=seq.end()) {
- coeffseq.push_back((*it).coeff(s,n));
- ++it;
- }
- return (new ncmul(coeffseq,1))->setflag(status_flags::dynallocated);
+ for (auto & it : seq)
+ coeffseq.push_back(it.coeff(s,n));
+ return (new ncmul(std::move(coeffseq),1))->setflag(status_flags::dynallocated);
}
- exvector::const_iterator i = seq.begin(), end = seq.end();
bool coeff_found = false;
- while (i != end) {
- ex c = i->coeff(s,n);
+ for (auto & i : seq) {
+ ex c = i.coeff(s,n);
if (c.is_zero()) {
- coeffseq.push_back(*i);
+ coeffseq.push_back(i);
} else {
coeffseq.push_back(c);
coeff_found = true;
}
- ++i;
}
- if (coeff_found) return (new ncmul(coeffseq,1))->setflag(status_flags::dynallocated);
+ if (coeff_found)
+ return (new ncmul(std::move(coeffseq), 1))->setflag(status_flags::dynallocated);
return _ex0;
}
// ncmul(...,*(x1,x2),...,ncmul(x3,x4),...) ->
// ncmul(...,x1,x2,...,x3,x4,...) (associativity)
size_t factors = 0;
- exvector::const_iterator cit = evaledseq.begin(), citend = evaledseq.end();
- while (cit != citend)
- factors += count_factors(*cit++);
+ for (auto & it : evaledseq)
+ factors += count_factors(it);
exvector assocseq;
assocseq.reserve(factors);
- cit = evaledseq.begin();
make_flat_inserter mf(evaledseq, true);
- while (cit != citend)
- { ex factor = mf.handle_factor(*(cit++), 1);
+ for (auto & it : evaledseq) {
+ ex factor = mf.handle_factor(it, 1);
append_factors(assocseq, factor);
}
size_t count_commutative=0;
size_t count_noncommutative=0;
size_t count_noncommutative_composite=0;
- cit = assocseq.begin(); citend = assocseq.end();
- while (cit != citend) {
- rettypes[i] = cit->return_type();
+ for (auto & it : assocseq) {
+ rettypes[i] = it.return_type();
switch (rettypes[i]) {
case return_types::commutative:
count_commutative++;
default:
throw(std::logic_error("ncmul::eval(): invalid return type"));
}
- ++i; ++cit;
+ ++i;
}
GINAC_ASSERT(count_commutative+count_noncommutative+count_noncommutative_composite==assocseq.size());
evv.reserve(assoc_num);
rttinfos.reserve(assoc_num);
- cit = assocseq.begin(), citend = assocseq.end();
- while (cit != citend) {
- return_type_t ti = cit->return_type_tinfo();
+ for (auto & it : assocseq) {
+ return_type_t ti = it.return_type_tinfo();
size_t rtt_num = rttinfos.size();
// search type in vector of known types
for (i=0; i<rtt_num; ++i) {
if(ti == rttinfos[i]) {
- evv[i].push_back(*cit);
+ evv[i].push_back(it);
break;
}
}
rttinfos.push_back(ti);
evv.push_back(exvector());
(evv.end()-1)->reserve(assoc_num);
- (evv.end()-1)->push_back(*cit);
+ (evv.end()-1)->push_back(it);
}
- ++cit;
}
size_t evv_num = evv.size();
// Evaluate children first
exvector s;
s.reserve(seq.size());
- exvector::const_iterator it = seq.begin(), itend = seq.end();
- while (it != itend) {
- s.push_back(it->evalm());
- it++;
- }
+ for (auto & it : seq)
+ s.push_back(it.evalm());
// If there are only matrices, simply multiply them
- it = s.begin(); itend = s.end();
+ auto it = s.begin(), itend = s.end();
if (is_a<matrix>(*it)) {
matrix prod(ex_to<matrix>(*it));
it++;
exvector ev;
ev.reserve(nops());
- for (const_iterator i=end(); i!=begin();) {
+ for (auto i=end(); i!=begin();) {
--i;
ev.push_back(i->conjugate());
}
- return (new ncmul(ev, true))->setflag(status_flags::dynallocated).eval();
+ return (new ncmul(std::move(ev), true))->setflag(status_flags::dynallocated).eval();
}
ex ncmul::real_part() const
return make_return_type_t<ncmul>();
// return type_info of first noncommutative element
- exvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- if (i->return_type() == return_types::noncommutative)
- return i->return_type_tinfo();
- ++i;
- }
+ for (auto & i : seq)
+ if (i.return_type() == return_types::noncommutative)
+ return i.return_type_tinfo();
// no noncommutative element found, should not happen
return make_return_type_t<ncmul>();
exvector ncmul::expandchildren(unsigned options) const
{
- const_iterator cit = this->seq.begin(), end = this->seq.end();
+ auto cit = this->seq.begin(), end = this->seq.end();
while (cit != end) {
const ex & expanded_ex = cit->expand(options);
if (!are_ex_trivially_equal(*cit, expanded_ex)) {
// Add symbol the sym_desc_vec (used internally by get_symbol_stats())
static void add_symbol(const ex &s, sym_desc_vec &v)
{
- sym_desc_vec::const_iterator it = v.begin(), itend = v.end();
- while (it != itend) {
- if (it->sym.is_equal(s)) // If it's already in there, don't add it a second time
+ for (auto & it : v)
+ if (it.sym.is_equal(s)) // If it's already in there, don't add it a second time
return;
- ++it;
- }
+
sym_desc d;
d.sym = s;
v.push_back(d);
{
collect_symbols(a.eval(), v); // eval() to expand assigned symbols
collect_symbols(b.eval(), v);
- sym_desc_vec::iterator it = v.begin(), itend = v.end();
- while (it != itend) {
- int deg_a = a.degree(it->sym);
- int deg_b = b.degree(it->sym);
- it->deg_a = deg_a;
- it->deg_b = deg_b;
- it->max_deg = std::max(deg_a, deg_b);
- it->max_lcnops = std::max(a.lcoeff(it->sym).nops(), b.lcoeff(it->sym).nops());
- it->ldeg_a = a.ldegree(it->sym);
- it->ldeg_b = b.ldegree(it->sym);
- ++it;
+ for (auto & it : v) {
+ int deg_a = a.degree(it.sym);
+ int deg_b = b.degree(it.sym);
+ it.deg_a = deg_a;
+ it.deg_b = deg_b;
+ it.max_deg = std::max(deg_a, deg_b);
+ it.max_lcnops = std::max(a.lcoeff(it.sym).nops(), b.lcoeff(it.sym).nops());
+ it.ldeg_a = a.ldegree(it.sym);
+ it.ldeg_b = b.ldegree(it.sym);
}
std::sort(v.begin(), v.end());
numeric add::integer_content() const
{
- epvector::const_iterator it = seq.begin();
- epvector::const_iterator itend = seq.end();
numeric c = *_num0_p, l = *_num1_p;
- while (it != itend) {
- GINAC_ASSERT(!is_exactly_a<numeric>(it->rest));
- GINAC_ASSERT(is_exactly_a<numeric>(it->coeff));
- c = gcd(ex_to<numeric>(it->coeff).numer(), c);
- l = lcm(ex_to<numeric>(it->coeff).denom(), l);
- it++;
+ for (auto & it : seq) {
+ GINAC_ASSERT(!is_exactly_a<numeric>(it.rest));
+ GINAC_ASSERT(is_exactly_a<numeric>(it.coeff));
+ c = gcd(ex_to<numeric>(it.coeff).numer(), c);
+ l = lcm(ex_to<numeric>(it.coeff).denom(), l);
}
GINAC_ASSERT(is_exactly_a<numeric>(overall_coeff));
c = gcd(ex_to<numeric>(overall_coeff).numer(), c);
numeric mul::integer_content() const
{
#ifdef DO_GINAC_ASSERT
- epvector::const_iterator it = seq.begin();
- epvector::const_iterator itend = seq.end();
- while (it != itend) {
- GINAC_ASSERT(!is_exactly_a<numeric>(recombine_pair_to_ex(*it)));
- ++it;
+ for (auto & it : seq) {
+ GINAC_ASSERT(!is_exactly_a<numeric>(recombine_pair_to_ex(it)));
}
#endif // def DO_GINAC_ASSERT
GINAC_ASSERT(is_exactly_a<numeric>(overall_coeff));
if (is_exactly_a<mul>(b)) {
ex qbar = a;
- for (const_iterator itrb = b.begin(); itrb != b.end(); ++itrb) {
+ for (const auto & it : b) {
sym_desc_vec sym_stats;
- get_symbol_stats(a, *itrb, sym_stats);
- if (!divide_in_z(qbar, *itrb, q, sym_stats.begin()))
+ get_symbol_stats(a, it, sym_stats);
+ if (!divide_in_z(qbar, it, q, sym_stats.begin()))
return false;
qbar = q;
numeric add::max_coefficient() const
{
- epvector::const_iterator it = seq.begin();
- epvector::const_iterator itend = seq.end();
GINAC_ASSERT(is_exactly_a<numeric>(overall_coeff));
numeric cur_max = abs(ex_to<numeric>(overall_coeff));
- while (it != itend) {
+ for (auto & it : seq) {
numeric a;
- GINAC_ASSERT(!is_exactly_a<numeric>(it->rest));
- a = abs(ex_to<numeric>(it->coeff));
+ GINAC_ASSERT(!is_exactly_a<numeric>(it.rest));
+ a = abs(ex_to<numeric>(it.coeff));
if (a > cur_max)
cur_max = a;
- it++;
}
return cur_max;
}
numeric mul::max_coefficient() const
{
#ifdef DO_GINAC_ASSERT
- epvector::const_iterator it = seq.begin();
- epvector::const_iterator itend = seq.end();
- while (it != itend) {
- GINAC_ASSERT(!is_exactly_a<numeric>(recombine_pair_to_ex(*it)));
- it++;
+ for (auto & it : seq) {
+ GINAC_ASSERT(!is_exactly_a<numeric>(recombine_pair_to_ex(it)));
}
#endif // def DO_GINAC_ASSERT
GINAC_ASSERT(is_exactly_a<numeric>(overall_coeff));
{
epvector newseq;
newseq.reserve(seq.size()+1);
- epvector::const_iterator it = seq.begin();
- epvector::const_iterator itend = seq.end();
- while (it != itend) {
- GINAC_ASSERT(!is_exactly_a<numeric>(it->rest));
- numeric coeff = GiNaC::smod(ex_to<numeric>(it->coeff), xi);
+ for (auto & it : seq) {
+ GINAC_ASSERT(!is_exactly_a<numeric>(it.rest));
+ numeric coeff = GiNaC::smod(ex_to<numeric>(it.coeff), xi);
if (!coeff.is_zero())
- newseq.push_back(expair(it->rest, coeff));
- it++;
+ newseq.push_back(expair(it.rest, coeff));
}
GINAC_ASSERT(is_exactly_a<numeric>(overall_coeff));
numeric coeff = GiNaC::smod(ex_to<numeric>(overall_coeff), xi);
ex mul::smod(const numeric &xi) const
{
#ifdef DO_GINAC_ASSERT
- epvector::const_iterator it = seq.begin();
- epvector::const_iterator itend = seq.end();
- while (it != itend) {
- GINAC_ASSERT(!is_exactly_a<numeric>(recombine_pair_to_ex(*it)));
- it++;
+ for (auto & it : seq) {
+ GINAC_ASSERT(!is_exactly_a<numeric>(recombine_pair_to_ex(it)));
}
#endif // def DO_GINAC_ASSERT
mul * mulcopyp = new mul(*this);
if (l.nops()==0) {
sym_desc_vec sdv;
get_symbol_stats(a, _ex0, sdv);
- sym_desc_vec::const_iterator it = sdv.begin(), itend = sdv.end();
- while (it != itend) {
- args.append(it->sym);
- ++it;
- }
+ for (auto & it : sdv)
+ args.append(it.sym);
} else {
args = l;
}
// recurse down the factors in remaining variables
if (newargs.nops()>0) {
- exvector::iterator i = factors.begin();
- while (i != factors.end()) {
- *i = sqrfree(*i, newargs);
- ++i;
- }
+ for (auto & it : factors)
+ it = sqrfree(it, newargs);
}
// Done with recursion, now construct the final result
ex result = _ex1;
- exvector::const_iterator it = factors.begin(), itend = factors.end();
- for (int p = 1; it!=itend; ++it, ++p)
- result *= power(*it, p);
+ int p = 1;
+ for (auto & it : factors)
+ result *= power(it, p++);
// Yun's algorithm does not account for constant factors. (For univariate
// polynomials it works only in the monic case.) We can correct this by
ex e_replaced = e.subs(repl, subs_options::no_pattern);
// Expression already replaced? Then return the assigned symbol
- exmap::const_iterator it = rev_lookup.find(e_replaced);
+ auto it = rev_lookup.find(e_replaced);
if (it != rev_lookup.end())
return it->second;
ex e_replaced = e.subs(repl, subs_options::no_pattern);
// Expression already replaced? Then return the assigned symbol
- for (exmap::const_iterator it = repl.begin(); it != repl.end(); ++it)
- if (it->second.is_equal(e_replaced))
- return it->first;
+ for (auto & it : repl)
+ if (it.second.is_equal(e_replaced))
+ return it.first;
// Otherwise create new symbol and add to list, taking care that the
// replacement expression doesn't itself contain symbols from repl,
exvector nums, dens;
nums.reserve(seq.size()+1);
dens.reserve(seq.size()+1);
- epvector::const_iterator it = seq.begin(), itend = seq.end();
- while (it != itend) {
- ex n = ex_to<basic>(recombine_pair_to_ex(*it)).normal(repl, rev_lookup, level-1);
+ for (auto & it : seq) {
+ ex n = ex_to<basic>(recombine_pair_to_ex(it)).normal(repl, rev_lookup, level-1);
nums.push_back(n.op(0));
dens.push_back(n.op(1));
- it++;
}
ex n = ex_to<numeric>(overall_coeff).normal(repl, rev_lookup, level-1);
nums.push_back(n.op(0));
//std::clog << "add::normal uses " << nums.size() << " summands:\n";
// Add fractions sequentially
- exvector::const_iterator num_it = nums.begin(), num_itend = nums.end();
- exvector::const_iterator den_it = dens.begin(), den_itend = dens.end();
+ auto num_it = nums.begin(), num_itend = nums.end();
+ auto den_it = dens.begin(), den_itend = dens.end();
//std::clog << " num = " << *num_it << ", den = " << *den_it << std::endl;
ex num = *num_it++, den = *den_it++;
while (num_it != num_itend) {
exvector num; num.reserve(seq.size());
exvector den; den.reserve(seq.size());
ex n;
- epvector::const_iterator it = seq.begin(), itend = seq.end();
- while (it != itend) {
- n = ex_to<basic>(recombine_pair_to_ex(*it)).normal(repl, rev_lookup, level-1);
+ for (auto & it : seq) {
+ n = ex_to<basic>(recombine_pair_to_ex(it)).normal(repl, rev_lookup, level-1);
num.push_back(n.op(0));
den.push_back(n.op(1));
- it++;
}
n = ex_to<numeric>(overall_coeff).normal(repl, rev_lookup, level-1);
num.push_back(n.op(0));
ex pseries::normal(exmap & repl, exmap & rev_lookup, int level) const
{
epvector newseq;
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- ex restexp = i->rest.normal();
+ for (auto & it : seq) {
+ ex restexp = it.rest.normal();
if (!restexp.is_zero())
- newseq.push_back(expair(restexp, i->coeff));
- ++i;
+ newseq.push_back(expair(restexp, it.coeff));
}
- ex n = pseries(relational(var,point), newseq);
+ ex n = pseries(relational(var,point), std::move(newseq));
return (new lst(replace_with_symbol(n, repl, rev_lookup), _ex1))->setflag(status_flags::dynallocated);
}
{
// Convert lst to exmap
exmap m;
- for (lst::const_iterator it = repl_lst.begin(); it != repl_lst.end(); ++it)
- m.insert(std::make_pair(it->op(0), it->op(1)));
+ for (auto & it : repl_lst)
+ m.insert(std::make_pair(it.op(0), it.op(1)));
ex ret = bp->to_rational(m);
// Convert exmap back to lst
repl_lst.remove_all();
- for (exmap::const_iterator it = m.begin(); it != m.end(); ++it)
- repl_lst.append(it->first == it->second);
+ for (auto & it : m)
+ repl_lst.append(it.first == it.second);
return ret;
}
{
// Convert lst to exmap
exmap m;
- for (lst::const_iterator it = repl_lst.begin(); it != repl_lst.end(); ++it)
- m.insert(std::make_pair(it->op(0), it->op(1)));
+ for (auto & it : repl_lst)
+ m.insert(std::make_pair(it.op(0), it.op(1)));
ex ret = bp->to_polynomial(m);
// Convert exmap back to lst
repl_lst.remove_all();
- for (exmap::const_iterator it = m.begin(); it != m.end(); ++it)
- repl_lst.append(it->first == it->second);
+ for (auto & it : m)
+ repl_lst.append(it.first == it.second);
return ret;
}
{
epvector s;
s.reserve(seq.size());
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- s.push_back(split_ex_to_pair(recombine_pair_to_ex(*i).to_rational(repl)));
- ++i;
- }
+ for (auto & it : seq)
+ s.push_back(split_ex_to_pair(recombine_pair_to_ex(it).to_rational(repl)));
+
ex oc = overall_coeff.to_rational(repl);
if (oc.info(info_flags::numeric))
return thisexpairseq(std::move(s), overall_coeff);
{
epvector s;
s.reserve(seq.size());
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- s.push_back(split_ex_to_pair(recombine_pair_to_ex(*i).to_polynomial(repl)));
- ++i;
- }
+ for (auto & it : seq)
+ s.push_back(split_ex_to_pair(recombine_pair_to_ex(it).to_polynomial(repl)));
+
ex oc = overall_coeff.to_polynomial(repl);
if (oc.info(info_flags::numeric))
return thisexpairseq(std::move(s), overall_coeff);
cln::default_float_format = cln::float_format(prec);
// call registered callbacks
- std::vector<digits_changed_callback>::const_iterator it = callbacklist.begin(), end = callbacklist.end();
- for (; it != end; ++it) {
- (*it)(digitsdiff);
+ for (auto it : callbacklist) {
+ (it)(digitsdiff);
}
return *this;
reader[make_pair("pow", 2)] = pow_reader;
reader[make_pair("power", 2)] = power_reader;
reader[make_pair("lst", 0)] = lst_reader;
- std::vector<function_options>::const_iterator it =
- registered_functions_hack::get_registered_functions().begin();
- std::vector<function_options>::const_iterator end =
- registered_functions_hack::get_registered_functions().end();
unsigned serial = 0;
- for (; it != end; ++it) {
- prototype proto = make_pair(it->get_name(), it->get_nparams());
+ for (auto & it : registered_functions_hack::get_registered_functions()) {
+ prototype proto = make_pair(it.get_name(), it.get_nparams());
reader[proto] = encode_serial_as_reader_func(serial);
++serial;
}
}
}
-GiNaC::ex
-ex_collect_to_ex(const ex_collect_t& ec, const GiNaC::exvector& vars)
+ex
+ex_collect_to_ex(const ex_collect_t& ec, const exvector& vars)
{
exvector ev;
ev.reserve(ec.size());
static inline bool operator<(const exp_vector_t& v1, const exp_vector_t& v2)
{
return std::lexicographical_compare(v1.rbegin(), v1.rend(),
- v2.rbegin(), v2.rend());
+ v2.rbegin(), v2.rend());
}
static inline bool operator>(const exp_vector_t& v1, const exp_vector_t& v2)
static inline bool zerop(const exp_vector_t& v)
{
- for (exp_vector_t::const_reverse_iterator i = v.rbegin(); i != v.rend(); ++i) {
- if (*i != 0)
+ for (auto & i : v) {
+ if (i != 0)
return false;
}
return true;
// Add symbol the sym_desc_vec (used internally by get_symbol_stats())
static void add_symbol(const ex &s, sym_desc_vec &v)
{
- sym_desc_vec::const_iterator it = v.begin(), itend = v.end();
- while (it != itend) {
- if (it->sym.is_equal(s)) // If it's already in there, don't add it a second time
+ for (auto & it : v) {
+ if (it.sym.is_equal(s)) // If it's already in there, don't add it a second time
return;
- ++it;
}
sym_desc d;
d.sym = s;
{
collect_symbols(a, v);
collect_symbols(b, v);
- sym_desc_vec::iterator it = v.begin(), itend = v.end();
- while (it != itend) {
- int deg_a = a.degree(it->sym);
- int deg_b = b.degree(it->sym);
- it->deg_a = deg_a;
- it->deg_b = deg_b;
- it->max_deg = std::max(deg_a, deg_b);
- it->max_lcnops = std::max(a.lcoeff(it->sym).nops(), b.lcoeff(it->sym).nops());
- it->ldeg_a = a.ldegree(it->sym);
- it->ldeg_b = b.ldegree(it->sym);
- ++it;
+ for (auto & it : v) {
+ int deg_a = a.degree(it.sym);
+ int deg_b = b.degree(it.sym);
+ it.deg_a = deg_a;
+ it.deg_b = deg_b;
+ it.max_deg = std::max(deg_a, deg_b);
+ it.max_lcnops = std::max(a.lcoeff(it.sym).nops(), b.lcoeff(it.sym).nops());
+ it.ldeg_a = a.ldegree(it.sym);
+ it.ldeg_b = b.ldegree(it.sym);
}
std::sort(v.begin(), v.end());
}
addp->setflag(status_flags::dynallocated);
addp->clearflag(status_flags::hash_calculated);
addp->overall_coeff = ex_to<numeric>(addp->overall_coeff).div_dyn(icont);
- for (epvector::iterator i = addp->seq.begin(); i != addp->seq.end(); ++i)
- i->coeff = ex_to<numeric>(i->coeff).div_dyn(icont);
+ for (auto & i : addp->seq)
+ i.coeff = ex_to<numeric>(i.coeff).div_dyn(icont);
const numeric c = icont.power(*num_exponent);
if (likely(c != *_num1_p))
if (!(options & subs_options::algebraic))
return subs_one_level(m, options);
- for (exmap::const_iterator it = m.begin(); it != m.end(); ++it) {
+ for (auto & it : m) {
int nummatches = std::numeric_limits<int>::max();
exmap repls;
- if (tryfactsubs(*this, it->first, nummatches, repls)) {
- ex anum = it->second.subs(repls, subs_options::no_pattern);
- ex aden = it->first.subs(repls, subs_options::no_pattern);
+ if (tryfactsubs(*this, it.first, nummatches, repls)) {
+ ex anum = it.second.subs(repls, subs_options::no_pattern);
+ ex aden = it.first.subs(repls, subs_options::no_pattern);
ex result = (*this)*power(anum/aden, nummatches);
return (ex_to<basic>(result)).subs_one_level(m, options);
}
epvector powseq;
prodseq.reserve(m.seq.size() + 1);
powseq.reserve(m.seq.size() + 1);
- epvector::const_iterator last = m.seq.end();
- epvector::const_iterator cit = m.seq.begin();
bool possign = true;
// search for positive/negative factors
- while (cit!=last) {
- ex e=m.recombine_pair_to_ex(*cit);
+ for (auto & cit : m.seq) {
+ ex e=m.recombine_pair_to_ex(cit);
if (e.info(info_flags::positive))
prodseq.push_back(pow(e, exponent).expand(options));
else if (e.info(info_flags::negative)) {
prodseq.push_back(pow(-e, exponent).expand(options));
possign = !possign;
} else
- powseq.push_back(*cit);
- ++cit;
+ powseq.push_back(cit);
}
// take care on the numeric coefficient
const add &a = ex_to<add>(expanded_exponent);
exvector distrseq;
distrseq.reserve(a.seq.size() + 1);
- epvector::const_iterator last = a.seq.end();
- epvector::const_iterator cit = a.seq.begin();
- while (cit!=last) {
- distrseq.push_back(power(expanded_basis, a.recombine_pair_to_ex(*cit)));
- ++cit;
+ for (auto & cit : a.seq) {
+ distrseq.push_back(power(expanded_basis, a.recombine_pair_to_ex(cit)));
}
// Make sure that e.g. (x+y)^(2+a) expands the (x+y)^2 factor
element *head, *i, *after_i;
// NB: Partition must be sorted in non-decreasing order.
explicit coolmulti(const std::vector<int>& partition)
+ : head(nullptr), i(nullptr), after_i(nullptr)
{
- head = nullptr;
for (unsigned n = 0; n < partition.size(); ++n) {
head = new element(partition[n], head);
if (n <= 1)
multinomial_coefficient(const std::vector<int> p)
{
numeric n = 0, d = 1;
- std::vector<int>::const_iterator it = p.begin(), itend = p.end();
- while (it != itend) {
- n += numeric(*it);
- d *= factorial(numeric(*it));
- ++it;
+ for (auto & it : p) {
+ n += numeric(it);
+ d *= factorial(numeric(it));
}
return factorial(numeric(n)) / d;
}
distrseq.reserve(m.seq.size());
bool need_reexpand = false;
- epvector::const_iterator last = m.seq.end();
- epvector::const_iterator cit = m.seq.begin();
- while (cit!=last) {
- expair p = m.combine_pair_with_coeff_to_pair(*cit, n);
- if (from_expand && is_exactly_a<add>(cit->rest) && ex_to<numeric>(p.coeff).is_pos_integer()) {
+ for (auto & cit : m.seq) {
+ expair p = m.combine_pair_with_coeff_to_pair(cit, n);
+ if (from_expand && is_exactly_a<add>(cit.rest) && ex_to<numeric>(p.coeff).is_pos_integer()) {
// this happens when e.g. (a+b)^(1/2) gets squared and
// the resulting product needs to be reexpanded
need_reexpand = true;
}
distrseq.push_back(p);
- ++cit;
}
const mul & result = static_cast<const mul &>((new mul(distrseq, ex_to<numeric>(m.overall_coeff).power_dyn(n)))->setflag(status_flags::dynallocated));
void pseries::read_archive(const archive_node &n, lst &sym_lst)
{
inherited::read_archive(n, sym_lst);
- archive_node::archive_node_cit first = n.find_first("coeff");
- archive_node::archive_node_cit last = n.find_last("power");
+ auto first = n.find_first("coeff");
+ auto last = n.find_last("power");
++last;
seq.reserve((last-first)/2);
- for (archive_node::archive_node_cit loc = first; loc < last;) {
+ for (auto loc = first; loc < last;) {
ex rest;
ex coeff;
n.find_ex_by_loc(loc++, rest, sym_lst);
void pseries::archive(archive_node &n) const
{
inherited::archive(n);
- epvector::const_iterator i = seq.begin(), iend = seq.end();
- while (i != iend) {
- n.add_ex("coeff", i->rest);
- n.add_ex("power", i->coeff);
- ++i;
+ for (auto & it : seq) {
+ n.add_ex("coeff", it.rest);
+ n.add_ex("power", it.coeff);
}
n.add_ex("var", var);
n.add_ex("point", point);
if (seq.empty())
c.s << '0';
- epvector::const_iterator i = seq.begin(), end = seq.end();
+ auto i = seq.begin(), end = seq.end();
while (i != end) {
// print a sign, if needed
new_seq.push_back(expair(it->rest.eval(level-1), it->coeff));
++it;
}
- return (new pseries(relational(var,point), new_seq))->setflag(status_flags::dynallocated | status_flags::evaluated);
+ return (new pseries(relational(var,point), std::move(new_seq)))->setflag(status_flags::dynallocated | status_flags::evaluated);
}
/** Evaluate coefficients numerically. */
new_seq.push_back(expair(it->rest.evalf(level-1), it->coeff));
++it;
}
- return (new pseries(relational(var,point), new_seq))->setflag(status_flags::dynallocated | status_flags::evaluated);
+ return (new pseries(relational(var,point), std::move(new_seq)))->setflag(status_flags::dynallocated | status_flags::evaluated);
}
ex pseries::conjugate() const
if(!var.info(info_flags::real))
return conjugate_function(*this).hold();
- epvector * newseq = conjugateepvector(seq);
+ std::unique_ptr<epvector> newseq(conjugateepvector(seq));
ex newpoint = point.conjugate();
if (!newseq && are_ex_trivially_equal(point, newpoint)) {
return *this;
}
- ex result = (new pseries(var==newpoint, newseq ? *newseq : seq))->setflag(status_flags::dynallocated);
- delete newseq;
- return result;
+ return (new pseries(var==newpoint, newseq ? std::move(*newseq) : seq))->setflag(status_flags::dynallocated);
}
ex pseries::real_part() const
epvector v;
v.reserve(seq.size());
- for(epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
- v.push_back(expair((i->rest).real_part(), i->coeff));
- return (new pseries(var==point, v))->setflag(status_flags::dynallocated);
+ for (auto & it : seq)
+ v.push_back(expair((it.rest).real_part(), it.coeff));
+ return (new pseries(var==point, std::move(v)))->setflag(status_flags::dynallocated);
}
ex pseries::imag_part() const
epvector v;
v.reserve(seq.size());
- for(epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
- v.push_back(expair((i->rest).imag_part(), i->coeff));
- return (new pseries(var==point, v))->setflag(status_flags::dynallocated);
+ for (auto & it : seq)
+ v.push_back(expair((it.rest).imag_part(), it.coeff));
+ return (new pseries(var==point, std::move(v)))->setflag(status_flags::dynallocated);
}
ex pseries::eval_integ() const
{
epvector *newseq = nullptr;
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+ for (auto i=seq.begin(); i!=seq.end(); ++i) {
if (newseq) {
newseq->push_back(expair(i->rest.eval_integ(), i->coeff));
continue;
if (!are_ex_trivially_equal(newterm, i->rest)) {
newseq = new epvector;
newseq->reserve(seq.size());
- for (epvector::const_iterator j=seq.begin(); j!=i; ++j)
+ for (auto j=seq.begin(); j!=i; ++j)
newseq->push_back(*j);
newseq->push_back(expair(newterm, i->coeff));
}
// evalm each coefficient
epvector newseq;
bool something_changed = false;
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+ for (auto i=seq.begin(); i!=seq.end(); ++i) {
if (something_changed) {
ex newcoeff = i->rest.evalm();
if (!newcoeff.is_zero())
}
}
if (something_changed)
- return (new pseries(var==point, newseq))->setflag(status_flags::dynallocated);
+ return (new pseries(var==point, std::move(newseq)))->setflag(status_flags::dynallocated);
else
return *this;
}
// expansion point
epvector newseq;
newseq.reserve(seq.size());
- epvector::const_iterator it = seq.begin(), itend = seq.end();
- while (it != itend) {
- newseq.push_back(expair(it->rest.subs(m, options), it->coeff));
- ++it;
- }
+ for (auto & it : seq)
+ newseq.push_back(expair(it.rest.subs(m, options), it.coeff));
return (new pseries(relational(var,point.subs(m, options)), newseq))->setflag(status_flags::dynallocated);
}
ex pseries::expand(unsigned options) const
{
epvector newseq;
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- ex restexp = i->rest.expand();
+ for (auto & it : seq) {
+ ex restexp = it.rest.expand();
if (!restexp.is_zero())
- newseq.push_back(expair(restexp, i->coeff));
- ++i;
+ newseq.push_back(expair(restexp, it.coeff));
}
- return (new pseries(relational(var,point), newseq))
+ return (new pseries(relational(var,point), std::move(newseq)))
->setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0));
}
ex pseries::derivative(const symbol & s) const
{
epvector new_seq;
- epvector::const_iterator it = seq.begin(), itend = seq.end();
if (s == var) {
// FIXME: coeff might depend on var
- while (it != itend) {
- if (is_order_function(it->rest)) {
- new_seq.push_back(expair(it->rest, it->coeff - 1));
+ for (auto & it : seq) {
+ if (is_order_function(it.rest)) {
+ new_seq.push_back(expair(it.rest, it.coeff - 1));
} else {
- ex c = it->rest * it->coeff;
+ ex c = it.rest * it.coeff;
if (!c.is_zero())
- new_seq.push_back(expair(c, it->coeff - 1));
+ new_seq.push_back(expair(c, it.coeff - 1));
}
- ++it;
}
} else {
- while (it != itend) {
- if (is_order_function(it->rest)) {
- new_seq.push_back(*it);
+ for (auto & it : seq) {
+ if (is_order_function(it.rest)) {
+ new_seq.push_back(it);
} else {
- ex c = it->rest.diff(s);
+ ex c = it.rest.diff(s);
if (!c.is_zero())
- new_seq.push_back(expair(c, it->coeff));
+ new_seq.push_back(expair(c, it.coeff));
}
- ++it;
}
}
- return pseries(relational(var,point), new_seq);
+ return pseries(relational(var,point), std::move(new_seq));
}
ex pseries::convert_to_poly(bool no_order) const
{
ex e;
- epvector::const_iterator it = seq.begin(), itend = seq.end();
-
- while (it != itend) {
- if (is_order_function(it->rest)) {
+ for (auto & it : seq) {
+ if (is_order_function(it.rest)) {
if (!no_order)
- e += Order(power(var - point, it->coeff));
+ e += Order(power(var - point, it.coeff));
} else
- e += it->rest * power(var - point, it->coeff);
- ++it;
+ e += it.rest * power(var - point, it.coeff);
}
return e;
}
ex pseries::coeffop(size_t i) const
{
- if (i >=nops())
+ if (i >= nops())
throw (std::out_of_range("coeffop() out of range"));
return seq[i].rest;
}
// Series addition
epvector new_seq;
- epvector::const_iterator a = seq.begin();
- epvector::const_iterator b = other.seq.begin();
- epvector::const_iterator a_end = seq.end();
- epvector::const_iterator b_end = other.seq.end();
+ auto a = seq.begin(), a_end = seq.end();
+ auto b = other.seq.begin(), b_end = other.seq.end();
int pow_a = std::numeric_limits<int>::max(), pow_b = std::numeric_limits<int>::max();
for (;;) {
// If a is empty, fill up with elements from b and stop
}
}
}
- return pseries(relational(var,point), new_seq);
+ return pseries(relational(var,point), std::move(new_seq));
}
acc = overall_coeff.series(r, order, options);
// Add remaining terms
- epvector::const_iterator it = seq.begin();
- epvector::const_iterator itend = seq.end();
- for (; it!=itend; ++it) {
+ for (auto & it : seq) {
ex op;
- if (is_exactly_a<pseries>(it->rest))
- op = it->rest;
+ if (is_exactly_a<pseries>(it.rest))
+ op = it.rest;
else
- op = it->rest.series(r, order, options);
- if (!it->coeff.is_equal(_ex1))
- op = ex_to<pseries>(op).mul_const(ex_to<numeric>(it->coeff));
+ op = it.rest.series(r, order, options);
+ if (!it.coeff.is_equal(_ex1))
+ op = ex_to<pseries>(op).mul_const(ex_to<numeric>(it.coeff));
// Series addition
acc = ex_to<pseries>(acc).add_series(ex_to<pseries>(op));
epvector new_seq;
new_seq.reserve(seq.size());
- epvector::const_iterator it = seq.begin(), itend = seq.end();
- while (it != itend) {
- if (!is_order_function(it->rest))
- new_seq.push_back(expair(it->rest * other, it->coeff));
+ for (auto & it : seq) {
+ if (!is_order_function(it.rest))
+ new_seq.push_back(expair(it.rest * other, it.coeff));
else
- new_seq.push_back(*it);
- ++it;
+ new_seq.push_back(it);
}
return pseries(relational(var,point), new_seq);
}
std::vector<bool> ldegree_redo;
// find minimal degrees
- const epvector::const_iterator itbeg = seq.begin();
- const epvector::const_iterator itend = seq.end();
// first round: obtain a bound up to which minimal degrees have to be
// considered
- for (epvector::const_iterator it=itbeg; it!=itend; ++it) {
+ for (auto & it : seq) {
- ex expon = it->coeff;
+ ex expon = it.coeff;
int factor = 1;
ex buf;
if (expon.info(info_flags::integer)) {
- buf = it->rest;
+ buf = it.rest;
factor = ex_to<numeric>(expon).to_int();
} else {
- buf = recombine_pair_to_ex(*it);
+ buf = recombine_pair_to_ex(it);
}
int real_ldegree = 0;
// method.
// here we can ignore ldegrees larger than degbound
size_t j = 0;
- for (epvector::const_iterator it=itbeg; it!=itend; ++it) {
+ for (auto & it : seq) {
if ( ldegree_redo[j] ) {
- ex expon = it->coeff;
+ ex expon = it.coeff;
int factor = 1;
ex buf;
if (expon.info(info_flags::integer)) {
- buf = it->rest;
+ buf = it.rest;
factor = ex_to<numeric>(expon).to_int();
} else {
- buf = recombine_pair_to_ex(*it);
+ buf = recombine_pair_to_ex(it);
}
int real_ldegree = 0;
int orderloop = 0;
}
// Multiply with remaining terms
- std::vector<int>::const_iterator itd = ldegrees.begin();
- for (epvector::const_iterator it=itbeg; it!=itend; ++it, ++itd) {
+ auto itd = ldegrees.begin();
+ for (auto it=seq.begin(), itend=seq.end(); it!=itend; ++it, ++itd) {
// do series expansion with adjusted order
ex op = recombine_pair_to_ex(*it).series(r, order-degsum+(*itd), options);
// Series multiplication
- if (it == itbeg)
+ if (it == seq.begin())
acc = ex_to<pseries>(op);
else
acc = ex_to<pseries>(acc.mul_series(ex_to<pseries>(op)));
pseries pseries::shift_exponents(int deg) const
{
epvector newseq = seq;
- epvector::iterator i = newseq.begin(), end = newseq.end();
- while (i != end) {
- i->coeff += deg;
- ++i;
- }
- return pseries(relational(var, point), newseq);
+ for (auto & it : newseq)
+ it.coeff += deg;
+ return pseries(relational(var, point), std::move(newseq));
}
return *this;
else {
epvector new_seq;
- epvector::const_iterator it = seq.begin(), itend = seq.end();
- while (it != itend) {
- int o = ex_to<numeric>(it->coeff).to_int();
+ for (auto & it : seq) {
+ int o = ex_to<numeric>(it.coeff).to_int();
if (o >= order) {
new_seq.push_back(expair(Order(_ex1), o));
break;
}
- new_seq.push_back(*it);
- ++it;
+ new_seq.push_back(it);
}
return pseries(r, new_seq);
}
n.find_string("name", tmp_name);
// If symbol is in sym_lst, return the existing symbol
- for (lst::const_iterator it = sym_lst.begin(); it != sym_lst.end(); ++it) {
- if (is_a<symbol>(*it) && (ex_to<symbol>(*it).name == tmp_name)) {
- *this = ex_to<symbol>(*it);
+ for (auto & s : sym_lst) {
+ if (is_a<symbol>(s) && (ex_to<symbol>(s).name == tmp_name)) {
+ *this = ex_to<symbol>(s);
// XXX: This method is responsible for reading realsymbol
// and possymbol objects too. But
// basic::operator=(const basic& other)
n.add_unsigned("type", type);
if (children.empty()) {
- std::set<unsigned>::const_iterator i = indices.begin(), iend = indices.end();
- while (i != iend) {
- n.add_unsigned("index", *i);
- i++;
+ for (auto & i : indices) {
+ n.add_unsigned("index", i);
}
} else {
- exvector::const_iterator i = children.begin(), iend = children.end();
- while (i != iend) {
- n.add_ex("child", *i);
- i++;
+ for (auto & i : children) {
+ n.add_ex("child", i);
}
}
}
return 1;
if (this_size < that_size)
return -1;
- typedef std::set<unsigned>::const_iterator set_it;
- set_it end = indices.end();
- for (set_it i=indices.begin(),j=othersymm.indices.begin(); i!=end; ++i,++j) {
+ auto end = indices.end();
+ for (auto i=indices.begin(),j=othersymm.indices.begin(); i!=end; ++i,++j) {
if(*i < *j)
return 1;
if(*i > *j)
if (!indices.empty())
v ^= *(indices.begin());
} else {
- for (exvector::const_iterator i=children.begin(); i!=children.end(); ++i)
- {
+ for (auto & i : children) {
v = rotate_left(v);
- v ^= i->gethash();
+ v ^= i.gethash();
}
}
c.s << ", indices=(";
if (!indices.empty()) {
- std::set<unsigned>::const_iterator i = indices.begin(), end = indices.end();
+ auto i = indices.begin(), end = indices.end();
--end;
while (i != end)
c.s << *i++ << ",";
}
c.s << ")\n";
- exvector::const_iterator i = children.begin(), end = children.end();
- while (i != end) {
- i->print(c, level + c.delta_indent);
- ++i;
+ for (auto & i : children) {
+ i.print(c, level + c.delta_indent);
}
}
if (type == antisymmetric || type == cyclic)
return true;
- for (exvector::const_iterator i=children.begin(); i!=children.end(); ++i)
- if (ex_to<symmetry>(*i).has_nonsymmetric())
+ for (auto & i : children)
+ if (ex_to<symmetry>(i).has_nonsymmetric())
return true;
return false;
if (type == cyclic)
return true;
- for (exvector::const_iterator i=children.begin(); i!=children.end(); ++i)
- if (ex_to<symmetry>(*i).has_cyclic())
+ for (auto & i : children)
+ if (ex_to<symmetry>(i).has_cyclic())
return true;
return false;
GINAC_ASSERT(is_exactly_a<symmetry>(lh));
GINAC_ASSERT(is_exactly_a<symmetry>(rh));
GINAC_ASSERT(ex_to<symmetry>(lh).indices.size() == ex_to<symmetry>(rh).indices.size());
- std::set<unsigned>::const_iterator ait = ex_to<symmetry>(lh).indices.begin(), aitend = ex_to<symmetry>(lh).indices.end(), bit = ex_to<symmetry>(rh).indices.begin();
+ auto ait = ex_to<symmetry>(lh).indices.begin(), aitend = ex_to<symmetry>(lh).indices.end(), bit = ex_to<symmetry>(rh).indices.begin();
while (ait != aitend) {
int cmpval = v[*ait].compare(v[*bit]);
if (cmpval < 0)
GINAC_ASSERT(is_exactly_a<symmetry>(lh));
GINAC_ASSERT(is_exactly_a<symmetry>(rh));
GINAC_ASSERT(ex_to<symmetry>(lh).indices.size() == ex_to<symmetry>(rh).indices.size());
- std::set<unsigned>::const_iterator ait = ex_to<symmetry>(lh).indices.begin(), aitend = ex_to<symmetry>(lh).indices.end(), bit = ex_to<symmetry>(rh).indices.begin();
+ auto ait = ex_to<symmetry>(lh).indices.begin(), aitend = ex_to<symmetry>(lh).indices.end(), bit = ex_to<symmetry>(rh).indices.begin();
while (ait != aitend) {
v[*ait].swap(v[*bit]);
++ait; ++bit;
// Canonicalize children first
bool something_changed = false;
int sign = 1;
- exvector::const_iterator first = symm.children.begin(), last = symm.children.end();
+ auto first = symm.children.begin(), last = symm.children.end();
while (first != last) {
GINAC_ASSERT(is_exactly_a<symmetry>(*first));
int child_sign = canonicalize(v, ex_to<symmetry>(*first));
exset found;
e[0].find(e[1], found);
lst l;
- for (exset::const_iterator i = found.begin(); i != found.end(); ++i)
- l.append(*i);
+ for (auto & i : found)
+ l.append(i);
return l;
}
exmap repls;
if (e[0].match(e[1], repls)) {
lst repl_lst;
- for (exmap::const_iterator i = repls.begin(); i != repls.end(); ++i)
- repl_lst.append(relational(i->first, i->second, relational::equal));
+ for (auto & i : repls)
+ repl_lst.append(relational(i.first, i.second, relational::equal));
return repl_lst;
}
throw std::runtime_error("FAIL");
namespace GiNaC {
static void ginsh_get_ginac_functions(void)
{
- vector<function_options> gfv = function::get_registered_functions();
- vector<function_options>::const_iterator i = gfv.begin(), end = gfv.end();
unsigned serial = 0;
- while (i != end) {
- fcns.insert(make_pair(i->get_name(), fcn_desc(f_ginac_function, i->get_nparams(), serial)));
- ++i;
+ for (auto & i : function::get_registered_functions()) {
+ fcns.insert(make_pair(i.get_name(), fcn_desc(f_ginac_function, i.get_nparams(), serial)));
serial++;
}
}