*
* Implementation of GiNaC's products of expressions. */
+/*
+ * 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 <vector>
#include <stdexcept>
-#include "ginac.h"
+#include "mul.h"
+#include "add.h"
+#include "power.h"
+#include "debugmsg.h"
+
+namespace GiNaC {
//////////
// default constructor, destructor, copy constructor assignment operator and helpers
mul::mul()
{
debugmsg("mul default constructor",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_MUL;
+ tinfo_key = TINFO_mul;
}
mul::~mul()
mul::mul(ex const & lh, ex const & rh)
{
debugmsg("mul constructor from ex,ex",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_MUL;
+ tinfo_key = TINFO_mul;
overall_coeff=exONE();
construct_from_2_ex(lh,rh);
- ASSERT(is_canonical());
+ GINAC_ASSERT(is_canonical());
}
mul::mul(exvector const & v)
{
debugmsg("mul constructor from exvector",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_MUL;
+ tinfo_key = TINFO_mul;
overall_coeff=exONE();
construct_from_exvector(v);
- ASSERT(is_canonical());
+ GINAC_ASSERT(is_canonical());
}
/*
mul::mul(epvector const & v, bool do_not_canonicalize)
{
debugmsg("mul constructor from epvector,bool",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_MUL;
+ tinfo_key = TINFO_mul;
if (do_not_canonicalize) {
seq=v;
#ifdef EXPAIRSEQ_USE_HASHTAB
} else {
construct_from_epvector(v);
}
- ASSERT(is_canonical());
+ GINAC_ASSERT(is_canonical());
}
*/
mul::mul(epvector const & v)
{
debugmsg("mul constructor from epvector",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_MUL;
+ tinfo_key = TINFO_mul;
overall_coeff=exONE();
construct_from_epvector(v);
- ASSERT(is_canonical());
+ GINAC_ASSERT(is_canonical());
}
mul::mul(epvector const & v, ex const & oc)
{
debugmsg("mul constructor from epvector,ex",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_MUL;
+ tinfo_key = TINFO_mul;
overall_coeff=oc;
construct_from_epvector(v);
- ASSERT(is_canonical());
+ GINAC_ASSERT(is_canonical());
}
mul::mul(epvector * vp, ex const & oc)
{
debugmsg("mul constructor from epvector *,ex",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_MUL;
- ASSERT(vp!=0);
+ tinfo_key = TINFO_mul;
+ GINAC_ASSERT(vp!=0);
overall_coeff=oc;
construct_from_epvector(*vp);
delete vp;
- ASSERT(is_canonical());
+ GINAC_ASSERT(is_canonical());
}
mul::mul(ex const & lh, ex const & mh, ex const & rh)
{
debugmsg("mul constructor from ex,ex,ex",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_MUL;
+ tinfo_key = TINFO_mul;
exvector factors;
factors.reserve(3);
factors.push_back(lh);
factors.push_back(rh);
overall_coeff=exONE();
construct_from_exvector(factors);
- ASSERT(is_canonical());
+ GINAC_ASSERT(is_canonical());
}
//////////
debugmsg("mul eval",LOGLEVEL_MEMBER_FUNCTION);
if ((level==1)&&(flags & status_flags::evaluated)) {
-#ifdef DOASSERT
+#ifdef DO_GINAC_ASSERT
for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- ASSERT((!is_ex_exactly_of_type((*cit).rest,mul))||
+ GINAC_ASSERT((!is_ex_exactly_of_type((*cit).rest,mul))||
(!(ex_to_numeric((*cit).coeff).is_integer())));
}
do {
cit--;
if (is_ex_exactly_of_type((*cit).rest,numeric)) {
- ASSERT(all_numeric);
+ GINAC_ASSERT(all_numeric);
if ((*cit).coeff.is_equal(exONE())) {
- ASSERT(all_coeff_1);
+ GINAC_ASSERT(all_coeff_1);
} else {
all_coeff_1=false;
}
}
} while (cit!=seq.begin());
}
-#endif // def DOASSERT
+#endif // def DO_GINAC_ASSERT
return *this;
}
}
-#ifdef DOASSERT
+#ifdef DO_GINAC_ASSERT
for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- ASSERT((!is_ex_exactly_of_type((*cit).rest,mul))||
+ GINAC_ASSERT((!is_ex_exactly_of_type((*cit).rest,mul))||
(!(ex_to_numeric((*cit).coeff).is_integer())));
}
do {
cit--;
if (is_ex_exactly_of_type((*cit).rest,numeric)) {
- ASSERT(all_numeric);
+ GINAC_ASSERT(all_numeric);
if ((*cit).coeff.is_equal(exONE())) {
- ASSERT(all_coeff_1);
+ GINAC_ASSERT(all_coeff_1);
} else {
all_coeff_1=false;
}
}
} while (cit!=seq.begin());
}
-#endif // def DOASSERT
+#endif // def DO_GINAC_ASSERT
if (flags & status_flags::evaluated) {
return *this;
setflag(status_flags::dynallocated);
}
-#ifdef DOASSERT
+#ifdef DO_GINAC_ASSERT
for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- ASSERT((!is_ex_exactly_of_type((*cit).rest,mul))||
+ GINAC_ASSERT((!is_ex_exactly_of_type((*cit).rest,mul))||
(!(ex_to_numeric((*cit).coeff).is_integer())));
- ASSERT(!((*cit).is_numeric_with_coeff_1()));
+ GINAC_ASSERT(!((*cit).is_numeric_with_coeff_1()));
if (is_ex_exactly_of_type(recombine_pair_to_ex(*cit),numeric)) {
printtree(cerr,0);
}
- ASSERT(!is_ex_exactly_of_type(recombine_pair_to_ex(*cit),numeric));
+ GINAC_ASSERT(!is_ex_exactly_of_type(recombine_pair_to_ex(*cit),numeric));
/* for paranoia */
expair p=split_ex_to_pair(recombine_pair_to_ex(*cit));
- ASSERT(p.rest.is_equal((*cit).rest));
- ASSERT(p.coeff.is_equal((*cit).coeff));
+ GINAC_ASSERT(p.rest.is_equal((*cit).rest));
+ GINAC_ASSERT(p.coeff.is_equal((*cit).coeff));
/* end paranoia */
}
-#endif // def DOASSERT
+#endif // def DO_GINAC_ASSERT
if (flags & status_flags::evaluated) {
- ASSERT(seq.size()>0);
- ASSERT((seq.size()>1)||!overall_coeff.is_equal(exONE()));
+ GINAC_ASSERT(seq.size()>0);
+ GINAC_ASSERT((seq.size()>1)||!overall_coeff.is_equal(exONE()));
return *this;
}
void mul::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).mul_dyn(ex_to_numeric(c));
}
void mul::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).
mul_dyn(ex_to_numeric(c1).power(ex_to_numeric(c2)));
}
bool mul::can_make_flat(expair const & p) const
{
- ASSERT(is_ex_exactly_of_type(p.coeff,numeric));
+ GINAC_ASSERT(is_ex_exactly_of_type(p.coeff,numeric));
// this assertion will probably fail somewhere
// it would require a more careful make_flat, obeying the power laws
// probably should return true only if p.coeff is integer
term=expanded_seq;
for (l=0; l<number_of_adds; l++) {
add const & addref=ex_to_add(expanded_seq[positions_of_adds[l]].rest);
- ASSERT(term[positions_of_adds[l]].coeff.compare(exONE())==0);
+ GINAC_ASSERT(term[positions_of_adds[l]].coeff.compare(exONE())==0);
term[positions_of_adds[l]]=split_ex_to_pair(addref.op(k[l]));
}
/*
const mul some_mul;
type_info const & typeid_mul=typeid(some_mul);
-
+} // namespace GiNaC