1 /*
2 Copyright (C) 2009 William Hart
3 Copyright (C) 2010 Sebastian Pancratz
4 Copyright (C) 2011 Fredrik Johansson
5
6 This file is part of FLINT.
7
8 FLINT is free software: you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License (LGPL) as published
10 by the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version. See <http://www.gnu.org/licenses/>.
12 */
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <gmp.h>
17 #include "flint.h"
18 #include "fmpz.h"
19 #include "fmpq_poly.h"
20 #include "ulong_extras.h"
21
22 int
main(void)23 main(void)
24 {
25 int i, result;
26 FLINT_TEST_INIT(state);
27
28 flint_printf("revert_series....");
29 fflush(stdout);
30
31
32
33 /* Check aliasing */
34 for (i = 0; i < 10 * flint_test_multiplier(); i++)
35 {
36 fmpq_poly_t f, g;
37 slong n;
38
39 fmpq_poly_init(f);
40 fmpq_poly_init(g);
41 do {
42 fmpq_poly_randtest(g, state, n_randint(state, 50), 1+n_randint(state,100));
43 } while (fmpq_poly_length(g) < 2 || fmpz_is_zero(g->coeffs + 1));
44 fmpq_poly_set_coeff_ui(g, 0, 0);
45 n = n_randint(state, 50);
46
47 fmpq_poly_revert_series(f, g, n);
48 fmpq_poly_revert_series(g, g, n);
49
50 result = (fmpq_poly_equal(f, g));
51 if (!result)
52 {
53 flint_printf("FAIL (aliasing):\n");
54 fmpq_poly_print(f), flint_printf("\n\n");
55 fmpq_poly_print(g), flint_printf("\n\n");
56 abort();
57 }
58
59 fmpq_poly_clear(f);
60 fmpq_poly_clear(g);
61 }
62
63 /* Check f(f^(-1)) = id */
64 for (i = 0; i < 10 * flint_test_multiplier(); i++)
65 {
66 fmpq_poly_t f, g, h;
67 slong n;
68
69 fmpq_poly_init(f);
70 fmpq_poly_init(g);
71 fmpq_poly_init(h);
72 do {
73 if (n_randint(state, 20) == 0)
74 fmpq_poly_randtest(g, state,
75 n_randint(state, 50), 1);
76 else
77 fmpq_poly_randtest(g, state,
78 n_randint(state, 50), 1+n_randint(state,100));
79 } while (fmpq_poly_length(g) < 2 || fmpz_is_zero(g->coeffs + 1));
80 fmpq_poly_set_coeff_ui(g, 0, 0);
81 n = n_randint(state, 50);
82
83 fmpq_poly_revert_series(f, g, n);
84 fmpq_poly_compose_series(h, g, f, n);
85
86 result = ((n <= 1 && fmpq_poly_is_zero(h)) ||
87 (h->length == 2 && fmpz_is_zero(h->coeffs + 0) &&
88 fmpz_is_one(h->coeffs + 1)));
89 if (!result)
90 {
91 flint_printf("FAIL (comparison):\n");
92 fmpq_poly_print(f), flint_printf("\n\n");
93 fmpq_poly_print(g), flint_printf("\n\n");
94 fmpq_poly_print(h), flint_printf("\n\n");
95 abort();
96 }
97
98 fmpq_poly_clear(f);
99 fmpq_poly_clear(g);
100 fmpq_poly_clear(h);
101 }
102
103 FLINT_TEST_CLEANUP(state);
104
105 flint_printf("PASS\n");
106 return 0;
107 }
108