X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fmul.cpp;h=78f2bd9eb0a3e7e8f12df27243117ff4ce22689c;hb=52b8a6451d4d5f32e45e3dbf93c22369fc2f99c2;hp=bf5e70dff0d77d4bc5687907cae8974ddee24d87;hpb=6b3768e8c544739ae53321539cb4d1e3112ded1b;p=ginac.git diff --git a/ginac/mul.cpp b/ginac/mul.cpp index bf5e70df..78f2bd9e 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -2,10 +2,33 @@ * * 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 #include -#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 @@ -16,7 +39,7 @@ mul::mul() { debugmsg("mul default constructor",LOGLEVEL_CONSTRUCT); - tinfo_key = TINFO_MUL; + tinfo_key = TINFO_mul; } mul::~mul() @@ -62,26 +85,26 @@ void mul::destroy(bool call_parent) 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 @@ -90,43 +113,43 @@ mul::mul(epvector const & v, bool do_not_canonicalize) } 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); @@ -134,7 +157,7 @@ mul::mul(ex const & lh, ex const & mh, ex const & rh) factors.push_back(rh); overall_coeff=exONE(); construct_from_exvector(factors); - ASSERT(is_canonical()); + GINAC_ASSERT(is_canonical()); } ////////// @@ -234,9 +257,9 @@ ex mul::eval(int level) const 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()))); } @@ -249,9 +272,9 @@ ex mul::eval(int level) const 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; } @@ -260,7 +283,7 @@ ex mul::eval(int level) const } } while (cit!=seq.begin()); } -#endif // def DOASSERT +#endif // def DO_GINAC_ASSERT return *this; } @@ -298,9 +321,9 @@ ex mul::eval(int level) const } -#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()))); } @@ -313,9 +336,9 @@ ex mul::eval(int level) const 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; } @@ -324,7 +347,7 @@ ex mul::eval(int level) const } } while (cit!=seq.begin()); } -#endif // def DOASSERT +#endif // def DO_GINAC_ASSERT if (flags & status_flags::evaluated) { return *this; @@ -458,26 +481,26 @@ ex mul::eval(int level) const 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; } @@ -750,23 +773,23 @@ ex mul::default_overall_coeff(void) const 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 @@ -829,7 +852,7 @@ ex mul::expand(unsigned options) const term=expanded_seq; for (l=0; l