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 <stdlib.h>
13 #include "flint.h"
14 #include "fmpz_poly.h"
15 #include "fmpz_poly_mat.h"
16 
17 void
fmpz_poly_mat_det_interpolate(fmpz_poly_t det,const fmpz_poly_mat_t A)18 fmpz_poly_mat_det_interpolate(fmpz_poly_t det, const fmpz_poly_mat_t A)
19 {
20     slong i, l, n, len;
21 
22     fmpz_mat_t X;
23     fmpz * x;
24     fmpz * d;
25 
26     n = A->r;
27 
28     if (n == 0)
29     {
30         fmpz_poly_one(det);
31         return;
32     }
33 
34     l = fmpz_poly_mat_max_length(A);
35 
36     if (l == 0)
37     {
38         fmpz_poly_zero(det);
39         return;
40     }
41 
42     /* Bound degree based on Laplace expansion */
43     len = n*(l - 1) + 1;
44 
45     x = _fmpz_vec_init(len);
46     d = _fmpz_vec_init(len);
47     fmpz_mat_init(X, n, n);
48 
49     for (i = 0; i < len; i++)
50     {
51         fmpz_set_si(x + i, -len/2 + i);
52         fmpz_poly_mat_evaluate_fmpz(X, A, x + i);
53         fmpz_mat_det(d + i, X);
54     }
55 
56     fmpz_poly_interpolate_fmpz_vec(det, x, d, len);
57 
58     _fmpz_vec_clear(x, len);
59     _fmpz_vec_clear(d, len);
60     fmpz_mat_clear(X);
61 }
62