Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
List of all members

#include <deal.II/differentiation/sd/symengine_number_types.h>

Public Member Functions

Constructors
 Expression ()
 
 Expression (const bool value)
 
template<typename NumberType , typename = typename std::enable_if< std::is_arithmetic<NumberType>::value>::type>
 Expression (const NumberType &value)
 
template<typename NumberType , typename = typename std::enable_if< std::is_arithmetic<NumberType>::value>::type>
 Expression (const std::complex< NumberType > &value)
 
 Expression (const SymEngine::integer_class &value)
 
template<typename NumberType , typename = typename std::enable_if< std::is_integral<NumberType>::value>::type>
 Expression (const NumberType &numerator, const NumberType &denominator)
 
 Expression (const SymEngine::rational_class &value)
 
 Expression (const Expression &condition, const Expression &expression_if_true, const Expression &expression_if_false)
 
 Expression (const std::vector< std::pair< Expression, Expression >> &condition_expression, const Expression &expression_otherwise)
 
 Expression (const std::vector< std::pair< Expression, Expression >> &condition_expression)
 
 Expression (const char *symbol)
 
 Expression (const std::string &symb_expr, const bool parse_as_expression=false)
 
 Expression (const std::string &symbol_func, const types::symbol_vector &arguments)
 
 Expression (const Expression &rhs)=default
 
 Expression (const SymEngine::Expression &rhs)
 
 Expression (const SymEngine::RCP< const SymEngine::Basic > &rhs)
 
 Expression (Expression &&rhs)=default
 
 Expression (SymEngine::RCP< const SymEngine::Basic > &&rhs)
 
virtual ~Expression ()=default
 
Expressionparse (const std::string &expression)
 
std::ostream & print (std::ostream &stream) const
 
void save (std::ostream &stream) const
 
void load (std::istream &stream)
 
template<class Archive >
void save (Archive &archive, const unsigned int version) const
 
template<class Archive >
void load (Archive &archive, const unsigned int version)
 
template<class Archive >
void serialize (Archive &archive, const unsigned int version)
 
Values
const SymEngine::Expression & get_expression () const
 
const SymEngine::Basic & get_value () const
 
const SymEngine::RCP< const SymEngine::Basic > & get_RCP () const
 
Math and relational operators with (potentially) symbolic types
Expressionoperator= (const Expression &rhs)
 
Expressionoperator= (Expression &&rhs) noexcept
 
Expressionoperator+= (const Expression &rhs)
 
Expressionoperator-= (const Expression &rhs)
 
Expressionoperator*= (const Expression &rhs)
 
Expressionoperator/= (const Expression &rhs)
 
Math and relational operators with numeric types
template<typename NumberType >
Expressionoperator= (const NumberType &rhs)
 
Expression operator- () const
 
template<typename NumberType >
Expressionoperator+= (const NumberType &rhs)
 
template<typename NumberType >
Expressionoperator-= (const NumberType &rhs)
 
template<typename NumberType >
Expressionoperator*= (const NumberType &rhs)
 
template<typename NumberType >
Expressionoperator/= (const NumberType &rhs)
 
Differentiation
Expression differentiate (const Expression &symbol) const
 
Expression differentiate (const SymEngine::RCP< const SymEngine::Symbol > &symbol) const
 
Expression differentiate (const SymEngine::RCP< const SymEngine::Basic > &symbol) const
 
Dictionary-based substitution
Expression substitute (const types::substitution_map &substitution_values) const
 
Expression substitute (const SymEngine::map_basic_basic &substitution_values) const
 
Expression substitute (const Expression &symbol, const Expression &value) const
 
template<typename NumberType >
Expression substitute (const Expression &symbol, const NumberType &value) const
 
template<typename ReturnType >
ReturnType substitute_and_evaluate (const types::substitution_map &substitution_values) const
 
template<typename ReturnType >
ReturnType substitute_and_evaluate (const SymEngine::map_basic_basic &substitution_values) const
 

Conversion operators

SymEngine::Expression expression
 
template<typename ResultType >
 operator ResultType () const
 
 operator const SymEngine::Expression & () const
 
 operator const SymEngine::RCP< const SymEngine::Basic > & () const
 
SymEngine::Expression & get_expression ()
 

Detailed Description

A class to wrap SymEngine expressions.

With this number type, SymEngine numbers can be used to perform scalar and tensor mathematics in deal.II. It (or the SymEngine::Expression class, of which it stores an instance) therefore forms the basis of symbolic computation via SymEngine in deal.II. With it one can perform symbolic differentiation and subsequent substitution with both scalars and deal.II's native Tensor and SymmetricTensor types.

The symbolic features that this class supports includes:

A simple example of how this class may be used is as follows:

// Constructing a symbolic expression:
// This is a symbol, which we will treat as an argument to a symbolic
// function.
const Expression x("x");
const Expression y("y");
// This is a symbolic expression, which is an expression constructed
// from individual symbols.
const Expression f = (x + y)*(x + y);
// Value substitution
const double evaluated_f =
f.substitute_and_evaluate<double>(substitution_map);
// We could also have performed substitution of each individual
// argument, if we wanted to. This means that one can partially
// substitute an expression at any time.

A more intricate example of conditional evaluation is as follows:

// Construct symbolic expressions
const Expression x("x");
const Expression y("y");
const Expression f_plus = (x + y)*(x + y);
// Parsing expressions from a string is also possible. Its arguments
// must have been previously declared through (and in scope).
const Expression f_minus ("(x-y)*(x-y)", true);
// Constructing a conditional expression
const SD_number_t f((x > Expression(0.0)), f_plus, f_minus);
// Value substitution
const double evaluated_f =
f.substitute_and_evaluate<double>(substitution_map);
// Since the substituted value for x was greater than zero, we expect
// that the returned result now in evaluated_f was evaluated from
// the function f_plus.

Lastly, here is an example using symbolic differentiation:

// Construct symbolic expressions
const Expression x("x");
const Expression f("x**2", true);
// Now perform differentiation. Specifically, we differentiate the
// function "f" with respect to the symbolic variable "x".
// The result should be the expression "2*x".
const Expression df_dx = f.differentiate(x);
// Value substitution
const double evaluated_df_dx =
evaluated_df_dx.substitute_and_evaluate<double>(substitution_map);
// We can expect the above to evaluate to "2*10" which is,
// of course, the numeric value 20.
Author
Jean-Paul Pelteret, 2019

Definition at line 179 of file symengine_number_types.h.


The documentation for this class was generated from the following files:
Differentiation::SD::types::substitution_map
std::map< SD::Expression, SD::Expression, internal::ExpressionKeyLess > substitution_map
Definition: symengine_types.h:62
Differentiation::SD::Expression::Expression
Expression()
Definition: symengine_number_types.cc:48