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 "fmpz.h"
17 #include "fmpz_poly.h"
18 #include "fmpz_poly_mat.h"
19 #include "ulong_extras.h"
20
21 int
main(void)22 main(void)
23 {
24 slong i;
25 FLINT_TEST_INIT(state);
26
27 flint_printf("trace....");
28 fflush(stdout);
29
30
31
32 /* Test trace(AB) = trace(BA) */
33 for (i = 0; i < 100 * flint_test_multiplier(); i++)
34 {
35 fmpz_poly_mat_t A, B, AB, BA;
36 fmpz_poly_t trab, trba;
37 slong m, n;
38
39 m = n_randint(state, 10);
40 n = n_randint(state, 10);
41
42 fmpz_poly_mat_init(A, m, n);
43 fmpz_poly_mat_init(B, n, m);
44 fmpz_poly_mat_init(AB, m, m);
45 fmpz_poly_mat_init(BA, n, n);
46
47 fmpz_poly_init(trab);
48 fmpz_poly_init(trba);
49
50 fmpz_poly_mat_randtest(A, state, 1 + n_randint(state, 10),
51 1 + n_randint(state, 100));
52 fmpz_poly_mat_randtest(B, state, 1 + n_randint(state, 10),
53 1 + n_randint(state, 100));
54
55 fmpz_poly_mat_mul(AB, A, B);
56 fmpz_poly_mat_mul(BA, B, A);
57
58 fmpz_poly_mat_trace(trab, AB);
59 fmpz_poly_mat_trace(trba, BA);
60
61 if (!fmpz_poly_equal(trab, trba))
62 {
63 flint_printf("FAIL:\n");
64 fmpz_poly_mat_print(A, "x"), flint_printf("\n");
65 fmpz_poly_mat_print(B, "x"), flint_printf("\n");
66 fmpz_poly_mat_print(AB, "x"), flint_printf("\n");
67 fmpz_poly_mat_print(BA, "x"), flint_printf("\n");
68 flint_printf("tr(AB): "), fmpz_poly_print(trab), flint_printf("\n");
69 flint_printf("tr(BA): "), fmpz_poly_print(trba), flint_printf("\n");
70 abort();
71 }
72
73 fmpz_poly_mat_clear(A);
74 fmpz_poly_mat_clear(B);
75 fmpz_poly_mat_clear(AB);
76 fmpz_poly_mat_clear(BA);
77 fmpz_poly_clear(trab);
78 fmpz_poly_clear(trba);
79 }
80
81 FLINT_TEST_CLEANUP(state);
82
83 flint_printf("PASS\n");
84 return 0;
85 }
86