]> www.ginac.de Git - ginac.git/blobdiff - ginac/simp_lor.cpp
- The status_flags::expanded is now used on some occasions.
[ginac.git] / ginac / simp_lor.cpp
index 5e289aa60b47c10152fc5e44d11f686209aa3859..c5d5f9eb92f5b331aa815a143e7b03db1a6c7820 100644 (file)
@@ -1,9 +1,10 @@
 /** @file simp_lor.cpp
  *
  *  Implementation of GiNaC's simp_lor objects.
- *  No real implementation yet, to be done.    
- *
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  No real implementation yet, to be done.     */
+
+/*
+ *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 #include "ex.h"
 #include "mul.h"
 #include "symbol.h"
+#include "debugmsg.h"
+#include "utils.h"
+
+#ifndef NO_NAMESPACE_GINAC
+namespace GiNaC {
+#endif // ndef NO_NAMESPACE_GINAC
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -50,13 +57,13 @@ simp_lor::~simp_lor()
     destroy(0);
 }
 
-simp_lor::simp_lor(simp_lor const & other)
+simp_lor::simp_lor(const simp_lor & other)
 {
     debugmsg("simp_lor copy constructor",LOGLEVEL_CONSTRUCT);
     copy (other);
 }
 
-simp_lor const & simp_lor::operator=(simp_lor const & other)
+const simp_lor & simp_lor::operator=(const simp_lor & other)
 {
     debugmsg("simp_lor operator=",LOGLEVEL_ASSIGNMENT);
     if (this != &other) {
@@ -68,7 +75,7 @@ simp_lor const & simp_lor::operator=(simp_lor const & other)
 
 // protected
 
-void simp_lor::copy(simp_lor const & other)
+void simp_lor::copy(const simp_lor & other)
 {
     indexed::copy(other);
     type=other.type;
@@ -94,36 +101,36 @@ simp_lor::simp_lor(simp_lor_types const t) : type(t)
     tinfo_key=TINFO_simp_lor;
 }
 
-simp_lor::simp_lor(simp_lor_types const t, ex const & i1, ex const & i2) :
+simp_lor::simp_lor(simp_lor_types const t, const ex & i1, const ex & i2) :
     indexed(i1,i2), type(t)
 {
     debugmsg("simp_lor constructor from simp_lor_types,ex,ex",LOGLEVEL_CONSTRUCT);
     tinfo_key=TINFO_simp_lor;
-    ASSERT(all_of_type_lorentzidx());
+    GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
-simp_lor::simp_lor(simp_lor_types const t, string const & n, ex const & i1) :
+simp_lor::simp_lor(simp_lor_types const t, const string & n, const ex & i1) :
     indexed(i1), type(t), name(n)
 {
     debugmsg("simp_lor constructor from simp_lor_types,string,ex",LOGLEVEL_CONSTRUCT);
     tinfo_key=TINFO_simp_lor;
-    ASSERT(all_of_type_lorentzidx());
+    GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
-simp_lor::simp_lor(simp_lor_types const t, string const & n, exvector const & iv) :
+simp_lor::simp_lor(simp_lor_types const t, const string & n, const exvector & iv) :
     indexed(iv), type(t), name(n)
 {
     debugmsg("simp_lor constructor from simp_lor_types,string,exvector",LOGLEVEL_CONSTRUCT);
     tinfo_key=TINFO_simp_lor;
-    ASSERT(all_of_type_lorentzidx());
+    GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
-simp_lor::simp_lor(simp_lor_types const t, string const & n, exvector * ivp) :
+simp_lor::simp_lor(simp_lor_types const t, const string & n, exvector * ivp) :
     indexed(ivp), type(t), name(n)
 {
     debugmsg("simp_lor constructor from simp_lor_types,string,exvector*",LOGLEVEL_CONSTRUCT);
     tinfo_key=TINFO_simp_lor;
-    ASSERT(all_of_type_lorentzidx());
+    GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
 //////////
@@ -197,30 +204,30 @@ ex simp_lor::eval(int level) const
         int sig=canonicalize_indices(iv,false); // symmetric
         if (sig!=INT_MAX) {
             // something has changed while sorting indices, more evaluations later
-            if (sig==0) return exZERO();
+            if (sig==0) return _ex0();
             return ex(sig)*simp_lor(type,name,iv);
         }
-        lorentzidx const & idx1=ex_to_lorentzidx(seq[0]);
-        lorentzidx const & idx2=ex_to_lorentzidx(seq[1]);
+        const lorentzidx & idx1=ex_to_lorentzidx(seq[0]);
+        const lorentzidx & idx2=ex_to_lorentzidx(seq[1]);
         if ((!idx1.is_symbolic())&&(!idx2.is_symbolic())) {
             // both indices are numeric
             if ((idx1.get_value()==idx2.get_value())) {
                 // both on diagonal
                 if (idx1.get_value()==0) {
                     // (0,0)
-                    return exONE();
+                    return _ex1();
                 } else {
                     if (idx1.is_covariant()!=idx2.is_covariant()) {
                         // (_i,~i) or (~i,_i), i=1..3
-                        return exONE();
+                        return _ex1();
                     } else {
                         // (_i,_i) or (~i,~i), i=1..3
-                        return exMINUSONE();
+                        return _ex_1();
                     }
                 }
             } else {
                 // at least one off-diagonal
-                return exZERO();
+                return _ex0();
             }
         } else if (idx1.is_symbolic() &&
                    idx1.is_co_contra_pair(idx2)) {
@@ -233,9 +240,9 @@ ex simp_lor::eval(int level) const
     
 // protected
 
-int simp_lor::compare_same_type(basic const & other) const
+int simp_lor::compare_same_type(const basic & other) const
 {
-    ASSERT(other.tinfo() == TINFO_simp_lor);
+    GINAC_ASSERT(other.tinfo() == TINFO_simp_lor);
     const simp_lor *o = static_cast<const simp_lor *>(&other);
     if (type==o->type) {
         if (name==o->name) {
@@ -246,9 +253,9 @@ int simp_lor::compare_same_type(basic const & other) const
     return type < o->type ? -1 : 1;
 }
 
-bool simp_lor::is_equal_same_type(basic const & other) const
+bool simp_lor::is_equal_same_type(const basic & other) const
 {
-    ASSERT(other.tinfo() == TINFO_simp_lor);
+    GINAC_ASSERT(other.tinfo() == TINFO_simp_lor);
     const simp_lor *o = static_cast<const simp_lor *>(&other);
     if (type!=o->type) return false;
     if (name!=o->name) return false;
@@ -265,7 +272,7 @@ unsigned simp_lor::return_type_tinfo(void) const
     return tinfo_key;
 }
 
-ex simp_lor::thisexprseq(exvector const & v) const
+ex simp_lor::thisexprseq(const exvector & v) const
 {
     return simp_lor(type,name,v);
 }
@@ -307,38 +314,38 @@ bool simp_lor::all_of_type_lorentzidx(void) const
 //////////
 
 const simp_lor some_simp_lor;
-type_info const & typeid_simp_lor=typeid(some_simp_lor);
+const type_info & typeid_simp_lor=typeid(some_simp_lor);
 
 //////////
 // friend functions
 //////////
 
-simp_lor lor_g(ex const & mu, ex const & nu)
+simp_lor lor_g(const ex & mu, const ex & nu)
 {
     return simp_lor(simp_lor::simp_lor_g,mu,nu);
 }
 
-simp_lor lor_vec(string const & n, ex const & mu)
+simp_lor lor_vec(const string & n, const ex & mu)
 {
     return simp_lor(simp_lor::simp_lor_vec,n,mu);
 }
 
-ex simplify_simp_lor_mul(ex const & m, scalar_products const & sp)
+ex simplify_simp_lor_mul(const ex & m, const scalar_products & sp)
 {
-    ASSERT(is_ex_exactly_of_type(m,mul));
+    GINAC_ASSERT(is_ex_exactly_of_type(m,mul));
     exvector v_contracted;
 
     // collect factors in an exvector, store squares twice
-    int n=m.nops();
+    unsigned n=m.nops();
     v_contracted.reserve(2*n);
-    for (int i=0; i<n; ++i) {
+    for (unsigned i=0; i<n; ++i) {
         ex f=m.op(i);
-        if (is_ex_exactly_of_type(f,power)&&f.op(1).is_equal(exTWO())) {
+        if (is_ex_exactly_of_type(f,power)&&f.op(1).is_equal(_ex2())) {
             v_contracted.push_back(f.op(0));
             v_contracted.push_back(f.op(0));
         } else {
             v_contracted.push_back(f);
-       }
+        }
     }
 
     unsigned replacements;
@@ -349,12 +356,12 @@ ex simplify_simp_lor_mul(ex const & m, scalar_products const & sp)
         // process only lor_g objects
         if (is_ex_exactly_of_type(*it,simp_lor) &&
             (ex_to_simp_lor(*it).type==simp_lor::simp_lor_g)) {
-            simp_lor const & g=ex_to_simp_lor(*it);
-            ASSERT(g.seq.size()==2);
-            idx const & first_idx=ex_to_lorentzidx(g.seq[0]);
-            idx const & second_idx=ex_to_lorentzidx(g.seq[1]);
+            const simp_lor & g=ex_to_simp_lor(*it);
+            GINAC_ASSERT(g.seq.size()==2);
+            const idx & first_idx=ex_to_lorentzidx(g.seq[0]);
+            const idx & second_idx=ex_to_lorentzidx(g.seq[1]);
             // g_{mu,mu} should have been contracted in simp_lor::eval()
-            ASSERT(!first_idx.is_equal(second_idx));
+            GINAC_ASSERT(!first_idx.is_equal(second_idx));
             ex saved_g=*it; // save to restore it later
 
             // try to contract first index
@@ -367,8 +374,8 @@ ex simplify_simp_lor_mul(ex const & m, scalar_products const & sp)
                     *it=saved_g;
                 } else {
                     // a contracted index should occur exactly once
-                    ASSERT(replacements==1);
-                    *it=exONE();
+                    GINAC_ASSERT(replacements==1);
+                    *it=_ex1();
                     something_changed=true;
                 }
             }
@@ -383,8 +390,8 @@ ex simplify_simp_lor_mul(ex const & m, scalar_products const & sp)
                     *it=saved_g;
                 } else {
                     // a contracted index should occur exactly once
-                    ASSERT(replacements==1);
-                    *it=exONE();
+                    GINAC_ASSERT(replacements==1);
+                    *it=_ex1();
                     something_changed=true;
                 }
             }
@@ -402,17 +409,17 @@ ex simplify_simp_lor_mul(ex const & m, scalar_products const & sp)
             while ((it2!=v_contracted.end())&&!jump_to_next) {
                 if (is_ex_exactly_of_type(*it2,simp_lor) && 
                     (ex_to_simp_lor(*it2).type==simp_lor::simp_lor_vec)) {
-                    simp_lor const & vec1=ex_to_simp_lor(*it1);
-                    simp_lor const & vec2=ex_to_simp_lor(*it2);
-                    ASSERT(vec1.seq.size()==1);
-                    ASSERT(vec2.seq.size()==1);
-                    lorentzidx const & idx1=ex_to_lorentzidx(vec1.seq[0]);
-                    lorentzidx const & idx2=ex_to_lorentzidx(vec2.seq[0]);
+                    const simp_lor & vec1=ex_to_simp_lor(*it1);
+                    const simp_lor & vec2=ex_to_simp_lor(*it2);
+                    GINAC_ASSERT(vec1.seq.size()==1);
+                    GINAC_ASSERT(vec2.seq.size()==1);
+                    const lorentzidx & idx1=ex_to_lorentzidx(vec1.seq[0]);
+                    const lorentzidx & idx2=ex_to_lorentzidx(vec2.seq[0]);
                     if (idx1.is_symbolic() &&
                         idx1.is_co_contra_pair(idx2) &&
                         sp.is_defined(vec1,vec2)) {
                         *it1=sp.evaluate(vec1,vec2);
-                        *it2=exONE();
+                        *it2=_ex1();
                         something_changed=true;
                         jump_to_next=true;
                     }
@@ -429,17 +436,17 @@ ex simplify_simp_lor_mul(ex const & m, scalar_products const & sp)
     return m;
 }
 
-ex simplify_simp_lor(ex const & e, scalar_products const & sp)
+ex simplify_simp_lor(const ex & e, const scalar_products & sp)
 {
     // all simplification is done on expanded objects
     ex e_expanded=e.expand();
 
     // simplification of sum=sum of simplifications
     if (is_ex_exactly_of_type(e_expanded,add)) {
-        ex sum=exZERO();
-        for (int i=0; i<e_expanded.nops(); ++i) {
+        ex sum=_ex0();
+        for (unsigned i=0; i<e_expanded.nops(); ++i)
             sum += simplify_simp_lor(e_expanded.op(i),sp);
-        }
+        
         return sum;
     }
 
@@ -452,18 +459,18 @@ ex simplify_simp_lor(ex const & e, scalar_products const & sp)
     return e_expanded;
 }
 
-ex Dim(void)
-{
-    static symbol * d=new symbol("dim");
-    return *d;
-}
+//ex Dim(void)   // FIXME: what's going on here?
+//{
+//    static symbol * d=new symbol("dim");
+//    return *d;
+//}
 
 //////////
 // helper classes
 //////////
 
-void scalar_products::reg(simp_lor const & v1, simp_lor const & v2,
-                          ex const & sp)
+void scalar_products::reg(const simp_lor & v1, const simp_lor & v2,
+                          const ex & sp)
 {
     if (v1.compare_same_type(v2)>0) {
         reg(v2,v1,sp);
@@ -472,7 +479,7 @@ void scalar_products::reg(simp_lor const & v1, simp_lor const & v2,
     spm[make_key(v1,v2)]=sp;
 }
 
-bool scalar_products::is_defined(simp_lor const & v1, simp_lor const & v2) const
+bool scalar_products::is_defined(const simp_lor & v1, const simp_lor & v2) const
 {
     if (v1.compare_same_type(v2)>0) {
         return is_defined(v2,v1);
@@ -480,7 +487,7 @@ bool scalar_products::is_defined(simp_lor const & v1, simp_lor const & v2) const
     return spm.find(make_key(v1,v2))!=spm.end();
 }
 
-ex scalar_products::evaluate(simp_lor const & v1, simp_lor const & v2) const
+ex scalar_products::evaluate(const simp_lor & v1, const simp_lor & v2) const
 {
     if (v1.compare_same_type(v2)>0) {
         return evaluate(v2,v1);
@@ -492,7 +499,7 @@ void scalar_products::debugprint(void) const
 {
     cerr << "map size=" << spm.size() << endl;
     for (spmap::const_iterator cit=spm.begin(); cit!=spm.end(); ++cit) {
-        spmapkey const & k=(*cit).first;
+        const spmapkey & k=(*cit).first;
         cerr << "item key=((" << k.first.first
              << "," << k.first.second << "),";
         k.second.printraw(cerr);
@@ -500,14 +507,15 @@ void scalar_products::debugprint(void) const
     }
 }
 
-spmapkey scalar_products::make_key(simp_lor const & v1, simp_lor const & v2)
+spmapkey scalar_products::make_key(const simp_lor & v1, const simp_lor & v2)
 {
-    ASSERT(v1.type==simp_lor::simp_lor_vec);
-    ASSERT(v2.type==simp_lor::simp_lor_vec);
+    GINAC_ASSERT(v1.type==simp_lor::simp_lor_vec);
+    GINAC_ASSERT(v2.type==simp_lor::simp_lor_vec);
     lorentzidx anon=ex_to_lorentzidx(v1.seq[0]).create_anonymous_representative();
-    ASSERT(anon.is_equal_same_type(ex_to_lorentzidx(v2.seq[0]).create_anonymous_representative()));
+    GINAC_ASSERT(anon.is_equal_same_type(ex_to_lorentzidx(v2.seq[0]).create_anonymous_representative()));
     return spmapkey(strstrpair(v1.name,v2.name),anon);
 }
 
-
-
+#ifndef NO_NAMESPACE_GINAC
+} // namespace GiNaC
+#endif // ndef NO_NAMESPACE_GINAC