]> www.ginac.de Git - ginac.git/blobdiff - ginac/basic.cpp
sums of indexed matrices are now possible
[ginac.git] / ginac / basic.cpp
index 6adc4c498ab07f157d1329343e2f6c7f89d28b7a..6415f33fde5a79456ebb97ba0e81f36139110c97 100644 (file)
@@ -117,7 +117,7 @@ void basic::archive(archive_node &n) const
 void basic::print(std::ostream & os, unsigned upper_precedence) const
 {
        debugmsg("basic print",LOGLEVEL_PRINT);
-       os << "[basic object]";
+       os << "[" << class_name() << " object]";
 }
 
 /** Output to ostream in ugly raw format, so brave developers can have a look
@@ -125,7 +125,7 @@ void basic::print(std::ostream & os, unsigned upper_precedence) const
 void basic::printraw(std::ostream & os) const
 {
        debugmsg("basic printraw",LOGLEVEL_PRINT);
-       os << "[basic object]";
+       os << "[" << class_name() << " object]";
 }
 
 /** Output to ostream formatted in tree- (indented-) form, so developers can
@@ -287,6 +287,47 @@ ex basic::evalf(int level) const
        return *this;
 }
 
+/** Perform automatic symbolic evaluations on indexed expression that
+ *  contains this object as the base expression. */
+ex basic::eval_indexed(const basic & i) const
+ // this function can't take a "const ex & i" because that would result
+ // in an infinite eval() loop
+{
+       // There is nothing to do for basic objects
+       return i.hold();
+}
+
+/** Add two indexed expressions. They are guaranteed to be of class indexed
+ *  (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 other Second indexed expression
+ *  @return sum of self and other 
+ *  @see ex::simplify_indexed() */
+ex basic::add_indexed(const ex & self, const ex & other) const
+{
+       return self + other;
+}
+
+/** Try to contract two indexed expressions that appear in the same product. 
+ *  If a contraction exists, the function overwrites one or both of the
+ *  expressions and returns true. Otherwise it returns false. It is
+ *  guaranteed that both expressions are of class indexed (or a subclass)
+ *  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 other Pointer to second indexed expression
+ *  @param v The complete vector of factors
+ *  @return true if the contraction was successful, false otherwise
+ *  @see ex::simplify_indexed() */
+bool basic::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
+{
+       // Do nothing
+       return false;
+}
+
 /** Substitute a set of symbols by arbitrary expressions. The ex returned
  *  will already be evaluated. */
 ex basic::subs(const lst & ls, const lst & lr) const
@@ -320,7 +361,8 @@ ex basic::diff(const symbol & s, unsigned nth) const
        return ndiff;
 }
 
-exvector basic::get_indices(void) const
+/** Return a vector containing the free indices of an expression. */
+exvector basic::get_free_indices(void) const
 {
        return exvector(); // return an empty exvector
 }
@@ -344,7 +386,8 @@ ex basic::derivative(const symbol & s) const
 /** Returns order relation between two objects of same type.  This needs to be
  *  implemented by each class. It may never return anything else than 0,
  *  signalling equality, or +1 and -1 signalling inequality and determining
- *  the canonical ordering. */
+ *  the canonical ordering.  (Perl hackers will wonder why C++ doesn't feature
+ *  the spaceship operator <=> for denoting just this.) */
 int basic::compare_same_type(const basic & other) const
 {
        return compare_pointers(this, &other);
@@ -475,16 +518,18 @@ int basic::compare(const basic & other) const
        
        GINAC_ASSERT(typeid(*this)==typeid(other));
        
-       int cmpval = compare_same_type(other);
-       if ((cmpval!=0) && (hash_this<0x80000000U)) {
+//     int cmpval = compare_same_type(other);
+//     if ((cmpval!=0) && (hash_this<0x80000000U)) {
 //             std::cout << "hash collision, same type: " 
 //                       << *this << " and " << other << std::endl;
 //             this->printraw(std::cout);
 //             std::cout << " and ";
 //             other.printraw(std::cout);
 //             std::cout << std::endl;
-       }
-       return cmpval;
+//     }
+//     return cmpval;
+       
+       return compare_same_type(other);
 }
 
 /** Test for equality.