Documentation of CSL
abstract.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 
21 #ifndef ABSTRACT_H_INCLUDED
22 #define ABSTRACT_H_INCLUDED
23 
24 #include <iostream>
25 #include <string>
26 #include <sstream>
27 #include <cassert>
28 
29 #include <memory>
30 #include <functional>
31 #include <optional>
32 
33 #include <vector>
34 #include <initializer_list>
35 #include <map>
36 #include <set>
37 
38 #include <thread>
39 #include <mutex>
40 
41 #include "allocator.h"
42 #include "support.h"
43 #include "error.h"
44 #include "typedef.h"
45 #include "enum.h"
46 #include "evaluation.h"
48 #ifdef DEBUG
49 #include "alloc_monitor.h"
50 #endif
51 
52 // Forward declaration of Index TensorParent
53 // and IndexStructure classes (indicial.h)
54 namespace csl {
55 
56 class Index;
57 class IndexStructure;
58 class Space;
59 class AbstractParent;
60 class TensorParent;
61 class Equation;
62 class ContractionChain;
63 class LibDependency;
64 
65 #ifdef DEBUG
66 class Abstract: public __alloc_monitor {
67 #else
68 
76 class Abstract{
77 #endif
78 
79  public:
80 
81  /*************************************************/
82  // Constructors and destructors //
83  /*************************************************/
84 
89 #ifdef DEBUG
90  Abstract(): __alloc_monitor() {};
91 #else
92  Abstract() {};
93 #endif
94 
96  virtual ~Abstract() {}
97 
98  Expr self();
99 
100 
101  /*************************************************/
102  // Utils, common to all Abstract //
103  /*************************************************/
104 
109  virtual void print(int mode=0,
110  std::ostream& out=std::cout,
111  bool lib = false) const = 0;
112 
113  virtual void printCode(
114  int mode=0,
115  std::ostream& out=std::cout
116  ) const;
117 
118  static std::string regularName(std::string const &name);
119  static std::string regularName(std::string_view name);
120  static std::string regularLiteral(std::string const &name);
121  static std::string regularLiteral(std::string_view name);
122 
123  virtual void printProp(std::ostream& fout = std::cout) const;
124 
129  void printExplicit(int mode=0) const;
130 
136  virtual std::string printLaTeX(int mode=0) const;
137 
138  virtual std::vector<Parent> getSubSymbols() const = 0;
139 
140  virtual LibDependency getLibDependency() const;
141 
142  virtual size_t memoryOverhead() const;
143 
144 
145  /*************************************************/
146  // Common access functions for all Abstracts //
147  /*************************************************/
148 
152  virtual std::string const &getName() const;
153 
154  virtual std::string const &getLatexName() const;
155 
159  virtual bool getCommutable() const;
160 
161  virtual bool getElementary() const;
162 
163  virtual bool getAllDependencies() const;
164 
173  virtual csl::PrimaryType getPrimaryType() const = 0;
174 
182  virtual csl::Type getType() const = 0;
183 
193  virtual int getDim() const;
194 
203  virtual bool isBuildingBlock() const;
204 
205  virtual int getOrderOf(Expr_info expr) const;
206 
207  virtual bool isArbitrary() const;
208 
212  virtual bool isIndexed() const;
213 
216  virtual const std::vector<Equation*>& getProperties() const;
217 
218  virtual bool isReal() const;
219 
220  virtual bool isPurelyImaginary() const;
221 
222  virtual bool isComplexConjugate() const;
223 
224  virtual bool isHermitianConjugate() const;
225 
226  virtual csl::ComplexProperty getComplexProperty() const;
227 
228  virtual void setComplexProperty(csl::ComplexProperty prop);
229 
230  virtual void setConjugated(bool t_conjugated);
231 
232 
233  /*************************************************/
234  // Access functions for specializations //
235  /*************************************************/
236 
238  // Numerical- and Literal types
240 
246  virtual bool isInteger() const;
252  virtual bool getValued() const;
258  virtual long double getValue() const;
259 
260  virtual long double getDeltaPlus() const;
261 
262  virtual long double getDeltaMinus() const;
263 
265  // Class IntFraction
267 
270  virtual long long int getNum() const;
273  virtual long long int getDenom() const;
274 
276  // (Multiple) argument(s) functions
278 
284  virtual int getNArgs(int axis=0) const;
285 
286  virtual size_t size() const;
287 
288  virtual bool empty() const;
289 
293  virtual csl::vector_expr::iterator begin();
294 
298  virtual csl::vector_expr::iterator end();
299 
303  virtual csl::vector_expr::const_iterator begin() const;
304 
308  virtual csl::vector_expr::const_iterator end() const;
309 
314  virtual Expr const &getArgument(int iArg=0) const;
315 
316  virtual Expr& getArgument(int iArg=0);
317 
324  virtual Expr const &getArgument(const std::vector<int>& indices) const;
325 
326  virtual Expr& getArgument(const std::vector<int>& indices);
327 
333  virtual const csl::vector_expr& getVectorArgument() const;
334 
336  // Derivative, Integral, Polynomial, Commutator
338 
342  virtual Expr getVariable() const;
343 
348  virtual int getOrder() const;
349 
352  virtual int getSign() const;
353 
358  virtual bool isAnOperator() const;
359 
365  virtual bool isEmpty() const;
366 
367  virtual bool operatorAppliesOn(Expr_info expr) const;
368 
372  virtual Expr getOperand() const;
373 
375  // Vectorial-type expressions
377 
382  virtual std::vector<int> getShape() const;
383 
385  // Integral
387 
388  virtual Expr getInfBoundary() const;
389 
390  virtual Expr getSupBoundary() const;
391 
392  virtual void setSupBoundary(Expr const &t_inf);
393 
394  virtual void setInfBoundary(Expr const &t_inf);
395 
397  // Indicial-type expressions
399  //
400 
403  virtual int getNIndices() const;
404 
408  virtual Index getIndex(int i=0) const;
409 
410  virtual void resetIndexStructure();
411 
414  virtual IndexStructure getIndexStructure() const;
415 
416  IndexStructure getIndexStructure(csl::Space const *space) const;
417 
418  virtual const IndexStructure& getIndexStructureView() const;
419 
420  virtual IndexStructure& getIndexStructureView();
421 
424  virtual IndexStructure getFreeIndexStructure() const;
425 
430  virtual Parent getParent() const;
431 
432  virtual Parent_info getParent_info() const;
433 
434  virtual Tensor getPoint() const;
435 
440  virtual int getNContractedPairs() const;
441 
447  virtual csl::vector_expr getPermutations(bool optimize = true) const;
448 
454  virtual std::set<std::pair<int,int> > getContractedPair() const;
455 
457  // Copy functions for derivated classes
458  // (to reimplement)
460 
461  Expr copy() const;
462 
463  virtual unique_Expr copy_unique() const = 0;
464 
465  virtual Expr deepCopy() const;
466 
467  virtual Expr refresh() const;
468 
469  virtual Expr deepRefresh() const;
470 
471 
472 
473  /*************************************************/
474  // Common modifiers for all Abstracts //
475  /*************************************************/
476 
480  virtual void setName(const std::string& t_name);
481 
485  virtual void setCommutable(bool t_commutable);
486 
490  virtual void addProperty(Equation* property);
491 
495  virtual void removeProperty(Equation* property);
496 
497 
498 
499 
500  /*************************************************/
501  // Modifiers for specializations //
502  /*************************************************/
503 
505  // Numerical- and Literal- types
507 
510  virtual void setValue(long double t_value);
511 
512  virtual void setValue(Expr const &t_value);
513 
515  // Variable
517 
518  virtual void setElementary(bool t_elementary);
519 
520  virtual void setAllDependencies(bool t_allDependencies);
521 
522  virtual void addDependency(Expr const& expr);
523 
524  virtual void removeDependency(Expr const& expr);
525 
527  // (Multi) argument(s) functions
529 
534  virtual void setArgument(const Expr& expr, int iArg=0);
535 
542  virtual void setArgument(const Expr& expr,
543  const std::vector<int>& indices);
544 
545  virtual void setEmpty(bool t_empty);
546 
550  virtual void setOperand(const Expr& operand);
551 
557  virtual void setOperandPrivate(const Expr& operand, bool leaveEmpty);
558 
562  virtual void setVectorArgument(const csl::vector_expr& t_argument);
563 
564  virtual void setVariable(Expr const &t_variable);
565 
567  // Sum and Prod
569 
579  virtual void insert(const Expr& expr, bool side=1);
580 
582  // Indicial types
584 
585  virtual void setParent(const Parent& t_parent);
586 
595  virtual std::optional<Expr> replaceIndex(
596  const Index& indexToReplace,
597  const Index& newIndex,
598  bool refresh = true) const;
599 
600  virtual std::optional<Expr> replaceIndices(
601  std::vector<Index> const &indexToReplace,
602  std::vector<Index> const &newIndex,
603  bool refresh = true,
604  bool flipped = false) const;
605 
606  virtual void replaceIndexInPlace(
607  Index const &oldIndex,
608  Index const &newIndex);
609 
610  std::optional<Expr> contractIndex(const Index& index) const;
611 
612  csl::vector_expr breakSpace(
613  const Space* brokenSpace,
614  const std::vector<const Space*>& newSpace) const;
615 
616  virtual csl::vector_expr breakSpace(
617  const Space* brokenSpace,
618  const std::vector<const Space*>& newSpace,
619  const std::vector<std::string>& indexNames) const;
620 
621 
627  virtual void setIndexStructure(const IndexStructure& t_index);
628 
629  virtual void setPoint(const Tensor& t_point);
630 
635  virtual void setFullySymmetric();
636 
642  virtual void setFullyAntiSymmetric();
643 
649  virtual void addSymmetry(int i1, int i2);
650 
656  virtual void addAntiSymmetry(int i1, int i2);
657 
667  virtual int permut(int i1, int i2);
668 
669 
670 
671 
672  /*************************************************/
673  // Getting properties that need calculation //
674  /*************************************************/
675 
677  // Useful functions in factorization and
678  // for making canonical expressions (basic
679  // simplifications).
681 
689  virtual Expr getNumericalFactor() const;
690 
693  virtual int getNFactor() const;
694 
699  virtual csl::vector_expr getFactors() const;
700 
705  virtual std::optional<Expr> getTerm() const;
706 
725  virtual void getExponents(
726  std::vector<Expr> const &factors,
727  std::vector<Expr> &exponents
728  ) const;
729 
731  // Checking matching of different indicial
732  // expressions in calculations.
734 
742  virtual bool checkIndexStructure(const std::vector<Index>& t_index) const;
743 
751  virtual bool checkIndexStructure(const std::initializer_list<Index>& index) const;
752 
763  virtual bool compareWithDummy(Expr_info expr,
764  std::map<Index,Index>& constraints,
765  bool keepAllCosntraints = false) const;
766 
767  bool compareWithDummy(Expr_info expr,
768  bool keepAllCosntraints = false) const;
769 
770 
771 
772  /*************************************************/
773  // Getting properties depending on an expr //
774  /*************************************************/
775 
783  virtual int getParity(Expr_info t_variable) const;
784 
793  virtual bool askTerm(Expr_info expr, bool exact=false) const;
794 
800  virtual bool dependsOn(Expr_info expr) const;
801 
802  virtual bool dependsOn(Parent_info parent) const;
803 
809  virtual bool dependsExplicitlyOn(Expr_info expr) const;
810 
811  virtual bool dependsExplicitlyOn(Parent_info parent) const;
812 
818  virtual bool commutesWith(Expr_info expr, int sign=-1) const;
819 
825  virtual std::optional<Expr> findSubExpression(
826  Expr_info subExpression,
827  const Expr& newExpression) const;
828 
835  virtual int isPolynomial(Expr_info expr) const;
836 
850  virtual bool matchShape(Expr_info expr, bool exact=false) const;
851 
858  virtual bool hasContractionProperty(Expr_info B) const;
859 
860  virtual bool hasChainContractionProperty() const;
861 
862  virtual std::vector<ContractionChain> getContractionProperties() const;
863 
870  virtual Expr contraction(Expr_info B) const;
871 
872  virtual Expr contraction(const csl::vector_expr& chain) const;
873 
874 
875 
876 
877  /*************************************************/
878  // Members that return new exprs //
879  // results of specific calculations //
880  // COMMON TO ALL ABSTRACTS PART //
881  /*************************************************/
882 
890  virtual long double evaluateScalar() const;
891 
899  virtual std::optional<Expr> evaluate(
900  csl::eval::mode user_mode = csl::eval::base) const = 0;
901 
910  virtual std::optional<Expr> derive(Expr_info expr) const;
911 
919  virtual std::optional<Expr> factor(bool full=false) const;
920 
925  virtual std::optional<Expr> factor(Expr_info factor, bool full=false) const;
926 
950  virtual std::optional<Expr> collect(
951  std::vector<Expr> const &factors,
952  bool full = false
953  ) const;
954 
960  virtual Expr suppressTerm(Expr_info expr) const;
961 
977  virtual std::optional<Expr> suppressExponent(
978  Expr const & factor,
979  Expr const &exponent
980  ) const;
981 
988  virtual std::optional<Expr> expand(bool full=false,
989  bool inPlace=false) const;
990 
999  virtual std::optional<Expr> expand_if(
1000  std::function<bool(Expr const&)> const& f,
1001  bool full=false,
1002  bool inPlace=false) const;
1003 
1007  virtual std::optional<Expr> getRealPart() const;
1008 
1012  virtual Expr getImaginaryPart() const;
1013 
1018  virtual std::optional<Expr> getComplexModulus() const;
1019 
1024  virtual std::optional<Expr> getComplexArgument() const;
1025 
1029  virtual std::optional<Expr> getComplexConjugate() const;
1030 
1031  virtual Expr& applySelfStructureOn(Expr& expr) const;
1032 
1033  virtual std::optional<Expr> getTransposed(
1034  const Space* space,
1035  bool applyProp = true) const;
1036 
1037  virtual std::optional<Expr> getTransposed(
1038  const std::vector<const Space*>& spaces,
1039  bool applyProp = true) const;
1040 
1041  virtual std::optional<Expr> getHermitianConjugate(
1042  const Space* space) const;
1043 
1044  virtual std::optional<Expr> getHermitianConjugate(
1045  const std::vector<const Space*>& spaces) const;
1046 
1056  virtual std::optional<Expr> getPolynomialTerm(
1057  Expr_info t_variable, int order) const;
1058 
1068  virtual csl::vector_expr getAlternateForms() const;
1069 
1075  virtual Expr applyOperator(const Expr& operand,
1076  bool leaveEmpty=false) const;
1077 
1078 
1079 
1080 
1081  /*************************************************/
1082  // Members that return new exprs //
1083  // results of specific calculations //
1084  // SPECIFIC TO SOME ABSTRACTS PART //
1085  /*************************************************/
1086 
1088  // Numerical- Polynomial- and Vectorial-types
1090 
1096  virtual Expr addition_own(const Expr& expr) const;
1097 
1103  virtual Expr multiplication_own(const Expr& expr, bool side=1) const;
1104 
1111  virtual Expr division_own(const Expr& expr) const;
1112 
1118  virtual Expr exponentiation_own(const Expr& expr) const;
1119 
1121  // Polynomial type
1123 
1128  virtual Expr getRegularExpression() const;
1129 
1131  // Vectorial type
1133 
1138  virtual Expr tensordot(const Expr& expr) const;
1139 
1144  virtual Expr dot(const Expr& expr) const;
1145 
1150  virtual Expr getSum() const;
1151 
1156  virtual Expr getProduct() const;
1157 
1163  virtual Expr getVectorialModulus() const;
1164 
1170  virtual Expr getSubVectorial(int iExcept) const;
1171 
1178  virtual Expr getSubVectorial(int iExcept, int jExcept) const;
1179 
1185  virtual Expr getSubVectorial(const std::vector<int>& exceptions) const;
1186 
1187  virtual Expr getSubVectorial(
1188  const std::vector<std::vector<int>>& keepIndices) const;
1189 
1190  virtual Expr getSubVectorial(
1191  std::vector<std::vector<int>>::const_iterator begin,
1192  std::vector<std::vector<int>>::const_iterator end) const;
1193 
1199  virtual Expr determinant() const;
1200 
1205  virtual Expr trace() const;
1206 
1214  virtual Expr trace(int axis1, int axis2) const;
1215 
1219  virtual Expr transpose() const;
1220 
1221  virtual Expr hermitian() const;
1222 
1226  virtual Expr symmetrise() const;
1227 
1231  virtual Expr antisymmetrise() const;
1232 
1238  virtual Expr inverseMatrix() const;
1239 
1241  // Indicial
1243 
1244  virtual Expr getCanonicalPermutation() const;
1245 
1249 
1250  virtual Expr applyDiracDelta(const Expr&, const Expr&) const;
1251 
1252 
1253  /*************************************************/
1254  // Operators //
1255  /*************************************************/
1256 
1260  virtual void operator=(double t_value);
1261 
1265  virtual bool operator==(int t_value) const;
1269  virtual bool operator==(double t_value) const;
1273  virtual bool operator!=(int t_value) const;
1277  virtual bool operator!=(double t_value) const;
1278 
1287  virtual bool operator==(Expr_info expr) const = 0;
1288 
1289  int testDummy(Expr_info expr) const;
1290 
1291  inline bool operator==(const Expr_c& expr) const;
1292  inline bool operator==(const Expr& expr) const;
1293  inline bool operator==(const Abstract& other) const;
1294  inline bool operator!=(Expr_info expr) const;
1300  inline bool operator!=(const Expr_c& expr) const;
1301  inline bool operator!=(const Expr& expr) const;
1302  inline bool operator!=(const Abstract& other) const;
1308  virtual Expr const &operator[](int iArg) const;
1309 
1315  virtual Expr& operator[](int iArg);
1316 
1317 
1319  // Comparison operators in terms of simplicity
1320  // For example x < x^2, (y*x+1) > (1+x*y) etc
1322 
1323 
1329  virtual bool operator<(Expr_info expr) const = 0;
1330 
1336  inline bool operator<(const Expr_c& expr) const {
1337  return *this < expr.get();
1338  }
1339 
1345  inline bool operator>(Expr_info expr) const {
1346  return *expr < this;
1347  }
1348 
1349  inline bool operator>(const Expr_c& expr) const {
1350  return *expr < this;
1351  }
1352 
1353  inline bool operator<=(Expr_info expr) const {
1354  return (not this->operator>(expr));
1355  }
1356 
1362  inline bool operator>=(Expr_info expr) const {
1363  return (not this->operator<(expr));
1364  }
1365 
1371  inline bool operator<=(const Expr_c& expr) const {
1372  return operator<=(expr.get());
1373  }
1374 
1375  inline bool operator>=(const Expr_c& expr) const {
1376  return operator>=(expr.get());
1377  }
1378 
1379 };
1380 
1381 
1382 /*************************************************/
1383 // User-functions to create objects defined //
1384 // in this file //
1385 /*************************************************/
1386 
1398 Expr sum_s(
1399  const Expr& leftOperand,
1400  const Expr& rightOperand,
1401  bool explicitSum = false);
1402 
1411 Expr sum_s(const csl::vector_expr& operands, bool explicitSum = false);
1412 
1424 Expr minus_(const Expr& leftOperand, const Expr& rightOperand);
1437 Expr prod_s(const Expr& leftOperand, const Expr& rightOperand, bool explicitProd=0);
1438 
1449 Expr prod_s(const csl::vector_expr& operands, bool explicitProd=false);
1450 
1460 Expr fraction_s(const Expr& leftOperand, const Expr& rightOperand);
1461 
1471 Expr pow_s(const Expr& leftOperand, const Expr& rightOperand);
1472 
1482 Expr pow_s(const Expr& leftOperand, int value);
1483 
1484 Expr sqrt_s(const Expr& operand);
1485 
1486 Expr sqrt_s(int number);
1487 
1500 Expr derivative_s(const Expr& leftOperand, const Expr& rightOperand, int order=1);
1501 Expr derivative_s(const Expr& leftOperand, const Expr& rightOperand, int order, bool empty);
1502 
1503 Expr derivative_s(const Expr& variable, int order=1);
1504 
1505 Expr integral_s(const Expr& leftOperand, const Expr& rightOperand);
1506 Expr integral_s(const Expr& leftOperand, const Expr& rightOperand, bool empty);
1507 Expr integral_s(const Expr& leftOperand, const Expr& rightOperand, bool empty,
1508  const Expr& t_inf, const Expr& t_sup);
1509 Expr integral_s(const Expr& variable);
1510 
1511 
1512 Expr polynomial_s(const Expr& expr, const Expr& t_variable);
1513 
1514 Expr polynomial_s(const csl::vector_expr& operands, const Expr& t_variable);
1515 
1516 
1518 /*************************************************/
1519 // Arithmetic operators //
1520 /*************************************************/
1522 
1530 Expr operator+(const Expr& a, const Expr& b);
1531 
1532 Expr operator-(const Expr& a);
1533 
1541 Expr operator-(const Expr& a, const Expr& b);
1542 
1550 Expr operator*(const Expr& a, const Expr& b);
1551 
1559 Expr operator/(const Expr& a, const Expr& b);
1560 
1568 //Expr operator^(const Expr& a, const Expr& b);
1569 
1573 class Expr: public std::shared_ptr<csl::Abstract> {
1574 
1575 public:
1576 
1577  INHERIT_SHARED_PTR_CONSTRUCTOR(Expr, csl::Abstract)
1578 
1579  Expr (int value);
1580  Expr (long int value);
1581  Expr (long long int value);
1582  Expr (unsigned int value);
1583  Expr (unsigned long int value);
1584  Expr (unsigned long long int value);
1585 
1586  Expr (float value);
1587  Expr (double value);
1588  Expr (long double value);
1589 
1590  inline explicit
1591  operator Expr_info() const {
1592  return get();
1593  }
1594 
1595  inline csl::vector_expr::iterator begin() {
1596  return (**this).begin();
1597  }
1598  inline csl::vector_expr::iterator end() {
1599  return (**this).end();
1600  }
1601  inline csl::vector_expr::const_iterator begin() const {
1602  return (**this).begin();
1603  }
1604  inline csl::vector_expr::const_iterator end() const {
1605  return (**this).end();
1606  }
1607 
1608  template<class Index>
1609  inline Expr &operator[](Index &&index) {
1610  return (**this)[std::forward<Index>(index)];
1611  }
1612 
1613  template<class Index>
1614  inline Expr const &operator[](Index &&index) const {
1615  return (**this)[std::forward<Index>(index)];
1616  }
1617 
1618  Expr& operator+=(Expr const &other) {
1619  return (*this = *this + other);
1620  }
1621 
1622  Expr& operator-=(Expr const &other) {
1623  return (*this = *this - other);
1624  }
1625 
1626  Expr& operator*=(Expr const &other) {
1627  return (*this = *this * other);
1628  }
1629 
1630  Expr& operator/=(Expr const &other) {
1631  return (*this = *this / other);
1632  }
1633 };
1634 
1635 DEFINE_SHARED_PTR_OPERATOR(Expr)
1636 
1637 std::ostream& operator<<(std::ostream& fout, const Expr& obj);
1638 
1639 
1641 /*************************************************/
1642 // Redefinition of operator for Expr alias //
1643 // std::shared_ptr<Abstract>. Allows then to use //
1644 // operator with both syntaxes: //
1645 // (*a op b) AND (a op b) with a and b Expr. //
1646 /*************************************************/
1648 
1651 bool operator==(const Expr& a, const Expr& b);
1652 
1655 bool operator!=(const Expr& a, const Expr& b);
1656 
1659 bool operator>=(const Expr& a, const Expr& b);
1660 
1663 bool operator<=(const Expr& a, const Expr& b);
1664 
1667 bool operator>(const Expr& a, const Expr& b);
1668 
1671 bool operator<(const Expr& a, const Expr& b);
1672 
1675 bool operator|=(const Expr& a, const Expr& b);
1676 
1679 bool operator&=(const Expr& a, const Expr& b);
1680 
1681  inline Expr Abstract::copy() const
1682  {
1683  return copy_unique();
1684  }
1685 
1686  inline bool Abstract::operator==(const Expr_c& expr) const {
1687  return *this == expr.get();
1688  }
1689 
1690  inline bool Abstract::operator==(const Expr& expr) const {
1691  return *this == expr.get();
1692  }
1693 
1694  inline bool Abstract::operator==(const Abstract& other) const {
1695  return *this == other.copy();
1696  }
1697 
1698  inline bool Abstract::operator!=(Expr_info expr) const {
1699  return not (*this == expr);
1700  }
1701 
1707  inline bool Abstract::operator!=(const Expr_c& expr) const {
1708  return *this != expr.get();
1709  }
1710 
1711  inline bool Abstract::operator!=(const Expr& expr) const {
1712  return *this != expr.get();
1713  }
1714 
1715  inline bool Abstract::operator!=(const Abstract& other) const {
1716  return *this != other.copy();
1717  }
1718 } // End of namespace csl
1719 
1720 
1721 #endif
virtual int isPolynomial(Expr_info expr) const
Determines if the expression is a mononomial term in expr, i.e. a term of the form C*expr^n with C in...
Definition: abstract.cpp:940
virtual Expr addition_own(const Expr &expr) const
Contains implementation of special addition for Numerical- and Vectorial-types.
Definition: abstract.cpp:878
bool operator>(Expr_info expr) const
Compares the simplicity of the expression to another.
Definition: abstract.h:1345
virtual Expr const & operator[](int iArg) const
Access operator for multi-argument expressions, equivalent to the function getArgument().
Definition: abstract.cpp:1004
Some useful functions.
virtual ~Abstract()
Destructor.
Definition: abstract.h:96
virtual bool commutesWith(Expr_info expr, int sign=-1) const
Tells if the object commutes with expr.
Definition: abstract.cpp:926
virtual IndexStructure getFreeIndexStructure() const
Definition: abstract.cpp:254
virtual bool isIndexed() const
Definition: abstract.cpp:531
Expr prod_s(const Expr &leftOperand, const Expr &rightOperand, bool explicitProd=0)
Returns the product of the two operands, applying basic simplifications.
Definition: operations.cpp:2246
virtual void getExponents(std::vector< Expr > const &factors, std::vector< Expr > &exponents) const
Fills in a vector the exponents corresponding to some factors for the expression. ...
Definition: abstract.cpp:609
virtual bool getValued() const
Tells if the expression is valued, i.e. is a function of numbers and valued literals (a Variable or C...
Definition: abstract.cpp:180
virtual bool operator<(Expr_info expr) const =0
Compares the simplicity of the expression to another.
virtual Parent getParent() const
For indicial expressions this function returns a pointer to the parent object of type TensorParent (n...
Definition: abstract.cpp:259
Namespace for csl library.
Definition: abreviation.h:34
virtual std::optional< Expr > suppressExponent(Expr const &factor, Expr const &exponent) const
Returns the expression where the factor factor^exponent has been suppressed.
Definition: abstract.cpp:784
Definition: parent.h:439
virtual std::optional< Expr > getComplexModulus() const
Evaluates the modulus in the complex plane of the Abstract and returns it.
Definition: abstract.cpp:672
virtual csl::PrimaryType getPrimaryType() const =0
Gives the primary type of Abstract.
bool operator &=(const Expr &a, const Expr &b)
see Abstract::operator&=()
Index object that is used for indicial objects.
Definition: index.h:75
virtual IndexStructure getIndexStructure() const
Definition: abstract.cpp:222
virtual std::string const & getName() const
Returns the Abstract&#39;s name.
Definition: abstract.cpp:37
virtual Expr inverseMatrix() const
Calculates and returns the inverse of a 2D square matrix. The applied method is: A^{-1} = 1/det(A)*Co...
Definition: abstract.cpp:1194
virtual void setFullySymmetric()
Sets an Indicial object fully symmetric. Allows to set quickly a frequent property of tensors...
Definition: abstract.cpp:384
virtual long double getValue() const
Returns the value of the expression, if it has one explicitely. In particular, it will work only on N...
Definition: abstract.cpp:572
virtual Expr getNumericalFactor() const
Returns the numerical factor of the expression, i.e. returns C if the expression if of the form C*x (...
Definition: abstract.cpp:589
bool operator<=(const Expr &a, const Expr &b)
see Abstract::operator<=()
Definition: abstract.cpp:1416
virtual bool askTerm(Expr_info expr, bool exact=false) const
Check if expr can factor *this.
Definition: abstract.cpp:741
Type
Enum of the different types of Abstract (i.e. list of all possible specializations).
Definition: enum.h:47
virtual std::optional< Expr > expand(bool full=false, bool inPlace=false) const
Develops the Abstract.
Definition: abstract.cpp:746
virtual Expr getProduct() const
Calculates and returns the product of all elements in the Vectorial object.
Definition: abstract.cpp:1089
virtual long double evaluateScalar() const
Evaluates the value of the Abstract.
Definition: abstract.cpp:871
virtual Expr transpose() const
Calculates and returns the transpose of a 2D matrix.
Definition: abstract.cpp:1166
virtual int getOrder() const
Accessor to the order (integer) that defines certain types of expressions.
Definition: abstract.cpp:621
virtual std::set< std::pair< int, int > > getContractedPair() const
Definition: abstract.cpp:429
virtual void print(int mode=0, std::ostream &out=std::cout, bool lib=false) const =0
Displays the abstract in standard output.
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
bool operator|=(const Expr &a, const Expr &b)
see Abstract::operator|=()
virtual Expr suppressTerm(Expr_info expr) const
Remove a factor from an expr, that must have been determined before.
Definition: abstract.cpp:779
virtual int getParity(Expr_info t_variable) const
Returns the parity property of the expression with respect to t_variable.
Definition: abstract.cpp:960
virtual Expr getRegularExpression() const
Returns a regular expression from the polynomial, that is a sum where the different powers of the var...
Definition: abstract.cpp:965
virtual int permut(int i1, int i2)
Tries to permut indices at place i1 and i2. If those two indices have a symmetry property, indices are swaped and the symmetry is returned. Else the fnuction does nothing and returns 0.
Definition: abstract.cpp:415
virtual long long int getNum() const
Definition: abstract.cpp:187
virtual std::vector< int > getShape() const
Accessor to the shape of the tensor in the form of a std::vector of integers.
Definition: abstract.cpp:436
virtual std::optional< Expr > collect(std::vector< Expr > const &factors, bool full=false) const
Collects terms in sum according to some factors given by the user.
Definition: abstract.cpp:766
Definition: alloc_monitor.h:70
virtual Expr dot(const Expr &expr) const
Returns the dot product of two Vectorial expressions.
Definition: abstract.cpp:1075
Abstract()
Default Constructor.
Definition: abstract.h:92
virtual Expr trace() const
Definition: abstract.cpp:1152
virtual std::optional< Expr > expand_if(std::function< bool(Expr const &)> const &f, bool full=false, bool inPlace=false) const
Develops the Abstract.
Definition: abstract.cpp:750
virtual std::optional< Expr > replaceIndex(const Index &indexToReplace, const Index &newIndex, bool refresh=true) const
For indicial expressions, this function searches indexToContract and replaces it with newIndex...
Definition: abstract.cpp:280
virtual Expr exponentiation_own(const Expr &expr) const
Contains implementation of special exponentiation for Numerical- and Vectorial-types.
Definition: abstract.cpp:899
virtual bool checkIndexStructure(const std::vector< Index > &t_index) const
Checks the compatibility of the index structure of an Indicial expression with another. In a sum, two terms must have exaclty the same index structure.
virtual bool hasContractionProperty(Expr_info B) const
Tells (for an Indicial type) if there is a special contraction property with B.
Definition: abstract.cpp:1037
virtual csl::vector_expr::iterator end()
Definition: abstract.cpp:468
virtual const std::vector< Equation * > & getProperties() const
Definition: abstract.cpp:87
virtual void addAntiSymmetry(int i1, int i2)
Add an anti-symmetry between the i1^{th} and the i2^{th} indices. If those indices are symmetric...
Definition: abstract.cpp:402
bool operator<(const Expr_c &expr) const
Compares the simplicity of the expression to another.
Definition: abstract.h:1336
File containing functions that are called by the program when something wrong happened: determines th...
virtual std::optional< Expr > getComplexArgument() const
Evaluates the argument in the complex plane of the Abstract and returns it.
Definition: abstract.cpp:677
virtual Index getIndex(int i=0) const
Definition: abstract.cpp:210
virtual std::optional< Expr > factor(bool full=false) const
Factors the Abstract.
Definition: abstract.cpp:757
virtual void operator=(double t_value)
Equivalent to the setValue() function.
Definition: abstract.cpp:972
bool operator>=(Expr_info expr) const
Compares the simplicity of the expression to another.
Definition: abstract.h:1362
Definition: diagonalization.h:34
virtual void setArgument(const Expr &expr, int iArg=0)
Sets the argument at position iArg (default=0).
Definition: abstract.cpp:830
Some of csl enumerations.
virtual void removeProperty(Equation *property)
Removes a property to the object.
Definition: abstract.cpp:378
ComplexProperty
Contains all possible complex properties of objects. Real, purely imaginary, or complex.
Definition: enum.h:127
virtual long long int getDenom() const
Definition: abstract.cpp:192
Definition: librarydependency.h:33
Expr fraction_s(const Expr &leftOperand, const Expr &rightOperand)
Returns the fraction of the two operands, applying basic simplifications.
Definition: operations.cpp:2393
virtual bool operator==(int t_value) const
Definition: abstract.cpp:988
virtual Expr tensordot(const Expr &expr) const
Returns the tensordot of two Vectorial expressions.
Definition: abstract.cpp:1068
virtual void addSymmetry(int i1, int i2)
Add a symmetry between the i1^{th} and the i2^{th} indices. If those indices are anti-symmetric, an error is thrown.
Definition: abstract.cpp:396
virtual std::optional< Expr > getRealPart() const
Evaluates the real part of the Abstract and returns it.
Definition: abstract.cpp:662
virtual void setValue(long double t_value)
Sets the value if there is one (for Numerical and Literal valued).
Definition: abstract.cpp:794
PrimaryType
Stores enumerations of types for Abstract objects.
Definition: enum.h:31
virtual int getNIndices() const
Definition: abstract.cpp:203
virtual csl::vector_expr getAlternateForms() const
Calculates and returns all possible alternate forms of the expression in terms of simplifications...
Definition: abstract.cpp:1017
void printExplicit(int mode=0) const
Displays explicitely the expression, with types of each component. This function is only used for deb...
Definition: abstract.cpp:154
virtual void setCommutable(bool t_commutable)
Allows the abstract to commute or not.
Definition: abstract.cpp:62
Expr pow_s(const Expr &leftOperand, const Expr &rightOperand)
Returns the exponentiation of the two operands, applying basic simplifications.
Definition: operations.cpp:2978
Expr minus_(const Expr &leftOperand, const Expr &rightOperand)
Returns the sum of the two operands (with a minus sign), applying basic simplifications.
Definition: operations.cpp:1030
virtual void setFullyAntiSymmetric()
Sets an Indicial object fully anti-symmetric. Allows to set quickly a frequent property of tensors...
Definition: abstract.cpp:390
virtual int getNContractedPairs() const
Returns the number of contracted pairs of indices in an Indicial expression.
Definition: abstract.cpp:408
Root class of the inheritance tree of abstracts.
Definition: abstract.h:76
virtual void setVectorArgument(const csl::vector_expr &t_argument)
Replaced the entire std::vector of argument.
Definition: abstract.cpp:859
virtual csl::vector_expr getFactors() const
Allows to get a std::vector of all terms than could factor the expression.
Definition: abstract.cpp:599
Expr operator/(const Expr &a, const Expr &b)
Shortcut function that allows to use arithmetic operator / with Expr (== shared_ptr<Abstract>).
Definition: abstract.cpp:1372
virtual int getNArgs(int axis=0) const
Returns the number of arguments of the expression. If the expression is a building block (AbstractBui...
Definition: abstract.cpp:197
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
virtual std::optional< Expr > findSubExpression(Expr_info subExpression, const Expr &newExpression) const
Searches a sub-expression and replaces it.
Definition: abstract.cpp:931
virtual void addProperty(Equation *property)
Adds a property to the object.
Definition: abstract.cpp:372
virtual Expr getSum() const
Calculates and returns the sum of all elements in the Vectorial object.
Definition: abstract.cpp:1082
virtual bool isBuildingBlock() const
Tells if the expression is a Building Block or not.
Definition: abstract.cpp:519
virtual Expr contraction(Expr_info B) const
Applies a special contraction of indices. Before calling this function we must check that there is in...
Definition: abstract.cpp:1054
Vector space that has a name, a dimension, a delta tensor and possibly a non-trivial metric...
Definition: space.h:64
virtual bool compareWithDummy(Expr_info expr, std::map< Index, Index > &constraints, bool keepAllCosntraints=false) const
Comparison disregarding name of dummy indices, i.e. the two expressions * are equals even if dummy in...
Base class for all parents (indicial, fields etc). All parents derive from this class.
Definition: parent.h:81
virtual bool isEmpty() const
Tells for a Derivative or an Integral if the argument is empty i.e. if the object must apply on the n...
Definition: abstract.cpp:640
Contains evaluation flags for csl.
virtual bool dependsExplicitlyOn(Expr_info expr) const
Check recursively if expr is present in the expression.
Definition: abstract.cpp:916
virtual Expr symmetrise() const
Calculates and returns the symmetrization of a 2D matrix.
Definition: abstract.cpp:1180
virtual Expr const & getArgument(int iArg=0) const
Definition: abstract.cpp:489
virtual bool isInteger() const
Tells if the expression is an integer. Either an Integer object directly, or a Float that has an inte...
Definition: abstract.cpp:568
virtual void setName(const std::string &t_name)
Change the name of the abstract.
Definition: abstract.cpp:57
virtual Expr multiplication_own(const Expr &expr, bool side=1) const
Contains implementation of special multiplication for Numerical- and Vectorial-types.
Definition: abstract.cpp:885
virtual bool getCommutable() const
Allows to know if the object commutes with all the others.
Definition: abstract.cpp:47
virtual int getNFactor() const
Definition: abstract.cpp:594
virtual int getSign() const
Definition: abstract.cpp:628
virtual bool dependsOn(Expr_info expr) const
Check recursively if the expression depends on expr.
Definition: abstract.cpp:906
virtual Expr determinant() const
Returns the determinant of the object if it corresponds to a square matrix (or a scalar), 0 else.
Definition: abstract.cpp:1145
virtual void setOperandPrivate(const Expr &operand, bool leaveEmpty)
Sets the operand of an operator.
Definition: abstract.cpp:848
Expr derivative_s(const Expr &leftOperand, const Expr &rightOperand, int order=1)
Returns the derivative of leftOperand wrt rightOperand, applying basic simplifications.
Definition: operations.cpp:3784
virtual Expr getSubVectorial(int iExcept) const
Allows to pick a part of a Vectorial expression, excluding the iExcept^{th} element.
Definition: abstract.cpp:1103
virtual Expr getImaginaryPart() const
Evaluates the imaginary part of the Abstract and returns it.
Definition: abstract.cpp:667
virtual int getDim() const
Gives the dimension of the object.
Definition: abstract.cpp:68
virtual Expr antisymmetrise() const
Calculates and returns the anti-symmetrization of a 2D matrix.
Definition: abstract.cpp:1187
virtual std::string printLaTeX(int mode=0) const
Creates a LaTeX output for the Abstract.
Definition: abstract.cpp:168
virtual Expr applyOperator(const Expr &operand, bool leaveEmpty=false) const
Apply the operator on an operand, iif the expression is an operator.
Definition: abstract.cpp:1022
virtual std::optional< Expr > getPolynomialTerm(Expr_info t_variable, int order) const
Calculates and returns the polynomial term corresponding to *this with the variable t_variable at ord...
Definition: abstract.cpp:950
Definition: equation.h:43
virtual bool operator!=(int t_value) const
Definition: abstract.cpp:978
virtual Expr getVariable() const
Accessor to the variable that defines certain types of expressions.
Definition: abstract.cpp:945
virtual csl::Type getType() const =0
Gives the type of Abstract.
virtual std::optional< Expr > getTerm() const
This function returns the same expression as *this but amputated of its numerical factor...
Definition: abstract.cpp:604
virtual void setOperand(const Expr &operand)
Sets the operand of an operator.
Definition: abstract.cpp:854
virtual csl::vector_expr getPermutations(bool optimize=true) const
Returns a std::vector of all possible permutations of an Indicial expression. The possible permutatio...
Definition: abstract.cpp:422
virtual Expr division_own(const Expr &expr) const
Contains implementation of special division for Numerical- and Polynomial-types. For polynomial...
Definition: abstract.cpp:892
virtual csl::vector_expr::iterator begin()
Definition: abstract.cpp:461
Definition: indicial.h:675
Manages a std::vector of Index, to be used by an TensorElement.
Definition: index.h:472
virtual bool isAnOperator() const
Tells if the expression is an operator (like a derivetive operator).
Definition: abstract.cpp:635
virtual std::optional< Expr > evaluate(csl::eval::mode user_mode=csl::eval::base) const =0
Evaluates the Abstract.
virtual std::optional< Expr > derive(Expr_info expr) const
Calculates the derivative of the Abstract wrt another.
Definition: abstract.cpp:774
virtual std::optional< Expr > getComplexConjugate() const
Calculates and returns the complex conjugate of the expression.
Definition: abstract.cpp:682
bool operator<=(const Expr_c &expr) const
Compares the simplicity of the expression to another.
Definition: abstract.h:1371
virtual void setIndexStructure(const IndexStructure &t_index)
Replaces the index structure of the object, that must be an Indicial expression.
Definition: abstract.cpp:331
virtual void insert(const Expr &expr, bool side=1)
Inserts an expression in a sum or a product.
Definition: abstract.cpp:735
virtual Expr getVectorialModulus() const
Returns the Vectorial modulus of the Vectorial object, that is defined here as the squared root of th...
Definition: abstract.cpp:1096
virtual bool matchShape(Expr_info expr, bool exact=false) const
In the case of a vectorial-type expression, this function checks if the shape of expr matches itself...
Definition: abstract.cpp:1030
Expression type/.
Definition: abstract.h:1573
virtual const csl::vector_expr & getVectorArgument() const
Allows to get the entire std::vector of arguments of the expression.
Definition: abstract.cpp:441
virtual Expr getOperand() const
Returns the operand of an Operator.
Definition: abstract.cpp:654