lortensor class
authorwelzel <welzel>
Fri, 17 Dec 1999 17:44:17 +0000 (17:44 +0000)
committerwelzel <welzel>
Fri, 17 Dec 1999 17:44:17 +0000 (17:44 +0000)
ginac/Makefile.am
ginac/Makefile.in
ginac/indexed.cpp
ginac/indexed.h
ginac/lortensor.cpp [new file with mode: 0644]
ginac/lortensor.h [new file with mode: 0644]
ginac/tinfos.h

index 4f20370dfb6606aeb1e401fbb0716c9cfdc4a422..1d165809e45f39b79b12f8bc148f418352812495 100644 (file)
@@ -7,7 +7,7 @@ libginac_la_SOURCES = add.cpp basic.cpp constant.cpp diff.cpp ex.cpp \
   normal.cpp numeric.cpp operators.cpp power.cpp relational.cpp symbol.cpp \
   utils.cpp series.cpp ncmul.cpp clifford.cpp structure.cpp color.cpp \
   indexed.cpp idx.cpp isospin.cpp exprseq_suppl.cpp lst.cpp lst_suppl.cpp \
-  simp_lor.cpp coloridx.cpp lorentzidx.cpp debugmsg.h utils.h
+  simp_lor.cpp coloridx.cpp lorentzidx.cpp lortensor.cpp debugmsg.h utils.h 
 libginac_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
   -release $(LT_RELEASE)
 ginacincludedir = $(includedir)/ginac
@@ -15,7 +15,7 @@ ginacinclude_HEADERS = ginac.h add.h basic.h clifford.h color.h coloridx.h \
   constant.h ex.h expair.h expairseq.h exprseq.h fail.h flags.h function.h \
   idx.h indexed.h inifcns.h isospin.h lorentzidx.h lst.h matrix.h mul.h \
   ncmul.h normal.h numeric.h operators.h power.h relational.h series.h \
-  simp_lor.h structure.h symbol.h tinfos.h assertion.h
+  simp_lor.h structure.h symbol.h lortensor.h tinfos.h assertion.h
 EXTRA_DIST = container.pl function.pl structure.pl
 
 # Files which are generated by perl scripts
index 14ff9e652403b1ff699a87d3b4e88a55f435e766..bffdd52843b8451c105b45b6433f9178db0114eb 100644 (file)
@@ -98,12 +98,12 @@ VERSION = @VERSION@
 YACC = @YACC@
 
 lib_LTLIBRARIES = libginac.la
-libginac_la_SOURCES = add.cpp basic.cpp constant.cpp diff.cpp ex.cpp   expairseq.cpp exprseq.cpp fail.cpp function.cpp inifcns.cpp   inifcns_trans.cpp inifcns_zeta.cpp inifcns_gamma.cpp matrix.cpp mul.cpp   normal.cpp numeric.cpp operators.cpp power.cpp relational.cpp symbol.cpp   utils.cpp series.cpp ncmul.cpp clifford.cpp structure.cpp color.cpp   indexed.cpp idx.cpp isospin.cpp exprseq_suppl.cpp lst.cpp lst_suppl.cpp   simp_lor.cpp coloridx.cpp lorentzidx.cpp debugmsg.h utils.h
+libginac_la_SOURCES = add.cpp basic.cpp constant.cpp diff.cpp ex.cpp   expairseq.cpp exprseq.cpp fail.cpp function.cpp inifcns.cpp   inifcns_trans.cpp inifcns_zeta.cpp inifcns_gamma.cpp matrix.cpp mul.cpp   normal.cpp numeric.cpp operators.cpp power.cpp relational.cpp symbol.cpp   utils.cpp series.cpp ncmul.cpp clifford.cpp structure.cpp color.cpp   indexed.cpp idx.cpp isospin.cpp exprseq_suppl.cpp lst.cpp lst_suppl.cpp   simp_lor.cpp coloridx.cpp lorentzidx.cpp lortensor.cpp debugmsg.h utils.h 
 
 libginac_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)   -release $(LT_RELEASE)
 
 ginacincludedir = $(includedir)/ginac
