Changeset dbbc24 in git
- Timestamp:
- Jun 7, 2018, 3:52:47 PM (6 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b4f17ed1d25f93d46dbe29e4b499baecc2fd51bb')
- Children:
- a718906498691a0860e186cfee5db4fc1142ccd6
- Parents:
- b2dba708c27f1a61cc99e30e069431d5408a06ca
- Location:
- libpolys/polys
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/polys/shiftop.cc
rb2dba70 rdbbc24 1 1 #include "shiftop.h" 2 #include "templates/p_MemCopy.h" 2 3 3 4 /* #define SHIFT_MULT_DEBUG */ 4 5 #define SHIFT_MULT_WARNINGS 6 #define SHIFT_MULT_COMPAT_MODE 5 7 6 8 #ifdef SHIFT_MULT_DEBUG … … 14 16 #endif 15 17 16 int lV = ri->isLPring; 17 18 // we just shift m and then call the commutative multiplication 19 int uptodeg = ri->N/lV; 20 int pshift = p_LastVblock(p, lV, ri); 21 int mshift = p_mFirstVblock(m, lV, ri) - 1; 22 #ifdef SHIFT_MULT_WARNINGS 23 // only needed because our examples still use x(1)*y(2) etc on the interface level 24 if (mshift > 0) { 25 PrintLn(); WarnS("m is already shifted"); 26 } 27 #endif 28 poly m2 = p_Copy(m,ri); 29 p_mLPshift(m2, pshift - mshift, uptodeg, lV, ri); 30 31 // this is the commutative multiplication procedure 32 extern poly pp_Mult_mm__FieldGeneral_LengthGeneral_OrdGeneral(spolyrec*, spolyrec*, ip_sring*); 33 p = pp_Mult_mm__FieldGeneral_LengthGeneral_OrdGeneral(p, m2, ri); 34 p = p_Shrink(p, lV, ri); 35 #ifdef SHIFT_MULT_DEBUG 36 PrintLn(); PrintS("shift_pp_Mult_mm result: "); p_wrp(p, ri, ri); PrintLn(); 37 #endif 38 return p; 18 p_Test(p, ri); 19 p_LmTest(m, ri); 20 if (p == NULL) 21 { 22 return NULL; 23 } 24 25 int lV = ri->isLPring; 26 poly _m = m; // temp hack because m is const 27 #ifdef SHIFT_MULT_COMPAT_MODE 28 _m = p_Copy(_m, ri); 29 p_mLPUnShift(_m, ri); 30 p = p_Copy(p, ri); 31 poly pCopyHead = p; // used to delete p later 32 p_LPUnShift(p, ri); 33 #else 34 assume(p_mFirstVblock(_m, lV, ri) <= 1); 35 assume(p_FirstVblock(p, lV, ri) <= 1); // TODO check that each block is <=1 36 #endif 37 // at this point _m and p are shifted to 1 38 39 spolyrec rp; 40 poly q = &rp; // we use p for iterating and q for the result 41 number mCoeff = pGetCoeff(_m); 42 omBin bin = ri->PolyBin; 43 pAssume(!n_IsZero(mCoeff, ri->cf)); 44 pAssume1(p_GetComp(m, ri) == 0 || p_MaxComp(p, ri) == 0); 45 46 int mLast = p_mLastVblock(_m, lV, ri); 47 int *mExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 48 p_GetExpV(_m,mExpV,ri); 49 do 50 { 51 p_AllocBin(pNext(q), bin, ri); 52 pIter(q); 53 pSetCoeff0(q, n_Mult(mCoeff, pGetCoeff(p), ri->cf)); 54 55 int *pExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 56 p_GetExpV(p, pExpV, ri); 57 p_LPExpVappend(pExpV, mExpV, p_mLastVblock(p, lV, ri), mLast, ri); 58 p_MemCopy_LengthGeneral(q->exp, p->exp, ri->ExpL_Size); // otherwise q is not initialized correctly 59 p_SetExpV(q, pExpV, ri); 60 omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int)); 61 62 pIter(p); 63 } 64 while (p != NULL); 65 omFreeSize((ADDRESS) mExpV, (ri->N+1)*sizeof(int)); 66 pNext(q) = NULL; 67 #ifdef SHIFT_MULT_COMPAT_MODE 68 p_Delete(&_m, ri); // in this case we copied _m before 69 p_Delete(&pCopyHead, ri); // in this case we copied p before 70 #endif 71 #ifdef SHIFT_MULT_DEBUG 72 PrintLn(); PrintS("shift_pp_Mult_mm result: "); p_wrp(pNext(&rp), ri, ri); PrintLn(); 73 #endif 74 p_Test(pNext(&rp), ri); 75 return pNext(&rp); 39 76 } 40 77 … … 46 83 #endif 47 84 48 int lV = ri->isLPring; 49 50 // we just shift m and then call the commutative multiplication 51 int uptodeg = ri->N/lV; 52 int pshift = p_LastVblock(p, lV, ri); 53 int mshift = p_mFirstVblock(m, lV, ri) - 1; 54 #ifdef SHIFT_MULT_WARNINGS 55 // only needed because our examples still use x(1)*y(2) etc on the interface level 56 if (mshift > 0) { 57 PrintLn(); WarnS("m is already shifted"); 58 } 59 #endif 60 poly m2 = p_Copy(m,ri); 61 p_mLPshift(m2, pshift - mshift, uptodeg, lV, ri); 62 63 // this is the commutative multiplication procedure 64 extern poly p_Mult_mm__FieldGeneral_LengthGeneral_OrdGeneral(spolyrec*, spolyrec*, ip_sring*); 65 66 p = p_Mult_mm__FieldGeneral_LengthGeneral_OrdGeneral(p, m2, ri); 67 poly q = p_Shrink(p, lV, ri); 68 p_Delete(&p, ri); 85 p_Test(p, ri); 86 p_LmTest(m, ri); 87 pAssume(m != NULL); 88 assume(p!=NULL); 89 90 int lV = ri->isLPring; 91 poly _m = m; // temp hack because m is const 92 #ifdef SHIFT_MULT_COMPAT_MODE 93 _m = p_Copy(_m, ri); 94 p_mLPUnShift(_m, ri); 95 p_LPUnShift(p, ri); 96 #else 97 assume(p_mFirstVblock(_m, lV, ri) <= 1); 98 assume(p_FirstVblock(p, lV, ri) <= 1); // TODO check that each block is <=1 99 #endif 100 // at this point _m and p are shifted to 1 101 102 poly q = p; // we use p for iterating and q for the result 103 number mCoeff = pGetCoeff(_m); 104 number pCoeff; 105 pAssume(!n_IsZero(mCoeff, ri->cf)); 106 107 int mLast = p_mLastVblock(_m, lV, ri); 108 int *mExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 109 p_GetExpV(_m,mExpV,ri); 110 while (p != NULL) 111 { 112 pCoeff = pGetCoeff(p); 113 pSetCoeff0(p, n_Mult(mCoeff, pCoeff, ri->cf)); 114 n_Delete(&pCoeff, ri->cf); // delete the old coeff 115 116 int *pExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 117 p_GetExpV(p,pExpV,ri); 118 p_LPExpVappend(pExpV, mExpV, p_mLastVblock(p, lV, ri), mLast, ri); 119 p_SetExpV(p, pExpV, ri); 120 omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int)); 121 122 pIter(p); 123 } 124 omFreeSize((ADDRESS) mExpV, (ri->N+1)*sizeof(int)); 125 #ifdef SHIFT_MULT_COMPAT_MODE 126 p_Delete(&_m, ri); // in this case we copied _m before 127 #endif 69 128 #ifdef SHIFT_MULT_DEBUG 70 129 PrintLn(); PrintS("shift_p_Mult_mm result: "); p_wrp(q, ri, ri); PrintLn(); 71 130 #endif 131 p_Test(q, ri); 72 132 return q; 73 133 } … … 85 145 int mshift = p_mLastVblock(m, lV, ri); 86 146 int pshift = p_FirstVblock(p, lV, ri) - 1; 147 148 assume(p_FirstVblock(p, lV, ri) <= 1); 149 assume(p_mFirstVblock(m, lV, ri) <= 1); 87 150 #ifdef SHIFT_MULT_WARNINGS 88 151 // only needed because our examples still use x(1)*y(2) etc on the interface level … … 118 181 int mshift = p_mLastVblock(m, lV, ri); 119 182 int pshift = p_FirstVblock(p, lV, ri) - 1; 183 184 assume(p_FirstVblock(p, lV, ri) <= 1); 185 assume(p_mFirstVblock(m, lV, ri) <= 1); 120 186 #ifdef SHIFT_MULT_WARNINGS 121 187 // only needed because our examples still use x(1)*y(2) etc on the interface level … … 188 254 return NULL; 189 255 } 256 257 // auxiliary 258 259 // unshifts the monomial m 260 void p_mLPUnShift(poly m, const ring ri) 261 { 262 if (m == NULL || p_LmIsConstant(m,ri)) return; 263 264 int lV = ri->isLPring; 265 266 int shift = p_mFirstVblock(m, lV, ri) - 1; 267 268 if (shift == 0) return; 269 270 int L = p_mLastVblock(m, lV, ri); 271 272 int *e=(int *)omAlloc0((ri->N+1)*sizeof(int)); 273 int *s=(int *)omAlloc0((ri->N+1)*sizeof(int)); 274 p_GetExpV(m, e, ri); 275 276 int expVoffset = shift*lV; 277 for (int i = 1 + expVoffset; i <= L*lV; i++) 278 { 279 assume(e[i] <= 1); 280 s[i - expVoffset] = e[i]; 281 } 282 p_SetExpV(m,s,ri); 283 omFreeSize((ADDRESS) e, (ri->N+1)*sizeof(int)); 284 omFreeSize((ADDRESS) s, (ri->N+1)*sizeof(int)); 285 } 286 287 // unshifts the polynomial p, note: the ordering can be destroyed if the shifts for the monomials are not equal 288 void p_LPUnShift(poly p, const ring ri) 289 { 290 while (p!=NULL) 291 { 292 p_mLPUnShift(p, ri); 293 pIter(p); 294 } 295 p_Test(p, ri); // check if ordering was destroyed 296 } 297 298 // appends mExpV to pExpV where pLast is the last Vblock of p and mLast the last Vblock of m 299 void p_LPExpVappend(int *pExpV, int *mExpV, int pLast, int mLast, const ring ri) { 300 #ifdef SHIFT_MULT_DEBUG 301 WriteLPExpV(pExpV, ri); PrintLn(); 302 WriteLPExpV(mExpV, ri); PrintLn(); 303 #endif 304 int appendOffset = pLast * ri->isLPring; 305 int appendEnd = appendOffset + mLast * ri->isLPring; 306 assume(appendOffset + appendEnd <= ri->N); 307 for (int i = 1 + appendOffset; i < 1 + appendEnd; i++) 308 { 309 assume(mExpV[i - appendOffset] <= 1); 310 pExpV[i] = mExpV[i - appendOffset]; 311 } 312 #ifdef SHIFT_MULT_DEBUG 313 WriteLPExpV(pExpV, ri); PrintLn(); 314 #endif 315 } 316 317 void WriteLPExpV(int *expV, ring ri) { 318 for (int i = 0; i <= ri->N; i++) { 319 Print("%d", expV[i]); 320 if (i == 0) { 321 Print("| "); 322 } 323 if (i % ri->isLPring == 0) { 324 Print(" "); 325 } 326 } 327 } -
libpolys/polys/shiftop.h
rb2dba70 rdbbc24 11 11 poly shift_pp_Mult_Coeff_mm_DivSelectMult_STUB(poly p,const poly m, const poly a, const poly b, int &shorter,const ring r); 12 12 poly shift_pp_Mult_Coeff_mm_DivSelect_STUB(poly p, const poly m, int &shorter, const ring r); 13 void p_mLPUnShift(poly m, const ring ri); 14 void p_LPUnShift(poly p, const ring ri); 15 void p_LPExpVappend(int *pExpV, int *mExpV, int pLast, int mLast, const ring ri); 16 void WriteLPExpV(int *expV, ring ri);
Note: See TracChangeset
for help on using the changeset viewer.