X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fpseries.cpp;h=0e1f183322c47114404c1c4c7b502f6cc44d68f4;hp=14488ba71c222b81e033379d51f61be66e94b062;hb=04aace56d3d2ca82be59460bf1922600ae43449a;hpb=690cd58cc13ad5052eb5851c573984965d0c40c1 diff --git a/ginac/pseries.cpp b/ginac/pseries.cpp index 14488ba7..0e1f1833 100644 --- a/ginac/pseries.cpp +++ b/ginac/pseries.cpp @@ -4,7 +4,7 @@ * methods for series expansion. */ /* - * GiNaC Copyright (C) 1999-2006 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2007 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 @@ -82,14 +82,19 @@ pseries::pseries(const ex &rel_, const epvector &ops_) : basic(&pseries::tinfo_s pseries::pseries(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst) { - for (unsigned int i=0; true; ++i) { + archive_node::archive_node_cit first = n.find_first("coeff"); + archive_node::archive_node_cit last = n.find_last("power"); + ++last; + seq.reserve((last-first)/2); + + for (archive_node::archive_node_cit loc = first; loc < last;) { ex rest; ex coeff; - if (n.find_ex("coeff", rest, sym_lst, i) && n.find_ex("power", coeff, sym_lst, i)) - seq.push_back(expair(rest, coeff)); - else - break; + n.find_ex_by_loc(loc++, rest, sym_lst); + n.find_ex_by_loc(loc++, coeff, sym_lst); + seq.push_back(expair(rest, coeff)); } + n.find_ex("var", var, sym_lst); n.find_ex("point", point, sym_lst); } @@ -484,6 +489,34 @@ ex pseries::eval_integ() const return *this; } +ex pseries::evalm() const +{ + // evalm each coefficient + epvector newseq; + bool something_changed = false; + for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) { + if (something_changed) { + ex newcoeff = i->rest.evalm(); + if (!newcoeff.is_zero()) + newseq.push_back(expair(newcoeff, i->coeff)); + } + else { + ex newcoeff = i->rest.evalm(); + if (!are_ex_trivially_equal(newcoeff, i->rest)) { + something_changed = true; + newseq.reserve(seq.size()); + std::copy(seq.begin(), i, std::back_inserter(newseq)); + if (!newcoeff.is_zero()) + newseq.push_back(expair(newcoeff, i->coeff)); + } + } + } + if (something_changed) + return (new pseries(var==point, newseq))->setflag(status_flags::dynallocated); + else + return *this; +} + ex pseries::subs(const exmap & m, unsigned options) const { // If expansion variable is being substituted, convert the series to a