int main(int argc, char *argv[]) { int out; ulong n, nref, maxq = 5000; ulong * rand; flint_rand_t state; slong r, nr; int l, nf = 5; do_f func[5] = { acb_dirichlet_gauss_sum_naive, acb_dirichlet_gauss_sum_factor, acb_dirichlet_gauss_sum_theta, acb_dirichlet_gauss_sum, acb_dirichlet_gauss_sum }; char * name[5] = { "naive", "factor", "theta", "default", "precomp" }; int i, ni = 5; ulong qmin[5] = { 3, 50, 500, 1000, 10000 }; ulong qmax[5] = { 50, 100, 599, 1050, 10030 }; int j, nj = 3; slong prec[3] = { 64, 128, 1024 }; if (argc < 2) out = LOG; else if (!strcmp(argv[1], "json")) out = JSON; else if (!strcmp(argv[1], "csv")) out = CSV; else if (!strcmp(argv[1], "log")) out = LOG; else { printf("usage: %s [log|csv|json]\n", argv[0]); flint_abort(); } if (out == CSV) flint_printf("# %-12s, %7s, %7s, %7s, %7s\n","name", "prec", "qmin", "qmax", "time"); for (j = 0; j < nj; j++) { for (i = 0; i < ni; i++) { if (out == LOG) flint_printf("G_q(a) at prec %wu for all %wu <= q <= %wu....\n", prec[j], qmin[i], qmax[i]); for (l = 0; l < nf; l++) { ulong q; if (qmin[i] > 2000 && l == 0) continue; if (out == LOG) flint_printf("%-14s ... ", name[l]); else if (out == CSV) flint_printf("%-12s, %7d, %7d, %7d, ", name[l], prec[j], qmin[i], qmax[i]); else if (out == JSON) flint_printf("{ \"name\": \"%s\", \"prec\": %d, \"qmin\": %d, \"qmax\": %d, \"time\": ", name[l], prec[j], qmin[i], qmax[i]); TIMEIT_ONCE_START for (q = qmin[i]; q <= qmax[i]; q++) { dirichlet_group_t G; dirichlet_char_t chi; acb_t res; if (q % 4 == 2) continue; dirichlet_group_init(G, q); if (l == 4) dirichlet_group_dlog_precompute(G, 1); dirichlet_char_init(chi, G); dirichlet_char_first_primitive(chi, G); acb_init(res); do { func[l](res, G, chi, prec[j]); } while (dirichlet_char_next_primitive(chi, G) >= 0); acb_clear(res); dirichlet_char_clear(chi); if (l == 4) dirichlet_group_dlog_clear(G); dirichlet_group_clear(G); } TIMEIT_ONCE_STOP if (out == JSON) flint_printf("}\n"); else flint_printf("\n"); } } } flint_cleanup(); return EXIT_SUCCESS; }
int main() { slong iter, bits; flint_rand_t state; flint_printf("properties...."); fflush(stdout); flint_randinit(state); for (bits = 5; bits <= 30; bits += 5) { for (iter = 0; iter < 50; iter++) { dirichlet_group_t G; dirichlet_char_t chi, psi; ulong q, iter2; q = 2 + n_randint(state, 1 << bits); dirichlet_group_init(G, q); dirichlet_char_init(chi, G); dirichlet_char_init(psi, G); /* check number char properties */ for (iter2 = 0; iter2 < 100; iter2++) { ulong m, n; ulong p1, p2, pairing, cm, cn, q2, q3; dirichlet_group_t G2, G3; dirichlet_char_t chi2, chi3; if (iter2 == 50) dirichlet_group_dlog_precompute(G, 5); /* one random character */ do m = n_randint(state, q); while (n_gcd(q, m) > 1); dirichlet_char_log(chi, G, m); p1 = dirichlet_order_ui(G, m); p2 = dirichlet_order_char(G, chi); check_eq(p1, p2, q, m, "order m", "order chi"); p1 = dirichlet_conductor_ui(G, m); p2 = dirichlet_conductor_char(G, chi); check_eq(p1, p2, q, m, "conductor m", "conductor chi"); p1 = dirichlet_parity_ui(G, m); p2 = dirichlet_parity_char(G, chi); check_eq(p1, p2, q, m, "parity m", "parity chi"); p1 = dirichlet_char_is_real(G, chi); p2 = (dirichlet_order_char(G, chi) <= 2); check_eq(p1, p2, q, m, "is_real", "(order <= 2)"); /* check index */ p1 = dirichlet_index_char(G, chi); dirichlet_char_index(psi, G, p1); if (!dirichlet_char_eq_deep(G, chi, psi)) { flint_printf("FAIL: index\n\n"); flint_printf("q = %wu\n\n", q); flint_printf("m = %wu\n\n", m); flint_printf("chi = "); dirichlet_char_print(G, chi); flint_printf("\n\nindex(chi) = %wu\n\n", p1); flint_printf("psi(index) = %wu\n\n", psi->n); flint_printf("psi = "); dirichlet_char_print(G, psi); flint_printf("\n\n"); abort(); } /* lift to higher modulus */ q2 = q * (1 + n_randint(state, 100)); dirichlet_group_init(G2, q2); dirichlet_char_init(chi2, G2); dirichlet_char_lift(chi2, G2, chi, G); p1 = dirichlet_conductor_char(G, chi); p2 = dirichlet_conductor_char(G2, chi2); check_eq(p1, p2, q, m, "conductor chi", "conductor lift"); p1 = dirichlet_order_char(G, chi); p2 = dirichlet_order_char(G2, chi2); check_eq(p1, p2, q, m, "order chi", "order lift"); /* and lower */ dirichlet_char_lower(psi, G, chi2, G2); if (!dirichlet_char_eq_deep(G, chi, psi)) { flint_printf("FAIL: lift and lower back\n\n"); flint_printf("q = %wu\n\nchi = ", q); dirichlet_char_print(G, chi); flint_printf("\n\nq2 = %wu\n\nchi2 = ", q2); dirichlet_char_print(G2, chi2); flint_printf("\n\nq = %wu\n\npsi = ", q); dirichlet_char_print(G, psi); flint_printf("\n\n"); abort(); } q3 = dirichlet_conductor_char(G, chi) * random_divisor(state, G); q3 = n_gcd(q, q3); dirichlet_group_init(G3, q3); dirichlet_char_init(chi3, G3); dirichlet_char_lower(chi3, G3, chi2, G2); p1 = dirichlet_conductor_char(G, chi); p2 = dirichlet_conductor_char(G3, chi3); check_eq(p1, p2, q, m, "conductor chi", "conductor lower"); p1 = dirichlet_order_char(G, chi); p2 = dirichlet_order_char(G3, chi3); check_eq(p1, p2, q, m, "order chi", "order lower"); dirichlet_char_clear(chi3); dirichlet_group_clear(G3); dirichlet_char_clear(chi2); dirichlet_group_clear(G2); /* another random character */ do n = n_randint(state, q); while (n_gcd(q, n) > 1); dirichlet_char_log(psi, G, n); pairing = dirichlet_pairing(G, m, n); cn = dirichlet_chi(G, chi, n); cm = dirichlet_chi(G, psi, m); if (pairing != cn || pairing != cm) { flint_printf("FAIL: pairing\n\n"); flint_printf("q = %wu\n\n", q); flint_printf("m = %wu\n\n", m); flint_printf("n = %wu\n\n", n); flint_printf("chi(m,n) = %wu\n\n", pairing); flint_printf("chi(m)(n) = %wu\n\n", cn); flint_printf("chi(n)(m) = %wu\n\n", cm); abort(); } } dirichlet_group_dlog_clear(G); dirichlet_char_clear(chi); dirichlet_char_clear(psi); dirichlet_group_clear(G); } } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }