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 
22 int
main(void)23 main(void)
24 {
25     fmpz_mat_t A;
26     slong i, m;
27 
28     fmpz_t det1, det2;
29 
30     FLINT_TEST_INIT(state);
31 
32     flint_printf("det_modular....");
33     fflush(stdout);
34 
35     for (i = 0; i < 1000 * flint_test_multiplier(); i++)
36     {
37         int proved = n_randlimb(state) % 2;
38         m = n_randint(state, 10);
39 
40         fmpz_mat_init(A, m, m);
41 
42         fmpz_init(det1);
43         fmpz_init(det2);
44 
45         fmpz_mat_randtest(A, state, 1+n_randint(state,200));
46 
47         fmpz_mat_det_bareiss(det1, A);
48         fmpz_mat_det_modular(det2, A, proved);
49 
50         if (!fmpz_equal(det1, det2))
51         {
52             flint_printf("FAIL:\n");
53             flint_printf("different determinants!\n");
54             fmpz_mat_print_pretty(A), flint_printf("\n");
55             flint_printf("det1: "), fmpz_print(det1), flint_printf("\n");
56             flint_printf("det2: "), fmpz_print(det2), flint_printf("\n");
57             abort();
58         }
59 
60         fmpz_clear(det1);
61         fmpz_clear(det2);
62         fmpz_mat_clear(A);
63     }
64 
65     for (i = 0; i < 10000; i++)
66     {
67         int proved = n_randlimb(state) % 2;
68         m = 2 + n_randint(state, 10);
69         fmpz_mat_init(A, m, m);
70         fmpz_init(det2);
71 
72         fmpz_mat_randrank(A, state, 1+n_randint(state, m - 1),
73                                     1+n_randint(state, 10));
74         fmpz_mat_randops(A, state, n_randint(state, 2*m*m + 1));
75 
76         fmpz_mat_det_modular(det2, A, proved);
77         if (!fmpz_is_zero(det2))
78         {
79             flint_printf("FAIL:\n");
80             flint_printf("expected zero determinant!\n");
81             fmpz_mat_print_pretty(A), flint_printf("\n");
82             abort();
83         }
84 
85         fmpz_mat_clear(A);
86         fmpz_clear(det2);
87     }
88 
89     FLINT_TEST_CLEANUP(state);
90 
91     flint_printf("PASS\n");
92     return 0;
93 }
94