]> www.ginac.de Git - ginac.git/blobdiff - ginac/simp_lor.cpp
* New funny timing added: compute an antipode in Yukawa theory.
[ginac.git] / ginac / simp_lor.cpp
index 3c9cb453e04c04e6e2313311d5cbb7275ffe506e..0734439efa10b5b2c68d2b821a68438fceb20bc9 100644 (file)
@@ -4,7 +4,7 @@
  *  No real implementation yet, to be done.     */
 
 /*
  *  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
  *
  *  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 "simp_lor.h"
 #include "ex.h"
 #include "mul.h"
 #include "simp_lor.h"
 #include "ex.h"
 #include "mul.h"
-#include "symbol.h"
+#include "archive.h"
 #include "debugmsg.h"
 #include "utils.h"
 
 #include "debugmsg.h"
 #include "utils.h"
 
-#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
 namespace GiNaC {
-#endif // ndef NO_NAMESPACE_GINAC
+
+GINAC_IMPLEMENT_REGISTERED_CLASS(simp_lor, indexed)
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -51,28 +51,6 @@ simp_lor::simp_lor() : type(invalid)
        tinfo_key=TINFO_simp_lor;
 }
 
        tinfo_key=TINFO_simp_lor;
 }
 
-simp_lor::~simp_lor()
-{
-       debugmsg("simp_lor destructor",LOGLEVEL_DESTRUCT);
-       destroy(0);
-}
-
-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(1);
-               copy(other);
-       }
-       return *this;
-}
-
 // protected
 
 void simp_lor::copy(const simp_lor & other)
 // protected
 
 void simp_lor::copy(const simp_lor & other)
@@ -101,32 +79,32 @@ simp_lor::simp_lor(simp_lor_types const t) : type(t)
        tinfo_key=TINFO_simp_lor;
 }
 
        tinfo_key=TINFO_simp_lor;
 }
 
-simp_lor::simp_lor(simp_lor_types const t, const ex & i1, const ex & i2) :
-       indexed(i1,i2), type(t)
+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;
        GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
 {
        debugmsg("simp_lor constructor from simp_lor_types,ex,ex",LOGLEVEL_CONSTRUCT);
        tinfo_key=TINFO_simp_lor;
        GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
-simp_lor::simp_lor(simp_lor_types const t, const std::string & n, const ex & i1) :
-       indexed(i1), type(t), name(n)
+simp_lor::simp_lor(simp_lor_types const t, const std::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;
        GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
 {
        debugmsg("simp_lor constructor from simp_lor_types,string,ex",LOGLEVEL_CONSTRUCT);
        tinfo_key=TINFO_simp_lor;
        GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
-simp_lor::simp_lor(simp_lor_types const t, const std::string & n, const exvector & iv) :
-       indexed(iv), type(t), name(n)
+simp_lor::simp_lor(simp_lor_types const t, const std::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;
        GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
 {
        debugmsg("simp_lor constructor from simp_lor_types,string,exvector",LOGLEVEL_CONSTRUCT);
        tinfo_key=TINFO_simp_lor;
        GINAC_ASSERT(all_of_type_lorentzidx());
 }
 
-simp_lor::simp_lor(simp_lor_types const t, const std::string & n, exvector * ivp) :
-       indexed(ivp), type(t), name(n)
+simp_lor::simp_lor(simp_lor_types const t, const std::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;
 {
        debugmsg("simp_lor constructor from simp_lor_types,string,exvector*",LOGLEVEL_CONSTRUCT);
        tinfo_key=TINFO_simp_lor;
@@ -134,17 +112,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);
+}
+
+/** Unarchive the object. */
+ex simp_lor::unarchive(const archive_node &n, const lst &sym_lst)
+{
+       return (new simp_lor(n, sym_lst))->setflag(status_flags::dynallocated);
+}
 
 
-basic * simp_lor::duplicate() const
+/** Archive the object. */
+void simp_lor::archive(archive_node &n) const
 {
 {
-       debugmsg("simp_lor duplicate",LOGLEVEL_DUPLICATE);
-       return new simp_lor(*this);
+       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);
 void simp_lor::printraw(std::ostream & os) const
 {
        debugmsg("simp_lor printraw",LOGLEVEL_PRINT);
@@ -229,9 +231,11 @@ ex simp_lor::eval(int level) const
                                // at least one off-diagonal
                                return _ex0();
                        }
                                // 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 +313,6 @@ bool simp_lor::all_of_type_lorentzidx(void) const
 
 // none
 
 
 // none
 
-//////////
-// global constants
-//////////
-
-const simp_lor some_simp_lor;
-const type_info & typeid_simp_lor = typeid(some_simp_lor);
-
 //////////
 // friend functions
 //////////
 //////////
 // friend functions
 //////////
@@ -367,8 +364,7 @@ ex simplify_simp_lor_mul(const ex & m, const scalar_products & sp)
                        // try to contract first index
                        replacements=0;
                        if (first_idx.is_symbolic()) {
                        // try to contract first index
                        replacements=0;
                        if (first_idx.is_symbolic()) {
-                               replacements = subs_index_in_exvector(v_contracted,
-                                                                  first_idx.toggle_covariant(),second_idx);
+                               replacements = subs_index_in_exvector(v_contracted, first_idx.toggle_covariant(),second_idx);
                                if (replacements==0) {
                                        // not contracted, restore g object
                                        *it=saved_g;
                                if (replacements==0) {
                                        // not contracted, restore g object
                                        *it=saved_g;
@@ -383,8 +379,7 @@ ex simplify_simp_lor_mul(const ex & m, const scalar_products & sp)
                        // try second index only if first was not contracted
                        if ((replacements==0)&&(second_idx.is_symbolic())) {
                                // first index not contracted, *it is again the original g object
                        // try second index only if first was not contracted
                        if ((replacements==0)&&(second_idx.is_symbolic())) {
                                // first index not contracted, *it is again the original g object
-                               replacements = subs_index_in_exvector(v_contracted,
-                                                                  second_idx.toggle_covariant(),first_idx);
+                               replacements = subs_index_in_exvector(v_contracted, second_idx.toggle_covariant(),first_idx);
                                if (replacements==0) {
                                        // not contracted except in itself, restore g object
                                        *it=saved_g;
                                if (replacements==0) {
                                        // not contracted except in itself, restore g object
                                        *it=saved_g;
@@ -439,14 +434,14 @@ ex simplify_simp_lor_mul(const ex & m, const scalar_products & sp)
 ex simplify_simp_lor(const ex & e, const scalar_products & sp)
 {
        // all simplification is done on expanded objects
 ex simplify_simp_lor(const ex & e, const scalar_products & sp)
 {
        // all simplification is done on expanded objects
-       ex e_expanded=e.expand();
+       ex e_expanded = e.expand();
 
        // simplification of sum=sum of simplifications
        if (is_ex_exactly_of_type(e_expanded,add)) {
                ex sum=_ex0();
                for (unsigned i=0; i<e_expanded.nops(); ++i)
                        sum += simplify_simp_lor(e_expanded.op(i),sp);
 
        // simplification of sum=sum of simplifications
        if (is_ex_exactly_of_type(e_expanded,add)) {
                ex sum=_ex0();
                for (unsigned i=0; i<e_expanded.nops(); ++i)
                        sum += simplify_simp_lor(e_expanded.op(i),sp);
-               
+
                return sum;
        }
 
                return sum;
        }
 
@@ -459,18 +454,12 @@ ex simplify_simp_lor(const ex & e, const scalar_products & sp)
        return e_expanded;
 }
 
        return e_expanded;
 }
 
-//ex Dim(void)   // FIXME: what's going on here?
-//{
-//    static symbol * d=new symbol("dim");
-//    return *d;
-//}
-
 //////////
 // helper classes
 //////////
 
 void scalar_products::reg(const simp_lor & v1, const simp_lor & v2,
 //////////
 // helper classes
 //////////
 
 void scalar_products::reg(const simp_lor & v1, const simp_lor & v2,
-                                                 const ex & sp)
+                          const ex & sp)
 {
        if (v1.compare_same_type(v2)>0) {
                reg(v2,v1,sp);
 {
        if (v1.compare_same_type(v2)>0) {
                reg(v2,v1,sp);
@@ -489,10 +478,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
 {
 
 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
 }
 
 void scalar_products::debugprint(void) const
@@ -501,9 +490,9 @@ void scalar_products::debugprint(void) const
        for (spmap::const_iterator cit=spm.begin(); cit!=spm.end(); ++cit) {
                const spmapkey & k=(*cit).first;
                std::cerr << "item key=((" << k.first.first
        for (spmap::const_iterator cit=spm.begin(); cit!=spm.end(); ++cit) {
                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.first.second << "),";
+               k.second.printraw(std::cerr);
+               std::cerr << ") value=" << (*cit).second << std::endl;
        }
 }
 
        }
 }
 
@@ -516,6 +505,4 @@ spmapkey scalar_products::make_key(const simp_lor & v1, const simp_lor & v2)
        return spmapkey(strstrpair(v1.name,v2.name),anon);
 }
 
        return spmapkey(strstrpair(v1.name,v2.name),anon);
 }
 
-#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
 } // namespace GiNaC
-#endif // ndef NO_NAMESPACE_GINAC