Changeset b00f8a in git for libpolys/polys/shiftop.cc
- Timestamp:
- Jun 14, 2018, 7:49:34 PM (6 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b4f17ed1d25f93d46dbe29e4b499baecc2fd51bb')
- Children:
- 8fdfee786b3e1012ed42fb016959acde02a0a50f
- Parents:
- 8c73fdea988c87d699605750b3180fa69edf5d10
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/polys/shiftop.cc
r8c73fde rb00f8a 13 13 #ifdef SHIFT_MULT_DEBUG 14 14 PrintLn(); PrintS("shift_pp_Mult_mm: ("); p_wrp(p, ri, ri); PrintS(") * "); p_wrp(m, ri, ri); 15 #endif 16 17 p_Test(p, ri); 18 p_LmTest(m, ri); 19 if (p == NULL) 20 { 21 return NULL; 22 } 23 24 int lV = ri->isLPring; 25 poly _m = m; // temp hack because m is const 26 #ifdef SHIFT_MULT_COMPAT_MODE 27 _m = p_Copy(_m, ri); 28 p_mLPUnShift(_m, ri); 29 p = p_Copy(p, ri); 30 poly pCopyHead = p; // used to delete p later 31 p_LPUnShift(p, ri); 32 #else 33 assume(p_mFirstVblock(_m, ri) <= 1); 34 assume(p_FirstVblock(p, ri) <= 1); // TODO check that each block is <=1 35 #endif 36 // at this point _m and p are shifted to 1 37 38 spolyrec rp; 39 poly q = &rp; // we use p for iterating and q for the result 40 number mCoeff = pGetCoeff(_m); 41 omBin bin = ri->PolyBin; 42 pAssume(!n_IsZero(mCoeff, ri->cf)); 43 pAssume1(p_GetComp(m, ri) == 0 || p_MaxComp(p, ri) == 0); 44 45 int mLength = p_mLastVblock(_m, ri) * lV; 46 int *mExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 47 p_GetExpV(_m,mExpV,ri); 48 do 49 { 50 p_AllocBin(pNext(q), bin, ri); 51 pIter(q); 52 pSetCoeff0(q, n_Mult(mCoeff, pGetCoeff(p), ri->cf)); 53 54 int *pExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 55 p_GetExpV(p, pExpV, ri); 56 p_LPExpVappend(pExpV, mExpV, p_mLastVblock(p, ri) * lV, mLength, ri); 57 p_MemCopy_LengthGeneral(q->exp, p->exp, ri->ExpL_Size); // otherwise q is not initialized correctly 58 p_SetExpV(q, pExpV, ri); 59 omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int)); 60 61 pIter(p); 62 } 63 while (p != NULL); 64 omFreeSize((ADDRESS) mExpV, (ri->N+1)*sizeof(int)); 65 pNext(q) = NULL; 66 #ifdef SHIFT_MULT_COMPAT_MODE 67 p_Delete(&_m, ri); // in this case we copied _m before 68 p_Delete(&pCopyHead, ri); // in this case we copied p before 69 #endif 70 #ifdef SHIFT_MULT_DEBUG 71 PrintLn(); PrintS("shift_pp_Mult_mm result: "); p_wrp(pNext(&rp), ri, ri); PrintLn(); 72 #endif 73 p_Test(pNext(&rp), ri); 74 return pNext(&rp); 75 } 76 77 // destroys p 78 poly shift_p_Mult_mm(poly p, const poly m, const ring ri) 79 { 80 #ifdef SHIFT_MULT_DEBUG 81 PrintLn(); PrintS("shift_p_Mult_mm: ("); p_wrp(p, ri, ri); PrintS(") * "); p_wrp(m, ri, ri); 82 #endif 83 84 p_Test(p, ri); 85 p_LmTest(m, ri); 86 pAssume(m != NULL); 87 assume(p!=NULL); 88 89 int lV = ri->isLPring; 90 poly _m = m; // temp hack because m is const 91 #ifdef SHIFT_MULT_COMPAT_MODE 92 _m = p_Copy(_m, ri); 93 p_mLPUnShift(_m, ri); 94 p_LPUnShift(p, ri); 95 #else 96 assume(p_mFirstVblock(_m, lV, ri) <= 1); 97 assume(p_FirstVblock(p, lV, ri) <= 1); // TODO check that each block is <=1 98 #endif 99 // at this point _m and p are shifted to 1 100 101 poly q = p; // we use p for iterating and q for the result 102 number mCoeff = pGetCoeff(_m); 103 number pCoeff; 104 pAssume(!n_IsZero(mCoeff, ri->cf)); 105 106 int mLength = p_mLastVblock(_m, ri) * lV; 107 int *mExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 108 p_GetExpV(_m,mExpV,ri); 109 while (p != NULL) 110 { 111 pCoeff = pGetCoeff(p); 112 pSetCoeff0(p, n_Mult(mCoeff, pCoeff, ri->cf)); 113 n_Delete(&pCoeff, ri->cf); // delete the old coeff 114 115 int *pExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 116 p_GetExpV(p,pExpV,ri); 117 p_LPExpVappend(pExpV, mExpV, p_mLastVblock(p, ri) * lV, mLength, ri); 118 p_SetExpV(p, pExpV, ri); 119 omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int)); 120 121 pIter(p); 122 } 123 omFreeSize((ADDRESS) mExpV, (ri->N+1)*sizeof(int)); 124 #ifdef SHIFT_MULT_COMPAT_MODE 125 p_Delete(&_m, ri); // in this case we copied _m before 126 #endif 127 #ifdef SHIFT_MULT_DEBUG 128 PrintLn(); PrintS("shift_p_Mult_mm result: "); p_wrp(q, ri, ri); PrintLn(); 129 #endif 130 p_Test(q, ri); 131 return q; 132 } 133 134 poly shift_pp_mm_Mult(poly p, const poly m, const ring ri) 135 { 136 #ifdef SHIFT_MULT_DEBUG 137 PrintLn(); PrintS("shift_pp_mm_Mult: "); p_wrp(m, ri, ri); PrintS(" * ("); p_wrp(p, ri, ri); PrintS(")"); 15 138 #endif 16 139 … … 43 166 pAssume1(p_GetComp(m, ri) == 0 || p_MaxComp(p, ri) == 0); 44 167 45 int mLength = p_mLastVblock(_m, lV,ri) * lV;168 int mLength = p_mLastVblock(_m, ri) * lV; 46 169 int *mExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 47 170 p_GetExpV(_m,mExpV,ri); … … 54 177 int *pExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 55 178 p_GetExpV(p, pExpV, ri); 56 p_LPExpV append(pExpV, mExpV, p_mLastVblock(p, lV, ri) * lV, mLength, ri);179 p_LPExpVprepend(pExpV, mExpV, p_mLastVblock(p, ri) * lV, mLength, ri); 57 180 p_MemCopy_LengthGeneral(q->exp, p->exp, ri->ExpL_Size); // otherwise q is not initialized correctly 58 181 p_SetExpV(q, pExpV, ri); … … 69 192 #endif 70 193 #ifdef SHIFT_MULT_DEBUG 71 PrintLn(); PrintS("shift_pp_ Mult_mmresult: "); p_wrp(pNext(&rp), ri, ri); PrintLn();194 PrintLn(); PrintS("shift_pp_mm_Mult result: "); p_wrp(pNext(&rp), ri, ri); PrintLn(); 72 195 #endif 73 196 p_Test(pNext(&rp), ri); … … 76 199 77 200 // destroys p 78 poly shift_p_ Mult_mm(poly p, const poly m, const ring ri)79 { 80 #ifdef SHIFT_MULT_DEBUG 81 PrintLn(); PrintS("shift_p_ Mult_mm: ("); p_wrp(p, ri, ri); PrintS(") * "); p_wrp(m, ri, ri);201 poly shift_p_mm_Mult(poly p, const poly m, const ring ri) 202 { 203 #ifdef SHIFT_MULT_DEBUG 204 PrintLn(); PrintS("shift_p_mm_Mult: "); p_wrp(m, ri, ri); PrintS(" * ("); p_wrp(p, ri, ri); PrintS(")"); 82 205 #endif 83 206 … … 104 227 pAssume(!n_IsZero(mCoeff, ri->cf)); 105 228 106 int mLength = p_mLastVblock(_m, lV,ri) * lV;229 int mLength = p_mLastVblock(_m, ri) * lV; 107 230 int *mExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 108 231 p_GetExpV(_m,mExpV,ri); … … 115 238 int *pExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 116 239 p_GetExpV(p,pExpV,ri); 117 p_LPExpVappend(pExpV, mExpV, p_mLastVblock(p, lV, ri) * lV, mLength, ri); 118 p_SetExpV(p, pExpV, ri); 119 omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int)); 120 121 pIter(p); 122 } 123 omFreeSize((ADDRESS) mExpV, (ri->N+1)*sizeof(int)); 124 #ifdef SHIFT_MULT_COMPAT_MODE 125 p_Delete(&_m, ri); // in this case we copied _m before 126 #endif 127 #ifdef SHIFT_MULT_DEBUG 128 PrintLn(); PrintS("shift_p_Mult_mm result: "); p_wrp(q, ri, ri); PrintLn(); 129 #endif 130 p_Test(q, ri); 131 return q; 132 } 133 134 poly shift_pp_mm_Mult(poly p, const poly m, const ring ri) 135 { 136 #ifdef SHIFT_MULT_DEBUG 137 PrintLn(); PrintS("shift_pp_mm_Mult: "); p_wrp(m, ri, ri); PrintS(" * ("); p_wrp(p, ri, ri); PrintS(")"); 138 #endif 139 140 p_Test(p, ri); 141 p_LmTest(m, ri); 142 if (p == NULL) 143 { 144 return NULL; 145 } 146 147 int lV = ri->isLPring; 148 poly _m = m; // temp hack because m is const 149 #ifdef SHIFT_MULT_COMPAT_MODE 150 _m = p_Copy(_m, ri); 151 p_mLPUnShift(_m, ri); 152 p = p_Copy(p, ri); 153 poly pCopyHead = p; // used to delete p later 154 p_LPUnShift(p, ri); 155 #else 156 assume(p_mFirstVblock(_m, lV, ri) <= 1); 157 assume(p_FirstVblock(p, lV, ri) <= 1); // TODO check that each block is <=1 158 #endif 159 // at this point _m and p are shifted to 1 160 161 spolyrec rp; 162 poly q = &rp; // we use p for iterating and q for the result 163 number mCoeff = pGetCoeff(_m); 164 omBin bin = ri->PolyBin; 165 pAssume(!n_IsZero(mCoeff, ri->cf)); 166 pAssume1(p_GetComp(m, ri) == 0 || p_MaxComp(p, ri) == 0); 167 168 int mLength = p_mLastVblock(_m, lV, ri) * lV; 169 int *mExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 170 p_GetExpV(_m,mExpV,ri); 171 do 172 { 173 p_AllocBin(pNext(q), bin, ri); 174 pIter(q); 175 pSetCoeff0(q, n_Mult(mCoeff, pGetCoeff(p), ri->cf)); 176 177 int *pExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 178 p_GetExpV(p, pExpV, ri); 179 p_LPExpVprepend(pExpV, mExpV, p_mLastVblock(p, lV, ri) * lV, mLength, ri); 180 p_MemCopy_LengthGeneral(q->exp, p->exp, ri->ExpL_Size); // otherwise q is not initialized correctly 181 p_SetExpV(q, pExpV, ri); 182 omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int)); 183 184 pIter(p); 185 } 186 while (p != NULL); 187 omFreeSize((ADDRESS) mExpV, (ri->N+1)*sizeof(int)); 188 pNext(q) = NULL; 189 #ifdef SHIFT_MULT_COMPAT_MODE 190 p_Delete(&_m, ri); // in this case we copied _m before 191 p_Delete(&pCopyHead, ri); // in this case we copied p before 192 #endif 193 #ifdef SHIFT_MULT_DEBUG 194 PrintLn(); PrintS("shift_pp_mm_Mult result: "); p_wrp(pNext(&rp), ri, ri); PrintLn(); 195 #endif 196 p_Test(pNext(&rp), ri); 197 return pNext(&rp); 198 } 199 200 // destroys p 201 poly shift_p_mm_Mult(poly p, const poly m, const ring ri) 202 { 203 #ifdef SHIFT_MULT_DEBUG 204 PrintLn(); PrintS("shift_p_mm_Mult: "); p_wrp(m, ri, ri); PrintS(" * ("); p_wrp(p, ri, ri); PrintS(")"); 205 #endif 206 207 p_Test(p, ri); 208 p_LmTest(m, ri); 209 pAssume(m != NULL); 210 assume(p!=NULL); 211 212 int lV = ri->isLPring; 213 poly _m = m; // temp hack because m is const 214 #ifdef SHIFT_MULT_COMPAT_MODE 215 _m = p_Copy(_m, ri); 216 p_mLPUnShift(_m, ri); 217 p_LPUnShift(p, ri); 218 #else 219 assume(p_mFirstVblock(_m, lV, ri) <= 1); 220 assume(p_FirstVblock(p, lV, ri) <= 1); // TODO check that each block is <=1 221 #endif 222 // at this point _m and p are shifted to 1 223 224 poly q = p; // we use p for iterating and q for the result 225 number mCoeff = pGetCoeff(_m); 226 number pCoeff; 227 pAssume(!n_IsZero(mCoeff, ri->cf)); 228 229 int mLength = p_mLastVblock(_m, lV, ri) * lV; 230 int *mExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 231 p_GetExpV(_m,mExpV,ri); 232 while (p != NULL) 233 { 234 pCoeff = pGetCoeff(p); 235 pSetCoeff0(p, n_Mult(mCoeff, pCoeff, ri->cf)); 236 n_Delete(&pCoeff, ri->cf); // delete the old coeff 237 238 int *pExpV = (int *) omAlloc0((ri->N+1)*sizeof(int)); 239 p_GetExpV(p,pExpV,ri); 240 p_LPExpVprepend(pExpV, mExpV, p_mLastVblock(p, lV, ri) * lV, mLength, ri); 240 p_LPExpVprepend(pExpV, mExpV, p_mLastVblock(p, ri) * lV, mLength, ri); 241 241 p_SetExpV(p, pExpV, ri); 242 242 omFreeSize((ADDRESS) pExpV, (ri->N+1)*sizeof(int)); … … 312 312 int lV = ri->isLPring; 313 313 314 int shift = p_mFirstVblock(m, lV,ri) - 1;314 int shift = p_mFirstVblock(m, ri) - 1; 315 315 316 316 if (shift == 0) return; 317 317 318 int L = p_mLastVblock(m, lV,ri);318 int L = p_mLastVblock(m, ri); 319 319 320 320 int *e=(int *)omAlloc0((ri->N+1)*sizeof(int));
Note: See TracChangeset
for help on using the changeset viewer.