#include "ncmul.h"
#include "numeric.h"
#include "power.h"
-#include "relational.h"
-#include "indexed.h"
#include "lst.h"
+#include "relational.h"
#include "input_lexer.h"
#include "debugmsg.h"
#include "utils.h"
// none (all inlined)
-//////////
-// functions overriding virtual functions from bases classes
-//////////
-
-// none
-
-//////////
-// new virtual functions which can be overridden by derived classes
-//////////
-
-// none
-
//////////
// non-virtual functions in this class
//////////
ex ex::expand(unsigned options) const
{
GINAC_ASSERT(bp!=0);
- if (bp->flags & status_flags::expanded)
+ if (options == 0 && (bp->flags & status_flags::expanded)) // The "expanded" flag only covers the standard options; someone might want to re-expand with different options
return *bp;
else
return bp->expand(options);
return bp->match(pattern, repl_lst);
}
-/** Simplify/canonicalize expression containing indexed objects. This
- * performs contraction of dummy indices where possible and checks whether
- * the free indices in sums are consistent.
- *
- * @return simplified expression */
-ex ex::simplify_indexed(void) const
+/** Find all occurrences of a pattern. The found matches are appended to
+ * the "found" list. If the expression itself matches the pattern, the
+ * children are not further examined. This function returns true when any
+ * matches were found. */
+bool ex::find(const ex & pattern, lst & found) const
{
- return GiNaC::simplify_indexed(*this);
-}
-
-/** Simplify/canonicalize expression containing indexed objects. This
- * performs contraction of dummy indices where possible, checks whether
- * the free indices in sums are consistent, and automatically replaces
- * scalar products by known values if desired.
- *
- * @param sp Scalar products to be replaced automatically
- * @return simplified expression */
-ex ex::simplify_indexed(const scalar_products & sp) const
-{
- return GiNaC::simplify_indexed(*this, sp);
+ if (match(pattern)) {
+ found.append(*this);
+ found.sort();
+ found.unique();
+ return true;
+ }
+ bool any_found = false;
+ for (unsigned i=0; i<nops(); i++)
+ if (op(i).find(pattern, found))
+ any_found = true;
+ return any_found;
}
ex ex::operator[](const ex & index) const
* @see ex::ex(const basic &) */
void ex::construct_from_basic(const basic & other)
{
- if ((other.flags & status_flags::evaluated)==0) {
- // cf. copy ctor
+ if (!(other.flags & status_flags::evaluated)) {
const ex & tmpex = other.eval(1); // evaluate only one (top) level
bp = tmpex.bp;
- GINAC_ASSERT(bp!=0);
GINAC_ASSERT(bp->flags & status_flags::dynallocated);
++bp->refcount;
- if ((other.flags & status_flags::dynallocated)&&(other.refcount==0))
+ if ((other.refcount==0) && (other.flags & status_flags::dynallocated))
delete &const_cast<basic &>(other);
} else {
if (other.flags & status_flags::dynallocated) {