arb/arb_poly/test/t-graeffe_transform.c
Matthias Gessinger c22f6a87bb Write tests for real and complex graeffe_transform
Create polynomials from a set of roots.
Square these roots to compute the expected output.
2021-07-27 14:12:42 +02:00

86 lines
2.3 KiB
C

/*
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"
int main()
{
slong iter;
flint_rand_t state;
flint_printf("graeffe_transform....");
fflush(stdout);
flint_randinit(state);
arb_poly_t a, b, c;
arb_poly_init(a);
arb_poly_init(b);
arb_poly_init(c);
arb_ptr roots;
for (iter = 0; iter < 500 * arb_test_multiplier(); iter++)
{
slong n, prec, i;
n = n_randint(state, 200);
prec = 2 + n_randint(state, 200);
roots = _arb_vec_init(n);
for (i = 0; i < n; i++)
arb_randtest(roots+i, state, prec, n_randint(state, 10));
arb_poly_product_roots(a, roots, n, prec);
for (i = 0; i < n; i++)
arb_sqr(roots+i, roots+i, prec);
arb_poly_product_roots(c, roots, n, prec);
arb_poly_graeffe_transform(b, a, prec);
if (!arb_poly_overlaps(b, c))
{
flint_printf("FAIL (containment)\n\n");
flint_printf("n = %wd, prec = %wd\n\n", n, prec);
flint_printf("a: "); arb_poly_printd(a, 15); flint_printf("\n\n");
flint_printf("b: "); arb_poly_printd(b, 15); flint_printf("\n\n");
flint_printf("c: "); arb_poly_printd(c, 15); flint_printf("\n\n");
flint_abort();
}
arb_poly_graeffe_transform(a, a, prec);
if (!arb_poly_equal(a, b))
{
flint_printf("FAIL (aliasing)\n\n");
flint_printf("n = %wd, prec = %wd\n\n", n, prec);
flint_printf("a: "); arb_poly_printd(a, 15); flint_printf("\n\n");
flint_printf("b: "); arb_poly_printd(b, 15); flint_printf("\n\n");
flint_printf("c: "); arb_poly_printd(c, 15); flint_printf("\n\n");
flint_abort();
}
_arb_vec_clear(roots, n);
}
arb_poly_clear(a);
arb_poly_clear(b);
arb_poly_clear(c);
flint_randclear(state);
flint_cleanup();
flint_printf("PASS\n");
return EXIT_SUCCESS;
}