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
/*
Copyright (C) 2014 Fredrik Johansson
This file is part of FLINT.
FLINT 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 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "mag.h"
void
mag_polylog_tail(mag_t u, const mag_t z, slong sigma, ulong d, ulong N)
{
mag_t TN, UN, t;
if (N < 2)
{
mag_inf(u);
return;
}
mag_init(TN);
mag_init(UN);
mag_init(t);
if (mag_cmp_2exp_si(z, 0) >= 0)
{
mag_inf(u);
}
else
{
/* Bound T(N) */
mag_pow_ui(TN, z, N);
/* multiply by log(N)^d */
if (d > 0)
{
mag_log_ui(t, N);
mag_pow_ui(t, t, d);
mag_mul(TN, TN, t);
}
/* multiply by 1/k^s */
if (sigma > 0)
{
mag_set_ui_lower(t, N);
mag_pow_ui_lower(t, t, sigma);
mag_div(TN, TN, t);
}
else if (sigma < 0)
{
mag_set_ui(t, N);
mag_pow_ui(t, t, -sigma);
mag_mul(TN, TN, t);
}
/* Bound U(N) */
mag_set(UN, z);
/* multiply by (1 + 1/N)**S */
if (sigma < 0)
{
mag_binpow_uiui(t, N, -sigma);
mag_mul(UN, UN, t);
}
/* multiply by (1 + 1/(N log(N)))^d */
if (d > 0)
{
ulong nl;
/* rounds down */
nl = mag_d_log_lower_bound(N) * N * (1 - 1e-13);
mag_binpow_uiui(t, nl, d);
mag_mul(UN, UN, t);
}
/* T(N) / (1 - U(N)) */
if (mag_cmp_2exp_si(UN, 0) >= 0)
{
mag_inf(u);
}
else
{
mag_one(t);
mag_sub_lower(t, t, UN);
mag_div(u, TN, t);
}
}
mag_clear(TN);
mag_clear(UN);
mag_clear(t);
}