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