]> www.ginac.de Git - ginac.git/blobdiff - ginac/basic.cpp
- in the output, list delimiters are now { } and matrix delimiters are [ ]
[ginac.git] / ginac / basic.cpp
index 90b9c1452baa6828788f51764275e161db2fbcd3..1990ebcba938bd4b5fedf81f1ac74b5724d5729f 100644 (file)
@@ -221,16 +221,32 @@ bool basic::has(const ex & other) const
 {
        GINAC_ASSERT(other.bp!=0);
        lst repl_lst;
-       if (match(*other.bp, repl_lst)) return true;
-       if (nops()>0) {
-               for (unsigned i=0; i<nops(); i++)
-                       if (op(i).has(other))
-                               return true;
-       }
+       if (match(*other.bp, repl_lst))
+               return true;
+       for (unsigned i=0; i<nops(); i++)
+               if (op(i).has(other))
+                       return true;
        
        return false;
 }
 
+/** Construct new expression by applying the specified function to all
+ *  sub-expressions. */
+ex basic::map(map_func f) const
+{
+       unsigned num = nops();
+       if (num == 0)
+               return *this;
+
+       basic *copy = duplicate();
+       copy->setflag(status_flags::dynallocated);
+       copy->clearflag(status_flags::hash_calculated);
+       ex e(*copy);
+       for (unsigned i=0; i<num; i++)
+               e.let_op(i) = f(e.op(i));
+       return e.eval();
+}
+
 /** Return degree of highest power in object s. */
 int basic::degree(const ex & s) const
 {
@@ -347,6 +363,16 @@ ex basic::evalf(int level) const
        return *this;
 }
 
+/** Evaluate sums and products of matrices. */
+ex basic::evalm(void) const
+{
+       unsigned num = nops();
+       if (num == 0)
+               return *this;
+       else
+               return map(GiNaC::evalm);
+}
+
 /** Perform automatic symbolic evaluations on indexed expression that
  *  contains this object as the base expression. */
 ex basic::eval_indexed(const basic & i) const