3 #include <symengine/symengine_exception.h>
5 #ifdef HAVE_SYMENGINE_ARB
10 class EvalArbVisitor :
public BaseVisitor<EvalArbVisitor>
17 EvalArbVisitor(
long precision) : prec_{precision} {}
19 void apply(arb_ptr result,
const Basic &b)
21 arb_ptr tmp = result_;
27 void bvisit(
const Integer &x)
31 fmpz_set_mpz(z_, get_mpz_t(x.as_integer_class()));
32 arb_set_fmpz(result_, z_);
36 void bvisit(
const Rational &x)
40 fmpq_set_mpq(q_, get_mpq_t(x.as_rational_class()));
41 arb_set_fmpq(result_, q_, prec_);
45 void bvisit(
const RealDouble &x)
50 arb_set_arf(result_, f_);
54 void bvisit(
const Add &x)
59 auto d = x.get_args();
60 for (
auto p = d.begin(); p != d.end(); p++) {
63 apply(result_, *(*p));
66 arb_add(result_, result_, t, prec_);
73 void bvisit(
const Mul &x)
78 auto d = x.get_args();
79 for (
auto p = d.begin(); p != d.end(); p++) {
82 apply(result_, *(*p));
85 arb_mul(result_, result_, t, prec_);
92 void bvisit(
const Pow &x)
94 if (
eq(*x.get_base(), *E)) {
95 apply(result_, *(x.get_exp()));
96 arb_exp(result_, result_, prec_);
101 apply(b, *(x.get_base()));
102 apply(result_, *(x.get_exp()));
103 arb_pow(result_, b, result_, prec_);
109 void bvisit(
const Sin &x)
111 apply(result_, *(x.get_arg()));
112 arb_sin(result_, result_, prec_);
115 void bvisit(
const Cos &x)
117 apply(result_, *(x.get_arg()));
118 arb_cos(result_, result_, prec_);
121 void bvisit(
const Tan &x)
123 apply(result_, *(x.get_arg()));
124 arb_tan(result_, result_, prec_);
127 void bvisit(
const Symbol &)
129 throw SymEngineException(
"Symbol cannot be evaluated as an arb type.");
132 void bvisit(
const UIntPoly &)
134 throw NotImplementedError(
"Not Implemented");
137 void bvisit(
const Complex &)
139 throw NotImplementedError(
"Not Implemented");
142 void bvisit(
const ComplexDouble &)
144 throw NotImplementedError(
"Not Implemented");
147 void bvisit(
const RealMPFR &)
149 throw NotImplementedError(
"Not Implemented");
151 #ifdef HAVE_SYMENGINE_MPC
152 void bvisit(
const ComplexMPC &)
154 throw NotImplementedError(
"Not Implemented");
157 void bvisit(
const Log &x)
159 apply(result_, *(x.get_arg()));
160 arb_log(result_, result_, prec_);
163 void bvisit(
const Derivative &)
165 throw NotImplementedError(
"Not Implemented");
168 void bvisit(
const Cot &x)
170 apply(result_, *(x.get_arg()));
171 arb_cot(result_, result_, prec_);
174 void bvisit(
const Csc &x)
176 apply(result_, *(x.get_arg()));
177 arb_sin(result_, result_, prec_);
178 arb_inv(result_, result_, prec_);
181 void bvisit(
const Sec &x)
183 apply(result_, *(x.get_arg()));
184 arb_cos(result_, result_, prec_);
185 arb_inv(result_, result_, prec_);
188 void bvisit(
const ASin &x)
190 apply(result_, *(x.get_arg()));
191 arb_asin(result_, result_, prec_);
194 void bvisit(
const ACos &x)
196 apply(result_, *(x.get_arg()));
197 arb_acos(result_, result_, prec_);
200 void bvisit(
const ASec &x)
202 apply(result_, *(x.get_arg()));
203 arb_inv(result_, result_, prec_);
204 arb_acos(result_, result_, prec_);
207 void bvisit(
const ACsc &x)
209 apply(result_, *(x.get_arg()));
210 arb_inv(result_, result_, prec_);
211 arb_asin(result_, result_, prec_);
214 void bvisit(
const ATan &x)
216 apply(result_, *(x.get_arg()));
217 arb_atan(result_, result_, prec_);
220 void bvisit(
const ACot &x)
222 apply(result_, *(x.get_arg()));
223 arb_inv(result_, result_, prec_);
224 arb_atan(result_, result_, prec_);
227 void bvisit(
const ATan2 &x)
232 apply(t, *(x.get_num()));
233 apply(result_, *(x.get_den()));
234 arb_atan2(result_, t, result_, prec_);
239 void bvisit(
const LambertW &)
241 throw NotImplementedError(
"Not Implemented");
244 void bvisit(
const FunctionWrapper &x)
246 x.eval(prec_)->accept(*
this);
249 void bvisit(
const Sinh &x)
251 apply(result_, *(x.get_arg()));
252 arb_sinh(result_, result_, prec_);
255 void bvisit(
const Csch &)
257 throw NotImplementedError(
"Not Implemented");
260 void bvisit(
const Cosh &x)
262 apply(result_, *(x.get_arg()));
263 arb_cosh(result_, result_, prec_);
266 void bvisit(
const Sech &)
268 throw NotImplementedError(
"Not Implemented");
271 void bvisit(
const Tanh &x)
273 apply(result_, *(x.get_arg()));
274 arb_tanh(result_, result_, prec_);
277 void bvisit(
const Coth &x)
279 apply(result_, *(x.get_arg()));
280 arb_coth(result_, result_, prec_);
283 void bvisit(
const Max &x)
288 auto d = x.get_args();
290 apply(result_, *(*p));
293 for (; p != d.end(); p++) {
296 if (arb_gt(t, result_))
303 void bvisit(
const Min &x)
308 auto d = x.get_args();
310 apply(result_, *(*p));
313 for (; p != d.end(); p++) {
316 if (arb_lt(t, result_))
323 void bvisit(
const ACsch &)
325 throw NotImplementedError(
"Not Implemented");
328 void bvisit(
const ASinh &x)
330 apply(result_, *(x.get_arg()));
331 arb_asinh(result_, result_, prec_);
334 void bvisit(
const ACosh &x)
336 apply(result_, *(x.get_arg()));
337 arb_acosh(result_, result_, prec_);
340 void bvisit(
const ATanh &x)
342 apply(result_, *(x.get_arg()));
343 arb_atanh(result_, result_, prec_);
346 void bvisit(
const ACoth &x)
348 apply(result_, *(x.get_arg()));
349 arb_inv(result_, result_, prec_);
350 arb_atanh(result_, result_, prec_);
353 void bvisit(
const ASech &x)
355 apply(result_, *(x.get_arg()));
356 arb_inv(result_, result_, prec_);
357 arb_acosh(result_, result_, prec_);
360 void bvisit(
const KroneckerDelta &)
362 throw NotImplementedError(
"Not Implemented");
365 void bvisit(
const LeviCivita &)
367 throw NotImplementedError(
"Not Implemented");
370 void bvisit(
const Zeta &x)
375 apply(t_, *(x.get_arg1()));
376 apply(result_, *(x.get_arg2()));
377 arb_hurwitz_zeta(result_, t_, result_, prec_);
382 void bvisit(
const Dirichlet_eta &)
384 throw NotImplementedError(
"Not Implemented");
387 void bvisit(
const Gamma &x)
389 apply(result_, *(x.get_args())[0]);
390 arb_gamma(result_, result_, prec_);
393 void bvisit(
const LogGamma &x)
395 apply(result_, *(x.get_args())[0]);
396 arb_lgamma(result_, result_, prec_);
399 void bvisit(
const LowerGamma &)
401 throw NotImplementedError(
"Not Implemented");
404 void bvisit(
const UpperGamma &)
406 throw NotImplementedError(
"Not Implemented");
409 void bvisit(
const Constant &x)
412 arb_const_pi(result_, prec_);
413 }
else if (x.__eq__(*E)) {
414 arb_const_e(result_, prec_);
415 }
else if (x.__eq__(*EulerGamma)) {
416 arb_const_euler(result_, prec_);
417 }
else if (x.__eq__(*Catalan)) {
418 arb_const_catalan(result_, prec_);
419 }
else if (x.__eq__(*GoldenRatio)) {
420 arb_sqrt_ui(result_, 5, prec_);
421 arb_add_ui(result_, result_, 1, prec_);
422 arb_div_ui(result_, result_, 2, prec_);
424 throw NotImplementedError(
"Constant " + x.get_name()
425 +
" is not implemented.");
429 void bvisit(
const Abs &x)
431 apply(result_, *(x.get_arg()));
432 arb_abs(result_, result_);
435 void bvisit(
const Basic &)
437 throw NotImplementedError(
"Not Implemented");
440 void bvisit(
const NumberWrapper &x)
442 x.eval(prec_)->accept(*
this);
445 void bvisit(
const UnevaluatedExpr &x)
447 apply(result_, *x.get_arg());
451 void eval_arb(arb_t result,
const Basic &b,
long precision)
453 EvalArbVisitor v(precision);
Main namespace for SymEngine package.
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b