HepLib
Eps.cpp
Go to the documentation of this file.
1 
6 #include "HEP.h"
7 
8 namespace HepLib {
9 
10  //-----------------------------------------------------------
11  // Eps Class
12  //-----------------------------------------------------------
13  //GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(Eps, basic,print_func<print_dflt>(&Eps::print).print_func<FormFormat>(&Eps::form_print).print_func<FCFormat>(&Eps::fc_print))
14  GiNaC::registered_class_info & Eps::get_class_info_static() { return reg_info; }
16  Eps * Eps::duplicate() const { Eps * bp = new Eps(*this); bp->setflag(GiNaC::status_flags::dynallocated); return bp; }
17  void Eps::accept(GiNaC::visitor & v) const { if (visitor *p = dynamic_cast<visitor *>(&v)) p->visit(*this); else inherited::accept(v); }
18  const GiNaC::registered_class_info &Eps::get_class_info() const { return get_class_info_static(); }
19  GiNaC::registered_class_info &Eps::get_class_info() { return get_class_info_static(); }
20  const char *Eps::class_name() const { return get_class_info_static().options.get_name(); }
21  //GINAC_IMPLEMENT_REGISTERED_CLASS END
22 
26 
27  Eps::Eps(const Vector &x1, const Vector &x2, const Vector &x3, const Vector &x4) : pis{x1,x2,x3,x4} { }
28  Eps::Eps(const Vector &x1, const Vector &x2, const Vector &x3, const Index &x4) : pis{x1,x2,x3,x4} { }
29  Eps::Eps(const Vector &x1, const Vector &x2, const Index &x3, const Index &x4) : pis{x1,x2,x3,x4} { }
30  Eps::Eps(const Vector &x1, const Index &x2, const Index &x3, const Index &x4) : pis{x1,x2,x3,x4} { }
31  Eps::Eps(const Index &x1, const Index &x2, const Index &x3, const Index &x4) : pis{x1,x2,x3,x4} { }
32  Eps::Eps(vector<Vector> vs, vector<Index> is) {
33  pis.resize(vs.size()+is.size());
34  int i=0;
35  for(auto vi : vs) pis[i++] = vi;
36  for(auto ii : is) pis[i++] = ii;
37  }
38  Eps::Eps(const exvector & pis0) {
39  int n = pis0.size();
40  pis.resize(n);
41  for(int i=0; i<n; i++) pis[i] = pis0[i];
42  }
43 
44  int Eps::compare_same_type(const basic &other) const {
45  if(!is_a<Eps>(other)) throw Error("Eps::compare_same_type");
46  const Eps &o = static_cast<const Eps &>(other);
47  int n = pis.size();
48  int no = o.pis.size();
49  if(n!=no) return n>no ? 1 : -1;
50  for(int i=0; i<n; i++) {
51  auto c = pis[i].compare(o.pis[i]);
52  if(c!=0) return c;
53  }
54  return 0;
55  }
56 
57  bool Eps::is_equal_same_type(const basic & other) const {
58  if(!is_a<Eps>(other)) throw Error("Eps::is_equal_same_type");
59  const Eps &o = static_cast<const Eps &>(other);
60  int n = pis.size();
61  int no = o.pis.size();
62  if(n!=no) return false;
63  for(int i=0; i<n; i++) {
64  if(!pis[i].is_equal(o.pis[i])) return false;
65  }
66  return true;
67  }
68 
69  ex Eps::eval() const {
70  if(flags & status_flags::evaluated) return *this;
71  int n = pis.size();
72  if(n==4) {
73  bool ok = true;
74  int ii = 4;
75  for(int i=0; i<4; i++) {
76  if(!is_a<Vector>(pis[i]) && !is_a<Index>(pis[i])) ok = false;
77  else if(is_a<Vector>(pis[i]) && ii!=4) ok = false; // Vector after Index
78  else if(is_a<Index>(pis[i]) && ii==4) ii = i;
79  if(!ok) break;
80  }
81  if(!ok) return LC(pis[0],pis[1],pis[2],pis[3]);
82 
83  const ex* pis_a = pis.data();
84  if(isSorted(ii,pis_a) && isSorted(4-ii,pis_a+ii)) return this->hold();
85  else {
86  ex pis2[4];
87  for(int i=0; i<4; i++) pis2[i] = pis[i];
88  int ac1 = ACSort(ii,pis2);
89  int ac2 = ACSort(4-ii,pis2+ii);
90  if(ac1 * ac2==0) return 0;
91  return ac1 * ac2 * LC(pis2[0],pis2[1],pis2[2],pis2[3]);
92  }
93  } else return this->hold();
94  }
95 
96  void Eps::print(const print_dflt &c, unsigned level) const {
97  int n = pis.size();
98  c.s << "\u03B5" << "(";
99  for(int i=0; i<n-1; i++) c.s << pis[i] << ",";
100  c.s << pis[n-1] << ")";
101  }
102 
112  void Eps::form_print(const FormFormat &c, unsigned level) const {
113  int n = pis.size();
114  if(n==4) c << "(i_*"; // only multiple i for gamma5
115  c << "e_(";
116  for(int i=0; i<n-1; i++) c << pis[i] << ",";
117  c << pis[n-1] << ")";
118  if(n==4) c << ")";
119  }
120 
121  void Eps::fc_print(const FCFormat &c, unsigned level) const {
122  int n = pis.size();
123  if(n==4) {
124  c << "LCD[";
125  bool first = true;
126  for(int i=3; i>=0; i--) {
127  if(is_a<Vector>(pis[i]) && first) {
128  c << "][";
129  first = false;
130  }
131  c << pis[i];
132 
133  if(i==0) c << "]";
134  else if(!first || !is_a<Vector>(pis[i-1])) c << ",";
135  }
136  if(first) c << "[]";
137  }
138  }
139 
140  size_t Eps::nops() const { return pis.size(); }
141  ex Eps::op(size_t i) const {
142  return pis[i];
143  }
144  ex & Eps::let_op(size_t i) {
145  ensure_if_modifiable();
146  return pis[i];
147  }
148 
149  void Eps::archive(archive_node & n) const {
150  inherited::archive(n);
151  int nn = pis.size();
152  n.add_ex("size", nn);
153  for(int i=0; i<nn; i++) n.add_ex("pis"+to_string(i), pis[i]);
154  }
155 
156  void Eps::read_archive(const archive_node& n) {
157  inherited::read_archive(n);
158  ex nex;
159  n.find_ex("size", nex);
160  int nn = ex_to<numeric>(nex).to_int();
161  if(pis.size()!=nn) pis.resize(nn);
162  for(int i=0; i<nn; i++) {
163  n.find_ex("pis"+to_string(i), pis[i]);
164  }
165  }
166 
167  ex Eps::derivative(const symbol & s) const {
168  return 0;
169  }
170 
179  ex LC(ex pi1, ex pi2, ex pi3, ex pi4) {
180  bool isEps = true;
181  lst pis = lst {pi1, pi2, pi3, pi4};
182  for(auto pi : pis) {
183  if(!is_a<Vector>(pi) && !is_a<Index>(pi)) {
184  isEps = false;
185  break;
186  }
187  }
188 
189  if(isEps) {
190  vector<Vector> vs;
191  vector<Index> is;
192  ex sign = 1;
193  for(int i=0; i<4; i++) {
194  if(is_a<Vector>(pis.op(i))) {
195  vs.push_back(ex_to<Vector>(pis.op(i)));
196  sign *= pow(-1, is.size());
197  } else is.push_back(ex_to<Index>(pis.op(i)));
198  }
199  return sign*Eps(vs, is);
200  }
201 
202  for(int i=0; i<4; i++) {
203  auto pi = collect_lst(pis.op(i), [](const ex & e)->bool{return Index::has(e) || Vector::has(e);});
204  for(auto item : pi) { // check
205  if(!is_a<Vector>(item.op(1)) && !is_a<Index>(item.op(1))) {
206  cout << "pi = " << pi << endl;
207  throw Error("LC Error: there is no Index or Vector.");
208  }
209  }
210  pis.let_op(i) = pi;
211  }
212 
213  ex res = 0;
214  for(auto i0 : pis.op(0))
215  for(auto i1 : pis.op(1))
216  for(auto i2 : pis.op(2))
217  for(auto i3 : pis.op(3)) {
218  res += i0.op(0)*i1.op(0)*i2.op(0)*i3.op(0) * LC(i0.op(1), i1.op(1), i2.op(1), i3.op(1));
219  }
220  return res;
221  }
222 
223 }
224 
#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.
virtual ~visitor()
Definition: Eps.cpp:15
class for Levi-Civita object https://onlinelibrary.wiley.com/doi/pdf/10.1002/9783527630097....
Definition: HEP.h:386
const char * class_name() const override
Definition: Eps.cpp:20
ex eval() const override
Definition: Eps.cpp:69
int compare_same_type(const GiNaC::basic &other) const override
Definition: Eps.cpp:44
void fc_print(const FCFormat &c, unsigned level=0) const
Definition: Eps.cpp:121
bool is_equal_same_type(const basic &other) const override
Definition: Eps.cpp:57
ex op(size_t i) const override
Definition: Eps.cpp:141
void form_print(const FormFormat &c, unsigned level=0) const
Eps in FORM format https://onlinelibrary.wiley.com/doi/pdf/10.1002/9783527630097.app3 to make Tr(g5,...
Definition: Eps.cpp:112
Eps * duplicate() const override
Definition: Eps.cpp:16
ex derivative(const symbol &s) const override
Definition: Eps.cpp:167
void accept(GiNaC::visitor &v) const override
Definition: Eps.cpp:17
void print(const print_dflt &c, unsigned level=0) const
Definition: Eps.cpp:96
ex & let_op(size_t i) override
Definition: Eps.cpp:144
void archive(archive_node &n) const override
Definition: Eps.cpp:149
size_t nops() const override
Definition: Eps.cpp:140
static GiNaC::registered_class_info & get_class_info_static()
Definition: Eps.cpp:14
void read_archive(const archive_node &n) override
Definition: Eps.cpp:156
exvector pis
Definition: HEP.h:410
const GiNaC::registered_class_info & get_class_info() const override
Definition: Eps.cpp:18
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
class for vector object
Definition: HEP.h:149
HepLib namespace.
Definition: BASIC.cpp:17
bool isSorted(const lst &exs)
Definition: Functions.cpp:273
int ACSort(lst &exs)
Definition: Functions.cpp:289
const Symbol vs
lst collect_lst(ex const &expr_in, std::function< bool(const ex &)> has_func, int opt)
the collect function like Mathematica, reture the lst { {c1,v1}, {c2,v2}, ... }
Definition: BASIC.cpp:1222
ex LC(ex pi1, ex pi2, ex pi3, ex pi4)
function similar to LCD in FeynCalc
Definition: Eps.cpp:179