From 1b4f926c07d97be365621e52628c637cfa3772f3 Mon Sep 17 00:00:00 2001 From: Fredrik Johansson Date: Sat, 1 Jun 2024 18:58:48 +0200 Subject: [PATCH] test dlog_rho --- src/dlog/rho.c | 5 +++++ src/dlog/test/t-dlog.c | 19 ++++++++++++++----- src/dlog/test/t-modpe.c | 2 +- src/dlog/test/t-vec.c | 2 +- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/dlog/rho.c b/src/dlog/rho.c index 2e0a714bf6..d2ad05c8cd 100644 --- a/src/dlog/rho.c +++ b/src/dlog/rho.c @@ -76,6 +76,10 @@ dlog_rho(const dlog_rho_t t, ulong b) flint_rand_init(state); + /* Fixme: the general algorithm hangs */ + if (t->mod.n <= 3) + return dlog_single(b, t->a, t->mod, t->n.n); + do { for (k = 0; k < RWALK; k++) @@ -116,3 +120,4 @@ dlog_rho(const dlog_rho_t t, ulong b) else return nmod_div(e[0], f[0], t->n); } + diff --git a/src/dlog/test/t-dlog.c b/src/dlog/test/t-dlog.c index 4b127c539c..bfef5b38f8 100644 --- a/src/dlog/test/t-dlog.c +++ b/src/dlog/test/t-dlog.c @@ -17,11 +17,12 @@ TEST_FUNCTION_START(dlog, state) { slong iter; - for (iter = 0; iter < 1000; iter++) + for (iter = 0; iter < 100 * flint_test_multiplier(); iter++) { dlog_table_t table; dlog_bsgs_t bsgs; dlog_crt_t crt; + dlog_rho_t rho; dlog_precomp_t pre1, pre100; ulong p, a, k; nmod_t modp; @@ -37,12 +38,13 @@ TEST_FUNCTION_START(dlog, state) dlog_table_init(table, a, p); dlog_bsgs_init(bsgs, a, p, p-1, dlog_bsgs_size(p, 1)); dlog_crt_init(crt, a, p, p-1, 10); + dlog_rho_init(rho, a, p, p-1); dlog_precomp_n_init(pre1, a, p, p-1, 1); dlog_precomp_n_init(pre100, a, p, p-1, 100); for (k = 1; k < 100 && k < p; k++) { - ulong l0, l1, l2, l3, l4, l5; + ulong l0, l1, l2, l3, l4, l5, l6; l1 = dlog_table(table, k); l2 = dlog_bsgs(bsgs, k); @@ -50,22 +52,29 @@ TEST_FUNCTION_START(dlog, state) l4 = dlog_precomp(pre1, k); l5 = dlog_precomp(pre100, k); + /* rho is slow, so don't test every time */ + if (n_randint(state, 10) == 0) + l6 = dlog_rho(rho, k); + else + l6 = l5; + if (iter < 50 && k <= 7) l0 = dlog_once(k, a, modp, p-1); else l0 = l1; - if (l0 != l1 || l1 != l2 || l1 != l3 || l1 != l4 || l1 != l5) + if (l0 != l1 || l1 != l2 || l1 != l3 || l1 != l4 || l1 != l5 || l1 != l6) { flint_printf("\n\nFAIL: log(%wu,%wu) mod %wu\n\n",k,a,p); - flint_printf("once: %wu\ntable: %wu\nbsgs: %wu\ncrt: %wu\nprecomp1: %wu\nprecomp100: %wu\n\n", - l0, l1, l2, l3, l4, l5); + flint_printf("once: %wu\ntable: %wu\nbsgs: %wu\ncrt: %wu\nprecomp1: %wu\nprecomp100: %wu\nrho: %wu\n", + l0, l1, l2, l3, l4, l5, l6); flint_abort(); } } dlog_table_clear(table); dlog_bsgs_clear(bsgs); dlog_crt_clear(crt); + dlog_rho_clear(rho); dlog_precomp_clear(pre1); dlog_precomp_clear(pre100); } diff --git a/src/dlog/test/t-modpe.c b/src/dlog/test/t-modpe.c index 7b26ef9836..ad272bf057 100644 --- a/src/dlog/test/t-modpe.c +++ b/src/dlog/test/t-modpe.c @@ -23,7 +23,7 @@ TEST_FUNCTION_START(dlog_modpe, state) { slong iter; - for (iter = 0; iter < 1000; iter++) + for (iter = 0; iter < 100 * flint_test_multiplier(); iter++) { ulong p, e, pe, a; diff --git a/src/dlog/test/t-vec.c b/src/dlog/test/t-vec.c index 462725c7bd..3a70437170 100644 --- a/src/dlog/test/t-vec.c +++ b/src/dlog/test/t-vec.c @@ -61,7 +61,7 @@ TEST_FUNCTION_START(dlog_vec, state) ref = flint_malloc(nv * sizeof(ulong)); v = flint_malloc(nv * sizeof(ulong)); - for (iter = 0; iter < 10; iter++) + for (iter = 0; iter < FLINT_MAX(2, flint_test_multiplier()); iter++) { int k;