2016-04-26 17:20:05 +02:00
|
|
|
/*
|
2014-06-19 15:43:48 +02:00
|
|
|
Copyright (C) 2013 Fredrik Johansson
|
|
|
|
|
2016-04-26 17:20:05 +02:00
|
|
|
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/>.
|
|
|
|
*/
|
2014-06-19 15:43:48 +02:00
|
|
|
|
|
|
|
#include "arb_calc.h"
|
|
|
|
|
|
|
|
/* sin((pi/2)x) */
|
|
|
|
static int
|
2015-11-05 17:56:52 +00:00
|
|
|
sin_pi2_x(arb_ptr out, const arb_t inp, void * params, slong order, slong prec)
|
2014-06-19 15:43:48 +02:00
|
|
|
{
|
|
|
|
arb_ptr x;
|
|
|
|
|
|
|
|
x = _arb_vec_init(2);
|
|
|
|
|
|
|
|
arb_set(x, inp);
|
|
|
|
arb_one(x + 1);
|
|
|
|
|
|
|
|
arb_const_pi(out, prec);
|
|
|
|
arb_mul_2exp_si(out, out, -1);
|
|
|
|
_arb_vec_scalar_mul(x, x, 2, out, prec);
|
|
|
|
_arb_poly_sin_series(out, x, order, order, prec);
|
|
|
|
|
|
|
|
_arb_vec_clear(x, 2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2015-11-05 17:56:52 +00:00
|
|
|
slong iter;
|
2014-06-19 15:43:48 +02:00
|
|
|
flint_rand_t state;
|
|
|
|
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("isolate_roots....");
|
2014-06-19 15:43:48 +02:00
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
flint_randinit(state);
|
|
|
|
|
2016-04-10 17:24:58 +02:00
|
|
|
for (iter = 0; iter < 40 * arb_test_multiplier(); iter++)
|
2014-06-19 15:43:48 +02:00
|
|
|
{
|
2015-11-05 17:56:52 +00:00
|
|
|
slong m, r, a, b, maxdepth, maxeval, maxfound, prec, i, j, num;
|
2014-06-19 15:43:48 +02:00
|
|
|
arf_interval_ptr blocks;
|
|
|
|
int * info;
|
|
|
|
arf_interval_t interval;
|
|
|
|
arb_t t;
|
|
|
|
fmpz_t nn;
|
|
|
|
|
|
|
|
prec = 2 + n_randint(state, 50);
|
|
|
|
|
|
|
|
m = n_randint(state, 80);
|
|
|
|
r = 1 + n_randint(state, 80);
|
|
|
|
a = m - r;
|
|
|
|
b = m + r;
|
|
|
|
|
|
|
|
maxdepth = 1 + n_randint(state, 60);
|
|
|
|
maxeval = 1 + n_randint(state, 5000);
|
|
|
|
maxfound = 1 + n_randint(state, 100);
|
|
|
|
|
|
|
|
arf_interval_init(interval);
|
|
|
|
arb_init(t);
|
|
|
|
fmpz_init(nn);
|
|
|
|
|
|
|
|
arf_set_si(&interval->a, a);
|
|
|
|
arf_set_si(&interval->b, b);
|
|
|
|
|
|
|
|
num = arb_calc_isolate_roots(&blocks, &info, sin_pi2_x, NULL,
|
|
|
|
interval, maxdepth, maxeval, maxfound, prec);
|
|
|
|
|
|
|
|
/* check that all roots are accounted for */
|
|
|
|
for (i = a; i <= b; i++)
|
|
|
|
{
|
|
|
|
if (i % 2 == 0)
|
|
|
|
{
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
for (j = 0; j < num; j++)
|
|
|
|
{
|
|
|
|
arf_interval_get_arb(t, blocks + j, ARF_PREC_EXACT);
|
|
|
|
|
|
|
|
if (arb_contains_si(t, i))
|
|
|
|
{
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("FAIL: missing root %wd\n", i);
|
|
|
|
flint_printf("a = %wd, b = %wd, maxdepth = %wd, maxeval = %wd, maxfound = %wd, prec = %wd\n",
|
2014-06-19 15:43:48 +02:00
|
|
|
a, b, maxdepth, maxeval, maxfound, prec);
|
|
|
|
|
|
|
|
for (j = 0; j < num; j++)
|
|
|
|
{
|
|
|
|
arf_interval_printd(blocks + j, 15);
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf(" %d \n", info[i]);
|
2014-06-19 15:43:48 +02:00
|
|
|
}
|
|
|
|
|
2017-02-28 16:50:03 +01:00
|
|
|
flint_abort();
|
2014-06-19 15:43:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check that all reported single roots are good */
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
if (info[i] == 1)
|
|
|
|
{
|
|
|
|
/* b contains unique 2n -> b/2 contains unique n */
|
|
|
|
arf_interval_get_arb(t, blocks + i, ARF_PREC_EXACT);
|
|
|
|
arb_mul_2exp_si(t, t, -1);
|
|
|
|
|
|
|
|
if (!arb_get_unique_fmpz(nn, t))
|
|
|
|
{
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("FAIL: bad root %wd\n", i);
|
|
|
|
flint_printf("a = %wd, b = %wd, maxdepth = %wd, maxeval = %wd, maxfound = %wd, prec = %wd\n",
|
2014-06-19 15:43:48 +02:00
|
|
|
a, b, maxdepth, maxeval, maxfound, prec);
|
|
|
|
|
|
|
|
for (j = 0; j < num; j++)
|
|
|
|
{
|
|
|
|
arf_interval_printd(blocks + j, 15);
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf(" %d \n", info[i]);
|
2014-06-19 15:43:48 +02:00
|
|
|
}
|
|
|
|
|
2017-02-28 16:50:03 +01:00
|
|
|
flint_abort();
|
2014-06-19 15:43:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_arf_interval_vec_clear(blocks, num);
|
|
|
|
flint_free(info);
|
|
|
|
|
|
|
|
arf_interval_clear(interval);
|
|
|
|
arb_clear(t);
|
|
|
|
fmpz_clear(nn);
|
|
|
|
}
|
|
|
|
|
|
|
|
flint_randclear(state);
|
|
|
|
flint_cleanup();
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("PASS\n");
|
2014-06-19 15:43:48 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|