mirror of
https://github.com/vale981/arb
synced 2025-03-06 09:51:39 -05:00
split dlog precomp file
This commit is contained in:
parent
36e1682d64
commit
401f91eed1
22 changed files with 484 additions and 285 deletions
92
dlog.h
92
dlog.h
|
@ -26,6 +26,12 @@
|
|||
#ifndef DLOG_H
|
||||
#define DLOG_H
|
||||
|
||||
#ifdef ACB_INLINES_C
|
||||
#define ACB_INLINE
|
||||
#else
|
||||
#define ACB_INLINE static __inline__
|
||||
#endif
|
||||
|
||||
#include "ulong_extras.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "padic.h"
|
||||
|
@ -36,6 +42,7 @@ enum
|
|||
};
|
||||
|
||||
typedef struct dlog_precomp_struct dlog_precomp_struct;
|
||||
typedef struct dlog_precomp_struct * dlog_precomp_ptr;
|
||||
|
||||
/* log in (1+pZ/p^eZ): compute via p-adic log */
|
||||
typedef struct
|
||||
|
@ -112,11 +119,7 @@ typedef struct
|
|||
ulong num;
|
||||
ulong * expo;
|
||||
ulong * crt_coeffs;
|
||||
dlog_precomp_struct ** pre;
|
||||
/*
|
||||
void * pre;
|
||||
dlog_precomp_t * pre;
|
||||
*/
|
||||
dlog_precomp_ptr pre;
|
||||
}
|
||||
dlog_crt_struct;
|
||||
|
||||
|
@ -130,10 +133,6 @@ typedef struct
|
|||
ulong e;
|
||||
ulong * apk;
|
||||
dlog_precomp_struct * pre;
|
||||
/*
|
||||
void * pre;
|
||||
dlog_precomp_t * pre;
|
||||
*/
|
||||
}
|
||||
dlog_power_struct;
|
||||
|
||||
|
@ -161,6 +160,15 @@ dlog_precomp_struct
|
|||
|
||||
typedef dlog_precomp_struct dlog_precomp_t[1];
|
||||
|
||||
void dlog_precomp_modpe_init(dlog_precomp_t pre, ulong a, ulong p, ulong e, ulong pe, ulong num);
|
||||
void dlog_precomp_small_init(dlog_precomp_t pre, ulong a, ulong mod, ulong n, ulong num);
|
||||
void dlog_precomp_n_init(dlog_precomp_t pre, ulong a, ulong mod, ulong n, ulong num);
|
||||
void dlog_precomp_p_init(dlog_precomp_t pre, ulong a, ulong mod, ulong p, ulong num);
|
||||
void dlog_precomp_pe_init(dlog_precomp_t pre, ulong a, ulong mod, ulong p, ulong e, ulong pe, ulong num);
|
||||
void dlog_precomp_clear(dlog_precomp_t pre);
|
||||
|
||||
ulong dlog_precomp(const dlog_precomp_t pre, ulong b);
|
||||
|
||||
ulong dlog_order23_init(dlog_order23_t t, ulong a);
|
||||
ulong dlog_table_init(dlog_table_t t, ulong a, ulong mod);
|
||||
ulong dlog_crt_init(dlog_crt_t t, ulong a, ulong mod, ulong n, ulong num);
|
||||
|
@ -171,14 +179,53 @@ void dlog_1modpe_init(dlog_1modpe_t t, ulong a1, ulong p, ulong e);
|
|||
void dlog_rho_init(dlog_rho_t t, ulong a, ulong mod, ulong n);
|
||||
/*#define dlog_bsgs_init(t, a, n, m) bsgs_table_init(t, a, n, m)*/
|
||||
|
||||
void dlog_order23_clear(dlog_order23_t t);
|
||||
void dlog_table_clear(dlog_table_t t);
|
||||
void dlog_1modpe_clear(dlog_1modpe_t t);
|
||||
ACB_INLINE void
|
||||
dlog_order23_clear(dlog_order23_t t)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ACB_INLINE void
|
||||
dlog_table_clear(dlog_table_t t)
|
||||
{
|
||||
flint_free(t->table);
|
||||
}
|
||||
|
||||
ACB_INLINE void
|
||||
dlog_1modpe_clear(dlog_1modpe_t t)
|
||||
{
|
||||
padic_clear(t->invlog);
|
||||
padic_ctx_clear(t->ctx);
|
||||
}
|
||||
|
||||
void dlog_crt_clear(dlog_crt_t t);
|
||||
void dlog_power_clear(dlog_power_t t);
|
||||
void dlog_modpe_clear(dlog_modpe_t t);
|
||||
void dlog_bsgs_clear(dlog_bsgs_t t);
|
||||
void dlog_rho_clear(dlog_rho_t t);
|
||||
|
||||
ACB_INLINE void
|
||||
dlog_power_clear(dlog_power_t t)
|
||||
{
|
||||
flint_free(t->apk);
|
||||
dlog_precomp_clear(t->pre);
|
||||
flint_free(t->pre);
|
||||
}
|
||||
|
||||
ACB_INLINE void
|
||||
dlog_modpe_clear(dlog_modpe_t t)
|
||||
{
|
||||
dlog_precomp_clear(t->modp);
|
||||
dlog_1modpe_clear(t->modpe);
|
||||
}
|
||||
|
||||
ACB_INLINE void
|
||||
dlog_bsgs_clear(dlog_bsgs_t t)
|
||||
{
|
||||
flint_free(t->table);
|
||||
}
|
||||
|
||||
ACB_INLINE void
|
||||
dlog_rho_clear(dlog_rho_t t)
|
||||
{
|
||||
return;
|
||||
}
|
||||
/*#define dlog_bsgs_clear(t) bsgs_table_clear(t)*/
|
||||
|
||||
ulong dlog_order23(const dlog_order23_t t, ulong b);
|
||||
|
@ -191,12 +238,13 @@ ulong dlog_bsgs(const dlog_bsgs_t t, ulong b);
|
|||
ulong dlog_rho(const dlog_rho_t t, ulong b);
|
||||
/*#define dlog_bsgs(t, b) n_discrete_log_bsgs_table(t, b)*/
|
||||
|
||||
void dlog_precomp_modpe_init(dlog_precomp_t pre, ulong a, ulong p, ulong e, ulong pe, ulong num);
|
||||
void dlog_precomp_n_init(dlog_precomp_t pre, ulong a, ulong mod, ulong n, ulong num);
|
||||
void dlog_precomp_p_init(dlog_precomp_t pre, ulong a, ulong mod, ulong p, ulong num);
|
||||
void dlog_precomp_pe_init(dlog_precomp_t pre, ulong a, ulong mod, ulong p, ulong e, ulong pe, ulong num);
|
||||
void dlog_precomp_clear(dlog_precomp_t pre);
|
||||
ulong dlog_precomp(const dlog_precomp_t pre, ulong b);
|
||||
#define DLOG_SMALL_LIM 50
|
||||
#define DLOG_TABLE_LIM 50
|
||||
#define DLOG_TABLE_P_LIM 50
|
||||
#define DLOG_TABLE_MODPE_LIM 50
|
||||
#define DLOG_TABLE_PE_LIM 50
|
||||
#define DLOG_TABLE_N_LIM 50
|
||||
#define DLOG_BSGS_LIM 500
|
||||
|
||||
#define LOOP_MAX_FACTOR 6
|
||||
#define G_SMALL 0
|
||||
|
|
|
@ -41,10 +41,3 @@ dlog_1modpe_init(dlog_1modpe_t t, ulong a1, ulong p, ulong e)
|
|||
|
||||
fmpz_clear(tmp);
|
||||
}
|
||||
|
||||
void
|
||||
dlog_1modpe_clear(dlog_1modpe_t t)
|
||||
{
|
||||
padic_clear(t->invlog);
|
||||
padic_ctx_clear(t->ctx);
|
||||
}
|
||||
|
|
|
@ -56,9 +56,3 @@ dlog_bsgs_init(dlog_bsgs_t t, ulong a, ulong mod, ulong n, ulong m)
|
|||
qsort(t->table, m, sizeof(apow_t), (int(*)(const void*,const void*))apow_cmp);
|
||||
return t->g;
|
||||
}
|
||||
|
||||
void
|
||||
dlog_bsgs_clear(dlog_bsgs_t t)
|
||||
{
|
||||
flint_free(t->table);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ dlog_crt(const dlog_crt_t t, ulong b)
|
|||
{
|
||||
ulong bk, rk;
|
||||
bk = nmod_pow_ui(b, t->expo[k], t->mod);
|
||||
rk = dlog_precomp(t->pre[k], bk);
|
||||
rk = dlog_precomp(t->pre + k, bk);
|
||||
#if 0
|
||||
flint_printf("##[crt-%d]: log(%wu)=log(%wu^%wu) = %wu [size %wu mod %wu]\n",
|
||||
k, bk, b, t->expo[k], rk, t->n/t->expo[k], t->mod);
|
||||
|
|
37
dlog/crt_clear.c
Normal file
37
dlog/crt_clear.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2016 Pascal Molin
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "dlog.h"
|
||||
|
||||
void
|
||||
dlog_crt_clear(dlog_crt_t t)
|
||||
{
|
||||
int k;
|
||||
flint_free(t->expo);
|
||||
flint_free(t->crt_coeffs);
|
||||
for (k = 0; k < t->num; k++)
|
||||
dlog_precomp_clear(t->pre + k);
|
||||
flint_free(t->pre);
|
||||
}
|
|
@ -42,9 +42,7 @@ dlog_crt_init(dlog_crt_t t, ulong a, ulong mod, ulong n, ulong num)
|
|||
|
||||
M = t->expo = flint_malloc(t->num * sizeof(ulong));
|
||||
u = t->crt_coeffs = flint_malloc(t->num * sizeof(ulong));
|
||||
t->pre = flint_malloc(t->num * sizeof(dlog_precomp_t));
|
||||
for (k = 0; k < t->num; k++)
|
||||
t->pre[k] = flint_malloc(sizeof(dlog_precomp_struct));
|
||||
t->pre = flint_malloc(t->num * sizeof(dlog_precomp_struct));
|
||||
|
||||
for (k = 0; k < t->num; k++)
|
||||
{
|
||||
|
@ -58,8 +56,8 @@ dlog_crt_init(dlog_crt_t t, ulong a, ulong mod, ulong n, ulong num)
|
|||
#if 0
|
||||
flint_printf("[sub-crt -- init for size %wu mod %wu]\n", mk, mod);
|
||||
#endif
|
||||
dlog_precomp_pe_init(t->pre[k], nmod_pow_ui(a, M[k], t->mod), mod, p, e, mk, num);
|
||||
cost += t->pre[k]->cost;
|
||||
dlog_precomp_pe_init(t->pre + k, nmod_pow_ui(a, M[k], t->mod), mod, p, e, mk, num);
|
||||
cost += t->pre[k].cost;
|
||||
}
|
||||
#if 0
|
||||
if (cost > 500)
|
||||
|
@ -67,17 +65,3 @@ dlog_crt_init(dlog_crt_t t, ulong a, ulong mod, ulong n, ulong num)
|
|||
#endif
|
||||
return cost;
|
||||
}
|
||||
|
||||
void
|
||||
dlog_crt_clear(dlog_crt_t t)
|
||||
{
|
||||
int k;
|
||||
flint_free(t->expo);
|
||||
flint_free(t->crt_coeffs);
|
||||
for (k = 0; k < t->num; k++)
|
||||
{
|
||||
dlog_precomp_clear(t->pre[k]);
|
||||
flint_free(t->pre[k]);
|
||||
}
|
||||
flint_free(t->pre);
|
||||
}
|
||||
|
|
18
dlog/modpe.c
18
dlog/modpe.c
|
@ -26,24 +26,6 @@
|
|||
#include "dlog.h"
|
||||
#include "padic.h"
|
||||
|
||||
ulong
|
||||
dlog_modpe_init(dlog_modpe_t t, ulong a, ulong p, ulong e, ulong pe, ulong num)
|
||||
{
|
||||
t->p = p;
|
||||
t->e = e;
|
||||
t->pe = pe;
|
||||
dlog_precomp_n_init(t->modp, a, p, p-1, num);
|
||||
dlog_1modpe_init(t->modpe, n_powmod(a, p - 1, pe), p, e);
|
||||
return t->modp->cost + e;
|
||||
}
|
||||
|
||||
void
|
||||
dlog_modpe_clear(dlog_modpe_t t)
|
||||
{
|
||||
dlog_precomp_clear(t->modp);
|
||||
dlog_1modpe_clear(t->modpe);
|
||||
}
|
||||
|
||||
ulong
|
||||
dlog_modpe(const dlog_modpe_t t, ulong b)
|
||||
{
|
||||
|
|
37
dlog/modpe_init.c
Normal file
37
dlog/modpe_init.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2016 Pascal Molin
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "dlog.h"
|
||||
|
||||
ulong
|
||||
dlog_modpe_init(dlog_modpe_t t, ulong a, ulong p, ulong e, ulong pe, ulong num)
|
||||
{
|
||||
t->p = p;
|
||||
t->e = e;
|
||||
t->pe = pe;
|
||||
dlog_precomp_n_init(t->modp, a, p, p-1, num);
|
||||
dlog_1modpe_init(t->modpe, n_powmod(a, p - 1, pe), p, e);
|
||||
return t->modp->cost + e;
|
||||
}
|
|
@ -31,9 +31,3 @@ dlog_order23_init(dlog_order23_t t, ulong a)
|
|||
* t = a;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
dlog_order23_clear(dlog_order23_t t)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -43,11 +43,3 @@ dlog_power_init(dlog_power_t t, ulong a, ulong mod, ulong p, ulong e, ulong num)
|
|||
dlog_precomp_p_init(t->pre, nmod_inv(t->apk[e-1], t->mod), mod, p, e * num);
|
||||
return e * t->pre->cost;
|
||||
}
|
||||
|
||||
void
|
||||
dlog_power_clear(dlog_power_t t)
|
||||
{
|
||||
flint_free(t->apk);
|
||||
dlog_precomp_clear(t->pre);
|
||||
flint_free(t->pre);
|
||||
}
|
||||
|
|
55
dlog/precomp_clear.c
Normal file
55
dlog/precomp_clear.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2016 Pascal Molin
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "dlog.h"
|
||||
|
||||
void
|
||||
dlog_precomp_clear(dlog_precomp_t pre)
|
||||
{
|
||||
switch (pre->type)
|
||||
{
|
||||
case DLOG_MODPE:
|
||||
dlog_modpe_clear(pre->t.modpe);
|
||||
break;
|
||||
case DLOG_CRT:
|
||||
dlog_crt_clear(pre->t.crt);
|
||||
break;
|
||||
case DLOG_POWER:
|
||||
dlog_power_clear(pre->t.power);
|
||||
break;
|
||||
case DLOG_TABLE:
|
||||
dlog_table_clear(pre->t.table);
|
||||
break;
|
||||
case DLOG_BSGS:
|
||||
dlog_bsgs_clear(pre->t.bsgs);
|
||||
break;
|
||||
case DLOG_23:
|
||||
dlog_order23_clear(pre->t.order23);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2016 Pascal Molin
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "math.h"
|
||||
#include "dlog.h"
|
||||
|
||||
#define SMALL_LIM 50
|
||||
#define TABLE_LIM 50
|
||||
#define TABLE_P_LIM 50
|
||||
#define TABLE_MODPE_LIM 50
|
||||
#define TABLE_PE_LIM 50
|
||||
#define TABLE_N_LIM 50
|
||||
#define BSGS_LIM 500
|
||||
|
||||
void
|
||||
dlog_precomp_small_init(dlog_precomp_t pre, ulong a, ulong mod, ulong n, ulong num)
|
||||
{
|
||||
if (n <= 3)
|
||||
{
|
||||
pre->type = DLOG_23;
|
||||
pre->cost = dlog_order23_init(pre->t.order23, a);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( mod < TABLE_LIM )
|
||||
{
|
||||
pre->type = DLOG_TABLE;
|
||||
pre->cost = dlog_table_init(pre->t.table, a, mod);
|
||||
}
|
||||
else
|
||||
{
|
||||
pre->type = DLOG_BSGS;
|
||||
pre->cost = dlog_bsgs_init(pre->t.bsgs, a, mod, n, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* log mod p^e */
|
||||
void
|
||||
dlog_precomp_modpe_init(dlog_precomp_t pre, ulong a, ulong p, ulong e, ulong pe, ulong num)
|
||||
{
|
||||
if ( pe < TABLE_MODPE_LIM )
|
||||
{
|
||||
dlog_precomp_small_init(pre, a, pe, pe - pe / p, num);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (e > 1)
|
||||
{
|
||||
pre->type = DLOG_MODPE;
|
||||
pre->cost = dlog_modpe_init(pre->t.modpe, a, p, e, pe, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
dlog_precomp_n_init(pre, a, p, p - 1, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* group of order n modulo mod, mod a prime and no information on n */
|
||||
void
|
||||
dlog_precomp_n_init(dlog_precomp_t pre, ulong a, ulong mod, ulong n, ulong num)
|
||||
{
|
||||
if (n%2 && n_is_probabprime(n))
|
||||
dlog_precomp_p_init(pre, a, mod, n, num);
|
||||
else {
|
||||
if (n < TABLE_N_LIM)
|
||||
{
|
||||
dlog_precomp_small_init(pre, a, mod, n, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (n < BSGS_LIM)
|
||||
{
|
||||
ulong m;
|
||||
m = (2 * num < n) ? ceil(sqrt((double) n * num)) : n;
|
||||
pre->type = DLOG_BSGS;
|
||||
pre->cost = dlog_bsgs_init(pre->t.bsgs, a, mod, n, m);
|
||||
} else {
|
||||
pre->type = DLOG_CRT;
|
||||
pre->cost = dlog_crt_init(pre->t.crt, a, mod, n, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* we known the order is prime */
|
||||
void
|
||||
dlog_precomp_p_init(dlog_precomp_t pre, ulong a, ulong mod, ulong p, ulong num)
|
||||
{
|
||||
if ( p < TABLE_P_LIM )
|
||||
{
|
||||
dlog_precomp_small_init(pre, a, mod, p, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
ulong m;
|
||||
m = (2 * num < p) ? ceil(sqrt((double) p * num)) : p;
|
||||
pre->type = DLOG_BSGS;
|
||||
pre->cost = dlog_bsgs_init(pre->t.bsgs, a, mod, p, m);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
dlog_precomp_pe_init(dlog_precomp_t pre, ulong a, ulong mod, ulong p, ulong e, ulong pe, ulong num)
|
||||
{
|
||||
if ( pe < TABLE_PE_LIM )
|
||||
{
|
||||
dlog_precomp_small_init(pre, a, mod, pe, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( e == 1)
|
||||
{
|
||||
dlog_precomp_p_init(pre, a, mod, p, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
pre->type = DLOG_POWER;
|
||||
pre->cost = dlog_power_init(pre->t.power, a, mod, p, e, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
dlog_precomp_clear(dlog_precomp_t pre)
|
||||
{
|
||||
switch (pre->type)
|
||||
{
|
||||
case DLOG_MODPE:
|
||||
dlog_modpe_clear(pre->t.modpe);
|
||||
break;
|
||||
case DLOG_CRT:
|
||||
dlog_crt_clear(pre->t.crt);
|
||||
break;
|
||||
case DLOG_POWER:
|
||||
dlog_power_clear(pre->t.power);
|
||||
break;
|
||||
case DLOG_TABLE:
|
||||
dlog_table_clear(pre->t.table);
|
||||
break;
|
||||
case DLOG_BSGS:
|
||||
dlog_bsgs_clear(pre->t.bsgs);
|
||||
break;
|
||||
case DLOG_23:
|
||||
dlog_order23_clear(pre->t.order23);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
}
|
48
dlog/precomp_modpe_init.c
Normal file
48
dlog/precomp_modpe_init.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2016 Pascal Molin
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "dlog.h"
|
||||
|
||||
/* log mod p^e */
|
||||
void
|
||||
dlog_precomp_modpe_init(dlog_precomp_t pre, ulong a, ulong p, ulong e, ulong pe, ulong num)
|
||||
{
|
||||
if ( pe < DLOG_TABLE_MODPE_LIM )
|
||||
{
|
||||
dlog_precomp_small_init(pre, a, pe, pe - pe / p, num);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (e > 1)
|
||||
{
|
||||
pre->type = DLOG_MODPE;
|
||||
pre->cost = dlog_modpe_init(pre->t.modpe, a, p, e, pe, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
dlog_precomp_n_init(pre, a, p, p - 1, num);
|
||||
}
|
||||
}
|
||||
}
|
54
dlog/precomp_n_init.c
Normal file
54
dlog/precomp_n_init.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2016 Pascal Molin
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "dlog.h"
|
||||
#include "math.h"
|
||||
|
||||
/* group of order n modulo mod, mod a prime and no information on n */
|
||||
void
|
||||
dlog_precomp_n_init(dlog_precomp_t pre, ulong a, ulong mod, ulong n, ulong num)
|
||||
{
|
||||
if (n%2 && n_is_probabprime(n))
|
||||
dlog_precomp_p_init(pre, a, mod, n, num);
|
||||
else {
|
||||
if (n < DLOG_TABLE_N_LIM)
|
||||
{
|
||||
dlog_precomp_small_init(pre, a, mod, n, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (n < DLOG_BSGS_LIM)
|
||||
{
|
||||
ulong m;
|
||||
m = (2 * num < n) ? ceil(sqrt((double) n * num)) : n;
|
||||
pre->type = DLOG_BSGS;
|
||||
pre->cost = dlog_bsgs_init(pre->t.bsgs, a, mod, n, m);
|
||||
} else {
|
||||
pre->type = DLOG_CRT;
|
||||
pre->cost = dlog_crt_init(pre->t.crt, a, mod, n, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
44
dlog/precomp_p_init.c
Normal file
44
dlog/precomp_p_init.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2016 Pascal Molin
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "dlog.h"
|
||||
#include "math.h"
|
||||
|
||||
/* we known the order is prime */
|
||||
void
|
||||
dlog_precomp_p_init(dlog_precomp_t pre, ulong a, ulong mod, ulong p, ulong num)
|
||||
{
|
||||
if ( p < DLOG_TABLE_P_LIM )
|
||||
{
|
||||
dlog_precomp_small_init(pre, a, mod, p, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
ulong m;
|
||||
m = (2 * num < p) ? ceil(sqrt((double) p * num)) : p;
|
||||
pre->type = DLOG_BSGS;
|
||||
pre->cost = dlog_bsgs_init(pre->t.bsgs, a, mod, p, m);
|
||||
}
|
||||
}
|
47
dlog/precomp_pe_init.c
Normal file
47
dlog/precomp_pe_init.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2016 Pascal Molin
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "dlog.h"
|
||||
|
||||
void
|
||||
dlog_precomp_pe_init(dlog_precomp_t pre, ulong a, ulong mod, ulong p, ulong e, ulong pe, ulong num)
|
||||
{
|
||||
if ( pe < DLOG_TABLE_PE_LIM )
|
||||
{
|
||||
dlog_precomp_small_init(pre, a, mod, pe, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( e == 1)
|
||||
{
|
||||
dlog_precomp_p_init(pre, a, mod, p, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
pre->type = DLOG_POWER;
|
||||
pre->cost = dlog_power_init(pre->t.power, a, mod, p, e, num);
|
||||
}
|
||||
}
|
||||
}
|
49
dlog/precomp_small_init.c
Normal file
49
dlog/precomp_small_init.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2016 Pascal Molin
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "dlog.h"
|
||||
|
||||
void
|
||||
dlog_precomp_small_init(dlog_precomp_t pre, ulong a, ulong mod, ulong n, ulong num)
|
||||
{
|
||||
if (n <= 3)
|
||||
{
|
||||
pre->type = DLOG_23;
|
||||
pre->cost = dlog_order23_init(pre->t.order23, a);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( mod < DLOG_TABLE_LIM )
|
||||
{
|
||||
pre->type = DLOG_TABLE;
|
||||
pre->cost = dlog_table_init(pre->t.table, a, mod);
|
||||
}
|
||||
else
|
||||
{
|
||||
pre->type = DLOG_BSGS;
|
||||
pre->cost = dlog_bsgs_init(pre->t.bsgs, a, mod, n, n);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -118,7 +118,7 @@ int main()
|
|||
flint_rand_t state;
|
||||
|
||||
flint_randinit(state);
|
||||
for (nbits = 10; nbits < 50; nbits += 5)
|
||||
for (nbits = 10; nbits <= 40; nbits += 5)
|
||||
{
|
||||
|
||||
int i;
|
||||
|
|
15
dlog/rho.c
15
dlog/rho.c
|
@ -26,21 +26,6 @@
|
|||
#include "dlog.h"
|
||||
#include <math.h>
|
||||
|
||||
void
|
||||
dlog_rho_init(dlog_rho_t t, ulong a, ulong mod, ulong n)
|
||||
{
|
||||
t->a = a;
|
||||
nmod_init(&t->n, n);
|
||||
nmod_init(&t->mod, mod);
|
||||
t->nisprime = n_is_prime(n);
|
||||
}
|
||||
|
||||
void
|
||||
dlog_rho_clear(dlog_rho_t t)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static ulong
|
||||
dlog_once(ulong b, ulong a, const nmod_t mod, ulong n)
|
||||
{
|
||||
|
|
36
dlog/rho_init.c
Normal file
36
dlog/rho_init.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2016 Pascal Molin
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "dlog.h"
|
||||
#include <math.h>
|
||||
|
||||
void
|
||||
dlog_rho_init(dlog_rho_t t, ulong a, ulong mod, ulong n)
|
||||
{
|
||||
t->a = a;
|
||||
nmod_init(&t->n, n);
|
||||
nmod_init(&t->mod, mod);
|
||||
t->nisprime = n_is_prime(n);
|
||||
}
|
|
@ -43,9 +43,3 @@ dlog_table_init(dlog_table_t t, ulong a, ulong mod)
|
|||
while (ak != 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
dlog_table_clear(dlog_table_t t)
|
||||
{
|
||||
flint_free(t->table);
|
||||
}
|
||||
|
|
|
@ -26,8 +26,9 @@
|
|||
#include "dlog.h"
|
||||
#include <math.h>
|
||||
|
||||
#define vbs 1
|
||||
#define vbs 0
|
||||
|
||||
/* TODO: tune the limit dlog -> index calculus */
|
||||
void
|
||||
dlog_vec_sieve(ulong *v, ulong nv, ulong a, ulong va, nmod_t mod, ulong na, nmod_t order)
|
||||
{
|
||||
|
@ -47,7 +48,6 @@ dlog_vec_sieve(ulong *v, ulong nv, ulong a, ulong va, nmod_t mod, ulong na, nmod
|
|||
pmax = (nv < mod.n) ? nv : mod.n;
|
||||
p1 = 50; /* FIXME: tune this limit! */
|
||||
dlog_precomp_n_init(pre, a, mod.n, na, p1);
|
||||
/*flint_printf("## single log cost: %wu\n", pre->cost);*/
|
||||
logcost = pre->cost;
|
||||
|
||||
if (logcost < 15)
|
||||
|
|
Loading…
Add table
Reference in a new issue