16#ifndef dealii_differentiation_sd_symengine_number_types_h
17#define dealii_differentiation_sd_symengine_number_types_h
21#ifdef DEAL_II_WITH_SYMENGINE
24# include <symengine/basic.h>
25# include <symengine/dict.h>
26# include <symengine/symengine_exception.h>
27# include <symengine/symengine_rcp.h>
30# include <symengine/expression.h>
31# include <symengine/integer.h>
32# include <symengine/logic.h>
33# include <symengine/number.h>
34# include <symengine/rational.h>
37# include <symengine/add.h>
38# include <symengine/functions.h>
39# include <symengine/mul.h>
40# include <symengine/pow.h>
43# include <symengine/eval.h>
44# include <symengine/eval_arb.h>
45# include <symengine/eval_double.h>
54# include <boost/serialization/split_member.hpp>
56# include <symengine/derivative.h>
61# include <type_traits>
83 <<
"The string '" << arg1
84 <<
"' could not be parsed successfully. Are you sure that (1) it "
85 <<
"consists of legitimate operations and syntax, and (2) you've "
86 <<
"previously declared all symbolic variables that are present "
87 <<
"in the expression?");
208 typename = std::enable_if_t<std::is_arithmetic<NumberType>::value>>
220 typename = std::enable_if_t<std::is_arithmetic<NumberType>::value>>
226 Expression(
const SymEngine::integer_class &value);
236 typename = std::enable_if_t<std::is_integral<NumberType>::value>>
237 Expression(
const NumberType &numerator,
const NumberType &denominator);
242 Expression(
const SymEngine::rational_class &value);
305 Expression(
const std::vector<std::pair<Expression, Expression>>
306 & condition_expression,
328 Expression(
const std::vector<std::pair<Expression, Expression>>
329 &condition_expression);
353 const bool parse_as_expression =
false);
376 explicit Expression(
const SymEngine::Expression &rhs);
386 Expression(
const SymEngine::RCP<const SymEngine::Basic> &rhs);
401 Expression(SymEngine::RCP<const SymEngine::Basic> &&rhs);
430 print(std::ostream &stream)
const;
438 save(std::ostream &stream)
const;
452 load(std::istream &stream);
462 template <
class Archive>
464 save(Archive &archive,
const unsigned int version)
const;
478 template <
class Archive>
480 load(Archive &archive,
const unsigned int version);
497 template <
class Archive>
499 serialize(Archive &archive,
const unsigned int version);
503 BOOST_SERIALIZATION_SPLIT_MEMBER()
516 const SymEngine::Expression &
523 const SymEngine::Basic &
530 const SymEngine::RCP<const SymEngine::Basic> &
607 template <
typename NumberType>
628 template <
typename NumberType>
638 template <
typename NumberType>
648 template <
typename NumberType>
658 template <
typename NumberType>
682 const SymEngine::RCP<const SymEngine::Symbol> &symbol)
const;
689 differentiate(
const SymEngine::RCP<const SymEngine::Basic> &symbol)
const;
730 substitute(
const SymEngine::map_basic_basic &substitution_values)
const;
753 template <
typename NumberType>
764 template <
typename ReturnType>
780 template <
typename ReturnType>
783 const SymEngine::map_basic_basic &substitution_values)
const;
842 template <
typename ResultType>
843 explicit operator ResultType()
const;
849 explicit operator const SymEngine::Expression &()
const;
855 operator const SymEngine::RCP<const SymEngine::Basic> &()
const;
863 SymEngine::Expression &
1086 template <
typename NumberType,
1087 typename = std::enable_if_t<
1088 std::is_constructible<Expression, NumberType>::value>>
1103 template <
typename NumberType,
1104 typename = std::enable_if_t<
1105 std::is_constructible<Expression, NumberType>::value>>
1120 template <
typename NumberType,
1121 typename = std::enable_if_t<
1122 std::is_constructible<Expression, NumberType>::value>>
1137 template <
typename NumberType,
1138 typename = std::enable_if_t<
1139 std::is_constructible<Expression, NumberType>::value>>
1154 template <
typename NumberType,
1155 typename = std::enable_if_t<
1156 std::is_constructible<Expression, NumberType>::value>>
1171 template <
typename NumberType,
1172 typename = std::enable_if_t<
1173 std::is_constructible<Expression, NumberType>::value>>
1188 template <
typename NumberType,
1189 typename = std::enable_if_t<
1190 std::is_constructible<Expression, NumberType>::value>>
1205 template <
typename NumberType,
1206 typename = std::enable_if_t<
1207 std::is_constructible<Expression, NumberType>::value>>
1230 template <
typename NumberType,
typename>
1236 template <
typename NumberType,
typename>
1237 Expression::Expression(
const std::complex<NumberType> &value)
1242 template <
typename NumberType,
typename>
1243 Expression::Expression(
const NumberType &numerator,
1244 const NumberType &denominator)
1246 SymEngine::Rational::from_two_ints(*SymEngine::integer(numerator),
1247 *SymEngine::integer(denominator)))
1251 template <
class Archive>
1253 Expression::save(Archive &ar,
const unsigned int )
const
1255 std::stringstream sstream;
1257 const std::string expr = sstream.str();
1262 template <
class Archive>
1264 Expression::load(Archive &ar,
const unsigned int )
1272 template <
typename NumberType>
1274 Expression::substitute(
const Expression &symbol,
1275 const NumberType &value)
const
1277 Assert(SymEngine::is_a<SymEngine::Symbol>(symbol.get_value()),
1279 "Substitution with a number that does not represent a symbol."));
1281 types::substitution_map sub_vals;
1282 sub_vals[symbol] = Expression(value);
1287 template <
typename ReturnType>
1289 Expression::substitute_and_evaluate(
1290 const types::substitution_map &substitution_values)
const
1292 return static_cast<ReturnType
>(
substitute(substitution_values));
1296 template <
typename ReturnType>
1298 Expression::substitute_and_evaluate(
1299 const SymEngine::map_basic_basic &substitution_values)
const
1301 return static_cast<ReturnType
>(
substitute(substitution_values));
1305 template <
typename NumberType>
1307 Expression::operator=(
const NumberType &rhs)
1309 *
this = Expression(rhs);
1314 template <
typename NumberType>
1316 Expression::operator+=(
const NumberType &rhs)
1318 *
this = Expression(SymEngine::add(get_RCP(), Expression(rhs).get_RCP()));
1323 template <
typename NumberType>
1325 Expression::operator-=(
const NumberType &rhs)
1327 *
this = Expression(SymEngine::sub(get_RCP(), Expression(rhs).get_RCP()));
1332 template <
typename NumberType>
1334 Expression::operator*=(
const NumberType &rhs)
1336 *
this = Expression(SymEngine::mul(get_RCP(), Expression(rhs).get_RCP()));
1341 template <
typename NumberType>
1343 Expression::operator/=(
const NumberType &rhs)
1345 *
this = Expression(SymEngine::div(get_RCP(), Expression(rhs).get_RCP()));
1350 template <
typename ResultType>
1351 Expression::operator ResultType()
const
1353 return static_cast<ResultType
>(get_expression());
1365template <
int rank_,
int dim,
typename Number>
1379 template <
typename T,
1380 typename = std::enable_if_t<std::is_arithmetic<T>::value>>
1387 template <
typename T,
1388 typename = std::enable_if_t<std::is_arithmetic<T>::value>>
1395 template <
typename T,
1396 typename = std::enable_if_t<std::is_arithmetic<T>::value>>
1398 value(
const std::complex<T> &t)
1403 template <
typename T,
int dim>
1410 template <
typename T,
int dim>
1426 if (SymEngine::is_a_Number(
value.get_value()))
1428 const SymEngine::RCP<const SymEngine::Number> number_rcp =
1429 SymEngine::rcp_static_cast<const SymEngine::Number>(
value.get_RCP());
1430 return number_rcp->is_zero();
Expression & operator/=(const Expression &rhs)
Expression & parse(const std::string &expression)
Expression & operator-=(const NumberType &rhs)
Expression operator-() const
Expression substitute(const Expression &symbol, const NumberType &value) const
Expression & operator=(const Expression &rhs)
Expression(const NumberType &value)
const SymEngine::RCP< const SymEngine::Basic > & get_RCP() const
ReturnType substitute_and_evaluate(const types::substitution_map &substitution_values) const
void load(std::istream &stream)
virtual ~Expression()=default
Expression & operator/=(const NumberType &rhs)
Expression(const NumberType &numerator, const NumberType &denominator)
Expression(Expression &&rhs)=default
Expression & operator*=(const Expression &rhs)
void serialize(Archive &archive, const unsigned int version)
Expression & operator+=(const NumberType &rhs)
std::ostream & print(std::ostream &stream) const
Expression substitute(const types::substitution_map &substitution_values) const
Expression & operator=(const NumberType &rhs)
void save(Archive &archive, const unsigned int version) const
Expression(const Expression &rhs)=default
void save(std::ostream &stream) const
Expression & operator*=(const NumberType &rhs)
ReturnType substitute_and_evaluate(const SymEngine::map_basic_basic &substitution_values) const
Expression & operator-=(const Expression &rhs)
const SymEngine::Basic & get_value() const
const SymEngine::Expression & get_expression() const
Expression & operator+=(const Expression &rhs)
void load(Archive &archive, const unsigned int version)
SymEngine::Expression expression
Expression(const std::complex< NumberType > &value)
Expression differentiate(const Expression &symbol) const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcSymEngineParserError(std::string arg1)
#define Assert(cond, exc)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcMessage(std::string arg1)
std::vector< SD::Expression > symbol_vector
std::map< SD::Expression, SD::Expression, internal::ExpressionKeyLess > substitution_map
Expression operator*(Expression lhs, const Expression &rhs)
Expression operator<(const Expression &lhs, const Expression &rhs)
Expression operator-(Expression lhs, const Expression &rhs)
Expression operator+(Expression lhs, const Expression &rhs)
Expression operator!(const Expression &expression)
Expression operator||(const Expression &lhs, const Expression &rhs)
Expression operator^(const Expression &lhs, const Expression &rhs)
Expression operator>=(const Expression &lhs, const Expression &rhs)
Expression operator!=(const Expression &lhs, const Expression &rhs)
Expression operator|(const Expression &lhs, const Expression &rhs)
Expression operator>(const Expression &lhs, const Expression &rhs)
Expression operator&(const Expression &lhs, const Expression &rhs)
Expression operator/(Expression lhs, const Expression &rhs)
Expression operator<=(const Expression &lhs, const Expression &rhs)
Expression operator&&(const Expression &lhs, const Expression &rhs)
Expression substitute(const Expression &expression, const types::substitution_map &substitution_map)
std::ostream & operator<<(std::ostream &stream, const Expression &expression)
Expression operator==(const Expression &lhs, const Expression &rhs)
std::istream & operator>>(std::istream &stream, Expression &expression)
constexpr bool value_is_zero(const Number &value)
constexpr bool values_are_equal(const Number1 &value_1, const Number2 &value_2)
bool value_is_less_than(const Number1 &value_1, const Number2 &value_2)