int main() { slong iter; flint_rand_t state; flint_printf("l...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++) { acb_t s, t, u; dirichlet_group_t G; dirichlet_char_t chi; ulong q, k; slong prec; acb_init(s); acb_init(t); acb_init(u); q = 1 + n_randint(state, 50); prec = 2 + n_randint(state, 100); k = n_randint(state, n_euler_phi(q)); dirichlet_group_init(G, q); dirichlet_char_init(chi, G); dirichlet_char_index(chi, G, k); if (n_randint(state, 2)) acb_set_si(s, n_randint(state, 50) - 25); else acb_randtest(s, state, 2 + n_randint(state, 200), 2); acb_dirichlet_l_hurwitz(t, s, NULL, G, chi, prec); acb_dirichlet_l(u, s, G, chi, prec); if (!acb_overlaps(t, u)) { flint_printf("FAIL: overlap\n\n"); flint_printf("iter = %ld q = %lu k = %lu prec = %ld\n\n", iter, q, k, prec); flint_printf("s = "); acb_printn(s, 100, 0); flint_printf("\n\n"); flint_printf("t = "); acb_printn(t, 100, 0); flint_printf("\n\n"); flint_printf("u = "); acb_printn(u, 100, 0); flint_printf("\n\n"); abort(); } dirichlet_char_clear(chi); dirichlet_group_clear(G); acb_clear(s); acb_clear(t); acb_clear(u); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
void arith_cos_minpoly(fmpz_poly_t poly, ulong n) { if (n == 0) { fmpz_poly_set_ui(poly, UWORD(1)); } else { slong d = (n <= 2) ? 1 : n_euler_phi(n) / 2; fmpz_poly_fit_length(poly, d + 1); _arith_cos_minpoly(poly->coeffs, d, n); _fmpz_poly_set_length(poly, d + 1); } }
void arith_euler_phi(fmpz_t res, const fmpz_t n) { fmpz_factor_t factors; fmpz_t t; ulong exp; slong i; if (fmpz_sgn(n) <= 0) { fmpz_zero(res); return; } if (fmpz_abs_fits_ui(n)) { fmpz_set_ui(res, n_euler_phi(fmpz_get_ui(n))); return; } fmpz_factor_init(factors); fmpz_factor(factors, n); fmpz_one(res); fmpz_init(t); for (i = 0; i < factors->num; i++) { fmpz_sub_ui(t, factors->p + i, UWORD(1)); fmpz_mul(res, res, t); exp = factors->exp[i]; if (exp != 1) { fmpz_pow_ui(t, factors->p + i, exp - UWORD(1)); fmpz_mul(res, res, t); } } fmpz_clear(t); fmpz_factor_clear(factors); }
int main() { slong iter; flint_rand_t state; flint_printf("chi...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { acb_t zn1, zn2, zn1n2, zn1zn2; dirichlet_group_t G; dirichlet_char_t chi; ulong q, m, n1, n2, iter2; int res; q = 1 + n_randint(state, 1000); dirichlet_group_init(G, q); dirichlet_char_init(chi, G); acb_init(zn1); acb_init(zn2); acb_init(zn1n2); acb_init(zn1zn2); /* check chi(n1) chi(n2) = chi(n1 n2) */ for (iter2 = 0; iter2 < 10; iter2++) { do { m = 1 + n_randint(state, q); } while (n_gcd(q, m) != 1); dirichlet_char_log(chi, G, m); n1 = n_randint(state, 1000); n2 = n_randint(state, 1000); acb_dirichlet_chi(zn1, G, chi, n1, 53); acb_dirichlet_pairing(zn2, G, m, n1, 53); if (!acb_overlaps(zn1, zn2)) { flint_printf("FAIL: overlap\n\n"); flint_printf("q = %wu\n\n", q); flint_printf("m = %wu\n\n", m); flint_printf("n = %wu\n\n", n1); flint_printf("char = "); acb_printd(zn1, 15); flint_printf("\n\n"); flint_printf("pairing = "); acb_printd(zn2, 15); flint_printf("\n\n"); dirichlet_char_print(G, chi); dirichlet_char_log(chi, G, m); flint_printf("log(m) = "); dirichlet_char_print(G, chi); dirichlet_char_log(chi, G, n1); flint_printf("log(n1) = "); dirichlet_char_print(G, chi); flint_abort(); } acb_dirichlet_pairing(zn2, G, m, n2, 53); acb_dirichlet_pairing(zn1n2, G, m, n1 * n2, 53); acb_mul(zn1zn2, zn1, zn2, 53); if (!acb_overlaps(zn1n2, zn1zn2)) { flint_printf("FAIL: overlap\n\n"); flint_printf("q = %wu\n\n", q); flint_printf("m = %wu\n\n", m); flint_printf("n1 = %wu\n\n", n1); flint_printf("n2 = %wu\n\n", n2); flint_printf("zn1 = "); acb_printd(zn1, 15); flint_printf("\n\n"); flint_printf("zn2 = "); acb_printd(zn2, 15); flint_printf("\n\n"); flint_printf("zn1n2 = "); acb_printd(zn1n2, 15); flint_printf("\n\n"); flint_printf("zn1zn2 = "); acb_printd(zn1zn2, 15); flint_printf("\n\n"); flint_abort(); } } if (iter % 10 == 0) { /* check orthogonality */ acb_zero(zn1); n1 = n_randint(state, 1000); for (m = 1; m <= q; m++) { if (n_gcd(q, m) == 1) { acb_dirichlet_pairing(zn2, G, m, n1, 53); acb_add(zn1, zn1, zn2, 53); } } if (n1 % q == 1 % q) res = arb_contains_si(acb_realref(zn1), n_euler_phi(q)) && arb_contains_zero(acb_imagref(zn1)); else res = acb_contains_zero(zn1); if (!res) { flint_printf("FAIL: orthogonality\n\n"); flint_printf("q = %wu\n\n", q); flint_printf("phi = %wu\n\n", n_euler_phi(q)); flint_printf("n1 = %wu\n\n", n1); flint_printf("zn1 = "); acb_printd(zn1, 15); flint_printf("\n\n"); flint_abort(); } } dirichlet_group_clear(G); dirichlet_char_clear(chi); acb_clear(zn1); acb_clear(zn2); acb_clear(zn1n2); acb_clear(zn1zn2); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("hardy_z...."); fflush(stdout); flint_randinit(state); /* test self-consistency */ for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++) { acb_t s, s2; dirichlet_group_t G; dirichlet_char_t chi; acb_ptr vec1, vec2; slong len1, len2; slong prec1, prec2; ulong q, k; slong i; len1 = n_randint(state, 6); len2 = n_randint(state, 6); prec1 = 2 + n_randint(state, 100); prec2 = 2 + n_randint(state, 100); do { q = 1 + n_randint(state, 30); } while (q % 4 == 2); dirichlet_group_init(G, q); dirichlet_char_init(chi, G); do { k = n_randint(state, n_euler_phi(q)); dirichlet_char_index(chi, G, k); } while (dirichlet_conductor_char(G, chi) != q); acb_init(s); acb_init(s2); vec1 = _acb_vec_init(len1); vec2 = _acb_vec_init(len2); acb_randtest(s, state, 2 + n_randint(state, 200), 2); acb_randtest(s2, state, 2 + n_randint(state, 200), 2); acb_sub(s2, s2, s2, 200); acb_add(s2, s, s2, 200); acb_dirichlet_hardy_z(vec1, s, G, chi, len1, prec1); acb_dirichlet_hardy_z(vec2, s2, G, chi, len2, prec2); for (i = 0; i < FLINT_MIN(len1, len2); i++) { if (!acb_overlaps(vec1 + i, vec2 + i)) { flint_printf("FAIL: overlap\n\n"); flint_printf("iter = %wd q = %wu k = %wu i = %wd\n\n", iter, q, k, i); flint_printf("s = "); acb_printn(s, 50, 0); flint_printf("\n\n"); flint_printf("r1 = "); acb_printn(vec1 + i, 50, 0); flint_printf("\n\n"); flint_printf("r2 = "); acb_printn(vec2 + i, 50, 0); flint_printf("\n\n"); flint_abort(); } } if (arb_contains_zero(acb_imagref(s))) { for (i = 0; i < len1; i++) { if (!arb_contains_zero(acb_imagref(vec1 + i))) { flint_printf("FAIL: real 1\n\n"); flint_printf("iter = %wd q = %wu k = %wu i = %wd\n\n", iter, q, k, i); flint_printf("s = "); acb_printn(s, 50, 0); flint_printf("\n\n"); flint_printf("r1 = "); acb_printn(vec1 + i, 50, 0); flint_printf("\n\n"); flint_abort(); } } } if (arb_contains_zero(acb_imagref(s2))) { for (i = 0; i < len2; i++) { if (!arb_contains_zero(acb_imagref(vec2 + i))) { flint_printf("FAIL: real 1\n\n"); flint_printf("iter = %wd q = %wu k = %wu i = %wd\n\n", iter, q, k, i); flint_printf("s = "); acb_printn(s, 50, 0); flint_printf("\n\n"); flint_printf("r1 = "); acb_printn(vec2 + i, 50, 0); flint_printf("\n\n"); flint_abort(); } } } dirichlet_char_clear(chi); dirichlet_group_clear(G); acb_clear(s); acb_clear(s2); _acb_vec_clear(vec1, len1); _acb_vec_clear(vec2, len2); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }