1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
Copyright (C) 2020 Fredrik Johansson
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "ca_mat.h"
#include "ca_poly.h"
void
ca_mat_adjugate_charpoly(ca_mat_t adj, ca_t det, const ca_mat_t A, ca_ctx_t ctx)
{
ca_poly_t pol;
slong n;
n = ca_mat_nrows(A);
if (n == 0)
{
ca_one(det, ctx);
return;
}
ca_poly_init(pol, ctx);
ca_mat_charpoly(pol, A, ctx);
ca_swap(det, ca_poly_coeff_ptr(pol, 0), ctx);
ca_poly_shift_right(pol, pol, 1, ctx);
ca_mat_ca_poly_evaluate(adj, pol, A, ctx);
if (n % 2)
ca_neg(det, det, ctx);
else
ca_mat_neg(adj, adj, ctx);
ca_poly_clear(pol, ctx);
}