3#include <symengine/symengine_exception.h>
8template <
typename T,
typename C>
22 T apply(
const Basic &b)
45#ifdef HAVE_SYMENGINE_MPFR
52 void bvisit(
const Add &x)
60 void bvisit(
const Mul &x)
68 void bvisit(
const Pow &x)
79 void bvisit(
const Sin &x)
85 void bvisit(
const Cos &x)
91 void bvisit(
const Tan &x)
97 void bvisit(
const Symbol &)
99 throw SymEngineException(
"Symbol cannot be evaluated.");
102 void bvisit(
const Log &x)
108 void bvisit(
const Cot &x)
114 void bvisit(
const Csc &x)
120 void bvisit(
const Sec &x)
126 void bvisit(
const ASin &x)
132 void bvisit(
const ACos &x)
138 void bvisit(
const ASec &x)
144 void bvisit(
const ACsc &x)
150 void bvisit(
const ATan &x)
156 void bvisit(
const ACot &x)
162 void bvisit(
const Sinh &x)
168 void bvisit(
const Csch &x)
174 void bvisit(
const Cosh &x)
180 void bvisit(
const Sech &x)
186 void bvisit(
const Tanh &x)
192 void bvisit(
const Coth &x)
198 void bvisit(
const ASinh &x)
204 void bvisit(
const ACsch &x)
210 void bvisit(
const ACosh &x)
216 void bvisit(
const ATanh &x)
222 void bvisit(
const ACoth &x)
228 void bvisit(
const ASech &x)
238 }
else if (
eq(x, *E)) {
240 }
else if (
eq(x, *EulerGamma)) {
241 result_ = 0.5772156649015328606065;
243 }
else if (
eq(x, *Catalan)) {
244 result_ = 0.9159655941772190150546;
245 }
else if (
eq(x, *GoldenRatio)) {
246 result_ = 1.6180339887498948482045;
249 +
" is not implemented.");
253 void bvisit(
const Abs &x)
256 result_ = std::abs(
tmp);
259 void bvisit(
const Basic &)
266 apply(*(x.eval(53)));
271 apply(*(x.eval(53)));
293 void bvisit(
const ATan2 &x)
300 void bvisit(
const Gamma &x)
312 void bvisit(
const Erf &x)
318 void bvisit(
const Erfc &x)
352 void bvisit(
const Max &x)
356 double result = apply(*(*p));
359 for (; p !=
d.end(); p++) {
360 double tmp = apply(*(*p));
366 void bvisit(
const Min &x)
370 double result = apply(*(*p));
373 for (; p !=
d.end(); p++) {
374 double tmp = apply(*(*p));
382 result_ =
ba.get_val();
387 SYMENGINE_ASSERT_MSG(
388 eq(*
pw.get_vec().back().second, *boolTrue),
389 "EvalDouble requires a (Expr, True) at the end of Piecewise");
397 throw SymEngineException(
398 "Unexpectedly reached end of Piecewise function.");
421 using EvalDoubleVisitor::bvisit;
433#ifdef HAVE_SYMENGINE_MPC
473#ifdef HAVE_SYMENGINE_MPFR
482 for (
const auto &p : x.get_args())
483 tmp += eval_double_single_dispatch(*p);
488 for (
const auto &p : x.get_args())
489 tmp *= eval_double_single_dispatch(*p);
493 double a = eval_double_single_dispatch(
495 double b = eval_double_single_dispatch(
500 double tmp = eval_double_single_dispatch(
505 double tmp = eval_double_single_dispatch(
510 double tmp = eval_double_single_dispatch(
515 double tmp = eval_double_single_dispatch(
520 double tmp = eval_double_single_dispatch(
525 double tmp = eval_double_single_dispatch(
530 double tmp = eval_double_single_dispatch(
535 double tmp = eval_double_single_dispatch(
540 double tmp = eval_double_single_dispatch(
545 double tmp = eval_double_single_dispatch(
547 return ::acos(1 /
tmp);
550 double tmp = eval_double_single_dispatch(
552 return ::asin(1 /
tmp);
555 double tmp = eval_double_single_dispatch(
560 double tmp = eval_double_single_dispatch(
562 return ::atan(1 /
tmp);
565 double num = eval_double_single_dispatch(
567 double den = eval_double_single_dispatch(
572 double tmp = eval_double_single_dispatch(
577 double tmp = eval_double_single_dispatch(
582 double tmp = eval_double_single_dispatch(
587 double tmp = eval_double_single_dispatch(
592 double tmp = eval_double_single_dispatch(
597 double tmp = eval_double_single_dispatch(
602 double tmp = eval_double_single_dispatch(
607 double tmp = eval_double_single_dispatch(
609 return ::asinh(1 /
tmp);
612 double tmp = eval_double_single_dispatch(
617 double tmp = eval_double_single_dispatch(
622 double tmp = eval_double_single_dispatch(
627 double tmp = eval_double_single_dispatch(
629 return ::acosh(1 /
tmp);
632 double tmp = eval_double_single_dispatch(
634 return ::tgamma(
tmp);
637 double tmp = eval_double_single_dispatch(
639 return ::lgamma(
tmp);
642 double tmp = eval_double_single_dispatch(
647 double tmp = eval_double_single_dispatch(
652 double lhs = eval_double_single_dispatch(
654 double rhs = eval_double_single_dispatch(
659 double lhs = eval_double_single_dispatch(
661 double rhs = eval_double_single_dispatch(
666 double lhs = eval_double_single_dispatch(
668 double rhs = eval_double_single_dispatch(
673 double lhs = eval_double_single_dispatch(
675 double rhs = eval_double_single_dispatch(
682 }
else if (
eq(x, *E)) {
684 }
else if (
eq(x, *EulerGamma)) {
685 return 0.5772156649015328606065;
687 }
else if (
eq(x, *Catalan)) {
688 return 0.9159655941772190150546;
689 }
else if (
eq(x, *GoldenRatio)) {
690 return 1.6180339887498948482045;
694 +
" is not implemented.");
698 double tmp = eval_double_single_dispatch(
700 return std::abs(
tmp);
704 result = eval_double_single_dispatch(
706 for (
const auto &p : down_cast<
const Max &>(x).get_args()) {
707 double tmp = eval_double_single_dispatch(*p);
714 result = eval_double_single_dispatch(
716 for (
const auto &p : down_cast<
const Min &>(x).get_args()) {
717 double tmp = eval_double_single_dispatch(*p);
725double eval_double(
const Basic &b)
727 EvalRealDoubleVisitorFinal v;
733 EvalComplexDoubleVisitor v;
737double eval_double_single_dispatch(
const Basic &b)
743double eval_double_visitor_pattern(
const Basic &b)
745 EvalRealDoubleVisitorPattern v;
749#define ACCEPT(CLASS) \
750 void CLASS::accept(EvalRealDoubleVisitorFinal &v) const \
755#define SYMENGINE_ENUM(TypeID, Class) ACCEPT(Class)
756#include "symengine/type_codes.inc"
RCP< const Basic > get_num() const
RCP< const Basic > get_den() const
The base class for representing addition in symbolic expressions.
vec_basic get_args() const override
Returns the arguments of the Add.
The lowest unit of symbolic representation.
Complex Double Class to hold std::complex<double> values.
std::string get_name() const
const integer_class & as_integer_class() const
Convert to integer_class.
vec_basic get_args() const override
Returns the list of arguments.
vec_basic get_args() const override
Returns the list of arguments.
RCP< const Basic > get_arg() const
vec_basic get_args() const override
Returns the list of arguments.
RCP< const Basic > get_base() const
RCP< const Basic > get_exp() const
const rational_class & as_rational_class() const
Convert to rational_class.
RealDouble Class to hold double values.
RCP< const Basic > get_arg2() const
RCP< const Basic > get_arg1() const
Main namespace for SymEngine package.
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
void hash_combine(hash_t &seed, const T &v)
RCP< const Basic > tan(const RCP< const Basic > &arg)
Canonicalize Tan:
RCP< const Basic > cosh(const RCP< const Basic > &arg)
Canonicalize Cosh:
RCP< const Basic > tanh(const RCP< const Basic > &arg)
Canonicalize Tanh:
RCP< const Basic > cos(const RCP< const Basic > &arg)
Canonicalize Cos:
RCP< const Basic > sinh(const RCP< const Basic > &arg)
Canonicalize Sinh:
RCP< const Basic > sin(const RCP< const Basic > &arg)
Canonicalize Sin: