forked from flintlib/flint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmpq_mat.h
202 lines (125 loc) · 6.54 KB
/
fmpq_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
/*=============================================================================
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 FMPQ_MAT_H
#define FMPQ_MAT_H
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_mat.h"
#include "fmpq.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
fmpq * entries;
slong r;
slong c;
fmpq ** rows;
} fmpq_mat_struct;
typedef fmpq_mat_struct fmpq_mat_t[1];
#define fmpq_mat_entry(mat,i,j) ((mat)->rows[(i)] + (j))
#define fmpq_mat_entry_num(mat,i,j) ((fmpz *)(&((*fmpq_mat_entry(mat,i,j)).num)))
#define fmpq_mat_entry_den(mat,i,j) ((fmpz *)(&((*fmpq_mat_entry(mat,i,j)).den)))
#define fmpq_mat_nrows(mat) ((mat)->r)
#define fmpq_mat_ncols(mat) ((mat)->c)
FLINT_DLL void fmpq_mat_init(fmpq_mat_t mat, slong rows, slong cols);
FLINT_DLL void fmpq_mat_clear(fmpq_mat_t mat);
FLINT_DLL void fmpq_mat_swap(fmpq_mat_t mat1, fmpq_mat_t mat2);
FLINT_DLL void fmpq_mat_print(const fmpq_mat_t mat);
/* Random matrix generation **************************************************/
FLINT_DLL void fmpq_mat_randbits(fmpq_mat_t mat, flint_rand_t state, mp_bitcnt_t bits);
FLINT_DLL void fmpq_mat_randtest(fmpq_mat_t mat, flint_rand_t state, mp_bitcnt_t bits);
/* Special matrices **********************************************************/
FLINT_DLL void fmpq_mat_hilbert_matrix(fmpq_mat_t mat);
/* Basic assignment **********************************************************/
FLINT_DLL void fmpq_mat_set(fmpq_mat_t dest, const fmpq_mat_t src);
FLINT_DLL void fmpq_mat_zero(fmpq_mat_t mat);
FLINT_DLL void fmpq_mat_one(fmpq_mat_t mat);
FLINT_DLL void fmpq_mat_transpose(fmpq_mat_t rop, const fmpq_mat_t op);
/* Addition, scalar multiplication ******************************************/
FLINT_DLL void fmpq_mat_add(fmpq_mat_t mat, const fmpq_mat_t mat1, const fmpq_mat_t mat2);
FLINT_DLL void fmpq_mat_sub(fmpq_mat_t mat, const fmpq_mat_t mat1, const fmpq_mat_t mat2);
FLINT_DLL void fmpq_mat_neg(fmpq_mat_t rop, const fmpq_mat_t op);
FLINT_DLL void fmpq_mat_scalar_mul_fmpz(fmpq_mat_t rop, const fmpq_mat_t op, const fmpz_t x);
FLINT_DLL void fmpq_mat_scalar_div_fmpz(fmpq_mat_t rop, const fmpq_mat_t op, const fmpz_t x);
/* Basic comparison and properties *******************************************/
FLINT_DLL int fmpq_mat_equal(const fmpq_mat_t mat1, const fmpq_mat_t mat2);
FLINT_DLL int fmpq_mat_is_integral(const fmpq_mat_t mat);
FLINT_DLL int fmpq_mat_is_zero(const fmpq_mat_t mat);
static __inline__ int
fmpq_mat_is_empty(const fmpq_mat_t mat)
{
return (mat->r == 0) || (mat->c == 0);
}
static __inline__ int
fmpq_mat_is_square(const fmpq_mat_t mat)
{
return (mat->r == mat->c);
}
/* Integer matrix conversion *************************************************/
FLINT_DLL int fmpq_mat_get_fmpz_mat(fmpz_mat_t dest, const fmpq_mat_t mat);
FLINT_DLL void fmpq_mat_get_fmpz_mat_entrywise(fmpz_mat_t num, fmpz_mat_t den,
const fmpq_mat_t mat);
FLINT_DLL void fmpq_mat_get_fmpz_mat_matwise(fmpz_mat_t num, fmpz_t den,
const fmpq_mat_t mat);
FLINT_DLL void fmpq_mat_get_fmpz_mat_rowwise(fmpz_mat_t num, fmpz * den,
const fmpq_mat_t mat);
FLINT_DLL void fmpq_mat_get_fmpz_mat_colwise(fmpz_mat_t num, fmpz * den,
const fmpq_mat_t mat);
FLINT_DLL void fmpq_mat_get_fmpz_mat_rowwise_2(fmpz_mat_t num, fmpz_mat_t num2,
fmpz * den, const fmpq_mat_t mat, const fmpq_mat_t mat2);
FLINT_DLL void fmpq_mat_get_fmpz_mat_mod_fmpz(fmpz_mat_t dest, const fmpq_mat_t mat,
const fmpz_t mod);
FLINT_DLL void fmpq_mat_set_fmpz_mat(fmpq_mat_t dest, const fmpz_mat_t src);
FLINT_DLL void fmpq_mat_set_fmpz_mat_div_fmpz(fmpq_mat_t X, const fmpz_mat_t Xmod,
const fmpz_t div);
FLINT_DLL int fmpq_mat_set_fmpz_mat_mod_fmpz(fmpq_mat_t X, const fmpz_mat_t Xmod,
const fmpz_t mod);
/* Matrix multiplication *****************************************************/
FLINT_DLL void fmpq_mat_mul_direct(fmpq_mat_t C, const fmpq_mat_t A, const fmpq_mat_t B);
FLINT_DLL void fmpq_mat_mul_cleared(fmpq_mat_t C, const fmpq_mat_t A,
const fmpq_mat_t B);
FLINT_DLL void fmpq_mat_mul(fmpq_mat_t C, const fmpq_mat_t A, const fmpq_mat_t B);
FLINT_DLL void fmpq_mat_mul_fmpz_mat(fmpq_mat_t C, const fmpq_mat_t A,
const fmpz_mat_t B);
FLINT_DLL void fmpq_mat_mul_r_fmpz_mat(fmpq_mat_t C, const fmpz_mat_t A,
const fmpq_mat_t B);
/* Trace *********************************************************************/
FLINT_DLL void fmpq_mat_trace(fmpq_t trace, const fmpq_mat_t mat);
/* Determinant ***************************************************************/
FLINT_DLL void fmpq_mat_det(fmpq_t det, const fmpq_mat_t mat);
/* Nonsingular solving *******************************************************/
FLINT_DLL int fmpq_mat_solve_fraction_free(fmpq_mat_t X, const fmpq_mat_t A,
const fmpq_mat_t B);
FLINT_DLL int fmpq_mat_solve_dixon(fmpq_mat_t X, const fmpq_mat_t A, const fmpq_mat_t B);
int fmpq_mat_solve_fmpz_mat(fmpq_mat_t X, const fmpz_mat_t A,
const fmpz_mat_t B);
/* Inverse *******************************************************************/
FLINT_DLL int fmpq_mat_inv(fmpq_mat_t B, const fmpq_mat_t A);
/* Echelon form **************************************************************/
FLINT_DLL int fmpq_mat_pivot(slong * perm, fmpq_mat_t mat, slong r, slong c);
FLINT_DLL slong fmpq_mat_rref_classical(fmpq_mat_t B, const fmpq_mat_t A);
FLINT_DLL slong fmpq_mat_rref_fraction_free(fmpq_mat_t B, const fmpq_mat_t A);
FLINT_DLL slong fmpq_mat_rref(fmpq_mat_t B, const fmpq_mat_t A);
/* Gram-Schmidt Orthogonalisation *******************************************/
FLINT_DLL void fmpq_mat_gso(fmpq_mat_t B, const fmpq_mat_t A);
#ifdef __cplusplus
}
#endif
#endif