Changeset ac00e2f in git for Singular/dyn_modules/syzextra/syzextra.cc
- Timestamp:
- May 14, 2014, 4:02:50 PM (10 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '98550b669234b32be762076c32b3be2c35188ac4')
- Children:
- 0f74a1d360bc1f2c80ba740d66bcf0a755b6e43d
- Parents:
- 8b5fff53b54b8c7889b6490e4871793cfd8e4efe
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/dyn_modules/syzextra/syzextra.cc
r8b5fff rac00e2f 1 1 // -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 2 /*****************************************************************************\ 3 * Computer Algebra System SINGULAR 3 * Computer Algebra System SINGULAR 4 4 \*****************************************************************************/ 5 5 /** @file syzextra.cc 6 * 6 * 7 7 * Here we implement the Computation of Syzygies 8 8 * … … 50 50 #include <Singular/attrib.h> 51 51 52 #include <Singular/ipid.h> 52 #include <Singular/ipid.h> 53 53 #include <Singular/ipshell.h> // For iiAddCproc 54 54 … … 73 73 static int cmp_c_ds(const void *p1, const void *p2) 74 74 { 75 void *R = currRing; 75 void *R = currRing; 76 76 #endif 77 77 … … 151 151 } 152 152 153 return 0; 154 } 155 156 153 return 0; 154 } 155 156 157 157 static int cmp_poly(const poly &a, const poly &b) 158 158 { … … 171 171 assume( p_GetComp(a, r) == 0 ); 172 172 assume( p_GetComp(b, r) == 0 ); 173 173 174 174 #ifndef NDEBUG 175 175 const int __DEBUG__ = 0; … … 198 198 } 199 199 200 return 0; 201 } 202 200 return 0; 201 } 202 203 203 END_NAMESPACE 204 204 /* namespace SORT_c_ds */ … … 213 213 return; 214 214 } 215 215 216 216 assume( r != NULL ); 217 217 const coeffs C = r->cf; assume(C != NULL); … … 221 221 222 222 do { 223 assume( p != NULL ); 224 223 assume( p != NULL ); 224 225 225 // write coef... 226 226 number& n = p_GetCoeff(p, r); 227 227 228 228 n_Normalize(n, C); 229 229 230 230 BOOLEAN writeMult = FALSE; ///< needs * before pp or module generator 231 231 232 232 BOOLEAN writeOne = FALSE; ///< need to write something after '-'! 233 233 234 234 if( n_IsZero(n, C) ) 235 235 { … … 237 237 // return; // yes? 238 238 } 239 239 240 240 if (n_IsMOne(n, C)) 241 { 241 { 242 242 PrintS(" - "); writeOne = TRUE; writePlus = FALSE; 243 } 243 } 244 244 else if (!n_IsOne(n, C)) 245 245 { 246 246 if( writePlus && n_GreaterZero(n, C) ) 247 247 PrintS(" + "); 248 249 StringSetS(""); n_WriteLong(n, C); 250 if (true) 248 249 StringSetS(""); n_WriteLong(n, C); 250 if (true) 251 251 { 252 252 char *s = StringEndS(); PrintS(s); omFree(s); 253 253 } 254 255 254 255 256 256 writeMult = TRUE; 257 257 writePlus = TRUE; 258 258 } else 259 259 writeOne = TRUE; 260 260 261 261 // missing '1' if no PP and gen...!? 262 262 // write monom... … … 268 268 { 269 269 const long ee = p_GetExp(p, i+1, r); 270 270 271 271 if (ee!=0L) 272 272 { … … 285 285 else 286 286 Print(" %s ", rRingVar(i, r)); 287 287 288 288 writeOne = FALSE; 289 289 wrotePP = TRUE; … … 292 292 293 293 writePlus = writePlus || wrotePP; 294 writeMult = writeMult || wrotePP; 294 writeMult = writeMult || wrotePP; 295 295 296 296 // write module gen... 297 297 const long comp = p_GetComp(p, r); 298 298 299 299 if (comp > 0 ) 300 300 { 301 301 if (writeMult) 302 302 PrintS(" \\\\cdot "); 303 else 303 else 304 304 if( writePlus ) 305 305 PrintS(" + "); … … 309 309 else 310 310 Print(" \\\\GENP{%ld} ", comp); 311 312 writeOne = FALSE; 313 } 314 311 312 writeOne = FALSE; 313 } 314 315 315 if ( writeOne ) 316 316 PrintS( writePlus? " + 1 " : " 1 " ); 317 317 318 318 319 319 pIter(p); 320 320 321 321 writePlus = TRUE; 322 322 } while( (!bLTonly) && (p != NULL) ); 323 324 } 325 326 327 328 329 323 324 } 325 326 327 328 329 330 330 /// return a new term: leading coeff * leading monomial of p 331 331 /// with 0 leading component! … … 346 346 p_Setm(m, r); 347 347 348 348 349 349 assume( m != NULL ); 350 350 assume( pNext(m) == NULL ); 351 351 assume( p_LmTest(m, r) ); 352 352 353 353 if( bSetZeroComp ) 354 354 assume( p_GetComp(m, r) == 0 ); … … 359 359 360 360 361 361 362 362 poly p_Tail(const poly p, const ring r) 363 363 { … … 375 375 376 376 const ideal newid = idInit(IDELEMS(id),id->rank); 377 377 378 378 for (int i=IDELEMS(id) - 1; i >= 0; i--) 379 379 newid->m[i] = p_Tail( id->m[i], r ); … … 381 381 newid->rank = id_RankFreeModule(newid, currRing); 382 382 383 return newid; 383 return newid; 384 384 } 385 385 … … 395 395 #define qsort_my(m, s, ss, r, cmp) qsort_r(m, s, ss, cmp) 396 396 #endif 397 397 398 398 if( sizeNew >= 2 ) 399 399 qsort_my(id->m, sizeNew, sizeof(poly), r, FROM_NAMESPACE(SORT_c_ds, cmp_c_ds)); … … 408 408 { 409 409 extern void id_Delete (ideal*, const ring); 410 410 411 411 id_Delete(const_cast<ideal*>(&m_idTails), m_rBaseRing); // TODO!!! 412 412 … … 422 422 m_spoly_bucket = NULL; 423 423 } 424 424 425 425 for( TCache::iterator it = m_cache.begin(); it != m_cache.end(); it++ ) 426 426 { 427 427 TP2PCache& T = it->second; 428 428 429 429 for(TP2PCache::iterator vit = T.begin(); vit != T.end(); vit++ ) 430 { 430 { 431 431 p_Delete( (&(vit->second)), m_rBaseRing); 432 432 p_Delete( const_cast<poly*>(&(vit->first)), m_rBaseRing); … … 465 465 CReducersHash::const_iterator itr = m_hash.find(comp); 466 466 467 if ( itr == m_hash.end() ) 467 if ( itr == m_hash.end() ) 468 468 return 2; // no such leading component!!! 469 469 470 470 assume( itr->first == comp ); 471 472 const bool bIdealCase = (comp == 0); 471 472 const bool bIdealCase = (comp == 0); 473 473 const bool bSyzCheck = syzChecker.IsNonempty(); // need to check even in ideal case????? proof? "&& !bIdealCase" 474 474 … … 485 485 const poly p = (*vit)->m_lt; 486 486 487 assume( p_GetComp(p, r) == comp ); 487 assume( p_GetComp(p, r) == comp ); 488 488 489 489 // TODO: check if coprime with Leads... if __TAILREDSYZ__ ! 490 490 for( int var = N; var > 0; --var ) 491 491 if( (p_GetExp(p, var, r) != 0) && (p_GetExp(t, var, r) != 0) ) 492 { 492 { 493 493 #ifndef NDEBUG 494 494 if( __DEBUG__ | 0) 495 { 495 { 496 496 PrintS("CReducerFinder::PreProcessTerm, 't' is NOT co-prime with the following leading term: \n"); 497 497 dPrint(p, r, r, 1); 498 498 } 499 #endif 499 #endif 500 500 coprime = false; // t not coprime with p! 501 501 break; … … 513 513 #ifndef NDEBUG 514 514 if( __DEBUG__ && !coprime) 515 { 515 { 516 516 PrintS("CReducerFinder::PreProcessTerm, 't' is co-prime with p but may lead to NOT divisible syz.term: \n"); 517 517 dPrint(ss, r, r, 1); 518 518 } 519 519 #endif 520 520 521 521 p_LmDelete(&ss, r); // deletes coeff as well??? 522 522 } … … 528 528 PrintS("CReducerFinder::PreProcessTerm, the following 't' is 'co-prime' with all of leading terms! \n"); 529 529 #endif 530 531 return coprime? 3: 0; // t was coprime with all of leading terms!!! 530 531 return coprime? 3: 0; // t was coprime with all of leading terms!!! 532 532 533 533 } … … 536 536 return 0; 537 537 } 538 539 538 539 540 540 void SchreyerSyzygyComputation::SetUpTailTerms() 541 541 { 542 const ideal idTails = m_idTails; 542 const ideal idTails = m_idTails; 543 543 assume( idTails != NULL ); 544 544 assume( idTails->m != NULL ); … … 557 557 for( int p = IDELEMS(idTails) - 1; p >= 0; --p ) 558 558 for( poly* tt = &(idTails->m[p]); (*tt) != NULL; ) 559 { 559 { 560 560 const poly t = *tt; 561 561 const int k = m_div.PreProcessTerm(t, m_checker); // 0..3 … … 565 565 pp[k]++; 566 566 #endif 567 567 568 568 if( k ) 569 569 { 570 570 #ifndef NDEBUG 571 571 if( __DEBUG__) 572 { 572 { 573 573 Print("SchreyerSyzygyComputation::SetUpTailTerms(): PP (%d) the following TT: \n", k); 574 574 dPrint(t, r, r, 1); … … 577 577 578 578 (*tt) = p_LmDeleteAndNext(t, r); // delete the lead and next... 579 } 580 else 579 } 580 else 581 581 tt = &pNext(t); // go next? 582 582 … … 588 588 Print("%% **!!** SchreyerSyzygyComputation::SetUpTailTerms()::PreProcessing(): X: {c: %lu, C: %lu, P: %lu} + %lu\n", pp[1], pp[2], pp[3], pp[0]); 589 589 #endif 590 590 591 591 #ifndef NDEBUG 592 592 if( !__TREEOUTPUT__ ) … … 597 597 } 598 598 #endif 599 600 } 601 /* 599 600 } 601 /* 602 602 m_idTailTerms.resize( IDELEMS(idTails) ); 603 603 604 604 for( unsigned int p = IDELEMS(idTails) - 1; p >= 0; p -- ) 605 605 { … … 609 609 610 610 unsigned int pp = 0; 611 611 612 612 while( t != NULL ) 613 613 { 614 614 assume( t != NULL ); 615 615 // TODO: compute L:t! 616 // ideal reducers; 616 // ideal reducers; 617 617 // CReducerFinder m_reducers 618 618 619 619 CTailTerm* d = v[pp] = new CTailTerm(); 620 620 621 621 ++pp; pIter(t); 622 622 } … … 649 649 if( size < 2 ) 650 650 { 651 const ideal newid = idInit(1, 0); newid->m[0] = NULL; // zero ideal... 651 const ideal newid = idInit(1, 0); newid->m[0] = NULL; // zero ideal... 652 652 return newid; 653 653 } … … 745 745 const ring& r = m_rBaseRing; 746 746 // const SchreyerSyzygyComputationFlags& attributes = m_atttributes; 747 747 748 748 // const BOOLEAN __DEBUG__ = attributes.__DEBUG__; 749 749 // const BOOLEAN __SYZCHECK__ = attributes.__SYZCHECK__; … … 751 751 // const BOOLEAN __HYBRIDNF__ = attributes.__HYBRIDNF__; 752 752 // const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__; 753 753 754 754 755 755 // 1. set of components S? … … 762 762 if( size < 2 ) 763 763 { 764 const ideal newid = idInit(1, 1); newid->m[0] = NULL; // zero module... 764 const ideal newid = idInit(1, 1); newid->m[0] = NULL; // zero module... 765 765 return newid; 766 766 } … … 768 768 769 769 // TODO/NOTE: input is supposed to be sorted wrt "C,ds"!?? 770 770 771 771 // components should come in groups: count elements in each group 772 772 // && estimate the real size!!! … … 863 863 // TEST_OPT_REDTAIL 864 864 assume( r == currRing ); 865 865 866 866 BITSET _save_test; SI_SAVE_OPT1(_save_test); 867 867 SI_RESTORE_OPT1(Sy_bit(OPT_REDTAIL) | Sy_bit(OPT_REDSB) | _save_test); 868 868 869 869 intvec* w=new intvec(IDELEMS(newid)); 870 ideal tmp = kStd(newid, curr Quotient, isHomog, &w);870 ideal tmp = kStd(newid, currRing->qideal, isHomog, &w); 871 871 delete w; 872 872 … … 887 887 888 888 Sort_c_ds(newid, r); 889 889 890 890 return newid; 891 891 } … … 898 898 const ring& R = m_rBaseRing; 899 899 900 const int r = p_GetComp(a, R) - 1; 900 const int r = p_GetComp(a, R) - 1; 901 901 902 902 assume( r >= 0 && r < IDELEMS(T) ); 903 903 assume( r >= 0 && r < IDELEMS(L) ); 904 905 assume( a != NULL ); 904 905 assume( a != NULL ); 906 906 907 907 if( __TREEOUTPUT__ ) … … 909 909 PrintS("{ \"nodelabel\": \""); writeLatexTerm(a, R); PrintS("\", \"children\": ["); 910 910 } 911 911 912 912 913 913 poly aa = leadmonom(a, R); assume( aa != NULL); // :( 914 914 915 poly t = TraverseTail(aa, r); 916 915 poly t = TraverseTail(aa, r); 916 917 917 if( a2 != NULL ) 918 918 { … … 929 929 assume( r2 >= 0 && r2 < IDELEMS(T) ); 930 930 931 t = p_Add_q(a2, p_Add_q(t, TraverseTail(aa2, r2), R), R); 931 t = p_Add_q(a2, p_Add_q(t, TraverseTail(aa2, r2), R), R); 932 932 933 933 p_Delete(&aa2, R); 934 934 935 935 if( __TREEOUTPUT__ ) 936 936 PrintS("]},"); … … 946 946 { 947 947 PrintS("], \"noderesult\": \""); writeLatexTerm(t, R, true, false); PrintS("\" },"); 948 } 948 } 949 949 return t; 950 950 } … … 971 971 assume( IDELEMS(L) == IDELEMS(T) ); 972 972 #ifndef NDEBUG 973 int t, r; 973 int t, r; 974 974 #endif 975 975 976 976 if( __TREEOUTPUT__ ) 977 977 { 978 Print("\n{ \"syzygylayer\": \"%d\", \"hybridnf\": \"%d\", \"diagrams\": \n[", __SYZNUMBER__, __HYBRIDNF__ ); 979 } 980 978 Print("\n{ \"syzygylayer\": \"%d\", \"hybridnf\": \"%d\", \"diagrams\": \n[", __SYZNUMBER__, __HYBRIDNF__ ); 979 } 980 981 981 if( m_syzLeads == NULL ) 982 { 982 { 983 983 #ifndef NDEBUG 984 984 if( !__TREEOUTPUT__ ) … … 988 988 Print("%% %5d **!TIME4!** SchreyerSyzygyComputation::ComputeSyzygy::ComputeLeadingSyzygyTerms: t: %d, r: %d\n", r, t, r); 989 989 } 990 #endif 990 #endif 991 991 ComputeLeadingSyzygyTerms( __LEAD2SYZ__ && !__IGNORETAILS__ ); // 2 terms OR 1 term! 992 992 #ifndef NDEBUG … … 998 998 } 999 999 #endif 1000 1000 1001 1001 } 1002 1002 … … 1010 1010 { 1011 1011 if( __TREEOUTPUT__ ) 1012 PrintS("]},"); 1012 PrintS("]},"); 1013 1013 return; 1014 1014 } 1015 1015 1016 1016 1017 1017 // use hybrid method? … … 1030 1030 } 1031 1031 #endif 1032 1032 1033 1033 SetUpTailTerms(); 1034 1034 #ifndef NDEBUG … … 1040 1040 } 1041 1041 #endif 1042 } 1042 } 1043 1043 } 1044 1044 … … 1051 1051 } 1052 1052 #endif 1053 1053 1054 1054 for( int k = size - 1; k >= 0; k-- ) 1055 1055 { 1056 1056 const poly a = LL->m[k]; assume( a != NULL ); 1057 1057 1058 poly a2 = pNext(a); 1058 poly a2 = pNext(a); 1059 1059 1060 1060 // Splitting 2-terms Leading syzygy module 1061 1061 if( a2 != NULL ) 1062 1062 pNext(a) = NULL; 1063 1063 1064 1064 if( __IGNORETAILS__ ) 1065 1065 { … … 1089 1089 Print("%% %5d **!TIME4!** SchreyerSyzygyComputation::ComputeSyzygy::SyzygyLift: dt: %d, dr: %d\n", getRTimer(), t, r); 1090 1090 } 1091 #endif 1091 #endif 1092 1092 1093 1093 TT->rank = id_RankFreeModule(TT, R); 1094 1094 1095 1095 if( __TREEOUTPUT__ ) 1096 1096 PrintS("\n]},"); … … 1115 1115 { 1116 1116 assume( !__LEAD2SYZ__ ); 1117 1117 1118 1118 m_syzLeads = Compute1LeadingSyzygyTerms(); 1119 1119 } 1120 1120 // m_syzLeads = FROM_NAMESPACE(INTERNAL, _ComputeLeadingSyzygyTerms(m_idLeads, m_rBaseRing, m_atttributes)); 1121 1121 1122 1122 // NOTE: set m_LS if tails are to be reduced! 1123 1123 assume( m_syzLeads!= NULL ); … … 1127 1127 m_LS = m_syzLeads; 1128 1128 m_checker.Initialize(m_syzLeads); 1129 #ifndef NDEBUG 1129 #ifndef NDEBUG 1130 1130 if( __DEBUG__ ) 1131 1131 { … … 1146 1146 poly SchreyerSyzygyComputation::SchreyerSyzygyNF(const poly syz_lead, poly syz_2) const 1147 1147 { 1148 1148 1149 1149 assume( !__IGNORETAILS__ ); 1150 1150 … … 1160 1160 PrintS("{ \"nodelabel\": \""); writeLatexTerm(syz_lead, r); PrintS("\", \"children\": ["); 1161 1161 } 1162 1162 1163 1163 if( syz_2 == NULL ) 1164 1164 { 1165 const int rr = p_GetComp(syz_lead, r) - 1; 1165 const int rr = p_GetComp(syz_lead, r) - 1; 1166 1166 1167 1167 assume( rr >= 0 && rr < IDELEMS(T) ); … … 1175 1175 PrintS("{ \"nodelabel\": \""); writeLatexTerm(syz_2, r); PrintS("\" },"); 1176 1176 } 1177 #else 1177 #else 1178 1178 poly aa = leadmonom(syz_lead, r); assume( aa != NULL); // :( 1179 1179 aa = p_Mult_mm(aa, L->m[rr], r); … … 1183 1183 PrintS("{ \"nodelabel\": \""); writeLatexTerm(syz_2, r); PrintS("\", \"edgelable\": \""); writeLatexTerm(aa, r, false); PrintS("\" },"); 1184 1184 } 1185 1185 1186 1186 syz_2 = m_div.FindReducer(aa, syz_lead, m_checker); 1187 1187 1188 1188 p_Delete(&aa, r); 1189 1189 #endif 1190 1191 } 1192 1193 assume( syz_2 != NULL ); // by construction of S-Polynomial 1190 1191 } 1192 1193 assume( syz_2 != NULL ); // by construction of S-Polynomial 1194 1194 1195 1195 assume( L != NULL ); … … 1213 1213 1214 1214 // kBucketInit(bucket, NULL, 0); // not needed!? 1215 1216 poly p = leadmonom(syz_lead, r); // :( 1217 // poly spoly = pp_Mult_qq(p, T->m[c], r); 1218 kBucket_Plus_mm_Mult_pp(bucket, p, T->m[c], 0); // TODO: store pLength(T->m[c]) separately!? 1215 1216 poly p = leadmonom(syz_lead, r); // :( 1217 // poly spoly = pp_Mult_qq(p, T->m[c], r); 1218 kBucket_Plus_mm_Mult_pp(bucket, p, T->m[c], 0); // TODO: store pLength(T->m[c]) separately!? 1219 1219 p_Delete(&p, r); 1220 1221 kbTest(bucket); 1220 1221 kbTest(bucket); 1222 1222 1223 1223 c = p_GetComp(syz_2, r) - 1; … … 1232 1232 // TODO: use bucket!? 1233 1233 // const bool bUsePolynomial = TEST_OPT_NOT_BUCKETS; // || (pLength(spoly) < MIN_LENGTH_BUCKET); 1234 // CPolynomialSummator tail(r, bUsePolynomial); 1235 sBucket_Add_p(tail, syz_2, 1); // tail.AddAndDelete(syz_2, 1); 1236 1234 // CPolynomialSummator tail(r, bUsePolynomial); 1235 sBucket_Add_p(tail, syz_2, 1); // tail.AddAndDelete(syz_2, 1); 1236 1237 1237 kbTest(bucket); 1238 1238 for( poly spoly = kBucketExtractLm(bucket); spoly != NULL; p_LmDelete(&spoly, r), spoly = kBucketExtractLm(bucket)) 1239 { 1239 { 1240 1240 kbTest(bucket); 1241 poly t = m_div.FindReducer(spoly, NULL, m_checker); 1241 poly t = m_div.FindReducer(spoly, NULL, m_checker); 1242 1242 1243 1243 if( t != NULL ) … … 1247 1247 1248 1248 assume( c >= 0 && c < IDELEMS(T) ); 1249 1249 1250 1250 if( __TREEOUTPUT__ ) 1251 1251 { … … 1270 1270 sBucketClearAdd(tail, &result, &len); // TODO: use Merge with sBucket??? 1271 1271 assume( pLength(result) == len ); 1272 1272 1273 1273 if( __TREEOUTPUT__ ) 1274 { 1274 { 1275 1275 PrintS("]},"); 1276 1276 } 1277 1277 1278 1278 1279 1279 return result; 1280 1280 } 1281 1281 1282 // namespace { 1282 // namespace { 1283 1283 1284 1284 // }; … … 1291 1291 { 1292 1292 const ring& r = m_rBaseRing; 1293 1293 1294 1294 assume(m_idTails != NULL && m_idTails->m != NULL); 1295 1295 assume( tail >= 0 && tail < IDELEMS(m_idTails) ); 1296 1296 1297 1297 /* return ComputeImage(multiplier, tail); */ 1298 1298 1299 1299 // TODO: store (multiplier, tail) -.-^-.-^-.--> ! 1300 1300 TCache::iterator top_itr = m_cache.find(tail); 1301 1301 1302 1302 if ( top_itr != m_cache.end() ) 1303 1303 { … … 1305 1305 1306 1306 TP2PCache& T = top_itr->second; 1307 1307 1308 1308 TP2PCache::iterator itr = T.find(multiplier); 1309 1309 1310 1310 if( itr != T.end() ) // Yey - Reuse!!! 1311 1311 { 1312 1312 assume( p_LmEqual(itr->first, multiplier, r) ); 1313 1313 1314 1314 if( itr->second == NULL ) 1315 1316 1315 return (NULL); 1316 1317 1317 poly p = p_Copy(itr->second, r); // no copy??? 1318 1318 1319 1319 if( __TREEOUTPUT__ ) 1320 1320 { 1321 // PrintS("{ \"nodelabel\": \""); writeLatexTerm(multiplier, r, false); 1321 // PrintS("{ \"nodelabel\": \""); writeLatexTerm(multiplier, r, false); 1322 1322 // Print(" \\\\cdot \\\\GEN{%d}\", \"children\": [ ", tail + 1); 1323 1324 1323 Print("{ \"lookedupnode\": \"1\", \"nodelabel\": \""); 1324 writeLatexTerm(p, r, true, false); 1325 1325 } 1326 1326 1327 1327 if( !n_Equal( pGetCoeff(multiplier), pGetCoeff(itr->first), r) ) // normalize coeffs!? 1328 1328 { 1329 number n = n_Div( pGetCoeff(multiplier), pGetCoeff(itr->first), r); 1330 p = p_Mult_nn(p, n, r); 1329 number n = n_Div( pGetCoeff(multiplier), pGetCoeff(itr->first), r); 1330 p = p_Mult_nn(p, n, r); 1331 1331 n_Delete(&n, r); 1332 1332 1333 1333 if( __TREEOUTPUT__ ) 1334 1334 Print("\", \"RESCALEDRESULT\": \"1\" },"); … … 1338 1338 Print("\", \"RESCALEDRESULT\": \"0\" },"); 1339 1339 } 1340 1340 1341 1341 return p; 1342 1342 } … … 1345 1345 { 1346 1346 // PrintS("{ \"nodelabel\": \""); writeLatexTerm(multiplier, r, false); Print(" \\\\cdot \\\\GEN{%d}\", \"children\": [", tail + 1); 1347 } 1348 1347 } 1348 1349 1349 const poly p = ComputeImage(multiplier, tail); 1350 1350 T.insert( TP2PCache::value_type(p_Copy(multiplier, r), p) ); // T[ multiplier ] = p; … … 1352 1352 // if( p == NULL ) 1353 1353 // return (NULL); 1354 1354 1355 1355 if( __TREEOUTPUT__ ) 1356 1356 { 1357 // 1357 // PrintS("], \"storedResult\": \""); writeLatexTerm(p, r, true, false); PrintS("\" },"); 1358 1358 } 1359 1359 1360 1360 return p_Copy(p, r); 1361 1361 } 1362 1362 1363 1363 CCacheCompare o(r); TP2PCache T(o); 1364 1364 … … 1367 1367 // PrintS("{ \"nodelabel\": \""); writeLatexTerm(multiplier, r, false); Print(" \\\\cdot \\\\GEN{%d}\", \"children\": [", tail + 1); 1368 1368 } 1369 1370 1369 1370 1371 1371 const poly p = ComputeImage(multiplier, tail); 1372 1372 1373 1373 T.insert( TP2PCache::value_type(p_Copy(multiplier, r), p) ); 1374 1374 1375 1375 m_cache.insert( TCache::value_type(tail, T) ); 1376 1376 1377 1377 // if( p == NULL ) 1378 1378 // return (NULL); 1379 1379 1380 1380 if( __TREEOUTPUT__ ) 1381 1381 { 1382 1382 // PrintS("], \"storedResult\": \""); writeLatexTerm(p, r, true, false); PrintS("\" },"); 1383 1383 } 1384 1384 1385 1385 return p_Copy(p, r); 1386 1386 } … … 1396 1396 } 1397 1397 1398 1398 1399 1399 poly SchreyerSyzygyComputation::TraverseTail(poly multiplier, poly tail) const 1400 1400 { … … 1419 1419 sBucket_pt& sum = m_sum_bucket; assume( sum != NULL ); 1420 1420 poly s; int len; 1421 1421 1422 1422 // CPolynomialSummator sum(r, bUsePolynomial); 1423 1423 // poly s = NULL; … … 1431 1431 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1432 1432 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1433 1433 1434 1434 const int lp = pLength(rt); 1435 1435 if( rt != NULL && lp != 0 ) 1436 sBucket_Add_p(sum, rt, lp); 1436 sBucket_Add_p(sum, rt, lp); 1437 1437 } 1438 1438 … … 1474 1474 if( s == NULL ) // No Reducer? 1475 1475 return s; 1476 1476 1477 1477 if( __TREEOUTPUT__ ) 1478 1478 { 1479 PrintS("{ \"nodelabel\": \""); writeLatexTerm(s, r); 1480 } 1481 1482 #else 1479 PrintS("{ \"nodelabel\": \""); writeLatexTerm(s, r); 1480 } 1481 1482 #else 1483 1483 // NOTE: only LT(term4reduction) should be used in the following: 1484 1484 poly product = pp_Mult_mm(multiplier, term4reduction, r); … … 1487 1487 if( s == NULL ) // No Reducer? 1488 1488 return s; 1489 1489 1490 1490 if( __TREEOUTPUT__ ) 1491 1491 { 1492 PrintS("{ \"nodelabel\": \""); writeLatexTerm(s, r); PrintS("\", \"edgelable\": \""); writeLatexTerm(product, r, false); 1493 } 1494 1492 PrintS("{ \"nodelabel\": \""); writeLatexTerm(s, r); PrintS("\", \"edgelable\": \""); writeLatexTerm(product, r, false); 1493 } 1494 1495 1495 p_Delete(&product, r); 1496 1496 #endif … … 1499 1499 if( s == NULL ) // No Reducer? 1500 1500 return s; 1501 1501 1502 1502 1503 1503 poly b = leadmonom(s, r); … … 1506 1506 assume( c >= 0 && c < IDELEMS(T) ); 1507 1507 1508 1508 1509 1509 if( __TREEOUTPUT__ ) 1510 1510 PrintS("\", \"children\": ["); 1511 1511 1512 1512 const poly t = TraverseTail(b, c); // T->m[c]; 1513 1513 1514 1514 if( t != NULL ) 1515 s = p_Add_q(s, t, r); 1515 s = p_Add_q(s, t, r); 1516 1516 1517 1517 if( __TREEOUTPUT__ ) 1518 1518 { 1519 1519 1520 1520 PrintS("], \"noderesult\": \""); 1521 writeLatexTerm(s, r, true, false); 1521 writeLatexTerm(s, r, true, false); 1522 1522 PrintS("\" },"); 1523 1523 } 1524 1524 1525 1525 return s; 1526 1526 } … … 1531 1531 1532 1532 BEGIN_NAMESPACE_NONAME 1533 1533 1534 1534 static inline int atGetInt(idhdl rootRingHdl, const char* attribute, long def) 1535 1535 { … … 1537 1537 } 1538 1538 1539 END_NAMESPACE 1540 1541 1539 END_NAMESPACE 1540 1541 1542 1542 SchreyerSyzygyComputationFlags::SchreyerSyzygyComputationFlags(idhdl rootRingHdl): 1543 1543 #ifndef NDEBUG … … 1547 1547 #endif 1548 1548 // __SYZCHECK__( (BOOLEAN)atGetInt(rootRingHdl, "SYZCHECK", __DEBUG__) ), 1549 __LEAD2SYZ__( atGetInt(rootRingHdl, "LEAD2SYZ", 1) ), 1550 __TAILREDSYZ__( atGetInt(rootRingHdl, "TAILREDSYZ", 1) ), 1549 __LEAD2SYZ__( atGetInt(rootRingHdl, "LEAD2SYZ", 1) ), 1550 __TAILREDSYZ__( atGetInt(rootRingHdl, "TAILREDSYZ", 1) ), 1551 1551 __HYBRIDNF__( atGetInt(rootRingHdl, "HYBRIDNF", 2) ), 1552 1552 __IGNORETAILS__( atGetInt(rootRingHdl, "IGNORETAILS", 0) ), … … 1554 1554 __TREEOUTPUT__( atGetInt(rootRingHdl, "TREEOUTPUT", 0) ), 1555 1555 m_rBaseRing( rootRingHdl->data.uring ) 1556 { 1556 { 1557 1557 #ifndef NDEBUG 1558 1558 if( __DEBUG__ ) … … 1568 1568 } 1569 1569 #endif 1570 1570 1571 1571 // TODO: just current setting! 1572 1572 assume( rootRingHdl == currRingHdl ); … … 1576 1576 } 1577 1577 1578 1578 1579 1579 1580 1580 CLeadingTerm::CLeadingTerm(unsigned int _label, const poly _lt, const ring R): … … 1601 1601 1602 1602 assume( m_L == L ); 1603 1603 1604 1604 if( L != NULL ) 1605 1605 { 1606 1606 const ring& R = m_rBaseRing; 1607 1607 assume( R != NULL ); 1608 1608 1609 1609 for( int k = IDELEMS(L) - 1; k >= 0; k-- ) 1610 1610 { … … 1685 1685 const unsigned long p_sev = m_sev; 1686 1686 1687 assume( p_sev == p_GetShortExpVector(p, r) ); 1687 assume( p_sev == p_GetShortExpVector(p, r) ); 1688 1688 1689 1689 return p_LmShortDivisibleByNoComp(p, p_sev, product, not_sev, r); … … 1704 1704 1705 1705 const unsigned long p_sev = m_sev; 1706 assume( p_sev == p_GetShortExpVector(p, r) ); 1706 assume( p_sev == p_GetShortExpVector(p, r) ); 1707 1707 1708 1708 if (p_sev & not_sev) … … 1720 1720 class CDivisorEnumerator: public SchreyerSyzygyComputationFlags 1721 1721 { 1722 private: 1722 private: 1723 1723 const CReducerFinder& m_reds; 1724 1724 const poly m_product; … … 1742 1742 { 1743 1743 assume( m_comp >= 0 ); 1744 assume( m_reds.m_L != NULL ); 1744 assume( m_reds.m_L != NULL ); 1745 1745 } 1746 1746 … … 1748 1748 { 1749 1749 m_active = false; 1750 1750 1751 1751 m_itr = m_reds.m_hash.find(m_comp); 1752 1752 … … 1763 1763 1764 1764 // m_active = true; 1765 return true; 1765 return true; 1766 1766 } 1767 1767 … … 1773 1773 return *(*m_current); 1774 1774 } 1775 1775 1776 1776 inline bool MoveNext() 1777 1777 { … … 1782 1782 else 1783 1783 m_active = true; // for Current() 1784 1784 1785 1785 // looking for the next good entry 1786 1786 for( ; m_current != m_finish; ++m_current ) … … 1804 1804 // the end... :( 1805 1805 assume( m_current == m_finish ); 1806 1806 1807 1807 m_active = false; 1808 1808 return false; … … 1819 1819 1820 1820 return itr.MoveNext(); 1821 1822 /* 1821 1822 /* 1823 1823 const ring& r = m_rBaseRing; 1824 1824 1825 1825 const long comp = p_GetComp(product, r); 1826 1826 const unsigned long not_sev = ~p_GetShortExpVector(product, r); … … 1830 1830 CReducersHash::const_iterator it = m_hash.find(comp); // same module component 1831 1831 1832 assume( m_L != NULL ); 1832 assume( m_L != NULL ); 1833 1833 1834 1834 if( it == m_hash.end() ) 1835 1835 return false; 1836 1836 // assume comp! 1837 1837 1838 1838 const TReducers& reducers = it->second; 1839 1839 … … 1855 1855 1856 1856 return false; 1857 */ 1857 */ 1858 1858 } 1859 1859 … … 1892 1892 class CDivisorEnumerator2: public SchreyerSyzygyComputationFlags 1893 1893 { 1894 private: 1894 private: 1895 1895 const CReducerFinder& m_reds; 1896 1896 const poly m_multiplier, m_term; … … 1914 1914 { 1915 1915 assume( m_comp >= 0 ); 1916 assume( m_reds.m_L != NULL ); 1917 assume( m_multiplier != NULL ); 1916 assume( m_reds.m_L != NULL ); 1917 assume( m_multiplier != NULL ); 1918 1918 assume( m_term != NULL ); 1919 1919 // assume( p_GetComp(m_multiplier, m_rBaseRing) == 0 ); … … 1923 1923 { 1924 1924 m_active = false; 1925 1926 m_itr = m_reds.m_hash.find(m_comp); 1925 1926 m_itr = m_reds.m_hash.find(m_comp); 1927 1927 1928 1928 if( m_itr == m_reds.m_hash.end() ) … … 1937 1937 return false; 1938 1938 1939 return true; 1939 return true; 1940 1940 } 1941 1941 … … 1947 1947 return *(*m_current); 1948 1948 } 1949 1949 1950 1950 inline bool MoveNext() 1951 1951 { … … 1954 1954 if( m_active ) 1955 1955 ++m_current; 1956 else 1956 else 1957 1957 m_active = true; 1958 1959 1958 1959 1960 1960 // looking for the next good entry 1961 1961 for( ; m_current != m_finish; ++m_current ) … … 1974 1974 // m_active = true; 1975 1975 return true; 1976 1976 1977 1977 } 1978 1978 } … … 1980 1980 // the end... :( 1981 1981 assume( m_current == m_finish ); 1982 1982 1983 1983 m_active = false; 1984 1984 return false; 1985 1985 } 1986 1986 }; 1987 1987 1988 1988 poly CReducerFinder::FindReducer(const poly multiplier, const poly t, 1989 1989 const poly syzterm, … … 2018 2018 2019 2019 poly pr = p_Mult_q( leadmonom(multiplier, r, false), leadmonom(t, r, false), r); 2020 2020 2021 2021 assume( p_EqualPolys(lm, pr, r) ); 2022 2022 … … 2024 2024 // def @@product = leadmonomial(syzterm) * L[@@r]; 2025 2025 2026 p_Delete(&lm, r); 2027 p_Delete(&pr, r); 2028 } 2029 2030 const BOOLEAN to_check = (syz_checker.IsNonempty()); // __TAILREDSYZ__ && 2026 p_Delete(&lm, r); 2027 p_Delete(&pr, r); 2028 } 2029 2030 const BOOLEAN to_check = (syz_checker.IsNonempty()); // __TAILREDSYZ__ && 2031 2031 2032 2032 const poly q = p_New(r); pNext(q) = NULL; … … 2039 2039 const poly p = itr.Current().m_lt; 2040 2040 const int k = itr.Current().m_label; 2041 2041 2042 2042 p_ExpVectorSum(q, multiplier, t, r); // q == product == multiplier * t // TODO: do it once? 2043 2043 p_ExpVectorDiff(q, q, p, r); // (LM(product) / LM(L[k])) 2044 2044 2045 2045 p_SetComp(q, k + 1, r); 2046 2046 p_Setm(q, r); … … 2055 2055 Print("_FindReducer::Test SYZTERM: q == syzterm !:((, syzterm is: "); 2056 2056 dPrint(syzterm, r, r, 1); 2057 } 2057 } 2058 2058 #endif 2059 2059 continue; 2060 2060 } 2061 2061 2062 // while the complement (the fraction) is not reducible by leading syzygies 2063 if( to_check && syz_checker.IsDivisible(q) ) 2062 // while the complement (the fraction) is not reducible by leading syzygies 2063 if( to_check && syz_checker.IsDivisible(q) ) 2064 2064 { 2065 2065 #ifndef NDEBUG … … 2075 2075 p_SetCoeff0(q, n_Neg( n_Div(n, p_GetCoeff(p, r), r), r), r); 2076 2076 n_Delete(&n, r); 2077 2077 2078 2078 return q; 2079 2079 } 2080 2080 2081 2081 /* 2082 2082 const long comp = p_GetComp(t, r); assume( comp >= 0 ); … … 2086 2086 // { 2087 2087 // const poly p = L->m[k]; 2088 // 2088 // 2089 2089 // if ( p_GetComp(p, r) != comp ) 2090 2090 // continue; 2091 // 2091 // 2092 2092 // const unsigned long p_sev = p_GetShortExpVector(p, r); // to be stored in m_hash!!! 2093 2093 … … 2099 2099 2100 2100 // assume comp! 2101 2101 2102 2102 assume( m_L != NULL ); 2103 2103 … … 2113 2113 2114 2114 // const unsigned long p_sev = (*vit)->m_sev; 2115 // assume( p_sev == p_GetShortExpVector(p, r) ); 2115 // assume( p_sev == p_GetShortExpVector(p, r) ); 2116 2116 2117 2117 // if( !p_LmShortDivisibleByNoComp(p, p_sev, product, not_sev, r) ) 2118 // continue; 2118 // continue; 2119 2119 2120 2120 if( !(*vit)->DivisibilityCheck(multiplier, t, not_sev, r) ) 2121 2121 continue; 2122 2123 2122 2123 2124 2124 // if (p_sev & not_sev) continue; 2125 // if( !_p_LmDivisibleByNoComp(p, multiplier, t, r) ) continue; 2126 2127 2128 p_ExpVectorSum(q, multiplier, t, r); // q == product == multiplier * t 2125 // if( !_p_LmDivisibleByNoComp(p, multiplier, t, r) ) continue; 2126 2127 2128 p_ExpVectorSum(q, multiplier, t, r); // q == product == multiplier * t 2129 2129 p_ExpVectorDiff(q, q, p, r); // (LM(product) / LM(L[k])) 2130 2130 2131 2131 p_SetComp(q, k + 1, r); 2132 2132 p_Setm(q, r); … … 2140 2140 Print("_FindReducer::Test SYZTERM: q == syzterm !:((, syzterm is: "); 2141 2141 dPrint(syzterm, r, r, 1); 2142 } 2142 } 2143 2143 2144 2144 continue; 2145 2145 } 2146 2146 2147 // while the complement (the fraction) is not reducible by leading syzygies 2148 if( to_check && syz_checker.IsDivisible(q) ) 2147 // while the complement (the fraction) is not reducible by leading syzygies 2148 if( to_check && syz_checker.IsDivisible(q) ) 2149 2149 { 2150 2150 if( __DEBUG__ ) … … 2159 2159 p_SetCoeff0(q, n_Neg( n_Div(n, p_GetCoeff(p, r), r), r), r); 2160 2160 n_Delete(&n, r); 2161 2161 2162 2162 return q; 2163 2163 } 2164 */ 2164 */ 2165 2165 2166 2166 p_LmFree(q, r); 2167 2167 2168 2168 return NULL; 2169 2169 2170 2170 } 2171 2171 … … 2203 2203 // def @@product = leadmonomial(syzterm) * L[@@r]; 2204 2204 2205 p_Delete(&lm, r); 2206 } 2207 2208 2209 const BOOLEAN to_check = (syz_checker.IsNonempty()); // __TAILREDSYZ__ && 2205 p_Delete(&lm, r); 2206 } 2207 2208 2209 const BOOLEAN to_check = (syz_checker.IsNonempty()); // __TAILREDSYZ__ && 2210 2210 2211 2211 const poly q = p_New(r); pNext(q) = NULL; … … 2218 2218 const poly p = itr.Current().m_lt; 2219 2219 const int k = itr.Current().m_label; 2220 2220 2221 2221 p_ExpVectorDiff(q, product, p, r); // (LM(product) / LM(L[k])) 2222 2222 p_SetComp(q, k + 1, r); … … 2232 2232 Print("_FindReducer::Test SYZTERM: q == syzterm !:((, syzterm is: "); 2233 2233 dPrint(syzterm, r, r, 1); 2234 } 2234 } 2235 2235 #endif 2236 2236 continue; 2237 2237 } 2238 2238 2239 // while the complement (the fraction) is not reducible by leading syzygies 2240 if( to_check && syz_checker.IsDivisible(q) ) 2239 // while the complement (the fraction) is not reducible by leading syzygies 2240 if( to_check && syz_checker.IsDivisible(q) ) 2241 2241 { 2242 2242 #ifndef NDEBUG … … 2250 2250 2251 2251 p_SetCoeff0(q, n_Neg( n_Div( p_GetCoeff(product, r), p_GetCoeff(p, r), r), r), r); 2252 2252 2253 2253 return q; 2254 2254 } 2255 2256 2257 2258 /* 2255 2256 2257 2258 /* 2259 2259 const long comp = p_GetComp(product, r); 2260 2260 const unsigned long not_sev = ~p_GetShortExpVector(product, r); … … 2265 2265 // { 2266 2266 // const poly p = L->m[k]; 2267 // 2267 // 2268 2268 // if ( p_GetComp(p, r) != comp ) 2269 2269 // continue; 2270 // 2270 // 2271 2271 // const unsigned long p_sev = p_GetShortExpVector(p, r); // to be stored in m_hash!!! 2272 2272 2273 2273 // looking for an appropriate diviser p = L[k]... 2274 2274 CReducersHash::const_iterator it = m_hash.find(comp); // same module component … … 2281 2281 const TReducers& reducers = it->second; 2282 2282 2283 const BOOLEAN to_check = (syz_checker.IsNonempty()); // __TAILREDSYZ__ && 2283 const BOOLEAN to_check = (syz_checker.IsNonempty()); // __TAILREDSYZ__ && 2284 2284 2285 2285 const poly q = p_New(r); pNext(q) = NULL; … … 2287 2287 if( __DEBUG__ ) 2288 2288 p_SetCoeff0(q, 0, r); // for printing q 2289 2289 2290 2290 for(TReducers::const_iterator vit = reducers.begin(); vit != reducers.end(); vit++ ) 2291 2291 { … … 2300 2300 const unsigned long p_sev = (*vit)->m_sev; 2301 2301 2302 assume( p_sev == p_GetShortExpVector(p, r) ); 2302 assume( p_sev == p_GetShortExpVector(p, r) ); 2303 2303 2304 2304 if( !p_LmShortDivisibleByNoComp(p, p_sev, product, not_sev, r) ) 2305 continue; 2305 continue; 2306 2306 2307 2307 // // ... which divides the product, looking for the _1st_ appropriate one! … … 2321 2321 Print("_FindReducer::Test SYZTERM: q == syzterm !:((, syzterm is: "); 2322 2322 dPrint(syzterm, r, r, 1); 2323 } 2323 } 2324 2324 2325 2325 continue; 2326 2326 } 2327 2327 2328 // while the complement (the fraction) is not reducible by leading syzygies 2329 if( to_check && syz_checker.IsDivisible(q) ) 2328 // while the complement (the fraction) is not reducible by leading syzygies 2329 if( to_check && syz_checker.IsDivisible(q) ) 2330 2330 { 2331 2331 if( __DEBUG__ ) … … 2333 2333 PrintS("_FindReducer::Test LS: q is divisible by LS[?] !:((: "); 2334 2334 } 2335 2335 2336 2336 continue; 2337 2337 } … … 2376 2376 } 2377 2377 2378 m_compute = true; 2378 m_compute = true; 2379 2379 } 2380 2380 } … … 2385 2385 assume( m != NULL ); 2386 2386 if( m_compute && (m != NULL)) 2387 { 2387 { 2388 2388 const ring& R = m_rBaseRing; 2389 2389 … … 2400 2400 } 2401 2401 2402 CCacheCompare::CCacheCompare(): m_ring(currRing) {} 2402 CCacheCompare::CCacheCompare(): m_ring(currRing) {} 2403 2403 2404 2404
Note: See TracChangeset
for help on using the changeset viewer.