From 82df718524319471d3a92fb051329aa8cd529c22 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Wed, 16 Dec 2015 22:02:25 +0100 Subject: [PATCH] Merge some cosmetic patches. This is a collection of some minor optimizations and indentation fixes. --- INSTALL | 4 +- doc/CodingStyle | 2 +- ginac/color.cpp | 8 +-- ginac/expairseq.cpp | 7 +-- ginac/expairseq.h | 6 +-- ginac/factor.cpp | 85 +++++++++++------------------- ginac/function.cppy | 4 +- ginac/inifcns.cpp | 4 +- ginac/inifcns_trans.cpp | 8 +-- ginac/mul.cpp | 44 ++++++++-------- ginac/normal.cpp | 74 +++++++++++++------------- ginac/operators.cpp | 16 +++--- ginac/polynomial/collect_vargs.cpp | 2 +- ginac/power.cpp | 53 +++++++++---------- ginac/pseries.cpp | 19 ++++--- 15 files changed, 149 insertions(+), 187 deletions(-) diff --git a/INSTALL b/INSTALL index 635ec4b6..08509aab 100644 --- a/INSTALL +++ b/INSTALL @@ -5,7 +5,7 @@ GiNaC requires the CLN library by Bruno Haible installed on your system. It is available from . You will also need a decent ISO C++-11 compiler. We recommend the C++ -compiler from the GNU compiler collection, GCC >= 4.9. If you have a +compiler from the GNU compiler collection, GCC >= 4.8. If you have a different or older compiler you are on your own. Note that you may have to use the same compiler you compiled CLN with because of differing name-mangling schemes. @@ -20,7 +20,7 @@ TeX are necessary. Known to work with: - Linux on x86 and x86_64 using - - GCC 4.8, 4.9, 5.1, and 5.2 + - GCC 4.8, 4.9, 5.1, 5.2, and 5.3 - Clang 3.5.0 Known not to work with: diff --git a/doc/CodingStyle b/doc/CodingStyle index e387bf29..b537f19b 100644 --- a/doc/CodingStyle +++ b/doc/CodingStyle @@ -27,7 +27,7 @@ please try to follow these rules. It will make our (and your) lives easier. :-) ---------------------- Any code in GiNaC should comply to the C++ standard, as defined by ISO/IEC -14882:1998(E). Don't use compiler-specific language extensions unless they +14882:2011(E). Don't use compiler-specific language extensions unless they are surrounded by appropriate "#ifdef"s, and you also provide a compliant version of the code in question for other compilers. diff --git a/ginac/color.cpp b/ginac/color.cpp index 0f7723e3..89377e24 100644 --- a/ginac/color.cpp +++ b/ginac/color.cpp @@ -400,9 +400,7 @@ bool su3d::contract_with(exvector::iterator self, exvector::iterator other, exve && ex_to(*self).has_dummy_index_for(other[1].op(1))) { exvector self_indices = ex_to(*self).get_indices(); - exvector dummy_indices; - dummy_indices.push_back(other[0].op(1)); - dummy_indices.push_back(other[1].op(1)); + exvector dummy_indices = {other[0].op(1), other[1].op(1)}; int sig; ex a = permute_free_index_to_front(self_indices, dummy_indices, sig); *self = numeric(5, 6); @@ -453,9 +451,7 @@ bool su3f::contract_with(exvector::iterator self, exvector::iterator other, exve && ex_to(*self).has_dummy_index_for(other[1].op(1))) { exvector self_indices = ex_to(*self).get_indices(); - exvector dummy_indices; - dummy_indices.push_back(other[0].op(1)); - dummy_indices.push_back(other[1].op(1)); + exvector dummy_indices = {other[0].op(1), other[1].op(1)}; int sig; ex a = permute_free_index_to_front(self_indices, dummy_indices, sig); *self = numeric(3, 2) * sig * I; diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index e99d21fe..55fa311b 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -601,11 +601,8 @@ bool expairseq::can_make_flat(const expair &p) const void expairseq::construct_from_2_ex_via_exvector(const ex &lh, const ex &rh) { - exvector v; - v.reserve(2); - v.push_back(lh); - v.push_back(rh); - construct_from_exvector(v); + const exvector v = {lh, rh}; + construct_from_exvector(std::move(v)); } void expairseq::construct_from_2_ex(const ex &lh, const ex &rh) diff --git a/ginac/expairseq.h b/ginac/expairseq.h index 41b077d5..f0a0b4e6 100644 --- a/ginac/expairseq.h +++ b/ginac/expairseq.h @@ -166,7 +166,7 @@ class make_flat_inserter return x; sort(dummies_of_factor.begin(), dummies_of_factor.end(), ex_is_less()); ex new_factor = rename_dummy_indices_uniquely(used_indices, - dummies_of_factor, x); + dummies_of_factor, x); combine_indices(dummies_of_factor); return new_factor; } @@ -175,8 +175,8 @@ class make_flat_inserter { exvector new_dummy_indices; set_union(used_indices.begin(), used_indices.end(), - dummies_of_factor.begin(), dummies_of_factor.end(), - std::back_insert_iterator(new_dummy_indices), ex_is_less()); + dummies_of_factor.begin(), dummies_of_factor.end(), + std::back_insert_iterator(new_dummy_indices), ex_is_less()); used_indices.swap(new_dummy_indices); } bool do_renaming; diff --git a/ginac/factor.cpp b/ginac/factor.cpp index 30d7953b..21f02426 100644 --- a/ginac/factor.cpp +++ b/ginac/factor.cpp @@ -916,8 +916,7 @@ static void berlekamp(const umodpoly& a, upvec& upv) return; } - list factors; - factors.push_back(a); + list factors = {a}; unsigned int size = 1; unsigned int r = 1; unsigned int q = cl_I_to_uint(R->modulus); @@ -937,8 +936,7 @@ static void berlekamp(const umodpoly& a, upvec& upv) div(*u, g, uo); if ( equal_one(uo) ) { throw logic_error("berlekamp: unexpected divisor."); - } - else { + } else { *u = uo; } factors.push_back(g); @@ -1021,8 +1019,7 @@ static void modsqrfree(const umodpoly& a, upvec& factors, vector& mult) mult[i] *= prime; } } - } - else { + } else { umodpoly ap; expt_1_over_p(a, prime, ap); size_t previ = mult.size(); @@ -1107,8 +1104,7 @@ static void same_degree_factor(const umodpoly& a, upvec& upv) for ( size_t i=0; i primes; - if ( primes.size() == 0 ) { - primes.push_back(3); primes.push_back(5); primes.push_back(7); + if (primes.empty()) { + primes = {3, 5, 7}; } if ( p >= primes.back() ) { unsigned int candidate = primes.back() + 2; while ( true ) { size_t n = primes.size()/2; for ( size_t i=0; i p ) break; + if (candidate > p) + break; } return candidate; } @@ -1405,8 +1402,7 @@ public: if ( len > n/2 ) return false; fill(k.begin(), k.begin()+len, 1); fill(k.begin()+len+1, k.end(), 0); - } - else { + } else { k[last++] = 0; k[last] = 1; } @@ -1429,8 +1425,7 @@ private: if ( d ) { if ( cache[pos].size() >= d ) { lr[group] = lr[group] * cache[pos][d-1]; - } - else { + } else { if ( cache[pos].size() == 0 ) { cache[pos].push_back(factors[pos] * factors[pos+1]); } @@ -1444,8 +1439,7 @@ private: } lr[group] = lr[group] * cache[pos].back(); } - } - else { + } else { lr[group] = lr[group] * factors[pos]; } } while ( i < n ); @@ -1456,8 +1450,7 @@ private: lr[1] = one; if ( n > 6 ) { split_cached(); - } - else { + } else { for ( size_t i=0; iretract(emod)); if ( n > halfmod ) { return n-mod; - } - else { + } else { return n; } } @@ -1937,8 +1924,7 @@ static vector multivar_diophant(const vector& a_, const ex& x, const ex& e = make_modular(buf, R); } } - } - else { + } else { upvec amod; for ( size_t i=0; i multivar_diophant(const vector& a_, const ex& x, const ex& if ( is_a(c) ) { nterms = c.nops(); z = c.op(0); - } - else { + } else { nterms = 1; z = c; } @@ -2090,8 +2075,7 @@ static ex hensel_multivar(const ex& a, const ex& x, const vector& I, res.append(U[i]); } return res; - } - else { + } else { lst res; return lst{}; } @@ -2325,8 +2309,7 @@ static ex factor_multivariate(const ex& poly, const exset& syms) for ( size_t i=1; i(ufaclst.op(i+1).lcoeff(x)); for ( int j=ftilde.size()-1; j>=0; --j ) { @@ -2486,8 +2468,7 @@ static ex factor_sqrfree(const ex& poly) int ld = poly.ldegree(x); ex res = factor_univariate(expand(poly/pow(x, ld)), x); return res * pow(x,ld); - } - else { + } else { ex res = factor_univariate(poly, x); return res; } @@ -2514,8 +2495,7 @@ struct apply_factor_map : public map_function { for ( size_t i=0; i(base) ) { res *= t; - } - else { + } else { ex f = factor_sqrfree(base); res *= pow(f, t.op(1)); } - } - else if ( is_a(t) ) { + } else if ( is_a(t) ) { ex f = factor_sqrfree(t); res *= f; - } - else { + } else { res *= t; } } diff --git a/ginac/function.cppy b/ginac/function.cppy index 686a76e6..0c551908 100644 --- a/ginac/function.cppy +++ b/ginac/function.cppy @@ -142,7 +142,7 @@ function_options & function_options::set_return_type(unsigned rt, const return_t { use_return_type = true; return_type = rt; - if (rtt != 0) + if (rtt != nullptr) return_type_tinfo = *rtt; else return_type_tinfo = make_return_type_t(); @@ -380,7 +380,7 @@ ex function::eval() const // Something has changed while sorting arguments, more evaluations later if (sig == 0) return _ex0; - return ex(sig) * thiscontainer(v); + return ex(sig) * thiscontainer(std::move(v)); } } diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index 850ed04a..89a3bcbf 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -354,9 +354,9 @@ static ex abs_power(const ex & arg, const ex & exp) { if ((is_a(exp) && ex_to(exp).is_even()) || exp.info(info_flags::even)) { if (arg.info(info_flags::real) || arg.is_equal(arg.conjugate())) - return power(arg, exp); + return pow(arg, exp); else - return power(arg, exp/2)*power(arg.conjugate(), exp/2); + return pow(arg, exp/2) * pow(arg.conjugate(), exp/2); } else return power(abs(arg), exp).hold(); } diff --git a/ginac/inifcns_trans.cpp b/ginac/inifcns_trans.cpp index dd844189..12a082a4 100644 --- a/ginac/inifcns_trans.cpp +++ b/ginac/inifcns_trans.cpp @@ -242,12 +242,8 @@ static ex log_series(const ex &arg, // in this case n more (or less) terms are needed // (sadly, to generate them, we have to start from the beginning) if (n == 0 && coeff == 1) { - epvector epv; - ex acc = dynallocate(rel, epv); - epv.reserve(2); - epv.push_back(expair(-1, _ex0)); - epv.push_back(expair(Order(_ex1), order)); - ex rest = pseries(rel, std::move(epv)).add_series(argser); + ex rest = pseries(rel, epvector{expair(-1, _ex0), expair(Order(_ex1), order)}).add_series(argser); + ex acc = dynallocate(rel, epvector()); for (int i = order-1; i>0; --i) { epvector cterm { expair(i%2 ? _ex1/i : _ex_1/i, _ex0) }; acc = pseries(rel, std::move(cterm)).add_series(ex_to(acc)); diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 0a6fca40..36960c0a 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -500,7 +500,7 @@ ex mul::eval() const distrseq.push_back(addref.combine_pair_with_coeff_to_pair(it, overall_coeff)); } return dynallocate(std::move(distrseq), - ex_to(addref.overall_coeff).mul_dyn(ex_to(overall_coeff))) + ex_to(addref.overall_coeff).mul_dyn(ex_to(overall_coeff))) .setflag(status_flags::evaluated); } else if ((seq_size >= 2) && (! (flags & status_flags::expanded))) { // Strip the content and the unit part from each term. Thus @@ -554,9 +554,9 @@ ex mul::eval() const add & primitive = dynallocate(addref); primitive.clearflag(status_flags::hash_calculated); primitive.overall_coeff = ex_to(primitive.overall_coeff).div_dyn(c); - for (epvector::iterator ai = primitive.seq.begin(); ai != primitive.seq.end(); ++ai) - ai->coeff = ex_to(ai->coeff).div_dyn(c); - + for (auto & ai : primitive.seq) + ai.coeff = ex_to(ai.coeff).div_dyn(c); + s.push_back(expair(primitive, _ex1)); ++i; @@ -577,7 +577,7 @@ ex mul::eval() const ex mul::evalf(int level) const { if (level==1) - return mul(seq,overall_coeff); + return mul(seq, overall_coeff); if (level==-max_recursion_level) throw(std::runtime_error("max recursion level reached")); @@ -797,10 +797,10 @@ retry1: subsed[j] = true; ex subsed_pattern = it.first.subs(repls, subs_options::no_pattern); - divide_by *= power(subsed_pattern, nummatches); + divide_by *= pow(subsed_pattern, nummatches); ex subsed_result = it.second.subs(repls, subs_options::no_pattern); - multiply_by *= power(subsed_result, nummatches); + multiply_by *= pow(subsed_result, nummatches); goto retry1; } else { @@ -812,10 +812,10 @@ retry1: subsed[j] = true; ex subsed_pattern = it.first.subs(repls, subs_options::no_pattern); - divide_by *= power(subsed_pattern, nummatches); + divide_by *= pow(subsed_pattern, nummatches); ex subsed_result = it.second.subs(repls, subs_options::no_pattern); - multiply_by *= power(subsed_result, nummatches); + multiply_by *= pow(subsed_result, nummatches); } } } @@ -879,7 +879,7 @@ ex mul::derivative(const symbol & s) const auto i = seq.begin(), end = seq.end(); auto i2 = mulseq.begin(); while (i != end) { - expair ep = split_ex_to_pair(power(i->rest, i->coeff - _ex1) * + expair ep = split_ex_to_pair(pow(i->rest, i->coeff - _ex1) * i->rest.diff(s)); ep.swap(*i2); addseq.push_back(dynallocate(mulseq, overall_coeff * i->coeff)); @@ -977,7 +977,7 @@ expair mul::combine_ex_with_coeff_to_pair(const ex & e, if (c.is_equal(_ex1)) return split_ex_to_pair(e); - return split_ex_to_pair(power(e,c)); + return split_ex_to_pair(pow(e,c)); } expair mul::combine_pair_with_coeff_to_pair(const expair & p, @@ -993,7 +993,7 @@ expair mul::combine_pair_with_coeff_to_pair(const expair & p, if (c.is_equal(_ex1)) return p; - return split_ex_to_pair(power(recombine_pair_to_ex(p),c)); + return split_ex_to_pair(pow(recombine_pair_to_ex(p),c)); } ex mul::recombine_pair_to_ex(const expair & p) const @@ -1071,20 +1071,22 @@ bool mul::can_be_further_expanded(const ex & e) ex mul::expand(unsigned options) const { - { - // trivial case: expanding the monomial (~ 30% of all calls) - epvector::const_iterator i = seq.begin(), seq_end = seq.end(); - while ((i != seq.end()) && is_a(i->rest) && i->coeff.info(info_flags::integer)) - ++i; - if (i == seq_end) { - setflag(status_flags::expanded); - return *this; + // Check for trivial case: expanding the monomial (~ 30% of all calls) + bool monomial_case = true; + for (const auto & i : seq) { + if (!is_a(i.rest) || !i.coeff.info(info_flags::integer)) { + monomial_case = false; + break; } } + if (monomial_case) { + setflag(status_flags::expanded); + return *this; + } // do not rename indices if the object has no indices at all if ((!(options & expand_options::expand_rename_idx)) && - this->info(info_flags::has_indices)) + this->info(info_flags::has_indices)) options |= expand_options::expand_rename_idx; const bool skip_idx_rename = !(options & expand_options::expand_rename_idx); diff --git a/ginac/normal.cpp b/ginac/normal.cpp index 7968b908..b4b5b694 100644 --- a/ginac/normal.cpp +++ b/ginac/normal.cpp @@ -388,7 +388,7 @@ ex quo(const ex &a, const ex &b, const ex &x, bool check_args) if (!divide(rcoeff, blcoeff, term, false)) return dynallocate(); } - term *= power(x, rdeg - bdeg); + term *= pow(x, rdeg - bdeg); v.push_back(term); r -= (term * b).expand(); if (r.is_zero()) @@ -441,7 +441,7 @@ ex rem(const ex &a, const ex &b, const ex &x, bool check_args) if (!divide(rcoeff, blcoeff, term, false)) return dynallocate(); } - term *= power(x, rdeg - bdeg); + term *= pow(x, rdeg - bdeg); r -= (term * b).expand(); if (r.is_zero()) break; @@ -501,23 +501,23 @@ ex prem(const ex &a, const ex &b, const ex &x, bool check_args) if (bdeg == 0) eb = _ex0; else - eb -= blcoeff * power(x, bdeg); + eb -= blcoeff * pow(x, bdeg); } else blcoeff = _ex1; int delta = rdeg - bdeg + 1, i = 0; while (rdeg >= bdeg && !r.is_zero()) { ex rlcoeff = r.coeff(x, rdeg); - ex term = (power(x, rdeg - bdeg) * eb * rlcoeff).expand(); + ex term = (pow(x, rdeg - bdeg) * eb * rlcoeff).expand(); if (rdeg == 0) r = _ex0; else - r -= rlcoeff * power(x, rdeg); + r -= rlcoeff * pow(x, rdeg); r = (blcoeff * r).expand() - term; rdeg = r.degree(x); i++; } - return power(blcoeff, delta - i) * r; + return pow(blcoeff, delta - i) * r; } @@ -553,17 +553,17 @@ ex sprem(const ex &a, const ex &b, const ex &x, bool check_args) if (bdeg == 0) eb = _ex0; else - eb -= blcoeff * power(x, bdeg); + eb -= blcoeff * pow(x, bdeg); } else blcoeff = _ex1; while (rdeg >= bdeg && !r.is_zero()) { ex rlcoeff = r.coeff(x, rdeg); - ex term = (power(x, rdeg - bdeg) * eb * rlcoeff).expand(); + ex term = (pow(x, rdeg - bdeg) * eb * rlcoeff).expand(); if (rdeg == 0) r = _ex0; else - r -= rlcoeff * power(x, rdeg); + r -= rlcoeff * pow(x, rdeg); r = (blcoeff * r).expand() - term; rdeg = r.degree(x); } @@ -663,7 +663,7 @@ bool divide(const ex &a, const ex &b, ex &q, bool check_args) int a_exp = ex_to(a.op(1)).to_int(); ex rem_i; if (divide(ab, b, rem_i, false)) { - q = rem_i*power(ab, a_exp - 1); + q = rem_i * pow(ab, a_exp - 1); return true; } // code below is commented-out because it leads to a significant slowdown @@ -693,7 +693,7 @@ bool divide(const ex &a, const ex &b, ex &q, bool check_args) else if (!divide(rcoeff, blcoeff, term, false)) return false; - term *= power(x, rdeg - bdeg); + term *= pow(x, rdeg - bdeg); v.push_back(term); r -= (term * b).expand(); if (r.is_zero()) { @@ -876,7 +876,7 @@ static bool divide_in_z(const ex &a, const ex &b, ex &q, sym_desc_vec::const_ite ex term, rcoeff = r.coeff(x, rdeg); if (!divide_in_z(rcoeff, blcoeff, term, var+1)) break; - term = (term * power(x, rdeg - bdeg)).expand(); + term = (term * pow(x, rdeg - bdeg)).expand(); v.push_back(term); r -= (term * eb).expand(); if (r.is_zero()) { @@ -1237,7 +1237,7 @@ static ex interpolate(const ex &gamma, const numeric &xi, const ex &x, int degre numeric rxi = xi.inverse(); for (int i=0; !e.is_zero(); i++) { ex gi = e.smod(xi); - g.push_back(gi * power(x, i)); + g.push_back(gi * pow(x, i)); e = (e - gi) * rxi; } return dynallocate(g); @@ -1563,7 +1563,7 @@ ex gcd(const ex &a, const ex &b, ex *ca, ex *cb, bool check_args, unsigned optio int ldeg_b = var->ldeg_b; int min_ldeg = std::min(ldeg_a,ldeg_b); if (min_ldeg > 0) { - ex common = power(x, min_ldeg); + ex common = pow(x, min_ldeg); return gcd((aex / common).expand(), (bex / common).expand(), ca, cb, false) * common; } @@ -1644,14 +1644,14 @@ static ex gcd_pf_pow_pow(const ex& a, const ex& b, ex* ca, ex* cb) if (ca) *ca = _ex1; if (cb) - *cb = power(p, exp_b - exp_a); - return power(p, exp_a); + *cb = pow(p, exp_b - exp_a); + return pow(p, exp_a); } else { if (ca) - *ca = power(p, exp_a - exp_b); + *ca = pow(p, exp_a - exp_b); if (cb) *cb = _ex1; - return power(p, exp_b); + return pow(p, exp_b); } } @@ -1671,11 +1671,11 @@ static ex gcd_pf_pow_pow(const ex& a, const ex& b, ex* ca, ex* cb) // a(x) = g(x)^n A(x)^n, b(x) = g(x)^m B(x)^m ==> // gcd(a, b) = g(x)^n gcd(A(x)^n, g(x)^(n-m) B(x)^m if (exp_a < exp_b) { - ex pg = gcd(power(p_co, exp_a), power(p_gcd, exp_b-exp_a)*power(pb_co, exp_b), ca, cb, false); - return power(p_gcd, exp_a)*pg; + ex pg = gcd(pow(p_co, exp_a), pow(p_gcd, exp_b-exp_a)*pow(pb_co, exp_b), ca, cb, false); + return pow(p_gcd, exp_a)*pg; } else { - ex pg = gcd(power(p_gcd, exp_a - exp_b)*power(p_co, exp_a), power(pb_co, exp_b), ca, cb, false); - return power(p_gcd, exp_b)*pg; + ex pg = gcd(pow(p_gcd, exp_a - exp_b)*pow(p_co, exp_a), pow(pb_co, exp_b), ca, cb, false); + return pow(p_gcd, exp_b)*pg; } } @@ -1694,7 +1694,7 @@ static ex gcd_pf_pow(const ex& a, const ex& b, ex* ca, ex* cb) if (p.is_equal(b)) { // a = p^n, b = p, gcd = p if (ca) - *ca = power(p, a.op(1) - 1); + *ca = pow(p, a.op(1) - 1); if (cb) *cb = _ex1; return p; @@ -1712,7 +1712,7 @@ static ex gcd_pf_pow(const ex& a, const ex& b, ex* ca, ex* cb) return _ex1; } // a(x) = g(x)^n A(x)^n, b(x) = g(x) B(x) ==> gcd(a, b) = g(x) gcd(g(x)^(n-1) A(x)^n, B(x)) - ex rg = gcd(power(p_gcd, exp_a-1)*power(p_co, exp_a), bpart_co, ca, cb, false); + ex rg = gcd(pow(p_gcd, exp_a-1)*pow(p_co, exp_a), bpart_co, ca, cb, false); return p_gcd*rg; } @@ -1876,7 +1876,7 @@ ex sqrfree(const ex &a, const lst &l) ex result = _ex1; int p = 1; for (auto & it : factors) - result *= power(it, p++); + result *= pow(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 @@ -2248,12 +2248,12 @@ ex power::normal(exmap & repl, exmap & rev_lookup, int level) const if (n_exponent.info(info_flags::positive)) { // (a/b)^n -> {a^n, b^n} - return dynallocate({power(n_basis.op(0), n_exponent), power(n_basis.op(1), n_exponent)}); + return dynallocate({pow(n_basis.op(0), n_exponent), pow(n_basis.op(1), n_exponent)}); } else if (n_exponent.info(info_flags::negative)) { // (a/b)^-n -> {b^n, a^n} - return dynallocate({power(n_basis.op(1), -n_exponent), power(n_basis.op(0), -n_exponent)}); + return dynallocate({pow(n_basis.op(1), -n_exponent), pow(n_basis.op(0), -n_exponent)}); } } else { @@ -2261,25 +2261,25 @@ ex power::normal(exmap & repl, exmap & rev_lookup, int level) const if (n_exponent.info(info_flags::positive)) { // (a/b)^x -> {sym((a/b)^x), 1} - return dynallocate({replace_with_symbol(power(n_basis.op(0) / n_basis.op(1), n_exponent), repl, rev_lookup), _ex1}); + return dynallocate({replace_with_symbol(pow(n_basis.op(0) / n_basis.op(1), n_exponent), repl, rev_lookup), _ex1}); } else if (n_exponent.info(info_flags::negative)) { if (n_basis.op(1).is_equal(_ex1)) { // a^-x -> {1, sym(a^x)} - return dynallocate({_ex1, replace_with_symbol(power(n_basis.op(0), -n_exponent), repl, rev_lookup)}); + return dynallocate({_ex1, replace_with_symbol(pow(n_basis.op(0), -n_exponent), repl, rev_lookup)}); } else { // (a/b)^-x -> {sym((b/a)^x), 1} - return dynallocate({replace_with_symbol(power(n_basis.op(1) / n_basis.op(0), -n_exponent), repl, rev_lookup), _ex1}); + return dynallocate({replace_with_symbol(pow(n_basis.op(1) / n_basis.op(0), -n_exponent), repl, rev_lookup), _ex1}); } } } // (a/b)^x -> {sym((a/b)^x, 1} - return dynallocate({replace_with_symbol(power(n_basis.op(0) / n_basis.op(1), n_exponent), repl, rev_lookup), _ex1}); + return dynallocate({replace_with_symbol(pow(n_basis.op(0) / n_basis.op(1), n_exponent), repl, rev_lookup), _ex1}); } @@ -2516,7 +2516,7 @@ ex numeric::to_polynomial(exmap & repl) const ex power::to_rational(exmap & repl) const { if (exponent.info(info_flags::integer)) - return power(basis.to_rational(repl), exponent); + return pow(basis.to_rational(repl), exponent); else return replace_with_symbol(*this, repl); } @@ -2526,17 +2526,17 @@ ex power::to_rational(exmap & repl) const ex power::to_polynomial(exmap & repl) const { if (exponent.info(info_flags::posint)) - return power(basis.to_rational(repl), exponent); + return pow(basis.to_rational(repl), exponent); else if (exponent.info(info_flags::negint)) { ex basis_pref = collect_common_factors(basis); if (is_exactly_a(basis_pref) || is_exactly_a(basis_pref)) { // (A*B)^n will be automagically transformed to A^n*B^n - ex t = power(basis_pref, exponent); + ex t = pow(basis_pref, exponent); return t.to_polynomial(repl); } else - return power(replace_with_symbol(power(basis, _ex_1), repl), -exponent); + return pow(replace_with_symbol(pow(basis, _ex_1), repl), -exponent); } else return replace_with_symbol(*this, repl); @@ -2655,8 +2655,8 @@ term_done: ; ex eb = e.op(0).to_polynomial(repl); ex factor_local(_ex1); ex pre_res = find_common_factor(eb, factor_local, repl); - factor *= power(factor_local, e_exp); - return power(pre_res, e_exp); + factor *= pow(factor_local, e_exp); + return pow(pre_res, e_exp); } else return e.to_polynomial(repl); diff --git a/ginac/operators.cpp b/ginac/operators.cpp index 4cb57ec7..9ab73b0a 100644 --- a/ginac/operators.cpp +++ b/ginac/operators.cpp @@ -34,13 +34,13 @@ namespace GiNaC { -/** Used internally by operator+() to add two ex objects together. */ +/** Used internally by operator+() to add two ex objects. */ static inline const ex exadd(const ex & lh, const ex & rh) { return dynallocate(lh, rh); } -/** Used internally by operator*() to multiply two ex objects together. */ +/** Used internally by operator*() to multiply two ex objects. */ static inline const ex exmul(const ex & lh, const ex & rh) { // Check if we are constructing a mul object or a ncmul object. Due to @@ -247,32 +247,32 @@ const numeric operator--(numeric & lh, int) const relational operator==(const ex & lh, const ex & rh) { - return relational(lh,rh,relational::equal); + return dynallocate(lh, rh, relational::equal); } const relational operator!=(const ex & lh, const ex & rh) { - return relational(lh,rh,relational::not_equal); + return dynallocate(lh, rh, relational::not_equal); } const relational operator<(const ex & lh, const ex & rh) { - return relational(lh,rh,relational::less); + return dynallocate(lh, rh, relational::less); } const relational operator<=(const ex & lh, const ex & rh) { - return relational(lh,rh,relational::less_or_equal); + return dynallocate(lh, rh, relational::less_or_equal); } const relational operator>(const ex & lh, const ex & rh) { - return relational(lh,rh,relational::greater); + return dynallocate(lh, rh, relational::greater); } const relational operator>=(const ex & lh, const ex & rh) { - return relational(lh,rh,relational::greater_or_equal); + return dynallocate(lh, rh, relational::greater_or_equal); } // input/output stream operators and manipulators diff --git a/ginac/polynomial/collect_vargs.cpp b/ginac/polynomial/collect_vargs.cpp index 9ff206ef..661372d1 100644 --- a/ginac/polynomial/collect_vargs.cpp +++ b/ginac/polynomial/collect_vargs.cpp @@ -155,7 +155,7 @@ ex_collect_to_ex(const ex_collect_t& ec, const exvector& vars) "expression has " << exp_vector.size() << " instead"); if (exp_vector[j] != 0) - tv.push_back(power(vars[j], exp_vector[j])); + tv.push_back(pow(vars[j], exp_vector[j])); } tv.push_back(ec[i].second); ex tmp = dynallocate(tv); diff --git a/ginac/power.cpp b/ginac/power.cpp index c376009b..3baa3c6f 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -421,7 +421,7 @@ ex power::eval() const // Turn (x^c)^d into x^(c*d) in the case that x is positive and c is real. if (is_exactly_a(basis) && basis.op(0).info(info_flags::positive) && basis.op(1).info(info_flags::real)) - return power(basis.op(0), basis.op(1) * exponent); + return dynallocate(basis.op(0), basis.op(1) * exponent); if ( num_exponent ) { @@ -472,8 +472,7 @@ ex power::eval() const // because otherwise we'll end up with something like // (7/8)^(4/3) -> 7/8*(1/2*7^(1/3)) // instead of 7/16*7^(1/3). - ex prod = power(*num_basis,r.div(m)); - return prod*power(*num_basis,q); + return pow(basis, r.div(m)) * pow(basis, q); } } } @@ -490,14 +489,14 @@ ex power::eval() const GINAC_ASSERT(num_sub_exponent!=numeric(1)); if (num_exponent->is_integer() || (abs(num_sub_exponent) - (*_num1_p)).is_negative() || (num_sub_exponent == *_num_1_p && num_exponent->is_positive())) { - return power(sub_basis,num_sub_exponent.mul(*num_exponent)); + return dynallocate(sub_basis, num_sub_exponent.mul(*num_exponent)); } } } // ^(*(x,y,z),c1) -> *(x^c1,y^c1,z^c1) (c1 integer) if (num_exponent->is_integer() && is_exactly_a(basis)) { - return expand_mul(ex_to(basis), *num_exponent, 0); + return expand_mul(ex_to(basis), *num_exponent, false); } // (2*x + 6*y)^(-4) -> 1/16*(x + 3*y)^(-4) @@ -584,7 +583,7 @@ ex power::evalf(int level) const eexponent = exponent; } - return power(ebasis,eexponent); + return dynallocate(ebasis, eexponent); } ex power::evalm() const @@ -642,7 +641,7 @@ ex power::subs(const exmap & m, unsigned options) const if (tryfactsubs(*this, it.first, nummatches, repls)) { ex anum = it.second.subs(repls, subs_options::no_pattern); ex aden = it.first.subs(repls, subs_options::no_pattern); - ex result = (*this)*power(anum/aden, nummatches); + ex result = (*this) * pow(anum/aden, nummatches); return (ex_to(result)).subs_one_level(m, options); } } @@ -691,12 +690,12 @@ ex power::real_part() const // Re((a+I*b)^c) w/ c ∈ ℤ long N = ex_to(c).to_long(); // Use real terms in Binomial expansion to construct - // Re(expand(power(a+I*b, N))). + // Re(expand(pow(a+I*b, N))). long NN = N > 0 ? N : -N; - ex numer = N > 0 ? _ex1 : power(power(a,2) + power(b,2), NN); + ex numer = N > 0 ? _ex1 : pow(pow(a,2) + pow(b,2), NN); ex result = 0; for (long n = 0; n <= NN; n += 2) { - ex term = binomial(NN, n) * power(a, NN-n) * power(b, n) / numer; + ex term = binomial(NN, n) * pow(a, NN-n) * pow(b, n) / numer; if (n % 4 == 0) { result += term; // sign: I^n w/ n == 4*m } else { @@ -708,11 +707,12 @@ ex power::real_part() const // Re((a+I*b)^(c+I*d)) const ex d = exponent.imag_part(); - return power(abs(basis),c)*exp(-d*atan2(b,a))*cos(c*atan2(b,a)+d*log(abs(basis))); + return pow(abs(basis),c) * exp(-d*atan2(b,a)) * cos(c*atan2(b,a)+d*log(abs(basis))); } ex power::imag_part() const { + // basis == a+I*b, exponent == c+I*d const ex a = basis.real_part(); const ex c = exponent.real_part(); if (basis.is_equal(a) && exponent.is_equal(c)) { @@ -725,13 +725,13 @@ ex power::imag_part() const // Im((a+I*b)^c) w/ c ∈ ℤ long N = ex_to(c).to_long(); // Use imaginary terms in Binomial expansion to construct - // Im(expand(power(a+I*b, N))). + // Im(expand(pow(a+I*b, N))). long p = N > 0 ? 1 : 3; // modulus for positive sign long NN = N > 0 ? N : -N; - ex numer = N > 0 ? _ex1 : power(power(a,2) + power(b,2), NN); + ex numer = N > 0 ? _ex1 : pow(pow(a,2) + pow(b,2), NN); ex result = 0; for (long n = 1; n <= NN; n += 2) { - ex term = binomial(NN, n) * power(a, NN-n) * power(b, n) / numer; + ex term = binomial(NN, n) * pow(a, NN-n) * pow(b, n) / numer; if (n % 4 == p) { result += term; // sign: I^n w/ n == 4*m+p } else { @@ -743,7 +743,7 @@ ex power::imag_part() const // Im((a+I*b)^(c+I*d)) const ex d = exponent.imag_part(); - return power(abs(basis),c)*exp(-d*atan2(b,a))*sin(c*atan2(b,a)+d*log(abs(basis))); + return pow(abs(basis),c) * exp(-d*atan2(b,a)) * sin(c*atan2(b,a)+d*log(abs(basis))); } // protected @@ -754,16 +754,11 @@ ex power::derivative(const symbol & s) const { if (is_a(exponent)) { // D(b^r) = r * b^(r-1) * D(b) (faster than the formula below) - epvector newseq; - newseq.reserve(2); - newseq.push_back(expair(basis, exponent - _ex1)); - newseq.push_back(expair(basis.diff(s), _ex1)); - return mul(std::move(newseq), exponent); + const epvector newseq = {expair(basis, exponent - _ex1), expair(basis.diff(s), _ex1)}; + return dynallocate(std::move(newseq), exponent); } else { // D(b^e) = b^e * (D(e)*ln(b) + e*D(b)/b) - return mul(*this, - add(mul(exponent.diff(s), log(basis)), - mul(mul(exponent, basis.diff(s)), power(basis, _ex_1)))); + return *this * (exponent.diff(s)*log(basis) + exponent*basis.diff(s)*pow(basis, _ex_1)); } } @@ -822,9 +817,9 @@ ex power::expand(unsigned options) const // take care on the numeric coefficient ex coeff=(possign? _ex1 : _ex_1); if (m.overall_coeff.info(info_flags::positive) && m.overall_coeff != _ex1) - prodseq.push_back(power(m.overall_coeff, exponent)); + prodseq.push_back(pow(m.overall_coeff, exponent)); else if (m.overall_coeff.info(info_flags::negative) && m.overall_coeff != _ex_1) - prodseq.push_back(power(-m.overall_coeff, exponent)); + prodseq.push_back(pow(-m.overall_coeff, exponent)); else coeff *= m.overall_coeff; @@ -832,7 +827,7 @@ ex power::expand(unsigned options) const // In either case we set a flag to avoid the second run on a part // which does not have positive/negative terms. if (prodseq.size() > 0) { - ex newbasis = coeff*mul(std::move(powseq)); + ex newbasis = dynallocate(std::move(powseq), coeff); ex_to(newbasis).setflag(status_flags::purely_indefinite); return dynallocate(std::move(prodseq)) * pow(newbasis, exponent); } else @@ -848,7 +843,7 @@ ex power::expand(unsigned options) const exvector distrseq; distrseq.reserve(a.seq.size() + 1); for (auto & cit : a.seq) { - distrseq.push_back(power(expanded_basis, a.recombine_pair_to_ex(cit))); + distrseq.push_back(pow(expanded_basis, a.recombine_pair_to_ex(cit))); } // Make sure that e.g. (x+y)^(2+a) expands the (x+y)^2 factor @@ -858,9 +853,9 @@ ex power::expand(unsigned options) const if (int_exponent > 0 && is_exactly_a(expanded_basis)) distrseq.push_back(expand_add(ex_to(expanded_basis), int_exponent, options)); else - distrseq.push_back(power(expanded_basis, a.overall_coeff)); + distrseq.push_back(pow(expanded_basis, a.overall_coeff)); } else - distrseq.push_back(power(expanded_basis, a.overall_coeff)); + distrseq.push_back(pow(expanded_basis, a.overall_coeff)); // Make sure that e.g. (x+y)^(1+a) -> x*(x+y)^a + y*(x+y)^a ex r = dynallocate(distrseq); diff --git a/ginac/pseries.cpp b/ginac/pseries.cpp index 31a92002..cc756ac4 100644 --- a/ginac/pseries.cpp +++ b/ginac/pseries.cpp @@ -177,7 +177,7 @@ void pseries::print_series(const print_context & c, const char *openbrace, const } } } else - Order(power(var-point,i->coeff)).print(c); + Order(pow(var - point, i->coeff)).print(c); ++i; } @@ -281,8 +281,8 @@ ex pseries::op(size_t i) const throw (std::out_of_range("op() out of range")); if (is_order_function(seq[i].rest)) - return Order(power(var-point, seq[i].coeff)); - return seq[i].rest * power(var - point, seq[i].coeff); + return Order(pow(var-point, seq[i].coeff)); + return seq[i].rest * pow(var - point, seq[i].coeff); } /** Return degree of highest power of the series. This is usually the exponent @@ -500,8 +500,7 @@ ex pseries::evalm() const ex newcoeff = i->rest.evalm(); if (!newcoeff.is_zero()) newseq.push_back(expair(newcoeff, i->coeff)); - } - else { + } else { ex newcoeff = i->rest.evalm(); if (!are_ex_trivially_equal(newcoeff, i->rest)) { something_changed = true; @@ -589,9 +588,9 @@ ex pseries::convert_to_poly(bool no_order) const for (auto & it : seq) { if (is_order_function(it.rest)) { if (!no_order) - e += Order(power(var - point, it.coeff)); + e += Order(pow(var - point, it.coeff)); } else - e += it.rest * power(var - point, it.coeff); + e += it.rest * pow(var - point, it.coeff); } return e; } @@ -644,7 +643,7 @@ ex basic::series(const relational & r, int order, unsigned options) const int n; for (n=1; n