15#ifndef dealii_differentiation_sd_symengine_number_types_h
16#define dealii_differentiation_sd_symengine_number_types_h
20#ifdef DEAL_II_WITH_SYMENGINE
23# include <symengine/basic.h>
24# include <symengine/dict.h>
25# include <symengine/symengine_exception.h>
26# include <symengine/symengine_rcp.h>
29# include <symengine/expression.h>
30# include <symengine/integer.h>
31# include <symengine/logic.h>
32# include <symengine/number.h>
33# include <symengine/rational.h>
36# include <symengine/add.h>
37# include <symengine/functions.h>
38# include <symengine/mul.h>
39# include <symengine/pow.h>
42# include <symengine/eval.h>
43# include <symengine/eval_arb.h>
44# include <symengine/eval_double.h>
53# include <boost/serialization/split_member.hpp>
55# include <symengine/derivative.h>
60# include <type_traits>
82 <<
"The string '" << arg1
83 <<
"' could not be parsed successfully. Are you sure that (1) it "
84 <<
"consists of legitimate operations and syntax, and (2) you've "
85 <<
"previously declared all symbolic variables that are present "
86 <<
"in the expression?");
205 template <
typename NumberType,
206 typename = std::enable_if_t<std::is_arithmetic_v<NumberType>>>
216 template <
typename NumberType,
217 typename = std::enable_if_t<std::is_arithmetic_v<NumberType>>>
223 Expression(
const SymEngine::integer_class &value);
231 template <
typename NumberType,
232 typename = std::enable_if_t<std::is_integral_v<NumberType>>>
233 Expression(
const NumberType &numerator,
const NumberType &denominator);
238 Expression(
const SymEngine::rational_class &value);
301 Expression(
const std::vector<std::pair<Expression, Expression>>
302 &condition_expression,
324 Expression(
const std::vector<std::pair<Expression, Expression>>
325 &condition_expression);
349 const bool parse_as_expression =
false);
372 explicit Expression(
const SymEngine::Expression &rhs);
382 Expression(
const SymEngine::RCP<const SymEngine::Basic> &rhs);
397 Expression(SymEngine::RCP<const SymEngine::Basic> &&rhs);
426 print(std::ostream &stream)
const;
434 save(std::ostream &stream)
const;
448 load(std::istream &stream);
458 template <
class Archive>
460 save(Archive &archive,
const unsigned int version)
const;
474 template <
class Archive>
476 load(Archive &archive,
const unsigned int version);
493 template <
class Archive>
495 serialize(Archive &archive,
const unsigned int version);
499 BOOST_SERIALIZATION_SPLIT_MEMBER()
512 const SymEngine::Expression &
519 const SymEngine::Basic &
526 const SymEngine::RCP<const SymEngine::Basic> &
603 template <
typename NumberType>
624 template <
typename NumberType>
634 template <
typename NumberType>
644 template <
typename NumberType>
654 template <
typename NumberType>
678 const SymEngine::RCP<const SymEngine::Symbol> &symbol)
const;
685 differentiate(
const SymEngine::RCP<const SymEngine::Basic> &symbol)
const;
726 substitute(
const SymEngine::map_basic_basic &substitution_values)
const;
749 template <
typename NumberType>
760 template <
typename ReturnType>
776 template <
typename ReturnType>
779 const SymEngine::map_basic_basic &substitution_values)
const;
838 template <
typename ResultType>
839 explicit operator ResultType()
const;
845 explicit operator const SymEngine::Expression &()
const;
851 operator const SymEngine::RCP<const SymEngine::Basic> &()
const;
859 SymEngine::Expression &
1082 template <
typename NumberType,
1083 typename = std::enable_if_t<
1084 std::is_constructible_v<Expression, NumberType>>>
1099 template <
typename NumberType,
1100 typename = std::enable_if_t<
1101 std::is_constructible_v<Expression, NumberType>>>
1116 template <
typename NumberType,
1117 typename = std::enable_if_t<
1118 std::is_constructible_v<Expression, NumberType>>>
1133 template <
typename NumberType,
1134 typename = std::enable_if_t<
1135 std::is_constructible_v<Expression, NumberType>>>
1150 template <
typename NumberType,
1151 typename = std::enable_if_t<
1152 std::is_constructible_v<Expression, NumberType>>>
1167 template <
typename NumberType,
1168 typename = std::enable_if_t<
1169 std::is_constructible_v<Expression, NumberType>>>
1184 template <
typename NumberType,
1185 typename = std::enable_if_t<
1186 std::is_constructible_v<Expression, NumberType>>>
1201 template <
typename NumberType,
1202 typename = std::enable_if_t<
1203 std::is_constructible_v<Expression, NumberType>>>
1226 template <
typename NumberType,
typename>
1232 template <
typename NumberType,
typename>
1233 Expression::Expression(
const std::complex<NumberType> &value)
1238 template <
typename NumberType,
typename>
1239 Expression::Expression(
const NumberType &numerator,
1240 const NumberType &denominator)
1242 SymEngine::Rational::from_two_ints(*SymEngine::integer(numerator),
1243 *SymEngine::integer(denominator)))
1247 template <
class Archive>
1249 Expression::save(Archive &ar,
const unsigned int )
const
1251 std::stringstream sstream;
1253 const std::string expr = sstream.str();
1258 template <
class Archive>
1260 Expression::load(Archive &ar,
const unsigned int )
1268 template <
typename NumberType>
1270 Expression::substitute(
const Expression &symbol,
1271 const NumberType &value)
const
1273 Assert(SymEngine::is_a<SymEngine::Symbol>(symbol.get_value()),
1275 "Substitution with a number that does not represent a symbol."));
1277 types::substitution_map sub_vals;
1278 sub_vals[symbol] = Expression(value);
1283 template <
typename ReturnType>
1285 Expression::substitute_and_evaluate(
1286 const types::substitution_map &substitution_values)
const
1288 return static_cast<ReturnType
>(
substitute(substitution_values));
1292 template <
typename ReturnType>
1294 Expression::substitute_and_evaluate(
1295 const SymEngine::map_basic_basic &substitution_values)
const
1297 return static_cast<ReturnType
>(
substitute(substitution_values));
1301 template <
typename NumberType>
1303 Expression::operator=(
const NumberType &rhs)
1305 *
this = Expression(rhs);
1310 template <
typename NumberType>
1312 Expression::operator+=(
const NumberType &rhs)
1314 *
this = Expression(SymEngine::add(get_RCP(), Expression(rhs).get_RCP()));
1319 template <
typename NumberType>
1321 Expression::operator-=(
const NumberType &rhs)
1323 *
this = Expression(SymEngine::sub(get_RCP(), Expression(rhs).get_RCP()));
1328 template <
typename NumberType>
1330 Expression::operator*=(
const NumberType &rhs)
1332 *
this = Expression(SymEngine::mul(get_RCP(), Expression(rhs).get_RCP()));
1337 template <
typename NumberType>
1339 Expression::operator/=(
const NumberType &rhs)
1341 *
this = Expression(SymEngine::div(get_RCP(), Expression(rhs).get_RCP()));
1346 template <
typename ResultType>
1347 Expression::operator ResultType()
const
1349 return static_cast<ResultType
>(get_expression());
1361template <
int rank_,
int dim,
typename Number>
1375 template <
typename T,
typename = std::enable_if_t<std::is_arithmetic_v<T>>>
1382 template <
typename T,
typename = std::enable_if_t<std::is_arithmetic_v<T>>>
1389 template <
typename T,
typename = std::enable_if_t<std::is_arithmetic_v<T>>>
1391 value(
const std::complex<T> &t)
1396 template <
typename T,
int dim>
1403 template <
typename T,
int dim>
1419 if (SymEngine::is_a_Number(
value.get_value()))
1421 const SymEngine::RCP<const SymEngine::Number> number_rcp =
1422 SymEngine::rcp_static_cast<const SymEngine::Number>(
value.get_RCP());
1423 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::map< SD::Expression, SD::Expression, internal::ExpressionKeyLess > substitution_map
std::vector< SD::Expression > symbol_vector
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)