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 <https://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....");
28     fflush(stdout);
29 
30     for (i = 0; i < 100 * flint_test_multiplier(); i++)
31     {
32         fmpz_poly_mat_t A, B, C;
33         slong m, j, exp, bits, deg;
34 
35         m = n_randint(state, 6);
36         deg = 1 + n_randint(state, 6);
37         bits = 1 + n_randint(state, 100);
38         exp = n_randint(state, 20);
39 
40         fmpz_poly_mat_init(A, m, m);
41         fmpz_poly_mat_init(B, m, m);
42         fmpz_poly_mat_init(C, m, m);
43 
44         fmpz_poly_mat_randtest(A, state, deg, bits);
45 
46         fmpz_poly_mat_pow(B, A, exp);
47 
48         fmpz_poly_mat_one(C);
49         for (j = 0; j < exp; j++)
50             fmpz_poly_mat_mul(C, C, A);
51 
52         if (!fmpz_poly_mat_equal(C, B))
53         {
54             flint_printf("FAIL:\n");
55             flint_printf("exp = %wd\n", exp);
56             flint_printf("A:\n");
57             fmpz_poly_mat_print(A, "x");
58             flint_printf("B:\n");
59             fmpz_poly_mat_print(B, "x");
60             flint_printf("C:\n");
61             fmpz_poly_mat_print(C, "x");
62             flint_printf("\n");
63             abort();
64         }
65 
66         fmpz_poly_mat_clear(A);
67         fmpz_poly_mat_clear(B);
68         fmpz_poly_mat_clear(C);
69     }
70 
71     /* Check aliasing B and A */
72     for (i = 0; i < 100 * flint_test_multiplier(); i++)
73     {
74         fmpz_poly_mat_t A, B;
75         slong m, exp, bits, deg;
76 
77         m = n_randint(state, 6);
78         deg = 1 + n_randint(state, 6);
79         bits = 1 + n_randint(state, 100);
80         exp = n_randint(state, 20);
81 
82         fmpz_poly_mat_init(A, m, m);
83         fmpz_poly_mat_init(B, m, m);
84 
85         fmpz_poly_mat_randtest(A, state, deg, bits);
86 
87         fmpz_poly_mat_pow(B, A, exp);
88         fmpz_poly_mat_pow(A, A, exp);
89 
90         if (!fmpz_poly_mat_equal(A, B))
91         {
92             flint_printf("FAIL (aliasing)\n");
93             flint_printf("exp = %wd\n", exp);
94             flint_printf("A:\n");
95             fmpz_poly_mat_print(A, "x");
96             flint_printf("B:\n");
97             fmpz_poly_mat_print(B, "x");
98             flint_printf("\n");
99             abort();
100         }
101 
102         fmpz_poly_mat_clear(A);
103         fmpz_poly_mat_clear(B);
104     }
105 
106     FLINT_TEST_CLEANUP(state);
107 
108     flint_printf("PASS\n");
109     return 0;
110 }
111