X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fbasic.cpp;h=9cb480f9f56ba06c9e4486316593da6ad570ebe7;hp=7a0634760354727c77aa06166e1922764b6f8338;hb=a629d98f0678a30e382283b3b7d4cd3abebaca20;hpb=12f5385726b14bd026f7722eae23c2239575fd00 diff --git a/ginac/basic.cpp b/ginac/basic.cpp index 7a063476..9cb480f9 100644 --- a/ginac/basic.cpp +++ b/ginac/basic.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's ABC. */ /* - * 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 @@ -57,7 +57,6 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(basic, void, * tinfo_key and the hash value. */ basic::basic(const basic & other) : tinfo_key(other.tinfo_key), flags(other.flags & ~status_flags::dynallocated), hashvalue(other.hashvalue) { - GINAC_ASSERT(typeid(*this) == typeid(other)); } /** basic assignment operator: the other object might be of a derived class. */ @@ -208,7 +207,7 @@ void basic::do_print_python_repr(const print_python_repr & c, unsigned level) co * @see basic::dbgprinttree */ void basic::dbgprint() const { - this->print(std::cerr); + this->print(print_dflt(std::cerr)); std::cerr << std::endl; } @@ -307,12 +306,23 @@ ex basic::map(map_function & f) const if (num == 0) return *this; - basic *copy = duplicate(); - copy->setflag(status_flags::dynallocated); - copy->clearflag(status_flags::hash_calculated | status_flags::expanded); - for (size_t i=0; ilet_op(i) = f(copy->op(i)); - return *copy; + basic *copy = NULL; + for (size_t i=0; ilet_op(i) = n; + } + } + + if (copy) { + copy->setflag(status_flags::dynallocated); + copy->clearflag(status_flags::hash_calculated | status_flags::expanded); + return *copy; + } else + return *this; } /** Return degree of highest power in object s. */ @@ -472,6 +482,20 @@ ex basic::evalm() const return map(map_evalm); } +/** Function object to be applied by basic::eval_integ(). */ +struct eval_integ_map_function : public map_function { + ex operator()(const ex & e) { return eval_integ(e); } +} map_eval_integ; + +/** Evaluate integrals, if result is known. */ +ex basic::eval_integ() const +{ + if (nops() == 0) + return *this; + else + return map(map_eval_integ); +} + /** Perform automatic symbolic evaluations on indexed expression that * contains this object as the base expression. */ ex basic::eval_indexed(const basic & i) const @@ -486,7 +510,7 @@ ex basic::eval_indexed(const basic & i) const * (or a subclass) and their indices are compatible. This function is used * internally by simplify_indexed(). * - * @param self First indexed expression; it's base object is *this + * @param self First indexed expression; its base object is *this * @param other Second indexed expression * @return sum of self and other * @see ex::simplify_indexed() */ @@ -498,7 +522,7 @@ ex basic::add_indexed(const ex & self, const ex & other) const /** Multiply an indexed expression with a scalar. This function is used * internally by simplify_indexed(). * - * @param self Indexed expression; it's base object is *this + * @param self Indexed expression; its base object is *this * @param other Numeric value * @return product of self and other * @see ex::simplify_indexed() */ @@ -514,7 +538,7 @@ ex basic::scalar_mul_indexed(const ex & self, const numeric & other) const * and that at least one dummy index has been found. This functions is * used internally by simplify_indexed(). * - * @param self Pointer to first indexed expression; it's base object is *this + * @param self Pointer to first indexed expression; its base object is *this * @param other Pointer to second indexed expression * @param v The complete vector of factors * @return true if the contraction was successful, false otherwise @@ -593,9 +617,11 @@ ex basic::subs_one_level(const exmap & m, unsigned options) const exmap::const_iterator it; if (options & subs_options::no_pattern) { - it = m.find(*this); + ex thisex = *this; + it = m.find(thisex); if (it != m.end()) return it->second; + return thisex; } else { for (it = m.begin(); it != m.end(); ++it) { lst repl_lst; @@ -781,7 +807,7 @@ unsigned basic::calchash() const struct expand_map_function : public map_function { unsigned options; expand_map_function(unsigned o) : options(o) {} - ex operator()(const ex & e) { return expand(e, options); } + ex operator()(const ex & e) { return e.expand(options); } }; /** Expand expression, i.e. multiply it out and return the result as a new