Documentation of CSL
indicial.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 
26 #ifndef INDICIAL_H_INCLUDED
27 #define INDICIAL_H_INCLUDED
28 
29 #include "memory_pool.h"
30 #include "literal.h"
31 #include "numerical.h"
32 #include "operations.h"
33 #include "index.h"
34 #include "symmetry.h"
35 #include "parent.h"
36 #include "element.h"
37 #include "vector.h"
38 
39 namespace csl {
40 
41 class ISum;
42 class IProd;
43 
44 csl::vector_expr getAllPermutations(const Expr& expr);
45 
54 
55  protected:
56 
57  std::vector<std::pair<int,csl::Index>> specialAValues;
58 
59  std::vector<std::pair<int,csl::Index>> specialBValues;
60 
65  std::vector<std::pair<int,int>> contraction;
66 
67  std::optional<std::function<bool(Expr_info, Expr_info)>> condition;
68 
69  std::array<IndexStructure, 2> freeStructures;
70 
71  bool swappable = true;
72 
73  public:
74 
75  SelfContraction() {}
76 
82  SelfContraction(const Expr& A,
83  const Expr& B,
84  std::optional<std::function<bool(Expr_info, Expr_info)>>
85  t_condition = std::nullopt);
86 
88  Expr_info B,
89  std::optional<std::function<bool(Expr_info, Expr_info)>>
90  t_condition = std::nullopt);
91 
92 
96  bool empty() const;
97 
98  bool conditionAppliesOn(Expr_info A,
99  Expr_info B) const;
100 
101  bool conditionAppliesOn(const Expr& A,
102  const Expr& B) const;
103 
104  bool isSwappable() const {
105  return swappable;
106  }
107 
108  void setSwappable(bool t_swappable) {
109  swappable = t_swappable;
110  }
111 
116  bool operator==(const SelfContraction& other) const;
117 
118  Expr applyIndices(const Expr& A,
119  const Expr& B,
120  const SelfContraction& targetContraction,
121  const Expr& res) const;
122 
127  friend std::ostream& operator<<(std::ostream& fout,
128  const SelfContraction& c);
129 
130  private:
131 
132  SelfContraction getSwapped() const;
133 
134  IndexStructure getFreeContractionIndex(const Expr& expr,
135  int index) const;
136 
137  bool compare(const SelfContraction& other) const;
138 
139  static bool comparePairs(const std::vector<std::pair<int,Index>>& A,
140  const std::vector<std::pair<int,Index>>& B);
141 };
142 
144 
145  public:
146 
148 
149  ContractionChain(csl::vector_expr& t_contractedTensors,
150  std::vector<IndexStructure>& t_structures,
151  std::vector<std::array<int, 4>>& t_contraction);
152 
153  explicit
154  ContractionChain(const csl::vector_expr& args,
155  const Expr& res = CSL_UNDEF);
156 
157  explicit
158  ContractionChain(const Expr& expr,
159  const Expr& res = CSL_UNDEF);
160 
161  public:
162 
163  ContractionChain(const ContractionChain& other) = default;
164 
165  ContractionChain& operator=(const ContractionChain& other) = default;
166 
167  std::optional<ContractionChain> splitAndEvaluate() const;
168 
169  bool contains(const Expr& tensor) const;
170 
171  Expr getResult() const;
172 
173  std::optional<std::vector<int>> comparison(
174  const ContractionChain& other,
175  Expr& remnant) const;
176 
177  bool operator==(const ContractionChain& other) const;
178 
179  bool operator<(ContractionChain const& other) const;
180 
181  friend
182  std::ostream& operator<<(std::ostream& fout,
183  const ContractionChain& c);
184 
185  private:
186 
187  void gatherContractions();
188 
189  std::vector<std::vector<int>> getPermutations(
190  const ContractionChain& other) const;
191 
192  std::optional<ContractionChain> createChain(
193  int nChains,
194  const std::vector<int>& chainNumber) const;
195 
196  static void mergeChains(std::vector<int>& chainNumber,
197  int chain1,
198  int chain2);
199 
200  bool compareContractions(const std::array<int, 4>& c1,
201  const std::array<int, 4>& c2) const;
202 
203  bool detectSpecialContraction();
204 
205  bool detectCycle(const Space* space);
206 
207  bool isGoodIndex(
208  csl::Space const *space,
209  size_t iTensor,
210  size_t iIndex
211  ) const;
212 
213  std::pair<csl::Index, csl::Index> getContractedIndices(
214  csl::Space const *space,
215  size_t iTensor
216  ) const;
217 
218  std::vector<std::vector<size_t>> getCycles(const Space *space);
219 
220  private:
221 
222  Expr scalarFactor = CSL_1;
223 
224  csl::vector_expr contractedTensors;
225 
226  std::vector<IndexStructure> structures;
227 
228  std::vector<std::array<int, 4>> contraction;
229 
230  bool specialContraction = false;
231 
232  bool cycleTrace = false;
233 
234  const Space* traceSpace = nullptr;
235 
236  Expr resultOfContraction = CSL_UNDEF;
237 };
238 
239 class TensorElement;
240 class Symbol;
241 
246 
247  protected:
248 
251  std::vector<const Space*> space;
252 
253  std::vector<bool> covariant;
254 
255  bool keepBestPermutation = true;
256 
260 
265 
270 
273  std::vector<std::pair<SelfContraction, Expr>> selfContraction;
274  std::vector<std::pair<SelfContraction, Expr>> extContraction;
275  std::vector<csl::AbstractParent const*> externalTensors;
276 
277  std::vector<csl::Space const*> traceLessNess;
278 
279  std::vector<ContractionChain> chainContraction;
280 
281  mutable
282  std::map<const csl::Space*, std::vector<csl::Parent>> brokenParts;
283 
286  bool valued;
287 
291 
295 
296  std::optional<std::pair<IndexStructure, Expr>>
297  conjugateProperty;
298 
299  std::map<const Space*, std::pair<IndexStructure, Expr>>
300  hermitianProperty;
301 
302  std::map<const Space*,std::pair<IndexStructure, Expr>>
303  transposedProperty;
304 
305  public:
306 
309  TensorParent();
310 
314  explicit TensorParent(const std::string& t_name);
315 
318  TensorParent(const TensorParent& abstract) = default;
319 
324  TensorParent(const std::string& t_name,
325  const Space* t_space);
326 
331  TensorParent(const std::string& t_name,
332  const std::vector<const Space*>& t_space);
333 
341  TensorParent(const std::string& t_name,
342  const std::vector<const Space*>& t_space,
343  const Expr& t_tensor);
344 
352  TensorParent(const std::string& t_name,
353  const Space* t_space,
354  const Expr& t_tensor);
355 
356  public:
357 
358  template<class ...Args>
359  friend
360  std::shared_ptr<TensorParent> tensor_s(Args&& ...args);
361 
362  template<class ...Args>
363  friend
365  std::string const& name,
366  std::vector<const Space*> const& indices,
367  Args&& ...args);
368 
369 
370  cslParent::PrimaryType getPrimaryType() const override;
371 
372  cslParent::Type getType() const override;
373 
374  void printDefinition(
375  std::ostream &out = std::cout,
376  int indentSize = 4,
377  bool header = false
378  ) const override;
379 
380  int getDim(const Space* t_space) const override;
381 
384  std::vector<const Space*> getSpace() const override;
385 
388  Symmetry getSymmetry() const;
389 
390  bool getFullySymmetric() const override;
391 
392  bool getFullyAntiSymmetric() const override;
393 
394  std::vector<Permutation> getPermutation() const override;
395 
396  bool isValued() const override;
397 
398  Expr getTensor() const override;
399 
400  Expr getTensor(Expr_info self) const override;
401 
402  Expr getTrace() const override;
403 
404  bool dependsOn(Expr_info expr) const override;
405 
406  bool dependsExplicitlyOn(Expr_info expr) const override;
407 
408  const std::vector<Equation*>& getProperties() const override;
409 
410  void setComplexProperty(csl::ComplexProperty t_prop) override;
411 
412  void setKeepBestPermutation(bool keep);
413 
414  void setFullySymmetric() override;
415 
416  void setFullyAntiSymmetric() override;
417 
418  bool isTraceLessIn(csl::Space const* space) const override;
419  void addTraceLessNess(csl::Space const* space) override;
420  void removeTraceLessNess(csl::Space const* space) override;
421 
422  void addSpace(const Space* space) override;
423 
424  void addSymmetry(int i1, int i2) override;
425 
426  void addAntiSymmetry(int i1, int i2) override;
427 
428  void setSymmetry(const Symmetry& t_symetry) override;
429 
430  void setTensor(const Expr& t_tensor) override;
431 
432  void setTrace(const Expr& t_trace) override;
433 
442  void setElementary(bool t_elementary);
443 
444  bool hasContractionProperty(const Abstract* self,
445  Expr_info B) const override;
446 
447  std::vector<ContractionChain> getContractionProperties() const override;
448 
449  Expr contraction(const Abstract* self, Expr_info B) const override;
450 
451  void addSelfContraction(
452  const Expr& A,
453  const Expr& B,
454  const Expr& res,
455  std::optional<std::function<bool(Expr_info, Expr_info)>>
456  condition = std::nullopt
457  ) override;
458 
459  void removeSelfContraction(
460  const Expr& A,
461  const Expr& B
462  ) override;
463 
464  bool hasChainContractionProperty() const override;
465 
466  void addContractionProperty(
467  csl::vector_expr const& leftHandSide,
468  const Expr& rightHandSide) override;
469 
470  void removeContractionProperty(
471  csl::vector_expr const& leftHandSide,
472  const Expr& rightHandSide) override;
473 
474  std::optional<Expr> getComplexProperty(
475  Expr_info self) const override;
476 
477  std::optional<Expr> getHermitianProperty(
478  Expr_info self,
479  const Space* t_space) const override;
480 
481  std::optional<Expr> getTransposedProperty(
482  Expr_info self,
483  const Space* t_space) const override;
484 
485  std::optional<Expr> evaluate(
486  Expr_info self,
487  csl::eval::mode user_mode = csl::eval::base) const override;
488 
489  void addComplexProperty(const Expr& init,
490  const Expr& res) override;
491 
492  void addHermitianProperty(const Space* space,
493  const Expr& init,
494  const Expr& res) override;
495 
496  void addTransposedProperty(const Space* space,
497  const Expr& init,
498  const Expr& res) override;
499 
500  std::vector<Parent> getBrokenParts(const Space* broken) const override;
501 
502  std::vector<Parent> breakSpace(
503  const Space* broken,
504  const std::vector<const Space*>& newSpace,
505  const std::vector<size_t>& pieces
506  ) const override;
507 
508  virtual Expr operator()(Index index) override;
509 
510  virtual Expr operator()(std::vector<Index> indices) override;
511 
512  virtual Expr operator()(const std::vector<int>& indices) override;
513 
518  virtual bool operator==(const TensorParent& other) const;
519 
524  virtual bool operator!=(const TensorParent& other) const;
525 
530  friend std::ostream& operator<<(std::ostream& fout, const TensorParent&);
531 
532  protected:
533 
534  void applyProperty(Expr_info self,
535  IndexStructure const& structure,
536  Expr& res) const;
537 
538  void checkIndexRequest(const Index& index);
539 
540  void checkIndexRequest(const std::vector<Index>& request);
541 
542  void createFixedIndices(Index& index) const;
543 
544  void createFixedIndices(std::vector<Index>& indices) const;
545 };
546 
547 template<class ...Args>
548  std::shared_ptr<TensorParent> tensor_s(Args&& ...args) {
549  return csl::make_shared<TensorParent>(std::forward<Args>(args)...);
550  }
551 
552 template<class ...Args>
554  std::string const& name,
555  std::vector<const Space*> const& indices,
556  Args&& ...args) {
557  return csl::make_shared<TensorParent>(
558  name,
559  indices,
560  std::forward<Args>(args)...);
561  }
562 
567 
568  public:
569 
570  EpsilonParent(const EpsilonParent& abstract) = delete;
571 
572  explicit EpsilonParent(const Space* t_space);
573 
574  cslParent::Type getType() const override;
575 
576  bool hasContractionProperty(const Abstract* self,
577  Expr_info B) const override;
578 
579  Expr contraction(const Abstract* self, Expr_info B) const override;
580 
581  void printDefinition(
582  std::ostream &out = std::cout,
583  int indentSize = 4,
584  bool header = false
585  ) const override;
586 
587  Expr operator()(std::vector<Index> indices) override;
588 };
589 
593 class DeltaParent: public TensorParent{
594 
595  public:
596 
599  DeltaParent();
600 
601  DeltaParent(const DeltaParent& abstract) = delete;
602 
603  explicit DeltaParent(const Space* t_space);
604 
605  cslParent::Type getType() const override;
606 
607  bool hasContractionProperty(const Abstract* self,
608  Expr_info B) const override;
609 
610  Expr contraction(const Abstract* self, Expr_info B) const override;
611 
612  void printDefinition(
613  std::ostream &out = std::cout,
614  int indentSize = 4,
615  bool header = false
616  ) const override;
617 
618  Expr operator()(std::vector<Index> indices) override;
619 };
620 
627 
628  public:
629 
633  MetricParent();
634 
635  MetricParent(const MetricParent& abstract) = delete;
636 
641  explicit MetricParent(const DeltaParent& abstract);
642 
652  MetricParent(const Space* t_space, const Expr& t_tensor,
653  const std::string& t_name="g");
654 
655  MetricParent(const Space* t_space,
656  const std::string& t_name="g");
657 
658 
659  cslParent::Type getType() const override;
660 
661  bool hasContractionProperty(const Abstract* self,
662  Expr_info B) const override;
663 
664  Expr contraction(const Abstract* self, Expr_info B) const override;
665 
666  void printDefinition(
667  std::ostream &out = std::cout,
668  int indentSize = 4,
669  bool header = false
670  ) const override;
671 
672  Expr operator()(std::vector<Index> indices) override;
673 };
674 
675 class Tensor: public std::shared_ptr<TensorParent> {
676 
677  public:
678 
679  INHERIT_SHARED_PTR_CONSTRUCTOR(Tensor, TensorParent)
680 
681 
686  const std::string& t_name,
687  const Space* t_space
688  )
689  :Tensor(tensor_s(t_name, t_space))
690  {}
691 
697  const std::string& t_name,
698  const std::vector<const Space*>& t_space
699  )
700  :Tensor(tensor_s(t_name, t_space))
701  {}
702 
711  const std::string& t_name,
712  const std::vector<const Space*>& t_space,
713  const Expr& t_tensor
714  )
715  :Tensor(tensor_s(t_name, t_space, t_tensor))
716  {}
717 
726  const std::string& t_name,
727  const Space* t_space,
728  const Expr& t_tensor
729  )
730  :Tensor(tensor_s(t_name, t_space, t_tensor))
731  {}
732 
733 
734  template<class ...Args>
735  inline
736  Expr operator()(Args&& ...args)
737  {
738  return (**this)(std::forward<Args>(args)...);
739  }
740 
741  template<class ...Args>
742  inline
743  Expr operator()(const std::vector<int>& indices, Args&& ...args)
744  {
745  return (**this)(indices, std::forward<Args>(args)...);
746  }
747 
748  template<class ...Args>
749  inline
750  Expr operator()(const std::vector<Index>& indices, Args&& ...args)
751  {
752  return (**this)(indices, std::forward<Args>(args)...);
753  }
754 };
755 
756 DEFINE_SHARED_PTR_OPERATOR(Tensor)
757 
758 
764 
765  protected:
766 
769 
770  public:
771 
772 
773  TensorElement() = default;
781  TensorElement(const Index& t_index,
782  const Parent& t_parent);
783 
791  TensorElement(const std::vector<Index>& indices,
792  const Parent& t_parent);
793 
802  TensorElement(const IndexStructure& indices,
803  const Parent& t_parent);
804 
805  public:
806 
813  explicit TensorElement(const Abstract*& expression);
814 
821  explicit TensorElement(const Expr& expression);
822 
823  template<typename ...Args>
824  friend Expr tensorelement_s(Args&& ...args);
825 
826 
827 #ifdef DEBUG
828  ~TensorElement(){ __record_data_alloc(static_cast<int>(getType())); }
829 #endif
830 
831  csl::PrimaryType getPrimaryType() const override {
833  }
834 
835  size_t memoryOverhead() const override;
836 
837  bool isIndexed() const override {
838  return true;
839  }
840 
841  int getNIndices() const override {
842  return index.size();
843  }
844 
845  void resetIndexStructure() override;
846 
848  return index;
849  }
850 
851  const IndexStructure& getIndexStructureView() const override {
852  return index;
853  }
854 
855  IndexStructure& getIndexStructureView() override {
856  return index;
857  }
858 
859  bool compareWithDummy(Expr_info expr,
860  std::map<Index,Index>& constraints,
861  bool keepAllCosntraints = false) const override;
862 
863  csl::Type getType() const override {
865  }
866 
867  std::optional<Expr> getComplexConjugate() const override;
868 
869  std::optional<Expr> getHermitianConjugate(
870  const Space* space) const override;
871 
872  std::optional<Expr> getHermitianConjugate(
873  const std::vector<const Space*>& spaces) const override;
874 
875  std::optional<Expr> getTransposed(
876  const Space* space,
877  bool applyProp = true) const override;
878 
879  std::optional<Expr> getTransposed(
880  const std::vector<const Space*>& t_spaces,
881  bool applyProp = true) const override;
882 
883  Index getIndex(int i) const override;
884 
899  bool askTerm(Expr_info expr, bool exact=false) const override;
900 
901  bool dependsOn(Expr_info expr) const override;
902 
903  bool dependsOn(Parent_info t_parent) const override;
904 
905  bool dependsExplicitlyOn(Expr_info expr) const override;
906 
907  const std::vector<Equation*>& getProperties() const override;
908 
909  void addProperty(Equation* property) override;
910 
911  void removeProperty(Equation* property) override;
912 
913  bool checkIndexStructure(
914  const std::vector<Index>& t_index) const override;
915 
916  void selfCheckIndexStructure();
917 
918  std::optional<Expr> replaceIndex(
919  const Index& indexToReplace,
920  const Index& newIndex,
921  bool refresh = true) const override;
922 
923  std::optional<Expr> replaceIndices(
924  std::vector<Index> const &indexToReplace,
925  std::vector<Index> const &newIndex,
926  bool refresh = true,
927  bool flipped = false) const override;
928 
929  void replaceIndexInPlace(
930  Index const &oldIndex,
931  Index const &newIndex) override;
932 
933  csl::vector_expr breakSpace(
934  const Space* brokenSpace,
935  const std::vector<const Space*>& newSpaces,
936  const std::vector<std::string>& indexNames
937  ) const override;
938 
939  void setIndexStructure(const IndexStructure& t_index) override;
940 
941  bool hasContractionProperty(Expr_info B) const override;
942 
943  std::vector<ContractionChain> getContractionProperties() const override;
944 
945  Expr contraction(Expr_info B) const override;
946 
947  bool hasChainContractionProperty() const override;
948 
957  Expr applyPermutation(const Permutation& permutations) const;
958 
959  csl::vector_expr getPermutations(bool optimize = true) const override;
960 
961  csl::vector_expr getAlternateForms() const override;
962 
963  Expr getCanonicalPermutation() const override;
964 
965  void print(int mode=0,
966  std::ostream& out=std::cout,
967  bool lib = false) const override;
968 
969  void printCode(
970  int mode=0,
971  std::ostream& out=std::cout
972  ) const override;
973 
974  std::string printLaTeX(int mode=0) const override;
975 
976  std::vector<Parent> getSubSymbols() const override;
977 
978  std::optional<Expr> derive(Expr_info expr) const override;
979 
980  std::optional<Expr> evaluate(
981  csl::eval::mode user_mode = csl::eval::base
982  ) const override;
983 
984  unique_Expr copy_unique() const override;
985 
986  Expr refresh() const override;
987 
988  Expr deepRefresh() const override;
989 
990  bool operator==(Expr_info expr) const override;
991 
992  bool operator<(const Abstract* expr) const override;
993 
994  protected:
995 
996  bool comparePermutations(Expr_info perm1,
997  Expr_info perm2) const;
998 
999  void selfCheckAutoIndices();
1000 
1001  Expr& applySelfStructureOn(Expr& expr) const override;
1002 
1003  void adjustMetricDeltaParent();
1004 
1005  csl::vector_expr applyBrokenIndices(
1006  std::vector<Parent>& brokenParents,
1007  const Space* broken,
1008  const std::vector<const Space*>& newSpaces,
1009  const std::vector<Index>& indices
1010  ) const;
1011 };
1012 
1013 inline csl::allocator<TensorElement> alloc_itensor;
1014 inline csl::allocator<ISum> alloc_isum;
1015 inline csl::allocator<IProd> alloc_iprod;
1016 
1017 template<typename ...Args>
1018 Expr tensorelement_s(Args&& ...args)
1019 {
1020  return csl::make_shared<TensorElement, alloc_itensor>(
1021  std::forward<Args>(args)...)
1022  ->getCanonicalPermutation();
1023 }
1024 
1025 bool IsIndicialTensor(const Expr& expr);
1026 
1027 bool IsIndicialTensor(Expr_info expr);
1028 
1043 void nameTensor(const std::string& name, Expr& tensor, bool first=true);
1044 
1055 Expr generateTensor(const std::string& name,
1056  const std::vector<const Space*>& spaces);
1057 
1062 class ISum: public Sum{
1063 
1064  public:
1065 
1069  ISum();
1070 
1080  ISum(const csl::vector_expr& t_argument, bool explicitSum=0);
1081 
1091  ISum(const Expr& leftOperand,
1092  const Expr& rightOperand,
1093  bool explicitSum=0);
1094 
1095 
1096 #ifdef DEBUG
1097  ~ISum(){ __record_data_alloc(static_cast<int>(getType())); }
1098 #endif
1099 
1100  bool isIndexed() const override;
1101 
1102  IndexStructure getIndexStructure() const override;
1103 
1104  std::optional<Expr> factor(bool full = false) const override;
1105 
1112  void selfCheckIndexStructure();
1113 
1114  std::optional<Expr> getTransposed(
1115  const Space* space,
1116  bool applyProp = true) const override;
1117 
1118  std::optional<Expr> getTransposed(
1119  const std::vector<const Space*>& spaces,
1120  bool applyProp = true) const override;
1121 
1122  std::optional<Expr> getHermitianConjugate(
1123  const Space* space) const override;
1124 
1125  std::optional<Expr> getHermitianConjugate(
1126  const std::vector<const Space*>& spaces) const override;
1127 
1128  std::optional<Expr> replaceIndex(
1129  const Index& indexToReplace,
1130  const Index& newIndex,
1131  bool refresh = true) const override;
1132 
1133  std::optional<Expr> replaceIndices(
1134  std::vector<Index> const &indexToReplace,
1135  std::vector<Index> const &newIndex,
1136  bool refresh = true,
1137  bool flipped = false) const override;
1138 
1139  csl::vector_expr breakSpace(
1140  const Space* brokenSpace,
1141  const std::vector<const Space*>& newSpaces,
1142  const std::vector<std::string>& indexNames
1143  ) const override;
1144 
1145  bool compareWithDummy(Expr_info other,
1146  std::map<Index, Index>& constraints,
1147  bool keepAllCosntraints = false) const override;
1148 
1149  bool operator==(Expr_info expr) const override;
1150 
1151  protected:
1152 
1153  void gatherFactors(csl::vector_expr& factors,
1154  csl::vector_expr& arg,
1155  bool full) const override;
1156 
1157  void clearRedundantIndicialFactors(csl::vector_expr& factors) const;
1158 
1159  void checkIndicialFactors(csl::vector_expr& factors) const;
1160 };
1161 
1166 class IProd: public Prod{
1167 
1168  public:
1169 
1173  IProd();
1174 
1184  IProd(const csl::vector_expr& t_argument, bool explicitProd=0);
1185 
1195  IProd(const Expr& leftOperand, const Expr& rightOperand, bool explicitProd=0);
1196 
1197 
1198 #ifdef DEBUG
1199  ~IProd(){ __record_data_alloc(static_cast<int>(getType())); }
1200 #endif
1201 
1202  bool isIndexed() const override;
1203 
1204  IndexStructure getIndexStructure() const override;
1205 
1206  Expr suppressTerm(Expr_info term) const override;
1207 
1208  void setArgument(const Expr& arg, int iArg=0) override;
1209 
1210  std::optional<Expr> evaluate(
1211  csl::eval::mode user_mode = csl::eval::base) const override;
1212 
1213  std::optional<Expr> getTransposed(
1214  const Space* space,
1215  bool applyProp = true) const override;
1216 
1217  std::optional<Expr> getTransposed(
1218  const std::vector<const Space*>& spaces,
1219  bool applyProp = true) const override;
1220 
1221  std::optional<Expr> replaceIndex(
1222  const Index& indexToReplace,
1223  const Index& newIndex,
1224  bool refresh = true) const override;
1225 
1226  std::optional<Expr> replaceIndices(
1227  std::vector<Index> const &indexToReplace,
1228  std::vector<Index> const &newIndex,
1229  bool refresh = true,
1230  bool flipped = false) const override;
1231 
1232  csl::vector_expr breakSpace(
1233  const Space* brokenSpace,
1234  const std::vector<const Space*>& newSpaces,
1235  const std::vector<std::string>& indexNames
1236  ) const override;
1237 
1238  bool mergeTerms() override;
1239 
1240  void leftInsert(const Expr& expr) override;
1241 
1242  void rightInsert(const Expr& expr) override;
1243 
1244  bool compareWithDummy(Expr_info expr,
1245  std::map<Index, Index>& constraints,
1246  bool keepAllCosntraints = false) const override;
1247 
1248  bool operator==(Expr_info expr) const override;
1249 
1250  protected:
1251 
1258  void selfCheckIndexStructure(bool explicitTimes = false);
1259 
1260  bool partialComparison(Expr_info expr) const override;
1261 
1262  void applyContractionChains();
1263 
1264  bool hasSeparableIndicialDenominator() const;
1265 
1266  bool compareDenominatorSeparately(Expr_info other) const;
1267 };
1268 
1269 } // End of namespace csl
1270 
1271 #endif
Definition: indicial.h:143
int getNIndices() const override
Definition: indicial.h:841
bool fullySymmetric
Attribute that can be set to True if the tensor must be fully symmetric.
Definition: indicial.h:264
const csl::Expr CSL_UNDEF
Constant that is useful in return of non-defined calculations as for example Commutator(): [A...
Definition: literal.h:617
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
Expr generateTensor(const std::string &name, const std::vector< const Space *> &spaces)
Generates a tensor of name name that lives in a list of spaces, filled with variables given by nameTe...
Definition: parent.h:439
Handles a sum, function of multiple arguments.
Definition: operations.h:33
Parent of an indicial object, allows to generate them (TensorElement).
Definition: indicial.h:245
Index object that is used for indicial objects.
Definition: index.h:75
Tensor(const std::string &t_name, const Space *t_space, const Expr &t_tensor)
Constructor of a 1-indexed parent, with explicit tensor tensor.
Definition: indicial.h:725
Handles a product, function of multiple arguments.
Definition: operations.h:289
Base classes for parents and elements.
Type
Enum of the different types of Abstract (i.e. list of all possible specializations).
Definition: enum.h:47
Handles the full symmetry properties of an TensorElement, i.e. a vector of Permutation objects...
Definition: symmetry.h:277
Definition: diagonalization.h:32
Objects handling multi-argument functions, primordial operations (+,*,/,etc)
PrimaryType
Definition: parent.h:39
bool valued
Boolean that is True iif an explicit tensor is given.
Definition: indicial.h:286
csl::Type getType() const override
Gives the type of Abstract.
Definition: indicial.h:863
std::vector< std::pair< SelfContraction, Expr > > selfContraction
List of (self) constractions that have special properties.
Definition: indicial.h:273
Tensor(const std::string &t_name, const std::vector< const Space *> &t_space)
Constructor of a n-indexed parent.
Definition: indicial.h:696
Specialization of Abstract for Indicial tensor. Building block carrying indices, and respecting Einst...
Definition: indicial.h:763
friend std::ostream & operator<<(std::ostream &fout, const SelfContraction &c)
Displays the SelfContraction c.
Specialization of TensorParent for a matric object (two indices symmetric etc). An object of type Spa...
Definition: indicial.h:626
Specialization of TensorParent for a kronecker delta.
Definition: indicial.h:566
ComplexProperty
Contains all possible complex properties of objects. Real, purely imaginary, or complex.
Definition: enum.h:127
PrimaryType
Stores enumerations of types for Abstract objects.
Definition: enum.h:31
std::vector< const Space * > space
Vector spaces in which the indices live.
Definition: indicial.h:251
Expr tensor
Explicit tensor that can be set by the user.
Definition: indicial.h:290
bool operator==(const SelfContraction &other) const
Compares the SelfContraction with another.
Definition: indicial.cpp:355
csl::PrimaryType getPrimaryType() const override
Gives the primary type of Abstract.
Definition: indicial.h:831
Small class that allows to handle contractions of indices between tensors.
Definition: indicial.h:53
Root class of the inheritance tree of abstracts.
Definition: abstract.h:76
bool empty() const
Definition: indicial.cpp:205
Specialization of a Prod object to handle TensorElement objects in the product (apply contraction of ...
Definition: indicial.h:1166
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...
Vector space that has a name, a dimension, a delta tensor and possibly a non-trivial metric...
Definition: space.h:64
Base class for all parents (indicial, fields etc). All parents derive from this class.
Definition: parent.h:81
Objects handling vectors, matrices and higher-dimensional tensors.
std::vector< std::pair< int, int > > contraction
Contains a list of pairs of integers. Each pair corresponds to the places of the two contracted indic...
Definition: indicial.h:65
Tensor(const std::string &t_name, const std::vector< const Space *> &t_space, const Expr &t_tensor)
Constructor of a n-indexed parent, with explicit tensor tensor.
Definition: indicial.h:710
Type
Definition: parent.h:47
Definition: equation.h:43
IndexStructure getIndexStructure() const override
Definition: indicial.h:847
void nameTensor(const std::string &name, Expr &tensor, bool first=true)
Fills an tensor with variables of the same name with the numbers correponding to their place in the t...
Specialization of a Prod object to handle TensorElement objects in the product (apply contraction of ...
Definition: indicial.h:1062
Specialization of TensorParent for a kronecker delta.
Definition: indicial.h:593
Expr trace
(almost) Unused attribute going to disappear.
Definition: indicial.h:294
bool operator<(const Expr &a, const Expr &b)
see Abstract::operator<()
Definition: abstract.cpp:1423
Definition: indicial.h:675
bool operator!=(const Expr &a, const Expr &b)
see Abstract::operator!=()
Definition: abstract.cpp:1404
Symmetry symmetry
Symmetry properties of the tensor.
Definition: indicial.h:259
bool fullyAntiSymmetric
Attribute that can be set to True if the tensor must be fully anti-symmetric.
Definition: indicial.h:269
Manages a std::vector of Index, to be used by an TensorElement.
Definition: index.h:472
Base class for all elements. Objects that are constructed by a parent (see AbstractParent) when the u...
Definition: element.h:37
bool isIndexed() const override
Definition: indicial.h:837
IndexStructure index
IndexStructure of the tensor.
Definition: indicial.h:768
Expression type/.
Definition: abstract.h:1573