X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fmul.cpp;h=90fd772ec2b16552c390e4697bfc30d3ca2871a8;hp=19dd2bdf406a8daa4e2b6689f6e0fcc7479a2df6;hb=7d6eeaeab9327e8a3349df45fb6cc6486bb43162;hpb=6d225ee55693c0617d254e6fa283c00c71bd2919 diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 19dd2bdf..90fd772e 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's products of expressions. */ /* - * GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2005 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 @@ -17,7 +17,7 @@ * * 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -30,6 +30,7 @@ #include "power.h" #include "operators.h" #include "matrix.h" +#include "indexed.h" #include "lst.h" #include "archive.h" #include "utils.h" @@ -40,7 +41,7 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(mul, expairseq, print_func(&mul::do_print). print_func(&mul::do_print_latex). print_func(&mul::do_print_csrc). - print_func(&inherited::do_print_tree). + print_func(&mul::do_print_tree). print_func(&mul::do_print_python_repr)) @@ -94,7 +95,7 @@ mul::mul(const epvector & v, const ex & oc) mul::mul(std::auto_ptr vp, const ex & oc) { tinfo_key = TINFO_mul; - GINAC_ASSERT(vp!=0); + GINAC_ASSERT(vp.get()!=0); overall_coeff = oc; construct_from_epvector(*vp); GINAC_ASSERT(is_canonical()); @@ -128,8 +129,8 @@ void mul::print_overall_coeff(const print_context & c, const char *mul_sym) cons const numeric &coeff = ex_to(overall_coeff); if (coeff.csgn() == -1) c.s << '-'; - if (!coeff.is_equal(_num1) && - !coeff.is_equal(_num_1)) { + if (!coeff.is_equal(*_num1_p) && + !coeff.is_equal(*_num_1_p)) { if (coeff.is_rational()) { if (coeff.is_negative()) (-coeff).print(c); @@ -421,7 +422,7 @@ ex mul::eval(int level) const return recombine_pair_to_ex(*(seq.begin())); } else if ((seq_size==1) && is_exactly_a((*seq.begin()).rest) && - ex_to((*seq.begin()).coeff).is_equal(_num1)) { + ex_to((*seq.begin()).coeff).is_equal(*_num1_p)) { // *(+(x,y,...);c) -> +(*(x,c),*(y,c),...) (c numeric(), no powers of +()) const add & addref = ex_to((*seq.begin()).rest); std::auto_ptr distrseq(new epvector); @@ -672,7 +673,7 @@ int mul::compare_same_type(const basic & other) const unsigned mul::return_type() const { if (seq.empty()) { - // mul without factors: should not happen, but commutes + // mul without factors: should not happen, but commutates return return_types::commutative; } @@ -766,7 +767,7 @@ expair mul::combine_pair_with_coeff_to_pair(const expair & p, ex mul::recombine_pair_to_ex(const expair & p) const { - if (ex_to(p.coeff).is_equal(_num1)) + if (ex_to(p.coeff).is_equal(*_num1_p)) return p.rest; else return (new power(p.rest,p.coeff))->setflag(status_flags::dynallocated); @@ -821,7 +822,7 @@ bool mul::can_make_flat(const expair & p) const // 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 - return ex_to(p.coeff).is_equal(_num1); + return ex_to(p.coeff).is_equal(*_num1_p); } bool mul::can_be_further_expanded(const ex & e) @@ -848,7 +849,6 @@ ex mul::expand(unsigned options) const // with the next one that is found while collecting the factors which are // not sums ex last_expanded = _ex1; - bool need_reexpand = false; epvector non_adds; non_adds.reserve(expanded_seq.size()); @@ -904,11 +904,12 @@ ex mul::expand(unsigned options) const for (epvector::const_iterator i2=add2begin; i2!=add2end; ++i2) { // Don't push_back expairs which might have a rest that evaluates to a numeric, // since that would violate an invariant of expairseq: - const ex rest = (new mul(i1->rest, i2->rest))->setflag(status_flags::dynallocated); - if (is_exactly_a(rest)) + const ex rest = (new mul(i1->rest, rename_dummy_indices_uniquely(i1->rest, i2->rest)))->setflag(status_flags::dynallocated); + if (is_exactly_a(rest)) { oc += ex_to(rest).mul(ex_to(i1->coeff).mul(ex_to(i2->coeff))); - else + } else { distrseq.push_back(expair(rest, ex_to(i1->coeff).mul_dyn(ex_to(i2->coeff)))); + } } tmp_accu += (new add(distrseq, oc))->setflag(status_flags::dynallocated); } @@ -934,11 +935,11 @@ ex mul::expand(unsigned options) const for (size_t i=0; isetflag(status_flags::dynallocated); - if (can_be_further_expanded(term)) + if (can_be_further_expanded(term)) { distrseq.push_back(term.expand()); - else { + } else { if (options == 0) ex_to(term).setflag(status_flags::expanded); distrseq.push_back(term);