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 "flint.h"
13 #include "nmod_poly.h"
14 #include "nmod_poly_mat.h"
15 #include "perm.h"
16
17 int
nmod_poly_mat_solve_fflu(nmod_poly_mat_t X,nmod_poly_t den,const nmod_poly_mat_t A,const nmod_poly_mat_t B)18 nmod_poly_mat_solve_fflu(nmod_poly_mat_t X, nmod_poly_t den,
19 const nmod_poly_mat_t A, const nmod_poly_mat_t B)
20 {
21 nmod_poly_mat_t LU;
22 slong dim, *perm;
23 int result;
24
25 if (nmod_poly_mat_is_empty(B))
26 {
27 nmod_poly_one(den);
28 return 1;
29 }
30
31 dim = nmod_poly_mat_nrows(A);
32 perm = _perm_init(dim);
33 nmod_poly_mat_init_set(LU, A);
34 result = (nmod_poly_mat_fflu(LU, den, perm, LU, 1) == dim);
35
36 if (result)
37 {
38 nmod_poly_mat_solve_fflu_precomp(X, perm, LU, B);
39
40 if (_perm_parity(perm, dim))
41 {
42 nmod_poly_neg(den, den);
43
44 nmod_poly_mat_neg(X, X);
45 }
46 } else
47 nmod_poly_zero(den);
48
49 _perm_clear(perm);
50 nmod_poly_mat_clear(LU);
51 return result;
52 }
53