18 #ifdef DEAL_II_WITH_SYMENGINE
26 # include <symengine/complex_double.h>
27 # include <symengine/logic.h>
28 # include <symengine/number.h>
29 # include <symengine/parser.h>
30 # include <symengine/real_double.h>
31 # include <symengine/symbol.h>
32 # include <symengine/symengine_exception.h>
42 namespace SE = ::SymEngine;
54 : expression(SE::boolean(
value))
74 "The conditional expression must return a boolean type."));
76 const SE::RCP<const SE::Boolean> condition_rcp =
77 SE::rcp_static_cast<const SE::Boolean>(condition.
get_RCP());
79 SE::piecewise({{expression_if_true.
get_RCP(), condition_rcp},
80 {expression_if_false.
get_RCP(), SE::boolTrue}});
85 & condition_expression,
88 SE::PiecewiseVec piecewise_function;
89 piecewise_function.reserve(condition_expression.size() + 1);
92 for (
const auto &entry : condition_expression)
94 Assert(SE::is_a_Boolean(entry.first.get_value()),
96 "The conditional expression must return a boolean type."));
97 piecewise_function.push_back(
98 {entry.second.get_RCP(),
99 SE::rcp_static_cast<const SE::Boolean>(entry.first.get_RCP())});
103 piecewise_function.push_back(
104 {expression_otherwise.
get_RCP(), SE::boolTrue});
107 expression = SE::piecewise(std::move(piecewise_function));
112 &condition_expression)
118 Expression(numbers::signaling_nan<double>()));
123 : expression(SE::symbol(symbol))
128 const bool parse_as_expression)
135 SE::rcp_static_cast<const SE::Basic>(SE::symbol(
147 : expression(SE::function_symbol(
203 std::getline(is, expr);
212 const SE::Expression &
233 const SE::RCP<const SE::Basic> &
245 const SymEngine::RCP<const SymEngine::Symbol> &symbol)
const
253 const SymEngine::RCP<const SymEngine::Basic> &symbol)
const
270 Expression::operator
const SymEngine::Expression &()
const
272 return get_expression();
276 Expression::operator
const SymEngine::RCP<const SymEngine::Basic> &()
const
278 return get_expression().get_basic();
287 const SymEngine::map_basic_basic &substitution_values)
const
308 "Substitution with a number that does not represent a symbol."));
311 sub_vals[symbol] =
value;
333 this->expression = std::move(rhs.expression);
441 ExcMessage(
"The expression must return a boolean type."));
443 const SE::RCP<const SE::Boolean> expression_rcp =
444 SE::rcp_static_cast<const SE::Boolean>(expression.
get_RCP());
446 return Expression(SE::logical_not(expression_rcp));
453 ExcMessage(
"The lhs expression must return a boolean type."));
455 ExcMessage(
"The rhs expression must return a boolean type."));
457 const SE::RCP<const SE::Boolean> lhs_rcp =
458 SE::rcp_static_cast<const SE::Boolean>(lhs.
get_RCP());
459 const SE::RCP<const SE::Boolean> rhs_rcp =
460 SE::rcp_static_cast<const SE::Boolean>(rhs.
get_RCP());
462 return Expression(SE::logical_and({lhs_rcp, rhs_rcp}));
470 ExcMessage(
"The lhs expression must return a boolean type."));
472 ExcMessage(
"The rhs expression must return a boolean type."));
474 const SE::RCP<const SE::Boolean> lhs_rcp =
475 SE::rcp_static_cast<const SE::Boolean>(lhs.
get_RCP());
476 const SE::RCP<const SE::Boolean> rhs_rcp =
477 SE::rcp_static_cast<const SE::Boolean>(rhs.
get_RCP());
479 return Expression(SE::logical_or({lhs_rcp, rhs_rcp}));
487 ExcMessage(
"The lhs expression must return a boolean type."));
489 ExcMessage(
"The rhs expression must return a boolean type."));
491 const SE::RCP<const SE::Boolean> lhs_rcp =
492 SE::rcp_static_cast<const SE::Boolean>(lhs.
get_RCP());
493 const SE::RCP<const SE::Boolean> rhs_rcp =
494 SE::rcp_static_cast<const SE::Boolean>(rhs.
get_RCP());
496 return Expression(SE::logical_xor({lhs_rcp, rhs_rcp}));
551 #endif // DEAL_II_WITH_SYMENGINE