2016-02-26 16:49:26 +01: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 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
|
|
|
|
|
|
|
|
=============================================================================*/
|
|
|
|
/******************************************************************************
|
|
|
|
|
2016-03-07 09:54:42 +01:00
|
|
|
Copyright (C) 2016 Pascal Molin
|
2016-02-26 16:49:26 +01:00
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "acb_dirichlet.h"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
slong iter;
|
|
|
|
flint_rand_t state;
|
|
|
|
|
2016-03-22 11:29:21 +01:00
|
|
|
flint_printf("conrey....");
|
2016-02-26 16:49:26 +01:00
|
|
|
fflush(stdout);
|
|
|
|
flint_randinit(state);
|
|
|
|
|
2016-04-05 11:55:04 +02:00
|
|
|
for (iter = 0; iter < 3000; iter++)
|
2016-02-26 16:49:26 +01:00
|
|
|
{
|
|
|
|
acb_dirichlet_group_t G;
|
2016-07-22 12:39:17 +02:00
|
|
|
acb_dirichlet_conrey_t x, y;
|
2016-02-26 16:49:26 +01:00
|
|
|
ulong q, n, k, sum;
|
|
|
|
long ref;
|
|
|
|
/*int * bits;*/
|
|
|
|
|
|
|
|
q = 1 + n_randint(state, 1000 * (1 + iter / 100));
|
|
|
|
|
|
|
|
acb_dirichlet_group_init(G, q);
|
|
|
|
|
2016-03-22 11:29:21 +01:00
|
|
|
acb_dirichlet_conrey_init(x, G);
|
2016-07-22 12:39:17 +02:00
|
|
|
acb_dirichlet_conrey_init(y, G);
|
2016-02-29 00:13:58 +01:00
|
|
|
|
|
|
|
/* check group size and elements */
|
2016-03-22 11:29:21 +01:00
|
|
|
acb_dirichlet_conrey_one(x, G);
|
2016-02-29 00:13:58 +01:00
|
|
|
sum = 1;
|
|
|
|
|
|
|
|
#if 1
|
2016-08-04 15:35:33 +02:00
|
|
|
for (n = 1; acb_dirichlet_conrey_next(x, G) >= 0; n++)
|
2016-02-29 00:13:58 +01:00
|
|
|
sum += x->n * x->n;
|
|
|
|
#else
|
|
|
|
/* iteration much faster than gcd below */
|
|
|
|
n = 1;
|
|
|
|
for (k = 2; k < G->q; k++)
|
|
|
|
{
|
|
|
|
if (n_gcd(k, G->q) > 1)
|
|
|
|
continue;
|
|
|
|
n++;
|
|
|
|
sum += k * k;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-26 16:49:26 +01:00
|
|
|
/* use http://oeis.org/A053818 to check all elements
|
|
|
|
* are gone through */
|
|
|
|
ref = (q % 4 == 2) ? -2 : 1;
|
2016-08-04 15:35:33 +02:00
|
|
|
for (k = (G->neven == 2); k < G->num; k++)
|
2016-07-06 18:39:29 +02:00
|
|
|
ref = - ref * G->P[k].p;
|
2016-02-26 16:49:26 +01:00
|
|
|
ref = ( G->phi_q * (2 * q * q + ref) ) / 6;
|
|
|
|
|
|
|
|
if (n != G->phi_q)
|
|
|
|
{
|
|
|
|
flint_printf("FAIL: group size\n\n");
|
|
|
|
flint_printf("q = %wu\n\n", q);
|
|
|
|
flint_printf("phi(q) = %wu\n\n", G->phi_q);
|
|
|
|
flint_printf("loop index = %wu\n\n", n);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (sum != ref && q > 1)
|
|
|
|
{
|
|
|
|
flint_printf("FAIL: sum test\n\n");
|
|
|
|
flint_printf("q = %wu\n\n", q);
|
|
|
|
flint_printf("sum k^2 = %wu\n\n", ref);
|
|
|
|
flint_printf("sum obtained = %wu\n\n", sum);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2016-02-29 00:13:58 +01:00
|
|
|
if (q % 4 == 2)
|
|
|
|
continue;
|
|
|
|
|
2016-03-22 11:29:21 +01:00
|
|
|
acb_dirichlet_conrey_first_primitive(x, G);
|
2016-08-04 15:35:33 +02:00
|
|
|
for (n = 1; acb_dirichlet_conrey_next_primitive(x, G) >= 0; n++);
|
2016-02-29 00:13:58 +01:00
|
|
|
|
2016-06-15 12:23:24 +02:00
|
|
|
ref = acb_dirichlet_number_primitive(G);
|
2016-02-29 00:13:58 +01:00
|
|
|
if (n != ref)
|
|
|
|
{
|
|
|
|
flint_printf("FAIL: number of primitive elements\n\n");
|
|
|
|
flint_printf("q = %wu\n\n", q);
|
|
|
|
flint_printf("# primitive = %wu\n\n", ref);
|
|
|
|
flint_printf("loop index = %wu\n\n", n);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2016-07-22 12:39:17 +02:00
|
|
|
|
|
|
|
/* some random elements, check log and exp */
|
|
|
|
for (n = 0; n < 30; n++)
|
|
|
|
{
|
|
|
|
slong k;
|
|
|
|
ulong m;
|
2016-08-04 18:56:27 +02:00
|
|
|
|
2016-07-22 12:39:17 +02:00
|
|
|
for (m = 1; n_gcd(m, q) > 1; m = n_randint(state, q));
|
|
|
|
acb_dirichlet_conrey_log(x, G, m);
|
|
|
|
|
|
|
|
if (m != acb_dirichlet_conrey_exp(x, G))
|
|
|
|
{
|
|
|
|
flint_printf("FAIL: conrey log and exp\n\n");
|
|
|
|
flint_printf("q = %wu\n\n", q);
|
|
|
|
flint_printf("m = %wu\n\n", m);
|
|
|
|
flint_printf("conrey = ");
|
|
|
|
acb_dirichlet_conrey_print(G, x);
|
|
|
|
flint_printf("\n\nnumber = %wu\n\n", x->n);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (k = 0; k < G->num; k++)
|
|
|
|
x->log[k] = n_randint(state, G->P[k].phi);
|
|
|
|
|
|
|
|
m = acb_dirichlet_conrey_exp(x, G);
|
|
|
|
acb_dirichlet_conrey_log(y, G, m);
|
|
|
|
|
|
|
|
if (!acb_dirichlet_conrey_eq(G, x, y))
|
|
|
|
{
|
|
|
|
flint_printf("FAIL: conrey log and exp\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("log = ");
|
|
|
|
acb_dirichlet_conrey_print(G, y);
|
|
|
|
flint_printf("\n\nnumber = %wu\n\n", y->n);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2016-08-04 18:56:27 +02:00
|
|
|
acb_dirichlet_conrey_next_primitive(x, G);
|
|
|
|
m = x->n;
|
|
|
|
|
|
|
|
if (m != acb_dirichlet_conrey_exp(x, G))
|
|
|
|
{
|
|
|
|
flint_printf("FAIL: conrey number next primitive\n\n");
|
|
|
|
flint_printf("q = %wu\n\n", q);
|
|
|
|
flint_printf("conrey = ");
|
|
|
|
acb_dirichlet_conrey_print(G, y);
|
|
|
|
flint_printf(", m = %wu\n\n", y->n);
|
|
|
|
flint_printf("next primitive = ");
|
|
|
|
acb_dirichlet_conrey_print(G, x);
|
|
|
|
flint_printf(", m = %wu\n\n", m);
|
|
|
|
flint_printf("exp = %wu\n\n", x->n);
|
|
|
|
abort();
|
|
|
|
}
|
2016-07-22 12:39:17 +02:00
|
|
|
}
|
|
|
|
|
2016-03-22 11:29:21 +01:00
|
|
|
acb_dirichlet_conrey_clear(x);
|
2016-07-22 12:39:17 +02:00
|
|
|
acb_dirichlet_conrey_clear(y);
|
2016-02-26 16:49:26 +01:00
|
|
|
acb_dirichlet_group_clear(G);
|
|
|
|
}
|
|
|
|
|
|
|
|
flint_randclear(state);
|
|
|
|
flint_cleanup();
|
|
|
|
flint_printf("PASS\n");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|