export log mod 2^e and fix conrey_log

This commit is contained in:
Pascal 2016-09-09 11:13:20 +02:00
parent b09fbfc7fa
commit 1a0bd47470
7 changed files with 38 additions and 31 deletions

View file

@ -11,6 +11,7 @@
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
#include "dlog.h"
#include "acb_dirichlet.h"
/* TODO: use dlog module instead of n_discrete_log_bsgs */
@ -27,7 +28,8 @@ acb_dirichlet_conrey_log(acb_dirichlet_conrey_t x, const acb_dirichlet_group_t G
{
ulong m2 = (x->log[0]) ? -m % G->q_even : m % G->q_even;
if (G->P[1].dlog == NULL)
x->log[1] = n_discrete_log_bsgs(m2, 5, G->q_even);
x->log[1] = dlog_mod2e_1mod4(m2, G->P[1].e,
nmod_inv(5, G->P[1].pe), G->P[1].pe);
else
x->log[1] = dlog_precomp(G->P[1].dlog, m2);
}

View file

@ -123,11 +123,11 @@ int main()
if (!acb_dirichlet_conrey_eq(G, x, y))
{
flint_printf("FAIL: conrey log and exp\n\n");
flint_printf("FAIL: conrey exp and log\n\n");
flint_printf("q = %wu\n\n", q);
flint_printf("conrey = ");
acb_dirichlet_conrey_print(G, x);
flint_printf("m = %wu\n\n", m);
flint_printf("\n\nm = %wu\n\n", m);
flint_printf("log = ");
acb_dirichlet_conrey_print(G, y);
flint_printf("\n\nnumber = %wu\n\n", y->n);

5
dlog.h
View file

@ -235,11 +235,12 @@ ulong dlog_table(const dlog_table_t t, ulong b);
ulong dlog_crt(const dlog_crt_t t, ulong b);
ulong dlog_power(const dlog_power_t t, ulong b);
ulong dlog_modpe(const dlog_modpe_t t, ulong b);
ulong dlog_mod2e(const dlog_modpe_t t, ulong b);
ulong dlog_bsgs(const dlog_bsgs_t t, ulong b);
ulong dlog_rho(const dlog_rho_t t, ulong b);
ulong dlog_1modpe_mod1p(ulong b1, ulong p, ulong e, ulong inv1p, nmod_t pe);
ulong dlog_1modpe_1modp(ulong b1, ulong p, ulong e, ulong inv1p, nmod_t pe);
ulong dlog_1modpe(const dlog_1modpe_t t, ulong b1, ulong p, ulong e, nmod_t pe);
ulong dlog_mod2e_1mod4(ulong b1, ulong e, ulong inva, nmod_t pe);
ulong dlog_mod2e(const dlog_modpe_t t, ulong b);
/*#define dlog_bsgs(t, b) n_discrete_log_bsgs_table(t, b)*/
#define DLOG_SMALL_LIM 50

View file

@ -19,7 +19,7 @@ dlog_1modpe(const dlog_1modpe_t t, ulong b1, ulong p, ulong e, nmod_t pe)
else
{
ulong logb1;
logb1 = dlog_1modpe_mod1p(b1, p, e, t->inv1p, pe);
logb1 = dlog_1modpe_1modp(b1, p, e, t->inv1p, pe);
/* only need mod p^(e-1) */
return nmod_mul(logb1, t->invloga1, pe);
}

View file

@ -25,7 +25,7 @@ dlog_1modpe_init(dlog_1modpe_t t, ulong a1, ulong p, ulong e, nmod_t pe)
if (a1 == 1)
abort();
t->inv1p = nmod_inv(1 + p, pe); /* 1 - p + p^2 - ... */
loga1 = dlog_1modpe_mod1p(a1, p, e, t->inv1p, pe);
loga1 = dlog_1modpe_1modp(a1, p, e, t->inv1p, pe);
/* only need inverse mod p^(e-1) but does not hurt */
t->invloga1 = nmod_inv(loga1, pe);
}

View file

@ -13,7 +13,7 @@
/* for odd prime p, assume b1 = 1 mod p */
ulong
dlog_1modpe_mod1p(ulong b1, ulong p, ulong e, ulong inv1p, nmod_t pe)
dlog_1modpe_1modp(ulong b1, ulong p, ulong e, ulong inv1p, nmod_t pe)
{
int f;
ulong x, xf, pf, pf1;

View file

@ -11,33 +11,37 @@
#include "dlog.h"
ulong
dlog_mod2e_1mod4(ulong b1, ulong e, ulong inv5, nmod_t pe)
{
slong f;
ulong pf1, pf, x, xf;
pf1 = 1;
pf = 4;
x = 0;
for (f = 2; f < e; f++)
{
if (b1 % pf != 1)
{
flint_printf("ERROR dlog_mod2e: %wu %% %wu != 1 mod %wu\n\n",
b1, pf, pe.n);
abort();
}
xf = (b1 - 1) / pf;
xf = (f == 2) ? xf % 4 : (xf % 2) * (pf1 / 2);
b1 = nmod_mul(b1, nmod_pow_ui(inv5, xf, pe), pe);
x += xf;
pf1 = pf;
pf *= 2;
}
return x;
}
ulong
dlog_mod2e(const dlog_modpe_t t, ulong b1)
{
if (t->e == 2)
return (b1 % 4) == 3;
else
{
slong f;
ulong pf1, pf, x, xf;
pf1 = 1;
pf = 4;
x = 0;
for (f = 2; f < t->e; f++)
{
if (b1 % pf != 1)
{
flint_printf("ERROR dlog_mod2e: %wu %% %wu != 1 mod %wu\n\n",
b1, pf, t->pe.n);
abort();
}
xf = (b1 - 1) / pf;
xf = (f == 2) ? xf % 4 : (xf % 2) * (pf1 / 2);
b1 = nmod_mul(b1, nmod_pow_ui(t->inva, xf, t->pe), t->pe);
x += xf;
pf1 = pf;
pf *= 2;
}
return x;
}
return dlog_mod2e_1mod4(b1, t->e, t->inva, t->pe);
}