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_mul_classical(fmpz_poly_mat_t C,const fmpz_poly_mat_t A,const fmpz_poly_mat_t B)18 fmpz_poly_mat_mul_classical(fmpz_poly_mat_t C, const fmpz_poly_mat_t A,
19 const fmpz_poly_mat_t B)
20 {
21 slong ar, bc, br;
22 slong i, j, k;
23 fmpz_poly_t t;
24
25 ar = A->r;
26 br = B->r;
27 bc = B->c;
28
29 if (br == 0)
30 {
31 fmpz_poly_mat_zero(C);
32 return;
33 }
34
35 if (C == A || C == B)
36 {
37 fmpz_poly_mat_t T;
38 fmpz_poly_mat_init(T, ar, bc);
39 fmpz_poly_mat_mul_classical(T, A, B);
40 fmpz_poly_mat_swap(C, T);
41 fmpz_poly_mat_clear(T);
42 return;
43 }
44
45 fmpz_poly_init(t);
46
47 for (i = 0; i < ar; i++)
48 {
49 for (j = 0; j < bc; j++)
50 {
51 fmpz_poly_mul(fmpz_poly_mat_entry(C, i, j),
52 fmpz_poly_mat_entry(A, i, 0),
53 fmpz_poly_mat_entry(B, 0, j));
54
55 for (k = 1; k < br; k++)
56 {
57 fmpz_poly_mul(t, fmpz_poly_mat_entry(A, i, k),
58 fmpz_poly_mat_entry(B, k, j));
59
60 fmpz_poly_add(fmpz_poly_mat_entry(C, i, j),
61 fmpz_poly_mat_entry(C, i, j), t);
62 }
63 }
64 }
65
66 fmpz_poly_clear(t);
67 }
68