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 slong i;
26
27 FLINT_TEST_INIT(state);
28
29 flint_printf("solve_bound....");
30 fflush(stdout);
31
32 for (i = 0; i < 1000 * flint_test_multiplier(); i++)
33 {
34 fmpz_mat_t A, B, X;
35 fmpz_t N, D, den;
36 slong m, n, b1, b2;
37 slong j, k;
38
39 b1 = 1 + n_randint(state, 100);
40 b2 = 1 + n_randint(state, 100);
41 m = n_randint(state, 20);
42 n = n_randint(state, 20);
43
44 fmpz_init(den);
45 fmpz_init(N);
46 fmpz_init(D);
47 fmpz_mat_init(A, m, m);
48 fmpz_mat_init(B, m, n);
49 fmpz_mat_init(X, m, n);
50
51 fmpz_mat_randrank(A, state, m, b1);
52 fmpz_mat_randops(A, state, n_randint(state, m)*n_randint(state, m));
53 fmpz_mat_randtest(B, state, b2);
54
55 fmpz_mat_solve_bound(N, D, A, B);
56 fmpz_mat_solve(X, den, A, B);
57
58 if (fmpz_cmpabs(D, den) < 0)
59 {
60 flint_printf("FAIL:\n");
61 flint_printf("denominator bound:\n");
62 fmpz_print(D);
63 flint_printf("\ndenominator:\n");
64 fmpz_print(den);
65 flint_printf("\n");
66 flint_printf("A:\n");
67 fmpz_mat_print_pretty(A);
68 flint_printf("B:\n");
69 fmpz_mat_print_pretty(B);
70 flint_printf("\n");
71 abort();
72 }
73
74 for (j = 0; j < m; j++)
75 {
76 for (k = 0; k < n; k++)
77 {
78 if (fmpz_cmpabs(N, fmpz_mat_entry(X, j, k)) < 0)
79 {
80 flint_printf("FAIL:\n");
81 flint_printf("numerator bound:\n");
82 fmpz_print(N);
83 flint_printf("\nnumerator:\n");
84 fmpz_print(fmpz_mat_entry(X, j, k));
85 flint_printf("\n");
86 flint_printf("A:\n");
87 fmpz_mat_print_pretty(A);
88 flint_printf("B:\n");
89 fmpz_mat_print_pretty(B);
90 flint_printf("\n");
91 abort();
92 }
93 }
94 }
95
96 fmpz_mat_clear(A);
97 fmpz_mat_clear(B);
98 fmpz_mat_clear(X);
99
100 fmpz_clear(den);
101 fmpz_clear(N);
102 fmpz_clear(D);
103 }
104
105 FLINT_TEST_CLEANUP(state);
106
107 flint_printf("PASS\n");
108 return 0;
109 }
110