1 /*
2     Copyright (C) 2011 Fredrik Johansson
3 
4     This file is part of FLINT.
5 
6     FLINT is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
10 */
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <gmp.h>
15 #include "flint.h"
16 #include "arith.h"
17 #include "fmpz.h"
18 #include "fmpz_poly.h"
19 
20 
main()21 int main()
22 {
23     fmpz_poly_t T0, T1, T2, t;
24     slong n;
25 
26     FLINT_TEST_INIT(state);
27 
28     flint_printf("chebyshev_t_polynomial....");
29     fflush(stdout);
30 
31     fmpz_poly_init(T0);
32     fmpz_poly_init(T1);
33     fmpz_poly_init(T2);
34     fmpz_poly_init(t);
35 
36     arith_chebyshev_t_polynomial(T0, 0);
37     arith_chebyshev_t_polynomial(T1, 1);
38 
39     for (n = 2; n <= 500; n++)
40     {
41         arith_chebyshev_t_polynomial(T2, n);
42 
43         /* Verify T_{n+1} = 2 x T_n - T_{n-1} */
44         fmpz_poly_scalar_mul_ui(t, T1, UWORD(2));
45         fmpz_poly_shift_left(t, t, 1);
46         fmpz_poly_sub(t, t, T0);
47 
48         if (!fmpz_poly_equal(t, T2))
49         {
50             flint_printf("FAIL: n = %wd\n", n);
51             flint_printf("t: "); fmpz_poly_print_pretty(t, "x"); flint_printf("\n");
52             flint_printf("T2: "); fmpz_poly_print_pretty(T2, "x"); flint_printf("\n");
53             abort();
54         }
55 
56         fmpz_poly_swap(T0, T1);
57         fmpz_poly_swap(T1, T2);
58     }
59 
60     fmpz_poly_clear(T0);
61     fmpz_poly_clear(T1);
62     fmpz_poly_clear(T2);
63     fmpz_poly_clear(t);
64 
65     FLINT_TEST_CLEANUP(state);
66     flint_printf("PASS\n");
67     return 0;
68 }
69