Skip to content

Commit

Permalink
Merge pull request #2142 from fredrik-johansson/sinc2
Browse files Browse the repository at this point in the history
Handle 0-containing constant term in arb_poly_sinc_pi_series; add acb_poly_sinc_pi_series
  • Loading branch information
fredrik-johansson authored Jan 9, 2025
2 parents d7f45cb + 3a4131b commit f0b28ad
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 1 deletion.
7 changes: 7 additions & 0 deletions doc/source/acb_poly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,13 @@ Elementary functions
Sets *s* to the sinc function of the power series *h*, truncated
to length *n*.

.. function:: void _acb_poly_sinc_pi_series(acb_ptr s, acb_srcptr h, slong hlen, slong n, slong prec)

.. function:: void acb_poly_sinc_pi_series(acb_poly_t s, const acb_poly_t h, slong n, slong prec)

Compute the sinc function of the input multiplied by `\pi`.


Lambert W function
-------------------------------------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions src/acb_poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ void acb_poly_tan_series(acb_poly_t g, const acb_poly_t h, slong n, slong prec);

void _acb_poly_sinc_series(acb_ptr g, acb_srcptr h, slong hlen, slong n, slong prec);
void acb_poly_sinc_series(acb_poly_t g, const acb_poly_t h, slong n, slong prec);
void _acb_poly_sinc_pi_series(acb_ptr g, acb_srcptr h, slong hlen, slong n, slong prec);
void acb_poly_sinc_pi_series(acb_poly_t g, const acb_poly_t h, slong n, slong prec);

void _acb_poly_lambertw_series(acb_ptr res, acb_srcptr z, slong zlen, const fmpz_t k, int flags, slong len, slong prec);
void acb_poly_lambertw_series(acb_poly_t res, const acb_poly_t z, const fmpz_t k, int flags, slong len, slong prec);
Expand Down
85 changes: 85 additions & 0 deletions src/acb_poly/sinc_pi_series.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright (C) 2016 Fredrik Johansson
Copyright (C) 2019 D.H.J. Polymath
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 "acb_poly.h"

void
_acb_poly_sinc_pi_series(acb_ptr g, acb_srcptr h, slong hlen, slong n, slong prec)
{
hlen = FLINT_MIN(hlen, n);

if (hlen == 1)
{
acb_sinc_pi(g, h, prec);
_acb_vec_zero(g + 1, n - 1);
}
else
{
acb_t pi;
acb_ptr t, u;

acb_init(pi);
t = _acb_vec_init(n + 1);
u = _acb_vec_init(hlen);

acb_const_pi(pi, prec);
_acb_vec_set(u, h, hlen);

if (acb_is_zero(h))
{
_acb_poly_sin_pi_series(t, u, hlen, n + 1, prec);
_acb_poly_div_series(g, t + 1, n, u + 1, hlen - 1, n, prec);
_acb_vec_scalar_div(g, g, n, pi, prec);
}
else if (acb_contains_zero(h))
{
_acb_vec_scalar_mul(u, h, hlen, pi, prec);
_acb_poly_sinc_series(g, u, hlen, n, prec);
}
else
{
_acb_poly_sin_pi_series(t, u, hlen, n, prec);
_acb_poly_div_series(g, t, n, u, hlen, n, prec);
_acb_vec_scalar_div(g, g, n, pi, prec);
}

acb_clear(pi);
_acb_vec_clear(t, n + 1);
_acb_vec_clear(u, hlen);
}
}

void
acb_poly_sinc_pi_series(acb_poly_t g, const acb_poly_t h, slong n, slong prec)
{
slong hlen = h->length;

if (n == 0)
{
acb_poly_zero(g);
return;
}

if (hlen == 0)
{
acb_poly_one(g);
return;
}

if (hlen == 1)
n = 1;

acb_poly_fit_length(g, n);
_acb_poly_sinc_pi_series(g->coeffs, h->coeffs, hlen, n, prec);
_acb_poly_set_length(g, n);
_acb_poly_normalise(g);
}
2 changes: 2 additions & 0 deletions src/acb_poly/test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include "t-sin_cos_pi_series.c"
#include "t-sin_cos_series.c"
#include "t-sinc_series.c"
#include "t-sinc_pi_series.c"
#include "t-sinh_cosh_series.c"
#include "t-sin_pi_series.c"
#include "t-sin_series_cos_series.c"
Expand Down Expand Up @@ -159,6 +160,7 @@ test_struct tests[] =
TEST_FUNCTION(acb_poly_sin_cos_pi_series),
TEST_FUNCTION(acb_poly_sin_cos_series),
TEST_FUNCTION(acb_poly_sinc_series),
TEST_FUNCTION(acb_poly_sinc_pi_series),
TEST_FUNCTION(acb_poly_sinh_cosh_series),
TEST_FUNCTION(acb_poly_sin_pi_series),
TEST_FUNCTION(acb_poly_sin_series_cos_series),
Expand Down
95 changes: 95 additions & 0 deletions src/acb_poly/test/t-sinc_pi_series.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copyright (C) 2012, 2013 Fredrik Johansson
Copyright (C) 2019 D.H.J. Polymath
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 "test_helpers.h"
#include "acb_poly.h"

