some cleanups
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Fri, 22 Jun 2001 01:03:27 +0000 (01:03 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Fri, 22 Jun 2001 01:03:27 +0000 (01:03 +0000)
21 files changed:
ginac/add.cpp
ginac/archive.cpp
ginac/clifford.cpp
ginac/color.cpp
ginac/container.pl
ginac/expairseq.cpp
ginac/expairseq.h
ginac/function.pl
ginac/indexed.cpp
ginac/inifcns_trans.cpp
ginac/matrix.cpp
ginac/mul.cpp
ginac/ncmul.cpp
ginac/normal.cpp
ginac/numeric.cpp
ginac/power.cpp
ginac/pseries.cpp
ginac/remember.cpp
ginac/symmetry.cpp
ginac/tensor.cpp
ginsh/ginsh_parser.yy

index 31e2f8f..28eeff5 100644 (file)
@@ -236,16 +236,20 @@ bool add::info(unsigned inf) const
                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;
                }
@@ -256,14 +260,16 @@ bool add::info(unsigned inf) const
 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;
 }
@@ -271,30 +277,34 @@ int add::degree(const ex & s) const
 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
@@ -304,19 +314,21 @@ 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
        
@@ -330,7 +342,7 @@ ex add::eval(int level) const
        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()));
        }
@@ -363,18 +375,19 @@ ex add::evalm(void) const
                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
@@ -389,9 +402,10 @@ ex add::derivative(const symbol & y) const
        // 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);
 }
@@ -408,18 +422,18 @@ bool add::is_equal_same_type(const basic & other) const
 
 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
@@ -500,13 +514,13 @@ ex add::expand(unsigned options) 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
index 2292228..c547916 100644 (file)
@@ -483,7 +483,7 @@ void archive_node::get_properties(propinfovector &v) const
                                found = true;
                                break;
                        }
-                       a++;
+                       ++a;
                }
                if (!found)
                        v.push_back(property_info(type, name));
@@ -546,11 +546,7 @@ void archive::clear(void)
 /** 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). */
index 7446592..a6a1333 100644 (file)
@@ -190,7 +190,7 @@ bool diracgamma::contract_with(exvector::iterator self, exvector::iterator other
                        while (it != other) {
                                if (!is_ex_of_type(*it, clifford))
                                        return false;
-                               it++;
+                               ++it;
                        }
 
                        it = self + 1;
@@ -243,11 +243,11 @@ ex clifford::simplify_ncmul(const exvector & v) const
                                }
                                if (it == first)
                                        break;
-                               it--;
+                               --it;
                        }
                        if (next_to_last == first)
                                break;
-                       next_to_last--;
+                       --next_to_last;
                }
        }
 
@@ -272,11 +272,11 @@ ex clifford::simplify_ncmul(const exvector & v) const
                                        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;
@@ -526,7 +526,7 @@ ex canonicalize_clifford(const ex & e)
                        // 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];
@@ -539,7 +539,7 @@ ex canonicalize_clifford(const ex & e)
                                        srl.let_op(i) = (lhs == canonicalize_clifford(sum));
                                        goto next_sym;
                                }
-                               it++;
+                               ++it;
                        }
 next_sym:      ;
                }
index 45521b7..195b93e 100644 (file)
@@ -165,7 +165,7 @@ ex color::simplify_ncmul(const exvector & v) const
                it++;
        }
 
-       if (s.size() == 0)
+       if (s.empty())
                return color(su3one(), representation_label);
        else
                return simplified_ncmul(s);
@@ -220,7 +220,7 @@ ex su3d::eval_indexed(const basic & i) const
        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
index bed117f..8f7cb87 100755 (executable)
@@ -200,7 +200,7 @@ class ${CONTAINER} : public basic
        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}
 
@@ -391,10 +391,10 @@ ex ${CONTAINER}::unarchive(const archive_node &n, const lst &sym_lst)
 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;
        }
 }
 
