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_poly.h"
16 #include "fmpz_poly_mat.h"
17
18
19 int
main(void)20 main(void)
21 {
22 slong i;
23
24 FLINT_TEST_INIT(state);
25
26 flint_printf("solve_fflu....");
27 fflush(stdout);
28
29 for (i = 0; i < 200 * flint_test_multiplier(); i++)
30 {
31 fmpz_poly_mat_t A, X, B, AX, Bden;
32 fmpz_poly_t den, det;
33 slong n, m, bits, deg;
34 float density;
35 int solved;
36
37 n = n_randint(state, 15);
38 m = n_randint(state, 5);
39 deg = 1 + n_randint(state, 5);
40 bits = 1 + n_randint(state, 100);
41 density = n_randint(state, 100) * 0.01;
42
43 fmpz_poly_mat_init(A, n, n);
44 fmpz_poly_mat_init(B, n, m);
45 fmpz_poly_mat_init(X, n, m);
46 fmpz_poly_mat_init(AX, n, m);
47 fmpz_poly_mat_init(Bden, n, m);
48 fmpz_poly_init(den);
49 fmpz_poly_init(det);
50
51 fmpz_poly_mat_randtest_sparse(A, state, deg, bits, density);
52 fmpz_poly_mat_randtest_sparse(B, state, deg, bits, density);
53
54 solved = fmpz_poly_mat_solve_fflu(X, den, A, B);
55 fmpz_poly_mat_det_interpolate(det, A);
56
57 if (m == 0 || n == 0)
58 {
59 if (solved == 0)
60 {
61 flint_printf("FAIL: expected empty system to pass\n");
62 abort();
63 }
64 }
65 else
66 {
67 if (!fmpz_poly_equal(den, det))
68 {
69 fmpz_poly_neg(det, det);
70 flint_printf("FAIL: den != +/- det(A)\n");
71 flint_printf("den:\n"); fmpz_poly_print_pretty(den, "x");
72 flint_printf("\n\n");
73 flint_printf("det:\n"); fmpz_poly_print_pretty(det, "x");
74 flint_printf("\n\n");
75 flint_printf("A:\n");
76 fmpz_poly_mat_print(A, "x");
77 flint_printf("B:\n");
78 fmpz_poly_mat_print(B, "x");
79 flint_printf("X:\n");
80 fmpz_poly_mat_print(X, "x");
81 abort();
82 }
83 }
84
85 if (solved != !fmpz_poly_is_zero(den))
86 {
87 flint_printf("FAIL: return value does not match denominator\n");
88 abort();
89 }
90
91 fmpz_poly_mat_mul(AX, A, X);
92 fmpz_poly_mat_scalar_mul_fmpz_poly(Bden, B, den);
93
94 if (!fmpz_poly_mat_equal(AX, Bden))
95 {
96 flint_printf("FAIL:\n");
97 flint_printf("A:\n");
98 fmpz_poly_mat_print(A, "x");
99 flint_printf("B:\n");
100 fmpz_poly_mat_print(B, "x");
101 flint_printf("X:\n");
102 fmpz_poly_mat_print(X, "x");
103 flint_printf("AX:\n");
104 fmpz_poly_mat_print(AX, "x");
105 flint_printf("Bden:\n");
106 fmpz_poly_mat_print(Bden, "x");
107 abort();
108 }
109
110 fmpz_poly_clear(den);
111 fmpz_poly_clear(det);
112 fmpz_poly_mat_clear(A);
113 fmpz_poly_mat_clear(B);
114 fmpz_poly_mat_clear(X);
115 fmpz_poly_mat_clear(AX);
116 fmpz_poly_mat_clear(Bden);
117 }
118
119 FLINT_TEST_CLEANUP(state);
120
121 flint_printf("PASS\n");
122 return 0;
123 }
124