]> www.ginac.de Git - ginac.git/blobdiff - ginac/simp_lor.cpp
- g~mu_mu contraction returns Dim for general Lorentz indices and Dim-dimP
[ginac.git] / ginac / simp_lor.cpp
index 06eef8ee6b03b5058784291c62565ac66abfc78f..ed79d7535746b3bc65ac3e2d0ae42cced4931f3c 100644 (file)
@@ -4,7 +4,7 @@
  *  No real implementation yet, to be done.     */
 
 /*
- *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2001 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
@@ -31,7 +31,7 @@
 #include "simp_lor.h"
 #include "ex.h"
 #include "mul.h"
-#include "symbol.h"
+#include "archive.h"
 #include "debugmsg.h"
 #include "utils.h"
 
@@ -39,6 +39,8 @@
 namespace GiNaC {
 #endif // ndef NO_NAMESPACE_GINAC
 
+GINAC_IMPLEMENT_REGISTERED_CLASS(simp_lor, indexed)
+
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
 //////////
@@ -51,28 +53,6 @@ simp_lor::simp_lor() : type(invalid)
        tinfo_key=TINFO_simp_lor;
 }
 
-simp_lor::~simp_lor()
-{
-       debugmsg("simp_lor destructor",LOGLEVEL_DESTRUCT);
-       destroy(false);
-}
-
-simp_lor::simp_lor(const simp_lor & other)
-{
-       debugmsg("simp_lor copy constructor",LOGLEVEL_CONSTRUCT);
-       copy (other);
-}
-
-const simp_lor & simp_lor::operator=(const simp_lor & other)
-{
-       debugmsg("simp_lor operator=",LOGLEVEL_ASSIGNMENT);
-       if (this != &other) {
-               destroy(true);
-               copy(other);
-       }
-       return *this;
-}
-
 // protected
 
 void simp_lor::copy(const simp_lor & other)
@@ -134,17 +114,41 @@ simp_lor::simp_lor(simp_lor_types const t, const std::string & n, exvector * ivp
 }
 
 //////////
-// functions overriding virtual functions from bases classes
+// archiving
 //////////
 
-// public
+/** Construct object from archive_node. */
+simp_lor::simp_lor(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
+{
+       debugmsg("simp_lor constructor from archive_node", LOGLEVEL_CONSTRUCT);
+       unsigned int ty;
+       if (!(n.find_unsigned("type", ty)))
+               throw (std::runtime_error("unknown simp_lor type in archive"));
+       type = (simp_lor_types)ty;
+       n.find_string("name", name);
+}
 
-basic * simp_lor::duplicate() const
+/** Unarchive the object. */
+ex simp_lor::unarchive(const archive_node &n, const lst &sym_lst)
 {
-       debugmsg("simp_lor duplicate",LOGLEVEL_DUPLICATE);
-       return new simp_lor(*this);
+       return (new simp_lor(n, sym_lst))->setflag(status_flags::dynallocated);
 }
 
+/** Archive the object. */
+void simp_lor::archive(archive_node &n) const
+{
+       inherited::archive(n);
+       n.add_unsigned("type", type);
+       n.add_string("name", name);
+}
+
+
+//////////
+// functions overriding virtual functions from bases classes
+//////////
+
+// public
+
 void simp_lor::printraw(std::ostream & os) const
 {
        debugmsg("simp_lor printraw",LOGLEVEL_PRINT);
@@ -229,9 +233,11 @@ ex simp_lor::eval(int level) const
                                // at least one off-diagonal
                                return _ex0();
                        }
-               } else if (idx1.is_symbolic() &&
-                          idx1.is_co_contra_pair(idx2)) {
-                       return Dim()-idx1.get_dim_parallel_space();
+               } else if (idx1.is_symbolic() && idx1.is_co_contra_pair(idx2)) {
+                       if (idx1.is_orthogonal_only())
+                               return Dim() - idx1.get_dim_parallel_space();
+                       else
+                               return Dim();
                }
        }
 
@@ -309,13 +315,6 @@ bool simp_lor::all_of_type_lorentzidx(void) const
 
 // none
 
-//////////
-// global constants
-//////////
-
-const simp_lor some_simp_lor;
-const type_info & typeid_simp_lor = typeid(some_simp_lor);
-
 //////////
 // friend functions
 //////////
@@ -457,12 +456,6 @@ ex simplify_simp_lor(const ex & e, const scalar_products & sp)
        return e_expanded;
 }
 
-//ex Dim(void)   // FIXME: what's going on here?
-//{
-//    static symbol * d=new symbol("dim");
-//    return *d;
-//}
-
 //////////
 // helper classes
 //////////
@@ -487,10 +480,10 @@ bool scalar_products::is_defined(const simp_lor & v1, const simp_lor & 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);
-       }
-       return spm.find(make_key(v1,v2))->second;
+       if (v1.compare_same_type(v2)>0)
+               return evaluate(v2, v1);
+       
+       return (*spm.find(make_key(v1,v2))).second;
 }
 
 void scalar_products::debugprint(void) const
@@ -500,8 +493,8 @@ void scalar_products::debugprint(void) const
                const spmapkey & k=(*cit).first;
                std::cerr << "item key=((" << k.first.first
                          << "," << k.first.second << "),";
-               k.second.printraw(cerr);
-               cerr << ") value=" << (*cit).second << std::endl;
+               k.second.printraw(std::cerr);
+               std::cerr << ") value=" << (*cit).second << std::endl;
        }
 }