]> www.ginac.de Git - ginac.git/blobdiff - ginac/clifford.cpp
* New funny timing added: compute an antipode in Yukawa theory.
[ginac.git] / ginac / clifford.cpp
index e60ced049b7fdc8bd397882fd8fb98ec803837ca..a3f26c964cb010ddc60b67d2be302aefc7d5a2e0 100644 (file)
@@ -4,7 +4,7 @@
  *  No real implementation yet, to be done.     */
 
 /*
- *  GiNaC Copyright (C) 1999 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
 #include "clifford.h"
 #include "ex.h"
 #include "ncmul.h"
+#include "archive.h"
 #include "utils.h"
 #include "debugmsg.h"
 
 namespace GiNaC {
 
+GINAC_IMPLEMENT_REGISTERED_CLASS(clifford, lortensor)
+
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
 //////////
@@ -39,48 +42,20 @@ namespace GiNaC {
 
 clifford::clifford()
 {
-    debugmsg("clifford default constructor",LOGLEVEL_CONSTRUCT);
-    serial=next_serial++;
-    name=autoname_prefix()+ToString(serial);
-    tinfo_key=TINFO_clifford;
-}
-
-clifford::~clifford()
-{
-    debugmsg("clifford destructor",LOGLEVEL_DESTRUCT);
-    destroy(0);
-}
-
-clifford::clifford(clifford const & other)
-{
-    debugmsg("clifford copy constructor",LOGLEVEL_CONSTRUCT);
-    copy (other);
-}
-
-clifford const & clifford::operator=(clifford const & other)
-{
-    debugmsg("clifford operator=",LOGLEVEL_ASSIGNMENT);
-    if (this != &other) {
-        destroy(1);
-        copy(other);
-    }
-    return *this;
+       debugmsg("clifford default constructor",LOGLEVEL_CONSTRUCT);
+       tinfo_key = TINFO_clifford;
 }
 
 // protected
 
-void clifford::copy(clifford const & other)
+void clifford::copy(const clifford & other)
 {
-    indexed::copy(other);
-    name=other.name;
-    serial=other.serial;
+       inherited::copy(other);
 }
 
 void clifford::destroy(bool call_parent)
 {
-    if (call_parent) {
-        indexed::destroy(call_parent);
-    }
+       if (call_parent) inherited::destroy(call_parent);
 }
 
 //////////
@@ -89,126 +64,128 @@ void clifford::destroy(bool call_parent)
 
 // public
 
-clifford::clifford(string const & initname)
+clifford::clifford(const std::string & n, const ex & mu) : inherited(lortensor_symbolic, n, mu)
 {
-    debugmsg("clifford constructor from string",LOGLEVEL_CONSTRUCT);
-    name=initname;
-    serial=next_serial++;
-    tinfo_key=TINFO_clifford;
+       debugmsg("clifford constructor from string,ex",LOGLEVEL_CONSTRUCT);
+       tinfo_key=TINFO_clifford;
+}
+
+clifford::clifford(const std::string & n, const exvector & iv) : inherited(lortensor_symbolic, n, iv)
+{
+       debugmsg("clifford constructor from string,exvector", LOGLEVEL_CONSTRUCT);
+       GINAC_ASSERT(all_of_type_lorentzidx());
+       tinfo_key=TINFO_clifford;
+}
+
+clifford::clifford(const std::string & n, exvector *ivp) : inherited(lortensor_symbolic, n, *ivp)
+{
+       debugmsg("clifford constructor from string,exvector", LOGLEVEL_CONSTRUCT);
+       GINAC_ASSERT(all_of_type_lorentzidx());
+       tinfo_key=TINFO_clifford;
 }
 
 //////////
-// functions overriding virtual functions from bases classes
+// archiving
 //////////
 
-// public
+/** Construct object from archive_node. */
+clifford::clifford(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
+{
+       debugmsg("clifford constructor from archive_node", LOGLEVEL_CONSTRUCT);
+}
 
-basic * clifford::duplicate() const
+/** Unarchive the object. */
+ex clifford::unarchive(const archive_node &n, const lst &sym_lst)
 {
-    debugmsg("clifford duplicate",LOGLEVEL_DUPLICATE);
-    return new clifford(*this);
+       return (new clifford(n, sym_lst))->setflag(status_flags::dynallocated);
 }
 
-void clifford::printraw(ostream & os) const
+/** Archive the object. */
+void clifford::archive(archive_node &n) const
 {
-    debugmsg("clifford printraw",LOGLEVEL_PRINT);
-    os << "clifford(" << "name=" << name << ",serial=" << serial
-       << ",indices=";
-    printrawindices(os);
-    os << ",hash=" << hashvalue << ",flags=" << flags << ")";
+       inherited::archive(n);
 }
 
-void clifford::printtree(ostream & os, unsigned indent) const
+//////////
+// functions overriding virtual functions from bases classes
+//////////
+
+// public
+
+void clifford::printraw(std::ostream & os) const
 {
-    debugmsg("clifford printtree",LOGLEVEL_PRINT);
-    os << string(indent,' ') << name << " (clifford): "
-       << "serial=" << serial << ","
-       << seq.size() << "indices=";
-    printtreeindices(os,indent);
-    os << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
-       << ", flags=" << flags << endl;
+       debugmsg("clifford printraw",LOGLEVEL_PRINT);
+       os << "clifford(" << "indices=";
+       printrawindices(os);
+       os << ",hash=" << hashvalue << ",flags=" << flags << ")";
 }
 
-void clifford::print(ostream & os, unsigned upper_precedence) const
+void clifford::printtree(std::ostream & os, unsigned indent) const
 {
-    debugmsg("clifford print",LOGLEVEL_PRINT);
-    os << name;
-    printindices(os);
+       debugmsg("clifford printtree",LOGLEVEL_PRINT);
+       os << std::string(indent,' ') << " (clifford): "
+          << seq.size() << "indices=";
+       printtreeindices(os, indent);
+       os << ", hash=" << hashvalue
+          << " (0x" << std::hex << hashvalue << std::dec << ")"
+          << ", flags=" << flags << std::endl;
 }
 
-void clifford::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
+void clifford::print(std::ostream & os, unsigned upper_precedence) const
 {
-    debugmsg("clifford print csrc",LOGLEVEL_PRINT);
-    print(os,upper_precedence);
+       debugmsg("clifford print",LOGLEVEL_PRINT);
+       os << name;
+       printindices(os);
 }
 
 bool clifford::info(unsigned inf) const
 {
-    return indexed::info(inf);
+       return inherited::info(inf);
 }
 
 // protected
 
-int clifford::compare_same_type(basic const & other) const
+int clifford::compare_same_type(const basic & other) const
 {
-    ASSERT(other.tinfo() == TINFO_clifford);
-    const clifford *o = static_cast<const clifford *>(&other);
-    if (serial==o->serial) {
-        return indexed::compare_same_type(other);
-    }
-    return serial < o->serial ? -1 : 1;
+       GINAC_ASSERT(is_of_type(other,clifford));
+       // only compare indices
+       return exprseq::compare_same_type(other);
 }
 
-ex clifford::simplify_ncmul(exvector const & v) const
+bool clifford::is_equal_same_type(const basic & other) const
 {
-    return simplified_ncmul(v);
+       GINAC_ASSERT(is_of_type(other,clifford));
+       // only compare indices
+       return exprseq::is_equal_same_type(other);
 }
 
-unsigned clifford::calchash(void) const
+ex clifford::thisexprseq(const exvector & v) const
 {
-    hashvalue=golden_ratio_hash(golden_ratio_hash(0x55555556U ^
-                                                  golden_ratio_hash(tinfo_key) ^
-                                                  serial));
-    setflag(status_flags::hash_calculated);
-    return hashvalue;
+       return clifford(name, v);
 }
 
-//////////
-// virtual functions which can be overridden by derived classes
-//////////
-
-// none
-
-//////////
-// non-virtual functions in this class
-//////////
-
-void clifford::setname(string const & n)
+ex clifford::thisexprseq(exvector *vp) const
 {
-    name=n;
+       return clifford(name, vp);
 }
 
-// private
-
-string & clifford::autoname_prefix(void)
+ex clifford::simplify_ncmul(const exvector & v) const
 {
-    static string * s=new string("clifford");
-    return *s;
+       return simplified_ncmul(v);
 }
 
 //////////
-// static member variables
-//////////
-
-// private
-
-unsigned clifford::next_serial=0;
-
-//////////
-// global constants
+// friend functions
 //////////
 
-const clifford some_clifford;
-type_info const & typeid_clifford=typeid(some_clifford);
+/** Construct an object representing a Dirac gamma matrix. The index must
+ *  be of class lorentzidx.
+ *
+ *  @param mu Index
+ *  @return newly constructed object */
+clifford clifford_gamma(const ex & mu)
+{
+       return clifford("gamma", mu);
+}
 
 } // namespace GiNaC