]> www.ginac.de Git - ginac.git/blobdiff - ginac/ex.h
Improved dummy index renaming.
[ginac.git] / ginac / ex.h
index 030046c5c1d576612634cb4c7a2daf4be4b3181c..60ffa12934047f2054e3549be071d77849c6ea1a 100644 (file)
@@ -52,6 +52,12 @@ private:
 /** For construction of flyweights, etc. */
 static library_init library_initializer;
 
+/** Rotate bits of unsigned value by one bit to the left.
+  * This can be necesary if the user wants to define its own hashes. */
+inline unsigned rotate_left(unsigned n)
+{
+       return (n & 0x80000000U) ? (n << 1 | 0x00000001U) : (n << 1);
+}
 
 class scalar_products;
 class const_iterator;
@@ -205,6 +211,7 @@ public:
        int compare(const ex & other) const;
        bool is_equal(const ex & other) const;
        bool is_zero() const { extern const ex _ex0; return is_equal(_ex0); }
+       bool is_zero_matrix() const;
        
        // symmetry
        ex symmetrize() const;
@@ -677,6 +684,10 @@ struct ex_swap : public std::binary_function<ex, ex, void> {
        void operator() (ex &lh, ex &rh) const { lh.swap(rh); }
 };
 
+// Make it possible to print exvectors and exmaps
+std::ostream & operator<<(std::ostream & os, const exvector & e);
+std::ostream & operator<<(std::ostream & os, const exmap & e);
+
 // wrapper functions around member functions
 inline size_t nops(const ex & thisex)
 { return thisex.nops(); }
@@ -855,6 +866,52 @@ public:
        ex operator()(const ex & e) { return ptr(e, arg1, arg2, arg3); }
 };
 
+template<class C>
+class pointer_to_member_to_map_function : public map_function {
+protected:
+       ex (C::*ptr)(const ex &);
+       C &c;
+public:
+       explicit pointer_to_member_to_map_function(ex (C::*member)(const ex &), C &obj) : ptr(member), c(obj) {}
+       ex operator()(const ex & e) { return (c.*ptr)(e); }
+};
+
+template<class C, class T1>
+class pointer_to_member_to_map_function_1arg : public map_function {
+protected:
+       ex (C::*ptr)(const ex &, T1);
+       C &c;
+       T1 arg1;
+public:
+       explicit pointer_to_member_to_map_function_1arg(ex (C::*member)(const ex &, T1), C &obj, T1 a1) : ptr(member), c(obj), arg1(a1) {}
+       ex operator()(const ex & e) { return (c.*ptr)(e, arg1); }
+};
+
+template<class C, class T1, class T2>
+class pointer_to_member_to_map_function_2args : public map_function {
+protected:
+       ex (C::*ptr)(const ex &, T1, T2);
+       C &c;
+       T1 arg1;
+       T2 arg2;
+public:
+       explicit pointer_to_member_to_map_function_2args(ex (C::*member)(const ex&, T1, T2), C &obj, T1 a1, T2 a2) : ptr(member), c(obj), arg1(a1), arg2(a2) {}
+       ex operator()(const ex & e) { return (c.*ptr)(e, arg1, arg2); }
+};
+
+template<class C, class T1, class T2, class T3>
+class pointer_to_member_to_map_function_3args : public map_function {
+protected:
+       ex (C::*ptr)(const ex &, T1, T2, T3);
+       C &c;
+       T1 arg1;
+       T2 arg2;
+       T3 arg3;
+public:
+       explicit pointer_to_member_to_map_function_3args(ex (C::*member)(const ex &, T1, T2, T3), C &obj, T1 a1, T2 a2, T3 a3) : ptr(member), c(obj), arg1(a1), arg2(a2), arg3(a3) {}
+       ex operator()(const ex & e) { return (c.*ptr)(e, arg1, arg2, arg3); }
+};
+
 inline ex ex::map(ex f(const ex &)) const
 {
        pointer_to_map_function fcn(f);