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