2016-09-06 15:43:12 +02:00
|
|
|
|
/*
|
2016-03-08 16:40:32 +01:00
|
|
|
|
Copyright (C) 2016 Pascal Molin
|
|
|
|
|
|
2016-09-06 15:43:12 +02:00
|
|
|
|
This file is part of Arb.
|
|
|
|
|
|
|
|
|
|
Arb is free software: you can redistribute it and/or modify it under
|
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
|
by the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
|
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2016-03-08 16:40:32 +01:00
|
|
|
|
|
2016-09-05 12:37:43 +02:00
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <string.h>
|
2016-03-11 10:35:42 +01:00
|
|
|
|
#include "dlog.h"
|
2016-03-08 16:40:32 +01:00
|
|
|
|
#include "profiler.h"
|
|
|
|
|
|
2016-03-15 15:39:26 +01:00
|
|
|
|
#define NUMPRIMES 400
|
2016-03-17 17:27:28 +01:00
|
|
|
|
#define LOG 0
|
|
|
|
|
#define CSV 1
|
|
|
|
|
#define JSON 2
|
2016-03-15 15:39:26 +01:00
|
|
|
|
|
|
|
|
|
typedef void (*log_f) (ulong p, ulong a, ulong num);
|
2016-03-08 16:40:32 +01:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
flog_table(ulong p, ulong a, ulong num)
|
|
|
|
|
{
|
|
|
|
|
int k;
|
|
|
|
|
dlog_table_t t;
|
|
|
|
|
dlog_table_init(t, a, p);
|
|
|
|
|
for (k = 1; k < num; k++)
|
|
|
|
|
{
|
2016-03-15 15:39:26 +01:00
|
|
|
|
if (k % p == 0) continue;
|
2016-03-08 16:40:32 +01:00
|
|
|
|
dlog_table(t, k % p);
|
|
|
|
|
}
|
|
|
|
|
dlog_table_clear(t);
|
|
|
|
|
}
|
|
|
|
|
void
|
|
|
|
|
flog_bsgs(ulong p, ulong a, ulong num)
|
|
|
|
|
{
|
|
|
|
|
int k;
|
|
|
|
|
dlog_bsgs_t t;
|
2016-03-29 12:52:26 +01:00
|
|
|
|
dlog_bsgs_init(t, a, p, p-1, dlog_bsgs_size(p, num));
|
2016-03-08 16:40:32 +01:00
|
|
|
|
for (k = 1; k < num; k++)
|
|
|
|
|
{
|
2016-03-15 15:39:26 +01:00
|
|
|
|
if (k % p == 0) continue;
|
2016-03-08 16:40:32 +01:00
|
|
|
|
dlog_bsgs(t, k % p);
|
|
|
|
|
}
|
|
|
|
|
dlog_bsgs_clear(t);
|
|
|
|
|
}
|
|
|
|
|
void
|
|
|
|
|
flog_rho(ulong p, ulong a, ulong num)
|
|
|
|
|
{
|
|
|
|
|
int k;
|
|
|
|
|
dlog_rho_t t;
|
|
|
|
|
dlog_rho_init(t, a, p, p-1);
|
|
|
|
|
for (k = 1; k < num; k++)
|
|
|
|
|
{
|
2016-03-15 15:39:26 +01:00
|
|
|
|
if (k % p == 0) continue;
|
2016-03-08 16:40:32 +01:00
|
|
|
|
dlog_rho(t, k % p);
|
|
|
|
|
}
|
|
|
|
|
dlog_rho_clear(t);
|
|
|
|
|
}
|
|
|
|
|
void
|
|
|
|
|
flog_crt(ulong p, ulong a, ulong num)
|
|
|
|
|
{
|
|
|
|
|
int k;
|
|
|
|
|
dlog_crt_t t;
|
|
|
|
|
dlog_crt_init(t, a, p, p-1, num);
|
|
|
|
|
for (k = 1; k < num; k++)
|
|
|
|
|
{
|
2016-03-15 15:39:26 +01:00
|
|
|
|
if (k % p == 0) continue;
|
2016-03-08 16:40:32 +01:00
|
|
|
|
dlog_crt(t, k % p);
|
|
|
|
|
}
|
|
|
|
|
dlog_crt_clear(t);
|
|
|
|
|
}
|
|
|
|
|
void
|
|
|
|
|
flog_gen(ulong p, ulong a, ulong num)
|
|
|
|
|
{
|
|
|
|
|
int k;
|
|
|
|
|
dlog_precomp_t t;
|
|
|
|
|
dlog_precomp_n_init(t, a, p, p-1, num);
|
|
|
|
|
for (k = 1; k < num; k++)
|
|
|
|
|
{
|
2016-03-15 15:39:26 +01:00
|
|
|
|
if (k % p == 0) continue;
|
2016-03-08 16:40:32 +01:00
|
|
|
|
dlog_precomp(t, k % p);
|
|
|
|
|
}
|
|
|
|
|
dlog_precomp_clear(t);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-05 12:37:43 +02:00
|
|
|
|
int main(int argc, char *argv[])
|
2016-03-08 16:40:32 +01:00
|
|
|
|
{
|
2016-09-05 12:37:43 +02:00
|
|
|
|
int out = LOG;
|
2016-03-08 16:40:32 +01:00
|
|
|
|
slong iter, k, nv, nref, r, nr;
|
|
|
|
|
ulong minq, maxq;
|
|
|
|
|
ulong * rand;
|
2016-03-15 15:39:26 +01:00
|
|
|
|
int nbits, nl = 5;
|
|
|
|
|
int l[5] = { 1, 10, 100, 1000 , 5000};
|
|
|
|
|
|
|
|
|
|
int nf = 4;
|
|
|
|
|
log_f func[4] = { flog_table, flog_bsgs, flog_crt, flog_gen };
|
|
|
|
|
char * n[4] = { "table", "bsgs", "crt", "generic" };
|
|
|
|
|
|
|
|
|
|
int np = NUMPRIMES;
|
|
|
|
|
|
2016-03-08 16:40:32 +01:00
|
|
|
|
flint_rand_t state;
|
|
|
|
|
|
2016-09-05 12:37:43 +02:00
|
|
|
|
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]);
|
2017-02-28 16:50:03 +01:00
|
|
|
|
flint_abort();
|
2016-09-05 12:37:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 16:40:32 +01:00
|
|
|
|
flint_randinit(state);
|
2016-03-23 22:10:58 +01:00
|
|
|
|
for (nbits = 10; nbits <= 40; nbits += 5)
|
2016-03-08 16:40:32 +01:00
|
|
|
|
{
|
|
|
|
|
|
2016-03-15 15:39:26 +01:00
|
|
|
|
int i;
|
|
|
|
|
ulong p[NUMPRIMES], a[NUMPRIMES];
|
|
|
|
|
|
|
|
|
|
if (nbits >= 25)
|
|
|
|
|
np /= 2;
|
|
|
|
|
|
2016-03-08 16:40:32 +01:00
|
|
|
|
for (i=0; i < np; i++)
|
|
|
|
|
{
|
|
|
|
|
p[i] = n_randprime(state, nbits, 0);
|
|
|
|
|
a[i] = n_primitive_root_prime(p[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nl; i++)
|
2016-03-29 12:52:26 +01:00
|
|
|
|
{
|
2016-03-15 15:39:26 +01:00
|
|
|
|
int f;
|
2016-09-05 12:37:43 +02:00
|
|
|
|
|
|
|
|
|
if (out == LOG)
|
|
|
|
|
flint_printf("%d * logs mod primes of size %d.....\n", l[i], nbits);
|
2016-03-08 16:40:32 +01:00
|
|
|
|
|
2016-03-15 15:39:26 +01:00
|
|
|
|
for (f = 0; f < nf; f++)
|
2016-03-08 16:40:32 +01:00
|
|
|
|
{
|
2016-03-15 15:39:26 +01:00
|
|
|
|
int j;
|
|
|
|
|
|
|
|
|
|
/* skip useless */
|
|
|
|
|
if (f == 0 && nbits >= 20)
|
|
|
|
|
continue;
|
|
|
|
|
if (f == 1 && nbits >= 30 && l[i] > 10)
|
|
|
|
|
continue;
|
2016-09-05 12:37:43 +02:00
|
|
|
|
if (out == LOG)
|
|
|
|
|
{
|
|
|
|
|
flint_printf("%-20s... ",n[f]);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
else if (out == CSV)
|
|
|
|
|
flint_printf("%-8s, %2d, %4d, %3d, ",n[f],nbits,l[i],np);
|
|
|
|
|
else if (out == JSON)
|
|
|
|
|
flint_printf("{ \"name\": \"%s\", \"bits\": %d, \"nlogs\": %d, \"nprimes\": %d, \"time\": ",
|
|
|
|
|
n[f],nbits,l[i],np);
|
2016-03-17 17:27:28 +01:00
|
|
|
|
|
2016-03-15 15:39:26 +01:00
|
|
|
|
TIMEIT_ONCE_START
|
|
|
|
|
for (j = 0; j < np; j ++)
|
|
|
|
|
(func[f])(p[j], a[j], l[i]);
|
|
|
|
|
TIMEIT_ONCE_STOP
|
2016-03-17 17:27:28 +01:00
|
|
|
|
|
2016-09-05 12:37:43 +02:00
|
|
|
|
if (out == JSON)
|
|
|
|
|
flint_printf("}\n");
|
|
|
|
|
else
|
|
|
|
|
flint_printf("\n");
|
2016-03-08 16:40:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
flint_randclear(state);
|
|
|
|
|
flint_cleanup();
|
|
|
|
|
flint_printf("PASS\n");
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}
|