arb/dirichlet/chi_vec_loop.c

71 lines
1.8 KiB
C
Raw Normal View History

2016-09-06 15:32:23 +02:00
/*
Copyright (C) 2016 Pascal Molin
2016-09-06 15:32:23 +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-10-06 14:19:39 +02:00
#include "dirichlet.h"
2016-10-08 17:22:19 +02:00
static void
dirichlet_exponents_char(ulong * expo, const dirichlet_group_t G, const dirichlet_char_t chi, ulong order)
{
slong k;
ulong factor = G->expo / order;
for (k = 0; k < G->num; k++)
/* no overflow: log[k] < phi[k] and G->expo = phi[k] * PHI[k] */
expo[k] = (chi->log[k] * G->PHI[k]) / factor;
}
/* loop over whole group */
void
2016-10-08 17:22:19 +02:00
dirichlet_chi_vec_loop_order(ulong * v, const dirichlet_group_t G, const dirichlet_char_t chi, ulong order, slong nv)
{
int j;
2016-03-29 14:37:21 +01:00
ulong t;
slong k;
2016-10-08 17:22:19 +02:00
ulong expo[MAX_FACTORS];
2016-10-07 13:06:05 +02:00
dirichlet_char_t x;
2016-10-08 17:22:19 +02:00
nmod_t o;
2016-10-07 13:06:05 +02:00
dirichlet_char_init(x, G);
dirichlet_char_one(x, G);
2016-10-08 17:22:19 +02:00
dirichlet_exponents_char(expo, G, chi, order);
nmod_init(&o, order);
for (k = 0; k < nv; k++)
2016-10-06 14:19:39 +02:00
v[k] = DIRICHLET_CHI_NULL;
t = v[1] = 0;
2016-03-29 14:04:08 +01:00
2016-10-07 13:06:05 +02:00
while ( (j = dirichlet_char_next(x, G)) >= 0 )
{
/* exponents were modified up to j */
for (k = G->num - 1; k >= j; k--)
2016-10-08 17:22:19 +02:00
t = nmod_add(t, expo[k], o);
2016-03-29 14:04:08 +01:00
if (x->n < nv)
v[x->n] = t;
}
2016-03-29 14:04:08 +01:00
/* fix result outside primes */
2016-10-06 14:19:39 +02:00
/* dirichlet_vec_set_null(v, G, nv);*/
/* copy outside modulus */
2016-03-29 14:04:08 +01:00
for (k = G->q; k < nv ; k++ )
v[k] = v[k - G->q];
2016-03-29 14:04:08 +01:00
2016-10-07 13:06:05 +02:00
dirichlet_char_clear(x);
}
2016-10-08 17:22:19 +02:00
void
dirichlet_chi_vec_loop(ulong * v, const dirichlet_group_t G, const dirichlet_char_t chi, slong nv)
{
dirichlet_chi_vec_loop_order(v, G, chi, G->expo, nv);
}