From: Jens Vollinga Date: Mon, 15 Oct 2007 23:40:30 +0000 (+0000) Subject: - Apparently, in ~ 30% of calls to mul::expand the expression is monomial. X-Git-Tag: release_1-5-0~133 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=da6a61ba2586263e46ade4b67dca121506c2bff9;hp=7d05f39c095dc51cc4526b17a5ab3280f8924219 - Apparently, in ~ 30% of calls to mul::expand the expression is monomial. Expanding monomials should be done as fast as possible [Sheplyakov]. --- diff --git a/ginac/mul.cpp b/ginac/mul.cpp index db8b9f14..298715b3 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -34,6 +34,7 @@ #include "lst.h" #include "archive.h" #include "utils.h" +#include "symbol.h" #include "compiler.h" namespace GiNaC { @@ -992,6 +993,15 @@ bool mul::can_be_further_expanded(const ex & e) ex mul::expand(unsigned options) const { + { + // 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); + } + const bool skip_idx_rename = ! info(info_flags::has_indices); // First, expand the children std::auto_ptr expanded_seqp = expandchildren(options); diff --git a/ginac/power.cpp b/ginac/power.cpp index 10de528d..1b28b509 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -772,6 +772,9 @@ tinfo_t power::return_type_tinfo() const ex power::expand(unsigned options) const { + if (is_a(basis) && exponent.info(info_flags::integer)) + return (new power(*this))->setflag(status_flags::dynallocated | status_flags::expanded); + if (options == 0 && (flags & status_flags::expanded)) return *this;