Documentation of CSL
symmetry.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 SYMMETRY_H_INCLUDED
24 #define SYMMETRY_H_INCLUDED
25 
26 #include <vector>
28 #include "index.h"
29 
30 namespace csl {
31 
38 
39  IMPLEMENTS_STD_VECTOR(int, permutation)
40 
41  private:
42 
47  int order;
48 
52  int sign;
53 
58  int symmetry;
59 
65  std::vector<int> permutation;
66 
67  public:
68 
72  Permutation();
73 
79  explicit Permutation(int n);
80 
89  explicit Permutation(const std::vector<int>& t_permutation);
90 
100  Permutation(int n, const std::vector<int>& list);
101 
102  Permutation(int n, const std::vector<int>& list, int sym);
103 
112  Permutation(int n,
113  const std::vector<std::vector<int> >& list);
114 
120  Permutation(const Permutation& permutation) = default;
121 
126 
133  int getOrder();
134 
141  int getSign();
142 
147  int getSymmetry() const;
148 
152  std::vector<int> getPermutation() const;
153 
158  void setSymmetry(int t_symmetry);
159 
160  void adjustToSize(size_t newSize);
161 
162  void applyRedefinition(const std::vector<size_t>& redefinition);
163 
172  Permutation& operator=(const Permutation& t_permutation) = default;
173 
182  Permutation operator*(const Permutation& t_permutation) const;
183 
192  bool operator==(const Permutation& t_permutation) const;
193 
202  bool operator!=(const Permutation& t_permuation) const;
203 
213  friend std::ostream& operator<<(std::ostream& fout,
214  const Permutation& permutation);
215 };
216 
226 std::vector<std::vector<int> > permutations(std::vector<int> init);
227 
236 std::vector<Permutation> permutations(const Permutation& init);
237 
245 void reducePermutation(std::vector<Permutation>& permutation);
246 
256 std::vector<Permutation> getSpan(const std::vector<Permutation>& init);
257 
268 void getSpan(std::vector<Permutation >& spanned,
269  const Permutation& element);
270 
277 class Symmetry{
278 
279  IMPLEMENTS_STD_VECTOR(Permutation, permutation)
280 
281  protected:
282 
286  int dim;
287 
288  bool mustGetSpan = true;
289 
294  std::vector<Permutation> permutation;
295 
296  public:
297 
301  Symmetry();
302 
306  Symmetry(int t_dim);
307 
313  Symmetry(const Symmetry& t_symmetry) = default;
314 
319 
327  int getDim() const;
328 
332  size_t getNPermutation() const;
333 
337  std::vector<Permutation> getPermutation() const;
338 
339  int getSymmetryOf(int i, int j) const;
340 
349  void addSymmetry(const Permutation& newPermutation, int sym=1);
350 
361  void addSymmetry(const std::vector<int>& newPermutation, int sym=1);
362 
373  void addSymmetry(
374  const std::vector<std::vector<int>>& newPermutation,
375  int sym=1);
376 
377  void adjustPermutationSize();
378 
379  void setMustGetSpan(bool t_must);
380 
389  bool operator==(const Symmetry& symmetry) const;
390 
399  bool operator!=(const Symmetry& symmetry) const;
400 
401  Symmetry operator*(const Symmetry& other) const;
402 
412  friend std::ostream& operator<<(std::ostream& fout,
413  const Symmetry& symmetry);
414 };
415 
416 class IndexedSymmetry: public Symmetry {
417 
418  public:
419 
420  IndexedSymmetry();
421 
422 
423  explicit
424  IndexedSymmetry(const IndexStructure& init);
425 
426  explicit
427  IndexedSymmetry(const Index& i1,
428  const Index& i2);
429 
430  explicit
431  IndexedSymmetry(const IndexStructure& init,
432  const Symmetry& initialSym);
433 
434  void addSymmetry(const Index& i1,
435  const Index& i2);
436 
437  void addSymmetry(const std::pair<Index, Index>& perm,
438  int symmetry = 1);
439 
440  void addAntiSymmetry(const Index& i1,
441  const Index& i2);
442 
443  void addAntiSymmetry(const std::pair<Index, Index>& perm);
444 
445 
446  IndexedSymmetry operator+(const IndexedSymmetry& other) const;
447 
448  IndexedSymmetry& operator+=(const IndexedSymmetry& other);
449 
450  IndexedSymmetry operator*(const IndexedSymmetry& other) const;
451 
452  IndexedSymmetry& operator*=(const IndexedSymmetry& other);
453 
454  csl::vector_expr applySymmetry(const Expr& expr) const;
455 
456  friend
457  std::ostream& operator<<(std::ostream& fout,
458  const IndexedSymmetry& sym);
459 
460  private:
461 
462  size_t findPos(const Index& index,
463  size_t& maxPos,
464  IndexStructure& newInit) const;
465 
466  std::pair<Symmetry, Symmetry> getCorrespondingSymmetries(
467  IndexedSymmetry other,
468  IndexStructure& newInit
469  ) const;
470 
471  private:
472 
473  IndexStructure init;
474 };
475 
476 } // End of namespace csl
477 
478 #endif
Permutation operator*(const Permutation &t_permutation) const
operator*, Compose two Permutation objects and returns the result in a new Permutation.
Definition: symmetry.cpp:212
std::vector< Permutation > getSpan(const std::vector< Permutation > &init)
Calculates all permutations spanned by an ensemble of initial Permutations init.
Definition: symmetry.cpp:324
Namespace for csl library.
Definition: abreviation.h:34
Handles a std::vector of integers that represents the permutation of n indices, with a possible symme...
Definition: symmetry.h:37
Index object that is used for indicial objects.
Definition: index.h:75
Handles the full symmetry properties of an TensorElement, i.e. a vector of Permutation objects...
Definition: symmetry.h:277
friend std::ostream & operator<<(std::ostream &fout, const Permutation &permutation)
operator<<, displays the Permutation t_permutation in the output fout.
Definition: symmetry.cpp:236
Expr operator+(const Expr &a, const Expr &b)
Shortcut function that allows to use arithmetic operator + with Expr (== shared_ptr<Abstract>).
Definition: abstract.cpp:1298
Permutation & operator=(const Permutation &t_permutation)=default
Assignement operator. Copies t_permutation and returns a reference to *this.
Permutation()
Default constructor.
Definition: symmetry.cpp:33
std::vector< int > getPermutation() const
Definition: symmetry.cpp:194
void setSymmetry(int t_symmetry)
Definition: symmetry.cpp:153
~Permutation()
Destructor.
Definition: symmetry.h:125
bool operator!=(const Permutation &t_permuation) const
operator!=, tells if two Permutation objects are not equal.
Definition: symmetry.cpp:208
int dim
Dimension of the symmetry, i.e. number of indices of the TensorElement.
Definition: symmetry.h:286
int getOrder()
This function calculates the order of the permutation the first time, or just return it if it has alr...
Definition: symmetry.cpp:113
std::vector< Permutation > permutation
List of the permutations for which the TensorElement have a symmetry or an antisymmetry property...
Definition: symmetry.h:294
bool operator==(const Permutation &t_permutation) const
operator==, tells if two Permutation objects are equal.
Definition: symmetry.cpp:198
~Symmetry()
Destructor.
Definition: symmetry.h:318
void reducePermutation(std::vector< Permutation > &permutation)
Takes a vector of Permutation objects and erase the redundant ones, i.e. the permutations present sev...
Definition: symmetry.cpp:313
int getSymmetry() const
Definition: symmetry.cpp:149
std::vector< std::vector< int > > permutations(std::vector< int > init)
Gets all permutations (int the form of vectors of integers) of n elements, n beeing the size of init...
int getSign()
This function calculates the sign of the permutation the first time, or just return it if it has alre...
Definition: symmetry.cpp:128
Manages a std::vector of Index, to be used by an TensorElement.
Definition: index.h:472
Expression type/.
Definition: abstract.h:1573
Definition: symmetry.h:416