int main() { long p = 1000; long d = 53; arb_t a, b, x, t; arb_init(a); arb_init(b); arb_init(x); arb_init(t); // a = 1 + 2 ^ -76 arb_set_str(a, "2", p); arb_set_str(t, "-76", p); arb_pow(a, a, t, p); arb_set_str(t, "1", p); arb_add(a, t, a, p); printf("a = "); arb_printd(a, d); printf("\n"); // b = 4 ^ 38 + 0.5 arb_set_str(b, "0.5", p); arb_ui_pow_ui(t, 4, 38, p); arb_add(b, t, b, p); printf("b = "); arb_printd(b, d); printf("\n"); // x = a ^ b arb_pow(x, a, b, p); printf("x = "); arb_printd(x, d); printf("\n"); arb_const_e(t, p); printf("e = "); arb_printd(t, d); printf("\n"); arb_sub(t, x, t, p); printf("x-e = "); arb_printd(t, d); printf("\n"); printf("Computed with arb-%s\n", arb_version); arb_clear(a); arb_clear(b); arb_clear(x); arb_clear(t); }
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); }
int main() { slong iter; flint_rand_t state; flint_printf("bernoulli_poly_ui...."); fflush(stdout); flint_randinit(state); /* test multiplication theorem */ for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++) { acb_t x, t, res1, res2; ulong n, m, k; slong prec; n = n_randint(state, 50); m = 1 + n_randint(state, 5); prec = 2 + n_randint(state, 200); acb_init(x); acb_init(t); acb_init(res1); acb_init(res2); acb_randtest(x, state, 2 + n_randint(state, 200), 20); acb_randtest(res1, state, 2 + n_randint(state, 200), 20); acb_mul_ui(t, x, m, prec); acb_bernoulli_poly_ui(res1, n, t, prec); acb_zero(res2); for (k = 0; k < m; k++) { acb_set_ui(t, k); acb_div_ui(t, t, m, prec); acb_add(t, t, x, prec); acb_bernoulli_poly_ui(t, n, t, prec); acb_add(res2, res2, t, prec); } if (n > 0) { arb_ui_pow_ui(acb_realref(t), m, n - 1, prec); acb_mul_arb(res2, res2, acb_realref(t), prec); } else { acb_div_ui(res2, res2, m, prec); } if (!acb_overlaps(res1, res2)) { flint_printf("FAIL: overlap\n\n"); flint_printf("n = %wu, m = %wu\n\n", n, m); flint_printf("x = "); acb_printd(x, 15); flint_printf("\n\n"); flint_printf("res1 = "); acb_printd(res1, 15); flint_printf("\n\n"); flint_printf("res2 = "); acb_printd(res2, 15); flint_printf("\n\n"); abort(); } acb_clear(x); acb_clear(t); acb_clear(res1); acb_clear(res2); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
void bernoulli_rev_init(bernoulli_rev_t iter, ulong nmax) { long j; fmpz_t t; arb_t x; arf_t u; int round1, round2; long wp; nmax -= (nmax % 2); iter->n = nmax; iter->alloc = 0; if (nmax < BERNOULLI_REV_MIN) return; iter->prec = wp = bernoulli_global_prec(nmax); iter->max_power = bernoulli_zeta_terms(nmax, iter->prec); iter->alloc = iter->max_power + 1; iter->powers = _fmpz_vec_init(iter->alloc); fmpz_init(iter->pow_error); arb_init(iter->prefactor); arb_init(iter->two_pi_squared); arb_init(x); fmpz_init(t); arf_init(u); /* precompute powers */ for (j = 3; j <= iter->max_power; j += 2) { arb_ui_pow_ui(x, j, nmax, bernoulli_power_prec(j, nmax, wp)); arb_inv(x, x, bernoulli_power_prec(j, nmax, wp)); round1 = arf_get_fmpz_fixed_si(t, arb_midref(x), -wp); fmpz_set(iter->powers + j, t); /* error: the radius, plus two roundings */ arf_set_mag(u, arb_radref(x)); round2 = arf_get_fmpz_fixed_si(t, u, -wp); fmpz_add_ui(t, t, (round1 != 0) + (round2 != 0)); if (fmpz_cmp(iter->pow_error, t) < 0) fmpz_set(iter->pow_error, t); } /* precompute (2pi)^2 and 2*(n!)/(2pi)^n */ arb_fac_ui(iter->prefactor, nmax, wp); arb_mul_2exp_si(iter->prefactor, iter->prefactor, 1); arb_const_pi(x, wp); arb_mul_2exp_si(x, x, 1); arb_mul(iter->two_pi_squared, x, x, wp); arb_pow_ui(x, iter->two_pi_squared, nmax / 2, wp); arb_div(iter->prefactor, iter->prefactor, x, wp); fmpz_clear(t); arb_clear(x); arf_clear(u); }