X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fcolor.cpp;h=c35e03e5d632f3bcd896f01f0419c0891edff607;hp=095a3b0c13564820cacdf328b529fec2ce1bf3a0;hb=a74473453218570d22f8932cc39ab48c7f0021ae;hpb=24fe247f9ed16114a765a01c593fec5c4a2f591c diff --git a/ginac/color.cpp b/ginac/color.cpp index 095a3b0c..c35e03e5 100644 --- a/ginac/color.cpp +++ b/ginac/color.cpp @@ -4,7 +4,7 @@ * No real implementation yet, to be done. */ /* - * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2000 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 @@ -33,9 +33,15 @@ #include "ncmul.h" #include "numeric.h" #include "relational.h" +#include "archive.h" #include "debugmsg.h" +#include "utils.h" +#ifndef NO_NAMESPACE_GINAC namespace GiNaC { +#endif // ndef NO_NAMESPACE_GINAC + +GINAC_IMPLEMENT_REGISTERED_CLASS(color, indexed) ////////// // default constructor, destructor, copy constructor assignment operator and helpers @@ -55,13 +61,13 @@ color::~color() destroy(0); } -color::color(color const & other) +color::color(const color & other) { debugmsg("color copy constructor",LOGLEVEL_CONSTRUCT); copy (other); } -color const & color::operator=(color const & other) +const color & color::operator=(const color & other) { debugmsg("color operator=",LOGLEVEL_ASSIGNMENT); if (this != &other) { @@ -73,9 +79,9 @@ color const & color::operator=(color const & other) // protected -void color::copy(color const & other) +void color::copy(const color & other) { - indexed::copy(other); + inherited::copy(other); type=other.type; representation_label=other.representation_label; } @@ -83,7 +89,7 @@ void color::copy(color const & other) void color::destroy(bool call_parent) { if (call_parent) { - indexed::destroy(call_parent); + inherited::destroy(call_parent); } } @@ -93,7 +99,7 @@ void color::destroy(bool call_parent) // protected -color::color(color_types const t, unsigned const rl) : type(t), representation_label(rl) +color::color(color_types const t, unsigned rl) : type(t), representation_label(rl) { debugmsg("color constructor from color_types,unsigned",LOGLEVEL_CONSTRUCT); GINAC_ASSERT(representation_labelsetflag(status_flags::dynallocated); +} + +/** Archive the object. */ +void color::archive(archive_node &n) const +{ + inherited::archive(n); + n.add_unsigned("type", type); + n.add_unsigned("representation", representation_label); +} + ////////// // functions overriding virtual functions from bases classes ////////// @@ -219,7 +255,7 @@ void color::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) co bool color::info(unsigned inf) const { - return indexed::info(inf); + return inherited::info(inf); } #define CMPINDICES(A,B,C) ((idx1.get_value()==(A))&&(idx2.get_value()==(B))&&(idx3.get_value()==(C))) @@ -240,7 +276,7 @@ ex color::eval(int level) const int sig=canonicalize_indices(iv,antisymmetric); if (sig!=INT_MAX) { // something has changed while sorting indices, more evaluations later - if (sig==0) return exZERO(); + if (sig==0) return _ex0(); return ex(sig)*color(type,iv,representation_label); } } @@ -254,8 +290,8 @@ ex color::eval(int level) const case color_delta8: { GINAC_ASSERT(seq.size()==2); - coloridx const & idx1=ex_to_coloridx(seq[0]); - coloridx const & idx2=ex_to_coloridx(seq[1]); + const coloridx & idx1=ex_to_coloridx(seq[0]); + const coloridx & idx2=ex_to_coloridx(seq[1]); // check for delta8_{a,a} where a is a symbolic index, replace by 8 if ((idx1.is_symbolic())&&(idx1.is_equal_same_type(idx2))) { @@ -265,9 +301,9 @@ ex color::eval(int level) const // check for delta8_{a,b} where a and b are numeric indices, replace by 0 or 1 if ((!idx1.is_symbolic())&&(!idx2.is_symbolic())) { if ((idx1.get_value()!=idx2.get_value())) { - return exONE(); + return _ex1(); } else { - return exZERO(); + return _ex0(); } } } @@ -276,14 +312,14 @@ ex color::eval(int level) const // check for d_{a,a,c} (=0) when a is symbolic { GINAC_ASSERT(seq.size()==3); - coloridx const & idx1=ex_to_coloridx(seq[0]); - coloridx const & idx2=ex_to_coloridx(seq[1]); - coloridx const & idx3=ex_to_coloridx(seq[2]); + const coloridx & idx1=ex_to_coloridx(seq[0]); + const coloridx & idx2=ex_to_coloridx(seq[1]); + const coloridx & idx3=ex_to_coloridx(seq[2]); if (idx1.is_equal_same_type(idx2) && idx1.is_symbolic()) { - return exZERO(); + return _ex0(); } else if (idx2.is_equal_same_type(idx3) && idx2.is_symbolic()) { - return exZERO(); + return _ex0(); } // check for three numeric indices @@ -292,9 +328,9 @@ ex color::eval(int level) const GINAC_ASSERT(idx2.get_value()<=idx3.get_value()); if (CMPINDICES(1,4,6)||CMPINDICES(1,5,7)||CMPINDICES(2,5,6)|| CMPINDICES(3,4,4)||CMPINDICES(3,5,5)) { - return exHALF(); + return _ex1_2(); } else if (CMPINDICES(2,4,7)||CMPINDICES(3,6,6)||CMPINDICES(3,7,7)) { - return -exHALF(); + return -_ex1_2(); } else if (CMPINDICES(1,1,8)||CMPINDICES(2,2,8)||CMPINDICES(3,3,8)) { return 1/sqrt(numeric(3)); } else if (CMPINDICES(8,8,8)) { @@ -302,28 +338,28 @@ ex color::eval(int level) const } else if (CMPINDICES(4,4,8)||CMPINDICES(5,5,8)||CMPINDICES(6,6,8)||CMPINDICES(7,7,8)) { return -1/(2*sqrt(numeric(3))); } - return exZERO(); + return _ex0(); } } break; case color_f: { GINAC_ASSERT(seq.size()==3); - coloridx const & idx1=ex_to_coloridx(seq[0]); - coloridx const & idx2=ex_to_coloridx(seq[1]); - coloridx const & idx3=ex_to_coloridx(seq[2]); + const coloridx & idx1=ex_to_coloridx(seq[0]); + const coloridx & idx2=ex_to_coloridx(seq[1]); + const coloridx & idx3=ex_to_coloridx(seq[2]); // check for three numeric indices if (!(idx1.is_symbolic()||idx2.is_symbolic()||idx3.is_symbolic())) { GINAC_ASSERT(idx1.get_value()<=idx2.get_value()); GINAC_ASSERT(idx2.get_value()<=idx3.get_value()); if (CMPINDICES(1,2,3)) { - return exONE(); + return _ex1(); } else if (CMPINDICES(1,4,7)||CMPINDICES(2,4,6)|| CMPINDICES(2,5,7)||CMPINDICES(3,4,5)) { - return exHALF(); + return _ex1_2(); } else if (CMPINDICES(1,5,6)||CMPINDICES(3,6,7)) { - return -exHALF(); + return -_ex1_2(); } else if (CMPINDICES(4,5,8)||CMPINDICES(6,7,8)) { return sqrt(numeric(3))/2; } else if (CMPINDICES(8,8,8)) { @@ -331,7 +367,7 @@ ex color::eval(int level) const } else if (CMPINDICES(4,4,8)||CMPINDICES(5,5,8)||CMPINDICES(6,6,8)||CMPINDICES(7,7,8)) { return -1/(2*sqrt(numeric(3))); } - return exZERO(); + return _ex0(); } break; } @@ -345,31 +381,31 @@ ex color::eval(int level) const // protected -int color::compare_same_type(basic const & other) const +int color::compare_same_type(const basic & other) const { GINAC_ASSERT(other.tinfo() == TINFO_color); const color *o = static_cast(&other); if (type==o->type) { if (representation_label==o->representation_label) { - return indexed::compare_same_type(other); + return inherited::compare_same_type(other); } return representation_label < o->representation_label ? -1 : 1; } return type < o->type ? -1 : 1; } -bool color::is_equal_same_type(basic const & other) const +bool color::is_equal_same_type(const basic & other) const { GINAC_ASSERT(other.tinfo() == TINFO_color); const color *o = static_cast(&other); if (type!=o->type) return false; if (representation_label!=o->representation_label) return false; - return indexed::is_equal_same_type(other); + return inherited::is_equal_same_type(other); } #include -ex color::simplify_ncmul(exvector const & v) const +ex color::simplify_ncmul(const exvector & v) const { // simplifications: contract delta8_{a,b} where possible // sort delta8,f,d,T(rl=0),T(rl=1),...,ONE(rl=0),ONE(rl=1),... @@ -387,8 +423,8 @@ ex color::simplify_ncmul(exvector const & v) const if (is_ex_exactly_of_type(*it,color) && (ex_to_color(*it).type==color_delta8)) { color & d8=ex_to_nonconst_color(*it); GINAC_ASSERT(d8.seq.size()==2); - coloridx const & first_idx=ex_to_coloridx(d8.seq[0]); - coloridx const & second_idx=ex_to_coloridx(d8.seq[1]); + const coloridx & first_idx=ex_to_coloridx(d8.seq[0]); + const coloridx & second_idx=ex_to_coloridx(d8.seq[1]); // delta8_{a,a} should have been contracted in color::eval() GINAC_ASSERT((!first_idx.is_equal(second_idx))||(!first_idx.is_symbolic())); ex saved_delta8=*it; // save to restore it later @@ -403,7 +439,7 @@ ex color::simplify_ncmul(exvector const & v) const } else { // a contracted index should occur exactly twice GINAC_ASSERT(replacements==2); - *it=exONE(); + *it=_ex1(); something_changed=true; } } @@ -418,7 +454,7 @@ ex color::simplify_ncmul(exvector const & v) const } else { // a contracted index should occur exactly twice GINAC_ASSERT(replacements==2); - *it=exONE(); + *it=_ex1(); something_changed=true; } } @@ -438,9 +474,9 @@ ex color::simplify_ncmul(exvector const & v) const exvector delta8vec; exvector fvec; exvector dvec; - vector Tvecs; + exvectorvector Tvecs; Tvecs.resize(MAX_REPRESENTATION_LABELS); - vector ONEvecs; + exvectorvector ONEvecs; ONEvecs.resize(MAX_REPRESENTATION_LABELS); exvector unknownvec; @@ -452,10 +488,10 @@ ex color::simplify_ncmul(exvector const & v) const for (exvector::iterator it2=fvec.begin(); it2!=fvec.end(); ++it2) { GINAC_ASSERT(is_ex_exactly_of_type(*it1,color)); GINAC_ASSERT(is_ex_exactly_of_type(*it2,color)); - color const & col1=ex_to_color(*it1); - color const & col2=ex_to_color(*it2); + const color & col1=ex_to_color(*it1); + const color & col2=ex_to_color(*it2); exvector iv_intersect=idx_intersect(col1.seq,col2.seq); - if (iv_intersect.size()>=2) return exZERO(); + if (iv_intersect.size()>=2) return _ex0(); } } } @@ -466,19 +502,19 @@ ex color::simplify_ncmul(exvector const & v) const for (exvector::iterator it2=it1+1; it2!=dvec.end(); ++it2) { GINAC_ASSERT(is_ex_exactly_of_type(*it1,color)); GINAC_ASSERT(is_ex_exactly_of_type(*it2,color)); - color const & col1=ex_to_color(*it1); - color const & col2=ex_to_color(*it2); + const color & col1=ex_to_color(*it1); + const color & col2=ex_to_color(*it2); exvector iv_intersect=idx_intersect(col1.seq,col2.seq); if (iv_intersect.size()>=2) { if (iv_intersect.size()==3) { *it1=numeric(40)/numeric(3); - *it2=exONE(); + *it2=_ex1(); } else { int sig1, sig2; // unimportant, since symmetric ex idx1=permute_free_index_to_front(col1.seq,iv_intersect,false,&sig1); ex idx2=permute_free_index_to_front(col2.seq,iv_intersect,false,&sig2); *it1=numeric(5)/numeric(3)*color(color_delta8,idx1,idx2); - *it2=exONE(); + *it2=_ex1(); } return nonsimplified_ncmul(recombine_color_string( delta8vec,fvec,dvec,Tvecs,ONEvecs,unknownvec)); @@ -493,19 +529,19 @@ ex color::simplify_ncmul(exvector const & v) const for (exvector::iterator it2=it1+1; it2!=fvec.end(); ++it2) { GINAC_ASSERT(is_ex_exactly_of_type(*it1,color)); GINAC_ASSERT(is_ex_exactly_of_type(*it2,color)); - color const & col1=ex_to_color(*it1); - color const & col2=ex_to_color(*it2); + const color & col1=ex_to_color(*it1); + const color & col2=ex_to_color(*it2); exvector iv_intersect=idx_intersect(col1.seq,col2.seq); if (iv_intersect.size()>=2) { if (iv_intersect.size()==3) { *it1=numeric(24); - *it2=exONE(); + *it2=_ex1(); } else { int sig1, sig2; ex idx1=permute_free_index_to_front(col1.seq,iv_intersect,true,&sig1); ex idx2=permute_free_index_to_front(col2.seq,iv_intersect,true,&sig2); *it1=numeric(sig1*sig2*5)/numeric(3)*color(color_delta8,idx1,idx2); - *it2=exONE(); + *it2=_ex1(); } return nonsimplified_ncmul(recombine_color_string( delta8vec,fvec,dvec,Tvecs,ONEvecs,unknownvec)); @@ -528,7 +564,7 @@ ex color::simplify_ncmul(exvector const & v) const // d_{a,b,c} T_b T_c = 5/6 T_a for (exvector::iterator it2=dvec.begin(); it2!=dvec.end(); ++it2) { GINAC_ASSERT(is_ex_exactly_of_type(*it2,color)&&ex_to_color(*it2).type==color_d); - color const & dref=ex_to_color(*it2); + const color & dref=ex_to_color(*it2); exvector iv_intersect=idx_intersect(dref.seq,iv); if (iv_intersect.size()==2) { int sig; // unimportant, since symmetric @@ -544,7 +580,7 @@ ex color::simplify_ncmul(exvector const & v) const // f_{a,b,c} T_b T_c = 3/2 I T_a for (exvector::iterator it2=fvec.begin(); it2!=fvec.end(); ++it2) { GINAC_ASSERT(is_ex_exactly_of_type(*it2,color)&&ex_to_color(*it2).type==color_f); - color const & fref=ex_to_color(*it2); + const color & fref=ex_to_color(*it2); exvector iv_intersect=idx_intersect(fref.seq,iv); if (iv_intersect.size()==2) { int sig; @@ -576,7 +612,7 @@ ex color::simplify_ncmul(exvector const & v) const ONEvecs,unknownvec)); } -ex color::thisexprseq(exvector const & v) const +ex color::thisexprseq(const exvector & v) const { return color(type,v,representation_label); } @@ -616,46 +652,46 @@ bool color::all_of_type_coloridx(void) const ////////// const color some_color; -type_info const & typeid_color=typeid(some_color); +const type_info & typeid_color=typeid(some_color); ////////// // friend functions ////////// -color color_ONE(unsigned const rl) +color color_ONE(unsigned rl) { return color(color::color_ONE,rl); } -color color_T(ex const & a, unsigned const rl) +color color_T(const ex & a, unsigned rl) { return color(color::color_T,a,rl); } -color color_f(ex const & a, ex const & b, ex const & c) +color color_f(const ex & a, const ex & b, const ex & c) { return color(color::color_f,a,b,c); } -color color_d(ex const & a, ex const & b, ex const & c) +color color_d(const ex & a, const ex & b, const ex & c) { return color(color::color_d,a,b,c); } -ex color_h(ex const & a, ex const & b, ex const & c) +ex color_h(const ex & a, const ex & b, const ex & c) { return color(color::color_d,a,b,c)+I*color(color::color_f,a,b,c); } -color color_delta8(ex const & a, ex const & b) +color color_delta8(const ex & a, const ex & b) { return color(color::color_delta8,a,b); } -void split_color_string_in_parts(exvector const & v, exvector & delta8vec, +void split_color_string_in_parts(const exvector & v, exvector & delta8vec, exvector & fvec, exvector & dvec, - vector & Tvecs, - vector & ONEvecs, + exvectorvector & Tvecs, + exvectorvector & ONEvecs, exvector & unknownvec) { // if not all elements are of type color, put all Ts in unknownvec to @@ -702,8 +738,8 @@ void split_color_string_in_parts(exvector const & v, exvector & delta8vec, } exvector recombine_color_string(exvector & delta8vec, exvector & fvec, - exvector & dvec, vector & Tvecs, - vector & ONEvecs, exvector & unknownvec) + exvector & dvec, exvectorvector & Tvecs, + exvectorvector & ONEvecs, exvector & unknownvec) { unsigned sz=delta8vec.size()+fvec.size()+dvec.size()+unknownvec.size(); for (unsigned rl=0; rl Tvecs; + exvectorvector Tvecs; Tvecs.resize(MAX_REPRESENTATION_LABELS); - vector ONEvecs; + exvectorvector ONEvecs; ONEvecs.resize(MAX_REPRESENTATION_LABELS); exvector unknownvec; @@ -808,16 +844,16 @@ ex color_trace(exvector const & v, unsigned const rl) return nonsimplified_ncmul(v_rest); } -ex simplify_pure_color_string(ex const & e) +ex simplify_pure_color_string(const ex & e) { GINAC_ASSERT(is_ex_exactly_of_type(e,ncmul)); exvector delta8vec; exvector fvec; exvector dvec; - vector Tvecs; + exvectorvector Tvecs; Tvecs.resize(MAX_REPRESENTATION_LABELS); - vector ONEvecs; + exvectorvector ONEvecs; ONEvecs.resize(MAX_REPRESENTATION_LABELS); exvector unknownvec; @@ -836,20 +872,20 @@ ex simplify_pure_color_string(ex const & e) GINAC_ASSERT(is_ex_exactly_of_type(t2,color)&& (ex_to_color(t2).type==color::color_T)&& (ex_to_color(t2).seq.size()==1)); - coloridx const & idx1=ex_to_coloridx(ex_to_color(t1).seq[0]); - coloridx const & idx2=ex_to_coloridx(ex_to_color(t2).seq[0]); + const coloridx & idx1=ex_to_coloridx(ex_to_color(t1).seq[0]); + const coloridx & idx2=ex_to_coloridx(ex_to_color(t2).seq[0]); if (idx1.is_equal(idx2) && idx1.is_symbolic()) { exvector S; for (unsigned k=i+1; k