-ginacinclude_HEADERS = ginac.h add.h basic.h clifford.h color.h coloridx.h   constant.h ex.h expair.h expairseq.h exprseq.h fail.h flags.h function.h   idx.h indexed.h inifcns.h isospin.h lorentzidx.h lst.h matrix.h mul.h   ncmul.h normal.h numeric.h operators.h power.h relational.h series.h   simp_lor.h structure.h symbol.h tinfos.h assertion.h
+ginacinclude_HEADERS = ginac.h add.h basic.h clifford.h color.h coloridx.h   constant.h ex.h expair.h expairseq.h exprseq.h fail.h flags.h function.h   idx.h indexed.h inifcns.h isospin.h lorentzidx.h lst.h matrix.h mul.h   ncmul.h normal.h numeric.h operators.h power.h relational.h series.h   simp_lor.h structure.h symbol.h lortensor.h tinfos.h assertion.h
 
 EXTRA_DIST = container.pl function.pl structure.pl
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
@@ -123,7 +123,7 @@ inifcns_zeta.lo inifcns_gamma.lo matrix.lo mul.lo normal.lo numeric.lo \
 operators.lo power.lo relational.lo symbol.lo utils.lo series.lo \
 ncmul.lo clifford.lo structure.lo color.lo indexed.lo idx.lo isospin.lo \
 exprseq_suppl.lo lst.lo lst_suppl.lo simp_lor.lo coloridx.lo \
-lorentzidx.lo
+lorentzidx.lo lortensor.lo
 CXXFLAGS = @CXXFLAGS@
 CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
 LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
@@ -148,10 +148,11 @@ DEP_FILES =  .deps/add.P .deps/basic.P .deps/clifford.P .deps/color.P \
 .deps/expairseq.P .deps/exprseq.P .deps/exprseq_suppl.P .deps/fail.P \
 .deps/function.P .deps/idx.P .deps/indexed.P .deps/inifcns.P \
 .deps/inifcns_gamma.P .deps/inifcns_trans.P .deps/inifcns_zeta.P \
-.deps/isospin.P .deps/lorentzidx.P .deps/lst.P .deps/lst_suppl.P \
-.deps/matrix.P .deps/mul.P .deps/ncmul.P .deps/normal.P .deps/numeric.P \
-.deps/operators.P .deps/power.P .deps/relational.P .deps/series.P \
-.deps/simp_lor.P .deps/structure.P .deps/symbol.P .deps/utils.P
+.deps/isospin.P .deps/lorentzidx.P .deps/lortensor.P .deps/lst.P \
+.deps/lst_suppl.P .deps/matrix.P .deps/mul.P .deps/ncmul.P \
+.deps/normal.P .deps/numeric.P .deps/operators.P .deps/power.P \
+.deps/relational.P .deps/series.P .deps/simp_lor.P .deps/structure.P \
+.deps/symbol.P .deps/utils.P
 SOURCES = $(libginac_la_SOURCES)
 OBJECTS = $(libginac_la_OBJECTS)
 
index 0364d99746e97567c466aeced3e5d15a4bfb3339..7dd2f0dae6f07c55392812634216974d0b05efa5 100644 (file)
@@ -107,6 +107,14 @@ indexed::indexed(ex const & i1, ex const & i2, ex const & i3)
     GINAC_ASSERT(all_of_type_idx());
 }
 
