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