1 | |
---|
2 | #ifndef NTL_mat_GF2__H |
---|
3 | #define NTL_mat_GF2__H |
---|
4 | |
---|
5 | |
---|
6 | #include <NTL/vec_vec_GF2.h> |
---|
7 | |
---|
8 | NTL_OPEN_NNS |
---|
9 | |
---|
10 | |
---|
11 | class mat_GF2 { |
---|
12 | public: |
---|
13 | |
---|
14 | vec_vec_GF2 _mat_GF2__rep; |
---|
15 | long _mat_GF2__numcols; |
---|
16 | |
---|
17 | mat_GF2() { _mat_GF2__numcols = 0; } |
---|
18 | mat_GF2(const mat_GF2& a); |
---|
19 | mat_GF2& operator=(const mat_GF2& a); |
---|
20 | ~mat_GF2() { } |
---|
21 | |
---|
22 | mat_GF2(INIT_SIZE_TYPE, long n, long m); |
---|
23 | |
---|
24 | void kill(); |
---|
25 | |
---|
26 | void SetDims(long n, long m); |
---|
27 | |
---|
28 | long NumRows() const { return _mat_GF2__rep.length(); } |
---|
29 | long NumCols() const { return _mat_GF2__numcols; } |
---|
30 | |
---|
31 | vec_GF2& operator[](long i) { return _mat_GF2__rep[i]; } |
---|
32 | const vec_GF2& operator[](long i) const { return _mat_GF2__rep[i]; } |
---|
33 | |
---|
34 | vec_GF2& operator()(long i) { return _mat_GF2__rep[i-1]; } |
---|
35 | const vec_GF2& operator()(long i) const { return _mat_GF2__rep[i-1]; } |
---|
36 | |
---|
37 | GF2 get(long i, long j) const { return _mat_GF2__rep[i].get(j); } |
---|
38 | void put(long i, long j, GF2 a) { _mat_GF2__rep[i].put(j, a); } |
---|
39 | void put(long i, long j, long a) { _mat_GF2__rep[i].put(j, a); } |
---|
40 | |
---|
41 | subscript_GF2 operator()(long i, long j) |
---|
42 | { return subscript_GF2(_mat_GF2__rep[i-1], j-1); } |
---|
43 | |
---|
44 | const_subscript_GF2 operator()(long i, long j) const |
---|
45 | { return const_subscript_GF2(_mat_GF2__rep[i-1], j-1); } |
---|
46 | |
---|
47 | long position(const vec_GF2& a) const { return _mat_GF2__rep.position(a); } |
---|
48 | |
---|
49 | mat_GF2(mat_GF2& x, INIT_TRANS_TYPE) : |
---|
50 | _mat_GF2__rep(x._mat_GF2__rep, INIT_TRANS), _mat_GF2__numcols(x._mat_GF2__numcols) { } |
---|
51 | }; |
---|
52 | |
---|
53 | inline const vec_vec_GF2& _mat_GF2__rep(const mat_GF2& a) |
---|
54 | { return a._mat_GF2__rep; } |
---|
55 | |
---|
56 | |
---|
57 | void swap(mat_GF2& X, mat_GF2& Y); |
---|
58 | |
---|
59 | void conv(mat_GF2& x, const vec_vec_GF2& a); |
---|
60 | inline mat_GF2 to_mat_GF2(const vec_vec_GF2& a) |
---|
61 | { mat_GF2 x; conv(x, a); NTL_OPT_RETURN(mat_GF2, x); } |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | long operator==(const mat_GF2& a, const mat_GF2& b); |
---|
66 | long operator!=(const mat_GF2& a, const mat_GF2& b); |
---|
67 | |
---|
68 | void add(mat_GF2& X, const mat_GF2& A, const mat_GF2& B); |
---|
69 | |
---|
70 | inline void sub(mat_GF2& X, const mat_GF2& A, const mat_GF2& B) |
---|
71 | { add(X, A, B); } |
---|
72 | |
---|
73 | inline void negate(mat_GF2& X, const mat_GF2& A) |
---|
74 | { X = A; } |
---|
75 | |
---|
76 | void mul(mat_GF2& X, const mat_GF2& A, const mat_GF2& B); |
---|
77 | void mul(vec_GF2& x, const mat_GF2& A, const vec_GF2& b); |
---|
78 | void mul(vec_GF2& x, const vec_GF2& a, const mat_GF2& B); |
---|
79 | |
---|
80 | void mul(mat_GF2& X, const mat_GF2& A, GF2 b); |
---|
81 | inline void mul(mat_GF2& X, GF2 a, const mat_GF2& B) |
---|
82 | { mul(X, B, a); } |
---|
83 | |
---|
84 | inline void mul(mat_GF2& X, const mat_GF2& A, long b) |
---|
85 | { mul(X, A, to_GF2(b)); } |
---|
86 | inline void mul(mat_GF2& X, long a, const mat_GF2& B) |
---|
87 | { mul(X, B, a); } |
---|
88 | |
---|
89 | void ident(mat_GF2& X, long n); |
---|
90 | inline mat_GF2 ident_mat_GF2(long n) |
---|
91 | { mat_GF2 X; ident(X, n); NTL_OPT_RETURN(mat_GF2, X); } |
---|
92 | |
---|
93 | long IsIdent(const mat_GF2& A, long n); |
---|
94 | void transpose(mat_GF2& X, const mat_GF2& A); |
---|
95 | void solve(GF2& d, vec_GF2& X, const mat_GF2& A, const vec_GF2& b); |
---|
96 | void inv(GF2& d, mat_GF2& X, const mat_GF2& A); |
---|
97 | |
---|
98 | inline void sqr(mat_GF2& X, const mat_GF2& A) |
---|
99 | { mul(X, A, A); } |
---|
100 | |
---|
101 | inline mat_GF2 sqr(const mat_GF2& A) |
---|
102 | { mat_GF2 X; sqr(X, A); NTL_OPT_RETURN(mat_GF2, X); } |
---|
103 | |
---|
104 | void inv(mat_GF2& X, const mat_GF2& A); |
---|
105 | |
---|
106 | inline mat_GF2 inv(const mat_GF2& A) |
---|
107 | { mat_GF2 X; inv(X, A); NTL_OPT_RETURN(mat_GF2, X); } |
---|
108 | |
---|
109 | void power(mat_GF2& X, const mat_GF2& A, const ZZ& e); |
---|
110 | inline mat_GF2 power(const mat_GF2& A, const ZZ& e) |
---|
111 | { mat_GF2 X; power(X, A, e); NTL_OPT_RETURN(mat_GF2, X); } |
---|
112 | |
---|
113 | inline void power(mat_GF2& X, const mat_GF2& A, long e) |
---|
114 | { power(X, A, ZZ_expo(e)); } |
---|
115 | inline mat_GF2 power(const mat_GF2& A, long e) |
---|
116 | { mat_GF2 X; power(X, A, e); NTL_OPT_RETURN(mat_GF2, X); } |
---|
117 | |
---|
118 | |
---|
119 | void diag(mat_GF2& X, long n, GF2 d); |
---|
120 | inline mat_GF2 diag(long n, GF2 d) |
---|
121 | { mat_GF2 X; diag(X, n, d); NTL_OPT_RETURN(mat_GF2, X); } |
---|
122 | |
---|
123 | long IsDiag(const mat_GF2& A, long n, GF2 d); |
---|
124 | |
---|
125 | |
---|
126 | long gauss(mat_GF2& M); |
---|
127 | long gauss(mat_GF2& M, long w); |
---|
128 | void image(mat_GF2& X, const mat_GF2& A); |
---|
129 | void kernel(mat_GF2& X, const mat_GF2& A); |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | |
---|
134 | void determinant(GF2& x, const mat_GF2& a); |
---|
135 | inline GF2 determinant(const mat_GF2& a) |
---|
136 | { GF2 x; determinant(x, a); return x; } |
---|
137 | |
---|
138 | inline mat_GF2 transpose(const mat_GF2 & a) |
---|
139 | { mat_GF2 x; transpose(x, a); NTL_OPT_RETURN(mat_GF2, x); } |
---|
140 | |
---|
141 | |
---|
142 | void clear(mat_GF2& a); |
---|
143 | // x = 0 (dimension unchanged) |
---|
144 | |
---|
145 | long IsZero(const mat_GF2& a); |
---|
146 | // test if a is the zero matrix (any dimension) |
---|
147 | |
---|
148 | |
---|
149 | // operator notation: |
---|
150 | |
---|
151 | mat_GF2 operator+(const mat_GF2& a, const mat_GF2& b); |
---|
152 | mat_GF2 operator-(const mat_GF2& a, const mat_GF2& b); |
---|
153 | mat_GF2 operator*(const mat_GF2& a, const mat_GF2& b); |
---|
154 | |
---|
155 | inline mat_GF2 operator-(const mat_GF2& a) |
---|
156 | { return a; } |
---|
157 | |
---|
158 | |
---|
159 | // matrix/scalar multiplication: |
---|
160 | |
---|
161 | inline mat_GF2 operator*(const mat_GF2& a, GF2 b) |
---|
162 | { mat_GF2 x; mul(x, a, b); NTL_OPT_RETURN(mat_GF2, x); } |
---|
163 | |
---|
164 | inline mat_GF2 operator*(const mat_GF2& a, long b) |
---|
165 | { mat_GF2 x; mul(x, a, b); NTL_OPT_RETURN(mat_GF2, x); } |
---|
166 | |
---|
167 | inline mat_GF2 operator*(GF2 a, const mat_GF2& b) |
---|
168 | { mat_GF2 x; mul(x, a, b); NTL_OPT_RETURN(mat_GF2, x); } |
---|
169 | |
---|
170 | inline mat_GF2 operator*(long a, const mat_GF2& b) |
---|
171 | { mat_GF2 x; mul(x, a, b); NTL_OPT_RETURN(mat_GF2, x); } |
---|
172 | |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | // matrix/vector multiplication: |
---|
177 | |
---|
178 | vec_GF2 operator*(const mat_GF2& a, const vec_GF2& b); |
---|
179 | |
---|
180 | vec_GF2 operator*(const vec_GF2& a, const mat_GF2& b); |
---|
181 | |
---|
182 | |
---|
183 | // assignment operator notation: |
---|
184 | |
---|
185 | inline mat_GF2& operator+=(mat_GF2& x, const mat_GF2& a) |
---|
186 | { |
---|
187 | add(x, x, a); |
---|
188 | return x; |
---|
189 | } |
---|
190 | |
---|
191 | inline mat_GF2& operator-=(mat_GF2& x, const mat_GF2& a) |
---|
192 | { |
---|
193 | sub(x, x, a); |
---|
194 | return x; |
---|
195 | } |
---|
196 | |
---|
197 | |
---|
198 | inline mat_GF2& operator*=(mat_GF2& x, const mat_GF2& a) |
---|
199 | { |
---|
200 | mul(x, x, a); |
---|
201 | return x; |
---|
202 | } |
---|
203 | |
---|
204 | inline mat_GF2& operator*=(mat_GF2& x, GF2 a) |
---|
205 | { |
---|
206 | mul(x, x, a); |
---|
207 | return x; |
---|
208 | } |
---|
209 | |
---|
210 | inline mat_GF2& operator*=(mat_GF2& x, long a) |
---|
211 | { |
---|
212 | mul(x, x, a); |
---|
213 | return x; |
---|
214 | } |
---|
215 | |
---|
216 | |
---|
217 | inline vec_GF2& operator*=(vec_GF2& x, const mat_GF2& a) |
---|
218 | { |
---|
219 | mul(x, x, a); |
---|
220 | return x; |
---|
221 | } |
---|
222 | |
---|
223 | |
---|
224 | NTL_CLOSE_NNS |
---|
225 | |
---|
226 | #endif |
---|