]> www.ginac.de Git - ginac.git/blobdiff - ginac/lorentzidx.cpp
* New funny timing added: compute an antipode in Yukawa theory.
[ginac.git] / ginac / lorentzidx.cpp
index 734c2fea577df0b429ae8017cffcfe567e073291..783316c48b9f173547abcdd16cc1d70ac5baf948 100644 (file)
@@ -1,6 +1,6 @@
 /** @file lorentzidx.cpp
  *
 /** @file lorentzidx.cpp
  *
- *  Implementation of GiNaC's lorentz indices. */
+ *  Implementation of GiNaC's Lorentz indices. */
 
 /*
  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
 
 /*
  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
 
 #include "lorentzidx.h"
 #include "lst.h"
 
 #include "lorentzidx.h"
 #include "lst.h"
+#include "symbol.h"
 #include "archive.h"
 #include "utils.h"
 #include "debugmsg.h"
 
 #include "archive.h"
 #include "utils.h"
 #include "debugmsg.h"
 
-#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
 namespace GiNaC {
-#endif // ndef NO_NAMESPACE_GINAC
 
 GINAC_IMPLEMENT_REGISTERED_CLASS(lorentzidx, idx)
 
 
 GINAC_IMPLEMENT_REGISTERED_CLASS(lorentzidx, idx)
 
@@ -48,28 +47,6 @@ lorentzidx::lorentzidx() : orthogonal_only(false), dim_parallel_space(0)
        tinfo_key = TINFO_lorentzidx;
 }
 
        tinfo_key = TINFO_lorentzidx;
 }
 
-lorentzidx::~lorentzidx() 
-{
-       debugmsg("lorentzidx destructor",LOGLEVEL_DESTRUCT);
-       destroy(false);
-}
-
-lorentzidx::lorentzidx(const lorentzidx & other)
-{
-       debugmsg("lorentzidx copy constructor",LOGLEVEL_CONSTRUCT);
-       copy(other);
-}
-
-const lorentzidx & lorentzidx::operator=(const lorentzidx & other)
-{
-       debugmsg("lorentzidx operator=",LOGLEVEL_ASSIGNMENT);
-       if (this != &other) {
-               destroy(true);
-               copy(other);
-       }
-       return *this;
-}
-
 // protected
 
 void lorentzidx::copy(const lorentzidx & other)
 // protected
 
 void lorentzidx::copy(const lorentzidx & other)
@@ -90,10 +67,16 @@ void lorentzidx::destroy(bool call_parent)
 
 // public
 
 
 // public
 
+/** Construct symbolic Lorentz index, using an automatically generated unique name.
+ *
+ *  @param cov Index is covariant (contravariant otherwise)
+ *  @param oonly Index only lives in orthogonal space
+ *  @param dimp Dimension of parallel space
+ *  @return newly constructed index */
 lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp)
   : idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp)
 {
 lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp)
   : idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp)
 {
-       debugmsg("lorentzidx constructor from bool",LOGLEVEL_CONSTRUCT);
+       debugmsg("lorentzidx constructor from bool,bool,unsigned",LOGLEVEL_CONSTRUCT);
        // serial is incremented in idx::idx(bool)
        if (oonly) {
                name="muorth"+ToString(serial);
        // serial is incremented in idx::idx(bool)
        if (oonly) {
                name="muorth"+ToString(serial);
@@ -103,6 +86,13 @@ lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp)
        tinfo_key=TINFO_lorentzidx;
 }
 
        tinfo_key=TINFO_lorentzidx;
 }
 
