26 #ifndef INDICIAL_H_INCLUDED 27 #define INDICIAL_H_INCLUDED 44 csl::vector_expr getAllPermutations(
const Expr& expr);
57 std::vector<std::pair<int,csl::Index>> specialAValues;
59 std::vector<std::pair<int,csl::Index>> specialBValues;
67 std::optional<std::function<bool(Expr_info, Expr_info)>> condition;
69 std::array<IndexStructure, 2> freeStructures;
71 bool swappable =
true;
85 t_condition = std::nullopt);
90 t_condition = std::nullopt);
101 bool conditionAppliesOn(
const Expr& A,
102 const Expr& B)
const;
104 bool isSwappable()
const {
108 void setSwappable(
bool t_swappable) {
109 swappable = t_swappable;
121 const Expr& res)
const;
127 friend std::ostream&
operator<<(std::ostream& fout,
139 static bool comparePairs(
const std::vector<std::pair<int,Index>>& A,
140 const std::vector<std::pair<int,Index>>& B);
150 std::vector<IndexStructure>& t_structures,
151 std::vector<std::array<int, 4>>& t_contraction);
167 std::optional<ContractionChain> splitAndEvaluate()
const;
169 bool contains(
const Expr& tensor)
const;
171 Expr getResult()
const;
173 std::optional<std::vector<int>> comparison(
175 Expr& remnant)
const;
187 void gatherContractions();
189 std::vector<std::vector<int>> getPermutations(
192 std::optional<ContractionChain> createChain(
194 const std::vector<int>& chainNumber)
const;
196 static void mergeChains(std::vector<int>& chainNumber,
200 bool compareContractions(
const std::array<int, 4>& c1,
201 const std::array<int, 4>& c2)
const;
203 bool detectSpecialContraction();
205 bool detectCycle(
const Space* space);
213 std::pair<csl::Index, csl::Index> getContractedIndices(
218 std::vector<std::vector<size_t>> getCycles(
const Space *space);
222 Expr scalarFactor = CSL_1;
224 csl::vector_expr contractedTensors;
226 std::vector<IndexStructure> structures;
230 bool specialContraction =
false;
232 bool cycleTrace =
false;
234 const Space* traceSpace =
nullptr;
253 std::vector<bool> covariant;
255 bool keepBestPermutation =
true;
274 std::vector<std::pair<SelfContraction, Expr>> extContraction;
275 std::vector<csl::AbstractParent const*> externalTensors;
277 std::vector<csl::Space const*> traceLessNess;
279 std::vector<ContractionChain> chainContraction;
282 std::map<const csl::Space*, std::vector<csl::Parent>> brokenParts;
296 std::optional<std::pair<IndexStructure, Expr>>
299 std::map<const Space*, std::pair<IndexStructure, Expr>>
302 std::map<const Space*,std::pair<IndexStructure, Expr>>
325 const Space* t_space);
332 const std::vector<const Space*>& t_space);
342 const std::vector<const Space*>& t_space,
343 const Expr& t_tensor);
353 const Space* t_space,
354 const Expr& t_tensor);
358 template<
class ...Args>
362 template<
class ...Args>
365 std::string
const& name,
366 std::vector<const Space*>
const& indices,
374 void printDefinition(
375 std::ostream &out = std::cout,
380 int getDim(
const Space* t_space)
const override;
384 std::vector<const Space*> getSpace()
const override;
390 bool getFullySymmetric()
const override;
392 bool getFullyAntiSymmetric()
const override;
394 std::vector<Permutation> getPermutation()
const override;
396 bool isValued()
const override;
398 Expr getTensor()
const override;
402 Expr getTrace()
const override;
404 bool dependsOn(
Expr_info expr)
const override;
406 bool dependsExplicitlyOn(
Expr_info expr)
const override;
408 const std::vector<Equation*>& getProperties()
const override;
412 void setKeepBestPermutation(
bool keep);
414 void setFullySymmetric()
override;
416 void setFullyAntiSymmetric()
override;
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;
422 void addSpace(
const Space* space)
override;
424 void addSymmetry(
int i1,
int i2)
override;
426 void addAntiSymmetry(
int i1,
int i2)
override;
428 void setSymmetry(
const Symmetry& t_symetry)
override;
430 void setTensor(
const Expr& t_tensor)
override;
432 void setTrace(
const Expr& t_trace)
override;
442 void setElementary(
bool t_elementary);
444 bool hasContractionProperty(
const Abstract*
self,
447 std::vector<ContractionChain> getContractionProperties()
const override;
451 void addSelfContraction(
456 condition = std::nullopt
459 void removeSelfContraction(
464 bool hasChainContractionProperty()
const override;
466 void addContractionProperty(
467 csl::vector_expr
const& leftHandSide,
468 const Expr& rightHandSide)
override;
470 void removeContractionProperty(
471 csl::vector_expr
const& leftHandSide,
472 const Expr& rightHandSide)
override;
474 std::optional<Expr> getComplexProperty(
477 std::optional<Expr> getHermitianProperty(
479 const Space* t_space)
const override;
481 std::optional<Expr> getTransposedProperty(
483 const Space* t_space)
const override;
485 std::optional<Expr> evaluate(
487 csl::eval::mode user_mode = csl::eval::base)
const override;
489 void addComplexProperty(
const Expr& init,
490 const Expr& res)
override;
492 void addHermitianProperty(
const Space* space,
494 const Expr& res)
override;
496 void addTransposedProperty(
const Space* space,
498 const Expr& res)
override;
500 std::vector<Parent> getBrokenParts(
const Space* broken)
const override;
502 std::vector<Parent> breakSpace(
504 const std::vector<const Space*>& newSpace,
505 const std::vector<size_t>& pieces
508 virtual Expr operator()(
Index index)
override;
510 virtual Expr operator()(std::vector<Index> indices)
override;
512 virtual Expr operator()(
const std::vector<int>& indices)
override;
538 void checkIndexRequest(
const Index& index);
540 void checkIndexRequest(
const std::vector<Index>& request);
542 void createFixedIndices(
Index& index)
const;
544 void createFixedIndices(std::vector<Index>& indices)
const;
547 template<
class ...Args>
549 return csl::make_shared<TensorParent>(std::forward<Args>(args)...);
552 template<
class ...Args>
554 std::string
const& name,
555 std::vector<const Space*>
const& indices,
557 return csl::make_shared<TensorParent>(
560 std::forward<Args>(args)...);
576 bool hasContractionProperty(
const Abstract*
self,
581 void printDefinition(
582 std::ostream &out = std::cout,
587 Expr operator()(std::vector<Index> indices)
override;
607 bool hasContractionProperty(
const Abstract*
self,
612 void printDefinition(
613 std::ostream &out = std::cout,
618 Expr operator()(std::vector<Index> indices)
override;
653 const std::string& t_name=
"g");
656 const std::string& t_name=
"g");
661 bool hasContractionProperty(
const Abstract*
self,
666 void printDefinition(
667 std::ostream &out = std::cout,
672 Expr operator()(std::vector<Index> indices)
override;
686 const
std::
string& t_name,
689 :
Tensor(tensor_s(t_name, t_space))
697 const std::string& t_name,
698 const std::vector<const Space*>& t_space
700 :
Tensor(tensor_s(t_name, t_space))
711 const std::string& t_name,
712 const std::vector<const Space*>& t_space,
715 :
Tensor(tensor_s(t_name, t_space, t_tensor))
726 const std::string& t_name,
727 const Space* t_space,
730 :
Tensor(tensor_s(t_name, t_space, t_tensor))
734 template<
class ...Args>
736 Expr operator()(Args&& ...args)
738 return (**
this)(std::forward<Args>(args)...);
741 template<
class ...Args>
743 Expr operator()(
const std::vector<int>& indices, Args&& ...args)
745 return (**
this)(indices, std::forward<Args>(args)...);
748 template<
class ...Args>
750 Expr operator()(
const std::vector<Index>& indices, Args&& ...args)
752 return (**
this)(indices, std::forward<Args>(args)...);
756 DEFINE_SHARED_PTR_OPERATOR(
Tensor)
823 template<
typename ...Args>
824 friend Expr tensorelement_s(Args&& ...args);
828 ~
TensorElement(){ __record_data_alloc(static_cast<int>(getType())); }
835 size_t memoryOverhead()
const override;
845 void resetIndexStructure()
override;
860 std::map<Index,Index>& constraints,
861 bool keepAllCosntraints =
false)
const override;
867 std::optional<Expr> getComplexConjugate()
const override;
869 std::optional<Expr> getHermitianConjugate(
870 const Space* space)
const override;
872 std::optional<Expr> getHermitianConjugate(
873 const std::vector<const Space*>& spaces)
const override;
875 std::optional<Expr> getTransposed(
877 bool applyProp =
true)
const override;
879 std::optional<Expr> getTransposed(
880 const std::vector<const Space*>& t_spaces,
881 bool applyProp =
true)
const override;
883 Index getIndex(
int i)
const override;
899 bool askTerm(
Expr_info expr,
bool exact=
false)
const override;
901 bool dependsOn(
Expr_info expr)
const override;
903 bool dependsOn(
Parent_info t_parent)
const override;
905 bool dependsExplicitlyOn(
Expr_info expr)
const override;
907 const std::vector<Equation*>& getProperties()
const override;
909 void addProperty(
Equation* property)
override;
911 void removeProperty(
Equation* property)
override;
913 bool checkIndexStructure(
914 const std::vector<Index>& t_index)
const override;
916 void selfCheckIndexStructure();
918 std::optional<Expr> replaceIndex(
919 const Index& indexToReplace,
920 const Index& newIndex,
921 bool refresh =
true)
const override;
923 std::optional<Expr> replaceIndices(
924 std::vector<Index>
const &indexToReplace,
925 std::vector<Index>
const &newIndex,
927 bool flipped =
false)
const override;
929 void replaceIndexInPlace(
930 Index const &oldIndex,
931 Index const &newIndex)
override;
933 csl::vector_expr breakSpace(
934 const Space* brokenSpace,
935 const std::vector<const Space*>& newSpaces,
936 const std::vector<std::string>& indexNames
941 bool hasContractionProperty(
Expr_info B)
const override;
943 std::vector<ContractionChain> getContractionProperties()
const override;
947 bool hasChainContractionProperty()
const override;
959 csl::vector_expr getPermutations(
bool optimize =
true)
const override;
961 csl::vector_expr getAlternateForms()
const override;
963 Expr getCanonicalPermutation()
const override;
965 void print(
int mode=0,
966 std::ostream& out=std::cout,
967 bool lib =
false)
const override;
971 std::ostream& out=std::cout
974 std::string printLaTeX(
int mode=0)
const override;
976 std::vector<Parent> getSubSymbols()
const override;
978 std::optional<Expr> derive(
Expr_info expr)
const override;
980 std::optional<Expr> evaluate(
981 csl::eval::mode user_mode = csl::eval::base
984 unique_Expr copy_unique()
const override;
986 Expr refresh()
const override;
988 Expr deepRefresh()
const override;
996 bool comparePermutations(
Expr_info perm1,
999 void selfCheckAutoIndices();
1001 Expr& applySelfStructureOn(
Expr& expr)
const override;
1003 void adjustMetricDeltaParent();
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
1013 inline csl::allocator<TensorElement> alloc_itensor;
1014 inline csl::allocator<ISum> alloc_isum;
1015 inline csl::allocator<IProd> alloc_iprod;
1017 template<
typename ...Args>
1018 Expr tensorelement_s(Args&& ...args)
1020 return csl::make_shared<TensorElement, alloc_itensor>(
1021 std::forward<Args>(args)...)
1022 ->getCanonicalPermutation();
1025 bool IsIndicialTensor(
const Expr& expr);
1043 void nameTensor(
const std::string& name,
Expr& tensor,
bool first=
true);
1056 const std::vector<const Space*>& spaces);
1080 ISum(
const csl::vector_expr& t_argument,
bool explicitSum=0);
1092 const Expr& rightOperand,
1093 bool explicitSum=0);
1097 ~
ISum(){ __record_data_alloc(static_cast<int>(getType())); }
1100 bool isIndexed()
const override;
1104 std::optional<Expr> factor(
bool full =
false)
const override;
1112 void selfCheckIndexStructure();
1114 std::optional<Expr> getTransposed(
1116 bool applyProp =
true)
const override;
1118 std::optional<Expr> getTransposed(
1119 const std::vector<const Space*>& spaces,
1120 bool applyProp =
true)
const override;
1122 std::optional<Expr> getHermitianConjugate(
1123 const Space* space)
const override;
1125 std::optional<Expr> getHermitianConjugate(
1126 const std::vector<const Space*>& spaces)
const override;
1128 std::optional<Expr> replaceIndex(
1129 const Index& indexToReplace,
1130 const Index& newIndex,
1131 bool refresh =
true)
const override;
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;
1139 csl::vector_expr breakSpace(
1140 const Space* brokenSpace,
1141 const std::vector<const Space*>& newSpaces,
1142 const std::vector<std::string>& indexNames
1146 std::map<Index, Index>& constraints,
1147 bool keepAllCosntraints =
false)
const override;
1153 void gatherFactors(csl::vector_expr& factors,
1154 csl::vector_expr& arg,
1155 bool full)
const override;
1157 void clearRedundantIndicialFactors(csl::vector_expr& factors)
const;
1159 void checkIndicialFactors(csl::vector_expr& factors)
const;
1184 IProd(
const csl::vector_expr& t_argument,
bool explicitProd=0);
1195 IProd(
const Expr& leftOperand,
const Expr& rightOperand,
bool explicitProd=0);
1199 ~
IProd(){ __record_data_alloc(static_cast<int>(getType())); }
1202 bool isIndexed()
const override;
1208 void setArgument(
const Expr& arg,
int iArg=0)
override;
1210 std::optional<Expr> evaluate(
1211 csl::eval::mode user_mode = csl::eval::base)
const override;
1213 std::optional<Expr> getTransposed(
1215 bool applyProp =
true)
const override;
1217 std::optional<Expr> getTransposed(
1218 const std::vector<const Space*>& spaces,
1219 bool applyProp =
true)
const override;
1221 std::optional<Expr> replaceIndex(
1222 const Index& indexToReplace,
1223 const Index& newIndex,
1224 bool refresh =
true)
const override;
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;
1232 csl::vector_expr breakSpace(
1233 const Space* brokenSpace,
1234 const std::vector<const Space*>& newSpaces,
1235 const std::vector<std::string>& indexNames
1238 bool mergeTerms()
override;
1240 void leftInsert(
const Expr& expr)
override;
1242 void rightInsert(
const Expr& expr)
override;
1245 std::map<Index, Index>& constraints,
1246 bool keepAllCosntraints =
false)
const override;
1258 void selfCheckIndexStructure(
bool explicitTimes =
false);
1260 bool partialComparison(
Expr_info expr)
const override;
1262 void applyContractionChains();
1264 bool hasSeparableIndicialDenominator()
const;
1266 bool compareDenominatorSeparately(
Expr_info other)
const;
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...
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