]> www.ginac.de Git - ginac.git/blobdiff - ginac/ex.cpp
- fixed a problem where (p\-m*ONE)*(p\-m*ONE) would be automatically simplified
[ginac.git] / ginac / ex.cpp
index e8ce2da1eabce3e5ba12b0ad1e60f415ceb62d42..b6b968595e05e662aa89e2b89c0aefd4a274fbef 100644 (file)
@@ -29,9 +29,8 @@
 #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"
@@ -44,18 +43,6 @@ namespace GiNaC {
 
 // 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
 //////////
@@ -116,7 +103,7 @@ void ex::dbgprinttree(void) const
 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);
@@ -144,26 +131,23 @@ bool ex::match(const ex & pattern) const
        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
@@ -230,14 +214,12 @@ void ex::makewriteable()
  *  @see ex::ex(const basic &) */
 void ex::construct_from_basic(const basic & other)
 {
-       if ((other.flags & status_flags::evaluated)==0) {
-               // cf. copy ctor
-               const ex & tmpex = other.eval(1); // evaluate only one (top) level
+       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) {