+indexed::indexed(ex const & i1, ex const & i2, ex const & i3, ex const & i4)
+    : exprseq(i1,i2,i3,i4)
+{
+    debugmsg("indexed constructor from ex,ex,ex,ex",LOGLEVEL_CONSTRUCT);
+    tinfo_key=TINFO_indexed;
+    GINAC_ASSERT(all_of_type_idx());
+}
+
 indexed::indexed(exvector const & iv) : exprseq(iv)
 {
     debugmsg("indexed constructor from exvector",LOGLEVEL_CONSTRUCT);
index a731769bd9f5c9826ead34ae4077094f4fb71500..7b425ba0697495fa76372e86178489c7cc5daeaf 100644 (file)
@@ -50,6 +50,7 @@ public:
     indexed(ex const & i1);
     indexed(ex const & i1, ex const & i2);
     indexed(ex const & i1, ex const & i2, ex const & i3);
+    indexed(ex const & i1, ex const & i2, ex const & i3, ex const & i4);
     indexed(exvector const & iv);
     indexed(exvector * iv);
 
diff --git a/ginac/lortensor.cpp b/ginac/lortensor.cpp
new file mode 100644 (file)
index 0000000..7cbd2f4
--- /dev/null
@@ -0,0 +1,489 @@
+/** @file lortensor.cpp
+ *
+ *  Implementation of GiNaC´s lortensor objects.
+ *  No real implementation yet, do be done.      */
+
+/*
+ *  GiNaC Copyright (C) 1999 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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <string>
+#include <list>
+#include <algorithm>
+#include <iostream>
+#include <stdexcept>
+#include <map>
+
+#include "basic.h"
+#include "add.h"
+#include "mul.h"
+#include "debugmsg.h"
+#include "flags.h"
+#include "lst.h"
+#include "lortensor.h"
+#include "utils.h"
+#include "operators.h"
+#include "tinfos.h"
+#include "power.h"
+#include "symbol.h"
+
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
+
+//////////
+// default constructor, destructor, copy constructor assignment operator and helpers
+//////////
+
+// public
+
+lortensor::lortensor()
+{
+    debugmsg("lortensor default constructor",LOGLEVEL_CONSTRUCT);
+    serial=next_serial++;
+    name=autoname_prefix()+ToString(serial);
+    tinfo_key=TINFO_lortensor;
+}
+
+lortensor::~lortensor()
+{
+    debugmsg("lortensor destructor",LOGLEVEL_DESTRUCT);
+    destroy(0);
+}
+
+lortensor::lortensor(lortensor const & other)
+{
+    debugmsg("lortensor copy constructor",LOGLEVEL_CONSTRUCT);
+    copy (other);
+}
+
+lortensor const & lortensor::operator=(lortensor const & other)
+{
+    debugmsg("lortensor operator=",LOGLEVEL_ASSIGNMENT);
+    if (this != & other) {
+        destroy(1);
+        copy(other);
+    }
+    return *this;
+}
+
+//protected
+
+void lortensor::copy(lortensor const & other)
+{
+    indexed::copy(other);
+    type=other.type;
+    name=other.name;
+    serial=other.serial;
+}
+
+void lortensor::destroy(bool call_parent)
+{
+    if (call_parent) {
+        indexed::destroy(call_parent);
+    }
+}
+
+//////////
+// other constructors
+//////////
+
+// protected
+
+lortensor::lortensor(lortensor_types const lt, string const & n) : type(lt), name(n)
+{
+    debugmsg("lortensor constructor from lortensor_types,string",LOGLEVEL_CONSTRUCT);
+    serial=next_serial++;
+    tinfo_key=TINFO_lortensor;
+}
+
+lortensor::lortensor(lortensor_types const lt, string const & n, ex const & mu) : indexed(mu), type(lt), name(n)
+{
+    debugmsg("lortensor constructor from lortensor_types,string,ex",LOGLEVEL_CONSTRUCT);
+    serial=next_serial++;    
+    GINAC_ASSERT(all_of_type_lorentzidx());
+    tinfo_key=TINFO_lortensor;
+}
+
+lortensor::lortensor(lortensor_types const lt, string const & n, ex const & mu, ex const & nu) : indexed(mu,nu), type(lt), name(n)
+{
+    debugmsg("lortensor constructor from lortensor_types,string,ex,ex",LOGLEVEL_CONSTRUCT);
+    serial=next_serial++;
+    GINAC_ASSERT(all_of_type_lorentzidx());
+    tinfo_key=TINFO_lortensor;
+}
+
+lortensor::lortensor(lortensor_types const lt, string const & n, ex const & mu, ex const & nu, ex const & rho) : indexed(mu,nu,rho), type(lt), name(n)
+{
+    debugmsg("lortensor constructor from lortensor_types,string,ex,ex,ex",LOGLEVEL_CONSTRUCT);
+    serial=next_serial++;
+    GINAC_ASSERT(all_of_type_lorentzidx());
+    tinfo_key=TINFO_lortensor;
+}
+
+lortensor::lortensor(lortensor_types const lt, string const & n, ex const & mu, ex const & nu, ex const & rho, ex const & sigma) : indexed(mu,nu,rho,sigma), type(lt), name(n)
+{
+    debugmsg("lortensor constructor from lortensor_types,string,ex,ex,ex,ex",LOGLEVEL_CONSTRUCT);
+    serial=next_serial++;
+    GINAC_ASSERT(all_of_type_lorentzidx());
+    tinfo_key=TINFO_lortensor;
+}
+
+lortensor::lortensor(lortensor_types const lt, string const & n, exvector const & iv) : indexed(iv), type(lt), name(n)
+{
+    debugmsg("lortensor constructor from lortensor_types,string,exvector",LOGLEVEL_CONSTRUCT);
+    serial=next_serial++;
+    GINAC_ASSERT(all_of_type_lorentzidx());
+    tinfo_key=TINFO_lortensor;
+}
+
+lortensor::lortensor(lortensor_types const lt, string const & n, unsigned s, exvector const & iv) : indexed(iv), type(lt), name(n), serial(s)
+{
+    debugmsg("lortensor constructor from lortensor_types,string,unsigned,exvector",LOGLEVEL_CONSTRUCT);
+    GINAC_ASSERT(all_of_type_lorentzidx());
+    tinfo_key=TINFO_lortensor;
+}
+
+lortensor::lortensor(lortensor_types const lt, string const & n, unsigned s, exvector *ivp) : indexed(ivp), type(lt), name(n), serial(s)
+{
+    debugmsg("lortensor constructor from lortensor_types,string,unsigned,exvector",LOGLEVEL_CONSTRUCT);
+    GINAC_ASSERT(all_of_type_lorentzidx());
+    tinfo_key=TINFO_lortensor;
+}
+
+//////////
+// functions overriding virtual functions from bases classes
+//////////
+
+//public
+
+basic * lortensor::duplicate() const
+{
+    debugmsg("lortensor duplicate",LOGLEVEL_DUPLICATE);
+    return new lortensor(*this);
+}
+
+void lortensor::printraw(ostream & os) const
+{
+    debugmsg("lortensor printraw",LOGLEVEL_PRINT);
+    os << "lortensor(type=" << (unsigned)type
+       << ",indices=";
+    printrawindices(os);
+    os << ",hash=" << hashvalue << ",flags=" << flags << ")";
+}
+
+void lortensor::printtree(ostream & os, unsigned indent) const
+{
+    debugmsg("lortensor printtree",LOGLEVEL_PRINT);
+    os << string(indent,' ') <<"lortensor object: "
+       << "type=" << (unsigned)type << ","
+       << seq.size() << " indices" << endl;
+    printtreeindices(os,indent);
+    os << string(indent,' ') << "hash=" << hashvalue
+       << " (0x" << hex << hashvalue << dec << ")"
+       << ", flags=" << flags << endl;
+}
+
+void lortensor::print(ostream & os, unsigned upper_precedence) const
+{
+    debugmsg("lortensor print",LOGLEVEL_PRINT);
+    switch (type) {
+    case lortensor_g:
+        os << "g";
+        break;
+    case lortensor_rankn:
+        os << name;
+        break;
+    case lortensor_rank1:
+        os << name;
+        break;
+    case lortensor_rank2:
+        os << name;
+        break;
+    case lortensor_epsilon:
+        os << "epsilon";
+        break;
+    case invalid:
+    default:
+        os << "INVALID_LORTENSOR_OBJECT";
+        break;
+    }
+    printindices(os);
+}
+
+void lortensor::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
+{
+    debugmsg("lortensor print csrc",LOGLEVEL_PRINT);
+    print(os,upper_precedence);
+}
+
+bool lortensor::info(unsigned inf) const
+{
+    return indexed::info(inf);
+}
+
+ex lortensor::eval(int level) const
+{
+    if (type==lortensor_g) {
+        // canonicalize indices
+        exvector iv=seq;
+        int sig=canonicalize_indices(iv,false); //symmetric
+        if (sig!=INT_MAX) {
+            //something has changed while sorting indices, more evaluations later
+            return ex(sig) *lortensor(type,name,iv);
+        }
+        lorentzidx const & idx1=ex_to_lorentzidx(seq[0]);
+        lorentzidx const & 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();
+                } else {
+                    if (idx1.is_covariant() != idx2.is_covariant()) {
+                        // (_i,~i) or (~i,_i), i = 1...3
+                        return exONE();
+                    } else {
+                        // (_i,_i) or (~i,~i), i= 1...3
+                        return exMINUSONE();
+                    }
+                }
+            } else {
+                // at least one off-diagonal
+                return exZERO();
+            }
+        } else if (idx1.is_symbolic() && idx1.is_co_contra_pair(idx2)) {
+            return Dim()-idx1.get_dim_parallel_space();
+        }
+    }
+    return this -> hold();
+}
+
+//protected
+
+int lortensor::compare_same_type(basic const & other) const
+{
+    GINAC_ASSERT(is_of_type(other,lortensor));
+    const lortensor *o = static_cast <const lortensor *> (&other);
+    if (type==o->type) {
+        if (type==lortensor_rankn) {
+            if (serial!=o->serial) {
+                return serial < o->serial ? -1 : 1;
+            }
+        }
+        return indexed::compare_same_type(other);
+    }
+    return type < o->type ? -1 : 1;            
+}
+
+bool lortensor::is_equal_same_type(basic const & other) const
+{
+    GINAC_ASSERT(is_of_type(other,lortensor));
+    const lortensor *o=static_cast<const lortensor *> (&other);
+    if (type!=o->type) return false;
+    if (type==lortensor_rankn) {
+        if (serial!=o->serial) return false;
+    }
+    return indexed::is_equal_same_type(other);            
+}
+
+unsigned lortensor::return_type(void) const
+{
+    return return_types::commutative;
+}
+unsigned lortensor::return_type_tinfo(void) const
+{
+    return tinfo_key;
+}
+ex lortensor::thisexprseq(exvector const & v) const
+{
+    return lortensor(type,name,serial,v);
+}
+ex lortensor::thisexprseq(exvector *vp) const
+{
+    return lortensor(type,name,serial,vp);
+}
+    
+//////////
+// non-virtual functions in this class
+//////////
+
+// protected
+
+void lortensor::setname(string const & n)
+{
+    name=n;
+}
+
+bool lortensor::all_of_type_lorentzidx(void) const
+{
+    for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++ cit) {
+        if (!is_ex_of_type(*cit,lorentzidx)) {
+            return false;
+        }
+    }
+    return true;
+}
+
+// private
+
+string & lortensor::autoname_prefix(void)
+{
+    static string * s=new string("lortensor");
+    return *s;
+}
+
+//////////
+// static member variables
+//////////
+
+// private
+
+unsigned lortensor::next_serial=0;
+
+//////////
+// friend functions
+//////////
+
+lortensor lortensor_g(ex const & mu, ex const & nu)
+{
+    return lortensor(lortensor::lortensor_g,"",mu,nu);
+}
+
+lortensor lortensor_epsilon(ex const & mu, ex const & nu, ex const & rho, ex const & sigma)
+{
+    return lortensor(lortensor::lortensor_epsilon,"",mu,nu,rho,sigma);
+}
+
+lortensor lortensor_rank1(string const & n, ex const & mu)
+{
+    return lortensor(lortensor::lortensor_rank1,n,mu);
+}
+
+lortensor lortensor_rank2(string const & n, ex const & mu, ex const & nu)
+{
+    return lortensor(lortensor::lortensor_rank2,n,mu,nu);
+}
+
+ex simplify_lortensor_mul(ex const & m)
+{
+    GINAC_ASSERT(is_ex_exactly_of_type(m,mul));
+    exvector v_contracted;
+
+    // collect factors in an exvector, store squares twice
+    int n=m.nops();
+    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).is_equal(exTWO())) {
+            v_contracted.push_back(f.op(0));
+            v_contracted.push_back(f.op(0));
+        } else {
+            v_contracted.push_back(f);
+       }
+    }
+
+    unsigned replacements;
+    bool something_changed=false;
+
+    exvector::iterator it=v_contracted.begin();
+    while (it!=v_contracted.end()) {
+        // process only lor_g objects
+        if (is_ex_exactly_of_type(*it,lortensor) &&
+            (ex_to_lortensor(*it).type==lortensor::lortensor_g)) {            
+            lortensor const & g=ex_to_lortensor(*it);
+            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 lortensor::eval()
+            GINAC_ASSERT(!first_idx.is_equal(second_idx));
+            ex saved_g=*it; // save to restore it later
+
+            // 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);
+                if (replacements==0) {
+                    // not contracted, restore g object
+                    *it=saved_g;
+                } else {
+                    // a contracted index should occur exactly once
+                    GINAC_ASSERT(replacements==1);
+                    *it=exONE();
+                    something_changed=true;
+                }
+            }
+
+            // 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);
+                if (replacements==0) {
+                    // not contracted except in itself, restore g object
+                    *it=saved_g;
+                } else {
+                    // a contracted index should occur exactly once
+                    GINAC_ASSERT(replacements==1);
+                    *it=exONE();
+                    something_changed=true;
+                }
+            }
+        }
+        ++it;
+    }
+    if (something_changed) {
+        return mul(v_contracted);
+    }
+    return m;
+}
+
+ex simplify_lortensor(ex const & e)
+{
+    // 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) {
+            sum += simplify_lortensor(e_expanded.op(i));
+        }
+        return sum;
+    }
+
+    // simplification of commutative product=commutative product of simplifications
+    if (is_ex_exactly_of_type(e_expanded,mul)) {
+        return simplify_lortensor_mul(e);
+    }
+
+    // cannot do anything
+    return e_expanded;
+}
+
+ex Dim(void)
+{
+    static symbol * d=new symbol("dim");
+    return *d;
+}
+
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE
diff --git a/ginac/lortensor.h b/ginac/lortensor.h
new file mode 100644 (file)
index 0000000..5dc925b
--- /dev/null
@@ -0,0 +1,153 @@
+/** @file lortensor.h
+ *
+ *  Interface to GiNaC´s lortensor objects. */
+
+/*
+ *  GiNaC Copyright (C) 1999 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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __GINAC_LORTENSOR_H__
+#define __GINAC_LORTENSOR_H__
+
+#include <string>
+#include <vector>
+#include "config.h"
+#include <iostream>
+#include <ginac/indexed.h>
+#include <ginac/lorentzidx.h>
+
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
+
+/** Base class for lortensor object */
+class lortensor : public indexed
+{
+    // friends
+    friend lortensor lortensor_g(ex const & mu, ex const & nu);
+    // friend lortensor lortensor_delta(ex const & mu, ex const & nu);
+    friend lortensor lortensor_epsilon(ex const & mu, ex const & nu,
+                                       ex const & rho, ex const & sigma);
+    friend lortensor lortensor_rankn(string const & n, exvector const & iv);
+    friend lortensor lortensor_rank1(string const & n, ex const & mu);
+    friend lortensor lortensor_rank2(string const & n, ex const & mu, ex const & nu);
+    friend ex simplify_lortensor_mul(ex const & m);
+    friend ex simplify_lortensor(ex const & e);
+    
+    // types
+
+public:
+    typedef enum { invalid,
+                   lortensor_g,
+                   lortensor_rankn,
+                   lortensor_rank1,
+                   lortensor_rank2,
+                   // lortensor_delta,
+                   lortensor_epsilon
+    } lortensor_types;
+
+    // member functions
+
+    // default constructor, destructor, copy constructor assignment operator and helpers
+public:
+    lortensor();
+    ~lortensor();
+    lortensor(lortensor const & other);
+    lortensor const & operator=(lortensor const & other);
+protected:
+    void copy(lortensor const & other);
+    void destroy(bool call_parent);
+
+    // other constructors
+protected:
+    lortensor(lortensor_types const lt, string const & n);
+    lortensor(lortensor_types const lt, string const & n, ex const & mu);
+    lortensor(lortensor_types const lt, string const & n, ex const & mu, ex const & nu);
+    lortensor(lortensor_types const lt, string const & n, ex const & mu, ex const & nu,
+              ex const & rho);
+    lortensor(lortensor_types const lt, string const & n, ex const & mu, ex const & nu, ex const & rho, ex const & sigma);
+    lortensor(lortensor_types const lt, string const & n, exvector const & iv);
+    lortensor(lortensor_types const lt, string const & n, unsigned s, exvector const & iv);
+    lortensor(lortensor_types const lt, string const & n, unsigned s, exvector * ivp);
+    
+    //functions overriding virtual functions from base classes
+public:
+    basic * duplicate() const;
+    void printraw(ostream & os) const;
+    void printtree(ostream & os, unsigned indent) const;
+    void print(ostream & os, unsigned upper_precedence=0) const;
+    void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
+    bool info(unsigned inf) const;
+    ex eval(int level=0) const;
+protected:
+    int compare_same_type(basic const & other) const;
+    bool is_equal_same_type(basic const & other) const;
+    unsigned return_type(void) const;
+    unsigned return_type_tinfo(void) const;
+    ex thisexprseq(exvector const & v) const;
+    ex thisexprseq(exvector * vp) const;
+
+    // new virtual functions which can be overridden by derived classes
+    // none
+
+    //non virtual functions in this class
+public:
+    void setname(string const & n);
+    string getname(void) const {return name;}
+protected:
+    bool all_of_type_lorentzidx(void) const;
+private:
+    string & autoname_prefix(void);
+
+    //member variables
+
+protected:
+    lortensor_types type;
+    string name;
+    unsigned serial;
+private:
+    static unsigned next_serial;
+};
+
+// global constants
+
+    extern const lortensor some_lortensor;
+    extern type_info const & typeid_lortensor;
+
+// utility functions !!!!!!!!!!!!!!!!!! (to do)
+    
+
+inline const lortensor & ex_to_lortensor(const ex &e)
+{
+       return static_cast<const lortensor &>(*e.bp);
+}
+
+inline lortensor &ex_to_nonconst_lortensor(const ex &e)
+{
+       return static_cast<lortensor &>(*e.bp);
+}
+
+lortensor lortensor_g(ex const & mu, ex const & nu);
+ex simplify_lortensor_mul(ex const & m);
+ex simplify_lortensor(ex const & e);
+ex Dim(void);    
+
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE
+
+#endif // ndef __GINAC_LORTENSOR_H__
index d13e2b958048e546ee033f9b4755a9aa389e29f5..90c34f9ef43ed05ec6ea6d8302d6ac8ae8a7ed71 100644 (file)
@@ -60,6 +60,7 @@ const unsigned TINFO_clifford     = 0x000b1101U;
 const unsigned TINFO_color        = 0x000b1201U;
 const unsigned TINFO_isospin      = 0x000b1301U;
 const unsigned TINFO_simp_lor     = 0x000b1401U;
+const unsigned TINFO_lortensor    = 0x000b1501U;
 
 const unsigned TINFO_structure    = 0x000c0001U;
 // reserved up to                   0x000cffffU