Documentation of CSL
libraryexpander.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 
23 #ifndef CSL_LIBRARY_EXPANDER_H_INCLUDED
24 #define CSL_LIBRARY_EXPANDER_H_INCLUDED
25 
26 #include "abstract.h"
27 #include "numerical.h"
28 #include "index.h"
29 #include "space.h"
30 
31 namespace csl {
32 
33 struct Structure;
35 
36 public:
37 
38  static void apply(
39  Expr &iprod,
40  csl::Space const *space = &csl::Minkowski
41  );
42 
43 private:
44 
45  static bool expand(
46  Expr &iprod,
47  csl::Space const *space
48  );
49 
50  static bool toExpand(
51  Expr const &term,
52  csl::Space const *space
53  );
54 
55  static Structure parseTerm(
56  Expr const &iprod,
57  csl::Space const *space
58  );
59 
60  static std::vector<Structure> parse(
61  Expr const &isum,
62  csl::Space const *space
63  );
64 
65  static size_t nCommonIndices(
66  Structure const &s1,
67  Structure const &s2
68  );
69 
70  static void merge(
71  std::vector<Structure> &A,
72  std::vector<Structure> const &B
73  );
74 
75  static std::vector<Structure> merge(
76  std::vector<std::vector<Structure>> &init,
77  csl::Space const *space
78  );
79 
80  static Expr toExpr(
81  Structure const &init,
82  csl::Space const *space
83  );
84 
85  static Expr toExpr(
86  std::vector<Structure> const &init,
87  csl::Space const *space
88  );
89 };
90 
91 struct Structure {
92 
93  struct ipair {
94 
95  private:
96  csl::Index first;
97  csl::Index second;
98 
99  inline void sort() {
100  if (second < first)
101  std::swap(first, second);
102  }
103 
104  public:
105 
106  ipair() {}
107 
108  ipair(csl::Index t_first,
109  csl::Index t_second)
110  :first(t_first),
111  second(t_second)
112  {
113  sort();
114  }
115 
116  inline csl::Index const &getFirst() const { return first; }
117  inline csl::Index const &getSecond() const { return second; }
118 
119  inline void setFirst(csl::Index const &index) {
120  first = index;
121  sort();
122  }
123  inline void setSecond(csl::Index const &index) {
124  second = index;
125  sort();
126  }
127 
128  inline bool operator==(ipair const &other) const {
129  return first == other.first
130  and second == other.second;
131  }
132  inline bool operator!=(ipair const &other) const {
133  return !(*this == other);
134  }
135 
136  inline bool operator<(ipair const &other) const {
137  if (first < other.first)
138  return true;
139  return (!(other.first < first)) ? second < other.second : false;
140  }
141  };
142 
143 public:
144 
145  Structure();
146 
147  Structure(Structure const &other);
148  Structure& operator=(Structure const &other);
149 
150  Structure(Structure &&other) = default;
151  Structure& operator=(Structure &&other) = default;
152 
153  ~Structure() {}
154 
155  inline bool isZero() const {
156  return factor == CSL_0;
157  }
158 
159  void add(Expr const &t_factor);
160 
161  void mult(Expr const &t_factor);
162 
163  void mult(ipair const &p);
164 
165  void mult(
166  ipair const &p,
167  Expr const &t_factor
168  );
169 
170  void simplify();
171 
172  Structure& operator*=(Structure const &other);
173  Structure operator* (Structure const &other) const;
174 
175  bool operator==(Structure const &other) const;
176 
177  static int commonIndex(
178  ipair const &p1,
179  ipair const &p2
180  );
181 
182 public:
183  size_t reserveStorage = 10;
184 
185  Expr factor;
186  std::vector<ipair> indices;
187 };
188 
189 }
190 
191 #endif
Definition: libraryexpander.h:91
Namespace for csl library.
Definition: abreviation.h:34
Index object that is used for indicial objects.
Definition: index.h:75
Definition: libraryexpander.h:34
void sort(std::vector< Expr > &argument)
Sorts a container using mergeSort().
Definition: sort.cpp:89
Expr operator*(const Expr &a, const Expr &b)
Shortcut function that allows to use arithmetic operator * with Expr (== shared_ptr<Abstract>).
Definition: abstract.cpp:1351
Vector space that has a name, a dimension, a delta tensor and possibly a non-trivial metric...
Definition: space.h:64
bool operator==(const Expr &a, const Expr &b)
see Abstract::operator==()
Definition: abstract.cpp:1398
Base classes for all exprs in the program.
Definition: libraryexpander.h:93
const Space & Minkowski
Space with a metric g = diag(-1,1,1,1).
Definition: space.h:448
bool operator<(const Expr &a, const Expr &b)
see Abstract::operator<()
Definition: abstract.cpp:1423
bool operator!=(const Expr &a, const Expr &b)
see Abstract::operator!=()
Definition: abstract.cpp:1404
Expression type/.
Definition: abstract.h:1573