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?");
206 template <
typename NumberType,
207 typename =
typename std::enable_if<
208 std::is_arithmetic<NumberType>::value>::type>
218 template <
typename NumberType,
219 typename =
typename std::enable_if<
220 std::is_arithmetic<NumberType>::value>::type>
226 Expression(
const SymEngine::integer_class &value);
234 template <
typename NumberType,
235 typename =
typename std::enable_if<
236 std::is_integral<NumberType>::value>::type>
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 &
1083 template <
typename NumberType,
1084 typename =
typename std::enable_if<
1085 std::is_constructible<Expression, NumberType>::value>::type>
1100 template <
typename NumberType,
1101 typename =
typename std::enable_if<
1102 std::is_constructible<Expression, NumberType>::value>::type>
1117 template <
typename NumberType,
1118 typename =
typename std::enable_if<
1119 std::is_constructible<Expression, NumberType>::value>::type>
1134 template <
typename NumberType,
1135 typename =
typename std::enable_if<
1136 std::is_constructible<Expression, NumberType>::value>::type>
1151 template <
typename NumberType,
1152 typename =
typename std::enable_if<
1153 std::is_constructible<Expression, NumberType>::value>::type>
1167 template <
typename NumberType,
1168 typename =
typename std::enable_if<
1169 std::is_constructible<Expression, NumberType>::value>::type>
1183 template <
typename NumberType,
1184 typename =
typename std::enable_if<
1185 std::is_constructible<Expression, NumberType>::value>::type>
1200 template <
typename NumberType,
1201 typename =
typename std::enable_if<
1202 std::is_constructible<Expression, NumberType>::value>::type>
1225 template <
typename NumberType,
typename>
1231 template <
typename NumberType,
typename>
1232 Expression::Expression(
const std::complex<NumberType> &value)
1237 template <
typename NumberType,
typename>
1238 Expression::Expression(
const NumberType &numerator,
1239 const NumberType &denominator)
1241 SymEngine::Rational::from_two_ints(*SymEngine::integer(numerator),
1242 *SymEngine::integer(denominator)))
1246 template <
class Archive>
1248 Expression::save(Archive &ar,
const unsigned int )
const
1250 std::stringstream sstream;
1252 const std::string expr = sstream.str();
1257 template <
class Archive>
1259 Expression::load(Archive &ar,
const unsigned int )
1267 template <
typename NumberType>
1270 const NumberType &value)
const
1272 Assert(SymEngine::is_a<SymEngine::Symbol>(symbol.get_value()),
1274 "Substitution with a number that does not represent a symbol."));
1277 sub_vals[symbol] = Expression(value);
1282 template <
typename ReturnType>
1287 return static_cast<ReturnType
>(
substitute(substitution_values));
1291 template <
typename ReturnType>
1294 const SymEngine::map_basic_basic &substitution_values)
const
1296 return static_cast<ReturnType
>(
substitute(substitution_values));
1300 template <
typename NumberType>
1302 Expression::operator=(
const NumberType &rhs)
1304 *
this = Expression(rhs);
1309 template <
typename NumberType>
1311 Expression::operator+=(
const NumberType &rhs)
1313 *
this = Expression(SymEngine::add(get_RCP(), Expression(rhs).get_RCP()));
1318 template <
typename NumberType>
1320 Expression::operator-=(
const NumberType &rhs)
1322 *
this = Expression(SymEngine::sub(get_RCP(), Expression(rhs).get_RCP()));
1327 template <
typename NumberType>
1329 Expression::operator*=(
const NumberType &rhs)
1331 *
this = Expression(SymEngine::mul(get_RCP(), Expression(rhs).get_RCP()));
1336 template <
typename NumberType>
1338 Expression::operator/=(
const NumberType &rhs)
1340 *
this = Expression(SymEngine::div(get_RCP(), Expression(rhs).get_RCP()));
1345 template <
typename ResultType>
1346 Expression::operator ResultType()
const
1348 return static_cast<ResultType
>(get_expression());
1360template <
int rank_,
int dim,
typename Number>
1376 typename =
typename std::enable_if<std::is_arithmetic<T>::value>::type>
1385 typename =
typename std::enable_if<std::is_arithmetic<T>::value>::type>
1394 typename =
typename std::enable_if<std::is_arithmetic<T>::value>::type>
1396 value(
const std::complex<T> &t)
1401 template <
typename T,
int dim>
1408 template <
typename T,
int dim>
1424 if (SymEngine::is_a_Number(
value.get_value()))
1426 const SymEngine::RCP<const SymEngine::Number> number_rcp =
1427 SymEngine::rcp_static_cast<const SymEngine::Number>(
value.get_RCP());
1428 return number_rcp->is_zero();
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
Expression & operator/=(const Expression &rhs)
Expression & parse(const std::string &expression)
Expression & operator-=(const NumberType &rhs)
Expression operator*(Expression lhs, const Expression &rhs)
Expression operator-() const
Expression operator<(const Expression &lhs, const Expression &rhs)
Expression operator-(Expression lhs, const Expression &rhs)
Expression substitute(const Expression &symbol, const NumberType &value) const
Expression & operator=(const Expression &rhs)
Expression operator+(Expression lhs, 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)
Expression operator!(const Expression &expression)
Expression operator||(const Expression &lhs, const Expression &rhs)
static ::ExceptionBase & ExcSymEngineParserError(std::string arg1)
Expression operator^(const Expression &lhs, const Expression &rhs)
void serialize(Archive &archive, const unsigned int version)
#define Assert(cond, exc)
Expression & operator+=(const NumberType &rhs)
Expression operator>=(const Expression &lhs, const Expression &rhs)
std::ostream & print(std::ostream &stream) const
Expression substitute(const types::substitution_map &substitution_values) const
Expression operator!=(const Expression &lhs, const Expression &rhs)
Expression & operator=(const NumberType &rhs)
Expression operator|(const Expression &lhs, const Expression &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 &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 &rhs)
#define DeclException1(Exception1, type1, outsequence)
Expression operator&&(const Expression &lhs, const Expression &rhs)
const SymEngine::Basic & get_value() const
const SymEngine::Expression & get_expression() const
std::ostream & operator<<(std::ostream &stream, const Expression &expression)
Expression operator==(const Expression &lhs, const Expression &rhs)
Expression & operator+=(const Expression &rhs)
void load(Archive &archive, const unsigned int version)
static ::ExceptionBase & ExcMessage(std::string arg1)
SymEngine::Expression expression
Expression(const std::complex< NumberType > &value)
Expression differentiate(const Expression &symbol) const
std::istream & operator>>(std::istream &stream, Expression &expression)
std::vector< SD::Expression > symbol_vector
std::map< SD::Expression, SD::Expression, internal::ExpressionKeyLess > substitution_map
ValueType substitute_and_evaluate(const Expression &expression, const types::substitution_map &substitution_map)
Expression substitute(const Expression &expression, const types::substitution_map &substitution_map)
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)
static constexpr const T & value(const T &t)