X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fadd.cpp;h=6c83e2a7028ba67b83fa9e4b2ba6e308c6bf3236;hb=HEAD;hp=2a2e2f8310fa56217c4e52934f0399d76f7b3108;hpb=6c946d4c762f5a0d6a3b742f03556dd018d63886;p=ginac.git diff --git a/ginac/add.cpp b/ginac/add.cpp index 2a2e2f83..b9f47938 100644 --- a/ginac/add.cpp +++ b/ginac/add.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's sums of expressions. */ /* - * GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2024 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 @@ -86,6 +86,13 @@ add::add(const epvector & v, const ex & oc) GINAC_ASSERT(is_canonical()); } +add::add(epvector && vp) +{ + overall_coeff = _ex0; + construct_from_epvector(std::move(vp)); + GINAC_ASSERT(is_canonical()); +} + add::add(epvector && vp, const ex & oc) { overall_coeff = oc; @@ -240,15 +247,6 @@ bool add::info(unsigned inf) const return true; return overall_coeff.info(inf); } - case info_flags::algebraic: { - epvector::const_iterator i = seq.begin(), end = seq.end(); - while (i != end) { - if ((recombine_pair_to_ex(*i).info(inf))) - return true; - ++i; - } - return false; - } } return inherited::info(inf); } @@ -347,7 +345,7 @@ ex add::eval() const } #endif // def DO_GINAC_ASSERT - int seq_size = seq.size(); + size_t seq_size = seq.size(); if (seq_size == 0) { // +(;c) -> c return overall_coeff; @@ -357,27 +355,7 @@ ex add::eval() const } else if (!overall_coeff.is_zero() && seq[0].rest.return_type() != return_types::commutative) { throw (std::logic_error("add::eval(): sum of non-commutative objects has non-zero numeric term")); } - - // if any terms in the sum still are purely numeric, then they are more - // appropriately collected into the overall coefficient - int terms_to_collect = 0; - for (auto & it : seq) { - if (unlikely(is_a(it.rest))) - ++terms_to_collect; - } - if (terms_to_collect) { - epvector s; - s.reserve(seq_size - terms_to_collect); - numeric oc = *_num1_p; - for (auto & it : seq) { - if (unlikely(is_a(it.rest))) - oc = oc.mul(ex_to(it.rest)).mul(ex_to(it.coeff)); - else - s.push_back(it); - } - return dynallocate(std::move(s), ex_to(overall_coeff).add_dyn(oc)); - } - + return this->hold(); } @@ -492,7 +470,7 @@ ex add::derivative(const symbol & y) const for (auto & it : seq) s.push_back(expair(it.rest.diff(y), it.coeff)); - return dynallocate(std::move(s), _ex0); + return dynallocate(std::move(s)); } int add::compare_same_type(const basic & other) const