Documentation of MARTY
A Modern ARtificial Theoretical phYsicist
indexchain.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
24 #pragma once
25 
26 #include <string>
27 #include <map>
28 #include "gammaindex.h"
29 #include "momentumindex.h"
30 #include "sglfield.h"
31 #include "cslexpr.h"
32 
33 namespace sgl {
34 
36 
37  public:
38 
39  // static inline bool applyMatrixOrdering = false;
40 
41  IndexChain() = default;
42  IndexChain(IndexChain const &) = default;
43 
44  IndexChain(Field const &psi);
45 
46  IndexChain(
47  csl::Index const &t_a,
48  csl::Index const &t_b
49  );
50 
51  IndexChain(
52  GExpr const &mu,
53  csl::Index const &t_a,
54  csl::Index const &t_b
55  );
56 
57  IndexChain(
58  std::vector<GExpr> const &mu,
59  csl::Index const &t_a,
60  csl::Index const &t_b
61  );
62 
63  IndexChain(
64  Field const &t_a,
65  csl::Index const &t_b
66  );
67 
68  IndexChain(
69  GExpr const &mu,
70  Field const &t_a,
71  csl::Index const &t_b
72  );
73 
74  IndexChain(
75  std::vector<GExpr> const &mu,
76  Field const &t_a,
77  csl::Index const &t_b
78  );
79 
80  IndexChain(
81  csl::Index const &t_a,
82  Field const &t_b
83  );
84 
85  IndexChain(
86  GExpr const &mu,
87  csl::Index const &t_a,
88  Field const &t_b
89  );
90 
91  IndexChain(
92  std::vector<GExpr> const &mu,
93  csl::Index const &t_a,
94  Field const &t_b
95  );
96 
97  IndexChain(
98  Field const &t_a,
99  Field const &t_b
100  );
101 
102  IndexChain(
103  GExpr const &mu,
104  Field const &t_a,
105  Field const &t_b
106  );
107 
108  IndexChain(
109  std::vector<GExpr> const &mu,
110  Field const &t_a,
111  Field const &t_b
112  );
113 
114  bool isZero() const override;
115 
116  csl::Expr getFactor() const override;
117  GExpr getTerm() const override;
118 
119  std::shared_ptr<Field> getPsiL() const {
120  return psiL;
121  }
122  std::shared_ptr<Field> getPsiR() const {
123  return psiR;
124  }
125  std::pair<csl::Index, csl::Index> getBorderIndices() const {
126  return {a, b};
127  }
128 
129  bool isHappy() const;
130 
131  bool isReversed() const;
132 
133  bool isFierzFixed() const { return fierzFixed; }
134  void setFixFierz(bool value) { fierzFixed = value; }
135 
136  bool hasCommonIndex(IndexChain const &other) const;
137  GExpr mergeChain(IndexChain const &other) const;
138  GExpr mergeConjugateChain(IndexChain const &other) const;
139  bool hasPropertyWith(GExpr const &other) const override;
140  GExpr propertyWith(GExpr const &other) const override;
141 
142  bool contains(csl::Index const &) const override;
143  void replace(csl::Index const&, csl::Index const&) override;
144 
145  GExpr copy() const override;
146  GExpr refresh() const override;
147 
148  csl::Expr toCSL(TensorSet const &tensors) const override;
149 
150  std::pair<GExpr, IndexChain> cut(
151  size_t pos,
152  size_t len = 1
153  ) const;
154 
155  void erase(size_t pos, size_t len);
156 
157  GExpr applyEOM(MomentumIndex const &p) const;
158 
159  GExpr simplify() override;
160 
161  GExpr calculateTrace() const;
162  GExpr calculateStandardTrace() const;
163  GExpr calculateChiralTrace() const;
164 
165  std::optional<GExpr> reduceStep() const;
166 
167  std::optional<GExpr> reduceMomenta(
168  MomentumIndex const &p1,
169  MomentumIndex const &p2
170  ) const;
171 
172  static GExpr trace(
173  IndexChain A,
174  IndexChain C,
175  IndexChain B,
176  IndexChain D
177  );
178 
179  GExpr applyGeneralFierz(
180  IndexChain const &other,
181  bool chiral = true
182  ) const;
183  GExpr applyGeneralFierzTwice(
184  IndexChain const &other,
185  bool chiral = true
186  ) const;
187 
188  void print(std::ostream &out) const override;
189 
190  bool isTrace() const { return a == b && !(psiL || psiR); }
191 
192  std::optional<GExpr> checkGammaAndConjugation() const;
193 
194  static csl::Index easyIndex(int i) {
195  if (auto pos = m_easyIndex.find(i); pos != m_easyIndex.end())
196  return pos->second;
197  m_easyIndex[i] = diracSpace->generateIndex();
198  return m_easyIndex[i];
199  }
200 
201  GExpr identityFactor(GammaIndex const &other) const;
202  GExpr factor(GammaIndex const &A, GammaIndex const &B) const;
203  GExpr getContributionTo(IndexChain const &other) const;
204 
205  std::pair<int, IndexChain> conjugated() const;
206 
207  friend GExpr momentumGammaContraction(
209  csl::Index const&, csl::Index const&, size_t, size_t
210  );
211 
212  GExpr moveIndex(size_t init, size_t target) const;
213 
214  private:
215 
216  bool hasContraction(size_t i, size_t j) const;
217  std::optional<std::pair<size_t, size_t>> firstMove() const;
218  std::optional<std::pair<size_t, size_t>> lastMove() const;
219 
220  GExpr contraction(size_t i) const;
221 
222  public:
223 
224  static bool isDelta(GExpr const &gamma) {
225  return dynamic_cast<GammaIndex const*>(gamma.get())->isDelta();
226  }
227  static bool isGammaMu(GExpr const &gamma) {
228  return dynamic_cast<GammaIndex const*>(gamma.get())->isGammaMu();
229  }
230  static bool isSigma(GExpr const &gamma) {
231  return dynamic_cast<GammaIndex const*>(gamma.get())->isSigma();
232  }
233  static bool isChiral(GExpr const &gamma) {
234  return isGamma5(gamma) || isP_L(gamma) || isP_R(gamma);
235  }
236  static bool isGamma5(GExpr const &gamma) {
237  return dynamic_cast<GammaIndex const*>(gamma.get())->isGamma5();
238  }
239  static bool isProjector(GExpr const &gamma) {
240  return isP_L(gamma) || isP_R(gamma);
241  }
242  static bool isP_L(GExpr const &gamma) {
243  return dynamic_cast<GammaIndex const*>(gamma.get())->isP_L();
244  }
245  static bool isP_R(GExpr const &gamma) {
246  return dynamic_cast<GammaIndex const*>(gamma.get())->isP_R();
247  }
248  static bool isC(GExpr const &gamma) {
249  return dynamic_cast<GammaIndex const*>(gamma.get())->isC();
250  }
251 
252  static GExpr CMatrix();
253  static GExpr Id();
254  static GExpr gamma5();
255  static GExpr P_L();
256  static GExpr P_R();
257 
258  private:
259 
260  csl::Index a;
261  csl::Index b;
262  std::shared_ptr<Field> psiL { nullptr };
263  std::shared_ptr<Field> psiR { nullptr };
264  bool fierzFixed = false;
265  };
266 
267  template<class ...Args>
268  GExpr indexchain_s(Args &&...args) {
269  auto chain = std::make_shared<IndexChain>(std::forward<Args>(args)...);
270  if (chain->isZero())
271  return cslexpr_s(CSL_0);
272  auto factor = chain->getFactor();
273  if (factor != CSL_1) {
274  auto term = std::dynamic_pointer_cast<IndexChain>(chain->getTerm());
275  auto opt_chain = term->checkGammaAndConjugation();
276  return factor * opt_chain.value_or(term);
277  }
278  return chain->checkGammaAndConjugation().value_or(chain);
279  }
280 
281  template<class ...Args>
282  GExpr indexchain_s(
283  std::initializer_list<GExpr> gammas,
284  Args &&...args) {
285  return indexchain_s(
286  std::vector<GExpr>(gammas.begin(), gammas.end()),
287  std::forward<Args>(args)...
288  );
289  }
290 
291  GExpr indexchain_s(
292  int a,
293  int b
294  );
295 
296  GExpr indexchain_s(
297  const char mu[],
298  int a,
299  int b
300  );
301 
302  GExpr indexchain_s(
303  std::vector<std::string> const &mu,
304  int a,
305  int b
306  );
307 }
Definition: tensorset.h:30
Definition: momentumindex.h:31
Definition: indexchain.h:35
csl::Expr mu
mu parameter.
Definition: MSSM.h:83
Definition: abstractgammasym.h:87
Definition: abstractgammasym.h:32
SGL object representing a CSL Expression, sgl::CSLExpr.
Definition: multifunction.h:29
SGL symbolic expression representing quantum fields, in particular external spinors.
Definition: sglfield.h:36
sgl::MomentumIndex, symbolic representation of of momentum in SGL.
Definition: gammaindex.h:36
Index generateIndex(const std::string &name) const
Gamma matrices symbolic expression for SGL.