-
Notifications
You must be signed in to change notification settings - Fork 142
/
pow_arb_series.c
163 lines (134 loc) · 3.69 KB
/
pow_arb_series.c
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
Copyright (C) 2013 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 "arb_poly.h"
/* (a + bx^c)^g where a = f[0] and b = f[flen-1] */
void
_arb_poly_binomial_pow_arb_series(arb_ptr h, arb_srcptr f, slong flen, const arb_t g, slong len, slong prec)
{
slong i, j, d;
arb_t t;
arb_init(t);
d = flen - 1;
arb_pow(h, f, g, prec);
arb_div(t, f + d, f, prec);
for (i = 1, j = d; j < len; i++, j += d)
{
arb_sub_ui(h + j, g, i - 1, prec);
arb_mul(h + j, h + j, h + j - d, prec);
arb_mul(h + j, h + j, t, prec);
arb_div_ui(h + j, h + j, i, prec);
}
if (d > 1)
{
for (i = 1; i < len; i++)
if (i % d != 0)
arb_zero(h + i);
}
arb_clear(t);
return;
}
void
_arb_poly_pow_arb_series(arb_ptr h,
arb_srcptr f, slong flen, const arb_t g, slong len, slong prec)
{
int f_binomial, g_exact, g_int;
while (flen > 0 && arb_is_zero(f + flen - 1))
flen--;
if (flen <= 1)
{
arb_pow(h, f, g, prec);
_arb_vec_zero(h + 1, len - 1);
return;
}
g_exact = arb_is_exact(g);
g_int = arb_is_int(g);
f_binomial = _arb_vec_is_zero(f + 1, flen - 2);
/* g = small integer */
if (g_exact && g_int &&
arf_cmpabs_2exp_si(arb_midref(g), FLINT_BITS - 1) < 0)
{
slong e, hlen;
e = arf_get_si(arb_midref(g), ARF_RND_DOWN);
hlen = poly_pow_length(flen, FLINT_ABS(e), len);
if (e >= 0)
{
_arb_poly_pow_ui_trunc_binexp(h, f, flen, e, hlen, prec);
_arb_vec_zero(h + hlen, len - hlen);
return;
}
else if (!f_binomial)
{
arb_ptr t;
t = _arb_vec_init(hlen);
_arb_poly_pow_ui_trunc_binexp(t, f, flen, -e, hlen, prec);
_arb_poly_inv_series(h, t, hlen, len, prec);
_arb_vec_clear(t, hlen);
return;
}
}
/* (a + bx^c)^g */
if (f_binomial)
{
_arb_poly_binomial_pow_arb_series(h, f, flen, g, len, prec);
return;
}
/* g = +/- 1/2 */
if (g_exact && arf_cmpabs_2exp_si(arb_midref(g), -1) == 0)
{
if (arf_sgn(arb_midref(g)) > 0)
_arb_poly_sqrt_series(h, f, flen, len, prec);
else
_arb_poly_rsqrt_series(h, f, flen, len, prec);
return;
}
/* f^g = exp(g*log(f)) */
_arb_poly_log_series(h, f, flen, len, prec);
_arb_vec_scalar_mul(h, h, len, g, prec);
_arb_poly_exp_series(h, h, len, len, prec);
}
void
arb_poly_pow_arb_series(arb_poly_t h,
const arb_poly_t f, const arb_t g, slong len, slong prec)
{
slong flen;
flen = f->length;
flen = FLINT_MIN(flen, len);
if (len == 0)
{
arb_poly_zero(h);
return;
}
if (arb_is_zero(g))
{
arb_poly_one(h);
return;
}
if (flen == 0)
{
arb_poly_zero(h);
return;
}
if (f == h)
{
arb_poly_t t;
arb_poly_init2(t, len);
_arb_poly_pow_arb_series(t->coeffs, f->coeffs, flen, g, len, prec);
_arb_poly_set_length(t, len);
_arb_poly_normalise(t);
arb_poly_swap(t, h);
arb_poly_clear(t);
}
else
{
arb_poly_fit_length(h, len);
_arb_poly_pow_arb_series(h->coeffs, f->coeffs, flen, g, len, prec);
_arb_poly_set_length(h, len);
_arb_poly_normalise(h);
}
}