File: jacobi_p.c

package info (click to toggle)
flint-arb 1%3A2.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,672 kB
  • sloc: ansic: 204,753; sh: 570; makefile: 287; python: 268
file content (119 lines) | stat: -rw-r--r-- 2,709 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
/*
    Copyright (C) 2015 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_hypgeom.h"

/* this can be improved */
static int
use_recurrence(const acb_t n, const acb_t a, const acb_t b, slong prec)
{
    if (!acb_is_int(n) || !arb_is_nonnegative(acb_realref(n)))
        return 0;

    if (arf_cmpabs_ui(arb_midref(acb_realref(n)), prec) > 0)
        return 0;

    if (arb_is_nonnegative(acb_realref(a)) ||
        arf_get_d(arb_midref(acb_realref(a)), ARF_RND_DOWN) > -0.9)
        return 0;

    return 1;
}

void
acb_hypgeom_jacobi_p_ui_direct(acb_t res, ulong n,
    const acb_t a, const acb_t b, const acb_t z, slong prec)
{
    acb_ptr terms;
    acb_t t, u, v;
    slong k;

    terms = _acb_vec_init(n + 1);
    acb_init(t);
    acb_init(u);
    acb_init(v);

    acb_one(terms);
    acb_add_ui(u, z, 1, prec);

    for (k = 1; k <= n; k++)
    {
        acb_add_ui(t, a, n + 1 - k, prec);
        acb_mul(t, t, u, prec);
        acb_div_ui(t, t, 2 * k, prec);
        acb_mul(terms + k, terms + k - 1, t, prec);
    }

    acb_sub_ui(u, z, 1, prec);
    acb_one(v);

    for (k = 1; k <= n; k++)
    {
        acb_add_ui(t, b, n + 1 - k, prec);
        acb_mul(t, t, u, prec);
        acb_div_ui(t, t, 2 * k, prec);
        acb_mul(v, v, t, prec);
        acb_mul(terms + n - k, terms + n - k, v, prec);
    }

    acb_set(res, terms);
    for (k = 1; k <= n; k++)
        acb_add(res, res, terms + k, prec);

    _acb_vec_clear(terms, n + 1);
    acb_clear(t);
    acb_clear(u);
    acb_clear(v);
}

void
acb_hypgeom_jacobi_p(acb_t res, const acb_t n, const acb_t a, const acb_t b,
    const acb_t z, slong prec)
{
    acb_t t, u, v, w;

    if (use_recurrence(n, a, b, prec))
    {
        acb_hypgeom_jacobi_p_ui_direct(res,
            arf_get_si(arb_midref(acb_realref(n)), ARF_RND_DOWN), a, b, z, prec);
        return;
    }

    acb_init(t);
    acb_init(u);
    acb_init(v);
    acb_init(w);

    acb_neg(t, n);
    acb_add_ui(v, a, 1, prec);
    acb_add(u, n, v, prec);
    acb_add(u, u, b, prec);
    acb_sub_ui(w, z, 1, prec);
    acb_mul_2exp_si(w, w, -1);
    acb_neg(w, w);

    acb_hypgeom_2f1(w, t, u, v, w, 0, prec);

    acb_rising(t, v, n, prec);
    acb_mul(w, w, t, prec);

    acb_add_ui(t, n, 1, prec);
    acb_rgamma(t, t, prec);
    acb_mul(w, w, t, prec);

    acb_set(res, w);

    acb_clear(t);
    acb_clear(u);
    acb_clear(v);
    acb_clear(w);
}