File: root.c

package info (click to toggle)
flint-arb 1%3A2.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,028 kB
  • sloc: ansic: 177,109; sh: 553; makefile: 288; python: 268
file content (103 lines) | stat: -rw-r--r-- 2,244 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
    Copyright (C) 2016 Pascal Molin
    Copyright (C) 2016 Fredrik Johansson

    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"

void
acb_dirichlet_root(acb_t z, const acb_dirichlet_roots_t t, ulong k, slong prec)
{
    ulong n = t->order;
    int swap, flip, conjugate;
    slong wp;

    if (k > n)
        k %= n;

    swap = flip = conjugate = 0;

    if (k > n / 2)
    {
        conjugate = 1;
        k = n - k;
    }

    if (n % 2 == 0 && k > n / 4)
    {
        flip = 1;
        k = n / 2 - k;
    }

    if (n % 4 == 0 && k > n / 8)
    {
        swap = 1;
        k = n / 4 - k;
    }

    wp = prec + 6 + 2 * FLINT_BIT_COUNT(t->reduced_order);

    if (k == 0)
    {
        acb_one(z);
    }
    else if (t->depth == 0)
    {
        if (t->use_pow)
        {
            acb_pow_ui(z, t->z, k, wp);
            acb_set_round(z, z, prec);
        }
        else
        {
            ulong r;
            fmpq_t t;
            fmpq_init(t);
            r = n_gcd(n, 2 * k); /* no overflow since since k <= n / 2 */
            fmpz_set_ui(fmpq_numref(t), (2 * k) / r);
            fmpz_set_ui(fmpq_denref(t), n / r);
            arb_sin_cos_pi_fmpq(acb_imagref(z), acb_realref(z), t, prec);
            fmpq_clear(t);
        }
    }
    else if (t->depth == 1)
    {
        acb_set_round(z, t->Z[0] + k, prec);
    }
    else
    {
        slong j;
        ulong r;

        r = k % t->size;
        k = k / t->size;
        acb_set(z, t->Z[0] + r);

        for (j = 1; j < t->depth && k != 0; j++)
        {
            r = k % t->size;
            k = k / t->size;
            acb_mul(z, z, t->Z[j] + r, wp);
        }

        if (k != 0)
            flint_abort();

        acb_set_round(z, z, prec);
    }

    if (swap)
        arb_swap(acb_realref(z), acb_imagref(z));
    if (flip)
        arb_neg(acb_realref(z), acb_realref(z));
    if (conjugate)
        arb_neg(acb_imagref(z), acb_imagref(z));
}