X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Findexed.cpp;h=77c8eb5c9cc80298dc55fb29bffe194be8e15e2d;hb=cd22e73d44e3320898f62a0accdbbe005b33d3e5;hp=5e63d8944db9d7156e68f3d108af3d7f75869e13;hpb=1b8bcb068171ce9d5c8202ae3c76647b65c9a06d;p=ginac.git diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index 5e63d894..77c8eb5c 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's indexed expressions. */ /* - * GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2016 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -61,53 +61,53 @@ indexed::indexed() : symtree(not_symmetric()) // other constructors ////////// -indexed::indexed(const ex & b) : inherited(b), symtree(not_symmetric()) +indexed::indexed(const ex & b) : inherited{b}, symtree(not_symmetric()) { validate(); } -indexed::indexed(const ex & b, const ex & i1) : inherited(b, i1), symtree(not_symmetric()) +indexed::indexed(const ex & b, const ex & i1) : inherited{b, i1}, symtree(not_symmetric()) { validate(); } -indexed::indexed(const ex & b, const ex & i1, const ex & i2) : inherited(b, i1, i2), symtree(not_symmetric()) +indexed::indexed(const ex & b, const ex & i1, const ex & i2) : inherited{b, i1, i2}, symtree(not_symmetric()) { validate(); } -indexed::indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3) : inherited(b, i1, i2, i3), symtree(not_symmetric()) +indexed::indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3) : inherited{b, i1, i2, i3}, symtree(not_symmetric()) { validate(); } -indexed::indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3, const ex & i4) : inherited(b, i1, i2, i3, i4), symtree(not_symmetric()) +indexed::indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3, const ex & i4) : inherited{b, i1, i2, i3, i4}, symtree(not_symmetric()) { validate(); } -indexed::indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2) : inherited(b, i1, i2), symtree(symm) +indexed::indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2) : inherited{b, i1, i2}, symtree(symm) { validate(); } -indexed::indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2, const ex & i3) : inherited(b, i1, i2, i3), symtree(symm) +indexed::indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2, const ex & i3) : inherited{b, i1, i2, i3}, symtree(symm) { validate(); } -indexed::indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2, const ex & i3, const ex & i4) : inherited(b, i1, i2, i3, i4), symtree(symm) +indexed::indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2, const ex & i3, const ex & i4) : inherited{b, i1, i2, i3, i4}, symtree(symm) { validate(); } -indexed::indexed(const ex & b, const exvector & v) : inherited(b), symtree(not_symmetric()) +indexed::indexed(const ex & b, const exvector & v) : inherited{b}, symtree(not_symmetric()) { seq.insert(seq.end(), v.begin(), v.end()); validate(); } -indexed::indexed(const ex & b, const symmetry & symm, const exvector & v) : inherited(b), symtree(symm) +indexed::indexed(const ex & b, const symmetry & symm, const exvector & v) : inherited{b}, symtree(symm) { seq.insert(seq.end(), v.begin(), v.end()); validate(); @@ -117,7 +117,7 @@ indexed::indexed(const symmetry & symm, const exprseq & es) : inherited(es), sym { } -indexed::indexed(const symmetry & symm, const exvector & v, bool discardable) : inherited(v, discardable), symtree(symm) +indexed::indexed(const symmetry & symm, const exvector & v) : inherited(v), symtree(symm) { } @@ -243,12 +243,6 @@ bool indexed::info(unsigned inf) const return inherited::info(inf); } -struct idx_is_not : public std::binary_function { - bool operator() (const ex & e, unsigned inf) const { - return !(ex_to(e).get_value().info(inf)); - } -}; - bool indexed::all_index_values_are(unsigned inf) const { // No indices? Then no property can be fulfilled @@ -256,7 +250,8 @@ bool indexed::all_index_values_are(unsigned inf) const return false; // Check all indices - return find_if(seq.begin() + 1, seq.end(), bind2nd(idx_is_not(), inf)) == seq.end(); + return find_if(seq.begin() + 1, seq.end(), + [inf](const ex & e) { return !(ex_to(e).get_value().info(inf)); }) == seq.end(); } int indexed::compare_same_type(const basic & other) const @@ -265,12 +260,8 @@ int indexed::compare_same_type(const basic & other) const return inherited::compare_same_type(other); } -ex indexed::eval(int level) const +ex indexed::eval() const { - // First evaluate children, then we will end up here again - if (level > 1) - return indexed(ex_to(symtree), evalchildren(level)); - const ex &base = seq[0]; // If the base object is 0, the whole object is 0 @@ -403,7 +394,7 @@ ex indexed::derivative(const symbol & s) const // global functions ////////// -struct idx_is_equal_ignore_dim : public std::binary_function { +struct idx_is_equal_ignore_dim { bool operator() (const ex &lh, const ex &rh) const { if (lh.is_equal(rh)) @@ -515,7 +506,7 @@ exvector ncmul::get_free_indices() const return free_indices; } -struct is_summation_idx : public std::unary_function { +struct is_summation_idx { bool operator()(const ex & e) { return is_dummy_pair(e, e); @@ -563,7 +554,9 @@ template static ex rename_dummy_indices(const ex & e, exvector & global int remaining = local_size - global_size; auto it = local_dummy_indices.begin(), itend = local_dummy_indices.end(); while (it != itend && remaining > 0) { - if (is_exactly_a(*it) && find_if(global_dummy_indices.begin(), global_dummy_indices.end(), bind2nd(idx_is_equal_ignore_dim(), *it)) == global_dummy_indices.end()) { + if (is_exactly_a(*it) && + find_if(global_dummy_indices.begin(), global_dummy_indices.end(), + [it](const ex &lh) { return idx_is_equal_ignore_dim()(lh, *it); }) == global_dummy_indices.end()) { global_dummy_indices.push_back(*it); global_size++; remaining--; @@ -688,10 +681,10 @@ bool reposition_dummy_indices(ex & e, exvector & variant_dummy_indices, exvector /* * N.B. we don't want to use * - * e = e.subs(lst( + * e = e.subs(lst{ * *it2 == ex_to(*it2).toggle_variance(), * ex_to(*it2).toggle_variance() == *it2 - * ), subs_options::no_pattern); + * }, subs_options::no_pattern); * * since this can trigger non-trivial repositioning of indices, * e.g. due to non-trivial symmetry properties of e, thus @@ -726,7 +719,7 @@ next_index: ; } /* Ordering that only compares the base expressions of indexed objects. */ -struct ex_base_is_less : public std::binary_function { +struct ex_base_is_less { bool operator() (const ex &lh, const ex &rh) const { return (is_a(lh) ? lh.op(0) : lh).compare(is_a(rh) ? rh.op(0) : rh) < 0; @@ -874,7 +867,7 @@ contraction_done: // the product bool is_a_product = (is_exactly_a(*it1) || is_exactly_a(*it1)) && (is_exactly_a(*it2) || is_exactly_a(*it2)); - ex r = (non_commutative ? ex(ncmul(v, true)) : ex(mul(v))); + ex r = (non_commutative ? ex(ncmul(std::move(v))) : ex(mul(std::move(v)))); // If new expression is a product we can call this function again, // otherwise we need to pass argument to simplify_indexed() to be expanded @@ -941,7 +934,7 @@ contraction_done: ex r; if (something_changed) - r = non_commutative ? ex(ncmul(v, true)) : ex(mul(v)); + r = non_commutative ? ex(ncmul(std::move(v))) : ex(mul(std::move(v))); else r = e; @@ -1237,7 +1230,7 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi } // Add all resulting terms - ex sum_symm = (new add(result))->setflag(status_flags::dynallocated); + ex sum_symm = dynallocate(result); if (sum_symm.is_zero()) free_indices.clear(); return sum_symm; @@ -1469,27 +1462,24 @@ lst rename_dummy_indices_uniquely(const exvector & va, const exvector & vb) exvector common_indices; set_intersection(va.begin(), va.end(), vb.begin(), vb.end(), std::back_insert_iterator(common_indices), ex_is_less()); if (common_indices.empty()) { - return lst(lst(), lst()); + return lst{lst{}, lst{}}; } else { exvector new_indices, old_indices; old_indices.reserve(2*common_indices.size()); new_indices.reserve(2*common_indices.size()); exvector::const_iterator ip = common_indices.begin(), ipend = common_indices.end(); while (ip != ipend) { - ex newsym=(new symbol)->setflag(status_flags::dynallocated); + ex newsym = dynallocate(); ex newidx; if(is_exactly_a(*ip)) - newidx = (new spinidx(newsym, ex_to(*ip).get_dim(), - ex_to(*ip).is_covariant(), - ex_to(*ip).is_dotted())) - -> setflag(status_flags::dynallocated); + newidx = dynallocate(newsym, ex_to(*ip).get_dim(), + ex_to(*ip).is_covariant(), + ex_to(*ip).is_dotted()); else if (is_exactly_a(*ip)) - newidx = (new varidx(newsym, ex_to(*ip).get_dim(), - ex_to(*ip).is_covariant())) - -> setflag(status_flags::dynallocated); + newidx = dynallocate(newsym, ex_to(*ip).get_dim(), + ex_to(*ip).is_covariant()); else - newidx = (new idx(newsym, ex_to(*ip).get_dim())) - -> setflag(status_flags::dynallocated); + newidx = dynallocate(newsym, ex_to(*ip).get_dim()); old_indices.push_back(*ip); new_indices.push_back(newidx); if(is_a(*ip)) { @@ -1498,7 +1488,7 @@ lst rename_dummy_indices_uniquely(const exvector & va, const exvector & vb) } ++ip; } - return lst(lst(old_indices.begin(), old_indices.end()), lst(new_indices.begin(), new_indices.end())); + return lst{lst(old_indices.begin(), old_indices.end()), lst(new_indices.begin(), new_indices.end())}; } } @@ -1568,10 +1558,10 @@ ex expand_dummy_sum(const ex & e, bool subs_idx) for (int i=0; i < idim; i++) { if (subs_idx && is_a(nu)) { ex other = ex_to(nu).toggle_variance(); - en += result.subs(lst( + en += result.subs(lst{ nu == idx(i, idim), other == idx(i, idim) - )); + }); } else { en += result.subs( nu.op(0) == i ); }