* Implementation of sequences of expression pairs. */
/*
- * GiNaC Copyright (C) 1999-2002 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
expairseq::expairseq(const epvector &v, const ex &oc)
: inherited(TINFO_expairseq), overall_coeff(oc)
{
+ GINAC_ASSERT(is_a<numeric>(oc));
construct_from_epvector(v);
GINAC_ASSERT(is_canonical());
}
: inherited(TINFO_expairseq), overall_coeff(oc)
{
GINAC_ASSERT(vp!=0);
+ GINAC_ASSERT(is_a<numeric>(oc));
construct_from_epvector(*vp);
delete vp;
GINAC_ASSERT(is_canonical());
{
epvector *vp = subschildren(ls, lr, no_pattern);
if (vp)
- return ex_to<basic>(thisexpairseq(vp, overall_coeff)).basic::subs(ls, lr, no_pattern);
+ return ex_to<basic>(thisexpairseq(vp, overall_coeff));
else
return basic::subs(ls, lr, no_pattern);
}
/** 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());
}
* 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<numeric>(itin1->coeff).
- add_dyn(ex_to<numeric>(itin2->coeff));
- if (expair_needs_further_processing(itin1))
- needs_further_processing = true;
- must_copy = true;
- } else {
- if (!ex_to<numeric>(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<numeric>(itin1->coeff).
+ add_dyn(ex_to<numeric>(itin2->coeff));
+ if (expair_needs_further_processing(itin1))
+ needs_further_processing = true;
+ must_copy = true;
+ } else {
+ if (!ex_to<numeric>(itin1->coeff).is_zero()) {
+ if (must_copy)
+ *itout = *itin1;
+ ++itout;
}
- ++itin2;
- }
- if (!ex_to<numeric>(itin1->coeff).is_zero()) {
- if (must_copy)
- *itout = *itin1;
- ++itout;
+ itin1 = itin2;
}
- if (itout!=last)
- seq.erase(itout,last);
+ ++itin2;
}
-
+ if (!ex_to<numeric>(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();