From dcc848e23e4d793b2b1095012a8951f5245a68d5 Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Tue, 4 Mar 2003 23:59:06 +0000 Subject: [PATCH] return type and parameter type of nops() and op()/let_op() (respectively) is now a size_t --- doc/tutorial/ginac.texi | 20 +++++++------- ginac/add.cpp | 2 +- ginac/basic.cpp | 57 +++++++++++++++++++++------------------ ginac/basic.h | 13 ++++----- ginac/clifford.cpp | 28 +++++++++---------- ginac/color.cpp | 6 ++--- ginac/container.pl | 18 ++++++------- ginac/ex.cpp | 6 ++--- ginac/ex.h | 14 +++++----- ginac/expairseq.cpp | 28 +++++++++---------- ginac/expairseq.h | 4 +-- ginac/exprseq_suppl.cpp | 4 +-- ginac/fderivative.cpp | 4 +-- ginac/function.pl | 16 +++++------ ginac/idx.cpp | 6 ++--- ginac/idx.h | 8 +++--- ginac/indexed.cpp | 48 ++++++++++++++++----------------- ginac/inifcns.cpp | 14 +++++----- ginac/matrix.cpp | 22 +++++++-------- ginac/matrix.h | 8 +++--- ginac/mul.cpp | 45 +++++++++---------------------- ginac/ncmul.cpp | 44 +++++++++++++++--------------- ginac/ncmul.h | 2 +- ginac/normal.cpp | 60 ++++++++++++++++++++--------------------- ginac/power.cpp | 17 ++++++------ ginac/power.h | 4 +-- ginac/pseries.cpp | 14 +++++----- ginac/pseries.h | 4 +-- ginac/relational.cpp | 5 ++-- ginac/relational.h | 4 +-- ginac/remember.cpp | 4 +-- ginac/symbol.cpp | 2 +- ginac/symmetry.cpp | 10 +++---- ginac/tensor.cpp | 14 +++++----- ginsh/ginsh_parser.yy | 4 +-- 35 files changed, 269 insertions(+), 290 deletions(-) diff --git a/doc/tutorial/ginac.texi b/doc/tutorial/ginac.texi index 7ffc1d0a..f0369865 100644 --- a/doc/tutorial/ginac.texi +++ b/doc/tutorial/ginac.texi @@ -2984,8 +2984,8 @@ for an explanation of these. GiNaC provides the two methods @example -unsigned ex::nops(); -ex ex::op(unsigned i); +size_t ex::nops(); +ex ex::op(size_t i); @end example for accessing the subexpressions in the container-like GiNaC classes like @@ -3450,7 +3450,7 @@ ex calc_trace(ex e) return ex_to(e).trace(); else if (is_a(e)) @{ ex sum = 0; - for (unsigned i=0; i)(e)) @{ @@ -4491,9 +4491,9 @@ static void my_print(const ex & e) else cout << e.bp->class_name(); cout << "("; - unsigned n = e.nops(); + size_t n = e.nops(); if (n) - for (unsigned i=0; i(index)) - return op(ex_to(index).to_int()); + return op(static_cast(ex_to(index).to_int())); - throw(std::invalid_argument("non-numeric indices not supported by this type")); + throw(std::invalid_argument(std::string("non-numeric indices not supported by ") + class_name())); } -ex basic::operator[](int i) const +ex basic::operator[](size_t i) const { return op(i); } @@ -207,10 +207,10 @@ ex & basic::operator[](const ex & index) if (is_exactly_a(index)) return let_op(ex_to(index).to_int()); - throw(std::invalid_argument("non-numeric indices not supported by this type")); + throw(std::invalid_argument(std::string("non-numeric indices not supported by ") + class_name())); } -ex & basic::operator[](int i) +ex & basic::operator[](size_t i) { return let_op(i); } @@ -224,7 +224,7 @@ bool basic::has(const ex & pattern) const lst repl_lst; if (match(pattern, repl_lst)) return true; - for (unsigned i=0; isetflag(status_flags::dynallocated); copy->clearflag(status_flags::hash_calculated | status_flags::expanded); ex e(*copy); - for (unsigned i=0; ildegree(si[i].sym); si[i].deg = this->degree(si[i].sym); @@ -306,14 +306,14 @@ ex basic::collect(const ex & s, bool distributed) const // Calculate coeff*x1^c1*...*xn^cn ex y = _ex1; - for (int i=0; i=0; n--) + size_t n = s.nops() - 1; + while (true) { x = x.collect(s[n]); + if (n == 0) + break; + n--; + } } } else { @@ -479,7 +484,7 @@ bool basic::match(const ex & pattern, lst & repl_lst) const // Wildcard matches anything, but check whether we already have found // a match for that wildcard first (if so, it the earlier match must // be the same expression) - for (unsigned i=0; i(repl_lst.op(i).op(1))); } @@ -506,7 +511,7 @@ bool basic::match(const ex & pattern, lst & repl_lst) const return false; // Otherwise the subexpressions must match one-to-one - for (unsigned i=0; i(ls.op(i)))) return lr.op(i); } } else { - for (unsigned i=0; i(ls.op(i)), repl_lst)) return lr.op(i).subs(repl_lst, options | subs_options::subs_no_pattern); // avoid infinite recursion when re-substituting the wildcards @@ -653,7 +658,7 @@ unsigned basic::return_type_tinfo(void) const unsigned basic::calchash(void) const { unsigned v = golden_ratio_hash(tinfo()); - for (unsigned i=0; i(this))->op(i).gethash(); } @@ -708,7 +713,7 @@ ex basic::subs(const ex & e, unsigned options) const } lst ls; lst lr; - for (unsigned i=0; i // for size_t #include // CINT needs to work properly with #include @@ -96,13 +97,13 @@ public: // only const functions please (may break reference counting) virtual void dbgprinttree(void) const; virtual unsigned precedence(void) const; virtual bool info(unsigned inf) const; - virtual unsigned nops() const; - virtual ex op(int i) const; + virtual size_t nops() const; + virtual ex op(size_t i) const; virtual ex operator[](const ex & index) const; - virtual ex operator[](int i) const; - virtual ex & let_op(int i); + virtual ex operator[](size_t i) const; + virtual ex & let_op(size_t i); virtual ex & operator[](const ex & index); - virtual ex & operator[](int i); + virtual ex & operator[](size_t i); virtual ex expand(unsigned options = 0) const; virtual bool has(const ex & other) const; virtual ex map(map_function & f) const; @@ -140,7 +141,7 @@ protected: // functions that should be called from class ex only // non-virtual functions in this class public: ex subs(const ex & e, unsigned options = 0) const; - ex diff(const symbol & s, unsigned nth=1) const; + ex diff(const symbol & s, unsigned nth = 1) const; int compare(const basic & other) const; bool is_equal(const basic & other) const; const basic & hold(void) const; diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index 0918fe42..9a1330e4 100644 --- a/ginac/clifford.cpp +++ b/ginac/clifford.cpp @@ -525,7 +525,7 @@ static bool is_clifford_tinfo(unsigned ti) /** Take trace of a string of an even number of Dirac gammas given a vector * of indices. */ -static ex trace_string(exvector::const_iterator ix, unsigned num) +static ex trace_string(exvector::const_iterator ix, size_t num) { // Tr gamma.mu gamma.nu = 4 g.mu.nu if (num == 2) @@ -547,8 +547,8 @@ static ex trace_string(exvector::const_iterator ix, unsigned num) exvector v(num - 2); int sign = 1; ex result; - for (unsigned i=1; i(e.op(0).op(0)); - unsigned num = e.nops(); + size_t num = e.nops(); if (has_gamma5) { @@ -625,23 +625,23 @@ ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE) // I/4! * epsilon0123.mu1.mu2.mu3.mu4 * Tr gamma.mu1 gamma.mu2 gamma.mu3 gamma.mu4 S_2k // (the epsilon is always 4-dimensional) exvector ix(num-1), bv(num-1); - for (unsigned i=1; i(e_expanded)) return color_trace(e_expanded, rl); - unsigned num = e.nops(); + size_t num = e.nops(); if (num == 2) { @@ -573,7 +573,7 @@ ex color_trace(const ex & e, unsigned char rl) exvector v1; v1.reserve(num - 2); - for (unsigned i=0; i=0); GINAC_ASSERT(i=0); GINAC_ASSERT(iinfo(inf); } - unsigned nops() const { return bp->nops(); } + size_t nops() const { return bp->nops(); } ex expand(unsigned options=0) const; bool has(const ex & pattern) const { return bp->has(pattern); } ex map(map_function & f) const { return bp->map(f); } @@ -159,12 +159,12 @@ public: ex symmetrize_cyclic(void) const; ex symmetrize_cyclic(const lst & l) const; ex eval_ncmul(const exvector & v) const { return bp->eval_ncmul(v); } - ex op(int i) const { return bp->op(i); } + ex op(size_t i) const { return bp->op(i); } ex operator[](const ex & index) const { return (*bp)[index]; } - ex operator[](int i) const { return (*bp)[i]; } - ex & let_op(int i); + ex operator[](size_t i) const { return (*bp)[i]; } + ex & let_op(size_t i); ex & operator[](const ex & index); - ex & operator[](int i); + ex & operator[](size_t i); ex lhs(void) const; ex rhs(void) const; int compare(const ex & other) const; @@ -371,7 +371,7 @@ inline bool are_ex_trivially_equal(const ex &e1, const ex &e2) } // wrapper functions around member functions -inline unsigned nops(const ex & thisex) +inline size_t nops(const ex & thisex) { return thisex.nops(); } inline ex expand(const ex & thisex, unsigned options = 0) @@ -461,7 +461,7 @@ inline ex symmetrize_cyclic(const ex & thisex) inline ex symmetrize_cyclic(const ex & thisex, const lst & l) { return thisex.symmetrize_cyclic(l); } -inline ex op(const ex & thisex, int i) +inline ex op(const ex & thisex, size_t i) { return thisex.op(i); } inline ex lhs(const ex & thisex) diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index 5c3c2fe7..0fbbf543 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -197,8 +197,8 @@ void expairseq::print(const print_context &c, unsigned level) const << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec << ", nops=" << nops() << std::endl; - unsigned num = seq.size(); - for (unsigned i=0; i(pattern.op(i))) { has_global_wildcard = true; global_wildcard = pattern.op(i); @@ -347,12 +347,12 @@ bool expairseq::match(const ex & pattern, lst & repl_lst) const // Chop into terms exvector ops; ops.reserve(nops()); - for (unsigned i=0; ireserve(num); - for (unsigned i=0; ipush_back(split_ex_to_pair(ops[i])); ex rest = thisexpairseq(vp, default_overall_coeff()); - for (unsigned i=0; i touched(num); unsigned number_of_zeroes = 0; @@ -1565,7 +1565,7 @@ epvector * expairseq::subschildren(const lst &ls, const lst &lr, unsigned option // is a product or power. In this case we have to recombine the pairs // because the numeric coefficients may be part of the search pattern. bool complex_subs = false; - for (unsigned i=0; i(ls.op(i)) || is_exactly_a(ls.op(i))) { complex_subs = true; break; diff --git a/ginac/expairseq.h b/ginac/expairseq.h index add8a8f9..8f4b6a89 100644 --- a/ginac/expairseq.h +++ b/ginac/expairseq.h @@ -89,8 +89,8 @@ public: void print(const print_context & c, unsigned level = 0) const; unsigned precedence(void) const {return 10;} bool info(unsigned inf) const; - unsigned nops() const; - ex op(int i) const; + size_t nops() const; + ex op(size_t i) const; ex map(map_function & f) const; ex eval(int level=0) const; ex to_rational(lst &repl_lst) const; diff --git a/ginac/exprseq_suppl.cpp b/ginac/exprseq_suppl.cpp index e348853c..3653b582 100644 --- a/ginac/exprseq_suppl.cpp +++ b/ginac/exprseq_suppl.cpp @@ -33,11 +33,9 @@ bool exprseq::info(unsigned inf) const return basic::info(inf); } -ex exprseq::op(int i) const +ex exprseq::op(size_t i) const { - GINAC_ASSERT(i>=0); GINAC_ASSERT(i(c).delta_indent; - for (unsigned i=0; iop(i).gethash(); } @@ -875,8 +875,8 @@ ex function::derivative(const symbol & s) const } else { // Chain rule ex arg_diff; - unsigned num = seq.size(); - for (unsigned i=0; i(ls.op(i)))) { // Substitution index->index diff --git a/ginac/idx.h b/ginac/idx.h index 7fc743b5..e9587e42 100644 --- a/ginac/idx.h +++ b/ginac/idx.h @@ -50,8 +50,8 @@ public: public: void print(const print_context & c, unsigned level = 0) const; bool info(unsigned inf) const; - unsigned nops() const; - ex op(int i) const; + size_t nops() const; + ex op(size_t i) const; ex map(map_function & f) const; ex evalf(int level = 0) const; ex subs(const lst & ls, const lst & lr, unsigned options = 0) const; @@ -249,7 +249,7 @@ inline void find_dummy_indices(const exvector & v, exvector & out_dummy) } /** Count the number of dummy index pairs in an index vector. */ -inline unsigned count_dummy_indices(const exvector & v) +inline size_t count_dummy_indices(const exvector & v) { exvector free_indices, dummy_indices; find_free_and_dummy(v.begin(), v.end(), free_indices, dummy_indices); @@ -257,7 +257,7 @@ inline unsigned count_dummy_indices(const exvector & v) } /** Count the number of dummy index pairs in an index vector. */ -inline unsigned count_free_indices(const exvector & v) +inline size_t count_free_indices(const exvector & v) { exvector free_indices, dummy_indices; find_free_and_dummy(v.begin(), v.end(), free_indices, dummy_indices); diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index 6e53a589..5799642a 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -294,7 +294,7 @@ ex indexed::expand(unsigned options) const // expand_indexed expands (a+b).i -> a.i + b.i const ex & base = seq[0]; ex sum = _ex0; - for (unsigned i=0; i 0) { @@ -548,10 +548,10 @@ static ex rename_dummy_indices(const ex & e, exvector & global_dummy_indices, ex // Construct lists of index symbols exlist local_syms, global_syms; - for (unsigned i=0; i(f) && f.op(1).is_equal(_ex2)) { v.push_back(f.op(0)); @@ -670,7 +670,7 @@ ex simplify_indexed_product(const ex & e, exvector & free_indices, exvector & du } else if (is_exactly_a(f)) { // Noncommutative factor found, split it as well non_commutative = true; // everything becomes noncommutative, ncmul will sort out the commutative factors later - for (unsigned j=0; j(symmterm_) && is_exactly_a(symmterm_.op(symmterm_.nops()-1))) { coeff = symmterm_.op(symmterm_.nops()-1); @@ -884,7 +884,7 @@ public: ex symmterm; /**< symmetrized term */ ex coeff; /**< coefficient of symmetrized term */ ex orig; /**< original term */ - unsigned num; /**< how many symmetrized terms resulted from the original term */ + size_t num; /**< how many symmetrized terms resulted from the original term */ }; class symminfo_is_less_by_symmterm { @@ -941,7 +941,7 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi ex sum; free_indices.clear(); - for (unsigned i=0; i(sum) ? sum.nops() : 1); + size_t num_terms_orig = (is_exactly_a(sum) ? sum.nops() : 1); if (num_terms_orig < 2 || dummy_indices.size() < 2) return sum; @@ -983,7 +983,7 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi // Chop the sum into terms and symmetrize each one over the dummy // indices std::vector terms; - for (unsigned i=0; i terms_pass2; for (std::vector::const_iterator i=terms.begin(); i!=terms.end(); ) { - unsigned num = 1; + size_t num = 1; std::vector::const_iterator j = i + 1; while (j != terms.end() && j->symm == i->symm) { num++; @@ -1015,8 +1015,8 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi std::vector sy; for (std::vector::const_iterator i=terms_pass2.begin(); i!=terms_pass2.end(); ++i) { if (is_exactly_a(i->symm)) { - unsigned num = i->symm.nops(); - for (unsigned j=0; jsymm.nops(); + for (size_t j=0; jsymm.op(j), i->orig, num)); } else sy.push_back(symminfo(i->symm, i->orig, 1)); @@ -1063,7 +1063,7 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi for (std::vector::const_iterator i=sy_pass2.begin(); i!=sy_pass2.end(); ) { // How many symmetrized terms of this original term are left? - unsigned num = 1; + size_t num = 1; std::vector::const_iterator j = i + 1; while (j != sy_pass2.end() && j->orig == i->orig) { num++; @@ -1224,10 +1224,10 @@ void scalar_products::add(const ex & v1, const ex & v2, const ex & dim, const ex void scalar_products::add_vectors(const lst & l, const ex & dim) { // Add all possible pairs of products - unsigned num = l.nops(); - for (unsigned i=0; i(symbols.op(c)),1); linpart -= co*symbols.op(c); sys(r,c) = co; @@ -486,7 +486,7 @@ ex lsolve(const ex &eqns, const ex &symbols, unsigned options) } // test if system is linear and fill vars matrix - for (unsigned i=0; i= r) break; // matrix smaller than list: throw away excessive elements m[y*c+x] = l.op(i); @@ -193,24 +193,22 @@ void matrix::print(const print_context & c, unsigned level) const } /** nops is defined to be rows x columns. */ -unsigned matrix::nops() const +size_t matrix::nops() const { - return row*col; + return static_cast(row) * static_cast(col); } /** returns matrix entry at position (i/col, i%col). */ -ex matrix::op(int i) const +ex matrix::op(size_t i) const { - GINAC_ASSERT(i>=0); GINAC_ASSERT(i=0); GINAC_ASSERT(i cols) cols = l.op(i).nops(); @@ -1474,11 +1472,11 @@ ex lst_to_matrix(const lst & l) ex diag_matrix(const lst & l) { - unsigned dim = l.nops(); + size_t dim = l.nops(); matrix &m = *new matrix(dim, dim); m.setflag(status_flags::dynallocated); - for (unsigned i=0; i(c)) { c.s << class_name() << '('; op(0).print(c); - for (unsigned i=1; i subsed(seq.size(), false); exvector subsresult(seq.size()); - for (unsigned i=0; i(ls.op(i))) { @@ -575,9 +575,9 @@ ex mul::algebraic_subs_mul(const lst & ls, const lst & lr, unsigned options) con bool succeed = true; lst repls; - for (unsigned j=0; j::max(); lst repls; - for (unsigned j=0; jnops(); j++) { + for (size_t j=0; jnops(); j++) { if (!subsed[j] && tryfactsubs(op(j), ls.op(i), nummatches, repls)) { subsed[j] = true; subsresult[j] = op(j) * power(lr.op(i).subs(ex(repls), subs_options::subs_no_pattern) / ls.op(i).subs(ex(repls), subs_options::subs_no_pattern), nummatches); @@ -622,7 +622,7 @@ ex mul::algebraic_subs_mul(const lst & ls, const lst & lr, unsigned options) con } bool subsfound = false; - for (unsigned i=0; icoeff.is_equal(_ex1))) { ++number_of_adds; if (is_exactly_a(last_expanded)) { -#if 0 - // Expand a product of two sums, simple and robust version. - const add & add1 = ex_to(last_expanded); - const add & add2 = ex_to(cit->rest); - const int n1 = add1.nops(); - const int n2 = add2.nops(); - ex tmp_accu; - exvector distrseq; - distrseq.reserve(n2); - for (int i1=0; i1 - setflag(status_flags::dynallocated); - } - last_expanded = tmp_accu; -#else + // Expand a product of two sums, aggressive version. // Caring for the overall coefficients in separate loops can // sometimes give a performance gain of up to 15%! @@ -917,7 +898,7 @@ ex mul::expand(unsigned options) const tmp_accu += (new add(distrseq, oc))->setflag(status_flags::dynallocated); } last_expanded = tmp_accu; -#endif + } else { non_adds.push_back(split_ex_to_pair(last_expanded)); last_expanded = cit->rest; @@ -935,9 +916,9 @@ ex mul::expand(unsigned options) const if (is_exactly_a(last_expanded)) { const add & finaladd = ex_to(last_expanded); exvector distrseq; - int n = finaladd.nops(); + size_t n = finaladd.nops(); distrseq.reserve(n); - for (int i=0; i diff --git a/ginac/ncmul.cpp b/ginac/ncmul.cpp index d2a2f21f..dc328818 100644 --- a/ginac/ncmul.cpp +++ b/ginac/ncmul.cpp @@ -144,15 +144,15 @@ ex ncmul::expand(unsigned options) const intvector positions_of_adds(expanded_seq.size()); intvector number_of_add_operands(expanded_seq.size()); - int number_of_adds = 0; - int number_of_expanded_terms = 1; + size_t number_of_adds = 0; + size_t number_of_expanded_terms = 1; - unsigned current_position = 0; + size_t current_position = 0; exvector::const_iterator last = expanded_seq.end(); for (exvector::const_iterator cit=expanded_seq.begin(); cit!=last; ++cit) { if (is_exactly_a(*cit)) { positions_of_adds[number_of_adds] = current_position; - unsigned num_ops = cit->nops(); + size_t num_ops = cit->nops(); number_of_add_operands[number_of_adds] = num_ops; number_of_expanded_terms *= num_ops; number_of_adds++; @@ -174,7 +174,7 @@ ex ncmul::expand(unsigned options) const while (true) { exvector term = expanded_seq; - for (int i=0; i setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0))); @@ -251,12 +251,12 @@ ex ncmul::coeff(const ex & s, int n) const return _ex0; } -unsigned ncmul::count_factors(const ex & e) const +size_t ncmul::count_factors(const ex & e) const { if ((is_exactly_a(e)&&(e.return_type()!=return_types::commutative))|| (is_exactly_a(e))) { - unsigned factors=0; - for (unsigned i=0; i(e)&&(e.return_type()!=return_types::commutative))|| (is_exactly_a(e))) { - for (unsigned i=0; i // ncmul(...,x1,x2,...,x3,x4,...) (associativity) - unsigned factors = 0; + size_t factors = 0; exvector::const_iterator cit = evaledseq.begin(), citend = evaledseq.end(); while (cit != citend) factors += count_factors(*cit++); @@ -325,10 +325,10 @@ ex ncmul::eval(int level) const // determine return types unsignedvector rettypes; rettypes.reserve(assocseq.size()); - unsigned i = 0; - unsigned count_commutative=0; - unsigned count_noncommutative=0; - unsigned count_noncommutative_composite=0; + size_t i = 0; + size_t count_commutative=0; + size_t count_noncommutative=0; + size_t count_noncommutative_composite=0; cit = assocseq.begin(); citend = assocseq.end(); while (cit != citend) { switch (rettypes[i] = cit->return_type()) { @@ -355,8 +355,8 @@ ex ncmul::eval(int level) const commutativeseq.reserve(count_commutative+1); exvector noncommutativeseq; noncommutativeseq.reserve(assocseq.size()-count_commutative); - unsigned num = assocseq.size(); - for (unsigned i=0; ireturn_type_tinfo(); - unsigned rtt_num = rttinfos.size(); + size_t rtt_num = rttinfos.size(); // search type in vector of known types for (i=0; i 0); - unsigned s=0; + size_t s=0; for (i=0; isetflag(status_flags::dynallocated)); diff --git a/ginac/ncmul.h b/ginac/ncmul.h index 78a45ed6..b2ea9ca2 100644 --- a/ginac/ncmul.h +++ b/ginac/ncmul.h @@ -75,7 +75,7 @@ protected: // non-virtual functions in this class protected: - unsigned count_factors(const ex & e) const; + size_t count_factors(const ex & e) const; void append_factors(exvector & v, const ex & e) const; exvector expandchildren(unsigned options) const; public: diff --git a/ginac/normal.cpp b/ginac/normal.cpp index c9e9352f..297a052b 100644 --- a/ginac/normal.cpp +++ b/ginac/normal.cpp @@ -97,7 +97,7 @@ static bool get_first_symbol(const ex &e, const symbol *&x) x = &ex_to(e); return true; } else if (is_exactly_a(e) || is_exactly_a(e)) { - for (unsigned i=0; i(e)) { @@ -138,7 +138,7 @@ struct sym_desc { int max_deg; /** Maximum number of terms of leading coefficient of symbol in both polynomials */ - int max_lcnops; + size_t max_lcnops; /** Commparison operator for sorting */ bool operator<(const sym_desc &x) const @@ -173,7 +173,7 @@ static void collect_symbols(const ex &e, sym_desc_vec &v) if (is_a(e)) { add_symbol(&ex_to(e), v); } else if (is_exactly_a(e) || is_exactly_a(e)) { - for (unsigned i=0; i(e)) { collect_symbols(e.op(0), v); @@ -234,12 +234,12 @@ static numeric lcmcoeff(const ex &e, const numeric &l) return lcm(ex_to(e).denom(), l); else if (is_exactly_a(e)) { numeric c = _num1; - for (unsigned i=0; i(e)) { numeric c = _num1; - for (unsigned i=0; i(e)) { @@ -271,10 +271,10 @@ static numeric lcm_of_coefficients_denominators(const ex &e) static ex multiply_lcm(const ex &e, const numeric &lcm) { if (is_exactly_a(e)) { - unsigned num = e.nops(); + size_t num = e.nops(); exvector v; v.reserve(num + 1); numeric lcm_accum = _num1; - for (unsigned i=0; isetflag(status_flags::dynallocated); } else if (is_exactly_a(e)) { - unsigned num = e.nops(); + size_t num = e.nops(); exvector v; v.reserve(num); - for (unsigned i=0; isetflag(status_flags::dynallocated); } else if (is_exactly_a(e)) { @@ -1260,11 +1260,11 @@ ex gcd(const ex &a, const ex &b, ex *ca, ex *cb, bool check_args) if (is_exactly_a(b) && b.nops() > a.nops()) goto factored_b; factored_a: - unsigned num = a.nops(); + size_t num = a.nops(); exvector g; g.reserve(num); exvector acc_ca; acc_ca.reserve(num); ex part_b = b; - for (unsigned i=0; i(a) && a.nops() > b.nops()) goto factored_a; factored_b: - unsigned num = b.nops(); + size_t num = b.nops(); exvector g; g.reserve(num); exvector acc_cb; acc_cb.reserve(num); ex part_a = a; - for (unsigned i=0; i(e)) { - unsigned num = e.nops(); + size_t num = e.nops(); exvector terms; terms.reserve(num); ex gc; // Find the common GCD - for (unsigned i=0; i(x) || is_exactly_a(x)) { @@ -2276,16 +2276,16 @@ static ex find_common_factor(const ex & e, ex & factor, lst & repl) factor *= gc; // Now divide all terms by the GCD - for (unsigned i=0; i(t)) { - for (unsigned j=0; j(e)) { - unsigned num = e.nops(); + size_t num = e.nops(); exvector v; v.reserve(num); - for (unsigned i=0; isetflag(status_flags::dynallocated); diff --git a/ginac/power.cpp b/ginac/power.cpp index 7312a692..f2fbe703 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -228,14 +228,13 @@ bool power::info(unsigned inf) const return inherited::info(inf); } -unsigned power::nops() const +size_t power::nops() const { return 2; } -ex power::op(int i) const +ex power::op(size_t i) const { - GINAC_ASSERT(i>=0); GINAC_ASSERT(i<2); return i==0 ? basis : exponent; @@ -530,7 +529,7 @@ extern bool tryfactsubs(const ex &, const ex &, unsigned &, lst &); ex power::subs(const lst & ls, const lst & lr, unsigned options) const { if (options & subs_options::subs_algebraic) { - for (unsigned i=0; i::max(); lst repls; if (tryfactsubs(*this, ls.op(i), nummatches, repls)) @@ -678,7 +677,7 @@ ex power::expand_add(const add & a, int n) const if (n==2) return expand_add_2(a); - const int m = a.nops(); + const size_t m = a.nops(); exvector result; // The number of terms will be the number of combinatorial compositions, // i.e. the number of unordered arrangement of m nonnegative integers @@ -690,7 +689,7 @@ ex power::expand_add(const add & a, int n) const intvector upper_limit(m-1); int l; - for (int l=0; l(c).delta_indent; - unsigned num = seq.size(); - for (unsigned i=0; i= seq.size()) + if (i >= seq.size()) throw (std::out_of_range("op() out of range")); return seq[i].rest * power(var - point, seq[i].coeff); diff --git a/ginac/pseries.h b/ginac/pseries.h index 17ae934a..308d0457 100644 --- a/ginac/pseries.h +++ b/ginac/pseries.h @@ -44,8 +44,8 @@ public: public: void print(const print_context & c, unsigned level = 0) const; unsigned precedence(void) const {return 38;} // for clarity just below add::precedence - unsigned nops(void) const; - ex op(int i) const; + size_t nops(void) const; + ex op(size_t i) const; int degree(const ex &s) const; int ldegree(const ex &s) const; ex coeff(const ex &s, int n = 1) const; diff --git a/ginac/relational.cpp b/ginac/relational.cpp index 7c395eea..70dc5bd0 100644 --- a/ginac/relational.cpp +++ b/ginac/relational.cpp @@ -160,14 +160,13 @@ bool relational::info(unsigned inf) const return 0; } -unsigned relational::nops() const +size_t relational::nops() const { return 2; } -ex relational::op(int i) const +ex relational::op(size_t i) const { - GINAC_ASSERT(i>=0); GINAC_ASSERT(i<2); return i==0 ? lh : rh; diff --git a/ginac/relational.h b/ginac/relational.h index 133a25f3..c8044f58 100644 --- a/ginac/relational.h +++ b/ginac/relational.h @@ -54,8 +54,8 @@ public: void print(const print_context & c, unsigned level = 0) const; unsigned precedence(void) const {return 20;} bool info(unsigned inf) const; - unsigned nops() const; - ex op(int i) const; + size_t nops() const; + ex op(size_t i) const; ex map(map_function & f) const; ex eval(int level=0) const; diff --git a/ginac/remember.cpp b/ginac/remember.cpp index cdd346f7..cc8a6b88 100644 --- a/ginac/remember.cpp +++ b/ginac/remember.cpp @@ -44,8 +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; - unsigned num = seq.size(); - for (unsigned i=0; isetflag(status_flags::dynallocated); // If symbol is in sym_lst, return the existing symbol - for (unsigned i=0; i(sym_lst.op(i)) && (ex_to(sym_lst.op(i)).name == ex_to(s).name)) return sym_lst.op(i); } diff --git a/ginac/symmetry.cpp b/ginac/symmetry.cpp index f5623608..473bd5b9 100644 --- a/ginac/symmetry.cpp +++ b/ginac/symmetry.cpp @@ -205,8 +205,8 @@ void symmetry::print(const print_context & c, unsigned level) const default: c.s << '?'; break; } c.s << '('; - unsigned num = children.size(); - for (unsigned i=0; i v; v.reserve(i.nops() - 1); - for (unsigned j=1; j(ex_to(i.op(j)).get_value()).to_int()); int sign = permutation_sign(v.begin(), v.end()); // In a Minkowski space, check for covariant indices if (minkowski) { - for (unsigned j=1; j(x)) throw(std::runtime_error("indices of epsilon tensor in Minkowski space must be of type varidx")); @@ -347,7 +347,7 @@ bool tensor::replace_contr_index(exvector::iterator self, exvector::iterator oth again: if (self_idx->is_symbolic()) { - for (unsigned i=1; inops(); i++) { + for (size_t i=1; inops(); i++) { const idx &other_idx = ex_to(other->op(i)); if (is_dummy_pair(*self_idx, other_idx)) { @@ -462,7 +462,7 @@ bool spinmetric::contract_with(exvector::iterator self, exvector::iterator other again: if (self_idx->is_symbolic()) { - for (unsigned i=1; inops(); i++) { + for (size_t i=1; inops(); i++) { const idx &other_idx = ex_to(other->op(i)); if (is_dummy_pair(*self_idx, other_idx)) { @@ -495,15 +495,15 @@ bool tensepsilon::contract_with(exvector::iterator self, exvector::iterator othe GINAC_ASSERT(is_a(*self)); GINAC_ASSERT(is_a(*other)); GINAC_ASSERT(is_a(self->op(0))); - unsigned num = self->nops() - 1; + size_t num = self->nops() - 1; if (is_exactly_a(other->op(0)) && num+1 == other->nops()) { // Contraction of two epsilon tensors is a determinant bool variance = is_a(self->op(1)); matrix M(num, num); - for (unsigned i=0; iop(i+1), other->op(j+1), pos_sig); else if (variance) diff --git a/ginsh/ginsh_parser.yy b/ginsh/ginsh_parser.yy index d1485943..02318cbd 100644 --- a/ginsh/ginsh_parser.yy +++ b/ginsh/ginsh_parser.yy @@ -352,9 +352,9 @@ static ex f_determinant(const exprseq &e) static ex f_diag(const exprseq &e) { - unsigned dim = e.nops(); + size_t dim = e.nops(); matrix &m = *new matrix(dim, dim); - for (unsigned i=0; i