<commit_before>/*
    Copyright (C) 2016 <NAME>

    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/>.
*/

#include "acb_dirichlet.h"

int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("conrey....");
    fflush(stdout);
    flint_randinit(state);

    for (iter = 0; iter < 3000 * arb_test_multiplier(); iter++)
    {
        acb_dirichlet_group_t G;
        acb_dirichlet_conrey_t x, y;
        ulong q, n, k, sum;
        long ref;
        /*int * bits;*/

        q = 1 + n_randint(state, 1000 * (1 + iter / 100));

        acb_dirichlet_group_init(G, q);

        acb_dirichlet_conrey_init(x, G);
        acb_dirichlet_conrey_init(y, G);

        /* check group size and elements */
        acb_dirichlet_conrey_one(x, G);
        sum = 1;

#if 1
        for (n = 1; acb_dirichlet_conrey_next(x, G) >= 0; n++)
            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

        /* use http://oeis.org/A053818 to check all elements
         * are gone through */
        ref = (q % 4 == 2) ? -2 : 1;
        for (k = (G->neven == 2); k < G->num; k++)
            ref = - ref * G->P[k].p;
        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();
        }

        if (q % 4 != 2)
        {
            acb_dirichlet_conrey_first_primitive(x, G);
            for (n = 1; acb_dirichlet_conrey_next_primitive(x, G) >= 0; n++);

            ref = acb_dirichlet_number_primitive(G);
            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();
            }


            /* some random elements, check log and exp */<commit_msg>sanitize conrey test for 32 bits<commit_after>/*
    Copyright (C) 2016 <NAME>

    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/>.
*/

#include "acb_dirichlet.h"

int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("conrey....");
    fflush(stdout);
    flint_randinit(state);

    for (iter = 0; iter < 3000 * arb_test_multiplier(); iter++)
    {
        acb_dirichlet_group_t G;
        acb_dirichlet_conrey_t x, y;
        ulong q, n, k, sum;
        slong ref;

        q = 1 + n_randint(state, 1000 * (1 + iter / 100));

        acb_dirichlet_group_init(G, q);

        acb_dirichlet_conrey_init(x, G);
        acb_dirichlet_conrey_init(y, G);

        /* check group size and elements */
        acb_dirichlet_conrey_one(x, G);
        sum = 1;

        for (n = 1; acb_dirichlet_conrey_next(x, G) >= 0; n++)
            sum += x->n * x->n;

        if (FLINT_BITS == 64 || q < 1024)
        {
            /* use http://oeis.org/A053818 to check all elements
             * are gone through */
            ref = (q % 4 == 2) ? -2 : 1;
            for (k = (G->neven == 2); k < G->num; k++)
                ref = - ref * G->P[k].p;
            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();
            }
        }

        if (q % 4 != 2)
        {
            acb_dirichlet_conrey_first_primitive(x, G);
            for (n = 1; acb_dirichlet_conrey_next_primitive(x, G) >= 0; n++);

            ref = acb_dirichlet_number_primitive(G);
            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();
            }

            /* some random elements, check log and exp */
{'fraction_non_alphanumeric': 0.14384057971014494, 'fraction_numerical': 0.017391304347826087, 'mean_word_length': 1.5667131566713157, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '899298', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1874, 'n_words': 495}