int bessel(acb_ptr out, const acb_t inp, void * params, long order, long prec) { acb_ptr t; acb_t z; ulong n; t = _acb_vec_init(order); acb_init(z); acb_set(t, inp); if (order > 1) acb_one(t + 1); n = 10; arb_set_si(acb_realref(z), 20); arb_set_si(acb_imagref(z), 10); /* z sin(t) */ _acb_poly_sin_series(out, t, FLINT_MIN(2, order), order, prec); _acb_vec_scalar_mul(out, out, order, z, prec); /* t n */ _acb_vec_scalar_mul_ui(t, t, FLINT_MIN(2, order), n, prec); _acb_poly_sub(out, t, FLINT_MIN(2, order), out, order, prec); _acb_poly_cos_series(out, out, order, order, prec); _acb_vec_clear(t, order); acb_clear(z); return 0; }
void custom_rate_mixture_get_prob(arb_t prob, const custom_rate_mixture_t x, slong idx, slong prec) { if (x->mode == RATE_MIXTURE_UNDEFINED) { flint_fprintf(stderr, "internal error: undefined rate mixture\n"); abort(); } else if (x->mode == RATE_MIXTURE_NONE) { arb_one(prob); } else if (x->mode == RATE_MIXTURE_UNIFORM) { /* * This code branch involves a division that could * unnecessarily lose exactness in some situations. */ arb_set_si(prob, x->n); arb_inv(prob, prob, prec); } else if (x->mode == RATE_MIXTURE_CUSTOM) { arb_set_d(prob, x->prior[idx]); } else { flint_fprintf(stderr, "internal error: " "unrecognized rate mixture mode\n"); abort(); } }
static void bsplit(arb_poly_t pol, const arb_t sqrtD, const slong * qbf, slong a, slong b, slong prec) { if (b - a == 0) { arb_poly_one(pol); } else if (b - a == 1) { acb_t z; acb_init(z); /* j((-b+sqrt(-D))/(2a)) */ arb_set_si(acb_realref(z), -FLINT_ABS(qbf[3 * a + 1])); arb_set(acb_imagref(z), sqrtD); acb_div_si(z, z, 2 * qbf[3 * a], prec); acb_modular_j(z, z, prec); if (qbf[3 * a + 1] < 0) { /* (x^2 - 2re(j) x + |j|^2) */ arb_poly_fit_length(pol, 3); arb_mul(pol->coeffs, acb_realref(z), acb_realref(z), prec); arb_addmul(pol->coeffs, acb_imagref(z), acb_imagref(z), prec); arb_mul_2exp_si(pol->coeffs + 1, acb_realref(z), 1); arb_neg(pol->coeffs + 1, pol->coeffs + 1); arb_one(pol->coeffs + 2); _arb_poly_set_length(pol, 3); } else { /* (x-j) */ arb_poly_fit_length(pol, 2); arb_neg(pol->coeffs, acb_realref(z)); arb_one(pol->coeffs + 1); _arb_poly_set_length(pol, 2); } acb_clear(z); } else { arb_poly_t tmp; arb_poly_init(tmp); bsplit(pol, sqrtD, qbf, a, a + (b - a) / 2, prec); bsplit(tmp, sqrtD, qbf, a + (b - a) / 2, b, prec); arb_poly_mul(pol, pol, tmp, prec); arb_poly_clear(tmp); } }
void arb_poly_set_coeff_si(arb_poly_t poly, long n, long x) { arb_poly_fit_length(poly, n + 1); if (n + 1 > poly->length) { _arb_vec_zero(poly->coeffs + poly->length, n - poly->length); poly->length = n + 1; } arb_set_si(poly->coeffs + n, x); _arb_poly_normalise(poly); }
static __inline__ void zeta_coeff_k(zeta_bsplit_t S, slong k, slong n, slong s) { arb_set_si(S->D, 2 * (n + k)); arb_mul_si(S->D, S->D, n - k, ARF_PREC_EXACT); arb_set_si(S->Q1, k + 1); arb_mul_si(S->Q1, S->Q1, 2*k + 1, ARF_PREC_EXACT); if (k == 0) { arb_zero(S->A); arb_one(S->Q2); } else { arb_set_si(S->A, k % 2 ? 1 : -1); arb_mul(S->A, S->A, S->Q1, ARF_PREC_EXACT); arb_ui_pow_ui(S->Q2, k, s, ARF_PREC_EXACT); } arb_mul(S->Q3, S->Q1, S->Q2, ARF_PREC_EXACT); arb_zero(S->B); arb_set(S->C, S->Q1); }
void arb_zeta_ui_borwein_bsplit(arb_t x, ulong s, slong prec) { zeta_bsplit_t sum; mag_t err; slong wp, n; /* zeta(0) = -1/2 */ if (s == 0) { arb_set_si(x, -1); arb_mul_2exp_si(x, x, -1); return; } if (s == 1) { flint_printf("zeta_ui_borwein_bsplit: zeta(1)"); abort(); } n = prec / ERROR_B + 2; wp = prec + 30; zeta_bsplit_init(sum); zeta_bsplit(sum, 0, n + 1, n, s, 0, wp); /* A/Q3 - B/Q3 / (C/Q1) = (A*C - B*Q1) / (Q3*C) */ arb_mul(sum->A, sum->A, sum->C, wp); arb_mul(sum->B, sum->B, sum->Q1, wp); arb_sub(sum->A, sum->A, sum->B, wp); arb_mul(sum->Q3, sum->Q3, sum->C, wp); arb_div(sum->C, sum->A, sum->Q3, wp); mag_init(err); mag_borwein_error(err, n); mag_add(arb_radref(sum->C), arb_radref(sum->C), err); mag_clear(err); /* convert from eta(s) to zeta(s) */ arb_div_2expm1_ui(x, sum->C, s - 1, wp); arb_mul_2exp_si(x, x, s - 1); zeta_bsplit_clear(sum); }
int _acb_modular_hilbert_class_poly(fmpz_poly_t res, slong D, const slong * qbf, slong qbf_len, slong prec) { arb_t sqrtD; arb_poly_t pol; int success; arb_init(sqrtD); arb_poly_init(pol); arb_set_si(sqrtD, -D); arb_sqrt(sqrtD, sqrtD, prec); bsplit(pol, sqrtD, qbf, 0, qbf_len, prec); success = arb_poly_get_unique_fmpz_poly(res, pol); arb_clear(sqrtD); arb_poly_clear(pol); return success; }
int main() { slong iter; flint_rand_t state; flint_printf("taylor_shift_convolution...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 2000 * arb_test_multiplier(); iter++) { slong prec1, prec2; arb_poly_t f, g; arb_t c, d, e; prec1 = 2 + n_randint(state, 500); prec2 = 2 + n_randint(state, 500); arb_poly_init(f); arb_poly_init(g); arb_init(c); arb_init(d); arb_init(e); arb_poly_randtest(f, state, 1 + n_randint(state, 40), 1 + n_randint(state, 500), 10); arb_poly_randtest(g, state, 1 + n_randint(state, 20), 1 + n_randint(state, 500), 10); if (n_randint(state, 2)) arb_set_si(c, n_randint(state, 5) - 2); else arb_randtest(c, state, 1 + n_randint(state, 500), 1 + n_randint(state, 100)); if (n_randint(state, 2)) arb_set_si(d, n_randint(state, 5) - 2); else arb_randtest(d, state, 1 + n_randint(state, 500), 1 + n_randint(state, 100)); arb_add(e, c, d, prec1); /* check f(x+c)(x+d) = f(x+c+d) */ arb_poly_taylor_shift_convolution(g, f, e, prec2); arb_poly_taylor_shift_convolution(f, f, c, prec1); arb_poly_taylor_shift_convolution(f, f, d, prec1); if (!arb_poly_overlaps(f, g)) { flint_printf("FAIL\n\n"); flint_printf("c = "); arb_printd(c, 15); flint_printf("\n\n"); flint_printf("d = "); arb_printd(d, 15); flint_printf("\n\n"); flint_printf("f = "); arb_poly_printd(f, 15); flint_printf("\n\n"); flint_printf("g = "); arb_poly_printd(g, 15); flint_printf("\n\n"); abort(); } arb_poly_clear(f); arb_poly_clear(g); arb_clear(c); arb_clear(d); arb_clear(e); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("sub_si...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000; iter++) { arb_t a, b, c, d; slong x; slong prec; arb_init(a); arb_init(b); arb_init(c); arb_init(d); arb_randtest_special(a, state, 1 + n_randint(state, 2000), 100); arb_randtest_special(b, state, 1 + n_randint(state, 2000), 100); arb_randtest_special(c, state, 1 + n_randint(state, 2000), 100); x = z_randtest(state); prec = 2 + n_randint(state, 2000); arb_set_si(b, x); arb_sub_si(c, a, x, prec); arb_sub(d, a, b, prec); if (!arb_equal(c, d)) { flint_printf("FAIL\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("c = "); arb_print(c); flint_printf("\n\n"); flint_printf("d = "); arb_print(d); flint_printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); arb_clear(d); } /* aliasing */ for (iter = 0; iter < 10000; iter++) { arb_t a, b, c; slong x; slong prec; arb_init(a); arb_init(b); arb_init(c); arb_randtest_special(a, state, 1 + n_randint(state, 2000), 100); arb_randtest_special(b, state, 1 + n_randint(state, 2000), 100); arb_randtest_special(c, state, 1 + n_randint(state, 2000), 100); x = z_randtest(state); prec = 2 + n_randint(state, 2000); arb_set_si(b, x); arb_sub_si(c, a, x, prec); arb_sub_si(a, a, x, prec); if (!arb_equal(a, c)) { flint_printf("FAIL (aliasing)\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("c = "); arb_print(c); flint_printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("power_sum_vec...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++) { arb_t a, b, s, t; arb_ptr res; slong aa, bb, k, n, len; slong prec; len = n_randint(state, 30); prec = 2 + n_randint(state, 500); aa = n_randint(state, 50) - 50; bb = aa + n_randint(state, 50); arb_init(a); arb_init(b); arb_init(s); arb_init(t); res = _arb_vec_init(len); arb_set_si(a, aa); arb_set_si(b, bb); arb_power_sum_vec(res, a, b, len, prec); for (n = 0; n < len; n++) { arb_zero(s); for (k = aa; k < bb; k++) { arb_set_si(t, k); arb_pow_ui(t, t, n, prec); arb_add(s, s, t, prec); } if (!arb_overlaps(res + n, s)) { flint_printf("FAIL: overlap\n\n"); flint_printf("a = %wd, b = %wd, n = %wd\n\n", aa, bb, n); flint_printf("res = "); arb_printd(res + n, 30); flint_printf("\n\n"); flint_printf("s = "); arb_printd(s, 30); flint_printf("\n\n"); abort(); } } arb_clear(a); arb_clear(b); arb_clear(s); arb_clear(t); _arb_vec_clear(res, len); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
void keiper_li_series(arb_ptr z, slong len, slong prec) { arb_ptr t, u, v; t = _arb_vec_init(len); u = _arb_vec_init(len); v = _arb_vec_init(len); /* -zeta(s) */ flint_printf("zeta: "); TIMEIT_ONCE_START arb_zero(t + 0); arb_one(t + 1); arb_one(u); _arb_poly_zeta_series(v, t, 2, u, 0, len, prec); _arb_vec_neg(v, v, len); TIMEIT_ONCE_STOP SHOW_MEMORY_USAGE /* logarithm */ flint_printf("log: "); TIMEIT_ONCE_START _arb_poly_log_series(t, v, len, len, prec); TIMEIT_ONCE_STOP /* add log(gamma(1+s/2)) */ flint_printf("gamma: "); TIMEIT_ONCE_START arb_one(u); arb_one(u + 1); arb_mul_2exp_si(u + 1, u + 1, -1); _arb_poly_lgamma_series(v, u, 2, len, prec); _arb_vec_add(t, t, v, len, prec); TIMEIT_ONCE_STOP /* subtract 0.5 s log(pi) */ arb_const_pi(u, prec); arb_log(u, u, prec); arb_mul_2exp_si(u, u, -1); arb_sub(t + 1, t + 1, u, prec); /* add log(1-s) */ arb_one(u); arb_set_si(u + 1, -1); _arb_poly_log_series(v, u, 2, len, prec); _arb_vec_add(t, t, v, len, prec); /* binomial transform */ flint_printf("binomial transform: "); TIMEIT_ONCE_START arb_set(z, t); _arb_vec_neg(t + 1, t + 1, len - 1); _arb_poly_binomial_transform(z + 1, t + 1, len - 1, len - 1, prec); TIMEIT_ONCE_STOP _arb_vec_clear(t, len); _arb_vec_clear(u, len); _arb_vec_clear(v, len); }
void _arb_poly_rgamma_series(arb_ptr res, arb_srcptr h, long hlen, long len, long prec) { int reflect; long i, rflen, r, n, wp; arb_ptr t, u, v; arb_struct f[2]; hlen = FLINT_MIN(hlen, len); wp = prec + FLINT_BIT_COUNT(prec); t = _arb_vec_init(len); u = _arb_vec_init(len); v = _arb_vec_init(len); arb_init(f); arb_init(f + 1); /* use zeta values at small integers */ if (arb_is_int(h) && (arf_cmpabs_ui(arb_midref(h), prec / 2) < 0)) { r = arf_get_si(arb_midref(h), ARF_RND_DOWN); _arb_poly_lgamma_series_at_one(u, len, wp); _arb_vec_neg(u, u, len); _arb_poly_exp_series(t, u, len, len, wp); if (r == 1) { _arb_vec_swap(v, t, len); } else if (r <= 0) { arb_set(f, h); arb_one(f + 1); rflen = FLINT_MIN(len, 2 - r); _arb_poly_rising_ui_series(u, f, FLINT_MIN(2, len), 1 - r, rflen, wp); _arb_poly_mullow(v, t, len, u, rflen, len, wp); } else { arb_one(f); arb_one(f + 1); rflen = FLINT_MIN(len, r); _arb_poly_rising_ui_series(v, f, FLINT_MIN(2, len), r - 1, rflen, wp); /* TODO: use div_series? */ _arb_poly_inv_series(u, v, rflen, len, wp); _arb_poly_mullow(v, t, len, u, len, len, wp); } } else { /* otherwise use Stirling series */ arb_gamma_stirling_choose_param(&reflect, &r, &n, h, 1, 0, wp); /* rgamma(h) = (gamma(1-h+r) sin(pi h)) / (rf(1-h, r) * pi), h = h0 + t*/ if (reflect) { /* u = gamma(r+1-h) */ arb_sub_ui(f, h, r + 1, wp); arb_neg(f, f); _arb_poly_gamma_stirling_eval(t, f, n, len, wp); _arb_poly_exp_series(u, t, len, len, wp); for (i = 1; i < len; i += 2) arb_neg(u + i, u + i); /* v = sin(pi x) */ arb_const_pi(f + 1, wp); arb_mul(f, h, f + 1, wp); _arb_poly_sin_series(v, f, 2, len, wp); _arb_poly_mullow(t, u, len, v, len, len, wp); /* rf(1-h,r) * pi */ if (r == 0) { arb_const_pi(u, wp); _arb_vec_scalar_div(v, t, len, u, wp); } else { arb_sub_ui(f, h, 1, wp); arb_neg(f, f); arb_set_si(f + 1, -1); rflen = FLINT_MIN(len, r + 1); _arb_poly_rising_ui_series(v, f, FLINT_MIN(2, len), r, rflen, wp); arb_const_pi(u, wp); _arb_vec_scalar_mul(v, v, rflen, u, wp); /* divide by rising factorial */ /* TODO: might better to use div_series, when it has a good basecase */ _arb_poly_inv_series(u, v, rflen, len, wp); _arb_poly_mullow(v, t, len, u, len, len, wp); } } else { /* rgamma(h) = rgamma(h+r) rf(h,r) */ if (r == 0) { arb_add_ui(f, h, r, wp); _arb_poly_gamma_stirling_eval(t, f, n, len, wp); _arb_vec_neg(t, t, len); _arb_poly_exp_series(v, t, len, len, wp); } else { arb_set(f, h); arb_one(f + 1); rflen = FLINT_MIN(len, r + 1); _arb_poly_rising_ui_series(t, f, FLINT_MIN(2, len), r, rflen, wp); arb_add_ui(f, h, r, wp); _arb_poly_gamma_stirling_eval(v, f, n, len, wp); _arb_vec_neg(v, v, len); _arb_poly_exp_series(u, v, len, len, wp); _arb_poly_mullow(v, u, len, t, rflen, len, wp); } } } /* compose with nonconstant part */ arb_zero(t); _arb_vec_set(t + 1, h + 1, hlen - 1); _arb_poly_compose_series(res, v, len, t, hlen, len, prec); arb_clear(f); arb_clear(f + 1); _arb_vec_clear(t, len); _arb_vec_clear(u, len); _arb_vec_clear(v, len); }
int main(int argc, char *argv[]) { acb_t r, s, a, b; arf_t inr, outr; long digits, prec; if (argc < 2) { printf("integrals d\n"); printf("compute integrals using d decimal digits of precision\n"); return 1; } acb_init(r); acb_init(s); acb_init(a); acb_init(b); arf_init(inr); arf_init(outr); arb_calc_verbose = 0; digits = atol(argv[1]); prec = digits * 3.32193; printf("Digits: %ld\n", digits); printf("----------------------------------------------------------------\n"); printf("Integral of sin(t) from 0 to 100.\n"); arf_set_d(inr, 0.125); arf_set_d(outr, 1.0); TIMEIT_ONCE_START acb_set_si(a, 0); acb_set_si(b, 100); acb_calc_integrate_taylor(r, sinx, NULL, a, b, inr, outr, prec, 1.1 * prec); printf("RESULT:\n"); acb_printd(r, digits); printf("\n"); TIMEIT_ONCE_STOP printf("----------------------------------------------------------------\n"); printf("Elliptic integral F(phi, m) = integral of 1/sqrt(1 - m*sin(t)^2)\n"); printf("from 0 to phi, with phi = 6+6i, m = 1/2. Integration path\n"); printf("0 -> 6 -> 6+6i.\n"); arf_set_d(inr, 0.2); arf_set_d(outr, 0.5); TIMEIT_ONCE_START acb_set_si(a, 0); acb_set_si(b, 6); acb_calc_integrate_taylor(r, elliptic, NULL, a, b, inr, outr, prec, 1.1 * prec); acb_set_si(a, 6); arb_set_si(acb_realref(b), 6); arb_set_si(acb_imagref(b), 6); acb_calc_integrate_taylor(s, elliptic, NULL, a, b, inr, outr, prec, 1.1 * prec); acb_add(r, r, s, prec); printf("RESULT:\n"); acb_printd(r, digits); printf("\n"); TIMEIT_ONCE_STOP printf("----------------------------------------------------------------\n"); printf("Bessel function J_n(z) = (1/pi) * integral of cos(t*n - z*sin(t))\n"); printf("from 0 to pi. With n = 10, z = 20 + 10i.\n"); arf_set_d(inr, 0.1); arf_set_d(outr, 0.5); TIMEIT_ONCE_START acb_set_si(a, 0); acb_const_pi(b, 3 * prec); acb_calc_integrate_taylor(r, bessel, NULL, a, b, inr, outr, prec, 3 * prec); acb_div(r, r, b, prec); printf("RESULT:\n"); acb_printd(r, digits); printf("\n"); TIMEIT_ONCE_STOP acb_clear(r); acb_clear(s); acb_clear(a); acb_clear(b); arf_clear(inr); arf_clear(outr); flint_cleanup(); return 0; }
int main() { slong iter; FLINT_TEST_INIT(state); { ulong k; arb_t a,b; arf_t c,d; fmpq_poly_t p; arb_init(a); arb_init(b); arf_init(c); arf_init(d); /* x+1 */ fmpq_poly_init(p); fmpq_poly_set_coeff_si(p, 0, 1); fmpq_poly_set_coeff_si(p, 1, 1); for (iter = 0; iter < 5000; iter++) { k = n_randint(state, 10000); arb_set_si(a, k); fmpq_poly_evaluate_arb(b, p, a, 30 + n_randint(state, 100)); if (!arb_equal_si(b, k + 1)) { printf("FAIL (fmpq_poly_evaluate_arb):\n"); printf("a = "); arb_print(a); printf("\n"); printf("b = "); arb_print(b); printf("\n"); printf("p = "); fmpq_poly_print(p); printf("\n"); abort(); } arf_set_si(c, k); fmpq_poly_evaluate_arf(d, p, c, 30 + n_randint(state, 100)); if (!arf_equal_si(d, k + 1)) { printf("FAIL (fmpq_poly_evaluate_arf):\n"); printf("c = "); arf_print(c); printf("\n"); printf("d = "); arf_print(d); printf("\n"); printf("p = "); fmpq_poly_print(p); printf("\n"); abort(); } } /* x^2 */ fmpq_poly_zero(p); fmpq_poly_set_coeff_si(p, 2, 1); for (iter = 0; iter < 1000; iter++) { k = n_randint(state, 10000); arb_set_si(a, k); fmpq_poly_evaluate_arb(b, p, a, 30 + n_randint(state, 100)); if (!arb_equal_si(b, k * k)) { printf("Error (test_fmpq_poly_evaluate_arb):\n"); printf("a = "); arb_print(a); printf("\n"); printf("b = "); arb_print(b); printf("\n"); printf("p = "); fmpq_poly_print(p); printf("\n"); abort(); } arf_set_si(c, k); fmpq_poly_evaluate_arf(d, p, c, 30 + n_randint(state, 100)); if (!arf_equal_si(d, k * k)) { printf("Error (test_fmpq_poly_evaluate_arf):\n"); printf("c = "); arf_print(c); printf("\n"); printf("d = "); arf_print(d); printf("\n"); printf("p = "); fmpq_poly_print(p); printf("\n"); abort(); } } fmpq_poly_clear(p); arb_clear(a); arb_clear(b); arf_clear(c); arf_clear(d); } /* check evaluate_arb agains exact evaluate_fmpq */ for (iter = 0; iter < 1000; iter++) { fmpq_poly_t p; fmpq_t x,y; arb_t a,b; fmpq_poly_init(p); fmpq_init(x); fmpq_init(y); arb_init(a); arb_init(b); fmpq_poly_randtest(p, state, 1 + n_randint(state,100), 10); fmpq_randtest(x, state, 10); arb_set_fmpq(a, x, 64); fmpq_poly_evaluate_fmpq(y, p, x); fmpq_poly_evaluate_arb(b, p, a, 60); if (!arb_contains_fmpq(b, y)) { printf("FAIL (y not in b):\n"); printf("p = "); fmpq_poly_print(p); printf("\n"); printf("x = "); fmpq_print(x); printf("\n"); printf("y = "); fmpq_print(y); printf("\n"); printf("a = "); arb_print(a); printf("\n"); printf("b = "); arb_print(b); printf("\n"); abort(); } fmpq_poly_evaluate_arb(a, p, a, 60); if (!arb_equal(a,b)) { printf("FAIL (a not equal b):\n"); printf("p = "); fmpq_poly_print(p); printf("\n"); printf("x = "); fmpq_print(x); printf("\n"); printf("y = "); fmpq_print(y); printf("\n"); printf("a = "); arb_print(a); printf("\n"); printf("b = "); arb_print(b); printf("\n"); abort(); } fmpq_poly_clear(p); fmpq_clear(x); fmpq_clear(y); arb_clear(a); arb_clear(b); } /* test aliasing */ for (iter = 0; iter < 1000; iter++) { fmpq_poly_t p; arb_t a,b; arf_t c,d; fmpq_poly_init(p); arb_init(a); arb_init(b); arf_init(c); arf_init(d); fmpq_poly_randtest(p, state, 1 + n_randint(state,100), 10); arb_randtest(a, state, 60, 10); arb_randtest(b, state, 60, 10); arf_randtest(c, state, 60, 10); arf_randtest(d, state, 60, 10); fmpq_poly_evaluate_arb(b, p, a, 60); fmpq_poly_evaluate_arb(a, p, a, 60); if (!arb_equal(a, b)) { printf("FAIL (a not equal b):\n"); printf("p = "); fmpq_poly_print(p); printf("\n"); printf("a = "); arb_print(a); printf("\n"); printf("b = "); arb_print(b); printf("\n"); abort(); } fmpq_poly_evaluate_arf(d, p, c, 60); fmpq_poly_evaluate_arf(c, p, c, 60); if (!arf_equal(c, d)) { printf("FAIL (c not equal d):\n"); printf("p = "); fmpq_poly_print(p); printf("\n"); printf("c = "); arf_print(c); printf("\n"); printf("d = "); arf_print(d); printf("\n"); } fmpq_poly_clear(p); arb_clear(a); arb_clear(b); arf_clear(c); arf_clear(d); } FLINT_TEST_CLEANUP(state); return 0; }
void _arb_poly_zeta_series(arb_ptr res, arb_srcptr h, long hlen, const arb_t a, int deflate, long len, long prec) { long i; acb_t cs, ca; acb_ptr z; arb_ptr t, u; if (arb_contains_nonpositive(a)) { _arb_vec_indeterminate(res, len); return; } hlen = FLINT_MIN(hlen, len); z = _acb_vec_init(len); t = _arb_vec_init(len); u = _arb_vec_init(len); acb_init(cs); acb_init(ca); /* use reflection formula */ if (arf_sgn(arb_midref(h)) < 0 && arb_is_one(a)) { /* zeta(s) = (2*pi)**s * sin(pi*s/2) / pi * gamma(1-s) * zeta(1-s) */ arb_t pi; arb_ptr f, s1, s2, s3, s4; arb_init(pi); f = _arb_vec_init(2); s1 = _arb_vec_init(len); s2 = _arb_vec_init(len); s3 = _arb_vec_init(len); s4 = _arb_vec_init(len); arb_const_pi(pi, prec); /* s1 = (2*pi)**s */ arb_mul_2exp_si(pi, pi, 1); _arb_poly_pow_cpx(s1, pi, h, len, prec); arb_mul_2exp_si(pi, pi, -1); /* s2 = sin(pi*s/2) / pi */ arb_set(f, h); arb_one(f + 1); arb_mul_2exp_si(f, f, -1); arb_mul_2exp_si(f + 1, f + 1, -1); _arb_poly_sin_pi_series(s2, f, 2, len, prec); _arb_vec_scalar_div(s2, s2, len, pi, prec); /* s3 = gamma(1-s) */ arb_sub_ui(f, h, 1, prec); arb_neg(f, f); arb_set_si(f + 1, -1); _arb_poly_gamma_series(s3, f, 2, len, prec); /* s4 = zeta(1-s) */ arb_sub_ui(f, h, 1, prec); arb_neg(f, f); acb_set_arb(cs, f); acb_one(ca); _acb_poly_zeta_cpx_series(z, cs, ca, 0, len, prec); for (i = 0; i < len; i++) arb_set(s4 + i, acb_realref(z + i)); for (i = 1; i < len; i += 2) arb_neg(s4 + i, s4 + i); _arb_poly_mullow(u, s1, len, s2, len, len, prec); _arb_poly_mullow(s1, s3, len, s4, len, len, prec); _arb_poly_mullow(t, u, len, s1, len, len, prec); /* add 1/(1-(s+t)) = 1/(1-s) + t/(1-s)^2 + ... */ if (deflate) { arb_sub_ui(u, h, 1, prec); arb_neg(u, u); arb_inv(u, u, prec); for (i = 1; i < len; i++) arb_mul(u + i, u + i - 1, u, prec); _arb_vec_add(t, t, u, len, prec); } arb_clear(pi); _arb_vec_clear(f, 2); _arb_vec_clear(s1, len); _arb_vec_clear(s2, len); _arb_vec_clear(s3, len); _arb_vec_clear(s4, len); } else { acb_set_arb(cs, h); acb_set_arb(ca, a); _acb_poly_zeta_cpx_series(z, cs, ca, deflate, len, prec); for (i = 0; i < len; i++) arb_set(t + i, acb_realref(z + i)); } /* compose with nonconstant part */ arb_zero(u); _arb_vec_set(u + 1, h + 1, hlen - 1); _arb_poly_compose_series(res, t, len, u, hlen, len, prec); _acb_vec_clear(z, len); _arb_vec_clear(t, len); _arb_vec_clear(u, len); acb_init(cs); acb_init(ca); }
void Lib_Arb_Set_Si(ArbPtr x, int32_t a) { arb_set_si( (arb_ptr) x, a); }