File: hardy_theta.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 (126 lines) | stat: -rw-r--r-- 3,027 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
    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"
#include "acb_poly.h"

void
acb_dirichlet_hardy_theta(acb_ptr res, const acb_t t,
    const dirichlet_group_t G, const dirichlet_char_t chi,
    slong len, slong prec)
{
    acb_struct y[2];
    arb_t c;
    slong k;
    int parity;
    ulong q;

    if (len <= 0)
        return;

    if (t == res)
    {
        acb_init(y);
        acb_set(y, t);
        acb_dirichlet_hardy_theta(res, y, G, chi, len, prec);
        acb_clear(y);
        return;
    }

    if (G == NULL)
    {
        parity = 0;
        q = 1;
    }
    else
    {
        parity = dirichlet_parity_char(G, chi);
        q = G->q;

        if (q != dirichlet_conductor_char(G, chi))
        {
            flint_printf("hardy theta: need primitive character\n");
            flint_abort();
        }
    }

    if (!acb_is_finite(t))
    {
        _acb_vec_indeterminate(res, len);
        return;
    }

    acb_init(y + 0);
    acb_init(y + 1);
    arb_init(c);

    /* res = log gamma((s+parity)/2), s = 0.5+i(t+x) */
    acb_mul_onei(y, t);
    arb_set_d(c, 0.5 + parity);
    arb_add(acb_realref(y), acb_realref(y), c, prec);
    acb_mul_2exp_si(y, y, -1);
    acb_onei(y + 1);
    acb_mul_2exp_si(y + 1, y + 1, -1);
    _acb_poly_lgamma_series(res, y, FLINT_MIN(len, 2), len, prec);

    if (acb_is_real(t))
    {
        for (k = 0; k < len; k++)
        {
            arb_set(acb_realref(res + k), acb_imagref(res + k));
            arb_zero(acb_imagref(res + k));
        }
    }
    else
    {
        acb_ptr v = _acb_vec_init(len);

        /* v = log gamma(((1-s)+parity)/2), s = 0.5+i(t+x) */
        acb_div_onei(y, t);
        arb_set_d(c, 0.5 + parity);
        arb_add(acb_realref(y), acb_realref(y), c, prec);
        acb_mul_2exp_si(y, y, -1);
        acb_neg(y + 1, y + 1);
        _acb_poly_lgamma_series(v, y, FLINT_MIN(len, 2), len, prec);

        _acb_vec_sub(res, res, v, len, prec);
        for (k = 0; k < len; k++)
        {
            acb_div_onei(res + k, res + k);
            acb_mul_2exp_si(res + k, res + k, -1);
        }

        _acb_vec_clear(v, len);
    }

    /* (t+x) [-(1/2) log(pi/q)] */
    arb_const_pi(c, prec);
    arb_div_ui(c, c, q, prec);
    arb_log(c, c, prec);
    arb_mul_2exp_si(c, c, -1);
    acb_submul_arb(res, t, c, prec);
    if (len > 1)
        acb_sub_arb(res + 1, res + 1, c, prec);

    /* i log(eps) / 2 */
    if (q > 1)
    {
        acb_dirichlet_root_number(y, G, chi, prec);
        acb_arg(c, y, prec);
        arb_mul_2exp_si(c, c, -1);
        arb_sub(acb_realref(res), acb_realref(res), c, prec);
    }

    acb_clear(y + 0);
    acb_clear(y + 1);
    arb_clear(c);
}