diff --git a/acb_dirichlet/conrey_log.c b/acb_dirichlet/conrey_log.c index 15040b26..d7a520f9 100644 --- a/acb_dirichlet/conrey_log.c +++ b/acb_dirichlet/conrey_log.c @@ -11,6 +11,7 @@ (at your option) any later version. See . */ +#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); } diff --git a/acb_dirichlet/test/t-conrey.c b/acb_dirichlet/test/t-conrey.c index 9b39f5c5..5e5a060b 100644 --- a/acb_dirichlet/test/t-conrey.c +++ b/acb_dirichlet/test/t-conrey.c @@ -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); diff --git a/dlog.h b/dlog.h index f62ef63a..b9352e26 100644 --- a/dlog.h +++ b/dlog.h @@ -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 diff --git a/dlog/1modpe.c b/dlog/1modpe.c index a9d12817..ecfa98c3 100644 --- a/dlog/1modpe.c +++ b/dlog/1modpe.c @@ -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); } diff --git a/dlog/1modpe_init.c b/dlog/1modpe_init.c index c8bef0b1..a28323bc 100644 --- a/dlog/1modpe_init.c +++ b/dlog/1modpe_init.c @@ -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); } diff --git a/dlog/1modpe_mod1p.c b/dlog/1modpe_mod1p.c index 830e1717..9693769f 100644 --- a/dlog/1modpe_mod1p.c +++ b/dlog/1modpe_mod1p.c @@ -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; diff --git a/dlog/mod2e.c b/dlog/mod2e.c index ed051503..2ef8e655 100644 --- a/dlog/mod2e.c +++ b/dlog/mod2e.c @@ -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); }