23 #ifndef ABREVIATION_H_INCLUDED 24 #define ABREVIATION_H_INCLUDED 40 inline std::map<std::string, std::vector<AbstractParent*>> abbreviationData;
49 static inline bool avoidDuplicates =
true;
50 static inline bool useDichotomy =
true;
57 static std::map<std::string, size_t> id_name;
59 static bool isAnAbbreviation(
Expr const &ab);
69 static void compressAbbreviations(std::string
const &name =
"");
73 static void compressAbbreviations_impl(
74 std::vector<AbstractParent*> &abbreviations
77 static void addAbbreviation(
79 std::string
const &t_name
82 static void removeAbbreviation(
84 std::string
const &t_name
87 static std::string getFinalName(std::string_view initialName);
89 static std::vector<AbstractParent*> &getAbbreviationsForName(
93 static void cleanEmptyAbbreviation();
97 static void printAbbreviations(std::ostream& fout = std::cout);
99 static void printAbbreviations(
100 std::string_view name,
101 std::ostream &fout = std::cout
104 static void enableEvaluation(std::string_view name);
106 static void disableEvaluation(std::string_view name);
108 static void toggleEvaluation(std::string_view name);
110 static void enableGenericEvaluation(std::string_view name);
112 static void disableGenericEvaluation(std::string_view name);
114 static void toggleGenericEvaluation(std::string_view name);
116 static void enableEvaluation(
Expr const& abreviation);
118 static void disableEvaluation(
Expr const& abreviation);
120 static void toggleEvaluation(
Expr const& abreviation);
128 static std::optional<Expr> findExisting(
129 std::string_view name,
132 static Expr makeSubAbbrev(
133 std::vector<csl::Expr>
const &args,
137 static Expr makeAbbreviation(
139 Expr const& encapsulated,
143 static Expr makeAbbreviation(
144 Expr const& encapsulated,
148 static void removeAbbreviations(
149 std::string
const &name
152 template<
class ...Args>
157 for (
auto &el : abbreviationData)
158 for (
auto &ab : el.second)
161 ab->getEncapsulated(),
162 std::forward<Args>(args)...
173 template<
class BaseParent>
180 template<
class ...Args>
182 std::string
const& t_name,
184 :BaseParent(Abbrev::getFinalName(t_name), std::forward<Args>(args)...),
185 encapsulated(t_encapsulated),
187 initialStructure(Abbrev::getFreeStructure(t_encapsulated))
189 Abbrev::addAbbreviation(
this, t_name);
194 Abbrev::removeAbbreviation(
this, baseName);
197 bool isAnAbbreviation()
const override {
return true; }
199 void printDefinition(
200 std::ostream &out = std::cout,
205 std::string indent(indentSize,
' ');
206 std::string regName = csl::Abstract::regularName(this->name);
207 std::string regLite = csl::Abstract::regularLiteral(this->name);
211 out <<
"csl::Expr " << regName <<
"_encaps = ";
212 encapsulated->printCode(1, out);
217 out <<
"csl::Expr " << regName
218 <<
" = csl::Abbrev::makeAbbreviation(\"" << regLite
219 <<
"\", " << regName <<
"_encaps);\n";
222 std::string
const &getBaseName()
const override {
226 void enableEvaluation()
override {
230 void disableEvaluation()
override {
234 void toggleEvaluation()
override {
235 evaluation = not evaluation;
256 if (self->isComplexConjugate())
257 res = csl::GetComplexConjugate(res);
259 CSL_ASSERT_SPEC(structure.size() == initialStructure.size(),
260 CSLError::RuntimeError,
261 "Wrong indicial structure " + toString(structure)
262 +
" to apply for " + toString(initialStructure)
267 std::map<csl::Index, csl::Index> mapping;
270 if (!IsIndicialTensor(sub))
273 for (
auto &i : index) {
274 auto pos = std::find(
275 initialStructure.begin(),
276 initialStructure.end(),
278 if (pos == initialStructure.end()) {
279 auto pos2 = mapping.find(i);
280 const bool sign = i.getSign();
281 if (pos2 == mapping.end()) {
282 mapping[i] = i.rename();
283 mapping[i].setSign(
false);
296 Replace(res, initialStructure, structure);
300 std::optional<Expr> evaluate(
302 csl::eval::mode user_mode = csl::eval::base)
const override {
303 if (evaluation or csl::eval::isContained(user_mode, csl::eval::abbreviation)){
304 auto res = getExactEncapsulated(
self);
305 return Evaluated(res, user_mode);
320 void setEncapsulated(
Expr const &t_encapsulated)
override {
321 encapsulated = t_encapsulated;
328 std::string baseName;
332 bool evaluation =
false;
Namespace for csl library.
Definition: abreviation.h:34
Expr DeepCopy(const Abstract *expr)
See DeepCopy(const Expr& expr).
Definition: utils.cpp:113
void ForEachLeaf(Expr &init, std::function< void(Expr &)> const &f, int depth=-1)
Applies a user function on each leaf of an expression. The expression may be modified.
Definition: algo.cpp:370
Definition: abreviation.h:52
Root class of the inheritance tree of abstracts.
Definition: abstract.h:76
csl::Expr getExactEncapsulated(Expr_info self) const override
Returns the encapsulated expression, applying to it the correct index structure.
Definition: abreviation.h:253
Expr const & getEncapsulated() const override
Definition: abreviation.h:316
Base class for all parents (indicial, fields etc). All parents derive from this class.
Definition: parent.h:81
Definition: abreviation.h:38
Contains algorithms that look over (and possibly modify on the go) expressions for you...
Base classes for all exprs in the program.
Manages a std::vector of Index, to be used by an TensorElement.
Definition: index.h:472
Definition: abreviation.h:42
Expression type/.
Definition: abstract.h:1573