@@ -415,8 +415,11 @@ void ${CONTAINER}::print(const print_context & c, unsigned level) const
                    << ", 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 {
@@ -438,8 +441,10 @@ ex ${CONTAINER}::map(map_function & f) const
 {
        ${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);
@@ -538,13 +543,13 @@ void ${CONTAINER}::printseq(const print_context & c, char openbracket, char deli
        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);
        }
@@ -577,11 +582,11 @@ bool ${CONTAINER}::is_canonical() const
 {
        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;
                        }
@@ -603,8 +608,10 @@ ${STLT} ${CONTAINER}::evalchildren(int level) const
                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;
 }
@@ -615,28 +622,29 @@ ${STLT} * ${CONTAINER}::subschildren(const lst & ls, const lst & lr, bool no_pat
        // 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;
index 605494a..96da57c 100644 (file)
@@ -200,10 +200,11 @@ void expairseq::print(const print_context & c, unsigned level) const
                    << 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())) {
@@ -365,7 +366,7 @@ bool expairseq::match(const ex & pattern, lst & repl_lst) const
                                        ops.erase(it);
                                        goto found;
                                }
-                               it++;
+                               ++it;
                        }
                        return false; // no match found
 found:         ;
@@ -376,9 +377,10 @@ 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++) {
@@ -547,15 +549,17 @@ unsigned expairseq::return_type(void) const
 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();
@@ -942,7 +946,6 @@ void expairseq::construct_from_exvector(const exvector &v)
        canonicalize();
        combine_same_terms_sorted_seq();
 #endif // EXPAIRSEQ_USE_HASHTAB
-       return;
 }
 
 void expairseq::construct_from_epvector(const epvector &v)
@@ -959,7 +962,6 @@ 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.
@@ -1004,8 +1006,6 @@ void expairseq::make_flat(const exvector &v)
                }
                ++cit;
        }
