]> www.ginac.de Git - ginac.git/blobdiff - ginac/expairseq.cpp
Finalize 1.7.7 release.
[ginac.git] / ginac / expairseq.cpp
index 11da774902a1d17994674291f674a0a022526482..59bd831620877496f71092145f006f1084a10f9e 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of sequences of expression pairs. */
 
 /*
- *  GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2019 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
@@ -112,17 +112,15 @@ expairseq::expairseq(epvector && vp, const ex &oc, bool do_index_renaming)
 void expairseq::read_archive(const archive_node &n, lst &sym_lst) 
 {
        inherited::read_archive(n, sym_lst);
-       auto first = n.find_first("rest");
-       auto last = n.find_last("coeff");
-       ++last;
-       seq.reserve((last-first)/2);
+       auto range = n.find_property_range("rest", "coeff");
+       seq.reserve((range.end-range.begin)/2);
 
-       for (auto loc = first; loc < last;) {
+       for (auto loc = range.begin; loc < range.end;) {
                ex rest;
                ex coeff;
                n.find_ex_by_loc(loc++, rest, sym_lst);
                n.find_ex_by_loc(loc++, coeff, sym_lst);
-               seq.push_back(expair(rest, coeff));
+               seq.emplace_back(expair(rest, coeff));
        }
 
        n.find_ex("overall_coeff", overall_coeff, sym_lst);
@@ -265,7 +263,7 @@ epvector* conjugateepvector(const epvector&epv)
                }
                newepv = new epvector;
                newepv->reserve(epv.size());
-               for (epvector::const_iterator j=epv.begin(); j!=i; ++j) {
+               for (auto j=epv.begin(); j!=i; ++j) {
                        newepv->push_back(*j);
                }
                newepv->push_back(x);
@@ -565,6 +563,11 @@ ex expairseq::recombine_pair_to_ex(const expair &p) const
 
 bool expairseq::expair_needs_further_processing(epp it)
 {
+       if (is_exactly_a<numeric>(it->rest) &&
+           it->coeff.is_equal(_ex1)) {
+               // the pair {<n>, 1} has yet to be absorbed into overall_coeff
+               return true;
+       }
        return false;
 }
 
@@ -601,8 +604,9 @@ bool expairseq::can_make_flat(const expair &p) const
 
 void expairseq::construct_from_2_ex(const ex &lh, const ex &rh)
 {
-       if (typeid(ex_to<basic>(lh)) == typeid(*this)) {
-               if (typeid(ex_to<basic>(rh)) == typeid(*this)) {
+       const std::type_info& typeid_this = typeid(*this);
+       if (typeid(ex_to<basic>(lh)) == typeid_this) {
+               if (typeid(ex_to<basic>(rh)) == typeid_this) {
                        if (is_a<mul>(lh) && lh.info(info_flags::has_indices) && 
                                rh.info(info_flags::has_indices)) {
                                ex newrh=rename_dummy_indices_uniquely(lh, rh);
@@ -617,7 +621,7 @@ void expairseq::construct_from_2_ex(const ex &lh, const ex &rh)
                        construct_from_expairseq_ex(ex_to<expairseq>(lh), rh);
                        return;
                }
-       } else if (typeid(ex_to<basic>(rh)) == typeid(*this)) {
+       } else if (typeid(ex_to<basic>(rh)) == typeid_this) {
                construct_from_expairseq_ex(ex_to<expairseq>(rh),lh);
                return;
        }
@@ -819,9 +823,10 @@ void expairseq::make_flat(const exvector &v)
        int nexpairseqs = 0;
        int noperands = 0;
        bool do_idx_rename = false;
-       
+
+       const std::type_info& typeid_this = typeid(*this);
        for (auto & cit : v) {
-               if (typeid(ex_to<basic>(cit)) == typeid(*this)) {
+               if (typeid(ex_to<basic>(cit)) == typeid_this) {
                        ++nexpairseqs;
                        noperands += ex_to<expairseq>(cit).seq.size();
                }
@@ -836,7 +841,7 @@ void expairseq::make_flat(const exvector &v)
        // copy elements and split off numerical part
        make_flat_inserter mf(v, do_idx_rename);
        for (auto & cit : v) {
-               if (typeid(ex_to<basic>(cit)) == typeid(*this)) {
+               if (typeid(ex_to<basic>(cit)) == typeid_this) {
                        ex newfactor = mf.handle_factor(cit, _ex1);
                        const expairseq &subseqref = ex_to<expairseq>(newfactor);
                        combine_overall_coeff(subseqref.overall_coeff);
@@ -863,9 +868,10 @@ void expairseq::make_flat(const epvector &v, bool do_index_renaming)
        int nexpairseqs = 0;
        int noperands = 0;
        bool really_need_rename_inds = false;
-       
+
+       const std::type_info& typeid_this = typeid(*this);
        for (auto & cit : v) {
-               if (typeid(ex_to<basic>(cit.rest)) == typeid(*this)) {
+               if (typeid(ex_to<basic>(cit.rest)) == typeid_this) {
                        ++nexpairseqs;
                        noperands += ex_to<expairseq>(cit.rest).seq.size();
                }
@@ -881,12 +887,11 @@ void expairseq::make_flat(const epvector &v, bool do_index_renaming)
        
        // copy elements and split off numerical part
        for (auto & cit : v) {
-               if (typeid(ex_to<basic>(cit.rest)) == typeid(*this) &&
+               if (typeid(ex_to<basic>(cit.rest)) == typeid_this &&
                    this->can_make_flat(cit)) {
                        ex newrest = mf.handle_factor(cit.rest, cit.coeff);
                        const expairseq &subseqref = ex_to<expairseq>(newrest);
-                       combine_overall_coeff(ex_to<numeric>(subseqref.overall_coeff),
-                                             ex_to<numeric>(cit.coeff));
+                       combine_overall_coeff(subseqref.overall_coeff, cit.coeff);
                        for (auto & cit_s : subseqref.seq) {
                                seq.push_back(expair(cit_s.rest,
                                                     ex_to<numeric>(cit_s.coeff).mul_dyn(ex_to<numeric>(cit.coeff))));