TEST_FUNCTION_START(acb_poly_sinc_pi_series, state)
{
slong iter;

for (iter = 0; iter < 200 * 0.1 * flint_test_multiplier(); iter++)
{
slong m, n1, n2, rbits1, rbits2, rbits3, rbits4;
acb_poly_t a, b, c, d;
acb_t pi;

rbits1 = 2 + n_randint(state, 300);
rbits2 = 2 + n_randint(state, 300);
rbits3 = 2 + n_randint(state, 300);
rbits4 = 2 + n_randint(state, 300);

m = n_randint(state, 15);
n1 = n_randint(state, 15);
n2 = n_randint(state, 15);

acb_poly_init(a);
acb_poly_init(b);
acb_poly_init(c);
acb_poly_init(d);
acb_init(pi);

acb_poly_randtest(a, state, m, rbits1, 10);
acb_poly_randtest(b, state, 10, rbits1, 10);
acb_poly_randtest(c, state, 10, rbits1, 10);

acb_poly_sinc_pi_series(b, a, n1, rbits2);
acb_poly_sinc_pi_series(c, a, n2, rbits3);

acb_poly_set(d, b);
acb_poly_truncate(d, FLINT_MIN(n1, n2));
acb_poly_truncate(c, FLINT_MIN(n1, n2));

acb_const_pi(pi, rbits4);

if (!acb_poly_overlaps(c, d))
{
flint_printf("FAIL\n\n");
flint_printf("n1 = %wd, n2 = %wd, bits2 = %wd, bits3 = %wd, bits4 = %wd\n", n1, n2, rbits2, rbits3, rbits4);
flint_printf("a = "); acb_poly_printd(a, 50); flint_printf("\n\n");
flint_printf("b = "); acb_poly_printd(b, 50); flint_printf("\n\n");
flint_printf("c = "); acb_poly_printd(c, 50); flint_printf("\n\n");
flint_abort();
}

/* check pi x sinc_pi(x) = sin_pi(x) */
acb_poly_mullow(c, b, a, n1, rbits2);
acb_poly_scalar_mul(c, c, pi, rbits2);
acb_poly_sin_pi_series(d, a, n1, rbits2);

if (!acb_poly_overlaps(c, d))
{
flint_printf("FAIL (functional equation)\n\n");
flint_printf("a = "); acb_poly_printd(a, 15); flint_printf("\n\n");
flint_printf("b = "); acb_poly_printd(b, 15); flint_printf("\n\n");
flint_printf("c = "); acb_poly_printd(c, 15); flint_printf("\n\n");
flint_printf("d = "); acb_poly_printd(d, 15); flint_printf("\n\n");
flint_abort();
}

acb_poly_sinc_pi_series(a, a, n1, rbits2);

if (!acb_poly_overlaps(a, b))
{
flint_printf("FAIL (aliasing)\n\n");
flint_abort();
}

acb_poly_clear(a);
acb_poly_clear(b);
acb_poly_clear(c);
acb_poly_clear(d);
acb_clear(pi);
}

TEST_FUNCTION_END(state);
}
8 changes: 7 additions & 1 deletion src/arb_poly/sinc_pi_series.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ _arb_poly_sinc_pi_series(arb_ptr g, arb_srcptr h, slong hlen, slong n, slong pre
{
_arb_poly_sin_pi_series(t, u, hlen, n + 1, prec);
_arb_poly_div_series(g, t + 1, n, u + 1, hlen - 1, n, prec);
_arb_vec_scalar_div(g, g, n, pi, prec);
}
else if (arb_contains_zero(h))
{
_arb_vec_scalar_mul(u, h, hlen, pi, prec);
_arb_poly_sinc_series(g, u, hlen, n, prec);
}
else
{
_arb_poly_sin_pi_series(t, u, hlen, n, prec);
_arb_poly_div_series(g, t, n, u, hlen, n, prec);
_arb_vec_scalar_div(g, g, n, pi, prec);
}
_arb_vec_scalar_div(g, g, n, pi, prec);

arb_clear(pi);
_arb_vec_clear(t, n + 1);
Expand Down

0 comments on commit f0b28ad

Please sign in to comment.