21 #ifndef OPERATIONS_H_INCLUDED 22 #define OPERATIONS_H_INCLUDED 44 Sum(
const csl::vector_expr& operands,
bool explicitSum=
false);
51 const Expr& rightOperand,
52 bool explicitSum =
false);
56 ~
Sum(){ __record_data_alloc(static_cast<int>(
getType())); }
66 virtual bool isIndexed()
const override {
return false; }
72 int getOrderOf(
Expr_info expr)
const override;
76 std::optional<Expr>
getTerm()
const override;
91 void insert(
const Expr& expr,
bool explicitSum=
false)
override;
93 void print(
int mode=0,
94 std::ostream& out=std::cout,
95 bool lib =
false)
const override;
99 std::ostream& out=std::cout
102 std::string
printLaTeX(
int mode=0)
const override;
112 csl::eval::mode user_mode = csl::eval::base
115 unique_Expr copy_unique()
const override;
117 Expr deepCopy()
const override;
119 Expr refresh()
const override;
121 Expr deepRefresh()
const override;
142 std::optional<Expr>
factor(
bool full=
false)
const override;
148 std::optional<Expr>
factor(
Expr_info expr,
bool full=
false)
const override;
151 std::vector<Expr>
const &factors,
165 bool operator<(
const Abstract* expr)
const override;
169 virtual void gatherFactors(
170 csl::vector_expr& factors,
171 csl::vector_expr& arg,
175 void clearRedundantFactors(csl::vector_expr& factors)
const;
205 Polynomial(
const csl::vector_expr& terms,
const Expr& t_variable);
223 int getOrderOf(
Expr_info expr)
const override;
231 void print(
int mode=0,
232 std::ostream& out=std::cout,
233 bool lib =
false)
const override;
237 std::ostream& out=std::cout
240 std::string
printLaTeX(
int mode=0)
const override;
250 csl::eval::mode user_mode = csl::eval::base
253 unique_Expr copy_unique()
const override;
255 Expr deepCopy()
const override;
257 Expr refresh()
const override;
259 Expr deepRefresh()
const override;
277 std::optional<Expr>
factor(
bool full=
false)
const override;
302 Prod(
const csl::vector_expr& t_argument,
bool explicitProd=0);
310 Prod(
const Expr& leftOperand,
const Expr& rightOperand,
bool explicitProd=0);
314 ~
Prod(){ __record_data_alloc(static_cast<int>(
getType())); }
324 virtual bool isIndexed()
const override {
return false; }
326 int getOrderOf(
Expr_info expr)
const override;
340 std::optional<Expr> getHermitianConjugate(
341 const Space* space)
const override;
343 std::optional<Expr> getHermitianConjugate(
344 const std::vector<const Space*>& spaces)
const override;
348 const Expr& newExpression)
const override;
356 std::optional<Expr>
getTerm()
const override;
369 std::vector<Expr>
const &factors,
370 std::vector<Expr> &exponents
393 void insert(
const Expr& expr,
bool side=1)
override;
394 virtual void leftInsert(
const Expr& expr);
395 virtual void rightInsert(
const Expr& expr);
397 void print(
int mode=0,
398 std::ostream& out=std::cout,
399 bool lib =
false)
const override;
403 std::ostream &out = std::cout
406 std::string
printLaTeX(
int mode=0)
const override;
416 csl::eval::mode user_mode = csl::eval::base
419 unique_Expr copy_unique()
const override;
421 Expr deepCopy()
const override;
423 Expr refresh()
const override;
425 Expr deepRefresh()
const override;
427 bool mergeNumericals();
429 void mergeProducts();
451 std::optional<Expr>
expand(
bool full=
false,
452 bool inPlace=
false)
const override;
463 std::function<
bool(
Expr const&)>
const& f,
465 bool inPlace=
false)
const override;
470 Expr_info t_variable,
int order)
const override;
476 virtual bool partialComparison(
Expr_info expr)
const;
499 const Expr& rightOperand,
500 bool explicitPow =
false);
504 ~
Pow(){ __record_data_alloc(static_cast<int>(
getType())); }
516 std::optional<Expr>
getTerm()
const override;
518 int getOrderOf(
Expr_info expr)
const override;
532 std::vector<Expr>
const &factors,
533 std::vector<Expr> &exponents
556 void print(
int mode=0,
557 std::ostream& out=std::cout,
558 bool lib =
false)
const override;
562 std::ostream &out = std::cout
565 std::string
printLaTeX(
int mode=0)
const override;
577 csl::eval::mode user_mode = csl::eval::base
580 unique_Expr copy_unique()
const override;
582 Expr deepCopy()
const override;
584 Expr refresh()
const override;
586 Expr deepRefresh()
const override;
606 std::optional<Expr>
expand(
bool full=
false,
607 bool inplace=
false)
const override;
618 std::function<
bool(
Expr const&)>
const& f,
620 bool inplace=
false)
const override;
625 Expr_info t_variable,
int order)
const override;
674 int t_order,
bool t_empty);
696 void print(
int mode=0,
697 std::ostream& out=std::cout,
698 bool lib =
false)
const override;
702 std::ostream &out = std::cout
705 std::string
printLaTeX(
int mode=0)
const override;
715 csl::eval::mode user_mode = csl::eval::base
718 unique_Expr copy_unique()
const override;
720 Expr deepCopy()
const override;
722 Expr refresh()
const override;
724 Expr deepRefresh()
const override;
734 bool operatorAppliesOn(
Expr_info expr)
const override;
759 const Expr& t_inf,
const Expr& t_sup);
762 const Expr& t_inf,
const Expr& t_sup);
780 Expr getSupBoundary()
const override;
782 Expr getInfBoundary()
const override;
786 void print(
int mode=0,
787 std::ostream& out=std::cout,
788 bool lib =
false)
const override;
792 std::ostream &out = std::cout
795 std::string
printLaTeX(
int mode=0)
const override;
801 Expr evaluateIntegral()
const;
804 csl::eval::mode user_mode = csl::eval::base
807 unique_Expr copy_unique()
const override;
809 Expr deepCopy()
const override;
811 Expr refresh()
const override;
813 Expr deepRefresh()
const override;
819 bool operatorAppliesOn(
Expr_info expr)
const override;
856 argument[1] = t_variable;
859 const Expr& rightOperand)
862 argument[0] = leftOperand;
863 argument[1] = rightOperand;
864 if (*argument[1] != CSL_1)
868 const Expr& rightOperand,
872 argument[0] = leftOperand;
873 argument[1] = rightOperand;
874 if (*argument[1] != CSL_1)
878 int t_order,
bool t_empty)
881 argument[0] = leftOperand;
882 argument[1] = rightOperand;
893 inline Integral::Integral(
const Expr& t_variable)
896 argument[1] = t_variable;
898 Expr tensor_s(
const std::vector<int>& shape,
const Expr& filler);
899 inline Integral::Integral(
const Expr& leftOperand,
const Expr& rightOperand)
905 argument[0] = leftOperand;
906 argument[1] = rightOperand;
909 if (*argument[1] != CSL_1)
913 inline Integral::Integral(
const Expr& leftOperand,
const Expr& rightOperand,
914 bool t_empty):
Integral(leftOperand, rightOperand)
918 inline Integral::Integral(
const Expr& leftOperand,
const Expr& rightOperand,
919 const Expr& t_inf,
const Expr& t_sup)
924 argument[0] = leftOperand;
925 argument[1] = rightOperand;
926 if (*argument[1] != CSL_1)
930 inline Integral::Integral(
const Expr& leftOperand,
const Expr& rightOperand,
931 bool t_empty,
const Expr& t_inf,
const Expr& t_sup)
932 :
Integral(leftOperand, rightOperand, t_inf, t_sup)
937 inline csl::allocator<Sum> alloc_sum;
938 inline csl::allocator<Prod> alloc_prod;
939 inline csl::allocator<Pow> alloc_pow;
virtual Expr addition_own(const Expr &expr) const
Contains implementation of special addition for Numerical- and Vectorial-types.
Definition: abstract.cpp:878
std::optional< Expr > findSubExpression(Expr_info subExpression, const Expr &newExpression) const override
Searches a sub-expression and replaces it.
Definition: scalarFunc.cpp:739
Polynomial()
Default constructor. Initializes argument to an empty std::vector, order to 0.
Definition: operations.h:843
Expr getNumericalFactor() const override
Definition: operations.cpp:530
int getParity(Expr_info t_variable) const override
Returns the parity property of the expression with respect to t_variable.
Definition: operations.cpp:893
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
Namespace for csl library.
Definition: abreviation.h:34
void insert(const Expr &expr, bool explicitSum=false) override
Inserts an expression in a sum or a product.
Definition: operations.cpp:129
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
Handle functions of multiple arguments. In the case of the call of a simplification function...
Definition: scalarFunc.h:199
Handles a sum, function of multiple arguments.
Definition: operations.h:33
bool askTerm(Expr_info term, bool exact=false) const override
Check if expr can factor *this.
Definition: operations.cpp:866
std::string printLaTeX(int mode=0) const override
Creates a LaTeX output for the Abstract.
Definition: operations.cpp:224
Expr suppressTerm(Expr_info term) const override
Remove a factor from an expr, that must have been determined before.
Definition: operations.cpp:880
virtual IndexStructure getIndexStructure() const
Definition: abstract.cpp:222
Handles a product, function of multiple arguments.
Definition: operations.h:289
Type
Enum of the different types of Abstract (i.e. list of all possible specializations).
Definition: enum.h:47
Expr getImaginaryPart() const override
Evaluates the imaginary part of the Abstract and returns it.
Definition: operations.cpp:99
Definition: operations.h:741
std::optional< Expr > factor(bool full=false) const override
Factors the expr if common factors are found.
Definition: operations.cpp:689
virtual int getOrder() const
Accessor to the order (integer) that defines certain types of expressions.
Definition: abstract.cpp:621
virtual bool isIndexed() const override
Definition: operations.h:324
std::optional< Expr > evaluate(csl::eval::mode user_mode=csl::eval::base) const override
Evaluates the Abstract.
Definition: operations.cpp:254
csl::Type getType() const override
Gives the type of a Derivative object.
Definition: operations.h:684
csl::vector_expr argument
std::vector containing the arguments.
Definition: scalarFunc.h:349
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
Pow()
Default constructor. Initializes both arguments to 0.
Definition: operations.h:844
virtual bool mergeTerms()
Merge identical terms.
Definition: operations.cpp:324
const csl::Expr CSL_INF
Represents infinity in the program.
Definition: literal.h:607
std::optional< Expr > getComplexArgument() const override
Evaluates the argument in the complex plane of the Abstract and returns it.
Definition: operations.cpp:121
void print(int mode=0, std::ostream &out=std::cout, bool lib=false) const override
Displays the abstract in standard output.
Definition: operations.cpp:182
bool dependsExplicitlyOn(Expr_info expr) const override
Check recursively if expr is present in the expression.
Definition: scalarFunc.cpp:1061
csl::Type getType() const override
Gives the type of a Polynomial object.
Definition: operations.h:217
Sum()
Default constructor. Initializes argument to an empty std::vector.
Definition: operations.h:841
long double evaluateScalar() const override
Return the sum of all the arguments.
Definition: operations.cpp:242
csl::Type getType() const override
Gives the type of a Integral object.
Definition: operations.h:772
virtual bool isIndexed() const override
Definition: operations.h:66
Generic template to handle operator expression, i.e. expression that applies on expressions on the ri...
csl::Type getType() const override
Gives the type of a Sum object.
Definition: operations.h:62
Definition: librarydependency.h:33
std::optional< Expr > derive(Expr_info expr) const override
Derives the sum.
Definition: operations.cpp:514
Prod()
Default constructor. Initializes argument to an empty std::vector.
Definition: operations.h:842
std::optional< Expr > getRealPart() const override
Evaluates the real part of the Abstract and returns it.
Definition: operations.cpp:85
std::optional< Expr > getTerm() const override
Definition: operations.cpp:560
bool dependsOn(Expr_info expr) const override
Check recursively if the expression depends on expr.
Definition: scalarFunc.cpp:1037
Root class of the inheritance tree of abstracts.
Definition: abstract.h:76
virtual std::optional< Expr > expand(bool full=false, bool inPlace=false) const override
Develops the Abstract.
Definition: scalarFunc.cpp:995
Handles a polynomial, function of multiple arguments.
Definition: operations.h:181
std::optional< Expr > collect(std::vector< Expr > const &factors, bool full) const override
Collects terms in sum according to some factors given by the user.
Definition: operations.cpp:774
Handles the exponentiation of one Abstract wrt another.
Definition: operations.h:486
Base classes for scalar functions.
Vector space that has a name, a dimension, a delta tensor and possibly a non-trivial metric...
Definition: space.h:64
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 int getNFactor() const
Definition: abstract.cpp:594
csl::vector_expr getFactors() const override
Returns all the possible factors.
Definition: operations.cpp:575
Handles the exponentiation of one Abstract wrt another.
Definition: operations.h:640
Handle functions of multiple arguments. In the case of the call of a simplification function...
Definition: scalarFunc.h:345
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
virtual Expr getVariable() const
Accessor to the variable that defines certain types of expressions.
Definition: abstract.cpp:945
Derivative()
Default constructor. Initializes both arguments to 0, order to 1.
Definition: operations.h:846
virtual void setOperand(const Expr &operand)
Sets the operand of an operator.
Definition: abstract.cpp:854
csl::Type getType() const override
Gives the type of a Prod object.
Definition: operations.h:320
virtual Expr division_own(const Expr &expr) const
Contains implementation of special division for Numerical- and Polynomial-types. For polynomial...
Definition: abstract.cpp:892
csl::vector_expr getAlternateForms() const override
Calculates and returns all possible alternate forms of the expression in terms of simplifications...
Definition: alternateForms.cpp:277
bool operator<(const Expr &a, const Expr &b)
see Abstract::operator<()
Definition: abstract.cpp:1423
Linear operator O(a*X+b*Y) = a*O(X) + b*O(Y)
Definition: operator.h:38
Manages a std::vector of Index, to be used by an TensorElement.
Definition: index.h:472
bool operator==(Expr_info expr) const override
Compares the Abstract with another.
Definition: operations.cpp:908
csl::Type getType() const override
Gives the type of a Pow object.
Definition: operations.h:510
std::optional< Expr > getComplexModulus() const override
Evaluates the modulus in the complex plane of the Abstract and returns it.
Definition: operations.cpp:111
virtual std::optional< Expr > expand_if(std::function< bool(Expr const &)> const &f, bool full=false, bool inPlace=false) const override
Develops the Abstract.
Definition: scalarFunc.cpp:1019
Expression type/.
Definition: abstract.h:1573
virtual Expr getOperand() const
Returns the operand of an Operator.
Definition: abstract.cpp:654
int isPolynomial(Expr_info expr) const override
Determines if the expression is a mononomial term in expr, i.e. a term of the form C*expr^n with C in...
Definition: scalarFunc.cpp:1090