Singular https://www.singular.uni-kl.de/forum/ |
|
ksReducePoly and loop construct [SOLVED] https://www.singular.uni-kl.de/forum/viewtopic.php?f=10&t=1941 |
Page 1 of 1 |
Author: | bschnitz [ Thu Jul 07, 2011 4:45 pm ] |
Post subject: | ksReducePoly and loop construct [SOLVED] |
Hello, i have two technical questions concerning some code from the singular kernel. 1.) In kInline.cc kspoly.cc a function named ksOldSpolyRed invokes the function ksReducePoly with 3 Arguments: Code: //extracted from kInline.cc ,KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether) { LObject L(p2); TObject T(p1); ksReducePoly(&L, &T, spNoether); return L.GetLmCurrRing(); } but i can find no definition of ksReducePoly, which need less than 5 Arguments. The only definition i can find (in kspoly.cc) needs 5 Argument (and none of it is optional). Where can i find the appropriate definition needed for ksOldSpolyRed? (I am sorry for spamming with code here, i don't really believe it will be necessary for you to review it, but i give it for the sake of completeness.) Code: //extracted from kspoly.cc /*************************************************************** * * Reduces PR with PW * Assumes PR != NULL, PW != NULL, Lm(PW) divides Lm(PR) * ***************************************************************/ int ksReducePoly(LObject* PR, TObject* PW, poly spNoether, number *coef, kStrategy strat) { #ifdef KDEBUG red_count++; #ifdef TEST_OPT_DEBUG_RED if (TEST_OPT_DEBUG) { Print("Red %d:", red_count); PR->wrp(); Print(" with:"); PW->wrp(); } #endif #endif int ret = 0; ring tailRing = PR->tailRing; kTest_L(PR); kTest_T(PW); poly p1 = PR->GetLmTailRing(); // p2 | p1 poly p2 = PW->GetLmTailRing(); // i.e. will reduce p1 with p2; lm = LT(p1) / LM(p2) poly t2 = pNext(p2), lm = p1; // t2 = p2 - LT(p2); really compute P = LC(p2)*p1 - LT(p1)/LM(p2)*p2 assume(p1 != NULL && p2 != NULL);// Attention, we have rings and there LC(p2) and LC(p1) are special p_CheckPolyRing(p1, tailRing); p_CheckPolyRing(p2, tailRing); pAssume1(p2 != NULL && p1 != NULL && p_DivisibleBy(p2, p1, tailRing)); pAssume1(p_GetComp(p1, tailRing) == p_GetComp(p2, tailRing) || (p_GetComp(p2, tailRing) == 0 && p_MaxComp(pNext(p2),tailRing) == 0)); #ifdef HAVE_PLURAL if (rIsPluralRing(currRing)) { // for the time being: we know currRing==strat->tailRing // no exp-bound checking needed // (only needed if exp-bound(tailring)<exp-b(currRing)) if (PR->bucket!=NULL) nc_kBucketPolyRed(PR->bucket, p2,coef); else { poly _p = (PR->t_p != NULL ? PR->t_p : PR->p); assume(_p != NULL); nc_PolyPolyRed(_p, p2,coef); if (PR->t_p!=NULL) PR->t_p=_p; else PR->p=_p; PR->pLength=0; // usaully not used, GetpLength re-comoutes it if needed } return 0; } #endif if (t2==NULL) // Divisor is just one term, therefore it will { // just cancel the leading term PR->LmDeleteAndIter(); if (coef != NULL) *coef = n_Init(1, tailRing); return 0; } p_ExpVectorSub(lm, p2, tailRing); // Calculate the Monomial we must multiply to p2 if (tailRing != currRing) { // check that reduction does not violate exp bound while (PW->max != NULL && !p_LmExpVectorAddIsOk(lm, PW->max, tailRing)) { // undo changes of lm p_ExpVectorAdd(lm, p2, tailRing); if (strat == NULL) return 2; if (! kStratChangeTailRing(strat, PR, PW)) return -1; tailRing = strat->tailRing; p1 = PR->GetLmTailRing(); p2 = PW->GetLmTailRing(); t2 = pNext(p2); lm = p1; p_ExpVectorSub(lm, p2, tailRing); ret = 1; } } // take care of coef buisness if (! n_IsOne(pGetCoeff(p2), tailRing)) { number bn = pGetCoeff(lm); number an = pGetCoeff(p2); int ct = ksCheckCoeff(&an, &bn); // Calculate special LC p_SetCoeff(lm, bn, tailRing); if ((ct == 0) || (ct == 2)) PR->Tail_Mult_nn(an); if (coef != NULL) *coef = an; else n_Delete(&an, tailRing); } else { if (coef != NULL) *coef = n_Init(1, tailRing); } // and finally, PR->Tail_Minus_mm_Mult_qq(lm, t2, PW->GetpLength() - 1, spNoether); assume(PW->GetpLength() == pLength(PW->p != NULL ? PW->p : PW->t_p)); PR->LmDeleteAndIter(); // the following is commented out: shrinking #ifdef HAVE_SHIFTBBA_NONEXISTENT if ( (currRing->isLPring) && (!strat->homog) ) { // assume? h->p in currRing PR->GetP(); poly qq = p_Shrink(PR->p, currRing->isLPring, currRing); PR->Clear(); // does the right things PR->p = qq; PR->t_p = NULL; PR->SetShortExpVector(); } #endif #if defined(KDEBUG) && defined(TEST_OPT_DEBUG_RED) if (TEST_OPT_DEBUG) { Print(" to: "); PR->wrp(); Print("\n"); } #endif return ret; } My second question is less important, i just ask out of curiosity. 2.) In various function in the kernel of Singular i found a strange loop construct, which i suspect not to be in the language specification of C. Is it a macro? Where is it defined? Here is an example extracted from the bba function in kstd2.cc: Code: loop { if (j>=k) break; clearS(strat->S[j],strat->sevS[j],&k,&j,strat); j++; } edit: I forgot to say, that i use Singular Version 3-1-3. Background: I am currently adapting code from the singular kernel for a new letterplace approach using Distance Vectors as shift invariant representations for monomials. I am a Hiwi of Viktor Levandovskyy Lehrstuhl D fuer Mathematik, Rwth Aachen and working together with Grischa Studzinski. Thanks in advance for any answers, especially with respect to my first question. Benjamin Schnitzler |
Author: | hannes [ Fri Jul 08, 2011 2:57 pm ] |
Post subject: | Re: ksReducePoly and loop construct |
1.) there are 2 functions ksReducePoly (botyh declared in kernel/kutil.h) one with 5 argument (the last 3 are optional), one with 4 argument (the last is optional) Remember, that optional argument can only be given at exact one place, which is usulaly the declaration, not the implementation 2.) loop is indeed a construct which is missing in C, but quite useful as Modula2 shows. We emulated it by: Quote: #define loop for(;;) in structs.h |
Author: | bschnitz [ Mon Jul 11, 2011 10:56 am ] |
Post subject: | Re: ksReducePoly and loop construct [SOLVED] |
Hi, thank you for your help. For some unknown reason, i can't find the declarations ksReducePoly through my by ctags generated tag file (:ts ksReducePoly in vim only showed me the definition in kspoly.cc), but now you gave me the header file, i could find it! Ben |
Page 1 of 1 | All times are UTC + 1 hour [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |