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>
221 explicit Expression(
const std::complex<NumberType> &value);
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);
281 const Expression &expression_if_true,
282 const Expression &expression_if_false);
305 Expression(
const std::vector<std::pair<Expression, Expression>>
306 & condition_expression,
307 const Expression &expression_otherwise);
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;
742 substitute(
const Expression &symbol,
const Expression &value)
const;
753 template <
typename NumberType>
755 substitute(
const Expression &symbol,
const NumberType &value)
const;
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 &
919 operator>>(std::istream &stream, Expression &expression);
934 operator==(
const Expression &lhs,
const Expression &rhs);
942 operator!=(
const Expression &lhs,
const Expression &rhs);
950 operator<(
const Expression &lhs,
const Expression &rhs);
958 operator>(
const Expression &lhs,
const Expression &rhs);
966 operator<=(
const Expression &lhs,
const Expression &rhs);
974 operator>=(
const Expression &lhs,
const Expression &rhs);
989 Expression
operator!(
const Expression &expression);
997 Expression
operator&(
const Expression &lhs,
const Expression &rhs);
1006 operator|(
const Expression &lhs,
const Expression &rhs);
1015 operator^(
const Expression &lhs,
const Expression &rhs);
1025 operator&&(
const Expression &lhs,
const Expression &rhs);
1035 operator||(
const Expression &lhs,
const Expression &rhs);
1050 operator+(Expression lhs,
const Expression &rhs);
1058 operator-(Expression lhs,
const Expression &rhs);
1065 Expression
operator*(Expression lhs,
const Expression &rhs);
1073 operator/(Expression lhs,
const Expression &rhs);
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>
1154 inline Expression
operator*(
const NumberType &lhs,
const Expression &rhs)
1167 template <
typename NumberType,
1168 typename =
typename std::enable_if<
1169 std::is_constructible<Expression, NumberType>::value>::type>
1170 inline Expression
operator*(
const Expression &lhs,
const NumberType &rhs)
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>
1237 template <
typename NumberType,
typename>
1239 const NumberType &denominator)
1241 SymEngine::Rational::from_two_ints(*SymEngine::integer(numerator),
1242 *SymEngine::integer(denominator)))
1246 template <
class Archive>
1250 std::stringstream sstream;
1252 const std::string expr = sstream.str();
1257 template <
class Archive>
1267 template <
typename NumberType>
1270 const NumberType &value)
const 1274 "Substitution with a number that does not represent a symbol."));
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>
1309 template <
typename NumberType>
1318 template <
typename NumberType>
1327 template <
typename NumberType>
1336 template <
typename NumberType>
1345 template <
typename ResultType>
1346 Expression::operator ResultType()
const 1360 template <
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>
1410 value(
const Tensor<0, dim, std::complex<T>> &t)
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();
1456 #endif // DEAL_II_WITH_SYMENGINE 1458 #endif // dealii_differentiation_sd_symengine_number_types_h std::ostream & operator<<(std::ostream &stream, const Expression &expression)
Expression operator+(Expression lhs, const Expression &rhs)
Expression operator<(const Expression &lhs, const Expression &rhs)
Expression differentiate(const Expression &symbol) const
std::istream & operator>>(std::istream &stream, Expression &expression)
Expression & operator/=(const Expression &rhs)
Expression operator-() const
Expression operator &&(const Expression &lhs, const Expression &rhs)
constexpr bool values_are_equal(const Number1 &value_1, const Number2 &value_2)
Expression operator>=(const Expression &lhs, const Expression &rhs)
void load(std::istream &stream)
Expression & parse(const std::string &expression)
ReturnType substitute_and_evaluate(const types::substitution_map &substitution_values) const
void serialize(Archive &archive, const unsigned int version)
std::ostream & print(std::ostream &stream) const
Expression substitute(const types::substitution_map &substitution_values) const
const SymEngine::RCP< const SymEngine::Basic > & get_RCP() const
Expression operator/(Expression lhs, const Expression &rhs)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define DeclException1(Exception1, type1, outsequence)
Expression operator<=(const Expression &lhs, const Expression &rhs)
#define Assert(cond, exc)
Expression & operator*=(const Expression &rhs)
Expression operator|(const Expression &lhs, const Expression &rhs)
static ::ExceptionBase & ExcSymEngineParserError(std::string arg1)
const SymEngine::Basic & get_value() const
#define DEAL_II_NAMESPACE_CLOSE
const SymEngine::Expression & get_expression() const
Expression & operator=(const Expression &rhs)
Expression operator>(const Expression &lhs, const Expression &rhs)
void save(std::ostream &stream) const
std::vector< SD::Expression > symbol_vector
Expression operator*(Expression lhs, const Expression &rhs)
Expression operator!(const Expression &expression)
virtual ~Expression()=default
SymEngine::Expression expression
bool value_is_less_than(const Number1 &value_1, const Number2 &value_2)
Expression operator==(const Expression &lhs, const Expression &rhs)
#define DEAL_II_NAMESPACE_OPEN
Expression operator||(const Expression &lhs, const Expression &rhs)
constexpr bool value_is_zero(const Number &value)
Expression operator^(const Expression &lhs, const Expression &rhs)
Expression & operator-=(const Expression &rhs)
Expression & operator+=(const Expression &rhs)
std::map< SD::Expression, SD::Expression, internal::ExpressionKeyLess > substitution_map
Expression operator!=(const Expression &lhs, const Expression &rhs)
Expression operator &(const Expression &lhs, const Expression &rhs)