X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fmul.cpp;h=3d33c78a129eeaeaaf9074bc291e76624e403da8;hp=298715b33fd2eabfd28ea9390229fb3f5b90b39d;hb=7d870583a6bf21a2ffb7b6f051b702064623892e;hpb=da6a61ba2586263e46ade4b67dca121506c2bff9 diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 298715b3..3d33c78a 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's products of expressions. */ /* - * GiNaC Copyright (C) 1999-2007 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2008 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 @@ -469,8 +469,8 @@ ex mul::eval(int level) const // XXX: What is the best way to check if the polynomial is a primitive? numeric c = i->rest.integer_content(); - const numeric& lead_coeff = - ex_to(ex_to(i->rest).seq.begin()->coeff).div_dyn(c); + const numeric lead_coeff = + ex_to(ex_to(i->rest).seq.begin()->coeff).div(c); const bool canonicalizable = lead_coeff.is_integer(); // XXX: The main variable is chosen in a random way, so this code @@ -994,15 +994,23 @@ bool mul::can_be_further_expanded(const ex & e) ex mul::expand(unsigned options) const { { - // trivial case: expanding the monomial (~ 30% of all calls) + // trivial case: expanding the monomial (~ 30% of all calls) epvector::const_iterator i = seq.begin(), seq_end = seq.end(); while ((i != seq.end()) && is_a(i->rest) && i->coeff.info(info_flags::integer)) ++i; - if (i == seq_end) - return (new mul(*this))->setflag(status_flags::dynallocated | status_flags::expanded); + if (i == seq_end) { + setflag(status_flags::expanded); + return *this; + } } - const bool skip_idx_rename = ! info(info_flags::has_indices); + // do not rename indices if the object has no indices at all + if ((!(options & expand_options::expand_rename_idx)) && + this->info(info_flags::has_indices)) + options |= expand_options::expand_rename_idx; + + const bool skip_idx_rename = !(options & expand_options::expand_rename_idx); + // First, expand the children std::auto_ptr expanded_seqp = expandchildren(options); const epvector & expanded_seq = (expanded_seqp.get() ? *expanded_seqp : seq);