algebramix_doc 0.3
|
00001 00002 #include <basix/int.hpp> 00003 #include <numerix/integer.hpp> 00004 #include <numerix/modular.hpp> 00005 #include <numerix/modular_integer.hpp> 00006 #include <basix/vector.hpp> 00007 #include <algebramix/vector_unrolled.hpp> 00008 #include <algebramix/vector_simd.hpp> 00009 #include <algebramix/vector_modular.hpp> 00010 #include <numerix/rational.hpp> 00011 #include <algebramix/permutation.hpp> 00012 #include <basix/row_tuple.hpp> 00013 #include <algebramix/matrix.hpp> 00014 #include <algebramix/matrix_ring_naive.hpp> 00015 #include <algebramix/matrix_integer.hpp> 00016 #include <algebramix/matrix_modular_integer.hpp> 00017 #include <algebramix/matrix_quotient.hpp> 00018 #include <basix/tuple.hpp> 00019 #include <basix/alias.hpp> 00020 #include <basix/glue.hpp> 00021 00022 #define int_literal(x) as_int (as_string (x)) 00023 #define identity_matrix_integer identity_matrix<integer> 00024 #define hilbert_matrix_rational hilbert_matrix<rational> 00025 00026 namespace mmx { 00027 template<typename C> matrix<C> 00028 matrix_new (const vector<row_tuple<C> >& t) { 00029 if (N(t) == 0) return matrix<C> (); 00030 nat i, j, rows= N(t), cols= N(t[0]); 00031 C dummy= 0; 00032 matrix<C> r (dummy, rows, cols); 00033 for (i=0; i<rows; i++) { 00034 ASSERT (N(t[i]) == cols, "unequal row lengths"); 00035 for (j=0; j<cols; j++) 00036 r(i,j)= t[i][j]; 00037 } 00038 return r; 00039 } 00040 00041 template<typename C> matrix<C> 00042 matrix_new (const vector<C>& t) { 00043 nat j, rows= 1, cols= N(t); 00044 C dummy= 0; 00045 matrix<C> r (dummy, rows, cols); 00046 for (j=0; j<cols; j++) 00047 r(0,j)= t[j]; 00048 return r; 00049 } 00050 00051 template<typename C> vector<generic> 00052 wrap_column_reduced_echelon_with_permutation (const matrix<C>& m) { 00053 permutation permut; 00054 generic tp=as<generic> (column_reduced_echelon (m, permut)); 00055 return vec (tp, as<generic> (permut)); 00056 } 00057 00058 template<typename C> vector<generic> 00059 wrap_column_reduced_echelon_with_transform (const matrix<C>& m) { 00060 matrix<C> k; 00061 generic tp=as<generic> (column_reduced_echelon (m, k)); 00062 return vec (tp, as<generic> (k)); 00063 } 00064 00065 template<typename C> vector<generic> 00066 wrap_row_reduced_echelon_with_transform (const matrix<C>& m) { 00067 matrix<C> k; 00068 generic tp=as<generic> (row_reduced_echelon (m, k)); 00069 return vec (tp, as<generic> (k)); 00070 } 00071 } 00072 00073 00074 namespace mmx { 00075 static row_tuple<mmx_modular(integer) > 00076 GLUE_1 (const tuple<mmx_modular(integer) > &arg_1) { 00077 return row_tuple<mmx_modular(integer) > (as_vector (arg_1)); 00078 } 00079 00080 static matrix<mmx_modular(integer) > 00081 GLUE_2 (const tuple<mmx_modular(integer) > &arg_1) { 00082 return matrix_new (as_vector (arg_1)); 00083 } 00084 00085 static matrix<mmx_modular(integer) > 00086 GLUE_3 (const tuple<row_tuple<mmx_modular(integer) > > &arg_1) { 00087 return matrix_new (as_vector (arg_1)); 00088 } 00089 00090 static matrix<mmx_modular(integer) > 00091 GLUE_4 (const tuple<row_tuple<mmx_modular(integer) > > &arg_1) { 00092 return matrix_new (as_vector (arg_1)); 00093 } 00094 00095 static int 00096 GLUE_5 (const matrix<mmx_modular(integer) > &arg_1) { 00097 return N (arg_1); 00098 } 00099 00100 static int 00101 GLUE_6 (const matrix<mmx_modular(integer) > &arg_1) { 00102 return rows (arg_1); 00103 } 00104 00105 static int 00106 GLUE_7 (const matrix<mmx_modular(integer) > &arg_1) { 00107 return cols (arg_1); 00108 } 00109 00110 static mmx_modular(integer) 00111 GLUE_8 (const matrix<mmx_modular(integer) > &arg_1, const int &arg_2, const int &arg_3) { 00112 return arg_1 (arg_2, arg_3); 00113 } 00114 00115 static alias<mmx_modular(integer) > 00116 GLUE_9 (const alias<matrix<mmx_modular(integer) > > &arg_1, const int &arg_2, const int &arg_3) { 00117 return alias_access<mmx_modular(integer) > (arg_1, arg_2, arg_3); 00118 } 00119 00120 static matrix<mmx_modular(integer) > 00121 GLUE_10 (const matrix<mmx_modular(integer) > &arg_1, const int &arg_2, const int &arg_3, const int &arg_4, const int &arg_5) { 00122 return range (arg_1, arg_2, arg_3, arg_4, arg_5); 00123 } 00124 00125 static vector<mmx_modular(integer) > 00126 GLUE_11 (const matrix<mmx_modular(integer) > &arg_1, const int &arg_2) { 00127 return row (arg_1, arg_2); 00128 } 00129 00130 static vector<mmx_modular(integer) > 00131 GLUE_12 (const matrix<mmx_modular(integer) > &arg_1, const int &arg_2) { 00132 return column (arg_1, arg_2); 00133 } 00134 00135 static matrix<mmx_modular(integer) > 00136 GLUE_13 (const matrix<mmx_modular(integer) > &arg_1) { 00137 return transpose (arg_1); 00138 } 00139 00140 static matrix<mmx_modular(integer) > 00141 GLUE_14 (const matrix<mmx_modular(integer) > &arg_1, const matrix<mmx_modular(integer) > &arg_2) { 00142 return horizontal_join (arg_1, arg_2); 00143 } 00144 00145 static matrix<mmx_modular(integer) > 00146 GLUE_15 (const matrix<mmx_modular(integer) > &arg_1, const matrix<mmx_modular(integer) > &arg_2) { 00147 return vertical_join (arg_1, arg_2); 00148 } 00149 00150 static row_tuple<generic> 00151 GLUE_16 (const row_tuple<mmx_modular(integer) > &arg_1) { 00152 return as<row_tuple<generic> > (arg_1); 00153 } 00154 00155 static matrix<generic> 00156 GLUE_17 (const matrix<mmx_modular(integer) > &arg_1) { 00157 return as<matrix<generic> > (arg_1); 00158 } 00159 00160 static matrix<mmx_modular(integer) > 00161 GLUE_18 (const mmx_modular(integer) &arg_1, const int &arg_2, const int &arg_3) { 00162 return fill_matrix (arg_1, arg_2, arg_3); 00163 } 00164 00165 static matrix<mmx_modular(integer) > 00166 GLUE_19 (const mmx_modular(integer) &arg_1, const int &arg_2) { 00167 return jordan_matrix (arg_1, arg_2); 00168 } 00169 00170 static matrix<mmx_modular(integer) > 00171 GLUE_20 (const vector<mmx_modular(integer) > &arg_1) { 00172 return toeplitz_matrix (arg_1); 00173 } 00174 00175 static matrix<mmx_modular(integer) > 00176 GLUE_21 (const vector<mmx_modular(integer) > &arg_1) { 00177 return hankel_matrix (arg_1); 00178 } 00179 00180 static matrix<mmx_modular(integer) > 00181 GLUE_22 (const vector<mmx_modular(integer) > &arg_1, const vector<mmx_modular(integer) > &arg_2) { 00182 return tensor_matrix (arg_1, arg_2); 00183 } 00184 00185 static matrix<mmx_modular(integer) > 00186 GLUE_23 (const vector<mmx_modular(integer) > &arg_1) { 00187 return vandermonde (arg_1); 00188 } 00189 00190 static matrix<mmx_modular(integer) > 00191 GLUE_24 (const matrix<mmx_modular(integer) > &arg_1) { 00192 return -arg_1; 00193 } 00194 00195 static matrix<mmx_modular(integer) > 00196 GLUE_25 (const matrix<mmx_modular(integer) > &arg_1) { 00197 return square (arg_1); 00198 } 00199 00200 static matrix<mmx_modular(integer) > 00201 GLUE_26 (const matrix<mmx_modular(integer) > &arg_1, const matrix<mmx_modular(integer) > &arg_2) { 00202 return arg_1 + arg_2; 00203 } 00204 00205 static matrix<mmx_modular(integer) > 00206 GLUE_27 (const matrix<mmx_modular(integer) > &arg_1, const matrix<mmx_modular(integer) > &arg_2) { 00207 return arg_1 - arg_2; 00208 } 00209 00210 static matrix<mmx_modular(integer) > 00211 GLUE_28 (const matrix<mmx_modular(integer) > &arg_1, const matrix<mmx_modular(integer) > &arg_2) { 00212 return arg_1 * arg_2; 00213 } 00214 00215 static matrix<mmx_modular(integer) > 00216 GLUE_29 (const mmx_modular(integer) &arg_1, const matrix<mmx_modular(integer) > &arg_2) { 00217 return arg_1 + arg_2; 00218 } 00219 00220 static matrix<mmx_modular(integer) > 00221 GLUE_30 (const matrix<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) { 00222 return arg_1 + arg_2; 00223 } 00224 00225 static matrix<mmx_modular(integer) > 00226 GLUE_31 (const mmx_modular(integer) &arg_1, const matrix<mmx_modular(integer) > &arg_2) { 00227 return arg_1 - arg_2; 00228 } 00229 00230 static matrix<mmx_modular(integer) > 00231 GLUE_32 (const matrix<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) { 00232 return arg_1 - arg_2; 00233 } 00234 00235 static matrix<mmx_modular(integer) > 00236 GLUE_33 (const mmx_modular(integer) &arg_1, const matrix<mmx_modular(integer) > &arg_2) { 00237 return arg_1 * arg_2; 00238 } 00239 00240 static matrix<mmx_modular(integer) > 00241 GLUE_34 (const matrix<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) { 00242 return arg_1 * arg_2; 00243 } 00244 00245 static vector<mmx_modular(integer) > 00246 GLUE_35 (const matrix<mmx_modular(integer) > &arg_1, const vector<mmx_modular(integer) > &arg_2) { 00247 return arg_1 * arg_2; 00248 } 00249 00250 static vector<mmx_modular(integer) > 00251 GLUE_36 (const vector<mmx_modular(integer) > &arg_1, const matrix<mmx_modular(integer) > &arg_2) { 00252 return arg_1 * arg_2; 00253 } 00254 00255 static matrix<mmx_modular(integer) > 00256 GLUE_37 (const mmx_modular(integer) &arg_1, const matrix<mmx_modular(integer) > &arg_2) { 00257 return arg_1 / arg_2; 00258 } 00259 00260 static matrix<mmx_modular(integer) > 00261 GLUE_38 (const matrix<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) { 00262 return arg_1 / arg_2; 00263 } 00264 00265 static matrix<mmx_modular(integer) > 00266 GLUE_39 (const matrix<mmx_modular(integer) > &arg_1, const matrix<mmx_modular(integer) > &arg_2) { 00267 return krylov (arg_1, arg_2); 00268 } 00269 00270 static mmx_modular(integer) 00271 GLUE_40 (const matrix<mmx_modular(integer) > &arg_1) { 00272 return det (arg_1); 00273 } 00274 00275 static matrix<mmx_modular(integer) > 00276 GLUE_41 (const matrix<mmx_modular(integer) > &arg_1) { 00277 return row_echelon (arg_1); 00278 } 00279 00280 static matrix<mmx_modular(integer) > 00281 GLUE_42 (const matrix<mmx_modular(integer) > &arg_1) { 00282 return column_echelon (arg_1); 00283 } 00284 00285 static matrix<mmx_modular(integer) > 00286 GLUE_43 (const matrix<mmx_modular(integer) > &arg_1) { 00287 return row_reduced_echelon (arg_1); 00288 } 00289 00290 static matrix<mmx_modular(integer) > 00291 GLUE_44 (const matrix<mmx_modular(integer) > &arg_1) { 00292 return column_reduced_echelon (arg_1); 00293 } 00294 00295 static vector<generic> 00296 GLUE_45 (const matrix<mmx_modular(integer) > &arg_1) { 00297 return wrap_row_reduced_echelon_with_transform (arg_1); 00298 } 00299 00300 static vector<generic> 00301 GLUE_46 (const matrix<mmx_modular(integer) > &arg_1) { 00302 return wrap_column_reduced_echelon_with_transform (arg_1); 00303 } 00304 00305 static vector<generic> 00306 GLUE_47 (const matrix<mmx_modular(integer) > &arg_1) { 00307 return wrap_column_reduced_echelon_with_permutation (arg_1); 00308 } 00309 00310 static matrix<mmx_modular(integer) > 00311 GLUE_48 (const matrix<mmx_modular(integer) > &arg_1) { 00312 return kernel (arg_1); 00313 } 00314 00315 static matrix<mmx_modular(integer) > 00316 GLUE_49 (const matrix<mmx_modular(integer) > &arg_1) { 00317 return image (arg_1); 00318 } 00319 00320 static int 00321 GLUE_50 (const matrix<mmx_modular(integer) > &arg_1) { 00322 return rank (arg_1); 00323 } 00324 00325 static matrix<mmx_modular(integer) > 00326 GLUE_51 (const matrix<mmx_modular(integer) > &arg_1) { 00327 return invert (arg_1); 00328 } 00329 00330 void 00331 glue_matrix_modular_integer () { 00332 static bool done = false; 00333 if (done) return; 00334 done = true; 00335 call_glue (string ("glue_vector_modular_integer")); 00336 call_glue (string ("glue_matrix_integer")); 00337 define_type<row_tuple<mmx_modular(integer) > > (gen (lit ("Row"), gen (lit ("Modular"), lit ("Integer")))); 00338 define_type<matrix<mmx_modular(integer) > > (gen (lit ("Matrix"), gen (lit ("Modular"), lit ("Integer")))); 00339 define ("(.)", GLUE_1); 00340 define ("matrix", GLUE_2); 00341 define ("matrix", GLUE_3); 00342 define ("[]", GLUE_4); 00343 define ("#", GLUE_5); 00344 define ("rows", GLUE_6); 00345 define ("columns", GLUE_7); 00346 define (".[]", GLUE_8); 00347 define (".[]", GLUE_9); 00348 define (".[]", GLUE_10); 00349 define ("row", GLUE_11); 00350 define ("column", GLUE_12); 00351 define ("transpose", GLUE_13); 00352 define ("horizontal_join", GLUE_14); 00353 define ("vertical_join", GLUE_15); 00354 define_converter (":>", GLUE_16, PENALTY_PROMOTE_GENERIC); 00355 define_converter (":>", GLUE_17, PENALTY_PROMOTE_GENERIC); 00356 define ("fill_matrix", GLUE_18); 00357 define ("jordan_matrix", GLUE_19); 00358 define ("toeplitz_matrix", GLUE_20); 00359 define ("hankel_matrix", GLUE_21); 00360 define ("tensor_matrix", GLUE_22); 00361 define ("vandermonde", GLUE_23); 00362 define ("-", GLUE_24); 00363 define ("square", GLUE_25); 00364 define ("+", GLUE_26); 00365 define ("-", GLUE_27); 00366 define ("*", GLUE_28); 00367 define ("+", GLUE_29); 00368 define ("+", GLUE_30); 00369 define ("-", GLUE_31); 00370 define ("-", GLUE_32); 00371 define ("*", GLUE_33); 00372 define ("*", GLUE_34); 00373 define ("*", GLUE_35); 00374 define ("*", GLUE_36); 00375 define ("/", GLUE_37); 00376 define ("/", GLUE_38); 00377 define ("krylov", GLUE_39); 00378 define ("det", GLUE_40); 00379 define ("row_echelon", GLUE_41); 00380 define ("column_echelon", GLUE_42); 00381 define ("row_reduced_echelon", GLUE_43); 00382 define ("column_reduced_echelon", GLUE_44); 00383 define ("row_reduced_echelon_with_transform", GLUE_45); 00384 define ("column_reduced_echelon_with_transform", GLUE_46); 00385 define ("column_reduced_echelon_with_permutation", GLUE_47); 00386 define ("ker", GLUE_48); 00387 define ("im", GLUE_49); 00388 define ("rank", GLUE_50); 00389 define ("invert", GLUE_51); 00390 } 00391 }