[691dba] | 1 | #include "config.h" |
---|
[18cb65] | 2 | #include <misc/auxiliary.h> |
---|
[31f1262] | 3 | |
---|
| 4 | #ifdef HAVE_FACTORY |
---|
| 5 | #include <factory/factory.h> |
---|
| 6 | #endif |
---|
| 7 | |
---|
[1820e7] | 8 | #include <omalloc/omalloc.h> |
---|
| 9 | |
---|
| 10 | #include <reporter/reporter.h> |
---|
[9eb0f9] | 11 | #include <resources/feResource.h> |
---|
[1112b76] | 12 | |
---|
[2d805a] | 13 | #include <coeffs/coeffs.h> |
---|
| 14 | #include <coeffs/numbers.h> |
---|
[c3d175] | 15 | |
---|
[2d805a] | 16 | #include <coeffs/longrat.h> |
---|
| 17 | #include <coeffs/gnumpfl.h> |
---|
| 18 | #include <coeffs/gnumpc.h> |
---|
| 19 | #include <coeffs/shortfl.h> |
---|
| 20 | #include <coeffs/ffields.h> |
---|
| 21 | #include <coeffs/modulop.h> |
---|
| 22 | #include <coeffs/rmodulon.h> |
---|
| 23 | #include <coeffs/rmodulo2m.h> |
---|
| 24 | #include <coeffs/rintegers.h> |
---|
[9eb0f9] | 25 | |
---|
| 26 | |
---|
[abb4787] | 27 | #ifdef HAVE_FACTORY |
---|
[643b1eb] | 28 | int initializeGMP(){ return 1; } |
---|
[abb4787] | 29 | #endif |
---|
[c3d175] | 30 | |
---|
[56abc3] | 31 | #include <iostream> |
---|
[17d2dd] | 32 | |
---|
[56abc3] | 33 | using namespace std; |
---|
| 34 | |
---|
[7c362e] | 35 | #pragma GCC diagnostic ignored "-Wwrite-strings" |
---|
| 36 | |
---|
[16f8f1] | 37 | void Print(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE) |
---|
[c3d175] | 38 | { |
---|
[2bd9ca] | 39 | n_Test(a,r); |
---|
[16f8f1] | 40 | |
---|
| 41 | StringSetS(""); |
---|
[17d2dd] | 42 | n_Write(a, r); |
---|
[16f8f1] | 43 | |
---|
| 44 | char* s = NULL; |
---|
| 45 | |
---|
| 46 | if( eoln ) |
---|
| 47 | s = StringAppend("\n"); |
---|
| 48 | else |
---|
| 49 | s = StringAppend(""); |
---|
| 50 | |
---|
| 51 | PrintS(s); |
---|
| 52 | |
---|
| 53 | // free s? |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | void PrintSized(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE) |
---|
| 58 | { |
---|
| 59 | Print(a, r, FALSE); |
---|
| 60 | Print(", of size: %d", n_Size(a, r)); |
---|
| 61 | |
---|
| 62 | if( eoln ) |
---|
| 63 | PrintLn(); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | bool TestArith(const coeffs r) |
---|
| 69 | { |
---|
| 70 | number a = n_Init(66666, r); |
---|
| 71 | |
---|
| 72 | PrintS("a: "); PrintSized(a, r); |
---|
[17d2dd] | 73 | |
---|
| 74 | number two = n_Init(2, r); |
---|
| 75 | |
---|
[16f8f1] | 76 | PrintS("two: "); PrintSized(two, r); |
---|
[17d2dd] | 77 | |
---|
[dc06550] | 78 | if (getCoeffType(r) == n_GF) //some special test for GF |
---|
| 79 | { |
---|
[16f8f1] | 80 | number z = nfPar (0, r); // also any integer instead of 0//? |
---|
| 81 | |
---|
| 82 | PrintS("Generator: "); PrintSized(z, r); |
---|
| 83 | |
---|
[7c362e] | 84 | n_Delete(&z, r); |
---|
[dc06550] | 85 | } |
---|
| 86 | |
---|
[17d2dd] | 87 | number aa = n_Add(a, a, r); |
---|
| 88 | |
---|
[16f8f1] | 89 | PrintS("aa = a + a: "); PrintSized(aa, r); |
---|
[5dcc9a6] | 90 | |
---|
[17d2dd] | 91 | number aa2 = n_Mult(a, two, r); |
---|
| 92 | |
---|
[16f8f1] | 93 | PrintS("aa2 = a * 2: "); PrintSized(aa2, r); |
---|
[17d2dd] | 94 | |
---|
| 95 | number aa1 = n_Mult(two, a, r); |
---|
| 96 | |
---|
[16f8f1] | 97 | PrintS("aa1 = 2 * a: "); PrintSized(aa1, r); |
---|
[56abc3] | 98 | |
---|
[b12b7c] | 99 | n_Delete(&a, r); |
---|
[17d2dd] | 100 | n_Delete(&two, r); |
---|
| 101 | |
---|
[2e6a06] | 102 | |
---|
| 103 | a = n_Sub( aa, aa1, r ); |
---|
| 104 | |
---|
[16f8f1] | 105 | PrintS("a = aa - aa1: "); PrintSized(a, r); |
---|
[2e6a06] | 106 | |
---|
| 107 | if( !n_IsZero(a, r) ) |
---|
[16f8f1] | 108 | WarnS("TestArith: ERROR: a != 0 !!!\n"); |
---|
[2e6a06] | 109 | |
---|
| 110 | n_Delete(&a, r); |
---|
| 111 | |
---|
| 112 | a = n_Sub( aa, aa2, r ); |
---|
| 113 | |
---|
[16f8f1] | 114 | PrintS("a = aa - aa2: "); PrintSized(a, r); |
---|
[2e6a06] | 115 | |
---|
| 116 | if( !n_IsZero(a, r) ) |
---|
[16f8f1] | 117 | WarnS("TestArith: ERROR: a != 0 !!!\n"); |
---|
[2e6a06] | 118 | |
---|
| 119 | n_Delete(&a, r); |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | a = n_Sub( aa1, aa2, r ); |
---|
| 123 | |
---|
[16f8f1] | 124 | PrintS("a = aa1 - aa2: "); PrintSized(a, r); |
---|
[2e6a06] | 125 | |
---|
| 126 | if( !n_IsZero(a, r) ) |
---|
[16f8f1] | 127 | WarnS("TestArith: ERROR: a != 0 !!!\n"); |
---|
[2e6a06] | 128 | |
---|
| 129 | n_Delete(&a, r); |
---|
| 130 | |
---|
| 131 | |
---|
[17d2dd] | 132 | |
---|
| 133 | if( !n_Equal(aa, aa1, r) ) |
---|
[16f8f1] | 134 | WarnS("TestArith: ERROR: aa != aa1 !!!\n"); |
---|
[17d2dd] | 135 | |
---|
| 136 | if( !n_Equal(aa, aa2, r) ) |
---|
[16f8f1] | 137 | WarnS("TestArith: ERROR: aa != aa2 !!!\n"); |
---|
[17d2dd] | 138 | |
---|
| 139 | if( !n_Equal(aa1, aa2, r) ) |
---|
[16f8f1] | 140 | WarnS("TestArith: ERROR: aa1 != aa2 !!!\n"); |
---|
[17d2dd] | 141 | |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | n_Delete(&aa, r); |
---|
| 146 | n_Delete(&aa1, r); |
---|
| 147 | n_Delete(&aa2, r); |
---|
[56abc3] | 148 | |
---|
| 149 | return false; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | |
---|
[17d2dd] | 154 | namespace |
---|
[56abc3] | 155 | { |
---|
[17d2dd] | 156 | static inline ostream& operator<< (ostream& o, const n_coeffType& type) |
---|
| 157 | { |
---|
| 158 | #define CASE(A) case A: return o << (" " # A) << " "; |
---|
| 159 | switch( type ) |
---|
| 160 | { |
---|
| 161 | CASE(n_unknown); |
---|
| 162 | CASE(n_Zp); |
---|
| 163 | CASE(n_Q); |
---|
| 164 | CASE(n_R); |
---|
| 165 | CASE(n_GF); |
---|
| 166 | CASE(n_long_R); |
---|
[141342] | 167 | CASE(n_algExt); |
---|
| 168 | CASE(n_transExt); |
---|
[17d2dd] | 169 | CASE(n_long_C); |
---|
| 170 | CASE(n_Z); |
---|
| 171 | CASE(n_Zn); |
---|
| 172 | CASE(n_Zpn); |
---|
| 173 | CASE(n_Z2m); |
---|
| 174 | CASE(n_CF); |
---|
| 175 | default: return o << "Unknown type: [" << (const unsigned long) type << "]"; |
---|
| 176 | } |
---|
| 177 | #undef CASE |
---|
| 178 | return o; |
---|
[2e6a06] | 179 | } |
---|
| 180 | } |
---|
[17d2dd] | 181 | |
---|
[56abc3] | 182 | |
---|
[17d2dd] | 183 | bool Test(const n_coeffType type, void* p = NULL) |
---|
| 184 | { |
---|
[fb0a699] | 185 | cout << endl << "----------------------- Testing coeffs: [" << type << ", " << p << |
---|
[f1c465f] | 186 | "]: -----------------------" << endl; |
---|
[c3d175] | 187 | |
---|
[1112b76] | 188 | const coeffs r = nInitChar( type, p ); |
---|
[c3d175] | 189 | |
---|
[fb0a699] | 190 | if( r == NULL ) { cout << "Test: could not get the specified coeff. domain for type: " << type << " and the parameter: " << p << endl; return false; }; |
---|
[56abc3] | 191 | |
---|
[fb0a699] | 192 | assume( r != NULL ); |
---|
[2b957a] | 193 | nSetChar( r ); |
---|
| 194 | assume( getCoeffType(r) == type ); |
---|
[c3d175] | 195 | |
---|
| 196 | assume( r->cfInit != NULL ); |
---|
| 197 | assume( r->cfWrite != NULL ); |
---|
| 198 | assume( r->cfAdd != NULL ); |
---|
| 199 | assume( r->cfDelete != NULL ); |
---|
[56abc3] | 200 | |
---|
[c3d175] | 201 | if( type == n_Q ) |
---|
| 202 | { |
---|
| 203 | assume( r->cfInit == nlInit ); |
---|
| 204 | assume( r->cfWrite == nlWrite ); |
---|
| 205 | assume( r->cfAdd == nlAdd ); |
---|
| 206 | assume( r->cfDelete == nlDelete ); |
---|
[2b957a] | 207 | } |
---|
[1c3d1f] | 208 | else if( type == n_long_R ) |
---|
| 209 | { |
---|
| 210 | assume( r->cfInit == ngfInit ); |
---|
| 211 | assume( r->cfWrite == ngfWrite ); |
---|
| 212 | assume( r->cfAdd == ngfAdd ); |
---|
| 213 | assume( r->cfDelete == ngfDelete ); |
---|
| 214 | } |
---|
[c3d175] | 215 | else if( type == n_long_C ) |
---|
| 216 | { |
---|
| 217 | assume( r->cfInit == ngcInit ); |
---|
| 218 | assume( r->cfWrite == ngcWrite ); |
---|
| 219 | assume( r->cfAdd == ngcAdd ); |
---|
| 220 | assume( r->cfDelete == ngcDelete ); |
---|
| 221 | } |
---|
[2b957a] | 222 | else if( type == n_R ) |
---|
| 223 | { |
---|
| 224 | assume( r->cfInit == nrInit ); |
---|
| 225 | assume( r->cfWrite == nrWrite ); |
---|
| 226 | assume( r->cfAdd == nrAdd ); |
---|
| 227 | // assume( r->cfDelete == nrDelete ); // No? |
---|
[21dc6a] | 228 | } |
---|
[f1c465f] | 229 | #ifdef HAVE_RINGS |
---|
[21dc6a] | 230 | else if( type == n_Z2m ) |
---|
| 231 | { |
---|
| 232 | assume( r->cfInit == nr2mInit ); |
---|
| 233 | assume( r->cfWrite == nr2mWrite ); |
---|
| 234 | assume( r->cfAdd == nr2mAdd ); |
---|
[e5ffec7] | 235 | assume( r->cfDelete == ndDelete ); |
---|
[21dc6a] | 236 | } |
---|
| 237 | else if( type == n_Zn ) |
---|
| 238 | { |
---|
| 239 | assume( r->cfInit == nrnInit ); |
---|
[e5ffec7] | 240 | assume( r->cfWrite == nrnWrite ); |
---|
| 241 | assume( r->cfAdd == nrnAdd ); |
---|
| 242 | assume( r->cfDelete == nrnDelete ); |
---|
[21dc6a] | 243 | } |
---|
[dc06550] | 244 | #endif |
---|
| 245 | else if( type == n_GF ) |
---|
| 246 | { |
---|
| 247 | assume( r->cfInit == nfInit ); |
---|
| 248 | assume( r->cfWrite == nfWrite ); |
---|
| 249 | assume( r->cfAdd == nfAdd ); |
---|
| 250 | //assume( r->cfDelete == nfDelete ); |
---|
| 251 | } |
---|
[21dc6a] | 252 | else |
---|
[2b957a] | 253 | { |
---|
| 254 | // ... |
---|
| 255 | } |
---|
[c3d175] | 256 | |
---|
[16f8f1] | 257 | bool ret = TestArith( r ); |
---|
[56abc3] | 258 | |
---|
| 259 | nKillChar( r ); |
---|
| 260 | |
---|
| 261 | return ret; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | |
---|
[9eb0f9] | 265 | int main( int, char *argv[] ) |
---|
| 266 | { |
---|
| 267 | feInitResources(argv[0]); |
---|
| 268 | |
---|
| 269 | StringSetS("ressources in use (as reported by feStringAppendResources(0):\n"); |
---|
| 270 | feStringAppendResources(0); |
---|
| 271 | PrintS(StringAppendS("\n")); |
---|
[c3d175] | 272 | |
---|
[56abc3] | 273 | |
---|
| 274 | int c = 0; |
---|
[c3d175] | 275 | |
---|
[56abc3] | 276 | n_coeffType type; |
---|
[d61b83a] | 277 | |
---|
[16f8f1] | 278 | |
---|
[f85d3e] | 279 | #ifdef HAVE_RINGS |
---|
[16f8f1] | 280 | // TODO(Frank, Segmentation fault! (if used wihout omalloc???). Please_ investigate!); |
---|
[7af488e] | 281 | type = n_Z2m; |
---|
[16f8f1] | 282 | if( Test(type, (void*) 4) ) |
---|
[f85d3e] | 283 | c ++; |
---|
| 284 | #endif |
---|
[0e4b5f] | 285 | |
---|
[7af488e] | 286 | type = n_Zp; |
---|
[16f8f1] | 287 | if( Test(type, (void*) 101) ) |
---|
[0e4b5f] | 288 | c ++; |
---|
| 289 | |
---|
[f85d3e] | 290 | #ifdef HAVE_RINGS |
---|
[16f8f1] | 291 | // TODO(Frank, memmory corruption_ if used wihout omalloc??? Please_ investigate!); |
---|
| 292 | |
---|
[7af488e] | 293 | type = n_Z2m; |
---|
[16f8f1] | 294 | if( Test(type, (void*) 8) ) |
---|
[f85d3e] | 295 | c ++; |
---|
[16f8f1] | 296 | |
---|
[f85d3e] | 297 | #endif |
---|
| 298 | |
---|
[56abc3] | 299 | |
---|
[7af488e] | 300 | type = n_Q; |
---|
[1c3d1f] | 301 | if( Test(type) ) |
---|
| 302 | c ++; |
---|
[2b957a] | 303 | |
---|
[7af488e] | 304 | type = n_R; |
---|
[56abc3] | 305 | if( Test(type) ) |
---|
| 306 | c ++; |
---|
| 307 | |
---|
[0e4b5f] | 308 | #ifdef HAVE_RINGS |
---|
[7af488e] | 309 | type = n_Z; |
---|
[bec902b] | 310 | if( Test(type) ) |
---|
| 311 | c ++; |
---|
[17d2dd] | 312 | #endif |
---|
[7af488e] | 313 | type = n_GF; |
---|
[2e6a06] | 314 | |
---|
[dc06550] | 315 | |
---|
[16f8f1] | 316 | GFInfo* param = new GFInfo(); |
---|
[2e6a06] | 317 | |
---|
[16f8f1] | 318 | param->GFChar= 5; |
---|
| 319 | param->GFDegree= 12; |
---|
| 320 | param->GFPar_name= (const char*)"q"; |
---|
| 321 | |
---|
| 322 | if( Test(type, (void*) param) ) |
---|
[0d5a99] | 323 | c ++; |
---|
[fb0a699] | 324 | |
---|
[16f8f1] | 325 | // it should not be used by numbers... right? |
---|
| 326 | // TODO: what is our policy wrt param-pointer-ownership? |
---|
| 327 | delete param; |
---|
| 328 | // Q: no way to deRegister a type? |
---|
| 329 | |
---|
| 330 | param = new GFInfo(); |
---|
[fb0a699] | 331 | |
---|
[16f8f1] | 332 | param->GFChar= 5; |
---|
| 333 | param->GFDegree= 2; |
---|
| 334 | param->GFPar_name= (const char*)"Q"; |
---|
[f85d3e] | 335 | |
---|
[16f8f1] | 336 | if( Test(type, (void*) param) ) |
---|
[f85d3e] | 337 | c ++; |
---|
| 338 | |
---|
[16f8f1] | 339 | delete param; |
---|
[fb0a699] | 340 | |
---|
[f85d3e] | 341 | |
---|
| 342 | |
---|
| 343 | |
---|
| 344 | #ifdef HAVE_RINGS |
---|
[16f8f1] | 345 | // TODO(Somebody, This will result in memory corruption at Z_2^m later on (due to the succs. setGMPFloatDigits?)...!?); // ???? |
---|
| 346 | |
---|
[7af488e] | 347 | type = n_Zn; |
---|
[f85d3e] | 348 | |
---|
| 349 | if( Test(type, (void*) 3) ) |
---|
| 350 | c ++; |
---|
[16f8f1] | 351 | |
---|
[f85d3e] | 352 | #endif |
---|
| 353 | |
---|
[16f8f1] | 354 | TODO(Somebody, floating arithmetics via GMP rely on two global variables (see setGMPFloatDigits). Please fix it!); |
---|
[f85d3e] | 355 | setGMPFloatDigits( 10, 5 ); // Init global variables in mpr_complex.cc for gmp_float's... // Note that this seems also to be required for Z_2^m (and Zn?)!???? |
---|
| 356 | |
---|
| 357 | |
---|
[7af488e] | 358 | type = n_long_C; |
---|
[2e6a06] | 359 | if( Test(type) ) |
---|
| 360 | c ++; |
---|
[17d2dd] | 361 | |
---|
[7af488e] | 362 | type = n_long_R; |
---|
[2e6a06] | 363 | if( Test(type) ) |
---|
| 364 | c ++; |
---|
[f85d3e] | 365 | |
---|
| 366 | #ifdef HAVE_RINGS |
---|
[7af488e] | 367 | type = n_Z2m; |
---|
[f85d3e] | 368 | if( Test(type, (void*) 2) ) |
---|
| 369 | c ++; |
---|
| 370 | #endif |
---|
| 371 | |
---|
| 372 | |
---|
[17d2dd] | 373 | #ifdef HAVE_RINGS |
---|
[7af488e] | 374 | type = n_Zn; |
---|
[0e4b5f] | 375 | |
---|
[1112b76] | 376 | if( Test(type, (void*) 3) ) |
---|
[21dc6a] | 377 | c ++; |
---|
[f1c465f] | 378 | #endif |
---|
[17d2dd] | 379 | |
---|
[141342] | 380 | // polynomial rings needed for: n_algExt, n_transExt ! |
---|
[0e4b5f] | 381 | |
---|
[56abc3] | 382 | return c; |
---|
[2b957a] | 383 | |
---|
[c3d175] | 384 | } |
---|