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 = std::enable_if_t<std::is_arithmetic_v<NumberType>>>
217 template <
typename NumberType,
218 typename = std::enable_if_t<std::is_arithmetic_v<NumberType>>>
224 Expression(
const SymEngine::integer_class &value);
232 template <
typename NumberType,
233 typename = std::enable_if_t<std::is_integral_v<NumberType>>>
234 Expression(
const NumberType &numerator,
const NumberType &denominator);
239 Expression(
const SymEngine::rational_class &value);
302 Expression(
const std::vector<std::pair<Expression, Expression>>
303 &condition_expression,
325 Expression(
const std::vector<std::pair<Expression, Expression>>
326 &condition_expression);
350 const bool parse_as_expression =
false);
373 explicit Expression(
const SymEngine::Expression &rhs);
383 Expression(
const SymEngine::RCP<const SymEngine::Basic> &rhs);
398 Expression(SymEngine::RCP<const SymEngine::Basic> &&rhs);
427 print(std::ostream &stream)
const;
435 save(std::ostream &stream)
const;
449 load(std::istream &stream);
459 template <
class Archive>
461 save(Archive &archive,
const unsigned int version)
const;
475 template <
class Archive>
477 load(Archive &archive,
const unsigned int version);
494 template <
class Archive>
496 serialize(Archive &archive,
const unsigned int version);
500 BOOST_SERIALIZATION_SPLIT_MEMBER()
513 const SymEngine::Expression &
520 const SymEngine::Basic &
527 const SymEngine::RCP<const SymEngine::Basic> &
604 template <
typename NumberType>
625 template <
typename NumberType>
635 template <
typename NumberType>
645 template <
typename NumberType>
655 template <
typename NumberType>
679 const SymEngine::RCP<const SymEngine::Symbol> &symbol)
const;
686 differentiate(
const SymEngine::RCP<const SymEngine::Basic> &symbol)
const;
727 substitute(
const SymEngine::map_basic_basic &substitution_values)
const;
750 template <
typename NumberType>
761 template <
typename ReturnType>
777 template <
typename ReturnType>
780 const SymEngine::map_basic_basic &substitution_values)
const;
839 template <
typename ResultType>
840 explicit operator ResultType()
const;
846 explicit operator const SymEngine::Expression &()
const;
852 operator const SymEngine::RCP<const SymEngine::Basic> &()
const;
860 SymEngine::Expression &
1083 template <
typename NumberType,
1084 typename = std::enable_if_t<
1085 std::is_constructible_v<Expression, NumberType>>>
1100 template <
typename NumberType,
1101 typename = std::enable_if_t<
1102 std::is_constructible_v<Expression, NumberType>>>
1117 template <
typename NumberType,
1118 typename = std::enable_if_t<
1119 std::is_constructible_v<Expression, NumberType>>>
1134 template <
typename NumberType,
1135 typename = std::enable_if_t<
1136 std::is_constructible_v<Expression, NumberType>>>
1151 template <
typename NumberType,
1152 typename = std::enable_if_t<
1153 std::is_constructible_v<Expression, NumberType>>>
1168 template <
typename NumberType,
1169 typename = std::enable_if_t<
1170 std::is_constructible_v<Expression, NumberType>>>
1185 template <
typename NumberType,
1186 typename = std::enable_if_t<
1187 std::is_constructible_v<Expression, NumberType>>>
1202 template <
typename NumberType,
1203 typename = std::enable_if_t<
1204 std::is_constructible_v<Expression, NumberType>>>
1227 template <
typename NumberType,
typename>
1233 template <
typename NumberType,
typename>
1234 Expression::Expression(
const std::complex<NumberType> &value)
1239 template <
typename NumberType,
typename>
1240 Expression::Expression(
const NumberType &numerator,
1241 const NumberType &denominator)
1243 SymEngine::Rational::from_two_ints(*SymEngine::integer(numerator),
1244 *SymEngine::integer(denominator)))
1248 template <
class Archive>
1250 Expression::save(Archive &ar,
const unsigned int )
const
1252 std::stringstream sstream;
1254 const std::string expr = sstream.str();
1259 template <
class Archive>
1261 Expression::load(Archive &ar,
const unsigned int )
1269 template <
typename NumberType>
1272 const NumberType &value)
const
1274 Assert(SymEngine::is_a<SymEngine::Symbol>(symbol.get_value()),
1276 "Substitution with a number that does not represent a symbol."));
1279 sub_vals[symbol] = Expression(value);
1284 template <
typename ReturnType>
1289 return static_cast<ReturnType
>(
substitute(substitution_values));
1293 template <
typename ReturnType>
1296 const SymEngine::map_basic_basic &substitution_values)
const
1298 return static_cast<ReturnType
>(
substitute(substitution_values));
1302 template <
typename NumberType>
1304 Expression::operator=(
const NumberType &rhs)
1306 *
this = Expression(rhs);
1311 template <
typename NumberType>
1313 Expression::operator+=(
const NumberType &rhs)
1315 *
this = Expression(SymEngine::add(get_RCP(), Expression(rhs).get_RCP()));
1320 template <
typename NumberType>
1322 Expression::operator-=(
const NumberType &rhs)
1324 *
this = Expression(SymEngine::sub(get_RCP(), Expression(rhs).get_RCP()));
1329 template <
typename NumberType>
1331 Expression::operator*=(
const NumberType &rhs)
1333 *
this = Expression(SymEngine::mul(get_RCP(), Expression(rhs).get_RCP()));
1338 template <
typename NumberType>
1340 Expression::operator/=(
const NumberType &rhs)
1342 *
this = Expression(SymEngine::div(get_RCP(), Expression(rhs).get_RCP()));
1347 template <
typename ResultType>
1348 Expression::operator ResultType()
const
1350 return static_cast<ResultType
>(get_expression());
1362 template <
int rank_,
int dim,
typename Number>
1376 template <
typename T,
typename = std::enable_if_t<std::is_arithmetic_v<T>>>
1383 template <
typename T,
typename = std::enable_if_t<std::is_arithmetic_v<T>>>
1390 template <
typename T,
typename = std::enable_if_t<std::is_arithmetic_v<T>>>
1392 value(
const std::complex<T> &t)
1397 template <
typename T,
int dim>
1404 template <
typename T,
int dim>
1420 if (SymEngine::is_a_Number(
value.get_value()))
1422 const SymEngine::RCP<const SymEngine::Number> number_rcp =
1423 SymEngine::rcp_static_cast<const SymEngine::Number>(
value.get_RCP());
1424 return number_rcp->is_zero();
Expression & operator/=(const Expression &rhs)
Expression & parse(const std::string &expression)
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(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)
Expression & operator+=(const NumberType &rhs)
std::ostream & print(std::ostream &stream) const
Expression substitute(const types::substitution_map &substitution_values) const
void save(Archive &archive, const unsigned int version) const
Expression & operator*=(const NumberType &rhs)
Expression(const Expression &rhs)=default
void save(std::ostream &stream) const
ReturnType substitute_and_evaluate(const SymEngine::map_basic_basic &substitution_values) const
Expression & operator/=(const NumberType &rhs)
Expression & operator=(const NumberType &rhs)
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)
ValueType substitute_and_evaluate(const Expression &expression, const types::substitution_map &substitution_map)
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)
static constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE const T & value(const T &t)