+/** Construct symbolic Lorentz index with specified name.
+ *
+ *  @param n Symbolic index name
+ *  @param cov Index is covariant (contravariant otherwise)
+ *  @param oonly Index only lives in orthogonal space
+ *  @param dimp Dimension of parallel space
+ *  @return newly constructed index */
 lorentzidx::lorentzidx(const std::string & n, bool cov, bool oonly, unsigned dimp)
   : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
 {
 lorentzidx::lorentzidx(const std::string & n, bool cov, bool oonly, unsigned dimp)
   : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
 {
@@ -111,6 +101,13 @@ lorentzidx::lorentzidx(const std::string & n, bool cov, bool oonly, unsigned dim
        tinfo_key=TINFO_lorentzidx;
 }
 
        tinfo_key=TINFO_lorentzidx;
 }
 
+/** Construct symbolic Lorentz index with specified name.
+ *
+ *  @param n Symbolic index name
+ *  @param cov Index is covariant (contravariant otherwise)
+ *  @param oonly Index only lives in orthogonal space
+ *  @param dimp Dimension of parallel space
+ *  @return newly constructed index */
 lorentzidx::lorentzidx(const char * n, bool cov, bool oonly, unsigned dimp)
   : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
 {
 lorentzidx::lorentzidx(const char * n, bool cov, bool oonly, unsigned dimp)
   : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
 {
@@ -119,6 +116,11 @@ lorentzidx::lorentzidx(const char * n, bool cov, bool oonly, unsigned dimp)
        tinfo_key=TINFO_lorentzidx;
 }
 
        tinfo_key=TINFO_lorentzidx;
 }
 
+/** Construct numeric Lorentz index with specified value.
+ *
+ *  @param v Numeric index value
+ *  @param cov Index is covariant (contravariant otherwise)
+ *  @return newly constructed index */
 lorentzidx::lorentzidx(unsigned v, bool cov)
   : idx(v,cov), orthogonal_only(false), dim_parallel_space(0)
 {
 lorentzidx::lorentzidx(unsigned v, bool cov)
   : idx(v,cov), orthogonal_only(false), dim_parallel_space(0)
 {
@@ -135,8 +137,7 @@ lorentzidx::lorentzidx(const archive_node &n, const lst &sym_lst) : inherited(n,
 {
        debugmsg("lorentzidx constructor from archive_node", LOGLEVEL_CONSTRUCT);
        n.find_bool("orthogonal_only", orthogonal_only);
 {
        debugmsg("lorentzidx constructor from archive_node", LOGLEVEL_CONSTRUCT);
        n.find_bool("orthogonal_only", orthogonal_only);
-       if (orthogonal_only)
-               n.find_unsigned("pdim", dim_parallel_space);
+       n.find_unsigned("pdim", dim_parallel_space);
 }
 
 /** Unarchive the object. */
 }
 
 /** Unarchive the object. */
@@ -159,8 +160,7 @@ void lorentzidx::archive(archive_node &n) const
 {
        inherited::archive(n);
        n.add_bool("orthogonal_only", orthogonal_only);
 {
        inherited::archive(n);
        n.add_bool("orthogonal_only", orthogonal_only);
-       if (orthogonal_only)
-               n.add_unsigned("pdim", dim_parallel_space);
+       n.add_unsigned("pdim", dim_parallel_space);
 }
 
 //////////
 }
 
 //////////
@@ -169,12 +169,6 @@ void lorentzidx::archive(archive_node &n) const
 
 // public
 
 
 // public
 
-basic * lorentzidx::duplicate() const
-{
-       debugmsg("lorentzidx duplicate",LOGLEVEL_DUPLICATE);
-       return new lorentzidx(*this);
-}
-
 void lorentzidx::printraw(std::ostream & os) const
 {
        debugmsg("lorentzidx printraw",LOGLEVEL_PRINT);
 void lorentzidx::printraw(std::ostream & os) const
 {
        debugmsg("lorentzidx printraw",LOGLEVEL_PRINT);
@@ -258,11 +252,17 @@ bool lorentzidx::info(unsigned inf) const
        return inherited::info(inf);
 }
 
        return inherited::info(inf);
 }
 
-//////////
-// new virtual functions which can be overridden by derived classes
-//////////
-
-// none
+int lorentzidx::compare_same_type(const basic & other) const
+{
+       GINAC_ASSERT(is_of_type(other, lorentzidx));
+       const lorentzidx &o = static_cast<const lorentzidx &>(other);
+
+       if (orthogonal_only != o.orthogonal_only)
+               return orthogonal_only ? -1 : 1;
+       if (dim_parallel_space != o.dim_parallel_space)
+               return dim_parallel_space < o.dim_parallel_space ? -1 : 1;
+       return inherited::compare_same_type(other);
+}
 
 //////////
 // non-virtual functions in this class
 
 //////////
 // non-virtual functions in this class
@@ -270,6 +270,7 @@ bool lorentzidx::info(unsigned inf) const
 
 // public
 
 
 // public
 
+/** Create anonymous contravariant copy of a symbolic Lorentz index. */
 lorentzidx lorentzidx::create_anonymous_representative(void) const
 {
        GINAC_ASSERT(is_symbolic());
 lorentzidx lorentzidx::create_anonymous_representative(void) const
 {
        GINAC_ASSERT(is_symbolic());
@@ -283,18 +284,14 @@ lorentzidx lorentzidx::create_anonymous_representative(void) const
 }
 
 //////////
 }
 
 //////////
-// static member variables
+// global functions
 //////////
 
 //////////
 
-// none
-
-//////////
-// global constants
-//////////
-
-const lorentzidx some_lorentzidx;
-const std::type_info & typeid_lorentzidx = typeid(some_lorentzidx);
+/** Return the global symbol that represents the dimension D of spacetime. */
+ex Dim(void)
+{
+       static symbol *d = new symbol("dim");
+       return *d;
+}
 
 
-#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
 } // namespace GiNaC
-#endif // ndef NO_NAMESPACE_GINAC