void bvisit(const Add &x) { RCP<const Basic> curr_num = zero; RCP<const Basic> curr_den = one; RCP<const Basic> arg_num, arg_den, den_mul, divx; RCP<const Basic> divx_num, divx_den; for (const auto &arg : x.get_args()) { // TODO: This is naive and slow. Fix it as_numer_denom(arg, outArg(arg_num), outArg(arg_den)); divx = div(arg_den, curr_den); as_numer_denom(divx, outArg(divx_num), outArg(divx_den)); if (eq(*divx_den, *one)) { // the curr_den completely divides the arg_den curr_den = arg_den; curr_num = add(mul(curr_num, divx), arg_num); continue; } divx = div(curr_den, arg_den); as_numer_denom(divx, outArg(divx_num), outArg(divx_den)); // the below two lines, cover the general case, as well as the case // where arg_den completely divides curr_den curr_den = mul(curr_den, divx_den); curr_num = add(mul(curr_num, divx_den), mul(arg_num, divx_num)); } *numer_ = curr_num; *denom_ = curr_den; }
void bvisit(const Add &x) { mpfr_class t(mpfr_get_prec(result_)); auto d = x.get_args(); auto p = d.begin(); apply(result_, *(*p)); p++; for (; p != d.end(); p++) { apply(t.get_mpfr_t(), *(*p)); mpfr_add(result_, result_, t.get_mpfr_t(), rnd_); } }