* 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
*
* 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 <iostream>
* 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. */
* @see basic::dbgprinttree */
void basic::dbgprint() const
{
- this->print(std::cerr);
+ this->print(print_dflt(std::cerr));
std::cerr << std::endl;
}
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; i<num; i++)
- copy->let_op(i) = f(copy->op(i));
- return *copy;
+ basic *copy = NULL;
+ for (size_t i=0; i<num; i++) {
+ const ex & o = op(i);
+ const ex & n = f(o);
+ if (!are_ex_trivially_equal(o, n)) {
+ if (copy == NULL)
+ copy = duplicate();
+ copy->let_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. */
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
* (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() */
/** 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() */
* 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
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;
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