HepLib
Loading...
Searching...
No Matches
DGamma.cpp
Go to the documentation of this file.
1
6#include "HEP.h"
7
8namespace HepLib {
9
10 static ex expl_TR_diff2(const ex & arg, const symbol & s) {
11 auto ret = arg.diff(s);
12 if(!is_a<add>(ret)) ret = lst{ret};
13 ex res = 0;
14 for(auto item : ret) {
15 if(!is_a<mul>(item)) res += TR(item);
16 else {
17 ex c=1; ex v=1;
18 for(auto it : item) {
19 if(!Index::has(it) && !DGamma::has(it)) c *= it;
20 else v *= it;
21 }
22 res += c * TR(v);
23 }
24 }
25 return res;
26 }
27
28 static ex expl_TR_diff(const ex & arg, const symbol & s) {
29 auto ret = arg.diff(s);
30 auto nd = numer_denom(ret.normal());
31 auto num = collect_common_factors(nd.op(0));
32 if(!is_a<mul>(num)) return TR(num)/nd.op(1);
33 ex c=1;
34 ex v=1;
35 for(auto it : num) {
36 if(!Index::has(it) && !DGamma::has(it)) c *= it;
37 else v *= it;
38 }
39 return c*TR(v)/nd.op(1);
40 }
41
42 //-----------------------------------------------------------
43 // DGamma Class
44 //-----------------------------------------------------------
45 //GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(DGamma, basic,print_func<print_dflt>(&DGamma::print).print_func<FormFormat>(&DGamma::form_print).print_func<FCFormat>(&DGamma::fc_print))
46 GiNaC::registered_class_info & DGamma::get_class_info_static() { return reg_info; }
48 DGamma * DGamma::duplicate() const { DGamma * bp = new DGamma(*this); bp->setflag(GiNaC::status_flags::dynallocated); return bp; }
49 void DGamma::accept(GiNaC::visitor & v) const { if (visitor *p = dynamic_cast<visitor *>(&v)) p->visit(*this); else inherited::accept(v); }
50 const GiNaC::registered_class_info &DGamma::get_class_info() const { return get_class_info_static(); }
51 GiNaC::registered_class_info &DGamma::get_class_info() { return get_class_info_static(); }
52 const char *DGamma::class_name() const { return get_class_info_static().options.get_name(); }
53 //GINAC_IMPLEMENT_REGISTERED_CLASS END
54
58
59 return_type_t DGamma::return_type_tinfo() const {
60 return make_return_type_t<clifford>(rl);
61 //return make_return_type_t<DGamma>(rl);
62 }
63
64 bool DGamma::match_same_type(const basic & other) const {
65 const DGamma &o = static_cast<const DGamma &>(other);
66 return rl == o.rl;
67 }
68
69 unsigned DGamma::get_rl() {
70 return rl;
71 }
72
73 int DGamma::compare_same_type(const basic &other) const {
74 if(!is_a<DGamma>(other)) throw Error("DGamma::compare_same_type");
75 const DGamma &o = static_cast<const DGamma &>(other);
76 if (rl != o.rl) return rl < o.rl ? -1 : 1;
77 return pi.compare(o.pi);
78 }
79
80 bool DGamma::is_equal_same_type(const basic & other) const {
81 if(!is_a<DGamma>(other)) throw Error("DGamma::is_equal_same_type");
82 const DGamma &o = static_cast<const DGamma &>(other);
83 if (rl != o.rl) return false;
84 return pi.is_equal(o.pi);
85 }
86
87 DGamma::DGamma(int int_1567c, unsigned _rl) : pi(int_1567c), rl(_rl) {
88 if(int_1567c==int('C')) pi = int('c');
89 if(pi!=1 && pi!=5 && pi!=6 && pi!=7 && pi!=int('c')) throw Error("1/5/6/7/'c'/'C' only supported in DGamma.");
90 }
91 DGamma::DGamma(const Vector &p, unsigned _rl) : pi(p), rl(_rl) { }
92 DGamma::DGamma(const Index &i, unsigned _rl) : pi(i), rl(_rl) { }
93 DGamma::DGamma(const DGamma &g, unsigned _rl) : pi(g.pi), rl(_rl) { }
94
95 size_t DGamma::nops() const { return 2; }
96 ex DGamma::op(size_t i) const {
97 if(i==0) return pi;
98 else if(i==1) return rl;
99 return 0;
100 }
101
102 ex & DGamma::let_op(size_t i) {
103 static ex ex_rl = numeric(rl);
104 ensure_if_modifiable();
105 if(i==0) return pi;
106 else return ex_rl;
107 }
108
109 ex DGamma::eval() const {
110 if(flags & status_flags::evaluated) return *this;
111 else if(is_zero(pi-int('C'))) return GAS(int('c'), rl);
112 else if(is_zero(pi) || is_zero(pi-1) || is_zero(pi-5) || is_zero(pi-6) || is_zero(pi-7) || is_zero(pi-int('c'))) return this->hold();
113 else if(!is_a<Vector>(pi) && !is_a<Index>(pi)) return GAS(pi,rl);
114 else return this->hold();
115 }
116
117 void DGamma::print(const print_dflt &c, unsigned level) const {
118 if(is_zero(pi-1)) {
119 c.s << "\u0130";
120 if(isTr) c.s << "\u1D40";
121 return;
122 } else if(is_zero(pi-5) || is_zero(pi-6) || is_zero(pi-7)) {
123 c.s << "\u0263";
124 if(isTr) c.s << "\u1D40";
125 if(is_a<numeric>(pi)) c.s << pi;
126 else c.s << "." << pi;
127 return;
128 } else if(is_zero(pi-int('c')) || is_zero(pi-int('C'))) {
129 c.s << "C";
130 if(isTr) c.s << "\u1D40";
131 return;
132 }
133 c.s << "(" << "\u0263";
134 if(isTr) c.s << "\u1D40";
135 if(is_a<numeric>(pi)) c.s << pi;
136 else c.s << "." << pi;
137 c.s << ")";
138 }
139
140 void DGamma::form_print(const FormFormat &c, unsigned level) const {
141 if(isTr) throw Error("Transposed not supported in DGamma::form_print.");
142 if(!is_a<numeric>(pi)) c << "g_(" << rl << "," << pi << ")";
143 else if(is_zero(pi-1)) c << "gi_(" << rl << ")";
144 else if(is_zero(pi-5)) c << "g5_(" << rl << ")";
145 else if(is_zero(pi-6)) c << "g6_(" << rl << ")";
146 else if(is_zero(pi-7)) c << "g7_(" << rl << ")";
147 else if(is_zero(pi-int('c'))) throw Error("C not supported @ DGamma::form_print.");
148 else throw Error("DGamma::form_print unexpected region.");
149 }
150
151 void DGamma::fc_print(const FCFormat &c, unsigned level) const {
152 if(is_zero(pi-1)) {
153 c << "1";
154 return;
155 } else if(is_zero(pi-int('c'))) {
156 if(isTr) c << "Transpose@";
157 c << "ChargeConjugationMatrix";
158 return;
159 }
160 if(isTr) c << "Transpose@";
161 if(is_a<Vector>(pi)) c << "GSD";
162 else c << "GAD";
163 c << "[" << pi << "]";
164 }
165
166 void DGamma::archive(archive_node & n) const {
167 inherited::archive(n);
168 n.add_ex("pi", pi);
169 n.add_unsigned("rl", rl);
170 n.add_unsigned("tr", isTr ? 1 : 0);
171 }
172
173 void DGamma::read_archive(const archive_node& n) {
174 inherited::read_archive(n);
175 n.find_unsigned("rl", rl);
176 n.find_ex("pi", pi);
177 unsigned tr = 0;
178 n.find_unsigned("rl", rl);("tr", tr);
179 if(tr>0) isTr = true;
180 else isTr = false;
181 }
182
183 ex DGamma::derivative(const symbol & s) const {
184 return 0;
185 }
186
187 ex DGamma::conjugate() const { // refers to g^0 . g^\dag . g^0
188 if(is_a<Index>(pi) || is_a<Vector>(pi)) return *this;
189 else if(is_zero(pi-5)) return (-1)*DGamma(5, rl);
190 else if(is_zero(pi-6)) return DGamma(7, rl);
191 else if(is_zero(pi-7)) return DGamma(6, rl);
192 else if(is_zero(pi-1)) return DGamma(1, rl);
193 else if(is_zero(pi-int('c'))) return DGamma(int('c'), rl);
194 throw Error("invalid Dirac Gamma Found.");
195 }
196
197 ex DGamma::sigma(const ex & mu, const ex & nu) {
198 return I/2 * (GAS(mu)*GAS(nu)-GAS(nu)*GAS(mu));
199 }
200
201 ex DGamma::G5Eps(int i, int rl) {
202 Index a("g5Idx"+to_string(i));
203 Index b("g5Idx"+to_string(i+1));
204 Index c("g5Idx"+to_string(i+2));
205 Index d("g5Idx"+to_string(i+3));
206 return -I/factorial(4) * LC(a,b,c,d) * GAS(a,rl)*GAS(b,rl)*GAS(c,rl)*GAS(d,rl);
207 }
208
209 //-----------------------------------------------------------
210 // TR/GAS functions
211 //-----------------------------------------------------------
212 namespace {
213 void TR_form_print(const ex &arg, const print_context &c0) {
214 auto c = static_cast<const FormFormat &>(c0);
215 c << "(" << arg << ")";
216 }
217 void TR_fc_print(const ex &arg, const print_context &c0) {
218 auto c = static_cast<const FCFormat &>(c0);
219 c << "DiracTrace[" << arg << "]";
220 }
221 ex tr_conj(const ex & e) {
222 return TR(e.conjugate());
223 }
224
225 void TTR_form_print(const ex &arg, const print_context &c0) {
226 auto c = static_cast<const FormFormat &>(c0);
227 if(!is_a<lst>(arg)) c << "TTR(" << arg << ")";
228 else {
229 bool first = true;
230 for(auto item : arg) {
231 if(first) { first=false; c << "TTR(" << item; }
232 else c << "," << item;
233 }
234 c << ")";
235 }
236 }
237 void TTR_fc_print(const ex &arg, const print_context &c0) {
238 auto c = static_cast<const FCFormat &>(c0);
239 if(!is_a<lst>(arg)) c << "SUNTrace[SUNT[" << arg << "]]";
240 else {
241 bool first = true;
242 for(auto item : arg) {
243 if(first) { first=false; c << "SUNTrace[SUNT[" << item; }
244 else c << "," << item;
245 }
246 c << "]]";
247 }
248 }
249 ex ttr_conj(const ex & e) {
250 lst argv;
251 if(!is_a<lst>(e)) return TTR(e);
252 else argv = ex_to<lst>(e);
253 lst as;
254 for(auto it=argv.rbegin(); it!=argv.rend(); ++it) as.append(*it);
255 return TTR(as);
256 }
257 }
258
259 REGISTER_FUNCTION(TR, do_not_evalf_params().
260 conjugate_func(tr_conj).
261 print_func<FormFormat>(&TR_form_print).
262 print_func<FCFormat>(&TR_fc_print).
263 set_return_type(return_types::commutative).
264 expl_derivative_func(expl_TR_diff)
265 );
266
267 REGISTER_FUNCTION(TTR, do_not_evalf_params().
268 conjugate_func(ttr_conj).
269 print_func<FormFormat>(&TTR_form_print).
270 print_func<FCFormat>(&TTR_fc_print)
271 );
272
273 REGISTER_FUNCTION(HF, do_not_evalf_params());
274
281 ex GAS(const ex &expr, unsigned rl) {
282 if(is_zero(expr)) return 0;
283 else if(is_zero(expr-1)) return DGamma(1,rl);
284 else if(is_zero(expr-5)) return DGamma(5,rl);
285 else if(is_zero(expr-6)) return DGamma(6,rl);
286 else if(is_zero(expr-7)) return DGamma(7,rl);
287 else if(is_zero(expr-int('c')) || is_zero(expr-int('C'))) return DGamma(int('c'),rl);
288
289 ex tmp = expand(expr);
290 lst ex_lst;
291 if(is_a<add>(tmp)) {
292 for(auto item : tmp) ex_lst.append(item);
293 } else ex_lst.append(tmp);
294 ex res = 0;
295 for(auto item : ex_lst) {
296 lst mul_lst;
297 if(is_a<mul>(item)) {
298 for(auto ii : item) mul_lst.append(ii);
299 } else mul_lst.append(item);
300 ex c=1, g=1;
301 for(auto ii : mul_lst) {
302 if(is_a<Vector>(ii)) {
303 if(is_a<DGamma>(g)) throw Error("Something Wrong with GAS @1, g="+ex2str(g));
304 g = DGamma(ex_to<Vector>(ii),rl);
305 } else if(is_a<Index>(ii)) {
306 if(is_a<DGamma>(g)) throw Error("Something Wrong with GAS @2, g="+ex2str(g));
307 g = DGamma(ex_to<Index>(ii),rl);
308 } else {
309 c *= ii;
310 }
311 }
312 if(!is_a<DGamma>(g)) throw Error("Something Wrong with GAS @3, g="+ex2str(g)+", in="+ex2str(expr));
313 res += c * g;
314 }
315 return res;
316 }
317
324 ex GAS(const initializer_list<ex> & expr_lst, unsigned rl) {
325 ex res = 1;
326 for(auto item : expr_lst) res *= GAS(item);
327 if(res.is_equal(1)) res = GAS(1);
328 return res;
329 }
330
331
332}
333
int * a
#define IMPLEMENT_HAS(classname)
Definition BASIC.h:24
#define DEFAULT_CTOR(classname)
Definition BASIC.h:21
#define IMPLEMENT_ALL(classname)
Definition BASIC.h:30
HEP header file.
class for Dirac Gamma object
Definition HEP.h:437
ex eval() const override
Definition DGamma.cpp:109
bool match_same_type(const basic &other) const override
Definition DGamma.cpp:64
return_type_t return_type_tinfo() const override
Definition DGamma.cpp:59
static ex I
Definition HEP.h:485
ex derivative(const symbol &s) const override
Definition DGamma.cpp:183
void archive(archive_node &n) const override
Definition DGamma.cpp:166
void form_print(const FormFormat &c, unsigned level=0) const
Definition DGamma.cpp:140
void accept(GiNaC::visitor &v) const override
Definition DGamma.cpp:49
ex conjugate() const override
Definition DGamma.cpp:187
static GiNaC::registered_class_info & get_class_info_static()
Definition DGamma.cpp:46
void read_archive(const archive_node &n) override
Definition DGamma.cpp:173
static ex sigma(const ex &mu, const ex &nu)
Definition DGamma.cpp:197
size_t nops() const override
Definition DGamma.cpp:95
ex op(size_t i) const override
Definition DGamma.cpp:96
int compare_same_type(const GiNaC::basic &other) const override
Definition DGamma.cpp:73
void print(const print_dflt &c, unsigned level=0) const
Definition DGamma.cpp:117
static ex G5Eps(int i=0, int rl=0)
Definition DGamma.cpp:201
static bool has(const ex &e)
void fc_print(const FCFormat &c, unsigned level=0) const
Definition DGamma.cpp:151
const GiNaC::registered_class_info & get_class_info() const override
Definition DGamma.cpp:50
bool is_equal_same_type(const basic &other) const override
Definition DGamma.cpp:80
bool isTr
Definition HEP.h:463
DGamma * duplicate() const override
Definition DGamma.cpp:48
ex & let_op(size_t i) override
Definition DGamma.cpp:102
unsigned rl
Definition HEP.h:462
unsigned get_rl()
Definition DGamma.cpp:69
const char * class_name() const override
Definition DGamma.cpp:52
class used to wrap error message
Definition BASIC.h:242
class for FCFormat Output
Definition HEP.h:71
class for FormFormat Output
Definition HEP.h:44
class for index object
Definition HEP.h:104
static bool has(const ex &e)
class for vector object
Definition HEP.h:149
HepLib namespace.
Definition BASIC.cpp:17
ex GAS(const ex &expr, unsigned rl)
function similar to GAD/GSD in FeynClac
Definition DGamma.cpp:281
const Symbol d
const Symbol mu
const Symbol as
string ex2str(const ex &expr)
convert ex to output string, the defalut printer format will be used
Definition BASIC.cpp:715
REGISTER_FUNCTION(GMat, do_not_evalf_params().print_func< FCFormat >(&GMat_fc_print).conjugate_func(mat_conj).set_return_type(return_types::commutative)) bool IsZero(const ex &e)
Definition Basic.cpp:1125
ex LC(ex pi1, ex pi2, ex pi3, ex pi4)
function similar to LCD in FeynCalc
Definition Eps.cpp:179