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 "flint.h"
15 #include "fmpz.h"
16 #include "fmpz_mat.h"
17 #include "fmpz_poly.h"
18 #include "fmpz_poly_mat.h"
19 
20 int
main(void)21 main(void)
22 {
23     slong i;
24 
25     FLINT_TEST_INIT(state);
26 
27     flint_printf("pow_trunc....");
28     fflush(stdout);
29 
30     /* Compare with pow */
31     for (i = 0; i < 100 * flint_test_multiplier(); i++)
32     {
33         fmpz_poly_mat_t A, B, C;
34         slong n, exp, bits, deg, len;
35 
36         n = n_randint(state, 10);
37         exp = n_randint(state, 15);
38         deg = 1 + n_randint(state, 10);
39         bits = 1 + n_randint(state, 100);
40         len = n_randint(state, 10);
41 
42         fmpz_poly_mat_init(A, n, n);
43         fmpz_poly_mat_init(B, n, n);
44         fmpz_poly_mat_init(C, n, n);
45 
46         fmpz_poly_mat_randtest(A, state, deg, bits);
47         fmpz_poly_mat_randtest(B, state, deg, bits);  /* noise in output */
48         fmpz_poly_mat_randtest(C, state, deg, bits);  /* noise in output */
49 
50         fmpz_poly_mat_pow_trunc(B, A, exp, len);
51         fmpz_poly_mat_pow(C, A, exp);
52         fmpz_poly_mat_truncate(C, len);
53 
54         if (!fmpz_poly_mat_equal(B, C))
55         {
56             flint_printf("FAIL:\n");
57             flint_printf("A:\n");
58             fmpz_poly_mat_print(A, "x");
59             flint_printf("B:\n");
60             fmpz_poly_mat_print(B, "x");
61             flint_printf("C:\n");
62             fmpz_poly_mat_print(C, "x");
63             flint_printf("\n");
64             abort();
65         }
66 
67         fmpz_poly_mat_clear(A);
68         fmpz_poly_mat_clear(B);
69         fmpz_poly_mat_clear(C);
70     }
71 
72     /* Check aliasing */
73     for (i = 0; i < 10 * flint_test_multiplier(); i++)
74     {
75         fmpz_poly_mat_t A, B;
76         slong n, exp, bits, deg, len;
77 
78         n = n_randint(state, 10);
79         exp = n_randint(state, 15);
80         deg = 1 + n_randint(state, 10);
81         bits = 1 + n_randint(state, 100);
82         len = n_randint(state, 10);
83 
84         fmpz_poly_mat_init(A, n, n);
85         fmpz_poly_mat_init(B, n, n);
86 
87         fmpz_poly_mat_randtest(A, state, deg, bits);
88         fmpz_poly_mat_randtest(B, state, deg, bits);
89 
90         fmpz_poly_mat_pow_trunc(B, A, exp, len);
91         fmpz_poly_mat_pow_trunc(A, A, exp, len);
92 
93         if (!fmpz_poly_mat_equal(B, A))
94         {
95             flint_printf("FAIL:\n");
96             flint_printf("A:\n");
97             fmpz_poly_mat_print(A, "x");
98             flint_printf("B:\n");
99             fmpz_poly_mat_print(B, "x");
100             flint_printf("\n");
101             abort();
102         }
103 
104         fmpz_poly_mat_clear(A);
105         fmpz_poly_mat_clear(B);
106     }
107 
108     FLINT_TEST_CLEANUP(state);
109 
110     flint_printf("PASS\n");
111     return 0;
112 }
113