Skip to content

Commit

Permalink
Merge pull request #2011 from fredrik-johansson/dlog
Browse files Browse the repository at this point in the history
Test dlog_rho
  • Loading branch information
fredrik-johansson committed Jun 1, 2024
2 parents 78cc8f9 + 1b4f926 commit f8d1a5f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/dlog/rho.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down Expand Up @@ -116,3 +120,4 @@ dlog_rho(const dlog_rho_t t, ulong b)
else
return nmod_div(e[0], f[0], t->n);
}

19 changes: 14 additions & 5 deletions src/dlog/test/t-dlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,35 +38,43 @@ 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);
l3 = dlog_crt(crt, k);
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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/dlog/test/t-modpe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/dlog/test/t-vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f8d1a5f

Please sign in to comment.