X-Git-Url: https://ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fpower.cpp;h=ec339b9a660afc6aac21fa9307b6bec5e26144ce;hb=a297391b22c1a4ec3464d13191f8cb33332c9863;hp=1b28b509ac4bd35ef4bbcf7777e40069bcf056f2;hpb=da6a61ba2586263e46ade4b67dca121506c2bff9;p=ginac.git diff --git a/ginac/power.cpp b/ginac/power.cpp index 1b28b509..ec339b9a 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's symbolic exponentiation (basis^exponent). */ /* - * 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 @@ -506,8 +506,8 @@ ex power::eval(int level) const // (2*x + 6*y)^(-4) -> 1/16*(x + 3*y)^(-4) if (num_exponent->is_integer() && is_exactly_a(ebasis)) { numeric icont = ebasis.integer_content(); - const numeric& lead_coeff = - ex_to(ex_to(ebasis).seq.begin()->coeff).div_dyn(icont); + const numeric lead_coeff = + ex_to(ex_to(ebasis).seq.begin()->coeff).div(icont); const bool canonicalizable = lead_coeff.is_integer(); const bool unit_normal = lead_coeff.is_pos_integer(); @@ -772,12 +772,12 @@ 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)) + if (is_a(basis) && exponent.info(info_flags::integer)) { + // A special case worth optimizing. + setflag(status_flags::expanded); return *this; - + } + const ex expanded_basis = basis.expand(options); const ex expanded_exponent = exponent.expand(options); @@ -1010,8 +1010,13 @@ ex power::expand_mul(const mul & m, const numeric & n, unsigned options, bool fr return _ex1; } + // do not bother to rename indices if there are no any. + if ((!(options & expand_options::expand_rename_idx)) + && m.info(info_flags::has_indices)) + options |= expand_options::expand_rename_idx; // Leave it to multiplication since dummy indices have to be renamed - if (get_all_dummy_indices(m).size() > 0 && n.is_positive()) { + if ((options & expand_options::expand_rename_idx) && + (get_all_dummy_indices(m).size() > 0) && n.is_positive()) { ex result = m; exvector va = get_all_dummy_indices(m); sort(va.begin(), va.end(), ex_is_less());