X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fclifford.cpp;h=c3c0d9f3a3ba9b9944f1bd96626aed8863c99ed3;hb=e5362a33f72613b324b3714524a8c2e5f7b7f46f;hp=2bf3fbb7abac689dba46342c582655fe91932d2f;hpb=bd2d7351b89743eb68ce7d3bfa7ab62c331f9522;p=ginac.git diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index 2bf3fbb7..c3c0d9f3 100644 --- a/ginac/clifford.cpp +++ b/ginac/clifford.cpp @@ -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 @@ -26,6 +26,7 @@ #include "clifford.h" #include "ex.h" #include "ncmul.h" +#include "archive.h" #include "utils.h" #include "debugmsg.h" @@ -33,6 +34,8 @@ namespace GiNaC { #endif // ndef NO_NAMESPACE_GINAC +GINAC_IMPLEMENT_REGISTERED_CLASS(clifford, lortensor) + ////////// // default constructor, destructor, copy constructor assignment operator and helpers ////////// @@ -41,62 +44,68 @@ namespace GiNaC { clifford::clifford() { - debugmsg("clifford default constructor",LOGLEVEL_CONSTRUCT); - serial=next_serial++; - name=autoname_prefix()+ToString(serial); - tinfo_key=TINFO_clifford; + debugmsg("clifford default constructor",LOGLEVEL_CONSTRUCT); + tinfo_key = TINFO_clifford; } -clifford::~clifford() +// protected + +void clifford::copy(const clifford & other) { - debugmsg("clifford destructor",LOGLEVEL_DESTRUCT); - destroy(0); + inherited::copy(other); } -clifford::clifford(const clifford & other) +void clifford::destroy(bool call_parent) { - debugmsg("clifford copy constructor",LOGLEVEL_CONSTRUCT); - copy (other); + if (call_parent) inherited::destroy(call_parent); } -const clifford & clifford::operator=(const clifford & other) +////////// +// other constructors +////////// + +// public + +clifford::clifford(const std::string & n, const ex & mu) : inherited(lortensor_symbolic, n, mu) { - debugmsg("clifford operator=",LOGLEVEL_ASSIGNMENT); - if (this != &other) { - destroy(1); - copy(other); - } - return *this; + debugmsg("clifford constructor from string,ex",LOGLEVEL_CONSTRUCT); + tinfo_key=TINFO_clifford; } -// protected - -void clifford::copy(const clifford & other) +clifford::clifford(const std::string & n, const exvector & iv) : inherited(lortensor_symbolic, n, iv) { - indexed::copy(other); - name=other.name; - serial=other.serial; + debugmsg("clifford constructor from string,exvector", LOGLEVEL_CONSTRUCT); + GINAC_ASSERT(all_of_type_lorentzidx()); + tinfo_key=TINFO_clifford; } -void clifford::destroy(bool call_parent) +clifford::clifford(const std::string & n, exvector *ivp) : inherited(lortensor_symbolic, n, *ivp) { - if (call_parent) { - indexed::destroy(call_parent); - } + debugmsg("clifford constructor from string,exvector", LOGLEVEL_CONSTRUCT); + GINAC_ASSERT(all_of_type_lorentzidx()); + tinfo_key=TINFO_clifford; } ////////// -// other constructors +// 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); +} + +/** Unarchive the object. */ +ex clifford::unarchive(const archive_node &n, const lst &sym_lst) +{ + return (new clifford(n, sym_lst))->setflag(status_flags::dynallocated); +} -clifford::clifford(const std::string & initname) +/** Archive the object. */ +void clifford::archive(archive_node &n) const { - debugmsg("clifford constructor from string",LOGLEVEL_CONSTRUCT); - name=initname; - serial=next_serial++; - tinfo_key=TINFO_clifford; + inherited::archive(n); } ////////// @@ -107,112 +116,85 @@ clifford::clifford(const std::string & initname) basic * clifford::duplicate() const { - debugmsg("clifford duplicate",LOGLEVEL_DUPLICATE); - return new clifford(*this); + debugmsg("clifford duplicate",LOGLEVEL_DUPLICATE); + return new clifford(*this); } void clifford::printraw(std::ostream & os) const { - debugmsg("clifford printraw",LOGLEVEL_PRINT); - os << "clifford(" << "name=" << name << ",serial=" << serial - << ",indices="; - printrawindices(os); - os << ",hash=" << hashvalue << ",flags=" << flags << ")"; + debugmsg("clifford printraw",LOGLEVEL_PRINT); + os << "clifford(" << "indices="; + printrawindices(os); + os << ",hash=" << hashvalue << ",flags=" << flags << ")"; } void clifford::printtree(std::ostream & os, unsigned indent) const { - debugmsg("clifford printtree",LOGLEVEL_PRINT); - os << std::string(indent,' ') << name << " (clifford): " - << "serial=" << serial << "," - << seq.size() << "indices="; - printtreeindices(os, indent); - os << ", hash=" << hashvalue - << " (0x" << std::hex << hashvalue << std::dec << ")" - << ", flags=" << flags << std::endl; + 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::print(std::ostream & os, unsigned upper_precedence) const { - debugmsg("clifford print",LOGLEVEL_PRINT); - os << name; - printindices(os); -} - -void clifford::printcsrc(std::ostream & os, unsigned type, 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(const basic & other) const { - GINAC_ASSERT(other.tinfo() == TINFO_clifford); - const clifford *o = static_cast(&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(const exvector & 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(const std::string & n) +ex clifford::thisexprseq(exvector *vp) const { - name = n; + return clifford(name, vp); } -// private - -std::string & clifford::autoname_prefix(void) +ex clifford::simplify_ncmul(const exvector & v) const { - static std::string * s = new std::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; -const type_info & 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); +} #ifndef NO_NAMESPACE_GINAC } // namespace GiNaC