mirror of
https://github.com/vale981/arb
synced 2025-03-06 01:41:39 -05:00
improve log_series for special-form input
This commit is contained in:
parent
be6a8ee46f
commit
94120b0ddd
4 changed files with 90 additions and 34 deletions
|
@ -28,33 +28,59 @@
|
||||||
void
|
void
|
||||||
_fmpcb_poly_log_series(fmpcb_ptr res, fmpcb_srcptr f, long flen, long n, long prec)
|
_fmpcb_poly_log_series(fmpcb_ptr res, fmpcb_srcptr f, long flen, long n, long prec)
|
||||||
{
|
{
|
||||||
fmpcb_ptr f_diff, f_inv;
|
flen = FLINT_MIN(flen, n);
|
||||||
fmpcb_t a;
|
|
||||||
long alloc;
|
|
||||||
|
|
||||||
if (flen == 1)
|
if (flen == 1)
|
||||||
{
|
{
|
||||||
fmpcb_log(res, f, prec);
|
fmpcb_log(res, f, prec);
|
||||||
_fmpcb_vec_zero(res + 1, n - 1);
|
_fmpcb_vec_zero(res + 1, n - 1);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else if (n == 2)
|
||||||
|
{
|
||||||
|
fmpcb_div(res + 1, f + 1, f + 0, prec); /* safe since hlen >= 2 */
|
||||||
|
fmpcb_log(res, f, prec);
|
||||||
|
}
|
||||||
|
else if (_fmpcb_vec_is_zero(f + 1, flen - 2)) /* f = a + bx^d */
|
||||||
|
{
|
||||||
|
long i, j, d = flen - 1;
|
||||||
|
|
||||||
flen = FLINT_MIN(flen, n);
|
for (i = 1, j = d; j < n; j += d, i++)
|
||||||
alloc = n + flen - 1;
|
{
|
||||||
f_inv = _fmpcb_vec_init(alloc);
|
if (i == 1)
|
||||||
f_diff = f_inv + n;
|
fmpcb_div(res + j, f + d, f + 0, prec);
|
||||||
|
else
|
||||||
|
fmpcb_mul(res + j, res + j - d, res + d, prec);
|
||||||
|
_fmpcb_vec_zero(res + j - d + 1, flen - 2);
|
||||||
|
}
|
||||||
|
_fmpcb_vec_zero(res + j - d + 1, n - (j - d + 1));
|
||||||
|
|
||||||
fmpcb_init(a);
|
for (i = 2, j = 2 * d; j < n; j += d, i++)
|
||||||
fmpcb_log(a, f, prec);
|
fmpcb_div_si(res + j, res + j, i % 2 ? i : -i, prec);
|
||||||
|
|
||||||
_fmpcb_poly_derivative(f_diff, f, flen, prec);
|
fmpcb_log(res, f, prec); /* done last to allow aliasing */
|
||||||
_fmpcb_poly_inv_series(f_inv, f, flen, n, prec);
|
}
|
||||||
_fmpcb_poly_mullow(res, f_inv, n - 1, f_diff, flen - 1, n - 1, prec);
|
else
|
||||||
_fmpcb_poly_integral(res, res, n, prec);
|
{
|
||||||
fmpcb_swap(res, a);
|
fmpcb_ptr f_diff, f_inv;
|
||||||
|
fmpcb_t a;
|
||||||
|
long alloc;
|
||||||
|
|
||||||
fmpcb_clear(a);
|
alloc = n + flen - 1;
|
||||||
_fmpcb_vec_clear(f_inv, alloc);
|
f_inv = _fmpcb_vec_init(alloc);
|
||||||
|
f_diff = f_inv + n;
|
||||||
|
|
||||||
|
fmpcb_init(a);
|
||||||
|
fmpcb_log(a, f, prec);
|
||||||
|
|
||||||
|
_fmpcb_poly_derivative(f_diff, f, flen, prec);
|
||||||
|
_fmpcb_poly_inv_series(f_inv, f, flen, n, prec);
|
||||||
|
_fmpcb_poly_mullow(res, f_inv, n - 1, f_diff, flen - 1, n - 1, prec);
|
||||||
|
_fmpcb_poly_integral(res, res, n, prec);
|
||||||
|
fmpcb_swap(res, a);
|
||||||
|
|
||||||
|
fmpcb_clear(a);
|
||||||
|
_fmpcb_vec_clear(f_inv, alloc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -61,6 +61,7 @@ int main()
|
||||||
|
|
||||||
fmpq_poly_log_series(B, A, n);
|
fmpq_poly_log_series(B, A, n);
|
||||||
fmpcb_poly_set_fmpq_poly(a, A, rbits1);
|
fmpcb_poly_set_fmpq_poly(a, A, rbits1);
|
||||||
|
fmpcb_poly_randtest(b, state, 1 + n_randint(state, 20), rbits1, 5);
|
||||||
fmpcb_poly_log_series(b, a, n, rbits2);
|
fmpcb_poly_log_series(b, a, n, rbits2);
|
||||||
|
|
||||||
if (!fmpcb_poly_contains_fmpq_poly(b, B))
|
if (!fmpcb_poly_contains_fmpq_poly(b, B))
|
||||||
|
@ -155,6 +156,7 @@ int main()
|
||||||
|
|
||||||
fmpcb_poly_set_fmpq_poly(a, A, rbits1);
|
fmpcb_poly_set_fmpq_poly(a, A, rbits1);
|
||||||
|
|
||||||
|
fmpcb_poly_randtest(b, state, 1 + n_randint(state, 20), rbits1, 5);
|
||||||
fmpcb_poly_log_series(b, a, n, rbits2);
|
fmpcb_poly_log_series(b, a, n, rbits2);
|
||||||
fmpcb_poly_exp_series_basecase(c, b, n, rbits3);
|
fmpcb_poly_exp_series_basecase(c, b, n, rbits3);
|
||||||
|
|
||||||
|
|
|
@ -28,33 +28,59 @@
|
||||||
void
|
void
|
||||||
_fmprb_poly_log_series(fmprb_ptr res, fmprb_srcptr f, long flen, long n, long prec)
|
_fmprb_poly_log_series(fmprb_ptr res, fmprb_srcptr f, long flen, long n, long prec)
|
||||||
{
|
{
|
||||||
fmprb_ptr f_diff, f_inv;
|
flen = FLINT_MIN(flen, n);
|
||||||
fmprb_t a;
|
|
||||||
long alloc;
|
|
||||||
|
|
||||||
if (flen == 1)
|
if (flen == 1)
|
||||||
{
|
{
|
||||||
fmprb_log(res, f, prec);
|
fmprb_log(res, f, prec);
|
||||||
_fmprb_vec_zero(res + 1, n - 1);
|
_fmprb_vec_zero(res + 1, n - 1);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else if (n == 2)
|
||||||
|
{
|
||||||
|
fmprb_div(res + 1, f + 1, f + 0, prec); /* safe since hlen >= 2 */
|
||||||
|
fmprb_log(res, f, prec);
|
||||||
|
}
|
||||||
|
else if (_fmprb_vec_is_zero(f + 1, flen - 2)) /* f = a + bx^d */
|
||||||
|
{
|
||||||
|
long i, j, d = flen - 1;
|
||||||
|
|
||||||
flen = FLINT_MIN(flen, n);
|
for (i = 1, j = d; j < n; j += d, i++)
|
||||||
alloc = n + flen - 1;
|
{
|
||||||
f_inv = _fmprb_vec_init(alloc);
|
if (i == 1)
|
||||||
f_diff = f_inv + n;
|
fmprb_div(res + j, f + d, f + 0, prec);
|
||||||
|
else
|
||||||
|
fmprb_mul(res + j, res + j - d, res + d, prec);
|
||||||
|
_fmprb_vec_zero(res + j - d + 1, flen - 2);
|
||||||
|
}
|
||||||
|
_fmprb_vec_zero(res + j - d + 1, n - (j - d + 1));
|
||||||
|
|
||||||
fmprb_init(a);
|
for (i = 2, j = 2 * d; j < n; j += d, i++)
|
||||||
fmprb_log(a, f, prec);
|
fmprb_div_si(res + j, res + j, i % 2 ? i : -i, prec);
|
||||||
|
|
||||||
_fmprb_poly_derivative(f_diff, f, flen, prec);
|
fmprb_log(res, f, prec); /* done last to allow aliasing */
|
||||||
_fmprb_poly_inv_series(f_inv, f, flen, n, prec);
|
}
|
||||||
_fmprb_poly_mullow(res, f_inv, n - 1, f_diff, flen - 1, n - 1, prec);
|
else
|
||||||
_fmprb_poly_integral(res, res, n, prec);
|
{
|
||||||
fmprb_swap(res, a);
|
fmprb_ptr f_diff, f_inv;
|
||||||
|
fmprb_t a;
|
||||||
|
long alloc;
|
||||||
|
|
||||||
fmprb_clear(a);
|
alloc = n + flen - 1;
|
||||||
_fmprb_vec_clear(f_inv, alloc);
|
f_inv = _fmprb_vec_init(alloc);
|
||||||
|
f_diff = f_inv + n;
|
||||||
|
|
||||||
|
fmprb_init(a);
|
||||||
|
fmprb_log(a, f, prec);
|
||||||
|
|
||||||
|
_fmprb_poly_derivative(f_diff, f, flen, prec);
|
||||||
|
_fmprb_poly_inv_series(f_inv, f, flen, n, prec);
|
||||||
|
_fmprb_poly_mullow(res, f_inv, n - 1, f_diff, flen - 1, n - 1, prec);
|
||||||
|
_fmprb_poly_integral(res, res, n, prec);
|
||||||
|
fmprb_swap(res, a);
|
||||||
|
|
||||||
|
fmprb_clear(a);
|
||||||
|
_fmprb_vec_clear(f_inv, alloc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -61,6 +61,7 @@ int main()
|
||||||
|
|
||||||
fmpq_poly_log_series(B, A, n);
|
fmpq_poly_log_series(B, A, n);
|
||||||
fmprb_poly_set_fmpq_poly(a, A, rbits1);
|
fmprb_poly_set_fmpq_poly(a, A, rbits1);
|
||||||
|
fmprb_poly_randtest(b, state, 1 + n_randint(state, 20), rbits1, 5);
|
||||||
fmprb_poly_log_series(b, a, n, rbits2);
|
fmprb_poly_log_series(b, a, n, rbits2);
|
||||||
|
|
||||||
if (!fmprb_poly_contains_fmpq_poly(b, B))
|
if (!fmprb_poly_contains_fmpq_poly(b, B))
|
||||||
|
@ -155,6 +156,7 @@ int main()
|
||||||
|
|
||||||
fmprb_poly_set_fmpq_poly(a, A, rbits1);
|
fmprb_poly_set_fmpq_poly(a, A, rbits1);
|
||||||
|
|
||||||
|
fmprb_poly_randtest(b, state, 1 + n_randint(state, 20), rbits1, 5);
|
||||||
fmprb_poly_log_series(b, a, n, rbits2);
|
fmprb_poly_log_series(b, a, n, rbits2);
|
||||||
fmprb_poly_exp_series_basecase(c, b, n, rbits3);
|
fmprb_poly_exp_series_basecase(c, b, n, rbits3);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue