X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fexpairseq.cpp;h=f46039d6c231cd34b9a04592591c6423015ea9fd;hp=08c81d0313baab96eb83496e473f26fcadeb5160;hb=9d2ba6504125b9c7f0ec8f547ee39a96c6e3806d;hpb=9bf900398c9e10c1cd486377038c24f9410fcb08 diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index 08c81d03..f46039d6 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -3,7 +3,7 @@ * Implementation of sequences of expression pairs. */ /* - * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2003 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 @@ -126,6 +126,7 @@ expairseq::expairseq(const exvector &v) : inherited(TINFO_expairseq) expairseq::expairseq(const epvector &v, const ex &oc) : inherited(TINFO_expairseq), overall_coeff(oc) { + GINAC_ASSERT(is_a(oc)); construct_from_epvector(v); GINAC_ASSERT(is_canonical()); } @@ -134,6 +135,7 @@ expairseq::expairseq(epvector *vp, const ex &oc) : inherited(TINFO_expairseq), overall_coeff(oc) { GINAC_ASSERT(vp!=0); + GINAC_ASSERT(is_a(oc)); construct_from_epvector(*vp); delete vp; GINAC_ASSERT(is_canonical()); @@ -402,7 +404,7 @@ ex expairseq::subs(const lst &ls, const lst &lr, bool no_pattern) const { epvector *vp = subschildren(ls, lr, no_pattern); if (vp) - return ex_to(thisexpairseq(vp, overall_coeff)).basic::subs(ls, lr, no_pattern); + return ex_to(thisexpairseq(vp, overall_coeff)); else return basic::subs(ls, lr, no_pattern); } @@ -1057,7 +1059,7 @@ void expairseq::make_flat(const epvector &v) /** Brings this expairseq into a sorted (canonical) form. */ void expairseq::canonicalize(void) { - std::sort(seq.begin(), seq.end(), expair_is_less()); + std::sort(seq.begin(), seq.end(), expair_rest_is_less()); } @@ -1066,42 +1068,43 @@ void expairseq::canonicalize(void) * instance. */ void expairseq::combine_same_terms_sorted_seq(void) { + if (seq.size()<2) + return; + bool needs_further_processing = false; - - if (seq.size()>1) { - epvector::iterator itin1 = seq.begin(); - epvector::iterator itin2 = itin1+1; - epvector::iterator itout = itin1; - epvector::iterator last = seq.end(); - // must_copy will be set to true the first time some combination is - // possible from then on the sequence has changed and must be compacted - bool must_copy = false; - while (itin2!=last) { - if (itin1->rest.compare(itin2->rest)==0) { - itin1->coeff = ex_to(itin1->coeff). - add_dyn(ex_to(itin2->coeff)); - if (expair_needs_further_processing(itin1)) - needs_further_processing = true; - must_copy = true; - } else { - if (!ex_to(itin1->coeff).is_zero()) { - if (must_copy) - *itout = *itin1; - ++itout; - } - itin1 = itin2; + + epvector::iterator itin1 = seq.begin(); + epvector::iterator itin2 = itin1+1; + epvector::iterator itout = itin1; + epvector::iterator last = seq.end(); + // must_copy will be set to true the first time some combination is + // possible from then on the sequence has changed and must be compacted + bool must_copy = false; + while (itin2!=last) { + if (itin1->rest.compare(itin2->rest)==0) { + itin1->coeff = ex_to(itin1->coeff). + add_dyn(ex_to(itin2->coeff)); + if (expair_needs_further_processing(itin1)) + needs_further_processing = true; + must_copy = true; + } else { + if (!ex_to(itin1->coeff).is_zero()) { + if (must_copy) + *itout = *itin1; + ++itout; } - ++itin2; - } - if (!ex_to(itin1->coeff).is_zero()) { - if (must_copy) - *itout = *itin1; - ++itout; + itin1 = itin2; } - if (itout!=last) - seq.erase(itout,last); + ++itin2; } - + if (!ex_to(itin1->coeff).is_zero()) { + if (must_copy) + *itout = *itin1; + ++itout; + } + if (itout!=last) + seq.erase(itout,last); + if (needs_further_processing) { epvector v = seq; seq.clear();