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_1567, unsigned _rl) : pi(int_1567), rl(_rl) { }
88 DGamma::DGamma(const Vector &p, unsigned _rl) : pi(p), rl(_rl) { }
89 DGamma::DGamma(const Index &i, unsigned _rl) : pi(i), rl(_rl) { }
90 DGamma::DGamma(const DGamma &g, unsigned _rl) : pi(g.pi), rl(_rl) { }
91
92 size_t DGamma::nops() const { return 2; }
93 ex DGamma::op(size_t i) const {
94 if(i==0) return pi;
95 else if(i==1) return rl;
96 return 0;
97 }
98
99 ex & DGamma::let_op(size_t i) {
100 static ex ex_rl = numeric(rl);
101 ensure_if_modifiable();
102 if(i==0) return pi;
103 else return ex_rl;
104 }
105
106 ex DGamma::eval() const {
107 if(flags & status_flags::evaluated) return *this;
108 else if(is_zero(pi) || is_zero(pi-1) || is_zero(pi-5) || is_zero(pi-6) || is_zero(pi-7)) return this->hold();
109 else if(!is_a<Vector>(pi) && !is_a<Index>(pi)) return GAS(pi,rl);
110 else return this->hold();
111 }
112
113 void DGamma::print(const print_dflt &c, unsigned level) const {
114 if(is_zero(pi-1)) {
115 c.s << "\u0130";
116 return;
117 } else if(is_zero(pi-5) || is_zero(pi-6) || is_zero(pi-7)) {
118 c.s << "\u0263";
119 if(is_a<numeric>(pi)) c.s << pi;
120 else c.s << "." << pi;
121 return;
122 }
123 c.s << "(" << "\u0263";
124 if(is_a<numeric>(pi)) c.s << pi;
125 else c.s << "." << pi;
126 c.s << ")";
127 }
128
129 void DGamma::form_print(const FormFormat &c, unsigned level) const {
130 if(!is_a<numeric>(pi)) c << "g_(" << rl << "," << pi << ")";
131 else if(is_zero(pi-1)) c << "gi_(" << rl << ")";
132 else if(is_zero(pi-5)) c << "g5_(" << rl << ")";
133 else if(is_zero(pi-6)) c << "g6_(" << rl << ")";
134 else if(is_zero(pi-7)) c << "g7_(" << rl << ")";
135 else throw Error("DGamma::form_print unexpected region.");
136 }
137
138 void DGamma::fc_print(const FCFormat &c, unsigned level) const {
139 if(is_zero(pi-1)) {
140 c << "1";
141 return;
142 }
143 if(is_a<Vector>(pi)) c << "GSD";
144 else c << "GAD";
145 c << "[" << pi << "]";
146 }
147
148 void DGamma::archive(archive_node & n) const {
149 inherited::archive(n);
150 n.add_ex("pi", pi);
151 n.add_unsigned("rl", rl);
152 }
153
154 void DGamma::read_archive(const archive_node& n) {
155 inherited::read_archive(n);
156 n.find_unsigned("rl", rl);
157 n.find_ex("pi", pi);
158 }
159
160 ex DGamma::derivative(const symbol & s) const {
161 return 0;
162 }
163
164 ex DGamma::conjugate() const {
165 if(is_a<Index>(pi) || is_a<Vector>(pi)) return *this;
166 else if(is_zero(pi-5)) return (-1)*DGamma(5, rl);
167 else if(is_zero(pi-6)) return DGamma(7, rl);
168 else if(is_zero(pi-7)) return DGamma(6, rl);
169 else if(is_zero(pi-1)) return DGamma(1, rl);
170 throw Error("invalid Dirac Gamma Found.");
171 }
172
173 ex DGamma::sigma(const ex & mu, const ex & nu) {
174 return I/2 * (GAS(mu)*GAS(nu)-GAS(nu)*GAS(mu));
175 }
176
177 ex DGamma::G5Eps(int i, int rl) {
178 Index a("g5Idx"+to_string(i));
179 Index b("g5Idx"+to_string(i+1));
180 Index c("g5Idx"+to_string(i+2));
181 Index d("g5Idx"+to_string(i+3));
182 return -I/factorial(4) * LC(a,b,c,d) * GAS(a,rl)*GAS(b,rl)*GAS(c,rl)*GAS(d,rl);
183 }
184
185 //-----------------------------------------------------------
186 // TR/GAS functions
187 //-----------------------------------------------------------
188 namespace {
189 void TR_form_print(const ex &arg, const print_context &c0) {
190 auto c = static_cast<const FormFormat &>(c0);
191 c << "(" << arg << ")";
192 }
193 void TR_fc_print(const ex &arg, const print_context &c0) {
194 auto c = static_cast<const FCFormat &>(c0);
195 c << "DiracTrace[" << arg << "]";
196 }
197 ex tr_conj(const ex & e) {
198 return TR(e.conjugate());
199 }
200
201 void TTR_form_print(const ex &arg, const print_context &c0) {
202 auto c = static_cast<const FormFormat &>(c0);
203 if(!is_a<lst>(arg)) c << "TTR(" << arg << ")";
204 else {
205 bool first = true;
206 for(auto item : arg) {
207 if(first) { first=false; c << "TTR(" << item; }
208 else c << "," << item;
209 }
210 c << ")";
211 }
212 }
213 void TTR_fc_print(const ex &arg, const print_context &c0) {
214 auto c = static_cast<const FCFormat &>(c0);
215 if(!is_a<lst>(arg)) c << "SUNTrace[SUNT[" << arg << "]]";
216 else {
217 bool first = true;
218 for(auto item : arg) {
219 if(first) { first=false; c << "SUNTrace[SUNT[" << item; }
220 else c << "," << item;
221 }
222 c << "]]";
223 }
224 }
225 ex ttr_conj(const ex & e) {
226 lst argv;
227 if(!is_a<lst>(e)) return TTR(e);
228 else argv = ex_to<lst>(e);
229 lst as;
230 for(auto it=argv.rbegin(); it!=argv.rend(); ++it) as.append(*it);
231 return TTR(as);
232 }
233 }
234
235 REGISTER_FUNCTION(TR, do_not_evalf_params().
236 conjugate_func(tr_conj).
237 print_func<FormFormat>(&TR_form_print).
238 print_func<FCFormat>(&TR_fc_print).
239 set_return_type(return_types::commutative).
240 expl_derivative_func(expl_TR_diff)
241 );
242
243 REGISTER_FUNCTION(TTR, do_not_evalf_params().
244 conjugate_func(ttr_conj).
245 print_func<FormFormat>(&TTR_form_print).
246 print_func<FCFormat>(&TTR_fc_print)
247 );
248
249 REGISTER_FUNCTION(HF, do_not_evalf_params());
250
257 ex GAS(const ex &expr, unsigned rl) {
258 if(is_zero(expr)) return 0;
259 else if(is_zero(expr-1)) return DGamma(1,rl);
260 else if(is_zero(expr-5)) return DGamma(5,rl);
261 else if(is_zero(expr-6)) return DGamma(6,rl);
262 else if(is_zero(expr-7)) return DGamma(7,rl);
263
264 ex tmp = expand(expr);
265 lst ex_lst;
266 if(is_a<add>(tmp)) {
267 for(auto item : tmp) ex_lst.append(item);
268 } else ex_lst.append(tmp);
269 ex res = 0;
270 for(auto item : ex_lst) {
271 lst mul_lst;
272 if(is_a<mul>(item)) {
273 for(auto ii : item) mul_lst.append(ii);
274 } else mul_lst.append(item);
275 ex c=1, g=1;
276 for(auto ii : mul_lst) {
277 if(is_a<Vector>(ii)) {
278 if(is_a<DGamma>(g)) throw Error("Something Wrong with GAS @1, g="+ex2str(g));
279 g = DGamma(ex_to<Vector>(ii),rl);
280 } else if(is_a<Index>(ii)) {
281 if(is_a<DGamma>(g)) throw Error("Something Wrong with GAS @2, g="+ex2str(g));
282 g = DGamma(ex_to<Index>(ii),rl);
283 } else {
284 c *= ii;
285 }
286 }
287 if(!is_a<DGamma>(g)) throw Error("Something Wrong with GAS @3, g="+ex2str(g));
288 res += c * g;
289 }
290 return res;
291 }
292
293
294
295}
296
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:106
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
ex derivative(const symbol &s) const override
Definition DGamma.cpp:160
void archive(archive_node &n) const override
Definition DGamma.cpp:148
void form_print(const FormFormat &c, unsigned level=0) const
Definition DGamma.cpp:129
void accept(GiNaC::visitor &v) const override
Definition DGamma.cpp:49
ex conjugate() const override
Definition DGamma.cpp:164
static GiNaC::registered_class_info & get_class_info_static()
Definition DGamma.cpp:46
void read_archive(const archive_node &n) override
Definition DGamma.cpp:154
static ex sigma(const ex &mu, const ex &nu)
Definition DGamma.cpp:173
size_t nops() const override
Definition DGamma.cpp:92
ex op(size_t i) const override
Definition DGamma.cpp:93
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:113
static ex G5Eps(int i=0, int rl=0)
Definition DGamma.cpp:177
static bool has(const ex &e)
void fc_print(const FCFormat &c, unsigned level=0) const
Definition DGamma.cpp:138
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
DGamma * duplicate() const override
Definition DGamma.cpp:48
ex & let_op(size_t i) override
Definition DGamma.cpp:99
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:257
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:1002
ex LC(ex pi1, ex pi2, ex pi3, ex pi4)
function similar to LCD in FeynCalc
Definition Eps.cpp:179