-
Notifications
You must be signed in to change notification settings - Fork 0
/
F_mpzmod_mat.h
176 lines (113 loc) · 5.62 KB
/
F_mpzmod_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
/*============================================================================
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
===============================================================================*/
/*****************************************************************************
F_mpzmod_mat.h: Matrices over F_mpz's mod p, for p a multiprecision
prime (FLINT 2.0).
Only used for test code at this point - not optimised.
Copyright (C) 2008, William Hart
*****************************************************************************/
#ifndef FLINT_F_MPZMOD_MAT_H
#define FLINT_F_MPZMOD_MAT_H
#include <gmp.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "flint.h"
#include "memory-manager.h"
#include "F_mpz.h"
#include "zmod_poly.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
F_mpz * entries; // array containing the entries
F_mpz ** rows; // array of pointers to the rows (so rows can be swapped easily)
ulong r; // number of rows
ulong c; // number of cols
F_mpz p[1]; // modulus
} F_mpzmod_mat_struct;
typedef F_mpzmod_mat_struct F_mpzmod_mat_t[1];
/*******************************************************************************************
Initialisation and memory management
*******************************************************************************************/
void F_mpzmod_mat_init(F_mpzmod_mat_t mat, F_mpz_t p, ulong rows, ulong cols);
void F_mpzmod_mat_clear(F_mpzmod_mat_t mat);
/*******************************************************************************************
Arithmetic
*******************************************************************************************/
void F_mpzmod_mat_add(F_mpzmod_mat_t res, F_mpzmod_mat_t mat1, F_mpzmod_mat_t mat2);
void F_mpzmod_mat_sub(F_mpzmod_mat_t res, F_mpzmod_mat_t mat1, F_mpzmod_mat_t mat2);
void F_mpzmod_mat_neg(F_mpzmod_mat_t res, F_mpzmod_mat_t mat);
void F_mpzmod_mat_mul_classical(F_mpzmod_mat_t res, F_mpzmod_mat_t mat1, F_mpzmod_mat_t mat2);
/*******************************************************************************************
Conversions
*******************************************************************************************/
void F_zmod_poly_to_mpzmod_mat_row(F_mpzmod_mat_t mat, ulong row, zmod_poly_t poly);
void F_zmod_poly_to_mpzmod_mat_col(F_mpzmod_mat_t mat, ulong col, zmod_poly_t poly);
void F_mpzmod_mat_col_to_zmod_poly(zmod_poly_t poly, F_mpzmod_mat_t mat, ulong col);
void F_mpzmod_mat_col_to_zmod_poly_shifted(zmod_poly_t poly, F_mpzmod_mat_t mat, ulong col, ulong * shift);
/*******************************************************************************************
Set/get coefficients
*******************************************************************************************/
/*static inline
void F_mpzmod_mat_set_coeff_ui(F_mpzmod_mat_t mat, ulong row, ulong col, ulong val)
{
mat->arr[row][col] = val;
}
static inline
ulong F_mpzmod_mat_get_coeff_ui(F_mpzmod_mat_t mat, ulong row, ulong col)
{
return mat->arr[row][col];
}
static inline
ulong * F_mpzmod_mat_get_coeff_ptr(F_mpzmod_mat_t mat, ulong row, ulong col)
{
return mat->arr[row] + col;
}
*/
/*******************************************************************************************
Swap
*******************************************************************************************/
/*static inline
void F_mpzmod_mat_swap_rows(F_mpzmod_mat_t mat, ulong row1, ulong row2)
{
ulong * temp = mat->arr[row1];
mat->arr[row1] = mat->arr[row2];
mat->arr[row2] = temp;
}*/
/*******************************************************************************************
Elementary row operations
*******************************************************************************************/
void F_mpzmod_mat_row_scalar_addmul_right(F_mpzmod_mat_t mat, ulong row1, ulong row2, ulong u, ulong start);
void F_mpzmod_mat_row_scalar_submul_right(F_mpzmod_mat_t mat, ulong row1, ulong row2, ulong u, ulong start);
void F_mpzmod_mat_row_scalar_mul_right(F_mpzmod_mat_t mat, ulong row, ulong u, ulong start);
void F_zmod_vec_scalar_mul_range(ulong * r1, ulong * r2, ulong u, ulong p, double p_inv, ulong start, ulong end);
void F_zmod_vec_sub_range(ulong * r1, ulong * r2, ulong p, ulong start, ulong end);
/*******************************************************************************************
Row reduction
*******************************************************************************************/
ulong F_mpzmod_mat_row_reduce_gauss(F_mpzmod_mat_t mat);
ulong F_mpzmod_mat_row_reduce_gauss_small(F_mpzmod_mat_t mat);
ulong F_mpzmod_mat_row_reduce_gauss_jordan(F_mpzmod_mat_t mat);
/*******************************************************************************************
Input/output
*******************************************************************************************/
void F_mpzmod_mat_print(F_mpzmod_mat_t mat);
#ifdef __cplusplus
}
#endif
#endif /* FLINT_F_mpzmod_mat_H */