]> www.ginac.de Git - ginac.git/blobdiff - ginac/simp_lor.cpp
- Banned exZERO(), exONE(), exMINUSHALF() and all this from the interface.
[ginac.git] / ginac / simp_lor.cpp
index ac8aae06d25cb13abc0028416e0ea8420fc5c510..ae0701989a56db36d6b25faba66dd293aca2bd98 100644 (file)
@@ -1,8 +1,9 @@
 /** @file simp_lor.cpp
  *
  *  Implementation of GiNaC's simp_lor objects.
- *  No real implementation yet, to be done.    
- *
+ *  No real implementation yet, to be done.     */
+
+/*
  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
 #include <stdexcept>
 #include <map>
 
-#include "ginac.h"
+#include "simp_lor.h"
+#include "ex.h"
+#include "mul.h"
+#include "symbol.h"
+#include "debugmsg.h"
+#include "utils.h"
+
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -38,7 +48,7 @@
 simp_lor::simp_lor() : type(invalid)
 {
     debugmsg("simp_lor default constructor",LOGLEVEL_CONSTRUCT);
-    tinfo_key=TINFO_SIMP_LOR;
+    tinfo_key=TINFO_simp_lor;
 }
 
 simp_lor::~simp_lor()
@@ -88,39 +98,39 @@ void simp_lor::destroy(bool call_parent)
 simp_lor::simp_lor(simp_lor_types const t) : type(t)
 {
     debugmsg("simp_lor constructor from simp_lor_types",LOGLEVEL_CONSTRUCT);
-    tinfo_key=TINFO_SIMP_LOR;
+    tinfo_key=TINFO_simp_lor;
 }
 
 simp_lor::simp_lor(simp_lor_types const t, ex const & i1, ex const & 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());
+    tinfo_key=TINFO_simp_lor;
+    GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
 simp_lor::simp_lor(simp_lor_types const t, string const & n, ex const & 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());
+    tinfo_key=TINFO_simp_lor;
+    GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
 simp_lor::simp_lor(simp_lor_types const t, string const & n, exvector const & 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());
+    tinfo_key=TINFO_simp_lor;
+    GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
 simp_lor::simp_lor(simp_lor_types const t, string const & 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());
+    tinfo_key=TINFO_simp_lor;
+    GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
 //////////
@@ -194,7 +204,7 @@ 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]);
@@ -205,19 +215,19 @@ ex simp_lor::eval(int level) const
                 // 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)) {
@@ -232,7 +242,7 @@ ex simp_lor::eval(int level) const
 
 int simp_lor::compare_same_type(basic const & 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) {
@@ -245,7 +255,7 @@ int simp_lor::compare_same_type(basic const & other) const
 
 bool simp_lor::is_equal_same_type(basic const & 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;
@@ -322,7 +332,7 @@ simp_lor lor_vec(string const & n, ex const & mu)
 
 ex simplify_simp_lor_mul(ex const & m, scalar_products const & 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
@@ -330,7 +340,7 @@ ex simplify_simp_lor_mul(ex const & m, scalar_products const & sp)
     v_contracted.reserve(2*n);
     for (int i=0; i<n; ++i) {
         ex f=m.op(i);
-        if (is_ex_exactly_of_type(f,power)&&f.op(1)==2) {
+        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 {
@@ -347,11 +357,11 @@ ex simplify_simp_lor_mul(ex const & m, scalar_products const & sp)
         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);
+            GINAC_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]);
             // 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
@@ -364,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;
                 }
             }
@@ -380,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;
                 }
             }
@@ -401,15 +411,15 @@ ex simplify_simp_lor_mul(ex const & m, scalar_products const & sp)
                     (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);
+                    GINAC_ASSERT(vec1.seq.size()==1);
+                    GINAC_ASSERT(vec2.seq.size()==1);
                     lorentzidx const & idx1=ex_to_lorentzidx(vec1.seq[0]);
                     lorentzidx const & 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;
                     }
@@ -433,7 +443,7 @@ ex simplify_simp_lor(ex const & e, scalar_products const & sp)
 
     // simplification of sum=sum of simplifications
     if (is_ex_exactly_of_type(e_expanded,add)) {
-        ex sum=exZERO();
+        ex sum=_ex0();
         for (int i=0; i<e_expanded.nops(); ++i) {
             sum += simplify_simp_lor(e_expanded.op(i),sp);
         }
@@ -449,11 +459,11 @@ 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
@@ -499,12 +509,13 @@ void scalar_products::debugprint(void) const
 
 spmapkey scalar_products::make_key(simp_lor const & v1, simp_lor const & 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_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE