Changeset a469814 in git for kernel/GBEngine/kutil.cc
- Timestamp:
- Jul 3, 2015, 1:35:17 PM (8 years ago)
- Branches:
- (u'spielwiese', 'e7cc1ebecb61be8b9ca6c18016352af89940b21a')
- Children:
- 81f40d79bb623106f176d7d1bc3cfb277b750b0e
- Parents:
- 1550ecaad46efdce1c9032818b53259c1f6c108a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/GBEngine/kutil.cc
r1550eca ra469814 36 36 #include <kernel/ideals.h> 37 37 #endif 38 #include <gmp.h> 38 39 39 40 // define if enterL, enterT should use memmove instead of doing it manually … … 4846 4847 } 4847 4848 4849 int posInLRing (const LSet set, const int length, 4850 LObject* p,const kStrategy /*strat*/) 4851 { 4852 if (length < 0) return 0; 4853 if (set[length].FDeg > p->FDeg) 4854 return length+1; 4855 if (set[length].FDeg == p->FDeg) 4856 if(set[length].GetpLength() > p->GetpLength()) 4857 return length+1; 4858 int i; 4859 int an = 0; 4860 int en= length+1; 4861 loop 4862 { 4863 if (an >= en-1) 4864 { 4865 if(an == en) 4866 return en; 4867 if (set[an].FDeg > p->FDeg) 4868 return en; 4869 if(set[an].FDeg == p->FDeg) 4870 { 4871 if(set[an].GetpLength() > p->GetpLength()) 4872 {return en;} 4873 else 4874 { 4875 if(set[an].GetpLength() == p->GetpLength()) 4876 { 4877 if(nGreater(set[an].p->coef, p->p->coef)) 4878 { 4879 return en; 4880 } 4881 else 4882 { 4883 return an; 4884 } 4885 } 4886 else 4887 { 4888 return an; 4889 } 4890 } 4891 } 4892 else 4893 {return an;} 4894 } 4895 i=(an+en) / 2; 4896 if (set[i].FDeg > p->FDeg) 4897 an=i; 4898 else 4899 { 4900 if(set[i].FDeg == p->FDeg) 4901 { 4902 if(set[i].GetpLength() > p->GetpLength()) 4903 an=i; 4904 else 4905 { 4906 if(set[i].GetpLength() == p->GetpLength()) 4907 { 4908 if(nGreater(set[i].p->coef, p->p->coef)) 4909 { 4910 an = i; 4911 } 4912 else 4913 { 4914 en = i; 4915 } 4916 } 4917 else 4918 { 4919 en=i; 4920 } 4921 } 4922 } 4923 else 4924 en=i; 4925 } 4926 } 4927 } 4928 4848 4929 // for sba, sorting syzygies 4849 4930 int posInSyz (const kStrategy strat, poly sig) … … 4938 5019 } 4939 5020 5021 /*2 5022 * looks up the position of polynomial p in set 5023 * set[length] is the smallest element in set with respect 5024 * to the ordering-procedure pLmCmp,totaldegree,coefficient 5025 * For the same totaldegree, original pairs (from F) will 5026 * be put at the end and smalles coefficents 5027 */ 5028 int posInL11Ring (const LSet set, const int length, 5029 LObject* p,const kStrategy strat) 5030 { 5031 #if 0 5032 if (length < 0) return 0; 5033 //if(pIsConstant(pHead(p->p))) return length+1; 5034 if (pLmCmp(set[length].p, p->p) == 1) 5035 return length+1; 5036 if (pLmCmp(set[0].p, p->p) == -1) 5037 return 0; 5038 5039 int i; 5040 int an = 0; 5041 int en = length+1; 5042 bool isFromF = (p->p1 == NULL) && (p->p2 == NULL); 5043 #if 0 5044 printf("\nThis is L:\n"); 5045 for(int ii=0; ii<=strat->Ll; ii++) 5046 { 5047 printf("\nL[%i]: grad = %i, length = %i\n", ii,set[ii].FDeg,set[ii].length); 5048 pWrite(set[ii].p); 5049 pWrite(set[ii].p1); 5050 pWrite(set[ii].p2); 5051 pWrite(pHead(set[ii].p)); 5052 printf("\nlmcmp = %i\n",pLmCmp(pHead(set[ii].p), pHead(p->p))); 5053 } 5054 printf("\nThis is P:\n");pWrite(p->p);pWrite(p->p1);pWrite(p->p2); 5055 #endif 5056 if(isFromF) 5057 { 5058 //printf("\nisFromF\n"); 5059 i = 0; 5060 while(i<=length && pLmCmp(set[i].p, p->p)==1) 5061 i++; 5062 while((i<=length) && ((set[i].p1 != NULL) || (set[i].p2 != NULL)) && (pLmCmp(set[i].p, p->p) == 0)) 5063 i++; 5064 an = i; 5065 i = length; 5066 while(i>=0 && pLmCmp(set[i].p, p->p) == -1) 5067 i--; 5068 en = i+1; 5069 } 5070 else 5071 { 5072 //printf("\nis not FromF\n"); 5073 i = 0; 5074 while(i<= length && pLmCmp(set[i].p, p->p) == 1) 5075 i++; 5076 an = i; 5077 //printf("\nan = %i\n",an); 5078 i = length; 5079 //printf("\ni = %i\n", i); 5080 while(i>=0 && pLmCmp(set[i].p, p->p)==-1) 5081 i--; 5082 //printf("\ni2 = %i\n", i); 5083 while(i<= length && ((set[i].p1 == NULL) && (set[i].p2 == NULL)) && (pLmCmp(set[i].p,p->p) == 0) && (i > an)) 5084 i--; 5085 en = i+1; 5086 //printf("\nen = %i\n",en); 5087 } 5088 //printf("\nan = %i\n en = %i\n",an,en); 5089 //getchar(); 5090 loop 5091 { 5092 if(an > length) 5093 return length+1; 5094 if (an >= en-1) 5095 { 5096 if(an == en) 5097 return en; 5098 if (pLmCmp(set[an].p, p->p) == 1) 5099 return en; 5100 if (pLmCmp(set[an].p, p->p) == -1) 5101 return an; 5102 if (pLmCmp(set[i].p, p->p) == 0) 5103 { 5104 if(nGreater(set[an].p->coef, p->p->coef)) 5105 return en; 5106 else 5107 return an; 5108 } 5109 } 5110 i=(an+en) / 2; 5111 if (pLmCmp(set[i].p, p->p) == 1) 5112 an=i; 5113 if (pLmCmp(set[i].p, p->p) == -1) 5114 en=i; 5115 if (pLmCmp(set[i].p, p->p) == 0) 5116 { 5117 if(nGreater(set[i].p->coef, p->p->coef)) 5118 an = i; 5119 else 5120 en = i; 5121 } 5122 } 5123 #else 5124 if (length < 0) return 0; 5125 if(pIsConstant(p->p)) return length+1; 5126 int i,an,en; 5127 if(pIsConstant(set[length].p) && length > 0) 5128 { 5129 if (set[length-1].FDeg > p->FDeg) 5130 return length; 5131 } 5132 else 5133 { 5134 if (set[length].FDeg > p->FDeg) 5135 return length+1; 5136 } 5137 if (set[0].FDeg < p->FDeg) 5138 return 0; 5139 5140 bool isFromF = (p->p1 == NULL) && (p->p2 == NULL); 5141 #if 0 5142 //printf("\nThis is L:\n"); 5143 /*for(int ii=0; ii<=strat->Ll; ii++) 5144 { 5145 printf("\nL[%i]: grad = %i, length = %i\n", ii,set[ii].FDeg,set[ii].length); 5146 pWrite(set[ii].p); 5147 pWrite(set[ii].p1); 5148 pWrite(set[ii].p2); 5149 }*/ 5150 printf("\nThis is P:\n");pWrite(p->p);pWrite(p->p1);pWrite(p->p2); 5151 #endif 5152 if(isFromF) 5153 { 5154 //printf("\nisFromF\n"); 5155 i = 0; 5156 while(i<= length && set[i].FDeg > p->FDeg && !pIsConstant(set[i].p)) 5157 i++; 5158 while(i<= length && ((set[i].p1 != NULL) || (set[i].p2 != NULL)) && (set[i].FDeg == p->FDeg) && !pIsConstant(set[i].p)) 5159 i++; 5160 an = i; 5161 if(pIsConstant(set[length].p)) 5162 i = length-1; 5163 else 5164 i = length; 5165 while(i>=0 && set[i].FDeg < p->FDeg) 5166 i--; 5167 en = i+1; 5168 } 5169 else 5170 { 5171 //printf("\nis not FromF\n"); 5172 i = 0; 5173 while(i<= length && set[i].FDeg > p->FDeg && !pIsConstant(set[i].p)) 5174 i++; 5175 an = i; 5176 //printf("\nan = %i\n",an); 5177 if(pIsConstant(set[length].p)) 5178 i = length-1; 5179 else 5180 i = length; 5181 //printf("\ni = %i\n", i); 5182 while(i>= 0 && set[i].FDeg < p->FDeg) 5183 i--; 5184 //printf("\ni2 = %i\n", i); 5185 while(i>=0 && ((set[i].p1 == NULL) && (set[i].p2 == NULL)) && (set[i].FDeg == p->FDeg) && (i > an)) 5186 i--; 5187 en = i+1; 5188 //printf("\nen = %i\n",en); 5189 } 5190 //printf("\nan = %i\n en = %i\n",an,en); 5191 //getchar(); 5192 loop 5193 { 5194 if(an > length) 5195 return length+1; 5196 if (an >= en-1) 5197 { 5198 if(an == en) 5199 return en; 5200 if (pLmCmp(set[an].p, p->p) == 1) 5201 return en; 5202 if (pLmCmp(set[an].p, p->p) == -1) 5203 return an; 5204 if (pLmCmp(set[i].p, p->p) == 0) 5205 { 5206 if(nGreater(set[an].p->coef, p->p->coef)) 5207 return en; 5208 else 5209 return an; 5210 } 5211 } 5212 i=(an+en) / 2; 5213 if (pLmCmp(set[i].p, p->p) == 1) 5214 an=i; 5215 if (pLmCmp(set[i].p, p->p) == -1) 5216 en=i; 5217 if (pLmCmp(set[i].p, p->p) == 0) 5218 { 5219 if(nGreater(set[i].p->coef, p->p->coef)) 5220 an = i; 5221 else 5222 en = i; 5223 } 5224 } 5225 #endif 5226 } 4940 5227 /*2 Position for rings L: Here I am 4941 5228 * looks up the position of polynomial p in set … … 8474 8761 return TRUE; 8475 8762 } 8763 /*! 8764 used for GB over ZZ: look for constant and monomial elements in the ideal 8765 background: any known constant element of ideal suppresses 8766 intermediate coefficient swell 8767 */ 8768 poly preIntegerCheck(ideal FOrig, ideal Q) 8769 { 8770 ideal F = idCopy(FOrig); 8771 idSkipZeroes(F); 8772 poly pmon; 8773 if(nCoeff_is_Ring_Z(currRing->cf)) 8774 { 8775 ring origR = currRing; 8776 ideal monred = idInit(1,1); 8777 for(int i=0; i<idElem(F); i++) 8778 { 8779 if(pNext(F->m[i]) == NULL) 8780 idInsertPoly(monred, F->m[i]); 8781 } 8782 int posconst = idPosConstant(F); 8783 if((posconst != -1) && (!nIsZero(F->m[posconst]->coef))) 8784 { 8785 pmon = pCopy(F->m[posconst]); 8786 return pmon; 8787 } 8788 int idelemQ = 0; 8789 if(Q!=NULL) 8790 { 8791 idelemQ = IDELEMS(Q); 8792 for(int i=0; i<idelemQ; i++) 8793 { 8794 if(pNext(Q->m[i]) == NULL) 8795 idInsertPoly(monred, Q->m[i]); 8796 } 8797 idSkipZeroes(monred); 8798 posconst = idPosConstant(monred); 8799 //the constant, if found, will be from Q 8800 if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef))) 8801 { 8802 pmon = pCopy(monred->m[posconst]); 8803 return pmon; 8804 } 8805 } 8806 ring QQ_ring = rCopy(currRing); 8807 rUnComplete(QQ_ring); 8808 QQ_ring->cf->ref--; 8809 QQ_ring->cf = nInitChar(n_Q, NULL); 8810 if(Q!= NULL) 8811 QQ_ring->qideal = NULL; 8812 rComplete(QQ_ring,1); 8813 QQ_ring = rAssure_c_dp(QQ_ring); 8814 rChangeCurrRing(QQ_ring); 8815 nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf); 8816 ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR)); 8817 int *perm = (int *)omAlloc0((QQ_ring->N+1)*sizeof(int)); 8818 for(int i=QQ_ring->N;i>0;i--) 8819 perm[i]=i; 8820 for(int i = 0, j = 0; i<IDELEMS(F); i++) 8821 II->m[j++] = p_PermPoly(F->m[i], perm, origR, QQ_ring, nMap, NULL, 0); 8822 for(int i = 0, j = IDELEMS(F); i<idelemQ; i++) 8823 II->m[j++] = p_PermPoly(Q->m[i], perm, origR, QQ_ring, nMap, NULL, 0); 8824 //rWrite(currRing); 8825 ideal one = kStd(II, NULL, isNotHomog, NULL); 8826 idSkipZeroes(one); 8827 if(idIsConstant(one)) 8828 { 8829 //one should be <1> 8830 for(int i = IDELEMS(II)-1; i>=0; i--) 8831 if(II->m[i] != NULL) 8832 II->m[i+1] = II->m[i]; 8833 II->m[0] = pOne(); 8834 ideal syz = idSyzygies(II, isNotHomog, NULL); 8835 poly integer = NULL; 8836 for(int i = IDELEMS(syz)-1;i>=0; i--) 8837 { 8838 if(pGetComp(syz->m[i]) == 1) 8839 { 8840 if(p_Deg(pHead(syz->m[i]), currRing) == 0) 8841 { 8842 integer = pCopy(pHead(syz->m[i])); 8843 pSetComp(integer, 0); 8844 break; 8845 } 8846 } 8847 } 8848 rChangeCurrRing(origR); 8849 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf); 8850 pmon = p_PermPoly(integer, perm, QQ_ring, origR, nMap2, NULL, 0); 8851 return pmon; 8852 } 8853 else 8854 { 8855 if(idIs0(monred)) 8856 { 8857 poly mindegmon = NULL; 8858 for(int i = 0; i<IDELEMS(one); i++) 8859 { 8860 if(pNext(one->m[i]) == NULL) 8861 { 8862 if(mindegmon == NULL) 8863 mindegmon = one->m[i]; 8864 else 8865 { 8866 if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring)) 8867 mindegmon = one->m[i]; 8868 } 8869 } 8870 } 8871 if(mindegmon != NULL) 8872 { 8873 for(int i = IDELEMS(II)-1; i>=0; i--) 8874 if(II->m[i] != NULL) 8875 II->m[i+1] = II->m[i]; 8876 II->m[0] = mindegmon; 8877 ideal syz = idSyzygies(II, isNotHomog, NULL); 8878 bool found = FALSE; 8879 for(int i = IDELEMS(syz)-1;i>=0; i--) 8880 { 8881 if(pGetComp(syz->m[i]) == 1) 8882 { 8883 if(p_Deg(pHead(syz->m[i]), currRing) == 0) 8884 { 8885 pSetCoeff(mindegmon, syz->m[i]->coef); 8886 found = TRUE; 8887 break; 8888 } 8889 } 8890 } 8891 if (found == FALSE) 8892 { 8893 rChangeCurrRing(origR); 8894 return NULL; 8895 } 8896 rChangeCurrRing(origR); 8897 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf); 8898 pmon = p_PermPoly(mindegmon, perm, QQ_ring, origR, nMap2, NULL, 0); 8899 return pmon; 8900 } 8901 else 8902 rChangeCurrRing(origR); 8903 } 8904 else 8905 rChangeCurrRing(origR); 8906 } 8907 return NULL; 8908 } 8909 } 8910 /*! 8911 used for GB over ZZ: intermediate reduction by monomial elements 8912 background: any known constant element of ideal suppresses 8913 intermediate coefficient swell 8914 */ 8915 void postReduceByMon(LObject* h, kStrategy strat) 8916 { 8917 if(!nCoeff_is_Ring_Z(currRing->cf)) 8918 return; 8919 poly pH = h->GetP(); 8920 poly p,pp; 8921 p = pH; 8922 bool deleted = FALSE, ok = FALSE; 8923 for(int i = 0; i<=strat->sl; i++) 8924 { 8925 p = pH; 8926 if(pNext(strat->S[i]) == NULL) 8927 { 8928 while(ok == FALSE) 8929 { 8930 if(pLmDivisibleBy(strat->S[i], p)) 8931 { 8932 p->coef = currRing->cf->cfIntMod(p->coef, strat->S[i]->coef, currRing->cf); 8933 } 8934 if(nIsZero(p->coef)) 8935 { 8936 pLmDelete(&pNext(p)); 8937 deleted = TRUE; 8938 } 8939 else 8940 { 8941 ok = TRUE; 8942 } 8943 } 8944 pp = pNext(p); 8945 while(pp != NULL) 8946 { 8947 if(pLmDivisibleBy(strat->S[i], pp)) 8948 { 8949 pp->coef = currRing->cf->cfIntMod(pp->coef, strat->S[i]->coef, currRing->cf); 8950 if(nIsZero(pp->coef)) 8951 { 8952 pLmDelete(&pNext(p)); 8953 pp = pNext(p); 8954 deleted = TRUE; 8955 } 8956 else 8957 { 8958 p = pp; 8959 pp = pNext(p); 8960 } 8961 } 8962 else 8963 { 8964 p = pp; 8965 pp = pNext(p); 8966 } 8967 } 8968 //printf("\nAfter\n");pWrite(pH); 8969 } 8970 } 8971 //printf("\nFinal\n");pWrite(pH);getchar(); 8972 h->SetLmCurrRing(); 8973 if(deleted) 8974 strat->initEcart(h); 8975 } 8976 8977 /*! 8978 used for GB over ZZ: final reduction by constant elements 8979 background: any known constant element of ideal suppresses 8980 intermediate coefficient swell and beautifies output 8981 */ 8982 void finalReduceByMon(kStrategy &strat) 8983 { 8984 if(!nCoeff_is_Ring_Z(currRing->cf)) 8985 return; 8986 poly p,pp; 8987 for(int j = 0; j<=strat->sl; j++) 8988 { 8989 if((strat->S[j]!=NULL)&&(pNext(strat->S[j]) == NULL)) 8990 { 8991 for(int i = 0; i<=strat->sl; i++) 8992 { 8993 if((i != j) && (strat->S[i] != NULL)) 8994 { 8995 p = strat->S[i]; 8996 if(pLmDivisibleBy(strat->S[j], p)) 8997 { 8998 p->coef = currRing->cf->cfIntMod(p->coef, strat->S[j]->coef, currRing->cf); 8999 } 9000 pp = pNext(p); 9001 if((pp == NULL) && (nIsZero(p->coef))) 9002 { 9003 strat->S[i] = NULL; 9004 //deleteInS(i, strat); 9005 } 9006 else 9007 { 9008 while(pp != NULL) 9009 { 9010 if(pLmDivisibleBy(strat->S[j], pp)) 9011 { 9012 pp->coef = currRing->cf->cfIntMod(pp->coef, strat->S[j]->coef, currRing->cf); 9013 if(nIsZero(pp->coef)) 9014 { 9015 pLmDelete(&pNext(p)); 9016 pp = pNext(p); 9017 } 9018 else 9019 { 9020 p = pp; 9021 pp = pNext(p); 9022 } 9023 } 9024 else 9025 { 9026 p = pp; 9027 pp = pNext(p); 9028 } 9029 } 9030 } 9031 if(strat->S[i]!= NULL && nIsZero(pGetCoeff(strat->S[i]))) 9032 { 9033 if(pNext(strat->S[i]) == NULL) 9034 strat->S[i]=NULL; 9035 else 9036 strat->S[i]=pNext(strat->S[i]); 9037 } 9038 } 9039 } 9040 //idPrint(strat->Shdl); 9041 } 9042 } 9043 //idSkipZeroes(strat->Shdl); 9044 } 9045 8476 9046 #endif 8477 9047
Note: See TracChangeset
for help on using the changeset viewer.