-/** @file expairseq.cpp */
+/** @file expairseq.cpp
+ *
+ * Implementation of sequences of expression pairs. */
+
+/*
+ * GiNaC Copyright (C) 1999 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
#include <algorithm>
#include <string>
#include <stdexcept>
-#include "ginac.h"
+#include "expairseq.h"
+#include "lst.h"
+#include "debugmsg.h"
+#include "utils.h"
+
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
#ifdef EXPAIRSEQ_USE_HASHTAB
-#error "!!!!!!!!TODO: expair_needs_further_processing not yet implemented for hashtabs, sorry. A.F."
+#error "FIXME: expair_needs_further_processing not yet implemented for hashtabs, sorry. A.F."
#endif // def EXPAIRSEQ_USE_HASHTAB
//////////
// other constructors
//////////
-expairseq::expairseq(ex const & lh, ex const & rh) : basic(TINFO_EXPAIRSEQ)
+expairseq::expairseq(ex const & lh, ex const & rh) : basic(TINFO_expairseq)
{
debugmsg("expairseq constructor from ex,ex",LOGLEVEL_CONSTRUCT);
construct_from_2_ex(lh,rh);
- ASSERT(is_canonical());
+ GINAC_ASSERT(is_canonical());
}
-expairseq::expairseq(exvector const & v) : basic(TINFO_EXPAIRSEQ)
+expairseq::expairseq(exvector const & v) : basic(TINFO_expairseq)
{
debugmsg("expairseq constructor from exvector",LOGLEVEL_CONSTRUCT);
construct_from_exvector(v);
- ASSERT(is_canonical());
+ GINAC_ASSERT(is_canonical());
}
/*
expairseq::expairseq(epvector const & v, bool do_not_canonicalize) :
- basic(TINFO_EXPAIRSEQ)
+ basic(TINFO_expairseq)
{
debugmsg("expairseq constructor from epvector",LOGLEVEL_CONSTRUCT);
if (do_not_canonicalize) {
} else {
construct_from_epvector(v);
}
- ASSERT(is_canonical());
+ GINAC_ASSERT(is_canonical());
}
*/
expairseq::expairseq(epvector const & v, ex const & oc) :
- basic(TINFO_EXPAIRSEQ), overall_coeff(oc)
+ basic(TINFO_expairseq), overall_coeff(oc)
{
debugmsg("expairseq constructor from epvector,ex",LOGLEVEL_CONSTRUCT);
construct_from_epvector(v);
- ASSERT(is_canonical());
+ GINAC_ASSERT(is_canonical());
}
expairseq::expairseq(epvector * vp, ex const & oc) :
- basic(TINFO_EXPAIRSEQ), overall_coeff(oc)
+ basic(TINFO_expairseq), overall_coeff(oc)
{
debugmsg("expairseq constructor from epvector *,ex",LOGLEVEL_CONSTRUCT);
- ASSERT(vp!=0);
+ GINAC_ASSERT(vp!=0);
construct_from_epvector(*vp);
delete vp;
- ASSERT(is_canonical());
+ GINAC_ASSERT(is_canonical());
}
//////////
if (unsigned(i)<seq.size()) {
return recombine_pair_to_ex(seq[i]);
}
- ASSERT(!overall_coeff.is_equal(default_overall_coeff()));
+ GINAC_ASSERT(!overall_coeff.is_equal(default_overall_coeff()));
return overall_coeff;
}
int expairseq::compare_same_type(basic const & other) const
{
- ASSERT(is_of_type(other, expairseq));
+ GINAC_ASSERT(is_of_type(other, expairseq));
expairseq const & o=static_cast<expairseq const &>(const_cast<basic &>(other));
int cmpval;
//if (seq.size()==0) return 0; // empty expairseq's are equal
#ifdef EXPAIRSEQ_USE_HASHTAB
- ASSERT(hashtabsize==o.hashtabsize);
+ GINAC_ASSERT(hashtabsize==o.hashtabsize);
if (hashtabsize==0) {
#endif // def EXPAIRSEQ_USE_HASHTAB
epvector::const_iterator cit1=seq.begin();
if (cmpval!=0) return cmpval;
}
- ASSERT(cit1==last1);
- ASSERT(cit2==last2);
+ GINAC_ASSERT(cit1==last1);
+ GINAC_ASSERT(cit2==last2);
return 0;
#ifdef EXPAIRSEQ_USE_HASHTAB
other.printtree(cout,0);
}
- ASSERT(hashtabsize==o.hashtabsize);
+ GINAC_ASSERT(hashtabsize==o.hashtabsize);
if (hashtabsize==0) {
#endif // def EXPAIRSEQ_USE_HASHTAB
expair expairseq::combine_ex_with_coeff_to_pair(ex const & e,
ex const & c) const
{
- ASSERT(is_ex_exactly_of_type(c,numeric));
+ GINAC_ASSERT(is_ex_exactly_of_type(c,numeric));
return expair(e,c);
}
expair expairseq::combine_pair_with_coeff_to_pair(expair const & p,
ex const & c) const
{
- ASSERT(is_ex_exactly_of_type(p.coeff,numeric));
- ASSERT(is_ex_exactly_of_type(c,numeric));
+ GINAC_ASSERT(is_ex_exactly_of_type(p.coeff,numeric));
+ GINAC_ASSERT(is_ex_exactly_of_type(c,numeric));
return expair(p.rest,ex_to_numeric(p.coeff).mul_dyn(ex_to_numeric(c)));
}
void expairseq::combine_overall_coeff(ex const & c)
{
- ASSERT(is_ex_exactly_of_type(overall_coeff,numeric));
- ASSERT(is_ex_exactly_of_type(c,numeric));
+ GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric));
+ GINAC_ASSERT(is_ex_exactly_of_type(c,numeric));
overall_coeff = ex_to_numeric(overall_coeff).add_dyn(ex_to_numeric(c));
}
void expairseq::combine_overall_coeff(ex const & c1, ex const & c2)
{
- ASSERT(is_ex_exactly_of_type(overall_coeff,numeric));
- ASSERT(is_ex_exactly_of_type(c1,numeric));
- ASSERT(is_ex_exactly_of_type(c2,numeric));
+ GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric));
+ GINAC_ASSERT(is_ex_exactly_of_type(c1,numeric));
+ GINAC_ASSERT(is_ex_exactly_of_type(c2,numeric));
overall_coeff = ex_to_numeric(overall_coeff).
add_dyn(ex_to_numeric(c1).mul(ex_to_numeric(c2)));
}
v.push_back(rh);
construct_from_exvector(v);
#ifdef EXPAIRSEQ_USE_HASHTAB
- ASSERT((hashtabsize==0)||(hashtabsize>=minhashtabsize));
- ASSERT(hashtabsize==calc_hashtabsize(seq.size()));
+ GINAC_ASSERT((hashtabsize==0)||(hashtabsize>=minhashtabsize));
+ GINAC_ASSERT(hashtabsize==calc_hashtabsize(seq.size()));
#endif // def EXPAIRSEQ_USE_HASHTAB
}
// size=nearest_power_of_2*hashtabfactor;
size=nearest_power_of_2/hashtabfactor;
if (size<minhashtabsize) return 0;
- ASSERT(hashtabsize<=0x8000000U); // really max size due to 31 bit hashing
+ GINAC_ASSERT(hashtabsize<=0x8000000U); // really max size due to 31 bit hashing
// hashtabsize must be a power of 2
- ASSERT((1U << log2(size))==size);
+ GINAC_ASSERT((1U << log2(size))==size);
return size;
}
// last hashtab entry is reserved for numerics
if (hashindex==hashmask) hashindex=0;
}
- ASSERT(hashindex>=0);
- ASSERT((hashindex<hashtabsize)||(hashtabsize==0));
+ GINAC_ASSERT(hashindex>=0);
+ GINAC_ASSERT((hashindex<hashtabsize)||(hashtabsize==0));
return hashindex;
}
{
unsigned new_hashtabsize;
while (hashtabsize!=(new_hashtabsize=calc_hashtabsize(seq.size()))) {
- ASSERT(new_hashtabsize<hashtabsize);
+ GINAC_ASSERT(new_hashtabsize<hashtabsize);
if (new_hashtabsize==0) {
hashtab.clear();
hashtabsize=0;
}
++epplit;
}
- ASSERT(erased);
+ GINAC_ASSERT(erased);
}
- ASSERT(erased);
+ GINAC_ASSERT(erased);
}
void expairseq::move_hashtab_entry(epvector::const_iterator oldpos,
epvector::iterator newpos)
{
- ASSERT(hashtabsize!=0);
+ GINAC_ASSERT(hashtabsize!=0);
// calculate hashindex of element which was moved
unsigned hashindex=calc_hashindex((*newpos).rest);
}
++epplit;
}
- ASSERT(epplit!=eppl.end());
+ GINAC_ASSERT(epplit!=eppl.end());
}
void expairseq::sorted_insert(epplist & eppl, epp elem)
}
}
}
- ASSERT(i==current-seq.begin());
+ GINAC_ASSERT(i==current-seq.begin());
}
bool expairseq::has_coeff_0(void) const
if (hashtabsize==0) {
canonicalize();
combine_same_terms_sorted_seq();
- ASSERT(!has_coeff_0());
+ GINAC_ASSERT(!has_coeff_0());
return;
}
unsigned number_of_zeroes=0;
- ASSERT(!has_coeff_0());
+ GINAC_ASSERT(!has_coeff_0());
build_hashtab_and_combine(first_numeric,last_non_zero,touched,number_of_zeroes);
/*
cout << "in combine:" << endl;
}
// shrink hashtabsize to calculated value
- ASSERT(!has_coeff_0());
+ GINAC_ASSERT(!has_coeff_0());
shrink_hashtab();
- ASSERT(!has_coeff_0());
+ GINAC_ASSERT(!has_coeff_0());
}
#endif // def EXPAIRSEQ_USE_HASHTAB
const expairseq some_expairseq;
type_info const & typeid_expairseq=typeid(some_expairseq);
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE