#include "config.h" #include #ifdef HAVE_FACTORY #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_FACTORY int initializeGMP(void){ return 1; } int mmInit(void) {return 1; } // ? due to SINGULAR!!!...??? #endif #include using namespace std; #pragma GCC diagnostic ignored "-Wwrite-strings" void Print(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE) { n_Test(a,r); StringSetS(""); n_Write(a, r); char* s = NULL; if( eoln ) s = StringAppend("\n"); else s = StringAppend(""); PrintS(s); // free s? } void PrintSized(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE) { Print(a, r, FALSE); Print(", of size: %d", n_Size(a, r)); if( eoln ) PrintLn(); } bool TestArith(const coeffs r) { number a = n_Init(66666, r); PrintS("a: "); PrintSized(a, r); number two = n_Init(2, r); PrintS("two: "); PrintSized(two, r); if (getCoeffType(r) == n_GF) //some special test for GF { number z = nfPar (0, r); // also any integer instead of 0//? PrintS("Generator: "); PrintSized(z, r); n_Delete(&z, r); } number aa = n_Add(a, a, r); PrintS("aa = a + a: "); PrintSized(aa, r); number aa2 = n_Mult(a, two, r); PrintS("aa2 = a * 2: "); PrintSized(aa2, r); number aa1 = n_Mult(two, a, r); PrintS("aa1 = 2 * a: "); PrintSized(aa1, r); n_Delete(&a, r); n_Delete(&two, r); a = n_Sub( aa, aa1, r ); PrintS("a = aa - aa1: "); PrintSized(a, r); if( !n_IsZero(a, r) ) WarnS("TestArith: ERROR: a != 0 !!!\n"); n_Delete(&a, r); a = n_Sub( aa, aa2, r ); PrintS("a = aa - aa2: "); PrintSized(a, r); if( !n_IsZero(a, r) ) WarnS("TestArith: ERROR: a != 0 !!!\n"); n_Delete(&a, r); a = n_Sub( aa1, aa2, r ); PrintS("a = aa1 - aa2: "); PrintSized(a, r); if( !n_IsZero(a, r) ) WarnS("TestArith: ERROR: a != 0 !!!\n"); n_Delete(&a, r); if( !n_Equal(aa, aa1, r) ) WarnS("TestArith: ERROR: aa != aa1 !!!\n"); if( !n_Equal(aa, aa2, r) ) WarnS("TestArith: ERROR: aa != aa2 !!!\n"); if( !n_Equal(aa1, aa2, r) ) WarnS("TestArith: ERROR: aa1 != aa2 !!!\n"); n_Delete(&aa, r); n_Delete(&aa1, r); n_Delete(&aa2, r); return false; } namespace { static inline ostream& operator<< (ostream& o, const n_coeffType& type) { #define CASE(A) case A: return o << (" " # A) << " "; switch( type ) { CASE(n_unknown); CASE(n_Zp); CASE(n_Q); CASE(n_R); CASE(n_GF); CASE(n_long_R); CASE(n_algExt); CASE(n_transExt); CASE(n_long_C); CASE(n_Z); CASE(n_Zn); CASE(n_Zpn); CASE(n_Z2m); CASE(n_CF); default: return o << "Unknown type: [" << (const unsigned long) type << "]"; } #undef CASE return o; } } bool Test(const n_coeffType type, void* p = NULL) { cout << endl << "----------------------- Testing coeffs: [" << type << ", " << p << "]: -----------------------" << endl; const coeffs r = nInitChar( type, p ); if( r == NULL ) { cout << "Test: could not get the specified coeff. domain for type: " << type << " and the parameter: " << p << endl; return false; }; assume( r != NULL ); nSetChar( r ); assume( getCoeffType(r) == type ); assume( r->cfInit != NULL ); assume( r->cfWrite != NULL ); assume( r->cfAdd != NULL ); assume( r->cfDelete != NULL ); if( type == n_Q ) { assume( r->cfInit == nlInit ); assume( r->cfWrite == nlWrite ); assume( r->cfAdd == nlAdd ); assume( r->cfDelete == nlDelete ); } else if( type == n_long_R ) { assume( r->cfInit == ngfInit ); assume( r->cfWrite == ngfWrite ); assume( r->cfAdd == ngfAdd ); assume( r->cfDelete == ngfDelete ); } else if( type == n_long_C ) { assume( r->cfInit == ngcInit ); assume( r->cfWrite == ngcWrite ); assume( r->cfAdd == ngcAdd ); assume( r->cfDelete == ngcDelete ); } else if( type == n_R ) { assume( r->cfInit == nrInit ); assume( r->cfWrite == nrWrite ); assume( r->cfAdd == nrAdd ); // assume( r->cfDelete == nrDelete ); // No? } #ifdef HAVE_RINGS else if( type == n_Z2m ) { assume( r->cfInit == nr2mInit ); assume( r->cfWrite == nr2mWrite ); assume( r->cfAdd == nr2mAdd ); assume( r->cfDelete == ndDelete ); } else if( type == n_Zn ) { assume( r->cfInit == nrnInit ); assume( r->cfWrite == nrnWrite ); assume( r->cfAdd == nrnAdd ); assume( r->cfDelete == nrnDelete ); } #endif else if( type == n_GF ) { assume( r->cfInit == nfInit ); assume( r->cfWrite == nfWrite ); assume( r->cfAdd == nfAdd ); //assume( r->cfDelete == nfDelete ); } else { // ... } bool ret = TestArith( r ); nKillChar( r ); return ret; } int main( int, char *argv[] ) { feInitResources(argv[0]); StringSetS("ressources in use (as reported by feStringAppendResources(0):\n"); feStringAppendResources(0); PrintS(StringAppendS("\n")); int c = 0; n_coeffType type; #ifdef HAVE_RINGS // TODO(Frank, Segmentation fault! (if used wihout omalloc???). Please_ investigate!); type = n_Z2m; if( Test(type, (void*) 4) ) c ++; #endif type = n_Zp; if( Test(type, (void*) 101) ) c ++; #ifdef HAVE_RINGS // TODO(Frank, memmory corruption_ if used wihout omalloc??? Please_ investigate!); type = n_Z2m; if( Test(type, (void*) 8) ) c ++; #endif type = n_Q; if( Test(type) ) c ++; type = n_R; if( Test(type) ) c ++; #ifdef HAVE_RINGS type = n_Z; if( Test(type) ) c ++; #endif type = n_GF; GFInfo* param = new GFInfo(); param->GFChar= 5; param->GFDegree= 12; param->GFPar_name= (const char*)"q"; if( Test(type, (void*) param) ) c ++; // it should not be used by numbers... right? // TODO: what is our policy wrt param-pointer-ownership? delete param; // Q: no way to deRegister a type? param = new GFInfo(); param->GFChar= 5; param->GFDegree= 2; param->GFPar_name= (const char*)"Q"; if( Test(type, (void*) param) ) c ++; delete param; #ifdef HAVE_RINGS // TODO(Somebody, This will result in memory corruption at Z_2^m later on (due to the succs. setGMPFloatDigits?)...!?); // ???? type = n_Zn; if( Test(type, (void*) 3) ) c ++; #endif TODO(Somebody, floating arithmetics via GMP rely on two global variables (see setGMPFloatDigits). Please fix it!); 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?)!???? type = n_long_C; if( Test(type) ) c ++; type = n_long_R; if( Test(type) ) c ++; #ifdef HAVE_RINGS type = n_Z2m; if( Test(type, (void*) 2) ) c ++; #endif #ifdef HAVE_RINGS type = n_Zn; if( Test(type, (void*) 3) ) c ++; #endif // polynomial rings needed for: n_algExt, n_transExt ! return c; }