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 <gmp.h>
15 #include "flint.h"
16 #include "fmpz.h"
17 #include "fmpz_vec.h"
18 #include "fmpz_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 < 1000 * flint_test_multiplier(); i++)
34     {
35         fmpz_mat_t A, B, AB, BA;
36         fmpz_t trab, trba;
37         slong m, n;
38 
39         m = n_randint(state, 10);
40         n = n_randint(state, 10);
41 
42         fmpz_mat_init(A, m, n);
43         fmpz_mat_init(B, n, m);
44         fmpz_mat_init(AB, m, m);
45         fmpz_mat_init(BA, n, n);
46 
47         fmpz_init(trab);
48         fmpz_init(trba);
49 
50         fmpz_mat_randtest(A, state, 1 + n_randint(state, 100));
51         fmpz_mat_randtest(B, state, 1 + n_randint(state, 100));
52 
53         fmpz_mat_mul(AB, A, B);
54         fmpz_mat_mul(BA, B, A);
55 
56         fmpz_mat_trace(trab, AB);
57         fmpz_mat_trace(trba, BA);
58 
59         if (!fmpz_equal(trab, trba))
60         {
61             flint_printf("FAIL:\n");
62             fmpz_mat_print_pretty(A), flint_printf("\n");
63             fmpz_mat_print_pretty(B), flint_printf("\n");
64             fmpz_mat_print_pretty(AB), flint_printf("\n");
65             fmpz_mat_print_pretty(BA), flint_printf("\n");
66             flint_printf("tr(AB): "),  fmpz_print(trab),    flint_printf("\n");
67             flint_printf("tr(BA): "),  fmpz_print(trba),    flint_printf("\n");
68             abort();
69         }
70 
71         fmpz_mat_clear(A);
72         fmpz_mat_clear(B);
73         fmpz_mat_clear(AB);
74         fmpz_mat_clear(BA);
75         fmpz_clear(trab);
76         fmpz_clear(trba);
77     }
78 
79     FLINT_TEST_CLEANUP(state);
80 
81     flint_printf("PASS\n");
82     return 0;
83 }
84