]> www.ginac.de Git - ginac.git/blobdiff - ginac/indexed.cpp
More shortcuts for trivial cases in mul::combine_*_to_pair().
[ginac.git] / ginac / indexed.cpp
index d5f7bf85eccaeaa6fc92736a3530afc4939dfe46..77c8eb5c9cc80298dc55fb29bffe194be8e15e2d 100644 (file)
@@ -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();
@@ -260,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<symmetry>(symtree), evalchildren(level));
-
        const ex &base = seq[0];
 
        // If the base object is 0, the whole object is 0
@@ -398,7 +394,7 @@ ex indexed::derivative(const symbol & s) const
 // global functions
 //////////
 
-struct idx_is_equal_ignore_dim : public std::binary_function<ex, ex, bool> {
+struct idx_is_equal_ignore_dim {
        bool operator() (const ex &lh, const ex &rh) const
        {
                if (lh.is_equal(rh))
@@ -510,7 +506,7 @@ exvector ncmul::get_free_indices() const
        return free_indices;
 }
 
-struct is_summation_idx : public std::unary_function<ex, bool> {
+struct is_summation_idx {
        bool operator()(const ex & e)
        {
                return is_dummy_pair(e, e);
@@ -558,7 +554,9 @@ template<class T> 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<T>(*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<T>(*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--;
@@ -683,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<varidx>(*it2).toggle_variance(),
                                         *  ex_to<varidx>(*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
@@ -721,7 +719,7 @@ next_index: ;
 }
 
 /* Ordering that only compares the base expressions of indexed objects. */
-struct ex_base_is_less : public std::binary_function<ex, ex, bool> {
+struct ex_base_is_less {
        bool operator() (const ex &lh, const ex &rh) const
        {
                return (is_a<indexed>(lh) ? lh.op(0) : lh).compare(is_a<indexed>(rh) ? rh.op(0) : rh) < 0;
@@ -1232,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<add>(result);
                if (sum_symm.is_zero())
                        free_indices.clear();
                return sum_symm;
@@ -1464,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<exvector>(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<symbol>();
                        ex newidx;
                        if(is_exactly_a<spinidx>(*ip))
-                               newidx = (new spinidx(newsym, ex_to<spinidx>(*ip).get_dim(),
-                                               ex_to<spinidx>(*ip).is_covariant(),
-                                               ex_to<spinidx>(*ip).is_dotted()))
-                                       -> setflag(status_flags::dynallocated);
+                               newidx = dynallocate<spinidx>(newsym, ex_to<spinidx>(*ip).get_dim(),
+                                                             ex_to<spinidx>(*ip).is_covariant(),
+                                                             ex_to<spinidx>(*ip).is_dotted());
                        else if (is_exactly_a<varidx>(*ip))
-                               newidx = (new varidx(newsym, ex_to<varidx>(*ip).get_dim(),
-                                               ex_to<varidx>(*ip).is_covariant()))
-                                       -> setflag(status_flags::dynallocated);
+                               newidx = dynallocate<varidx>(newsym, ex_to<varidx>(*ip).get_dim(),
+                                                            ex_to<varidx>(*ip).is_covariant());
                        else
-                               newidx = (new idx(newsym, ex_to<idx>(*ip).get_dim()))
-                                       -> setflag(status_flags::dynallocated);
+                               newidx = dynallocate<idx>(newsym, ex_to<idx>(*ip).get_dim());
                        old_indices.push_back(*ip);
                        new_indices.push_back(newidx);
                        if(is_a<varidx>(*ip)) {
@@ -1493,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())};
        }
 }
 
@@ -1563,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<varidx>(nu)) {
                                                ex other = ex_to<varidx>(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 );
                                        }