case info_flags::rational_polynomial:
case info_flags::crational_polynomial:
case info_flags::rational_function: {
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
if (!(recombine_pair_to_ex(*i).info(inf)))
return false;
+ ++i;
}
return overall_coeff.info(inf);
}
case info_flags::algebraic: {
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
if ((recombine_pair_to_ex(*i).info(inf)))
return true;
+ ++i;
}
return false;
}
int add::degree(const ex & s) const
{
int deg = INT_MIN;
- if (!overall_coeff.is_equal(_ex0()))
+ if (!overall_coeff.is_zero())
deg = 0;
- int cur_deg;
- for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- cur_deg = (*cit).rest.degree(s);
- if (cur_deg>deg)
+ // 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);
+ if (cur_deg > deg)
deg = cur_deg;
+ ++i;
}
return deg;
}
int add::ldegree(const ex & s) const
{
int deg = INT_MAX;
- if (!overall_coeff.is_equal(_ex0()))
+ if (!overall_coeff.is_zero())
deg = 0;
- int cur_deg;
- for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- cur_deg = (*cit).rest.ldegree(s);
- if (cur_deg<deg) deg=cur_deg;
+ // 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);
+ if (cur_deg < deg)
+ deg = cur_deg;
+ ++i;
}
return deg;
}
ex add::coeff(const ex & s, int n) const
{
- epvector coeffseq;
-
- epvector::const_iterator it=seq.begin();
- while (it!=seq.end()) {
- ex restcoeff = it->rest.coeff(s,n);
+ epvector *coeffseq = new epvector();
+
+ // 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);
if (!restcoeff.is_zero())
- coeffseq.push_back(combine_ex_with_coeff_to_pair(restcoeff,it->coeff));
- ++it;
+ coeffseq->push_back(combine_ex_with_coeff_to_pair(restcoeff, i->coeff));
+ ++i;
}
-
- return (new add(coeffseq, n==0 ? overall_coeff : default_overall_coeff()))->setflag(status_flags::dynallocated);
+
+ return (new add(coeffseq, n==0 ? overall_coeff : _ex0()))->setflag(status_flags::dynallocated);
}
ex add::eval(int level) const
debugmsg("add eval",LOGLEVEL_MEMBER_FUNCTION);
- epvector * evaled_seqp = evalchildren(level);
- if (evaled_seqp!=0) {
+ epvector *evaled_seqp = evalchildren(level);
+ if (evaled_seqp) {
// do more evaluation later
- return (new add(evaled_seqp,overall_coeff))->
+ return (new add(evaled_seqp, overall_coeff))->
setflag(status_flags::dynallocated);
}
#ifdef DO_GINAC_ASSERT
- for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- GINAC_ASSERT(!is_ex_exactly_of_type((*cit).rest,add));
- if (is_ex_exactly_of_type((*cit).rest,numeric))
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
+ GINAC_ASSERT(!is_ex_exactly_of_type(i->rest,add));
+ if (is_ex_exactly_of_type(i->rest,numeric))
dbgprint();
- GINAC_ASSERT(!is_ex_exactly_of_type((*cit).rest,numeric));
+ GINAC_ASSERT(!is_ex_exactly_of_type(i->rest,numeric));
+ ++i;
}
#endif // def DO_GINAC_ASSERT
if (seq_size==0) {
// +(;c) -> c
return overall_coeff;
- } else if ((seq_size==1) && overall_coeff.is_equal(_ex0())) {
+ } else if ((seq_size==1) && overall_coeff.is_zero()) {
// +(x;0) -> x
return recombine_pair_to_ex(*(seq.begin()));
}
it++;
}
- if (all_matrices)
+ if (all_matrices) {
+ delete s;
return sum + overall_coeff;
- else
+ } else
return (new add(s, overall_coeff))->setflag(status_flags::dynallocated);
}
ex add::simplify_ncmul(const exvector & v) const
{
- if (seq.size()==0) {
+ if (seq.empty())
return inherited::simplify_ncmul(v);
- }
- return (*seq.begin()).rest.simplify_ncmul(v);
+ else
+ return seq.begin()->rest.simplify_ncmul(v);
}
// protected
// 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).
- for (epvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- s->push_back(combine_ex_with_coeff_to_pair((*it).rest.diff(y),
- (*it).coeff));
+ 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;
}
return (new add(s, _ex0()))->setflag(status_flags::dynallocated);
}
unsigned add::return_type(void) const
{
- if (seq.size()==0) {
+ if (seq.empty())
return return_types::commutative;
- }
- return (*seq.begin()).rest.return_type();
+ else
+ return seq.begin()->rest.return_type();
}
unsigned add::return_type_tinfo(void) const
{
- if (seq.size()==0) {
+ if (seq.empty())
return tinfo_key;
- }
- return (*seq.begin()).rest.return_type_tinfo();
+ else
+ return seq.begin()->rest.return_type_tinfo();
}
ex add::thisexpairseq(const epvector & v, const ex & oc) const
if (flags & status_flags::expanded)
return *this;
- epvector * vp = expandchildren(options);
+ epvector *vp = expandchildren(options);
if (vp == NULL) {
// the terms have not changed, so it is safe to declare this expanded
return this->setflag(status_flags::expanded);
}
- return (new add(vp,overall_coeff))->setflag(status_flags::expanded | status_flags::dynallocated);
+ return (new add(vp, overall_coeff))->setflag(status_flags::expanded | status_flags::dynallocated);
}
} // namespace GiNaC
found = true;
break;
}
- a++;
+ ++a;
}
if (!found)
v.push_back(property_info(type, name));
/** Delete cached unarchived expressions in all archive_nodes (mainly for debugging). */
void archive::forget(void)
{
- std::vector<archive_node>::iterator i = nodes.begin(), iend = nodes.end();
- while (i != iend) {
- i->forget();
- i++;
- }
+ for_each(nodes.begin(), nodes.end(), std::mem_fun_ref(&archive_node::forget));
}
/** Delete cached unarchived expressions from node (for debugging). */
while (it != other) {
if (!is_ex_of_type(*it, clifford))
return false;
- it++;
+ ++it;
}
it = self + 1;
}
if (it == first)
break;
- it--;
+ --it;
}
if (next_to_last == first)
break;
- next_to_last--;
+ --next_to_last;
}
}
something_changed = true;
}
}
- it++;
+ ++it;
}
}
- if (s.size() == 0)
+ if (s.empty())
return clifford(diracone(), representation_label) * sign;
if (something_changed)
return nonsimplified_ncmul(s) * sign;
// Stupid recursive bubble sort because we only want to swap adjacent gammas
exvector::iterator it = v.begin(), next_to_last = v.end() - 1;
if (is_ex_of_type(it->op(0), diracgamma5))
- it++;
+ ++it;
while (it != next_to_last) {
if (it[0].op(1).compare(it[1].op(1)) > 0) {
ex save0 = it[0], save1 = it[1];
srl.let_op(i) = (lhs == canonicalize_clifford(sum));
goto next_sym;
}
- it++;
+ ++it;
}
next_sym: ;
}
it++;
}
- if (s.size() == 0)
+ if (s.empty())
return color(su3one(), representation_label);
else
return simplified_ncmul(s);
GINAC_ASSERT(is_ex_of_type(i.op(0), su3d));
// Convolutions are zero
- if (static_cast<const indexed &>(i).get_dummy_indices().size() != 0)
+ if (!(static_cast<const indexed &>(i).get_dummy_indices().empty()))
return _ex0();
// Numeric evaluation
GINAC_DECLARE_REGISTERED_CLASS(${CONTAINER}, basic)
public:
- ${CONTAINER}(${STLT} const & s, bool discardable=0);
+ ${CONTAINER}(${STLT} const & s, bool discardable = false);
${CONTAINER}(${STLT} * vp); // vp will be deleted
${constructors_interface}
void ${CONTAINER}::archive(archive_node &n) const
{
inherited::archive(n);
- ${STLT}::const_iterator i = seq.begin(), iend = seq.end();
- while (i != iend) {
+ ${STLT}::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
n.add_ex("seq", *i);
- i++;
+ ++i;
}
}
<< ", nops=" << nops()
<< std::endl;
unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
- for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit)
- cit->print(c, level + delta_indent);
+ ${STLT}::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
+ i->print(c, level + delta_indent);
+ ++i;
+ }
c.s << std::string(level + delta_indent,' ') << "=====" << std::endl;
} else {
{
${STLT} s;
RESERVE(s,seq.size());
- for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- s.push_back(f(*it));
+ ${STLT}::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
+ s.push_back(f(*i));
+ ++i;
}
return this${CONTAINER}(s);
if (this_precedence <= upper_precedence)
c.s << openbracket;
- if (seq.size() != 0) {
+ if (!seq.empty()) {
${STLT}::const_iterator it = seq.begin(), itend = seq.end();
--itend;
while (it != itend) {
it->print(c, this_precedence);
c.s << delim;
- it++;
+ ++it;
}
it->print(c, this_precedence);
}
{
if (seq.size()<=1) { return 1; }
- ${STLT}::const_iterator it=seq.begin();
+ ${STLT}::const_iterator it = seq.begin(), itend = seq.end();
${STLT}::const_iterator it_last=it;
- for (++it; it!=seq.end(); it_last=it, ++it) {
- if ((*it_last).compare(*it)>0) {
- if ((*it_last).compare(*it)>0) {
+ for (++it; it!=itend; it_last=it, ++it) {
+ if (it_last->compare(*it)>0) {
+ if (it_last->compare(*it)>0) {
std::cout << *it_last << ">" << *it << "\\n";
return 0;
}
throw(std::runtime_error("max recursion level reached"));
}
--level;
- for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- s.push_back((*it).eval(level));
+ ${STLT}::const_iterator it = seq.begin(), itend = seq.end();
+ while (it != itend) {
+ s.push_back(it->eval(level));
+ ++it;
}
return s;
}
// returns a pointer to a newly created epvector otherwise
// (which has to be deleted somewhere else)
- ${STLT}::const_iterator last=seq.end();
- ${STLT}::const_iterator cit=seq.begin();
- while (cit!=last) {
- const ex & subsed_ex=(*cit).subs(ls,lr,no_pattern);
- if (!are_ex_trivially_equal(*cit,subsed_ex)) {
+ ${STLT}::const_iterator cit = seq.begin(), end = seq.end();
+ while (cit != end) {
+ const ex & subsed_ex = cit->subs(ls, lr, no_pattern);
+ if (!are_ex_trivially_equal(*cit, subsed_ex)) {
// something changed, copy seq, subs and return it
${STLT} *s=new ${STLT};
- RESERVE(*s,seq.size());
+ RESERVE(*s, seq.size());
// copy parts of seq which are known not to have changed
- ${STLT}::const_iterator cit2=seq.begin();
- while (cit2!=cit) {
+ ${STLT}::const_iterator cit2 = seq.begin();
+ while (cit2 != cit) {
s->push_back(*cit2);
++cit2;
}
+
// copy first changed element
s->push_back(subsed_ex);
++cit2;
+
// copy rest
- while (cit2!=last) {
- s->push_back((*cit2).subs(ls,lr,no_pattern));
+ while (cit2 != end) {
+ s->push_back(cit2->subs(ls, lr, no_pattern));
++cit2;
}
return s;
<< std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
<< ", nops=" << nops()
<< std::endl;
- for (unsigned i=0; i<seq.size(); ++i) {
+ unsigned num = seq.size();
+ for (unsigned i=0; i<num; ++i) {
seq[i].rest.print(c, level + delta_indent);
seq[i].coeff.print(c, level + delta_indent);
- if (i != seq.size()-1)
+ if (i != num - 1)
c.s << std::string(level + delta_indent, ' ') << "-----" << std::endl;
}
if (!overall_coeff.is_equal(default_overall_coeff())) {
ops.erase(it);
goto found;
}
- it++;
+ ++it;
}
return false; // no match found
found: ;
// Assign all the remaining terms to the global wildcard (unless
// it has already been matched before, in which case the matches
// must be equal)
+ unsigned num = ops.size();
epvector *vp = new epvector();
- vp->reserve(ops.size());
- for (unsigned i=0; i<ops.size(); i++)
+ vp->reserve(num);
+ for (unsigned i=0; i<num; i++)
vp->push_back(split_ex_to_pair(ops[i]));
ex rest = thisexpairseq(vp, default_overall_coeff());
for (unsigned i=0; i<repl_lst.nops(); i++) {
unsigned expairseq::calchash(void) const
{
unsigned v = golden_ratio_hash(tinfo());
- for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
#if !EXPAIRSEQ_USE_HASHTAB
v = rotate_left_31(v); // rotation would spoil commutativity
#endif // EXPAIRSEQ_USE_HASHTAB
- v ^= cit->rest.gethash();
+ v ^= i->rest.gethash();
#if !EXPAIRSEQ_USE_HASHTAB
v = rotate_left_31(v);
- v ^= cit->coeff.gethash();
+ v ^= i->coeff.gethash();
#endif // EXPAIRSEQ_USE_HASHTAB
+ ++i;
}
v ^= overall_coeff.gethash();
canonicalize();
combine_same_terms_sorted_seq();
#endif // EXPAIRSEQ_USE_HASHTAB
- return;
}
void expairseq::construct_from_epvector(const epvector &v)
canonicalize();
combine_same_terms_sorted_seq();
#endif // EXPAIRSEQ_USE_HASHTAB
- return;
}
/** Combine this expairseq with argument exvector.
}
++cit;
}
-
- return;
}
/** Combine this expairseq with argument epvector.
}
++cit;
}
- return;
}
/** Brings this expairseq into a sorted (canonical) form. */
void expairseq::canonicalize(void)
{
- // canonicalize
- sort(seq.begin(),seq.end(),expair_is_less());
- return;
+ sort(seq.begin(), seq.end(), expair_is_less());
}
seq.clear();
construct_from_epvector(v);
}
- return;
}
#if EXPAIRSEQ_USE_HASHTAB
void expairseq::sorted_insert(epplist &eppl, epp elem)
{
- epplist::iterator current = eppl.begin();
+ epplist::const_iterator current = eppl.begin();
while ((current!=eppl.end())&&((*(*current)).is_less(*elem))) {
++current;
}
* debugging purposes. */
bool expairseq::has_coeff_0(void) const
{
- for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- if ((*cit).coeff.is_zero())
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
+ if (i->coeff.is_zero())
return true;
+ ++i;
}
return false;
}
void expairseq::add_numerics_to_hashtab(epvector::iterator first_numeric,
epvector::const_iterator last_non_zero)
{
- if (first_numeric==seq.end()) return; // no numerics
+ if (first_numeric == seq.end()) return; // no numerics
- epvector::iterator current = first_numeric;
- epvector::const_iterator last = last_non_zero+1;
- while (current!=last) {
- sorted_insert(hashtab[hashmask],current);
+ epvector::const_iterator current = first_numeric, last = last_non_zero + 1;
+ while (current != last) {
+ sorted_insert(hashtab[hashmask], current);
++current;
}
}
epvector::iterator first_numeric = seq.end();
epvector::iterator last_non_zero = seq.end()-1;
- std::vector<bool> touched;
- touched.reserve(seq.size());
- for (unsigned i=0; i<seq.size(); ++i) touched[i]=false;
+ unsigned num = seq.size();
+ std::vector<bool> touched(num);
unsigned number_of_zeroes = 0;
GINAC_ASSERT(!has_coeff_0());
build_hashtab_and_combine(first_numeric,last_non_zero,touched,number_of_zeroes);
- /*
- cout << "in combine:" << std::endl;
- printtree(cout,0);
- cout << "size=" << seq.end() - seq.begin() << std::endl;
- cout << "first_numeric=" << first_numeric - seq.begin() << std::endl;
- cout << "last_non_zero=" << last_non_zero - seq.begin() << std::endl;
- for (unsigned i=0; i<seq.size(); ++i) {
- if (touched[i]) cout << i << " is touched" << std::endl;
- }
- cout << "end in combine" << std::endl;
- */
// there should not be any terms with coeff 0 from the beginning,
// so it should be safe to skip this step
if (number_of_zeroes!=0) {
drop_coeff_0_terms(first_numeric,last_non_zero,touched,number_of_zeroes);
- /*
- cout << "in combine after drop:" << std::endl;
- printtree(cout,0);
- cout << "size=" << seq.end() - seq.begin() << std::endl;
- cout << "first_numeric=" << first_numeric - seq.begin() << std::endl;
- cout << "last_non_zero=" << last_non_zero - seq.begin() << std::endl;
- for (unsigned i=0; i<seq.size(); ++i) {
- if (touched[i]) cout << i << " is touched" << std::endl;
- }
- cout << "end in combine after drop" << std::endl;
- */
}
add_numerics_to_hashtab(first_numeric,last_non_zero);
if (hashtabsize > 0) return 1; // not canoncalized
#endif // EXPAIRSEQ_USE_HASHTAB
- epvector::const_iterator it = seq.begin();
+ epvector::const_iterator it = seq.begin(), itend = seq.end();
epvector::const_iterator it_last = it;
- for (++it; it!=seq.end(); it_last=it, ++it) {
+ for (++it; it!=itend; it_last=it, ++it) {
if (!((*it_last).is_less(*it) || (*it_last).is_equal(*it))) {
if (!is_ex_exactly_of_type((*it_last).rest,numeric) ||
!is_ex_exactly_of_type((*it).rest,numeric)) {
#define EXPAIRSEQ_USE_HASHTAB 0
typedef std::vector<expair> epvector; ///< expair-vector
-typedef epvector::iterator epviter; ///< expair-vector iterator
typedef epvector::iterator epp; ///< expair-vector pointer
typedef std::list<epp> epplist; ///< list of expair-vector pointers
typedef std::vector<epplist> epplistvector; ///< vector of epplist
$constructors_interface
// end of generated lines
function(unsigned ser, const exprseq & es);
- function(unsigned ser, const exvector & v, bool discardable=0);
+ function(unsigned ser, const exvector & v, bool discardable = false);
function(unsigned ser, exvector * vp); // vp will be deleted
// functions overriding virtual functions from bases classes
<< ", nops=" << nops()
<< std::endl;
unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
- for (unsigned i=0; i<nops(); ++i)
+ for (unsigned i=0; i<seq.size(); ++i)
seq[i].print(c, level + delta_indent);
c.s << std::string(level + delta_indent, ' ') << "=====" << std::endl;
// Print function name in lowercase
std::string lname = registered_functions()[serial].name;
- for (unsigned i=0; i<lname.size(); i++)
+ unsigned num = lname.size();
+ for (unsigned i=0; i<num; i++)
lname[i] = tolower(lname[i]);
c.s << lname << "(";
} else {
// Chain rule
ex arg_diff;
- for (unsigned i=0; i!=seq.size(); i++) {
+ unsigned num = seq.size();
+ for (unsigned i=0; i<num; i++) {
arg_diff = seq[i].diff(s);
// We apply the chain rule only when it makes sense. This is not
// just for performance reasons but also to allow functions to
unsigned function::return_type(void) const
{
- if (seq.size()==0) {
+ if (seq.empty())
return return_types::commutative;
- }
- return (*seq.begin()).return_type();
+ else
+ return seq.begin()->return_type();
}
unsigned function::return_type_tinfo(void) const
{
- if (seq.size()==0) {
+ if (seq.empty())
return tinfo_key;
- }
- return (*seq.begin()).return_type_tinfo();
+ else
+ return seq.begin()->return_type_tinfo();
}
//////////
// Check whether the two factors share dummy indices
exvector free, dummy;
find_free_and_dummy(un, free, dummy);
- if (dummy.size() == 0)
+ unsigned num_dummies = dummy.size();
+ if (num_dummies == 0)
continue;
// At least one dummy index, is it a defined scalar product?
bool contracted = false;
- if (free.size() == 0) {
+ if (free.empty()) {
if (sp.is_defined(*it1, *it2)) {
*it1 = sp.evaluate(*it1, *it2);
*it2 = _ex1();
}
// Contraction of symmetric with antisymmetric object is zero
- if (dummy.size() > 1
+ if (num_dummies > 1
&& ex_to<symmetry>(ex_to<indexed>(*it1).symtree).has_symmetry()
&& ex_to<symmetry>(ex_to<indexed>(*it2).symtree).has_symmetry()) {
// Check all pairs of dummy indices
- for (unsigned idx1=0; idx1<dummy.size()-1; idx1++) {
- for (unsigned idx2=idx1+1; idx2<dummy.size(); idx2++) {
+ for (unsigned idx1=0; idx1<num_dummies-1; idx1++) {
+ for (unsigned idx2=idx1+1; idx2<num_dummies; idx2++) {
// Try and swap the index pair and check whether the
// relative sign changed
void scalar_products::debugprint(void) const
{
std::cerr << "map size=" << spm.size() << std::endl;
- for (spmap::const_iterator cit=spm.begin(); cit!=spm.end(); ++cit) {
- const spmapkey & k = cit->first;
+ spmap::const_iterator i = spm.begin(), end = spm.end();
+ while (i != end) {
+ const spmapkey & k = i->first;
std::cerr << "item key=(" << k.first << "," << k.second;
- std::cerr << "), value=" << cit->second << std::endl;
+ std::cerr << "), value=" << i->second << std::endl;
+ ++i;
}
}
static ex log_eval(const ex & x)
{
if (x.info(info_flags::numeric)) {
- if (x.is_equal(_ex0())) // log(0) -> infinity
+ if (x.is_zero()) // log(0) -> infinity
throw(pole_error("log_eval(): log(0)",0));
if (x.info(info_flags::real) && x.info(info_flags::negative))
return (log(-x)+I*Pi);
{
if (x.info(info_flags::numeric)) {
// atan(0) -> 0
- if (x.is_equal(_ex0()))
+ if (x.is_zero())
return _ex0();
// atan(1) -> Pi/4
if (x.is_equal(_ex1()))
throw std::logic_error("matrix::add(): incompatible matrices");
exvector sum(this->m);
- exvector::iterator i;
- exvector::const_iterator ci;
- for (i=sum.begin(), ci=other.m.begin(); i!=sum.end(); ++i, ++ci)
- (*i) += (*ci);
+ exvector::iterator i = sum.begin(), end = sum.end();
+ exvector::const_iterator ci = other.m.begin();
+ while (i != end)
+ *i++ += *ci++;
return matrix(row,col,sum);
}
throw std::logic_error("matrix::sub(): incompatible matrices");
exvector dif(this->m);
- exvector::iterator i;
- exvector::const_iterator ci;
- for (i=dif.begin(), ci=other.m.begin(); i!=dif.end(); ++i, ++ci)
- (*i) -= (*ci);
+ exvector::iterator i = dif.begin(), end = dif.end();
+ exvector::const_iterator ci = other.m.begin();
+ while (i != end)
+ *i++ -= *ci++;
return matrix(row,col,dif);
}
bool numeric_flag = true;
bool normal_flag = false;
unsigned sparse_count = 0; // counts non-zero elements
- for (exvector::const_iterator r=m.begin(); r!=m.end(); ++r) {
+ exvector::const_iterator r = m.begin(), rend = m.end();
+ while (r != rend) {
lst 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::numeric))
if (!rtest.info(info_flags::crational_polynomial) &&
rtest.info(info_flags::rational_function))
normal_flag = true;
+ ++r;
}
// Here is the heuristics in case this routine has to decide:
}
sort(c_zeros.begin(),c_zeros.end());
std::vector<unsigned> pre_sort;
- for (std::vector<uintpair>::iterator i=c_zeros.begin(); i!=c_zeros.end(); ++i)
+ for (std::vector<uintpair>::const_iterator i=c_zeros.begin(); i!=c_zeros.end(); ++i)
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>::iterator i=pre_sort.begin();
+ for (std::vector<unsigned>::const_iterator i=pre_sort.begin();
i!=pre_sort.end();
++i,++c) {
for (unsigned r=0; r<row; ++r)
throw (std::logic_error("matrix::charpoly(): matrix not square"));
bool numeric_flag = true;
- for (exvector::const_iterator r=m.begin(); r!=m.end(); ++r) {
- if (!(*r).info(info_flags::numeric)) {
+ exvector::const_iterator r = m.begin(), rend = m.end();
+ while (r != rend) {
+ if (!r->info(info_flags::numeric))
numeric_flag = false;
- }
+ ++r;
}
// The pure numeric case is traditionally rather common. Hence, it is
// Gather some statistical information about the augmented matrix:
bool numeric_flag = true;
- for (exvector::const_iterator r=aug.m.begin(); r!=aug.m.end(); ++r) {
- if (!(*r).info(info_flags::numeric))
+ exvector::const_iterator r = aug.m.begin(), rend = aug.m.end();
+ while (r != rend) {
+ if (!r->info(info_flags::numeric))
numeric_flag = false;
+ ++r;
}
// Here is the heuristics in case this routine has to decide:
matrix tmp_n(*this);
matrix tmp_d(m,n); // for denominators, if needed
lst srl; // symbol replacement list
- exvector::iterator it = this->m.begin();
- exvector::iterator tmp_n_it = tmp_n.m.begin();
- exvector::iterator tmp_d_it = tmp_d.m.begin();
- for (; it!= this->m.end(); ++it, ++tmp_n_it, ++tmp_d_it) {
- (*tmp_n_it) = (*it).normal().to_rational(srl);
- (*tmp_d_it) = (*tmp_n_it).denom();
- (*tmp_n_it) = (*tmp_n_it).numer();
+ 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;
+ *tmp_n_it++ = nd.op(0);
+ *tmp_d_it++ = nd.op(1);
}
unsigned r0 = 0;
}
}
// repopulate *this matrix:
- it = this->m.begin();
+ exvector::iterator it = this->m.begin(), itend = this->m.end();
tmp_n_it = tmp_n.m.begin();
tmp_d_it = tmp_d.m.begin();
- for (; it!= this->m.end(); ++it, ++tmp_n_it, ++tmp_d_it)
- (*it) = ((*tmp_n_it)/(*tmp_d_it)).subs(srl);
+ while (it != itend)
+ *it++ = ((*tmp_n_it++)/(*tmp_d_it++)).subs(srl);
return sign;
}
case info_flags::rational_polynomial:
case info_flags::crational_polynomial:
case info_flags::rational_function: {
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
if (!(recombine_pair_to_ex(*i).info(inf)))
return false;
+ ++i;
}
return overall_coeff.info(inf);
}
case info_flags::algebraic: {
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
if ((recombine_pair_to_ex(*i).info(inf)))
return true;
+ ++i;
}
return false;
}
int mul::degree(const ex & s) const
{
+ // Sum up degrees of factors
int deg_sum = 0;
- for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- if (ex_to<numeric>(cit->coeff).is_integer())
- deg_sum+=cit->rest.degree(s) * ex_to<numeric>(cit->coeff).to_int();
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
+ if (ex_to<numeric>(i->coeff).is_integer())
+ deg_sum += i->rest.degree(s) * ex_to<numeric>(i->coeff).to_int();
+ ++i;
}
return deg_sum;
}
int mul::ldegree(const ex & s) const
{
+ // Sum up degrees of factors
int deg_sum = 0;
- for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- if (ex_to<numeric>(cit->coeff).is_integer())
- deg_sum+=cit->rest.ldegree(s) * ex_to<numeric>(cit->coeff).to_int();
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
+ if (ex_to<numeric>(i->coeff).is_integer())
+ deg_sum += i->rest.ldegree(s) * ex_to<numeric>(i->coeff).to_int();
+ ++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 it = seq.begin();
- while (it!=seq.end()) {
- coeffseq.push_back(recombine_pair_to_ex(*it).coeff(s,n));
- ++it;
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
+ coeffseq.push_back(recombine_pair_to_ex(*i).coeff(s,n));
+ ++i;
}
coeffseq.push_back(overall_coeff);
return (new mul(coeffseq))->setflag(status_flags::dynallocated);
}
- epvector::const_iterator it=seq.begin();
- bool coeff_found = 0;
- while (it!=seq.end()) {
- ex t = recombine_pair_to_ex(*it);
- ex c = t.coeff(s,n);
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ bool coeff_found = false;
+ while (i != end) {
+ ex t = recombine_pair_to_ex(*i);
+ ex c = t.coeff(s, n);
if (!c.is_zero()) {
coeffseq.push_back(c);
coeff_found = 1;
} else {
coeffseq.push_back(t);
}
- ++it;
+ ++i;
}
if (coeff_found) {
coeffseq.push_back(overall_coeff);
debugmsg("mul eval",LOGLEVEL_MEMBER_FUNCTION);
- epvector * evaled_seqp = evalchildren(level);
- if (evaled_seqp!=0) {
+ epvector *evaled_seqp = evalchildren(level);
+ if (evaled_seqp) {
// do more evaluation later
return (new mul(evaled_seqp,overall_coeff))->
setflag(status_flags::dynallocated);
}
#ifdef DO_GINAC_ASSERT
- for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- GINAC_ASSERT((!is_ex_exactly_of_type((*cit).rest,mul)) ||
- (!(ex_to<numeric>((*cit).coeff).is_integer())));
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
+ GINAC_ASSERT((!is_ex_exactly_of_type(i->rest, mul)) ||
+ (!(ex_to<numeric>(i->coeff).is_integer())));
GINAC_ASSERT(!(cit->is_canonical_numeric()));
- if (is_ex_exactly_of_type(recombine_pair_to_ex(*cit),numeric))
+ if (is_ex_exactly_of_type(recombine_pair_to_ex(*i), numeric))
print(print_tree(std::cerr));
- GINAC_ASSERT(!is_ex_exactly_of_type(recombine_pair_to_ex(*cit),numeric));
+ GINAC_ASSERT(!is_ex_exactly_of_type(recombine_pair_to_ex(*i), numeric));
/* for paranoia */
- expair p = split_ex_to_pair(recombine_pair_to_ex(*cit));
- GINAC_ASSERT(p.rest.is_equal((*cit).rest));
- GINAC_ASSERT(p.coeff.is_equal((*cit).coeff));
+ expair p = split_ex_to_pair(recombine_pair_to_ex(*i));
+ GINAC_ASSERT(p.rest.is_equal(i->rest));
+ GINAC_ASSERT(p.coeff.is_equal(i->coeff));
/* end paranoia */
+ ++i;
}
#endif // def DO_GINAC_ASSERT
}
int seq_size = seq.size();
- if (overall_coeff.is_equal(_ex0())) {
+ if (overall_coeff.is_zero()) {
// *(...,x;0) -> 0
return _ex0();
} else if (seq_size==0) {
ex_to<numeric>((*seq.begin()).coeff).is_equal(_num1())) {
// *(+(x,y,...);c) -> +(*(x,c),*(y,c),...) (c numeric(), no powers of +())
const add & addref = ex_to<add>((*seq.begin()).rest);
- epvector distrseq;
- distrseq.reserve(addref.seq.size());
- for (epvector::const_iterator cit=addref.seq.begin(); cit!=addref.seq.end(); ++cit) {
- distrseq.push_back(addref.combine_pair_with_coeff_to_pair(*cit, overall_coeff));
+ epvector *distrseq = new epvector();
+ 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;
}
return (new add(distrseq,
ex_to<numeric>(addref.overall_coeff).
if (level==-max_recursion_level)
throw(std::runtime_error("max recursion level reached"));
- epvector s;
- s.reserve(seq.size());
-
+ epvector *s = new epvector();
+ s->reserve(seq.size());
+
--level;
- for (epvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- s.push_back(combine_ex_with_coeff_to_pair((*it).rest.evalf(level),
- (*it).coeff));
+ 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;
}
- return mul(s,overall_coeff.evalf(level));
+ return mul(s, overall_coeff.evalf(level));
}
ex mul::evalm(void) const
bool have_matrix = false;
epvector::iterator the_matrix;
- epvector::const_iterator it = seq.begin(), itend = seq.end();
- while (it != itend) {
- const ex &m = recombine_pair_to_ex(*it).evalm();
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
+ const ex &m = recombine_pair_to_ex(*i).evalm();
s->push_back(split_ex_to_pair(m));
if (is_ex_of_type(m, matrix)) {
have_matrix = true;
the_matrix = s->end() - 1;
}
- it++;
+ ++i;
}
if (have_matrix) {
ex mul::simplify_ncmul(const exvector & v) const
{
- if (seq.size()==0) {
+ if (seq.empty())
return inherited::simplify_ncmul(v);
- }
// Find first noncommutative element and call its simplify_ncmul()
- for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- if (cit->rest.return_type() == return_types::noncommutative)
- return cit->rest.simplify_ncmul(v);
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
+ if (i->rest.return_type() == return_types::noncommutative)
+ return i->rest.simplify_ncmul(v);
+ ++i;
}
return inherited::simplify_ncmul(v);
}
* @see ex::diff */
ex mul::derivative(const symbol & s) const
{
+ unsigned num = seq.size();
exvector addseq;
- addseq.reserve(seq.size());
+ addseq.reserve(num);
// D(a*b*c) = D(a)*b*c + a*D(b)*c + a*b*D(c)
- for (unsigned i=0; i!=seq.size(); ++i) {
- epvector mulseq = seq;
- mulseq[i] = split_ex_to_pair(power(seq[i].rest,seq[i].coeff - _ex1()) *
- seq[i].rest.diff(s));
- addseq.push_back((new mul(mulseq,overall_coeff*seq[i].coeff))->setflag(status_flags::dynallocated));
+ epvector mulseq = seq;
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ epvector::iterator i2 = mulseq.begin();
+ while (i != end) {
+ expair ep = split_ex_to_pair(power(i->rest, i->coeff - _ex1()) *
+ i->rest.diff(s));
+ ep.swap(*i2);
+ addseq.push_back((new mul(mulseq, overall_coeff * i->coeff))->setflag(status_flags::dynallocated));
+ ep.swap(*i2);
+ ++i; ++i2;
}
return (new add(addseq))->setflag(status_flags::dynallocated);
}
unsigned mul::return_type(void) const
{
- if (seq.size()==0) {
+ if (seq.empty()) {
// mul without factors: should not happen, but commutes
return return_types::commutative;
}
- bool all_commutative = 1;
- unsigned rt;
- epvector::const_iterator cit_noncommutative_element; // point to first found nc element
+ bool all_commutative = true;
+ epvector::const_iterator noncommutative_element; // point to first found nc element
- for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- rt=(*cit).rest.return_type();
- if (rt==return_types::noncommutative_composite) return rt; // one ncc -> mul also ncc
- if ((rt==return_types::noncommutative)&&(all_commutative)) {
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
+ unsigned rt = i->rest.return_type();
+ if (rt == return_types::noncommutative_composite)
+ return rt; // one ncc -> mul also ncc
+ if ((rt == return_types::noncommutative) && (all_commutative)) {
// first nc element found, remember position
- cit_noncommutative_element = cit;
- all_commutative = 0;
+ noncommutative_element = i;
+ all_commutative = false;
}
- if ((rt==return_types::noncommutative)&&(!all_commutative)) {
+ if ((rt == return_types::noncommutative) && (!all_commutative)) {
// another nc element found, compare type_infos
- if ((*cit_noncommutative_element).rest.return_type_tinfo()!=(*cit).rest.return_type_tinfo()) {
+ if (noncommutative_element->rest.return_type_tinfo() != i->rest.return_type_tinfo()) {
// diffent types -> mul is ncc
return return_types::noncommutative_composite;
}
}
+ ++i;
}
// all factors checked
return all_commutative ? return_types::commutative : return_types::noncommutative;
unsigned mul::return_type_tinfo(void) const
{
- if (seq.size()==0)
+ if (seq.empty())
return tinfo_key; // mul without factors: should not happen
// return type_info of first noncommutative element
- for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- if ((*cit).rest.return_type()==return_types::noncommutative)
- return (*cit).rest.return_type_tinfo();
+ 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;
}
// no noncommutative element found, should not happen
return tinfo_key;
ex mul::thisexpairseq(const epvector & v, const ex & oc) const
{
- return (new mul(v,oc))->setflag(status_flags::dynallocated);
+ return (new mul(v, oc))->setflag(status_flags::dynallocated);
}
ex mul::thisexpairseq(epvector * vp, const ex & oc) const
{
- return (new mul(vp,oc))->setflag(status_flags::dynallocated);
+ return (new mul(vp, oc))->setflag(status_flags::dynallocated);
}
expair mul::split_ex_to_pair(const ex & e) const
setflag(status_flags::dynallocated | status_flags::expanded));
}
non_adds.push_back(split_ex_to_pair(last_expanded));
- return (new mul(non_adds,overall_coeff))->
+ return (new mul(non_adds, overall_coeff))->
setflag(status_flags::dynallocated | status_flags::expanded);
}
int ncmul::degree(const ex & s) const
{
- int deg_sum=0;
- for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- deg_sum+=(*cit).degree(s);
+ // 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;
}
return deg_sum;
}
int ncmul::ldegree(const ex & s) const
{
- int deg_sum=0;
- for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- deg_sum+=(*cit).ldegree(s);
+ // 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;
}
return deg_sum;
}
exvector coeffseq;
coeffseq.reserve(seq.size());
- if (n==0) {
+ 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();
return (new ncmul(coeffseq,1))->setflag(status_flags::dynallocated);
}
- exvector::const_iterator it=seq.begin();
- bool coeff_found=0;
- while (it!=seq.end()) {
- ex c=(*it).coeff(s,n);
- if (!c.is_zero()) {
- coeffseq.push_back(c);
- coeff_found=1;
+ exvector::const_iterator i = seq.begin(), end = seq.end();
+ bool coeff_found = false;
+ while (i != end) {
+ ex c = i->coeff(s,n);
+ if (c.is_zero()) {
+ coeffseq.push_back(*i);
} else {
- coeffseq.push_back(*it);
+ coeffseq.push_back(c);
+ coeff_found = true;
}
- ++it;
+ ++i;
}
if (coeff_found) return (new ncmul(coeffseq,1))->setflag(status_flags::dynallocated);
(is_ex_exactly_of_type(e,ncmul))) {
for (unsigned i=0; i<e.nops(); i++)
append_factors(v,e.op(i));
-
- return;
- }
- v.push_back(e);
+ } else
+ v.push_back(e);
}
typedef std::vector<unsigned> unsignedvector;
// ncmul(...,*(x1,x2),...,ncmul(x3,x4),...) ->
// ncmul(...,x1,x2,...,x3,x4,...) (associativity)
- unsigned factors=0;
- for (exvector::const_iterator cit=evaledseq.begin(); cit!=evaledseq.end(); ++cit)
- factors += count_factors(*cit);
+ unsigned factors = 0;
+ exvector::const_iterator cit = evaledseq.begin(), citend = evaledseq.end();
+ while (cit != citend)
+ factors += count_factors(*cit++);
exvector assocseq;
assocseq.reserve(factors);
- for (exvector::const_iterator cit=evaledseq.begin(); cit!=evaledseq.end(); ++cit)
- append_factors(assocseq,*cit);
+ cit = evaledseq.begin();
+ while (cit != citend)
+ append_factors(assocseq, *cit++);
// ncmul(x) -> x
if (assocseq.size()==1) return *(seq.begin());
// ncmul() -> 1
- if (assocseq.size()==0) return _ex1();
+ if (assocseq.empty()) return _ex1();
// determine return types
unsignedvector rettypes;
rettypes.reserve(assocseq.size());
- unsigned i=0;
+ unsigned i = 0;
unsigned count_commutative=0;
unsigned count_noncommutative=0;
unsigned count_noncommutative_composite=0;
- for (exvector::const_iterator cit=assocseq.begin(); cit!=assocseq.end(); ++cit) {
- switch (rettypes[i]=(*cit).return_type()) {
+ cit = assocseq.begin(); citend = assocseq.end();
+ while (cit != citend) {
+ switch (rettypes[i] = cit->return_type()) {
case return_types::commutative:
count_commutative++;
break;
default:
throw(std::logic_error("ncmul::eval(): invalid return type"));
}
- ++i;
+ ++i; ++cit;
}
GINAC_ASSERT(count_commutative+count_noncommutative+count_noncommutative_composite==assocseq.size());
commutativeseq.reserve(count_commutative+1);
exvector noncommutativeseq;
noncommutativeseq.reserve(assocseq.size()-count_commutative);
- for (i=0; i<assocseq.size(); ++i) {
+ unsigned num = assocseq.size();
+ for (unsigned i=0; i<num; ++i) {
if (rettypes[i]==return_types::commutative)
commutativeseq.push_back(assocseq[i]);
else
// elements in assocseq
GINAC_ASSERT(count_commutative==0);
+ unsigned assoc_num = assocseq.size();
exvectorvector evv;
unsignedvector rttinfos;
- evv.reserve(assocseq.size());
- rttinfos.reserve(assocseq.size());
+ evv.reserve(assoc_num);
+ rttinfos.reserve(assoc_num);
- for (exvector::const_iterator cit=assocseq.begin(); cit!=assocseq.end(); ++cit) {
- unsigned ti=(*cit).return_type_tinfo();
+ cit = assocseq.begin(), citend = assocseq.end();
+ while (cit != citend) {
+ unsigned ti = cit->return_type_tinfo();
+ unsigned rtt_num = rttinfos.size();
// search type in vector of known types
- for (i=0; i<rttinfos.size(); ++i) {
- if (ti==rttinfos[i]) {
+ for (i=0; i<rtt_num; ++i) {
+ if (ti == rttinfos[i]) {
evv[i].push_back(*cit);
break;
}
}
- if (i>=rttinfos.size()) {
+ if (i >= rtt_num) {
// new type
rttinfos.push_back(ti);
evv.push_back(exvector());
- (*(evv.end()-1)).reserve(assocseq.size());
- (*(evv.end()-1)).push_back(*cit);
+ (evv.end()-1)->reserve(assoc_num);
+ (evv.end()-1)->push_back(*cit);
}
+ ++cit;
}
+ unsigned evv_num = evv.size();
#ifdef DO_GINAC_ASSERT
- GINAC_ASSERT(evv.size()==rttinfos.size());
- GINAC_ASSERT(evv.size()>0);
+ GINAC_ASSERT(evv_num == rttinfos.size());
+ GINAC_ASSERT(evv_num > 0);
unsigned s=0;
- for (i=0; i<evv.size(); ++i) {
+ for (i=0; i<evv_num; ++i)
s += evv[i].size();
- }
- GINAC_ASSERT(s==assocseq.size());
+ GINAC_ASSERT(s == assoc_num);
#endif // def DO_GINAC_ASSERT
// if all elements are of same type, simplify the string
- if (evv.size()==1)
+ if (evv_num == 1)
return evv[0][0].simplify_ncmul(evv[0]);
exvector splitseq;
- splitseq.reserve(evv.size());
- for (i=0; i<evv.size(); ++i) {
+ splitseq.reserve(evv_num);
+ for (i=0; i<evv_num; ++i)
splitseq.push_back((new ncmul(evv[i]))->setflag(status_flags::dynallocated));
- }
return (new mul(splitseq))->setflag(status_flags::dynallocated);
}
* @see ex::diff */
ex ncmul::derivative(const symbol & s) const
{
+ unsigned num = seq.size();
exvector addseq;
- addseq.reserve(seq.size());
+ addseq.reserve(num);
// D(a*b*c) = D(a)*b*c + a*D(b)*c + a*b*D(c)
- for (unsigned i=0; i!=seq.size(); ++i) {
- exvector ncmulseq = seq;
- ncmulseq[i] = seq[i].diff(s);
+ exvector ncmulseq = seq;
+ for (unsigned i=0; i<num; ++i) {
+ ex e = seq[i].diff(s);
+ e.swap(ncmulseq[i]);
addseq.push_back((new ncmul(ncmulseq))->setflag(status_flags::dynallocated));
+ e.swap(ncmulseq[i]);
}
return (new add(addseq))->setflag(status_flags::dynallocated);
}
unsigned ncmul::return_type(void) const
{
- if (seq.size()==0) {
- // ncmul without factors: should not happen, but commutes
+ if (seq.empty())
return return_types::commutative;
- }
- bool all_commutative=1;
- unsigned rt;
- exvector::const_iterator cit_noncommutative_element; // point to first found nc element
+ bool all_commutative = true;
+ exvector::const_iterator noncommutative_element; // point to first found nc element
- for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- rt=(*cit).return_type();
- if (rt==return_types::noncommutative_composite) return rt; // one ncc -> mul also ncc
- if ((rt==return_types::noncommutative)&&(all_commutative)) {
+ exvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
+ unsigned rt = i->return_type();
+ if (rt == return_types::noncommutative_composite)
+ return rt; // one ncc -> mul also ncc
+ if ((rt == return_types::noncommutative) && (all_commutative)) {
// first nc element found, remember position
- cit_noncommutative_element=cit;
- all_commutative=0;
+ noncommutative_element = i;
+ all_commutative = false;
}
- if ((rt==return_types::noncommutative)&&(!all_commutative)) {
+ if ((rt == return_types::noncommutative) && (!all_commutative)) {
// another nc element found, compare type_infos
- if ((*cit_noncommutative_element).return_type_tinfo()!=(*cit).return_type_tinfo()) {
+ if (noncommutative_element->return_type_tinfo() != i->return_type_tinfo()) {
// diffent types -> mul is ncc
return return_types::noncommutative_composite;
}
}
+ ++i;
}
// all factors checked
GINAC_ASSERT(!all_commutative); // not all factors should commute, because this is a ncmul();
unsigned ncmul::return_type_tinfo(void) const
{
- if (seq.size()==0) {
- // mul without factors: should not happen
+ if (seq.empty())
return tinfo_key;
- }
+
// return type_info of first noncommutative element
- for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- if ((*cit).return_type()==return_types::noncommutative) {
- return (*cit).return_type_tinfo();
- }
+ 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;
}
+
// no noncommutative element found, should not happen
return tinfo_key;
}
ex simplified_ncmul(const exvector & v)
{
- if (v.size()==0) {
+ if (v.empty())
return _ex1();
- } else if (v.size()==1) {
+ else if (v.size() == 1)
return v[0];
- }
- return (new ncmul(v))->setflag(status_flags::dynallocated |
- status_flags::evaluated);
+ else
+ return (new ncmul(v))->setflag(status_flags::dynallocated |
+ status_flags::evaluated);
}
} // namespace GiNaC
// Add symbol the sym_desc_vec (used internally by get_symbol_stats())
static void add_symbol(const symbol *s, sym_desc_vec &v)
{
- sym_desc_vec::iterator it = v.begin(), itend = v.end();
+ sym_desc_vec::const_iterator it = v.begin(), itend = v.end();
while (it != itend) {
if (it->sym->compare(*s) == 0) // If it's already in there, don't add it a second time
return;
- it++;
+ ++it;
}
sym_desc d;
d.sym = s;
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++;
+ ++it;
}
sort(v.begin(), v.end());
#if 0
while (it != itend) {
std::clog << " " << *it->sym << ": deg_a=" << it->deg_a << ", deg_b=" << it->deg_b << ", ldeg_a=" << it->ldeg_a << ", ldeg_b=" << it->ldeg_b << ", max_deg=" << it->max_deg << ", max_lcnops=" << it->max_lcnops << endl;
std::clog << " lcoeff_a=" << a.lcoeff(*(it->sym)) << ", lcoeff_b=" << b.lcoeff(*(it->sym)) << endl;
- it++;
+ ++it;
}
#endif
}
if (is_ex_of_type(a,numeric) || // algorithm does not trap a==0
is_ex_of_type(a,symbol)) // shortcut
return a;
+
// If no lst of variables to factorize in was specified we have to
// invent one now. Maybe one can optimize here by reversing the order
// or so, I don't know.
if (l.nops()==0) {
sym_desc_vec sdv;
get_symbol_stats(a, _ex0(), sdv);
- for (sym_desc_vec::iterator it=sdv.begin(); it!=sdv.end(); ++it)
+ sym_desc_vec::const_iterator it = sdv.begin(), itend = sdv.end();
+ while (it != itend) {
args.append(*it->sym);
+ ++it;
+ }
} else {
args = l;
}
+
// Find the symbol to factor in at this stage
if (!is_ex_of_type(args.op(0), symbol))
throw (std::runtime_error("sqrfree(): invalid factorization variable"));
const symbol x = ex_to<symbol>(args.op(0));
+
// convert the argument from something in Q[X] to something in Z[X]
numeric lcm = lcm_of_coefficients_denominators(a);
ex tmp = multiply_lcm(a,lcm);
+
// find the factors
exvector factors = sqrfree_yun(tmp,x);
+
// construct the next list of symbols with the first element popped
- lst newargs;
- for (int i=1; i<args.nops(); ++i)
- newargs.append(args.op(i));
+ lst newargs = args;
+ newargs.remove_first();
+
// recurse down the factors in remaining vars
if (newargs.nops()>0) {
- for (exvector::iterator i=factors.begin(); i!=factors.end(); ++i)
+ exvector::iterator i = factors.begin(), end = factors.end();
+ while (i != end) {
*i = sqrfree(*i, newargs);
+ ++i;
+ }
}
+
// Done with recursion, now construct the final result
ex result = _ex1();
- exvector::iterator it = factors.begin();
- for (int p = 1; it!=factors.end(); ++it, ++p)
+ exvector::const_iterator it = factors.begin(), itend = factors.end();
+ for (int p = 1; it!=itend; ++it, ++p)
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 inserting what has been lost back into the result:
ex pseries::normal(lst &sym_lst, lst &repl_lst, int level) const
{
epvector newseq;
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
ex restexp = i->rest.normal();
if (!restexp.is_zero())
newseq.push_back(expair(restexp, i->coeff));
+ ++i;
}
ex n = pseries(relational(var,point), newseq);
return (new lst(replace_with_symbol(n, sym_lst, repl_lst), _ex1()))->setflag(status_flags::dynallocated);
{
epvector s;
s.reserve(seq.size());
- for (epvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- s.push_back(split_ex_to_pair(recombine_pair_to_ex(*it).to_rational(repl_lst)));
- // s.push_back(combine_ex_with_coeff_to_pair((*it).rest.to_rational(repl_lst),
+ 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_lst)));
+ ++i;
}
ex oc = overall_coeff.to_rational(repl_lst);
if (oc.info(info_flags::numeric))
return thisexpairseq(s, overall_coeff);
- else s.push_back(combine_ex_with_coeff_to_pair(oc,_ex1()));
+ else
+ s.push_back(combine_ex_with_coeff_to_pair(oc, _ex1()));
return thisexpairseq(s, default_overall_coeff());
}
ourflags.default_float_format = cln::float_format(cln::the<cln::cl_F>(num));
cln::print_real(os, ourflags, num);
}
- return;
}
/** This method adds to the output so it blends more consistently together
static std::vector< cln::cl_RA > results;
static int highest_result = 0;
// algorithm not applicable to B(0), so just store it
- if (results.size()==0)
+ if (results.empty())
results.push_back(cln::cl_RA(1));
int n = nn.to_long();
// second part: add terms coming from overall_factor (if != 0)
if (!a.overall_coeff.is_zero()) {
- for (epvector::const_iterator cit=a.seq.begin(); cit!=a.seq.end(); ++cit) {
- sum.push_back(a.combine_pair_with_coeff_to_pair(*cit,ex_to<numeric>(a.overall_coeff).mul_dyn(_num2())));
+ epvector::const_iterator i = a.seq.begin(), end = a.seq.end();
+ while (i != end) {
+ sum.push_back(a.combine_pair_with_coeff_to_pair(*i, ex_to<numeric>(a.overall_coeff).mul_dyn(_num2())));
+ ++i;
}
sum.push_back(expair(ex_to<numeric>(a.overall_coeff).power_dyn(_num2()),_ex1()));
}
<< std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
<< std::endl;
unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
- for (unsigned i=0; i<seq.size(); ++i) {
+ unsigned num = seq.size();
+ for (unsigned i=0; i<num; ++i) {
seq[i].rest.print(c, level + delta_indent);
seq[i].coeff.print(c, level + delta_indent);
c.s << std::string(level + delta_indent, ' ') << "-----" << std::endl;
// objects of type pseries must not have any zero entries, so the
// trivial (zero) pseries needs a special treatment here:
- if (seq.size() == 0)
+ if (seq.empty())
c.s << '0';
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
// print a sign, if needed
if (i != seq.begin())
c.s << '+';
}
} else
Order(power(var-point,i->coeff)).print(c);
+ ++i;
}
if (precedence() <= level)
ex pseries::coeff(const ex &s, int n) const
{
if (var.is_equal(s)) {
- if (seq.size() == 0)
+ if (seq.empty())
return _ex0();
// Binary search in sequence for given power
ex pseries::expand(unsigned options) const
{
epvector newseq;
- for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
ex restexp = i->rest.expand();
if (!restexp.is_zero())
newseq.push_back(expair(restexp, i->coeff));
+ ++i;
}
return (new pseries(relational(var,point), newseq))
->setflag(status_flags::dynallocated | status_flags::expanded);
bool pseries::is_terminating(void) const
{
- return seq.size() == 0 || !is_order_function((seq.end()-1)->rest);
+ return seq.empty() || !is_order_function((seq.end()-1)->rest);
}
// repeat the above derivation. The leading power of C2(x) = A2(x)^2 is
// then of course x^(p*m) but the recurrence formula still holds.
- if (seq.size()==0) {
+ if (seq.empty()) {
// as a spacial case, handle the empty (zero) series honoring the
// usual power laws such as implemented in power::eval()
if (p.real().is_zero())
/** Return a new pseries object with the powers shifted by deg. */
pseries pseries::shift_exponents(int deg) const
{
- epvector newseq(seq);
- for (epvector::iterator i=newseq.begin(); i!=newseq.end(); ++i)
- i->coeff = i->coeff + deg;
+ epvector newseq = seq;
+ epvector::iterator i = newseq.begin(), end = newseq.end();
+ while (i != end) {
+ i->coeff += deg;
+ ++i;
+ }
return pseries(relational(var, point), newseq);
}
{
GINAC_ASSERT(f.seq.size()==seq.size());
if (f.gethash()!=hashvalue) return false;
- for (unsigned i=0; i<seq.size(); ++i)
+ unsigned num = seq.size();
+ for (unsigned i=0; i<num; ++i)
if (!seq[i].is_equal(f.seq[i])) return false;
++last_access = access_counter;
++successful_hits;
bool remember_table_list::lookup_entry(function const & f, ex & result) const
{
- for (const_iterator cit=begin(); cit!=end(); ++cit) {
- if ((*cit).is_equal(f)) {
- result = (*cit).get_result();
+ const_iterator i = begin(), iend = end();
+ while (i != iend) {
+ if (i->is_equal(f)) {
+ result = i->get_result();
return true;
}
+ ++i;
}
return false;
}
default: c.s << '?'; break;
}
c.s << '(';
- for (unsigned i=0; i<children.size(); i++) {
+ unsigned num = children.size();
+ for (unsigned i=0; i<num; i++) {
children[i].print(c);
- if (i != children.size() - 1)
+ if (i != num - 1)
c.s << ",";
}
c.s << ')';
const spinidx & i2 = ex_to<spinidx>(i.op(2));
// Convolutions are zero
- if (static_cast<const indexed &>(i).get_dummy_indices().size() != 0)
+ if (!(static_cast<const indexed &>(i).get_dummy_indices().empty()))
return _ex0();
// Numeric evaluation
GINAC_ASSERT(is_ex_of_type(i.op(0), tensepsilon));
// Convolutions are zero
- if (static_cast<const indexed &>(i).get_dummy_indices().size() != 0)
+ if (!(static_cast<const indexed &>(i).get_dummy_indices().empty()))
return _ex0();
// Numeric evaluation
unsigned serial = 0;
while (i != end) {
fcns.insert(make_pair(i->get_name(), fcn_desc(f_ginac_function, i->get_nparams(), serial)));
- i++;
+ ++i;
serial++;
}
}
// Return the next function which partially matches
while (index != fcns.end()) {
const char *fcn_name = index->first.c_str();
- index++;
+ ++index;
if (strncmp(fcn_name, text, len) == 0)
return strdup(fcn_name);
}