-       
-       return;
 }
 
 /** Combine this expairseq with argument epvector.
@@ -1055,15 +1055,12 @@ void expairseq::make_flat(const epvector &v)
                }
                ++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());
 }
 
 
@@ -1113,7 +1110,6 @@ void expairseq::combine_same_terms_sorted_seq(void)
                seq.clear();
                construct_from_epvector(v);
        }
-       return;
 }
 
 #if EXPAIRSEQ_USE_HASHTAB
@@ -1240,7 +1236,7 @@ void expairseq::move_hashtab_entry(epvector::const_iterator oldpos,
 
 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;
        }
@@ -1349,9 +1345,11 @@ void expairseq::drop_coeff_0_terms(epvector::iterator &first_numeric,
  *  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;
 }
@@ -1359,12 +1357,11 @@ bool expairseq::has_coeff_0(void) const
 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;
        }
 }
@@ -1395,41 +1392,18 @@ void expairseq::combine_same_terms(void)
        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);
@@ -1460,9 +1434,9 @@ bool expairseq::is_canonical() const
        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)) {
index cebc016..1b5e211 100644 (file)
@@ -44,7 +44,6 @@ namespace GiNaC {
 #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
index 2fdfedf..baaf910 100755 (executable)
@@ -325,7 +325,7 @@ public:
 $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
@@ -668,7 +668,7 @@ void function::print(const print_context & c, unsigned level) const
                    << ", 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;
 
@@ -676,7 +676,8 @@ void function::print(const print_context & c, unsigned level) const
 
                // 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 << "(";
 
@@ -881,7 +882,8 @@ ex function::derivative(const symbol & s) const
        } 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
@@ -917,18 +919,18 @@ bool function::is_equal_same_type(const basic & other) const
 
 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();
 }
 
 //////////
index 4bbeeee..736c109 100644 (file)
@@ -645,12 +645,13 @@ try_again:
                        // 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();
@@ -659,13 +660,13 @@ try_again:
                        }
 
                        // 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
@@ -890,10 +891,12 @@ ex scalar_products::evaluate(const ex & v1, const ex & v2) const
 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;
        }
 }
 
index a37f716..89b0454 100644 (file)
@@ -108,7 +108,7 @@ static ex log_evalf(const ex & x)
 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);
@@ -595,7 +595,7 @@ static ex atan_eval(const ex & x)
 {
        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()))
index b133b61..8d2e0b8 100644 (file)
@@ -503,10 +503,10 @@ matrix matrix::add(const matrix & other) const
                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);
 }
@@ -521,10 +521,10 @@ matrix matrix::sub(const matrix & other) const
                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);
 }
@@ -689,9 +689,10 @@ ex matrix::determinant(unsigned algo) const
        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))
@@ -699,6 +700,7 @@ ex matrix::determinant(unsigned algo) const
                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:
@@ -778,13 +780,13 @@ ex matrix::determinant(unsigned algo) const
                        }
                        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)
@@ -840,10 +842,11 @@ ex matrix::charpoly(const symbol & lambda) const
                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
@@ -950,9 +953,11 @@ matrix matrix::solve(const matrix & vars,
        
        // 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:
@@ -1299,13 +1304,13 @@ int matrix::fraction_free_elimination(const bool det)
        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;
@@ -1357,11 +1362,11 @@ int matrix::fraction_free_elimination(const bool det)
                }
        }
        // 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;
 }
index 04941b3..a6a2df2 100644 (file)
@@ -245,16 +245,20 @@ bool mul::info(unsigned inf) const
                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;
                }
@@ -264,20 +268,26 @@ bool mul::info(unsigned inf) const
 
 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;
 }
@@ -290,27 +300,27 @@ ex mul::coeff(const ex & s, int n) const
        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);
@@ -329,26 +339,28 @@ ex mul::eval(int level) const
        
        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
        
@@ -359,7 +371,7 @@ ex mul::eval(int level) const
        }
        
        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) {
@@ -373,10 +385,12 @@ ex mul::eval(int level) const
                   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).
@@ -394,15 +408,17 @@ ex mul::evalf(int level) const
        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
@@ -421,15 +437,15 @@ 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) {
@@ -447,14 +463,15 @@ ex mul::evalm(void) const
 
 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);
 }
@@ -465,15 +482,21 @@ ex mul::simplify_ncmul(const exvector & v) const
  *  @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);
 }
@@ -490,30 +513,32 @@ bool mul::is_equal_same_type(const basic & other) const
 
 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;
@@ -521,13 +546,15 @@ unsigned mul::return_type(void) const
    
 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;
@@ -535,12 +562,12 @@ unsigned mul::return_type_tinfo(void) const
 
 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
@@ -700,7 +727,7 @@ ex mul::expand(unsigned options) 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);
 }
 
index dbd5732..7874509 100644 (file)
@@ -214,18 +214,24 @@ ex ncmul::expand(unsigned options) const
 
 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;
 }
@@ -235,7 +241,7 @@ ex ncmul::coeff(const ex & s, int n) const
        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();
@@ -246,17 +252,17 @@ ex ncmul::coeff(const ex & s, int n) const
                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);
@@ -283,10 +289,8 @@ void ncmul::append_factors(exvector & v, const ex & e) const
                (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;
@@ -318,30 +322,33 @@ ex ncmul::eval(int level) const
 
        // 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;
@@ -354,7 +361,7 @@ ex ncmul::eval(int level) const
                default:
                        throw(std::logic_error("ncmul::eval(): invalid return type"));
                }
-               ++i;
+               ++i; ++cit;
        }
        GINAC_ASSERT(count_commutative+count_noncommutative+count_noncommutative_composite==assocseq.size());
 
@@ -365,7 +372,8 @@ ex ncmul::eval(int level) const
                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
@@ -383,48 +391,51 @@ ex ncmul::eval(int level) const
                // 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);
        }
@@ -480,14 +491,17 @@ ex ncmul::thisexprseq(exvector * vp) const
  *  @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);
 }
@@ -499,30 +513,30 @@ int ncmul::compare_same_type(const basic & other) const
 
 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();
@@ -531,16 +545,17 @@ unsigned ncmul::return_type(void) const
    
 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;
 }
@@ -583,13 +598,13 @@ ex nonsimplified_ncmul(const exvector & v)
 
 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
index a016a76..8ee00c8 100644 (file)
@@ -155,11 +155,11 @@ typedef std::vector<sym_desc> sym_desc_vec;
 // 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;
@@ -205,7 +205,7 @@ static void get_symbol_stats(const ex &a, const ex &b, sym_desc_vec &v)
                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
@@ -214,7 +214,7 @@ static void get_symbol_stats(const ex &a, const ex &b, sym_desc_vec &v)
        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
 }
@@ -1755,6 +1755,7 @@ ex sqrfree(const ex &a, const lst &l)
        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.
@@ -1762,34 +1763,46 @@ ex sqrfree(const ex &a, const lst &l)
        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:
@@ -2191,10 +2204,12 @@ ex power::normal(lst &sym_lst, lst &repl_lst, int level) const
 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);
@@ -2345,14 +2360,16 @@ ex expairseq::to_rational(lst &repl_lst) const
 {
        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());
 }
 
index b29bf9f..ffcdfbf 100644 (file)
@@ -359,7 +359,6 @@ static void print_real_number(std::ostream &os, const cln::cl_R &num)
                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
@@ -1574,7 +1573,7 @@ const numeric bernoulli(const numeric &nn)
        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();
index 76c72ac..227da2f 100644 (file)
@@ -787,8 +787,10 @@ ex power::expand_add_2(const add & a) const
        
        // 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()));
        }
index 37f2958..2c8aa8f 100644 (file)
@@ -132,7 +132,8 @@ void pseries::print(const print_context & c, unsigned level) const
                    << 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;
@@ -150,9 +151,10 @@ void pseries::print(const print_context & c, unsigned level) const
                
                // 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 << '+';
@@ -196,6 +198,7 @@ void pseries::print(const print_context & c, unsigned level) const
                                }
                        } else
                                Order(power(var-point,i->coeff)).print(c);
+                       ++i;
                }
 
                if (precedence() <= level)
@@ -319,7 +322,7 @@ int pseries::ldegree(const ex &s) const
 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
@@ -418,10 +421,12 @@ ex pseries::subs(const lst & ls, const lst & lr, bool no_pattern) const
 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);
@@ -471,7 +476,7 @@ ex pseries::convert_to_poly(bool no_order) const
 
 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);
 }
 
 
@@ -771,7 +776,7 @@ ex pseries::power_const(const numeric &p, int deg) const
        // 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())
@@ -824,9 +829,12 @@ ex pseries::power_const(const numeric &p, int deg) const
 /** 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);
 }
 
index 3a92273..37e403c 100644 (file)
@@ -44,7 +44,8 @@ bool remember_table_entry::is_equal(function const & f) const
 {
        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;
@@ -120,11 +121,13 @@ void remember_table_list::add_entry(function const & f, ex const & result)
 
 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;
 }
index a07fbe7..7d56f6a 100644 (file)
@@ -164,9 +164,10 @@ void symmetry::print(const print_context & c, unsigned level = 0) const
                        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 << ')';
index 0991f58..00d0cdf 100644 (file)
@@ -268,7 +268,7 @@ ex spinmetric::eval_indexed(const basic & i) const
        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
@@ -294,7 +294,7 @@ ex tensepsilon::eval_indexed(const basic & i) const
        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
index 98213e2..5fc99fd 100644 (file)
@@ -570,7 +570,7 @@ void GiNaC::ginsh_get_ginac_functions(void)
        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++;
        }
 }
@@ -681,7 +681,7 @@ static char *fcn_generator(char *text, int state)
        // 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);
        }