forked from flintlib/flint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nmod_poly_mat.h
222 lines (144 loc) · 7.24 KB
/
nmod_poly_mat.h
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#ifndef NMOD_POLY_MAT_H
#define NMOD_POLY_MAT_H
#include <mpir.h>
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "nmod_mat.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Types *********************************************************************/
typedef struct
{
nmod_poly_struct * entries;
long r;
long c;
nmod_poly_struct ** rows;
mp_limb_t modulus;
} nmod_poly_mat_struct;
typedef nmod_poly_mat_struct nmod_poly_mat_t[1];
#define nmod_poly_mat_entry(mat,i,j) ((mat)->rows[(i)] + (j))
/* Memory management *********************************************************/
void nmod_poly_mat_init(nmod_poly_mat_t mat, long rows, long cols, mp_limb_t n);
void nmod_poly_mat_init_set(nmod_poly_mat_t mat, const nmod_poly_mat_t src);
void nmod_poly_mat_swap(nmod_poly_mat_t mat1, nmod_poly_mat_t mat2);
void nmod_poly_mat_set(nmod_poly_mat_t mat1, const nmod_poly_mat_t mat2);
void nmod_poly_mat_clear(nmod_poly_mat_t mat);
/* Basic properties **********************************************************/
static __inline__ long
nmod_poly_mat_nrows(const nmod_poly_mat_t mat)
{
return mat->r;
}
static __inline__ long
nmod_poly_mat_ncols(const nmod_poly_mat_t mat)
{
return mat->c;
}
static __inline__ mp_limb_t
nmod_poly_mat_modulus(const nmod_poly_mat_t mat)
{
return mat->modulus;
}
/* Comparison ****************************************************************/
int nmod_poly_mat_equal(const nmod_poly_mat_t mat1,
const nmod_poly_mat_t mat2);
int nmod_poly_mat_is_zero(const nmod_poly_mat_t mat);
int nmod_poly_mat_is_one(const nmod_poly_mat_t mat);
static __inline__ int
nmod_poly_mat_is_empty(const nmod_poly_mat_t mat)
{
return (mat->r == 0) || (mat->c == 0);
}
static __inline__ int
nmod_poly_mat_is_square(const nmod_poly_mat_t mat)
{
return (mat->r == mat->c);
}
/* Standard matrices *********************************************************/
void nmod_poly_mat_zero(nmod_poly_mat_t mat);
void nmod_poly_mat_one(nmod_poly_mat_t mat);
/* Random matrices ***********************************************************/
void nmod_poly_mat_randtest(nmod_poly_mat_t mat, flint_rand_t state,
long len);
void nmod_poly_mat_randtest_sparse(nmod_poly_mat_t A, flint_rand_t state,
long len, float density);
/* Input and output **********************************************************/
void nmod_poly_mat_print(const nmod_poly_mat_t mat, const char * x);
/* Norms *********************************************************************/
long nmod_poly_mat_max_length(const nmod_poly_mat_t A);
/* Scalar arithmetic *********************************************************/
void nmod_poly_mat_scalar_mul_nmod_poly(nmod_poly_mat_t B,
const nmod_poly_mat_t A, const nmod_poly_t c);
void nmod_poly_mat_scalar_mul_nmod(nmod_poly_mat_t B,
const nmod_poly_mat_t A, mp_limb_t c);
/* Matrix arithmetic *********************************************************/
void nmod_poly_mat_add(nmod_poly_mat_t C, const nmod_poly_mat_t A,
const nmod_poly_mat_t B);
void nmod_poly_mat_sub(nmod_poly_mat_t C, const nmod_poly_mat_t A,
const nmod_poly_mat_t B);
void nmod_poly_mat_neg(nmod_poly_mat_t B, const nmod_poly_mat_t A);
void nmod_poly_mat_mul(nmod_poly_mat_t C, const nmod_poly_mat_t A,
const nmod_poly_mat_t B);
void nmod_poly_mat_mul_classical(nmod_poly_mat_t C, const nmod_poly_mat_t A,
const nmod_poly_mat_t B);
void nmod_poly_mat_mul_KS(nmod_poly_mat_t C, const nmod_poly_mat_t A,
const nmod_poly_mat_t B);
void nmod_poly_mat_sqr(nmod_poly_mat_t B, const nmod_poly_mat_t A);
void nmod_poly_mat_sqr_classical(nmod_poly_mat_t B, const nmod_poly_mat_t A);
void nmod_poly_mat_sqr_KS(nmod_poly_mat_t B, const nmod_poly_mat_t A);
void nmod_poly_mat_pow(nmod_poly_mat_t B, const nmod_poly_mat_t A, ulong exp);
/* Evaluation ****************************************************************/
void nmod_poly_mat_evaluate_nmod(nmod_mat_t B, const nmod_poly_mat_t A, mp_limb_t x);
/* Row reduction *************************************************************/
long nmod_poly_mat_find_pivot_any(const nmod_poly_mat_t mat,
long start_row, long end_row, long c);
long nmod_poly_mat_find_pivot_partial(const nmod_poly_mat_t mat,
long start_row, long end_row, long c);
long nmod_poly_mat_fflu(nmod_poly_mat_t B, nmod_poly_t den, long * perm,
const nmod_poly_mat_t A, int rank_check);
long nmod_poly_mat_rref(nmod_poly_mat_t B, nmod_poly_t den, long * perm,
const nmod_poly_mat_t A);
/* Trace *********************************************************************/
void nmod_poly_mat_trace(nmod_poly_t trace, const nmod_poly_mat_t mat);
/* Determinant and rank ******************************************************/
void nmod_poly_mat_det(nmod_poly_t det, const nmod_poly_mat_t A);
void nmod_poly_mat_det_fflu(nmod_poly_t det, const nmod_poly_mat_t A);
void nmod_poly_mat_det_interpolate(nmod_poly_t det, const nmod_poly_mat_t A);
long nmod_poly_mat_rank(const nmod_poly_mat_t A);
/* Inverse *******************************************************************/
int nmod_poly_mat_inv(nmod_poly_mat_t Ainv, nmod_poly_t den,
const nmod_poly_mat_t A);
/* Nullspace *****************************************************************/
long nmod_poly_mat_nullspace(nmod_poly_mat_t res, const nmod_poly_mat_t mat);
/* Solving *******************************************************************/
int nmod_poly_mat_solve(nmod_poly_mat_t X, nmod_poly_t den,
const nmod_poly_mat_t A, const nmod_poly_mat_t B);
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);
void nmod_poly_mat_solve_fflu_precomp(nmod_poly_mat_t X,
const long * perm,
const nmod_poly_mat_t FFLU, const nmod_poly_mat_t B);
#ifdef __cplusplus
}
#endif
#endif